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 <bits/stdc++.h> #include <math.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) typedef long long ll; using Graph = vector<vector<int>>; typedef long long ll; typedef pair<int, int> P; const int MOD = 1000000007; const int INF_32 = 1LL << 30; const int64_t INF_64 = 1LL << 60; int main() { string s, t; cin >> s; cin >> t; int n_s = s.size(); int n_t = t.size(); map<char, set<int>> mp; for (int i = 0; i < n_s; i++) { mp[s[i]].insert(i); } ll now = 0; ll cycle = 0; for (int i = 0; i < n_t; i++) { if (!mp.count(t[i])) { cout << -1 << endl; return 0; } auto it = mp[t[i]].upper_bound(now); if (it == mp[t[i]].end()) { now = *mp[t[i]].begin(); cycle++; continue; } else { now = *it; } } cout << n_s * cycle + now << endl; return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) typedef long long ll; using Graph = vector<vector<int>>; typedef long long ll; typedef pair<int, int> P; const int MOD = 1000000007; const int INF_32 = 1LL << 30; const int64_t INF_64 = 1LL << 60; int main() { string s, t; cin >> s; cin >> t; int n_s = s.size(); int n_t = t.size(); map<char, set<int>> mp; for (int i = 0; i < n_s; i++) { mp[s[i]].insert(i); } ll now = -1; ll cycle = 0; for (int i = 0; i < n_t; i++) { if (!mp.count(t[i])) { cout << -1 << endl; return 0; } auto it = mp[t[i]].upper_bound(now); if (it == mp[t[i]].end()) { now = *mp[t[i]].begin(); cycle++; continue; } else { now = *it; } } cout << n_s * cycle + now + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,944
739,945
u715366261
cpp
p02937
#include <bits/stdc++.h> #include <math.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) typedef long long ll; using Graph = vector<vector<int>>; typedef long long ll; typedef pair<int, int> P; const int MOD = 1000000007; const int INF_32 = 1LL << 30; const int64_t INF_64 = 1LL << 60; int main() { string s, t; cin >> s; cin >> t; int n_s = s.size(); int n_t = t.size(); map<char, set<int>> mp; for (int i = 0; i < n_s; i++) { mp[s[i]].insert(i); } ll now = 0; ll cycle = 0; for (int i = 0; i < n_t; i++) { if (!mp.count(t[i])) { cout << -1 << endl; return 0; } auto it = mp[t[i]].upper_bound(now); if (it == mp[t[i]].end()) { now = *mp[t[i]].begin(); cycle++; continue; } else { now = *it; } } cout << n_s * cycle + now + 1 << endl; return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) typedef long long ll; using Graph = vector<vector<int>>; typedef long long ll; typedef pair<int, int> P; const int MOD = 1000000007; const int INF_32 = 1LL << 30; const int64_t INF_64 = 1LL << 60; int main() { string s, t; cin >> s; cin >> t; int n_s = s.size(); int n_t = t.size(); map<char, set<int>> mp; for (int i = 0; i < n_s; i++) { mp[s[i]].insert(i); } ll now = -1; ll cycle = 0; for (int i = 0; i < n_t; i++) { if (!mp.count(t[i])) { cout << -1 << endl; return 0; } auto it = mp[t[i]].upper_bound(now); if (it == mp[t[i]].end()) { now = *mp[t[i]].begin(); cycle++; continue; } else { now = *it; } } cout << n_s * cycle + now + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,946
739,945
u715366261
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repo(i, n) for (int i = 1; i < (int)(n); i++) #define pb push_back #define mp make_pair #define np next_permutation #define lb lower_bound #define ub upper_bound #define fi first #define se second #define all(x) (x).begin(), (x).end() #define mod 1000000007 #define pi acos(-1.0) const ll INF = 1LL << 61; 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; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } ll jou(ll N, ll P) { if (P == 0) return 1; if (P % 2 == 0) { ll t = jou(N, P / 2); return t * t % mod; } return (N * jou(N, P - 1)) % mod; } // jou(n,mod-2)で逆元 // intの最大値2147483647 ≒ 2×10^9 // long longの最大値9223372036854775807 ≒ 9×10^18 //'大文字'+=32; で小文字に // cout << fixed << setprecision (20); 小数点以下20桁まで //実行時間制約2秒では2×10^8回くらいまで計算できる int main() { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); string ss = s + s + s; vector<vector<ll>> p(26); rep(i, 3 * n) { p[ss[i] - 'a'].pb(i); } vector<vector<ll>> q(26, vector<ll>(3 * n)); rep(i, 26) { if (p[i].empty()) { rep(j, 3 * n) { q[i][j] = -1; } } else { ll cnt = 0; ll now = p[i].size() - 1; for (int j = 3 * n - 1; j >= 0; j--) { if (j == p[i][now]) { q[i][j] = cnt; cnt = 0; now--; if (now == 0) now = p[i].size() - 1; } else q[i][j] = cnt; cnt++; } } } ll ans = 0; ll now = n - 1; rep(i, m) { if (q[t[i] - 'a'][now] == -1) { cout << -1 << endl; return 0; } ans += q[t[i] - 'a'][now]; now += q[t[i] - 'a'][now]; if (now >= n) now %= n; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repo(i, n) for (int i = 1; i < (int)(n); i++) #define pb push_back #define mp make_pair #define np next_permutation #define lb lower_bound #define ub upper_bound #define fi first #define se second #define all(x) (x).begin(), (x).end() #define mod 1000000007 #define pi acos(-1.0) const ll INF = 1LL << 61; 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; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } ll jou(ll N, ll P) { if (P == 0) return 1; if (P % 2 == 0) { ll t = jou(N, P / 2); return t * t % mod; } return (N * jou(N, P - 1)) % mod; } // jou(n,mod-2)で逆元 // intの最大値2147483647 ≒ 2×10^9 // long longの最大値9223372036854775807 ≒ 9×10^18 //'大文字'+=32; で小文字に // cout << fixed << setprecision (20); 小数点以下20桁まで //実行時間制約2秒では2×10^8回くらいまで計算できる int main() { string s, t; cin >> s >> t; int n = s.size(); int m = t.size(); string ss = s + s + s; vector<vector<ll>> p(26); rep(i, 3 * n) { p[ss[i] - 'a'].pb(i); } vector<vector<ll>> q(26, vector<ll>(3 * n)); rep(i, 26) { if (p[i].empty()) { rep(j, 3 * n) { q[i][j] = -1; } } else { ll cnt = 0; ll now = p[i].size() - 1; for (int j = 3 * n - 1; j >= 0; j--) { if (j == p[i][now]) { q[i][j] = cnt; cnt = 0; now--; if (now < 0) now = p[i].size() - 1; } else q[i][j] = cnt; cnt++; } } } ll ans = 0; ll now = n - 1; rep(i, m) { if (q[t[i] - 'a'][now] == -1) { cout << -1 << endl; return 0; } ans += q[t[i] - 'a'][now]; now += q[t[i] - 'a'][now]; if (now >= n) now %= n; } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,965
739,966
u604329931
cpp
p02937
#include <bits/stdc++.h> using std::bitset; using std::cin; using std::cout; using std::endl; using std::string; using std::vector; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define reps(i, s, e) for (int i = s; i < (int)e; i++) #define coutd(i) cout << std::fixed << std::setprecision(i) typedef long double ld; typedef long long ll; typedef vector<int> vint; typedef vector<ll> vll; typedef std::pair<int, int> pii; typedef std::pair<ll, ll> pll; template <class T> using Set = std::set<T>; template <class T, class U> using Map = std::map<T, U>; template <class T> using Graph = vector<vector<T>>; const int INT_BIG = 1 << 28; int main() { string s, t; cin >> s >> t; ll slen = s.length(); Map<char, vll> cmap; rep(i, slen) { char c = s[i]; cmap[c].push_back(i); } ll ans = 1; ll nowpos = -1; int tlen = t.length(); rep(i, tlen) { char c = t[i]; if (cmap.find(c) == cmap.end()) { cout << -1 << endl; return 0; } int cmapvlen = cmap[c].size(); // cout << "c" << c << cmap[c][0] << endl; if (nowpos >= cmap[c][cmapvlen - 1]) { ans++; nowpos = cmap[c][0]; } else if (nowpos < cmap[c][0]) { nowpos = cmap[c][0]; } else { int left = -1; int right = cmapvlen; while ((right - left) > 1) { int mid = left + (right - left) / 2; if (cmap[c][mid] <= nowpos) { left = mid; } else { right = mid; } } nowpos = right; } // cout << nowpos << endl; } // cout << slen << endl; // cout << tlen << endl; // cout << ans << endl; cout << (ans - 1) * slen + nowpos + 1 << endl; }
#include <bits/stdc++.h> using std::bitset; using std::cin; using std::cout; using std::endl; using std::string; using std::vector; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define reps(i, s, e) for (int i = s; i < (int)e; i++) #define coutd(i) cout << std::fixed << std::setprecision(i) typedef long double ld; typedef long long ll; typedef vector<int> vint; typedef vector<ll> vll; typedef std::pair<int, int> pii; typedef std::pair<ll, ll> pll; template <class T> using Set = std::set<T>; template <class T, class U> using Map = std::map<T, U>; template <class T> using Graph = vector<vector<T>>; const int INT_BIG = 1 << 28; int main() { string s, t; cin >> s >> t; ll slen = s.length(); Map<char, vll> cmap; rep(i, slen) { char c = s[i]; cmap[c].push_back(i); } ll ans = 1; ll nowpos = -1; int tlen = t.length(); rep(i, tlen) { char c = t[i]; if (cmap.find(c) == cmap.end()) { cout << -1 << endl; return 0; } int cmapvlen = cmap[c].size(); // cout << "c" << c << cmap[c][0] << endl; if (nowpos >= cmap[c][cmapvlen - 1]) { ans++; nowpos = cmap[c][0]; } else if (nowpos < cmap[c][0]) { nowpos = cmap[c][0]; } else { int left = -1; int right = cmapvlen; while ((right - left) > 1) { int mid = left + (right - left) / 2; if (cmap[c][mid] <= nowpos) { left = mid; } else { right = mid; } } nowpos = cmap[c][right]; } // cout << "n" << nowpos << endl; // cout << ans << endl; } cout << (ans - 1) * slen + nowpos + 1 << endl; }
[]
739,967
739,968
u718048349
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) using ll = long long; const ll MOD = 1000000007; // 998244353; void solve() { string s, t; cin >> s >> t; vector<set<int>> vs(26); rep(i, s.size()) vs[int(s[i] - 'a')].insert(i + 1); int k = 1; ll ans = 0; rep(i, t.size()) { if (vs[int(t[i] - 'a')].empty()) { cout << -1 << endl; return; } set<int>::iterator itr = vs[int(t[i] - 'a')].lower_bound(k + 1); if (itr == vs[int(t[i] - 'a')].end()) { itr = vs[int(t[i] - 'a')].lower_bound(1); ans += s.size() - k + *itr; k = *itr; } else { ans += *itr - k; k = *itr; } } ans++; cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) using ll = long long; const ll MOD = 1000000007; // 998244353; void solve() { string s, t; cin >> s >> t; vector<set<int>> vs(26); rep(i, s.size()) vs[int(s[i] - 'a')].insert(i + 1); int k = 0; ll ans = 0; rep(i, t.size()) { if (vs[int(t[i] - 'a')].empty()) { cout << -1 << endl; return; } set<int>::iterator itr = vs[int(t[i] - 'a')].lower_bound(k + 1); if (itr == vs[int(t[i] - 'a')].end()) { itr = vs[int(t[i] - 'a')].lower_bound(1); ans += s.size() - k + *itr; k = *itr; } else { ans += *itr - k; k = *itr; } } cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); }
[ "literal.number.change", "variable_declaration.value.change", "expression.unary.arithmetic.remove" ]
739,969
739,970
u528388170
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) using ll = long long; const ll MOD = 1000000007; // 998244353; void solve() { string s, t; cin >> s >> t; vector<set<int>> vs(26); rep(i, s.size()) vs[int(s[i] - 'a')].insert(i + 1); int k = -1; ll ans = 0; rep(i, t.size()) { if (vs[int(t[i] - 'a')].empty()) { cout << -1 << endl; return; } set<int>::iterator itr = vs[int(t[i] - 'a')].lower_bound(k); if (itr == vs[int(t[i] - 'a')].end()) { itr = vs[int(t[i] - 'a')].lower_bound(-1); ans += s.size() - k + *itr; k = *itr; } else { ans += *itr - k; k = *itr; } } cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) using ll = long long; const ll MOD = 1000000007; // 998244353; void solve() { string s, t; cin >> s >> t; vector<set<int>> vs(26); rep(i, s.size()) vs[int(s[i] - 'a')].insert(i + 1); int k = 0; ll ans = 0; rep(i, t.size()) { if (vs[int(t[i] - 'a')].empty()) { cout << -1 << endl; return; } set<int>::iterator itr = vs[int(t[i] - 'a')].lower_bound(k + 1); if (itr == vs[int(t[i] - 'a')].end()) { itr = vs[int(t[i] - 'a')].lower_bound(1); ans += s.size() - k + *itr; k = *itr; } else { ans += *itr - k; k = *itr; } } cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); }
[ "literal.number.change", "variable_declaration.value.change", "expression.operation.unary.arithmetic.remove" ]
739,971
739,970
u528388170
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) using ll = long long; const ll MOD = 1000000007; // 998244353; void solve() { string s, t; cin >> s >> t; vector<set<int>> vs(26); rep(i, s.size()) vs[int(s[i] - 'a')].insert(i + 1); int k = 0; ll ans = 0; rep(i, t.size()) { if (vs[int(t[i] - 'a')].empty()) { cout << -1 << endl; return; } set<int>::iterator itr = vs[int(t[i] - 'a')].lower_bound(k); if (itr == vs[int(t[i] - 'a')].end()) { itr = vs[int(t[i] - 'a')].lower_bound(0); ans += s.size() - k + *itr; k = *itr; } else { ans += *itr - k; k = *itr; } } cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) using ll = long long; const ll MOD = 1000000007; // 998244353; void solve() { string s, t; cin >> s >> t; vector<set<int>> vs(26); rep(i, s.size()) vs[int(s[i] - 'a')].insert(i + 1); int k = 0; ll ans = 0; rep(i, t.size()) { if (vs[int(t[i] - 'a')].empty()) { cout << -1 << endl; return; } set<int>::iterator itr = vs[int(t[i] - 'a')].lower_bound(k + 1); if (itr == vs[int(t[i] - 'a')].end()) { itr = vs[int(t[i] - 'a')].lower_bound(1); ans += s.size() - k + *itr; k = *itr; } else { ans += *itr - k; k = *itr; } } cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); }
[ "literal.number.change", "assignment.value.change", "call.arguments.change" ]
739,972
739,970
u528388170
cpp
p02937
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #define imx INT_MAX #define imn INT_MIN #define llmx LLONG_MAX #define llmn LLONG_MIN #define INF 100000000000000000 #define PI 3.1415926535897932384626433832795l #define fi first #define se second #define pb push_back #define f_s(a) sort(a.begin(), a.end()) #define b_s(a) sort(a.rbegin(), a.rend()) #define p(a) cout << a << "\n" // ll mod = 1000000007; // #define l(i, ) // #define rl(i, a, b) for(int i = a; i < b; i++) // struct mycomp { // bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{ // if (a.second-a.first != b.second-b.first) // return (a.second-a.first > b.second-b.first); // return a.first < b.first; // } // }; /////////////////////GCD////////////////////// ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll extended_gcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll x1, y1; ll d = extended_gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } ////////////////////SIEVE OF ERATOSTHENES////////////////////// vector<int> sieveoferatosthenes(int n) { vector<bool> prime(n + 1, true); for (int i = 2; i <= sqrt(n); i++) { if (prime[i]) { for (int j = i * i; j <= n; j += i) { prime[j] = false; } } } vector<int> all_primes; for (int i = 2; i <= n; i++) { if (prime[i]) all_primes.pb(i); } return all_primes; } ////////////////////BINARY EXPONENTIATION/////////////////////// ll bin_exp(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b % 2) { b--; ans = (ans % mod * a % mod) % mod; } b /= 2; a = (a % mod * a % mod) % mod; } return ans; } ///////////////////////////BFS////////////////////////////////// void bfs(vector<int> &distance, vector<int> a[], vector<bool> &visited, int u, vector<int> &parent) { visited[u] = true; parent[u] = -1; distance[u] = 0; queue<int> q; q.push(u); while (!q.empty()) { int f = q.front(); q.pop(); for (int i = 0; i < a[f].size(); i++) { if (visited[a[f][i]] == false) { distance[a[f][i]] = distance[f] + 1; parent[a[f][i]] = f; visited[a[f][i]] = true; q.push(a[f][i]); } } } } void solve() {} int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif string s, t; cin >> s >> t; vector<int> c1(26, 0), c2(26, 0); vector<int> adj[26]; for (int i = 0; i < s.size(); i++) { adj[s[i] - 97].pb(i); c1[s[i] - 97]++; } // for(int i = 0; i < 26; i++) // { // for(auto j:adj[i]) // { // cout<<j<<" "; // } // cout<<endl; // } for (int i = 0; i < t.size(); i++) { c2[t[i] - 97]++; } int f = 0; for (int i = 0; i < 26; i++) { if (c2[i] != 0) { if (c1[i] == 0) { f = 1; break; } } } if (f) { p(-1); return 0; } int curr = -1, turns = 0; for (int i = 0; i < t.size(); i++) { auto lw = lower_bound(adj[t[i] - 97].begin(), adj[t[i] - 97].end(), curr); // cout<<*lw<<endl; if (lw == adj[t[i] - 97].end()) { // cout<<"Entered\n"; turns++; // curr=-1; curr = adj[t[i] - 97][0]; } else { curr = *lw; } } cout << turns * s.size() + curr + 1; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #define imx INT_MAX #define imn INT_MIN #define llmx LLONG_MAX #define llmn LLONG_MIN #define INF 100000000000000000 #define PI 3.1415926535897932384626433832795l #define fi first #define se second #define pb push_back #define f_s(a) sort(a.begin(), a.end()) #define b_s(a) sort(a.rbegin(), a.rend()) #define p(a) cout << a << "\n" // ll mod = 1000000007; // #define l(i, ) // #define rl(i, a, b) for(int i = a; i < b; i++) // struct mycomp { // bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{ // if (a.second-a.first != b.second-b.first) // return (a.second-a.first > b.second-b.first); // return a.first < b.first; // } // }; /////////////////////GCD////////////////////// ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll extended_gcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll x1, y1; ll d = extended_gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } ////////////////////SIEVE OF ERATOSTHENES////////////////////// vector<int> sieveoferatosthenes(int n) { vector<bool> prime(n + 1, true); for (int i = 2; i <= sqrt(n); i++) { if (prime[i]) { for (int j = i * i; j <= n; j += i) { prime[j] = false; } } } vector<int> all_primes; for (int i = 2; i <= n; i++) { if (prime[i]) all_primes.pb(i); } return all_primes; } ////////////////////BINARY EXPONENTIATION/////////////////////// ll bin_exp(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b % 2) { b--; ans = (ans % mod * a % mod) % mod; } b /= 2; a = (a % mod * a % mod) % mod; } return ans; } ///////////////////////////BFS////////////////////////////////// void bfs(vector<int> &distance, vector<int> a[], vector<bool> &visited, int u, vector<int> &parent) { visited[u] = true; parent[u] = -1; distance[u] = 0; queue<int> q; q.push(u); while (!q.empty()) { int f = q.front(); q.pop(); for (int i = 0; i < a[f].size(); i++) { if (visited[a[f][i]] == false) { distance[a[f][i]] = distance[f] + 1; parent[a[f][i]] = f; visited[a[f][i]] = true; q.push(a[f][i]); } } } } void solve() {} int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif string s, t; cin >> s >> t; vector<int> c1(26, 0), c2(26, 0); vector<int> adj[26]; for (int i = 0; i < s.size(); i++) { adj[s[i] - 97].pb(i); c1[s[i] - 97]++; } // for(int i = 0; i < 26; i++) // { // for(auto j:adj[i]) // { // cout<<j<<" "; // } // cout<<endl; // } for (int i = 0; i < t.size(); i++) { c2[t[i] - 97]++; } int f = 0; for (int i = 0; i < 26; i++) { if (c2[i] != 0) { if (c1[i] == 0) { f = 1; break; } } } if (f) { p(-1); return 0; } int curr = -1, turns = 0; for (int i = 0; i < t.size(); i++) { auto lw = lower_bound(adj[t[i] - 97].begin(), adj[t[i] - 97].end(), curr + 1); // cout<<*lw<<endl; if (lw == adj[t[i] - 97].end()) { // cout<<"Entered\n"; turns++; // curr=-1; curr = adj[t[i] - 97][0]; } else { curr = *lw; } // cout<<curr<<endl; } cout << turns * s.size() + curr + 1; return 0; }
[ "assignment.change" ]
739,973
739,974
u644164234
cpp
p02937
/* URL https:// SCORE 0 AC false WA false TLE false MLE false TASK_TYPE FAILURE_TYPE NOTES */ #include <algorithm> #include <cstdint> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> /* import STL */ // stream using std::cerr; using std::cin; using std::cout; using std::endl; using std::flush; // basic types using std::nullptr_t; using std::pair; using std::string; using std::tuple; // function for basic types using std::get; using std::make_pair; using std::make_tuple; /* TODO remove them */ using std::queue; using std::stack; using std::vector; // algorithms using std::accumulate; using std::lower_bound; using std::max_element; using std::min_element; using std::nth_element; using std::upper_bound; /* macros */ // loops #define REP(i, n) for (i64 i = 0; i < static_cast<decltype(i)>(n); ++i) #define REPR(i, n) for (i64 i = (n)-1; i >= static_cast<decltype(i)>(0); --i) #define FOR(i, n, m) for (i64 i = (n); i < static_cast<decltype(i)>(m); ++i) #define FORR(i, n, m) for (i64 i = (m)-1; i >= static_cast<decltype(i)>(n); --i) #define EACH(x, xs) for (auto &x : (xs)) #define EACH_V(x, xs) for (auto x : (xs)) // helpers #define CTR(x) (x).begin(), (x).end() /* utils for std::tuple */ namespace internal { namespace tuple_utils { // TODO rename to "internal::tuple" template <size_t...> struct seq {}; template <size_t N, size_t... Is> struct gen_seq : gen_seq<N - 1, N - 1, Is...> {}; template <size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {}; template <class Tuple, size_t... Is> void read(std::istream &stream, Tuple &t, seq<Is...>) { static_cast<void>((int[]){0, (void(stream >> get<Is>(t)), 0)...}); } template <class Tuple, size_t... Is> void print(std::ostream &stream, Tuple const &t, seq<Is...>) { static_cast<void>( (int[]){0, (void(stream << (Is == 0 ? "" : ", ") << get<Is>(t)), 0)...}); } template <size_t I, class F, class A, class... Elems> struct ForEach { void operator()(A &arg, tuple<Elems...> const &t) const { F()(arg, get<I>(t)); ForEach<I - 1, F, A, Elems...>()(arg, t); } void operator()(A &arg, tuple<Elems...> &t) const { F()(arg, get<I>(t)); ForEach<I - 1, F, A, Elems...>()(arg, t); } }; template <class F, class A, class... Elems> struct ForEach<0, F, A, Elems...> { void operator()(A &arg, tuple<Elems...> const &t) const { F()(arg, get<0>(t)); } void operator()(A &arg, tuple<Elems...> &t) const { F()(arg, get<0>(t)); } }; template <class F, class A, class... Elems> void for_each(A &arg, tuple<Elems...> const &t) { ForEach<std::tuple_size<tuple<Elems...>>::value - 1, F, A, Elems...>()(arg, t); } template <class F, class A, class... Elems> void for_each(A &arg, tuple<Elems...> &t) { ForEach<std::tuple_size<tuple<Elems...>>::value - 1, F, A, Elems...>()(arg, t); } } // namespace tuple_utils } // namespace internal /* utils for Matrix (definition of Matrix) */ namespace internal { namespace matrix { template <typename V, int N> struct matrix_t { using type = std::vector<typename matrix_t<V, N - 1>::type>; }; template <typename V> struct matrix_t<V, 0> { using type = V; }; template <typename V, int N> using Matrix = typename matrix_t<V, N>::type; template <typename V, typename It, int N> struct matrix_helper { static Matrix<V, N> create(const It &begin, const It &end, const V &default_value) { return Matrix<V, N>(*begin, matrix_helper<V, It, N - 1>::create( begin + 1, end, default_value)); } }; template <typename V, typename It> struct matrix_helper<V, It, 0> { static Matrix<V, 0> create(const It &begin __attribute__((unused)), const It &end __attribute__((unused)), const V &default_value) { return default_value; } }; } // namespace matrix } // namespace internal /* Primitive types */ using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using usize = size_t; /* Data structure type */ template <typename T> using Vector = std::vector<T>; template <typename V> using OrderedSet = std::set<V>; template <typename V> using HashSet = std::unordered_set<V>; template <typename K, typename V> using OrderedMap = std::map<K, V>; template <typename K, typename V> using HashMap = std::unordered_map<K, V>; template <typename T, int N> using Matrix = internal::matrix::Matrix<T, N>; template <typename T, typename Compare = std::less<T>, typename Container = std::vector<T>> using PriorityQueue = std::priority_queue<T, Container, Compare>; /* utils for Vector */ template <typename V> Vector<V> make_pre_allocated_vector(size_t N) { Vector<V> retval; retval.reserve(N); return retval; } /* utils for Matrix */ template <class V, int N> Matrix<V, N> make_matrix(const std::array<size_t, N> &shape, V default_value = V()) { return internal::matrix::matrix_helper<V, decltype(shape.begin()), N>::create( shape.begin(), shape.end(), default_value); } /* utils for STL iterators */ namespace internal { template <typename Iterator, typename F> struct MappedIterator { MappedIterator(const Iterator &it, const F &function) : it(it), function(function) {} auto operator*() const { return this->function(this->it); } void operator++() { ++this->it; } void operator+=(size_t n) { this->it += n; } auto operator+(size_t n) const { return MappedIterator<Iterator, F>(this->it + n, this->function); } bool operator==(const MappedIterator<Iterator, F> &rhs) const { return this->it == rhs.it; } bool operator!=(const MappedIterator<Iterator, F> &rhs) const { return !(*this == rhs); } private: Iterator it; F function; }; template <typename Iterator, typename P> struct FilteredIterator { FilteredIterator(const Iterator &it, const Iterator &end, const P &predicate) : it(it), end(end), predicate(predicate) { if (this->it != end) { if (!predicate(this->it)) { this->increment(); } } } decltype(auto) operator*() const { return *this->it; } auto operator->() const { return this->it; } void operator++() { this->increment(); } void operator+=(size_t n) { REP(i, n) { this->increment(); } } auto operator+(size_t n) const { auto retval = *this; retval += n; return retval; } bool operator==(const FilteredIterator<Iterator, P> &rhs) const { return this->it == rhs.it; } bool operator!=(const FilteredIterator<Iterator, P> &rhs) const { return !(*this == rhs); } private: void increment() { if (this->it == this->end) { return; } ++this->it; while (this->it != this->end && !this->predicate(this->it)) { ++this->it; } } Iterator it; Iterator end; P predicate; }; template <typename Iterator, typename ElementIterator> struct FlattenedIterator { FlattenedIterator(const Iterator &it, const Iterator &end) : it(make_pair(it, ElementIterator())), end(end) { if (this->it.first != this->end) { this->it.second = it->begin(); } this->find_valid(); } decltype(auto) operator*() const { return this->it; } const pair<Iterator, ElementIterator> *operator->() const { return &this->it; } void operator++() { this->increment(); } void operator+=(size_t n) { REP(i, n) { this->increment(); } } auto operator+(size_t n) const { auto retval = *this; retval += n; return retval; } bool operator==(const FlattenedIterator<Iterator, ElementIterator> &rhs) const { if (this->it.first != rhs.it.first) { return false; } if (this->it.first == this->end || rhs.it.first == rhs.end) { if (this->end == rhs.end) { return true; } else { return false; } } else { return this->it.second == rhs.it.second; } } bool operator!=(const FlattenedIterator<Iterator, ElementIterator> &rhs) const { return !(*this == rhs); } private: bool is_end() const { return this->it.first == this->end; } bool is_valid() const { if (this->is_end()) return false; if (this->it.second == this->it.first->end()) return false; return true; } void _increment() { if (this->it.second == this->it.first->end()) { ++this->it.first; if (this->it.first != this->end) { this->it.second = this->it.first->begin(); } } else { ++this->it.second; } } void find_valid() { while (!this->is_end() && !this->is_valid()) { this->_increment(); } } void increment() { this->_increment(); while (!this->is_end() && !this->is_valid()) { this->_increment(); } } pair<Iterator, ElementIterator> it; Iterator end; }; } // namespace internal template <class Iterator> struct Container { Container(const Iterator &begin, const Iterator &end) : m_begin(begin), m_end(end) {} const Iterator &begin() const { return this->m_begin; } const Iterator &end() const { return this->m_end; } Iterator m_begin; Iterator m_end; }; template <typename C, typename F> auto iterator_map(const C &c, F function) { using Iterator = std::remove_const_t<std::remove_reference_t<decltype(c.begin())>>; return Container<internal::MappedIterator<Iterator, F>>( internal::MappedIterator<Iterator, F>(c.begin(), function), internal::MappedIterator<Iterator, F>(c.end(), function)); } template <typename C, typename P> auto iterator_filter(const C &c, P predicate) { using Iterator = std::remove_const_t<std::remove_reference_t<decltype(c.begin())>>; return Container<internal::FilteredIterator<Iterator, P>>( internal::FilteredIterator<Iterator, P>(c.begin(), c.end(), predicate), internal::FilteredIterator<Iterator, P>(c.end(), c.end(), predicate)); } template <typename C> auto iterator_flatten(const C &c) { using Iterator = std::remove_const_t<std::remove_reference_t<decltype(c.begin())>>; using ElementIterator = std::remove_const_t< std::remove_reference_t<decltype(c.begin()->begin())>>; return Container<internal::FlattenedIterator<Iterator, ElementIterator>>( internal::FlattenedIterator<Iterator, ElementIterator>(c.begin(), c.end()), internal::FlattenedIterator<Iterator, ElementIterator>(c.end(), c.end())); } /* input */ template <class F, class S> std::istream &operator>>(std::istream &stream, pair<F, S> &pair) { stream >> pair.first; stream >> pair.second; return stream; } template <class... Args> std::istream &operator>>(std::istream &stream, tuple<Args...> &tuple) { internal::tuple_utils::read( stream, tuple, internal::tuple_utils::gen_seq<sizeof...(Args)>()); return stream; } template <class T> T read() { T t; cin >> t; return t; } template <class F, class S> pair<F, S> read() { pair<F, S> p; cin >> p; return p; } template <class T1, class T2, class T3, class... Args> tuple<T1, T2, T3, Args...> read() { tuple<T1, T2, T3, Args...> t; cin >> t; return t; } template <typename T, typename F = std::function<T()>> Vector<T> read(const usize length, F r) { auto retval = make_pre_allocated_vector<T>(length); REP(i, length) { retval.emplace_back(r()); } return retval; } template <class T> Vector<T> read(const usize length) { return read<T>(length, [] { return read<T>(); }); } template <class F, class S> Vector<pair<F, S>> read(const usize length) { return read<pair<F, S>>(length); } template <class T1, class T2, class T3, class... Args> Vector<tuple<T1, T2, T3, Args...>> read(const usize length) { return read<tuple<T1, T2, T3, Args...>>(length); } namespace internal { template <typename T> struct oneline { std::string operator()(const T &t) const { std::ostringstream oss; oss << t; return oss.str(); } }; template <typename F, typename S> struct oneline<pair<F, S>> { std::string operator()(const pair<F, S> &p) const { std::ostringstream oss; oss << "{" << oneline<F>()(p.first) << ", " << oneline<S>()(p.second) << "}"; return oss.str(); } }; template <typename... Args> struct oneline<tuple<Args...>> { struct oneline_tuple { template <class V> void operator()(Vector<std::string> &strs, const V &v) const { strs.emplace_back(oneline<V>()(v)); } }; std::string operator()(const tuple<Args...> &t) const { std::ostringstream oss; Vector<std::string> strs; internal::tuple_utils::for_each<oneline_tuple, Vector<std::string>, Args...>(strs, t); oss << "{"; REPR(i, strs.size()) { oss << strs[i]; if (i != 0) { oss << ", "; } } oss << "}"; return oss.str(); } }; template <> struct oneline<bool> { std::string operator()(const bool b) const { return b ? "true" : "false"; } }; template <typename X> struct oneline<Vector<X>> { std::string operator()(const Vector<X> &vec) const { std::string retval = "["; auto f = oneline<X>(); REP(i, vec.size()) { retval += f(vec[i]); if (i != static_cast<i64>(vec.size() - 1)) { retval += ", "; } } retval += "]"; return retval; } }; template <typename X> struct oneline<OrderedSet<X>> { std::string operator()(const OrderedSet<X> &s) const { std::string retval = "{"; auto f = oneline<X>(); size_t ctr = 0; EACH(x, s) { retval += f(x); ctr += 1; if (ctr != s.size()) { retval += ", "; } } retval += "}"; return retval; } }; template <typename X> struct oneline<HashSet<X>> { std::string operator()(const HashSet<X> &s) const { std::string retval = "{"; auto f = oneline<X>(); size_t ctr = 0; EACH(x, s) { retval += f(x); ctr += 1; if (ctr != s.size()) { retval += ", "; } } retval += "}"; return retval; } }; template <typename K, typename V> struct oneline<OrderedMap<K, V>> { std::string operator()(const OrderedMap<K, V> &s) const { std::string retval = "{"; auto f1 = oneline<K>(); auto f2 = oneline<V>(); size_t ctr = 0; EACH(x, s) { retval += f1(x.first); retval += ": "; retval += f2(x.second); ctr += 1; if (ctr != s.size()) { retval += ", "; } } retval += "}"; return retval; } }; template <typename K, typename V> struct oneline<HashMap<K, V>> { std::string operator()(const HashMap<K, V> &s) const { std::string retval = "{"; auto f1 = oneline<K>(); auto f2 = oneline<V>(); size_t ctr = 0; EACH(x, s) { retval += f1(x.first); retval += ": "; retval += f2(x.second); ctr += 1; if (ctr != s.size()) { retval += ", "; } } retval += "}"; return retval; } }; template <typename V> struct keys { /* no implementation */ }; template <typename X> struct keys<std::vector<X>> { Vector<size_t> operator()(const Vector<X> &v) const { Vector<size_t> keys; REP(i, v.size()) { keys.emplace_back(i); } return keys; } }; template <typename K, typename V> struct keys<OrderedMap<K, V>> { Vector<K> operator()(const OrderedMap<K, V> &c) const { Vector<K> keys; EACH(elem, c) { keys.emplace_back(elem.first); } return keys; } }; template <typename K, typename V> struct keys<HashMap<K, V>> { Vector<K> operator()(const HashMap<K, V> &c) const { Vector<K> keys; EACH(elem, c) { keys.emplace_back(elem.first); } return keys; } }; } // namespace internal template <typename T> void dump(const T &t) { using namespace internal; std::cerr << oneline<T>()(t) << std::endl; } template <typename V1, typename V2, typename... Args> void dump(const V1 &v1, const V2 &v2, const Args &...args) { using namespace internal; using F = typename oneline<tuple<V1, V2, Args...>>::oneline_tuple; auto x = std::make_tuple(v1, v2, args...); Vector<std::string> strs; internal::tuple_utils::for_each<F, Vector<std::string>, V1, V2, Args...>(strs, x); REPR(i, strs.size()) { std::cerr << strs[i]; if (i != 0) { std::cerr << ", "; } } std::cerr << std::endl; } template <typename C> std::string as_set(const C &ctr) { Vector<std::string> values; using namespace internal; EACH(x, ctr) { values.emplace_back(oneline<decltype(x)>()(x)); } std::string retval = "---\n"; REP(i, values.size()) { retval += values[i]; retval += "\n"; } retval += "---"; return retval; } template <typename C> std::string as_map(const C &ctr) { using namespace internal; auto ks = keys<C>()(ctr); Vector<std::string> keys; Vector<std::string> values; EACH(key, ks) { keys.emplace_back(oneline<decltype(key)>()(key)); values.emplace_back(oneline<decltype(ctr.at(key))>()(ctr.at(key))); } size_t l = 0; EACH(key, keys) { l = std::max(l, key.size()); } std::string retval = "---\n"; REP(i, values.size()) { retval += keys[i]; REP(j, l - keys[i].size()) { retval += " "; } retval += ": "; retval += values[i]; retval += "\n"; } retval += "---"; return retval; } template <typename C> std::string as_table(const C &ctr) { using namespace internal; auto rkeys = keys<C>()(ctr); auto ckeys = OrderedSet<std::string>(); auto values = Vector<pair<std::string, OrderedMap<std::string, std::string>>>(); /* Stringify all data */ EACH(rkey, rkeys) { auto rkey_str = oneline<decltype(rkey)>()(rkey); values.emplace_back(rkey_str, OrderedMap<std::string, std::string>()); auto row = ctr.at(rkey); auto ks = keys<decltype(row)>()(row); EACH(ckey, ks) { auto ckey_str = oneline<decltype(ckey)>()(ckey); ckeys.emplace(ckey_str); values.back().second.emplace( ckey_str, oneline<decltype(row.at(ckey))>()(row.at(ckey))); } } /* Calculate string length */ size_t max_row_key_length = 0; EACH(value, values) { max_row_key_length = std::max(max_row_key_length, value.first.size()); } OrderedMap<std::string, size_t> max_col_length; EACH(ckey, ckeys) { max_col_length.emplace(ckey, ckey.size()); } EACH(value, values) { EACH(elem, value.second) { auto ckey = elem.first; auto value = elem.second; max_col_length[ckey] = std::max(max_col_length[ckey], value.size()); } } std::string retval = "---\n"; /* Header */ REP(i, max_row_key_length) { retval += " "; } retval += " "; size_t cnt = 0; EACH(ckey, ckeys) { retval += ckey; REP(j, max_col_length[ckey] - ckey.size()) { retval += " "; } cnt += 1; if (cnt != ckeys.size()) { retval += ", "; } } retval += "\n------\n"; /* Values */ EACH(value, values) { retval += value.first; REP(i, max_row_key_length - value.first.size()) { retval += " "; } retval += "| "; size_t cnt = 0; EACH(ckey, ckeys) { auto v = std::string(""); if (value.second.find(ckey) != value.second.end()) { v = value.second.at(ckey); } retval += v; REP(j, max_col_length[ckey] - v.size()) { retval += " "; } cnt += 1; if (cnt != ckeys.size()) { retval += ", "; } } retval += "\n"; } retval += "---"; return retval; } // Hash namespace std { template <class F, class S> struct hash<pair<F, S>> { size_t operator()(const pair<F, S> &p) const { return hash<F>()(p.first) ^ hash<S>()(p.second); } }; template <class... Args> struct hash<tuple<Args...>> { struct hash_for_element { template <class V> void operator()(size_t &size, const V &v) const { size ^= std::hash<V>()(v); } }; size_t operator()(const tuple<Args...> &t) const { size_t retval = 0; internal::tuple_utils::for_each<hash_for_element, size_t, Args...>(retval, t); return retval; } }; } // namespace std #define MAIN void body(); // main function (DO NOT EDIT) int main(int argc, char **argv) { cin.tie(0); std::ios_base::sync_with_stdio(false); cout << std::fixed; body(); return 0; } void body() { auto s = read<string>(); auto t = read<string>(); OrderedMap<char, Vector<i64>> I; REP(i, s.size()) { I[s[i]].push_back(i + 1); } i64 ans = 0; size_t i_s = 0, i_t = 0; while (i_t < t.size()) { auto ch = t[i_t]; auto it_j = std::lower_bound(I[ch].begin(), I[ch].end(), i_s); if (it_j == I[ch].end() && i_s == 0) { cout << -1 << endl; return; } if (it_j == I[ch].end()) { ans += (s.size() - i_s); i_s = 0; continue; } auto j = *it_j; ans += (j - i_s); i_s = j; i_t += 1; } cout << ans << endl; }
/* URL https:// SCORE 0 AC false WA false TLE false MLE false TASK_TYPE FAILURE_TYPE NOTES */ #include <algorithm> #include <cstdint> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> /* import STL */ // stream using std::cerr; using std::cin; using std::cout; using std::endl; using std::flush; // basic types using std::nullptr_t; using std::pair; using std::string; using std::tuple; // function for basic types using std::get; using std::make_pair; using std::make_tuple; /* TODO remove them */ using std::queue; using std::stack; using std::vector; // algorithms using std::accumulate; using std::lower_bound; using std::max_element; using std::min_element; using std::nth_element; using std::upper_bound; /* macros */ // loops #define REP(i, n) for (i64 i = 0; i < static_cast<decltype(i)>(n); ++i) #define REPR(i, n) for (i64 i = (n)-1; i >= static_cast<decltype(i)>(0); --i) #define FOR(i, n, m) for (i64 i = (n); i < static_cast<decltype(i)>(m); ++i) #define FORR(i, n, m) for (i64 i = (m)-1; i >= static_cast<decltype(i)>(n); --i) #define EACH(x, xs) for (auto &x : (xs)) #define EACH_V(x, xs) for (auto x : (xs)) // helpers #define CTR(x) (x).begin(), (x).end() /* utils for std::tuple */ namespace internal { namespace tuple_utils { // TODO rename to "internal::tuple" template <size_t...> struct seq {}; template <size_t N, size_t... Is> struct gen_seq : gen_seq<N - 1, N - 1, Is...> {}; template <size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {}; template <class Tuple, size_t... Is> void read(std::istream &stream, Tuple &t, seq<Is...>) { static_cast<void>((int[]){0, (void(stream >> get<Is>(t)), 0)...}); } template <class Tuple, size_t... Is> void print(std::ostream &stream, Tuple const &t, seq<Is...>) { static_cast<void>( (int[]){0, (void(stream << (Is == 0 ? "" : ", ") << get<Is>(t)), 0)...}); } template <size_t I, class F, class A, class... Elems> struct ForEach { void operator()(A &arg, tuple<Elems...> const &t) const { F()(arg, get<I>(t)); ForEach<I - 1, F, A, Elems...>()(arg, t); } void operator()(A &arg, tuple<Elems...> &t) const { F()(arg, get<I>(t)); ForEach<I - 1, F, A, Elems...>()(arg, t); } }; template <class F, class A, class... Elems> struct ForEach<0, F, A, Elems...> { void operator()(A &arg, tuple<Elems...> const &t) const { F()(arg, get<0>(t)); } void operator()(A &arg, tuple<Elems...> &t) const { F()(arg, get<0>(t)); } }; template <class F, class A, class... Elems> void for_each(A &arg, tuple<Elems...> const &t) { ForEach<std::tuple_size<tuple<Elems...>>::value - 1, F, A, Elems...>()(arg, t); } template <class F, class A, class... Elems> void for_each(A &arg, tuple<Elems...> &t) { ForEach<std::tuple_size<tuple<Elems...>>::value - 1, F, A, Elems...>()(arg, t); } } // namespace tuple_utils } // namespace internal /* utils for Matrix (definition of Matrix) */ namespace internal { namespace matrix { template <typename V, int N> struct matrix_t { using type = std::vector<typename matrix_t<V, N - 1>::type>; }; template <typename V> struct matrix_t<V, 0> { using type = V; }; template <typename V, int N> using Matrix = typename matrix_t<V, N>::type; template <typename V, typename It, int N> struct matrix_helper { static Matrix<V, N> create(const It &begin, const It &end, const V &default_value) { return Matrix<V, N>(*begin, matrix_helper<V, It, N - 1>::create( begin + 1, end, default_value)); } }; template <typename V, typename It> struct matrix_helper<V, It, 0> { static Matrix<V, 0> create(const It &begin __attribute__((unused)), const It &end __attribute__((unused)), const V &default_value) { return default_value; } }; } // namespace matrix } // namespace internal /* Primitive types */ using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using usize = size_t; /* Data structure type */ template <typename T> using Vector = std::vector<T>; template <typename V> using OrderedSet = std::set<V>; template <typename V> using HashSet = std::unordered_set<V>; template <typename K, typename V> using OrderedMap = std::map<K, V>; template <typename K, typename V> using HashMap = std::unordered_map<K, V>; template <typename T, int N> using Matrix = internal::matrix::Matrix<T, N>; template <typename T, typename Compare = std::less<T>, typename Container = std::vector<T>> using PriorityQueue = std::priority_queue<T, Container, Compare>; /* utils for Vector */ template <typename V> Vector<V> make_pre_allocated_vector(size_t N) { Vector<V> retval; retval.reserve(N); return retval; } /* utils for Matrix */ template <class V, int N> Matrix<V, N> make_matrix(const std::array<size_t, N> &shape, V default_value = V()) { return internal::matrix::matrix_helper<V, decltype(shape.begin()), N>::create( shape.begin(), shape.end(), default_value); } /* utils for STL iterators */ namespace internal { template <typename Iterator, typename F> struct MappedIterator { MappedIterator(const Iterator &it, const F &function) : it(it), function(function) {} auto operator*() const { return this->function(this->it); } void operator++() { ++this->it; } void operator+=(size_t n) { this->it += n; } auto operator+(size_t n) const { return MappedIterator<Iterator, F>(this->it + n, this->function); } bool operator==(const MappedIterator<Iterator, F> &rhs) const { return this->it == rhs.it; } bool operator!=(const MappedIterator<Iterator, F> &rhs) const { return !(*this == rhs); } private: Iterator it; F function; }; template <typename Iterator, typename P> struct FilteredIterator { FilteredIterator(const Iterator &it, const Iterator &end, const P &predicate) : it(it), end(end), predicate(predicate) { if (this->it != end) { if (!predicate(this->it)) { this->increment(); } } } decltype(auto) operator*() const { return *this->it; } auto operator->() const { return this->it; } void operator++() { this->increment(); } void operator+=(size_t n) { REP(i, n) { this->increment(); } } auto operator+(size_t n) const { auto retval = *this; retval += n; return retval; } bool operator==(const FilteredIterator<Iterator, P> &rhs) const { return this->it == rhs.it; } bool operator!=(const FilteredIterator<Iterator, P> &rhs) const { return !(*this == rhs); } private: void increment() { if (this->it == this->end) { return; } ++this->it; while (this->it != this->end && !this->predicate(this->it)) { ++this->it; } } Iterator it; Iterator end; P predicate; }; template <typename Iterator, typename ElementIterator> struct FlattenedIterator { FlattenedIterator(const Iterator &it, const Iterator &end) : it(make_pair(it, ElementIterator())), end(end) { if (this->it.first != this->end) { this->it.second = it->begin(); } this->find_valid(); } decltype(auto) operator*() const { return this->it; } const pair<Iterator, ElementIterator> *operator->() const { return &this->it; } void operator++() { this->increment(); } void operator+=(size_t n) { REP(i, n) { this->increment(); } } auto operator+(size_t n) const { auto retval = *this; retval += n; return retval; } bool operator==(const FlattenedIterator<Iterator, ElementIterator> &rhs) const { if (this->it.first != rhs.it.first) { return false; } if (this->it.first == this->end || rhs.it.first == rhs.end) { if (this->end == rhs.end) { return true; } else { return false; } } else { return this->it.second == rhs.it.second; } } bool operator!=(const FlattenedIterator<Iterator, ElementIterator> &rhs) const { return !(*this == rhs); } private: bool is_end() const { return this->it.first == this->end; } bool is_valid() const { if (this->is_end()) return false; if (this->it.second == this->it.first->end()) return false; return true; } void _increment() { if (this->it.second == this->it.first->end()) { ++this->it.first; if (this->it.first != this->end) { this->it.second = this->it.first->begin(); } } else { ++this->it.second; } } void find_valid() { while (!this->is_end() && !this->is_valid()) { this->_increment(); } } void increment() { this->_increment(); while (!this->is_end() && !this->is_valid()) { this->_increment(); } } pair<Iterator, ElementIterator> it; Iterator end; }; } // namespace internal template <class Iterator> struct Container { Container(const Iterator &begin, const Iterator &end) : m_begin(begin), m_end(end) {} const Iterator &begin() const { return this->m_begin; } const Iterator &end() const { return this->m_end; } Iterator m_begin; Iterator m_end; }; template <typename C, typename F> auto iterator_map(const C &c, F function) { using Iterator = std::remove_const_t<std::remove_reference_t<decltype(c.begin())>>; return Container<internal::MappedIterator<Iterator, F>>( internal::MappedIterator<Iterator, F>(c.begin(), function), internal::MappedIterator<Iterator, F>(c.end(), function)); } template <typename C, typename P> auto iterator_filter(const C &c, P predicate) { using Iterator = std::remove_const_t<std::remove_reference_t<decltype(c.begin())>>; return Container<internal::FilteredIterator<Iterator, P>>( internal::FilteredIterator<Iterator, P>(c.begin(), c.end(), predicate), internal::FilteredIterator<Iterator, P>(c.end(), c.end(), predicate)); } template <typename C> auto iterator_flatten(const C &c) { using Iterator = std::remove_const_t<std::remove_reference_t<decltype(c.begin())>>; using ElementIterator = std::remove_const_t< std::remove_reference_t<decltype(c.begin()->begin())>>; return Container<internal::FlattenedIterator<Iterator, ElementIterator>>( internal::FlattenedIterator<Iterator, ElementIterator>(c.begin(), c.end()), internal::FlattenedIterator<Iterator, ElementIterator>(c.end(), c.end())); } /* input */ template <class F, class S> std::istream &operator>>(std::istream &stream, pair<F, S> &pair) { stream >> pair.first; stream >> pair.second; return stream; } template <class... Args> std::istream &operator>>(std::istream &stream, tuple<Args...> &tuple) { internal::tuple_utils::read( stream, tuple, internal::tuple_utils::gen_seq<sizeof...(Args)>()); return stream; } template <class T> T read() { T t; cin >> t; return t; } template <class F, class S> pair<F, S> read() { pair<F, S> p; cin >> p; return p; } template <class T1, class T2, class T3, class... Args> tuple<T1, T2, T3, Args...> read() { tuple<T1, T2, T3, Args...> t; cin >> t; return t; } template <typename T, typename F = std::function<T()>> Vector<T> read(const usize length, F r) { auto retval = make_pre_allocated_vector<T>(length); REP(i, length) { retval.emplace_back(r()); } return retval; } template <class T> Vector<T> read(const usize length) { return read<T>(length, [] { return read<T>(); }); } template <class F, class S> Vector<pair<F, S>> read(const usize length) { return read<pair<F, S>>(length); } template <class T1, class T2, class T3, class... Args> Vector<tuple<T1, T2, T3, Args...>> read(const usize length) { return read<tuple<T1, T2, T3, Args...>>(length); } namespace internal { template <typename T> struct oneline { std::string operator()(const T &t) const { std::ostringstream oss; oss << t; return oss.str(); } }; template <typename F, typename S> struct oneline<pair<F, S>> { std::string operator()(const pair<F, S> &p) const { std::ostringstream oss; oss << "{" << oneline<F>()(p.first) << ", " << oneline<S>()(p.second) << "}"; return oss.str(); } }; template <typename... Args> struct oneline<tuple<Args...>> { struct oneline_tuple { template <class V> void operator()(Vector<std::string> &strs, const V &v) const { strs.emplace_back(oneline<V>()(v)); } }; std::string operator()(const tuple<Args...> &t) const { std::ostringstream oss; Vector<std::string> strs; internal::tuple_utils::for_each<oneline_tuple, Vector<std::string>, Args...>(strs, t); oss << "{"; REPR(i, strs.size()) { oss << strs[i]; if (i != 0) { oss << ", "; } } oss << "}"; return oss.str(); } }; template <> struct oneline<bool> { std::string operator()(const bool b) const { return b ? "true" : "false"; } }; template <typename X> struct oneline<Vector<X>> { std::string operator()(const Vector<X> &vec) const { std::string retval = "["; auto f = oneline<X>(); REP(i, vec.size()) { retval += f(vec[i]); if (i != static_cast<i64>(vec.size() - 1)) { retval += ", "; } } retval += "]"; return retval; } }; template <typename X> struct oneline<OrderedSet<X>> { std::string operator()(const OrderedSet<X> &s) const { std::string retval = "{"; auto f = oneline<X>(); size_t ctr = 0; EACH(x, s) { retval += f(x); ctr += 1; if (ctr != s.size()) { retval += ", "; } } retval += "}"; return retval; } }; template <typename X> struct oneline<HashSet<X>> { std::string operator()(const HashSet<X> &s) const { std::string retval = "{"; auto f = oneline<X>(); size_t ctr = 0; EACH(x, s) { retval += f(x); ctr += 1; if (ctr != s.size()) { retval += ", "; } } retval += "}"; return retval; } }; template <typename K, typename V> struct oneline<OrderedMap<K, V>> { std::string operator()(const OrderedMap<K, V> &s) const { std::string retval = "{"; auto f1 = oneline<K>(); auto f2 = oneline<V>(); size_t ctr = 0; EACH(x, s) { retval += f1(x.first); retval += ": "; retval += f2(x.second); ctr += 1; if (ctr != s.size()) { retval += ", "; } } retval += "}"; return retval; } }; template <typename K, typename V> struct oneline<HashMap<K, V>> { std::string operator()(const HashMap<K, V> &s) const { std::string retval = "{"; auto f1 = oneline<K>(); auto f2 = oneline<V>(); size_t ctr = 0; EACH(x, s) { retval += f1(x.first); retval += ": "; retval += f2(x.second); ctr += 1; if (ctr != s.size()) { retval += ", "; } } retval += "}"; return retval; } }; template <typename V> struct keys { /* no implementation */ }; template <typename X> struct keys<std::vector<X>> { Vector<size_t> operator()(const Vector<X> &v) const { Vector<size_t> keys; REP(i, v.size()) { keys.emplace_back(i); } return keys; } }; template <typename K, typename V> struct keys<OrderedMap<K, V>> { Vector<K> operator()(const OrderedMap<K, V> &c) const { Vector<K> keys; EACH(elem, c) { keys.emplace_back(elem.first); } return keys; } }; template <typename K, typename V> struct keys<HashMap<K, V>> { Vector<K> operator()(const HashMap<K, V> &c) const { Vector<K> keys; EACH(elem, c) { keys.emplace_back(elem.first); } return keys; } }; } // namespace internal template <typename T> void dump(const T &t) { using namespace internal; std::cerr << oneline<T>()(t) << std::endl; } template <typename V1, typename V2, typename... Args> void dump(const V1 &v1, const V2 &v2, const Args &...args) { using namespace internal; using F = typename oneline<tuple<V1, V2, Args...>>::oneline_tuple; auto x = std::make_tuple(v1, v2, args...); Vector<std::string> strs; internal::tuple_utils::for_each<F, Vector<std::string>, V1, V2, Args...>(strs, x); REPR(i, strs.size()) { std::cerr << strs[i]; if (i != 0) { std::cerr << ", "; } } std::cerr << std::endl; } template <typename C> std::string as_set(const C &ctr) { Vector<std::string> values; using namespace internal; EACH(x, ctr) { values.emplace_back(oneline<decltype(x)>()(x)); } std::string retval = "---\n"; REP(i, values.size()) { retval += values[i]; retval += "\n"; } retval += "---"; return retval; } template <typename C> std::string as_map(const C &ctr) { using namespace internal; auto ks = keys<C>()(ctr); Vector<std::string> keys; Vector<std::string> values; EACH(key, ks) { keys.emplace_back(oneline<decltype(key)>()(key)); values.emplace_back(oneline<decltype(ctr.at(key))>()(ctr.at(key))); } size_t l = 0; EACH(key, keys) { l = std::max(l, key.size()); } std::string retval = "---\n"; REP(i, values.size()) { retval += keys[i]; REP(j, l - keys[i].size()) { retval += " "; } retval += ": "; retval += values[i]; retval += "\n"; } retval += "---"; return retval; } template <typename C> std::string as_table(const C &ctr) { using namespace internal; auto rkeys = keys<C>()(ctr); auto ckeys = OrderedSet<std::string>(); auto values = Vector<pair<std::string, OrderedMap<std::string, std::string>>>(); /* Stringify all data */ EACH(rkey, rkeys) { auto rkey_str = oneline<decltype(rkey)>()(rkey); values.emplace_back(rkey_str, OrderedMap<std::string, std::string>()); auto row = ctr.at(rkey); auto ks = keys<decltype(row)>()(row); EACH(ckey, ks) { auto ckey_str = oneline<decltype(ckey)>()(ckey); ckeys.emplace(ckey_str); values.back().second.emplace( ckey_str, oneline<decltype(row.at(ckey))>()(row.at(ckey))); } } /* Calculate string length */ size_t max_row_key_length = 0; EACH(value, values) { max_row_key_length = std::max(max_row_key_length, value.first.size()); } OrderedMap<std::string, size_t> max_col_length; EACH(ckey, ckeys) { max_col_length.emplace(ckey, ckey.size()); } EACH(value, values) { EACH(elem, value.second) { auto ckey = elem.first; auto value = elem.second; max_col_length[ckey] = std::max(max_col_length[ckey], value.size()); } } std::string retval = "---\n"; /* Header */ REP(i, max_row_key_length) { retval += " "; } retval += " "; size_t cnt = 0; EACH(ckey, ckeys) { retval += ckey; REP(j, max_col_length[ckey] - ckey.size()) { retval += " "; } cnt += 1; if (cnt != ckeys.size()) { retval += ", "; } } retval += "\n------\n"; /* Values */ EACH(value, values) { retval += value.first; REP(i, max_row_key_length - value.first.size()) { retval += " "; } retval += "| "; size_t cnt = 0; EACH(ckey, ckeys) { auto v = std::string(""); if (value.second.find(ckey) != value.second.end()) { v = value.second.at(ckey); } retval += v; REP(j, max_col_length[ckey] - v.size()) { retval += " "; } cnt += 1; if (cnt != ckeys.size()) { retval += ", "; } } retval += "\n"; } retval += "---"; return retval; } // Hash namespace std { template <class F, class S> struct hash<pair<F, S>> { size_t operator()(const pair<F, S> &p) const { return hash<F>()(p.first) ^ hash<S>()(p.second); } }; template <class... Args> struct hash<tuple<Args...>> { struct hash_for_element { template <class V> void operator()(size_t &size, const V &v) const { size ^= std::hash<V>()(v); } }; size_t operator()(const tuple<Args...> &t) const { size_t retval = 0; internal::tuple_utils::for_each<hash_for_element, size_t, Args...>(retval, t); return retval; } }; } // namespace std #define MAIN void body(); // main function (DO NOT EDIT) int main(int argc, char **argv) { cin.tie(0); std::ios_base::sync_with_stdio(false); cout << std::fixed; body(); return 0; } void body() { auto s = read<string>(); auto t = read<string>(); OrderedMap<char, Vector<i64>> I; REP(i, s.size()) { I[s[i]].push_back(i + 1); } i64 ans = 0; size_t i_s = 0, i_t = 0; while (i_t < t.size()) { auto ch = t[i_t]; auto it_j = std::upper_bound(I[ch].begin(), I[ch].end(), i_s); if (it_j == I[ch].end() && i_s == 0) { cout << -1 << endl; return; } if (it_j == I[ch].end()) { ans += (s.size() - i_s); i_s = 0; continue; } auto j = *it_j; ans += (j - i_s); i_s = j; i_t += 1; } cout << ans << endl; }
[ "identifier.change" ]
739,975
739,976
u071730284
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vout(x) rep(i, x.size()) cout << x[i] << " " template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } using namespace std; using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int, int>; const int inf = 1e9; const ll inf_l = 1e18; const int MAX = 1e5; int main() { string s, t; cin >> s >> t; int n_s = s.size(); int n_t = t.size(); queue<char> q; rep(i, n_t) q.push(t[i]); vvint data(26); rep(i, 2 * n_s) { data[s[i % n_s] - 'a'].push_back(i); } rep(i, n_t) { if (data[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll ans = 0; int now = 0; while (!q.empty()) { now = *lower_bound(all(data[q.front() - 'a']), now + 1); if (now >= n_s) { ans += n_s; now %= n_s; } q.pop(); } cout << ans + now + 1 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vout(x) rep(i, x.size()) cout << x[i] << " " template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } using namespace std; using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int, int>; const int inf = 1e9; const ll inf_l = 1e18; const int MAX = 1e5; int main() { string s, t; cin >> s >> t; int n_s = s.size(); int n_t = t.size(); queue<char> q; rep(i, n_t) q.push(t[i]); vvint data(26); rep(i, 2 * n_s) { data[s[i % n_s] - 'a'].push_back(i); } rep(i, n_t) { if (data[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll ans = 0; int now = -1; while (!q.empty()) { now = *lower_bound(all(data[q.front() - 'a']), now + 1); if (now >= n_s) { ans += n_s; now %= n_s; } q.pop(); } cout << ans + now + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,990
739,989
u697968316
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vout(x) rep(i, x.size()) cout << x[i] << " " template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } using namespace std; using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int, int>; const int inf = 1e9; const ll inf_l = 1e18; const int MAX = 1e5; int main() { string s, t; cin >> s >> t; int n_s = s.size(); int n_t = t.size(); queue<char> q; rep(i, n_t) q.push(t[i]); vvint data(26); rep(i, 2 * n_s) { data[s[i % n_s] - 'a'].push_back(i); } rep(i, n_t) { if (data[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll ans = 0; int now = 0; while (!q.empty()) { now = *lower_bound(all(data[q.front() - 'a']), now + 1); if (now >= n_s) { ans += n_s; now %= n_s; } q.pop(); } cout << ans + now + 1 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vout(x) rep(i, x.size()) cout << x[i] << " " template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } using namespace std; using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int, int>; const int inf = 1e9; const ll inf_l = 1e18; const int MAX = 1e5; int main() { string s, t; cin >> s >> t; int n_s = s.size(); int n_t = t.size(); queue<char> q; rep(i, n_t) q.push(t[i]); vvint data(26); rep(i, 2 * n_s) { data[s[i % n_s] - 'a'].push_back(i); } rep(i, n_t) { if (data[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll ans = 0; int now = 0; while (!q.empty()) { now = *lower_bound(all(data[q.front() - 'a']), now) + 1; if (now >= n_s) { ans += n_s; now %= n_s; } q.pop(); } cout << ans + now << endl; }
[ "call.arguments.change", "expression.operation.binary.remove" ]
739,990
739,991
u697968316
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vout(x) rep(i, x.size()) cout << x[i] << " " template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } using namespace std; using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int, int>; const int inf = 1e9; const ll inf_l = 1e18; const int MAX = 1e5; int main() { string s, t; cin >> s >> t; int n_s = s.size(); int n_t = t.size(); queue<char> q; rep(i, n_t) q.push(t[i]); vvint data(26); rep(i, 2 * n_s) { data[s[i % n_s] - 'a'].push_back(i); } rep(i, n_t) { if (data[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll ans = 0; int now = 0; while (!q.empty()) { now = *lower_bound(all(data[q.front() - 'a']), now) + 1; if (now > n_s) { ans += n_s; now %= n_s; } q.pop(); } cout << ans + now << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vout(x) rep(i, x.size()) cout << x[i] << " " template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } using namespace std; using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int, int>; const int inf = 1e9; const ll inf_l = 1e18; const int MAX = 1e5; int main() { string s, t; cin >> s >> t; int n_s = s.size(); int n_t = t.size(); queue<char> q; rep(i, n_t) q.push(t[i]); vvint data(26); rep(i, 2 * n_s) { data[s[i % n_s] - 'a'].push_back(i); } rep(i, n_t) { if (data[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll ans = 0; int now = 0; while (!q.empty()) { now = *lower_bound(all(data[q.front() - 'a']), now) + 1; if (now >= n_s) { ans += n_s; now %= n_s; } q.pop(); } cout << ans + now << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,992
739,991
u697968316
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string t; cin >> t; int N = s.size(); int M = t.size(); vector<set<int>> pos(26); for (int i = 0; i < N; i++) { pos[s[i] - 'a'].insert(i); } bool ok = true; for (int i = 0; i < M; i++) { if (pos[t[i] - 'a'].empty()) { ok = false; } } if (!ok) { cout << -1 << endl; } else { int ans = 0; for (int i = 0; i < M; i++) { auto itr = pos[t[i] - 'a'].upper_bound(ans % N); if (itr != pos[t[i] - 'a'].end()) { ans += *itr - ans % N; } else { ans += N - ans % N; auto itr2 = pos[t[i] - 'a'].begin(); ans += *itr2; } } cout << ans + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string t; cin >> t; int N = s.size(); int M = t.size(); vector<set<int>> pos(26); for (int i = 0; i < N; i++) { pos[s[i] - 'a'].insert(i); } bool ok = true; for (int i = 0; i < M; i++) { if (pos[t[i] - 'a'].empty()) { ok = false; } } if (!ok) { cout << -1 << endl; } else { long long ans = -1; for (int i = 0; i < M; i++) { auto itr = pos[t[i] - 'a'].upper_bound(ans % N); if (itr != pos[t[i] - 'a'].end()) { ans += *itr - ans % N; } else { ans += N - ans % N; auto itr2 = pos[t[i] - 'a'].begin(); ans += *itr2; } } cout << ans + 1 << endl; } }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "literal.number.change", "variable_declaration.value.change" ]
740,000
740,001
u424374375
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<long long, long long> #define ii pair<ll, ll> #define mod 1000000007 #define endl '\n' #define IOS \ std::ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); ll power(ll a, ll b) { ll ans = 1; while (b > 0) { if (b % 2 != 0) { ans = (ans * a) % mod; } a = ((a % mod) * (a % mod)) % mod; b >>= 1; } return ans; } void sieve(ll n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (ll p = 2; p * p <= n; p++) { if (prime[p]) { for (ll i = p * p; i <= n; i += p) prime[i] = false; } } for (ll p = 2; p <= n; p++) { if (prime[p]) cout << p << " "; } } int main() { IOS; ll t = 1; // cin>>t; while (t--) { string s, t; cin >> s >> t; vector<ll> v[26]; for (ll i = 0; i < s.size(); i++) { v[s[i] - 'a'].push_back(i); } ll cnt = 0; ll j = 0; for (ll i = 0; i < t.size(); i++) { if (v[t[i] - 'a'].size() == 0) { cout << -1; return 0; } ll kha = t[i] - 'a'; ll ind = upper_bound(v[kha].begin(), v[kha].end(), j) - v[kha].begin(); if (ind == v[kha].size()) { j = v[kha][0]; cnt++; } else { j = v[kha][ind]; } } cout << cnt * s.size() + j + 1; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<long long, long long> #define ii pair<ll, ll> #define mod 1000000007 #define endl '\n' #define IOS \ std::ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); ll power(ll a, ll b) { ll ans = 1; while (b > 0) { if (b % 2 != 0) { ans = (ans * a) % mod; } a = ((a % mod) * (a % mod)) % mod; b >>= 1; } return ans; } void sieve(ll n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (ll p = 2; p * p <= n; p++) { if (prime[p]) { for (ll i = p * p; i <= n; i += p) prime[i] = false; } } for (ll p = 2; p <= n; p++) { if (prime[p]) cout << p << " "; } } int main() { IOS; ll t = 1; // cin>>t; while (t--) { string s, t; cin >> s >> t; vector<ll> v[26]; for (ll i = 0; i < s.size(); i++) { v[s[i] - 'a'].push_back(i); } ll cnt = 0; ll j = -1; for (ll i = 0; i < t.size(); i++) { if (v[t[i] - 'a'].size() == 0) { cout << -1; return 0; } ll kha = t[i] - 'a'; ll ind = upper_bound(v[kha].begin(), v[kha].end(), j) - v[kha].begin(); if (ind == v[kha].size()) { j = v[kha][0]; cnt++; } else { j = v[kha][ind]; } } cout << cnt * s.size() + j + 1; } return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,002
740,003
u224168474
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define pli pair<ll, int> #define pil pair<int, ll> #define pll pair<ll, ll> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() #define endl '\n' const int inf = 1000000007; const ll INF = 1e18; int mod = 998244353; // int mod = 1000000007; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } 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; } template <typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; } ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; } template <typename T> inline istream &operator>>(istream &is, vector<T> &v) { rep(j, sz(v)) is >> v[j]; return is; } template <class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; } template <class T> void operator+=(vector<T> &v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(11); int T; T = 1; while (T--) solve(); } void solve() { string s, t; cin >> s >> t; { set<char> st; for (char si : s) st.emplace(si); for (char ti : t) if (st.count(ti) == 0) { cout << -1 << endl; return; } } s += s; vector<vector<int>> x(26); rep(i, sz(s)) x[s[i] - 'a'].eb(i); int it = 0; int r = 0; for (char ti : t) { it = lb(x[ti - 'a'], it); it = x[ti - 'a'][it]; if (it >= sz(s) / 2) { it -= sz(s) / 2; r++; } } cout << r * 1LL * sz(s) / 2 + it + 1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define pli pair<ll, int> #define pil pair<int, ll> #define pll pair<ll, ll> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() #define endl '\n' const int inf = 1000000007; const ll INF = 1e18; int mod = 998244353; // int mod = 1000000007; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } 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; } template <typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; } ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; } template <typename T> inline istream &operator>>(istream &is, vector<T> &v) { rep(j, sz(v)) is >> v[j]; return is; } template <class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; } template <class T> void operator+=(vector<T> &v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(11); int T; T = 1; while (T--) solve(); } void solve() { string s, t; cin >> s >> t; { set<char> st; for (char si : s) st.emplace(si); for (char ti : t) if (st.count(ti) == 0) { cout << -1 << endl; return; } } s += s; vector<vector<int>> x(26); rep(i, sz(s)) x[s[i] - 'a'].eb(i); int it = -1; int r = 0; for (char ti : t) { it = ub(x[ti - 'a'], it); // debuged it = x[ti - 'a'][it]; if (it >= sz(s) / 2) { it -= sz(s) / 2; r++; } } cout << r * 1LL * sz(s) / 2 + it + 1 << endl; } /* abc aaaa x 1 */
[ "literal.number.change", "variable_declaration.value.change", "assignment.value.change", "identifier.change", "call.function.change" ]
740,004
740,005
u277556971
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define min(a, b) (a > b ? b : a) #define chmax(a, b) a = (a >= b ? a : b) #define chmin(a, b) a = (a <= b ? a : b) #define out(a) cout << a << endl #define outa(a, n) \ { \ rep(_, n) cout << a[_] << " "; \ cout << endl; \ } #define outp(a, n) \ { \ cout << endl; \ rep(_, n) cout << a[_].F << " " << a[_].S << endl; \ } #define SZ(v) (int)v.size() #define inf (int)(1e9 + 7) #define abs(x) (x >= 0 ? x : -(x)) #define ceil(a, b) a / b + !!(a % b) #define FIX(a) fixed << setprecision(a) #define LB(v, n) (int)(lower_bound(all(v), n) - v.begin()) #define UB(v, n) (int)(upper_bound(all(v), n) - v.begin()) ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; { map<char, int> mp; rep(i, SZ(s)) mp[s[i]]++; rep(i, SZ(t)) if (mp[t[i]] == 0) { out(-1); return 0; } } vector<int> v[26]; rep(i, SZ(s)) { v[s[i] - 'a'].eb(i); } if (SZ(t) == 1) { out(v[t[0] - 'a'][0] + 1); return 0; } int now = v[t[0] - 'a'][0]; // out(now); ll cnt = 0; rep3(i, 1, SZ(t) - 1) { int it = UB(v[t[i] - 'a'], now); if (it == SZ(v[t[i] - 'a'])) { now = v[t[i] - 'a'][0]; cnt++; } else { now = v[t[i] - 'a'][it]; } // out(now); } // out(cnt); // out(now); { // 最後の文字 int it = UB(v[t[SZ(t) - 1] - 'a'], now); if (it == SZ(v[t[SZ(t) - 1] - 'a'])) { cnt++; out(cnt * SZ(s) + v[t[SZ(t) - 1] - 'a'][0] + 1); } else { now = v[t[SZ(t) - 1] - 'a'][it]; out(now); out(cnt * SZ(s) + v[t[SZ(t) - 1] - 'a'][it] + 1); } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define min(a, b) (a > b ? b : a) #define chmax(a, b) a = (a >= b ? a : b) #define chmin(a, b) a = (a <= b ? a : b) #define out(a) cout << a << endl #define outa(a, n) \ { \ rep(_, n) cout << a[_] << " "; \ cout << endl; \ } #define outp(a, n) \ { \ cout << endl; \ rep(_, n) cout << a[_].F << " " << a[_].S << endl; \ } #define SZ(v) (int)v.size() #define inf (int)(1e9 + 7) #define abs(x) (x >= 0 ? x : -(x)) #define ceil(a, b) a / b + !!(a % b) #define FIX(a) fixed << setprecision(a) #define LB(v, n) (int)(lower_bound(all(v), n) - v.begin()) #define UB(v, n) (int)(upper_bound(all(v), n) - v.begin()) ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; { map<char, int> mp; rep(i, SZ(s)) mp[s[i]]++; rep(i, SZ(t)) if (mp[t[i]] == 0) { out(-1); return 0; } } vector<int> v[26]; rep(i, SZ(s)) { v[s[i] - 'a'].eb(i); } if (SZ(t) == 1) { out(v[t[0] - 'a'][0] + 1); return 0; } int now = v[t[0] - 'a'][0]; // out(now); ll cnt = 0; rep3(i, 1, SZ(t) - 1) { int it = UB(v[t[i] - 'a'], now); if (it == SZ(v[t[i] - 'a'])) { now = v[t[i] - 'a'][0]; cnt++; } else { now = v[t[i] - 'a'][it]; } // out(now); } // out(cnt); // out(now); { // 最後の文字 int it = UB(v[t[SZ(t) - 1] - 'a'], now); if (it == SZ(v[t[SZ(t) - 1] - 'a'])) { cnt++; out(cnt * SZ(s) + v[t[SZ(t) - 1] - 'a'][0] + 1); } else { now = v[t[SZ(t) - 1] - 'a'][it]; // out(now); out(cnt * SZ(s) + v[t[SZ(t) - 1] - 'a'][it] + 1); } } }
[ "call.remove" ]
740,008
740,009
u277556971
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<int, int> P; ll Mod = 1000000007; int main() { string s, t; cin >> s >> t; vector<ll> A[26]; for (int i = 0; i < s.size(); i++) { A[s[i] - 'a'].push_back(i + 1); } ll ans = 0; for (int i = 0; i < t.size(); i++) { char c = t[i]; ll spot = ans % s.size(); if (A[c - 'a'].size() == 0) { cout << -1 << endl; return 0; } auto itr = lower_bound(A[c - 'a'].begin(), A[c - 'a'].end(), spot); if (itr == A[c - 'a'].end()) { ans += s.size() + A[c - 'a'][0] - spot; } else { ans += *itr - spot; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<int, int> P; ll Mod = 1000000007; int main() { string s, t; cin >> s >> t; vector<ll> A[26]; for (int i = 0; i < s.size(); i++) { A[s[i] - 'a'].push_back(i + 1); } ll ans = 0; for (int i = 0; i < t.size(); i++) { char c = t[i]; ll spot = ans % s.size(); if (A[c - 'a'].size() == 0) { cout << -1 << endl; return 0; } auto itr = upper_bound(A[c - 'a'].begin(), A[c - 'a'].end(), spot); if (itr == A[c - 'a'].end()) { ans += s.size() + A[c - 'a'][0] - spot; } else { ans += *itr - spot; } } cout << ans << endl; return 0; }
[ "identifier.change", "call.function.change" ]
740,010
740,011
u083494782
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<int, int> P; ll Mod = 1000000007; int main() { string s, t; cin >> s >> t; vector<int> A[26]; for (int i = 0; i < s.size(); i++) { A[s[i] - 'a'].push_back(i + 1); } ll ans = 0; for (int i = 0; i < t.size(); i++) { char c = t[i]; ll spot = ans % s.size(); if (A[c - 'a'].size() == 0) { cout << -1 << endl; return 0; } auto itr = lower_bound(A[c - 'a'].begin(), A[c - 'a'].end(), spot); if (itr == A[c - 'a'].end()) { ans += s.size() + A[c - 'a'][0] - spot; } else { ans += *itr - spot; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<int, int> P; ll Mod = 1000000007; int main() { string s, t; cin >> s >> t; vector<ll> A[26]; for (int i = 0; i < s.size(); i++) { A[s[i] - 'a'].push_back(i + 1); } ll ans = 0; for (int i = 0; i < t.size(); i++) { char c = t[i]; ll spot = ans % s.size(); if (A[c - 'a'].size() == 0) { cout << -1 << endl; return 0; } auto itr = upper_bound(A[c - 'a'].begin(), A[c - 'a'].end(), spot); if (itr == A[c - 'a'].end()) { ans += s.size() + A[c - 'a'][0] - spot; } else { ans += *itr - spot; } } cout << ans << endl; return 0; }
[ "identifier.change", "call.function.change" ]
740,012
740,011
u083494782
cpp
p02937
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef uint64_t ull; typedef pair<int, int> P; constexpr double EPS = 1e-9; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s, t; cin >> s >> t; int n = s.length(); int m = t.length(); string str = s + s; vector<vector<int>> pos(26); for (int i = 0; i < n * 2; ++i) { pos[str[i] - 'a'].emplace_back(i); } ll cnt = 0; int cur = 0; for (int i = 0; i < m; ++i) { int c = t[i] - 'a'; if (pos[c].size() == 0) { cout << -1 << endl; return 0; } int p = lower_bound(pos[c].begin(), pos[c].end(), cur) - pos[c].begin(); int now = pos[c][p]; if (now >= n) { ++cnt; now -= n; } cur = now; } ll ans = cnt * n + cur + 1; cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef uint64_t ull; typedef pair<int, int> P; constexpr double EPS = 1e-9; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s, t; cin >> s >> t; int n = s.length(); int m = t.length(); string str = s + s; vector<vector<int>> pos(26); for (int i = 0; i < n * 2; ++i) { pos[str[i] - 'a'].emplace_back(i); } ll cnt = 0; int cur = -1; for (int i = 0; i < m; ++i) { int c = t[i] - 'a'; if (pos[c].size() == 0) { cout << -1 << endl; return 0; } int p = upper_bound(pos[c].begin(), pos[c].end(), cur) - pos[c].begin(); int now = pos[c][p]; if (now >= n) { ++cnt; now -= n; } cur = now; } ll ans = cnt * n + cur + 1; cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change", "expression.operation.binary.change" ]
740,013
740,014
u190018920
cpp
p02937
// Author: Fuadul Hasan(fuadul202@gmail.com) // BSMRSTU,Gopalganj #include <bits/stdc++.h> using namespace std; int tc = 1; #define happy ios::sync_with_stdio(false); #define coding cin.tie(0); #define F first #define S second #define mp make_pair #define ll long long #define Pi atan(1) * 4 #define pb push_back #define vpr vector<pr> #define pr pair<int, int> #define vi std::vector<int> #define vll std::vector<ll> #define YES printf("YES\n"); #define NO printf("NO\n"); #define Yes printf("Yes\n"); #define No printf("No\n"); #define all(n) n.begin(), n.end() #define point(x) setprecision(x) #define Test printf("Case %d: ", tc++); #define Unique(c) (c).resize(unique(all(c)) - (c).begin()) #define vout(v) \ for (auto z : v) \ cout << z << " "; \ cout << endl; #define error(args...) \ { \ vector<string> _v = split(#args, ','); \ err(_v.begin(), args); \ cout << endl; \ } vector<string> split(const string &s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.emplace_back(x); return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) { cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...); } const int M = 1e9 + 7; const ll Inf = (ll)2e18 + 5; const int N = 2e5 + 5; ll vis[N], res[N]; int solve() { // happy coding string s; string t; cin >> s >> t; vector<int> m[26]; for (int i = 0; s[i]; i++) { m[s[i] - 'a'].pb(i); } for (int i = 0; t[i]; i++) { if (m[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } int n = s.size(); int idx = 0; int sum = 0; for (int i = 0; t[i]; i++) { auto x = lower_bound(all(m[t[i] - 'a']), idx + 1); if (x != m[t[i] - 'a'].end()) { idx = *x; } else { sum++; idx = m[t[i] - 'a'][0]; } } cout << sum * s.length() + idx + 1 << endl; return 0; } int main() { int test = 1; // scanf("%d", &test); while (test--) solve(); return 0; }
// Author: Fuadul Hasan(fuadul202@gmail.com) // BSMRSTU,Gopalganj #include <bits/stdc++.h> using namespace std; int tc = 1; #define happy ios::sync_with_stdio(false); #define coding cin.tie(0); #define F first #define S second #define mp make_pair #define ll long long #define Pi atan(1) * 4 #define pb push_back #define vpr vector<pr> #define pr pair<int, int> #define vi std::vector<int> #define vll std::vector<ll> #define YES printf("YES\n"); #define NO printf("NO\n"); #define Yes printf("Yes\n"); #define No printf("No\n"); #define all(n) n.begin(), n.end() #define point(x) setprecision(x) #define Test printf("Case %d: ", tc++); #define Unique(c) (c).resize(unique(all(c)) - (c).begin()) #define vout(v) \ for (auto z : v) \ cout << z << " "; \ cout << endl; #define error(args...) \ { \ vector<string> _v = split(#args, ','); \ err(_v.begin(), args); \ cout << endl; \ } vector<string> split(const string &s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.emplace_back(x); return move(v); } void err(vector<string>::iterator it) {} template <typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) { cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...); } const int M = 1e9 + 7; const ll Inf = (ll)2e18 + 5; const int N = 2e5 + 5; ll vis[N], res[N]; int solve() { // happy coding string s; string t; cin >> s >> t; vector<int> m[27]; for (int i = 0; s[i]; i++) { m[s[i] - 'a'].pb(i); } for (int i = 0; t[i]; i++) { if (m[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } int n = s.size(); int idx = -2; int sum = 0; for (int i = 0; t[i]; i++) { auto x = lower_bound(all(m[t[i] - 'a']), idx + 1); if (x != m[t[i] - 'a'].end()) { idx = *x; } else { sum++; idx = m[t[i] - 'a'][0]; } } cout << sum * s.length() + idx + 1 << endl; return 0; } int main() { int test = 1; // scanf("%d", &test); while (test--) solve(); return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "variable_declaration.value.change" ]
740,023
740,024
u526278960
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { string s, t; cin >> s >> t; map<char, vector<int>> mp; rep(i, s.size()) { mp[s[i]].push_back(i + 1); } long long ans = 0; int p = 0; rep(i, t.size()) { if (!mp[t[i]].size()) { ans = -1; break; } auto it = lower_bound(mp[t[i]].begin(), mp[t[i]].end(), p); if (it == mp[t[i]].end()) { ans += s.size() - p + mp[t[i]][0]; p = mp[t[i]][0]; } else { ans += *it - p; p = *it; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { string s, t; cin >> s >> t; map<char, vector<int>> mp; rep(i, s.size()) { mp[s[i]].push_back(i + 1); } long long ans = 0; int p = 0; rep(i, t.size()) { if (!mp[t[i]].size()) { ans = -1; break; } auto it = upper_bound(mp[t[i]].begin(), mp[t[i]].end(), p); if (it == mp[t[i]].end()) { ans += s.size() - p + mp[t[i]][0]; p = mp[t[i]][0]; } else { ans += *it - p; p = *it; } } cout << ans << endl; return 0; }
[ "identifier.change", "call.function.change" ]
740,031
740,032
u929618357
cpp
p02937
// In the name of GOD #include <bits/stdc++.h> #define ll long long #define pp pair<int, int> using namespace std; const int N = 2e5 + 10, MOD = 1e9 + 7; const ll INF = 1e18; void solve() { string s; string t; cin >> s >> t; map<char, vector<int>> mp; int i = 0; for (char c : s) { mp[c].push_back(i); ++i; } int id = 0; ll freq = 0; for (int i = 0; i < t.length(); ++i) { char c = t[i]; if (mp[c].empty()) { cout << -1; return; } if (lower_bound(mp[c].begin(), mp[c].end(), id) == mp[c].end()) { freq++; id = mp[c][0]; } else id = mp[c][lower_bound(mp[c].begin(), mp[c].end(), id) - mp[c].begin()]; // cout << freq << " " << id << "\n"; } ll ans = 1LL * (int)s.length() * freq + id + 1; cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tt = 1; // cin >> tt; for (int tc = 1; tc <= tt; ++tc) { solve(); } }
// In the name of GOD #include <bits/stdc++.h> #define ll long long #define pp pair<int, int> using namespace std; const int N = 2e5 + 10, MOD = 1e9 + 7; const ll INF = 1e18; void solve() { string s; string t; cin >> s >> t; map<char, vector<int>> mp; int i = 0; for (char c : s) { mp[c].push_back(i); ++i; } int id = -1; ll freq = 0; for (int i = 0; i < t.length(); ++i) { char c = t[i]; if (mp[c].empty()) { cout << -1; return; } if (upper_bound(mp[c].begin(), mp[c].end(), id) == mp[c].end()) { freq++; id = mp[c][0]; } else id = mp[c][upper_bound(mp[c].begin(), mp[c].end(), id) - mp[c].begin()]; // cout << freq << " " << id << "\n"; } ll ans = 1LL * (int)s.length() * freq + id + 1; cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tt = 1; // cin >> tt; for (int tc = 1; tc <= tt; ++tc) { solve(); } }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change", "control_flow.branch.if.condition.change", "assignment.value.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
740,040
740,041
u927520692
cpp
p02937
#include <algorithm> #include <cmath> #include <iostream> #include <set> #include <vector> //#include "cxx-prettyprint/prettyprint.hpp" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repR(i, n) for (int i = (n)-1; i > -1; i--) #define rep1(i, n) for (int i = 1; i < (int)(n + 1); i++) #define rep1R(i, n) for (int i = (n); i > 0; i--) typedef long long ll; typedef unsigned long long ull; using namespace std; int main() { string s, t; cin >> s >> t; vector<set<int>> pos(26); rep(i, s.size()) { pos.at(s[i] - 'a').insert(i); } rep(i, t.size()) { if (pos.at(t[i] - 'a').lower_bound(0) == pos.at(t[i] - 'a').end()) { cout << "-1" << endl; return 0; } } ll cur = -1; ll ans = 0; rep(i, t.size()) { auto it = pos.at(t[i] - 'a').lower_bound(cur + 1); if (it == pos.at(t[i] - 'a').end()) { cur = *pos.at(t[i] - 'a').lower_bound(0); ans += (ll)s.size(); } else { cur = *it; } if (i == t.size() - 1) { ans += *it + 1; } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <set> #include <vector> //#include "cxx-prettyprint/prettyprint.hpp" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repR(i, n) for (int i = (n)-1; i > -1; i--) #define rep1(i, n) for (int i = 1; i < (int)(n + 1); i++) #define rep1R(i, n) for (int i = (n); i > 0; i--) typedef long long ll; typedef unsigned long long ull; using namespace std; int main() { string s, t; cin >> s >> t; vector<set<int>> pos(26); rep(i, s.size()) { pos.at(s[i] - 'a').insert(i); } rep(i, t.size()) { if (pos.at(t[i] - 'a').lower_bound(0) == pos.at(t[i] - 'a').end()) { cout << "-1" << endl; return 0; } } ll cur = -1; ll ans = 0; rep(i, t.size()) { auto it = pos.at(t[i] - 'a').lower_bound(cur + 1); if (it == pos.at(t[i] - 'a').end()) { cur = *pos.at(t[i] - 'a').lower_bound(0); ans += s.size(); } else { cur = *it; } if (i == t.size() - 1) { ans += cur + 1; } } cout << ans << endl; return 0; }
[ "assignment.value.change", "expression.operation.binary.change" ]
740,042
740,043
u529632089
cpp
p02937
#include <iostream> #include <map> #include <set> using namespace std; int main() { string s, t; cin >> s; cin >> t; map<char, set<int>> sm, tm; for (int i = 0; i < s.length(); i++) { sm[s[i]].insert(i); } for (int i = 0; i < t.length(); i++) { tm[t[i]].insert(i); } for (auto q : tm) { if (sm[q.first].empty()) { cout << -1 << endl; return 0; } } int prev = 0; long cnt = 1; for (int i = 0; i < t.length(); i++) { auto pos = sm[t[i]].lower_bound(prev + 1); if (pos == sm[t[i]].end()) { prev = *(sm[t[i]].begin()); cnt++; } else { prev = *pos; } } long ans = s.length() * (cnt - 1) + prev + 1; cout << ans << endl; return 0; }
#include <iostream> #include <map> #include <set> using namespace std; int main() { string s, t; cin >> s; cin >> t; map<char, set<int>> sm, tm; for (int i = 0; i < s.length(); i++) { sm[s[i]].insert(i); } for (int i = 0; i < t.length(); i++) { tm[t[i]].insert(i); } for (auto q : tm) { if (sm[q.first].empty()) { cout << -1 << endl; return 0; } } int prev = -1; long cnt = 1; for (int i = 0; i < t.length(); i++) { auto pos = sm[t[i]].lower_bound(prev + 1); if (pos == sm[t[i]].end()) { prev = *(sm[t[i]].begin()); cnt++; } else { prev = *pos; } } long ans = s.length() * (cnt - 1) + prev + 1; cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,096
740,097
u506846578
cpp
p02937
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> #define user spaesk #define pi acos(-1) #define lli long long int #define ld long double #define ff first #define ss second #define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower); using namespace std; typedef vector<vector<lli>> matrix; const int N = 3e5 + 500; const long long mod = 1e9 + 7; const long long cmod = 998244353; const long long inf = 1LL << 61; const int M = 1e6 + 500; const lli ths = 1LL << 40; const int NN = 5e3 + 6; void solve() { string s, t; cin >> s >> t; vector<lli> f[26]; for (int i = 0; i < s.size(); i++) { f[s[i] - 'a'].push_back(i); } lli prev = 0; lli ans = 0; for (int i = 0; i < t.size();) { lli x = t[i] - 'a'; lli idx = lower_bound(f[x].begin(), f[x].end(), prev + 1) - f[x].begin(); if (idx < f[x].size() and f[x][idx] > prev) { prev = f[x][idx]; i++; if (i == t.size()) { ans += prev + 1; break; } } else { if (prev == -1) { cout << -1; return; } prev = -1; ans += s.size(); } // cout<<prev<<endl; } cout << ans; cout << "\n"; return; } /* */ int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> #define user spaesk #define pi acos(-1) #define lli long long int #define ld long double #define ff first #define ss second #define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower); using namespace std; typedef vector<vector<lli>> matrix; const int N = 3e5 + 500; const long long mod = 1e9 + 7; const long long cmod = 998244353; const long long inf = 1LL << 61; const int M = 1e6 + 500; const lli ths = 1LL << 40; const int NN = 5e3 + 6; void solve() { string s, t; cin >> s >> t; vector<lli> f[26]; for (int i = 0; i < s.size(); i++) { f[s[i] - 'a'].push_back(i); } lli prev = -1; lli ans = 0; for (int i = 0; i < t.size();) { lli x = t[i] - 'a'; lli idx = lower_bound(f[x].begin(), f[x].end(), prev + 1) - f[x].begin(); if (idx < f[x].size() and f[x][idx] > prev) { prev = f[x][idx]; i++; if (i == t.size()) { ans += prev + 1; break; } } else { if (prev == -1) { cout << -1; return; } prev = -1; ans += s.size(); } // cout<<prev<<endl; } cout << ans; cout << "\n"; return; } /* */ int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,098
740,099
u684423349
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vll = vector<long long>; using vp = vector<pair<int, int>>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; using vvll = vector<vector<long long>>; 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 (b < a) { a = b; return 1; } return 0; } int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; ll n = sz(s); vvi cnt(26); rep(i, n) { cnt[s[i] - 'a'].pb(i); } ll now = 0; ll m = sz(t); rep(i, m) { int idx = t[i] - 'a'; if (sz(cnt[idx]) == 0) { cout << -1 << endl; return 0; } int x = upper_bound(cnt[idx].begin(), cnt[idx].end(), now % n) - cnt[idx].begin(); if (x == sz(cnt[idx])) { now = (now + n - 1) / n * n + cnt[idx][0]; } else { now = now / n * n + cnt[idx][x]; } } cout << now + 1 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vll = vector<long long>; using vp = vector<pair<int, int>>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; using vvll = vector<vector<long long>>; 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 (b < a) { a = b; return 1; } return 0; } int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; ll n = sz(s); vvi cnt(26); rep(i, n) { cnt[s[i] - 'a'].pb(i); } ll now = -1; ll m = sz(t); rep(i, m) { int idx = t[i] - 'a'; if (sz(cnt[idx]) == 0) { cout << -1 << endl; return 0; } int x = upper_bound(cnt[idx].begin(), cnt[idx].end(), now % n) - cnt[idx].begin(); if (x == sz(cnt[idx])) { now = (now + n) / n * n + cnt[idx][0]; } else { now = now / n * n + cnt[idx][x]; } } cout << now + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operation.binary.remove" ]
740,102
740,103
u009414205
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define ll long long #define LLMAX (1ll << 60) - 1 #define INTMAX (1 << 30) - 1 #define MOD 1000000007 #define NMAX 1000 * 100 + 1 #define numberOfSetBits(S) \ __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S) #define MSET(x, y) memset(x, y, sizeof(x)) #define gcd(a, b) __gcd(a, b) #define all(x) x.begin(), x.end() #define isOn(S, j) (S & (1 << j)) #define endl '\n' #define setBit(S, j) (S |= (1 << j)) #define clearBit(S, j) (S &= ~(1 << j)) #define toggleBit(S, j) (S ^= (1 << j)) #define print(x) \ for (auto it : x) \ cout << it << ' '; \ cout << endl; #define printii(x) \ for (auto it : x) \ cout << it.F << ' ' << it.S << '\t'; \ cout << endl; #define in(x, n) \ for (int e = 0; e < n; e++) { \ ll y; \ cin >> y; \ x.pb(y); \ } #define vi vector<ll> #define vvi vector<vi> #define ii pair<ll, ll> #define pll pair<ll, ll> #define vii vector<ii> #define vvii vector<vii> #define viii vector<pair<ii, ll>> #define pb push_back #define F first #define S second #define mp make_pair #define mc(a, b, c) mp(mp(a, b), c) set<ll> cnt[26]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, x, m, y, z; string s, t; cin >> s >> t; n = s.size(); for (int i = 0; i < n; i++) { cnt[s[i] - 'a'].insert(i + 1); } n = t.size(); for (int j = 0; j < n; j++) { if (!cnt[t[j] - 'a'].size()) { cout << -1; return 0; } } ll curr = 1, foo = 0; for (int i = 0; i < n; i++) { auto it = cnt[t[i] - 'a'].upper_bound(curr); if (it == cnt[t[i] - 'a'].end()) { foo++; curr = *cnt[t[i] - 'a'].begin(); } else { curr = *it; } } n = s.size(); cout << foo * n + curr; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define LLMAX (1ll << 60) - 1 #define INTMAX (1 << 30) - 1 #define MOD 1000000007 #define NMAX 1000 * 100 + 1 #define numberOfSetBits(S) \ __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S) #define MSET(x, y) memset(x, y, sizeof(x)) #define gcd(a, b) __gcd(a, b) #define all(x) x.begin(), x.end() #define isOn(S, j) (S & (1 << j)) #define endl '\n' #define setBit(S, j) (S |= (1 << j)) #define clearBit(S, j) (S &= ~(1 << j)) #define toggleBit(S, j) (S ^= (1 << j)) #define print(x) \ for (auto it : x) \ cout << it << ' '; \ cout << endl; #define printii(x) \ for (auto it : x) \ cout << it.F << ' ' << it.S << '\t'; \ cout << endl; #define in(x, n) \ for (int e = 0; e < n; e++) { \ ll y; \ cin >> y; \ x.pb(y); \ } #define vi vector<ll> #define vvi vector<vi> #define ii pair<ll, ll> #define pll pair<ll, ll> #define vii vector<ii> #define vvii vector<vii> #define viii vector<pair<ii, ll>> #define pb push_back #define F first #define S second #define mp make_pair #define mc(a, b, c) mp(mp(a, b), c) set<ll> cnt[26]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, x, m, y, z; string s, t; cin >> s >> t; n = s.size(); for (int i = 0; i < n; i++) { cnt[s[i] - 'a'].insert(i + 1); } n = t.size(); for (int j = 0; j < n; j++) { if (!cnt[t[j] - 'a'].size()) { cout << -1; return 0; } } ll curr = 0, foo = 0; for (int i = 0; i < n; i++) { auto it = cnt[t[i] - 'a'].upper_bound(curr); if (it == cnt[t[i] - 'a'].end()) { foo++; curr = *cnt[t[i] - 'a'].begin(); } else { curr = *it; } } n = s.size(); cout << foo * n + curr; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,104
740,105
u313568050
cpp
p02937
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; int main() { string s, t; cin >> s >> t; vector<vector<int>> arf(26, vector<int>(0)); for (int i = 0; i < (int)s.size(); ++i) { int x = s[i] - 'a'; arf[x].push_back(i + 1); } for (int i = 0; i < 26; ++i) { arf[i].push_back(INF); } long long ans = 0; int num = 0; for (int i = 0; i < (int)t.size(); ++i) { int x = t[i] - 'a'; if (arf[x].size() == 1) { cout << -1 << endl; return 0; } auto itr = upper_bound(arf[x].begin(), arf[x].end(), num); int newnum; if (*itr == INF) newnum = arf[x][0]; else newnum = *itr; if (newnum < num) { ans += s.size() - num + newnum; } else { ans += newnum - num; } num = newnum; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; int main() { string s, t; cin >> s >> t; vector<vector<int>> arf(26, vector<int>(0)); for (int i = 0; i < (int)s.size(); ++i) { int x = s[i] - 'a'; arf[x].push_back(i + 1); } for (int i = 0; i < 26; ++i) { arf[i].push_back(INF); } long long ans = 0; int num = 0; for (int i = 0; i < (int)t.size(); ++i) { int x = t[i] - 'a'; if (arf[x].size() == 1) { cout << -1 << endl; return 0; } auto itr = upper_bound(arf[x].begin(), arf[x].end(), num); int newnum; if (*itr == INF) newnum = arf[x][0]; else newnum = *itr; if (newnum <= num) { ans += s.size() - num + newnum; } else { ans += newnum - num; } num = newnum; } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,106
740,107
u031240034
cpp
p02937
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; int main() { string s, t; cin >> s >> t; vector<vector<int>> arf(26, vector<int>(0)); for (int i = 0; i < (int)s.size(); ++i) { int x = s[i] - 'a'; arf[x].push_back(i + 1); } for (int i = 0; i < 26; ++i) { arf[i].push_back(INF); } long long ans = 0; int num = 0; for (int i = 0; i < (int)t.size(); ++i) { int x = t[i] - 'a'; if (arf[x].size() == 1) { cout << -1 << endl; return 0; } auto itr = lower_bound(arf[x].begin(), arf[x].end(), num); int newnum; if (*itr == INF) newnum = arf[x][0]; else newnum = *itr; if (newnum < num) { ans += s.size() - num + newnum; } else { ans += newnum - num; } num = newnum; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; int main() { string s, t; cin >> s >> t; vector<vector<int>> arf(26, vector<int>(0)); for (int i = 0; i < (int)s.size(); ++i) { int x = s[i] - 'a'; arf[x].push_back(i + 1); } for (int i = 0; i < 26; ++i) { arf[i].push_back(INF); } long long ans = 0; int num = 0; for (int i = 0; i < (int)t.size(); ++i) { int x = t[i] - 'a'; if (arf[x].size() == 1) { cout << -1 << endl; return 0; } auto itr = upper_bound(arf[x].begin(), arf[x].end(), num); int newnum; if (*itr == INF) newnum = arf[x][0]; else newnum = *itr; if (newnum <= num) { ans += s.size() - num + newnum; } else { ans += newnum - num; } num = newnum; } cout << ans << endl; }
[ "identifier.change", "call.function.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,108
740,107
u031240034
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using LL = long long; int main() { string s, t; cin >> s >> t; s += s; LL ans = 0, prev = -1; vector<vector<LL>> chara(26); rep(i, s.size()) { int c = s[i] - 'a'; chara[c].emplace_back(i); } rep(i, t.size()) { int c = t[i] - 'a'; auto itr = lower_bound(chara[c].begin(), chara[c].end(), prev); if (itr == chara[c].end()) { cout << -1 << endl; return 0; } LL num = *itr; ans += num - prev; if (num >= s.size() / 2) prev = num - s.size() / 2; else prev = num; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using LL = long long; int main() { string s, t; cin >> s >> t; s += s; LL ans = 0, prev = -1; vector<vector<LL>> chara(26); rep(i, s.size()) { int c = s[i] - 'a'; chara[c].emplace_back(i); } rep(i, t.size()) { int c = t[i] - 'a'; auto itr = upper_bound(chara[c].begin(), chara[c].end(), prev); if (itr == chara[c].end()) { cout << -1 << endl; return 0; } LL num = *itr; ans += num - prev; if (num >= s.size() / 2) prev = num - s.size() / 2; else prev = num; } cout << ans << endl; return 0; }
[ "identifier.change", "call.function.change" ]
740,112
740,113
u226233437
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long LL; int main() { string s, t; cin >> s >> t; map<char, vector<int>> m; rep(i, s.size()) { char c = s[i]; m[c].emplace_back(i); } LL num = 0, pos = 0, ans = 0; LL n = s.size(); rep(i, t.size()) { char c = t[i]; if (!m[c].size()) { cout << -1 << endl; return 0; } auto itr = upper_bound(m[c].begin(), m[c].end(), num); if (itr - m[c].begin() == m[c].size()) { pos++; num = m[c][0]; ans = m[c][0] + n * pos; } else { num = *itr; ans = num + n * pos; } } cout << ans + 1 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long LL; int main() { string s, t; cin >> s >> t; map<char, vector<int>> m; rep(i, s.size()) { char c = s[i]; m[c].emplace_back(i); } LL num = -1, pos = 0, ans = 0; LL n = s.size(); rep(i, t.size()) { char c = t[i]; if (!m[c].size()) { cout << -1 << endl; return 0; } auto itr = upper_bound(m[c].begin(), m[c].end(), num); if (itr - m[c].begin() == m[c].size()) { pos++; num = m[c][0]; ans = m[c][0] + n * pos; } else { num = *itr; ans = num + n * pos; } } cout << ans + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,114
740,115
u226233437
cpp
p02937
#include <cstdio> #include <iostream> #include <vector> using namespace std; typedef long long ll; string s, t; vector<ll> c[30]; ll x, times; int main() { ll i, j, k; cin >> s >> t; for (i = 0; s[i]; i++) c[s[i] - 'a'].push_back(i); for (i = 0, j = -1; t[i]; i++) { x = t[i] - 'a'; if (c[x].size() == 0) return puts("-1"), 0; k = lower_bound(c[x].begin(), c[x].end(), j) - c[x].begin(); if (k == c[x].size()) { times++; j = c[x][0]; } else { j = c[x][k]; } } cout << times * (ll)s.size() + j + 1; return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; typedef long long ll; string s, t; vector<ll> c[30]; ll x, times; int main() { ll i, j, k; cin >> s >> t; for (i = 0; s[i]; i++) c[s[i] - 'a'].push_back(i); for (i = 0, j = -1; t[i]; i++) { x = t[i] - 'a'; if (c[x].size() == 0) return puts("-1"), 0; k = upper_bound(c[x].begin(), c[x].end(), j) - c[x].begin(); if (k == c[x].size()) { times++; j = c[x][0]; } else { j = c[x][k]; } } cout << times * (ll)s.size() + j + 1; return 0; }
[ "import.add", "assignment.value.change", "identifier.change", "call.function.change", "expression.operation.binary.change" ]
740,118
740,119
u093170535
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define eee(a) (cerr << (#a) << ": " << (a) << endl); #define ppp(a) (cout << (a) << endl); #define cop(a) \ for (auto x : (a)) { \ cout << x << endl; \ } using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; using mint = map<int, int>; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; constexpr char sp = ' '; constexpr char cmm = ','; constexpr int MOD = 1e9 + 7; constexpr int INF = 1e9; constexpr ll LINF = 1e18; ll mod(ll a, ll b) { return (a % b + b) % b; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void Judge(bool b) { b ? Yes() : No(); } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void JUDGE(bool b) { b ? YES() : NO(); } ll powmod(ll b, ll e) { ll r = 1; while (e > 0) { if (e & 1) r = (r % MOD) * (b % MOD) % MOD; b = (b % MOD) * (b % MOD) % MOD; e >>= 1; } return r; } double distance(ll x1, ll y1, ll x2, ll y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { int len = v.size(); s << '['; for (int i = 0; i < len; ++i) { s << v[i]; if (i < len - 1) s << ", "; } s << ']'; return s; } struct aaa { aaa() { // comment this out when you use scanf or printf cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15); }; } fastio; int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); string ss = s + s; vector<set<int>> pos(26); for (int i = 0; i < 2 * n; ++i) pos[ss[i] - 'a'].insert(i); ll idx = -1; ll loop = 0; for (int i = 0; i < m; ++i) { if (pos[t[i] - 'a'].empty()) { ppp(-1); return 0; } auto itr = pos[t[i] - 'a'].upper_bound(idx); if (itr == pos[t[i] - 'a'].end()) { ppp(-1); return 0; } idx = *itr; loop += idx / n; } ppp(loop * n + idx + 1); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define eee(a) (cerr << (#a) << ": " << (a) << endl); #define ppp(a) (cout << (a) << endl); #define cop(a) \ for (auto x : (a)) { \ cout << x << endl; \ } using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; using mint = map<int, int>; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; constexpr char sp = ' '; constexpr char cmm = ','; constexpr int MOD = 1e9 + 7; constexpr int INF = 1e9; constexpr ll LINF = 1e18; ll mod(ll a, ll b) { return (a % b + b) % b; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void Judge(bool b) { b ? Yes() : No(); } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void JUDGE(bool b) { b ? YES() : NO(); } ll powmod(ll b, ll e) { ll r = 1; while (e > 0) { if (e & 1) r = (r % MOD) * (b % MOD) % MOD; b = (b % MOD) * (b % MOD) % MOD; e >>= 1; } return r; } double distance(ll x1, ll y1, ll x2, ll y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { int len = v.size(); s << '['; for (int i = 0; i < len; ++i) { s << v[i]; if (i < len - 1) s << ", "; } s << ']'; return s; } struct aaa { aaa() { // comment this out when you use scanf or printf cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15); }; } fastio; int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); string ss = s + s; vector<set<int>> pos(26); for (int i = 0; i < 2 * n; ++i) pos[ss[i] - 'a'].insert(i); ll idx = -1; ll loop = 0; for (int i = 0; i < m; ++i) { if (pos[t[i] - 'a'].empty()) { ppp(-1); return 0; } auto itr = pos[t[i] - 'a'].upper_bound(idx); if (itr == pos[t[i] - 'a'].end()) { ppp(-1); return 0; } idx = *itr; loop += idx / n; idx %= n; } ppp(loop * n + idx + 1); return 0; }
[ "assignment.add" ]
740,146
740,147
u306142032
cpp
p02937
#if __has_include("../library/Basic/Debug.hpp") #include "../library/Basic/Debug.hpp" #else /* ----- Header Files ----- */ // IO #include <cstdio> #include <iomanip> #include <ios> #include <iostream> // algorithm #include <algorithm> #include <cmath> #include <numeric> // container #include <bitset> #include <complex> #include <deque> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> // others #include <cassert> #include <cstdint> #include <ctime> #include <functional> #include <limits> #include <random> /* ----- Type Alias ----- */ using Bool = bool; using Int = long long int; using Real = long double; using Char = char; using String = std::string; template <class T, class U> using Pair = std::pair<T, U>; template <class... Ts> using Tuple = std::tuple<Ts...>; template <class T> using Vector = std::vector<T>; template <size_t N> using Bits = std::bitset<N>; template <class T> using Queue = std::queue<T>; template <class T> using Stack = std::stack<T>; template <class T> using Deque = std::deque<T>; template <class T> using MaxHeap = std::priority_queue<T>; template <class T> using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <class T> using Set = std::set<T>; template <class T, class U> using Map = std::map<T, U>; template <class T, class... Us> using Func = std::function<T(Us...)>; template <class T> T genv(T v) { return v; } template <class T, class... Ts> auto genv(size_t l, Ts... ts) { return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...)); } template <class Cost = Int> struct Edge { Int src, dst; Cost cost; Edge(Int src = -1, Int dst = -1, Cost cost = 1) : src(src), dst(dst), cost(cost){}; bool operator<(const Edge<Cost> &e) const { return this->cost < e.cost; } bool operator>(const Edge<Cost> &e) const { return this->cost > e.cost; } }; template <class Cost = Int> using Edges = Vector<Edge<Cost>>; template <class Cost = Int> using Graph = Vector<Vector<Edge<Cost>>>; #endif /* ----- Misc ----- */ void fastio() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } struct Fout { Int precision; Fout(Int precision) : precision(precision) {} }; std::ostream &operator<<(std::ostream &os, const Fout &fio) { os << std::fixed << std::setprecision(fio.precision); return os; } /* ----- Constants ----- */ // constexpr Int INF = std::numeric_limits<Int>::max() / 3; // constexpr Int MOD = 1000000007; // constexpr Real PI = acos(-1); // constexpr Real EPS = 1e-10; // std::mt19937 mt(int(std::time(nullptr))); int main() { String s, t; std::cin >> s >> t; Int n = s.length(); Vector<Set<Int>> pos(26); for (Int i = 0; i < n; ++i) { pos[s[i] - 'a'].insert(i); } Int ans = 0; for (Char c : t) { Int d = c - 'a'; if (pos[d].empty()) { std::cout << -1 << std::endl; return 0; } while (true) { auto itr = pos[d].lower_bound(ans % s.length()); if (itr != pos[d].end()) { ans = ans / n * n + *itr; break; } else { ans = (ans / n + 1) * n; } } } std::cout << ans + 1 << std::endl; return 0; }
#if __has_include("../library/Basic/Debug.hpp") #include "../library/Basic/Debug.hpp" #else /* ----- Header Files ----- */ // IO #include <cstdio> #include <iomanip> #include <ios> #include <iostream> // algorithm #include <algorithm> #include <cmath> #include <numeric> // container #include <bitset> #include <complex> #include <deque> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> // others #include <cassert> #include <cstdint> #include <ctime> #include <functional> #include <limits> #include <random> /* ----- Type Alias ----- */ using Bool = bool; using Int = long long int; using Real = long double; using Char = char; using String = std::string; template <class T, class U> using Pair = std::pair<T, U>; template <class... Ts> using Tuple = std::tuple<Ts...>; template <class T> using Vector = std::vector<T>; template <size_t N> using Bits = std::bitset<N>; template <class T> using Queue = std::queue<T>; template <class T> using Stack = std::stack<T>; template <class T> using Deque = std::deque<T>; template <class T> using MaxHeap = std::priority_queue<T>; template <class T> using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <class T> using Set = std::set<T>; template <class T, class U> using Map = std::map<T, U>; template <class T, class... Us> using Func = std::function<T(Us...)>; template <class T> T genv(T v) { return v; } template <class T, class... Ts> auto genv(size_t l, Ts... ts) { return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...)); } template <class Cost = Int> struct Edge { Int src, dst; Cost cost; Edge(Int src = -1, Int dst = -1, Cost cost = 1) : src(src), dst(dst), cost(cost){}; bool operator<(const Edge<Cost> &e) const { return this->cost < e.cost; } bool operator>(const Edge<Cost> &e) const { return this->cost > e.cost; } }; template <class Cost = Int> using Edges = Vector<Edge<Cost>>; template <class Cost = Int> using Graph = Vector<Vector<Edge<Cost>>>; #endif /* ----- Misc ----- */ void fastio() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } struct Fout { Int precision; Fout(Int precision) : precision(precision) {} }; std::ostream &operator<<(std::ostream &os, const Fout &fio) { os << std::fixed << std::setprecision(fio.precision); return os; } /* ----- Constants ----- */ // constexpr Int INF = std::numeric_limits<Int>::max() / 3; // constexpr Int MOD = 1000000007; // constexpr Real PI = acos(-1); // constexpr Real EPS = 1e-10; // std::mt19937 mt(int(std::time(nullptr))); int main() { String s, t; std::cin >> s >> t; Int n = s.length(); Vector<Set<Int>> pos(26); for (Int i = 0; i < n; ++i) { pos[s[i] - 'a'].insert(i); } Int ans = 0; for (Char c : t) { Int d = c - 'a'; if (pos[d].empty()) { std::cout << -1 << std::endl; return 0; } while (true) { auto itr = pos[d].lower_bound(ans % s.length()); if (itr != pos[d].end()) { ans = ans / n * n + *itr + 1; break; } else { ans = (ans / n + 1) * n; } } } std::cout << ans << std::endl; return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
740,150
740,151
u059727354
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define p_ary(ary, a, b, i) \ do { \ cout << "["; \ for (int(i) = (a); (i) < (b); ++(i)) \ cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \ cout << "]\n"; \ } while (0) #define p_map(map, it) \ do { \ cout << "{"; \ for (auto(it) = map.begin();; ++(it)) { \ if ((it) == map.end()) { \ cout << "}\n"; \ break; \ } else \ cout << "" << (it)->first << "=>" << (it)->second << ", "; \ } \ } while (0) int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vector<int> x[26]; for (int i = 0; i < n; ++i) x[s[i] - 'a'].push_back(i); int ans = 0, p = 0; for (int i = 0; i < m; ++i) { int c = t[i] - 'a'; if (x[c].empty()) { cout << "-1" << endl; return 0; } auto it = upper_bound(x[c].begin(), x[c].end(), p); if (it == x[c].end()) { ans++; p = x[c][0]; } else { p = *it; } } cout << (ll)ans * n + p + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define p_ary(ary, a, b, i) \ do { \ cout << "["; \ for (int(i) = (a); (i) < (b); ++(i)) \ cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \ cout << "]\n"; \ } while (0) #define p_map(map, it) \ do { \ cout << "{"; \ for (auto(it) = map.begin();; ++(it)) { \ if ((it) == map.end()) { \ cout << "}\n"; \ break; \ } else \ cout << "" << (it)->first << "=>" << (it)->second << ", "; \ } \ } while (0) int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vector<int> x[26]; for (int i = 0; i < n; ++i) x[s[i] - 'a'].push_back(i); int ans = 0, p = -1; for (int i = 0; i < m; ++i) { int c = t[i] - 'a'; if (x[c].empty()) { cout << "-1" << endl; return 0; } auto it = upper_bound(x[c].begin(), x[c].end(), p); if (it == x[c].end()) { ans++; p = x[c][0]; } else { p = *it; } } cout << (ll)ans * n + p + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,154
740,155
u506255180
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define p_ary(ary, a, b, i) \ do { \ cout << "["; \ for (int(i) = (a); (i) < (b); ++(i)) \ cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \ cout << "]\n"; \ } while (0) #define p_map(map, it) \ do { \ cout << "{"; \ for (auto(it) = map.begin();; ++(it)) { \ if ((it) == map.end()) { \ cout << "}\n"; \ break; \ } else \ cout << "" << (it)->first << "=>" << (it)->second << ", "; \ } \ } while (0) int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vector<int> x[26]; for (int i = 0; i < n; ++i) x[s[i] - 'a'].push_back(i); int ans = 0, p = 0; for (int i = 0; i < m; ++i) { int c = t[i] - 'a'; if (x[c].empty()) { cout << "-1" << endl; return 0; } auto it = lower_bound(x[c].begin(), x[c].end(), p); if (it == x[c].end()) { ans++; p = x[c][0]; } else { p = *it; } } cout << (ll)ans * n + p + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define p_ary(ary, a, b, i) \ do { \ cout << "["; \ for (int(i) = (a); (i) < (b); ++(i)) \ cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \ cout << "]\n"; \ } while (0) #define p_map(map, it) \ do { \ cout << "{"; \ for (auto(it) = map.begin();; ++(it)) { \ if ((it) == map.end()) { \ cout << "}\n"; \ break; \ } else \ cout << "" << (it)->first << "=>" << (it)->second << ", "; \ } \ } while (0) int main() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); vector<int> x[26]; for (int i = 0; i < n; ++i) x[s[i] - 'a'].push_back(i); int ans = 0, p = -1; for (int i = 0; i < m; ++i) { int c = t[i] - 'a'; if (x[c].empty()) { cout << "-1" << endl; return 0; } auto it = upper_bound(x[c].begin(), x[c].end(), p); if (it == x[c].end()) { ans++; p = x[c][0]; } else { p = *it; } } cout << (ll)ans * n + p + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change" ]
740,156
740,155
u506255180
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define REPR(i, n) for (int i = n; i >= 0; --i) #define FOR(i, m, n) for (int i = m, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int INF = 1e9; const ll LLINF = 1e16; int main(void) { string s, t; cin >> s; cin >> t; vector<int> sc(26, 0); vector<int> tc(26, 0); vector<vector<int>> sp(26); REP(i, s.size()) { sc[s[i] - 'a']++; sp[s[i] - 'a'].push_back(i); sp[s[i] - 'a'].push_back(i + s.size()); } REP(i, sp.size()) sort(all(sp[i])); REP(i, t.size()) { tc[t[i] - 'a']++; } REP(i, tc.size()) { if (tc[i] > 0 && sc[i] == 0) { cout << -1 << endl; return 0; } } ll ans = 0; int pre = -1; REP(i, t.size()) { char crt = t[i]; int crt_i = crt - 'a'; auto itr = lower_bound(all(sp[crt_i]), pre); int mp = *itr; ans += mp - pre; pre = (mp >= s.size()) ? mp - s.size() : mp; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define REPR(i, n) for (int i = n; i >= 0; --i) #define FOR(i, m, n) for (int i = m, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } const int INF = 1e9; const ll LLINF = 1e16; int main(void) { string s, t; cin >> s; cin >> t; vector<int> sc(26, 0); vector<int> tc(26, 0); vector<vector<int>> sp(26); REP(i, s.size()) { sc[s[i] - 'a']++; sp[s[i] - 'a'].push_back(i); sp[s[i] - 'a'].push_back(i + s.size()); } REP(i, sp.size()) sort(all(sp[i])); REP(i, t.size()) { tc[t[i] - 'a']++; } REP(i, tc.size()) { if (tc[i] > 0 && sc[i] == 0) { cout << -1 << endl; return 0; } } ll ans = 0; int pre = -1; REP(i, t.size()) { char crt = t[i]; int crt_i = crt - 'a'; auto itr = upper_bound(all(sp[crt_i]), pre); int mp = *itr; ans += mp - pre; pre = (mp >= s.size()) ? mp - s.size() : mp; } cout << ans << endl; return 0; }
[ "identifier.change", "call.function.change" ]
740,159
740,160
u272997285
cpp
p02937
#include <bits/stdc++.h> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define pii std::pair<int, int> #define pli std::pair<ll, int> #define pil std::pair<int, ll> #define psi std::pair<string, int> #define pll std::pair<ll, ll> #define pci std::pair<char, int> #define sll(x) scanf("%lld", &x) #define prll(x) printf("%lld ", x) #define pri(x) printf("%d ", x) #define si(x) scanf("%d", &x) #define pb push_back #define vll std::vector<ll> #define vpi std::vector<std::pair<int, int>> #define vi std::vector<int> #define vvi std::vector<std::vector<int>> #define vvpil std::vector<std::vector<std::pair<int, ll>>> #define vlpii std::vector<std::list<pii>> #define vlpil std::vector<std::list<pil>> #define li std::list<int> #define lpil std::list<pil> #define Endl printf("\n") #define vli vector<list<int>> #define vvll vector<vector<ll>> #define mp make_pair #define x first #define y second #define ull uint64_t #define ma 100000000 #define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " const ll INF = 10000000000000; const ll mod = 1e9 + 7; const int MAX = 300005; using namespace std; void add(ll &a, ll b) { a += b; if (a >= mod) a -= mod; } ll mul(ll a, ll b) { return (a * b) % mod; } ll Pow(ll a, ll b) { if (b == 0) return 1; ll c = Pow(a, b / 2); if (b % 2) return (a * ((c * c) % mod)) % mod; return (c * c) % mod; } // check modulo int main() { IOS; cout.precision(50); string s, t; cin >> s >> t; vector<vi> v(26); for (int i = 0; i < (int)s.size(); i++) v[(int)s[i] - (int)'a'].pb(i); ll nb = 0, last = 0; int n = (int)t.size(); for (int i = 0; i < n; i++) { int x = (int)t[i] - (int)'a'; if (v[x].size() == 0) return cout << -1 << "\n", 0; vi::iterator up = upper_bound(v[x].begin(), v[x].end(), last); if (up == v[x].end()) { nb++; up = upper_bound(v[x].begin(), v[x].end(), -1); last = *up; } else last = *up; } cout << nb * (int)s.size() + last + 1 << endl; return 0; }
#include <bits/stdc++.h> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define pii std::pair<int, int> #define pli std::pair<ll, int> #define pil std::pair<int, ll> #define psi std::pair<string, int> #define pll std::pair<ll, ll> #define pci std::pair<char, int> #define sll(x) scanf("%lld", &x) #define prll(x) printf("%lld ", x) #define pri(x) printf("%d ", x) #define si(x) scanf("%d", &x) #define pb push_back #define vll std::vector<ll> #define vpi std::vector<std::pair<int, int>> #define vi std::vector<int> #define vvi std::vector<std::vector<int>> #define vvpil std::vector<std::vector<std::pair<int, ll>>> #define vlpii std::vector<std::list<pii>> #define vlpil std::vector<std::list<pil>> #define li std::list<int> #define lpil std::list<pil> #define Endl printf("\n") #define vli vector<list<int>> #define vvll vector<vector<ll>> #define mp make_pair #define x first #define y second #define ull uint64_t #define ma 100000000 #define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " const ll INF = 10000000000000; const ll mod = 1e9 + 7; const int MAX = 300005; using namespace std; void add(ll &a, ll b) { a += b; if (a >= mod) a -= mod; } ll mul(ll a, ll b) { return (a * b) % mod; } ll Pow(ll a, ll b) { if (b == 0) return 1; ll c = Pow(a, b / 2); if (b % 2) return (a * ((c * c) % mod)) % mod; return (c * c) % mod; } // check modulo int main() { IOS; cout.precision(50); string s, t; cin >> s >> t; vector<vi> v(26); for (int i = 0; i < (int)s.size(); i++) { v[(int)s[i] - (int)'a'].pb(i); } ll nb = 0, last = -1; int n = (int)t.size(); for (int i = 0; i < n; i++) { int x = (int)t[i] - (int)'a'; if (v[x].size() == 0) return cout << -1 << "\n", 0; vi::iterator up = upper_bound(v[x].begin(), v[x].end(), last); if (up == v[x].end()) { nb++; up = upper_bound(v[x].begin(), v[x].end(), -1); last = *up; } else last = *up; } cout << nb * (ll)s.size() + last + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "io.output.change" ]
740,167
740,166
u752814744
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s; cin >> t; int spos = 0; long long result; vector<int> sna; for (auto &e : t) { int sn = s.substr(spos).find(e); if (sn == string::npos) { if (s.find(e) == string::npos) { result = -1; break; } spos = 0; sn = s.substr(spos).find(e); } sna.push_back(sn + spos); spos = spos + sn + 1; if (spos == s.size()) spos = 0; } if (result == -1) { cout << result << endl; return 0; } int stimes; for (int i = 0; i < sna.size() - 1; i++) { if (sna[i] >= sna[i + 1]) stimes += 1; } result = s.size() * stimes + sna[sna.size() - 1] + 1; cout << result << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s; cin >> t; int spos = 0; long long result = 0; vector<int> sna; for (auto &e : t) { int sn = s.substr(spos).find(e); if (sn == string::npos) { if (s.find(e) == string::npos) { result = -1; break; } spos = 0; sn = s.substr(spos).find(e); } sna.push_back(sn + spos); spos = spos + sn + 1; if (spos == s.size()) spos = 0; } if (result == -1) { cout << result << endl; return 0; } int stimes = 0; for (int i = 0; i < sna.size() - 1; i++) { if (sna[i] >= sna[i + 1]) stimes += 1; } result = s.size() * stimes + sna[sna.size() - 1] + 1; cout << result << endl; return 0; }
[ "variable_declaration.value.change" ]
740,177
740,178
u280802329
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s; cin >> t; int spos = 0; long result; vector<int> sna; for (auto &e : t) { int sn = s.substr(spos).find(e); if (sn == string::npos) { if (s.find(e) == string::npos) { result = -1; break; } spos = 0; sn = s.substr(spos).find(e); } sna.push_back(sn + spos); spos = spos + sn + 1; if (spos == s.size()) spos = 0; } if (result == -1) { cout << result << endl; return 0; } int stimes; for (int i = 0; i < sna.size() - 1; i++) { if (sna[i] >= sna[i + 1]) stimes += 1; } result = s.size() * stimes + sna[sna.size() - 1] + 1; cout << result << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s; cin >> t; int spos = 0; long long result = 0; vector<int> sna; for (auto &e : t) { int sn = s.substr(spos).find(e); if (sn == string::npos) { if (s.find(e) == string::npos) { result = -1; break; } spos = 0; sn = s.substr(spos).find(e); } sna.push_back(sn + spos); spos = spos + sn + 1; if (spos == s.size()) spos = 0; } if (result == -1) { cout << result << endl; return 0; } int stimes = 0; for (int i = 0; i < sna.size() - 1; i++) { if (sna[i] >= sna[i + 1]) stimes += 1; } result = s.size() * stimes + sna[sna.size() - 1] + 1; cout << result << endl; return 0; }
[ "variable_declaration.type.widen.change", "variable_declaration.value.change" ]
740,179
740,178
u280802329
cpp
p02937
#include <algorithm> #include <iostream> #include <map> #include <vector> void chmax(long &target, long const &value) { if (target < value) { target = value; } } int main() { using namespace std; cin.tie(nullptr); ios::sync_with_stdio(false); string s, t; cin >> s >> t; vector<vector<long>> chars_index(26); for (size_t i = 0; i < s.size(); ++i) { chars_index[s[i] - 'a'].push_back(i); } size_t result = 0, last = 0; for (size_t i = 0; i < t.size(); ++i) { char t_i = t[i]; auto &chars = chars_index[t_i - 'a']; if (chars.empty()) { // t の文字が s に含まれていないので cout << "-1\n"; return 0; } auto next = upper_bound(chars.begin(), chars.end(), last); if (next == chars.end()) { // 今のループにはもうないので result += s.size(); // 次のループへ next = chars.begin(); } last = *next; } result += last + 1; // 1 始まりにしておく cout << result << "\n"; }
#include <algorithm> #include <iostream> #include <map> #include <vector> void chmax(long &target, long const &value) { if (target < value) { target = value; } } int main() { using namespace std; cin.tie(nullptr); ios::sync_with_stdio(false); string s, t; cin >> s >> t; vector<vector<long>> chars_index(26); for (size_t i = 0; i < s.size(); ++i) { chars_index[s[i] - 'a'].push_back(i + 1); // 1 始まりにしておく } size_t result = 0, last = 0; for (size_t i = 0; i < t.size(); ++i) { char t_i = t[i]; auto &chars = chars_index[t_i - 'a']; if (chars.empty()) { // t の文字が s に含まれていないので cout << "-1\n"; return 0; } auto next = upper_bound(chars.begin(), chars.end(), last); if (next == chars.end()) { // 今のループにはもうないので result += s.size(); // 次のループへ next = chars.begin(); } last = *next; } result += last; cout << result << "\n"; }
[ "expression.operation.binary.remove" ]
740,183
740,184
u596082532
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define ALL(a) (a).begin(), (a).end() using namespace std; string s, t; vector<int> abc[26]; int main() { cin >> s >> t; rep(i, s.size()) { abc[s[i] - 'a'].push_back(i); } rep(i, s.size()) { abc[s[i] - 'a'].push_back(i + s.size()); } int cnt = 0; int where = -1; int over; rep(i, t.size()) { if ((abc[t[i] - 'a']).size() == 0) { cout << -1 << endl; return 0; } auto nex = upper_bound(ALL(abc[t[i] - 'a']), where); where = *nex % s.size(); over = *nex / s.size(); cnt += over; } cout << (int64_t)s.size() * (cnt - over) + where + 1 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define ALL(a) (a).begin(), (a).end() using namespace std; string s, t; vector<int> abc[26]; int main() { cin >> s >> t; rep(i, s.size()) { abc[s[i] - 'a'].push_back(i); } rep(i, s.size()) { abc[s[i] - 'a'].push_back(i + s.size()); } int cnt = 0; int where = -1; int over; rep(i, t.size()) { if ((abc[t[i] - 'a']).size() == 0) { cout << -1 << endl; return 0; } auto nex = upper_bound(ALL(abc[t[i] - 'a']), where); where = *nex % s.size(); over = *nex / s.size(); cnt += over; } cout << (int64_t)s.size() * cnt + where + 1 << endl; return 0; }
[]
740,192
740,193
u499824662
cpp
p02937
#include <bits/stdc++.h> using namespace std; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vll = vector<long long>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define pb push_back #define mp make_pair #define MOD 1000000007 int main() { string s, t, u; cin >> s >> t; u = s + s; ll x = s.size(), y = t.size(); vll hu[26]; rep(i, 2 * x) { int j = s[i] - 'a'; hu[j].pb(i); } vector<vll> next(x, vll(26, -1)); // next[i][j]はsのi番目(0-origin)以降(i含む)でjが初めて出てくる場所 rep(i, x) { rep(j, 26) { if (hu[j].empty()) continue; ll c = *lower_bound(all(hu[j]), i); next[i][j] = c % x; } } ll ans = 0; vll So(100005, -1); // greedyにtのi番目に対応してsの文字の出現場所を列挙 bool f = true; rep(i, y) { int j = t[i] - 'a'; So[i + 1] = next[(So[i] + 1) % x][j]; if (So[i + 1] == -1) { f = false; break; } ll tmp = (So[i + 1] > So[i] ? So[i + 1] - So[i] : So[i + 1] - So[i] + x); ans = ans + tmp; } cout << (f ? ans : -1) << endl; }
#include <bits/stdc++.h> using namespace std; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vll = vector<long long>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define pb push_back #define mp make_pair #define MOD 1000000007 int main() { string s, t, u; cin >> s >> t; u = s + s; ll x = s.size(), y = t.size(); vll hu[26]; rep(i, 2 * x) { int j = u[i] - 'a'; hu[j].pb(i); } vector<vll> next(x, vll(26, -1)); // next[i][j]はsのi番目(0-origin)以降(i含む)でjが初めて出てくる場所 rep(i, x) { rep(j, 26) { if (hu[j].empty()) continue; ll c = *lower_bound(all(hu[j]), i); next[i][j] = c % x; } } ll ans = 0; vll So(100005, -1); // greedyにtのi番目に対応してsの文字の出現場所を列挙 bool f = true; rep(i, y) { int j = t[i] - 'a'; So[i + 1] = next[(So[i] + 1) % x][j]; if (So[i + 1] == -1) { f = false; break; } ll tmp = (So[i + 1] > So[i] ? So[i + 1] - So[i] : So[i + 1] - So[i] + x); ans = ans + tmp; } cout << (f ? ans : -1) << endl; }
[ "identifier.change", "expression.operation.binary.change" ]
740,194
740,195
u073486874
cpp
p02937
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const ll mod = 1000000007; const ll INF = mod * mod; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; typedef vector<int> vec; typedef vector<string> svec; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define int long long void solve() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); set<int> se[27]; rep(i, n) { int k = s[i] - 'a'; se[k].insert(i); } int j = 0; int now = -1, cnt = 0; int ans = 0; while (j < m) { int a = t[j] - 'a'; auto b = se[a].lower_bound(now); if (b == se[a].end()) { if (now == -1) { cout << -1 << endl; return; } cnt++; ans += n; now = -1; } else { now = *b; j++; } } cout << ans + now + 1 << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // init(); solve(); // cout << "finish" << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const ll mod = 1000000007; const ll INF = mod * mod; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; typedef vector<int> vec; typedef vector<string> svec; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define int long long void solve() { string s, t; cin >> s >> t; int n = s.size(), m = t.size(); set<int> se[27]; rep(i, n) { int k = s[i] - 'a'; se[k].insert(i); } int j = 0; int now = -1, cnt = 0; int ans = 0; while (j < m) { int a = t[j] - 'a'; auto b = se[a].upper_bound(now); if (b == se[a].end()) { if (now == -1) { cout << -1 << endl; return; } cnt++; ans += n; now = -1; } else { now = *b; j++; } } cout << ans + now + 1 << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // init(); solve(); // cout << "finish" << endl; return 0; }
[ "call.function.change" ]
740,205
740,206
u508571192
cpp
p02937
#pragma GCC optimize "03" #include <bits/stdc++.h> using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; vector<int> a[27]; signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS; string s, t; cin >> s >> t; for (int i = 0; i < s.length(); i++) a[s[i] - 'a'].push_back(i + 1); int cur = 0, ans = 0; for (int i = 0; i < t.length(); i++) { int tx = t[i] - 'a'; if (a[tx].empty()) return cout << -1, 0; int x = lower_bound(a[tx].begin(), a[tx].end(), cur) - a[tx].begin(); if (x != a[tx].size()) { ans += (a[tx][x] - cur); cur = a[tx][x]; } else { x = lower_bound(a[tx].begin(), a[tx].end(), 0) - a[tx].begin(); ans += (s.length() - cur + a[tx][x]); cur = a[tx][x]; } } cout << ans; return 0; }
#pragma GCC optimize "03" #include <bits/stdc++.h> using namespace std; #define int long long int #define ld long double #define pi pair<int, int> #define pb push_back #define fi first #define se second #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #ifndef LOCAL #define endl '\n' #endif const int N = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9 + 9; vector<int> a[27]; signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS; string s, t; cin >> s >> t; for (int i = 0; i < s.length(); i++) a[s[i] - 'a'].push_back(i + 1); int cur = 0, ans = 0; for (int i = 0; i < t.length(); i++) { int tx = t[i] - 'a'; if (a[tx].empty()) return cout << -1, 0; int x = upper_bound(a[tx].begin(), a[tx].end(), cur) - a[tx].begin(); if (x != a[tx].size()) { ans += (a[tx][x] - cur); cur = a[tx][x]; } else { x = upper_bound(a[tx].begin(), a[tx].end(), 0) - a[tx].begin(); ans += ((int)s.length() - cur + a[tx][x]); cur = a[tx][x]; } } cout << ans; return 0; }
[ "identifier.change", "call.function.change", "expression.operation.binary.change", "assignment.value.change" ]
740,212
740,213
u995439034
cpp
p02937
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; constexpr ll MOD = 1000000007; // struct UnionFind { // vector<int> par; // UnionFind(int N): par(N) { // for (int i=0;i<N;i++) par[i] = i; // } // int root(int x) { // if (par[x] == x) return x; // else return par[x] = root(par[x]); // } // void unite(int x, int y) { // int rx = root(x); // int ry = root(y); // if (rx == ry) return; // par[rx] = ry; // } // bool same(int x, int y) { // int rx = root(x); // int ry = root(y); // return rx == ry; // } // }; int main(void) { string s, t; cin >> s >> t; const int N = s.size(), M = t.size(); set<char> sc, tc; for (int i = 0; i < N; i++) { sc.insert(s[i]); } for (int j = 0; j < M; j++) { if (sc.find(t[j]) == sc.end()) { cout << -1 << endl; return 0; } } ll ans = 0; string::size_type itr = 0; for (int j = 0; j < M; j++) { itr = s.find(t[j], itr + 1); if (itr == string::npos) { ans += (ll)N; itr = s.find(t[j], 0); } #ifdef DEBUG cout << t[j] << ": " << ans << " + " << itr << endl; #endif } ans += (ll)itr; cout << ans + 1LL << endl; return 0; }
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; constexpr ll MOD = 1000000007; // struct UnionFind { // vector<int> par; // UnionFind(int N): par(N) { // for (int i=0;i<N;i++) par[i] = i; // } // int root(int x) { // if (par[x] == x) return x; // else return par[x] = root(par[x]); // } // void unite(int x, int y) { // int rx = root(x); // int ry = root(y); // if (rx == ry) return; // par[rx] = ry; // } // bool same(int x, int y) { // int rx = root(x); // int ry = root(y); // return rx == ry; // } // }; int main(void) { string s, t; cin >> s >> t; const int N = s.size(), M = t.size(); set<char> sc, tc; for (int i = 0; i < N; i++) { sc.insert(s[i]); } for (int j = 0; j < M; j++) { if (sc.find(t[j]) == sc.end()) { cout << -1 << endl; return 0; } } ll ans = 0; string::size_type itr = -1; for (int j = 0; j < M; j++) { itr = s.find(t[j], itr + 1); if (itr == string::npos) { ans += (ll)N; itr = s.find(t[j], 0); } #ifdef DEBUG cout << t[j] << ": " << ans << " + " << itr << endl; #endif } ans += (ll)itr; cout << ans + 1LL << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,217
740,218
u677149117
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int MAX = 1e5 + 10; int pos[30]; int Nxt[MAX][30]; void pr(ll res) { cout << res << "\n"; exit(0); } int main() { string S, T; cin >> S >> T; int sz = S.size(); for (int i = 0; i < 26; i++) pos[i] = sz; for (int i = sz; i >= 0; i--) { for (int j = 0; j < 26; j++) Nxt[i][j] = pos[j]; if (i) pos[S[i - 1] - 'a'] = i; } /*for(int i=0;i<sz;i++){ for(int j=0;j<26;j++)cout<<Nxt[i][j]<<' '; cout<<endl; }*/ ll res = 0, curr = 0, prev = 0; for (int i = 0; i < T.size(); i++) { curr = Nxt[prev][T[i] - 'a']; // cout<<prev<<" "<<curr<<endl; if (curr >= sz) { res += sz; curr = Nxt[0][T[i] - 'a']; } if (curr >= sz) { pr(-1); } prev = curr; } pr(res + prev); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int MAX = 1e5 + 10; int pos[30]; int Nxt[MAX][30]; void pr(ll res) { cout << res << "\n"; exit(0); } int main() { string S, T; cin >> S >> T; int sz = S.size(); for (int i = 0; i < 26; i++) pos[i] = sz + 1; for (int i = sz; i >= 0; i--) { for (int j = 0; j < 26; j++) Nxt[i][j] = pos[j]; if (i) pos[S[i - 1] - 'a'] = i; } /*for(int i=0;i<sz;i++){ for(int j=0;j<26;j++)cout<<Nxt[i][j]<<' '; cout<<endl; }*/ ll res = 0, curr = 0, prev = 0; for (int i = 0; i < T.size(); i++) { curr = Nxt[prev][T[i] - 'a']; // cout<<prev<<" "<<curr<<endl; if (curr > sz) { res += sz; curr = Nxt[0][T[i] - 'a']; } if (curr > sz) { pr(-1); } prev = curr; } pr(res + prev); return 0; }
[ "assignment.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,221
740,222
u205197147
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define pb push_back #define pf push_front typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define mp make_pair #define fi first #define se second typedef pair<int, int> pint; #define All(s) s.begin(), s.end() #define rAll(s) s.rbegin(), s.rend() #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define sz(x) int(x.size()) double pi = 3.141592653589793; ll mod = 1000000007; ll INF = 1000000001; int intmax = 2147483647; int intmin = -2147483648; ll llmax = 9223372036854775807; ll llmin = -9223372036854775807; int main() { string s, t; cin >> s >> t; int n = sz(s), m = sz(t); vector<vector<int>> is(26); rep(i, n) is[s[i] - 'a'].push_back(i); rep(i, n) is[s[i] - 'a'].push_back(i + n); ll ans = 0; int p = 0; rep(i, m) { int c = t[i] - 'a'; if (sz(is[c]) == 0) { puts("-1"); return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p); if (p >= n) { p -= n; ans += n; } } ans += p; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define pf push_front typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define mp make_pair #define fi first #define se second typedef pair<int, int> pint; #define All(s) s.begin(), s.end() #define rAll(s) s.rbegin(), s.rend() #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define sz(x) int(x.size()) double pi = 3.141592653589793; ll mod = 1000000007; ll INF = 1000000001; int intmax = 2147483647; int intmin = -2147483648; ll llmax = 9223372036854775807; ll llmin = -9223372036854775807; int main() { string s, t; cin >> s >> t; int n = sz(s), m = sz(t); vector<vector<int>> is(26); rep(i, n) is[s[i] - 'a'].push_back(i); rep(i, n) is[s[i] - 'a'].push_back(i + n); ll ans = 0; int p = 0; rep(i, m) { int c = t[i] - 'a'; if (sz(is[c]) == 0) { puts("-1"); return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p) + 1; if (p >= n) { p -= n; ans += n; } } ans += p; cout << ans << endl; return 0; }
[ "assignment.change" ]
740,223
740,224
u033602950
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define watch(x) cerr << (#x) << ": " << (x) << endl #define int long long void nope() { cout << -1 << endl; exit(0); } int32_t main() { string s, t; cin >> s >> t; int n = s.length(), m = t.length(); vector<vector<int>> inds(26); for (int i = 0; i < n; ++i) { int cur = s[i] - 'a'; inds[cur].push_back(i + 1); } int ans = 0; int times = 0; for (int i = 0; i < m; ++i) { int cur = t[i] - 'a'; vector<int> &ind = inds[cur]; int round = ans % n; if (ind.empty()) nope(); auto it = upper_bound(ind.begin(), ind.end(), round); if (it == ind.end()) { it = ind.begin(); times++; } ans = *it; } cout << times * n + ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define watch(x) cerr << (#x) << ": " << (x) << endl #define int long long void nope() { cout << -1 << endl; exit(0); } int32_t main() { string s, t; cin >> s >> t; int n = s.length(), m = t.length(); vector<vector<int>> inds(26); for (int i = 0; i < n; ++i) { int cur = s[i] - 'a'; inds[cur].push_back(i + 1); } int ans = 0; int times = 0; for (int i = 0; i < m; ++i) { int cur = t[i] - 'a'; vector<int> &ind = inds[cur]; int round = ans; if (ind.empty()) nope(); auto it = upper_bound(ind.begin(), ind.end(), round); if (it == ind.end()) { it = ind.begin(); times++; } ans = *it; } cout << times * n + ans << endl; return 0; }
[ "expression.operation.binary.remove" ]
740,227
740,228
u455309216
cpp
p02937
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll i, j; string s, t; cin >> s >> t; vector<ll> c_idx[26]; for (i = 0; i < s.length(); i++) { c_idx[s[i] - 'a'].push_back(i); } ll next[26][s.length()]; for (i = 0; i < 26; i++) { ll k = 0; if (c_idx[i].size() == 0) continue; for (j = 0; j < c_idx[i].size(); j++) { ll t = c_idx[i][j]; while (k < t) { next[i][k] = t; k++; } } while (k < s.length()) { next[i][k] = c_idx[i][0]; k++; } } ll a = 0; j = s.length() - 1; for (i = 0; i < t.length(); i++) { if (c_idx[t[i] - 'a'].size() == 0) { a = -1; break; } ll n = next[t[i] - 'a'][j]; if (n < j) { a += n + s.length() - j; } else { a += n - j; } j = n; } cout << a << endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll i, j; string s, t; cin >> s >> t; vector<ll> c_idx[26]; for (i = 0; i < s.length(); i++) { c_idx[s[i] - 'a'].push_back(i); } ll next[26][s.length()]; for (i = 0; i < 26; i++) { ll k = 0; if (c_idx[i].size() == 0) continue; for (j = 0; j < c_idx[i].size(); j++) { ll t = c_idx[i][j]; while (k < t) { next[i][k] = t; k++; } } while (k < s.length()) { next[i][k] = c_idx[i][0]; k++; } } ll a = 0; j = s.length() - 1; for (i = 0; i < t.length(); i++) { if (c_idx[t[i] - 'a'].size() == 0) { a = -1; break; } ll n = next[t[i] - 'a'][j]; if (n <= j) { a += n + s.length() - j; } else { a += n - j; } j = n; } cout << a << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,233
740,234
u898143674
cpp
p02937
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll i, j; string s, t; cin >> s >> t; vector<int> c_idx[26]; for (i = 0; i < s.length(); i++) { c_idx[s[i] - 'a'].push_back(i); } int next[26][s.length()]; for (i = 0; i < 26; i++) { ll k = 0; if (c_idx[i].size() == 0) continue; for (j = 0; j < c_idx[i].size(); j++) { ll t = c_idx[i][j]; while (k < t) { next[i][k] = t; k++; } } while (k < s.length()) { next[i][k] = c_idx[i][0]; k++; } } ll a = 0; j = s.length() - 1; for (i = 0; i < t.length(); i++) { if (c_idx[t[i] - 'a'].size() == 0) { a = -1; break; } ll n = next[t[i] - 'a'][j]; if (n < j) { a += n + s.length() - j; } else { a += n - j; } j = n; } cout << a << endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll i, j; string s, t; cin >> s >> t; vector<ll> c_idx[26]; for (i = 0; i < s.length(); i++) { c_idx[s[i] - 'a'].push_back(i); } ll next[26][s.length()]; for (i = 0; i < 26; i++) { ll k = 0; if (c_idx[i].size() == 0) continue; for (j = 0; j < c_idx[i].size(); j++) { ll t = c_idx[i][j]; while (k < t) { next[i][k] = t; k++; } } while (k < s.length()) { next[i][k] = c_idx[i][0]; k++; } } ll a = 0; j = s.length() - 1; for (i = 0; i < t.length(); i++) { if (c_idx[t[i] - 'a'].size() == 0) { a = -1; break; } ll n = next[t[i] - 'a'][j]; if (n <= j) { a += n + s.length() - j; } else { a += n - j; } j = n; } cout << a << endl; }
[ "variable_declaration.type.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,235
740,234
u898143674
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define rando \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define fi first #define se second #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) \ cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define debugii(x) cerr << " - " << #x << ": " << x.fi << "," << x.se << endl; #define sep() cerr << "--------------------" << endl; #define all(x) (x).begin(), (x).end() #define sz(x) (ll) x.size() #define ll long long #define ii pair<int, int> #define v vector<int> #define vii vector<ii> #define vv vector<vector<int>> #define mp make_pair #define INF 1000000000 #define pb push_back #define EPS 1e-9 const int MOD = 1000000007; // 998244353 int main() { boost; string a, b; cin >> a >> b; vv vec(26); for (int i = 0; i < sz(a); ++i) vec[a[i] - 'a'].pb(i); for (int i = 0; i < sz(b); ++i) if (vec[b[i] - 'a'].empty()) { cout << -1; return 0; } int idx = 0, c = 0; for (int i = 0; i < sz(b); ++i) { int s = lower_bound(all(vec[b[i] - 'a']), idx) - vec[b[i] - 'a'].begin(); if (s == sz(vec[b[i] - 'a'])) c++, idx = vec[b[i] - 'a'][0]; else { idx = vec[b[i] - 'a'][s] + 1; if (s == sz(a)) s = 0, c++; } } cout << c * sz(a) + idx; return 0; } // long long // array bounds // special cases // binary search
#include <bits/stdc++.h> using namespace std; #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define rando \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define fi first #define se second #define debug(x) cerr << " - " << #x << ": " << x << endl; #define debugs(x, y) \ cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl; #define debugii(x) cerr << " - " << #x << ": " << x.fi << "," << x.se << endl; #define sep() cerr << "--------------------" << endl; #define all(x) (x).begin(), (x).end() #define sz(x) (ll) x.size() #define ll long long #define ii pair<int, int> #define v vector<int> #define vii vector<ii> #define vv vector<vector<int>> #define mp make_pair #define INF 1000000000 #define pb push_back #define EPS 1e-9 const int MOD = 1000000007; // 998244353 int main() { boost; string a, b; cin >> a >> b; vv vec(26); for (int i = 0; i < sz(a); ++i) vec[a[i] - 'a'].pb(i); for (int i = 0; i < sz(b); ++i) if (vec[b[i] - 'a'].empty()) { cout << -1; return 0; } int idx = 0, c = 0; for (int i = 0; i < sz(b); ++i) { int s = lower_bound(all(vec[b[i] - 'a']), idx) - vec[b[i] - 'a'].begin(); if (s == sz(vec[b[i] - 'a'])) c++, idx = vec[b[i] - 'a'][0] + 1; else { idx = vec[b[i] - 'a'][s] + 1; if (s == sz(a)) s = 0, c++; } } cout << c * sz(a) + idx; return 0; } // long long // array bounds // special cases // binary search
[ "assignment.change" ]
740,236
740,237
u036734295
cpp
p02937
#include <algorithm> #include <assert.h> #include <bitset> #include <climits> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <type_traits> #include <vector> using namespace std; typedef unsigned long long ull; #define ll long long int static const double PI = 3.141592653589793; ll mod = 1000000007; // typedef vector<int> V; // typedef vector<V> VV; // typedef vector<VV> VVV; int main() { string s, t; cin >> s >> t; vector<vector<ll>> vec(28); for (int i = 0; i < s.size(); i++) { vec[s[i] - 'a'].push_back(i); } for (int i = 0; i < t.size(); i++) { if (vec[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll y = 0, ind = 0; for (int i = 0; i < t.size(); i++) { int it = upper_bound(vec[t[i] - 'a'].begin(), vec[t[i] - 'a'].end(), ind) - vec[t[i] - 'a'].begin(); if (it >= vec[t[i] - 'a'].size()) { y += s.size(); ind = vec[t[i] - 'a'][0]; } else { ind = vec[t[i] - 'a'][it]; } } cout << y + ind + 1 << endl; }
#include <algorithm> #include <assert.h> #include <bitset> #include <climits> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <type_traits> #include <vector> using namespace std; typedef unsigned long long ull; #define ll long long int static const double PI = 3.141592653589793; ll mod = 1000000007; // typedef vector<int> V; // typedef vector<V> VV; // typedef vector<VV> VVV; int main() { string s, t; cin >> s >> t; vector<vector<ll>> vec(28); for (int i = 0; i < s.size(); i++) { vec[s[i] - 'a'].push_back(i); } for (int i = 0; i < t.size(); i++) { if (vec[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll y = 0, ind = -1; for (int i = 0; i < t.size(); i++) { int it = upper_bound(vec[t[i] - 'a'].begin(), vec[t[i] - 'a'].end(), ind) - vec[t[i] - 'a'].begin(); if (it >= vec[t[i] - 'a'].size()) { y += s.size(); ind = vec[t[i] - 'a'][0]; } else { ind = vec[t[i] - 'a'][it]; } } cout << y + ind + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,241
740,242
u065923107
cpp
p02937
#include <algorithm> #include <assert.h> #include <bitset> #include <climits> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <type_traits> #include <vector> using namespace std; typedef unsigned long long ull; #define ll long long int static const double PI = 3.141592653589793; ll mod = 1000000007; // typedef vector<int> V; // typedef vector<V> VV; // typedef vector<VV> VVV; int main() { string s, t; cin >> s >> t; vector<vector<ll>> vec(28); for (int i = 0; i < s.size(); i++) { vec[s[i] - 'a'].push_back(i); } for (int i = 0; i < t.size(); i++) { if (vec[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll y = 0, ind = 0; for (int i = 0; i < t.size(); i++) { int it = lower_bound(vec[t[i] - 'a'].begin(), vec[t[i] - 'a'].end(), 2) - vec[t[i] - 'a'].begin(); if (it >= vec[t[i] - 'a'].size()) { y += s.size(); ind = vec[t[i] - 'a'][0]; } else { ind = vec[t[i] - 'a'][it]; } } cout << y + ind + 1 << endl; }
#include <algorithm> #include <assert.h> #include <bitset> #include <climits> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <type_traits> #include <vector> using namespace std; typedef unsigned long long ull; #define ll long long int static const double PI = 3.141592653589793; ll mod = 1000000007; // typedef vector<int> V; // typedef vector<V> VV; // typedef vector<VV> VVV; int main() { string s, t; cin >> s >> t; vector<vector<ll>> vec(28); for (int i = 0; i < s.size(); i++) { vec[s[i] - 'a'].push_back(i); } for (int i = 0; i < t.size(); i++) { if (vec[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } ll y = 0, ind = -1; for (int i = 0; i < t.size(); i++) { int it = upper_bound(vec[t[i] - 'a'].begin(), vec[t[i] - 'a'].end(), ind) - vec[t[i] - 'a'].begin(); if (it >= vec[t[i] - 'a'].size()) { y += s.size(); ind = vec[t[i] - 'a'][0]; } else { ind = vec[t[i] - 'a'][it]; } } cout << y + ind + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change", "expression.operation.binary.change", "identifier.replace.add", "literal.replace.remove", "call.arguments.change" ]
740,243
740,242
u065923107
cpp
p02937
/* author : mpily :-() title : Competing.cpp time :Tue Aug 27 09:33:36 2019 */ #include <bits/stdc++.h> using namespace std; vector<int> letters[26]; int getAns(string s, string t) { int indexs = 0; int indext = 0; int rounds = 0; int prev = indext; while (indext < t.size()) { if (s[indexs % s.size()] == t[indext]) { indext += 1; indexs += 1; } else { indexs += 1; } if (indexs && !(indexs % s.size())) { if (indext == prev) return -1; else prev = indext; } } return indexs; } int main() { string s, t; cin >> s >> t; // cout<<getAns(s,t)<<"\n"; int count = 1; for (auto &a : s) { letters[a - 'a'].push_back(count); count += 1; } long long letterscount = 0; bool can = 1; int prev = 0; for (auto &a : t) { if (!(letters[a - 'a'].size())) { can = 0; break; } else { bool did = 0; /* for(auto & b : letters[a-'a']){ if(b > prev){ letterscount+=(b-prev); prev = b; did = 1; break; } }*/ if (prev > letters[a - 'a'][letters[a - 'a'].size() - 1]) did = 0; else { did = 1; int max = letters[a - 'a'].size() - 1; int min = 0; int mid = (max + min) / 2; while (max > min) { if (letters[a - 'a'][mid] < prev) { min = mid + 1; mid = (max + min) / 2; } else if (letters[a - 'a'][mid] == prev) { mid = mid + 1; max = mid; min = mid; } else { max = mid; mid = (min + max) / 2; } } letterscount += (letters[a - 'a'][mid] - prev); prev = letters[a - 'a'][mid]; } if (did) continue; else { letterscount += s.size() - prev; letterscount += letters[a - 'a'][0]; prev = letters[a - 'a'][0]; } } } if (can) cout << letterscount << "\n"; else cout << -1 << "\n"; return 0; }
/* author : mpily :-() title : Competing.cpp time :Tue Aug 27 09:33:36 2019 */ #include <bits/stdc++.h> using namespace std; vector<int> letters[26]; int getAns(string s, string t) { int indexs = 0; int indext = 0; int rounds = 0; int prev = indext; while (indext < t.size()) { if (s[indexs % s.size()] == t[indext]) { indext += 1; indexs += 1; } else { indexs += 1; } if (indexs && !(indexs % s.size())) { if (indext == prev) return -1; else prev = indext; } } return indexs; } int main() { string s, t; cin >> s >> t; // cout<<getAns(s,t)<<"\n"; int count = 1; for (auto &a : s) { letters[a - 'a'].push_back(count); count += 1; } long long letterscount = 0; bool can = 1; int prev = 0; for (auto &a : t) { if (!(letters[a - 'a'].size())) { can = 0; break; } else { bool did = 0; /* for(auto & b : letters[a-'a']){ if(b > prev){ letterscount+=(b-prev); prev = b; did = 1; break; } }*/ if (prev >= letters[a - 'a'][letters[a - 'a'].size() - 1]) did = 0; else { did = 1; int max = letters[a - 'a'].size() - 1; int min = 0; int mid = (max + min) / 2; while (max > min) { if (letters[a - 'a'][mid] < prev) { min = mid + 1; mid = (max + min) / 2; } else if (letters[a - 'a'][mid] == prev) { mid = mid + 1; max = mid; min = mid; } else { max = mid; mid = (min + max) / 2; } } letterscount += (letters[a - 'a'][mid] - prev); prev = letters[a - 'a'][mid]; } if (did) continue; else { letterscount += s.size() - prev; letterscount += letters[a - 'a'][0]; prev = letters[a - 'a'][0]; } } } if (can) cout << letterscount << "\n"; else cout << -1 << "\n"; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,247
740,248
u605757515
cpp
p02937
#include "bits/stdc++.h" using namespace std; #define REP(k, m, n) for (int(k) = (m); (k) < (n); (k)++) #define rep(i, n) REP((i), 0, (n)) using ll = long long; int main() { string s, t; cin >> s >> t; map<char, vector<ll>> mp; rep(i, s.size()) mp[s[i]].push_back(i); ll loop = 0; ll now = -1; for (char c : t) { if (mp.find(c) == mp.end()) { cout << -1 << endl; return 0; } auto itr = lower_bound(mp[c].begin(), mp[c].end(), now); if (itr == mp[c].end()) { loop++; now = -1; itr = lower_bound(mp[c].begin(), mp[c].end(), now); } now = *itr; } cout << loop * s.size() + now + 1 << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define REP(k, m, n) for (int(k) = (m); (k) < (n); (k)++) #define rep(i, n) REP((i), 0, (n)) using ll = long long; int main() { string s, t; cin >> s >> t; map<char, vector<ll>> mp; rep(i, s.size()) mp[s[i]].push_back(i); ll loop = 0; ll now = -1; for (char c : t) { if (mp.find(c) == mp.end()) { cout << -1 << endl; return 0; } auto itr = upper_bound(mp[c].begin(), mp[c].end(), now); if (itr == mp[c].end()) { loop++; now = -1; itr = upper_bound(mp[c].begin(), mp[c].end(), now); } now = *itr; } cout << loop * s.size() + now + 1 << endl; return 0; }
[ "identifier.change", "call.function.change", "assignment.value.change" ]
740,249
740,250
u692632484
cpp
p02937
#include <iostream> #include <string> #include <vector> const int NUM_CHAR = 'z' - 'a' + 1; inline constexpr int charToIndex(char c) { return c - 'a'; } int main() { std::string s, t; std::cin >> s; std::cin >> t; // nextIndex[i][charToIndex(c)]: sのi番目から見て、次のcまでの距離 std::vector<std::vector<int>> nextDistance(s.length(), std::vector<int>(NUM_CHAR, -1)); for (char c = 'a'; c <= 'z'; c++) { // 最初に c が現れるインデックスから逆向きに一周する。 int distance = 0; const int pos = s.find(c); if (pos == s.npos) { continue; } const int start = (pos - 1) % s.length(); int i = start; while (true) { distance++; nextDistance[i][charToIndex(c)] = distance; if (s[i] == c) { distance = 0; } i = (i + s.length() - 1) % s.length(); if (i == start) { break; } } } long long result = 0; int index = s.length() - 1; for (const char &c : t) { const int distance = nextDistance[index][charToIndex(c)]; if (distance == -1) { std::cout << -1 << std::endl; return 0; } result += distance; index = (index + distance) % s.length(); } std::cout << result << std::endl; return 0; }
#include <iostream> #include <string> #include <vector> const int NUM_CHAR = 'z' - 'a' + 1; inline constexpr int charToIndex(char c) { return c - 'a'; } int main() { std::string s, t; std::cin >> s; std::cin >> t; // nextIndex[i][charToIndex(c)]: sのi番目から見て、次のcまでの距離 std::vector<std::vector<int>> nextDistance(s.length(), std::vector<int>(NUM_CHAR, -1)); for (char c = 'a'; c <= 'z'; c++) { // 最初に c が現れるインデックスから逆向きに一周する。 int distance = 0; const int pos = s.find(c); if (pos == s.npos) { continue; } const int start = (pos + s.length() - 1) % s.length(); int i = start; while (true) { distance++; nextDistance[i][charToIndex(c)] = distance; if (s[i] == c) { distance = 0; } i = (i + s.length() - 1) % s.length(); if (i == start) { break; } } } long long result = 0; int index = s.length() - 1; for (const char &c : t) { const int distance = nextDistance[index][charToIndex(c)]; if (distance == -1) { std::cout << -1 << std::endl; return 0; } result += distance; index = (index + distance) % s.length(); } std::cout << result << std::endl; return 0; }
[ "assignment.change" ]
740,258
740,259
u591440280
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { string s, t; cin >> s >> t; vector<vector<ll>> al(26); for (int i = 0; i < s.size(); i++) { al[s[i] - 'a'].push_back(i); } ll now = -1; ll loop = 0; for (int i = 0; i < t.size(); i++) { ll id = t[i] - 'a'; if (al[id].size() == 0) { cout << -1 << endl; return 0; } ll last = al[id].size() - 1; if (al[id][last] < now) { loop++; now = al[id][0]; } else { auto itr = lower_bound(al[id].begin(), al[id].end(), now + 1); now = *itr; } } ll ans = loop * s.size() + now + 1; 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>> al(26); for (int i = 0; i < s.size(); i++) { al[s[i] - 'a'].push_back(i); } ll now = -1; ll loop = 0; for (int i = 0; i < t.size(); i++) { ll id = t[i] - 'a'; if (al[id].size() == 0) { cout << -1 << endl; return 0; } ll last = al[id].size() - 1; if (al[id][last] <= now) { loop++; now = al[id][0]; } else { auto itr = lower_bound(al[id].begin(), al[id].end(), now + 1); now = *itr; } } ll ans = loop * s.size() + now + 1; cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,266
740,267
u003019316
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; #define inf = 1e9 + 5; #define dbg(vari) cerr << #vari << " = " << (vari) << endl; void solve(std::string s, std::string t) { unordered_map<char, vector<ll>> m; for (int i = 0; i < s.size(); i++) { char c = s[i]; m[c].push_back(i); } long long copies = 0; long long curr = 0; for (int i = 0; i < t.length(); i++) { if (!m.count(t[i])) { cout << "-1" << endl; return; } auto &vectorToSearch = m[t[i]]; auto found_iter = upper_bound(vectorToSearch.begin(), vectorToSearch.end(), curr); if (found_iter == vectorToSearch.end()) { copies++; curr = vectorToSearch[0]; } else { curr = *found_iter; } } cout << copies * s.length() + curr + 1 << endl; } int main() { std::string s; std::cin >> s; std::string t; std::cin >> t; solve(s, t); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define inf = 1e9 + 5; #define dbg(vari) cerr << #vari << " = " << (vari) << endl; void solve(std::string s, std::string t) { unordered_map<char, vector<ll>> m; for (int i = 0; i < s.size(); i++) { char c = s[i]; m[c].push_back(i); } long long copies = 0; long long curr = -1; for (int i = 0; i < t.length(); i++) { if (!m.count(t[i])) { cout << "-1" << endl; return; } auto &vectorToSearch = m[t[i]]; auto found_iter = upper_bound(vectorToSearch.begin(), vectorToSearch.end(), curr); if (found_iter == vectorToSearch.end()) { copies++; curr = vectorToSearch[0]; } else { curr = *found_iter; } } cout << copies * s.length() + curr + 1 << endl; } int main() { std::string s; std::cin >> s; std::string t; std::cin >> t; solve(s, t); return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,268
740,269
u407431337
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; #define inf = 1e9 + 5; #define dbg(vari) cerr << #vari << " = " << (vari) << endl; void solve(std::string s, std::string t) { unordered_map<char, vector<ll>> m; for (int i = 0; i < s.size(); i++) { char c = s[i]; m[c].push_back(i); } long long copies = 0; long long curr = 0; for (int i = 0; i < t.length(); i++) { if (!m.count(t[i])) { cout << "-1" << endl; return; } auto &vectorToSearch = m[t[i]]; auto found_iter = lower_bound(vectorToSearch.begin(), vectorToSearch.end(), curr); if (found_iter == vectorToSearch.end()) { copies++; curr = vectorToSearch[0]; } else { curr = *found_iter; } } cout << copies * s.length() + curr + 1 << endl; } int main() { std::string s; std::cin >> s; std::string t; std::cin >> t; solve(s, t); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define inf = 1e9 + 5; #define dbg(vari) cerr << #vari << " = " << (vari) << endl; void solve(std::string s, std::string t) { unordered_map<char, vector<ll>> m; for (int i = 0; i < s.size(); i++) { char c = s[i]; m[c].push_back(i); } long long copies = 0; long long curr = -1; for (int i = 0; i < t.length(); i++) { if (!m.count(t[i])) { cout << "-1" << endl; return; } auto &vectorToSearch = m[t[i]]; auto found_iter = upper_bound(vectorToSearch.begin(), vectorToSearch.end(), curr); if (found_iter == vectorToSearch.end()) { copies++; curr = vectorToSearch[0]; } else { curr = *found_iter; } } cout << copies * s.length() + curr + 1 << endl; } int main() { std::string s; std::cin >> s; std::string t; std::cin >> t; solve(s, t); return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change" ]
740,270
740,269
u407431337
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define maxn 200005 #define fr(i, j, k) for (int i = j; i < k; i++) #define f(n) fr(i, 0, n) #define f1(n) fr(i, 1, n + 1) #define ms(i) memset(i, 0, sizeof(i)); #define ms1(i) memset(i, -1, sizeof(i)); #define F first #define S second const int mod = 998244353; int main() { string s, t; cin >> s >> t; vector<int> v[26]; for (int i = 0; i < s.size(); i++) { v[s[i] - 'a'].pb(i); } for (int i = 0; i < t.size(); i++) { if (v[t[i] - 'a'].size() == 0) { cout << -1 << endl; exit(0); } } int r = 0; int cur = 0; for (int i = 0; i < t.size(); i++) { int nxt = t[i] - 'a'; if (upper_bound(v[nxt].begin(), v[nxt].end(), cur) == v[nxt].end()) { r++; cur = v[nxt][0]; } else { cur = *upper_bound(v[nxt].begin(), v[nxt].end(), cur); } } cout << (ll)r * (ll)s.size() + cur + 1 << '\n'; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define maxn 200005 #define fr(i, j, k) for (int i = j; i < k; i++) #define f(n) fr(i, 0, n) #define f1(n) fr(i, 1, n + 1) #define ms(i) memset(i, 0, sizeof(i)); #define ms1(i) memset(i, -1, sizeof(i)); #define F first #define S second const int mod = 998244353; int main() { string s, t; cin >> s >> t; vector<int> v[26]; for (int i = 0; i < s.size(); i++) { v[s[i] - 'a'].pb(i); } for (int i = 0; i < t.size(); i++) { if (v[t[i] - 'a'].size() == 0) { cout << -1 << endl; exit(0); } } int r = 0; int cur = -1; for (int i = 0; i < t.size(); i++) { int nxt = t[i] - 'a'; if (upper_bound(v[nxt].begin(), v[nxt].end(), cur) == v[nxt].end()) { r++; cur = v[nxt][0]; } else { cur = *upper_bound(v[nxt].begin(), v[nxt].end(), cur); } } cout << (ll)r * (ll)s.size() + cur + 1 << '\n'; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,271
740,272
u308590217
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define vl vector<long long> #define pb push_back #define si set<int> #define sl set<long long> #define pq prioirty_queue #define all(v) v.begin(), v.end() #define left (2 * idx) + 1 #define right (2 * idx) + 2 #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); const ll N = (ll)(1e5); const ll MOD = (ll)(1e9 + 7); int main() { FIO; string s, t; cin >> s >> t; map<char, vector<long long>> m; long long ans = 0; long long prev = -1; for (int i = 0; i < s.length(); i++) { m[s[i]].push_back(i + 1); } for (auto ch : t) { if (m[ch].size() == 0) { cout << -1 << "\n"; return 0; } vector<long long>::iterator it = lower_bound(m[ch].begin(), m[ch].end(), prev); if (it == m[ch].end()) { ans += 1; prev = *(m[ch].begin()); } else { prev = *(it); } } cout << (ans * s.size()) + prev << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define vl vector<long long> #define pb push_back #define si set<int> #define sl set<long long> #define pq prioirty_queue #define all(v) v.begin(), v.end() #define left (2 * idx) + 1 #define right (2 * idx) + 2 #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); const ll N = (ll)(1e5); const ll MOD = (ll)(1e9 + 7); int main() { FIO; string s, t; cin >> s >> t; map<char, vector<long long>> m; long long ans = 0; long long prev = -1; for (int i = 0; i < s.length(); i++) { m[s[i]].push_back(i + 1); } for (auto ch : t) { if (m[ch].size() == 0) { cout << -1 << "\n"; return 0; } vector<long long>::iterator it = upper_bound(m[ch].begin(), m[ch].end(), prev); if (it == m[ch].end()) { ans += 1; prev = *(m[ch].begin()); } else { prev = *(it); } } cout << (ans * s.size()) + prev << "\n"; return 0; }
[ "identifier.change", "call.function.change" ]
740,275
740,276
u166359301
cpp
p02937
#include <iostream> #include <stdio.h> #include <bits/stdc++.h> using namespace std; #define INPUT_INT(valName) \ int valName; \ cin >> valName; #define INPUT_STR(valName) \ string valName; \ cin >> valName; #define INPUT_LINE(valName) \ string valName; \ getline(cin, s); #define INPUT_VECTOR_INT(valName, N) \ vector<int> valName(N); \ for (int i = 0; i < N; ++i) { \ cin >> valName[i]; \ } #define INPUT_VECTOR_DOUBLE(valName, N) \ vector<double> valName(N); \ for (int i = 0; i < N; ++i) { \ cin >> valName[i]; \ } #define OUTPUT(A) cout << (A) << endl; #define OUTPUT2(A, B) cout << (A) << " " << (B) << endl; #define OUTPUT3(A, B, C) cout << (A) << " " << (B) << " " << (C) << endl; #define REP(valName, N) for (int valName = 0; valName < N; ++valName) vector<string> split(const string &str, char delimiter) { vector<string> ret; string tmp = ""; for (auto c : str) { if (c != delimiter) { tmp.push_back(c); } else { ret.push_back(tmp); tmp = ""; } } ret.push_back(tmp); return ret; } template <typename T> void sortAsc(vector<T> &v) { sort(v.begin(), v.end(), less<T>()); } template <typename T> void sortDesc(vector<T> &v) { sort(v.begin(), v.end(), greater<T>()); } template <typename T> void insert(vector<T> &dest, const vector<T> &src) { copy(src.begin(), src.end(), back_inserter(dest)); } //------------------------------------------------------------------------------------------------------------------------------ int main() { INPUT_STR(s); INPUT_STR(t); vector<int> dp(t.length() + 1); dp[0] = 0; bool valid = true; int lastIndex; for (int i = 1; i <= t.length(); ++i) { if (i == 1) { lastIndex = s.find(t[0]); if (lastIndex != string::npos) { dp[1] = 1; } else { valid = false; break; } } else { lastIndex = s.find(t[i - 1], lastIndex); if (lastIndex != string::npos) { dp[i] = dp[i - 1]; } else { lastIndex = s.find(t[i - 1]); if (lastIndex != string::npos) { dp[i] = dp[i - 1] + 1; } else { valid = false; break; } } } } if (valid) { long long int res = (long long int)(dp[t.length()] - 1) * s.length() + (lastIndex + 1); OUTPUT(res); } else { OUTPUT(-1); } return 0; }
#include <iostream> #include <stdio.h> #include <bits/stdc++.h> using namespace std; #define INPUT_INT(valName) \ int valName; \ cin >> valName; #define INPUT_STR(valName) \ string valName; \ cin >> valName; #define INPUT_LINE(valName) \ string valName; \ getline(cin, s); #define INPUT_VECTOR_INT(valName, N) \ vector<int> valName(N); \ for (int i = 0; i < N; ++i) { \ cin >> valName[i]; \ } #define INPUT_VECTOR_DOUBLE(valName, N) \ vector<double> valName(N); \ for (int i = 0; i < N; ++i) { \ cin >> valName[i]; \ } #define OUTPUT(A) cout << (A) << endl; #define OUTPUT2(A, B) cout << (A) << " " << (B) << endl; #define OUTPUT3(A, B, C) cout << (A) << " " << (B) << " " << (C) << endl; #define REP(valName, N) for (int valName = 0; valName < N; ++valName) vector<string> split(const string &str, char delimiter) { vector<string> ret; string tmp = ""; for (auto c : str) { if (c != delimiter) { tmp.push_back(c); } else { ret.push_back(tmp); tmp = ""; } } ret.push_back(tmp); return ret; } template <typename T> void sortAsc(vector<T> &v) { sort(v.begin(), v.end(), less<T>()); } template <typename T> void sortDesc(vector<T> &v) { sort(v.begin(), v.end(), greater<T>()); } template <typename T> void insert(vector<T> &dest, const vector<T> &src) { copy(src.begin(), src.end(), back_inserter(dest)); } //------------------------------------------------------------------------------------------------------------------------------ int main() { INPUT_STR(s); INPUT_STR(t); vector<int> dp(t.length() + 1); dp[0] = 0; bool valid = true; int lastIndex; for (int i = 1; i <= t.length(); ++i) { if (i == 1) { lastIndex = s.find(t[0]); if (lastIndex != string::npos) { dp[1] = 1; } else { valid = false; break; } } else { lastIndex = s.find(t[i - 1], lastIndex + 1); if (lastIndex != string::npos) { dp[i] = dp[i - 1]; } else { lastIndex = s.find(t[i - 1]); if (lastIndex != string::npos) { dp[i] = dp[i - 1] + 1; } else { valid = false; break; } } } } if (valid) { long long int res = (long long int)(dp[t.length()] - 1) * s.length() + (lastIndex + 1); OUTPUT(res); } else { OUTPUT(-1); } return 0; }
[ "assignment.change" ]
740,277
740,278
u911738004
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll solve(string s, string t) { int len = s.size(); s = '@' + s; vector<int> sum[26]; for (char x = 0; x < 26; ++x) { sum[x].resize(len + 1); sum[x][0] = 0; } for (int j = 1; j <= len; ++j) { for (char x = 0; x < 26; ++x) sum[x][j] = sum[x][j - 1]; sum[s[j] - 'a'][j] += 1; } ll i = 1, dup = 0; for (int j = 0; j < t.size(); ++j) { char x = t[j] - 'a'; // printf("t[%d] %c\n",j,x+'a'); if (sum[x][len] - sum[x][i] == 0) { i = 0; dup += 1; } if (sum[x][len] - sum[x][i] == 0) { return -1; } i = upper_bound(sum[x].begin() + i + 1, sum[x].end(), sum[x][i]) - sum[x].begin(); // printf("then dup=%lld i=%lld\n",dup,i); } return dup * len + i; } int main() { string s, t; cin >> s >> t; cout << solve(s, t) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll solve(string s, string t) { int len = s.size(); s = '@' + s; vector<int> sum[26]; for (char x = 0; x < 26; ++x) { sum[x].resize(len + 1); sum[x][0] = 0; } for (int j = 1; j <= len; ++j) { for (char x = 0; x < 26; ++x) sum[x][j] = sum[x][j - 1]; sum[s[j] - 'a'][j] += 1; } ll i = 0, dup = 0; for (int j = 0; j < t.size(); ++j) { char x = t[j] - 'a'; // printf("t[%d] %c\n",j,x+'a'); if (sum[x][len] - sum[x][i] == 0) { i = 0; dup += 1; } if (sum[x][len] - sum[x][i] == 0) { return -1; } i = upper_bound(sum[x].begin() + i + 1, sum[x].end(), sum[x][i]) - sum[x].begin(); // printf("then dup=%lld i=%lld\n",dup,i); } return dup * len + i; } int main() { string s, t; cin >> s >> t; cout << solve(s, t) << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,281
740,282
u745685739
cpp
p02937
#include <algorithm> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define rep(i, a, b) for (auto i = (a); i < (b); i++) #define rrep(i, a, b) for (auto i = (a); i > (b); i--) #define all(v) (v).begin(), (v).end() #define print(v) \ { \ for (auto x : v) \ cout << x << ' '; \ cout << endl; \ } #define printn(v, n) \ { \ for (int _i = 0; _i < n; _i++) \ cout << *(v + _i) << ' '; \ cout << endl; \ } typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; const int MAXN = 1e5 + 20; int post[MAXN][26] = {}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s, t; int ns, nt; cin >> s; cin >> t; ns = s.size(); nt = t.size(); for (int i = 0; i < MAXN; i++) for (int j = 0; j < 26; j++) post[i][j] = -1; unordered_map<char, int> mp; for (int i = ns - 1; i >= 0; i--) { mp[s[i]] = i + ns; } for (int i = ns - 1; i >= 0; i--) { for (char c = 'a'; c <= 'z'; c++) { if (mp.count(c)) post[i][c - 'a'] = mp[c] - i; mp[s[i]] = i; } } if (!mp.count(t[0])) { cout << -1 << endl; return 0; } long long cur = mp[t[0]], res = mp[t[0]]; for (int i = 1; i < nt; i++) { // cout << cur << endl; if (post[cur][t[i] - 'a'] == -1) { cout << -1 << endl; return 0; } res += post[cur][t[i] - 'a']; cur = res % ns; } cout << res + 1 << endl; return 0; }
#include <algorithm> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define rep(i, a, b) for (auto i = (a); i < (b); i++) #define rrep(i, a, b) for (auto i = (a); i > (b); i--) #define all(v) (v).begin(), (v).end() #define print(v) \ { \ for (auto x : v) \ cout << x << ' '; \ cout << endl; \ } #define printn(v, n) \ { \ for (int _i = 0; _i < n; _i++) \ cout << *(v + _i) << ' '; \ cout << endl; \ } typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; const int MAXN = 1e5 + 20; int post[MAXN][26] = {}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s, t; int ns, nt; cin >> s; cin >> t; ns = s.size(); nt = t.size(); for (int i = 0; i < MAXN; i++) for (int j = 0; j < 26; j++) post[i][j] = -1; unordered_map<char, int> mp; for (int i = ns - 1; i >= 0; i--) { mp[s[i]] = i + ns; } for (int i = ns - 1; i >= 0; i--) { for (char c = 'a'; c <= 'z'; c++) { if (mp.count(c)) post[i][c - 'a'] = mp[c] - i; } mp[s[i]] = i; } if (!mp.count(t[0])) { cout << -1 << endl; return 0; } long long cur = mp[t[0]], res = mp[t[0]]; for (int i = 1; i < nt; i++) { // cout << cur << endl; if (post[cur][t[i] - 'a'] == -1) { cout << -1 << endl; return 0; } res += post[cur][t[i] - 'a']; cur = res % ns; } cout << res + 1 << endl; return 0; }
[]
740,285
740,286
u096453658
cpp
p02937
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int inf = 1e8; int nxt[maxn << 1][26]; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; string s1; cin >> s >> s1; int n = s.length(); int n1 = s1.length(); s += s; for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) { nxt[i][j] = inf; } } for (int i = 0; i < n * 2; i++) { char c = s[i] - 'a'; for (int j = i - 1; j >= 0; j--) { nxt[j][c] = i < n ? i : i - n; if (s[i] == s[j]) break; } } int cur = -1; for (int i = 0; i < n; i++) { if (s[i] == s1[0]) { cur = i; break; } } if (cur == -1) { cout << -1; return 0; } int cnt = 0; for (int i = 1; i < n1; i++) { int t = nxt[cur][s1[i] - 'a']; if (t < cur) cnt++; cur = t; if (cur == inf) { cout << -1; return 0; } } cout << 1ll * cnt * n + cur + 1; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; const int inf = 1e8; int nxt[maxn << 1][26]; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; string s1; cin >> s >> s1; int n = s.length(); int n1 = s1.length(); s += s; for (int i = 0; i < n * 2; i++) { for (int j = 0; j < 26; j++) { nxt[i][j] = inf; } } for (int i = 0; i < n * 2; i++) { char c = s[i] - 'a'; for (int j = i - 1; j >= 0; j--) { nxt[j][c] = i < n ? i : i - n; if (s[i] == s[j]) break; } } int cur = -1; for (int i = 0; i < n; i++) { if (s[i] == s1[0]) { cur = i; break; } } if (cur == -1) { cout << -1; return 0; } int cnt = 0; for (int i = 1; i < n1; i++) { int t = nxt[cur][s1[i] - 'a']; if (t <= cur) cnt++; cur = t; if (cur == inf) { cout << -1; return 0; } } cout << 1ll * cnt * n + cur + 1; return 0; }
[ "control_flow.loop.for.condition.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,291
740,292
u773531304
cpp
p02937
#include <bits/stdc++.h> #define int long long #define P pair<int, int> #define PP pair<P, int> #define F first #define S second #define f(i, n) for (int i = 0; i < (n); i++) #define INF LLONG_MAX / 3 #define eps LDBL_EPSILON #define mod (int)(1000000007) #define pie 3.141592653589793238462643383279 #define Bpri priority_queue #define Spri priority_queue<P, vector<P>, greater<P>> #define all(x) (x).begin(), (x).end() using namespace std; vector<int> v[26]; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { return a * b / gcd(a, b); } signed main() { string s, t; cin >> s >> t; f(i, s.size()) { v[s[i] - 'a'].push_back(i); } int z = 0, ans = 0, vz; f(i, t.size()) { vz = (int)(lower_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), z) - v[t[i] - 'a'].begin()); if (vz == (int)v[t[i] - 'a'].size()) ans++; if (v[t[i] - 'a'].size() == 0) { puts("-1"); return 0; } z = v[t[i] - 'a'][vz % (int)(v[t[i] - 'a'].size())]; } cout << ans * (int)s.size() + z + 1 << endl; }
#include <bits/stdc++.h> #define int long long #define P pair<int, int> #define PP pair<P, int> #define F first #define S second #define f(i, n) for (int i = 0; i < (n); i++) #define INF LLONG_MAX / 3 #define eps LDBL_EPSILON #define mod (int)(1000000007) #define pie 3.141592653589793238462643383279 #define Bpri priority_queue #define Spri priority_queue<P, vector<P>, greater<P>> #define all(x) (x).begin(), (x).end() using namespace std; vector<int> v[26]; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { return a * b / gcd(a, b); } signed main() { string s, t; cin >> s >> t; f(i, s.size()) { v[s[i] - 'a'].push_back(i); } int z = -1, ans = 0, vz; f(i, t.size()) { vz = (int)(upper_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), z) - v[t[i] - 'a'].begin()); if (vz == (int)v[t[i] - 'a'].size()) ans++; if (v[t[i] - 'a'].size() == 0) { puts("-1"); return 0; } z = v[t[i] - 'a'][vz % (int)(v[t[i] - 'a'].size())]; } cout << ans * (int)s.size() + z + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change", "assignment.value.change", "identifier.change", "call.function.change", "expression.operation.binary.change" ]
740,302
740,303
u259210975
cpp
p02937
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; const double PI = acos(-1.0); int main() { string s, t; cin >> s >> t; vector<vector<int>> c(26, vector<int>()); int sz_s = (int)s.size(); for (int i = 0; i < sz_s; i++) { c[s[i] - 'a'].push_back(i); } int sz_t = (int)t.size(); int pre = -1; int a; ll res = 0; for (int i = 0; i < sz_t; i++) { a = t[i] - 'a'; if ((int)c[a].size() == 0) { res = -1; break; } auto it = lower_bound(c[a].begin(), c[a].end(), pre); if (it == c[a].end()) { it = c[a].begin(); res += sz_s; } res += (*it) - pre; pre = (*it); } cout << res << endl; return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; const double PI = acos(-1.0); int main() { string s, t; cin >> s >> t; vector<vector<int>> c(26, vector<int>()); int sz_s = (int)s.size(); for (int i = 0; i < sz_s; i++) { c[s[i] - 'a'].push_back(i); } int sz_t = (int)t.size(); int pre = -1; int a; ll res = 0; for (int i = 0; i < sz_t; i++) { a = t[i] - 'a'; if ((int)c[a].size() == 0) { res = -1; break; } auto it = lower_bound(c[a].begin(), c[a].end(), pre + 1); if (it == c[a].end()) { it = c[a].begin(); res += sz_s; } res += (*it) - pre; pre = (*it); } cout << res << endl; return 0; }
[ "assignment.change" ]
740,306
740,307
u403813525
cpp
p02937
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; inline void rd(char &c) { int i; for (;;) { i = getchar_unlocked(); if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF) { break; } } c = i; } inline int rd(char c[]) { int i, sz = 0; for (;;) { i = getchar_unlocked(); if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF) { break; } } c[sz++] = i; for (;;) { i = getchar_unlocked(); if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF) { break; } c[sz++] = i; } c[sz] = '\0'; return sz; } inline void wt_L(char a) { putchar_unlocked(a); } inline void wt_L(int x) { char f[10]; int m = 0, s = 0; if (x < 0) { m = 1; x = -x; } while (x) { f[s++] = x % 10; x /= 10; } if (!s) { f[s++] = 0; } if (m) { putchar_unlocked('-'); } while (s--) { putchar_unlocked(f[s] + '0'); } } inline void wt_L(long long x) { char f[20]; int m = 0, s = 0; if (x < 0) { m = 1; x = -x; } while (x) { f[s++] = x % 10; x /= 10; } if (!s) { f[s++] = 0; } if (m) { putchar_unlocked('-'); } while (s--) { putchar_unlocked(f[s] + '0'); } } char S[200002]; char T[100002]; int Slen; int Tlen; int nx[26][200002]; int main() { int c, i, j, k; long long res; Slen = rd(S); Tlen = rd(T); for (i = 0; i < (Slen); i++) { S[i] -= 'a'; } for (i = 0; i < (Tlen); i++) { T[i] -= 'a'; } for (i = 0; i < (Slen); i++) { S[i + Slen] = S[i]; } for (k = 0; k < (26); k++) { nx[k][2 * Slen - 1] = 1073709056; for (i = 2 * Slen - 2; i >= 0; i--) { nx[k][i] = nx[k][i + 1]; if (S[i + 1] == k) { nx[k][i] = i + 1; } } } k = 0; res = 0; for (i = 0; i < (Tlen); i++) { c = T[i]; if (nx[c][k] == 1073709056) { wt_L(-1); wt_L('\n'); return 0; } k = nx[c][k]; if (k >= Slen) { k -= Slen; res++; } } res = res * Slen + k + 1; wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20190818-1 // --- original code --- // char S[200002], T[100002]; // int Slen, Tlen; // // int nx[26][200002]; // // { // int i, j, k, c; // ll res; // // rd(S@Slen, T@Tlen); // // rep(i,Slen) S[i] -= 'a'; // rep(i,Tlen) T[i] -= 'a'; // rep(i,Slen) S[i+Slen] = S[i]; // // rep(k,26){ // nx[k][2Slen-1] = int_inf; // for(i=2Slen-2;i>=0;i--){ // nx[k][i] = nx[k][i+1]; // if(S[i+1]==k) nx[k][i] = i+1; // } // } // // k = 0; // res = 0; // rep(i,Tlen){ // c = T[i]; // if(nx[c][k]==int_inf){ wt(-1); return 0; } // k = nx[c][k]; // if(k >= Slen) k -= Slen, res++; // } // res = res * Slen + k + 1; // wt(res); // }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; inline void rd(char &c) { int i; for (;;) { i = getchar_unlocked(); if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF) { break; } } c = i; } inline int rd(char c[]) { int i, sz = 0; for (;;) { i = getchar_unlocked(); if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF) { break; } } c[sz++] = i; for (;;) { i = getchar_unlocked(); if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF) { break; } c[sz++] = i; } c[sz] = '\0'; return sz; } inline void wt_L(char a) { putchar_unlocked(a); } inline void wt_L(int x) { char f[10]; int m = 0, s = 0; if (x < 0) { m = 1; x = -x; } while (x) { f[s++] = x % 10; x /= 10; } if (!s) { f[s++] = 0; } if (m) { putchar_unlocked('-'); } while (s--) { putchar_unlocked(f[s] + '0'); } } inline void wt_L(long long x) { char f[20]; int m = 0, s = 0; if (x < 0) { m = 1; x = -x; } while (x) { f[s++] = x % 10; x /= 10; } if (!s) { f[s++] = 0; } if (m) { putchar_unlocked('-'); } while (s--) { putchar_unlocked(f[s] + '0'); } } char S[200002]; char T[100002]; int Slen; int Tlen; int nx[26][200002]; int main() { int c, i, j, k; long long res; Slen = rd(S); Tlen = rd(T); for (i = 0; i < (Slen); i++) { S[i] -= 'a'; } for (i = 0; i < (Tlen); i++) { T[i] -= 'a'; } for (i = 0; i < (Slen); i++) { S[i + Slen] = S[i]; } for (k = 0; k < (26); k++) { nx[k][2 * Slen - 1] = 1073709056; for (i = 2 * Slen - 2; i >= 0; i--) { nx[k][i] = nx[k][i + 1]; if (S[i + 1] == k) { nx[k][i] = i + 1; } } } k = Slen - 1; res = -1; for (i = 0; i < (Tlen); i++) { c = T[i]; if (nx[c][k] == 1073709056) { wt_L(-1); wt_L('\n'); return 0; } k = nx[c][k]; if (k >= Slen) { k -= Slen; res++; } } res = res * Slen + k + 1; wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20190820-1 // --- original code --- // char S[200002], T[100002]; // int Slen, Tlen; // // int nx[26][200002]; // // { // int i, j, k, c; // ll res; // // rd(S@Slen, T@Tlen); // // rep(i,Slen) S[i] -= 'a'; // rep(i,Tlen) T[i] -= 'a'; // rep(i,Slen) S[i+Slen] = S[i]; // // rep(k,26){ // nx[k][2Slen-1] = int_inf; // for(i=2Slen-2;i>=0;i--){ // nx[k][i] = nx[k][i+1]; // if(S[i+1]==k) nx[k][i] = i+1; // } // } // // k = Slen-1; // res = -1; // rep(i,Tlen){ // c = T[i]; // if(nx[c][k]==int_inf){ wt(-1); return 0; } // k = nx[c][k]; // if(k >= Slen) k -= Slen, res++; // } // res = res * Slen + k + 1; // wt(res); // }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove", "assignment.change", "literal.number.change" ]
740,314
740,315
u066369439
cpp
p02937
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; inline void rd(char &c) { int i; for (;;) { i = getchar_unlocked(); if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF) { break; } } c = i; } inline int rd(char c[]) { int i, sz = 0; for (;;) { i = getchar_unlocked(); if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF) { break; } } c[sz++] = i; for (;;) { i = getchar_unlocked(); if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF) { break; } c[sz++] = i; } c[sz] = '\0'; return sz; } inline void wt_L(char a) { putchar_unlocked(a); } inline void wt_L(int x) { char f[10]; int m = 0, s = 0; if (x < 0) { m = 1; x = -x; } while (x) { f[s++] = x % 10; x /= 10; } if (!s) { f[s++] = 0; } if (m) { putchar_unlocked('-'); } while (s--) { putchar_unlocked(f[s] + '0'); } } inline void wt_L(long long x) { char f[20]; int m = 0, s = 0; if (x < 0) { m = 1; x = -x; } while (x) { f[s++] = x % 10; x /= 10; } if (!s) { f[s++] = 0; } if (m) { putchar_unlocked('-'); } while (s--) { putchar_unlocked(f[s] + '0'); } } char S[200002]; char T[100002]; int Slen; int Tlen; int nx[26][200002]; int main() { int c, i, j, k; long long res; Slen = rd(S); Tlen = rd(T); for (i = 0; i < (Slen); i++) { S[i] -= 'a'; } for (i = 0; i < (Tlen); i++) { T[i] -= 'a'; } for (i = 0; i < (Slen); i++) { S[i + Slen] = S[i]; } for (k = 0; k < (26); k++) { nx[k][2 * Slen - 1] = 1073709056; for (i = 2 * Slen - 2; i >= 0; i--) { nx[k][i] = nx[k][i + 1]; if (S[i + 1] == k) { nx[k][i] = i + 1; } } } k = 0; res = 0; for (i = 0; i < (Tlen); i++) { c = T[i]; if (nx[c][k] == 1073709056) { wt_L(-1); wt_L('\n'); return 0; } k = nx[c][k]; if (k >= Slen) { k -= Slen; res++; } } res = res * Slen + k + 1; wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20190818-1 // --- original code --- // char S[200002], T[100002]; // int Slen, Tlen; // // int nx[26][200002]; // // { // int i, j, k, c; // ll res; // // rd(S@Slen, T@Tlen); // // rep(i,Slen) S[i] -= 'a'; // rep(i,Tlen) T[i] -= 'a'; // rep(i,Slen) S[i+Slen] = S[i]; // // rep(k,26){ // nx[k][2Slen-1] = int_inf; // for(i=2Slen-2;i>=0;i--){ // nx[k][i] = nx[k][i+1]; // if(S[i+1]==k) nx[k][i] = i+1; // } // } // // k = 0; // res = 0; // rep(i,Tlen){ // c = T[i]; // if(nx[c][k]==int_inf){ wt(-1); return 0; } // k = nx[c][k]; // if(k >= Slen) k -= Slen, res++; // } // res = res * Slen + k + 1; // wt(res); // }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; inline void rd(char &c) { int i; for (;;) { i = getchar_unlocked(); if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF) { break; } } c = i; } inline int rd(char c[]) { int i, sz = 0; for (;;) { i = getchar_unlocked(); if (i != ' ' && i != '\n' && i != '\r' && i != '\t' && i != EOF) { break; } } c[sz++] = i; for (;;) { i = getchar_unlocked(); if (i == ' ' || i == '\n' || i == '\r' || i == '\t' || i == EOF) { break; } c[sz++] = i; } c[sz] = '\0'; return sz; } inline void wt_L(char a) { putchar_unlocked(a); } inline void wt_L(int x) { char f[10]; int m = 0, s = 0; if (x < 0) { m = 1; x = -x; } while (x) { f[s++] = x % 10; x /= 10; } if (!s) { f[s++] = 0; } if (m) { putchar_unlocked('-'); } while (s--) { putchar_unlocked(f[s] + '0'); } } inline void wt_L(long long x) { char f[20]; int m = 0, s = 0; if (x < 0) { m = 1; x = -x; } while (x) { f[s++] = x % 10; x /= 10; } if (!s) { f[s++] = 0; } if (m) { putchar_unlocked('-'); } while (s--) { putchar_unlocked(f[s] + '0'); } } char S[200002]; char T[100002]; int Slen; int Tlen; int nx[26][200002]; int main() { int c, i, j, k; long long res; Slen = rd(S); Tlen = rd(T); for (i = 0; i < (Slen); i++) { S[i] -= 'a'; } for (i = 0; i < (Tlen); i++) { T[i] -= 'a'; } for (i = 0; i < (Slen); i++) { S[i + Slen] = S[i]; } for (k = 0; k < (26); k++) { nx[k][2 * Slen - 1] = 1073709056; for (i = 2 * Slen - 2; i >= 0; i--) { nx[k][i] = nx[k][i + 1]; if (S[i + 1] == k) { nx[k][i] = i + 1; } } } k = Slen - 1; res = -1; for (i = 0; i < (Tlen); i++) { c = T[i]; if (nx[c][k] == 1073709056) { wt_L(-1); wt_L('\n'); return 0; } k = nx[c][k]; if (k >= Slen) { k -= Slen; res++; } } res = res * Slen + k + 1; wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20190818-1 // --- original code --- // char S[200002], T[100002]; // int Slen, Tlen; // // int nx[26][200002]; // // { // int i, j, k, c; // ll res; // // rd(S@Slen, T@Tlen); // // rep(i,Slen) S[i] -= 'a'; // rep(i,Tlen) T[i] -= 'a'; // rep(i,Slen) S[i+Slen] = S[i]; // // rep(k,26){ // nx[k][2Slen-1] = int_inf; // for(i=2Slen-2;i>=0;i--){ // nx[k][i] = nx[k][i+1]; // if(S[i+1]==k) nx[k][i] = i+1; // } // } // // k = Slen-1; // res = -1; // rep(i,Tlen){ // c = T[i]; // if(nx[c][k]==int_inf){ wt(-1); return 0; } // k = nx[c][k]; // if(k >= Slen) k -= Slen, res++; // } // res = res * Slen + k + 1; // wt(res); // }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove", "assignment.change", "literal.number.change" ]
740,314
740,316
u066369439
cpp
p02937
#include <bits/stdc++.h> #define ll long long #define pb(x) push_back(x) using namespace std; int main() { ll n, m; string s, t; cin >> s >> t; n = s.length(); m = t.length(); vector<ll> adj[26]; for (ll i = 0; i < n; i++) { adj[s[i] - 'a'].pb(i); } ll iter = 0; ll ind = 0; for (ll i = 0; i < m; i++) { ll val = t[i] - 'a'; auto tmp_ind = lower_bound(adj[val].begin(), adj[val].end(), ind); if (tmp_ind == adj[val].end()) { iter++; ind = 0; tmp_ind = lower_bound(adj[val].begin(), adj[val].end(), ind); if (tmp_ind == adj[val].end()) { cout << -1; return 0; } } ind = *tmp_ind; // cout<<"it : "<<i<<" "<<iter<<" "<<ind<<"\n"; } ll ans = iter * n + ind + 1; cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long #define pb(x) push_back(x) using namespace std; int main() { ll n, m; string s, t; cin >> s >> t; n = s.length(); m = t.length(); vector<ll> adj[26]; for (ll i = 0; i < n; i++) { adj[s[i] - 'a'].pb(i); } ll iter = 0; ll ind = 0; for (ll i = 0; i < m; i++) { ll val = t[i] - 'a'; auto tmp_ind = lower_bound(adj[val].begin(), adj[val].end(), ind); if (tmp_ind == adj[val].end()) { iter++; ind = 0; tmp_ind = lower_bound(adj[val].begin(), adj[val].end(), ind); if (tmp_ind == adj[val].end()) { cout << -1; return 0; } } ind = *tmp_ind + 1; // cout<<"it : "<<i<<" "<<iter<<" "<<ind<<"\n"; } ll ans = iter * n + ind; cout << ans; return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
740,317
740,318
u357713705
cpp
p02937
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { string s, t; cin >> s >> t; vector<vector<long long>> ab2vec(26); for (long long i = 0; i < s.size(); i++) { ab2vec[s[i] - 'a'].push_back(i); } long long loop = 0, ans = -1; for (long long i = 0; i < t.size(); i++) { long long now = t[i] - 'a'; if (ab2vec[now].size() == 0) { cout << -1 << endl; return 0; } if (ans > ab2vec[now][ab2vec[now].size() - 1]) { loop++; ans = ab2vec[now][0]; } else { auto itr = lower_bound(ab2vec[now].begin(), ab2vec[now].end(), ans + 1); ans = *itr; } // cout << t[i] << " : " << loop << " : " << ans << endl; } cout << loop * s.size() + ans + 1 << endl; }
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { string s, t; cin >> s >> t; vector<vector<long long>> ab2vec(26); for (long long i = 0; i < s.size(); i++) { ab2vec[s[i] - 'a'].push_back(i); } long long loop = 0, ans = -1; for (long long i = 0; i < t.size(); i++) { long long now = t[i] - 'a'; if (ab2vec[now].size() == 0) { cout << -1 << endl; return 0; } if (ans >= ab2vec[now][ab2vec[now].size() - 1]) { loop++; ans = ab2vec[now][0]; } else { auto itr = lower_bound(ab2vec[now].begin(), ab2vec[now].end(), ans + 1); ans = *itr; } // cout << t[i] << " : " << loop << " : " << ans << endl; } cout << loop * s.size() + ans + 1 << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,321
740,322
u990764614
cpp
p02937
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { string s, t; cin >> s >> t; vector<vector<long long>> ab2vec(26); for (long long i = 0; i < s.size(); i++) { ab2vec[s[i] - 'a'].push_back(i); } long long loop = 0, ans = -1; for (long long i = 0; i < t.size(); i++) { long long now = t[i] - 'a'; if (ab2vec[now].size() == 0) { cout << -1 << endl; return 0; } if (ans > ab2vec[now][ab2vec[now].size() - 1]) { loop++; ans = ab2vec[now][0]; } else { auto itr = lower_bound(ab2vec[now].begin(), ab2vec[now].end(), ans); ans = *itr; } // cout << t[i] << " : " << loop << " : " << ans << endl; } cout << loop * s.size() + ans + 1 << endl; }
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { string s, t; cin >> s >> t; vector<vector<long long>> ab2vec(26); for (long long i = 0; i < s.size(); i++) { ab2vec[s[i] - 'a'].push_back(i); } long long loop = 0, ans = -1; for (long long i = 0; i < t.size(); i++) { long long now = t[i] - 'a'; if (ab2vec[now].size() == 0) { cout << -1 << endl; return 0; } if (ans >= ab2vec[now][ab2vec[now].size() - 1]) { loop++; ans = ab2vec[now][0]; } else { auto itr = lower_bound(ab2vec[now].begin(), ab2vec[now].end(), ans + 1); ans = *itr; } // cout << t[i] << " : " << loop << " : " << ans << endl; } cout << loop * s.size() + ans + 1 << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,323
740,322
u990764614
cpp
p02937
// g++ 5.4.0 #include <bits/stdc++.h> using namespace std; #define ll long long int ll c[27] = {0}; ll l[27][1000001]; ll bsearch(ll *ar, ll l, ll r, ll v) { ll ret = -1; while (l <= r) { ll m = (l + r) / 2; if (ar[m] >= v) { ret = ar[m]; r = m - 1; } else l = m + 1; } return ret; } void solve(string s, string tt) { ll n = s.length(); ll m = tt.length(); ll i; for (i = 0; i < n; i++) { ll t = s[i] - 'a'; l[t][c[t]++] = i; } int loop = 0; int pos = 0; for (i = 0; i < m; i++) { ll t = tt[i] - 'a'; if (c[t] == 0) { cout << "-1"; return; } ll ret = bsearch(l[t], 0, c[t] - 1, pos + 1); if (ret == -1) { loop++; pos = l[t][0]; } else pos = ret; } cout << loop * n + pos + 1ll; } int main() { string s, t; cin >> s >> t; solve(s, t); return 0; }
// g++ 5.4.0 #include <bits/stdc++.h> using namespace std; #define ll long long int ll c[27] = {0}; ll l[27][1000001]; ll bsearch(ll *ar, ll l, ll r, ll v) { ll ret = -1; while (l <= r) { ll m = (l + r) / 2; if (ar[m] >= v) { ret = ar[m]; r = m - 1; } else l = m + 1; } return ret; } void solve(string s, string tt) { ll n = s.length(); ll m = tt.length(); ll i; for (i = 0; i < n; i++) { ll t = s[i] - 'a'; l[t][c[t]++] = i; } int loop = 0; int pos = -1; for (i = 0; i < m; i++) { ll t = tt[i] - 'a'; if (c[t] == 0) { cout << "-1"; return; } ll ret = bsearch(l[t], 0, c[t] - 1, pos + 1); if (ret == -1) { loop++; pos = l[t][0]; } else pos = ret; } cout << loop * n + pos + 1ll; } int main() { string s, t; cin >> s >> t; solve(s, t); return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,324
740,325
u453299312
cpp
p02937
#include <algorithm> #include <iostream> #include <set> #include <string> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) using namespace std; typedef long long ll; string s, t; set<int> se[30]; int main() { cin >> s >> t; int ss = s.size(), ts = t.size(); rep(i, 26) se[i].clear(); rep(i, ss) se[(int)(s[i] - 'a')].insert(i); ll x = 0; int front = 0; bool f = true; rep(i, ts) { int tn = t[i] - 'a'; if (se[tn].empty()) { f = false; break; } auto itr = se[tn].upper_bound(front); if (itr != se[tn].end()) { front = *itr; } else { x++; front = *se[tn].begin(); } } if (f) { ll res = (ll)front + 1 + x * ss; cout << res << "\n"; } else cout << -1 << "\n"; return 0; }
#include <algorithm> #include <iostream> #include <set> #include <string> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) using namespace std; typedef long long ll; string s, t; set<int> se[30]; int main() { cin >> s >> t; int ss = s.size(), ts = t.size(); rep(i, 26) se[i].clear(); rep(i, ss) se[(int)(s[i] - 'a')].insert(i); ll x = 0; int front = -1; bool f = true; rep(i, ts) { int tn = t[i] - 'a'; if (se[tn].empty()) { f = false; break; } auto itr = se[tn].upper_bound(front); if (itr != se[tn].end()) { front = *itr; } else { x++; front = *se[tn].begin(); } } if (f) { ll res = (ll)front + 1 + x * ss; cout << res << "\n"; } else cout << -1 << "\n"; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,332
740,333
u110996038
cpp
p02937
#include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; int main() { string s, t; cin >> s; cin >> t; vector<set<int>> pos(26); for (int i = 0; i < s.size(); ++i) pos[s[i] - 'a'].insert(i); long long ans = 1; int prev_pos; for (int i = 0; i < t.size(); ++i) { int num = t[i] - 'a'; if (pos[num].empty()) { ans = -1; break; } else { if (i == 0) { prev_pos = *pos[num].begin(); ans += prev_pos; } else { auto itr = pos[num].lower_bound(prev_pos); // cout << i << " " << prev_pos << " " << *itr << " "; if (itr == pos[num].end()) { ans += (long long)s.size() - prev_pos + *pos[num].begin(); prev_pos = *pos[num].begin(); // cout << " no" << endl; } else { ans += (long long)*itr - prev_pos; prev_pos = *itr; } } } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; int main() { string s, t; cin >> s; cin >> t; vector<set<int>> pos(26); for (int i = 0; i < s.size(); ++i) pos[s[i] - 'a'].insert(i); long long ans = 1; int prev_pos; for (int i = 0; i < t.size(); ++i) { int num = t[i] - 'a'; if (pos[num].empty()) { ans = -1; break; } else { if (i == 0) { prev_pos = *pos[num].begin(); ans += prev_pos; } else { auto itr = pos[num].upper_bound(prev_pos); // cout << i << " " << prev_pos << " " << *itr << " "; if (itr == pos[num].end()) { ans += (long long)s.size() - prev_pos + *pos[num].begin(); prev_pos = *pos[num].begin(); // cout << " no" << endl; } else { ans += (long long)*itr - prev_pos; prev_pos = *itr; } } } } cout << ans << endl; return 0; }
[ "call.function.change" ]
740,334
740,335
u725661271
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define int long long const int MAX = 998244353; vector<int> k[26]; signed main() { string s, t; cin >> s >> t; for (int i = 0; i < s.size(); i++) { k[s[i] - 'a'].push_back(i); } int ans1 = 0, ans2 = 0, ok, ng, mid; for (int i = 0; i < t.size(); i++) { if (k[t[i] - 'a'].size() == 0) { cout << -1; return 0; } if (ans2 > k[t[i] - 'a'][k[t[i] - 'a'].size() - 1]) { ans1++; ans2 = k[t[i] - 'a'][0]; } else { ng = -1; ok = k[t[i] - 'a'].size() - 1; while (abs(ok - ng) > 1) { mid = (ok + ng) / 2; if (ans2 < k[t[i] - 'a'][mid]) { ok = mid; } else ng = mid; } ans2 = k[t[i] - 'a'][ok]; } } cout << ans1 * s.size() + ans2 + 1; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int MAX = 998244353; vector<int> k[26]; signed main() { string s, t; cin >> s >> t; for (int i = 0; i < s.size(); i++) { k[s[i] - 'a'].push_back(i); } int ans1 = 0, ans2 = -1, ok, ng, mid; for (int i = 0; i < t.size(); i++) { if (k[t[i] - 'a'].size() == 0) { cout << -1; return 0; } if (ans2 >= k[t[i] - 'a'][k[t[i] - 'a'].size() - 1]) { ans1++; ans2 = k[t[i] - 'a'][0]; } else { ng = -1; ok = k[t[i] - 'a'].size() - 1; while (abs(ok - ng) > 1) { mid = (ok + ng) / 2; if (ans2 < k[t[i] - 'a'][mid]) { ok = mid; } else ng = mid; } ans2 = k[t[i] - 'a'][ok]; } } cout << ans1 * s.size() + ans2 + 1; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,341
740,342
u651317892
cpp
p02937
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef long double D; typedef complex<D> P; const ll E = 1e18 + 7; const ll MOD = 1000000007; #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define fill(x, y) memset(x, y, sizeof(x)) #define pcnt __builtin_popcount #define buli(x) __builtin_popcountll(x) #define pb push_back #define mp make_pair #define F first #define S second template <class... A> void prints() { cout << endl; } template <class... A> void prints_rest() { cout << endl; } template <class T, class... A> void prints_rest(const T &first, const A &...rest) { cout << " " << first; prints_rest(rest...); } template <class T, class... A> void prints(const T &first, const A &...rest) { cout << first; prints_rest(rest...); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; vector<vector<int>> indices(26, vector<int>(0)); rep(i, sz(s)) { int c = s[i] - 'a'; indices[c].push_back(i); } ll loc = 0; ll loop = 0; rep(i, sz(t)) { int c = t[i] - 'a'; if (sz(indices[c]) == 0) { prints("-1"); return 0; } auto nextIter = lower_bound(all(indices[c]), loc + 1); if (nextIter == indices[c].end()) { ++loop; loc = indices[c][0]; } else { loc = *nextIter; } } ll lenS = s.length(); ll ans = lenS * loop + loc + 1; prints(ans); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef long double D; typedef complex<D> P; const ll E = 1e18 + 7; const ll MOD = 1000000007; #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define fill(x, y) memset(x, y, sizeof(x)) #define pcnt __builtin_popcount #define buli(x) __builtin_popcountll(x) #define pb push_back #define mp make_pair #define F first #define S second template <class... A> void prints() { cout << endl; } template <class... A> void prints_rest() { cout << endl; } template <class T, class... A> void prints_rest(const T &first, const A &...rest) { cout << " " << first; prints_rest(rest...); } template <class T, class... A> void prints(const T &first, const A &...rest) { cout << first; prints_rest(rest...); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; vector<vector<int>> indices(26, vector<int>(0)); rep(i, sz(s)) { int c = s[i] - 'a'; indices[c].push_back(i); } ll loc = -1; ll loop = 0; rep(i, sz(t)) { int c = t[i] - 'a'; if (sz(indices[c]) == 0) { prints("-1"); return 0; } auto nextIter = upper_bound(all(indices[c]), loc); if (nextIter == indices[c].end()) { ++loop; loc = indices[c][0]; } else { loc = *nextIter; } // cout << i << " " << loc << " " << loop << endl; } ll lenS = s.length(); ll ans = lenS * loop + loc + 1; prints(ans); return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change", "expression.operation.binary.remove" ]
740,356
740,357
u598755311
cpp
p02937
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef long double D; typedef complex<D> P; const ll E = 1e18 + 7; const ll MOD = 1000000007; #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define fill(x, y) memset(x, y, sizeof(x)) #define pcnt __builtin_popcount #define buli(x) __builtin_popcountll(x) #define pb push_back #define mp make_pair #define F first #define S second template <class... A> void prints() { cout << endl; } template <class... A> void prints_rest() { cout << endl; } template <class T, class... A> void prints_rest(const T &first, const A &...rest) { cout << " " << first; prints_rest(rest...); } template <class T, class... A> void prints(const T &first, const A &...rest) { cout << first; prints_rest(rest...); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; vector<vector<int>> indices(26, vector<int>(0)); rep(i, sz(s)) { int c = s[i] - 'a'; indices[c].push_back(i); } ll loc = 0; ll loop = 0; rep(i, sz(t)) { int c = t[i] - 'a'; if (sz(indices[c]) == 0) { prints("-1"); return 0; } auto nextIter = lower_bound(all(indices[c]), loc); if (nextIter == indices[c].end()) { ++loop; loc = indices[c][0]; } else { loc = *nextIter; } } ll lenS = s.length(); ll ans = lenS * loop + loc + 1; prints(ans); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef long double D; typedef complex<D> P; const ll E = 1e18 + 7; const ll MOD = 1000000007; #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define fill(x, y) memset(x, y, sizeof(x)) #define pcnt __builtin_popcount #define buli(x) __builtin_popcountll(x) #define pb push_back #define mp make_pair #define F first #define S second template <class... A> void prints() { cout << endl; } template <class... A> void prints_rest() { cout << endl; } template <class T, class... A> void prints_rest(const T &first, const A &...rest) { cout << " " << first; prints_rest(rest...); } template <class T, class... A> void prints(const T &first, const A &...rest) { cout << first; prints_rest(rest...); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; vector<vector<int>> indices(26, vector<int>(0)); rep(i, sz(s)) { int c = s[i] - 'a'; indices[c].push_back(i); } ll loc = -1; ll loop = 0; rep(i, sz(t)) { int c = t[i] - 'a'; if (sz(indices[c]) == 0) { prints("-1"); return 0; } auto nextIter = upper_bound(all(indices[c]), loc); if (nextIter == indices[c].end()) { ++loop; loc = indices[c][0]; } else { loc = *nextIter; } // cout << i << " " << loc << " " << loop << endl; } ll lenS = s.length(); ll ans = lenS * loop + loc + 1; prints(ans); return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change" ]
740,358
740,357
u598755311
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { string s, t; cin >> s >> t; int n = s.length(), m = t.length(); vector<vector<int>> nxt(n, vector<int>(26, -1)); nxt[n - 1][s[n - 1] - 'a'] = n - 1; for (int i = n - 2; i >= 0; --i) { nxt[i] = nxt[i + 1]; nxt[i][s[i] - 'a'] = i; } for (int i = n - 1; i >= 0; --i) { nxt[i] = nxt[(i + 1) % n]; nxt[i][s[i] - 'a'] = i; } int cnt = 0; int ch; int i = 0, j = 0; while (i < m) { ch = t[i] - 'a'; cnt += (nxt[j][ch] - j + 1 + n) % n; j = nxt[j][ch]; // cout << j << " "<<cnt<<"\n"; if (j == -1) { cout << -1; exit(0); } i++; j = (j + 1) % n; } cout << cnt; }
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { string s, t; cin >> s >> t; int n = s.length(), m = t.length(); vector<vector<int>> nxt(n, vector<int>(26, -1)); nxt[n - 1][s[n - 1] - 'a'] = n - 1; for (int i = n - 2; i >= 0; --i) { nxt[i] = nxt[i + 1]; nxt[i][s[i] - 'a'] = i; } for (int i = n - 1; i >= 0; --i) { nxt[i] = nxt[(i + 1) % n]; nxt[i][s[i] - 'a'] = i; } int cnt = 0; int ch; int i = 0, j = 0; while (i < m) { ch = t[i] - 'a'; cnt += (nxt[j][ch] - j + n) % n + 1; j = nxt[j][ch]; // cout << j << " "<<cnt<<"\n"; if (j == -1) { cout << -1; exit(0); } i++; j = (j + 1) % n; } cout << cnt; }
[ "expression.operation.binary.remove", "assignment.change" ]
740,369
740,370
u342757721
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s, t; cin >> s >> t; ll ans = 0; int n = s.size(); int m = t.size(); vector<vector<int>> cindex(26); for (int i = 0; i < n; i++) { cindex[s[i] - 'a'].push_back(i); } int now = 0; for (int i = 0; i < m; i++) { if (cindex[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } auto it = lower_bound(cindex[t[i] - 'a'].begin(), cindex[t[i] - 'a'].end(), now); if (it == cindex[t[i] - 'a'].end()) { now = cindex[t[i] - 'a'][0]; ans += n; } else { now = *it; } } ans += now + 1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s, t; cin >> s >> t; ll ans = 0; int n = s.size(); int m = t.size(); vector<vector<int>> cindex(26); for (int i = 0; i < n; i++) { cindex[s[i] - 'a'].push_back(i); } int now = -1; for (int i = 0; i < m; i++) { if (cindex[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } auto it = upper_bound(cindex[t[i] - 'a'].begin(), cindex[t[i] - 'a'].end(), now); if (it == cindex[t[i] - 'a'].end()) { now = cindex[t[i] - 'a'][0]; ans += n; } else { now = *it; } } ans += now + 1; cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change" ]
740,385
740,386
u656572785
cpp
p02937
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define input(arr, n) \ for (ll i1 = 0; i1 < n; i1++) \ cin >> arr[i1] #define pb(x) push_back(x) #define si(a) scanf("%lld", &a) #define pi(a) printf("%lld", a) #define mod 1000000007 #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") //recursions\ #pragma comment(linker, "/stack:200000000") //loops\ #pragma GCC optimize("unroll-loops") using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, greater_equal<ll>, rb_tree_tag, \ tree_order_statistics_node_update> // s.order_of_key(val) // *s.find_by_order(ind) using namespace std; int main() { sync; string s, t; cin >> s >> t; vector<ll> v[26]; for (ll i = 0; i < s.length(); i++) v[s[i] - 'a'].push_back(i + 1); ll ans = 0, ind = 0; for (ll i = 0; i < t.length(); i++) { if (!v[t[i] - 'a'].size()) return cout << -1, 0; if (ind > v[t[i] - 'a'][v[t[i] - 'a'].size() - 1]) { ans += s.length(); ind = v[t[i] - 'a'][0]; continue; } ll low = 0, high = v[t[i] - 'a'].size() - 1, hind = -1; while (low <= high) { ll mid = (low + high) / 2; if (v[t[i] - 'a'][mid] > ind) high = mid - 1, hind = mid; else low = mid + 1; } ind = v[t[i] - 'a'][hind]; } ans += ind; cout << ans; }
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define input(arr, n) \ for (ll i1 = 0; i1 < n; i1++) \ cin >> arr[i1] #define pb(x) push_back(x) #define si(a) scanf("%lld", &a) #define pi(a) printf("%lld", a) #define mod 1000000007 #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") //recursions\ #pragma comment(linker, "/stack:200000000") //loops\ #pragma GCC optimize("unroll-loops") using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, greater_equal<ll>, rb_tree_tag, \ tree_order_statistics_node_update> // s.order_of_key(val) // *s.find_by_order(ind) using namespace std; int main() { sync; string s, t; cin >> s >> t; vector<ll> v[26]; for (ll i = 0; i < s.length(); i++) v[s[i] - 'a'].push_back(i + 1); ll ans = 0, ind = 0; for (ll i = 0; i < t.length(); i++) { if (!v[t[i] - 'a'].size()) return cout << -1, 0; if (ind >= v[t[i] - 'a'][v[t[i] - 'a'].size() - 1]) { ans += s.length(); ind = v[t[i] - 'a'][0]; continue; } ll low = 0, high = v[t[i] - 'a'].size() - 1, hind = -1; while (low <= high) { ll mid = (low + high) / 2; if (v[t[i] - 'a'][mid] > ind) high = mid - 1, hind = mid; else low = mid + 1; } ind = v[t[i] - 'a'][hind]; } ans += ind; cout << ans; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,391
740,392
u181228520
cpp
p02937
#include <bits/stdc++.h> using namespace std; using lint = long long; vector<int> pos[26]; int main() { #if DEBUG freopen("in.txt", "r", stdin); #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s1, s2; cin >> s1 >> s2; for (int i = 0; i < s1.size(); ++i) pos[s1[i] - 'a'].push_back(i); for (auto ch : s2) { if (pos[ch - 'a'].size() == 0) { cout << "-1\n"; return 0; } } lint ans = 0LL; for (char ch : s2) { auto p = lower_bound(pos[ch - 'a'].begin(), pos[ch - 'a'].end(), ans % s1.size()); if (p == pos[ch - 'a'].end()) { auto rp = lower_bound(pos[ch - 'a'].begin(), pos[ch - 'a'].end(), 0); ans = 1LL * ((ans / s1.size()) + 1LL) * s1.size() + *rp; // cout << *rp << '\n'; } else { ans = 1LL * (ans / s1.size()) * s1.size(); ans += 1LL * (*p) + 1; // cout << *p << '\n'; } // cout << ans << '\n'; } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; using lint = long long; vector<int> pos[26]; int main() { #if DEBUG freopen("in.txt", "r", stdin); #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s1, s2; cin >> s1 >> s2; for (int i = 0; i < s1.size(); ++i) pos[s1[i] - 'a'].push_back(i); for (auto ch : s2) { if (pos[ch - 'a'].size() == 0) { cout << "-1\n"; return 0; } } lint ans = 0LL; // ans는 문자열의 길이 for (char ch : s2) { auto p = lower_bound(pos[ch - 'a'].begin(), pos[ch - 'a'].end(), ans % s1.size()); // ans % s1.size() 이상의 위치를 탐색 if (p == pos[ch - 'a'].end()) { auto rp = lower_bound(pos[ch - 'a'].begin(), pos[ch - 'a'].end(), 0); // 다시 탐색한다. ans = 1LL * ((ans / s1.size()) + 1LL) * s1.size() + *rp + 1; // cout << *rp << '\n'; } else { ans = 1LL * (ans / s1.size()) * s1.size(); ans += 1LL * (*p) + 1; // ans % s1.size() 초과의 위치를 찾아야 하므로 1을 더해준다. // cout << *p << '\n'; } // cout << ans << '\n'; } cout << ans << '\n'; }
[ "assignment.change" ]
740,393
740,394
u277427445
cpp
p02937
#pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long using namespace std; ll i, p, ans; string s, t; int main() { cin >> s >> t; map<char, vector<ll>> a; for (; i < s.size(); i++) a[s[i]].push_back(i + 1); for (auto &i : t) { if (!a[i].size()) return cout << -1, 0; auto k = lower_bound(a[i].begin(), a[i].end(), p); if (k != a[i].end()) { ans += *k - p; p = *k; } else { ans += s.size() - p + *a[i].begin(); p = *a[i].begin(); } } cout << ans; }
#pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long using namespace std; ll i, p, ans; string s, t; int main() { cin >> s >> t; map<char, vector<ll>> a; for (; i < s.size(); i++) a[s[i]].push_back(i + 1); for (auto &i : t) { if (!a[i].size()) return cout << -1, 0; auto k = upper_bound(a[i].begin(), a[i].end(), p); if (k != a[i].end()) { ans += *k - p; p = *k; } else { ans += s.size() - p + *a[i].begin(); p = *a[i].begin(); } } cout << ans; }
[ "identifier.change", "call.function.change" ]
740,401
740,402
u952593352
cpp
p02937
#pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long using namespace std; ll i, p, ans; string s, t; int main() { cin >> s >> t; map<char, vector<ll>> a; for (; i < s.size(); i++) a[s[i]].push_back(i + 1); for (i : t) { if (!a[i].size()) return cout << -1, 0; auto k = lower_bound(a[i].begin(), a[i].end(), p); if (k != a[i].end()) { ans += *k - p; p = *k; } else { ans += s.size() - p + *a[i].begin(); p = *a[i].begin(); } } cout << ans; }
#pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long using namespace std; ll i, p, ans; string s, t; int main() { cin >> s >> t; map<char, vector<ll>> a; for (; i < s.size(); i++) a[s[i]].push_back(i + 1); for (auto &i : t) { if (!a[i].size()) return cout << -1, 0; auto k = upper_bound(a[i].begin(), a[i].end(), p); if (k != a[i].end()) { ans += *k - p; p = *k; } else { ans += s.size() - p + *a[i].begin(); p = *a[i].begin(); } } cout << ans; }
[ "identifier.change", "call.function.change" ]
740,403
740,402
u952593352
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define ll long long #define vl vector<ll> #define pb push_back #define sz size #define xx first #define yy second #define all(x) begin(x), end(x) #define FOR(i, start, end) for (ll i = start; i < end; ++i) #define FORD(i, start, end) for (ll i = end - 1; i >= start; --i) int main() { string s, t; cin >> s >> t; ll n = s.sz(); ll m = t.sz(); vector<vl> letters; letters.resize(26); FOR(i, 0, n) { letters[s[i] - 'a'].pb(i); } ll i = -1; FOR(j, 0, m) { ll ind = t[j] - 'a'; if (letters[ind].sz() == 0) goto fail; auto a = lower_bound(all(letters[ind]), i % n); ll x = -1; if (a != letters[ind].end()) x = *a; if (x >= 0) { i += x - i % n; } else { i += n + letters[ind][0] - i % n; } } cout << i + 1 << endl; return 0; fail: cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define vl vector<ll> #define pb push_back #define sz size #define xx first #define yy second #define all(x) begin(x), end(x) #define FOR(i, start, end) for (ll i = start; i < end; ++i) #define FORD(i, start, end) for (ll i = end - 1; i >= start; --i) int main() { string s, t; cin >> s >> t; ll n = s.sz(); ll m = t.sz(); vector<vl> letters; letters.resize(26); FOR(i, 0, n) { letters[s[i] - 'a'].pb(i); } ll i = -1; FOR(j, 0, m) { ll ind = t[j] - 'a'; if (letters[ind].sz() == 0) goto fail; auto a = lower_bound(all(letters[ind]), i % n + 1); ll x = -1; if (a != letters[ind].end()) x = *a; if (x >= 0) { i += x - i % n; } else { i += n + letters[ind][0] - i % n; } } cout << i + 1 << endl; return 0; fail: cout << -1 << endl; }
[ "assignment.change" ]
740,404
740,405
u511954806
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll oo = 0x3f3f3f3f3f3f3f3fLL; #define sz(c) ll((c).size()) #define all(c) begin(c), end(c) #define TR(X) \ ({ \ if (1) \ cerr << "Trace: " << (#X) << " = " << (X) << endl; \ }) int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s, t; cin >> s >> t; map<char, vector<ll>> ind; ll ns = sz(s), nt = sz(t); for (ll i = 0; i < ns; i++) ind[s[i]].push_back(i); ll copies = 1, curidx = -1; for (ll i = 0; i < nt; i++) { if (sz(ind[t[i]]) == 0) return cout << -1 << endl, 0; auto nxt = lower_bound(all(ind[t[i]]), curidx); if (nxt == ind[t[i]].end()) { copies++; curidx = ind[t[i]][0]; } else { curidx = *nxt; } } cout << (copies - 1) * ns + curidx + 1 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll oo = 0x3f3f3f3f3f3f3f3fLL; #define sz(c) ll((c).size()) #define all(c) begin(c), end(c) #define TR(X) \ ({ \ if (1) \ cerr << "Trace: " << (#X) << " = " << (X) << endl; \ }) int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s, t; cin >> s >> t; map<char, vector<ll>> ind; ll ns = sz(s), nt = sz(t); for (ll i = 0; i < ns; i++) ind[s[i]].push_back(i); ll copies = 1, curidx = -1; for (ll i = 0; i < nt; i++) { if (sz(ind[t[i]]) == 0) return cout << -1 << endl, 0; auto nxt = upper_bound(all(ind[t[i]]), curidx); if (nxt == ind[t[i]].end()) { copies++; curidx = ind[t[i]][0]; } else { curidx = *nxt; } } cout << (copies - 1) * ns + curidx + 1 << endl; }
[ "identifier.change", "call.function.change" ]
740,410
740,411
u882935040
cpp
p02937
#include <algorithm> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define ll int64_t #define Rep(i, n) for (ll i = 0; i < n; i++) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; string S = s + s; ll ns, nt; ns = s.size(); nt = t.size(); vector<vector<ll>> order(26); Rep(i, ns * 2) { order[S[i] - 'a'].push_back(i); } // Rep (i, 26) { // for (auto e : order[i]) { // cout << 'a' + i << " " << e << endl; // } // } ll now = 0; ll cnt = 0; Rep(i, nt) { ll target = t[i] - 'a'; if (order[target].size() == 0) { cout << -1 << endl; return 0; } auto itr = upper_bound(order[target].begin(), order[target].end(), now % ns); ll idx = *itr; // cout << t[i] << " idx:" << idx << endl; now = now - now % ns + idx; // cout << t[i] << " " << now << endl; } cout << now + 1 << endl; }
#include <algorithm> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define ll int64_t #define Rep(i, n) for (ll i = 0; i < n; i++) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; string S = s + s; ll ns, nt; ns = s.size(); nt = t.size(); vector<vector<ll>> order(26); Rep(i, ns * 2) { order[S[i] - 'a'].push_back(i); } // Rep (i, 26) { // for (auto e : order[i]) { // cout << 'a' + i << " " << e << endl; // } // } ll now = -1; ll cnt = 0; Rep(i, nt) { ll target = t[i] - 'a'; if (order[target].size() == 0) { cout << -1 << endl; return 0; } auto itr = upper_bound(order[target].begin(), order[target].end(), now % ns); ll idx = *itr; // cout << t[i] << " idx:" << idx << endl; now = now - now % ns + idx; // cout << t[i] << " " << now << endl; } cout << now + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,414
740,415
u017271745
cpp
p02937
#include <algorithm> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define ll int64_t #define Rep(i, n) for (ll i = 0; i < n; i++) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; string S = s + s; ll ns, nt; ns = s.size(); nt = t.size(); vector<vector<ll>> order(26); Rep(i, ns * 2) { order[S[i] - 'a'].push_back(i); } // Rep (i, 26) { // for (auto e : order[i]) { // cout << 'a' + i << " " << e << endl; // } // } ll now = 0; ll cnt = 0; Rep(i, nt) { ll target = t[i] - 'a'; if (order[target].size() == 0) { cout << -1 << endl; return 0; } auto itr = lower_bound(order[target].begin(), order[target].end(), now % ns); ll idx = *itr; // cout << t[i] << " idx:" << idx << endl; now = now - now % ns + idx; // cout << now << endl; } cout << now + 1 << endl; }
#include <algorithm> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define ll int64_t #define Rep(i, n) for (ll i = 0; i < n; i++) using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; string S = s + s; ll ns, nt; ns = s.size(); nt = t.size(); vector<vector<ll>> order(26); Rep(i, ns * 2) { order[S[i] - 'a'].push_back(i); } // Rep (i, 26) { // for (auto e : order[i]) { // cout << 'a' + i << " " << e << endl; // } // } ll now = -1; ll cnt = 0; Rep(i, nt) { ll target = t[i] - 'a'; if (order[target].size() == 0) { cout << -1 << endl; return 0; } auto itr = upper_bound(order[target].begin(), order[target].end(), now % ns); ll idx = *itr; // cout << t[i] << " idx:" << idx << endl; now = now - now % ns + idx; // cout << t[i] << " " << now << endl; } cout << now + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change" ]
740,416
740,415
u017271745
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> P; const int MOD = 1000000007; int back[100000][26]; int main() { string s, t; cin >> s >> t; int sl = s.length(); int tl = t.length(); s = s + s; int last[26]; rep(i, 26) { last[i] = -1; } for (int i = sl * 2 - 1; i >= 0; i--) { last[s[i] - 'a'] = i; if (i < sl) { rep(j, 26) { back[i][j] = last[j]; } } } ll ans = 0; bool flag = true; rep(i, tl) { if (last[t[i] - 'a'] == -1) { flag = false; break; } ans++; ans = ans / sl * sl + back[ans % sl][t[i] - 'a']; } cout << (flag ? (ans + 1) : -1) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> P; const int MOD = 1000000007; int back[100000][26]; int main() { string s, t; cin >> s >> t; int sl = s.length(); int tl = t.length(); s = s + s; int last[26]; rep(i, 26) { last[i] = -1; } for (int i = sl * 2 - 1; i >= 0; i--) { last[s[i] - 'a'] = i; if (i < sl) { rep(j, 26) { back[i][j] = last[j]; } } } ll ans = -1; bool flag = true; rep(i, tl) { if (last[t[i] - 'a'] == -1) { flag = false; break; } ans++; ans = ans / sl * sl + back[ans % sl][t[i] - 'a']; } cout << (flag ? (ans + 1) : -1) << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,419
740,420
u976817999
cpp
p02937
// warm heart, wagging tail,and a smile just for you! // // ▒█████▒▒ // ██████████▒ // ▒████████████▒ // ██████████████████ // ████████████████████▒ // ▒██████████████████████▒ // ▒███████████████████████ // ▒████▒▒▒▒▒▒█████████████████▒ // ███▒▒▒▒▒▒██████████████████████▒▒▒ // ▒██▒▒███████████████████████▒▒▒▒▒██████ // ▒█████████████████████████▒▒▒▒▒▒█████████▒ // ▒█████████████████████▒▒▒▒▒▒██████████████ // ▒████ ████▒▒▒▒▒████ ████▒ // ▒█████▒ ████ ▒▒▒▒███████ ████ ██████▒ // ▒██▒▒▒▒▒ ██████ █████████ ██████ ██▒▒▒██▒ // █████████ ████████ █████████ ████████ ▒▒▒▒█████ // ▒█████████ ██████ ████████▒ ██████ █████████ // ▒██████████ ████ █████▒▒▒▒▒▒ ████ ██████████ // ████████████ ▒▒▒▒▒▒▒████████ ███████████▒ // ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒ // ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒ // ▒▒▒▒▒▒▒▒▒██████████████ ███████▒▒▒▒███████████ // █████████████████████████ ███████▒▒▒██████████████▒ // █████████████████████████████ ███████▒▒▒██████████████████▒ // ██████████████████████████████████████████████████████████████████████ // ██████████████████████████████████████████████████████████████████▒ // ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒ // #include "bits/stdc++.h" using namespace std; #define MOD 1000000007 //#define MOD 998244353 const double EPS = 1e-9; #define INF (1LL << 60) #define D double #define fs first #define sc second #define int long long #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, a, b) for (int i = (b - 1); i >= (a); --i) #define REP(i, n) FOR(i, 0, (n)) #define RREP(i, n) RFOR(i, 0, (n)) #define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr) #define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr) #define range(i, a, b) ((a) <= (i) && (i) < (b)) #define debug(x) cout << #x << " = " << (x) << endl; #define SP << " " << typedef pair<int, int> P; typedef vector<int> vec; typedef vector<vector<int>> mat; //文字列Sのi文字目以降初めてアルファベットjが出現するindex mat next_index(string &s) { int len = s.size(); mat nx(2 * len, vec(26, INF)); REP(i, 2 * len - 1) nx[i][s[i + 1] - 'a'] = i + 1; RREP(i, 2 * len - 1) REP(j, 26) nx[i][j] = min(nx[i][j], nx[i + 1][j]); return nx; } signed main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; string u = s + s; mat nx = next_index(u); int n = s.size(); int ans = 0, now = n - 1; REP(i, t.size()) { int id = nx[now][t[i] - 'a']; if (id == INF) { cout << -1 << endl; return 0; } ans += id - now; now = id % n; } cout << ans << endl; return 0; }
// warm heart, wagging tail,and a smile just for you! // // ▒█████▒▒ // ██████████▒ // ▒████████████▒ // ██████████████████ // ████████████████████▒ // ▒██████████████████████▒ // ▒███████████████████████ // ▒████▒▒▒▒▒▒█████████████████▒ // ███▒▒▒▒▒▒██████████████████████▒▒▒ // ▒██▒▒███████████████████████▒▒▒▒▒██████ // ▒█████████████████████████▒▒▒▒▒▒█████████▒ // ▒█████████████████████▒▒▒▒▒▒██████████████ // ▒████ ████▒▒▒▒▒████ ████▒ // ▒█████▒ ████ ▒▒▒▒███████ ████ ██████▒ // ▒██▒▒▒▒▒ ██████ █████████ ██████ ██▒▒▒██▒ // █████████ ████████ █████████ ████████ ▒▒▒▒█████ // ▒█████████ ██████ ████████▒ ██████ █████████ // ▒██████████ ████ █████▒▒▒▒▒▒ ████ ██████████ // ████████████ ▒▒▒▒▒▒▒████████ ███████████▒ // ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒ // ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒ // ▒▒▒▒▒▒▒▒▒██████████████ ███████▒▒▒▒███████████ // █████████████████████████ ███████▒▒▒██████████████▒ // █████████████████████████████ ███████▒▒▒██████████████████▒ // ██████████████████████████████████████████████████████████████████████ // ██████████████████████████████████████████████████████████████████▒ // ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒ // #include "bits/stdc++.h" using namespace std; #define MOD 1000000007 //#define MOD 998244353 const double EPS = 1e-9; #define INF (1LL << 60) #define D double #define fs first #define sc second #define int long long #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, a, b) for (int i = (b - 1); i >= (a); --i) #define REP(i, n) FOR(i, 0, (n)) #define RREP(i, n) RFOR(i, 0, (n)) #define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr) #define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr) #define range(i, a, b) ((a) <= (i) && (i) < (b)) #define debug(x) cout << #x << " = " << (x) << endl; #define SP << " " << typedef pair<int, int> P; typedef vector<int> vec; typedef vector<vector<int>> mat; //文字列Sのi文字目以降初めてアルファベットjが出現するindex。O(|S|*文字種) mat next_index(string &s) { int len = s.size(); mat nx(len, vec(26, INF)); REP(i, len - 1) nx[i][s[i + 1] - 'a'] = i + 1; RREP(i, len - 1) REP(j, 26) nx[i][j] = min(nx[i][j], nx[i + 1][j]); return nx; } signed main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; string u = s + s; mat nx = next_index(u); int n = s.size(); int ans = 0, now = n - 1; REP(i, t.size()) { int id = nx[now][t[i] - 'a']; if (id == INF) { cout << -1 << endl; return 0; } ans += id - now; now = id % n; } cout << ans << endl; return 0; }
[ "expression.operation.binary.remove" ]
740,428
740,429
u239493918
cpp
p02937
// Author: Vamsi Krishna Reddy Satti // With love for Competitive Programming! #include <bits/stdc++.h> using namespace std; #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr); #define cout_precision \ cout.setf(ios::fixed); \ cout.precision(32); using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>; using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>; using ld = long double; // ------------------------------------------------------------------------------------------------ ll idx, ans; string s, t; vvll pos; int main() { fast_io; cout_precision; cin >> s >> t; pos.assign(26, vll()); for (ll i = 0; i < (ll)s.length(); i++) { pos[s[i] - 'a'].push_back(i); } for (ll i = 0; i < 26; i++) { sort(pos[i].begin(), pos[i].end()); } idx = 0, ans = 0; for (ll i = 0, c; i < (ll)t.length(); i++) { c = t[i] - 'a'; if (pos[c].empty()) { cout << -1 << endl; return 0; } auto it = upper_bound(pos[c].begin(), pos[c].end(), idx); if (it == pos[c].end()) { ans += s.length(); it = pos[c].begin(); } idx = *it; } cout << ans + idx + 1 << endl; }
// Author: Vamsi Krishna Reddy Satti // With love for Competitive Programming! #include <bits/stdc++.h> using namespace std; #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr); #define cout_precision \ cout.setf(ios::fixed); \ cout.precision(32); using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>; using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>; using ld = long double; // ------------------------------------------------------------------------------------------------ ll idx, ans; string s, t; vvll pos; int main() { fast_io; cout_precision; cin >> s >> t; pos.assign(26, vll()); for (ll i = 0; i < (ll)s.length(); i++) { pos[s[i] - 'a'].push_back(i); } for (ll i = 0; i < 26; i++) { sort(pos[i].begin(), pos[i].end()); } idx = -1, ans = 0; for (ll i = 0, c; i < (ll)t.length(); i++) { c = t[i] - 'a'; if (pos[c].empty()) { cout << -1 << endl; return 0; } auto it = upper_bound(pos[c].begin(), pos[c].end(), idx); if (it == pos[c].end()) { ans += s.length(); it = pos[c].begin(); } idx = *it; } cout << ans + idx + 1 << endl; }
[ "literal.number.change", "assignment.value.change" ]
740,437
740,438
u060072952
cpp
p02937
#include <algorithm> #include <bitset> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits.h> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; string s; using MIte = multimap<int, int>::iterator; int main() { string s; cin >> s; string t; cin >> t; vector<vector<int>> vvPosi(26, vector<int>(0)); for (int i = 0; i != s.length(); i++) { int chara = (int)(s[i] - 'a'); vvPosi[chara].push_back(i); } // for (int i = 0; i != 26; i++) { // sort(vvPosi[i].begin(), vvPosi[i].end()); // } bool fail = false; for (int i = 0; i != t.size(); i++) { // t[i]がsの何番目の文字かを求める if (vvPosi[(int)(t[i] - 'a')].empty()) { fail = true; break; } } if (!fail) { long long nDecrease = 0; long long previdx = 0; for (int i = 0; i != t.size(); i++) { const vector<int> &vtmpPosi = vvPosi[(int)(t[i] - 'a')]; int tmpidx1 = previdx; // bool judge = false; auto it = lower_bound(vtmpPosi.begin(), vtmpPosi.end(), (tmpidx1 + 1)); // for (int j = 0; j != vtmpPosi.size(); j++) { // int tmpidx2 = vtmpPosi[j]; // if (tmpidx2 > tmpidx1) { // previdx = tmpidx2; // judge = true; // break; // } // } if (it == vtmpPosi.end()) { nDecrease++; previdx = vtmpPosi[0]; } else { previdx = (*it); } // if (!judge) { // nDecrease++; // previdx = 0; // } } long long ans = (long long)nDecrease * s.size() + previdx + 1; cout << ans << endl; } else { cout << "-1" << endl; } return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits.h> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; string s; using MIte = multimap<int, int>::iterator; int main() { string s; cin >> s; string t; cin >> t; vector<vector<int>> vvPosi(26, vector<int>(0)); for (int i = 0; i != s.length(); i++) { int chara = (int)(s[i] - 'a'); vvPosi[chara].push_back(i); } // for (int i = 0; i != 26; i++) { // sort(vvPosi[i].begin(), vvPosi[i].end()); // } bool fail = false; for (int i = 0; i != t.size(); i++) { // t[i]がsの何番目の文字かを求める if (vvPosi[(int)(t[i] - 'a')].empty()) { fail = true; break; } } if (!fail) { long long nDecrease = 0; long long previdx = -1; for (int i = 0; i != t.size(); i++) { const vector<int> &vtmpPosi = vvPosi[(int)(t[i] - 'a')]; int tmpidx1 = previdx; // bool judge = false; auto it = lower_bound(vtmpPosi.begin(), vtmpPosi.end(), (tmpidx1 + 1)); // for (int j = 0; j != vtmpPosi.size(); j++) { // int tmpidx2 = vtmpPosi[j]; // if (tmpidx2 > tmpidx1) { // previdx = tmpidx2; // judge = true; // break; // } // } if (it == vtmpPosi.end()) { nDecrease++; previdx = vtmpPosi[0]; } else { previdx = (*it); } // if (!judge) { // nDecrease++; // previdx = 0; // } } long long ans = (long long)nDecrease * s.size() + previdx + 1; cout << ans << endl; } else { cout << "-1" << endl; } return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,443
740,444
u468440945
cpp
p02937
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define initdp(a, b) \ for (int i = 0; i <= a; i++) \ for (int j = 0; j <= b; j++) \ dp[i][j] = -1; #define fi first #define se second #define pb push_back #define pii pair<int, int> #define ll long long #define pll pair<ll, ll> #define rep(i, n) for (int i = 0; i < n; i++) #define repd(i, n) for (int i = n - 1; i >= 0; i--) #define inf 1e9 + 1 #define inf1 1e18 + 1 #define mod 1000000007 #define pie 3.14159265358979323846 #define N 1000005 #define mid(l, r) l + (r - l) / 2 using namespace std; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; void mad(ll &a, ll b) { a = (a + b) % mod; if (a < 0) a += mod; } ll gcd(ll a, ll b) { if (a > b) swap(a, b); if (!a) return b; return gcd(b % a, a); } vector<int> id[26]; void solve() { string s; string t; cin >> s >> t; int n = s.length(), m = t.length(); rep(i, n) id[s[i] - 'a'].pb(i); int pre = 0, ans = 0; rep(i, m) { auto it = upper_bound(id[t[i] - 'a'].begin(), id[t[i] - 'a'].end(), pre); if (it == id[t[i] - 'a'].end()) { pre = -1; it = upper_bound(id[t[i] - 'a'].begin(), id[t[i] - 'a'].end(), pre); if (it == id[t[i] - 'a'].end()) { cout << -1; return; } pre = *it; ans += n; } else pre = *it; } cout << pre + ans + 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; // cin>>t; t = 1; while (t--) { solve(); } }
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define initdp(a, b) \ for (int i = 0; i <= a; i++) \ for (int j = 0; j <= b; j++) \ dp[i][j] = -1; #define fi first #define se second #define pb push_back #define pii pair<int, int> #define ll long long #define pll pair<ll, ll> #define rep(i, n) for (int i = 0; i < n; i++) #define repd(i, n) for (int i = n - 1; i >= 0; i--) #define inf 1e9 + 1 #define inf1 1e18 + 1 #define mod 1000000007 #define pie 3.14159265358979323846 #define N 1000005 #define mid(l, r) l + (r - l) / 2 using namespace std; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; void mad(ll &a, ll b) { a = (a + b) % mod; if (a < 0) a += mod; } ll gcd(ll a, ll b) { if (a > b) swap(a, b); if (!a) return b; return gcd(b % a, a); } vector<ll int> id[26]; void solve() { string s; string t; cin >> s >> t; ll int n = s.length(), m = t.length(); rep(i, n) id[s[i] - 'a'].pb(i); ll int pre = -1, ans = 0; rep(i, m) { auto it = upper_bound(id[t[i] - 'a'].begin(), id[t[i] - 'a'].end(), pre); if (it == id[t[i] - 'a'].end()) { pre = -1; it = upper_bound(id[t[i] - 'a'].begin(), id[t[i] - 'a'].end(), pre); if (it == id[t[i] - 'a'].end()) { cout << -1; return; } pre = *it; ans += n; } else pre = *it; } cout << pre + ans + 1ll; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; // cin>>t; t = 1; while (t--) { solve(); } }
[ "literal.number.change", "variable_declaration.value.change" ]
740,445
740,446
u133630059
cpp
p02937
#include <bits/stdc++.h> using namespace std; long long ans; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s, t; cin >> s; cin >> t; int ssize = s.size(), tsize = t.size(); vector<set<int>> A(26); for (int i = 0; i < ssize; i++) { A[s[i] - 'a'].insert(i); } vector<int> N(tsize); if (A[t[0] - 'a'].empty()) { printf("-1\n"); return 0; } else { N[0] = *A[t[0] - 'a'].begin(); } for (int i = 1; i < tsize; i++) { int abc = t[i] - 'a'; auto it = upper_bound(A[abc].begin(), A[abc].end(), N[i - 1]); if (it != A[abc].end()) { if (A[abc].empty()) { printf("-1\n"); return 0; } N[i] = *A[abc].begin(); ans += ssize; } else { N[i] = *it; } } ans += N[tsize - 1] + 1; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; long long ans; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s, t; cin >> s; cin >> t; int ssize = s.size(), tsize = t.size(); vector<vector<int>> A(26); for (int i = 0; i < ssize; i++) { A[s[i] - 'a'].push_back(i); } vector<int> N(tsize); if (A[t[0] - 'a'].empty()) { printf("-1\n"); return 0; } else { N[0] = *A[t[0] - 'a'].begin(); } for (int i = 1; i < tsize; i++) { int abc = t[i] - 'a'; auto it = upper_bound(A[abc].begin(), A[abc].end(), N[i - 1]); if (it == A[abc].end()) { if (A[abc].empty()) { printf("-1\n"); return 0; } N[i] = *A[abc].begin(); ans += ssize; } else { N[i] = *it; } } ans += N[tsize - 1] + 1; printf("%lld\n", ans); return 0; }
[ "call.function.change", "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
740,449
740,448
u572532976
cpp
p02937
#include <bits/stdc++.h> #define N (200005) #define int long long #define debug(x) cerr << #x << " : " << x << endl #define CM cerr << (&MOP2 - &MOP1) / 1024.0 / 1024.0 << endl using namespace std; template <class T> inline T Min(T x, T y) { return x < y ? x : y; } template <class T> inline T Max(T x, T y) { return x > y ? x : y; } bool MOP1; char a[100005], b[100005]; int t[100005][30]; int ans; bool MOP2; signed main() { scanf("%s%s", a, b); int n = strlen(a); int m = strlen(b); for (int i = 0; i < 26; i++) t[n][i] = n; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < 26; j++) t[i][j] = t[i + 1][j]; t[i][a[i] - 'a'] = i; } for (int i = 0; i < m; i++) if (t[0][b[i] - 'a'] == n) { puts("-1"); return 0; } int cnt = 0; while (cnt < m) { int now = 0; while (t[now][b[cnt] - 'a'] < n) { now = t[now][b[cnt] - 'a'] + 1, cnt++; if (cnt == m) { printf("%lld", now + ans * n + 1LL); return 0; } } ans++; } return 0; }
#include <bits/stdc++.h> #define N (200005) #define int long long #define debug(x) cerr << #x << " : " << x << endl #define CM cerr << (&MOP2 - &MOP1) / 1024.0 / 1024.0 << endl using namespace std; template <class T> inline T Min(T x, T y) { return x < y ? x : y; } template <class T> inline T Max(T x, T y) { return x > y ? x : y; } bool MOP1; char a[100005], b[100005]; int t[100005][30]; int ans; bool MOP2; signed main() { scanf("%s%s", a, b); int n = strlen(a); int m = strlen(b); for (int i = 0; i < 26; i++) t[n][i] = n; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < 26; j++) t[i][j] = t[i + 1][j]; t[i][a[i] - 'a'] = i; } for (int i = 0; i < m; i++) if (t[0][b[i] - 'a'] == n) { puts("-1"); return 0; } int cnt = 0; while (cnt < m) { int now = 0; while (t[now][b[cnt] - 'a'] < n) { now = t[now][b[cnt] - 'a'] + 1, cnt++; if (cnt == m) { printf("%lld", now + ans * n); return 0; } } ans++; } return 0; }
[ "expression.operation.binary.remove" ]
740,452
740,453
u392797842
cpp
p02937
#include <bits/stdc++.h> #define N (200005) #define int long long #define debug(x) cerr << #x << " : " << x << endl #define CM cerr << (&MOP2 - &MOP1) / 1024.0 / 1024.0 << endl using namespace std; template <class T> inline T Min(T x, T y) { return x < y ? x : y; } template <class T> inline T Max(T x, T y) { return x > y ? x : y; } bool MOP1; char a[100005], b[100005]; int t[100005][30]; int ans; bool MOP2; signed main() { scanf("%s%s", a, b); int n = strlen(a); int m = strlen(b); for (int i = 0; i < 26; i++) t[n][i] = n; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < 26; j++) t[i][j] = t[i + 1][j]; t[i][a[i] - 'a'] = i; } for (int i = 0; i < m; i++) if (t[0][b[i] - 'a'] == n) { puts("-1"); return 0; } // for(int i=0;i<n;i++)printf("%d ",t[i]['t'-'a']);puts(""); int cnt = 0; while (cnt < m) { int now = 0; while (t[now][b[cnt] - 'a'] < n) { now = t[now][b[cnt] - 'a'], cnt++; if (cnt == m) { printf("%lld", now + ans * n + 1LL); return 0; } } ans++; } return 0; }
#include <bits/stdc++.h> #define N (200005) #define int long long #define debug(x) cerr << #x << " : " << x << endl #define CM cerr << (&MOP2 - &MOP1) / 1024.0 / 1024.0 << endl using namespace std; template <class T> inline T Min(T x, T y) { return x < y ? x : y; } template <class T> inline T Max(T x, T y) { return x > y ? x : y; } bool MOP1; char a[100005], b[100005]; int t[100005][30]; int ans; bool MOP2; signed main() { scanf("%s%s", a, b); int n = strlen(a); int m = strlen(b); for (int i = 0; i < 26; i++) t[n][i] = n; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < 26; j++) t[i][j] = t[i + 1][j]; t[i][a[i] - 'a'] = i; } for (int i = 0; i < m; i++) if (t[0][b[i] - 'a'] == n) { puts("-1"); return 0; } int cnt = 0; while (cnt < m) { int now = 0; while (t[now][b[cnt] - 'a'] < n) { now = t[now][b[cnt] - 'a'] + 1, cnt++; if (cnt == m) { printf("%lld", now + ans * n); return 0; } } ans++; } return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
740,454
740,453
u392797842
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; signed main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; int n = s.size(), m = t.size(); int now = 0; ll ans = 0; vector<vector<int>> v(26); bool used[26] = {}; for (int i = 0; i < n; i++) { used[s[i] - 'a'] = 1; v[s[i] - 'a'].push_back(i); } for (int i = 0; i < m; i++) { if (!used[t[i] - 'a']) { cout << -1 << endl; return 0; } int p = t[i] - 'a'; auto itr = upper_bound(v[p].begin(), v[p].end(), now); if (itr == v[p].end()) { now = v[p][0]; ans++; } else now = *itr; } ans *= n; ans += now + 1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; signed main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; int n = s.size(), m = t.size(); int now = -2; ll ans = 0; vector<vector<int>> v(26); bool used[26] = {}; for (int i = 0; i < n; i++) { used[s[i] - 'a'] = 1; v[s[i] - 'a'].push_back(i); } for (int i = 0; i < m; i++) { if (!used[t[i] - 'a']) { cout << -1 << endl; return 0; } int p = t[i] - 'a'; auto itr = upper_bound(v[p].begin(), v[p].end(), now); // cerr<<i<<" "<<*itr<<endl; if (itr == v[p].end()) { // cerr<<*itr<<endl; now = v[p][0]; ans++; } else now = *itr; } ans *= n; ans += now + 1; cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,469
740,470
u676029460
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define ran 101101 char s[ran], t[ran]; vector<int> v[33]; int main() { scanf("%s%s", s, t); int ls = strlen(s); int lt = strlen(t); for (int i = 0; i < ls; i++) v[s[i] - 'a'].push_back(i); int cur = 0, cycle = 0; for (int i = 0; i < lt; i++) { int id = t[i] - 'a'; if (v[id].size() <= 0) { puts("-1"); return 0; } int nxt_id = upper_bound(v[id].begin(), v[id].end(), cur) - v[id].begin(); if (nxt_id >= v[id].size()) { cur = v[id][0]; cycle++; } else cur = v[id][nxt_id]; } printf("%lld\n", 1LL * ls * cycle + cur + 1); return 0; }
#include <bits/stdc++.h> using namespace std; #define ran 101101 char s[ran], t[ran]; vector<int> v[33]; int main() { scanf("%s%s", s, t); int ls = strlen(s); int lt = strlen(t); for (int i = 0; i < ls; i++) v[s[i] - 'a'].push_back(i); int cur = -1, cycle = 0; for (int i = 0; i < lt; i++) { int id = t[i] - 'a'; if (v[id].size() <= 0) { puts("-1"); return 0; } int nxt_id = upper_bound(v[id].begin(), v[id].end(), cur) - v[id].begin(); if (nxt_id >= v[id].size()) { cur = v[id][0]; cycle++; } else cur = v[id][nxt_id]; } printf("%lld\n", 1LL * ls * cycle + cur + 1); return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
740,475
740,476
u534772498
cpp
p02937
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <string> using namespace std; #define LL long long string s, t; LL pos, cnt; int main() { cin >> s >> t; for (int i = 0; i <= t.length(); i++) { pos = s.find(t[i], pos); if (pos == -1) { pos = s.find(t[i], 0); if (pos == -1) { puts("-1"); // system("pause"); return 0; } cnt++; } pos++; } LL ans = cnt * s.length() + cnt; printf("%lld \n", ans); // system("pause"); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <string> using namespace std; #define LL long long string s, t; LL pos, cnt; int main() { cin >> s >> t; for (int i = 0; i < t.length(); i++) { pos = s.find(t[i], pos); if (pos == -1) { pos = s.find(t[i], 0); if (pos == -1) { puts("-1"); return 0; } cnt++; } pos++; } LL ans = cnt * s.length() + pos; printf("%lld \n", ans); // system("pause"); return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change", "identifier.change" ]
740,477
740,478
u520815352
cpp