solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; long long n, r1, c1, r2, c2; vector<string> s; long long vis[51][51]; vector<pair<long long, long long> > pp{ {-1ll, 0ll}, {1ll, 0ll}, {0ll, 1ll}, {0ll, -1ll}}; vector<pair<long long, long long> > bfs(long long lx, long long ly) { vector<pair<long long, long long> > ans; queue<pair<long long, long long> > q; q.push({lx, ly}); vis[lx][ly] = 1; while (q.size()) { auto top = q.front(); ans.push_back(top); q.pop(); for (auto &i : pp) { long long nx = top.first + i.first, ny = top.second + i.second; if (nx < 0 || nx >= n) continue; if (ny < 0 || ny >= n) continue; if (vis[nx][ny]) continue; if (s[nx][ny] == '1') continue; vis[nx][ny] = 1; q.push({nx, ny}); } } return ans; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> r1 >> c1 >> r2 >> c2; r1--; c1--; r2--; c2--; s.resize(n); for (long long i = 0; i < n; i++) { cin >> s[i]; } long long ans = 2 * n * n; auto a = bfs(r1, c1), b = bfs(r2, c2); for (auto &i : a) { for (auto &j : b) { ans = min(ans, (i.first - j.first) * (i.first - j.first) + (i.second - j.second) * (i.second - j.second)); } } cout << ans << '\n'; return 0; }
3
#include<bits/stdc++.h> #define cs const #define pb push_back using namespace std; cs int N = 25005; int n, m, a[N]; int lu[N], ld[N], ru[N], rd[N]; int lp[N], rp[N], ans; void upt(int l, int r) { for(int i = l; i <= r; i++) { for(int &j = lp[i]; j >= l; j--) { if(a[j] > a[i]) { int &k = lu[i]; if(a[j] < a[k]) { ans += rd[j] == i; ans -= rd[k] == i; k = j; } } else { int &k = ld[i]; if(a[j] > a[k]) { ans += ru[j] == i; ans -= ru[k] == i; k = j; } } } for(int &j = rp[i]; j <= r; j++) { if(a[j] > a[i]) { int &k = ru[i]; if(a[j] < a[k]) { ans += ld[j] == i; ans -= ld[k] == i; k = j; } } else { int &k = rd[i]; if(a[j] > a[k]) { ans += lu[j] == i; ans -= lu[k] == i; k = j; } } } } } int main() { #ifdef FSYo freopen("1.in", "r", stdin); #endif cin >> n >> m; for(int i = 1; i <= n; i++) scanf("%d", &a[i]); a[n + 1] = n + 1; for(int i = 1; i <= n; i++) { lu[i] = ru[i] = n + 1; lp[i] = i - 1, rp[i] = i + 1; } for(int i = 1, l, r; i <= m; i++) { scanf("%d%d", &l, &r); upt(l, r), cout << ans << '\n'; } return 0; }
6
#include <bits/stdc++.h> using namespace std; const int MAXN = 101; const int MAXM = 20; const long long INF = 1LL << 61; struct person { int monitors, solve; long long cost; person() { monitors = solve = 0; cost = 0; } person(int _monitors, int _solve, long long _cost) { monitors = _monitors; solve = _solve; cost = _cost; } bool operator<(const person& p) const { return monitors < p.monitors; } }; person P[MAXN]; int N, M; long long B; long long DP[1 << MAXM]; int main() { cin >> N >> M >> B; for (int i = 0; i < N; ++i) { int NM; cin >> P[i].cost >> P[i].monitors >> NM; int msk = 0; for (int k = 0; k < NM; ++k) { int num; cin >> num; --num; msk |= (1 << num); } P[i].solve = msk; } sort(P, P + N); int all = (1 << M) - 1; for (int i = 0; i <= all; ++i) { DP[i] = INF; } DP[0] = 0; long long res = INF; for (int i = 0; i < N; ++i) { for (int msk = 0; msk <= all; ++msk) { if (DP[msk] < INF) { int nxt = msk | P[i].solve; DP[nxt] = min(DP[nxt], DP[msk] + P[i].cost); } } if (DP[all] < INF) { res = min(res, DP[all] + B * P[i].monitors); } } if (res == INF) { cout << -1 << endl; } else { cout << res << endl; } return 0; }
2
#include<iostream> #include<math.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,x=1; cin>>n; if(n==3) { cout<<2<<endl<<3<<" "<<2<<endl<<3<<" "<<2<<endl; continue; } if(n>10) { while(pow(8,x)<n) x++; cout<<n-1+x<<endl; for(int i=3;i<=7;i++) cout<<i<<" "<<i+1<<endl; for(int i=9;i<=n-1;i++) cout<<i<<" "<<i+1<<endl; while(x--) cout<<n<<" "<<8<<endl; cout<<8<<" "<<2<<endl<<8<<" "<<2<<endl<<8<<" "<<2<<endl; continue; } while(pow(3,x)<n) x++; cout<<n-4+2+x<<endl; for(int i=4;i<=n-1;i++) cout<<i<<" "<<i+1<<endl; while(x--) cout<<n<<" "<<3<<endl; cout<<3<<" "<<2<<endl<<3<<" "<<2<<endl; } return 0; }
4
#include <bits/stdc++.h> using namespace std; int n, k, a[100005], b[100005], q; vector<int> ke[100005], t[100005 * 4]; void setup() { cin >> n >> k; for (long long i = (1); i <= (n); i++) { cin >> a[i]; ke[a[i]].push_back(i); } } void add(int x) { int y = x * 2, z = x * 2 + 1; int i = 0, j = 0, cnt = 0; t[x].resize(t[y].size() + t[z].size()); while (i < t[y].size() || j < t[z].size()) { if (i == t[y].size()) t[x][cnt++] = t[z][j++]; else if (j == t[z].size()) t[x][cnt++] = t[y][i++]; else if (t[y][i] < t[z][j]) t[x][cnt++] = t[y][i++]; else t[x][cnt++] = t[z][j++]; } } void build(int node, int l, int r) { if (l == r) { t[node].push_back(b[l]); return; } int mid = (l + r) >> 1; build(node * 2, l, mid); build(node * 2 + 1, mid + 1, r); add(node); } int get(int node, int l, int r, int u, int v) { if (l > v || u > r) return 0; if (u <= l && r <= v) { int pos = lower_bound(t[node].begin(), t[node].end(), u) - t[node].begin(); return pos; } int mid = (l + r) >> 1; int m1 = get(node * 2, l, mid, u, v); int m2 = get(node * 2 + 1, mid + 1, r, u, v); return m1 + m2; } void work() { for (long long i = (1); i <= (n); i++) { int pos = lower_bound(ke[a[i]].begin(), ke[a[i]].end(), i) - ke[a[i]].begin(); if (pos < k) b[i] = 0; else b[i] = ke[a[i]][pos - k]; } build(1, 1, n); cin >> q; int last = 0; while (q--) { int l, r; cin >> l >> r; l = ((l + last) % n) + 1; r = ((r + last) % n) + 1; if (l > r) swap(l, r); cout << (last = get(1, 1, n, l, r)) << '\n'; } } int main() { ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); setup(); work(); return 0; }
5
#include <bits/stdc++.h> using namespace std; const double pi(3.14159265358979); int row[1010], col[1010]; int main() { int i, j, cnt, n, m, ans; scanf("%d", &m); scanf("%d", &n); char a[1010][1010]; for (i = 0; i < m; i++) scanf("%s", &a[i]); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) if (a[i][j] == '*') row[i]++; } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if (a[j][i] == '*') col[i]++; } } cnt = 0; for (i = 0; i < m; i++) for (j = 0; j < n; j++) if (a[i][j] == '*') cnt++; int r, c, f = 0; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { ans = col[j] + row[i]; if (a[i][j] == '*') ans--; if (ans == cnt) { f = 1; r = i + 1; c = j + 1; } } } if (f == 0) { printf("NO\n"); } else { printf("YES\n%d %d\n", r, c); } return 0; }
2
#include <bits/stdc++.h> int main() { int n, k; scanf("%d %d", &n, &k); if (n % k == 0) printf("%d", n + k); else { printf("%d", n + (k - (n % k))); } return 0; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; int H, W; bitset<100> field; bitset<100> zeros; int carpet[15][15]; int baseans; int ans; vector<bitset<100>> bits; void print(bitset<100> a) { for(int h = 0; h < H; h++) { for(int w = 0; w < W; w++) { cerr << a[h*10+w]; } cerr << endl; } } void dfs(int index, int nowans, bitset<100> nowfield) { if(index == bits.size()) { if(nowfield == (~zeros)) { ans = min(ans, nowans); } return; } dfs(index + 1, nowans, nowfield); dfs(index + 1, nowans + 1, nowfield |= bits[index]); } int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); while(true) { bits.clear(); baseans = 0; ans = INF; cin >> W >> H; if(H == 0) break; for(int h = 0; h < H; h++) { for(int w = 0; w < W; w++) { cin >> carpet[h][w]; } } field &= zeros; /* for(int h = H; h < 10; h++) { for(int w = W; w < 10; w++) { field[h * 10 + w] = true; } }*/ for(int h = 0; h < 10; h++) { for(int w = 0; w < 10; w++) { if(h >= H || w >= W) { field[h * 10 + w] = true; continue; } if(carpet[h][w] == 0) field[h * 10 + w] = true; } } for(int h = 0; h < H; h++) { for(int w = 0; w < W; w++) { if(carpet[h][w] == 0) continue; int SIZE = 1; while(true) { //cerr << h << " " << w << " " << SIZE << endl; if(h + SIZE == H) break; if(w + SIZE == W) break; bool ok = true; for(int noww = w; noww <= w + SIZE; noww++) { if(carpet[h+SIZE][noww] == 0) ok = false; } for(int nowh = h; nowh <= h + SIZE; nowh++) { if(carpet[nowh][w+SIZE] == 0) ok = false; } if(!ok) break; SIZE++; } bitset<100> now; for(int nowh = h; nowh < h + SIZE; nowh++) { for(int noww = w; noww < w + SIZE; noww++) { now[nowh * 10 + noww] = true; } } bits.push_back(now); } } for(int timer = 0; timer <= 10; timer++) { for(int i = 0; i < bits.size(); i++) { //cerr << i << endl; for(int j = 0; j < bits.size(); j++) { if(i == j) continue; if((bits[i] & bits[j]) == bits[i]) { //cerr << i << " " << bits[i] << endl; //cerr << j << " " << bits[j] << endl; bits.erase(bits.begin() + i); i--; break; } } } for(int i = 0; i < bits.size(); i++) { //cerr << endl << i << endl; //print(bits[i]); } for(int i = 0; i < bits.size(); i++) { //cerr << "others " << i << endl; bitset<100> others; for(int j = 0; j < bits.size(); j++) { if(i == j) continue; others |= bits[j]; } if((bits[i] | others) != others) { field |= bits[i]; for(int k = 0; k < bits.size(); k++) { if(i == k) continue; bits[k] &= (~bits[i]); } baseans++; bits.erase(bits.begin() + i); i--; continue; } } } /* cerr << baseans << endl; for(int i = 0; i < bits.size(); i++) cerr << bits[i] << endl; */ for(int i = 0; i < bits.size(); i++) { if(bits[i] == zeros) { bits.erase(bits.begin() + i); i--; } } //cerr << baseans << endl; //cerr << bits.size() << endl; //print(field); //cerr << field << endl; dfs(0, 0, field); cout << ans + baseans << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j; string in, out; cin >> n; cin >> in; for (i = 0; i < in.length(); i++) out += '9'; for (j = 0; j < in.length(); j++) { string s; int x = (10 - (in[j] - '0')) % 10; for (i = j; i != (j - 1 + in.length()) % in.length(); i = (i + 1) % in.length()) s += ((in[i] - '0' + x) % 10 + '0'); s += ((in[i] - '0' + x) % 10 + '0'); if (s < out) out = s; } cout << out << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; const int N = 1000 * 100 + 100, INF = 1000 * 1000 * 1000; int dp[N], b[N], ans[N], seg[4 * N], n, t[4 * N]; vector<int> num[N]; vector<pair<int, int> > q[N]; void upd(int p, int val, int s = 0, int e = n, int id = 1) { if (e - s == 1) { seg[id] = val; return; } int mid = (s + e) / 2; if (p < mid) upd(p, val, s, mid, id * 2); else upd(p, val, mid, e, id * 2 + 1); seg[id] = min(seg[id * 2], seg[id * 2 + 1]); } int get(int l, int r, int s = 0, int e = n, int id = 1) { if (r <= s || e <= l) return INF; if (l <= s && e <= r) return seg[id]; int mid = (s + e) / 2; return min(get(l, r, s, mid, id * 2), get(l, r, mid, e, id * 2 + 1)); } void updt(int p, int val, int s = 0, int e = n, int id = 1) { t[id] += val; if (e - s == 1) return; int mid = (s + e) / 2; if (p < mid) updt(p, val, s, mid, id * 2); else updt(p, val, mid, e, id * 2 + 1); } int get2(int l, int r, int s = 0, int e = n, int id = 1) { if (r <= s || e <= l) return 0; if (l <= s && e <= r) return t[id]; int mid = (s + e) / 2; return get2(l, r, s, mid, id * 2) + get2(l, r, mid, e, id * 2 + 1); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> b[i]; int m; cin >> m; for (int i = 0; i < m; i++) { int l, r; cin >> l >> r; l--; r--; q[r].push_back({l, i}); } for (int i = 0; i < N; i++) dp[i] = INF; for (int i = 0; i < 4 * N; i++) seg[i] = INF; for (int i = 0; i < n; i++) { num[b[i]].push_back(i); int s = num[b[i]].size(); if (s == 1) dp[i] = 0; else if (s == 2) { dp[i] = 0; dp[num[b[i]][s - 2]] = INF; upd(num[b[i]][s - 2], INF); updt(num[b[i]][s - 2], -1); } else { if (num[b[i]][s - 1] - num[b[i]][s - 2] == num[b[i]][s - 2] - num[b[i]][s - 3]) dp[i] = dp[num[b[i]][s - 2]]; else dp[i] = num[b[i]][s - 3] + 1; dp[num[b[i]][s - 2]] = INF; upd(num[b[i]][s - 2], INF); updt(num[b[i]][s - 2], -1); } upd(i, dp[i]); updt(i, +1); for (int j = 0; j < q[i].size(); j++) { int l = q[i][j].first; ans[q[i][j].second] = get2(l, i + 1); if (get(l, i + 1) > l) ans[q[i][j].second]++; } } for (int i = 0; i < m; i++) cout << ans[i] << '\n'; return 0; }
4
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize "trapv" void solve() { long long int a, b, c; cin >> a >> b >> c; long long int x = c + a + b - 2; cout << x; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); ; long long int t; cin >> t; while (t--) { solve(); cout << '\n'; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int n, now, sfeefw; long long ans; int rnk[22 + 1][500005], bal[500005], tot[500005]; pair<pair<int, int>, int> sa[500005]; vector<int> v[2 * 500005]; char s[500005]; int total(int ind, int sz) { auto it1 = prev(upper_bound(v[bal[ind] - 1 + 500005].begin(), v[bal[ind] - 1 + 500005].end(), ind + sz - 1)); auto it2 = lower_bound(v[bal[ind] - 1 + 500005].begin(), v[bal[ind] - 1 + 500005].end(), ind); return it1 - it2 + 1; } int getnear(int now) { auto it = lower_bound(v[bal[now] - 2 + 500005].begin(), v[bal[now] - 2 + 500005].end(), now); if (it == v[bal[now] - 2 + 500005].end()) return 2000000009; return *it - now; } int getlcp(int x, int y) { int res = 0; for (int i = sfeefw; i >= 0; i--) { if ((1 << (i)) + max(x, y) - 1 > n) continue; if (rnk[i][x] == rnk[i][y]) { res += (1 << (i)); x += (1 << (i)); y += (1 << (i)); } } return res; } void suffix_array() { now = 1; sfeefw = 0; for (int i = 1; i <= n; i++) { sa[i] = {{s[i], s[i]}, i}; } while (1) { sort(sa + 1, sa + 1 + n); int cnt = 0; for (int i = 1; i <= n; i++) { ++cnt; while (i + 1 <= n && sa[i].first == sa[i + 1].first) { rnk[sfeefw][sa[i].second] = cnt; i++; } rnk[sfeefw][sa[i].second] = cnt; } if (now >= n) break; for (int i = 1; i <= n; i++) { sa[i] = {{rnk[sfeefw][i], (i + now <= n ? rnk[sfeefw][i + now] : 0)}, i}; } now *= 2; sfeefw++; } } int main() { scanf("%d", &n); scanf("%s", s + 1); for (int i = 1; i <= n; i++) { bal[i] = bal[i - 1] + (s[i] == '(') - (s[i] == ')'); v[bal[i] + 500005].push_back(i); } suffix_array(); for (int i = 1; i < n; i++) { int ind = sa[i].second; int go = min(getlcp(sa[i].second, sa[i + 1].second), getnear(ind)); if (s[ind] == ')') continue; ans -= total(ind, go); } tot[0] = 1; int add = 0; for (int i = 1; i <= n; i++) { if (bal[i] + add < 0) { tot[0] = 1; add++; continue; } if (s[i] == ')') { ans += tot[bal[i] + add]; tot[bal[i] + 1 + add] = 0; } tot[bal[i] + add]++; } printf("%lld", ans); }
6
#include <cstdio> #include <algorithm> #include <utility> using namespace std; const int N = 1000000; int n; pair<int, int> a1[N]; pair<int, int> a2[N]; int n1, n2; char s[N + 1]; bool test(pair<int, int> *a, int n) { sort(a, a + n); int p = 0; for (int i = 0; i < n; ++i) { if (a[i].first > p) return false; p += a[i].second; } return true; } int main() { scanf("%d", &n); int b = 0; for (int i = 0; i < n; ++i) { scanf("%s", s); int f = 0; int l = 0; for (int j = 0; s[j]; ++j) { f += (s[j] == '(') * 2 - 1; l = min(l, f); } b += f; if (f >= 0) { a1[n1] = make_pair(-l, f); ++n1; } else { a2[n2] = make_pair(-l + f, -f); ++n2; } } if (!b && test(a1, n1) && test(a2, n2)) printf("Yes\n"); else printf("No\n"); return 0; }
0
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") const int N = 1e5 + 5; int t[2][N]; void up(int i, int p, int v) { if (p <= 0) return; for (; p < N; p += p & (-p)) { t[i][p] = max(t[i][p], v); } } int qry(int i, int p) { if (p <= 0) return 0; int res = 0; for (; p > 0; p -= p & (-p)) { res = max(res, t[i][p]); } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, c, d; cin >> n >> c >> d; int ans = 0; for (int i = 0; i < n; i++) { int b, p, val = 0; char t; cin >> b >> p >> t; if (t == 'C') { val = max(qry(0, c - p), qry(1, d) * (p <= c)); up(0, p, b); } if (t == 'D') { val = max(qry(1, d - p), qry(0, c) * (p <= d)); up(1, p, b); } ans = max(ans, val + b * (val > 0)); } cout << ans; }
3
#include <bits/stdc++.h> using namespace std; long long mp[27][27]; char s[110]; long long n; long long mem[101][101][27]; long long dp(long long cur, long long k, long long pre) { if (k < 0) return -1000000007; if (n == cur) return 0; long long &ret = mem[cur][k][pre], x = s[cur] - 'a' + 1; if (ret != -1000000007) return ret; for (long long i = 1; i <= 26; i++) ret = max(ret, mp[pre][i] + dp(cur + 1, x == i ? k : k - 1, i)); return ret; } int main() { for (long long i = 0; i <= 100; i++) for (long long j = 0; j <= 100; j++) for (long long k = 0; k <= 26; k++) mem[i][j][k] = -1000000007; long long k, q, x; char a, b; scanf("%s %lld", s, &k); n = strlen(s); scanf("%lld", &q); while (q--) { cin >> a >> b >> x; mp[a - 'a' + 1][b - 'a' + 1] = x; } printf("%lld\n", dp(0, k, 0)); return 0; }
3
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; const int maxn = 2010; const unsigned long long base = 234323; unsigned long long p[maxn] = {}; unsigned long long h[maxn] = {}; unsigned long long gethash(int i, int j) { unsigned long long ans = h[j]; if (i) ans -= h[i - 1] * p[j - i + 1]; return ans; } unsigned long long vv[maxn * maxn]; int vvcnt = 0; int main() { p[0] = 1; for (int i = 1; i < maxn; ++i) p[i] = p[i - 1] * base; string s, sbeg, send; cin >> s >> sbeg >> send; unsigned long long hbeg = 0, hend = 0; for (int i = 0; i < sbeg.length(); ++i) hbeg = hbeg * base + (sbeg[i] - 'a' + 1); for (int i = 0; i < send.length(); ++i) hend = hend * base + (send[i] - 'a' + 1); for (int i = 0; i < s.length(); ++i) h[i] = s[i] - 'a' + 1 + base * (i ? h[i - 1] : 0); int minlen = max(send.length(), sbeg.length()); for (int l = 0; l < s.length(); ++l) for (int r = l + minlen - 1; r < s.length(); ++r) { unsigned long long hl = gethash(l, l + sbeg.length() - 1); unsigned long long hr = gethash(r - send.length() + 1, r); if (hl == hbeg && hr == hend) vv[vvcnt++] = gethash(l, r); } sort(vv, vv + vvcnt); int ans = unique(vv, vv + vvcnt) - vv; printf("%d", ans); return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, m; int a[50]; int b[50]; int score[51][51][51][51][2][2]; int memo[51][51][51][51][2]; bool check[51][51][51][51][2]; int getPassScore(int i, int j, int beforeI, int beforeJ, int turn, int player){ if(i == beforeI && j == beforeJ){ return 0; } int temp = score[i][j][beforeI][beforeJ][turn][player]; if(temp != -1){ return temp; } if((player == 0 && i == beforeI) || (player == 1 && j == beforeJ)){ score[i][j][beforeI][beforeJ][turn][player] = 0; return 0; } //cout << i << " " << j << " " << beforeI << " " << beforeJ << " " << turn << " " << player << endl; int ret = 0; if(turn == 0){ if(player == 0){ if(j != beforeJ && b[j - 1] == -1){ ret = 0; } else{ ret = getPassScore(i, j - 1, beforeI, beforeJ, 1, player); } } else{ if(b[j - 1] == -1){ ret = getPassScore(i, j - 1, beforeI, beforeJ, 1, player); } else{ ret = getPassScore(i, j - 1, beforeI, beforeJ, 1, player) + b[j - 1]; } } } else{ if(player == 0){ if(a[i - 1] == -1){ ret = getPassScore(i - 1, j, beforeI, beforeJ, 0, player); } else{ ret = getPassScore(i - 1, j, beforeI, beforeJ, 0, player) + a[i - 1]; } } else{ if(i != beforeI && a[i - 1] == -1){ ret = 0; } else{ ret = getPassScore(i - 1, j, beforeI, beforeJ, 0, player); } } } score[i][j][beforeI][beforeJ][turn][player] = ret; return ret; } int getScore(int i, int j, int beforeI, int beforeJ, int turn){ if(i == n && j == m) { //cout << beforeI << " " << beforeJ << endl; //cout << "score" << getPassScore(i, j, beforeI, beforeJ, turn, 0) << " " << getPassScore(i, j, beforeI, beforeJ, turn, 1) << endl; return getPassScore(i, j, beforeI, beforeJ, turn, 0) - getPassScore(i, j, beforeI, beforeJ, turn, 1); } if(check[i][j][beforeI][beforeJ][turn]){ return memo[i][j][beforeI][beforeJ][turn]; } check[i][j][beforeI][beforeJ][turn] = true; if(turn == 0){ int putScore = 0; if(i == n){ putScore = -(1 << 30); } else{ putScore = getScore(i + 1, j, beforeI, beforeJ, 1); } int passScore = 0; if(i == beforeI && j == beforeJ){ if(j == m){ passScore = 0; } else{ passScore = min(0, getScore(i, j + 1, i, j, 0)); } } else{ passScore = getScore(i, j, i, j, 1) + getPassScore(i, j, beforeI, beforeJ, turn, 0) - getPassScore(i, j, beforeI, beforeJ, turn, 1); } int ret = max(putScore, passScore); memo[i][j][beforeI][beforeJ][turn] = ret; //cout << i << " " << j << " " << beforeI << " " << beforeJ << " " << turn << " " << ret << endl; return ret; } else{ int putScore = 0; if(j == m){ putScore = (1 << 30); } else{ putScore = getScore(i, j + 1, beforeI, beforeJ, 0); } int passScore = 0; if(i == beforeI && j == beforeJ){ if(i == n){ passScore = 0; } else{ passScore = max(0, getScore(i + 1, j, i, j, 1)); } } else{ passScore = getScore(i, j, i, j, 0) + getPassScore(i, j, beforeI, beforeJ, turn, 0) - getPassScore(i, j, beforeI, beforeJ, turn, 1); } int ret = min(putScore, passScore); memo[i][j][beforeI][beforeJ][turn] = ret; //cout << i << " " << j << " " << beforeI << " " << beforeJ << " " << turn << " " << ret << endl; return ret; } } int main(){ cin >> n >> m; for(int i = 0; i < n; i++){ cin >> a[i]; } for(int j = 0; j < m; j++){ cin >> b[j]; } memset(score, -1, sizeof(score)); memset(memo, -1, sizeof(memo)); for(int i = 0; i <= n; i++){ for(int j = 0; j <= m; j++){ for(int beforeI = 0; beforeI <= i; beforeI++){ for(int beforeJ = 0; beforeJ <= j; beforeJ++){ check[i][j][beforeI][beforeJ][0] = false; check[i][j][beforeI][beforeJ][1] = false; } } } } int ans = getScore(0, 0, 0, 0, 0); cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main(void){ int n,t; cin>>n>>t; int ans =10000; for(int i=0;i<n;i++){ int c,t1; cin>>c>>t1; if(ans>c&&t1<=t) ans=c; } if(ans!=10000) cout<<ans<<endl; else cout<<"TLE"<<endl; }
0
#include <iostream> #include <vector> #include <cmath> using std::cin; using std::cout; using std::endl; int digit(int n, int d) { int m = (int)(n/pow(10,d)) * pow(10,d); return (n - m)/pow(10,d-1); } int check_digit(int n) { for (int i = 15; i > 0; i--) { if (digit(n, i) > 0) { return i; } } return 1; } bool check_ruel(int n) { int d = check_digit(n); for (int i = 1; i < d; i++) { if ((digit(n,i) - digit(n,i+1)) != 1) { return false; } } return true; } int main(void) { int N; cin >> N; std::vector<int> nums(N); for (int i = 0; i < N; i++ ) { cin >> nums[i]; } int maxp = -1; int pro; for (int i = 0; i < N; i++) { for (int j = i+1; j < N; j++) { pro = nums[i] * nums[j]; if (check_ruel(pro)) { if (pro > maxp) { maxp = pro; } } } } cout << maxp << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; void solve() { long long int n, a; cin >> n; long long int val = n / 2; long long int ans = 0, beg = 3; for (long long int i = 1; i <= val; i++) { ans += i * (2 * beg + 2 * (beg - 2)); beg += 2; } cout << ans << endl; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) solve(); return 0; }
3
#include <bits/stdc++.h> using namespace std; const int MN = 1e5 + 10, MOD = 1e9 + 7; int f, w, h, fact[MN], lfac[MN]; int bpw(int a, int b) { if (!b) return 1; int t = bpw(a, b / 2); t = 1ll * t * t % MOD; if (b & 1) return 1ll * a * t % MOD; return t; } int get(int a, int b) { if (a == 0 && b == 0) return 1; if (a > 0 && b == 0) return 0; if (b > a) return 0; return 1ll * fact[a - 1] * lfac[b - 1] % MOD * lfac[a - b] % MOD; } void ok(int &x) { if (x >= MOD) x -= MOD; } int main() { ios_base ::sync_with_stdio(false), cout.tie(0), cin.tie(0); cin >> f >> w >> h; if (w == 0) return cout << 1 << '\n', 0; for (int i = 0; i < MN; ++i) { fact[i] = (i ? 1ll * i * fact[i - 1] % MOD : 1); lfac[i] = bpw(fact[i], MOD - 2); } int P = 0, Q = 0; for (int i = 1; i <= w && f >= max(0, i - 1); ++i) { if (w >= 1ll * i * h) { P += 1ll * get(w - i * h, i) * get(f, i - 1) % MOD; ok(P); P += 1ll * get(w - i * h, i) * get(f, i) % MOD * 2 % MOD; ok(P); P += 1ll * get(w - i * h, i) * get(f, i + 1) % MOD; ok(P); } Q += 1ll * get(w, i) * get(f, i - 1) % MOD; ok(Q); Q += 1ll * get(w, i) * get(f, i) % MOD * 2 % MOD; ok(Q); Q += 1ll * get(w, i) * get(f, i + 1) % MOD; ok(Q); } cout << 1ll * P * bpw(Q, MOD - 2) % MOD << '\n'; return 0; }
6
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; template <typename S, typename T> inline bool Min(S &a, const T &b) { return a > b ? a = b, true : false; } template <typename S, typename T> inline bool Max(S &a, const T &b) { return a < b ? a = b, true : false; } template <typename S, typename T> inline void Adm(S &a, const T &b) { a = (a + b) % MOD; if (a < 0) a += MOD; } template <typename S, typename T> inline void Mum(S &a, const T &b) { a = 1LL * a * b % MOD; } template <typename T> inline T Gcd(T a, T b) { while (b) { T t = b; b = a % b; a = t; } return a; } template <typename T> inline int BCnt(T x) { int cnt = 0; while (x) ++cnt, x &= x - 1; return cnt; } inline long long Pow(long long a, long long n) { long long t = 1; while (n) { if (n & 1) t = t * a % MOD; a = a * a % MOD, n >>= 1; } return t; } int a[1000]; int main() { int n; cin >> n; cin >> a[1]; long long s = 0, t = a[1]; vector<int> v; for (int i = 2; i <= n; ++i) { int x; cin >> a[i]; if (a[i] <= a[1] / 2) t += a[i], v.push_back(i); else s += a[i]; } if (t > s) { cout << ((int)(v).size()) + 1 << endl << 1; for (int x : v) cout << ' ' << x; cout << endl; } else cout << 0 << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; int a[1005], b[1005], c[1005]; int main() { int t, n, i, s; cin >> t; while (t--) { cin >> n; for (i = 1; i <= n; i++) cin >> a[i] >> b[i]; c[1] = a[1]; for (i = 2, s = a[1] + 1; i <= n; i++, s++) { if (b[i] >= s) { if (a[i] >= s) { s = a[i]; c[i] = s; } else c[i] = s; } else { s--; c[i] = 0; } } for (i = 1; i <= n; i++) cout << c[i] << " "; cout << endl; } return 0; }
2
#include <bits/stdc++.h> using namespace std; vector<int> lst; void gen(long long n) { if (n > 1000000000) return; if (n > 0) lst.push_back(n); gen(n * 10 + 4); gen(n * 10 + 7); } int L1, R1, L2, R2, k; double f(double x, double y, double L, double R) { return max(0.0, min(R, y) - max(L, x) + 1); } double cal(int x1, int y1, int x2, int y2) { double ret = 0; ret += f(x1, y1, L1, R1) * f(x2, y2, L2, R2); ret += f(x2, y2, L1, R1) * f(x1, y1, L2, R2); if (y1 == x2) ret -= f(y1, y1, L1, R1) * f(x2, x2, L2, R2); return ret; } int main() { gen(0); lst.push_back(-1); lst.push_back(1000000001); sort(lst.begin(), lst.end()); double ans = 0; scanf("%d%d%d%d%d", &L1, &R1, &L2, &R2, &k); for (int i = 1; i + k < (int)lst.size(); i++) ans += cal(lst[i - 1] + 1, lst[i], lst[i + k - 1], lst[i + k] - 1); printf("%.14f\n", ans / (R1 - L1 + 1) / (R2 - L2 + 1)); return 0; }
2
#include <bits/stdc++.h> using namespace std; const int MAX_N = 50 + 7; const int MAX_K = 2000 + 7; const int INF = 0x3f3f3f3f; int N; int A[MAX_N]; char B[MAX_N]; int dp[MAX_N][MAX_K]; int dfs(int n, int k) { k -= A[n]; if (k <= 0) return 0; int &res = dp[n][k]; if (res != -1) return res; res = INF; for (int i = 1; i <= N; i++) { if (A[n] < A[i] && B[i] != B[n]) res = min(res, dfs(i, k) + abs(n - i)); } return res; } int main() { int S, K; scanf("%d%d%d", &N, &S, &K); for (int i = 1; i <= N; i++) scanf("%d", &A[i]); scanf("%s", B + 1); memset(dp, -1, sizeof(dp)); int ans = INF; for (int i = 1; i <= N; i++) ans = min(ans, dfs(i, K) + abs(S - i)); if (ans == INF) puts("-1"); else printf("%d\n", ans); return 0; }
3
#include <bits/stdc++.h> using namespace std; long long mod = 10000000000; int main() { long long t; cin >> t; while (t--) { string s; cin >> s; int ans = 0, n = s.length(); if (n <= 1) cout << ans << endl; else { int st = -1, ed = -1; for (int i = 0; i < n; i++) { if (s[i] == '1') { st = i; break; } } for (int i = n - 1; i >= 0; i--) { if (s[i] == '1') { ed = i; break; } } for (int i = st; i <= ed; i++) if (s[i] == '0') { ans++; } cout << ans << endl; } } return 0; }
1
#include <vector> #include <algorithm> #include <utility> #include <bitset> #include <iostream> using namespace std; const int inf = 1000000009; int dfs(vector<vector<int>> &graph, bitset<101> &used, int flow, int pos, int t) { if (pos == t) return flow; for (int i=0; i<graph[pos].size(); i++) { if (used[i] == 0 && graph[pos][i] > 0) { used[i] = 1; int maxflow = dfs(graph, used, min(flow, graph[pos][i]), i, t); if (maxflow > 0) { graph[i][pos] = graph[i][pos] + maxflow; graph[pos][i] = graph[pos][i] - maxflow; return maxflow; } } } return 0; } int maxflow(vector<vector<int>> graph, int s, int t) { bool f = true; int sum = 0; while (f) { bitset<101> b(0); b[s] = 1; int current = dfs(graph, b, inf, s, t); sum += current; f &= current != 0; } return sum; } int main() { int v, e; cin >> v >> e; vector<vector<int>> graph(v); for(auto &l: graph) l.resize(v, 0); for(int i=0; i<e; i++) { int u, v, c; cin >> u >> v >> c; graph[u][v] = c; } cout << maxflow(graph, 0, v-1) << endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; while (t--) { int ans = 0; cin >> n; cout << n / 2 << endl; } }
1
#include <bits/stdc++.h> using namespace std; template <typename... T> void scan(T &...args) { ((cin >> args), ...); } template <typename... T> void print(T... args) { ((cout << args), ...); } class Solution_To_Problem { int r, g, b, m, ans; array<pair<char, int>, 3> count; public: void solution_function() { scan(r, g, b); count[0] = make_pair('B', ceil(b / 2.0)); count[1] = make_pair('G', ceil(g / 2.0)); count[2] = make_pair('R', ceil(r / 2.0)); m = INT_MIN; for (int i = 0; i < 3; i++) { if (count[i].second > m) { m = count[i].second; ans = 30 + (3 - i - 1) + (m - 1) * 3; } } print(ans, '\n'); } } Solution; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); Solution.solution_function(); return 0; }
1
#include <bits/stdc++.h> using namespace std; char in[10]; int main() { int n; cin >> n; long long h = 1LL; long long w = 1LL; for (int i = 0; i < n; ++i) { scanf("%s", in); string txt = in; if (txt == "UR" || txt == "DL") { ++h; } else if (txt == "UL" || txt == "DR") { ++w; } else { assert(txt == "ULDR"); ++h; ++w; } } cout << h * w << endl; }
1
#include <bits/stdc++.h> using namespace std; int N, K, A[1 << 11], dp[2][1 << 11]; bool pos(int g) { if (g < 0) return false; memset(dp, 0, sizeof dp); for (int i = (1); i <= (N); i++) for (int j = (0); j <= (N - i); j++) if (i + j < N && abs(A[i + j] - A[i - 1]) > (long long)g * (j + 1)) dp[i & 1][j] = 1 + dp[i - 1 & 1][j + 1]; else dp[i & 1][j] = min(1 + dp[i - 1 & 1][j + 1], dp[i - 1 & 1][0]); return dp[N & 1][0] <= K; } int main() { ios_base::sync_with_stdio(false); cin >> N >> K; for (int i = 0; i < N; i++) cin >> A[i]; if (N <= 1) { cout << "0\n"; return 0; } int ans = 2e9; for (int b = 1 << 30; b > 0; b /= 2) if (pos(ans - b)) ans -= b; cout << ans << '\n'; return 0; }
4
#include<bits/stdc++.h> #define fi first #define se second #define pb push_back #define SZ(x) ((int)x.size()) #define L(i,u) for (register int i=head[u]; i; i=nxt[i]) #define rep(i,a,b) for (register int i=(a); i<=(b); i++) #define per(i,a,b) for (register int i=(a); i>=(b); i--) using namespace std; typedef long long ll; typedef unsigned int ui; typedef pair<int,int> Pii; typedef vector<int> Vi; template<class T> inline void read(T &x){ x=0; char c=getchar(); int f=1; while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();} while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f; } template<class T> inline void umin(T &x, T y){x=x<y?x:y;} template<class T> inline void umax(T &x, T y){x=x>y?x:y;} inline ui R() { static ui seed=416; return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13; } const int N = 2300; int n,m,a,b;char s[N][N]; void A(int x, int y){ if(s[x][y]=='.'&&s[x][y+1]=='.'&&a){ a--;s[x][y]='<';s[x][y+1]='>'; } } void B(int x, int y){ if(s[x][y]=='.'&&s[x+1][y]=='.'&&b){ b--;s[x][y]='^';s[x+1][y]='v'; } } int main() { read(n);read(m);read(a);read(b); rep(i,1,n)rep(j,1,m)s[i][j]='.'; if((n&1)&&(m&1)){ if(n==1){for(int j=1;j+1<=m;j+=2)A(1,j);} else if(m==1){for(int i=1;i+1<=n;i+=2)B(i,1);} else{ for(int i=2;i+1<=m;i+=2)A(n,i); for(int i=1;i+1<=n;i+=2)B(i,m); if(b&1)B(n-1,1),A(n-2,1); for(int i=1;i+1<=n;i+=2)for(int j=1;j+1<=m;j+=2) if(a)A(i,j),A(i+1,j);else B(i,j),B(i,j+1); } } else{ if(n&1)for(int j=1;j+1<=m;j+=2)A(n,j); if(m&1)for(int j=1;j+1<=n;j+=2)B(j,m); for(int i=1;i+1<=n;i+=2)for(int j=1;j+1<=m;j+=2) if(a)A(i,j),A(i+1,j);else B(i,j),B(i,j+1); } if(a||b)puts("NO"); else{ puts("YES");rep(i,1,n){rep(j,1,m)printf("%c",s[i][j]);puts("");} } return 0; }
0
#include <cstdio> using namespace std; const int MOD = 1000000007; int main() { int n, m; scanf("%d%d", &n, &m); long long x[100000], y[100000]; long long xl = 0, yl = 0; for(int i=0;i<n;i++) { scanf("%lld", x+i); if (i!=0) { xl += (x[i] - x[i-1]) * (n-i) * (i); xl %= MOD; } } for(int i=0;i<m;i++) { scanf("%lld", y+i); if (i!=0) { yl += (y[i] - y[i-1]) * (m-i) * (i); yl %= MOD; } } long long res = (xl * yl) % MOD; printf("%lld\n", res); return 0; }
0
#include <bits/stdc++.h> using namespace std; #define MAXN 300010 int n, a[MAXN]; int ans[2]; int f[1000010], p[1000010]; vector<int> adj; void prime(){ for(int i = 2; i <= 1000000; ++i){ if(!f[i]) p[++p[0]] = i, f[i] = i; for(int j = 1; j <= p[0] && 1ll * p[j] * i <= 1000000; ++j){ f[p[j] * i] = p[j]; if(i % p[j] == 0) break; } } } void read(){ scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", a + i); } void work(){ adj.clear(); for(int i = 1; i <= n; ++i){ int num = 1, pre = -1, cnt = 0; for(int j = a[i]; ; j /= f[j]){ if(f[j] != pre){ if(cnt & 1) num *= pre; pre = f[j]; cnt = 0; } if(j == 1) break; ++cnt; } adj.push_back(num); } sort(adj.begin(), adj.end()); int pre = -1, cnt = 0; ans[0] = 0, ans[1] = 0; for(auto &it: adj){ if(it != pre){ if(cnt % 2 == 0 || pre == 1) ans[1] += cnt; pre = it, cnt = 0; } ++cnt; ans[0] = max(ans[0], cnt); } if(cnt % 2 == 0 || pre == 1) ans[1] += cnt; ans[1] = max(ans[1], ans[0]); int q; long long w; for(scanf("%d", &q); q; --q){ scanf("%lld", &w); printf("%d\n", ans[min(w, 1ll)]); } } int main() { prime(); int T; for(scanf("%d", &T); T; --T){ read(); work(); } return 0; }
2
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 99999999999999999 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define NUM 55 int length; char S[NUM],T[NUM]; void func(){ scanf("%s %s",S,T); for(length = 0; S[length] != '\0'; length++); int diff_loc = -1; for(int i = 0; i < length; i++){ if(S[i] != T[i]){ diff_loc = i; break; } } if(diff_loc == -1){ printf("0\n"); return; } int R1_S,R1_T; for(R1_S = length-1; R1_S >= 0 && S[R1_S] == '0'; R1_S--); for(R1_T = length-1; R1_T >= 0 && T[R1_T] == '0'; R1_T--); if(R1_S < diff_loc){ printf("%d\n",R1_T-R1_S); return; } if(R1_T < diff_loc){ printf("%d\n",R1_S-R1_T); return; } if(R1_S == diff_loc){ printf("%d\n",R1_T-R1_S); return; } if(R1_T == diff_loc){ printf("%d\n",R1_S-R1_T); return; } printf("%d\n",(R1_S-diff_loc)+R1_T-diff_loc); } int main(){ int num_query; scanf("%d",&num_query); for(int loop = 0; loop < num_query; loop++){ func(); } return 0; }
0
#include <bits/stdc++.h> using namespace std; int64_t N = 1e9 + 7; int64_t M = 9223372036854775807; int GCD(int A, int B) { if (B == 0) return A; else return GCD(B, A % B); } bool isPrime(long long n) { if (n <= 1) { return false; } if (n <= 3) { return true; } if (n % 2 == 0 || n % 3 == 0) { return false; } for (long long i = 5; i * i <= n; i = i + 6) { if (n % i == 0 || n % (i + 2) == 0) { return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long TTC; cin >> TTC; while (TTC--) { long long n; cin >> n; long long ans = 0; long long a[n], b[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; ans = max(ans, a[i] - i - 1); } cout << ans << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<int> prime_sieve(int n) { vector<bool> a(n + 1, 1); for (int i = 2; i * i <= n; i++) { if (a[i]) { for (int j = i * i; j <= n; j += i) a[j] = 0; } } vector<int> res; for (int i = 2; i <= n; i++) { if (a[i]) res.push_back(i); } return res; } const vector<int> primes = prime_sieve(50000); map<int, int> factor(int n) { map<int, int> f; for (int pi = 0, p = 0; pi < primes.size() && primes[pi] * primes[pi] <= n; pi++) { p = primes[pi]; while (n % p == 0) { n /= p; f[p]++; } } if (n != 1) f[n] = 1; return f; } vector<pair<int, int>> s_factor(int n, int m, int k) { map<int, int> f = factor(n); f[2]++; for (pair<int, int> p : factor(m)) f[p.first] += p.second; for (pair<int, int> p : factor(k)) f[p.first] -= p.second; vector<pair<int, int>> res; for (pair<int, int> p : f) res.push_back(p); return res; } vector<int> func(int n, int m, int k) { vector<pair<int, int>> sf = s_factor(n, m, k); vector<vector<int>> pw(sf.size()); for (int i = 0; i < sf.size(); i++) { pw[i].push_back(1); for (int j = 0; j < sf[i].second; i++) pw[i].push_back(pw[i][j] * sf[i].first); } vector<int> divs; int cd = 1; for (int i = 0; i < sf.size(); i++) cd *= sf[i].second + 1; for (int i = 0; i < cd; i++) { ; } return {0}; } int main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); long long n, m, k; cin >> n >> m >> k; if ((2 * n * m) % k != 0) { cout << "NO\n"; return 0; } vector<int> divs; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { divs.push_back(i); divs.push_back(n / i); } } for (int i = 1; i * i <= m && i <= n; i++) { if (m % i == 0) { divs.push_back(i); if (m / i <= n) divs.push_back(m / i); } } sort(divs.begin(), divs.end()); long long s = 2 * (long long)n * (long long)m / (long long)k; long long a = 1; for (int i = divs.size() - 1; i >= 0; --i) { if (s % divs[i] == 0) { a = divs[i]; break; } } if (2 * a <= n && s % (2 * a) == 0) a *= 2; if (s / a <= m) { cout << "YES\n"; cout << 0 << ' ' << 0 << '\n'; cout << a << ' ' << 0 << '\n'; cout << 0 << ' ' << s / a << '\n'; } else cout << "NO\n"; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10, mod = 1e9 + 7; long long n, k, q; long long dp[N][2]; vector<pair<long long, long long> > adj[N]; void dfs(int v, int par = -1) { dp[v][0] = dp[v][1] = 0; long long sum = 0; vector<long long> c; for (auto x : adj[v]) { long long u = x.first, w = x.second; if (u != par) { dfs(u, v); sum += dp[u][1]; c.push_back(w - dp[u][1] + dp[u][0]); } } sort(c.begin(), c.end(), greater<long long>()); dp[v][0] = sum; long long p = 0; for (long long i = 0; i < min((long long)c.size(), k - 1); i++) { p += c[i]; dp[v][0] = max(dp[v][0], p + sum); } if (c.size() >= k) p += c[k - 1]; dp[v][1] = max(dp[v][1], max(p + sum, dp[v][0])); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> q; while (q--) { cin >> n >> k; for (int i = 1; i < n; i++) { long long v, u, w; cin >> v >> u >> w; adj[v].push_back({u, w}); adj[u].push_back({v, w}); } dfs(1); cout << dp[1][1] << "\n"; for (int i = 0; i <= n; i++) adj[i].clear(); } }
3
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<map> using namespace std; #define int long long #define inf 3000000000000 typedef pair<int, int>P; int dp[160][10][80]; vector<P>s[160];//P(??????,???????????????) void init(int m) { for (int i = 0; i < 160; i++) { s[i].clear(); for (int j = 0; j < 10; j++) { for (int k = 0; k < 80; k++) { if (!i&&k==m)dp[i][j][k]=0; else if (i == 1 && k == m - 1)dp[i][j][k] = 0; else dp[i][j][k] = inf; } } } return; } signed main() { int n, m; while (cin >> n >> m) { if (!n && !m)break; init(m); for (int i = 0; i < n; i++) { int a; cin >> a; for (int j = 0; j < a; j++) { int b, c; cin >> b >> c; s[i].push_back(P(b, c)); } } for (int i = 1; i < n; i++) {//?¬????????????? for (int j = 0; j < s[i].size(); j++) {//?????????????????? for (int k = m; k >= 0; k--) {//???????????§?????£?????? for (int l = 0; l < s[i - 1].size(); l++) { int dang = (s[i-1][l].second+s[i][j].second)*abs(s[i][j].first-s[i-1][l].first); dp[i][j][k] = min(dp[i][j][k], dp[i - 1][l][k] + dang); } if (i > 1) { for (int l = 0; l < s[i - 2].size(); l++) { int dang = (s[i - 2][l].second + s[i][j].second)*abs(s[i][j].first - s[i - 2][l].first); dp[i][j][k] = min(dp[i][j][k], dp[i - 2][l][k + 1] + dang); } } } } } int ans = inf; for (int i = 0; i < 10; i++) { for (int j = 0; j < 80; j++) { ans = min(ans, dp[n - 1][i][j]); } } for (int i = 0; i < 10; i++) { for (int j = 1; j < 80; j++) { ans = min(ans, dp[n - 2][i][j]); } } cout << ans << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { int a[100005], dp[100005], b[100005]; int n, ans, maxx; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[a[i]] = i; } memset(dp, 0, sizeof(b)); b[0] = 0; ans = 1; for (int i = 1; i <= n; i++) { if (b[i - 1] < b[i]) dp[i] = dp[i - 1] + 1; else dp[i] = 1; ans = max(ans, dp[i]); } cout << n - ans << endl; }
1
#include <bits/stdc++.h> using namespace std; void solve(long long n, long long d) { long long i; if (d <= n) { cout << "YES" << endl; return; } for (i = 1; i <= n; i++) { long long x = i + ceil(1.0 * d / (i + 1)); if (x <= n) { cout << "YES" << endl; return; } } cout << "NO" << endl; return; } int main() { int t; cin >> t; while (t--) { long long n, d; cin >> n >> d; solve(n, d); } }
1
#include <bits/stdc++.h> using namespace std; int t, n, mp[21][21]; char a[100010], b[100010]; int main() { cin >> t; while (t--) { cin >> n; scanf("%s%s", a + 1, b + 1); int flg = 0; memset(mp, 0, sizeof(mp)); for (int i = 1; i <= n; i++) { if (a[i] == b[i]) { continue; } mp[a[i] - 'a'][b[i] - 'a']++; if (a[i] > b[i]) { flg = 1; cout << "-1\n"; break; } } if (flg) { continue; } int ans = 0; for (int i = 1; i < 20; i++) { for (int j = 0; j < i; j++) { if (mp[j][i] > 0) { ans++; for (int k = i + 1; k < 20; k++) { mp[i][k] += mp[j][k]; mp[j][k] = 0; } mp[j][i] = 0; } } } cout << ans << "\n"; } }
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a[2] = {0}; for (int i = 0; i < n; i++) { a[s[i] - '0']++; } cout << n - min(a[0], a[1]) * 2 << endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); } template <class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); } template <class T> inline bool read(T &x) { int c = getchar(); int sgn = 1; while (~c && c < '0' || c > '9') { if (c == '-') sgn = -1; c = getchar(); } for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sgn; return ~c; } const int INF = 2000009; const int MX = 100005; const double EPS = 1e-9; const int MOD = 1000000007; vector<int> g[20]; int dp[1 << 14], dp2[1 << 14][14][14][14]; int n, m, allmask; int rec(int mask); void prec(int mask, int val); int rec2(int mask, int pre, int x, int y) { if (x == y) { if (pre != x) return rec(mask); } int &ret = dp2[mask][pre][x][y]; if (ret != -1) return ret; ret = INF; for (int v : g[x]) if (v != pre && (!(mask & (1 << v)) || v == y)) { ret = min(ret, 1 + rec2(mask | (1 << v), x, v, y)); } return ret; } int rec(int mask) { if (mask == allmask) { return 0; } if (dp[mask] != -1) return dp[mask]; dp[mask] = INF; for (int i = 0; i < n; i++) if ((mask & (1 << i))) { for (int j = 0; j <= i; j++) if ((mask & (1 << j))) { dp[mask] = min(dp[mask], rec2(mask, i, i, j)); } } return dp[mask]; } void prec2(int mask, int pre, int x, int y, int val) { if (x == y) { if (x != pre) { prec(mask, val); return; } } for (int v : g[x]) if (v != pre && (!(mask & (1 << v)) || v == y)) { if (1 + rec2(mask | (1 << v), x, v, y) == val) { printf("%d %d\n", x + 1, v + 1); prec2(mask | (1 << v), x, v, y, val - 1); return; } } } void prec(int mask, int val) { if (mask == allmask) return; for (int i = 0; i < n; i++) if ((mask & (1 << i))) { for (int j = 0; j <= i; j++) if ((mask & (1 << j))) { if (rec2(mask, i, i, j) == val) { prec2(mask, i, i, j, val); return; } } } } int adj[20][20]; int main() { n = ({ int a; read(a); a; }), m = ({ int a; read(a); a; }); allmask = (1 << n) - 1; while (m--) { int u = ({ int a; read(a); a; }) - 1, v = ({ int a; read(a); a; }) - 1; g[u].push_back(v); g[v].push_back(u); adj[u][v] = adj[v][u] = 1; } memset(dp, -1, sizeof(dp)); memset(dp2, -1, sizeof(dp2)); int ans = rec(1); printf("%d\n", ans); prec(1, ans); return 0; }
6
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<tuple> #include<cassert> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define Per(i,sta,n) for(int i=n-1;i>=sta;i--) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,1,-1 }; 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 S, S(*op)(S, S), S(*e)(), class F, S(*mapping)(F, S), F(*composition)(F, F), F(*id)()> struct SegmentTree { public: SegmentTree() : SegmentTree(0) {} SegmentTree(int n) : SegmentTree(std::vector<S>(n, e())) {} SegmentTree(const std::vector<S>& v) : _n(int(v.size())) { log = ceil_pow2(_n); size = 1 << log; d = std::vector<S>(2 * size, e()); lz = std::vector<F>(size, id()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) { update_(i); } } void set(int p, S x) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); d[p] = x; for (int i = 1; i <= log; i++) update_(p >> i); } S get(int p) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); return d[p]; } S query(int l, int r) { assert(0 <= l && l <= r && r <= _n); if (l == r) return e(); l += size; r += size; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push(r >> i); } S sml = e(), smr = e(); while (l < r) { if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_query() { return d[1]; } void update(int p, F f) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); d[p] = mapping(f, d[p]); for (int i = 1; i <= log; i++) update_(p >> i); } void update(int l, int r, F f) { assert(0 <= l && l <= r && r <= _n); if (l == r) return; l += size; r += size; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } { int l2 = l, r2 = r; while (l < r) { if (l & 1) all_apply(l++, f); if (r & 1) all_apply(--r, f); l >>= 1; r >>= 1; } l = l2; r = r2; } for (int i = 1; i <= log; i++) { if (((l >> i) << i) != l) update_(l >> i); if (((r >> i) << i) != r) update_((r - 1) >> i); } } template <bool (*g)(S)> int max_right(int l) { return max_right(l, [](S x) { return g(x); }); } template <class G> int max_right(int l, G g) { assert(0 <= l && l <= _n); assert(g(e())); if (l == _n) return _n; l += size; for (int i = log; i >= 1; i--) push(l >> i); S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!g(op(sm, d[l]))) { while (l < size) { push(l); l = (2 * l); if (g(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template <bool (*g)(S)> int min_left(int r) { return min_left(r, [](S x) { return g(x); }); } template <class G> int min_left(int r, G g) { assert(0 <= r && r <= _n); assert(g(e())); if (r == 0) return 0; r += size; for (int i = log; i >= 1; i--) push((r - 1) >> i); S sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!g(op(d[r], sm))) { while (r < size) { push(r); r = (2 * r + 1); if (g(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } private: int _n, size, log; std::vector<S> d; std::vector<F> lz; void update_(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } void all_apply(int k, F f) { d[k] = mapping(f, d[k]); if (k < size) lz[k] = composition(f, lz[k]); } void push(int k) { all_apply(2 * k, lz[k]); all_apply(2 * k + 1, lz[k]); lz[k] = id(); } int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } }; struct T { int num0 = 0, num1 = 0; ll inv = 0; T() {} T(int n0, int n1, ll in) :num0(n0), num1(n1), inv(in) {} }; T f(T a, T b) { return T(a.num0 + b.num0, a.num1 + b.num1, a.inv + b.inv + (ll)a.num1 * (ll)b.num0); } T e() { return T(0, 0, 0); }; T g(int p, T a) { if (p == 0) return a; return T(a.num1, a.num0, a.num0 * a.num1 - a.inv); } int h(int a, int b) { return (a + b) % 2; } int id() { return 0; }; int n, q; vector<T> a; void solve() { cin >> n >> q; a.resize(n); rep(i, n) { int p; cin >> p; if (p == 0)a[i].num0 = 1; else a[i].num1 = 1; } SegmentTree<T, f, e, int, g, h, id> seg(a); rep(i, q) { int t; cin >> t; if (t == 1) { int l, r; cin >> l >> r; l--; seg.update(l, r, 1); } else { int l, r; cin >> l >> r; l--; cout << seg.query(l, r).inv << endl; } // rep(i,n){ // T a=seg.get(i); // if(a.num0==1) cout << 0 << " "; // else cout << 1 << " "; // } // cout << "" << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; int p = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) p += v[i] > v[j]; cout << p % 2 + p / 2 * 4 << endl; }
4
#include <bits/stdc++.h> using namespace std; const long long N = 1005; int ar[N][N], row[N], col[N], n, m, k, a, b; char t; void solve() { cin >> n >> m >> k; for (int i = 1; i <= n; i++) { row[i] = i; for (int j = 1; j <= m; j++) { col[j] = j; cin >> ar[i][j]; } } while (k--) { cin >> t; cin >> a >> b; if (t == 'c') { swap(col[a], col[b]); } else if (t == 'r') { swap(row[a], row[b]); } else { cout << ar[row[a]][col[b]] << "\n"; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int test = 1; while (test--) { solve(); } return 0; }
2
#include<bits/stdc++.h> using namespace std; const int N=1e6; int A[N+1]; int GCD(int a,int b){ return b==0?a:GCD(b,a%b); } int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif int n,tmp,gcd=0; cin>>n; for(int i=0;i<n;++i){ cin>>tmp; ++A[tmp]; gcd=GCD(tmp,gcd); } //pairwise for(int i=2;i<=N;++i){ int flag=0; for(int j=i;j<=N;j+=i){ if(j<=N && A[j]>=1) flag+=A[j]; if(flag>=2) goto setwise; } } cout<<"pairwise coprime"<<endl; return 0; setwise: if(gcd==1) cout<<"setwise coprime"<<endl; else cout<<"not coprime"<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; string str; stack<string> chat; map<string, int> check; cin >> n; while (n--) { cin >> str; chat.push(str); check[str] = 1; } while (!chat.empty()) { if (check[chat.top()] == 1) cout << chat.top() << "\n"; check[chat.top()] = 0; chat.pop(); } return 0; }
2
#include <bits/stdc++.h> using namespace std; double x[10000], y[10000], q[100000]; int r[100000]; int main() { int i, j, n, mj, s = 0; double m, m1, m2, m3, c = 0; cin >> n >> s; for (i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i]; for (i = 0; i < n; i++) { q[i] = sqrt((x[i] - 0) * (x[i] - 0) + (y[i] - 0) * (y[i] - 0)); } for (i = 0; i < n - 1; i++) { for (m = 1e9, j = i; j < n; j++) if (q[j] < m) m = q[j], mj = j, m1 = x[j], m2 = y[j], m3 = r[j]; q[mj] = q[i], q[i] = m, x[mj] = x[i], y[mj] = y[i], r[mj] = r[i], x[i] = m1, y[i] = m2, r[i] = m3; } i = 0; while (1) { s += r[i]; c = q[i]; i++; if (s >= 1000000) { cout << fixed << setprecision(7); cout << c << endl; return 0; } if (i >= n) break; } cout << -1 << endl; return 0; }
2
#include<cstdio> #include<algorithm> #include<cstring> #include<queue> using namespace std; const int N=2333; struct edge{int to,nxt,w,cost;}a[N<<5]; int n,S,T,hd[N],cnt=1,vis[N],pe[N];long long dis[N],ans; queue<int>Q; void link(int u,int v,int w,int cost){ a[++cnt]=(edge){v,hd[u],w,cost};hd[u]=cnt; a[++cnt]=(edge){u,hd[v],0,-cost};hd[v]=cnt; } bool spfa(){ memset(dis,-63,sizeof(dis)); dis[S]=0;Q.push(S); while(!Q.empty()){ int u=Q.front();Q.pop(); for(int i=hd[u];i;i=a[i].nxt){ int v=a[i].to; if(a[i].w&&dis[v]<dis[u]+a[i].cost){ dis[v]=dis[u]+a[i].cost;pe[v]=i; if(!vis[v])vis[v]=1,Q.push(v); } } vis[u]=0; } if(dis[T]==dis[0])return false; int sum=1<<30; for(int i=T;i!=S;i=a[pe[i]^1].to)sum=min(sum,a[pe[i]].w); ans+=dis[T]*sum; for(int i=T;i!=S;i=a[pe[i]^1].to)a[pe[i]].w-=sum,a[pe[i]^1].w+=sum; return true; } int main(){ scanf("%d",&n);S=n+n+1;T=S+1; for(int i=1,x,y,z;i<=n;++i){ scanf("%d%d%d",&x,&y,&z); link(S,i,z,0); link(i,n+n+3,z,x+y); link(i,n+n+4,z,x-y); link(i,n+n+5,z,-x+y); link(i,n+n+6,z,-x-y); } for(int i=1,x,y,z;i<=n;++i){ scanf("%d%d%d",&x,&y,&z); link(i+n,T,z,0); link(n+n+3,i+n,z,-x-y); link(n+n+4,i+n,z,-x+y); link(n+n+5,i+n,z,x-y); link(n+n+6,i+n,z,x+y); } while(spfa()); printf("%lld\n",ans); return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (n % 2 == 1) { cout << 7; n -= 3; } for (int i = 0; i < (n / 2); i++) cout << 1; cout << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; struct Pnt { long double x; long double y; Pnt(long double x, long double y) : x(x), y(y) {} Pnt() : x(0), y(0) {} long double operator%(Pnt p) const { return x * p.y - y * p.x; } long double len2() const { return x * x + y * y; } long double len() const { return sqrt(len2()); } Pnt operator-(Pnt p) const { return Pnt(x - p.x, y - p.y); } }; int main() { int n; cin >> n; vector<Pnt> p(n); for (int i = 0; i < n; ++i) { cin >> p[i].x >> p[i].y; } long double D = 4 * 1e18 + 500; for (int i = 0; i < n; ++i) { Pnt cur = p[i]; Pnt prev = p[(n + i - 1) % n]; Pnt next = p[(i + 1) % n]; long double d = abs(((cur - prev) % (next - prev)) / (next - prev).len()); D = min(D, d / 2); } cout.precision(10); cout << fixed << D << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; const long long INF = numeric_limits<long long>::max(); const long long nax = (long long)(100001); const long long mod = 1e9 + 7; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, k; cin >> n >> k; cout << ((n - k < 0 || (n - k) & 1LL || ((n - k) >> 1) & k) ? 0 : (1LL << __builtin_popcountll(k)) - 2 * (n == k)); return 0; }
1
#include <bits/stdc++.h> using namespace std; inline int ma(int a, int b) { return ((a - b > 0) ? a : b); } inline int mi(int a, int b) { return ((a - b > 0) ? b : a); } template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } string s[502]; int cost[502][502], p = 0; int ans[502][502]; inline void solve(string& s) { int ta = s.size(); int dp[502]; s[0] == '0' ? dp[0] = 0 : dp[0] = 1; for (int(i) = (1); (i) < (ta); (i)++) { if (s[i] == '1') dp[i] = dp[i - 1] + 1; else dp[i] = dp[i - 1]; } int mx = dp[ta - 1]; vector<int> v[502]; for (int(i) = (0); (i) < (ta); (i)++) { for (int(j) = (i); (j) < (ta); (j)++) { int val = j - i + 1, cur; if (i == 0) cur = dp[j]; else cur = dp[j] - dp[i - 1]; v[mx - cur].push_back(val); } } v[mx].push_back(0); for (int(i) = (0); (i) < (mx + 1); (i)++) sort((v[i]).begin(), (v[i]).end()); for (int(i) = (0); (i) < (mx + 1); (i)++) { for (auto xd : v[i]) { cost[p][i] = xd; break; } } p++; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; int n, m, k; cin >> n >> m >> k; for (int(i) = (0); (i) < (n); (i)++) cin >> s[i]; for (int(i) = (0); (i) < (n); (i)++) solve(s[i]); ans[0][0] = 0; for (int(i) = (0); (i) < (k + 1); (i)++) ans[i][0] = 0; int val; for (int(i) = (1); (i) < (n + 1); (i)++) { for (int(k1) = (0); (k1) < (k + 1); (k1)++) { val = 1065435634; for (int(j) = (0); (j) < (k1 + 1); (j)++) { val = mi(val, ans[k1 - j][i - 1] + cost[i - 1][j]); } ans[k1][i] = val; } } cout << ans[k][n] << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; double probability_mass_function(vector<double> probabilities, long long k) { const double pi = acos(-1); const complex<double> I(0, 1); long long n = probabilities.size(); complex<double> C = exp(2.0 * I * pi / (n + 1.0)); complex<double> answer(0, 0); for (long long l = 0; l <= n; l++) { complex<double> product(1, 0); complex<double> factor = pow(C, l) - 1.0; for (auto p : probabilities) product += product * factor * p; answer += pow(C, -l * k) * product; } return (answer / (n + 1.0)).real(); } double probability_of_success(vector<long long> distances_squared, long long K, double R_squared) { long long automatic = count_if(distances_squared.begin(), distances_squared.end(), [&](long long d) { return d < R_squared; }); if (automatic >= K) return 1.0; K = K - automatic; vector<double> probabilities; for (auto d : distances_squared) { if (d >= R_squared) probabilities.push_back(exp(1 - (d / R_squared))); } double answer = 0; long long max_successes = probabilities.size(); for (long long k = K; k <= max_successes; k++) { answer += probability_mass_function(probabilities, k); } return answer; } int main(void) { ios::sync_with_stdio(false); cout << setprecision(10); long long N; long long K, epsilon; long long X0, Y0; cin >> N; cin >> K >> epsilon; double requested_probability = 1.0 - (epsilon / 1000.0); cin >> X0 >> Y0; vector<long long> distances_squared; for (int i = 0; i < N; i++) { long long x, y; cin >> x >> y; long long distance_squared = (X0 - x) * (X0 - x) + (Y0 - y) * (Y0 - y); distances_squared.push_back(distance_squared); } if (probability_of_success(distances_squared, K, 1e-20) >= requested_probability) { cout << 0.0 << endl; return 0; } double min_R_squared = 0; double max_R_squared = *max_element(distances_squared.begin(), distances_squared.end()); while ((sqrt(max_R_squared) - sqrt(min_R_squared)) > 1e-8) { double avg_R_squared = (min_R_squared + max_R_squared) / 2.0; double p = probability_of_success(distances_squared, K, avg_R_squared); if (p < requested_probability) min_R_squared = avg_R_squared; else max_R_squared = avg_R_squared; } cout << sqrt(min_R_squared) << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; int arr[10000]; int main() { int n, m, k, i, c = 0; cin >> n >> m >> k; for (i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] == 1 && m > 0) m--; else if (arr[i] == 1) c++; if (arr[i] == 2 && k > 0) k--; else if (arr[i] == 2 && m > 0) m--; else if (arr[i] == 2) c++; } cout << c << endl; }
1
#include <bits/stdc++.h> using namespace std; inline long long Read() { long long res = 0, f = 1; char c; while (c = getchar(), c < 48 || c > 57) if (c == '-') f = 0; do res = (res << 3) + (res << 1) + (c ^ 48); while (c = getchar(), c >= 48 && c <= 57); return f ? res : -res; } template <class T> inline bool Min(T &a, T const &b) { return a > b ? a = b, 1 : 0; } template <class T> inline bool Max(T &a, T const &b) { return a < b ? a = b, 1 : 0; } const long long N = 5e5 + 5, M = 1e6 + 5, mod = 1e9 + 7; bool MOP1; long long n, cnt, A[N], B[N], C[N], d[N]; inline bool Insert(long long x) { for (register long long i = (60), i_end_ = (0); i >= i_end_; --i) if (x >> i & 1) { if (d[i]) x ^= d[i]; else { d[i] = x; return true; } } return false; } bool MOP2; inline void _main(void) { n = Read(); long long Sum = 0; for (register long long i = (1), i_end_ = (n); i <= i_end_; ++i) { A[i] = Read(), B[i] = Read(); C[i] = A[i] ^ B[i]; Sum ^= A[i]; if (Insert(C[i])) cnt++; } for (register long long i = (60), i_end_ = (0); i >= i_end_; --i) if (Sum >> i & 1) Sum ^= d[i]; if (Sum) printf("1/1"); else printf("%lld/%lld", (1ll << cnt) - 1, 1ll << cnt); } signed main() { _main(); return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<int> p[4000]; int ans[300000]; int in[4000], out[4000], vis[4000]; char s[300000][4]; int n, cnt; int js(char ch) { if (ch >= 'a' && ch <= 'z') return ch - 'a'; else if (ch >= 'A' && ch <= 'Z') return ch - 'A' + 26; else if (ch >= '0' && ch <= '9') return ch - '0' + 52; } char rejs(int d) { if (d < 26) return 'a' + d; else if (d < 52) return 'A' + d - 26; else return '0' + d - 52; } void dfs(int u) { while (vis[u] < p[u].size()) { int v = p[u][vis[u]]; vis[u]++; dfs(v); ans[cnt++] = v; } } int main() { int u, v; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s", s[i]); u = js(s[i][0]) * 62 + js(s[i][1]) + 1; v = js(s[i][1]) * 62 + js(s[i][2]) + 1; p[u].push_back(v); out[u]++; in[v]++; } int mini = 4000, flag = 0; int odd = 0; for (int i = 1; i <= 62 * 62; i++) { if ((out[i] - in[i] > 1) || (out[i] - in[i] < -1)) { flag = 1; break; } if ((out[i] - in[i] == 1) || (out[i] - in[i] == -1)) { odd++; if (out[i] - in[i] == 1) mini = i; } } if (odd != 0 && odd != 2) flag = 1; if (flag) printf("NO\n"); else { cnt = 0; if (mini == 4000) mini = js(s[0][0]) * 62 + js(s[0][1]) + 1; dfs(mini); if (cnt == n) { printf("YES\n"); printf("%c%c", rejs((mini - 1) / 62), rejs((mini - 1) % 62)); for (int i = n - 1; i >= 0; i--) putchar(rejs((ans[i] - 1) % 62)); puts(""); } else printf("NO\n"); } return 0; }
4
#include <bits/stdc++.h> using namespace std; void require(bool cond, const string& message = "Runtime error") { if (!cond) { cerr << message << endl; assert(false); } } string text; int L, R; struct Restriction { char c; int l, r; int lp, rp; int lcnt, rcnt; }; ostream& operator<<(ostream& os, const Restriction& r) { os << "Restriction(" << r.c << "," << r.l << "," << r.r; os << ";" << r.lp << "," << r.rp << ";" << r.lcnt << "," << r.rcnt; os << ")" << endl; return os; } template <class T> void print(ostream& os, const vector<T>& a) { for (int i = 0; i < int(a.size()); ++i) { if (i > 0) os << " "; os << a[i]; } os << endl; } vector<Restriction> r; vector<int> x; void readData() { cin >> text; int k; cin >> k >> L >> R; r.resize(k); for (int i = 0; i < int(k); ++i) { cin >> r[i].c >> r[i].l >> r[i].r; r[i].rp = r[i].lp = 0; r[i].lcnt = r[i].rcnt = 0; } } bool good(const string& s) { int c = 0; for (int i = 0; i < int(r.size()); ++i) { int t = 0; for (int j = 0; j < int(s.size()); ++j) { if (s[j] == r[i].c) { ++t; } } if (t >= r[i].l && t <= r[i].r) { ++c; } } return L <= c && c <= R; } int naive() { int ret = 0; for (int j = 0; j < int(text.length() + 1); ++j) { for (int i = 0; i < int(j); ++i) { string s = text.substr(i, j - i); if (good(s)) { ++ret; } } } return ret; } bool inside(int x, int l, int r) { return l <= x && x <= r; } void solve() { int n = x.size(); int satR = 0; x.resize(text.length()); long long ans = 0; for (int prefix = 0; prefix < int(x.size()); ++prefix) { for (int i = 0; i < int(r.size()); ++i) { Restriction& rr = r[i]; if (r[i].c == text[prefix]) { ++rr.lcnt; ++rr.rcnt; } while (rr.lcnt > rr.r && rr.lp <= prefix) { if (!inside(x[rr.lp], L, R) && inside(x[rr.lp] - 1, L, R)) { ++satR; } if (inside(x[rr.lp], L, R) && !inside(x[rr.lp] - 1, L, R)) { --satR; } --x[rr.lp]; if (text[rr.lp] == rr.c) { --rr.lcnt; } ++rr.lp; } while (rr.rcnt >= rr.l && rr.rp <= prefix) { if (!inside(x[rr.rp], L, R) && inside(x[rr.rp] + 1, L, R)) { ++satR; } if (inside(x[rr.rp], L, R) && !inside(x[rr.rp] + 1, L, R)) { --satR; } ++x[rr.rp]; if (text[rr.rp] == rr.c) { --rr.rcnt; } ++rr.rp; } } if (L == 0) { ++satR; } ans += satR; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); readData(); solve(); return 0; }
5
#include <bits/stdc++.h> using namespace std; int const N = 2200100; double const PI = acos(-1); void cmul(double &x, double &y, double cx, double cy) { double newx = x * cx - y * cy; y = x * cy + y * cx; x = newx; } double wx[N], wy[N]; int bitrev[N]; void fft(double *x, double *y, int n) { for (int i = 0; i < n; ++i) { if (i < bitrev[i]) { swap(x[i], x[bitrev[i]]); swap(y[i], y[bitrev[i]]); } } for (int len = 2; len <= n; len *= 2) { int s = n / len; for (int i = 0; i < n; i += len) { for (int q = 0, j = i, k = i + len / 2; k < i + len; q += s, ++j, ++k) { double cx = x[k], cy = y[k]; cmul(cx, cy, wx[q], wy[q]); x[k] = x[j] - cx; y[k] = y[j] - cy; x[j] += cx; y[j] += cy; } } } } int const size = 8800800; char in[size]; int ptr; int next_int() { while (in[ptr] < 33) ++ptr; int ret = 0; while (in[ptr] > 32) ret = 10 * ret + in[ptr++] - '0'; return ret; } int main() { fread(in, 1, size, stdin); ptr = 0; int n = next_int(); int m = next_int(); static int used[N]; static double px[N], py[N]; for (int i = 0; i < n; ++i) { int x = next_int(); px[x] = 1; used[x] = 1; } int size = 1, logs = 0; while (size / 2 < m + 1) { size *= 2; ++logs; } for (int i = 0; i < size; ++i) { double a = 2 * PI * i / size; wx[i] = cos(a); wy[i] = sin(a); } bitrev[0] = 0; for (int i = 1; i < size; ++i) { bitrev[i] = bitrev[i >> 1] >> 1 | (i & 1) << (logs - 1); } fft(px, py, size); for (int i = 0; i < size; ++i) { cmul(px[i], py[i], px[i], py[i]); py[i] *= -1; } fft(px, py, size); static int ans[N]; int sz = 0; for (int i = 0; i <= m; ++i) { if (px[i] > size / 2) { if (!used[i]) { cout << "NO\n"; return 0; } used[i] = false; } if (used[i]) { ans[++sz] = i; } } static char out[::size]; memcpy(out, "YES\n", 4); int ptr = 3; ans[0] = sz; for (int i = 0; i <= sz; ++i) { static char x[55]; int cur = 0; do { x[++cur] = ans[i] % 10 + '0'; ans[i] /= 10; } while (ans[i]); while (cur) out[++ptr] = x[cur--]; out[++ptr] = ' '; } out[ptr++] = '\n'; fwrite(out, 1, ptr, stdout); }
5
#include <bits/stdc++.h> using namespace std; int main(){ int N; string S; cin >> N >> S; int res = 0; vector<vector<int>> dp(N+1, vector<int>(N+1, 0)); for(int i=N-1;i>=0;i--){ for(int j=N-1;j>i;j--){ if(S[i] == S[j]){ dp[i][j] = max(dp[i][j], dp[i+1][j+1]+1); } res = max(res, min(dp[i][j], j-i)); } } cout << res << endl; }
0
#include <bits/stdc++.h> using namespace std; int n, m; char stra[200]; char strb[10]; map<char, set<int>> mapa; int main() { scanf("%d", &n); scanf("%d", &m); scanf("%s", &stra); for (int i = 0; i < n; i++) { mapa[stra[i]].insert(i); } int l, r, c1, c2; for (int i = 0; i < m; i++) { scanf("%d", &l); scanf("%d", &r); l--, r--; scanf("%s", &strb); c1 = strb[0]; scanf("%s", &strb); c2 = strb[0]; if (c1 == c2) continue; if (mapa[c1].empty()) { continue; } auto it = mapa[c1].lower_bound(l); while (it != mapa[c1].end() && *it <= r) { mapa[c2].insert(*it); auto it2 = it++; mapa[c1].erase(it2); } } for (auto &au : mapa) { for (int au2 : au.second) { stra[au2] = au.first; } } printf("%s\n", stra); }
1
#include <bits/stdc++.h> using namespace std; struct particip { string name; int region; int points; }; vector<particip> a; int n, m; bool smaller(const particip &a, const particip &b) { if (a.region == b.region) { return a.points > b.points; } return a.region < b.region; } int main() { cin >> n >> m; particip p; particip z; z.name = '0'; z.region = z.points = 0; a.push_back(z); for (int i = 1; i <= n; i++) { cin >> p.name >> p.region >> p.points; a.push_back(p); } particip fin; fin.name = "fin"; fin.region = m + 1; fin.points = 800; sort(a.begin(), a.end(), smaller); a.push_back(fin); a.push_back(fin); for (int i = 1; i < n; i++) { if (a[i - 1].region < a[i].region) { if (a[i + 1].region == a[i + 2].region && a[i + 1].points == a[i + 2].points) cout << "?" << "\n"; else cout << a[i].name << " " << a[i + 1].name << "\n"; } } return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, m, p[100010], a[100010], id[100010], Next[100010], Prev[100010]; set<pair<int, int> > s; bool cmp(int a, int b) { return p[a] < p[b]; } int calc(int x, int y) { if (x == y) return 1e9; int d = (p[y] - p[x] + m) % m; if (x > y) d = (d + a[y]) % m; if (d <= a[x]) return 1; if (a[x] <= a[y]) return 1e9; return (d - a[y] - 1) / (a[x] - a[y]) + 1; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%d", &p[i], &a[i]); p[i]--; id[i] = i; } sort(id + 1, id + 1 + n, cmp); for (int i = 1; i <= n; i++) Next[id[i]] = id[i + 1], Prev[id[i]] = id[i - 1]; Next[id[n]] = id[1l]; Prev[id[1]] = id[n]; for (int i = 1; i <= n; i++) s.insert(make_pair(calc(i, Next[i]), i)); while (1) { pair<int, int> u = *s.begin(); if (u.first == 1e9) break; int v = u.second; s.erase(s.begin()); s.erase(make_pair(calc(Next[v], Next[Next[v]]), Next[v])); if (s.size()) s.erase(make_pair(calc(Prev[v], v), Prev[v])); p[v] += u.first; p[v] %= m; a[v]--; Next[v] = Next[Next[v]]; Prev[Next[v]] = v; s.insert(make_pair(calc(Prev[v], v), Prev[v])); s.insert(make_pair(calc(v, Next[v]), v)); } printf("%d\n", s.size()); for (auto it : s) printf("%d ", it.second); return 0; }
5
#include <bits/stdc++.h> using namespace std; string s[255] = { "0\n", "1\nlea ebx, [2*eax]\n", "1\nlea ebx, [eax + 2*eax]\n", "1\nlea ebx, [4*eax]\n", "1\nlea ebx, [eax + 4*eax]\n", "2\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\n", "2\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*eax]\n", "1\nlea ebx, [8*eax]\n", "1\nlea ebx, [eax + 8*eax]\n", "2\nlea ebx, [2*eax]\nlea ecx, [ebx + 8*eax]\n", "2\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*eax]\n", "2\nlea ebx, [4*eax]\nlea ecx, [ebx + 8*eax]\n", "2\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*ebx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 4*ecx]\n", "2\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*ebx]\n", "2\nlea ebx, [2*eax]\nlea ecx, [8*ebx]\n", "2\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\n", "2\nlea ebx, [2*eax]\nlea ecx, [ebx + 8*ebx]\n", "2\nlea ebx, [eax + 8*eax]\nlea ecx, [eax + 2*ebx]\n", "2\nlea ebx, [4*eax]\nlea ecx, [ebx + 4*ebx]\n", "2\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 4*ebx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ebx + 4*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ebx + " "4*ecx]\n", "2\nlea ebx, [8*eax]\nlea ecx, [ebx + 2*ebx]\n", "2\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 8*ebx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 8*ecx]\n", "2\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*ebx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ecx + " "8*ebx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + 4*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + " "8*ebx]\n", "2\nlea ebx, [4*eax]\nlea ecx, [8*ebx]\n", "2\nlea ebx, [4*eax]\nlea ecx, [eax + 8*ebx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [4*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + 2*ecx]\n", "2\nlea ebx, [4*eax]\nlea ecx, [ebx + 8*ebx]\n", "2\nlea ebx, [eax + 8*eax]\nlea ecx, [eax + 4*ebx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*eax]\nlea edx, [ebx + 4*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 8*eax]\nlea edx, [ebx + " "4*ecx]\n", "2\nlea ebx, [8*eax]\nlea ecx, [ebx + 4*ebx]\n", "2\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 8*ebx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ebx + " "8*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ebx + 8*ecx]\n", "2\nlea ebx, [eax + 4*eax]\nlea ecx, [ebx + 8*ebx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [ebx + 1*eax]\nlea edx, [ecx + " "8*ebx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [ebx + " "4*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [8*ebx]\nlea edx, [ecx + 2*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [eax + 8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 2*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [ebx + 2*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [eax + " "4*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [ecx + " "4*ecx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ebx + 4*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [eax + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 4*eax]\nlea " "eex, [ebx + 8*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ebx + " "8*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [ecx + 4*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*ebx]\nlea edx, [eax + " "4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 4*ecx]\nlea " "eex, [ebx + 4*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + " "8*ecx]\n", "2\nlea ebx, [8*eax]\nlea ecx, [8*ebx]\n", "2\nlea ebx, [8*eax]\nlea ecx, [eax + 8*ebx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [8*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + 2*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [4*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + 4*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ebx + 4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [eax + 8*ebx]\nlea " "eex, [ecx + 4*edx]\n", "2\nlea ebx, [8*eax]\nlea ecx, [ebx + 8*ebx]\n", "2\nlea ebx, [eax + 8*eax]\nlea ecx, [eax + 8*ebx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 8*eax]\nlea edx, [ebx + " "8*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [eax + 8*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 8*eax]\nlea edx, [ebx + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 8*ebx]\nlea " "eex, [ebx + 4*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 8*ebx]\nlea " "eex, [ecx + 4*edx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [8*ebx]\nlea edx, [ecx + 4*ecx]\n", "2\nlea ebx, [eax + 8*eax]\nlea ecx, [ebx + 8*ebx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + " "2*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [ebx + 4*ebx]\nlea edx, [ebx + 4*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ecx + 8*ebx]\nlea " "eex, [ebx + 4*edx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ebx + " "2*ecx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [ebx + 2*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [eax + " "8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [ecx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [ebx + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ecx + 8*ecx]\nlea " "eex, [ebx + 2*edx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 2*ebx]\nlea edx, [ebx + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + 8*ebx]\nlea " "eex, [ecx + 4*edx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [ebx + " "2*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [8*ebx]\nlea edx, [ecx + 2*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [eax + 8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [4*eax]\nlea edx, [ecx + 8*eax]\nlea eex, " "[ebx + 8*edx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 2*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + " "4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [4*eax]\nlea edx, [ebx + 8*ecx]\nlea eex, " "[edx + 2*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ebx + " "4*ecx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [eax + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [eax + 4*ecx]\nlea " "eex, [ebx + 8*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [ebx + " "8*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [ecx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [eax + " "4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 8*ecx]\nlea " "eex, [ebx + 4*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [ebx + " "4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [8*ebx]\nlea edx, [ecx + 8*eax]\nlea eex, " "[ecx + 4*edx]\n", "3\nlea ebx, [eax + 8*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ebx + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 4*ecx]\nlea " "eex, [ebx + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 4*ecx]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 8*ecx]\nlea " "eex, [ebx + 4*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [ecx + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + 8*eax]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 2*ecx]\nlea " "eex, [edx + 4*ecx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [ebx + 2*ebx]\nlea edx, [ecx + 4*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*ebx]\nlea edx, [eax + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 4*ecx]\nlea " "eex, [ebx + 8*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*ebx]\nlea edx, [ebx + " "8*ecx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 4*ecx]\nlea " "eex, [ebx + 8*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + " "4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 4*ecx]\nlea " "eex, [edx + 8*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + " "8*eax]\nlea eex, [ecx + 8*edx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [8*ebx]\nlea edx, [8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [8*ebx]\nlea edx, [eax + 8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [8*ebx]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + 2*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [4*ebx]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + 4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [4*eax]\nlea edx, [eax + 8*ecx]\nlea eex, " "[ebx + 4*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*ebx]\nlea edx, [ecx + " "8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + 8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ebx + 8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [eax + 8*ebx]\nlea " "eex, [ecx + 8*edx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [ebx + 8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [eax + 8*ebx]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [eax + 8*ebx]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 8*ebx]\nlea " "eex, [ecx + 4*edx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [8*ebx]\nlea edx, [ecx + 8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [eax + 8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [eax + 8*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + " "2*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [ebx + 4*ecx]\n", "3\nlea ebx, [eax + 8*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [eax + " "4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 8*eax]\nlea edx, [eax + 4*ecx]\nlea " "eex, [ebx + 4*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 8*eax]\nlea edx, [eax + " "4*ecx]\nlea eex, [ebx + 4*edx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [ebx + 2*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 8*ebx]\nlea " "eex, [ebx + 8*edx]\n", "3\nlea ebx, [eax + 8*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ebx + " "2*ecx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 4*ebx]\nlea " "eex, [ebx + 8*edx]\n", "3\nlea ebx, [eax + 8*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [ebx + " "4*ecx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [ebx + 2*eax]\nlea edx, [ecx + 8*ebx]\nlea " "eex, [ecx + 4*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 8*eax]\nlea edx, [ebx + " "4*ecx]\nlea eex, [ebx + 4*edx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [8*ebx]\nlea edx, [ecx + 4*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [ebx + 4*ebx]\nlea edx, [eax + 8*ecx]\n", "3\nlea ebx, [2*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [ecx + 8*ecx]\n", "3\nlea ebx, [eax + 8*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [eax + " "2*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [ebx + 4*ebx]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [eax + 8*ecx]\nlea " "eex, [ebx + 4*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 2*eax]\nlea " "eex, [edx + 4*ecx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [ebx + 4*ebx]\nlea edx, [ebx + 4*ecx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [eax + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [4*eax]\nlea edx, [ebx + 8*ecx]\nlea eex, " "[edx + 4*edx]\n", "3\nlea ebx, [eax + 8*eax]\nlea ecx, [eax + 2*ebx]\nlea edx, [ecx + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [eax + 8*ecx]\nlea " "eex, [ecx + 2*edx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [ebx + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [eax + 4*ecx]\nlea " "eex, [ecx + 4*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + 2*ecx]\nlea " "eex, [edx + 4*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [8*ebx]\nlea edx, [ecx + 4*eax]\nlea eex, " "[ecx + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ebx + 4*ecx]\nlea " "eex, [eax + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ebx + 4*ecx]\nlea " "eex, [ebx + 8*edx]\n", "4\nlea ebx, [8*eax]\nlea ecx, [eax + 2*ebx]\nlea edx, [ecx + 8*ebx]\nlea " "eex, [ecx + 2*edx]\n", "3\nlea ebx, [4*eax]\nlea ecx, [ebx + 4*ebx]\nlea edx, [ecx + 8*ecx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [eax + " "4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ecx + 8*ecx]\nlea " "eex, [ebx + 4*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ecx + " "8*ecx]\nlea eex, [ebx + 4*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ecx + 8*ecx]\nlea " "eex, [ebx + 4*edx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [ebx + " "4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [ebx + 2*ecx]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 2*ecx]\nlea " "eex, [edx + 8*ecx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [ecx + 8*ebx]\nlea " "eex, [ecx + 4*edx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [ecx + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 8*eax]\nlea edx, [ebx + 4*ecx]\nlea " "eex, [edx + 4*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [eax + " "4*ecx]\nlea eex, [ecx + 4*edx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [8*ebx]\nlea edx, [ecx + 2*ecx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [ebx + 2*ebx]\nlea edx, [eax + 8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [8*eax]\nlea edx, [ecx + 8*ebx]\nlea eex, " "[ebx + 8*edx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 2*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [eax + 8*ecx]\nlea " "eex, [4*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [eax + 8*ecx]\nlea " "eex, [eax + 4*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [8*eax]\nlea edx, [ebx + 8*ecx]\nlea eex, " "[edx + 2*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + 2*ecx]\nlea " "eex, [edx + 4*ecx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [ebx + 2*ebx]\nlea edx, [ebx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [eax + 8*ecx]\nlea " "eex, [ebx + 8*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ebx + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [4*ecx]\nlea eex, " "[edx + 8*ecx]\n", "3\nlea ebx, [eax + 4*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + " "4*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [eax + 4*ecx]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [eax + 4*ecx]\nlea " "eex, [edx + 2*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [8*ebx]\nlea edx, [ecx + 8*eax]\nlea eex, " "[ecx + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 8*ecx]\nlea " "eex, [eax + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 8*ecx]\nlea " "eex, [ebx + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 8*ecx]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [ebx + 2*eax]\nlea edx, [ebx + 8*ecx]\nlea " "eex, [ebx + 4*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [ecx + 8*ebx]\nlea " "eex, [ecx + 4*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ebx + 4*ecx]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ebx + " "8*ecx]\nlea eex, [edx + 4*edx]\n", "3\nlea ebx, [8*eax]\nlea ecx, [ebx + 2*ebx]\nlea edx, [ecx + 8*ecx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [eax + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 8*ecx]\nlea " "eex, [ebx + 8*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [ebx + " "8*ecx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 8*ecx]\nlea " "eex, [ebx + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 2*ecx]\nlea " "eex, [ecx + 4*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 8*eax]\nlea edx, [ebx + 8*ecx]\nlea " "eex, [edx + 2*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ebx + " "8*ebx]\nlea eex, [ecx + 8*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [8*ebx]\nlea edx, [ecx + 4*ebx]\nlea eex, " "[ecx + 4*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + " "8*ecx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [ecx + 8*eax]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 8*ecx]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 8*ecx]\nlea " "eex, [ebx + 8*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 4*ebx]\nlea " "eex, [ecx + 4*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [ebx + 2*eax]\nlea edx, [ebx + 4*ecx]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 2*ecx]\nlea " "eex, [edx + 4*ecx]\n", "4\nlea ebx, [8*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ebx + 4*ecx]\nlea " "eex, [ebx + 8*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ecx + " "8*ebx]\nlea eex, [eax + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 8*ecx]\nlea " "eex, [edx + 8*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ecx + " "8*ebx]\nlea eex, [ebx + 8*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [ebx + 8*eax]\nlea edx, [ecx + 4*ebx]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*eax]\nlea edx, [ecx + " "8*ebx]\nlea eex, [ecx + 8*edx]\n", "4\nlea ebx, [eax + 4*eax]\nlea ecx, [ebx + 1*eax]\nlea edx, [ebx + " "4*ecx]\nlea eex, [ecx + 8*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [eax + " "4*ecx]\nlea eex, [ecx + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [8*ebx]\nlea edx, [ecx + 2*ecx]\nlea eex, " "[edx + 4*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + 4*ecx]\nlea " "eex, [eax + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + 4*ecx]\nlea " "eex, [ebx + 8*edx]\n", "3\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 8*ebx]\nlea edx, [ecx + " "8*ecx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [ebx + 2*eax]\nlea edx, [ecx + 4*ecx]\nlea " "eex, [ebx + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [eax + 8*ecx]\nlea " "eex, [edx + 4*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + 4*ecx]\nlea " "eex, [ecx + 8*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [eax + 4*ebx]\nlea edx, [ecx + " "8*ecx]\nlea eex, [ecx + 2*edx]\n", "4\nlea ebx, [8*eax]\nlea ecx, [ebx + 2*eax]\nlea edx, [ecx + 2*ecx]\nlea " "eex, [ebx + 8*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + " "8*ebx]\nlea eex, [eax + 8*edx]\n", "4\nlea ebx, [2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ebx + 8*ecx]\nlea " "eex, [edx + 4*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + " "8*ebx]\nlea eex, [ebx + 8*edx]\n", "4\nlea ebx, [4*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ebx + 8*ecx]\nlea " "eex, [edx + 8*edx]\n", "4\nlea ebx, [eax + 2*eax]\nlea ecx, [ebx + 4*eax]\nlea edx, [ecx + " "8*ecx]\nlea eex, [eax + 4*edx]\n", "5\nlea ebx, [2*eax]\nlea ecx, [eax + 2*eax]\nlea edx, [ecx + 4*eax]\nlea " "eex, [edx + 8*edx]\nlea efx, [ebx + 4*eex]\n", "4\nlea ebx, [2*eax]\nlea ecx, [eax + 8*ebx]\nlea edx, [ecx + 2*ecx]\nlea " "eex, [edx + 4*edx]\n", }; int main() { int n; cin >> n; cout << s[n - 1]; return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int t = 1; string ans = ""; for (int i = 0; i < n; i += t) { ans += s[i]; t++; } cout << ans << endl; return 0; }
1
#include <cstdio> #include <algorithm> #define Rep(i, n) for (int i = 1; i <= n; i ++) #define Rep0(i, n) for (int i = 0; i <= n; i ++) using namespace std; const int N0 = 100010; const int N = 410; int x[N0], y[N0]; bool g[N][N], v[N]; int main() { int n, m; scanf("%d%d", &n, &m); Rep(i, m) scanf("%d%d", &x[i], &y[i]); Rep(i, n) { g[i][i] = true; for (int j = m; j; j --) { if (!g[i][x[j]] && !g[i][y[j]]) continue; if (g[i][x[j]] && g[i][y[j]]) v[i] = true; else g[i][x[j]] = g[i][y[j]] = true; } } int ans = 0; Rep(i, n) if (!v[i]) Rep(j, i - 1) if (!v[j]) { bool flag = false; Rep(k, n) if (g[i][k] && g[j][k]){ flag = true; break;} if (!flag) ans ++; } printf("%d\n", ans); return 0; }
0
#include <bits/stdc++.h> using namespace std; const int N = 5000; const int MOD = 1e9 + 7; int n; int m; string str; int R[N]; int Last[N]; void add(int &a, int b) { a += b; if (a < 0) a += MOD; if (a >= MOD) a -= MOD; } int dp[N][N]; int go(int pos, int curr) { if (pos == n) return 1; if (curr == m) return 0; if (dp[pos][curr] != -1) return dp[pos][curr]; int ret = 0; add(ret, go(pos + 1, curr)); add(ret, go(pos, curr + 1)); if (R[curr] != -1) add(ret, -go(pos + 1, R[curr])); return dp[pos][curr] = ret; } int main(int argc, char *argv[]) { ios::sync_with_stdio(0); cin >> n; cin >> str; str.resize(unique(str.begin(), str.end()) - str.begin()); m = str.size(); for (int(i) = (0); (i) < (str.size()); (i)++) str[i] -= 'a'; memset(R, -1, sizeof R); memset(Last, -1, sizeof Last); for (int(i) = (0); (i) < (m); (i)++) { if (Last[str[i]] != -1) R[Last[str[i]]] = i; Last[str[i]] = i; } memset(dp, -1, sizeof dp); cout << go(0, 0) << endl; return 0; }
4
#include <bits/stdc++.h> using namespace std; long long ans, kq, n; string s; int dem; int main() { cin >> n; while (n > 0) { n--; cin >> s; ans = 0; dem = 0; for (int j = 0; j <= s.size() - 1; j++) { if (s[j] == '0') dem++; else { kq = 0; for (int i = j; i <= (s.size() - 1); i++) { dem++; if (s[i] == '1') kq = kq * 2 + 1; else kq = kq * 2; if (dem >= kq) ans += 1; if (kq > 2 * int(1e5) + 1) break; } dem = 0; } } cout << ans << endl; } }
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double eps = 1e-7; int w, l, a[MAXN], sum[MAXN]; int main() { scanf("%d %d", &w, &l); for (int i = 1; i < w; i++) scanf("%d", &a[i]), sum[i] = sum[i - 1] + a[i]; int ans = INF; for (int i = l; i < w; i++) { ans = min(ans, sum[i] - sum[i - l]); } printf("%d\n", ans); return 0; }
4
#include "bits/stdc++.h" using namespace std; int main() { int N; cin >> N; if (N == 2) { cout << -1 << endl; return 0; } if (N == 3) { cout << "aa.\n..b\n..b\n"; return 0; } if (N == 6) { cout << "aa....\n..b...\n..b...\n...aa.\n.....b\n.....b\n"; return 0; } if (N == 7) { cout << "aabbcc.\nddee..h\nffgg..h\n....mki\n....mki\n....nlj\n....nlj\n"; return 0; } if (N == 11) { cout << "aacd.......\nbbcd.......\nefgg.......\nefhh.......\n....aabbcc.\n....ddee..h\n....ffgg..h\n........mki\n........mki\n........nlj\n........nlj\n"; return 0; } vector<vector<char> > V4 = { {'a','a','c','d'},{'b','b','c','d'},{'e','f','g','g'},{'e','f','h','h'} }; vector<vector<char> > V5 = { {'a','a','b','b','c'},{'h','i','i','.','c'},{'h','.','.','j','d'},{'g','.','.','j','d'},{'g','f','f','e','e'} }; vector<vector<char> > ANS(N, vector<char>(N, '.')); int C4, C5; for (int i = 0; ; i++) { if ((N - i * 4) % 5 == 0) { C4 = i; C5 = (N - i * 4) / 5; break; } } int NOW = 0; for (int i = 0; i < C4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { ANS[NOW + j][NOW + k] = V4[j][k]; } } NOW += 4; } for (int i = 0; i < C5; i++) { for (int j = 0; j < 5; j++) { for (int k = 0; k < 5; k++) { ANS[NOW + j][NOW + k] = V5[j][k]; } } NOW += 5; } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << ANS[i][j]; } cout << endl; } }
0
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; int ans = a * (a - 1) / 2; cout << ans * 12 + 1; }
2
#include <bits/stdc++.h> using namespace std; const double E = 1e-6; const double PI = 2 * acos(0); struct p3d { double x, y, z; p3d() : x(0), y(0), z(0) {} p3d(double x, double y) : x(x), y(y), z(0) {} p3d(double x, double y, double z) : x(x), y(y), z(z) {} p3d operator+(const p3d& o) const { return p3d(x + o.x, y + o.y, z + o.z); } p3d operator-(const p3d& o) const { return p3d(x - o.x, y - o.y, z - o.z); } p3d operator*(const double m) const { return p3d(x * m, y * m, z * m); } p3d operator/(const double m) const { return p3d(x / m, y / m, z / m); } void operator/=(const double m) { x /= m, y /= m, z /= m; } void operator*=(const double m) { x *= m, y *= m, z *= m; } void operator-=(const p3d& o) { x -= o.x, y -= o.y, z -= o.z; } void operator+=(const p3d& o) { x += o.x, y += o.y, z += o.z; } bool operator<(const p3d& o) const { if (fabs(x - o.x) > E) return x < o.x; if (fabs(y - o.y) > E) return y < o.y; if (fabs(z - o.z) > E) return z < o.z; return false; } } Orig(0, 0, 0); p3d operator*(double m, const p3d& p) { return p * m; } p3d operator-(const p3d& p) { return Orig - p; } struct l3d { p3d P, v; l3d() : P(0, 0, 0), v(1, 0, 0) {} l3d(const p3d& P, const p3d& v) : P(P), v(v) {} p3d A() const { return P; } p3d B() const { return P + v; } }; double abs(const p3d& v) { return sqrt(v.x * v.x + v.y * v.y + v.z * v.z); } double dist_pp(const p3d& p, const p3d& p2) { return abs(p - p2); } double dot(const p3d& a, const p3d& b) { return a.x * b.x + a.y * b.y + a.z * b.z; } p3d cross(const p3d& a, const p3d& b) { return p3d(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); } p3d proj(const p3d& p, const p3d& over) { return over * dot(p, over) / dot(over, over); } p3d line_line_intersection(const l3d& A, const l3d& B) { p3d v1 = cross(A.v, B.v), v2 = cross(B.P - A.P, B.v); return A.P + A.v * (dot(v2, v1) / dot(v1, v1)); } p3d closest_point(l3d to, const l3d& from) { if (abs(cross(to.v, from.v)) < E) return from.P; p3d ll = proj(to.P - from.P, cross(to.v, from.v)); to.P -= ll; return line_line_intersection(to, from); } l3d make_seg(const p3d& a, const p3d& b) { return l3d(a, b - a); } l3d p2p_line(const p3d& a, const p3d& b) { return make_seg(a, b); } struct relation4 { double val[4]; relation4() {} relation4(double a, double b, double c, double d) { val[0] = a, val[1] = b, val[2] = c, val[3] = d; canonize(); } void canonize() { for (int i = 0; i < 4; i++) if (fabs(val[i]) > E) { const double norm = val[i]; for (int j = 0; j < 4; j++) val[j] /= norm; break; } } bool operator<(const relation4& o) const { for (int i = 0; i < 4; i++) if (fabs(val[i] - o.val[i]) > E) return val[i] < o.val[i]; return false; } }; l3d lines[1100]; relation4 directors[1100]; int main(int argc, char** argv) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { int x0, y0, z0, x1, y1, z1; scanf("%d %d %d %d %d %d", &x0, &y0, &z0, &x1, &y1, &z1); lines[i] = p2p_line(p3d(x0, y0, z0), p3d(x1, y1, z1)); directors[i] = relation4(0.0, x1 - x0, y1 - y0, z1 - z0); } map<relation4, set<relation4> > planes; map<p3d, set<int> > points; int result = min(1, n); for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { p3d c = cross(lines[i].v, lines[j].v); if (abs(c) > E) { p3d pi = closest_point(lines[i], lines[j]); p3d pj = closest_point(lines[j], lines[i]); if (dist_pp(pi, pj) < E) { p3d p = (pi + pj) / 2.0; relation4 plane = relation4(c.x, c.y, c.z, -(c.x * p.x + c.y * p.y + c.z * p.z)); points[p].insert(i); points[p].insert(j); planes[plane].insert(directors[i]); planes[plane].insert(directors[j]); } } } for (map<p3d, set<int> >::iterator it = points.begin(); it != points.end(); it++) result = max(result, (int)(it->second).size()); for (map<relation4, set<relation4> >::iterator it = planes.begin(); it != planes.end(); it++) result = max(result, (int)(it->second).size()); printf("%d\n", result); return 0; }
5
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; char a[n + 1][n + 1]; int ans[n + 1][n + 1]; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { cin >> a[i][j]; ans[i][j] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - k + 1; j++) { bool x = true; for (int t = j; t < j + k; t++) { if (a[i][t] == '#') { x = false; break; } } if (x) { for (int t = j; t < j + k; t++) ans[i][t]++; } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n - k + 1; j++) { bool x = true; for (int t = j; t < j + k; t++) { if (a[t][i] == '#') { x = false; break; } } if (x) { for (int t = j; t < j + k; t++) ans[t][i]++; } } } int mx = ans[1][1]; int p = 1, q = 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (ans[i][j] > mx) { mx = ans[i][j]; p = i; q = j; } } cout << p << " " << q; return 0; }
2
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 7, p = 998244353; int n, k, lim, a[N], b[N], c[N], rev[N], w[N], fac[N], ifac[N]; inline long long pows(long long a, int b) { long long ans = 1; while (b > 0) { if (b & 1) ans = (ans * a) % p; a = (a * a) % p, b = b >> 1; } return ans; } inline void ntt(int *s, int x) { for (int i = 0; i < lim; i++) if (rev[i] < i) swap(s[i], s[rev[i]]); for (int mid = 1; mid < lim; mid = mid << 1) { long long w = pows(x, (p - 1) / (mid << 1)); for (int i = 0, r = mid << 1; i < lim; i += r) { long long wn = 1; for (int j = 0; j < mid; j++, wn = (wn * w) % p) { int a = s[i + j], b = (s[i + j + mid] * wn) % p; s[i + j] = (a + b) % p, s[i + j + mid] = (a - b + p) % p; } } } } inline int mul(int a, int b) { return 1ll * a * b % p; } int main() { cin >> n; long long m; cin >> m; m %= (p - 1); for (int i = 0; i <= n; i++) scanf("%d", &w[i]); fac[0] = ifac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = 1ll * i * fac[i - 1] % p, ifac[i] = pows(fac[i], p - 2); lim = 1, k = 0; while (lim <= n + n) lim = lim << 1, k++; for (int i = 0; i < lim; i++) rev[i] = (rev[i >> 1] >> 1) | (i & 1) << (k - 1); for (int i = 0; i <= n; i++) a[i] = mul(w[i], fac[i]); for (int i = 0; i <= n; i++) b[n - i] = ifac[i]; ntt(a, 3), ntt(b, 3); for (int i = 0; i < lim; i++) a[i] = 1ll * a[i] * b[i] % p; ntt(a, (p + 1) / 3); long long inv = pows(lim, p - 2); for (int i = 0; i < lim; i++) a[i] = a[i] * inv % p; for (int i = 0; i <= n; i++) c[i] = mul(a[i + n] * pows(pows(i + 1, p - 2), m) % p, ifac[i]); for (int i = 0; i < lim; i++) a[i] = b[i] = 0; for (int i = 0; i <= n; i++) a[i] = mul(c[i], fac[i]); for (int i = 0; i <= n; i++) b[n - i] = mul(ifac[i], pows(p - 1, i)); ntt(a, 3), ntt(b, 3); for (int i = 0; i < lim; i++) a[i] = 1ll * a[i] * b[i] % p; ntt(a, (p + 1) / 3); for (int i = 0; i < lim; i++) a[i] = a[i] * inv % p; for (int i = 0; i <= n; i++) c[i] = mul(a[i + n], ifac[i]); for (int i = 0; i <= n; i++) printf("%d ", c[i]); return 0; }
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 20; long long int dp[MAXN][MAXN]; long long int tav[MAXN]; long long int n; string s; long long int dtoc(char x) { return x - '0'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); tav[0] = 1; for (int i = 1; i < MAXN; i++) { tav[i] = 10 * tav[i - 1]; } cin >> n; cin >> s; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { if (i) { dp[i][j] = dp[i - 1][j] + dtoc(s[2 * n - i - j]) * tav[i - 1]; } if (j) { dp[i][j] = max(dp[i][j], dp[i][j - 1] + dtoc(s[2 * n - i - j]) * tav[j - 1]); } } } int i = n; int j = n; while (i > 0 || j > 0) { if (i && dp[i - 1][j] + dtoc(s[2 * n - i - j]) * tav[i - 1] == dp[i][j]) { i--; cout << 'H'; } else { j--; cout << 'M'; } } }
5
#include <bits/stdc++.h> using namespace std; void Solve() { long long n; cin >> n; vector<pair<pair<long long, long long>, long long> > a(n); vector<long long> ans(n); for (long long i = 0; i < (n); ++i) { cin >> a[i].first.first >> a[i].first.second; a[i].second = i; if (a[i].first.first < 0) { a[i].first.first = -a[i].first.first; a[i].first.second = -a[i].first.second; ans[i] ^= 1; } } sort((a).begin(), (a).end(), [](pair<pair<long long, long long>, long long> a, pair<pair<long long, long long>, long long> b) { return a.first.second * b.first.first < a.first.first * b.first.second; }); long long x = a[0].first.first, y = a[0].first.second; for (long long i = 1; i < n; ++i) { long long x1 = x - a[i].first.first, y1 = y - a[i].first.second; long long x2 = x + a[i].first.first, y2 = y + a[i].first.second; if (x1 * x1 + y1 * y1 < x2 * x2 + y2 * y2) { ans[a[i].second] ^= 1; x = x1, y = y1; } else { x = x2, y = y2; } } for (long long i = 0; i < (n); ++i) { cout << (ans[i] ? -1 : 1) << ' '; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(); Solve(); return 0; }
3
#include <bits/stdc++.h> const int MAXN = 300005, MOD = 998244353; inline int add(int x, int y) { return x + y < MOD ? x + y : x + y - MOD; } inline int dec(int x, int y) { return x - y < 0 ? x - y + MOD : x - y; } struct Z { int x; Z(int x = 0) : x(x) {} friend Z operator+(const Z& l, const Z& r) { return Z(add(l.x, r.x)); } friend Z operator-(const Z& l, const Z& r) { return Z(dec(l.x, r.x)); } friend Z operator*(const Z& l, const Z& r) { return Z(1ll * l.x * r.x % MOD); } }; Z q_pow(Z a, int b) { Z ret = 1; for (; b; a = a * a, b >>= 1) if (b & 1) ret = ret * a; return ret; } Z inverse(Z x) { return q_pow(x, MOD - 2); } int N, M, a[MAXN]; Z f[MAXN], sum, inv[MAXN]; int main() { scanf("%d", &N); for (int i = 1; i <= N; ++i) scanf("%d", &a[i]), M += a[i]; f[0] = f[1] = 1; Z invM = inverse(M), invNp = inverse(N - 1); inv[1] = 1; for (int i = 2; i <= M; ++i) inv[i] = (MOD - MOD / i) * inv[MOD % i]; for (int i = 1; i < M; ++i) { f[i + 1] = ((1 - invNp * invM * (N - 2) * (M - i)) * f[i] - invM * i * (f[i - 1] + 1)) * M * (N - 1) * inv[M - i]; } for (int i = 1; i <= N; ++i) sum = sum + f[a[i]]; sum = sum - f[0] * (N - 1) - f[M]; printf("%d\n", sum.x); return 0; }
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t, class... A> inline void read(t &x, A &...a) { read(x); read(a...); } template <class t> inline void write(t x) { if (x < 0) putchar('-'), write(-x); else { if (x > 9) write(x / 10); putchar('0' + x % 10); } } const int N = 2005; long long f[N], ans, x; int l[N], r[N], a[N], n, k; void GG() { write(-1); exit(0); } signed main() { read(n, k); for (int i = 1; i <= n; i++) read(l[i], r[i], a[i]); for (int i = n; i; i--) { x = a[i]; if (r[i] == l[i + 1]) x += f[i + 1]; f[i] = max(0ll, x - 1ll * (r[i] - l[i]) * k); if (f[i] > k) GG(); } x = k; for (int i = 1; i <= n; i++) { if (x < f[i]) ans += x, x = k; ans += a[i]; x = (x + k - a[i] % k) % k; } write(ans); }
6
#include<bits/stdc++.h> #define LL long long #define REP(i,n) for(int i=0;i<n;++i) #define FOR(i,a,b) for(int i=a;i<=b;++i) using namespace std; static const LL INF = 1LL<<61LL; static const int mod = 10007; typedef pair<int,int> PII; LL N,K; LL V[11][2020]; LL Q[11][2020],T[11][2020]; LL mem[2020][11]; LL temp; LL cal(int n,int kind){ LL res=0; if(mem[n][kind]!=INF){ return mem[n][kind]; } if(n==K||kind>temp) return 0; REP(i,K-n){ if(n+i<=K){ if(Q[kind][i]){ res=max(cal(n+i+1,kind+1)+Q[kind][i],max(cal(n,kind+1),res)); } } } return mem[n][kind]=res; } signed main(){ REP(i,2001)REP(j,11)mem[i][j]=INF; cin>>N>>K; REP(i,N){ LL C,G; cin>>C>>G; V[G][i]=C; temp=max(temp,G); } FOR(i,1,temp){ sort(V[i],V[i]+N,greater<LL>()); REP(j,K){ if(!V[i][j])break; T[i][j]=j*(j+1); Q[i][j]=Q[i][j-1]+V[i][j]+T[i][j]-T[i][j-1]; } } cout<<cal(0,1)<<endl; }
0
#include <bits/stdc++.h> unsigned long long counts[500001] = {0}; char s[500001], t[500001]; int main() { unsigned long long n, k; scanf("%llu %llu", &n, &k); scanf("%s %s", (char *)s, (char *)t); unsigned long long i; for (i = 0; i < n && s[i] == t[i]; i++) ; counts[n] = 1; counts[n - i] += 1; unsigned long long j, pow, branches; for (i++; i < n; i++) { branches = (s[i] == 'a') + (t[i] == 'b'); if (branches) { counts[n - i] += branches; for (j = i + 1, pow = branches; j < n && j < i + 31; pow <<= 1, j++) counts[n - j] += pow; } } unsigned long long c = 0; for (i = n; i > 0 && k >= counts[i]; k -= counts[i], i--) c += i * counts[i]; c += i * k; printf("%llu\n", c); }
5
#include <bits/stdc++.h> using namespace std; const long long A = 100000000000000LL, N = 228228; const int e[13] = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000}; string a, o; string t[13] = {"I", "VI", "V", "XI", "X", "LX", "L", "CX", "C", "DC", "D", "MC", "M"}; long long s, _s, b, i, j, n, m; string norm(string a) { string b = ""; i = 0; while (i < a.size() && a[i] == '0') i++; if (i == a.size()) i--; for (; i < a.size(); i++) b += a[i]; return b; } long long get(char a) { if (a >= '0' && a <= '9') return a - '0'; return a - 'A' + 10; } long long ToTen(string a) { long long o = 0, k = 1; for (i = a.size() - 1; i >= 0; i--, k *= s) o += k * get(a[i]); return o; } char Get(long long a) { if (a < 10) return a + '0'; return 'A' + (a - 10); } string ToS(long long a) { long long k = 1; string o = ""; if (!a) o = "0"; while (a) o += Get(a % _s), a /= _s; reverse(o.begin(), o.end()); return o; } long long val(string a) { long long o = 0, k = 1; for (int i = a.size() - 1; i >= 0; i--, k *= 10) o += (a[i] - '0') * k; return o; } int main() { cin >> s >> a; for (i = 0; i < 13; i++) reverse(t[i].begin(), t[i].end()); if (a == "R") { cin >> a; a = norm(a); b = ToTen(a); for (i = 12; i >= 0; i--) while (b >= e[i]) b -= e[i], o += t[i]; cout << o << "\n"; } else { _s = val(a), cin >> a, a = norm(a); b = ToTen(a); cout << ToS(b) << "\n"; } }
3
#include <bits/stdc++.h> using namespace std; long long int n, a[100005], sum = 0, p = 0, s = 0, ans = 0; bool mark[100005], rang[100005]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } if (sum % 3 == 0) { sum /= 3; for (int i = 1; i <= n; i++) { s += a[i]; if (s == sum) { mark[i] = 1; } if (s == sum * 2) { rang[i] = 1; } } for (int i = n - 1; i >= 1; i--) { if (mark[i] == 1) { ans += p; } if (rang[i] == 1) { p++; } } } cout << ans << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, cnt = 0, res = 0; cin >> n; string s; int cnt0 = 0, cnt1 = 0, nt = 0; for (int i = 0; i < n; i++) { cin >> s; cnt0 = 0; cnt1 = 0; for (int j = 0; j < s.length(); j++) if (s[j] == '0') cnt0++; else cnt1++; if ((cnt0 % 2) != (cnt1 % 2)) { cnt++; res++; } else { if (cnt0 % 2 == 0) cnt++; else nt++; } cnt += nt - (nt % 2); nt = nt % 2; } if (nt <= res) { cnt += nt; res -= nt; nt = 0; } else { cnt += res; nt -= res; res = 0; } cout << cnt << "\n"; } }
2
#include <bits/stdc++.h> using namespace std; int n, len; int a[100005], v[100005], dp[2][100005], poz[100005], fact[100005]; inline bool Lucky(int x) { while (x) { if (x % 10 != 4 && x % 10 != 7) return false; x /= 10; } return true; } inline int Pow_Log(int x, int p) { int sol = 1; while (p) { if (p & 1) { sol = (1LL * sol * x) % 1000000007; --p; } p >>= 1; x = (1LL * x * x) % 1000000007; } return sol; } inline int Comb(int n, int k) { if (k > n) return 0; return (1LL * fact[n] * Pow_Log((1LL * fact[k] * fact[n - k]) % 1000000007, 1000000007 - 2)) % 1000000007; } int main() { int i, k, nr = 0, j, sol = 0; scanf("%d%d", &n, &k); fact[0] = 1; for (i = 1; i <= 100000; ++i) fact[i] = (1LL * fact[i - 1] * i) % 1000000007; for (i = 1; i <= n; ++i) { scanf("%d", &a[i]); if (Lucky(a[i])) v[++len] = a[i]; else ++nr; } sort(v + 1, v + len + 1); for (i = 1; i <= len; ++i) if (v[i] == v[i - 1]) poz[i] = poz[i - 1]; else poz[i] = i - 1; for (i = 0; i <= len; ++i) dp[0][i] = 1; for (j = 1; j <= 1100 && j <= k; ++j) { int l1 = (j & 1), l2 = ((j - 1) & 1); for (i = 0; i <= len; ++i) dp[l1][i] = 0; for (i = j; i <= len; ++i) { dp[l1][i] = dp[l1][i - 1]; dp[l1][i] += dp[l2][poz[i]]; if (dp[l1][i] >= 1000000007) dp[l1][i] -= 1000000007; } sol += (1LL * Comb(nr, k - j) * dp[l1][len]) % 1000000007; if (sol >= 1000000007) sol -= 1000000007; } sol += Comb(nr, k); if (sol >= 1000000007) sol -= 1000000007; printf("%d\n", sol); return 0; }
5
#include <bits/stdc++.h> using namespace std; bool comp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; } int main() { ios_base::sync_with_stdio(0); string a, b; cin >> a >> b; int tab1[26], tab2[26]; for (int i = int(0); i < int(26); ++i) { tab1[i] = tab2[i] = 0; } for (int i = int(0); i < int(a.size()); ++i) tab1[(int)(a[i] - 'a')]++; for (int i = int(0); i < int(b.size()); ++i) tab2[(int)(b[i] - 'a')]++; int cpt = 0; bool ok = true; for (int i = int(0); i < int(26); ++i) { if (tab2[i] >= tab1[i]) cpt += tab1[i]; else cpt += tab2[i]; if (tab1[i] == 0 && tab2[i] != 0) { ok = false; break; } } if (!ok) cout << -1 << endl; else cout << cpt << endl; return 0; }
2
#include <bits/stdc++.h> #define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i)) #define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i)) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair<int, int> pii; typedef pair<lint, lint> pll; template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;} template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;} template<class T> T div_floor(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>=0 ? a/b : (a+1)/b-1; } template<class T> T div_ceil(T a, T b){ if(b < 0) a *= -1, b *= -1; return a>0 ? (a-1)/b+1 : a/b; } constexpr lint mod = 1000000007; constexpr lint INF = mod * mod; constexpr int MAX = 100010; int n, m; vector<int> G[MAX]; vector<int> bfs(int s){ vector<int> d(n, mod); d[s] = 0; queue<int> que; que.push(s); while(!que.empty()){ int v = que.front(); que.pop(); for(auto nv: G[v])if(chmin(d[nv], d[v] + 1)){ que.push(nv); } } return d; } int main(){ int s, t; scanf("%d%d%d%d", &n, &m, &s, &t); --s; --t; rep(i, m){ int a, b; scanf("%d%d", &a, &b); --a; --b; G[a].push_back(b); G[b].push_back(a); } auto ds = bfs(s), dt = bfs(t); int dst = ds[t]; lint ans = 0, cnt[n+10]; memset(cnt, 0LL, sizeof(cnt)); rep(i, n)if(dt[i] < n+10) ++cnt[dt[i]]; rep(i, n)if(dst-2 - ds[i] >= 0) ans += cnt[dst-2 - ds[i]]; printf("%lld\n", ans); }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; constexpr auto MOD = 1000000007LL; constexpr auto LINF = (1LL << 60); constexpr auto INF = 2147483647LL; constexpr auto PI = 3.1415926535897932384626433; constexpr auto EPS = 1E-9; template <typename T1, typename T2> ostream& operator<<(ostream& out, const pair<T1, T2> p) { out << p.first << ' ' << p.second; return out; } template <typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2>& p) { in >> p.first >> p.second; return in; } template <typename T> istream& operator>>(istream& in, vector<T>& v) { for (auto& x : v) in >> x; return in; } template <typename T> ostream& operator<<(ostream& out, vector<T> v) { for (int i = 0; i < v.size(); i++) out << v[i] << (i + 1 == v.size() ? '\n' : ' '); out.flush(); return out; } int n, m; ll cnt[1010], sqcnt[1010]; int main() { ios_base::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= min(n, m); i++) { cnt[i] = (n - i) / m + 1; if (i * i % m) sqcnt[i * i % m] += cnt[i]; else sqcnt[m] += cnt[i]; } ll res = 0; for (int i = 1; i <= m; i++) { res += cnt[i] * sqcnt[-i * i % m + m]; } cout << res << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAXN = 1e5 + 9; ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } int main() { ios::sync_with_stdio(false); ll a; cin >> a; ll b, c, x; for (int i = 0; i < 5; i++) x = sqrt(a); for (ll i = sqrt(a); i > 0; i--) { for (int i = 0; i < 123; i++) a = a; for (int i = 0; i < 123; i++) a = a; for (int i = 0; i < 123; i++) a = a; if (a % i == 0) { if (a / gcd(i, a / i) == a) { b = i; c = a / i; break; } if (i == 1) { b = i; c = a / i; break; } } } cout << b << " " << c << endl; return 0; }
3
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,m,a[100005],b,c; ll ans; vector<pair<ll,ll>> p; int main() { cin>>n>>m; for(int i=0;i<n;i++){ cin>>a[i]; } sort(a,a+n); for(int i=0;i<m;i++){ cin>>b>>c; p.push_back({c,b}); } sort(p.begin(),p.end(),greater<pair<ll,ll>>()); int j=0; for(int i=0;i<n;i++){ if(j<m&&p[j].second==0)j++; if(j<m)ans+=max(a[i],p[j].first),p[j].second--; else ans+=a[i]; } cout<<ans<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { double w,h,x,y;cin>>w>>h>>x>>y; cout<< fixed<< setprecision(6)<<w*h/2<<" "; if(w/2==x&&h/2==y) cout<<1; else cout<<0; }
0
#include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> using namespace std; int n,m,q; long long ans; long long a[100000+10],b[100000+10]; int main() { scanf("%d%d%d",&n,&m,&q); for(int i=1;i<=n;i++) scanf("%lld",&a[i]); n++;a[n]=1e18;a[0]=-1e18; for(int i=1;i<=m;i++) scanf("%lld",&b[i]); m++;b[m]=1e18;b[0]=-1e18; for(int i=1;i<=q;i++){ long long x; scanf("%lld",&x); int k1=lower_bound(a+1,a+n+1,x)-a; int k2=lower_bound(b+1,b+m+1,x)-b; ans=min(min(a[k1]-b[k2-1]+min(a[k1]-x,x-b[k2-1]),b[k2]-a[k1-1]+min(b[k2]-x,x-a[k1-1])), min(x-min(a[k1-1],b[k2-1]),max(a[k1],b[k2])-x)); printf("%lld\n",ans); } return 0; }
0
#include <bits/stdc++.h> using namespace std; string s, d, h; int cnt = 1; char c[6][6], x; map<string, bool> ch; vector<int> ind; void tot(string s) { if (ch[s]) return; ch[s] = 1; string a; c[0][2] = s[0]; c[2][2] = s[1]; c[1][0] = s[2]; c[1][1] = s[3]; c[1][2] = s[4]; c[1][3] = s[5]; c[3][2] = c[1][0]; x = c[1][0]; c[1][0] = c[1][1]; c[1][1] = c[1][2]; c[1][2] = c[1][3]; c[1][3] = x; c[3][2] = c[1][0]; a = c[0][2]; a += c[2][2]; for (int k = 0; k < 4; k++) a += c[1][k]; tot(a); c[0][2] = s[0]; c[2][2] = s[1]; c[1][0] = s[2]; c[1][1] = s[3]; c[1][2] = s[4]; c[1][3] = s[5]; c[3][2] = c[1][0]; x = c[0][2]; c[0][2] = c[1][2]; c[1][2] = c[2][2]; c[2][2] = c[3][2]; c[3][2] = x; c[1][0] = c[3][2]; a = c[0][2]; a += c[2][2]; for (int k = 0; k < 4; k++) a += c[1][k]; tot(a); } int main() { cin >> s; sort(s.begin(), s.end()); h = s; tot(s); for (int i = 0; i < 6; i++) ind.push_back(i); s.clear(); while (next_permutation(ind.begin(), ind.end())) { s.clear(); for (int i = 0; i < 6; i++) { s += h[ind[i]]; } if (!ch[s]) { cnt++; tot(s); } } cout << cnt << endl; }
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; template <typename T> struct LCT { int ch[MAXN][2] = {0, 0}, fa[MAXN] = {0}, siz[MAXN] = {0}; bool rev_tag[MAXN]; inline void maintain(int p) { siz[p] = siz[ch[p][0]] + siz[ch[p][1]] + 1; } inline void lazydown(int p) { if (rev_tag[p]) { swap(ch[p][0], ch[p][1]); rev_tag[ch[p][0]] ^= 1, rev_tag[ch[p][1]] ^= 1; rev_tag[p] = 0; } } void lazyflow(int p) { if (!isroot(p)) lazyflow(fa[p]); lazydown(p); } inline bool isroot(int p) { return ch[fa[p]][0] != p && ch[fa[p]][1] != p; } inline bool isrc(int p) { return p == ch[fa[p]][1]; } void rotate(int x) { int y = fa[x], z = fa[y], ci = isrc(x); if (!isroot(y)) ch[z][y == ch[z][1]] = x; ch[y][ci] = ch[x][!ci], fa[ch[x][!ci]] = y; ch[x][!ci] = y, fa[y] = x; fa[x] = z; maintain(y), maintain(x); } void splay(int x) { lazyflow(x); for (int f; f = fa[x], !isroot(x); rotate(x)) if (!isroot(f)) rotate((isrc(x) == isrc(f)) ? f : x); } int access(int x) { int c; for (c = 0; x; c = x, x = fa[x]) splay(x), ch[x][1] = c, maintain(x); return c; } int findroot(int x) { x = access(x); while (lazydown(x), ch[x][0]) x = ch[x][0]; splay(x); return x; } inline void makeroot(int x) { rev_tag[access(x)] ^= 1; } inline void link(int x, int y) { makeroot(x), fa[x] = y; } inline void split(int x, int y) { makeroot(x), access(y), splay(y); } inline void cut(int x, int y) { split(x, y), fa[x] = ch[y][0] = 0, maintain(y); } }; int n, q, k[MAXN], cmd, p, k2; LCT<int> lct; int main() { ios::sync_with_stdio(0); cin >> n >> q; for (int i = 1; i <= n; ++i) { cin >> k[i]; if (i + k[i] <= n) lct.link(i, i + k[i]); } while (q--) { cin >> cmd >> p; if (cmd == 1) { int rt = lct.findroot(p); cout << rt << ' ' << lct.siz[rt] << '\n'; } else { cin >> k2; if (p + k[p] <= n) { int rt = lct.findroot(p); lct.cut(p, p + k[p]); lct.makeroot(rt); } if (p + k2 <= n) lct.link(p, p + k2); k[p] = k2; } } return 0; }
5
#include <bits/stdc++.h> using namespace std; int main(void) { int n, k, l, c, d, nl, np, p; scanf("%d%d%d%d%d%d%d%d", &n, &k, &l, &c, &d, &p, &nl, &np); printf("%d\n", min(min(k * l / nl, c * d), p / np) / n); return 0; }
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count()); template <typename T1, typename T2> inline bool upmax(T1& a, T2 b) { return (a < b ? (a = b, true) : false); } template <typename T1, typename T2> inline bool upmin(T1& a, T2 b) { return (b < a ? (a = b, true) : false); } const int maxn = (int)1e5 + 100; const int maxlog = 21; const int base = 1e9 + 7; const long double eps = (long double)1e-9; const long double PI = acos(-1.); const int inf = 2e9; const long long llinf = 2e18; vector<int> g[maxn]; vector<int> st; int used[maxn]; bool inc[maxn]; vector<int> cyc; void dfs(int v, int p = -1) { used[v] = 2; st.push_back(v); for (auto to : g[v]) { if (to == p) continue; if (!used[to]) { dfs(to, v); } else if (used[to] == 2) { for (int i = st.size() - 1; st[i] != to; i--) { cyc.push_back(st[i]); inc[st[i]] = 1; } cyc.push_back(to); inc[to] = 1; } } st.pop_back(); used[v] = 1; } long long sz[maxn], d[maxn], opt[maxn]; long long sumd[maxn]; int wh[maxn]; int root; void dfs2(int v, int p = -1) { wh[v] = root; sumd[root] += d[v]; sz[root] += 1; for (auto to : g[v]) { if (to == p) continue; if (inc[to]) continue; d[to] = d[v] + 1; dfs2(to, v); } } long long res = 0; void dfs3(int v, int d, int p = -1) { res += d; for (auto to : g[v]) { if (to != p && wh[to] == wh[v]) dfs3(to, d + 1, v); } } long long dp[maxn][2]; long long pr[maxn]; int main() { srand(time(0)); ios_base::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs(0); for (int i = 0; i < cyc.size(); i++) { root = cyc[i]; d[root] = 1; opt[root] = n; dfs2(cyc[i]); } long long all = 0; for (int i = 0; i < n; i++) { if (!inc[i]) { res = 0; dfs3(i, 1); res += 1ll * d[i] * (n - sz[wh[i]]); upmax(opt[wh[i]], res); } else { all += sumd[i]; } } for (int i = 0; i < cyc.size(); i++) { dp[i][0] = all - sumd[cyc[i]] + opt[cyc[i]]; dp[i][1] = -1; pr[i] = sz[cyc[i]]; pr[i + cyc.size()] = pr[i]; } for (int i = 1; i < cyc.size() * 2; i++) { pr[i] += pr[i - 1]; } for (int i = 0; i < cyc.size() - 1; i++) { dp[cyc.size()][0] = dp[0][0]; for (int l = 0; l < cyc.size(); l++) { upmax(dp[l][1], max(dp[l][0], dp[l + 1][0]) + n - pr[l + i + 1] + (l ? pr[l - 1] : 0)); } for (int i = 0; i < cyc.size(); i++) { dp[i][0] = dp[i][1]; dp[i][1] = -1; } } long long res = 0; for (int i = 0; i < cyc.size(); i++) { upmax(res, dp[i][0]); } cout << res; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int MAXN = 1E5 + 10; const int INF = 1 << 30; struct OPT { int x, s1, s2, id; } op[MAXN], tL[MAXN], tR[MAXN]; pair<int, int> p[MAXN]; int n, V, t[MAXN], Ans1[MAXN], Ans2[MAXN]; long long v1[MAXN], v2[MAXN], totv1, totv2, val1[MAXN], val2[MAXN]; void C(int x, int v) { for (; x; x -= x & (-x)) t[x] = max(t[x], v); } int Q(int x) { int ret = -INF; for (; x <= n + 1; x += x & (-x)) ret = max(ret, t[x]); return ret; } void Cls(int x) { for (; x; x -= x & (-x)) t[x] = -INF; } void solve(int l, int r, int *F) { if (l == r) return; int mid = (l + r) >> 1, totl = mid - l + 1, totr = r - mid; solve(l, mid, F); for (int i = l; i <= mid; i++) tL[i - l + 1] = op[i]; for (int i = mid + 1; i <= r; i++) tR[i - mid] = op[i]; sort(tL + 1, tL + 1 + totl, [](const OPT &Lhs, const OPT &Rhs) { return Lhs.x < Rhs.x; }); sort(tR + 1, tR + 1 + totr, [](const OPT &Lhs, const OPT &Rhs) { return Lhs.x < Rhs.x; }); int ptrL = 1, ptrR = 1; while (ptrL <= totl && ptrR <= totr) { if (tL[ptrL].x <= tR[ptrR].x) C(tL[ptrL].s1, F[tL[ptrL].id]), ++ptrL; else F[tR[ptrR].id] = max(F[tR[ptrR].id], Q(tR[ptrR].s1) + 1), ++ptrR; } while (ptrR <= totr) F[tR[ptrR].id] = max(F[tR[ptrR].id], Q(tR[ptrR].s1) + 1), ++ptrR; for (int i = 1; i <= totl; i++) Cls(tL[i].s1); ptrL = totl; ptrR = totr; while (ptrL && ptrR) { if (tL[ptrL].x >= tR[ptrR].x) C(tL[ptrL].s2, F[tL[ptrL].id]), --ptrL; else F[tR[ptrR].id] = max(F[tR[ptrR].id], Q(tR[ptrR].s2) + 1), --ptrR; } while (ptrR) F[tR[ptrR].id] = max(F[tR[ptrR].id], Q(tR[ptrR].s2) + 1), --ptrR; for (int i = 1; i <= totl; i++) Cls(tL[i].s2); solve(mid + 1, r, F); } int main() { memset(Ans1, 0xcf, sizeof Ans1); memset(Ans2, 0xcf, sizeof Ans2); scanf("%d", &n); for (int i = 1; i <= n + 1; i++) Cls(i); for (int i = 1; i <= n; i++) scanf("%d%d", &p[i].second, &p[i].first); scanf("%d", &V); sort(p + 1, p + 1 + n); for (int i = 0; i <= n; i++) v1[++totv1] = val1[i] = p[i].second - 1ll * V * p[i].first, v2[++totv2] = val2[i] = -p[i].second - 1ll * V * p[i].first; sort(v1 + 1, v1 + 1 + totv1); sort(v2 + 1, v2 + 1 + totv2); totv1 = unique(v1 + 1, v1 + 1 + totv1) - v1 - 1; totv2 = unique(v2 + 1, v2 + 1 + totv2) - v2 - 1; for (int i = 0; i <= n; i++) val1[i] = lower_bound(v1 + 1, v1 + 1 + totv1, val1[i]) - v1, val2[i] = lower_bound(v2 + 1, v2 + 1 + totv2, val2[i]) - v2; for (int i = 0; i <= n; i++) op[i] = (OPT){p[i].second, (int)val1[i], (int)val2[i], i}; Ans1[0] = Ans2[0] = 0; solve(0, n, Ans1); sort(op, op + n + 1, [](const OPT &Lhs, const OPT &Rhs) { return Lhs.id < Rhs.id; }); for (int i = 1; i <= n; i++) Ans2[i] = 1; solve(0, n, Ans2); int ans1 = 0, ans2 = 0; for (int i = 0; i <= n; i++) ans1 = max(ans1, Ans1[i]), ans2 = max(ans2, Ans2[i]); printf("%d %d\n", ans1, ans2); }
6
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const long long mod = 1e9 + 7; const int alphabet = 26; const int inf = INT_MAX; const long long lint = 1e18 + 9; inline long long cnm(char ch) { return (ch - '0'); } inline long long cap(char ch) { return (ch - 'a'); } inline void instr(string& s, long long& n) { cin >> s; n = s.length(); } inline void instr(string& s) { cin >> s; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long i, j, k, m, n; cin >> n >> m; long long ans = inf; for (i = 0; i < m; i++) { long long l, r; cin >> l >> r; ans = min(ans, r - l + 1); } long long sum = 0; cout << ans << endl; for (i = 0; i < n; i++) { cout << sum << " "; sum++; sum %= ans; } return 0; }
1
#include <bits/stdc++.h> using namespace std; vector<int> ans[105]; vector<int> lag, kom; int main() { int n, m, k; cin >> n >> m >> k; lag.resize(m); kom.resize(k); for (int i = 0; i < m; cin >> lag[i], i++) ; for (int i = 0; i < k; cin >> kom[i], i++) ; int kol = 0; for (int i = 0; i < m; i++) { kol = 0; for (int j = 0; j < k; j++) if (kom[j] % lag[i] == 0) kol++; ans[kol].push_back(i + 1); } for (int i = 0; i <= k; i++) if (ans[i].size()) { cout << ans[i].size() << "\n"; for (int j = 0; j < ans[i].size(); j++) cout << ans[i][j] << " "; break; } return 0; }
6