problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02937 | Python | Runtime Error | # Library
import bisect
alp = "abcdefghijklmnopqrstuvwxyz"
#
s = input()
t = input()
ss = s * 2
index = -1
cir = 0
letter = []
res = 0
for i in range(len(ss)):
letter.append([ss[i], i])
# Sort出来る.
letter.sort()
for i in range(len(t)):
search = [t[i], index]
tmp_ind = bisect.bisect(letter, search)
# print("now searching " + str(search))
# print("find: " + str(tmp_ind))
# print("found: " + str(letter[tmp_ind]))
if t[i] != letter[tmp_ind][0]:
# Not exist
res = -1
break
index += letter[tmp_ind][1] - index
if index >= len(s):
cir += 1
index -= len(s)
# print("cir,index : " + str(cir) + " " + str(index))
res = cir * len(s) + index + 1
print(res)
| # Library
import bisect
alp = "abcdefghijklmnopqrstuvwxyz"
#
s = input()
t = input()
ss = s * 2
index = -1
cir = 0
letter = []
res = 0
for i in range(len(ss)):
letter.append([ss[i], i])
# Sort出来る.
letter.sort()
for i in range(len(t)):
search = [t[i], index]
tmp_ind = bisect.bisect(letter, search)
# print("now searching " + str(search))
# print("find: " + str(tmp_ind))
# print("found: " + str(letter[tmp_ind]))
if tmp_ind == len(ss):
res = -1
break
if t[i] != letter[tmp_ind][0]:
# Not exist
res = -1
break
index += letter[tmp_ind][1] - index
if index >= len(s):
cir += 1
index -= len(s)
# print("cir,index : " + str(cir) + " " + str(index))
res = cir * len(s) + index + 1
print(res)
| insert | 26 | 26 | 26 | 29 | 0 | |
p02937 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
using ll = long long;
int main() {
string s, t;
cin >> s >> t;
ll s_size = s.length();
ll t_size = t.length();
ll s_table[26][s_size];
ll s_cur[26];
bool used[26];
for (int i = 0; i < 26; i++) {
for (int j = 0; j < s_size; j++) {
s_table[i][j] = -1;
}
s_cur[i] = -1;
used[i] = false;
}
for (int i = s_size - 1; i >= 0; i--) {
ll c = s.at(i) - 'a';
s_cur[c] = i;
used[c] = true;
for (int j = 0; j < 26; j++) {
s_table[j][i] = s_cur[j];
}
}
ll ans = 0;
ll s_pos = 0;
for (int i = 0; i < t_size; i++) {
int c = t.at(i) - 'a';
if (used[c] == false) {
cout << -1 << endl;
return 0;
}
int cur = s_table[c][s_pos];
// cout << "cur1:" << cur << endl;
if (cur == -1) {
ans += (s_size - s_pos);
s_pos = 0;
cur = s_table[c][s_pos];
}
// cout << "cur2:" << cur << endl;
// cout << "s_pos:" << cur << endl;
ans += cur - s_pos + 1;
s_pos = cur + 1;
// cout << "ans:" << ans << endl;
}
cout << ans << endl;
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
using ll = long long;
int main() {
string s, t;
cin >> s >> t;
ll s_size = s.length();
ll t_size = t.length();
ll s_table[26][s_size];
ll s_cur[26];
bool used[26];
for (int i = 0; i < 26; i++) {
for (int j = 0; j < s_size; j++) {
s_table[i][j] = -1;
}
s_cur[i] = -1;
used[i] = false;
}
for (int i = s_size - 1; i >= 0; i--) {
ll c = s.at(i) - 'a';
s_cur[c] = i;
used[c] = true;
for (int j = 0; j < 26; j++) {
s_table[j][i] = s_cur[j];
}
}
ll ans = 0;
ll s_pos = 0;
for (int i = 0; i < t_size; i++) {
int c = t.at(i) - 'a';
if (used[c] == false) {
cout << -1 << endl;
return 0;
}
int cur = s_table[c][s_pos];
// cout << "cur1:" << cur << endl;
if (cur == -1) {
ans += (s_size - s_pos);
s_pos = 0;
cur = s_table[c][s_pos];
}
// cout << "cur2:" << cur << endl;
// cout << "s_pos:" << cur << endl;
ans += cur - s_pos + 1;
s_pos = (cur + 1) % s_size;
// cout << "ans:" << ans << endl;
}
cout << ans << endl;
return 0;
}
| replace | 52 | 53 | 52 | 53 | 0 | |
p02937 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
string s, t;
vector<int> dict[30];
long long ans;
long long search(char t) {
long long x;
long long y = 0;
x = ans % s.length();
if (dict[(int)t - 97][0] > x) {
return dict[(int)t - 97][0] - x + y;
} else if (dict[(int)t - 97][dict[(int)t - 97].size() - 1] <= x) {
y = s.length() - x;
x = 0;
if (dict[(int)t - 97][0] > x) {
return dict[(int)t - 97][0] + y;
}
}
long long ub = dict[(int)t - 97].size() - 1;
long long lb = 0;
long long mid = (ub + lb) / 2;
while (ub - lb > 1) {
if (dict[(int)t - 97][mid] > x) {
ub = mid;
} else {
lb = mid;
}
}
return dict[(int)t - 97][ub] - x + y;
}
int main() {
cin >> s >> t;
ans = 0;
for (int i = 0; i < s.length(); i++) {
dict[(int)s[i] - 97].push_back(i + 1);
}
for (int i = 0; i < t.length(); i++) {
if (dict[(int)t[i] - 97].empty()) {
ans = -1;
break;
} else if (dict[(int)t[i] - 97].size() == 1) {
long long x;
x = ans % s.length();
if (dict[(int)t[i] - 97][0] > x) {
x = dict[(int)t[i] - 97][0] - x;
ans += x;
} else {
ans += (s.length() - x) + dict[(int)t[i] - 97][0];
}
} else {
ans += search(t[i]);
}
// cout << ans << endl;
}
cout << ans << endl;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
string s, t;
vector<int> dict[30];
long long ans;
long long search(char t) {
long long x;
long long y = 0;
x = ans % s.length();
if (dict[(int)t - 97][0] > x) {
return dict[(int)t - 97][0] - x + y;
} else if (dict[(int)t - 97][dict[(int)t - 97].size() - 1] <= x) {
y = s.length() - x;
x = 0;
if (dict[(int)t - 97][0] > x) {
return dict[(int)t - 97][0] + y;
}
}
long long ub = dict[(int)t - 97].size() - 1;
long long lb = 0;
long long mid = (ub + lb) / 2;
while (ub - lb > 1) {
if (dict[(int)t - 97][mid] > x) {
ub = mid;
} else {
lb = mid;
}
mid = (ub + lb) / 2;
}
return dict[(int)t - 97][ub] - x + y;
}
int main() {
cin >> s >> t;
ans = 0;
for (int i = 0; i < s.length(); i++) {
dict[(int)s[i] - 97].push_back(i + 1);
}
for (int i = 0; i < t.length(); i++) {
if (dict[(int)t[i] - 97].empty()) {
ans = -1;
break;
} else if (dict[(int)t[i] - 97].size() == 1) {
long long x;
x = ans % s.length();
if (dict[(int)t[i] - 97][0] > x) {
x = dict[(int)t[i] - 97][0] - x;
ans += x;
} else {
ans += (s.length() - x) + dict[(int)t[i] - 97][0];
}
} else {
ans += search(t[i]);
}
// cout << ans << endl;
}
cout << ans << endl;
} | insert | 38 | 38 | 38 | 39 | TLE | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll findNext(ll curr_idx, ll len, vector<ll> pos) {
ll multiplier = curr_idx / len;
curr_idx = curr_idx % len;
ll next_pos = lower_bound(pos.begin(), pos.end(), curr_idx) - pos.begin();
if (next_pos == pos.size())
return len * (multiplier + 1) + pos[0];
return len * multiplier + pos[next_pos];
}
bool ifPossible(string s, string t) {
for (int i = 0; i < 26; ++i) {
char ch = (char)(i + 'a');
bool find_s = (s.find(ch) != string ::npos);
bool find_t = (t.find(ch) != string ::npos);
if (find_s == false && find_t == true)
return false;
}
return true;
}
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
if (!ifPossible(s, t)) {
cout << -1;
return 0;
}
vector<ll> pos[26];
ll s_len = s.length(), t_len = t.length();
for (int i = 0; i < s_len; ++i)
pos[s[i] - 'a'].push_back(i);
ll start = 0, t_pos = 0;
while (t_pos < t_len) {
start = findNext(start, s_len, pos[t[t_pos] - 'a']) + 1;
++t_pos;
}
cout << start;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll findNext(ll curr_idx, ll len, vector<ll> pos) {
ll multiplier = curr_idx / len;
curr_idx = curr_idx % len;
ll next_pos = lower_bound(pos.begin(), pos.end(), curr_idx) - pos.begin();
if (next_pos == pos.size())
return len * (multiplier + 1) + pos[0];
return len * multiplier + pos[next_pos];
}
bool ifPossible(string s, string t) {
for (int i = 0; i < 26; ++i) {
char ch = (char)(i + 'a');
bool find_s = (s.find(ch) != string ::npos);
bool find_t = (t.find(ch) != string ::npos);
if (find_s == false && find_t == true)
return false;
}
return true;
}
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
if (!ifPossible(s, t)) {
cout << -1;
return 0;
}
vector<ll> pos[26];
ll s_len = s.length(), t_len = t.length();
for (int i = 0; i < s_len; ++i)
pos[s[i] - 'a'].push_back(i);
ll start = 0, t_pos = 0;
while (t_pos < t_len) {
ll len = s_len, curr_idx = start, multiplier = curr_idx / len;
curr_idx = curr_idx % len;
ll next_pos = lower_bound(pos[t[t_pos] - 'a'].begin(),
pos[t[t_pos] - 'a'].end(), curr_idx) -
pos[t[t_pos] - 'a'].begin();
if (next_pos == pos[t[t_pos] - 'a'].size())
start = len * (multiplier + 1) + pos[t[t_pos] - 'a'][0] + 1;
else
start = len * multiplier + pos[t[t_pos] - 'a'][next_pos] + 1;
++t_pos;
}
cout << start;
} | replace | 48 | 49 | 48 | 58 | TLE | |
p02937 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S, T;
cin >> S >> T;
int64_t s, t;
s = S.size();
t = T.size();
S = S + S;
vector<vector<int64_t>> a(1e+5 + 10, vector<int64_t>(26, 2 * s));
for (int64_t i = 2 * s - 1; i >= 0; --i) {
for (int64_t j = 0; j < 26; ++j) {
a[i][j] = a[i + 1][j];
}
a[i][S[i] - 'a'] = i + 1;
}
int64_t cur = 0;
bool flg = false;
for (auto b : T) {
int64_t c = b - 'a';
int64_t pos = cur % s;
if (a[pos][c] == 2 * s) {
flg = true;
break;
}
cur = cur + a[pos][c] - pos;
}
if (flg) {
cout << -1 << endl;
} else {
cout << cur << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S, T;
cin >> S >> T;
int64_t s, t;
s = S.size();
t = T.size();
S = S + S;
vector<vector<int64_t>> a(2 * s + 10, vector<int64_t>(26, 2 * s));
for (int64_t i = 2 * s - 1; i >= 0; --i) {
for (int64_t j = 0; j < 26; ++j) {
a[i][j] = a[i + 1][j];
}
a[i][S[i] - 'a'] = i + 1;
}
int64_t cur = 0;
bool flg = false;
for (auto b : T) {
int64_t c = b - 'a';
int64_t pos = cur % s;
if (a[pos][c] == 2 * s) {
flg = true;
break;
}
cur = cur + a[pos][c] - pos;
}
if (flg) {
cout << -1 << endl;
} else {
cout << cur << endl;
}
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1 << (n))
#define ii(x) \
int x; \
cin >> (x)
#define ii2(x, y) \
int x, y; \
cin >> (x) >> (y)
#define ii3(x, y, z) \
int x, y, z; \
cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x) ? (ok) : (ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;
}
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 const INF = 1001001001;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
s += s;
vvi mp(26);
rep(i, SZ(s)) { mp[s[i] - 'a'].push_back(i); }
// tにあってsにない文字があるとtを作ることはできない
rep(i, SZ(t)) {
if (!SZ(mp[t[i] - 'a'])) {
cout << -1 << endl;
return 0;
}
}
ll cur = 0;
ll ans = 0;
rep(i, SZ(t)) {
vi v = mp[t[i] - 'a'];
ll iter = lower_bound(v.begin(), v.end(), cur) - v.begin();
ll idx = v[iter];
ans += idx - cur + 1;
if (idx >= SZ(s) / 2)
idx -= SZ(s) / 2;
cur = idx + 1;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1 << (n))
#define ii(x) \
int x; \
cin >> (x)
#define ii2(x, y) \
int x, y; \
cin >> (x) >> (y)
#define ii3(x, y, z) \
int x, y, z; \
cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x) ? (ok) : (ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;
}
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 const INF = 1001001001;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
s += s;
vvi mp(26);
rep(i, SZ(s)) { mp[s[i] - 'a'].push_back(i); }
// tにあってsにない文字があるとtを作ることはできない
rep(i, SZ(t)) {
if (!SZ(mp[t[i] - 'a'])) {
cout << -1 << endl;
return 0;
}
}
ll cur = 0;
ll ans = 0;
rep(i, SZ(t)) {
ll iter = lower_bound(mp[t[i] - 'a'].begin(), mp[t[i] - 'a'].end(), cur) -
mp[t[i] - 'a'].begin();
ll idx = mp[t[i] - 'a'][iter];
ans += idx - cur + 1;
if (idx >= SZ(s) / 2)
idx -= SZ(s) / 2;
cur = idx + 1;
}
cout << ans << endl;
return 0;
} | replace | 65 | 68 | 65 | 68 | TLE | |
p02937 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char a[maxn];
char b[maxn];
vector<int> c[30];
int main() {
scanf("%s %s", a, b);
int n = strlen(a);
int m = strlen(b);
long long sum = 0;
for (int i = 0; i < n; i++) {
c[a[i] - 'a'].push_back(i + 1);
}
int j;
int x = b[0] - 'a';
if (c[x].empty()) {
printf("-1\n");
return 0;
}
int k = c[x][0];
sum += k;
for (int i = 1; i < m; i++) {
x = b[i] - 'a';
j = upper_bound(c[x].begin(), c[x].end(), k) - c[x].begin();
if (j == c[x].end() - c[x].begin())
sum += c[x][0] + n - k, k = c[x][0];
else {
sum += c[x][j] - k;
k = c[x][j];
}
}
printf("%lld\n", sum);
} | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char a[maxn];
char b[maxn];
vector<int> c[30];
int main() {
scanf("%s %s", a, b);
int n = strlen(a);
int m = strlen(b);
long long sum = 0;
for (int i = 0; i < n; i++) {
c[a[i] - 'a'].push_back(i + 1);
}
int j;
int x = b[0] - 'a';
if (c[x].empty()) {
printf("-1\n");
return 0;
}
int k = c[x][0];
sum += k;
for (int i = 1; i < m; i++) {
x = b[i] - 'a';
if (c[x].empty()) {
printf("-1\n");
return 0;
}
j = upper_bound(c[x].begin(), c[x].end(), k) - c[x].begin();
if (j == c[x].end() - c[x].begin())
sum += c[x][0] + n - k, k = c[x][0];
else {
sum += c[x][j] - k;
k = c[x][j];
}
}
printf("%lld\n", sum);
} | insert | 24 | 24 | 24 | 28 | 0 | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define pp pair<int, int>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
ll MOD = 1000000007;
ll mod = 998244353;
int inf = 1000000000;
ll INF = 10000000000000000;
int main() {
string s, t;
cin >> s >> t;
vector<vector<ll>> o(26, vector<ll>(0));
rep(i, s.size()) {
int x = s.at(i) - 'a';
o.at(x).push_back(i);
}
ll ans = 0, e = -1;
rep(i, t.size()) {
int x = t.at(i) - 'a';
if (o.at(x).size() == 0) {
cout << -1 << endl;
return 0;
} else {
vector<ll> y = o.at(x);
auto itt = upper_bound(y.begin(), y.end(), e);
if (itt == y.end()) {
ans += y.at(0) + s.size() - e;
e = y.at(0);
} else {
ans += *itt - e;
e = *itt;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define pp pair<int, int>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
ll MOD = 1000000007;
ll mod = 998244353;
int inf = 1000000000;
ll INF = 10000000000000000;
int main() {
string s, t;
cin >> s >> t;
vector<vector<ll>> o(26, vector<ll>(0));
rep(i, s.size()) {
int x = s.at(i) - 'a';
o.at(x).push_back(i);
}
ll ans = 0, e = -1;
rep(i, t.size()) {
int x = t.at(i) - 'a';
if (o.at(x).size() == 0) {
cout << -1 << endl;
return 0;
} else {
auto itt = upper_bound(o.at(x).begin(), o.at(x).end(), e);
if (itt == o.at(x).end()) {
ans += o.at(x).at(0) + s.size() - e;
e = o.at(x).at(0);
} else {
ans += *itt - e;
e = *itt;
}
}
}
cout << ans << endl;
} | replace | 24 | 29 | 24 | 28 | TLE | |
p02937 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
string ss = s + s;
vector<vector<int>> nex(s.length(), vector<int>(26, -1));
vector<int> idx(26, -1);
for (size_t i = ss.length() - 1; i >= s.length(); --i) {
idx[ss[i] - 'a'] = i;
}
for (size_t i = s.length() - 1; i--;) {
nex[i] = idx;
idx[s[i] - 'a'] = i;
}
long long ans = 0;
size_t i = idx[t[0] - 'a'];
if (idx[t[0] - 'a'] < 0) {
cout << -1 << endl;
return 0;
}
ans += i + 1;
for (size_t j = 1; j < t.length(); ++j) {
int c = t[j] - 'a';
if (nex[i][c] < 0) {
cout << -1 << endl;
return 0;
}
ans += (nex[i][c] - i);
i = nex[i][c] % s.length();
}
cout << ans << endl;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
string ss = s + s;
vector<vector<int>> nex(s.length(), vector<int>(26, -1));
vector<int> idx(26, -1);
for (size_t i = ss.length() - 1; i >= s.length(); --i) {
idx[ss[i] - 'a'] = i;
}
for (size_t i = s.length() - 1; i < s.length(); --i) {
nex[i] = idx;
idx[s[i] - 'a'] = i;
}
long long ans = 0;
size_t i = idx[t[0] - 'a'];
if (idx[t[0] - 'a'] < 0) {
cout << -1 << endl;
return 0;
}
ans += i + 1;
for (size_t j = 1; j < t.length(); ++j) {
int c = t[j] - 'a';
if (nex[i][c] < 0) {
cout << -1 << endl;
return 0;
}
ans += (nex[i][c] - i);
i = nex[i][c] % s.length();
}
cout << ans << endl;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02937 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
string s, t;
cin >> t >> s;
vector<vector<long>> tc(26);
long n = t.size();
for (long i = 0; i < n; i++) {
// cout << t[i] << " " << t[i] - 'a' << endl;
tc[t[i] - 'a'].push_back(i);
}
n = s.size();
long cnt = 0;
long m = -1;
vector<vector<long>> ntc = tc;
for (long i = 0; i < n; i++) {
if (tc[s[i] - 'a'].size() <= 0) {
cout << -1 << endl;
return 0;
}
bool flag = false;
for (auto j : tc[s[i] - 'a']) {
// cout << j << " " << m << endl;
if (j <= m)
continue;
else {
flag = true;
m = j;
break;
}
}
if (!flag) {
cnt++;
m = tc[s[i] - 'a'][0];
}
}
// cout << cnt << " " << m << endl;
cout << (long long)t.size() * cnt + m + 1 << endl;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
string s, t;
cin >> t >> s;
vector<vector<long>> tc(26);
long n = t.size();
for (long i = 0; i < n; i++) {
// cout << t[i] << " " << t[i] - 'a' << endl;
tc[t[i] - 'a'].push_back(i);
}
n = s.size();
long cnt = 0;
long m = -1;
vector<vector<long>> ntc = tc;
for (long i = 0; i < n; i++) {
if (tc[s[i] - 'a'].size() <= 0) {
cout << -1 << endl;
return 0;
}
bool flag = false;
int ind = s[i] - 'a';
auto it = upper_bound(tc[ind].begin(), tc[ind].end(), m);
if (it != tc[ind].end()) {
flag = true;
m = *it;
}
if (!flag) {
cnt++;
m = tc[s[i] - 'a'][0];
}
}
// cout << cnt << " " << m << endl;
cout << (long long)t.size() * cnt + m + 1 << endl;
} | replace | 33 | 42 | 33 | 38 | TLE | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define EM 1000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9 + 7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> dp(26, vector<int>(2 * s.size(), INF));
string ss = s + s;
for (int i = 0; i < 26; i++) {
int c = 'a' + i;
int l = 0;
for (int j = 0; j < ss.size(); j++) {
if (ss[j] == c) {
while (l < j) {
dp[i][l] = j - l;
l++;
}
}
if (l >= s.size())
break;
}
}
LL ans = 0;
bool ju = false;
for (int j = 0; j < s.size(); j++) {
if (t[0] == s[j]) {
ju = true;
ans += j + 1;
int r = j;
for (int k = 1; k < t.size(); k++) {
int d = dp[t[k] - 'a'][r];
if (d == INF) {
ju = false;
break;
}
ans += d;
r += d;
r %= s.size();
}
if (ju)
break;
}
}
if (ju)
cout << ans << endl;
else
cout << -1 << endl;
} | #include <bits/stdc++.h>
#define EM 1000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9 + 7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> dp(26, vector<int>(2 * s.size(), INF));
string ss = s + s;
for (int i = 0; i < 26; i++) {
int c = 'a' + i;
int l = 0;
for (int j = 0; j < ss.size(); j++) {
if (ss[j] == c) {
while (l < j) {
dp[i][l] = j - l;
l++;
}
}
if (l >= s.size())
break;
}
}
LL ans = 0;
bool ju = false;
for (int j = 0; j < s.size(); j++) {
if (t[0] == s[j]) {
ju = true;
ans += j + 1;
int r = j;
for (int k = 1; k < t.size(); k++) {
int d = dp[t[k] - 'a'][r];
if (d == INF) {
ju = false;
break;
}
ans += d;
r += d;
r %= s.size();
}
break;
}
}
if (ju)
cout << ans << endl;
else
cout << -1 << endl;
} | replace | 64 | 66 | 64 | 65 | TLE | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> memo(26);
int cur = 0; // 今何週目を見ているか
int dex = 0; // 次に何文字目をみるか
ll ans = 0;
for (int i = 0; i < s.size(); i++) {
memo[s[i] - 'a'].push_back(i);
}
int judge = 1;
for (int i = 0; i < t.size(); i++) {
if (memo[t[i] - 'a'].size() == 0) {
judge = 0;
cout << -1 << endl;
break;
}
int curjudge = 1;
for (int j = 0; j < memo[t[i] - 'a'].size(); j++) {
if (dex <= memo[t[i] - 'a'][j]) {
curjudge = 0;
dex = memo[t[i] - 'a'][j] + 1;
break;
}
}
if (curjudge) {
cur++;
dex = memo[t[i] - 'a'][0] + 1;
}
}
if (judge)
cout << cur * s.size() + dex << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> memo(26);
int cur = 0; // 今何週目を見ているか
int dex = 0; // 次に何文字目をみるか
ll ans = 0;
for (int i = 0; i < s.size(); i++) {
memo[s[i] - 'a'].push_back(i);
}
int judge = 1;
for (int i = 0; i < t.size(); i++) {
if (memo[t[i] - 'a'].size() == 0) {
judge = 0;
cout << -1 << endl;
break;
}
int curjudge = 1;
/*for(int j = 0; j < memo[t[i]-'a'].size(); j++){
if(dex <= memo[t[i]-'a'][j]){
curjudge = 0;
dex = memo[t[i]-'a'][j] + 1;
break;
}
}*/
int index =
int(lower_bound(memo[t[i] - 'a'].begin(), memo[t[i] - 'a'].end(), dex) -
memo[t[i] - 'a'].begin());
if (index < memo[t[i] - 'a'].size() && dex <= memo[t[i] - 'a'][index]) {
dex = memo[t[i] - 'a'][index] + 1;
curjudge = 0;
}
if (curjudge) {
cur++;
dex = memo[t[i] - 'a'][0] + 1;
}
}
if (judge)
cout << cur * s.size() + dex << endl;
} | replace | 23 | 29 | 23 | 36 | TLE | |
p02937 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007
int main() {
string s, t, u;
cin >> s >> t;
u = s + s;
ll x = s.size(), y = t.size();
vll hu[26];
rep(i, 2 * x) {
int j = s[i] - 'a';
hu[j].pb(i);
}
vector<vll> next(x, vll(26, -1));
// next[i][j]はsのi番目(0-origin)以降(i含む)でjが初めて出てくる場所
rep(i, x) {
rep(j, 26) {
if (hu[j].empty())
continue;
ll c = *lower_bound(all(hu[j]), i);
next[i][j] = c % x;
}
}
ll ans = 0;
vll So(100005, -1); // greedyにtのi番目に対応してsの文字の出現場所を列挙
bool f = true;
rep(i, y) {
int j = t[i] - 'a';
So[i + 1] = next[(So[i] + 1) % x][j];
if (So[i + 1] == -1) {
f = false;
break;
}
ll tmp = (So[i + 1] > So[i] ? So[i + 1] - So[i] : So[i + 1] - So[i] + x);
ans = ans + tmp;
}
cout << (f ? ans : -1) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007
int main() {
string s, t, u;
cin >> s >> t;
u = s + s;
ll x = s.size(), y = t.size();
vll hu[26];
rep(i, 2 * x) {
int j = u[i] - 'a';
hu[j].pb(i);
}
vector<vll> next(x, vll(26, -1));
// next[i][j]はsのi番目(0-origin)以降(i含む)でjが初めて出てくる場所
rep(i, x) {
rep(j, 26) {
if (hu[j].empty())
continue;
ll c = *lower_bound(all(hu[j]), i);
next[i][j] = c % x;
}
}
ll ans = 0;
vll So(100005, -1); // greedyにtのi番目に対応してsの文字の出現場所を列挙
bool f = true;
rep(i, y) {
int j = t[i] - 'a';
So[i + 1] = next[(So[i] + 1) % x][j];
if (So[i + 1] == -1) {
f = false;
break;
}
ll tmp = (So[i + 1] > So[i] ? So[i + 1] - So[i] : So[i + 1] - So[i] + x);
ans = ans + tmp;
}
cout << (f ? ans : -1) << endl;
}
| replace | 27 | 28 | 27 | 28 | -11 | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// const ll p = 1e9 + 7;
// const ll p = 998244353;
string s, t;
cin >> s >> t;
ll n = s.size(), m = t.size();
vll cnt(26, 0);
for (ll i = 0; i < n; i++)
cnt[s[i] - 'a']++;
for (ll i = 0; i < m; i++) {
if (cnt[t[i] - 'a'] == 0) {
cout << -1 << endl;
return 0;
}
}
vector<vll> v(26, vll(0));
for (ll i = 0; i < n; i++)
v[s[i] - 'a'].push_back(i);
ll ans = 1, prev_idx = -1;
for (ll i = 0; i < m; i++) {
for (ll j = 0; j < v[t[i] - 'a'].size(); j++) {
if (v[t[i] - 'a'][j] > prev_idx) {
prev_idx = v[t[i] - 'a'][j];
break;
}
if (j == v[t[i] - 'a'].size() - 1) {
prev_idx = v[t[i] - 'a'][0];
ans++;
}
}
}
cout << n * (ans - 1) + prev_idx + 1 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// const ll p = 1e9 + 7;
// const ll p = 998244353;
string s, t;
cin >> s >> t;
ll n = s.size(), m = t.size();
vll cnt(26, 0);
for (ll i = 0; i < n; i++)
cnt[s[i] - 'a']++;
for (ll i = 0; i < m; i++) {
if (cnt[t[i] - 'a'] == 0) {
cout << -1 << endl;
return 0;
}
}
vector<vll> v(26, vll(0));
for (ll i = 0; i < n; i++)
v[s[i] - 'a'].push_back(i);
ll ans = 1, prev_idx = -1;
for (ll i = 0; i < m; i++) {
auto itr = upper_bound(all(v[t[i] - 'a']), prev_idx);
if (itr == v[t[i] - 'a'].end()) {
prev_idx = v[t[i] - 'a'][0];
ans++;
} else
prev_idx = *itr;
}
cout << n * (ans - 1) + prev_idx + 1 << endl;
}
| replace | 40 | 50 | 40 | 46 | TLE | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
string ss = s + s;
map<char, vi> ss_m;
for (int i = 0; i < ss.length(); i++) {
ss_m[ss[i]].push_back(i + 1);
}
vi t_i(t.length() + 1, 0);
for (int i = 0; i < t.length(); i++) {
auto &v = ss_m[t[i]];
if (v.size() == 0) {
cout << -1 << endl;
return 0;
}
for (int j = 0; j < v.size(); j++) {
if (t_i[i] < v[j]) {
t_i[i + 1] = (v[j] > s.length()) ? v[j] - s.length() : v[j];
break;
}
}
}
// for (int i = 0; i < t_i.size(); i++) {
// printf("%d ", t_i[i]);
// }
// printf("\n");
ll ans = 0;
for (int i = 1; i < t_i.size(); i++) {
if (i == t_i.size() - 1) {
// printf("last\n");
ans += t_i[i];
} else {
if (t_i[i] >= t_i[i + 1]) {
ans += s.length();
// printf("ans=%d\n", ans);
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
string ss = s + s;
map<char, vi> ss_m;
for (int i = 0; i < ss.length(); i++) {
ss_m[ss[i]].push_back(i + 1);
}
vi t_i(t.length() + 1, 0);
for (int i = 0; i < t.length(); i++) {
auto &v = ss_m[t[i]];
if (v.size() == 0) {
cout << -1 << endl;
return 0;
}
// for (int j = 0; j < v.size(); j++) {
// if (t_i[i] < v[j]) {
// t_i[i + 1] = (v[j] > s.length()) ? v[j] - s.length() : v[j];
// break;
// }
// }
auto it = lower_bound(v.begin(), v.end(), t_i[i] + 1);
t_i[i + 1] = (*it > s.length()) ? *it - s.length() : *it;
}
// for (int i = 0; i < t_i.size(); i++) {
// printf("%d ", t_i[i]);
// }
// printf("\n");
ll ans = 0;
for (int i = 1; i < t_i.size(); i++) {
if (i == t_i.size() - 1) {
// printf("last\n");
ans += t_i[i];
} else {
if (t_i[i] >= t_i[i + 1]) {
ans += s.length();
// printf("ans=%d\n", ans);
}
}
}
cout << ans << endl;
return 0;
}
| replace | 28 | 34 | 28 | 36 | TLE | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
string ds = s + s;
vector<vector<int>> abc(26);
for (int i = 0; i < ds.length(); i++) {
abc[ds[i] - 'a'].push_back(i);
}
for (int i = 0; i < 26; i++) {
sort(abc[i].begin(), abc[i].end());
}
// now:今のsでの添字
int now = -1;
long long int ans = 0;
for (int i = 0; i < t.length(); i++) {
vector<int> temp = abc[t[i] - 'a'];
auto itr = lower_bound(temp.begin(), temp.end(), now + 1);
if (itr != temp.end()) {
ans += *itr - now;
now = *itr % s.length();
} else {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
string ds = s + s;
vector<vector<int>> abc(26);
for (int i = 0; i < ds.length(); i++) {
abc[ds[i] - 'a'].push_back(i);
}
for (int i = 0; i < 26; i++) {
sort(abc[i].begin(), abc[i].end());
}
// now:今のsでの添字
int now = -1;
long long int ans = 0;
for (int i = 0; i < t.length(); i++) {
// vector<int> temp=abc[t[i]-'a'];
auto itr =
lower_bound(abc[t[i] - 'a'].begin(), abc[t[i] - 'a'].end(), now + 1);
if (itr != abc[t[i] - 'a'].end()) {
ans += *itr - now;
now = *itr % s.length();
} else {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
} | replace | 18 | 21 | 18 | 22 | TLE | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
int main() {
string s, t;
cin >> s >> t;
vector<set<int>> v(26);
int n = int(s.size());
rep(i, n) { v[s[i] - 'a'].insert(i + 1); }
ll ans = 0;
int id = 0;
int m = int(t.size());
rep(i, m) {
int c = t[i] - 'a';
if (v[c].empty()) {
cout << -1 << endl;
return 0;
}
auto itr = lower_bound(v[c].begin(), v[c].end(), id + 1);
if (itr == v[c].end()) {
itr = v[c].begin();
ans += ll(n - id + *itr);
} else {
ans += ll(*itr - id);
}
id = *itr;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
int main() {
string s, t;
cin >> s >> t;
vector<set<int>> v(26);
int n = int(s.size());
rep(i, n) { v[s[i] - 'a'].insert(i + 1); }
ll ans = 0;
int id = 0;
int m = int(t.size());
rep(i, m) {
int c = t[i] - 'a';
if (v[c].empty()) {
cout << -1 << endl;
return 0;
}
auto itr = v[c].lower_bound(id + 1);
if (itr == v[c].end()) {
itr = v[c].begin();
ans += ll(n - id + *itr);
} else {
ans += ll(*itr - id);
}
id = *itr;
}
cout << ans << endl;
return 0;
} | replace | 22 | 23 | 22 | 23 | TLE | |
p02937 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
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;
}
int main() {
string s, t;
cin >> s >> t;
vector<vector<ll>> v(26);
rep(i, s.size()) { v[s[i] - 'a'].push_back(i); }
ll ind = 0, numOf_s = 0;
for (auto c : t) {
auto ite = lower_bound(ALL(v[c - 'a']), ind);
if (ite == v[c - 'a'].end()) {
numOf_s++;
ind = v[c - 'a'][0] + 1;
} else {
ind = *ite + 1;
}
}
cout << numOf_s * s.size() + ind << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
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;
}
int main() {
string s, t;
cin >> s >> t;
vector<vector<ll>> v(26);
rep(i, s.size()) { v[s[i] - 'a'].push_back(i); }
ll ind = 0, numOf_s = 0;
for (auto c : t) {
if (v[c - 'a'].size() == 0) {
cout << -1 << endl;
return 0;
}
auto ite = lower_bound(ALL(v[c - 'a']), ind);
if (ite == v[c - 'a'].end()) {
numOf_s++;
ind = v[c - 'a'][0] + 1;
} else {
ind = *ite + 1;
}
}
cout << numOf_s * s.size() + ind << endl;
return 0;
}
| insert | 33 | 33 | 33 | 37 | 0 | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int last = -1, ans = 0;
vector<vector<int>> v(26);
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); ++i) {
v[s[i] - 'a'].push_back(i);
}
for (int i = 0; i < t.size(); ++i) {
if (v[t[i] - 'a'].size() == 0) {
cout << -1 << '\n';
return 0;
} else {
int isReturn = 1;
for (int j = 0; j < v[t[i] - 'a'].size(); ++j) {
int n = v[t[i] - 'a'][j];
if (n > last) {
ans += n - last;
last = n;
isReturn = 0;
break;
}
}
if (isReturn) {
ans += s.size() - last + v[t[i] - 'a'][0];
last = v[t[i] - 'a'][0];
}
}
}
cout << ans << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long int last = -1, ans = 0;
vector<vector<int>> v(26);
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); ++i) {
v[s[i] - 'a'].push_back(i);
}
for (int i = 0; i < t.size(); ++i) {
if (v[t[i] - 'a'].size() == 0) {
cout << -1 << '\n';
return 0;
} else {
int isReturn = 1;
int idx = distance(
v[t[i] - 'a'].begin(),
lower_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), last));
for (int j = idx; j < v[t[i] - 'a'].size(); ++j) {
int n = v[t[i] - 'a'][j];
if (n > last) {
ans += n - last;
last = n;
isReturn = 0;
break;
}
}
if (isReturn) {
ans += s.size() - last + v[t[i] - 'a'][0];
last = v[t[i] - 'a'][0];
}
}
}
cout << ans << '\n';
}
| replace | 17 | 18 | 17 | 21 | TLE | |
p02937 | Python | Time Limit Exceeded | def main():
s = input()
t = input()
if not set(t) <= set(s):
print(-1)
return
s_indexes = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
for i, s_c in enumerate(s):
s_indexes[s_c].append(i)
s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
s_length = {c: len(s_indexes[c]) for c in "abcdefghijklmnopqrstuvwxyz"}
power = 0
last_index = -1
for i, t_c in enumerate(t):
if s_length[t_c] <= s_pointer[t_c]:
# reset
s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
power += 1
elif s_indexes[t_c][s_pointer[t_c]] <= last_index:
for i, index in enumerate(s_indexes[t_c]):
if last_index < index:
s_pointer[t_c] = i
break
else:
# reset
s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
power += 1
last_index = s_indexes[t_c][s_pointer[t_c]]
s_pointer[t_c] += 1
print(len(s) * power + last_index + 1)
main()
| def main():
s = input()
t = input()
if not set(t) <= set(s):
print(-1)
return
s_indexes = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
for i, s_c in enumerate(s):
s_indexes[s_c].append(i)
s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
s_length = {c: len(s_indexes[c]) for c in "abcdefghijklmnopqrstuvwxyz"}
power = 0
last_index = -1
for i, t_c in enumerate(t):
if s_length[t_c] <= s_pointer[t_c]:
# reset
s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
power += 1
elif s_indexes[t_c][s_pointer[t_c]] <= last_index:
for j in range(s_pointer[t_c], s_length[t_c]):
if last_index < s_indexes[t_c][j]:
s_pointer[t_c] = j
break
else:
# reset
s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
power += 1
last_index = s_indexes[t_c][s_pointer[t_c]]
s_pointer[t_c] += 1
print(len(s) * power + last_index + 1)
main()
| replace | 22 | 25 | 22 | 25 | TLE | |
p02937 | C++ | Time Limit Exceeded | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using ll = long long;
using P = std::pair<ll, ll>;
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
// 問題文中の添え字が0-indexか1-indexか確認!
std::string s, t;
std::cin >> s >> t;
bool flag = true;
ll n = s.size(), m = t.size();
std::vector<std::vector<ll>> itr(26);
rep(i, 0, m) {
ll num = t[i] - 'a';
if (itr[num].empty()) {
rep(j, 0, n) if (s[j] == t[i]) itr[num].push_back(j);
if (itr[num].empty())
flag = false;
}
}
if (!flag) {
std::cout << -1;
return 0;
}
ll ans = itr[(ll)(t[0] - 'a')][0] + 1;
ll now = ans - 1;
rep(i, 1, m) {
ll next = t[i] - 'a';
auto len = std::upper_bound(all(itr[next]), now);
if (len != itr[next].end()) {
ans += (*len - now);
now = *len;
} else {
ans += (n - now + itr[next][0]);
now = itr[next][0];
}
// debug(now);
// debug(ans);
}
std::cout << ans;
return 0;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using ll = long long;
using P = std::pair<ll, ll>;
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
// 問題文中の添え字が0-indexか1-indexか確認!
std::string s, t;
std::cin >> s >> t;
bool flag = true;
ll n = s.size(), m = t.size();
std::vector<std::vector<ll>> itr(26);
rep(i, 0, 26) { rep(j, 0, n) if ((s[j] - 'a') == i) itr[i].push_back(j); }
rep(i, 0, m) if (itr[t[i] - 'a'].empty()) flag = false;
if (!flag) {
std::cout << -1;
return 0;
}
ll ans = itr[(ll)(t[0] - 'a')][0] + 1;
ll now = ans - 1;
rep(i, 1, m) {
ll next = t[i] - 'a';
auto len = std::upper_bound(all(itr[next]), now);
if (len != itr[next].end()) {
ans += (*len - now);
now = *len;
} else {
ans += (n - now + itr[next][0]);
now = itr[next][0];
}
// debug(now);
// debug(ans);
}
std::cout << ans;
return 0;
}
| replace | 41 | 49 | 41 | 44 | TLE | |
p02937 | C++ | Runtime Error | //
// Created by yamunaku on 2019/08/19.
//
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repl(i, l, r) for (int i = (l); i < (r); i++)
#define per(i, n) for (int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for (int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(), (x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP << " " <<
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define CFS \
cin.tie(0); \
ios::sync_with_stdio(false)
#define CST(x) cout << fixed << setprecision(x)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;
int main() {
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
mti nx(n, vi(26, -1));
vi a(26, -1);
per(i, n) { a[s[i] - 'a'] = n + i; }
per(i, n) {
rep(j, 26) { nx[i][j] = a[j] - i; }
a[s[i] - 'a'] = i;
}
ll now = n - 1;
rep(i, m) { now += nx[now % n][t[i] - 'a']; }
cout << now - (n - 1) << endl;
return 0;
}
| //
// Created by yamunaku on 2019/08/19.
//
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repl(i, l, r) for (int i = (l); i < (r); i++)
#define per(i, n) for (int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for (int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(), (x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP << " " <<
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define CFS \
cin.tie(0); \
ios::sync_with_stdio(false)
#define CST(x) cout << fixed << setprecision(x)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;
int main() {
string s, t;
cin >> s >> t;
int n = s.size();
int m = t.size();
mti nx(n, vi(26, -1));
vi a(26, -1);
per(i, n) { a[s[i] - 'a'] = n + i; }
per(i, n) {
rep(j, 26) { nx[i][j] = a[j] - i; }
a[s[i] - 'a'] = i;
}
ll now = n - 1;
rep(i, m) {
if (nx[now % n][t[i] - 'a'] < 0) {
cout << -1 << endl;
return 0;
}
now += nx[now % n][t[i] - 'a'];
}
cout << now - (n - 1) << endl;
return 0;
}
| replace | 45 | 46 | 45 | 52 | 0 | |
p02937 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define db long double
#define ii pair<int, int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repv(i, a, b) for (int i = b - 1; i >= a; i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
const int N = 100005;
int nxt[N][26];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
string s2 = s;
s2 += s2;
rep(j, 0, 26) nxt[sz(s2)][j] = -1;
repv(i, 0, sz(s2)) {
int curr = s2[i] - 'a';
rep(j, 0, 26) {
if (curr == j)
nxt[i][j] = i;
else
nxt[i][j] = nxt[i + 1][j];
}
}
repv(i, 0, sz(s)) rep(j, 0, 26) {
if (nxt[i][j] != -1)
nxt[i][j] %= sz(s);
}
ll ans = 0;
int curr = 0;
rep(i, 0, sz(t)) {
int id = t[i] - 'a';
int p = nxt[curr][id];
if (p == -1) {
cout << -1 << endl;
exit(0);
}
if (p < curr)
ans += sz(s) - curr + p + 1;
else
ans += p - curr + 1;
curr = p + 1;
curr %= sz(s);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define db long double
#define ii pair<int, int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repv(i, a, b) for (int i = b - 1; i >= a; i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
const int N = 200005;
int nxt[N][26];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
string s2 = s;
s2 += s2;
rep(j, 0, 26) nxt[sz(s2)][j] = -1;
repv(i, 0, sz(s2)) {
int curr = s2[i] - 'a';
rep(j, 0, 26) {
if (curr == j)
nxt[i][j] = i;
else
nxt[i][j] = nxt[i + 1][j];
}
}
repv(i, 0, sz(s)) rep(j, 0, 26) {
if (nxt[i][j] != -1)
nxt[i][j] %= sz(s);
}
ll ans = 0;
int curr = 0;
rep(i, 0, sz(t)) {
int id = t[i] - 'a';
int p = nxt[curr][id];
if (p == -1) {
cout << -1 << endl;
exit(0);
}
if (p < curr)
ans += sz(s) - curr + p + 1;
else
ans += p - curr + 1;
curr = p + 1;
curr %= sz(s);
}
cout << ans << endl;
return 0;
}
| replace | 41 | 42 | 41 | 42 | 0 | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#ifdef _PRINTDEBUG
#include "lib/printdebug.hpp"
#else
#define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL << 60)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i, n) for (long long i = 1; i < (long long)(n); i++)
#define rep2(i, n) for (long long i = 2; i < (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)
#define REP(i, n, m) for (long long i = (long long)(n); i < (long long)(m); i++)
namespace solver {
using namespace std;
typedef long long ll;
string S, T, ABC = "abcdefghijklmnopqrstuvwxyz";
ll table[100010][26];
void init() {
cin >> S;
cin >> T;
}
void solve() {
string S2 = S + S;
size_t s_size = S.size();
size_t t_size = T.size();
rep(i, s_size) {
rep(j, 26) {
auto itr = find(S2.begin() + i, S2.end(), ABC[j]);
if (itr == S2.end())
table[i][j] = -1;
else
table[i][j] = ((ll)(itr - S2.begin())) % s_size;
}
}
ll cur = 0, ans = 0;
rep(i, t_size) {
ll next_cur = table[cur][ABC.find(T[i])];
if (next_cur == -1) {
ans = -1;
break;
}
if (cur <= next_cur)
ans += next_cur + 1 - cur;
else
ans += s_size + (next_cur + 1 - cur);
cur = (next_cur + 1) % s_size;
}
cout << ans << endl;
}
} // namespace solver
int main() {
solver::init();
solver::solve();
return 0;
} | #include <bits/stdc++.h>
#ifdef _PRINTDEBUG
#include "lib/printdebug.hpp"
#else
#define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL << 60)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i, n) for (long long i = 1; i < (long long)(n); i++)
#define rep2(i, n) for (long long i = 2; i < (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)
#define REP(i, n, m) for (long long i = (long long)(n); i < (long long)(m); i++)
namespace solver {
using namespace std;
typedef long long ll;
string S, T, ABC = "abcdefghijklmnopqrstuvwxyz";
ll table[100010][26];
void init() {
cin >> S;
cin >> T;
}
void solve() {
string S2 = S + S;
size_t s_size = S.size();
size_t t_size = T.size();
vector<ll> vec[26];
rep(i, 2 * s_size) { vec[ABC.find(S2[i])].push_back(i); }
rep(i, 26) {
if (vec[i].size() == 0)
rep(j, s_size) table[j][i] = -1;
else {
ll cur = 0;
for (const auto &j : vec[i]) {
REP(k, cur, min(j + 1, (ll)s_size)) table[k][i] = j % s_size;
cur = j + 1;
}
}
}
ll cur = 0, ans = 0;
rep(i, t_size) {
ll next_cur = table[cur][ABC.find(T[i])];
if (next_cur == -1) {
ans = -1;
break;
}
if (cur <= next_cur)
ans += next_cur + 1 - cur;
else
ans += s_size + (next_cur + 1 - cur);
cur = (next_cur + 1) % s_size;
}
cout << ans << endl;
}
} // namespace solver
int main() {
solver::init();
solver::solve();
return 0;
} | replace | 36 | 43 | 36 | 47 | TLE | |
p02937 | C++ | Runtime Error | /*author : Yashvardhan
Sunday, August 18, 2019
6:46 PM
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))
#define printArr(name, from, to) \
for (int x = from; x < to; x++) \
cout << name[x] << " ";
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < v.size(); ++i)
os << v[i] << " ";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (auto it : v)
os << it << " ";
return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
os << v.ff << " " << v.ss;
return os;
}
const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;
const int N = 1e5 + 5;
int arr[26][N];
int focc[N];
int takemod(int a) { return ((a % mod) + mod) % mod; }
int pow(int a, int b, int m) {
int ans = 1;
while (b) {
if (b & 1)
ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
int modinv(int a) { return takemod(pow(takemod(a), mod - 2, mod)); }
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
time_t t1, t2;
t1 = clock();
string s, t;
cin >> s >> t;
int n = s.size();
bool possi = true;
initialise(focc, -1);
initialise(arr, 0);
vi occ[26];
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++)
arr[j][i] = arr[j][i - 1];
int curr = s[i - 1] - 'a';
arr[curr][i]++;
if (focc[curr] == -1)
focc[curr] = i;
occ[curr].pb(i);
}
for (auto i : t) {
int curr = i - 'a';
if (arr[curr][n] == 0) {
possi = false;
break;
}
}
if (!possi) {
cout << -1 << endl;
return 0;
}
int cpos = 0;
int ans = 0;
for (int i = 0; i < t.size(); i++) {
int curr = t[i] - 'a';
if (cpos == 0) {
ans++;
cpos = focc[curr];
} else {
if (arr[curr][n] - arr[curr][cpos - 1] == 0) {
cpos = focc[curr];
ans++;
} else {
int ind = lower_bound(all(occ[curr]), cpos + 1) - occ[curr].begin();
cpos = occ[curr][ind];
}
}
}
ans = ans * n;
ans -= (n - cpos);
cout << ans << endl;
t2 = clock();
cerr << endl << t2 - t1 << endl;
return 0;
}
| /*author : Yashvardhan
Sunday, August 18, 2019
6:46 PM
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))
#define printArr(name, from, to) \
for (int x = from; x < to; x++) \
cout << name[x] << " ";
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < v.size(); ++i)
os << v[i] << " ";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (auto it : v)
os << it << " ";
return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
os << v.ff << " " << v.ss;
return os;
}
const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;
const int N = 1e5 + 5;
int arr[26][N];
int focc[N];
int takemod(int a) { return ((a % mod) + mod) % mod; }
int pow(int a, int b, int m) {
int ans = 1;
while (b) {
if (b & 1)
ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
int modinv(int a) { return takemod(pow(takemod(a), mod - 2, mod)); }
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
time_t t1, t2;
t1 = clock();
string s, t;
cin >> s >> t;
int n = s.size();
bool possi = true;
initialise(focc, -1);
initialise(arr, 0);
vi occ[26];
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++)
arr[j][i] = arr[j][i - 1];
int curr = s[i - 1] - 'a';
arr[curr][i]++;
if (focc[curr] == -1)
focc[curr] = i;
occ[curr].pb(i);
}
for (auto i : t) {
int curr = i - 'a';
if (arr[curr][n] == 0) {
possi = false;
break;
}
}
if (!possi) {
cout << -1 << endl;
return 0;
}
int cpos = 0;
int ans = 0;
for (int i = 0; i < t.size(); i++) {
int curr = t[i] - 'a';
if (cpos == 0) {
ans++;
cpos = focc[curr];
} else {
if (arr[curr][n] - arr[curr][cpos] == 0) {
cpos = focc[curr];
ans++;
} else {
int ind = lower_bound(all(occ[curr]), cpos + 1) - occ[curr].begin();
cpos = occ[curr][ind];
}
}
}
ans = ans * n;
ans -= (n - cpos);
cout << ans << endl;
t2 = clock();
cerr << endl << t2 - t1 << endl;
return 0;
}
| replace | 143 | 144 | 143 | 144 | 0 |
18892
|
p02937 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int>> mati;
typedef vector<vector<double>> matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;
#define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i)
#define REP(i, y) FOR(i, 0, y)
#define RFOR(i, x, y) for (ll i = (ll)x; i >= (ll)y; --i)
#define RREP(i, x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
cin >> first;
IN(rest...);
return;
}
inline void OUT(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest) {
cout << first << " ";
OUT(rest...);
return;
}
template <typename T> void vec_print(vector<T> VEC) {
REP(i, VEC.size()) { cout << VEC[i] << " "; }
cout << "\n";
};
template <typename T>
void mat_print(vector<vector<T>> MAT){
REP(i, MAT.size()){REP(j, MAT[i].size()){cout << MAT[i][j] << " ";
}
cout << "\n";
}
}
;
template <typename CLASS1, typename CLASS2> class HOGE {
public:
CLASS1 key;
CLASS2 value;
HOGE(void) { return; };
HOGE(CLASS1 key, CLASS2 value) {
this->key = key;
this->value = value;
};
~HOGE(void) { return; };
void print(void) {
cout << "key : " << key << ", value : " << value << "\n";
return;
};
bool operator==(const HOGE &obj) { return (this->value == obj.value); };
bool operator<(const HOGE &obj) { return (this->value < obj.value); };
bool operator>(const HOGE &obj) { return (this->value > obj.value); };
};
template <typename CLASS1, typename CLASS2>
bool operator==(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value == hoge2.value;
};
template <typename CLASS1, typename CLASS2>
bool operator<(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value < hoge2.value;
};
template <typename CLASS1, typename CLASS2>
bool operator>(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value > hoge2.value;
};
constexpr int INF = (1 << 30);
constexpr ll INFLL = 1LL << 62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9) + 7);
int main() {
cin.tie(0); // cut the cin and cout (default, std::flush is performed after
// std::cin)
ios::sync_with_stdio(
false); // cut the iostream and stdio (DON'T endl; BUT "\n";)
string s, t;
IN(s, t);
map<ll, ll> mps, mpt;
REP(i, s.size()) mps[s[i] - 'a']++;
REP(i, t.size()) mpt[t[i] - 'a']++;
bool flag = true;
for (ll i = 0; i <= 'z' - 'a'; ++i) {
if (mps[i] == 0 && mpt[i] > 0)
flag = false;
}
if (!flag) {
OUT(-1);
return 0;
}
string s2 = s + s;
vvll next_pos('z' - 'a' + 1, vll(s.size(), -1));
REP(i, s2.size()) {
ll pos = s2.size() - i - 1;
REP(j, 'z' - 'a' + 1) {
next_pos[j][pos % s.size()] = next_pos[j][(pos + 1) % s.size()];
}
next_pos[s2[pos] - 'a'][pos % s.size()] = pos % s.size();
}
// mat_print(next_pos);
ll ans = 1;
ll pos = 0;
REP(i, t.size()) {
ll next = next_pos[t[i] - 'a'][pos];
if (next >= pos)
ans += next - pos;
else
ans += next + (s.size() - pos);
pos = next;
if (i < t.size() - 1) {
pos++;
ans++;
}
}
OUT(ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int>> mati;
typedef vector<vector<double>> matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;
#define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i)
#define REP(i, y) FOR(i, 0, y)
#define RFOR(i, x, y) for (ll i = (ll)x; i >= (ll)y; --i)
#define RREP(i, x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
inline void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
cin >> first;
IN(rest...);
return;
}
inline void OUT(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest) {
cout << first << " ";
OUT(rest...);
return;
}
template <typename T> void vec_print(vector<T> VEC) {
REP(i, VEC.size()) { cout << VEC[i] << " "; }
cout << "\n";
};
template <typename T>
void mat_print(vector<vector<T>> MAT){
REP(i, MAT.size()){REP(j, MAT[i].size()){cout << MAT[i][j] << " ";
}
cout << "\n";
}
}
;
template <typename CLASS1, typename CLASS2> class HOGE {
public:
CLASS1 key;
CLASS2 value;
HOGE(void) { return; };
HOGE(CLASS1 key, CLASS2 value) {
this->key = key;
this->value = value;
};
~HOGE(void) { return; };
void print(void) {
cout << "key : " << key << ", value : " << value << "\n";
return;
};
bool operator==(const HOGE &obj) { return (this->value == obj.value); };
bool operator<(const HOGE &obj) { return (this->value < obj.value); };
bool operator>(const HOGE &obj) { return (this->value > obj.value); };
};
template <typename CLASS1, typename CLASS2>
bool operator==(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value == hoge2.value;
};
template <typename CLASS1, typename CLASS2>
bool operator<(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value < hoge2.value;
};
template <typename CLASS1, typename CLASS2>
bool operator>(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value > hoge2.value;
};
constexpr int INF = (1 << 30);
constexpr ll INFLL = 1LL << 62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9) + 7);
int main() {
cin.tie(0); // cut the cin and cout (default, std::flush is performed after
// std::cin)
ios::sync_with_stdio(
false); // cut the iostream and stdio (DON'T endl; BUT "\n";)
string s, t;
IN(s, t);
map<ll, ll> mps, mpt;
REP(i, s.size()) mps[s[i] - 'a']++;
REP(i, t.size()) mpt[t[i] - 'a']++;
bool flag = true;
for (ll i = 0; i <= 'z' - 'a'; ++i) {
if (mps[i] == 0 && mpt[i] > 0)
flag = false;
}
if (!flag) {
OUT(-1);
return 0;
}
string s2 = s + s;
vvll next_pos('z' - 'a' + 1, vll(s.size(), -1));
REP(i, s2.size()) {
ll pos = s2.size() - i - 1;
REP(j, 'z' - 'a' + 1) {
next_pos[j][pos % s.size()] = next_pos[j][(pos + 1) % s.size()];
}
next_pos[s2[pos] - 'a'][pos % s.size()] = pos % s.size();
}
// mat_print(next_pos);
ll ans = 1;
ll pos = 0;
REP(i, t.size()) {
ll next = next_pos[t[i] - 'a'][pos];
if (next >= pos)
ans += next - pos;
else
ans += next + (s.size() - pos);
pos = next;
if (i < t.size() - 1) {
pos++;
ans++;
pos %= s.size();
}
}
OUT(ans);
return 0;
} | insert | 155 | 155 | 155 | 156 | 0 | |
p02937 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
// contest
// sentence
// s e nte n ce
// 7*4 + 5
//
// c ontest
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> pos(26, vector<int>());
for (int i = 0; i < s.size(); i++) {
pos[s[i] - 'a'].push_back(i + 1);
}
int fpos = -1;
ll ans = 0;
for (int i = 0; i < t.size(); i++) {
auto a = upper_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), fpos);
if (fpos == -1 && a == pos[t[i] - 'a'].end()) {
cout << -1 << endl;
return 0;
} else {
if (a == pos[t[i] - 'a'].end()) {
fpos = -1;
ans += s.size();
a = upper_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), fpos);
fpos = *a;
} else {
fpos = *a;
}
if (i == t.size() - 1) {
ans += fpos;
}
}
}
cout << ans << endl;
} | #pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
// contest
// sentence
// s e nte n ce
// 7*4 + 5
//
// c ontest
int main() {
string s, t;
cin >> s >> t;
vector<vector<int>> pos(26, vector<int>());
for (int i = 0; i < s.size(); i++) {
pos[s[i] - 'a'].push_back(i + 1);
}
int fpos = -1;
ll ans = 0;
for (int i = 0; i < t.size(); i++) {
auto a = upper_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), fpos);
if (fpos == -1 && a == pos[t[i] - 'a'].end()) {
cout << -1 << endl;
return 0;
} else {
if (a == pos[t[i] - 'a'].end()) {
fpos = -1;
ans += s.size();
a = upper_bound(pos[t[i] - 'a'].begin(), pos[t[i] - 'a'].end(), fpos);
if (a == pos[t[i] - 'a'].end()) {
cout << -1 << endl;
return 0;
}
fpos = *a;
} else {
fpos = *a;
}
if (i == t.size() - 1) {
ans += fpos;
}
}
}
cout << ans << endl;
} | insert | 35 | 35 | 35 | 39 | 0 | |
p02937 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef long long ll;
int main() {
string s, t;
cin >> s >> t;
ll ans = -1;
vector<vector<int>> a(26);
rep(i, s.size()) { a[s[i] - 'a'].pb(i); }
/* vector<vector<int>> b(t.size());
rep(i, t.size()){
for (auto x : a[t[i] - 'a']){
b[i].pb(x);
}
if (b[i].empty()){
cout << ans << endl;
return 0;
}
}*/
ll now = a[t[0] - 'a'][0];
int res = 0;
rep(i, t.size() - 1) {
auto it =
upper_bound(a[t[i + 1] - 'a'].begin(), a[t[i + 1] - 'a'].end(), now);
if (it - a[t[i + 1] - 'a'].begin() == a[t[i + 1] - 'a'].size()) {
now = a[t[i + 1] - 'a'][0];
res++;
} else {
now = *it;
}
}
ans = (ll)res * s.size() + now + 1;
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef long long ll;
int main() {
string s, t;
cin >> s >> t;
ll ans = -1;
vector<vector<int>> a(26);
rep(i, s.size()) { a[s[i] - 'a'].pb(i); }
rep(i, t.size()) {
if (a[t[i] - 'a'].empty()) {
cout << ans << endl;
return 0;
}
}
ll now = a[t[0] - 'a'][0];
int res = 0;
rep(i, t.size() - 1) {
auto it =
upper_bound(a[t[i + 1] - 'a'].begin(), a[t[i + 1] - 'a'].end(), now);
if (it - a[t[i + 1] - 'a'].begin() == a[t[i + 1] - 'a'].size()) {
now = a[t[i + 1] - 'a'][0];
res++;
} else {
now = *it;
}
}
ans = (ll)res * s.size() + now + 1;
cout << ans << endl;
} | replace | 13 | 23 | 13 | 20 | 0 | |
p02937 | C++ | Runtime Error | /*
[abc138] E - Strings of Impurity
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()
const int MAX_S = 1e5;
const int INF = 1e9;
string s, t;
int d['z' - 'a' + 1][MAX_S];
ll solve() {
int sl = s.length();
string ss = s + s;
for (char c = 'a'; c <= 'z'; c++) {
for (int i = 0; i < sl;) {
size_t idx = ss.find(c, i);
if (idx == string::npos) {
fill(d[c - 'a'], d[c - 'a'] + sl, INF);
break;
}
for (; i <= (int)idx; i++) {
d[c - 'a'][i] = idx - i;
}
}
}
ll ans = 0;
for (char c : t) {
int dd = d[c - 'a'][ans % sl];
if (dd >= INF) {
return -1;
}
ans += dd + 1;
}
return ans;
}
int main() {
cin >> s;
cin >> t;
cout << solve() << endl;
return 0;
}
| /*
[abc138] E - Strings of Impurity
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()
const int MAX_S = 1e5;
const int INF = 1e9;
string s, t;
int d['z' - 'a' + 1][MAX_S];
ll solve() {
int sl = s.length();
string ss = s + s;
for (char c = 'a'; c <= 'z'; c++) {
for (int i = 0; i < sl;) {
size_t idx = ss.find(c, i);
if (idx == string::npos) {
fill(d[c - 'a'], d[c - 'a'] + sl, INF);
break;
}
for (; i < sl && i <= (int)idx; i++) {
d[c - 'a'][i] = idx - i;
}
}
}
ll ans = 0;
for (char c : t) {
int dd = d[c - 'a'][ans % sl];
if (dd >= INF) {
return -1;
}
ans += dd + 1;
}
return ans;
}
int main() {
cin >> s;
cin >> t;
cout << solve() << endl;
return 0;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s, t;
cin >> s >> t;
unordered_map<char, vector<int>> s_mp;
REP(i, s.size()) s_mp[s[i]].push_back(i + 1);
ll cnt = 0;
int pos = 0;
REP(i, t.size()) {
if (s_mp[t[i]].size() == 0) {
cout << -1 << '\n';
return 0;
}
bool flag = true;
for (auto p : s_mp[t[i]]) {
if (pos < p) {
pos = p;
flag = false;
break;
}
}
if (flag) {
cnt += (ll)s.size();
pos = s_mp[t[i]][0];
}
// cout << cnt << " " << pos << '\n';
}
cout << cnt + (ll)pos << '\n';
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s, t;
cin >> s >> t;
unordered_map<char, vector<int>> s_mp;
REP(i, s.size()) s_mp[s[i]].push_back(i + 1);
ll cnt = 0;
int pos = 0;
REP(i, t.size()) {
if (s_mp[t[i]].size() == 0) {
cout << -1 << '\n';
return 0;
}
bool flag = true;
auto itr = upper_bound(ALL(s_mp[t[i]]), pos);
if (itr != s_mp[t[i]].end()) {
pos = *itr;
} else {
cnt += (ll)s.size();
pos = s_mp[t[i]][0];
}
// cout << cnt << " " << pos << '\n';
}
cout << cnt + (ll)pos << '\n';
return 0;
}
| replace | 24 | 32 | 24 | 28 | TLE | |
p02937 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long;
using ld = long double;
const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*-
* -*- -*- -*- -*- */
#include <bits/extc++.h>
namespace pbds = __gnu_pbds;
template <typename key, typename val = pbds::null_type,
typename comp = less<key>>
using ostree = pbds::tree<key, val, comp, pbds::rb_tree_tag,
pbds::tree_order_statistics_node_update>;
using vi = vector<int>;
using vll = vector<ll>;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename... Args, template <typename...> typename T>
string to_string(T<Args...> const &);
string to_string(string const &s) { return '"' + s + '"'; }
string to_string(char const &c) { return to_string(string(1, c)); }
string to_string(char const *c) { return to_string(string(c)); }
string to_string(bool const &b) { return (b ? "T" : "F"); }
template <typename... Args> string to_string(pair<Args...> const &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename... Args, template <typename...> typename T>
string to_string(T<Args...> const &S) {
string s = "{";
for (auto const &e : S)
s += " " + to_string(e);
s += " }";
return s;
}
template <typename Tail> void debug_out(Tail t) {
cerr << " " << to_string(t) << " ]" << endl;
}
template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) {
cerr << " " << to_string(h) << ",";
debug_out(t...);
}
#define pr(...) cerr << "[" << (#__VA_ARGS__) << "] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub) {
cerr << '{';
for (auto it = lb; it != ub; it++)
cerr << ' ' << to_string(*it);
cerr << " }" << endl;
}
template <typename T, typename Comp = less<T>>
bool smin(T &mem, T const &v, Comp const &cmp = Comp()) {
return cmp(v, mem) ? mem = v, true : false;
}
template <typename T, typename Comp = less<T>>
bool smax(T &mem, T const &v, Comp const &cmp = Comp()) {
return cmp(mem, v) ? mem = v, true : false;
}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*-
* -*- -*- -*- -*- */
string s, t;
int a[26][100100], n, m;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s >> t;
{
set<char> S;
for (char c : s)
S.emplace(c);
for (char c : t)
if (S.find(c) == S.end()) {
cout << -1 << endl;
return 0;
}
}
n = s.length(), m = t.length();
for (int z = 0; z < 2; z++) {
for (int i = n - 1; i >= 0; i--) {
for (char c = 'a'; c <= 'z'; c++) {
a[c - 'a'][i] = a[c - 'a'][(i + 1) % n];
}
a[s[i] - 'a'][i] = i;
}
}
int pos = 0, cur = 0;
for (;;) {
for (; cur < m and t[cur] == s[pos % n]; cur++, pos++)
;
if (cur == m)
break;
char c = t[cur];
int npos = a[c - 'a'][pos % n];
if (npos > (pos % n))
pos += npos - (pos % n);
else
pos += (n - (pos % n) + npos);
}
cout << pos << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long;
using ld = long double;
const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*-
* -*- -*- -*- -*- */
#include <bits/extc++.h>
namespace pbds = __gnu_pbds;
template <typename key, typename val = pbds::null_type,
typename comp = less<key>>
using ostree = pbds::tree<key, val, comp, pbds::rb_tree_tag,
pbds::tree_order_statistics_node_update>;
using vi = vector<int>;
using vll = vector<ll>;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename... Args, template <typename...> typename T>
string to_string(T<Args...> const &);
string to_string(string const &s) { return '"' + s + '"'; }
string to_string(char const &c) { return to_string(string(1, c)); }
string to_string(char const *c) { return to_string(string(c)); }
string to_string(bool const &b) { return (b ? "T" : "F"); }
template <typename... Args> string to_string(pair<Args...> const &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename... Args, template <typename...> typename T>
string to_string(T<Args...> const &S) {
string s = "{";
for (auto const &e : S)
s += " " + to_string(e);
s += " }";
return s;
}
template <typename Tail> void debug_out(Tail t) {
cerr << " " << to_string(t) << " ]" << endl;
}
template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) {
cerr << " " << to_string(h) << ",";
debug_out(t...);
}
#define pr(...) cerr << "[" << (#__VA_ARGS__) << "] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub) {
cerr << '{';
for (auto it = lb; it != ub; it++)
cerr << ' ' << to_string(*it);
cerr << " }" << endl;
}
template <typename T, typename Comp = less<T>>
bool smin(T &mem, T const &v, Comp const &cmp = Comp()) {
return cmp(v, mem) ? mem = v, true : false;
}
template <typename T, typename Comp = less<T>>
bool smax(T &mem, T const &v, Comp const &cmp = Comp()) {
return cmp(mem, v) ? mem = v, true : false;
}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*-
* -*- -*- -*- -*- */
string s, t;
int a[26][100100], n, m;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s >> t;
{
set<char> S;
for (char c : s)
S.emplace(c);
for (char c : t)
if (S.find(c) == S.end()) {
cout << -1 << endl;
return 0;
}
}
n = s.length(), m = t.length();
for (int z = 0; z < 2; z++) {
for (int i = n - 1; i >= 0; i--) {
for (char c = 'a'; c <= 'z'; c++) {
a[c - 'a'][i] = a[c - 'a'][(i + 1) % n];
}
a[s[i] - 'a'][i] = i;
}
}
ll pos = 0, cur = 0;
for (;;) {
for (; cur < m and t[cur] == s[pos % n]; cur++, pos++)
;
if (cur == m)
break;
char c = t[cur];
int npos = a[c - 'a'][pos % n];
if (npos > (pos % n))
pos += npos - (pos % n);
else
pos += (n - (pos % n) + npos);
}
cout << pos << endl;
}
| replace | 92 | 93 | 92 | 93 | 0 | |
p02937 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
string s, t;
cin >> s >> t;
map<char, vector<ll>> mps;
for (ll i = 0; i < s.size(); i++)
mps[s[i]].push_back(i + 1), mps[s[i]].push_back(i + 1 + s.size());
for (char s = 'a'; s <= 'z'; s++) {
auto &v = mps[s];
sort(v.begin(), v.end());
}
ll cnt = 0;
ll freq = 0;
for (ll i = 0; i < t.size(); i++) {
if (mps[t[i]].empty()) {
printf("%d\n", -1);
return 0;
} else {
auto q = mps[t[i]];
ll tmp = *upper_bound(q.begin(), q.end(), cnt);
if (tmp < s.size())
cnt = tmp;
else
freq++, cnt = tmp - s.size();
}
}
printf("%lld\n", freq * s.size() + cnt);
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
string s, t;
cin >> s >> t;
map<char, vector<ll>> mps;
for (ll i = 0; i < s.size(); i++)
mps[s[i]].push_back(i + 1), mps[s[i]].push_back(i + 1 + s.size());
for (char s = 'a'; s <= 'z'; s++) {
auto &v = mps[s];
sort(v.begin(), v.end());
}
ll cnt = 0;
ll freq = 0;
for (ll i = 0; i < t.size(); i++) {
if (mps[t[i]].empty()) {
printf("%d\n", -1);
return 0;
} else {
ll tmp = *upper_bound(mps[t[i]].begin(), mps[t[i]].end(), cnt);
if (tmp < s.size())
cnt = tmp;
else
freq++, cnt = tmp - s.size();
}
}
printf("%lld\n", freq * s.size() + cnt);
} | replace | 30 | 32 | 30 | 31 | TLE | |
p02937 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
map<char, vector<int>> m3;
string s, t;
int binarySearch(int i, int l, int r, int x) {
while (l <= r) {
int m = l + (r - l) / 2;
// Check if x is present at mid
if (m == m3[t[i]].size() - 1)
return m;
if ((m3[t[i]][m] <= x) && (m3[t[i]][m + 1] > x))
return m + 1;
// If x greater, ignore left half
if (m3[t[i]][m] < x)
l = m + 1;
// If x is smaller, ignore right half
else
r = m - 1;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s >> t;
int n = s.length();
int m = t.length();
map<char, int> m1, m2;
for (int i = 0; i < n; i++) {
m1[s[i]] = 1;
}
for (int i = 0; i < m; i++) {
m2[t[i]] = 1;
}
map<char, int>::iterator it = m2.begin();
for (it; it != m2.end(); it++) {
if (m1[it->first] != 1) {
cout << -1 << endl;
return 0;
}
}
for (int i = 0; i < n; i++) {
m3[s[i]].push_back(i);
}
map<char, vector<int>>::iterator it1 = m3.begin();
for (it1; it1 != m3.end(); it1++) {
sort((it1->second).begin(), (it1->second).end());
}
ll res = 0;
int cnt = 0;
int last = 0;
for (int i = 0; i < m; i++) {
if (i == 0) {
res += (1 + m3[t[0]][0]);
last = m3[t[0]][0];
continue;
}
int taille = m3[t[i]].size();
int el = 0;
if (last >= m3[t[i]][taille - 1])
el = m3[t[i]][0];
else {
el = m3[t[i]][binarySearch(i, 0, taille - 1, last)];
}
if (el > last) {
res += (el - last);
} else {
res += (el + 1);
res += (n - last - 1);
}
last = el;
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
map<char, vector<int>> m3;
string s, t;
int binarySearch(int i, int l, int r, int x) {
while (l <= r) {
int m = l + (r - l) / 2;
// Check if x is present at mid
if (m == m3[t[i]].size() - 1)
return m;
if ((m3[t[i]][m] <= x) && (m3[t[i]][m + 1] > x))
return m + 1;
// If x greater, ignore left half
if (m3[t[i]][m] < x)
l = m + 1;
// If x is smaller, ignore right half
else
r = m - 1;
}
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s >> t;
int n = s.length();
int m = t.length();
map<char, int> m1, m2;
for (int i = 0; i < n; i++) {
m1[s[i]] = 1;
}
for (int i = 0; i < m; i++) {
m2[t[i]] = 1;
}
map<char, int>::iterator it = m2.begin();
for (it; it != m2.end(); it++) {
if (m1[it->first] != 1) {
cout << -1 << endl;
return 0;
}
}
for (int i = 0; i < n; i++) {
m3[s[i]].push_back(i);
}
map<char, vector<int>>::iterator it1 = m3.begin();
for (it1; it1 != m3.end(); it1++) {
sort((it1->second).begin(), (it1->second).end());
}
ll res = 0;
int cnt = 0;
int last = 0;
for (int i = 0; i < m; i++) {
if (i == 0) {
res += (1 + m3[t[0]][0]);
last = m3[t[0]][0];
continue;
}
int taille = m3[t[i]].size();
int el = 0;
if (last >= m3[t[i]][taille - 1])
el = m3[t[i]][0];
else {
el = m3[t[i]][binarySearch(i, 0, taille - 1, last)];
}
if (el > last) {
res += (el - last);
} else {
res += (el + 1);
res += (n - last - 1);
}
last = el;
}
cout << res << endl;
return 0;
} | insert | 37 | 37 | 37 | 38 | 0 | |
p02937 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -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;
}
string s, t;
vector<int> v[25];
signed main() {
cin >> s >> t;
for (int i = 0; i < s.size(); ++i)
v[s[i] - 'a'].push_back(i);
int front = -1;
int k = 0;
int cnt = 0;
while (k < t.size()) {
int c = t[k] - 'a';
if (v[c].size() == 0) {
cout << -1 << endl;
return 0;
}
int idx = lower_bound(v[c].begin(), v[c].end(), front + 1) - v[c].begin();
if (idx == v[c].size()) {
cnt++;
front = -1;
} else {
k++;
front = v[c][idx];
}
}
cout << cnt * s.size() + front + 1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -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;
}
string s, t;
vector<int> v[30];
signed main() {
cin >> s >> t;
for (int i = 0; i < s.size(); ++i)
v[s[i] - 'a'].push_back(i);
int front = -1;
int k = 0;
int cnt = 0;
while (k < t.size()) {
int c = t[k] - 'a';
if (v[c].size() == 0) {
cout << -1 << endl;
return 0;
}
int idx = lower_bound(v[c].begin(), v[c].end(), front + 1) - v[c].begin();
if (idx == v[c].size()) {
cnt++;
front = -1;
} else {
k++;
front = v[c][idx];
}
}
cout << cnt * s.size() + front + 1 << endl;
} | replace | 35 | 36 | 35 | 36 | 0 | |
p02937 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <float.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
#define int long long
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()
template <typename T> void DEBUG(T e) {
if (DEBUG_OUT == false)
return;
std::cout << e << " ";
}
template <typename T> void DEBUG(const std::vector<T> &v) {
if (DEBUG_OUT == false)
return;
for (const auto &e : v) {
std::cout << e << " ";
}
std::cout << std::endl;
}
template <typename T> void DEBUG(const std::vector<std::vector<T>> &vv) {
if (DEBUG_OUT == false)
return;
for (const auto &v : vv) {
DEBUG(v);
}
}
template <class T, class... Ts> void DEBUG(T d, Ts... e) {
if (DEBUG_OUT == false)
return;
DEBUG(d);
DEBUG(e...);
}
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
abort();
}
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
// SOLVE
void solve(void) {
string str, ref;
cin >> str >> ref;
map<char, int> pos;
int N = str.size();
vector<int> next(26, -1);
vector<vector<int>> mat(26, vector<int>(N, -1));
for (int i = N - 1; i >= 0; i--) {
char c = str[i];
for (int j = 0; j < 26; j++) {
mat[j][i] = next[j];
}
next[(int)(c - 'a')] = i;
}
for (int i = N - 1; i >= 0; i--) {
char c = str[i];
for (int j = 0; j < 26; j++) {
if (mat[j][i] == -1)
mat[j][i] = next[j];
}
next[(int)(c - 'a')] = i;
// DEBUG(next);
}
// DEBUG(next);
// DEBUG(mat);
int index = 0;
int lcnt = 0;
int flg = 0;
for (int i = 0; i < ref.size(); i++) {
int ni = mat[(int)(ref[i] - 'a')][index];
if (i == 0) {
ni = next[(int)(ref[i] - 'a')];
index = ni;
continue;
}
if (ni == -1) {
cout << -1 << endl;
return;
}
if (ni <= index && i != 0)
lcnt++;
index = ni;
// DEBUG(index,ni,"\n");
}
cout << lcnt * N + index + 1 - flg << endl;
return;
}
int32_t main(int32_t argc, const char *argv[]) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();
return 0;
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <float.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
#define int long long
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()
template <typename T> void DEBUG(T e) {
if (DEBUG_OUT == false)
return;
std::cout << e << " ";
}
template <typename T> void DEBUG(const std::vector<T> &v) {
if (DEBUG_OUT == false)
return;
for (const auto &e : v) {
std::cout << e << " ";
}
std::cout << std::endl;
}
template <typename T> void DEBUG(const std::vector<std::vector<T>> &vv) {
if (DEBUG_OUT == false)
return;
for (const auto &v : vv) {
DEBUG(v);
}
}
template <class T, class... Ts> void DEBUG(T d, Ts... e) {
if (DEBUG_OUT == false)
return;
DEBUG(d);
DEBUG(e...);
}
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
abort();
}
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
// SOLVE
void solve(void) {
string str, ref;
cin >> str >> ref;
map<char, int> pos;
int N = str.size();
vector<int> next(26, -1);
vector<vector<int>> mat(26, vector<int>(N, -1));
for (int i = N - 1; i >= 0; i--) {
char c = str[i];
for (int j = 0; j < 26; j++) {
mat[j][i] = next[j];
}
next[(int)(c - 'a')] = i;
}
for (int i = N - 1; i >= 0; i--) {
char c = str[i];
for (int j = 0; j < 26; j++) {
if (mat[j][i] == -1)
mat[j][i] = next[j];
}
next[(int)(c - 'a')] = i;
// DEBUG(next);
}
// DEBUG(next);
// DEBUG(mat);
int index = 0;
int lcnt = 0;
int flg = 0;
for (int i = 0; i < ref.size(); i++) {
int ni = mat[(int)(ref[i] - 'a')][index];
if (i == 0) {
ni = next[(int)(ref[i] - 'a')];
if (ni == -1) {
cout << -1 << endl;
return;
}
index = ni;
continue;
}
if (ni == -1) {
cout << -1 << endl;
return;
}
if (ni <= index && i != 0)
lcnt++;
index = ni;
// DEBUG(index,ni,"\n");
}
cout << lcnt * N + index + 1 - flg << endl;
return;
}
int32_t main(int32_t argc, const char *argv[]) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();
return 0;
}
| insert | 111 | 111 | 111 | 115 | 0 | |
p02937 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define MN 400005
char ch[MN], ch2[MN];
int nex[MN][26];
long long ans;
int main() {
scanf("%s%s", ch + 1, ch2);
long long l1 = strlen(ch + 1), l2 = strlen(ch2);
for (int i = 0; i < 26; ++i)
nex[(l1 << 1)][i] = -1;
for (int i = (l1 << 1); i; --i) {
for (int j = 0; j < 26; ++j) {
nex[i - 1][j] = nex[i][j];
}
nex[i - 1][ch[i % l1 == 0 ? i : (i % l1)] - 'a'] = i;
}
int now = 0;
for (int i = 0; i < l2; ++i) {
if (nex[now][ch2[i] - 'a'] == -1) {
puts("-1");
return 0;
}
now = nex[now][ch2[i] - 'a'];
// cout<<"HI "<<i<<" "<<now<<endl;
if (now >= l1)
ans += l1, now -= l1;
}
printf("%lld", ans + (long long)now);
} | #include <bits/stdc++.h>
using namespace std;
#define MN 400005
char ch[MN], ch2[MN];
int nex[MN][26];
long long ans;
int main() {
scanf("%s%s", ch + 1, ch2);
long long l1 = strlen(ch + 1), l2 = strlen(ch2);
for (int i = 0; i < 26; ++i)
nex[(l1 << 1)][i] = -1;
for (int i = (l1 << 1); i; --i) {
for (int j = 0; j < 26; ++j) {
nex[i - 1][j] = nex[i][j];
}
int real = i;
if (i > l1)
real -= l1;
nex[i - 1][ch[real] - 'a'] = i;
}
int now = 0;
for (int i = 0; i < l2; ++i) {
if (nex[now][ch2[i] - 'a'] == -1) {
puts("-1");
return 0;
}
now = nex[now][ch2[i] - 'a'];
// cout<<"HI "<<i<<" "<<now<<endl;
if (now >= l1)
ans += l1, now -= l1;
}
printf("%lld", ans + (long long)now);
} | replace | 15 | 16 | 15 | 19 | 0 | |
p02937 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using ll = long long;
using namespace std;
int main() {
string s, t;
cin >> s >> t;
string sample = s + s;
ll pos[s.size()][26];
for (int yi = 0; yi < s.size(); ++yi) {
for (int xi = 0; xi < 26; ++xi) {
pos[yi][xi] = -1;
}
}
vector<queue<ll>> a(26);
for (int i = 0; i < sample.length(); i++) {
a[sample[i] - 'a'].push(i);
}
for (int i = 0; i < 26; ++i) {
ll currentPos = 0;
while (!a[i].empty()) {
ll tmp = a[i].front();
a[i].pop();
for (int j = currentPos; j <= tmp; j++) {
if (j == s.size()) {
break;
}
pos[j][i] = tmp;
}
currentPos = tmp + 1;
}
}
for (int xi = 0; xi < 26; ++xi) {
for (int yi = 0; yi < s.size(); yi++) {
// cout << pos[yi][xi] << " ";
}
// cout << endl;
}
ll count = 0;
for (int i = 0; i < t.size(); ++i) {
int current = t[i] - 'a';
ll m = count % s.size();
ll next = pos[m][current];
if (next == -1) {
cout << -1 << endl;
return 0;
}
count += next - m + 1;
}
cout << count << endl;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using ll = long long;
using namespace std;
int main() {
string s, t;
cin >> s >> t;
string sample = s + s;
ll pos[s.size()][26];
for (int yi = 0; yi < s.size(); ++yi) {
for (int xi = 0; xi < 26; ++xi) {
pos[yi][xi] = -1;
}
}
vector<queue<ll>> a(26);
for (int i = 0; i < sample.length(); i++) {
a[sample[i] - 'a'].push(i);
}
for (int i = 0; i < 26; ++i) {
ll currentPos = 0;
while (!a[i].empty()) {
ll tmp = a[i].front();
a[i].pop();
for (int j = currentPos; j <= tmp; j++) {
if (j >= s.size()) {
break;
}
pos[j][i] = tmp;
}
currentPos = tmp + 1;
}
}
for (int xi = 0; xi < 26; ++xi) {
for (int yi = 0; yi < s.size(); yi++) {
// cout << pos[yi][xi] << " ";
}
// cout << endl;
}
ll count = 0;
for (int i = 0; i < t.size(); ++i) {
int current = t[i] - 'a';
ll m = count % s.size();
ll next = pos[m][current];
if (next == -1) {
cout << -1 << endl;
return 0;
}
count += next - m + 1;
}
cout << count << endl;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02937 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>
string s, t;
bool used[26], used2[26];
ll nx[110000][26];
int main() {
cin >> s >> t;
ll n = s.size();
//-1判定
REP(i, s.size()) used[s[i] - 'a'] = true;
REP(i, t.size()) used2[t[i] - 'a'] = true;
REP(i, 26) {
if (used2[i] and !used[i]) {
cout << -1 << endl;
return 0;
}
}
s = s + s;
REPR(i, s.size() - 1) {
REP(j, 26) {
nx[i][j] = nx[i + 1][j];
if (i != s.size() - 1) {
nx[i][s[i + 1] - 'a'] = i + 1;
}
}
}
ll ans = 0, now = n - 1;
REP(i, t.size()) {
ans += nx[now][t[i] - 'a'] - now;
now = nx[now][t[i] - 'a'] % n;
}
cout << ans << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>
string s, t;
bool used[26], used2[26];
ll nx[210000][26];
int main() {
cin >> s >> t;
ll n = s.size();
//-1判定
REP(i, s.size()) used[s[i] - 'a'] = true;
REP(i, t.size()) used2[t[i] - 'a'] = true;
REP(i, 26) {
if (used2[i] and !used[i]) {
cout << -1 << endl;
return 0;
}
}
s = s + s;
REPR(i, s.size() - 1) {
REP(j, 26) {
nx[i][j] = nx[i + 1][j];
if (i != s.size() - 1) {
nx[i][s[i + 1] - 'a'] = i + 1;
}
}
}
ll ans = 0, now = n - 1;
REP(i, t.size()) {
ans += nx[now][t[i] - 'a'] - now;
now = nx[now][t[i] - 'a'] % n;
}
cout << ans << endl;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using P = pair<char, int>;
vector<int> c2p[10000];
string s, t;
int main() {
cin >> s >> t;
int sz = s.size();
for (int i = 0; i < sz; i++) {
c2p[s[i]].push_back(i);
}
long long int cnt = 0;
int prep = -1;
for (auto c : t) {
if (c2p[c].size() == 0) {
cout << -1 << endl;
return 0;
}
auto cand = c2p[c];
auto pos = upper_bound(cand.begin(), cand.end(), prep);
if (pos == cand.end())
pos = cand.begin();
if (prep >= *pos)
cnt++;
prep = *pos;
}
cout << cnt * s.size() + prep + 1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
using P = pair<char, int>;
vector<int> c2p[10000];
string s, t;
int main() {
cin >> s >> t;
int sz = s.size();
for (int i = 0; i < sz; i++) {
c2p[s[i]].push_back(i);
}
long long int cnt = 0;
int prep = -1;
for (auto c : t) {
if (c2p[c].size() == 0) {
cout << -1 << endl;
return 0;
}
auto &cand = c2p[c];
auto pos = upper_bound(cand.begin(), cand.end(), prep);
if (pos == cand.end())
pos = cand.begin();
if (prep >= *pos)
cnt++;
prep = *pos;
}
cout << cnt * s.size() + prep + 1 << endl;
} | replace | 22 | 23 | 22 | 23 | TLE | |
p02937 | C++ | Runtime Error | // 17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std ::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
#define n_l '\n'
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; }
template <typename T> int SIZE(const T &t) { return t.size(); }
string to_string(string s, int x1 = 0, int x2 = 1e9) {
return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"';
}
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(char c) { return string({c}); }
template <size_t N> string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) {
string t = "";
for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);
__iii__ <= __jjj__; ++__iii__) {
t += b[__iii__] + '0';
}
return '"' + t + '"';
}
template <typename A, typename... C>
string to_string(A(&v), int x1 = 0, int x2 = 1e9, C... coords);
int l_v_l_v_l = 0, t_a_b_s = 0;
template <typename A, typename B> string to_string(pair<A, B> &p) {
l_v_l_v_l++;
string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
l_v_l_v_l--;
return res;
}
template <typename A, typename... C>
string to_string(A(&v), int x1, int x2, C... coords) {
int rnk = rank<A>::value;
string tab(t_a_b_s, ' ');
string res = "";
bool first = true;
if (l_v_l_v_l == 0)
res += n_l;
res += tab + "[";
x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));
auto l = begin(v);
advance(l, x1);
auto r = l;
advance(r, (x2 - x1) + (x2 < SIZE(v)));
for (auto e = l; e != r; e = next(e)) {
if (!first) {
res += ", ";
}
first = false;
l_v_l_v_l++;
if (e != l) {
if (rnk > 1) {
res += n_l;
t_a_b_s = l_v_l_v_l;
};
} else {
t_a_b_s = 0;
}
res += to_string(*e, coords...);
l_v_l_v_l--;
}
res += "]";
if (l_v_l_v_l == 0)
res += n_l;
return res;
}
void dbgs() { ; }
template <typename Heads, typename... Tails> void dbgs(Heads H, Tails... T) {
cout << to_string(H) << " | ";
dbgs(T...);
}
#define dbgm(...) \
cout << "[" << #__VA_ARGS__ << "]: "; \
dbgs(__VA_ARGS__); \
cout << endl;
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MOD9 1000000009
#define ll long long
#define gc getchar_unlocked
#define eps 1e-8
#define ms(s, n) memset(s, n, sizeof(s))
#define bolt ios::sync_with_stdio(false)
const double pie = 2 * acos(0.0);
#define prec(n) fixed << setprecision(n)
#define eof (scanf("%d", &n)) != EOF
#define Unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EraseSpace(s) s.erase(remove(s.begin(), s.end(), ' '), s.end());
#define leftrotate(str, n) rotate(str.begin(), str.begin() + n, str.end());
#define rightrotate(str, n) \
rotate(str.begin(), str.begin() + str.size() - n, str.end());
#define pii pair<int, int>
#define f(i, x, n) for (int i = x; i < n; i++)
#define MP make_pair
#define db(x) cout << #x << " :: " << x << endl;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
gp_hash_table<long long, int, custom_hash> smp;
int main() {
#ifndef ONLINE_JUDGE
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
bolt;
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
int ssz = s.size();
int tz = t.size();
vector<vector<int>> pos(255);
for (int i = 0; i < ssz; i++) {
pos[s[i]].push_back(i);
}
ll res = 0;
ll ctr = 0;
ll updated = -1;
for (int i = 0; i < tz;) {
if (pos[t[i]].size() == 0) {
cout << -1 << endl;
return 0;
}
auto idx = upper_bound(pos[t[i]].begin(), pos[t[i]].end(), updated);
// dbgm(*idx, updated, t[i]);
if (upper_bound(pos[t[i]].begin(), pos[t[i]].end(), updated) ==
pos[t[i]].end()) {
ctr++;
updated = -1;
} else {
updated = *idx;
i++;
}
// dbgm(updated);
}
// dbgm(ctr, updated);
cout << ssz * ctr + updated + 1 << endl;
return 0;
} | // 17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std ::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
#define n_l '\n'
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; }
template <typename T> int SIZE(const T &t) { return t.size(); }
string to_string(string s, int x1 = 0, int x2 = 1e9) {
return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"';
}
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(char c) { return string({c}); }
template <size_t N> string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) {
string t = "";
for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1);
__iii__ <= __jjj__; ++__iii__) {
t += b[__iii__] + '0';
}
return '"' + t + '"';
}
template <typename A, typename... C>
string to_string(A(&v), int x1 = 0, int x2 = 1e9, C... coords);
int l_v_l_v_l = 0, t_a_b_s = 0;
template <typename A, typename B> string to_string(pair<A, B> &p) {
l_v_l_v_l++;
string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
l_v_l_v_l--;
return res;
}
template <typename A, typename... C>
string to_string(A(&v), int x1, int x2, C... coords) {
int rnk = rank<A>::value;
string tab(t_a_b_s, ' ');
string res = "";
bool first = true;
if (l_v_l_v_l == 0)
res += n_l;
res += tab + "[";
x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v));
auto l = begin(v);
advance(l, x1);
auto r = l;
advance(r, (x2 - x1) + (x2 < SIZE(v)));
for (auto e = l; e != r; e = next(e)) {
if (!first) {
res += ", ";
}
first = false;
l_v_l_v_l++;
if (e != l) {
if (rnk > 1) {
res += n_l;
t_a_b_s = l_v_l_v_l;
};
} else {
t_a_b_s = 0;
}
res += to_string(*e, coords...);
l_v_l_v_l--;
}
res += "]";
if (l_v_l_v_l == 0)
res += n_l;
return res;
}
void dbgs() { ; }
template <typename Heads, typename... Tails> void dbgs(Heads H, Tails... T) {
cout << to_string(H) << " | ";
dbgs(T...);
}
#define dbgm(...) \
cout << "[" << #__VA_ARGS__ << "]: "; \
dbgs(__VA_ARGS__); \
cout << endl;
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MOD9 1000000009
#define ll long long
#define gc getchar_unlocked
#define eps 1e-8
#define ms(s, n) memset(s, n, sizeof(s))
#define bolt ios::sync_with_stdio(false)
const double pie = 2 * acos(0.0);
#define prec(n) fixed << setprecision(n)
#define eof (scanf("%d", &n)) != EOF
#define Unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EraseSpace(s) s.erase(remove(s.begin(), s.end(), ' '), s.end());
#define leftrotate(str, n) rotate(str.begin(), str.begin() + n, str.end());
#define rightrotate(str, n) \
rotate(str.begin(), str.begin() + str.size() - n, str.end());
#define pii pair<int, int>
#define f(i, x, n) for (int i = x; i < n; i++)
#define MP make_pair
#define db(x) cout << #x << " :: " << x << endl;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
gp_hash_table<long long, int, custom_hash> smp;
int main() {
bolt;
cin.tie(NULL);
cout.tie(NULL);
string s, t;
cin >> s >> t;
int ssz = s.size();
int tz = t.size();
vector<vector<int>> pos(255);
for (int i = 0; i < ssz; i++) {
pos[s[i]].push_back(i);
}
ll res = 0;
ll ctr = 0;
ll updated = -1;
for (int i = 0; i < tz;) {
if (pos[t[i]].size() == 0) {
cout << -1 << endl;
return 0;
}
auto idx = upper_bound(pos[t[i]].begin(), pos[t[i]].end(), updated);
// dbgm(*idx, updated, t[i]);
if (upper_bound(pos[t[i]].begin(), pos[t[i]].end(), updated) ==
pos[t[i]].end()) {
ctr++;
updated = -1;
} else {
updated = *idx;
i++;
}
// dbgm(updated);
}
// dbgm(ctr, updated);
cout << ssz * ctr + updated + 1 << endl;
return 0;
} | delete | 131 | 135 | 131 | 131 | 0 | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define invrep(i, n) for (int64_t i = n - 1; i >= 0; i--)
using namespace std;
//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;
void setfspattern_core(int floor, int number, int degree) {
if (floor == degree) {
fspattern.at(fspcnt) = fspattern_draft;
fspcnt++;
} else {
rep(i, number) {
fspattern_draft.at(floor) = i;
setfspattern_core(floor + 1, number, degree);
}
}
}
void setfspattern(int number, int degree) {
fspcnt = 0;
int64_t array_num = 1;
rep(i, degree) { array_num *= number; }
fspattern = vector<vector<int>>(array_num, vector<int>(degree));
fspattern_draft = vector<int>(degree);
setfspattern_core(0, number, degree);
}
//////nCrのmodを求めたいときに開けよ/////////
// int64_t univMod = 1000000007;
// int64_t factnum = 100000
// vector<int64_t> modfact(factnum);
// vector<int64_t> modinvfact(factnum);
/*void setmodfact(){
for(int i=0;i<factnum;i++){
if(i == 0){
modfact.at(i) = 1;
}else{
modfact.at(i) = (modfact.at(i-1)*i)%univMod;
}
}
}
int64_t calcmodpower(int64_t a,int64_t n){
int64_t res = 1;
while(n != 0){
if(n & 1){
res = (res * a) % univMod;
}
a = (a*a) % univMod;
n = n >> 1;
}
return res;
}
int64_t calcinverse(int64_t n){
return calcmodpower(n,univMod-2);
}
void setmodinvfact(){
for(int i=0;i<factnum;i++){
if(i==0){
modinvfact.at(i) = 1;
}else{
modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
}
}
}*/
/*
int64_t calcGCD(int64_t a,int64_t b){
int64_t p = a;
int64_t q = b;
int64_t c = a%b;
while(c != 0){
p = q;
q = c;
c = p%q;
}
return q;
}
*/
int64_t INF = 1000000000000000000;
int main() {
string s, t;
cin >> s >> t;
string ss = s + s;
vector<vector<int64_t>> ch(26);
rep(i, ss.size()) { ch.at(ss.at(i) - 'a').push_back(i); }
vector<vector<int64_t>> CH(26, vector<int64_t>(s.size(), -1));
rep(i, 26) {
rep(j, s.size()) {
rep(k, ch.at(i).size()) {
if (ch.at(i).at(k) >= j) {
CH.at(i).at(j) = ch.at(i).at(k);
break;
}
}
}
}
/*rep(i,26){
rep(j,s.size()){
if(CH.at(i).at(j) != -1){
cout << CH.at(i).at(j);
}else{
cout << "D/";
}
}
cout << endl;
}*/
int64_t benow = 0;
int64_t result = 0;
bool failure = false;
rep(i, t.size()) {
// cout << benow << "->";
if (CH.at(t.at(i) - 'a').at(benow) != -1) {
result += CH.at(t.at(i) - 'a').at(benow) + 1 - benow;
benow = (CH.at(t.at(i) - 'a').at(benow) + 1) % s.size();
} else {
failure = true;
break;
}
// cout << benow << endl;
}
if (!failure) {
cout << result << endl;
} else {
cout << -1 << endl;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define invrep(i, n) for (int64_t i = n - 1; i >= 0; i--)
using namespace std;
//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;
void setfspattern_core(int floor, int number, int degree) {
if (floor == degree) {
fspattern.at(fspcnt) = fspattern_draft;
fspcnt++;
} else {
rep(i, number) {
fspattern_draft.at(floor) = i;
setfspattern_core(floor + 1, number, degree);
}
}
}
void setfspattern(int number, int degree) {
fspcnt = 0;
int64_t array_num = 1;
rep(i, degree) { array_num *= number; }
fspattern = vector<vector<int>>(array_num, vector<int>(degree));
fspattern_draft = vector<int>(degree);
setfspattern_core(0, number, degree);
}
//////nCrのmodを求めたいときに開けよ/////////
// int64_t univMod = 1000000007;
// int64_t factnum = 100000
// vector<int64_t> modfact(factnum);
// vector<int64_t> modinvfact(factnum);
/*void setmodfact(){
for(int i=0;i<factnum;i++){
if(i == 0){
modfact.at(i) = 1;
}else{
modfact.at(i) = (modfact.at(i-1)*i)%univMod;
}
}
}
int64_t calcmodpower(int64_t a,int64_t n){
int64_t res = 1;
while(n != 0){
if(n & 1){
res = (res * a) % univMod;
}
a = (a*a) % univMod;
n = n >> 1;
}
return res;
}
int64_t calcinverse(int64_t n){
return calcmodpower(n,univMod-2);
}
void setmodinvfact(){
for(int i=0;i<factnum;i++){
if(i==0){
modinvfact.at(i) = 1;
}else{
modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
}
}
}*/
/*
int64_t calcGCD(int64_t a,int64_t b){
int64_t p = a;
int64_t q = b;
int64_t c = a%b;
while(c != 0){
p = q;
q = c;
c = p%q;
}
return q;
}
*/
int64_t INF = 1000000000000000000;
int main() {
string s, t;
cin >> s >> t;
string ss = s + s;
vector<vector<int64_t>> ch(26);
rep(i, ss.size()) { ch.at(ss.at(i) - 'a').push_back(i); }
vector<vector<int64_t>> CH(26, vector<int64_t>(s.size(), -1));
rep(i, 26) {
rep(j, s.size()) {
auto itr = lower_bound(ch.at(i).begin(), ch.at(i).end(), j);
if (itr != ch.at(i).end()) {
CH.at(i).at(j) = *itr;
}
}
}
/*rep(i,26){
rep(j,s.size()){
if(CH.at(i).at(j) != -1){
cout << CH.at(i).at(j);
}else{
cout << "D/";
}
}
cout << endl;
}*/
int64_t benow = 0;
int64_t result = 0;
bool failure = false;
rep(i, t.size()) {
// cout << benow << "->";
if (CH.at(t.at(i) - 'a').at(benow) != -1) {
result += CH.at(t.at(i) - 'a').at(benow) + 1 - benow;
benow = (CH.at(t.at(i) - 'a').at(benow) + 1) % s.size();
} else {
failure = true;
break;
}
// cout << benow << endl;
}
if (!failure) {
cout << result << endl;
} else {
cout << -1 << endl;
}
} | replace | 96 | 101 | 96 | 99 | TLE | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
void solve(string s, string t) {
int sn = s.size(), tn = t.size();
vector<vector<int>> positions(26);
for (int i = 0; i < sn; i++) {
positions.at(s.at(i) - 'a').push_back(i);
}
for (int i = 0; i < sn; i++) {
positions.at(s.at(i) - 'a').push_back(sn + i);
}
for (int i = 0; i < tn; i++) {
if (positions.at(t.at(i) - 'a').size() == 0) {
cout << -1 << endl;
return;
}
}
int64_t res = 0, p = 0;
for (int i = 0; i < tn; i++) {
vector<int> pos_ti = positions.at(t.at(i) - 'a');
int p_n = *lower_bound(pos_ti.begin(), pos_ti.end(), p) + 1;
if (p_n >= sn) {
res += sn;
p_n -= sn;
}
p = p_n;
}
res += p;
cout << res << endl;
}
int main() {
string s, t;
cin >> s >> t;
solve(move(s), move(t));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
void solve(string s, string t) {
int sn = s.size(), tn = t.size();
vector<vector<int>> positions(26);
for (int i = 0; i < sn; i++) {
positions.at(s.at(i) - 'a').push_back(i);
}
for (int i = 0; i < sn; i++) {
positions.at(s.at(i) - 'a').push_back(sn + i);
}
for (int i = 0; i < tn; i++) {
if (positions.at(t.at(i) - 'a').size() == 0) {
cout << -1 << endl;
return;
}
}
int64_t res = 0, p = 0;
for (int i = 0; i < tn; i++) {
int p_n = *lower_bound(positions.at(t.at(i) - 'a').begin(),
positions.at(t.at(i) - 'a').end(), p) +
1;
if (p_n >= sn) {
res += sn;
p_n -= sn;
}
p = p_n;
}
res += p;
cout << res << endl;
}
int main() {
string s, t;
cin >> s >> t;
solve(move(s), move(t));
return 0;
}
| replace | 22 | 24 | 22 | 25 | TLE | |
p02937 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
vector<vector<ll>> a(26);
int main() {
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); i++) {
ll now = s[i] - 'a';
a[now].push_back(i + 1);
}
ll ans = 0, now = 0;
bool out = false;
for (int i = 0; i < t.size(); i++) {
ll sear = t[i] - 'a';
bool ch = false;
for (int j = 0; j < a[sear].size(); j++) {
ll fi = a[sear][j];
if (fi > now) {
ans += fi - now;
now = fi;
ch = true;
out = false;
break;
}
}
if (out) {
cout << -1;
return 0;
}
if (ch != true) {
i--;
ans += s.size() - now;
now = 0;
out = true;
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
vector<vector<ll>> a(26);
int main() {
string s, t;
cin >> s >> t;
for (int i = 0; i < s.size(); i++) {
ll now = s[i] - 'a';
a[now].push_back(i + 1);
}
ll ans = 0, now = 0;
bool out = false;
for (int i = 0; i < t.size(); i++) {
ll sear = t[i] - 'a';
bool ch = false;
auto Iter1 = upper_bound(a.at(sear).begin(), a.at(sear).end(), now);
ll res = Iter1 - a[sear].begin();
if (res != a[sear].size()) {
ll fi = a[sear][res];
ans += fi - now;
now = fi;
ch = true;
out = false;
}
if (out) {
cout << -1;
return 0;
}
if (ch != true) {
i--;
ans += s.size() - now;
now = 0;
out = true;
}
}
cout << ans;
return 0;
} | replace | 19 | 28 | 19 | 27 | TLE | |
p02938 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main() {
long long l, r;
cin >> l >> r;
long long ans = 0;
// x ⊂ y
// (0, 0), (0, 1), (1, 1)
for (int k = 0; k < 62; k++) {
long long c = 1LL << k;
long long d = 1LL << (k + 1);
if (l >= d || c > r)
continue;
long long dp[k + 1][4];
// 0: l < curr && r > curr, 1: l <= curr, 2: r >= curr
memset(dp, 0, sizeof(dp));
int s = 0;
if (c <= l && l < d)
s += 1 << 0;
if (c <= r && r < d)
s += 1 << 1;
dp[k][s]++;
long long prev = ans;
for (int i = k - 1; i >= 0; i--) {
if (i < 0)
continue;
bool lb = l & (1LL << i);
bool rb = r & (1LL << i);
// dp[i+1][0]
dp[i][0] += dp[i + 1][0] * 3 % mod;
// dp[i+1][1]
if (lb) {
dp[i][1] += dp[i + 1][1];
} else {
dp[i][0] += dp[i + 1][1];
dp[i][1] += dp[i + 1][1] * 2 % mod;
}
// dp[i+1][2]
if (rb) {
dp[i][2] += dp[i + 1][2] * 2 % mod;
dp[i][0] += dp[i + 1][2];
} else {
dp[i][2] += dp[i + 1][2];
}
// dp[i+1][3]
if (lb == rb) {
dp[i][3] += dp[i + 1][3];
} else {
if (dp[i + 1][3])
assert(!lb);
// lb 0, rb 1
dp[i][1] += dp[i + 1][3];
dp[i][2] += dp[i + 1][3];
dp[i][3] += dp[i + 1][3];
}
}
for (int j = 0; j < 4; j++) {
ans = (ans + dp[0][j]) % mod;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main() {
long long l, r;
cin >> l >> r;
long long ans = 0;
// x ⊂ y
// (0, 0), (0, 1), (1, 1)
for (int k = 0; k < 62; k++) {
long long c = 1LL << k;
long long d = 1LL << (k + 1);
if (l >= d || c > r)
continue;
long long dp[k + 1][4];
// 0: l < curr && r > curr, 1: l <= curr, 2: r >= curr
memset(dp, 0, sizeof(dp));
int s = 0;
if (c <= l && l < d)
s += 1 << 0;
if (c <= r && r < d)
s += 1 << 1;
dp[k][s]++;
long long prev = ans;
for (int i = k - 1; i >= 0; i--) {
if (i < 0)
continue;
bool lb = l & (1LL << i);
bool rb = r & (1LL << i);
// dp[i+1][0]
dp[i][0] += dp[i + 1][0] * 3 % mod;
// dp[i+1][1]
if (lb) {
dp[i][1] += dp[i + 1][1];
} else {
dp[i][0] += dp[i + 1][1];
dp[i][1] += dp[i + 1][1] * 2 % mod;
}
// dp[i+1][2]
if (rb) {
dp[i][2] += dp[i + 1][2] * 2 % mod;
dp[i][0] += dp[i + 1][2];
} else {
dp[i][2] += dp[i + 1][2];
}
// dp[i+1][3]
if (lb == rb) {
dp[i][3] += dp[i + 1][3];
} else if (rb) {
dp[i][1] += dp[i + 1][3];
dp[i][2] += dp[i + 1][3];
dp[i][3] += dp[i + 1][3];
}
}
for (int j = 0; j < 4; j++) {
ans = (ans + dp[0][j]) % mod;
}
}
cout << ans << endl;
return 0;
} | replace | 52 | 56 | 52 | 53 | 0 | |
p02938 | C++ | Runtime Error | #include <bits/stdc++.h>
#define dbug(x) cout << #x << "=" << x << endl
using namespace std;
template <typename T> void read(T &t) {
t = 0;
char ch = getchar();
int f = 1;
while ('0' > ch || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
do {
(t *= 10) += ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
t *= f;
}
typedef long long ll;
const ll mod = (1e9) + 7;
int mx = 63;
int d[70], e[70];
ll dp[70][2][2][3];
void update(ll &x, ll y) {
x += y;
x %= mod;
}
ll solve(ll L, ll R) {
for (int i = 0; i < mx; i++) {
if (R & (1LL << i))
d[i] = 1;
else
d[i] = 0;
if (L & (1LL << i))
e[i] = 1;
else
e[i] = 0;
}
// for (int i=0;i<mx;i++) printf("%d",d[i]); printf("\n");
// for (int i=0;i<mx;i++) printf("%d",e[i]); printf("\n");
memset(dp, 0, sizeof(dp));
dp[mx][1][1][0] = 1;
int C;
for (int i = mx; i >= 0; i--) {
for (int j = 0; j <= 1; j++)
for (int k = 0; k <= 1; k++)
for (int B = 0; B <= 2; B++) {
// printf("%d %d %d %d %lld\n",i,j,k,B,dp[i][j][k][B]);
for (int a = 0; a <= 1; a++)
for (int b = 0; b <= 1; b++) {
if (j && a > d[i - 1])
continue;
if (k && b > e[i - 1])
continue;
if (a < b)
continue;
if (B == 2)
C = 2;
else {
if (b || B)
C = 1;
else if (a - b)
C = 2;
else
C = 0;
}
update(dp[i - 1][j & (a == d[i - 1])][k & (b == e[i - 1])][C],
dp[i][j][k][B]);
}
}
}
ll res = 0;
for (int j = 0; j <= 1; j++)
for (int k = 0; k <= 1; k++)
update(res, dp[0][j][k][1]);
// printf("%lld\n",res);
return res;
}
int main() {
// freopen("1.txt","r",stdin);
// freopen("1.out","w",stdout);
ll L, R;
read(L);
read(R);
ll ans = solve(R, R) - solve(L - 1, R);
ans = (ans % mod + mod) % mod;
printf("%lld\n", ans);
/*ans=0;
for (int x=1;x<=R;x++)
for (int y=x;y<=R;y++)
if (y%x==(x^y)) ans++;
printf("%lld\n",ans);*/
return 0;
} | #include <bits/stdc++.h>
#define dbug(x) cout << #x << "=" << x << endl
using namespace std;
template <typename T> void read(T &t) {
t = 0;
char ch = getchar();
int f = 1;
while ('0' > ch || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
do {
(t *= 10) += ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
t *= f;
}
typedef long long ll;
const ll mod = (1e9) + 7;
int mx = 63;
int d[70], e[70];
ll dp[70][2][2][3];
void update(ll &x, ll y) {
x += y;
x %= mod;
}
ll solve(ll L, ll R) {
for (int i = 0; i < mx; i++) {
if (R & (1LL << i))
d[i] = 1;
else
d[i] = 0;
if (L & (1LL << i))
e[i] = 1;
else
e[i] = 0;
}
// for (int i=0;i<mx;i++) printf("%d",d[i]); printf("\n");
// for (int i=0;i<mx;i++) printf("%d",e[i]); printf("\n");
memset(dp, 0, sizeof(dp));
dp[mx][1][1][0] = 1;
int C;
for (int i = mx; i >= 1; i--) {
for (int j = 0; j <= 1; j++)
for (int k = 0; k <= 1; k++)
for (int B = 0; B <= 2; B++) {
// printf("%d %d %d %d %lld\n",i,j,k,B,dp[i][j][k][B]);
for (int a = 0; a <= 1; a++)
for (int b = 0; b <= 1; b++) {
if (j && a > d[i - 1])
continue;
if (k && b > e[i - 1])
continue;
if (a < b)
continue;
if (B == 2)
C = 2;
else {
if (b || B)
C = 1;
else if (a - b)
C = 2;
else
C = 0;
}
update(dp[i - 1][j & (a == d[i - 1])][k & (b == e[i - 1])][C],
dp[i][j][k][B]);
}
}
}
ll res = 0;
for (int j = 0; j <= 1; j++)
for (int k = 0; k <= 1; k++)
update(res, dp[0][j][k][1]);
// printf("%lld\n",res);
return res;
}
int main() {
// freopen("1.txt","r",stdin);
// freopen("1.out","w",stdout);
ll L, R;
read(L);
read(R);
ll ans = solve(R, R) - solve(L - 1, R);
ans = (ans % mod + mod) % mod;
printf("%lld\n", ans);
/*ans=0;
for (int x=1;x<=R;x++)
for (int y=x;y<=R;y++)
if (y%x==(x^y)) ans++;
printf("%lld\n",ans);*/
return 0;
} | replace | 43 | 44 | 43 | 44 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define endl '\n'
#define PI 3.14159265359d
#define sz(x) (int)x.size()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define magic 109
#define INF INT_MAX
using namespace std;
const int MN = 20000000;
// struct trie
// {
// int n;
// int nodes[MN][2];
// void clear()
// {
// n = 1; nodes[0][0] = nodes[0][1] = -1;
// }
// void insert(int x)
// {
// int node = 0;
// for(int i = 31; i>=0; i--)
// {
// int next = (x & 1<<i )!=0;
// if(nodes[node][next]==-1)
// {
// nodes[node][next] = n;
// nodes[n][0] = nodes[n][1] = -1;
// n++;
// }
// node = nodes[node][next];
// }
// }
// int query(int x)
// {
// int node = 0;
// int ans = 0;
// for(int i = 31; i>=0; i--)
// {
// int next = fc (x & (1<<i))!=0;
// int cool = -1;
// if(nodes[node][next^1]==-1)
// {
// next^=1;
// cool = 0;
// }
// if(cool)
// ans+=1<<i;
// if(nodes[node][next^1]==-1)while(true){}
// node = nodes[node][next^1];
// }
// return ans;
// }
// };
// trie tree;
void solve() {
string s;
cin >> s;
int n = s.length();
int ans = 0;
vector<string> st;
string l = "";
rep(i, 0, n) {
l += s[i];
if (st.size() == 0) {
st.push_back(l);
l = "";
} else if (st.back() != l) {
st.push_back(l);
l = "";
}
}
cout << st.size();
}
signed main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define endl '\n'
#define PI 3.14159265359d
#define sz(x) (int)x.size()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define magic 109
#define INF INT_MAX
using namespace std;
const int MN = 20000000;
// struct trie
// {
// int n;
// int nodes[MN][2];
// void clear()
// {
// n = 1; nodes[0][0] = nodes[0][1] = -1;
// }
// void insert(int x)
// {
// int node = 0;
// for(int i = 31; i>=0; i--)
// {
// int next = (x & 1<<i )!=0;
// if(nodes[node][next]==-1)
// {
// nodes[node][next] = n;
// nodes[n][0] = nodes[n][1] = -1;
// n++;
// }
// node = nodes[node][next];
// }
// }
// int query(int x)
// {
// int node = 0;
// int ans = 0;
// for(int i = 31; i>=0; i--)
// {
// int next = fc (x & (1<<i))!=0;
// int cool = -1;
// if(nodes[node][next^1]==-1)
// {
// next^=1;
// cool = 0;
// }
// if(cool)
// ans+=1<<i;
// if(nodes[node][next^1]==-1)while(true){}
// node = nodes[node][next^1];
// }
// return ans;
// }
// };
// trie tree;
void solve() {
string s;
cin >> s;
int n = s.length();
int ans = 0;
vector<string> st;
string l = "";
rep(i, 0, n) {
l += s[i];
if (st.size() == 0) {
st.push_back(l);
l = "";
} else if (st.back() != l) {
st.push_back(l);
l = "";
}
}
cout << st.size();
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
} | replace | 83 | 89 | 83 | 84 | 0 | |
p02939 | C++ | Runtime Error | #include <cstdio>
#include <cstring>
char s[100010];
int main() {
scanf("%s", s + 1);
int L = strlen(s + 1), ans = 0;
for (int i = 1, j; i <= L; ++i) {
for (j = i; s[j] == s[j + 1]; ++j)
;
int l = j - i + 1;
switch (l % 3) {
case 0:
ans += l / 3 * 2;
break;
case 1:
ans += l / 3 * 2 + 1;
break;
case 2:
ans += l / 3 * 2 + 2, ++j;
break;
}
j > L &&l % 3 == 2 && (--ans);
i = j;
}
printf("%d\n", ans);
return 0;
} | #include <cstdio>
#include <cstring>
char s[200010];
int main() {
scanf("%s", s + 1);
int L = strlen(s + 1), ans = 0;
for (int i = 1, j; i <= L; ++i) {
for (j = i; s[j] == s[j + 1]; ++j)
;
int l = j - i + 1;
switch (l % 3) {
case 0:
ans += l / 3 * 2;
break;
case 1:
ans += l / 3 * 2 + 1;
break;
case 2:
ans += l / 3 * 2 + 2, ++j;
break;
}
j > L &&l % 3 == 2 && (--ans);
i = j;
}
printf("%d\n", ans);
return 0;
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02939 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);
string s;
map<pair<int, string>, int> memo;
int ans;
int solve(int pos, string last) {
auto key = make_pair(pos, last);
if (memo.find(key) != memo.end())
return memo[key];
if (pos == s.size())
return memo[key] = 0;
int ret = -1;
for (int i = 1; (pos + i) <= s.size(); ++i) {
int next_pos = pos + i;
if (last == s.substr(pos, i))
continue;
ret = max(ret, solve(next_pos, s.substr(pos, i)));
}
ret += (ret == -1) ? 0 : 1;
return memo[key] = ret;
}
int main(void) {
// Here your code !
cin >> s;
// int pos = 0;
// for (int i = 1; (pos + i) <= s.size(); ++i) {
// int next_pos = pos + i;
// printf("%d\n", next_pos);
// cout << s.substr(pos, i) << endl;
// }
set<string> occur;
ans = solve(0, "");
printf("%d\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);
string s;
map<pair<int, string>, int> memo;
int ans;
int solve(int pos, string last) {
auto key = make_pair(pos, last);
if (memo.find(key) != memo.end())
return memo[key];
if (pos == s.size())
return memo[key] = 0;
int ret = -1;
for (int i = 1; (pos + i) <= min((int)(s.size()), pos + 2); ++i) {
int next_pos = pos + i;
if (last == s.substr(pos, i))
continue;
ret = max(ret, solve(next_pos, s.substr(pos, i)));
}
ret += (ret == -1) ? 0 : 1;
return memo[key] = ret;
}
int main(void) {
// Here your code !
cin >> s;
// int pos = 0;
// for (int i = 1; (pos + i) <= s.size(); ++i) {
// int next_pos = pos + i;
// printf("%d\n", next_pos);
// cout << s.substr(pos, i) << endl;
// }
set<string> occur;
ans = solve(0, "");
printf("%d\n", ans);
return 0;
}
| replace | 24 | 25 | 24 | 25 | TLE | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fio() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define int long long
#define MOD 998244353
using namespace std;
const int N = 300005;
string s;
int dp[100001][2];
int solve(int i, int b) {
int j = b;
if (i == s.size())
return 0;
if (dp[i][b] != -1)
return dp[i][b];
if (b == 0) {
dp[i][j] = 0;
if (i != s.size() - 1)
dp[i][j] = 1 + solve(i + 2, 1);
if (s[i] != s[i - 1])
dp[i][j] = max(dp[i][j], 1 + solve(i + 1, 0));
}
if (b == 1)
dp[i][j] = 1 + solve(i + 1, 0);
// cout << i << " " << b << " " << dp[i][b] << endl;
return dp[i][j];
}
int32_t main() {
fio();
cin >> s;
if (s.size() == 1)
return 1;
for (int i = 0; i < s.size(); i++)
dp[i][0] = -1, dp[i][1] = -1;
cout << 1 + max(solve(1, 0), solve(2, 1));
} | #include <bits/stdc++.h>
#define fio() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define int long long
#define MOD 998244353
using namespace std;
const int N = 300005;
string s;
int dp[200006][2];
int solve(int i, int b) {
int j = b;
if (i == s.size())
return 0;
if (dp[i][b] != -1)
return dp[i][b];
if (b == 0) {
dp[i][j] = 0;
if (i != s.size() - 1)
dp[i][j] = 1 + solve(i + 2, 1);
if (s[i] != s[i - 1])
dp[i][j] = max(dp[i][j], 1 + solve(i + 1, 0));
}
if (b == 1)
dp[i][j] = 1 + solve(i + 1, 0);
// cout << i << " " << b << " " << dp[i][b] << endl;
return dp[i][j];
}
int32_t main() {
fio();
cin >> s;
if (s.size() == 1)
return 1;
for (int i = 0; i < s.size(); i++)
dp[i][0] = -1, dp[i][1] = -1;
cout << 1 + max(solve(1, 0), solve(2, 1));
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02939 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, o) for (int i = 0; i < (o); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) < (int)(b); i++)
#define NUM 1e5
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
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 (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
string s;
cin >> s;
int dp[100010][3];
memset(dp, 0, sizeof(dp));
/* dp[i][j] で
1.i文字目まで見たか,
2.前の文字の長さが j 文字の時 を表現*/
dp[1][0] = dp[2][1] = 1;
rep(i, s.size() + 1) {
if (i >= 1 && s[i - 1] != s[i]) {
chmax(dp[i + 1][1], dp[i][1] + 1);
}
if (i >= 2 && (s[i - 2] != s[i] || s[i - 1] != s[i + 1])) {
chmax(dp[i + 2][2], dp[i][2] + 1);
}
chmax(dp[i + 2][2], dp[i][1] + 1); // 1 -> 2
chmax(dp[i + 1][1], dp[i][2] + 1); // 2 -> 1
// rep(i, s.size() + 1) {
// cout << dp[i][1] << " " << dp[i][2] << endl;
// }
}
cout << max(dp[s.size()][1], dp[s.size()][2]) << endl;
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define rep(i, o) for (int i = 0; i < (o); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) < (int)(b); i++)
#define NUM 1e5
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
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 (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
string s;
cin >> s;
int dp[s.size() + 1][3];
memset(dp, 0, sizeof(dp));
/* dp[i][j] で
1.i文字目まで見たか,
2.前の文字の長さが j 文字の時 を表現*/
dp[1][0] = dp[2][1] = 1;
rep(i, s.size() + 1) {
if (i >= 1 && s[i - 1] != s[i]) {
chmax(dp[i + 1][1], dp[i][1] + 1);
}
if (i >= 2 && (s[i - 2] != s[i] || s[i - 1] != s[i + 1])) {
chmax(dp[i + 2][2], dp[i][2] + 1);
}
chmax(dp[i + 2][2], dp[i][1] + 1); // 1 -> 2
chmax(dp[i + 1][1], dp[i][2] + 1); // 2 -> 1
// rep(i, s.size() + 1) {
// cout << dp[i][1] << " " << dp[i][2] << endl;
// }
}
cout << max(dp[s.size()][1], dp[s.size()][2]) << endl;
return 0;
} | replace | 40 | 41 | 40 | 41 | 0 | |
p02939 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
mt19937 mt(736);
int foo(const string &s, const string &last = "", int p = 0) {
static map<pair<int, string>, int> dp;
if (p == s.size())
return 0;
for (int i = p + 1; i <= s.size() && i < p + 4; i++)
if (s.substr(p, i - p) != last)
dp[{p, last}] = max(dp[{p, last}], 1 + foo(s, s.substr(p, i - p), i));
return dp[{p, last}];
}
void solve(istream &cin = std::cin, ostream &cout = std::cout) {
string s;
cin >> s;
cout << foo(s) << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed;
#ifdef LOCAL
auto st = clock();
ifstream fin("../input.txt");
solve(fin);
cout << "clock: " << setprecision(4)
<< (clock() - st) / (double)CLOCKS_PER_SEC << endl;
#else
solve();
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
mt19937 mt(736);
int foo(const string &s, const string &last = "", int p = 0) {
static map<pair<int, string>, int> dp;
if (p == s.size())
return 0;
if (!dp.count({p, last}))
for (int i = p + 1; i <= s.size() && i < p + 4; i++)
if (s.substr(p, i - p) != last)
dp[{p, last}] = max(dp[{p, last}], 1 + foo(s, s.substr(p, i - p), i));
return dp[{p, last}];
}
void solve(istream &cin = std::cin, ostream &cout = std::cout) {
string s;
cin >> s;
cout << foo(s) << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed;
#ifdef LOCAL
auto st = clock();
ifstream fin("../input.txt");
solve(fin);
cout << "clock: " << setprecision(4)
<< (clock() - st) / (double)CLOCKS_PER_SEC << endl;
#else
solve();
#endif
return 0;
}
| replace | 14 | 17 | 14 | 18 | TLE | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, n) for (ll i = x; i < n; i++)
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
const int mod = 1e9 + 7;
const int N = 2e5 + 6;
int arr[N];
int DP[N][3];
string input;
int f(int idx, int cnt) {
if (idx >= input.size())
return 0;
if (DP[idx][cnt] != -1)
return DP[idx][cnt];
if (idx == 0) {
int ans1 = 1 + f(idx + 1, 1);
int ans2 = 1 + f(idx + 2, 2);
return DP[idx][cnt] = max(ans1, ans2);
} else {
if (cnt == 1) {
int ans1 = -9999999999, ans2 = -9999999999;
if (input[idx] != input[idx - 1]) {
ans1 = 1 + f(idx + 1, 1);
ans2 = 1 + f(idx + 2, 2);
} else if (idx != input.si - 1) {
ans2 = 1 + f(idx + 2, 2);
}
return DP[idx][cnt] = max(ans1, ans2);
} else {
int ans1 = 1 + f(idx + 1, 1);
return DP[idx][cnt] = ans1;
}
}
}
void solve() {
cin >> input;
int n = input.size();
memset(DP, -1, sizeof(DP));
cout << f(0, 0);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, n) for (ll i = x; i < n; i++)
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
const int mod = 1e9 + 7;
const int N = 2e5 + 6;
int arr[N];
int DP[N][3];
string input;
int f(int idx, int cnt) {
if (idx >= input.size())
return 0;
if (DP[idx][cnt] != -1)
return DP[idx][cnt];
if (idx == 0) {
int ans1 = 1 + f(idx + 1, 1);
int ans2 = 1 + f(idx + 2, 2);
return DP[idx][cnt] = max(ans1, ans2);
} else {
if (cnt == 1) {
int ans1 = -9999999999, ans2 = -9999999999;
if (input[idx] != input[idx - 1]) {
ans1 = 1 + f(idx + 1, 1);
ans2 = 1 + f(idx + 2, 2);
} else if (idx != input.si - 1) {
ans2 = 1 + f(idx + 2, 2);
}
return DP[idx][cnt] = max(ans1, ans2);
} else {
int ans1 = 1 + f(idx + 1, 1);
return DP[idx][cnt] = ans1;
}
}
}
void solve() {
cin >> input;
int n = input.size();
memset(DP, -1, sizeof(DP));
cout << f(0, 0);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
solve();
return 0;
} | replace | 62 | 66 | 62 | 66 | 0 | |
p02939 | C++ | Runtime Error | #include "bits/stdc++.h"
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(), a.end())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MP(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define INF LLONG_MAX / 2
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) \
cerr << #v << ":"; \
rep(i, v.size()) cerr << " " << v[i]; \
cerr << endl
using namespace std;
int MOD = 998244353;
ll dp[20010][2] = {0};
signed main() {
string s;
cin >> s;
ll n = s.size();
dp[1][0] = 1;
dp[1][1] = 0;
for (int i = 2; i <= n; i++) {
// 2コ使う
if (i < 4 || (s[i - 1] == s[i - 3] && s[i - 2] == s[i - 4])) {
dp[i][1] = dp[i - 2][0] + 1;
} else {
dp[i][1] = max(dp[i - 2][0], dp[i - 2][1]) + 1;
}
if (s[i - 1] == s[i - 2]) {
dp[i][0] = dp[i - 1][1] + 1;
} else {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
}
}
cout << max(dp[n][0], dp[n][1]) << endl;
return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl
// https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a rm -r -f
// test;oj dl http://agc037.contest.atcoder.jp/tasks/agc037_a | #include "bits/stdc++.h"
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(), a.end())
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MP(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define INF LLONG_MAX / 2
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) \
cerr << #v << ":"; \
rep(i, v.size()) cerr << " " << v[i]; \
cerr << endl
using namespace std;
int MOD = 998244353;
ll dp[200010][2] = {0};
signed main() {
string s;
cin >> s;
ll n = s.size();
dp[1][0] = 1;
dp[1][1] = 0;
for (int i = 2; i <= n; i++) {
// 2コ使う
if (i < 4 || (s[i - 1] == s[i - 3] && s[i - 2] == s[i - 4])) {
dp[i][1] = dp[i - 2][0] + 1;
} else {
dp[i][1] = max(dp[i - 2][0], dp[i - 2][1]) + 1;
}
if (s[i - 1] == s[i - 2]) {
dp[i][0] = dp[i - 1][1] + 1;
} else {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + 1;
}
}
cout << max(dp[n][0], dp[n][1]) << endl;
return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl
// https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a rm -r -f
// test;oj dl http://agc037.contest.atcoder.jp/tasks/agc037_a | replace | 21 | 22 | 21 | 22 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#define N 200005
#define task "t"
#define mu(x) x *x
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<int, pii>;
const int inf = 1e9 + 7;
const int base = 311;
string s;
ll Hash = 0, res = 0, Hash1 = -1;
int main() {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
#ifndef ONLINE_JUDGE
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
#endif // ONLINE_JUDGE
cin >> s;
for (int i = 0; i < s.length(); i++) {
Hash = (Hash * base + s[i] - 'a' + 1) % inf;
if (Hash != Hash1) {
res++;
Hash1 = Hash;
Hash = 0;
}
}
cout << res;
return 0;
}
| #include <bits/stdc++.h>
#define N 200005
#define task "t"
#define mu(x) x *x
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<int, pii>;
const int inf = 1e9 + 7;
const int base = 311;
string s;
ll Hash = 0, res = 0, Hash1 = -1;
int main() {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
#ifndef ONLINE_JUDGE
// freopen(task".inp","r",stdin);
// freopen(task".out","w",stdout);
#endif // ONLINE_JUDGE
cin >> s;
for (int i = 0; i < s.length(); i++) {
Hash = (Hash * base + s[i] - 'a' + 1) % inf;
if (Hash != Hash1) {
res++;
Hash1 = Hash;
Hash = 0;
}
}
cout << res;
return 0;
}
| replace | 20 | 22 | 20 | 22 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#define maxn 20100
using namespace std;
string s;
int f[maxn][3], n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> s;
n = s.length();
for (int i = 0; i < n; i++)
for (int k = 0; k < 3; k++)
f[i][k] = -1;
f[0][0] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < 3; j++) {
if (f[i][j] == -1)
continue;
for (int k = 1; k < 3; k++) {
if (i + k > n)
continue;
if (j != k || s.substr(i - j, j) != s.substr(i, k))
f[i + k][k] = max(f[i + k][k], f[i][j] + 1);
}
// cout<<f[i][j]<<endl;
}
int ans = 0;
for (int i = 0; i < 3; i++)
ans = max(ans, f[n][i]);
cout << ans;
}
| #include <bits/stdc++.h>
#define maxn 200100
using namespace std;
string s;
int f[maxn][3], n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> s;
n = s.length();
for (int i = 0; i < n; i++)
for (int k = 0; k < 3; k++)
f[i][k] = -1;
f[0][0] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < 3; j++) {
if (f[i][j] == -1)
continue;
for (int k = 1; k < 3; k++) {
if (i + k > n)
continue;
if (j != k || s.substr(i - j, j) != s.substr(i, k))
f[i + k][k] = max(f[i + k][k], f[i][j] + 1);
}
// cout<<f[i][j]<<endl;
}
int ans = 0;
for (int i = 0; i < 3; i++)
ans = max(ans, f[n][i]);
cout << ans;
}
| replace | 1 | 2 | 1 | 2 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
int main() {
string S;
cin >> S;
int n = (int)(S.length());
vector<int> dp(n);
int i = 0;
dp[0] = 0;
int tmp = 1;
while (i < n - 1) {
// cout << i << endl;
// for (int j = 0;j < n; j++){
// cout << dp[j] << endl;
// }
if (tmp == 1) {
if (S[i] != S[i + 1]) {
dp[i + 1] = dp[i] + 1;
i++;
tmp = 1;
} else {
dp[i + 1] = dp[i];
dp[i + 2] = dp[i] + 1;
i += 2;
tmp = 2;
}
} else {
dp[i + 1] = dp[i] + 1;
i++;
tmp = 1;
}
}
if (dp[n - 1] == 0) {
cout << dp[n - 1] << endl;
} else {
cout << dp[n - 1] + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
int main() {
string S;
cin >> S;
int n = (int)(S.length());
vector<int> dp(n + 2);
int i = 0;
dp[0] = 0;
int tmp = 1;
while (i < n - 1) {
// cout << i << endl;
// for (int j = 0;j < n; j++){
// cout << dp[j] << endl;
// }
if (tmp == 1) {
if (S[i] != S[i + 1]) {
dp[i + 1] = dp[i] + 1;
i++;
tmp = 1;
} else {
dp[i + 1] = dp[i];
dp[i + 2] = dp[i] + 1;
i += 2;
tmp = 2;
}
} else {
dp[i + 1] = dp[i] + 1;
i++;
tmp = 1;
}
}
if (dp[n - 1] == 0) {
cout << dp[n - 1] << endl;
} else {
cout << dp[n - 1] + 1 << endl;
}
return 0;
} | replace | 19 | 20 | 19 | 20 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02939 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;
using namespace std;
int inputValue() {
int a;
cin >> a;
return a;
};
void inputArray(int *p, int a){rep(i, a){cin >> p[i];
}
}
;
void inputVector(vector<int> *p, int a) {
rep(i, a) {
int input;
cin >> input;
p->push_back(input);
}
}
template <typename T> void output(T a, int precision) {
if (precision > 0) {
cout << setprecision(precision) << a << "\n";
} else {
cout << a << "\n";
}
}
int main(int argc, const char *argv[]) {
// source code
string ss;
cin >> ss;
int vccount = 0;
vector<string> vc;
rep(i, ss.length()) {
vc.push_back(&ss[i]);
if (vc.size() > 1 && (vc.at(vc.size() - 2) == string() + ss[i])) {
if (i == ss.length() - 1) {
cout << vc.size() - 1;
return 0;
} else {
vc.at(vc.size() - 1) = vc.at(vc.size() - 1) + ss[i + 1];
i++;
}
}
}
cout << vc.size();
return 0;
}
| #include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;
using namespace std;
int inputValue() {
int a;
cin >> a;
return a;
};
void inputArray(int *p, int a){rep(i, a){cin >> p[i];
}
}
;
void inputVector(vector<int> *p, int a) {
rep(i, a) {
int input;
cin >> input;
p->push_back(input);
}
}
template <typename T> void output(T a, int precision) {
if (precision > 0) {
cout << setprecision(precision) << a << "\n";
} else {
cout << a << "\n";
}
}
int main(int argc, const char *argv[]) {
// source code
string ss;
cin >> ss;
int vccount = 0;
vector<string> vc;
rep(i, ss.length()) {
vc.push_back(string() + ss[i]);
if (vc.size() > 1 && (vc.at(vc.size() - 2) == string() + ss[i])) {
if (i == ss.length() - 1) {
cout << vc.size() - 1;
return 0;
} else {
vc.at(vc.size() - 1) = vc.at(vc.size() - 1) + ss[i + 1];
i++;
}
}
}
cout << vc.size();
return 0;
}
| replace | 53 | 54 | 53 | 54 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define debug(var) \
do { \
cout << #var << " : "; \
view(var); \
} while (0)
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
template <class T> void view(T e) { cout << e << endl; }
template <class T> void view(const vector<T> &v) {
for (const auto &e : v) {
cout << e << " ";
}
cout << endl;
}
template <class T> void view(const vector<vector<T>> &vv) {
for (const auto &v : vv) {
view(v);
}
}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
int dp[20005][3];
int main() {
string s;
cin >> s;
int n = s.size();
for (int i = 1; i <= n; i++) {
chmax(dp[i][1], dp[i - 1][2] + 1);
if (i - 2 >= 0 && s[i - 1] != s[i - 2])
chmax(dp[i][1], dp[i - 1][1] + 1);
if (i - 2 >= 0)
chmax(dp[i][2], dp[i - 2][1] + 1);
if (i - 3 >= 0 && s.substr(i - 1, 2) != s.substr(i - 3, 2)) {
chmax(dp[i][2], dp[i - 2][2] + 1);
}
}
int ans = max(dp[n][1], dp[n][2]);
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define debug(var) \
do { \
cout << #var << " : "; \
view(var); \
} while (0)
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
template <class T> void view(T e) { cout << e << endl; }
template <class T> void view(const vector<T> &v) {
for (const auto &e : v) {
cout << e << " ";
}
cout << endl;
}
template <class T> void view(const vector<vector<T>> &vv) {
for (const auto &v : vv) {
view(v);
}
}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int, int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
int dp[200005][3];
int main() {
string s;
cin >> s;
int n = s.size();
for (int i = 1; i <= n; i++) {
chmax(dp[i][1], dp[i - 1][2] + 1);
if (i - 2 >= 0 && s[i - 1] != s[i - 2])
chmax(dp[i][1], dp[i - 1][1] + 1);
if (i - 2 >= 0)
chmax(dp[i][2], dp[i - 2][1] + 1);
if (i - 3 >= 0 && s.substr(i - 1, 2) != s.substr(i - 3, 2)) {
chmax(dp[i][2], dp[i - 2][2] + 1);
}
}
int ans = max(dp[n][1], dp[n][2]);
cout << ans << endl;
} | replace | 47 | 48 | 47 | 48 | 0 | |
p02939 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define MAXN 100000
#define LL long long
LL read() {
LL x = 0, F = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
F = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * F;
}
char s[MAXN + 5];
int n, ans, cnt, flag;
char pre;
int main() {
scanf("%s", s + 1);
n = strlen(s + 1);
int i;
pre = '0';
for (i = 1; i <= n; i++)
if (s[i] == pre) {
pre = '0';
flag = 1;
} else {
if (!flag)
pre = s[i];
flag = 0;
ans++;
}
printf("%d", ans);
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define MAXN 200000
#define LL long long
LL read() {
LL x = 0, F = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
F = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * F;
}
char s[MAXN + 5];
int n, ans, cnt, flag;
char pre;
int main() {
scanf("%s", s + 1);
n = strlen(s + 1);
int i;
pre = '0';
for (i = 1; i <= n; i++)
if (s[i] == pre) {
pre = '0';
flag = 1;
} else {
if (!flag)
pre = s[i];
flag = 0;
ans++;
}
printf("%d", ans);
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int INF = 1 << 29;
int main() {
string s;
cin >> s;
int n = s.length();
int dp[100001][2] =
{}; // dp[i][j] = (s[0,i) について, 分割した一番右の文字列が長さ j+1
// であるような最大分割数)
for (int i = 1; i <= n; i++) {
// 1 文字で分割
dp[i][0] = dp[i - 1][1] + 1;
if (i >= 2 && s[i - 1] != s[i - 2])
dp[i][0] = max(dp[i][0], dp[i - 1][0] + 1);
// 2 文字で分割
dp[i][1] = -INF;
if (i >= 2)
dp[i][1] = dp[i - 2][0] + 1;
if (i >= 4 && s.substr(i - 2, 2) != s.substr(i - 4, 2))
dp[i][1] = max(dp[i][1], dp[i - 2][1] + 1);
}
printf("%d\n", max(dp[n][0], dp[n][1]));
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int INF = 1 << 29;
int main() {
string s;
cin >> s;
int n = s.length();
int dp[200001][2] =
{}; // dp[i][j] = (s[0,i) について, 分割した一番右の文字列が長さ j+1
// であるような最大分割数)
for (int i = 1; i <= n; i++) {
// 1 文字で分割
dp[i][0] = dp[i - 1][1] + 1;
if (i >= 2 && s[i - 1] != s[i - 2])
dp[i][0] = max(dp[i][0], dp[i - 1][0] + 1);
// 2 文字で分割
dp[i][1] = -INF;
if (i >= 2)
dp[i][1] = dp[i - 2][0] + 1;
if (i >= 4 && s.substr(i - 2, 2) != s.substr(i - 4, 2))
dp[i][1] = max(dp[i][1], dp[i - 2][1] + 1);
}
printf("%d\n", max(dp[n][0], dp[n][1]));
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll) a.size()
#define pll pair<ll, ll>
#define rep(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define sep(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define mll map<ll, ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll dp[100005][2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
if (s.size() == 1) {
cout << 1 << "\n";
return 0;
}
dp[0][1] = 1;
dp[1][2] = 1;
if (s[1] != s[0])
dp[1][1] = 2;
rep(i, 2, sz(s)) {
if (dp[i - 1][2])
dp[i][1] = 1 + dp[i - 1][2];
if (dp[i - 1][1] && s[i] != s[i - 1])
dp[i][1] = max(dp[i][1], 1 + dp[i - 1][1]);
dp[i][2] = 1 + dp[i - 2][1];
if (dp[i - 2][2] && !(s[i - 3] == s[i - 1] && s[i - 2] == s[i]))
dp[i][2] = max(dp[i][2], 1 + dp[i - 2][2]);
}
cout << max(dp[sz(s) - 1][1], dp[sz(s) - 1][2]);
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll) a.size()
#define pll pair<ll, ll>
#define rep(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define sep(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define mll map<ll, ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll dp[200005][2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
if (s.size() == 1) {
cout << 1 << "\n";
return 0;
}
dp[0][1] = 1;
dp[1][2] = 1;
if (s[1] != s[0])
dp[1][1] = 2;
rep(i, 2, sz(s)) {
if (dp[i - 1][2])
dp[i][1] = 1 + dp[i - 1][2];
if (dp[i - 1][1] && s[i] != s[i - 1])
dp[i][1] = max(dp[i][1], 1 + dp[i - 1][1]);
dp[i][2] = 1 + dp[i - 2][1];
if (dp[i - 2][2] && !(s[i - 3] == s[i - 1] && s[i - 2] == s[i]))
dp[i][2] = max(dp[i][2], 1 + dp[i - 2][2]);
}
cout << max(dp[sz(s) - 1][1], dp[sz(s) - 1][2]);
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p02939 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
const int inf = 1012345678;
int dp[100009][5];
int main() {
string s;
cin >> s;
int n = s.size();
for (int i = 0; i <= n; ++i) {
for (int j = 1; j <= 4; ++j) {
dp[i][j] = -inf;
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= 4 && j <= i; ++j) {
if (i == j)
dp[i][j] = 1;
for (int k = 1; k <= 4; ++k) {
if (dp[i - j][k] != -inf &&
s.substr(i - j - k, k) != s.substr(i - j, j)) {
dp[i][j] = max(dp[i][j], dp[i - j][k] + 1);
}
}
}
}
int ans = -inf;
for (int i = 1; i <= 4; ++i) {
ans = max(ans, dp[n][i]);
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
const int inf = 1012345678;
int dp[200009][5];
int main() {
string s;
cin >> s;
int n = s.size();
for (int i = 0; i <= n; ++i) {
for (int j = 1; j <= 4; ++j) {
dp[i][j] = -inf;
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= 4 && j <= i; ++j) {
if (i == j)
dp[i][j] = 1;
for (int k = 1; k <= 4; ++k) {
if (dp[i - j][k] != -inf &&
s.substr(i - j - k, k) != s.substr(i - j, j)) {
dp[i][j] = max(dp[i][j], dp[i - j][k] + 1);
}
}
}
}
int ans = -inf;
for (int i = 1; i <= 4; ++i) {
ans = max(ans, dp[n][i]);
}
cout << ans << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int n;
char s[N + 5];
int main() {
scanf("%s", s);
n = strlen(s);
vector<int> a;
int j = 0;
for (int i = 0; i < n; ++i) {
if (i && s[i] != s[i - 1])
a.push_back(j), j = 1;
else
++j;
}
a.push_back(j);
int ans = 0;
while (!a.empty()) {
int x = a.back();
a.pop_back();
if (x % 3 == 0)
ans += x / 3 * 2;
if (x % 3 == 1)
ans += x / 3 * 2 + 1;
if (x % 3 == 2) {
if (!a.empty())
a.back()--, ans += x / 3 * 2 + 2;
else
ans += x / 3 * 2 + 1;
}
}
printf("%d\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int n;
char s[N + 5];
int main() {
scanf("%s", s);
n = strlen(s);
vector<int> a;
int j = 0;
for (int i = 0; i < n; ++i) {
if (i && s[i] != s[i - 1])
a.push_back(j), j = 1;
else
++j;
}
a.push_back(j);
int ans = 0;
while (!a.empty()) {
int x = a.back();
a.pop_back();
if (x % 3 == 0)
ans += x / 3 * 2;
if (x % 3 == 1)
ans += x / 3 * 2 + 1;
if (x % 3 == 2) {
if (!a.empty())
a.back()--, ans += x / 3 * 2 + 2;
else
ans += x / 3 * 2 + 1;
}
}
printf("%d\n", ans);
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02939 | Python | Runtime Error | from sys import stdin
def main():
S = stdin.readline().rstrip()
S_len = len(S)
sum = 0
s = S[0]
x = 1
while True:
if len(s) == 1:
if s == S[x]:
s = s + S[x]
else:
sum += 1
s = S[x]
else:
sum += 2
x += 1
s = S[x]
x += 1
if x >= S_len:
sum += 1
break
print(sum)
if __name__ == "__main__":
main()
| from sys import stdin
def main():
S = stdin.readline().rstrip()
S_len = len(S)
sum = 0
s = S[0]
x = 1
while True:
if len(s) == 1:
if s == S[x]:
s = s + S[x]
else:
sum += 1
s = S[x]
else:
sum += 2
x += 1
if x >= S_len:
break
s = S[x]
x += 1
if x >= S_len:
sum += 1
break
print(sum)
if __name__ == "__main__":
main()
| insert | 21 | 21 | 21 | 24 | 0 | |
p02939 | Python | Runtime Error | # https://atcoder.jp/contests/agc037/tasks/agc037_a
s = input()
ans = 0
pre = s[0]
i = 0
while i < len(s):
cur = s[i]
if pre == cur:
pre = s[i] + s[i + 1]
i += 2
else:
pre = cur
i += 1
ans += 1
print(ans)
| # https://atcoder.jp/contests/agc037/tasks/agc037_a
s = input()
ans = 0
pre = ""
cur = ""
for i in range(len(s)):
pre += s[i]
if pre != cur:
ans += 1
cur = pre
pre = ""
print(ans)
| replace | 5 | 16 | 5 | 13 | 0 | |
p02939 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;
int dfs(string S, string s_pre, string s_post, int i) {
if (i == S.size()) {
return 0;
} else {
s_post.push_back(S[i]);
if (s_pre == s_post) {
return dfs(S, s_pre, s_post, i + 1);
} else {
s_pre = s_post;
s_post = {};
return dfs(S, s_pre, s_post, i + 1) + 1;
}
}
}
int main() {
string S;
cin >> S;
string s_pre, s_post;
int ans = dfs(S, s_pre, s_post, 0);
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;
int dfs(string &S, string &s_pre, string &s_post, int i) {
if (i == S.size()) {
return 0;
} else {
s_post.push_back(S[i]);
if (s_pre == s_post) {
return dfs(S, s_pre, s_post, i + 1);
} else {
s_pre = s_post;
s_post = {};
return dfs(S, s_pre, s_post, i + 1) + 1;
}
}
}
int main() {
string S;
cin >> S;
string s_pre, s_post;
int ans = dfs(S, s_pre, s_post, 0);
cout << ans << endl;
}
| replace | 8 | 9 | 8 | 9 | TLE | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);
string S;
int dp[220000][5];
int dfs(int idx, int n) {
if (idx + n == S.length())
return 1;
if (dp[idx][n] != -1)
return dp[idx][n];
int ret = 0;
for (int i = 1; i < 5; i++) {
if (idx + n + i > S.length())
continue;
if (S.substr(idx, n) == S.substr(idx + n, i))
continue;
ret = max(ret, dfs(idx + n, i) + 1);
}
return dp[idx][n] = ret;
}
signed main() {
cin >> S;
int ans = 0;
for (int i = 0; i < 220000; i++)
for (int j = 0; j < 11; j++)
dp[i][j] = -1;
for (int i = 1; i < 5; i++)
ans = max(ans, dfs(0, i));
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);
string S;
int dp[220000][5];
int dfs(int idx, int n) {
if (idx + n == S.length())
return 1;
if (dp[idx][n] != -1)
return dp[idx][n];
int ret = 0;
for (int i = 1; i < 5; i++) {
if (idx + n + i > S.length())
continue;
if (S.substr(idx, n) == S.substr(idx + n, i))
continue;
ret = max(ret, dfs(idx + n, i) + 1);
}
return dp[idx][n] = ret;
}
signed main() {
cin >> S;
int ans = 0;
for (int i = 0; i < 220000; i++)
for (int j = 0; j < 5; j++)
dp[i][j] = -1;
for (int i = 1; i < 5; i++)
ans = max(ans, dfs(0, i));
cout << ans << endl;
}
| replace | 35 | 36 | 35 | 36 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef pair<int, int> pii;
const int MN = 1e5 + 5;
int N, D[MN][2];
string S;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> S;
int N = S.size();
D[0][1] = 1;
D[0][2] = -1e9;
D[1][1] = -1e9;
if (S[0] != S[1])
D[1][1] = 2;
D[1][2] = 1;
for (int i = 2; i < N; i++) {
D[i][1] = D[i - 1][2] + 1;
if (S[i - 1] != S[i])
D[i][1] = max(D[i][1], D[i - 1][1] + 1);
D[i][2] = D[i - 2][1] + 1;
if (i >= 3 && (S[i - 2] != S[i] || S[i - 3] != S[i - 1]))
D[i][2] = max(D[i][2], D[i - 2][2] + 1);
}
cout << max(D[N - 1][1], D[N - 1][2]);
}
| #include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef pair<int, int> pii;
const int MN = 2e5 + 5;
int N, D[MN][2];
string S;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> S;
int N = S.size();
D[0][1] = 1;
D[0][2] = -1e9;
D[1][1] = -1e9;
if (S[0] != S[1])
D[1][1] = 2;
D[1][2] = 1;
for (int i = 2; i < N; i++) {
D[i][1] = D[i - 1][2] + 1;
if (S[i - 1] != S[i])
D[i][1] = max(D[i][1], D[i - 1][1] + 1);
D[i][2] = D[i - 2][1] + 1;
if (i >= 3 && (S[i - 2] != S[i] || S[i - 3] != S[i - 1]))
D[i][2] = max(D[i][2], D[i - 2][2] + 1);
}
cout << max(D[N - 1][1], D[N - 1][2]);
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long double ld;
typedef long long ll;
const int max_n = 100011, max_m = 500011, inf = 1000111222;
const ll inff = 1000111222333444;
int dp[2][max_n];
int n;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
string s;
cin >> s;
n = s.length();
int cnt = 0;
dp[0][0] = 1;
dp[1][1] = 1;
for (int i = 1; i < s.length(); ++i) {
if (s[i] != s[i - 1]) {
dp[0][i] = max(dp[0][i - 1], dp[1][i - 1]) + 1;
if (i > 1)
dp[1][i] = max(dp[1][i], max(dp[0][i - 2], dp[1][i - 2]) + 1);
} else {
dp[0][i] = dp[1][i - 1] + 1;
dp[1][i] = max(dp[0][i - 2], dp[1][i - 2]) + 1;
}
// cout << dp[0][i] << " " << dp[1][i] << endl;
}
cout << max(dp[0][n - 1], dp[1][n - 1]) << endl;
return 0;
}
| #include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long double ld;
typedef long long ll;
const int max_n = 200011, max_m = 500011, inf = 1000111222;
const ll inff = 1000111222333444;
int dp[2][max_n];
int n;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
string s;
cin >> s;
n = s.length();
int cnt = 0;
dp[0][0] = 1;
dp[1][1] = 1;
for (int i = 1; i < s.length(); ++i) {
if (s[i] != s[i - 1]) {
dp[0][i] = max(dp[0][i - 1], dp[1][i - 1]) + 1;
if (i > 1)
dp[1][i] = max(dp[1][i], max(dp[0][i - 2], dp[1][i - 2]) + 1);
} else {
dp[0][i] = dp[1][i - 1] + 1;
dp[1][i] = max(dp[0][i - 2], dp[1][i - 2]) + 1;
}
// cout << dp[0][i] << " " << dp[1][i] << endl;
}
cout << max(dp[0][n - 1], dp[1][n - 1]) << endl;
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
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;
}
const ll INF = 1LL << 60;
string s;
int dp[100005];
int main() {
cin >> s;
dp[0] = 1;
if (s[0] == s[1]) {
dp[1] = 1;
dp[2] = 2;
} else {
dp[1] = 2;
if (s[1] == s[2])
dp[2] = 2;
else
dp[2] = 3;
}
for (int i = 3; i <= s.size(); i++) {
if (s[i] != s[i - 1])
dp[i] = dp[i - 1] + 1;
else
dp[i] = dp[i - 3] + 2;
}
cout << dp[s.size() - 1] << "\n";
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
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;
}
const ll INF = 1LL << 60;
string s;
ll dp[1000010];
int main() {
cin >> s;
dp[0] = 1;
if (s[0] == s[1]) {
dp[1] = 1;
dp[2] = 2;
} else {
dp[1] = 2;
if (s[1] == s[2])
dp[2] = 2;
else
dp[2] = 3;
}
for (int i = 3; i <= s.size(); i++) {
if (s[i] != s[i - 1])
dp[i] = dp[i - 1] + 1;
else
dp[i] = dp[i - 3] + 2;
}
cout << dp[s.size() - 1] << "\n";
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02939 | C++ | Runtime Error | /**
* author: bholuakku
**/
#include <bits/stdc++.h>
#define Endl cout << "\n"
#define Test cout << "Hello\n"
using namespace std;
using ll = long long;
int main() {
#ifndef ONLINE_JUDGE
freopen("C:\\Users\\ACER\\Desktop\\Codes\\input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.size();
vector<int> A(n + 1, 0), B(n + 1, 0);
A[1] = 1;
s = " " + s;
for (int i = 2; i <= n; i++) {
// taking 1 section
int Max = 0;
Max = max(Max, 1 + B[i - 1]);
if (s[i] != s[i - 1])
Max = max(Max, 1 + A[i - 1]);
A[i] = Max;
// taking 2 section
Max = 0;
Max = max(Max, 1 + A[i - 2]);
// if(s[i]!=s[i-2]&&s[i-1]!=s[i-3])
B[i] = Max;
}
// for(int i = 1; i<=n; i++
cout << max(A[n], B[n]);
}
| /**
* author: bholuakku
**/
#include <bits/stdc++.h>
#define Endl cout << "\n"
#define Test cout << "Hello\n"
using namespace std;
using ll = long long;
int main() {
#ifndef ONLINE_JUDGE
// freopen("C:\\Users\\ACER\\Desktop\\Codes\\input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.size();
vector<int> A(n + 1, 0), B(n + 1, 0);
A[1] = 1;
s = " " + s;
for (int i = 2; i <= n; i++) {
// taking 1 section
int Max = 0;
Max = max(Max, 1 + B[i - 1]);
if (s[i] != s[i - 1])
Max = max(Max, 1 + A[i - 1]);
A[i] = Max;
// taking 2 section
Max = 0;
Max = max(Max, 1 + A[i - 2]);
// if(s[i]!=s[i-2]&&s[i-1]!=s[i-3])
B[i] = Max;
}
// for(int i = 1; i<=n; i++
cout << max(A[n], B[n]);
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02939 | C++ | Runtime Error | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define abdelrahman010 \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
string s;
vector<string> v;
int main() {
abdelrahman010 cin >> s;
string tmp = "";
tmp += s[0];
char c = '?';
for (int i = 1; i < s.size(); i++) {
if (c != s[i] && tmp.size() == 1 && s[i] == s[i - 1])
tmp += s[i], c = s[i];
else if (tmp == "" || tmp == v.back())
tmp += s[i], c = '?';
if (v.empty() || tmp != v.back()) {
v.push_back(tmp);
tmp = "";
}
}
cout << v.size();
return 0;
} | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define abdelrahman010 \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
string s;
vector<string> v;
int main() {
abdelrahman010 cin >> s;
string tmp = "";
for (int i = 0; i < s.size(); i++) {
tmp += s[i];
if (v.empty() || tmp != v.back()) {
v.push_back(tmp);
tmp = "";
}
}
cout << v.size();
return 0;
} | replace | 14 | 21 | 14 | 16 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
template <typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
class Prints {
private:
class __Prints {
public:
__Prints(const char *sep, const char *term) : sep(sep), term(term) {}
template <class... Args> void operator()(const Args &...args) const {
print(args...);
}
private:
const char *sep, *term;
void print() const { std::cout << term; }
void print_rest() const { std::cout << term; }
template <class T, class... Tail>
void print(const T &head, const Tail &...tail) const {
std::cout << head, print_rest(tail...);
}
template <class T, class... Tail>
void print_rest(const T &head, const Tail &...tail) const {
std::cout << sep << head, print_rest(tail...);
}
};
public:
Prints() {}
__Prints operator()(const char *sep = " ", const char *term = "\n") const {
return __Prints(sep, term);
}
};
Prints prints;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ll dp[100010][2];
void solve() {
string S;
cin >> S;
ll n = (ll)S.size();
for (ll i = 0; i < n; i++) {
if (i - 1 >= 0 && S[i] != S[i - 1]) {
chmax(dp[i + 1][0], dp[i][0] + 1);
}
chmax(dp[i + 1][0], dp[i][1] + 1);
if (i - 2 >= 0) {
chmax(dp[i + 1][1], dp[i - 1][0] + 1);
chmax(dp[i + 1][1], dp[i - 1][1] + 1);
}
}
prints()(max(dp[n][0], dp[n][1]));
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int main() {
#ifdef FASTIO
cin.tie(nullptr), cout.tie(nullptr);
ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
ifstream ifs("./in_out/input.txt");
cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
ofstream ofs("./in_out/output.txt");
cout.rdbuf(ofs.rdbuf());
#endif
cout << setprecision(18) << fixed;
solve();
cout << flush;
return 0;
} | #include <bits/stdc++.h>
#define FASTIO
using namespace std;
using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();
template <typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
class Prints {
private:
class __Prints {
public:
__Prints(const char *sep, const char *term) : sep(sep), term(term) {}
template <class... Args> void operator()(const Args &...args) const {
print(args...);
}
private:
const char *sep, *term;
void print() const { std::cout << term; }
void print_rest() const { std::cout << term; }
template <class T, class... Tail>
void print(const T &head, const Tail &...tail) const {
std::cout << head, print_rest(tail...);
}
template <class T, class... Tail>
void print_rest(const T &head, const Tail &...tail) const {
std::cout << sep << head, print_rest(tail...);
}
};
public:
Prints() {}
__Prints operator()(const char *sep = " ", const char *term = "\n") const {
return __Prints(sep, term);
}
};
Prints prints;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ll dp[200010][2];
void solve() {
string S;
cin >> S;
ll n = (ll)S.size();
for (ll i = 0; i < n; i++) {
if (i - 1 >= 0 && S[i] != S[i - 1]) {
chmax(dp[i + 1][0], dp[i][0] + 1);
}
chmax(dp[i + 1][0], dp[i][1] + 1);
if (i - 2 >= 0) {
chmax(dp[i + 1][1], dp[i - 1][0] + 1);
chmax(dp[i + 1][1], dp[i - 1][1] + 1);
}
}
prints()(max(dp[n][0], dp[n][1]));
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int main() {
#ifdef FASTIO
cin.tie(nullptr), cout.tie(nullptr);
ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
ifstream ifs("./in_out/input.txt");
cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
ofstream ofs("./in_out/output.txt");
cout.rdbuf(ofs.rdbuf());
#endif
cout << setprecision(18) << fixed;
solve();
cout << flush;
return 0;
} | replace | 62 | 63 | 62 | 63 | 0 | |
p02939 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
char s[100005] = {};
scanf("%s", s);
int len = strlen(s);
int rem = 0;
int flag = 0;
for (int i = 0; i < len; i++) {
// printf("###%d\n",i);
if (i >= 1) {
if (s[i] == s[i - 1] && flag == 0) {
rem++;
flag = 1;
i++;
} else {
flag = 0;
}
}
}
printf("%d\n", len - rem);
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
char s[200005] = {};
scanf("%s", s);
int len = strlen(s);
int rem = 0;
int flag = 0;
for (int i = 0; i < len; i++) {
// printf("###%d\n",i);
if (i >= 1) {
if (s[i] == s[i - 1] && flag == 0) {
rem++;
flag = 1;
i++;
} else {
flag = 0;
}
}
}
printf("%d\n", len - rem);
return 0;
} | replace | 21 | 22 | 21 | 22 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = a; i > n; i--)
#define leng(n) (int)(log10(n) + 1)
#define INF 9000000000000000000
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } // 最大公約数gcd
int lcm(int a, int b) { return a / gcd(a, b) * b; } // 最小公倍数lcm
signed main() {
string s;
cin >> s;
int ans = 0;
int same = 1;
vector<int> sa(0);
rep(i, 0, s.size() - 1) {
if (s[i] == s[i + 1]) {
same++;
continue;
}
if (s[i] != s[i + 1]) {
if (same % 3 != 0)
sa.pb(same % 3);
if (same % 3 == 0)
ans += 2 * (same / 3);
else
ans += (2 * (same / 3) + 1);
same = 1;
}
}
if (same % 3 != 0)
sa.pb(same % 3);
if (same % 3 == 0)
ans += 2 * (same / 3);
else
ans += (2 * (same / 3) + 1);
rep(i, 0, sa.size() - 1) {
if (sa[i] == 2 && sa[i + 1] == 2) {
ans++;
sa[i] = 1;
sa[i + 1] = 1;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = a; i > n; i--)
#define leng(n) (int)(log10(n) + 1)
#define INF 9000000000000000000
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } // 最大公約数gcd
int lcm(int a, int b) { return a / gcd(a, b) * b; } // 最小公倍数lcm
signed main() {
string s;
cin >> s;
int ans = 0;
int same = 1;
vector<int> sa(0);
rep(i, 0, s.size() - 1) {
if (s[i] == s[i + 1]) {
same++;
continue;
}
if (s[i] != s[i + 1]) {
if (same % 3 != 0)
sa.pb(same % 3);
if (same % 3 == 0)
ans += 2 * (same / 3);
else
ans += (2 * (same / 3) + 1);
same = 1;
}
}
if (same % 3 != 0)
sa.pb(same % 3);
if (same % 3 == 0)
ans += 2 * (same / 3);
else
ans += (2 * (same / 3) + 1);
if (sa.size() != 0) {
rep(i, 0, sa.size() - 1) {
if (sa[i] == 2 && sa[i + 1] == 2) {
ans++;
sa[i] = 1;
sa[i + 1] = 1;
}
}
}
cout << ans << endl;
}
| replace | 40 | 45 | 40 | 47 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize("O3")
// #pragma GCC target("sse4")
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i >= (a); --i)
#define ITER(it, a) \
for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;
const int MAX = 1 << 17;
const int K = 4;
int dp[MAX][K];
void upd(int &x, int val) { x = max(x, val); }
int main() {
// ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
string s;
cin >> s;
int n = SZ(s);
FOR(i, 0, MAX)
FOR(j, 0, K)
dp[i][j] = -INF;
FOR(i, 0, K)
dp[i][i] = 1;
FOR(i, 0, n)
FOR(j, 0, K) {
if (dp[i][j] >= 0 && i + j + 1 < n) {
bool ok = false;
FOR(k, i - j, i + 1)
ok |= s[k] != s[k + j + 1];
if (ok)
upd(dp[i + j + 1][j], dp[i][j] + 1);
}
FOR(k, 0, K)
if (k != j && i + k + 1 < n)
upd(dp[i + k + 1][k], dp[i][j] + 1);
}
int ans = 0;
FOR(i, 0, K)
upd(ans, dp[n - 1][i]);
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize("O3")
// #pragma GCC target("sse4")
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i >= (a); --i)
#define ITER(it, a) \
for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;
const int MAX = 1 << 18;
const int K = 4;
int dp[MAX][K];
void upd(int &x, int val) { x = max(x, val); }
int main() {
// ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
string s;
cin >> s;
int n = SZ(s);
FOR(i, 0, MAX)
FOR(j, 0, K)
dp[i][j] = -INF;
FOR(i, 0, K)
dp[i][i] = 1;
FOR(i, 0, n)
FOR(j, 0, K) {
if (dp[i][j] >= 0 && i + j + 1 < n) {
bool ok = false;
FOR(k, i - j, i + 1)
ok |= s[k] != s[k + j + 1];
if (ok)
upd(dp[i + j + 1][j], dp[i][j] + 1);
}
FOR(k, 0, K)
if (k != j && i + k + 1 < n)
upd(dp[i + k + 1][k], dp[i][j] + 1);
}
int ans = 0;
FOR(i, 0, K)
upd(ans, dp[n - 1][i]);
cout << ans;
return 0;
}
| replace | 24 | 25 | 24 | 25 | 0 | |
p02939 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
long long int cnt = 1;
char cur = s[0];
int i = 1;
while (1) {
if (s[i] != cur) {
cur = s[i];
cnt++;
i++;
if (i == s.length()) {
break;
}
} else {
if (i == s.length() - 1) {
break;
} else if (i == s.length() - 2) {
cnt++;
break;
} else {
cur = s[i + 2];
i += 3;
cnt += 2;
}
}
}
cout << cnt << endl;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
long long int cnt = 1;
char cur = s[0];
int i = 1;
while (1) {
if (s[i] != cur) {
cur = s[i];
cnt++;
i++;
if (i == s.length()) {
break;
}
} else {
if (i == s.length() - 1) {
break;
} else if (i == s.length() - 2) {
cnt++;
break;
} else {
cur = s[i + 2];
i += 3;
cnt += 2;
if (i == s.length()) {
break;
}
}
}
}
cout << cnt << endl;
} | insert | 34 | 34 | 34 | 37 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
int main() {
string s;
cin >> s;
int ret = 0;
if (s.size() == 1) {
ret = 1;
} else if (s.size() == 2 && s[0] == s[1]) {
ret = 1;
} else if (s.size() == 2 && s[0] != s[1]) {
ret = 2;
} else {
string bef = "";
while (true) {
if (s.size() == 3) {
if (bef == s.substr(0, 1))
return 2; // bef is 1 char: ab-c
if (bef != s.substr(0, 1) && s[0] != s[1] && s[1] != s[2]) {
ret += 3;
break;
} // a-b-c or a-b-a
ret += 2;
break;
}
if (s.size() == 2) {
if (bef != s.substr(0, 1) && s[0] != s[1]) {
ret += 2;
break;
} else {
ret += 1;
break;
}
}
int i = 1;
while (s.substr(0, i) == bef)
i++;
bef = s.substr(0, i);
s = s.substr(i, s.size() - i);
++ret;
}
}
cout << ret << endl;
return 0;
} | #include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
int main() {
string s;
cin >> s;
int ret = 0;
if (s.size() == 1) {
ret = 1;
} else if (s.size() == 2 && s[0] == s[1]) {
ret = 1;
} else if (s.size() == 2 && s[0] != s[1]) {
ret = 2;
} else {
string bef = "";
while (true) {
if (s.size() == 3) {
if (bef == s.substr(0, 1)) {
ret += 2;
break;
}; // bef is 1 char: ab-c
if (bef != s.substr(0, 1) && s[0] != s[1] && s[1] != s[2]) {
ret += 3;
break;
} // a-b-c or a-b-a
ret += 2;
break;
}
if (s.size() == 2) {
if (bef != s.substr(0, 1) && s[0] != s[1]) {
ret += 2;
break;
} else {
ret += 1;
break;
}
}
int i = 1;
while (s.substr(0, i) == bef)
i++;
bef = s.substr(0, i);
s = s.substr(i, s.size() - i);
++ret;
}
}
cout << ret << endl;
return 0;
} | replace | 18 | 20 | 18 | 22 | 0 | |
p02939 | C++ | Runtime Error | /**
* Name: Ajay
* Institute: IIITH
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
#define ll long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<ppi>
#define vll vector<ll>
#define mp make_pair
#define fi first
#define se second
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void input() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
fastio();
input();
string s;
cin >> s;
int n, i, k = 0;
n = s.size();
string temp = "", prev = "";
for (i = 0; i < n; i++) {
if (temp + s[i] != prev) {
prev = temp + s[i];
k++;
temp = "";
} else
temp += s[i];
}
if (temp.size() > 0 && temp != prev)
k++;
cout << k;
return 0;
} | /**
* Name: Ajay
* Institute: IIITH
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
#define ll long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<ppi>
#define vll vector<ll>
#define mp make_pair
#define fi first
#define se second
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void input() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
fastio();
string s;
cin >> s;
int n, i, k = 0;
n = s.size();
string temp = "", prev = "";
for (i = 0; i < n; i++) {
if (temp + s[i] != prev) {
prev = temp + s[i];
k++;
temp = "";
} else
temp += s[i];
}
if (temp.size() > 0 && temp != prev)
k++;
cout << k;
return 0;
} | delete | 46 | 47 | 46 | 46 | 0 | |
p02939 | C++ | Runtime Error | #include <cstdio>
#include <cstring>
int len, ans;
char S[100100];
int main() {
scanf("%s", S + 1);
len = strlen(S + 1);
int now = 1;
while (now <= len) {
ans++, now++;
while (S[now] != S[now - 1] && now <= len)
ans++, now++;
if (now >= len)
break;
ans++, now += 2;
}
printf("%d\n", ans);
} | #include <cstdio>
#include <cstring>
int len, ans;
char S[200100];
int main() {
scanf("%s", S + 1);
len = strlen(S + 1);
int now = 1;
while (now <= len) {
ans++, now++;
while (S[now] != S[now - 1] && now <= len)
ans++, now++;
if (now >= len)
break;
ans++, now += 2;
}
printf("%d\n", ans);
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define pr(...) \
cerr << GET_MACRO(__VA_ARGS__, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define prArr(a) \
{ \
cerr << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
cerr << (i++ ? ", " : "") << t; \
cerr << "}" << endl; \
}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int mod = (1e9) + 7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
for (T t : a)
o << (i++ ? " " : "") << t;
return o;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
// INSERT ABOVE HERE
_int used[2][200010], mem[2][200010];
const Int INF = 1e9; // ~ 1.15 * 1e18
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
string str;
cin >> str;
Int N = str.size();
const Int null = 29;
function<Int(Int, Int)> dfs = [&](Int len, Int idx) {
if (idx == N)
return 0;
if (used[len][idx]++)
return mem[len][idx];
Int a = -INF, b = -INF;
char p1 = len == 2 ? str[idx - 2] - 'a' : 29;
char p2 = idx > 0 ? str[idx - 1] - 'a' : 29;
if (idx + 1 <= N) {
Int ch1 = null;
Int ch2 = str[idx] - 'a';
if (p1 != ch1 || p2 != ch2)
a = dfs(1, idx + 1) + 1;
}
if (idx + 2 <= N) {
Int ch1 = str[idx] - 'a';
Int ch2 = str[idx + 1] - 'a';
if (p1 != ch1 || p2 != ch2)
b = dfs(2, idx + 2) + 1;
}
Int res = max(a, b);
return mem[len][idx] = res;
};
Int ans = dfs(0, 0);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME
#define pr(...) \
cerr << GET_MACRO(__VA_ARGS__, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define prArr(a) \
{ \
cerr << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
cerr << (i++ ? ", " : "") << t; \
cerr << "}" << endl; \
}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int mod = (1e9) + 7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
for (T t : a)
o << (i++ ? " " : "") << t;
return o;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
// INSERT ABOVE HERE
_int used[3][200010], mem[3][200010];
const Int INF = 1e9; // ~ 1.15 * 1e18
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
string str;
cin >> str;
Int N = str.size();
const Int null = 29;
function<Int(Int, Int)> dfs = [&](Int len, Int idx) {
if (idx == N)
return 0;
if (used[len][idx]++)
return mem[len][idx];
Int a = -INF, b = -INF;
char p1 = len == 2 ? str[idx - 2] - 'a' : 29;
char p2 = idx > 0 ? str[idx - 1] - 'a' : 29;
if (idx + 1 <= N) {
Int ch1 = null;
Int ch2 = str[idx] - 'a';
if (p1 != ch1 || p2 != ch2)
a = dfs(1, idx + 1) + 1;
}
if (idx + 2 <= N) {
Int ch1 = str[idx] - 'a';
Int ch2 = str[idx + 1] - 'a';
if (p1 != ch1 || p2 != ch2)
b = dfs(2, idx + 2) + 1;
}
Int res = max(a, b);
return mem[len][idx] = res;
};
Int ans = dfs(0, 0);
cout << ans << endl;
return 0;
}
| replace | 56 | 57 | 56 | 57 | 0 | |
p02939 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
cout << setprecision(15);
char s[2000000];
scanf("%s", s);
int ans = 0;
const int n = strlen(s);
for (int length = 1; length < n; ++length) {
if (n - length <= ans)
break;
int prev_length = length;
int count = 1;
for (int j = length; j < n;) {
if (prev_length == 1 && s[j] == s[j - 1]) {
if (j > n - 2)
break;
j += 2;
prev_length = 2;
count++;
continue;
}
prev_length = 1;
j++;
count++;
}
ans = max(ans, count);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
cout << setprecision(15);
char s[2000000];
scanf("%s", s);
int ans = 0;
const int n = strlen(s);
for (int length = 1; length <= 2; ++length) {
if (n - length <= ans)
break;
int prev_length = length;
int count = 1;
for (int j = length; j < n;) {
if (prev_length == 1 && s[j] == s[j - 1]) {
if (j > n - 2)
break;
j += 2;
prev_length = 2;
count++;
continue;
}
prev_length = 1;
j++;
count++;
}
ans = max(ans, count);
}
cout << ans << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | TLE | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#if !ONLINE_JUDGE
#define debug
#endif
using namespace std;
/******* All Required define Pre-Processors and typedef Constants *******/
#define mem(a, b) memset(a, (b), sizeof(a))
#define repd(i, k) for (int i = k; i >= 0; i--)
#define rep(i, k) for (int i = 0; i < k; i++)
#define repn(i, k1, k2) for (ll i = k1; i < k2; i++)
#define sz(x) (ll)(x).size()
#define ff first
#define ss second
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ee6 (ll)1000001
#define ee5 (ll)100001
#define trav(a, v) for (auto &a : v)
#define tt \
ll t; \
cin >> t; \
while (t--)
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pr> vpr;
typedef vector<vpr> vvpr;
typedef vector<vi> vvi;
//*X.find_by_order(2) element at index=2
// X.order_of_key(1) how many elements strictly less than 1
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef debug
#define dbg(...) \
{ \
cerr << "[ "; \
dump(#__VA_ARGS__, __VA_ARGS__); \
}
#undef endl
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const pair<Arg1, Arg2> &x) {
return out << "(" << x.ff << "," << x.ss << ")";
}
template <typename Arg1>
ostream &operator<<(ostream &out, const vector<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> ostream &operator<<(ostream &out, const set<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const map<Arg1, Arg2> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const unordered_map<Arg1, Arg2> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> void dump(const string name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << " ] " << endl;
}
template <typename Arg1, typename... Args>
void dump(const string names, Arg1 &&arg1, Args &&...args) {
const string name = names.substr(0, names.find(','));
cerr << name << " : " << arg1 << " | ";
dump(names.substr(1 + (int)name.size()), args...);
}
#else
#define dbg(args...)
#endif
ll powmod(ll x, ll y) {
ll res = 1;
x = x % MOD;
while (y > 0) {
if (y & 1)
res = (res * x) % MOD;
y = y >> 1; // y = y/2
x = (x * x) % MOD;
}
return res;
}
int main() {
// #if !ONLINE_JUDGE
freopen("in.txt", "r", stdin);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.size();
int ans = 0;
string prev = "", temp = "";
int cnt = 0;
for (int i = 0; i < n; i++) {
temp = temp + s[i];
if (temp == prev)
continue;
else {
prev = temp;
temp.clear();
cnt++; /*cout<<prev<<" ";*/
}
}
cout << cnt;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#if !ONLINE_JUDGE
#define debug
#endif
using namespace std;
/******* All Required define Pre-Processors and typedef Constants *******/
#define mem(a, b) memset(a, (b), sizeof(a))
#define repd(i, k) for (int i = k; i >= 0; i--)
#define rep(i, k) for (int i = 0; i < k; i++)
#define repn(i, k1, k2) for (ll i = k1; i < k2; i++)
#define sz(x) (ll)(x).size()
#define ff first
#define ss second
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ee6 (ll)1000001
#define ee5 (ll)100001
#define trav(a, v) for (auto &a : v)
#define tt \
ll t; \
cin >> t; \
while (t--)
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pr> vpr;
typedef vector<vpr> vvpr;
typedef vector<vi> vvi;
//*X.find_by_order(2) element at index=2
// X.order_of_key(1) how many elements strictly less than 1
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef debug
#define dbg(...) \
{ \
cerr << "[ "; \
dump(#__VA_ARGS__, __VA_ARGS__); \
}
#undef endl
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const pair<Arg1, Arg2> &x) {
return out << "(" << x.ff << "," << x.ss << ")";
}
template <typename Arg1>
ostream &operator<<(ostream &out, const vector<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> ostream &operator<<(ostream &out, const set<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const map<Arg1, Arg2> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const unordered_map<Arg1, Arg2> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> void dump(const string name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << " ] " << endl;
}
template <typename Arg1, typename... Args>
void dump(const string names, Arg1 &&arg1, Args &&...args) {
const string name = names.substr(0, names.find(','));
cerr << name << " : " << arg1 << " | ";
dump(names.substr(1 + (int)name.size()), args...);
}
#else
#define dbg(args...)
#endif
ll powmod(ll x, ll y) {
ll res = 1;
x = x % MOD;
while (y > 0) {
if (y & 1)
res = (res * x) % MOD;
y = y >> 1; // y = y/2
x = (x * x) % MOD;
}
return res;
}
int main() {
// #if !ONLINE_JUDGE
// freopen("in.txt","r",stdin);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.size();
int ans = 0;
string prev = "", temp = "";
int cnt = 0;
for (int i = 0; i < n; i++) {
temp = temp + s[i];
if (temp == prev)
continue;
else {
prev = temp;
temp.clear();
cnt++; /*cout<<prev<<" ";*/
}
}
cout << cnt;
} | replace | 127 | 128 | 127 | 128 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
string s;
void Process() {
int i = 0, cou = 0, state = 0;
while (i <= s.length() - 1) {
if (s[i] == s[i + 1]) {
if (state == 0) {
i += 2;
state = 1;
} else {
state = 0;
i++;
}
} else {
i++;
state = 0;
}
// cout << i << " ";
cou++;
}
// cout << endl;
cout << cou;
}
void Input() {
ios_base::sync_with_stdio(0);
cin.tie(0);
freopen("abc.txt", "r", stdin);
cin >> s;
}
int main() {
Input();
Process();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
string s;
void Process() {
int i = 0, cou = 0, state = 0;
while (i <= s.length() - 1) {
if (s[i] == s[i + 1]) {
if (state == 0) {
i += 2;
state = 1;
} else {
state = 0;
i++;
}
} else {
i++;
state = 0;
}
// cout << i << " ";
cou++;
}
// cout << endl;
cout << cou;
}
void Input() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("abc.txt", "r", stdin);
cin >> s;
}
int main() {
Input();
Process();
return 0;
}
| replace | 36 | 37 | 36 | 37 | -11 | |
p02939 | C++ | Time Limit Exceeded | // #pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back
const int N = 2e5 + 5;
const int M = 17 + 5;
const int W = 1000 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;
string s;
map<pair<int, string>, int> dp, vis;
int solve(int idx, string x) {
if (idx == s.size())
return 0;
int &ret = dp[mp(idx, x)];
if (vis[mp(idx, x)])
return ret;
ret = -OO;
string c;
c += s[idx];
if (x != c)
ret = max(ret, 1 + solve(idx + 1, c));
if (idx < s.size() - 1) {
c += s[idx + 1];
if (x != c)
ret = max(ret, 1 + solve(idx + 2, c));
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> s;
cout << solve(0, "") << '\n';
return 0;
} | // #pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back
const int N = 2e5 + 5;
const int M = 17 + 5;
const int W = 1000 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;
string s;
map<pair<int, string>, int> dp, vis;
int solve(int idx, string x) {
if (idx == s.size())
return 0;
int &ret = dp[mp(idx, x)];
if (vis[mp(idx, x)])
return ret;
vis[mp(idx, x)] = 1;
ret = -OO;
string c;
c += s[idx];
if (x != c)
ret = max(ret, 1 + solve(idx + 1, c));
if (idx < s.size() - 1) {
c += s[idx + 1];
if (x != c)
ret = max(ret, 1 + solve(idx + 2, c));
}
return ret;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> s;
cout << solve(0, "") << '\n';
return 0;
} | insert | 31 | 31 | 31 | 33 | TLE | |
p02939 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ALL(x) begin(x), end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> inline bool chmax(T &a, const T &b) {
return b > a ? a = b, true : false;
}
template <class T> inline bool chmin(T &a, const T &b) {
return b < a ? a = b, true : false;
}
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) {
sort(begin(v), end(v), f);
v.resize(unique(begin(v), end(v)) - begin(v));
}
const int N = 2e5 + 5;
string s;
int dp[N];
int solve(int i, int prv) {
if (i >= s.size())
return 0;
if (dp[i])
return dp[i];
int res = 0;
for (int j = i; j < s.size(); j++) {
if (s.substr(prv, i - prv) == s.substr(i, j - i + 1))
continue;
chmax(res, solve(j + 1, i) + 1);
}
return dp[i] = res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s;
cout << solve(0, 0) << '\n';
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ALL(x) begin(x), end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> inline bool chmax(T &a, const T &b) {
return b > a ? a = b, true : false;
}
template <class T> inline bool chmin(T &a, const T &b) {
return b < a ? a = b, true : false;
}
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) {
sort(begin(v), end(v), f);
v.resize(unique(begin(v), end(v)) - begin(v));
}
const int N = 2e5 + 5;
string s;
int dp[N];
int solve(int i, int prv) {
if (i >= s.size())
return 0;
if (dp[i])
return dp[i];
int res = 0;
for (int j = i; j <= min(i + 2, (int)s.size()); j++) {
if (s.substr(prv, i - prv) == s.substr(i, j - i + 1))
continue;
chmax(res, solve(j + 1, i) + 1);
}
return dp[i] = res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> s;
cout << solve(0, 0) << '\n';
return 0;
}
| replace | 31 | 32 | 31 | 32 | TLE | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
#define gc getchar //_unlocked
#define pc putchar //_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int, int>
#define ppl pair<ll, ll>
#define bigint boost::multiprecision::cpp_int
#define finp \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define bc __builtin_popcountll
#define afor(i, a, b) for (int i = a; i <= b; ++i)
#define bfor(i, a, b) for (int i = a; i >= b; --i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>
#define fr first
#define se second
using namespace std;
using namespace __gnu_pbds;
char putnb[20];
void putn(ll n) {
if (!n)
pc('0');
if (n < 0)
pc('-'), n = 0 - n;
int pi = 0;
while (n)
putnb[pi++] = (n % 10) + '0', n /= 10;
while (pi)
pc(putnb[--pi]);
}
void sci(int *x) {
register char c = gc();
*x = 0;
for (; (c < 48) || (c > 57); c = gc())
;
for (; (c > 47) && (c < 58); c = gc())
*x = (int)((((*x) << 1) + ((*x) << 3)) + c - 48);
}
void scll(ll *x) {
register char c = gc();
*x = 0;
for (; (c < 48) || (c > 57); c = gc())
;
for (; (c > 47) && (c < 58); c = gc())
*x = (ll)((((*x) << 1) + ((*x) << 3)) + c - 48);
}
ll fp(ll a, ll b, ll c) {
if (b == 0)
return 1 % c;
if (b == 1)
return a % c;
ll ret = fp(a, b / 2, c);
ret = (ret * ret) % c;
if (b & 1)
ret = (ret * a) % c;
return ret;
}
const ll mod = 1e9 + 7;
const ll mod2 = 1999999973;
const ll inf = 1e18;
const int infs = 1e9 + 1000;
const int N = 100000;
const long double PI = acos(-1);
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int dp[3][N + 5];
int main() {
finp;
string s;
cin >> s;
int n = s.length();
dp[1][1] = 1;
afor(i, 2, n) {
dp[1][i] = 1 + dp[2][i - 1];
if (s[i - 1] != s[i - 2])
dp[1][i] = max(dp[1][i], 1 + dp[1][i - 1]);
if (i == 2)
dp[2][i] = 1;
else {
dp[2][i] = dp[1][i - 2] + 1;
if (i >= 4) {
if (s[i - 3] != s[i - 1] || s[i - 4] != s[i - 2]) {
dp[2][i] = max(dp[2][i], dp[2][i - 2] + 1);
}
}
}
}
cout << max(dp[1][n], dp[2][n]);
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
#define gc getchar //_unlocked
#define pc putchar //_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int, int>
#define ppl pair<ll, ll>
#define bigint boost::multiprecision::cpp_int
#define finp \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define bc __builtin_popcountll
#define afor(i, a, b) for (int i = a; i <= b; ++i)
#define bfor(i, a, b) for (int i = a; i >= b; --i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>
#define fr first
#define se second
using namespace std;
using namespace __gnu_pbds;
char putnb[20];
void putn(ll n) {
if (!n)
pc('0');
if (n < 0)
pc('-'), n = 0 - n;
int pi = 0;
while (n)
putnb[pi++] = (n % 10) + '0', n /= 10;
while (pi)
pc(putnb[--pi]);
}
void sci(int *x) {
register char c = gc();
*x = 0;
for (; (c < 48) || (c > 57); c = gc())
;
for (; (c > 47) && (c < 58); c = gc())
*x = (int)((((*x) << 1) + ((*x) << 3)) + c - 48);
}
void scll(ll *x) {
register char c = gc();
*x = 0;
for (; (c < 48) || (c > 57); c = gc())
;
for (; (c > 47) && (c < 58); c = gc())
*x = (ll)((((*x) << 1) + ((*x) << 3)) + c - 48);
}
ll fp(ll a, ll b, ll c) {
if (b == 0)
return 1 % c;
if (b == 1)
return a % c;
ll ret = fp(a, b / 2, c);
ret = (ret * ret) % c;
if (b & 1)
ret = (ret * a) % c;
return ret;
}
const ll mod = 1e9 + 7;
const ll mod2 = 1999999973;
const ll inf = 1e18;
const int infs = 1e9 + 1000;
const int N = 200000;
const long double PI = acos(-1);
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int dp[3][N + 5];
int main() {
finp;
string s;
cin >> s;
int n = s.length();
dp[1][1] = 1;
afor(i, 2, n) {
dp[1][i] = 1 + dp[2][i - 1];
if (s[i - 1] != s[i - 2])
dp[1][i] = max(dp[1][i], 1 + dp[1][i - 1]);
if (i == 2)
dp[2][i] = 1;
else {
dp[2][i] = dp[1][i - 2] + 1;
if (i >= 4) {
if (s[i - 3] != s[i - 1] || s[i - 4] != s[i - 2]) {
dp[2][i] = max(dp[2][i], dp[2][i - 2] + 1);
}
}
}
}
cout << max(dp[1][n], dp[2][n]);
return 0;
} | replace | 73 | 74 | 73 | 74 | 0 | |
p02939 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG
#include "cpp-pyprint/pyprint.h"
#endif
int dp[100005][2];
void Main() {
string s;
cin >> s;
int n = s.size();
if (n == 1) {
cout << 1 << endl;
return;
} else {
if (s[0] == s[1]) {
dp[0][0] = 1;
dp[0][1] = 0;
dp[1][0] = 1;
dp[1][1] = 1;
} else {
dp[0][0] = 1;
dp[0][1] = 0;
dp[1][0] = 2;
dp[1][1] = 1;
}
}
rep2(i, 2, n) {
if (s[i] == s[i - 1]) {
dp[i][0] += dp[i - 1][1] + 1;
dp[i][1] += dp[i - 2][0] + 1;
} else {
dp[i][0] += dp[i - 1][0] + 1;
dp[i][1] += dp[i - 2][0] + 1;
}
}
cout << max(dp[n - 1][0], dp[n - 1][1]) << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG
#include "cpp-pyprint/pyprint.h"
#endif
int dp[200005][2];
void Main() {
string s;
cin >> s;
int n = s.size();
if (n == 1) {
cout << 1 << endl;
return;
} else {
if (s[0] == s[1]) {
dp[0][0] = 1;
dp[0][1] = 0;
dp[1][0] = 1;
dp[1][1] = 1;
} else {
dp[0][0] = 1;
dp[0][1] = 0;
dp[1][0] = 2;
dp[1][1] = 1;
}
}
rep2(i, 2, n) {
if (s[i] == s[i - 1]) {
dp[i][0] += dp[i - 1][1] + 1;
dp[i][1] += dp[i - 2][0] + 1;
} else {
dp[i][0] += dp[i - 1][0] + 1;
dp[i][1] += dp[i - 2][0] + 1;
}
}
cout << max(dp[n - 1][0], dp[n - 1][1]) << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p02940 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define zerol
using LL = long long;
#define FOR(i, x, y) \
for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) \
for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) \
do { \
cout << "\033[32;1m" << #x << " -> "; \
err(x); \
} while (0)
void err() { cout << "\033[39;0m" << endl; }
template <template <typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
for (auto v : a)
cout << v << ' ';
err(x...);
}
template <typename T, typename... A> void err(T a, A... x) {
cout << a << ' ';
err(x...);
}
#else
#define dbg(...)
#endif
//--------------------------------------------------------------------------------------------
const int MAXN = 1e5 + 5;
const LL MOD = 998244353;
typedef vector<int> vi;
vi r, g, b, low, mid, high;
char s[MAXN];
int n, len;
int main(int argc, char const *argv[]) {
scanf("%d%s", &n, s);
// printf("%d %s\n", n, s);
len = n * 3;
// dbg(n, len);
for (int i = 0; i < len; ++i) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else if (s[i] == 'B')
b.push_back(i);
}
low.resize(n);
high.resize(n);
mid.resize(n);
for (int i = 0; i < n; ++i) {
vi tmp = {r[i], g[i], b[i]};
sort(tmp.begin(), tmp.end());
low[i] = tmp[0];
mid[i] = tmp[1];
high[i] = tmp[2];
}
LL ans = 1;
for (int i = 1; i <= n; ++i)
ans = ans * i % MOD;
int j = 0;
for (int i = 0; i < n; ++i) {
while (j + 1 < n && low[j + 1] <= mid[i])
++j;
ans = ans * (j - i + 1) % MOD;
}
j = 0;
for (int i = 0; i < n; ++i) {
while (j + 1 < n && mid[j + 1] <= high[i])
++j;
ans = ans * (j - i + 1) % MOD;
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define zerol
using LL = long long;
#define FOR(i, x, y) \
for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) \
for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) \
do { \
cout << "\033[32;1m" << #x << " -> "; \
err(x); \
} while (0)
void err() { cout << "\033[39;0m" << endl; }
template <template <typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
for (auto v : a)
cout << v << ' ';
err(x...);
}
template <typename T, typename... A> void err(T a, A... x) {
cout << a << ' ';
err(x...);
}
#else
#define dbg(...)
#endif
//--------------------------------------------------------------------------------------------
const int MAXN = 3e5 + 5;
const LL MOD = 998244353;
typedef vector<int> vi;
vi r, g, b, low, mid, high;
char s[MAXN];
int n, len;
int main(int argc, char const *argv[]) {
scanf("%d%s", &n, s);
// printf("%d %s\n", n, s);
len = n * 3;
// dbg(n, len);
for (int i = 0; i < len; ++i) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else if (s[i] == 'B')
b.push_back(i);
}
low.resize(n);
high.resize(n);
mid.resize(n);
for (int i = 0; i < n; ++i) {
vi tmp = {r[i], g[i], b[i]};
sort(tmp.begin(), tmp.end());
low[i] = tmp[0];
mid[i] = tmp[1];
high[i] = tmp[2];
}
LL ans = 1;
for (int i = 1; i <= n; ++i)
ans = ans * i % MOD;
int j = 0;
for (int i = 0; i < n; ++i) {
while (j + 1 < n && low[j + 1] <= mid[i])
++j;
ans = ans * (j - i + 1) % MOD;
}
j = 0;
for (int i = 0; i < n; ++i) {
while (j + 1 < n && mid[j + 1] <= high[i])
++j;
ans = ans * (j - i + 1) % MOD;
}
printf("%lld\n", ans);
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p02940 | C++ | Runtime Error | // marico el que lo lea
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
void fastIO() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0]) * sz)
#define fst first
#define snd second
template <typename T, typename U> inline void mnze(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void mxze(T &x, U y) {
if (x < y)
x = y;
}
void _scan(int &x) { scanf("%d", &x); }
void _scan(long long &x) { scanf("%lld", &x); }
void _scan(double &x) { scanf("%lf", &x); }
void _scan(char &x) { scanf(" %c", &x); }
void _scan(char *x) { scanf("%s", x); }
template <typename T> void _scan(vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++)
_scan(v[i]);
}
void scan() {}
template <typename T, typename... U> void scan(T &head, U &...tail) {
_scan(head);
scan(tail...);
}
template <typename T> void _dbg(const char *sdbg, T h) {
cerr << sdbg << "=" << h << "\n";
}
template <typename T, typename... U> void _dbg(const char *sdbg, T h, U... t) {
while (*sdbg != ',')
cerr << *sdbg++;
cerr << "=" << h << ",";
_dbg(sdbg + 1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) \
{ \
{ \
cerr << #x << " = "; \
for (auto _i : x) \
cerr << _i << ", "; \
cerr << "\n"; \
} \
}
#define debuga(x, sz) \
{ \
{ \
cerr << #x << " = "; \
for (int _i = 0; _i < sz; _i++) \
cerr << x[_i] << ", "; \
cerr << "\n"; \
} \
}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr \
if (0) \
cout
#endif
ll MOD = 998244353;
inline ll Msum(ll x) { return x; }
template <typename... Rest> inline ll Msum(ll x, Rest... rest) {
return (x + Msum(rest...)) % MOD;
}
inline ll Mprod(ll x) { return x; }
template <typename... Rest> inline ll Mprod(ll x, Rest... rest) {
return x * Mprod(rest...) % MOD;
}
inline ll Mnorm(ll x) { return (x % MOD + MOD) % MOD; }
inline ll Msq(ll x) { return (x * x) % MOD; }
inline ll Mpot(ll x, ll e) {
if (!e)
return 1;
return Msq(Mpot(x, e >> 1)) * (e & 1 ? x : 1) % MOD;
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
const int MAXN = 1e5 + 5;
int n, a[MAXN];
char s[MAXN];
ll cnt[3], comp[3];
int other(int x, int y) {
if (x > y)
swap(x, y);
if (x == 0) {
if (y == 1)
return 2;
return 1;
}
if (x == 1) {
assert(y == 2);
return 0;
}
assert(false);
}
int main() {
int m[300];
m['R'] = 0;
m['G'] = 1;
m['B'] = 2;
scan(n, s);
for (int i = 0; i < 3 * n; i++)
a[i] = m[(int)s[i]];
ll ans = 1;
for (int i = 2; i < n + 1; i++)
ans = Mprod(ans, i);
for (int i = 0; i < 3 * n; i++) {
int x = a[i];
if (comp[x]) {
ans = Mprod(comp[x], ans);
comp[x]--;
} else {
bool found = false;
for (int y = 0; y < 3; y++)
if (y != x && cnt[y] > 0) {
found = true;
ans = Mprod(ans, cnt[y]);
cnt[y]--;
comp[other(x, y)]++;
break;
}
if (!found) {
cnt[x]++;
}
}
}
printf("%lld\n", ans);
}
| // marico el que lo lea
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
void fastIO() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0]) * sz)
#define fst first
#define snd second
template <typename T, typename U> inline void mnze(T &x, U y) {
if (y < x)
x = y;
}
template <typename T, typename U> inline void mxze(T &x, U y) {
if (x < y)
x = y;
}
void _scan(int &x) { scanf("%d", &x); }
void _scan(long long &x) { scanf("%lld", &x); }
void _scan(double &x) { scanf("%lf", &x); }
void _scan(char &x) { scanf(" %c", &x); }
void _scan(char *x) { scanf("%s", x); }
template <typename T> void _scan(vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++)
_scan(v[i]);
}
void scan() {}
template <typename T, typename... U> void scan(T &head, U &...tail) {
_scan(head);
scan(tail...);
}
template <typename T> void _dbg(const char *sdbg, T h) {
cerr << sdbg << "=" << h << "\n";
}
template <typename T, typename... U> void _dbg(const char *sdbg, T h, U... t) {
while (*sdbg != ',')
cerr << *sdbg++;
cerr << "=" << h << ",";
_dbg(sdbg + 1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) \
{ \
{ \
cerr << #x << " = "; \
for (auto _i : x) \
cerr << _i << ", "; \
cerr << "\n"; \
} \
}
#define debuga(x, sz) \
{ \
{ \
cerr << #x << " = "; \
for (int _i = 0; _i < sz; _i++) \
cerr << x[_i] << ", "; \
cerr << "\n"; \
} \
}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr \
if (0) \
cout
#endif
ll MOD = 998244353;
inline ll Msum(ll x) { return x; }
template <typename... Rest> inline ll Msum(ll x, Rest... rest) {
return (x + Msum(rest...)) % MOD;
}
inline ll Mprod(ll x) { return x; }
template <typename... Rest> inline ll Mprod(ll x, Rest... rest) {
return x * Mprod(rest...) % MOD;
}
inline ll Mnorm(ll x) { return (x % MOD + MOD) % MOD; }
inline ll Msq(ll x) { return (x * x) % MOD; }
inline ll Mpot(ll x, ll e) {
if (!e)
return 1;
return Msq(Mpot(x, e >> 1)) * (e & 1 ? x : 1) % MOD;
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
const int MAXN = 3e5 + 5;
int n, a[MAXN];
char s[MAXN];
ll cnt[3], comp[3];
int other(int x, int y) {
if (x > y)
swap(x, y);
if (x == 0) {
if (y == 1)
return 2;
return 1;
}
if (x == 1) {
assert(y == 2);
return 0;
}
assert(false);
}
int main() {
int m[300];
m['R'] = 0;
m['G'] = 1;
m['B'] = 2;
scan(n, s);
for (int i = 0; i < 3 * n; i++)
a[i] = m[(int)s[i]];
ll ans = 1;
for (int i = 2; i < n + 1; i++)
ans = Mprod(ans, i);
for (int i = 0; i < 3 * n; i++) {
int x = a[i];
if (comp[x]) {
ans = Mprod(comp[x], ans);
comp[x]--;
} else {
bool found = false;
for (int y = 0; y < 3; y++)
if (y != x && cnt[y] > 0) {
found = true;
ans = Mprod(ans, cnt[y]);
cnt[y]--;
comp[other(x, y)]++;
break;
}
if (!found) {
cnt[x]++;
}
}
}
printf("%lld\n", ans);
}
| replace | 120 | 121 | 120 | 121 | 0 | |
p02940 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, mod = 998244353;
typedef long long ll;
int n, f[1 << 3];
char s[N];
int main() {
scanf("%d", &n);
f[0] = n;
scanf("%s", s + 1);
ll ans = 1;
for (int l = 1; l <= n * 3; l++) {
int t = 0;
if (s[l] == 'R')
t = 1;
if (s[l] == 'G')
t = 2;
bool flag = true;
for (int j = 2; j >= 0 && flag; j--) {
for (int i = (1 << 3) - 1; i >= 0; i--)
if ((!(1 << t & i)) && f[i] && __builtin_popcount(i) == j) {
ans = ans * f[i] % mod;
f[i]--;
f[i ^ (1 << t)]++;
flag = false;
break;
}
}
}
printf("%lld\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, mod = 998244353;
typedef long long ll;
int n, f[1 << 3];
char s[N];
int main() {
scanf("%d", &n);
f[0] = n;
scanf("%s", s + 1);
ll ans = 1;
for (int l = 1; l <= n * 3; l++) {
int t = 0;
if (s[l] == 'R')
t = 1;
if (s[l] == 'G')
t = 2;
bool flag = true;
for (int j = 2; j >= 0 && flag; j--) {
for (int i = (1 << 3) - 1; i >= 0; i--)
if ((!(1 << t & i)) && f[i] && __builtin_popcount(i) == j) {
ans = ans * f[i] % mod;
f[i]--;
f[i ^ (1 << t)]++;
flag = false;
break;
}
}
}
printf("%lld\n", ans);
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p02940 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock() / CLOCKS_PER_SEC
const int N = 1e5 + 7, MOD = 998244353;
string s;
vector<int> a[3];
int type(char c) {
if (c == 'R')
return 0;
else if (c == 'G')
return 1;
else
return 2;
}
int n, lmao_rofl[N], curva[4];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
cin >> n >> s;
for (int i = 0; i < n * 3; ++i)
a[type(s[i])].app(i);
for (int i = 0; i < 3; ++i)
sort(all(a[i]));
for (int i = 0; i < n; ++i) {
vector<int> t;
for (int j = 0; j < 3; ++j)
t.app(a[j][i]);
sort(all(t));
for (int j = 0; j < 3; ++j)
lmao_rofl[t[j]] = j;
}
int ans = 1;
curva[0] = n;
for (int i = 0; i < 3 * n; ++i) {
ans = (ans * curva[lmao_rofl[i]]) % MOD;
--curva[lmao_rofl[i]];
++curva[lmao_rofl[i] + 1];
}
cout << ans << '\n';
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock() / CLOCKS_PER_SEC
const int N = 3e5 + 7, MOD = 998244353;
string s;
vector<int> a[3];
int type(char c) {
if (c == 'R')
return 0;
else if (c == 'G')
return 1;
else
return 2;
}
int n, lmao_rofl[N], curva[4];
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif
cin >> n >> s;
for (int i = 0; i < n * 3; ++i)
a[type(s[i])].app(i);
for (int i = 0; i < 3; ++i)
sort(all(a[i]));
for (int i = 0; i < n; ++i) {
vector<int> t;
for (int j = 0; j < 3; ++j)
t.app(a[j][i]);
sort(all(t));
for (int j = 0; j < 3; ++j)
lmao_rofl[t[j]] = j;
}
int ans = 1;
curva[0] = n;
for (int i = 0; i < 3 * n; ++i) {
ans = (ans * curva[lmao_rofl[i]]) % MOD;
--curva[lmao_rofl[i]];
++curva[lmao_rofl[i] + 1];
}
cout << ans << '\n';
} | replace | 14 | 15 | 14 | 15 | 0 | |
p02940 | C++ | Runtime Error | // 08:09~
#include <bits/stdc++.h>
using namespace std;
template <uint32_t mod> class modint {
uint64_t value;
public:
constexpr modint(const int64_t x = 0) noexcept
: value(x % mod + (x < 0 ? mod : 0)) {}
constexpr explicit operator uint64_t() const noexcept { return value; }
constexpr modint inverse() const noexcept { return pow(*this, mod - 2); }
constexpr bool operator==(const modint &rhs) const noexcept {
return value == rhs.value;
}
constexpr bool operator!=(const modint &rhs) const noexcept {
return value != rhs.value;
}
constexpr modint operator+() const noexcept { return modint(*this); }
constexpr modint operator-() const noexcept { return modint(mod - value); }
constexpr modint operator+(const modint &rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint &rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint &rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint &rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint &rhs) noexcept {
if ((value += rhs.value) >= mod)
value -= mod;
return *this;
}
constexpr modint &operator-=(const modint &rhs) noexcept {
return *this += mod - rhs.value;
}
constexpr modint &operator*=(const modint &rhs) noexcept {
if ((value *= rhs.value) >= mod)
value %= mod;
return *this;
}
constexpr modint &operator/=(const modint &rhs) noexcept {
return *this *= rhs.inverse();
}
constexpr modint operator++(int) noexcept {
modint ret(*this);
if ((++value) >= mod)
value -= mod;
return ret;
}
constexpr modint operator--(int) noexcept {
modint ret(*this);
if ((value += mod - 1) >= mod)
value -= mod;
return ret;
}
constexpr modint &operator++() noexcept { return *this += 1; }
constexpr modint &operator--() noexcept { return *this -= 1; }
friend std::ostream &operator<<(std::ostream &os, const modint<mod> &x) {
return os << x.value;
}
friend std::istream &operator>>(std::istream &is, modint<mod> &x) {
int64_t i;
is >> i;
x = modint<mod>(i);
return is;
}
friend constexpr modint<mod> pow(const modint<mod> &x, uint64_t y) {
modint<mod> ret{1}, m{x};
while (y > 0) {
if (y & 1)
ret *= m;
m *= m;
y >>= 1;
}
return ret;
}
};
constexpr int64_t mod = 998244353;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
string s;
static int color[100000];
cin >> n >> s;
for (int i = 0; i < 3 * n; ++i)
color[i] = 1 << (s[i] % 3);
static int64_t dp[8];
modint<mod> ans = 1;
for (int i = 0; i < 3 * n; ++i) {
if (dp[7 & ~color[i]] > 0)
ans *= dp[7 & ~color[i]]--;
else if (dp[1] > 0 && color[i] != 1) {
ans *= dp[1]--;
dp[1 | color[i]]++;
} else if (dp[2] > 0 && color[i] != 2) {
ans *= dp[2]--;
dp[2 | color[i]]++;
} else if (dp[4] > 0 && color[i] != 4) {
ans *= dp[4]--;
dp[4 | color[i]]++;
} else
dp[color[i]]++;
}
for (int i = 1; i <= n; ++i)
ans *= i;
cout << ans << endl;
return 0;
} | // 08:09~
#include <bits/stdc++.h>
using namespace std;
template <uint32_t mod> class modint {
uint64_t value;
public:
constexpr modint(const int64_t x = 0) noexcept
: value(x % mod + (x < 0 ? mod : 0)) {}
constexpr explicit operator uint64_t() const noexcept { return value; }
constexpr modint inverse() const noexcept { return pow(*this, mod - 2); }
constexpr bool operator==(const modint &rhs) const noexcept {
return value == rhs.value;
}
constexpr bool operator!=(const modint &rhs) const noexcept {
return value != rhs.value;
}
constexpr modint operator+() const noexcept { return modint(*this); }
constexpr modint operator-() const noexcept { return modint(mod - value); }
constexpr modint operator+(const modint &rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint &rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint &rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint &rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint &rhs) noexcept {
if ((value += rhs.value) >= mod)
value -= mod;
return *this;
}
constexpr modint &operator-=(const modint &rhs) noexcept {
return *this += mod - rhs.value;
}
constexpr modint &operator*=(const modint &rhs) noexcept {
if ((value *= rhs.value) >= mod)
value %= mod;
return *this;
}
constexpr modint &operator/=(const modint &rhs) noexcept {
return *this *= rhs.inverse();
}
constexpr modint operator++(int) noexcept {
modint ret(*this);
if ((++value) >= mod)
value -= mod;
return ret;
}
constexpr modint operator--(int) noexcept {
modint ret(*this);
if ((value += mod - 1) >= mod)
value -= mod;
return ret;
}
constexpr modint &operator++() noexcept { return *this += 1; }
constexpr modint &operator--() noexcept { return *this -= 1; }
friend std::ostream &operator<<(std::ostream &os, const modint<mod> &x) {
return os << x.value;
}
friend std::istream &operator>>(std::istream &is, modint<mod> &x) {
int64_t i;
is >> i;
x = modint<mod>(i);
return is;
}
friend constexpr modint<mod> pow(const modint<mod> &x, uint64_t y) {
modint<mod> ret{1}, m{x};
while (y > 0) {
if (y & 1)
ret *= m;
m *= m;
y >>= 1;
}
return ret;
}
};
constexpr int64_t mod = 998244353;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
string s;
static int color[300000];
cin >> n >> s;
for (int i = 0; i < 3 * n; ++i)
color[i] = 1 << (s[i] % 3);
static int64_t dp[8];
modint<mod> ans = 1;
for (int i = 0; i < 3 * n; ++i) {
if (dp[7 & ~color[i]] > 0)
ans *= dp[7 & ~color[i]]--;
else if (dp[1] > 0 && color[i] != 1) {
ans *= dp[1]--;
dp[1 | color[i]]++;
} else if (dp[2] > 0 && color[i] != 2) {
ans *= dp[2]--;
dp[2 | color[i]]++;
} else if (dp[4] > 0 && color[i] != 4) {
ans *= dp[4]--;
dp[4 | color[i]]++;
} else
dp[color[i]]++;
}
for (int i = 1; i <= n; ++i)
ans *= i;
cout << ans << endl;
return 0;
} | replace | 90 | 91 | 90 | 91 | 0 | |
p02940 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ss(x) (int)x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
using ll = long long;
using namespace std;
const int N = 2e5 + 100;
const int MOD = 998244353;
int n, type[N], cnt[3];
char s[N];
vector<int> g[3];
int main() {
scanf("%d%s", &n, s + 1);
rep(i, 1, 3 * n) {
if (s[i] == 'R')
g[0].pb(i);
if (s[i] == 'G')
g[1].pb(i);
if (s[i] == 'B')
g[2].pb(i);
}
rep(i, 0, n - 1) {
vector<int> v;
rep(j, 0, 2) v.pb(g[j][i]);
sort(v.begin(), v.end());
rep(j, 0, 2) type[v[j]] = j;
}
ll res = 1;
rep(i, 1, 3 * n) {
if (type[i] == 0)
res = res * (n - cnt[0]) % MOD;
if (type[i] == 1)
res = res * (cnt[0] - cnt[1]) % MOD;
if (type[i] == 2)
res = res * (cnt[1] - cnt[2]) % MOD;
cnt[type[i]]++;
}
printf("%lld\n", res);
return 0;
}
| #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ss(x) (int)x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
using ll = long long;
using namespace std;
const int N = 3e5 + 100;
const int MOD = 998244353;
int n, type[N], cnt[3];
char s[N];
vector<int> g[3];
int main() {
scanf("%d%s", &n, s + 1);
rep(i, 1, 3 * n) {
if (s[i] == 'R')
g[0].pb(i);
if (s[i] == 'G')
g[1].pb(i);
if (s[i] == 'B')
g[2].pb(i);
}
rep(i, 0, n - 1) {
vector<int> v;
rep(j, 0, 2) v.pb(g[j][i]);
sort(v.begin(), v.end());
rep(j, 0, 2) type[v[j]] = j;
}
ll res = 1;
rep(i, 1, 3 * n) {
if (type[i] == 0)
res = res * (n - cnt[0]) % MOD;
if (type[i] == 1)
res = res * (cnt[0] - cnt[1]) % MOD;
if (type[i] == 2)
res = res * (cnt[1] - cnt[2]) % MOD;
cnt[type[i]]++;
}
printf("%lld\n", res);
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02940 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
template <class T> void read(T &x) {
x = 0;
int f = 1, ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 - '0' + ch;
ch = getchar();
}
x *= f;
}
typedef long long ll;
const int mod = 998244353;
const int maxn = 1e5 + 10;
int n;
char s[maxn];
int main() {
read(n);
scanf("%s", s + 1);
int an = 1;
int t = n, r = 0, b = 0, g = 0, rb = 0, rg = 0, bg = 0;
for (int i = 1; i <= n * 3; ++i) {
if (s[i] == 'R') {
if (bg) {
an = (ll)an * bg % mod;
--bg;
} else if (b) {
an = (ll)an * b % mod;
--b, ++rb;
} else if (g) {
an = (ll)an * g % mod;
--g, ++rg;
} else {
an = (ll)an * t % mod;
--t, ++r;
}
} else if (s[i] == 'B') {
if (rg) {
an = (ll)an * rg % mod;
--rg;
} else if (r) {
an = (ll)an * r % mod;
--r, ++rb;
} else if (g) {
an = (ll)an * g % mod;
--g, ++bg;
} else {
an = (ll)an * t % mod;
--t, ++b;
}
} else if (s[i] == 'G') {
if (rb) {
an = (ll)an * rb % mod;
--rb;
} else if (b) {
an = (ll)an * b % mod;
--b, ++bg;
} else if (r) {
an = (ll)an * r % mod;
--r, ++rg;
} else {
an = (ll)an * t % mod;
--t, ++g;
}
}
}
printf("%d\n", an);
return 0;
} | #include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
template <class T> void read(T &x) {
x = 0;
int f = 1, ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 - '0' + ch;
ch = getchar();
}
x *= f;
}
typedef long long ll;
const int mod = 998244353;
const int maxn = 1e5 + 10;
int n;
char s[maxn * 3];
int main() {
read(n);
scanf("%s", s + 1);
int an = 1;
int t = n, r = 0, b = 0, g = 0, rb = 0, rg = 0, bg = 0;
for (int i = 1; i <= n * 3; ++i) {
if (s[i] == 'R') {
if (bg) {
an = (ll)an * bg % mod;
--bg;
} else if (b) {
an = (ll)an * b % mod;
--b, ++rb;
} else if (g) {
an = (ll)an * g % mod;
--g, ++rg;
} else {
an = (ll)an * t % mod;
--t, ++r;
}
} else if (s[i] == 'B') {
if (rg) {
an = (ll)an * rg % mod;
--rg;
} else if (r) {
an = (ll)an * r % mod;
--r, ++rb;
} else if (g) {
an = (ll)an * g % mod;
--g, ++bg;
} else {
an = (ll)an * t % mod;
--t, ++b;
}
} else if (s[i] == 'G') {
if (rb) {
an = (ll)an * rb % mod;
--rb;
} else if (b) {
an = (ll)an * b % mod;
--b, ++bg;
} else if (r) {
an = (ll)an * r % mod;
--r, ++rg;
} else {
an = (ll)an * t % mod;
--t, ++g;
}
}
}
printf("%d\n", an);
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02940 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define fornum(A, B, C) for (A = B; A < C; A++)
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
/////////////////////////////////////////////////////
#define MOD 998244353ll
char S[303030];
ll N, N3, rgb[5];
ll Fa[303030];
ll i, j, k, ans;
ll moddiv(ll a, ll b) {
a %= MOD;
b %= MOD;
for (ll m = MOD - 2; m > 0; m /= 2) {
if (m & 1) {
a = a * b % MOD;
}
b = b * b % MOD;
}
return a;
}
int main() {
scanf("%d%s", &N, S);
N3 = N * 3;
fornum(i, 0, N3) {
switch (S[i]) {
case 'R':
rgb[i] = 0;
break;
case 'G':
rgb[i] = 1;
break;
case 'B':
rgb[i] = 2;
break;
}
}
ll rgbn[] = {0, 0, 0};
ll mk[] = {N, 0, 0, 0};
ans = 1;
fornum(i, 0, N3) {
k = 0;
fornum(j, 0, 3) {
if (rgbn[rgb[i]] < rgbn[j]) {
++k;
}
}
rgbn[rgb[i]]++;
(ans *= mk[k]) %= MOD;
--mk[k];
++mk[k + 1];
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define fornum(A, B, C) for (A = B; A < C; A++)
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
/////////////////////////////////////////////////////
#define MOD 998244353ll
char S[303030];
ll N, N3, rgb[303030];
ll Fa[303030];
ll i, j, k, ans;
ll moddiv(ll a, ll b) {
a %= MOD;
b %= MOD;
for (ll m = MOD - 2; m > 0; m /= 2) {
if (m & 1) {
a = a * b % MOD;
}
b = b * b % MOD;
}
return a;
}
int main() {
scanf("%d%s", &N, S);
N3 = N * 3;
fornum(i, 0, N3) {
switch (S[i]) {
case 'R':
rgb[i] = 0;
break;
case 'G':
rgb[i] = 1;
break;
case 'B':
rgb[i] = 2;
break;
}
}
ll rgbn[] = {0, 0, 0};
ll mk[] = {N, 0, 0, 0};
ans = 1;
fornum(i, 0, N3) {
k = 0;
fornum(j, 0, 3) {
if (rgbn[rgb[i]] < rgbn[j]) {
++k;
}
}
rgbn[rgb[i]]++;
(ans *= mk[k]) %= MOD;
--mk[k];
++mk[k + 1];
}
printf("%lld\n", ans);
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02940 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#define mod 998244353
#define MN 101000
int n, cnt[8];
char s[MN];
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
int ans = 1;
for (int i = 1; i <= n; i++)
ans = 1ll * ans * i % mod;
for (int i = 1; i <= 3 * n; i++) {
int x;
if (s[i] == 'R')
x = 1;
if (s[i] == 'G')
x = 2;
if (s[i] == 'B')
x = 4;
if (cnt[x ^ 7])
ans = 1ll * ans * cnt[x ^ 7] % mod, cnt[x ^ 7]--;
else if (x != 1 && cnt[1])
ans = 1ll * ans * cnt[1] % mod, cnt[1]--, cnt[x ^ 1]++;
else if (x != 2 && cnt[2])
ans = 1ll * ans * cnt[2] % mod, cnt[2]--, cnt[x ^ 2]++;
else if (x != 4 && cnt[4])
ans = 1ll * ans * cnt[4] % mod, cnt[4]--, cnt[x ^ 4]++;
else
cnt[x]++;
}
printf("%d\n", ans);
} | #include <cstdio>
#include <iostream>
#define mod 998244353
#define MN 301000
int n, cnt[8];
char s[MN];
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
int ans = 1;
for (int i = 1; i <= n; i++)
ans = 1ll * ans * i % mod;
for (int i = 1; i <= 3 * n; i++) {
int x;
if (s[i] == 'R')
x = 1;
if (s[i] == 'G')
x = 2;
if (s[i] == 'B')
x = 4;
if (cnt[x ^ 7])
ans = 1ll * ans * cnt[x ^ 7] % mod, cnt[x ^ 7]--;
else if (x != 1 && cnt[1])
ans = 1ll * ans * cnt[1] % mod, cnt[1]--, cnt[x ^ 1]++;
else if (x != 2 && cnt[2])
ans = 1ll * ans * cnt[2] % mod, cnt[2]--, cnt[x ^ 2]++;
else if (x != 4 && cnt[4])
ans = 1ll * ans * cnt[4] % mod, cnt[4]--, cnt[x ^ 4]++;
else
cnt[x]++;
}
printf("%d\n", ans);
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02940 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define db long double
#define ii pair<int, int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repv(i, a, b) for (int i = b - 1; i >= a; i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
const int mod = 998244353, N = 100005;
int add(int x, int y) {
x += y;
if (x >= mod)
x -= mod;
if (x < 0)
x += mod;
return x;
}
int mult(int x, int y) {
ll tmp = (ll)x * y;
if (tmp >= mod)
tmp %= mod;
return tmp;
}
// R,G,B,RG,RB,BG
map<vi, int> dp[N];
string s;
int fun(vi v, int ind) {
if (ind == sz(s))
return 1;
if (dp[ind].count(v))
return dp[ind][v];
int ans = 0, id;
if (s[ind] == 'R')
id = 0;
else if (s[ind] == 'G')
id = 1;
else
id = 2;
int nxt1 = (id + 1), nxt2 = (id + 2);
nxt1 %= 3;
nxt2 %= 3;
if (v[5 - id]) // 2 are there
{
vi tmp(v);
tmp[5 - id]--;
ans = mult(v[5 - id], fun(tmp, ind + 1));
} else if (!v[nxt1] && !v[nxt2]) // no single is there to join
{
vi tmp(v);
tmp[id]++;
ans = fun(tmp, ind + 1);
} else // join with one of the singles
{
if (s[ind] == 'R') {
vi tmp(v);
// RG
if (tmp[nxt1]) {
tmp[nxt1]--;
tmp[3]++;
ans = add(ans, mult(v[nxt1], fun(tmp, ind + 1)));
tmp[nxt1]++;
tmp[3]--;
}
// RB
if (tmp[nxt2]) {
tmp[nxt2]--;
tmp[4]++;
ans = add(ans, mult(v[nxt2], fun(tmp, ind + 1)));
tmp[nxt2]++;
tmp[4]--;
}
} else if (s[ind] == 'G') {
vi tmp(v);
// GB
if (tmp[nxt1]) {
tmp[nxt1]--;
tmp[5]++;
ans = add(ans, mult(v[nxt1], fun(tmp, ind + 1)));
tmp[nxt1]++;
tmp[5]--;
}
// RG
if (tmp[nxt2]) {
tmp[nxt2]--;
tmp[3]++;
ans = add(ans, mult(v[nxt2], fun(tmp, ind + 1)));
tmp[nxt2]++;
tmp[3]--;
}
} else {
vi tmp(v);
// RB
if (tmp[nxt1]) {
tmp[nxt1]--;
tmp[4]++;
ans = add(ans, mult(v[nxt1], fun(tmp, ind + 1)));
tmp[nxt1]++;
tmp[4]--;
}
// BG
if (tmp[nxt2]) {
tmp[nxt2]--;
tmp[5]++;
ans = add(ans, mult(v[nxt2], fun(tmp, ind + 1)));
tmp[nxt2]++;
tmp[5]--;
}
}
}
return dp[ind][v] = ans;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
cin >> s;
vi v;
v.resize(6, 0);
int ans = fun(v, 0);
rep(i, 1, n + 1) ans = mult(ans, i);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define db long double
#define ii pair<int, int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repv(i, a, b) for (int i = b - 1; i >= a; i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
const int mod = 998244353, N = 100005;
int add(int x, int y) {
x += y;
if (x >= mod)
x -= mod;
if (x < 0)
x += mod;
return x;
}
int mult(int x, int y) {
ll tmp = (ll)x * y;
if (tmp >= mod)
tmp %= mod;
return tmp;
}
// R,G,B,RG,RB,BG
map<vi, int> dp[3 * N];
string s;
int fun(vi v, int ind) {
if (ind == sz(s))
return 1;
if (dp[ind].count(v))
return dp[ind][v];
int ans = 0, id;
if (s[ind] == 'R')
id = 0;
else if (s[ind] == 'G')
id = 1;
else
id = 2;
int nxt1 = (id + 1), nxt2 = (id + 2);
nxt1 %= 3;
nxt2 %= 3;
if (v[5 - id]) // 2 are there
{
vi tmp(v);
tmp[5 - id]--;
ans = mult(v[5 - id], fun(tmp, ind + 1));
} else if (!v[nxt1] && !v[nxt2]) // no single is there to join
{
vi tmp(v);
tmp[id]++;
ans = fun(tmp, ind + 1);
} else // join with one of the singles
{
if (s[ind] == 'R') {
vi tmp(v);
// RG
if (tmp[nxt1]) {
tmp[nxt1]--;
tmp[3]++;
ans = add(ans, mult(v[nxt1], fun(tmp, ind + 1)));
tmp[nxt1]++;
tmp[3]--;
}
// RB
if (tmp[nxt2]) {
tmp[nxt2]--;
tmp[4]++;
ans = add(ans, mult(v[nxt2], fun(tmp, ind + 1)));
tmp[nxt2]++;
tmp[4]--;
}
} else if (s[ind] == 'G') {
vi tmp(v);
// GB
if (tmp[nxt1]) {
tmp[nxt1]--;
tmp[5]++;
ans = add(ans, mult(v[nxt1], fun(tmp, ind + 1)));
tmp[nxt1]++;
tmp[5]--;
}
// RG
if (tmp[nxt2]) {
tmp[nxt2]--;
tmp[3]++;
ans = add(ans, mult(v[nxt2], fun(tmp, ind + 1)));
tmp[nxt2]++;
tmp[3]--;
}
} else {
vi tmp(v);
// RB
if (tmp[nxt1]) {
tmp[nxt1]--;
tmp[4]++;
ans = add(ans, mult(v[nxt1], fun(tmp, ind + 1)));
tmp[nxt1]++;
tmp[4]--;
}
// BG
if (tmp[nxt2]) {
tmp[nxt2]--;
tmp[5]++;
ans = add(ans, mult(v[nxt2], fun(tmp, ind + 1)));
tmp[nxt2]++;
tmp[5]--;
}
}
}
return dp[ind][v] = ans;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
cin >> s;
vi v;
v.resize(6, 0);
int ans = fun(v, 0);
rep(i, 1, n + 1) ans = mult(ans, i);
cout << ans << endl;
return 0;
}
| replace | 57 | 58 | 57 | 58 | 0 | |
p02940 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
char s[100005];
int n, cnt[3];
int main() {
while (~scanf("%d", &n)) {
ll ans = 1;
scanf("%s", s + 1);
for (int i = 1; i <= n * 3; i++) { // 思路填满再说
int x[3], _x[3];
x[0] = cnt[0], x[1] = cnt[1], x[2] = cnt[2]; // 现有的
sort(x, x + 3);
int color = (s[i] == 'R' ? 0 : (s[i] == 'G' ? 1 : 2));
cnt[color]++;
_x[0] = cnt[0], _x[1] = cnt[1], _x[2] = cnt[2]; // 进来的
sort(_x, _x + 3);
if (_x[2] != x[2]) {
; // 进了一个最多的,给下一个人
} else if (_x[0] != x[0]) { // 进了一个最少,选一个人给
ans = 1ll * ans * (x[1] - x[0]) % mod;
} else { // 进了一个中间的,选一个人给
ans = 1ll * ans * (x[2] - x[1]) % mod;
}
}
for (int i = 1; i <= n; i++) // A[n,n]
ans = 1ll * ans * i % mod;
printf("%d\n", ans);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
char s[300005];
int n, cnt[3];
int main() {
while (~scanf("%d", &n)) {
ll ans = 1;
scanf("%s", s + 1);
for (int i = 1; i <= n * 3; i++) { // 思路填满再说
int x[3], _x[3];
x[0] = cnt[0], x[1] = cnt[1], x[2] = cnt[2]; // 现有的
sort(x, x + 3);
int color = (s[i] == 'R' ? 0 : (s[i] == 'G' ? 1 : 2));
cnt[color]++;
_x[0] = cnt[0], _x[1] = cnt[1], _x[2] = cnt[2]; // 进来的
sort(_x, _x + 3);
if (_x[2] != x[2]) {
; // 进了一个最多的,给下一个人
} else if (_x[0] != x[0]) { // 进了一个最少,选一个人给
ans = 1ll * ans * (x[1] - x[0]) % mod;
} else { // 进了一个中间的,选一个人给
ans = 1ll * ans * (x[2] - x[1]) % mod;
}
}
for (int i = 1; i <= n; i++) // A[n,n]
ans = 1ll * ans * i % mod;
printf("%d\n", ans);
}
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02940 | C++ | Runtime Error | /*Lucky_Glass*/
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1e5, MOD = 998244353;
int n;
char str[N + 3];
struct MODNUM {
int num;
MODNUM() {}
MODNUM(int _n) : num(_n) {}
MODNUM operator*(const MODNUM B) { return 1ll * num * B.num % MOD; }
MODNUM operator+(const MODNUM B) { return (1ll * num + B.num) % MOD; }
MODNUM operator-(const MODNUM B) {
return ((1ll * num - B.num) % MOD + MOD) % MOD;
}
MODNUM operator+=(const MODNUM B) { return *this = (*this) + B; }
MODNUM operator*=(const MODNUM B) { return *this = (*this) * B; }
MODNUM operator-=(const MODNUM B) { return *this = (*this) - B; }
} ans, num[4][4];
int main() {
// freopen("legend.in","r",stdin);
// freopen("legend.out","w",stdout);
scanf("%d%s", &n, str + 1);
for (int i = 1; i <= 3 * n; i++) {
if (str[i] == 'R')
str[i] = '1';
if (str[i] == 'G')
str[i] = '2';
if (str[i] == 'B')
str[i] = '3';
}
ans = 1;
for (int i = 1; i <= 3 * n; i++) {
int ano1, ano2, thi = str[i] - '0';
if (str[i] == '1')
ano1 = 2, ano2 = 3;
if (str[i] == '2')
ano1 = 1, ano2 = 3;
if (str[i] == '3')
ano1 = 1, ano2 = 2;
if (num[ano1][ano2].num)
ans *= num[ano1][ano2], num[ano1][ano2] -= 1;
else if (num[ano1][0].num)
ans *= num[ano1][0], num[ano1][0] -= 1,
num[min(ano1, thi)][max(ano1, thi)] += 1;
else if (num[ano2][0].num)
ans *= num[ano2][0], num[ano2][0] -= 1,
num[min(ano2, thi)][max(ano2, thi)] += 1;
else
num[thi][0] += 1;
}
for (int i = 1; i <= n; i++)
ans *= i;
printf("%d\n", ans);
return 0;
}
| /*Lucky_Glass*/
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1e5, MOD = 998244353;
int n;
char str[3 * N + 3];
struct MODNUM {
int num;
MODNUM() {}
MODNUM(int _n) : num(_n) {}
MODNUM operator*(const MODNUM B) { return 1ll * num * B.num % MOD; }
MODNUM operator+(const MODNUM B) { return (1ll * num + B.num) % MOD; }
MODNUM operator-(const MODNUM B) {
return ((1ll * num - B.num) % MOD + MOD) % MOD;
}
MODNUM operator+=(const MODNUM B) { return *this = (*this) + B; }
MODNUM operator*=(const MODNUM B) { return *this = (*this) * B; }
MODNUM operator-=(const MODNUM B) { return *this = (*this) - B; }
} ans, num[4][4];
int main() {
// freopen("legend.in","r",stdin);
// freopen("legend.out","w",stdout);
scanf("%d%s", &n, str + 1);
for (int i = 1; i <= 3 * n; i++) {
if (str[i] == 'R')
str[i] = '1';
if (str[i] == 'G')
str[i] = '2';
if (str[i] == 'B')
str[i] = '3';
}
ans = 1;
for (int i = 1; i <= 3 * n; i++) {
int ano1, ano2, thi = str[i] - '0';
if (str[i] == '1')
ano1 = 2, ano2 = 3;
if (str[i] == '2')
ano1 = 1, ano2 = 3;
if (str[i] == '3')
ano1 = 1, ano2 = 2;
if (num[ano1][ano2].num)
ans *= num[ano1][ano2], num[ano1][ano2] -= 1;
else if (num[ano1][0].num)
ans *= num[ano1][0], num[ano1][0] -= 1,
num[min(ano1, thi)][max(ano1, thi)] += 1;
else if (num[ano2][0].num)
ans *= num[ano2][0], num[ano2][0] -= 1,
num[min(ano2, thi)][max(ano2, thi)] += 1;
else
num[thi][0] += 1;
}
for (int i = 1; i <= n; i++)
ans *= i;
printf("%d\n", ans);
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.