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
//============================================================================ // Name : e.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { string s, t; cin >> s >> t; vector<vector<int>> a(26); for (int i = 0; i < s.size(); i++) { a[s[i] - 'a'].push_back(i); } long long ans = -1; for (int i = 0; i < s.size(); i++) { if (s[i] == t[0]) { ans = i; break; } } // cout<<s<<t<<ans<<endl; if (ans == -1) { cout << -1 << endl; return 0; } for (int i = 1; i < t.size(); i++) { vector<int> v; // v=a[t[i]-'a']; if (a[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } // for(int j=0;j<v.size();j++){ // cout<<v[j]<<' '; // }cout<<endl; int idx = upper_bound(a[t[i] - 'a'].begin(), a[t[i] - 'a'].end(), ans % s.size()) - a[t[i] - 'a'].begin(); if (idx == a[t[i] - 'a'].size()) { ans = ((ans + 1) / s.size() + 1) * s.size() + a[t[i] - 'a'][0]; } else { ans += a[t[i] - 'a'][idx] - ans % s.size(); } // cout<<idx<<' '<<ans<<endl; } cout << ans + 1 << endl; return 0; }
//============================================================================ // Name : e.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { string s, t; cin >> s >> t; vector<vector<int>> a(26); for (int i = 0; i < s.size(); i++) { a[s[i] - 'a'].push_back(i); } long long ans = -1; for (int i = 0; i < s.size(); i++) { if (s[i] == t[0]) { ans = i; break; } } // cout<<s<<t<<ans<<endl; if (ans == -1) { cout << -1 << endl; return 0; } for (int i = 1; i < t.size(); i++) { vector<int> v; // v=a[t[i]-'a']; if (a[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } // for(int j=0;j<v.size();j++){ // cout<<v[j]<<' '; // }cout<<endl; int idx = upper_bound(a[t[i] - 'a'].begin(), a[t[i] - 'a'].end(), ans % s.size()) - a[t[i] - 'a'].begin(); if (idx == a[t[i] - 'a'].size()) { ans = ((ans) / s.size() + 1) * s.size() + a[t[i] - 'a'][0]; } else { ans += a[t[i] - 'a'][idx] - ans % s.size(); } // cout<<idx<<' '<<ans<<endl; } cout << ans + 1 << endl; return 0; }
[ "expression.operation.binary.remove" ]
739,522
739,523
u342703951
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back using ll = long long; using P = pair<int, int>; using Graph = vector<vector<int>>; 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'].pb(i); rep(i, n) is[s[i] - 'a'].pb(i + n); ll ans = 0; int p = 0; //現在位置 rep(i, m) { int c = t[i] - 'a'; if (sz(is[c]) == 0) { cout << "-1" << endl; return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p) + 1; if (p >= n) { p -= n; ans += n; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back using ll = long long; using P = pair<int, int>; using Graph = vector<vector<int>>; 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'].pb(i); rep(i, n) is[s[i] - 'a'].pb(i + n); ll ans = 0; int p = 0; //現在位置 rep(i, m) { int c = t[i] - 'a'; if (sz(is[c]) == 0) { cout << "-1" << endl; return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p) + 1; if (p >= n) { p -= n; ans += n; } } ans += p; //答えは0-indexedでないのでpを足すだけ。 cout << ans << endl; }
[ "assignment.add" ]
739,526
739,527
u455067221
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define mp make_pair #define pb push_back #define ins insert #define pqueue(x) priority_queue<x, vector<x>, greater<x>> #define all(x) (x).begin(), (x).end() #define CST(x) cout << fixed << setprecision(x) #define vtpl(x, y, z) vector<tuple<x, y, z>> #define rev(x) reverse(x); using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pl = pair<ll, ll>; using vpl = vector<pl>; using vvpl = vector<vpl>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { string s, t; cin >> s >> t; vvl alp(26); rep(i, s.size()) { ll a = s[i] - 'a'; alp[a].pb(i); } ll ans = 0; ll tmp = 0; rep(i, t.size()) { ll x = t[i] - 'a'; if (alp[x].size() == 0) { cout << -1 << endl; return 0; } ll ind = lower_bound(all(alp[x]), tmp) - alp[x].begin(); if (ind < alp[x].size()) tmp = alp[x][ind] + 1; else { ans += s.size(); tmp = alp[x][0]; } } cout << ans + tmp << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define mp make_pair #define pb push_back #define ins insert #define pqueue(x) priority_queue<x, vector<x>, greater<x>> #define all(x) (x).begin(), (x).end() #define CST(x) cout << fixed << setprecision(x) #define vtpl(x, y, z) vector<tuple<x, y, z>> #define rev(x) reverse(x); using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; using pl = pair<ll, ll>; using vpl = vector<pl>; using vvpl = vector<vpl>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { string s, t; cin >> s >> t; vvl alp(26); rep(i, s.size()) { ll a = s[i] - 'a'; alp[a].pb(i); } ll ans = 0; ll tmp = 0; rep(i, t.size()) { ll x = t[i] - 'a'; if (alp[x].size() == 0) { cout << -1 << endl; return 0; } ll ind = lower_bound(all(alp[x]), tmp) - alp[x].begin(); if (ind < alp[x].size()) tmp = alp[x][ind] + 1; else { ans += s.size(); tmp = alp[x][0] + 1; } } cout << ans + tmp << endl; }
[ "assignment.change" ]
739,530
739,531
u160429264
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define PI acos(-1) using namespace std; using ll = long long; using P = pair<int, int>; using LP = pair<ll, ll>; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; ll n = s.size(); map<char, vector<ll>> mp; rep(i, n) { mp[s[i]].push_back(i); } ll m = t.size(); ll cur = 0; ll cnt = 0; rep(i, m) { char c = t[i]; if (mp[c].size() == 0) { cout << -1 << endl; return 0; } auto it = upper_bound(mp[c].begin(), mp[c].end(), cur); if (it == mp[c].end()) { cur = mp[c][0]; cnt += n; continue; } cur = *it; } cnt += cur + 1; cout << cnt << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define PI acos(-1) using namespace std; using ll = long long; using P = pair<int, int>; using LP = pair<ll, ll>; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; ll n = s.size(); map<char, vector<ll>> mp; rep(i, n) { mp[s[i]].push_back(i); } ll m = t.size(); ll cur = -1; ll cnt = 0; rep(i, m) { char c = t[i]; if (mp[c].size() == 0) { cout << -1 << endl; return 0; } auto it = upper_bound(mp[c].begin(), mp[c].end(), cur); if (it == mp[c].end()) { cur = mp[c][0]; cnt += n; continue; } cur = *it; } cnt += cur + 1; cout << cnt << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,536
739,537
u482770395
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define PI acos(-1) using namespace std; using ll = long long; using P = pair<int, int>; using LP = pair<ll, ll>; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; int n = s.size(); map<char, vector<int>> mp; rep(i, n) { mp[s[i]].push_back(i); } int m = t.size(); int cur = 0; ll cnt = 0; rep(i, m) { char c = t[i]; if (mp[c].size() == 0) { cout << -1 << endl; return 0; } auto it = upper_bound(mp[c].begin(), mp[c].end(), cur); if (it == mp[c].end()) { cur = mp[c][0]; cnt += n; continue; } cur = *it; } cnt += cur + 1; cout << cnt << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define PI acos(-1) using namespace std; using ll = long long; using P = pair<int, int>; using LP = pair<ll, ll>; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; ll n = s.size(); map<char, vector<ll>> mp; rep(i, n) { mp[s[i]].push_back(i); } ll m = t.size(); ll cur = -1; ll cnt = 0; rep(i, m) { char c = t[i]; if (mp[c].size() == 0) { cout << -1 << endl; return 0; } auto it = upper_bound(mp[c].begin(), mp[c].end(), cur); if (it == mp[c].end()) { cur = mp[c][0]; cnt += n; continue; } cur = *it; } cnt += cur + 1; cout << cnt << endl; }
[ "variable_declaration.type.change", "literal.number.change", "variable_declaration.value.change" ]
739,538
739,537
u482770395
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define PI acos(-1) using namespace std; using ll = long long; using P = pair<int, int>; using LP = pair<ll, ll>; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; map<char, vector<ll>> mp; int n = s.size(); rep(i, n) mp[s[i]].push_back(i); int m = t.size(); ll prev = -1; ll cnt = 0; rep(i, m) { if (mp[t[i]].size() == 0) { cout << -1 << endl; return 0; } vector<ll>::iterator iter = lower_bound(mp[t[i]].begin(), mp[t[i]].end(), prev); if (iter == mp[t[i]].end()) { cnt++; prev = mp[t[i]][0]; } else { prev = *iter; } } cout << cnt * n + prev + 1 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define PI acos(-1) using namespace std; using ll = long long; using P = pair<int, int>; using LP = pair<ll, ll>; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; map<char, vector<ll>> mp; int n = s.size(); rep(i, n) mp[s[i]].push_back(i); int m = t.size(); ll prev = -1; ll cnt = 0; rep(i, m) { if (mp[t[i]].size() == 0) { cout << -1 << endl; return 0; } vector<ll>::iterator iter = upper_bound(mp[t[i]].begin(), mp[t[i]].end(), prev); if (iter == mp[t[i]].end()) { cnt++; prev = mp[t[i]][0]; } else { prev = *iter; } } cout << cnt * n + prev + 1 << endl; }
[ "identifier.change", "call.function.change" ]
739,539
739,540
u482770395
cpp
p02937
#include <bits/stdc++.h> #include <math.h> #include <regex> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const ll mod = 1000000007; const int INF = 1001001001; const ll LINF = 1001001001001001001; int main() { string s, t; cin >> s >> t; vector<vector<ll>> alp(26); ll ns = s.size(), nt = t.size(); rep(i, ns) { ll x = s.at(i) - 'a'; alp.at(x).push_back(i); } pair<ll, ll> now(1, 0); // 1週目の0文字目にいるところからスタート rep(i, nt) { ll x = t.at(i) - 'a'; if (alp.at(x).size() == 0) { // sにそのアルファベットが含まれていない場合は不可 std::cout << -1 << endl; return 0; } label:; auto it = lower_bound(alp.at(x).begin(), alp.at(x).end(), now.second); if (it == alp.at(x).end()) { now.first++; now.second = 0; goto label; } else { now.second = *it; now.second++; } } std::cout << (now.first - 1) * ns + now.second + 1 << endl; }
#include <bits/stdc++.h> #include <math.h> #include <regex> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const ll mod = 1000000007; const int INF = 1001001001; const ll LINF = 1001001001001001001; int main() { string s, t; cin >> s >> t; vector<vector<ll>> alp(26); ll ns = s.size(), nt = t.size(); rep(i, ns) { ll x = s.at(i) - 'a'; alp.at(x).push_back(i); } pair<ll, ll> now(1, 0); // 1週目の0文字目にいるところからスタート rep(i, nt) { ll x = t.at(i) - 'a'; if (alp.at(x).size() == 0) { // sにそのアルファベットが含まれていない場合は不可 std::cout << -1 << endl; return 0; } label:; auto it = lower_bound(alp.at(x).begin(), alp.at(x).end(), now.second); if (it == alp.at(x).end()) { now.first++; now.second = 0; goto label; } else { now.second = *it; now.second++; } } std::cout << (now.first - 1) * ns + now.second << endl; }
[ "expression.operation.binary.remove" ]
739,543
739,544
u628597699
cpp
p02937
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl typedef long long ll; const ll mod = 1e9 + 7; const int maxn = 1e6 + 5; string s, t; int n, m; bool ha[maxn]; ll ans = 0; map<char, vector<int>> mp; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> s >> t; n = s.length(); m = t.length(); for (int i = 0; i < n; i++) { mp[s[i]].push_back(i); } for (char c : s) { ha[c - 'a'] = true; } for (char c : t) { if (!ha[c - 'a']) out(-1); } int j = -1; for (int i = 0; i < m; i++) { auto iter = lower_bound(mp[t[i]].begin(), mp[t[i]].end(), j); if (iter == mp[t[i]].end()) { ans += n - j - 1; j = -1; iter = lower_bound(mp[t[i]].begin(), mp[t[i]].end(), j); assert(iter != mp[t[i]].end()); } ans += *iter - j; // watch(ans); j = *iter; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl typedef long long ll; const ll mod = 1e9 + 7; const int maxn = 1e6 + 5; string s, t; int n, m; bool ha[maxn]; ll ans = 0; map<char, vector<int>> mp; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> s >> t; n = s.length(); m = t.length(); for (int i = 0; i < n; i++) { mp[s[i]].push_back(i); } for (char c : s) { ha[c - 'a'] = true; } for (char c : t) { if (!ha[c - 'a']) out(-1); } int j = -1; for (int i = 0; i < m; i++) { auto iter = upper_bound(mp[t[i]].begin(), mp[t[i]].end(), j); if (iter == mp[t[i]].end()) { ans += n - j - 1; j = -1; iter = upper_bound(mp[t[i]].begin(), mp[t[i]].end(), j); assert(iter != mp[t[i]].end()); } ans += *iter - j; // watch(ans); j = *iter; } cout << ans << endl; return 0; }
[ "identifier.change", "call.function.change", "assignment.value.change" ]
739,555
739,556
u774417629
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; vector<int> pos[26]; int n = t.length(), m = s.length(); for (int i = 0; i < m; i++) { pos[s[i] - 'a'].push_back(i); } long long ans = 0; for (int i = 0; i < n; i++) { int j = t[i] - 'a'; auto &v = pos[j]; int x = ans % m, lo = 0, hi = v.size(); while (lo < hi) { int mid = lo + (hi - lo) / 2; if (v[mid] >= x) { hi = mid; } else { lo = mid + 1; } } if (v.empty()) { cout << -1 << endl; return 0; } else if (hi == (int)v.size()) { ans += m - x + v[0]; } else { ans += v[hi] - x + 1; } //$ cerr << ans << endl; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; vector<int> pos[26]; int n = t.length(), m = s.length(); for (int i = 0; i < m; i++) { pos[s[i] - 'a'].push_back(i); } long long ans = 0; for (int i = 0; i < n; i++) { int j = t[i] - 'a'; auto &v = pos[j]; int x = ans % m, lo = 0, hi = v.size(); while (lo < hi) { int mid = lo + (hi - lo) / 2; if (v[mid] >= x) { hi = mid; } else { lo = mid + 1; } } if (v.empty()) { cout << -1 << endl; return 0; } else if (hi == (int)v.size()) { ans += m - x + v[0] + 1; } else { ans += v[hi] - x + 1; } //$ cerr << ans << endl; } cout << ans << endl; }
[ "assignment.change" ]
739,561
739,562
u370709193
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; vector<int> pos[26]; int n = t.length(), m = s.length(); for (int i = 0; i < m; i++) { pos[s[i] - 'a'].push_back(i); } int ans = 0; for (int i = 0; i < n; i++) { int j = t[i] - 'a'; auto &v = pos[j]; int x = ans % m, lo = 0, hi = v.size(); while (lo < hi) { int mid = lo + (hi - lo) / 2; if (v[mid] >= x) { hi = mid; } else { lo = mid + 1; } } if (v.empty()) { cout << -1 << endl; return 0; } else if (hi == (int)v.size()) { ans += m - x + v[0]; } else { ans += v[hi] - x + 1; } //$ cerr << ans << endl; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; vector<int> pos[26]; int n = t.length(), m = s.length(); for (int i = 0; i < m; i++) { pos[s[i] - 'a'].push_back(i); } long long ans = 0; for (int i = 0; i < n; i++) { int j = t[i] - 'a'; auto &v = pos[j]; int x = ans % m, lo = 0, hi = v.size(); while (lo < hi) { int mid = lo + (hi - lo) / 2; if (v[mid] >= x) { hi = mid; } else { lo = mid + 1; } } if (v.empty()) { cout << -1 << endl; return 0; } else if (hi == (int)v.size()) { ans += m - x + v[0] + 1; } else { ans += v[hi] - x + 1; } //$ cerr << ans << endl; } cout << ans << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "assignment.change" ]
739,563
739,562
u370709193
cpp
p02937
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define int long long const int ALP = 26; vector<int> w[ALP]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; int n = (int)s.size(); for (int i = 0; i < n; i++) { w[s[i] - 'a'].push_back(i); } int pnt = 0; int full = 0; for (auto x : t) { int c = x - 'a'; if (w[c].empty()) { cout << -1 << endl; return 0; } if (w[c].back() <= pnt) { full++; pnt = w[c].front(); } else { pnt = *upper_bound(w[c].begin(), w[c].end(), pnt); } } cout << full * n + pnt + 1 << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define int long long const int ALP = 26; vector<int> w[ALP]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; int n = (int)s.size(); for (int i = 0; i < n; i++) { w[s[i] - 'a'].push_back(i); } int pnt = -1; int full = 0; for (auto x : t) { int c = x - 'a'; if (w[c].empty()) { cout << -1 << endl; return 0; } if (w[c].back() <= pnt) { full++; pnt = w[c].front(); } else { pnt = *upper_bound(w[c].begin(), w[c].end(), pnt); } } cout << full * n + pnt + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,575
739,576
u293523151
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define PI 3.14159265359 #define INF 1000100100 #define all(x) (x).begin(), (x).end() typedef long long ll; using namespace std; int main() { string s, t; cin >> s >> t; vector<vector<int>> ord(26); int sl = s.length(); int tl = t.length(); rep(i, sl) ord[s[i] - 'a'].push_back(i + 1); rep(i, sl) ord[s[i] - 'a'].push_back(i + 1 + sl); ll ans = 0; int p = 1; rep(i, tl) { if (ord[t[i] - 'a'].empty()) { cout << -1 << endl; return 0; } else { p = *upper_bound(ord[t[i] - 'a'].begin(), ord[t[i] - 'a'].end(), p); if (p > sl) { p -= sl; ans += sl; } } } ans += p; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define PI 3.14159265359 #define INF 1000100100 #define all(x) (x).begin(), (x).end() typedef long long ll; using namespace std; int main() { string s, t; cin >> s >> t; vector<vector<int>> ord(26); int sl = s.length(); int tl = t.length(); rep(i, sl) ord[s[i] - 'a'].push_back(i + 1); rep(i, sl) ord[s[i] - 'a'].push_back(i + 1 + sl); ll ans = 0; int p = 0; rep(i, tl) { if (ord[t[i] - 'a'].empty()) { cout << -1 << endl; return 0; } else { p = *upper_bound(ord[t[i] - 'a'].begin(), ord[t[i] - 'a'].end(), p); if (p > sl) { p -= sl; ans += sl; } } } ans += p; cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,577
739,578
u437779154
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; //#include <boost/multiprecision/cpp_ll.hpp> // typedef boost::multiprecision::cpp_ll ll; typedef long double dd; #define i_7 (ll)(1E9 + 7) //#define i_7 998244353 #define i_5 i_7 - 2 ll mod(ll a) { ll c = a % i_7; if (c >= 0) return c; return c + i_7; } typedef pair<ll, ll> l_l; ll inf = (ll)1E16; #define rep(i, l, r) for (ll i = l; i <= r; i++) #define pb push_back ll max(ll a, ll b) { if (a < b) return b; else return a; } ll min(ll a, ll b) { if (a > b) return b; else return a; } void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]); void Min(ll &pos, ll val) { pos = min(pos, val); } void Add(ll &pos, ll val) { pos = mod(pos + val); } dd EPS = 1E-9; string alp = "abcdefghijklmnopqrstuvwxyz"; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); int main() { string s, t; cin >> s >> t; vector<ll> a[26]; unordered_map<char, ll> mp; rep(i, 0, 25) mp[alp[i]] = i; rep(i, 0, s.size() - 1) { a[mp[s[i]]].pb(i); } ll num = 0; ll now = 0; rep(i, 0, t.size() - 1) { if (a[mp[t[i]]].size() == 0) { cout << -1 << endl; return 0; } ll l = lower_bound(a[mp[t[i]]].begin(), a[mp[t[i]]].end(), now) - a[mp[t[i]]].begin(); if (l == a[mp[t[i]]].size()) { num++; now = a[mp[t[i]]][0]; } else { now = a[mp[t[i]]][l] + 1; } } cout << num * s.size() + now << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; //#include <boost/multiprecision/cpp_ll.hpp> // typedef boost::multiprecision::cpp_ll ll; typedef long double dd; #define i_7 (ll)(1E9 + 7) //#define i_7 998244353 #define i_5 i_7 - 2 ll mod(ll a) { ll c = a % i_7; if (c >= 0) return c; return c + i_7; } typedef pair<ll, ll> l_l; ll inf = (ll)1E16; #define rep(i, l, r) for (ll i = l; i <= r; i++) #define pb push_back ll max(ll a, ll b) { if (a < b) return b; else return a; } ll min(ll a, ll b) { if (a > b) return b; else return a; } void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]); void Min(ll &pos, ll val) { pos = min(pos, val); } void Add(ll &pos, ll val) { pos = mod(pos + val); } dd EPS = 1E-9; string alp = "abcdefghijklmnopqrstuvwxyz"; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); int main() { string s, t; cin >> s >> t; vector<ll> a[26]; unordered_map<char, ll> mp; rep(i, 0, 25) mp[alp[i]] = i; rep(i, 0, s.size() - 1) { a[mp[s[i]]].pb(i); } ll num = 0; ll now = 0; rep(i, 0, t.size() - 1) { if (a[mp[t[i]]].size() == 0) { cout << -1 << endl; return 0; } ll l = lower_bound(a[mp[t[i]]].begin(), a[mp[t[i]]].end(), now) - a[mp[t[i]]].begin(); if (l == a[mp[t[i]]].size()) { num++; now = a[mp[t[i]]][0] + 1; } else { now = a[mp[t[i]]][l] + 1; } // cout<<num<<' '<<now<<endl; } cout << num * s.size() + now << endl; return 0; }
[ "assignment.change" ]
739,583
739,584
u541784678
cpp
p02937
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; // const ll mod = 998244353; const ll MOD = 1000000007; const ll INF = 1LL << 60; #define PI (acos(-1)) #define ALL(c) (c).begin(), (c).end() #define en '\n' #define endl '\n' template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; // template <typename A, size_t N, typename T> template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; template <typename T> struct Combination { vector<T> _fact, _rfact, _inv; Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) { _fact[0] = _rfact[sz] = _inv[0] = 1; for (int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i; _rfact[sz] /= _fact[sz]; for (int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1); for (int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1]; } inline T fact(int k) const { return _fact[k]; } inline T rfact(int k) const { return _rfact[k]; } inline T inv(int k) const { return _inv[k]; } T P(int n, int r) const { if (r < 0 || n < r) return 0; return fact(n) * rfact(n - r); } T C(int p, int q) const { if (q < 0 || p < q) return 0; return fact(p) * rfact(q) * rfact(p - q); } T H(int n, int r) const { if (n < 0 || r < 0) return (0); return r == 0 ? 1 : C(n + r - 1, r); } T NC(int p, int q) const { modint ret = 1; for (int i = 1; i <= q; i += 1) { ret = ret * p / i; p--; } return ret; } }; ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } bool is_prime(ll x) { if (x == 1) { return false; } for (ll i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } map<ll, int> prime_factor(ll n) { map<ll, int> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } const ll MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; struct BIT { // 1-indexed!!! int n; vector<int> bit; BIT() { init(); } BIT(int n) : n(n) { init(); } void init() { bit.clear(); bit.resize(n + 1, 0); } int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } int sum(int x, int y) { return sum(y) - sum(x - 1); } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } int lower_bound(int w) { if (w <= 0) return 0; int x = 0, r = 1; while (r < n) r <<= 1; for (int k = r; k > 0; k >>= 1) { if (x + k <= n && bit[x + k] < w) { w -= bit[x + k]; x += k; } } return x + 1; } }; struct LazySegmentTree { // private: ll n; vector<ll> node, lazy; // public: LazySegmentTree(vector<ll> v) { int sz = (int)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1); lazy.resize(2 * n - 1, 0); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2]; } void eval(int k, int l, int r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r - l > 1) { lazy[2 * k + 1] += lazy[k] / 2; lazy[2 * k + 2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2 * k + 1, l, (l + r) / 2); add(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = node[2 * k + 1] + node[2 * k + 2]; } } ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return 0; if (a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; ll digit_sum(ll v) { ll ret = 0; while (v) { ret += (v % 10); v /= 10; } return ret; } template <typename T> struct Kruskal { struct edge { ll from, to; T cost; ll used; edge() {} edge(ll from, ll to, T cost) : from(from), to(to), cost(cost), used(0) {} bool operator<(const edge &e) const { return cost < e.cost; } }; ll n; vector<ll> p, r; vector<edge> edges; Kruskal() {} Kruskal(ll n) : n(n) {} void init(ll n) { r.assign(n, 1); p.resize(n); iota(p.begin(), p.end(), 0); } ll find(ll x) { return (x == p[x] ? x : p[x] = find(p[x])); } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) swap(x, y); r[x] += r[y]; p[y] = x; } void add_edge(ll u, ll v, T c) { edges.emplace_back(u, v, c); } T build() { sort(edges.begin(), edges.end()); init(n); T res = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; } } return res; } T build(ll k) { sort(edges.begin(), edges.end()); init(n); T res = 0; ll cnt = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; cnt++; } if (cnt == k) { break; } } return res; } }; int LIS(int a[], int n) { vector<int> A(n, 0x3f3f3f3f); for (int i = 0; i < n; i++) *lower_bound(A.begin(), A.end(), a[i]) = a[i]; return find(A.begin(), A.end(), 0x3f3f3f3f) - A.begin(); } // string maze[1010]; // //ll maze[100][100]; // ll grid_bfs(ll H, ll W, ll sx, ll sy, ll gx, ll gy) // { // //O(E) // int dx[4] = {1, 0, -1, 0}; // int dy[4] = {0, 1, 0, -1}; // vector<vector<ll>> dist(H, vector<ll>(W, -1)); // dist[sy][sx] = 0; // queue<PL> q; // q.push({sy, sx}); // while (!q.empty()) // { // ll x, y; // tie(y, x) = q.front(); // q.pop(); // if (y == gy && x == gx) // { // break; // } // for (int t = 0; t < 4; t++) // { // ll nx = x + dx[t], ny = y + dy[t]; // if (nx < 0 || ny < 0 || nx >= W || ny >= H || dist[ny][nx] != -1 // || maze[ny][nx] == '#') // { // continue; // } // dist[ny][nx] = dist[y][x] + 1; // q.push({ny, nx}); // } // } // return dist[gy][gx]; // } // no verify ll bfs(ll n, ll start, vector<vector<PL>> Edges) { vector<ll> dist(n + 1, -1); dist[start] = 0; queue<PL> q; q.push({start, 0}); while (!q.empty()) { ll node, cost; tie(cost, node) = q.front(); q.pop(); for (auto p : Edges[node]) { ll v = p.first, cost = p.second; if (dist[v] == -1) { dist[v] = dist[node] + cost; q.push({v, cost}); } } } } vector<vector<ll>> warshall_floyd(ll n, vector<vector<ll>> g, ll INF) { // init vector<vector<ll>> c(10,vector<ll>(10,0)); for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (g[i][k] == INF || g[k][j] == INF) continue; g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } return g; } struct Dijkstra { ll n; vector<vector<pair<ll, ll>>> Edges; vector<ll> Dist; vector<ll> Prev; vector<ll> PathNum; Dijkstra(ll n) : n(n), Edges(n), Dist(n), Prev(n), PathNum(n) { Prev.assign(n, -1); }; void add_edge(ll a, ll b, ll c, bool directed = true) { if (directed) { Edges[a].emplace_back(make_pair(b, c)); } else { Edges[a].emplace_back(make_pair(b, c)); Edges[b].emplace_back(make_pair(a, c)); } } // O((E+V)logV) void build(int start) { priority_queue<P, vector<P>, greater<P>> queue; fill(Dist.begin(), Dist.end(), 1e+18); // 1e18 !?!? fill(Prev.begin(), Prev.end(), -1); // 1e18 !?!? Dist[start] = 0; PathNum[start] = 1; queue.push(PL(0, start)); while (!queue.empty()) { PL p = queue.top(); queue.pop(); int v = p.second; if (Dist[v] < p.first) continue; for (int i = 0; i < Edges[v].size(); i++) { PL e = Edges[v][i]; if (Dist[e.first] > Dist[v] + e.second) { Dist[e.first] = Dist[v] + e.second; queue.push(P(Dist[e.first], e.first)); Prev[e.first] = v; PathNum[e.first] = PathNum[v]; } else if (Dist[e.first] == Dist[v] + e.second) { PathNum[e.first] += PathNum[v]; PathNum[e.first] %= MOD; } } } } ll dist(ll t) { return Dist[t]; } vector<ll> get_path(ll t) { vector<ll> path; for (; t != -1; t = Prev[t]) { path.push_back(t); } reverse(path.begin(), path.end()); return path; } ll get_path_num(ll t) { return PathNum[t]; } // int solve() // { // ll v, e, r; // cin >> v >> e >> r; // Dijkstra dij(v); // for (int i = 0; i < e; i++) // { // ll a, b, c; // cin >> a >> b >> c; // dij.add_edge(a, b, c); // } // dij.build(r); // for (int i = 0; i < v; i++) // { // if (dij.dist(i) == 1e18) // { // cout << "INF" << endl; // } // else // { // cout << dij.dist(i) << endl; // cout << dij.get_path(i) << endl; // cout << dij.get_path_num(i) << endl; // } // } // return 0; // } }; struct CumulativeSum2D { int H; int W; vector<vector<ll>> data; CumulativeSum2D(int H, int W) : H(H), W(W), data(H + 1, vector<ll>(W + 1, 0LL)) {} void add(int x, int y, ll z) { data[x + 1][y + 1] += z; } void build() { for (int i = 1; i < data.size(); i++) { for (int j = 1; j < data[i].size(); j++) { data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1]; } } } void print() { for (int i = 0; i <= H; i++) { for (int j = 0; j <= W; j++) { cout << data[i][j] << " "; } cout << endl; } } ll query(int sx, int sy, int gx, int gy) { return (data[gy][gx] - data[sy - 1][gx] - data[gy][sx - 1] + data[sy - 1][sx - 1]); } }; struct LCA { int n, h; vector<vector<int>> par; vector<vector<pair<int, int>>> v; vector<ll> depth, dis; LCA(int sz) : n(sz), v(n), depth(n), dis(n) { h = 1; while ((1 << h) < n) h++; par.assign(h, vector<int>(n, -1)); } void add_edge(int x, int y, int z) { v[x].push_back({y, z}); v[y].push_back({x, z}); } void dfs(int x, int p, int d, ll di) { par[0][x] = p; depth[x] = d; dis[x] = di; for (auto to : v[x]) if (to.first != p) dfs(to.first, x, d + 1, di + to.second); } void build() { dfs(0, -1, 0, 0); for (int i = 0; i < h - 1; i++) { for (int j = 0; j < n; j++) { if (par[i][j] < 0) par[i + 1][j] = -1; else par[i + 1][j] = par[i][par[i][j]]; } } } int lca(int u, int v) { if (depth[u] > depth[v]) swap(u, v); for (int i = 0; i < h; i++) if ((depth[v] - depth[u]) >> i & 1) v = par[i][v]; if (u == v) return u; for (int i = h - 1; i >= 0; i--) { if (par[i][u] != par[i][v]) { u = par[i][u]; v = par[i][v]; } } return par[0][u]; } ll dist(int u, int v) { return dis[u] + dis[v] - 2 * dis[lca(u, v)]; } // int solve() // { // ll n; // cin >> n; // LCA lca(n); // for (int i = 0; i < n - 1; i++) // { // ll u, v, w; // cin >> u >> v >> w; // lca.add_edge(u, v, w); // } // lca.build(); // ll q; // cin >> q; // while (q--) // { // ll a, b, c; // cin >> a >> b >> c; // cout << (lca.dist(a, b) + lca.dist(b, c) + lca.dist(c, a)) / 2 << // endl; // } // return 0; // } }; vector<ll> compress(vector<ll> r) { // 1-indexed set<ll> se; for (int i = 0; i < r.size(); i++) { se.insert(r[i]); } map<ll, ll> m; ll cnt = 1; for (auto t : se) { m[t] = cnt; cnt++; } for (int i = 0; i < r.size(); i++) { r[i] = m[r[i]]; } return r; } template <class Abel> struct WeightedUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; vector<int> z_algorithm(const string &s) { /* Z[i] は - 文字列 S=S[0]+S[1]+⋯+S[|S|−1] - 文字列 S[i]+S[i+1]+⋯+S[|S|−1] の最長共通接頭辞の長さ */ // https://qiita.com/Pro_ktmr/items/16904c9570aa0953bf05#1-z-algorithm-%E3%81%A7%E6%B1%82%E3%82%81%E3%82%8B-z-%E9%85%8D%E5%88%97%E3%81%A8%E3%81%AF vector<int> prefix(s.size()); for (int i = 1, j = 0; i < s.size(); i++) { if (i + prefix[i - j] < j + prefix[j]) { prefix[i] = prefix[i - j]; } else { int k = max(0, j + prefix[j] - i); while (i + k < s.size() && s[k] == s[i + k]) ++k; prefix[i] = k; j = i; } } prefix[0] = (int)s.size(); return prefix; } void YES() { cout << "YES" << endl; exit(0); } void NO() { cout << "NO" << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } void m1() { cout << -1 << endl; exit(0); } template <typename T> void out(const T t) { cout << t << '\n'; } template <typename T> void fout(const T t) { cout << fixed << setprecision(10) << t << '\n'; } /*------------------------------*/ void solve() { string s, t; cin >> s >> t; map<char, int> m; for (int i = 0; i < s.size(); i++) { m[s[i]] = 1; } for (int i = 0; i < t.size(); i++) { if (m[t[i]] == 0) { m1(); } } vector<int> next[26]; for (int i = 0; i < s.size(); i++) { next[s[i] - 'a'].push_back(i); // dbg(next[s[i] - 'a']); } int now = 0; // 0にするとsの一文字目を使えない(upperboundなので ll ans = 0; for (int i = 0; i < t.size(); i++) { auto index = upper_bound(ALL(next[t[i] - 'a']), now) - next[t[i] - 'a'].begin(); ll v = next[t[i] - 'a'][index]; if (index == next[t[i] - 'a'].size()) { v = next[t[i] - 'a'][0]; ans += (s.size() - now) + v; } else { ans += v - now; } // cout << now << " " << v << " " << ans << en; now = v; } out(ans + 1); } // g++.exe bbb.cpp -std=c++14 int main() { cout.precision(10); ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } // IMOSs//https://imoz.jp/algorithms/imos_method.html /*名前 accumulate(ALL(b),0LL) prev_permutation(ALL(v)) 辞書順で一個前の順列を構築する bitcount __builtin_popcountll 二次元累積和 CumulativeSum2D 10進数の桁和 digit_sum (b*b+c*c)**0.5 hypot cout << fixed << setprecision(10) << ans << endl; // 文字列t ->整数 atoi(t.c_str()); // 文字列t ->long long整数 stoll(t); ローカルではつかえない */ /* */ /* ********** 区間 ********** L=(1,0,1,1,3,4) C(1,3,0,1,1) 配列Lの中で x 以上 y 未満の値が何個あるのかが、累積和を使うとわかる。 具体的には C の累積和を S とすると、S[ y ] - S[ x ] で求められる ********** 木 ********** */ /*実装例 zaatu sort(ALL(c)); c.erase(unique(ALL(c)), end(c)); ******* 再帰 ******* https://atcoder.jp/contests/abc015/tasks/abc015_3 ********** DP ********** ・ナップサックDP https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_C 個数制限なしナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_B 01ナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_F 01ナップサック N<=100,W<=10^9,v<=100 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_H 巨大ナップザック N=40 w<10^15 , v<10^15 解)半分全列挙して、wi > wj かつvi < vj となるようなiを除いて、二分探索 ・部分文字列DP https://qiita.com/drken/items/a207e5ae3ea2cf17f4bd next[i][c] := S の i 文字目以降で最初に文字 c が登場する index https://www.hackerrank.com/contests/bbc003/challenges/bbc003-e/submissions/code/1321355726 (部分文字列の中で+の個数の偶奇によって、カウントするか決める) No.852 連続部分文字列 https://yukicoder.me/problems/no/852/editorial 連続な部分文字列における、文字の種類数の平均を求める 解)右端を固定すると dp[i+1] = dp[i] + (左にs[i]がでてきた位置との距離) E - Common Subsequence https://atcoder.jp/contests/abc130/tasks/abc130_e 文字列S、Tの共通整数列の数を求める 遷移はLCSのようにできるが、重複が発生するので除く必要がある ・桁DP 1 https://atcoder.jp/contests/abc029/tasks/abc029_d n以下の数字の中で現れた1の数を求める dp[i][j][k]:i桁目まで見たときに1の個数がk個の数字の個数 S - Digit Sum https://atcoder.jp/contests/dp/tasks/dp_s n以下の数字の中で、各桁の総和がDの倍数となるものを数える E - Almost Everywhere Zero https://atcoder.jp/contests/abc154/tasks/abc154_e n以下の数字の中で,0でない数字が丁度K個あるものの数を数える E - Sum Equals Xor https://atcoder.jp/contests/abc129/tasks/abc129_e a+b<=L,a+b=a^bとなる(a,b)を数える ************* 組み合わせ ************* https://codeforces.com/contest/888/problem/D 少なくともn-k個がpi=iとなるような順列の組の数え上げ →pi≠iとなる順列をモンモール数という。n-k~n個をpi=iと固定したときに、他の要素がpi≠iとなるような組み合わせの数(モンモール数)の積をとる https://codeforces.com/problemset/problem/322/B 赤・青・緑の花束が存在し、ある色を3本or全ての色を1本ずつ使ったときに、できる花束の最大数 https://atcoder.jp/contests/abc021/tasks/abc021_d https://codeforces.com/problemset/problem/1288/C 1 <=a1 <= a2 <= ... <= ak <= n となる(a1,a2..ak)の組の数 →等号がなければ単純にn個の要素の中からk個を選べばよい -> C(n,k) →等号がある場合は重複を許してk個選べばよい      -> H(n,k) http://codeforces.com/contest/1312/problem/D aj < aj+i < ... ai > ....ak > ak+1 かつ同じ数字のペアが一つだけ含まれるような組の数 D - Blue and Red Balls https://atcoder.jp/contests/abc132/tasks/abc132_d 青と赤のボールを並べ、連続している青を1~k個作ったときの並べ方の数 ************* 最短経路 ************* https://atcoder.jp/contests/joi2014yo/tasks/joi2014yo_e 移動できるノード数に制限がある場合の最短経路問題 →事前に幅優先探索でノード毎に移動できるノードを求めて、ダイクストラ ************* 遅延セグ木 ************* https://atcoder.jp/contests/abc153/submissions/10165699 *********** BIT *********** https://atcoder.jp/contests/abc157/tasks/abc157_e(アルファベット毎にBITもつやつ) https://hoj.hamako-ths.ed.jp/onlinejudge/problems/1276(中央値求めるやつ) *********** 数学 *********** 大きい数の約数 https://yukicoder.me/problems/no/677 10^nの全ての正の約数を列挙 →10^kは素因数として2^k,5^kしかもたないので、それぞれをかけ合わせる 例えば10は2^1*5*1なので、2^0,2^1に5^0,5^1をそれぞれかけ合わせればよい。 */
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; // const ll mod = 998244353; const ll MOD = 1000000007; const ll INF = 1LL << 60; #define PI (acos(-1)) #define ALL(c) (c).begin(), (c).end() #define en '\n' #define endl '\n' template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; // template <typename A, size_t N, typename T> template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; template <typename T> struct Combination { vector<T> _fact, _rfact, _inv; Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) { _fact[0] = _rfact[sz] = _inv[0] = 1; for (int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i; _rfact[sz] /= _fact[sz]; for (int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1); for (int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1]; } inline T fact(int k) const { return _fact[k]; } inline T rfact(int k) const { return _rfact[k]; } inline T inv(int k) const { return _inv[k]; } T P(int n, int r) const { if (r < 0 || n < r) return 0; return fact(n) * rfact(n - r); } T C(int p, int q) const { if (q < 0 || p < q) return 0; return fact(p) * rfact(q) * rfact(p - q); } T H(int n, int r) const { if (n < 0 || r < 0) return (0); return r == 0 ? 1 : C(n + r - 1, r); } T NC(int p, int q) const { modint ret = 1; for (int i = 1; i <= q; i += 1) { ret = ret * p / i; p--; } return ret; } }; ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } bool is_prime(ll x) { if (x == 1) { return false; } for (ll i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } map<ll, int> prime_factor(ll n) { map<ll, int> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } const ll MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; struct BIT { // 1-indexed!!! int n; vector<int> bit; BIT() { init(); } BIT(int n) : n(n) { init(); } void init() { bit.clear(); bit.resize(n + 1, 0); } int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } int sum(int x, int y) { return sum(y) - sum(x - 1); } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } int lower_bound(int w) { if (w <= 0) return 0; int x = 0, r = 1; while (r < n) r <<= 1; for (int k = r; k > 0; k >>= 1) { if (x + k <= n && bit[x + k] < w) { w -= bit[x + k]; x += k; } } return x + 1; } }; struct LazySegmentTree { // private: ll n; vector<ll> node, lazy; // public: LazySegmentTree(vector<ll> v) { int sz = (int)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1); lazy.resize(2 * n - 1, 0); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2]; } void eval(int k, int l, int r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r - l > 1) { lazy[2 * k + 1] += lazy[k] / 2; lazy[2 * k + 2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2 * k + 1, l, (l + r) / 2); add(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = node[2 * k + 1] + node[2 * k + 2]; } } ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return 0; if (a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; ll digit_sum(ll v) { ll ret = 0; while (v) { ret += (v % 10); v /= 10; } return ret; } template <typename T> struct Kruskal { struct edge { ll from, to; T cost; ll used; edge() {} edge(ll from, ll to, T cost) : from(from), to(to), cost(cost), used(0) {} bool operator<(const edge &e) const { return cost < e.cost; } }; ll n; vector<ll> p, r; vector<edge> edges; Kruskal() {} Kruskal(ll n) : n(n) {} void init(ll n) { r.assign(n, 1); p.resize(n); iota(p.begin(), p.end(), 0); } ll find(ll x) { return (x == p[x] ? x : p[x] = find(p[x])); } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) swap(x, y); r[x] += r[y]; p[y] = x; } void add_edge(ll u, ll v, T c) { edges.emplace_back(u, v, c); } T build() { sort(edges.begin(), edges.end()); init(n); T res = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; } } return res; } T build(ll k) { sort(edges.begin(), edges.end()); init(n); T res = 0; ll cnt = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; cnt++; } if (cnt == k) { break; } } return res; } }; int LIS(int a[], int n) { vector<int> A(n, 0x3f3f3f3f); for (int i = 0; i < n; i++) *lower_bound(A.begin(), A.end(), a[i]) = a[i]; return find(A.begin(), A.end(), 0x3f3f3f3f) - A.begin(); } // string maze[1010]; // //ll maze[100][100]; // ll grid_bfs(ll H, ll W, ll sx, ll sy, ll gx, ll gy) // { // //O(E) // int dx[4] = {1, 0, -1, 0}; // int dy[4] = {0, 1, 0, -1}; // vector<vector<ll>> dist(H, vector<ll>(W, -1)); // dist[sy][sx] = 0; // queue<PL> q; // q.push({sy, sx}); // while (!q.empty()) // { // ll x, y; // tie(y, x) = q.front(); // q.pop(); // if (y == gy && x == gx) // { // break; // } // for (int t = 0; t < 4; t++) // { // ll nx = x + dx[t], ny = y + dy[t]; // if (nx < 0 || ny < 0 || nx >= W || ny >= H || dist[ny][nx] != -1 // || maze[ny][nx] == '#') // { // continue; // } // dist[ny][nx] = dist[y][x] + 1; // q.push({ny, nx}); // } // } // return dist[gy][gx]; // } // no verify ll bfs(ll n, ll start, vector<vector<PL>> Edges) { vector<ll> dist(n + 1, -1); dist[start] = 0; queue<PL> q; q.push({start, 0}); while (!q.empty()) { ll node, cost; tie(cost, node) = q.front(); q.pop(); for (auto p : Edges[node]) { ll v = p.first, cost = p.second; if (dist[v] == -1) { dist[v] = dist[node] + cost; q.push({v, cost}); } } } } vector<vector<ll>> warshall_floyd(ll n, vector<vector<ll>> g, ll INF) { // init vector<vector<ll>> c(10,vector<ll>(10,0)); for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (g[i][k] == INF || g[k][j] == INF) continue; g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } return g; } struct Dijkstra { ll n; vector<vector<pair<ll, ll>>> Edges; vector<ll> Dist; vector<ll> Prev; vector<ll> PathNum; Dijkstra(ll n) : n(n), Edges(n), Dist(n), Prev(n), PathNum(n) { Prev.assign(n, -1); }; void add_edge(ll a, ll b, ll c, bool directed = true) { if (directed) { Edges[a].emplace_back(make_pair(b, c)); } else { Edges[a].emplace_back(make_pair(b, c)); Edges[b].emplace_back(make_pair(a, c)); } } // O((E+V)logV) void build(int start) { priority_queue<P, vector<P>, greater<P>> queue; fill(Dist.begin(), Dist.end(), 1e+18); // 1e18 !?!? fill(Prev.begin(), Prev.end(), -1); // 1e18 !?!? Dist[start] = 0; PathNum[start] = 1; queue.push(PL(0, start)); while (!queue.empty()) { PL p = queue.top(); queue.pop(); int v = p.second; if (Dist[v] < p.first) continue; for (int i = 0; i < Edges[v].size(); i++) { PL e = Edges[v][i]; if (Dist[e.first] > Dist[v] + e.second) { Dist[e.first] = Dist[v] + e.second; queue.push(P(Dist[e.first], e.first)); Prev[e.first] = v; PathNum[e.first] = PathNum[v]; } else if (Dist[e.first] == Dist[v] + e.second) { PathNum[e.first] += PathNum[v]; PathNum[e.first] %= MOD; } } } } ll dist(ll t) { return Dist[t]; } vector<ll> get_path(ll t) { vector<ll> path; for (; t != -1; t = Prev[t]) { path.push_back(t); } reverse(path.begin(), path.end()); return path; } ll get_path_num(ll t) { return PathNum[t]; } // int solve() // { // ll v, e, r; // cin >> v >> e >> r; // Dijkstra dij(v); // for (int i = 0; i < e; i++) // { // ll a, b, c; // cin >> a >> b >> c; // dij.add_edge(a, b, c); // } // dij.build(r); // for (int i = 0; i < v; i++) // { // if (dij.dist(i) == 1e18) // { // cout << "INF" << endl; // } // else // { // cout << dij.dist(i) << endl; // cout << dij.get_path(i) << endl; // cout << dij.get_path_num(i) << endl; // } // } // return 0; // } }; struct CumulativeSum2D { int H; int W; vector<vector<ll>> data; CumulativeSum2D(int H, int W) : H(H), W(W), data(H + 1, vector<ll>(W + 1, 0LL)) {} void add(int x, int y, ll z) { data[x + 1][y + 1] += z; } void build() { for (int i = 1; i < data.size(); i++) { for (int j = 1; j < data[i].size(); j++) { data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1]; } } } void print() { for (int i = 0; i <= H; i++) { for (int j = 0; j <= W; j++) { cout << data[i][j] << " "; } cout << endl; } } ll query(int sx, int sy, int gx, int gy) { return (data[gy][gx] - data[sy - 1][gx] - data[gy][sx - 1] + data[sy - 1][sx - 1]); } }; struct LCA { int n, h; vector<vector<int>> par; vector<vector<pair<int, int>>> v; vector<ll> depth, dis; LCA(int sz) : n(sz), v(n), depth(n), dis(n) { h = 1; while ((1 << h) < n) h++; par.assign(h, vector<int>(n, -1)); } void add_edge(int x, int y, int z) { v[x].push_back({y, z}); v[y].push_back({x, z}); } void dfs(int x, int p, int d, ll di) { par[0][x] = p; depth[x] = d; dis[x] = di; for (auto to : v[x]) if (to.first != p) dfs(to.first, x, d + 1, di + to.second); } void build() { dfs(0, -1, 0, 0); for (int i = 0; i < h - 1; i++) { for (int j = 0; j < n; j++) { if (par[i][j] < 0) par[i + 1][j] = -1; else par[i + 1][j] = par[i][par[i][j]]; } } } int lca(int u, int v) { if (depth[u] > depth[v]) swap(u, v); for (int i = 0; i < h; i++) if ((depth[v] - depth[u]) >> i & 1) v = par[i][v]; if (u == v) return u; for (int i = h - 1; i >= 0; i--) { if (par[i][u] != par[i][v]) { u = par[i][u]; v = par[i][v]; } } return par[0][u]; } ll dist(int u, int v) { return dis[u] + dis[v] - 2 * dis[lca(u, v)]; } // int solve() // { // ll n; // cin >> n; // LCA lca(n); // for (int i = 0; i < n - 1; i++) // { // ll u, v, w; // cin >> u >> v >> w; // lca.add_edge(u, v, w); // } // lca.build(); // ll q; // cin >> q; // while (q--) // { // ll a, b, c; // cin >> a >> b >> c; // cout << (lca.dist(a, b) + lca.dist(b, c) + lca.dist(c, a)) / 2 << // endl; // } // return 0; // } }; vector<ll> compress(vector<ll> r) { // 1-indexed set<ll> se; for (int i = 0; i < r.size(); i++) { se.insert(r[i]); } map<ll, ll> m; ll cnt = 1; for (auto t : se) { m[t] = cnt; cnt++; } for (int i = 0; i < r.size(); i++) { r[i] = m[r[i]]; } return r; } template <class Abel> struct WeightedUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; vector<int> z_algorithm(const string &s) { /* Z[i] は - 文字列 S=S[0]+S[1]+⋯+S[|S|−1] - 文字列 S[i]+S[i+1]+⋯+S[|S|−1] の最長共通接頭辞の長さ */ // https://qiita.com/Pro_ktmr/items/16904c9570aa0953bf05#1-z-algorithm-%E3%81%A7%E6%B1%82%E3%82%81%E3%82%8B-z-%E9%85%8D%E5%88%97%E3%81%A8%E3%81%AF vector<int> prefix(s.size()); for (int i = 1, j = 0; i < s.size(); i++) { if (i + prefix[i - j] < j + prefix[j]) { prefix[i] = prefix[i - j]; } else { int k = max(0, j + prefix[j] - i); while (i + k < s.size() && s[k] == s[i + k]) ++k; prefix[i] = k; j = i; } } prefix[0] = (int)s.size(); return prefix; } void YES() { cout << "YES" << endl; exit(0); } void NO() { cout << "NO" << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } void m1() { cout << -1 << endl; exit(0); } template <typename T> void out(const T t) { cout << t << '\n'; } template <typename T> void fout(const T t) { cout << fixed << setprecision(10) << t << '\n'; } /*------------------------------*/ void solve() { string s, t; cin >> s >> t; map<char, int> m; for (int i = 0; i < s.size(); i++) { m[s[i]] = 1; } for (int i = 0; i < t.size(); i++) { if (m[t[i]] == 0) { m1(); } } vector<int> next[26]; for (int i = 0; i < s.size(); i++) { next[s[i] - 'a'].push_back(i); // dbg(next[s[i] - 'a']); } int now = -1; ll ans = 0; for (int i = 0; i < t.size(); i++) { auto index = upper_bound(ALL(next[t[i] - 'a']), now) - next[t[i] - 'a'].begin(); ll v = next[t[i] - 'a'][index]; if (index == next[t[i] - 'a'].size()) { v = next[t[i] - 'a'][0]; ans += (s.size() - now) + v; } else { ans += v - now; } now = v; } out(ans); } // g++.exe bbb.cpp -std=c++14 int main() { cout.precision(10); ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } // IMOSs//https://imoz.jp/algorithms/imos_method.html /*名前 accumulate(ALL(b),0LL) prev_permutation(ALL(v)) 辞書順で一個前の順列を構築する bitcount __builtin_popcountll 二次元累積和 CumulativeSum2D 10進数の桁和 digit_sum (b*b+c*c)**0.5 hypot cout << fixed << setprecision(10) << ans << endl; // 文字列t ->整数 atoi(t.c_str()); // 文字列t ->long long整数 stoll(t); ローカルではつかえない */ /* */ /* ********** 区間 ********** L=(1,0,1,1,3,4) C(1,3,0,1,1) 配列Lの中で x 以上 y 未満の値が何個あるのかが、累積和を使うとわかる。 具体的には C の累積和を S とすると、S[ y ] - S[ x ] で求められる ********** 木 ********** */ /*実装例 zaatu sort(ALL(c)); c.erase(unique(ALL(c)), end(c)); ******* 再帰 ******* https://atcoder.jp/contests/abc015/tasks/abc015_3 ********** DP ********** ・ナップサックDP https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_C 個数制限なしナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_B 01ナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_F 01ナップサック N<=100,W<=10^9,v<=100 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_H 巨大ナップザック N=40 w<10^15 , v<10^15 解)半分全列挙して、wi > wj かつvi < vj となるようなiを除いて、二分探索 ・部分文字列DP https://qiita.com/drken/items/a207e5ae3ea2cf17f4bd next[i][c] := S の i 文字目以降で最初に文字 c が登場する index https://www.hackerrank.com/contests/bbc003/challenges/bbc003-e/submissions/code/1321355726 (部分文字列の中で+の個数の偶奇によって、カウントするか決める) No.852 連続部分文字列 https://yukicoder.me/problems/no/852/editorial 連続な部分文字列における、文字の種類数の平均を求める 解)右端を固定すると dp[i+1] = dp[i] + (左にs[i]がでてきた位置との距離) E - Common Subsequence https://atcoder.jp/contests/abc130/tasks/abc130_e 文字列S、Tの共通整数列の数を求める 遷移はLCSのようにできるが、重複が発生するので除く必要がある ・桁DP 1 https://atcoder.jp/contests/abc029/tasks/abc029_d n以下の数字の中で現れた1の数を求める dp[i][j][k]:i桁目まで見たときに1の個数がk個の数字の個数 S - Digit Sum https://atcoder.jp/contests/dp/tasks/dp_s n以下の数字の中で、各桁の総和がDの倍数となるものを数える E - Almost Everywhere Zero https://atcoder.jp/contests/abc154/tasks/abc154_e n以下の数字の中で,0でない数字が丁度K個あるものの数を数える E - Sum Equals Xor https://atcoder.jp/contests/abc129/tasks/abc129_e a+b<=L,a+b=a^bとなる(a,b)を数える ************* 組み合わせ ************* https://codeforces.com/contest/888/problem/D 少なくともn-k個がpi=iとなるような順列の組の数え上げ →pi≠iとなる順列をモンモール数という。n-k~n個をpi=iと固定したときに、他の要素がpi≠iとなるような組み合わせの数(モンモール数)の積をとる https://codeforces.com/problemset/problem/322/B 赤・青・緑の花束が存在し、ある色を3本or全ての色を1本ずつ使ったときに、できる花束の最大数 https://atcoder.jp/contests/abc021/tasks/abc021_d https://codeforces.com/problemset/problem/1288/C 1 <=a1 <= a2 <= ... <= ak <= n となる(a1,a2..ak)の組の数 →等号がなければ単純にn個の要素の中からk個を選べばよい -> C(n,k) →等号がある場合は重複を許してk個選べばよい      -> H(n,k) http://codeforces.com/contest/1312/problem/D aj < aj+i < ... ai > ....ak > ak+1 かつ同じ数字のペアが一つだけ含まれるような組の数 D - Blue and Red Balls https://atcoder.jp/contests/abc132/tasks/abc132_d 青と赤のボールを並べ、連続している青を1~k個作ったときの並べ方の数 ************* 最短経路 ************* https://atcoder.jp/contests/joi2014yo/tasks/joi2014yo_e 移動できるノード数に制限がある場合の最短経路問題 →事前に幅優先探索でノード毎に移動できるノードを求めて、ダイクストラ ************* 遅延セグ木 ************* https://atcoder.jp/contests/abc153/submissions/10165699 *********** BIT *********** https://atcoder.jp/contests/abc157/tasks/abc157_e(アルファベット毎にBITもつやつ) https://hoj.hamako-ths.ed.jp/onlinejudge/problems/1276(中央値求めるやつ) *********** 数学 *********** 大きい数の約数 https://yukicoder.me/problems/no/677 10^nの全ての正の約数を列挙 →10^kは素因数として2^k,5^kしかもたないので、それぞれをかけ合わせる 例えば10は2^1*5*1なので、2^0,2^1に5^0,5^1をそれぞれかけ合わせればよい。 */
[ "literal.number.change", "variable_declaration.value.change", "expression.operation.binary.remove" ]
739,587
739,588
u644778646
cpp
p02937
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; // const ll mod = 998244353; const ll MOD = 1000000007; const ll INF = 1LL << 60; #define PI (acos(-1)) #define ALL(c) (c).begin(), (c).end() #define en '\n' #define endl '\n' template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; // template <typename A, size_t N, typename T> template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; template <typename T> struct Combination { vector<T> _fact, _rfact, _inv; Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) { _fact[0] = _rfact[sz] = _inv[0] = 1; for (int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i; _rfact[sz] /= _fact[sz]; for (int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1); for (int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1]; } inline T fact(int k) const { return _fact[k]; } inline T rfact(int k) const { return _rfact[k]; } inline T inv(int k) const { return _inv[k]; } T P(int n, int r) const { if (r < 0 || n < r) return 0; return fact(n) * rfact(n - r); } T C(int p, int q) const { if (q < 0 || p < q) return 0; return fact(p) * rfact(q) * rfact(p - q); } T H(int n, int r) const { if (n < 0 || r < 0) return (0); return r == 0 ? 1 : C(n + r - 1, r); } T NC(int p, int q) const { modint ret = 1; for (int i = 1; i <= q; i += 1) { ret = ret * p / i; p--; } return ret; } }; ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } bool is_prime(ll x) { if (x == 1) { return false; } for (ll i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } map<ll, int> prime_factor(ll n) { map<ll, int> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } const ll MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; struct BIT { // 1-indexed!!! int n; vector<int> bit; BIT() { init(); } BIT(int n) : n(n) { init(); } void init() { bit.clear(); bit.resize(n + 1, 0); } int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } int sum(int x, int y) { return sum(y) - sum(x - 1); } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } int lower_bound(int w) { if (w <= 0) return 0; int x = 0, r = 1; while (r < n) r <<= 1; for (int k = r; k > 0; k >>= 1) { if (x + k <= n && bit[x + k] < w) { w -= bit[x + k]; x += k; } } return x + 1; } }; struct LazySegmentTree { // private: ll n; vector<ll> node, lazy; // public: LazySegmentTree(vector<ll> v) { int sz = (int)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1); lazy.resize(2 * n - 1, 0); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2]; } void eval(int k, int l, int r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r - l > 1) { lazy[2 * k + 1] += lazy[k] / 2; lazy[2 * k + 2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2 * k + 1, l, (l + r) / 2); add(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = node[2 * k + 1] + node[2 * k + 2]; } } ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return 0; if (a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; ll digit_sum(ll v) { ll ret = 0; while (v) { ret += (v % 10); v /= 10; } return ret; } template <typename T> struct Kruskal { struct edge { ll from, to; T cost; ll used; edge() {} edge(ll from, ll to, T cost) : from(from), to(to), cost(cost), used(0) {} bool operator<(const edge &e) const { return cost < e.cost; } }; ll n; vector<ll> p, r; vector<edge> edges; Kruskal() {} Kruskal(ll n) : n(n) {} void init(ll n) { r.assign(n, 1); p.resize(n); iota(p.begin(), p.end(), 0); } ll find(ll x) { return (x == p[x] ? x : p[x] = find(p[x])); } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) swap(x, y); r[x] += r[y]; p[y] = x; } void add_edge(ll u, ll v, T c) { edges.emplace_back(u, v, c); } T build() { sort(edges.begin(), edges.end()); init(n); T res = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; } } return res; } T build(ll k) { sort(edges.begin(), edges.end()); init(n); T res = 0; ll cnt = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; cnt++; } if (cnt == k) { break; } } return res; } }; int LIS(int a[], int n) { vector<int> A(n, 0x3f3f3f3f); for (int i = 0; i < n; i++) *lower_bound(A.begin(), A.end(), a[i]) = a[i]; return find(A.begin(), A.end(), 0x3f3f3f3f) - A.begin(); } // string maze[1010]; // //ll maze[100][100]; // ll grid_bfs(ll H, ll W, ll sx, ll sy, ll gx, ll gy) // { // //O(E) // int dx[4] = {1, 0, -1, 0}; // int dy[4] = {0, 1, 0, -1}; // vector<vector<ll>> dist(H, vector<ll>(W, -1)); // dist[sy][sx] = 0; // queue<PL> q; // q.push({sy, sx}); // while (!q.empty()) // { // ll x, y; // tie(y, x) = q.front(); // q.pop(); // if (y == gy && x == gx) // { // break; // } // for (int t = 0; t < 4; t++) // { // ll nx = x + dx[t], ny = y + dy[t]; // if (nx < 0 || ny < 0 || nx >= W || ny >= H || dist[ny][nx] != -1 // || maze[ny][nx] == '#') // { // continue; // } // dist[ny][nx] = dist[y][x] + 1; // q.push({ny, nx}); // } // } // return dist[gy][gx]; // } // no verify ll bfs(ll n, ll start, vector<vector<PL>> Edges) { vector<ll> dist(n + 1, -1); dist[start] = 0; queue<PL> q; q.push({start, 0}); while (!q.empty()) { ll node, cost; tie(cost, node) = q.front(); q.pop(); for (auto p : Edges[node]) { ll v = p.first, cost = p.second; if (dist[v] == -1) { dist[v] = dist[node] + cost; q.push({v, cost}); } } } } vector<vector<ll>> warshall_floyd(ll n, vector<vector<ll>> g, ll INF) { // init vector<vector<ll>> c(10,vector<ll>(10,0)); for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (g[i][k] == INF || g[k][j] == INF) continue; g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } return g; } struct Dijkstra { ll n; vector<vector<pair<ll, ll>>> Edges; vector<ll> Dist; vector<ll> Prev; vector<ll> PathNum; Dijkstra(ll n) : n(n), Edges(n), Dist(n), Prev(n), PathNum(n) { Prev.assign(n, -1); }; void add_edge(ll a, ll b, ll c, bool directed = true) { if (directed) { Edges[a].emplace_back(make_pair(b, c)); } else { Edges[a].emplace_back(make_pair(b, c)); Edges[b].emplace_back(make_pair(a, c)); } } // O((E+V)logV) void build(int start) { priority_queue<P, vector<P>, greater<P>> queue; fill(Dist.begin(), Dist.end(), 1e+18); // 1e18 !?!? fill(Prev.begin(), Prev.end(), -1); // 1e18 !?!? Dist[start] = 0; PathNum[start] = 1; queue.push(PL(0, start)); while (!queue.empty()) { PL p = queue.top(); queue.pop(); int v = p.second; if (Dist[v] < p.first) continue; for (int i = 0; i < Edges[v].size(); i++) { PL e = Edges[v][i]; if (Dist[e.first] > Dist[v] + e.second) { Dist[e.first] = Dist[v] + e.second; queue.push(P(Dist[e.first], e.first)); Prev[e.first] = v; PathNum[e.first] = PathNum[v]; } else if (Dist[e.first] == Dist[v] + e.second) { PathNum[e.first] += PathNum[v]; PathNum[e.first] %= MOD; } } } } ll dist(ll t) { return Dist[t]; } vector<ll> get_path(ll t) { vector<ll> path; for (; t != -1; t = Prev[t]) { path.push_back(t); } reverse(path.begin(), path.end()); return path; } ll get_path_num(ll t) { return PathNum[t]; } // int solve() // { // ll v, e, r; // cin >> v >> e >> r; // Dijkstra dij(v); // for (int i = 0; i < e; i++) // { // ll a, b, c; // cin >> a >> b >> c; // dij.add_edge(a, b, c); // } // dij.build(r); // for (int i = 0; i < v; i++) // { // if (dij.dist(i) == 1e18) // { // cout << "INF" << endl; // } // else // { // cout << dij.dist(i) << endl; // cout << dij.get_path(i) << endl; // cout << dij.get_path_num(i) << endl; // } // } // return 0; // } }; struct CumulativeSum2D { int H; int W; vector<vector<ll>> data; CumulativeSum2D(int H, int W) : H(H), W(W), data(H + 1, vector<ll>(W + 1, 0LL)) {} void add(int x, int y, ll z) { data[x + 1][y + 1] += z; } void build() { for (int i = 1; i < data.size(); i++) { for (int j = 1; j < data[i].size(); j++) { data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1]; } } } void print() { for (int i = 0; i <= H; i++) { for (int j = 0; j <= W; j++) { cout << data[i][j] << " "; } cout << endl; } } ll query(int sx, int sy, int gx, int gy) { return (data[gy][gx] - data[sy - 1][gx] - data[gy][sx - 1] + data[sy - 1][sx - 1]); } }; struct LCA { int n, h; vector<vector<int>> par; vector<vector<pair<int, int>>> v; vector<ll> depth, dis; LCA(int sz) : n(sz), v(n), depth(n), dis(n) { h = 1; while ((1 << h) < n) h++; par.assign(h, vector<int>(n, -1)); } void add_edge(int x, int y, int z) { v[x].push_back({y, z}); v[y].push_back({x, z}); } void dfs(int x, int p, int d, ll di) { par[0][x] = p; depth[x] = d; dis[x] = di; for (auto to : v[x]) if (to.first != p) dfs(to.first, x, d + 1, di + to.second); } void build() { dfs(0, -1, 0, 0); for (int i = 0; i < h - 1; i++) { for (int j = 0; j < n; j++) { if (par[i][j] < 0) par[i + 1][j] = -1; else par[i + 1][j] = par[i][par[i][j]]; } } } int lca(int u, int v) { if (depth[u] > depth[v]) swap(u, v); for (int i = 0; i < h; i++) if ((depth[v] - depth[u]) >> i & 1) v = par[i][v]; if (u == v) return u; for (int i = h - 1; i >= 0; i--) { if (par[i][u] != par[i][v]) { u = par[i][u]; v = par[i][v]; } } return par[0][u]; } ll dist(int u, int v) { return dis[u] + dis[v] - 2 * dis[lca(u, v)]; } // int solve() // { // ll n; // cin >> n; // LCA lca(n); // for (int i = 0; i < n - 1; i++) // { // ll u, v, w; // cin >> u >> v >> w; // lca.add_edge(u, v, w); // } // lca.build(); // ll q; // cin >> q; // while (q--) // { // ll a, b, c; // cin >> a >> b >> c; // cout << (lca.dist(a, b) + lca.dist(b, c) + lca.dist(c, a)) / 2 << // endl; // } // return 0; // } }; vector<ll> compress(vector<ll> r) { // 1-indexed set<ll> se; for (int i = 0; i < r.size(); i++) { se.insert(r[i]); } map<ll, ll> m; ll cnt = 1; for (auto t : se) { m[t] = cnt; cnt++; } for (int i = 0; i < r.size(); i++) { r[i] = m[r[i]]; } return r; } template <class Abel> struct WeightedUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; vector<int> z_algorithm(const string &s) { /* Z[i] は - 文字列 S=S[0]+S[1]+⋯+S[|S|−1] - 文字列 S[i]+S[i+1]+⋯+S[|S|−1] の最長共通接頭辞の長さ */ // https://qiita.com/Pro_ktmr/items/16904c9570aa0953bf05#1-z-algorithm-%E3%81%A7%E6%B1%82%E3%82%81%E3%82%8B-z-%E9%85%8D%E5%88%97%E3%81%A8%E3%81%AF vector<int> prefix(s.size()); for (int i = 1, j = 0; i < s.size(); i++) { if (i + prefix[i - j] < j + prefix[j]) { prefix[i] = prefix[i - j]; } else { int k = max(0, j + prefix[j] - i); while (i + k < s.size() && s[k] == s[i + k]) ++k; prefix[i] = k; j = i; } } prefix[0] = (int)s.size(); return prefix; } void YES() { cout << "YES" << endl; exit(0); } void NO() { cout << "NO" << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } void m1() { cout << -1 << endl; exit(0); } template <typename T> void out(const T t) { cout << t << '\n'; } template <typename T> void fout(const T t) { cout << fixed << setprecision(10) << t << '\n'; } /*------------------------------*/ void solve() { string s, t; cin >> s >> t; map<char, int> m; for (int i = 0; i < s.size(); i++) { m[s[i]] = 1; } for (int i = 0; i < t.size(); i++) { if (m[t[i]] == 0) { m1(); } } vector<ll> next[26]; for (int i = 0; i < s.size(); i++) { next[s[i] - 'a'].push_back(i); } ll now = -1; ll ans = 0; for (int i = 0; i < t.size(); i++) { ll index = lower_bound(ALL(next[t[i] - 'a']), now) - next[t[i] - 'a'].begin(); ll v = next[t[i] - 'a'][index]; if (index == next[t[i] - 'a'].size()) { // index = lower_bound(ALL(next[t[i] - 'a']), -1) - next[t[i] - // 'a'].begin(); v = next[t[i] - 'a'][0]; ans += (s.size() - now) + v; } else { ans += v - now; } now = v; } out(ans); } // g++.exe bbb.cpp -std=c++14 int main() { cout.precision(10); ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } // IMOSs//https://imoz.jp/algorithms/imos_method.html /*名前 accumulate(ALL(b),0LL) prev_permutation(ALL(v)) 辞書順で一個前の順列を構築する bitcount __builtin_popcountll 二次元累積和 CumulativeSum2D 10進数の桁和 digit_sum (b*b+c*c)**0.5 hypot cout << fixed << setprecision(10) << ans << endl; // 文字列t ->整数 atoi(t.c_str()); // 文字列t ->long long整数 stoll(t); ローカルではつかえない */ /* */ /* ********** 区間 ********** L=(1,0,1,1,3,4) C(1,3,0,1,1) 配列Lの中で x 以上 y 未満の値が何個あるのかが、累積和を使うとわかる。 具体的には C の累積和を S とすると、S[ y ] - S[ x ] で求められる ********** 木 ********** */ /*実装例 zaatu sort(ALL(c)); c.erase(unique(ALL(c)), end(c)); ******* 再帰 ******* https://atcoder.jp/contests/abc015/tasks/abc015_3 ********** DP ********** ・ナップサックDP https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_C 個数制限なしナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_B 01ナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_F 01ナップサック N<=100,W<=10^9,v<=100 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_H 巨大ナップザック N=40 w<10^15 , v<10^15 解)半分全列挙して、wi > wj かつvi < vj となるようなiを除いて、二分探索 ・部分文字列DP https://qiita.com/drken/items/a207e5ae3ea2cf17f4bd next[i][c] := S の i 文字目以降で最初に文字 c が登場する index https://www.hackerrank.com/contests/bbc003/challenges/bbc003-e/submissions/code/1321355726 (部分文字列の中で+の個数の偶奇によって、カウントするか決める) No.852 連続部分文字列 https://yukicoder.me/problems/no/852/editorial 連続な部分文字列における、文字の種類数の平均を求める 解)右端を固定すると dp[i+1] = dp[i] + (左にs[i]がでてきた位置との距離) E - Common Subsequence https://atcoder.jp/contests/abc130/tasks/abc130_e 文字列S、Tの共通整数列の数を求める 遷移はLCSのようにできるが、重複が発生するので除く必要がある ・桁DP 1 https://atcoder.jp/contests/abc029/tasks/abc029_d n以下の数字の中で現れた1の数を求める dp[i][j][k]:i桁目まで見たときに1の個数がk個の数字の個数 S - Digit Sum https://atcoder.jp/contests/dp/tasks/dp_s n以下の数字の中で、各桁の総和がDの倍数となるものを数える E - Almost Everywhere Zero https://atcoder.jp/contests/abc154/tasks/abc154_e n以下の数字の中で,0でない数字が丁度K個あるものの数を数える E - Sum Equals Xor https://atcoder.jp/contests/abc129/tasks/abc129_e a+b<=L,a+b=a^bとなる(a,b)を数える ************* 組み合わせ ************* https://codeforces.com/contest/888/problem/D 少なくともn-k個がpi=iとなるような順列の組の数え上げ →pi≠iとなる順列をモンモール数という。n-k~n個をpi=iと固定したときに、他の要素がpi≠iとなるような組み合わせの数(モンモール数)の積をとる https://codeforces.com/problemset/problem/322/B 赤・青・緑の花束が存在し、ある色を3本or全ての色を1本ずつ使ったときに、できる花束の最大数 https://atcoder.jp/contests/abc021/tasks/abc021_d https://codeforces.com/problemset/problem/1288/C 1 <=a1 <= a2 <= ... <= ak <= n となる(a1,a2..ak)の組の数 →等号がなければ単純にn個の要素の中からk個を選べばよい -> C(n,k) →等号がある場合は重複を許してk個選べばよい      -> H(n,k) http://codeforces.com/contest/1312/problem/D aj < aj+i < ... ai > ....ak > ak+1 かつ同じ数字のペアが一つだけ含まれるような組の数 D - Blue and Red Balls https://atcoder.jp/contests/abc132/tasks/abc132_d 青と赤のボールを並べ、連続している青を1~k個作ったときの並べ方の数 ************* 最短経路 ************* https://atcoder.jp/contests/joi2014yo/tasks/joi2014yo_e 移動できるノード数に制限がある場合の最短経路問題 →事前に幅優先探索でノード毎に移動できるノードを求めて、ダイクストラ ************* 遅延セグ木 ************* https://atcoder.jp/contests/abc153/submissions/10165699 *********** BIT *********** https://atcoder.jp/contests/abc157/tasks/abc157_e(アルファベット毎にBITもつやつ) https://hoj.hamako-ths.ed.jp/onlinejudge/problems/1276(中央値求めるやつ) *********** 数学 *********** 大きい数の約数 https://yukicoder.me/problems/no/677 10^nの全ての正の約数を列挙 →10^kは素因数として2^k,5^kしかもたないので、それぞれをかけ合わせる 例えば10は2^1*5*1なので、2^0,2^1に5^0,5^1をそれぞれかけ合わせればよい。 */
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; // const ll mod = 998244353; const ll MOD = 1000000007; const ll INF = 1LL << 60; #define PI (acos(-1)) #define ALL(c) (c).begin(), (c).end() #define en '\n' #define endl '\n' template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; // template <typename A, size_t N, typename T> template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; template <typename T> struct Combination { vector<T> _fact, _rfact, _inv; Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) { _fact[0] = _rfact[sz] = _inv[0] = 1; for (int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i; _rfact[sz] /= _fact[sz]; for (int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1); for (int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1]; } inline T fact(int k) const { return _fact[k]; } inline T rfact(int k) const { return _rfact[k]; } inline T inv(int k) const { return _inv[k]; } T P(int n, int r) const { if (r < 0 || n < r) return 0; return fact(n) * rfact(n - r); } T C(int p, int q) const { if (q < 0 || p < q) return 0; return fact(p) * rfact(q) * rfact(p - q); } T H(int n, int r) const { if (n < 0 || r < 0) return (0); return r == 0 ? 1 : C(n + r - 1, r); } T NC(int p, int q) const { modint ret = 1; for (int i = 1; i <= q; i += 1) { ret = ret * p / i; p--; } return ret; } }; ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } bool is_prime(ll x) { if (x == 1) { return false; } for (ll i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } map<ll, int> prime_factor(ll n) { map<ll, int> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } const ll MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; struct BIT { // 1-indexed!!! int n; vector<int> bit; BIT() { init(); } BIT(int n) : n(n) { init(); } void init() { bit.clear(); bit.resize(n + 1, 0); } int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } int sum(int x, int y) { return sum(y) - sum(x - 1); } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } int lower_bound(int w) { if (w <= 0) return 0; int x = 0, r = 1; while (r < n) r <<= 1; for (int k = r; k > 0; k >>= 1) { if (x + k <= n && bit[x + k] < w) { w -= bit[x + k]; x += k; } } return x + 1; } }; struct LazySegmentTree { // private: ll n; vector<ll> node, lazy; // public: LazySegmentTree(vector<ll> v) { int sz = (int)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1); lazy.resize(2 * n - 1, 0); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2]; } void eval(int k, int l, int r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r - l > 1) { lazy[2 * k + 1] += lazy[k] / 2; lazy[2 * k + 2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2 * k + 1, l, (l + r) / 2); add(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = node[2 * k + 1] + node[2 * k + 2]; } } ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return 0; if (a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; ll digit_sum(ll v) { ll ret = 0; while (v) { ret += (v % 10); v /= 10; } return ret; } template <typename T> struct Kruskal { struct edge { ll from, to; T cost; ll used; edge() {} edge(ll from, ll to, T cost) : from(from), to(to), cost(cost), used(0) {} bool operator<(const edge &e) const { return cost < e.cost; } }; ll n; vector<ll> p, r; vector<edge> edges; Kruskal() {} Kruskal(ll n) : n(n) {} void init(ll n) { r.assign(n, 1); p.resize(n); iota(p.begin(), p.end(), 0); } ll find(ll x) { return (x == p[x] ? x : p[x] = find(p[x])); } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) swap(x, y); r[x] += r[y]; p[y] = x; } void add_edge(ll u, ll v, T c) { edges.emplace_back(u, v, c); } T build() { sort(edges.begin(), edges.end()); init(n); T res = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; } } return res; } T build(ll k) { sort(edges.begin(), edges.end()); init(n); T res = 0; ll cnt = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; cnt++; } if (cnt == k) { break; } } return res; } }; int LIS(int a[], int n) { vector<int> A(n, 0x3f3f3f3f); for (int i = 0; i < n; i++) *lower_bound(A.begin(), A.end(), a[i]) = a[i]; return find(A.begin(), A.end(), 0x3f3f3f3f) - A.begin(); } // string maze[1010]; // //ll maze[100][100]; // ll grid_bfs(ll H, ll W, ll sx, ll sy, ll gx, ll gy) // { // //O(E) // int dx[4] = {1, 0, -1, 0}; // int dy[4] = {0, 1, 0, -1}; // vector<vector<ll>> dist(H, vector<ll>(W, -1)); // dist[sy][sx] = 0; // queue<PL> q; // q.push({sy, sx}); // while (!q.empty()) // { // ll x, y; // tie(y, x) = q.front(); // q.pop(); // if (y == gy && x == gx) // { // break; // } // for (int t = 0; t < 4; t++) // { // ll nx = x + dx[t], ny = y + dy[t]; // if (nx < 0 || ny < 0 || nx >= W || ny >= H || dist[ny][nx] != -1 // || maze[ny][nx] == '#') // { // continue; // } // dist[ny][nx] = dist[y][x] + 1; // q.push({ny, nx}); // } // } // return dist[gy][gx]; // } // no verify ll bfs(ll n, ll start, vector<vector<PL>> Edges) { vector<ll> dist(n + 1, -1); dist[start] = 0; queue<PL> q; q.push({start, 0}); while (!q.empty()) { ll node, cost; tie(cost, node) = q.front(); q.pop(); for (auto p : Edges[node]) { ll v = p.first, cost = p.second; if (dist[v] == -1) { dist[v] = dist[node] + cost; q.push({v, cost}); } } } } vector<vector<ll>> warshall_floyd(ll n, vector<vector<ll>> g, ll INF) { // init vector<vector<ll>> c(10,vector<ll>(10,0)); for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (g[i][k] == INF || g[k][j] == INF) continue; g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } return g; } struct Dijkstra { ll n; vector<vector<pair<ll, ll>>> Edges; vector<ll> Dist; vector<ll> Prev; vector<ll> PathNum; Dijkstra(ll n) : n(n), Edges(n), Dist(n), Prev(n), PathNum(n) { Prev.assign(n, -1); }; void add_edge(ll a, ll b, ll c, bool directed = true) { if (directed) { Edges[a].emplace_back(make_pair(b, c)); } else { Edges[a].emplace_back(make_pair(b, c)); Edges[b].emplace_back(make_pair(a, c)); } } // O((E+V)logV) void build(int start) { priority_queue<P, vector<P>, greater<P>> queue; fill(Dist.begin(), Dist.end(), 1e+18); // 1e18 !?!? fill(Prev.begin(), Prev.end(), -1); // 1e18 !?!? Dist[start] = 0; PathNum[start] = 1; queue.push(PL(0, start)); while (!queue.empty()) { PL p = queue.top(); queue.pop(); int v = p.second; if (Dist[v] < p.first) continue; for (int i = 0; i < Edges[v].size(); i++) { PL e = Edges[v][i]; if (Dist[e.first] > Dist[v] + e.second) { Dist[e.first] = Dist[v] + e.second; queue.push(P(Dist[e.first], e.first)); Prev[e.first] = v; PathNum[e.first] = PathNum[v]; } else if (Dist[e.first] == Dist[v] + e.second) { PathNum[e.first] += PathNum[v]; PathNum[e.first] %= MOD; } } } } ll dist(ll t) { return Dist[t]; } vector<ll> get_path(ll t) { vector<ll> path; for (; t != -1; t = Prev[t]) { path.push_back(t); } reverse(path.begin(), path.end()); return path; } ll get_path_num(ll t) { return PathNum[t]; } // int solve() // { // ll v, e, r; // cin >> v >> e >> r; // Dijkstra dij(v); // for (int i = 0; i < e; i++) // { // ll a, b, c; // cin >> a >> b >> c; // dij.add_edge(a, b, c); // } // dij.build(r); // for (int i = 0; i < v; i++) // { // if (dij.dist(i) == 1e18) // { // cout << "INF" << endl; // } // else // { // cout << dij.dist(i) << endl; // cout << dij.get_path(i) << endl; // cout << dij.get_path_num(i) << endl; // } // } // return 0; // } }; struct CumulativeSum2D { int H; int W; vector<vector<ll>> data; CumulativeSum2D(int H, int W) : H(H), W(W), data(H + 1, vector<ll>(W + 1, 0LL)) {} void add(int x, int y, ll z) { data[x + 1][y + 1] += z; } void build() { for (int i = 1; i < data.size(); i++) { for (int j = 1; j < data[i].size(); j++) { data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1]; } } } void print() { for (int i = 0; i <= H; i++) { for (int j = 0; j <= W; j++) { cout << data[i][j] << " "; } cout << endl; } } ll query(int sx, int sy, int gx, int gy) { return (data[gy][gx] - data[sy - 1][gx] - data[gy][sx - 1] + data[sy - 1][sx - 1]); } }; struct LCA { int n, h; vector<vector<int>> par; vector<vector<pair<int, int>>> v; vector<ll> depth, dis; LCA(int sz) : n(sz), v(n), depth(n), dis(n) { h = 1; while ((1 << h) < n) h++; par.assign(h, vector<int>(n, -1)); } void add_edge(int x, int y, int z) { v[x].push_back({y, z}); v[y].push_back({x, z}); } void dfs(int x, int p, int d, ll di) { par[0][x] = p; depth[x] = d; dis[x] = di; for (auto to : v[x]) if (to.first != p) dfs(to.first, x, d + 1, di + to.second); } void build() { dfs(0, -1, 0, 0); for (int i = 0; i < h - 1; i++) { for (int j = 0; j < n; j++) { if (par[i][j] < 0) par[i + 1][j] = -1; else par[i + 1][j] = par[i][par[i][j]]; } } } int lca(int u, int v) { if (depth[u] > depth[v]) swap(u, v); for (int i = 0; i < h; i++) if ((depth[v] - depth[u]) >> i & 1) v = par[i][v]; if (u == v) return u; for (int i = h - 1; i >= 0; i--) { if (par[i][u] != par[i][v]) { u = par[i][u]; v = par[i][v]; } } return par[0][u]; } ll dist(int u, int v) { return dis[u] + dis[v] - 2 * dis[lca(u, v)]; } // int solve() // { // ll n; // cin >> n; // LCA lca(n); // for (int i = 0; i < n - 1; i++) // { // ll u, v, w; // cin >> u >> v >> w; // lca.add_edge(u, v, w); // } // lca.build(); // ll q; // cin >> q; // while (q--) // { // ll a, b, c; // cin >> a >> b >> c; // cout << (lca.dist(a, b) + lca.dist(b, c) + lca.dist(c, a)) / 2 << // endl; // } // return 0; // } }; vector<ll> compress(vector<ll> r) { // 1-indexed set<ll> se; for (int i = 0; i < r.size(); i++) { se.insert(r[i]); } map<ll, ll> m; ll cnt = 1; for (auto t : se) { m[t] = cnt; cnt++; } for (int i = 0; i < r.size(); i++) { r[i] = m[r[i]]; } return r; } template <class Abel> struct WeightedUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; vector<int> z_algorithm(const string &s) { /* Z[i] は - 文字列 S=S[0]+S[1]+⋯+S[|S|−1] - 文字列 S[i]+S[i+1]+⋯+S[|S|−1] の最長共通接頭辞の長さ */ // https://qiita.com/Pro_ktmr/items/16904c9570aa0953bf05#1-z-algorithm-%E3%81%A7%E6%B1%82%E3%82%81%E3%82%8B-z-%E9%85%8D%E5%88%97%E3%81%A8%E3%81%AF vector<int> prefix(s.size()); for (int i = 1, j = 0; i < s.size(); i++) { if (i + prefix[i - j] < j + prefix[j]) { prefix[i] = prefix[i - j]; } else { int k = max(0, j + prefix[j] - i); while (i + k < s.size() && s[k] == s[i + k]) ++k; prefix[i] = k; j = i; } } prefix[0] = (int)s.size(); return prefix; } void YES() { cout << "YES" << endl; exit(0); } void NO() { cout << "NO" << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } void m1() { cout << -1 << endl; exit(0); } template <typename T> void out(const T t) { cout << t << '\n'; } template <typename T> void fout(const T t) { cout << fixed << setprecision(10) << t << '\n'; } /*------------------------------*/ void solve() { string s, t; cin >> s >> t; map<char, int> m; for (int i = 0; i < s.size(); i++) { m[s[i]] = 1; } for (int i = 0; i < t.size(); i++) { if (m[t[i]] == 0) { m1(); } } vector<int> next[26]; for (int i = 0; i < s.size(); i++) { next[s[i] - 'a'].push_back(i); // dbg(next[s[i] - 'a']); } int now = -1; ll ans = 0; for (int i = 0; i < t.size(); i++) { auto index = upper_bound(ALL(next[t[i] - 'a']), now) - next[t[i] - 'a'].begin(); ll v = next[t[i] - 'a'][index]; if (index == next[t[i] - 'a'].size()) { v = next[t[i] - 'a'][0]; ans += (s.size() - now) + v; } else { ans += v - now; } now = v; } out(ans); } // g++.exe bbb.cpp -std=c++14 int main() { cout.precision(10); ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } // IMOSs//https://imoz.jp/algorithms/imos_method.html /*名前 accumulate(ALL(b),0LL) prev_permutation(ALL(v)) 辞書順で一個前の順列を構築する bitcount __builtin_popcountll 二次元累積和 CumulativeSum2D 10進数の桁和 digit_sum (b*b+c*c)**0.5 hypot cout << fixed << setprecision(10) << ans << endl; // 文字列t ->整数 atoi(t.c_str()); // 文字列t ->long long整数 stoll(t); ローカルではつかえない */ /* */ /* ********** 区間 ********** L=(1,0,1,1,3,4) C(1,3,0,1,1) 配列Lの中で x 以上 y 未満の値が何個あるのかが、累積和を使うとわかる。 具体的には C の累積和を S とすると、S[ y ] - S[ x ] で求められる ********** 木 ********** */ /*実装例 zaatu sort(ALL(c)); c.erase(unique(ALL(c)), end(c)); ******* 再帰 ******* https://atcoder.jp/contests/abc015/tasks/abc015_3 ********** DP ********** ・ナップサックDP https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_C 個数制限なしナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_B 01ナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_F 01ナップサック N<=100,W<=10^9,v<=100 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_H 巨大ナップザック N=40 w<10^15 , v<10^15 解)半分全列挙して、wi > wj かつvi < vj となるようなiを除いて、二分探索 ・部分文字列DP https://qiita.com/drken/items/a207e5ae3ea2cf17f4bd next[i][c] := S の i 文字目以降で最初に文字 c が登場する index https://www.hackerrank.com/contests/bbc003/challenges/bbc003-e/submissions/code/1321355726 (部分文字列の中で+の個数の偶奇によって、カウントするか決める) No.852 連続部分文字列 https://yukicoder.me/problems/no/852/editorial 連続な部分文字列における、文字の種類数の平均を求める 解)右端を固定すると dp[i+1] = dp[i] + (左にs[i]がでてきた位置との距離) E - Common Subsequence https://atcoder.jp/contests/abc130/tasks/abc130_e 文字列S、Tの共通整数列の数を求める 遷移はLCSのようにできるが、重複が発生するので除く必要がある ・桁DP 1 https://atcoder.jp/contests/abc029/tasks/abc029_d n以下の数字の中で現れた1の数を求める dp[i][j][k]:i桁目まで見たときに1の個数がk個の数字の個数 S - Digit Sum https://atcoder.jp/contests/dp/tasks/dp_s n以下の数字の中で、各桁の総和がDの倍数となるものを数える E - Almost Everywhere Zero https://atcoder.jp/contests/abc154/tasks/abc154_e n以下の数字の中で,0でない数字が丁度K個あるものの数を数える E - Sum Equals Xor https://atcoder.jp/contests/abc129/tasks/abc129_e a+b<=L,a+b=a^bとなる(a,b)を数える ************* 組み合わせ ************* https://codeforces.com/contest/888/problem/D 少なくともn-k個がpi=iとなるような順列の組の数え上げ →pi≠iとなる順列をモンモール数という。n-k~n個をpi=iと固定したときに、他の要素がpi≠iとなるような組み合わせの数(モンモール数)の積をとる https://codeforces.com/problemset/problem/322/B 赤・青・緑の花束が存在し、ある色を3本or全ての色を1本ずつ使ったときに、できる花束の最大数 https://atcoder.jp/contests/abc021/tasks/abc021_d https://codeforces.com/problemset/problem/1288/C 1 <=a1 <= a2 <= ... <= ak <= n となる(a1,a2..ak)の組の数 →等号がなければ単純にn個の要素の中からk個を選べばよい -> C(n,k) →等号がある場合は重複を許してk個選べばよい      -> H(n,k) http://codeforces.com/contest/1312/problem/D aj < aj+i < ... ai > ....ak > ak+1 かつ同じ数字のペアが一つだけ含まれるような組の数 D - Blue and Red Balls https://atcoder.jp/contests/abc132/tasks/abc132_d 青と赤のボールを並べ、連続している青を1~k個作ったときの並べ方の数 ************* 最短経路 ************* https://atcoder.jp/contests/joi2014yo/tasks/joi2014yo_e 移動できるノード数に制限がある場合の最短経路問題 →事前に幅優先探索でノード毎に移動できるノードを求めて、ダイクストラ ************* 遅延セグ木 ************* https://atcoder.jp/contests/abc153/submissions/10165699 *********** BIT *********** https://atcoder.jp/contests/abc157/tasks/abc157_e(アルファベット毎にBITもつやつ) https://hoj.hamako-ths.ed.jp/onlinejudge/problems/1276(中央値求めるやつ) *********** 数学 *********** 大きい数の約数 https://yukicoder.me/problems/no/677 10^nの全ての正の約数を列挙 →10^kは素因数として2^k,5^kしかもたないので、それぞれをかけ合わせる 例えば10は2^1*5*1なので、2^0,2^1に5^0,5^1をそれぞれかけ合わせればよい。 */
[ "variable_declaration.type.change", "identifier.change", "call.function.change", "expression.operation.binary.change" ]
739,589
739,588
u644778646
cpp
p02937
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; // const ll mod = 998244353; const ll MOD = 1000000007; const ll INF = 1LL << 60; #define PI (acos(-1)) #define ALL(c) (c).begin(), (c).end() #define en '\n' #define endl '\n' template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; // template <typename A, size_t N, typename T> template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; template <typename T> struct Combination { vector<T> _fact, _rfact, _inv; Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) { _fact[0] = _rfact[sz] = _inv[0] = 1; for (int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i; _rfact[sz] /= _fact[sz]; for (int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1); for (int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1]; } inline T fact(int k) const { return _fact[k]; } inline T rfact(int k) const { return _rfact[k]; } inline T inv(int k) const { return _inv[k]; } T P(int n, int r) const { if (r < 0 || n < r) return 0; return fact(n) * rfact(n - r); } T C(int p, int q) const { if (q < 0 || p < q) return 0; return fact(p) * rfact(q) * rfact(p - q); } T H(int n, int r) const { if (n < 0 || r < 0) return (0); return r == 0 ? 1 : C(n + r - 1, r); } T NC(int p, int q) const { modint ret = 1; for (int i = 1; i <= q; i += 1) { ret = ret * p / i; p--; } return ret; } }; ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } bool is_prime(ll x) { if (x == 1) { return false; } for (ll i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } map<ll, int> prime_factor(ll n) { map<ll, int> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } const ll MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; struct BIT { // 1-indexed!!! int n; vector<int> bit; BIT() { init(); } BIT(int n) : n(n) { init(); } void init() { bit.clear(); bit.resize(n + 1, 0); } int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } int sum(int x, int y) { return sum(y) - sum(x - 1); } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } int lower_bound(int w) { if (w <= 0) return 0; int x = 0, r = 1; while (r < n) r <<= 1; for (int k = r; k > 0; k >>= 1) { if (x + k <= n && bit[x + k] < w) { w -= bit[x + k]; x += k; } } return x + 1; } }; struct LazySegmentTree { // private: ll n; vector<ll> node, lazy; // public: LazySegmentTree(vector<ll> v) { int sz = (int)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1); lazy.resize(2 * n - 1, 0); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2]; } void eval(int k, int l, int r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r - l > 1) { lazy[2 * k + 1] += lazy[k] / 2; lazy[2 * k + 2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2 * k + 1, l, (l + r) / 2); add(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = node[2 * k + 1] + node[2 * k + 2]; } } ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return 0; if (a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; ll digit_sum(ll v) { ll ret = 0; while (v) { ret += (v % 10); v /= 10; } return ret; } template <typename T> struct Kruskal { struct edge { ll from, to; T cost; ll used; edge() {} edge(ll from, ll to, T cost) : from(from), to(to), cost(cost), used(0) {} bool operator<(const edge &e) const { return cost < e.cost; } }; ll n; vector<ll> p, r; vector<edge> edges; Kruskal() {} Kruskal(ll n) : n(n) {} void init(ll n) { r.assign(n, 1); p.resize(n); iota(p.begin(), p.end(), 0); } ll find(ll x) { return (x == p[x] ? x : p[x] = find(p[x])); } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) swap(x, y); r[x] += r[y]; p[y] = x; } void add_edge(ll u, ll v, T c) { edges.emplace_back(u, v, c); } T build() { sort(edges.begin(), edges.end()); init(n); T res = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; } } return res; } T build(ll k) { sort(edges.begin(), edges.end()); init(n); T res = 0; ll cnt = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; cnt++; } if (cnt == k) { break; } } return res; } }; int LIS(int a[], int n) { vector<int> A(n, 0x3f3f3f3f); for (int i = 0; i < n; i++) *lower_bound(A.begin(), A.end(), a[i]) = a[i]; return find(A.begin(), A.end(), 0x3f3f3f3f) - A.begin(); } // string maze[1010]; // //ll maze[100][100]; // ll grid_bfs(ll H, ll W, ll sx, ll sy, ll gx, ll gy) // { // //O(E) // int dx[4] = {1, 0, -1, 0}; // int dy[4] = {0, 1, 0, -1}; // vector<vector<ll>> dist(H, vector<ll>(W, -1)); // dist[sy][sx] = 0; // queue<PL> q; // q.push({sy, sx}); // while (!q.empty()) // { // ll x, y; // tie(y, x) = q.front(); // q.pop(); // if (y == gy && x == gx) // { // break; // } // for (int t = 0; t < 4; t++) // { // ll nx = x + dx[t], ny = y + dy[t]; // if (nx < 0 || ny < 0 || nx >= W || ny >= H || dist[ny][nx] != -1 // || maze[ny][nx] == '#') // { // continue; // } // dist[ny][nx] = dist[y][x] + 1; // q.push({ny, nx}); // } // } // return dist[gy][gx]; // } // no verify ll bfs(ll n, ll start, vector<vector<PL>> Edges) { vector<ll> dist(n + 1, -1); dist[start] = 0; queue<PL> q; q.push({start, 0}); while (!q.empty()) { ll node, cost; tie(cost, node) = q.front(); q.pop(); for (auto p : Edges[node]) { ll v = p.first, cost = p.second; if (dist[v] == -1) { dist[v] = dist[node] + cost; q.push({v, cost}); } } } } vector<vector<ll>> warshall_floyd(ll n, vector<vector<ll>> g, ll INF) { // init vector<vector<ll>> c(10,vector<ll>(10,0)); for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (g[i][k] == INF || g[k][j] == INF) continue; g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } return g; } struct Dijkstra { ll n; vector<vector<pair<ll, ll>>> Edges; vector<ll> Dist; vector<ll> Prev; vector<ll> PathNum; Dijkstra(ll n) : n(n), Edges(n), Dist(n), Prev(n), PathNum(n) { Prev.assign(n, -1); }; void add_edge(ll a, ll b, ll c, bool directed = true) { if (directed) { Edges[a].emplace_back(make_pair(b, c)); } else { Edges[a].emplace_back(make_pair(b, c)); Edges[b].emplace_back(make_pair(a, c)); } } // O((E+V)logV) void build(int start) { priority_queue<P, vector<P>, greater<P>> queue; fill(Dist.begin(), Dist.end(), 1e+18); // 1e18 !?!? fill(Prev.begin(), Prev.end(), -1); // 1e18 !?!? Dist[start] = 0; PathNum[start] = 1; queue.push(PL(0, start)); while (!queue.empty()) { PL p = queue.top(); queue.pop(); int v = p.second; if (Dist[v] < p.first) continue; for (int i = 0; i < Edges[v].size(); i++) { PL e = Edges[v][i]; if (Dist[e.first] > Dist[v] + e.second) { Dist[e.first] = Dist[v] + e.second; queue.push(P(Dist[e.first], e.first)); Prev[e.first] = v; PathNum[e.first] = PathNum[v]; } else if (Dist[e.first] == Dist[v] + e.second) { PathNum[e.first] += PathNum[v]; PathNum[e.first] %= MOD; } } } } ll dist(ll t) { return Dist[t]; } vector<ll> get_path(ll t) { vector<ll> path; for (; t != -1; t = Prev[t]) { path.push_back(t); } reverse(path.begin(), path.end()); return path; } ll get_path_num(ll t) { return PathNum[t]; } // int solve() // { // ll v, e, r; // cin >> v >> e >> r; // Dijkstra dij(v); // for (int i = 0; i < e; i++) // { // ll a, b, c; // cin >> a >> b >> c; // dij.add_edge(a, b, c); // } // dij.build(r); // for (int i = 0; i < v; i++) // { // if (dij.dist(i) == 1e18) // { // cout << "INF" << endl; // } // else // { // cout << dij.dist(i) << endl; // cout << dij.get_path(i) << endl; // cout << dij.get_path_num(i) << endl; // } // } // return 0; // } }; struct CumulativeSum2D { int H; int W; vector<vector<ll>> data; CumulativeSum2D(int H, int W) : H(H), W(W), data(H + 1, vector<ll>(W + 1, 0LL)) {} void add(int x, int y, ll z) { data[x + 1][y + 1] += z; } void build() { for (int i = 1; i < data.size(); i++) { for (int j = 1; j < data[i].size(); j++) { data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1]; } } } void print() { for (int i = 0; i <= H; i++) { for (int j = 0; j <= W; j++) { cout << data[i][j] << " "; } cout << endl; } } ll query(int sx, int sy, int gx, int gy) { return (data[gy][gx] - data[sy - 1][gx] - data[gy][sx - 1] + data[sy - 1][sx - 1]); } }; struct LCA { int n, h; vector<vector<int>> par; vector<vector<pair<int, int>>> v; vector<ll> depth, dis; LCA(int sz) : n(sz), v(n), depth(n), dis(n) { h = 1; while ((1 << h) < n) h++; par.assign(h, vector<int>(n, -1)); } void add_edge(int x, int y, int z) { v[x].push_back({y, z}); v[y].push_back({x, z}); } void dfs(int x, int p, int d, ll di) { par[0][x] = p; depth[x] = d; dis[x] = di; for (auto to : v[x]) if (to.first != p) dfs(to.first, x, d + 1, di + to.second); } void build() { dfs(0, -1, 0, 0); for (int i = 0; i < h - 1; i++) { for (int j = 0; j < n; j++) { if (par[i][j] < 0) par[i + 1][j] = -1; else par[i + 1][j] = par[i][par[i][j]]; } } } int lca(int u, int v) { if (depth[u] > depth[v]) swap(u, v); for (int i = 0; i < h; i++) if ((depth[v] - depth[u]) >> i & 1) v = par[i][v]; if (u == v) return u; for (int i = h - 1; i >= 0; i--) { if (par[i][u] != par[i][v]) { u = par[i][u]; v = par[i][v]; } } return par[0][u]; } ll dist(int u, int v) { return dis[u] + dis[v] - 2 * dis[lca(u, v)]; } // int solve() // { // ll n; // cin >> n; // LCA lca(n); // for (int i = 0; i < n - 1; i++) // { // ll u, v, w; // cin >> u >> v >> w; // lca.add_edge(u, v, w); // } // lca.build(); // ll q; // cin >> q; // while (q--) // { // ll a, b, c; // cin >> a >> b >> c; // cout << (lca.dist(a, b) + lca.dist(b, c) + lca.dist(c, a)) / 2 << // endl; // } // return 0; // } }; vector<ll> compress(vector<ll> r) { // 1-indexed set<ll> se; for (int i = 0; i < r.size(); i++) { se.insert(r[i]); } map<ll, ll> m; ll cnt = 1; for (auto t : se) { m[t] = cnt; cnt++; } for (int i = 0; i < r.size(); i++) { r[i] = m[r[i]]; } return r; } template <class Abel> struct WeightedUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; vector<int> z_algorithm(const string &s) { /* Z[i] は - 文字列 S=S[0]+S[1]+⋯+S[|S|−1] - 文字列 S[i]+S[i+1]+⋯+S[|S|−1] の最長共通接頭辞の長さ */ // https://qiita.com/Pro_ktmr/items/16904c9570aa0953bf05#1-z-algorithm-%E3%81%A7%E6%B1%82%E3%82%81%E3%82%8B-z-%E9%85%8D%E5%88%97%E3%81%A8%E3%81%AF vector<int> prefix(s.size()); for (int i = 1, j = 0; i < s.size(); i++) { if (i + prefix[i - j] < j + prefix[j]) { prefix[i] = prefix[i - j]; } else { int k = max(0, j + prefix[j] - i); while (i + k < s.size() && s[k] == s[i + k]) ++k; prefix[i] = k; j = i; } } prefix[0] = (int)s.size(); return prefix; } void YES() { cout << "YES" << endl; exit(0); } void NO() { cout << "NO" << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } void m1() { cout << -1 << endl; exit(0); } template <typename T> void out(const T t) { cout << t << '\n'; } template <typename T> void fout(const T t) { cout << fixed << setprecision(10) << t << '\n'; } /*------------------------------*/ void solve() { string s, t; cin >> s >> t; map<char, int> m; for (int i = 0; i < s.size(); i++) { m[s[i]] = 1; } for (int i = 0; i < t.size(); i++) { if (m[t[i]] == 0) { m1(); } } vector<ll> next[26]; for (int i = 0; i < s.size(); i++) { next[s[i] - 'a'].push_back(i); } ll now = -1; ll ans = 0; for (int i = 0; i < t.size(); i++) { ll index = lower_bound(ALL(next[t[i] - 'a']), now) - next[t[i] - 'a'].begin(); ll v = next[t[i] - 'a'][index]; if (index == next[t[i] - 'a'].size()) { // index = lower_bound(ALL(next[t[i] - 'a']), -1) - next[t[i] - // 'a'].begin(); v = next[t[i] - 'a'][0]; ans += (s.size() - now) + v; } else { ans += v - now; } now = v; } out(ans); } // g++.exe bbb.cpp -std=c++14 int main() { cout.precision(10); ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } // IMOSs//https://imoz.jp/algorithms/imos_method.html /*名前 accumulate(ALL(b),0LL) prev_permutation(ALL(v)) 辞書順で一個前の順列を構築する bitcount __builtin_popcountll 二次元累積和 CumulativeSum2D 10進数の桁和 digit_sum (b*b+c*c)**0.5 hypot cout << fixed << setprecision(10) << ans << endl; // 文字列t ->整数 atoi(t.c_str()); // 文字列t ->long long整数 stoll(t); ローカルではつかえない */ /* */ /* ********** 区間 ********** L=(1,0,1,1,3,4) C(1,3,0,1,1) 配列Lの中で x 以上 y 未満の値が何個あるのかが、累積和を使うとわかる。 具体的には C の累積和を S とすると、S[ y ] - S[ x ] で求められる ********** 木 ********** */ /*実装例 zaatu sort(ALL(c)); c.erase(unique(ALL(c)), end(c)); ******* 再帰 ******* https://atcoder.jp/contests/abc015/tasks/abc015_3 ********** DP ********** ・ナップサックDP https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_C 個数制限なしナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_B 01ナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_F 01ナップサック N<=100,W<=10^9,v<=100 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_H 巨大ナップザック N=40 w<10^15 , v<10^15 解)半分全列挙して、wi > wj かつvi < vj となるようなiを除いて、二分探索 ・部分文字列DP https://qiita.com/drken/items/a207e5ae3ea2cf17f4bd next[i][c] := S の i 文字目以降で最初に文字 c が登場する index https://www.hackerrank.com/contests/bbc003/challenges/bbc003-e/submissions/code/1321355726 (部分文字列の中で+の個数の偶奇によって、カウントするか決める) No.852 連続部分文字列 https://yukicoder.me/problems/no/852/editorial 連続な部分文字列における、文字の種類数の平均を求める 解)右端を固定すると dp[i+1] = dp[i] + (左にs[i]がでてきた位置との距離) E - Common Subsequence https://atcoder.jp/contests/abc130/tasks/abc130_e 文字列S、Tの共通整数列の数を求める 遷移はLCSのようにできるが、重複が発生するので除く必要がある ・桁DP 1 https://atcoder.jp/contests/abc029/tasks/abc029_d n以下の数字の中で現れた1の数を求める dp[i][j][k]:i桁目まで見たときに1の個数がk個の数字の個数 S - Digit Sum https://atcoder.jp/contests/dp/tasks/dp_s n以下の数字の中で、各桁の総和がDの倍数となるものを数える E - Almost Everywhere Zero https://atcoder.jp/contests/abc154/tasks/abc154_e n以下の数字の中で,0でない数字が丁度K個あるものの数を数える E - Sum Equals Xor https://atcoder.jp/contests/abc129/tasks/abc129_e a+b<=L,a+b=a^bとなる(a,b)を数える ************* 組み合わせ ************* https://codeforces.com/contest/888/problem/D 少なくともn-k個がpi=iとなるような順列の組の数え上げ →pi≠iとなる順列をモンモール数という。n-k~n個をpi=iと固定したときに、他の要素がpi≠iとなるような組み合わせの数(モンモール数)の積をとる https://codeforces.com/problemset/problem/322/B 赤・青・緑の花束が存在し、ある色を3本or全ての色を1本ずつ使ったときに、できる花束の最大数 https://atcoder.jp/contests/abc021/tasks/abc021_d https://codeforces.com/problemset/problem/1288/C 1 <=a1 <= a2 <= ... <= ak <= n となる(a1,a2..ak)の組の数 →等号がなければ単純にn個の要素の中からk個を選べばよい -> C(n,k) →等号がある場合は重複を許してk個選べばよい      -> H(n,k) http://codeforces.com/contest/1312/problem/D aj < aj+i < ... ai > ....ak > ak+1 かつ同じ数字のペアが一つだけ含まれるような組の数 D - Blue and Red Balls https://atcoder.jp/contests/abc132/tasks/abc132_d 青と赤のボールを並べ、連続している青を1~k個作ったときの並べ方の数 ************* 最短経路 ************* https://atcoder.jp/contests/joi2014yo/tasks/joi2014yo_e 移動できるノード数に制限がある場合の最短経路問題 →事前に幅優先探索でノード毎に移動できるノードを求めて、ダイクストラ ************* 遅延セグ木 ************* https://atcoder.jp/contests/abc153/submissions/10165699 *********** BIT *********** https://atcoder.jp/contests/abc157/tasks/abc157_e(アルファベット毎にBITもつやつ) https://hoj.hamako-ths.ed.jp/onlinejudge/problems/1276(中央値求めるやつ) *********** 数学 *********** 大きい数の約数 https://yukicoder.me/problems/no/677 10^nの全ての正の約数を列挙 →10^kは素因数として2^k,5^kしかもたないので、それぞれをかけ合わせる 例えば10は2^1*5*1なので、2^0,2^1に5^0,5^1をそれぞれかけ合わせればよい。 */
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; // const ll mod = 998244353; const ll MOD = 1000000007; const ll INF = 1LL << 60; #define PI (acos(-1)) #define ALL(c) (c).begin(), (c).end() #define en '\n' #define endl '\n' template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; // template <typename A, size_t N, typename T> template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; template <typename T> struct Combination { vector<T> _fact, _rfact, _inv; Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) { _fact[0] = _rfact[sz] = _inv[0] = 1; for (int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i; _rfact[sz] /= _fact[sz]; for (int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1); for (int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1]; } inline T fact(int k) const { return _fact[k]; } inline T rfact(int k) const { return _rfact[k]; } inline T inv(int k) const { return _inv[k]; } T P(int n, int r) const { if (r < 0 || n < r) return 0; return fact(n) * rfact(n - r); } T C(int p, int q) const { if (q < 0 || p < q) return 0; return fact(p) * rfact(q) * rfact(p - q); } T H(int n, int r) const { if (n < 0 || r < 0) return (0); return r == 0 ? 1 : C(n + r - 1, r); } T NC(int p, int q) const { modint ret = 1; for (int i = 1; i <= q; i += 1) { ret = ret * p / i; p--; } return ret; } }; ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } bool is_prime(ll x) { if (x == 1) { return false; } for (ll i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } map<ll, int> prime_factor(ll n) { map<ll, int> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } const ll MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; struct BIT { // 1-indexed!!! int n; vector<int> bit; BIT() { init(); } BIT(int n) : n(n) { init(); } void init() { bit.clear(); bit.resize(n + 1, 0); } int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } int sum(int x, int y) { return sum(y) - sum(x - 1); } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } int lower_bound(int w) { if (w <= 0) return 0; int x = 0, r = 1; while (r < n) r <<= 1; for (int k = r; k > 0; k >>= 1) { if (x + k <= n && bit[x + k] < w) { w -= bit[x + k]; x += k; } } return x + 1; } }; struct LazySegmentTree { // private: ll n; vector<ll> node, lazy; // public: LazySegmentTree(vector<ll> v) { int sz = (int)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1); lazy.resize(2 * n - 1, 0); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2]; } void eval(int k, int l, int r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r - l > 1) { lazy[2 * k + 1] += lazy[k] / 2; lazy[2 * k + 2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2 * k + 1, l, (l + r) / 2); add(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = node[2 * k + 1] + node[2 * k + 2]; } } ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return 0; if (a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; ll digit_sum(ll v) { ll ret = 0; while (v) { ret += (v % 10); v /= 10; } return ret; } template <typename T> struct Kruskal { struct edge { ll from, to; T cost; ll used; edge() {} edge(ll from, ll to, T cost) : from(from), to(to), cost(cost), used(0) {} bool operator<(const edge &e) const { return cost < e.cost; } }; ll n; vector<ll> p, r; vector<edge> edges; Kruskal() {} Kruskal(ll n) : n(n) {} void init(ll n) { r.assign(n, 1); p.resize(n); iota(p.begin(), p.end(), 0); } ll find(ll x) { return (x == p[x] ? x : p[x] = find(p[x])); } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) swap(x, y); r[x] += r[y]; p[y] = x; } void add_edge(ll u, ll v, T c) { edges.emplace_back(u, v, c); } T build() { sort(edges.begin(), edges.end()); init(n); T res = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; } } return res; } T build(ll k) { sort(edges.begin(), edges.end()); init(n); T res = 0; ll cnt = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; cnt++; } if (cnt == k) { break; } } return res; } }; int LIS(int a[], int n) { vector<int> A(n, 0x3f3f3f3f); for (int i = 0; i < n; i++) *lower_bound(A.begin(), A.end(), a[i]) = a[i]; return find(A.begin(), A.end(), 0x3f3f3f3f) - A.begin(); } // string maze[1010]; // //ll maze[100][100]; // ll grid_bfs(ll H, ll W, ll sx, ll sy, ll gx, ll gy) // { // //O(E) // int dx[4] = {1, 0, -1, 0}; // int dy[4] = {0, 1, 0, -1}; // vector<vector<ll>> dist(H, vector<ll>(W, -1)); // dist[sy][sx] = 0; // queue<PL> q; // q.push({sy, sx}); // while (!q.empty()) // { // ll x, y; // tie(y, x) = q.front(); // q.pop(); // if (y == gy && x == gx) // { // break; // } // for (int t = 0; t < 4; t++) // { // ll nx = x + dx[t], ny = y + dy[t]; // if (nx < 0 || ny < 0 || nx >= W || ny >= H || dist[ny][nx] != -1 // || maze[ny][nx] == '#') // { // continue; // } // dist[ny][nx] = dist[y][x] + 1; // q.push({ny, nx}); // } // } // return dist[gy][gx]; // } // no verify ll bfs(ll n, ll start, vector<vector<PL>> Edges) { vector<ll> dist(n + 1, -1); dist[start] = 0; queue<PL> q; q.push({start, 0}); while (!q.empty()) { ll node, cost; tie(cost, node) = q.front(); q.pop(); for (auto p : Edges[node]) { ll v = p.first, cost = p.second; if (dist[v] == -1) { dist[v] = dist[node] + cost; q.push({v, cost}); } } } } vector<vector<ll>> warshall_floyd(ll n, vector<vector<ll>> g, ll INF) { // init vector<vector<ll>> c(10,vector<ll>(10,0)); for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (g[i][k] == INF || g[k][j] == INF) continue; g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } return g; } struct Dijkstra { ll n; vector<vector<pair<ll, ll>>> Edges; vector<ll> Dist; vector<ll> Prev; vector<ll> PathNum; Dijkstra(ll n) : n(n), Edges(n), Dist(n), Prev(n), PathNum(n) { Prev.assign(n, -1); }; void add_edge(ll a, ll b, ll c, bool directed = true) { if (directed) { Edges[a].emplace_back(make_pair(b, c)); } else { Edges[a].emplace_back(make_pair(b, c)); Edges[b].emplace_back(make_pair(a, c)); } } // O((E+V)logV) void build(int start) { priority_queue<P, vector<P>, greater<P>> queue; fill(Dist.begin(), Dist.end(), 1e+18); // 1e18 !?!? fill(Prev.begin(), Prev.end(), -1); // 1e18 !?!? Dist[start] = 0; PathNum[start] = 1; queue.push(PL(0, start)); while (!queue.empty()) { PL p = queue.top(); queue.pop(); int v = p.second; if (Dist[v] < p.first) continue; for (int i = 0; i < Edges[v].size(); i++) { PL e = Edges[v][i]; if (Dist[e.first] > Dist[v] + e.second) { Dist[e.first] = Dist[v] + e.second; queue.push(P(Dist[e.first], e.first)); Prev[e.first] = v; PathNum[e.first] = PathNum[v]; } else if (Dist[e.first] == Dist[v] + e.second) { PathNum[e.first] += PathNum[v]; PathNum[e.first] %= MOD; } } } } ll dist(ll t) { return Dist[t]; } vector<ll> get_path(ll t) { vector<ll> path; for (; t != -1; t = Prev[t]) { path.push_back(t); } reverse(path.begin(), path.end()); return path; } ll get_path_num(ll t) { return PathNum[t]; } // int solve() // { // ll v, e, r; // cin >> v >> e >> r; // Dijkstra dij(v); // for (int i = 0; i < e; i++) // { // ll a, b, c; // cin >> a >> b >> c; // dij.add_edge(a, b, c); // } // dij.build(r); // for (int i = 0; i < v; i++) // { // if (dij.dist(i) == 1e18) // { // cout << "INF" << endl; // } // else // { // cout << dij.dist(i) << endl; // cout << dij.get_path(i) << endl; // cout << dij.get_path_num(i) << endl; // } // } // return 0; // } }; struct CumulativeSum2D { int H; int W; vector<vector<ll>> data; CumulativeSum2D(int H, int W) : H(H), W(W), data(H + 1, vector<ll>(W + 1, 0LL)) {} void add(int x, int y, ll z) { data[x + 1][y + 1] += z; } void build() { for (int i = 1; i < data.size(); i++) { for (int j = 1; j < data[i].size(); j++) { data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1]; } } } void print() { for (int i = 0; i <= H; i++) { for (int j = 0; j <= W; j++) { cout << data[i][j] << " "; } cout << endl; } } ll query(int sx, int sy, int gx, int gy) { return (data[gy][gx] - data[sy - 1][gx] - data[gy][sx - 1] + data[sy - 1][sx - 1]); } }; struct LCA { int n, h; vector<vector<int>> par; vector<vector<pair<int, int>>> v; vector<ll> depth, dis; LCA(int sz) : n(sz), v(n), depth(n), dis(n) { h = 1; while ((1 << h) < n) h++; par.assign(h, vector<int>(n, -1)); } void add_edge(int x, int y, int z) { v[x].push_back({y, z}); v[y].push_back({x, z}); } void dfs(int x, int p, int d, ll di) { par[0][x] = p; depth[x] = d; dis[x] = di; for (auto to : v[x]) if (to.first != p) dfs(to.first, x, d + 1, di + to.second); } void build() { dfs(0, -1, 0, 0); for (int i = 0; i < h - 1; i++) { for (int j = 0; j < n; j++) { if (par[i][j] < 0) par[i + 1][j] = -1; else par[i + 1][j] = par[i][par[i][j]]; } } } int lca(int u, int v) { if (depth[u] > depth[v]) swap(u, v); for (int i = 0; i < h; i++) if ((depth[v] - depth[u]) >> i & 1) v = par[i][v]; if (u == v) return u; for (int i = h - 1; i >= 0; i--) { if (par[i][u] != par[i][v]) { u = par[i][u]; v = par[i][v]; } } return par[0][u]; } ll dist(int u, int v) { return dis[u] + dis[v] - 2 * dis[lca(u, v)]; } // int solve() // { // ll n; // cin >> n; // LCA lca(n); // for (int i = 0; i < n - 1; i++) // { // ll u, v, w; // cin >> u >> v >> w; // lca.add_edge(u, v, w); // } // lca.build(); // ll q; // cin >> q; // while (q--) // { // ll a, b, c; // cin >> a >> b >> c; // cout << (lca.dist(a, b) + lca.dist(b, c) + lca.dist(c, a)) / 2 << // endl; // } // return 0; // } }; vector<ll> compress(vector<ll> r) { // 1-indexed set<ll> se; for (int i = 0; i < r.size(); i++) { se.insert(r[i]); } map<ll, ll> m; ll cnt = 1; for (auto t : se) { m[t] = cnt; cnt++; } for (int i = 0; i < r.size(); i++) { r[i] = m[r[i]]; } return r; } template <class Abel> struct WeightedUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; vector<int> z_algorithm(const string &s) { /* Z[i] は - 文字列 S=S[0]+S[1]+⋯+S[|S|−1] - 文字列 S[i]+S[i+1]+⋯+S[|S|−1] の最長共通接頭辞の長さ */ // https://qiita.com/Pro_ktmr/items/16904c9570aa0953bf05#1-z-algorithm-%E3%81%A7%E6%B1%82%E3%82%81%E3%82%8B-z-%E9%85%8D%E5%88%97%E3%81%A8%E3%81%AF vector<int> prefix(s.size()); for (int i = 1, j = 0; i < s.size(); i++) { if (i + prefix[i - j] < j + prefix[j]) { prefix[i] = prefix[i - j]; } else { int k = max(0, j + prefix[j] - i); while (i + k < s.size() && s[k] == s[i + k]) ++k; prefix[i] = k; j = i; } } prefix[0] = (int)s.size(); return prefix; } void YES() { cout << "YES" << endl; exit(0); } void NO() { cout << "NO" << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } void m1() { cout << -1 << endl; exit(0); } template <typename T> void out(const T t) { cout << t << '\n'; } template <typename T> void fout(const T t) { cout << fixed << setprecision(10) << t << '\n'; } /*------------------------------*/ void solve() { string s, t; cin >> s >> t; map<char, int> m; for (int i = 0; i < s.size(); i++) { m[s[i]] = 1; } for (int i = 0; i < t.size(); i++) { if (m[t[i]] == 0) { m1(); } } vector<ll> next[26]; for (int i = 0; i < s.size(); i++) { next[s[i] - 'a'].push_back(i); } ll now = -1; ll ans = 0; for (int i = 0; i < t.size(); i++) { // lowerにすると同じ文字がひっかかってOUT!!!(同じ文字が並んでいる場合) ll index = upper_bound(ALL(next[t[i] - 'a']), now) - next[t[i] - 'a'].begin(); ll v = next[t[i] - 'a'][index]; if (index == next[t[i] - 'a'].size()) { v = next[t[i] - 'a'][0]; ans += (s.size() - now) + v; } else { ans += v - now; } now = v; } out(ans); } // g++.exe bbb.cpp -std=c++14 int main() { cout.precision(10); ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } // IMOSs//https://imoz.jp/algorithms/imos_method.html /*名前 accumulate(ALL(b),0LL) prev_permutation(ALL(v)) 辞書順で一個前の順列を構築する bitcount __builtin_popcountll 二次元累積和 CumulativeSum2D 10進数の桁和 digit_sum (b*b+c*c)**0.5 hypot cout << fixed << setprecision(10) << ans << endl; // 文字列t ->整数 atoi(t.c_str()); // 文字列t ->long long整数 stoll(t); ローカルではつかえない */ /* */ /* ********** 区間 ********** L=(1,0,1,1,3,4) C(1,3,0,1,1) 配列Lの中で x 以上 y 未満の値が何個あるのかが、累積和を使うとわかる。 具体的には C の累積和を S とすると、S[ y ] - S[ x ] で求められる ********** 木 ********** */ /*実装例 zaatu sort(ALL(c)); c.erase(unique(ALL(c)), end(c)); ******* 再帰 ******* https://atcoder.jp/contests/abc015/tasks/abc015_3 ********** DP ********** ・ナップサックDP https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_C 個数制限なしナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_B 01ナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_F 01ナップサック N<=100,W<=10^9,v<=100 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_H 巨大ナップザック N=40 w<10^15 , v<10^15 解)半分全列挙して、wi > wj かつvi < vj となるようなiを除いて、二分探索 ・部分文字列DP https://qiita.com/drken/items/a207e5ae3ea2cf17f4bd next[i][c] := S の i 文字目以降で最初に文字 c が登場する index https://www.hackerrank.com/contests/bbc003/challenges/bbc003-e/submissions/code/1321355726 (部分文字列の中で+の個数の偶奇によって、カウントするか決める) No.852 連続部分文字列 https://yukicoder.me/problems/no/852/editorial 連続な部分文字列における、文字の種類数の平均を求める 解)右端を固定すると dp[i+1] = dp[i] + (左にs[i]がでてきた位置との距離) E - Common Subsequence https://atcoder.jp/contests/abc130/tasks/abc130_e 文字列S、Tの共通整数列の数を求める 遷移はLCSのようにできるが、重複が発生するので除く必要がある ・桁DP 1 https://atcoder.jp/contests/abc029/tasks/abc029_d n以下の数字の中で現れた1の数を求める dp[i][j][k]:i桁目まで見たときに1の個数がk個の数字の個数 S - Digit Sum https://atcoder.jp/contests/dp/tasks/dp_s n以下の数字の中で、各桁の総和がDの倍数となるものを数える E - Almost Everywhere Zero https://atcoder.jp/contests/abc154/tasks/abc154_e n以下の数字の中で,0でない数字が丁度K個あるものの数を数える E - Sum Equals Xor https://atcoder.jp/contests/abc129/tasks/abc129_e a+b<=L,a+b=a^bとなる(a,b)を数える ************* 組み合わせ ************* https://codeforces.com/contest/888/problem/D 少なくともn-k個がpi=iとなるような順列の組の数え上げ →pi≠iとなる順列をモンモール数という。n-k~n個をpi=iと固定したときに、他の要素がpi≠iとなるような組み合わせの数(モンモール数)の積をとる https://codeforces.com/problemset/problem/322/B 赤・青・緑の花束が存在し、ある色を3本or全ての色を1本ずつ使ったときに、できる花束の最大数 https://atcoder.jp/contests/abc021/tasks/abc021_d https://codeforces.com/problemset/problem/1288/C 1 <=a1 <= a2 <= ... <= ak <= n となる(a1,a2..ak)の組の数 →等号がなければ単純にn個の要素の中からk個を選べばよい -> C(n,k) →等号がある場合は重複を許してk個選べばよい      -> H(n,k) http://codeforces.com/contest/1312/problem/D aj < aj+i < ... ai > ....ak > ak+1 かつ同じ数字のペアが一つだけ含まれるような組の数 D - Blue and Red Balls https://atcoder.jp/contests/abc132/tasks/abc132_d 青と赤のボールを並べ、連続している青を1~k個作ったときの並べ方の数 ************* 最短経路 ************* https://atcoder.jp/contests/joi2014yo/tasks/joi2014yo_e 移動できるノード数に制限がある場合の最短経路問題 →事前に幅優先探索でノード毎に移動できるノードを求めて、ダイクストラ ************* 遅延セグ木 ************* https://atcoder.jp/contests/abc153/submissions/10165699 *********** BIT *********** https://atcoder.jp/contests/abc157/tasks/abc157_e(アルファベット毎にBITもつやつ) https://hoj.hamako-ths.ed.jp/onlinejudge/problems/1276(中央値求めるやつ) *********** 数学 *********** 大きい数の約数 https://yukicoder.me/problems/no/677 10^nの全ての正の約数を列挙 →10^kは素因数として2^k,5^kしかもたないので、それぞれをかけ合わせる 例えば10は2^1*5*1なので、2^0,2^1に5^0,5^1をそれぞれかけ合わせればよい。 */
[ "identifier.change", "call.function.change", "expression.operation.binary.change" ]
739,589
739,590
u644778646
cpp
p02937
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; // const ll mod = 998244353; const ll MOD = 1000000007; const ll INF = 1LL << 60; #define PI (acos(-1)) #define ALL(c) (c).begin(), (c).end() #define en '\n' #define endl '\n' template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; // template <typename A, size_t N, typename T> template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; template <typename T> struct Combination { vector<T> _fact, _rfact, _inv; Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) { _fact[0] = _rfact[sz] = _inv[0] = 1; for (int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i; _rfact[sz] /= _fact[sz]; for (int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1); for (int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1]; } inline T fact(int k) const { return _fact[k]; } inline T rfact(int k) const { return _rfact[k]; } inline T inv(int k) const { return _inv[k]; } T P(int n, int r) const { if (r < 0 || n < r) return 0; return fact(n) * rfact(n - r); } T C(int p, int q) const { if (q < 0 || p < q) return 0; return fact(p) * rfact(q) * rfact(p - q); } T H(int n, int r) const { if (n < 0 || r < 0) return (0); return r == 0 ? 1 : C(n + r - 1, r); } T NC(int p, int q) const { modint ret = 1; for (int i = 1; i <= q; i += 1) { ret = ret * p / i; p--; } return ret; } }; ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } bool is_prime(ll x) { if (x == 1) { return false; } for (ll i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } map<ll, int> prime_factor(ll n) { map<ll, int> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } const ll MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; struct BIT { // 1-indexed!!! int n; vector<int> bit; BIT() { init(); } BIT(int n) : n(n) { init(); } void init() { bit.clear(); bit.resize(n + 1, 0); } int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } int sum(int x, int y) { return sum(y) - sum(x - 1); } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } int lower_bound(int w) { if (w <= 0) return 0; int x = 0, r = 1; while (r < n) r <<= 1; for (int k = r; k > 0; k >>= 1) { if (x + k <= n && bit[x + k] < w) { w -= bit[x + k]; x += k; } } return x + 1; } }; struct LazySegmentTree { // private: ll n; vector<ll> node, lazy; // public: LazySegmentTree(vector<ll> v) { int sz = (int)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1); lazy.resize(2 * n - 1, 0); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2]; } void eval(int k, int l, int r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r - l > 1) { lazy[2 * k + 1] += lazy[k] / 2; lazy[2 * k + 2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2 * k + 1, l, (l + r) / 2); add(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = node[2 * k + 1] + node[2 * k + 2]; } } ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return 0; if (a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; ll digit_sum(ll v) { ll ret = 0; while (v) { ret += (v % 10); v /= 10; } return ret; } template <typename T> struct Kruskal { struct edge { ll from, to; T cost; ll used; edge() {} edge(ll from, ll to, T cost) : from(from), to(to), cost(cost), used(0) {} bool operator<(const edge &e) const { return cost < e.cost; } }; ll n; vector<ll> p, r; vector<edge> edges; Kruskal() {} Kruskal(ll n) : n(n) {} void init(ll n) { r.assign(n, 1); p.resize(n); iota(p.begin(), p.end(), 0); } ll find(ll x) { return (x == p[x] ? x : p[x] = find(p[x])); } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) swap(x, y); r[x] += r[y]; p[y] = x; } void add_edge(ll u, ll v, T c) { edges.emplace_back(u, v, c); } T build() { sort(edges.begin(), edges.end()); init(n); T res = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; } } return res; } T build(ll k) { sort(edges.begin(), edges.end()); init(n); T res = 0; ll cnt = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; cnt++; } if (cnt == k) { break; } } return res; } }; int LIS(int a[], int n) { vector<int> A(n, 0x3f3f3f3f); for (int i = 0; i < n; i++) *lower_bound(A.begin(), A.end(), a[i]) = a[i]; return find(A.begin(), A.end(), 0x3f3f3f3f) - A.begin(); } // string maze[1010]; // //ll maze[100][100]; // ll grid_bfs(ll H, ll W, ll sx, ll sy, ll gx, ll gy) // { // //O(E) // int dx[4] = {1, 0, -1, 0}; // int dy[4] = {0, 1, 0, -1}; // vector<vector<ll>> dist(H, vector<ll>(W, -1)); // dist[sy][sx] = 0; // queue<PL> q; // q.push({sy, sx}); // while (!q.empty()) // { // ll x, y; // tie(y, x) = q.front(); // q.pop(); // if (y == gy && x == gx) // { // break; // } // for (int t = 0; t < 4; t++) // { // ll nx = x + dx[t], ny = y + dy[t]; // if (nx < 0 || ny < 0 || nx >= W || ny >= H || dist[ny][nx] != -1 // || maze[ny][nx] == '#') // { // continue; // } // dist[ny][nx] = dist[y][x] + 1; // q.push({ny, nx}); // } // } // return dist[gy][gx]; // } // no verify ll bfs(ll n, ll start, vector<vector<PL>> Edges) { vector<ll> dist(n + 1, -1); dist[start] = 0; queue<PL> q; q.push({start, 0}); while (!q.empty()) { ll node, cost; tie(cost, node) = q.front(); q.pop(); for (auto p : Edges[node]) { ll v = p.first, cost = p.second; if (dist[v] == -1) { dist[v] = dist[node] + cost; q.push({v, cost}); } } } } vector<vector<ll>> warshall_floyd(ll n, vector<vector<ll>> g, ll INF) { // init vector<vector<ll>> c(10,vector<ll>(10,0)); for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (g[i][k] == INF || g[k][j] == INF) continue; g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } return g; } struct Dijkstra { ll n; vector<vector<pair<ll, ll>>> Edges; vector<ll> Dist; vector<ll> Prev; vector<ll> PathNum; Dijkstra(ll n) : n(n), Edges(n), Dist(n), Prev(n), PathNum(n) { Prev.assign(n, -1); }; void add_edge(ll a, ll b, ll c, bool directed = true) { if (directed) { Edges[a].emplace_back(make_pair(b, c)); } else { Edges[a].emplace_back(make_pair(b, c)); Edges[b].emplace_back(make_pair(a, c)); } } // O((E+V)logV) void build(int start) { priority_queue<P, vector<P>, greater<P>> queue; fill(Dist.begin(), Dist.end(), 1e+18); // 1e18 !?!? fill(Prev.begin(), Prev.end(), -1); // 1e18 !?!? Dist[start] = 0; PathNum[start] = 1; queue.push(PL(0, start)); while (!queue.empty()) { PL p = queue.top(); queue.pop(); int v = p.second; if (Dist[v] < p.first) continue; for (int i = 0; i < Edges[v].size(); i++) { PL e = Edges[v][i]; if (Dist[e.first] > Dist[v] + e.second) { Dist[e.first] = Dist[v] + e.second; queue.push(P(Dist[e.first], e.first)); Prev[e.first] = v; PathNum[e.first] = PathNum[v]; } else if (Dist[e.first] == Dist[v] + e.second) { PathNum[e.first] += PathNum[v]; PathNum[e.first] %= MOD; } } } } ll dist(ll t) { return Dist[t]; } vector<ll> get_path(ll t) { vector<ll> path; for (; t != -1; t = Prev[t]) { path.push_back(t); } reverse(path.begin(), path.end()); return path; } ll get_path_num(ll t) { return PathNum[t]; } // int solve() // { // ll v, e, r; // cin >> v >> e >> r; // Dijkstra dij(v); // for (int i = 0; i < e; i++) // { // ll a, b, c; // cin >> a >> b >> c; // dij.add_edge(a, b, c); // } // dij.build(r); // for (int i = 0; i < v; i++) // { // if (dij.dist(i) == 1e18) // { // cout << "INF" << endl; // } // else // { // cout << dij.dist(i) << endl; // cout << dij.get_path(i) << endl; // cout << dij.get_path_num(i) << endl; // } // } // return 0; // } }; struct CumulativeSum2D { int H; int W; vector<vector<ll>> data; CumulativeSum2D(int H, int W) : H(H), W(W), data(H + 1, vector<ll>(W + 1, 0LL)) {} void add(int x, int y, ll z) { data[x + 1][y + 1] += z; } void build() { for (int i = 1; i < data.size(); i++) { for (int j = 1; j < data[i].size(); j++) { data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1]; } } } void print() { for (int i = 0; i <= H; i++) { for (int j = 0; j <= W; j++) { cout << data[i][j] << " "; } cout << endl; } } ll query(int sx, int sy, int gx, int gy) { return (data[gy][gx] - data[sy - 1][gx] - data[gy][sx - 1] + data[sy - 1][sx - 1]); } }; struct LCA { int n, h; vector<vector<int>> par; vector<vector<pair<int, int>>> v; vector<ll> depth, dis; LCA(int sz) : n(sz), v(n), depth(n), dis(n) { h = 1; while ((1 << h) < n) h++; par.assign(h, vector<int>(n, -1)); } void add_edge(int x, int y, int z) { v[x].push_back({y, z}); v[y].push_back({x, z}); } void dfs(int x, int p, int d, ll di) { par[0][x] = p; depth[x] = d; dis[x] = di; for (auto to : v[x]) if (to.first != p) dfs(to.first, x, d + 1, di + to.second); } void build() { dfs(0, -1, 0, 0); for (int i = 0; i < h - 1; i++) { for (int j = 0; j < n; j++) { if (par[i][j] < 0) par[i + 1][j] = -1; else par[i + 1][j] = par[i][par[i][j]]; } } } int lca(int u, int v) { if (depth[u] > depth[v]) swap(u, v); for (int i = 0; i < h; i++) if ((depth[v] - depth[u]) >> i & 1) v = par[i][v]; if (u == v) return u; for (int i = h - 1; i >= 0; i--) { if (par[i][u] != par[i][v]) { u = par[i][u]; v = par[i][v]; } } return par[0][u]; } ll dist(int u, int v) { return dis[u] + dis[v] - 2 * dis[lca(u, v)]; } // int solve() // { // ll n; // cin >> n; // LCA lca(n); // for (int i = 0; i < n - 1; i++) // { // ll u, v, w; // cin >> u >> v >> w; // lca.add_edge(u, v, w); // } // lca.build(); // ll q; // cin >> q; // while (q--) // { // ll a, b, c; // cin >> a >> b >> c; // cout << (lca.dist(a, b) + lca.dist(b, c) + lca.dist(c, a)) / 2 << // endl; // } // return 0; // } }; vector<ll> compress(vector<ll> r) { // 1-indexed set<ll> se; for (int i = 0; i < r.size(); i++) { se.insert(r[i]); } map<ll, ll> m; ll cnt = 1; for (auto t : se) { m[t] = cnt; cnt++; } for (int i = 0; i < r.size(); i++) { r[i] = m[r[i]]; } return r; } template <class Abel> struct WeightedUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; vector<int> z_algorithm(const string &s) { /* Z[i] は - 文字列 S=S[0]+S[1]+⋯+S[|S|−1] - 文字列 S[i]+S[i+1]+⋯+S[|S|−1] の最長共通接頭辞の長さ */ // https://qiita.com/Pro_ktmr/items/16904c9570aa0953bf05#1-z-algorithm-%E3%81%A7%E6%B1%82%E3%82%81%E3%82%8B-z-%E9%85%8D%E5%88%97%E3%81%A8%E3%81%AF vector<int> prefix(s.size()); for (int i = 1, j = 0; i < s.size(); i++) { if (i + prefix[i - j] < j + prefix[j]) { prefix[i] = prefix[i - j]; } else { int k = max(0, j + prefix[j] - i); while (i + k < s.size() && s[k] == s[i + k]) ++k; prefix[i] = k; j = i; } } prefix[0] = (int)s.size(); return prefix; } void YES() { cout << "YES" << endl; exit(0); } void NO() { cout << "NO" << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } void m1() { cout << -1 << endl; exit(0); } template <typename T> void out(const T t) { cout << t << '\n'; } template <typename T> void fout(const T t) { cout << fixed << setprecision(10) << t << '\n'; } /*------------------------------*/ void solve() { string s, t; cin >> s >> t; map<char, int> m; for (int i = 0; i < s.size(); i++) { m[s[i]] = 1; } for (int i = 0; i < t.size(); i++) { if (m[t[i]] == 0) { m1(); } } vector<ll> next[26]; for (int i = 0; i < s.size(); i++) { next[s[i] - 'a'].push_back(i); } ll now = -1; ll ans = 0; for (int i = 0; i < t.size(); i++) { ll index = lower_bound(ALL(next[t[i] - 'a']), now) - next[t[i] - 'a'].begin(); ll v = next[t[i] - 'a'][index]; if (index == next[t[i] - 'a'].size()) { // index = lower_bound(ALL(next[t[i] - 'a']), -1) - next[t[i] - // 'a'].begin(); v = next[t[i] - 'a'][0]; ans += (s.size() - now) + v; } else { ans += v - now; } now = v; } out(ans); } // g++.exe bbb.cpp -std=c++14 int main() { cout.precision(10); ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } // IMOSs//https://imoz.jp/algorithms/imos_method.html /*名前 accumulate(ALL(b),0LL) prev_permutation(ALL(v)) 辞書順で一個前の順列を構築する bitcount __builtin_popcountll 二次元累積和 CumulativeSum2D 10進数の桁和 digit_sum (b*b+c*c)**0.5 hypot cout << fixed << setprecision(10) << ans << endl; // 文字列t ->整数 atoi(t.c_str()); // 文字列t ->long long整数 stoll(t); ローカルではつかえない */ /* */ /* ********** 区間 ********** L=(1,0,1,1,3,4) C(1,3,0,1,1) 配列Lの中で x 以上 y 未満の値が何個あるのかが、累積和を使うとわかる。 具体的には C の累積和を S とすると、S[ y ] - S[ x ] で求められる ********** 木 ********** */ /*実装例 zaatu sort(ALL(c)); c.erase(unique(ALL(c)), end(c)); ******* 再帰 ******* https://atcoder.jp/contests/abc015/tasks/abc015_3 ********** DP ********** ・ナップサックDP https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_C 個数制限なしナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_B 01ナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_F 01ナップサック N<=100,W<=10^9,v<=100 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_H 巨大ナップザック N=40 w<10^15 , v<10^15 解)半分全列挙して、wi > wj かつvi < vj となるようなiを除いて、二分探索 ・部分文字列DP https://qiita.com/drken/items/a207e5ae3ea2cf17f4bd next[i][c] := S の i 文字目以降で最初に文字 c が登場する index https://www.hackerrank.com/contests/bbc003/challenges/bbc003-e/submissions/code/1321355726 (部分文字列の中で+の個数の偶奇によって、カウントするか決める) No.852 連続部分文字列 https://yukicoder.me/problems/no/852/editorial 連続な部分文字列における、文字の種類数の平均を求める 解)右端を固定すると dp[i+1] = dp[i] + (左にs[i]がでてきた位置との距離) E - Common Subsequence https://atcoder.jp/contests/abc130/tasks/abc130_e 文字列S、Tの共通整数列の数を求める 遷移はLCSのようにできるが、重複が発生するので除く必要がある ・桁DP 1 https://atcoder.jp/contests/abc029/tasks/abc029_d n以下の数字の中で現れた1の数を求める dp[i][j][k]:i桁目まで見たときに1の個数がk個の数字の個数 S - Digit Sum https://atcoder.jp/contests/dp/tasks/dp_s n以下の数字の中で、各桁の総和がDの倍数となるものを数える E - Almost Everywhere Zero https://atcoder.jp/contests/abc154/tasks/abc154_e n以下の数字の中で,0でない数字が丁度K個あるものの数を数える E - Sum Equals Xor https://atcoder.jp/contests/abc129/tasks/abc129_e a+b<=L,a+b=a^bとなる(a,b)を数える ************* 組み合わせ ************* https://codeforces.com/contest/888/problem/D 少なくともn-k個がpi=iとなるような順列の組の数え上げ →pi≠iとなる順列をモンモール数という。n-k~n個をpi=iと固定したときに、他の要素がpi≠iとなるような組み合わせの数(モンモール数)の積をとる https://codeforces.com/problemset/problem/322/B 赤・青・緑の花束が存在し、ある色を3本or全ての色を1本ずつ使ったときに、できる花束の最大数 https://atcoder.jp/contests/abc021/tasks/abc021_d https://codeforces.com/problemset/problem/1288/C 1 <=a1 <= a2 <= ... <= ak <= n となる(a1,a2..ak)の組の数 →等号がなければ単純にn個の要素の中からk個を選べばよい -> C(n,k) →等号がある場合は重複を許してk個選べばよい      -> H(n,k) http://codeforces.com/contest/1312/problem/D aj < aj+i < ... ai > ....ak > ak+1 かつ同じ数字のペアが一つだけ含まれるような組の数 D - Blue and Red Balls https://atcoder.jp/contests/abc132/tasks/abc132_d 青と赤のボールを並べ、連続している青を1~k個作ったときの並べ方の数 ************* 最短経路 ************* https://atcoder.jp/contests/joi2014yo/tasks/joi2014yo_e 移動できるノード数に制限がある場合の最短経路問題 →事前に幅優先探索でノード毎に移動できるノードを求めて、ダイクストラ ************* 遅延セグ木 ************* https://atcoder.jp/contests/abc153/submissions/10165699 *********** BIT *********** https://atcoder.jp/contests/abc157/tasks/abc157_e(アルファベット毎にBITもつやつ) https://hoj.hamako-ths.ed.jp/onlinejudge/problems/1276(中央値求めるやつ) *********** 数学 *********** 大きい数の約数 https://yukicoder.me/problems/no/677 10^nの全ての正の約数を列挙 →10^kは素因数として2^k,5^kしかもたないので、それぞれをかけ合わせる 例えば10は2^1*5*1なので、2^0,2^1に5^0,5^1をそれぞれかけ合わせればよい。 */
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, ll> PL; const ll mod = 1000000007; // const ll mod = 998244353; const ll MOD = 1000000007; const ll INF = 1LL << 60; #define PI (acos(-1)) #define ALL(c) (c).begin(), (c).end() #define en '\n' #define endl '\n' template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << "(" << pa.first << "," << pa.second << ")"; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; } #define dbg(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl; // template <typename A, size_t N, typename T> template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; template <typename T> struct Combination { vector<T> _fact, _rfact, _inv; Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) { _fact[0] = _rfact[sz] = _inv[0] = 1; for (int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i; _rfact[sz] /= _fact[sz]; for (int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1); for (int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1]; } inline T fact(int k) const { return _fact[k]; } inline T rfact(int k) const { return _rfact[k]; } inline T inv(int k) const { return _inv[k]; } T P(int n, int r) const { if (r < 0 || n < r) return 0; return fact(n) * rfact(n - r); } T C(int p, int q) const { if (q < 0 || p < q) return 0; return fact(p) * rfact(q) * rfact(p - q); } T H(int n, int r) const { if (n < 0 || r < 0) return (0); return r == 0 ? 1 : C(n + r - 1, r); } T NC(int p, int q) const { modint ret = 1; for (int i = 1; i <= q; i += 1) { ret = ret * p / i; p--; } return ret; } }; ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } bool is_prime(ll x) { if (x == 1) { return false; } for (ll i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } map<ll, int> prime_factor(ll n) { map<ll, int> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } vector<ll> divisor(ll n) { vector<ll> ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } const ll MAX = 510000; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; struct BIT { // 1-indexed!!! int n; vector<int> bit; BIT() { init(); } BIT(int n) : n(n) { init(); } void init() { bit.clear(); bit.resize(n + 1, 0); } int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } int sum(int x, int y) { return sum(y) - sum(x - 1); } void add(int i, int x) { while (i <= n) { bit[i] += x; i += i & -i; } } int lower_bound(int w) { if (w <= 0) return 0; int x = 0, r = 1; while (r < n) r <<= 1; for (int k = r; k > 0; k >>= 1) { if (x + k <= n && bit[x + k] < w) { w -= bit[x + k]; x += k; } } return x + 1; } }; struct LazySegmentTree { // private: ll n; vector<ll> node, lazy; // public: LazySegmentTree(vector<ll> v) { int sz = (int)v.size(); n = 1; while (n < sz) n *= 2; node.resize(2 * n - 1); lazy.resize(2 * n - 1, 0); for (int i = 0; i < sz; i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2]; } void eval(int k, int l, int r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r - l > 1) { lazy[2 * k + 1] += lazy[k] / 2; lazy[2 * k + 2] += lazy[k] / 2; } lazy[k] = 0; } } void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r - l) * x; eval(k, l, r); } else { add(a, b, x, 2 * k + 1, l, (l + r) / 2); add(a, b, x, 2 * k + 2, (l + r) / 2, r); node[k] = node[2 * k + 1] + node[2 * k + 2]; } } ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; eval(k, l, r); if (b <= l || r <= a) return 0; if (a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2); ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r); return vl + vr; } }; ll digit_sum(ll v) { ll ret = 0; while (v) { ret += (v % 10); v /= 10; } return ret; } template <typename T> struct Kruskal { struct edge { ll from, to; T cost; ll used; edge() {} edge(ll from, ll to, T cost) : from(from), to(to), cost(cost), used(0) {} bool operator<(const edge &e) const { return cost < e.cost; } }; ll n; vector<ll> p, r; vector<edge> edges; Kruskal() {} Kruskal(ll n) : n(n) {} void init(ll n) { r.assign(n, 1); p.resize(n); iota(p.begin(), p.end(), 0); } ll find(ll x) { return (x == p[x] ? x : p[x] = find(p[x])); } bool same(ll x, ll y) { return find(x) == find(y); } void unite(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) swap(x, y); r[x] += r[y]; p[y] = x; } void add_edge(ll u, ll v, T c) { edges.emplace_back(u, v, c); } T build() { sort(edges.begin(), edges.end()); init(n); T res = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; } } return res; } T build(ll k) { sort(edges.begin(), edges.end()); init(n); T res = 0; ll cnt = 0; for (auto &e : edges) { if (!same(e.from, e.to)) { res += e.cost; unite(e.from, e.to); e.used = 1; cnt++; } if (cnt == k) { break; } } return res; } }; int LIS(int a[], int n) { vector<int> A(n, 0x3f3f3f3f); for (int i = 0; i < n; i++) *lower_bound(A.begin(), A.end(), a[i]) = a[i]; return find(A.begin(), A.end(), 0x3f3f3f3f) - A.begin(); } // string maze[1010]; // //ll maze[100][100]; // ll grid_bfs(ll H, ll W, ll sx, ll sy, ll gx, ll gy) // { // //O(E) // int dx[4] = {1, 0, -1, 0}; // int dy[4] = {0, 1, 0, -1}; // vector<vector<ll>> dist(H, vector<ll>(W, -1)); // dist[sy][sx] = 0; // queue<PL> q; // q.push({sy, sx}); // while (!q.empty()) // { // ll x, y; // tie(y, x) = q.front(); // q.pop(); // if (y == gy && x == gx) // { // break; // } // for (int t = 0; t < 4; t++) // { // ll nx = x + dx[t], ny = y + dy[t]; // if (nx < 0 || ny < 0 || nx >= W || ny >= H || dist[ny][nx] != -1 // || maze[ny][nx] == '#') // { // continue; // } // dist[ny][nx] = dist[y][x] + 1; // q.push({ny, nx}); // } // } // return dist[gy][gx]; // } // no verify ll bfs(ll n, ll start, vector<vector<PL>> Edges) { vector<ll> dist(n + 1, -1); dist[start] = 0; queue<PL> q; q.push({start, 0}); while (!q.empty()) { ll node, cost; tie(cost, node) = q.front(); q.pop(); for (auto p : Edges[node]) { ll v = p.first, cost = p.second; if (dist[v] == -1) { dist[v] = dist[node] + cost; q.push({v, cost}); } } } } vector<vector<ll>> warshall_floyd(ll n, vector<vector<ll>> g, ll INF) { // init vector<vector<ll>> c(10,vector<ll>(10,0)); for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (g[i][k] == INF || g[k][j] == INF) continue; g[i][j] = min(g[i][j], g[i][k] + g[k][j]); } } } return g; } struct Dijkstra { ll n; vector<vector<pair<ll, ll>>> Edges; vector<ll> Dist; vector<ll> Prev; vector<ll> PathNum; Dijkstra(ll n) : n(n), Edges(n), Dist(n), Prev(n), PathNum(n) { Prev.assign(n, -1); }; void add_edge(ll a, ll b, ll c, bool directed = true) { if (directed) { Edges[a].emplace_back(make_pair(b, c)); } else { Edges[a].emplace_back(make_pair(b, c)); Edges[b].emplace_back(make_pair(a, c)); } } // O((E+V)logV) void build(int start) { priority_queue<P, vector<P>, greater<P>> queue; fill(Dist.begin(), Dist.end(), 1e+18); // 1e18 !?!? fill(Prev.begin(), Prev.end(), -1); // 1e18 !?!? Dist[start] = 0; PathNum[start] = 1; queue.push(PL(0, start)); while (!queue.empty()) { PL p = queue.top(); queue.pop(); int v = p.second; if (Dist[v] < p.first) continue; for (int i = 0; i < Edges[v].size(); i++) { PL e = Edges[v][i]; if (Dist[e.first] > Dist[v] + e.second) { Dist[e.first] = Dist[v] + e.second; queue.push(P(Dist[e.first], e.first)); Prev[e.first] = v; PathNum[e.first] = PathNum[v]; } else if (Dist[e.first] == Dist[v] + e.second) { PathNum[e.first] += PathNum[v]; PathNum[e.first] %= MOD; } } } } ll dist(ll t) { return Dist[t]; } vector<ll> get_path(ll t) { vector<ll> path; for (; t != -1; t = Prev[t]) { path.push_back(t); } reverse(path.begin(), path.end()); return path; } ll get_path_num(ll t) { return PathNum[t]; } // int solve() // { // ll v, e, r; // cin >> v >> e >> r; // Dijkstra dij(v); // for (int i = 0; i < e; i++) // { // ll a, b, c; // cin >> a >> b >> c; // dij.add_edge(a, b, c); // } // dij.build(r); // for (int i = 0; i < v; i++) // { // if (dij.dist(i) == 1e18) // { // cout << "INF" << endl; // } // else // { // cout << dij.dist(i) << endl; // cout << dij.get_path(i) << endl; // cout << dij.get_path_num(i) << endl; // } // } // return 0; // } }; struct CumulativeSum2D { int H; int W; vector<vector<ll>> data; CumulativeSum2D(int H, int W) : H(H), W(W), data(H + 1, vector<ll>(W + 1, 0LL)) {} void add(int x, int y, ll z) { data[x + 1][y + 1] += z; } void build() { for (int i = 1; i < data.size(); i++) { for (int j = 1; j < data[i].size(); j++) { data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1]; } } } void print() { for (int i = 0; i <= H; i++) { for (int j = 0; j <= W; j++) { cout << data[i][j] << " "; } cout << endl; } } ll query(int sx, int sy, int gx, int gy) { return (data[gy][gx] - data[sy - 1][gx] - data[gy][sx - 1] + data[sy - 1][sx - 1]); } }; struct LCA { int n, h; vector<vector<int>> par; vector<vector<pair<int, int>>> v; vector<ll> depth, dis; LCA(int sz) : n(sz), v(n), depth(n), dis(n) { h = 1; while ((1 << h) < n) h++; par.assign(h, vector<int>(n, -1)); } void add_edge(int x, int y, int z) { v[x].push_back({y, z}); v[y].push_back({x, z}); } void dfs(int x, int p, int d, ll di) { par[0][x] = p; depth[x] = d; dis[x] = di; for (auto to : v[x]) if (to.first != p) dfs(to.first, x, d + 1, di + to.second); } void build() { dfs(0, -1, 0, 0); for (int i = 0; i < h - 1; i++) { for (int j = 0; j < n; j++) { if (par[i][j] < 0) par[i + 1][j] = -1; else par[i + 1][j] = par[i][par[i][j]]; } } } int lca(int u, int v) { if (depth[u] > depth[v]) swap(u, v); for (int i = 0; i < h; i++) if ((depth[v] - depth[u]) >> i & 1) v = par[i][v]; if (u == v) return u; for (int i = h - 1; i >= 0; i--) { if (par[i][u] != par[i][v]) { u = par[i][u]; v = par[i][v]; } } return par[0][u]; } ll dist(int u, int v) { return dis[u] + dis[v] - 2 * dis[lca(u, v)]; } // int solve() // { // ll n; // cin >> n; // LCA lca(n); // for (int i = 0; i < n - 1; i++) // { // ll u, v, w; // cin >> u >> v >> w; // lca.add_edge(u, v, w); // } // lca.build(); // ll q; // cin >> q; // while (q--) // { // ll a, b, c; // cin >> a >> b >> c; // cout << (lca.dist(a, b) + lca.dist(b, c) + lca.dist(c, a)) / 2 << // endl; // } // return 0; // } }; vector<ll> compress(vector<ll> r) { // 1-indexed set<ll> se; for (int i = 0; i < r.size(); i++) { se.insert(r[i]); } map<ll, ll> m; ll cnt = 1; for (auto t : se) { m[t] = cnt; cnt++; } for (int i = 0; i < r.size(); i++) { r[i] = m[r[i]]; } return r; } template <class Abel> struct WeightedUnionFind { vector<int> par; vector<int> rank; vector<Abel> diff_weight; WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0) { init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0) { par.resize(n); rank.resize(n); diff_weight.resize(n); for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x) { root(x); return diff_weight[x]; } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y, Abel w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y), w = -w; if (rank[x] == rank[y]) ++rank[x]; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y) { return weight(y) - weight(x); } }; vector<int> z_algorithm(const string &s) { /* Z[i] は - 文字列 S=S[0]+S[1]+⋯+S[|S|−1] - 文字列 S[i]+S[i+1]+⋯+S[|S|−1] の最長共通接頭辞の長さ */ // https://qiita.com/Pro_ktmr/items/16904c9570aa0953bf05#1-z-algorithm-%E3%81%A7%E6%B1%82%E3%82%81%E3%82%8B-z-%E9%85%8D%E5%88%97%E3%81%A8%E3%81%AF vector<int> prefix(s.size()); for (int i = 1, j = 0; i < s.size(); i++) { if (i + prefix[i - j] < j + prefix[j]) { prefix[i] = prefix[i - j]; } else { int k = max(0, j + prefix[j] - i); while (i + k < s.size() && s[k] == s[i + k]) ++k; prefix[i] = k; j = i; } } prefix[0] = (int)s.size(); return prefix; } void YES() { cout << "YES" << endl; exit(0); } void NO() { cout << "NO" << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } void m1() { cout << -1 << endl; exit(0); } template <typename T> void out(const T t) { cout << t << '\n'; } template <typename T> void fout(const T t) { cout << fixed << setprecision(10) << t << '\n'; } /*------------------------------*/ void solve() { string s, t; cin >> s >> t; map<char, int> m; for (int i = 0; i < s.size(); i++) { m[s[i]] = 1; } for (int i = 0; i < t.size(); i++) { if (m[t[i]] == 0) { m1(); } } vector<ll> next[26]; for (int i = 0; i < s.size(); i++) { next[s[i] - 'a'].push_back(i); } ll now = -1; ll ans = 0; for (int i = 0; i < t.size(); i++) { ll index = upper_bound(ALL(next[t[i] - 'a']), now) - next[t[i] - 'a'].begin(); ll v = next[t[i] - 'a'][index]; if (index == next[t[i] - 'a'].size()) { v = next[t[i] - 'a'][0]; ans += (s.size() - now) + v; } else { ans += v - now; } now = v; } out(ans); } // g++.exe bbb.cpp -std=c++14 int main() { cout.precision(10); ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } // IMOSs//https://imoz.jp/algorithms/imos_method.html /*名前 accumulate(ALL(b),0LL) prev_permutation(ALL(v)) 辞書順で一個前の順列を構築する bitcount __builtin_popcountll 二次元累積和 CumulativeSum2D 10進数の桁和 digit_sum (b*b+c*c)**0.5 hypot cout << fixed << setprecision(10) << ans << endl; // 文字列t ->整数 atoi(t.c_str()); // 文字列t ->long long整数 stoll(t); ローカルではつかえない */ /* */ /* ********** 区間 ********** L=(1,0,1,1,3,4) C(1,3,0,1,1) 配列Lの中で x 以上 y 未満の値が何個あるのかが、累積和を使うとわかる。 具体的には C の累積和を S とすると、S[ y ] - S[ x ] で求められる ********** 木 ********** */ /*実装例 zaatu sort(ALL(c)); c.erase(unique(ALL(c)), end(c)); ******* 再帰 ******* https://atcoder.jp/contests/abc015/tasks/abc015_3 ********** DP ********** ・ナップサックDP https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_C 個数制限なしナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_B 01ナップサック N<=100,W<=10000,v<=1000 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/all/DPL_1_F 01ナップサック N<=100,W<=10^9,v<=100 https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/1/DPL_1_H 巨大ナップザック N=40 w<10^15 , v<10^15 解)半分全列挙して、wi > wj かつvi < vj となるようなiを除いて、二分探索 ・部分文字列DP https://qiita.com/drken/items/a207e5ae3ea2cf17f4bd next[i][c] := S の i 文字目以降で最初に文字 c が登場する index https://www.hackerrank.com/contests/bbc003/challenges/bbc003-e/submissions/code/1321355726 (部分文字列の中で+の個数の偶奇によって、カウントするか決める) No.852 連続部分文字列 https://yukicoder.me/problems/no/852/editorial 連続な部分文字列における、文字の種類数の平均を求める 解)右端を固定すると dp[i+1] = dp[i] + (左にs[i]がでてきた位置との距離) E - Common Subsequence https://atcoder.jp/contests/abc130/tasks/abc130_e 文字列S、Tの共通整数列の数を求める 遷移はLCSのようにできるが、重複が発生するので除く必要がある ・桁DP 1 https://atcoder.jp/contests/abc029/tasks/abc029_d n以下の数字の中で現れた1の数を求める dp[i][j][k]:i桁目まで見たときに1の個数がk個の数字の個数 S - Digit Sum https://atcoder.jp/contests/dp/tasks/dp_s n以下の数字の中で、各桁の総和がDの倍数となるものを数える E - Almost Everywhere Zero https://atcoder.jp/contests/abc154/tasks/abc154_e n以下の数字の中で,0でない数字が丁度K個あるものの数を数える E - Sum Equals Xor https://atcoder.jp/contests/abc129/tasks/abc129_e a+b<=L,a+b=a^bとなる(a,b)を数える ************* 組み合わせ ************* https://codeforces.com/contest/888/problem/D 少なくともn-k個がpi=iとなるような順列の組の数え上げ →pi≠iとなる順列をモンモール数という。n-k~n個をpi=iと固定したときに、他の要素がpi≠iとなるような組み合わせの数(モンモール数)の積をとる https://codeforces.com/problemset/problem/322/B 赤・青・緑の花束が存在し、ある色を3本or全ての色を1本ずつ使ったときに、できる花束の最大数 https://atcoder.jp/contests/abc021/tasks/abc021_d https://codeforces.com/problemset/problem/1288/C 1 <=a1 <= a2 <= ... <= ak <= n となる(a1,a2..ak)の組の数 →等号がなければ単純にn個の要素の中からk個を選べばよい -> C(n,k) →等号がある場合は重複を許してk個選べばよい      -> H(n,k) http://codeforces.com/contest/1312/problem/D aj < aj+i < ... ai > ....ak > ak+1 かつ同じ数字のペアが一つだけ含まれるような組の数 D - Blue and Red Balls https://atcoder.jp/contests/abc132/tasks/abc132_d 青と赤のボールを並べ、連続している青を1~k個作ったときの並べ方の数 ************* 最短経路 ************* https://atcoder.jp/contests/joi2014yo/tasks/joi2014yo_e 移動できるノード数に制限がある場合の最短経路問題 →事前に幅優先探索でノード毎に移動できるノードを求めて、ダイクストラ ************* 遅延セグ木 ************* https://atcoder.jp/contests/abc153/submissions/10165699 *********** BIT *********** https://atcoder.jp/contests/abc157/tasks/abc157_e(アルファベット毎にBITもつやつ) https://hoj.hamako-ths.ed.jp/onlinejudge/problems/1276(中央値求めるやつ) *********** 数学 *********** 大きい数の約数 https://yukicoder.me/problems/no/677 10^nの全ての正の約数を列挙 →10^kは素因数として2^k,5^kしかもたないので、それぞれをかけ合わせる 例えば10は2^1*5*1なので、2^0,2^1に5^0,5^1をそれぞれかけ合わせればよい。 */
[ "identifier.change", "call.function.change", "expression.operation.binary.change" ]
739,589
739,591
u644778646
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(void) { string s; string t; cin >> s; cin >> t; map<char, vector<int>> mp; rep(i, s.size()) { mp[s[i]].push_back(i); mp[s[i]].push_back(i + s.size()); } for (char i = 'a'; i <= 'z'; i++) { if (mp[i].empty()) continue; sort(mp[i].begin(), mp[i].end()); /*rep(j, mp[i].size()) cout<<mp[i][j]<<" "; cout<<endl;*/ } ll ans = 0; ll bef = -1; rep(i, t.size()) { if (mp[t[i]].empty()) { cout << -1 << endl; return 0; } auto p = upper_bound(mp[t[i]].begin(), mp[t[i]].end(), bef); ll idx = (ll)*p; ans += (idx - bef); bef = idx; if (idx > s.size()) bef -= (ll)(s.size()); // cout<<*idx<<endl; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(void) { string s; string t; cin >> s; cin >> t; map<char, vector<int>> mp; rep(i, s.size()) { mp[s[i]].push_back(i); mp[s[i]].push_back(i + s.size()); } for (char i = 'a'; i <= 'z'; i++) { if (mp[i].empty()) continue; sort(mp[i].begin(), mp[i].end()); } ll ans = 0; ll bef = -1; rep(i, t.size()) { if (mp[t[i]].empty()) { cout << -1 << endl; return 0; } auto p = upper_bound(mp[t[i]].begin(), mp[t[i]].end(), bef); ll idx = (ll)*p; ans += (idx - bef); bef = idx; if (idx >= s.size()) bef -= (ll)(s.size()); } cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,592
739,593
u247576416
cpp
p02937
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define MOD (1000000007) using namespace std; typedef long long int Int; constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); } vector<int> alpha[30]; int main(void) { string s, t; cin >> s >> t; Int N = s.size(); map<char, int> ms; for (int i = 0; i < s.size(); i++) { ms[s[i]]++; alpha[s[i] - 'a'].push_back(i + 1); } for (auto it : t) { if (ms.find(it) == ms.end()) { cout << -1 << endl; return 0; } } Int length = 0; for (int i = 0; i < t.size();) { Int prev_num = 0; Int num = 0; while (true) { int index = t[i] - 'a'; auto itr = lower_bound(alpha[index].begin(), alpha[index].end(), num); if (itr == alpha[index].end()) { length += (N - num); break; } num = *itr; length += (num - prev_num); prev_num = num; i++; if (i >= t.size()) { break; } } } cout << length << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define MOD (1000000007) using namespace std; typedef long long int Int; constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); } vector<int> alpha[30]; int main(void) { string s, t; cin >> s >> t; Int N = s.size(); map<char, int> ms; for (int i = 0; i < s.size(); i++) { ms[s[i]]++; alpha[s[i] - 'a'].push_back(i + 1); } for (auto it : t) { if (ms.find(it) == ms.end()) { cout << -1 << endl; return 0; } } Int length = 0; for (int i = 0; i < t.size();) { Int prev_num = 0; Int num = 0; while (true) { int index = t[i] - 'a'; auto itr = upper_bound(alpha[index].begin(), alpha[index].end(), num); if (itr == alpha[index].end()) { length += (N - num); break; } num = *itr; length += (num - prev_num); prev_num = num; i++; if (i >= t.size()) { break; } } } cout << length << endl; return 0; }
[ "identifier.change", "call.function.change" ]
739,602
739,603
u498141549
cpp
p02937
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define MOD (1000000007) using namespace std; typedef long long int Int; constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); } vector<int> alpha[30]; int main(void) { string s, t; cin >> s >> t; Int N = s.size(); map<char, int> ms; for (int i = 0; i < s.size(); i++) { ms[s[i]]++; alpha[s[i] - 'a'].push_back(i + 1); } for (auto it : t) { if (ms.find(it) == ms.end()) { cout << -1 << endl; return 0; } } Int length = 0; for (int i = 0; i < t.size();) { int prev_num = 0; int num = 0; while (true) { int index = t[i] - 'a'; auto itr = lower_bound(alpha[index].begin(), alpha[index].end(), num); if (itr == alpha[index].end()) { length += (N - num); break; } num = *itr; length += (num - prev_num); prev_num = num; i++; if (i >= t.size()) { break; } } } cout << length << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define MOD (1000000007) using namespace std; typedef long long int Int; constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n - 1); } vector<int> alpha[30]; int main(void) { string s, t; cin >> s >> t; Int N = s.size(); map<char, int> ms; for (int i = 0; i < s.size(); i++) { ms[s[i]]++; alpha[s[i] - 'a'].push_back(i + 1); } for (auto it : t) { if (ms.find(it) == ms.end()) { cout << -1 << endl; return 0; } } Int length = 0; for (int i = 0; i < t.size();) { Int prev_num = 0; Int num = 0; while (true) { int index = t[i] - 'a'; auto itr = upper_bound(alpha[index].begin(), alpha[index].end(), num); if (itr == alpha[index].end()) { length += (N - num); break; } num = *itr; length += (num - prev_num); prev_num = num; i++; if (i >= t.size()) { break; } } } cout << length << endl; return 0; }
[ "variable_declaration.type.change", "identifier.change", "call.function.change" ]
739,604
739,603
u498141549
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i) #define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i) #define FOR(e, c) for (auto &e : c) #define SORT(v, n) sort(v, v + n); #define vsort(v) sort(v.begin(), v.end()); #define rvisort(v) sort(v.begin(), v.end(), greater<int>()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout << d << endl; #define coutd(d) cout << std::setprecision(10) << d << endl; #define cinline(n) getline(cin, n); #define replace_all(s, b, a) replace(s.begin(), s.end(), b, a); // #define int long long #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) int(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using ul = unsigned long; const int MOD = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e18; 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; } int LCM(int a, int b) { return a * b / GCD(a, b); } // 場所i以降で文字Cが最初に現れる位置 signed main() { string s, t; cin >> s >> t; vector<vector<int>> is(26); int n = s.size(); int m = s.size(); 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 (is[c].size() == 0) { cout << -1 << endl; return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p) + 1; if (p >= n) { p -= n; ans += n; } } ans += p; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i) #define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i) #define FOR(e, c) for (auto &e : c) #define SORT(v, n) sort(v, v + n); #define vsort(v) sort(v.begin(), v.end()); #define rvisort(v) sort(v.begin(), v.end(), greater<int>()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout << d << endl; #define coutd(d) cout << std::setprecision(10) << d << endl; #define cinline(n) getline(cin, n); #define replace_all(s, b, a) replace(s.begin(), s.end(), b, a); // #define int long long #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) int(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using ul = unsigned long; const int MOD = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e18; 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; } int LCM(int a, int b) { return a * b / GCD(a, b); } // 場所i以降で文字Cが最初に現れる位置 signed main() { string s, t; cin >> s >> t; vector<vector<int>> is(26); int n = s.size(); int m = t.size(); 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 (is[c].size() == 0) { cout << -1 << endl; return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p) + 1; if (p >= n) { p -= n; ans += n; } } ans += p; cout << ans << endl; }
[ "identifier.change" ]
739,607
739,608
u530107518
cpp
p02937
#include <algorithm> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define N (1000000000 + 7) #define INF 1e16 typedef long long ll; typedef pair<ll, ll> P; ll Abs(ll x, ll y) { if (x >= y) return x - y; else return y - x; } int main(void) { string s, t; cin >> s >> t; ll ssize = s.length(); ll tsize = t.length(); vector<ll> pos[26]; for (ll i = 0; i < ssize; i++) { pos[s[i] - 'a'].push_back(i + 1); } for (ll i = 0; i < tsize; i++) { ll x = t[i] - 'a'; auto itr = lower_bound(pos[x].begin(), pos[x].end(), 0); if (itr == pos[x].end()) { cout << -1 << endl; return 0; } } ll ans = 0; ll now = 0; ll cnt = 0; for (ll i = 0; i < tsize; i++) { ll x = t[i] - 'a'; auto itr = lower_bound(pos[x].begin(), pos[x].end(), now); if (itr != pos[x].end()) { ans = ssize * cnt + (*itr); now = (*itr); } else { cnt++; ans = ssize * cnt + pos[x][0]; now = pos[x][0]; } // cout<<now<<endl; } cout << ans << endl; return 0; }
#include <algorithm> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define N (1000000000 + 7) #define INF 1e16 typedef long long ll; typedef pair<ll, ll> P; ll Abs(ll x, ll y) { if (x >= y) return x - y; else return y - x; } int main(void) { string s, t; cin >> s >> t; ll ssize = s.length(); ll tsize = t.length(); vector<ll> pos[26]; for (ll i = 0; i < ssize; i++) { pos[s[i] - 'a'].push_back(i + 1); } for (ll i = 0; i < tsize; i++) { ll x = t[i] - 'a'; auto itr = lower_bound(pos[x].begin(), pos[x].end(), 0); if (itr == pos[x].end()) { cout << -1 << endl; return 0; } } ll ans = 0; ll now = 0; ll cnt = 0; for (ll i = 0; i < tsize; i++) { ll x = t[i] - 'a'; auto itr = upper_bound(pos[x].begin(), pos[x].end(), now); if (itr != pos[x].end()) { ans = ssize * cnt + (*itr); now = (*itr); } else { cnt++; ans = ssize * cnt + pos[x][0]; now = pos[x][0]; } // cout<<now<<endl; } cout << ans << endl; return 0; }
[ "identifier.change", "call.function.change" ]
739,609
739,610
u744305661
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define show(x) \ { \ for (auto i : x) { \ cout << i << " "; \ } \ cout << endl; \ } #define showm(m) \ { \ for (auto i : m) { \ cout << m.x << " "; \ } \ cout << endl; \ } typedef long long ll; typedef pair<int, int> P; ll gcd(int x, int y) { return y ? gcd(y, x % y) : x; } ll lcm(ll x, ll y) { return (x * y) / gcd(x, y); } int main() { string s, t; cin >> s >> t; vector<set<int>> alpha(26); rep(i, s.size()) { int id = s[i] - 'a'; alpha[id].insert(i); } ll ans = 0; int itr = -1; rep(i, t.size()) { int id = t[i] - 'a'; if (alpha[id].empty()) { cout << -1 << endl; return 0; } int new_itr = *alpha[id].upper_bound(itr); if (new_itr == alpha[id].size()) { // exist but over itr = -1; itr = *alpha[id].upper_bound(itr); ans += s.size(); } else { itr = new_itr; } } ans += itr + 1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define show(x) \ { \ for (auto i : x) { \ cout << i << " "; \ } \ cout << endl; \ } #define showm(m) \ { \ for (auto i : m) { \ cout << m.x << " "; \ } \ cout << endl; \ } typedef long long ll; typedef pair<int, int> P; ll gcd(int x, int y) { return y ? gcd(y, x % y) : x; } ll lcm(ll x, ll y) { return (x * y) / gcd(x, y); } int main() { string s, t; cin >> s >> t; vector<set<int>> alpha(26); rep(i, s.size()) { int id = s[i] - 'a'; alpha[id].insert(i); } ll ans = 0; int itr = -1; rep(i, t.size()) { int id = t[i] - 'a'; if (alpha[id].empty()) { cout << -1 << endl; return 0; } auto new_itr = alpha[id].upper_bound(itr); if (new_itr == alpha[id].end()) { itr = -1; itr = *alpha[id].upper_bound(itr); ans += s.size(); } else { itr = *new_itr; } } ans += itr + 1; cout << ans << endl; }
[ "call.function.change", "control_flow.branch.if.condition.change" ]
739,613
739,614
u317715099
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; /* 判定式を指定できるめぐる式二分探索 */ /* input: arr:行列、callback:判定方法の関数ポインタ、 * userQuery:判定に使用するための引数(省略可)*/ /* output: 条件を満たす要素の最小値(全て満たさなければ要素サイズを返す) */ /* 制約事項: * 行列のある要素に対して判定方法callbackを満たすとき、それより大きな要素も判定方法を満たす必要がある。 */ template <class X> int binarySearch_latest(vector<X> &arr, bool (*callback)(X, int), X userQuery = 0) { int ng = -1; int ok = (int)arr.size(); while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (callback(arr[mid], userQuery)) { ok = mid; } else { ng = mid; } } return ok; } /* 判定方法1 */ /* input: arrValue:行列の要素、user:任意に指定した引数*/ /* 指定した値userがarrValueより小さいとき真を返す */ template <class X> bool judge1(X arrValue, int user) { return (arrValue > (X)user); } int main() { string s, t; cin >> s; cin >> t; vector<vector<int>> alphamap(30); rep(i, s.size()) { int a = s[i] - 'a'; alphamap[a].push_back(i); } ll ansloop = 0; int cnt = 0; rep(i, t.size()) { // t[i]文字目を調査 int targalpha = t[i] - 'a'; if (alphamap[targalpha].size() == 0) { cout << "-1" << endl; return 0; } int add = binarySearch_latest(alphamap[targalpha], judge1, cnt); if (add == alphamap[targalpha].size()) { cnt = alphamap[targalpha][0]; ansloop++; } else { cnt = alphamap[targalpha][add]; } } ll ans = ((ll)ansloop * (ll)s.size()) + (ll)cnt + 1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; /* 判定式を指定できるめぐる式二分探索 */ /* input: arr:行列、callback:判定方法の関数ポインタ、 * userQuery:判定に使用するための引数(省略可)*/ /* output: 条件を満たす要素の最小値(全て満たさなければ要素サイズを返す) */ /* 制約事項: * 行列のある要素に対して判定方法callbackを満たすとき、それより大きな要素も判定方法を満たす必要がある。 */ template <class X> int binarySearch_latest(vector<X> &arr, bool (*callback)(X, int), X userQuery = 0) { int ng = -1; int ok = (int)arr.size(); while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (callback(arr[mid], userQuery)) { ok = mid; } else { ng = mid; } } return ok; } /* 判定方法1 */ /* input: arrValue:行列の要素、user:任意に指定した引数*/ /* 指定した値userがarrValueより小さいとき真を返す */ template <class X> bool judge1(X arrValue, int user) { return (arrValue > (X)user); } int main() { string s, t; cin >> s; cin >> t; vector<vector<int>> alphamap(30); rep(i, s.size()) { int a = s[i] - 'a'; alphamap[a].push_back(i); } ll ansloop = 0; int cnt = -1; rep(i, t.size()) { // t[i]文字目を調査 int targalpha = t[i] - 'a'; if (alphamap[targalpha].size() == 0) { cout << "-1" << endl; return 0; } int add = binarySearch_latest(alphamap[targalpha], judge1, cnt); if (add == alphamap[targalpha].size()) { cnt = alphamap[targalpha][0]; ansloop++; } else { cnt = alphamap[targalpha][add]; } } ll ans = ((ll)ansloop * (ll)s.size()) + (ll)cnt + 1; cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,615
739,616
u317715099
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; /* 判定式を指定できるめぐる式二分探索 */ /* input: arr:行列、callback:判定方法の関数ポインタ、 * userQuery:判定に使用するための引数(省略可)*/ /* output: 条件を満たす要素の最小値(全て満たさなければ要素サイズを返す) */ /* 制約事項: * 行列のある要素に対して判定方法callbackを満たすとき、それより大きな要素も判定方法を満たす必要がある。 */ template <class X> int binarySearch_latest(vector<X> &arr, bool (*callback)(X, int), X userQuery = 0) { int ng = -1; int ok = (int)arr.size(); while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (callback(arr[mid], userQuery)) { ok = mid; } else { ng = mid; } } return ok; } /* 判定方法1 */ /* input: arrValue:行列の要素、user:任意に指定した引数*/ /* 指定した値userがarrValueより小さいとき真を返す */ template <class X> bool judge1(X arrValue, int user) { return (arrValue >= (X)user); } int main() { string s, t; cin >> s; cin >> t; vector<vector<int>> alphamap(30); rep(i, s.size()) { int a = s[i] - 'a'; alphamap[a].push_back(i); } ll ansloop = 0; int cnt = 0; rep(i, t.size()) { // t[i]文字目を調査 int targalpha = t[i] - 'a'; if (alphamap[targalpha].size() == 0) { cout << "-1" << endl; return 0; } int add = binarySearch_latest(alphamap[targalpha], judge1, cnt); if (add == alphamap[targalpha].size()) { cnt = alphamap[targalpha][0]; ansloop++; } else { cnt = alphamap[targalpha][add]; } } ll ans = ((ll)ansloop * (ll)s.size()) + (ll)cnt + 1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; /* 判定式を指定できるめぐる式二分探索 */ /* input: arr:行列、callback:判定方法の関数ポインタ、 * userQuery:判定に使用するための引数(省略可)*/ /* output: 条件を満たす要素の最小値(全て満たさなければ要素サイズを返す) */ /* 制約事項: * 行列のある要素に対して判定方法callbackを満たすとき、それより大きな要素も判定方法を満たす必要がある。 */ template <class X> int binarySearch_latest(vector<X> &arr, bool (*callback)(X, int), X userQuery = 0) { int ng = -1; int ok = (int)arr.size(); while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (callback(arr[mid], userQuery)) { ok = mid; } else { ng = mid; } } return ok; } /* 判定方法1 */ /* input: arrValue:行列の要素、user:任意に指定した引数*/ /* 指定した値userがarrValueより小さいとき真を返す */ template <class X> bool judge1(X arrValue, int user) { return (arrValue > (X)user); } int main() { string s, t; cin >> s; cin >> t; vector<vector<int>> alphamap(30); rep(i, s.size()) { int a = s[i] - 'a'; alphamap[a].push_back(i); } ll ansloop = 0; int cnt = -1; rep(i, t.size()) { // t[i]文字目を調査 int targalpha = t[i] - 'a'; if (alphamap[targalpha].size() == 0) { cout << "-1" << endl; return 0; } int add = binarySearch_latest(alphamap[targalpha], judge1, cnt); if (add == alphamap[targalpha].size()) { cnt = alphamap[targalpha][0]; ansloop++; } else { cnt = alphamap[targalpha][add]; } } ll ans = ((ll)ansloop * (ll)s.size()) + (ll)cnt + 1; cout << ans << endl; }
[ "expression.operator.compare.change", "function.return_value.change", "expression.operation.binary.change", "literal.number.change", "variable_declaration.value.change" ]
739,617
739,616
u317715099
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair<int, int> P; constexpr ll INF = (1LL << 55); int main() { string s, t; cin >> s >> t; int n = sz(s); vector<set<int>> st(26); for (int i = 0; i < n; i++) { st[s[i] - 'a'].insert(i); st[s[i] - 'a'].insert(i + n); } ll res = 0; ll cnt = 0; int m = sz(t); int id = 0; for (int i = 0; i < m; i++) { if (st[t[i] - 'a'].empty()) { cout << -1 << endl; return 0; } auto itr = *st[t[i] - 'a'].upper_bound(id); if (itr >= n) itr %= n, cnt++; id = itr; } cout << cnt * n + id + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair<int, int> P; constexpr ll INF = (1LL << 55); int main() { string s, t; cin >> s >> t; int n = sz(s); vector<set<int>> st(26); for (int i = 0; i < n; i++) { st[s[i] - 'a'].insert(i); st[s[i] - 'a'].insert(i + n); } ll res = 0; ll cnt = 0; int m = sz(t); int id = -1; for (int i = 0; i < m; i++) { if (st[t[i] - 'a'].empty()) { cout << -1 << endl; return 0; } auto itr = *st[t[i] - 'a'].upper_bound(id); if (itr >= n) itr %= n, cnt++; id = itr; } cout << cnt * n + id + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,618
739,619
u108540384
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair<int, int> P; constexpr ll INF = (1LL << 55); int main() { string s, t; cin >> s >> t; int n = sz(s); vector<set<int>> st(26); for (int i = 0; i < n; i++) { st[s[i] - 'a'].insert(i); st[s[i] - 'a'].insert(i + n); } ll res = 0; ll cnt = 0; int m = sz(t); int id = 0; for (int i = 0; i < m; i++) { if (st[t[i] - 'a'].empty()) { cout << -1 << endl; return 0; } auto itr = *st[t[i] - 'a'].lower_bound(id); if (itr >= n) itr %= n, cnt++; id = itr; } cout << cnt * n + id + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair<int, int> P; constexpr ll INF = (1LL << 55); int main() { string s, t; cin >> s >> t; int n = sz(s); vector<set<int>> st(26); for (int i = 0; i < n; i++) { st[s[i] - 'a'].insert(i); st[s[i] - 'a'].insert(i + n); } ll res = 0; ll cnt = 0; int m = sz(t); int id = -1; for (int i = 0; i < m; i++) { if (st[t[i] - 'a'].empty()) { cout << -1 << endl; return 0; } auto itr = *st[t[i] - 'a'].upper_bound(id); if (itr >= n) itr %= n, cnt++; id = itr; } cout << cnt * n + id + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "call.function.change" ]
739,620
739,619
u108540384
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(s.size()) typedef long long ll; //部分列判定 -> 場所i以降で文字Cが最初に現れる位置を保存しておく //各文字が文字列のどの位置にあるかのリストを作る 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 res = 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; //文字cが何文字目にあるか if (p >= n) { p -= n; res += n; } } res += p; cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define sz(x) int(x.size()) typedef long long ll; //部分列判定 -> 場所i以降で文字Cが最初に現れる位置を保存しておく //各文字が文字列のどの位置にあるかのリストを作る 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 res = 0; int p = 0; // p以降 rep(i, m) { int c = t[i] - 'a'; if (sz(is[c]) == 0) { puts("-1"); return 0; } p = *lower_bound(is[c].begin(), is[c].end(), p) + 1; //文字cが何文字目にあるか if (p >= n) { p -= n; res += n; } } res += p; cout << res << endl; return 0; }
[ "preprocessor.define.value.change" ]
739,621
739,622
u108540384
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (ll i = a; i <= b; i++) #define FORD(i, a, b) for (ll i = a; i >= b; i--) #define FORL(i, x) for (int i = head[x]; i; i = nxt[i]) #define ALL(a) (a).begin(), (a).end() #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define PB push_back #define MP make_pair 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 main() { string s, t; cin >> s >> t; string ss = s; ss += s; ll n = s.length(); ll chap[2 * n + 1][26]; FOR(i, 0, 25) { chap[2 * n][i] = -1; } FORD(i, 2 * n - 1, 0) { FOR(j, 0, 25) { chap[i][j] = chap[i + 1][j]; } chap[i][ss[i] - 'a'] = i; } ll sum = 0; ll back = 0; FOR(i, 0, t.length() - 1) { // cout << chap[back][t[i]-'a'] << " " << back << endl; if (chap[back][t[i] - 'a'] == -1) { cout << -1 << endl; return 0; } sum += chap[back][t[i] - 'a'] - back; back = chap[back][t[i] - 'a'] % s.length(); // cout << sum << " " << back << endl; } cout << sum + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (ll i = a; i <= b; i++) #define FORD(i, a, b) for (ll i = a; i >= b; i--) #define FORL(i, x) for (int i = head[x]; i; i = nxt[i]) #define ALL(a) (a).begin(), (a).end() #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define PB push_back #define MP make_pair 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 main() { string s, t; cin >> s >> t; string ss = s; ss += s; ll n = s.length(); ll chap[2 * n + 1][26]; FOR(i, 0, 25) { chap[2 * n][i] = -1; } FORD(i, 2 * n - 1, 0) { FOR(j, 0, 25) { chap[i][j] = chap[i + 1][j]; } chap[i][ss[i] - 'a'] = i + 1; } ll sum = 0; ll back = 0; FOR(i, 0, t.length() - 1) { // cout << chap[back][t[i]-'a'] << " " << back << endl; if (chap[back][t[i] - 'a'] == -1) { cout << -1 << endl; return 0; } sum += chap[back][t[i] - 'a'] - back; back = chap[back][t[i] - 'a'] % s.length(); // cout << sum << " " << back << endl; } cout << sum << endl; return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
739,629
739,630
u054501336
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string S, T; cin >> S >> T; int n = S.size(), m = T.size(); vector<vector<int>> D(2 * n + 1, vector<int>(26, n + 1)); string U = S + S; for (int i = 2 * n; i > 0; i--) { for (int j = 0; j < 26; j++) D[i - 1][j] = D[i][j] + 1; int k = U[i - 1] - 'a'; D[i - 1][k] = 1; } int64_t ans = 0; int64_t cur = 0; for (int i = 0; i < m; i++) { int k = T[i] - 'a'; if (D[cur + 1][k] > n) { puts("-1"); return 0; } cur += D[cur + 1][k]; if (cur >= n) { ans++; cur -= n; } } cout << ans * n + cur + 1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S, T; cin >> S >> T; int n = S.size(), m = T.size(); vector<vector<int>> D(2 * n + 1, vector<int>(26, n + 1)); string U = S + S; for (int i = 2 * n; i > 0; i--) { for (int j = 0; j < 26; j++) D[i - 1][j] = D[i][j] + 1; int k = U[i - 1] - 'a'; D[i - 1][k] = 1; } int64_t ans = 0; int64_t cur = -1; for (int i = 0; i < m; i++) { int k = T[i] - 'a'; if (D[cur + 1][k] > n) { puts("-1"); return 0; } cur += D[cur + 1][k]; if (cur >= n) { ans++; cur -= n; } } cout << ans * n + cur + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,631
739,632
u268793453
cpp
p02937
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 1000000007; vector<vector<int>> nextidx(const string &s) { int n = s.size(); vector<vector<int>> ret(n + 1, vector<int>(26, n)); for (int i = n - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) ret[i][j] = ret[i + 1][j]; ret[i][s[i] - 'a'] = i; } return ret; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s, t; cin >> s >> t; map<char, int> cnts; for (int i = 0; i < (int)s.size(); ++i) { cnts[s[i]] = 1; } for (int i = 0; i < (int)t.size(); ++i) { if (cnts[t[i]] == 0) { cout << -1 << "\n"; return 0; } } int ns = s.size(); s += s; auto idx = nextidx(s); lint ret = 0; lint curr = 0; for (int i = 0; i < (int)t.size(); ++i) { curr = idx[curr][t[i] - 'a']; if (curr >= ns) { curr %= ns; ret += ns; } } cout << ret + curr + 1 << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 1000000007; vector<vector<int>> nextidx(const string &s) { int n = s.size(); vector<vector<int>> ret(n + 1, vector<int>(26, n)); for (int i = n - 1; i >= 0; --i) { for (int j = 0; j < 26; ++j) ret[i][j] = ret[i + 1][j]; ret[i][s[i] - 'a'] = i; } return ret; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s, t; cin >> s >> t; map<char, int> cnts; for (int i = 0; i < (int)s.size(); ++i) { cnts[s[i]] = 1; } for (int i = 0; i < (int)t.size(); ++i) { if (cnts[t[i]] == 0) { cout << -1 << "\n"; return 0; } } lint ns = s.size(); s += s; auto idx = nextidx(s); lint ret = 0; lint curr = 0; for (int i = 0; i < (int)t.size(); ++i) { curr = idx[curr][t[i] - 'a'] + 1; if (curr >= ns) { curr %= ns; ret += ns; } } cout << ret + curr << "\n"; return 0; }
[ "variable_declaration.type.change", "assignment.change", "expression.operation.binary.remove" ]
739,635
739,636
u756088996
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define INF 1000000007 #define LINF (1LL << 60) #define PI 3.14159265358979 typedef long long i64; typedef pair<i64, i64> P; inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; } 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; } string s, t; bool b[26]; vector<int> v[26]; void solve() { cin >> s >> t; int n = s.size(), m = t.size(); for (int i = 0; i < n; i++) b[s[i] - 'a'] = 1; for (int i = 0; i < m; i++) { if (!b[t[i] - 'a']) { cout << -1 << endl; return; } } for (int i = 0; i < n + n; i++) { v[s[i % n] - 'a'].push_back(i); } i64 cnt = 0, now = 0; for (int i = 0; i < m; i++) { int c = t[i] - 'a'; int nx = *lower_bound(v[c].begin(), v[c].end(), now + 1); cnt += nx - now; now = nx % n; } cout << cnt + 1 << endl; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 1000000007 #define LINF (1LL << 60) #define PI 3.14159265358979 typedef long long i64; typedef pair<i64, i64> P; inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; } 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; } string s, t; bool b[26]; vector<int> v[26]; void solve() { cin >> s >> t; int n = s.size(), m = t.size(); for (int i = 0; i < n; i++) b[s[i] - 'a'] = 1; for (int i = 0; i < m; i++) { if (!b[t[i] - 'a']) { cout << -1 << endl; return; } } for (int i = 0; i < n + n; i++) { v[s[i % n] - 'a'].push_back(i); } i64 cnt = 0, now = -1; for (int i = 0; i < m; i++) { int c = t[i] - 'a'; int nx = *lower_bound(v[c].begin(), v[c].end(), now + 1); cnt += nx - now; now = nx % n; } cout << cnt << endl; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operation.binary.remove" ]
739,637
739,638
u414947284
cpp
p02937
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> P; typedef long long ll; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const ll INF = 1000000007; // clear memory #define CLR(a) memset((a), 0, sizeof(a)) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // chmax chmin template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int main(void) { string s, t; cin >> s >> t; VVI exist(26); REP(i, s.size()) exist[s[i] - 'a'].push_back(i); if (exist[t[0] - 'a'].size() == 0) { cout << "-1" << endl; return 0; } int idx = exist[t[0] - 'a'][0]; ll top = 0, next; FOR(i, 1, t.size()) { if (exist[t[i] - 'a'].empty()) { cout << "-1" << endl; return 0; } else if (exist[t[i] - 'a'].size() == 1) next = exist[t[i] - 'a'][0]; else { if (exist[t[i] - 'a'][0] > idx) next = exist[t[i] - 'a'][0]; else if (exist[t[i] - 'a'][exist[t[i] - 'a'].size() - 1] <= idx) next = exist[t[i] - 'a'][0]; else { int l = 0, r = exist[t[i] - 'a'].size() - 1; int n = (l + r) / 2; while (r - l > 1) { if (exist[t[i] - 'a'][n] <= idx) l = n; else r = n; n = (l + r) / 2; } next = exist[t[i] - 'a'][r]; } } if (idx > next) top++; idx = next; } ll ans = top * s.size() + next + 1; cout << ans << endl; return 0; }
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> P; typedef long long ll; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const ll INF = 1000000007; // clear memory #define CLR(a) memset((a), 0, sizeof(a)) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // chmax chmin template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int main(void) { string s, t; cin >> s >> t; VVI exist(26); REP(i, s.size()) exist[s[i] - 'a'].push_back(i); if (exist[t[0] - 'a'].size() == 0) { cout << "-1" << endl; return 0; } ll idx = exist[t[0] - 'a'][0]; ll top = 0, next; FOR(i, 1, t.size()) { if (exist[t[i] - 'a'].empty()) { cout << "-1" << endl; return 0; } else if (exist[t[i] - 'a'].size() == 1) next = exist[t[i] - 'a'][0]; else { if (exist[t[i] - 'a'][0] > idx) next = exist[t[i] - 'a'][0]; else if (exist[t[i] - 'a'][exist[t[i] - 'a'].size() - 1] <= idx) next = exist[t[i] - 'a'][0]; else { int l = 0, r = exist[t[i] - 'a'].size() - 1; int n = (l + r) / 2; while (r - l > 1) { if (exist[t[i] - 'a'][n] <= idx) l = n; else r = n; n = (l + r) / 2; } next = exist[t[i] - 'a'][r]; } } if (idx >= next) top++; idx = next; } ll ans = top * s.size() + idx + 1; cout << ans << endl; return 0; }
[ "variable_declaration.type.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change", "identifier.change", "expression.operation.binary.change" ]
739,643
739,642
u934272719
cpp
p02937
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() #define ln '\n' const long long MOD = 1000000007LL; // const long long MOD = 998244353LL; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<long long, long long> pll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } /////////////////////////////////////////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string S, T; cin >> S >> T; int N = S.size(); int M = T.size(); vector<vector<int>> G(26); rep(i, N) { int k = S[i] - 'a'; G[k].emplace_back(i); G[k].emplace_back(N + i); } rep(i, 26) sort(all(G[i])); ll ans = 1; int cur = 0; rep(i, M) { int k = T[i] - 'a'; if (G[k].empty()) { cout << -1 << ln; return 0; } int p = *upper_bound(all(G[k]), cur); ans += p - cur; cur = p; if (cur >= N) cur -= N; } cout << ans << ln; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() #define ln '\n' const long long MOD = 1000000007LL; // const long long MOD = 998244353LL; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<long long, long long> pll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } /////////////////////////////////////////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string S, T; cin >> S >> T; int N = S.size(); int M = T.size(); vector<vector<int>> G(26); rep(i, N) { int k = S[i] - 'a'; G[k].emplace_back(i); G[k].emplace_back(N + i); } rep(i, 26) sort(all(G[i])); ll ans = 0; int cur = -1; rep(i, M) { int k = T[i] - 'a'; if (G[k].empty()) { cout << -1 << ln; return 0; } int p = *upper_bound(all(G[k]), cur); ans += p - cur; cur = p; if (cur >= N) cur -= N; } cout << ans << ln; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,651
739,652
u842939260
cpp
p02937
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<LL, LL> PLL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int MOD = 1000000007; // grid //-------------------------------------------- VL dx = {0, 1, 0, -1}; VL dy = {1, 0, -1, 0}; VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1}; VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1}; // debug //-------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // IO accelerate //-------------------------------------------- struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; // template //-------------------------------------------- template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : "\t"); } return os; } template <typename T> ostream &operator<<(ostream &s, const vector<vector<T>> &vv) { for (int i = 0; i < vv.size(); ++i) { s << vv[i] << endl; } return s; } // 多重vector // auto dp=make_v<int>(4,h,w) みたいに使える template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } // 多重vectorのためのfill // fill_v(dp,0) みたいに使える template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // main code int main(int argc, char const *argv[]) { string s, t; cin >> s >> t; map<char, VL> mp; LL loop = 0; for (int i = 0; i < s.size(); i++) { mp[s[i]].push_back(i); } for (auto &&var : mp) { var.second.push_back(s.size() * 2); } int prev = -1; for (auto &&c : t) { if (mp[c].empty()) { cout << -1 << endl; return 0; } int b = *lower_bound(ALL(mp[c]), prev); if (b > s.size()) { loop++; b = *lower_bound(ALL(mp[c]), -1); } prev = b; } LL ans = s.size() * loop + prev + 1; cout << ans << endl; return 0; }
// include //------------------------------------------ #include <bits/stdc++.h> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<LL, LL> PLL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int MOD = 1000000007; // grid //-------------------------------------------- VL dx = {0, 1, 0, -1}; VL dy = {1, 0, -1, 0}; VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1}; VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1}; // debug //-------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // IO accelerate //-------------------------------------------- struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; // template //-------------------------------------------- template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : "\t"); } return os; } template <typename T> ostream &operator<<(ostream &s, const vector<vector<T>> &vv) { for (int i = 0; i < vv.size(); ++i) { s << vv[i] << endl; } return s; } // 多重vector // auto dp=make_v<int>(4,h,w) みたいに使える template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } // 多重vectorのためのfill // fill_v(dp,0) みたいに使える template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } // main code int main(int argc, char const *argv[]) { string s, t; cin >> s >> t; map<char, VL> mp; LL loop = 0; for (int i = 0; i < s.size(); i++) { mp[s[i]].push_back(i); } for (auto &&var : mp) { var.second.push_back(s.size() * 2); } int prev = -1; for (auto &&c : t) { if (mp[c].empty()) { cout << -1 << endl; return 0; } int b = *lower_bound(ALL(mp[c]), prev); if (b > s.size()) { loop++; b = *lower_bound(ALL(mp[c]), -1); } prev = b + 1; } LL ans = s.size() * loop + prev; cout << ans << endl; return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
739,656
739,657
u150376070
cpp
p02937
#include <algorithm> //sort,二分探索,など #include <bitset> //固定長bit集合 #include <cmath> //pow,logなど #include <complex> //複素数 #include <deque> //両端アクセスのキュー #include <functional> //sortのgreater #include <iomanip> //setprecision(浮動小数点の出力の誤差) #include <iostream> //入出力 #include <list> #include <map> //map(辞書) #include <numeric> //iota(整数列の生成),gcdとlcm(c++17) #include <queue> //キュー #include <set> //集合 #include <stack> //スタック #include <string> //文字列 #include <utility> //pair #include <vector> //可変長配列 using namespace std; #define rep(i, a) for (int i = 0; i < a; i++) #define mp make_pair #define pb push_back #define ll __int64 #define __int64 long long #define P pair<int, int> #define PP pair<P, int> #define F first #define S second int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; string s, t; int rui[26][222222]; int q(int c, int l, int r) { if (l == 0) return rui[c][r]; return rui[c][r] - rui[c][l - 1]; } int main() { cin >> s >> t; s = s + s; int ss = s.size(); rep(i, ss) { rui[s[i] - 'a'][i]++; } rep(i, 26) { rep(j, ss) { rui[i][j + 1] += rui[i][j]; } } rep(i, t.size()) { if (q(t[i] - 'a', 0, ss) == 0) { cout << -1 << endl; return 0; } } ll ans = 0; ll now = 0; rep(i, t.size()) { int ng = now - 1, ok = ss; while (abs(ok - ng) > 1) { int mid = (ng + ok) / 2; int res = q(t[i] - 'a', now, mid); if (res >= 1) ok = mid; else ng = mid; } // cout << t[i] << " " << ok << endl; if (ok == ss) { ans += ss; now = 0; } else { now = ok + 1; } } cout << ans + now << endl; return 0; }
#include <algorithm> //sort,二分探索,など #include <bitset> //固定長bit集合 #include <cmath> //pow,logなど #include <complex> //複素数 #include <deque> //両端アクセスのキュー #include <functional> //sortのgreater #include <iomanip> //setprecision(浮動小数点の出力の誤差) #include <iostream> //入出力 #include <list> #include <map> //map(辞書) #include <numeric> //iota(整数列の生成),gcdとlcm(c++17) #include <queue> //キュー #include <set> //集合 #include <stack> //スタック #include <string> //文字列 #include <utility> //pair #include <vector> //可変長配列 using namespace std; #define rep(i, a) for (int i = 0; i < a; i++) #define mp make_pair #define pb push_back #define ll __int64 #define __int64 long long #define P pair<int, int> #define PP pair<P, int> #define F first #define S second int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; string s, t; int rui[26][222222]; int q(int c, int l, int r) { if (l == 0) return rui[c][r]; return rui[c][r] - rui[c][l - 1]; } int main() { cin >> s >> t; s = s + s; int ss = s.size(); rep(i, ss) { rui[s[i] - 'a'][i]++; } rep(i, 26) { rep(j, ss) { rui[i][j + 1] += rui[i][j]; } } rep(i, t.size()) { if (q(t[i] - 'a', 0, ss) == 0) { cout << -1 << endl; return 0; } } ll ans = 0; ll now = 0; rep(i, t.size()) { int ng = now - 1, ok = ss; while (abs(ok - ng) > 1) { int mid = (ng + ok) / 2; int res = q(t[i] - 'a', now, mid); if (res >= 1) ok = mid; else ng = mid; } // cout << t[i] << " " << ok << endl; if (ok == ss) { ans += ss; now = 0; i--; } else { now = ok + 1; } } cout << ans + now << endl; return 0; }
[ "expression.unary.arithmetic.add" ]
739,660
739,661
u341406884
cpp
p02937
#include <algorithm> //sort,二分探索,など #include <bitset> //固定長bit集合 #include <cmath> //pow,logなど #include <complex> //複素数 #include <deque> //両端アクセスのキュー #include <functional> //sortのgreater #include <iomanip> //setprecision(浮動小数点の出力の誤差) #include <iostream> //入出力 #include <list> #include <map> //map(辞書) #include <numeric> //iota(整数列の生成),gcdとlcm(c++17) #include <queue> //キュー #include <set> //集合 #include <stack> //スタック #include <string> //文字列 #include <utility> //pair #include <vector> //可変長配列 using namespace std; #define rep(i, a) for (int i = 0; i < a; i++) #define mp make_pair #define pb push_back #define ll __int64 #define __int64 long long #define P pair<int, int> #define PP pair<P, int> #define F first #define S second int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; string s, t; int rui[26][222222]; int q(int c, int l, int r) { if (l == 0) return rui[c][r]; return rui[c][r] - rui[c][l - 1]; } int main() { cin >> s >> t; s = s + s; int ss = s.size(); rep(i, ss) { rui[s[i] - 'a'][i]++; } rep(i, 26) { rep(j, ss) { rui[i][j + 1] += rui[i][j]; } } rep(i, t.size()) { if (q(t[i] - 'a', 0, ss) == 0) { cout << -1 << endl; return 0; } } int ans = 0; int now = 0; rep(i, t.size()) { int ng = now - 1, ok = ss; while (abs(ok - ng) > 1) { int mid = (ng + ok) / 2; int res = q(t[i] - 'a', now, mid); if (res >= 1) ok = mid; else ng = mid; } // cout << t[i] << " " << ok << endl; if (ok == ss) { ans += ss; now = 0; } else { now = ok + 1; } } cout << ans + now << endl; return 0; }
#include <algorithm> //sort,二分探索,など #include <bitset> //固定長bit集合 #include <cmath> //pow,logなど #include <complex> //複素数 #include <deque> //両端アクセスのキュー #include <functional> //sortのgreater #include <iomanip> //setprecision(浮動小数点の出力の誤差) #include <iostream> //入出力 #include <list> #include <map> //map(辞書) #include <numeric> //iota(整数列の生成),gcdとlcm(c++17) #include <queue> //キュー #include <set> //集合 #include <stack> //スタック #include <string> //文字列 #include <utility> //pair #include <vector> //可変長配列 using namespace std; #define rep(i, a) for (int i = 0; i < a; i++) #define mp make_pair #define pb push_back #define ll __int64 #define __int64 long long #define P pair<int, int> #define PP pair<P, int> #define F first #define S second int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; string s, t; int rui[26][222222]; int q(int c, int l, int r) { if (l == 0) return rui[c][r]; return rui[c][r] - rui[c][l - 1]; } int main() { cin >> s >> t; s = s + s; int ss = s.size(); rep(i, ss) { rui[s[i] - 'a'][i]++; } rep(i, 26) { rep(j, ss) { rui[i][j + 1] += rui[i][j]; } } rep(i, t.size()) { if (q(t[i] - 'a', 0, ss) == 0) { cout << -1 << endl; return 0; } } ll ans = 0; ll now = 0; rep(i, t.size()) { int ng = now - 1, ok = ss; while (abs(ok - ng) > 1) { int mid = (ng + ok) / 2; int res = q(t[i] - 'a', now, mid); if (res >= 1) ok = mid; else ng = mid; } // cout << t[i] << " " << ok << endl; if (ok == ss) { ans += ss; now = 0; i--; } else { now = ok + 1; } } cout << ans + now << endl; return 0; }
[ "variable_declaration.type.change", "expression.unary.arithmetic.add" ]
739,662
739,661
u341406884
cpp
p02937
#include <algorithm> //sort,二分探索,など #include <bitset> //固定長bit集合 #include <cmath> //pow,logなど #include <complex> //複素数 #include <deque> //両端アクセスのキュー #include <functional> //sortのgreater #include <iomanip> //setprecision(浮動小数点の出力の誤差) #include <iostream> //入出力 #include <list> #include <map> //map(辞書) #include <numeric> //iota(整数列の生成),gcdとlcm(c++17) #include <queue> //キュー #include <set> //集合 #include <stack> //スタック #include <string> //文字列 #include <utility> //pair #include <vector> //可変長配列 using namespace std; #define rep(i, a) for (int i = 0; i < a; i++) #define mp make_pair #define pb push_back #define ll __int64 #define __int64 long long #define P pair<int, int> #define PP pair<P, int> #define F first #define S second int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; string s, t; int rui[26][222222]; int q(int c, int l, int r) { if (l == 0) return rui[c][r]; return rui[c][r] - rui[c][l - 1]; } int main() { cin >> s >> t; s = s + s; int ss = s.size(); rep(i, ss) { rui[s[i] - 'a'][i]++; } rep(i, 26) { rep(j, ss) { rui[i][j + 1] += rui[i][j]; } } rep(i, t.size()) { if (q(t[i] - 'a', 0, ss) == 0) { cout << -1 << endl; return 0; } } ll ans = 0; int now = 0; rep(i, t.size()) { int ng = now - 1, ok = ss; while (abs(ok - ng) > 1) { int mid = (ng + ok) / 2; int res = q(t[i] - 'a', now, mid); if (res >= 1) ok = mid; else ng = mid; } // cout << t[i] << " " << ok << endl; if (ok == ss) { ans += ss; now = 0; } else { now = ok + 1; } } cout << ans + now << endl; return 0; }
#include <algorithm> //sort,二分探索,など #include <bitset> //固定長bit集合 #include <cmath> //pow,logなど #include <complex> //複素数 #include <deque> //両端アクセスのキュー #include <functional> //sortのgreater #include <iomanip> //setprecision(浮動小数点の出力の誤差) #include <iostream> //入出力 #include <list> #include <map> //map(辞書) #include <numeric> //iota(整数列の生成),gcdとlcm(c++17) #include <queue> //キュー #include <set> //集合 #include <stack> //スタック #include <string> //文字列 #include <utility> //pair #include <vector> //可変長配列 using namespace std; #define rep(i, a) for (int i = 0; i < a; i++) #define mp make_pair #define pb push_back #define ll __int64 #define __int64 long long #define P pair<int, int> #define PP pair<P, int> #define F first #define S second int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; string s, t; int rui[26][222222]; int q(int c, int l, int r) { if (l == 0) return rui[c][r]; return rui[c][r] - rui[c][l - 1]; } int main() { cin >> s >> t; s = s + s; int ss = s.size(); rep(i, ss) { rui[s[i] - 'a'][i]++; } rep(i, 26) { rep(j, ss) { rui[i][j + 1] += rui[i][j]; } } rep(i, t.size()) { if (q(t[i] - 'a', 0, ss) == 0) { cout << -1 << endl; return 0; } } ll ans = 0; ll now = 0; rep(i, t.size()) { int ng = now - 1, ok = ss; while (abs(ok - ng) > 1) { int mid = (ng + ok) / 2; int res = q(t[i] - 'a', now, mid); if (res >= 1) ok = mid; else ng = mid; } // cout << t[i] << " " << ok << endl; if (ok == ss) { ans += ss; now = 0; i--; } else { now = ok + 1; } } cout << ans + now << endl; return 0; }
[ "variable_declaration.type.change", "expression.unary.arithmetic.add" ]
739,663
739,661
u341406884
cpp
p02937
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; const ll MOD_CONST = 1000000007; const int BIG_INT = 1000000000; int main() { string s, t; cin >> s >> t; vector<vector<int>> v(26); for (int i = 0; i < s.length(); i++) { v[(s[i] - 'a')].emplace_back(i + 1); } ll cnt = 0; int last = 0; for (int i = 0; i < t.length(); i++) { int num = t[i] - 'a'; if (v[num].size() == 0) { cout << -1 << endl; return 0; } auto it = lower_bound(v[num].begin(), v[num].end(), last); if (it == v[num].end()) { cnt++; last = v[num][0]; } else { last = *it; } } cout << cnt * s.length() + last << endl; }
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; const ll MOD_CONST = 1000000007; const int BIG_INT = 1000000000; int main() { string s, t; cin >> s >> t; vector<vector<int>> v(26); for (int i = 0; i < s.length(); i++) { v[(s[i] - 'a')].emplace_back(i + 1); } ll cnt = 0; int last = 0; for (int i = 0; i < t.length(); i++) { int num = t[i] - 'a'; if (v[num].size() == 0) { cout << -1 << endl; return 0; } auto it = upper_bound(v[num].begin(), v[num].end(), last); if (it == v[num].end()) { cnt++; last = v[num][0]; } else { last = *it; } } cout << cnt * s.length() + last << endl; }
[ "identifier.change", "call.function.change" ]
739,666
739,667
u156778176
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define ll long long #define fw(p) for (int w = 0; w < (p); w++) #define fx(p) for (int x = 0; x < (p); x++) #define fy(p) for (int y = 0; y < (p); y++) #define fz(p) for (int z = 0; z < (p); z++) #define fyg(p, g) for (int y = (g); y < (p); y++) #define fzg(p, g) for (int z = (g); z < (p); z++) #define ce(d) cout << d << endl; #define vecp(p) \ int aa; \ cin >> aa; \ (p).push_back(aa); #define vecpl(p) \ long long aa; \ cin >> aa; \ (p).push_back(aa); #define vecps(p) \ string aa; \ cin >> aa; \ (p).push_back(aa); #define vecp2(p) \ cin >> aa; \ (p).push_back(aa); #define vecpl2(p) \ long long a b; \ cin >> ab; \ (p).push_back(ab); #define vecps2(p) \ string ab; \ cin >> ab; \ (p).push_back(ab); #define sorts(c) sort((c).begin(), (c).end()); #define reverses(c) reverse((c).begin(), (c).end()); #define vec(b) vector<int>(b); #define vecl(b) vector<long long>(b); #define vecs(b) vector<string>(b); #define pb(b, a) (b).push_back((a)); #define doublece(a, b) cout << (a) << ' ' << (b) << endl; #define pairs(s) vector<pair<int, int>>(s); #define pairsp(s) \ int aa, bb; \ cin >> aa >> bb; \ (s).push_back(make_pair(aa, bb)); #define MOD 1000000007 #define cey ce("Yes") #define cen ce("No") #define ceY ce("YES") #define ceN ce("NO") int main() { string S, T; cin >> S >> T; vector<vector<int>> K(26); fx(S.size()) { K[S[x] - 'a'].push_back(x + 1); } ll ans = 0; ll s = S.size(); int place = 1; fx(T.size()) { int k = T[x] - 'a'; int t = K[k].size(); if (t == 0) { ce(-1); return 0; } int i = lower_bound(K[k].begin(), K[k].end(), place) - K[k].begin(); if (i == t) { place = 1; ans += s; i = lower_bound(K[k].begin(), K[k].end(), place) - K[k].begin(); } place = K[k][i]; } ce(ans + place) return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fw(p) for (int w = 0; w < (p); w++) #define fx(p) for (int x = 0; x < (p); x++) #define fy(p) for (int y = 0; y < (p); y++) #define fz(p) for (int z = 0; z < (p); z++) #define fyg(p, g) for (int y = (g); y < (p); y++) #define fzg(p, g) for (int z = (g); z < (p); z++) #define ce(d) cout << d << endl; #define vecp(p) \ int aa; \ cin >> aa; \ (p).push_back(aa); #define vecpl(p) \ long long aa; \ cin >> aa; \ (p).push_back(aa); #define vecps(p) \ string aa; \ cin >> aa; \ (p).push_back(aa); #define vecp2(p) \ cin >> aa; \ (p).push_back(aa); #define vecpl2(p) \ long long a b; \ cin >> ab; \ (p).push_back(ab); #define vecps2(p) \ string ab; \ cin >> ab; \ (p).push_back(ab); #define sorts(c) sort((c).begin(), (c).end()); #define reverses(c) reverse((c).begin(), (c).end()); #define vec(b) vector<int>(b); #define vecl(b) vector<long long>(b); #define vecs(b) vector<string>(b); #define pb(b, a) (b).push_back((a)); #define doublece(a, b) cout << (a) << ' ' << (b) << endl; #define pairs(s) vector<pair<int, int>>(s); #define pairsp(s) \ int aa, bb; \ cin >> aa >> bb; \ (s).push_back(make_pair(aa, bb)); #define MOD 1000000007 #define cey ce("Yes") #define cen ce("No") #define ceY ce("YES") #define ceN ce("NO") int main() { string S, T; cin >> S >> T; vector<vector<int>> K(26); fx(S.size()) { K[S[x] - 'a'].push_back(x + 1); } ll ans = 0; ll s = S.size(); int place = 1; fx(T.size()) { int k = T[x] - 'a'; int t = K[k].size(); if (t == 0) { ce(-1); return 0; } int i = lower_bound(K[k].begin(), K[k].end(), place) - K[k].begin(); if (i == t) { place = 1; ans += s; i = lower_bound(K[k].begin(), K[k].end(), place) - K[k].begin(); } place = K[k][i] + 1; } ce(ans + place - 1) return 0; }
[ "assignment.change" ]
739,668
739,669
u824327013
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string S, T; cin >> S >> T; vector<vector<int>> pos(26); for (int i = 0; i < (int)S.size(); i++) { pos[S[i] - 'a'].emplace_back(i); } int res = 0, p = 0; for (int i = 0; i < (int)T.size(); i++) { int c = T[i] - 'a'; if (pos[c].empty()) { cout << -1 << '\n'; return 0; } int idx = upper_bound(pos[c].begin(), pos[c].end(), p) - pos[c].begin(); if (idx < (int)pos[c].size()) { p = pos[c][idx]; } else { res++; p = pos[c][0]; } } cout << 1LL * res * (int)S.size() + p + 1 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string S, T; cin >> S >> T; vector<vector<int>> pos(26); for (int i = 0; i < (int)S.size(); i++) { pos[S[i] - 'a'].emplace_back(i); } int res = 0, p = -1; for (int i = 0; i < (int)T.size(); i++) { int c = T[i] - 'a'; if (pos[c].empty()) { cout << -1 << '\n'; return 0; } int idx = upper_bound(pos[c].begin(), pos[c].end(), p) - pos[c].begin(); if (idx < (int)pos[c].size()) { p = pos[c][idx]; } else { res++; p = pos[c][0]; } } cout << 1LL * res * (int)S.size() + p + 1 << '\n'; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,670
739,671
u782098901
cpp
p02937
#include <bits/stdc++.h> using namespace std; string S, T; vector<vector<int64_t>> inS(26); int64_t solve(char ch, int64_t p) { int c = ch - 'a'; if (inS[c].empty()) return -p; p %= S.length(); int res = lower_bound(inS[c].begin(), inS[c].end(), p) - inS[c].begin(); return inS[c][res] - p; } int main() { cin >> S >> T; string S2 = S + S; for (int i = 0; i < S2.length(); i++) inS[S2[i] - 'a'].push_back(i + 1); int64_t ans = 1; for (int i = 0; i < T.length(); i++) { ans += solve(T[i], ans); if (ans == 0) { cout << -1 << endl; return 0; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; string S, T; vector<vector<int64_t>> inS(26); int64_t solve(char ch, int64_t p) { int c = ch - 'a'; if (inS[c].empty()) return -p; p %= S.length(); int res = lower_bound(inS[c].begin(), inS[c].end(), p) - inS[c].begin(); return inS[c][res] + 1 - p; } int main() { cin >> S >> T; string S2 = S + S; for (int i = 0; i < S2.length(); i++) inS[S2[i] - 'a'].push_back(i); int64_t ans = 0; for (int i = 0; i < T.length(); i++) { ans += solve(T[i], ans); if (ans == 0) { cout << -1 << endl; return 0; } } cout << ans << endl; }
[ "expression.operation.binary.remove", "literal.number.change", "variable_declaration.value.change" ]
739,687
739,688
u285358283
cpp
p02937
//他者回答参考 #include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, a, b) for (int i = (a); i < (b); i++) #define per(i, a, b) for (int i = (b)-1; i >= (a); i--) #define pb push_back #define mp make_pair #define bg begin() #define en end() using namespace std; typedef long long ll; static const long long MOD = 1000000007; ll now; string s, t; ll nxt[26][200005]; int main(void) { cin >> s >> t; ll S = (ll)s.size(); ll T = (ll)t.size(); s += s; for (ll i = 0; i < 26; i++) nxt[i][S * 2] = S * 2; for (ll i = S * 2 - 1; i >= 0; i--) { for (int ch = 0; ch < 26; ch++) { nxt[ch][i] = nxt[ch][i + 1]; nxt[s[i] - 'a'][i] = i; } } for (ll i = 0; i < T; i++) { char ch = t[i] - 'a'; ll x = now % S; if (nxt[ch][x] == S * 2) { puts("-1"); return 0; } now += nxt[ch][x] - x; } printf("%lld\n", now + 1); return 0; }
//他者回答参考 #include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, a, b) for (int i = (a); i < (b); i++) #define per(i, a, b) for (int i = (b)-1; i >= (a); i--) #define pb push_back #define mp make_pair #define bg begin() #define en end() using namespace std; typedef long long ll; static const long long MOD = 1000000007; ll now; string s, t; ll nxt[26][200005]; int main(void) { cin >> s >> t; ll S = (ll)s.size(); ll T = (ll)t.size(); s += s; for (ll i = 0; i < 26; i++) nxt[i][S * 2] = S * 2; for (ll i = S * 2 - 1; i >= 0; i--) { for (int ch = 0; ch < 26; ch++) { nxt[ch][i] = nxt[ch][i + 1]; nxt[s[i] - 'a'][i] = i; } } for (ll i = 0; i < T; i++) { char ch = t[i] - 'a'; ll x = now % S; if (nxt[ch][x] == S * 2) { puts("-1"); return 0; } now += nxt[ch][x] - x + 1; } printf("%lld\n", now); return 0; }
[ "assignment.change", "expression.operation.binary.remove" ]
739,691
739,692
u877847737
cpp
p02937
#pragma region #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define each(x, y) for (auto &x : y) #define all(a) (a).begin(), (a).end() #define bit32(x) (1 << (x)) #define bit64(x) (1ll << (x)) using namespace std; using i32 = int; using i64 = long long; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; inline void yes() { cout << "Yes" << '\n'; exit(0); } inline void no() { cout << "No" << '\n'; exit(0); } inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); } inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; } template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; } template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; } template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } #pragma endregion void solve() { string s, t; cin >> s >> t; int n = s.size(); s += s; vector<vi32> next(26, vi32(s.size())); { vi32 position(26, -1); rrep(i, s.size()) { position[s[i] - 'a'] = i + 1; rep(j, 26) next[j][i] = position[j] - i; } } i64 acc = 0; rep(i, t.size()) { int nxt = next[t[i] - 'a'][acc % n]; if (nxt == -1) { cout << -1 << endl; return; } acc += nxt; } cout << acc << endl; }
#pragma region #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define each(x, y) for (auto &x : y) #define all(a) (a).begin(), (a).end() #define bit32(x) (1 << (x)) #define bit64(x) (1ll << (x)) using namespace std; using i32 = int; using i64 = long long; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; inline void yes() { cout << "Yes" << '\n'; exit(0); } inline void no() { cout << "No" << '\n'; exit(0); } inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); } inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; } template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; } template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; } template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } #pragma endregion void solve() { string s, t; cin >> s >> t; int n = s.size(); s += s; vector<vi32> next(26, vi32(s.size())); { vi32 position(26, -1); rrep(i, s.size()) { position[s[i] - 'a'] = i + 1; rep(j, 26) next[j][i] = position[j] - i; } } i64 acc = 0; rep(i, t.size()) { int nxt = next[t[i] - 'a'][acc % n]; if (nxt < 0) { cout << -1 << endl; return; } acc += nxt; } cout << acc << endl; }
[ "control_flow.branch.if.condition.change" ]
739,697
739,698
u908318580
cpp
p02937
#pragma region #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define each(x, y) for (auto &x : y) #define all(a) (a).begin(), (a).end() #define bit32(x) (1 << (x)) #define bit64(x) (1ll << (x)) using namespace std; using i32 = int; using i64 = long long; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; inline void yes() { cout << "Yes" << '\n'; exit(0); } inline void no() { cout << "No" << '\n'; exit(0); } inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); } inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; } template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; } template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; } template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } #pragma endregion void solve() { string s, t; cin >> s >> t; { vector<bool> sf(26), tf(26); rep(i, s.size()) sf[s[i] - 'a'] = true; rep(i, t.size()) tf[t[i] - 'a'] = true; rep(i, 26) if (!sf[i] && tf[i]) { cout << -1 << endl; return; } } int n = s.size(); s += s; vector<vi32> next(26, vi32(s.size())); { vi32 position(26, -1); rrep(i, s.size()) { position[s[i] - 'a'] = i; rep(j, 26) next[j][i] = position[j] % n; } } i64 acc = 1; int now = 0; rep(i, t.size()) { int nxt = next[t[i] - 'a'][now]; acc += nxt > now ? nxt - now : nxt - now + n; now = nxt; } cout << acc << endl; }
#pragma region #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define each(x, y) for (auto &x : y) #define all(a) (a).begin(), (a).end() #define bit32(x) (1 << (x)) #define bit64(x) (1ll << (x)) using namespace std; using i32 = int; using i64 = long long; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; inline void yes() { cout << "Yes" << '\n'; exit(0); } inline void no() { cout << "No" << '\n'; exit(0); } inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); } inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; } template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; } template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; } template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } #pragma endregion void solve() { string s, t; cin >> s >> t; { vector<bool> sf(26), tf(26); rep(i, s.size()) sf[s[i] - 'a'] = true; rep(i, t.size()) tf[t[i] - 'a'] = true; rep(i, 26) if (!sf[i] && tf[i]) { cout << -1 << endl; return; } } int n = s.size(); s += s; vector<vi32> next(26, vi32(s.size())); { vi32 position(26, -1); rrep(i, s.size()) { position[s[i] - 'a'] = i + 1; rep(j, 26) next[j][i] = position[j] % n; } } i64 acc = 0; int now = 0; rep(i, t.size()) { int nxt = next[t[i] - 'a'][now]; acc += nxt > now ? nxt - now : nxt - now + n; now = nxt; } cout << acc << endl; }
[ "assignment.change", "literal.number.change", "variable_declaration.value.change" ]
739,699
739,700
u908318580
cpp
p02937
#pragma region #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define each(x, y) for (auto &x : y) #define all(a) (a).begin(), (a).end() #define bit32(x) (1 << (x)) #define bit64(x) (1ll << (x)) using namespace std; using i32 = int; using i64 = long long; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; inline void yes() { cout << "Yes" << '\n'; exit(0); } inline void no() { cout << "No" << '\n'; exit(0); } inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); } inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; } template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; } template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; } template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } #pragma endregion void solve() { string s, t; cin >> s >> t; { vector<bool> sf(26), tf(26); rep(i, s.size()) sf[s[i] - 'a'] = true; rep(i, t.size()) tf[t[i] - 'a'] = true; rep(i, 26) if (!sf[i] && tf[i]) { cout << -1 << endl; return; } } int n = s.size(); s += s; vector<vi32> next(26, vi32(s.size())); { vi32 position(26, -1); rrep(i, s.size()) { position[s[i] - 'a'] = i; rep(j, 26) next[j][i] = position[j] % n; } } int acc = 1; int now = 0; rep(i, t.size()) { int nxt = next[t[i] - 'a'][now]; acc += nxt > now ? nxt - now : nxt - now + n; now = nxt; } cout << acc << endl; }
#pragma region #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define each(x, y) for (auto &x : y) #define all(a) (a).begin(), (a).end() #define bit32(x) (1 << (x)) #define bit64(x) (1ll << (x)) using namespace std; using i32 = int; using i64 = long long; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; inline void yes() { cout << "Yes" << '\n'; exit(0); } inline void no() { cout << "No" << '\n'; exit(0); } inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); } inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; } template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; } template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; } template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } #pragma endregion void solve() { string s, t; cin >> s >> t; { vector<bool> sf(26), tf(26); rep(i, s.size()) sf[s[i] - 'a'] = true; rep(i, t.size()) tf[t[i] - 'a'] = true; rep(i, 26) if (!sf[i] && tf[i]) { cout << -1 << endl; return; } } int n = s.size(); s += s; vector<vi32> next(26, vi32(s.size())); { vi32 position(26, -1); rrep(i, s.size()) { position[s[i] - 'a'] = i + 1; rep(j, 26) next[j][i] = position[j] % n; } } i64 acc = 0; int now = 0; rep(i, t.size()) { int nxt = next[t[i] - 'a'][now]; acc += nxt > now ? nxt - now : nxt - now + n; now = nxt; } cout << acc << endl; }
[ "assignment.change", "variable_declaration.type.change", "literal.number.change", "variable_declaration.value.change" ]
739,701
739,700
u908318580
cpp
p02937
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; 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; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; const ll mod = 1e9 + 7; const int inf = 1 << 30; int dp[100010]; int main() { string s, t; cin >> s >> t; int sl = s.size(); map<char, set<int>> mp; rep(i, sl) { mp[s[i]].insert(i + 1); mp[s[i]].insert(sl + 1); } int tl = t.size(); if (mp[t[0]].size() == 0) { cout << -1 << endl; return 0; } dp[0] = *begin(mp[t[0]]); rep(i, tl - 1) { if (mp[t[i + 1]].size() == 0) { cout << -1 << endl; return 0; } dp[i + 1] = *mp[t[i + 1]].upper_bound(dp[i]); if (dp[i + 1] == sl + 1) dp[i + 1] = *begin(mp[t[i + 1]]); } ll cnt = 0; rep(i, tl - 1) { if (dp[i] > dp[i + 1]) cnt++; } ll ans = sl * cnt + dp[tl - 1]; cout << ans << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; 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; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; const ll mod = 1e9 + 7; const int inf = 1 << 30; int dp[100010]; int main() { string s, t; cin >> s >> t; int sl = s.size(); map<char, set<int>> mp; rep(i, sl) { mp[s[i]].insert(i + 1); mp[s[i]].insert(sl + 1); } int tl = t.size(); if (mp[t[0]].size() == 0) { cout << -1 << endl; return 0; } dp[0] = *begin(mp[t[0]]); rep(i, tl - 1) { if (mp[t[i + 1]].size() == 0) { cout << -1 << endl; return 0; } dp[i + 1] = *mp[t[i + 1]].upper_bound(dp[i]); if (dp[i + 1] == sl + 1) dp[i + 1] = *begin(mp[t[i + 1]]); } ll cnt = 0; rep(i, tl - 1) { if (dp[i] >= dp[i + 1]) cnt++; } ll ans = sl * cnt + dp[tl - 1]; cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,713
739,714
u136342563
cpp
p02937
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; 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; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; const ll mod = 1e9 + 7; const int inf = 1 << 30; int dp[100010]; int main() { string s, t; cin >> s >> t; int sl = s.size(); map<char, set<int>> mp; rep(i, sl) { mp[s[i]].insert(i + 1); mp[s[i]].insert(sl + 1); } int tl = t.size(); if (mp[t[0]].size() == 0) { cout << -1 << endl; return 0; } dp[0] = *begin(mp[t[0]]); rep(i, tl - 1) { if (mp[t[i + 1]].size() == 0) { cout << -1 << endl; return 0; } dp[i + 1] = *mp[t[i + 1]].upper_bound(dp[i]); if (dp[i + 1] == sl + 1) dp[i + 1] = *begin(mp[t[i + 1]]); } int cnt = 0; rep(i, tl - 1) { if (dp[i] > dp[i + 1]) cnt++; } ll ans = sl * cnt + dp[tl - 1]; cout << ans << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; 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; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; const ll mod = 1e9 + 7; const int inf = 1 << 30; int dp[100010]; int main() { string s, t; cin >> s >> t; int sl = s.size(); map<char, set<int>> mp; rep(i, sl) { mp[s[i]].insert(i + 1); mp[s[i]].insert(sl + 1); } int tl = t.size(); if (mp[t[0]].size() == 0) { cout << -1 << endl; return 0; } dp[0] = *begin(mp[t[0]]); rep(i, tl - 1) { if (mp[t[i + 1]].size() == 0) { cout << -1 << endl; return 0; } dp[i + 1] = *mp[t[i + 1]].upper_bound(dp[i]); if (dp[i + 1] == sl + 1) dp[i + 1] = *begin(mp[t[i + 1]]); } ll cnt = 0; rep(i, tl - 1) { if (dp[i] >= dp[i + 1]) cnt++; } ll ans = sl * cnt + dp[tl - 1]; cout << ans << endl; }
[ "variable_declaration.type.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,715
739,714
u136342563
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define repr(i, a, b) for (int i = a; i < (b); ++i) #define reprev(i, n) for (int i = n - 1; i >= 0; --i) #define reprrev(i, a, b) for (int i = b - 1; i >= (a); --i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { cout << fixed << setprecision(10); string s, t; cin >> s >> t; // 出現文字の集合を作成 set<char> sett; rep(i, t.size()) { sett.insert(t[i]); } // 元のsのサイズ int os = s.size(); string ds = s + s; // 2ばいのsのサイズ int ns = ds.size(); map<char, vector<int>> wa; for (char x : sett) { vector<int> wa_c(ns, 1e5 + 3); int min_i = 1e5 + 3; // 各文字について、s*2の文字列の中で、どの位置に出現するか reprev(i, ns) { if (x == ds[i]) { min_i = i; } wa_c[i] = min_i; } if (min_i == 1e5 + 3) { // tのある文字がsに存在しなかった cout << -1 << endl; return 0; } wa[x] = wa_c; } // 今のi int now_i = 0; ll ans = 1; for (char x : t) { int next_i = wa[x][now_i]; // cout << x << " " << next_i << endl; ans += next_i - now_i; // cout << "ans " << ans << endl; now_i = next_i + 1; now_i %= os; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define repr(i, a, b) for (int i = a; i < (b); ++i) #define reprev(i, n) for (int i = n - 1; i >= 0; --i) #define reprrev(i, a, b) for (int i = b - 1; i >= (a); --i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { cout << fixed << setprecision(10); string s, t; cin >> s >> t; // 出現文字の集合を作成 set<char> sett; rep(i, t.size()) { sett.insert(t[i]); } // 元のsのサイズ int os = s.size(); string ds = s + s; // 2ばいのsのサイズ int ns = ds.size(); map<char, vector<int>> wa; for (char x : sett) { vector<int> wa_c(ns, 1e5 + 3); int min_i = 1e5 + 3; // 各文字について、s*2の文字列の中で、どの位置に出現するか reprev(i, ns) { if (x == ds[i]) { min_i = i; } wa_c[i] = min_i; } if (min_i == 1e5 + 3) { // tのある文字がsに存在しなかった cout << -1 << endl; return 0; } wa[x] = wa_c; } // 今のi int now_i = 0; ll ans = 0; for (char x : t) { int next_i = wa[x][now_i]; // cout << x << " " << next_i << endl; ans += next_i - now_i + 1; // cout << "ans " << ans << endl; now_i = next_i + 1; now_i %= os; } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "assignment.change" ]
739,716
739,717
u495903598
cpp
p02937
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <vector> using namespace std; #define int long long int #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define dup(x, y) (((x) + (y)-1) / (y)) #define sz(x) int(x.size()) int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } typedef pair<int, int> P; const int MOD = 1e9 + 7; // const int MOD = 998244353; const int INF = 1e18; const long double PI = (acos(-1)); signed main() { string s, t; cin >> s >> t; set<char> se; for (auto i : s) se.insert(i); for (auto i : t) { if (!se.count(i)) { cout << -1 << endl; return 0; } } vector<vector<int>> v(26); rep(i, s.size()) { int n = (int)s[i] - (int)'a'; v[n].push_back(i + 1); } rep(i, s.size()) { int n = (int)s[i] - (int)'a'; v[n].push_back(i + 1 + s.size()); } int ans = 0; int pre = 0; int SLEN = s.size(); int TLEN = t.size(); rep(i, TLEN) { int n = (int)t[i] - (int)'a'; int now = *lower_bound(v[n].begin(), v[n].end(), pre); ans += now - pre; if (now > SLEN) pre = now - SLEN; else pre = now; } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <vector> using namespace std; #define int long long int #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define dup(x, y) (((x) + (y)-1) / (y)) #define sz(x) int(x.size()) int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } typedef pair<int, int> P; const int MOD = 1e9 + 7; // const int MOD = 998244353; const int INF = 1e18; const long double PI = (acos(-1)); signed main() { string s, t; cin >> s >> t; set<char> se; for (auto i : s) se.insert(i); for (auto i : t) { if (!se.count(i)) { cout << -1 << endl; return 0; } } vector<vector<int>> v(26); rep(i, s.size()) { int n = (int)s[i] - (int)'a'; v[n].push_back(i + 1); } rep(i, s.size()) { int n = (int)s[i] - (int)'a'; v[n].push_back(i + 1 + s.size()); } int ans = 0; int pre = 0; int SLEN = s.size(); int TLEN = t.size(); rep(i, TLEN) { int n = (int)t[i] - (int)'a'; int now = *lower_bound(v[n].begin(), v[n].end(), pre + 1); ans += now - pre; if (now > SLEN) pre = now - SLEN; else pre = now; } cout << ans << endl; }
[ "assignment.change" ]
739,720
739,721
u697090185
cpp
p02937
#include "bits/stdc++.h" using namespace std; using ll = long long; template <typename T> void print_vec(const vector<T> &v, bool is_reverse = false, ll num = 0) { if (num == 0) num = (ll)v.size(); cout << endl; cout << "i= "; for (ll i = 0; i < num; i++) cout << i << " "; cout << endl; cout << " "; if (is_reverse) for (ll i = num - 1; i >= 0; i--) { cout << v[i]; if (i != 0) cout << " "; } else for (ll i = 0; i < num; i++) { cout << v[i]; if (i != num - 1) cout << " "; } cout << endl; } // template <typename T> // void print_pairvec(const vector<T> &v, ll num=0){ // if(num == 0) num = (ll)v.size(); // cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << // v[i].second << endl;} // } template <typename T> void print_pairvec(const T &_pair, ll num = 0) { cout << endl; for (pair<ll, int> x : _pair) { cout << x.first << " " << x.second << endl; } } template <typename T> void print_vec2(const vector<vector<T>> &v) { cout << endl; cout << " "; for (ll i = 0; i < v[0].size(); i++) cout << i << " "; cout << endl; for (ll i = 0; i < v.size(); i++) { cout << "i=" << i << ": "; for (ll j = 0; j < v[i].size(); j++) { if (v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << " "; else cout << "\x1B[31m" << v[i][j] << " "; // https://stackoverrun.com/ja/q/12618775 } cout << "\x1B[0m" << endl; } } int main() { string s, t; cin >> s >> t; map<char, int> s_mp, t_mp; for (int i = 0; i < (int)s.size(); i++) s_mp[s[i]]++; for (int i = 0; i < (int)t.size(); i++) t_mp[t[i]]++; for (int i = 0; i < (int)t.size(); i++) { if (s_mp[t[i]] == 0) { cout << "-1" << endl; return 0; } } vector<vector<ll>> vec(26); for (int i = 0; i < (int)s.size(); i++) vec[s[i] - 'a'].push_back((i + 1)); for (int i = 0; i < (int)s.size(); i++) vec[s[i] - 'a'].push_back((i + 1) + (int)s.size()); // 2周分つける ll ans = 0; ll place = 0; ll cnt = 0; for (int i = 0; i < (int)t.size(); i++) { int c = t[i] - 'a'; place = *lower_bound(vec[c].begin(), vec[c].end(), place); // cout << " vec[" << t[i] << "]: "; print_vec(vec[c]); // cout << " ans: " << ans << " t[i]: " << t[i] << " c: " << c << " place: " // << place << endl; if (place > (int)s.size()) { place -= (int)s.size(); cnt++; // cout << " yah " << endl; } ans = place + (int)s.size() * cnt; } cout << ans << endl; return 0; }
#include "bits/stdc++.h" using namespace std; using ll = long long; template <typename T> void print_vec(const vector<T> &v, bool is_reverse = false, ll num = 0) { if (num == 0) num = (ll)v.size(); cout << endl; cout << "i= "; for (ll i = 0; i < num; i++) cout << i << " "; cout << endl; cout << " "; if (is_reverse) for (ll i = num - 1; i >= 0; i--) { cout << v[i]; if (i != 0) cout << " "; } else for (ll i = 0; i < num; i++) { cout << v[i]; if (i != num - 1) cout << " "; } cout << endl; } // template <typename T> // void print_pairvec(const vector<T> &v, ll num=0){ // if(num == 0) num = (ll)v.size(); // cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << // v[i].second << endl;} // } template <typename T> void print_pairvec(const T &_pair, ll num = 0) { cout << endl; for (pair<ll, int> x : _pair) { cout << x.first << " " << x.second << endl; } } template <typename T> void print_vec2(const vector<vector<T>> &v) { cout << endl; cout << " "; for (ll i = 0; i < v[0].size(); i++) cout << i << " "; cout << endl; for (ll i = 0; i < v.size(); i++) { cout << "i=" << i << ": "; for (ll j = 0; j < v[i].size(); j++) { if (v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << " "; else cout << "\x1B[31m" << v[i][j] << " "; // https://stackoverrun.com/ja/q/12618775 } cout << "\x1B[0m" << endl; } } int main() { string s, t; cin >> s >> t; map<char, int> s_mp, t_mp; for (int i = 0; i < (int)s.size(); i++) s_mp[s[i]]++; for (int i = 0; i < (int)t.size(); i++) t_mp[t[i]]++; for (int i = 0; i < (int)t.size(); i++) { if (s_mp[t[i]] == 0) { cout << "-1" << endl; return 0; } } vector<vector<ll>> vec(26); for (int i = 0; i < (int)s.size(); i++) vec[s[i] - 'a'].push_back((i + 1)); for (int i = 0; i < (int)s.size(); i++) vec[s[i] - 'a'].push_back((i + 1) + (int)s.size()); // 2周分つける ll ans = 0; ll place = 0; ll cnt = 0; for (int i = 0; i < (int)t.size(); i++) { int c = t[i] - 'a'; place = *lower_bound(vec[c].begin(), vec[c].end(), place + 1); // cout << " vec[" << t[i] << "]: "; print_vec(vec[c]); // cout << " ans: " << ans << " t[i]: " << t[i] << " c: " << c << " place: " // << place << endl; if (place > (int)s.size()) { place -= (int)s.size(); cnt++; // cout << " yah " << endl; } ans = place + (int)s.size() * cnt; } cout << ans << endl; return 0; }
[ "assignment.change" ]
739,724
739,725
u153607901
cpp
p02937
#include <bits/stdc++.h> #include <ctime> #include <iostream> using namespace std; #define _LL long long #define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++) #define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++) int main() { string s, t; cin >> s >> t; vector<_LL> index[26]; _LL slen = s.length(); _LL tlen = t.length(); rep(i, slen) { index[s[i] - 'a'].push_back(i); } _LL loop = 0; _LL i = 0; rep(j, tlen) { int nextc = t[j] - 'a'; if (index[nextc].size() == 0) { cout << -1 << endl; return 0; } auto itr = upper_bound(index[nextc].begin(), index[nextc].end(), i); if (itr == index[nextc].end()) { loop++; i = index[nextc][0]; } else { i = *itr; } } cout << loop * slen + i + 1 << endl; return 0; }
#include <bits/stdc++.h> #include <ctime> #include <iostream> using namespace std; #define _LL long long #define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++) #define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++) int main() { string s, t; cin >> s >> t; vector<_LL> index[26]; _LL slen = s.length(); _LL tlen = t.length(); rep(i, slen) { index[s[i] - 'a'].push_back(i); } _LL loop = 0; _LL i = -1; rep(j, tlen) { int nextc = t[j] - 'a'; if (index[nextc].size() == 0) { cout << -1 << endl; return 0; } auto itr = upper_bound(index[nextc].begin(), index[nextc].end(), i); if (itr == index[nextc].end()) { loop++; i = index[nextc][0]; } else { i = *itr; } } cout << loop * slen + i + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,726
739,727
u131663893
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; const ll M = 1e9 + 7; int main(void) { string s, t; ll ans = 0, cur = 0, n, m, x; bool ok = true; cin >> s >> t; n = s.length(), m = t.length(); vector<set<int>> vs(26); rep(i, 26) vs[i].insert(M); rep(i, n) vs[s[i] - 'a'].insert(i); rep(i, m) { x = t[i] - 'a'; cur = *vs[x].lower_bound(cur); if (cur == M) ++ans, cur = *vs[x].begin(); if (cur == M) ok = false; } (ans *= n) += cur + 1; printf("%lld\n", ok ? ans : -1); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) typedef long long ll; const ll M = 1e9 + 7; int main(void) { string s, t; ll ans = 0, cur = 0, n, m, x; bool ok = true; cin >> s >> t; n = s.length(), m = t.length(); vector<set<int>> vs(26); rep(i, 26) vs[i].insert(M); rep(i, n) vs[s[i] - 'a'].insert(i + 1); rep(i, m) { x = t[i] - 'a'; cur = *vs[x].upper_bound(cur); if (cur == M) ++ans, cur = *vs[x].begin(); if (cur == M) ok = false; } (ans *= n) += cur; printf("%lld\n", ok ? ans : -1); return 0; }
[ "assignment.value.change", "call.function.change", "expression.operation.binary.remove" ]
739,736
739,737
u767543103
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { // cout << fixed << setprecision(10) << flush; string s, t; cin >> s >> t; for (int i = 0; i < s.size(); i++) { s[i] -= 'a'; } for (int j = 0; j < t.size(); j++) { t[j] -= 'a'; } // last['d'-'a'][i] は i 文字目より真に後に最初に 'd' が出てくる場所 // 次のループに突入もする、-1 か i 以上かどっちか // last[x][0] != -1 <=> s に x がいる vector<vector<int>> last(26, vector<int>(s.size(), -1)); for (int i = 0; i < s.size(); i++) { for (int j = i; j >= 0 && last[s[i]][j] == -1; j--) { last[s[i]][j] = i; } } for (int i = 0; i < 26; i++) { if (last[i][s.size() - 1] == -1 && last[i][0] != -1) { last[i][s.size() - 1] = s.size() + last[i][0]; for (int j = s.size() - 2; j >= 0 && last[i][j] == -1; j--) { last[i][j] = last[i][j + 1]; } } } // あるかどうか for (int i = 0; i < t.size(); i++) { if (last[t[i]][0] == -1) { cout << -1 << endl; return 0; } } // 最小 int ans = 0; for (int i = 0; i < t.size(); i++) { ans += last[t[i]][(ans + 1) % s.size()] - ((ans + 1) % s.size()) + 1; } cout << ans + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { // cout << fixed << setprecision(10) << flush; string s, t; cin >> s >> t; for (int i = 0; i < s.size(); i++) { s[i] -= 'a'; } for (int j = 0; j < t.size(); j++) { t[j] -= 'a'; } // last['d'-'a'][i] は i 文字目より真に後に最初に 'd' が出てくる場所 // 次のループに突入もする、-1 か i 以上かどっちか // last[x][0] != -1 <=> s に x がいる vector<vector<int>> last(26, vector<int>(s.size(), -1)); for (int i = 0; i < s.size(); i++) { for (int j = i; j >= 0 && last[s[i]][j] == -1; j--) { last[s[i]][j] = i; } } for (int i = 0; i < 26; i++) { if (last[i][s.size() - 1] == -1 && last[i][0] != -1) { last[i][s.size() - 1] = s.size() + last[i][0]; for (int j = s.size() - 2; j >= 0 && last[i][j] == -1; j--) { last[i][j] = last[i][j + 1]; } } } // あるかどうか for (int i = 0; i < t.size(); i++) { if (last[t[i]][0] == -1) { cout << -1 << endl; return 0; } } // 最小 int ans = -1; // あほ for (int i = 0; i < t.size(); i++) { ans += last[t[i]][(ans + 1) % s.size()] - ((ans + 1) % s.size()) + 1; } cout << ans + 1 << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,738
739,739
u658401995
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define ll int typedef pair<ll, ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; #define f first #define s second #define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i) #define DEC(i, s, e) for (ll i = s; i >= ll(e); --i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i, x) for (auto i : x) #define mem(x, i) memset(x, i, sizeof x) #define fast ios_base::sync_with_stdio(false), cin.tie(0) #define maxn 100001 #define int ll string S, T; int numS[maxn][26]; int N, M; int _min(int i, int j) { if (i == -1) return j; if (j == -1) return i; return min(i, j); } int32_t main() { fast; cin >> S >> T; int N = S.size(), M = T.size(); mem(numS, -1); DEC(i, N - 1, 0) { numS[i][(int)S[i] - 97] = _min(numS[i][(int)S[i] - 97], i); if (i < N - 1) FOR(j, 0, 25) numS[i][j] = _min(numS[i][j], numS[i + 1][j]); } int curstr = 0, curidx = 1; aFOR(i, T) { if (numS[curidx][(int)i - 97] == -1) { if (numS[0][(int)i - 97] == -1) { cout << -1; return 0; } curstr++; curidx = 0; } curidx = numS[curidx][(int)i - 97] + 1; if (curidx == S.size()) { curidx = 0; curstr++; } } cout << curstr * (ll)S.size() + curidx; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define ll int typedef pair<ll, ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; #define f first #define s second #define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i) #define DEC(i, s, e) for (ll i = s; i >= ll(e); --i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i, x) for (auto i : x) #define mem(x, i) memset(x, i, sizeof x) #define fast ios_base::sync_with_stdio(false), cin.tie(0) #define maxn 100001 #define int ll string S, T; int numS[maxn][26]; int N, M; int _min(int i, int j) { if (i == -1) return j; if (j == -1) return i; return min(i, j); } int32_t main() { fast; cin >> S >> T; int N = S.size(), M = T.size(); mem(numS, -1); DEC(i, N - 1, 0) { numS[i][(int)S[i] - 97] = _min(numS[i][(int)S[i] - 97], i); if (i < N - 1) FOR(j, 0, 25) numS[i][j] = _min(numS[i][j], numS[i + 1][j]); } int curstr = 0, curidx = 0; aFOR(i, T) { if (numS[curidx][(int)i - 97] == -1) { if (numS[0][(int)i - 97] == -1) { cout << -1; return 0; } curstr++; curidx = 0; } curidx = numS[curidx][(int)i - 97] + 1; if (curidx == S.size()) { curidx = 0; curstr++; } } cout << curstr * (ll)S.size() + curidx; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,740
739,741
u801120804
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define ll int typedef pair<ll, ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; #define f first #define s second #define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i) #define DEC(i, s, e) for (ll i = s; i >= ll(e); --i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i, x) for (auto i : x) #define mem(x, i) memset(x, i, sizeof x) #define fast ios_base::sync_with_stdio(false), cin.tie(0) #define maxn 100001 #define int ll string S, T; int numS[maxn][26]; int N, M; int _min(int i, int j) { if (i == -1) return j; if (j == -1) return i; return min(i, j); } int32_t main() { fast; cin >> S >> T; int N = S.size(), M = T.size(); mem(numS, -1); DEC(i, N - 1, 0) { numS[i][(int)S[i] - 97] = _min(numS[i][(int)S[i] - 97], i); if (i < N - 1) FOR(j, 0, 25) numS[i][j] = _min(numS[i][j], numS[i + 1][j]); } int curstr = 0, curidx = 1; aFOR(i, T) { if (numS[curidx][(int)i - 97] == -1) { if (numS[0][(int)i - 97] == -1) { cout << -1; return 0; } curstr++; curidx = 1; } curidx = numS[curidx][(int)i - 97] + 1; if (curidx == S.size()) { curidx = 0; curstr++; } } cout << curstr * (ll)S.size() + curidx; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define ll int typedef pair<ll, ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; #define f first #define s second #define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i) #define DEC(i, s, e) for (ll i = s; i >= ll(e); --i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i, x) for (auto i : x) #define mem(x, i) memset(x, i, sizeof x) #define fast ios_base::sync_with_stdio(false), cin.tie(0) #define maxn 100001 #define int ll string S, T; int numS[maxn][26]; int N, M; int _min(int i, int j) { if (i == -1) return j; if (j == -1) return i; return min(i, j); } int32_t main() { fast; cin >> S >> T; int N = S.size(), M = T.size(); mem(numS, -1); DEC(i, N - 1, 0) { numS[i][(int)S[i] - 97] = _min(numS[i][(int)S[i] - 97], i); if (i < N - 1) FOR(j, 0, 25) numS[i][j] = _min(numS[i][j], numS[i + 1][j]); } int curstr = 0, curidx = 0; aFOR(i, T) { if (numS[curidx][(int)i - 97] == -1) { if (numS[0][(int)i - 97] == -1) { cout << -1; return 0; } curstr++; curidx = 0; } curidx = numS[curidx][(int)i - 97] + 1; if (curidx == S.size()) { curidx = 0; curstr++; } } cout << curstr * (ll)S.size() + curidx; }
[ "literal.number.change", "variable_declaration.value.change", "assignment.value.change" ]
739,742
739,741
u801120804
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++) #define DEC(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--) typedef pair<ll, ll> pi; typedef pair<pi, ll> pii; typedef pair<pi, pi> pipi; #define f first #define s second typedef vector<ll> vi; typedef vector<pi> vpi; typedef vector<pii> vpii; #define pb push_back #define pf push_front #define all(v) v.begin(), v.end() #define disc(v) \ sort(all(v)); \ v.resize(unique(all(v)) - v.begin()); #define INF (ll)1e9 + 100 #define LLINF (ll)1e18 #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define sandybridge \ __attribute__((optimize("Ofast"), target("arch=sandybridge"))) mt19937 rng(chrono::steady_clock::now() .time_since_epoch() .count()); // can be used by calling rng() or shuffle(A, A+n, rng) inline ll rand(ll x, ll y) { ++y; return (rng() % (y - x)) + x; } // inclusivesss string s, t; ll n, m, cur, ans; map<char, vi> pos; int main() { fastio; cin >> s >> t; n = s.length(), m = t.length(); FOR(i, 0, n - 1) pos[s[i]].pb(i); FOR(i, 0, m - 1) { #define v pos[t[i]] if (v.empty()) { cout << -1; return 0; } auto it = upper_bound(all(v), cur); if (it != v.end()) cur = *it; else cur = v[0], ans += n; } cout << ans + cur + 1; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++) #define DEC(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--) typedef pair<ll, ll> pi; typedef pair<pi, ll> pii; typedef pair<pi, pi> pipi; #define f first #define s second typedef vector<ll> vi; typedef vector<pi> vpi; typedef vector<pii> vpii; #define pb push_back #define pf push_front #define all(v) v.begin(), v.end() #define disc(v) \ sort(all(v)); \ v.resize(unique(all(v)) - v.begin()); #define INF (ll)1e9 + 100 #define LLINF (ll)1e18 #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define sandybridge \ __attribute__((optimize("Ofast"), target("arch=sandybridge"))) mt19937 rng(chrono::steady_clock::now() .time_since_epoch() .count()); // can be used by calling rng() or shuffle(A, A+n, rng) inline ll rand(ll x, ll y) { ++y; return (rng() % (y - x)) + x; } // inclusivesss string s, t; ll n, m, cur = -1, ans; map<char, vi> pos; int main() { fastio; cin >> s >> t; n = s.length(), m = t.length(); FOR(i, 0, n - 1) pos[s[i]].pb(i); FOR(i, 0, m - 1) { #define v pos[t[i]] if (v.empty()) { cout << -1; return 0; } auto it = upper_bound(all(v), cur); if (it != v.end()) cur = *it; else cur = v[0], ans += n; } cout << ans + cur + 1; }
[ "variable_declaration.value.change" ]
739,743
739,744
u968778920
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0), ios::sync_with_stdio(false); string s, t; cin >> s >> t; vector<vector<int>> v(26); for (int i = 0; i < s.size(); ++i) v.at(s.at(i) - 'a').emplace_back(i); for (int i = 0; i < s.size(); ++i) v.at(s.at(i) - 'a').emplace_back(i + s.size()); int64_t ans = 0; int cur = 0; for (int i = 0; i < t.size(); ++i) { int c = t.at(i) - 'a'; if (v.at(c).size() == 0) { cout << "-1\n"s; return 0; } cur = *lower_bound(v.at(c).begin(), v.at(c).end(), cur) + 1; if (cur < s.size()) continue; cur = 0; ans += s.size(); } cout << ans + cur << "\n"s; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0), ios::sync_with_stdio(false); string s, t; cin >> s >> t; vector<vector<int>> v(26); for (int i = 0; i < s.size(); ++i) v.at(s.at(i) - 'a').emplace_back(i); for (int i = 0; i < s.size(); ++i) v.at(s.at(i) - 'a').emplace_back(i + s.size()); int64_t ans = 0; int cur = 0; for (int i = 0; i < t.size(); ++i) { int c = t.at(i) - 'a'; if (v.at(c).size() == 0) { cout << "-1\n"s; return 0; } cur = *lower_bound(v.at(c).begin(), v.at(c).end(), cur) + 1; if (cur < s.size()) continue; cur -= s.size(); ans += s.size(); } cout << ans + cur << "\n"s; }
[ "assignment.change", "call.add" ]
739,752
739,753
u104613587
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; ++i) #define all_map(pos, mp) for (ll pos = mp.begin(); pos != mp.end(); pos - ++) #define ALL(a) (a).begin(), (a).end() using namespace std; using ll = long long; using pll = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll LINF = 1LL << 62; const int INF = 1e9 + 7; int main() { string s, t; cin >> s >> t; vector<vector<ll>> vec(26); rep(i, s.size()) { vec[s[i] - 'a'].push_back(i + 1); } ll ans = 0; ll pos = 1; for (char c : t) { if (vec[c - 'a'].empty()) { cout << -1 << endl; return 0; } auto itr = upper_bound(ALL(vec[c - 'a']), pos); if (itr == vec[c - 'a'].end()) { ans += s.size(); pos = vec[c - 'a'].front(); } else pos = *itr; } cout << ans + pos; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; ++i) #define all_map(pos, mp) for (ll pos = mp.begin(); pos != mp.end(); pos - ++) #define ALL(a) (a).begin(), (a).end() using namespace std; using ll = long long; using pll = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll LINF = 1LL << 62; const int INF = 1e9 + 7; int main() { string s, t; cin >> s >> t; vector<vector<ll>> vec(26); rep(i, s.size()) { vec[s[i] - 'a'].push_back(i + 1); } ll ans = 0; ll pos = -1; for (char c : t) { if (vec[c - 'a'].empty()) { cout << -1 << endl; return 0; } auto itr = upper_bound(ALL(vec[c - 'a']), pos); if (itr == vec[c - 'a'].end()) { ans += s.size(); pos = vec[c - 'a'].front(); } else pos = *itr; } cout << ans + pos; }
[ "expression.operation.unary.arithmetic.add" ]
739,754
739,755
u969116807
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; int l; cin >> s >> t; l = s.size(); vector<vector<int>> al(26); rep(i, 26) { al[i].push_back(-1); } rep(i, l) { al[s[i] - 97].push_back(i); } ll ans = 0; int k = 0; int l2; int rt, lt, m; int l3; l3 = t.size(); rep(i, l3) { l2 = al[t[i] - 97].size(); // cout << l2 << endl; if (l2 == 1) { ans = -1; break; } if (k > al[t[i] - 97][l2 - 1]) { ans += l; k = 0; } rt = l2 - 1; lt = 0; while (rt - lt > 1) { m = (rt + lt) / 2; if (al[t[i] - 97][m] <= k) { lt = m; } else { rt = m; } } k = al[t[i] - 97][rt]; ++k; // cout << k << endl; if (i == (l3 - 1)) { ans += k; } } 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; int l; cin >> s >> t; l = s.size(); vector<vector<int>> al(26); rep(i, 26) { al[i].push_back(-1); } rep(i, l) { al[s[i] - 97].push_back(i); } ll ans = 0; int k = 0; int l2; int rt, lt, m; int l3; l3 = t.size(); rep(i, l3) { l2 = al[t[i] - 97].size(); // cout << l2 << endl; if (l2 == 1) { ans = -1; break; } if (k > al[t[i] - 97][l2 - 1]) { ans += l; k = 0; } rt = l2 - 1; lt = 0; while (rt - lt > 1) { m = (rt + lt) / 2; if (al[t[i] - 97][m] < k) { lt = m; } else { rt = m; } } k = al[t[i] - 97][rt]; ++k; // cout << k << endl; if (i == (l3 - 1)) { ans += k; } } cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,760
739,761
u992471673
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) template <class S> S sum(vector<S> &a) { return accumulate(all(a), S()); } template <class S> S max(vector<S> &a) { return *max_element(all(a)); } template <class S> S min(vector<S> &a) { return *min_element(all(a)); } ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); } ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); } template <class S> void print(vector<S> &v) { for (ll i = 0; i < (ll)v.size(); i++) { cerr << v[i] << ' '; } cerr << endl; } template <class S> void print(vector<vector<S>> &v) { for (ll i = 0; i < (ll)v.size(); i++) { for (ll j = 0; j < (ll)v[i].size(); j++) { cerr << v[i][j] << ' '; } cerr << endl; } } void Main(); int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); Main(); return 0; } void Main() { string s, t; cin >> s >> t; vector<vector<ll>> sc(26, vector<ll>()); rep(i, s.size()) { sc[s[i] - 'a'].push_back(i); } ll loop = 0; ll head = 0; for (char a : t) { auto sp = sc[a - 'a']; if (sp.empty()) { cout << "-1\n"; return; } auto ub = upper_bound(all(sp), head); if (ub == sp.end()) { loop++; ub = sp.begin(); } head = *ub; } cout << (ll)loop * s.size() + head + 1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) template <class S> S sum(vector<S> &a) { return accumulate(all(a), S()); } template <class S> S max(vector<S> &a) { return *max_element(all(a)); } template <class S> S min(vector<S> &a) { return *min_element(all(a)); } ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); } ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); } template <class S> void print(vector<S> &v) { for (ll i = 0; i < (ll)v.size(); i++) { cerr << v[i] << ' '; } cerr << endl; } template <class S> void print(vector<vector<S>> &v) { for (ll i = 0; i < (ll)v.size(); i++) { for (ll j = 0; j < (ll)v[i].size(); j++) { cerr << v[i][j] << ' '; } cerr << endl; } } void Main(); int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); Main(); return 0; } void Main() { string s, t; cin >> s >> t; vector<vector<int>> sc(26, vector<int>()); rep(i, s.size()) { sc[s[i] - 'a'].push_back(i); } int loop = 0; int head = -1; for (char a : t) { auto sp = sc[a - 'a']; if (sp.empty()) { cout << "-1\n"; return; } auto ub = upper_bound(all(sp), head); if (ub == sp.end()) { loop++; ub = sp.begin(); } head = *ub; } cout << (ll)loop * s.size() + head + 1 << endl; }
[ "call.arguments.change", "variable_declaration.type.change", "literal.number.change", "variable_declaration.value.change" ]
739,773
739,774
u466335531
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) template <class S> S sum(vector<S> &a) { return accumulate(all(a), S()); } template <class S> S max(vector<S> &a) { return *max_element(all(a)); } template <class S> S min(vector<S> &a) { return *min_element(all(a)); } ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); } ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); } template <class S> void print(vector<S> &v) { for (ll i = 0; i < (ll)v.size(); i++) { cerr << v[i] << ' '; } cerr << endl; } template <class S> void print(vector<vector<S>> &v) { for (ll i = 0; i < (ll)v.size(); i++) { for (ll j = 0; j < (ll)v[i].size(); j++) { cerr << v[i][j] << ' '; } cerr << endl; } } void Main(); int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); Main(); return 0; } void Main() { string s, t; cin >> s >> t; vector<vector<int>> sc(26, vector<int>()); rep(i, s.size()) { sc[s[i] - 'a'].push_back(i); } int loop = 0; int head = 0; for (char a : t) { auto sp = sc[a - 'a']; if (sp.empty()) { cout << "-1\n"; return; } auto ub = upper_bound(all(sp), head); if (ub == sp.end()) { loop++; ub = sp.begin(); } head = *ub; } cout << (ll)loop * s.size() + head + 1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) template <class S> S sum(vector<S> &a) { return accumulate(all(a), S()); } template <class S> S max(vector<S> &a) { return *max_element(all(a)); } template <class S> S min(vector<S> &a) { return *min_element(all(a)); } ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); } ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); } template <class S> void print(vector<S> &v) { for (ll i = 0; i < (ll)v.size(); i++) { cerr << v[i] << ' '; } cerr << endl; } template <class S> void print(vector<vector<S>> &v) { for (ll i = 0; i < (ll)v.size(); i++) { for (ll j = 0; j < (ll)v[i].size(); j++) { cerr << v[i][j] << ' '; } cerr << endl; } } void Main(); int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); Main(); return 0; } void Main() { string s, t; cin >> s >> t; vector<vector<int>> sc(26, vector<int>()); rep(i, s.size()) { sc[s[i] - 'a'].push_back(i); } int loop = 0; int head = -1; for (char a : t) { auto sp = sc[a - 'a']; if (sp.empty()) { cout << "-1\n"; return; } auto ub = upper_bound(all(sp), head); if (ub == sp.end()) { loop++; ub = sp.begin(); } head = *ub; } cout << (ll)loop * s.size() + head + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,775
739,774
u466335531
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--) #define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++) #define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main() { string s, t; cin >> s >> t; vector<bool> chk(26, false); vector<vector<int>> index(26, vector<int>()); rep(i, s.size()) { int now = s.at(i) - 'a'; chk.at(now) = true; index.at(now).push_back(i); } rep(i, t.size()) { int now = t.at(i) - 'a'; if (chk.at(now) != true) { cout << -1 << endl; return 0; } } int ni = -1; ll ans = 0; rep(i, t.size()) { int now = t.at(i) - 'a'; auto itr = upper_bound(index.at(now).begin(), index.at(now).end(), ni); if (itr == index.at(now).end()) { ans += index.at(now).front() + (s.size() - ni); ni = index.at(now).front(); } else { ans += *itr - ni; ni = *itr; } } ans++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--) #define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++) #define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main() { string s, t; cin >> s >> t; vector<bool> chk(26, false); vector<vector<int>> index(26, vector<int>()); rep(i, s.size()) { int now = s.at(i) - 'a'; chk.at(now) = true; index.at(now).push_back(i); } rep(i, t.size()) { int now = t.at(i) - 'a'; if (chk.at(now) != true) { cout << -1 << endl; return 0; } } int ni = s.size(); ll ans = 0; rep(i, t.size()) { int now = t.at(i) - 'a'; auto itr = upper_bound(index.at(now).begin(), index.at(now).end(), ni); if (itr == index.at(now).end()) { ans += index.at(now).front() + (s.size() - ni); ni = index.at(now).front(); } else { ans += *itr - ni; ni = *itr; } } ans++; cout << ans << endl; return 0; }
[ "call.add" ]
739,776
739,777
u617826263
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--) #define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++) #define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main() { string s, t; cin >> s >> t; vector<bool> chk(26, false); vector<vector<int>> index(26, vector<int>()); rep(i, s.size()) { int now = s.at(i) - 'a'; chk.at(now) = true; index.at(now).push_back(i); } rep(i, t.size()) { int now = t.at(i) - 'a'; if (chk.at(now) != true) { cout << -1 << endl; return 0; } } int ni = 0; ll ans = 0; rep(i, t.size()) { int now = t.at(i) - 'a'; auto itr = upper_bound(index.at(now).begin(), index.at(now).end(), ni); if (itr == index.at(now).end()) { ans += index.at(now).front() + (s.size() - ni); ni = index.at(now).front(); } else { ans += *itr - ni; ni = *itr; } } ans++; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--) #define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++) #define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main() { string s, t; cin >> s >> t; vector<bool> chk(26, false); vector<vector<int>> index(26, vector<int>()); rep(i, s.size()) { int now = s.at(i) - 'a'; chk.at(now) = true; index.at(now).push_back(i); } rep(i, t.size()) { int now = t.at(i) - 'a'; if (chk.at(now) != true) { cout << -1 << endl; return 0; } } int ni = s.size(); ll ans = 0; rep(i, t.size()) { int now = t.at(i) - 'a'; auto itr = upper_bound(index.at(now).begin(), index.at(now).end(), ni); if (itr == index.at(now).end()) { ans += index.at(now).front() + (s.size() - ni); ni = index.at(now).front(); } else { ans += *itr - ni; ni = *itr; } } ans++; cout << ans << endl; return 0; }
[ "identifier.replace.add", "literal.replace.remove", "call.add" ]
739,778
739,777
u617826263
cpp
p02937
#include <iostream> using namespace std; int main() { string s, t; cin >> s >> t; bool pass = true, over = false; long long ans = 0; int alp[26][s.size()], now = -1; for (int i = s.size() - 1; i >= 0; i--) { if (i == s.size() - 1) { for (int j = 0; j < 26; j++) { alp[j][i] = -1; } alp[s[i] - 'a'][i] = i; } else { for (int j = 0; j < 26; j++) { alp[j][i] = alp[j][i + 1]; } alp[s[i] - 'a'][i] = i; } } for (int i = 0, j = 0; i < t.size(); i++) { if (alp[t[i] - 'a'][j] == -1) { if (alp[t[i] - 'a'][0] == -1) { pass = -1; break; } ans = ans + alp[t[i] - 'a'][0] + s.size() - now; j = alp[t[i] - 'a'][0] + 1; now = alp[t[i] - 'a'][0]; if (j >= s.size()) { j = 0; } } else { if (over) { ans = ans + alp[t[i] - 'a'][j] + s.size() - now; over = false; } else { ans = ans + alp[t[i] - 'a'][j] - now; } now = alp[t[i] - 'a'][j]; j = alp[t[i] - 'a'][j] + 1; if (j >= s.size()) { j = 0; over = true; } } } if (pass) { cout << ans << endl; } else { cout << -1 << endl; } return 0; }
#include <iostream> using namespace std; int main() { string s, t; cin >> s >> t; bool pass = true, over = false; long long ans = 0; int alp[26][s.size()], now = -1; for (int i = s.size() - 1; i >= 0; i--) { if (i == s.size() - 1) { for (int j = 0; j < 26; j++) { alp[j][i] = -1; } alp[s[i] - 'a'][i] = i; } else { for (int j = 0; j < 26; j++) { alp[j][i] = alp[j][i + 1]; } alp[s[i] - 'a'][i] = i; } } for (int i = 0, j = 0; i < t.size(); i++) { if (alp[t[i] - 'a'][j] == -1) { if (alp[t[i] - 'a'][0] == -1) { pass = false; break; } ans = ans + alp[t[i] - 'a'][0] + s.size() - now; j = alp[t[i] - 'a'][0] + 1; now = alp[t[i] - 'a'][0]; if (j >= s.size()) { j = 0; } } else { if (over) { ans = ans + alp[t[i] - 'a'][j] + s.size() - now; over = false; } else { ans = ans + alp[t[i] - 'a'][j] - now; } now = alp[t[i] - 'a'][j]; j = alp[t[i] - 'a'][j] + 1; if (j >= s.size()) { j = 0; over = true; } } } if (pass) { cout << ans << endl; } else { cout << -1 << endl; } return 0; }
[ "assignment.value.change" ]
739,779
739,780
u353919145
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mk make_pair #define fi first #define se second #define eb emplace_back typedef long long ll; typedef pair<int, int> ii; typedef vector<pair<int, int>> vii; const int INF = 0x3f3f3f3f; const int T = 1e5 + 3; const int N = 27; int v[T][N]; string s, t; int main() { ios::sync_with_stdio(false); memset(v, INF, sizeof v); cin >> s >> t; int n = s.size(); s = "#" + s; for (int i = 1; i <= n; i++) v[i - 1][s[i] - 'a'] = i; for (int i = 0; i < 27; i++) for (int j = n; j >= 0; j--) v[j][i] = min(v[j][i], v[j + 1][i]); ll ans = 0; int at = 0; int as = 0; while (at < t.size()) { if (v[as][t[at] - 'a'] == INF) { if (as == 0) { cout << 1 << endl; return 0; } as = 0; ans += n; } else { as = v[as][t[at] - 'a']; at++; } } cout << ans + as << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mk make_pair #define fi first #define se second #define eb emplace_back typedef long long ll; typedef pair<int, int> ii; typedef vector<pair<int, int>> vii; const int INF = 0x3f3f3f3f; const int T = 1e5 + 3; const int N = 27; int v[T][N]; string s, t; int main() { ios::sync_with_stdio(false); memset(v, INF, sizeof v); cin >> s >> t; int n = s.size(); s = "#" + s; for (int i = 1; i <= n; i++) v[i - 1][s[i] - 'a'] = i; for (int i = 0; i < 27; i++) for (int j = n; j >= 0; j--) v[j][i] = min(v[j][i], v[j + 1][i]); ll ans = 0; int at = 0; int as = 0; while (at < t.size()) { if (v[as][t[at] - 'a'] == INF) { if (as == 0) { cout << -1 << endl; return 0; } as = 0; ans += n; } else { as = v[as][t[at] - 'a']; at++; } } cout << ans + as << endl; return 0; }
[ "expression.operation.unary.arithmetic.add" ]
739,783
739,784
u353919145
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pull = pair<ull, ll>; using pis = pair<int, string>; #define all(x) (x).begin(), (x).end() #define INF 1000000000 #define LLINF 10000000000000000ll #define MOD 1000000007LL int main() { cin.tie(0); ios::sync_with_stdio(false); // cout << fixed << setprecision(15) string s, t; cin >> s >> t; vector<vector<ll>> alphabets(26); for (int i = 0; i < s.size(); i++) alphabets[s[i] - 'a'].emplace_back(i); ll index = 0, ans = 0; for (int i = 0; i < t.size(); i++) { int c = t[i] - 'a'; if (alphabets[c].empty()) { cout << -1 << endl; return 0; } auto it = upper_bound(alphabets[c].begin(), alphabets[c].end(), index); if (it == alphabets[c].end()) { ans += (ll)(s.size()) - index; index = alphabets[c][0]; ans += index; } else { ans += *it - index; index = *it; } } cout << ans + 1 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pull = pair<ull, ll>; using pis = pair<int, string>; #define all(x) (x).begin(), (x).end() #define INF 1000000000 #define LLINF 10000000000000000ll #define MOD 1000000007LL int main() { cin.tie(0); ios::sync_with_stdio(false); // cout << fixed << setprecision(15) string s, t; cin >> s >> t; vector<vector<ll>> alphabets(26); for (int i = 0; i < s.size(); i++) alphabets[s[i] - 'a'].emplace_back(i); ll index = -1, ans = 0; for (int i = 0; i < t.size(); i++) { int c = t[i] - 'a'; if (alphabets[c].empty()) { cout << -1 << endl; return 0; } auto it = upper_bound(alphabets[c].begin(), alphabets[c].end(), index); if (it == alphabets[c].end()) { ans += (ll)(s.size()) - index; index = alphabets[c][0]; ans += index; } else { ans += *it - index; index = *it; } } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operation.binary.remove" ]
739,785
739,786
u499966353
cpp
p02937
#include <algorithm> #include <bits/stdc++.h> #include <string> #include <vector> #define rep(i, w) for (int i = 0; i < (w); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int INF = 1e9; int main() { string s, t; cin >> s >> t; vector<vector<int>> G(26); s = s + s; int ch; rep(i, s.size()) { ch = s[i] - 'a'; G[ch].push_back(i + 1); } ll ans = 0; int temp; if (s.find(t[0]) == string::npos) { cout << -1 << endl; return 0; } else { temp = G[t[0] - 'a'][0]; ans += temp; } // cout << ans << endl; for (int i = 1; i < t.size(); i++) { if (s.find(t[i]) == string::npos) { cout << -1 << endl; return 0; } ch = t[i] - 'a'; // cout << ch << " " << G[ch][0] << endl; vector<int>::iterator it = lower_bound(G[ch].begin(), G[ch].end(), temp); ans += *it - temp; temp = *it % (s.size() / 2); // cout << ans << endl; } cout << ans << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <string> #include <vector> #define rep(i, w) for (int i = 0; i < (w); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int INF = 1e9; int main() { string s, t; cin >> s >> t; vector<vector<int>> G(26); s = s + s; int ch; rep(i, s.size()) { ch = s[i] - 'a'; G[ch].push_back(i + 1); } ll ans = 0; int temp; if (s.find(t[0]) == string::npos) { cout << -1 << endl; return 0; } else { temp = G[t[0] - 'a'][0]; ans += temp; } // cout << ans << endl; for (int i = 1; i < t.size(); i++) { if (s.find(t[i]) == string::npos) { cout << -1 << endl; return 0; } ch = t[i] - 'a'; // cout << ch << " " << G[ch][0] << endl; vector<int>::iterator it = upper_bound(G[ch].begin(), G[ch].end(), temp); ans += *it - temp; temp = *it % (s.size() / 2); // cout << ans << endl; } cout << ans << endl; }
[ "identifier.change", "call.function.change" ]
739,789
739,790
u563170985
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { string s, t; cin >> s >> t; int sn = s.length(); int tn = t.length(); map<char, int> m; vector<vector<int>> v(26); for (int i = 0; i < sn; i++) { auto itr = m.find(s[i]); if (itr == m.end()) { m[s[i]] = 1; } v[s[i] - 'a'].push_back(i); } int flag = 0; for (int i = 0; i < tn; i++) { auto itr = m.find(t[i]); if (itr == m.end()) { flag = 1; break; } } if (flag == 0) { int now = 0; ll cou = 0; int k = -1; while (1) { if (now == tn) { break; } auto itr = lower_bound(v[t[now] - 'a'].begin(), v[t[now] - 'a'].end(), k); if (itr == v[t[now] - 'a'].end()) { k = v[t[now] - 'a'][0]; cou++; } else { k = *itr; } now++; } cout << sn * cou + k + 1 << endl; } else { cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { string s, t; cin >> s >> t; int sn = s.length(); int tn = t.length(); map<char, int> m; vector<vector<int>> v(26); for (int i = 0; i < sn; i++) { auto itr = m.find(s[i]); if (itr == m.end()) { m[s[i]] = 1; } v[s[i] - 'a'].push_back(i); } int flag = 0; for (int i = 0; i < tn; i++) { auto itr = m.find(t[i]); if (itr == m.end()) { flag = 1; break; } } if (flag == 0) { int now = 0; ll cou = 0; int k = -1; while (1) { if (now == tn) { break; } auto itr = upper_bound(v[t[now] - 'a'].begin(), v[t[now] - 'a'].end(), k); if (itr == v[t[now] - 'a'].end()) { k = v[t[now] - 'a'][0]; cou++; } else { k = *itr; } now++; } cout << sn * cou + k + 1 << endl; } else { cout << -1 << endl; } }
[ "identifier.change", "call.function.change" ]
739,791
739,792
u457483230
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1000000007; const ll INF = 1e18; #define all(v) v.begin(), v.end() int main() { string s, t; cin >> s >> t; vector<vector<ll>> A(26); rep(i, s.size()) { A.at(s.at(i) - 'a').push_back(i); } ll ans = 0, k = 0; rep(i, t.size()) { if (A.at(t.at(i) - 'a').size() == 0) { cout << -1 << endl; return 0; } if (lower_bound(all(A.at(t.at(i) - 'a')), k) != A.at(t.at(i) - 'a').end()) { k = *lower_bound(all(A.at(t.at(i) - 'a')), k); k++; if (k == s.size()) k = 0; } else { ans++; k = *lower_bound(all(A.at(t.at(i) - 'a')), 0); k++; } } cout << ans * s.size() + k << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1000000007; const ll INF = 1e18; #define all(v) v.begin(), v.end() int main() { string s, t; cin >> s >> t; vector<vector<ll>> A(26); rep(i, s.size()) { A.at(s.at(i) - 'a').push_back(i); } ll ans = 0, k = 0; rep(i, t.size()) { if (A.at(t.at(i) - 'a').size() == 0) { cout << -1 << endl; return 0; } if (lower_bound(all(A.at(t.at(i) - 'a')), k) != A.at(t.at(i) - 'a').end()) { k = *lower_bound(all(A.at(t.at(i) - 'a')), k); k++; if (k == s.size()) { k = 0; ans++; } } else { ans++; k = *lower_bound(all(A.at(t.at(i) - 'a')), 0); k++; } } cout << ans * s.size() + k << endl; }
[ "expression.unary.arithmetic.add" ]
739,803
739,804
u896137920
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main() { string S, T; cin >> S >> T; int N = S.size(), M = T.size(); S += S; map<char, vector<int>> mp; for (int i = 0; i < 2 * N; ++i) mp[S[i]].push_back(i); int64_t ans = -1; for (auto &c : T) { int i = ans % N; auto it = lower_bound(mp[c].begin(), mp[c].end(), i); if (it == mp[c].end()) { cout << -1 << '\n'; return 0; } ans += *it - i; } cout << ans + 1 << '\n'; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; int main() { string S, T; cin >> S >> T; int N = S.size(), M = T.size(); S += S; map<char, vector<int>> mp; for (int i = 0; i < 2 * N; ++i) mp[S[i]].push_back(i); int64_t ans = -1; for (auto &c : T) { int i = ans % N; auto it = upper_bound(mp[c].begin(), mp[c].end(), i); if (it == mp[c].end()) { cout << -1 << '\n'; return 0; } ans += *it - i; } cout << ans + 1 << '\n'; return 0; }
[ "identifier.change", "call.function.change" ]
739,809
739,810
u756388720
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main() { string S; string T; cin >> S >> T; vector<vector<int>> A(26); for (int i = 0; i < S.size(); i++) A[S[i] - 'a'].push_back(i); int ans = 0, n = 0; for (int i = 0; i < T.size(); i++) { if (A[T[i] - 'a'].size() == 0) { puts("-1"); return 0; } int it = lower_bound(A[T[i] - 'a'].begin(), A[T[i] - 'a'].end(), n) - A[T[i] - 'a'].begin(); if (it == A[T[i] - 'a'].size()) ans++, n = A[T[i] - 'a'][0]; else n = A[T[i] - 'a'][it]; } cout << ans * S.size() + n + 1 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S; string T; cin >> S >> T; vector<vector<int>> A(26); for (int i = 0; i < S.size(); i++) A[S[i] - 'a'].push_back(i); int ans = 0, n = -1; for (int i = 0; i < T.size(); i++) { if (A[T[i] - 'a'].size() == 0) { puts("-1"); return 0; } int it = upper_bound(A[T[i] - 'a'].begin(), A[T[i] - 'a'].end(), n) - A[T[i] - 'a'].begin(); if (it == A[T[i] - 'a'].size()) ans++, n = A[T[i] - 'a'][0]; else n = A[T[i] - 'a'][it]; } cout << ans * S.size() + n + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "call.function.change", "expression.operation.binary.change" ]
739,820
739,821
u306482197
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> P; int INF = 1e16 + 7; int mod = 1e9 + 7; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; vector<int> cnt[26]; signed main() { string S, T; cin >> S >> T; for (int i = 0; i < S.size(); i++) { cnt[S[i] - 'a'].push_back(i); } for (int i = 0; i < T.size(); i++) { if (cnt[T[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } int now = 0; int res = 0; for (int i = 0; i < T.size(); i++) { int l = -1, r = cnt[T[i] - 'a'].size(); while (l + 1 < r) { int mid = (l + r) / 2; if (cnt[T[i] - 'a'][mid] > now) { r = mid; } else { l = mid; } } if (r == cnt[T[i] - 'a'].size()) { now = cnt[T[i] - 'a'][0]; res++; } else { now = cnt[T[i] - 'a'][r]; } } cout << now + res * S.size() + 1 << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> P; int INF = 1e16 + 7; int mod = 1e9 + 7; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; vector<int> cnt[26]; signed main() { string S, T; cin >> S >> T; for (int i = 0; i < S.size(); i++) { cnt[S[i] - 'a'].push_back(i); } for (int i = 0; i < T.size(); i++) { if (cnt[T[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } int now = -1; int res = 0; for (int i = 0; i < T.size(); i++) { int l = -1, r = cnt[T[i] - 'a'].size(); while (l + 1 < r) { int mid = (l + r) / 2; if (cnt[T[i] - 'a'][mid] > now) { r = mid; } else { l = mid; } } if (r == cnt[T[i] - 'a'].size()) { now = cnt[T[i] - 'a'][0]; res++; } else { now = cnt[T[i] - 'a'][r]; } } cout << now + res * S.size() + 1 << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,822
739,823
u237390401
cpp
p02937
#include <bits/stdc++.h> using namespace std; using lint = long long; signed main() { string s, t; cin >> s >> t; lint N = s.size(), M = t.size(); vector<lint> cs(26, 0), ct(26, 0); vector<vector<lint>> alp(26); for (lint i = 0; i < N; i++) { cs[s[i] - 'a']++; alp[s[i] - 'a'].push_back(i + 1); } for (lint i = 0; i < M; i++) ct[t[i] - 'a']++; for (lint i = 0; i < 26; i++) { if (cs[i] == 0 && ct[i] != 0) { cout << -1 << endl; return 0; } } lint ans = 0, index = 0; for (lint i = 0; i < M; i++) { lint j = t[i] - 'a'; int v = lower_bound(alp[j].begin(), alp[j].end(), index) - alp[j].begin(); if (v == alp[j].size()) { ans += (N - index); ans += alp[j][0]; index = alp[j][0]; } else { ans += (alp[j][v] - index); index = alp[j][v]; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using lint = long long; signed main() { string s, t; cin >> s >> t; lint N = s.size(), M = t.size(); vector<lint> cs(26, 0), ct(26, 0); vector<vector<lint>> alp(26); for (lint i = 0; i < N; i++) { cs[s[i] - 'a']++; alp[s[i] - 'a'].push_back(i + 1); } for (lint i = 0; i < M; i++) ct[t[i] - 'a']++; for (lint i = 0; i < 26; i++) { if (cs[i] == 0 && ct[i] != 0) { cout << -1 << endl; return 0; } } lint ans = 0, index = 0; for (lint i = 0; i < M; i++) { lint j = t[i] - 'a'; int v = upper_bound(alp[j].begin(), alp[j].end(), index) - alp[j].begin(); if (v == alp[j].size()) { ans += (N - index); ans += alp[j][0]; index = alp[j][0]; } else { ans += (alp[j][v] - index); index = alp[j][v]; } } cout << ans << endl; }
[ "identifier.change", "call.function.change", "expression.operation.binary.change" ]
739,826
739,827
u265359795
cpp
p02937
#include <bits/stdc++.h> #define cinf(n, x) \ for (int i = 0; i < (n); i++) \ cin >> x[i]; #define ft first #define sc second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define LB(a, x) lb(all(a), x) - a.begin() #define UB(a, x) ub(all(a), x) - a.begin() #define mod 1000000007 #define FS fixed << setprecision(15) using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < n; i++) const double pi = 3.141592653589793; template <class T> using V = vector<T>; using Graph = vector<vector<int>>; using P = pair<ll, ll>; typedef unsigned long long ull; typedef long double ldouble; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const ll INF = 1e18; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; V<V<ll>> a(26); ll ns = s.size(); ll nt = t.size(); rep(i, ns) a[s[i] - 'a'].push_back(i); ll ans = 0; bool ok = 1; ll pos = -1; // 0-indexed ll cnt = 0; rep(i, nt) { if (a[t[i] - 'a'].empty()) { ok = 0; break; } ll m = t[i] - 'a'; ll cur = lb(a[m].begin(), a[m].end(), pos) - a[m].begin(); if (cur == a[m].size()) { cnt++; ans = cnt * ns + a[m][0] + 1; pos = a[m][0]; } else { ans = cnt * ns + a[m][cur] + 1; pos = a[m][cur]; } } if (ok) cout << ans << endl; else cout << -1 << endl; } //ペナルティ出しても焦らない ACできると信じろ!!! //どうしてもわからないときはサンプルで実験 何か見えてくるかも //頭で考えてダメなら紙におこせ!! /* V,P(大文字)使用不可 乗算などの際にオーバーフローに注意せよ! (適切にmodをとれ にぶたんで途中で切り上げろ) 制約をよく読め! { ・全探索できるなら全探索しろ ・異常な制約ならそこに注目 } stringの計算量(扱い)注意 コーナー注意!(特に数値が小さいものについては要検証) N行出力のときは'¥n' グリッド上では行先が範囲内におさまるかif文で確認(RE注意) if文ではちゃんと比較演算子==を使え('='でもエラー出ない) 配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意) (vector<int> a(m)でm==0というものはできない) modはなるべく最後に取れ! doubleを扱うときには(abs)ではなく'fabs'!!! */
#include <bits/stdc++.h> #define cinf(n, x) \ for (int i = 0; i < (n); i++) \ cin >> x[i]; #define ft first #define sc second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define LB(a, x) lb(all(a), x) - a.begin() #define UB(a, x) ub(all(a), x) - a.begin() #define mod 1000000007 #define FS fixed << setprecision(15) using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < n; i++) const double pi = 3.141592653589793; template <class T> using V = vector<T>; using Graph = vector<vector<int>>; using P = pair<ll, ll>; typedef unsigned long long ull; typedef long double ldouble; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const ll INF = 1e18; int main() { cin.tie(0); ios::sync_with_stdio(false); string s, t; cin >> s >> t; V<V<ll>> a(26); ll ns = s.size(); ll nt = t.size(); rep(i, ns) a[s[i] - 'a'].push_back(i); ll ans = 0; bool ok = 1; ll pos = -1; // 0-indexed ll cnt = 0; rep(i, nt) { if (a[t[i] - 'a'].empty()) { ok = 0; break; } ll m = t[i] - 'a'; ll cur = ub(a[m].begin(), a[m].end(), pos) - a[m].begin(); if (cur == a[m].size()) { cnt++; ans = cnt * ns + a[m][0] + 1; pos = a[m][0]; } else { ans = cnt * ns + a[m][cur] + 1; pos = a[m][cur]; } } if (ok) cout << ans << endl; else cout << -1 << endl; } //ペナルティ出しても焦らない ACできると信じろ!!! //どうしてもわからないときはサンプルで実験 何か見えてくるかも //頭で考えてダメなら紙におこせ!! /* V,P(大文字)使用不可 乗算などの際にオーバーフローに注意せよ! (適切にmodをとれ にぶたんで途中で切り上げろ) 制約をよく読め! { ・全探索できるなら全探索しろ ・異常な制約ならそこに注目 } stringの計算量(扱い)注意 コーナー注意!(特に数値が小さいものについては要検証) N行出力のときは'¥n' グリッド上では行先が範囲内におさまるかif文で確認(RE注意) if文ではちゃんと比較演算子==を使え('='でもエラー出ない) 配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意) (vector<int> a(m)でm==0というものはできない) modはなるべく最後に取れ! doubleを扱うときには(abs)ではなく'fabs'!!! */
[ "identifier.change", "call.function.change", "expression.operation.binary.change" ]
739,837
739,838
u619683748
cpp
p02937
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { string s, t; cin >> s; cin >> t; long long n = s.size(); long long m = t.size(); vector<vector<long long>> index(30); for (long long i = 0; i < 30; i++) index[s[i] - 'a'].push_back(i + 1); long long ans = 0; long long last = 0; for (long long i = 0; i < m; i++) { long long nch = t[i] - 'a'; if (index[nch].size() <= 0) { printf("-1\n"); return 0; } auto itr = upper_bound(index[nch].begin(), index[nch].end(), last); if (itr == index[nch].end()) { ans += n; itr = index[nch].begin(); } last = *itr; } ans += last; cout << ans << endl; return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { string s, t; cin >> s; cin >> t; long long n = s.size(); long long m = t.size(); vector<vector<long long>> index(30); for (long long i = 0; i < n; i++) index[s[i] - 'a'].push_back(i + 1); long long ans = 0; long long last = 0; for (long long i = 0; i < m; i++) { long long nch = t[i] - 'a'; if (index[nch].size() <= 0) { printf("-1\n"); return 0; } auto itr = upper_bound(index[nch].begin(), index[nch].end(), last); if (itr == index[nch].end()) { ans += n; itr = index[nch].begin(); } last = *itr; } ans += last; cout << ans << endl; return 0; }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
739,839
739,840
u418879326
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 vector<ll> ch[27]; int main() { string s, t; cin >> s >> t; for (ll i = 0; i < s.size(); i++) { ll now = s[i] - 'a'; ch[now].push_back(i + 1); } for (ll i = 0; i < 26; i++) { ch[i].push_back(INF); } // cout << 0<<endl; ll sum = 0; ll nex = 0; for (ll i = 0; i < t.size(); i++) { ll now = t[i] - 'a'; auto itr = lower_bound(ch[now].begin(), ch[now].end(), nex); if (*itr == INF) { if (ch[now][0] == INF) { cout << -1; return 0; } sum += s.size() - 1 - nex + ch[now][0] + 1; nex = ch[now][0]; } else { sum += *itr + 1 - nex - 1; nex = *itr; } // cout << sum<<endl; } cout << sum; // your code goes here return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1LL << 62 #define inf 1000000007 vector<ll> ch[27]; int main() { string s, t; cin >> s >> t; for (ll i = 0; i < s.size(); i++) { ll now = s[i] - 'a'; ch[now].push_back(i + 1); } for (ll i = 0; i < 26; i++) { ch[i].push_back(INF); } // cout << 0<<endl; ll sum = 0; ll nex = 0; for (ll i = 0; i < t.size(); i++) { ll now = t[i] - 'a'; auto itr = upper_bound(ch[now].begin(), ch[now].end(), nex); if (*itr == INF) { if (ch[now][0] == INF) { cout << -1; return 0; } sum += s.size() - 1 - nex + ch[now][0] + 1; nex = ch[now][0]; } else { sum += *itr + 1 - nex - 1; nex = *itr; } // cout << sum<<endl; } cout << sum; // your code goes here return 0; }
[ "identifier.change", "call.function.change" ]
739,845
739,846
u166378830
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { string s, t; cin >> s >> t; vector<vector<ll>> l(26); for (int i = 0; i < (int)s.size(); i++) { l[s[i] - 'a'].push_back(i + 1); } ll ans = 0; ll cnt = 0; bool ok = true; for (int i = 0; i < (int)t.size(); i++) { int tmp = t[i] - 'a'; if (l[tmp].empty()) { ok = false; break; } int num = lower_bound(l[tmp].begin(), l[tmp].end(), cnt) - l[tmp].begin(); bool next = false; if (num == (int)l[tmp].size()) { ans += s.size(); cnt = 0; next = true; } if (next) num = lower_bound(l[tmp].begin(), l[tmp].end(), cnt) - l[tmp].begin(); if (num < (int)l[tmp].size()) cnt = l[tmp][num]; } ans += cnt; if (!ok) cout << -1 << endl; else 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>> l(26); for (int i = 0; i < (int)s.size(); i++) { l[s[i] - 'a'].push_back(i + 1); } ll ans = 0; ll cnt = 0; bool ok = true; for (int i = 0; i < (int)t.size(); i++) { int tmp = t[i] - 'a'; if (l[tmp].empty()) { ok = false; break; } int num = lower_bound(l[tmp].begin(), l[tmp].end(), cnt + 1) - l[tmp].begin(); // cout << cnt << " " << num << endl; bool next = false; if (num == (int)l[tmp].size()) { ans += s.size(); cnt = 0; next = true; } if (next) num = lower_bound(l[tmp].begin(), l[tmp].end(), cnt) - l[tmp].begin(); if (num < (int)l[tmp].size()) { cnt = l[tmp][num]; } } ans += cnt; if (!ok) cout << -1 << endl; else cout << ans << endl; }
[ "assignment.change" ]
739,849
739,850
u515131769
cpp
p02937
// // Created by Koki Igarashi on 7/28/20. // #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef int Int; typedef pair<Int, Int> pii; typedef pair<Int, double> pid; typedef pair<double, double> pdd; typedef pair<Int, pii> pip; typedef pair<pii, Int> ppi; typedef pair<double, Int> pdp; typedef vector<Int> veci; typedef vector<double> vecd; typedef vector<int> veci; typedef vector<ll> vecll; typedef vector<double> vecd; typedef vector<pii> vecpii; typedef vector<ppi> vecppi; typedef vector<veci> mati; typedef vector<vecll> matll; typedef vector<vecd> matd; #define PB(x) push_back(x) #define EB(x) emplace_back(x) #define ALL(x) x.begin(), x.end() #define SZ(x) (x).size() #define len(x) (x).length() #define CLR(x) memset(x, 0, sizeof x) #define pdebug() printf("%d\n", __LINE__) #define REP(i, a, b) for (int i = (a); i <= (b); i++) #define FORO(i, n) REP(i, 0, (int)n - 1) #define FORI(i, n) REP(i, 1, (int)n) #define FORIT(i, t) for (auto i = t.begin(); i != t.end(); i++) #define eps 1e-6 #define sqr(x) ((x) * (x)) #define dist(_a, _b) sqrt(sqr(_a.A - _b.A) + sqr(_a.B - _b.B)) #define norm(_a) sqrt(sqr(_a.A) + sqr(_a.B)) #define DEBUG true #if DEBUG #define DUMP(a) \ do { \ std::cout << #a " = " << (a) << ", "; \ } while (false) #define DUMPLN(a) \ do { \ std::cout << #a " = " << (a) << std::endl; \ } while (false) #else #define DUMP(a) #define DUMPLN(a) #endif template <typename T, typename U> inline void getMin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void getMax(T &a, U b) { if (a < b) a = b; } template <typename T> vector<T> getVector(const int n) { return vector<T>(n); } template <typename T> vector<T> getVector(const int n, const T a) { return vector<T>(n, a); } template <typename T> vector<T> getEmptyVector() { return vector<T>(); } template <typename T> void appendAll(vector<T> &a, vector<T> b) { a.insert(a.end(), b.begin(), b.end()); } // #define X first // #define Y second const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, 1, -1}; const ll MOD = 1000000007; const int MAXN = 1 << 17; const int inf = 1 << 20; const int NIL = -inf; int popcount(int x) { return __builtin_popcount(x); } int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; veci al_pos[26]; FORO(i, len(s)) { al_pos[s[i] - 'a'].EB(i); } veci index(26); ll ans = -1; int mk = 0; ll num_rep = 0; FORO(i, len(t)) { // DUMPLN(t[i]); int c_index = t[i] - 'a'; if (SZ(al_pos[c_index]) == 0) { ans = -1; break; } while (al_pos[c_index][index[c_index]] < mk) { index[c_index]++; if (index[c_index] == SZ(al_pos[c_index])) { break; } } if (index[c_index] == SZ(al_pos[c_index])) { mk = 0; index.assign(26, 0); num_rep++; } getMax(mk, al_pos[c_index][index[c_index]]); // DUMP(c_index); DUMPLN(index[c_index]); // DUMP(num_rep); DUMPLN(mk); ll sr = (ll)len(s) * num_rep; getMax(ans, sr + al_pos[c_index][index[c_index]] + 1); index[c_index]++; } cout << ans << endl; return 0; }
// // Created by Koki Igarashi on 7/28/20. // #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef int Int; typedef pair<Int, Int> pii; typedef pair<Int, double> pid; typedef pair<double, double> pdd; typedef pair<Int, pii> pip; typedef pair<pii, Int> ppi; typedef pair<double, Int> pdp; typedef vector<Int> veci; typedef vector<double> vecd; typedef vector<int> veci; typedef vector<ll> vecll; typedef vector<double> vecd; typedef vector<pii> vecpii; typedef vector<ppi> vecppi; typedef vector<veci> mati; typedef vector<vecll> matll; typedef vector<vecd> matd; #define PB(x) push_back(x) #define EB(x) emplace_back(x) #define ALL(x) x.begin(), x.end() #define SZ(x) (x).size() #define len(x) (x).length() #define CLR(x) memset(x, 0, sizeof x) #define pdebug() printf("%d\n", __LINE__) #define REP(i, a, b) for (int i = (a); i <= (b); i++) #define FORO(i, n) REP(i, 0, (int)n - 1) #define FORI(i, n) REP(i, 1, (int)n) #define FORIT(i, t) for (auto i = t.begin(); i != t.end(); i++) #define eps 1e-6 #define sqr(x) ((x) * (x)) #define dist(_a, _b) sqrt(sqr(_a.A - _b.A) + sqr(_a.B - _b.B)) #define norm(_a) sqrt(sqr(_a.A) + sqr(_a.B)) #define DEBUG true #if DEBUG #define DUMP(a) \ do { \ std::cout << #a " = " << (a) << ", "; \ } while (false) #define DUMPLN(a) \ do { \ std::cout << #a " = " << (a) << std::endl; \ } while (false) #else #define DUMP(a) #define DUMPLN(a) #endif template <typename T, typename U> inline void getMin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void getMax(T &a, U b) { if (a < b) a = b; } template <typename T> vector<T> getVector(const int n) { return vector<T>(n); } template <typename T> vector<T> getVector(const int n, const T a) { return vector<T>(n, a); } template <typename T> vector<T> getEmptyVector() { return vector<T>(); } template <typename T> void appendAll(vector<T> &a, vector<T> b) { a.insert(a.end(), b.begin(), b.end()); } // #define X first // #define Y second const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, 1, -1}; const ll MOD = 1000000007; const int MAXN = 1 << 17; const int inf = 1 << 20; const int NIL = -inf; int popcount(int x) { return __builtin_popcount(x); } int main() { ios::sync_with_stdio(false); cin.tie(0); string s, t; cin >> s >> t; veci al_pos[26]; FORO(i, len(s)) { al_pos[s[i] - 'a'].EB(i); } veci index(26); ll ans = -1; int mk = 0; ll num_rep = 0; FORO(i, len(t)) { // DUMPLN(t[i]); int c_index = t[i] - 'a'; if (SZ(al_pos[c_index]) == 0) { ans = -1; break; } while (al_pos[c_index][index[c_index]] < mk) { index[c_index]++; if (index[c_index] >= SZ(al_pos[c_index])) { break; } } if (index[c_index] >= SZ(al_pos[c_index])) { mk = 0; index.assign(26, 0); num_rep++; } getMax(mk, al_pos[c_index][index[c_index]]); // DUMP(c_index); DUMPLN(index[c_index]); // DUMP(num_rep); DUMPLN(mk); ll sr = (ll)len(s) * num_rep; getMax(ans, sr + al_pos[c_index][index[c_index]] + 1); index[c_index]++; } cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,851
739,852
u414444658
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n); i >= 0; i--) #define all(v) v.begin(), v.end() typedef long long ll; int main() { string S; cin >> S; string T; cin >> T; ll len = S.size(); vector<vector<ll>> vec(26, vector<ll>(0)); rep(i, len) { int x = S[i] - 'a'; ll y = i + 1; vec[x].push_back(y); } rep(i, len) { int x = S[i] - 'a'; ll y = i + len + 1; vec[x].push_back(y); } ll now = 0; ll ans = 0; rep(i, T.size()) { int x = T[i] - 'a'; if (vec[x].size() == 0) { ans += -500000000000; } else { vector<ll>::iterator itr = lower_bound(all(vec[x]), now); ans += (*itr - now); if (*itr > len) now = *itr - len; else now = *itr; } } if (ans < 0) cout << -1 << endl; else cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n); i >= 0; i--) #define all(v) v.begin(), v.end() typedef long long ll; int main() { string S; cin >> S; string T; cin >> T; ll len = S.size(); vector<vector<ll>> vec(26, vector<ll>(0)); rep(i, len) { int x = S[i] - 'a'; ll y = i + 1; vec[x].push_back(y); } rep(i, len) { int x = S[i] - 'a'; ll y = i + len + 1; vec[x].push_back(y); } ll now = 0; ll ans = 0; rep(i, T.size()) { int x = T[i] - 'a'; if (vec[x].size() == 0) { ans += -500000000000; } else { vector<ll>::iterator itr = upper_bound(all(vec[x]), now); ans += (*itr - now); if (*itr > len) now = *itr - len; else now = *itr; } } if (ans < 0) cout << -1 << endl; else cout << ans << endl; }
[ "identifier.change", "call.function.change" ]
739,853
739,854
u356539385
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; using vll = vector<ll>; using vvll = vector<vll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vb = vector<bool>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; using plli = pair<ll, int>; using vplli = vector<pair<ll, int>>; using pllll = pair<ll, ll>; using vpllll = vector<pair<ll, ll>>; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // pow(llpow,modpow) template <class T> ll llpow(ll x, T n) { ll ans = 1; if (x == 0) ans = 0; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } //最大公約数 template <class T> inline T gcd(T x, T y) { if (y == 0) return x; else { return gcd(y, x % y); } } //最小公倍数 template <class T> inline T lcm(T x, T y) { return x / gcd(x, y) * y; } //逆元 long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } #define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++) //試験導入 #define irep(i, end_i, begin_i) \ for (ll i = (ll)begin_i - 1; i >= (ll)end_i; i--) long long INF = 1LL << 60; int main() { string s, t; cin >> s >> t; set<int> st[26]; rep(i, 0, s.size()) { int c = s[i] - 'a'; st[c].insert(i + 1); } ll a = 0, b = 0; rep(i, 0, t.size()) { int c = t[i] - 'a'; if (st[c].empty()) { cout << -1 << endl; return 0; } auto pos = st[c].lower_bound(b); if (pos == st[c].end()) { b = 0; a++; pos = st[c].lower_bound(b); } b = *pos; } cout << s.size() * a + b << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; using vll = vector<ll>; using vvll = vector<vll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vb = vector<bool>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; using plli = pair<ll, int>; using vplli = vector<pair<ll, int>>; using pllll = pair<ll, ll>; using vpllll = vector<pair<ll, ll>>; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // pow(llpow,modpow) template <class T> ll llpow(ll x, T n) { ll ans = 1; if (x == 0) ans = 0; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } //最大公約数 template <class T> inline T gcd(T x, T y) { if (y == 0) return x; else { return gcd(y, x % y); } } //最小公倍数 template <class T> inline T lcm(T x, T y) { return x / gcd(x, y) * y; } //逆元 long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } #define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++) //試験導入 #define irep(i, end_i, begin_i) \ for (ll i = (ll)begin_i - 1; i >= (ll)end_i; i--) long long INF = 1LL << 60; int main() { string s, t; cin >> s >> t; set<int> st[26]; rep(i, 0, s.size()) { int c = s[i] - 'a'; st[c].insert(i); } ll a = 0, b = 0; rep(i, 0, t.size()) { int c = t[i] - 'a'; if (st[c].empty()) { cout << -1 << endl; return 0; } auto pos = st[c].lower_bound(b); if (pos == st[c].end()) { b = 0; a++; pos = st[c].lower_bound(b); } b = *pos + 1; } cout << s.size() * a + b << endl; return 0; }
[ "expression.operation.binary.remove", "assignment.change" ]
739,855
739,856
u410506856
cpp
p02937
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef pair<int, int> ii; typedef long long ll; typedef pair<ll, ll> p; typedef unsigned long long int ull; int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; const int MAXN = 100000; const int MAXE = 100000; const int MAXV = 10000; const int INF = 1e9; const ll MOD = 1e9 + 7; struct UnionFind { vector<int> par, rank; UnionFind(int n) : par(n), rank(n, 0) { for (int i = 0; i < n; ++i) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x), ry = root(y); if (rx == ry) return; if (rank[rx] > rank[ry]) par[ry] = rx; else par[rx] = ry; if (rank[rx] == rank[ry]) rank[ry]++; } bool same(int x, int y) { return root(x) == root(y); } int cnt(int n) { int res = 0; for (int i = 0; i < n; ++i) { if (root(i) == i) res++; } return res; } }; int main() { string S, T; cin >> S >> T; ll N, M; N = (ll)S.size(); M = (ll)T.size(); vector<vector<ll>> st(26); for (int i = 0; i < N; ++i) { st[S[i] - 'a'].push_back(i + 1); } for (int i = 0; i < 26; ++i) { if (st[i].size() == 0) continue; st[i].push_back(INF); } ll cnt = 1; ll roop = 0; for (int i = 0; i < M; i++) { if (st[T[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } cnt = *lower_bound(st[T[i] - 'a'].begin(), st[T[i] - 'a'].end(), cnt + 1); if (cnt == INF) { roop++; cnt = *lower_bound(st[T[i] - 'a'].begin(), st[T[i] - 'a'].end(), 1); } } cout << N * roop + cnt << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef pair<int, int> ii; typedef long long ll; typedef pair<ll, ll> p; typedef unsigned long long int ull; int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; const int MAXN = 100000; const int MAXE = 100000; const int MAXV = 10000; const int INF = 1e9; const ll MOD = 1e9 + 7; struct UnionFind { vector<int> par, rank; UnionFind(int n) : par(n), rank(n, 0) { for (int i = 0; i < n; ++i) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x), ry = root(y); if (rx == ry) return; if (rank[rx] > rank[ry]) par[ry] = rx; else par[rx] = ry; if (rank[rx] == rank[ry]) rank[ry]++; } bool same(int x, int y) { return root(x) == root(y); } int cnt(int n) { int res = 0; for (int i = 0; i < n; ++i) { if (root(i) == i) res++; } return res; } }; int main() { string S, T; cin >> S >> T; ll N, M; N = (ll)S.size(); M = (ll)T.size(); vector<vector<ll>> st(26); for (int i = 0; i < N; ++i) { st[S[i] - 'a'].push_back(i + 1); } for (int i = 0; i < 26; ++i) { if (st[i].size() == 0) continue; st[i].push_back(INF); } ll cnt = 0; ll roop = 0; for (int i = 0; i < M; i++) { if (st[T[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } cnt = *lower_bound(st[T[i] - 'a'].begin(), st[T[i] - 'a'].end(), cnt + 1); if (cnt == INF) { roop++; cnt = *lower_bound(st[T[i] - 'a'].begin(), st[T[i] - 'a'].end(), 1); } } cout << N * roop + cnt << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,863
739,864
u765815947
cpp
p02937
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef pair<int, int> ii; typedef long long ll; typedef pair<ll, ll> p; typedef unsigned long long int ull; int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; const int MAXN = 100000; const int MAXE = 100000; const int MAXV = 10000; const int INF = 1e9; const ll MOD = 1e9 + 7; struct UnionFind { vector<int> par, rank; UnionFind(int n) : par(n), rank(n, 0) { for (int i = 0; i < n; ++i) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x), ry = root(y); if (rx == ry) return; if (rank[rx] > rank[ry]) par[ry] = rx; else par[rx] = ry; if (rank[rx] == rank[ry]) rank[ry]++; } bool same(int x, int y) { return root(x) == root(y); } int cnt(int n) { int res = 0; for (int i = 0; i < n; ++i) { if (root(i) == i) res++; } return res; } }; int main() { string S, T; cin >> S >> T; ll N, M; N = (ll)S.size(); M = (ll)T.size(); vector<vector<ll>> st(26); for (int i = 0; i < N; ++i) { st[S[i] - 'a'].push_back(i + 1); } for (int i = 0; i < 26; ++i) { if (st[i].size() == 0) continue; st[i].push_back(INF); } ll cnt = 0; ll roop = 0; for (int i = 0; i < M; i++) { if (st[T[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } cnt = *lower_bound(st[T[i] - 'a'].begin(), st[T[i] - 'a'].end(), cnt); if (cnt == INF) { roop++; cnt = *lower_bound(st[T[i] - 'a'].begin(), st[T[i] - 'a'].end(), 1); } } cout << N * roop + cnt << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef pair<int, int> ii; typedef long long ll; typedef pair<ll, ll> p; typedef unsigned long long int ull; int dy[] = {1, 0, -1, 0}; int dx[] = {0, 1, 0, -1}; const int MAXN = 100000; const int MAXE = 100000; const int MAXV = 10000; const int INF = 1e9; const ll MOD = 1e9 + 7; struct UnionFind { vector<int> par, rank; UnionFind(int n) : par(n), rank(n, 0) { for (int i = 0; i < n; ++i) par[i] = i; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x), ry = root(y); if (rx == ry) return; if (rank[rx] > rank[ry]) par[ry] = rx; else par[rx] = ry; if (rank[rx] == rank[ry]) rank[ry]++; } bool same(int x, int y) { return root(x) == root(y); } int cnt(int n) { int res = 0; for (int i = 0; i < n; ++i) { if (root(i) == i) res++; } return res; } }; int main() { string S, T; cin >> S >> T; ll N, M; N = (ll)S.size(); M = (ll)T.size(); vector<vector<ll>> st(26); for (int i = 0; i < N; ++i) { st[S[i] - 'a'].push_back(i + 1); } for (int i = 0; i < 26; ++i) { if (st[i].size() == 0) continue; st[i].push_back(INF); } ll cnt = 0; ll roop = 0; for (int i = 0; i < M; i++) { if (st[T[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } cnt = *lower_bound(st[T[i] - 'a'].begin(), st[T[i] - 'a'].end(), cnt + 1); if (cnt == INF) { roop++; cnt = *lower_bound(st[T[i] - 'a'].begin(), st[T[i] - 'a'].end(), 1); } } cout << N * roop + cnt << endl; return 0; }
[ "assignment.change" ]
739,865
739,864
u765815947
cpp
p02937
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> P; int main() { string S, T; cin >> S >> T; string S2 = S + S; long long ans = -1; for (int n = 0; n < T.size(); ++n) { string S3 = S2.substr(1 + ans % S.size()); int anstmp = S3.find(T[n]); if (string::npos == anstmp) { cout << "-1" << endl; return 0; } ans += (long long)anstmp + 1; } cout << ans + 1 << endl; return 0; }
#include "bits/stdc++.h" #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> P; int main() { string S, T; cin >> S >> T; string S2 = S + S; long long ans = -1; for (int n = 0; n < T.size(); ++n) { string S3 = S2.substr((1 + ans) % S.size()); int anstmp = S3.find(T[n]); if (string::npos == anstmp) { cout << "-1" << endl; return 0; } ans += (long long)anstmp + 1; } cout << ans + 1 << endl; return 0; }
[ "call.arguments.change" ]
739,866
739,867
u835523614
cpp
p02937
#include <bits/stdc++.h> #define LOCAL using namespace std; template <typename A, typename B> ostream &operator<<(ostream &out, const pair<A, B> &a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream &operator<<(ostream &out, const array<T, N> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T, class Cmp> ostream &operator<<(ostream &out, const set<T, Cmp> &a) { out << "{"; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "}"; return out; } template <typename U, typename T, class Cmp> ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) { out << "{"; bool first = true; for (auto &p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0; } out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; #define int long long using P = pair<int, int>; //######################################### signed main() { string s, t; cin >> s >> t; set<int> st[26]; rep(i, (int)s.size()) st[s[i] - 'a'].insert(i); rep(i, (int)t.size()) { if (st[s[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } int cur = 0; int T = 0; rep(i, (int)t.size()) { auto tmp = st[t[i] - 'a'].lower_bound(cur); if (tmp == st[t[i] - 'a'].end()) { T++; cur = 1 + *st[t[i] - 'a'].begin(); continue; } cur = 1 + *tmp; } int ret = T * (int)s.size() + cur; cout << ret << endl; return 0; }
#include <bits/stdc++.h> #define LOCAL using namespace std; template <typename A, typename B> ostream &operator<<(ostream &out, const pair<A, B> &a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream &operator<<(ostream &out, const array<T, N> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &a) { out << "["; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "]"; return out; } template <typename T, class Cmp> ostream &operator<<(ostream &out, const set<T, Cmp> &a) { out << "{"; bool first = true; for (auto &v : a) { out << (first ? "" : ", "); out << v; first = 0; } out << "}"; return out; } template <typename U, typename T, class Cmp> ostream &operator<<(ostream &out, const map<U, T, Cmp> &a) { out << "{"; bool first = true; for (auto &p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0; } out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; #define int long long using P = pair<int, int>; //######################################### signed main() { string s, t; cin >> s >> t; set<int> st[26]; rep(i, (int)s.size()) st[s[i] - 'a'].insert(i); rep(i, (int)t.size()) { if (st[t[i] - 'a'].size() == 0) { cout << -1 << endl; return 0; } } int cur = 0; int T = 0; rep(i, (int)t.size()) { auto tmp = st[t[i] - 'a'].lower_bound(cur); if (tmp == st[t[i] - 'a'].end()) { T++; cur = 1 + *st[t[i] - 'a'].begin(); continue; } cur = 1 + *tmp; } int ret = T * (int)s.size() + cur; cout << ret << endl; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
739,868
739,869
u818349438
cpp
p02937
/////////////////////////////////////////////////////////////////////////////// #include <bits/stdc++.h> #include <sys/time.h> #include <time.h> #include <unistd.h> using namespace std; /////////////////////////////////////////////////////////////////////////////// #define DEBUG 0 #define pb push_back #define V vector #define M unordered_map #define S static #define rep(i, n) for (ll i = 0LL; i < n; ++i) #define srep(i, s, n) for (ll i = s; i < n; ++i) #define rrep(i, n) for (ll i = n - 1LL; i >= 0LL; --i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define CIN(x) \ do { \ assert(!cin.eof()); \ cin >> x; \ assert(!cin.fail()); \ } while (0); #if DEBUG #define debug_print(...) _debug_print(__VA_ARGS__) #define debug_printf(...) printf(__VA_ARGS__) #define debug_print_time _debug_print_time #else // DEBUG #define debug_print(...) #define debug_printf(...) #define debug_print_time #endif // DEBUG typedef long long ll; typedef unsigned long long ull; typedef tuple<ll, ll> t2; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; template <typename T> using priority_queue_incr = priority_queue<T, V<T>, greater<T>>; /////////////////////////////////////////////////////////////////////////////// template <typename TT, typename T> T get_m(M<TT, T> &m, TT k, T default_value) { if (m.find(k) == m.end()) return m[k] = default_value; return m[k]; } template <typename TT, typename T> void incr_m(M<TT, T> &m, TT k) { if (m.find(k) == m.end()) m[k] = 0; m[k]++; } void llin(ll &a) { CIN(a); } void llinl1(V<ll> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a; CIN(a); v.push_back(a); } } void llinl2(V<t2> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b; CIN(a >> b); v.push_back(t2(a, b)); } } void llinl3(V<t3> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c; CIN(a >> b >> c); v.push_back(t3(a, b, c)); } } void llinl4(V<t4> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c, d; CIN(a >> b >> c >> d); v.push_back(t4(a, b, c, d)); } } void llina(V<ll> &v, ll count) { llinl1(v, count); } template <typename T> void sort(V<T> &v) { sort(v.begin(), v.end()); } template <typename T> void sort_reverse(V<T> &v) { sort(v.begin(), v.end(), greater<T>()); } template <typename T> void _debug_print(T x) { cout << x << endl; } void _debug_print(const t2 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); cout << "-- " << x1 << " -- " << x2 << endl; } void _debug_print(const t3 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << endl; } void _debug_print(const t4 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); ll x4 = get<3>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << " -- " << x4 << endl; } template <typename T> void _debug_print(T xarray[], ll n) { rep(i, n) _debug_print(xarray[i]); } template <typename T> void _debug_print(const V<T> &xlist) { for (auto x : xlist) { cout << "-- "; _debug_print(x); } } template <typename T> void _debug_print(const set<T> &xset) { for (auto x : xset) { cout << "-- "; _debug_print(x); } } template <typename TT, typename T> void _debug_print(const M<TT, T> &xlist) { for (auto x : xlist) { TT k = x.first; T v = x.second; cout << "====" << endl; cout << "K="; _debug_print(k); cout << "V="; _debug_print(v); } } void _debug_print_time(const char *prefix) { struct timeval tv; gettimeofday(&tv, NULL); struct tm *tm = localtime(&tv.tv_sec); printf("-- %s %02d:%02d:%02d.%06ld\n", prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); } /////////////////////////////////////////////////////////////////////////////// void _main(); int main() { cout << setprecision(12); #if !DEBUG ios::sync_with_stdio(false); cin.tie(0); #endif _main(); return 0; } void _main() { string s; CIN(s); string t; CIN(t); set<ll> idxlist[256]; rep(i, s.size()) idxlist[s[i]].insert(i); ll ans = 0; ll pos = s.size() - 1; for (auto c : t) { if (idxlist[c].empty()) { cout << -1 << endl; return; } auto iter = idxlist[c].lower_bound(pos); if (iter == idxlist[c].end()) { ans += s.size() - 1 - pos; ans += *idxlist[c].begin() + 1; pos = *idxlist[c].begin(); } else { ans += *iter - pos; pos = *iter; } } cout << ans << endl; } ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// #include <bits/stdc++.h> #include <sys/time.h> #include <time.h> #include <unistd.h> using namespace std; /////////////////////////////////////////////////////////////////////////////// #define DEBUG 0 #define pb push_back #define V vector #define M unordered_map #define S static #define rep(i, n) for (ll i = 0LL; i < n; ++i) #define srep(i, s, n) for (ll i = s; i < n; ++i) #define rrep(i, n) for (ll i = n - 1LL; i >= 0LL; --i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define CIN(x) \ do { \ assert(!cin.eof()); \ cin >> x; \ assert(!cin.fail()); \ } while (0); #if DEBUG #define debug_print(...) _debug_print(__VA_ARGS__) #define debug_printf(...) printf(__VA_ARGS__) #define debug_print_time _debug_print_time #else // DEBUG #define debug_print(...) #define debug_printf(...) #define debug_print_time #endif // DEBUG typedef long long ll; typedef unsigned long long ull; typedef tuple<ll, ll> t2; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; template <typename T> using priority_queue_incr = priority_queue<T, V<T>, greater<T>>; /////////////////////////////////////////////////////////////////////////////// template <typename TT, typename T> T get_m(M<TT, T> &m, TT k, T default_value) { if (m.find(k) == m.end()) return m[k] = default_value; return m[k]; } template <typename TT, typename T> void incr_m(M<TT, T> &m, TT k) { if (m.find(k) == m.end()) m[k] = 0; m[k]++; } void llin(ll &a) { CIN(a); } void llinl1(V<ll> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a; CIN(a); v.push_back(a); } } void llinl2(V<t2> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b; CIN(a >> b); v.push_back(t2(a, b)); } } void llinl3(V<t3> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c; CIN(a >> b >> c); v.push_back(t3(a, b, c)); } } void llinl4(V<t4> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c, d; CIN(a >> b >> c >> d); v.push_back(t4(a, b, c, d)); } } void llina(V<ll> &v, ll count) { llinl1(v, count); } template <typename T> void sort(V<T> &v) { sort(v.begin(), v.end()); } template <typename T> void sort_reverse(V<T> &v) { sort(v.begin(), v.end(), greater<T>()); } template <typename T> void _debug_print(T x) { cout << x << endl; } void _debug_print(const t2 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); cout << "-- " << x1 << " -- " << x2 << endl; } void _debug_print(const t3 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << endl; } void _debug_print(const t4 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); ll x4 = get<3>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << " -- " << x4 << endl; } template <typename T> void _debug_print(T xarray[], ll n) { rep(i, n) _debug_print(xarray[i]); } template <typename T> void _debug_print(const V<T> &xlist) { for (auto x : xlist) { cout << "-- "; _debug_print(x); } } template <typename T> void _debug_print(const set<T> &xset) { for (auto x : xset) { cout << "-- "; _debug_print(x); } } template <typename TT, typename T> void _debug_print(const M<TT, T> &xlist) { for (auto x : xlist) { TT k = x.first; T v = x.second; cout << "====" << endl; cout << "K="; _debug_print(k); cout << "V="; _debug_print(v); } } void _debug_print_time(const char *prefix) { struct timeval tv; gettimeofday(&tv, NULL); struct tm *tm = localtime(&tv.tv_sec); printf("-- %s %02d:%02d:%02d.%06ld\n", prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); } /////////////////////////////////////////////////////////////////////////////// void _main(); int main() { cout << setprecision(12); #if !DEBUG ios::sync_with_stdio(false); cin.tie(0); #endif _main(); return 0; } void _main() { string s; CIN(s); string t; CIN(t); set<ll> idxlist[256]; rep(i, s.size()) idxlist[s[i]].insert(i); ll ans = 0; ll pos = s.size() - 1; for (auto c : t) { if (idxlist[c].empty()) { cout << -1 << endl; return; } auto iter = idxlist[c].upper_bound(pos); if (iter == idxlist[c].end()) { ans += s.size() - 1 - pos; ans += *idxlist[c].begin() + 1; pos = *idxlist[c].begin(); } else { ans += *iter - pos; pos = *iter; } } cout << ans << endl; } ///////////////////////////////////////////////////////////////////////////////
[ "call.function.change" ]
739,870
739,871
u167931717
cpp
p02937
#include <bits/stdc++.h> using namespace std; using ll = long long; #define debug(x) cout << #x << " = " << x << endl; #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it) #define MSET(c, v) memset(c, v, sizeof(c)) const int INF = 0x3F3F3F3F; const int NEGINF = 0xC0C0C0C0; const int NULO = -1; const double EPS = 1e-10; const ll mod = 961748941; inline int cmp(double x, double y = 0) { if (fabs(x - y) < EPS) return 0; return x > y ? 1 : -1; } ll exp(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans; } const int maxn = 2e5 + 5; ll fat[maxn], inv[maxn]; ll C(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod; } void initFactorials() { fat[0] = 1; inv[0] = 1; for (int i = 1; i < maxn; i++) { fat[i] = (i * fat[i - 1]) % mod; inv[i] = exp(fat[i], mod - 2); } } set<ll> q[26]; int main() { ios::sync_with_stdio(0); string s; string t; cin >> s >> t; for (int i = 0; i < s.size(); i++) { q[s[i] - 'a'].insert(i + 1); } int last = 0; ll cnt = 0; for (int i = 0; i < t.size(); i++) { int val = t[i] - 'a'; if (q[val].size() == 0) { cout << "-1\n"; return 0; } auto it = q[val].lower_bound(last); if (it == q[val].end()) { cnt++; last = *q[val].begin(); } else { last = *it; } } cout << (cnt * s.size() + last) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define debug(x) cout << #x << " = " << x << endl; #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it) #define MSET(c, v) memset(c, v, sizeof(c)) const int INF = 0x3F3F3F3F; const int NEGINF = 0xC0C0C0C0; const int NULO = -1; const double EPS = 1e-10; const ll mod = 961748941; inline int cmp(double x, double y = 0) { if (fabs(x - y) < EPS) return 0; return x > y ? 1 : -1; } ll exp(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans; } const int maxn = 2e5 + 5; ll fat[maxn], inv[maxn]; ll C(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod; } void initFactorials() { fat[0] = 1; inv[0] = 1; for (int i = 1; i < maxn; i++) { fat[i] = (i * fat[i - 1]) % mod; inv[i] = exp(fat[i], mod - 2); } } set<ll> q[26]; int main() { ios::sync_with_stdio(0); string s; string t; cin >> s >> t; for (int i = 0; i < s.size(); i++) { q[s[i] - 'a'].insert(i + 1); } int last = 0; ll cnt = 0; for (int i = 0; i < t.size(); i++) { int val = t[i] - 'a'; if (q[val].size() == 0) { cout << "-1\n"; return 0; } auto it = q[val].lower_bound(last + 1); if (it == q[val].end()) { cnt++; last = *q[val].begin(); } else { last = *it; } } cout << (cnt * s.size() + last) << endl; return 0; }
[ "assignment.change" ]
739,872
739,873
u259039862
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef vector<lint> vlint; #define inf 1e+9 #define endl "\n" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define Size(c) (int)(c).size() #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; template <class T, class S> inline bool chmax(T &a, S b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class S> inline bool chmin(T &a, S b) { if (a > b) { a = b; return 1; } return 0; } template <class T> void line(vector<T> &x) { for (auto &&xi : x) cin >> xi; } inline void IN(void) { return; } template <typename First, typename... Rest> void IN(First &first, Rest &...rest) { cin >> first; IN(rest...); return; } #define INT(...) \ int __VA_ARGS__; \ IN(__VA_ARGS__) #define LINT(...) \ lint __VA_ARGS__; \ IN(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ IN(__VA_ARGS__) template <class T> void UNIQUE(vector<T> &x) { sort(all(x)); x.erase(unique(all(x)), x.end()); } template <class T> void print_vec(T first, T end) { for (auto i = first; i < end - 1; i++) cout << *i << " "; cout << *(end - 1) << endl; } template <class T> void print(T a) { cout << a << endl; }; vector<string> Yes = {"No", "Yes"}; vector<string> YES = {"NO", "YES"}; lint stl(char x) { return (lint)(x - 'a'); } int main() { STR(s, t); lint n = Size(s); vector<vlint> cnt(26, vlint()); rep(i, 2 * n) { cnt[stl(s[i % n])].pb(i); } lint ans = -1; rep(i, Size(t)) { auto it = upper_bound(all(cnt[stl(t[i])]), (ans + 1) % n); if (cnt[stl(t[i])].empty()) { ans = -2; break; } ans += *it - ans % n; } print(ans + 1); }
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef vector<lint> vlint; #define inf 1e+9 #define endl "\n" #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define Size(c) (int)(c).size() #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; template <class T, class S> inline bool chmax(T &a, S b) { if (a < b) { a = b; return 1; } return 0; } template <class T, class S> inline bool chmin(T &a, S b) { if (a > b) { a = b; return 1; } return 0; } template <class T> void line(vector<T> &x) { for (auto &&xi : x) cin >> xi; } inline void IN(void) { return; } template <typename First, typename... Rest> void IN(First &first, Rest &...rest) { cin >> first; IN(rest...); return; } #define INT(...) \ int __VA_ARGS__; \ IN(__VA_ARGS__) #define LINT(...) \ lint __VA_ARGS__; \ IN(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ IN(__VA_ARGS__) template <class T> void UNIQUE(vector<T> &x) { sort(all(x)); x.erase(unique(all(x)), x.end()); } template <class T> void print_vec(T first, T end) { for (auto i = first; i < end - 1; i++) cout << *i << " "; cout << *(end - 1) << endl; } template <class T> void print(T a) { cout << a << endl; }; vector<string> Yes = {"No", "Yes"}; vector<string> YES = {"NO", "YES"}; lint stl(char x) { return (lint)(x - 'a'); } int main() { STR(s, t); lint n = Size(s); vector<vlint> cnt(26, vlint()); rep(i, 2 * n) { cnt[stl(s[i % n])].pb(i); } lint ans = -1; rep(i, Size(t)) { auto it = upper_bound(all(cnt[stl(t[i])]), ans % n); if (cnt[stl(t[i])].empty()) { ans = -2; break; } ans += *it - ans % n; } print(ans + 1); }
[ "call.arguments.change" ]
739,878
739,879
u595289165
cpp
p02937
#include <bits/stdc++.h> using namespace std; int main(void) { string s, t; cin >> s >> t; vector<vector<long long>> count(26); for (long long i = 0; i < s.size(); i++) { count[s[i] - 'a'].push_back(i); } long long mem = -1; long long ans = 1; for (long long i = 0; i < t.size(); i++) { if (count[t[i] - 'a'].size() == 0) { cout << -1 << endl; exit(0); } else { long long answer; long long min = -1; long long max = count[t[i] - 'a'].size(); while (1) { if (max - min == 1) { answer = max; break; } else { if (count[t[i] - 'a'][(max + min) / 2] > mem) { max = (max + min) / 2; } else { min = (max + min) / 2; } } } if (answer == count[t[i] - 'a'].size()) { ans += s.size() - mem + count[t[i] - 'a'][0]; mem = count[t[i] - 'a'][0]; } else { ans += count[t[i] - 'a'][answer] - mem; mem = count[t[i] - 'a'][answer]; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(void) { string s, t; cin >> s >> t; vector<vector<long long>> count(26); for (long long i = 0; i < s.size(); i++) { count[s[i] - 'a'].push_back(i); } long long mem = -1; long long ans = 0; for (long long i = 0; i < t.size(); i++) { if (count[t[i] - 'a'].size() == 0) { cout << -1 << endl; exit(0); } else { long long answer; long long min = -1; long long max = count[t[i] - 'a'].size(); while (1) { if (max - min == 1) { answer = max; break; } else { if (count[t[i] - 'a'][(max + min) / 2] > mem) { max = (max + min) / 2; } else { min = (max + min) / 2; } } } if (answer == count[t[i] - 'a'].size()) { ans += s.size() - mem + count[t[i] - 'a'][0]; mem = count[t[i] - 'a'][0]; } else { ans += count[t[i] - 'a'][answer] - mem; mem = count[t[i] - 'a'][answer]; } } } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,882
739,883
u194393111
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define boost \ ios::sync_with_stdio(false); \ cin.tie(nullptr) #define int long long #define ff first #define ss second #define pi pair<int, int> int32_t main() { boost; string s, t; cin >> s >> t; vector<int> v[26]; for (int i = 0; i < s.size(); i++) v[s[i] - 'a'].push_back(i); int pre = -1, ans = 0, cnt = 0; ; for (int i = 0; i < t.size(); i++) { int cur = t[i] - 'a'; if (v[cur].empty()) { cout << -1 << endl; return 0; } if (v[cur].back() < pre) { pre = -1; cnt++; } auto it = lower_bound(v[cur].begin(), v[cur].end(), pre + 1) - v[cur].begin(); pre = v[cur][it]; ans = cnt * s.size() + pre + 1; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define boost \ ios::sync_with_stdio(false); \ cin.tie(nullptr) #define int long long #define ff first #define ss second #define pi pair<int, int> int32_t main() { boost; string s, t; cin >> s >> t; vector<int> v[26]; for (int i = 0; i < s.size(); i++) v[s[i] - 'a'].push_back(i); int pre = -1, ans = 0, cnt = 0; ; for (int i = 0; i < t.size(); i++) { int cur = t[i] - 'a'; if (v[cur].empty()) { cout << -1 << endl; return 0; } if (v[cur].back() <= pre) { pre = -1; cnt++; } auto it = lower_bound(v[cur].begin(), v[cur].end(), pre + 1) - v[cur].begin(); pre = v[cur][it]; ans = cnt * s.size() + pre + 1; } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,885
739,886
u371555975
cpp
p02937
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { string s, t; cin >> s >> t; map<char, set<int>> mp; vector<vector<int>> v; rep(i, s.size()) { v[s[i] - 'a'].push_back(i); } int id = -1; ll ans = 0; rep(i, t.size()) { int x = t[i] - 'a'; if (v[x].size() == 0) { cout << -1 << endl; return 0; } auto it = upper_bound(v[x].begin(), v[x].end(), id); if (it == v[x].end()) { ans += s.size(); id = *(v[x].begin()); } else { id = *it; } } ans += id + 1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { string s, t; cin >> s >> t; map<char, set<int>> mp; vector<vector<int>> v(26); rep(i, s.size()) { v[s[i] - 'a'].push_back(i); } int id = -1; ll ans = 0; rep(i, t.size()) { int x = t[i] - 'a'; if (v[x].size() == 0) { cout << -1 << endl; return 0; } auto it = upper_bound(v[x].begin(), v[x].end(), id); if (it == v[x].end()) { ans += s.size(); id = *(v[x].begin()); } else { id = *it; } } ans += id + 1; cout << ans << endl; return 0; }
[ "call.arguments.add" ]
739,891
739,892
u489302942
cpp
p02937
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 1'000'000'007; const ld PI = acos(-1); const ld EPS = 0.0000000001; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repd(i, n) for (ll i = n - 1; 0 <= i; i--) #define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++) #define FORD(i, a, b) for (ll i = a - 1; (ll)(b) <= i; i--) #define ALL(x) x.begin(), x.end() #define rALL(x) x.rbegin(), x.rend() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; vector<vector<char>> g; int main() { string s, t; cin >> s >> t; vector<vector<ll>> key(26); ll n = s.size(); rep(i, n) { key[s[i] - 'a'].push_back(i + 1); } ll res = 0; rep(i, t.size()) { if (!key[t[i] - 'a'].size()) res = -1; } if (0 <= res) { ll now = 0; rep(i, t.size()) { ll c = t[i] - 'a'; auto itr = lower_bound(ALL(key[c]), now); if (itr == key[c].end()) { res += s.size() - now + *key[c].begin(); now = *key[c].begin(); } else { res += *itr - now; now = *itr; } } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 1'000'000'007; const ld PI = acos(-1); const ld EPS = 0.0000000001; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repd(i, n) for (ll i = n - 1; 0 <= i; i--) #define FOR(i, a, b) for (ll i = a; i < (ll)(b); i++) #define FORD(i, a, b) for (ll i = a - 1; (ll)(b) <= i; i--) #define ALL(x) x.begin(), x.end() #define rALL(x) x.rbegin(), x.rend() #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; vector<vector<char>> g; int main() { string s, t; cin >> s >> t; vector<vector<ll>> key(26); ll n = s.size(); rep(i, n) { key[s[i] - 'a'].push_back(i + 1); } ll res = 0; rep(i, t.size()) { if (!key[t[i] - 'a'].size()) res = -1; } if (0 <= res) { ll now = 0; rep(i, t.size()) { ll c = t[i] - 'a'; auto itr = upper_bound(ALL(key[c]), now); if (itr == key[c].end()) { res += s.size() - now + *key[c].begin(); now = *key[c].begin(); } else { res += *itr - now; now = *itr; } } } cout << res << endl; }
[ "identifier.change", "call.function.change" ]
739,893
739,894
u050087249
cpp
p02937
/**Function Template**/ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pint; const int MAX = 510000; const int MOD = 1000000007; #define rep(i, n) for (ll i = ll(0); i < ll(n); i++) #define Rep(i, n) for (ll i = ll(1); i < ll(n); i++) #define ALL(a) (a).begin(), (a).end() #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265358979323846 #define ifYN(x) cout << (x ? "Yes" : "No") << "\n" ll fac[MAX], finv[MAX], inv[MAX]; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } bool palindrome(string s) { bool flag = true; rep(i, (ll)s.size()) if (s[i] != s[s.size() - 1 - i]) flag = false; return flag; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll Len(ll n) { ll s = 0; while (n != 0) s++, n /= 10; return s; } ll Sint(ll n) { ll ans = 0; while (n != 0) ans += n % 10, n /= 10; return ans; } ll Svec(vector<ll> v) { ll n = 0; rep(i, (ll)v.size()) n += v[i]; return n; } ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } ll Factorial(ll n) { ll m = 1; while (n >= 1) m *= n, n--; return m; } void runlength(string s, vector<pair<char, ll>> &p) { ll x = 1; if (s.size() == 1) { p.push_back(pair<char, ll>(s[0], 1)); } rep(i, (ll)s.size() - 1) { if (s[i] == s[i + 1]) { x++; if (i == (ll)s.size() - 2) { p.push_back(pair<char, ll>(s[i], x)); } } else { p.push_back(pair<char, ll>(s[i], x)); x = 1; if (i == (ll)s.size() - 2) { p.push_back(pair<char, ll>(s[s.size() - 1], x)); } } } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } string Toupper(string s) { string ans = ""; rep(i, s.size()) { if ('a' <= s[i] && s[i] <= 'z') ans += (char)s[i] - 32; else ans += s[i]; } return ans; } string Tolower(string s) { string ans = ""; rep(i, s.size()) { if ('A' <= s[i] && s[i] <= 'Z') ans += (char)s[i] + 32; else ans += s[i]; } return ans; } void dis(vector<ll> v) { rep(i, v.size()) cout << v[i] << endl; } void dis2(vector<vector<ll>> v) { rep(i, v.size()) { rep(j, v[0].size()) cout << v[i][j] << ' '; cout << endl; } } const int MAX_N = 100010; vector<bool> sieve_of_eratosthenes() { vector<bool> isPrime(MAX_N + 1, true); /* isPrime[1]=false; */ for (int i = 2; i <= MAX_N; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= MAX_N; j += i) { isPrime[j] = false; } } } return isPrime; } vector<pint> prime_factorize(ll n) { vector<pint> ans; for (ll p = 2; p <= sqrt(n); p++) { if (n % p != 0) continue; ll cnt = 0; while (n % p == 0) { n /= p; cnt++; } ans.push_back(make_pair(p, cnt)); } if (n != 1) ans.push_back(make_pair(n, 1)); return ans; } /*bool cmp(pint a, pint b) { return a.second < b.second; }*/ /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ int main() { IOS; string s, t; cin >> s >> t; ll n = s.size(); s = s + s; vector<vector<ll>> v(n * 2, vector<ll>(26)); rep(i, 26) v[n * 2 - 1][i] = n * 2; for (ll i = n * 2 - 2; i >= 0; i--) { rep(j, 26) v[i][j] = v[i + 1][j]; v[i][s[i] - 'a'] = i + 1; } ll ans = 0; for (auto c : s) { ll tmp = ans % n; if (v[tmp][c - 'a'] == n * 2) { cout << -1 << endl; return 0; } ans += v[tmp][c - 'a'] - tmp; } cout << ans << endl; }
/**Function Template**/ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pint; const int MAX = 510000; const int MOD = 1000000007; #define rep(i, n) for (ll i = ll(0); i < ll(n); i++) #define Rep(i, n) for (ll i = ll(1); i < ll(n); i++) #define ALL(a) (a).begin(), (a).end() #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265358979323846 #define ifYN(x) cout << (x ? "Yes" : "No") << "\n" ll fac[MAX], finv[MAX], inv[MAX]; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } bool palindrome(string s) { bool flag = true; rep(i, (ll)s.size()) if (s[i] != s[s.size() - 1 - i]) flag = false; return flag; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll Len(ll n) { ll s = 0; while (n != 0) s++, n /= 10; return s; } ll Sint(ll n) { ll ans = 0; while (n != 0) ans += n % 10, n /= 10; return ans; } ll Svec(vector<ll> v) { ll n = 0; rep(i, (ll)v.size()) n += v[i]; return n; } ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } ll Factorial(ll n) { ll m = 1; while (n >= 1) m *= n, n--; return m; } void runlength(string s, vector<pair<char, ll>> &p) { ll x = 1; if (s.size() == 1) { p.push_back(pair<char, ll>(s[0], 1)); } rep(i, (ll)s.size() - 1) { if (s[i] == s[i + 1]) { x++; if (i == (ll)s.size() - 2) { p.push_back(pair<char, ll>(s[i], x)); } } else { p.push_back(pair<char, ll>(s[i], x)); x = 1; if (i == (ll)s.size() - 2) { p.push_back(pair<char, ll>(s[s.size() - 1], x)); } } } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } string Toupper(string s) { string ans = ""; rep(i, s.size()) { if ('a' <= s[i] && s[i] <= 'z') ans += (char)s[i] - 32; else ans += s[i]; } return ans; } string Tolower(string s) { string ans = ""; rep(i, s.size()) { if ('A' <= s[i] && s[i] <= 'Z') ans += (char)s[i] + 32; else ans += s[i]; } return ans; } void dis(vector<ll> v) { rep(i, v.size()) cout << v[i] << endl; } void dis2(vector<vector<ll>> v) { rep(i, v.size()) { rep(j, v[0].size()) cout << v[i][j] << ' '; cout << endl; } } const int MAX_N = 100010; vector<bool> sieve_of_eratosthenes() { vector<bool> isPrime(MAX_N + 1, true); /* isPrime[1]=false; */ for (int i = 2; i <= MAX_N; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= MAX_N; j += i) { isPrime[j] = false; } } } return isPrime; } vector<pint> prime_factorize(ll n) { vector<pint> ans; for (ll p = 2; p <= sqrt(n); p++) { if (n % p != 0) continue; ll cnt = 0; while (n % p == 0) { n /= p; cnt++; } ans.push_back(make_pair(p, cnt)); } if (n != 1) ans.push_back(make_pair(n, 1)); return ans; } /*bool cmp(pint a, pint b) { return a.second < b.second; }*/ /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ int main() { IOS; string s, t; cin >> s >> t; ll n = s.size(); s = s + s; vector<vector<ll>> v(n * 2, vector<ll>(26)); rep(i, 26) v[n * 2 - 1][i] = n * 2; for (ll i = n * 2 - 2; i >= 0; i--) { rep(j, 26) v[i][j] = v[i + 1][j]; v[i][s[i] - 'a'] = i + 1; } ll ans = 0; for (auto c : t) { ll tmp = ans % n; if (v[tmp][c - 'a'] == n * 2) { cout << -1 << endl; return 0; } ans += v[tmp][c - 'a'] - tmp; } cout << ans << endl; }
[ "identifier.change" ]
739,899
739,900
u264265458
cpp
p02937
#include <algorithm> #include <cfloat> #include <complex> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; int main() { string s, t; cin >> s >> t; unordered_map<int, vector<int>> um; for (size_t i = 0; i < s.size(); i++) { int c_i = s[i] - '0'; um[c_i].emplace_back(i); } ll ans = 1; ll curpos = 0; for (size_t j = 0; j < t.size(); j++) { int d_j = t[j] - '0'; if (um[d_j].empty()) { ans = -1; break; } auto lb = lower_bound(um[d_j].begin(), um[d_j].end(), curpos); if (lb == um[d_j].end()) { curpos = 0; ans += (ll)s.size(); j--; } else { curpos = (ll)(*lb); if (j == t.size() - 1) { ans += curpos; } } } cout << ans << endl; return 0; }
#include <algorithm> #include <cfloat> #include <complex> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; int main() { string s, t; cin >> s >> t; unordered_map<int, vector<int>> um; for (size_t i = 0; i < s.size(); i++) { int c_i = s[i] - '0'; um[c_i].emplace_back(i); } ll ans = 0; ll curpos = 0; for (size_t j = 0; j < t.size(); j++) { int d_j = t[j] - '0'; if (um[d_j].empty()) { ans = -1; break; } auto lb = lower_bound(um[d_j].begin(), um[d_j].end(), curpos); if (lb == um[d_j].end()) { curpos = 0; ans += (ll)s.size(); j--; } else { curpos = (ll)(*lb) + 1; if (j == t.size() - 1) { ans += curpos; } } } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "assignment.change" ]
739,907
739,908
u714724786
cpp
p02937
#include <bits/stdc++.h> #define ll long long int #define MOD 1000000007 #define INF 1e18 #define PI 3.14159265358979 using namespace std; ll power(ll n, ll k); ll inv(ll n); ll genfact(ll n, ll k); ll fact(ll n); ll nck(ll n, ll k); int main(void) { string s, t; cin >> s >> t; vector<vector<ll>> a(26, vector<ll>(0)); for (int i = 0; i < (int)s.size(); i++) { a[s[i] - 'a'].emplace_back(i); } ll snum = 1, id = 0, ok = 1; for (int i = 0; i < (int)t.size(); i++) { int n = a[t[i] - 'a'].size(); if (n == 0) { ok = 0; break; } if (a[t[i] - 'a'][n - 1] < id) { snum += 1; id = a[t[i] - 'a'][0]; } else { int l = -1, r = n - 1, mid; while (l + 1 < r) { mid = (l + r) / 2; if (a[t[i] - 'a'][mid] < id) { l = mid; } else r = mid; } id = a[t[i] - 'a'][l + 1]; } } if (ok) cout << (snum - 1) * s.size() + id + 1 << endl; else cout << -1 << endl; return 0; } ll power(ll n, ll k) { ll res = 1; while (k > 0) { if (k & 1) res = res * n % MOD; n = n * n % MOD; k >>= 1; } return res; } ll genfact(ll n, ll k) { ll res = 1; while (k >= 0) { res = (res * (n - k)) % MOD; k--; } return res; } ll inv(ll n) { return power(n, MOD - 2); } ll fact(ll n) { return genfact(n, n - 1); } ll nck(ll n, ll k) { if (k == 0) return 1; if (n <= 0) return 0; return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD; }
#include <bits/stdc++.h> #define ll long long int #define MOD 1000000007 #define INF 1e18 #define PI 3.14159265358979 using namespace std; ll power(ll n, ll k); ll inv(ll n); ll genfact(ll n, ll k); ll fact(ll n); ll nck(ll n, ll k); int main(void) { string s, t; cin >> s >> t; vector<vector<ll>> a(26, vector<ll>(0)); for (int i = 0; i < (int)s.size(); i++) { a[s[i] - 'a'].emplace_back(i); } ll snum = 1, id = -1, ok = 1; for (int i = 0; i < (int)t.size(); i++) { int n = a[t[i] - 'a'].size(); if (n == 0) { ok = 0; break; } if (a[t[i] - 'a'][n - 1] <= id) { snum += 1; id = a[t[i] - 'a'][0]; } else { int l = -1, r = n - 1, mid; while (l + 1 < r) { mid = (l + r) / 2; if (a[t[i] - 'a'][mid] <= id) { l = mid; } else r = mid; } id = a[t[i] - 'a'][l + 1]; } } if (ok) cout << (snum - 1) * s.size() + id + 1 << endl; else cout << -1 << endl; return 0; } ll power(ll n, ll k) { ll res = 1; while (k > 0) { if (k & 1) res = res * n % MOD; n = n * n % MOD; k >>= 1; } return res; } ll genfact(ll n, ll k) { ll res = 1; while (k >= 0) { res = (res * (n - k)) % MOD; k--; } return res; } ll inv(ll n) { return power(n, MOD - 2); } ll fact(ll n) { return genfact(n, n - 1); } ll nck(ll n, ll k) { if (k == 0) return 1; if (n <= 0) return 0; return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,911
739,912
u755121033
cpp
p02937
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <tuple> #include <utility> #include <vector> #define ll long long #define itn int #define endl '\n' #define co(ans) cout << ans << endl #define COYE cout << "YES" << endl #define COYe cout << "Yes" << endl #define COye cout << "yes" << endl #define CONO cout << "NO" << endl #define CONo cout << "No" << endl #define COno cout << "no" << endl #define FORE(i, a) for (auto &i : a) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FFOR(i, a, b) for (int i = (a); i <= (b); ++i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) FFOR(i, 1, n) #define PB push_back #define MP make_pair #define ALL(V) (V).begin(), (V).end() #define SORT(V) sort((V).begin(), (V).end()) #define REVERSE(V) reverse((V).begin(), (V).end()) #define EACH(V, i) \ for (typeof((V).begin()) i = (V).begin(); i != (V).end(); ++i) #define equals(a, b) (fabs((a) - (b)) < EPS) #define INF ((1LL << 62) - (1LL << 31)) #define EPS 1e-10 #define PI 3.141592653589793238 #define MOD 1000000007 #define MAX 5100000 using namespace std; using Edge = pair<int, int>; using Graph = vector<vector<int>>; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } 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; } typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { string S, T; cin >> S >> T; ll ans = 0, cnt = 0, roop = 0, SS = S.size(), TT = T.size(); bool SC[26]; REP(i, 26) SC[i] = false; REP(i, SS) SC[S[i] - 'a'] = true; REP(i, TT) { if (SC[T[i] - 'a'] == false) { co(-1); return 0; } } vector<vector<ll>> L(26); REP(i, SS) { L[S[i] - 'a'].PB(i); } for (int i = 0; i < TT; ++i) { if (cnt >= L[T[i] - 'a'][L[T[i] - 'a'].size() - 1]) { roop++; cnt = L[T[i] - 'a'][0]; } else { auto it = upper_bound(ALL(L[T[i] - 'a']), cnt); cnt = *it; } } ans = roop * SS + cnt + 1; co(ans); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <tuple> #include <utility> #include <vector> #define ll long long #define itn int #define endl '\n' #define co(ans) cout << ans << endl #define COYE cout << "YES" << endl #define COYe cout << "Yes" << endl #define COye cout << "yes" << endl #define CONO cout << "NO" << endl #define CONo cout << "No" << endl #define COno cout << "no" << endl #define FORE(i, a) for (auto &i : a) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FFOR(i, a, b) for (int i = (a); i <= (b); ++i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) FFOR(i, 1, n) #define PB push_back #define MP make_pair #define ALL(V) (V).begin(), (V).end() #define SORT(V) sort((V).begin(), (V).end()) #define REVERSE(V) reverse((V).begin(), (V).end()) #define EACH(V, i) \ for (typeof((V).begin()) i = (V).begin(); i != (V).end(); ++i) #define equals(a, b) (fabs((a) - (b)) < EPS) #define INF ((1LL << 62) - (1LL << 31)) #define EPS 1e-10 #define PI 3.141592653589793238 #define MOD 1000000007 #define MAX 5100000 using namespace std; using Edge = pair<int, int>; using Graph = vector<vector<int>>; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } 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; } typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { string S, T; cin >> S >> T; ll ans = 0, cnt = -1, roop = 0, SS = S.size(), TT = T.size(); bool SC[26]; REP(i, 26) SC[i] = false; REP(i, SS) SC[S[i] - 'a'] = true; REP(i, TT) { if (SC[T[i] - 'a'] == false) { co(-1); return 0; } } vector<vector<ll>> L(26); REP(i, SS) { L[S[i] - 'a'].PB(i); } for (int i = 0; i < TT; ++i) { if (cnt >= L[T[i] - 'a'][L[T[i] - 'a'].size() - 1]) { roop++; cnt = L[T[i] - 'a'][0]; } else { auto it = upper_bound(ALL(L[T[i] - 'a']), cnt); cnt = *it; } } ans = roop * SS + cnt + 1; co(ans); return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
739,913
739,914
u673211643
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define repd(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) repd(i, 0, n) #define all(x) (x).begin(), (x).end() template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; const long long INF = 1LL << 60; typedef pair<int, int> P; int main() { string S, T; cin >> S >> T; vector<vector<ll>> index(26, vector<ll>((ll)S.size(), -1)); rep(i, S.size()) { index[(ll)(S[i] - 'a')][i] = i; } rep(i, 26) { ll place = -1; rep(j, S.size()) { if (index[i][j] != -1) { place = index[i][j]; break; } } if (place == -1) continue; for (ll j = (ll)S.size() - 1; j >= 0; j--) { if (index[i][j] != -1) { place = index[i][j]; } else index[i][j] = place; } } /* rep(i, 26) { cout << "i : " << (char)('a' + i) << endl; rep(j, S.size()) { cout << index[i][j] << endl; } }*/ ll cnt = 0, ans; ll now = -1; ll next; rep(i, T.size()) { if (now == (ll)S.size() - 1) next = index[(ll)(T[i] - 'a')][0]; else next = index[(ll)(T[i] - 'a')][now + 1]; if (next == -1) { cout << -1 << endl; return 0; } if (now > next) { cnt++; } // cout << now << " " << next << " " << cnt << endl; now = next; } ans = cnt * (ll)S.size(); ans += (next + 1); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define repd(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) repd(i, 0, n) #define all(x) (x).begin(), (x).end() template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; const long long INF = 1LL << 60; typedef pair<int, int> P; int main() { string S, T; cin >> S >> T; vector<vector<ll>> index(26, vector<ll>((ll)S.size(), -1)); rep(i, S.size()) { index[(ll)(S[i] - 'a')][i] = i; } rep(i, 26) { ll place = -1; rep(j, S.size()) { if (index[i][j] != -1) { place = index[i][j]; break; } } if (place == -1) continue; for (ll j = (ll)S.size() - 1; j >= 0; j--) { if (index[i][j] != -1) { place = index[i][j]; } else index[i][j] = place; } } /* rep(i, 26) { cout << "i : " << (char)('a' + i) << endl; rep(j, S.size()) { cout << index[i][j] << endl; } } */ ll cnt = 0, ans; ll now = -1; ll next; rep(i, T.size()) { if (now == (ll)S.size() - 1) next = index[(ll)(T[i] - 'a')][0]; else next = index[(ll)(T[i] - 'a')][now + 1]; if (next == -1) { cout << -1 << endl; return 0; } if (now >= next) { cnt++; } // cout << now << " " << next << " " << cnt << endl; now = next; } ans = cnt * (ll)S.size(); ans += (next + 1); cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,919
739,920
u628332144
cpp
p02937
#include <bits/stdc++.h> using namespace std; #define repd(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) repd(i, 0, n) #define all(x) (x).begin(), (x).end() template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; const long long INF = 1LL << 60; typedef pair<int, int> P; int main() { string S, T; cin >> S >> T; vector<vector<ll>> index(26, vector<ll>((ll)S.size(), -1)); rep(i, S.size()) { index[(ll)(S[i] - 'a')][i] = i; } rep(i, 26) { ll place = -1; rep(j, S.size()) { if (index[i][j] != -1) { place = index[i][j]; break; } } if (place == -1) continue; for (ll j = (ll)S.size() - 1; j >= 0; j--) { if (index[i][j] != -1) { place = index[i][j]; } else index[i][j] = place; } } /* rep(i, 26) { cout << "i : " << (char)('a' + i) << endl; rep(j, S.size()) { cout << index[i][j] << endl; } }*/ ll cnt = 0, ans; ll now = 0; ll next; rep(i, T.size()) { if (now == (ll)S.size() - 1) next = index[(ll)(T[i] - 'a')][0]; else next = index[(ll)(T[i] - 'a')][now + 1]; if (next == -1) { cout << -1 << endl; return 0; } if (now > next) { cnt++; } now = next; // cout << now << " " << next << " " << cnt << endl; } ans = cnt * (ll)S.size(); ans += (next + 1); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define repd(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) repd(i, 0, n) #define all(x) (x).begin(), (x).end() template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; const long long INF = 1LL << 60; typedef pair<int, int> P; int main() { string S, T; cin >> S >> T; vector<vector<ll>> index(26, vector<ll>((ll)S.size(), -1)); rep(i, S.size()) { index[(ll)(S[i] - 'a')][i] = i; } rep(i, 26) { ll place = -1; rep(j, S.size()) { if (index[i][j] != -1) { place = index[i][j]; break; } } if (place == -1) continue; for (ll j = (ll)S.size() - 1; j >= 0; j--) { if (index[i][j] != -1) { place = index[i][j]; } else index[i][j] = place; } } /* rep(i, 26) { cout << "i : " << (char)('a' + i) << endl; rep(j, S.size()) { cout << index[i][j] << endl; } } */ ll cnt = 0, ans; ll now = -1; ll next; rep(i, T.size()) { if (now == (ll)S.size() - 1) next = index[(ll)(T[i] - 'a')][0]; else next = index[(ll)(T[i] - 'a')][now + 1]; if (next == -1) { cout << -1 << endl; return 0; } if (now >= next) { cnt++; } // cout << now << " " << next << " " << cnt << endl; now = next; } ans = cnt * (ll)S.size(); ans += (next + 1); cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,921
739,920
u628332144
cpp
p02937
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" #define PI 3.14159265358979 #define MOD 1000000007 // = 10^9 + 7 using namespace std; using ll = long long; void solve() { string s, t; cin >> s >> t; ll s_size = s.length(); ll t_size = t.length(); vector<int> bin[26] = {}; for (int i = 0; i < s_size; ++i) { bin[s[i] - 'a'].emplace_back(i); } for (int i = 0; i < t_size; ++i) { if (bin[t[i] - 'a'].empty()) { cout << "-1"; return; } } vector<int> t_num(t_size, -1); t_num[0] = bin[t[0] - 'a'][0]; for (int i = 1; i < t_size; ++i) { t_num[i] = bin[t[i] - 'a'][0]; for (int j = 0; j < bin[t[i] - 'a'].size(); ++j) { if (bin[t[i] - 'a'][j] > t_num[i - 1]) { t_num[i] = bin[t[i] - 'a'][j]; break; } } } ll ans = 0; // cout << t_num[0]; for (int i = 1; i < t_size; ++i) { // cout << " " << t_num[i]; if (t_num[i - 1] > t_num[i]) { ans += s_size; } } // cout << endl; cout << ans + t_num.back() + 1; return; } int main() { fastio; solve(); return 0; }
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" #define PI 3.14159265358979 #define MOD 1000000007 // = 10^9 + 7 using namespace std; using ll = long long; void solve() { string s, t; cin >> s >> t; ll s_size = s.length(); ll t_size = t.length(); vector<int> bin[26] = {}; for (int i = 0; i < s_size; ++i) { bin[s[i] - 'a'].emplace_back(i); } for (int i = 0; i < t_size; ++i) { if (bin[t[i] - 'a'].empty()) { cout << "-1"; return; } } vector<int> t_num(t_size, -1); t_num[0] = bin[t[0] - 'a'][0]; for (int i = 1; i < t_size; ++i) { t_num[i] = bin[t[i] - 'a'][0]; for (int j = 0; j < bin[t[i] - 'a'].size(); ++j) { if (bin[t[i] - 'a'][j] > t_num[i - 1]) { t_num[i] = bin[t[i] - 'a'][j]; break; } } } ll ans = 0; // cout << t_num[0]; for (int i = 1; i < t_size; ++i) { // cout << " " << t_num[i]; if (t_num[i - 1] >= t_num[i]) { ans += s_size; } } // cout << endl; cout << ans + t_num.back() + 1; return; } int main() { fastio; solve(); return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
739,930
739,931
u866535689
cpp
p02937
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> // using i128 = boost::multiprecision::int128_t; #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using ld = long double; using V = vector<int>; using Vll = vector<ll>; using Vld = vector<ld>; using Vbo = vector<bool>; using VV = vector<V>; using VVll = vector<Vll>; using VVld = vector<Vld>; using VVbo = vector<Vbo>; using VVV = vector<VV>; using VVVll = vector<VVll>; using P = pair<int, int>; using Pll = pair<ll, ll>; using Pld = pair<ld, ld>; #define rep2(i, m, n) for (int i = int(m); i < int(n); ++i) #define drep2(i, m, n) for (int i = int(m) - 1; i >= int(n); --i) #define rep(i, n) rep2(i, 0, n) #define drep(i, n) drep2(i, n, 0) #define all(a) a.begin(), a.end() struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; } template <typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits const int INF = 1 << 30; const ll INFll = 1ll << 62; const ld EPS = 1e-10; const ld PI = acos(-1.0); const int MOD = int(1e9) + 7; // const int MOD = 998244353; int main() { string s, t; cin >> s >> t; int m = s.size(); VV lc(26, V()); rep(i, m) { int x = s[i] - 'a'; lc[x].push_back(i); } int i = -1; ll cnt = 0; for (auto c : t) { int x = c - 'a'; if (lc[x].size() == 0) { cout << -1 << "\n"; return 0; } auto it = lower_bound(all(lc[x]), i); if (it == lc[x].end()) { i = lc[x][0]; ++cnt; } else i = *it; } ll ans = cnt * m + i + 1; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> // using i128 = boost::multiprecision::int128_t; #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using ld = long double; using V = vector<int>; using Vll = vector<ll>; using Vld = vector<ld>; using Vbo = vector<bool>; using VV = vector<V>; using VVll = vector<Vll>; using VVld = vector<Vld>; using VVbo = vector<Vbo>; using VVV = vector<VV>; using VVVll = vector<VVll>; using P = pair<int, int>; using Pll = pair<ll, ll>; using Pld = pair<ld, ld>; #define rep2(i, m, n) for (int i = int(m); i < int(n); ++i) #define drep2(i, m, n) for (int i = int(m) - 1; i >= int(n); --i) #define rep(i, n) rep2(i, 0, n) #define drep(i, n) drep2(i, n, 0) #define all(a) a.begin(), a.end() struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; } template <typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits const int INF = 1 << 30; const ll INFll = 1ll << 62; const ld EPS = 1e-10; const ld PI = acos(-1.0); const int MOD = int(1e9) + 7; // const int MOD = 998244353; int main() { string s, t; cin >> s >> t; int m = s.size(); VV lc(26, V()); rep(i, m) { int x = s[i] - 'a'; lc[x].push_back(i); } int i = -1; ll cnt = 0; for (auto c : t) { int x = c - 'a'; if (lc[x].size() == 0) { cout << -1 << "\n"; return 0; } auto it = lower_bound(all(lc[x]), i + 1); if (it == lc[x].end()) { i = lc[x][0]; ++cnt; } else i = *it; } ll ans = cnt * m + i + 1; cout << ans << "\n"; return 0; }
[ "assignment.change" ]
739,934
739,935
u366381207
cpp