intmain(){ int n, k; cin >> n >> k; if (k < n/2 || (n == 1 && k)) cout << -1; elseif (k == n/2) for (int i = 1; i <= n; i++) cout << i << ' '; else { int res = k - (n-2)/2, x = 1; cout << res << ' ' << res*2 << ' '; n -= 2;
for (int i = 1; i < n; i += 2) { while (x == res || x+1 == res || x == res*2 || x+1 == res*2) x ++; cout << x << ' ' << ++x << ' '; x++; } if (n & 1) { while (x == res || x == res*2) x ++; cout << x; } } }
usingnamespace std; constint N = 105; int n, m, a[N][N];
voidsolve(){ memset (a, 0, sizeof a); int ans = 0; cin >> n >> m; //intput string for (int i = 1; i <= n; i++) { string s; cin >> s; for (int j = 0; j < m; j++) { if (s[j] == '1') ans += 3, a[i][j+1] = 1; } }
cout << ans << endl; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i][j] == 0) continue; int dx = 1, dy = 1; if (i == 1) dx = -1; if (j == 1) dy = -1; cout << i << ' ' << j << ' ' << i-dx << ' ' << j << ' ' << i-dx << ' ' << j-dy << endl; cout << i << ' ' << j << ' ' << i << ' ' << j-dy << ' ' << i-dx << ' ' << j << endl; cout << i << ' ' << j << ' ' << i << ' ' << j-dy << ' ' << i-dx << ' ' << j-dy << endl; } } }
intmain(){ int t; cin >> t; while (t --) solve (); }
usingnamespace std; constint N = 2e5 + 5; int n, m, k, sum, b[N]; pair<int, int> a[N];
signedmain(){ cin >> n >> m >> k; set <int> s; for (int i = 1; i <= n; i++) { cin >> b[i]; a[i] = {b[i], i}; } sort (a + 1, a + n + 1, greater<>()); for (int i = 1; i <= k*m; i++) sum += a[i].first, s.insert (a[i].second); cout << sum << endl; k --; vector <int> v; int cnt = 0; for (int i = 1; i <= n && k; i ++) { if (s.count (i)) cnt ++; if (cnt == m) cout << i << ' ', k--, cnt = 0; } }
intqmi(int a,int k){ int ans = 1; while (k) { if (k & 1)//末位1取出 ans = (longlong)ans * a % p; k >>= 1;//次末位 a = (longlong)a * a % p; } return ans; }
voidsolve(){ int n, m; cin >> n >> m; int ans = 0; while (m --) { int x; cin >> x >> x >> x; //l,r无用 ans |= x; } cout << 1ll * ans * qmi(2, n-1) % p << endl; }
intmain(){ int t; cin >> t; while (t --) solve (); }
intmain(){ string a, b; cin >> a >> b; if (a == b) { puts ("YES"); return0; } if (a.size() != b.size()) { puts ("NO"); return0; }
int cnta = 0, cntb = 0; //1的个数 for (int i = 0; i < a.size(); i++) { if (a[i] == '1') cnta ++; } for (int i = 0; i < b.size(); i++) { if (b[i] == '1') cntb ++; }
usingnamespace std; constint N = 105; char a[N][N]; bool change[N];
intmain(){ int n, m, ans = 0; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> a[i][j]; } }
for (int t = 1; t <= 100; t++) { for (int i = 1; i < n; i++) { for (int j = 0; j < m; j++) { if (change[j]) continue; if (a[i-1][j] < a[i][j]) break; if (a[i-1][j] > a[i][j]) change[j] = true; } } } for (int i = 0; i < m; i++) { if (change[i]) ans ++; } cout << ans; }
usingnamespace std; constint N = 505; int a[N][N], b[N][N];
intmain(){ int n, m; scanf ("%d%d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf ("%d", &a[i][j]); } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf ("%d", &b[i][j]); } }
bool suc = true; for (int k = 1; k <= m; k++) { //(1, j),(2, j+1-2),... map<int, int>c, d; for (int i = 1, j = k; i <= n && j >= 1; i++, j--) { int x = a[i][j], y = b[i][j]; c[x] ++, d[y] ++; } if (c != d) { suc = false; break; } }
if (!suc) { puts ("NO"); return0; }
for (int k = 2; k <= n; k++) { map<int, int>c, d; for (int i = k, j = m; i <= n && j >= 1; i++, j--) { int x = a[i][j], y = b[i][j]; c[x] ++, d[y] ++; } if (c != d) { suc = false; break; } } if (suc) puts ("YES"); elseputs ("NO"); }
intmain(){ string a, b; cin >> a >> b; int n = a.size();
int ed = 0, st = 0, cnt = 0; //cnt=?的个数 for (int i = 0; i < n; i++) { if (a[i] == '+') ed ++; else ed --; } for (int i = 0; i < n; i++) { if (b[i] == '?') cnt ++; elseif (b[i] == '+') st ++; else st --; }
//二进制枚举 int tot = 0, m = (1 << cnt); for (int i = 0; i < m; i++) { int dx = 0; //b的偏移 for (int j = 0; j < cnt; j++) { if (i >> j & 1) dx ++; else dx --; } if (st + dx == ed) tot ++; } double ans = 1.0*tot/m;
usingnamespace std; typedef pair<int, int> pii; constint N = 2e5 + 5; int n, b[N]; pii a[N]; string s; bool in_stk[N];
voidsolve(){ memset (in_stk, false, sizeof in_stk); cin >> n >> s; for (int i = 0; i < n; i++) a[i+1] = {s[i] - '0', i+1}; stack<pii> stk; for (int i = 1; i <= n; i++) { while (!stk.empty() && stk.top().first > a[i].first) in_stk[stk.top().second] = false, stk.pop(); stk.push (a[i]), in_stk[i] = true; } int x = 10; for (int i = 1; i <= n; i++) { if (!in_stk[i]) x = min (x, a[i].first); }
boolis_prime(int x){ for (int i = 2; i*i <= x; i++) { if (x % i == 0) returnfalse; } returntrue; }
intmain(){ int n; cin >> n; if (is_prime (n)) { cout << n << endl; for (int i = 1; i < n; i++) cout << i << ' ' << i + 1 << endl; cout << n << " 1\n"; } else { int dx = 0; while (!is_prime(n + dx)) dx ++; cout << n + dx << endl; for (int i = 1; i < n; i++) cout << i << ' ' << i + 1 << endl; cout << n << " 1\n"; for (int i = 1; i <= dx; i++) cout << i << ' ' << n - i << endl; } }
intmain(){ int n, k, tot = -1; cin >> n >> k; for (int i = n; i > n-k; i--) { ans[i] = s[++tot]; } for (int i = 1; i <= n-k+1; i++) { string ss; cin >> ss; if (ss[0] == 'Y') check[i] = true; }
for (int i = n-k+1; i >= 1; i--) { if (check[i]) ans[i] = s[++tot]; else ans[i] = ans[i+k-1]; }
for (int i = 1; i <= n; i++) cout << ans[i] << ' '; }
usingnamespace std; constint N = 2e5 + 5; int a[N], n;
voidsolve(){ cin >> n; if (n == 3) { cout << "2 1 3\n"; return ; } if (n % 4 == 0) { int x = 0; for (int i = 1; i <= n; i += 2) a[i] = x++; for (int i = 2; i <= n; i += 2) a[i] = x++; } elseif (n % 4 == 3) { a[1] = 1, a[2] = 2, a[3] = 3; int x = 4; for (int i = 4; i <= n; i += 2) a[i] = x++; for (int i = 5; i <= n; i += 2) a[i] = x++; }
elseif (n % 4 == 2) { for (int i = 16; i < n + 9; i += 4) cout << i << ' ' << i+1 << ' ' << i+3 << ' ' << i+2 << ' '; cout << "12 8 2 4 1 3\n"; return ; }
else { int x = 4; for (int i = 1; i < n; i += 2) a[i] = x++; for (int i = 2; i <= n; i += 2) a[i] = x++; a[n] = 0; }
for (int i = 1; i <= n; i++) cout << a[i] << ' '; cout << "\n"; }
signedmain(){ ios::sync_with_stdio (0);cin.tie(0);cout.tie(0); int t; cin >> t; while (t --) { solve (); } }
usingnamespace std; constint N = 1e5 + 5; int ans, sumb; int b[N], g[N];
signedmain(){ int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> b[i]; sumb += b[i]; } ans += sumb * m; sort (b + 1, b + n + 1, greater <int> ());
bool suc = true, add = false; for (int i = 1; i <= m; i++) { cin >> g[i]; if (b[1] > g[i]) suc = false; if (b[1] == g[i]) add = true; }
if (!suc) { cout << -1; return0; }
sort (g + 1, g + m + 1); if (add) ans += g[1] - b[1]; else ans += g[1] - b[2]; // for (int i = 2; i <= m; i++) ans += g[i] - b[1];
intmain(){ int n; cin >> n; //不符合——链 if (n < 6) cout << "-1\n"; else { for (int i = 2; i <= 4; i++) cout << "1 " << i << endl; for (int i = 5; i <= n; i++) cout << "2 " << i << endl; } //符合——1连所有点 for (int i = 2; i <= n; i++) cout << "1 " << i << endl; }