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
p02937
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; #define rep(i, s) for (int i = 0; i < s; ++i) #define all(v) (v.begin(), v.end()) #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define EACH(i, s) \ for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i) #define VEC(a, n) vector<int> a(n) #define PQ(a) priority_queue<int> a #define PQmin(a) priority_queue<int, : vector<int>, greater<int>> a #define PAIR pair<int, int> /* sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){ return l.first<r.first || (l.first==r.first && l.second > r.second); }); */ typedef long long ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); vector<vector<int>> is(26); for (int i = 0; i < n; i++) { is[s[i] - 'a'].push_back(i); } for (int i = 0; i < n; i++) { is[s[i] - 'a'].push_back(i + n); } ll ans = 0; int p = 0; for (int i = 0; i < m; i++) { int c = t[i] - 'a'; if (is[c].size() == 0) { cout << "-1" << endl; return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p); // p以上の最小の値 if (p >= n) { p -= n; ans += n; } } ans += p; cout << ans + 1 << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; #define rep(i, s) for (int i = 0; i < s; ++i) #define all(v) (v.begin(), v.end()) #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define EACH(i, s) \ for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i) #define VEC(a, n) vector<int> a(n) #define PQ(a) priority_queue<int> a #define PQmin(a) priority_queue<int, : vector<int>, greater<int>> a #define PAIR pair<int, int> /* sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){ return l.first<r.first || (l.first==r.first && l.second > r.second); }); */ typedef long long ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); vector<vector<int>> is(26); for (int i = 0; i < n; i++) { is[s[i] - 'a'].push_back(i); } for (int i = 0; i < n; i++) { is[s[i] - 'a'].push_back(i + n); } ll ans = 0; int p = 0; for (int i = 0; i < m; i++) { int c = t[i] - 'a'; if (is[c].size() == 0) { cout << "-1" << endl; return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p) + 1; // p以上の最小の値 if (p >= n) { p -= n; ans += n; } } ans += p; cout << ans << endl; return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
740,497
740,498
u275934251
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 1e5 + 5; int va[26], vb[26]; char a[N], b[N]; vector<int> v[26]; int main() { scanf("%s%s", a, b); int n = strlen(a), m = strlen(b), x, flag = 0; for (int i = 0; i < n; i++) { x = a[i] - 'a'; va[x] = 1; v[x].push_back(i + 1); } for (int i = 0; i < m; i++) if (va[b[i] - 'a'] == 0) { flag = 1; break; } if (flag) puts("-1"); else { ll len = 0; int now = 0; for (int i = 0; i < m; i++) { int k = b[i] - 'a'; int pos = lower_bound(v[k].begin(), v[k].end(), now) - v[k].begin(); if (pos == v[k].size()) { len += n; now = 0; pos = lower_bound(v[k].begin(), v[k].end(), now) - v[k].begin(); } now = v[k][pos]; } printf("%lld\n", now + len); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 1e5 + 5; int va[26], vb[26]; char a[N], b[N]; vector<int> v[26]; int main() { scanf("%s%s", a, b); int n = strlen(a), m = strlen(b), x, flag = 0; for (int i = 0; i < n; i++) { x = a[i] - 'a'; va[x] = 1; v[x].push_back(i + 1); } for (int i = 0; i < m; i++) if (va[b[i] - 'a'] == 0) { flag = 1; break; } if (flag) puts("-1"); else { ll len = 0; int now = 0; for (int i = 0; i < m; i++) { int k = b[i] - 'a'; int pos = upper_bound(v[k].begin(), v[k].end(), now) - v[k].begin(); if (pos == v[k].size()) { len += n; now = 0; pos = upper_bound(v[k].begin(), v[k].end(), now) - v[k].begin(); } now = v[k][pos]; } printf("%lld\n", now + len); } return 0; }
[ "identifier.change", "call.function.change", "expression.operation.binary.change", "assignment.value.change" ]
740,500
740,501
u820628270
cpp
p02937
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep_down(i, n) for (int i = n - 1; i >= 0; --i) typedef long long ll; using namespace std; const ll MOD = 1000000007LL; const int INF = 1000000007; string S, T; unordered_map<char, int> M; unordered_map<char, vector<ll>> N; int main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> S >> T; rep(i, S.size()) { M[S[i]]++; N[S[i]].push_back(i); } rep(i, T.size()) { char s = T[i]; if (M[s] == 0) { cout << -1 << endl; return 0; } } ll current = 0ll; ll counter = 0ll; rep(i, T.size()) { char c = T[i]; vector<ll>::iterator it = upper_bound(N[c].begin(), N[c].end(), current); if (it == N[c].end()) { counter++; current = N[c][0]; } else current = *it; } cout << counter * S.size() + current + 1ll << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep_down(i, n) for (int i = n - 1; i >= 0; --i) typedef long long ll; using namespace std; const ll MOD = 1000000007LL; const int INF = 1000000007; string S, T; unordered_map<char, int> M; unordered_map<char, vector<ll>> N; int main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> S >> T; rep(i, S.size()) { M[S[i]]++; N[S[i]].push_back(i); } rep(i, T.size()) { char t = T[i]; if (M[t] == 0) { cout << -1 << endl; return 0; } } ll current = -1ll; ll counter = 0ll; rep(i, T.size()) { char c = T[i]; vector<ll>::iterator it = upper_bound(N[c].begin(), N[c].end(), current); if (it == N[c].end()) { counter++; current = N[c][0]; } else current = *it; } cout << counter * S.size() + current + 1ll << endl; return 0; }
[ "variable_declaration.name.change", "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change", "literal.number.change", "variable_declaration.value.change" ]
740,502
740,503
u288087195
cpp
p02937
#include <algorithm> #include <cstdio> #include <cstring> #include <vector> using namespace std; const int maxn = 1e5 + 5; char s[maxn], t[maxn]; vector<int> pos[30]; int main() { int lens, lent, cur = 0; long long ans = 0; vector<int>::iterator it; scanf("%s%s", s, t); lens = strlen(s); lent = strlen(t); for (int i = 0; i < lens; i++) pos[s[i] - 'a'].push_back(i + 1); for (int i = 0; i < lent; i++) { if (!pos[t[i] - 'a'].size()) return puts("-1") & 0; it = lower_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), cur); if (it == pos[t[i] - 'a'].end()) { ans += lens - cur + pos[t[i] - 'a'][0]; cur = pos[t[i] - 'a'][0]; } else { ans += *it - cur; cur = *it; } } printf("%lld\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <vector> using namespace std; const int maxn = 1e5 + 5; char s[maxn], t[maxn]; vector<int> pos[30]; int main() { int lens, lent, cur = 0; long long ans = 0; vector<int>::iterator it; scanf("%s%s", s, t); lens = strlen(s); lent = strlen(t); for (int i = 0; i < lens; i++) pos[s[i] - 'a'].push_back(i + 1); for (int i = 0; i < lent; i++) { if (!pos[t[i] - 'a'].size()) return puts("-1") & 0; it = upper_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), cur); if (it == pos[t[i] - 'a'].end()) { ans += lens - cur + pos[t[i] - 'a'][0]; cur = pos[t[i] - 'a'][0]; } else { ans += *it - cur; cur = *it; } } printf("%lld\n", ans); return 0; }
[ "assignment.value.change", "identifier.change", "call.function.change" ]
740,506
740,507
u303496477
cpp
p02937
#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/stack:512000000") #include <algorithm> #include <bitset> #include <cassert> #include <ccomplex> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define rep(i, n) for (ll i = 0; i < (n); i++) #define forn(i, n, m) for (ll i = (n); i <= (m); i++) #define all(x) x.begin(), x.end() #define mp make_pair #define X first #define Y second using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; mt19937_64 gen(time(NULL)); ll const mod = 1e9 + 7; ll mul(ll a, ll b) { ll val = a * b - (ll)((ld)a * b / mod) * mod; if (val < 0) val += mod; if (val >= mod) val -= mod; return val; } ll poww(ll a, ll b) { ll val = 1; a %= mod; while (b > 0) { if (b % 2) val = mul(a, val); a = mul(a, a); b >>= 1; } return val % mod; } ll inv(ll a) { return poww(a, mod - 2); } ll const maxn = 2e5 + 5; vector<ll> kek[26]; ll ptr[26]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s, t; cin >> s >> t; for (ll i = 0; i < s.size(); i++) { kek[s[i] - 'a'].push_back(i); } ll cnt = 0; for (char c : t) { if (kek[c - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll k = 0; ll mx = 0; for (char c : t) { k++; ll id = upper_bound(all(kek[c - 'a']), mx) - begin(kek[c - 'a']); if (id < kek[c - 'a'].size()) { mx = kek[c - 'a'][id]; } else { cnt++; mx = kek[c - 'a'][0]; } if (k == t.size()) { cout << cnt * (s.size()) + mx + 1 << endl; return 0; } } return 0; } /* */
#define _CRT_SECURE_NO_WARNINGS #pragma comment(linker, "/stack:512000000") #include <algorithm> #include <bitset> #include <cassert> #include <ccomplex> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define rep(i, n) for (ll i = 0; i < (n); i++) #define forn(i, n, m) for (ll i = (n); i <= (m); i++) #define all(x) x.begin(), x.end() #define mp make_pair #define X first #define Y second using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; mt19937_64 gen(time(NULL)); ll const mod = 1e9 + 7; ll mul(ll a, ll b) { ll val = a * b - (ll)((ld)a * b / mod) * mod; if (val < 0) val += mod; if (val >= mod) val -= mod; return val; } ll poww(ll a, ll b) { ll val = 1; a %= mod; while (b > 0) { if (b % 2) val = mul(a, val); a = mul(a, a); b >>= 1; } return val % mod; } ll inv(ll a) { return poww(a, mod - 2); } ll const maxn = 2e5 + 5; vector<ll> kek[26]; ll ptr[26]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s, t; cin >> s >> t; for (ll i = 0; i < s.size(); i++) { kek[s[i] - 'a'].push_back(i); } ll cnt = 0; for (char c : t) { if (kek[c - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll k = 0; ll mx = -1; for (char c : t) { k++; ll id = upper_bound(all(kek[c - 'a']), mx) - begin(kek[c - 'a']); if (id < kek[c - 'a'].size()) { mx = kek[c - 'a'][id]; } else { cnt++; mx = kek[c - 'a'][0]; } if (k == t.size()) { cout << cnt * (s.size()) + mx + 1 << endl; return 0; } } return 0; } /* */
[ "literal.number.change", "variable_declaration.value.change" ]
740,511
740,512
u258032299
cpp
p02937
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <iterator> #include <set> using namespace std; using namespace __gnu_pbds; #define f first #define s second #define pb push_back #define all(x) x.begin(), x.end() #define ll long long int #define vi vector<int> #define vii vector<pair<int, int>> #define pii pair<int, int> #define plii pair<pair<ll, int>, int> #define piii pair<pii, int> #define viii vector<pair<pii, int>> #define vl vector<ll> #define vll vector<pair<ll, ll>> #define pll pair<ll, ll> #define pli pair<ll, int> #define mp make_pair #define ms(x, v) memset(x, v, sizeof x) #define pr_vec(v) \ for (int i = 0; i < v.size(); i++) \ cout << v[i] << " "; #define f_in(st) freopen(st, "r", stdin) #define f_out(st) freopen(st, "w", stdout) #define INF INT_MAX #define matrix vector<vector<ll>> #define fr(i, a, b) for (i = a; i <= b; i++) #define fb(i, a, b) for (i = a; i >= b; i--) #define ASST(x, l, r) assert(x <= r && x >= l) #define maxbits 9 #define maxmask (1ll << maxbits) typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; const int N = 200000 + 10, M = (ll)1e9 + 1; const int mod = 998244353, sz = 5; void work() { string s, t; cin >> s >> t; ll l1 = s.length(), l2 = t.length(); ll nx[l1 + 1][26]; vl ls(26, -1); for (ll i = 0; i < 26; i++) nx[l1][i] = -1; for (ll i = l1 - 1; i >= 0; --i) { ls[s[i] - 'a'] = i; for (ll j = 0; j < 26; j++) { nx[i][j] = ls[j]; } } ll ind, cycle; ind = cycle = 0; for (ll i = 0; i < l2; i++) { if (nx[ind][t[i] - 'a'] != -1) { ind = (nx[ind][t[i] - 'a']); } else { cycle++; ind = 0; if (nx[ind][t[i] - 'a'] != -1) { ind = (nx[ind][t[i] - 'a']); } else { cout << -1; return; } } } cout << l1 * cycle + ind + 1; return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll t; // cin >> t; t = 1; while (t--) { work(); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <iterator> #include <set> using namespace std; using namespace __gnu_pbds; #define f first #define s second #define pb push_back #define all(x) x.begin(), x.end() #define ll long long int #define vi vector<int> #define vii vector<pair<int, int>> #define pii pair<int, int> #define plii pair<pair<ll, int>, int> #define piii pair<pii, int> #define viii vector<pair<pii, int>> #define vl vector<ll> #define vll vector<pair<ll, ll>> #define pll pair<ll, ll> #define pli pair<ll, int> #define mp make_pair #define ms(x, v) memset(x, v, sizeof x) #define pr_vec(v) \ for (int i = 0; i < v.size(); i++) \ cout << v[i] << " "; #define f_in(st) freopen(st, "r", stdin) #define f_out(st) freopen(st, "w", stdout) #define INF INT_MAX #define matrix vector<vector<ll>> #define fr(i, a, b) for (i = a; i <= b; i++) #define fb(i, a, b) for (i = a; i >= b; i--) #define ASST(x, l, r) assert(x <= r && x >= l) #define maxbits 9 #define maxmask (1ll << maxbits) typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; const int N = 200000 + 10, M = (ll)1e9 + 1; const int mod = 998244353, sz = 5; void work() { string s, t; cin >> s >> t; ll l1 = s.length(), l2 = t.length(); ll nx[l1 + 1][26]; vl ls(26, -1); for (ll i = 0; i < 26; i++) nx[l1][i] = -1; for (ll i = l1 - 1; i >= 0; --i) { ls[s[i] - 'a'] = i + 1; for (ll j = 0; j < 26; j++) { nx[i][j] = ls[j]; } } ll ind, cycle; ind = cycle = 0; for (ll i = 0; i < l2; i++) { if (nx[ind][t[i] - 'a'] != -1) { ind = (nx[ind][t[i] - 'a']); } else { cycle++; ind = 0; if (nx[ind][t[i] - 'a'] != -1) { ind = (nx[ind][t[i] - 'a']); } else { cout << -1; return; } } } cout << l1 * cycle + ind; return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll t; // cin >> t; t = 1; while (t--) { work(); } return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
740,521
740,522
u888735570
cpp
p02937
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <vector> std::size_t indexOf(char c) { return c - 'a'; } int main(void) { std::string s, t; std::cin >> s >> t; std::vector<std::vector<int>> map(27); for (int i = 0; i < s.size(); i++) { map[indexOf(s[i])].push_back(i); } long long count = 0; long long index = -1; for (std::size_t i = 0; i < t.size(); i++) { auto &vec = map[indexOf(t[i])]; if (vec.size() == 0) { std::cout << -1 << std::endl; return 0; } } for (std::size_t i = 0; i < t.size(); i++) { auto &vec = map[indexOf(t[i])]; if (vec[vec.size() - 1] < index) { index = vec[0]; count++; } else { index = *std::upper_bound(vec.begin(), vec.end(), index); } } std::cout << count * s.size() + index + 1 << std::endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <vector> std::size_t indexOf(char c) { return c - 'a'; } int main(void) { std::string s, t; std::cin >> s >> t; std::vector<std::vector<int>> map(27); for (int i = 0; i < s.size(); i++) { map[indexOf(s[i])].push_back(i); } long long count = 0; long long index = -1; for (std::size_t i = 0; i < t.size(); i++) { auto &vec = map[indexOf(t[i])]; if (vec.size() == 0) { std::cout << -1 << std::endl; return 0; } } for (std::size_t i = 0; i < t.size(); i++) { auto &vec = map[indexOf(t[i])]; if (vec[vec.size() - 1] <= index) { index = vec[0]; count++; } else { index = *std::upper_bound(vec.begin(), vec.end(), index); } } std::cout << count * s.size() + index + 1 << std::endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,525
740,526
u257511191
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define endl "\n" const int MAX = 100005; const long long mod = 1.0e9 + 7; ll ceil(ll a, ll b) { if (a % b == 0) { return a / b; } else { return a / b + 1; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, q, i, j; string s, t; cin >> s >> t; n = s.length(); m = t.length(); int pos = 0, x; map<ll, vector<ll>> mp; for (i = 0; i < n; i++) { mp[s[i] - 'a'].push_back(i + 1); } for (i = 0; i < m; i++) { if (mp[t[i] - 'a'].size() == 0) { cout << "-1" << endl; return 0; } x = lower_bound(mp[t[i] - 'a'].begin(), mp[t[i] - 'a'].end(), pos % n) - mp[t[i] - 'a'].begin(); if (x == mp[t[i] - 'a'].size()) { pos = n * ceil(pos, n) + mp[t[i] - 'a'][0]; } else pos = n * (pos / n) + mp[t[i] - 'a'][x]; // cout<<pos<<endl; } cout << pos << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ull; typedef long double ld; #define endl "\n" const int MAX = 100005; const long long mod = 1.0e9 + 7; ll ceil(ll a, ll b) { if (a % b == 0) { return a / b; } else { return a / b + 1; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, q, i, j; string s, t; cin >> s >> t; n = s.length(); m = t.length(); int pos = 0, x; map<ll, vector<ll>> mp; for (i = 0; i < n; i++) { mp[s[i] - 'a'].push_back(i + 1); } for (i = 0; i < m; i++) { if (mp[t[i] - 'a'].size() == 0) { cout << "-1" << endl; return 0; } x = upper_bound(mp[t[i] - 'a'].begin(), mp[t[i] - 'a'].end(), pos % n) - mp[t[i] - 'a'].begin(); if (x == (mp[t[i] - 'a'].size())) { pos = n * ceil(pos, n) + mp[t[i] - 'a'][0]; } else pos = n * (pos / n) + mp[t[i] - 'a'][x]; // cout<<pos<<endl; } cout << pos << endl; return 0; }
[ "assignment.value.change", "identifier.change", "call.function.change", "expression.operation.binary.change", "control_flow.branch.if.condition.change" ]
740,531
740,532
u103914968
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 1e5 + 5; int lst[26], nxt[maxn][26]; int main() { string s, t; cin >> s >> t; int n = s.length(); int m = t.length(); for (int i = 0; i < 26; i++) lst[i] = -1; for (int i = 0; i < 26; i++) nxt[n][26] = -1; for (int i = n - 1; i >= 0; i--) { lst[s[i] - 'a'] = i + 1; for (int j = 0; j < 26; j++) { nxt[i][j] = lst[j]; } } ll ans = 0; ll cur = 0, idx = 0; for (int i = 0; i < m; i++) { if (nxt[idx][t[i] - 'a'] != -1) { idx = nxt[idx][t[i] - 'a']; } else { idx = 0; if (nxt[idx][t[i] - 'a'] == -1) { cout << "-1"; return 0; } else { cur++; idx = nxt[idx][t[i] - 'a']; } } } ans = cur * n + idx; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 1e5 + 5; int lst[26], nxt[maxn][26]; int main() { string s, t; cin >> s >> t; int n = s.length(); int m = t.length(); for (int i = 0; i < 26; i++) lst[i] = -1; for (int i = 0; i < 26; i++) nxt[n][i] = -1; for (int i = n - 1; i >= 0; i--) { lst[s[i] - 'a'] = i + 1; for (int j = 0; j < 26; j++) { nxt[i][j] = lst[j]; } } ll ans = 0; ll cur = 0, idx = 0; for (int i = 0; i < m; i++) { if (nxt[idx][t[i] - 'a'] != -1) { idx = nxt[idx][t[i] - 'a']; } else { idx = 0; if (nxt[idx][t[i] - 'a'] == -1) { cout << "-1"; return 0; } else { cur++; idx = nxt[idx][t[i] - 'a']; } } } ans = cur * n + idx; cout << ans; return 0; }
[ "assignment.variable.change", "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change" ]
740,533
740,534
u711524482
cpp
p02937
/*-------enazuma11----------------*/ #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int, int> #define pll pair<long long, long long> #define all(v) v.begin(), v.end() #define inc(a, n) sort(a, a + n) #define dec(a, n) sort(a, a + n, greater<int>()) #define rep(i, a, b) for (i = a; i < b; i++) #define repr(i, a, b) for (i = a; i > b; i--) #define F first #define S second #define M 1000000007 #define sz(x) (int)x.size() /* int x[]={-1,-1,0,1,1,1,0,-1}; int y[]={0,1,1,1,0,-1,-1,-1}; */ /* int x[]={-1,0,1,0}; int y[]={0,1,0,-1}; */ const int N = 2e5 + 5; ll n, q; vector<ll> g[N]; int visited[N]; ll v[N]; void solve() { string s, t; cin >> s >> t; int l1 = s.size(); int l2 = t.size(); vector<ll> v[26]; ll in[26]; memset(in, 0, sizeof(in)); ll i, j; rep(i, 0, l1) { v[s[i] - 'a'].pb(i); } ll f = 0; rep(i, 0, l2) { if (v[t[i] - 'a'].size() == 0) { // cout<<t[i]-'a'<<" "; cout << -1; return; } } ll ans = 0, pre = -1; int curindex; rep(i, 0, l2) { ll cur = t[i] - 'a'; ll tmp = lower_bound(v[cur].begin(), v[cur].end(), pre + 1) - v[cur].begin(); if (tmp >= v[cur].size()) { tmp = v[cur][0]; } curindex = v[cur][tmp]; // curindex=v[cur][in[cur]]; if (curindex <= pre) { // ans-=pre+1; ans += l1; } pre = curindex; // cout<<pre<<" "; // cout<<t[i]<<" "<<curindex<<" "<<ans<<'\n'; } ans += curindex + 1; cout << ans << " "; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
/*-------enazuma11----------------*/ #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int, int> #define pll pair<long long, long long> #define all(v) v.begin(), v.end() #define inc(a, n) sort(a, a + n) #define dec(a, n) sort(a, a + n, greater<int>()) #define rep(i, a, b) for (i = a; i < b; i++) #define repr(i, a, b) for (i = a; i > b; i--) #define F first #define S second #define M 1000000007 #define sz(x) (int)x.size() /* int x[]={-1,-1,0,1,1,1,0,-1}; int y[]={0,1,1,1,0,-1,-1,-1}; */ /* int x[]={-1,0,1,0}; int y[]={0,1,0,-1}; */ const int N = 2e5 + 5; ll n, q; vector<ll> g[N]; int visited[N]; ll v[N]; void solve() { string s, t; cin >> s >> t; int l1 = s.size(); int l2 = t.size(); vector<ll> v[26]; ll in[26]; memset(in, 0, sizeof(in)); ll i, j; rep(i, 0, l1) { v[s[i] - 'a'].pb(i); } ll f = 0; rep(i, 0, l2) { if (v[t[i] - 'a'].size() == 0) { // cout<<t[i]-'a'<<" "; cout << -1; return; } } ll ans = 0, pre = -1; int curindex; rep(i, 0, l2) { ll cur = t[i] - 'a'; ll tmp = lower_bound(v[cur].begin(), v[cur].end(), pre + 1) - v[cur].begin(); if (tmp >= v[cur].size()) { tmp = 0; } curindex = v[cur][tmp]; // curindex=v[cur][in[cur]]; if (curindex <= pre) { // ans-=pre+1; ans += l1; } pre = curindex; // cout<<pre<<" "; // cout<<t[i]<<" "<<curindex<<" "<<ans<<'\n'; } ans += curindex + 1; cout << ans << " "; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
[]
740,537
740,538
u944248697
cpp
p02937
/*-------enazuma11----------------*/ #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int, int> #define pll pair<long long, long long> #define all(v) v.begin(), v.end() #define inc(a, n) sort(a, a + n) #define dec(a, n) sort(a, a + n, greater<int>()) #define rep(i, a, b) for (i = a; i < b; i++) #define repr(i, a, b) for (i = a; i > b; i--) #define F first #define S second #define M 1000000007 #define sz(x) (int)x.size() /* int x[]={-1,-1,0,1,1,1,0,-1}; int y[]={0,1,1,1,0,-1,-1,-1}; */ /* int x[]={-1,0,1,0}; int y[]={0,1,0,-1}; */ const int N = 2e5 + 5; ll n, q; vector<ll> g[N]; int visited[N]; ll v[N]; void solve() { string s, t; cin >> s >> t; int l1 = s.size(); int l2 = t.size(); vector<ll> v[26]; ll in[26]; memset(in, 0, sizeof(in)); ll i, j; rep(i, 0, l1) { v[s[i] - 'a'].pb(i); } ll f = 0; rep(i, 0, l2) { if (v[t[i] - 'a'].size() == 0) { // cout<<t[i]-'a'<<" "; cout << -1; return; } } ll ans = 0, pre = -1; ll c = 0; rep(i, 0, l2) { ll cur = t[i] - 'a'; ll tmp = upper_bound(v[cur].begin(), v[cur].end(), pre) - v[cur].begin(); if (tmp == v[cur].size()) { tmp = v[cur][0]; c++; } pre = v[cur][tmp]; } ans = c * l1 + pre + 1; cout << ans << " "; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
/*-------enazuma11----------------*/ #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<int, int> #define pll pair<long long, long long> #define all(v) v.begin(), v.end() #define inc(a, n) sort(a, a + n) #define dec(a, n) sort(a, a + n, greater<int>()) #define rep(i, a, b) for (i = a; i < b; i++) #define repr(i, a, b) for (i = a; i > b; i--) #define F first #define S second #define M 1000000007 #define sz(x) (int)x.size() /* int x[]={-1,-1,0,1,1,1,0,-1}; int y[]={0,1,1,1,0,-1,-1,-1}; */ /* int x[]={-1,0,1,0}; int y[]={0,1,0,-1}; */ const int N = 2e5 + 5; ll n, q; vector<ll> g[N]; int visited[N]; ll v[N]; void solve() { string s, t; cin >> s >> t; int l1 = s.size(); int l2 = t.size(); vector<ll> v[26]; ll in[26]; memset(in, 0, sizeof(in)); ll i, j; rep(i, 0, l1) { v[s[i] - 'a'].pb(i); } ll f = 0; rep(i, 0, l2) { if (v[t[i] - 'a'].size() == 0) { // cout<<t[i]-'a'<<" "; cout << -1; return; } } ll ans = 0, pre = -1; ll c = 0; rep(i, 0, l2) { ll cur = t[i] - 'a'; ll tmp = upper_bound(v[cur].begin(), v[cur].end(), pre) - v[cur].begin(); if (tmp == v[cur].size()) { tmp = 0; c++; } pre = v[cur][tmp]; } ans = c * l1 + pre + 1; cout << ans << " "; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
[]
740,539
740,540
u944248697
cpp
p02937
#include "bits/stdc++.h" #define REP(i, a, b) for (int i = (a); i <= (b); ++i) #define REV(i, a, b) for (int i = (a); i >= (b); --i) #define FORV(a, A) for (auto &a : A) using namespace std; using ll = long long; void Main() { string S, T; cin >> S >> T; int pos, previous_pos = -1; int xpos; int s_len = S.length(); ll ans = 0; FORV(t, T) { pos = S.find(t); if (pos == string::npos) { cout << -1 << endl; return; } if (pos <= previous_pos) { xpos = S.substr(previous_pos + 1, s_len).find(t); if (xpos == string::npos) ans += s_len; else pos = xpos; } ans += pos - previous_pos; previous_pos = pos; } cout << ans << endl; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); Main(); }
#include "bits/stdc++.h" #define REP(i, a, b) for (int i = (a); i <= (b); ++i) #define REV(i, a, b) for (int i = (a); i >= (b); --i) #define FORV(a, A) for (auto &a : A) using namespace std; using ll = long long; void Main() { string S, T; cin >> S >> T; int pos, previous_pos = -1; int xpos; int s_len = S.length(); ll ans = 0; FORV(t, T) { pos = S.find(t); if (pos == string::npos) { cout << -1 << endl; return; } if (pos <= previous_pos) { xpos = S.substr(previous_pos + 1, s_len).find(t); if (xpos == string::npos) ans += s_len; else pos = xpos + previous_pos + 1; } ans += pos - previous_pos; previous_pos = pos; } cout << ans << endl; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); Main(); }
[ "assignment.change" ]
740,544
740,545
u747184036
cpp
p02937
// https://atcoder.jp/contests/abc138/tasks/abc138_e #include <bits/stdc++.h> using namespace std; using ll = int64_t; #define FOR(i, a, b) for (int64_t i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) int main() { #if LOCAL & 01 std::ifstream in("./test/sample-1.in"); // input.txt std::cin.rdbuf(in.rdbuf()); #endif string s, t; cin >> s >> t; string ss = s + s; // sを連結 unordered_map<char, vector<ll>> chpos_tbl; // a-z REP(i, ss.size()) { //連結したやつで chpos_tbl[ss[i]].push_back(i); } ll ans = 0; ll idx = -1; ll multip = 0; for (auto c : t) { auto it = chpos_tbl.find(c); if (it == chpos_tbl.end()) { cout << -1 << endl; return 0; } auto nx = lower_bound(it->second.begin(), it->second.end(), idx); ans = multip * s.size() + *nx + 1; idx = *nx; if (*nx >= s.size()) { ++multip; idx -= s.size(); } } cout << ans << endl; return 0; }
// https://atcoder.jp/contests/abc138/tasks/abc138_e #include <bits/stdc++.h> using namespace std; using ll = int64_t; #define FOR(i, a, b) for (int64_t i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) int main() { #if LOCAL & 01 std::ifstream in("./test/sample-1.in"); // input.txt std::cin.rdbuf(in.rdbuf()); #endif string s, t; cin >> s >> t; string ss = s + s; // sを連結 unordered_map<char, vector<ll>> chpos_tbl; // a-z REP(i, ss.size()) { //連結したやつで chpos_tbl[ss[i]].push_back(i); } ll ans = 0; ll idx = -1; ll multip = 0; for (auto c : t) { auto it = chpos_tbl.find(c); if (it == chpos_tbl.end()) { cout << -1 << endl; return 0; } auto nx = upper_bound(it->second.begin(), it->second.end(), idx); ans = multip * s.size() + *nx + 1; idx = *nx; if (*nx >= s.size()) { ++multip; idx -= s.size(); } } cout << ans << endl; return 0; }
[ "identifier.change", "call.function.change" ]
740,548
740,549
u182321487
cpp
p02937
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <sstream> #include <string> #include <vector> using namespace std; using lint = long long; constexpr int MOD = 1000000007, INF = 1111111111; template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " "); 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 int main() { cin.tie(nullptr); ios::sync_with_stdio(false); vector<vector<int>> alpha(26); string s, t; cin >> s >> t; for (int i = 0; i < s.size(); i++) { alpha[s[i] - 'a'].emplace_back(i + 1); } DMP(alpha); int pre = 0; lint ans = 0; for (int i = 0; i < t.size(); i++) { int idx = t[i] - 'a'; if (alpha[idx].empty()) { cout << -1 << "\n"; return 0; } else if (lower_bound(alpha[idx].begin(), alpha[idx].end(), pre) == alpha[idx].end()) { ans += s.size() - pre; pre = alpha[idx][0]; ans += pre; } else { ans += *lower_bound(alpha[idx].begin(), alpha[idx].end(), pre) - pre; pre = *lower_bound(alpha[idx].begin(), alpha[idx].end(), pre); } } cout << ans << "\n"; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <sstream> #include <string> #include <vector> using namespace std; using lint = long long; constexpr int MOD = 1000000007, INF = 1111111111; template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " "); 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 int main() { cin.tie(nullptr); ios::sync_with_stdio(false); vector<vector<int>> alpha(26); string s, t; cin >> s >> t; for (int i = 0; i < s.size(); i++) { alpha[s[i] - 'a'].emplace_back(i + 1); } DMP(alpha); int pre = 0; lint ans = 0; for (int i = 0; i < t.size(); i++) { int idx = t[i] - 'a'; if (alpha[idx].empty()) { cout << -1 << "\n"; return 0; } else if (upper_bound(alpha[idx].begin(), alpha[idx].end(), pre) == alpha[idx].end()) { ans += s.size() - pre; pre = alpha[idx][0]; ans += pre; } else { ans += *upper_bound(alpha[idx].begin(), alpha[idx].end(), pre) - pre; pre = *upper_bound(alpha[idx].begin(), alpha[idx].end(), pre); } } cout << ans << "\n"; return 0; }
[ "identifier.change", "call.function.change", "control_flow.branch.if.condition.change", "assignment.value.change", "expression.operation.binary.change" ]
740,550
740,551
u532573979
cpp
p02937
#include <bits/stdc++.h> #define ll long long #define dl double #define pb push_back #define mp make_pair #define pll pair<long long, long long> #define vll vector<long long> #define all(a) (a).begin(), (a).end() #define F first #define S second #define sz(x) (long long)x.size() #define hell 1000000007 #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); using namespace std; int main() { string t, s; cin >> t >> s; ll f[26] = {0}; vector<ll> v[26]; for (ll i = 0; i < t.size(); i++) { v[t[i] - 'a'].push_back(i); } for (ll i = 0; i < s.size(); i++) { if (v[s[i] - 'a'].size() == 0) return cout << "-1", 0; } ll inx = 0; ll n = t.size(); // cout<<n<<endl; ll c = 0; for (ll i = 0; i < s.size(); i++) { ll c = inx - f[s[i] - 'a']; // cout<<"c "<<inx<<endl; ll x = lower_bound(all(v[s[i] - 'a']), c) - v[s[i] - 'a'].begin(); // cout<<"x "<<x<<" "<<v[s[i]-'a'].size()<<endl; if (x == v[s[i] - 'a'].size()) { for (ll j = 0; j < 26; j++) f[j] += n - 1; // cout<<"f[s[i]-'a'] "<<f[s[i]-'a']<<endl; inx = f[s[i] - 'a'] + v[s[i] - 'a'][0] + 1; // cout<<"inx1 "<<inx<<endl; } else { // cout<<"f[s[i]-'a'] "<<f[s[i]-'a']<<endl; inx = f[s[i] - 'a'] + v[s[i] - 'a'][x] + 1; // cout<<"inx2 "<<inx<<endl; } } cout << inx << endl; }
#include <bits/stdc++.h> #define ll long long #define dl double #define pb push_back #define mp make_pair #define pll pair<long long, long long> #define vll vector<long long> #define all(a) (a).begin(), (a).end() #define F first #define S second #define sz(x) (long long)x.size() #define hell 1000000007 #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); using namespace std; int main() { string t, s; cin >> t >> s; ll f[26] = {0}; vector<ll> v[26]; for (ll i = 0; i < t.size(); i++) { v[t[i] - 'a'].push_back(i); } for (ll i = 0; i < s.size(); i++) { if (v[s[i] - 'a'].size() == 0) return cout << "-1", 0; } ll inx = 0; ll n = t.size(); // cout<<n<<endl; ll c = 0; for (ll i = 0; i < s.size(); i++) { ll c = inx - f[s[i] - 'a']; // cout<<"c "<<inx<<endl; ll x = lower_bound(all(v[s[i] - 'a']), c) - v[s[i] - 'a'].begin(); // cout<<"x "<<x<<" "<<v[s[i]-'a'].size()<<endl; if (x == v[s[i] - 'a'].size()) { for (ll j = 0; j < 26; j++) f[j] += n; // cout<<"f[s[i]-'a'] "<<f[s[i]-'a']<<endl; inx = f[s[i] - 'a'] + v[s[i] - 'a'][0] + 1; // cout<<"inx1 "<<inx<<endl; } else { // cout<<"f[s[i]-'a'] "<<f[s[i]-'a']<<endl; inx = f[s[i] - 'a'] + v[s[i] - 'a'][x] + 1; // cout<<"inx2 "<<inx<<endl; } } cout << inx << endl; }
[ "expression.operation.binary.remove" ]
740,552
740,553
u006069211
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 dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; vector<vector<LL>> nextIndex(int k, const string &s) { int n = s.length(); vector<vector<LL>> ret(n + 1, vector<LL>(26, n)); for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < 26; j++) ret[i][j] = ret[i + 1][j]; ret[i][s[i] - 'a'] = i % k; } return ret; } int main() { string s, t; cin >> s >> t; vector<bool> a(26, false), b(26, false); for (int i = 0; i < s.length(); i++) { a[s[i] - 'a'] = true; } for (int i = 0; i < t.length(); i++) { b[t[i] - 'a'] = true; } for (int i = 0; i < 26; i++) { if (b[i] && !a[i]) { puts("-1"); return 0; } } int n = s.length(); auto p = nextIndex(n, s + s); LL ans = 1; LL pos = 0; for (int i = 0; i < t.length(); i++) { LL nx = p[pos][t[i] - 'a']; if (nx <= pos) { ans += n - (pos - nx); pos = nx; } else { ans += nx - pos; pos = nx; } } 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 dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; vector<vector<LL>> nextIndex(int k, const string &s) { int n = s.length(); vector<vector<LL>> ret(n + 1, vector<LL>(26, n)); for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < 26; j++) ret[i][j] = ret[i + 1][j]; ret[i][s[i] - 'a'] = (i + 1) % k; } return ret; } int main() { string s, t; cin >> s >> t; vector<bool> a(26, false), b(26, false); for (int i = 0; i < s.length(); i++) { a[s[i] - 'a'] = true; } for (int i = 0; i < t.length(); i++) { b[t[i] - 'a'] = true; } for (int i = 0; i < 26; i++) { if (b[i] && !a[i]) { puts("-1"); return 0; } } LL n = s.length(); auto p = nextIndex(n, s + s); LL ans = 0; LL pos = 0; for (int i = 0; i < t.length(); i++) { LL nx = p[pos][t[i] - 'a']; if (nx <= pos) { ans += n - (pos - nx); pos = nx; } else { ans += nx - pos; pos = nx; } } cout << ans << endl; return 0; }
[ "variable_declaration.type.change", "literal.number.change", "variable_declaration.value.change" ]
740,556
740,557
u640323045
cpp
p02937
#include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; vector<int> v[30], v1[30]; string s, s1; long long k = 0, ans = 0; void st(char c, int x) { int l = 0, r = v[c - 'a'].size(), w; while (r - l != 1) { w = (r + l) / 2; if (v[c - 'a'][w] < x) l = w; else if (v[c - 'a'][w] > x) r = w; else break; } w = (r + l) / 2; if (v[c - 'a'][w] > x) { ans += v[c - 'a'][w] - x; k = v[c - 'a'][w]; } else if (w == v[c - 'a'].size() - 1) { ans += s.size() - (x - v[c - 'a'][0]); k = v[c - 'a'][0]; } else { ans += (v[c - 'a'][w + 1] - x); k = v[c - 'a'][w + 1]; } return; } int main() { bool no = false; cin >> s >> s1; for (int i = 0; i < s.size(); i++) v[s[i] - 'a'].push_back(i); for (int i = 0; i < s1.size(); i++) v1[s1[i] - 'a'].push_back(i); for (int i = 0; i < s1.size(); i++) { if (v[s1[i] - 'a'].size() == 0) { no = true; break; } } if (no == true) cout << -1 << endl; else { for (int i = 0; i < s.size(); i++) if (s[i] == s1[0]) { k = i; ans += i + 1; } for (int i = 1; i < s1.size(); i++) st(s1[i], k); cout << ans << endl; } }
#include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; vector<int> v[30], v1[30]; string s, s1; long long k = 0, ans = 0; void st(char c, int x) { int l = 0, r = v[c - 'a'].size(), w; while (r - l != 1) { w = (r + l) / 2; if (v[c - 'a'][w] < x) l = w; else if (v[c - 'a'][w] > x) r = w; else break; } w = (r + l) / 2; if (v[c - 'a'][w] > x) { ans += v[c - 'a'][w] - x; k = v[c - 'a'][w]; } else if (w == v[c - 'a'].size() - 1) { ans += s.size() - (x - v[c - 'a'][0]); k = v[c - 'a'][0]; } else { ans += (v[c - 'a'][w + 1] - x); k = v[c - 'a'][w + 1]; } return; } int main() { bool no = false; cin >> s >> s1; for (int i = 0; i < s.size(); i++) v[s[i] - 'a'].push_back(i); for (int i = 0; i < s1.size(); i++) v1[s1[i] - 'a'].push_back(i); for (int i = 0; i < s1.size(); i++) { if (v[s1[i] - 'a'].size() == 0) { no = true; break; } } if (no == true) cout << -1 << endl; else { for (int i = 0; i < s.size(); i++) if (s[i] == s1[0]) { k = i; ans += i + 1; break; } for (int i = 1; i < s1.size(); i++) st(s1[i], k); cout << ans << endl; } }
[ "control_flow.break.add" ]
740,560
740,561
u019229278
cpp
p02937
#include <bits/stdc++.h> using namespace std; void solve() { string s, t; cin >> s >> t; vector<int> pos[26]; s += s; int n = s.size(); for (int i = 0; i < n; i++) { pos[s[i] - 'a'].push_back(i); } long ans = 0, now = -1; for (char c : t) { int x = c - 'a'; if (pos[x].empty()) { cout << -1 << endl; return; } int nxt = *lower_bound(pos[x].begin(), pos[x].end(), now); ans += nxt - now; if (nxt >= n / 2) nxt -= n / 2; now = nxt; } cout << ans << endl; } int main() { solve(); cerr << "努力不足ですね!" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { string s, t; cin >> s >> t; vector<int> pos[26]; s += s; int n = s.size(); for (int i = 0; i < n; i++) { pos[s[i] - 'a'].push_back(i); } long ans = 0, now = -1; for (char c : t) { int x = c - 'a'; if (pos[x].empty()) { cout << -1 << endl; return; } int nxt = *lower_bound(pos[x].begin(), pos[x].end(), now + 1); ans += nxt - now; if (nxt >= n / 2) { nxt -= n / 2; } now = nxt; } cout << ans << endl; } int main() { solve(); cerr << "努力不足ですね!" << endl; return 0; }
[ "assignment.change" ]
740,562
740,563
u344412812
cpp
p02937
#include <bits/stdc++.h> using namespace std; void solve() { string s, t; cin >> s >> t; vector<int> pos[26]; s += s; int n = s.size(); for (int i = 0; i < n; i++) { pos[s[i] - 'a'].push_back(i); } long ans = 0, now = -1; for (char c : t) { int x = c - 'a'; if (pos[x].empty()) { cout << -1 << endl; return; } int nxt = *lower_bound(pos[x].begin(), pos[x].end(), now); ans += nxt - now; if (nxt > n / 2) nxt -= n / 2; now = nxt; } cout << ans << endl; } int main() { solve(); cerr << "努力不足ですね!" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { string s, t; cin >> s >> t; vector<int> pos[26]; s += s; int n = s.size(); for (int i = 0; i < n; i++) { pos[s[i] - 'a'].push_back(i); } long ans = 0, now = -1; for (char c : t) { int x = c - 'a'; if (pos[x].empty()) { cout << -1 << endl; return; } int nxt = *lower_bound(pos[x].begin(), pos[x].end(), now + 1); ans += nxt - now; if (nxt >= n / 2) { nxt -= n / 2; } now = nxt; } cout << ans << endl; } int main() { solve(); cerr << "努力不足ですね!" << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,564
740,563
u344412812
cpp
p02937
#include <algorithm> #include <bitset> //#include <boost/multiprecision/cpp_int.hpp> #include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <sstream> #include <stdio.h> #include <string> #include <tuple> #include <vector> // namespace mp = boost::multiprecision; using namespace std; using ull = unsigned long long; using ld = long double; // using ll = boost::multiprecision::cpp_int; using ll = long long; #define FOR(i, N) for (ll i = 0; i < N; ++i) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() // using int = ll; ll gcd(ll m, ll n) { if (n == 0) return abs(m); return (gcd(n, m % n)); } void putYN(bool b) { if (b) { cout << "Yes" << endl; } else { cout << "No" << endl; } } void swap(ll &a, ll &b) { ll tmp = a; a = b; b = tmp; } ll combi(ll n, ll k) { ll r = 1, rr = 1; for (ll i = 0; i < k; ++i) { r *= (n - i); rr *= (i + 1); // r %= 1000000007; // rr %= 1000000007; } r /= rr; // r %= 1000000007; return r; } int main() { string s, t; cin >> s >> t; map<char, vector<ll>> nummap; FOR(i, s.size()) { ; if (nummap.find(s[i]) == nummap.end()) { nummap[s[i]] = vector<ll>(); } auto itr = lower_bound(nummap[s[i]].begin(), nummap[s[i]].end(), i); nummap[s[i]].insert(itr, i); } /*for(auto a : nummap) { sort(a.second.begin(), a.second.end()); }*/ FOR(i, t.size()) { if (nummap.find(t[i]) == nummap.end()) { cout << -1 << endl; return 0; } } ll min_ = LLONG_MAX; // for(ll ii = 0; ii < nummap[t[t.size() - 1]].size(); ++ii) { { ll re = 0; // ll num = nummap[t[t.size() - 1]][ii]; ll num = -1; for (ll i = 0; i < t.size(); ++i) { vector<ll> v = nummap[t[i]]; auto numi = lower_bound(v.begin(), v.end(), num); // cout << *(numi - 1) << " " << num << endl; if (numi == v.end()) { re++; num = v[0]; } else { num = *(numi); } } ll m = re * s.size() + num + 1; if (m < min_) min_ = m; } cout << min_ << endl; return 0; }
#include <algorithm> #include <bitset> //#include <boost/multiprecision/cpp_int.hpp> #include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <sstream> #include <stdio.h> #include <string> #include <tuple> #include <vector> // namespace mp = boost::multiprecision; using namespace std; using ull = unsigned long long; using ld = long double; // using ll = boost::multiprecision::cpp_int; using ll = long long; #define FOR(i, N) for (ll i = 0; i < N; ++i) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() // using int = ll; ll gcd(ll m, ll n) { if (n == 0) return abs(m); return (gcd(n, m % n)); } void putYN(bool b) { if (b) { cout << "Yes" << endl; } else { cout << "No" << endl; } } void swap(ll &a, ll &b) { ll tmp = a; a = b; b = tmp; } ll combi(ll n, ll k) { ll r = 1, rr = 1; for (ll i = 0; i < k; ++i) { r *= (n - i); rr *= (i + 1); // r %= 1000000007; // rr %= 1000000007; } r /= rr; // r %= 1000000007; return r; } int main() { string s, t; cin >> s >> t; map<char, vector<ll>> nummap; FOR(i, s.size()) { ; if (nummap.find(s[i]) == nummap.end()) { nummap[s[i]] = vector<ll>(); } auto itr = lower_bound(nummap[s[i]].begin(), nummap[s[i]].end(), i); nummap[s[i]].insert(itr, i); } /*for(auto a : nummap) { sort(a.second.begin(), a.second.end()); }*/ FOR(i, t.size()) { if (nummap.find(t[i]) == nummap.end()) { cout << -1 << endl; return 0; } } ll min_ = LLONG_MAX; // for(ll ii = 0; ii < nummap[t[t.size() - 1]].size(); ++ii) { { ll re = 0; // ll num = nummap[t[t.size() - 1]][ii]; ll num = -1; for (ll i = 0; i < t.size(); ++i) { vector<ll> &v = nummap[t[i]]; auto numi = lower_bound(v.begin(), v.end(), num + 1); // cout << *(numi - 1) << " " << num << endl; if (numi == v.end()) { re++; num = v[0]; } else { // cout << num << *(numi)<<endl; num = *(numi); } } ll m = re * s.size() + num + 1; if (m < min_) min_ = m; } cout << min_ << endl; return 0; }
[ "assignment.change" ]
740,573
740,574
u373586461
cpp
p02937
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define rep(i, j, n) for (int i = j; i < n; i++) #define out(ans) cout << ans << endl; const long long mod = 1e9 + 7; int main() { string s, t; cin >> s >> t; ll sn = s.size(), tn = t.size(); vector<ll> v[26]; rep(i, 0, sn) { v[s[i] - 'a'].push_back(i + 1); } ll count = 0; ll k = 0; for (ll i = 0; i < tn; i++) { char c = t[i]; ll a = c - 'a'; if (v[a].size() == 0) { out(-1); return 0; } vector<ll>::iterator it = lower_bound(v[a].begin(), v[a].end(), k); if (it == v[a].end()) { it = v[a].begin(); count++; } k = *it; } out(count * sn + k); return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define rep(i, j, n) for (int i = j; i < n; i++) #define out(ans) cout << ans << endl; const long long mod = 1e9 + 7; int main() { string s, t; cin >> s >> t; ll sn = s.size(), tn = t.size(); vector<ll> v[26]; rep(i, 0, sn) { v[s[i] - 'a'].push_back(i + 1); } ll count = 0; ll k = 0; for (ll i = 0; i < tn; i++) { char c = t[i]; ll a = c - 'a'; if (v[a].size() == 0) { out(-1); return 0; } vector<ll>::iterator it = upper_bound(v[a].begin(), v[a].end(), k); if (it == v[a].end()) { it = v[a].begin(); count++; } k = *it; } out(count * sn + k); return 0; }
[ "identifier.change", "call.function.change" ]
740,577
740,578
u139458416
cpp
p02937
#include <iostream> #include <string> using namespace std; string s, t; long long m; long long p[100000]; int main() { cin >> s >> t; long long w = s.size(); s = s + s; for (int i = 0; i < t.size(); i++) { if (s.find_first_of(t[i]) == std::string::npos) { m = -1; break; } else { if (i == 0) { p[0] = s.find_first_of(t[0]); m = p[0] + 1; } else { long long u = s.find_first_of(t[i], p[i - 1]); p[i] = u % w; m += u - p[i - 1]; } } } cout << m << endl; return 0; }
#include <iostream> #include <string> using namespace std; string s, t; long long m; long long p[100000]; int main() { cin >> s >> t; long long w = s.size(); s = s + s; for (int i = 0; i < t.size(); i++) { if (s.find_first_of(t[i]) == std::string::npos) { m = -1; break; } else { if (i == 0) { p[0] = s.find_first_of(t[0]); m = p[0] + 1; } else { long long u = s.find_first_of(t[i], p[i - 1] + 1); p[i] = u % w; m += u - p[i - 1]; } } } cout << m << endl; return 0; }
[ "assignment.change" ]
740,585
740,586
u597243424
cpp
p02937
//#include<bits/stdc++.h> #pragma GCC optimize(2) #pragma G++ optimize(2) #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef long double ld; #define pa pair<int, int> #define sc(n) scanf("%d", &n) #define ss(s) scanf("%s", s) #define fo(i, a, b) for (int i = a; i <= b; i++) #define of(i, a, b) for (int i = a; i >= b; i--) #define mem(a, b) memset(a, b, sizeof a) #define uint unsigned int const int N = 2e5 + 10; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; int n; int a[N]; string s, t; unordered_map<char, int> mp; int minn[150]; set<int> v[150]; int main() { ios::sync_with_stdio(false); cin >> s >> t; mem(minn, -1); for (int i = 0; s[i]; i++) { mp[s[i]] = 1; if (minn[s[i]] == -1) { minn[s[i]] = i; v[s[i]].insert(inf); } v[s[i]].insert(i); } for (auto i : t) if (!mp[i]) { puts("-1"); return 0; } int len = t.size(); if (len == 1) { cout << minn[t[0]] + 1 << endl; } else { int mi = minn[t[0]]; ll ans = 0; ll size = s.size(); int flag = 0; for (int i = 1; t[i]; i++) { flag = 0; int tp = *(v[t[i]].upper_bound(mi)); if (tp != inf) { flag = 1; mi = tp; } if (!flag) { ans += size; mi = minn[t[i]]; } } if (flag) ans += mi; cout << ans + 1 << endl; } return 0; }
//#include<bits/stdc++.h> #pragma GCC optimize(2) #pragma G++ optimize(2) #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef long double ld; #define pa pair<int, int> #define sc(n) scanf("%d", &n) #define ss(s) scanf("%s", s) #define fo(i, a, b) for (int i = a; i <= b; i++) #define of(i, a, b) for (int i = a; i >= b; i--) #define mem(a, b) memset(a, b, sizeof a) #define uint unsigned int const int N = 2e5 + 10; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; int n; int a[N]; string s, t; unordered_map<char, int> mp; int minn[150]; set<int> v[150]; int main() { ios::sync_with_stdio(false); cin >> s >> t; mem(minn, -1); for (int i = 0; s[i]; i++) { mp[s[i]] = 1; if (minn[s[i]] == -1) { minn[s[i]] = i; v[s[i]].insert(inf); } v[s[i]].insert(i); } for (auto i : t) if (!mp[i]) { puts("-1"); return 0; } int len = t.size(); if (len == 1) { cout << minn[t[0]] + 1 << endl; } else { int mi = minn[t[0]]; ll ans = 0; ll size = s.size(); int flag = 0; for (int i = 1; t[i]; i++) { flag = 0; int tp = *(v[t[i]].upper_bound(mi)); if (tp != inf) { flag = 1; mi = tp; } if (!flag) { ans += size; mi = minn[t[i]]; } } ans += mi; cout << ans + 1 << endl; } return 0; }
[]
740,587
740,588
u980074233
cpp
p02937
//#include<bits/stdc++.h> #pragma GCC optimize(2) #pragma G++ optimize(2) #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef long double ld; #define pa pair<int, int> #define sc(n) scanf("%d", &n) #define ss(s) scanf("%s", s) #define fo(i, a, b) for (int i = a; i <= b; i++) #define of(i, a, b) for (int i = a; i >= b; i--) #define mem(a, b) memset(a, b, sizeof a) #define uint unsigned int const int N = 2e5 + 10; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; int n; int a[N]; string s, t; unordered_map<char, int> mp; int minn[150]; set<int> v[150]; int main() { ios::sync_with_stdio(false); cin >> s >> t; mem(minn, -1); for (int i = 0; s[i]; i++) { mp[s[i]] = 1; if (minn[s[i]] == -1) { minn[s[i]] = i; v[s[i]].insert(inf); } v[s[i]].insert(i); } for (auto i : t) if (!mp[i]) { puts("-1"); return 0; } int len = t.size(); if (len == 1) { cout << minn[t[0]] + 1 << endl; } else { int mi = minn[t[0]]; ll ans = 0; ll size = s.size(); int flag = 0; for (int i = 1; t[i]; i++) { flag = 0; int tp = *(v[t[i]].lower_bound(mi)); if (tp != inf) { flag = 1; mi = tp; } if (!flag) { ans += size; mi = minn[t[i]]; } } if (flag) ans += mi; cout << ans + 1 << endl; } return 0; }
//#include<bits/stdc++.h> #pragma GCC optimize(2) #pragma G++ optimize(2) #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef long double ld; #define pa pair<int, int> #define sc(n) scanf("%d", &n) #define ss(s) scanf("%s", s) #define fo(i, a, b) for (int i = a; i <= b; i++) #define of(i, a, b) for (int i = a; i >= b; i--) #define mem(a, b) memset(a, b, sizeof a) #define uint unsigned int const int N = 2e5 + 10; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; int n; int a[N]; string s, t; unordered_map<char, int> mp; int minn[150]; set<int> v[150]; int main() { ios::sync_with_stdio(false); cin >> s >> t; mem(minn, -1); for (int i = 0; s[i]; i++) { mp[s[i]] = 1; if (minn[s[i]] == -1) { minn[s[i]] = i; v[s[i]].insert(inf); } v[s[i]].insert(i); } for (auto i : t) if (!mp[i]) { puts("-1"); return 0; } int len = t.size(); if (len == 1) { cout << minn[t[0]] + 1 << endl; } else { int mi = minn[t[0]]; ll ans = 0; ll size = s.size(); int flag = 0; for (int i = 1; t[i]; i++) { flag = 0; int tp = *(v[t[i]].upper_bound(mi)); if (tp != inf) { flag = 1; mi = tp; } if (!flag) { ans += size; mi = minn[t[i]]; } } ans += mi; cout << ans + 1 << endl; } return 0; }
[ "call.function.change" ]
740,589
740,588
u980074233
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; /* short */ #define pb push_back #define mp make_pair #define Fi first #define Se second #define ALL(v) begin(v), end(v) #define RALL(v) rbegin(v), rend(v) /* REPmacro */ #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define FOREACH(x, a) for (auto x : a) /* function */ #define IN(x) cin >> x #define DEBUG(x) cerr << (x) << " " #define LN() cerr << "\n" #define PRINT(x) cout << (x) << endl #define BR cout << endl /* const */ const int ARRAY = 100005; const int INF = 1001001001; // 10^9 const ll LINF = 1001001001001001001; // 10^18 const int MOD = 1e9 + 7; ll N = 0; string s; string t; ll ret = 0; vector<ll> table[26]; ll findIndex(ll i, ll c) { if (table[c].size() == 0) { return -1; } else { auto itr = upper_bound(ALL(table[c]), i); if (itr == table[c].end()) { return table[c][0]; } else { return *itr; } } } void input() { IN(s); IN(t); N = s.size(); } void solve() { ll c; REP(i, N) { c = s[i] - 'a'; table[c].pb(i + 1); } ll p = N; ll next; REP(i, t.size()) { c = t[i] - 'a'; next = findIndex(p, c); if (p == -1) { ret = -1; break; } if (next > p) { ret += next - p; } else { ret += N - p + next; } p = next; } PRINT(ret); } int main(void) { input(); solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; /* short */ #define pb push_back #define mp make_pair #define Fi first #define Se second #define ALL(v) begin(v), end(v) #define RALL(v) rbegin(v), rend(v) /* REPmacro */ #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define FOREACH(x, a) for (auto x : a) /* function */ #define IN(x) cin >> x #define DEBUG(x) cerr << (x) << " " #define LN() cerr << "\n" #define PRINT(x) cout << (x) << endl #define BR cout << endl /* const */ const int ARRAY = 100005; const int INF = 1001001001; // 10^9 const ll LINF = 1001001001001001001; // 10^18 const int MOD = 1e9 + 7; ll N = 0; string s; string t; ll ret = 0; vector<ll> table[26]; ll findIndex(ll i, ll c) { if (table[c].empty()) { return -1; } else { auto itr = upper_bound(ALL(table[c]), i); if (itr == table[c].end()) { return table[c][0]; } else { return *itr; } } } void input() { IN(s); IN(t); N = s.size(); } void solve() { ll c; REP(i, N) { c = s[i] - 'a'; table[c].pb(i + 1); } ll p = N; ll next; REP(i, t.size()) { c = t[i] - 'a'; next = findIndex(p, c); if (next == -1) { ret = -1; break; } if (next > p) { ret += next - p; } else { ret += N - p + next; } p = next; } PRINT(ret); } int main(void) { input(); solve(); }
[ "call.function.change", "control_flow.branch.if.condition.change", "expression.operation.binary.remove", "identifier.change" ]
740,594
740,595
u790171360
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; /* short */ #define pb push_back #define mp make_pair #define Fi first #define Se second #define ALL(v) begin(v), end(v) #define RALL(v) rbegin(v), rend(v) /* REPmacro */ #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define FOREACH(x, a) for (auto x : a) /* function */ #define IN(x) cin >> x #define DEBUG(x) cerr << (x) << " " #define LN() cerr << "\n" #define PRINT(x) cout << (x) << endl #define BR cout << endl /* const */ const int ARRAY = 100005; const int INF = 1001001001; // 10^9 const ll LINF = 1001001001001001001; // 10^18 const int MOD = 1e9 + 7; ll N = 0; string s; string t; ll ret = 0; vector<ll> table[27]; ll findIndex(ll i, ll c) { if (table[c].size() == 0) { return -1; } else { auto itr = upper_bound(ALL(table[c]), i); if (itr == table[c].end()) { return table[c][0]; } else { return *itr; } } } void input() { IN(s); IN(t); N = s.size(); } void solve() { ll c; REP(i, N) { c = s[i] - 'a'; table[c].pb(i + 1); } ll p = N; ll next; REP(i, t.size()) { c = t[i] - 'a'; next = findIndex(p, c); if (p == -1) { ret = -1; break; } if (next > p) { ret += next - p; } else { ret += N - p + next; } p = next; } PRINT(ret); } int main(void) { input(); solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; /* short */ #define pb push_back #define mp make_pair #define Fi first #define Se second #define ALL(v) begin(v), end(v) #define RALL(v) rbegin(v), rend(v) /* REPmacro */ #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define FOREACH(x, a) for (auto x : a) /* function */ #define IN(x) cin >> x #define DEBUG(x) cerr << (x) << " " #define LN() cerr << "\n" #define PRINT(x) cout << (x) << endl #define BR cout << endl /* const */ const int ARRAY = 100005; const int INF = 1001001001; // 10^9 const ll LINF = 1001001001001001001; // 10^18 const int MOD = 1e9 + 7; ll N = 0; string s; string t; ll ret = 0; vector<ll> table[26]; ll findIndex(ll i, ll c) { if (table[c].empty()) { return -1; } else { auto itr = upper_bound(ALL(table[c]), i); if (itr == table[c].end()) { return table[c][0]; } else { return *itr; } } } void input() { IN(s); IN(t); N = s.size(); } void solve() { ll c; REP(i, N) { c = s[i] - 'a'; table[c].pb(i + 1); } ll p = N; ll next; REP(i, t.size()) { c = t[i] - 'a'; next = findIndex(p, c); if (next == -1) { ret = -1; break; } if (next > p) { ret += next - p; } else { ret += N - p + next; } p = next; } PRINT(ret); } int main(void) { input(); solve(); }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "call.function.change", "control_flow.branch.if.condition.change", "expression.operation.binary.remove", "identifier.change" ]
740,596
740,595
u790171360
cpp
p02937
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; string s, t; int A[26][100000]; int main() { cin >> s >> t; const int N = s.size(); for (int k = 0; k < 26; ++k) { for (int i = 0; i < N; ++i) { if (s[i] == 'a' + k) { A[k][i] = 0; } else { A[k][i] = INF; } } } for (int k = 0; k < 26; ++k) { for (int i = 2 * N; i >= 0; --i) { A[k][i % N] = min(A[k][i % N], A[k][(i + 1) % N] + 1); } } long sum = 1; for (char c : t) { ++sum; int i = sum % N; if (A[c - 'a'][i] == INF) { cout << -1 << endl; return 0; } sum += A[c - 'a'][i]; } cout << sum + 1 << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; string s, t; int A[26][100000]; int main() { cin >> s >> t; const int N = s.size(); for (int k = 0; k < 26; ++k) { for (int i = 0; i < N; ++i) { if (s[i] == 'a' + k) { A[k][i] = 0; } else { A[k][i] = INF; } } } for (int k = 0; k < 26; ++k) { for (int i = 2 * N; i >= 0; --i) { A[k][i % N] = min(A[k][i % N], A[k][(i + 1) % N] + 1); } } long sum = -1; for (char c : t) { ++sum; int i = sum % N; if (A[c - 'a'][i] == INF) { cout << -1 << endl; return 0; } sum += A[c - 'a'][i]; } cout << sum + 1 << endl; }
[ "expression.operation.unary.arithmetic.add" ]
740,599
740,600
u993619636
cpp
p02937
#include <algorithm> #include <fstream> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <string.h> #include <string> #include <vector> using namespace std; long long int euclidean_gcd(long long int a, long long int b) { if (a < b) return euclidean_gcd(b, a); long long int r; while ((r = a % b)) { a = b; b = r; } return b; } int main() { string s, t; cin >> s >> t; vector<vector<int>> A(26); for (int i = 0; i < s.size(); i++) A[s[i] - 'a'].push_back(i); long long int a = 0, ans = 0; bool flag = true; for (int i = 0; i < t.size();) { int k = t[i] - 'a'; if (A[k].size() == 0) { flag = false; break; } if (i == 0) { ans = A[k][0]; i++; } else { if (A[k][A[k].size() - 1] < ans) { ans = A[k][0]; i++; a++; } else { auto it = std::lower_bound(A[k].begin(), A[k].end(), ans); ans = *it; i++; } } } if (flag) cout << 1 + ans + a * s.size(); else cout << -1; }
#include <algorithm> #include <fstream> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <string.h> #include <string> #include <vector> using namespace std; long long int euclidean_gcd(long long int a, long long int b) { if (a < b) return euclidean_gcd(b, a); long long int r; while ((r = a % b)) { a = b; b = r; } return b; } int main() { string s, t; cin >> s >> t; vector<vector<int>> A(26); for (int i = 0; i < s.size(); i++) A[s[i] - 'a'].push_back(i); long long int a = 0, ans = 0; bool flag = true; for (int i = 0; i < t.size();) { int k = t[i] - 'a'; if (A[k].size() == 0) { flag = false; break; } if (i == 0) { ans = A[k][0]; i++; } else { if (A[k][A[k].size() - 1] <= ans) { ans = A[k][0]; i++; a++; } else { auto it = std::upper_bound(A[k].begin(), A[k].end(), ans); ans = *it; i++; } } } if (flag) cout << 1 + ans + a * s.size(); else cout << -1; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "identifier.change" ]
740,607
740,608
u444349080
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (ll(i) = (0); (i) < (n); ++i) #define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v, n) \ { \ REP(WW, n) cerr << v[WW] << ' '; \ cerr << endl << endl; \ } #define SHOW2d(v, WW, HH) \ { \ REP(W_, WW) { \ REP(H_, HH) cerr << v[W_][H_] << ' '; \ cerr << endl; \ } \ cerr << endl; \ } #define ALL(v) v.begin(), v.end() #define Decimal fixed << setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 998244353 typedef long long ll; typedef pair<ll, ll> P; ll nxt[111111][33]; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; vector<ll> tmp(33, LLINF); REP(seica, 2) REV(i, s.size()) { REP(j, 33) { nxt[i][j] = tmp[j]; } tmp[s[i] - 'a'] = i; } ll ans = tmp[t[0] - 'a']; ll now = ans; if (ans == LLINF) { cout << -1 << endl; return 0; } REP(i, t.size() - 1) { ll tsugi = nxt[now][t[i + 1] - 'a']; if (tsugi == LLINF) { cout << -1 << endl; return 0; } ans += (tsugi - now) + (tsugi < now) * (ll)s.size(); now = tsugi; } cout << ans + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (ll(i) = (0); (i) < (n); ++i) #define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v, n) \ { \ REP(WW, n) cerr << v[WW] << ' '; \ cerr << endl << endl; \ } #define SHOW2d(v, WW, HH) \ { \ REP(W_, WW) { \ REP(H_, HH) cerr << v[W_][H_] << ' '; \ cerr << endl; \ } \ cerr << endl; \ } #define ALL(v) v.begin(), v.end() #define Decimal fixed << setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 998244353 typedef long long ll; typedef pair<ll, ll> P; ll nxt[111111][33]; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; vector<ll> tmp(33, LLINF); REP(seica, 2) REV(i, s.size()) { REP(j, 33) { nxt[i][j] = tmp[j]; } tmp[s[i] - 'a'] = i; } ll ans = tmp[t[0] - 'a']; ll now = ans; if (ans == LLINF) { cout << -1 << endl; return 0; } REP(i, t.size() - 1) { ll tsugi = nxt[now][t[i + 1] - 'a']; if (tsugi == LLINF) { cout << -1 << endl; return 0; } ans += (tsugi - now) + (tsugi <= now) * (ll)s.size(); now = tsugi; } cout << ans + 1 << endl; return 0; }
[ "expression.operator.compare.change", "assignment.value.change", "expression.operation.binary.change" ]
740,638
740,639
u382880969
cpp
p02937
#include <bits/stdc++.h> // include all standard C++ libraries using namespace std; // Loops #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define _rrep(i, n) rrepi(i, n, 0) #define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(xi, x) for (auto &&xi : x) // Note: we can use rep(i,N) or rep(i,from,to) // typedef using ll = long long; template <class T> using vec = vector<T>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; // Constants // Shorter repr for frequently used terms #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second // Algorithms #define all(x) (x).begin(), (x).end() #define uniq(v) v.erase(unique(all(v)), v.end()) #define perm(c) \ sort(all(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(all(c))) template <class T> pair<T, size_t> max(vector<T> &x) { auto it = max_element(all(x)); return mp(*it, it - x.begin()); } template <class T> pair<T, size_t> min(vector<T> &x) { auto it = min_element(all(x)); return mp(*it, it - x.begin()); } template <class T> inline bool chmax(T &maxval, const T &newval) { if (maxval < newval) { maxval = newval; return 1; } return 0; } template <class T> inline bool chmin(T &minval, const T &newval) { if (minval > newval) { minval = newval; return 1; } return 0; } // Utilities // Grid world utilities int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; #define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H) inline int in() { int x; cin >> x; return x; } // read int from cin inline ll IN() { ll x; cin >> x; return x; } // read ll from cin // Debug #ifdef LOCAL #include "dump.hpp" #define debug(x) cerr << #x << ": " << x << '\n' #else #define dump(...) #define debug(x) #endif // Paste snippets here!! // int main() { cin.tie(0); ios::sync_with_stdio(false); // Magic for faster cin unordered_set<char> buf; string s, t; cin >> s >> t; for (int i = 0; i < s.size(); ++i) { buf.insert(s[i]); } for (char ti : t) { if (buf.find(ti) == buf.end()) { cout << -1 << endl; return 0; } } vector<vector<ll>> pos(256); rep(i, s.size()) pos[s[i]].push_back(i); rep(i, 256) sort(all(pos[i])); ll ans = 0; ll curpos = -1; for (char ti : t) { // auto it = lower_bound(all(pos[ti]), curpos); auto it = upper_bound(all(pos[ti]), curpos); if (it == pos[ti].end()) { ans += s.size() - curpos + pos[ti][0]; curpos = pos[ti][0]; // nback++; curpos = 0; it = upper_bound(all(pos[ti]), curpos); } else { ans += *it - curpos; curpos = *it; } } cout << ans + 1 << endl; return 0; }
#include <bits/stdc++.h> // include all standard C++ libraries using namespace std; // Loops #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define _rrep(i, n) rrepi(i, n, 0) #define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(xi, x) for (auto &&xi : x) // Note: we can use rep(i,N) or rep(i,from,to) // typedef using ll = long long; template <class T> using vec = vector<T>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; // Constants // Shorter repr for frequently used terms #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second // Algorithms #define all(x) (x).begin(), (x).end() #define uniq(v) v.erase(unique(all(v)), v.end()) #define perm(c) \ sort(all(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(all(c))) template <class T> pair<T, size_t> max(vector<T> &x) { auto it = max_element(all(x)); return mp(*it, it - x.begin()); } template <class T> pair<T, size_t> min(vector<T> &x) { auto it = min_element(all(x)); return mp(*it, it - x.begin()); } template <class T> inline bool chmax(T &maxval, const T &newval) { if (maxval < newval) { maxval = newval; return 1; } return 0; } template <class T> inline bool chmin(T &minval, const T &newval) { if (minval > newval) { minval = newval; return 1; } return 0; } // Utilities // Grid world utilities int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; #define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H) inline int in() { int x; cin >> x; return x; } // read int from cin inline ll IN() { ll x; cin >> x; return x; } // read ll from cin // Debug #ifdef LOCAL #include "dump.hpp" #define debug(x) cerr << #x << ": " << x << '\n' #else #define dump(...) #define debug(x) #endif // Paste snippets here!! // int main() { cin.tie(0); ios::sync_with_stdio(false); // Magic for faster cin unordered_set<char> buf; string s, t; cin >> s >> t; for (int i = 0; i < s.size(); ++i) { buf.insert(s[i]); } for (char ti : t) { if (buf.find(ti) == buf.end()) { cout << -1 << endl; return 0; } } vector<vector<ll>> pos(256); rep(i, s.size()) pos[s[i]].push_back(i); rep(i, 256) sort(all(pos[i])); ll ans = 0; ll curpos = -1; for (char ti : t) { // auto it = lower_bound(all(pos[ti]), curpos); auto it = upper_bound(all(pos[ti]), curpos); if (it == pos[ti].end()) { ans += s.size() - curpos + pos[ti][0]; curpos = pos[ti][0]; // nback++; curpos = 0; it = upper_bound(all(pos[ti]), curpos); } else { ans += *it - curpos; curpos = *it; } } cout << ans << endl; return 0; }
[ "expression.operation.binary.remove" ]
740,640
740,641
u292813062
cpp
p02937
#include <bits/stdc++.h> // include all standard C++ libraries using namespace std; // Loops #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define _rrep(i, n) rrepi(i, n, 0) #define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(xi, x) for (auto &&xi : x) // Note: we can use rep(i,N) or rep(i,from,to) // typedef using ll = long long; template <class T> using vec = vector<T>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; // Constants // Shorter repr for frequently used terms #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second // Algorithms #define all(x) (x).begin(), (x).end() #define uniq(v) v.erase(unique(all(v)), v.end()) #define perm(c) \ sort(all(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(all(c))) template <class T> pair<T, size_t> max(vector<T> &x) { auto it = max_element(all(x)); return mp(*it, it - x.begin()); } template <class T> pair<T, size_t> min(vector<T> &x) { auto it = min_element(all(x)); return mp(*it, it - x.begin()); } template <class T> inline bool chmax(T &maxval, const T &newval) { if (maxval < newval) { maxval = newval; return 1; } return 0; } template <class T> inline bool chmin(T &minval, const T &newval) { if (minval > newval) { minval = newval; return 1; } return 0; } // Utilities // Grid world utilities int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; #define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H) inline int in() { int x; cin >> x; return x; } // read int from cin inline ll IN() { ll x; cin >> x; return x; } // read ll from cin // Debug #ifdef LOCAL #include "dump.hpp" #define debug(x) cerr << #x << ": " << x << '\n' #else #define dump(...) #define debug(x) #endif // Paste snippets here!! // int main() { cin.tie(0); ios::sync_with_stdio(false); // Magic for faster cin unordered_set<char> buf; string s, t; cin >> s >> t; for (int i = 0; i < s.size(); ++i) { buf.insert(s[i]); } for (char ti : t) { if (buf.find(ti) == buf.end()) { cout << -1 << endl; return 0; } } vector<vector<ll>> pos(256); rep(i, s.size()) pos[s[i]].push_back(i); rep(i, 256) sort(all(pos[i])); ll ans = 0; ll curpos = 0; for (char ti : t) { // auto it = lower_bound(all(pos[ti]), curpos); auto it = upper_bound(all(pos[ti]), curpos); if (it == pos[ti].end()) { ans += s.size() - curpos + pos[ti][0]; curpos = pos[ti][0]; // nback++; curpos = 0; it = upper_bound(all(pos[ti]), curpos); } else { ans += *it - curpos; curpos = *it; } } cout << ans + 1 << endl; return 0; }
#include <bits/stdc++.h> // include all standard C++ libraries using namespace std; // Loops #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define _rrep(i, n) rrepi(i, n, 0) #define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(xi, x) for (auto &&xi : x) // Note: we can use rep(i,N) or rep(i,from,to) // typedef using ll = long long; template <class T> using vec = vector<T>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; // Constants // Shorter repr for frequently used terms #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second // Algorithms #define all(x) (x).begin(), (x).end() #define uniq(v) v.erase(unique(all(v)), v.end()) #define perm(c) \ sort(all(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(all(c))) template <class T> pair<T, size_t> max(vector<T> &x) { auto it = max_element(all(x)); return mp(*it, it - x.begin()); } template <class T> pair<T, size_t> min(vector<T> &x) { auto it = min_element(all(x)); return mp(*it, it - x.begin()); } template <class T> inline bool chmax(T &maxval, const T &newval) { if (maxval < newval) { maxval = newval; return 1; } return 0; } template <class T> inline bool chmin(T &minval, const T &newval) { if (minval > newval) { minval = newval; return 1; } return 0; } // Utilities // Grid world utilities int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; #define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H) inline int in() { int x; cin >> x; return x; } // read int from cin inline ll IN() { ll x; cin >> x; return x; } // read ll from cin // Debug #ifdef LOCAL #include "dump.hpp" #define debug(x) cerr << #x << ": " << x << '\n' #else #define dump(...) #define debug(x) #endif // Paste snippets here!! // int main() { cin.tie(0); ios::sync_with_stdio(false); // Magic for faster cin unordered_set<char> buf; string s, t; cin >> s >> t; for (int i = 0; i < s.size(); ++i) { buf.insert(s[i]); } for (char ti : t) { if (buf.find(ti) == buf.end()) { cout << -1 << endl; return 0; } } vector<vector<ll>> pos(256); rep(i, s.size()) pos[s[i]].push_back(i); rep(i, 256) sort(all(pos[i])); ll ans = 0; ll curpos = -1; for (char ti : t) { // auto it = lower_bound(all(pos[ti]), curpos); auto it = upper_bound(all(pos[ti]), curpos); if (it == pos[ti].end()) { ans += s.size() - curpos + pos[ti][0]; curpos = pos[ti][0]; // nback++; curpos = 0; it = upper_bound(all(pos[ti]), curpos); } else { ans += *it - curpos; curpos = *it; } } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operation.binary.remove" ]
740,642
740,641
u292813062
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define vvi vector<vector<int>> #define ll long long int int main() { string s, t; cin >> s >> t; vvi dic(30); int num; for (int i = 0; i < s.length(); i++) { num = int(s[i]) - int('a'); dic[num].push_back(i); } ll j = 0; ll count = 0; int num_i; for (int i = 0; i < t.length(); i++) { num_i = int(t[i]) - int('a'); if (dic[num_i].size() > 0) { auto itr = lower_bound(dic[num_i].begin(), dic[num_i].end(), j + 1); if (itr == dic[num_i].end()) { count++; j = dic[num_i][0]; } else j = *itr; } else { cout << -1 << endl; return 0; } } cout << count * s.length() + j + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define vvi vector<vector<int>> #define ll long long int int main() { string s, t; cin >> s >> t; vvi dic(30); int num; for (int i = 0; i < s.length(); i++) { num = int(s[i]) - int('a'); dic[num].push_back(i); } ll j = -1; ll count = 0; int num_i; for (int i = 0; i < t.length(); i++) { num_i = int(t[i]) - int('a'); if (dic[num_i].size() > 0) { auto itr = lower_bound(dic[num_i].begin(), dic[num_i].end(), j + 1); if (itr == dic[num_i].end()) { count++; j = dic[num_i][0]; } else j = *itr; } else { cout << -1 << endl; return 0; } } cout << count * s.length() + j + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,648
740,649
u269804060
cpp
p02937
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <iterator> #include <queue> #include <stack> #include <unordered_map> #include <vector> using namespace std; struct v { vector<int> tos; int counter; }; int main() { string s, t; cin >> s >> t; // 事前にsを処理して、アルファベット毎に出現位置を記録しておく unordered_map<char, vector<int>> char_pos; for (int i = 'a'; i <= 'z'; i++) { char_pos.emplace(i, vector<int>()); } for (int i = 0; i < s.size(); i++) { char_pos[s[i]].emplace_back(i); } int t_pos = 0; long long int result = -1; for (int i = 0;; i++) { // sの繰り返し回数。10**100なので、無限ループと変わらない int before_t_pos = t_pos; for (int s_pos = 0; s_pos < s.size();) { // 1ずつでは間に合わないので、次の出現位置を2分探索で探す const auto &next_t = t[t_pos]; const auto &next_char_pos = char_pos[next_t]; auto ite = lower_bound(next_char_pos.begin(), next_char_pos.end(), s_pos); if (ite == next_char_pos.end()) { // 見つからなかった。 break; } s_pos = *ite; t_pos++; if (t_pos == t.size()) { // 全部見つかった result = i * s.size() + s_pos + 1; goto finish; } } if (t_pos == before_t_pos) { // 今回のsでは見つからなかったので、もう見つかる可能性はない break; } } finish: cout << result << endl; return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <iterator> #include <queue> #include <stack> #include <unordered_map> #include <vector> using namespace std; struct v { vector<int> tos; int counter; }; int main() { string s, t; cin >> s >> t; // 事前にsを処理して、アルファベット毎に出現位置を記録しておく unordered_map<char, vector<int>> char_pos; for (int i = 'a'; i <= 'z'; i++) { char_pos.emplace(i, vector<int>()); } for (int i = 0; i < s.size(); i++) { char_pos[s[i]].emplace_back(i); } int t_pos = 0; long long int result = -1; for (int i = 0;; i++) { // sの繰り返し回数。10**100なので、無限ループと変わらない int before_t_pos = t_pos; for (int s_pos = 0; s_pos < s.size(); s_pos++) { // 1ずつでは間に合わないので、次の出現位置を2分探索で探す const auto &next_t = t[t_pos]; const auto &next_char_pos = char_pos[next_t]; auto ite = lower_bound(next_char_pos.begin(), next_char_pos.end(), s_pos); if (ite == next_char_pos.end()) { // 見つからなかった。 break; } s_pos = *ite; t_pos++; if (t_pos == t.size()) { // 全部見つかった result = i * s.size() + s_pos + 1; goto finish; } } if (t_pos == before_t_pos) { // 今回のsでは見つからなかったので、もう見つかる可能性はない break; } } finish: cout << result << endl; return 0; }
[ "control_flow.loop.for.update.change" ]
740,652
740,653
u538188080
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; map<char, set<uint64_t>> chmap; for (char c = 'a'; c <= 'z'; ++c) { chmap.emplace(c, set<uint64_t>()); } for (uint64_t n = 0; n < s.size(); ++n) { chmap[s[n]].insert(n); } bool not_partial_flag = false; uint64_t ix = 0, iy = 0; for (uint64_t n = 0; n < t.size(); ++n) { if (chmap[t[n]].size() == 0) { not_partial_flag = true; break; } auto itr = chmap[t[n]].upper_bound(iy); if (itr == chmap[t[n]].end()) { ++ix; iy = *chmap[t[n]].begin(); } else { iy = *itr; } } if (not_partial_flag) { cout << -1 << endl; } else { cout << (ix * s.size() + iy + 1) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; map<char, set<int64_t>> chmap; for (char c = 'a'; c <= 'z'; ++c) { chmap.emplace(c, set<int64_t>()); } for (uint64_t n = 0; n < s.size(); ++n) { chmap[s[n]].insert(n); } bool not_partial_flag = false; int64_t ix = 0, iy = -1; for (uint64_t n = 0; n < t.size(); ++n) { if (chmap[t[n]].size() == 0) { not_partial_flag = true; break; } auto itr = chmap[t[n]].upper_bound(iy); if (itr == chmap[t[n]].end()) { ++ix; iy = *chmap[t[n]].begin(); } else { iy = *itr; } } if (not_partial_flag) { cout << -1 << endl; } else { cout << (ix * s.size() + iy + 1) << endl; } return 0; }
[ "variable_declaration.type.primitive.change", "literal.number.change", "variable_declaration.value.change" ]
740,670
740,671
u198355306
cpp
p02937
#include <assert.h> #include <bits/stdc++.h> using namespace std; using i64 = long long; int main() { string s, t; cin >> s >> t; vector<i64> pos[26]; i64 ssize = s.size(), tsize = t.size(); for (i64 i = 0; i < ssize; i++) pos[s[i] - 'a'].push_back(i); for (i64 i = 0; i < tsize; i++) if (pos[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } i64 ans = 0, l = 0; for (i64 i = 0; i < tsize; i++) { i64 c = t[i] - 'a'; i64 it = upper_bound(pos[c].begin(), pos[c].end(), ans) - pos[c].begin(); if (it == (i64)pos[c].size()) { ans = pos[c][0]; l++; } else ans = pos[c][it]; } cout << l * ssize + ans + 1 << endl; return 0; }
#include <assert.h> #include <bits/stdc++.h> using namespace std; using i64 = long long; int main() { string s, t; cin >> s >> t; vector<i64> pos[26]; i64 ssize = s.size(), tsize = t.size(); for (i64 i = 0; i < ssize; i++) pos[s[i] - 'a'].push_back(i); for (i64 i = 0; i < tsize; i++) if (pos[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } i64 ans = -1, l = 0; for (i64 i = 0; i < tsize; i++) { i64 c = t[i] - 'a'; i64 it = upper_bound(pos[c].begin(), pos[c].end(), ans) - pos[c].begin(); if (it == (i64)pos[c].size()) { ans = pos[c][0]; l++; } else ans = pos[c][it]; } cout << l * ssize + ans + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,684
740,685
u623115612
cpp
p02937
/*author : Yashvardhan Sunday, August 18, 2019 6:46 PM */ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll #define pb push_back #define vi vector<int> #define pi pair<int, int> #define vpi vector<pi> #define ff first #define ss second #define mp make_pair #define endl '\n' #define all(a) a.begin(), a.end() #define initialise(a, x) memset(a, x, sizeof(a)) #define rev(Y) reverse(all(Y)) #define printArr(name, from, to) \ for (int x = from; x < to; x++) \ cout << name[x] << " "; #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define _CRT_SECURE_NO_WARNINGS #ifdef __APPLE__ #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " "; __f(comma + 1, args...); } #else #define debug(...) #endif template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size(); ++i) os << v[i] << " "; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto it : v) os << it << " "; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << v.ff << " " << v.ss; return os; } const int mod = 1e9 + 7; const int inf = 2e18; const int ninf = -2e18; const int N = 1e5 + 5; int arr[26][N]; int focc[N]; int takemod(int a) { return ((a % mod) + mod) % mod; } int pow(int a, int b, int m) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } int modinv(int a) { return takemod(pow(takemod(a), mod - 2, mod)); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef __APPLE__ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif time_t t1, t2; t1 = clock(); string s, t; cin >> s >> t; int n = s.size(); bool possi = true; initialise(focc, -1); initialise(arr, 0); vi occ[26]; for (int i = 1; i <= n; i++) { for (int j = 0; j < 26; j++) arr[j][i] = arr[j][i - 1]; int curr = s[i - 1] - 'a'; arr[curr][i]++; if (focc[curr] == -1) focc[curr] = i; occ[curr].pb(i); } for (auto i : t) { int curr = i - 'a'; if (arr[curr][n] == 0) { possi = false; break; } } if (!possi) { cout << -1 << endl; return 0; } int cpos = 0; int ans = 0; for (int i = 0; i < t.size(); i++) { int curr = t[i] - 'a'; if (cpos == 0) { ans++; cpos = focc[curr]; } else { if (arr[curr][n] - arr[curr][cpos - 1] == 0) { cpos = focc[curr]; ans++; } else { int ind = lower_bound(all(occ[curr]), cpos + 1) - occ[curr].begin(); cpos = occ[curr][ind]; } } } ans = ans * n; ans -= (n - cpos); cout << ans << endl; t2 = clock(); cerr << endl << t2 - t1 << endl; return 0; }
/*author : Yashvardhan Sunday, August 18, 2019 6:46 PM */ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll #define pb push_back #define vi vector<int> #define pi pair<int, int> #define vpi vector<pi> #define ff first #define ss second #define mp make_pair #define endl '\n' #define all(a) a.begin(), a.end() #define initialise(a, x) memset(a, x, sizeof(a)) #define rev(Y) reverse(all(Y)) #define printArr(name, from, to) \ for (int x = from; x < to; x++) \ cout << name[x] << " "; #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define _CRT_SECURE_NO_WARNINGS #ifdef __APPLE__ #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " "; __f(comma + 1, args...); } #else #define debug(...) #endif template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size(); ++i) os << v[i] << " "; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto it : v) os << it << " "; return os; } template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << v.ff << " " << v.ss; return os; } const int mod = 1e9 + 7; const int inf = 2e18; const int ninf = -2e18; const int N = 1e5 + 5; int arr[26][N]; int focc[N]; int takemod(int a) { return ((a % mod) + mod) % mod; } int pow(int a, int b, int m) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; } int modinv(int a) { return takemod(pow(takemod(a), mod - 2, mod)); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifdef __APPLE__ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif time_t t1, t2; t1 = clock(); string s, t; cin >> s >> t; int n = s.size(); bool possi = true; initialise(focc, -1); initialise(arr, 0); vi occ[26]; for (int i = 1; i <= n; i++) { for (int j = 0; j < 26; j++) arr[j][i] = arr[j][i - 1]; int curr = s[i - 1] - 'a'; arr[curr][i]++; if (focc[curr] == -1) focc[curr] = i; occ[curr].pb(i); } for (auto i : t) { int curr = i - 'a'; if (arr[curr][n] == 0) { possi = false; break; } } if (!possi) { cout << -1 << endl; return 0; } int cpos = 0; int ans = 0; for (int i = 0; i < t.size(); i++) { int curr = t[i] - 'a'; if (cpos == 0) { ans++; cpos = focc[curr]; } else { if (arr[curr][n] - arr[curr][cpos] == 0) { cpos = focc[curr]; ans++; } else { int ind = lower_bound(all(occ[curr]), cpos + 1) - occ[curr].begin(); cpos = occ[curr][ind]; } } } ans = ans * n; ans -= (n - cpos); cout << ans << endl; t2 = clock(); cerr << endl << t2 - t1 << endl; return 0; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
740,694
740,695
u368039995
cpp
p02937
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mkp(a, b) make_pair(a, b) #define PI 3.14159265359 #define ll long long #define ul unsigned long long #define ld long double #define mset(arr, val) memset(arr, val, sizeof arr) #define MAXN (long long)2e5 + 5 #define eb emplace_back #define mod (long long)(1e9 + 7) #define FILE_READ freopen("input.txt", "r", stdin) #define FILE_WRITE freopen("output.txt", "w", stdout) using namespace std; using namespace __gnu_pbds; ; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; void dfs(int root, int par, vector<int> nbs[], ll val[]) { for (auto i : nbs[root]) { if (i == par) { continue; } val[i] += val[root]; dfs(i, root, nbs, val); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // FILE_READ; // FILE_WRITE; string s, t; cin >> s >> t; vector<int> a[26]; for (int i = 0; i < s.size(); ++i) { a[s[i] - 'a'].eb(i); } bool p = false; for (int i = 0; i < t.size(); ++i) { if (a[t[i] - 'a'].empty()) { p = true; break; } } if (p) { cout << "-1"; return 0; } int j = 0; ll c = 0; ll last = -1; while (j != t.size()) { // cout<<c<<endl; ++c; int prev = -1; while (j != t.size()) { int pos = lower_bound(a[t[j] - 'a'].begin(), a[t[j] - 'a'].end(), prev) - a[t[j] - 'a'].begin(); // cout<<pos<<endl; // cout<<a[t[j]-'a'].size()<<endl; if (pos == a[t[j] - 'a'].size()) break; prev = a[t[j] - 'a'][pos]; ++j; } last = prev; // break; } c -= 1ll; c = c * (ll)s.size(); c++; c += last; cout << c; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mkp(a, b) make_pair(a, b) #define PI 3.14159265359 #define ll long long #define ul unsigned long long #define ld long double #define mset(arr, val) memset(arr, val, sizeof arr) #define MAXN (long long)2e5 + 5 #define eb emplace_back #define mod (long long)(1e9 + 7) #define FILE_READ freopen("input.txt", "r", stdin) #define FILE_WRITE freopen("output.txt", "w", stdout) using namespace std; using namespace __gnu_pbds; ; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; void dfs(int root, int par, vector<int> nbs[], ll val[]) { for (auto i : nbs[root]) { if (i == par) { continue; } val[i] += val[root]; dfs(i, root, nbs, val); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // FILE_READ; // FILE_WRITE; string s, t; cin >> s >> t; vector<int> a[26]; for (int i = 0; i < s.size(); ++i) { a[s[i] - 'a'].eb(i); } bool p = false; for (int i = 0; i < t.size(); ++i) { if (a[t[i] - 'a'].empty()) { p = true; break; } } if (p) { cout << "-1"; return 0; } int j = 0; ll c = 0; ll last = -1; while (j != t.size()) { // cout<<c<<endl; ++c; int prev = -1; while (j != t.size()) { int pos = upper_bound(a[t[j] - 'a'].begin(), a[t[j] - 'a'].end(), prev) - a[t[j] - 'a'].begin(); // cout<<pos<<endl; // cout<<a[t[j]-'a'].size()<<endl; if (pos == a[t[j] - 'a'].size()) break; prev = a[t[j] - 'a'][pos]; ++j; } last = prev; // break; } c -= 1ll; c = c * (ll)s.size(); c++; c += last; cout << c; return 0; }
[ "identifier.change", "call.function.change", "expression.operation.binary.change" ]
740,700
740,701
u481634050
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() typedef int64_t ll; ll solve(const string &s, const string &t) { int ns = s.length(); int nt = t.length(); vector<vector<ll>> cnts(26); REP(i, ns) { cnts[s[i] - 'a'].emplace_back(i); cnts[s[i] - 'a'].emplace_back(i + ns); } REP(i, 26) sort(ALL(cnts[i])); ll cnt = 0; REP(i, nt) { if (cnts[t[i] - 'a'].empty()) return -1; auto itr = lower_bound(ALL(cnts[t[i] - 'a']), cnt % ns); cnt += *itr - cnt % ns; } return cnt + 1; } int main() { string s, t; cin >> s >> t; cout << solve(s, t) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() typedef int64_t ll; ll solve(const string &s, const string &t) { int ns = s.length(); int nt = t.length(); vector<vector<ll>> cnts(26); REP(i, ns) { cnts[s[i] - 'a'].emplace_back(i); cnts[s[i] - 'a'].emplace_back(i + ns); } REP(i, 26) sort(ALL(cnts[i])); ll cnt = -1; REP(i, nt) { if (cnts[t[i] - 'a'].empty()) return -1; auto itr = upper_bound(ALL(cnts[t[i] - 'a']), cnt % ns); cnt += *itr - cnt % ns; } return cnt + 1; } int main() { string s, t; cin >> s >> t; cout << solve(s, t) << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change" ]
740,704
740,705
u886956383
cpp
p02937
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; int main() { string s; cin >> s; string t; cin >> t; vector<vector<ll>> m(30); rep(i, s.size()) { char c = s[i]; ll d = c - 'a'; m[d].pb(i); } /* rep(i,26){ rep(j,m[i].size()){ cout<<i<<" "<<m[i][j]<<" "; } cout<<endl; } */ //ない場合は-1を出力 rep(i, t.size()) { char tc = t[i]; ll td = tc - 'a'; if (m[td].size() == 0) { cout << -1 << endl; return 0; } } ll ans = 0; ll cnt = 1; ll ts = t[0] - 'a'; ll tmp = m[ts][0]; for (int i = 1; i < t.size(); i++) { ll ts = t[i] - 'a'; ll next = POSL(m[ts], tmp); if (next == m[ts].size()) { tmp = m[ts][0]; cnt++; } else { tmp = m[ts][next]; } // cout<<t[i]<<" "<<cnt<<" "<<tmp<<endl; } // cout<<cnt<<endl; ans = (ll)s.size() * (ll)(cnt - 1) + (ll)tmp + 1; cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; int main() { string s; cin >> s; string t; cin >> t; vector<vector<ll>> m(30); rep(i, s.size()) { char c = s[i]; ll d = c - 'a'; m[d].pb(i); } /* rep(i,26){ rep(j,m[i].size()){ cout<<i<<" "<<m[i][j]<<" "; } cout<<endl; } */ //ない場合は-1を出力 rep(i, t.size()) { char tc = t[i]; ll td = tc - 'a'; if (m[td].size() == 0) { cout << -1 << endl; return 0; } } ll ans = 0; ll cnt = 1; ll ts = t[0] - 'a'; ll tmp = m[ts][0]; for (ll i = 1; i < t.size(); i++) { ll ts = t[i] - 'a'; ll next = POSU(m[ts], tmp); if (next == m[ts].size()) { tmp = m[ts][0]; cnt++; } else { tmp = m[ts][next]; } // cout<<t[i]<<" "<<cnt<<" "<<tmp<<endl; } // cout<<cnt<<endl; ans = (ll)s.size() * (ll)(cnt - 1) + (ll)tmp + 1; cout << ans << endl; }
[ "control_flow.loop.for.initializer.change", "variable_declaration.type.change", "identifier.change", "call.function.change" ]
740,710
740,711
u284045566
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for (LL i = (l); i < (r); ++i) #define incII(i, l, r) for (LL i = (l); i <= (r); ++i) #define decID(i, l, r) for (LL i = (r)-1; i >= (l); --i) #define decII(i, l, r) for (LL i = (r); i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() template <typename T> bool setmin(T &a, T b) { if (b < a) { a = b; return true; } else { return false; } } template <typename T> bool setmax(T &a, T b) { if (b > a) { a = b; return true; } else { return false; } } template <typename T> bool setmineq(T &a, T b) { if (b <= a) { a = b; return true; } else { return false; } } template <typename T> bool setmaxeq(T &a, T b) { if (b >= a) { a = b; return true; } else { return false; } } LL mo(LL a, LL b) { assert(b > 0); a %= b; if (a < 0) { a += b; } return a; } LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); } LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); } template <typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define bit(b, i) (((b) >> (i)) & 1) #define BC __builtin_popcountll #define SC static_cast #define SI(v) SC<int>(v.size()) #define SL(v) SC<LL>(v.size()) #define RF(e, v) for (auto &e : v) #define ef else if #define UR assert(false) // ---- ---- string s, t; set<int> se[26]; int INF = 1e6; int main() { cin >> s >> t; inc(i, SI(s)) { se[s[i] - 'a'].insert(i + 1); } inc(i, SI(t)) { if (se[t[i] - 'a'].empty()) { cout << -1 << endl; return 0; } } inc(i, 26) { se[i].insert(INF); } int x = 0, y = 0; inc(i, SI(t)) { y = *se[t[i] - 'a'].lower_bound(y); if (y == INF) { x++; y = 0; i--; } } cout << SL(s) * x + y << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for (LL i = (l); i < (r); ++i) #define incII(i, l, r) for (LL i = (l); i <= (r); ++i) #define decID(i, l, r) for (LL i = (r)-1; i >= (l); --i) #define decII(i, l, r) for (LL i = (r); i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() template <typename T> bool setmin(T &a, T b) { if (b < a) { a = b; return true; } else { return false; } } template <typename T> bool setmax(T &a, T b) { if (b > a) { a = b; return true; } else { return false; } } template <typename T> bool setmineq(T &a, T b) { if (b <= a) { a = b; return true; } else { return false; } } template <typename T> bool setmaxeq(T &a, T b) { if (b >= a) { a = b; return true; } else { return false; } } LL mo(LL a, LL b) { assert(b > 0); a %= b; if (a < 0) { a += b; } return a; } LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); } LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); } template <typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define bit(b, i) (((b) >> (i)) & 1) #define BC __builtin_popcountll #define SC static_cast #define SI(v) SC<int>(v.size()) #define SL(v) SC<LL>(v.size()) #define RF(e, v) for (auto &e : v) #define ef else if #define UR assert(false) // ---- ---- string s, t; set<int> se[26]; int INF = 1e6; int main() { cin >> s >> t; inc(i, SI(s)) { se[s[i] - 'a'].insert(i + 1); } inc(i, SI(t)) { if (se[t[i] - 'a'].empty()) { cout << -1 << endl; return 0; } } inc(i, 26) { se[i].insert(INF); } int x = 0, y = 0; inc(i, SI(t)) { y = *se[t[i] - 'a'].upper_bound(y); if (y == INF) { x++; y = 0; i--; } } cout << SL(s) * x + y << endl; return 0; }
[ "assignment.value.change", "call.function.change" ]
740,712
740,713
u568652083
cpp
p02937
#include <algorithm> #include <iostream> #include <vector> #define REP(i, a, b) for (auto i = (a); i < (b); ++i) using namespace std; #define int long long signed main() { string ss; getline(cin, ss, '\n'); string ts; getline(cin, ts, '\n'); long long n = ss.size(), m = ts.size(); int s[n], t[m]; REP(i, 0, m) t[i] = ts[i] - 'a'; REP(i, 0, n) s[i] = ss[i] - 'a'; vector<int> freq[27]; REP(i, 0, n) freq[s[i]].push_back(i); bool flag = 0; REP(i, 0, m) flag |= freq[t[i]].empty(); if (flag) { cout << -1; return 0; } int prev = 0; long long ans = 0; REP(i, 0, m) { auto it = upper_bound(freq[t[i]].begin(), freq[t[i]].end(), prev); if (it != freq[t[i]].end()) prev = *it; else { ++ans; prev = freq[t[i]][0]; } } cout << ans * n + prev + 1LL; }
#include <algorithm> #include <iostream> #include <vector> #define REP(i, a, b) for (auto i = (a); i < (b); ++i) using namespace std; #define int long long signed main() { string ss; getline(cin, ss, '\n'); string ts; getline(cin, ts, '\n'); long long n = ss.size(), m = ts.size(); int s[n], t[m]; REP(i, 0, m) t[i] = ts[i] - 'a'; REP(i, 0, n) s[i] = ss[i] - 'a'; vector<int> freq[27]; REP(i, 0, n) freq[s[i]].push_back(i); bool flag = 0; REP(i, 0, m) flag |= freq[t[i]].empty(); if (flag) { cout << -1; return 0; } int prev = -1; long long ans = 0; REP(i, 0, m) { auto it = upper_bound(freq[t[i]].begin(), freq[t[i]].end(), prev); if (it != freq[t[i]].end()) prev = *it; else { ++ans; prev = freq[t[i]][0]; } } cout << ans * n + prev + 1LL; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,714
740,715
u883745615
cpp
p02937
#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() { string s, t; cin >> s >> t; string ss = s + s; int slen = s.length(); int sslen = ss.length(); int dp[sslen][26] = {}; rep(j, sslen) { char c = ss[j]; int cnum = c - 'a'; repr(k, j - 1, 0) { if (dp[k][cnum] != 0) break; dp[k][cnum] = j - k; } } int tlen = t.length(); ll ans = 1; int now = 0; rep(i, tlen) { char c = t[i]; int cnum = c - 'a'; if (dp[now][cnum] == 0) { std::cout << -1 << '\n'; return 0; } ans += dp[now][cnum]; now += dp[now][cnum]; if (now >= slen) now -= slen; } 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() { string s, t; cin >> s >> t; string ss = s + s; int slen = s.length(); int sslen = ss.length(); int dp[sslen][26] = {}; rep(j, sslen) { char c = ss[j]; int cnum = c - 'a'; repr(k, j - 1, 0) { if (dp[k][cnum] != 0) break; dp[k][cnum] = j - k; } } int tlen = t.length(); ll ans = 0; int now = slen - 1; rep(i, tlen) { char c = t[i]; int cnum = c - 'a'; if (dp[now][cnum] == 0) { std::cout << -1 << '\n'; return 0; } ans += dp[now][cnum]; now += dp[now][cnum]; if (now >= slen) now -= slen; } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.replace.add", "literal.replace.remove" ]
740,738
740,739
u556276145
cpp
p02937
// abc138_e #include <bits/stdc++.h> #ifdef LOCAL #include "../cxx-prettyprint/prettyprint.hpp" #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i)) #define REP_REV(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i)) #define REPN_REV(i, m, n) for (int(i) = (int)(n)-1; (i) >= m; --(i)) #define ALL(x) x.begin(), x.end() #define INF ((1 << 29) - 1) #define MOD (1000000007) #define print2D(h, w, arr) \ REP(i, h) { \ REP(j, w) cout << arr[i][j] << " "; \ cout << endl; \ } template <class T> void print(const T &x) { cout << x << endl; } template <class T, class... A> void print(const T &first, const A &...rest) { cout << first << " "; print(rest...); } struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } premain; int main() { #ifdef LOCAL ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf()); #endif string S, T; cin >> S >> T; map<char, vector<int>> mp_s; REP(i, S.size()) { char c = S[i]; mp_s[c].emplace_back(i); } REP(i, T.size()) { char c = T[i]; if (mp_s[c].empty()) { print(-1); return 0; } } // print(mp_s); int idx = 0; ll ans = 0; REP(i, T.size()) { char c = T[i]; auto it = upper_bound(ALL(mp_s[c]), idx); if (it != mp_s[c].end()) { idx = *it; } else { idx = mp_s[c][0]; ans += S.size(); } } ans += idx + 1; print(ans); return 0; }
// abc138_e #include <bits/stdc++.h> #ifdef LOCAL #include "../cxx-prettyprint/prettyprint.hpp" #endif using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i)) #define REP_REV(i, n) for (int(i) = (int)(n)-1; (i) >= 0; --(i)) #define REPN_REV(i, m, n) for (int(i) = (int)(n)-1; (i) >= m; --(i)) #define ALL(x) x.begin(), x.end() #define INF ((1 << 29) - 1) #define MOD (1000000007) #define print2D(h, w, arr) \ REP(i, h) { \ REP(j, w) cout << arr[i][j] << " "; \ cout << endl; \ } template <class T> void print(const T &x) { cout << x << endl; } template <class T, class... A> void print(const T &first, const A &...rest) { cout << first << " "; print(rest...); } struct PreMain { PreMain() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } premain; int main() { #ifdef LOCAL ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf()); #endif string S, T; cin >> S >> T; map<char, vector<int>> mp_s; REP(i, S.size()) { char c = S[i]; mp_s[c].emplace_back(i); } REP(i, T.size()) { char c = T[i]; if (mp_s[c].empty()) { print(-1); return 0; } } // print(mp_s); int idx = -1; ll ans = 0; REP(i, T.size()) { char c = T[i]; auto it = upper_bound(ALL(mp_s[c]), idx); if (it != mp_s[c].end()) { idx = *it; } else { idx = mp_s[c][0]; ans += S.size(); } } ans += idx + 1; print(ans); return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,740
740,741
u614550445
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { string s, t; cin >> s >> t; vector<vector<ll>> alpha(26); for (ll i = 0; i < s.size(); i++) { alpha[s[i] - 'a'].push_back(i); } ll ans = 0; ll count = 0; ll tpos = 0; ll npos = 0; while (tpos < t.size()) { ll al = t[tpos] - 'a'; if (alpha[al].empty()) { cout << -1 << endl; return 0; } auto itr = lower_bound(alpha[al].begin(), alpha[al].end(), npos); if (itr == alpha[al].end()) { npos = 0; count++; continue; } npos = *itr; tpos++; } ans = count * ll(s.size()) + npos + 1LL; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { string s, t; cin >> s >> t; vector<vector<ll>> alpha(26); for (ll i = 0; i < s.size(); i++) { alpha[s[i] - 'a'].push_back(i); } ll ans = 0; ll count = 0; ll tpos = 0; ll npos = 0; while (tpos < t.size()) { ll al = t[tpos] - 'a'; if (alpha[al].empty()) { cout << -1 << endl; return 0; } auto itr = lower_bound(alpha[al].begin(), alpha[al].end(), npos); if (itr == alpha[al].end()) { npos = 0; count++; continue; } npos = *itr + 1; tpos++; } ans = count * ll(s.size()) + npos; cout << ans << endl; }
[ "assignment.change", "expression.operation.binary.remove" ]
740,742
740,743
u410878763
cpp
p02937
#include <bits/stdc++.h> using namespace std; string s, t; long long ans, a, now, ls, lt; int main() { cin >> s >> t; ls = s.size(); lt = t.size(); vector<vector<long long>> abc(26); for (long long i = 0; i < ls; i++) { a = s[i] - 97; abc[a].push_back(i); } for (long long i = 0; i < lt; i++) { a = t[i] - 97; if (abc[a].size() == 0) { cout << -1 << endl; return 0; } if (now >= *(abc[a].end() - 1)) { ans++; now = abc[a][0]; } else { now = *upper_bound(abc[a].begin(), abc[a].end(), now); } } cout << ls * ans + now + 1 << endl; }
#include <bits/stdc++.h> using namespace std; string s, t; long long ans, a, now, ls, lt; int main() { cin >> s >> t; ls = s.size(); lt = t.size(); vector<vector<long long>> abc(26); for (long long i = 0; i < ls; i++) { a = s[i] - 97; abc[a].push_back(i); } now = -1; for (long long i = 0; i < lt; i++) { a = t[i] - 97; if (abc[a].size() == 0) { cout << -1 << endl; return 0; } if (now >= *(abc[a].end() - 1)) { ans++; now = abc[a][0]; } else { now = *upper_bound(abc[a].begin(), abc[a].end(), now); } } cout << ls * ans + now + 1 << endl; }
[ "assignment.add" ]
740,744
740,745
u576357314
cpp
p02937
#include <bits/stdc++.h> using namespace std; string s, t; long long ans, a, now, ls, lt; int main() { cin >> s >> t; ls = s.size(); lt = t.size(); vector<vector<long long>> abc(26); for (long long i = 0; i < ls; i++) { a = s[i] - 97; abc[a].push_back(i); } for (long long i = 0; i < lt; i++) { a = t[i] - 97; if (abc[a].size() == 0) { cout << -1 << endl; return 0; } if (now > *(abc[a].end() - 1)) { ans++; now = abc[a][0]; } else { now = *upper_bound(abc[a].begin(), abc[a].end(), now); } } cout << ls * ans + now + 1 << endl; }
#include <bits/stdc++.h> using namespace std; string s, t; long long ans, a, now, ls, lt; int main() { cin >> s >> t; ls = s.size(); lt = t.size(); vector<vector<long long>> abc(26); for (long long i = 0; i < ls; i++) { a = s[i] - 97; abc[a].push_back(i); } now = -1; for (long long i = 0; i < lt; i++) { a = t[i] - 97; if (abc[a].size() == 0) { cout << -1 << endl; return 0; } if (now >= *(abc[a].end() - 1)) { ans++; now = abc[a][0]; } else { now = *upper_bound(abc[a].begin(), abc[a].end(), now); } } cout << ls * ans + now + 1 << endl; }
[ "assignment.add", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,746
740,745
u576357314
cpp
p02937
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, n) for (int i = 1; i <= n; i++) const double PI = acos(-1); const double EPS = 1e-15; long long INF = (long long)1E17; #define i_7 (long long)(1E9 + 7) long mod(long a) { long long c = a % i_7; if (c >= 0) return c; return c + i_7; } using namespace std; bool prime_(int n) { if (n == 1) { return false; } else if (n == 2) { return true; } else { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } } long long gcd_(long long a, long long b) { if (a < b) { swap(a, b); } if (a % b == 0) { return b; } else { return gcd_(b, a % b); } } long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; } class UnionFind { public: //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。 vector<int> Parent; //クラスを作るときは、Parentの値を全て-1にする。 //以下のようにすると全てバラバラの頂点として解釈できる。 UnionFind(int N) { Parent = vector<int>(N, -1); } // Aがどのグループに属しているか調べる int root(int A) { if (Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } //自分のいるグループの頂点数を調べる int size(int A) { return -Parent[root(A)]; //先祖をrootで取っておきたい。 } // AとBをくっ付ける bool connect(int A, int B) { // AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける A = root(A); B = root(B); if (A == B) { //すでにくっついてるからくっ付けない return false; } //大きい方(A)に小さいほう(B)をくっ付けたい //大小が逆だったらAとBをひっくり返す。 if (size(A) < size(B)) swap(A, B); // Aのサイズを更新する Parent[A] += Parent[B]; // Bの親をAに変更する Parent[B] = A; return true; } }; int main() { string s; string t; bool es[26] = {}; bool et[26] = {}; cin >> s; cin >> t; int n = s.size(); int m = t.size(); int index; REP(i, n) { index = s[i] - 'a'; es[index] = true; } REP(i, m) { index = t[i] - 'a'; et[index] = true; } bool flag = true; REP(i, 26) { if (!es[i] && et[i]) { flag = false; break; } } if (!flag) { cout << -1 << endl; return 0; } string temp = s; string now = ""; long long pos; long long cnt = 0; long long offset = 0; long long ans; index = 0; while (index < m) { pos = temp.find(t[index]); if (pos == -1) { cnt++; temp = s; offset = 0; continue; } else if (pos == temp.size() - 1) { cnt++; temp = s; offset = 0; index++; } else { if (index == m - 1) { offset = pos + 1; break; } temp = temp.substr(pos + 1); offset += pos + 1; index++; } } ans = cnt * (long long)s.size() + offset + 1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, n) for (int i = 1; i <= n; i++) const double PI = acos(-1); const double EPS = 1e-15; long long INF = (long long)1E17; #define i_7 (long long)(1E9 + 7) long mod(long a) { long long c = a % i_7; if (c >= 0) return c; return c + i_7; } using namespace std; bool prime_(int n) { if (n == 1) { return false; } else if (n == 2) { return true; } else { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } } long long gcd_(long long a, long long b) { if (a < b) { swap(a, b); } if (a % b == 0) { return b; } else { return gcd_(b, a % b); } } long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; } class UnionFind { public: //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。 vector<int> Parent; //クラスを作るときは、Parentの値を全て-1にする。 //以下のようにすると全てバラバラの頂点として解釈できる。 UnionFind(int N) { Parent = vector<int>(N, -1); } // Aがどのグループに属しているか調べる int root(int A) { if (Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } //自分のいるグループの頂点数を調べる int size(int A) { return -Parent[root(A)]; //先祖をrootで取っておきたい。 } // AとBをくっ付ける bool connect(int A, int B) { // AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける A = root(A); B = root(B); if (A == B) { //すでにくっついてるからくっ付けない return false; } //大きい方(A)に小さいほう(B)をくっ付けたい //大小が逆だったらAとBをひっくり返す。 if (size(A) < size(B)) swap(A, B); // Aのサイズを更新する Parent[A] += Parent[B]; // Bの親をAに変更する Parent[B] = A; return true; } }; int main() { string s; string t; bool es[26] = {}; bool et[26] = {}; cin >> s; cin >> t; int n = s.size(); int m = t.size(); int index; REP(i, n) { index = s[i] - 'a'; es[index] = true; } REP(i, m) { index = t[i] - 'a'; et[index] = true; } bool flag = true; REP(i, 26) { if (!es[i] && et[i]) { flag = false; break; } } if (!flag) { cout << -1 << endl; return 0; } string temp = s; string now = ""; long long pos; long long cnt = 0; long long offset = 0; long long ans; index = 0; while (index < m) { pos = temp.find(t[index]); if (pos == -1) { cnt++; temp = s; offset = 0; continue; } else if (pos == temp.size() - 1) { cnt++; temp = s; offset = 0; index++; } else { if (index == m - 1) { offset += pos + 1; break; } temp = temp.substr(pos + 1); offset += pos + 1; index++; } } ans = cnt * (long long)s.size() + offset; cout << ans << endl; return 0; }
[ "assignment.value.change", "expression.operation.binary.remove" ]
740,753
740,754
u222293734
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n1 = s.size(), n2 = t.size(), fl = 0; long long int cnt = 0, rem = 1, ans; int a[26]; set<int> se[26]; set<int>::iterator s1; for (int i = 0; i < 26; i++) a[i] = -1; for (int i = 0; i < n1; i++) { int ind = s[i] - 97; if (a[ind] == -1) { a[ind] = i + 1; } se[ind].insert(i + 1); } for (int i = 0; i < n2; i++) { int l = t[i] - 97; if (a[l] == -1) { cout << "-1"; fl = 1; break; } s1 = se[l].lower_bound(rem + 1); if (s1 != se[l].end()) { rem = *s1; } else { cnt++; rem = a[l]; } // cout<<i<<" - "<<cnt<<" "<<rem<<"\n"; } if (!fl) { ans = cnt * n1 + rem; cout << ans; } }
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n1 = s.size(), n2 = t.size(), fl = 0; long long int cnt = 0, rem = 0, ans; int a[26]; set<int> se[26]; set<int>::iterator s1; for (int i = 0; i < 26; i++) a[i] = -1; for (int i = 0; i < n1; i++) { int ind = s[i] - 97; if (a[ind] == -1) { a[ind] = i + 1; } se[ind].insert(i + 1); } for (int i = 0; i < n2; i++) { int l = t[i] - 97; if (a[l] == -1) { cout << "-1"; fl = 1; break; } s1 = se[l].lower_bound(rem + 1); if (s1 != se[l].end()) { rem = *s1; } else { cnt++; rem = a[l]; } // cout<<i<<" - "<<cnt<<" "<<rem<<"\n"; } if (!fl) { ans = cnt * n1 + rem; cout << ans; } }
[ "literal.number.change", "variable_declaration.value.change" ]
740,766
740,767
u547420959
cpp
p02937
// SeeAlso: https://atcoder.jp/contests/abc138/tasks/abc138_e #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define MAX 100000 typedef int _loop_int; #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i) #define FORR(i, a, b) \ for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i) #define DEBUG(x) cout << #x << ": " << x << endl #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << " " << v[i]; \ cout << endl #define ALL(a) (a).begin(), (a).end() #define CHMIN(a, b) a = min((a), (b)) #define CHMAX(a, b) a = max((a), (b)) // 最大公約数 inline constexpr ll gcd(ll a, ll b) { if (!a || !b) return 0; while (b) { ll c = b; b = a % b; a = c; } return a; } // 最小公倍数 inline constexpr ll lcm(ll a, ll b) { if (!a || !b) return 0; return a * b / gcd(a, b); } #define print2D(h, w, arr) \ REP(i, h) { \ REP(j, w) cout << arr[i][j] << " "; \ cout << endl; \ } template <class T> void print(const T &x) { cout << setprecision(12) << x << endl; } template <class T, class... A> void print(const T &first, const A &...rest) { cout << first << " "; print(rest...); } string s, t; int main() { cin >> s; cin >> t; bool flag = true; for (ll i = 0; i < t.size(); i++) { if (s.find(t[i]) == -1) { flag = false; break; } } if (!flag) { print("-1"); return 0; } ll ans = 0; string temp = s; for (ll i = 0; i < t.size(); i++) { print(temp); ll length = temp.find(t[i]); if (length == -1) { temp += s; length = temp.find(t[i]); } temp.erase(temp.begin(), temp.begin() + length + 1); ans += (length + 1); } ll length = temp.find(t[t.size()]); print(ans); return 0; }
// SeeAlso: https://atcoder.jp/contests/abc138/tasks/abc138_e #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define MAX 100000 typedef int _loop_int; #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i) #define FORR(i, a, b) \ for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i) #define DEBUG(x) cout << #x << ": " << x << endl #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << " " << v[i]; \ cout << endl #define ALL(a) (a).begin(), (a).end() #define CHMIN(a, b) a = min((a), (b)) #define CHMAX(a, b) a = max((a), (b)) // 最大公約数 inline constexpr ll gcd(ll a, ll b) { if (!a || !b) return 0; while (b) { ll c = b; b = a % b; a = c; } return a; } // 最小公倍数 inline constexpr ll lcm(ll a, ll b) { if (!a || !b) return 0; return a * b / gcd(a, b); } #define print2D(h, w, arr) \ REP(i, h) { \ REP(j, w) cout << arr[i][j] << " "; \ cout << endl; \ } template <class T> void print(const T &x) { cout << setprecision(12) << x << endl; } template <class T, class... A> void print(const T &first, const A &...rest) { cout << first << " "; print(rest...); } string s, t; int main() { cin >> s; cin >> t; bool flag = true; for (ll i = 0; i < t.size(); i++) { if (s.find(t[i]) == -1) { flag = false; break; } } if (!flag) { print("-1"); return 0; } ll ans = 0; string temp = s; for (ll i = 0; i < t.size(); i++) { ll length = temp.find(t[i]); if (length == -1) { temp += s; length = temp.find(t[i]); } temp.erase(temp.begin(), temp.begin() + length + 1); ans += (length + 1); } ll length = temp.find(t[t.size()]); print(ans); return 0; }
[ "call.remove" ]
740,768
740,769
u185518252
cpp
p02937
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; char s[100005]; char t[100005]; int p[100005][26]; int main() { scanf("%s", s); scanf("%s", t); int sn = strlen(s); int a[26]; memset(a, -1, sizeof(a)); for (int i = sn - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) { p[i][j] = a[j]; } a[s[i] - 'a'] = i; } for (int i = sn - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) { p[i][j] = a[j]; } a[s[i] - 'a'] = i; } int tn = strlen(t); ll res = 0; int next = -1; for (int i = 0; i < tn; ++i) { int cur = next; if (i == 0) { next = a[t[i] - 'a']; } else { next = p[cur][t[i] - 'a']; } if (next == -1) { res = -1; break; } else { if (next < cur) { res += sn - cur + next; } else { res += next - cur; } cur = next; } } printf("%lld\n", res); return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; char s[100005]; char t[100005]; int p[100005][26]; int main() { scanf("%s", s); scanf("%s", t); int sn = strlen(s); int a[26]; memset(a, -1, sizeof(a)); for (int i = sn - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) { p[i][j] = a[j]; } a[s[i] - 'a'] = i; } for (int i = sn - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) { p[i][j] = a[j]; } a[s[i] - 'a'] = i; } int tn = strlen(t); ll res = 0; int next = -1; for (int i = 0; i < tn; ++i) { int cur = next; if (i == 0) { next = a[t[i] - 'a']; } else { next = p[cur][t[i] - 'a']; } if (next == -1) { res = -1; break; } else { if (next <= cur) { res += sn - cur + next; } else { res += next - cur; } cur = next; } } printf("%lld\n", res); return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,776
740,777
u591075912
cpp
p02937
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define pll pair<ll, ll> #pragma GCC optimize("O3") using namespace std; int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #else ios::sync_with_stdio(false); cin.tie(NULL); #endif string s, t; cin >> s >> t; ll n1 = s.size(), n2 = t.size(); map<char, vector<ll>> pos; for (ll i = 0; i < n1; ++i) pos[s[i]].push_back(i); ll now = 0, ans = 0; for (ll i = 0; i < n2; ++i) { if (pos.count(t[i]) == 0) { cout << -1; return 0; } ll cur = upper_bound(pos[t[i]].begin(), pos[t[i]].end(), now) - pos[t[i]].begin(); if (cur == pos[t[i]].size()) { ans += n1; now = pos[t[i]][0]; } else now = pos[t[i]][cur]; } cout << ans + now + 1; return 0; }
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define pll pair<ll, ll> #pragma GCC optimize("O3") using namespace std; int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #else ios::sync_with_stdio(false); cin.tie(NULL); #endif string s, t; cin >> s >> t; ll n1 = s.size(), n2 = t.size(); map<char, vector<ll>> pos; for (ll i = 0; i < n1; ++i) pos[s[i]].push_back(i); ll now = -1, ans = 0; for (ll i = 0; i < n2; ++i) { if (pos.count(t[i]) == 0) { cout << -1; return 0; } ll cur = upper_bound(pos[t[i]].begin(), pos[t[i]].end(), now) - pos[t[i]].begin(); if (cur == pos[t[i]].size()) { ans += n1; now = pos[t[i]][0]; } else now = pos[t[i]][cur]; } cout << ans + now + 1; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,780
740,781
u042208369
cpp
p02937
#include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { string s, t; cin >> s >> t; unsigned long long ans = 1; int pre_index = 0, index; rep(i, t.length()) { char _t = t[i]; auto it = s.find(_t, pre_index); if (it == string::npos) { it = s.find(_t, 0); if (it == string::npos) { cout << "-1" << endl; exit(0); } else { index = (int)it; ans += index + s.length() - pre_index; } } else { index = (int)it; ans += index - pre_index; } pre_index = index; } cout << ans << endl; }
#include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { string s, t; cin >> s >> t; unsigned long long ans = 0; int pre_index = -1, index; rep(i, t.length()) { char _t = t[i]; auto it = s.find(_t, pre_index + 1); if (it == string::npos) { it = s.find(_t, 0); if (it == string::npos) { cout << "-1" << endl; exit(0); } else { index = (int)it; ans += index + s.length() - pre_index; } } else { index = (int)it; ans += index - pre_index; } pre_index = index; } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,786
740,787
u190679129
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define sz(x) (int)(x).size() #define v(T) vector<T> #define vv(T) v(v(T)) #define in(e, l) (std::find(l.begin(), l.end(), e) != l.end()) #define asort(l) (std::sort(l.begin(), l.end())) #define dsort(l) (std::sort(l.rbegin(), l.rend())) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; int main() { string s, t; cin >> s >> t; ll lst = 0; ll column = 0; for (ll i = 0; i < t.size(); ++i) { lst = s.find(t[i], lst); if (lst != -1) { ++lst; ll tmp = lst % s.size(); if (tmp != lst) { ++column; lst = tmp; } continue; } ++column; lst = 0; lst = s.find(t[i], lst); if (lst == -1) { cout << -1 << endl; return 0; } } cout << column * s.size() + lst << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define sz(x) (int)(x).size() #define v(T) vector<T> #define vv(T) v(v(T)) #define in(e, l) (std::find(l.begin(), l.end(), e) != l.end()) #define asort(l) (std::sort(l.begin(), l.end())) #define dsort(l) (std::sort(l.rbegin(), l.rend())) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; int main() { string s, t; cin >> s >> t; ll lst = 0; ll column = 0; for (ll i = 0; i < t.size(); ++i) { lst = s.find(t[i], lst); if (lst != -1) { ++lst; ll tmp = lst % s.size(); if (tmp != lst) { ++column; lst = tmp; } continue; } ++column; lst = 0; lst = s.find(t[i], lst); if (lst == -1) { cout << -1 << endl; return 0; } ++lst; } cout << column * s.size() + lst << endl; return 0; }
[ "expression.unary.arithmetic.add" ]
740,796
740,797
u777853124
cpp
p02937
/* !!!!!! !!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!! !!!!!!!!!! !!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!! !!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! !!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! !!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!! !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!! !!!!!! !!!! */ #include <bits/stdc++.h> #define MAXN 200005 #define mod 1000000007 #define inf LLONG_MAX / 3 using namespace std; /* * author : vivekcrux */ typedef long long ll; typedef pair<ll, ll> pll; ll power(ll x, ll y, ll m = mod) { ll ans = 1; while (y > 0) { if (y & 1) { ans = (ans * x) % m; } x = (x * x) % m; y /= 2; } return ans % m; } ll modInverse(ll a, ll m = mod) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { // q is quotient ll q = a / m; ll t = m; // m is remainder now, process same as // Euclid's algo m = a % m, a = t; t = y; // Update y and x y = x - q * y; x = t; } // Make x positive if (x < 0) x += m0; return x; } vector<ll> tree[MAXN], val, vis; void dfs(int n) { vis[n] = true; for (auto it : tree[n]) { if (!vis[it]) { val[it] += val[n]; dfs(it); } } } ll iss(string s, string t) { int i, j; for (i = 0, j = 0; i < s.length(); i++) { if (s[i] == t[j]) { j++; if (j == t.length()) return i + 1; } } return false; } int main() { // freopen("input.txt","r",stdin); ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; // cin>>t; t = 1; while (t--) { ll n, m, i, j, ans = LONG_MAX; string s, rs; cin >> s >> rs; n = s.length(); m = rs.length(); map<char, vector<ll>> pos; map<char, ll> cs, cr; i = 0; for (auto it : s) { cs[it]++; pos[it].push_back(i); i++; } for (auto it : rs) { cr[it]++; } for (i = 'a'; i <= 'z'; i++) { if (cs[i] == 0 && cr[i] > 0) { cout << "-1"; return 0; } } ll k = 2; i = 0; for (j = 0; j < m; j++) { // cout<<rs[j]<<" // "<<pos[rs[j]][lower_bound(pos[rs[j]].begin(),pos[rs[j]].end(),i%n)-pos[rs[j]].begin()]<<" // "; if (*pos[rs[j]].rbegin() > (i % n)) i += pos[rs[j]] [upper_bound(pos[rs[j]].begin(), pos[rs[j]].end(), i % n) - pos[rs[j]].begin()] - i % n; else i += n - (i % n - pos[rs[j]][upper_bound(pos[rs[j]].begin(), pos[rs[j]].end(), -1) - pos[rs[j]].begin()]); // cout<<i<<":"; // cout<<s[i%n]<<" "; } cout << i + 1; } return 0; }
/* !!!!!! !!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!! !!!!!!!!!! !!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!! !!!!!!!!!!!!!!!!!!! !!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!! ! !!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! !!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! !!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!! !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !!!!!!!!!!!!!!! !!!!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!!!!!! !!!!!!!! !!!!!! !!!! */ #include <bits/stdc++.h> #define MAXN 200005 #define mod 1000000007 #define inf LLONG_MAX / 3 using namespace std; /* * author : vivekcrux */ typedef long long ll; typedef pair<ll, ll> pll; ll power(ll x, ll y, ll m = mod) { ll ans = 1; while (y > 0) { if (y & 1) { ans = (ans * x) % m; } x = (x * x) % m; y /= 2; } return ans % m; } ll modInverse(ll a, ll m = mod) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { // q is quotient ll q = a / m; ll t = m; // m is remainder now, process same as // Euclid's algo m = a % m, a = t; t = y; // Update y and x y = x - q * y; x = t; } // Make x positive if (x < 0) x += m0; return x; } vector<ll> tree[MAXN], val, vis; void dfs(int n) { vis[n] = true; for (auto it : tree[n]) { if (!vis[it]) { val[it] += val[n]; dfs(it); } } } ll iss(string s, string t) { int i, j; for (i = 0, j = 0; i < s.length(); i++) { if (s[i] == t[j]) { j++; if (j == t.length()) return i + 1; } } return false; } int main() { // freopen("input.txt","r",stdin); ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; // cin>>t; t = 1; while (t--) { ll n, m, i, j, ans = LONG_MAX; string s, rs; cin >> s >> rs; n = s.length(); m = rs.length(); map<char, vector<ll>> pos; map<char, ll> cs, cr; i = 0; for (auto it : s) { cs[it]++; pos[it].push_back(i); i++; } for (auto it : rs) { cr[it]++; } for (i = 'a'; i <= 'z'; i++) { if (cs[i] == 0 && cr[i] > 0) { cout << "-1"; return 0; } } ll k = 2; i = -1; for (j = 0; j < m; j++) { // cout<<rs[j]<<" // "<<pos[rs[j]][lower_bound(pos[rs[j]].begin(),pos[rs[j]].end(),i%n)-pos[rs[j]].begin()]<<" // "; if (*pos[rs[j]].rbegin() > (i % n)) i += pos[rs[j]] [upper_bound(pos[rs[j]].begin(), pos[rs[j]].end(), i % n) - pos[rs[j]].begin()] - i % n; else i += n - (i % n - pos[rs[j]][upper_bound(pos[rs[j]].begin(), pos[rs[j]].end(), -1) - pos[rs[j]].begin()]); // cout<<i<<":"<<s[i%n]<<" "; } cout << i + 1; } return 0; }
[ "literal.number.change", "assignment.value.change" ]
740,798
740,799
u965943031
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++) #define all(x) (x).begin(), (x).end() int main() { string s, t; cin >> s >> t; vector<int> s_num(26, 0), t_num(26, 0); vector<vector<int>> a(26); rep(i, s.size()) { s_num[s[i] - 'a']++; a[s[i] - 'a'].push_back(i + 1); } rep(i, t.size()) t_num[t[i] - 'a']++; rep(i, 26) { if (s_num[i] == 0 && t_num[i] > 0) { cout << -1 << endl; return 0; } } LL ans = a[t[0] - 'a'][0]; LL pos_before_char = a[t[0] - 'a'][0]; for (LL i = 1; i < t.size(); i++) { int j = t[i] - 'a'; int x = lower_bound(a[j].begin(), a[j].end(), pos_before_char) - a[j].begin(); if (x == a[j].size()) { ans += s.size() - pos_before_char + a[j][0]; pos_before_char = a[j][0]; } else { ans += a[j][x] - pos_before_char; pos_before_char = a[j][x]; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() int main() { string s, t; cin >> s >> t; vector<int> s_num(26, 0), t_num(26, 0); vector<vector<int>> a(26); rep(i, s.size()) { s_num[s[i] - 'a']++; a[s[i] - 'a'].push_back(i + 1); } rep(i, t.size()) t_num[t[i] - 'a']++; rep(i, 26) { if (s_num[i] == 0 && t_num[i] > 0) { cout << -1 << endl; return 0; } } LL ans = a[t[0] - 'a'][0]; LL pos_before_char = a[t[0] - 'a'][0]; for (LL i = 1; i < t.size(); i++) { int j = t[i] - 'a'; int x = lower_bound(a[j].begin(), a[j].end(), pos_before_char + 1) - a[j].begin(); if (x == a[j].size()) { ans += s.size() - pos_before_char + a[j][0]; pos_before_char = a[j][0]; } else { ans += a[j][x] - pos_before_char; pos_before_char = a[j][x]; } } cout << ans << endl; }
[ "assignment.change" ]
740,800
740,801
u392423112
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define fi first #define se second #define all(v) v.begin(), v.end() #define allarr(a) a, a + n #define ll long long #define ull unsigned long long #define pb push_back #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<int, pi> trp; typedef vector<pi> vpi; typedef vector<pll> vpll; // int ab (int x ) { return (x>0?x:-x); } vector<int> freq[28]; int main() { string s, t; cin >> s >> t; for (int i = 0; i < (int)s.length(); i++) { freq[s[i] - 'a'].pb(i + 1); } // for(int i = 0 ; i < 28 ; i++ ){ // reverse(all(freq[i])); // } ll S = (int)s.length(), T = (int)t.length(); int j = 0; ll cnt = 0, last = 0; for (; j < T && cnt <= T;) { auto it = lower_bound(all(freq[t[j] - 'a']), last); if (it == freq[t[j] - 'a'].end()) { cnt++; last = 0; } else { j++; last = (*it) * 1LL; } } // cerr << cnt << endl; if (j == T) cout << (cnt)*S + last << endl; else cout << -1; }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define fi first #define se second #define all(v) v.begin(), v.end() #define allarr(a) a, a + n #define ll long long #define ull unsigned long long #define pb push_back #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<int, pi> trp; typedef vector<pi> vpi; typedef vector<pll> vpll; // int ab (int x ) { return (x>0?x:-x); } vector<int> freq[28]; int main() { string s, t; cin >> s >> t; for (int i = 0; i < (int)s.length(); i++) { freq[s[i] - 'a'].pb(i + 1); } // for(int i = 0 ; i < 28 ; i++ ){ // reverse(all(freq[i])); // } ll S = (ll)s.length(), T = (int)t.length(); int j = 0; ll cnt = 0, last = 0; for (; j < T && cnt <= T;) { auto it = lower_bound(all(freq[t[j] - 'a']), last + 1); if (it == freq[t[j] - 'a'].end()) { cnt++; last = 0; } else { j++; last = (*it) * 1LL; } } // cerr << cnt << endl; if (j == T) cout << (cnt)*S + last << endl; else cout << -1; }
[ "assignment.change" ]
740,806
740,807
u179395482
cpp
p02937
#include <bits/stdc++.h> #define ll long long #define MAX 300005 #define pp pair<int, pair<int, pair<int, int>>> #define pb push_back #define mod 1000000007 using namespace std; /* * author: Kruti_20 */ ll power(ll x, ll y); ll gcd(ll a, ll b); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s, t; cin >> s >> t; vector<int> v[26]; for (int i = 0; i < s.length(); i++) v[s[i] - 'a'].push_back(i); for (int i = 0; i < t.length(); i++) { if (v[t[i] - 'a'].size()) continue; else { cout << "-1\n"; return 0; } } ll count = 0; ll prev_idx = 0; ll idx = 0; for (int i = 1; i < t.length(); i++) { idx = lower_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), v[t[i - 1] - 'a'][prev_idx]) - v[t[i] - 'a'].begin(); if (idx == v[t[i] - 'a'].size()) { count++; idx = lower_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), 0) - v[t[i] - 'a'].begin(); } prev_idx = idx; } cout << count * s.length() + v[t[t.length() - 1] - 'a'][prev_idx] + 1ll; return 0; } ll power(ll x, ll y) { ll res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
#include <bits/stdc++.h> #define ll long long #define MAX 300005 #define pp pair<int, pair<int, pair<int, int>>> #define pb push_back #define mod 1000000007 using namespace std; /* * author: Kruti_20 */ ll power(ll x, ll y); ll gcd(ll a, ll b); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s, t; cin >> s >> t; vector<int> v[26]; for (int i = 0; i < s.length(); i++) v[s[i] - 'a'].push_back(i); for (int i = 0; i < t.length(); i++) { if (v[t[i] - 'a'].size()) continue; else { cout << "-1\n"; return 0; } } ll count = 0; ll prev_idx = 0; ll idx = 0; for (int i = 1; i < t.length(); i++) { idx = lower_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), v[t[i - 1] - 'a'][prev_idx] + 1) - v[t[i] - 'a'].begin(); if (idx == v[t[i] - 'a'].size()) { count++; idx = lower_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), 0) - v[t[i] - 'a'].begin(); } prev_idx = idx; } cout << count * s.length() + v[t[t.length() - 1] - 'a'][prev_idx] + 1ll; return 0; } ll power(ll x, ll y) { ll res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
[ "assignment.change" ]
740,808
740,809
u352059674
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() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; ll n = (ll)s.size(); ll m = (ll)t.size(); vector<int> alp(26, 0); rep(i, n) alp[s[i] - 'a']++; rep(i, m) { if (alp[t[i] - 'a'] == 0) { cout << -1 << endl; return 0; } } map<int, vector<ll>> mp; rep(i, n) { mp[s[i] - 'a'].push_back((ll)i); } for (auto itr = mp.begin(); itr != mp.end(); itr++) { sort((itr->second).begin(), (itr->second).end()); } // // map<int, int> mp2; // for(auto itr = mp.begin(); itr != mp.end(); itr++){ // mp2[itr->first] = 0; // } ll ans = 1LL; ll pos = 0; for (int i = 0; i < m; i++) { int c = t[i] - 'a'; auto itr2 = upper_bound(mp[c].begin(), mp[c].end(), pos); if (itr2 == mp[c].end()) { ans += (n - pos - 1); ans += *mp[c].begin() + 1; // cout << (n - pos - 1) + *mp[c].begin() + 1 << endl; pos = *mp[c].begin(); } else { ans += (*itr2 - pos); // cout << (*itr2 - pos) << endl; pos = *itr2; } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = (0); i < (n); i++) using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; ll n = (ll)s.size(); ll m = (ll)t.size(); vector<int> alp(26, 0); rep(i, n) alp[s[i] - 'a']++; rep(i, m) { if (alp[t[i] - 'a'] == 0) { cout << -1 << endl; return 0; } } map<int, vector<ll>> mp; rep(i, n) { mp[s[i] - 'a'].push_back((ll)i); } for (auto itr = mp.begin(); itr != mp.end(); itr++) { sort((itr->second).begin(), (itr->second).end()); } // // map<int, int> mp2; // for(auto itr = mp.begin(); itr != mp.end(); itr++){ // mp2[itr->first] = 0; // } ll ans = 1LL; ll pos = -1; for (int i = 0; i < m; i++) { int c = t[i] - 'a'; auto itr2 = upper_bound(mp[c].begin(), mp[c].end(), pos); if (itr2 == mp[c].end()) { ans += (n - pos - 1); ans += *mp[c].begin() + 1; // cout << (n - pos - 1) + *mp[c].begin() + 1 << endl; pos = *mp[c].begin(); } else { ans += (*itr2 - pos); // cout << (*itr2 - pos) << endl; pos = *itr2; } } cout << ans - 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,812
740,813
u755830696
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() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; ll n = (ll)s.size(); ll m = (ll)t.size(); vector<int> alp(26, 0); rep(i, n) alp[s[i] - 'a']++; rep(i, m) { if (alp[t[i] - 'a'] == 0) { cout << -1 << endl; return 0; } } map<int, vector<ll>> mp; rep(i, n) { mp[s[i] - 'a'].push_back((ll)i); } for (auto itr = mp.begin(); itr != mp.end(); itr++) { sort((itr->second).begin(), (itr->second).end()); } // // map<int, int> mp2; // for(auto itr = mp.begin(); itr != mp.end(); itr++){ // mp2[itr->first] = 0; // } ll ans = 1LL; ll pos = 0; for (int i = 0; i < m; i++) { int c = t[i] - 'a'; auto itr2 = lower_bound(mp[c].begin(), mp[c].end(), pos); if (itr2 == mp[c].end()) { ans += (n - pos - 1); ans += *mp[c].begin() + 1; // cout << (n - pos - 1) + *mp[c].begin() + 1 << endl; pos = *mp[c].begin(); } else { ans += (*itr2 - pos); // cout << (*itr2 - pos) << endl; pos = *itr2; } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = (0); i < (n); i++) using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; ll n = (ll)s.size(); ll m = (ll)t.size(); vector<int> alp(26, 0); rep(i, n) alp[s[i] - 'a']++; rep(i, m) { if (alp[t[i] - 'a'] == 0) { cout << -1 << endl; return 0; } } map<int, vector<ll>> mp; rep(i, n) { mp[s[i] - 'a'].push_back((ll)i); } for (auto itr = mp.begin(); itr != mp.end(); itr++) { sort((itr->second).begin(), (itr->second).end()); } // // map<int, int> mp2; // for(auto itr = mp.begin(); itr != mp.end(); itr++){ // mp2[itr->first] = 0; // } ll ans = 1LL; ll pos = -1; for (int i = 0; i < m; i++) { int c = t[i] - 'a'; auto itr2 = upper_bound(mp[c].begin(), mp[c].end(), pos); if (itr2 == mp[c].end()) { ans += (n - pos - 1); ans += *mp[c].begin() + 1; // cout << (n - pos - 1) + *mp[c].begin() + 1 << endl; pos = *mp[c].begin(); } else { ans += (*itr2 - pos); // cout << (*itr2 - pos) << endl; pos = *itr2; } } cout << ans - 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change" ]
740,814
740,813
u755830696
cpp
p02937
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <iostream> #include <map> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> #define fio \ ios::sync_with_stdio(false); \ cin.tie(NULL); using namespace std; typedef long long ll; typedef pair<int, int> pii; char s[(int)1e5 + 5], t[(int)1e5 + 5]; vector<ll> p[300]; ll next(ll pidx, ll v) { if (p[v].size() == 0) return -1; if (p[v].back() <= pidx) return p[v][0]; return p[v][upper_bound(p[v].begin(), p[v].end(), pidx) - p[v].begin()]; } ll n; ll ans; ll calc(ll a, ll b) { if (a <= b) return b - a; return n - 1 - a + b + 1; } int main(void) { scanf("%s %s", s, t); for (ll i = 0; s[i]; i++, n++) { p[s[i]].push_back(i); } ll pidx = -1; for (ll i = 0; t[i]; i++) { ll cidx = next(pidx, t[i]); if (cidx == -1) return !printf("-1\n"); ans += calc(pidx, cidx); pidx = cidx; } printf("%lld\n", ans); }
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <iostream> #include <map> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> #define fio \ ios::sync_with_stdio(false); \ cin.tie(NULL); using namespace std; typedef long long ll; typedef pair<int, int> pii; char s[(int)1e5 + 5], t[(int)1e5 + 5]; vector<ll> p[300]; ll next(ll pidx, ll v) { if (p[v].size() == 0) return -1; if (p[v].back() <= pidx) return p[v][0]; return p[v][upper_bound(p[v].begin(), p[v].end(), pidx) - p[v].begin()]; } ll n; ll ans; ll calc(ll a, ll b) { if (a < b) return b - a; return n - 1 - a + b + 1; } int main(void) { scanf("%s %s", s, t); for (ll i = 0; s[i]; i++, n++) { p[s[i]].push_back(i); } ll pidx = -1; for (ll i = 0; t[i]; i++) { ll cidx = next(pidx, t[i]); if (cidx == -1) return !printf("-1\n"); ans += calc(pidx, cidx); pidx = cidx; } printf("%lld\n", ans); }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,823
740,824
u716033247
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<ll>; using VV = vector<VI>; using VS = vector<string>; // tourist set template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // tourist set end template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, b) FOR(i, 0, b) #define ALL(v) (v).begin(), (v).end() #define p(s) cout << (s) << endl #define p2(s, t) cout << (s) << " " << (t) << endl #define br() p("") #define pn(s) cout << (#s) << " " << (s) << endl #define p_yes() p("YES") #define p_no() p("NO") #define pb(s) push_back(s) #define SZ(x) ((int)(x).size()) const ll mod = 1e9 + 7; const ll inf = 1e18; void vprint(vector<ll> A) { ll L = A.size(); FOR(i, 0, L) { if (i) cout << ' '; cout << A[i]; } cout << endl; } VV T; int main() { cin.tie(0); ios::sync_with_stdio(false); // input string s, t; cin >> s >> t; T.resize(26); map<char, ll> mp_s, mp_t; for (char c : s) { mp_s[c]++; } for (char c : t) { mp_t[c]++; } for (auto pa : mp_t) { char c = pa.first; if (mp_s.count(c) == 0) { p(-1); return 0; } } // p("作れる"); string s2 = s + s; ll L = s2.size(); rep(i, L) { char c = s2[i]; ll v = c - 'a'; T[v].push_back(i); } ll ans = 0; ll pos = 0; rep(i, t.size()) { char c = t[i]; ll v = c - 'a'; // 今の位置からcを探す auto it = upper_bound(ALL(T[v]), pos); ll diff = (*it) - pos; ans += diff; pos += diff; pos %= s.size(); } p(ans + 1); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<ll>; using VV = vector<VI>; using VS = vector<string>; // tourist set template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // tourist set end template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, b) FOR(i, 0, b) #define ALL(v) (v).begin(), (v).end() #define p(s) cout << (s) << endl #define p2(s, t) cout << (s) << " " << (t) << endl #define br() p("") #define pn(s) cout << (#s) << " " << (s) << endl #define p_yes() p("YES") #define p_no() p("NO") #define pb(s) push_back(s) #define SZ(x) ((int)(x).size()) const ll mod = 1e9 + 7; const ll inf = 1e18; void vprint(vector<ll> A) { ll L = A.size(); FOR(i, 0, L) { if (i) cout << ' '; cout << A[i]; } cout << endl; } VV T; int main() { cin.tie(0); ios::sync_with_stdio(false); // input string s, t; cin >> s >> t; T.resize(26); map<char, ll> mp_s, mp_t; for (char c : s) { mp_s[c]++; } for (char c : t) { mp_t[c]++; } for (auto pa : mp_t) { char c = pa.first; if (mp_s.count(c) == 0) { p(-1); return 0; } } // p("作れる"); string s2 = s + s; ll L = s2.size(); rep(i, L) { char c = s2[i]; ll v = c - 'a'; T[v].push_back(i); } ll ans = 0; ll pos = -1; rep(i, t.size()) { char c = t[i]; ll v = c - 'a'; // 今の位置からcを探す auto it = upper_bound(ALL(T[v]), pos); ll diff = (*it) - pos; ans += diff; pos += diff; pos %= s.size(); } p(ans); return 0; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operation.binary.remove" ]
740,825
740,826
u432688695
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; char buf[100100]; int nxt[30][100100]; string s, t; string s2; int n, m; int main() { scanf("%s", buf); s = buf; n = s.size(); s2 = s + s; scanf("%s", buf); t = buf; m = t.size(); rep(num, 26) { char now = num + 'a'; bool has = 0, need = 0; rep(i, n) has |= (s[i] == now); rep(i, m) need |= (t[i] == now); if (need && !has) { cout << "-1" << endl; return 0; } if (!has) continue; rep(i, n) { if (s2[n + i] == now) { nxt[num][i] = i; for (int j = n + i - 1; s2[j] != now; j--) { nxt[num][j % n] = i; } } } } long long num = 0ll, ans = 0ll; int pos = -1; rep(i, m) { int to = nxt[t[i] - 'a'][(pos + 1) % n]; if (to < pos) num++; pos = to; ans = to; } cout << n * num + ans + 1 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; char buf[100100]; int nxt[30][100100]; string s, t; string s2; int n, m; int main() { scanf("%s", buf); s = buf; n = s.size(); s2 = s + s; scanf("%s", buf); t = buf; m = t.size(); rep(num, 26) { char now = num + 'a'; bool has = 0, need = 0; rep(i, n) has |= (s[i] == now); rep(i, m) need |= (t[i] == now); if (need && !has) { cout << "-1" << endl; return 0; } if (!has) continue; rep(i, n) { if (s2[n + i] == now) { nxt[num][i] = i; for (int j = n + i - 1; s2[j] != now; j--) { nxt[num][j % n] = i; } } } } long long num = 0ll, ans = 0ll; int pos = -1; rep(i, m) { int to = nxt[t[i] - 'a'][(pos + 1) % n]; if (to <= pos) num++; pos = to; ans = to; } cout << n * num + ans + 1 << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,827
740,828
u083800325
cpp
p02937
#include <bits/stdc++.h> #define int long long #define MAXN 200010 using namespace std; int n, m, A[30][MAXN]; char S[MAXN], T[MAXN]; long long ans; bool vis[30]; signed main() { scanf("%s", S + 1); n = strlen(S + 1); scanf("%s", T + 1); m = strlen(T + 1); for (int i = 1; i <= n; i++) { int num = S[i] - 'a' + 1; A[num][++A[num][0]] = i; vis[num] = true; } int la = 0; for (int i = 1; i <= m; i++) { int num = T[i] - 'a' + 1; if (vis[num] == false) { puts("-1"); return 0; } int p = lower_bound(A[num] + 1, A[num] + 1 + A[num][0], la) - A[num]; if (p == A[num][0] + 1) { ans = ((ans / n) + 1) * 1LL * n; la = A[num][1]; } else la = A[num][p]; } ans += la; printf("%lld", ans); return 0; }
#include <bits/stdc++.h> #define int long long #define MAXN 200010 using namespace std; int n, m, A[30][MAXN]; char S[MAXN], T[MAXN]; long long ans; bool vis[30]; signed main() { scanf("%s", S + 1); n = strlen(S + 1); scanf("%s", T + 1); m = strlen(T + 1); for (int i = 1; i <= n; i++) { int num = S[i] - 'a' + 1; A[num][++A[num][0]] = i; vis[num] = true; } int la = 0; for (int i = 1; i <= m; i++) { int num = T[i] - 'a' + 1; if (vis[num] == false) { puts("-1"); return 0; } int p = upper_bound(A[num] + 1, A[num] + 1 + A[num][0], la) - A[num]; if (p == A[num][0] + 1) { ans = ((ans / n) + 1) * 1LL * n; la = A[num][1]; } else la = A[num][p]; } ans += la; printf("%lld", ans); return 0; }
[ "identifier.change", "call.function.change", "expression.operation.binary.change" ]
740,829
740,830
u047371023
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define REP(i, a, n) for (int i = a; i < n; ++i) #define REPR(i, a, n) for (int i = a; i > n; --i) #define RUP(a, b) ((a + b - 1) / (b)) #define ALL(v) (v).begin(), (v).end() #define pb push_back #define mp make_pair #define mt make_tuple typedef long long ll; typedef pair<int, int> Pii; typedef tuple<int, int, int> Tiii; typedef vector<int> Vi; typedef vector<Vi> VVi; typedef vector<Pii> VPii; typedef vector<string> Vs; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> void YesNo(T a) { cout << (a ? "Yes" : "No") << endl; } template <class T> void YESNO(T a) { cout << (a ? "YES" : "NO") << endl; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } void uniq(Vi &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); string s, t; int ans = 0; cin >> s >> t; map<char, Vi> ma; map<char, int> mab; REP(i, 0, s.size()) { ma[s[i]].pb(i + 1); mab[s[i]]++; } int now = 0; REP(i, 0, t.size()) { if (mab[t[i]] == 0) { cout << -1 << endl; return 0; } auto iter = lower_bound(ALL(ma[t[i]]), now); if (iter == ma[t[i]].end()) { ans += s.size(); now = ma[t[i]][0]; } else { now = *iter; } } cout << ans + now << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define REP(i, a, n) for (int i = a; i < n; ++i) #define REPR(i, a, n) for (int i = a; i > n; --i) #define RUP(a, b) ((a + b - 1) / (b)) #define ALL(v) (v).begin(), (v).end() #define pb push_back #define mp make_pair #define mt make_tuple typedef long long ll; typedef pair<int, int> Pii; typedef tuple<int, int, int> Tiii; typedef vector<int> Vi; typedef vector<Vi> VVi; typedef vector<Pii> VPii; typedef vector<string> Vs; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> void YesNo(T a) { cout << (a ? "Yes" : "No") << endl; } template <class T> void YESNO(T a) { cout << (a ? "YES" : "NO") << endl; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } void uniq(Vi &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); string s, t; int ans = 0; cin >> s >> t; map<char, Vi> ma; map<char, int> mab; REP(i, 0, s.size()) { ma[s[i]].pb(i + 1); mab[s[i]]++; } int now = 0; REP(i, 0, t.size()) { if (mab[t[i]] == 0) { cout << -1 << endl; return 0; } auto iter = upper_bound(ALL(ma[t[i]]), now); if (iter == ma[t[i]].end()) { ans += s.size(); now = ma[t[i]][0]; } else { now = *iter; } } cout << ans + now << endl; return 0; }
[ "identifier.change", "call.function.change" ]
740,831
740,832
u635484372
cpp
p02937
#include <bits/stdc++.h> #define pb push_back #define mp make_pair typedef long long int ll; using namespace std; string s, t; ll n; ll nextIndex[26][100000]; int main() { cin >> s >> t; n = s.size(); for (int i = 0; i < 26; i++) { vector<ll> shown; for (int j = 0; j < n; j++) if (s[j] == 'a' + i) shown.pb(j); if (shown.size() == 0) for (int j = 0; j < n; j++) nextIndex[i][j] = -1; else { int offs = 0; for (int j = 0; j < n; j++) { if (j == shown[offs]) offs = (offs + 1) % shown.size(); nextIndex[i][j] = shown[offs]; } } } ll ans = -n; ll now = n - 1; for (int i = 0; i < t.size(); i++) { ll next = nextIndex[t[i] - 'a'][now]; // cerr << next << endl; if (next == -1) { cout << -1 << endl; return 0; } if (now > next) ans += n; now = next; } ans += 1 + now; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair typedef long long int ll; using namespace std; string s, t; ll n; ll nextIndex[26][100000]; int main() { cin >> s >> t; n = s.size(); for (int i = 0; i < 26; i++) { vector<ll> shown; for (int j = 0; j < n; j++) if (s[j] == 'a' + i) shown.pb(j); if (shown.size() == 0) for (int j = 0; j < n; j++) nextIndex[i][j] = -1; else { int offs = 0; for (int j = 0; j < n; j++) { if (j == shown[offs]) offs = (offs + 1) % shown.size(); nextIndex[i][j] = shown[offs]; } } } ll ans = -n; ll now = n - 1; for (int i = 0; i < t.size(); i++) { ll next = nextIndex[t[i] - 'a'][now]; // cerr << next << endl; if (next == -1) { cout << -1 << endl; return 0; } if (now >= next) ans += n; now = next; } ans += 1 + now; cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,844
740,845
u628262476
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define DEBUG(x) cout << #x << ": " << (x) << '\n' #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << ' ' << v[i]; \ cout << '\n' #define ALL(a) (a).begin(), (a).end() template <typename T> inline void CHMAX(T &a, const T b) { if (a < b) a = b; } template <typename T> inline void CHMIN(T &a, const T b) { if (a > b) a = b; } constexpr ll MOD = 1000000007ll; // constexpr ll MOD=998244353ll; #define FIX(a) ((a) % MOD + MOD) % MOD const double EPS = 1e-11; #define EQ0(x) (abs((x)) < EPS) #define EQ(a, b) (abs((a) - (b)) < EPS) int num1[30]; int num2[30]; constexpr int INF = 1e9; int main() { ios::sync_with_stdio(false); cin.tie(0); // cout<<setprecision(10)<<fixed; string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vi a[30]; REP(i, n) { ++num1[s[i] - 'a']; a[s[i] - 'a'].push_back(i + 1); } REP(i, m) { ++num2[t[i] - 'a']; } REP(i, 30) { if (num1[i] == 0 && num2[i] > 0) { cout << -1 << '\n'; return 0; } } REP(i, 30) { a[i].push_back(INF); } ll ans = 0; int crt = 0; REP(i, m) { int tmp1 = *lower_bound(ALL(a[t[i] - 'a']), crt); int tmp2 = *lower_bound(ALL(a[t[i] - 'a']), 0); // DEBUG(tmp1); // DEBUG(tmp2); if (tmp1 == INF) { ans += n - crt + tmp2; crt = tmp2; } else { ans += tmp1 - crt; crt = tmp1; } // DEBUG(ans); } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define DEBUG(x) cout << #x << ": " << (x) << '\n' #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << ' ' << v[i]; \ cout << '\n' #define ALL(a) (a).begin(), (a).end() template <typename T> inline void CHMAX(T &a, const T b) { if (a < b) a = b; } template <typename T> inline void CHMIN(T &a, const T b) { if (a > b) a = b; } constexpr ll MOD = 1000000007ll; // constexpr ll MOD=998244353ll; #define FIX(a) ((a) % MOD + MOD) % MOD const double EPS = 1e-11; #define EQ0(x) (abs((x)) < EPS) #define EQ(a, b) (abs((a) - (b)) < EPS) int num1[30]; int num2[30]; constexpr int INF = 1e9; int main() { ios::sync_with_stdio(false); cin.tie(0); // cout<<setprecision(10)<<fixed; string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vi a[30]; REP(i, n) { ++num1[s[i] - 'a']; a[s[i] - 'a'].push_back(i + 1); } REP(i, m) { ++num2[t[i] - 'a']; } REP(i, 30) { if (num1[i] == 0 && num2[i] > 0) { cout << -1 << '\n'; return 0; } } REP(i, 30) { a[i].push_back(INF); } ll ans = 0; int crt = 0; REP(i, m) { int tmp1 = *upper_bound(ALL(a[t[i] - 'a']), crt); int tmp2 = *upper_bound(ALL(a[t[i] - 'a']), 0); // DEBUG(tmp1); // DEBUG(tmp2); if (tmp1 == INF) { ans += n - crt + tmp2; crt = tmp2; } else { ans += tmp1 - crt; crt = tmp1; } // DEBUG(ans); } cout << ans << '\n'; return 0; }
[ "identifier.change", "call.function.change" ]
740,846
740,847
u833393891
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pic pair<int, char> #define pci pair<char, int> #define pll pair<ll, ll> #define plc pair<ll, char> #define pcl pair<char, ll> #define vi vector<int> #define vl vector<ll> #define vii vector<pii> #define vll vector<pll> #define vic vector<pic> #define vci vector<pci> #define vlc vector<plc> #define vcl vector<pcl> #define pb push_back const ll MOD = 1e9 + 7; const ll MAXN = 1e5 + 3; const ll MAXM = 1e5 + 3; vector<int> idxs[32]; int brt[32]; int brs[32]; string s; string t; int bs(vector<int> v, int val) { int l = 0, r = v.size() - 1, m, ans = -1; while (l <= r) { m = (l + r) / 2; if (v[m] > val) { ans = m; r = m - 1; } else l = m + 1; } // cout<<ans<<endl; return ans; } bool b2[32]; void solve() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> s; cin >> t; int tsize = t.size(); int ssize = s.size(); for (int i = 0; i < ssize; ++i) { idxs[s[i] - 'a'].push_back(i); b2[s[i] - 'a'] = 1; } for (int i = 0; i < tsize; ++i) { if (b2[t[i] - 'a'] == 0) { cout << "-1\n"; return; } } int last = -1, l1 = 0, r2 = -1; for (int i = 0; i < tsize; ++i) { if (i != 0 && t[i] == t[i - 1]) { if (r2 == idxs[t[i] - 'a'].size() - 1) { last = idxs[t[i] - 'a'][0]; l1++; r2 = 0; } else { last = idxs[t[i] - 'a'][r2 + 1]; r2++; } } if (idxs[t[i] - 'a'][idxs[t[i] - 'a'].size() - 1] <= last) { last = idxs[t[i] - 'a'][0]; ++l1; r2 = 0; } else { int r1 = bs(idxs[t[i] - 'a'], last); last = idxs[t[i] - 'a'][r1]; r2 = r1; } } cout << (ll)((ll)last + (ll)l1 * ssize + 1ll) << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pic pair<int, char> #define pci pair<char, int> #define pll pair<ll, ll> #define plc pair<ll, char> #define pcl pair<char, ll> #define vi vector<int> #define vl vector<ll> #define vii vector<pii> #define vll vector<pll> #define vic vector<pic> #define vci vector<pci> #define vlc vector<plc> #define vcl vector<pcl> #define pb push_back const ll MOD = 1e9 + 7; const ll MAXN = 1e5 + 3; const ll MAXM = 1e5 + 3; vector<int> idxs[32]; int brt[32]; int brs[32]; string s; string t; int bs(vector<int> v, int val) { int l = 0, r = v.size() - 1, m, ans = -1; while (l <= r) { m = (l + r) / 2; if (v[m] > val) { ans = m; r = m - 1; } else l = m + 1; } // cout<<ans<<endl; return ans; } bool b2[32]; void solve() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> s; cin >> t; int tsize = t.size(); int ssize = s.size(); for (int i = 0; i < ssize; ++i) { idxs[s[i] - 'a'].push_back(i); b2[s[i] - 'a'] = 1; } for (int i = 0; i < tsize; ++i) { if (b2[t[i] - 'a'] == 0) { cout << "-1\n"; return; } } int last = -1, l1 = 0, r2 = -1; for (int i = 0; i < tsize; ++i) { if (i != 0 && t[i] == t[i - 1]) { if (r2 == idxs[t[i] - 'a'].size() - 1) { last = idxs[t[i] - 'a'][0]; l1++; r2 = 0; } else { last = idxs[t[i] - 'a'][r2 + 1]; r2++; } } else if (idxs[t[i] - 'a'][idxs[t[i] - 'a'].size() - 1] <= last) { last = idxs[t[i] - 'a'][0]; ++l1; r2 = 0; } else { int r1 = bs(idxs[t[i] - 'a'], last); last = idxs[t[i] - 'a'][r1]; r2 = r1; } } cout << (ll)((ll)last + (ll)l1 * ssize + 1ll) << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); return 0; }
[ "control_flow.branch.else_if.replace.add", "control_flow.branch.if.replace.remove" ]
740,848
740,849
u375708802
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; const ll INF = 1e18; bool isOK(int index, int key, vector<ll> &a) { /*indexが条件を満たすかどうかを判定(今回はkeyよりおおきいか)*/ if (a[index] > key) return true; else return false; } int binary_search(int key, vector<ll> &a) { int ng = -1; int ok = (int)a.size(); // okとngの初期値によって最大値だけでなく最小値も求められる. // ng=-1の時はkey以上の数値の最小値 while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, a)) ok = mid; else ng = mid; } return ok; } int main() { ll n, m, i, j, k; string s, t; cin >> s >> t; vector<vector<ll>> c(27); ll ss = s.size(); ll ts = t.size(); for (i = 0; i < ss; i++) { c[s[i] - 'a'].push_back(i); } ll now = 0; ll ret = 0; ll flag = 0; for (i = 0; i < ts; i++) { if (c[t[i] - 'a'].size() > 0) { flag = 1; } else { cout << -1 << endl; return 0; } ll ch = 0; /*for(j=0;j<c[t[i]-'a'].size();j++){ if(now<c[t[i]-'a'][j]){ ch = 1; now = c[t[i]-'a'][j]; break; } }*/ ch = binary_search(now, c[t[i] - 'a']); if (ch == c[t[i] - 'a'].size()) { now = c[t[i] - 'a'][0]; ret++; } else { now = c[t[i] - 'a'][ch]; } flag = 0; } cout << ret * (ll)ss + now + 1LL << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; const ll INF = 1e18; bool isOK(int index, int key, vector<ll> &a) { /*indexが条件を満たすかどうかを判定(今回はkeyよりおおきいか)*/ if (a[index] > key) return true; else return false; } int binary_search(int key, vector<ll> &a) { int ng = -1; int ok = (int)a.size(); // okとngの初期値によって最大値だけでなく最小値も求められる. // ng=-1の時はkey以上の数値の最小値 while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(mid, key, a)) ok = mid; else ng = mid; } return ok; } int main() { ll n, m, i, j, k; string s, t; cin >> s >> t; vector<vector<ll>> c(27); ll ss = s.size(); ll ts = t.size(); for (i = 0; i < ss; i++) { c[s[i] - 'a'].push_back(i + 1); } ll now = 0; ll ret = 0; ll flag = 0; for (i = 0; i < ts; i++) { if (c[t[i] - 'a'].size() > 0) { flag = 1; } else { cout << -1 << endl; return 0; } ll ch = 0; /*for(j=0;j<c[t[i]-'a'].size();j++){ if(now<c[t[i]-'a'][j]){ ch = 1; now = c[t[i]-'a'][j]; break; } }*/ ch = binary_search(now, c[t[i] - 'a']); if (ch == c[t[i] - 'a'].size()) { now = c[t[i] - 'a'][0]; ret++; } else { now = c[t[i] - 'a'][ch]; } flag = 0; // cout << now << endl; } cout << ret * (ll)ss + now << endl; return 0; }
[ "expression.operation.binary.remove" ]
740,852
740,853
u595893956
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = pow(10, 9) + 7; // const ll MOD = 998244353; // const ll MOD = ; ll mod(ll A, ll M) { return (A % M + M) % M; } const ll INF = 1LL << 60; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll divCeil(ll A, ll B) { return (A + (B - 1)) / B; } ll myctoi(char C) { return C - '0'; } char myitoc(ll N) { return '0' + N; } #define FINALANS(A) \ { \ cout << (A) << endl; \ exit(0); \ } int main() { string S, T; cin >> S >> T; ll N = S.size(); map<char, set<ll>> mp; for (ll i = 0; i < N; i++) { mp[S.at(i)].emplace(i); mp[S.at(i)].emplace(i + N); } ll ans = 0; for (ll i = 0; i < T.size(); i++) { if (mp[T.at(i)].size() == 0) FINALANS(-1); ll x = *(mp[T.at(i)].upper_bound(ans % N)); // cerr << ans << " " << x << endl; ans = ans / N * N + x; } ans++; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = pow(10, 9) + 7; // const ll MOD = 998244353; // const ll MOD = ; ll mod(ll A, ll M) { return (A % M + M) % M; } const ll INF = 1LL << 60; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll divCeil(ll A, ll B) { return (A + (B - 1)) / B; } ll myctoi(char C) { return C - '0'; } char myitoc(ll N) { return '0' + N; } #define FINALANS(A) \ { \ cout << (A) << endl; \ exit(0); \ } int main() { string S, T; cin >> S >> T; ll N = S.size(); map<char, set<ll>> mp; for (ll i = 0; i < N; i++) { mp[S.at(i)].emplace(i); mp[S.at(i)].emplace(i + N); } ll ans = -1; for (ll i = 0; i < T.size(); i++) { if (mp[T.at(i)].size() == 0) FINALANS(-1); ll x = *(mp[T.at(i)].upper_bound(ans % N)); // cerr << ans << " " << x << endl; ans = ans / N * N + x; } ans++; cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,856
740,857
u811472478
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = pow(10, 9) + 7; // const ll MOD = 998244353; // const ll MOD = ; ll mod(ll A, ll M) { return (A % M + M) % M; } const ll INF = 1LL << 60; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll divCeil(ll A, ll B) { return (A + (B - 1)) / B; } ll myctoi(char C) { return C - '0'; } char myitoc(ll N) { return '0' + N; } #define FINALANS(A) \ { \ cout << (A) << endl; \ exit(0); \ } int main() { string S, T; cin >> S >> T; ll N = S.size(); map<char, set<ll>> mp; for (ll i = 0; i < N; i++) { mp[S.at(i)].emplace(i); mp[S.at(i)].emplace(i + N); } ll ans = 0; for (ll i = 0; i < T.size(); i++) { if (mp[T.at(i)].size() == 0) FINALANS(-1); ll x = *(mp[T.at(i)].lower_bound(ans % N)); // cerr << ans << " " << x << endl; ans = ans / N * N + x; } ans++; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = pow(10, 9) + 7; // const ll MOD = 998244353; // const ll MOD = ; ll mod(ll A, ll M) { return (A % M + M) % M; } const ll INF = 1LL << 60; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll divCeil(ll A, ll B) { return (A + (B - 1)) / B; } ll myctoi(char C) { return C - '0'; } char myitoc(ll N) { return '0' + N; } #define FINALANS(A) \ { \ cout << (A) << endl; \ exit(0); \ } int main() { string S, T; cin >> S >> T; ll N = S.size(); map<char, set<ll>> mp; for (ll i = 0; i < N; i++) { mp[S.at(i)].emplace(i); mp[S.at(i)].emplace(i + N); } ll ans = -1; for (ll i = 0; i < T.size(); i++) { if (mp[T.at(i)].size() == 0) FINALANS(-1); ll x = *(mp[T.at(i)].upper_bound(ans % N)); // cerr << ans << " " << x << endl; ans = ans / N * N + x; } ans++; cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change", "call.function.change" ]
740,858
740,857
u811472478
cpp
p02937
#include <algorithm> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; unordered_map<char, vector<int>> pos; int main() { string s, t; cin >> s >> t; const ull N = s.size(); for (ull i = 0; i < N; ++i) { pos[s[i]].push_back(i); } ull ans = 0; int last = 0; for (auto c : t) { auto &p = pos[c]; if (p.empty()) { cout << -1 << endl; return 0; } auto it = upper_bound(p.begin(), p.end(), last); if (it == p.end()) { ans += N; last = *p.begin(); } else { last = *it; } } cout << ans + last + 1 << endl; }
#include <algorithm> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; using ull = unsigned long long; unordered_map<char, vector<int>> pos; int main() { string s, t; cin >> s >> t; const ull N = s.size(); for (ull i = 0; i < N; ++i) { pos[s[i]].push_back(i + 1); } ull ans = 0; int last = 0; for (auto c : t) { auto &p = pos[c]; if (p.empty()) { cout << -1 << endl; return 0; } auto it = upper_bound(p.begin(), p.end(), last); if (it == p.end()) { ans += N; last = *p.begin(); } else { last = *it; } } cout << ans + last << endl; }
[ "expression.operation.binary.remove" ]
740,859
740,860
u419944616
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1LL << 60; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); vector<vector<ll>> ord(26); string s, t; cin >> s >> t; int tmp; for (int i = 0; i < s.length(); i++) { tmp = s[i] - 'a'; ord[tmp].push_back(i); } // t判定 bool ok = true; for (int i = 0; i < t.length(); i++) { tmp = t[i] - 'a'; if (ord[tmp].size() == 0) { ok = false; break; } } if (ok) { ll cur = 0; ll cnt_loop = 0; for (int i = 0; i < t.length(); i++) { tmp = t[i] - 'a'; auto itr = lower_bound(ord[tmp].begin(), ord[tmp].end(), cur); if (itr == ord[tmp].end()) { cur = ord[tmp][0]; cnt_loop++; } else { if (cur == *itr) { itr++; if (itr == ord[tmp].end()) { cur = ord[tmp][0]; cnt_loop++; } else { cur = *itr; } } else { cur = *itr; } } } ll ans = (cnt_loop * s.length() + cur + 1); cout << ans << endl; } else { cout << -1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1LL << 60; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); vector<vector<ll>> ord(26); string s, t; cin >> s >> t; int tmp; for (int i = 0; i < s.length(); i++) { tmp = s[i] - 'a'; ord[tmp].push_back(i); } // t判定 bool ok = true; for (int i = 0; i < t.length(); i++) { tmp = t[i] - 'a'; if (ord[tmp].size() == 0) { ok = false; break; } } if (ok) { ll cur = -1; ll cnt_loop = 0; for (int i = 0; i < t.length(); i++) { tmp = t[i] - 'a'; auto itr = lower_bound(ord[tmp].begin(), ord[tmp].end(), cur); if (itr == ord[tmp].end()) { cur = ord[tmp][0]; cnt_loop++; } else { if (cur == *itr) { itr++; if (itr == ord[tmp].end()) { cur = ord[tmp][0]; cnt_loop++; } else { cur = *itr; } } else { cur = *itr; } } } ll ans = (cnt_loop * s.length() + cur + 1); cout << ans << endl; } else { cout << -1 << endl; } return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,861
740,862
u187878098
cpp
p02937
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define MOD 1000000007 using namespace std; typedef pair<int, int> P; typedef pair<long long, long long> LLP; int main() { string s, t; cin >> s >> t; vector<int> appear[26]; for (int i = 0; i < s.length(); i++) { appear[s[i] - 'a'].push_back(i); } bool isPossible = true; for (int i = 0; i < t.length(); i++) { if (appear[t[i] - 'a'].size() <= 0) isPossible = false; } if (isPossible) { long long ans = 0; int nowIndex = appear[t[0] - 'a'][0]; ans += nowIndex; for (int i = 1; i < t.length(); i++) { vector<int>::iterator it = lower_bound( appear[t[i] - 'a'].begin(), appear[t[i] - 'a'].end(), nowIndex); if (it != appear[t[i] - 'a'].end()) { ans += *it - nowIndex; nowIndex = *it; } else { ans += s.length() - nowIndex + appear[t[i] - 'a'][0]; nowIndex = appear[t[i] - 'a'][0]; } } cout << ans + 1 << endl; } else { cout << -1 << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define MOD 1000000007 using namespace std; typedef pair<int, int> P; typedef pair<long long, long long> LLP; int main() { string s, t; cin >> s >> t; vector<int> appear[26]; for (int i = 0; i < s.length(); i++) { appear[s[i] - 'a'].push_back(i); } bool isPossible = true; for (int i = 0; i < t.length(); i++) { if (appear[t[i] - 'a'].size() <= 0) isPossible = false; } if (isPossible) { long long ans = 0; int nowIndex = appear[t[0] - 'a'][0]; ans += nowIndex; for (int i = 1; i < t.length(); i++) { vector<int>::iterator it = upper_bound( appear[t[i] - 'a'].begin(), appear[t[i] - 'a'].end(), nowIndex); if (it != appear[t[i] - 'a'].end()) { ans += *it - nowIndex; nowIndex = *it; } else { ans += s.length() - nowIndex + appear[t[i] - 'a'][0]; nowIndex = appear[t[i] - 'a'][0]; } } cout << ans + 1 << endl; } else { cout << -1 << endl; } return 0; }
[ "identifier.change", "call.function.change" ]
740,863
740,864
u997325490
cpp
p02937
#include <algorithm> #include <array> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; #define Rep(i, a, b) for (int i = a; i < b; i++) #define rep(i, b) Rep(i, 0, b) #define allof(a) (a).begin(), (a).end() typedef long long ll; const int inf = 1e9 + 7; const ll infll = 1ll << 60ll; const ll mod = 1e9 + 7; // 0~3までは右左下上 4~7までは斜め constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1}; namespace { // 名前なし名前空間 // gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意 // 最大公約数 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; } } // namespace int main() { string s; cin >> s; string t; cin >> t; int sn = (int)s.size(); int tn = (int)t.size(); // tのすべての文字がsに含まれていないなら-1 それ以外は答えある vector<int> cnum(26, 0); rep(i, sn) { cnum[s[i] - 'a']++; } rep(i, tn) { if (cnum[t[i] - 'a'] == 0) { cout << -1 << endl; return 0; } } // 左から貪欲に見ていく int left = 0; // それぞれの文字がどこにあるのか記録しておく vector<vector<int>> c(26, vector<int>()); rep(i, sn) { c[s[i] - 'a'].push_back(i + 1); } ll ans = 0; ll pos = 0; while (left != tn) { int size = (int)c[t[left] - 'a'].size(); // 2分探索 if (size != 0) { ll ma = c[t[left] - 'a'][size - 1]; // cout << pos << " " << ma << endl; if (pos > ma) { ans += (ll)sn - pos; // ここ怪しい // posを先頭に戻してる pos = c[t[left] - 'a'][0]; // 最初の文字のところへ ans += pos; left++; // << "a" << " " << ans << endl; continue; } } ll next = *lower_bound(allof(c[t[left] - 'a']), pos); ans += next - pos; pos = next; left++; // << "b " << ans << endl; } cout << ans << endl; return 0; }
#include <algorithm> #include <array> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; #define Rep(i, a, b) for (int i = a; i < b; i++) #define rep(i, b) Rep(i, 0, b) #define allof(a) (a).begin(), (a).end() typedef long long ll; const int inf = 1e9 + 7; const ll infll = 1ll << 60ll; const ll mod = 1e9 + 7; // 0~3までは右左下上 4~7までは斜め constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1}; namespace { // 名前なし名前空間 // gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意 // 最大公約数 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; } } // namespace int main() { string s; cin >> s; string t; cin >> t; int sn = (int)s.size(); int tn = (int)t.size(); // tのすべての文字がsに含まれていないなら-1 それ以外は答えある vector<int> cnum(26, 0); rep(i, sn) { cnum[s[i] - 'a']++; } rep(i, tn) { if (cnum[t[i] - 'a'] == 0) { cout << -1 << endl; return 0; } } // 左から貪欲に見ていく int left = 0; // それぞれの文字がどこにあるのか記録しておく vector<vector<int>> c(26, vector<int>()); rep(i, sn) { c[s[i] - 'a'].push_back(i + 1); } ll ans = 0; ll pos = 0; while (left != tn) { int size = (int)c[t[left] - 'a'].size(); // 2分探索 if (size != 0) { ll ma = c[t[left] - 'a'][size - 1]; // cout << pos << " " << ma << endl; if (pos >= ma) { ans += (ll)sn - pos; // ここ怪しい // posを先頭に戻してる pos = c[t[left] - 'a'][0]; // 最初の文字のところへ ans += pos; left++; // << "a" << " " << ans << endl; continue; } } ll next = *upper_bound(allof(c[t[left] - 'a']), pos); ans += next - pos; pos = next; left++; // << "b " << ans << endl; } cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "identifier.change", "call.function.change" ]
740,869
740,870
u725458677
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; vector<long int> x[26]; // cout<<s<<endl; for (long int i = 0; i < s.length(); i++) { // cout<<s[i]<<endl; x[s[i] - 'a'].push_back(i + 1); } long long int ans = 0; long int temp1 = 1; long int ans1 = INT_MAX; for (long int i = 0; i < t.length(); i++) { ans1 = INT_MAX; long int l = 0, r = x[t[i] - 'a'].size() - 1; while (l <= r) { long int mid = (l + r) / 2; if (x[t[i] - 'a'][mid] >= temp1) { ans1 = min(ans1, x[t[i] - 'a'][mid]); r = mid - 1; } else l = mid + 1; } // cout<<ans1<<endl; if (ans1 == INT_MAX) { ans += temp1; ans = ((ans - 1) / s.length() + 1) * s.length(); temp1 = 1; long int l = 0, r = x[t[i] - 'a'].size() - 1; while (l <= r) { long int mid = (l + r) / 2; if (x[t[i] - 'a'][mid] >= temp1) { ans1 = min(ans1, x[t[i] - 'a'][mid]); r = mid - 1; } else l = mid + 1; } } if (ans1 == INT_MAX) break; temp1 = ans1; temp1++; // cout<<ans1<<" "<<ans<<endl; } if (ans1 == INT_MAX) cout << "-1"; else cout << ans + temp1 - 1; }
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; vector<long int> x[26]; // cout<<s<<endl; for (long int i = 0; i < s.length(); i++) { // cout<<s[i]<<endl; x[s[i] - 'a'].push_back(i + 1); } long long int ans = 0; long int temp1 = 1; long int ans1 = INT_MAX; for (long int i = 0; i < t.length(); i++) { ans1 = INT_MAX; long int l = 0, r = x[t[i] - 'a'].size() - 1; while (l <= r) { long int mid = (l + r) / 2; if (x[t[i] - 'a'][mid] >= temp1) { ans1 = min(ans1, x[t[i] - 'a'][mid]); r = mid - 1; } else l = mid + 1; } // cout<<ans1<<endl; if (ans1 == INT_MAX) { ans += temp1 - 1; ans = ((ans - 1) / s.length() + 1) * s.length(); temp1 = 1; long int l = 0, r = x[t[i] - 'a'].size() - 1; while (l <= r) { long int mid = (l + r) / 2; if (x[t[i] - 'a'][mid] >= temp1) { ans1 = min(ans1, x[t[i] - 'a'][mid]); r = mid - 1; } else l = mid + 1; } } if (ans1 == INT_MAX) break; temp1 = ans1; temp1++; // cout<<ans1<<" "<<ans<<endl; } if (ans1 == INT_MAX) cout << "-1"; else cout << ans + temp1 - 1; }
[ "assignment.change" ]
740,877
740,878
u492448945
cpp
p02937
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #define LL long long using namespace std; long long vis[200]; char s[200010], t[200010]; long long id[27][200010]; int main() { long long lens, lent, i, j; scanf("%s", s), lens = strlen(s); scanf("%s", t), lent = strlen(t); for (i = 0; i < lens; i++) { id[s[i] - 'a'][++id[s[i] - 'a'][0]] = i; vis[s[i]] = 1; } for (i = 0; i < lent; i++) if (!vis[t[i]]) { printf("-1\n"); return 0; } long long tem = -1; long long ans = 0; for (i = 0; i < lent; i++) { if (id[t[i] - 'a'][id[t[i] - 'a'][0]] < tem) { ans += 1ll * (lens - tem + id[t[i] - 'a'][1]); tem = id[t[i] - 'a'][1]; } else { long long l = 1, r = id[t[i] - 'a'][0], mid; mid = (l + r) >> 1; while (r - l >= 2) { if (id[t[i] - 'a'][mid] > tem) r = mid; else l = mid + 1; mid = (l + r) >> 1; } for (mid = l; mid <= r; mid++) if (id[t[i] - 'a'][mid] > tem) break; ans += 1ll * (id[t[i] - 'a'][mid] - tem); tem = id[t[i] - 'a'][mid]; } } printf("%lld\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #define LL long long using namespace std; long long vis[200]; char s[200010], t[200010]; long long id[27][200010]; int main() { long long lens, lent, i, j; scanf("%s", s), lens = strlen(s); scanf("%s", t), lent = strlen(t); for (i = 0; i < lens; i++) { id[s[i] - 'a'][++id[s[i] - 'a'][0]] = i; vis[s[i]] = 1; } for (i = 0; i < lent; i++) if (!vis[t[i]]) { printf("-1\n"); return 0; } long long tem = -1; long long ans = 0; for (i = 0; i < lent; i++) { if (id[t[i] - 'a'][id[t[i] - 'a'][0]] <= tem) { ans += 1ll * (lens - tem + id[t[i] - 'a'][1]); tem = id[t[i] - 'a'][1]; } else { long long l = 1, r = id[t[i] - 'a'][0], mid; mid = (l + r) >> 1; while (r - l >= 2) { if (id[t[i] - 'a'][mid] > tem) r = mid; else l = mid + 1; mid = (l + r) >> 1; } for (mid = l; mid <= r; mid++) if (id[t[i] - 'a'][mid] > tem) break; ans += 1ll * (id[t[i] - 'a'][mid] - tem); tem = id[t[i] - 'a'][mid]; } } printf("%lld\n", ans); return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,879
740,880
u665380288
cpp
p02937
#include <bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define rep(i, n) for (auto i = 0; i < (n); i++) #define rep1(i, n) for (auto i = 1; i <= (n); i++) #define all(x) (x).begin(), (x).end() using namespace std; struct init { init() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } aaaaaaa; int main() { string s; string t; cin >> s >> t; ll n = s.size(); map<char, vector<ll>> ma; rep(i, 26) ma['a' + i] = vector<ll>(); rep(i, n) ma[s[i]].push_back(i); ll idx = 0; bool ok = true; ull cnt = 0; rep(i, t.size()) { if (ma[t[i]].empty()) { ok = false; break; } ll id = lower_bound(all(ma[t[i]]), idx) - ma[t[i]].begin(); if (id == ma[t[i]].size()) id = 0, cnt++; idx = ma[t[i]][id]; } if (!ok) cout << -1 << endl; else cout << cnt * (ull)s.size() + (ull)idx + 1 << endl; return 0; }
#include <bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define rep(i, n) for (auto i = 0; i < (n); i++) #define rep1(i, n) for (auto i = 1; i <= (n); i++) #define all(x) (x).begin(), (x).end() using namespace std; struct init { init() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } aaaaaaa; int main() { string s; string t; cin >> s >> t; ll n = s.size(); map<char, vector<ll>> ma; rep(i, 26) ma['a' + i] = vector<ll>(); rep(i, n) ma[s[i]].push_back(i); ll idx = -1; bool ok = true; ull cnt = 0; rep(i, t.size()) { if (ma[t[i]].empty()) { ok = false; break; } ll id = upper_bound(all(ma[t[i]]), idx) - ma[t[i]].begin(); if (id == ma[t[i]].size()) id = 0, cnt++; idx = ma[t[i]][id]; } if (!ok) cout << -1 << endl; else cout << cnt * (ull)s.size() + (ull)idx + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change", "expression.operation.binary.change" ]
740,883
740,884
u779159595
cpp
p02937
#include <cstdio> #include <cstring> #include <vector> const int MAXN = 1e5 + 5; int lenS, lenT, cur; char s[MAXN], t[MAXN]; std::vector<int> place[26]; int search(int key, int position) { int left = 0, right = place[position].size() - 1, tmpAns = -1; while (left <= right) { int mid = (left + right) >> 1; if (place[position][mid] > key) { right = mid - 1; tmpAns = mid; } else left = mid + 1; } return tmpAns; } int main() { scanf("%s%s", s + 1, t + 1); lenS = strlen(s + 1); lenT = strlen(t + 1); for (int i = 1; i <= lenS; ++i) { place[s[i] - 'a'].push_back(i); } for (int i = 1; i <= lenT; ++i) { int tmp = t[i] - 'a'; int k = search((cur % lenS == 0) ? lenS : cur % lenS, tmp); if (place[tmp].empty()) { printf("-1"); return 0; } if (k == -1) { if (cur % lenS == 0) cur += place[tmp][0]; else cur = cur + lenS - (cur % lenS - place[tmp][0]); } else cur += (place[tmp][0] - cur % lenS); } printf("%d", cur); return 0; }
#include <cstdio> #include <cstring> #include <vector> const int MAXN = 1e5 + 5; int lenS, lenT; long long int cur; char s[MAXN], t[MAXN]; std::vector<int> place[26]; int search(int key, int position) { int left = 0, right = place[position].size() - 1, tmpAns = -1; while (left <= right) { int mid = (left + right) >> 1; if (place[position][mid] > key) { right = mid - 1; tmpAns = mid; } else left = mid + 1; } return tmpAns; } int main() { scanf("%s%s", s + 1, t + 1); lenS = strlen(s + 1); lenT = strlen(t + 1); for (int i = 1; i <= lenS; ++i) { place[s[i] - 'a'].push_back(i); } for (int i = 1; i <= lenT; ++i) { int tmp = t[i] - 'a'; int k = search((cur % lenS == 0) ? lenS : cur % lenS, tmp); if (place[tmp].empty()) { printf("-1"); return 0; } if (k == -1) { if (cur % lenS == 0) cur += place[tmp][0]; else cur = cur + lenS - (cur % lenS - place[tmp][0]); } else cur += (place[tmp][k] - cur % lenS); } printf("%lld", cur); return 0; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change", "expression.operation.binary.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
740,904
740,903
u645561303
cpp
p02937
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() typedef vector<int> vi; typedef pair<int, int> ii; typedef long long ll; typedef long double ld; const int mod = 1e9 + 7; const ll inf = 3e18 + 5; int add(int a, int b) { return (a += b) < mod ? a : a - mod; } int mul(int a, int b) { return 1LL * a * b % mod; } vi inds[26]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; ll res = 0; int n = (int)s.size(); int m = (int)t.size(); for (int i = 0; i < n; i++) { inds[s[i] - 'a'].push_back(i); } int lst = -1; for (int i = 0; i < m; i++) { if (inds[t[i] - 'a'].empty()) return cout << -1, 0; int j = (int)(t[i] - 'a'); int ind = lower_bound(all(inds[j]), lst + 1) - inds[j].begin(); int cur = 0; if (ind == (int)inds[j].size()) cur = inds[j][0]; else cur = inds[j][ind]; if (cur < lst) { res += (n - lst - 1); res += cur + 1; } else { res += (cur - lst); } lst = cur; } cout << res; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() typedef vector<int> vi; typedef pair<int, int> ii; typedef long long ll; typedef long double ld; const int mod = 1e9 + 7; const ll inf = 3e18 + 5; int add(int a, int b) { return (a += b) < mod ? a : a - mod; } int mul(int a, int b) { return 1LL * a * b % mod; } vi inds[26]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; ll res = 0; int n = (int)s.size(); int m = (int)t.size(); for (int i = 0; i < n; i++) { inds[s[i] - 'a'].push_back(i); } int lst = -1; for (int i = 0; i < m; i++) { if (inds[t[i] - 'a'].empty()) return cout << -1, 0; int j = (int)(t[i] - 'a'); int ind = lower_bound(all(inds[j]), lst + 1) - inds[j].begin(); int cur = 0; if (ind == (int)inds[j].size()) cur = inds[j][0]; else cur = inds[j][ind]; if (cur <= lst) { res += (n - lst - 1); res += cur + 1; } else { res += (cur - lst); } lst = cur; } cout << res << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "io.output.newline.add" ]
740,905
740,906
u348155686
cpp
p02937
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; vector<long long> vec[30]; long long id[30], cur, l; int main() { string s, t; cin >> s >> t; long long n = s.size(); for (int i = 0; i < s.size(); i++) vec[s[i] - 'a'].push_back(i); for (int i = 0; i < t.size(); i++) { long long c = t[i] - 'a'; if (vec[c].empty()) return cout << -1 << endl, 0; if (vec[c].back() <= l) cur++, l = -1; l = *upper_bound(vec[c].begin(), vec[c].end(), l); } cout << cur * n + l + 1 << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; vector<long long> vec[30]; long long id[30], cur, l = -1; int main() { string s, t; cin >> s >> t; long long n = s.size(); for (int i = 0; i < s.size(); i++) vec[s[i] - 'a'].push_back(i); for (int i = 0; i < t.size(); i++) { long long c = t[i] - 'a'; if (vec[c].empty()) return cout << -1 << endl, 0; if (vec[c].back() <= l) cur++, l = -1; l = *upper_bound(vec[c].begin(), vec[c].end(), l); } cout << cur * n + l + 1 << endl; }
[ "variable_declaration.value.change" ]
740,907
740,908
u951561009
cpp
p02937
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; vector<long long> vec[30]; long long id[30], cur, l; int main() { string s, t; cin >> s >> t; long long n = s.size(); for (int i = 0; i < s.size(); i++) vec[s[i] - 'a'].push_back(i); for (int i = 0; i < t.size(); i++) { long long c = t[i] - 'a'; if (vec[c].empty()) return cout << -1 << endl, 0; if (vec[c].back() <= l) cur++, l = 0; l = *upper_bound(vec[c].begin(), vec[c].end(), l); } cout << cur * n + l + 1 << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; vector<long long> vec[30]; long long id[30], cur, l = -1; int main() { string s, t; cin >> s >> t; long long n = s.size(); for (int i = 0; i < s.size(); i++) vec[s[i] - 'a'].push_back(i); for (int i = 0; i < t.size(); i++) { long long c = t[i] - 'a'; if (vec[c].empty()) return cout << -1 << endl, 0; if (vec[c].back() <= l) cur++, l = -1; l = *upper_bound(vec[c].begin(), vec[c].end(), l); } cout << cur * n + l + 1 << endl; }
[ "variable_declaration.value.change", "literal.number.change", "assignment.value.change" ]
740,909
740,908
u951561009
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define ll long long int #define mm 1000000007 #define pb push_back // nestedcode int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s, t; ll n, nn, i, p = -1, ans = 0; map<char, vector<ll>> m; cin >> s >> t; n = s.length(); nn = t.length(); for (i = 0; i < n; i++) { m[s[i]].pb(i); } for (i = 0; i < nn; i++) { if (m[t[i]].size() == 0) { cout << -1; return 0; } p = (upper_bound(m[t[i]].begin(), m[t[i]].end(), p) - m[t[i]].begin()); if (p == m[t[i]].size()) { ans++; p = m[t[i]][0]; } else { p = m[t[i]][p]; } // cout<<p<<endl; } cout << ans * n + p << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define mm 1000000007 #define pb push_back // nestedcode int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s, t; ll n, nn, i, p = -1, ans = 0; map<char, vector<ll>> m; cin >> s >> t; n = s.length(); nn = t.length(); for (i = 0; i < n; i++) { m[s[i]].pb(i); } for (i = 0; i < nn; i++) { if (m[t[i]].size() == 0) { cout << -1; return 0; } p = (upper_bound(m[t[i]].begin(), m[t[i]].end(), p) - m[t[i]].begin()); if (p == m[t[i]].size()) { ans++; p = m[t[i]][0]; } else { p = m[t[i]][p]; } // cout<<p<<endl; } cout << ans * n + p + 1 << endl; }
[ "expression.operation.binary.add" ]
740,915
740,916
u995107278
cpp
p02937
// // Created by Naman Bhalla on 2019-08-18. // #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); string s, t; cin >> s >> t; vector<vector<int>> ind(26); long long int n = s.size(); for (int i = 0; i < n; ++i) { ind[s[i] - 'a'].push_back(i); } int m = t.size(); long long int nums = 0; long long int li = -1; for (int i = 0; i < m; ++i) { int l = 0; int r = ind[t[i] - 'a'].size() - 1; if (r == -1) { cout << -1 << "\n"; return 0; } if (li > ind[t[i] - 'a'][r]) { li = -1; ++nums; } int ans = -1; int mid; while (l <= r) { mid = l + (r - l) / 2; if (ind[t[i] - 'a'][mid] > li) { ans = ind[t[i] - 'a'][mid]; r = mid - 1; } else { l = mid + 1; } } li = ans; } cout << nums * n + li + 1ll << "\n"; return 0; }
// // Created by Naman Bhalla on 2019-08-18. // #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); string s, t; cin >> s >> t; vector<vector<int>> ind(26); long long int n = s.size(); for (int i = 0; i < n; ++i) { ind[s[i] - 'a'].push_back(i); } int m = t.size(); long long int nums = 0; long long int li = -1; for (int i = 0; i < m; ++i) { int l = 0; int r = ind[t[i] - 'a'].size() - 1; if (r == -1) { cout << -1 << "\n"; return 0; } if (li >= ind[t[i] - 'a'][r]) { li = -1; ++nums; } int ans = -1; int mid; while (l <= r) { mid = l + (r - l) / 2; if (ind[t[i] - 'a'][mid] > li) { ans = ind[t[i] - 'a'][mid]; r = mid - 1; } else { l = mid + 1; } } li = ans; } cout << nums * n + li + 1ll << "\n"; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,917
740,918
u959910661
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; int main() { string s, t; cin >> s >> t; set<char> unique_char; for (auto c : s) { unique_char.insert(c); } bool isBad = false; for (auto c : t) { if (unique_char.count(c) == 0) isBad = true; } if (isBad) { cout << "-1" << endl; return 0; } vector<vector<ll>> s_map(26, vector<ll>()); for (int i = 0; i < s.size(); i++) { s_map[s[i] - 'a'].push_back(i); } ll res = 0; ll i_tmp = -1; for (int i = 0; i < t.size(); i++) { auto c = t[i] - 'a'; auto itr = lower_bound(s_map[c].begin(), s_map[c].end(), i_tmp); if (itr == s_map[c].end()) { res += s.size() - i_tmp - 1; i_tmp = -1; i--; } else { res += *itr - i_tmp; i_tmp = *itr; } } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; int main() { string s, t; cin >> s >> t; set<char> unique_char; for (auto c : s) { unique_char.insert(c); } bool isBad = false; for (auto c : t) { if (unique_char.count(c) == 0) isBad = true; } if (isBad) { cout << "-1" << endl; return 0; } vector<vector<ll>> s_map(26, vector<ll>()); for (int i = 0; i < s.size(); i++) { s_map[s[i] - 'a'].push_back(i); } ll res = 0; ll i_tmp = -1; for (int i = 0; i < t.size(); i++) { auto c = t[i] - 'a'; auto itr = lower_bound(s_map[c].begin(), s_map[c].end(), i_tmp + 1); if (itr == s_map[c].end()) { res += s.size() - i_tmp - 1; i_tmp = -1; i--; } else { res += *itr - i_tmp; i_tmp = *itr; } } cout << res << endl; return 0; }
[ "assignment.change" ]
740,924
740,925
u235057691
cpp
p02937
#include <bits/stdc++.h> #include <stdio.h> using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; #define SZ(a) int((a).size()) #define _REP(_1, _2, _3, _4, name, ...) name #define _REP4(i, b, e, s) \ for (decltype(e) _b = (b), _e = (e), i = _b + (0 < (s) ? 0 : (s)); \ (0 < (s) ? i < _e : _e <= i); i += (s)) #define _REP3(i, b, e) \ for (decltype(e) _b = (b), _e = (e), i = (_b < _e ? _b : _b - 1); \ (_b < _e ? i < _e : _e <= i); (_b < _e ? i++ : i--)) #define _REP2(i, n) for (decltype(n) i = 0, _n = (n); i < _n; i++) #define _REP1(n) for (decltype(n) _i = 0, _n = (n); _i < _n; _i++) #define REP(...) _REP(__VA_ARGS__, _REP4, _REP3, _REP2, _REP1)(__VA_ARGS__) #define FOR(it, c) for (auto &&it = begin(c); it != end(c); it++) #define ROF(it, c) for (auto &&it = rbegin(c); it != rend(c); it++) #define EB emplace_back #define PB push_back #define MP make_pair #define MT make_tuple #define INT(n) \ int n; \ assert(0 < scanf("%d", &n)) #define AI(a, size, n) \ array<int, size> a; \ REP(i, n) { assert(0 < scanf("%d", &a[i])); } #define STR(s) \ string s; \ cin >> s int main() { STR(s); STR(t); int n = SZ(s), m = SZ(t); int idx = 0, cnt = 0; ll ans = 0; vector<vector<int>> v(26); REP(i, n) { v[s[i] - 'a'].PB(i); } REP(i, m) { int j = t[i] - 'a'; if (v[j].empty()) { ans = -1; break; } auto it = lower_bound(v[j].begin(), v[j].end(), idx + 1); if (it == v[j].end()) { cnt++; idx = v[j][0]; } else { idx = *it; } } if (ans == 0) { ans = (ll)cnt * n + idx + 1; } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> #include <stdio.h> using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; #define SZ(a) int((a).size()) #define _REP(_1, _2, _3, _4, name, ...) name #define _REP4(i, b, e, s) \ for (decltype(e) _b = (b), _e = (e), i = _b + (0 < (s) ? 0 : (s)); \ (0 < (s) ? i < _e : _e <= i); i += (s)) #define _REP3(i, b, e) \ for (decltype(e) _b = (b), _e = (e), i = (_b < _e ? _b : _b - 1); \ (_b < _e ? i < _e : _e <= i); (_b < _e ? i++ : i--)) #define _REP2(i, n) for (decltype(n) i = 0, _n = (n); i < _n; i++) #define _REP1(n) for (decltype(n) _i = 0, _n = (n); _i < _n; _i++) #define REP(...) _REP(__VA_ARGS__, _REP4, _REP3, _REP2, _REP1)(__VA_ARGS__) #define FOR(it, c) for (auto &&it = begin(c); it != end(c); it++) #define ROF(it, c) for (auto &&it = rbegin(c); it != rend(c); it++) #define EB emplace_back #define PB push_back #define MP make_pair #define MT make_tuple #define INT(n) \ int n; \ assert(0 < scanf("%d", &n)) #define AI(a, size, n) \ array<int, size> a; \ REP(i, n) { assert(0 < scanf("%d", &a[i])); } #define STR(s) \ string s; \ cin >> s int main() { STR(s); STR(t); int n = SZ(s), m = SZ(t); int idx = -1, cnt = 0; ll ans = 0; vector<vector<int>> v(26); REP(i, n) { v[s[i] - 'a'].PB(i); } REP(i, m) { int j = t[i] - 'a'; if (v[j].empty()) { ans = -1; break; } auto it = lower_bound(v[j].begin(), v[j].end(), idx + 1); if (it == v[j].end()) { cnt++; idx = v[j][0]; } else { idx = *it; } } if (ans == 0) { ans = (ll)cnt * n + idx + 1; } printf("%lld\n", ans); return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,933
740,934
u872191059
cpp
p02937
#include <bits/stdc++.h> #include <stdio.h> using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; #define SZ(a) int((a).size()) #define _REP(_1, _2, _3, _4, name, ...) name #define _REP4(i, b, e, s) \ for (decltype(e) _b = (b), _e = (e), i = _b + (0 < (s) ? 0 : (s)); \ (0 < (s) ? i < _e : _e <= i); i += (s)) #define _REP3(i, b, e) \ for (decltype(e) _b = (b), _e = (e), i = (_b < _e ? _b : _b - 1); \ (_b < _e ? i < _e : _e <= i); (_b < _e ? i++ : i--)) #define _REP2(i, n) for (decltype(n) i = 0, _n = (n); i < _n; i++) #define _REP1(n) for (decltype(n) _i = 0, _n = (n); _i < _n; _i++) #define REP(...) _REP(__VA_ARGS__, _REP4, _REP3, _REP2, _REP1)(__VA_ARGS__) #define FOR(it, c) for (auto &&it = begin(c); it != end(c); it++) #define ROF(it, c) for (auto &&it = rbegin(c); it != rend(c); it++) #define EB emplace_back #define PB push_back #define MP make_pair #define MT make_tuple #define INT(n) \ int n; \ assert(0 < scanf("%d", &n)) #define AI(a, size, n) \ array<int, size> a; \ REP(i, n) { assert(0 < scanf("%d", &a[i])); } #define STR(s) \ string s; \ cin >> s int main() { STR(s); STR(t); int n = SZ(s), m = SZ(t); int idx = 0, cnt = 0; ll ans = 0; vector<vector<int>> v(26); REP(i, n) { v[s[i] - 'a'].PB(i); } REP(i, m) { int j = t[i] - 'a'; if (v[j].empty()) { ans = -1; break; } auto it = lower_bound(v[j].begin(), v[j].end(), idx); if (it == v[j].end()) { cnt++; idx = v[j][0]; } else { idx = *it; } } if (ans == 0) { ans = (ll)cnt * n + idx + 1; } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> #include <stdio.h> using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned long long ull; #define SZ(a) int((a).size()) #define _REP(_1, _2, _3, _4, name, ...) name #define _REP4(i, b, e, s) \ for (decltype(e) _b = (b), _e = (e), i = _b + (0 < (s) ? 0 : (s)); \ (0 < (s) ? i < _e : _e <= i); i += (s)) #define _REP3(i, b, e) \ for (decltype(e) _b = (b), _e = (e), i = (_b < _e ? _b : _b - 1); \ (_b < _e ? i < _e : _e <= i); (_b < _e ? i++ : i--)) #define _REP2(i, n) for (decltype(n) i = 0, _n = (n); i < _n; i++) #define _REP1(n) for (decltype(n) _i = 0, _n = (n); _i < _n; _i++) #define REP(...) _REP(__VA_ARGS__, _REP4, _REP3, _REP2, _REP1)(__VA_ARGS__) #define FOR(it, c) for (auto &&it = begin(c); it != end(c); it++) #define ROF(it, c) for (auto &&it = rbegin(c); it != rend(c); it++) #define EB emplace_back #define PB push_back #define MP make_pair #define MT make_tuple #define INT(n) \ int n; \ assert(0 < scanf("%d", &n)) #define AI(a, size, n) \ array<int, size> a; \ REP(i, n) { assert(0 < scanf("%d", &a[i])); } #define STR(s) \ string s; \ cin >> s int main() { STR(s); STR(t); int n = SZ(s), m = SZ(t); int idx = -1, cnt = 0; ll ans = 0; vector<vector<int>> v(26); REP(i, n) { v[s[i] - 'a'].PB(i); } REP(i, m) { int j = t[i] - 'a'; if (v[j].empty()) { ans = -1; break; } auto it = lower_bound(v[j].begin(), v[j].end(), idx + 1); if (it == v[j].end()) { cnt++; idx = v[j][0]; } else { idx = *it; } } if (ans == 0) { ans = (ll)cnt * n + idx + 1; } printf("%lld\n", ans); return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,935
740,934
u872191059
cpp
p02937
#include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) using namespace std; using ll = long long; ll inf = 100000000007ll; string s, t; int ssz, tsz; map<char, set<ll>> mcs; ll succ(int from, char c) { return *(mcs[c].upper_bound(from)); } ll solve(int from, int t_ind) { if (t_ind == tsz) return from; ll spos = succ(from, t[t_ind]); if (spos >= ssz) return solve(spos - ssz, t_ind + 1) + ssz; else return solve(spos, t_ind + 1); } int main(void) { cin >> s >> t; ssz = s.size(); tsz = t.size(); ll exist[200] = {}; for (auto c : s) ++exist[c]; for (auto c : t) { if (!exist[c]) { cout << -1 << endl; return 0; } } REP(i, ssz) { mcs[s[i]].insert(i); mcs[s[i]].insert(i + ssz); } cout << solve(0, 0) + 1 << endl; return 0; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) using namespace std; using ll = long long; ll inf = 100000000007ll; string s, t; int ssz, tsz; map<char, set<ll>> mcs; ll succ(int from, char c) { return *(mcs[c].upper_bound(from)); } ll solve(int from, int t_ind) { if (t_ind == tsz) return from; ll spos = succ(from, t[t_ind]); if (spos >= ssz) return solve(spos - ssz, t_ind + 1) + ssz; else return solve(spos, t_ind + 1); } int main(void) { cin >> s >> t; ssz = s.size(); tsz = t.size(); ll exist[200] = {}; for (auto c : s) ++exist[c]; for (auto c : t) { if (!exist[c]) { cout << -1 << endl; return 0; } } REP(i, ssz) { mcs[s[i]].insert(i); mcs[s[i]].insert(i + ssz); } cout << solve(-1, 0) + 1 << endl; return 0; }
[ "literal.number.change", "io.output.change", "call.arguments.change" ]
740,938
740,939
u633757735
cpp
p02937
#include <bits/stdc++.h> #define ll long long using namespace std; int ls, lt; char s[100004], t[100004]; vector<int> cs[34], ct[34]; vector<int>::iterator it; int main() { scanf("%s%s", s + 1, t + 1); ls = strlen(s + 1); lt = strlen(t + 1); for (int i = 1; i <= ls; i++) { cs[s[i] - 'a'].push_back(i); } for (int i = 1; i <= lt; i++) { ct[t[i] - 'a'].push_back(i); } for (int i = 0; i < 26; i++) if ((cs[i].size() == 0) && ct[i].size() != 0) return puts("-1"), 0; ll count_s = 0; int pos = 0; for (int i = 1; i <= lt; i++) { int x = t[i] - 'a'; it = lower_bound(cs[x].begin(), cs[x].end(), pos); if (it == cs[x].end()) { count_s++; pos = 0; it = lower_bound(cs[x].begin(), cs[x].end(), pos); } pos = (*it); } printf("%lld\n", count_s * ls + pos); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int ls, lt; char s[100004], t[100004]; vector<int> cs[34], ct[34]; vector<int>::iterator it; int main() { scanf("%s%s", s + 1, t + 1); ls = strlen(s + 1); lt = strlen(t + 1); for (int i = 1; i <= ls; i++) { cs[s[i] - 'a'].push_back(i); } for (int i = 1; i <= lt; i++) { ct[t[i] - 'a'].push_back(i); } for (int i = 0; i < 26; i++) if ((cs[i].size() == 0) && ct[i].size() != 0) return puts("-1"), 0; ll count_s = 0; int pos = 0; for (int i = 1; i <= lt; i++) { int x = t[i] - 'a'; it = lower_bound(cs[x].begin(), cs[x].end(), pos + 1); if (it == cs[x].end()) { count_s++; pos = 0; it = lower_bound(cs[x].begin(), cs[x].end(), pos + 1); } pos = (*it); } printf("%lld\n", count_s * ls + pos); return 0; }
[ "assignment.change" ]
740,940
740,941
u628253919
cpp
p02937
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define INF 10000000000000000 #define MOD 1000000007 typedef pair<int, int> P; bool prime(int n) { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 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 mod_pow(int n, int p, int m) { if (p == 0) return 1; if (p % 2 == 0) { int t = mod_pow(n, p / 2, m); return (t * t) % m; } return n * mod_pow(n, p - 1, m) % m; } int extGCD(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } int modinv(int a, int m) { int b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } signed main() { string s, t; cin >> s >> t; int ans = 1, now = 0; vector<int> vec[27]; rep(i, s.size()) { vec[s[i] - 'a'].push_back(i); } rep(i, t.size()) { if (vec[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } if (upper_bound(vec[t[i] - 'a'].begin(), vec[t[i] - 'a'].end(), now) == vec[t[i] - 'a'].end()) { ans += s.size() - 1 - now; now = vec[t[i] - 'a'][0]; ans += now + 1; } else { ans += *upper_bound(vec[t[i] - 'a'].begin(), vec[t[i] - 'a'].end(), now) - now; now = *upper_bound(vec[t[i] - 'a'].begin(), vec[t[i] - 'a'].end(), now); } } cout << ans << endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define INF 10000000000000000 #define MOD 1000000007 typedef pair<int, int> P; bool prime(int n) { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 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 mod_pow(int n, int p, int m) { if (p == 0) return 1; if (p % 2 == 0) { int t = mod_pow(n, p / 2, m); return (t * t) % m; } return n * mod_pow(n, p - 1, m) % m; } int extGCD(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } int modinv(int a, int m) { int b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } signed main() { string s, t; cin >> s >> t; int ans = 0, now = -1; vector<int> vec[27]; rep(i, s.size()) { vec[s[i] - 'a'].push_back(i); } rep(i, t.size()) { if (vec[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } if (upper_bound(vec[t[i] - 'a'].begin(), vec[t[i] - 'a'].end(), now) == vec[t[i] - 'a'].end()) { ans += s.size() - 1 - now; now = vec[t[i] - 'a'][0]; ans += now + 1; } else { ans += *upper_bound(vec[t[i] - 'a'].begin(), vec[t[i] - 'a'].end(), now) - now; now = *upper_bound(vec[t[i] - 'a'].begin(), vec[t[i] - 'a'].end(), now); } } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,944
740,945
u452009494
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; #define fi first #define se second #define pb push_back #define all(v) (v).begin(), (v).end() #define siz(v) (ll)(v).size() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repi(i, x, n) for (ll i = x; i < (ll)(n); i++) typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; const ll INF = 1000000099; vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1}; // cin.tie(0); // ios::sync_with_stdio(false); signed main() { string s, t; cin >> s >> t; vector<vector<ll>> bac(26, vector<ll>(0)); rep(i, siz(s)) { bac.at(s[i] - 'a').pb(i); } ll nofs = 0, ind = 0; for (int i = 0; i < siz(t); i++) { if (siz(bac[t[i] - 'a']) == 0) { cout << -1 << endl; return 0; } int it = upper_bound(all(bac[t[i] - 'a']), ind) - bac[t[i] - 'a'].begin(); if (it == siz(bac[t[i] - 'a'])) { nofs++; ind = bac[t[i] - 'a'][0]; } else { ind = bac[t[i] - 'a'][it]; } } cout << siz(s) * nofs + ind + 1ll << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; #define fi first #define se second #define pb push_back #define all(v) (v).begin(), (v).end() #define siz(v) (ll)(v).size() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repi(i, x, n) for (ll i = x; i < (ll)(n); i++) typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; const ll INF = 1000000099; vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1}; // cin.tie(0); // ios::sync_with_stdio(false); signed main() { string s, t; cin >> s >> t; vector<vector<ll>> bac(26, vector<ll>(0)); rep(i, siz(s)) { bac.at(s[i] - 'a').pb(i); } ll nofs = 0, ind = -1; for (int i = 0; i < siz(t); i++) { if (siz(bac[t[i] - 'a']) == 0) { cout << -1 << endl; return 0; } int it = upper_bound(all(bac[t[i] - 'a']), ind) - bac[t[i] - 'a'].begin(); if (it == siz(bac[t[i] - 'a'])) { nofs++; ind = bac[t[i] - 'a'][0]; } else { ind = bac[t[i] - 'a'][it]; } } cout << siz(s) * nofs + ind + 1ll << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,946
740,947
u317711717
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; #define fi first #define se second #define pb push_back #define all(v) (v).begin(), (v).end() #define siz(v) (ll)(v).size() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repi(i, x, n) for (ll i = x; i < (ll)(n); i++) typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; const ll INF = 1000000099; vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1}; // cin.tie(0); // ios::sync_with_stdio(false); signed main() { string s, t; cin >> s >> t; vector<vector<ll>> bac(26, vector<ll>(0)); rep(i, siz(s)) { bac.at(s[i] - 'a').pb(i); } ll nofs = 0, ind = 0; for (int i = 0; i < siz(t); i++) { if (siz(bac[t[i] - 'a']) == 0) { cout << -1 << endl; return 0; } int it = lower_bound(all(bac[t[i] - 'a']), ind) - bac[t[i] - 'a'].begin(); if (it == siz(bac[t[i] - 'a'])) { nofs++; ind = bac[t[i] - 'a'][0]; } else { ind = bac[t[i] - 'a'][it]; } } cout << siz(s) * nofs + ind + 1ll << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; #define fi first #define se second #define pb push_back #define all(v) (v).begin(), (v).end() #define siz(v) (ll)(v).size() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repi(i, x, n) for (ll i = x; i < (ll)(n); i++) typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; const ll INF = 1000000099; vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1}; // cin.tie(0); // ios::sync_with_stdio(false); signed main() { string s, t; cin >> s >> t; vector<vector<ll>> bac(26, vector<ll>(0)); rep(i, siz(s)) { bac.at(s[i] - 'a').pb(i); } ll nofs = 0, ind = -1; for (int i = 0; i < siz(t); i++) { if (siz(bac[t[i] - 'a']) == 0) { cout << -1 << endl; return 0; } int it = upper_bound(all(bac[t[i] - 'a']), ind) - bac[t[i] - 'a'].begin(); if (it == siz(bac[t[i] - 'a'])) { nofs++; ind = bac[t[i] - 'a'][0]; } else { ind = bac[t[i] - 'a'][it]; } } cout << siz(s) * nofs + ind + 1ll << endl; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change", "expression.operation.binary.change" ]
740,948
740,947
u317711717
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.size(); s = s + s; vector<vector<int>> nex(2 * n, vector<int>(26, -1)); for (int i = 2 * n - 2; i >= 0; i--) { for (int j = 0; j < 26; j++) { if (s[i + 1] == 'a' + j) { nex[i][j] = i + 1; } else { nex[i][j] = nex[i + 1][j]; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) { if (nex[i][j] >= n) { nex[i][j] -= n; } } } long long ans = 0; int now = t[0] == s[0] ? 0 : nex[0][t[0] - 'a']; if (now == -1) { cout << -1 << endl; return 0; } int cur = 1; while (cur < t.size()) { int tmp = nex[now][t[cur] - 'a']; if (tmp == -1) { cout << -1 << endl; return 0; } if (tmp < now) { ans += n; } now = tmp; cur++; } cout << ans + now + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.size(); s = s + s; vector<vector<int>> nex(2 * n, vector<int>(26, -1)); for (int i = 2 * n - 2; i >= 0; i--) { for (int j = 0; j < 26; j++) { if (s[i + 1] == 'a' + j) { nex[i][j] = i + 1; } else { nex[i][j] = nex[i + 1][j]; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) { if (nex[i][j] >= n) { nex[i][j] -= n; } } } long long ans = 0; int now = t[0] == s[0] ? 0 : nex[0][t[0] - 'a']; if (now == -1) { cout << -1 << endl; return 0; } int cur = 1; while (cur < t.size()) { int tmp = nex[now][t[cur] - 'a']; if (tmp == -1) { cout << -1 << endl; return 0; } if (tmp <= now) { ans += n; } now = tmp; cur++; } cout << ans + now + 1 << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,953
740,954
u891482208
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.size(); s = s + s; vector<vector<int>> nex(2 * n, vector<int>(26, -1)); for (int i = 2 * n - 2; i >= 0; i--) { for (int j = 0; j < 26; j++) { if (s[i + 1] == 'a' + j) { nex[i][j] = i + 1; } else { nex[i][j] = nex[i + 1][j]; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) { if (nex[i][j] >= n) { nex[i][j] -= n; } } } int ans = 0; int now = t[0] == s[0] ? 0 : nex[0][t[0] - 'a']; if (now == -1) { cout << -1 << endl; return 0; } int cur = 1; while (cur < t.size()) { int tmp = nex[now][t[cur] - 'a']; if (tmp == -1) { cout << -1 << endl; return 0; } if (tmp < now) { ans += n; } now = tmp; cur++; } cout << ans + now + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int n = s.size(); s = s + s; vector<vector<int>> nex(2 * n, vector<int>(26, -1)); for (int i = 2 * n - 2; i >= 0; i--) { for (int j = 0; j < 26; j++) { if (s[i + 1] == 'a' + j) { nex[i][j] = i + 1; } else { nex[i][j] = nex[i + 1][j]; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) { if (nex[i][j] >= n) { nex[i][j] -= n; } } } long long ans = 0; int now = t[0] == s[0] ? 0 : nex[0][t[0] - 'a']; if (now == -1) { cout << -1 << endl; return 0; } int cur = 1; while (cur < t.size()) { int tmp = nex[now][t[cur] - 'a']; if (tmp == -1) { cout << -1 << endl; return 0; } if (tmp <= now) { ans += n; } now = tmp; cur++; } cout << ans + now + 1 << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,955
740,954
u891482208
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef vector<ll> vl; typedef vector<pair<ll, ll>> vp; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define all(v) v.begin(), v.end() #define inputv(v, n) \ rep(i, n) { \ ll x; \ cin >> x; \ v.push_back(x); \ } const ll INF = 99999999999999; const ll MOD = 1000000007; string s, t; vl moji[26]; void input(void) { cin >> s >> t; } void solve(void) { ll ans = 0, now = 0, now2, k; rep(i, s.length()) { moji[s[i] - 'a'].push_back(i); } rep(i, t.length()) { k = t[i] - 'a'; if (moji[k].empty()) { cout << -1 << endl; return; } now2 = upper_bound(all(moji[k]), now) - moji[k].begin(); if (now2 == moji[k].size()) { ans += s.length() - now + moji[k][0]; now = moji[k][0]; } else { ans += moji[k][now2] - now; now = moji[k][now2]; } } cout << ans + 1 << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); input(); solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef vector<ll> vl; typedef vector<pair<ll, ll>> vp; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define all(v) v.begin(), v.end() #define inputv(v, n) \ rep(i, n) { \ ll x; \ cin >> x; \ v.push_back(x); \ } const ll INF = 99999999999999; const ll MOD = 1000000007; string s, t; vl moji[26]; void input(void) { cin >> s >> t; } void solve(void) { ll ans = -1, now = -1, now2, k; rep(i, s.length()) { moji[s[i] - 'a'].push_back(i); } rep(i, t.length()) { k = t[i] - 'a'; if (moji[k].empty()) { cout << -1 << endl; return; } now2 = upper_bound(all(moji[k]), now) - moji[k].begin(); if (now2 == moji[k].size()) { ans += s.length() - now + moji[k][0]; now = moji[k][0]; } else { ans += moji[k][now2] - now; now = moji[k][now2]; } } cout << ans + 1 << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); input(); solve(); }
[ "literal.number.change", "variable_declaration.value.change" ]
740,956
740,957
u268571052
cpp
p02937
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define PSET(x, y) fixed << setprecision(y) << x #define pb push_back #define pf push_front #define pii pair<int, int> #define mp make_pair #define vi vector<int> #define vip vector<pair<int, int>> #define ff first #define ss second #define int long long #define SIZE 200010 #define mod 1000000007 #define BIG 998244353 #define s(t) scanf("%d", &t) #define p(t) printf("%d\n", t) #define mii map<int, int> #define MSET(table, i) memset(table, i, sizeof(table)) #define endl '\n' #define tc \ int t; \ cin >> t; \ while (t--) #define pi 3.1415926358 #define print(x) \ for (auto el : x) \ cout << el << " "; \ cout << endl #define bits(x) __builtin_popcount(x) #define minimum(a, n) min_element(a, a + n) - a #define maximum(a, n) max_element(a, a + n) - a #define pqbig priority_queue<int> #define pqsmall priority_queue<int, vector<int>, greater<int>> #define all(v) v.begin(), v.end() #define sitr set<int>::iterator #define mitr map<int, int>::iterator #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 const int N = 30; vi adj[N]; int32_t main() { fast; string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); for (int i = 0; i < n; i++) adj[s[i] - 'a'].pb(i); for (int i = 0; i < m; i++) { if (adj[t[i] - 'a'].size() == 0) { cout << -1; return 0; } } int complete_rounds = 0; int prev = -1; for (int i = 0; i < m; i++) { int val = t[i] - 'a'; int id = lower_bound(all(adj[val]), prev) - adj[val].begin(); if (id == adj[val].size()) { complete_rounds++; prev = adj[val][0]; } else prev = adj[val][id]; } cout << n * complete_rounds + prev + 1; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define PSET(x, y) fixed << setprecision(y) << x #define pb push_back #define pf push_front #define pii pair<int, int> #define mp make_pair #define vi vector<int> #define vip vector<pair<int, int>> #define ff first #define ss second #define int long long #define SIZE 200010 #define mod 1000000007 #define BIG 998244353 #define s(t) scanf("%d", &t) #define p(t) printf("%d\n", t) #define mii map<int, int> #define MSET(table, i) memset(table, i, sizeof(table)) #define endl '\n' #define tc \ int t; \ cin >> t; \ while (t--) #define pi 3.1415926358 #define print(x) \ for (auto el : x) \ cout << el << " "; \ cout << endl #define bits(x) __builtin_popcount(x) #define minimum(a, n) min_element(a, a + n) - a #define maximum(a, n) max_element(a, a + n) - a #define pqbig priority_queue<int> #define pqsmall priority_queue<int, vector<int>, greater<int>> #define all(v) v.begin(), v.end() #define sitr set<int>::iterator #define mitr map<int, int>::iterator #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 const int N = 30; vi adj[N]; int32_t main() { fast; string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); for (int i = 0; i < n; i++) adj[s[i] - 'a'].pb(i); for (int i = 0; i < m; i++) { if (adj[t[i] - 'a'].size() == 0) { cout << -1; return 0; } } int complete_rounds = 0; int prev = -1; for (int i = 0; i < m; i++) { int val = t[i] - 'a'; int id = upper_bound(all(adj[val]), prev) - adj[val].begin(); if (id == adj[val].size()) { complete_rounds++; prev = adj[val][0]; } else prev = adj[val][id]; } cout << n * complete_rounds + prev + 1; }
[ "identifier.change", "call.function.change", "expression.operation.binary.change" ]
740,958
740,959
u273957331
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, e) for (int i = a; i < e; ++i) using LL = long long; // template< unsigned mod > // struct RollingHash { // vector< unsigned > hashed, power; // // inline unsigned mul(unsigned a, unsigned b) const { // unsigned long long x = (unsigned long long) a * b; // unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m; // asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" //(mod)); return m; // } // // RollingHash(const string &s, unsigned base = 10007) { // int sz = (int)s.size(); // hashed.assign(sz + 1, 0); // power.assign(sz + 1, 0); // power[0] = 1; // for (int i = 0; i < sz; i++) { // power[i + 1] = mul(power[i], base); // hashed[i + 1] = mul(hashed[i], base) + s[i]; // if (hashed[i + 1] >= mod) hashed[i + 1] -= mod; // } // } // // unsigned get(int l, int r) const { // unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]); // if (ret >= mod) ret -= mod; // return ret; // } // // unsigned connect(unsigned h1, int h2, int h2len) const { // unsigned ret = mul(h1, power[h2len]) + h2; // if (ret >= mod) ret -= mod; // return ret; // } // // int LCP(const RollingHash< mod > &b, int l1, int r1, int l2, int r2) { // int len = min(r1 - l1, r2 - l2); // int low = -1, high = len + 1; // while (high - low > 1) { // int mid = (low + high) / 2; // if (get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid; // else high = mid; // } // return (low); // } //}; // // using RH = RollingHash< 1000000007 >; // using RH2 = RollingHash< 1000000009 >; int main() { string s, t; cin >> s >> t; vector<vector<LL>> ssum(26, vector<LL>((int)s.size() + 1, 0)); { vector<vector<LL>> b(26, vector<LL>((int)s.size() + 1, 0)); FOR(i, 0, (int)s.size()) { b[s[i] - 'a'][i]++; } FOR(i, 0, 26) { FOR(j, 0, (int)s.size()) { ssum[i][j + 1] += ssum[i][j] + b[i][j]; } } } auto cntquery = [&](int c, int l, int r) { return ssum[c][r] - ssum[c][l]; }; auto query = [&](int c, int l, int r) { return lower_bound(ssum[c].begin() + l, ssum[c].begin() + r, ssum[c][l] + 1LL) - ssum[c].begin() - 1; }; LL ans = 1; LL si = 0; FOR(ti, 0, (int)t.size()) { bool found = 0; { //[si,s) LL cnt = cntquery(t[ti] - 'a', si, (int)s.size()); if (cnt) { LL fs = query(t[ti] - 'a', si, (int)s.size()); ans += fs - si; si = fs; found = 1; } } if (!found) { //[0,si) ans += (LL)s.size() - si; LL cnt = cntquery(t[ti] - 'a', 0, si); if (cnt) { LL fs = query(t[ti] - 'a', 0, si); ans += fs; si = fs; found = 1; } } // cerr << ans << ", " << si << endl; if (!found) { ans = -1; break; } } // cerr << "case end" << endl; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, e) for (int i = a; i < e; ++i) using LL = long long; // template< unsigned mod > // struct RollingHash { // vector< unsigned > hashed, power; // // inline unsigned mul(unsigned a, unsigned b) const { // unsigned long long x = (unsigned long long) a * b; // unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m; // asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" //(mod)); return m; // } // // RollingHash(const string &s, unsigned base = 10007) { // int sz = (int)s.size(); // hashed.assign(sz + 1, 0); // power.assign(sz + 1, 0); // power[0] = 1; // for (int i = 0; i < sz; i++) { // power[i + 1] = mul(power[i], base); // hashed[i + 1] = mul(hashed[i], base) + s[i]; // if (hashed[i + 1] >= mod) hashed[i + 1] -= mod; // } // } // // unsigned get(int l, int r) const { // unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]); // if (ret >= mod) ret -= mod; // return ret; // } // // unsigned connect(unsigned h1, int h2, int h2len) const { // unsigned ret = mul(h1, power[h2len]) + h2; // if (ret >= mod) ret -= mod; // return ret; // } // // int LCP(const RollingHash< mod > &b, int l1, int r1, int l2, int r2) { // int len = min(r1 - l1, r2 - l2); // int low = -1, high = len + 1; // while (high - low > 1) { // int mid = (low + high) / 2; // if (get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid; // else high = mid; // } // return (low); // } //}; // // using RH = RollingHash< 1000000007 >; // using RH2 = RollingHash< 1000000009 >; int main() { string s, t; cin >> s >> t; vector<vector<LL>> ssum(26, vector<LL>((int)s.size() + 1, 0)); { vector<vector<LL>> b(26, vector<LL>((int)s.size() + 1, 0)); FOR(i, 0, (int)s.size()) { b[s[i] - 'a'][i]++; } FOR(i, 0, 26) { FOR(j, 0, (int)s.size()) { ssum[i][j + 1] += ssum[i][j] + b[i][j]; } } } auto cntquery = [&](int c, int l, int r) { return ssum[c][r] - ssum[c][l]; }; auto query = [&](int c, int l, int r) { return lower_bound(ssum[c].begin() + l, ssum[c].begin() + r, ssum[c][l] + 1LL) - ssum[c].begin(); }; LL ans = 0; LL si = 0; FOR(ti, 0, (int)t.size()) { bool found = 0; { //[si,s) LL cnt = cntquery(t[ti] - 'a', si, (int)s.size()); if (cnt) { LL fs = query(t[ti] - 'a', si, (int)s.size()); ans += fs - si; si = fs; found = 1; } } if (!found) { //[0,si) ans += (LL)s.size() - si; LL cnt = cntquery(t[ti] - 'a', 0, si); if (cnt) { LL fs = query(t[ti] - 'a', 0, si); ans += fs; si = fs; found = 1; } } // cerr << ans << ", " << si << endl; if (!found) { ans = -1; break; } } // cerr << "case end" << endl; cout << ans << endl; }
[ "expression.operation.binary.remove", "literal.number.change", "variable_declaration.value.change" ]
740,962
740,963
u110336585
cpp
p02937
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define all(v) v.begin(), v.end() #define MP make_pair #define F first #define S second #define sz(v) (ll) v.size() #define inf 100000000000000 #define vll vector<ll> #define pll pair<ll, ll> nnnn using namespace std; const int N = 200004; ll dp[N][26]; ll fst[N]; void solve() { string a, b; ll n, m, idx, i, tot = 0, j; cin >> a; cin >> b; n = a.length(); m = b.length(); a = "0" + a; b = "0" + b; for (i = 1; i <= n; i++) if (!fst[a[i] - 'a']) fst[a[i] - 'a'] = i; for (i = n - 1; i >= 1; i--) { for (j = 0; j < 26; j++) dp[i][j] = dp[i + 1][j]; dp[i][a[i + 1] - 'a'] = i + 1; } for (i = 1; i <= m; i++) if (!fst[b[i] - 'a']) { cout << -1; return; } idx = fst[b[1]]; i = 2; while (i <= m) { if (dp[idx][b[i] - 'a']) idx = dp[idx][b[i] - 'a']; else idx = fst[b[i] - 'a'], tot++; i++; } cout << (tot * n + idx); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1; // cin>>t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define all(v) v.begin(), v.end() #define MP make_pair #define F first #define S second #define sz(v) (ll) v.size() #define inf 100000000000000 #define vll vector<ll> #define pll pair<ll, ll> nnnn using namespace std; const int N = 200004; ll dp[N][26]; ll fst[N]; void solve() { string a, b; ll n, m, idx, i, tot = 0, j; cin >> a; cin >> b; n = a.length(); m = b.length(); a = "0" + a; b = "0" + b; for (i = 1; i <= n; i++) if (!fst[a[i] - 'a']) fst[a[i] - 'a'] = i; for (i = n - 1; i >= 1; i--) { for (j = 0; j < 26; j++) dp[i][j] = dp[i + 1][j]; dp[i][a[i + 1] - 'a'] = i + 1; } for (i = 1; i <= m; i++) if (!fst[b[i] - 'a']) { cout << -1; return; } idx = fst[b[1] - 'a']; i = 2; while (i <= m) { if (dp[idx][b[i] - 'a']) idx = dp[idx][b[i] - 'a']; else idx = fst[b[i] - 'a'], tot++; i++; } cout << (tot * n + idx); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1; // cin>>t; while (t--) solve(); return 0; }
[ "assignment.change" ]
740,966
740,967
u850006519
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; (i)--) #define rrep1(i, n) for (int i = ((int)(n)); i > 0; (i)--) #define sz(c) ((int)(c).size()) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> P; typedef pair<int, pair<int, int>> PP; const int MAX = 2e5 + 10; const ll INF = 1e18; string S, T; int ls, lt; void input() { cin >> S >> T; ls = sz(S); lt = sz(T); } ll nex[MAX][26]; ll ans = 0; void solve() { rep(i, ls) rep(k, 26) nex[i][k] = INF; for (int i = 2 * ls - 1; i >= 0; i--) { rep(k, 26) nex[i % ls][k] = min(INF, nex[(i + 1) % ls][k] + 1); int Z = S[i % ls] - 'a'; nex[i % ls][Z] = 0; } rep(i, lt) { ll tmp = nex[ans % ls][T[i] - 'a']; ans = min(ans + tmp, INF); ans++; } if (ans == INF) cout << -1 << endl; else cout << ans << endl; } void output() { rep(k, 26) if (nex[0][k] != INF) { char Z = 'a' + k; cout << Z << " "; rep(i, ls) cout << nex[i][k]; cout << endl; } } int main() { input(); solve(); }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; (i)--) #define rrep1(i, n) for (int i = ((int)(n)); i > 0; (i)--) #define sz(c) ((int)(c).size()) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> P; typedef pair<int, pair<int, int>> PP; const int MAX = 2e5 + 10; const ll INF = 1e18; string S, T; int ls, lt; void input() { cin >> S >> T; ls = sz(S); lt = sz(T); } ll nex[MAX][26]; ll ans = 0; void solve() { rep(i, ls) rep(k, 26) nex[i][k] = INF; for (int i = 2 * ls - 1; i >= 0; i--) { rep(k, 26) nex[i % ls][k] = min(INF, nex[(i + 1) % ls][k] + 1); int Z = S[i % ls] - 'a'; nex[i % ls][Z] = 0; } rep(i, lt) { ll tmp = nex[ans % ls][T[i] - 'a']; ans = min(ans + tmp, INF); ans++; } if (ans > INF) cout << -1 << endl; else cout << ans << endl; } void output() { rep(k, 26) if (nex[0][k] != INF) { char Z = 'a' + k; cout << Z << " "; rep(i, ls) cout << nex[i][k]; cout << endl; } } int main() { input(); solve(); }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,968
740,969
u228214259
cpp
p02937
#include <algorithm> #include <chrono> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; using lli = long long int; using Vint = std::vector<int>; using Vlli = std::vector<lli>; using Wint = std::vector<Vint>; using Wlli = std::vector<Vlli>; using Vbool = std::vector<bool>; using Wbool = std::vector<Vbool>; using pii = std::pair<int, int>; using pll = std::pair<lli, lli>; template <class T> using Vec = std::vector<T>; template <class T> using Wec = Vec<Vec<T>>; constexpr int MOD = 1e9 + 7; constexpr int INFi = 2e9 + 1; constexpr lli INFl = (lli)(9e18) + 1; const std::vector<std::pair<int, int>> DXDY = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}}; constexpr char BR = '\n'; #define DEBUG(x) std::cerr << #x << " = " << x << '\n'; #define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i)) #define FOReq(i, a, b) for (int(i) = (a); (i) <= (b); ++(i)) #define rFOR(i, a, b) for (int(i) = (b); (i) >= (a); --(i)) #define FORstep(i, a, b, step) for (int(i) = (a); i < (b); i += (step)) #define REP(i, n) FOR(i, 0, n) #define rREP(i, n) rFOR(i, 0, (n - 1)) #define vREP(ele, vec) for (auto &(ele) : (vec)) #define vREPcopy(ele, vec) for (auto(ele) : (vec)) #define SORT(A) std::sort((A).begin(), (A).end()) #define RSORT(A) std::sort((A).rbegin(), (A).rend()) #define ALL(A) (A).begin(), (A).end() // 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => // COORDINATE_COMPRESSION(A) #define COORDINATE_COMPRESSION(A) \ (A).erase(unique((A).begin(), (A).end()), (A).end()) template <class T> inline int argmin(std::vector<T> &vec) { return min_element(vec.begin(), vec.end()) - vec.begin(); } template <class T> inline int argmax(std::vector<T> &vec) { return max_element(vec.begin(), vec.end()) - vec.begin(); } template <class T> inline T &chmin(T &a, T b) { return (a > b) ? a = b : a; } template <class T> inline T &chmax(T &a, T b) { return (a < b) ? a = b : a; } template <class T> inline void reverseSORT(Vec<T> &Array) { std::sort(Array.begin(), Array.end(), std::greater<T>()); } inline int BitI(int k) { return 1 << k; } inline lli BitL(int k) { return 1LL << k; } inline void putsDouble(double d) { printf("%.16lf\n", d); } template <class T> inline std::string toString(T n) { if (n == 0) return "0"; std::string res; if (n < 0) { n = -n; while (n != 0) { res += (char)(n % 10 + '0'); n /= 10; } std::reverse(res.begin(), res.end()); return '-' + res; } while (n != 0) { res += (char)(n % 10 + '0'); n /= 10; } std::reverse(res.begin(), res.end()); return res; } namespace MyFunc { using LLi = long long int; using ULLi = unsigned long long int; // GCD(a, b) ; a, bの最大公約数を求める関数 inline LLi gcd(LLi a, LLi b) { while (b != 0) { a %= b; std::swap(a, b); } return a; } // LCM(a, b) ; a, bの最小公倍数を求める関数 inline LLi lcm(LLi a, LLi b) { return (a * b) / MyFunc::gcd(a, b); } // 累乗を求める関数 inline LLi power(LLi a, LLi n) { LLi res = 1LL, waiting = a; while (n != 0LL) { if ((n & 1LL) != 0LL) res *= waiting; waiting *= waiting; n >>= 1; } return res; } // 累乗の余りを求める関数 inline LLi power_mod(LLi a, LLi n, LLi mod_number___ = 1e9 + 7) { LLi res = 1LL, waiting = a; while (n != 0LL) { if ((n & 1LL) != 0LL) { res *= waiting; res %= mod_number___; } waiting *= waiting; waiting %= mod_number___; n >>= 1; } return res; } // Z/pZ上の逆元を求める関数 (フェルマーの小定理) inline LLi inverse_mod(LLi a, LLi mod_number___ = 1e9 + 7) { return MyFunc::power_mod(a, mod_number___ - 2); } inline LLi inverse_mod_euclid(LLi a, LLi mod_number___ = 1e9 + 7) { LLi b = mod_number___, u = 1, v = 0; while (b != 0) { LLi t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } u %= mod_number___; if (u < 0) u += mod_number___; return u; } // 素数であるかを判定する関数 template <typename Integer_type> inline bool isPrime(Integer_type n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (Integer_type x = 3; x * x <= n; ++++x) if (n % x == 0) return false; return true; } // 素数であるかの真偽表を返す : n ≥ 1 inline std::vector<bool> primeTable(int n) { std::vector<bool> res(n + 1, true); res[0] = false; res[1] = false; for (int x = 2; x * x <= n; ++x) if (res[x]) { for (int i = 2 * x; i <= n; i += x) { res[i] = false; } } return std::move(res); } // 素因数分解したベクトルを返す ; {素因数, 指数} template <typename Integer_type> inline std::vector<std::pair<Integer_type, int>> prime_factorization(Integer_type n) { std::vector<std::pair<Integer_type, int>> res(0); if (n <= 0) return std::move(res); // 例外処理 : nが 0 以下 if (n % 2 == 0) { n /= 2; int cnt = 1; while (n % 2 == 0) { n /= 2; cnt++; } res.emplace_back(make_pair(2, cnt)); } Integer_type x = 3; while (x * x <= n) { if (n % x == 0) { n /= x; int cnt = 1; while (n % x == 0) { n /= x; cnt++; } res.emplace_back(make_pair(x, cnt)); } ++++x; } if (n > 1) res.emplace_back(make_pair(n, 1)); return std::move(res); } // unsigned long 符号なし64bit整数で平方数かを判定する関数 O(log(N)) inline bool is_square_unsigned(ULLi n) { // 0 は 平方数 if (n == 0) return true; // 平方数の可能性としては 2^32 - 1 が最大 : (2^32)^2 - 1 static ULLi MAX_LONG_SQRT__ = (1UL << 32) - 1; if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ < n) return false; if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ == n) return true; // 二分探索 ULLi smaller = 0, bigger = MAX_LONG_SQRT__; while (bigger - smaller > 1) { ULLi m = (smaller + bigger) >> 1; if (m * m == n) return true; if (m * m < n) smaller = m; else bigger = m; } return false; } // 符号付き64bit整数で平方数か判定する関数 inline bool is_square(LLi n) { if (n < 0) return false; // 平方数を4で割った余りは 0 か 1 に限る if ((n & 0b11) > 0b01) return false; return is_square_unsigned(n); } } // namespace MyFunc // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ std::string S, T; constexpr int ALPHABET_SIZE = 'z' - 'a' + 1; std::vector<int> Index[ALPHABET_SIZE]; int findex(char a, int u) { int c = a - 'a'; if (Index[c].size() == 0) return -1; // 存在しない auto itr = std::upper_bound(ALL(Index[c]), u); if (itr == (Index[c].end())) { // 先頭要素が次のものになる場合 return Index[c].front(); } else return *itr; } int main(void) { std::cin >> S >> T; const int n = S.size(); const int m = T.size(); REP(i, n) { Index[S[i] - 'a'].push_back(i); } lli res = 0; int prev = 0; REP(i, m) { int J = findex(T[i], prev); if (J == -1) { puts("-1"); return 0; } if (prev < J) res += J - prev; else { res += J - prev + n; } // std::cout << T[i] << " : " << prev <<" ,"<< J << " -> " << res << BR; prev = J; } std::cout << res + 1 << BR; return 0; }
#include <algorithm> #include <chrono> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; using lli = long long int; using Vint = std::vector<int>; using Vlli = std::vector<lli>; using Wint = std::vector<Vint>; using Wlli = std::vector<Vlli>; using Vbool = std::vector<bool>; using Wbool = std::vector<Vbool>; using pii = std::pair<int, int>; using pll = std::pair<lli, lli>; template <class T> using Vec = std::vector<T>; template <class T> using Wec = Vec<Vec<T>>; constexpr int MOD = 1e9 + 7; constexpr int INFi = 2e9 + 1; constexpr lli INFl = (lli)(9e18) + 1; const std::vector<std::pair<int, int>> DXDY = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}}; constexpr char BR = '\n'; #define DEBUG(x) std::cerr << #x << " = " << x << '\n'; #define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i)) #define FOReq(i, a, b) for (int(i) = (a); (i) <= (b); ++(i)) #define rFOR(i, a, b) for (int(i) = (b); (i) >= (a); --(i)) #define FORstep(i, a, b, step) for (int(i) = (a); i < (b); i += (step)) #define REP(i, n) FOR(i, 0, n) #define rREP(i, n) rFOR(i, 0, (n - 1)) #define vREP(ele, vec) for (auto &(ele) : (vec)) #define vREPcopy(ele, vec) for (auto(ele) : (vec)) #define SORT(A) std::sort((A).begin(), (A).end()) #define RSORT(A) std::sort((A).rbegin(), (A).rend()) #define ALL(A) (A).begin(), (A).end() // 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => // COORDINATE_COMPRESSION(A) #define COORDINATE_COMPRESSION(A) \ (A).erase(unique((A).begin(), (A).end()), (A).end()) template <class T> inline int argmin(std::vector<T> &vec) { return min_element(vec.begin(), vec.end()) - vec.begin(); } template <class T> inline int argmax(std::vector<T> &vec) { return max_element(vec.begin(), vec.end()) - vec.begin(); } template <class T> inline T &chmin(T &a, T b) { return (a > b) ? a = b : a; } template <class T> inline T &chmax(T &a, T b) { return (a < b) ? a = b : a; } template <class T> inline void reverseSORT(Vec<T> &Array) { std::sort(Array.begin(), Array.end(), std::greater<T>()); } inline int BitI(int k) { return 1 << k; } inline lli BitL(int k) { return 1LL << k; } inline void putsDouble(double d) { printf("%.16lf\n", d); } template <class T> inline std::string toString(T n) { if (n == 0) return "0"; std::string res; if (n < 0) { n = -n; while (n != 0) { res += (char)(n % 10 + '0'); n /= 10; } std::reverse(res.begin(), res.end()); return '-' + res; } while (n != 0) { res += (char)(n % 10 + '0'); n /= 10; } std::reverse(res.begin(), res.end()); return res; } namespace MyFunc { using LLi = long long int; using ULLi = unsigned long long int; // GCD(a, b) ; a, bの最大公約数を求める関数 inline LLi gcd(LLi a, LLi b) { while (b != 0) { a %= b; std::swap(a, b); } return a; } // LCM(a, b) ; a, bの最小公倍数を求める関数 inline LLi lcm(LLi a, LLi b) { return (a * b) / MyFunc::gcd(a, b); } // 累乗を求める関数 inline LLi power(LLi a, LLi n) { LLi res = 1LL, waiting = a; while (n != 0LL) { if ((n & 1LL) != 0LL) res *= waiting; waiting *= waiting; n >>= 1; } return res; } // 累乗の余りを求める関数 inline LLi power_mod(LLi a, LLi n, LLi mod_number___ = 1e9 + 7) { LLi res = 1LL, waiting = a; while (n != 0LL) { if ((n & 1LL) != 0LL) { res *= waiting; res %= mod_number___; } waiting *= waiting; waiting %= mod_number___; n >>= 1; } return res; } // Z/pZ上の逆元を求める関数 (フェルマーの小定理) inline LLi inverse_mod(LLi a, LLi mod_number___ = 1e9 + 7) { return MyFunc::power_mod(a, mod_number___ - 2); } inline LLi inverse_mod_euclid(LLi a, LLi mod_number___ = 1e9 + 7) { LLi b = mod_number___, u = 1, v = 0; while (b != 0) { LLi t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } u %= mod_number___; if (u < 0) u += mod_number___; return u; } // 素数であるかを判定する関数 template <typename Integer_type> inline bool isPrime(Integer_type n) { if (n < 2) return false; if (n == 2) return true; if (n % 2 == 0) return false; for (Integer_type x = 3; x * x <= n; ++++x) if (n % x == 0) return false; return true; } // 素数であるかの真偽表を返す : n ≥ 1 inline std::vector<bool> primeTable(int n) { std::vector<bool> res(n + 1, true); res[0] = false; res[1] = false; for (int x = 2; x * x <= n; ++x) if (res[x]) { for (int i = 2 * x; i <= n; i += x) { res[i] = false; } } return std::move(res); } // 素因数分解したベクトルを返す ; {素因数, 指数} template <typename Integer_type> inline std::vector<std::pair<Integer_type, int>> prime_factorization(Integer_type n) { std::vector<std::pair<Integer_type, int>> res(0); if (n <= 0) return std::move(res); // 例外処理 : nが 0 以下 if (n % 2 == 0) { n /= 2; int cnt = 1; while (n % 2 == 0) { n /= 2; cnt++; } res.emplace_back(make_pair(2, cnt)); } Integer_type x = 3; while (x * x <= n) { if (n % x == 0) { n /= x; int cnt = 1; while (n % x == 0) { n /= x; cnt++; } res.emplace_back(make_pair(x, cnt)); } ++++x; } if (n > 1) res.emplace_back(make_pair(n, 1)); return std::move(res); } // unsigned long 符号なし64bit整数で平方数かを判定する関数 O(log(N)) inline bool is_square_unsigned(ULLi n) { // 0 は 平方数 if (n == 0) return true; // 平方数の可能性としては 2^32 - 1 が最大 : (2^32)^2 - 1 static ULLi MAX_LONG_SQRT__ = (1UL << 32) - 1; if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ < n) return false; if (MAX_LONG_SQRT__ * MAX_LONG_SQRT__ == n) return true; // 二分探索 ULLi smaller = 0, bigger = MAX_LONG_SQRT__; while (bigger - smaller > 1) { ULLi m = (smaller + bigger) >> 1; if (m * m == n) return true; if (m * m < n) smaller = m; else bigger = m; } return false; } // 符号付き64bit整数で平方数か判定する関数 inline bool is_square(LLi n) { if (n < 0) return false; // 平方数を4で割った余りは 0 か 1 に限る if ((n & 0b11) > 0b01) return false; return is_square_unsigned(n); } } // namespace MyFunc // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ std::string S, T; constexpr int ALPHABET_SIZE = 'z' - 'a' + 1; std::vector<int> Index[ALPHABET_SIZE]; int findex(char a, int u) { int c = a - 'a'; if (Index[c].size() == 0) return -1; // 存在しない auto itr = std::upper_bound(ALL(Index[c]), u); if (itr == (Index[c].end())) { // 先頭要素が次のものになる場合 return Index[c].front(); } else return *itr; } int main(void) { std::cin >> S >> T; const int n = S.size(); const int m = T.size(); REP(i, n) { Index[S[i] - 'a'].push_back(i); } lli res = 0; int prev = -1; REP(i, m) { int J = findex(T[i], prev); if (J == -1) { puts("-1"); return 0; } if (prev < J) res += J - prev; else { res += J - prev + n; } // std::cout << T[i] << " : " << prev <<" ,"<< J << " -> " << res << BR; prev = J; } std::cout << res << BR; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operation.binary.remove" ]
740,970
740,971
u394853232
cpp
p02937
// -------------- // Tejas Pandey | // 18 - 08 - 19 | // ABC #138 | // -------------- #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define vi vector<int> typedef long long int ll; int main(void) { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { // cout << "Case #" << c-t << ": "; string s, t; cin >> s >> t; vector<int> pos[26]; for (int i = 0; i < s.size(); i++) { pos[s[i] - 'a'].push_back(i + 1); } int prev = 0, ans = 0; for (int i = 0; i < t.size(); i++) { int sc = t[i] - 'a'; int position = (lower_bound(pos[sc].begin(), pos[sc].end(), prev)) - pos[sc].begin(); if (position == pos[sc].size()) { if (pos[sc].size() == 0) { cout << "-1"; return 0; } ans += s.size() - prev; prev = 0; i--; } else { ans += pos[sc][position] - prev; prev = pos[sc][position]; } } cout << ans; } return 0; }
// -------------- // Tejas Pandey | // 18 - 08 - 19 | // ABC #138 | // -------------- #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define vi vector<int> typedef long long int ll; int main(void) { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { // cout << "Case #" << c-t << ": "; string s, t; cin >> s >> t; vector<int> pos[26]; for (int i = 0; i < s.size(); i++) { pos[s[i] - 'a'].push_back(i + 1); } ll prev = 0, ans = 0; for (int i = 0; i < t.size(); i++) { int sc = t[i] - 'a'; int position = (lower_bound(pos[sc].begin(), pos[sc].end(), prev + 1)) - pos[sc].begin(); if (position == pos[sc].size()) { if (pos[sc].size() == 0) { cout << "-1"; return 0; } ans += s.size() - prev; prev = 0; i--; } else { ans += pos[sc][position] - prev; prev = pos[sc][position]; } } cout << ans; } return 0; }
[ "variable_declaration.type.change" ]
740,974
740,973
u878492982
cpp