Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
8 values
p02940
#include <bits/stdc++.h> #define SORT(x) sort((x).begin(), (x).end()) #define ALL(x) x.begin(), x.end() #define db(x) cout << #x << "=" << x << endl #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, m, n) for (int i = m; i < n; i++) #define repr(i, n, m) for (int i = n; i >= m; i--) #define INF (1e9) #define PI (acos(-1)) using namespace std; typedef long long ll; int main() { int N; cin >> N; string S; cin >> S; ll MOD = 998244353; ll ans = 1; ll ct = N; char c1 = 'O', c2 = 'O'; int v1 = 0, v2 = 0; rep(i, 3 * N) { char c = S[i]; if (c1 == 'O') { c1 = c; v1 = 1; ans = (ans * ct) % MOD; ct--; } else if (c2 == 'O') { if (c == c1) { v1 += 1; ans = (ans * ct) % MOD; ct--; } else { c2 = c; v2 = 1; ans = (ans * v1) % MOD; } } else if (c != c1 && c != c2) { ans = (ans * min(v1, v2)) % MOD; v1 -= 1; v2 -= 1; } else { if (v1 == v2) { if (c == c1) { v1 += 1; ans = (ans * ct) % MOD; ct--; } else { v2 += 1; ans = (ans * ct) % MOD; ct--; } } else if (v1 < v2) { if (c == c1) { ans = (ans * (v2 - v1)) % MOD; v1 += 1; } else { v2 += 1; ans = (ans * ct) % MOD; ct--; } } else { if (c == c2) { ans = (ans * (v1 - v2)) % MOD; v2 += 1; } else { v1 += 1; ans = (ans * ct) % MOD; ct--; } } } if (v2 == 0) c2 = 'O'; if (v1 == 0) { if (v2 == 0) c1 = 'O'; else { c1 = c2; v1 = v2; c2 = 0; v2 = 0; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define SORT(x) sort((x).begin(), (x).end()) #define ALL(x) x.begin(), x.end() #define db(x) cout << #x << "=" << x << endl #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, m, n) for (int i = m; i < n; i++) #define repr(i, n, m) for (int i = n; i >= m; i--) #define INF (1e9) #define PI (acos(-1)) using namespace std; typedef long long ll; int main() { int N; cin >> N; string S; cin >> S; ll MOD = 998244353; ll ans = 1; ll ct = N; char c1 = 'O', c2 = 'O'; int v1 = 0, v2 = 0; rep(i, 3 * N) { char c = S[i]; if (c1 == 'O') { c1 = c; v1 = 1; ans = (ans * ct) % MOD; ct--; } else if (c2 == 'O') { if (c == c1) { v1 += 1; ans = (ans * ct) % MOD; ct--; } else { c2 = c; v2 = 1; ans = (ans * v1) % MOD; } } else if (c != c1 && c != c2) { ans = (ans * min(v1, v2)) % MOD; v1 -= 1; v2 -= 1; } else { if (v1 == v2) { if (c == c1) { v1 += 1; ans = (ans * ct) % MOD; ct--; } else { v2 += 1; ans = (ans * ct) % MOD; ct--; } } else if (v1 < v2) { if (c == c1) { ans = (ans * (v2 - v1)) % MOD; v1 += 1; } else { v2 += 1; ans = (ans * ct) % MOD; ct--; } } else { if (c == c2) { ans = (ans * (v1 - v2)) % MOD; v2 += 1; } else { v1 += 1; ans = (ans * ct) % MOD; ct--; } } } if (v2 == 0) c2 = 'O'; if (v1 == 0) { if (v2 == 0) c1 = 'O'; else { c1 = c2; v1 = v2; c2 = 'O'; v2 = 0; } } } cout << ans << endl; return 0; }
[ "assignment.value.change" ]
741,941
741,942
u556276145
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string S, T; cin >> S >> T; vector<vector<int>> v(26); int s = S.size(); for (int i = 0; i < s; i++) { v[S[i] - 'a'].push_back(i); v[S[i] - 'a'].push_back(i + s); } for (int i = 0; i < 26; i++) { if (v[i].size() > 3) { sort(v[i].begin(), v[i].end()); } } long long ans = 1, now = 0; for (int i = 0; i < T.size(); i++) { auto itr = upper_bound(v[T[i] - 'a'].begin(), v[T[i] - 'a'].end(), now); if (itr == v[T[i] - 'a'].end()) { ans = -1; break; } else { ans += *itr - now; now = *itr % s; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S, T; cin >> S >> T; vector<vector<int>> v(26); int s = S.size(); for (int i = 0; i < s; i++) { v[S[i] - 'a'].push_back(i); v[S[i] - 'a'].push_back(i + s); } for (int i = 0; i < 26; i++) { if (v[i].size() > 3) { sort(v[i].begin(), v[i].end()); } } long long ans = 0, now = -1; for (int i = 0; i < T.size(); i++) { auto itr = upper_bound(v[T[i] - 'a'].begin(), v[T[i] - 'a'].end(), now); if (itr == v[T[i] - 'a'].end()) { ans = -1; break; } else { ans += *itr - now; now = *itr % s; } } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
742,057
742,058
u275786410
cpp
p02937
#include <bits/stdc++.h> #define ts cout << "ok" << endl #define int long long #define hh puts("") #define pc putchar #define ite vector<int>::iterator //#define getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) char // buf[1<<21],*p1=buf,*p2=buf; using namespace std; int n, m, use, now; char a[100005], b[100005]; vector<int> v[1005]; inline int read() { int ret = 0, ff = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') ff = -ff; ch = getchar(); } while (isdigit(ch)) { ret = (ret << 3) + (ret << 1) + ch - '0'; ch = getchar(); } return ret * ff; } void write(int x) { if (x < 0) { x = -x; putchar('-'); } if (x > 9) write(x / 10); putchar(x % 10 + 48); } signed main() { scanf("%s", a + 1); scanf("%s", b + 1); n = strlen(a + 1); m = strlen(b + 1); for (int i = 1; i <= n; i++) v[a[i] - 'a'].push_back(i); for (int i = 1; i <= m; i++) { if (!v[b[i] - 'a'].size()) { printf("-1"); return 0; } } now = v[b[1] - 'a'][0]; for (int i = 2; i <= m; i++) { ite it = lower_bound(v[b[i] - 'a'].begin(), v[b[i] - 'a'].end(), now); if (it == v[b[i] - 'a'].end()) { use++; now = v[b[i] - 'a'][0]; } else now = *it; } printf("%lld", use * n + now); return 0; }
#include <bits/stdc++.h> #define ts cout << "ok" << endl #define int long long #define hh puts("") #define pc putchar #define ite vector<int>::iterator //#define getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) char // buf[1<<21],*p1=buf,*p2=buf; using namespace std; int n, m, use, now; char a[100005], b[100005]; vector<int> v[1005]; inline int read() { int ret = 0, ff = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') ff = -ff; ch = getchar(); } while (isdigit(ch)) { ret = (ret << 3) + (ret << 1) + ch - '0'; ch = getchar(); } return ret * ff; } void write(int x) { if (x < 0) { x = -x; putchar('-'); } if (x > 9) write(x / 10); putchar(x % 10 + 48); } signed main() { scanf("%s", a + 1); scanf("%s", b + 1); n = strlen(a + 1); m = strlen(b + 1); for (int i = 1; i <= n; i++) v[a[i] - 'a'].push_back(i); for (int i = 1; i <= m; i++) { if (!v[b[i] - 'a'].size()) { printf("-1"); return 0; } } now = v[b[1] - 'a'][0]; for (int i = 2; i <= m; i++) { ite it = upper_bound(v[b[i] - 'a'].begin(), v[b[i] - 'a'].end(), now); if (it == v[b[i] - 'a'].end()) { use++; now = v[b[i] - 'a'][0]; } else now = *it; } printf("%lld", use * n + now); return 0; }
[ "identifier.change", "call.function.change" ]
742,071
742,072
u108577768
cpp
p02937
#include <bits/stdc++.h> #define ts cout << "ok" << endl #define int long long #define hh puts("") #define pc putchar #define ite vector<int>::iterator //#define getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) char // buf[1<<21],*p1=buf,*p2=buf; using namespace std; int n, m, use, now; char a[100005], b[100005]; vector<int> v[1005]; inline int read() { int ret = 0, ff = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') ff = -ff; ch = getchar(); } while (isdigit(ch)) { ret = (ret << 3) + (ret << 1) + ch - '0'; ch = getchar(); } return ret * ff; } void write(int x) { if (x < 0) { x = -x; putchar('-'); } if (x > 9) write(x / 10); putchar(x % 10 + 48); } signed main() { scanf("%s", a + 1); scanf("%s", b + 1); n = strlen(a + 1); m = strlen(b + 1); for (int i = 1; i <= n; i++) v[a[i] - 'a'].push_back(i); for (int i = 1; i <= m; i++) { if (!v[b[i] - 'a'].size()) { printf("-1"); return 0; } } now = v[b[1] - 'a'][0]; for (int i = 2; i <= m; i++) { ite it = lower_bound(v[b[i] - 'a'].begin(), v[b[i] - 'a'].end(), now); if (it == v[b[i] - 'a'].end()) { use++; now = v[b[i] - 'a'][0]; } else now = *it; } printf("%lld", use * n + now); return 0; }
#include <bits/stdc++.h> #define ts cout << "ok" << endl #define int long long #define hh puts("") #define pc putchar #define ite vector<int>::iterator //#define getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) char // buf[1<<21],*p1=buf,*p2=buf; using namespace std; int n, m, use, now; char a[100005], b[100005]; vector<int> v[1005]; inline int read() { int ret = 0, ff = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') ff = -ff; ch = getchar(); } while (isdigit(ch)) { ret = (ret << 3) + (ret << 1) + ch - '0'; ch = getchar(); } return ret * ff; } void write(int x) { if (x < 0) { x = -x; putchar('-'); } if (x > 9) write(x / 10); putchar(x % 10 + 48); } signed main() { scanf("%s", a + 1); scanf("%s", b + 1); n = strlen(a + 1); m = strlen(b + 1); for (int i = 1; i <= n; i++) v[a[i] - 'a'].push_back(i); for (int i = 1; i <= m; i++) { if (!v[b[i] - 'a'].size()) { printf("-1"); return 0; } } now = v[b[1] - 'a'][0]; for (int i = 2; i <= m; i++) { ite it = upper_bound(v[b[i] - 'a'].begin(), v[b[i] - 'a'].end(), now); if (it == v[b[i] - 'a'].end()) { use++; now = v[b[i] - 'a'][0]; } else now = *it; } printf("%lld", use * n + now); return 0; }
[ "identifier.change", "call.function.change" ]
742,071
742,073
u108577768
cpp
p02937
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; const long long LINF = 1e18; #define dump(x) cout << 'x' << ' = ' << (x) << ` `; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) typedef long long ll; using namespace std; typedef pair<ll, ll> P; template <typename T> void print(const vector<T> &x) { int n = x.size(); rep(i, n) { cout << x[i]; if (i != n - 1) cout << " "; else cout << endl; } } template <typename T> void print(const vector<vector<T>> &x) { int n = x.size(); rep(i, n) { rep(j, x[i].size()) { cout << x[i][j] << " "; } cout << endl; } } template <typename T> void print(const vector<T> &x, int n) { rep(i, n) { cout << x[i]; if (i != n - 1) cout << " "; else cout << endl; } } template <typename T> void print(const vector<vector<T>> &x, int n, int m) { rep(i, n) { rep(j, m) { cout << x[i][j] << " "; } cout << endl; } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } void input_init() { cin.tie(0); ios::sync_with_stdio(false); } int main(int argc, char const *argv[]) { string s, t; cin >> s >> t; map<char, vector<int>> mp; int n = s.length(); rep(i, n) { mp[s[i]].push_back(i); } for (char c = 'a'; c <= 'z'; c++) { if (!mp[c].empty()) mp[c].push_back(INF); } int m = t.length(); ll ans = 0; ll cur = 0; rep(i, m) { if (mp[t[i]].empty()) { cout << -1 << '\n'; return 0; } auto itr = lower_bound(mp[t[i]].begin(), mp[t[i]].end(), cur); if (*itr == INF) { ans += n; cur = 0; auto itr2 = lower_bound(mp[t[i]].begin(), mp[t[i]].end(), cur); cur = *itr2; } else { cur = *itr; } } ans += cur + 1; cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; const long long LINF = 1e18; #define dump(x) cout << 'x' << ' = ' << (x) << ` `; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) typedef long long ll; using namespace std; typedef pair<ll, ll> P; template <typename T> void print(const vector<T> &x) { int n = x.size(); rep(i, n) { cout << x[i]; if (i != n - 1) cout << " "; else cout << endl; } } template <typename T> void print(const vector<vector<T>> &x) { int n = x.size(); rep(i, n) { rep(j, x[i].size()) { cout << x[i][j] << " "; } cout << endl; } } template <typename T> void print(const vector<T> &x, int n) { rep(i, n) { cout << x[i]; if (i != n - 1) cout << " "; else cout << endl; } } template <typename T> void print(const vector<vector<T>> &x, int n, int m) { rep(i, n) { rep(j, m) { cout << x[i][j] << " "; } cout << endl; } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } void input_init() { cin.tie(0); ios::sync_with_stdio(false); } int main(int argc, char const *argv[]) { string s, t; cin >> s >> t; map<char, vector<int>> mp; int n = s.length(); rep(i, n) { mp[s[i]].push_back(i + 1); } for (char c = 'a'; c <= 'z'; c++) { if (!mp[c].empty()) mp[c].push_back(INF); } int m = t.length(); ll ans = 0; ll cur = 0; rep(i, m) { if (mp[t[i]].empty()) { cout << -1 << '\n'; return 0; } auto itr = upper_bound(mp[t[i]].begin(), mp[t[i]].end(), cur); if (*itr == INF) { ans += n; cur = 0; auto itr2 = upper_bound(mp[t[i]].begin(), mp[t[i]].end(), cur); cur = *itr2; } else { cur = *itr; } } ans += cur; cout << ans << '\n'; return 0; }
[ "identifier.change", "call.function.change", "expression.operation.binary.remove" ]
742,074
742,075
u102602414
cpp
p02937
#include <algorithm> #include <assert.h> #include <climits> #include <cmath> #include <iostream> #include <queue> #include <unordered_map> #include <vector> using namespace std; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); string s, t; cin >> s >> t; unordered_map<char, vector<int>> idx_map; int slen = (int)s.size(); int tlen = (int)t.size(); for (int i = 0; i < slen; i++) { idx_map[s[i]].push_back(i); } for (int i = 0; i < tlen; i++) { if (idx_map.count(t[i]) == 0) { cout << -1 << endl; return 0; } } int offset = 0; int rep_cnt = 0; for (int i = 0; i < tlen; i++) { char c = t[i]; auto it = upper_bound(idx_map[c].begin(), idx_map[c].end(), offset); if (it == idx_map[c].end()) { rep_cnt++; offset = 0; it = idx_map[c].begin(); } offset = *it; } int64_t res = (int64_t)rep_cnt * slen + offset + 1; cout << res << endl; return 0; }
#include <algorithm> #include <assert.h> #include <climits> #include <cmath> #include <iostream> #include <queue> #include <unordered_map> #include <vector> using namespace std; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); string s, t; cin >> s >> t; unordered_map<char, vector<int>> idx_map; int slen = (int)s.size(); int tlen = (int)t.size(); for (int i = 0; i < slen; i++) { idx_map[s[i]].push_back(i); } for (int i = 0; i < tlen; i++) { if (idx_map.count(t[i]) == 0) { cout << -1 << endl; return 0; } } int offset = -1; int rep_cnt = 0; for (int i = 0; i < tlen; i++) { char c = t[i]; auto it = upper_bound(idx_map[c].begin(), idx_map[c].end(), offset); if (it == idx_map[c].end()) { rep_cnt++; offset = -1; it = idx_map[c].begin(); } offset = *it; } int64_t res = (int64_t)rep_cnt * slen + offset + 1; cout << res << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "assignment.value.change" ]
742,076
742,077
u775900747
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define For(i, n, k) for (ll i = (n); i < (k); i++) #define ALL(a) (a).begin(), (a).end() ll ans = 0; void Main() { string S; cin >> S; string T; cin >> T; string S2 = S + S; vector<vector<int>> alphabet(26); For(i, 0, S2.size()) { alphabet[S2[i] - 'a'].push_back(i); } int p = -1; For(i, 0, T.size()) { auto itr = upper_bound(ALL(alphabet[T[i] - 'a']), p); if (itr == alphabet[T[i] - 'a'].end()) { ans = -1; break; } else { p = (*itr); if (p >= S.size()) { p -= S.size(); ans += S.size(); } } } if (p > -1) ans += p + 1; cout << ans << endl; } int main() { Main(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define For(i, n, k) for (ll i = (n); i < (k); i++) #define ALL(a) (a).begin(), (a).end() ll ans = 0; void Main() { string S; cin >> S; string T; cin >> T; string S2 = S + S; vector<vector<int>> alphabet(26); For(i, 0, S2.size()) { alphabet[S2[i] - 'a'].push_back(i); } int p = -1; For(i, 0, T.size()) { auto itr = upper_bound(ALL(alphabet[T[i] - 'a']), p); if (itr == alphabet[T[i] - 'a'].end()) { ans = -1; break; } else { p = (*itr); if (p >= S.size()) { p -= S.size(); ans += S.size(); } } } if (ans > -1) ans += p + 1; cout << ans << endl; } int main() { Main(); return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
742,080
742,081
u813174766
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); vector<vector<int>> sPos(26); rep(i, n) { int c = s.at(i) - 'a'; sPos.at(c).push_back(i); } rep(i, n) { int c = s.at(i) - 'a'; sPos.at(c).push_back(i + n); } ll ans = 0; int pos = 0; rep(i, m) { int c = t.at(i) - 'a'; if (sPos.at(c).empty()) { cout << -1 << endl; return 0; } else { pos = *upper_bound(sPos.at(c).begin(), sPos.at(c).end(), pos); if (pos >= n) { ans += n; pos -= n; } } } ans += pos + 1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); vector<vector<int>> sPos(26); rep(i, n) { int c = s.at(i) - 'a'; sPos.at(c).push_back(i); } rep(i, n) { int c = s.at(i) - 'a'; sPos.at(c).push_back(i + n); } ll ans = 0; int pos = 0; rep(i, m) { int c = t.at(i) - 'a'; if (sPos.at(c).empty()) { cout << -1 << endl; return 0; } else { pos = *lower_bound(sPos.at(c).begin(), sPos.at(c).end(), pos) + 1; if (pos >= n) { ans += n; pos -= n; } } } ans += pos; cout << ans << endl; return 0; }
[ "assignment.value.change", "identifier.change", "call.function.change", "assignment.change", "expression.operation.binary.remove" ]
742,084
742,085
u048904090
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long #define all(v) v.begin(), v.end() #define f first #define s second #define PB push_back #define MP make_pair #define double long double #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define cases \ int testcases; \ cin >> testcases; \ while (testcases--) #define MOD 998244353 #define N 200005 #define INF 1000000000000 #define eps 1e-6 int arr[26]; set<int> pos[26]; int32_t main() { IOS string s, t; cin >> s >> t; for (int i = 0; i < s.length(); i++) { arr[s[i] - 'a']++; } for (int i = 0; i < t.length(); i++) { if (arr[t[i] - 'a'] == 0) { cout << -1; return 0; } } for (int i = 0; i < s.length(); i++) { pos[s[i] - 'a'].insert(i); } int prev = -1; int ans = 0; for (int i = 0; i < t.length(); i++) { auto it = pos[t[i] - 'a'].lower_bound(prev); if (it == pos[t[i] - 'a'].end()) { it = pos[t[i] - 'a'].begin(); ans += (s.length() - prev + *it); } else { ans += (*it - prev); } prev = *it; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long #define all(v) v.begin(), v.end() #define f first #define s second #define PB push_back #define MP make_pair #define double long double #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define cases \ int testcases; \ cin >> testcases; \ while (testcases--) #define MOD 998244353 #define N 200005 #define INF 1000000000000 #define eps 1e-6 int arr[26]; set<int> pos[26]; int32_t main() { IOS string s, t; cin >> s >> t; for (int i = 0; i < s.length(); i++) { arr[s[i] - 'a']++; } for (int i = 0; i < t.length(); i++) { if (arr[t[i] - 'a'] == 0) { cout << -1; return 0; } } for (int i = 0; i < s.length(); i++) { pos[s[i] - 'a'].insert(i); } int prev = -1; int ans = 0; for (int i = 0; i < t.length(); i++) { auto it = pos[t[i] - 'a'].upper_bound(prev); if (it == pos[t[i] - 'a'].end()) { it = pos[t[i] - 'a'].begin(); ans += (s.length() - prev + *it); // trace1(s.length() - prev + *it); } else { ans += (*it - prev); // trace2(*it,prev); } prev = *it; } cout << ans << endl; return 0; }
[ "call.function.change" ]
742,088
742,089
u021648187
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(), A.end() #define RALL(A) A.rbegin(), A.rend() typedef long long ll; typedef pair<ll, ll> P; const ll mod = 1000000007; const ll LINF = 1LL << 60; const int INF = 1 << 30; int main() { string s, t; cin >> s >> t; set<char> u; for (int i = 0; i < s.size(); i++) { u.insert(s[i]); } for (int i = 0; i < t.size(); i++) { if (u.find(t[i]) == u.end()) { cout << -1 << endl; return 0; } } string s2 = s + s; vector<vector<ll>> a(26); vector<ll> count(26, 1); for (int i = 0; i < s2.size(); i++) { a[s2[i] - 'a'].pb(i); // cout << s2[i] << endl; } // for(int i = 0; i < 26; i++) { // for(int j = 0; j < a[i].size(); j++) { // cout << char('a' + i) <<a[i][j]; // } // cout << endl; // } ll tmp = a[t[0] - 'a'][0]; ll ans = tmp + 1; // 0オリを考慮しますた for (int i = 1; i < t.size(); i++) { auto ite = lower_bound(ALL(a[t[i] - 'a']), tmp); if (*(ite) < s.size()) { ans += (*(ite)-tmp); tmp = *(ite); } else { ans += (*(ite)-tmp); tmp = a[t[i] - 'a'][0]; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(), A.end() #define RALL(A) A.rbegin(), A.rend() typedef long long ll; typedef pair<ll, ll> P; const ll mod = 1000000007; const ll LINF = 1LL << 60; const int INF = 1 << 30; int main() { string s, t; cin >> s >> t; set<char> u; for (int i = 0; i < s.size(); i++) { u.insert(s[i]); } for (int i = 0; i < t.size(); i++) { if (u.find(t[i]) == u.end()) { cout << -1 << endl; return 0; } } string s2 = s + s; vector<vector<ll>> a(26); vector<ll> count(26, 1); for (int i = 0; i < s2.size(); i++) { a[s2[i] - 'a'].pb(i); // cout << s2[i] << endl; } // for(int i = 0; i < 26; i++) { // for(int j = 0; j < a[i].size(); j++) { // cout << char('a' + i) <<a[i][j]; // } // cout << endl; // } ll tmp = a[t[0] - 'a'][0]; ll ans = tmp + 1; // 0オリを考慮しますた for (int i = 1; i < t.size(); i++) { auto ite = upper_bound(ALL(a[t[i] - 'a']), tmp); if (*(ite) < s.size()) { ans += (*(ite)-tmp); tmp = *(ite); } else { ans += (*(ite)-tmp); tmp = a[t[i] - 'a'][0]; } } cout << ans << endl; return 0; }
[ "identifier.change", "call.function.change" ]
742,092
742,093
u471212175
cpp
p02937
#include <bits/stdc++.h> #define PI 3.14159265358979323846 #define MAXINF (1e18L) #define INF (1e9L) #define EPS (1e-9) #define MOD ((ll)(1e9 + 7)) #define REP(i, n) for (int i = 0; i < int(n); ++i) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i) #define ALL(v) v.begin(), v.end() #define FIND(v, x) (binary_search(ALL(v), (x))) #define SORT(v) sort(ALL(v)) #define RSORT(v) \ sort(ALL(v)); \ reverse(ALL(v)) #define DEBUG(x) cerr << #x << ": " << x << endl; #define DEBUG_VEC(v) \ cerr << #v << ":"; \ for (int i = 0; i < v.size(); i++) \ cerr << " " << v[i]; \ cerr << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define pb push_back #define fi first #define se second using namespace std; template <class A> void pr(A a) { cout << (a) << endl; } template <class A, class B> void pr(A a, B b) { cout << a << " "; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << " "; pr(b, c); } template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) { cout << a << " "; pr(b, c, d); } template <class T> inline bool chmin(T &a, T b) { return a > b ? a = b, true : false; } template <class T> inline bool chmax(T &a, T b) { return a < b ? a = b, true : false; } typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main(void) { string s, t; cin >> s >> t; int sn = s.length(); int tn = t.length(); map<char, vector<int>> ms; REP(i, sn) { ms[s[i]].pb(i + 1); } ll ans = 0; ll n = 0; ll id = 0; REP(i, tn) { if (ms[t[i]].size() == 0) { pr(-1); return 0; } auto it = lower_bound(ALL(ms[t[i]]), id); if (it != ms[t[i]].end()) { id = *it; } else { n++; id = ms[t[i]].back(); } } pr(sn * n + id); }
#include <bits/stdc++.h> #define PI 3.14159265358979323846 #define MAXINF (1e18L) #define INF (1e9L) #define EPS (1e-9) #define MOD ((ll)(1e9 + 7)) #define REP(i, n) for (int i = 0; i < int(n); ++i) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i) #define ALL(v) v.begin(), v.end() #define FIND(v, x) (binary_search(ALL(v), (x))) #define SORT(v) sort(ALL(v)) #define RSORT(v) \ sort(ALL(v)); \ reverse(ALL(v)) #define DEBUG(x) cerr << #x << ": " << x << endl; #define DEBUG_VEC(v) \ cerr << #v << ":"; \ for (int i = 0; i < v.size(); i++) \ cerr << " " << v[i]; \ cerr << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define pb push_back #define fi first #define se second using namespace std; template <class A> void pr(A a) { cout << (a) << endl; } template <class A, class B> void pr(A a, B b) { cout << a << " "; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << " "; pr(b, c); } template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) { cout << a << " "; pr(b, c, d); } template <class T> inline bool chmin(T &a, T b) { return a > b ? a = b, true : false; } template <class T> inline bool chmax(T &a, T b) { return a < b ? a = b, true : false; } typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main(void) { string s, t; cin >> s >> t; int sn = s.length(); int tn = t.length(); map<char, vector<int>> ms; REP(i, sn) { ms[s[i]].pb(i + 1); } ll ans = 0; ll n = 0; ll id = 0; REP(i, tn) { if (ms[t[i]].size() == 0) { pr(-1); return 0; } auto it = upper_bound(ALL(ms[t[i]]), id); if (it != ms[t[i]].end()) { id = *it; } else { n++; id = ms[t[i]].front(); } } pr(sn * n + id); }
[ "identifier.change", "call.function.change", "assignment.value.change" ]
742,106
742,105
u528720841
cpp
p02937
#include <bits/stdc++.h> #define PI 3.14159265358979323846 #define MAXINF (1e18L) #define INF (1e9L) #define EPS (1e-9) #define MOD ((ll)(1e9 + 7)) #define REP(i, n) for (int i = 0; i < int(n); ++i) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i) #define ALL(v) v.begin(), v.end() #define FIND(v, x) (binary_search(ALL(v), (x))) #define SORT(v) sort(ALL(v)) #define RSORT(v) \ sort(ALL(v)); \ reverse(ALL(v)) #define DEBUG(x) cerr << #x << ": " << x << endl; #define DEBUG_VEC(v) \ cerr << #v << ":"; \ for (int i = 0; i < v.size(); i++) \ cerr << " " << v[i]; \ cerr << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define pb push_back #define fi first #define se second using namespace std; template <class A> void pr(A a) { cout << (a) << endl; } template <class A, class B> void pr(A a, B b) { cout << a << " "; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << " "; pr(b, c); } template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) { cout << a << " "; pr(b, c, d); } template <class T> inline bool chmin(T &a, T b) { return a > b ? a = b, true : false; } template <class T> inline bool chmax(T &a, T b) { return a < b ? a = b, true : false; } typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main(void) { string s, t; cin >> s >> t; int sn = s.length(); int tn = t.length(); map<char, vector<int>> ms; REP(i, sn) { ms[s[i]].pb(i + 1); } ll ans = 0; int n = 0; int id = 0; REP(i, tn) { if (ms[t[i]].size() == 0) { pr(-1); return 0; } auto it = lower_bound(ALL(ms[t[i]]), id); if (it != ms[t[i]].end()) { id = *it; } else { n++; id = ms[t[i]].back(); } } pr(sn * n + id); }
#include <bits/stdc++.h> #define PI 3.14159265358979323846 #define MAXINF (1e18L) #define INF (1e9L) #define EPS (1e-9) #define MOD ((ll)(1e9 + 7)) #define REP(i, n) for (int i = 0; i < int(n); ++i) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i) #define ALL(v) v.begin(), v.end() #define FIND(v, x) (binary_search(ALL(v), (x))) #define SORT(v) sort(ALL(v)) #define RSORT(v) \ sort(ALL(v)); \ reverse(ALL(v)) #define DEBUG(x) cerr << #x << ": " << x << endl; #define DEBUG_VEC(v) \ cerr << #v << ":"; \ for (int i = 0; i < v.size(); i++) \ cerr << " " << v[i]; \ cerr << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define pb push_back #define fi first #define se second using namespace std; template <class A> void pr(A a) { cout << (a) << endl; } template <class A, class B> void pr(A a, B b) { cout << a << " "; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << " "; pr(b, c); } template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) { cout << a << " "; pr(b, c, d); } template <class T> inline bool chmin(T &a, T b) { return a > b ? a = b, true : false; } template <class T> inline bool chmax(T &a, T b) { return a < b ? a = b, true : false; } typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main(void) { string s, t; cin >> s >> t; int sn = s.length(); int tn = t.length(); map<char, vector<int>> ms; REP(i, sn) { ms[s[i]].pb(i + 1); } ll ans = 0; ll n = 0; ll id = 0; REP(i, tn) { if (ms[t[i]].size() == 0) { pr(-1); return 0; } auto it = upper_bound(ALL(ms[t[i]]), id); if (it != ms[t[i]].end()) { id = *it; } else { n++; id = ms[t[i]].front(); } } pr(sn * n + id); }
[ "variable_declaration.type.change", "identifier.change", "call.function.change", "assignment.value.change" ]
742,107
742,105
u528720841
cpp
p02937
#include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<ll, ll> P; typedef vector<P> vpl; #define rep(i, n) for (ll i = 0; i < (n); i++) #define REP(i, a, b) for (ll i = (a); i < (b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = 1 << 30; const ll linf = 1LL << 62; const int MAX = 2100000; ll dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; ll dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const double pi = acos(-1); template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } template <typename T1, typename T2> inline void print2(T1 a, T2 b) { cout << a << " " << b << endl; } template <typename T1, typename T2, typename T3> inline void print3(T1 a, T2 b, T3 c) { cout << a << " " << b << " " << c << endl; } const int mod = 1e9 + 7; int main() { string s, t; cin >> s >> t; ll n = s.size(); ll m = t.size(); vvl alpha(26); rep(i, n) { alpha[s[i] - 'a'].push_back(i + 1); } ll now = 0; ll ans = 0; rep(i, m) { auto itr = lower_bound(all(alpha[t[i] - 'a']), now); if (alpha[t[i] - 'a'].empty()) { puts("-1"); return 0; } if (itr == alpha[t[i] - 'a'].end()) { ans += n - now; now = alpha[t[i] - 'a'][0]; ans += now; } else { ans += *itr - now; now = *itr; } } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<ll, ll> P; typedef vector<P> vpl; #define rep(i, n) for (ll i = 0; i < (n); i++) #define REP(i, a, b) for (ll i = (a); i < (b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = 1 << 30; const ll linf = 1LL << 62; const int MAX = 2100000; ll dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; ll dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const double pi = acos(-1); template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } template <typename T1, typename T2> inline void print2(T1 a, T2 b) { cout << a << " " << b << endl; } template <typename T1, typename T2, typename T3> inline void print3(T1 a, T2 b, T3 c) { cout << a << " " << b << " " << c << endl; } const int mod = 1e9 + 7; int main() { string s, t; cin >> s >> t; ll n = s.size(); ll m = t.size(); vvl alpha(26); rep(i, n) { alpha[s[i] - 'a'].push_back(i + 1); } ll now = 0; ll ans = 0; rep(i, m) { auto itr = upper_bound(all(alpha[t[i] - 'a']), now); if (alpha[t[i] - 'a'].empty()) { puts("-1"); return 0; } if (itr == alpha[t[i] - 'a'].end()) { ans += n - now; now = alpha[t[i] - 'a'][0]; ans += now; } else { ans += *itr - now; now = *itr; } } cout << ans << endl; }
[ "identifier.change", "call.function.change" ]
742,115
742,116
u242679311
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr); #define sz(a) int((a).size()) #define all(c) (c).begin(), (c).end() #define tr(c, i) for (typeof((c)).begin() i = (c).begin(); i != (c).end(); i++) #define present(c, x) ((c).find(x) != (c).end()) #define cpresent(c, x) (find(all(c), x) != (c).end()) #define what_is(x) cout << #x << " is: " << x << endl; #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define ll long long int #define vi vector<int> #define pii pair<int, int> #define vl vector<ll> #define pll pair<ll, ll> template <typename T> T extgcd(T a, T b, T &x, T &y) { if (b == 0) { x = 1; y = 0; return b; } T x1, y1; T g = extgcd(b, a % b, x1, y1); x = y1; y = x1 - (a / b) * y1; return g; } template <typename T> T fast_power(T a, T b) { T res = (T)1; while (b) { if (b & 1) res = res * a; b >>= 1; a *= a; } return res; } template <typename T> T fast_powerModulo(T a, T b, T M) { T res = (T)1; a %= M; while (b) { if (b & 1) res = (res * a) % M; b >>= 1; a *= a; a %= M; } return res; } template <typename T> T LCM(T a, T b) { T gd = __gcd(a, b); T ml = a * b; return ml / gd; } const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; const int INF = 1 << 30; const ll LINF = 1ll << 60; int main() { FAST string s, t; cin >> s >> t; int n = sz(s); int m = sz(t); vector<vi> ids(26, vi()); for (int i = 0; i < n; ++i) { ids[s[i] - 'a'].push_back(i); } int poss = 1; int pos = 0; int lenid = 0; int cycle = 0; for (int i = 0; i < m; ++i) { if (ids[t[i] - 'a'].empty()) { poss = 0; break; } // check if last char posn is < pos // than inc cycle and lowerbound on pos = 0; if (ids[t[i] - 'a'][sz(ids[t[i] - 'a']) - 1] < pos) { pos = 0; cycle++; } auto it = lower_bound(all(ids[t[i] - 'a']), pos); pos = *it; // cout << i << " " << pos << " " << cycle << '\n'; } if (!poss) { cout << -1 << '\n'; } else { ll ans = 0; ans += 1LL * cycle * n; ans += 1LL * (pos + 1); cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr); #define sz(a) int((a).size()) #define all(c) (c).begin(), (c).end() #define tr(c, i) for (typeof((c)).begin() i = (c).begin(); i != (c).end(); i++) #define present(c, x) ((c).find(x) != (c).end()) #define cpresent(c, x) (find(all(c), x) != (c).end()) #define what_is(x) cout << #x << " is: " << x << endl; #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define ll long long int #define vi vector<int> #define pii pair<int, int> #define vl vector<ll> #define pll pair<ll, ll> template <typename T> T extgcd(T a, T b, T &x, T &y) { if (b == 0) { x = 1; y = 0; return b; } T x1, y1; T g = extgcd(b, a % b, x1, y1); x = y1; y = x1 - (a / b) * y1; return g; } template <typename T> T fast_power(T a, T b) { T res = (T)1; while (b) { if (b & 1) res = res * a; b >>= 1; a *= a; } return res; } template <typename T> T fast_powerModulo(T a, T b, T M) { T res = (T)1; a %= M; while (b) { if (b & 1) res = (res * a) % M; b >>= 1; a *= a; a %= M; } return res; } template <typename T> T LCM(T a, T b) { T gd = __gcd(a, b); T ml = a * b; return ml / gd; } const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; const int INF = 1 << 30; const ll LINF = 1ll << 60; int main() { FAST string s, t; cin >> s >> t; int n = sz(s); int m = sz(t); vector<vi> ids(26, vi()); for (int i = 0; i < n; ++i) { ids[s[i] - 'a'].push_back(i); } int poss = 1; int pos = 0; int lenid = 0; int cycle = 0; for (int i = 0; i < m; ++i) { if (ids[t[i] - 'a'].empty()) { poss = 0; break; } // check if last char posn is < pos // than inc cycle and lowerbound on pos = 0; if (ids[t[i] - 'a'][sz(ids[t[i] - 'a']) - 1] < pos) { pos = 0; cycle++; } auto it = lower_bound(all(ids[t[i] - 'a']), pos); pos = *it + 1; // cout << i << " " << pos << " " << cycle << '\n'; } if (!poss) { cout << -1 << '\n'; } else { ll ans = 0; ans += 1LL * cycle * n; ans += 1LL * (pos); cout << ans << '\n'; } return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
742,119
742,120
u227976892
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } /* attention long longのシフト演算には気をつけよう タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも sizeは(int)とキャストしよう ごちゃごちゃ場合分けを考える前に全探索は考えましたか? */ const ll mod = 1e9 + 7; void chmod(ll &M) { if (M >= mod) M %= mod; else if (M < 0) { M += (abs(M) / mod + 1) * mod; M %= mod; } } int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; int slen = s.length(), tlen = t.length(); vector<bool> mps(30, false); for (int i = 0; i < slen; ++i) mps[s[i] - 'a'] = true; for (int i = 0; i < tlen; ++i) if (mps[t[i] - 'a'] == false) { cout << "-1" << endl; return 0; } s = '0' + s; vector<int> pos[30]; for (int i = 1; i <= slen; ++i) { pos[s[i] - 'a'].push_back(i); } ll ans = 0; ll now = 0; for (int i = 0; i < tlen; ++i) { int c = t[i] - 'a'; auto itr = lower_bound(pos[c].begin(), pos[c].end(), now); if (itr == pos[c].end()) { ans += slen; now = 0; itr = lower_bound(pos[c].begin(), pos[c].end(), now); } now = *itr; if (i == tlen - 1) { cout << ans + now << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } /* attention long longのシフト演算には気をつけよう タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも sizeは(int)とキャストしよう ごちゃごちゃ場合分けを考える前に全探索は考えましたか? */ const ll mod = 1e9 + 7; void chmod(ll &M) { if (M >= mod) M %= mod; else if (M < 0) { M += (abs(M) / mod + 1) * mod; M %= mod; } } int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; int slen = s.length(), tlen = t.length(); vector<bool> mps(30, false); for (int i = 0; i < slen; ++i) mps[s[i] - 'a'] = true; for (int i = 0; i < tlen; ++i) if (mps[t[i] - 'a'] == false) { cout << "-1" << endl; return 0; } s = '0' + s; vector<int> pos[30]; for (int i = 1; i <= slen; ++i) { pos[s[i] - 'a'].push_back(i); } ll ans = 0; ll now = 0; for (int i = 0; i < tlen; ++i) { int c = t[i] - 'a'; auto itr = lower_bound(pos[c].begin(), pos[c].end(), now); if (itr == pos[c].end()) { ans += slen; now = 0; itr = lower_bound(pos[c].begin(), pos[c].end(), now); } now = *itr; if (i == tlen - 1) { cout << ans + now << endl; } else ++now; } return 0; }
[ "control_flow.branch.else_if.replace.remove", "control_flow.branch.if.replace.add", "expression.unary.arithmetic.add" ]
742,124
742,125
u052332717
cpp
p02937
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using VL = vector<ll>; #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) const long long INF = 999999999; ll nx[29][100100]; char ch[26]; ll pos[30]; //次にch[i]が出る文字の位置 // jを今見ている位置とすると // j>=pos[i]となるまではnext[i][j]=pos[i] int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vector<vector<int>> is(26); REP(i, n) is[s[i] - 'a'].push_back(i); REP(i, n) is[s[i] - 'a'].push_back(i + n); ll ans = 0; int p = 0; bool flag = false; REP(i, m) { int c = t[i] - 'a'; if (is[c].size() == 0) { flag = true; break; } p = *upper_bound(is[c].begin(), is[c].end(), p); if (p >= n) { p -= n; ans += n; } } ans += p + 1; cout << (flag ? -1 : ans) << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using VL = vector<ll>; #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) const long long INF = 999999999; ll nx[29][100100]; char ch[26]; ll pos[30]; //次にch[i]が出る文字の位置 // jを今見ている位置とすると // j>=pos[i]となるまではnext[i][j]=pos[i] int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vector<vector<int>> is(26); REP(i, n) is[s[i] - 'a'].push_back(i); REP(i, n) is[s[i] - 'a'].push_back(i + n); ll ans = 0; int p = 0; bool flag = false; REP(i, m) { int c = t[i] - 'a'; if (is[c].size() == 0) { flag = true; break; } p = *lower_bound(is[c].begin(), is[c].end(), p) + 1; if (p >= n) { p -= n; ans += n; } } ans += p; cout << (flag ? -1 : ans) << endl; }
[ "assignment.value.change", "identifier.change", "call.function.change", "assignment.change", "expression.operation.binary.remove" ]
742,126
742,127
u832095504
cpp
p02937
#include <bits/stdc++.h> #include <math.h> #define _GLIBCXX_DEBUG #define _LIBCPP_DEBUG 0 using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define MOD (1000000007) #define vi vector<int> #define vl vector<ll> #define vb vector<bool> #define vvi vector<vi> #define vvl vector<vl> #define pii pair<int, int> #define pli pair<ll, int> a #define pb push_back #define sz(x) int(x.size()) #define mp make_pair #define all(a) (a).begin(), (a).end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll keta(ll n) { string s = to_string(n); ll num = s.size(); return num; } const ll INF = 1LL << 60; const int dh[4] = {1, 0, -1, 0}; const int dw[4] = {0, 1, 0, -1}; struct Edge { int to; int weight; Edge(int t, int w) : to(t), weight(w) {} }; using Graph = vector<vector<Edge>>; using P = pair<ll, int>; class UnionFind { public: vi Parent; UnionFind(int n) { Parent = vi(n, -1); } int root(int a) { if (Parent[a] < 0) return a; else return Parent[a] = root(Parent[a]); } int size(int a) { return -Parent[root(a)]; } bool merge(int a, int b) { a = root(a); b = root(b); if (a == b) return false; if (size(a) < size(b)) swap(a, b); Parent[a] += Parent[b]; Parent[b] = a; return true; } }; class Factrial { public: vl Fac; Factrial(int MAX) { Fac = vl(MAX + 1); rep(i, MAX) { if (i == 0) Fac[i + 1] = 1; else Fac[i + 1] = ((i + 1) * Fac[i]) % MOD; } } }; int main() { string s, t; cin >> s >> t; vvi C(26); int n = sz(s); rep(i, n) C[s[i] - 'a'].pb(i); rep(i, n) C[s[i] - 'a'].pb(i + n); ll ans = 0; int p = -1; rep(i, t.size()) { int c = t[i] - 'a'; if (C[c].empty()) { cout << -1 << endl; return 0; } p = *upper_bound(all(C[c]), p); if (p > n) { p -= n; ans += n; } } cout << ans + p + 1 << endl; }
#include <bits/stdc++.h> #include <math.h> #define _GLIBCXX_DEBUG #define _LIBCPP_DEBUG 0 using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define MOD (1000000007) #define vi vector<int> #define vl vector<ll> #define vb vector<bool> #define vvi vector<vi> #define vvl vector<vl> #define pii pair<int, int> #define pli pair<ll, int> a #define pb push_back #define sz(x) int(x.size()) #define mp make_pair #define all(a) (a).begin(), (a).end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll keta(ll n) { string s = to_string(n); ll num = s.size(); return num; } const ll INF = 1LL << 60; const int dh[4] = {1, 0, -1, 0}; const int dw[4] = {0, 1, 0, -1}; struct Edge { int to; int weight; Edge(int t, int w) : to(t), weight(w) {} }; using Graph = vector<vector<Edge>>; using P = pair<ll, int>; class UnionFind { public: vi Parent; UnionFind(int n) { Parent = vi(n, -1); } int root(int a) { if (Parent[a] < 0) return a; else return Parent[a] = root(Parent[a]); } int size(int a) { return -Parent[root(a)]; } bool merge(int a, int b) { a = root(a); b = root(b); if (a == b) return false; if (size(a) < size(b)) swap(a, b); Parent[a] += Parent[b]; Parent[b] = a; return true; } }; class Factrial { public: vl Fac; Factrial(int MAX) { Fac = vl(MAX + 1); rep(i, MAX) { if (i == 0) Fac[i + 1] = 1; else Fac[i + 1] = ((i + 1) * Fac[i]) % MOD; } } }; int main() { string s, t; cin >> s >> t; vvi C(26); int n = sz(s); rep(i, n) C[s[i] - 'a'].pb(i); rep(i, n) C[s[i] - 'a'].pb(i + n); ll ans = 0; int p = -1; rep(i, t.size()) { int c = t[i] - 'a'; if (C[c].empty()) { cout << -1 << endl; return 0; } p = *upper_bound(all(C[c]), p); if (p >= n) { p -= n; ans += n; } } cout << ans + p + 1 << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
742,128
742,129
u354567428
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define debug(x) \ cout << "DEBUG" \ << " " << #x << ":" << x << '\n' //↓0-originか1-originでn回繰り返し #define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-origin昇順 #define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++) // 1-origin昇順 #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) // 0-origin降順 #define rrep1(i, n) for (int i = ((int)(n)); i >= 1; i--) // 1-origin降順 // rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで #define rep2(i, m, n) for (int i = ((int)(m)); i < ((int)(n)) + ((int)(m)); i++) #define SIZE(x) ((int)((x).size())) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vi> vii; // 2次元配列 typedef vector<ll> vll; typedef vector<string> vs; typedef pair<int, int> PII; template <class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return 1; } return 0; } /* 円周率は M_PI を使おうね */ const ll infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; int mod = 1000000007; /*FUNCs=================================================*/ /*MAIN==================================================*/ signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); // cin cout 高速化 // cout << fixed << setprecision(10); string s, t; cin >> s >> t; ll siz = s.size(); s += s; map<char, vll> chs; // s中の各文字のindexを格納 for (int idx = 0; idx < s.size(); ++idx) { chs[s[idx]].push_back((ll)idx); } // sに無い文字があれば-1 for (auto ch : t) { if (chs.count(ch)) continue; cout << -1 << '\n'; return 0; } // sの中でchが出現するindexに対してにぶたんしてかんがえる ll i = 0; // sss...内での位置 for (auto ch : t) { auto iter = upper_bound(all(chs[ch]), i % siz); ll plus = *iter - i % siz; i += plus; } cout << i + 1 << endl; }
#include <bits/stdc++.h> using namespace std; #define debug(x) \ cout << "DEBUG" \ << " " << #x << ":" << x << '\n' //↓0-originか1-originでn回繰り返し #define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-origin昇順 #define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++) // 1-origin昇順 #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) // 0-origin降順 #define rrep1(i, n) for (int i = ((int)(n)); i >= 1; i--) // 1-origin降順 // rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで #define rep2(i, m, n) for (int i = ((int)(m)); i < ((int)(n)) + ((int)(m)); i++) #define SIZE(x) ((int)((x).size())) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vi> vii; // 2次元配列 typedef vector<ll> vll; typedef vector<string> vs; typedef pair<int, int> PII; template <class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return 1; } return 0; } /* 円周率は M_PI を使おうね */ const ll infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; int mod = 1000000007; /*FUNCs=================================================*/ /*MAIN==================================================*/ signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); // cin cout 高速化 // cout << fixed << setprecision(10); string s, t; cin >> s >> t; ll siz = s.size(); s += s; map<char, vll> chs; // s中の各文字のindexを格納 for (int idx = 0; idx < s.size(); ++idx) { chs[s[idx]].push_back((ll)idx); } // sに無い文字があれば-1 for (auto ch : t) { if (chs.count(ch)) continue; cout << -1 << '\n'; return 0; } // s+s の中で ch が出現する index に対してにぶたんしてかんがえる ll i = 0; // sss...内での位置 for (auto ch : t) { auto iter = lower_bound(all(chs[ch]), i % siz); ll plus = *iter - i % siz + 1; i += plus; } cout << i << endl; }
[ "identifier.change", "call.function.change", "expression.operation.binary.remove" ]
742,138
742,139
u457985479
cpp
p02937
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X)) #define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X)) #define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++) #define all(X) (X).begin(), (X).end() #define sortDecending(X) sort(all(X), greater<ll>()) //降順 #define sortAscending(X) sort(all(X)) //昇順 #define pb push_back #define mp make_pair #define fi first #define sc second #define print(x) cout << x << endl #define printDouble(x) cout << fixed << setprecision(13) << x << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<bool> vb; typedef priority_queue<ll, vl> decendingQueue; //降順 typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順 const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ll INF = 9 * 1e18; const ll MOD = 1e9 + 7; long long gcd(long long m, long long n) { if (m < n) return gcd(n, m); if (n == 0) return m; return gcd(n, m % n); } long long lcm(long long m, long long n) { // m * nでlong型のオーバフローを発生させないため、先に割り算から行う return m * (n / gcd(m, n)); } // a + b + cをprimeで割った値を返す long long addMod(long long a, long long b) { return (a + b) % MOD; } long long minusMod(long long a, long long b) { return (a + MOD - b) % MOD; } long long multipleMod(long long a, long long b) { return (a * b) % MOD; } vector<long long> SieveOfEratosthenes(int max) { vector<long long> sieve; vector<long long> primes; for (int i = 1; i < max + 1; ++i) { sieve.push_back(i); } sieve[0] = 0; for (int i = 2; i < max + 1; ++i) { if (sieve[i - 1] != 0) { primes.push_back(sieve[i - 1]); for (int j = 2 * sieve[i - 1]; j < max + 1; j += sieve[i - 1]) { sieve[j - 1] = 0; } } } return primes; } class Combination { private: vector<long long> fac_; vector<long long> finv_; vector<long long> inv_; long long prime_; public: Combination(long long n, long long prime) { fac_ = vector<long long>(n + 1); finv_ = vector<long long>(n + 1); inv_ = vector<long long>(n + 1); prime_ = prime; fac_[0] = fac_[1] = 1; finv_[0] = finv_[1] = 1; inv_[1] = 1; for (long long i = 2; i <= n; i++) { fac_[i] = fac_[i - 1] * i % prime_; inv_[i] = prime_ - inv_[prime_ % i] * (prime_ / i) % prime_; finv_[i] = finv_[i - 1] * inv_[i] % prime_; } } // nCk long long getCombination(long long n, long long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac_[n] * (finv_[k] * finv_[n - k] % prime_) % prime_; } }; class UnionFindTree { private: vector<int> par; vector<int> rnk; vector<int> siz; public: UnionFindTree(int n) { par.assign(n, -1); rnk.assign(n, -1); siz.assign(n, -1); for (int i = 0; i < n; ++i) { par[i] = i; rnk[i] = 0; siz[i] = 1; } } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; siz[y] += siz[x]; } else { par[y] = x; siz[x] += siz[y]; if (rnk[x] == rnk[y]) ++rnk[x]; } } int size(int x) { x = find(x); return siz[x]; } }; class Edge { public: ll from; ll to; ll cost; Edge() {} Edge(ll from, ll to, ll cost) { this->from = from; this->to = to; this->cost = cost; } bool operator<(const Edge &edge) const { return cost < edge.cost; //昇順 } }; class Graph { public: ll nodes; // ノード数 vector<Edge> edges; Graph() {} Graph(ll nodes) { this->nodes = nodes; } void addEdge(ll from, ll to, ll cost) { this->edges.push_back(Edge(from, to, cost)); } }; // クラスカル法 // 連結グラフの最小全域木を求める class Kruskal { private: Graph graph; vector<Edge> MinimumSpanningTree; ll minimumCost; void searchMinimumSpanningTree() { UnionFindTree uf(graph.nodes); sort(all(graph.edges)); itrep(edge, graph.edges) { if (!uf.same(edge->from, edge->to)) { uf.unite(edge->from, edge->to); MinimumSpanningTree.push_back(*edge); } } } public: Kruskal(Graph graph) { this->graph = graph; } ll getMinimumSpanningTreeCost() { searchMinimumSpanningTree(); ll cost = 0; itrep(it, MinimumSpanningTree) { cost += it->cost; } return cost; } }; // ダイクストラ法 O((E+V)logV) // 最小経路問題を解くためのアルゴリズム。辺の重みに負数を含む場合は利用不可 class Dijkstra { private: Graph graph; map<ll, vector<Edge>> fromPaths; vl distances; vl srcs; public: Dijkstra(Graph graph) { this->graph = graph; itrep(edge, graph.edges) { fromPaths[edge->from].push_back(*edge); fromPaths[edge->to].push_back(Edge(edge->to, edge->from, edge->cost)); } } void searchMinimumPathFrom(ll src) { // 複数回呼ばれる度に計算する this->distances = vl(graph.nodes + 1, INF); this->srcs = vl(graph.nodes + 1, INF); priority_queue<ll> pq; distances[src] = 0; srcs[src] = -1; pq.push(src); while (!pq.empty()) { int u = pq.top(); pq.pop(); itrep(edge, fromPaths[u]) { int v = edge->to; int w = edge->cost; if (distances[v] > distances[u] + w) { distances[v] = distances[u] + w; srcs[v] = u; pq.push(v); } } } }; ll getDistance(ll n) { return this->distances[n]; } ll getFrom(ll n) { return this->srcs[n]; } }; // ベルマンフォード O(|V||E|) // 非負コストが含まれていても最短経路問題を解くためのアルゴリズム。閉路の検出も可能 class BellmanFord { private: Graph graph; // 閉路が含まれるかは個々のノードごとに管理する必要あり vector<bool> hasNegativeCycles; vector<ll> distances; public: BellmanFord(Graph graph) { this->graph = graph; this->distances = vector<ll>(this->graph.nodes + 1, INF); this->hasNegativeCycles = vector<bool>(this->graph.nodes + 1, false); } void searchMinimumPathFrom(ll src) { this->distances[src] = 0; for (ll i = 0; i < graph.nodes - 1; i++) { itrep(edge, graph.edges) { ll u = edge->from; ll v = edge->to; ll w = edge->cost; if (this->distances[u] + w < this->distances[v]) { this->distances[v] = this->distances[u] + w; } } } itrep(edge, graph.edges) { ll u = edge->from; ll v = edge->to; ll w = edge->cost; if (this->distances[u] + w < this->distances[v]) { this->hasNegativeCycles[v] = true; } if (this->hasNegativeCycles[u] == true) { this->hasNegativeCycles[v] = true; } } } ll getDistance(ll n) { return this->distances[n]; } bool hasNegativeCycle(ll n) { return this->hasNegativeCycles[n]; } }; void solve(std::string s, std::string t) { vector<vl> pos(30); rep(i, 0, s.size()) { pos[s[i] - 'a'].push_back(i); } rep(i, 0, 30) { pos[i].push_back(INF); } ll loop = 0; ll npos = 0; rep(i, 0, t.size()) { vl p = pos[t[i] - 'a']; if (p.size() == 1) { print(-1); return; } ll next = *upper_bound(all(p), npos); if (next < s.size()) { npos = next; } else { loop++; npos = p.front(); } } print(loop * s.size() + npos + 1); } int main() { std::string s; std::cin >> s; std::string t; std::cin >> t; solve(s, t); return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X)) #define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X)) #define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++) #define all(X) (X).begin(), (X).end() #define sortDecending(X) sort(all(X), greater<ll>()) //降順 #define sortAscending(X) sort(all(X)) //昇順 #define pb push_back #define mp make_pair #define fi first #define sc second #define print(x) cout << x << endl #define printDouble(x) cout << fixed << setprecision(13) << x << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<bool> vb; typedef priority_queue<ll, vl> decendingQueue; //降順 typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順 const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ll INF = 9 * 1e18; const ll MOD = 1e9 + 7; long long gcd(long long m, long long n) { if (m < n) return gcd(n, m); if (n == 0) return m; return gcd(n, m % n); } long long lcm(long long m, long long n) { // m * nでlong型のオーバフローを発生させないため、先に割り算から行う return m * (n / gcd(m, n)); } // a + b + cをprimeで割った値を返す long long addMod(long long a, long long b) { return (a + b) % MOD; } long long minusMod(long long a, long long b) { return (a + MOD - b) % MOD; } long long multipleMod(long long a, long long b) { return (a * b) % MOD; } vector<long long> SieveOfEratosthenes(int max) { vector<long long> sieve; vector<long long> primes; for (int i = 1; i < max + 1; ++i) { sieve.push_back(i); } sieve[0] = 0; for (int i = 2; i < max + 1; ++i) { if (sieve[i - 1] != 0) { primes.push_back(sieve[i - 1]); for (int j = 2 * sieve[i - 1]; j < max + 1; j += sieve[i - 1]) { sieve[j - 1] = 0; } } } return primes; } class Combination { private: vector<long long> fac_; vector<long long> finv_; vector<long long> inv_; long long prime_; public: Combination(long long n, long long prime) { fac_ = vector<long long>(n + 1); finv_ = vector<long long>(n + 1); inv_ = vector<long long>(n + 1); prime_ = prime; fac_[0] = fac_[1] = 1; finv_[0] = finv_[1] = 1; inv_[1] = 1; for (long long i = 2; i <= n; i++) { fac_[i] = fac_[i - 1] * i % prime_; inv_[i] = prime_ - inv_[prime_ % i] * (prime_ / i) % prime_; finv_[i] = finv_[i - 1] * inv_[i] % prime_; } } // nCk long long getCombination(long long n, long long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac_[n] * (finv_[k] * finv_[n - k] % prime_) % prime_; } }; class UnionFindTree { private: vector<int> par; vector<int> rnk; vector<int> siz; public: UnionFindTree(int n) { par.assign(n, -1); rnk.assign(n, -1); siz.assign(n, -1); for (int i = 0; i < n; ++i) { par[i] = i; rnk[i] = 0; siz[i] = 1; } } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; siz[y] += siz[x]; } else { par[y] = x; siz[x] += siz[y]; if (rnk[x] == rnk[y]) ++rnk[x]; } } int size(int x) { x = find(x); return siz[x]; } }; class Edge { public: ll from; ll to; ll cost; Edge() {} Edge(ll from, ll to, ll cost) { this->from = from; this->to = to; this->cost = cost; } bool operator<(const Edge &edge) const { return cost < edge.cost; //昇順 } }; class Graph { public: ll nodes; // ノード数 vector<Edge> edges; Graph() {} Graph(ll nodes) { this->nodes = nodes; } void addEdge(ll from, ll to, ll cost) { this->edges.push_back(Edge(from, to, cost)); } }; // クラスカル法 // 連結グラフの最小全域木を求める class Kruskal { private: Graph graph; vector<Edge> MinimumSpanningTree; ll minimumCost; void searchMinimumSpanningTree() { UnionFindTree uf(graph.nodes); sort(all(graph.edges)); itrep(edge, graph.edges) { if (!uf.same(edge->from, edge->to)) { uf.unite(edge->from, edge->to); MinimumSpanningTree.push_back(*edge); } } } public: Kruskal(Graph graph) { this->graph = graph; } ll getMinimumSpanningTreeCost() { searchMinimumSpanningTree(); ll cost = 0; itrep(it, MinimumSpanningTree) { cost += it->cost; } return cost; } }; // ダイクストラ法 O((E+V)logV) // 最小経路問題を解くためのアルゴリズム。辺の重みに負数を含む場合は利用不可 class Dijkstra { private: Graph graph; map<ll, vector<Edge>> fromPaths; vl distances; vl srcs; public: Dijkstra(Graph graph) { this->graph = graph; itrep(edge, graph.edges) { fromPaths[edge->from].push_back(*edge); fromPaths[edge->to].push_back(Edge(edge->to, edge->from, edge->cost)); } } void searchMinimumPathFrom(ll src) { // 複数回呼ばれる度に計算する this->distances = vl(graph.nodes + 1, INF); this->srcs = vl(graph.nodes + 1, INF); priority_queue<ll> pq; distances[src] = 0; srcs[src] = -1; pq.push(src); while (!pq.empty()) { int u = pq.top(); pq.pop(); itrep(edge, fromPaths[u]) { int v = edge->to; int w = edge->cost; if (distances[v] > distances[u] + w) { distances[v] = distances[u] + w; srcs[v] = u; pq.push(v); } } } }; ll getDistance(ll n) { return this->distances[n]; } ll getFrom(ll n) { return this->srcs[n]; } }; // ベルマンフォード O(|V||E|) // 非負コストが含まれていても最短経路問題を解くためのアルゴリズム。閉路の検出も可能 class BellmanFord { private: Graph graph; // 閉路が含まれるかは個々のノードごとに管理する必要あり vector<bool> hasNegativeCycles; vector<ll> distances; public: BellmanFord(Graph graph) { this->graph = graph; this->distances = vector<ll>(this->graph.nodes + 1, INF); this->hasNegativeCycles = vector<bool>(this->graph.nodes + 1, false); } void searchMinimumPathFrom(ll src) { this->distances[src] = 0; for (ll i = 0; i < graph.nodes - 1; i++) { itrep(edge, graph.edges) { ll u = edge->from; ll v = edge->to; ll w = edge->cost; if (this->distances[u] + w < this->distances[v]) { this->distances[v] = this->distances[u] + w; } } } itrep(edge, graph.edges) { ll u = edge->from; ll v = edge->to; ll w = edge->cost; if (this->distances[u] + w < this->distances[v]) { this->hasNegativeCycles[v] = true; } if (this->hasNegativeCycles[u] == true) { this->hasNegativeCycles[v] = true; } } } ll getDistance(ll n) { return this->distances[n]; } bool hasNegativeCycle(ll n) { return this->hasNegativeCycles[n]; } }; void solve(std::string s, std::string t) { vector<vl> pos(26); rep(i, 0, s.size()) { pos[s[i] - 'a'].push_back(i); } rep(i, 0, 26) { pos[i].push_back(INF); } ll loop = 0; ll npos = -1; rep(i, 0, t.size()) { // vl p = pos[t[i] - 'a']; // TLEになる vl &p = pos[t[i] - 'a']; // 参照渡し if (p.size() == 1) { print(-1); return; } ll next = *upper_bound(all(p), npos); if (next < s.size()) { npos = next; } else { loop++; npos = p.front(); } } print(loop * s.size() + npos + 1); } int main() { std::string s; std::cin >> s; std::string t; std::cin >> t; solve(s, t); return 0; }
[ "literal.number.change", "call.arguments.change", "variable_declaration.value.change" ]
742,143
742,141
u925940521
cpp
p02937
#include <bits/stdc++.h> #ifdef _DEBUG #define debug(x) \ cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x \ << " = " << x << endl #else #define debug(x) #endif #define all(s) begin(s), end(s) #define rall(s) rbegin(s), rend(s) #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--) #define pb push_back #define sz(a) int((a).size()) #define put(a) ((cout) << (a) << (endl)) #define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl)) #define deg2rad(x) (((x)*PI) / (180.0)) #define rad2deg(x) (((x) * (180.0)) / PI) #define fi first #define se second using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using i_i = pair<int, int>; using ll_ll = pair<ll, ll>; using d_ll = pair<double, ll>; using ll_d = pair<ll, double>; using d_d = pair<double, double>; template <class T> using vec = vector<T>; static constexpr ll LL_INF = 1LL << 60; static constexpr int I_INF = 1 << 28; static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288); static constexpr double EPS = numeric_limits<double>::epsilon(); static map<type_index, const char *const> scanType = {{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}}; template <class T> static void scan(vector<T> &v); [[maybe_unused]] static void scan(vector<string> &v, bool isWord = true); template <class T> static inline bool chmax(T &a, T b); template <class T> static inline bool chmin(T &a, T b); template <class T> static inline T gcd(T a, T b); template <class T> static inline T lcm(T a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); template <class T> T mod(T a, T m); int main(int argc, char *argv[]) { string s, t; cin >> s >> t; int orig_s = sz(s); s += s; unordered_map<char, vec<int>> cnt; rep(i, 0, sz(s)) cnt[s[i]].pb(i); ll loop = 0; int index = 0; rep(i, 0, sz(t)) { char c = t[i]; if (sz(cnt[c]) == 0) { put(-1); return 0; } index = *lower_bound(all(cnt[c]), index); if (index >= orig_s) { loop++; index -= orig_s; } } put(loop * orig_s + index + 1); return 0; } template <class T> static void scan(vector<T> &v) { auto tFormat = scanType[typeid(T)]; for (T &n : v) { scanf(tFormat, &n); } } static void scan(vector<string> &v, bool isWord) { if (isWord) { for (auto &n : v) { cin >> n; } return; } int i = 0, size = v.size(); string s; getline(cin, s); if (s.size() != 0) { i++; v[0] = s; } for (; i < size; ++i) { getline(cin, v[i]); } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); }
#include <bits/stdc++.h> #ifdef _DEBUG #define debug(x) \ cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x \ << " = " << x << endl #else #define debug(x) #endif #define all(s) begin(s), end(s) #define rall(s) rbegin(s), rend(s) #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--) #define pb push_back #define sz(a) int((a).size()) #define put(a) ((cout) << (a) << (endl)) #define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl)) #define deg2rad(x) (((x)*PI) / (180.0)) #define rad2deg(x) (((x) * (180.0)) / PI) #define fi first #define se second using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using i_i = pair<int, int>; using ll_ll = pair<ll, ll>; using d_ll = pair<double, ll>; using ll_d = pair<ll, double>; using d_d = pair<double, double>; template <class T> using vec = vector<T>; static constexpr ll LL_INF = 1LL << 60; static constexpr int I_INF = 1 << 28; static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288); static constexpr double EPS = numeric_limits<double>::epsilon(); static map<type_index, const char *const> scanType = {{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}}; template <class T> static void scan(vector<T> &v); [[maybe_unused]] static void scan(vector<string> &v, bool isWord = true); template <class T> static inline bool chmax(T &a, T b); template <class T> static inline bool chmin(T &a, T b); template <class T> static inline T gcd(T a, T b); template <class T> static inline T lcm(T a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); template <class T> T mod(T a, T m); int main(int argc, char *argv[]) { string s, t; cin >> s >> t; int orig_s = sz(s); s += s; unordered_map<char, vec<int>> cnt; rep(i, 0, sz(s)) cnt[s[i]].pb(i); ll loop = 0; int index = -1; rep(i, 0, sz(t)) { char c = t[i]; if (sz(cnt[c]) == 0) { put(-1); return 0; } index = *upper_bound(all(cnt[c]), index); if (index >= orig_s) { loop++; index -= orig_s; } } put(loop * orig_s + index + 1); return 0; } template <class T> static void scan(vector<T> &v) { auto tFormat = scanType[typeid(T)]; for (T &n : v) { scanf(tFormat, &n); } } static void scan(vector<string> &v, bool isWord) { if (isWord) { for (auto &n : v) { cin >> n; } return; } int i = 0, size = v.size(); string s; getline(cin, s); if (s.size() != 0) { i++; v[0] = s; } for (; i < size; ++i) { getline(cin, v[i]); } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); }
[ "literal.number.change", "variable_declaration.value.change", "assignment.value.change", "identifier.change", "call.function.change" ]
742,146
742,147
u209647862
cpp
p02937
#include <bits/stdc++.h> #ifdef _DEBUG #define debug(x) \ cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x \ << " = " << x << endl #define INFILE freopen("input.txt", "r", stdin) #else #define debug(x) #define INFILE #endif #define ALL(s) begin(s), end(s) #define RALL(s) rbegin(s), rend(s) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define RREP(i, a, b) for (int i = (a); i >= (b); i--) using namespace std; using ll = long long; using ull = unsigned long long; using i_i = pair<int, int>; using ll_ll = pair<ll, ll>; using d_ll = pair<double, ll>; using ll_d = pair<ll, double>; using d_d = pair<double, double>; static constexpr ll INF = 1LL << 60; static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288); static constexpr double EPS = numeric_limits<double>::epsilon(); static map<type_index, const char *const> scanType = {{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}}; template <class T> static void scan(vector<T> &v); [[maybe_unused]] static void scan(vector<string> &v, bool isWord = true); template <class T> static inline bool chmax(T &a, T b); template <class T> static inline bool chmin(T &a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); int indexes[100010][26]; int f_indexes[26]; int checked[26][26]; vector<int> index_list[26]; int main(int argc, char *argv[]) { string s, t; cin >> s >> t; for (int &index : f_indexes) { index = -1; } Fill(indexes, int(-1)); REP(i, 0, s.size()) { int index = s[i] - 'a'; f_indexes[index] = f_indexes[index] == -1 ? i : f_indexes[index]; REP(j, 0, 26) { REP(k, checked[j][index], index_list[j].size()) { indexes[index_list[j][k]][index] = i; } checked[j][index] = index_list[j].size(); } index_list[index].push_back(i); } int cur_index = f_indexes[t[0] - 'a']; ll result = cur_index + 1; if (cur_index == -1) { cout << -1 << endl; return 0; } REP(i, 1, t.size()) { int index = t[i] - 'a'; if (indexes[cur_index][index] == -1) { result += s.size() - cur_index - 1; cur_index = f_indexes[index]; result += cur_index + 1; if (cur_index == -1) { cerr << -1 << endl; return 0; } continue; } int diff = indexes[cur_index][index] - cur_index; result += diff; cur_index = indexes[cur_index][index]; } cout << result << endl; // REP(i, 0, 26) { // cerr << "t -> " << string(1, 'a' + i) << ": "; // cerr << indexes[3][i]; // cerr << endl; // } return 0; } template <class T> static void scan(vector<T> &v) { auto tFormat = scanType[typeid(T)]; for (T &n : v) { scanf(tFormat, &n); } } static void scan(vector<string> &v, bool isWord) { if (isWord) { for (auto &n : v) { cin >> n; } return; } int i = 0, size = v.size(); string s; getline(cin, s); if (s.size() != 0) { i++; v[0] = s; } for (; i < size; ++i) { getline(cin, v[i]); } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); }
#include <bits/stdc++.h> #ifdef _DEBUG #define debug(x) \ cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x \ << " = " << x << endl #define INFILE freopen("input.txt", "r", stdin) #else #define debug(x) #define INFILE #endif #define ALL(s) begin(s), end(s) #define RALL(s) rbegin(s), rend(s) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define RREP(i, a, b) for (int i = (a); i >= (b); i--) using namespace std; using ll = long long; using ull = unsigned long long; using i_i = pair<int, int>; using ll_ll = pair<ll, ll>; using d_ll = pair<double, ll>; using ll_d = pair<ll, double>; using d_d = pair<double, double>; static constexpr ll INF = 1LL << 60; static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288); static constexpr double EPS = numeric_limits<double>::epsilon(); static map<type_index, const char *const> scanType = {{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}}; template <class T> static void scan(vector<T> &v); [[maybe_unused]] static void scan(vector<string> &v, bool isWord = true); template <class T> static inline bool chmax(T &a, T b); template <class T> static inline bool chmin(T &a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); int indexes[100010][26]; int f_indexes[26]; int checked[26][26]; vector<int> index_list[26]; int main(int argc, char *argv[]) { string s, t; cin >> s >> t; for (int &index : f_indexes) { index = -1; } Fill(indexes, int(-1)); REP(i, 0, s.size()) { int index = s[i] - 'a'; f_indexes[index] = f_indexes[index] == -1 ? i : f_indexes[index]; REP(j, 0, 26) { REP(k, checked[j][index], index_list[j].size()) { indexes[index_list[j][k]][index] = i; } checked[j][index] = index_list[j].size(); } index_list[index].push_back(i); } int cur_index = f_indexes[t[0] - 'a']; ll result = cur_index + 1; if (cur_index == -1) { cout << -1 << endl; return 0; } REP(i, 1, t.size()) { int index = t[i] - 'a'; if (indexes[cur_index][index] == -1) { result += s.size() - cur_index - 1; cur_index = f_indexes[index]; result += cur_index + 1; if (cur_index == -1) { cout << -1 << endl; return 0; } continue; } int diff = indexes[cur_index][index] - cur_index; result += diff; cur_index = indexes[cur_index][index]; } cout << result << endl; return 0; } template <class T> static void scan(vector<T> &v) { auto tFormat = scanType[typeid(T)]; for (T &n : v) { scanf(tFormat, &n); } } static void scan(vector<string> &v, bool isWord) { if (isWord) { for (auto &n : v) { cin >> n; } return; } int i = 0, size = v.size(); string s; getline(cin, s); if (s.size() != 0) { i++; v[0] = s; } for (; i < size; ++i) { getline(cin, v[i]); } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); }
[ "identifier.change", "io.output.change" ]
742,148
742,149
u209647862
cpp
p02937
#include <bits/stdc++.h> #ifdef _DEBUG #define debug(x) \ cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x \ << " = " << x << endl #define INFILE freopen("input.txt", "r", stdin) #else #define debug(x) #define INFILE #endif #define ALL(s) begin(s), end(s) #define RALL(s) rbegin(s), rend(s) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define RREP(i, a, b) for (int i = (a); i >= (b); i--) using namespace std; using ll = long long; using ull = unsigned long long; using i_i = pair<int, int>; using ll_ll = pair<ll, ll>; using d_ll = pair<double, ll>; using ll_d = pair<ll, double>; using d_d = pair<double, double>; static constexpr ll INF = 1LL << 60; static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288); static constexpr double EPS = numeric_limits<double>::epsilon(); static map<type_index, const char *const> scanType = {{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}}; template <class T> static void scan(vector<T> &v); [[maybe_unused]] static void scan(vector<string> &v, bool isWord = true); template <class T> static inline bool chmax(T &a, T b); template <class T> static inline bool chmin(T &a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); int indexes[100010][26]; int f_indexes[26]; int checked[26][26]; vector<int> index_list[26]; int main(int argc, char *argv[]) { string s, t; cin >> s >> t; for (int &index : f_indexes) { index = -1; } Fill(indexes, int(-1)); REP(i, 0, s.size()) { int index = s[i] - 'a'; f_indexes[index] = f_indexes[index] == -1 ? i : f_indexes[index]; REP(j, 0, 26) { REP(k, checked[j][index], index_list[j].size()) { indexes[index_list[j][k]][index] = i; } checked[j][index] = index_list[j].size(); } index_list[index].push_back(i); } int cur_index = f_indexes[t[0] - 'a']; ll result = cur_index + 1; if (cur_index == -1) { cout << -1 << endl; return 0; } REP(i, 1, t.size()) { int index = t[i] - 'a'; if (indexes[cur_index][index] == -1) { result += s.size() - cur_index - 1; cur_index = f_indexes[index]; result += cur_index + 1; if (cur_index == -1) { cerr << -1 << endl; return 0; } continue; } int diff = indexes[cur_index][index] - cur_index; result += diff; cur_index = indexes[cur_index][index]; } cout << result << endl; // REP(i, 0, 26) { // cerr << "t -> " << string(1, 'a' + i) << ": "; // cerr << indexes[3][i]; // cerr << endl; // } return 0; } template <class T> static void scan(vector<T> &v) { auto tFormat = scanType[typeid(T)]; for (T &n : v) { scanf(tFormat, &n); } } static void scan(vector<string> &v, bool isWord) { if (isWord) { for (auto &n : v) { cin >> n; } return; } int i = 0, size = v.size(); string s; getline(cin, s); if (s.size() != 0) { i++; v[0] = s; } for (; i < size; ++i) { getline(cin, v[i]); } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); }
#include <bits/stdc++.h> #ifdef _DEBUG #define debug(x) \ cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x \ << " = " << x << endl #define INFILE freopen("input.txt", "r", stdin) #else #define debug(x) #define INFILE #endif #define ALL(s) begin(s), end(s) #define RALL(s) rbegin(s), rend(s) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define RREP(i, a, b) for (int i = (a); i >= (b); i--) using namespace std; using ll = long long; using ull = unsigned long long; using i_i = pair<int, int>; using ll_ll = pair<ll, ll>; using d_ll = pair<double, ll>; using ll_d = pair<ll, double>; using d_d = pair<double, double>; static constexpr ll INF = 1LL << 60; static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288); static constexpr double EPS = numeric_limits<double>::epsilon(); static map<type_index, const char *const> scanType = {{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}}; template <class T> static void scan(vector<T> &v); [[maybe_unused]] static void scan(vector<string> &v, bool isWord = true); template <class T> static inline bool chmax(T &a, T b); template <class T> static inline bool chmin(T &a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); int indexes[100010][26]; int f_indexes[26]; int checked[26][26]; vector<int> index_list[26]; int main(int argc, char *argv[]) { string s, t; cin >> s >> t; for (int &index : f_indexes) { index = -1; } Fill(indexes, int(-1)); REP(i, 0, s.size()) { int index = s[i] - 'a'; f_indexes[index] = f_indexes[index] == -1 ? i : f_indexes[index]; REP(j, 0, 26) { REP(k, checked[j][index], index_list[j].size()) { indexes[index_list[j][k]][index] = i; } checked[j][index] = index_list[j].size(); } index_list[index].push_back(i); } int cur_index = f_indexes[t[0] - 'a']; ll result = cur_index + 1; if (cur_index == -1) { cout << -1 << endl; return 0; } REP(i, 1, t.size()) { int index = t[i] - 'a'; if (indexes[cur_index][index] == -1) { result += s.size() - cur_index - 1; cur_index = f_indexes[index]; result += cur_index + 1; if (cur_index == -1) { cout << -1 << endl; return 0; } continue; } int diff = indexes[cur_index][index] - cur_index; result += diff; cur_index = indexes[cur_index][index]; } cout << result << endl; // REP(i, 0, 26) { // cerr << "t -> " << string(1, 'a' + i) << ": "; // cerr << indexes[3][i]; // cerr << endl; // } return 0; } template <class T> static void scan(vector<T> &v) { auto tFormat = scanType[typeid(T)]; for (T &n : v) { scanf(tFormat, &n); } } static void scan(vector<string> &v, bool isWord) { if (isWord) { for (auto &n : v) { cin >> n; } return; } int i = 0, size = v.size(); string s; getline(cin, s); if (s.size() != 0) { i++; v[0] = s; } for (; i < size; ++i) { getline(cin, v[i]); } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); }
[ "identifier.change", "io.output.change" ]
742,148
742,151
u209647862
cpp
p02937
#include <bits/stdc++.h> #define int long long using namespace std; const int INF = 1e14; const int ZERO = 0; const int MOD = 1000000007; const double PI = 3.1415926535897; typedef pair<int, int> P; signed main() { string S, T; cin >> S >> T; vector<int> s[26]; for (int i = 0; i < S.size(); i++) { s[S.at(i) - 'a'].push_back(i); } int ret = 0; for (int i = 0; i < T.size(); i++) { int A = T.at(i) - 'a'; if (s[A].empty()) { cout << -1 << endl; return 0; } int cnt = ret / S.size() * S.size(); int cnt2 = ret % S.size(); auto itr = upper_bound(s[A].begin(), s[A].end(), cnt2); int cnt3 = itr - s[A].begin(); if (cnt3 == s[A].size()) { ret = cnt + S.size() + s[A].at(0); } else { ret = cnt + s[A].at(cnt3); } } cout << ret + 1 << endl; }
#include <bits/stdc++.h> #define int long long using namespace std; const int INF = 1e14; const int ZERO = 0; const int MOD = 1000000007; const double PI = 3.1415926535897; typedef pair<int, int> P; signed main() { string S, T; cin >> S >> T; vector<int> s[26]; for (int i = 0; i < S.size(); i++) { s[S.at(i) - 'a'].push_back(i + 1); } int ret = 0; for (int i = 0; i < T.size(); i++) { int A = T.at(i) - 'a'; if (s[A].empty()) { cout << -1 << endl; return 0; } int cnt = ret / S.size() * S.size(); int cnt2 = ret % S.size(); auto itr = upper_bound(s[A].begin(), s[A].end(), cnt2); int cnt3 = itr - s[A].begin(); if (cnt3 == s[A].size()) { ret = cnt + S.size() + s[A].at(0); } else { ret = cnt + s[A].at(cnt3); } } cout << ret << endl; }
[ "expression.operation.binary.remove" ]
742,159
742,160
u322714721
cpp
p02937
#include <bits/stdc++.h> using namespace std; set<int> pos[128]; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) pos[s[i]].insert(i + 1); string t; cin >> t; long long p = 0; long long cnt = 0; for (char c : t) { if (pos[c].empty()) { cout << -1 << endl; return 0; } auto it = pos[c].lower_bound(p); if (it == pos[c].end()) { p = *pos[c].begin(); cnt++; } else { p = *it; } } cout << (cnt * s.size() + p) << endl; }
#include <bits/stdc++.h> using namespace std; set<int> pos[128]; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) pos[s[i]].insert(i + 1); string t; cin >> t; long long p = 0; long long cnt = 0; for (char c : t) { if (pos[c].empty()) { cout << -1 << endl; return 0; } auto it = pos[c].lower_bound(p + 1); if (it == pos[c].end()) { p = *pos[c].begin(); cnt++; } else { p = *it; } } cout << (cnt * s.size() + p) << endl; }
[ "assignment.change" ]
742,164
742,165
u729337236
cpp
p02937
#include <iostream> #include <vector> using namespace std; string s, t; int main() { cin >> s; cin >> t; string s_double = s + s; vector<int> chr_idx[26]; for (int i = 0; i < s_double.size(); i++) { chr_idx[s_double[i] - 'a'].push_back(i); } long long rep = 0, resid = 0; for (int i = 0; i < t.size(); i++) { auto itr = lower_bound(chr_idx[t[i] - 'a'].begin(), chr_idx[t[i] - 'a'].end(), resid); if (itr == chr_idx[t[i] - 'a'].end()) { cout << -1 << endl; return 0; } resid = *itr; if (resid >= s.size()) { resid -= s.size(); rep++; } } cout << 1LL * s.size() * rep + resid + 1 << endl; }
#include <iostream> #include <vector> using namespace std; string s, t; int main() { cin >> s; cin >> t; string s_double = s + s; vector<int> chr_idx[26]; for (int i = 0; i < s_double.size(); i++) { chr_idx[s_double[i] - 'a'].push_back(i); } long long rep = 0, resid = 0; for (int i = 0; i < t.size(); i++) { auto itr = lower_bound(chr_idx[t[i] - 'a'].begin(), chr_idx[t[i] - 'a'].end(), resid); if (itr == chr_idx[t[i] - 'a'].end()) { cout << -1 << endl; return 0; } resid = *itr + 1; if (resid >= s.size()) { resid -= s.size(); rep++; } } cout << 1LL * s.size() * rep + resid << endl; }
[ "assignment.change", "expression.operation.binary.remove" ]
742,166
742,167
u425351967
cpp
p02937
#include <algorithm> #include <cmath> #include <complex> #include <cstdlib> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using Int = long long; Int INF = 1LL << 60; const Int MOD = 1000000000 + 7; template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " "); return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &st) { for (const auto &e : st) os << e << " "; return os; } template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T1, class T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (const auto &e : mp) os << e << " "; return os; } #ifdef _DEBUG template <class T> void dump(const char *str, T &&h) { cerr << str << " = " << h << "\n"; }; template <class Head, class... Tail> void dump(const char *str, Head &&h, Tail &&...t) { while (*str != ',') cerr << *str++; cerr << " = " << h << "\n"; dump(str + (*(str + 1) == ' ' ? 2 : 1), t...); } #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif string s, t; Int lens, lent; vector<vector<Int>> calcNext(const string &S) { // int n = (int)S.size(); vector<vector<Int>> res(lens + 1, vector<Int>(26, lens)); for (int i = lens - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j]; res[i][S[i] - 'a'] = i; } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> s >> t; lens = s.size(); lent = t.size(); // next[i][c]: = S の i 文字目以降で最初に文字 c が登場する index vector<vector<Int>> next = calcNext(s); // DMP(next); Int temp1 = 0; //丸何セットあるか Int temp2 = 0; //何番目か Int tempc; for (Int i = 0; i < lent; i++) { tempc = t[i] - 'a'; if (next[0][tempc] == lens) { // t中の文字が存在しない場合 cout << -1 << "\n"; return 0; } ////if (i != lent - 1) { // if (temp2 == lens - 1) { // temp1++; // temp2 = -1; // } ////} temp2 = next[temp2 + 1][tempc]; if (temp2 == lens) { temp1++; temp2 = next[0][tempc]; } } Int ans = temp1 * lens + temp2 + 1; cout << ans << "\n"; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdlib> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using Int = long long; Int INF = 1LL << 60; const Int MOD = 1000000000 + 7; template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " "); return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &st) { for (const auto &e : st) os << e << " "; return os; } template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T1, class T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (const auto &e : mp) os << e << " "; return os; } #ifdef _DEBUG template <class T> void dump(const char *str, T &&h) { cerr << str << " = " << h << "\n"; }; template <class Head, class... Tail> void dump(const char *str, Head &&h, Tail &&...t) { while (*str != ',') cerr << *str++; cerr << " = " << h << "\n"; dump(str + (*(str + 1) == ' ' ? 2 : 1), t...); } #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif string s, t; Int lens, lent; vector<vector<Int>> calcNext(const string &S) { // int n = (int)S.size(); vector<vector<Int>> res(lens + 1, vector<Int>(26, lens)); for (int i = lens - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j]; res[i][S[i] - 'a'] = i; } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> s >> t; lens = s.size(); lent = t.size(); // next[i][c]: = S の i 文字目以降で最初に文字 c が登場する index vector<vector<Int>> next = calcNext(s); // DMP(next); Int temp1 = 0; //丸何セットあるか Int temp2 = -1; //何番目か Int tempc; for (Int i = 0; i < lent; i++) { tempc = t[i] - 'a'; if (next[0][tempc] == lens) { // t中の文字が存在しない場合 cout << -1 << "\n"; return 0; } ////if (i != lent - 1) { // if (temp2 == lens - 1) { // temp1++; // temp2 = -1; // } ////} temp2 = next[temp2 + 1][tempc]; if (temp2 == lens) { temp1++; temp2 = next[0][tempc]; } } Int ans = temp1 * lens + temp2 + 1; cout << ans << "\n"; }
[ "literal.number.change", "variable_declaration.value.change" ]
742,170
742,171
u612271542
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define int long long // typedef pair<int, int> P; #define mod 1000000007 #define INF (1LL << 60) #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define YES puts("YES") #define Yes puts("Yes") #define NO puts("NO") #define No puts("No") int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; #if 1 //------------- // DUMPマクロ // https://www.creativ.xyz/dump-cpp-652/ // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif #endif // res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n) vector<vector<int>> calcNext(const string &S) { int n = (int)S.size(); vector<vector<int>> res(n + 1, vector<int>(26, n)); for (int i = n - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j]; res[i][S[i] - 'a'] = i + 1; } return res; } signed main() { string s, t; cin >> s >> t; int N = s.size(); string ss = s + s; int NN = ss.size(); vector<vector<int>> v = calcNext(ss); int now = 0, prev_idx = 0; int next_idx; rep(i, t.size()) { next_idx = v[prev_idx][t[i] - 'a']; dump(t[i], next_idx, prev_idx); if (next_idx == NN) { cout << -1 << endl; return 0; } now += next_idx - prev_idx; prev_idx = next_idx % N; } cout << now + 1 << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long // typedef pair<int, int> P; #define mod 1000000007 #define INF (1LL << 60) #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) #define YES puts("YES") #define Yes puts("Yes") #define NO puts("NO") #define No puts("No") int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; #if 1 //------------- // DUMPマクロ // https://www.creativ.xyz/dump-cpp-652/ // vector template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } // pair template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif #endif // res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n) vector<vector<int>> calcNext(const string &S) { int n = (int)S.size(); vector<vector<int>> res(n + 1, vector<int>(26, n)); for (int i = n - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j]; res[i][S[i] - 'a'] = i + 1; } return res; } signed main() { string s, t; cin >> s >> t; int N = s.size(); string ss = s + s; int NN = ss.size(); vector<vector<int>> v = calcNext(ss); int now = 0, prev_idx = 0; int next_idx; rep(i, t.size()) { next_idx = v[prev_idx][t[i] - 'a']; dump(t[i], next_idx, prev_idx); if (next_idx == NN) { cout << -1 << endl; return 0; } now += next_idx - prev_idx; prev_idx = next_idx % N; } cout << now << endl; }
[ "expression.operation.binary.remove" ]
742,182
742,183
u592610268
cpp
p02937
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; typedef long long ll; vector<int> a[30]; int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; int l = s.length(); int l2 = t.length(); ll ans = 0; for (int i = 0; i < l; ++i) { a[s[i] - 'a'].push_back(i); } int cnt = 0; for (int i = 0; i < l2; ++i) { if (a[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } int k = upper_bound(a[t[i] - 'a'].begin(), a[t[i] - 'a'].end(), cnt) - a[t[i] - 'a'].begin(); if (k == a[t[i] - 'a'].size()) { ans += l; cnt = a[t[i] - 'a'][0]; } else cnt = a[t[i] - 'a'][k]; } printf("%lld", ans + 1 + cnt); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; typedef long long ll; vector<int> a[30]; int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; int l = s.length(); int l2 = t.length(); ll ans = 0; for (int i = 0; i < l; ++i) { a[s[i] - 'a'].push_back(i); } int cnt = -1; for (int i = 0; i < l2; ++i) { if (a[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } int k = upper_bound(a[t[i] - 'a'].begin(), a[t[i] - 'a'].end(), cnt) - a[t[i] - 'a'].begin(); if (k == a[t[i] - 'a'].size()) { ans += l; cnt = a[t[i] - 'a'][0]; } else cnt = a[t[i] - 'a'][k]; } printf("%lld", ans + 1 + cnt); return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
742,184
742,185
u011492570
cpp
p02937
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; typedef long long ll; vector<int> a[30]; int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; int l = s.length(); int l2 = t.length(); ll ans = 0; for (int i = 0; i < l; ++i) { a[s[i] - 'a'].push_back(i); } int cnt = 0; for (int i = 0; i < l2; ++i) { if (a[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } int k = lower_bound(a[t[i] - 'a'].begin(), a[t[i] - 'a'].end(), cnt) - a[t[i] - 'a'].begin(); if (k == a[t[i] - 'a'].size()) { ans += l; cnt = a[t[i] - 'a'][0]; } else cnt = a[t[i] - 'a'][k]; } printf("%lld", ans + 1 + cnt); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; typedef long long ll; vector<int> a[30]; int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; int l = s.length(); int l2 = t.length(); ll ans = 0; for (int i = 0; i < l; ++i) { a[s[i] - 'a'].push_back(i); } int cnt = -1; for (int i = 0; i < l2; ++i) { if (a[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } int k = upper_bound(a[t[i] - 'a'].begin(), a[t[i] - 'a'].end(), cnt) - a[t[i] - 'a'].begin(); if (k == a[t[i] - 'a'].size()) { ans += l; cnt = a[t[i] - 'a'][0]; } else cnt = a[t[i] - 'a'][k]; } printf("%lld", ans + 1 + cnt); return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change", "expression.operation.binary.change" ]
742,186
742,185
u011492570
cpp
p02937
#include <array> #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using LL = long long; using ULL = unsigned long long; void solve() { vector<unsigned> p[256]; string s, t; cin >> s >> t; rep(i, s.size()) p[s[i]].push_back(i); unsigned pp = 0, cycle = 0; rep(i, t.size()) { if (p[t[i]].size() == 0) { cout << -1 << endl; return; } char c = t[i]; unsigned l = 0, r = p[c].size(); while (l != r) { unsigned m = (l + r) / 2; if (p[c][m] >= pp) r = m; else l = m + 1; } if (p[c].size() == l) { cycle++; pp = p[c][0]; } else { pp = p[c][l] + 1; } } ULL ans = ULL(s.size()) * cycle + pp; cout << ans << endl; } int main() { solve(); return 0; }
#include <array> #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using LL = long long; using ULL = unsigned long long; void solve() { vector<unsigned> p[256]; string s, t; cin >> s >> t; rep(i, s.size()) p[s[i]].push_back(i); unsigned pp = 0, cycle = 0; rep(i, t.size()) { if (p[t[i]].size() == 0) { cout << -1 << endl; return; } char c = t[i]; unsigned l = 0, r = p[c].size(); while (l != r) { unsigned m = (l + r) / 2; if (p[c][m] >= pp) r = m; else l = m + 1; } if (p[c].size() == l) { cycle++; pp = p[c][0] + 1; } else { pp = p[c][l] + 1; } } ULL ans = ULL(s.size()) * cycle + pp; cout << ans << endl; } int main() { solve(); return 0; }
[ "assignment.change" ]
742,191
742,192
u331948661
cpp
p02937
//#include "bits/stdc++.h" #define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair // typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector<vector<int>> mat; 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 (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; signed main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; set<int> ps[30]; bool tcon[30] = {false}; bool scon[30] = {false}; rep(i, 0, SZ(t)) { tcon[t[i] - 'a'] = true; } rep(i, 0, SZ(s)) { scon[s[i] - 'a'] = true; ps[s[i] - 'a'].insert(i); } rep(i, 0, 30) { if (tcon[i] && !scon[i]) { cout << -1 << endl; return 0; } } int p = *ps[t[0] - 'a'].begin(); rep(i, 1, SZ(t)) { auto itr = ps[t[i] - 'a'].lower_bound(p % SZ(s)); if (itr == ps[t[i] - 'a'].end()) { p = (p / SZ(s) + 1) * SZ(s) + (*ps[t[i] - 'a'].begin()); } else { p += (*itr) - (p % SZ(s)); } } cout << p + 1 << endl; return 0; }
//#include "bits/stdc++.h" #define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair // typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector<vector<int>> mat; 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 (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; signed main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; set<int> ps[30]; bool tcon[30] = {false}; bool scon[30] = {false}; rep(i, 0, SZ(t)) { tcon[t[i] - 'a'] = true; } rep(i, 0, SZ(s)) { scon[s[i] - 'a'] = true; ps[s[i] - 'a'].insert(i); } rep(i, 0, 30) { if (tcon[i] && !scon[i]) { cout << -1 << endl; return 0; } } int p = *ps[t[0] - 'a'].begin(); rep(i, 1, SZ(t)) { auto itr = ps[t[i] - 'a'].upper_bound(p % SZ(s)); if (itr == ps[t[i] - 'a'].end()) { p = (p / SZ(s) + 1) * SZ(s) + (*ps[t[i] - 'a'].begin()); } else { p += (*itr) - (p % SZ(s)); } } cout << p + 1 << endl; return 0; }
[ "call.function.change" ]
742,202
742,203
u874947858
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { string s, t; cin >> s; cin >> t; string ss = s + s; vector<vector<int>> locate(26); rep(i, ss.size()) { locate[ss[i] - 'a'].push_back(i); } ll res = 0; int p = 0; rep(i, t.size()) { int nowch = t[i] - 'a'; if (locate[nowch].empty()) { cout << -1 << endl; return 0; } int np = *upper_bound(locate[nowch].begin(), locate[nowch].end(), p); res += np - p; p = np; if (p >= s.size()) p -= s.size(); } cout << res + 1 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { string s, t; cin >> s; cin >> t; string ss = s + s; vector<vector<int>> locate(26); rep(i, ss.size()) { locate[ss[i] - 'a'].push_back(i); } ll res = 0; int p = 0; rep(i, t.size()) { int nowch = t[i] - 'a'; if (locate[nowch].empty()) { cout << -1 << endl; return 0; } int np = *lower_bound(locate[nowch].begin(), locate[nowch].end(), p) + 1; res += np - p; p = np; if (p >= s.size()) p -= s.size(); } cout << res << endl; return 0; }
[ "identifier.change", "call.function.change", "expression.operation.binary.remove" ]
742,206
742,207
u762183504
cpp
p02937
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define REP(i, m, n) for (int i = m; i < n; i++) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define lamsort(v, p) \ sort(v.begin(), v.end(), [](p a, p b) { return a.num < b.num; }); #define check(v) \ rep(i, v.size()) cout << v[i] << " "; \ cout << endl const long long INF = 1LL << 60; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } typedef long long ll; using namespace std; //オーバーフローに気をつけろよおおおおおお //確認忘れるなよおおおおおお int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s, t; cin >> s >> t; int n = (int)s.size(), m = (int)t.size(); vector<vector<int>> is(26); rep(i, n) is[s[i] - 'a'].push_back(i); rep(i, n) is[s[i] - 'a'].push_back(i + n); ll ans = 0; int p = 0; rep(i, m) { int c = t[i] - 'a'; if ((int)is[c].size() == 0) { cout << -1 << endl; return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p) + 1; if (p >= n) { p -= n; ans += n; } ans += p; cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define REP(i, m, n) for (int i = m; i < n; i++) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define lamsort(v, p) \ sort(v.begin(), v.end(), [](p a, p b) { return a.num < b.num; }); #define check(v) \ rep(i, v.size()) cout << v[i] << " "; \ cout << endl const long long INF = 1LL << 60; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } typedef long long ll; using namespace std; //オーバーフローに気をつけろよおおおおおお //確認忘れるなよおおおおおお int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s, t; cin >> s >> t; int n = (int)s.size(), m = (int)t.size(); vector<vector<int>> is(26); rep(i, n) is[s[i] - 'a'].push_back(i); rep(i, n) is[s[i] - 'a'].push_back(i + n); ll ans = 0; int p = 0; rep(i, m) { int c = t[i] - 'a'; if ((int)is[c].size() == 0) { cout << -1 << endl; return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p) + 1; if (p >= n) { p -= n; ans += n; } } ans += p; cout << ans << endl; return 0; }
[]
742,208
742,209
u008582165
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, N) for (int i = 0; i < (int)N; i++) const ll MOD = pow(10, 9) + 7; const ll LLINF = pow(2, 61) - 1; const int INF = pow(2, 30) - 1; int main() { string s, t; cin >> s >> t; ll ls = s.length(), lt = t.length(); map<char, vector<int>> cs, ct; rep(i, ls) cs[s[i]].push_back(i); ll result = 0; rep(i, lt) { if (cs[t[i]].empty()) { cout << -1 << endl; return 0; } auto pos = upper_bound(cs[t[i]].begin(), cs[t[i]].end(), result % ls); if (pos == cs[t[i]].end()) result += cs[t[i]][0] + ls - result % ls; else result += *pos - result % ls; } result++; cout << result << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, N) for (int i = 0; i < (int)N; i++) const ll MOD = pow(10, 9) + 7; const ll LLINF = pow(2, 61) - 1; const int INF = pow(2, 30) - 1; int main() { string s, t; cin >> s >> t; ll ls = s.length(), lt = t.length(); map<char, vector<int>> cs, ct; rep(i, ls) cs[s[i]].push_back(i); ll result = 0; rep(i, lt) { if (cs[t[i]].empty()) { cout << -1 << endl; return 0; } auto pos = lower_bound(cs[t[i]].begin(), cs[t[i]].end(), result % ls); if (pos == cs[t[i]].end()) result += cs[t[i]][0] + ls - result % ls; else result += *pos - result % ls; result++; // cout << i << " " << result << endl; } cout << result << endl; return 0; }
[ "identifier.change", "call.function.change" ]
742,219
742,220
u680707192
cpp
p02937
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, N) for (int i = 0; i < (int)N; i++) #define FORIN(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #define MOD 1000000007 #define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__) using Pi = pair<int, int>; using ll = long long; const int INF = 1 << 28; string to_string(string s) { return s; } template <class T> string to_string(vector<T> v) { string ret = "{"; for (int i = 0; i < v.size() - 1; ++i) { ret += to_string(v[i]) + ","; } if (v.size() > 0) { ret += to_string(v.back()); } ret += "}"; return ret; } void debug() { cerr << endl; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << to_string(head) << " "; debug(tail...); } void print() { cout << endl; } template <class Head, class... Tail> void print(Head head, Tail... tail) { cout << to_string(head); print(tail...); } void get() {} template <class Head, class... Tail> void get(Head &head, Tail &...tail) { cin >> head; get(tail...); } template <class T> void getv(vector<T> &vec) { for (int i = 0; i < vec.size(); ++i) cin >> vec[i]; } int main() { string s, t; cin >> s >> t; vector<int> charpos[26]; int n = s.size(), m = t.size(); FOR(i, n) { charpos[s[i] - 'a'].push_back(i); } ll ans = 0; FOR(i, m) { if (charpos[t[i] - 'a'].empty()) { cout << -1 << endl; return 0; } else { int nowpad = ans % n; int pos = upper_bound(ALL(charpos[t[i] - 'a']), nowpad) - charpos[t[i] - 'a'].begin(); if (pos == charpos[t[i] - 'a'].size()) { pos = 0; ans += n - nowpad; nowpad = 0; } ans += charpos[t[i] - 'a'][pos] - nowpad; } } cout << ans + 1 << endl; return 0; } #include <algorithm>
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_set> #include <vector> using namespace std; #define FOR(i, N) for (int i = 0; i < (int)N; i++) #define FORIN(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #define MOD 1000000007 #define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__) using Pi = pair<int, int>; using ll = long long; const int INF = 1 << 28; string to_string(string s) { return s; } template <class T> string to_string(vector<T> v) { string ret = "{"; for (int i = 0; i < v.size() - 1; ++i) { ret += to_string(v[i]) + ","; } if (v.size() > 0) { ret += to_string(v.back()); } ret += "}"; return ret; } void debug() { cerr << endl; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << to_string(head) << " "; debug(tail...); } void print() { cout << endl; } template <class Head, class... Tail> void print(Head head, Tail... tail) { cout << to_string(head); print(tail...); } void get() {} template <class Head, class... Tail> void get(Head &head, Tail &...tail) { cin >> head; get(tail...); } template <class T> void getv(vector<T> &vec) { for (int i = 0; i < vec.size(); ++i) cin >> vec[i]; } int main() { string s, t; cin >> s >> t; vector<int> charpos[26]; int n = s.size(), m = t.size(); FOR(i, n) { charpos[s[i] - 'a'].push_back(i); } ll ans = -1; FOR(i, m) { if (charpos[t[i] - 'a'].empty()) { cout << -1 << endl; return 0; } else { int nowpad = ans % n; int pos = upper_bound(ALL(charpos[t[i] - 'a']), nowpad) - charpos[t[i] - 'a'].begin(); if (pos == charpos[t[i] - 'a'].size()) { pos = 0; ans += n - nowpad; nowpad = 0; } ans += charpos[t[i] - 'a'][pos] - nowpad; } } cout << ans + 1 << endl; return 0; } #include <algorithm>
[ "literal.number.change", "variable_declaration.value.change" ]
742,221
742,222
u656771711
cpp
p02937
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> #define Rep(i, n) for (int i = 0; i < n; ++i) #define rep(i, n) for (int i = 1; i <= n; ++i) #define ll long long #define INF 10e9 #define PI 3.14159265359 #define All(a) (a).begin(), (a).end() using namespace std; using P = pair<ll int, ll int>; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } string s; string t; int m; int n; int nexts[30][300000]; int main() { cin >> s; cin >> t; m = s.size(); n = t.size(); s = s + s; Rep(i, 2 * m) { Rep(j, 30) { nexts[j][i] = -1; } } for (int i = 2 * m - 1; i >= 0; --i) { Rep(j, 26) { nexts[j][i] = nexts[j][i + 1]; } nexts[s[i] - 'a'][i] = i + 1; } // Rep(i, 2*m) { // Rep(j, 26) cout << nexts[j][i] << " "; // // cout << "\n"; // } ll int ans = 0; int pos = 0; Rep(i, n) { int data = nexts[t[i] - 'a'][pos]; // cout << pos << data << "\n"; if (data == -1) { ans = -1; break; } else { int tmp = pos; pos = data; ans += pos - tmp; pos %= m; } } cout << ans << "\n"; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> #define Rep(i, n) for (int i = 0; i < n; ++i) #define rep(i, n) for (int i = 1; i <= n; ++i) #define ll long long #define INF 10e9 #define PI 3.14159265359 #define All(a) (a).begin(), (a).end() using namespace std; using P = pair<ll int, ll int>; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } string s; string t; int m; int n; int nexts[30][300000]; int main() { cin >> s; cin >> t; m = s.size(); n = t.size(); s = s + s; Rep(i, 2 * m + 2) { Rep(j, 30) { nexts[j][i] = -1; } } for (int i = 2 * m - 1; i >= 0; --i) { Rep(j, 26) { nexts[j][i] = nexts[j][i + 1]; } nexts[s[i] - 'a'][i] = i + 1; } // Rep(i, 2*m) { // Rep(j, 26) cout << nexts[j][i] << " "; // // cout << "\n"; //} ll int ans = 0; int pos = 0; Rep(i, n) { int data = nexts[t[i] - 'a'][pos]; // cout << pos << data << "\n"; if (data == -1) { ans = -1; break; } else { int tmp = pos; pos = data; ans += pos - tmp; pos %= m; } } cout << ans << "\n"; }
[ "expression.operation.binary.add" ]
742,257
742,258
u337199858
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using P = pair<int, int>; using namespace std; vector<int> pos[30]; int main() { string s, t; cin >> s >> t; map<char, int> sn, tn; for (char c : s) sn[c]++; bool ok = true; for (char c : t) { if (sn[c] == 0) ok = false; } if (!ok) { cout << -1 << endl; return 0; } rep(i, s.size()) { int x = s[i] - 'a'; pos[x].push_back(i); } ll ans = pos[t[0] - 'a'][0]; int cur = pos[t[0] - 'a'][0]; for (int i = 1; i < t.size(); ++i) { int x = t[i] - 'a'; auto itr = lower_bound(pos[x].begin(), pos[x].end(), cur); if (itr != pos[x].end()) { // cout << t[i] << ", " << cur << " / " << itr - pos[x].begin() << ", " << // *itr << endl; ans += (*itr - cur); cur = *itr; } else { ans += (s.size() - cur); ans += pos[x][0]; cur = pos[x][0]; } } cout << ans + 1 << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; using P = pair<int, int>; using namespace std; vector<int> pos[30]; int main() { string s, t; cin >> s >> t; map<char, int> sn, tn; for (char c : s) sn[c]++; bool ok = true; for (char c : t) { if (sn[c] == 0) ok = false; } if (!ok) { cout << -1 << endl; return 0; } rep(i, s.size()) { int x = s[i] - 'a'; pos[x].push_back(i); } ll ans = pos[t[0] - 'a'][0]; int cur = pos[t[0] - 'a'][0]; for (int i = 1; i < t.size(); ++i) { int x = t[i] - 'a'; auto itr = upper_bound(pos[x].begin(), pos[x].end(), cur); if (itr != pos[x].end()) { ans += (*itr - cur); cur = *itr; } else { ans += (s.size() - cur); ans += pos[x][0]; cur = pos[x][0]; } } cout << ans + 1 << endl; }
[ "identifier.change", "call.function.change" ]
742,261
742,262
u482544950
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int N = 1e5 + 5; int n, m, occ_next[N][256]; string s, t; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> s >> t; n = s.size(); m = t.size(); memset(occ_next, -1, sizeof(occ_next)); // Preprocess t for next occurence of a character at any index for (int i = n - 1; i >= 0; i--) { occ_next[i][s[i]] = i; for (char c = 'a'; c <= 'z'; c++) { if (c != s[i]) { occ_next[i][c] = occ_next[i + 1][c]; } } } ll ans = 0, cidx = 0; for (char c : t) { if (occ_next[cidx][c] == -1) { cidx = 0; ans += n; } // We can't find it if (occ_next[cidx][c] == -1) { cout << -1 << "\n"; return 0; } cidx = occ_next[cidx][c]; } ans += cidx + 1; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int N = 1e5 + 5; int n, m, occ_next[N][256]; string s, t; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> s >> t; n = s.size(); m = t.size(); memset(occ_next, -1, sizeof(occ_next)); // Preprocess t for next occurence of a character at any index for (int i = n - 1; i >= 0; i--) { occ_next[i][s[i]] = i; for (char c = 'a'; c <= 'z'; c++) { if (c != s[i]) { occ_next[i][c] = occ_next[i + 1][c]; } } } // Calculate index ll ans = 0, cidx = 0; for (char c : t) { if (occ_next[cidx][c] == -1) { cidx = 0; ans += n; } // We can't find it if (occ_next[cidx][c] == -1) { cout << -1 << "\n"; return 0; } cidx = occ_next[cidx][c] + 1; } ans += cidx; cout << ans << "\n"; return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
742,278
742,279
u575588317
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; string S, T; int main() { cin >> S >> T; string S2 = S + S; int next[S2.length() + 1][26]; for (int i = 0; i < 26; i++) { next[S2.length()][i] = S2.length(); } for (int i = S2.length() - 1; i >= 0; i--) { for (int j = 0; j < 26; j++) { next[i][j] = next[i + 1][j]; } next[i][S2[i] - 'a'] = i + 1; } /* for (int i = 0; i < 26; i++) { cout << (char)('a' + i) << ": "; for (int j = 0; j < S.length(); j++) { cout << next[j][i] << " "; } cout << endl; }*/ bool f = true; ll x = 0; ll cnt = 0; for (int i = 0; i < T.length(); i++) { if (next[x][T[i] - 'a'] == S2.length()) { f = false; break; } else { x = next[x][T[i] - 'a']; if (x > S.length()) { x %= S.length(); cnt++; } } } if (f) { cout << cnt * S.length() + x << endl; } else { cout << -1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; string S, T; int main() { cin >> S >> T; string S2 = S + S; int next[S2.length() + 1][26]; for (int i = 0; i < 26; i++) { next[S2.length()][i] = S2.length(); } for (int i = S2.length() - 1; i >= 0; i--) { for (int j = 0; j < 26; j++) { next[i][j] = next[i + 1][j]; } next[i][S2[i] - 'a'] = i + 1; } /* for (int i = 0; i < 26; i++) { cout << (char)('a' + i) << ": "; for (int j = 0; j < S.length(); j++) { cout << next[j][i] << " "; } cout << endl; }*/ bool f = true; ll x = 0; ll cnt = 0; for (int i = 0; i < T.length(); i++) { if (next[x][T[i] - 'a'] == S2.length()) { f = false; break; } else { x = next[x][T[i] - 'a']; if (x >= S.length()) { x %= S.length(); cnt++; } } } if (f) { cout << cnt * S.length() + x << endl; } else { cout << -1 << endl; } return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
742,282
742,283
u488352661
cpp
p02937
/* 友利奈緒ぱわーでACしてくれ!!!!!!!!!!!! Charlotteまだ見てない人は見ような!!!!!!! /  /:/              \:ヽ \         /  /                     \  ヽ      \__L 彡                    ヽ  ',        フ /   /  /  /   ,         ヽ  ',  j        レ    /  /  /                ',  ヽ j         //     ! /_l_/__ノ   { \}       ',  ',/       i ハ     { 从j ハ i    ',  ト-、}  i i  }  jj       ( ハ   (  川 ハ ハ  !  ' ハ  ハ j j ,'   八     <_,ィ∧   斗芹テミxハ ハ  レ } /__レレ /   ∧ \ ノ         ∨ \  ゝ 辷:ソ    ) 芹レ心ヾレ′ / ト-- ´    \ー‐' ノ   \ゝ           ゞ:_ソ "/  /  ヽ        フ    i八 " "   ,       ム彡    \       /  /  j  ト           " "イト<      \\      /  /   j //ヽ、   ∩     イ { {   ̄ フフへ \\     ( /    ,/ /   i >――<ニニニニ┐  〃/: : ヽ ヽヽ     /  ィT´/ /┌―  ̄ ̄ /::: , ,)      〃//: : : : : :} ヽヽ)    / /  ∧ヾi┌― { { ̄    ノ:::ト゚<      ∥//: : : : : : : : i  ノ ノ .   ( 人  {:ヽヾi∨ ∧V    /:::/ 、ヽ    ∥/: : : : : : : : : :} /    V ( ∧: :\'∨ ∧V   ノ:::/  ∧ 〉___∥: : : : : :/: : : :レ        /∧: : : : ∨ ∧V┬イ:::ノ  〈 TT | |{{: : : : /: : : : : ∧   ノ       ( ハ: : : : :∨'T∧Vi i (    V ! ! {{: : / : : : : : : / ー ノ      V ハ: : : : :∨ヘ∧V i ゝゝ  i/⌒\{/ : : : : : : : /ー― ´       ∨ ヽ: : : : :∨ヘ∧∨i 〉 〉 / /二  ): : : : : : : : :/ (https://seesaawiki.jp/asciiart/d/Charlotte より) */ #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; #define int ll // #define DEBUG 42 inline void nprint() {} template <class Head, class... Tail> inline void nprint(Head &&head, Tail &&...tail) { cout << head << endl; nprint(move(tail)...); } #ifdef DEBUG #define eprint(...) nprint(__VA_ARGS__) #else #define eprint(...) \ if (0 == 1) \ cout << 1 << endl; #endif #define Yes(a) cout << (a ? "Yes" : "No") << endl #define YES(a) cout << (a ? "YES" : "NO") << endl #define POSSIBLE(a) cout << (a ? "POSSIBLE" : "IMPOSSIBLE") << endl using cmp = complex<double>; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; template <class T> using V = vector<T>; template <class T> using VV = vector<V<T>>; #define fi first #define se second #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) using pii = pair<int, int>; using pll = pair<ll, ll>; #define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i) #define REP(i, n) FOR(i, 0, n) #define FORS(i, a, b) FOR(i, a, b + 1) #define REPS(i, n) REP(i, n + 1) #define RFOR(i, a, b) for (ll i = (ll)(b)-1; i >= a; --i) #define RREP(i, n) RFOR(i, 0, n) #define RREPS(i, n) RREP(i, n + 1) #define RFORS(i, a, b) RFOR(i, a, b + 1) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define PERM(c) \ sort(ALL(c)); \ for (bool cp = true; cp; cp = next_permutation(ALL(c))) #define eb(val) emplace_back(val) const double PI = acos(-1), EPS = 1e-10; constexpr ll MOD = 1E9 + 7; constexpr int dx[] = {1, 0, -1, 0}; constexpr int dy[] = {0, 1, 0, -1}; template <typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } template <class T> istream &operator>>(istream &is, vector<T> &st) { for (size_t i = 0; i < st.size(); ++i) is >> st[i]; return is; } template <class T> istream &operator>>(istream &is, vector<vector<T>> &st) { for (size_t i = 0; i < st.size(); ++i) is >> st[i]; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &st) { for (size_t i = 0; i < st.size(); ++i) { if (i == st.size() - 1) os << st[i]; else os << st[i] << " "; } return os; } template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> &st) { for (size_t i = 0; i < st.size(); ++i) { os << st[i]; if (i != st.size() - 1) os << endl; } return os; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); string s, t; cin >> s >> t; vvi cs(26); REP(i, s.size()) { cs[s[i] - 'a'].eb(i); } REP(i, 26) { int n = cs[i].size(); REP(j, n) { cs[i].eb(cs[i][j] + s.size()); } } bool ng = false; REP(i, t.size()) { if (cs[t[i] - 'a'].size() == 0) ng = true; } if (ng) { cout << -1 << endl; return 0; } REP(i, 26) { sort(ALL(cs[i])); } ll ans = 0; ll tmp = 0; REP(i, t.size()) { ll quot = ans / s.size(); tmp %= s.size(); // eprint(ans); // ans = *lower_bound(cs[t[i]-'a'].begin(),cs[t[i]-'a'].end(),tmp) + // m*s.size(); ans = *lower_bound(ALL(cs[t[i] - 'a']), tmp) + quot * s.size(); tmp = ++ans; } cout << ans + 1 << endl; }
/* 友利奈緒ぱわーでACしてくれ!!!!!!!!!!!! Charlotteまだ見てない人は見ような!!!!!!! /  /:/              \:ヽ \         /  /                     \  ヽ      \__L 彡                    ヽ  ',        フ /   /  /  /   ,         ヽ  ',  j        レ    /  /  /                ',  ヽ j         //     ! /_l_/__ノ   { \}       ',  ',/       i ハ     { 从j ハ i    ',  ト-、}  i i  }  jj       ( ハ   (  川 ハ ハ  !  ' ハ  ハ j j ,'   八     <_,ィ∧   斗芹テミxハ ハ  レ } /__レレ /   ∧ \ ノ         ∨ \  ゝ 辷:ソ    ) 芹レ心ヾレ′ / ト-- ´    \ー‐' ノ   \ゝ           ゞ:_ソ "/  /  ヽ        フ    i八 " "   ,       ム彡    \       /  /  j  ト           " "イト<      \\      /  /   j //ヽ、   ∩     イ { {   ̄ フフへ \\     ( /    ,/ /   i >――<ニニニニ┐  〃/: : ヽ ヽヽ     /  ィT´/ /┌―  ̄ ̄ /::: , ,)      〃//: : : : : :} ヽヽ)    / /  ∧ヾi┌― { { ̄    ノ:::ト゚<      ∥//: : : : : : : : i  ノ ノ .   ( 人  {:ヽヾi∨ ∧V    /:::/ 、ヽ    ∥/: : : : : : : : : :} /    V ( ∧: :\'∨ ∧V   ノ:::/  ∧ 〉___∥: : : : : :/: : : :レ        /∧: : : : ∨ ∧V┬イ:::ノ  〈 TT | |{{: : : : /: : : : : ∧   ノ       ( ハ: : : : :∨'T∧Vi i (    V ! ! {{: : / : : : : : : / ー ノ      V ハ: : : : :∨ヘ∧V i ゝゝ  i/⌒\{/ : : : : : : : /ー― ´       ∨ ヽ: : : : :∨ヘ∧∨i 〉 〉 / /二  ): : : : : : : : :/ (https://seesaawiki.jp/asciiart/d/Charlotte より) */ #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; #define int ll // #define DEBUG 42 inline void nprint() {} template <class Head, class... Tail> inline void nprint(Head &&head, Tail &&...tail) { cout << head << endl; nprint(move(tail)...); } #ifdef DEBUG #define eprint(...) nprint(__VA_ARGS__) #else #define eprint(...) \ if (0 == 1) \ cout << 1 << endl; #endif #define Yes(a) cout << (a ? "Yes" : "No") << endl #define YES(a) cout << (a ? "YES" : "NO") << endl #define POSSIBLE(a) cout << (a ? "POSSIBLE" : "IMPOSSIBLE") << endl using cmp = complex<double>; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; template <class T> using V = vector<T>; template <class T> using VV = vector<V<T>>; #define fi first #define se second #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) using pii = pair<int, int>; using pll = pair<ll, ll>; #define FOR(i, a, b) for (ll i = (a); i < (ll)(b); ++i) #define REP(i, n) FOR(i, 0, n) #define FORS(i, a, b) FOR(i, a, b + 1) #define REPS(i, n) REP(i, n + 1) #define RFOR(i, a, b) for (ll i = (ll)(b)-1; i >= a; --i) #define RREP(i, n) RFOR(i, 0, n) #define RREPS(i, n) RREP(i, n + 1) #define RFORS(i, a, b) RFOR(i, a, b + 1) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define PERM(c) \ sort(ALL(c)); \ for (bool cp = true; cp; cp = next_permutation(ALL(c))) #define eb(val) emplace_back(val) const double PI = acos(-1), EPS = 1e-10; constexpr ll MOD = 1E9 + 7; constexpr int dx[] = {1, 0, -1, 0}; constexpr int dy[] = {0, 1, 0, -1}; template <typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } template <class T> istream &operator>>(istream &is, vector<T> &st) { for (size_t i = 0; i < st.size(); ++i) is >> st[i]; return is; } template <class T> istream &operator>>(istream &is, vector<vector<T>> &st) { for (size_t i = 0; i < st.size(); ++i) is >> st[i]; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &st) { for (size_t i = 0; i < st.size(); ++i) { if (i == st.size() - 1) os << st[i]; else os << st[i] << " "; } return os; } template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> &st) { for (size_t i = 0; i < st.size(); ++i) { os << st[i]; if (i != st.size() - 1) os << endl; } return os; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); string s, t; cin >> s >> t; vvi cs(26); REP(i, s.size()) { cs[s[i] - 'a'].eb(i); } REP(i, 26) { int n = cs[i].size(); REP(j, n) { cs[i].eb(cs[i][j] + s.size()); } } bool ng = false; REP(i, t.size()) { if (cs[t[i] - 'a'].size() == 0) ng = true; } if (ng) { cout << -1 << endl; return 0; } REP(i, 26) { sort(ALL(cs[i])); } ll ans = 0; ll tmp = 0; REP(i, t.size()) { ll quot = ans / s.size(); tmp %= s.size(); // eprint(ans); // ans = *lower_bound(cs[t[i]-'a'].begin(),cs[t[i]-'a'].end(),tmp) + // m*s.size(); ans = *lower_bound(ALL(cs[t[i] - 'a']), tmp) + quot * s.size(); tmp = ++ans; } cout << ans << endl; }
[ "expression.operation.binary.remove" ]
742,286
742,287
u949798495
cpp
p02937
#include <algorithm> #include <bitset> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, i, j, k, m, a, b, c, x; string s, t, ss; cin >> s >> t; ss = s + s; n = s.length(); vector<vector<int>> next(n + n + 1, vector<int>(26, -1)); for (i = n + n - 1; i >= 0; i--) { next[i] = next[i + 1]; next[i][ss[i] - 'a'] = i; } set<char> sc; for (auto ch : s) sc.insert(ch); bool valid = true; for (auto ch : t) { if (sc.find(ch) == sc.end()) valid = false; } if (!valid) cout << "-1\n"; else { x = 0; a = 0; for (auto ch : t) { b = next[a][ch - 'a']; x += b - a; a = x % n; } cout << x + 1 << "\n"; } return 0; }
#include <algorithm> #include <bitset> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, i, j, k, m, a, b, c, x; string s, t, ss; cin >> s >> t; ss = s + s; n = s.length(); vector<vector<int>> next(n + n + 1, vector<int>(26, -1)); for (i = n + n - 1; i >= 0; i--) { next[i] = next[i + 1]; next[i][ss[i] - 'a'] = i; } set<char> sc; for (auto ch : s) sc.insert(ch); bool valid = true; for (auto ch : t) { if (sc.find(ch) == sc.end()) valid = false; } if (!valid) cout << "-1\n"; else { x = 0; a = 0; for (auto ch : t) { b = next[a][ch - 'a']; x += b - a + 1; a = x % n; } cout << x << "\n"; } return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
742,288
742,289
u696290869
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; #define repi(i, a, b) for (ll i = a; i < b; i++) #define rep(i, a) repi(i, 0, a) #define rrep(i, a) for (ll i = a - 1; i >= 0; i--) #define MOD 1000000007 // debug #define debug(arr) \ cerr << #arr << "(l" << __LINE__ << ") : "; \ for (auto x : arr) \ cerr << x << " "; \ cerr << endl; int main() { string s, t; cin >> s >> t; vector<set<ll>> charlist(26); rep(i, s.length()) charlist[s[i] - 'a'].insert(i); ll ans = 0, idx = -1; for (char c : t) { if (charlist[c - 'a'].size() == 0) { ans = -1; break; } auto it = charlist[c - 'a'].lower_bound(idx); if (it != charlist[c - 'a'].end()) { idx = *it; } else { idx = *charlist[c - 'a'].begin(); ans += s.length(); } } if (ans >= 0) ans += idx + 1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; #define repi(i, a, b) for (ll i = a; i < b; i++) #define rep(i, a) repi(i, 0, a) #define rrep(i, a) for (ll i = a - 1; i >= 0; i--) #define MOD 1000000007 // debug #define debug(arr) \ cerr << #arr << "(l" << __LINE__ << ") : "; \ for (auto x : arr) \ cerr << x << " "; \ cerr << endl; int main() { string s, t; cin >> s >> t; vector<set<ll>> charlist(26); rep(i, s.length()) charlist[s[i] - 'a'].insert(i); ll ans = 0, idx = -1; for (char c : t) { if (charlist[c - 'a'].size() == 0) { ans = -1; break; } auto it = charlist[c - 'a'].upper_bound(idx); if (it != charlist[c - 'a'].end()) { idx = *it; } else { idx = *charlist[c - 'a'].begin(); ans += s.length(); } // cout << idx << endl; } if (ans >= 0) ans += idx + 1; cout << ans << endl; return 0; }
[ "call.function.change" ]
742,292
742,293
u336721073
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string S, T; long long ans = 0; cin >> S >> T; int N = S.size(), M = T.size(); vector<vector<int>> V('z' + 1, vector<int>(0)); for (int i = 0; i < N; i++) V[S[i]].push_back(i); for (int i = 0; i < M; i++) { if (V[T[i]].size() == 0) { cout << -1 << endl; return 0; } int x = ans % N; int y; auto it = V[T[i]].end(); it--; if (x > *it) y = V[T[i]][0]; else y = *upper_bound(V[T[i]].begin(), V[T[i]].end(), x); if (y > x) ans += y - x + 1; else ans += (N - x) + y; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S, T; long long ans = 0; cin >> S >> T; int N = S.size(), M = T.size(); vector<vector<int>> V('z' + 1, vector<int>(0)); for (int i = 0; i < N; i++) V[S[i]].push_back(i); for (int i = 0; i < M; i++) { if (V[T[i]].size() == 0) { cout << -1 << endl; return 0; } int x = ans % N; int y; auto it = V[T[i]].end(); it--; if (x > *it) y = V[T[i]][0]; else y = *lower_bound(V[T[i]].begin(), V[T[i]].end(), x); if (y >= x) ans += y - x + 1; else ans += (N - x) + y + 1; } cout << ans << endl; return 0; }
[ "assignment.value.change", "identifier.change", "call.function.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change", "assignment.change" ]
742,302
742,303
u122034453
cpp
p02937
#include <algorithm> #include <bits/stdc++.h> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <sstream> #include <string> #include <vector> using namespace std; #define REP(i, n) FOR(i, 0, n) #define FOR(i, a, b) for (long long i = (a), i##Len_ = (b); i < i##Len_; i++) typedef long long ll; static const ll MOD = 1000000007; static const ll INF = 1000000000000000000LL; //[i文字目][alphabet] int nex[201010][26]; int main() { string s, t; cin >> s; cin >> t; int A = s.size(); string s2 = s + s; for (int j = 0; j < 26; ++j) { nex[2 * A][j] = s2.size(); } for (int i = s2.size() - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) { // 1文字前の(後ろからだから後)の情報をもらう nex[i][j] = nex[i + 1][j]; } //今回の分(位置なので+1) nex[i][s[i] - 'a'] = i + 1; } // nex[0] - nex[s*2 -1]までのoffsetが完成 ll res = 0; for (auto c : t) { //数値に変換 c -= 'a'; // xはsのあまり int x = res % A; // s中にないアルファベットなら if (nex[x][c] == s2.size()) { cout << -1 << endl; return 0; } res += nex[x][c] - x; } cout << res << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <sstream> #include <string> #include <vector> using namespace std; #define REP(i, n) FOR(i, 0, n) #define FOR(i, a, b) for (long long i = (a), i##Len_ = (b); i < i##Len_; i++) typedef long long ll; static const ll MOD = 1000000007; static const ll INF = 1000000000000000000LL; //[i文字目][alphabet] int nex[201010][26]; int main() { string s, t; cin >> s; cin >> t; int A = s.size(); string s2 = s + s; for (int j = 0; j < 26; ++j) { nex[2 * A][j] = s2.size(); } for (int i = s2.size() - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) { // 1文字前の(後ろからだから後)の情報をもらう nex[i][j] = nex[i + 1][j]; } //今回の分(位置なので+1) nex[i][s2[i] - 'a'] = i + 1; } // nex[0] - nex[s*2 -1]までのoffsetが完成 ll res = 0; for (auto c : t) { //数値に変換 c -= 'a'; // xはsのあまり int x = res % A; // s中にないアルファベットなら if (nex[x][c] == s2.size()) { cout << -1 << endl; return 0; } res += nex[x][c] - x; } cout << res << endl; return 0; }
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
742,307
742,308
u485731913
cpp
p02937
#include <bits/stdc++.h> // ver2.2.0 #define int long long #define endl "\n" #define ALL(v) (v).begin(), (v).end() #define Vi vector<int> #define VVi vector<Vi> #define Vs vector<string> #define Pii pair<int, int> #define VPii vector<Pii> #define Tiii tuple<int, int, int> #define PQi priority_queue<int> #define PQir priority_queue<int, vector<int>, greater<int>> #define pb push_back #define mp make_pair #define mt make_tuple #define FI first #define SE second #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define cYes cout << "Yes" << endl #define cNo cout << "No" << endl #define sortr(v) sort(v, greater<>()) #define rep(i, a, b) for (int i = a; i < b; i++) #define repeq(i, a, b) for (int i = a; i <= b; i++) #define repreq(i, a, b) for (int i = a; i >= b; i--) #define leng(n) (int)(log10(n) + 1) #define dem(a, b) ((a + b - 1) / (b)) #define Vin(a) rep(iI, 0, a.size()) cin >> a[iI] #define Vout(a) \ rep(lZ, 0, a.size() - 1) cout << a[lZ] << ' '; \ cout << a.back() << endl #define VVout(a) \ rep(lY, 0, a.size()) { Vout(a[lY]); } #define VPout(a) \ rep(lX, 0, a.size()) cout << a[lX].FI << ' ' << a[lX].SE << endl #define INF 3000000000000000000 // 3.0 * 10 ^ 18 (MAXの1/3くらい) #define MOD 1000000007 // 10^9 + 7 using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } // 最大公約数gcd int lcm(int a, int b) { return a / gcd(a, b) * b; } // 最小公倍数lcm void uniq(Vi &v) { sort(ALL(v)); v.erase(unique(ALL(v)), v.end()); } // uniqのやつ int mypow(int x, int n, int m) { // 累乗x^n(mod m) O(log(n)) if (n == 0) return 1; if (n % 2 == 0) return mypow(x * x % m, n / 2, m); else return x * mypow(x, n - 1, m) % m; } VVi a(26, Vi(0)); int ser(char c, int n) { int m = c - 'a'; int l = a[m].size(); int L = 0, R = l, mid = (L + R) / 2; int ans = -1; while (L < R) { if (a[m][mid] > n) { R = mid; ans = a[m][mid]; } else if (a[m][mid] <= n) L = mid + 1; mid = (L + R) / 2; } if (ans == -1) ans = a[m][0]; return ans; } signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); string s, t; cin >> s >> t; int L = s.size(); int qw, er, ty, ui; rep(i, 0, s.size()) { qw = s[i] - 'a'; a[qw].pb(i); } /*rep(i,0,26){ if(a[i].size()==0) a[i].pb(-1); }*/ // VVout(a); Vi memo(t.size()); int now = -1; char c; rep(i, 0, t.size()) { c = t[i]; if (a[c - 'a'].size() == 0) { cout << -1 << endl; return 0; } now = ser(c, now); memo[i] = now; } // Vout(memo); int ans = memo.back() + 1; rep(i, 1, memo.size()) { if (memo[i] < memo[i - 1]) ans += L; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> // ver2.2.0 #define int long long #define endl "\n" #define ALL(v) (v).begin(), (v).end() #define Vi vector<int> #define VVi vector<Vi> #define Vs vector<string> #define Pii pair<int, int> #define VPii vector<Pii> #define Tiii tuple<int, int, int> #define PQi priority_queue<int> #define PQir priority_queue<int, vector<int>, greater<int>> #define pb push_back #define mp make_pair #define mt make_tuple #define FI first #define SE second #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define cYes cout << "Yes" << endl #define cNo cout << "No" << endl #define sortr(v) sort(v, greater<>()) #define rep(i, a, b) for (int i = a; i < b; i++) #define repeq(i, a, b) for (int i = a; i <= b; i++) #define repreq(i, a, b) for (int i = a; i >= b; i--) #define leng(n) (int)(log10(n) + 1) #define dem(a, b) ((a + b - 1) / (b)) #define Vin(a) rep(iI, 0, a.size()) cin >> a[iI] #define Vout(a) \ rep(lZ, 0, a.size() - 1) cout << a[lZ] << ' '; \ cout << a.back() << endl #define VVout(a) \ rep(lY, 0, a.size()) { Vout(a[lY]); } #define VPout(a) \ rep(lX, 0, a.size()) cout << a[lX].FI << ' ' << a[lX].SE << endl #define INF 3000000000000000000 // 3.0 * 10 ^ 18 (MAXの1/3くらい) #define MOD 1000000007 // 10^9 + 7 using namespace std; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } // 最大公約数gcd int lcm(int a, int b) { return a / gcd(a, b) * b; } // 最小公倍数lcm void uniq(Vi &v) { sort(ALL(v)); v.erase(unique(ALL(v)), v.end()); } // uniqのやつ int mypow(int x, int n, int m) { // 累乗x^n(mod m) O(log(n)) if (n == 0) return 1; if (n % 2 == 0) return mypow(x * x % m, n / 2, m); else return x * mypow(x, n - 1, m) % m; } VVi a(26, Vi(0)); int ser(char c, int n) { int m = c - 'a'; int l = a[m].size(); int L = 0, R = l, mid = (L + R) / 2; int ans = -1; while (L < R) { if (a[m][mid] > n) { R = mid; ans = a[m][mid]; } else if (a[m][mid] <= n) L = mid + 1; mid = (L + R) / 2; } if (ans == -1) ans = a[m][0]; return ans; } signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); string s, t; cin >> s >> t; int L = s.size(); int qw, er, ty, ui; rep(i, 0, s.size()) { qw = s[i] - 'a'; a[qw].pb(i); } /*rep(i,0,26){ if(a[i].size()==0) a[i].pb(-1); }*/ // VVout(a); Vi memo(t.size()); int now = -1; char c; rep(i, 0, t.size()) { c = t[i]; if (a[c - 'a'].size() == 0) { cout << -1 << endl; return 0; } now = ser(c, now); memo[i] = now; } // Vout(memo); int ans = memo.back() + 1; rep(i, 1, memo.size()) { if (memo[i] <= memo[i - 1]) ans += L; } cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
742,309
742,310
u095453583
cpp
p02937
#include <bits/stdc++.h> #define For(i, a, b) for (int(i) = (a); (i) < (b); ++(i)) #define rFor(i, a, b) for (int(i) = (a)-1; (i) >= (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 pair<int, int> pii; int main() { string s, t; cin >> s >> t; int k = s.size(); s += s; int n = s.size(); int m = t.size(); int Next[n][26]; rep(i, 26) Next[n - 1][i] = k; rFor(i, n, 1) rep(j, 26) { if (s[i] - 'a' == j) Next[i - 1][j] = i % k; else Next[i - 1][j] = Next[i][j]; } lint ans = 0; int cur = k - 1; rep(i, m) { int ncur = Next[cur][t[i] - 'a']; if (ncur == k) { printf("-1\n"); return 0; } if (ncur <= cur) ncur += k; ans += (lint)ncur - (lint)cur; cur = ncur % k; } printf("%lld\n", ans + 1LL); }
#include <bits/stdc++.h> #define For(i, a, b) for (int(i) = (a); (i) < (b); ++(i)) #define rFor(i, a, b) for (int(i) = (a)-1; (i) >= (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 pair<int, int> pii; int main() { string s, t; cin >> s >> t; int k = s.size(); s += s; int n = s.size(); int m = t.size(); int Next[n][26]; rep(i, 26) Next[n - 1][i] = k; rFor(i, n, 1) rep(j, 26) { if (s[i] - 'a' == j) Next[i - 1][j] = i % k; else Next[i - 1][j] = Next[i][j]; } lint ans = 0; int cur = k - 1; rep(i, m) { int ncur = Next[cur][t[i] - 'a']; if (ncur == k) { printf("-1\n"); return 0; } if (ncur <= cur) ncur += k; ans += (lint)ncur - (lint)cur; cur = ncur % k; } printf("%lld\n", ans); }
[ "expression.operation.binary.remove" ]
742,313
742,314
u434208140
cpp
p02937
#include <bits/stdc++.h> #define int long long #define mod (int)(1e9 + 7) #define inf (int)(3e18) #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i < n; i++) #define P pair<int, int> #define PiP pair<int, pair<int, int>> #define PP pair<P, P> #define all(v) v.begin(), v.end() #define mkp make_pair #define mkt make_tuple #define prique(T) priority_queue<T, vector<T>, greater<T>> #define vecunique(vec) \ sort(vec.begin(), vec.end()); \ decltype(vec)::iterator result = std::unique(vec.begin(), vec.end()); \ vec.erase(result, vec.end()) using namespace std; template <class T> inline void chmax(T &a, T b) { a = max(a, b); } template <class T> inline void chmin(T &a, T b) { a = min(a, b); } bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return x > 1; } int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int mod_pow(int x, int y, int m) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int comb(int x, int y) { if (y > x) return 0; return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod; } int get_rand(int MIN, int MAX) { random_device rnd; mt19937_64 mt64(rnd()); uniform_int_distribution<int> engine(MIN, MAX); return engine(mt64); } /*--------Library Zone!--------*/ string s, t; int ans; set<int> st[30]; signed main() { cin >> s >> t; rep(i, s.size()) { st[s[i] - 'a'].insert(i); } int now = 0; rep(i, t.size()) { if (st[t[i] - 'a'].upper_bound(now) != st[t[i] - 'a'].end()) { now = *st[t[i] - 'a'].upper_bound(now); } else if (st[t[i] - 'a'].size()) { ans++; now = *st[t[i] - 'a'].begin(); } else { cout << -1 << endl; return 0; } } cout << ans * s.size() + now + 1 << endl; }
#include <bits/stdc++.h> #define int long long #define mod (int)(1e9 + 7) #define inf (int)(3e18) #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i < n; i++) #define P pair<int, int> #define PiP pair<int, pair<int, int>> #define PP pair<P, P> #define all(v) v.begin(), v.end() #define mkp make_pair #define mkt make_tuple #define prique(T) priority_queue<T, vector<T>, greater<T>> #define vecunique(vec) \ sort(vec.begin(), vec.end()); \ decltype(vec)::iterator result = std::unique(vec.begin(), vec.end()); \ vec.erase(result, vec.end()) using namespace std; template <class T> inline void chmax(T &a, T b) { a = max(a, b); } template <class T> inline void chmin(T &a, T b) { a = min(a, b); } bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return x > 1; } int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } int lcm(int x, int y) { return x / gcd(x, y) * y; } int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int mod_pow(int x, int y, int m) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int comb(int x, int y) { if (y > x) return 0; return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod; } int get_rand(int MIN, int MAX) { random_device rnd; mt19937_64 mt64(rnd()); uniform_int_distribution<int> engine(MIN, MAX); return engine(mt64); } /*--------Library Zone!--------*/ string s, t; int ans; set<int> st[30]; signed main() { cin >> s >> t; rep(i, s.size()) { st[s[i] - 'a'].insert(i); } int now = -1; rep(i, t.size()) { if (st[t[i] - 'a'].upper_bound(now) != st[t[i] - 'a'].end()) { now = *st[t[i] - 'a'].upper_bound(now); } else if (st[t[i] - 'a'].size()) { ans++; now = *st[t[i] - 'a'].begin(); } else { cout << -1 << endl; return 0; } } cout << ans * s.size() + now + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
742,323
742,324
u147049801
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define sz(x) int(x.size()) using namespace std; typedef long long ll; int main() { string s, t; cin >> s >> t; int n = sz(s), m = sz(t); vector<vector<int>> is(26); rep(i, n) is[s[i] - 'a'].push_back(i); rep(i, n) is[s[i] - 'a'].push_back(i + n); ll ans = 0; int p = 0; // after p rep(i, m) { int c = t[i] - 'a'; if (sz(is[c]) == 0) { puts("-1"); return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p + 1); if (p >= n) { p -= n; ans += n; } } ans += p; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define sz(x) int(x.size()) using namespace std; typedef long long ll; int main() { string s, t; cin >> s >> t; int n = sz(s), m = sz(t); vector<vector<int>> is(26); rep(i, n) is[s[i] - 'a'].push_back(i); rep(i, n) is[s[i] - 'a'].push_back(i + n); ll ans = 0; int p = 0; // after p rep(i, m) { int c = t[i] - 'a'; if (sz(is[c]) == 0) { puts("-1"); return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p) + 1; if (p >= n) { p -= n; ans += n; } } ans += p; cout << ans << endl; return 0; }
[ "call.arguments.change" ]
742,325
742,326
u506858457
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; map<char, set<long long>> char_pos; int n = (int)s.size(), m = (int)t.size(); for (int i = 0; i < n; ++i) { char_pos[s[i]].insert((long long)i); } long long pos = 0; for (char c : t) { if (char_pos[c].size() == 0) { cout << -1 << endl; return 0; } auto it = char_pos[c].upper_bound(pos % n); if (it == char_pos[c].end()) { pos = (pos / n) * n + n + *char_pos[c].begin(); } else { pos = (pos / n) * n + *it; } } cout << pos + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; map<char, set<long long>> char_pos; int n = (int)s.size(), m = (int)t.size(); for (int i = 0; i < n; ++i) { char_pos[s[i]].insert((long long)i); } long long pos = -1; for (char c : t) { if (char_pos[c].size() == 0) { cout << -1 << endl; return 0; } auto it = char_pos[c].upper_bound(pos % n); if (it == char_pos[c].end()) { pos = (pos / n) * n + n + *char_pos[c].begin(); } else { pos = (pos / n) * n + *it; } } cout << pos + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
742,331
742,332
u813181182
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define PI 3.14159265358979 #define rep(i, n) for (int i = 0; i < (n); ++i) #define repp(i, s, e) for (int i = (s); i <= (e); ++i) #define sz(x) ((int)x.size()) #define all(x) x.begin(), x.end() #define FAST_IO() \ ios::sync_with_stdio(0); \ cin.tie(0) template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; } template <class U, class V> ostream &operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")"; } int main() { string s, t; cin >> s >> t; int S = sz(s), T = sz(t); vector<vector<int>> A(26); rep(i, S) { A[s[i] - 'a'].push_back(i); } int ans = 0; int here = 0; for (auto &c : t) { if (A[c - 'a'].empty()) { cout << "-1\n"; return 0; } int next = upper_bound(A[c - 'a'].begin(), A[c - 'a'].end(), here) - A[c - 'a'].begin(); if (next == sz(A[c - 'a'])) { next = upper_bound(A[c - 'a'].begin(), A[c - 'a'].end(), -1) - A[c - 'a'].begin(); ans += A[c - 'a'][next] + S - here; } else { ans += A[c - 'a'][next] - here; } here = A[c - 'a'][next]; } cout << ans + 1 << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define PI 3.14159265358979 #define rep(i, n) for (int i = 0; i < (n); ++i) #define repp(i, s, e) for (int i = (s); i <= (e); ++i) #define sz(x) ((int)x.size()) #define all(x) x.begin(), x.end() #define FAST_IO() \ ios::sync_with_stdio(0); \ cin.tie(0) template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; } template <class U, class V> ostream &operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")"; } int main() { string s, t; cin >> s >> t; int S = sz(s), T = sz(t); vector<vector<int>> A(26); rep(i, S) { A[s[i] - 'a'].push_back(i); } ll ans = 0; int here = -1; for (auto &c : t) { if (A[c - 'a'].empty()) { cout << "-1\n"; return 0; } int next = upper_bound(A[c - 'a'].begin(), A[c - 'a'].end(), here) - A[c - 'a'].begin(); if (next == sz(A[c - 'a'])) { next = upper_bound(A[c - 'a'].begin(), A[c - 'a'].end(), -1) - A[c - 'a'].begin(); ans += A[c - 'a'][next] + S - here; } else { ans += A[c - 'a'][next] - here; } // cout << here << "->" << A[c - 'a'][next] << "\n"; here = A[c - 'a'][next]; } cout << ans << "\n"; }
[ "variable_declaration.type.change", "literal.number.change", "variable_declaration.value.change", "expression.operation.binary.remove" ]
742,339
742,338
u573653733
cpp
p02937
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 #define MOD 1000000007 //#define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; int main() { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); s += s; vector<vector<int>> id(26); rep(i, 2 * n) { id[s[i] - 'a'].push_back(i); } ll now = 0; ll ans = 0; rep(i, m) { if (id[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } now = *lower_bound(id[t[i] - 'a'].begin(), id[t[i] - 'a'].end(), now); if (now >= n) { ans += n; now -= n; } } ans += now + 1; cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 #define MOD 1000000007 //#define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 using ll = long long; using Pi = pair<int, int>; using Pl = pair<ll, ll>; int main() { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); s += s; vector<vector<int>> id(26); rep(i, 2 * n) { id[s[i] - 'a'].push_back(i); } int now = -1; ll ans = 0; rep(i, m) { if (id[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } now = *upper_bound(id[t[i] - 'a'].begin(), id[t[i] - 'a'].end(), now); if (now >= n) { ans += n; now -= n; } } ans += now + 1; cout << ans << endl; }
[ "variable_declaration.type.change", "literal.number.change", "variable_declaration.value.change", "assignment.value.change", "identifier.change", "call.function.change" ]
742,352
742,351
u314008046
cpp
p02937
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = int(a); i < int(b); ++i) using namespace std; typedef long long ll; int INF = (1LL << 30) - 1; int MOD = 1e9 + 7; main() { string S, T; cin >> S >> T; vector<int> V[26]; int used[26] = {}; rep(i, 0, S.size()) { V[S[i] - 'a'].push_back(i); used[S[i] - 'a'] = 1; } rep(i, 0, T.size()) { if (used[T[i] - 'a'] == 0) { cout << -1 << endl; return 0; } } ll sum = 0, idx = 0; rep(i, 0, T.size()) { char c = T[i] - 'a'; auto itr1 = lower_bound(V[c].begin(), V[c].end(), idx + 1); auto itr2 = lower_bound(V[c].begin(), V[c].end(), 0); ll cost1 = INF, cost2 = INF; if (itr1 != V[c].end()) cost1 = *itr1 - idx; cost2 = *itr2 + S.size() - idx; sum += min(cost1, cost2); if (cost1 <= cost2) { idx = *itr1; } else { idx = *itr2; } // cout << cost1 << " " << cost2 << "," << idx << endl; // cout << S[*itr1] << " " << *itr1 << endl; // cout << S[*itr2] << " " << *itr2 << endl; } cout << sum + 1 << endl; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = int(a); i < int(b); ++i) using namespace std; typedef long long ll; int INF = (1LL << 30) - 1; int MOD = 1e9 + 7; main() { string S, T; cin >> S >> T; vector<int> V[26]; int used[26] = {}; rep(i, 0, S.size()) { V[S[i] - 'a'].push_back(i); used[S[i] - 'a'] = 1; } rep(i, 0, T.size()) { if (used[T[i] - 'a'] == 0) { cout << -1 << endl; return 0; } } ll sum = 0, idx = -1; rep(i, 0, T.size()) { char c = T[i] - 'a'; auto itr1 = lower_bound(V[c].begin(), V[c].end(), idx + 1); auto itr2 = lower_bound(V[c].begin(), V[c].end(), 0); ll cost1 = INF, cost2 = INF; if (itr1 != V[c].end()) cost1 = *itr1 - idx; cost2 = *itr2 + S.size() - idx; sum += min(cost1, cost2); if (cost1 <= cost2) { idx = *itr1; } else { idx = *itr2; } // cout << cost1 << " " << cost2 << "," << idx << endl; // cout << S[*itr1] << " " << *itr1 << endl; // cout << S[*itr2] << " " << *itr2 << endl; } cout << sum << endl; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operation.binary.remove" ]
742,355
742,356
u157322125
cpp
p02937
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; map<char, vector<int>> sMap; for (int i = 0; i < s.size(); i++) { if (sMap.find(s[i]) == sMap.end()) { sMap.insert({s[i], vector<int>(1, i)}); } else { sMap[s[i]].push_back(i); } } ll mul = 0; int curIndex = -1; for (char c : t) { if (sMap.find(c) == sMap.end()) { cout << -1 << endl; return 0; } auto it = lower_bound(sMap[c].begin(), sMap[c].end(), curIndex); if (it == sMap[c].end()) { curIndex = sMap[c][0]; mul++; } else { curIndex = *it; } } cout << (ll)s.size() * mul + curIndex + 1 << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; map<char, vector<int>> sMap; for (int i = 0; i < s.size(); i++) { if (sMap.find(s[i]) == sMap.end()) { sMap.insert({s[i], vector<int>(1, i)}); } else { sMap[s[i]].push_back(i); } } ll mul = 0; int curIndex = -1; for (char c : t) { if (sMap.find(c) == sMap.end()) { cout << -1 << endl; return 0; } auto it = upper_bound(sMap[c].begin(), sMap[c].end(), curIndex); if (it == sMap[c].end()) { curIndex = sMap[c][0]; mul++; } else { curIndex = *it; } } cout << (ll)s.size() * mul + curIndex + 1 << endl; return 0; }
[ "identifier.change", "call.function.change" ]
742,359
742,360
u007567244
cpp
p02941
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ms(s, n) memset(s, n, sizeof(s)) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORd(i, a, b) for (int i = (a)-1; i >= (b); --i) #define FORall(it, a) \ for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) #define sz(a) int((a).size()) #define present(t, x) (t.find(x) != t.end()) #define all(a) (a).begin(), (a).end() #define uni(a) (a).erase(unique(all(a)), (a).end()) #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define prec(n) fixed << setprecision(n) #define bit(n, i) (((n) >> (i)) & 1) #define bitcount(n) __builtin_popcountll(n) typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<pi> vii; const int MOD = (int)1e9 + 7; const int FFTMOD = 119 << 23 | 1; const int INF = (int)1e9 + 23111992; const ll LINF = (ll)1e18 + 23111992; const ld PI = acos((ld)-1); const ld EPS = 1e-9; inline ll gcd(ll a, ll b) { ll r; while (b) { r = a % b; a = b; b = r; } return a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline ll fpow(ll n, ll k, int p = MOD) { ll r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } template <class T> inline int chkmin(T &a, const T &val) { return val < a ? a = val, 1 : 0; } template <class T> inline int chkmax(T &a, const T &val) { return a < val ? a = val, 1 : 0; } inline ull isqrt(ull k) { ull r = sqrt(k) + 1; while (r * r > k) r--; return r; } inline ll icbrt(ll k) { ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r; } inline void addmod(int &a, int val, int p = MOD) { if ((a = (a + val)) >= p) a -= p; } inline void submod(int &a, int val, int p = MOD) { if ((a = (a - val)) < 0) a += p; } inline int mult(int a, int b, int p = MOD) { return (ll)a * b % p; } inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } inline int sign(ld x) { return x < -EPS ? -1 : x > +EPS; } inline int sign(ld x, ld y) { return sign(x - y); } mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count()); inline int mrand() { return abs((int)mt()); } #define db(x) cerr << "[" << #x << ": " << (x) << "] "; #define endln cerr << "\n"; void solve() { int n; cin >> n; vi a(n), b(n); FOR(i, 0, n) cin >> a[i]; FOR(i, 0, n) cin >> b[i]; set<pi> st; FOR(i, 0, n) st.insert(mp(b[i], i)); int res = 0; while (sz(st)) { int u = st.rbegin()->se; st.erase(*st.rbegin()); int pu = (u + n - 1) % n; int nu = (u + 1) % n; if (b[u] < a[u]) { cout << -1 << "\n"; return; } if (a[u] < b[u]) { int s = b[pu] + b[nu]; int x = (b[u] - a[u]) / s; chkmin(x, (b[u] - b[nu]) / s); chkmin(x, (b[u] - b[pu]) / s); if (!x) { cout << -1 << "\n"; return; } res += x; b[u] -= s * x; if (b[u] < a[u]) { cout << -1 << "\n"; return; } if (a[u] < b[u]) { st.insert(mp(b[u], u)); } } } cout << res << "\n"; } int main(int argc, char *argv[]) { ios_base::sync_with_stdio(0), cin.tie(0); if (argc > 1) { assert(freopen(argv[1], "r", stdin)); } if (argc > 2) { assert(freopen(argv[2], "wb", stdout)); } solve(); cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ms(s, n) memset(s, n, sizeof(s)) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORd(i, a, b) for (int i = (a)-1; i >= (b); --i) #define FORall(it, a) \ for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) #define sz(a) int((a).size()) #define present(t, x) (t.find(x) != t.end()) #define all(a) (a).begin(), (a).end() #define uni(a) (a).erase(unique(all(a)), (a).end()) #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define prec(n) fixed << setprecision(n) #define bit(n, i) (((n) >> (i)) & 1) #define bitcount(n) __builtin_popcountll(n) typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<pi> vii; const int MOD = (int)1e9 + 7; const int FFTMOD = 119 << 23 | 1; const int INF = (int)1e9 + 23111992; const ll LINF = (ll)1e18 + 23111992; const ld PI = acos((ld)-1); const ld EPS = 1e-9; inline ll gcd(ll a, ll b) { ll r; while (b) { r = a % b; a = b; b = r; } return a; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } inline ll fpow(ll n, ll k, int p = MOD) { ll r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } template <class T> inline int chkmin(T &a, const T &val) { return val < a ? a = val, 1 : 0; } template <class T> inline int chkmax(T &a, const T &val) { return a < val ? a = val, 1 : 0; } inline ull isqrt(ull k) { ull r = sqrt(k) + 1; while (r * r > k) r--; return r; } inline ll icbrt(ll k) { ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r; } inline void addmod(int &a, int val, int p = MOD) { if ((a = (a + val)) >= p) a -= p; } inline void submod(int &a, int val, int p = MOD) { if ((a = (a - val)) < 0) a += p; } inline int mult(int a, int b, int p = MOD) { return (ll)a * b % p; } inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } inline int sign(ld x) { return x < -EPS ? -1 : x > +EPS; } inline int sign(ld x, ld y) { return sign(x - y); } mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count()); inline int mrand() { return abs((int)mt()); } #define db(x) cerr << "[" << #x << ": " << (x) << "] "; #define endln cerr << "\n"; void solve() { int n; cin >> n; vi a(n), b(n); FOR(i, 0, n) cin >> a[i]; FOR(i, 0, n) cin >> b[i]; set<pi> st; FOR(i, 0, n) st.insert(mp(b[i], i)); long long res = 0; while (sz(st)) { int u = st.rbegin()->se; st.erase(*st.rbegin()); int pu = (u + n - 1) % n; int nu = (u + 1) % n; if (b[u] < a[u]) { cout << -1 << "\n"; return; } if (a[u] < b[u]) { int s = b[pu] + b[nu]; int x = (b[u] - a[u]) / s; chkmin(x, (b[u] - b[nu]) / s + 1); chkmin(x, (b[u] - b[pu]) / s + 1); if (!x) { cout << -1 << "\n"; return; } res += x; b[u] -= s * x; if (b[u] < a[u]) { cout << -1 << "\n"; return; } if (a[u] < b[u]) { st.insert(mp(b[u], u)); } } } cout << res << "\n"; } int main(int argc, char *argv[]) { ios_base::sync_with_stdio(0), cin.tie(0); if (argc > 1) { assert(freopen(argv[1], "r", stdin)); } if (argc > 2) { assert(freopen(argv[2], "wb", stdout)); } solve(); cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
742,380
742,381
u264312457
cpp
p02941
#include <algorithm> #include <complex> #include <fstream> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; const int NMAX = 1e5 + 5; int n, a[NMAX], b[NMAX]; ll ans = 0; pair<int, int> p; bool possible = true; priority_queue<pair<int, int>> valeurs; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = a[n]; a[n + 1] = a[1]; for (int i = 1; i <= n; i++) { cin >> b[i]; if (b[i] != a[i]) valeurs.push(make_pair(b[i], i)); } b[0] = b[n]; b[n + 1] = b[1]; while (!valeurs.empty() && possible) { p = valeurs.top(); valeurs.pop(); int id = p.second; // cout << (int)valeurs.size() << '\n'; // cout << id << ' ' << b[id] << ' '; if (b[id] - (b[id - 1] + b[id + 1]) < a[id]) possible = false; else { int rep = (b[id] - a[id]) / (b[id - 1] + b[id + 1]); ans += rep; b[id] -= (b[id - 1] + b[id + 1]) * rep; if (id == n) b[n] = b[id]; if (id == 1) b[n + 1] = b[id]; if (b[id] != a[id]) valeurs.push(make_pair(b[id], id)); } // cout << b[id] << ' ' << a[id] << '\n'; } /*for(int i=1;i<=n;i++) cout << b[i] << ' '; cout << '\n';*/ if (possible) cout << ans << '\n'; else cout << -1 << '\n'; return 0; }
#include <algorithm> #include <complex> #include <fstream> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; const int NMAX = 2 * 1e5 + 5; int n, a[NMAX], b[NMAX]; ll ans = 0; pair<int, int> p; bool possible = true; priority_queue<pair<int, int>> valeurs; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = a[n]; a[n + 1] = a[1]; for (int i = 1; i <= n; i++) { cin >> b[i]; if (b[i] != a[i]) valeurs.push(make_pair(b[i], i)); } b[0] = b[n]; b[n + 1] = b[1]; while (!valeurs.empty() && possible) { p = valeurs.top(); valeurs.pop(); int id = p.second; // cout << (int)valeurs.size() << '\n'; // cout << id << ' ' << b[id] << ' '; if (b[id] - (b[id - 1] + b[id + 1]) < a[id]) possible = false; else { int rep = (b[id] - a[id]) / (b[id - 1] + b[id + 1]); ans += rep; b[id] -= (b[id - 1] + b[id + 1]) * rep; if (id == n) b[0] = b[id]; if (id == 1) b[n + 1] = b[id]; if (b[id] != a[id]) valeurs.push(make_pair(b[id], id)); } // cout << b[id] << ' ' << a[id] << '\n'; } /*for(int i=1;i<=n;i++) cout << b[i] << ' '; cout << '\n';*/ if (possible) cout << ans << '\n'; else cout << -1 << '\n'; return 0; }
[ "assignment.variable.change", "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change" ]
742,441
742,440
u558431380
cpp
p02942
#include <iostream> #include <vector> using namespace std; class BipartiteMatch { public: explicit BipartiteMatch(int N, int M) : N(N), M(M), g(N + M), match(N + M, -1), visit(N + M, 0) {} public: void addEdge(int a, int b) { g[a].push_back(b + N); g[b + N].push_back(a); } int maximumMatch() { int res = 0; fill(match.begin(), match.end(), -1); for (int i = 0; i < N; i++) { fill(visit.begin(), visit.end(), 0); if (search_(i)) ++res; } return res; } int getMatch(int t) const { return t < N ? match[t] - N : match[t]; } private: bool search_(int u) { if (u < 0) return true; for (auto next : g[u]) { if (visit[next]) continue; visit[next] = 1; if (search_(match[next])) { match[u] = next, match[next] = u; return true; } } return false; } private: const int N, M; vector<vector<int>> g; vector<int> match; vector<int> visit; }; int main() { int N, M; cin >> N >> M; vector<vector<int>> A(N, vector<int>(M)); vector<vector<vector<int>>> val(N, vector<vector<int>>(N)); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { int a; cin >> a; val[i][(a - 1) / M].push_back(a); } } vector<vector<int>> B(N); vector<vector<int>> C(N); for (int i = 0; i < M; i++) { BipartiteMatch bm(N, N); for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { if (!val[j][k].empty()) bm.addEdge(j, k); } } cout << bm.maximumMatch() << endl; for (int j = 0; j < N; j++) { int m = bm.getMatch(j); int b = val[j][m].back(); val[j][m].pop_back(); B[j].push_back(b); C[(b - 1) / M].push_back(b); } } for (auto &v : B) { cout << v[0]; for (int i = 1; i < v.size(); i++) cout << " " << v[i]; cout << endl; } for (auto &v : C) { cout << v[0]; for (int i = 1; i < v.size(); i++) cout << " " << v[i]; cout << endl; } }
#include <iostream> #include <vector> using namespace std; class BipartiteMatch { public: explicit BipartiteMatch(int N, int M) : N(N), M(M), g(N + M), match(N + M, -1), visit(N + M, 0) {} public: void addEdge(int a, int b) { g[a].push_back(b + N); g[b + N].push_back(a); } int maximumMatch() { int res = 0; fill(match.begin(), match.end(), -1); for (int i = 0; i < N; i++) { fill(visit.begin(), visit.end(), 0); if (search_(i)) ++res; } return res; } int getMatch(int t) const { return t < N ? match[t] - N : match[t]; } private: bool search_(int u) { if (u < 0) return true; for (auto next : g[u]) { if (visit[next]) continue; visit[next] = 1; if (search_(match[next])) { match[u] = next, match[next] = u; return true; } } return false; } private: const int N, M; vector<vector<int>> g; vector<int> match; vector<int> visit; }; int main() { int N, M; cin >> N >> M; vector<vector<int>> A(N, vector<int>(M)); vector<vector<vector<int>>> val(N, vector<vector<int>>(N)); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { int a; cin >> a; val[i][(a - 1) / M].push_back(a); } } vector<vector<int>> B(N); vector<vector<int>> C(N); for (int i = 0; i < M; i++) { BipartiteMatch bm(N, N); for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { if (!val[j][k].empty()) bm.addEdge(j, k); } } bm.maximumMatch(); for (int j = 0; j < N; j++) { int m = bm.getMatch(j); int b = val[j][m].back(); val[j][m].pop_back(); B[j].push_back(b); C[(b - 1) / M].push_back(b); } } for (auto &v : B) { cout << v[0]; for (int i = 1; i < v.size(); i++) cout << " " << v[i]; cout << endl; } for (auto &v : C) { cout << v[0]; for (int i = 1; i < v.size(); i++) cout << " " << v[i]; cout << endl; } }
[ "expression.operation.binary.remove" ]
742,477
742,478
u002023395
cpp
p02942
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100 + 10; vector<int> g[N]; int vis[N], match[N]; bool dfs(int u) { if (vis[u]) return false; vis[u] = 1; for (int v : g[u]) if (!match[v] || dfs(v)) { match[v] = u; return true; } return false; } int a[N][N], b[N][N], c[N][N], ok[N][N], n, m; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j], ok[i][j] = 1; for (int col = 1; col <= m; col++) { for (int i = 1; i <= n; i++) g[i].clear(); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (ok[i][j]) { g[i].push_back((a[i][j] - 1) / m + 1); } memset(match, 0, sizeof(match)); for (int i = 1; i <= n; i++) memset(vis, 0, sizeof(vis)), dfs(i); for (int i = 1; i <= n; i++) { int x; for (int j = 1; j <= n; j++) if (match[j] == i) x = j; for (int j = 1; j <= m; j++) if (ok[i][j]) { if ((a[i][j] - 1) / m + 1 == x) { b[i][col] = a[i][j]; ok[i][j] = 0; break; } } } } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) c[(b[i][j] - 1) / m + 1][j] = b[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) printf("%d%c", b[i][j], " \n"[j == m]); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) printf("%d%c", c[i][j], " \n"[j == m]); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100 + 10; vector<int> g[N]; int vis[N], match[N]; bool dfs(int u) { if (vis[u]) return false; vis[u] = 1; for (int v : g[u]) if (!match[v] || dfs(match[v])) { match[v] = u; return true; } return false; } int a[N][N], b[N][N], c[N][N], ok[N][N], n, m; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j], ok[i][j] = 1; for (int col = 1; col <= m; col++) { for (int i = 1; i <= n; i++) g[i].clear(); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (ok[i][j]) { g[i].push_back((a[i][j] - 1) / m + 1); } memset(match, 0, sizeof(match)); for (int i = 1; i <= n; i++) memset(vis, 0, sizeof(vis)), dfs(i); for (int i = 1; i <= n; i++) { int x; for (int j = 1; j <= n; j++) if (match[j] == i) x = j; for (int j = 1; j <= m; j++) if (ok[i][j]) { if ((a[i][j] - 1) / m + 1 == x) { b[i][col] = a[i][j]; ok[i][j] = 0; break; } } } } for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) c[(b[i][j] - 1) / m + 1][j] = b[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) printf("%d%c", b[i][j], " \n"[j == m]); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) printf("%d%c", c[i][j], " \n"[j == m]); }
[ "control_flow.branch.if.condition.change" ]
742,487
742,488
u401742026
cpp
p02942
#include <bits/stdc++.h> using namespace std; #define ll long long #define REP(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; i++) #define DREP(i, a, b) for (int i = (a), _end_ = (b); i >= _end_; i--) #define EREP(i, u) for (int i = start[u]; i; i = e[i].next) #define fi first #define se second #define mkr(a, b) make_pair(a, b) #define SZ(A) ((int)A.size()) template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } inline void myassert(bool a, string s) { if (!a) cerr << s << endl, exit(0); } inline int read() { int s = 0, f = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') ch = getchar(), f = -1; while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar(); return ~f ? s : -s; } const int maxn = 120; int n, m, col[maxn][maxn]; vector<int> rest[maxn][maxn]; inline void init() { n = read(); m = read(); REP(i, 1, n) REP(j, 1, m) { int x = read(); col[i][j] = (x + m - 1) / m; rest[i][col[i][j]].push_back(x); } } int f[maxn][maxn]; int mch[maxn], vis[maxn]; inline bool dfs(int u) { REP(v, 1, n) if (f[u][v] && !vis[v]) { vis[v] = 1; if (!mch[v] || dfs(v)) { mch[v] = u; return 1; } } return 0; } int B[maxn][maxn]; int C[maxn][maxn]; inline void doing() { REP(k, 1, m) { REP(i, 1, n) REP(j, 1, n) f[i][j] = !rest[i][j].empty(); memset(mch, 0, sizeof(int) * (n + 1)); REP(i, 1, n) { memset(vis, 0, sizeof(int) * (n + 1)); dfs(i); } REP(i, 1, n) { int x = mch[i], y = i; B[x][k] = rest[x][y].back(); rest[x][y].pop_back(); C[y][k] = B[x][k]; } } REP(i, 1, n) REP(j, 1, m) printf("%d%c", B[i][j], j == m ? '\n' : ' '); REP(i, 1, n) REP(j, 1, m) printf("%d%c", C[i][j], j == m ? '\n' : ' '); } int main() { init(); doing(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define REP(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; i++) #define DREP(i, a, b) for (int i = (a), _end_ = (b); i >= _end_; i--) #define EREP(i, u) for (int i = start[u]; i; i = e[i].next) #define fi first #define se second #define mkr(a, b) make_pair(a, b) #define SZ(A) ((int)A.size()) template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } inline void myassert(bool a, string s) { if (!a) cerr << s << endl, exit(0); } inline int read() { int s = 0, f = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') ch = getchar(), f = -1; while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar(); return ~f ? s : -s; } const int maxn = 120; int n, m, col[maxn][maxn]; vector<int> rest[maxn][maxn]; inline void init() { n = read(); m = read(); REP(i, 1, n) REP(j, 1, m) { int x = read(); col[i][j] = (x + m - 1) / m; rest[i][col[i][j]].push_back(x); } } int f[maxn][maxn]; int mch[maxn], vis[maxn]; inline bool dfs(int u) { REP(v, 1, n) if (f[u][v] && !vis[v]) { vis[v] = 1; if (!mch[v] || dfs(mch[v])) { mch[v] = u; return 1; } } return 0; } int B[maxn][maxn]; int C[maxn][maxn]; inline void doing() { REP(k, 1, m) { REP(i, 1, n) REP(j, 1, n) f[i][j] = !rest[i][j].empty(); memset(mch, 0, sizeof(int) * (n + 1)); REP(i, 1, n) { memset(vis, 0, sizeof(int) * (n + 1)); dfs(i); } REP(i, 1, n) { int x = mch[i], y = i; B[x][k] = rest[x][y].back(); rest[x][y].pop_back(); C[y][k] = B[x][k]; } } REP(i, 1, n) REP(j, 1, m) printf("%d%c", B[i][j], j == m ? '\n' : ' '); REP(i, 1, n) REP(j, 1, m) printf("%d%c", C[i][j], j == m ? '\n' : ' '); } int main() { init(); doing(); return 0; }
[ "control_flow.branch.if.condition.change" ]
742,495
742,496
u057222094
cpp
p02943
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #include <bits/stdc++.h> 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 = 5005; char mc = 'z', s[N << 1]; int n, k, f[N << 1], ma, p; bool compare(int l, int r) { for (; s[l] == s[r]; l++, r++) ; return s[l] < s[r]; } signed main() { read(n, k); k = min(k, 15); scanf("%s", s + 1); for (int i = 1; i <= n; i++) s[n * 2 - i + 1] = s[i]; for (int i = 1; i <= n; i++) s[i] < mc ? mc = s[i] : 1; for (int i = n; i; i--) f[i] = s[i] == mc ? f[i + 1] + 1 : 0, ma = f[i] > ma ? f[i] : ma; int rest = max(n - (ma << k - 1), 0); for (int i = 1; i <= n; i++) if (f[i] == ma && (!p || compare(i + ma, p))) p = i + ma; for (int i = 1; i <= n - rest; i++) putchar(mc); for (int i = 0; i < rest; i++) putchar(s[p + i]); }
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #include <bits/stdc++.h> 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 = 5005; char mc = 'z', s[N << 1]; int n, k, f[N << 1], ma, p; bool compare(int l, int r) { for (; s[l] == s[r]; l++, r++) ; return s[l] < s[r]; } signed main() { read(n, k); k = min(k, 15); scanf("%s", s + 1); for (int i = 1; i <= n; i++) s[n * 2 - i + 1] = s[i]; for (int i = 1; i <= n; i++) s[i] < mc ? mc = s[i] : 1; for (int i = n * 2; i; i--) f[i] = s[i] == mc ? f[i + 1] + 1 : 0, ma = f[i] > ma ? f[i] : ma; int rest = max(n - (ma << k - 1), 0); for (int i = 1; i <= n; i++) if (f[i] == ma && (!p || compare(i + ma, p))) p = i + ma; // write(ma);return 0; for (int i = 1; i <= n - rest; i++) putchar(mc); for (int i = 0; i < rest; i++) putchar(s[p + i]); }
[ "control_flow.loop.for.initializer.change" ]
742,536
742,537
u052435908
cpp
p02943
#include <bits/stdc++.h> using namespace std; #define N 10010 int n, k; char s[N], st[N]; int id[N], x[N], y[N], c[N]; void build(char *s) { int n = strlen(s) + 1, m = 256; for (int i = 0; i < m; i++) c[i] = 0; for (int i = 0; i < n; i++) c[x[i] = s[i]]++; for (int i = 1; i < m; i++) c[i] += c[i - 1]; for (int i = n - 1; i >= 0; i--) id[--c[x[i]]] = i; for (int j = 1, p = 1; p < n; j <<= 1, m = p) { p = 0; for (int i = n - j; i < n; i++) y[p++] = i; for (int i = 0; i < n; i++) if (id[i] >= j) y[p++] = id[i] - j; for (int i = 0; i < m; i++) c[i] = 0; for (int i = 0; i < n; i++) c[x[i]]++; for (int i = 1; i < m; i++) c[i] += c[i - 1]; for (int i = n - 1; i >= 0; i--) id[--c[x[y[i]]]] = y[i]; swap(x, y); x[id[0]] = 0, p = 1; for (int i = 1; i < n; i++) { x[id[i]] = (y[id[i]] == y[id[i - 1]] && y[id[i] + j] == y[id[i - 1] + j]) ? p - 1 : p++; } } } int main() { scanf("%d %d %s", &n, &k, s); strcpy(st, s); reverse(st, st + strlen(st)); strcat(s, st); k--; build(s); int t = 1; for (; id[t] >= n; t++) ; t = id[t]; int l = 1; while (l < n && s[t + l] == s[t]) l++; vector<char> vec; for (int i = l; i < n; i++) vec.push_back(s[t + i]); while (k--) { l <<= 1; if (l >= n) break; } for (int i = 0; i < l; i++) putchar(s[t]); for (int i = l; i < n; i++) putchar(vec[i - l]); puts(""); }
#include <bits/stdc++.h> using namespace std; #define N 10010 int n, k; char s[N], st[N]; int id[N], x[N], y[N], c[N]; void build(char *s) { int n = strlen(s) + 1, m = 256; for (int i = 0; i < m; i++) c[i] = 0; for (int i = 0; i < n; i++) c[x[i] = s[i]]++; for (int i = 1; i < m; i++) c[i] += c[i - 1]; for (int i = n - 1; i >= 0; i--) id[--c[x[i]]] = i; for (int j = 1, p = 1; p < n; j <<= 1, m = p) { p = 0; for (int i = n - j; i < n; i++) y[p++] = i; for (int i = 0; i < n; i++) if (id[i] >= j) y[p++] = id[i] - j; for (int i = 0; i < m; i++) c[i] = 0; for (int i = 0; i < n; i++) c[x[i]]++; for (int i = 1; i < m; i++) c[i] += c[i - 1]; for (int i = n - 1; i >= 0; i--) id[--c[x[y[i]]]] = y[i]; swap(x, y); x[id[0]] = 0, p = 1; for (int i = 1; i < n; i++) { x[id[i]] = (y[id[i]] == y[id[i - 1]] && y[id[i] + j] == y[id[i - 1] + j]) ? p - 1 : p++; } } } int main() { scanf("%d %d %s", &n, &k, s); strcpy(st, s); reverse(st, st + strlen(st)); strcat(s, st); k--; build(s); int t = 1; for (; id[t] >= n; t++) ; t = id[t]; int l = 1; while (l < n && s[t + l] == s[t]) l++; vector<char> vec; for (int i = l; i < n; i++) vec.push_back(s[t + i]); while (k--) { l <<= 1; if (l >= n) break; } for (int i = 0; i < min(n, l); i++) putchar(s[t]); for (int i = l; i < n; i++) putchar(vec[i - l]); puts(""); }
[ "control_flow.loop.for.condition.change", "call.add", "call.arguments.change" ]
742,540
742,541
u074493292
cpp
p02943
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long int n, k; string s; string go(string s, int h) { string ret; for (int i = h; i < n; i++) { ret += s[i]; } for (int i = n - 1; i >= n - h; i--) { ret += s[i]; } return ret; } string calc(string s, int k) { if (k == 0) return s; int cnt = 0; char c = s.back(); while (cnt < n && s[n - cnt - 1] == c) { cnt++; } if (cnt == n) return s; while (k > 1) { cnt *= 2; k--; if (cnt >= n) { return string(n, c); } } while (s.back() == c) { s.pop_back(); } s += string(cnt, c); s = s.substr((int)s.size() - n); int r = s.size() - 1; while (s[r] == c) r--; r++; return go(s, r); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> s; string ans = s; ans = min(s, calc(s, k)); for (int i = 0; i < n; i++) { string cur = go(s, i); ans = min(ans, calc(cur, k - 1)); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long int n, k; string s; string go(string s, int h) { string ret; for (int i = h; i < n; i++) { ret += s[i]; } for (int i = n - 1; i >= n - h; i--) { ret += s[i]; } return ret; } string calc(string s, int k) { if (k == 0) return s; int cnt = 0; char c = s.back(); while (cnt < n && s[n - cnt - 1] == c) { cnt++; } if (cnt == n) return s; while (k > 1) { cnt *= 2; k--; if (cnt >= n) { return string(n, c); } } while (s.back() == c) { s.pop_back(); } s += string(cnt, c); s = s.substr((int)s.size() - n); int r = s.size() - 1; while (s[r] == c) r--; r++; return go(s, r); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> s; string ans = s; ans = min(s, calc(s, k)); for (int i = 0; i <= n; i++) { string cur = go(s, i); ans = min(ans, calc(cur, k - 1)); } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
742,548
742,549
u878355493
cpp
p02943
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using vc = vector<char>; using vvc = vector<vc>; using vb = vector<bool>; using vvb = vector<vb>; using pll = pair<ll, ll>; #define all(v) v.begin(), v.end() const ll INF = 1e18; const ll mod = 1e9 + 7; const double pie = acos(-1); vll dx4 = {-1, 0, 1, 0}; vll dy4 = {0, -1, 0, 1}; vll dx8 = {-1, 0, 1, 1, 1, 0, -1, -1}; vll dy8 = {-1, 1, -1, 0, 1, 1, 1, 0}; void fix_cout() { cout << fixed << setprecision(20); } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } void chmax(ll &a, ll b) { if (a < b) a = b; } void chmin(ll &a, ll b) { if (a > b) a = b; } int main() { ll n, k; cin >> n >> k; string s, t; cin >> s; ll cnt = 0; for (int i = 1; i < k; i++) { bool ok = true; for (int j = 0; j < n; j++) ok &= (s.at(0) == s.at(j)); if (ok) break; if (i == 1) { string tmp = ""; tmp += (char)('z' + 1); for (int j = 0; j < n; j++) { t = ""; for (int l = 0; l < n; l++) t += s.at(min((ll)j + l, 2 * n - 1 - j - l)); reverse(all(t)); tmp = min(tmp, t); } s = tmp; for (int j = 0; j < n; j++) { if (s.at(j) != s.at(0)) break; cnt++; } reverse(all(s)); } else { t = ""; for (int j = 0; j < n; j++) t += s.at(min(n - cnt + j, n - 1 + cnt - j)); reverse(all(t)); s = t; cnt = min(cnt * 2, n); } } string tmp = ""; tmp += (char)('z' + 1); for (int i = 0; i < n; i++) { t = ""; for (int j = 0; j < n; j++) t += s.at(min((ll)i + j, 2 * n - 1 - i - j)); tmp = min(tmp, t); } s = tmp; cout << s << endl; }
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using vc = vector<char>; using vvc = vector<vc>; using vb = vector<bool>; using vvb = vector<vb>; using pll = pair<ll, ll>; #define all(v) v.begin(), v.end() const ll INF = 1e18; const ll mod = 1e9 + 7; const double pie = acos(-1); vll dx4 = {-1, 0, 1, 0}; vll dy4 = {0, -1, 0, 1}; vll dx8 = {-1, 0, 1, 1, 1, 0, -1, -1}; vll dy8 = {-1, 1, -1, 0, 1, 1, 1, 0}; void fix_cout() { cout << fixed << setprecision(20); } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } void chmax(ll &a, ll b) { if (a < b) a = b; } void chmin(ll &a, ll b) { if (a > b) a = b; } int main() { ll n, k; cin >> n >> k; string s, t; cin >> s; ll cnt = 0; for (int i = 1; i < k; i++) { bool ok = true; for (int j = 0; j < n; j++) ok &= (s.at(0) == s.at(j)); if (ok) break; if (i == 1) { string tmp = ""; tmp += (char)('z' + 1); for (int j = 0; j <= n; j++) { t = ""; for (int l = 0; l < n; l++) t += s.at(min((ll)j + l, 2 * n - 1 - j - l)); reverse(all(t)); tmp = min(tmp, t); } s = tmp; for (int j = 0; j < n; j++) { if (s.at(j) != s.at(0)) break; cnt++; } reverse(all(s)); } else { t = ""; for (int j = 0; j < n; j++) t += s.at(min(n - cnt + j, n - 1 + cnt - j)); reverse(all(t)); s = t; cnt = min(cnt * 2, n); } } string tmp = ""; tmp += (char)('z' + 1); for (int i = 0; i <= n; i++) { t = ""; for (int j = 0; j < n; j++) t += s.at(min((ll)i + j, 2 * n - 1 - i - j)); tmp = min(tmp, t); } s = tmp; cout << s << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
742,550
742,551
u993074316
cpp
p02943
/* * じょえチャンネル * 高評価・チャンネル登録よろしくおねがいします! * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ */ #include <bits/stdc++.h> //#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") // here!!! // define int long long !!!!! #define int long long // define int long long !!!!! #define mod 1000000007ll // constexpr int mod = 998244353ll; typedef long long ll; #ifdef int #define inf (int)(3e18) #else #define inf (int)(5e8) #endif #define intt long long #define itn long long #define P pair<long long, long long> #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) #define rev_rep(i, n) for (int i = n - 1; i >= 0; i--) #define REV_REP(i, n) for (int i = n; i >= 1; i--) #define ALL(v) v.begin(), v.end() #define smallpriority_queue(x) priority_queue<x, vector<x>, greater<x>> using namespace std; // Library //モッドパウ inline int modpow(int x, int y, int m = mod) { int res = 1; while (y) { if (y & 1) { res *= x; res %= m; } x = x * x % m; y /= 2; } return res; } int mypow(int x, int y) { int res = 1; while (y) { if (y % 2) { res *= x; } x = x * x; y /= 2; } return res; } // is the number (x) a prime number? bool prime(int x) { if (!x || x == 1) { return false; } for (int i = 2; i * i <= x; i++) { if (!(x % i)) { return false; } } return true; } // saidai-kouyakusuu inline int gcd(int x, int y) { if (!y) { return x; } return gcd(y, x % y); } // number of keta int keta(int x) { int ans = 0; while (x) { x /= 10; ans++; } return ans; } // number of 2shinsuu keta int bitketa(int x) { int ans = 0; while (x) { x >>= 1; ans++; } return ans; } // sum of keta int ketasum(int x) { int ans = 0; while (x) { ans += x % 10; x /= 10; } return ans; } inline int lcm(int x, int y) { int ans = x / gcd(x, y) * y; return ans; } int twobeki(int x) { int ans = 0; while (1) { if (!(x & 1)) { ans++; x >>= 1; } else { break; } } return ans; } template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } #define fin(i) scanf("%lld", &i) #define fout(i) printf("%lld", i) #define fendl printf("\n") int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int comb(int x, int y) { if (y > x) return 0; // cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl; return kai(x, y) * modpow(kai(y, y), mod - 2) % mod; } // Library-End #define vecin(v) \ for (int i = 0; i < v.size(); i++) \ scanf("%lld", &v[i]); #define vecout(v) \ { \ for (int i = 0; i < (int)v.size(); i++) \ printf("%lld ", v[i]); \ printf("\n"); \ } template <typename T> class kaageSegTree { protected: unsigned int n = 1, rank = 0; std::vector<T> node; T nodee; virtual T nodef(const T &, const T &) const = 0; public: kaageSegTree(unsigned int m, T init, T nodee) : nodee(nodee) { while (n < m) { n *= 2; rank++; } node.resize(2 * n); for (unsigned int i = n; i < 2 * n; i++) node[i] = init; } kaageSegTree(const std::vector<T> &initvec, T nodee) : nodee(nodee) { unsigned int m = initvec.size(); while (n < m) { n *= 2; rank++; } node.resize(2 * n); for (unsigned int i = n; i < 2 * n; i++) { if (i - n < m) node[i] = initvec[i - n]; } } virtual void update(int i, T x) { i += n; node[i] = x; while (i != 1) { i >>= 1; node[i] = nodef(node[2 * i], node[2 * i + 1]); } } virtual T query(int l, int r) { l += n; r += n; T ls = nodee, rs = nodee; while (l < r) { if (l & 1) { ls = nodef(ls, node[l]); l++; } if (r & 1) { r--; rs = nodef(node[r], rs); } l >>= 1; r >>= 1; } return nodef(ls, rs); } virtual T operator[](const int &x) { return node[n + x]; } void fill(T x) { std::fill(ALL(node), x); } void print() { rep(i, n) std::cout << operator[](i) << " "; std::cout << std::endl; } }; class RSQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return lhs + rhs; } public: RSQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, 0) {} RSQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, 0) {} }; class RMiQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return std::min(lhs, rhs); } public: RMiQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, inf) {} RMiQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, inf) {} }; class RMaQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return std::max(lhs, rhs); } public: RMaQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, -inf) {} RMaQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, -inf) {} }; template <typename T, typename U> class IntervalSegTree : public kaageSegTree<T> { protected: using kaageSegTree<T>::n; using kaageSegTree<T>::rank; using kaageSegTree<T>::node; using kaageSegTree<T>::nodef; using kaageSegTree<T>::nodee; std::vector<U> lazy; std::vector<bool> lazyflag; std::vector<int> width; virtual void lazyf(U &, const U &) = 0; virtual void updf(T &, const U &, const unsigned int &) = 0; void eval(int k) { for (int i = rank; i > 0; i--) { int nk = k >> i; if (lazyflag[nk]) { updf(node[2 * nk], lazy[nk], width[2 * nk]); updf(node[2 * nk + 1], lazy[nk], width[2 * nk + 1]); if (lazyflag[2 * nk]) lazyf(lazy[2 * nk], lazy[nk]); else lazy[2 * nk] = lazy[nk]; if (lazyflag[2 * nk + 1]) lazyf(lazy[2 * nk + 1], lazy[nk]); else lazy[2 * nk + 1] = lazy[nk]; lazyflag[2 * nk] = lazyflag[2 * nk + 1] = true; lazyflag[nk] = false; } } } public: IntervalSegTree(unsigned int m, T init, T nodee) : kaageSegTree<T>(m, init, nodee) { lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n); width[1] = n; for (unsigned int i = 2; i < 2 * n; i++) { width[i] = width[i >> 1] >> 1; } } IntervalSegTree(T nodee, const std::vector<T> &initvec) : kaageSegTree<T>(initvec, nodee) { lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n); width[1] = n; for (unsigned int i = 2; i < 2 * n; i++) { width[i] = width[i >> 1] >> 1; } } void update(int i, U x) { i += n; eval(i); updf(node[i], x, width[i]); if (lazyflag[i]) lazyf(lazy[i], x); else { lazyflag[i] = true; lazy[i] = x; } while (i /= 2) node[i] = nodef(node[2 * i], node[2 * i + 1]); } void update(int l, int r, U x) { l += n; r += n; int nl = l, nr = r; while (!(nl & 1)) nl >>= 1; while (!(nr & 1)) nr >>= 1; nr--; eval(nl); eval(nr); while (l < r) { if (l & 1) { updf(node[l], x, width[l]); if (lazyflag[l]) lazyf(lazy[l], x); else { lazyflag[l] = true; lazy[l] = x; } l++; } if (r & 1) { r--; updf(node[r], x, width[r]); if (lazyflag[r]) lazyf(lazy[r], x); else { lazyflag[r] = true; lazy[r] = x; } } l >>= 1; r >>= 1; } while (nl >>= 1) node[nl] = nodef(node[2 * nl], node[2 * nl + 1]); while (nr >>= 1) node[nr] = nodef(node[2 * nr], node[2 * nr + 1]); } T query(int l, int r) { l += n; r += n; eval(l); eval(r - 1); int ls = nodee, rs = nodee; while (l < r) { if (l & 1) { ls = nodef(ls, node[l]); l++; } if (r & 1) { r--; rs = nodef(node[r], rs); } l >>= 1; r >>= 1; } return nodef(ls, rs); } T operator[](const int &x) { eval(n + x); return node[n + x]; } T queryForAll() { return node[1]; } }; class RAQRSQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return a + b; } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += width * b; } public: RAQRSQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, 0) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRSQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>((int)0, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RAQRMiQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::min(a, b); } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += b; } public: RAQRMiQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRMiQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RAQRMaQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::max(a, b); } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += b; } public: RAQRMaQ(unsigned int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, -inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRMaQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(-inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRSQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return a + b; } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = width * b; } public: RUQRSQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, 0) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRSQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>((int)0, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRMiQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::min(a, b); } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = b; } public: RUQRMiQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRMiQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRMaQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::max(a, b); } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = b; } public: RUQRMaQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, -inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRMaQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(-inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; ////SegTree // template <class T> // class SegTree { // int n; // 葉の数 // vector<T> node; // データを格納するvector // T def; // 初期値かつ単位元 // function<T(T, T)> operation; // 区間クエリで使う処理 // function<T(T, T)> update; // 点更新で使う処理 // // // 区間[a,b)の総和。ノードk=[l,r)に着目している。 // T _query(int a, int b, int k, int l, int r) { // if (r <= a || b <= l) return def; // 交差しない // if (a <= l && r <= b) // return node[k]; // a,l,r,bの順で完全に含まれる // else { // T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 // T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 // return operation(c1, c2); // } // } // // public: // // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数, // // _update:更新関数 // SegTree(size_t _n, T _def, function<T(T, T)> _operation, // function<T(T, T)> _update) // : def(_def), operation(_operation), update(_update) { // n = 1; // while (n < _n) { // n *= 2; // } // node = vector<T>(2 * n , def); // } // // // 場所i(0-indexed)の値をxで更新 // void change(int i, T x) { // i += n - 1; // node[i] = update(node[i], x); // while (i > 0) { // i = (i - 1) / 2; // node[i] = operation(node[i * 2 + 1], node[i * 2 + 2]); // } // } // // // [a, b)の区間クエリを実行 // T query(int a, int b) { // return _query(a, b, 0, 0, n); // } // // // 添字でアクセス // T operator[](int i) { // return node[i + n - 1]; // } //}; template <class T> class SegTree { int n; vector<T> node; T def; function<T(T, T)> operation; function<T(T, T)> update; public: SegTree(unsigned int _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } node = vector<T>(n * 2, def); } SegTree(vector<int> &initvec, function<T(T, T)> _operation, function<T(T, T)> _update) : operation(_operation), update(_update) { n = 1; while (n < initvec.size()) { n *= 2; } node = vector<T>(n * 2, def); for (int i = n; i < n + initvec.size(); i++) { node[i] = initvec[i - n]; } for (int i = n - 1; i >= 1; i--) { node[i] = operation(node[i * 2], node[i * 2 + 1]); } } void change(int i, T x) { i += n; node[i] = update(node[i], x); while (i >= 1) { i >>= 1; node[i] = operation(node[i * 2], node[i * 2 + 1]); } } T query(int l, int r) { l += n; r += n; T rx = def, lx = def; while (l < r) { if (l & 1) { lx = operation(lx, node[l]); l++; } if (r & 1) { r--; rx = operation(node[r], rx); } l >>= 1; r >>= 1; } return operation(lx, rx); } T operator[](const int &x) { return node[x + n]; } void fill(T x) { std::fill(ALL(node), x); } void print() { rep(i, n) std::cout << operator[](i) << " "; std::cout << std::endl; } }; #define R_MIN ([](P a, P b) { return min(a, b); }) #define R_MAX ([](long long a, long long b) { return max(a, b); }) #define R_SUM ([](long long a, long long b) { return a + b; }) #define NORMAL_UPDATE ([](P a, P b) { return b; }) #define ADD_UPDATE ([](long long a, long long b) { return a + b; }) #define MINUS_UPDATE ([](long long a, long long b) { return a - b; } class Union_Find { vector<int> par; vector<int> rankmy; vector<int> ookisa; public: Union_Find(int size) { par = vector<int>(size); rankmy = vector<int>(size); ookisa = vector<int>(size); for (int i = 0; i < size; i++) { par[i] = i; ookisa[i] = 1; } } int find(int x) { if (par[x] == x) { return x; } return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } if (rankmy[x] < rankmy[y]) { par[x] = y; ookisa[y] += ookisa[x]; ookisa[x] = 0; } else { par[y] = x; ookisa[x] += ookisa[y]; ookisa[y] = 0; if (rankmy[x] == rankmy[y]) { rankmy[x]++; } } } int size(int i) { i = find(i); return ookisa[i]; } bool same(int x, int y) { return find(x) == find(y); } }; class BIT { vector<int> data; int size = 0; public: BIT(int _size) { data = vector<int>(_size + 1); size = _size; } void add(int i, int x) { while (i <= size) { data[i] += x; i += i & -i; } } int sum(int i) { assert(i <= size); int s = 0; while (i > 0) { s += data[i]; i -= i & -i; } return s; } int lower_bound(int x) { if (x <= 0) { return 0; } else { int i = 0; int r = 1; while (r < size) r = r << 1; for (int len = r; len > 0; len = len >> 1) { if (i + len < size && data[i + len] < x) { x -= data[i + len]; i += len; } } return i + 1; } } }; // Union-Find-End int perm[2000005]; void init_perm() { perm[0] = 1; REP(i, 2000004) { perm[i] = perm[i - 1] * i % mod; } } int nCk(int x, int y) { if (y > x) { return 0; } if (x < 0) { return 0; } return perm[x] * modpow(perm[x - y], mod - 2) % mod * modpow(perm[y], mod - 2) % mod; } double kyori(pair<int, int> f, pair<int, int> s) { double ans = 0; double t = fabs(f.first - s.first); double y = fabs(f.second - s.second); ans = sqrt(t * t + y * y); return ans; } inline string stringmax(string &x, string &y) { if (x.size() > y.size()) { return x; } if (x.size() < y.size()) { return y; } rep(i, x.size()) { if (x[i] > y[i]) { return x; } if (x[i] < y[i]) { return y; } } return x; } vector<int> RollingHash(string &s, string &t) { vector<int> ans; __int128 h = 0, hamod = 0, ki = 0, kim = 0, hikaku = 0, one = 0; one = 1; ki = 1000000007ll; hamod = (one << 61) - 1; kim = 1; rep(i, t.size()) { hikaku *= ki; h *= ki; kim *= ki; hikaku += t[i]; h += s[i]; hikaku %= hamod; h %= hamod; kim %= hamod; } rep(i, (int)s.size() - (int)t.size() + 1) { if (h == hikaku) { ans.emplace_back(i); } h *= ki; h %= hamod; h += s[i + (int)t.size()]; h %= hamod; h += hamod; h -= s[i] * kim % hamod; h %= hamod; } return ans; } struct edge { int to; int length; edge(int _to, int _length) { to = _to; length = _length; } }; vector<int> djkstra(vector<vector<edge>> &road, int start) { vector<int> kyo(road.size(), inf); smallpriority_queue(P) q; q.push({0, start}); kyo[start] = 0; while (q.size()) { int x = q.top().second; itn now = q.top().first; q.pop(); if (kyo[x] < now) { continue; } for (auto &i : road[x]) { if (kyo[i.to] > now + i.length) { kyo[i.to] = now + i.length; q.push({kyo[i.to], i.to}); } } } return kyo; } #define endl "\n" // interactive の時に注意!!! #define Endl "\n" // interactive の時に注意!!! #define printd cout << fixed << setprecision(10) #define rrep(i, f, s) for (int i = f; i < s; i++) #define RREP(i, f, s) for (int i = f; i <= s; i++) int n, k; string s, t, t2; signed main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n >> k >> s; char c = 'a' + 27; rep(i, n) { chmin(c, s[i]); } if (bitketa(n) + 1 <= k) { rep(i, n) { cout << c; } cout << endl; return 0; } t = s; t2 = s; rep(i, k) { string v(n + 1, 'z'), v2(n + 1, 'z'); string l = t; reverse(ALL(t)); l += t; rep(j, n) { string k = l.substr(j, n); chmin(v, k); reverse(ALL(k)); chmin(v2, k); } l = t2; reverse(ALL(t2)); l += t2; rep(j, n) { string k = l.substr(j, n); chmin(v, k); reverse(ALL(k)); chmin(v2, k); } t = v; reverse(ALL(v2)); t2 = v2; } cout << t << endl; }
/* * じょえチャンネル * 高評価・チャンネル登録よろしくおねがいします! * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ */ #include <bits/stdc++.h> //#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") // here!!! // define int long long !!!!! #define int long long // define int long long !!!!! #define mod 1000000007ll // constexpr int mod = 998244353ll; typedef long long ll; #ifdef int #define inf (int)(3e18) #else #define inf (int)(5e8) #endif #define intt long long #define itn long long #define P pair<long long, long long> #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) #define rev_rep(i, n) for (int i = n - 1; i >= 0; i--) #define REV_REP(i, n) for (int i = n; i >= 1; i--) #define ALL(v) v.begin(), v.end() #define smallpriority_queue(x) priority_queue<x, vector<x>, greater<x>> using namespace std; // Library //モッドパウ inline int modpow(int x, int y, int m = mod) { int res = 1; while (y) { if (y & 1) { res *= x; res %= m; } x = x * x % m; y /= 2; } return res; } int mypow(int x, int y) { int res = 1; while (y) { if (y % 2) { res *= x; } x = x * x; y /= 2; } return res; } // is the number (x) a prime number? bool prime(int x) { if (!x || x == 1) { return false; } for (int i = 2; i * i <= x; i++) { if (!(x % i)) { return false; } } return true; } // saidai-kouyakusuu inline int gcd(int x, int y) { if (!y) { return x; } return gcd(y, x % y); } // number of keta int keta(int x) { int ans = 0; while (x) { x /= 10; ans++; } return ans; } // number of 2shinsuu keta int bitketa(int x) { int ans = 0; while (x) { x >>= 1; ans++; } return ans; } // sum of keta int ketasum(int x) { int ans = 0; while (x) { ans += x % 10; x /= 10; } return ans; } inline int lcm(int x, int y) { int ans = x / gcd(x, y) * y; return ans; } int twobeki(int x) { int ans = 0; while (1) { if (!(x & 1)) { ans++; x >>= 1; } else { break; } } return ans; } template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } #define fin(i) scanf("%lld", &i) #define fout(i) printf("%lld", i) #define fendl printf("\n") int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int comb(int x, int y) { if (y > x) return 0; // cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl; return kai(x, y) * modpow(kai(y, y), mod - 2) % mod; } // Library-End #define vecin(v) \ for (int i = 0; i < v.size(); i++) \ scanf("%lld", &v[i]); #define vecout(v) \ { \ for (int i = 0; i < (int)v.size(); i++) \ printf("%lld ", v[i]); \ printf("\n"); \ } template <typename T> class kaageSegTree { protected: unsigned int n = 1, rank = 0; std::vector<T> node; T nodee; virtual T nodef(const T &, const T &) const = 0; public: kaageSegTree(unsigned int m, T init, T nodee) : nodee(nodee) { while (n < m) { n *= 2; rank++; } node.resize(2 * n); for (unsigned int i = n; i < 2 * n; i++) node[i] = init; } kaageSegTree(const std::vector<T> &initvec, T nodee) : nodee(nodee) { unsigned int m = initvec.size(); while (n < m) { n *= 2; rank++; } node.resize(2 * n); for (unsigned int i = n; i < 2 * n; i++) { if (i - n < m) node[i] = initvec[i - n]; } } virtual void update(int i, T x) { i += n; node[i] = x; while (i != 1) { i >>= 1; node[i] = nodef(node[2 * i], node[2 * i + 1]); } } virtual T query(int l, int r) { l += n; r += n; T ls = nodee, rs = nodee; while (l < r) { if (l & 1) { ls = nodef(ls, node[l]); l++; } if (r & 1) { r--; rs = nodef(node[r], rs); } l >>= 1; r >>= 1; } return nodef(ls, rs); } virtual T operator[](const int &x) { return node[n + x]; } void fill(T x) { std::fill(ALL(node), x); } void print() { rep(i, n) std::cout << operator[](i) << " "; std::cout << std::endl; } }; class RSQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return lhs + rhs; } public: RSQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, 0) {} RSQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, 0) {} }; class RMiQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return std::min(lhs, rhs); } public: RMiQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, inf) {} RMiQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, inf) {} }; class RMaQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return std::max(lhs, rhs); } public: RMaQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, -inf) {} RMaQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, -inf) {} }; template <typename T, typename U> class IntervalSegTree : public kaageSegTree<T> { protected: using kaageSegTree<T>::n; using kaageSegTree<T>::rank; using kaageSegTree<T>::node; using kaageSegTree<T>::nodef; using kaageSegTree<T>::nodee; std::vector<U> lazy; std::vector<bool> lazyflag; std::vector<int> width; virtual void lazyf(U &, const U &) = 0; virtual void updf(T &, const U &, const unsigned int &) = 0; void eval(int k) { for (int i = rank; i > 0; i--) { int nk = k >> i; if (lazyflag[nk]) { updf(node[2 * nk], lazy[nk], width[2 * nk]); updf(node[2 * nk + 1], lazy[nk], width[2 * nk + 1]); if (lazyflag[2 * nk]) lazyf(lazy[2 * nk], lazy[nk]); else lazy[2 * nk] = lazy[nk]; if (lazyflag[2 * nk + 1]) lazyf(lazy[2 * nk + 1], lazy[nk]); else lazy[2 * nk + 1] = lazy[nk]; lazyflag[2 * nk] = lazyflag[2 * nk + 1] = true; lazyflag[nk] = false; } } } public: IntervalSegTree(unsigned int m, T init, T nodee) : kaageSegTree<T>(m, init, nodee) { lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n); width[1] = n; for (unsigned int i = 2; i < 2 * n; i++) { width[i] = width[i >> 1] >> 1; } } IntervalSegTree(T nodee, const std::vector<T> &initvec) : kaageSegTree<T>(initvec, nodee) { lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n); width[1] = n; for (unsigned int i = 2; i < 2 * n; i++) { width[i] = width[i >> 1] >> 1; } } void update(int i, U x) { i += n; eval(i); updf(node[i], x, width[i]); if (lazyflag[i]) lazyf(lazy[i], x); else { lazyflag[i] = true; lazy[i] = x; } while (i /= 2) node[i] = nodef(node[2 * i], node[2 * i + 1]); } void update(int l, int r, U x) { l += n; r += n; int nl = l, nr = r; while (!(nl & 1)) nl >>= 1; while (!(nr & 1)) nr >>= 1; nr--; eval(nl); eval(nr); while (l < r) { if (l & 1) { updf(node[l], x, width[l]); if (lazyflag[l]) lazyf(lazy[l], x); else { lazyflag[l] = true; lazy[l] = x; } l++; } if (r & 1) { r--; updf(node[r], x, width[r]); if (lazyflag[r]) lazyf(lazy[r], x); else { lazyflag[r] = true; lazy[r] = x; } } l >>= 1; r >>= 1; } while (nl >>= 1) node[nl] = nodef(node[2 * nl], node[2 * nl + 1]); while (nr >>= 1) node[nr] = nodef(node[2 * nr], node[2 * nr + 1]); } T query(int l, int r) { l += n; r += n; eval(l); eval(r - 1); int ls = nodee, rs = nodee; while (l < r) { if (l & 1) { ls = nodef(ls, node[l]); l++; } if (r & 1) { r--; rs = nodef(node[r], rs); } l >>= 1; r >>= 1; } return nodef(ls, rs); } T operator[](const int &x) { eval(n + x); return node[n + x]; } T queryForAll() { return node[1]; } }; class RAQRSQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return a + b; } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += width * b; } public: RAQRSQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, 0) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRSQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>((int)0, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RAQRMiQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::min(a, b); } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += b; } public: RAQRMiQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRMiQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RAQRMaQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::max(a, b); } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += b; } public: RAQRMaQ(unsigned int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, -inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRMaQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(-inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRSQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return a + b; } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = width * b; } public: RUQRSQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, 0) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRSQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>((int)0, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRMiQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::min(a, b); } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = b; } public: RUQRMiQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRMiQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRMaQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::max(a, b); } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = b; } public: RUQRMaQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, -inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRMaQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(-inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; ////SegTree // template <class T> // class SegTree { // int n; // 葉の数 // vector<T> node; // データを格納するvector // T def; // 初期値かつ単位元 // function<T(T, T)> operation; // 区間クエリで使う処理 // function<T(T, T)> update; // 点更新で使う処理 // // // 区間[a,b)の総和。ノードk=[l,r)に着目している。 // T _query(int a, int b, int k, int l, int r) { // if (r <= a || b <= l) return def; // 交差しない // if (a <= l && r <= b) // return node[k]; // a,l,r,bの順で完全に含まれる // else { // T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 // T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 // return operation(c1, c2); // } // } // // public: // // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数, // // _update:更新関数 // SegTree(size_t _n, T _def, function<T(T, T)> _operation, // function<T(T, T)> _update) // : def(_def), operation(_operation), update(_update) { // n = 1; // while (n < _n) { // n *= 2; // } // node = vector<T>(2 * n , def); // } // // // 場所i(0-indexed)の値をxで更新 // void change(int i, T x) { // i += n - 1; // node[i] = update(node[i], x); // while (i > 0) { // i = (i - 1) / 2; // node[i] = operation(node[i * 2 + 1], node[i * 2 + 2]); // } // } // // // [a, b)の区間クエリを実行 // T query(int a, int b) { // return _query(a, b, 0, 0, n); // } // // // 添字でアクセス // T operator[](int i) { // return node[i + n - 1]; // } //}; template <class T> class SegTree { int n; vector<T> node; T def; function<T(T, T)> operation; function<T(T, T)> update; public: SegTree(unsigned int _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } node = vector<T>(n * 2, def); } SegTree(vector<int> &initvec, function<T(T, T)> _operation, function<T(T, T)> _update) : operation(_operation), update(_update) { n = 1; while (n < initvec.size()) { n *= 2; } node = vector<T>(n * 2, def); for (int i = n; i < n + initvec.size(); i++) { node[i] = initvec[i - n]; } for (int i = n - 1; i >= 1; i--) { node[i] = operation(node[i * 2], node[i * 2 + 1]); } } void change(int i, T x) { i += n; node[i] = update(node[i], x); while (i >= 1) { i >>= 1; node[i] = operation(node[i * 2], node[i * 2 + 1]); } } T query(int l, int r) { l += n; r += n; T rx = def, lx = def; while (l < r) { if (l & 1) { lx = operation(lx, node[l]); l++; } if (r & 1) { r--; rx = operation(node[r], rx); } l >>= 1; r >>= 1; } return operation(lx, rx); } T operator[](const int &x) { return node[x + n]; } void fill(T x) { std::fill(ALL(node), x); } void print() { rep(i, n) std::cout << operator[](i) << " "; std::cout << std::endl; } }; #define R_MIN ([](P a, P b) { return min(a, b); }) #define R_MAX ([](long long a, long long b) { return max(a, b); }) #define R_SUM ([](long long a, long long b) { return a + b; }) #define NORMAL_UPDATE ([](P a, P b) { return b; }) #define ADD_UPDATE ([](long long a, long long b) { return a + b; }) #define MINUS_UPDATE ([](long long a, long long b) { return a - b; } class Union_Find { vector<int> par; vector<int> rankmy; vector<int> ookisa; public: Union_Find(int size) { par = vector<int>(size); rankmy = vector<int>(size); ookisa = vector<int>(size); for (int i = 0; i < size; i++) { par[i] = i; ookisa[i] = 1; } } int find(int x) { if (par[x] == x) { return x; } return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } if (rankmy[x] < rankmy[y]) { par[x] = y; ookisa[y] += ookisa[x]; ookisa[x] = 0; } else { par[y] = x; ookisa[x] += ookisa[y]; ookisa[y] = 0; if (rankmy[x] == rankmy[y]) { rankmy[x]++; } } } int size(int i) { i = find(i); return ookisa[i]; } bool same(int x, int y) { return find(x) == find(y); } }; class BIT { vector<int> data; int size = 0; public: BIT(int _size) { data = vector<int>(_size + 1); size = _size; } void add(int i, int x) { while (i <= size) { data[i] += x; i += i & -i; } } int sum(int i) { assert(i <= size); int s = 0; while (i > 0) { s += data[i]; i -= i & -i; } return s; } int lower_bound(int x) { if (x <= 0) { return 0; } else { int i = 0; int r = 1; while (r < size) r = r << 1; for (int len = r; len > 0; len = len >> 1) { if (i + len < size && data[i + len] < x) { x -= data[i + len]; i += len; } } return i + 1; } } }; // Union-Find-End int perm[2000005]; void init_perm() { perm[0] = 1; REP(i, 2000004) { perm[i] = perm[i - 1] * i % mod; } } int nCk(int x, int y) { if (y > x) { return 0; } if (x < 0) { return 0; } return perm[x] * modpow(perm[x - y], mod - 2) % mod * modpow(perm[y], mod - 2) % mod; } double kyori(pair<int, int> f, pair<int, int> s) { double ans = 0; double t = fabs(f.first - s.first); double y = fabs(f.second - s.second); ans = sqrt(t * t + y * y); return ans; } inline string stringmax(string &x, string &y) { if (x.size() > y.size()) { return x; } if (x.size() < y.size()) { return y; } rep(i, x.size()) { if (x[i] > y[i]) { return x; } if (x[i] < y[i]) { return y; } } return x; } vector<int> RollingHash(string &s, string &t) { vector<int> ans; __int128 h = 0, hamod = 0, ki = 0, kim = 0, hikaku = 0, one = 0; one = 1; ki = 1000000007ll; hamod = (one << 61) - 1; kim = 1; rep(i, t.size()) { hikaku *= ki; h *= ki; kim *= ki; hikaku += t[i]; h += s[i]; hikaku %= hamod; h %= hamod; kim %= hamod; } rep(i, (int)s.size() - (int)t.size() + 1) { if (h == hikaku) { ans.emplace_back(i); } h *= ki; h %= hamod; h += s[i + (int)t.size()]; h %= hamod; h += hamod; h -= s[i] * kim % hamod; h %= hamod; } return ans; } struct edge { int to; int length; edge(int _to, int _length) { to = _to; length = _length; } }; vector<int> djkstra(vector<vector<edge>> &road, int start) { vector<int> kyo(road.size(), inf); smallpriority_queue(P) q; q.push({0, start}); kyo[start] = 0; while (q.size()) { int x = q.top().second; itn now = q.top().first; q.pop(); if (kyo[x] < now) { continue; } for (auto &i : road[x]) { if (kyo[i.to] > now + i.length) { kyo[i.to] = now + i.length; q.push({kyo[i.to], i.to}); } } } return kyo; } #define endl "\n" // interactive の時に注意!!! #define Endl "\n" // interactive の時に注意!!! #define printd cout << fixed << setprecision(10) #define rrep(i, f, s) for (int i = f; i < s; i++) #define RREP(i, f, s) for (int i = f; i <= s; i++) int n, k; string s, t, t2; signed main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n >> k >> s; char c = 'a' + 27; rep(i, n) { chmin(c, s[i]); } if (bitketa(n) + 1 <= k) { rep(i, n) { cout << c; } cout << endl; return 0; } t = s; t2 = s; rep(i, k) { string v(n + 1, 'z'), v2(n + 1, 'z'); string l = t; reverse(ALL(t)); l += t; rep(j, n + 1) { string k = l.substr(j, n); chmin(v, k); reverse(ALL(k)); chmin(v2, k); } l = t2; reverse(ALL(t2)); l += t2; rep(j, n + 1) { string k = l.substr(j, n); chmin(v, k); reverse(ALL(k)); chmin(v2, k); } t = v; reverse(ALL(v2)); t2 = v2; } cout << t << endl; }
[ "expression.operation.binary.add" ]
742,552
742,553
u943070796
cpp
p02943
/* * じょえチャンネル * 高評価・チャンネル登録よろしくおねがいします! * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ */ #include <bits/stdc++.h> //#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") // here!!! // define int long long !!!!! #define int long long // define int long long !!!!! #define mod 1000000007ll // constexpr int mod = 998244353ll; typedef long long ll; #ifdef int #define inf (int)(3e18) #else #define inf (int)(5e8) #endif #define intt long long #define itn long long #define P pair<long long, long long> #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) #define rev_rep(i, n) for (int i = n - 1; i >= 0; i--) #define REV_REP(i, n) for (int i = n; i >= 1; i--) #define ALL(v) v.begin(), v.end() #define smallpriority_queue(x) priority_queue<x, vector<x>, greater<x>> using namespace std; // Library //モッドパウ inline int modpow(int x, int y, int m = mod) { int res = 1; while (y) { if (y & 1) { res *= x; res %= m; } x = x * x % m; y /= 2; } return res; } int mypow(int x, int y) { int res = 1; while (y) { if (y % 2) { res *= x; } x = x * x; y /= 2; } return res; } // is the number (x) a prime number? bool prime(int x) { if (!x || x == 1) { return false; } for (int i = 2; i * i <= x; i++) { if (!(x % i)) { return false; } } return true; } // saidai-kouyakusuu inline int gcd(int x, int y) { if (!y) { return x; } return gcd(y, x % y); } // number of keta int keta(int x) { int ans = 0; while (x) { x /= 10; ans++; } return ans; } // number of 2shinsuu keta int bitketa(int x) { int ans = 0; while (x) { x >>= 1; ans++; } return ans; } // sum of keta int ketasum(int x) { int ans = 0; while (x) { ans += x % 10; x /= 10; } return ans; } inline int lcm(int x, int y) { int ans = x / gcd(x, y) * y; return ans; } int twobeki(int x) { int ans = 0; while (1) { if (!(x & 1)) { ans++; x >>= 1; } else { break; } } return ans; } template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } #define fin(i) scanf("%lld", &i) #define fout(i) printf("%lld", i) #define fendl printf("\n") int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int comb(int x, int y) { if (y > x) return 0; // cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl; return kai(x, y) * modpow(kai(y, y), mod - 2) % mod; } // Library-End #define vecin(v) \ for (int i = 0; i < v.size(); i++) \ scanf("%lld", &v[i]); #define vecout(v) \ { \ for (int i = 0; i < (int)v.size(); i++) \ printf("%lld ", v[i]); \ printf("\n"); \ } template <typename T> class kaageSegTree { protected: unsigned int n = 1, rank = 0; std::vector<T> node; T nodee; virtual T nodef(const T &, const T &) const = 0; public: kaageSegTree(unsigned int m, T init, T nodee) : nodee(nodee) { while (n < m) { n *= 2; rank++; } node.resize(2 * n); for (unsigned int i = n; i < 2 * n; i++) node[i] = init; } kaageSegTree(const std::vector<T> &initvec, T nodee) : nodee(nodee) { unsigned int m = initvec.size(); while (n < m) { n *= 2; rank++; } node.resize(2 * n); for (unsigned int i = n; i < 2 * n; i++) { if (i - n < m) node[i] = initvec[i - n]; } } virtual void update(int i, T x) { i += n; node[i] = x; while (i != 1) { i >>= 1; node[i] = nodef(node[2 * i], node[2 * i + 1]); } } virtual T query(int l, int r) { l += n; r += n; T ls = nodee, rs = nodee; while (l < r) { if (l & 1) { ls = nodef(ls, node[l]); l++; } if (r & 1) { r--; rs = nodef(node[r], rs); } l >>= 1; r >>= 1; } return nodef(ls, rs); } virtual T operator[](const int &x) { return node[n + x]; } void fill(T x) { std::fill(ALL(node), x); } void print() { rep(i, n) std::cout << operator[](i) << " "; std::cout << std::endl; } }; class RSQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return lhs + rhs; } public: RSQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, 0) {} RSQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, 0) {} }; class RMiQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return std::min(lhs, rhs); } public: RMiQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, inf) {} RMiQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, inf) {} }; class RMaQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return std::max(lhs, rhs); } public: RMaQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, -inf) {} RMaQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, -inf) {} }; template <typename T, typename U> class IntervalSegTree : public kaageSegTree<T> { protected: using kaageSegTree<T>::n; using kaageSegTree<T>::rank; using kaageSegTree<T>::node; using kaageSegTree<T>::nodef; using kaageSegTree<T>::nodee; std::vector<U> lazy; std::vector<bool> lazyflag; std::vector<int> width; virtual void lazyf(U &, const U &) = 0; virtual void updf(T &, const U &, const unsigned int &) = 0; void eval(int k) { for (int i = rank; i > 0; i--) { int nk = k >> i; if (lazyflag[nk]) { updf(node[2 * nk], lazy[nk], width[2 * nk]); updf(node[2 * nk + 1], lazy[nk], width[2 * nk + 1]); if (lazyflag[2 * nk]) lazyf(lazy[2 * nk], lazy[nk]); else lazy[2 * nk] = lazy[nk]; if (lazyflag[2 * nk + 1]) lazyf(lazy[2 * nk + 1], lazy[nk]); else lazy[2 * nk + 1] = lazy[nk]; lazyflag[2 * nk] = lazyflag[2 * nk + 1] = true; lazyflag[nk] = false; } } } public: IntervalSegTree(unsigned int m, T init, T nodee) : kaageSegTree<T>(m, init, nodee) { lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n); width[1] = n; for (unsigned int i = 2; i < 2 * n; i++) { width[i] = width[i >> 1] >> 1; } } IntervalSegTree(T nodee, const std::vector<T> &initvec) : kaageSegTree<T>(initvec, nodee) { lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n); width[1] = n; for (unsigned int i = 2; i < 2 * n; i++) { width[i] = width[i >> 1] >> 1; } } void update(int i, U x) { i += n; eval(i); updf(node[i], x, width[i]); if (lazyflag[i]) lazyf(lazy[i], x); else { lazyflag[i] = true; lazy[i] = x; } while (i /= 2) node[i] = nodef(node[2 * i], node[2 * i + 1]); } void update(int l, int r, U x) { l += n; r += n; int nl = l, nr = r; while (!(nl & 1)) nl >>= 1; while (!(nr & 1)) nr >>= 1; nr--; eval(nl); eval(nr); while (l < r) { if (l & 1) { updf(node[l], x, width[l]); if (lazyflag[l]) lazyf(lazy[l], x); else { lazyflag[l] = true; lazy[l] = x; } l++; } if (r & 1) { r--; updf(node[r], x, width[r]); if (lazyflag[r]) lazyf(lazy[r], x); else { lazyflag[r] = true; lazy[r] = x; } } l >>= 1; r >>= 1; } while (nl >>= 1) node[nl] = nodef(node[2 * nl], node[2 * nl + 1]); while (nr >>= 1) node[nr] = nodef(node[2 * nr], node[2 * nr + 1]); } T query(int l, int r) { l += n; r += n; eval(l); eval(r - 1); int ls = nodee, rs = nodee; while (l < r) { if (l & 1) { ls = nodef(ls, node[l]); l++; } if (r & 1) { r--; rs = nodef(node[r], rs); } l >>= 1; r >>= 1; } return nodef(ls, rs); } T operator[](const int &x) { eval(n + x); return node[n + x]; } T queryForAll() { return node[1]; } }; class RAQRSQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return a + b; } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += width * b; } public: RAQRSQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, 0) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRSQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>((int)0, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RAQRMiQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::min(a, b); } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += b; } public: RAQRMiQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRMiQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RAQRMaQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::max(a, b); } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += b; } public: RAQRMaQ(unsigned int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, -inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRMaQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(-inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRSQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return a + b; } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = width * b; } public: RUQRSQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, 0) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRSQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>((int)0, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRMiQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::min(a, b); } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = b; } public: RUQRMiQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRMiQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRMaQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::max(a, b); } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = b; } public: RUQRMaQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, -inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRMaQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(-inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; ////SegTree // template <class T> // class SegTree { // int n; // 葉の数 // vector<T> node; // データを格納するvector // T def; // 初期値かつ単位元 // function<T(T, T)> operation; // 区間クエリで使う処理 // function<T(T, T)> update; // 点更新で使う処理 // // // 区間[a,b)の総和。ノードk=[l,r)に着目している。 // T _query(int a, int b, int k, int l, int r) { // if (r <= a || b <= l) return def; // 交差しない // if (a <= l && r <= b) // return node[k]; // a,l,r,bの順で完全に含まれる // else { // T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 // T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 // return operation(c1, c2); // } // } // // public: // // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数, // // _update:更新関数 // SegTree(size_t _n, T _def, function<T(T, T)> _operation, // function<T(T, T)> _update) // : def(_def), operation(_operation), update(_update) { // n = 1; // while (n < _n) { // n *= 2; // } // node = vector<T>(2 * n , def); // } // // // 場所i(0-indexed)の値をxで更新 // void change(int i, T x) { // i += n - 1; // node[i] = update(node[i], x); // while (i > 0) { // i = (i - 1) / 2; // node[i] = operation(node[i * 2 + 1], node[i * 2 + 2]); // } // } // // // [a, b)の区間クエリを実行 // T query(int a, int b) { // return _query(a, b, 0, 0, n); // } // // // 添字でアクセス // T operator[](int i) { // return node[i + n - 1]; // } //}; template <class T> class SegTree { int n; vector<T> node; T def; function<T(T, T)> operation; function<T(T, T)> update; public: SegTree(unsigned int _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } node = vector<T>(n * 2, def); } SegTree(vector<int> &initvec, function<T(T, T)> _operation, function<T(T, T)> _update) : operation(_operation), update(_update) { n = 1; while (n < initvec.size()) { n *= 2; } node = vector<T>(n * 2, def); for (int i = n; i < n + initvec.size(); i++) { node[i] = initvec[i - n]; } for (int i = n - 1; i >= 1; i--) { node[i] = operation(node[i * 2], node[i * 2 + 1]); } } void change(int i, T x) { i += n; node[i] = update(node[i], x); while (i >= 1) { i >>= 1; node[i] = operation(node[i * 2], node[i * 2 + 1]); } } T query(int l, int r) { l += n; r += n; T rx = def, lx = def; while (l < r) { if (l & 1) { lx = operation(lx, node[l]); l++; } if (r & 1) { r--; rx = operation(node[r], rx); } l >>= 1; r >>= 1; } return operation(lx, rx); } T operator[](const int &x) { return node[x + n]; } void fill(T x) { std::fill(ALL(node), x); } void print() { rep(i, n) std::cout << operator[](i) << " "; std::cout << std::endl; } }; #define R_MIN ([](P a, P b) { return min(a, b); }) #define R_MAX ([](long long a, long long b) { return max(a, b); }) #define R_SUM ([](long long a, long long b) { return a + b; }) #define NORMAL_UPDATE ([](P a, P b) { return b; }) #define ADD_UPDATE ([](long long a, long long b) { return a + b; }) #define MINUS_UPDATE ([](long long a, long long b) { return a - b; } class Union_Find { vector<int> par; vector<int> rankmy; vector<int> ookisa; public: Union_Find(int size) { par = vector<int>(size); rankmy = vector<int>(size); ookisa = vector<int>(size); for (int i = 0; i < size; i++) { par[i] = i; ookisa[i] = 1; } } int find(int x) { if (par[x] == x) { return x; } return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } if (rankmy[x] < rankmy[y]) { par[x] = y; ookisa[y] += ookisa[x]; ookisa[x] = 0; } else { par[y] = x; ookisa[x] += ookisa[y]; ookisa[y] = 0; if (rankmy[x] == rankmy[y]) { rankmy[x]++; } } } int size(int i) { i = find(i); return ookisa[i]; } bool same(int x, int y) { return find(x) == find(y); } }; class BIT { vector<int> data; int size = 0; public: BIT(int _size) { data = vector<int>(_size + 1); size = _size; } void add(int i, int x) { while (i <= size) { data[i] += x; i += i & -i; } } int sum(int i) { assert(i <= size); int s = 0; while (i > 0) { s += data[i]; i -= i & -i; } return s; } int lower_bound(int x) { if (x <= 0) { return 0; } else { int i = 0; int r = 1; while (r < size) r = r << 1; for (int len = r; len > 0; len = len >> 1) { if (i + len < size && data[i + len] < x) { x -= data[i + len]; i += len; } } return i + 1; } } }; // Union-Find-End int perm[2000005]; void init_perm() { perm[0] = 1; REP(i, 2000004) { perm[i] = perm[i - 1] * i % mod; } } int nCk(int x, int y) { if (y > x) { return 0; } if (x < 0) { return 0; } return perm[x] * modpow(perm[x - y], mod - 2) % mod * modpow(perm[y], mod - 2) % mod; } double kyori(pair<int, int> f, pair<int, int> s) { double ans = 0; double t = fabs(f.first - s.first); double y = fabs(f.second - s.second); ans = sqrt(t * t + y * y); return ans; } inline string stringmax(string &x, string &y) { if (x.size() > y.size()) { return x; } if (x.size() < y.size()) { return y; } rep(i, x.size()) { if (x[i] > y[i]) { return x; } if (x[i] < y[i]) { return y; } } return x; } vector<int> RollingHash(string &s, string &t) { vector<int> ans; __int128 h = 0, hamod = 0, ki = 0, kim = 0, hikaku = 0, one = 0; one = 1; ki = 1000000007ll; hamod = (one << 61) - 1; kim = 1; rep(i, t.size()) { hikaku *= ki; h *= ki; kim *= ki; hikaku += t[i]; h += s[i]; hikaku %= hamod; h %= hamod; kim %= hamod; } rep(i, (int)s.size() - (int)t.size() + 1) { if (h == hikaku) { ans.emplace_back(i); } h *= ki; h %= hamod; h += s[i + (int)t.size()]; h %= hamod; h += hamod; h -= s[i] * kim % hamod; h %= hamod; } return ans; } struct edge { int to; int length; edge(int _to, int _length) { to = _to; length = _length; } }; vector<int> djkstra(vector<vector<edge>> &road, int start) { vector<int> kyo(road.size(), inf); smallpriority_queue(P) q; q.push({0, start}); kyo[start] = 0; while (q.size()) { int x = q.top().second; itn now = q.top().first; q.pop(); if (kyo[x] < now) { continue; } for (auto &i : road[x]) { if (kyo[i.to] > now + i.length) { kyo[i.to] = now + i.length; q.push({kyo[i.to], i.to}); } } } return kyo; } #define endl "\n" // interactive の時に注意!!! #define Endl "\n" // interactive の時に注意!!! #define printd cout << fixed << setprecision(10) #define rrep(i, f, s) for (int i = f; i < s; i++) #define RREP(i, f, s) for (int i = f; i <= s; i++) int n, k; string s, t, t2; signed main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n >> k >> s; char c = 'a' + 27; rep(i, n) { chmin(c, s[i]); } if (bitketa(n) + 1 <= k) { rep(i, n) { cout << c; } cout << endl; return 0; } t = s; t2 = s; rep(i, k) { string v(n + 1, 'z'), v2(n + 1, 'z'); string l = t; reverse(ALL(t)); l += t; rep(j, n) { string k = l.substr(j, n); chmin(v, k); reverse(ALL(k)); chmin(v2, k); } l = t2; reverse(ALL(t2)); l += t2; rep(j, n) { string k = l.substr(j, n); chmin(v, k); reverse(ALL(k)); chmin(v2, k); } t = v; reverse(ALL(v2)); t2 = v2; } cout << t << endl; }
/* * じょえチャンネル * 高評価・チャンネル登録よろしくおねがいします! * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ */ #include <bits/stdc++.h> //#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") // here!!! // define int long long !!!!! #define int long long // define int long long !!!!! #define mod 1000000007ll // constexpr int mod = 998244353ll; typedef long long ll; #ifdef int #define inf (int)(3e18) #else #define inf (int)(5e8) #endif #define intt long long #define itn long long #define P pair<long long, long long> #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) #define rev_rep(i, n) for (int i = n - 1; i >= 0; i--) #define REV_REP(i, n) for (int i = n; i >= 1; i--) #define ALL(v) v.begin(), v.end() #define smallpriority_queue(x) priority_queue<x, vector<x>, greater<x>> using namespace std; // Library //モッドパウ inline int modpow(int x, int y, int m = mod) { int res = 1; while (y) { if (y & 1) { res *= x; res %= m; } x = x * x % m; y /= 2; } return res; } int mypow(int x, int y) { int res = 1; while (y) { if (y % 2) { res *= x; } x = x * x; y /= 2; } return res; } // is the number (x) a prime number? bool prime(int x) { if (!x || x == 1) { return false; } for (int i = 2; i * i <= x; i++) { if (!(x % i)) { return false; } } return true; } // saidai-kouyakusuu inline int gcd(int x, int y) { if (!y) { return x; } return gcd(y, x % y); } // number of keta int keta(int x) { int ans = 0; while (x) { x /= 10; ans++; } return ans; } // number of 2shinsuu keta int bitketa(int x) { int ans = 0; while (x) { x >>= 1; ans++; } return ans; } // sum of keta int ketasum(int x) { int ans = 0; while (x) { ans += x % 10; x /= 10; } return ans; } inline int lcm(int x, int y) { int ans = x / gcd(x, y) * y; return ans; } int twobeki(int x) { int ans = 0; while (1) { if (!(x & 1)) { ans++; x >>= 1; } else { break; } } return ans; } template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } #define fin(i) scanf("%lld", &i) #define fout(i) printf("%lld", i) #define fendl printf("\n") int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int comb(int x, int y) { if (y > x) return 0; // cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl; return kai(x, y) * modpow(kai(y, y), mod - 2) % mod; } // Library-End #define vecin(v) \ for (int i = 0; i < v.size(); i++) \ scanf("%lld", &v[i]); #define vecout(v) \ { \ for (int i = 0; i < (int)v.size(); i++) \ printf("%lld ", v[i]); \ printf("\n"); \ } template <typename T> class kaageSegTree { protected: unsigned int n = 1, rank = 0; std::vector<T> node; T nodee; virtual T nodef(const T &, const T &) const = 0; public: kaageSegTree(unsigned int m, T init, T nodee) : nodee(nodee) { while (n < m) { n *= 2; rank++; } node.resize(2 * n); for (unsigned int i = n; i < 2 * n; i++) node[i] = init; } kaageSegTree(const std::vector<T> &initvec, T nodee) : nodee(nodee) { unsigned int m = initvec.size(); while (n < m) { n *= 2; rank++; } node.resize(2 * n); for (unsigned int i = n; i < 2 * n; i++) { if (i - n < m) node[i] = initvec[i - n]; } } virtual void update(int i, T x) { i += n; node[i] = x; while (i != 1) { i >>= 1; node[i] = nodef(node[2 * i], node[2 * i + 1]); } } virtual T query(int l, int r) { l += n; r += n; T ls = nodee, rs = nodee; while (l < r) { if (l & 1) { ls = nodef(ls, node[l]); l++; } if (r & 1) { r--; rs = nodef(node[r], rs); } l >>= 1; r >>= 1; } return nodef(ls, rs); } virtual T operator[](const int &x) { return node[n + x]; } void fill(T x) { std::fill(ALL(node), x); } void print() { rep(i, n) std::cout << operator[](i) << " "; std::cout << std::endl; } }; class RSQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return lhs + rhs; } public: RSQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, 0) {} RSQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, 0) {} }; class RMiQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return std::min(lhs, rhs); } public: RMiQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, inf) {} RMiQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, inf) {} }; class RMaQ : public kaageSegTree<int> { int nodef(const int &lhs, const int &rhs) const { return std::max(lhs, rhs); } public: RMaQ(int size, const int &def = 0) : kaageSegTree<int>(size, def, -inf) {} RMaQ(const std::vector<int> &initvec) : kaageSegTree<int>(initvec, -inf) {} }; template <typename T, typename U> class IntervalSegTree : public kaageSegTree<T> { protected: using kaageSegTree<T>::n; using kaageSegTree<T>::rank; using kaageSegTree<T>::node; using kaageSegTree<T>::nodef; using kaageSegTree<T>::nodee; std::vector<U> lazy; std::vector<bool> lazyflag; std::vector<int> width; virtual void lazyf(U &, const U &) = 0; virtual void updf(T &, const U &, const unsigned int &) = 0; void eval(int k) { for (int i = rank; i > 0; i--) { int nk = k >> i; if (lazyflag[nk]) { updf(node[2 * nk], lazy[nk], width[2 * nk]); updf(node[2 * nk + 1], lazy[nk], width[2 * nk + 1]); if (lazyflag[2 * nk]) lazyf(lazy[2 * nk], lazy[nk]); else lazy[2 * nk] = lazy[nk]; if (lazyflag[2 * nk + 1]) lazyf(lazy[2 * nk + 1], lazy[nk]); else lazy[2 * nk + 1] = lazy[nk]; lazyflag[2 * nk] = lazyflag[2 * nk + 1] = true; lazyflag[nk] = false; } } } public: IntervalSegTree(unsigned int m, T init, T nodee) : kaageSegTree<T>(m, init, nodee) { lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n); width[1] = n; for (unsigned int i = 2; i < 2 * n; i++) { width[i] = width[i >> 1] >> 1; } } IntervalSegTree(T nodee, const std::vector<T> &initvec) : kaageSegTree<T>(initvec, nodee) { lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n); width[1] = n; for (unsigned int i = 2; i < 2 * n; i++) { width[i] = width[i >> 1] >> 1; } } void update(int i, U x) { i += n; eval(i); updf(node[i], x, width[i]); if (lazyflag[i]) lazyf(lazy[i], x); else { lazyflag[i] = true; lazy[i] = x; } while (i /= 2) node[i] = nodef(node[2 * i], node[2 * i + 1]); } void update(int l, int r, U x) { l += n; r += n; int nl = l, nr = r; while (!(nl & 1)) nl >>= 1; while (!(nr & 1)) nr >>= 1; nr--; eval(nl); eval(nr); while (l < r) { if (l & 1) { updf(node[l], x, width[l]); if (lazyflag[l]) lazyf(lazy[l], x); else { lazyflag[l] = true; lazy[l] = x; } l++; } if (r & 1) { r--; updf(node[r], x, width[r]); if (lazyflag[r]) lazyf(lazy[r], x); else { lazyflag[r] = true; lazy[r] = x; } } l >>= 1; r >>= 1; } while (nl >>= 1) node[nl] = nodef(node[2 * nl], node[2 * nl + 1]); while (nr >>= 1) node[nr] = nodef(node[2 * nr], node[2 * nr + 1]); } T query(int l, int r) { l += n; r += n; eval(l); eval(r - 1); int ls = nodee, rs = nodee; while (l < r) { if (l & 1) { ls = nodef(ls, node[l]); l++; } if (r & 1) { r--; rs = nodef(node[r], rs); } l >>= 1; r >>= 1; } return nodef(ls, rs); } T operator[](const int &x) { eval(n + x); return node[n + x]; } T queryForAll() { return node[1]; } }; class RAQRSQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return a + b; } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += width * b; } public: RAQRSQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, 0) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRSQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>((int)0, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RAQRMiQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::min(a, b); } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += b; } public: RAQRMiQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRMiQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RAQRMaQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::max(a, b); } void lazyf(int &a, const int &b) { a += b; } void updf(int &a, const int &b, const unsigned int &width) { a += b; } public: RAQRMaQ(unsigned int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, -inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RAQRMaQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(-inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRSQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return a + b; } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = width * b; } public: RUQRSQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, 0) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRSQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>((int)0, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRMiQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::min(a, b); } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = b; } public: RUQRMiQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRMiQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; class RUQRMaQ : public IntervalSegTree<int, int> { int nodef(const int &a, const int &b) const { return std::max(a, b); } void lazyf(int &a, const int &b) { a = b; } void updf(int &a, const int &b, const unsigned int &width) { a = b; } public: RUQRMaQ(int size, const int &def = 0) : IntervalSegTree<int, int>(size, def, -inf) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } RUQRMaQ(const std::vector<int> &initvec) : IntervalSegTree<int, int>(-inf, initvec) { for (int i = n - 1; i > 0; i--) node[i] = nodef(node[2 * i], node[2 * i + 1]); } }; ////SegTree // template <class T> // class SegTree { // int n; // 葉の数 // vector<T> node; // データを格納するvector // T def; // 初期値かつ単位元 // function<T(T, T)> operation; // 区間クエリで使う処理 // function<T(T, T)> update; // 点更新で使う処理 // // // 区間[a,b)の総和。ノードk=[l,r)に着目している。 // T _query(int a, int b, int k, int l, int r) { // if (r <= a || b <= l) return def; // 交差しない // if (a <= l && r <= b) // return node[k]; // a,l,r,bの順で完全に含まれる // else { // T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 // T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 // return operation(c1, c2); // } // } // // public: // // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数, // // _update:更新関数 // SegTree(size_t _n, T _def, function<T(T, T)> _operation, // function<T(T, T)> _update) // : def(_def), operation(_operation), update(_update) { // n = 1; // while (n < _n) { // n *= 2; // } // node = vector<T>(2 * n , def); // } // // // 場所i(0-indexed)の値をxで更新 // void change(int i, T x) { // i += n - 1; // node[i] = update(node[i], x); // while (i > 0) { // i = (i - 1) / 2; // node[i] = operation(node[i * 2 + 1], node[i * 2 + 2]); // } // } // // // [a, b)の区間クエリを実行 // T query(int a, int b) { // return _query(a, b, 0, 0, n); // } // // // 添字でアクセス // T operator[](int i) { // return node[i + n - 1]; // } //}; template <class T> class SegTree { int n; vector<T> node; T def; function<T(T, T)> operation; function<T(T, T)> update; public: SegTree(unsigned int _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } node = vector<T>(n * 2, def); } SegTree(vector<int> &initvec, function<T(T, T)> _operation, function<T(T, T)> _update) : operation(_operation), update(_update) { n = 1; while (n < initvec.size()) { n *= 2; } node = vector<T>(n * 2, def); for (int i = n; i < n + initvec.size(); i++) { node[i] = initvec[i - n]; } for (int i = n - 1; i >= 1; i--) { node[i] = operation(node[i * 2], node[i * 2 + 1]); } } void change(int i, T x) { i += n; node[i] = update(node[i], x); while (i >= 1) { i >>= 1; node[i] = operation(node[i * 2], node[i * 2 + 1]); } } T query(int l, int r) { l += n; r += n; T rx = def, lx = def; while (l < r) { if (l & 1) { lx = operation(lx, node[l]); l++; } if (r & 1) { r--; rx = operation(node[r], rx); } l >>= 1; r >>= 1; } return operation(lx, rx); } T operator[](const int &x) { return node[x + n]; } void fill(T x) { std::fill(ALL(node), x); } void print() { rep(i, n) std::cout << operator[](i) << " "; std::cout << std::endl; } }; #define R_MIN ([](P a, P b) { return min(a, b); }) #define R_MAX ([](long long a, long long b) { return max(a, b); }) #define R_SUM ([](long long a, long long b) { return a + b; }) #define NORMAL_UPDATE ([](P a, P b) { return b; }) #define ADD_UPDATE ([](long long a, long long b) { return a + b; }) #define MINUS_UPDATE ([](long long a, long long b) { return a - b; } class Union_Find { vector<int> par; vector<int> rankmy; vector<int> ookisa; public: Union_Find(int size) { par = vector<int>(size); rankmy = vector<int>(size); ookisa = vector<int>(size); for (int i = 0; i < size; i++) { par[i] = i; ookisa[i] = 1; } } int find(int x) { if (par[x] == x) { return x; } return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } if (rankmy[x] < rankmy[y]) { par[x] = y; ookisa[y] += ookisa[x]; ookisa[x] = 0; } else { par[y] = x; ookisa[x] += ookisa[y]; ookisa[y] = 0; if (rankmy[x] == rankmy[y]) { rankmy[x]++; } } } int size(int i) { i = find(i); return ookisa[i]; } bool same(int x, int y) { return find(x) == find(y); } }; class BIT { vector<int> data; int size = 0; public: BIT(int _size) { data = vector<int>(_size + 1); size = _size; } void add(int i, int x) { while (i <= size) { data[i] += x; i += i & -i; } } int sum(int i) { assert(i <= size); int s = 0; while (i > 0) { s += data[i]; i -= i & -i; } return s; } int lower_bound(int x) { if (x <= 0) { return 0; } else { int i = 0; int r = 1; while (r < size) r = r << 1; for (int len = r; len > 0; len = len >> 1) { if (i + len < size && data[i + len] < x) { x -= data[i + len]; i += len; } } return i + 1; } } }; // Union-Find-End int perm[2000005]; void init_perm() { perm[0] = 1; REP(i, 2000004) { perm[i] = perm[i - 1] * i % mod; } } int nCk(int x, int y) { if (y > x) { return 0; } if (x < 0) { return 0; } return perm[x] * modpow(perm[x - y], mod - 2) % mod * modpow(perm[y], mod - 2) % mod; } double kyori(pair<int, int> f, pair<int, int> s) { double ans = 0; double t = fabs(f.first - s.first); double y = fabs(f.second - s.second); ans = sqrt(t * t + y * y); return ans; } inline string stringmax(string &x, string &y) { if (x.size() > y.size()) { return x; } if (x.size() < y.size()) { return y; } rep(i, x.size()) { if (x[i] > y[i]) { return x; } if (x[i] < y[i]) { return y; } } return x; } vector<int> RollingHash(string &s, string &t) { vector<int> ans; __int128 h = 0, hamod = 0, ki = 0, kim = 0, hikaku = 0, one = 0; one = 1; ki = 1000000007ll; hamod = (one << 61) - 1; kim = 1; rep(i, t.size()) { hikaku *= ki; h *= ki; kim *= ki; hikaku += t[i]; h += s[i]; hikaku %= hamod; h %= hamod; kim %= hamod; } rep(i, (int)s.size() - (int)t.size() + 1) { if (h == hikaku) { ans.emplace_back(i); } h *= ki; h %= hamod; h += s[i + (int)t.size()]; h %= hamod; h += hamod; h -= s[i] * kim % hamod; h %= hamod; } return ans; } struct edge { int to; int length; edge(int _to, int _length) { to = _to; length = _length; } }; vector<int> djkstra(vector<vector<edge>> &road, int start) { vector<int> kyo(road.size(), inf); smallpriority_queue(P) q; q.push({0, start}); kyo[start] = 0; while (q.size()) { int x = q.top().second; itn now = q.top().first; q.pop(); if (kyo[x] < now) { continue; } for (auto &i : road[x]) { if (kyo[i.to] > now + i.length) { kyo[i.to] = now + i.length; q.push({kyo[i.to], i.to}); } } } return kyo; } #define endl "\n" // interactive の時に注意!!! #define Endl "\n" // interactive の時に注意!!! #define printd cout << fixed << setprecision(10) #define rrep(i, f, s) for (int i = f; i < s; i++) #define RREP(i, f, s) for (int i = f; i <= s; i++) int n, k; string s, t, t2; signed main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n >> k >> s; char c = 'a' + 27; rep(i, n) { chmin(c, s[i]); } if (bitketa(n) * 2 <= k) { rep(i, n) { cout << c; } cout << endl; return 0; } t = s; t2 = s; rep(i, k) { string v(n + 1, 'z'), v2(n + 1, 'z'); string l = t; reverse(ALL(t)); l += t; rep(j, n + 1) { string k = l.substr(j, n); chmin(v, k); reverse(ALL(k)); chmin(v2, k); } l = t2; reverse(ALL(t2)); l += t2; rep(j, n + 1) { string k = l.substr(j, n); chmin(v, k); reverse(ALL(k)); chmin(v2, k); } t = v; reverse(ALL(v2)); t2 = v2; } cout << t << endl; }
[ "expression.operation.binary.add" ]
742,552
742,554
u943070796
cpp
p02943
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <vector> using namespace std; #define int long long #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 1000000007 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define pi 3.141592653589793238462643383279 #define e_ 2.718281828459045235360287471352 #define P pair<int, int> #define upp(a, n, x) upper_bound(a, a + n, x) - a; #define low(a, n, x) lower_bound(a, a + n, x) - a; #define UF UnionFind // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { if (x == 0 || y == 0) return x + y; int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool p(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } string maxst(string s, string t) { int n = s.size(); int m = t.size(); if (n > m) return s; else if (n < m) return t; else { rep(0, i, n) { if (s[i] > t[i]) return s; if (s[i] < t[i]) return t; } return s; } } string minst(string s, string t) { int n = s.size(); int m = t.size(); if (n < m) return s; else if (n > m) return t; else { rep(0, i, n) { if (s[i] < t[i]) return s; if (s[i] > t[i]) return t; } return s; } } string string_reverse(string s) { int n = s.size(); string t; rep(0, i, n) t += s[n - i - 1]; return t; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[41]; int nis[41]; int nia[41]; int mody[41]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int gyakugen(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } mody[0] = y; rep(1, i, 41) { y = (y * y) % mod; mody[i] = y; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { n = (n * mody[i]) % mod; } } return n; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } int poow(int y, int n) { if (n == 0) return 1; n -= 1; int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int yy = y; mody[0] = yy; rep(1, i, 41) { yy = (yy * yy) % mod; mody[i] = yy; } rep(0, i, 41) nis[i] = 0; nn = n; for (int i = 40; i >= 0; i -= 1) { if (nn >= n2[i]) { nis[i]++; nn -= n2[i]; } } rep(0, i, 41) { if (nis[i] == 1) { y = (y * mody[i]) % mod; } } return y; } int minpow(int x, int y) { int sum = 1; rep(0, i, y) sum *= x; return sum; } int ketawa(int x, int sinsuu) { int sum = 0; rep(0, i, 100) sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i)); return sum; } int sankaku(int a) { return a * (a + 1) / 2; } int sames(int a[1111111], int n) { int ans = 0; rep(0, i, n) { if (a[i] == a[i + 1]) { int j = i; while (a[j + 1] == a[i] && j <= n - 2) j++; ans += sankaku(j - i); i = j; } } return ans; } using Graph = vector<vector<int>>; int oya[114514]; int depth[114514]; void dfs(const Graph &G, int v, int p, int d) { depth[v] = d; oya[v] = p; for (auto nv : G[v]) { if (nv == p) continue; // nv が親 p だったらダメ dfs(G, nv, v, d + 1); // d を 1 増やして子ノードへ } } /*int H=10,W=10; char field[10][10]; char memo[10][10]; void dfs(int h, int w) { memo[h][w] = 'x'; // 八方向を探索 for (int dh = -1; dh <= 1; ++dh) { for (int dw = -1; dw <= 1; ++dw) { if(abs(0-dh)+abs(0-dw)==2)continue; int nh = h + dh, nw = w + dw; // 場外アウトしたり、0 だったりはスルー if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (memo[nh][nw] == 'x') continue; // 再帰的に探索 dfs(nh, nw); } } }*/ int XOR(int a, int b) { if (a == 0 || b == 0) { return a + b; } int ni = 1; rep(0, i, 41) { n2[i] = ni; ni *= 2; } rep(0, i, 41) nis[i] = 0; for (int i = 40; i >= 0; i -= 1) { if (a >= n2[i]) { nis[i]++; a -= n2[i]; } if (b >= n2[i]) { nis[i]++; b -= n2[i]; } } int sum = 0; rep(0, i, 41) sum += (nis[i] % 2 * n2[i]); return sum; } // int ma[1024577][21]; // for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1; struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; signed main() { ic(n) ic(k) sc(s) rep(0, i, min(30, k - 1)) { string ans = s + string_reverse(s); string t = string_reverse(s); rep(0, j, n) t = minst(t, string_reverse(ans.substr(j, n))); s = string_reverse(t); } string m = s; string an = s + string_reverse(s); rep(0, j, n) m = minst(m, an.substr(j, n)); c(m) }
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <vector> using namespace std; #define int long long #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 1000000007 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define pi 3.141592653589793238462643383279 #define e_ 2.718281828459045235360287471352 #define P pair<int, int> #define upp(a, n, x) upper_bound(a, a + n, x) - a; #define low(a, n, x) lower_bound(a, a + n, x) - a; #define UF UnionFind // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { if (x == 0 || y == 0) return x + y; int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool p(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } string maxst(string s, string t) { int n = s.size(); int m = t.size(); if (n > m) return s; else if (n < m) return t; else { rep(0, i, n) { if (s[i] > t[i]) return s; if (s[i] < t[i]) return t; } return s; } } string minst(string s, string t) { int n = s.size(); int m = t.size(); if (n < m) return s; else if (n > m) return t; else { rep(0, i, n) { if (s[i] < t[i]) return s; if (s[i] > t[i]) return t; } return s; } } string string_reverse(string s) { int n = s.size(); string t; rep(0, i, n) t += s[n - i - 1]; return t; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[41]; int nis[41]; int nia[41]; int mody[41]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int gyakugen(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } mody[0] = y; rep(1, i, 41) { y = (y * y) % mod; mody[i] = y; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { n = (n * mody[i]) % mod; } } return n; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } int poow(int y, int n) { if (n == 0) return 1; n -= 1; int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int yy = y; mody[0] = yy; rep(1, i, 41) { yy = (yy * yy) % mod; mody[i] = yy; } rep(0, i, 41) nis[i] = 0; nn = n; for (int i = 40; i >= 0; i -= 1) { if (nn >= n2[i]) { nis[i]++; nn -= n2[i]; } } rep(0, i, 41) { if (nis[i] == 1) { y = (y * mody[i]) % mod; } } return y; } int minpow(int x, int y) { int sum = 1; rep(0, i, y) sum *= x; return sum; } int ketawa(int x, int sinsuu) { int sum = 0; rep(0, i, 100) sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i)); return sum; } int sankaku(int a) { return a * (a + 1) / 2; } int sames(int a[1111111], int n) { int ans = 0; rep(0, i, n) { if (a[i] == a[i + 1]) { int j = i; while (a[j + 1] == a[i] && j <= n - 2) j++; ans += sankaku(j - i); i = j; } } return ans; } using Graph = vector<vector<int>>; int oya[114514]; int depth[114514]; void dfs(const Graph &G, int v, int p, int d) { depth[v] = d; oya[v] = p; for (auto nv : G[v]) { if (nv == p) continue; // nv が親 p だったらダメ dfs(G, nv, v, d + 1); // d を 1 増やして子ノードへ } } /*int H=10,W=10; char field[10][10]; char memo[10][10]; void dfs(int h, int w) { memo[h][w] = 'x'; // 八方向を探索 for (int dh = -1; dh <= 1; ++dh) { for (int dw = -1; dw <= 1; ++dw) { if(abs(0-dh)+abs(0-dw)==2)continue; int nh = h + dh, nw = w + dw; // 場外アウトしたり、0 だったりはスルー if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (memo[nh][nw] == 'x') continue; // 再帰的に探索 dfs(nh, nw); } } }*/ int XOR(int a, int b) { if (a == 0 || b == 0) { return a + b; } int ni = 1; rep(0, i, 41) { n2[i] = ni; ni *= 2; } rep(0, i, 41) nis[i] = 0; for (int i = 40; i >= 0; i -= 1) { if (a >= n2[i]) { nis[i]++; a -= n2[i]; } if (b >= n2[i]) { nis[i]++; b -= n2[i]; } } int sum = 0; rep(0, i, 41) sum += (nis[i] % 2 * n2[i]); return sum; } // int ma[1024577][21]; // for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1; struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; signed main() { ic(n) ic(k) sc(s) rep(0, i, min(30, k - 1)) { string ans = s + string_reverse(s); string t = string_reverse(s); rep(0, j, n + 1) t = minst(t, string_reverse(ans.substr(j, n))); s = string_reverse(t); } string m = s; string an = s + string_reverse(s); rep(0, j, n) m = minst(m, an.substr(j, n)); c(m) }
[ "assignment.change" ]
742,561
742,562
u942393279
cpp
p02943
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <vector> using namespace std; #define int long long #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 1000000007 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define pi 3.141592653589793238462643383279 #define e_ 2.718281828459045235360287471352 #define P pair<int, int> #define upp(a, n, x) upper_bound(a, a + n, x) - a; #define low(a, n, x) lower_bound(a, a + n, x) - a; #define UF UnionFind // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { if (x == 0 || y == 0) return x + y; int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool p(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } string maxst(string s, string t) { int n = s.size(); int m = t.size(); if (n > m) return s; else if (n < m) return t; else { rep(0, i, n) { if (s[i] > t[i]) return s; if (s[i] < t[i]) return t; } return s; } } string minst(string s, string t) { int n = s.size(); int m = t.size(); if (n < m) return s; else if (n > m) return t; else { rep(0, i, n) { if (s[i] < t[i]) return s; if (s[i] > t[i]) return t; } return s; } } string string_reverse(string s) { int n = s.size(); string t; rep(0, i, n) t += s[n - i - 1]; return t; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[41]; int nis[41]; int nia[41]; int mody[41]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int gyakugen(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } mody[0] = y; rep(1, i, 41) { y = (y * y) % mod; mody[i] = y; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { n = (n * mody[i]) % mod; } } return n; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } int poow(int y, int n) { if (n == 0) return 1; n -= 1; int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int yy = y; mody[0] = yy; rep(1, i, 41) { yy = (yy * yy) % mod; mody[i] = yy; } rep(0, i, 41) nis[i] = 0; nn = n; for (int i = 40; i >= 0; i -= 1) { if (nn >= n2[i]) { nis[i]++; nn -= n2[i]; } } rep(0, i, 41) { if (nis[i] == 1) { y = (y * mody[i]) % mod; } } return y; } int minpow(int x, int y) { int sum = 1; rep(0, i, y) sum *= x; return sum; } int ketawa(int x, int sinsuu) { int sum = 0; rep(0, i, 100) sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i)); return sum; } int sankaku(int a) { return a * (a + 1) / 2; } int sames(int a[1111111], int n) { int ans = 0; rep(0, i, n) { if (a[i] == a[i + 1]) { int j = i; while (a[j + 1] == a[i] && j <= n - 2) j++; ans += sankaku(j - i); i = j; } } return ans; } using Graph = vector<vector<int>>; int oya[114514]; int depth[114514]; void dfs(const Graph &G, int v, int p, int d) { depth[v] = d; oya[v] = p; for (auto nv : G[v]) { if (nv == p) continue; // nv が親 p だったらダメ dfs(G, nv, v, d + 1); // d を 1 増やして子ノードへ } } /*int H=10,W=10; char field[10][10]; char memo[10][10]; void dfs(int h, int w) { memo[h][w] = 'x'; // 八方向を探索 for (int dh = -1; dh <= 1; ++dh) { for (int dw = -1; dw <= 1; ++dw) { if(abs(0-dh)+abs(0-dw)==2)continue; int nh = h + dh, nw = w + dw; // 場外アウトしたり、0 だったりはスルー if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (memo[nh][nw] == 'x') continue; // 再帰的に探索 dfs(nh, nw); } } }*/ int XOR(int a, int b) { if (a == 0 || b == 0) { return a + b; } int ni = 1; rep(0, i, 41) { n2[i] = ni; ni *= 2; } rep(0, i, 41) nis[i] = 0; for (int i = 40; i >= 0; i -= 1) { if (a >= n2[i]) { nis[i]++; a -= n2[i]; } if (b >= n2[i]) { nis[i]++; b -= n2[i]; } } int sum = 0; rep(0, i, 41) sum += (nis[i] % 2 * n2[i]); return sum; } // int ma[1024577][21]; // for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1; struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; signed main() { ic(n) ic(k) sc(s) rep(0, i, min(15, k - 1)) { string ans = s + string_reverse(s); string t = string_reverse(s); rep(0, j, n) t = minst(t, string_reverse(ans.substr(j, n))); s = string_reverse(t); } string m = s; string an = s + string_reverse(s); rep(0, j, n) m = minst(m, an.substr(j, n)); c(m) }
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <vector> using namespace std; #define int long long #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 1000000007 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define pi 3.141592653589793238462643383279 #define e_ 2.718281828459045235360287471352 #define P pair<int, int> #define upp(a, n, x) upper_bound(a, a + n, x) - a; #define low(a, n, x) lower_bound(a, a + n, x) - a; #define UF UnionFind // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { if (x == 0 || y == 0) return x + y; int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool p(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } string maxst(string s, string t) { int n = s.size(); int m = t.size(); if (n > m) return s; else if (n < m) return t; else { rep(0, i, n) { if (s[i] > t[i]) return s; if (s[i] < t[i]) return t; } return s; } } string minst(string s, string t) { int n = s.size(); int m = t.size(); if (n < m) return s; else if (n > m) return t; else { rep(0, i, n) { if (s[i] < t[i]) return s; if (s[i] > t[i]) return t; } return s; } } string string_reverse(string s) { int n = s.size(); string t; rep(0, i, n) t += s[n - i - 1]; return t; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[41]; int nis[41]; int nia[41]; int mody[41]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int gyakugen(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } mody[0] = y; rep(1, i, 41) { y = (y * y) % mod; mody[i] = y; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { n = (n * mody[i]) % mod; } } return n; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } int poow(int y, int n) { if (n == 0) return 1; n -= 1; int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int yy = y; mody[0] = yy; rep(1, i, 41) { yy = (yy * yy) % mod; mody[i] = yy; } rep(0, i, 41) nis[i] = 0; nn = n; for (int i = 40; i >= 0; i -= 1) { if (nn >= n2[i]) { nis[i]++; nn -= n2[i]; } } rep(0, i, 41) { if (nis[i] == 1) { y = (y * mody[i]) % mod; } } return y; } int minpow(int x, int y) { int sum = 1; rep(0, i, y) sum *= x; return sum; } int ketawa(int x, int sinsuu) { int sum = 0; rep(0, i, 100) sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i)); return sum; } int sankaku(int a) { return a * (a + 1) / 2; } int sames(int a[1111111], int n) { int ans = 0; rep(0, i, n) { if (a[i] == a[i + 1]) { int j = i; while (a[j + 1] == a[i] && j <= n - 2) j++; ans += sankaku(j - i); i = j; } } return ans; } using Graph = vector<vector<int>>; int oya[114514]; int depth[114514]; void dfs(const Graph &G, int v, int p, int d) { depth[v] = d; oya[v] = p; for (auto nv : G[v]) { if (nv == p) continue; // nv が親 p だったらダメ dfs(G, nv, v, d + 1); // d を 1 増やして子ノードへ } } /*int H=10,W=10; char field[10][10]; char memo[10][10]; void dfs(int h, int w) { memo[h][w] = 'x'; // 八方向を探索 for (int dh = -1; dh <= 1; ++dh) { for (int dw = -1; dw <= 1; ++dw) { if(abs(0-dh)+abs(0-dw)==2)continue; int nh = h + dh, nw = w + dw; // 場外アウトしたり、0 だったりはスルー if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (memo[nh][nw] == 'x') continue; // 再帰的に探索 dfs(nh, nw); } } }*/ int XOR(int a, int b) { if (a == 0 || b == 0) { return a + b; } int ni = 1; rep(0, i, 41) { n2[i] = ni; ni *= 2; } rep(0, i, 41) nis[i] = 0; for (int i = 40; i >= 0; i -= 1) { if (a >= n2[i]) { nis[i]++; a -= n2[i]; } if (b >= n2[i]) { nis[i]++; b -= n2[i]; } } int sum = 0; rep(0, i, 41) sum += (nis[i] % 2 * n2[i]); return sum; } // int ma[1024577][21]; // for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1; struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; signed main() { ic(n) ic(k) sc(s) rep(0, i, min(30, k - 1)) { string ans = s + string_reverse(s); string t = string_reverse(s); rep(0, j, n + 1) t = minst(t, string_reverse(ans.substr(j, n))); s = string_reverse(t); } string m = s; string an = s + string_reverse(s); rep(0, j, n) m = minst(m, an.substr(j, n)); c(m) }
[ "literal.number.change", "call.arguments.change", "assignment.change" ]
742,563
742,562
u942393279
cpp
p02943
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int N, K; while (cin >> N >> K) { string S; cin >> S; vector<string> vs; string T = S; reverse(T.begin(), T.end()); S += T; char best = 'z' + 1; int len = 0; int rep = 0; for (int i = 0; i < N; i++) { int curL = 0; for (int j = i; j < T.size(); j++) { if (S[i] == S[j]) ++curL; else break; } if (S[i] < best || (S[i] == best && curL > len)) { vs.clear(); best = S[i]; len = curL; rep = len; for (int j = 0; j < K - 1 && rep < N; j++) rep *= 2; rep = min(N, rep); } if (S[i] == best && len == curL) { vs.emplace_back(S.substr(i + len, N - rep)); } } sort(vs.begin(), vs.end()); cout << (string(rep, best) + vs[0]) << endl; } }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int N, K; while (cin >> N >> K) { string S; cin >> S; vector<string> vs; string T = S; reverse(T.begin(), T.end()); S += T; char best = 'z' + 1; int len = 0; int rep = 0; for (int i = 0; i < N; i++) { int curL = 0; for (int j = i; j < S.size(); j++) { if (S[i] == S[j]) ++curL; else break; } if (S[i] < best || (S[i] == best && curL > len)) { vs.clear(); best = S[i]; len = curL; rep = len; for (int j = 0; j < K - 1 && rep < N; j++) rep *= 2; rep = min(N, rep); } if (S[i] == best && len == curL) { vs.emplace_back(S.substr(i + len, N - rep)); } } sort(vs.begin(), vs.end()); cout << (string(rep, best) + vs[0]) << endl; } }
[ "identifier.change", "control_flow.loop.condition.change" ]
742,568
742,569
u002023395
cpp
p02943
#include <bits/stdc++.h> #define be(v) (v).begin(), (v).end() #define pb(q) push_back(q) typedef long long ll; using namespace std; const ll mod = 1000000007, INF = mod * mod * 3LL; #define doublecout(a) cout << fixed << setprecision(10) << a << endl; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); string s; int n, k; cin >> n >> k >> s; string t = s; reverse(be(t)); s += t; string u = s.substr(0, n); for (int i = 1; i <= n; i++) u = min(u, s.substr(i, n)); int x = 1; while (x < u.length() && u[0] == u[x]) x++; int y = x; k--; if (k > 17) y = n; else y <<= k; string ans = ""; while (ans.length() < n && k > 0) y--, ans += u[0]; ans += u.substr(x, n - ans.length()); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define be(v) (v).begin(), (v).end() #define pb(q) push_back(q) typedef long long ll; using namespace std; const ll mod = 1000000007, INF = mod * mod * 3LL; #define doublecout(a) cout << fixed << setprecision(10) << a << endl; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); string s; int n, k; cin >> n >> k >> s; string t = s; reverse(be(t)); s += t; string u = s.substr(0, n); for (int i = 1; i <= n; i++) u = min(u, s.substr(i, n)); int x = 1; while (x < u.length() && u[0] == u[x]) x++; int y = x; k--; if (k > 17) y = n; else y <<= k; string ans = ""; while (ans.length() < n && y > 0) y--, ans += u[0]; ans += u.substr(x, n - ans.length()); cout << ans << endl; return 0; }
[ "identifier.change", "control_flow.loop.condition.change" ]
742,570
742,571
u192903163
cpp
p02943
#include <bits/stdc++.h> #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; #define lli long long int #define uli unsigned long long int #define INF 9999999999 #define rep(i, m, n) for (lli i = m; i < n; i++) #define rrep(i, m, n) for (lli i = m - 1; i >= n; i--) #define pb(n) push_back(n) #define UE(N) N.erase(unique(N.begin(), N.end()), N.end()); #define Sort(n) sort(n.begin(), n.end()) #define Rev(n) reverse(n.begin(), n.end()) #define Out(S) cout << S << endl #define NeOut(S) cout << S #define HpOut(S) cout << setprecision(25) << S << endl #define Vec(K, L, N, S) vector<L> K(N, S) #define DV(K, L, N, M, S) vector<vector<L>> K(N, vector<L>(M, S)) #define TV(K, L, N, M, R, S) \ vector<vector<vector<L>>> K(N, vector<vector<L>>(M, vector<L>(R, S))) #define pint pair<lli, lli> #define paf(L, R) pair<L, R> #define mod 1000000007 #define MAX 10000000 #define ALL(a) a.begin(), a.end() #define chmax(a, b) a = (((a) < (b)) ? (b) : (a)) #define chmin(a, b) a = (((a) > (b)) ? (b) : (a)) int main() { ios::sync_with_stdio(false); cin.tie(0); lli A, B, C, D, E, F, N, M, K, L, X, Y, Z, H, W, sum = 0, num = 0, flag = 0; string S, T; cin >> N >> K >> S; T = S; Sort(T); rrep(i, N, 0) { if (S[i] == T[0]) sum++; else break; } while (N > sum) { if (sum > 0) sum *= 2; else sum++; num++; } if (K >= num) { rep(i, 0, N) NeOut(T[0]); Out(""); } else { rep(i, 0, K - 1) { Vec(G, string, 0, ""); T = S; Rev(S); S += T; Rev(S); rep(j, 0, N + 1) { T = S.substr(j, N); G.pb(T); } Sort(G); S = G[0]; Rev(S); } Vec(G, string, 0, ""); T = S; Rev(T); S += T; rep(i, 0, N + 1) G.pb(S.substr(i, N)); Sort(G); Out(G[0]); } }
#include <bits/stdc++.h> #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; #define lli long long int #define uli unsigned long long int #define INF 9999999999 #define rep(i, m, n) for (lli i = m; i < n; i++) #define rrep(i, m, n) for (lli i = m - 1; i >= n; i--) #define pb(n) push_back(n) #define UE(N) N.erase(unique(N.begin(), N.end()), N.end()); #define Sort(n) sort(n.begin(), n.end()) #define Rev(n) reverse(n.begin(), n.end()) #define Out(S) cout << S << endl #define NeOut(S) cout << S #define HpOut(S) cout << setprecision(25) << S << endl #define Vec(K, L, N, S) vector<L> K(N, S) #define DV(K, L, N, M, S) vector<vector<L>> K(N, vector<L>(M, S)) #define TV(K, L, N, M, R, S) \ vector<vector<vector<L>>> K(N, vector<vector<L>>(M, vector<L>(R, S))) #define pint pair<lli, lli> #define paf(L, R) pair<L, R> #define mod 1000000007 #define MAX 10000000 #define ALL(a) a.begin(), a.end() #define chmax(a, b) a = (((a) < (b)) ? (b) : (a)) #define chmin(a, b) a = (((a) > (b)) ? (b) : (a)) int main() { ios::sync_with_stdio(false); cin.tie(0); lli A, B, C, D, E, F, N, M, K, L, X, Y, Z, H, W, sum = 0, num = 0, flag = 0; string S, T; cin >> N >> K >> S; T = S; Sort(T); rrep(i, N, 0) { if (S[i] == T[0]) sum++; else break; } while (N > sum) { if (sum > 0) sum *= 2; else sum++; num++; } if (K >= num) { rep(i, 0, N) NeOut(T[0]); Out(""); } else { rep(i, 0, K - 1) { Vec(G, string, 0, ""); T = S; Rev(T); S += T; Rev(S); rep(j, 0, N + 1) { T = S.substr(j, N); G.pb(T); } Sort(G); S = G[0]; Rev(S); // Out(S); } Vec(G, string, 0, ""); T = S; Rev(T); S += T; rep(i, 0, N + 1) G.pb(S.substr(i, N)); Sort(G); Out(G[0]); } }
[ "identifier.change", "call.arguments.change" ]
742,574
742,575
u618604643
cpp
p02943
#include "algorithm" #include "cmath" #include "cstdio" #include "cstring" #include "iostream" #include "map" #include "queue" #include "set" #include "vector" using namespace std; #define MAXN 100006 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int, int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin(), (x).end() #define mem(a) memset(a, 0, sizeof a) typedef long long ll; int n, k; char ch[MAXN]; int l[MAXN]; string res, t; void solve() { cin >> n >> k; scanf("%s", ch + 1); char c = 'z'; rep(i, 1, n) ch[n + (n - i + 1)] = ch[i], c = min(c, ch[i]); n <<= 1; if (k == 1) { string res; rep(i, 1, (n >> 1)) { string t; rep(j, i, i + (n >> 1) - 1) t += ch[j]; if (res.empty() || res > t) res = t; } cout << res << endl; return; } if (k >= 15) { rep(i, 1, n >> 1) putchar(c); return; } int mx = 0; rep(i, 1, n) { if (ch[i] == c) l[i] = l[i - 1] + 1, mx = max(mx, l[i]); else l[i] = 0; } int len = (mx << k - 1); if (len >= (n >> 1)) { rep(i, 1, n >> 1) putchar(c); return; } rep(i, 1, n) { if (l[i] == mx) { t.clear(); if (i + (n >> 1) > n) break; rep(j, i + 1, i + (n >> 1)) t.push_back(ch[j]); if (res.empty() || res > t) res = t; } } int l = len; rep(i, 1, len) putchar(c); for (auto &t : res) { ++l, putchar(t); if (l >= (n >> 1)) break; } } signed main() { // int T;cin >> T;while( T-- ) solve(); solve(); }
#include "algorithm" #include "cmath" #include "cstdio" #include "cstring" #include "iostream" #include "map" #include "queue" #include "set" #include "vector" using namespace std; #define MAXN 100006 //#define int long long #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int, int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin(), (x).end() #define mem(a) memset(a, 0, sizeof a) typedef long long ll; int n, k; char ch[MAXN]; int l[MAXN]; string res, t; void solve() { cin >> n >> k; scanf("%s", ch + 1); char c = 'z'; rep(i, 1, n) ch[n + (n - i + 1)] = ch[i], c = min(c, ch[i]); n <<= 1; if (k == 1) { string res; rep(i, 1, (n >> 1)) { string t; rep(j, i, i + (n >> 1) - 1) t += ch[j]; if (res.empty() || res > t) res = t; } cout << res << endl; return; } if (k >= 15) { rep(i, 1, n >> 1) putchar(c); return; } int mx = 0; rep(i, 1, n) { if (ch[i] == c) l[i] = l[i - 1] + 1, mx = max(mx, l[i]); else l[i] = 0; } int len = (mx << k - 1); if (len >= (n >> 1)) { rep(i, 1, n >> 1) putchar(c); return; } rep(i, 1, n) { if (l[i] == mx) { t.clear(); if (i - mx + (n >> 1) > n) break; rep(j, i + 1, i + (n >> 1) - mx) t.push_back(ch[j]); if (res.empty() || res > t) res = t; } } int l = len; rep(i, 1, len) putchar(c); for (auto &t : res) { ++l, putchar(t); if (l >= (n >> 1)) break; } } signed main() { // int T;cin >> T;while( T-- ) solve(); solve(); }
[ "control_flow.branch.if.condition.change" ]
742,579
742,580
u390140944
cpp
p02943
#include <bits/stdc++.h> using namespace std; const int N = 5010; char s[N * 2]; int n; inline void FUCK(char t) { for (int i = 1; i <= n; i++) putchar(t); exit(0); } int tmp[N * 2]; char res[N]; int main() { int k; scanf("%d%d%s", &n, &k, s + 1); char t = 127; for (int i = 1; i <= n; i++) t = min(t, s[i]); for (int i = n + 1; i <= n * 2; i++) s[i] = s[n * 2 - i + 1]; for (int i = 1; i <= n; i++) res[i] = 127; if (k == 1) { for (int i = 1; i <= n + 1; i++) { bool flag = false; for (int j = 1; j <= n; j++) if (s[i + j - 1] != res[j]) { if (s[i + j - 1] < res[j]) flag = true; break; } if (flag) for (int j = 1; j <= n; j++) res[j] = s[i + j - 1]; } for (int i = 1; i <= n; i++) putchar(res[i]); return 0; } if (k >= 20) FUCK(t); int mx = 0; for (int i = 1; i <= n * 2; i++) if (s[i] == t) tmp[i] = tmp[i - 1] + 1, mx = max(mx, tmp[i]); if ((mx << (k - 1)) >= n) FUCK(t); int all = mx << k - 1, len = n - all; for (int i = 1; i <= all; i++) putchar(t); for (int i = 1; i <= n * 2; i++) if (tmp[i] == mx && i - mx - len + 1 >= 1) { int st = i - mx + 1; bool flag = false; for (int j = 1; j <= len; j++) if (s[st - j] != res[j]) { if (s[st - j] < res[j]) flag = true; break; } if (flag) for (int j = 1; j <= len; j++) res[j] = s[st - j]; } for (int i = 1; i <= len; i++) putchar(res[i]); }
#include <bits/stdc++.h> using namespace std; const int N = 5010; char s[N * 2]; int n; inline void FUCK(char t) { for (int i = 1; i <= n; i++) putchar(t); exit(0); } int tmp[N * 2]; char res[N]; int main() { int k; scanf("%d%d%s", &n, &k, s + 1); char t = 127; for (int i = 1; i <= n; i++) t = min(t, s[i]); for (int i = n + 1; i <= n * 2; i++) s[i] = s[n * 2 - i + 1]; for (int i = 1; i <= n; i++) res[i] = 127; if (k == 1) { for (int i = 1; i <= n + 1; i++) { bool flag = false; for (int j = 1; j <= n; j++) if (s[i + j - 1] != res[j]) { if (s[i + j - 1] < res[j]) flag = true; break; } if (flag) for (int j = 1; j <= n; j++) res[j] = s[i + j - 1]; } for (int i = 1; i <= n; i++) putchar(res[i]); return 0; } if (k >= 20) FUCK(t); int mx = 0; for (int i = 1; i <= n * 2; i++) if (s[i] == t) tmp[i] = tmp[i - 1] + 1, mx = max(mx, tmp[i]); if ((mx << (k - 1)) >= n) FUCK(t); int all = mx << k - 1, len = n - mx; for (int i = 1; i <= all; i++) putchar(t); for (int i = 1; i <= n * 2; i++) if (tmp[i] == mx && i - mx - len + 1 >= 1) { int st = i - mx + 1; bool flag = false; for (int j = 1; j <= len; j++) if (s[st - j] != res[j]) { if (s[st - j] < res[j]) flag = true; break; } if (flag) for (int j = 1; j <= len; j++) res[j] = s[st - j]; } for (int i = 1; i <= n - all; i++) putchar(res[i]); } //
[ "identifier.change", "expression.operation.binary.change", "control_flow.loop.for.condition.change" ]
742,582
742,583
u741086489
cpp
p02943
#include <bits/stdc++.h> using namespace std; const int N = 5010; char s[N * 2]; int n; inline void FUCK(char t) { for (int i = 1; i <= n; i++) putchar(t); exit(0); } int tmp[N * 2]; char res[N]; int main() { int k; scanf("%d%d%s", &n, &k, s + 1); char t = 127; for (int i = 1; i <= n; i++) t = min(t, s[i]); for (int i = n + 1; i <= n * 2; i++) s[i] = s[n * 2 - i + 1]; for (int i = 1; i <= n; i++) res[i] = 127; if (k == 1) { for (int i = 1; i <= n + 1; i++) { bool flag = false; for (int j = 1; j <= n; j++) if (s[i + j - 1] != res[j]) { if (s[i + j - 1] < res[j]) flag = true; break; } if (flag) for (int j = 1; j <= n; j++) res[j] = s[i + j - 1]; } for (int i = 1; i <= n; i++) putchar(res[i]); return 0; } if (k >= 20) FUCK(t); int mx = 0; for (int i = 1; i <= n * 2; i++) if (s[i] == t) tmp[i] = tmp[i - 1] + 1, mx = max(mx, tmp[i]); if ((mx << (k - 1)) >= n) FUCK(t); int all = mx << k - 1, len = n - all; for (int i = 1; i <= all; i++) putchar(t); for (int i = 1; i <= n * 2; i++) if (tmp[i] == mx && i - mx - len + 1 >= 1) { int st = i - mx + 1; bool flag = false; for (int j = 1; j <= len; j++) if (s[st - j] != res[j]) { if (s[st - j] < res[j]) flag = true; break; } if (flag) for (int j = 1; j <= len; j++) res[j] = s[st - j]; } for (int i = 1; i <= len; i++) putchar(res[i]); }
#include <bits/stdc++.h> using namespace std; const int N = 5010; char s[N * 2]; int n; inline void FUCK(char t) { for (int i = 1; i <= n; i++) putchar(t); exit(0); } int tmp[N * 2]; char res[N]; int main() { int k; scanf("%d%d%s", &n, &k, s + 1); char t = 127; for (int i = 1; i <= n; i++) t = min(t, s[i]); for (int i = n + 1; i <= n * 2; i++) s[i] = s[n * 2 - i + 1]; for (int i = 1; i <= n; i++) res[i] = 127; if (k == 1) { for (int i = 1; i <= n + 1; i++) { bool flag = false; for (int j = 1; j <= n; j++) if (s[i + j - 1] != res[j]) { if (s[i + j - 1] < res[j]) flag = true; break; } if (flag) for (int j = 1; j <= n; j++) res[j] = s[i + j - 1]; } for (int i = 1; i <= n; i++) putchar(res[i]); return 0; } if (k >= 20) FUCK(t); int mx = 0; for (int i = 1; i <= n * 2; i++) if (s[i] == t) tmp[i] = tmp[i - 1] + 1, mx = max(mx, tmp[i]); if ((mx << (k - 1)) >= n) FUCK(t); int all = mx << k - 1, len = n - mx; for (int i = 1; i <= all; i++) putchar(t); for (int i = 1; i <= n * 2; i++) if (tmp[i] == mx && i - mx - len + 1 >= 1) { int st = i - mx + 1; bool flag = false; for (int j = 1; j <= len; j++) if (s[st - j] != res[j]) { if (s[st - j] < res[j]) flag = true; break; } if (flag) for (int j = 1; j <= len; j++) res[j] = s[st - j]; } for (int i = 1; i <= n - all; i++) putchar(res[i]); }
[ "identifier.change", "expression.operation.binary.change", "control_flow.loop.for.condition.change" ]
742,582
742,584
u741086489
cpp
p02943
#include <algorithm> #include <cassert> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; string rev(string s) { reverse(s.begin(), s.end()); return s; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n, k; cin >> n >> k; string s; cin >> s; if (k > 15) { char mn = 'z'; for (char c : s) mn = min(mn, c); for (int i = 0; i < n; ++i) cout << mn; cout << '\n'; return 0; } for (int i = 0; i < k; ++i) { string u = s + rev(s); if (i % 2 == (k - 1) % 2) { s = string(n, 'z'); for (int i = 0; i <= n; ++i) { s = min(s, u.substr(i, n)); } } else { s = string(n, 'z'); for (int i = 0; i <= n; ++i) { s = min(s, rev(u.substr(i, n))); } s = rev(s); } } cout << s << '\n'; }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; string rev(string s) { reverse(s.begin(), s.end()); return s; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n, k; cin >> n >> k; string s; cin >> s; if (k > 15) { char mn = 'z'; for (char c : s) mn = min(mn, c); for (int i = 0; i < n; ++i) cout << mn; cout << '\n'; return 0; } for (int i = 0; i < k; ++i) { string u = s + rev(s); if (i == k - 1) { s = string(n, 'z'); for (int i = 0; i <= n; ++i) { s = min(s, u.substr(i, n)); } } else { s = string(n, 'z'); for (int i = 0; i <= n; ++i) { s = min(s, rev(u.substr(i, n))); } s = rev(s); } } cout << s << '\n'; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove", "control_flow.branch.if.condition.change" ]
742,585
742,586
u108304786
cpp
p02943
#include <algorithm> // #include <cstdlib> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <map> #include <queue> #include <set> #include <string> using namespace std; typedef long long LL; typedef double db; const int oo = 2139063143; const int N = 1010000; const int P = 1000000007; const db eps = 1e-7; #define pritnf printf // char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf; //#define getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) template <typename T> inline void sc(T &x) { x = 0; static int p; p = 1; static char c; c = getchar(); while (!isdigit(c)) { if (c == '-') p = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c - 48); c = getchar(); } x *= p; } template <typename T> inline void print(T x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) print(x / 10); putchar(x % 10 + '0'); } template <typename T> inline void pr(T x) { print(x), putchar('\n'); } template <typename T1, typename T2> void chkmax(T1 &A, T2 B) { A = A >= B ? A : B; } template <typename T1, typename T2> void chkmin(T1 &A, T2 B) { A = A <= B ? A : B; } int n, k; char s[N]; bool check(int x, int y) // x< y { for (int i = 1; i <= n; i++) if (s[x + i - 1] != s[y + i - 1]) return s[x + i - 1] < s[y + i - 1]; return 0; } int main() { // freopen (".in","r",stdin); // freopen (".out","w",stdout); sc(n), sc(k); scanf("%s", s + 1); for (int i = 1; i <= n; i++) s[n * 2 - i + 1] = s[i]; int p = 1; for (int i = 2; i <= n + 1; i++) if (check(i, p)) p = i; int len = 1, f = 1 << (k - 1); while (len < n && s[p + len] == s[1]) ++len; if (k >= 15 || len * f >= n) { for (int i = 1; i <= n; i++) putchar(s[p]); return 0; } for (int i = 1; i <= len * f; i++) putchar(s[p]); int las = n - len * f; for (int i = 1; i <= las; i++) putchar(s[p + len + i - 1]); return 0; }
#include <algorithm> // #include <cstdlib> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <map> #include <queue> #include <set> #include <string> using namespace std; typedef long long LL; typedef double db; const int oo = 2139063143; const int N = 1010000; const int P = 1000000007; const db eps = 1e-7; #define pritnf printf // char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf; //#define getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) template <typename T> inline void sc(T &x) { x = 0; static int p; p = 1; static char c; c = getchar(); while (!isdigit(c)) { if (c == '-') p = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c - 48); c = getchar(); } x *= p; } template <typename T> inline void print(T x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) print(x / 10); putchar(x % 10 + '0'); } template <typename T> inline void pr(T x) { print(x), putchar('\n'); } template <typename T1, typename T2> void chkmax(T1 &A, T2 B) { A = A >= B ? A : B; } template <typename T1, typename T2> void chkmin(T1 &A, T2 B) { A = A <= B ? A : B; } int n, k; char s[N]; bool check(int x, int y) // x< y { for (int i = 1; i <= n; i++) if (s[x + i - 1] != s[y + i - 1]) return s[x + i - 1] < s[y + i - 1]; return 0; } int main() { // freopen (".in","r",stdin); // freopen (".out","w",stdout); sc(n), sc(k); scanf("%s", s + 1); for (int i = 1; i <= n; i++) s[n * 2 - i + 1] = s[i]; int p = 1; for (int i = 2; i <= n + 1; i++) if (check(i, p)) p = i; int len = 1, f = 1 << (k - 1); while (len < n && s[p + len] == s[p]) ++len; if (k >= 15 || len * f >= n) { for (int i = 1; i <= n; i++) putchar(s[p]); return 0; } for (int i = 1; i <= len * f; i++) putchar(s[p]); int las = n - len * f; for (int i = 1; i <= las; i++) putchar(s[p + len + i - 1]); return 0; }
[ "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change", "control_flow.loop.condition.change" ]
742,590
742,591
u110991149
cpp
p02943
#include <bits/stdc++.h> using namespace std; namespace io { const int l = 1 << 20; char buf[l], *s, *t, c; inline void gc() { if (s == t) { t = (s = buf) + fread(buf, 1, l, stdin); c = s == t ? EOF : *s++; } else c = *s++; } template <class IT> inline void gi(IT &x) { x = 0; gc(); while (c < '0' || c > '9') gc(); while ('0' <= c && c <= '9') { x = (x << 1) + (x << 3) + (c ^ 48); gc(); } } char buf0[20]; int a; template <class IT> inline void pi(IT x) { if (x < 0) { putchar('-'); x = -x; } do buf0[++a] = x % 10 + 48; while (x /= 10); while (a) putchar(buf0[a--]); putchar('\n'); } }; // namespace io using io::gi; using io::pi; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; #define pque priority_queue #define rep(i, l, r) for (i = (l); i <= (r); ++i) #define per(i, l, r) for (i = (l); i >= (r); --i) #define REP(i, l, r) for (i = (l); i < (r); ++i) #define PER(i, l, r) for (i = (l); i > (r); --i) #define mp make_pair #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define fi first #define se second template <class IT> inline void cmax(IT &a, IT b) { if (a < b) a = b; } template <class IT> inline void cmin(IT &a, IT b) { if (b < a) a = b; } const int N = 5005; char c[N << 1], a[N], b[N]; int main() { int n, i, j, k, m, t = 0, x = 0, len, nle, sta, f; char ming = 'z'; scanf("%d%d%s", &n, &k, c + 1); m = n << 1 | 1; rep(i, 1, n) b[i] = c[i]; rep(i, 1, n) cmin(ming, c[m - i] = c[i]); REP(i, 1, m) { if (c[i] == ming) cmax(x, ++t); else t = 0; } if (k > 13 || (len = (x << (k - 1))) >= n) { rep(i, 1, n) putchar(ming); return 0; } nle = n - len; sta = len - (x + n); t = 0; REP(j, 1, m) { ++sta; if (c[j] == ming) { if (x == (++t) && j > n) { f = 0; per(i, nle, 1) a[i] = c[i + sta]; per(i, nle, 1) if (a[i] != b[i]) { f = (a[i] < b[i]); break; } if (f) per(i, nle, 1) b[i] = a[i]; } } else t = 0; } per(i, len, 1) putchar(ming); per(i, nle, 1) putchar(b[i]); return 0; }
#include <bits/stdc++.h> using namespace std; namespace io { const int l = 1 << 20; char buf[l], *s, *t, c; inline void gc() { if (s == t) { t = (s = buf) + fread(buf, 1, l, stdin); c = s == t ? EOF : *s++; } else c = *s++; } template <class IT> inline void gi(IT &x) { x = 0; gc(); while (c < '0' || c > '9') gc(); while ('0' <= c && c <= '9') { x = (x << 1) + (x << 3) + (c ^ 48); gc(); } } char buf0[20]; int a; template <class IT> inline void pi(IT x) { if (x < 0) { putchar('-'); x = -x; } do buf0[++a] = x % 10 + 48; while (x /= 10); while (a) putchar(buf0[a--]); putchar('\n'); } }; // namespace io using io::gi; using io::pi; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; #define pque priority_queue #define rep(i, l, r) for (i = (l); i <= (r); ++i) #define per(i, l, r) for (i = (l); i >= (r); --i) #define REP(i, l, r) for (i = (l); i < (r); ++i) #define PER(i, l, r) for (i = (l); i > (r); --i) #define mp make_pair #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define fi first #define se second template <class IT> inline void cmax(IT &a, IT b) { if (a < b) a = b; } template <class IT> inline void cmin(IT &a, IT b) { if (b < a) a = b; } const int N = 5005; char c[N << 1], a[N], b[N]; int main() { int n, i, j, k, m, t = 0, x = 0, len, nle, sta, f; char ming = 'z'; scanf("%d%d%s", &n, &k, c + 1); m = n << 1 | 1; rep(i, 1, n) b[i] = 'z'; // puts(b+1); rep(i, 1, n) cmin(ming, c[m - i] = c[i]); REP(i, 1, m) { if (c[i] == ming) cmax(x, ++t); else t = 0; } if (k > 13 || (len = (x << (k - 1))) >= n) { rep(i, 1, n) putchar(ming); return 0; } nle = n - len; sta = len - (x + n); t = 0; REP(j, 1, m) { ++sta; if (c[j] == ming) { if (x == (++t) && j > n) { f = 0; per(i, nle, 1) a[i] = c[i + sta]; // printf("j=%d sta=%d //nle=%d\n",j,sta,nle); puts(a+1);printf("len=%d\n\n",strlen(a+1)); per(i, nle, 1) if (a[i] != b[i]) { f = (a[i] < b[i]); break; } // printf("i=%d f=%d\n\n",i,f); if (f) per(i, nle, 1) b[i] = a[i]; } } else t = 0; } per(i, len, 1) putchar(ming); per(i, nle, 1) putchar(b[i]); return 0; }
[]
742,592
742,593
u238671650
cpp
p02943
#include <bits/stdc++.h> using namespace std; const int N = 10010; char s[N], ans[N]; int n, k; int check(int l) { for (int i = 0; i < n; i++) { if (s[i + l] != ans[i]) { return s[i + l] < ans[i]; } } return 0; } void cov(int l) { for (int i = 0; i < n; i++) ans[i] = s[i + l]; } int main() { cin >> n >> k; scanf("%s", s); for (int i = n; i < 2 * n; i++) s[i] = s[2 * n - 1 - i]; cov(1); for (int i = 1; i < n; i++) if (check(i)) cov(i); int cnt = 0, cnt1 = 0; for (int i = 0; i < n; i++) { if (ans[i] != ans[0]) break; else cnt++; } cnt1 = cnt; while (k > 1 && cnt < n) k--, cnt <<= 1; cnt = min(cnt, n); for (int i = 1; i <= cnt; i++) putchar(ans[0]); for (int i = 0; i < n - cnt; i++) putchar(ans[i + cnt1]); cout << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 10010; char s[N], ans[N]; int n, k; int check(int l) { for (int i = 0; i < n; i++) { if (s[i + l] != ans[i]) { return s[i + l] < ans[i]; } } return 0; } void cov(int l) { for (int i = 0; i < n; i++) ans[i] = s[i + l]; } int main() { cin >> n >> k; scanf("%s", s); for (int i = n; i < 2 * n; i++) s[i] = s[2 * n - 1 - i]; cov(0); for (int i = 1; i < n; i++) if (check(i)) cov(i); int cnt = 0, cnt1 = 0; for (int i = 0; i < n; i++) { if (ans[i] != ans[0]) break; else cnt++; } cnt1 = cnt; while (k > 1 && cnt < n) k--, cnt <<= 1; cnt = min(cnt, n); for (int i = 1; i <= cnt; i++) putchar(ans[0]); for (int i = 0; i < n - cnt; i++) putchar(ans[i + cnt1]); cout << endl; }
[ "literal.number.change", "call.arguments.change" ]
742,594
742,595
u493993074
cpp
p02943
#include <bits/stdc++.h> using namespace std; int main() { string s; int n, k, st = 0, ed; cin >> n >> k >> s; if (k > 30 || (1 << (k - 1)) >= n) { cout << string(n, *min_element(s.begin(), s.end())) << "\n"; return 0; } string S = s; reverse(S.begin(), S.end()); string T = s + S; for (int i = 1; i < n; i++) if (T.substr(i, n) < T.substr(st, n)) st = i; for (ed = st; ed - st + 1 < n && T[st] == T[ed]; ed++) ; for (int i = 1; i <= ((ed - st) << (k - 1)); i++) cout << T[st], n--; while (n--) cout << T[ed++]; cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; int n, k, st = 0, ed; cin >> n >> k >> s; if (k > 30 || (1 << (k - 1)) >= n) { cout << string(n, *min_element(s.begin(), s.end())) << "\n"; return 0; } string S = s; reverse(S.begin(), S.end()); string T = s + S; for (int i = 1; i < n; i++) if (T.substr(i, n) < T.substr(st, n)) st = i; for (ed = st; ed - st + 1 < n && T[st] == T[ed]; ed++) ; for (int i = 1; i <= ((ed - st) << (k - 1)) && n; i++) cout << T[st], n--; while (n--) cout << T[ed++]; cout << "\n"; return 0; }
[ "control_flow.loop.for.condition.change" ]
742,598
742,599
u004427876
cpp
p02943
#include <bits/stdc++.h> using namespace std; #define ll long long #define REP(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; i++) #define DREP(i, a, b) for (int i = (a), _end_ = (b); i >= _end_; i--) #define EREP(i, u) for (int i = start[u]; i; i = e[i].next) #define fi first #define se second #define mkr(a, b) make_pair(a, b) #define SZ(A) ((int)A.size()) template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } inline void myassert(bool a, string s) { if (!a) cerr << s << endl, exit(0); } inline int read() { int s = 0, f = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') ch = getchar(), f = -1; while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar(); return ~f ? s : -s; } const int maxn = 5e3 + 20; int n, k; char str[maxn]; char mn; int len; inline string solve(int l, int r) { string s; int len = r - l + 1; REP(i, 1, len << k - 1) s += mn; REP(i, r + 1, n) if (SZ(s) < n) s += str[i]; DREP(i, n, 1) if (SZ(s) < n) s += str[i]; return s; } inline string solve1(int l, int r) { string s; int len = r - l + 1; REP(i, 1, len << k) s += mn; DREP(i, l - 1, 1) if (SZ(s) < n) s += str[i]; return s; } inline void init() { n = read(); k = read(); scanf("%s", str + 1); mn = 'z' + 1; REP(i, 1, n) chkmin(mn, str[i]); if (k > 20) { REP(i, 1, n) putchar(mn); exit(0); } int slen = 0, lstlen = 0; REP(i, 1, n) { if (i == n || str[i] != mn) { chkmax(len, slen); slen = 0; } else slen++; } while (lstlen < n && str[n - lstlen] == mn) ++lstlen; if (slen << k - 1 >= n) { REP(i, 1, n) putchar(mn); exit(0); } if (lstlen << k >= n) { REP(i, 1, n) putchar(mn); exit(0); } string s; slen = 0; REP(i, 1, n) { if (i == n || str[i] != mn) { // chkmax(len,slen); if (slen == len) { string up = solve(i - len, i - 1); if (s.empty() || s > up) s = up; } slen = 0; } else slen++; } if (lstlen > 0) { string up = solve1(n - lstlen + 1, n); if (s.empty() || s > up) s = up; } cout << s << endl; } inline void doing() {} int main() { init(); doing(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define REP(i, a, b) for (int i = (a), _end_ = (b); i <= _end_; i++) #define DREP(i, a, b) for (int i = (a), _end_ = (b); i >= _end_; i--) #define EREP(i, u) for (int i = start[u]; i; i = e[i].next) #define fi first #define se second #define mkr(a, b) make_pair(a, b) #define SZ(A) ((int)A.size()) template <class T> inline void chkmin(T &a, T b) { if (a > b) a = b; } template <class T> inline void chkmax(T &a, T b) { if (a < b) a = b; } inline void myassert(bool a, string s) { if (!a) cerr << s << endl, exit(0); } inline int read() { int s = 0, f = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') ch = getchar(), f = -1; while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar(); return ~f ? s : -s; } const int maxn = 5e3 + 20; int n, k; char str[maxn]; char mn; int len; inline string solve(int l, int r) { string s; int len = r - l + 1; REP(i, 1, len << k - 1) s += mn; REP(i, r + 1, n) if (SZ(s) < n) s += str[i]; DREP(i, n, 1) if (SZ(s) < n) s += str[i]; return s; } inline string solve1(int l, int r) { string s; int len = r - l + 1; REP(i, 1, len << k) s += mn; DREP(i, l - 1, 1) if (SZ(s) < n) s += str[i]; return s; } inline void init() { n = read(); k = read(); scanf("%s", str + 1); mn = 'z' + 1; REP(i, 1, n) chkmin(mn, str[i]); if (k > 20) { REP(i, 1, n) putchar(mn); exit(0); } int slen = 0, lstlen = 0; REP(i, 1, n) { if (i == n || str[i] != mn) { chkmax(len, slen); slen = 0; } else slen++; } while (lstlen < n && str[n - lstlen] == mn) ++lstlen; if (len << k - 1 >= n) { REP(i, 1, n) putchar(mn); exit(0); } if (lstlen << k >= n) { REP(i, 1, n) putchar(mn); exit(0); } string s; slen = 0; REP(i, 1, n) { if (i == n || str[i] != mn) { // chkmax(len,slen); if (slen == len) { string up = solve(i - len, i - 1); if (s.empty() || s > up) s = up; } slen = 0; } else slen++; } if (lstlen > 0) { string up = solve1(n - lstlen + 1, n); if (s.empty() || s > up) s = up; } cout << s << endl; } inline void doing() {} int main() { init(); doing(); return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
742,602
742,603
u057222094
cpp
p02943
#include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <algorithm> #include <bitset> #include <chrono> #include <functional> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> #define LOG(FMT...) fprintf(stderr, FMT) using namespace std; typedef long long ll; typedef unsigned long long ull; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { if (!v.empty()) { os << v.front(); for (int i = 1; i < v.size(); ++i) os << ' ' << v[i]; } return os; } const int N = 5010; char s[N * 2], ans[N], tmp[N]; int cur[N * 2]; int main() { #ifdef LBT freopen("test.in", "r", stdin); int nol_cl = clock(); #endif ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k >> (s + 1); for (int i = 1; i <= n; ++i) s[i + n] = s[n - i + 1]; char c = *min_element(s + 1, s + n + 1); int len = 0; for (int i = 1; i <= n * 2; ++i) if (s[i] == c) len = max(len, cur[i] = cur[i - 1] + 1); if (k >= 15 || (len << (k - 1)) >= n) { for (int rep = 0; rep < n; ++rep) putchar('c'); putchar('\n'); return 0; } for (int i = n + 1; i <= n * 2; ++i) if (cur[i] == len) { for (int j = 1; j <= (n - (len << (k - 1))); ++j) tmp[j] = s[i - len - j + 1]; if (ans[1] == 0 || strcmp(ans + 1, tmp + 1) > 0) memcpy(ans + 1, tmp + 1, n - (len << (k - 1))); } for (int rep = 0; rep < len << (k - 1); ++rep) putchar(c); puts(ans + 1); #ifdef LBT LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000)); #endif return 0; }
#include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <algorithm> #include <bitset> #include <chrono> #include <functional> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> #define LOG(FMT...) fprintf(stderr, FMT) using namespace std; typedef long long ll; typedef unsigned long long ull; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { if (!v.empty()) { os << v.front(); for (int i = 1; i < v.size(); ++i) os << ' ' << v[i]; } return os; } const int N = 5010; char s[N * 2], ans[N], tmp[N]; int cur[N * 2]; int main() { #ifdef LBT freopen("test.in", "r", stdin); int nol_cl = clock(); #endif ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k >> (s + 1); for (int i = 1; i <= n; ++i) s[i + n] = s[n - i + 1]; char c = *min_element(s + 1, s + n + 1); int len = 0; for (int i = 1; i <= n * 2; ++i) if (s[i] == c) len = max(len, cur[i] = cur[i - 1] + 1); if (k >= 15 || (len << (k - 1)) >= n) { for (int rep = 0; rep < n; ++rep) putchar(c); putchar('\n'); return 0; } for (int i = n + 1; i <= n * 2; ++i) if (cur[i] == len) { for (int j = 1; j <= (n - (len << (k - 1))); ++j) tmp[j] = s[i - len - j + 1]; if (ans[1] == 0 || strcmp(ans + 1, tmp + 1) > 0) memcpy(ans + 1, tmp + 1, n - (len << (k - 1))); } for (int rep = 0; rep < len << (k - 1); ++rep) putchar(c); puts(ans + 1); #ifdef LBT LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000)); #endif return 0; }
[ "call.arguments.change" ]
742,608
742,609
u895067736
cpp
p02943
#include <bits/stdc++.h> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int, P> pip; typedef vector<pip> vip; const int inf = 1 << 30; const ll INF = 1ll << 55; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; int n, k; string s; int main() { cin >> n >> k >> s; char c = (char)('z' + 1); int m, I = 0; string s_ = s; reverse(s_.begin(), s_.end()); s += s_ + '#'; for (int i = 1; i <= 2 * n; i++) if (s[i] != s[i - 1]) { if (s[I] < c) c = s[i], m = i - I; else if (s[I] == c && i - I > m) m = i - I; I = i; } string res; res += (char)('z' + 1); int M = min(n, (k >= 14 ? n : m * (1 << (k - 1)))); for (int i = 0; i < n; i++) if (s.substr(i, m) == string(m, c)) { string t(M, c); for (int j = 0; j < n - M; j++) t += s[i + j + m]; res = min(res, t); } cout << res << endl; }
#include <bits/stdc++.h> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int, P> pip; typedef vector<pip> vip; const int inf = 1 << 30; const ll INF = 1ll << 55; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; int n, k; string s; int main() { cin >> n >> k >> s; char c = (char)('z' + 1); int m, I = 0; string s_ = s; reverse(s_.begin(), s_.end()); s += s_ + '#'; for (int i = 1; i <= 2 * n; i++) if (s[i] != s[i - 1]) { if (s[I] < c) c = s[I], m = i - I; else if (s[I] == c && i - I > m) m = i - I; I = i; } string res; res += (char)('z' + 1); int M = min(n, (k >= 14 ? n : m * (1 << (k - 1)))); for (int i = 0; i < n; i++) if (s.substr(i, m) == string(m, c)) { string t(M, c); for (int j = 0; j < n - M; j++) t += s[i + j + m]; res = min(res, t); } cout << res << endl; }
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change" ]
742,610
742,611
u434747175
cpp
p02943
#include <bits/stdc++.h> #define clr(x) memset(x, 0, sizeof x) #define For(i, a, b) for (int i = (a); i <= (b); i++) #define Fod(i, b, a) for (int i = (b); i >= (a); i--) #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #define fi first #define se second #define outval(x) cerr << #x " = " << x << endl #define outtag(x) cerr << "-----------------" #x "-----------------\n" #define outarr(a, L, R) \ cerr << #a "[" << L << ".." << R << "] = "; \ For(_x, L, R) cerr << a[_x] << " "; \ cerr << endl; using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int, int> pii; LL read() { LL x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f = ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return f ? -x : x; } const int N = 5005 * 2; int n, k; char s[N], mi = 'z'; int cl[N]; int cmp(char *a, char *b, int len) { For(i, 0, len - 1) if (a[i] != b[i]) return a[i] < b[i]; return 0; } int main() { n = read(), k = read() - 1; cin >> (s + 1); For(i, 1, n) s[i + n] = s[i]; reverse(s + n + 1, s + n * 2 + 1); For(i, 1, n) mi = min(mi, s[i]); For(i, 1, n * 2) cl[i] = s[i] != s[i - 1] ? 1 : cl[i - 1] + 1; int mx = 1; For(i, 1, n * 2) if (s[i] == mi) mx = max(mx, cl[i]); k = min(k, 15); if ((mx << k) >= n) { For(i, 1, n) putchar(mi); puts(""); return 0; } int rlen = n - (mx << k); int res = 0; For(i, 1, n * 2 - rlen) if (s[i] == mi && cl[i] == mx) { if (!res || !cmp(s + res, s + i + 1, rlen)) res = i + 1; } For(i, 1, (mx << k)) putchar(mi); For(i, 0, rlen - 1) putchar(s[res + i]); puts(""); return 0; }
#include <bits/stdc++.h> #define clr(x) memset(x, 0, sizeof x) #define For(i, a, b) for (int i = (a); i <= (b); i++) #define Fod(i, b, a) for (int i = (b); i >= (a); i--) #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #define fi first #define se second #define outval(x) cerr << #x " = " << x << endl #define outtag(x) cerr << "-----------------" #x "-----------------\n" #define outarr(a, L, R) \ cerr << #a "[" << L << ".." << R << "] = "; \ For(_x, L, R) cerr << a[_x] << " "; \ cerr << endl; using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int, int> pii; LL read() { LL x = 0, f = 0; char ch = getchar(); while (!isdigit(ch)) f = ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return f ? -x : x; } const int N = 5005 * 2; int n, k; char s[N], mi = 'z'; int cl[N]; int cmp(char *a, char *b, int len) { For(i, 0, len - 1) if (a[i] != b[i]) return a[i] < b[i]; return 0; } int main() { n = read(), k = read() - 1; cin >> (s + 1); For(i, 1, n) s[i + n] = s[i]; reverse(s + n + 1, s + n * 2 + 1); For(i, 1, n) mi = min(mi, s[i]); For(i, 1, n * 2) cl[i] = s[i] != s[i - 1] ? 1 : cl[i - 1] + 1; int mx = 1; For(i, 1, n * 2) if (s[i] == mi) mx = max(mx, cl[i]); k = min(k, 15); if ((mx << k) >= n) { For(i, 1, n) putchar(mi); puts(""); return 0; } int rlen = n - (mx << k); int res = 0; For(i, 1, n * 2 - (n - mx)) if (s[i] == mi && cl[i] == mx) { if (!res || !cmp(s + res, s + i + 1, rlen)) res = i + 1; } For(i, 1, (mx << k)) putchar(mi); For(i, 0, rlen - 1) putchar(s[res + i]); puts(""); return 0; }
[ "call.arguments.change", "expression.operation.binary.change" ]
742,612
742,613
u773881973
cpp
p02943
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int n, k, last, mx, len; char a, s[10010], ans[5050] = {0, 'z'}, now[5050]; void work(int l) { for (int i = 1; i <= len; ++i) now[n - len + i] = s[l - mx + 1 - i]; for (int i = 1; i <= n - len; ++i) now[i] = a; for (int i = 1; i <= n; ++i) if (now[i] != ans[i]) { if (now[i] < ans[i]) swap(now, ans); return; } } int main() { scanf("%d %d", &n, &k); scanf("%s", s + 1); a = 'z'; for (int i = 1; i <= n; ++i) s[2 * n + 1 - i] = s[i], a = min(a, s[i]); if (k >= 14) { for (int i = 1; i <= n; ++i) putchar(a); return 0; } last = 1, mx = 0, len; for (int i = 1; i <= 2 * n; ++i) if (s[i] != a) mx = max(mx, i - last), last = i + 1; len = mx; for (int i = 1; i < k; ++i) len <<= 1; if (len >= n) { for (int i = 1; i <= n; ++i) putchar(a); return 0; } len = n - len; last = 1; for (int i = 1; i <= 2 * n; ++i) if (s[i] != a) { if (i - last == mx && i - 1 >= n) work(i - 1); last = i + 1; } for (int i = 1; i <= n; ++i) putchar(ans[i]); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int n, k, last, mx, len; char a, s[10010], ans[5050] = {0, 'z'}, now[5050]; void work(int l) { for (int i = 1; i <= len; ++i) now[n - len + i] = s[l - mx + 1 - i]; for (int i = 1; i <= n - len; ++i) now[i] = a; for (int i = 1; i <= n; ++i) if (now[i] != ans[i]) { if (now[i] < ans[i]) swap(now, ans); return; } } int main() { scanf("%d %d", &n, &k); scanf("%s", s + 1); a = 'z'; for (int i = 1; i <= n; ++i) s[2 * n + 1 - i] = s[i], a = min(a, s[i]); if (k >= 14) { for (int i = 1; i <= n; ++i) putchar(a); return 0; } last = 1, mx = 0, len; for (int i = 1; i <= 2 * n + 1; ++i) if (s[i] != a) mx = max(mx, i - last), last = i + 1; len = mx; for (int i = 1; i < k; ++i) len <<= 1; if (len >= n) { for (int i = 1; i <= n; ++i) putchar(a); return 0; } len = n - len; last = 1; for (int i = 1; i <= 2 * n + 1; ++i) if (s[i] != a) { if (i - last == mx && i - 1 >= n) work(i - 1); last = i + 1; } for (int i = 1; i <= n; ++i) putchar(ans[i]); return 0; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
742,614
742,615
u361707943
cpp
p02943
/*Lucky_Glass*/ #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> using namespace std; const int N = 20000; int n, m; char Is[N + 5], ReS[N + 5], It[N + 3], Ns[N + 3], Nans[N + 3]; int main() { scanf("%d%d%s", &n, &m, Is + 1); strcpy(ReS + 1, Is + 1); reverse(ReS + 1, ReS + 1 + n); strcat(Is + 1, ReS + 1); m--; for (int i = 1; i <= n; i++) { for (int j = 0; j < n; j++) It[j + 1] = Is[j + i]; It[n + 1] = It[n]; int Vlen = 0; for (int j = n; j >= 1; j--) if (It[j] == It[j + 1]) Vlen++; else break; int logf = ceil(log2(ceil((double)n / Vlen))); if (m >= logf) { for (int j = 1; j <= n; j++) Ns[j] = It[n]; } else { int k = n - Vlen; for (int j = 1; j <= Vlen * (1 << m); j++) Ns[j] = It[n]; for (int j = 1; j + Vlen * (1 << m) <= n; j++) Ns[j + Vlen * (1 << m)] = It[k--]; } Ns[n + 1] = '\0'; // printf("%s\n",Ns+1); if (Nans[1] == '\0') strcpy(Nans + 1, Ns + 1); else if (strcmp(Nans + 1, Ns + 1) > 0) strcpy(Nans + 1, Ns + 1); } printf("%s\n", Nans + 1); return 0; } /* 10 100000 bbaabbbaab */
/*Lucky_Glass*/ #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> using namespace std; const int N = 20000; int n, m; char Is[N + 5], ReS[N + 5], It[N + 3], Ns[N + 3], Nans[N + 3]; int main() { scanf("%d%d%s", &n, &m, Is + 1); strcpy(ReS + 1, Is + 1); reverse(ReS + 1, ReS + 1 + n); strcat(Is + 1, ReS + 1); m--; for (int i = 1; i <= n + 1; i++) { for (int j = 0; j < n; j++) It[j + 1] = Is[j + i]; It[n + 1] = It[n]; int Vlen = 0; for (int j = n; j >= 1; j--) if (It[j] == It[j + 1]) Vlen++; else break; int logf = ceil(log2(ceil((double)n / Vlen))); if (m >= logf) { for (int j = 1; j <= n; j++) Ns[j] = It[n]; } else { int k = n - Vlen; for (int j = 1; j <= Vlen * (1 << m); j++) Ns[j] = It[n]; for (int j = 1; j + Vlen * (1 << m) <= n; j++) Ns[j + Vlen * (1 << m)] = It[k--]; } Ns[n + 1] = '\0'; // printf("%s\n",Ns+1); if (Nans[1] == '\0') strcpy(Nans + 1, Ns + 1); else if (strcmp(Nans + 1, Ns + 1) > 0) strcpy(Nans + 1, Ns + 1); } printf("%s\n", Nans + 1); return 0; } /* 10 1 bbaabbbaab */
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
742,616
742,617
u414712570
cpp
p02943
/*Lucky_Glass*/ #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> using namespace std; const int N = 5000; int n, m; char Is[N + 5], ReS[N + 5], It[N + 3], Ns[N + 3], Nans[N + 3]; int main() { scanf("%d%d%s", &n, &m, Is + 1); strcpy(ReS + 1, Is + 1); reverse(ReS + 1, ReS + 1 + n); strcat(Is + 1, ReS + 1); m--; for (int i = 1; i <= n; i++) { for (int j = 0; j < n; j++) It[j + 1] = Is[j + i]; It[n + 1] = It[n]; int Vlen = 0; for (int j = n; j >= 1; j--) if (It[j] == It[j + 1]) Vlen++; else break; int logf = ceil(log2(ceil((double)n / Vlen))); if (m >= logf) { for (int j = 1; j <= n; j++) Ns[j] = It[n]; } else { int k = n - Vlen; for (int j = 1; j <= Vlen * (1 << m); j++) Ns[j] = It[n]; for (int j = 1; j + Vlen * (1 << m) <= n; j++) Ns[j + Vlen * (1 << m)] = It[k--]; } Ns[n + 1] = '\0'; // printf("%s\n",Ns+1); if (Nans[1] == '\0') strcpy(Nans + 1, Ns + 1); else if (strcmp(Nans + 1, Ns + 1) > 0) strcpy(Nans + 1, Ns + 1); } printf("%s\n", Nans + 1); return 0; } /* 10 100000 bbaabbbaab */
/*Lucky_Glass*/ #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> using namespace std; const int N = 20000; int n, m; char Is[N + 5], ReS[N + 5], It[N + 3], Ns[N + 3], Nans[N + 3]; int main() { scanf("%d%d%s", &n, &m, Is + 1); strcpy(ReS + 1, Is + 1); reverse(ReS + 1, ReS + 1 + n); strcat(Is + 1, ReS + 1); m--; for (int i = 1; i <= n + 1; i++) { for (int j = 0; j < n; j++) It[j + 1] = Is[j + i]; It[n + 1] = It[n]; int Vlen = 0; for (int j = n; j >= 1; j--) if (It[j] == It[j + 1]) Vlen++; else break; int logf = ceil(log2(ceil((double)n / Vlen))); if (m >= logf) { for (int j = 1; j <= n; j++) Ns[j] = It[n]; } else { int k = n - Vlen; for (int j = 1; j <= Vlen * (1 << m); j++) Ns[j] = It[n]; for (int j = 1; j + Vlen * (1 << m) <= n; j++) Ns[j + Vlen * (1 << m)] = It[k--]; } Ns[n + 1] = '\0'; // printf("%s\n",Ns+1); if (Nans[1] == '\0') strcpy(Nans + 1, Ns + 1); else if (strcmp(Nans + 1, Ns + 1) > 0) strcpy(Nans + 1, Ns + 1); } printf("%s\n", Nans + 1); return 0; } /* 10 1 bbaabbbaab */
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
742,618
742,617
u414712570
cpp
p02943
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; #define MAXN 10000 #define LL long long #define Pr pair<int, int> #define X first #define Y second int n, k; char s[MAXN + 5], Mn, Mx, ans[MAXN + 5], tmp[MAXN + 5]; LL read() { LL x = 0, F = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') F = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * F; } void cal(char *s, int t) { int np = n, len = 0; while (np >= 1 && s[np] == Mn) np--, len++; while (k > 0 && len < n) len *= 2, k--; if (len >= n) { for (int i = 1; i <= n; i++) ans[i] = Mn; return; } for (int i = 1; i <= len; i++) tmp[i] = Mn; for (int i = len + 1; i <= n; i++) tmp[i] = s[np--]; for (int i = 1; i <= n; i++) if (tmp[i] < ans[i]) { for (int j = 1; j <= n; j++) ans[j] = tmp[j]; return; } else if (tmp[i] > ans[i]) return; } int main() { n = read(), k = read(); scanf("%s", s + 1); Mn = 'z', Mx = 'a'; for (int i = 1; i <= n; i++) { Mn = min(Mn, s[i]), Mx = max(Mx, s[i]); s[n * 2 - i + 1] = s[i]; ans[i] = 'z'; } if (s[n] == Mn) cal(s, k); for (int i = n; i <= 2 * n; i++) if (s[i] == Mn) cal(s + i - n, k - 1); printf("%s", ans + 1); }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; #define MAXN 10000 #define LL long long #define Pr pair<int, int> #define X first #define Y second int n, k; char s[MAXN + 5], Mn, Mx, ans[MAXN + 5], tmp[MAXN + 5]; LL read() { LL x = 0, F = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') F = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * F; } void cal(char *s, int t) { int np = n, len = 0; while (np >= 1 && s[np] == Mn) np--, len++; while (t > 0 && len < n) len *= 2, t--; if (len >= n) { for (int i = 1; i <= n; i++) ans[i] = Mn; return; } for (int i = 1; i <= len; i++) tmp[i] = Mn; for (int i = len + 1; i <= n; i++) tmp[i] = s[np--]; for (int i = 1; i <= n; i++) if (tmp[i] < ans[i]) { for (int j = 1; j <= n; j++) ans[j] = tmp[j]; return; } else if (tmp[i] > ans[i]) return; } int main() { n = read(), k = read(); scanf("%s", s + 1); Mn = 'z', Mx = 'a'; for (int i = 1; i <= n; i++) { Mn = min(Mn, s[i]), Mx = max(Mx, s[i]); s[n * 2 - i + 1] = s[i]; ans[i] = 'z'; } if (s[n] == Mn) cal(s, k); for (int i = n; i <= 2 * n; i++) if (s[i] == Mn) cal(s + i - n, k - 1); printf("%s", ans + 1); }
[ "identifier.change", "control_flow.loop.condition.change" ]
742,619
742,620
u778193086
cpp
p02943
#include <algorithm> #include <cstdio> #include <cstring> #include <string> using namespace std; int read() { int x = 0; bool f = 0; char c = getchar(); while (c < '0' || c > '9') f |= c == '-', c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getchar(); return f ? -x : x; } #define MAXN 5000 #define LL long long int N, K; char Min, Max, Ans[2 * MAXN + 5], str[2 * MAXN + 5]; char tmp[2 * MAXN + 5]; void Solve(char *S) { int Now = N, len = 0, k = K; while (Now >= 1 && S[Now] == Min) Now--, len++; while (k && len <= N - 1) len <<= 1, k--; if (len >= N) { for (int i = 1; i <= N; i++) Ans[i] = Min; puts(Ans); exit(0); } for (int i = 1; i <= len; i++) tmp[i] = Min; for (int i = len + 1; i <= N; i++) tmp[i] = S[Now--]; /* for(int i=1;i<=N;i++){ if(tmp[i]!=Ans[i]){ if(tmp[i]<Ans[i]) memcpy(Ans,tmp,sizeof tmp); return; } } */ for (int i = 1; i <= N; i++) if (tmp[i] < Ans[i]) { for (int j = 1; j <= N; j++) Ans[j] = tmp[j]; return; } else if (tmp[i] > Ans[i]) return; } int main() { N = read(), K = read(); scanf("%s", str + 1); Min = 'z', Max = 'a'; for (int i = 1; i <= N; i++) { Min = min(Min, str[i]); Max = max(Max, str[i]); str[2 * N - i + 1] = str[i]; Ans[i] = 'z'; } if (Min == Max) return puts(str + 1), 0; if (str[N] == Min) Solve(str); K--; for (int i = N + 1; i <= 2 * N; i++) if (str[i] == Min) Solve(str + i - N); puts(Ans + 1); }
#include <algorithm> #include <cstdio> #include <cstring> #include <string> using namespace std; int read() { int x = 0; bool f = 0; char c = getchar(); while (c < '0' || c > '9') f |= c == '-', c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getchar(); return f ? -x : x; } #define MAXN 5000 #define LL long long int N, K; char Min, Max, Ans[2 * MAXN + 5], str[2 * MAXN + 5]; char tmp[2 * MAXN + 5]; void Solve(char *S) { int Now = N, len = 0, k = K; while (Now >= 1 && S[Now] == Min) Now--, len++; while (k && len <= N - 1) len <<= 1, k--; if (len >= N) { for (int i = 1; i <= N; i++) Ans[i] = Min; puts(Ans + 1); exit(0); } for (int i = 1; i <= len; i++) tmp[i] = Min; for (int i = len + 1; i <= N; i++) tmp[i] = S[Now--]; /* for(int i=1;i<=N;i++){ if(tmp[i]!=Ans[i]){ if(tmp[i]<Ans[i]) memcpy(Ans,tmp,sizeof tmp); return; } } */ for (int i = 1; i <= N; i++) if (tmp[i] < Ans[i]) { for (int j = 1; j <= N; j++) Ans[j] = tmp[j]; return; } else if (tmp[i] > Ans[i]) return; } int main() { N = read(), K = read(); scanf("%s", str + 1); Min = 'z', Max = 'a'; for (int i = 1; i <= N; i++) { Min = min(Min, str[i]); Max = max(Max, str[i]); str[2 * N - i + 1] = str[i]; Ans[i] = 'z'; } if (Min == Max) return puts(str + 1), 0; if (str[N] == Min) Solve(str); K--; for (int i = N + 1; i <= 2 * N; i++) if (str[i] == Min) Solve(str + i - N); puts(Ans + 1); }
[ "expression.operation.binary.add" ]
742,621
742,622
u879099684
cpp
p02943
#include <bits/stdc++.h> using namespace std; void read(int &x) { x = 0; int f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -f; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; x *= f; } void print(int x) { if (x < 0) putchar('-'), x = -x; if (!x) return; print(x / 10), putchar(x % 10 + 48); } void write(int x) { if (!x) putchar('0'); else print(x); putchar('\n'); } #define lf double #define ll long long #define pii pair<int, int> #define vec vector<int> #define pb push_back #define mp make_pair #define fr first #define sc second #define FOR(i, l, r) for (int i = l, i##_r = r; i <= i##_r; i++) const int maxn = 1e6 + 10; const int inf = 1e9; const lf eps = 1e-8; const int mod = 1e9 + 7; int n, k; char s[maxn]; vector<int> p; int cmp(int a, int b) { for (; a && b; a--, b--) if (s[a] > s[b]) return 0; else if (s[a] < s[b]) return 1; return 0; } int main() { read(n), read(k), scanf("%s", s + 1); int t = 1e9; for (int i = n + 1; i <= 2 * n; i++) s[i] = s[2 * n - i + 1], t = min(t, (int)s[i]); // cout<<s+1<<endl; int mx = 0, r = 0; for (int i = 1; i <= (n << 1) + 1; i++) if (s[i] != t && s[i - 1] == t) { if (r > mx) mx = r, p.clear(), i > n ? p.pb(i - 1) : void(); else if (r == mx) i > n ? p.pb(i - 1) : void(); r = 0; } else if (s[i] == t) r++; // for(auto x:p) printf("%d ",x);puts(""); t = p[0]; for (int i = 1; i < p.size(); i++) if (cmp(i, t)) t = i; k--; // write(t); if (k > 18) for (int i = 1; i <= n; i++) putchar(s[t]); else { for (int i = 1; i <= min(n, mx * (1 << k)); i++) putchar(s[t]); for (int i = 1; i <= max(0, n - mx * (1 << k)); i++) putchar(s[t - mx + 1 - i]); } puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; void read(int &x) { x = 0; int f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -f; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; x *= f; } void print(int x) { if (x < 0) putchar('-'), x = -x; if (!x) return; print(x / 10), putchar(x % 10 + 48); } void write(int x) { if (!x) putchar('0'); else print(x); putchar('\n'); } #define lf double #define ll long long #define pii pair<int, int> #define vec vector<int> #define pb push_back #define mp make_pair #define fr first #define sc second #define FOR(i, l, r) for (int i = l, i##_r = r; i <= i##_r; i++) const int maxn = 1e6 + 10; const int inf = 1e9; const lf eps = 1e-8; const int mod = 1e9 + 7; int n, k; char s[maxn]; vector<int> p; int cmp(int a, int b) { for (; a && b; a--, b--) if (s[a] > s[b]) return 0; else if (s[a] < s[b]) return 1; return 0; } int main() { read(n), read(k), scanf("%s", s + 1); int t = 1e9; for (int i = n + 1; i <= 2 * n; i++) s[i] = s[2 * n - i + 1], t = min(t, (int)s[i]); // cout<<s+1<<endl; int mx = 0, r = 0; for (int i = 1; i <= (n << 1) + 1; i++) if (s[i] != t && s[i - 1] == t) { if (r > mx) mx = r, p.clear(), i > n ? p.pb(i - 1) : void(); else if (r == mx) i > n ? p.pb(i - 1) : void(); r = 0; } else if (s[i] == t) r++; // for(auto x:p) printf("%d ",x);puts(""); t = p[0]; for (int i = 1; i < p.size(); i++) if (cmp(p[i], t)) t = p[i]; k--; // write(t); if (k > 18) for (int i = 1; i <= n; i++) putchar(s[t]); else { for (int i = 1; i <= min(n, mx * (1 << k)); i++) putchar(s[t]); for (int i = 1; i <= max(0, n - mx * (1 << k)); i++) putchar(s[t - mx + 1 - i]); } puts(""); return 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change" ]
742,623
742,624
u074465060
cpp
p02943
#include <bits/stdc++.h> using namespace std; typedef bool boolean; const int N = 5005; int n, K; int mxR[N]; char s[N << 1], t[N], ans[N]; void check(char *s, int k, char min_c) { int L = 0, p = n; while (s[n - L] == min_c) L++, p--; L <<= k; if (L >= n) { for (int i = 1; i <= n; i++) putchar(min_c); putchar('\n'); return; } for (int i = 1; i <= L; i++) { t[i] = min_c; } for (int i = L + 1; i <= n; i++) t[i] = s[p--]; for (int i = 1; i <= n; i++) if (t[i] ^ ans[i]) { if (t[i] > ans[i]) { return; } break; } for (int i = 1; i <= n; i++) ans[i] = t[i]; } int main() { scanf("%d%d", &n, &K); scanf("%s", s + 1); for (int i = 1; i <= n; i++) s[2 * n - i + 1] = s[i]; char x = 'z', y = 'a'; for (int i = 1; i <= n; i++) { x = min(x, s[i]); y = max(y, s[i]); } if (K >= 20 || x == y) { for (int i = 1; i <= n; i++) putchar(x); putchar('\n'); return 0; } ans[1] = 'z' + 1; if (s[n] == x) check(s, K, x); int mxL = 0; for (int i = 1, j = 1; i <= n; i = j) { if (s[i] != x) { j++; continue; } while (s[j] == s[i]) j++; mxR[i] = j - i; mxL = max(mxL, mxR[i]); } for (int i = 1; i <= n; i++) { if (mxR[i] == mxL) { check(s + (n - i + 1), K - 1, x); } } puts(ans + 1); return 0; }
#include <bits/stdc++.h> using namespace std; typedef bool boolean; const int N = 5005; int n, K; int mxR[N]; char s[N << 1], t[N], ans[N]; void check(char *s, int k, char min_c) { int L = 0, p = n; while (s[n - L] == min_c) L++, p--; L <<= k; if (L >= n) { for (int i = 1; i <= n; i++) putchar(min_c); putchar('\n'); exit(0); } for (int i = 1; i <= L; i++) { t[i] = min_c; } for (int i = L + 1; i <= n; i++) t[i] = s[p--]; for (int i = 1; i <= n; i++) if (t[i] ^ ans[i]) { if (t[i] > ans[i]) { return; } break; } for (int i = 1; i <= n; i++) ans[i] = t[i]; } int main() { scanf("%d%d", &n, &K); scanf("%s", s + 1); for (int i = 1; i <= n; i++) s[2 * n - i + 1] = s[i]; char x = 'z', y = 'a'; for (int i = 1; i <= n; i++) { x = min(x, s[i]); y = max(y, s[i]); } if (K >= 20 || x == y) { for (int i = 1; i <= n; i++) putchar(x); putchar('\n'); return 0; } ans[1] = 'z' + 1; if (s[n] == x) check(s, K, x); int mxL = 0; for (int i = 1, j = 1; i <= n; i = j) { if (s[i] != x) { j++; continue; } while (s[j] == s[i]) j++; mxR[i] = j - i; mxL = max(mxL, mxR[i]); } for (int i = 1; i <= n; i++) { if (mxR[i] == mxL) { check(s + (n - i + 1), K - 1, x); } } puts(ans + 1); return 0; }
[ "control_flow.return.remove", "control_flow.exit.add", "call.arguments.add" ]
742,627
742,628
u355154283
cpp
p02943
#define y1 askjdkasldjlkasd #include <bits/stdc++.h> #undef y1 using namespace std; #define pb push_back #define mp make_pair #define fi(a, b) for (int i = a; i <= b; i++) #define fj(a, b) for (int j = a; j <= b; j++) #define fo(a, b) for (int o = a; o <= b; o++) #define fdi(a, b) for (int i = a; i >= b; i--) #define fdj(a, b) for (int j = a; j >= b; j--) #define fdo(a, b) for (int o = a; o >= b; o--) #define sz(x) (int)x.size() typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<ll> vll; #ifdef LOCAL #define err(...) fprintf(stderr, __VA_ARGS__) #else #define err(...) while (0) #endif double START_TIME; void exit() { #ifdef LOCAL cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl; #endif exit(0); } template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> v) { fi(0, sz(v) - 1) { os << v[i] << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, set<T> t) { for (auto z : t) { os << z << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, map<T1, T2> t) { cerr << endl; for (auto z : t) { os << "\t" << z.first << " -> " << z.second << endl; } return os; } #ifdef LOCAL #define dbg(x) \ { cerr << __LINE__ << "\t" << #x << ": " << x << endl; } #define dbg0(x, n) \ { \ cerr << __LINE__ << "\t" << #x << ": "; \ for (int ABC = 0; ABC < n; ABC++) \ cerr << x[ABC] << ' '; \ cerr << endl; \ } #else #define dbg(x) \ while (0) { \ } #define dbg0(x, n) \ while (0) { \ } #endif #ifdef LOCAL #define ass(x) \ if (!(x)) { \ cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); \ } #else #define ass(x) assert(x) #endif /////////////////////////////////////////////////// const int MAX = 5e3 + 41; int n, k; char s[MAX]; string ans; void refresh(string &str) { if (sz(ans) == 0 || ans > str) ans = str; } string get(string s, int cnt) { // dbg(s); int lq = 1; fdi(sz(s) - 2, 0) { if (s[i] != s[i + 1]) break; lq++; } ll can = ((ll)lq << cnt); if (can >= n) { return string(n, s[n - 1]); } string res = ""; int shift = can - lq; fi(shift, n - 1) { res.pb(s[i]); } fi(0, can - 1 - lq) { res.pb(s[n - 1]); } // dbg(res); assert(sz(res) == n); reverse(res.begin(), res.end()); return res; } void solve() { k = min(k, 30); string str = ""; str += s; reverse(s, s + n); str += s; reverse(s, s + n); // dbg(str); fi(0, n - 1) { string cur = str.substr(i, n); string resp = get(cur, k - 1); refresh(resp); } printf("%s\n", ans.c_str()); } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); START_TIME = (double)clock(); #endif scanf("%d %d", &n, &k); scanf("%s", s); solve(); exit(); return 0; }
#define y1 askjdkasldjlkasd #include <bits/stdc++.h> #undef y1 using namespace std; #define pb push_back #define mp make_pair #define fi(a, b) for (int i = a; i <= b; i++) #define fj(a, b) for (int j = a; j <= b; j++) #define fo(a, b) for (int o = a; o <= b; o++) #define fdi(a, b) for (int i = a; i >= b; i--) #define fdj(a, b) for (int j = a; j >= b; j--) #define fdo(a, b) for (int o = a; o >= b; o--) #define sz(x) (int)x.size() typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<ll> vll; #ifdef LOCAL #define err(...) fprintf(stderr, __VA_ARGS__) #else #define err(...) while (0) #endif double START_TIME; void exit() { #ifdef LOCAL cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl; #endif exit(0); } template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> v) { fi(0, sz(v) - 1) { os << v[i] << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, set<T> t) { for (auto z : t) { os << z << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, map<T1, T2> t) { cerr << endl; for (auto z : t) { os << "\t" << z.first << " -> " << z.second << endl; } return os; } #ifdef LOCAL #define dbg(x) \ { cerr << __LINE__ << "\t" << #x << ": " << x << endl; } #define dbg0(x, n) \ { \ cerr << __LINE__ << "\t" << #x << ": "; \ for (int ABC = 0; ABC < n; ABC++) \ cerr << x[ABC] << ' '; \ cerr << endl; \ } #else #define dbg(x) \ while (0) { \ } #define dbg0(x, n) \ while (0) { \ } #endif #ifdef LOCAL #define ass(x) \ if (!(x)) { \ cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); \ } #else #define ass(x) assert(x) #endif /////////////////////////////////////////////////// const int MAX = 5e3 + 41; int n, k; char s[MAX]; string ans; void refresh(string &str) { if (sz(ans) == 0 || ans > str) ans = str; } string get(string s, int cnt) { // dbg(s); int lq = 1; fdi(sz(s) - 2, 0) { if (s[i] != s[i + 1]) break; lq++; } ll can = ((ll)lq << cnt); if (can >= n) { return string(n, s[n - 1]); } string res = ""; int shift = can - lq; fi(shift, n - 1) { res.pb(s[i]); } fi(0, can - 1 - lq) { res.pb(s[n - 1]); } // dbg(res); assert(sz(res) == n); reverse(res.begin(), res.end()); return res; } void solve() { k = min(k, 30); string str = ""; str += s; reverse(s, s + n); str += s; reverse(s, s + n); // dbg(str); fi(0, n) { string cur = str.substr(i, n); string resp = get(cur, k - 1); refresh(resp); } printf("%s\n", ans.c_str()); } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); START_TIME = (double)clock(); #endif scanf("%d %d", &n, &k); scanf("%s", s); solve(); exit(); return 0; }
[ "expression.operation.binary.remove" ]
742,629
742,630
u197964611
cpp
p02943
#define y1 askjdkasldjlkasd #include <bits/stdc++.h> #undef y1 using namespace std; #define pb push_back #define mp make_pair #define fi(a, b) for (int i = a; i <= b; i++) #define fj(a, b) for (int j = a; j <= b; j++) #define fo(a, b) for (int o = a; o <= b; o++) #define fdi(a, b) for (int i = a; i >= b; i--) #define fdj(a, b) for (int j = a; j >= b; j--) #define fdo(a, b) for (int o = a; o >= b; o--) #define sz(x) (int)x.size() typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<ll> vll; #ifdef LOCAL #define err(...) fprintf(stderr, __VA_ARGS__) #else #define err(...) while (0) #endif double START_TIME; void exit() { #ifdef LOCAL cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl; #endif exit(0); } template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> v) { fi(0, sz(v) - 1) { os << v[i] << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, set<T> t) { for (auto z : t) { os << z << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, map<T1, T2> t) { cerr << endl; for (auto z : t) { os << "\t" << z.first << " -> " << z.second << endl; } return os; } #ifdef LOCAL #define dbg(x) \ { cerr << __LINE__ << "\t" << #x << ": " << x << endl; } #define dbg0(x, n) \ { \ cerr << __LINE__ << "\t" << #x << ": "; \ for (int ABC = 0; ABC < n; ABC++) \ cerr << x[ABC] << ' '; \ cerr << endl; \ } #else #define dbg(x) \ while (0) { \ } #define dbg0(x, n) \ while (0) { \ } #endif #ifdef LOCAL #define ass(x) \ if (!(x)) { \ cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); \ } #else #define ass(x) assert(x) #endif /////////////////////////////////////////////////// const int MAX = 5e3 + 41; int n, k; char s[MAX]; string ans; void refresh(string &str) { if (sz(ans) == 0 || ans > str) ans = str; } string get(string s, int cnt) { // dbg(s); int lq = 1; fdi(sz(s) - 2, 0) { if (s[i] != s[i + 1]) break; lq++; } ll can = (lq << cnt); if (can >= n) { return string(n, s[n - 1]); } string res = ""; int shift = can - lq; fi(shift, n - 1) { res.pb(s[i]); } fi(0, can - 1 - lq) { res.pb(s[n - 1]); } // dbg(res); assert(sz(res) == n); reverse(res.begin(), res.end()); return res; } void solve() { k = min(k, 30); string str = ""; str += s; reverse(s, s + n); str += s; reverse(s, s + n); // dbg(str); fi(0, n - 1) { string cur = str.substr(i, n); string resp = get(cur, k - 1); refresh(resp); } printf("%s\n", ans.c_str()); } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); START_TIME = (double)clock(); #endif scanf("%d %d", &n, &k); scanf("%s", s); solve(); exit(); return 0; }
#define y1 askjdkasldjlkasd #include <bits/stdc++.h> #undef y1 using namespace std; #define pb push_back #define mp make_pair #define fi(a, b) for (int i = a; i <= b; i++) #define fj(a, b) for (int j = a; j <= b; j++) #define fo(a, b) for (int o = a; o <= b; o++) #define fdi(a, b) for (int i = a; i >= b; i--) #define fdj(a, b) for (int j = a; j >= b; j--) #define fdo(a, b) for (int o = a; o >= b; o--) #define sz(x) (int)x.size() typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<ll> vll; #ifdef LOCAL #define err(...) fprintf(stderr, __VA_ARGS__) #else #define err(...) while (0) #endif double START_TIME; void exit() { #ifdef LOCAL cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl; #endif exit(0); } template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, vector<T> v) { fi(0, sz(v) - 1) { os << v[i] << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, set<T> t) { for (auto z : t) { os << z << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, map<T1, T2> t) { cerr << endl; for (auto z : t) { os << "\t" << z.first << " -> " << z.second << endl; } return os; } #ifdef LOCAL #define dbg(x) \ { cerr << __LINE__ << "\t" << #x << ": " << x << endl; } #define dbg0(x, n) \ { \ cerr << __LINE__ << "\t" << #x << ": "; \ for (int ABC = 0; ABC < n; ABC++) \ cerr << x[ABC] << ' '; \ cerr << endl; \ } #else #define dbg(x) \ while (0) { \ } #define dbg0(x, n) \ while (0) { \ } #endif #ifdef LOCAL #define ass(x) \ if (!(x)) { \ cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); \ } #else #define ass(x) assert(x) #endif /////////////////////////////////////////////////// const int MAX = 5e3 + 41; int n, k; char s[MAX]; string ans; void refresh(string &str) { if (sz(ans) == 0 || ans > str) ans = str; } string get(string s, int cnt) { // dbg(s); int lq = 1; fdi(sz(s) - 2, 0) { if (s[i] != s[i + 1]) break; lq++; } ll can = ((ll)lq << cnt); if (can >= n) { return string(n, s[n - 1]); } string res = ""; int shift = can - lq; fi(shift, n - 1) { res.pb(s[i]); } fi(0, can - 1 - lq) { res.pb(s[n - 1]); } // dbg(res); assert(sz(res) == n); reverse(res.begin(), res.end()); return res; } void solve() { k = min(k, 30); string str = ""; str += s; reverse(s, s + n); str += s; reverse(s, s + n); // dbg(str); fi(0, n) { string cur = str.substr(i, n); string resp = get(cur, k - 1); refresh(resp); } printf("%s\n", ans.c_str()); } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); START_TIME = (double)clock(); #endif scanf("%d %d", &n, &k); scanf("%s", s); solve(); exit(); return 0; }
[ "expression.operation.binary.remove" ]
742,631
742,630
u197964611
cpp
p02943
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> using namespace std; const int N = 10005; int n, k; char mi, mx, s[N], t[N], ans[N]; void ckmin() { bool flag = false; for (int i = 1; i <= n; i++) { if (t[i] > ans[i]) { break; } else if (t[i] < ans[i]) { flag = true; break; } } if (flag) { for (int i = 1; i <= n; i++) { ans[i] = t[i]; } } } void gao(char s[], int k) { int len = 1; while (len < n && s[n - len] == mi) { len++; } int now = n - len + 1; while (k && len < n) { len *= 2; k--; } if (len >= n) { for (int i = 1; i <= n; i++) { t[i] = mi; } ckmin(); } else { for (int i = 1; i <= len; i++) { t[i] = mi; } for (int i = len + 1; i <= n; i++) { t[i] = s[--now]; } ckmin(); } } int main() { scanf("%d%d%s", &n, &k, s + 1); mi = 'z', mx = 'a'; for (int i = 1; i <= n; i++) { s[2 * n - i + 1] = s[i]; mi = min(mi, s[i]); mx = max(mx, s[i]); ans[i] = 'z'; } if (mx == mi) { puts(s + 1); return 0; } if (s[n] == mi) { gao(s, k); } for (int i = n; i < 2 * n; i++) { if (s[i] == mi) { gao(s + i - n, k - 1); } } puts(ans + 1); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> using namespace std; const int N = 10005; int n, k; char mi, mx, s[N], t[N], ans[N]; void ckmin() { bool flag = false; for (int i = 1; i <= n; i++) { if (t[i] > ans[i]) { break; } else if (t[i] < ans[i]) { flag = true; break; } } if (flag) { for (int i = 1; i <= n; i++) { ans[i] = t[i]; } } } void gao(char s[], int k) { int len = 1; while (len < n && s[n - len] == mi) { len++; } int now = n - len + 1; while (k && len < n) { len *= 2; k--; } if (len >= n) { for (int i = 1; i <= n; i++) { t[i] = mi; } ckmin(); } else { for (int i = 1; i <= len; i++) { t[i] = mi; } for (int i = len + 1; i <= n; i++) { t[i] = s[--now]; } ckmin(); } } int main() { scanf("%d%d%s", &n, &k, s + 1); mi = 'z', mx = 'a'; for (int i = 1; i <= n; i++) { s[2 * n - i + 1] = s[i]; mi = min(mi, s[i]); mx = max(mx, s[i]); ans[i] = 'z'; } if (mx == mi) { puts(s + 1); return 0; } if (s[n] == mi) { gao(s, k); } for (int i = n + 1; i <= 2 * n; i++) { if (s[i] == mi) { gao(s + i - n, k - 1); } } puts(ans + 1); return 0; }
[ "control_flow.loop.for.initializer.change", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
742,632
742,633
u159112689
cpp
p02943
#include <bits/stdc++.h> using namespace std; namespace mine { #define double long double typedef long long ll; #define pr pair<int, int> #define FR first #define SE second #define MP make_pair #define PB push_back #define vc vector #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define bin(x) (1ll << (x)) ll qread() { ll ans = 0, f = 1; char c = getchar(); while (c < '0' or c > '9') { if (c == '-') f = -1; c = getchar(); } while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar(); return ans * f; } void write(ll num) { if (num < 0) putchar('-'), num = -num; if (num >= 10) write(num / 10); putchar('0' + num % 10); } void write1(ll num) { write(num); putchar(' '); } void write2(ll num) { write(num); putchar('\n'); } void chmax(int &x, const ll y) { x = (x > y ? x : y); } void chmin(int &x, const ll y) { x = (x < y ? x : y); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : 0; } const int INF = 0x3f3f3f3f; const int MOD = 998244353; inline int mm(const int x) { return x >= MOD ? x - MOD : x; } inline ll qpower(ll x, ll e) { ll ans = 1; while (e) { if (e & 1) ans = ans * x % MOD; x = x * x % MOD; e >>= 1; } return ans; } inline int invm(int x) { return qpower(x, MOD - 2); } const int N = 1e6 + 10; char str[N]; int n; int getmi(int a, int b) { int ta = a, tb = b; while (str[a] == str[b]) a++, b++; return str[a] < str[b] ? ta : tb; } vc<char> ans, ans2; void main() { int n = qread(), k = qread() - 1; scanf("%s", str); for (int i = n; i < n + n; i++) str[i] = str[i - n]; reverse(str + n, str + n + n); int mi = 0; for (int i = 1; i <= n; i++) mi = getmi(mi, i); int cnt = 0; while (cnt < n and str[mi] == str[mi + cnt]) cnt++; // printf("cnt=%d\n",cnt); mi = (n + n - 1 - mi) - n + 1; for (int i = mi; i < mi + n; i++) ans.PB(str[i]); while (k--) { ans2.clear(); if (cnt * 2 >= n) { while (n--) ans2.PB(ans[n - 1]); swap(ans, ans2); break; } int st = n - 1 - (n - cnt) + 1, op = 1; int pp = n; while (pp--) { ans2.PB(ans[st]); st += op; if (st == n) st--, op = -1; } swap(ans, ans2); cnt *= 2; // puts(""); } for (int t = sz(ans) - 1; t >= 0; t--) putchar(ans[t]); } }; // namespace mine int main() { srand(time(0)); mine::main(); }
#include <bits/stdc++.h> using namespace std; namespace mine { #define double long double typedef long long ll; #define pr pair<int, int> #define FR first #define SE second #define MP make_pair #define PB push_back #define vc vector #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define bin(x) (1ll << (x)) ll qread() { ll ans = 0, f = 1; char c = getchar(); while (c < '0' or c > '9') { if (c == '-') f = -1; c = getchar(); } while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar(); return ans * f; } void write(ll num) { if (num < 0) putchar('-'), num = -num; if (num >= 10) write(num / 10); putchar('0' + num % 10); } void write1(ll num) { write(num); putchar(' '); } void write2(ll num) { write(num); putchar('\n'); } void chmax(int &x, const ll y) { x = (x > y ? x : y); } void chmin(int &x, const ll y) { x = (x < y ? x : y); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : 0; } const int INF = 0x3f3f3f3f; const int MOD = 998244353; inline int mm(const int x) { return x >= MOD ? x - MOD : x; } inline ll qpower(ll x, ll e) { ll ans = 1; while (e) { if (e & 1) ans = ans * x % MOD; x = x * x % MOD; e >>= 1; } return ans; } inline int invm(int x) { return qpower(x, MOD - 2); } const int N = 1e6 + 10; char str[N]; int n; int getmi(int a, int b) { int ta = a, tb = b; while (str[a] == str[b]) a++, b++; return str[a] < str[b] ? ta : tb; } vc<char> ans, ans2; void main() { int n = qread(), k = qread() - 1; scanf("%s", str); for (int i = n; i < n + n; i++) str[i] = str[i - n]; reverse(str + n, str + n + n); int mi = 0; for (int i = 1; i <= n; i++) mi = getmi(mi, i); int cnt = 0; while (cnt < n and str[mi] == str[mi + cnt]) cnt++; // printf("cnt=%d\n",cnt); mi = (n + n - 1 - mi) - n + 1; for (int i = mi; i < mi + n; i++) ans.PB(str[i]); while (k--) { ans2.clear(); if (cnt * 2 >= n) { int t = n; while (t--) ans2.PB(ans[n - 1]); swap(ans, ans2); break; } int st = n - 1 - (n - cnt) + 1, op = 1; int pp = n; while (pp--) { ans2.PB(ans[st]); st += op; if (st == n) st--, op = -1; } swap(ans, ans2); cnt *= 2; // puts(""); } for (int t = sz(ans) - 1; t >= 0; t--) putchar(ans[t]); } }; // namespace mine int main() { srand(time(0)); mine::main(); }
[ "variable_declaration.add", "identifier.change", "control_flow.loop.condition.change" ]
742,638
742,639
u960093366
cpp
p02943
#include <bits/stdc++.h> using namespace std; /* Coded by 秦惜梦 The most charming girl in the world @@@@@@@@@@##&|;!!!!!!!!!!||||||||%%%%%$$$$$$$$$$$$%%$$$&&&&&&&&&$$&&&&&&&&&@@@&%||||||$&&&&@&%;'```'`':!||%&@@@@#@&&&&&@@@&&$$$&&@@&$$$&@@@@@@@@@@@@@#@@@@@@@@@@#@@@@@#@@@@@@@@@@##$ @@@@@@@@@####$!;!!!!!!!!!||||||||%%%%%%%%%%%%%%%$$$$&&&&&&&&&&&&&&&&&&&&@@@@@@&%|||||!:'`'!$&&&&&&%:''!|||$&&&@@@@@@&&&&&@@@&$$$&&@&&$&&@@@@@@@@@@@@@@@@@@@@@@@@##@@@@#@@@@@@@@@@#@% @@@@@@@@@####@|;!!!!!!!!!|||||||%%%%%%%%%%%%%$$$$$$$$$$&&&&&&&&&&&&&&&@@@@@@@@&%|;:'''''``````'!$&&&@@&|:;%$$&&&@@@@@&&&&&@@@&$$$&&@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@@@@@#@@@@#@@@@##@% @@@@@@@@####@@&|;!!!!!!!!|||||||%%%%%%%%%%%%%%$$$$$$$$&&&&&&&&&&&$$$&&@@@@@@@@@@&$|;'''''````````'':!$&&&$%%%%$$&@@@@@&&&&&@@@@&&&@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@@#@@@@#@@% @@@@@@@#####@@@$!;!!!!!!|||||||%%%$$$$$%%%%%%%%%$$$$$$$&&&&&&&&&$$$$&&@@@@@@@@$%$&@@&&&@&$%;:':;:''`````'|%%%%%%$$&@@@@@&&&&@@#@@@@@@#@@@@@@@@@@@@@@@@#@@@@@@@@@#@@@@@@@@@@@@@@#@@@% @@@@@@#####@$%%%$$$%%%||%%||||%%%%$%%$$$$$%%%%%%%$$$$&&&&&&&&&$$$$$$&&@@@@@@@&$;'''''':!%&&&&&&@@&%;'```:$&&%%%%%$$$&@@@@&&&&@@@@@@@@@#@@@@@##@@@@@@@@#@@@@@@@@@@@@@@#@@@@@@@@@#@@@% $&@@@@######&&&&&$%%%%|%|||||||%%%%%$$$$$$$$$$$$$&&&&&&&&&&&&&&&&$$$$&&@@@@@@&$!''''''````````:!|$&&&&&&&$&&&$%%%%$$$&&@@@&&&&&@@@@&@@@@@@@@@#@@@@@@@@#@@@@@&&&@@@@@@@@@@@@@@@#@@@@$ $$$&@######@&&&&&&|!!!!!|||||||%%$$$$$$$$$$$$$$$&&&&&$$&&&&&&&&&&&&$$&&&@@@@@@&%;::''````````'':'``....`;|%$&&&$%%$$$$$&@@@&&&&&@@@@@@@@#@@@@@#@@@@@@@@@@@@@@&&@&&&&&&&&&@@@@@@@@@@$ $$$&@#####@&$$&&@#&|!!!!!|||||||%%%$$$$%%%%%$$$$$$$&&&&&&&&&&&&@@@@@&&&&&&@@@@@@@@@@@&&&&&&&&@@@@&&$$%||||%%%$$&&&$$$$$$$&@@@&&&&&@@@@@@@#@@@@@@@@@@@@@@@@@@@@&&@&&&&&&&&@@@@@@@@@#$ $$&@######@&$&@##@&$|!!!!|||||||%%%%%%%%%%%%%$$$$&&&&&&&&&&&&&&&&&&&&$$&&&&&&@@&|'`````````':::;;;;;;!|%%%%%%%%$&@@&$$$$$$$&@@&&&&&@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@&&&&&&&&&@@@@@@@#@% $&@######@&&&@##@$$$$|!!!||||||||%%%%%%%%%%%%$$$$&&&&&&&&&&&&&&&&&&&&$&&&&&&&&@@$!:::'':::::::::::::''``.:%%$$$$$$&@@@&$$$$$&@@@&&&&@@@@@@@@@@@@#@@@@@@@@@@#@@@@#@@@@@@&&&@@@@@@@@@% $&@######@&&@#@&$$$$&$|!!!||||||||%%%%%%%%%$$$$$&&&&&&&&&&&&&&&&&&&$$$&&&&&&&&&&&%;::::::::::::':''':'':::%&$$$$$$$$&&@@&$$$$$&@@@&&&&@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@@@% &@#######@@@#@&$$$$$&&$|!!|||||||||%%%%%%$$$$$$$$$&&&&&&&&&&&&&&&$$$$$&&&&&&&&&&&$!''::::'''::;!|%%$&&@@@@&&@@$$%%$$$$&&@&&$$$$&@@@&&&&@@@@@@#@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@% ############&$$$$$$$&&&$|!!||||||||%%%%%%$$$$$$$$$$$$$$&&&&&$$$$$$$$$$&&&&&&&&&&&&@@@&&&&&&&@@@@@@&&&$$%|!;%@@@@&$$$$$$$$&@@&$$$$&@@@&&&@@@@@@@@@#@@@@@@#@@#@@@@@@@@@@@@@@@@@@@@@@@$ ########@&$$$$$$$$$&&&&&$|!!||||||%%%%%%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&@@&&&&&&&&&&&&&&$$$$$$$$$$&&&$$%!;:::|$&@@@@&$$$$$$$&@@&$$$&@@@&&&@@@@@@@@##@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@$ ########@$%%%$$$$$$&&&&&&&%!||||%%%$$$%%%%%%%%%%%%%%%%%%%%%%%$$$$$&&&&&&&&&&@@@&&&&&&&&&&&&$$$$$$$$$$$$$&&%!!$$$$&@@@@&$$$$$$&@@@&&&&@@@&&@@@@@@@##@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@@@% #######@&$$$$$$$$$$$$&$|!||%%%%||%%%%%%%%%%%%%%%%%$$$$$$&$$$$$&&&&&&&&@@@@&&&&&&&&&&&&&&&&&&&$$&&$$$$$$$$$&&&$&@&$$$&@@@&$$$$$$&@@@@&&@@@@&@@@@@@###@@@@@@@@@@@@@@@@@@@@@@@@#@@@@#@% #######@$$$$$$%$$$$$$$&&$||||%%%%%%$$$$$$$$$$$$$$$$$$$$$$$&&&&&&&&&&@@&&&&&&&&&&&&$$$$$$&&&&$$$$$$$$$$$$$$$$$$&@@@@&$$$&@@@&$$$$&&&@@@&@@@@&&@@@@@###@@@@#@@@@@#@@@@@@@@@@@#@@@@#@@$ #######&$$$$$$$$$$&$$$$$&&&&&$%||%%%%%%$$$$$$$$$$$$$$$$$&&&&&&&&&&&@&&&&&&&&&&&&$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&@@@&$$$&@@@&$$&&&@@@@@@#@@@@@@@@##@@@@#@@@@@@@@@@@@@#@@@@@@##@##$ ######@$$$$$$$$$$$$$$$$$$&&&&&&$||%%%%%%%$$$$$$$$$$$$$&&&&&&&&&@@&&&&&&&&&&&&&&$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&@@@@@&&$&&@@@&&&&&@@@@@##@@@@@@@##@@@###@@@@@@@@@@@@@@#@@@#@#@@% ######&$$$$$$$$$$$$$$$$$&&&&&&&&$%|%%%%%%%$$$$$$$$$$&&&&&&&&&&@&&@@&&&&&&&&&&$$$$$$$$$$$$$$$$$$$$$$$&$$$$$$$$$$$$$$$$&@@@@@@&&&&&@@@&&&&@@@@@#@@@@@###@@@##@@@@@@@@@@@@@@#@@@####@#$ #####@$$$$$$$$$$$$$$$$$$$&&&&&&&&&%%%%%%%%%$$$$$$$$&&&&&&&&&&&&&&&&&&&&&&&&$$$$$$$$$$$$$$$$$$$$$$$$$$&$$$$$$$$$$$$$$$$$&&&@@@@@&&&&@@@@@@@@@@@@#@@@@###@@@$%%%%%%%%%%%%%$&@@#######$ #####@&$%$$$$$$$$$$$$$$$$$$&&&&&&&&$%%%%%%%%%%$$$$&&&&&&&&&&&&&&&&$$$$$$$$$$$$$$$$$$$$$$$$$$%$$$$$$$$$%%$$$$$$$$%%$$$$$%&@&&&&@@@@@&&@@@@@&&@@@@#@@@@###@&%%%%%%%%%%%%%%%%%&@##@##@% ####@@@@&$$$$$$$$$$$$$$$$$$&&&&&&&&&&%%%%%%%%%%$$&@&&&&$&&&$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$||$$$$$$$$%%$$$$$|%$$$$$$$%%$&@@@&&&@@@@@@@@@@@@&@@@@@@@@##@&%%%%%%%%%%%%%%%%%%%$@@@@@% ####@@@@@@&$%$$$$$$$$$$$$$$$$$&&&&&&&&$%%%%%%%$&&&&&$$$$$$&$$$$$$$$$$$$$$$$$$$$$$$%%$$$%%%%|!|||$$$$%!|%%%$$&$$$$$$$$$$%%%$&@#@@@@&&@@@@@@@@@@@@@@##@@@@#@@@&$$%%%%%%%%|%%%%%|$@@@@$ ###@@@@@@@@$$$%$$$$$$$$$$$$$&&&&&&&&&&&&%%%%%&&&&&$%%%$$&&&$$$$$$$$$%%%$$|%$$$%%%$%%|%%!;!||!!||%$$$$$$$%%$&$$&&$$$$$$$$$$%%$@@#@@@@@@&&@@@@@@@@#@@###@@@########@@$%%%%%%%|%%$&@##$ ##@@@@@@@@@&$$$&$$$$$$$$$$$$$$$&&&&&&&&&&&%%%$&%|%%%%%$%%$$%%%%%%$$$%%%$$||%%%$$$$$%%%%%$$$$$%!!|%&&$$$$%|$$$$$$&$$$$$$$$$$$%$$&@@@@@@@@@@@@@@@##@@@@##@@####@@#######&%%%%%%%$@###$ #@@@@@@@@@@&&$$&$$$$$$$$$$$$$$$&&&&&&$||%%%$$%!;!;!|%%%%$%!||||%%%$$$||%$%%%%%%$$$$%$$%%%%$%$$$$||$&&$$&%|%$$$$$$$&$%%$%|%$$$$%$%$@@@@@@##@@@@@@@@@@########@##@@@######&$$&@@@@@##$ @$$&@@@@@@@&&$$$$$$$$$$$$$$$$$$&&&$&&&&$$&$$%!|%%%%%%%%%%||%%%%%%%%$$||%$$$$%%%%$$$%%$$%%%%%%%$$%|%&&$$&$%%$$$$$$$&&$%%&&&&$$$$$$$||$@@@@@@@@@@@@@@@@@@@####@@@@##@@@#@@@@@@@@@@@@@% &$%%$$&&&$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&&&&|!|%%%%|%%%%%%$%%%%||||%$$%|%$&&$%%%%$$$$%$$%%%%$$$$$%|$&&&$&$$$&$&$$$$&&&$%$&&&$$&&&&&$%!!|$&@@@@@@@@@@@@@@@@###@@@@@@@@@@@@@@@@@@@@@@@% $$%$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&$&&&&&&$|!|||%%|%%%%%%$$%%%%||||%$$%%%$&&$%%%$$&&&$$$$$$$$$$$$$%%&&&&&$$&&$&$$&&&&&&&&&&&&&&&&&&&&$|!!!!$&@@@@@@@@@@@#####@######@##@@&@@@@@@@@@@$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&&$|!|||%$%%%%%%%$$$$%%%||||%$$%%%$&&$$%%$&&&&&$$$$$$$$$$$$%%&&&&&$$&&$&$$&&&&&&&&&&&&&&&&&&&&&&%!!!!|&&&@@@@@@#########@########@@##########$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&$&$%|!||%$$%%$%%%%$$$$$%%|||||$$$&$$&$$$%$&&&&&&$$$$$%$$$$$$%$&&&&&&&&&&&$$&&&&&&&&&&&&&&@@&&&&&@@$|!$@&||||%&@#@@####@########@@@@@@@#@&&@@##$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&$$&$%|!||%$$%%%%%%%$$$%$$%%||||%$&&&&&&$$$$$$&&&&&$%$$$%%$$$$$%$&&&&&&&&$$$$$&&&&&&&&&&&&&&@@@&&@@@@@&@@&|||||||||%&@###############@@@@@@##@@@@% %$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&$&&$$$$%!!|%$$$%%%%%%$$$$%$$$%||||$&&$$&&$$$$$$$&&&$&$%%$%%%%%%$$%$$$&&&&&$$$$$$&&&&&&$&&&&&&&&&&&&&&&@@@@&||||||||||||$@#####@@@########@@@@@###@@$ %%%%%%%%$$$$$$$$$$$$$$$$$$$$$$$$$&&%%&%!!||%$$%%$$%%$$$$%%$$%%|!|%&&$%%&&$%%%%$$$&$|%$||$%%%%%%$$$$$$&&&&$$$$$$&&&&&&$$$&&&&&&&&&&@@&&&@@@&&%|||||||||%&@@##@$$@@@@########@@@@@@##$ ;:''':;!|%%$$$$$$$$$$$$$$&&&&&&&&%%&&$!!|%%%%%%%$$$$$$$%%%$%%%|||$$&%!%&$%%%%|%%%&%!|$||%%%%%%%$$$$%%$&&$$$$$$$&&&&&&$$$$&&&&&&&&&&&&&&@@@@&&%|||||||%@@@@#@%|&#$||||%&@@@@@@@@@@@@$ ..... .`;|%%$$$$$$$$$$$&&&&&&$%%$&&$!;|%%|||%%$$&&&&$$%%$$%%%%%%%&%!;|$$%||||%%%$|;!%||$%$$$$$%%%%||$&$%%%$$$$&&&&&&$$$$&&&&&&&&&&&&&@@@@@@&&%|||||$@@@##&%|%@@%||||||||||&@@@@@@@% ........ `;|%$$$&&&&&&&&&&&$%$&&&&$|!|%%|!!|||$&$&&&$$%%%%%||||%$$|;;|%%|||||%$&&$|!|!!%%%%%%|!!|%!%$$%||%$&$&&&&&&&$$$$&&&&&&&&&&&&@@@@@@@@&&%|||$@@@##@$||$#&|||||||||||&#$|||||! ... .. `;|%$$$$&&&&&&$%$$&&&&&&||%%$||!!||$&$$$$$$%%%%%%||||%$%!:!!!%%$$$%%%%|!;;;;;!!!!!;;;||!%&%|%%%$&&$&&&&&&&$$$$&&&&&&&&&&&@@@@@@@@@&&$||$@##@@@%||%&@$||||||||||%&@$|||||! .. .'!|%$$&&&&&&&&&&&&&&&&||$$&%||!||%&&$$$$$$%%$%||||||%|!;:;;;|%|!!!!!|!|$$&&&&$$$%!!!!;|&&$%%%$&$$$$%||&@&$$$$&&&&&&&&&@@@@@@@@@@@@&$|%@@@@#@%|||$@&%||||||||||%@@%|||||! ... .';|%$$&&&&&&&&&&&&&&&%%&$&&%|||||%&&$$$$$$%%$%%%||||%!;:::::::'':;!|%%%%$&@&&$%|!|%|;!$&$%|%%$$$$&$|!|$@@&$$$&@@@@@@@@@@@@@@@@@@@@&$$@@@#@&%|||%&#$|||||||||||$@&%|||||! .... .:!|%$$&&&&&&&&&&&&&&$$&&&&$|||||%$@&$$&$$&&&$%|%%%%|;::''''''````'!!!;'`'%@&%|!::!;;!$$||%%%$&$$$$|!!|%&@@&&&&@@@@@@@@@@@@@@@@@@@@&&@@@@#@%||||$@@$|||||||||||$#&||||||! .. .';!|%$$$&&&&&&&&&&&&$$&&&&&$$%||%%&@&$$&$$$$%|!;;;;:::'`````````````````';;:;!;'::::;%$|||!!|$$$%$%||||$@@@&&&@@@@@@@@@@@@@@@@@&&@&&&&&&@@@$%%||&#&%||||||||||%&#$||||||! .`:!!!|$$&&&&&&&&&&&&&&&&&&&&&&&$%$$$&@&&$&&$$|!|%$$$$%|;''``````````````':;!!!;::''':;!$%|$$%%$$$$$$%!!%&@@@@@@@@@@@@@@@@@@@@@@@@&&&&@&$$&@@@@@@@@@#&%||||||||||%@@$||||||! ;:''`'':;!!!!|%$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&$&&&&&$|!%%%%$&$$|;'``````````````''''''''::::;|$&$$$%%$$%%$$$&@@@@@@@@@@@@@@@@@@@@@@@@@@@&&&@&$$$&&&@@@@@@@@@@@@@@&$%|||$@@$||||||! |!;;;!!!!!!|%$$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%!:;|!||!!:'''``````````````''''''''':;;|$$$$$%%$%$$$&&&&&@@@@@@@@@@@@@@@@@@@@@@@@&&&@&$$$&&&&&@@@@@##@@@@@&&@@@@@@#@&%|||||! %|!!!!!!||%$$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&@@&&&&&&$$$!';;;:'```''`````````````````'''''';;:|$$$$$$$$%$$$&@&&&&@@@#@@@@@@@@@@@@@@@@@@@&&@&$$$$$$$&&&@@@@##@%;''|&@@@@@@@#@@@@@@@% &$%%%%%%$$$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&@&&&@&&&$$$%;``'''``':'``````````````````'''':::;|$$$$$$$%$$$$&&&&&&@@@##@@@@@@@@@@@@@@@@@@&@&$$$&&&$$$&&&@@@@|:''':%@@@@@@@#@@@@@@@@% @@&$$$$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&@&&@@&&&$$$$%:``````';:'```...`````````````'''':;|$$$$$$%%$$$$&&&&&&&@@##@@#######@@#@@@@@@#@&$$&&&&&$%$$&&@@%:'::'!&@@@@&@@@@@@@@@@@% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&@@&&&&&&&$$%:``````':;:```..``````````````''':;|$$$$$$%%$$$&&&&&&&@@@####################@&$$&&$$$$$$$|;|&$!''':;$&&&&&&@@@@@@@@@@@% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&$&@&$&&&$&&&&&%'``````.``````....```````````'`'';|$&$$$%$$$$$$&&&&&@@@@@##################@$$$&&$$$$$|:':;%&$;''''|&&&&&&&&@@@@@@@@@@% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&$%$&@@$$$$$&&&&&@@!````````.......````````````''`'':!%$&&&$$&&&&&&&&&&@@@#@@##############@@&$$$$&$$$$$$|:''|&&|''''!$&&&&&&@@@@@@@@@@@@% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|;%&$&@$$$$$$&&&&&@@&;..``..........````````````''``'';%$&&&&&&&&&&&&&&@@@@@##@############@@@$$$$&$!|$$$$!:':%@%:``':%&&@@@@@@@@@@@@@@@@@% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&$!!$&&$&&$|!|%$$$&&&@@@@$:.........``'''``':;:'`````````':!%$&&&&&&&@&&&&&@@@@@@@#@@#########@@@&$$$%!!$$$$$%;'';$&!``':%@@@@@@@@@@@@@@@@@@@&% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|;%&&&&$%%$%!|%%$$$$&&@@@@@$;`.....`...````````````````````';|$&&&&&&&&@@@&&&@###@@@@#@&&##@@@@@&$$$$&&$$$$$$|'```!&%;|&&&&&@@@@@@@@@@@@@@@&&&&% ###&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%:|&&&&&$$||$&$|%%%$$&&&@@@@@@@@$;`........``'::'`...```'``````:|$$$&@@&$&@@@@@@&@#@@####@#&&#@$|%&$$%%&&$$$$%!'`.`:!$@@&&&&@@@@@@@@@@@@@@&&&&&&&&% ###@&&&&&&&&&&&&&&&&&&&&&&&&&&|:!&&&&&&$$%||$&&$%%%$$&&&&@@@@@@@@@@&%:`.................`'````:!;;|$$$&&@@&&&&@@@@&&@########@!':|&$$%%$|;:;;!|%%%%||$@@&&&&&&&@&&&&&&&&&&&&&&&&&&&% ###@&&&&&&&&&&&&&&&&&&&&&&$!:|&&&&&&&&$$%|%$&&&$%%%$&&&&&@@@@@@@@@@@@&&$;`..............``'';|!;;;;|%$$$$&@@@&&&@@&&$$&&@@@@##@&%||%%%$!:|%%%%%||%!|$@@@&&&&&&&&$$$$$$&&&&&&&&&&&&&% ###@&&&&&&&&&&&&&&&&&&&|:!$&&&&&&&&&&$%%%%$$&&&$%%$$$$&&@#@@@@@@@@@@@&&&&&&|'...........``:!!;;;;;!!;|$&$%|&@@@&&&&&$!|$$$&@@#@@&%%%%$|'':!%%%%|!|$&&@@&&&&&&&$%%%%$$$$$&&$$$$$$&&&% ###@&&&&&&&&&&&&&&&|:;%&&&&&&&&&&&&$$%%%%$$&&&&$$$$$$$$&@#@@@@@@@@@&&&&&&&&&&&&|'.....`;%%!!!!;;;!!!!;!%$$&$|%@@@@@&&@$;:::!|%$&$%%%$%:'``';!!|||%$&@@@&&&&&&$%%%%%%%$$$$$%%%%$$$$$| ###@&&&&&&&&&$|:;%&&&&&&&&&&&&&&&$$%%$%%$&&&&&&$$$$%$$$&@@@@@@@@@##@&&&&&&&&&&&&&&%|%&&&&&$|;;;;;;;;;;;;!$&$&$|!%&@@@@@@&%;::!$$$$$$%;:```````;||||%$&&$$$$$$%|%%%%%%%$$$%%%%%%%%$%| ###@&&$%|||$&&&&&&&&&&&&&&&&&&$$$$%%$$%$&&&&&&&$$$%%$$&&@@@@@@@@@@@##@&&&&&&&&&&&&&&&&&&&&@%;;;;;;;::;;;;!!$&&$$%!;|$$$&&&$&&&$$$$$%!|$&%:...`.`;|!|||!;!|||||||%%%%%%$%%%||||%%%%%| &&@@&&&&&&&&&&&&&&&&&&&&&&&$$$$$$%%$$%$&&&&&&&&$%%%%$$&&@@@@@@@@@@@@#@&@@&&&&&&&&&&&&&@###&%;;;;;;::::;;;!!!!|$$$&&%!:;!$&&&@&$$$&@&&&$%$&|``..'%#@@&$%%||||!;:'`';|%%$%%||||||||||| ###@&&&&&&&&&&&&&&&&&&&&$$$$$$$$%%$&&$$&&&&&&&&$%%%%$$&&&@@@@@@@@@@@@@@&&&&@@@@@&&@####$;':!!;;;::::;;;;!;!;::::;%&&&&&$$$&@&$$$@@$$$$$&@@@@$%@#@@##@@&%%||||||||%%%|!'`:!|||||||||| ###@&&&&&&&&&&&&&&&&&$$$$$$$$$$$$$$$%%$$$$&&&&@$%%%%$$&&&&&@@@@@@@@@&&&&@@&&&&&&&@@@@|:':;;!!;;:::::::;;!!;:::::::::':::';$$$$$&&$&&&@@@&&@@@@@#######@@##@&%||||||||%%%%|!''!|||||! ###@&&&&&&&&&&&&&&$$$$$$$$$$$&&$$$$$%%$$$$$&&&&&$%%$$$&&&&&$&&&@@@@&&&&&&&&&&&&@@@%:''':;;;;;:::::::::;;;:::::::::::::;;!%$$$$$|:::|$&&$&@@@@@&$&@#####@@@@####@&$%||%%%||||||;:!||! ###@&&&&&&&&&&&$$$$$$$$$$$&&&&&$$&&$%%$$$&&&&&&&&$%$$$$$&&&&&&&@@@#@&&&&&&&&@##$;''''':;;;;;:::::::::;!;:::::::::::::::;%&$$$$|''':;%&%!;:'''':|%$&@@@@#@@&&&@##@&&@@$|%%|||||||!:;| :;$@@&&&&&&&$$$$$$$$$$$&&&&&&&&&$$&&$$&&&&&&&&&&&$%%$$$&&&&&&&&&&&&@@#######@|:'''''';!!!;::::::;;!!!!;::::::::::::::::|$$$$$!'::;!!%&|;;''''''''''';$&@@#@&&$$&@&&@#@@@#####@$%||;: ''''':|$&$$$$$$$$$$&&&&&&&&&&&&&&$$&$$&&&&&&&&&&&&&$$$$$&&$$&&&&&@@@@@&$%$%|:''''''':;:::::::::::::;;:::::::::::::::::|$$$$$!::;;;;|&%;;:''''''''''''':!$&@@@&$$$$&################$ '''''''''';%$$&&&&&&&&&&&&&&&&&&&&$$$$&&&&&&&&&&&&&&$$$$$&@@@@@###@&&$%;''''''''':::;;:::::::::::;;:::'':::::::::::':|$$$$$!::;:::|&%;;:''''''''''''''```:%&@@&&&$$$&##############$ '''''''''''':':|&&&&&&&&&&&&&&&&&&&&$%$&&&&&&&&&&&&&&$$$$$&@@&@@@&$$%%!:''''''::::::!;::::::::::;;::::::::::::::''':|$$$$$|;;:::;%&|::'''''''''''''`.....``;$@@&&&&$$$&@###########$ ;:'''''''''''''':::!$&&&&&&&&&&&&&&&&&%|$&&&&&&&&&&&&&&$$$$&$$$$$$|:!|;':::::::::::;!;::::::::;;:::::::::::::''''':|$$$$$|;::::|&&|::'''''''''''``........`''!&@@&&&&$$$&@#########$ .';;;;;:'''''''''''':::;%&@&&&&&&&&&&&&%$&&$$$$&&&&&&$&@&&&$$$$%!:::!|;::::::::::::!!;::::::!;::::::::::::::''''':|&$$$$|;::::|&%;;:'``''''''''````......````'!$@@&&&&&$$$&@#######$ ;;;:`.`:;;;;::'''''''''''':;%@@@&&&&&&&&$$$&&&&&&&&&&@@&!::':'':::::||;::::::::::::!!;:::;!!;;:::::::::::::::''':%&$$$$|;:::;%&|:::'`````````'''```..`...````''!$@@&&&&&&&$$&@#####$ ;;;;;;;;;'..';;;;::''''''''''':|@@@@&&&&&&$%$&&&&&&&@@%:::::::::::::!|;:::::''''''';!;:;!!;:::::::::::::::::''':%&$$$%|;:::|&%;;:'''```````'''''``... ```''!&@&&&&&&&&&&&&@###$ :::;;;;;;;;!;;;'':;;;;:'''''''''':!&@@@&&&&&$$&&&&@@@$;::::::::::::';|:``````````'';!;;;:'''```````````````''''|$$$$%|;::|&$!;;:'````````''::''``.... .``'':%@&&&&&&&&&&&&&&@#$ ::::::::;;;;;;;;;;;;:'':;;:''''''''':;%@@@@&&&&$&@@@$;''''''':''`''`:|;````````````:!!:'''``.........``......`!$%%%%|;;|&$!:;'`````````'''::''. .. `''``''!$&&@@&&&&&&&&&&&&% ###@%!:::::::;;;;;;;;;;;;;;;;::'''''::::|&@@@&&&&&&%'```.....````''`'||'``````````';;'''``................. .!$%%%%|!%&$!:;:'``'''````'::::''. ....``''``'''|@&&&@&&&@&&&&&&$| ####@&&&@&|;::::::;;;;;;;;;;;;;;;:'''''''::!&@@@@@%:````......```'```;%;`````````''''``................. .!$%%%%%$&%;:::''```'''```'::::'`. ...``'```''';$@&&&@@&&&&&&&&&% ####@&&&&&&&&&$!:::::::;;;;;;;;;;;;;:''''''':|@@@$;````.......``''```'!%;``````''''``....... .... .;%%%%%%$%;::'''`````''''`'::::`. ...`````'''|@&&&&@@&&&&&&&&% ####@&&&&&&&&&&&&&&|;::::::;;;;;;;;;;;;:::'':;;%&;````.........``'````:||:```':''`...... .`:|%%%%%|;::''''``````'''''::::`. ....```'''!$@&&&&@@&&&&&&&% ####@&&&&&&&&&&&&&&&&&&|::::::::;;;;;;;;;:::::;;'````..........``'`````:||:':''`...... .`'!$%%%%|;:''```````````'''''::;'. ......``':%@@&&&&&@&&&&&&% ####@&&&&&&&&&&&&&&&&&&&&&$!:::::::;;;;;;;;;;;;'`````..........`''``````:||:''`. . .``!$&$%%%%%;'''`````````````'':::;;` .....```'!&@&&&&&&@&&&&&% ####@&&&&&&&&&&&&&&&&&&&&&&&&&|;:::::;;;;;;;;;:``````...........''````':':|%!'. .``'|$&|;|%|%%%!''````...`````````':::;;` .....```'|@&&&&&&&@&&&&% ####@&&&&&&&&&&&&&&&&&&&&&&&&&&&$!::::::;;;;;:``````....``......''``':'''':!|%;.. ..``:|%$|;::;|%||%%!'`````......```''`'':::;:' ....... ....````:%@&&&&&&@@&&&% ####@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%;:::::;;:```````....`. ...`'':''`. .':!||;````````';|%%|;::::';|%||%%;'```.........```'''''::::;'. ....````........ ......````:%@&&&&&&@@&&% ####@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|:::::'```````...``. ..'::'``. .```':;!||!;;!||!;::::''``';|%||%|;'```..........```'''''::::;:.....``````````...........`````;&&&&&&&@@@&% */ string s; int n, m; int main() { cin >> n >> m; cin >> s; while (m--) { string t = s; reverse(t.begin(), t.end()); string ss = s + t; string ff = "\xff"; for (int i = 0; i + n <= ss.size(); i++) { ff = min(ff, ss.substr(i, n)); } if (!m) { cout << ff << endl; return 0; } reverse(ff.begin(), ff.end()); bool xx = 1; for (int i = 1; i < n; i++) { if (ff[xx] != ff[xx - 1]) { xx = 0; break; } } if (xx) { cout << ff << endl; return 0; } s = ff; } cout << s << endl; return 0; }
#include <bits/stdc++.h> using namespace std; /* Coded by 秦惜梦 The most charming girl in the world @@@@@@@@@@##&|;!!!!!!!!!!||||||||%%%%%$$$$$$$$$$$$%%$$$&&&&&&&&&$$&&&&&&&&&@@@&%||||||$&&&&@&%;'```'`':!||%&@@@@#@&&&&&@@@&&$$$&&@@&$$$&@@@@@@@@@@@@@#@@@@@@@@@@#@@@@@#@@@@@@@@@@##$ @@@@@@@@@####$!;!!!!!!!!!||||||||%%%%%%%%%%%%%%%$$$$&&&&&&&&&&&&&&&&&&&&@@@@@@&%|||||!:'`'!$&&&&&&%:''!|||$&&&@@@@@@&&&&&@@@&$$$&&@&&$&&@@@@@@@@@@@@@@@@@@@@@@@@##@@@@#@@@@@@@@@@#@% @@@@@@@@@####@|;!!!!!!!!!|||||||%%%%%%%%%%%%%$$$$$$$$$$&&&&&&&&&&&&&&&@@@@@@@@&%|;:'''''``````'!$&&&@@&|:;%$$&&&@@@@@&&&&&@@@&$$$&&@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@@@@@#@@@@#@@@@##@% @@@@@@@@####@@&|;!!!!!!!!|||||||%%%%%%%%%%%%%%$$$$$$$$&&&&&&&&&&&$$$&&@@@@@@@@@@&$|;'''''````````'':!$&&&$%%%%$$&@@@@@&&&&&@@@@&&&@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@@#@@@@#@@% @@@@@@@#####@@@$!;!!!!!!|||||||%%%$$$$$%%%%%%%%%$$$$$$$&&&&&&&&&$$$$&&@@@@@@@@$%$&@@&&&@&$%;:':;:''`````'|%%%%%%$$&@@@@@&&&&@@#@@@@@@#@@@@@@@@@@@@@@@@#@@@@@@@@@#@@@@@@@@@@@@@@#@@@% @@@@@@#####@$%%%$$$%%%||%%||||%%%%$%%$$$$$%%%%%%%$$$$&&&&&&&&&$$$$$$&&@@@@@@@&$;'''''':!%&&&&&&@@&%;'```:$&&%%%%%$$$&@@@@&&&&@@@@@@@@@#@@@@@##@@@@@@@@#@@@@@@@@@@@@@@#@@@@@@@@@#@@@% $&@@@@######&&&&&$%%%%|%|||||||%%%%%$$$$$$$$$$$$$&&&&&&&&&&&&&&&&$$$$&&@@@@@@&$!''''''````````:!|$&&&&&&&$&&&$%%%%$$$&&@@@&&&&&@@@@&@@@@@@@@@#@@@@@@@@#@@@@@&&&@@@@@@@@@@@@@@@#@@@@$ $$$&@######@&&&&&&|!!!!!|||||||%%$$$$$$$$$$$$$$$&&&&&$$&&&&&&&&&&&&$$&&&@@@@@@&%;::''````````'':'``....`;|%$&&&$%%$$$$$&@@@&&&&&@@@@@@@@#@@@@@#@@@@@@@@@@@@@@&&@&&&&&&&&&@@@@@@@@@@$ $$$&@#####@&$$&&@#&|!!!!!|||||||%%%$$$$%%%%%$$$$$$$&&&&&&&&&&&&@@@@@&&&&&&@@@@@@@@@@@&&&&&&&&@@@@&&$$%||||%%%$$&&&$$$$$$$&@@@&&&&&@@@@@@@#@@@@@@@@@@@@@@@@@@@@&&@&&&&&&&&@@@@@@@@@#$ $$&@######@&$&@##@&$|!!!!|||||||%%%%%%%%%%%%%$$$$&&&&&&&&&&&&&&&&&&&&$$&&&&&&@@&|'`````````':::;;;;;;!|%%%%%%%%$&@@&$$$$$$$&@@&&&&&@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@&&&&&&&&&@@@@@@@#@% $&@######@&&&@##@$$$$|!!!||||||||%%%%%%%%%%%%$$$$&&&&&&&&&&&&&&&&&&&&$&&&&&&&&@@$!:::'':::::::::::::''``.:%%$$$$$$&@@@&$$$$$&@@@&&&&@@@@@@@@@@@@#@@@@@@@@@@#@@@@#@@@@@@&&&@@@@@@@@@% $&@######@&&@#@&$$$$&$|!!!||||||||%%%%%%%%%$$$$$&&&&&&&&&&&&&&&&&&&$$$&&&&&&&&&&&%;::::::::::::':''':'':::%&$$$$$$$$&&@@&$$$$$&@@@&&&&@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@@@% &@#######@@@#@&$$$$$&&$|!!|||||||||%%%%%%$$$$$$$$$&&&&&&&&&&&&&&&$$$$$&&&&&&&&&&&$!''::::'''::;!|%%$&&@@@@&&@@$$%%$$$$&&@&&$$$$&@@@&&&&@@@@@@#@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@% ############&$$$$$$$&&&$|!!||||||||%%%%%%$$$$$$$$$$$$$$&&&&&$$$$$$$$$$&&&&&&&&&&&&@@@&&&&&&&@@@@@@&&&$$%|!;%@@@@&$$$$$$$$&@@&$$$$&@@@&&&@@@@@@@@@#@@@@@@#@@#@@@@@@@@@@@@@@@@@@@@@@@$ ########@&$$$$$$$$$&&&&&$|!!||||||%%%%%%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&@@&&&&&&&&&&&&&&$$$$$$$$$$&&&$$%!;:::|$&@@@@&$$$$$$$&@@&$$$&@@@&&&@@@@@@@@##@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@$ ########@$%%%$$$$$$&&&&&&&%!||||%%%$$$%%%%%%%%%%%%%%%%%%%%%%%$$$$$&&&&&&&&&&@@@&&&&&&&&&&&&$$$$$$$$$$$$$&&%!!$$$$&@@@@&$$$$$$&@@@&&&&@@@&&@@@@@@@##@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@@@% #######@&$$$$$$$$$$$$&$|!||%%%%||%%%%%%%%%%%%%%%%%$$$$$$&$$$$$&&&&&&&&@@@@&&&&&&&&&&&&&&&&&&&$$&&$$$$$$$$$&&&$&@&$$$&@@@&$$$$$$&@@@@&&@@@@&@@@@@@###@@@@@@@@@@@@@@@@@@@@@@@@#@@@@#@% #######@$$$$$$%$$$$$$$&&$||||%%%%%%$$$$$$$$$$$$$$$$$$$$$$$&&&&&&&&&&@@&&&&&&&&&&&&$$$$$$&&&&$$$$$$$$$$$$$$$$$$&@@@@&$$$&@@@&$$$$&&&@@@&@@@@&&@@@@@###@@@@#@@@@@#@@@@@@@@@@@#@@@@#@@$ #######&$$$$$$$$$$&$$$$$&&&&&$%||%%%%%%$$$$$$$$$$$$$$$$$&&&&&&&&&&&@&&&&&&&&&&&&$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&@@@&$$$&@@@&$$&&&@@@@@@#@@@@@@@@##@@@@#@@@@@@@@@@@@@#@@@@@@##@##$ ######@$$$$$$$$$$$$$$$$$$&&&&&&$||%%%%%%%$$$$$$$$$$$$$&&&&&&&&&@@&&&&&&&&&&&&&&$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&@@@@@&&$&&@@@&&&&&@@@@@##@@@@@@@##@@@###@@@@@@@@@@@@@@#@@@#@#@@% ######&$$$$$$$$$$$$$$$$$&&&&&&&&$%|%%%%%%%$$$$$$$$$$&&&&&&&&&&@&&@@&&&&&&&&&&$$$$$$$$$$$$$$$$$$$$$$$&$$$$$$$$$$$$$$$$&@@@@@@&&&&&@@@&&&&@@@@@#@@@@@###@@@##@@@@@@@@@@@@@@#@@@####@#$ #####@$$$$$$$$$$$$$$$$$$$&&&&&&&&&%%%%%%%%%$$$$$$$$&&&&&&&&&&&&&&&&&&&&&&&&$$$$$$$$$$$$$$$$$$$$$$$$$$&$$$$$$$$$$$$$$$$$&&&@@@@@&&&&@@@@@@@@@@@@#@@@@###@@@$%%%%%%%%%%%%%$&@@#######$ #####@&$%$$$$$$$$$$$$$$$$$$&&&&&&&&$%%%%%%%%%%$$$$&&&&&&&&&&&&&&&&$$$$$$$$$$$$$$$$$$$$$$$$$$%$$$$$$$$$%%$$$$$$$$%%$$$$$%&@&&&&@@@@@&&@@@@@&&@@@@#@@@@###@&%%%%%%%%%%%%%%%%%&@##@##@% ####@@@@&$$$$$$$$$$$$$$$$$$&&&&&&&&&&%%%%%%%%%%$$&@&&&&$&&&$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$||$$$$$$$$%%$$$$$|%$$$$$$$%%$&@@@&&&@@@@@@@@@@@@&@@@@@@@@##@&%%%%%%%%%%%%%%%%%%%$@@@@@% ####@@@@@@&$%$$$$$$$$$$$$$$$$$&&&&&&&&$%%%%%%%$&&&&&$$$$$$&$$$$$$$$$$$$$$$$$$$$$$$%%$$$%%%%|!|||$$$$%!|%%%$$&$$$$$$$$$$%%%$&@#@@@@&&@@@@@@@@@@@@@@##@@@@#@@@&$$%%%%%%%%|%%%%%|$@@@@$ ###@@@@@@@@$$$%$$$$$$$$$$$$$&&&&&&&&&&&&%%%%%&&&&&$%%%$$&&&$$$$$$$$$%%%$$|%$$$%%%$%%|%%!;!||!!||%$$$$$$$%%$&$$&&$$$$$$$$$$%%$@@#@@@@@@&&@@@@@@@@#@@###@@@########@@$%%%%%%%|%%$&@##$ ##@@@@@@@@@&$$$&$$$$$$$$$$$$$$$&&&&&&&&&&&%%%$&%|%%%%%$%%$$%%%%%%$$$%%%$$||%%%$$$$$%%%%%$$$$$%!!|%&&$$$$%|$$$$$$&$$$$$$$$$$$%$$&@@@@@@@@@@@@@@@##@@@@##@@####@@#######&%%%%%%%$@###$ #@@@@@@@@@@&&$$&$$$$$$$$$$$$$$$&&&&&&$||%%%$$%!;!;!|%%%%$%!||||%%%$$$||%$%%%%%%$$$$%$$%%%%$%$$$$||$&&$$&%|%$$$$$$$&$%%$%|%$$$$%$%$@@@@@@##@@@@@@@@@@########@##@@@######&$$&@@@@@##$ @$$&@@@@@@@&&$$$$$$$$$$$$$$$$$$&&&$&&&&$$&$$%!|%%%%%%%%%%||%%%%%%%%$$||%$$$$%%%%$$$%%$$%%%%%%%$$%|%&&$$&$%%$$$$$$$&&$%%&&&&$$$$$$$||$@@@@@@@@@@@@@@@@@@@####@@@@##@@@#@@@@@@@@@@@@@% &$%%$$&&&$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&&&&|!|%%%%|%%%%%%$%%%%||||%$$%|%$&&$%%%%$$$$%$$%%%%$$$$$%|$&&&$&$$$&$&$$$$&&&$%$&&&$$&&&&&$%!!|$&@@@@@@@@@@@@@@@@###@@@@@@@@@@@@@@@@@@@@@@@% $$%$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&$&&&&&&$|!|||%%|%%%%%%$$%%%%||||%$$%%%$&&$%%%$$&&&$$$$$$$$$$$$$%%&&&&&$$&&$&$$&&&&&&&&&&&&&&&&&&&&$|!!!!$&@@@@@@@@@@@#####@######@##@@&@@@@@@@@@@$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&&$|!|||%$%%%%%%%$$$$%%%||||%$$%%%$&&$$%%$&&&&&$$$$$$$$$$$$%%&&&&&$$&&$&$$&&&&&&&&&&&&&&&&&&&&&&%!!!!|&&&@@@@@@#########@########@@##########$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&&&$&$%|!||%$$%%$%%%%$$$$$%%|||||$$$&$$&$$$%$&&&&&&$$$$$%$$$$$$%$&&&&&&&&&&&$$&&&&&&&&&&&&&&@@&&&&&@@$|!$@&||||%&@#@@####@########@@@@@@@#@&&@@##$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&&&$$&$%|!||%$$%%%%%%%$$$%$$%%||||%$&&&&&&$$$$$$&&&&&$%$$$%%$$$$$%$&&&&&&&&$$$$$&&&&&&&&&&&&&&@@@&&@@@@@&@@&|||||||||%&@###############@@@@@@##@@@@% %$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&$&&$$$$%!!|%$$$%%%%%%$$$$%$$$%||||$&&$$&&$$$$$$$&&&$&$%%$%%%%%%$$%$$$&&&&&$$$$$$&&&&&&$&&&&&&&&&&&&&&&@@@@&||||||||||||$@#####@@@########@@@@@###@@$ %%%%%%%%$$$$$$$$$$$$$$$$$$$$$$$$$&&%%&%!!||%$$%%$$%%$$$$%%$$%%|!|%&&$%%&&$%%%%$$$&$|%$||$%%%%%%$$$$$$&&&&$$$$$$&&&&&&$$$&&&&&&&&&&@@&&&@@@&&%|||||||||%&@@##@$$@@@@########@@@@@@##$ ;:''':;!|%%$$$$$$$$$$$$$$&&&&&&&&%%&&$!!|%%%%%%%$$$$$$$%%%$%%%|||$$&%!%&$%%%%|%%%&%!|$||%%%%%%%$$$$%%$&&$$$$$$$&&&&&&$$$$&&&&&&&&&&&&&&@@@@&&%|||||||%@@@@#@%|&#$||||%&@@@@@@@@@@@@$ ..... .`;|%%$$$$$$$$$$$&&&&&&$%%$&&$!;|%%|||%%$$&&&&$$%%$$%%%%%%%&%!;|$$%||||%%%$|;!%||$%$$$$$%%%%||$&$%%%$$$$&&&&&&$$$$&&&&&&&&&&&&&@@@@@@&&%|||||$@@@##&%|%@@%||||||||||&@@@@@@@% ........ `;|%$$$&&&&&&&&&&&$%$&&&&$|!|%%|!!|||$&$&&&$$%%%%%||||%$$|;;|%%|||||%$&&$|!|!!%%%%%%|!!|%!%$$%||%$&$&&&&&&&$$$$&&&&&&&&&&&&@@@@@@@@&&%|||$@@@##@$||$#&|||||||||||&#$|||||! ... .. `;|%$$$$&&&&&&$%$$&&&&&&||%%$||!!||$&$$$$$$%%%%%%||||%$%!:!!!%%$$$%%%%|!;;;;;!!!!!;;;||!%&%|%%%$&&$&&&&&&&$$$$&&&&&&&&&&&@@@@@@@@@&&$||$@##@@@%||%&@$||||||||||%&@$|||||! .. .'!|%$$&&&&&&&&&&&&&&&&||$$&%||!||%&&$$$$$$%%$%||||||%|!;:;;;|%|!!!!!|!|$$&&&&$$$%!!!!;|&&$%%%$&$$$$%||&@&$$$$&&&&&&&&&@@@@@@@@@@@@&$|%@@@@#@%|||$@&%||||||||||%@@%|||||! ... .';|%$$&&&&&&&&&&&&&&&%%&$&&%|||||%&&$$$$$$%%$%%%||||%!;:::::::'':;!|%%%%$&@&&$%|!|%|;!$&$%|%%$$$$&$|!|$@@&$$$&@@@@@@@@@@@@@@@@@@@@&$$@@@#@&%|||%&#$|||||||||||$@&%|||||! .... .:!|%$$&&&&&&&&&&&&&&$$&&&&$|||||%$@&$$&$$&&&$%|%%%%|;::''''''````'!!!;'`'%@&%|!::!;;!$$||%%%$&$$$$|!!|%&@@&&&&@@@@@@@@@@@@@@@@@@@@&&@@@@#@%||||$@@$|||||||||||$#&||||||! .. .';!|%$$$&&&&&&&&&&&&$$&&&&&$$%||%%&@&$$&$$$$%|!;;;;:::'`````````````````';;:;!;'::::;%$|||!!|$$$%$%||||$@@@&&&@@@@@@@@@@@@@@@@@&&@&&&&&&@@@$%%||&#&%||||||||||%&#$||||||! .`:!!!|$$&&&&&&&&&&&&&&&&&&&&&&&$%$$$&@&&$&&$$|!|%$$$$%|;''``````````````':;!!!;::''':;!$%|$$%%$$$$$$%!!%&@@@@@@@@@@@@@@@@@@@@@@@@&&&&@&$$&@@@@@@@@@#&%||||||||||%@@$||||||! ;:''`'':;!!!!|%$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&$&&&&&$|!%%%%$&$$|;'``````````````''''''''::::;|$&$$$%%$$%%$$$&@@@@@@@@@@@@@@@@@@@@@@@@@@@&&&@&$$$&&&@@@@@@@@@@@@@@&$%|||$@@$||||||! |!;;;!!!!!!|%$$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%!:;|!||!!:'''``````````````''''''''':;;|$$$$$%%$%$$$&&&&&@@@@@@@@@@@@@@@@@@@@@@@@&&&@&$$$&&&&&@@@@@##@@@@@&&@@@@@@#@&%|||||! %|!!!!!!||%$$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&@@&&&&&&$$$!';;;:'```''`````````````````'''''';;:|$$$$$$$$%$$$&@&&&&@@@#@@@@@@@@@@@@@@@@@@@&&@&$$$$$$$&&&@@@@##@%;''|&@@@@@@@#@@@@@@@% &$%%%%%%$$$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&@&&&@&&&$$$%;``'''``':'``````````````````'''':::;|$$$$$$$%$$$$&&&&&&@@@##@@@@@@@@@@@@@@@@@@&@&$$$&&&$$$&&&@@@@|:''':%@@@@@@@#@@@@@@@@% @@&$$$$$&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&@&&@@&&&$$$$%:``````';:'```...`````````````'''':;|$$$$$$%%$$$$&&&&&&&@@##@@#######@@#@@@@@@#@&$$&&&&&$%$$&&@@%:'::'!&@@@@&@@@@@@@@@@@% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&@@&&&&&&&$$%:``````':;:```..``````````````''':;|$$$$$$%%$$$&&&&&&&@@@####################@&$$&&$$$$$$$|;|&$!''':;$&&&&&&@@@@@@@@@@@% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&$&@&$&&&$&&&&&%'``````.``````....```````````'`'';|$&$$$%$$$$$$&&&&&@@@@@##################@$$$&&$$$$$|:':;%&$;''''|&&&&&&&&@@@@@@@@@@% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&$%$&@@$$$$$&&&&&@@!````````.......````````````''`'':!%$&&&$$&&&&&&&&&&@@@#@@##############@@&$$$$&$$$$$$|:''|&&|''''!$&&&&&&@@@@@@@@@@@@% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|;%&$&@$$$$$$&&&&&@@&;..``..........````````````''``'';%$&&&&&&&&&&&&&&@@@@@##@############@@@$$$$&$!|$$$$!:':%@%:``':%&&@@@@@@@@@@@@@@@@@% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&$!!$&&$&&$|!|%$$$&&&@@@@$:.........``'''``':;:'`````````':!%$&&&&&&&@&&&&&@@@@@@@#@@#########@@@&$$$%!!$$$$$%;'';$&!``':%@@@@@@@@@@@@@@@@@@@&% ##@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|;%&&&&$%%$%!|%%$$$$&&@@@@@$;`.....`...````````````````````';|$&&&&&&&&@@@&&&@###@@@@#@&&##@@@@@&$$$$&&$$$$$$|'```!&%;|&&&&&@@@@@@@@@@@@@@@&&&&% ###&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%:|&&&&&$$||$&$|%%%$$&&&@@@@@@@@$;`........``'::'`...```'``````:|$$$&@@&$&@@@@@@&@#@@####@#&&#@$|%&$$%%&&$$$$%!'`.`:!$@@&&&&@@@@@@@@@@@@@@&&&&&&&&% ###@&&&&&&&&&&&&&&&&&&&&&&&&&&|:!&&&&&&$$%||$&&$%%%$$&&&&@@@@@@@@@@&%:`.................`'````:!;;|$$$&&@@&&&&@@@@&&@########@!':|&$$%%$|;:;;!|%%%%||$@@&&&&&&&@&&&&&&&&&&&&&&&&&&&% ###@&&&&&&&&&&&&&&&&&&&&&&$!:|&&&&&&&&$$%|%$&&&$%%%$&&&&&@@@@@@@@@@@@&&$;`..............``'';|!;;;;|%$$$$&@@@&&&@@&&$$&&@@@@##@&%||%%%$!:|%%%%%||%!|$@@@&&&&&&&&$$$$$$&&&&&&&&&&&&&% ###@&&&&&&&&&&&&&&&&&&&|:!$&&&&&&&&&&$%%%%$$&&&$%%$$$$&&@#@@@@@@@@@@@&&&&&&|'...........``:!!;;;;;!!;|$&$%|&@@@&&&&&$!|$$$&@@#@@&%%%%$|'':!%%%%|!|$&&@@&&&&&&&$%%%%$$$$$&&$$$$$$&&&% ###@&&&&&&&&&&&&&&&|:;%&&&&&&&&&&&&$$%%%%$$&&&&$$$$$$$$&@#@@@@@@@@@&&&&&&&&&&&&|'.....`;%%!!!!;;;!!!!;!%$$&$|%@@@@@&&@$;:::!|%$&$%%%$%:'``';!!|||%$&@@@&&&&&&$%%%%%%%$$$$$%%%%$$$$$| ###@&&&&&&&&&$|:;%&&&&&&&&&&&&&&&$$%%$%%$&&&&&&$$$$%$$$&@@@@@@@@@##@&&&&&&&&&&&&&&%|%&&&&&$|;;;;;;;;;;;;!$&$&$|!%&@@@@@@&%;::!$$$$$$%;:```````;||||%$&&$$$$$$%|%%%%%%%$$$%%%%%%%%$%| ###@&&$%|||$&&&&&&&&&&&&&&&&&&$$$$%%$$%$&&&&&&&$$$%%$$&&@@@@@@@@@@@##@&&&&&&&&&&&&&&&&&&&&@%;;;;;;;::;;;;!!$&&$$%!;|$$$&&&$&&&$$$$$%!|$&%:...`.`;|!|||!;!|||||||%%%%%%$%%%||||%%%%%| &&@@&&&&&&&&&&&&&&&&&&&&&&&$$$$$$%%$$%$&&&&&&&&$%%%%$$&&@@@@@@@@@@@@#@&@@&&&&&&&&&&&&&@###&%;;;;;;::::;;;!!!!|$$$&&%!:;!$&&&@&$$$&@&&&$%$&|``..'%#@@&$%%||||!;:'`';|%%$%%||||||||||| ###@&&&&&&&&&&&&&&&&&&&&$$$$$$$$%%$&&$$&&&&&&&&$%%%%$$&&&@@@@@@@@@@@@@@&&&&@@@@@&&@####$;':!!;;;::::;;;;!;!;::::;%&&&&&$$$&@&$$$@@$$$$$&@@@@$%@#@@##@@&%%||||||||%%%|!'`:!|||||||||| ###@&&&&&&&&&&&&&&&&&$$$$$$$$$$$$$$$%%$$$$&&&&@$%%%%$$&&&&&@@@@@@@@@&&&&@@&&&&&&&@@@@|:':;;!!;;:::::::;;!!;:::::::::':::';$$$$$&&$&&&@@@&&@@@@@#######@@##@&%||||||||%%%%|!''!|||||! ###@&&&&&&&&&&&&&&$$$$$$$$$$$&&$$$$$%%$$$$$&&&&&$%%$$$&&&&&$&&&@@@@&&&&&&&&&&&&@@@%:''':;;;;;:::::::::;;;:::::::::::::;;!%$$$$$|:::|$&&$&@@@@@&$&@#####@@@@####@&$%||%%%||||||;:!||! ###@&&&&&&&&&&&$$$$$$$$$$$&&&&&$$&&$%%$$$&&&&&&&&$%$$$$$&&&&&&&@@@#@&&&&&&&&@##$;''''':;;;;;:::::::::;!;:::::::::::::::;%&$$$$|''':;%&%!;:'''':|%$&@@@@#@@&&&@##@&&@@$|%%|||||||!:;| :;$@@&&&&&&&$$$$$$$$$$$&&&&&&&&&$$&&$$&&&&&&&&&&&$%%$$$&&&&&&&&&&&&@@#######@|:'''''';!!!;::::::;;!!!!;::::::::::::::::|$$$$$!'::;!!%&|;;''''''''''';$&@@#@&&$$&@&&@#@@@#####@$%||;: ''''':|$&$$$$$$$$$$&&&&&&&&&&&&&&$$&$$&&&&&&&&&&&&&$$$$$&&$$&&&&&@@@@@&$%$%|:''''''':;:::::::::::::;;:::::::::::::::::|$$$$$!::;;;;|&%;;:''''''''''''':!$&@@@&$$$$&################$ '''''''''';%$$&&&&&&&&&&&&&&&&&&&&$$$$&&&&&&&&&&&&&&$$$$$&@@@@@###@&&$%;''''''''':::;;:::::::::::;;:::'':::::::::::':|$$$$$!::;:::|&%;;:''''''''''''''```:%&@@&&&$$$&##############$ '''''''''''':':|&&&&&&&&&&&&&&&&&&&&$%$&&&&&&&&&&&&&&$$$$$&@@&@@@&$$%%!:''''''::::::!;::::::::::;;::::::::::::::''':|$$$$$|;;:::;%&|::'''''''''''''`.....``;$@@&&&&$$$&@###########$ ;:'''''''''''''':::!$&&&&&&&&&&&&&&&&&%|$&&&&&&&&&&&&&&$$$$&$$$$$$|:!|;':::::::::::;!;::::::::;;:::::::::::::''''':|$$$$$|;::::|&&|::'''''''''''``........`''!&@@&&&&$$$&@#########$ .';;;;;:'''''''''''':::;%&@&&&&&&&&&&&&%$&&$$$$&&&&&&$&@&&&$$$$%!:::!|;::::::::::::!!;::::::!;::::::::::::::''''':|&$$$$|;::::|&%;;:'``''''''''````......````'!$@@&&&&&$$$&@#######$ ;;;:`.`:;;;;::'''''''''''':;%@@@&&&&&&&&$$$&&&&&&&&&&@@&!::':'':::::||;::::::::::::!!;:::;!!;;:::::::::::::::''':%&$$$$|;:::;%&|:::'`````````'''```..`...````''!$@@&&&&&&&$$&@#####$ ;;;;;;;;;'..';;;;::''''''''''':|@@@@&&&&&&$%$&&&&&&&@@%:::::::::::::!|;:::::''''''';!;:;!!;:::::::::::::::::''':%&$$$%|;:::|&%;;:'''```````'''''``... ```''!&@&&&&&&&&&&&&@###$ :::;;;;;;;;!;;;'':;;;;:'''''''''':!&@@@&&&&&$$&&&&@@@$;::::::::::::';|:``````````'';!;;;:'''```````````````''''|$$$$%|;::|&$!;;:'````````''::''``.... .``'':%@&&&&&&&&&&&&&&@#$ ::::::::;;;;;;;;;;;;:'':;;:''''''''':;%@@@@&&&&$&@@@$;''''''':''`''`:|;````````````:!!:'''``.........``......`!$%%%%|;;|&$!:;'`````````'''::''. .. `''``''!$&&@@&&&&&&&&&&&&% ###@%!:::::::;;;;;;;;;;;;;;;;::'''''::::|&@@@&&&&&&%'```.....````''`'||'``````````';;'''``................. .!$%%%%|!%&$!:;:'``'''````'::::''. ....``''``'''|@&&&@&&&@&&&&&&$| ####@&&&@&|;::::::;;;;;;;;;;;;;;;:'''''''::!&@@@@@%:````......```'```;%;`````````''''``................. .!$%%%%%$&%;:::''```'''```'::::'`. ...``'```''';$@&&&@@&&&&&&&&&% ####@&&&&&&&&&$!:::::::;;;;;;;;;;;;;:''''''':|@@@$;````.......``''```'!%;``````''''``....... .... .;%%%%%%$%;::'''`````''''`'::::`. ...`````'''|@&&&&@@&&&&&&&&% ####@&&&&&&&&&&&&&&|;::::::;;;;;;;;;;;;:::'':;;%&;````.........``'````:||:```':''`...... .`:|%%%%%|;::''''``````'''''::::`. ....```'''!$@&&&&@@&&&&&&&% ####@&&&&&&&&&&&&&&&&&&|::::::::;;;;;;;;;:::::;;'````..........``'`````:||:':''`...... .`'!$%%%%|;:''```````````'''''::;'. ......``':%@@&&&&&@&&&&&&% ####@&&&&&&&&&&&&&&&&&&&&&$!:::::::;;;;;;;;;;;;'`````..........`''``````:||:''`. . .``!$&$%%%%%;'''`````````````'':::;;` .....```'!&@&&&&&&@&&&&&% ####@&&&&&&&&&&&&&&&&&&&&&&&&&|;:::::;;;;;;;;;:``````...........''````':':|%!'. .``'|$&|;|%|%%%!''````...`````````':::;;` .....```'|@&&&&&&&@&&&&% ####@&&&&&&&&&&&&&&&&&&&&&&&&&&&$!::::::;;;;;:``````....``......''``':'''':!|%;.. ..``:|%$|;::;|%||%%!'`````......```''`'':::;:' ....... ....````:%@&&&&&&@@&&&% ####@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%;:::::;;:```````....`. ...`'':''`. .':!||;````````';|%%|;::::';|%||%%;'```.........```'''''::::;'. ....````........ ......````:%@&&&&&&@@&&% ####@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|:::::'```````...``. ..'::'``. .```':;!||!;;!||!;::::''``';|%||%|;'```..........```'''''::::;:.....``````````...........`````;&&&&&&&@@@&% */ string s; int n, m; int main() { cin >> n >> m; cin >> s; while (m--) { string t = s; reverse(t.begin(), t.end()); string ss = s + t; string ff = s; for (int i = 0; i + n <= ss.size(); i++) { ff = min(ff, ss.substr(i, n)); } if (!m) { cout << ff << endl; return 0; } reverse(ff.begin(), ff.end()); bool xx = 1; for (int i = 1; i < n; i++) { if (ff[i] != ff[i - 1]) { xx = 0; break; } } if (xx) { cout << ff << endl; return 0; } s = ff; } cout << s << endl; return 0; }
[ "variable_declaration.value.change", "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
742,645
742,646
u545001286
cpp
p02943
// Relive your past life. // Face your demons. // The past is never dead,it is not even past. // The memories are not only the key to the past but...also to the future. // coded in Rusty Lake #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ctype.h> #include <cwchar> #include <cwctype> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <math.h> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <stdio.h> #include <stdlib.h> #include <streambuf> #include <string.h> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define ll long long #define pb push_back #define mp make_pair #define orz 1000000007 using namespace std; int n, k, L, f[10005], ans; char c[10005]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf(" %c", c + i); char C = 'z'; for (int i = 1; i <= n; ++i) C = min(C, c[i]); if (k > 20) { for (int i = 1; i <= n; ++i) printf("%c", C); printf("\n"); return 0; } for (int i = 1; i <= n; ++i) c[n * 2 + 1 - i] = c[i]; for (int i = 1; i <= n * 2; ++i) { if (c[i] != C) continue; if (i > 1 && c[i - 1] == C) f[i] = f[i - 1] + 1; else f[i] = 1; L = max(L, f[i]); } int _ = L; for (int i = 1; i < k; ++i) { _ *= 2; if (_ >= n) break; } if (_ >= n) { for (int i = 1; i <= n; ++i) printf("%c", C); printf("\n"); return 0; } _ = n - _; for (int i = n + 1; i <= n * 2; ++i) { if (f[i] < L) continue; if (!ans) { ans = i; continue; } int t = 0; for (int j = 0; j < _; ++j) { if (c[ans - j - L] == c[i - j - L]) continue; if (c[ans - j - L] < c[i - j - L]) t = 1; else t = 2; break; } if (t == 1) ans = i; } for (int i = 1; i <= n - _; ++i) printf("%c", C); for (int i = 0; i < _; ++i) printf("%c", c[ans - i - L]); printf("\n"); // system("pause"); return 0; }
// Relive your past life. // Face your demons. // The past is never dead,it is not even past. // The memories are not only the key to the past but...also to the future. // coded in Rusty Lake #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ctype.h> #include <cwchar> #include <cwctype> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <math.h> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <stdio.h> #include <stdlib.h> #include <streambuf> #include <string.h> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define ll long long #define pb push_back #define mp make_pair #define orz 1000000007 using namespace std; int n, k, L, f[10005], ans; char c[10005]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf(" %c", c + i); char C = 'z'; for (int i = 1; i <= n; ++i) C = min(C, c[i]); if (k > 20) { for (int i = 1; i <= n; ++i) printf("%c", C); printf("\n"); return 0; } for (int i = 1; i <= n; ++i) c[n * 2 + 1 - i] = c[i]; for (int i = 1; i <= n * 2; ++i) { if (c[i] != C) continue; if (i > 1 && c[i - 1] == C) f[i] = f[i - 1] + 1; else f[i] = 1; L = max(L, f[i]); } int _ = L; for (int i = 1; i < k; ++i) { _ *= 2; if (_ >= n) break; } if (_ >= n) { for (int i = 1; i <= n; ++i) printf("%c", C); printf("\n"); return 0; } _ = n - _; for (int i = n + 1; i <= n * 2; ++i) { if (f[i] < L) continue; if (!ans) { ans = i; continue; } int t = 0; for (int j = 0; j < _; ++j) { if (c[ans - j - L] == c[i - j - L]) continue; if (c[ans - j - L] < c[i - j - L]) t = 1; else t = 2; break; } if (t == 2) ans = i; } for (int i = 1; i <= n - _; ++i) printf("%c", C); for (int i = 0; i < _; ++i) printf("%c", c[ans - i - L]); printf("\n"); // system("pause"); return 0; }
[ "literal.number.change", "control_flow.branch.if.condition.change" ]
742,651
742,652
u728472449
cpp
p02943
// Relive your past life. // Face your demons. // The past is never dead,it is not even past. // The memories are not only the key to the past but...also to the future. // coded in Rusty Lake #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ctype.h> #include <cwchar> #include <cwctype> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <math.h> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <stdio.h> #include <stdlib.h> #include <streambuf> #include <string.h> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define ll long long #define pb push_back #define mp make_pair #define orz 1000000007 using namespace std; int n, k, L, f[10005], ans; char c[10005]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf(" %c", c + i); char C = 'z'; for (int i = 1; i <= n; ++i) C = min(C, c[i]); if (k > 20) { for (int i = 1; i <= n; ++i) printf("%c", C); printf("\n"); return 0; } for (int i = 1; i <= n; ++i) c[n * 2 + 1 - i] = c[i]; for (int i = 1; i <= n * 2; ++i) { if (c[i] != C) continue; if (i > 1 && c[i - 1] == C) f[i] = f[i - 1] + 1; else f[i] = 1; L = max(L, f[i]); } int _ = L; for (int i = 1; i < k; ++i) { _ *= 2; if (_ >= n) break; } if (_ >= n) { for (int i = 1; i <= n; ++i) printf("%c", C); printf("\n"); return 0; } _ = n - _; for (int i = n + 1; i <= n * 2; ++i) { if (f[i] < L) continue; if (!ans) { ans = i; continue; } int t = 0; for (int j = 0; j < _; ++j) { if (c[ans - j - L] == c[i - j - L]) continue; if (c[ans - j - L] < c[i - j - L]) t = 1; else t = 2; } if (t == 1) ans = i; } for (int i = 1; i <= n - _; ++i) printf("%c", C); for (int i = 0; i < _; ++i) printf("%c", c[ans - i - L]); printf("\n"); // system("pause"); return 0; }
// Relive your past life. // Face your demons. // The past is never dead,it is not even past. // The memories are not only the key to the past but...also to the future. // coded in Rusty Lake #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <ctype.h> #include <cwchar> #include <cwctype> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <math.h> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <stdio.h> #include <stdlib.h> #include <streambuf> #include <string.h> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #define ll long long #define pb push_back #define mp make_pair #define orz 1000000007 using namespace std; int n, k, L, f[10005], ans; char c[10005]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf(" %c", c + i); char C = 'z'; for (int i = 1; i <= n; ++i) C = min(C, c[i]); if (k > 20) { for (int i = 1; i <= n; ++i) printf("%c", C); printf("\n"); return 0; } for (int i = 1; i <= n; ++i) c[n * 2 + 1 - i] = c[i]; for (int i = 1; i <= n * 2; ++i) { if (c[i] != C) continue; if (i > 1 && c[i - 1] == C) f[i] = f[i - 1] + 1; else f[i] = 1; L = max(L, f[i]); } int _ = L; for (int i = 1; i < k; ++i) { _ *= 2; if (_ >= n) break; } if (_ >= n) { for (int i = 1; i <= n; ++i) printf("%c", C); printf("\n"); return 0; } _ = n - _; for (int i = n + 1; i <= n * 2; ++i) { if (f[i] < L) continue; if (!ans) { ans = i; continue; } int t = 0; for (int j = 0; j < _; ++j) { if (c[ans - j - L] == c[i - j - L]) continue; if (c[ans - j - L] < c[i - j - L]) t = 1; else t = 2; break; } if (t == 2) ans = i; } for (int i = 1; i <= n - _; ++i) printf("%c", C); for (int i = 0; i < _; ++i) printf("%c", c[ans - i - L]); printf("\n"); // system("pause"); return 0; }
[ "literal.number.change", "control_flow.branch.if.condition.change" ]
742,653
742,652
u728472449
cpp
p02943
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 998244353; int n, k, i; char c[10005], ans[10005], mn = 127; struct str { char c[5005]; } p[5005]; bool cmp(str a, str b) { return strcmp(a.c + 1, b.c + 1) < 0; } void dfs(char c[], int k) { int i, j, mx = 0, s[10005]; memset(s, 0, sizeof(s)); for (i = 1; i <= n; i++) if (c[i] != mn) break; if (i > n) { for (i = 1; i <= n; i++) printf("%c", mn); exit(0); } for (i = n + 1; i <= 2 * n; i++) c[i] = c[2 * n - i + 1]; if (k == 1) { for (i = 1; i <= 2 * n;) { if (c[i] != mn) { i++; continue; } for (j = i; j <= 2 * n && c[i] == c[j]; j++) ; s[i] = j - i; i = j; } for (i = 1; i <= n; i++) mx = max(mx, s[i]); int u = 0; for (i = 1; i <= n; i++) if (mx == s[i]) { u++; for (j = i; j < i + n; j++) p[u].c[j - i + 1] = c[j]; } sort(p + 1, p + 1 + u, cmp); if (ans[1] == 0 || strcmp(ans + 1, p[1].c + 1) < 0) for (i = 1; i <= n; i++) ans[i] = p[1].c[i]; return; } char m[10005]; for (i = n * 2; i >= 1;) { if (c[i] != mn) { i--; continue; } for (j = i; j >= 1 && c[i] == c[j]; j--) ; s[i] = i - j; i = j; } for (i = 1; i <= 2 * n; i++) mx = max(mx, s[i]); for (i = n; i < 2 * n; i++) if (mx == s[i]) { for (j = i - n + 1; j <= i; j++) m[j - (i - n)] = c[j]; dfs(m, k - 1); } } int main() { scanf("%d %d", &n, &k); scanf("%s", c + 1); for (i = 1; i <= n; i++) mn = min(mn, c[i]); dfs(c, k); printf("%s", ans + 1); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 998244353; int n, k, i; char c[10005], ans[10005], mn = 127; struct str { char c[5005]; } p[5005]; bool cmp(str a, str b) { return strcmp(a.c + 1, b.c + 1) < 0; } void dfs(char c[], int k) { int i, j, mx = 0, s[10005]; memset(s, 0, sizeof(s)); for (i = 1; i <= n; i++) if (c[i] != mn) break; if (i > n) { for (i = 1; i <= n; i++) printf("%c", mn); exit(0); } for (i = n + 1; i <= 2 * n; i++) c[i] = c[2 * n - i + 1]; if (k == 1) { for (i = 1; i <= 2 * n;) { if (c[i] != mn) { i++; continue; } for (j = i; j <= 2 * n && c[i] == c[j]; j++) ; s[i] = j - i; i = j; } for (i = 1; i <= n + 1; i++) mx = max(mx, s[i]); int u = 0; for (i = 1; i <= n + 1; i++) if (mx == s[i]) { u++; for (j = i; j < i + n; j++) p[u].c[j - i + 1] = c[j]; } sort(p + 1, p + 1 + u, cmp); if (ans[1] == 0 || strcmp(ans + 1, p[1].c + 1) > 0) for (i = 1; i <= n; i++) ans[i] = p[1].c[i]; return; } char m[10005]; for (i = n * 2; i >= 1;) { if (c[i] != mn) { i--; continue; } for (j = i; j >= 1 && c[i] == c[j]; j--) ; s[i] = i - j; i = j; } for (i = 1; i <= 2 * n; i++) mx = max(mx, s[i]); for (i = n; i <= 2 * n; i++) if (mx == s[i]) { for (j = i - n + 1; j <= i; j++) m[j - (i - n)] = c[j]; dfs(m, k - 1); } } int main() { scanf("%d %d", &n, &k); scanf("%s", c + 1); for (i = 1; i <= n; i++) mn = min(mn, c[i]); dfs(c, k); printf("%s", ans + 1); }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one", "misc.opposites", "expression.operator.compare.change", "expression.off_by_one", "expression.operation.binary.change" ]
742,655
742,656
u204432355
cpp
p02943
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 998244353; int n, k, i; char c[10005], ans[10005], mn = 127; struct str { char c[5005]; } p[5005]; bool cmp(str a, str b) { return strcmp(a.c + 1, b.c + 1) < 0; } void dfs(char c[], int k) { int i, j, mx = 0, s[10005]; memset(s, 0, sizeof(s)); for (i = 1; i <= n; i++) if (c[i] != mn) break; if (i > n) { for (i = 1; i <= n; i++) printf("%c", mn); exit(0); } for (i = n + 1; i <= 2 * n; i++) c[i] = c[2 * n - i + 1]; if (k == 1) { for (i = 1; i <= 2 * n;) { if (c[i] != mn) { i++; continue; } for (j = i; j <= 2 * n && c[i] == c[j]; j++) ; s[i] = j - i; i = j; } for (i = 1; i <= n; i++) mx = max(mx, s[i]); int u = 0; for (i = 1; i <= n; i++) if (mx == s[i]) { u++; for (j = i; j < i + n; j++) p[u].c[j - i + 1] = c[j]; } sort(p + 1, p + 1 + u, cmp); if (ans[1] == 0 || strcmp(ans + 1, p[1].c + 1) > 0) for (i = 1; i <= n; i++) ans[i] = p[1].c[i]; return; } char m[10005]; for (i = n * 2; i >= 1;) { if (c[i] != mn) { i--; continue; } for (j = i; j >= 1 && c[i] == c[j]; j--) ; s[i] = i - j; i = j; } for (i = 1; i <= 2 * n; i++) mx = max(mx, s[i]); for (i = n; i < 2 * n; i++) if (mx == s[i]) { for (j = i - n + 1; j <= i; j++) m[j - (i - n)] = c[j]; dfs(m, k - 1); } } int main() { scanf("%d %d", &n, &k); scanf("%s", c + 1); for (i = 1; i <= n; i++) mn = min(mn, c[i]); dfs(c, k); printf("%s", ans + 1); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 998244353; int n, k, i; char c[10005], ans[10005], mn = 127; struct str { char c[5005]; } p[5005]; bool cmp(str a, str b) { return strcmp(a.c + 1, b.c + 1) < 0; } void dfs(char c[], int k) { int i, j, mx = 0, s[10005]; memset(s, 0, sizeof(s)); for (i = 1; i <= n; i++) if (c[i] != mn) break; if (i > n) { for (i = 1; i <= n; i++) printf("%c", mn); exit(0); } for (i = n + 1; i <= 2 * n; i++) c[i] = c[2 * n - i + 1]; if (k == 1) { for (i = 1; i <= 2 * n;) { if (c[i] != mn) { i++; continue; } for (j = i; j <= 2 * n && c[i] == c[j]; j++) ; s[i] = j - i; i = j; } for (i = 1; i <= n + 1; i++) mx = max(mx, s[i]); int u = 0; for (i = 1; i <= n + 1; i++) if (mx == s[i]) { u++; for (j = i; j < i + n; j++) p[u].c[j - i + 1] = c[j]; } sort(p + 1, p + 1 + u, cmp); if (ans[1] == 0 || strcmp(ans + 1, p[1].c + 1) > 0) for (i = 1; i <= n; i++) ans[i] = p[1].c[i]; return; } char m[10005]; for (i = n * 2; i >= 1;) { if (c[i] != mn) { i--; continue; } for (j = i; j >= 1 && c[i] == c[j]; j--) ; s[i] = i - j; i = j; } for (i = 1; i <= 2 * n; i++) mx = max(mx, s[i]); for (i = n; i <= 2 * n; i++) if (mx == s[i]) { for (j = i - n + 1; j <= i; j++) m[j - (i - n)] = c[j]; dfs(m, k - 1); } } int main() { scanf("%d %d", &n, &k); scanf("%s", c + 1); for (i = 1; i <= n; i++) mn = min(mn, c[i]); dfs(c, k); printf("%s", ans + 1); }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one", "expression.operator.compare.change", "expression.off_by_one", "expression.operation.binary.change" ]
742,657
742,656
u204432355
cpp
p02943
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 998244353; int n, k, i; char c[10005], ans[10005], mn = 127; struct str { char c[5005]; } p[5005]; bool cmp(str a, str b) { return strcmp(a.c + 1, b.c + 1) > 0; } void dfs(char c[], int k) { int i, j, mx = 0, s[10005]; memset(s, 0, sizeof(s)); for (i = 1; i <= n; i++) if (c[i] != mn) break; if (i > n) { for (i = 1; i <= n; i++) printf("%c", mn); exit(0); } for (i = n + 1; i <= 2 * n; i++) c[i] = c[2 * n - i + 1]; if (k == 1) { for (i = 1; i <= 2 * n;) { if (c[i] != mn) { i++; continue; } for (j = i; j <= 2 * n && c[i] == c[j]; j++) ; s[i] = j - i; i = j; } for (i = 1; i <= n; i++) mx = max(mx, s[i]); int u = 0; for (i = 1; i <= n; i++) if (mx == s[i]) { u++; for (j = i; j < i + n; j++) p[u].c[j - i + 1] = c[j]; } sort(p + 1, p + 1 + u, cmp); if (ans[1] == 0 || strcmp(ans + 1, p[1].c + 1) > 0) for (i = 1; i <= n; i++) ans[i] = p[1].c[i]; return; } char m[10005]; for (i = n * 2; i >= 1;) { if (c[i] != mn) { i--; continue; } for (j = i; j >= 1 && c[i] == c[j]; j--) ; s[i] = i - j; i = j; } for (i = 1; i <= 2 * n; i++) mx = max(mx, s[i]); for (i = n; i < 2 * n; i++) if (mx == s[i]) { for (j = i - n + 1; j <= i; j++) m[j - (i - n)] = c[j]; dfs(m, k - 1); } } int main() { scanf("%d %d", &n, &k); scanf("%s", c + 1); for (i = 1; i <= n; i++) mn = min(mn, c[i]); dfs(c, k); printf("%s", ans + 1); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 998244353; int n, k, i; char c[10005], ans[10005], mn = 127; struct str { char c[5005]; } p[5005]; bool cmp(str a, str b) { return strcmp(a.c + 1, b.c + 1) < 0; } void dfs(char c[], int k) { int i, j, mx = 0, s[10005]; memset(s, 0, sizeof(s)); for (i = 1; i <= n; i++) if (c[i] != mn) break; if (i > n) { for (i = 1; i <= n; i++) printf("%c", mn); exit(0); } for (i = n + 1; i <= 2 * n; i++) c[i] = c[2 * n - i + 1]; if (k == 1) { for (i = 1; i <= 2 * n;) { if (c[i] != mn) { i++; continue; } for (j = i; j <= 2 * n && c[i] == c[j]; j++) ; s[i] = j - i; i = j; } for (i = 1; i <= n + 1; i++) mx = max(mx, s[i]); int u = 0; for (i = 1; i <= n + 1; i++) if (mx == s[i]) { u++; for (j = i; j < i + n; j++) p[u].c[j - i + 1] = c[j]; } sort(p + 1, p + 1 + u, cmp); if (ans[1] == 0 || strcmp(ans + 1, p[1].c + 1) > 0) for (i = 1; i <= n; i++) ans[i] = p[1].c[i]; return; } char m[10005]; for (i = n * 2; i >= 1;) { if (c[i] != mn) { i--; continue; } for (j = i; j >= 1 && c[i] == c[j]; j--) ; s[i] = i - j; i = j; } for (i = 1; i <= 2 * n; i++) mx = max(mx, s[i]); for (i = n; i <= 2 * n; i++) if (mx == s[i]) { for (j = i - n + 1; j <= i; j++) m[j - (i - n)] = c[j]; dfs(m, k - 1); } } int main() { scanf("%d %d", &n, &k); scanf("%s", c + 1); for (i = 1; i <= n; i++) mn = min(mn, c[i]); dfs(c, k); printf("%s", ans + 1); }
[ "misc.opposites", "expression.operator.compare.change", "function.return_value.change", "expression.operation.binary.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one", "expression.off_by_one" ]
742,658
742,656
u204432355
cpp
p02943
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int n, K; #define Maxn 10010 char S[Maxn], Ans[Maxn]; int L = 0, H; int G = 0; char c = 'z'; char ch[Maxn]; int sum[Maxn]; inline void solve() { for (register int i = 1; i <= n - L; ++i) ch[i] = ch[L - H + i]; for (register int i = n - L + 1; i <= n; ++i) ch[i] = c; reverse(ch + 1, ch + n + 1); } int main() { scanf("%d%d", &n, &K); scanf("%s", S + 1); for (register int i = 1; i <= n; ++i) Ans[i] = c; for (register int i = 1; i <= n; ++i) if (S[i] < c) c = S[i]; int at; bool flag = false; for (register int i = 1; i <= n; i = at) if (S[i] == c) { at = i; while (at <= n && S[at] == c) at++; if (at == n + 1) G = at - i; if (at - i >= L) { L = at - i; if (at == n + 1) flag = true; } } else at = i + 1; H = L; if (G * 2 >= H) { H = G; L = G; flag = true; } if (!flag) K--; for (register int i = 1; i <= K; ++i) { L *= 2; if (L >= n) { for (register int j = 1; j <= n; ++j) printf("%c", c); return 0; } } if (flag) { for (register int i = 1; i <= n; ++i) ch[i] = S[i]; solve(); bool Ha = false; for (register int i = 1; i <= n; ++i) { if (Ha == false && ch[i] > Ans[i]) break; if (ch[i] < Ans[i]) Ha = true; if (Ha) Ans[i] = ch[i]; } } else { for (register int i = n + 1; i <= 2 * n; ++i) S[i] = S[2 * n + 1 - i]; sum[0] = 0; for (register int i = 1; i <= 2 * n; ++i) { sum[i] = sum[i - 1]; if (S[i] == c) sum[i]++; } for (register int i = n; i <= 2 * n; ++i) if (sum[i] - sum[i - H] == H) { for (register int j = 1; j <= n; ++j) ch[j] = S[i - n + j]; solve(); bool Ha = false; for (register int i = 1; i <= n; ++i) { if (Ha == false && ch[i] > Ans[i]) break; if (ch[i] < Ans[i]) Ha = true; if (Ha) Ans[i] = ch[i]; } } } for (register int i = 1; i <= n; ++i) printf("%c", Ans[i]); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int n, K; #define Maxn 10010 char S[Maxn], Ans[Maxn]; int L = 0, H; int G = 0; char c = 'z'; char ch[Maxn]; int sum[Maxn]; inline void solve() { for (register int i = 1; i <= n - L; ++i) ch[i] = ch[L - H + i]; for (register int i = n - L + 1; i <= n; ++i) ch[i] = c; reverse(ch + 1, ch + n + 1); } int main() { scanf("%d%d", &n, &K); scanf("%s", S + 1); for (register int i = 1; i <= n; ++i) Ans[i] = c; for (register int i = 1; i <= n; ++i) if (S[i] < c) c = S[i]; int at; bool flag = false; for (register int i = 1; i <= n; i = at) if (S[i] == c) { at = i; while (at <= n && S[at] == c) at++; if (at == n + 1) G = at - i; if (at - i >= L) { L = at - i; if (at == n + 1) flag = true; } } else at = i + 1; H = L; if (G * 2 > H) { H = G; L = G; flag = true; } if (!flag) K--; for (register int i = 1; i <= K; ++i) { L *= 2; if (L >= n) { for (register int j = 1; j <= n; ++j) printf("%c", c); return 0; } } if (flag) { for (register int i = 1; i <= n; ++i) ch[i] = S[i]; solve(); bool Ha = false; for (register int i = 1; i <= n; ++i) { if (Ha == false && ch[i] > Ans[i]) break; if (ch[i] < Ans[i]) Ha = true; if (Ha) Ans[i] = ch[i]; } } else { for (register int i = n + 1; i <= 2 * n; ++i) S[i] = S[2 * n + 1 - i]; sum[0] = 0; for (register int i = 1; i <= 2 * n; ++i) { sum[i] = sum[i - 1]; if (S[i] == c) sum[i]++; } for (register int i = n; i <= 2 * n; ++i) if (sum[i] - sum[i - H] == H) { for (register int j = 1; j <= n; ++j) ch[j] = S[i - n + j]; solve(); bool Ha = false; for (register int i = 1; i <= n; ++i) { if (Ha == false && ch[i] > Ans[i]) break; if (ch[i] < Ans[i]) Ha = true; if (Ha) Ans[i] = ch[i]; } } } for (register int i = 1; i <= n; ++i) printf("%c", Ans[i]); return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
742,661
742,662
u299340570
cpp
p02943
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int n, K; #define Maxn 10010 char S[Maxn], Ans[Maxn]; int L = 0, H; int G = 0; char c = 'z'; char ch[Maxn]; int sum[Maxn]; inline void solve() { for (register int i = 1; i <= n - L; ++i) ch[i] = ch[L - H + i]; for (register int i = n - L + 1; i <= n; ++i) ch[i] = c; reverse(ch + 1, ch + n + 1); } int main() { scanf("%d%d", &n, &K); scanf("%s", S + 1); for (register int i = 1; i <= n; ++i) Ans[i] = c; for (register int i = 1; i <= n; ++i) if (S[i] < c) c = S[i]; int at; bool flag = false; for (register int i = 1; i <= n; i = at) if (S[i] == c) { at = i; while (at <= n && S[at] == c) at++; if (at == n + 1) G = at - i; if (at - i >= L) { L = at - i; if (at == n + 1) flag = true; } } else at = i + 1; H = L; if (G * 2 >= H) { H = G; flag = true; } if (!flag) K--; for (register int i = 1; i <= K; ++i) { L *= 2; if (L >= n) { for (register int j = 1; j <= n; ++j) printf("%c", c); return 0; } } if (flag) { for (register int i = 1; i <= n; ++i) ch[i] = S[i]; solve(); bool Ha = false; for (register int i = 1; i <= n; ++i) { if (Ha == false && ch[i] > Ans[i]) break; if (ch[i] < Ans[i]) Ha = true; if (Ha) Ans[i] = ch[i]; } } else { for (register int i = n + 1; i <= 2 * n; ++i) S[i] = S[2 * n + 1 - i]; sum[0] = 0; for (register int i = 1; i <= 2 * n; ++i) { sum[i] = sum[i - 1]; if (S[i] == c) sum[i]++; } for (register int i = n; i <= 2 * n; ++i) if (sum[i] - sum[i - H] == H) { for (register int j = 1; j <= n; ++j) ch[j] = S[i - n + j]; solve(); bool Ha = false; for (register int i = 1; i <= n; ++i) { if (Ha == false && ch[i] > Ans[i]) break; if (ch[i] < Ans[i]) Ha = true; if (Ha) Ans[i] = ch[i]; } } } for (register int i = 1; i <= n; ++i) printf("%c", Ans[i]); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int n, K; #define Maxn 10010 char S[Maxn], Ans[Maxn]; int L = 0, H; int G = 0; char c = 'z'; char ch[Maxn]; int sum[Maxn]; inline void solve() { for (register int i = 1; i <= n - L; ++i) ch[i] = ch[L - H + i]; for (register int i = n - L + 1; i <= n; ++i) ch[i] = c; reverse(ch + 1, ch + n + 1); } int main() { scanf("%d%d", &n, &K); scanf("%s", S + 1); for (register int i = 1; i <= n; ++i) Ans[i] = c; for (register int i = 1; i <= n; ++i) if (S[i] < c) c = S[i]; int at; bool flag = false; for (register int i = 1; i <= n; i = at) if (S[i] == c) { at = i; while (at <= n && S[at] == c) at++; if (at == n + 1) G = at - i; if (at - i >= L) { L = at - i; if (at == n + 1) flag = true; } } else at = i + 1; H = L; if (G * 2 > H) { H = G; L = G; flag = true; } if (!flag) K--; for (register int i = 1; i <= K; ++i) { L *= 2; if (L >= n) { for (register int j = 1; j <= n; ++j) printf("%c", c); return 0; } } if (flag) { for (register int i = 1; i <= n; ++i) ch[i] = S[i]; solve(); bool Ha = false; for (register int i = 1; i <= n; ++i) { if (Ha == false && ch[i] > Ans[i]) break; if (ch[i] < Ans[i]) Ha = true; if (Ha) Ans[i] = ch[i]; } } else { for (register int i = n + 1; i <= 2 * n; ++i) S[i] = S[2 * n + 1 - i]; sum[0] = 0; for (register int i = 1; i <= 2 * n; ++i) { sum[i] = sum[i - 1]; if (S[i] == c) sum[i]++; } for (register int i = n; i <= 2 * n; ++i) if (sum[i] - sum[i - H] == H) { for (register int j = 1; j <= n; ++j) ch[j] = S[i - n + j]; solve(); bool Ha = false; for (register int i = 1; i <= n; ++i) { if (Ha == false && ch[i] > Ans[i]) break; if (ch[i] < Ans[i]) Ha = true; if (Ha) Ans[i] = ch[i]; } } } for (register int i = 1; i <= n; ++i) printf("%c", Ans[i]); return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "assignment.add" ]
742,664
742,662
u299340570
cpp