code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include<bits/stdc++.h> using namespace std; int main(){ int s=100;vector<int>v(4); for(int i=0;i<4;i++){ cin>>v[i]; if(s>v[i])s=v[i]; } cout<<s<<endl; }
#include<bits/stdc++.h> #define ll long long #define eb emplace_back using namespace std; const int mx= 1e3 + 10; void solve(){ int a, b , c , d; cin >> a >> b >> c >> d; cout << min(a, min(c , min(b,d))); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t; //cin>>t; t=1; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long double ld; #define int long long #define pb push_back #define mk make_pair #define MOD 1000000007 #define vii vector<int> #define pii pair<int,int> #define piii pair<int, pii> #define yes cout<<"YES\n"; #define no cout<<"NO\n"; #define UB upper_bound #define LB lower_bound #define BS binary_search #define PI 3.1415926535897932384626433832795 #define dec(x) fixed<<setprecision(x) #define tc int t;cin>>t;while(t--) #define pr(x) for(auto it : x)cout<<it<<" "; #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) (a*b/__gcd(a,b)) #define fi(i,n) for(int i=0;i<n;i++) #define f(i, a, b) for(int i=a;i<b;i++) #define all(v) v.begin(),v.end() #define fast ios_base::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL); #define endl cout<<"\n"; map<int,int>mp; int comp(int a, int b){ return (a>b); } bool prime(int n) { if(n==0 or n==1) return false; if(n==2) return true; else if(n%2==0) return false; for(int i=3;i*i<=n;i+=2) { if(n%i==0) { return false; } } return true; } int binCo(int n, int r){ int C[n+1][r+1]; for(int i=0;i<n;i++) { for(int j=0;j<=min(i,r);j++) { if(j==0 or j==i) C[i][j] = 1; else C[i][j] = C[i-1][j] + C[i-1][j-1]; } } return C[n][r]; } //Modular Exponentiation O(Log y) int power(int x, int y, int MODL) { int res = 1; x = x % MODL; while (y > 0) { if (y & 1) res = (res*x) % MODL; y = y>>1; x = (x*x) % MODL; } return res; } //Fermat's Little theorem, O(Log m) int modInverse(int a, int m) { return power(a, m-2, m); } int binSearch(int arr[], int n, int x) { int l = 0, r=n-1; while(l<=r) { int mid = (l+r)/2; if(x==arr[mid]) return mid; if(x>arr[mid]) { l = mid+1; } else if(x<arr[mid]) { r = mid-1; } } return -1; } void solve() { int n,k; cin>>n>>k; string s = "" ; while(k--){ if(n%200==0) n/=200; else { s = to_string(n); s+="200"; n = stoll(s); } } cout<<n; } int32_t main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; solve(); return 0; }
///* ***Bismillahir Rahmanir Rahim*** */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double dl; typedef unsigned long long ull; #define pb push_back #define PB pop_back #define nn "\n" #define O_O \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define all(p) p.begin(), p.end() #define zz(v) (ll) v.size() #define ss ' ' #define MEM(a, b) memset(a, (b), sizeof(a)) #define CLR(p) memset(p, 0, sizeof(p)) #define precision(a) fixed << setprecision(a) #define rep(i, b) for (ll i = 0; i < (b); i++) #define rep1(i, b) for (int i = 1; i <= (b); i++) //#define rep(s,e) for(i=s;i<e;i+=1) //#define rep(i,a,b) for(int i=(a);i<(b);i++) #define fr(i, b, a) for (int i = (b); i >= (a); i--) #define rep2(i, a, b, c) for (int i = (a); i != (b); i += (c)) #define arrsize(a) (sizeof(a) / sizeof(a[0])) //#define arrsize(a) (sizeof(a)/sizeof(*a)) #define S(a) scanf("%lld", &a) #define SS(a, b) scanf("%lld %lld", &a, &b) #define SSS(a, b, c) scanf("%lld %lld %lld", &a, &b, &c) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (a * b) / gcd(a, b) #define pi acos(-1.0) #define ff first #define sc second #define print(v) \ for (ll i : v) \ cout << i << ss typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef vector<ll> vll; typedef map<string, ll> msl; typedef map<ll, ll> mll; #define yes cout << "YES\n" #define no cout << "NO\n" bool comp(pair<ll, ll> a, pair<ll, ll> b) { if (a.first != b.first) return a.first > b.first; else return a.second > b.second; } //ll minelementindex = min_element(v.begin(),v.end()) - v.begin(); //ll minelement = *min_element(v.begin(), v.end()); //ll maxelementindex = max_element(v.begin(),v.end()) - v.begin(); //ll maxelement = *max_element(v.begin(), v.end()); //memset(ar,-1,sizeof(ar)); //#define sort(x) sort(x.begin(), x.end()) //sort(a,a+n,greater<ll>()) //for (auto it = mp.begin(); it != mp.end(); ++it){} // string x(w.size(),'1'); //auto s =to_string(42); //string s = "12345"; // object from the class stringstream //stringstream geek(s); // The object has the value 12345 and stream // it to the integer x //int x = 0; //geek >> x; #define MAX 1000005 #define precision(a) fixed << setprecision(a) #define mod 1000000007 int main() { //O_O ; ll t = 1; // cin>>t; while (t--) { ll n, k; cin >> n >> k; auto s = to_string(n); while (k--) { stringstream geek(s); ll x = 0; geek >> x; // cout << x << nn; if (x % 200 == 0) { x /= 200; auto c = to_string(x); s = c; } else s += "200"; } cout << s << nn; } return 0; }
#include <bits/stdc++.h> using namespace std; using lli = long long int; using ii = pair<int, int>; const int MAXN = 500; int r, c; int a[MAXN+1][MAXN]; int b[MAXN][MAXN+1]; int cost[MAXN+1][MAXN+1]; int dijkstra() { memset(cost, -1, sizeof(cost)); priority_queue<pair<int, ii>, vector<pair<int, ii>>, greater<pair<int, ii>>> pq; cost[1][1] = 0; pq.push({0, {1, 1}}); while(!pq.empty()) { pair<int, ii> u = pq.top(); pq.pop(); int curCost = u.first; ii pos = u.second; // printf("%d %d %d\n", curCost, pos.first, pos.second); if(pos.first == r and pos.second == c) { return curCost; } if(curCost > cost[pos.first][pos.second]) { continue; } if(pos.first < r and (cost[pos.first+1][pos.second] == -1 or curCost+b[pos.first][pos.second] < cost[pos.first+1][pos.second])) { cost[pos.first+1][pos.second] = curCost+b[pos.first][pos.second]; pq.push({cost[pos.first+1][pos.second], {pos.first+1, pos.second}}); } if(pos.second > 1 and (cost[pos.first][pos.second-1] == -1 or curCost+a[pos.first][pos.second-1] < cost[pos.first][pos.second-1])) { cost[pos.first][pos.second-1] = curCost+a[pos.first][pos.second-1]; pq.push({cost[pos.first][pos.second-1], {pos.first, pos.second-1}}); } if(pos.second < c and (cost[pos.first][pos.second+1] == -1 or curCost+a[pos.first][pos.second] < cost[pos.first][pos.second+1])) { cost[pos.first][pos.second+1] = curCost+a[pos.first][pos.second]; pq.push({cost[pos.first][pos.second+1], {pos.first, pos.second+1}}); } for(int i=1; i<pos.first; i++) { if(cost[pos.first-i][pos.second] == -1 or curCost+i+1 < cost[pos.first-i][pos.second]) { cost[pos.first-i][pos.second] = curCost+i+1; pq.push({cost[pos.first-i][pos.second], {pos.first-i, pos.second}}); } else if(curCost+i+1 == cost[pos.first-i][pos.second]) { continue; } else { break; } } } } int main() { scanf("%d %d", &r, &c); for(int i=1; i<=r; i++) { for(int j=1; j<c; j++) { scanf("%d", &a[i][j]); } } for(int i=1; i<r; i++) { for(int j=1; j<=c; j++) { scanf("%d", &b[i][j]); } } printf("%d\n", dijkstra()); }
//#pragma GCC optimize("O3") //#pragma GCC target("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; #define all(v) (v).begin(), (v).end() #define ar array #define PB push_back using ll = long long; const int INF = 1e9; const ll LINF = 1e15; const int MOD = 1e9 + 7; //998244353 const int N = 2e5 + 1, LOG = 20; vector<int> adj[N]; unordered_map<int, vector<int>, custom_hash> m1; int n, dep[N], u, v, d, st[N], en[N], timer = 0; void dfs(int V, int pV) { st[V] = timer; m1[dep[V]].PB(st[V]); for (auto &e : adj[V]) { if (e == pV) continue; timer++; dep[e] = dep[V] + 1; dfs(e, V); } en[V] = timer; } int search(int U, int D) { if (dep[U] > D) return 0LL; if (dep[U] == D) return 1LL; int targ1 = st[U], targ2 = en[U]; int l = 0, r = (int)m1[D].size() - 1, lbound = -1, rbound = -1; while (l <= r) { int m = l + (r - l) / 2; if (m1[D][m] >= targ1) { lbound = m; r = m - 1; } else l = m + 1; } if (lbound == -1) return 0LL; l = 0, r = (int)m1[D].size() - 1; while (l <= r) { int m = l + (r - l) / 2; if (m1[D][m] <= targ2) { rbound = m; l = m + 1; } else r = m - 1; } if (rbound == -1) return 0LL; return rbound - lbound + 1; } void solve() { cin >> n; for (int i = 2; i <= n; i++) { cin >> v; adj[v].PB(i); adj[i].PB(v); } dfs(1, 0); int q; cin >> q; while (q--) { cin >> u >> d; cout << search(u, d) << "\n"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); solve(); #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * (double)clock() / CLOCKS_PER_SEC << " s.\n"; #endif }
#include<bits/stdc++.h> #include<string> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long; //auto test int main(){ ll N; cin>>N; for(ll i=1;;i++){ if(stoll(to_string(i)+to_string(i))>N){ cout<<i-1<<endl; return 0; } } }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<ll ,ll> pll; #define F first #define S second #define pb push_back #define mp make_pair #define all(X) (X).begin(), (X).end() #define REP(i,x,y) for(ll i = x;i <= y;++i) #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) vector<string> vec_splitter(string s) { for(char& c: s) c = c == ','? ' ': c; stringstream ss; ss << s; vector<string> res; for(string z; ss >> z; res.push_back(z)) ; return res; } void debug_out(vector<string> args, int idx) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, Head H, Tail... T) { if(idx > 0) cerr << ", "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, T...); } #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__) void localTest() { #ifndef ONLINE_JUDGE freopen("inp", "r", stdin); freopen("out", "w", stdout); #endif } void solver() { ll n, cnt = 0; cin >> n; for(ll i = 1; i <= min((ll)1e6, n); ++i) { string s = to_string(i); s += s; if(stoll(s) <= n) { ++cnt; } } cout << cnt << "\n"; return; } int main() { localTest(); fastio; int t = 1; // cin >> t; while(t--) { solver(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; ll H, W; vector<string> S; pair<ll,ll> st, en; map<char,vector<pair<ll,ll>>> T; map<char,bool> seen; vector<ll> dx = {1,0,-1,0}; vector<ll> dy = {0,1,0,-1}; void init() { cin >> H >> W; S.resize(H); rep(i,H) cin >> S[i]; rep(i,H) rep(j,W) { char c = S[i][j]; pair<ll,ll> p = {i,j}; if (c=='.' || c=='#') continue; if (c=='S') st = p; else if (c=='G') en = p; else T[c].push_back(p); } } ll solve() { vector<vector<ll>> dist(H,vector<ll>(W,inf)); dist[st.first][st.second] = 0; queue<pair<ll,ll>> que; que.push(st); while (que.size()) { pair<ll,ll> p = que.front(); que.pop(); ll x = p.first, y = p.second; ll d = dist[x][y]; rep(i,4) { ll nx = x + dx[i], ny = y + dy[i]; if (nx<0 || nx>=H || ny<0 || ny>=W) continue; if (S[nx][ny]=='#') continue; ll nd = d + 1; if (nd<dist[nx][ny]) { dist[nx][ny] = nd; que.push({nx,ny}); } } char c = S[x][y]; if (c=='.' || c=='S' || c=='G') continue; if (seen[c]) continue; seen[c] = true; for (auto p : T[c]) { ll nx = p.first, ny = p.second; ll nd = d + 1; if (dist[nx][ny]>nd) { dist[nx][ny] = nd; que.push(p); } } } ll res = dist[en.first][en.second]; if (res==inf) res = -1; return res; } int main() { init(); ll ans = solve(); Cout(ans); }
///Bismillahir Rahmanir Rahim #include "bits/stdc++.h" #define ll long long #define int ll #define fi first #define si second #define mp make_pair #define pb push_back #define pi pair<int,int> #define nd(a,b,c) mp(mp(a,b),c) #define clr(x) memset(x,0,sizeof(x)); #define f(i,l,r) for(int i=l;i<=r;i++) #define rf(i,r,l) for(int i=r;i>=l;i--) #define done(i) cout<<"done = "<<i<<endl; #define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll inf=2e18; const int mod=1e9+7; const int M=3005; inline ll bigmod(ll B,ll P){ll R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;} inline ll ad(ll x,ll y){ll ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;} inline ll sub(ll x,ll y){ll ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;} inline ll gun(ll x,ll y){ll ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;} int n; int a[M],pre[M]; int dp[M][M]; int sum[M],nxt[M]; main() { fast cin>>n; f(i,1,n)cin>>a[i],pre[i]=a[i]+pre[i-1]; rf(k,n,1) { f(pos,1,n) { int val=pre[pos-1]%k; sum[val]=sub(sum[val],dp[pos][k+1]); dp[pos][k]=sum[val]; int z=pre[n]-pre[pos-1]; z=z%k; if(z==0)dp[pos][k]=(dp[pos][k]+1)%mod; if(k!=1){ val=pre[pos-1]%(k-1); nxt[val]=ad(nxt[val],dp[pos][k]); } } f(j,0,k+1) { sum[j]=nxt[j]; nxt[j]=0; } } cout<<dp[1][1]<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string s;cin>>s;s+="################"; int ans=0; for(int i=0;s[i]!='#';i++)ans+=s.substr(i,4)=="ZONe"; cout<<ans<<endl; }
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using i64 = int64_t; using vi64 = vector<i64>; using vvi64 = vector<vi64>; using vvvi64 = vector<vvi64>; using u64 = uint64_t; #define rep(i, s, n) for (i64 i = (s); i < (n); ++i) // constexpr i64 mod{1000000007}; // constexpr i64 izero{0}; // constexpr i64 ione{1}; // constexpr u64 uone{1}; // constexpr i64 di[]{0, 1, 0, -1}, dj[]{1, 0, -1, 0}; void run() { string s; cin >> s; i64 ret{0}; rep(i, 0, 4){ i64 c{0}; rep(j, i, 9){ if(s.substr(j, 4) == "ZONe"){ ++c; } } ret = max(ret, c); } cout << ret << endl; } int main() { cin.tie(nullptr); cout.precision(std::numeric_limits<double>::max_digits10); cerr.precision(std::numeric_limits<double>::max_digits10); clog.precision(std::numeric_limits<double>::max_digits10); run(); return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0;i<(int)(n);i++) using ll = long long; using P = pair<int, int>; const int INF = 1e9; int main(){ int R,C; cin >> R >> C; vector<vector<char>> table(R, vector<char>(C)); vector<vector<int>> dist(R, vector<int>(C)); int sy, sx, gy, gx; vector<int> alx[26], aly[26]; bool alf[26]={}; rep(i, R){ rep(j, C){ cin >> table.at(i).at(j); if(table.at(i).at(j) == 'S'){sx = j; sy = i;} if(table.at(i).at(j) == 'G'){gx = j; gy = i;} if(table.at(i).at(j) >= 'a' && table.at(i).at(j) <= 'z'){ assert(table.at(i).at(j) - 'a' < 26); alx[table.at(i).at(j) - 'a'].push_back(j); aly[table.at(i).at(j) - 'a'].push_back(i); } dist.at(i).at(j) = INF; } } //sx--; sy--; gx--; gy--; queue<pair<int, int>> Q; Q.push(make_pair(sy, sx)); dist.at(sy).at(sx)=0; while(!Q.empty()){ int cy = Q.front().first, cx = Q.front().second; Q.pop(); int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; rep(i, 4){ int ex = cx + dx[i], ey = cy + dy[i]; if(ex < 0 || ex >=C || ey < 0 || ey >= R) continue; if (table.at(ey).at(ex) == '#' || dist.at(ey).at(ex) != INF) continue; Q.push(make_pair(ey, ex)); dist.at(ey).at(ex) = dist.at(cy).at(cx) + 1; } if(table.at(cy).at(cx) >= 'a' && table.at(cy).at(cx) <= 'z'){ if(alf[table.at(cy).at(cx)-'a']) continue; int aaa=table.at(cy).at(cx)-'a'; assert(aaa <= 25); assert(alx[aaa].size() <= 2000 * 2000); assert(alx[aaa].size() == aly[aaa].size()); rep(j, alx[aaa].size()){ if(alx[aaa][j] == cx && aly[aaa][j] == cy) continue; if(dist.at(aly[aaa][j]).at(alx[aaa][j]) != INF) continue; Q.push(make_pair(aly[aaa][j], alx[aaa][j])); dist.at(aly[aaa][j]).at(alx[aaa][j]) = dist.at(cy).at(cx) + 1; } alf[table.at(cy).at(cx)-'a'] = true; } } if(dist.at(gy).at(gx) == INF){ cout << -1 << endl; return 0; } cout << dist.at(gy).at(gx) << endl; }
#include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #include<queue> using namespace std; int tesuu[2006][2006]; int used[1000]; int dx[4]={-1,0,1,0}; int dy[4]={0,-1,0,1}; string karifie[2006]; char fie[2006][2006]; int main(){ for(int i=0;i<2006;i++){ for(int j=0;j<2006;j++){ tesuu[i][j]=-1; } } int H,W; cin>>H>>W; for(int i=0;i<H;i++){ cin>>karifie[i]; } int gy,gx,sy,sx; for(int i=0;i<=H+1;i++){ for(int j=0;j<=W+1;j++){ if(i==0||j==0||i==H+1||j==W+1)fie[i][j]='#'; else fie[i][j]=karifie[i-1][j-1]; if(fie[i][j]=='S'){sy=i;sx=j;}; if(fie[i][j]=='G'){gy=i;gx=j;}; } } queue<int> Qx,Qy; Qy.push(sy); Qx.push(sx); tesuu[sy][sx]=0; while(!Qx.empty()){ int kariy=Qy.front();Qy.pop(); int karix=Qx.front();Qx.pop(); for(int i=0;i<4;i++){ if(fie[kariy+dy[i]][karix+dx[i]]!='#'){ if(tesuu[kariy+dy[i]][karix+dx[i]]==-1){ Qy.push(kariy+dy[i]);Qx.push(karix+dx[i]); tesuu[kariy+dy[i]][karix+dx[i]]=tesuu[kariy][karix]+1; } } } if('a'<=fie[kariy][karix]&&fie[kariy][karix]<='z'){ if(used[fie[kariy][karix]]==0){ used[fie[kariy][karix]]=1; for(int i=1;i<=H;i++){ for(int j=1;j<=W;j++){ if(i==kariy&&j==karix)continue; if(fie[kariy][karix]==fie[i][j]){ if(tesuu[i][j]==-1){ Qy.push(i);Qx.push(j); tesuu[i][j]=tesuu[kariy][karix]+1; } } } } } } } cout<<tesuu[gy][gx]<<endl; return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, M, w[10]; int l[101010], v[101010]; ll dp[10][10]; //--------------------------------------------------------------------------------------------------- ll solve() { rep(i, 0, N) rep(j, 0, M) if (v[j] < w[i]) return -1; map<int, int> pr; rep(i, 0, M) { if (pr.count(l[i]) == 0) pr[l[i]] = inf; chmin(pr[l[i]], v[i]); } set<pair<ll, int>> lens; // {weight, len} int pre = inf; for (auto ite = pr.rbegin(); ite != pr.rend(); ite++) if (ite->second < pre) { lens.insert({ ite->second, ite->first }); pre = ite->second; } vector<int> ord; rep(i, 0, N) ord.push_back(i); ll ans = infl; do { rep(i, 0, N) rep(j, 0, N) dp[i][j] = infl; rep(i, 0, N) dp[i][i] = 0; rep(len, 2, N + 1) rep(l, 0, N) { int r = l + len - 1; if (N <= r) continue; ll weight = 0; rep(i, l, r + 1) weight += w[ord[i]]; auto ite = lens.lower_bound({ weight, -1 }); if (ite == lens.begin()) { dp[l][r] = 0; } else { ite--; dp[l][r] = ite->second; } rep(c, l, r + 1) chmax(dp[l][r], dp[l][c] + dp[c][r]); } chmin(ans, dp[0][N - 1]); } while (next_permutation(all(ord))); return ans; } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> M; rep(i, 0, N) cin >> w[i]; rep(i, 0, M) cin >> l[i] >> v[i]; cout << solve() << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define mp make_pair #define fr first #define sc second int main(){ ld x,y,rr; cin>>x>>y>>rr; x+=200100.; y+=200100.; ll X=10000*x+0.5; ll Y=10000*y+0.5; ll R=10000*rr+0.5; ll ret=0; for(ll s=x-rr-10;s<x+rr+10;s++){ ll b,u; ll l=y-rr-10,r=y+1; //cerr<<l<<" "<<r<<endl; while(l<r){ ll t=(l+r)/2; ll d=(s*10000-X)*(s*10000-X)+(t*10000-Y)*(t*10000-Y); //cerr<<t<<" "<<d<<" "<<R<<endl; if(d<=R*R)r=t; else l=t+1; } b=l; l=y; r=y+rr+10; //cerr<<l<<" "<<r<<endl; while(l<r){ ll t=(l+r+1)/2; ll d=(s*10000-X)*(s*10000-X)+(t*10000-Y)*(t*10000-Y); if(d<=R*R)l=t; else r=t-1; } u=l; if(b<=u)ret+=u-b+1; //cout<<s<<" "<<b<<" "<<u<<endl; } cout<<ret<<endl; }
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define mp make_pair #define fi first #define se second #define phi 3.1415926535 #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; const ll mod = 1000000007; ll tc, cnt = 0, number, many, total = 0, query, require, length; int rmove[8] = {1, 0, 0, -1, -1, 1, -1, 1}; int cmove[8] = {0, -1, 1, 0, 1, -1, -1, 1}; ll modpow(ll x, ll y, ll m) { ll res = 1; while(y > 0) { if(y & 1) res = (res * x) % m; x = (x * x) % m; y >>= 1; } return res; } int main() { fastio(); // freopen("input.txt","r", stdin); // freopen("output.txt","w", stdout); // g++ -std=c++11 Default.cpp -o test // g++ -Wl,--stack=268435456 -std=c++11 Default.cpp -o test int a, b; cin >> a >> b; int temp = (a + b) / 2; cout << temp << " " << a - temp << '\n'; // return 0; }
#include <bits/stdc++.h> #define N 10005 const int mmax = 1e9; using namespace std; int a, b; void process() { cin >> a >> b; int x = (a-b)/2; int y = (a+b)/2; if (x-y == b) cout << x <<" "<<y; else cout << y <<" "<< x; } int main() { //freopen("test.INP", "r", stdin); process(); return 0; }
#include <bits/stdc++.h> using namespace std; void center(vector<pair<int, int>>& points) { int n = points.size(); pair<int, int> center(0, 0); for (int i = 0; i < n; ++i) { center.first += points[i].first; center.second += points[i].second; points[i].first *= n; points[i].second *= n; } for (int i = 0; i < n; ++i) { points[i].first -= center.first; points[i].second -= center.second; } } int get_zero_ind(const vector<pair<int, int>>& points) { int n = points.size(); for (int i = 0; i < n; ++i) { if ((points[i].first == 0) && (points[i].second == 0)) { return i; } } return -1; } vector<pair<int, int>> remove_point(const vector<pair<int, int>>& points, int ind) { vector<pair<int, int>> result; for (int i = 0; i < int(points.size()); ++i) { if (i != ind) { result.push_back(points[i]); } } return result; } vector<int> get_order(const vector<pair<int, int>>& points) { const pair<int, int> origin(0, 0); int n = points.size(); vector<int> order(n); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&points, &origin](int i1, int i2) { bool ba = points[i1] < origin; bool bb = points[i2] < origin; if (ba != bb) { return (ba < bb); } int cross = points[i1].first * points[i2].second - points[i2].first * points[i1].second; if (cross == 0) { auto point_length = [](const pair<int, int>& p) { return p.first * p.first + p.second * p.second; }; return point_length(points[i1]) < point_length(points[i2]); } return (cross > 0); }); return order; } vector<array<int, 3>> make_features(const vector<pair<int, int>>& points, const vector<int>& order) { int n = order.size(); vector<array<int, 3>> features(n); for (int i = 0; i < n; ++i) { const pair<int, int>& me = points[order[i]]; const pair<int, int>& he = points[order[(i+1)%n]]; features[i][0] = me.first * me.first + me.second * me.second; features[i][1] = me.first * he.first + me.second * he.second; features[i][2] = me.first * he.second - me.second * he.first; } return features; } bool can(vector<pair<int, int>>& S, vector<pair<int, int>>& T) { int n = S.size(); center(S); center(T); int zero_S = get_zero_ind(S); int zero_T = get_zero_ind(T); if ((zero_S >= 0) != (zero_T >= 0)) { return false; } if (zero_S >= 0) { remove_point(S, zero_S).swap(S); remove_point(T, zero_T).swap(T); } n = S.size(); if (n < 2) { return true; } vector<int> order_S = get_order(S); vector<int> order_T = get_order(T); vector<array<int, 3>> features_S = make_features(S, order_S); vector<array<int, 3>> features_T = make_features(T, order_T); for (int i = 0; i < n; ++i) { bool ok = true; for (int j = 0; ok && (j < n); ++j) { ok = (features_S[j] == features_T[(j+i)%n]); } if (ok) { return true; } } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; vector<pair<int, int>> S(N), T(N); for (int i = 0; i < N; ++i) { cin >> S[i].first >> S[i].second; } for (int i = 0; i < N; ++i) { cin >> T[i].first >> T[i].second; } cout << (can(S, T) ? "Yes" : "No") << endl; }
#include <bits/stdc++.h> using namespace std; int main(void) { int n, m; cin >> n >> m; vector<int> a(m), b(m); for(int i = 0; i < m; i++) cin >> a[i] >> b[i]; int k, ans = 0; cin >> k; vector<int> c(k), d(k); for(int i = 0; i < k; i++) cin >> c[i] >> d[i]; int k2 = 1 << k; for(int i = 0; i < k2; i++) { vector<int> dish(n+1); for(int j = 0; j < k; j++) { if((i>>j) & 1) { //iのj桁目が1なら dish[d[j]]++; } else { dish[c[j]]++; } } int now = 0; for(int j = 0; j < m; j++) { if(dish[a[j]] == 0) continue; if(dish[b[j]] == 0) continue; now++; } ans = max(ans, now); } cout << ans << endl; return 0; }
#pragma region Region_1 #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() using ll = long long; using P = pair<int, int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VP = vector<P>; #define MOD 1000000007 const int INF = 1e9 + 10; template <class T, class C> void chmax(T& a, C b) { if (a <= b) a = b; } template <class T, class C> void chmin(T& a, C b) { if (a >= b) a = b; } // const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1}; // const int dx[]{0, 1, 0, -1}, dy[]{1, 0, -1, 0}; template <class T> T sum(const vector<T>& v) { T res = 0; for (size_t i = 0; i < v.size(); ++i) res += v[i]; return res; } ///////////////////////////////////////////////////////// // print like python // https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed ///////////////////////////////////////////////////////// void print() { cout << endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); } template <class T> void print(vector<T>& vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; } template <class T> void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); } } #pragma endregion Region_1 ///////////////////////////////////////////////////////// int main() { //入力の高速化用のコード ios::sync_with_stdio(false); cin.tie(nullptr); std::cout << std::setprecision(15); ////////////////////////////////////////// int n,k,m; cin >> n >> k >> m; VI A(n-1); ll tot=0; rep(i,n-1){ cin >> A[i]; tot += A[i]; } if(tot - (n*m)>=0){ print(0); }else if(tot + k <(n*m)){ print(-1); }else{ print((n*m)-tot); } return 0; }
// Problem : D - Snuke Prime // Contest : AtCoder - AtCoder Beginner Contest 188 // URL : https://atcoder.jp/contests/abc188/tasks/abc188_d // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) /*ヽ`、ヽ``、ヽ`ヽ`、、ヽ `ヽ 、ヽ`🌙`ヽヽ`ヽ、ヽ` ヽ`、ヽ``、ヽ 、``、 `、ヽ` 、` ヽ`ヽ、ヽ `、ヽ``、 ヽ、``、`、ヽ``、 、ヽヽ`、`、、ヽヽ、``、 、 ヽ`、 ヽ``、 ヽ`ヽ`、、ヽ `ヽ 、 🚶ヽ````ヽヽヽ`、、ヽ`、、ヽ*/ #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define F0R(i, a) for (int i=0; i<(a); i++) #define FORd(i,b,a) for (int i = (b)-1; i >= a; i--) #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) #define trav(a,x) for (auto& a : x) #define bug(x) cout<<#x<<"="<<x<<endl; #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define ins insert template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ld pii=3.14159265359; const int MOD = 1000000007; const char nl = '\n'; const int MX = 200001; //check the limits, dummy void solve() { ll N,C;cin>>N>>C; vl pt; map<ll,ll> st,en; F0R(x,N) { ll a,b,c;cin>>a>>b>>c; st[a]+=c; en[b]+=c; pt.pb(a); pt.pb(b);//? } sort(all(pt)); pt.erase(unique(all(pt)),pt.end()); ll sum=0,ans=0; F0R(x,sz(pt)) { if(x!=0) { ans+=(pt[x]-pt[x-1]-1)*min(C,sum); } if(st.count(pt[x])) sum+=st[pt[x]]; ans+=min(C,sum); if(en.count(pt[x])) sum-=en[pt[x]]; } cout<<ans; } int main() { // think two times, so you won't have to code three times ios_base::sync_with_stdio(0); cin.tie(0); int Test_case=1; // cin>>Test_case; while(Test_case--!=0) { solve(); } return 0; } // read the question correctly (ll vs int) // template by bqi343
#include<bits/stdc++.h> using namespace std; int main(){ int a ,b, c; cin >> a >> b >> c; if(a%6==1){ a = 6; }else if(a%6==2){ a = 5; }else if(a%6==3){ a = 4; }else if(a%6==4){ a = 3; }else if(a%6==5){ a = 2; }else if(a%6==0){ a = 1; } if(b%6==1){ b = 6; }else if(b%6==2){ b = 5; }else if(b%6==3){ b = 4; }else if(b%6==4){ b = 3; }else if(b%6==5){ b = 2; }else if(b%6==0){ b = 1; } if(c%6==1){ c = 6; }else if(c%6==2){ c = 5; }else if(c%6==3){ c = 4; }else if(c%6==4){ c = 3; }else if(c%6==5){ c = 2; }else if(c%6==0){ c = 1; } cout << a+b+c << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using Graph = vector<vector<int>>; int main(void) { ll a,b,c; cin >> a >> b >>c; cout << 7-a+7-b+7-c << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() using namespace std; using ll = long long; using P = pair<int, int>; const ll INF = 1LL << 60; const int MOD = (int)1e9 + 7; int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(all(a)); ll ans = 0; int l = 0, r = n - 1; while (r - l >= 1) { ans += (a[r] - a[l]) * (n - 1); n -= 2; r--; l++; } cout << ans << '\n'; return 0; }
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #ifdef ENABLE_DEBUG #include <debug.h> #else #define DEBUG(...) do {} while (0) #endif using namespace std; using namespace __gnu_pbds; using ll = long long; using ull = unsigned long long; using lll = __int128; using ulll = unsigned __int128; template<typename T, size_t N> using ar = array<T, N>; template<typename T, typename Cmp = less<T>> using iset = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update, allocator<T>>; #define REPSI(name, start, stop, step) for (ll name = start; name < (ll)stop; name += step) #define REPS(name, start, stop) REPSI(name, start, stop, 1) #define REP(name, stop) REPS(name, 0, stop) #define RREPSI(name, start, stop, step) for (ll name = stop-1; name >= (ll)start; name -= step) #define RREPS(name, start, stop) RREPSI(name, start, stop, 1) #define RREP(name, stop) RREPS(name, 0, stop) #define cin fastIO #define cout fastIO struct FastIO { static const int IBUF_SZ = 2e8, OBUF_SZ = 2e8; char IBUF[IBUF_SZ], OBUF[OBUF_SZ]; int IBUF_I = 0, OBUF_I = 0; FastIO() { fread(IBUF, 1, sizeof(IBUF), stdin); } ~FastIO() { OBUF[OBUF_I++] = 0; fputs(OBUF, stdout); } FastIO &operator>>(char &c) { c = IBUF[IBUF_I++]; return *this; } FastIO &operator<<(char c) { OBUF[OBUF_I++] = c; return *this; } template<typename Int> FastIO &operator>>(Int &x) { x = 0; bool neg=false; while (IBUF[IBUF_I] < '0' || IBUF[IBUF_I] > '9') if (IBUF[++IBUF_I] == '-') neg=true; while (IBUF[IBUF_I] >= '0' && IBUF[IBUF_I] <= '9') x = 10*x + IBUF[IBUF_I++]-'0'; if (neg) x = -x; return *this; } template<typename Int> FastIO &operator<<(Int x) { static char BUF[40]; if (x < 0) OBUF[OBUF_I++] = '-', x = -x; int i = 40; do { BUF[--i] = x%10 + '0'; } while (x /= 10); while (i < 40) OBUF[OBUF_I++] = BUF[i++]; return *this; } template<typename T> FastIO &operator>>(vector<T> &vec) { REP(i, vec.size()) (*this) >> vec[i]; return *this; } }; FastIO fastIO; template<typename T> void cins(T &first) { cin >> first; } template<typename T, typename... Ts> void cins(T &first, T &second, Ts&... rest) { cin >> first; cins(second, rest...); } #define GET(type, ...) type __VA_ARGS__; cins(__VA_ARGS__) #define GETI(...) GET(int, __VA_ARGS__) #define GETLL(...) GET(ll, __VA_ARGS__) #define GETS(...) GET(string, __VA_ARGS__) #define GETD(...) GET(double, __VA_ARGS__) #define GETC(...) GET(char, __VA_ARGS__) template<typename T> istream &operator>>(istream &is, vector<T> &a) { for (T &v : a) is >> v; return is; } template<typename T, size_t N> istream &operator>>(istream &is, ar<T, N> &a) { REP(i, N) is >> a[i]; return is; } int main() { GETLL(n); vector<ll> a(n); cin >> a; sort(a.begin(), a.end()); ll ans = 0; ll cur = 0; REP(i, n) cur += a[i]-a[0]; ans += cur; REPS(i, 1, n) { ll smaller = i-1; ll larger = n-i-1; ll diff = a[i]-a[i-1]; cur += diff*smaller; cur -= diff*larger; ans += cur; } cout << ans/2 << '\n'; }
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; #define debug(x) cout << #x << " is " << x << endl #define inc(i, a, b) for (int i = a; i <= b; ++i) typedef long long ll; const int INF = 0x3f3f3f3f, N = 2005; const int MOD = 1e9 + 7; int n, m; ll qpow(ll x, ll y) { ll ans = 1; for (; y; y >>= 1, x = x * x % MOD) if (y & 1) ans = ans * x % MOD; return ans; } int main() { scanf("%d%d", &n, &m); int a = n + m, b = n, x, y; for (int i = 1; i <= n; ++i) scanf("%d", &x), b += x; if (a < b) { puts("0"); return 0; } x = 1, y = 1; for (int i = 1; i <= b; ++i) { x = (ll)x * (a - i + 1) % MOD; y = (ll)y * i % MOD; } printf("%lld\n", (ll)x * qpow(y, MOD - 2) % MOD); return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define x first #define y second #define FOR(i, m, n) for (ll i(m); i < n; i++) #define DWN(i, m, n) for (ll i(m); i >= n; i--) #define REP(i, n) FOR(i, 0, n) #define DW(i, n) DWN(i, n, 0) #define F(n) REP(i, n) #define FF(n) REP(j, n) #define D(n) DW(i, n) #define DD(n) DW(j, n) using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; using vll = vector<ll>; using vpll = vector<pll>; using vtll = vector<tll>; using gr = vector<vll>; using wgr = vector<vpll>; void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); } void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); } template<typename T,typename U> ostream& operator<<(ostream& os, const pair<T,U>& p) { cerr << ' ' << p.x << ',' << p.y; return os; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for(auto x: v) os << ' ' << x; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for(auto x: v) os << ' ' << x; return os; } template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& v) { for(auto x: v) os << ' ' << x; return os; } struct d_ { template<typename T> d_& operator,(const T& x) { cerr << ' ' << x; return *this;} } d_t; #define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; } #define deb(X ...) dbg(#X, "=", X); #define EPS (1e-10) #define INF (1LL<<61) #define YES(x) cout << (x ? "YES" : "NO") << endl; #define CL(A,I) (memset(A,I,sizeof(A))) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() const ll MOD = 998244353; int main(void) { ios_base::sync_with_stdio(false); ll n; cin >> n; vll a(n); F(n) cin >> a[i]; sort(all(a)); ll ret = 0; ll p = 0; F(n) { ret += a[i]*a[i]; ret %= MOD; ret += (p*a[i])%MOD; ret %= MOD; p *= 2; p += a[i]; p %= MOD; } cout << ret << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cout << #x << ": " << x << '\n'; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20); #endif int n, L; cin >> n >> L; vector <int> a(n + 2), b(n + 1); a[n + 1] = L + 1; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) cin >> b[i]; map <int, int> l, r; for (int i = 0; i <= n + 1; ++i) { if (!l.count(a[i] - i)) { l[a[i] - i] = i; } r[a[i] - i] = i; } vector <int> link(n + 1); int ans = 0; for (int i = 1; i <= n; ++i) { if (a[i] == b[i]) { link[i] = -1; } else if (b[i] < a[i]) { if (!r.count(b[i] - i)) { cout << -1 << endl; exit(0); } link[i] = r[b[i] - i]; } else { if (!l.count(b[i] - i)) { cout << -1 << endl; exit(0); } link[i] = l[b[i] - i]; } } #ifdef HOME for (int i = 1; i <= n; ++i) { cout << link[i] << ' '; } cout << endl; #endif int mx = 0; for (int i = 1; i <= n; ++i) { if (link[i] != -1 && link[i] > i) { if (link[i] < mx) { cout << -1 << endl; exit(0); } if (link[i] > mx) { ans += link[i] - i; mx = link[i]; } } } #ifdef HOME cout << "right ok" << endl; debug(ans); #endif const int INF = 1e18; int mn = INF; for (int i = n; i; --i) { if (link[i] != -1 && link[i] < i) { if (link[i] > mn) { cout << -1 << endl; exit(0); } if (link[i] < mn) { ans += i - link[i]; mn = link[i]; } } } cout << ans << endl; }
#include<bits/stdc++.h> #define pb emplace_back #define AI(i) begin(i), end(i) using namespace std; using ll = long long; #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] = ", args) void kout() {cerr << endl;} template<class T1, class ...T2> void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); } template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; } #else #define DE(...) 0 #define debug(...) 0 #endif const int MAX_N = 300010; int n, L, a[MAX_N], b[MAX_N], c[MAX_N], d[MAX_N]; ll solve() { for (int i = 1;i <= n;++i) { c[i] = a[i] - a[i-1] - 1; d[i] = b[i] - b[i-1] - 1; } ll res = 0; for (int i = 1, j = 1;i <= n;++i) { if (d[i] == 0) continue; while (!c[j]) ++j; int k = j, sum = 0; while (sum < d[i]) { assert(k <= n); sum += c[k++]; } if (sum != d[i]) return -1; res += max(0, k-i-1) + max(0, i-j); j = k; } return res; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> L; for (int i = 1;i <= n;++i) cin >> a[i]; for (int i = 1;i <= n;++i) cin >> b[i]; a[n+1] = b[n+1] = L+1, ++n; cout << solve() << '\n'; }
#pragma GCC target("avx2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<double> vd; typedef pair<ll,ll> P; typedef pair<int,int> pii; typedef vector<P> vpl; typedef tuple<ll,ll,ll> tapu; #define rep(i,n) for(int i=0; i<(n); i++) #define REP(i,a,b) for(int i=(a); i<(b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = (1<<30) - 1; const ll linf = 1LL<<61; const int MAX = 510000; int dy[8] = {0,1,0,-1,1,-1,-1,1}; int dx[8] = {-1,0,1,0,1,-1,1,-1}; const double pi = acos(-1); const double eps = 1e-7; template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){ if(a>b){ a = b; return true; } else return false; } template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){ if(a<b){ a = b; return true; } else return false; } template<typename T> inline void print(T &a){ int sz = a.size(); for(auto itr = a.begin(); itr != a.end(); itr++){ cout << *itr; sz--; if(sz) cout << " "; } cout << "\n"; } template<typename T1,typename T2> inline void print2(T1 a, T2 b){ cout << a << " " << b << "\n"; } template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){ cout << a << " " << b << " " << c << "\n"; } void mark() {cout << "#" << "\n";} ll pcount(ll x) {return __builtin_popcountll(x);} //const int mod = 1e9 + 7; const int mod = 998244353; int main(){ int n; cin >> n; rep(i,n) cout << i/2+1 << " " << (i+n)/2+1 << "\n"; }
#include <bits/stdc++.h> #define For(i,l,r) for (register int i=l; i<=r; i++) using namespace std; typedef unsigned long long LL; typedef signed long long ll; template <typename T> inline void read(T &x) { char c = getchar(); int w = 1; x = 0; while (!isdigit(c)) (c == '-') && (w = -w), c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar(); x *= w; } ll n, k; signed main() { read(n); read(k); for (register int i=1; i<=k; ++i) { if (n % 200 == 0) { n /= 200; } else n = n*1000+200; } cout << n; getchar(); return 0; }
//Keep calm and carry on.. /* Problem : URL : Memory Limit: 1024 MB Time Limit: 2000 ms Powered by CP Editor (https://github.com/cpeditor/cpeditor) */ #include<bits/stdc++.h> //#include <boost/math/common_factor.hpp> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; # define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL); # define pi 3.1415926535897932384626 # define mod 1000000007 # define pb push_back # define all(v) v.begin(), v.end() # define rall(v) v.rbegin(), v.rend() # define F first # define S second # define mk make_pair # define loop1(i,a,b) for(ll i = a; i<b; i++) # define loop2(i,a,b) for(ll i = b-1; i>=a; i--) # define endl '\n' # define DEBUG false # define sz(x) (int)x.size() # define mem(a, val) memset(a, val, sizeof(a)) # define deci(x) cout << fixed << setprecision(x); # define bitcount(x) __builtin_popcountll(x) # pragma GCC optimize "trapv" typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; const int dx[8] = { -1, -1, -1, 0, 1, 1, 1, 0}; const int dy[8] = { -1, 0, 1, 1, 1, 0, -1, -1}; const long double EPS = 1e-12; const int N = 1e5 + 20; int countDigit(ll n) { return floor(log10(n) + 1); } int sumDigits(int no) { return no == 0 ? 0 : no % 10 + sumDigits(no / 10) ; } // // void reverse(int n, int &rev) { // base case if (n == 0) { return; } rev = rev * 10 + (n % 10); reverse(n / 10, rev); } int isPalindrome(int num) { int rev = 0; // reverse `num` and store it in `rev` reverse(num, rev); // if the given number is equal to its reverse, // then the number is a palindrome return (num == rev); } // // void soln() { //cout << "Case #" << ks << ": " << abs(k - cnt); } int main() { fast; ll n; cin >> n; if (n < 12){ cout << "Yes"; return 0; } while (n % 10 == 0){ n /= 10; } if (n < 12) cout << "Yes"; else if (isPalindrome(n)) cout << "Yes"; else cout << "No"; return 0; }
#include<iostream> #include<bits/stdc++.h> #include<string> #include<vector> using namespace std; using ll= long long; int main() { string t; cin>>t; int count=0; int n=t.length(); int k=stoi(t); int flag=1; for(int i=0;i<n;i++) { if(k%10==0) { count++; k=k/10; } else { break; } } for(int i=0;i<n-count;i++) { if(t[i]!=t[n-i-1-count]) { flag=0; break; } else { flag++; } } if(flag!=0) { cout<<"Yes"; } else { cout<<"No"; } }
#include<iostream> #include<cstdio> using namespace std; const int N=200005; int n,m,Q; int a[N],b[N]; struct Segment_Tree { struct Node { int ls,rs; int cnt; long long sum; }tree[N*20]; int rt,tot; void modifycnt(int &i,int l,int r,int pos,int val) { if(!i) i=++tot; if(l==r) { tree[i].cnt+=val; return; } int mid=(l+r)/2; if(pos<=mid) modifycnt(tree[i].ls,l,mid,pos,val); else modifycnt(tree[i].rs,mid+1,r,pos,val); tree[i].cnt=tree[tree[i].ls].cnt+tree[tree[i].rs].cnt; return; } void modifysum(int &i,int l,int r,int pos,int val) { if(!i) i=++tot; if(l==r) { tree[i].sum+=val; return; } int mid=(l+r)/2; if(pos<=mid) modifysum(tree[i].ls,l,mid,pos,val); else modifysum(tree[i].rs,mid+1,r,pos,val); tree[i].sum=tree[tree[i].ls].sum+tree[tree[i].rs].sum; return; } int querycnt(int i,int l,int r,int L,int R) { if(!i) return 0; if(L<=l&&r<=R) return tree[i].cnt; int mid=(l+r)/2; int res=0; if(L<=r) res+=querycnt(tree[i].ls,l,mid,L,R); if(R>=l) res+=querycnt(tree[i].rs,mid+1,r,L,R); return res; } long long querysum(int i,int l,int r,int L,int R) { if(!i) return 0; if(L<=l&&r<=R) return tree[i].sum; int mid=(l+r)/2; long long res=0; if(L<=r) res+=querysum(tree[i].ls,l,mid,L,R); if(R>=l) res+=querysum(tree[i].rs,mid+1,r,L,R); return res; } }TA,TB; int main() { scanf("%d%d%d",&n,&m,&Q); TA.modifycnt(TA.rt,1,1e8,0,n); TB.modifycnt(TB.rt,1,1e8,0,m); long long ans=0; while(Q--) { int t,x,y; scanf("%d%d%d",&t,&x,&y); if(t==1) { TA.modifycnt(TA.rt,1,1e8,a[x],-1); TA.modifysum(TA.rt,1,1e8,a[x],-a[x]); TA.modifycnt(TA.rt,1,1e8,y,1); TA.modifysum(TA.rt,1,1e8,y,y); ans-=1LL*TB.querycnt(TB.rt,1,1e8,1,a[x])*a[x]+TB.querysum(TB.rt,1,1e8,a[x]+1,1e8); ans+=1LL*TB.querycnt(TB.rt,1,1e8,1,y)*y+TB.querysum(TB.rt,1,1e8,y+1,1e8); a[x]=y; } else if(t==2) { TB.modifycnt(TB.rt,1,1e8,b[x],-1); TB.modifysum(TB.rt,1,1e8,b[x],-b[x]); TB.modifycnt(TB.rt,1,1e8,y,1); TB.modifysum(TB.rt,1,1e8,y,y); // cerr<<"del"<<ans<<" "<<1LL*TA.querycnt(TA.rt,1,1e8,1,b[x])*b[x]-TA.querysum(TA.rt,1,1e8,b[x]+1,1e8)<<" "<<1LL*TA.querycnt(TA.rt,1,1e8,1,y)*y-TA.querysum(TA.rt,1,1e8,y+1,1e8)<<"\n"; ans-=1LL*TA.querycnt(TA.rt,1,1e8,1,b[x])*b[x]+TA.querysum(TA.rt,1,1e8,b[x]+1,1e8); ans+=1LL*TA.querycnt(TA.rt,1,1e8,1,y)*y+TA.querysum(TA.rt,1,1e8,y+1,1e8); b[x]=y; } printf("%lld\n",ans); } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; //#define ACL #ifdef ACL #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif #if __has_include("acl-all.h") #include "acl-all.h" //on Wandbox using namespace atcoder; #endif #endif //#ifdef ACL typedef long double ld; typedef long long int ll; typedef unsigned long long int ull; typedef vector<int> vi; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vll; typedef vector<pair<ll, ll> > vpll; typedef vector<vector<int> > vvi; typedef vector<vector<char> > vvc; typedef vector<vector<string> > vvs; typedef vector<vector<ll> > vvll; typedef vector<vector<bool> > vvb; typedef pair<ll, ll> pll; #define rep(i, n) for (int i = 0; i < int(n); ++i) #define rrep(i, n) for (int i = 1; i <= int(n); ++i) #define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++) #define drep(i, n) for (int i = int(n)-1; i >= 0; --i) #define MES(a) MES2 a #define MES2(a0,a1,a2,a3,a4,x,...) x #define mes_1(x1) cout<<x1<<endl #define mes_2(x1,x2) cout<<x1<<" "<<x2<<endl #define mes_3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<endl #define mes_4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl #define mes_5(x1,x2,x3,x4,x5) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<endl #define mes(...) CHOOSE((__VA_ARGS__,mes_5,mes_4,mes_3,mes_2,mes_1,~))(__VA_ARGS__) #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #define Ynmes(a) (a) ? mes("Yes") : mes("No") #define YNmes(a) (a) ? mes("YES") : mes("NO") #define re0 return 0 #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define Sort(a) sort(a.begin(), a.end()) #define rSort(a) sort(a.rbegin(), a.rend()) #define Rev(a) reverse(a.begin(), a.end()) int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 }; int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 }; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } }; const int INF = INT_MAX; const ll LLINF = 1LL << 60; const ll MOD = 1000000007; const double EPS = 1e-9; ll fact_mod(ll n, ll mod) { ll f = 1; for (ll i = 2; i <= n; i++) f = f * (i % mod) % mod; return f; } ll modpow(ll x, ll n, ll mod) { if(n == 0) return 1; ll res = modpow((x * x) % mod, n / 2 , mod); if(n & 1) res = (res * x) % mod; return res; } ll modncr(ll n, ll r, ll mod) { if(r > n-r) r = n-r; if(r == 0) return 1; ll a = 1; rep(i, r) a = a * ((n-i) % mod) % mod; ll b = modpow(fact_mod(r, mod), mod-2, mod); return (a % mod) * (b % mod) % mod; } signed main() { ll a, b, c; cin >> a >> b >> c; mes(21-a-b-c); }
#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> #include<utility> #include<map> using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 1'000'000'007; struct fast_io { fast_io(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; signed main(){ cout<<fixed<<setprecision(10); int N; int ans = 0; vector<int> A; map<int,int> mp; cin>>N; A.resize(N); for(int i = 0; i < N; i++){ cin>>A[i]; if(i%2 == 0) A[i] *= -1; } mp[0] = 1; for(int i = 0, sum = 0; i < N; i++){ sum += A[i]; ans += mp[sum]; // cout<<"sum = "<<sum<<" += "<<A[i]<<" "<<mp[sum]<<endl; mp[sum]++; } cout<<ans<<endl; return 0; }
#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <set> #include <map> #include <cmath> #include <list> #include <ctime> #include <sstream> #include <queue> #include <stack> #include <random> #include <bitset> #include <numeric> #include <cassert> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define rep(x, b, e) for(int x=(b); x<(e); ++x) #define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x) #define all(c) c.begin(),c.end() #define sz(x) ((int)((x).size())) #define pb push_back #define st first #define nd second #define mp(x,y) make_pair(x,y) typedef short int sint; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vi a(n + 1); map<ll, int> wys; ll suma = 0; ll res = 0; wys[0] = 1; rep(i, 0, n) { cin >> a[i]; if ((i&1) == 0) { suma += a[i]; } else { suma -= a[i]; } // printf("suma is :%d, adding: %d\n", suma, wys[suma]); res += wys[suma]; ++wys[suma]; } cout << res << endl; }
#include <cstring> #include <cmath> #include <algorithm> #include <string> #include <map> #include <iostream> #include <vector> #include <queue> #include <unordered_map> #include <random> #include <stack> #include <set> #include <unordered_set> #define bug(x) cout<<"zdongdebug1: "<<x<<endl; #define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl; #define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl; using namespace std; typedef long long ll; const int maxn = 105; const int mod = 998244353; int main() { #ifdef suiyuan2009 freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin); //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout); #endif string s, t; cin>>s>>t; if(s[0]=='N')cout<<t<<endl; else { cout<<char(t[0] - 'a' + 'A')<<endl; } return 0; }
#include <bits/stdc++.h> int main() { std::string S, Y; std::cin >> S >> Y; if (S == "Y") { Y[0] = std::toupper(Y[0]); } std::cout << Y << std::endl; }
#include <bits/stdc++.h> const int N = 400010; int n, C[3][3]; char str[N]; int Lucas(int n, int m) { if (!n || !m) return 1; return 1ll * Lucas(n / 3, m / 3) * C[n % 3][m % 3] % 3; } int main() { scanf("%d", &n); scanf("%s", str); C[0][0] = 1; C[1][0] = C[1][1] = 1; C[2][0] = 1; C[2][1] = 2; C[2][2] = 1; int ans = 0; for (int i = 0; i < n; i ++) { int t; if (str[i] == 'W') t = 0; else if (str[i] == 'B') t = 1; else t = 2; ans = (ans + 1ll * Lucas(n - 1, i) * t % 3) % 3; } if (n % 2 == 0) ans = (-ans + 3) % 3; if (!ans) puts("W"); else if(ans == 1) puts("B"); else puts("R"); return 0; }
#include<bits/stdc++.h> using namespace std; #define arep(i,x,n) for(int i=int(x);i<(int)(n);i++) #define rep(i,n) for(int i = 0;i < n;++i) #define rrep(i,n) for(int i=int(n-1);i>=0;i--) #define fs first #define sc second #define all(x) (x).begin(), (x).end() #define rall(x) (x).begin(), (x).end() #define coy cout<<"Yes"<<endl #define con cout<<"No"<<endl #define pi 3.141592653589793 #define eps 0.00000001 #define INF 1e9+7 #define LINF 1e18+10 using ll = long long; using P = pair<int, int>; using lP = pair<ll, ll>; using fP = pair<double, double>; using PPI = pair<P, int>; using PIP = pair<int, P>; using Ps = pair<int, string>; using vi = vector<int>; using vl = vector<ll>; using vc = vector<char>; using vd = vector<double>; using vs = vector<string>; using vp = vector<P>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; using vvd = vector<vector<double>>; using vvc = vector<vector<char>>; using vvp = vector<vector<P>>; using vvb = vector<vector<bool>>; template <typename T> bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; } //const ll mod=998244353; const ll mod = 1e9 + 7; const ll MAX = 100; template <typename T> T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error ////////////////////////////////////// int main(){ int t; cin>>t; vl res; rep(i,t){ ll l,r; cin>>l>>r; ll ans=max((ll)0,(r-2*l+1)*(r-2*l+2)/2); if(r-2*l+1<0)ans=0; res.push_back(ans); } for(auto x:res)cout<<x<<endl; return 0; }
#include <iostream> #include <vector> #include <utility> #include <string> #include <algorithm> #include <unordered_map> #include <numeric> #define fore(i, l, r) for(int i = int(l); i < int(r); i++) //Python style baby #define sz(a) int((a).size()) #define mp make_pair #define pb push_back #define vi vector<int> #define vpi vector<pair<int, int>> #define vl vector<long long> #define vpl vector<pair<long long, long long>> using namespace std; using ll = long long; int mode, t; const int N = 101; int total(vpi &queries, vpi &choices, int k, int code) { int hits[N] = {}; fore (i, 0, k) { if (code & 1) { hits[choices[i].first]++; } else { hits[choices[i].second]++; } code /= 2; } int ans = 0; for (auto ab : queries) { if (hits[ab.first] > 0 && hits[ab.second] > 0) { ans++; } } return ans; } void solve() { int n, m; cin >> n >> m; vpi queries; int a, b; fore (i, 0, m) { cin >> a >> b; queries.pb(mp(a,b)); } int k; cin >> k; vpi choices; fore (i, 0, k) { cin >> a >> b; choices.pb(mp(a,b)); } int ans = 0; fore (i, 0, 1<<k) { ans = max(ans, total(queries, choices, k, i)); } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); mode = 0; if (mode == 0) { solve(); } else { cin >> t; while (t--) { solve(); } } }
# include <bits/stdc++.h> # pragma GCC optimize("Ofast") # pragma GCC target("avx,avx2,fma") using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; int n; int q; cin >> n; cin >> s; cin >> q; int t, a, b; int start = 0; while(q--){ cin >> t >> a >> b; --a; --b; if(t == 1){ if(start){ a += (start); b += (start); } swap(s[a % (2*n)], s[b % (2*n)]); } else { start = (start == n) ? 0 : n; } } if(!start){ cout << s; return 0; } for(int i = start; i < s.size(); ++i){ cout << s[i]; } for(int i = 0; i < start; ++i){ cout << s[i]; } return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; namespace IO{ inline char ch(){ static char s[1<<16],*S,*T; return (S == T)&&(T = (S = s)+ fread(s,1,1<<16,stdin),S == T)?EOF:*S++; } template<typename T> void read(T &x){ x = 0; int f(1); char c = ch(); for(;!isdigit(c);c = ch()) if(c == '-') f = -1; for(;isdigit(c);c = ch()) x = x*10+c-'0'; x *= f; } template<typename T,typename... Args> inline void read(T &x,Args&... args){ read(x); read(args...); } template<typename T> void write(T x,char f = '\n'){ if(x < 0) putchar('-'),x = -x; if(x > 9) write(x/10,'\0'); putchar('0'+x%10); if(f != '\0') putchar(f); } } using namespace IO; const int maxn = 103; int n; ll A[maxn],X; ll dp[2][maxn][maxn]; int main(){ #ifdef LZX_CAI freopen("test.in","r",stdin); freopen("test.out","w",stdout); #endif read(n,X); for(int i(1);i <= n;++i) read(A[i]); ll Ans = 1e18; for(int d(1);d <= n;++d){ int x = X%d; for(int i(0);i <= d;++i) for(int j(0);j < d;++j) dp[0][i][j] = -1e14; dp[0][0][0] = 0; for(int i(1);i <= n;++i){ int nw = (i&1); for(int i(0);i <= min(i,d);++i) for(int j(0);j < d;++j) dp[nw][i][j] = -1e14; for(int j(0);j <= min(i,d);++j) for(int k(0);k < d;++k){ int x = A[i]%d; if(j > 0) dp[nw][j][k] = max(dp[nw][j][k],dp[nw^1][j-1][(k-x+d)%d]+A[i]); dp[nw][j][k] = max(dp[nw][j][k],dp[nw^1][j][k]); } } if(dp[n&1][d][x] > 0){ ll tm = (X-dp[n&1][d][x])/d; Ans = min(Ans,tm); } } cout << Ans << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <numeric> #include <utility> #include <tuple> #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; } template<typename T> void print(T a) { cout << a << '\n'; } template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on template<ll MOD = 1000000007> class ModInt { ll n; ModInt constexpr inverse() const { return ModInt::pow(*this, MOD - 2); } public: ModInt() : n(0) {} ModInt(ll _n) : n(((_n % MOD) + MOD) % MOD) {} ModInt operator+=(const ModInt &m) { n += m.n; if (n >= MOD) n -= MOD; return *this; } ModInt operator-=(const ModInt &m) { n -= m.n; if (n < 0) n += MOD; return *this; } ModInt operator*=(const ModInt &m) { n *= m.n; if (n >= MOD) n %= MOD; return *this; } ModInt operator/=(const ModInt &m) { (*this) *= m.inverse(); return *this; } friend ModInt operator+(ModInt t, const ModInt &m) { return t += m; } friend ModInt operator-(ModInt t, const ModInt &m) { return t -= m; } friend ModInt operator*(ModInt t, const ModInt &m) { return t *= m; } friend ModInt operator/(ModInt t, const ModInt &m) { return t /= m; } ModInt operator=(const ll l) { n = l % MOD; if (n < 0) n += MOD; return *this; } friend ostream &operator<<(ostream &out, const ModInt &m) { out << m.n; return out; } friend istream &operator>>(istream &in, ModInt &m) { ll l; in >> l; m = l; return in; } static constexpr ModInt pow(const ModInt x, ll p) { ModInt<MOD> ans = 1; for (ModInt<MOD> m = x; p > 0; p /= 2, m *= m) { if (p % 2) ans *= m; } return ans; } }; using mint = ModInt<998244353>; mint operator"" _m(unsigned long long m) { return mint(m); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m, k; cin, n, m, k; mint ans = 0; if (n == 1 || m == 1) { print(mint::pow(k, m * n)); return 0; } rep(i, 0, k) { mint a = mint::pow(k - i, m) - mint::pow(k - i - 1, m); ans += a * mint::pow(i + 1, n); // dump(ans, a); } print(ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define vi vector<int> #define rep(i,a,b) for(int i=a;i<b;i++) #define sz(a) a.size() #define all(v) (v.begin(),v.end()); #define pb push_back #define int long long void solve() { int n; cin >> n; vi v(n); map<int, int> m; rep(i, 0, n) { cin >> v[i]; m[v[i]]++; } int tot = n * (n - 1) / 2; for (auto x : m) { int temp = x.second; if (temp > 1) { tot -= (temp * (temp - 1) / 2); } } cout << tot << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif solve(); }
#include <bits/stdc++.h> #include <bits/extc++.h> #define sz(v) int (v.size()) #define ff first #define ss second #define pb push_back #define int long long #define all(a) a.begin(),a.end() typedef long long ll; typedef long double ld; using namespace std; using namespace __gnu_cxx; using namespace __gnu_pbds; template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int MOD = 1000000009; mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count()); double GetTime() { return clock() / (double) CLOCKS_PER_SEC; }; /// Actual code starts here int n; const int N = 100005; void solve() { cin >> n; int res = 0; vector<int> v(n); for (auto &i : v) cin >> i; map<int, int> cnt; for (int i = 0; i < n; i++) { cnt[v[i]]++; res += i - cnt[v[i]] + 1; } cout << res; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // freopen("input.txt", "r", stdin); int tt = 1; //cin >> tt; while (tt--) solve(); }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll=long long; using ld=long double; using pll=pair<ll, ll>; //using mint = modint1000000007; #define rep(i,n) for (ll i=0; i<n; ++i) #define all(c) begin(c),end(c) #define PI acos(-1) #define oo 2e18 template<typename T1, typename T2> bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;} template<typename T1, typename T2> bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} //priority_queue<ll, vector<ll>, greater<ll>> Q; /* */ vector<vector<ll>> G(100010); bool used[100010]; ll C[100010]; ll D[100010]; vector<ll> ans; void dfs(ll v){ used[v] = true; ll col = C[v]; if (!D[col]) ans.push_back(v+1); D[col]++; for(auto nv: G[v]){ if (used[nv]) continue; dfs(nv); } D[col]--; } int main(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); ll N; cin >> N; rep(i, N) cin >> C[i]; rep(i, N-1){ ll a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } dfs(0); sort(all(ans)); for(auto v: ans) cout << v << endl; }
#include <bits/stdc++.h> using namespace std; #define LL long long const int M=1e5+5,P=1e9+7,base=269; const long double e=1e-10; inline int rd(){ int x=0;char c=getchar(); while(!isdigit(c))c=getchar(); while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x; } int K,n,m,p[M],ans[M]; long double A[M],B[M],C[M]; bool cmp(int x,int y){ return C[x]>C[y]+e; } int main(){ K=rd(),n=rd(),m=rd(); int t=m; for(int i=1;i<=K;++i){ A[i]=rd();p[i]=i; B[i]=A[i]/n*m; int tmp=B[i]; t-=tmp; C[i]=B[i]-tmp; ans[i]=tmp; } sort(p+1,p+K+1,cmp); for(int i=1;i<=t;++i){ ans[p[i]]++; } for(int i=1;i<=K;++i){ printf("%d ",ans[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long namespace math{ const int MOD = 1e9+7; const int MN = 10'100; int fact[MN], inv_fact[MN]; int power(int a, int n) { int res = 1; for (;n; n >>= 1, a = (a * a) % MOD) if (n & 1) res = (res * a) % MOD; return res; } int inv(int a) { return inv_fact[a]*fact[a-1]%MOD; } void init_fact() { fact[0]=1; for (int i=1;i<MN;++i) fact[i] = fact[i-1]*i%MOD; inv_fact[MN-1] = power(fact[MN-1], MOD - 2); for (int i=MN-1; i>0;--i) inv_fact[i-1]=inv_fact[i]*i%MOD; } struct mint { int n; mint(int n): n(n){} mint(): n(0){} mint operator+(mint o){return (n + o.n) % MOD;} mint operator-(mint o){return (n - o.n % MOD + MOD) % MOD;} mint operator*(mint o){return (n * o.n) % MOD;} mint operator/(mint o){return o.n >= MN ? n * power(o.n, MOD - 2) % MOD : n * inv(o.n) % MOD;} }; }; using namespace math; using mat = vector<vector<mint>>; int n, m, k; vector<int> g[100]; mat M; mat operator*(mat A, mat B) { mat ret(A.size(), vector<mint>(B[0].size())); for (int i = 0; i < A.size(); ++i) { for (int j = 0; j < B[0].size(); ++j) { for (int k = 0; k < B.size(); ++k) ret[i][j] = ret[i][j] + A[i][k] * B[k][j]; } } return ret; } mat power(mat A, int n) { mat ret(A.size(), vector<mint>(A.size())); for (int i = 0; i < A.size(); ++i) ret[i][i] = 1; for (; n; A = A * A, n >>= 1) { if (n & 1) ret = ret * A; } return ret; } signed main() { cin.tie(0)->sync_with_stdio(false); cin>>n>>m>>k; M.resize(n, vector<mint>(n)); mat A(1, vector<mint>(n)); for (int i = 0; i< n;++i) cin>>A[0][i].n; for (int i = 0; i<m;++i) { int u, v; cin>>u>>v; --u, --v; g[u].push_back(v); g[v].push_back(u); } init_fact(); for (int i = 0; i < n;++i) { M[i][i] = mint(1) - mint(g[i].size()) / m / 2; for (int it: g[i]) { M[it][i] = mint(1) / m / 2; } } mat Ans = A * power(M, k); for (int i = 0; i<n;++i) cout << Ans[0][i].n << '\n'; return 0; }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} ll mod_pow(ll x,ll n){ x%=MOD; ll res=1; while(n>0){ if(n&1) res=res*x%MOD; x=x*x%MOD; n>>=1; } return res; } ll mod_inverse(ll x){ return mod_pow(x,MOD-2); } void add(ll &a,ll b){ a=(a+b)%MOD; } void mul(ll &a,ll b){ a%=MOD;b%=MOD; a=a*b%MOD; } typedef vector<ll> vec; typedef vector<vec> mat; mat mul(mat &A,mat &B){ mat C(A.size(),vec(B[0].size())); for(int i=0;i<A.size();i++){ for(int k=0;k<B.size();k++){ for(int j=0;j<B[0].size();j++){ C[i][j]=(C[i][j]+(A[i][k]*B[k][j])%MOD)%MOD; } } } return C; } // C=pow(A,n) mat pow(mat A,ll n){ mat B(A.size(),vec(A.size())); for(int i=0;i<A.size();i++){ B[i][i]=1; } while(n>0){ if(n&1) B=mul(B,A); A=mul(A,A); n=(n>>1); } return B; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,M,K; cin>>N>>M>>K; vector<ll> A(N); rep(i,N) cin>>A[i]; vector<int> X(M),Y(M); rep(i,M) cin>>X[i]>>Y[i]; rep(i,M) X[i]--,Y[i]--; vector<vector<int>> g(N); rep(i,M){ g[X[i]].push_back(Y[i]); g[Y[i]].push_back(X[i]); } mat P(N,vec(N,0)); for(int i=0;i<N;i++){ int deg=g[i].size(); ll inv=mod_inverse(M); { ll coef=M-deg; mul(coef,inv); add(P[i][i],coef); } { ll coef=deg; mul(coef,inv); mul(coef,mod_inverse(2)); add(P[i][i],coef); mul(coef,mod_inverse(deg)); for(auto n:g[i]){ add(P[i][n],coef); } } } mat C=pow(P,K); mat B(N,vec(1,0)); rep(i,N) B[i][0]=A[i]; B=mul(C,B); rep(i,N) cout<<B[i][0]<<"\n"; return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <string> #include <set> #include <queue> #include <cmath> #include <algorithm> #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() typedef long long ll; using P = pair<int,int>; #define INF 1001001001 #define LINF (1LL<<60) #define F first #define S second template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; } int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; sort(all(a)); bool ans = true; rep(i, n) { if (a[i] != i+1) ans = false; } if (ans) puts("Yes"); else puts("No"); }
/** * \author KienNguyen246 * \date 01/06/2021 */ ///😭😢😞☹🙁😐🙂☺😊😁😀😆😂🤣 ///----------------🤔🤔🤔 -----------------/// /**< 🤣🤣🤣 */ #include <bits/stdc++.h> ///TLE (in case of emergency) #define TLE 0 #if TLE #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #endif // TLE #define NOT_INTERACTIVE 1 using namespace std; typedef long long ll; //typedef double db; typedef pair <int, int> pii; typedef pair <ll, ll> pll; //const int maxn = 5005; const int maxn = 5e5 + 7; const int mod = 1e9 + 7; const int infi = (2e9 + 69); const ll infy = (2e16 + 69); const int base = 311; const ll MM = 7ll * mod * mod; const int addition = 1e5; const double eps = 1e-8; const string numd[10] = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"}; const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, 1, -1}; const double pi = 3.14159265358980; const string P1 = "ALICE"; const string P2 = "BOB"; const string spmcode = "My power does not end. Ask for aid and you will receive it.\n"; template <typename Num> void maximize (Num &x, Num y) {x = mx (x, y);} template <typename Num> void minimize (Num &x, Num y) {x = min (x, y);} void exit_with_runtime() {double x = 1.0 * clock() / CLOCKS_PER_SEC; cerr << "\n\n---------------------\nTime elapsed: " << x << " s.\n\n"; exit (0);} void decorate() {cerr << "KienNguyen246\n"; chrono:: system_clock::time_point today = chrono::system_clock::now(); time_t tt = chrono::system_clock::to_time_t (today); cerr << ctime (&tt); cerr << "\nProcessing...\n\n";} ///Multiple tests? #define MUL_TEST 0 /**< 🤣🤣🤣 */ //bool Palin(string s) {string r = s; reverse(whole(r)); return (r == s);} /* 🙃🙃🙃 */ int n, a[maxn], cnt[maxn]; //My power does not end. Ask for aid and you will receive it. void Main_Process() { cin >> n; for (int i = 1; i <= n; i ++) { cin >> a[i]; cnt[a[i]] ++; if (cnt[a[i]] == 2) { cout << "No"; return; } } cout << "Yes"; } /**< 😂😂😂 */ int main() { /**< Main preprocessing begin */ ios_base::sync_with_stdio (0); #if NOT_INTERACTIVE cin.tie(0); cout.tie(0); decorate(); #ifndef ONLINE_JUDGE freopen(".inp", "r", stdin); // freopen(".out", "w", stdout); #endif #endif /**< Main preprocessing end */ /*😍😍😍*/ int test = 1; // Prepare(); #if MUL_TEST cin >> test; #endif while (test --) { Main_Process(); } exit_with_runtime(); } /**< 😂😂😂 */ ///😂😂😂😂😂😂😂😂🌚🔥😂😂😂😂🌚🔥😂😂🔥😂😂😂🔥😂😂😂🔥😂💯💯💯💯💩🐸🔥😂🔥😂🔥💩🔥🔥😂🌚💯🐸💯💩🐸🔥🔥💞🔥💩💩💩💞😂😂😂😂😂😂😂💞💞😂😂😂💞🔥🔥💞💯💩💞💯💞😂😂😂💞💩💩💩💩💩💩💞💩💩💩💩💩💩💩💩💞🔥🔥😂💞🔥😂😂💞
/* Saturday 29 May 2021 05:32:07 PM IST @uthor::astrainL3gi0N */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef std::vector<int> vi; typedef std::pair<int,int> ii; typedef std::vector<ii> vii; typedef std::vector<ll> vl; #define pb push_back #define mp make_pair #define debg(x) std::cerr<<(#x)<<" => "<<x<<'\n'; #define debgg(x,y) std::cerr<<(#x)<<" => "<<x<<'\t'<<(#y)<<' '<<y<<'\n'; #define len(a) (int)(a).size() #define all(x) x.begin(),x.end() const int mod = 1000000007; //const int mod = 998244353; bool comp (ii x, ii y) { if (x.second == y.second) return x.first < y.first; return x.second < y.second; } template < typename T> void printv (T &a) { cout<<'\n'; for (auto it = a.begin(); it != a.end(); ++it) cout<<it->first<<' '<<it->second<<'\n'; } int gint() { int n; cin>>n; return n; } //int t[510][510]; ll ans; void solve () { map <ii,int> hmp; int n = gint(); vii vpr; vii arr; for (int i = 0; i < n;++i) { int x = gint(); int y = gint(); vpr.pb(mp(x,y)); hmp[mp(x,y)] = i+1; } for (auto v:vpr) { arr.pb(mp(v.first,v.second)); } vi vr; set <int> hsh; sort(all(vpr)); hsh.insert(hmp[vpr[0]]); hsh.insert(hmp[vpr[1]]); hsh.insert(hmp[vpr[n-1]]); hsh.insert(hmp[vpr[n-2]]); for (auto &v: vpr) { swap(v.first,v.second); } sort(all(vpr)); hsh.insert(hmp[mp(vpr[0].second,vpr[0].first)]); hsh.insert(hmp[mp(vpr[1].second,vpr[1].first)]); hsh.insert(hmp[mp(vpr[n-1].second,vpr[n-1].first)]); hsh.insert(hmp[mp(vpr[n-2].second,vpr[n-2].first)]); for (auto &v: vpr) { swap(v.first,v.second); } vii vrr; for (auto v: arr) { if (hsh.count(hmp[v])) vrr.pb(v); } for (int i = 0; i < len(vrr); ++i) { for (int j = i+1; j < len(vrr); ++j) { vr.pb(max(abs(vrr[i].first-vrr[j].first), abs(vrr[i].second-vrr[j].second))); } } sort(all(vr)); cout<<vr[len(vr)-2]; } void sol () { //test //cout << setprecision(15) << fixed; } int main () { int testcases = 1; for (int t = 0; t < testcases; ++t) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n, m) for (ll i = (n); i < (ll)(m); i++) template <typename T> vector<vector<T> > binomial_table(int N) { vector<vector<T> > mat(N + 1, vector<T>(N + 1)); for (int i = 0; i <= N; i++) { for (int j = 0; j <= i; j++) { if (j == 0 || j == i) mat[i][j] = 1; else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j]; } } return mat; } int main() { auto c = binomial_table<ll>(61); ll a, b; cin >> a >> b; ll k; cin >> k; string ans; ll n = a + b; rep(i, 0, n) { if (a > 0 && c[a + b - 1][b] >= k) { ans += 'a'; a--; } else { k -= c[a + b - 1][b]; ans += 'b'; b--; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long // #include <atcoder/all> // using namespace atcoder; // using mint = modint1000000007; using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) constexpr int MOD = 998244353; constexpr int INF = numeric_limits<int>::max() / 2; typedef pair<int,int> P; using Graph = vector<vector<int>>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long double PI = acos(-1.0); // cout << fixed << setprecision(14); int modpow(int x, int n, int mod) { int res = 1; while (n > 0) { if (n & 1) { // nが奇数のとき res *= x; res %= mod; } x *= x; x %= mod; n >>= 1; } return res; } signed main() { int N, M, K; cin >> N >> M >> K; if(N==1 && M==1){ cout << K << endl; return 0; } if(N==1){ cout << modpow(K,M,MOD) << endl; return 0; } if(M==1){ cout << modpow(K,N,MOD) << endl; return 0; } int ans = 0; int mi[K+2]{}, ma[K+2]{}; int mis[K+2]{}, mas[K+2]{}; for(int i=1;i<=K;i++){ int miZ = modpow(i,N,MOD); mi[i] = (miZ + MOD - mi[i-1]) % MOD; } for(int i=K;i>=1;i--){ int maZ = modpow((K-i+1), M, MOD); ma[i] = (maZ + MOD - ma[i+1]) % MOD; } for(int i=1;i<=K;i++){ ans += (modpow(i,N,MOD) - modpow(i-1,N,MOD) + MOD) * modpow((K-i+1), M, MOD); ans %= MOD; } cout << ans << endl; /* for(auto c : mi) cout << c << " "; for(auto c : ma) cout << c << " "; */ }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; #define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr)) #define pb push_back #define ppb pop_back #define ff first #define ss second #define iter(it, s) for (auto it = s.begin(); it != s.end(); it++) #define fillc(a,b) memset(a,b,sizeof(a)) #define MOD 1000000007 #define INF 1e17 void check(ll a,ll b,ll c) { double la,lb; if(a==0) la=-INF; else la=c*log(a); if(b==0) lb=-INF; else lb=c*log(b); //cout<<setprecision(10)<<la<<" "<<lb<<endl; if(la<lb) cout<<"<"<<endl; else if(la>lb) cout<<">"<<endl; else cout<<"="<<endl; } void solve() { ll a,b,c; cin>>a>>b>>c; if(a==b) { cout<<"="<<endl; return; } if(c%2) { if(a<0 && b>=0) { cout<<"<"<<endl; return; } else if(a>=0 && b<0) { cout<<">"<<endl; return; } else if(a<0 && b<0) { check(abs(b),abs(a),c); return; } } a=abs(a); b=abs(b); check(a,b,c); } int main() { //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); }
#include <ctime> #include <cmath> #include <cctype> #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #include <vector> #include <queue> #define inf 100010 #define INF 0x7fffffff #define ll long long template <class I> inline void read(I &num){ num = 0; char c = getchar(), up = c; while(!isdigit(c)) up = c, c = getchar(); while(isdigit(c)) num = (num << 1) + (num << 3) + (c ^ '0'), c = getchar(); up == '-' ? num = -num : 0; return; } template <class I> inline void read(I &a, I &b) {read(a); read(b);} template <class I> inline void read(I &a, I &b, I &c) {read(a); read(b); read(c);} int n, x; signed main(){ read(n, x); double cnt = 0; for(int i = 1; i <= n; i++) { int a, b; read(a, b); cnt += a * (b / 100.0); if(cnt - x > 1e-8) { printf("%d\n", i); return 0; } } puts("-1"); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int n, x; cin>>n>>x; x *= 100; int res = 0; int count = 1; int ans = -1; bool ok = false; while(n--){ int a, b; cin>>a>>b; res += a * b; if(res > x and !ok)ok = true, ans = count; count++; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a,b; cin >> a >> b; if (a == b) { for (int i=0; i<a; i++) { int e_i = i+1; cout << e_i << " " << -1*e_i ; if (i != a-1) cout << " "; } } else { int s = a > b ? 1 : -1; int sum = 0; for (int i=0; i<max(a,b); i++) { cout << s*(i+1) << " "; sum = sum + i+1; } int n = min(a,b); // cout << sum << endl; int k = sum/n; int w = n/2; int r = sum%n; // cout << k << " "<< w <<" "<< r << endl; for (int i=k+w; i>=k-w; i--) { // cout << i << endl; if (n%2==0 && i == k) continue; int e_i = i; if (r>0) { e_i++; r--; } e_i = -1 * s * e_i; cout << e_i; if (i != k-w) cout << " "; } } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, suma = 0; cin >> a >> b; for (int i = 0; i < a; i++) { cout << 1000000 - i << " "; suma += 1000000 - i; } for (int i = 1; i < b; i++) { cout << -i << " "; suma -= i; } cout << -suma << endl; }
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; #define rep(i, init, end) for(ll i = init; i < end; i++) #define REP(i, init, end) for(ll i = init; i < end + 1; i++) #define rev(i, end, init) for(ll i = init - 1; i >= end; i--) #define REV(i, end, init) for(ll i = init; i >= end; i--) #define PI 3.14159265359 // #define EPS 0.0000000001 #define MOD 1000000007 //cout << std::fixed << std::setprecision(15) << y << endl; #define INF 1 << 30 int main(){ ll H, W; cin >> H >> W; string A[H]; rep(i, 0, H){ cin >> A[i]; } ll diff = 0; ll dp[H][W]; rep(i, 0, H){ rep(j, 0, W){ dp[i][j] = INF; } } dp[H - 1][W - 1] = 0; rev(i, 0, H){ rev(j, 0, W){ if(i == H - 1 && j == W - 1){ continue; } if(i == H - 1){ if((i + j) % 2 == 1){ dp[i][j] = (A[i][j + 1] == '+' ? -1 : 1) + dp[i][j + 1]; }else{ dp[i][j] = (A[i][j + 1] == '+' ? 1 : -1) + dp[i][j + 1]; } }else if(j == W - 1){ if((i + j) % 2 == 1){ dp[i][j] = (A[i + 1][j] == '+' ? -1 : 1) + dp[i + 1][j]; }else{ dp[i][j] = (A[i + 1][j] == '+' ? 1 : -1) + dp[i + 1][j]; } }else{ if((i + j) % 2 == 1){ dp[i][j] = min((A[i][j + 1] == '+' ? -1 : 1) + dp[i][j + 1], (A[i + 1][j] == '+' ? -1 : 1) + dp[i + 1][j]); }else{ dp[i][j] = max((A[i][j + 1] == '+' ? 1 : -1) + dp[i][j + 1], (A[i + 1][j] == '+' ? 1 : -1) + dp[i + 1][j]); } } } } if(dp[0][0] > 0){ cout << "Takahashi" << endl; }else if(dp[0][0] < 0){ cout << "Aoki" << endl; }else{ cout << "Draw" << endl; } return 0; }
//* #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") //*/ #include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl; #define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;} typedef long long ll; #define int ll #define vi vector<int> #define vl vector<ll> #define vii vector< vector<int> > #define vll vector< vector<ll> > #define vs vector<string> #define pii pair<int,int> #define pis pair<int,string> #define psi pair<string,int> #define pll pair<ll,ll> template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); } template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i<b;i++) #define in(x, a, b) (a <= x && x < b) #define all(c) c.begin(),c.end() void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;} void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;} void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;} void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;} void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;} void no(bool t=true) {cout<<(t?"no":"yes")<<endl;} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; int popcount(ll t) { return __builtin_popcountll(t); } // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0}; // vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 }; struct Setup_io { Setup_io() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(25); } } setup_io; const ll MOD = 1000000007; // const ll MOD = 998244353; // #define mp make_pair //#define endl '\n' void solve(vector<pii> wv, vi x) { sort(all(x)); ll ans = 0; for (pii temp: wv) { int w = temp.first, v = temp.second; rep (i, x.size()) { if (x[i] >= w) { ans += v; x.erase(x.begin() + i); break; } } } cout << ans << endl; } signed main() { int n, m, q; cin >> n >> m >> q; vector<pii> wv(n); rep (i, n) { cin >> wv[i].first >> wv[i].second; } sort(all(wv), [&](pii a, pii b) { return a.second > b.second; }); vi x(m); rep (i, m) cin >> x[i]; while (q--) { vi X; int l, r; cin >> l >> r; l--; rep (i, m) { if (in(i, l, r)) continue; X.push_back(x[i]); } solve(wv, X); } }
// #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #define all(x) (x).begin(),(x).end() #define sz(x) int(x.size()) using namespace std; using ll = long long; using pii = pair<int, int>; template<typename... T> void rd(T&... args) {((cin>>args), ...);} template<typename... T> void wr(T... args) {((cout<<args<<" "), ...); cout<<'\n';} template<typename T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } // set a = min(a,b) template<typename T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template <int MOD> struct ModInt { int val; // constructor ModInt(ll v = 0) : val(int(v % MOD)) { if (val < 0) val += MOD; }; // unary operator ModInt operator+() const { return ModInt(val); } ModInt operator-() const { return ModInt(MOD - val); } ModInt inv() const { return this->pow(MOD - 2); } // arithmetic ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; } ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; } ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; } ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; } ModInt pow(ll n) const { auto x = ModInt(1); auto b = *this; while (n > 0) { if (n & 1) x *= b; n >>= 1; b *= b; } return x; } // compound assignment ModInt& operator+=(const ModInt& x) { if ((val += x.val) >= MOD) val -= MOD; return *this; } ModInt& operator-=(const ModInt& x) { if ((val -= x.val) < 0) val += MOD; return *this; } ModInt& operator*=(const ModInt& x) { val = int(ll(val) * x.val % MOD); return *this; } ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); } // compare bool operator==(const ModInt& b) const { return val == b.val; } bool operator!=(const ModInt& b) const { return val != b.val; } // I/O friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; } friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; } }; using mint = ModInt<int(998244353)>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin>>n>>m; mint ans=0; int M=m+n; vector<mint> fac(M+1), inv(M+1); fac[0]=1; for (int i=1; i<=M; i++) { fac[i]=fac[i-1]*i; } inv[M]=fac[M].inv(); for (int i=M-1; i>=0; i--) inv[i]=inv[i+1]*(i+1); auto C=[&](int n, int m) -> mint { return fac[n]*inv[m]*inv[n-m]; }; for (int i=1; i<=m; i++) { mint tmp=1; int x=i; for (int f=2; f*f<=x; f++) { int cnt=0; while (x%f==0) x/=f, cnt++; tmp*=C(cnt+n-1, n-1); } if (x>1) tmp*=C(1+n-1, n-1); ans+=tmp; } cout<<ans; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define endl '\n' using namespace std; const int mod = 998244353; int add(int a, int b) { a += b; if (a >= mod) a -= mod; return a; } int fast_pow(int x, int deg) { int ans = 1, y = x; while (deg) { if (deg & 1) ans = 1ll * ans * y % mod; deg >>= 1; y = 1ll * y * y % mod; } return ans; } int n, m; void read() { cin >> n >> m; } const int maxn = 2e5 + 3; const int maxlog = 20; int fact[maxn], inv_fact[maxn]; void precompute() { fact[0] = 1; for (int i = 1; i < maxn; i++) fact[i] = 1ll * fact[i-1] * i % mod; inv_fact[maxn-1] = fast_pow(fact[maxn-1], mod-2); for (int i = maxn-2; i >= 0; i--) inv_fact[i] = 1ll * inv_fact[i+1] * (i + 1) % mod; } int comb(int a, int b) { if (b > a) return 0; return 1ll * fact[a] * inv_fact[b] % mod * inv_fact[a-b] % mod; } int f[maxn][maxlog]; vector <int> d[maxn]; void solve() { precompute(); for (int i = 1; i <= m; i++) for (int j = i + i; j <= m; j += i) d[j].push_back(i); f[1][1] = 1; for (int i = 2; i <= m; i++) { f[i][1] = 1; for (int j = 2; j < maxlog; j++) for (auto k: d[i]) f[i][j] = add(f[i][j], f[k][j-1]); } int ans = 0; for (int i = 1; i <= m; i++) for (int j = 1; j < maxlog; j++) ans = add(ans, 1ll * f[i][j] * comb(n-1, j-1) % mod); cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); read(); solve(); }
#include<iostream> using namespace std; int main(){ int n; cin >> n; cout << (n + 99) / 100 << endl; return 0; }
#include<bits/stdc++.h> #define pl(a) " [" << #a << ": " << (a) << "] " #define pts(a) " [" << #a << ": { first: " << (a.first) << ", second: " << (a.second) << "}] " #define all(vi) vi.begin(), vi.end() #define endl "\n" #define ll long long using namespace std; pair<int, int> n4[4] { {1, 0}, {-1, 0}, {0, 1}, {0, -1} }; pair<int, int> n8[8] { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1} }; ll int h(ll int x1, ll int y1, ll int x2, ll int y2) { return abs(x2 - x1) + abs(y2 - y1); } ll int pow(ll int x, ll int y) { if (y == 0) return 1; if (y % 2 == 0) { ll int a = pow(x, y / 2); return a * a; } else { int a = pow(x, y / 2); return a * a * x; } return 0;} template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "[" << p.first << ", " << p.second << "]"; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";} template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } ll int pow(int x, int y) { if (y == 0) return 1; if (y % 2 == 0) { int a = pow(x, y / 2); return a * a; } else { int a = pow(x, y / 2); return a * a * x; } assert(false); return 0; } void set_in(string s) { if (s.length() > 0) { freopen ((s+".in").c_str(), "r", stdin); freopen ((s+".out").c_str(), "w", stdout); } } void solve() { int n; cin >> n; n--; n = max(n, 1); n /= 100; cout << n + 1 << endl; } int main() { #ifndef DEBUG set_in(""); #endif #ifdef DEBUG auto clock_start = chrono::high_resolution_clock::now(); cout << endl; #endif ios::sync_with_stdio(false); cin.tie(nullptr); solve(); // int T; cin >> T; // for (int t = 1; t <= T; t++) { // cout << "Case #" << t << ": "; // solve(); // } // Clock #ifdef DEBUG auto clock_end = chrono::high_resolution_clock::now(); cout << endl; chrono::duration<double> elapsed = clock_end - clock_start; cout << "Execution time: " << elapsed.count() << "s" << endl; #endif return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> #define int long long struct edge { int to; int cost; }; using namespace std; // using namespace atcoder; using vi = vector<int>; using vii = vector<vector<int>>; using vb = vector<bool>; using qi = queue<int>; using P = pair<int, int>; using graph = vector<vector<edge>>; // using graph = vector<vector<int>>; // using mint = modint1000000007; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define REP(i,n) for(int i=0;i<n;i++) #define delim(i, n) cout << (i == n-1 ? "\n" : " ") #define print1(v) cout << fixed << setprecision(10) << v << "\n" #define print2(v1, v2) cout << fixed << setprecision(10) << v1 << " " << v2 << "\n" #define print3(v1, v2, v3) cout << fixed << setprecision(10) << v1 << " " << v2 << " " << v3 << "\n" #define printvi(v, n) REP(iiii, n) { cout << v[iiii]; delim(iiii, n); } #define printvii(v, h, w) REP(iiiii, h) { printvi(v[iiiii], w); } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } const int inf = 1LL << 60; // const int inf = 100000000; const int mod = 1000000007; const int maxn = 2e5+10; int n, m, k; vi p(maxn); vi dx = {-1, 0, 0, 1}; vi dy = {0, -1, 1, 0}; signed main () { cin.tie(0); ios::sync_with_stdio(false); cin >> n; int cnt = 0; REP(i, n) { int tmp; cin >> tmp; p[tmp] = 1; while(p[cnt] > 0) { cnt++; } print1(cnt); } }
#include <iostream> #include <algorithm> #include <tuple> #include <vector> #include <string> #include <queue> #include <cmath> #include <set> #include <map> #include <cassert> using namespace std; using ll = long long; int main() { string s; cin >> s; for(int i = 0; i < s.size(); i++){ if(s[i] == '.'){ for(int j = 0; j < i; j++){ cout << s[j]; } cout << endl; return 0; } } cout << s << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); puts(n == 191 ? "so-so" : (n < 191 ? "Yay!" : ":(")); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair<int, int>; int main() { ll n; cin >> n; vector<ll> ans; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { if (i * i == n) ans.push_back(i); else { ans.push_back(i); ans.push_back(n / i); } } } sort(ans.begin(), ans.end()); rep(i, (int)ans.size()) { cout << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(long long i=0;i<(long long)(n);i++) #define REP(i,k,n) for(long long i=k;i<(long long)(n);i++) #define all(a) a.begin(),a.end() #define rsort(a) {sort(all(a));reverse(all(a));} #define pb emplace_back #define eb emplace_back #define lb(v,k) (lower_bound(all(v),k)-v.begin()) #define ub(v,k) (upper_bound(all(v),k)-v.begin()) #define fi first #define se second #define pi M_PI #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T,vector<T>,greater<T>> #define dame(a) {out(a);return 0;} #define decimal cout<<fixed<<setprecision(15); #define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());} typedef long long ll; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> PP; typedef tuple<ll,ll,ll,ll> PPP; typedef multiset<ll> S; using vi=vector<ll>; using vvi=vector<vi>; using vvvi=vector<vvi>; using vvvvi=vector<vvvi>; using vp=vector<P>; using vvp=vector<vp>; using vb=vector<bool>; using vvb=vector<vb>; const ll inf=1001001001001001001; const ll INF=1001001001; const ll mod=1000000007; const double eps=1e-10; template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';} template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';} template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);} template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template<class T> void yesno(T b){if(b)out("yes");else out("no");} template<class T> void YesNo(T b){if(b)out("Yes");else out("No");} template<class T> void YESNO(T b){if(b)out("YES");else out("NO");} template<class T> void noyes(T b){if(b)out("no");else out("yes");} template<class T> void NoYes(T b){if(b)out("No");else out("Yes");} template<class T> void NOYES(T b){if(b)out("NO");else out("YES");} void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);} ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;} vi seg; ll N; void init(ll n){ N=1; while(N<n)N*=2; seg=vi(N*2-1); } void add(ll i,ll x){ i=N+i-1; seg[i]+=x; while(i>0){ i=(i-1)/2; seg[i]=seg[i*2+1]+seg[i*2+2]; } } ll getsum(ll a,ll b,ll k,ll l,ll r){ if(r<=a||b<=l)return 0; if(a<=l&&r<=b)return seg[k]; ll c1=getsum(a,b,k*2+1,l,(l+r)/2); ll c2=getsum(a,b,k*2+2,(l+r)/2,r); return c1+c2; } inline ll readll() { ll x = 0; char ch = getchar_unlocked(); while (ch < '0' || ch > '9') ch = getchar_unlocked(); while (ch >= '0' && ch <= '9'){ x = (x << 3) + (x << 1) + ch - '0'; ch = getchar_unlocked(); } return x; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n;cin>>n; vp v(n); rep(i,n){ ll a,b;cin>>a>>b; v[i].fi=a+b;v[i].se=a-b; }sort(all(v)); vi srt(n);rep(i,n)srt[i]=v[i].se;sort(all(srt)); init(n); ll ans=0; rep(i,n){ ll l=lb(srt,v[i].se); ans+=getsum(0,l+1,0,0,N); add(l,1); } out(ans); }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define rep(i,n) for (int i = 0; i < (n); ++i) #define pb push_back bool solve() { int n; cin >> n; vi x(n); vi y(n); rep(i,n){ cin >> x[i] >> y[i]; } int ans = 0; for(int i = 0; i < n-1; i++){ for(int j = i+1; j < n; j++){ if(abs(y[i]-y[j]) <= abs(x[i]-x[j])){ ans++; } } } cout << ans << endl; return true; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int T , n , a[550] , pl[550] , minn[2] , noww , it , flag , ans[300000] , tot , p[550]; void build( int l ) { for(int i = 1 ; i <= n ; i++ ) pl[a[i]] = i; minn[1] = minn[0] = 1e9; for(int i = l ; i <= n ; i++ ) minn[i & 1] = min(minn[i & 1] , a[i]); // for(int i = l ; i <= n ; i++ ) // if(a[i] == 297) cerr << minn[i & 1] << endl; return ; } void print( int a ) { int qwq = a / 10; if(qwq) print(qwq); putchar(a - (qwq << 1) - (qwq << 3) + '0'); return ; } void run( int pl ) { ans[++tot] = pl - 2; swap(a[pl - 2] , a[pl - 1]); ans[++tot] = pl - 1; swap(a[pl - 1] , a[pl]); ans[++tot] = pl - 2; swap(a[pl - 2] , a[pl - 1]); ans[++tot] = pl - 1; swap(a[pl - 1] , a[pl]); } void walk( int pl ) { ans[++tot] = pl - 2; swap(a[pl - 2] , a[pl - 1]); ans[++tot] = pl - 1; swap(a[pl - 1] , a[pl]); ans[++tot] = pl - 2; swap(a[pl - 2] , a[pl - 1]); ans[++tot] = pl - 1; swap(a[pl - 1] , a[pl]); ans[++tot] = pl - 2; swap(a[pl - 2] , a[pl - 1]); } int main() { // freopen("1.in" , "r" , stdin); // freopen("1.out" , "w" , stdout); scanf("%d" , &T); while(T--) { // cerr << 11111; scanf("%d" , &n); noww = tot = flag = 0; it = 1; for(int i = 1 ; i <= n ; i++ ) scanf("%d" , &a[i]) , p[i] = 1 , flag |= (a[i] != i); if(!flag) { // printf("yes\n"); if(a[2] == 2) printf("0\n\n"); continue; } if(n == 2) { // printf("yes\n"); if(a[2] == 2) printf("0\n\n"); else printf("1\n1\n"); continue; } if(a[1] == 1) it = 2 , p[1] = 0; build(it); while(it <= n) { int u = minn[noww] , d = 0; if(u > 500) u = a[n - (noww ^ (n & 1))]; p[u] = 0; for(int i = 1 ; i < u ; i++ ) d += p[i]; for(int i = pl[u] - 1 ; i >= u - d ; i-- ) ans[++tot] = i , swap(a[i] , a[i + 1]) , noww ^= 1; it++; build(it); // for(int i = 1 ; i <= n ; i++ ) cerr << a[i] << ' '; cerr << endl; } if(a[n] != n) { // cerr << 111111; int pl = n , u = a[n]; while(pl - u >= 2) run(pl) , pl -= 2; if(pl - u == 1) walk(pl); // if(pl - u == 1) cerr << a[n] << ' ' << "walk\n"; // else cerr << a[n] << ' ' << "run\n"; } // for(int i = 1 ; i <= n ; i++ ) cerr << a[i] << ' '; cerr << endl; print(tot); printf("\n"); for(int i = 1 ; i <= tot ; i++ ) print(ans[i]) , putchar(' '); printf("\n"); // while(1); // flag = (tot > n * n); // for(int i = 1 ; i <= n ; i++ ) flag |= (a[i] != i); // for(int i = 1 ; i <= tot ; i++ ) flag |= (ans[i] == 0); // if(flag) printf("no\n"); // else printf("yes\n"); } return 0; } /* 1 4 1 2 3 4 */
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i <= (n); i++) #define zep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl; ll n, p[555], at; vector<ll> ans; void sp(ll k){ ans.push_back(k); ll tmp = p[k]; p[k] = p[k + 1]; p[k + 1] = tmp; } void lst4(){ if(p[4] == 4)return; if(p[3] == 4){ if(ans.size() % 2 == 0){ sp(3); }else{ sp(2); sp(3); sp(2); sp(3); } return; } if(p[2] == 4){ if(ans.size() % 2 == 1){ sp(2); sp(3); }else{ sp(3); sp(2); sp(3); } return; } if(p[1] == 4){ if(ans.size() % 2 == 0){ sp(1); sp(2); sp(3); }else{ sp(2); sp(1); sp(2); sp(3); } } } void lst3(){ while(p[1] != 1 || p[2] != 2){ if(ans.size() % 2 == 0){ sp(1); }else{ sp(2); } } } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll T; cin >> T; while(T--){ while(!ans.empty())ans.pop_back(); cin >> n; rep(i, 1, n)cin >> p[i]; if(n == 2){ if(p[1] != 1)sp(1); }else{ rrep(i, n, 5){ if(p[i] == i)continue; rep(j, 1, i)if(p[j] == i)at = j; if(ans.size() % 2 == 1 && at % 2 == 1){ if(at == 3){ sp(4); }else{ sp(2); } } if(ans.size() % 2 == 0 && at % 2 == 0){ if(at == 2){ sp(3); }else{ sp(1); } } rep(j, at, i - 1){ sp(j); } } if(n >= 4)lst4(); lst3(); } print(ans.size()) zep(j, 0, ans.size())cout << ans[j] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> #define int long long #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define pre(i,a,b) for(int i=(b);i>=(a);i--) #define ios ios::sync_with_stdio(false),cin.tie(0); #define pb push_back #define ps push #define fi first #define se second #define ps push #define Inf 0x3f3f3f3f3f3f3f3f #define eps 1e-5 typedef long long ll; const int N=3e5+5; const int M=2e5+5; const int mod=998244353; using namespace std; ll quick_power_mod(ll a,ll b,ll m)//pow(a,b)%m { a%=m; ll result = 1; while(b>0) { if(b&1) result=(result*a)%m; a=(a*a)%m; b>>=1; } return result; } //计算组合数取模 ll comp(ll a,ll b,int p)//composite num C(a,b)%p { if(a<b)return 0; if(a==b)return 1; if(b>a-b)b=a-b; ll ans=1,ca=1,cb=1; for(ll i=0;i<b;i++) { ca=(ca*(a-i))%p; cb=(cb*(b-i))%p; } ans=(ca*quick_power_mod(cb,p-2,p))%p; return ans; } ll lucas(ll n,ll m,ll p) { ll ans=1; while(n&&m&&ans) { ans=(ans*comp(n%p,m%p,p))%p;//also can be recusive n/=p; m/=p; } return ans; } ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); } string str; signed main() { ios; int n,q; cin>>n>>str>>q; int t,a,b; int cc=0; while(q--){ cin>>t>>a>>b; if(t==1){ if(cc%2==0){ swap(str[a-1],str[b-1]); } else{ if(a<=n){ a+=n; } else{ a-=n; } if(b<=n){ b+=n; } else{ b-=n; } swap(str[a-1],str[b-1]); } } else{ cc++; // swap(str[n-1],str[2*n-1]); } } if(cc%2==0){ cout<<str<<endl; } else{ for(int i=n;i<2*n;i++){ cout<<str[i]; } for(int i=0;i<n;i++){ cout<<str[i]; } cout<<endl; } return 0 ; }
#include "bits/stdc++.h" using namespace std; #define int long long #define pb push_back #define f(i,a,n) for(int i=a ; i<n ; i++) #define rf(i,n,a) for(int i=n ; i>=a ; i--) #define F first #define S second #define all(c) (c).begin(),(c).end() #define sz(v) (int)(v).size() #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; const int inf = 1e9; const int inf64 = 1e18; const int MOD = inf + 7; const int N = 1e5 + 5; struct node{ int to; int cost; int k; node(int _to, int _cost, int _k){ to = _to; cost = _cost; k = _k; } }; vector<node> g[N]; int32_t main() { fast; int n,m,x,y; cin >> n >> m >> x >> y; f(i,0,m){ int u,v,cost,k; cin >> u >> v >> cost >> k; g[u].pb(node(v, cost, k)); g[v].pb(node(u, cost, k)); } priority_queue<pii, vector<pii>, greater<pii>> pq; vi dis(n+1, 1e18); dis[x] = 0; pq.push({0, x}); while(!pq.empty()){ pii p = pq.top(); pq.pop(); int u = p.S; int cur = p.F; for(int i=0 ; i<g[u].size() ; i++){ int v = g[u][i].to; int cost = g[u][i].cost; int k = g[u][i].k; int temp = (k - cur % k)%k + cur + cost; if(dis[v] > temp){ dis[v] = temp; pq.push({temp, v}); } } } int ans = dis[y]; if(ans == 1e18){ ans = -1; } cout << ans << "\n"; }
#include <algorithm> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdint> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <queue> #include <random> #include <regex> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ld = long double; using ll = long long; using ull = unsigned long long; using pairll = pair<ll, ll>; using pairint = pair<int, int>; using vecll = vector<ll>; using vecvecll = vector<vector<ll>>; using vecpairll = vector<pair<ll, ll>>; using vecstring = vector<string>; #define rep(i, n) for (ll i = (0); i < (n); ++i) #define Rep(i, a, b) for (ll i = (a); i < (b); ++i) constexpr ll MOD = 1000000007; template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first; is >> p.second; return is; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &&x : v) is >> x; return is; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << ' ' << p.second; return os; } template <class T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto i = begin(v); i != end(v); ++i) { if (i != begin(v)) os << ' '; os << *i; } return os; } inline ll nizyou(ll x) { return x * x; } bool isprime(long long N) { if (N <= 1) { return 0; } for (long long i = 2; i * i <= N; i++) { if (N % i == 0) { return 0; } } return 1; } map<long long, int> Prime_factorization(long long N) { map<long long, int> primefact; for (long long i = 2; i * i <= N; i++) { ll count = 0; while (N % i == 0) { count += 1; N /= i; } if (count > 0) { primefact[i] = count; } } if (N > 1) { primefact[N]++; } return primefact; } //整数の指数の累乗 ll expo(ll a, unsigned long long N) { if (N < 1) { return 1; } ll sum = a; for (ull i = 1; i < N; ++i) { sum *= a; } return sum; } ll modexpo(ll a, unsigned long long N, ll mod) { if (N < 1) { return 1; } ll sum = a; for (ull i = 1; i < N; ++i) { sum = sum * a % mod; } return sum; } template <typename T> void exchange(T &a, T &b) { T c = a; a = b; b = c; } void YesOut() { cout << "Yes" << endl; } void NoOut() { cout << "No" << endl; } template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } //デバッグ用表示関数 基本これを使うこと template <typename T> void checkOut(T s) { //非表示にするときはfalse 表示するときはtrueへ bool frag = false; if (frag) { cout << s << endl; } } const double PI = acos(-1); //0~9のchar型のint変換 int ctoi(char c) { return c - '0'; } ll ctoll(char c) { return static_cast<ll>(ctoi(c)); } #define INF 10000000000 int main() { ll N, Q; string S; cin >> N >> S >> Q; string s1 = S.substr(0, N); string s2 = S.substr(N, N); rep(i, Q) { ll T, a, b; cin >> T >> a >> b; if (T == 1) { if (b <= N) { swap(s1[a - 1], s1[b - 1]); } else if (a <= N) { swap(s1[a - 1], s2[b - N - 1]); } else { swap(s2[a - 1 - N], s2[b - 1 - N]); } } if (T == 2) { swap(s1, s2); } } cout << s1 + s2 << endl; return 0; }
/** * In The Name Of God * author : Behradm * Idvwhu wkdq idvw, Txlfnhu wkdq txlfn, L dp Oljkwqlqj, Vshhg, L dp Vshhg :D :D **/ #include "bits/stdc++.h" using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n; cin >> n; string s; cin >> s; int Q; cin >> Q; bool f = 1; while (Q--) { int t, a, b; cin >> t >> a >> b; --a, --b; if (t == 2) { f = !f; } else { if (!f) { if (a < n) a += n; else a -= n; if (b < n) b += n; else b -= n; } swap(s[a], s[b]); } } if (f) { cout << s << '\n'; return 0; } for (int i = n; i < 2 * n; i++) cout << s[i]; for (int i = 0; i < n; i++) cout << s[i]; cout << '\n'; return 0; }
#include<iostream> #include<algorithm> #include<vector> using namespace std; typedef long long ll; const int max_n = 50; ll a[50],n,t; void Solve(int l,int r,vector<ll>& v,ll tmp){ if (l>r||tmp>t)return; if (l==r){ v.push_back(a[l]+tmp); v.push_back(tmp); return; } Solve(l+1,r,v,tmp);Solve(l+1,r,v,tmp+a[l]); } int main(){ ios::sync_with_stdio(0); cin>>n>>t; for (int i=1;i<=n;++i)cin>>a[i]; int mid=n/2; vector<ll> lft,rgt; Solve(1,mid,lft,0);Solve(mid+1,n,rgt,0); lft.push_back(0);rgt.push_back(0); sort(lft.begin(),lft.end()); sort(rgt.begin(),rgt.end()); ll ans = 0; for (int i=0;i<lft.size();++i){ ll l = lft[i];if (l>t)break; auto r = lower_bound(rgt.begin(),rgt.end(),t-l); ll rr=0; if (r!=rgt.end()){ rr = *r; if (rr!=t-l){ if (r==rgt.begin())rr=0; else rr = *(--r); }ans = max(ans,l+rr); } else ans = max(ans,l+rgt.back()); }cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 10; int n, m, a[N]; vector <int> G[N]; int in[N], dp[N]; int main() { memset(dp, -1, sizeof(dp)); scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", a + i); for (int i = 1; i <= m; i++) { int u, v; scanf("%d %d", &u, &v); G[u].push_back(v); in[v]++; } queue <int> Q; for (int i = 1; i <= n; i++) { if (!in[i]) { Q.push(i); dp[i] = a[i]; } } int ans = INT_MIN; while (!Q.empty()) { int u = Q.front(); Q.pop(); for (auto v : G[u]) { if (~dp[v]) dp[v] = min(dp[v], min(dp[u], a[u])); else dp[v] = min(dp[u], a[u]); in[v]--; if (!in[v]) Q.push(v); ans = max(ans, a[v] - dp[v]); } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline bool chmin(T& a, const T b) {a = min(a, b); return (a == b);} template <typename T> inline bool chmax(T& a, const T b) {a = max(a, b); return (a == b);} inline void cls() {} void solve() { cls(); string s; cin >> s; cout << s[1] << s[2] << s[0] << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; #ifdef _LOCAL system("color a"); freopen("in.txt", "r", stdin); cin >> t; #endif for (int i = 1; i <= t; ++i) { cerr << "Case #" << i << ": \n"; solve(); cerr << "\n"; } return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(), (x).end() #define uniq(v) (v).erase(unique(all(v)), (v).end()) #define sz(x) (int)((x).size()) #define fr first #define sc second #define pii pair<int, int> #define rep(i, a, b) for (int i = a; i < b; i++) #define mem1(a) memset(a, -1, sizeof(a)) #define mem0(a) memset(a, 0, sizeof(a)) #define ppc __builtin_popcount #define ppcll __builtin_popcountll #define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); template <typename T_vector> void output_vector(const T_vector &v, bool addOne = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = (int)v.size(); for (int i = start; i < end; i++) cout << v[i] + (addOne ? 1 : 0) << (i < end - 1 ? ' ' : '\n'); } int ceil(int x, int y) { return x / y + (x % y > 0); } const long long INF = 1e18; const int32_t M = 1e9 + 7; const int32_t MM = 998244353; const int N = 2e5 + 5; void solve() { int n; cin >> n; cout << n / 100 + (n % 100 > 0 ? 1 : 0) << "\n"; } signed main() { fast #ifndef ONLINE_JUDGE // For getting input from input.txt file freopen("input.txt", "r", stdin); // Printing the Output to output.txt file freopen("output.txt", "w", stdout); #endif cout << setprecision(12); cout << fixed; int t = 1; // cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int f[1010][1010], a[1010], b[1010], n, m; int main() { cin >> n >> m; for(register int i = 1; i <= n; i++) { cin >> a[i]; } for(register int j = 1; j <= m; j++) { cin >> b[j]; } for(register int i = 1; i <= m; i++) f[0][i] = i; for(register int i = 1; i <= n; i++) f[i][0] = i; for(register int i = 1; i <= n; i++) { for(register int j = 1; j <= m; j++) { f[i][j] = min(f[i - 1][j], f[i][j - 1]) + 1; if(a[i] == b[j]) f[i][j] = min(f[i][j], f[i - 1][j - 1]); else f[i][j] = min(f[i][j], f[i - 1][j - 1] + 1); } } cout << f[n][m] << endl; return 0; }
/* AUTHOR: julianferres */ #include <bits/stdc++.h> using namespace std; // neal Debugger template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifdef LOCAL #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif typedef long long ll; typedef vector<ll> vi; typedef pair<ll,ll> ii; typedef vector<ii> vii; typedef vector<bool> vb; #define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define forr(i, a, b) for(int i = (a); i < (int) (b); i++) #define forn(i, n) forr(i, 0, n) #define DBG(x) cerr << #x << " = " << (x) << endl #define RAYA cerr << "===============================" << endl #define pb push_back #define mp make_pair #define all(c) (c).begin(),(c).end() #define esta(x,c) ((c).find(x) != (c).end()) const int INF = 1e9+15; // const ll INF = 2e18; const int MOD = 1e9+7; // 998244353 const int MAXN = 1005; vi a(MAXN), b(MAXN); vector<vi> dp(MAXN, vi(MAXN, -1)); ll solve(ll n,ll m){ if(dp[n][m]!=-1) return dp[n][m]; if(n==0 || m==0) return max(n,m); dp[n][m] = min({solve(n-1,m-1)+((ll)(a[n]!=b[m])),solve(n,m-1)+1,solve(n-1,m)+1}); return dp[n][m]; } int main(){ FIN; int n, m; cin >> n >> m; forr(i, 1, n+1) cin >> a[i]; forr(i, 1, m+1) cin >> b[i]; cout << solve(n,m) << endl; return 0; }
// choker #include<bits/stdc++.h> using namespace std; using lli = long long; using ul = unsigned long long; const int maxN = 1e6 + 1; const int mod = 1e9 + 7; const int BLOCK_SIZE = 400; const int LIM = 1e4; //const int ep = 100; const lli infty = 1e18; const lli base = 37; const int ep = 'a' - 1; void FastInput() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } void InputFile() { freopen("a.INP","r",stdin); //freopen("a.OUT","w",stdout); } int n,q; lli a[maxN]; vector<lli> selct; map<string,int> apr; void Read() { cin >> n >> q; for(int i = 1; i <= n; i++) { cin >> a[i]; string trans = to_string(a[i]); apr[trans] = 1; } } void Prc(lli m) { lli mini = 1; lli maxi = 1e18 + 1e6; while(mini <= maxi) { lli mid = (mini + maxi) / 2; lli k = upper_bound(selct.begin(),selct.end(),mid) - selct.begin(); if(mid - k == m) { string trans = to_string(mid); if(apr[trans] == 1) maxi = mid - 1; else { cout << mid <<'\n'; return; } } if(mid - k < m) { mini = mid + 1; } if(mid - k > m) { maxi = mid - 1; } } } void Solve() { sort(a + 1,a + n + 1); selct.push_back(a[1]); for(int i = 2; i <= n; i++) { if(a[i] != a[i-1]) selct.push_back(a[i]); } while(q--) { lli m; cin >> m; Prc(m); } } void Debug() { } int main() { FastInput(); //InputFile(); int test; //cin >> test; test = 1; while(test--) { Read(); Solve(); Debug(); } }
#include <iostream> #include <string> #include <stdio.h> #include <math.h> #include <queue> #include <algorithm> #include <utility> #include <vector> #include <tuple> #include <numeric> #include <climits> using namespace std; int main(int argc, char* argv[]){ long long n,q; cin>>n>>q; vector<long long>a(n); vector<long long>query(q); vector<pair<long long,long long>> p; pair<long long, long long> p_; p_.first = 1; for(int i=0;i<n;i++){ cin>>a[i]; if(p_.first==a[i]){ p_.first = a[i]+1; }else{ p_.second = a[i]-1; // cout<<p_.first<<" "<<p_.second<<endl; p.push_back(p_); p_.first = a[i]+1; } if(i==n-1){ p_.second = LLONG_MAX; // cout<<p_.first<<" "<<p_.second<<endl; p.push_back(p_); } } vector<long long> len; long long len_ = 0; for(long long i=0;i<p.size();i++){ len_ += p[i].second - p[i].first +1; len.push_back(len_); // cout<<len_<<endl; } for(long long i=0;i<q;i++){ cin>>query[i]; } for(auto q_ : query ){ auto itr = lower_bound(len.begin(),len.end(), q_); long long idx = distance(len.begin(),itr); long long idx_; if(idx==0){ idx_ = q_ - 1; }else{ idx_ = q_ - len[idx-1] -1; } // cout<<q_<<" "<<idx<<" "<<idx_<<endl; long long ans = p[idx].first+idx_; cout<<ans<<endl; } }
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ms(s, n) memset(s, n, sizeof(s)) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i) #define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) #define sz(a) int((a).size()) #define present(t, x) (t.find(x) != t.end()) #define all(a) (a).begin(), (a).end() #define uni(a) (a).erase(unique(all(a)), (a).end()) #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define prec(n) fixed<<setprecision(n) #define bit(n, i) (((n) >> (i)) & 1) #define bitcount(n) __builtin_popcountll(n) typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<pi> vii; const int MOD = (int) 1e9 + 7; const int FFTMOD = 119 << 23 | 1; const int INF = (int) 1e9 + 23111992; const ll LINF = (ll) 1e18 + 23111992; const ld PI = acos((ld) -1); const ld EPS = 1e-9; inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;} inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;} template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;} template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;} inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;} inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;} inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;} inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;} inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;} inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);} inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;} inline int sign(ld x, ld y) {return sign(x - y);} mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count()); inline int mrand() {return abs((int) mt());} inline int mrand(int k) {return abs((int) mt()) % k;} #define db(x) cerr << "[" << #x << ": " << (x) << "] "; #define endln cerr << "\n"; void chemthan() { int n; cin >> n; vector<string> s(n); FOR(i, 0, n) cin >> s[i]; vector<vi> g(n, vi(n)); FOR(i, 0, n) g[i][i] = 1; FOR(i, 0, n) FOR(j, 0, n) if (i != j) { g[i][j] = s[i][j] == '1'; } FOR(k, 0, n) FOR(i, 0, n) FOR(j, 0, n) { g[i][j] |= g[i][k] & g[k][j]; } double res = 0; FOR(i, 0, n) { int num = 0; FOR(j, 0, n) if (i ^ j) { if (g[j][i]) { num++; } } res += 1.0 / (num + 1); } cout << prec(9) << res << "\n"; } int32_t main(int32_t argc, char* argv[]) { ios_base::sync_with_stdio(0), cin.tie(0); if (argc > 1) { assert(freopen(argv[1], "r", stdin)); } if (argc > 2) { assert(freopen(argv[2], "wb", stdout)); } chemthan(); cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100+19; int g[N][N],vis[N],val[N],n; void dfs(int u) { ++val[u]; vis[u] = 1; for(int i = 1 ; i <= n ; ++i) if(g[u][i] && !vis[i]) dfs(i); } void solve() { cin >> n; for(int i = 1 ; i <= n ; ++i) { string s; cin >> s; for(int j = 1 ; j <= n ; ++j) if(s[j-1] == '1') g[i][j] = 1; } for(int i = 1 ; i <= n ; ++i) { for(int j = 1 ; j <= n ; ++j) vis[j] = 0; dfs(i); } double ans = 0; for(int i = 1 ; i <= n ; ++i) ans += 1.0 / val[i]; printf("%.12lf\n",ans); } int main() { int T = 1; ios::sync_with_stdio(0); //cin >> T; while(T--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n; cin>>n; vector<int> a(2*n); for(int i=0;i<2*n;++i) cin>>a[i]; ll ans=0; priority_queue<int,vector<int>,greater<int>> q; for(int i=n-1;i>=0;--i) { int l=a[i],r=a[2*n-1-i]; if(l>r) swap(l,r); if(!q.empty() && q.top()<l) { ans-=q.top(),q.pop(); q.push(l);ans+=l; } q.push(r);ans+=r; } cout<<ans<<endl; }
#include<bits/stdc++.h> #define FORz(i,t,n) for(int i=t;i<=n;i++) #define FORf(i,n,t) for(int i=n;i>=t;i--) #define SCC(x) scanf("%d",&x) #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) typedef long long ll; using namespace std; const int N=1e5+5; const ll MOD=1e9+7; // inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;} //ll pow1(ll a,ll b){ll r=1;while(b){if(b&1)r=r*a;a=a*a;b>>=1;}return r;} //ll pow2(ll a,ll b,ll mod){ll r=1;while(b){if(b&1)r=r*a%mod;a=a*a%mod;b>>=1;}return r%mod;} //ll gcd(ll a,ll b){ll m=a%b;while(m){a=b;b=m;m=a%b;}return b;} //void exgcd(ll a, ll b, ll &d, ll &x, ll &y){if(!b) { d = a; x = 1; y = 0;}else { exgcd(b, a % b, d, y, x); y -= x * (a / b); }} //ll inv(ll a){ll d, x, y;exgcd(a, MOD, d, x, y);return d == 1 ? (x + MOD) % MOD : -1;}struct node{ll mat[105][105];};node mul(node x,node y,int n,ll mod){node tmp;for(int i=0;i<n;i++)for(int j=0;j<n;j++){tmp.mat[i][j]=0;for(int k=0;k<n;k++)tmp.mat[i][j]+=(x.mat[i][k]*y.mat[k][j])%mod;tmp.mat[i][j]%=mod;}return tmp;} // node matpow(node x,node y,ll num,int n,ll mod){while(num){if(num&1){y=mul(x,y,n,mod);}x=mul(x,x,n,mod);num=num>>1;}return y;} //for(ll i=2;i<N-1;i++){if(!a[i]) b[++cnt]=i;for(ll j=1;j<=cnt&&i*b[j]<N;j++){a[i*b[j]]=1;if(i%b[j]==0) break;}} //int find(int x){return a[x]==x?x:a[x]=find(a[x]);} //void merge(int x,int y){a[find(y)]=a[find(x)];} ll n; ll a[N]; int main() { cin>>n; FORz(i,1,n) cin>>a[i]; sort(a+1,a+n+1); ll sum=1; FORz(i,1,n) sum=sum*(a[i]-a[i-1]+1)%MOD; cout<<sum; }
#include<iostream> #include<vector> #include<cstdlib> #include<algorithm> #include<climits> #include<queue> #include<stack> #include<cmath> #include<iterator> #include<set> typedef long long ll; using namespace std; #define rep(x, y) for (ll i = x; i < y; i ++) #define repi(x, y) for (ll i = x; i > y; i --) #define si(x) ll x;cin>>x ll arr[200005]; vector<ll> brr[100005]; ll crr[100005]; ll drr[100005]; set<int, greater<int> > num; set<int, greater<int> >::iterator numitr; int main() { ll test = 1; // cin>>test; for(ll z=0;z<test;z++) { si(n); for(ll i=0;i<=n;i++) { crr[i] = 0; drr[i] = -1; } for(ll i=0;i<n;i++) { cin>>arr[i]; } for(ll i=0;i<n;i++) { si(a); brr[a].push_back(i+1); } for(ll i=0;i<n;i++) { ll a; cin>>a; crr[a]++; } ll counter =0; for(ll i=0;i<n;i++) { if(drr[arr[i]] == -1) { ll prevcounter = counter; for(ll j = 0;j<brr[arr[i]].size();j++) { counter += crr[brr[arr[i]][j]]; } drr[arr[i]] = counter - prevcounter; } else { counter += drr[arr[i]]; } } cout<<counter<<endl; } }
#include <algorithm> #include <vector> #include <iostream> #include <stdio.h> #include <bits/stdc++.h> using namespace std; int main(){ //int a, b, c; int n; cin >> n; vector<int> a(n); vector<int> b(n); vector<int> c(n); int t; for(int i=0;i<n;i++){ cin >> t; a[i]=t-1; } for(int j=0;j<n;j++){ cin >> t; b[j]=t-1; } for(int k=0;k<n;k++){ cin >> t; c[k]=t-1; } vector<int> count(n); for (int j = 0; j < n; ++j) { count[b[c[j]]] += 1; } long long ans = 0; for (int i = 0; i < n; ++i) { ans += count[a[i]]; } cout << ans << '\n'; return 0; }
// C - Large RPS Tournament #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;++i) map<char,char> win{{'R','P'}, {'P','S'}, {'S','R'}}; // [lose]=win int main(){ int N, K; string S; cin>>N>>K>>S; while(K--){ string t = S + S; rep(i, N){ char a = t[i*2], b = t[i*2+1]; S[i] = win[a]==b? b:a; } } cout<< S[0] <<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ long long a,b,c,d;cin>>a>>b>>c>>d; cout<<min(a,min(b,min(c,d)))<<"\n"; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int h, w, a, b, ans = 0; void dfs(int i, int bit, int a, int b) { if (i == h*w) { ans++; return; } if (bit & 1 << i) { dfs(i+1, bit, a, b); return; } if (b) dfs(i+1, bit | 1 << i, a, b-1); if (a) { if (i%w != w-1 && ~bit & 1 << i+1) dfs(i+1, bit | 1 << i | 1 << i+1, a-1, b); if (i/w != h-1 && ~bit & 1 << i+w) dfs(i+1, bit | 1 << i | 1 << i+w, a-1, b); } } int main(void){ cin >> h >> w >> a >> b; dfs(0, 0, a, b); cout << ans << endl; return 0; }
#include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <deque> #include <complex> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <cstring> #include <ctime> #include <iterator> #include <bitset> #include <numeric> #include <list> #include <iomanip> #include <cassert> #if __cplusplus >= 201103L #include <array> #include <tuple> #include <initializer_list> #include <unordered_set> #include <unordered_map> #include <forward_list> using namespace std; #define cauto const auto& #define ALL(v) begin(v),end(v) #else #define ALL(v) (v).begin(),(v).end() #endif namespace{ typedef long long LL; typedef pair<int,int> pii; typedef pair<LL,LL> pll; typedef vector<int> vint; typedef vector<vector<int> > vvint; typedef vector<long long> vll, vLL; typedef vector<vector<long long> > vvll, vvLL; #define VV(T) vector<vector< T > > template <class T> void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){ v.assign(a, vector<T>(b, t)); } template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); } template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); } template <class F, class T> void convert(const F &f, T &t){ stringstream ss; ss << f; ss >> t; } template <class Con> string concat(const Con &c, const string &spr){ stringstream ss; typename Con::const_iterator it = c.begin(), en = c.end(); bool fst = true; for(; it != en; ++it){ if(!fst){ ss << spr; } fst = false; ss << *it; } return ss.str(); } template <class Con, class Fun> vector<typename Con::value_type> cfilter(const Con &c, Fun f) { vector<typename Con::value_type> ret; typename Con::const_iterator it = c.begin(), en = c.end(); for(; it != en; ++it){ if(f(*it)){ ret.emplace_back(*it); } } return ret; } #if __cplusplus >= 201103L template <class Con, class Fun> auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> { vector<decltype(f(*c.begin()))> ret; ret.reserve(c.size()); for(const auto &x: c){ ret.emplace_back(f(x)); } return ret; } #endif #if __cplusplus >= 201402L #define lambda(e) ([&](const auto &_){ return (e); }) #define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); }) #endif #define REP(i,n) for(int i=0;i<int(n);++i) #define RALL(v) (v).rbegin(),(v).rend() #define tget(t,i) get<i>(t) #define MOD 1000000007LL #define EPS 1e-8 void mainmain(){ LL x, y; cin >> x >> y; LL ans = abs(x - y); for(int i = 1; x <= y; ++i){ x *= 2; LL d = abs(y - x); LL res = i; for(int j = 0; j <= i; ++j){ if(d >> j & 1){ ++res; if(j < i - 2 && (d >> (j + 1) & 3) == 3){ d += 1LL << j; } else{ d -= 1LL << j; } } } res += d >> i; chmin(ans, res); } cout << ans << endl; } } int main() { // ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(4); mainmain(); }
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define pii pair<int, int> #define pll pair<long long,long long> #define vl vector<long long> #define vll vector<pll> #define vi vector<int> #define vii vector<pii> #define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl '\n' #define tcase int tt; cin>>tt; while(tt--) #define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++) using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; const int MAXN = 1000002; const int MOD2 = 998244353; const int MOD = 1000000007; const int INF = 1e8; const ld EPS = 1e-7; // Extra #define forn(i, n) for(int i = 0; i < (int)n; i++) #define forne(i, a, b) for(int i = a; i <= b; i++) #define all(x) x.begin(), x.end() #define trav(a, x) for(auto& a : x) #define fill(x,y) memset(x,y,sizeof(x)) /* run this program using the console pauser or add your own getch, system("pause") or input loop */ ll mul(ll x, ll y) { return (x * 1ll * y) % MOD; } ll fastpow(ll x, ll y) { ll z = 1; while(y) { if(y & 1) z = mul(z, x); x = mul(x, x); y >>= 1; } return z; } ll modinv(ll n,ll p) { return fastpow(n,p-2) ; } struct Comp { bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b) { if (a.first != b.first) { return a.first < b.first; } return a.second >b.second; } }; int main(int argc, char** argv) { sws ; // cout<<setprecision(10); // ll google=0 ; // tcase { ll n,k ; cin>>n>>k ; vector<pair<ll,ll>>p; forn(i,n) { ll x,y ; cin>>x>>y ; p.pb({x,y}) ; } sort(p.begin(),p.end()) ; ll cur=0 ; forn(i,n) { if(cur+k>=p[i].ff) { k-=(p[i].ff-cur) ; cur=p[i].ff ; k+=p[i].ss ; } } cur+=k ; cout<<cur<<"\n"; } return 0 ; }
#include<bits/stdc++.h> using namespace std; #define ll unsigned long long struct num{ ll a; int b; bool operator<(const num& k)const { return a<k.a; } }nzk[200500]; int main() { int n,flag=0; ll k; cin>>n>>k; for(int i=1;i<=n;i++) { cin>>nzk[i].a>>nzk[i].b; } nzk[0].a=0,nzk[0].b=0; sort(nzk+1,nzk+n+1); for(int i=1;i<=n;i++) { if(k>=nzk[i].a) { k+=nzk[i].b; } else { break; } } cout<<k<<'\n'; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ long long n,l,r,mid; scanf("%lld",&n),l=1,r=n; while(l<r){ mid=(l+r+1)>>1; if(mid+1<=((n+1)<<1)/mid)l=mid; else r=mid-1; }printf("%lld\n",n+1-r); return 0; }
// Problem: B - log // Contest: AtCoder - AtCoder Regular Contest 109 // URL: https://atcoder.jp/contests/arc109/tasks/arc109_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define mp make_pair #define pb push_back #define ff first #define ss second #define vi vector<int> #define vll vector<ll> #define all(x) (x).begin() , (x).end() void dbg(){ cerr << endl; } template<typename Head , typename... Tail> void dbg(Head h , Tail... t){ cerr << h << " "; dbg(t...); } #ifdef EMBI_DEBUG #define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", dbg(__VA_ARGS__) #else #define debug(...) #endif const int max_n = 1e5 + 9; const int mod = 1e9 + 7; const int inf = 1e12; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; ll power(ll a , ll b) { ll prod = 1; while(b) { if(b&1) prod = (prod*a)%mod; a = (a*a)%mod; b >>= 1; } return prod; } void solve(){ ll n; cin >> n; ll beg = 0 , last = inf , mid , ans; while(beg <= last){ mid = beg + (last - beg) / 2; if((n+1) * (n+2) / 2 - mid * (mid + 1) / 2 >= n * (n + 1) / 2){ ans = mid; beg = mid + 1; } else last = mid - 1; } cout << n - ans + 1 << "\n"; } signed main(){ int t = 1; // cin >> t; for(int i = 1 ; i <= t ; i++){ solve(); } }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll = int64_t; using ull = uint64_t; using pll = pair<ll,ll>; const ll INF = 4e18; void print0() {} template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);} void print() { print0("\n"); } template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);} // clang-format on ll a,b,c; vector<vector<vector<double>>> memo(101, vector<vector<double>>(101, vector<double>(101, -INF))); double rec(ll i,ll j,ll k){ if(i==100||j==100||k==100)return 0; if(memo[i][j][k]>-INF+100)return memo[i][j][k]; return memo[i][j][k] = (rec(i+1,j,k) + 1) * i / (i+j+k) + (rec(i,j+1,k) + 1) * j / (i+j+k) + (rec(i,j,k+1) + 1) * k / (i+j+k); } int main() { cin >>a>>b>>c; print(rec(a,b,c)); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, m, n) for (int i = (m); i < (int)(n); i++) using ll = long long; using vl = vector<ll>; using P = pair<ll, int>; ll solve(vl& A, map<P, ll>& m, ll x, int i) { if (i == int(A.size()) - 1) return 1; if (m.count(P(x, i))) return m[P(x, i)]; ll d = x % A[i + 1]; ll ret = solve(A, m, x - d, i + 1); if (d > 0) ret += solve(A, m, x + (A[i + 1] - d), i + 1); return m[P(x, i)] = ret; } int main() { // input ll N, X; cin >> N >> X; vl A(N); rep(i, N) cin >> A[i]; // solve map<P, ll> m; ll ans = solve(A, m, X, 0); cout << ans << endl; }
#include <bits/stdc++.h> #define NIL (-1) #define ll long long using namespace std; const double PI = acos(-1.0); int main() { int A, B , C; cin >> A >> B >> C; char ans; if (A >= 0 && B >= 0) { if (A == B) ans = '='; else if (A < B) ans = '<'; else ans = '>'; } else if (A < 0 && B < 0) { if (C & 1) { if (A == B) ans = '='; else if (A < B) ans = '<'; else ans = '>'; } else { if (A == B) ans = '='; else if (A < B) ans = '>'; else ans = '<'; } } else { if (C & 1) { if (A == B) ans = '='; else if (A < B) ans = '<'; else ans = '>'; } else { if (abs(A) == abs(B)) ans = '='; else if (abs(A) < abs(B)) ans = '<'; else ans = '>'; } } cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main(){ int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; int r = r2 - r1, c = c2 - c1; int ans = 3; if(!r && !c) ans = 0; else if(r == c || r == -c || abs(r) + abs(c) <= 3) ans = 1; else if((r ^ c ^ 1) & 1 || abs(r + c) <= 3 || abs(r - c) <= 3 || abs(r) + abs(c) <= 6) ans = 2; cout << ans << endl; }
// #pragma comment(linker, "/stack:200000000") // #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #include <iostream> #include <limits.h> #include <string> #include <unordered_map> #include <unordered_set> #include <cstring> #include <chrono> #include <vector> #include <map> #include <random> #include <set> #include <algorithm> #include <math.h> #include <cstdio> #include <stdio.h> #include <queue> #include <bitset> #include <cstdlib> #include <deque> #include <cassert> #include <stack> #include <memory> using namespace std; // #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; // typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define emb emplace_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define endl '\n' #define uset unordered_set #define umap unordered_map #define pii pair<int, int> #define pll pair<long long, long long> #define ld long double mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline T range(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } template <typename T> void Min(T &a, T b) { a = min(a, b); } template <typename T> void Max(T &a, T b) { a = max(a, b); } const ll INF = 2e18; const int inf = 0x3f3f3f3f; const int N = 1e2 + 5; int n, m, k; int dp[N][N * N * N]; int p[N]; inline int add(int a, int b) { a += b; if(a >= m) return a - m; if(a < 0) return a + m; return a; } inline void add_t(int &a, int b) { a = add(a, b); } inline int mul(int a, int b) { return 1LL * a * b % m; } main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); cin >> n >> k >> m; dp[0][0] = 1; for(int i = 1; i <= n; ++i) { memset(p, 0, sizeof(p)); for(int j = 0; j <= n * n * k; ++j) { add_t(p[j % i], dp[i-1][j]); dp[i][j] = p[j % i]; if(j >= i * k) add_t(p[j % i], -dp[i-1][j - i * k]); } } for(int x = 1; x <= n; ++x) { int res = 0; for(int i = 1; i <= n * n * k; ++i) add_t(res, mul(1LL * dp[x-1][i] * dp[n-x][i] % m, k + 1)); cout << add(res, k) << endl; } return 0; }
#include<bits/stdc++.h> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;} template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;} int readint(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } const int cys=998244353; int n; int a[105],d[105][10005],fac[105]; int mod(int x){return x>=cys?x-cys:x;} void add(int &x,int y){x=mod(x+y);} int main(){ n=readint(); for(int i=1;i<=n;i++) a[i]=readint(); d[0][0]=1; int sum=0; for(int i=1;i<=n;i++){ for(int j=i-1;j>=0;j--) for(int k=sum;k>=0;k--) add(d[j+1][k+a[i]],d[j][k]); sum+=a[i]; } if(sum&1) return printf("0\n"),0; fac[0]=1; for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%cys; ll ans=0; for(int i=1;i<=n;i++) ans=(ans+1ll*fac[i]*fac[n-i]%cys*d[i][sum/2])%cys; printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int a,b; cin >> a >> b; if (a+b >= 15 && b >=8){ cout << 1 << endl; } else if (a+b >=10 && b>=3){ cout << 2 << endl; } else if (a+b>=3){ cout << 3 << endl; } else{ cout << 4 << endl; } }
#define _CRT_SECURE_NO_WARNINGS #define _SCL_SECURE_NO_WARNINGS #include <cstdio> #include <cstdlib> #include <cstring> #include <cassert> #include <iostream> #include <string> #include <vector> #include <list> #include <utility> #include <algorithm> #include <functional> #include <cmath> #include <stack> #include <queue> #include <set> #include <map> #include <iomanip> #include <sstream> #include <bitset> #include <limits> #include <numeric> #include <valarray> #include <fstream> #include <array> #include <random> #include <unordered_set> #include <unordered_map> using namespace std; using uint = uint32_t; using LL = int64_t; using ULL = uint64_t; using PP = pair<LL, LL>; template <typename T> using PriorityQ = priority_queue<T, vector<T>, greater<T> >; #define REP(i, a, n) for(LL i = (a), i##_max_ = (n); i < i##_max_; ++i) #define REM(i, a, n) for(LL i = (LL)(n) - 1, i##_min_ = (a); i >= i##_min_; --i) #define FLOAT fixed << setprecision(16) #define SPEEDUP { cin.tie(NULL); ios::sync_with_stdio(false); } const int INF = 0x3FFFFFFF; const LL INFLL = 0x3FFFFFFF3FFFFFFF; const double INFD = 1.0e+308; const double EPS = 1.0e-9; void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } template <class T, class U> istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; } template <class T, class U> ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; } template <class T, class TCompatible, size_t N> void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); } template <class T, class TCompatible, size_t M, size_t N> void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); } template <class T> T Next() { T buf; cin >> buf; return buf; } istream& Ignore(istream& ist) { string s; ist >> s; return ist; } bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h&& j >= 0 && j < w; } #ifdef ONLY_MY_ENVIR #include "Accumulator.h" #include "Algebraic.h" #include "BinaryMatrix.h" #include "BinaryTree.h" #include "Bipartite.h" #include "BIT.h" #include "Compressor.h" #include "Decompositions.h" #include "DiscreteLog.h" #include "DynamicMod.h" #include "Exponential.h" #include "Factorization.h" #include "FFT.h" #include "FlowSolver.h" #include "Geometric2D.h" #include "Geometric2DFloat.h" #include "Geometric3D.h" #include "Geometric3DFloat.h" #include "Graph.h" #include "GraphUtil.h" #include "Interpolation.h" #include "IntMod.h" #include "KDTree.h" #include "LazySegmentTree.h" #include "LIS.h" #include "List.h" #include "Math.h" #include "MathUtil.h" #include "Matrix.h" #include "MinCostFlowSolver.h" #include "MinMax.h" #include "Numbers.h" #include "Optimize.h" #include "Permutation.h" #include "Polynomial.h" #include "Position.h" #include "Random.h" #include "Range.h" #include "Rational.h" #include "RollingHash.h" #include "RuntimeMod.h" #include "SegmentTree.h" #include "SegmentTree2D.h" #include "Sets.h" #include "Shortest.h" #include "SlidingWindow.h" #include "SpanningTree.h" #include "StringSearching.h" #include "SuffixArray.h" #include "SwitchList.h" #include "Timer.h" #include "Tree.h" #include "TreeUtil.h" #include "UnionFind.h" #include "Util.h" #include "VectorUtil.h" #endif #ifdef __GNUC__ typedef __int128 LLL; istream& operator>>(istream& ist, __int128& val) { LL tmp; ist >> tmp; val = tmp; return ist; } ostream& operator<<(ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; } #endif LL a, b; int main() { cin >> a >> b; bool ok = false; for (LL i = 1; i * i <= b; ++i) { if (b % i != 0) continue; LL j = b / i; if (i + j == a) { ok = true; } } YesNo(ok); return 0; }
#include<bits/stdc++.h> int main(){ using namespace std; unsigned long N, K; cin >> N >> K; vector<pair<unsigned long, unsigned long>> fr(N); for(auto&& [a, b] : fr)cin >> a >> b; sort(begin(fr), end(fr)); unsigned long now{K}; for(const auto& [a, b] : fr)if(now < a)return 0 & printf("%lu\n", now); else now += b; cout << now << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(void) { int n; long long k; long long x, y; vector<pair<long long, long long> >a; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x >> y; a.push_back({ x,y }); //a[i].first=A_i, a[i].second=B_i } sort(a.begin(), a.end()); for (int i = 0; i < n; i++) { if (a[i].first > k)break; k += a[i].second; } cout << k << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(hoge) (hoge).begin(), (hoge).end() #define en '\n' using ll = long long; using ull = unsigned long long; #define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i) #define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i) #define REP(i, n) rep(i, 0, n) #define REP2(i, n) rep2(i, 0, n) template<class T> using vec = vector<T>; template<class T> using vvec = vector<vec<T>>; typedef pair<ll, ll> P; using tp = tuple<ll, ll, ll>; constexpr long long INF = 1LL << 60; constexpr int INF_INT = 1 << 25; //constexpr long long MOD = (ll) 1e9 + 7; constexpr long long MOD = 998244353LL; using ld = long double; static const ld pi = 3.141592653589793L; using Array = vector<ll>; using Matrix = vector<Array>; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } struct Edge { ll to, cap, rev; Edge(ll _to, ll _cap, ll _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) { G[from].push_back(Edge(to, cap, (ll) G[to].size())); if (revFlag) G[to].push_back(Edge(from, revCap, (ll) G[from].size() - 1)); } void solve() { ll n; cin>>n; REP(i,n){ cout<<(2*i)%n+1<<" "<<(2*i+1)%n+1<<en; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); /* ll t; cin >> t; REP(i, t - 1) { solve(); }*/ solve(); return 0; }
#include<cstdio> int n,u; int main() { scanf("%d",&n); if(n==1) { puts("1 1"); return 0; } for(u=1;u<n;u*=2); for(int i=0,x;i<n;++i) { x=i<<1&u-1; if(x<n) printf("%d ",(x)+1); else printf("%d ",(x^u>>1)+1); if(x+1<n) printf("%d\n",(x+1)+1); else printf("%d\n",(x+1^u>>1)+1); } return 0; }
#pragma region Macros #include <bits/stdc++.h> using namespace std; using ll = long long; #define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i) #define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i) #define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME #define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__) #define RREP2(i, n) for (int i = (n - 1); i >= 0; --i) #define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i) #define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME #define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__) #define IN(type, n) type n; cin >> n #define INALL(type, v) REP(i, v.size()) { IN(type, _tmp); v.at(i) = _tmp; } #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #ifdef _DEBUG #define DEBUG(x) cout << #x << ": " << x << endl #else #define DEBUG(x) #endif template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } void yes() { cout << "Yes" << endl; } void no() { cout << "No" << endl; } #pragma endregion void set_values(int A, int B, int C, vector<vector<vector<double> > > &values, double val) { values.at(A).at(B).at(C) = val; values.at(A).at(C).at(B) = val; values.at(B).at(A).at(C) = val; values.at(B).at(C).at(A) = val; values.at(C).at(A).at(B) = val; values.at(C).at(B).at(A) = val; } double calc(int A, int B, int C, vector<vector<vector<double> > > &values) { if (A == 100 || B == 100 || C == 100) return 0.0; if (values.at(A).at(B).at(C) != -1) return values.at(A).at(B).at(C); double ans = 0.0; if (A != 0) ans += (1.0 + calc(A + 1, B, C, ref(values))) * A / (A + B + C); if (B != 0) ans += (1.0 + calc(A, B + 1, C, ref(values))) * B / (A + B + C); if (C != 0) ans += (1.0 + calc(A, B, C + 1, ref(values))) * C / (A + B + C); set_values(A, B, C, ref(values), ans); return ans; } int main() { IN(int, A); IN(int, B); IN(int, C); vector<vector<vector<double> > > values(100, vector<vector<double> >(100, vector<double>(100, -1))); cout << fixed << setprecision(6); cout << calc(A, B, C, ref(values)) << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long const int mx=200100; double ans[101][101][101]; bool vis[101][101][101]; double dfs(int i,int j,int k){ if(vis[i][j][k]) return ans[i][j][k]; vis[i][j][k]=1; if(!i||!j||!k) return ans[i][j][k]=0.0; double fm=300-(i+k+j); ans[i][j][k]+=1.0*(100-i)/fm*dfs(i-1,j,k); ans[i][j][k]+=1.0*(100-j)/fm*dfs(i,j-1,k); ans[i][j][k]+=1.0*(100-k)/fm*dfs(i,j,k-1); ans[i][j][k]+=1.0; return ans[i][j][k]; } int main(){ // ios::sync_with_stdio(0); int a,b,c; // cin>>a>>b>>c; scanf("%d %d %d",&a,&b,&c); printf("%.8lf",dfs(100-a,100-b,100-c)); return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; co((N + 99) / 100); Would you please return 0; }
#include <bits/stdc++.h> using namespace std; #define vi vector<int> #define pb push_back #define vli vector<long long int> #define mp make_pair #define pii pair<ll, ll> typedef long long ll; #define mii map<int, int> #define mod 1000000007 #define vstr vector<string> #define setval(a, v) memset(a, v, sizeof(a)) #define ff first #define ss second #define oo (1LL << 30) #define endl "\n" int main() { ll n; cin>>n; if(n%100==0) { cout<<n/100; } else { cout<<(n/100)+1; } /*if(n<=100) { cout<<"1"; }else { int cnt=0; while(n>100) { n-=100; cnt++; } cout<<cnt; }*/ }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int,int>; using T = tuple<int,int,int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int charToInt(char c){ char zero_num = '0'; return (int)c - (int)zero_num; } signed main(){ double A; cin>>A; double B; cin>>B; cout<<fixed<<setprecision(10)<<100.- B/A*100.<<endl; return 0; }
#include <iostream> using namespace std; int main(void) { int A, B; cin >> A >> B; cout << (A-B)*100./A << endl; return 0; }
/* CREATED BY STREAM_CIPHER nov-2020 */ #include<bits/stdc++.h> using namespace std; void __print(long long x) {cerr << x;}void __print(unsigned long long x) {cerr << x;}void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';}void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long int #define double long double #define fix_precision(n) cout<<fixed<<setprecision(n) #define all(a) a.begin(),a.end() const double pi=acos(-1.0); int inf=0x3f3f3f3f3f3f3f3f; const int mod=1e9+7; const int mx=5*1000000;//5*64M bit ->5*8M byte ->40MB size for long long int (64 bit) int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif int n; cin>>n; vector<int>a; int nn=n; if(n%3==0) { cout<<"0\n"; return 0; } int sum=0; while(nn>0) { a.push_back(nn%10); sum+=nn%10; nn/=10; } int rem_1=0,rem_2=0,rem_0=0; for(auto i:a) { if(i%3==1) rem_1++; if(i%3==2) rem_2++; if(i%3==0) rem_0++; } if(sum%3==1) { if(rem_1>0) { rem_1--; if(rem_1+rem_2+rem_0>0) cout<<"1\n"; else cout<<"-1\n"; } else { if(rem_0>0) { cout<<rem_2<<endl; } else cout<<"-1\n"; } } if(sum%3==2) { if(rem_2>0) { if(rem_2-1+rem_1+rem_0>0) cout<<"1\n"; else { if(rem_1>1) { rem_1-=2; if(rem_0+rem_1+rem_2>0) cout<<"2\n"; else cout<<"-1\n"; } else { if(rem_0>0) cout<<rem_1+rem_2<<endl; else cout<<"-1\n"; } } } else { if(rem_1>1) { rem_1-=2; if(rem_0+rem_1+rem_2>0) cout<<"2\n"; else { if(rem_0>0) cout<<rem_1+rem_2<<endl; else cout<<"-1\n"; } } else { if(rem_0>0) cout<<rem_1+rem_2<<endl; else cout<<"-1\n"; } } } } //always use s.lower_bound instead of lower_bound(all(s)) //also whenever there exist an standerd method for stl container prefer that //otherwise this will happen //https://codeforces.com/contest/1435/submission/96683823//tle //https://codeforces.com/contest/1435/submission/96703923//accepted
#include<iostream> #include<cstdio> using namespace std; int a[5]={0}; int main() { char ch; int mid=0; while(scanf("%c",&ch)!=EOF) { if(ch>'9'||ch<='0') break; a[(ch-'0')%3]++; mid+=(ch-'0')%3; } mid%=3; if(!mid) { cout<<0; return 0; } if(a[mid]>1||(a[mid]==1&&a[0]+a[3-mid])) { cout<<1; return 0; } if(mid==2&&(a[1]>2||(a[1]==2)&&a[0]+a[2])) { cout<<2; return 0; } if(mid==1&&(a[2]>2||(a[2]==2&&a[0]+a[1]))) { cout<<2; return 0; } cout<<-1; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long vector<int>bit(200001); void update(int x, int val){ for(int a = x; a<=200000; a+=a&-a){ bit[a]+=val; } } int query(int x){ int sum = 0; for(int a = x; a>0; a-=a&-a){ sum+=bit[a]; } return sum; } signed main(){ cin.tie(nullptr)->sync_with_stdio(false); int r,c,m; cin >> r >> c >> m; vector<int>mnv(c+1, r+1); vector<int>mnh(r+1, c+1); for(int i = 0; i<m; i++){ int x,y; cin >> x >> y; mnv[y] = min(mnv[y],x); mnh[x] = min(mnh[x],y); } int ans = 0; set<pair<int,int>>s; for(int i = 2; i<mnh[1]; i++){ int val = mnv[i]-1; ans+=val; s.insert({mnv[i],i}); } for(int i = mnh[1]; i<=c; i++){ update(i,1); } //cout << ans << "\n"; update(1,1); int cur = 1; for(int i = 2; i<mnv[1]; i++){ if(s.size()>0) while(s.size()>0&&(*s.begin()).first+1<=i){ update((*s.begin()).second,1); s.erase(s.begin()); } ans+=query(mnh[i]-1); //cout << ans << "\n"; } cout << ans+1 << "\n"; return 0; }
/* author : sgupta_2001 */ #include<bits/stdc++.h> using namespace std; using db = double; using ll = long long; using ld = long double; using ull = unsigned long long; //containers #define sz(x) int((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) x.rbegin(), x.rend() #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define eb emplace_back #define pf push_front //pairs #define mp make_pair #define ff first #define ss second //loops #define rep(i, a, b) for(int i = a; i < b; ++i) #define per(i, a, b) for(int i = b - 1; i >= a; --i) #define each(x, a) for(auto &x : a) //popular constants const int mod = 1e9 + 7; //998244353; const ll inf = 1e18; const ld pie = acos((ld) - 1); //grid problems const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //modulo operations ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} #ifdef SGUPTA_2001 #define deb(x) cerr<< #x <<" "; __print(x); cerr<<'\n'; #else #define deb(x); #endif //debug containers template<class T> void __print(T x) {cerr<<x;} template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";} template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; } template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";} template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";} template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";} template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";} template<typename... T> void read(T&... args) { ((cin>>args),...);} template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';} void solve() { int N, A, B; scanf("%d%d%d", &N, &A, &B); printf("%d\n", N - A + B); return; } int main() { #ifdef SGUPTA_2001 freopen("input.txt", "r", stdin); freopen("error.txt", "w", stderr); #endif auto start = std::chrono::high_resolution_clock::now(); int t; t=1; while(t--) solve(); auto stop = std::chrono::high_resolution_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start); // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< '\n'; /* STUFF TO LOOK: 1. Check the constraints 2. Corner cases(n == 0 || n == 1) 3. Variables in loops 4. Make sure two ints aren’t multiplied to get a long long */ return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <string> #include <map> #define amax(a, b) a = max(a, b) #define amin(a, b) a = min(a, b) using ll = long long; using P = std::pair<ll, int>; #define fi first #define se second int main() { int n; std::cin >> n; std::map<ll, int> cnt; for (int i=0; i<n; i++) { ll ai; std::cin >> ai; cnt[ai]++; } while (cnt.size() > 1) { ll x = cnt.begin()->fi; auto [X, X_cnt] = *(--cnt.end()); cnt.erase(X); cnt[X-x] += X_cnt; } std::cout << cnt.begin()->fi << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define mx INT_MAX #define mi INT_MIN #define pb push_back #define mp make_pair #define YES cout<<"YES\n"; #define Yes cout<<"Yes\n"; #define NO cout<<"NO\n"; #define No cout<<"No\n"; #define all(v) (v).begin(),(v).end() #define ff first #define ss second #define vi vector<int> #define vpii vector< pair<int,int> > #define si set<int> ll md=1e9+7; ll __gcd(ll a, ll b) {if(b==0) return a; return __gcd(b, a%b);} ll poww(ll a, ll b) {ll res=1;while(b) {if(b&1){res*=a;res%=md;}a*=a;a%=md;b>>=1;}return res;} void ainp(int arr[], int n) {for(int i=0;i<n;i++) cin>>arr[i];} void fast() {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);} void solve() { int n,i,m=INT_MAX,p=INT_MAX; cin>>n; int a[n]; for(i=0;i<n;i++) { cin>>a[i]; m=min(m,a[i]); } for(i=0;i<n;i++) { a[i]=__gcd(m,a[i]); p=min(p,a[i]); } cout<<p; } int main() { fast(); int t; //cin>>t; t=1; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<long long>; using vvl = vector<vector<long long>>; using pii = pair<int, int>; #define rep(i, s, n) for (int i = (int)s; i < (int)n; i++) #define repr(i, n, s) for (int i = (int)n; (int)s < i; i--) #define len(a) (int)a.size() #define all(a) a.begin(), a.end() #define debug(var) if(DEBUG) do{cout << #var << " : "; print(var);}while(0) template<typename T> void print(T e){cout << e << '\n';} template<typename T> void print(const vector<T>& v){string s=""; for(auto& e : v){s+=to_string(e)+' ';} s.pop_back(); cout << s << '\n';} template<typename T> void print(const vector<vector<T>>& vv){cout << '\n'; for(auto& v : vv){print(v);}} template<typename T> void print(const set<T>& v){string s=""; for(auto& e : v){s+=to_string(e)+' ';} s.pop_back(); cout << s << '\n';} template<typename T> void print(const list<T>& v){string s=""; for(auto& e : v){s+=to_string(e)+' ';} s.pop_back(); cout << s << '\n';} template<typename T> inline bool chmin(T &a, T b) {if(a>b) {a=b; return true;} return false;} template<typename T> inline bool chmax(T &a, T b) {if(a<b) {a=b; return true;} return false;} template<typename T> T mod(T a, T m) {return (a % m + m) % m;} const int INF32 = INT_MAX / 2; const long long INF64 = LONG_LONG_MAX / 2; const long long MOD = 1000000007; const double PI = acos(-1); const bool DEBUG = false; int main() { int N; cin >> N; if (N == 1) { print("Yes"); return 0; } vector<pair<int, int>> S, T; int x1c=0, y1c=0, x2c = 0, y2c = 0; rep(i, 0, N) { double a, b; cin >> a >> b; S.push_back(make_pair(a * N, b * N)); x1c += a; y1c += b; } rep(i, 0, N) { double c, d; cin >> c >> d; T.push_back(make_pair(c * N, d * N)); x2c += c; y2c += d; } // 重心を原点に移動 rep(i, 0, N) { S[i] = make_pair(S[i].first - x1c, S[i].second - y1c); T[i] = make_pair(T[i].first - x2c, T[i].second - y2c); } // Sの基準vectorを決める。(0, 0以外) int ibase; rep(i, 0, N) { if (abs(S[i].first) + abs(S[i].second) >= 1) { ibase = i; break; } } // Sの基準との距離、クロス積、内積のtupleを計算。並び替え。 vector<tuple<int, int, int>> S2; rep(i, 0, N) { if (i == ibase) continue; int x, y, x0, y0, dist, cp, ip; tie(x0, y0) = S[ibase]; tie(x, y) = S[i]; dist = (int)(pow(x - x0, 2) + pow(y - y0, 2)); cp = x0 * y - y0 * x; ip = x0 * x + y0 * y; S2.emplace_back(dist, cp, ip); } sort(all(S2)); // Tの各々の基準vectorについて bool ans = false; rep(i, 0, N) { bool ok = true; //  距離、クロス積、内積のtupleを計算 vector<tuple<int, int, int>> T2; rep(j, 0, N) { if (j == i) continue; int x, y, x0, y0, dist, cp, ip; tie(x0, y0) = T[i]; tie(x, y) = T[j]; dist = (int)(pow(x - x0, 2) + pow(y - y0, 2)); cp = x0 * y - y0 * x; ip = x0 * x + y0 * y; T2.emplace_back(dist, cp, ip); } sort(all(T2)); // set同士で比較。全部ほぼ一致ならTrue, break int eps = 0.1; rep(i, 0, N - 1) { int dist1, cp1, ip1, dist2, cp2, ip2; tie(dist1, cp1, ip1) = S2[i]; tie(dist2, cp2, ip2) = T2[i]; if (abs(dist2 - dist1) > eps || abs(cp2 - cp1) > eps || abs(ip2 - ip1) > eps) { ok = false; break; } } if (ok) { ans = true; break; } } if (ans) { print("Yes"); } else { print("No"); } }
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N; vector<ll> X1; vector<ll> Y1; vector<ll> X2; vector<ll> Y2; ll d(ll x1, ll y1, ll x2, ll y2){ ll dx = x1 - x2; ll dy = y1 - y2; return dx * dx + dy * dy; } ll c(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3){ ll dx = x1 - x2; ll dy = y1 - y2; ll dx2 = x1 - x3; ll dy2 = y1 - y3; return dx * dy2 - dx2 * dy; } vector<pair<ll,pair<ll,ll>>> f(vector<ll>& X, vector<ll>& Y){ vector<pair<ll,pair<ll,ll>>> res; int n = X.size()-2; rep(i,n){ ll z1 = d(X[i],Y[i],X[n],Y[n]); ll z2 = d(X[i],Y[i],X[n+1],Y[n+1]); ll z3 = c(X[i],Y[i],X[n],Y[n],X[n+1],Y[n+1]); res.push_back({z1,{z2,z3}}); } sort(res.begin(),res.end()); return move(res); } int main(){ cin >> N; X1.resize(N); Y1.resize(N); rep(i,N) cin >> X1[i] >> Y1[i]; X2.resize(N); Y2.resize(N); rep(i,N) cin >> X2[i] >> Y2[i]; if(N == 1){ cout << "Yes\n"; return 0; } rep(i,N) rep(j,i) rep(t,2){ if(d(X2[i],Y2[i],X2[j],Y2[j]) != d(X1[N-2],Y1[N-2],X1[N-1],Y1[N-1])) continue; swap(X2[i],X2[N-1]); swap(Y2[i],Y2[N-1]); swap(X2[j],X2[N-2]); swap(Y2[j],Y2[N-2]); if(f(X1,Y1) == f(X2,Y2)){ cout << "Yes\n"; return 0; } swap(X2[j],X2[N-2]); swap(Y2[j],Y2[N-2]); swap(X2[i],X2[N-1]); swap(Y2[i],Y2[N-1]); swap(X2[i],X2[j]); swap(Y2[i],Y2[j]); } cout << "No\n"; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;
#include<bits/stdc++.h> using namespace std; #define ll long long #define lson rt<<1,l,mid #define rson rt<<1|1,mid+1,r int a,b,x,y; int solve() { if(a==b) return x; int dis=abs(a-b); dis--; int ans=x; if(a>b) ans+=dis*min(y,2*x); if(a<b) ans+=(dis+1)*min(y,2*x); return ans; } int main() { //freopen("1.txt","r",stdin); scanf("%d%d%d%d",&a,&b,&x,&y); cout<<solve()<<endl; //fclose(stdin); }
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c,d=0; cin>>a>>b>>c; if(a==1) d=d+6; else if(a==2) d=d+5; else if(a==3) d=d+4; else if(a==4) d=d+3; else if(a==5) d=d+2; else if(a==6) d=d+1; if(b==1) d=d+6; else if(b==2) d=d+5; else if(b==3) d=d+4; else if(b==4) d=d+3; else if(b==5) d=d+2; else if(b==6) d=d+1; if(c==1) d=d+6; else if(c==2) d=d+5; else if(c==3) d=d+4; else if(c==4) d=d+3; else if(c==5) d=d+2; else if(c==6) d=d+1; cout<<d<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; for (int i=1; i<=n; i++) { cout << (2*i-2)%n+1 << " " << (2*i-1)%n+1 << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i) #define irreps(i, m, n) for (long long i = ((long long)(n)-1); i > (long long)(m); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v+n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cinline(n) getline(cin,n); #define replace_all(s, b, a) replace(s.begin(),s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) (long long)(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using vtp = vector<tuple<ll,ll,ll>>; using vb = vector<bool>; using ld = long double; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; const ll INF = 1e9+10; const ll MOD = 1e9+7; const ll LINF = 1e18; signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); ll k; cin>>k; ll ans=0; reps(i,k){ for(int j=1; j*i<=k; j++){ ll x=i*j; ans+=k/x; } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(x) x.begin(), x.end() int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n); for(auto &v: a) cin >> v, v %= 200; n = min(8, n); vector<vector<int>> dp(200); for(int mask = 1; mask < (1 << n); ++mask){ int cur_mod = 0; vector<int> local; for(int j = 0; j < n; ++j){ if(mask & (1 << j)){ cur_mod = (cur_mod + a[j]) % 200; local.push_back(j + 1); } } if(dp[cur_mod].empty()){ dp[cur_mod] = local; }else{ cout << "Yes" << "\n"; cout << dp[cur_mod].size() << " "; for(auto i : dp[cur_mod]) cout << i << " "; cout << "\n"; cout << local.size() << " "; for(auto i : local) cout << i << " "; cout << "\n"; exit(0); } } cout << "No" << "\n"; }
#include <bits/stdc++.h> using namespace std; int dp[210][210]; int mod(int x) { return (x + 200 * 10) % 200; } int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; a[i] %= 200; } for (int i = 0; i < n; i++) { for (int sum = 0; sum < 200; sum++) { if (sum == 0) { dp[i + 1][mod(sum + a[i])] += 1; } dp[i + 1][sum] += dp[i][sum]; dp[i + 1][mod(sum + a[i])] += dp[i][sum]; } } bool ok = false; int sum = 0, last = 0; for (int i = 0; i <= n and ok == false; i++) { for (int j = 0; j < 200 and ok == false; j++) { if (dp[i][j] >= 2) { ok = true; sum = j; last = i; break; } } } // for (int i = 0; i <= n; i++) { // for (int j = 0; j < 200; j++) { // cout << dp[i][j] << " "; // } // cout << endl; // } // cout << sum << " " << last << endl; if (ok == false) { cout << "No" << endl; return 0; } vector<int> b, c; b.push_back(last - 1); int cur = mod(sum - a[last - 1]); for (int i = last - 1; i - 1 >= 0; i--) { if (dp[i][cur] != dp[i - 1][cur]) { cur = mod(cur - a[i - 1]); b.push_back(i - 1); } } cur = sum; if (dp[last - 1][cur] == 0) c.push_back(last - 1); else { for (int i = last - 1; i - 1 >= 0; i--) { if (dp[i][cur] != dp[i - 1][cur]) { cur = mod(cur - a[i - 1]); c.push_back(i - 1); } } } sort(b.begin(), b.end()); sort(c.begin(), c.end()); cout << "Yes" << endl; cout << b.size() << " "; for (int e : b) cout << e + 1 << " "; cout << endl; cout << c.size() << " "; for (int e : c) cout << e + 1 << " "; cout << endl; }
#include<bits/stdc++.h> using namespace std; int mx=200005; bool prime[200005]; vector <int> vec; void normal_sieve(int n) { int i, N=sqrt(n), p; memset(prime, 1, sizeof(prime)); for(p=3; p<=N; p+=2) { if(prime[p]==1) { for(i=p*p; i<=n; i+=p) { prime[i]=0; } } } vec.push_back(2); for(i=3; i<200001; i+=2) { if(prime[i] == 1) vec.push_back(i); } } int main() { int a,b; cin >> a >> b; int mx = 0; int dif = b-a; for(int i=dif; i>=0; i--) { int low = ceil(a*1.0/i); int high = floor(b*1.0/i); if(low*i >= a && low*i<=b && high*i>=a && high*i<=b && low!=high) { mx = i; break; } } cout << mx << endl; return 0; }
#include <iostream> #include <algorithm> #include <stack> #include <queue> #include <vector> #include <bitset> #include <iomanip> #include <cmath> #include <set> #include <unordered_set> #include <functional> #include <map> #include <unordered_map> #include <string> #include <tuple> using namespace std; using ll = long long; const int MOD=1e9+7; const int MAX=100009; ll fac[100009],finv[100009],inv[100009]; #define pi 3.14159265358979323846 #define ee 2.71828182845904523536 #define INF 1e18+1 ll gcd(ll x, ll y) { // 最大公約数 if (y == 0)return x; else return gcd(y, x % y); } bool prime(ll x) { //素数判定 if(x==1)return false; if (x!=2&&x % 2 == 0)return false; for (ll i = 3; i <= sqrt(x); i+=2) { if (x % i == 0)return false; } return true; } ll modinv(ll a, ll m) { //逆元 long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll modpow(ll a, ll n, ll mod) { //二分累乗法 ll res = 1; while (n) { if (n % 2)res = res * a % mod; a = a * a % mod; n /= 2; } return res; } void COMinit() { //二項係数計算の前処理 fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(int n, int k){ //二項係数計算 if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } struct UnionFind { // UnionFind vector<int> par; vector<int> siz; UnionFind(int N) : par(N), siz(N, 1) { for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; if (par[rx] > par[ry])swap(rx, ry); siz[rx] += siz[ry]; par[ry] = rx; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } int size(int x) { return siz[root(x)]; } }; int main() { int a,b; cin>>a>>b; if(a>b){ for(int i=0;i<a;i++){ cout<<i+1<<" "; } int sum=a*(a+1)/2; for(int i=0;i<b-1;i++){ cout<<-(i+1)<<" "; sum-=(i+1); } cout<<-sum<<endl; } else{ for(int i=0;i<b;i++){ cout<<-(i+1)<<endl; } int sum=b*(b+1)/2; for(int i=0;i<a-1;i++){ cout<<i+1<<" "; sum-=(i+1); } cout<<sum<<endl; } }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for(int i = 0; i < (n); i++) #define reps(i, s, n) for(int i = (s); i < (n); i++) #define rrep(i, n) for(int i = (n) - 1; i >= 0; i--) #define rreps(i, s, n) for(int i = (n) - 1; i >= (s); i--) #define INF ~(1 << 31) #define INFL ~(1LL << 63) int main() { int N; cin >> N; vector<int> p(N); vector<bool> used(N+1); int ans = 0; rep(i, N){ cin >> p[i]; used[p[i]] = true; if(ans == p[i]){ reps(i, ans+1, N+1){ if(!used[i]){ ans = i; break; } } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vector<int64_t> x(N); for (int i = 0; i < N; i++) { cin >> x[i]; } int64_t man = 0; for (int i = 0; i < N; i++) { man += abs(x[i]); } cout << man << "\n"; double euclid = 0; for (int i = 0; i < N; i++) { euclid += pow(x[i],2); } cout << setprecision(12) << fixed; cout << sqrt(euclid) << "\n"; int64_t cheby = 0; for (int i = 0; i < N; i++) { cheby = max(cheby, abs(x[i])); } cout << cheby << "\n"; }
#include <bits/stdc++.h> int nextInt() { int temp; scanf("%d", &temp); return temp; } long long nextLL() { long long temp; scanf("%lld", &temp); return temp; } void print(int x, char endc = '\n') { printf("%d%c", x, endc); return; } void print(long long x, char endc = '\n') { printf("%lld%c", x, endc); return; } void print(size_t x, char endc = '\n') { printf("%zu%c", x, endc); return; } void print(float x, char endc = '\n') { printf("%f%c", x, endc); return; } void print(double x, char endc = '\n') { printf("%lf%c", x, endc); return; } template<typename T1, typename T2> void print(std::pair<T1, T2> &p, char sepc = ' ', char endc = '\n') { print(p.first, sepc); print(p.second, endc); return; } template<typename T> void print(std::vector<T> &v, char sepc = ' ', char endc = '\n') { for(T e : v) print(e, sepc); printf("%c", endc); return; } using namespace std; const int MAX_V = 2000; const long long int INF = 96543219987654321; int V; vector<pair<int, long long> > adj[MAX_V]; void pushAllAdj(int here, vector<long long> &dist, long long cost, priority_queue<pair<long long, int>> &pq) { for(int i = 0; i < adj[here].size(); ++i) { int there = adj[here][i].first; int nextDist = cost + adj[here][i].second; if(dist[there] > nextDist) { dist[there] = nextDist; pq.push(make_pair(-nextDist, there)); } } } vector<long long> dijkstra(int src) { vector<long long> dist(V, INF); priority_queue<pair<long long, int> > pq; pushAllAdj(src, dist, 0, pq); while(!pq.empty()) { long long cost = -pq.top().first; int here = pq.top().second; pq.pop(); if(dist[here] < cost) continue; pushAllAdj(here, dist, cost, pq); } return dist; } int main() { int N = nextInt(), M = nextInt(); V = N; for(int i = 0; i < M; i++) { int A = nextInt(), B = nextInt(), C = nextInt(); adj[A-1].push_back(make_pair(B-1, C)); } for(int i = 0; i < N; i++) { auto res = dijkstra(i)[i]; print(res == INF ? -1LL : res); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, a, b) for (auto i = (a); i < (b); ++i) #define per(i, a, b) for (auto i = (b); i-- > (a); ) #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sz(x) int((x).size()) #define lb(x...) lower_bound(x) #define ub(x...) upper_bound(x) template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1 << 11, inf = 1e9; int dp[N][N], a[N][N]; void verdict(int x) { if (x == 0) cout << "Draw\n"; else cout << (x > 0 ? "Takahashi" : "Aoki") << '\n'; exit(0); } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; auto f = [&](int i, int j) { return (i ^ j) & 1; }; rep(i, 0, n) rep(j, 0, m) { char c; cin >> c; a[i][j] = c == '+' ? +1 : -1; dp[i][j] = f(i, j) ? inf : -inf; } dp[n - 1][m - 1] = 0; per(i, 0, n) { per(j, 0, m) { if (f(i, j)) { int nxt = dp[i][j] + a[i][j]; if (i > 0) ckmax(dp[i - 1][j], nxt); if (j > 0) ckmax(dp[i][j - 1], nxt); } else { int nxt = dp[i][j] - a[i][j]; if (i > 0) ckmin(dp[i - 1][j], nxt); if (j > 0) ckmin(dp[i][j - 1], nxt); } } } verdict(dp[0][0]); }
// In god we trust #include <bits/stdc++.h> #include <chrono> #include <algorithm> #include <signal.h> #include <thread> #include <pthread.h> #include <omp.h> #define pb push_back #define fi first #define se second #define Vi vector<int> #define Vb vector<bool> #define Pi pair<int, int> #define Si set<int> #define Ui unordered_map<int, int> #define MP make_pair #define MT make_tuple #define Q queue #define Qi Q<int> #define INF 1000000000 #define LINF 1000000000000000000 #define _USE_MATH_DEFINES #define int long long using namespace std; using namespace std::chrono; int mod_power(int x, int y, int mod){ int ans = 1; x %= mod; while(y){ if (y & 1) ans *= x, ans %= mod; y /= 2; x = (x * x) % mod; } return ans; } int mod_inverse(int n, int mod){ return mod_power(n, mod - 2, mod); } // Returns factorial of n int fact(int n) { int res = 1; for (int i = 2; i <= n; i++) res = res * i; } int ncr(int n, int r) { if (r > n) return 0; if (r == 0 or r == n) return 1; int fact = 1; for (int i = 1; i <= r; i++) fact *= i; int ans = 1; for (int i = n; i > n - r; i--) ans *= i; ans /= fact; return ans; } int mod_ncr(int n, int r, int mod){ if (r > n) return 0; if (r == 0 or r == n) return 1; int fact = 1; for (int i = 1; i <= r; i++) fact *= i, fact %= mod; int ans = 1; for (int i = n; i > n - r; i--) ans *= i, ans %= mod; ans *= mod_inverse(fact, mod), ans %= mod; return ans; } unordered_map<int, int> factor(int n){ int cnt = 0; unordered_map<int, int> m; int nn = n; while (!(nn & 1)) cnt++, nn /= 2; if(cnt) m[2] = cnt; for (int i = 3; i <= sqrt(n); i++){ cnt = 0; while(nn % i == 0) nn /= i, cnt++; if (cnt) m[i] = cnt; } if (nn > 2) m[nn] = 1; return m; } Vi divisors(int n){ Vi front; Vi back; for (int i = 1; i <= sqrt(n); i++){ if (n % i == 0) if (i == n / i) front.pb(i); else front.pb(i), back.pb(n / i); } for (int i = back.size() - 1; i >= 0 ; i--) front.pb(back[i]); return front; } int cnt[1500000]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); double n; cin >> n; double e = 0; for (int i = 1; i <= n - 1; i++) e = e + n / i; cout << fixed << setprecision(10) << e << endl; }
#include <iostream> #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> P; ll k,a[800][800],b[801][801],key,st=-1,go=1000000000,mid; set<ll> se,se1,se2; vector<P> v; map<ll,vector<ll>> vv; ld n,ans; ld f(ld x){ return x*(pow(2,x)-2)/pow(3,x); } int main(void){ cin>>n; for(int i=1;i<n;i++){ ans+=n/ld(n-i); } cout<<setprecision(10)<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ map<int,int> mp; int n; cin>>n; long long ans=0; for(int i=0;i<n;++i){ int x; cin>>x; int len=i-mp[x]; ans+=len; mp[x]++; } cout<<ans; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a.begin(), a.end()); long long sum = 0; int cnt = 1; for (int i = 0; i < n; i++) { if (a[i] == a[i + 1]) { cnt++; } else { sum += 1LL * cnt * (cnt - 1) / 2; cnt = 1; } } sum += 1LL * cnt * (cnt - 1) / 2; cout << 1LL * n * (n - 1) / 2 - sum << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; //全探索 int main() { int N; cin >> N; vector<vector<int>> C(N, vector<int> (N)); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++){ cin >> C.at(i).at(j); } int min = C.at(0).at(0); for (int j = 0; j < N; j++){ if(min > C.at(0).at(j)){ min = C.at(0).at(j); } } vector<int> B(N); for (int j = 0; j < N; j++){ B.at(j) = C.at(0).at(j) - min; } int minus = 0; vector<int> A(N); for (int i = 0; i < N; i++){ A.at(i) = C.at(i).at(0) - B.at(0); if(A.at(i) < minus){ minus = A.at(i); } } if(minus != 0){ for (int k = 0; k < N; k++){ A.at(k) += 0 - minus; B.at(k) += 0 - minus; } } //ここまででAとBが完成した。 string res = "Yes"; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++){ if(C.at(i).at(j) != A.at(i) + B.at(j)){ res = "No"; goto END; } } END: cout << res << endl; if(res == "Yes"){ for (int i = 0; i < N; i++){ cout << A.at(i); if(i != N - 1){ cout << " "; }else{ cout << endl; } } for (int j = 0; j < N; j++){ cout << B.at(j); if(j != N - 1){ cout << " "; }else{ cout << endl; } } } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define F first #define S second #define ALL(a) a.begin(),a.end() #define mp make_pair #define pb push_back #define FOR(i,a,b) for(int i=a;i<b;i++) #define FORN(i,a,b) for(int i=a;i<=b;i++) #define FORB(i,a,b) for(int i=a;i>=b;i--) #define INT_MAXI 2147483647 #define INT_MINI -2147483648 #define REV(a) reverse(a.begin(),a.end()) #define NP(a) next_permutation(a.begin(),a.end()) typedef pair<int,int> pi; typedef pair<ll,ll> pl; typedef vector<int> vi; typedef vector<ll> vl; int findMin(vi arr, int n) { // Calculate sum of all elements int sum = 0; for (int i = 0; i < n; i++) sum += arr[i]; // Create an array to store results of subproblems bool dp[n+1][sum+1]; // Initialize first column as true. 0 sum is possible // with all elements. for (int i = 0; i <= n; i++) dp[i][0] = true; // Initialize top row, except dp[0][0], as false. With // 0 elements, no other sum except 0 is possible for (int i = 1; i <= sum; i++) dp[0][i] = false; // Fill the partition table in bottom up manner for (int i=1; i<=n; i++) { for (int j=1; j<=sum; j++) { // If i'th element is excluded dp[i][j] = dp[i-1][j]; // If i'th element is included if (arr[i-1] <= j) dp[i][j] |= dp[i-1][j-arr[i-1]]; } } // Initialize difference of two sums. int diff = INT_MAX; for (int j=sum/2; j>=0; j--) { if (dp[n][j] == true) { diff = sum-2*j; break; } } return diff; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vi v(n); for(auto &i:v) cin >> i; int dif = findMin(v, n), sum = accumulate(ALL(v), 0); cout << (sum + dif)/2 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define watch(x) cout << (#x) << " is " << (x) << endl #define MOD 1000000007 int gcd(int a,int b){ if(a==0 || b==0){ return (a+b); } return gcd(b,a%b); } vector<int> sieve(int n){ vector<int> v(n+2,0); n++; v[0]=1; for(int i=2;i*i<n;i++){ if(!v[i]) for(int j=2*i;j<n;j+=i) v[j]++; } return v; } int fastExpo(int a,int n,int mod){ int result = 1; while ( n > 0){ if ( n&1 ) result = (result*a)%mod; a=(a*a)%mod; n>>=1; } return result; } int modInverse(int n,int mod){ return fastExpo(n,mod-2,mod); } vector<int> factorial(int n){ std::vector<int> fac(n+2,0); fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % MOD; return fac; } int __nCr(int n,int r, vector<int>& Fact,int mod){ int ans= (((Fact[n] * modInverse(Fact[r],mod))%mod) *modInverse(Fact[n-r],mod))%mod; return ans; } class Triplet{ public: int x; int y; int gcd; }; Triplet extendedEuclid(int a,int b){ if(b==0){ Triplet obj; obj.x=1; obj.y=0; obj.gcd=a; return obj; } Triplet smallans = extendedEuclid(b,a%b); Triplet ans; ans.gcd=smallans.gcd; ans.x=smallans.y; ans.y= smallans.x-(a/b)*smallans.y; return ans; } /*---------------------------------------------------------*/ void solve(int T) { int n,m; cin >> n >> m; int arr[m]; for(auto &i: arr) cin >> i; if(m==0){ cout<<1<<endl; return; } sort(arr,arr+m); int d=INT_MAX; if(arr[0]!=1){ d=arr[0]-1; } if(arr[m-1]!=n){ d=min(d,n-arr[m-1]); } for(int i=1;i<m;i++){ int gap=(arr[i]-arr[i-1])-1; if(gap!=0){ d=min(d,gap); } } //cout<<d<<endl; if(d==0 || m==n){ cout<<0<<endl;return; } int last=0; int ans=0; for(int i=0;i<m;i++){ int g=(arr[i]-last)-1; if(g<0){ continue; } ans+=ceil((1.0*g)/d); last=arr[i]; } ans+=ceil(1.0*(n-last)/d); cout<<ans<<endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("inputf.in", "r", stdin); freopen("error.out", "w", stderr); freopen("outputf.out", "w", stdout); #endif int T = 1; //cin >> T; for (int t=1;t<=T; t++) { solve(t); } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int i=0;i<n;i++) const ll MOD=20000000000000000; const long double PI=3.14159265358979; const ll MAX=100000; int main() { ll N,M; cin>>N>>M; ll a[M+2]; rep(i,M){ cin>>a[i+1]; } a[0]=0;a[M+1]=N+1; sort(a,a+M+2); vector<ll> w; rep(i,M+1){ if(a[i+1]-a[i]>1){ w.push_back(a[i+1]-a[i]-1); } } ll minw=MOD; ll ws=w.size(); rep(i,ws){ minw=min(minw,w[i]); } ll ans=0; rep(i,ws){ ans+=(w[i]-1)/minw+1; //cout<<w[i]<<ans; } cout<<ans; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i= 0;i<(n);++i) #define sz(s) (int)(s.size()) using ll = long long; using ld = long double; using P = pair<ll, ll>; using vi = vector<int> ; using vll = vector<ll>; using vvi = vector<vi> ; using vvll = vector<vll>; using vs = vector<string>; #define pb push_back #define all(a) (a).begin(),(a).end() #define SORT(v) sort((v).begin(),(v).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) const int INF = INT_MAX; const ll LLINF = LLONG_MAX; int main() { int n,m,q; cin >> n >> m >> q; vector<P> nim; rep(i,n){ ll w,v; cin >> w >> v; nim.pb({v,w}); } RSORT(nim); vector<ll> box; rep(i,m){ ll x; cin >> x; box.pb(x); } vector<int> left,right; rep(i,q){ int l,r; cin >> l >> r; l--;r--; left.pb(l); right.pb(r); } rep(i,q){ vector<ll> box2; ll ans = 0; for(int j = 0;j<left[i];j++){ box2.pb(box[j]); } for(int j = right[i] + 1; j < m;j++){ box2.push_back(box[j]); } SORT(box2); rep(j,n){ ll val = nim[j].first; ll wei = nim[j].second; rep(k,box2.size()){ if (wei <= box2[k]){ ans+=val; box2[k] = 0; break; } } } cout << ans << endl; } return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; const int N = 59; int w[N]; int v[N]; int x[N]; int main() { #ifndef LOCAL cin.tie(0); #endif ios::sync_with_stdio(false); int n, m, qq; cin >> n >> m >> qq; for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; } for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (v[j] > v[i]) { swap(w[i], w[j]); swap(v[i], v[j]); } } } for (int i = 0; i < m; ++i) { cin >> x[i]; } while (qq--) { int l, r; cin >> l >> r; --l; --r; vector<int> a; for (int i = 0; i < l; ++i) { a.push_back(x[i]); } for (int i = r + 1; i < m; ++i) { a.push_back(x[i]); } sort(a.begin(), a.end()); vector<bool> used(a.size(), false); int ans = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < (int)a.size(); ++j) { if (!used[j] && a[j] >= w[i]) { used[j] = true; ans += v[i]; break; } } } cout << ans << '\n'; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(void){ int n,m; cin >> n >> m; int a[n]; rep(i,n) cin >> a[i]; set<int> b; map<int,int> c; rep(i,1.5*1e6+1){ b.insert(i); c[i]++; } rep(i,m){ c[a[i]]--; b.erase(a[i]); } int ans = *begin(b); for(int i=0;i+m<n;i++){ c[a[i]]++; c[a[i+m]]--; if(c[a[i]]>0) b.insert(a[i]); if(c[a[i+m]]<=0) b.erase(a[i+m]); ans = min(ans,*begin(b)); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; vector<string> vec_splitter(string s) { s += ','; vector<string> res; while(!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out( vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx, __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #ifndef ONLINE_JUDGE #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define debug(...) 42 #endif clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } #define PI 3.14159265358979323846 const int maxn = 1500002; vector<int> v(maxn), last(maxn); int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; int ans = 987654321; for (int i = 1; i <= n; i++) { cin >> v[i]; if (i - last[v[i]] > m) { ans = min(ans, v[i]); } last[v[i]] = i; } for (int i = 0; i <= n; i++) { if (n + 1 - last[i] > m) { ans = min(ans, i); } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i) #define Ford(i, l, r) for (register int i = r, _l = l; i >= _l; --i) using namespace std; typedef long long ll; #define pii pair<int, int> #define mk make_pair const int N = 1e5 + 20; const int mod = 1e9 + 7; int T, n, a[N]; ll sum, tot; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); } return x * f; } int main() { int t = read(); while (t--) { sum = tot = 0; n = read(); For(i, 1, n) a[i] = read(); sort(a + 1, a + 1 + n); if (n & 1) { For(i, 2, n) i & 1 ? sum += a[i] : tot += a[i]; sum += a[1]; puts(sum ^ tot ? "Second" : "First"); } else { For(i, 1, n) i & 1 ? sum += a[i] : tot += a[i]; puts(sum ^ tot ? "First" : "Second"); } } return 0; }
#define _DEBUG #include "bits/stdc++.h" //#include <atcoder/all> #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #else #define debug(...) #endif #define rep(index,num) for(int index=0;index<(int)num;index++) #define rep1(index,num) for(int index=1;index<=(int)num;index++) #define brep(index,num) for(int index=(int)num-1;index>=0;index--) #define brep1(index,num) for(int index=(int)num;index>0;index--) #define scan(argument) cin>>argument #define prin(argument) cout<<argument<<endl #define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl #define kaigyo cout<<endl #define eps 1e-7 #define PI acosl(-1) #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define puba(a) emplace_back(a) #define pubamp(a,b) emplace_back(mp(a,b)) typedef long long ll; typedef long double ld; using namespace std; //using namespace atcoder; typedef pair<ll,ll> pll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<pint> vpint; typedef vector<pll> vpll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } ll INFl=(ll)1e+18+1; int INF=1e+9+1; /*n進数変換*/ template<typename TypeInt> std::string Itoa(const TypeInt v, int base) { static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string ret; static numeric_limits<TypeInt> t; TypeInt n = v; if (t.is_signed) { if (v < 0) n *= -1; } while (n >= base) { ret += table[n%base]; n /= base; } ret += table[n]; if (t.is_signed) { if (v < 0 && base == 10) ret += '-'; } // 文字列の順番を逆にする std::reverse(ret.begin(), ret.end()); return ret; } ll dp[19][(1<<18)]; int main(){ int N,M; int X[101],Y[101],Z[101]; scan(N>>M); rep(i,M){ scan(X[i]>>Y[i]>>Z[i]); X[i]--; Y[i]--; } dp[0][0]=1; int bitall=(1<<N); rep(i,N){ rep(bit,bitall){ if(dp[i][bit]==0) continue; //string BIT=Itoa(bit,2); //debug(i,BIT,dp[i][bit]); rep(j,N){ if(bit>>j&1) continue; int nextbit=bit|(1<<j); //string NEXTBIT=Itoa(nextbit,2); bool ok=1; rep(m,M){ if(X[m]<i) continue; int yikacnt=0; int tmpbit=nextbit; rep(k,Y[m]+1){ yikacnt+=((tmpbit>>k)&1); } if(yikacnt>Z[m]){ //debug(NEXTBIT,Y[m],yikacnt,Z[m]); ok=0; break; } } //debug(i,BIT,NEXTBIT,ok); if(ok) dp[i+1][nextbit]+=dp[i][bit]; } } } prin(dp[N][bitall-1]); return 0; }
//#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define arep(a,i,n) for(ll i=(a);i<(n);i++) #define rep(i,n) for(ll i=0;i<(n);i++) #define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i]; #define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using namespace std; int main(){ //ios::sync_with_stdio(false); //cin.tie(nullptr); ll a,b,c; cin >> a >> b >> c; ll tmp,ans; if(c%2==0){ switch(b%4){ case 1:tmp=1;break; case 2:tmp=4;break; case 3:tmp=1;break; case 0:tmp=4;break; } }else{ switch(b%4){ case 1:tmp=1;break; case 2:if(c==1)tmp=2;else tmp=4;break; case 3:tmp=3;break; case 0:tmp=4;break; } } if(a%10==0) cout << 0 << endl; else cout << static_cast<ll>(powl((a%10),tmp))%10 << endl; }
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl") #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define LL long long #define DB double #define LD long double #define ST string #define BS bitset #define PA pair<LL,LL> #define VE vector #define VL VE<LL> #define VP VE<PA> #define VVL VE<VL> #define VVVL VE<VVL> #define PQ priority_queue #define PQS priority_queue<LL,vector<LL>,greater<LL>> #define FI first #define SE second #define PB push_back #define POB pop_back #define PF push_front #define POF pop_front #define MP make_pair #define TS to_string #define TU to_ullong #define BPL __builtin_popcountll #define FOR(i,a,n) for(i=a;i<n;++i) #define FORR(i,a,n) for(i=n-1;i>=a;--i) #define rep(i,n) FOR(i,0,n) #define repr(i,n) FORR(i,0,n) #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define SORT(a) sort(ALL(a)) #define REV(a) reverse(ALL(a)) #define UB(a,n) *upper_bound(ALL(a),n) #define UBn(a,n) upper_bound(ALL(a),n)-a.begin() #define LB(a,n) *lower_bound(ALL(a),n) #define LBn(a,n) lower_bound(ALL(a),n)-a.begin() #define INF 1000000000000000003 #define PI 3.14159265358979323846264338327950288 //#define MOD 1000000007 #define MOD 998244353 #define ERR 1e-10 #define coutl cout<<fixed<<setprecision(15) #define FAST cin.tie(0);ios::sync_with_stdio(false) void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;} void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;} LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;} LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;} LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;} LL LCM(LL a,LL b){return a*b/GCD(a,b);} LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;} LL cdiv(LL a,LL b){return ((a<0&&b<0)||(a>=0&&b>=0)?a/b:(a-b+1)/b);} LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);} LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;} VL fact,finv,inv; void comi(LL n){LL i;fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;FOR(i,2,n+1){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}} LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;} bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;} template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;} template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;} template<typename T>void vout(VE<T> &v){LL i;rep(i,v.size()){cout<<v[i];if(i<v.size()-1)cout<<" ";}cout<<endl;} template<typename T>void v2out(VE<VE<T>> &v){for(auto a:v)vout(a);} int main(){ FAST; LL i,j,k,A,B,C,a=1; cin>>A>>B>>C; k=POW(B,C,4)+4; j=A%10; rep(i,k)a*=j; cout<<a%10<<endl; }
#include <iostream> using namespace std; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { long long aa,b,c; cin>>aa>>b>>c; int a = aa%10; int ans=0; if(a==0||a==1||a==5||a==6){ ans=a; }else if(a==4){ if(b%2==0){ ans=6; }else{ ans=4; } }else if(a==9){ if(b%2==0){ ans=1; }else{ ans=9; } }else{ long long mod = 0; mod =modpow(b,c,4); if(mod==0){ if(a==2) ans=6; if(a==3) ans=1; if(a==7) ans=1; if(a==8) ans=6; }else if(mod==1){ ans=a; }else if(mod==2){ if(a==2) ans=4; if(a==3) ans=9; if(a==7) ans=9; if(a==8) ans=4; }else{ if(a==2) ans=8; if(a==3) ans=7; if(a==7) ans=3; if(a==8) ans=2; } } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define vii vector<vector<int>> #define pb push_back #define f1(i,l,r) for(i=l;i<=r;i++) #define f2(a,b) for(auto a:b) #define all(v) v.begin(),v.end() #define mp make_pair #define pi pair<int,int> int main() { float V,T,S,D; cin>>V>>T>>S>>D; float ins; ins=D/V; if(ins<T||ins>S) cout<<"Yes"; else cout<<"No"; }
#include <bits/stdc++.h> #define INF INT_MAX #define ll long long #define ull unsigned long long #define rep(i,n) for(ll i=0; i<n; ++i) #define FOR(i, s, e) for(ll i=s; i<e; ++i) #define MOD 1000000007 using namespace std; template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;} template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;} int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<double> X(N); rep(i,N) cin >> X[i]; double m = 0, u = 0, c = 0; rep(i,N) { m+=abs(X[i]); u+=(X[i] * X[i]); c = max(c, abs(X[i])); } cout << setprecision(20) << m << endl; cout << sqrt(u) << endl; cout << c << endl; }
#include "bits/stdc++.h" using namespace std; using LLI = long long; #define INF 999999999 #define MOD 1000000007 #define FOR(i, s, e) for(LLI i = s, i##_lim = (e); i < i##_lim; i++) #define FORR(i, s, e) for(LLI i = s-1, i##_lim = (e); i##_lim<=i; i--) #define REP(i, n) FOR(i,0,n) #define REPR(i, n) FORR(i,n,0) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define bit(a, shift) ((a>>shift)&1)) #define pm(a) ((a)?1:-1) #define SORT(v) sort(v.begin(),v.end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define Mat2(type,name,h,w,def) vector<vector<type>> name(h,vector<type>(w, def)) #define Mat3(type,name,h,w,d,def) vector<vector<vector<type>>> name(h,vector<vector<type>>(w, vector<int>(d,def))) // int 2.14E±9 LLIi 9.2E±18 double 1.7E±380 #define PI 3.1415926535 int main() { cout << fixed << setprecision(10); int n; cin >> n; double x0, y0, x, y; cin >> x0 >> y0 >> x >> y; double th = atan2(-(y - y0), x - x0); th -= 2 * PI / n; double len = sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0)) / 2; //cout << len * cos(th - 2 * PI / n) << " " << len * sin(th - 2 * PI / n); cout << (x + x0) / 2 - len * cos(th) << " " << (y + y0) / 2 + len * sin(th); return 0; }
// C++ (GCC9.2.1) AtCoder /* Ctrl+Option+N で 実行 */ #include <bits/stdc++.h> #define INF 100000000000 #define MOD 1000000007 #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define print(x) cout << (x) << endl; typedef long long ll; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin>>N; vector <ll> A(N+1); REP(i,N) cin>>A[i+1]; ll ruiseki = 0; vector <ll> ans(1+N,0); ans[1] = A[1] + A[1]; ruiseki += A[1]; ll ma = A[1]; for(int i=1;i<N;i++){ ruiseki += A[i+1]; ll pma = ma; ma = max(ma,A[i+1]); ans[i+1] = ruiseki + (i+1) * ma - i * pma + ans[i]; } for(int i=1;i<=N;i++) print(ans[i]) return 0; }
#include <bits/stdc++.h> using namespace std; long long A[200005]; int main() { ios::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); int n; cin >> n; long long maxx = 0, sum = 0, pre = 0; for (int i=1; i<=n; i++) { cin >> A[i]; maxx = max(maxx, A[i]); sum += A[i]; pre += sum; cout << maxx * i + pre << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define ll long long #define int ll #define ld long double #define reps(i,s,n) for(int i=(s);i<(int)(n);i++) #define rep(i,n) reps(i,0,n) #define rreps(i,s,n) for(int i=(int)(s-1);i>=n;i--) #define rrep(i,n) rreps(i,n,0) #define all(v) (v).begin(),(v).end() #define mset(a,n) memset(a,n,sizeof(a)) #define eras(v,n) (v).erase(remove(all(v),n),(v).end()) #define uni(v) sort(all(v));(v).erase(unique(all(v)),(v).end()) #define bcnt(i) __builtin_popcount(i) #define fi first #define se second constexpr ll INF = 1e18; constexpr ll MOD = 1000000007; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<class T>T min(vector<T> &v) { return *min_element(v.begin(),v.end()); } template<class T>T max(vector<T> &v) { return *max_element(v.begin(),v.end()); } template<class T>T modpow(T a, T b, T m) { a %= m; T r = 1; while (b > 0) { if (b & 1) r = (r * a) % m; a = (a * a) % m; b >>= 1; } return r; } ll modinv(ll a,ll m=MOD) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;} template<class T>string radixconv(T n, T k){ string s; while(n/k){ s=to_string(n%k)+s; n/=k; } s=to_string(n%k)+s; return s; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(11); cerr << fixed << setprecision(6); string s; cin >> s; int ocnt=count(all(s),'o'); int ans=0; cerr << ocnt << endl; rep(a,10)rep(b,10)rep(c,10)rep(d,10){ if(s[a]=='x')continue; if(s[b]=='x')continue; if(s[c]=='x')continue; if(s[d]=='x')continue; vector<bool> chk(10,0); chk[a]=1; chk[b]=1; chk[c]=1; chk[d]=1; int cnt=0; rep(i,10)if(chk[i]&&s[i]=='o')cnt++; if(cnt!=ocnt)continue; ans++; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); string s; cin >> s; int onum =0, qnum = 0; int i; for(i = 0;i<10;i++){ if(s[i] == 'o'){ onum++; }else if(s[i] == '?'){ qnum++; } } if(onum > 4){ cout << 0 << endl; }else if(onum == 4){ cout << 24 << endl; }else if(onum == 3){ cout << 36 + 24 * qnum << endl; }else if(onum == 2){ cout << 4 + 6 + 4 + (qnum - 1) * qnum / 2 * 24 + qnum * 36 << endl; }else if(onum == 1){ cout << 1 + qnum * 14 + (qnum - 1) * qnum / 2 * 36 + (qnum - 2) * (qnum - 1) * qnum / 6 * 24 << endl; }else{ cout << qnum * qnum * qnum * qnum << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int,int>; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<ll>a(n); for (auto& x : a) cin >> x; vector<ll> pr(n+1); for (int i = 1; i <= n; i++) pr[i] = pr[i-1]+a[i-1]; ll mx =0; ll sum = 0; for (int k = 0; k < n; k++) { mx = max(mx,a[k]); cout << (k+1)*mx+pr[k+1]+sum << '\n';; sum += pr[k+1]; } }
#include<bits/stdc++.h> #define mx 100005 #define lli long long int #define ulli unsigned long long int #define mset(a,b) memset(a, b, sizeof(a)) #define infile freopen("in.txt", "r", stdin); #define outfile freopen ("out.txt","w",stdout); #define fileclose fclose (stdin); fclose (stdout); #define test_case lli T; cin>>T;for(lli t=1;t<=T;t++) #define scani(x) scanf("%d",&x); #define printi(x) printf("%d\n",x); #define scanli(x) scanf("%lld",&x); #define printli(x) printf("%lld\n",x); #define frep(i,from,to) for(lli i=from;i<=to;i++) #define frev(i,from,to) for(lli i=from;i>=to;i--) using namespace std; lli n; lli arr[50]; lli ans = 1e18; lli prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; bool isSet(lli num, lli pos) { return (num & (1 << pos)); } void fun() { frep(mask, 0, (1 << 15) - 1) { lli num = 1; frep(pos, 0, 15) { if (isSet(mask, pos)) { num *= prime[pos]; } } bool flag = true; frep(i, 1, n) { if (__gcd(num, arr[i]) == 1) { flag = false; break; } } if (flag) ans = min(ans, num); } } int main() { cin >> n; frep(i, 1, n) { cin >> arr[i]; } fun(); cout << ans << "\n"; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; #define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ff first #define ss second #define int long long #define ll long long #define pb push_back #define pii pair<int,int> #define vi vector<int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define mod 998244353 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define vpii vector<pair<int,int> > #define all(x) x.begin(),x.end() #define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";} #define show(arr,x,y) for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n" #define sz(x) (int)x.size() #define db(x) cout<<x<<"\n"; typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //insert,find_by_order,order_of_key,lower_bound,upper_bound; #define TRACE #ifdef TRACE #define deb(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define deb(...) #endif //////////////////////////////code////////////////////////////// const int N = 200; int power(int a, int b = mod - 2) { int x = 1 % mod; a %= mod; b %= mod - 1; while (b) { if (b & 1) x = (x * a)%mod; a = (a * a)%mod; b >>= 1; // deb(x); } return x; } void solve() { int n; cin >> n; map<int,int>m; for(int i = 0;i < n; i++) { int d; cin >> d; m[d]++; //deb(m[d],d); } int ans = 0,sum = 0, nodesum = 0; vpii num; /*for(auto x : m) num.pb({x.ff,x.ss}); */ /* deb(sz(num)); deb(num[0].ff,num[0].ss); */ for(auto it = m.begin() ; it != m.end() ; it++) { int f = it->ss; int a = it->ff; // deb(f,a); int twof = (power(2,f) - 1); int two = power(2,f); ans += (((twof*a)%mod)*a)%mod; ans %= mod; ans += (((twof*sum)%mod)*a)%mod; ans %= mod; sum *= two; sum %= mod; sum += (twof*a)%mod; sum %= mod; } db(ans) } int32_t main() { LETS_GET_SCHWIFTY; #ifndef ONLINE_JUDGE freopen("INP.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) solve(); } // check out for following mistakes- // if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only // is using prime sieve make sure it fits // when using factorial template or combinatorics make sure that you edit fillfac fun values and array values
#include <vector> #include <iostream> #include <algorithm> #define R 998244353 using namespace std; typedef long long ll; vector<int> myNum; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int N; cin >> N; while (N--) { int num; cin >> num; myNum.push_back(num); } sort(myNum.begin(), myNum.end()); ll partSum = 0; ll res = 0; for (int num : myNum) { res += num * ((partSum + num)%R)%R; res %= R; partSum = ((partSum * 2)%R + num)%R; } cout << res; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using ll = long long; const ll INF = 1e17; int main(){ int n; cin >> n; ll a[n][5]; rep(i,n) rep(j,5) cin >> a[i][j]; ll l = 0, r = INF; while(r-l > 1) { ll m = (l + r) / 2; vector<vector<int>> bit(n); vector<int> val(n); vector<int> cnt(1<<5); rep(i,n) { int b = 0; rep(j,5) if(a[i][j] >= m) b += (1<<j); val[i] = b; rep(k,1<<5) { if((b & k) == k) { bit[i].push_back(k); cnt[k]++; } } } int all = (1<<5)-1; bool can = false; rep(i,n) { for(int j = 1; j < n; j++) { int res = (val[i] | val[j]); res ^= all; if(cnt[res]) can = true; } } if(can) l = m; else r = m; } cout << l << endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #include <iostream> #include <vector> #include <string> #include <stdlib.h> #include <cmath> #include <algorithm> #include <numeric> #include <climits> #include <iomanip> #include <deque> #include <limits> #include <map> #include <set> #include <functional> using namespace std; int N; vector<int> A, B, C, D, E; bool binary_check(int x) { set<int> S; for (int i = 0; i < N; i++) { int s = (A[i] >= x) << 4 | (B[i] >= x) << 3 | (C[i] >= x) << 2 | (D[i] >= x) << 1 | (E[i] >= x) << 0; S.insert(s); } for (auto &&a : S) { for (auto &&b : S) { for (auto &&c : S) { if ((a | b | c) == 0b11111) { return true; } } } } return false; } int main() { cin >> N; A.resize(N); B.resize(N); C.resize(N); D.resize(N); E.resize(N); for (int i = 0; i < N; i++) { cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i]; } int ok = 0; int ng = 1e9 + 5; int x = 0; while (abs(ng - ok) > 1) { x = (ok + ng) / 2; if (binary_check(x)) { ok = x; } else { ng = x; } } cout << ok << endl; return 0; }
#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <stack> #include <cassert> #include <map> #include <numeric> #include <cstring> #include <set> #include <ctime> #include <queue> #include <cmath> #include <iomanip> #include <iterator> using namespace std; clock_t timeStart, timeFinish; void timeBegin() { timeStart = clock(); } void timeEnd() { timeFinish = clock(); } void timeDuration() { timeEnd(); double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC); cout << "Time taken by program is : " << fixed << time_taken << setprecision(5); cout << " sec " << endl; } class InputReader { public: InputReader() { input_file = stdin; cursor = 0; fread(buffer, SIZE, 1, input_file); } InputReader(const char *file_name) { input_file = fopen(file_name, "r"); cursor = 0; fread(buffer, SIZE, 1, input_file); } inline InputReader &operator >>(int &n) { while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') { advance(); } int sign = 1; if (buffer[cursor] == '-') { sign = -1; advance(); } n = 0; while('0' <= buffer[cursor] && buffer[cursor] <= '9') { n = n * 10 + buffer[cursor] - '0'; advance(); } n *= sign; return *this; } private: FILE *input_file; static const int SIZE = 1 << 17; int cursor; char buffer[SIZE]; inline void advance() { ++ cursor; if(cursor == SIZE) { cursor = 0; fread(buffer, SIZE, 1, input_file); } } }; const int MAXN = 5000; const int MOD = 998244353; int power[1 + MAXN][1 + MAXN]; void addTo(int &x, int y) { x += y; if (x >= MOD) { x -= MOD; } } void precompute(int m, int n) { for (int i = 1; i <= m; i++) { power[i][0] = 1; for (int j = 1; j <= n; j++) { power[i][j] = 1LL * power[i][j - 1] * i % MOD; } } } int main() { timeBegin(); //ifstream cin("input.in"); //ofstream cout("abbreviation.out"); int n, m; cin >> n >> m; if (n == 1) { cout << m % MOD << "\n"; return 0; } precompute(m, n); int answer = 0; for (int x = 1; x <= m; x++) { addTo(answer, power[m][n - 1]); int sum = (x - 1) % MOD; for (int i = 2; i <= n; i++) { int current = sum; addTo(current, power[m - x][i - 1]); addTo(answer, 1LL * current * power[m][n - i] % MOD); sum = 1LL * sum * m % MOD; addTo(sum, 1LL * power[m - x][i - 1] * (x - 1) % MOD); } } cout << answer << "\n"; //timeDuration(); return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") // #include <atcoder/all> // #include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <iomanip> #include <fstream> using namespace std; // using namespace atcoder; typedef long long ll; typedef long double ld; typedef pair<ll, ll> p32; typedef pair<ll, ll> p64; typedef pair<p64, p64> pp64; typedef pair<double, double> pdd; typedef vector<ll> v64; typedef vector<ll> v32; typedef vector<vector<ll>> vv32; typedef vector<vector<ll>> vv64; typedef vector<vector<p64>> vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; ll MOD = 998244353; double eps = 1e-12; #define forn(i, e) for (ll i = 0; i < e; i++) #define forsn(i, s, e) for (ll i = s; i < e; i++) #define rforn(i, s) for (ll i = s; i >= 0; i--) #define rforsn(i, s, e) for (ll i = s; i >= e; i--) #define ln '\n' #define dbg(x) cout << #x << " = " << x << ln #define mp make_pair #define pb push_back #define fi first #define se second #define INF 2e18 #define fast_cin() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) #define zero ll(0) #define set_bits(x) __builtin_popcountll(x) // #define mll modll998244353 ll mpow(ll a, ll b) { if (a == 0) return 0; if (b == 0) return 1; ll t1 = mpow(a, b / 2); t1 *= t1; t1 %= MOD; if (b % 2) t1 *= a; t1 %= MOD; return t1; } ll mpow(ll a, ll b, ll p) { if (b == 0) return 1; if (a == 0) return 0; ll t1 = mpow(a, b / 2, p); t1 *= t1; t1 %= p; if (b % 2) t1 *= a; t1 %= p; return t1; } ll modinverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); ll range(ll l, ll r) { return l + mt() % (r - l + 1); } ll rev(ll v) { return mpow(v, MOD - 2); } ll ceil(ll p, ll q) { return (p + q - 1) / q; } struct node { ll tot=0, add=0, fact=1; }; void solve() { ll n,m; cin >> n >> m; ll p[n+1]; p[0]=1; forn(i,n){ p[i+1] = (p[i]*m)%MOD; p[i+1] %= MOD; } ll ans = 0; ll revm = rev(m); ll r[m+1]; ll rev1[m+1]; forsn(j,1,m+1){ r[j] = (m-j)*revm; r[j] %= MOD; rev1[j]=rev(j); } forsn(j,1,m+1){ ll tmp = 1; forn(i,n){ if(i==0) ans++; else{ ans += (((j-1)*rev1[j])%MOD)*(1-tmp)+tmp; ans %= MOD; } tmp*=r[j]; tmp%=MOD; // ans += 1-rev(j)*(1-mpow(r[j],i)); } } ans *= p[n-1]; ans %= MOD; if(ans<0) ans+=MOD; cout << ans << ln; } int main() { fast_cin(); ll t = 1; // cin >> t; forn(i, t) { // cout << "Case #" << i+1 << ": "; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n - 1; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define FORR(i,m,n) for(int i = m - 1; i >= n; i--) #define ALL(v) v.begin(), v.end() #define itn int #define Yes() cout << "Yes" << endl #define No() cout << "No" << endl #define YES() cout << "YES" << endl #define NO() cout << "NO" << endl #define println(x) cout << x << endl #define print(x) cout << x << " " template<typename T, typename U> inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; } template<typename T, typename U> inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; } typedef long long lint; typedef long double ldouble; const int INF = 1e9; const lint LINF = 1e18; const int MOD = 1e9+7; int main(){ int n; cin >> n; vector<int> a(n); vector<int> b(n); vector<int> c(n); REP(i, n){ cin >> a[i]; } REP(i, n){ cin >> b[i]; } REP(i, n){ cin >> c[i]; } vector <int> bc; REP(i,n){ bc.push_back(b[--c[i]]); } sort(ALL(a)); sort(ALL(bc)); lint time = 0; REP(i,n){ auto itr = lower_bound(ALL(bc),a[i]); auto temp = upper_bound(ALL(bc), a[i]); if(itr != bc.end()){ int index = distance(bc.begin(), itr); int upper = distance(bc.begin(), temp); time += (lint)upper - index; } } println(time); return 0; }
#include <iostream> #include <cmath> #include <stdio.h> #include <string.h> #include <bits/stdc++.h> #include <vector> #include <array> #include <tuple> using namespace std; int main(){ long long C[61][61]; for (int i=0; i<=60; i++){ for (int j=0; j<=60; j++){ C[i][j]=0; } } C[0][0]=1; for (int i=1; i<=60; i++){ C[i][0]=1; for (int j=1; j<=60; j++){ C[i][j]=C[i-1][j-1]+C[i-1][j]; } } int A, B; long long K; cin >> A >> B; cin >> K; int P=A+B; for (int i=0; i<P; i++){ if (A==0){ cout << "b"; B=B-1; } else if (K<=C[A+B-1][A-1]){ cout << "a"; A=A-1; } else { cout << "b"; K=K-C[A+B-1][A-1]; B=B-1; } } cout << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long int lli; typedef long double ld; /* #include <chrono> using namespace std::chrono; #include <boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<lli, null_type,less_equal<lli>, rb_tree_tag,tree_order_statistics_node_update> //remove _equal from less_equal to make it ordered set , currently it is ordered_multiset */ #define pb push_back const lli mod=1e9+7; const lli mod1=998244353; #define fir first #define sec second #define plli pair<lli,lli> #define pplli pair<lli,plli> /* lli power(lli a, lli b) { lli res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } lli powermod(lli a, lli b) { lli res = 1; while (b > 0) { if (b & 1) res = ((res%mod)*(a%mod))%mod; a = (a * a)%mod; b >>= 1; } return res%mod; } */ int main() { lli T,i,j; T=1; while(T--) { lli n; cin>>n; lli a[n]; for(i=0;i<n;i++) cin>>a[i]; sort(a,a+n); lli x=a[n/2]/2; lli f=(a[n/2]%2); lli loss=0; for(i=0;i<n;i++) { lli z=((a[i]+x)-min(a[n/2]*1ll,a[i]*1ll)); loss=loss+z; } if(f) { loss+=(n/2); } ld ans=(ld) loss/n; if((n%2==1)and(f)) ans=ans+ ((ld)0.5/n); cout<<fixed<<setprecision(10)<<ans<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; // using T = tuple<int,int,int>; using P = pair<int,int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int charToInt(char c){ char zero_num = '0'; return (int)c - (int)zero_num; } void cout_line(vector<int> &a){ for(int i=0;i<a.size();i++){ if(i<a.size()-1){ cout<<a.at(i)<<" "; }else{ cout<<a.at(i)<<endl; } } } long double calc(vector<long double> &A, long double mid){ double result = 0.; for(int i=0;i<A.size();i++){ result += mid+A.at(i)-min(A.at(i), 2.*mid); } return result/((long double)A.size()); } signed main(){ int N; cin>>N; vector<long double> A(N); rep(i,N)cin>>A.at(i); long double left = 0.; long double right = 2*(int)pow(10,9); while(right>left+pow(10,-7)){ long double mid1 = (left*2. + right)/3.; long double mid2 = (left + right*2.)/3.; if(calc(A, mid1)>calc(A,mid2)){ left = mid1; }else{ right = mid2; } } cout<<fixed<<setprecision(10)<<calc(A,left)<<endl; return 0; }
#include <iostream> #include <vector> #include <string> #include <deque> #include <list> #include <tuple> #include <algorithm> #include <set> #include <queue> #include <functional> #include <map> #include <set> #include <unordered_map> #include <cmath> #include <iomanip> using namespace std; uint64_t MAX_NUM = 1000000000; int32_t N; vector<int32_t> parent; vector<int32_t> mysize; int find_set(int v){ if(v == parent[v]){ return v; } return find_set(parent[v]); } void union_sets(int a, int b){ //cout << " a " << a << " b " << b << endl; a = find_set(a); b = find_set(b); //cout << "find a " << a << " b " << b << endl; if(a != b){ if(mysize[a] < mysize[b]){ swap(a, b); } parent[b] = a; mysize[a] += mysize[b]; mysize[b] = 1; } } int main() { //int32_t N; cin >> N; vector<int32_t> A = vector<int32_t>(N+1); for(int32_t count = 1; count <= N; count++){ int32_t a; cin >> a; A[count] = a; } vector<int32_t> temp(200001, 0); for(int32_t count = 1; count <= N; count++){ int32_t a = A[count]; if(temp[a] == 0){ temp[a] = count; } A[count] = temp[a]; } // for(int32_t count = 1; count <= N; count++){ // cout << A[count] << endl; //} parent = vector<int32_t>(N+1); mysize = vector<int32_t>(N+1, 1); for(int32_t count = 1; count <= N; count++){ parent[count] = A[count]; } int32_t i, j; for(i = 1, j = N; i < j; i++, j--){ int32_t a1 = A[i]; int32_t a2 = A[j]; if(a1 != a2){ int32_t a = find_set(i); int32_t b = find_set(j); union_sets(a, b); } } uint64_t result = 0; for(int32_t count = 1; count <= N; count++){ //cout << " count " << count << " size " << size[count] << endl; result += mysize[count] - 1; } cout << result << endl; }
#include<bits/stdc++.h> using namespace std; struct zz{ int a[15]; }t[200005]; int Max[15]={}; int n; int dp[5][(1<<5)+5]; int dp2[5][(1<<5)+5]; int main(){ cin>>n; for(int i=1;i<=n;i++) for(int j=0;j<5;j++) scanf("%d",&t[i].a[j]); dp[0][0]=1e9; for(int i=1;i<=n;i++){ for(int j=0;j<3;j++) for(int k=0;k<(1<<5);k++) dp2[j][k]=dp[j][k]; for(int l=0;l<5;l++){ for(int j=0;j<3;j++) for(int k=0;k<(1<<5);k++) if(k&(1<<l)) dp2[j][k]=max(dp2[j][k],min(dp2[j][k^(1<<l)],t[i].a[l])); } for(int j=1;j<=3;j++) for(int k=0;k<(1<<5);k++) dp[j][k]=max(dp[j][k],dp2[j-1][k]); } cout<<dp[3][(1<<5)-1]; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,cc,n) for(int i=cc;i<n;++i) #define lrep(i,cc,n) for(long long i=cc;i<n;++i) #define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i) #define rrep(i,cc,n) for(long i=cc;i>n;--i) #define pii pair<int, int> #define pll pair<long long, long long> using ll = long long; //using mint = modint; const vector<int> dx = {1, 1, 1, 0, 0, 0, -1, -1, -1}; const vector<int> dy = {1, 0, -1, 1, -1, 0, 1, 0, -1}; const double PI = 3.141592653589793; const ll inf = 1001001001; const ll e9 = 1000000000; const ll mod = 1000000007; const ll mod2 = 998244353; const int MAX = 1000000; const ll MOD = 998244353; const ll big = 1ll<<60; struct edge{ int to; ll cost; }; ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; } int main(){ int l, r; cin >> l >> r; vector<ll>cnt(1001005); for(int i = 1001001; i>=2; i--){ cnt[i] = 1ll*(r/i-(l-1)/i)*(r/i-(l-1)/i); int x = 2*i; while(x <= r){ cnt[i] -= cnt[x]; x += i; } } ll ans = 0; rep(i, 2, 1001002){ ans += cnt[i]; if(l<=i&&i<=r){ ans -= 1ll*(r/i-(l-1)/i); ans -= 1ll*(r/i-(l-1)/i); ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll solve(int L, int R){ vector<ll> memo(1<<21, -1); auto f = [&](auto self, int L, int R) -> ll { // L < x <= R であって、gcd(x,y) == 1 となるものを数える auto key = L + R; if(memo[key] != -1) return memo[key]; ll res = ll(R - L) * (R - L); int d = max(L, R); while(d > 1){ int nxt_d = max(L / (L / d + 1), R / (R / d + 1)); res -= (d - nxt_d) * self(self, L / d, R / d); d = nxt_d; } memo[key] = res; return res; }; auto g = [&](int L, int R) -> ll { ll res = 0; int d = max(L, R); while(d){ int nxt_d = max(L / (L / d + 1), R / (R / d + 1)); ll cnt = max(0, min(d, R) - max(nxt_d, L)); res += cnt * (R / d - L / d); d = nxt_d; } return res; }; --L; ll ans = ll(R - L) * (R - L); ans -= f(f, L, R) + 2 * g(L, R); ans += 2 * (L < 1 ? R - L : 0) + (R - L); ans -= L < 1; return ans; } int main(){ int L, R; cin >> L >> R; ll ans = solve(L, R); cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define int long long int using namespace std; int32_t main() { int a,b,c; cin>>a>>b>>c; int array[]={a,b,c}; int sum=0; for(int i=0;i<3;i++) { sum=sum+(7-array[i]); } cout<<sum; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e5+10; const int mod=1e9+7; int main() { double x1,x2,y1,y2; cin>>x1>>y1>>x2>>y2; y2=-y2; double k=(y1-y2)/(x1-x2); double b=y1-k*x1; printf("%.10f",-b/k); }
#include "bits/stdc++.h" using namespace std; #define ll long long int main(){ int a,b,c,d; cin>>a>>b>>c>>d; cout<<b-c<<endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <math.h> #include <set> #include <unordered_map> using namespace std; #define MAXN 1000001 #define MAXN1 101 #define MAXN2 1001 #define mod 1000000007 #define CONSTANT 1e8 #define ll long long // pair<int,int> ll res = 0; int BS(vector<int> arr, int val){ int l = 0, u = (int)arr.size() - 1, res = -1; while(l <= u){ int mid = (l + u) / 2; // if() } return 0; } vector<pair<int,ll>> g(vector<pair<int,ll>> left, vector<pair<int,ll>> right){ int l = (int)left.size(); int r = (int)right.size(); vector<ll> pref(r,0); vector<pair<int,ll>> arr(l + r); pref[0] = right[0].second; for(int i = 1; i < r; i++){ pref[i] = right[i].second + pref[i - 1]; } int j = 0, i = 0; while(i < l){ // cout << "i: " << i << " " << j << endl; if(j < r && left[i].first > right[j].first){ // curr += right[j].second; j++; } else{ if(j - 1 >= 0){ // cout << "Adding: " << pref[j - 1] << endl; res += pref[j - 1]; } i++; } } i = 0; j = 0; int index = 0; while(i < (int)left.size() && j < (int)right.size()){ if(left[i].first <= right[j].first) arr[index++] = left[i++]; else arr[index++] = right[j++]; } while(i < (int)left.size()) arr[index++] = left[i++]; while(j < (int)right.size()) arr[index++] = right[j++]; return arr; } vector<pair<int,ll>> f(vector<pair<int,ll>> arr, int n){ if(n == 1) return arr; int mid = n / 2; vector<pair<int,ll>> left(mid), right(n - mid); for(int i = 0; i < mid; i++) left[i] = arr[i]; for(int j = mid; j < n; j++) right[j - mid] = arr[j]; left = f(left, mid); right = f(right, n - mid); arr = g(left, right); return arr; } void zz(vector<pair<int,ll>> &left, vector<pair<int,ll>> &right){ int l = (int)left.size(); int r = (int)right.size(); vector<ll> pref(r,0); pref[0] = right[0].second; for(int i = 1; i < r; i++){ pref[i] = right[i].second + pref[i - 1]; } int j = 0, i = 0; while(i < l){ // cout << "i: " << i << " " << j << endl; if(j < r && left[i].first > right[j].first){ // curr += right[j].second; j++; } else{ if(j - 1 >= 0){ // cout << "Adding: " << pref[j - 1] << endl; res += pref[j - 1]; } i++; } } } vector<pair<int,ll>> gg(vector<pair<int,ll>> &left, vector<pair<int,ll>> &right){ int l = (int)left.size(); int r = (int)right.size(); vector<pair<int,ll>> arr(l + r); int i = 0; int j = 0; int index = 0; while(i < l && j < r){ if(left[i].first <= right[j].first){ left[i].second += j; arr[index++] = left[i++]; } else{ // left[i].second += j + 1; arr[index++] = right[j++]; } } while(i < (int)left.size()){ left[i].second += r; arr[index++] = left[i++]; } while(j < (int)right.size()) arr[index++] = right[j++]; // zz(left, right); return arr; } vector<pair<int,ll>> ff(vector<pair<int,ll>> &arr, int n){ if(n == 1) return arr; int mid = n / 2; vector<pair<int,ll>> left(mid), right(n - mid); for(int i = 0; i < mid; i++) left[i] = arr[i]; for(int j = mid; j < n; j++) right[j - mid] = arr[j]; left = ff(left, mid); right = ff(right, n - mid); arr = gg(left, right); return arr; } int main(){ int a, b, c, d; cin >> a >> b >> c >> d; cout << max(a - d, b - c) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) ll ans = 0; const ll mo = 1000000007; auto mod = [](ll modx) {modx%=mo;modx+=mo;modx%=mo;return modx; }; int main() { ll h , w ; cin >> h >> w ; vector<vector<ll>> v(h, vector<ll>(w,0) ); vector<vector<ll>> vv(h, vector<ll>(w,0) ); vector<ll> vh(w,0); vector<ll> vw(h,0); vector<ll> vhw(h+w+1,0); rep(i,h)rep(j,w){ char a; cin >> a ; if(a=='#')v[i][j]=1; } vv[0][0]=1; vw[0]=1; vh[0]=1; vhw[w]=1; rep(i,h)rep(j,w){ if(i==0&&j==0)continue; if(v[i][j]==1){ vw[i]=0; vh[j]=0; vhw[w+i-j]=0; } else{ vv[i][j]=mod(vw[i]+vh[j]+vhw[w+i-j]); vw[i]=mod(vw[i]+vv[i][j]); vh[j]=mod(vh[j]+vv[i][j]); vhw[w+i-j]=mod(vhw[w+i-j]+vv[i][j]); } } cout << vv[h-1][w-1] << endl; return 0; }
//This Code was made by Chinese_zjc_. #include <iostream> #include <fstream> #include <iomanip> #include <algorithm> #include <vector> #include <bitset> #include <cmath> #include <queue> #include <stack> #include <list> #include <string> #include <cstring> #include <cstdio> #include <cstdlib> #include <cctype> #include <map> #include <set> #include <ctime> // #include<windows.h> // #define debug true #define int long long #define double long double using namespace std; const double PI = acos(-1); const double eps = 0.0000000001; const int INF = 0x3fffffffffffffff; const int MOD = 1000000007; int n, m, dp[2005][2005], heng[2005][2005], shu[2005][2005], xie[2005][2005]; char Map[2005][2005]; signed main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> Map[i][j]; } } shu[1][1] = xie[1][1] = heng[1][1] = dp[1][1] = 1; Map[1][1] = '#'; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (Map[i][j] == '.') { dp[i][j] = (shu[i - 1][j] + heng[i][j - 1] + xie[i - 1][j - 1]) % MOD; heng[i][j] = heng[i][j - 1] + dp[i][j]; shu[i][j] = shu[i - 1][j] + dp[i][j]; xie[i][j] = xie[i - 1][j - 1] + dp[i][j]; } } } cout << dp[n][m] << endl; return 0; }
#include <iostream> #include <vector> #include <numeric> #include <algorithm> int main() { int K, N, M; std::cin >> K >> N >> M; std::vector<long long> as(K); for (auto& a : as) { std::cin >> a; } std::vector<long long> bs(K); for (int i = 0; i < K; i++) { bs[i] = (as[i] * M) / N; } int remain = M - std::accumulate(bs.begin(), bs.end(), 0); struct Score { int id; long long value; }; std::vector<Score> scores(K); for (int i = 0; i < K; i++) { scores[i] = { i, std::abs(bs[i] * N - as[i] * M) }; } std::sort(scores.begin(), scores.end(), [&](auto& a, auto& b) {return a.value > b.value; }); for (int i = 0; i < remain; i++) { bs[scores[i].id] += 1; } for (auto& e : bs) { std::cout << e << " "; } std::cout << std::endl; return 0; }
#include <iostream> #include <algorithm> #include <vector> #define ll long long #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int k; ll n,m,a[100001],b[100001],cnt,s; vector< pair<ll, int> > r(100001); int main(){ cin >> k >> n>> m; rep(i,k)cin>>a[i]; rep(i,k){ cnt = a[i]*m; b[i] = cnt/n; s += b[i]; r.push_back(pair<ll,int>(-cnt%n, i)); } sort(r.begin(), r.end()); rep(i,m-s){ b[r[i].second]++; } rep(i,k)cout << b[i] << " ";cout << endl; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int T; int N; int P[555]; vector<int> R; void go(int x) { swap(P[x],P[x+1]); R.push_back(x); } void solve() { int i,j,k,l,r,x,y; string s; cin>>T; while(T--) { cin>>N; FOR(i,N) { cin>>P[i]; P[i]--; } R.clear(); int step=0; for(i=N-1;i>=3;i--) { FOR(j,N) if(P[j]==i) break; if(j==i) continue; if(i==3&&j==2&&step==1) { go(1); go(2); j=1; } while(j<i) { if(step==j%2) { go(j); j++; } else if(step==0) { if(j==1) go(2); else go(0); } else { if(j==2) go(3); else go(1); } step^=1; } } while(1) { for(j=N-1;j>=0;j--) if(P[j]!=j) break; if(j<0) break; assert(j<3); swap(P[step],P[step+1]); R.push_back(step); step^=1; } cout<<R.size()<<endl; FOR(i,R.size()) { assert(R[i]%2==i%2); cout<<(R[i]+1)<<" "; } cout<<endl; FOR(i,N) assert(P[i]==i); } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#include <stdio.h> #include <vector> using namespace std; typedef long long ll; int main(void) { ll i, j, k, n, t, p, q; bool f; scanf("%lld", &t); for(k = 0; k < t; ++k) { scanf("%lld", &n); ll a[n]; vector<ll> vec; for(i = 0; i < n; ++i) scanf("%lld", &a[i]); f = true; for(i = n - 1; i > 2; --i) { for(j = 0; j < n; ++j) if(a[j] == i + 1) break; if(j == i) continue; if((j & 1 ? 1 : 0) == f) { if(f) q = 1; else q = 2; vec.push_back(q); p = a[q], a[q] = a[q - 1], a[q - 1] = p; if(q == j) { vec.push_back(q + 1), j--; p = a[q], a[q] = a[q + 1], a[q + 1] = p; } } for(; j < i; ++j) vec.push_back(j + 1), p = a[j], a[j] = a[j + 1], a[j + 1] = p; f = i & 1 ? 0 : 1; } while(a[0] != 1 || a[1] != 2) { vec.push_back(2 - f), p = a[2 - f], a[2 - f] = a[1 - f], a[1 - f] = p, f = !f; } printf("%lld\n", vec.size()); for(i = 0; i < vec.size(); ++i) printf("%lld ", vec[i]); printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; while (t--) { int n; cin >> n; int k = 0; while (n % 2 == 0) { k++; n /= 2; } if (k == 0) { cout << "Odd\n"; } else if (k == 1) { cout << "Same\n"; } else { cout << "Even\n"; } } }
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define umap unordered_map #define mod 998244353ll #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define MN(a,b,c) min(a,min(b,c)) #define MX(a,b,c) max(a,max(b,c)) #define pr1 pair<ll,ll> #define F first #define S second #define mP make_pair #define f(i,n) for(ll i=0;i<n;i++) #define f1(i,x,y) for(ll i=x;i<=y;i++) #define f2(i,x,y) for(ll i=x;i>=y;i--) #define yes cout<<"Yes"<<"\n" #define no cout<<"No"<<"\n" #define modsum(a,b) ((a%mod)+(b%mod))%mod #define modpro(a,b) ((a%mod)*(b%mod))%mod #define moddif(a,b) ((a%mod)-(b%mod)+mod)%mod #define modsumt(a,b,c) modsum(a,modsum(b,c)) //__builtin_popcount(x) //__builtin_parity(x) =(number of set bits)%2 //__builtin_clz(x) to count the number of leading zeroes //__builtin_ctz(x) to count the number of trailing zeroes //__gcd(a,b) using namespace std; ll modularExponentiation(ll x,ll n,ll M) { ll result=1; while(n>0) { if(n % 2 ==1) result=modpro(result,x); x=modpro(x,x); n=n/2; } return result; } ll binaryExponentiation(ll x,ll n) { ll result=1; while(n>0) { if(n % 2 ==1) result=result * x; x=x*x; n=n/2; } return result; } ll pow1(ll x,ll y) { ll z=1; while(y--){z=z*x;} return z; } bool isprime(ll n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } // Returns n^(-1) mod p ll modInverse(ll n, ll p) { return modularExponentiation(n, p - 2, p); } // Returns nCr % p using Fermat's little // theorem. unsigned long long nCrModPFermat(unsigned long long n, ll r, ll p) { // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r unsigned long long fac[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } bool compare(pair<ll,ll> a, pair<ll,ll> b) { if(a.F==b.F) return a.S>b.S; else return a.F>b.F; } ll check(ll x,ll y) { ll z=1; ll ans=0; while(z<x){ans++;z*=y;} return ans; } ll countbits(ll n) { ll x=0; while(n>0) { x++; n=(n&(n-1)); } return x; } ll visited[100001]; void dfs(ll p,set <ll> v[]) { visited[p]=1; for(auto it=v[p].begin();it!=v[p].end();it++) { ll x=*it; if(visited[x]==0) { dfs(x,v); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t,x; cin>>t; while(t--) { cin>>x; ll num=0; while((x%2)==0) { x/=2; num++; } if(num==0) { cout<<"Odd"<<"\n"; } else { if(num==1) cout<<"Same"<<"\n"; else cout<<"Even"<<"\n"; } } }
#include<bits/stdc++.h> using namespace std; long long ans=0,num=0,a[200002]; int n; int main(){ scanf("%d",&n); for(int i=0;i<n;++i)scanf("%lld",&a[i]); sort(a,a+n); for(int i=n-2;i>=0;--i){ num=(num+a[i+1])%998244353; ans=(ans+a[i]*num%998244353)%998244353; num=num*2%998244353; } for(int i=0;i<n;++i)ans=(ans+a[i]*a[i]%998244353)%998244353; printf("%lld",ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define f first #define s second #define pb push_back #define all(x) x.begin(), x.end() #define mp(x, y) make_pair(x, y) #define sz(li) (int) (li).size() #define sum(a) (accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) (min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define vi vector<int> #define vl vector<ll> #define vvi vector<vi> #define vvl vector<vl> #define pii pair<int, int> #define pll pair<ll, ll> #define vpii vector<pii> #define vpll vector<pll> #define endl "\n" template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v); template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "[ "; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << " ]"; } template<typename A> ostream& operator<<(ostream &cout, vector<vector<A>> const &v) { cout << "["; for (int i = 0; i < v.size(); i++) { if (i) { cout << " "; } cout << v[i]; if (i < v.size() - 1) { cout << endl; } } return cout << "]"; } template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; } template<typename T, typename U> void cmin(T& a, U b){ if (a > b) a = b; } template<typename T, typename U> void cmax(T& a, U b){ if (a < b) a = b; } void solve() { int n; cin >> n; vi a(n); map<int, ll> freq; for (int i = 0; i < n; i++) { cin >> a[i]; freq[a[i] % 200]++; } ll ans = 0; for (int i = 0; i < 200; i++) { ans += freq[i] * (freq[i] - 1) / 2; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } cerr << "Time: " << 1000.0*clock()/CLOCKS_PER_SEC << " ms\n"; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; vector<vector<int>> g; int main() { int n, m; cin >> n >> m; vector<int> a(n); int ma = 1000000001, MA = -1; rep(i, n) { cin >> a[i]; if (ma > a[i]) ma = a[i]; if (MA < a[i]) MA = a[i]; } g.resize(n); rep(i, m) { int x, y; cin >> x >> y; --x;--y; g[y].push_back(x); } vector<int> dp(n, -1); rep(i, n) { if (dp[i] >= 0) continue; int res = 1e9+1; for (auto x : g[i]) { if (dp[x] == -1) res = min(res, a[x]); else res = min({res, dp[x], a[x]}); } dp[i] = res; } int ans = -1e9; for (int i = 0; i < n; i++) { if (dp[i] == 1e9+1) continue; ans = max(ans, a[i] - dp[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> /* #include <atcoder/all> */ #define rng(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define per(i, b) gnr(i, 0, b) using namespace std; /* using namespace atcoder; */ using ll = long long; using P = pair<int, int>; const int MOD = 1'000'000'007; template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int h, w; cin >> h >> w; vector<string> s(h); rep(i, h) { cin >> s.at(i); } vector<vector<ll>> r(h, vector<ll>(w)); vector<vector<ll>> d(h, vector<ll>(w)); vector<vector<ll>> rd(h, vector<ll>(w)); vector<vector<ll>> dp(h, vector<ll>(w, 0)); dp.at(0).at(0) = 1; rep(i, h) { rep(j, w) { if (s.at(i).at(j) == '#') { r.at(i).at(j) = 0; d.at(i).at(j) = 0; rd.at(i).at(j) = 0; continue; } // r int oi = i - 1; int oj = j; if (oi < h && oj < w && oi >= 0 && oj >= 0) { r.at(i).at(j) += dp.at(oi).at(oj); r.at(i).at(j) += r.at(oi).at(oj); } // d oi = i; oj = j - 1; if (oi < h && oj < w && oi >= 0 && oj >= 0) { d.at(i).at(j) += dp.at(oi).at(oj); d.at(i).at(j) += d.at(oi).at(oj); } // rd oi = i - 1; oj = j - 1; if (oi < h && oj < w && oi >= 0 && oj >= 0) { rd.at(i).at(j) += dp.at(oi).at(oj); rd.at(i).at(j) += rd.at(oi).at(oj); } dp.at(i).at(j) += r.at(i).at(j); dp.at(i).at(j) %= MOD; dp.at(i).at(j) += d.at(i).at(j); dp.at(i).at(j) %= MOD; dp.at(i).at(j) += rd.at(i).at(j); dp.at(i).at(j) %= MOD; } } cout << dp.at(h - 1).at(w - 1) << endl; return 0; }
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <iomanip> #include <vector> #include <string> #include <math.h> #include <algorithm> #include <map> #include <queue> #include <climits> #define rep(i,n) for (int i=0;i<(n);i++) using namespace std; long long MAX = 100005; long long N, M, Y, K; string S,T; //vector<int> g(Max); int main() { string s; cin >> s; int o_num = 0; int nate_num = 0; for (int i = 0;i < s.length();i++) { if (s[i] == 'o') { o_num++; } else if (s[i] == '?') { nate_num++; } } int ans = 0; if (o_num > 4) { cout << 0 << endl; return 0; } else if(o_num == 4) { ans = 4 * 3 * 2; } else if(o_num == 3){ ans += 4 * (3 * 2) * (nate_num);//はてなあり ans += 3 * 2 * 3 * 2;//はてななし } else if (o_num == 2) { ans += (3 * 2) * 2 * (nate_num * nate_num);//はてな2 ans += 4 * 6 * (nate_num);//はてな1 ans += 14;//はてななし } else if (o_num == 1) { ans += 4 * pow(nate_num, 3);//はてな3 ans += (3 * 2) * (nate_num * nate_num);//はてな2 ans += 4 * (nate_num);//はてな1 ans += 1;//はてななし } else if (o_num == 0) { ans += pow(nate_num, 4); } cout << ans << endl; return 0; }
// L:27 #include <bits/stdc++.h> #define MOD 1000000007 #define INF 1000000000 #define LINF 1000000000000000000 #define rep(i,n) for(int i=0;i<n;i++) #define ALL(a) a.begin(),a.end() #define PB(a) push_back(a) using namespace std; using ll=long long; using P=pair<int,int>; const int dx[]={0,-1,1,0},dy[]={-1,0,0,1}; //const int dx[]={-1,0,1,-1,1,-1,0,1},dy[]={-1,-1,-1,0,0,1,1,1}; ll modpow(ll a,ll k,ll m) { ll r=1; while(k>0) { if(k&1) r=r*a%m; a=a*a%m; k>>=1; } return r; } int main(void) { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(7); string s; cin >> s; int ans=0; vector<int> o,x; rep(i,10) { if(s[i]=='o') o.PB(i); else if(s[i]=='x') x.PB(i); } rep(i,10000) { int a,b,c,d; a=i%10; b=i%100/10; c=i%1000/100; d=i/1000; bool f=true; rep(j,o.size()) { if(!(o[j]==a || o[j]==b || o[j]==c || o[j]==d) ) f=false; } rep(j,x.size()) { if(x[j]==a || x[j]==b || x[j]==c || x[j]==d) f=false; } if(f) ans++; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int re(){ int i=0,f=1; char c=getchar(); for(;!isdigit(c);c=getchar()) if(c=='-') f=-1; for(;isdigit(c);c=getchar()) i=(i<<3)+(i<<1)+c-'0'; return i*f; } void solve(){ int n; cin>>n; int haha=((int)(sqrt(8.0*n+17))-3)/2; while(haha*haha+3*haha>=2*n+2) --haha; while((haha+1)*(haha+1)+3*(haha+1)<2*n+2) ++haha; cout<<n-haha; } signed main(){ int T=1; while(T--) solve(); }
#include <bits/stdc++.h> using namespace std; typedef int_fast32_t int32; typedef int_fast64_t int64; const int32 inf = 1e9+7; const int32 MOD = 998244353; const int64 llinf = 1e18; #define YES(n) cout << ((n) ? "YES\n" : "NO\n" ) #define Yes(n) cout << ((n) ? "Yes\n" : "No\n" ) #define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n" ) #define ANS(n) cout << (n) << "\n" #define REP(i,n) for(int64 i=0;i<(n);++i) #define FOR(i,a,b) for(int64 i=(a);i<(b);i++) #define FORR(i,a,b) for(int64 i=(a);i>=(b);i--) #define all(obj) (obj).begin(),(obj).end() #define rall(obj) (obj).rbegin(),(obj).rend() #define fi first #define se second #define pb(a) push_back(a) typedef pair<int32,int32> pii; typedef pair<int64,int64> pll; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } struct UnionFind{ vector<int> par; UnionFind(int32 n){ par = vector<int>(n, -1); } int root(int x){ if(par[x] < 0)return x; return par[x] = root(par[x]); } bool unite(int x, int y){ x = root(x); y = root(y); if(x == y)return false; if(-par[x] < -par[y])swap(x,y); par[x] += par[y]; par[y] = x; return true; } bool same(int x, int y){ return root(x) == root(y); } int size(int x){ return -par[root(x)]; } }; template<int64 mod> struct ModInt{ int64 x; constexpr ModInt(int64 y = 0):x((y%mod+mod)%mod){} constexpr ModInt& operator+=(const ModInt& a){ if((x += a.x) >= mod) x -= mod; return *this; } constexpr ModInt& operator-=(const ModInt& a){ if((x -= a.x) < 0)x += mod; return *this; } constexpr ModInt& operator*=(const ModInt& a){ x = x * a.x % mod; return *this; } constexpr ModInt& operator/=(const ModInt& a){ *this *= a.inv(); return *this; } constexpr ModInt operator-() const { return ModInt(-x); } constexpr ModInt operator+(const ModInt& a) const { return ModInt(*this) += a; } constexpr ModInt operator-(const ModInt& a) const { return ModInt(*this) -= a; } constexpr ModInt operator*(const ModInt& a) const { return ModInt(*this) *= a; } constexpr ModInt operator/(const ModInt& a) const { return ModInt(*this) /= a; } constexpr ModInt operator++(){ *this += ModInt(1); return *this; } constexpr ModInt operator++(int){ ModInt old = *this; ++*this; return old; } constexpr ModInt operator--(){ *this -= ModInt(1); return *this; } constexpr ModInt operator--(int){ ModInt old = *this; --*this; return old; } constexpr bool operator==(const ModInt& a) const { return x == a.x; } constexpr bool operator!=(const ModInt& a) const { return x != a.x; } constexpr ModInt pow(int64 r) const { if(!r)return 1; ModInt res = pow(r>>1); res *= res; if(r & 1) res *= *this; return res; } constexpr ModInt inv() const { return pow(mod-2); } friend istream& operator>>(istream& is, ModInt& a){ int64 t; is >> t; a = ModInt(t); return is; } friend ostream& operator<<(ostream& os, const ModInt& a){ return os << a.x; } }; using mint = ModInt<MOD>; int main(){ cin.tie(0); ios::sync_with_stdio(false); int32 n; cin >> n; UnionFind uf(n); REP(i,n){ int32 f; cin >> f; --f; uf.unite(i,f); } int32 cnt = 0; REP(i,n){ if(i == uf.root(i))++cnt; } ANS(mint(2).pow(cnt)-1); return 0; }