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
p03129
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define pii pair<int, int> #define pb push_back #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); const int MOD = 1e9 + 7; using namespace std; int32_t main() { IOS #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { int s = i + 2, j = 0; for (j = 2; j <= k && s <= n; j++) { s += 2; } if (j > k) { cout << "YES\n"; return 0; } } cout << "NO\n"; return 0; }
#include <bits/stdc++.h> #define int long long #define pii pair<int, int> #define pb push_back #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); const int MOD = 1e9 + 7; using namespace std; int32_t main() { IOS int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { int s = i + 2, j = 0; for (j = 2; j <= k && s <= n; j++) { s += 2; } if (j > k) { cout << "YES\n"; return 0; } } cout << "NO\n"; return 0; }
replace
12
18
12
13
TLE
p03129
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { int cnt[5] = {0}; for (int i = 0; i < 3; i++) { int a, b; cin >> a >> b; cnt[a]++, cnt[b]++; } bool ok = 1; for (int i = 1; i <= 4; i++) if (cnt[i] == 3) ok = 0; cout << (ok ? "YES" : "NO") << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { ll n, k; cin >> n >> k; cout << (k * 2 <= n + 1 ? "YES" : "NO") << endl; return 0; }
replace
7
18
7
10
0
p03129
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(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using pi = pair<int, int>; const ll INF = 1LL << 60; int main() { int n, k; cin >> n >> k; if (n == 1) { if (k == 1) cout << "YES" << endl; else cout << "NO" << endl; return 0; } n--; k--; if (2 <= n / k) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#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(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = long long; using pi = pair<int, int>; const ll INF = 1LL << 60; int main() { int n, k; cin >> n >> k; if (k == 1) { if (1 <= n) cout << "YES" << endl; else cout << "NO" << endl; return 0; } n--; k--; if (2 <= n / k) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
replace
14
16
14
16
0
p03129
C++
Runtime Error
///////////////////////////////////////////////////////// // // c/temp.cpp file // Last Updated: 2018-10-23 ...Maybe // // I hope you adding this code to the setting file // alias g++='g++ -std=c++1y -DDEBUG_LOCAL' // ///////////////////////////////////////////////////////// #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back // #define int long long #define _overload3(_1, _2, _3, name, ...) name #define _REP(i, n) REAP(i, 0, n) #define REAP(i, a, b) for (int i = int(a); i < int(b); ++i) #define REP(...) _overload3(__VA_ARGS__, REAP, _REP, )(__VA_ARGS__) #define _REPR(i, n) REAPR(i, n, 0) #define REAPR(i, a, b) for (int i = int(a - 1); i >= int(b); --i) #define REPR(...) _overload3(__VA_ARGS__, REAPR, _REPR, )(__VA_ARGS__) #define ALL(a) a.begin(), a.end() #define rALL(a) a.rbegin(), a.rend() #define coutALL(a) \ { \ int loop_coutALL = 0; \ for (auto e : a) \ cout << (loop_coutALL++ ? " " : "") << e; \ cout << endl; \ } #define coutYN(a) cout << ((a) ? "YES" : "NO") << endl; #define coutYn(a) cout << ((a) ? "Yes" : "No") << endl; #define coutyn(a) cout << ((a) ? "yes" : "no") << endl; #define pcnt __builtin_popcount #define buli(x) __builtin_popcountll(x) const int INF = 1145141919; // const long long INF=114514191911451419; const int MOD = (int)1e9 + 7; const double EPS = 1e-12; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; // const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1}; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; typedef pair<int, int> pii; typedef pair<int, string> pis; typedef pair<string, int> psi; typedef pair<string, string> pss; typedef long long ll; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { int i = 0; for (T &x : v) os << (i++ ? " " : "") << x; return os; } ll rev(ll n) { ll x = 0; for (; n > 0;) { x = x * 10 + n % 10; n /= 10; } return x; } ll upper(ll n, ll m) { return (n + m - 1) / m; }; ll rounding(ll n) { return (long double)n + 0.5; }; bool inG(ll x, ll n) { return 0 <= x && x < n; } bool outG(ll x, ll n) { return x < 0 || n <= x; } inline int qp(int a, ll b) { if (!b) return 1; int ans = 1; do { if (b & 1) ans = 1ll * ans * a; a = 1ll * a * a; } while (b >>= 1); return ans; } inline int qp(int a, ll b, int mo) { if (!b) return 1; int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; } inline ll fac(ll k, ll n) { ll a = 1; for (int i = 0; i < n; i++) a *= k--; return a; } inline ll fac(ll k, ll n, int mo) { ll a = 1; for (int i = 0; i < n; i++) a *= k--, a %= mo; return a; } inline int dsum(ll n) { int a = 0; for (; n; n /= 10) a += n % 10; return a; } struct Arithmetic { Arithmetic() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } }; // #define DEBUG_LOCAL #ifdef DEBUG_LOCAL template <typename T> void deb(T a) { cerr << "deb: " << a << "です" << endl; } #define debl \ { cerr << "debug: " << __LINE__ << "行目だ" << endl; } void what_cr() { cout << __GCC_ATOMIC_CHAR16_T_LOCK_FREE << " ←?" << endl; } // ori_func S // ori_func E #else template <typename T> void deb(T a) {} #define debl void what_cr() {} void t_t() {} #endif signed main() { Arithmetic Exception; int a, b; cin >> a >> b; a--, b--; coutYN(a / b >= 2); return 0; }
///////////////////////////////////////////////////////// // // c/temp.cpp file // Last Updated: 2018-10-23 ...Maybe // // I hope you adding this code to the setting file // alias g++='g++ -std=c++1y -DDEBUG_LOCAL' // ///////////////////////////////////////////////////////// #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back // #define int long long #define _overload3(_1, _2, _3, name, ...) name #define _REP(i, n) REAP(i, 0, n) #define REAP(i, a, b) for (int i = int(a); i < int(b); ++i) #define REP(...) _overload3(__VA_ARGS__, REAP, _REP, )(__VA_ARGS__) #define _REPR(i, n) REAPR(i, n, 0) #define REAPR(i, a, b) for (int i = int(a - 1); i >= int(b); --i) #define REPR(...) _overload3(__VA_ARGS__, REAPR, _REPR, )(__VA_ARGS__) #define ALL(a) a.begin(), a.end() #define rALL(a) a.rbegin(), a.rend() #define coutALL(a) \ { \ int loop_coutALL = 0; \ for (auto e : a) \ cout << (loop_coutALL++ ? " " : "") << e; \ cout << endl; \ } #define coutYN(a) cout << ((a) ? "YES" : "NO") << endl; #define coutYn(a) cout << ((a) ? "Yes" : "No") << endl; #define coutyn(a) cout << ((a) ? "yes" : "no") << endl; #define pcnt __builtin_popcount #define buli(x) __builtin_popcountll(x) const int INF = 1145141919; // const long long INF=114514191911451419; const int MOD = (int)1e9 + 7; const double EPS = 1e-12; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; // const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1}; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; typedef pair<int, int> pii; typedef pair<int, string> pis; typedef pair<string, int> psi; typedef pair<string, string> pss; typedef long long ll; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { int i = 0; for (T &x : v) os << (i++ ? " " : "") << x; return os; } ll rev(ll n) { ll x = 0; for (; n > 0;) { x = x * 10 + n % 10; n /= 10; } return x; } ll upper(ll n, ll m) { return (n + m - 1) / m; }; ll rounding(ll n) { return (long double)n + 0.5; }; bool inG(ll x, ll n) { return 0 <= x && x < n; } bool outG(ll x, ll n) { return x < 0 || n <= x; } inline int qp(int a, ll b) { if (!b) return 1; int ans = 1; do { if (b & 1) ans = 1ll * ans * a; a = 1ll * a * a; } while (b >>= 1); return ans; } inline int qp(int a, ll b, int mo) { if (!b) return 1; int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; } inline ll fac(ll k, ll n) { ll a = 1; for (int i = 0; i < n; i++) a *= k--; return a; } inline ll fac(ll k, ll n, int mo) { ll a = 1; for (int i = 0; i < n; i++) a *= k--, a %= mo; return a; } inline int dsum(ll n) { int a = 0; for (; n; n /= 10) a += n % 10; return a; } struct Arithmetic { Arithmetic() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } }; // #define DEBUG_LOCAL #ifdef DEBUG_LOCAL template <typename T> void deb(T a) { cerr << "deb: " << a << "です" << endl; } #define debl \ { cerr << "debug: " << __LINE__ << "行目だ" << endl; } void what_cr() { cout << __GCC_ATOMIC_CHAR16_T_LOCK_FREE << " ←?" << endl; } // ori_func S // ori_func E #else template <typename T> void deb(T a) {} #define debl void what_cr() {} void t_t() {} #endif signed main() { Arithmetic Exception; int a, b; cin >> a >> b; if (b == 1) { coutYN(1); return 0; } a--, b--; coutYN(a / b >= 2); return 0; }
insert
169
169
169
175
0
p03129
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define int long long #define ends ' ' #define endl '\n' #define pb push_back #define x first #define y second int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS; int n, k; cin >> n >> k; if (k <= (ceil((double)n / 2))) { cout << "YES"; } else { cout << "NO"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define int long long #define ends ' ' #define endl '\n' #define pb push_back #define x first #define y second int32_t main() { #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif IOS; int n, k; cin >> n >> k; if (k <= (ceil((double)n / 2))) { cout << "YES"; } else { cout << "NO"; } return 0; }
replace
12
14
12
14
0
p03129
C++
Runtime Error
/** source code by coolreshab **/ #include <bits/stdc++.h> using namespace std; #define MAX 100000 #define MAX1 100000 #define inf 1000000000 #define mod 1000000007 #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif // freopen("out.txt","w",stdout); // begin int n, k, x; cin >> n >> k; if (n & 1) { x = n / 2; x++; } else x = n / 2; if (x >= k) cout << "YES"; else cout << "NO"; // end return 0; }
/** source code by coolreshab **/ #include <bits/stdc++.h> using namespace std; #define MAX 100000 #define MAX1 100000 #define inf 1000000000 #define mod 1000000007 #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // begin int n, k, x; cin >> n >> k; if (n & 1) { x = n / 2; x++; } else x = n / 2; if (x >= k) cout << "YES"; else cout << "NO"; // end return 0; }
delete
14
18
14
14
0
p03129
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define inf 1000000000 #define infll 1000000000000000000ll #define vi vector<int> #define vll vector<ll> #define pb push_back #define pii pair<int, int> #define pll pair<ll, ll> #define pdd pair<double, double> #define mpr make_pair #define fi first #define se second #define pq priority_queue<int> #define pqll priority_queue<ll> #define up(x, y) (x < (y) ? x = (y) : 0) #define dn(x, y) (x > (y) ? x = (y) : 0) #define ad(x, y) (x = (x + (y)) % mod) using namespace std; int read() { int x = 0; char ch = getchar(); bool flag = 0; while (ch < '0' || ch > '9') { if (ch == '-') flag = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return flag ? -x : x; } ll readll() { ll x = 0; char ch = getchar(); bool flag = 0; while (ch < '0' || ch > '9') { if (ch == '-') flag = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return flag ? -x : x; } int main() { int a, b; scanf("%d%d", &a, b); puts((b <= (a + 1 >> 1)) ? "YES" : "NO"); return 0; }
#include <bits/stdc++.h> #define ll long long #define inf 1000000000 #define infll 1000000000000000000ll #define vi vector<int> #define vll vector<ll> #define pb push_back #define pii pair<int, int> #define pll pair<ll, ll> #define pdd pair<double, double> #define mpr make_pair #define fi first #define se second #define pq priority_queue<int> #define pqll priority_queue<ll> #define up(x, y) (x < (y) ? x = (y) : 0) #define dn(x, y) (x > (y) ? x = (y) : 0) #define ad(x, y) (x = (x + (y)) % mod) using namespace std; int read() { int x = 0; char ch = getchar(); bool flag = 0; while (ch < '0' || ch > '9') { if (ch == '-') flag = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return flag ? -x : x; } ll readll() { ll x = 0; char ch = getchar(); bool flag = 0; while (ch < '0' || ch > '9') { if (ch == '-') flag = 1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return flag ? -x : x; } int main() { int a, b; scanf("%d%d", &a, &b); puts((b <= (a + 1 >> 1)) ? "YES" : "NO"); return 0; }
replace
52
53
52
53
-11
p03130
Python
Runtime Error
def solution(path1, path2, path3): counts = [0, 0, 0, 0] paths = [path1, path2, path3] for path in paths: counts[path[0] - 1] += 1 counts[path[1] - 1] += 1 countsOfCounts = [0, 0] for count in counts: if count == 1: if countsOfCounts[0] == 2: return "NO" countsOfCounts[0] += 1 elif count == 2: if countsOfCounts[1] == 2: return "NO" countsOfCounts[1] += 1 else: return "NO" return "YES" s1, s2, s3 = input().split("\n") path1 = [int(s) for s in s1.split(" ")] path2 = [int(s) for s in s2.split(" ")] path3 = [int(s) for s in s3.split(" ")] print(solution(path1, path2, path3))
def solution(path1, path2, path3): counts = [0, 0, 0, 0] paths = [path1, path2, path3] for path in paths: counts[path[0] - 1] += 1 counts[path[1] - 1] += 1 countsOfCounts = [0, 0] for count in counts: if count == 1: if countsOfCounts[0] == 2: return "NO" countsOfCounts[0] += 1 elif count == 2: if countsOfCounts[1] == 2: return "NO" countsOfCounts[1] += 1 else: return "NO" return "YES" path1 = [int(s) for s in input().split(" ")] path2 = [int(s) for s in input().split(" ")] path3 = [int(s) for s in input().split(" ")] print(solution(path1, path2, path3))
replace
22
26
22
25
ValueError: not enough values to unpack (expected 3, got 1)
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03130/Python/s731098655.py", line 23, in <module> s1, s2, s3 = input().split('\n') ValueError: not enough values to unpack (expected 3, got 1)
p03130
C++
Runtime Error
#include <iostream> #include <vector> int main() { std::vector<std::pair<int, int>> list; for (int i = 0; i < 3; ++i) { int n, k; std::cin >> n; std::cin >> k; list.emplace_back(n, k); } int a[4] = {0}; bool flg = false; for (auto c : list) { a[c.first]++; a[c.second]++; } int cnt = 0; for (int i = 0; i < 4; ++i) { if (a[i] == 2) cnt++; } if (cnt == 2) flg = true; if (flg) std::cout << "YES" << std::endl; else std::cout << "NO" << std::endl; return 0; }
#include <iostream> #include <vector> int main() { std::vector<std::pair<int, int>> list; for (int i = 0; i < 3; ++i) { int n, k; std::cin >> n; std::cin >> k; list.emplace_back(n, k); } int a[4] = {0}; bool flg = false; for (auto c : list) { a[c.first - 1]++; a[c.second - 1]++; } int cnt = 0; for (int i = 0; i < 4; ++i) { if (a[i] == 2) cnt++; } if (cnt == 2) flg = true; if (flg) std::cout << "YES" << std::endl; else std::cout << "NO" << std::endl; return 0; }
replace
16
18
16
18
0
p03130
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) int main() { int i; vector<int> v(5); rep(i, 6) { cin >> i; v.at(i)++; } if (v.at(1) <= 2 && v.at(2) <= 2 && v.at(3) <= 2 && v.at(4) <= 2) { cout << "YES" << endl; } else { cout << "NO" << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) int main() { int i; vector<int> v(5); rep(j, 6) { cin >> i; v.at(i)++; } if (v.at(1) <= 2 && v.at(2) <= 2 && v.at(3) <= 2 && v.at(4) <= 2) { cout << "YES" << endl; } else { cout << "NO" << endl; } }
replace
7
8
7
8
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p03130
C++
Time Limit Exceeded
#include <iostream> using namespace std; int mat[4][4] = {0}; int check(int i, int j); int main(void) { int p, n; for (int i = 0; i < 3; i++) { cin >> p >> n; mat[p - 1][n - 1] = 1; mat[n - 1][p - 1] = 1; } /* for(int i = 0; i < 4; i++){ for(int j = 0; j < 4; j++){ cout << mat[i][j]; } cout << endl; } */ if (check(0, 0) == 3) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; } int check(int i, int j) { if (mat[i][j] == 0) { // printf("check(%d,%d) %d ==> check(%d,%d)\n",i,j,mat[i][j],i,j+1); if (j + 1 < 4) { return check(i, j + 1); } else if (i + 1 < 4) { return check(i + 1, 0); } else { return 0; } } else if (mat[i][j] == 1) { mat[j][i] = 0; // printf("check(%d,%d) %d ==> check(%d,%d)\n",i,j + 1,mat[i][j],j,0); return check(j, 0) + 1; } }
#include <iostream> using namespace std; int mat[4][4] = {0}; int check(int i, int j); int main(void) { int p, n; for (int i = 0; i < 3; i++) { cin >> p >> n; mat[p - 1][n - 1] = 1; mat[n - 1][p - 1] = 1; } /* for(int i = 0; i < 4; i++){ for(int j = 0; j < 4; j++){ cout << mat[i][j]; } cout << endl; } */ if (check(0, 0) == 3) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; } int check(int i, int j) { if (mat[i][j] == 0) { // printf("check(%d,%d) %d ==> check(%d,%d)\n",i,j,mat[i][j],i,j+1); if (j + 1 < 4) { return check(i, j + 1); } /* else if(i + 1 < 4){ return check(i + 1, 0); } */ else { return 0; } } else if (mat[i][j] == 1) { mat[j][i] = 0; // printf("check(%d,%d) %d ==> check(%d,%d)\n",i,j + 1,mat[i][j],j,0); return check(j, 0) + 1; } }
replace
39
42
39
46
TLE
p03131
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = a; i <= b; i++) #define FORD(i, a, b) for (int i = a; i >= b; i--) #define FORL(i, x) for (int i = head[x]; i; i = nxt[i]) #define ALL(a) (a).begin(), (a).end() #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define PB push_back #define MP make_pair template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { ll k, a, b; scanf("%lld%lld%lld", &k, &a, &b); ll ans = ((k - (a - 1)) / 2) * (b - a) + k % (((k - (a - 1)) / 2)) + 1; chmax(ans, k + 1); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = a; i <= b; i++) #define FORD(i, a, b) for (int i = a; i >= b; i--) #define FORL(i, x) for (int i = head[x]; i; i = nxt[i]) #define ALL(a) (a).begin(), (a).end() #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define PB push_back #define MP make_pair template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { ll k, a, b; scanf("%lld%lld%lld", &k, &a, &b); ll ans = ((k - (a - 1)) / 2) * (b - a) + a + (k - (a - 1)) % 2; chmax(ans, k + 1); cout << ans << endl; }
replace
33
34
33
34
0
p03131
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; #define maxn 100000 + 5 typedef long long int ll; const double INF = 1e20; const double pi = acos(-1.0); int vis[5]; int main() { ll k, a, b; scanf("%lld%lld%lld", &k, &a, &b); if (b - a <= 1) { printf("%lld", k + 1); } else { ll ans = 1; ans += (a - 1); k -= (a - 1); // cout<<k<<endl; ans += (k / 2) * (b - a); k -= (k / 2) * 2; if (k == 1) ans++; printf("%lld", ans); } while (1) getchar(); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; #define maxn 100000 + 5 typedef long long int ll; const double INF = 1e20; const double pi = acos(-1.0); int vis[5]; int main() { ll k, a, b; scanf("%lld%lld%lld", &k, &a, &b); if (b - a <= 1) { printf("%lld", k + 1); } else { ll ans = 1; ans += (a - 1); k -= (a - 1); // cout<<k<<endl; ans += (k / 2) * (b - a); k -= (k / 2) * 2; if (k == 1) ans++; printf("%lld", ans); } // while(1)getchar(); return 0; }
replace
31
33
31
32
TLE
p03131
C++
Runtime Error
#include <bits/stdc++.h> #define pt(sth) cout << sth << "\n" #define chmax(a, b) \ { \ if (a < b) \ a = b; \ } #define chmin(a, b) \ { \ if (a > b) \ a = b; \ } #define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD using namespace std; typedef long long ll; typedef pair<ll, ll> P; static const ll INF = 1e18; static const ll MAX = 101010; static const ll MOD = 1e9 + 7; int main(void) { ll k, a, b; cin >> k >> a >> b; ll ans = max(1 + k, (b - a) / (k / 2) + k % 2); pt(ans); }
#include <bits/stdc++.h> #define pt(sth) cout << sth << "\n" #define chmax(a, b) \ { \ if (a < b) \ a = b; \ } #define chmin(a, b) \ { \ if (a > b) \ a = b; \ } #define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD using namespace std; typedef long long ll; typedef pair<ll, ll> P; static const ll INF = 1e18; static const ll MAX = 101010; static const ll MOD = 1e9 + 7; int main(void) { ll k, a, b; cin >> k >> a >> b; ll t = a - 1; ll ans = max(1 + k, a + (b - a) * ((k - t) / 2) + (k - t) % 2); pt(ans); }
replace
24
25
24
26
0
p03131
C++
Runtime Error
// submitted by Himj #include <bits/stdc++.h> #define ll long long #define mod 1000000007 #define pb push_back #define fi first #define se second #define fr(i, s, e) for (i = s; i < e; i++) #define ms(arr, val) memset(arr, val, sizeof(arr)) using namespace std; const int mxn = 2e5 + 1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin>>t; while (t--) { ll k, a, b, cur = 1; cin >> k >> a >> b; if (b - a > 2) { ll temp = min(a - cur, k); k -= temp; cur += temp; temp = k / 2; cur += temp * (b - a); if (k % 2) cur++; } else cur += k; cout << cur; } return 0; }
// submitted by Himj #include <bits/stdc++.h> #define ll long long #define mod 1000000007 #define pb push_back #define fi first #define se second #define fr(i, s, e) for (i = s; i < e; i++) #define ms(arr, val) memset(arr, val, sizeof(arr)) using namespace std; const int mxn = 2e5 + 1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { ll k, a, b, cur = 1; cin >> k >> a >> b; if (b - a > 2) { ll temp = min(a - cur, k); k -= temp; cur += temp; temp = k / 2; cur += temp * (b - a); if (k % 2) cur++; } else cur += k; cout << cur; } return 0; }
replace
17
21
17
18
0
p03132
C++
Runtime Error
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv #include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1); #define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++) #define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME #define each(i, a) for (auto &&i : a) #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__) #define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__) #define pb push_back #define eb emplace_back #define all(a) begin(a), end(a) #define chmin(x, v) x = min(x, v) #define chmax(x, v) x = max(x, v) #define min(x, y) (x < y ? x : y) #define max(x, y) (x < y ? y : x) template <typename Head> void out(Head h) { cout << h << endl; } template <typename Head, typename... Tail> void out(Head h, Tail... t) { cout << h << " "; out(t...); } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << " "; os << v[i]; } return os; } ostream &operator<<(ostream &os, const vector<string> &v) { rep(i, v.size()) { if (i) os << endl; os << v[i]; } return os; } template <typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { rep(i, v.size()) { if (i) os << endl; os << v[i]; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << "(" << p.first << ", " << p.second << ")"; } struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } }; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha; solve(); } // ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^ void solve() { ll n; cin >> n; vector<ll> a(n); cin >> a; vector<ll> Sl(n + 1, 0), Sr(n + 1, 0); rep(i, n) Sl[i + 1] = Sl[i] + a[i]; rrep(i, n) Sr[i] = Sr[i + 1] + a[i]; vector<vector<ll>> dp(n + 1, vector<ll>(5, linf)); dp[0][0] = 0; rep(i, n) { rep(j, 5) { if (dp[i][j] == linf) continue; // cout << i << " " << j << ": " << dp[i][j] << endl; chmin(dp[i][j + 1], dp[i][j]); // mode 0, 4 if (j == 0 || j == 4) { chmin(dp[i + 1][j], dp[i][j] + a[i]); } // mode 1, 3 if (j == 1 || j == 3) { ll cost = a[i] == 0 ? 2 : a[i] == 1 ? 1 : a[i] % 2; chmin(dp[i + 1][j], dp[i][j] + cost); } // mode 2 if (j == 2) { ll cost = a[i] == 0 ? 1 : 1 - a[i] % 2; chmin(dp[i + 1][j], dp[i][j] + cost); } } } ll ans = linf; rep(j, 5) chmin(ans, dp[n][j]); cout << ans << endl; }
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv #include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1); #define FOR(i, a, b) for (ll i = (a), __last_##i = (b); i < __last_##i; i++) #define RFOR(i, a, b) for (ll i = (b)-1, __last_##i = (a); i >= __last_##i; i--) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME #define each(i, a) for (auto &&i : a) #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__) #define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__) #define pb push_back #define eb emplace_back #define all(a) begin(a), end(a) #define chmin(x, v) x = min(x, v) #define chmax(x, v) x = max(x, v) #define min(x, y) (x < y ? x : y) #define max(x, y) (x < y ? y : x) template <typename Head> void out(Head h) { cout << h << endl; } template <typename Head, typename... Tail> void out(Head h, Tail... t) { cout << h << " "; out(t...); } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << " "; os << v[i]; } return os; } ostream &operator<<(ostream &os, const vector<string> &v) { rep(i, v.size()) { if (i) os << endl; os << v[i]; } return os; } template <typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { rep(i, v.size()) { if (i) os << endl; os << v[i]; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << "(" << p.first << ", " << p.second << ")"; } struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } }; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha; solve(); } // ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^ void solve() { ll n; cin >> n; vector<ll> a(n); cin >> a; vector<ll> Sl(n + 1, 0), Sr(n + 1, 0); rep(i, n) Sl[i + 1] = Sl[i] + a[i]; rrep(i, n) Sr[i] = Sr[i + 1] + a[i]; vector<vector<ll>> dp(n + 1, vector<ll>(5, linf)); dp[0][0] = 0; rep(i, n) { rep(j, 5) { if (dp[i][j] == linf) continue; // cout << i << " " << j << ": " << dp[i][j] << endl; if (j < 4) { chmin(dp[i][j + 1], dp[i][j]); } // mode 0, 4 if (j == 0 || j == 4) { chmin(dp[i + 1][j], dp[i][j] + a[i]); } // mode 1, 3 if (j == 1 || j == 3) { ll cost = a[i] == 0 ? 2 : a[i] == 1 ? 1 : a[i] % 2; chmin(dp[i + 1][j], dp[i][j] + cost); } // mode 2 if (j == 2) { ll cost = a[i] == 0 ? 1 : 1 - a[i] % 2; chmin(dp[i + 1][j], dp[i][j] + cost); } } } ll ans = linf; rep(j, 5) chmin(ans, dp[n][j]); cout << ans << endl; }
replace
90
91
90
93
-6
free(): invalid pointer
p03132
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define lint long long #define P pair<int, int> #define LLP pair<long long, long long> #define REP(i, x, n) for (int i = (x), i##_len = (int)(n); i < i##_len; ++i) #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i) #define repr(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define SORT(x) sort((x).begin(), (x).end()) #define SORT_INV(x) sort((x).rbegin(), (x).rend()) const int IINF = 1e9 + 100; const long long LLINF = 2e18 + 129; const long long MOD = 1e9 + 7; const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1}; const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1}; const double EPS = 1e-8; vector<lint> a; lint cost(int i, int k) { if (k == 0 || k == 4) { return a[i]; } else if (k == 1 || k == 3) { if (a[i] == 0) { return 2LL; } else if (a[i] % 2 == 0) { return 0LL; } else { return 1LL; } } else { if (a[i] % 2 == 0) { return 1LL; } else { return 0LL; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); lint l; cin >> l; a.resize(l); rep(i, l) { cin >> a[i]; } lint dp[100010][5]; fill(dp[0], dp[l + 1], LLINF); dp[0][0] = 0; rep(i, l) { rep(j, 5) { REP(k, j, 5) { dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + cost(i, k)); } } } lint ans = LLINF; rep(i, 5) { ans = min(ans, dp[l][i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define lint long long #define P pair<int, int> #define LLP pair<long long, long long> #define REP(i, x, n) for (int i = (x), i##_len = (int)(n); i < i##_len; ++i) #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i) #define repr(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define SORT(x) sort((x).begin(), (x).end()) #define SORT_INV(x) sort((x).rbegin(), (x).rend()) const int IINF = 1e9 + 100; const long long LLINF = 2e18 + 129; const long long MOD = 1e9 + 7; const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1}; const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1}; const double EPS = 1e-8; vector<lint> a; lint cost(int i, int k) { if (k == 0 || k == 4) { return a[i]; } else if (k == 1 || k == 3) { if (a[i] == 0) { return 2LL; } else if (a[i] % 2 == 0) { return 0LL; } else { return 1LL; } } else { if (a[i] % 2 == 0) { return 1LL; } else { return 0LL; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); lint l; cin >> l; a.resize(l); rep(i, l) { cin >> a[i]; } lint dp[200010][5]; fill(dp[0], dp[l + 1], LLINF); dp[0][0] = 0; rep(i, l) { rep(j, 5) { REP(k, j, 5) { dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + cost(i, k)); } } } lint ans = LLINF; rep(i, 5) { ans = min(ans, dp[l][i]); } cout << ans << endl; return 0; }
replace
52
53
52
53
0
p03132
C++
Runtime Error
#include <bits/stdc++.h> 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 INF = (9e18); const int maxn = (1e5) + 10; int n, a[maxn]; ll dp[maxn][5], ans = INF; int op(int i, int j) { if (j == 1 || j == 3) { if (a[i] == 0) return 2; return a[i] & 1; } if (j == 2) return a[i] & 1 ^ 1; return a[i]; } int main() { // freopen("1.txt","r",stdin); read(n); for (int i = 1; i <= n; i++) read(a[i]); for (int i = 1; i <= n; i++) for (int j = 0; j <= 4; j++) { dp[i][j] = INF; for (int k = 0; k <= j; k++) dp[i][j] = min(dp[i][j], dp[i - 1][k]); dp[i][j] += op(i, j); if (i == n) ans = min(ans, dp[i][j]); } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> 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 INF = (9e18); const int maxn = (2e5) + 10; int n, a[maxn]; ll dp[maxn][5], ans = INF; int op(int i, int j) { if (j == 1 || j == 3) { if (a[i] == 0) return 2; return a[i] & 1; } if (j == 2) return a[i] & 1 ^ 1; return a[i]; } int main() { // freopen("1.txt","r",stdin); read(n); for (int i = 1; i <= n; i++) read(a[i]); for (int i = 1; i <= n; i++) for (int j = 0; j <= 4; j++) { dp[i][j] = INF; for (int k = 0; k <= j; k++) dp[i][j] = min(dp[i][j], dp[i - 1][k]); dp[i][j] += op(i, j); if (i == n) ans = min(ans, dp[i][j]); } printf("%lld\n", ans); return 0; }
replace
19
20
19
20
0
p03132
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using uint = unsigned int; using P = pair<int, int>; using node = pair<string, ll>; const ll inf = numeric_limits<ll>::max() / 3; const ll mod = 1e9 + 7; ll a[100100]; ll acc[100100]; ll to_left[100100]; ll to_right[100100]; ll dp[100100]; int main(void) { int l; cin >> l; acc[0] = 0LL; for (int i = 1; i <= l; ++i) { cin >> a[i]; acc[i] = acc[i - 1] + a[i]; } to_left[0] = 0LL; for (int i = 1; i <= l; ++i) { if (a[i] == 0) { to_left[i] = min(2 + to_left[i - 1], acc[i]); } else { to_left[i] = min(a[i] % 2 + to_left[i - 1], acc[i]); } } to_right[l] = 0LL; for (int i = l - 1; i >= 0; --i) { if (a[i + 1] == 0) { to_right[i] = min(2 + to_right[i + 1], acc[l] - acc[i]); } else { to_right[i] = min(a[i + 1] % 2 + to_right[i + 1], acc[l] - acc[i]); } } dp[0] = 0LL; for (int i = 1; i <= l; ++i) { dp[i] = min((a[i] + 1) % 2 + dp[i - 1], to_left[i]); } ll res = inf; for (int i = 0; i <= l; ++i) { res = min(res, dp[i] + to_right[i]); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using uint = unsigned int; using P = pair<int, int>; using node = pair<string, ll>; const ll inf = numeric_limits<ll>::max() / 3; const ll mod = 1e9 + 7; ll a[200200]; ll acc[200200]; ll to_left[200200]; ll to_right[200200]; ll dp[200200]; int main(void) { int l; cin >> l; acc[0] = 0LL; for (int i = 1; i <= l; ++i) { cin >> a[i]; acc[i] = acc[i - 1] + a[i]; } to_left[0] = 0LL; for (int i = 1; i <= l; ++i) { if (a[i] == 0) { to_left[i] = min(2 + to_left[i - 1], acc[i]); } else { to_left[i] = min(a[i] % 2 + to_left[i - 1], acc[i]); } } to_right[l] = 0LL; for (int i = l - 1; i >= 0; --i) { if (a[i + 1] == 0) { to_right[i] = min(2 + to_right[i + 1], acc[l] - acc[i]); } else { to_right[i] = min(a[i + 1] % 2 + to_right[i + 1], acc[l] - acc[i]); } } dp[0] = 0LL; for (int i = 1; i <= l; ++i) { dp[i] = min((a[i] + 1) % 2 + dp[i - 1], to_left[i]); } ll res = inf; for (int i = 0; i <= l; ++i) { res = min(res, dp[i] + to_right[i]); } cout << res << endl; return 0; }
replace
9
14
9
14
0
p03132
C++
Runtime Error
#include <bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long #define vi vector<ll> #define vvi vector<vi> #define BITLE(n) (1LL << (n)) #define BITCNT(n) (__builtin_popcountll(n)) #define SUBS(s, f, t) (s.substr(f - 1, t - f + 1)) #define ALL(a) (a).begin(), (a).end() using namespace std; struct Grid { ll x, y, t; }; struct Edge { ll to, cost; }; struct Graph { vector<vector<Edge>> E; int V; const ll Inf = llINF; const int MAX_V = 201010; vector<ll> d; Graph(int n) : E(n) { d.resize(MAX_V); E.resize(n); V = n; } void init() { for (int i = 0; i < MAX_V; i++) d[i] = Inf; } void add_edge(ll from, ll to, ll cost) { E[from].pb({to, cost}); } }; ll L; vi A(210000); ll dp[210000][5]; ll cost(ll sta, ll i) { if (sta == 0 || sta == 4) { return A[i]; } else if (sta == 1 || sta == 3) { if (A[i] % 2 == 0 && A[i] != 0) return 0; else if (A[i] == 0) return 2; else return 1; } else if (sta == 2) { return (A[i] % 2 == 0) ? 1 : 0; } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> L; for (int i = 0; i < L; i++) cin >> A[i]; for (int i = 0; i < 210000; i++) for (int j = 0; j < 5; j++) dp[i][j] = llINF; dp[0][0] = 0; for (int i = 0; i < 210000; i++) { for (int j = 0; j < 5; j++) { for (int k = j; k < 5; k++) dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + cost(k, i)); } } ll ans = llINF; for (int i = 0; i < 5; i++) ans = min(ans, dp[L][i]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1000000007 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long #define vi vector<ll> #define vvi vector<vi> #define BITLE(n) (1LL << (n)) #define BITCNT(n) (__builtin_popcountll(n)) #define SUBS(s, f, t) (s.substr(f - 1, t - f + 1)) #define ALL(a) (a).begin(), (a).end() using namespace std; struct Grid { ll x, y, t; }; struct Edge { ll to, cost; }; struct Graph { vector<vector<Edge>> E; int V; const ll Inf = llINF; const int MAX_V = 201010; vector<ll> d; Graph(int n) : E(n) { d.resize(MAX_V); E.resize(n); V = n; } void init() { for (int i = 0; i < MAX_V; i++) d[i] = Inf; } void add_edge(ll from, ll to, ll cost) { E[from].pb({to, cost}); } }; ll L; vi A(210000); ll dp[210000][5]; ll cost(ll sta, ll i) { if (sta == 0 || sta == 4) { return A[i]; } else if (sta == 1 || sta == 3) { if (A[i] % 2 == 0 && A[i] != 0) return 0; else if (A[i] == 0) return 2; else return 1; } else if (sta == 2) { return (A[i] % 2 == 0) ? 1 : 0; } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> L; for (int i = 0; i < L; i++) cin >> A[i]; for (int i = 0; i < 210000; i++) for (int j = 0; j < 5; j++) dp[i][j] = llINF; dp[0][0] = 0; for (int i = 0; i < L; i++) { for (int j = 0; j < 5; j++) { for (int k = j; k < 5; k++) dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + cost(k, i)); } } ll ans = llINF; for (int i = 0; i < 5; i++) ans = min(ans, dp[L][i]); cout << ans << endl; return 0; }
replace
67
68
67
68
0
p03132
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef vector<string> VS; typedef pair<int, int> P; typedef tuple<int, int, int> tpl; #define ALL(a) (a).begin(), (a).end() #define SORT(c) sort((c).begin(), (c).end()) #define REVERSE(c) reverse((c).begin(), (c).end()) #define EXIST(m, v) (m).find((v)) != (m).end() #define LB(a, x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a, x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define RFOR(i, a, b) for (int i = (a)-1; i >= (b); --i) #define RREP(i, n) RFOR(i, n, 0) #define en "\n" constexpr double EPS = 1e-9; constexpr double PI = 3.1415926535897932; constexpr int INF = 2147483647; constexpr long long LINF = 1LL << 60; constexpr long long MOD = 1000000007; // 998244353; #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } void Main() { int L; cin >> L; VL A(L); REP(i, L) cin >> A[i]; ll dp[L + 1][5]; REP(i, L + 1) REP(j, 5) dp[i][j] = LINF; REP(i, 5) dp[0][i] = 0; REP(i, L) REP(j, 5) { if (j == 0 || j == 4) chmin(dp[i + 1][j], dp[i][j] + A[i]); else if (j == 2) chmin(dp[i + 1][j], dp[i][j] + (A[i] % 2 != 1)); else if (j < 4) { if (A[i] > 0) chmin(dp[i + 1][j], dp[i][j] + (A[i] % 2 != 0)); else chmin(dp[i + 1][j], dp[i][j] + 2); } if (j < 4) chmin(dp[i + 1][j + 1], dp[i + 1][j]); } ll ans = dp[L][4]; cout << ans << en; return; } int main(void) { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(15); int t = 1; cin >> t; REP(_, t) Main(); return 0; }
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef vector<string> VS; typedef pair<int, int> P; typedef tuple<int, int, int> tpl; #define ALL(a) (a).begin(), (a).end() #define SORT(c) sort((c).begin(), (c).end()) #define REVERSE(c) reverse((c).begin(), (c).end()) #define EXIST(m, v) (m).find((v)) != (m).end() #define LB(a, x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a, x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define RFOR(i, a, b) for (int i = (a)-1; i >= (b); --i) #define RREP(i, n) RFOR(i, n, 0) #define en "\n" constexpr double EPS = 1e-9; constexpr double PI = 3.1415926535897932; constexpr int INF = 2147483647; constexpr long long LINF = 1LL << 60; constexpr long long MOD = 1000000007; // 998244353; #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } void Main() { int L; cin >> L; VL A(L); REP(i, L) cin >> A[i]; ll dp[L + 1][5]; REP(i, L + 1) REP(j, 5) dp[i][j] = LINF; REP(i, 5) dp[0][i] = 0; REP(i, L) REP(j, 5) { if (j == 0 || j == 4) chmin(dp[i + 1][j], dp[i][j] + A[i]); else if (j == 2) chmin(dp[i + 1][j], dp[i][j] + (A[i] % 2 != 1)); else if (j < 4) { if (A[i] > 0) chmin(dp[i + 1][j], dp[i][j] + (A[i] % 2 != 0)); else chmin(dp[i + 1][j], dp[i][j] + 2); } if (j < 4) chmin(dp[i + 1][j + 1], dp[i + 1][j]); } ll ans = dp[L][4]; cout << ans << en; return; } int main(void) { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(15); int t = 1; // cin>>t; REP(_, t) Main(); return 0; }
replace
100
102
100
101
0
p03132
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> using namespace std; #define ll long long #define N 200010 char getc() { char c = getchar(); while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9')) c = getchar(); return c; } int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); } int read() { int 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 << 1) + (x << 3) + (c ^ 48), c = getchar(); return x * f; } int n, a[N], delta[N]; ll f[N][5]; // ll ans,f[N][2],s[N],g[N][2],h[N]; int main() { freopen("d.in", "r", stdin); freopen("d.out", "w", stdout); n = read(); for (int i = 1; i <= n; i++) a[i] = read(); /*for (int i=1;i<=n;i++) if (a[i]==0) delta[i]=2; else delta[i]=a[i]&1; for (int i=1;i<=n;i++) g[i][0]=g[i-1][0]+delta[i],s[i]=s[i-1]+a[i]; ll u=0; for (int i=1;i<=n;i++) { u=min(u,s[i]-g[i][0]); f[i][0]=g[i][0]+u; } for (int i=n;i>=1;i--) g[i][1]=g[i+1][1]+delta[i],s[i]=s[i+1]+a[i]; u=0; for (int i=n;i>=1;i--) { u=min(u,s[i]-g[i][1]); f[i][1]=g[i][1]+u; } for (int i=1;i<=n;i++) ans+=a[i]; u=0; for (int i=1;i<=n;i++) ans=min(ans,f[i][1]+s[i-1]); for (int i=1;i<=n;i++) h[i]=h[i-1]+(a[i]&1^1); for (int i=1;i<=n+1;i++) { ans=min(ans,f[i][1]+u+h[i-1]); u=min(u,f[i][0]-h[i]); }*/ for (int i = 1; i <= n; i++) { f[i][0] = f[i - 1][0]; for (int j = 1; j <= 4; j++) f[i][j] = min(f[i][j - 1], f[i - 1][j]); f[i][0] += a[i], f[i][4] += a[i]; f[i][1] += a[i] == 0 ? 2 : (a[i] & 1); f[i][3] += a[i] == 0 ? 2 : (a[i] & 1); f[i][2] += a[i] & 1 ^ 1; } ll ans = f[n][0]; for (int i = 1; i <= 4; i++) ans = min(ans, f[n][i]); cout << ans; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> using namespace std; #define ll long long #define N 200010 char getc() { char c = getchar(); while ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && (c < '0' || c > '9')) c = getchar(); return c; } int gcd(int n, int m) { return m == 0 ? n : gcd(m, n % m); } int read() { int 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 << 1) + (x << 3) + (c ^ 48), c = getchar(); return x * f; } int n, a[N], delta[N]; ll f[N][5]; // ll ans,f[N][2],s[N],g[N][2],h[N]; int main() { n = read(); for (int i = 1; i <= n; i++) a[i] = read(); /*for (int i=1;i<=n;i++) if (a[i]==0) delta[i]=2; else delta[i]=a[i]&1; for (int i=1;i<=n;i++) g[i][0]=g[i-1][0]+delta[i],s[i]=s[i-1]+a[i]; ll u=0; for (int i=1;i<=n;i++) { u=min(u,s[i]-g[i][0]); f[i][0]=g[i][0]+u; } for (int i=n;i>=1;i--) g[i][1]=g[i+1][1]+delta[i],s[i]=s[i+1]+a[i]; u=0; for (int i=n;i>=1;i--) { u=min(u,s[i]-g[i][1]); f[i][1]=g[i][1]+u; } for (int i=1;i<=n;i++) ans+=a[i]; u=0; for (int i=1;i<=n;i++) ans=min(ans,f[i][1]+s[i-1]); for (int i=1;i<=n;i++) h[i]=h[i-1]+(a[i]&1^1); for (int i=1;i<=n+1;i++) { ans=min(ans,f[i][1]+u+h[i-1]); u=min(u,f[i][0]-h[i]); }*/ for (int i = 1; i <= n; i++) { f[i][0] = f[i - 1][0]; for (int j = 1; j <= 4; j++) f[i][j] = min(f[i][j - 1], f[i - 1][j]); f[i][0] += a[i], f[i][4] += a[i]; f[i][1] += a[i] == 0 ? 2 : (a[i] & 1); f[i][3] += a[i] == 0 ? 2 : (a[i] & 1); f[i][2] += a[i] & 1 ^ 1; } ll ans = f[n][0]; for (int i = 1; i <= 4; i++) ans = min(ans, f[n][i]); cout << ans; return 0; }
delete
32
34
32
32
TLE
p03132
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, l, r) for (register int i = l; i <= r; i++) #define repd(i, r, l) for (register int i = r; i >= l; i--) #define rvc(i, S) for (register int i = 0; i < (int)S.size(); i++) #define rvcd(i, S) for (register int i = ((int)S.size()) - 1; i >= 0; i--) #define fore(i, x) for (register int i = head[x]; i; i = e[i].next) #define forup(i, l, r) for (register int i = l; i <= r; i += lowbit(i)) #define fordown(i, id) for (register int i = id; i; i -= lowbit(i)) #define pb push_back #define prev prev_ #define stack stack_ #define mp make_pair #define fi first #define se second #define lowbit(x) (x & (-x)) typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pr; const ll inf = 2e18; const int N = 3e6 + 10; const int maxn = 100020; const ll mod = 1e9 + 7; int a[maxn], n; ll sum[maxn], cnt0[maxn], cnt1[maxn], cnt2[maxn], mn2[maxn], mn[maxn]; int main() { scanf("%d", &n); rep(i, 1, n) { scanf("%d", &a[i]), sum[i] = a[i] + sum[i - 1]; cnt0[i] = cnt0[i - 1]; cnt2[i] = cnt2[i - 1]; cnt1[i] = cnt1[i - 1]; if (a[i] % 2 == 0) { if (a[i]) cnt2[i]++; else cnt0[i]++; } else cnt1[i]++; } memset(mn, 0x3f, sizeof(mn)); memset(mn2, 0x3f, sizeof(mn)); ll premn = inf, postmn = inf; rep(i, 1, n + 1) { premn = min(premn, sum[i - 1] - cnt1[i - 1] - 2 * cnt0[i - 1]); mn[i] = min(mn[i - 1], premn + cnt0[i - 1] * 2 + cnt1[i - 1] - cnt0[i - 1] - cnt2[i - 1]); } repd(i, n, 1) { postmn = min(postmn, sum[n] - sum[i] + cnt0[i] * 2 + cnt1[i]); mn2[i] = min(mn2[i + 1], postmn + cnt0[i] + cnt2[i] - cnt0[i] * 2 - cnt1[i]); } ll ans = inf; rep(i, 1, n) ans = min(ans, mn[i + 1] + mn2[i]); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, l, r) for (register int i = l; i <= r; i++) #define repd(i, r, l) for (register int i = r; i >= l; i--) #define rvc(i, S) for (register int i = 0; i < (int)S.size(); i++) #define rvcd(i, S) for (register int i = ((int)S.size()) - 1; i >= 0; i--) #define fore(i, x) for (register int i = head[x]; i; i = e[i].next) #define forup(i, l, r) for (register int i = l; i <= r; i += lowbit(i)) #define fordown(i, id) for (register int i = id; i; i -= lowbit(i)) #define pb push_back #define prev prev_ #define stack stack_ #define mp make_pair #define fi first #define se second #define lowbit(x) (x & (-x)) typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pr; const ll inf = 2e18; const int N = 3e6 + 10; const int maxn = 200020; const ll mod = 1e9 + 7; int a[maxn], n; ll sum[maxn], cnt0[maxn], cnt1[maxn], cnt2[maxn], mn2[maxn], mn[maxn]; int main() { scanf("%d", &n); rep(i, 1, n) { scanf("%d", &a[i]), sum[i] = a[i] + sum[i - 1]; cnt0[i] = cnt0[i - 1]; cnt2[i] = cnt2[i - 1]; cnt1[i] = cnt1[i - 1]; if (a[i] % 2 == 0) { if (a[i]) cnt2[i]++; else cnt0[i]++; } else cnt1[i]++; } memset(mn, 0x3f, sizeof(mn)); memset(mn2, 0x3f, sizeof(mn)); ll premn = inf, postmn = inf; rep(i, 1, n + 1) { premn = min(premn, sum[i - 1] - cnt1[i - 1] - 2 * cnt0[i - 1]); mn[i] = min(mn[i - 1], premn + cnt0[i - 1] * 2 + cnt1[i - 1] - cnt0[i - 1] - cnt2[i - 1]); } repd(i, n, 1) { postmn = min(postmn, sum[n] - sum[i] + cnt0[i] * 2 + cnt1[i]); mn2[i] = min(mn2[i + 1], postmn + cnt0[i] + cnt2[i] - cnt0[i] * 2 - cnt1[i]); } ll ans = inf; rep(i, 1, n) ans = min(ans, mn[i + 1] + mn2[i]); cout << ans << endl; }
replace
25
26
25
26
0
p03132
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <cfloat> #include <cmath> #include <cstdint> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using lint = int64_t; using uint = uint32_t; using ulint = uint64_t; template <class T> using vector2d = vector<vector<T>>; template <class T> bool UpdateMax(T &a, const T &b) { if (a < b) { a = b; return true; } else { return false; } } template <class T> bool UpdateMin(T &a, const T &b) { if (a > b) { a = b; return true; } else { return false; } } template <class T> void OutVec(const vector<T> &vec) { for (int i = 0; i < vec.size() - 1; ++i) { cout << vec[i] << " "; } cout << vec.back() << endl; } template <class T> void OutVec2d(const vector2d<T> &vec) { for (auto v : vec) { OutVec(v); } } int main() { cout << std::fixed << std::setprecision(16); cin.tie(nullptr); std::ios::sync_with_stdio(false); int l; cin >> l; vector<lint> a(l), odd(l), even(l), cum(l); for (int i = 0; i < l; i++) { cin >> a[i]; if (a[i] == 0) { odd[i] = 1; even[i] = 2; } else { odd[i] = (a[i] % 2 == 0) ? 1 : 0; even[i] = (a[i] % 2 == 0) ? 0 : 1; } cum[i] = a[i]; if (i != 0) { cum[i] += cum[i - 1]; } } const lint INF = INT64_MAX - 10; vector2d<lint> dp(l, vector<lint>(5, INF)); dp[0][0] = a[0]; dp[0][1] = even[0]; dp[0][2] = odd[0]; for (int i = 1; i < l; i++) { dp[i][0] = dp[i - 1][0] + a[i]; dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + even[i]; dp[i][2] = min({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) + odd[i]; dp[i][3] = min(dp[i - 1][2], dp[i - 1][3]) + even[i]; } lint result = min( {dp[l - 1][0], dp[l - 1][1], dp[l - 1][2], dp[l - 1][3], dp[l - 1][4]}); for (int i = 1; i < l; i++) { for (int j = 0; j < l; j++) { if (dp[i - 1][j] == INF) continue; lint tmp_result = dp[i - 1][j] + cum[l - 1] - cum[i - 1]; UpdateMin(result, tmp_result); } } cout << result << endl; return 0; }
#include <algorithm> #include <cassert> #include <cfloat> #include <cmath> #include <cstdint> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using lint = int64_t; using uint = uint32_t; using ulint = uint64_t; template <class T> using vector2d = vector<vector<T>>; template <class T> bool UpdateMax(T &a, const T &b) { if (a < b) { a = b; return true; } else { return false; } } template <class T> bool UpdateMin(T &a, const T &b) { if (a > b) { a = b; return true; } else { return false; } } template <class T> void OutVec(const vector<T> &vec) { for (int i = 0; i < vec.size() - 1; ++i) { cout << vec[i] << " "; } cout << vec.back() << endl; } template <class T> void OutVec2d(const vector2d<T> &vec) { for (auto v : vec) { OutVec(v); } } int main() { cout << std::fixed << std::setprecision(16); cin.tie(nullptr); std::ios::sync_with_stdio(false); int l; cin >> l; vector<lint> a(l), odd(l), even(l), cum(l); for (int i = 0; i < l; i++) { cin >> a[i]; if (a[i] == 0) { odd[i] = 1; even[i] = 2; } else { odd[i] = (a[i] % 2 == 0) ? 1 : 0; even[i] = (a[i] % 2 == 0) ? 0 : 1; } cum[i] = a[i]; if (i != 0) { cum[i] += cum[i - 1]; } } const lint INF = INT64_MAX - 10; vector2d<lint> dp(l, vector<lint>(5, INF)); dp[0][0] = a[0]; dp[0][1] = even[0]; dp[0][2] = odd[0]; for (int i = 1; i < l; i++) { dp[i][0] = dp[i - 1][0] + a[i]; dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + even[i]; dp[i][2] = min({dp[i - 1][0], dp[i - 1][1], dp[i - 1][2]}) + odd[i]; dp[i][3] = min(dp[i - 1][2], dp[i - 1][3]) + even[i]; } lint result = min( {dp[l - 1][0], dp[l - 1][1], dp[l - 1][2], dp[l - 1][3], dp[l - 1][4]}); for (int i = 1; i < l; i++) { for (int j = 0; j < 4; j++) { if (dp[i - 1][j] == INF) continue; lint tmp_result = dp[i - 1][j] + cum[l - 1] - cum[i - 1]; UpdateMin(result, tmp_result); } } cout << result << endl; return 0; }
replace
92
93
92
93
TLE
p03132
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define vvi vector<vector<int>> #define vec vector #define pq priority_queue #define all(v) (v).begin(), (v).end() #define uniqueV(x) \ sort(x.begin(), x.end()); \ x.erase(unique(x.begin(), x.end()), x.end()); #define rep(i, n) for (int(i) = (0); (i) < (n); ++(i)) #define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i)) #define dbg(x) cerr << #x << ": " << x << endl; #define dbg2(x, y) \ cerr << "(" << #x << ", " << #y << ") = " \ << "(" << x << ", " << y << ")" << endl; #define dbg3(x, y, z) \ cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \ << "(" << x << ", " << y << ", " << z << ")" << endl; #define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl; #define line() cerr << "---------------" << endl; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const double PI = 3.14159265358979323846; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T> void print1(T begin, T end) { while (begin != end) { cout << (*begin) << " "; *begin++; } cout << endl; } template <typename T> void print2(T Array, int height, int width) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { cout << " " << Array[i][j]; } cout << endl; } } void print() { std::cerr << endl; } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { std::cerr << head << " "; print(std::forward<Tail>(tail)...); } template <class T> void Add(T &a, const T &b, const T &mod = 1e9 + 7) { int val = ((a % mod) + (b % mod)) % mod; if (val < 0) { val += mod; } a = val; } // ------------------------------------------------------------------------------------------ const int INF = 1e18; int score(int a, int t) { if (t == 0 || t == 4) return a; if (t == 1 || t == 3) { if (a == 0) return 2; return a % 2; } return (a + 1) % 2; } int A[111111]; int dp[111111][5]; signed main() { int n; cin >> n; rep(i, n) cin >> A[i]; rep(i, n + 1) rep(j, 5) dp[i][j] = INF; rep(j, 5) dp[0][j] = 0; rep(i, n) { rep(j, 5) { if (j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + score(A[i], j)); } } int ret = INF; rep(i, 5) { ret = min(ret, dp[n][i]); } cout << ret << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define vvi vector<vector<int>> #define vec vector #define pq priority_queue #define all(v) (v).begin(), (v).end() #define uniqueV(x) \ sort(x.begin(), x.end()); \ x.erase(unique(x.begin(), x.end()), x.end()); #define rep(i, n) for (int(i) = (0); (i) < (n); ++(i)) #define repp(i, m, n) for (int(i) = (m); (i) < (n); ++(i)) #define dbg(x) cerr << #x << ": " << x << endl; #define dbg2(x, y) \ cerr << "(" << #x << ", " << #y << ") = " \ << "(" << x << ", " << y << ")" << endl; #define dbg3(x, y, z) \ cerr << "(" << #x << ", " << #y << ", " << #z << ") = " \ << "(" << x << ", " << y << ", " << z << ")" << endl; #define dbgB(value, size) cerr << #value << ": " << bitset<size>(value) << endl; #define line() cerr << "---------------" << endl; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const double PI = 3.14159265358979323846; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T> void print1(T begin, T end) { while (begin != end) { cout << (*begin) << " "; *begin++; } cout << endl; } template <typename T> void print2(T Array, int height, int width) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { cout << " " << Array[i][j]; } cout << endl; } } void print() { std::cerr << endl; } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { std::cerr << head << " "; print(std::forward<Tail>(tail)...); } template <class T> void Add(T &a, const T &b, const T &mod = 1e9 + 7) { int val = ((a % mod) + (b % mod)) % mod; if (val < 0) { val += mod; } a = val; } // ------------------------------------------------------------------------------------------ const int INF = 1e18; int score(int a, int t) { if (t == 0 || t == 4) return a; if (t == 1 || t == 3) { if (a == 0) return 2; return a % 2; } return (a + 1) % 2; } int A[222222]; int dp[222222][5]; signed main() { int n; cin >> n; rep(i, n) cin >> A[i]; rep(i, n + 1) rep(j, 5) dp[i][j] = INF; rep(j, 5) dp[0][j] = 0; rep(i, n) { rep(j, 5) { if (j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + score(A[i], j)); } } int ret = INF; rep(i, 5) { ret = min(ret, dp[n][i]); } cout << ret << endl; return 0; }
replace
88
90
88
90
0
p03132
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int inf = 1e15 + 10, N = 1e5 + 10; int a[N], n; long long dp[N][6], ans = inf; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) for (int j = 0; j < 5; j++) dp[i][j] = inf; for (int i = 0; i < n; i++) { for (int j = 0; j < 5; j++) { int w = 0; if (a[i] == 0 && j != 0 && j != 4) w = 1 + (j % 2); else if (j == 2 && a[i] % 2 == 0) w = 1; else if ((j == 1 || j == 3) && a[i] % 2 != 0) w = 1; else if ((j == 0 || j == 4)) w = a[i]; for (int k = 0; k <= j; k++) dp[i][j] = min(dp[i - 1][k] + w, dp[i][j]); } } for (int i = 0; i < 5; i++) ans = min(ans, dp[n - 1][i]); cout << ans; }
#include <bits/stdc++.h> using namespace std; const int inf = 1e15 + 10, N = 3e5 + 10; int a[N], n; long long dp[N][6], ans = inf; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) for (int j = 0; j < 5; j++) dp[i][j] = inf; for (int i = 0; i < n; i++) { for (int j = 0; j < 5; j++) { int w = 0; if (a[i] == 0 && j != 0 && j != 4) w = 1 + (j % 2); else if (j == 2 && a[i] % 2 == 0) w = 1; else if ((j == 1 || j == 3) && a[i] % 2 != 0) w = 1; else if ((j == 0 || j == 4)) w = a[i]; for (int k = 0; k <= j; k++) dp[i][j] = min(dp[i - 1][k] + w, dp[i][j]); } } for (int i = 0; i < 5; i++) ans = min(ans, dp[n - 1][i]); cout << ans; }
replace
3
4
3
4
0
p03132
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <cstring> #define ll long long using namespace std; ll a[200010]; ll sum[200010]; ll dp[200010][2][3]; ll n; ll func(ll here, ll ch, ll ch1) { if (ch1 >= 3) return sum[here]; if (here == n + 1) return 0; ll &ret = dp[here][ch][ch1]; ret = 9999999999999999; if (ch1 < 3) { ret = min(ret, func(here, ch ^ 1, ch1 + 1)); } if (a[here] == 0) { if (ch == 0) ret = min(ret, func(here + 1, ch, ch1) + 2); else ret = min(ret, func(here + 1, ch, ch1) + 1); } else { if (ch == a[here] % 2) ret = min(ret, func(here + 1, ch, ch1)); else ret = min(ret, func(here + 1, ch, ch1) + 1); } return ret; } int main() { memset(dp, -1, sizeof(dp)); scanf("%lld", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } for (int i = n; i >= 1; i--) sum[i] = sum[i + 1] + a[i]; ll dap = 9999999999999999; ll sum1 = 0; for (int i = 1; i <= n; i++) { dap = min(func(i, 0, 0) + sum1, dap); sum1 += a[i]; } printf("%lld", dap); }
#include <algorithm> #include <cstdio> #include <cstring> #define ll long long using namespace std; ll a[200010]; ll sum[200010]; ll dp[200010][2][3]; ll n; ll func(ll here, ll ch, ll ch1) { if (ch1 >= 3) return sum[here]; if (here == n + 1) return 0; ll &ret = dp[here][ch][ch1]; if (ret != -1) return ret; ret = 9999999999999999; if (ch1 < 3) { ret = min(ret, func(here, ch ^ 1, ch1 + 1)); } if (a[here] == 0) { if (ch == 0) ret = min(ret, func(here + 1, ch, ch1) + 2); else ret = min(ret, func(here + 1, ch, ch1) + 1); } else { if (ch == a[here] % 2) ret = min(ret, func(here + 1, ch, ch1)); else ret = min(ret, func(here + 1, ch, ch1) + 1); } return ret; } int main() { memset(dp, -1, sizeof(dp)); scanf("%lld", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } for (int i = n; i >= 1; i--) sum[i] = sum[i + 1] + a[i]; ll dap = 9999999999999999; ll sum1 = 0; for (int i = 1; i <= n; i++) { dap = min(func(i, 0, 0) + sum1, dap); sum1 += a[i]; } printf("%lld", dap); }
insert
15
15
15
17
TLE
p03132
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; typedef unsigned int uint; using namespace std; int L; ll A[100005], dp[100005][5]; int main() { cin.sync_with_stdio(false); cin.tie(0); cin >> L; for (int i = 1; i <= L; i++) { cin >> A[i]; } for (int i = 1; i <= L; i++) { ll mn = dp[i - 1][0]; dp[i][0] = mn + A[i]; mn = min(mn, dp[i - 1][1]); dp[i][1] = mn + (A[i] == 0 ? 2 : A[i] % 2); mn = min(mn, dp[i - 1][2]); dp[i][2] = mn - (A[i] % 2 - 1); mn = min(mn, dp[i - 1][3]); dp[i][3] = mn + (A[i] == 0 ? 2 : A[i] % 2); mn = min(mn, dp[i - 1][4]); dp[i][4] = mn + A[i]; } ll ret = dp[L][0]; for (int i = 1; i < 5; i++) { ret = min(ret, dp[L][i]); } cout << ret << "\n"; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; typedef unsigned int uint; using namespace std; int L; ll A[200005], dp[200005][5]; int main() { cin.sync_with_stdio(false); cin.tie(0); cin >> L; for (int i = 1; i <= L; i++) { cin >> A[i]; } for (int i = 1; i <= L; i++) { ll mn = dp[i - 1][0]; dp[i][0] = mn + A[i]; mn = min(mn, dp[i - 1][1]); dp[i][1] = mn + (A[i] == 0 ? 2 : A[i] % 2); mn = min(mn, dp[i - 1][2]); dp[i][2] = mn - (A[i] % 2 - 1); mn = min(mn, dp[i - 1][3]); dp[i][3] = mn + (A[i] == 0 ? 2 : A[i] % 2); mn = min(mn, dp[i - 1][4]); dp[i][4] = mn + A[i]; } ll ret = dp[L][0]; for (int i = 1; i < 5; i++) { ret = min(ret, dp[L][i]); } cout << ret << "\n"; return 0; }
replace
16
17
16
17
0
p03132
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for (int64 i = 0; i < (n); i++) #define FOR(i, a, b) for (int64 i = (a); i < (b); i++) #define all(x) x.begin(), x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) { u = U(v...); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v) { for (auto &e : u) fill_v<T>(e, v...); } template <::std::uint_fast64_t mod> class ModInt { private: using value_type = ::std::uint_fast64_t; value_type n; public: ModInt() : n(0) {} ModInt(value_type n_) : n(n_ % mod) {} ModInt(const ModInt &m) : n(m.n) {} template <typename T> explicit operator T() const { return static_cast<T>(n); } value_type get() const { return n; } friend ::std::ostream &operator<<(::std::ostream &os, const ModInt<mod> &a) { return os << a.n; } friend ::std::istream &operator>>(::std::istream &is, ModInt<mod> &a) { value_type x; is >> x; a = ModInt<mod>(x); return is; } bool operator==(const ModInt &m) const { return n == m.n; } bool operator!=(const ModInt &m) const { return n != m.n; } ModInt &operator*=(const ModInt &m) { n = n * m.n % mod; return *this; } ModInt pow(value_type b) const { ModInt ans = 1, m = ModInt(*this); while (b) { if (b & 1) ans *= m; m *= m; b >>= 1; } return ans; } ModInt inv() const { return (*this).pow(mod - 2); } ModInt &operator+=(const ModInt &m) { n += m.n; n = (n < mod ? n : n - mod); return *this; } ModInt &operator-=(const ModInt &m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; } ModInt &operator/=(const ModInt &m) { *this *= m.inv(); return *this; } ModInt operator+(const ModInt &m) const { return ModInt(*this) += m; } ModInt operator-(const ModInt &m) const { return ModInt(*this) -= m; } ModInt operator*(const ModInt &m) const { return ModInt(*this) *= m; } ModInt operator/(const ModInt &m) const { return ModInt(*this) /= m; } ModInt &operator++() { n += 1; return *this; } ModInt &operator--() { n -= 1; return *this; } ModInt operator++(int) { ModInt old(n); n += 1; return old; } ModInt operator--(int) { ModInt old(n); n -= 1; return old; } ModInt operator-() const { return ModInt(mod - n); } }; template <::std::size_t size, ::std::uint_fast64_t mod = 1000000007> class Factorial { private: using value_type = ModInt<mod>; ::std::vector<value_type> fact, inv; public: Factorial() : fact(size + 1, 1), inv(size + 1, 1) { for (::std::size_t i = 1; i <= size; ++i) { fact[i] = fact[i - 1] * value_type(i); inv[i] = fact[i].inv(); } } value_type comb(::std::int64_t a, ::std::int64_t b) { assert(a >= b); assert(b >= 0); return fact[a] * inv[b] * inv[a - b]; } value_type &operator[](::std::size_t k) { return fact[k]; } }; const int64 mod = 1e9 + 7; using Mint = ModInt<mod>; Factorial<112345> f; int main(void) { int64 N; cin >> N; vector<int64> A(N); REP(i, N) cin >> A[i]; auto dp = make_v<int64>(N + 1, 5); fill_v<int64>(dp, INF_LL); dp[0][0] = 0; REP(i, N) { REP(j, 5) { chmin(dp[i][j + 1], dp[i][j]); int64 cost = 0; if (j == 0 || j == 4) { cost = A[i]; } else if (j == 1 || j == 3) { cost = A[i] % 2 + (A[i] == 0 ? 2 : 0); } else { cost = (1 - A[i] % 2); } chmin(dp[i + 1][j], dp[i][j] + cost); chmin(dp[i + 1][min(j + 1, (int64)4)], dp[i][j] + cost); } } cout << (*min_element(all(dp[N]))) << endl; }
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for (int64 i = 0; i < (n); i++) #define FOR(i, a, b) for (int64 i = (a); i < (b); i++) #define all(x) x.begin(), x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template <typename A, typename B> inline void chmin(A &a, B b) { if (a > b) a = b; } template <typename A, typename B> inline void chmax(A &a, B b) { if (a < b) a = b; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) { u = U(v...); } template <typename T, typename U, typename... V> typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v) { for (auto &e : u) fill_v<T>(e, v...); } template <::std::uint_fast64_t mod> class ModInt { private: using value_type = ::std::uint_fast64_t; value_type n; public: ModInt() : n(0) {} ModInt(value_type n_) : n(n_ % mod) {} ModInt(const ModInt &m) : n(m.n) {} template <typename T> explicit operator T() const { return static_cast<T>(n); } value_type get() const { return n; } friend ::std::ostream &operator<<(::std::ostream &os, const ModInt<mod> &a) { return os << a.n; } friend ::std::istream &operator>>(::std::istream &is, ModInt<mod> &a) { value_type x; is >> x; a = ModInt<mod>(x); return is; } bool operator==(const ModInt &m) const { return n == m.n; } bool operator!=(const ModInt &m) const { return n != m.n; } ModInt &operator*=(const ModInt &m) { n = n * m.n % mod; return *this; } ModInt pow(value_type b) const { ModInt ans = 1, m = ModInt(*this); while (b) { if (b & 1) ans *= m; m *= m; b >>= 1; } return ans; } ModInt inv() const { return (*this).pow(mod - 2); } ModInt &operator+=(const ModInt &m) { n += m.n; n = (n < mod ? n : n - mod); return *this; } ModInt &operator-=(const ModInt &m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; } ModInt &operator/=(const ModInt &m) { *this *= m.inv(); return *this; } ModInt operator+(const ModInt &m) const { return ModInt(*this) += m; } ModInt operator-(const ModInt &m) const { return ModInt(*this) -= m; } ModInt operator*(const ModInt &m) const { return ModInt(*this) *= m; } ModInt operator/(const ModInt &m) const { return ModInt(*this) /= m; } ModInt &operator++() { n += 1; return *this; } ModInt &operator--() { n -= 1; return *this; } ModInt operator++(int) { ModInt old(n); n += 1; return old; } ModInt operator--(int) { ModInt old(n); n -= 1; return old; } ModInt operator-() const { return ModInt(mod - n); } }; template <::std::size_t size, ::std::uint_fast64_t mod = 1000000007> class Factorial { private: using value_type = ModInt<mod>; ::std::vector<value_type> fact, inv; public: Factorial() : fact(size + 1, 1), inv(size + 1, 1) { for (::std::size_t i = 1; i <= size; ++i) { fact[i] = fact[i - 1] * value_type(i); inv[i] = fact[i].inv(); } } value_type comb(::std::int64_t a, ::std::int64_t b) { assert(a >= b); assert(b >= 0); return fact[a] * inv[b] * inv[a - b]; } value_type &operator[](::std::size_t k) { return fact[k]; } }; const int64 mod = 1e9 + 7; using Mint = ModInt<mod>; Factorial<112345> f; int main(void) { int64 N; cin >> N; vector<int64> A(N); REP(i, N) cin >> A[i]; auto dp = make_v<int64>(N + 1, 5); fill_v<int64>(dp, INF_LL); dp[0][0] = 0; REP(i, N) { REP(j, 5) { if (j < 4) chmin(dp[i][j + 1], dp[i][j]); int64 cost = 0; if (j == 0 || j == 4) { cost = A[i]; } else if (j == 1 || j == 3) { cost = A[i] % 2 + (A[i] == 0 ? 2 : 0); } else { cost = (1 - A[i] % 2); } chmin(dp[i + 1][j], dp[i][j] + cost); chmin(dp[i + 1][min(j + 1, (int64)4)], dp[i][j] + cost); } } cout << (*min_element(all(dp[N]))) << endl; }
replace
167
168
167
169
-6
free(): invalid pointer
p03132
C++
Runtime Error
#include <bits/stdc++.h> #define ALL(c) (c).begin(), (c).end() #define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i) using namespace std; #define int long long vector<int> calc1(int L, vector<int> &A) { vector<int> dp(L + 1); int sum = 0; for (int i = 1; i <= L; ++i) { sum += A[i]; if (A[i] == 0) { dp[i] = min(sum, dp[i - 1] + 2); } else if (A[i] % 2 == 0) { dp[i] = min(sum, dp[i - 1]); } else { dp[i] = min(sum, dp[i - 1] + 1); } } return dp; } vector<int> calc2(int L, vector<int> &A, vector<int> &B) { vector<int> dp(L + 1); for (int i = 1; i <= L + 1; ++i) { int c; if (A[i] % 2 == 0) { c = 1; } else { c = 0; } dp[i] = min(B[i], dp[i - 1] + c); } return dp; } signed main() { int L; cin >> L; vector<int> A(L + 2); for (int i = 1; i <= L; ++i) { cin >> A[i]; } vector<int> dp1 = calc1(L, A); vector<int> dp2 = calc2(L, A, dp1); reverse(ALL(A)); vector<int> rdp1 = calc1(L, A); vector<int> rdp2 = calc2(L, A, rdp1); reverse(ALL(rdp1)); reverse(ALL(rdp2)); int res = (int)(1e17); /* for(int i = 0; i <= L; ++i) { cout << dp1[i] << "," << dp2[i] << "," << rdp1[i] << "," << rdp2[i] << endl; } */ for (int i = 1; i <= L; ++i) { res = min(res, dp1[i] + rdp2[i]); res = min(res, rdp1[i] + dp2[i]); } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define ALL(c) (c).begin(), (c).end() #define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i) using namespace std; #define int long long vector<int> calc1(int L, vector<int> &A) { vector<int> dp(L + 1); int sum = 0; for (int i = 1; i <= L; ++i) { sum += A[i]; if (A[i] == 0) { dp[i] = min(sum, dp[i - 1] + 2); } else if (A[i] % 2 == 0) { dp[i] = min(sum, dp[i - 1]); } else { dp[i] = min(sum, dp[i - 1] + 1); } } return dp; } vector<int> calc2(int L, vector<int> &A, vector<int> &B) { vector<int> dp(L + 1); for (int i = 1; i <= L; ++i) { int c; if (A[i] % 2 == 0) { c = 1; } else { c = 0; } dp[i] = min(B[i], dp[i - 1] + c); } return dp; } signed main() { int L; cin >> L; vector<int> A(L + 2); for (int i = 1; i <= L; ++i) { cin >> A[i]; } vector<int> dp1 = calc1(L, A); vector<int> dp2 = calc2(L, A, dp1); reverse(ALL(A)); vector<int> rdp1 = calc1(L, A); vector<int> rdp2 = calc2(L, A, rdp1); reverse(ALL(rdp1)); reverse(ALL(rdp2)); int res = (int)(1e17); /* for(int i = 0; i <= L; ++i) { cout << dp1[i] << "," << dp2[i] << "," << rdp1[i] << "," << rdp2[i] << endl; } */ for (int i = 1; i <= L; ++i) { res = min(res, dp1[i] + rdp2[i]); res = min(res, rdp1[i] + dp2[i]); } cout << res << endl; return 0; }
replace
23
24
23
24
-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)
p03132
C++
Runtime Error
#include <bits/stdc++.h> #define null "" #define endl '\n' #define all(dat) dat.begin(), dat.end() #define loop(i, to) for (int i = 0; i < to; ++i) #define cont(i, to) for (int i = 1; i <= to; ++i) #define circ(i, fr, to) for (int i = fr; i <= to; ++i) #define foreach(i, dat) \ for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) typedef long long num; using namespace std; const num inf = 0x7f7f7f7f7f7f; int n; num a[100005], dp[100005][5], ans = inf; int main() { memset(dp, inf, sizeof(dp)); cin >> n; cont(i, n) { cin >> a[i]; } dp[0][0] = 0; cont(i, n) { circ(j, 0, 4) { circ(k, 0, j) { if (j == 0 || j == 4) { dp[i][j] = min(dp[i][j], dp[i - 1][k] + a[i]); } else if (j == 1 || j == 3) { dp[i][j] = min(dp[i][j], dp[i - 1][k] + (a[i] > 0 ? a[i] % 2 : 2)); } else { dp[i][j] = min(dp[i][j], dp[i - 1][k] + (a[i] + 1) % 2); } } } } ans = min(ans, dp[n][0]); ans = min(ans, dp[n][1]); ans = min(ans, dp[n][2]); ans = min(ans, dp[n][3]); ans = min(ans, dp[n][4]); cout << ans << endl; }
#include <bits/stdc++.h> #define null "" #define endl '\n' #define all(dat) dat.begin(), dat.end() #define loop(i, to) for (int i = 0; i < to; ++i) #define cont(i, to) for (int i = 1; i <= to; ++i) #define circ(i, fr, to) for (int i = fr; i <= to; ++i) #define foreach(i, dat) \ for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) typedef long long num; using namespace std; const num inf = 0x7f7f7f7f7f7f; int n; num a[200005], dp[200005][5], ans = inf; int main() { memset(dp, inf, sizeof(dp)); cin >> n; cont(i, n) { cin >> a[i]; } dp[0][0] = 0; cont(i, n) { circ(j, 0, 4) { circ(k, 0, j) { if (j == 0 || j == 4) { dp[i][j] = min(dp[i][j], dp[i - 1][k] + a[i]); } else if (j == 1 || j == 3) { dp[i][j] = min(dp[i][j], dp[i - 1][k] + (a[i] > 0 ? a[i] % 2 : 2)); } else { dp[i][j] = min(dp[i][j], dp[i - 1][k] + (a[i] + 1) % 2); } } } } ans = min(ans, dp[n][0]); ans = min(ans, dp[n][1]); ans = min(ans, dp[n][2]); ans = min(ans, dp[n][3]); ans = min(ans, dp[n][4]); cout << ans << endl; }
replace
19
20
19
20
0
p03132
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #define llong long long using namespace std; const int N = 1e5; llong a[N + 3]; int b[N + 3]; llong dp[N + 3][5]; int n; int eval(int x, int y, int id) { if (x == 0 || x == 4) { return a[id]; } else if (x == 1 || x == 3) { return 2 - y; } else if (x == 2) { return y == 1 ? 0 : 1; } } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= n; i++) { if (a[i] == 0) b[i] = 0; else if (a[i] & 1) b[i] = 1; else b[i] = 2; } memset(dp, 42, sizeof(dp)); for (int i = 0; i <= 4; i++) dp[0][i] = 0ll; for (int i = 1; i <= n; i++) { for (int j = 0; j <= 4; j++) { for (int k = 0; k <= j; k++) { dp[i][j] = min(dp[i][j], dp[i - 1][k] + eval(j, b[i], i)); } } } llong ans = min(min(min(dp[n][0], dp[n][1]), dp[n][2]), min(dp[n][3], dp[n][4])); printf("%lld\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #define llong long long using namespace std; const int N = 2e5; llong a[N + 3]; int b[N + 3]; llong dp[N + 3][5]; int n; int eval(int x, int y, int id) { if (x == 0 || x == 4) { return a[id]; } else if (x == 1 || x == 3) { return 2 - y; } else if (x == 2) { return y == 1 ? 0 : 1; } } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= n; i++) { if (a[i] == 0) b[i] = 0; else if (a[i] & 1) b[i] = 1; else b[i] = 2; } memset(dp, 42, sizeof(dp)); for (int i = 0; i <= 4; i++) dp[0][i] = 0ll; for (int i = 1; i <= n; i++) { for (int j = 0; j <= 4; j++) { for (int k = 0; k <= j; k++) { dp[i][j] = min(dp[i][j], dp[i - 1][k] + eval(j, b[i], i)); } } } llong ans = min(min(min(dp[n][0], dp[n][1]), dp[n][2]), min(dp[n][3], dp[n][4])); printf("%lld\n", ans); return 0; }
replace
7
8
7
8
0
p03133
C++
Runtime Error
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; const int mod = 998244353; int n, m, a[310][310]; int od[310], ev[310], bit[310], xxj[310]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j], a[i][j] &= 1; /* if(n<m) { for(int i=1;i<=n;i++) for(int j=i+1;j<=m;j++) swap(a[i][j],a[j][i]); swap(n,m); } */ /* for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=m;j++) printf("%d ",a[i][j]); */ int u = max(n, m); od[1] = 1; ev[1] = 3; for (int i = 2; i <= u; i++) { od[i] = (ev[i - 1] + 3ll * od[i - 1] % mod) % mod; ev[i] = (od[i - 1] + 3ll * ev[i - 1] % mod) % mod; } int cnt = 0; /* for(int i=1;i<=u;i++) { int p=i; for(int j=i+1;j<=u;j++) if(a[i][i]<a[j][i]) p=j; if(p!=i) swap(a[p],a[i]); if(!a[i][i]) continue; cnt++; for(int j=i+1;j<=u;j++) if(a[j][i]) for(int k=i;k<=u;k++) a[j][k]^=a[i][k]; } */ for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) if (a[i][j]) { if (xxj[j]) for (int k = j; k <= m; j++) a[i][k] ^= a[xxj[j]][k]; else { xxj[j] = i; cnt++; break; } } } bit[0] = 1; for (int i = 1; i <= u; i++) bit[i] = 2ll * bit[i - 1] % mod; int bs = 1ll * bit[n - cnt] * bit[m - cnt] % mod; printf("%lld\n", 1ll * od[cnt] * bs % mod); }
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; const int mod = 998244353; int n, m, a[310][310]; int od[310], ev[310], bit[310], xxj[310]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j], a[i][j] &= 1; /* if(n<m) { for(int i=1;i<=n;i++) for(int j=i+1;j<=m;j++) swap(a[i][j],a[j][i]); swap(n,m); } */ /* for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=m;j++) printf("%d ",a[i][j]); */ int u = max(n, m); od[1] = 1; ev[1] = 3; for (int i = 2; i <= u; i++) { od[i] = (ev[i - 1] + 3ll * od[i - 1] % mod) % mod; ev[i] = (od[i - 1] + 3ll * ev[i - 1] % mod) % mod; } int cnt = 0; /* for(int i=1;i<=u;i++) { int p=i; for(int j=i+1;j<=u;j++) if(a[i][i]<a[j][i]) p=j; if(p!=i) swap(a[p],a[i]); if(!a[i][i]) continue; cnt++; for(int j=i+1;j<=u;j++) if(a[j][i]) for(int k=i;k<=u;k++) a[j][k]^=a[i][k]; } */ for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) if (a[i][j]) { if (xxj[j]) for (int k = j; k <= m; k++) a[i][k] ^= a[xxj[j]][k]; else { xxj[j] = i; cnt++; break; } } } bit[0] = 1; for (int i = 1; i <= u; i++) bit[i] = 2ll * bit[i - 1] % mod; int bs = 1ll * bit[n - cnt] * bit[m - cnt] % mod; printf("%lld\n", 1ll * od[cnt] * bs % mod); }
replace
51
52
51
52
0
p03133
C++
Runtime Error
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; const int mod = 998244353; const int N = 700; int n, m, a[N][N]; int od[N], ev[N], bit[N], xxj[N]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j], a[i][j] &= 1; if (n < m) { for (int i = 1; i <= n; i++) for (int j = i + 1; j <= m; j++) swap(a[i][j], a[j][i]); swap(n, m); } int u = max(n, m); od[1] = 1; ev[1] = 3; for (int i = 2; i <= u; i++) { od[i] = (ev[i - 1] + 3ll * od[i - 1] % mod) % mod; ev[i] = (od[i - 1] + 3ll * ev[i - 1] % mod) % mod; } int cnt = 0; for (int i = 1; i <= u; i++) { int p = i; for (int j = i + 1; j <= u; j++) if (a[i][i] < a[j][i]) p = j; if (p != i) swap(a[p], a[i]); if (!a[i][i]) { u++; swap(a[i], a[u]); continue; } cnt++; for (int j = i + 1; j <= u; j++) if (a[j][i]) for (int k = i; k <= u; k++) a[j][k] ^= a[i][k]; } /* for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) if(a[i][j]) { if(xxj[j]) for(int k=j;k<=m;k++) a[i][k]^=a[xxj[j]][k]; else {xxj[j]=i;cnt++;break;} } } */ bit[0] = 1; for (int i = 1; i <= u; i++) bit[i] = 2ll * bit[i - 1] % mod; int bs = 1ll * bit[n - cnt] * bit[m - cnt] % mod; printf("%lld\n", 1ll * od[cnt] * bs % mod); }
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; const int mod = 998244353; const int N = 700; int n, m, a[N][N]; int od[N], ev[N], bit[N], xxj[N]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j], a[i][j] &= 1; if (n < m) { for (int i = 1; i <= n; i++) for (int j = i + 1; j <= m; j++) swap(a[i][j], a[j][i]); swap(n, m); } int u = max(n, m); od[1] = 1; ev[1] = 3; for (int i = 2; i <= u; i++) { od[i] = (ev[i - 1] + 3ll * od[i - 1] % mod) % mod; ev[i] = (od[i - 1] + 3ll * ev[i - 1] % mod) % mod; } int cnt = 0; for (int i = 1; i <= u; i++) { int p = i; for (int j = i + 1; j <= u; j++) if (a[i][i] < a[j][i]) p = j; if (p != i) swap(a[p], a[i]); if (!a[i][i]) { int fl = 0; for (int j = i + 1; j <= m; j++) fl |= a[i][j]; if (fl) swap(a[i], a[++u]); continue; } cnt++; for (int j = i + 1; j <= u; j++) if (a[j][i]) for (int k = i; k <= u; k++) a[j][k] ^= a[i][k]; } /* for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) if(a[i][j]) { if(xxj[j]) for(int k=j;k<=m;k++) a[i][k]^=a[xxj[j]][k]; else {xxj[j]=i;cnt++;break;} } } */ bit[0] = 1; for (int i = 1; i <= u; i++) bit[i] = 2ll * bit[i - 1] % mod; int bs = 1ll * bit[n - cnt] * bit[m - cnt] % mod; printf("%lld\n", 1ll * od[cnt] * bs % mod); }
replace
36
38
36
41
0
p03133
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll const mod = 998244353; #define p_ary(ary, a, b, i) \ do { \ cout << "["; \ for (int(i) = (a); (i) < (b); ++(i)) \ cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \ cout << "]\n"; \ } while (0) #define p_map(map, it) \ do { \ cout << "{"; \ for (auto(it) = map.begin();; ++(it)) { \ if ((it) == map.end()) { \ cout << "}\n"; \ break; \ } else \ cout << "" << (it)->first << "=>" << (it)->second << ", "; \ } \ } while (0) ll power_mod(ll a, ll b, ll mod) { if (b == 1) return a; ll c = power_mod(a, b / 2, mod); if (b % 2) return c * c % mod * a % mod; else return c * c % mod; } int main() { int n, m; cin >> n >> m; bool a[n][m]; int r = 0; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j]; for (int i = 0; i < min(n, m); ++i) { int p = i, q = i; for (int j = i; j < n; ++j) { if (a[p][q]) break; for (int k = i; k < m; ++k) if (a[j][k]) { p = j; q = k; break; } } if (!a[p][q]) break; r = i + 1; for (int j = i; j < n; ++j) swap(a[j][i], a[j][q]); for (int j = i; j < m; ++j) swap(a[i][j], a[p][j]); for (int j = i + 1; j < n; ++j) if (a[j][i]) for (int k = i; k < m; ++k) a[j][k] ^= a[i][k]; for (int j = i + 1; j < m; ++j) if (a[i][j]) for (int k = i; k < n; ++k) a[k][j] ^= a[k][i]; } cout << (power_mod(2, n + m - 1, mod) - power_mod(2, n + m - r - 1, mod) + mod) % mod << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll const mod = 998244353; #define p_ary(ary, a, b, i) \ do { \ cout << "["; \ for (int(i) = (a); (i) < (b); ++(i)) \ cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \ cout << "]\n"; \ } while (0) #define p_map(map, it) \ do { \ cout << "{"; \ for (auto(it) = map.begin();; ++(it)) { \ if ((it) == map.end()) { \ cout << "}\n"; \ break; \ } else \ cout << "" << (it)->first << "=>" << (it)->second << ", "; \ } \ } while (0) ll power_mod(ll a, ll b, ll mod) { if (b == 0) return 1; if (b == 1) return a; ll c = power_mod(a, b / 2, mod); if (b % 2) return c * c % mod * a % mod; else return c * c % mod; } int main() { int n, m; cin >> n >> m; bool a[n][m]; int r = 0; for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j]; for (int i = 0; i < min(n, m); ++i) { int p = i, q = i; for (int j = i; j < n; ++j) { if (a[p][q]) break; for (int k = i; k < m; ++k) if (a[j][k]) { p = j; q = k; break; } } if (!a[p][q]) break; r = i + 1; for (int j = i; j < n; ++j) swap(a[j][i], a[j][q]); for (int j = i; j < m; ++j) swap(a[i][j], a[p][j]); for (int j = i + 1; j < n; ++j) if (a[j][i]) for (int k = i; k < m; ++k) a[j][k] ^= a[i][k]; for (int j = i + 1; j < m; ++j) if (a[i][j]) for (int k = i; k < n; ++k) a[k][j] ^= a[k][i]; } cout << (power_mod(2, n + m - 1, mod) - power_mod(2, n + m - r - 1, mod) + mod) % mod << endl; return 0; }
insert
26
26
26
28
0
p03133
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <vector> using namespace std; typedef long long lint; const int mod = 998244353; int modpow(int x, int y, int m) { int ret = 1 % m, x2p = x; while (y > 0) { if (y % 2) ret = (lint)ret * x2p % m; y /= 2; x2p = (lint)x2p * x2p % m; } return ret; } int inv(int a, int p) { return modpow(a, p - 2, p); } vector<int> fact, inv_fact; void prepare_binom(int lim) { fact.resize(lim + 1); fact[0] = 1; for (int i = 1; i <= lim; ++i) fact[i] = (lint)i * fact[i - 1] % mod; inv_fact.resize(lim + 1); inv_fact[lim] = inv(fact[lim], mod); for (int i = lim - 1; i >= 0; --i) inv_fact[i] = (lint)(i + 1) * inv_fact[i + 1] % mod; } int binom(int a, int b) { if (!(0 <= b && b <= a)) return 0; return (lint)fact[a] * inv_fact[b] % mod * inv_fact[a - b] % mod; } int main() { int n, m; scanf("%d %d", &n, &m); prepare_binom(min(n, m)); vector<vector<int>> mat(n, vector<int>(m)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) { scanf("%d", &mat[i][j]); mat[i][j] %= 2; } int rank = 0; for (int x = 0; x < m; ++x) { int selected = -1; for (int y = rank; y < n; ++y) if (mat[y][x]) selected = y; if (selected == -1) continue; swap(mat[selected], mat[rank]); for (int y = rank + 1; y < n; ++y) { if (!mat[y][x]) continue; for (int x2 = x; x2 < n; ++x2) mat[y][x2] ^= mat[rank][x2]; } ++rank; } int result = 0; for (int i = 1; i <= rank; i += 2) result = (result + (lint)binom(rank, i) * modpow(3, rank - i, mod) % mod * modpow(2, n + m - 2 * rank, mod)) % mod; printf("%d\n", result); return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <vector> using namespace std; typedef long long lint; const int mod = 998244353; int modpow(int x, int y, int m) { int ret = 1 % m, x2p = x; while (y > 0) { if (y % 2) ret = (lint)ret * x2p % m; y /= 2; x2p = (lint)x2p * x2p % m; } return ret; } int inv(int a, int p) { return modpow(a, p - 2, p); } vector<int> fact, inv_fact; void prepare_binom(int lim) { fact.resize(lim + 1); fact[0] = 1; for (int i = 1; i <= lim; ++i) fact[i] = (lint)i * fact[i - 1] % mod; inv_fact.resize(lim + 1); inv_fact[lim] = inv(fact[lim], mod); for (int i = lim - 1; i >= 0; --i) inv_fact[i] = (lint)(i + 1) * inv_fact[i + 1] % mod; } int binom(int a, int b) { if (!(0 <= b && b <= a)) return 0; return (lint)fact[a] * inv_fact[b] % mod * inv_fact[a - b] % mod; } int main() { int n, m; scanf("%d %d", &n, &m); prepare_binom(min(n, m)); vector<vector<int>> mat(n, vector<int>(m)); for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) { scanf("%d", &mat[i][j]); mat[i][j] %= 2; } int rank = 0; for (int x = 0; x < m; ++x) { int selected = -1; for (int y = rank; y < n; ++y) if (mat[y][x]) selected = y; if (selected == -1) continue; swap(mat[selected], mat[rank]); for (int y = rank + 1; y < n; ++y) { if (!mat[y][x]) continue; for (int x2 = x; x2 < m; ++x2) mat[y][x2] ^= mat[rank][x2]; } ++rank; } int result = 0; for (int i = 1; i <= rank; i += 2) result = (result + (lint)binom(rank, i) * modpow(3, rank - i, mod) % mod * modpow(2, n + m - 2 * rank, mod)) % mod; printf("%d\n", result); return 0; }
replace
86
87
86
87
0
p03133
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; const int MOD = 998244353; bool p[302][302]; int _pow(int x) { int v = 1, w = 2; while (x > 0) { if (x & 1) v = 1LL * v * w % MOD; w = 1LL * w * w % MOD; x >>= 1; } return v; } int main() { int N, M; scanf("%d%d", &N, &M); for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { int x; scanf("%d", &x); p[i][j] = x == 1; } } int f = 0; for (int i = 1; i <= M; i++) { int z = 0; for (int j = f + 1; j <= N; j++) { if (p[j][i]) { z = j; break; } } if (z == 0) continue; f++; for (int j = 1; j <= M; j++) swap(p[f][j], p[z][j]); for (int j = 1; j <= N; j++) { if (j == f) continue; if (p[j][i]) { for (int k = 1; i <= M; k++) p[j][k] ^= p[f][k]; } } } int a = _pow(N), b = _pow(N - f), c = _pow(M - 1); int ans = 1LL * (a - b < 0 ? a - b + MOD : a - b) * c % MOD; printf("%d\n", ans); return 0; }
#include <algorithm> #include <cstdio> using namespace std; const int MOD = 998244353; bool p[302][302]; int _pow(int x) { int v = 1, w = 2; while (x > 0) { if (x & 1) v = 1LL * v * w % MOD; w = 1LL * w * w % MOD; x >>= 1; } return v; } int main() { int N, M; scanf("%d%d", &N, &M); for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { int x; scanf("%d", &x); p[i][j] = x == 1; } } int f = 0; for (int i = 1; i <= M; i++) { int z = 0; for (int j = f + 1; j <= N; j++) { if (p[j][i]) { z = j; break; } } if (z == 0) continue; f++; for (int j = 1; j <= M; j++) swap(p[f][j], p[z][j]); for (int j = 1; j <= N; j++) { if (j == f) continue; if (p[j][i]) { for (int k = 1; k <= M; k++) p[j][k] ^= p[f][k]; } } } int a = _pow(N), b = _pow(N - f), c = _pow(M - 1); int ans = 1LL * (a - b < 0 ? a - b + MOD : a - b) * c % MOD; printf("%d\n", ans); return 0; }
replace
57
58
57
58
0
p03133
C++
Runtime Error
#include <algorithm> #include <bitset> #include <climits> #include <complex> #include <deque> #include <iomanip> #include <iostream> #include <istream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; // typedef pair<ll, ll> P; #define rep(i, n) for (ll i = 0; i < (n); i++) #define revrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define pb push_back #define f first #define s second #define chmin(x, y) x = min(x, y); #define chmax(x, y) x = max(x, y); // const ll INFL = LLONG_MAX;//10^18 = 2^60 const ll INFL = 1LL << 60; // const int INF = INT_MAX; const ll INF = 1 << 30; // 10^9 // ll MOD = 1000000007; ll MOD = 998244353; vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0}; vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0}; void pres(double A, ll x = 20) { cout << fixed << setprecision(x) << A << endl; } void BinarySay(ll x, ll y = 60) { rep(i, y) cout << (x >> (y - 1 - i) & 1); cout << endl; } ll cnt_bit(ll x) { return __builtin_popcountll(x); } ll pow_long(ll x, ll k) { ll res = 1; while (k > 0) { if (k % 2) res *= x; x *= x; k /= 2; } return res; } ll pow_mod(ll x, ll k) { ll res = 1; while (k > 0) { if (k % 2) { res *= x; res %= MOD; } x *= x; x %= MOD; k /= 2; } return res; } ll inverse(ll x) { return pow_mod(x, MOD - 2); }; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll x, ll y) { ll res = x / gcd(x, y); res *= y; return res; }; // コンビネーション const int MAXcomb = 200010; ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb]; // facはn!,finvは1/n! // invは逆元 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAXcomb; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll comb(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] % MOD * finv[n - k] % MOD; } const int MAXkai = 200010; ll kai_memo[MAXkai]; ll kai(ll N) { if (kai_memo[N] != 0) return kai_memo[N]; if (N <= 1) return 1; return kai_memo[N] = N * kai(N - 1) % MOD; } ll Rank(ll N, ll M, vector<vector<ll>> A) { ll next = 0; rep(i, M) { for (ll j = next; j < N; j++) { if (A[j][i]) { swap(A[next], A[j]); } } if (!A[next][i]) continue; rep(j, N) if (j != next) { if (A[j][i]) { rep(k, M) A[j][k] ^= A[next][k]; } } next++; if (next == N + 1) break; } return next; } ll N, M; vector<vector<ll>> A; void solve() { COMinit(); cin >> N >> M; A.resize(N); rep(i, N) A[i].resize(M); rep(i, N) rep(j, M) cin >> A[i][j]; ll r = Rank(N, M, A); ll ans = 0; rep(i, r + 1) { ll add = comb(r, i) * pow_mod(2, r - i) % MOD; for (ll j = 1; j <= i; j += 2) { ans += add * comb(i, j) % MOD; ans %= MOD; } } ans *= pow_mod(2, N + M - 2 * r); ans %= MOD; cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include <algorithm> #include <bitset> #include <climits> #include <complex> #include <deque> #include <iomanip> #include <iostream> #include <istream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; // typedef pair<ll, ll> P; #define rep(i, n) for (ll i = 0; i < (n); i++) #define revrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define pb push_back #define f first #define s second #define chmin(x, y) x = min(x, y); #define chmax(x, y) x = max(x, y); // const ll INFL = LLONG_MAX;//10^18 = 2^60 const ll INFL = 1LL << 60; // const int INF = INT_MAX; const ll INF = 1 << 30; // 10^9 // ll MOD = 1000000007; ll MOD = 998244353; vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0}; vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0}; void pres(double A, ll x = 20) { cout << fixed << setprecision(x) << A << endl; } void BinarySay(ll x, ll y = 60) { rep(i, y) cout << (x >> (y - 1 - i) & 1); cout << endl; } ll cnt_bit(ll x) { return __builtin_popcountll(x); } ll pow_long(ll x, ll k) { ll res = 1; while (k > 0) { if (k % 2) res *= x; x *= x; k /= 2; } return res; } ll pow_mod(ll x, ll k) { ll res = 1; while (k > 0) { if (k % 2) { res *= x; res %= MOD; } x *= x; x %= MOD; k /= 2; } return res; } ll inverse(ll x) { return pow_mod(x, MOD - 2); }; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll x, ll y) { ll res = x / gcd(x, y); res *= y; return res; }; // コンビネーション const int MAXcomb = 200010; ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb]; // facはn!,finvは1/n! // invは逆元 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAXcomb; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll comb(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] % MOD * finv[n - k] % MOD; } const int MAXkai = 200010; ll kai_memo[MAXkai]; ll kai(ll N) { if (kai_memo[N] != 0) return kai_memo[N]; if (N <= 1) return 1; return kai_memo[N] = N * kai(N - 1) % MOD; } ll Rank(ll N, ll M, vector<vector<ll>> A) { ll next = 0; rep(i, M) { for (ll j = next; j < N; j++) { if (A[j][i]) { swap(A[next], A[j]); } } if (!A[next][i]) continue; rep(j, N) if (j != next) { if (A[j][i]) { rep(k, M) A[j][k] ^= A[next][k]; } } next++; if (next == N) break; } return next; } ll N, M; vector<vector<ll>> A; void solve() { COMinit(); cin >> N >> M; A.resize(N); rep(i, N) A[i].resize(M); rep(i, N) rep(j, M) cin >> A[i][j]; ll r = Rank(N, M, A); ll ans = 0; rep(i, r + 1) { ll add = comb(r, i) * pow_mod(2, r - i) % MOD; for (ll j = 1; j <= i; j += 2) { ans += add * comb(i, j) % MOD; ans %= MOD; } } ans *= pow_mod(2, N + M - 2 * r); ans %= MOD; cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
replace
136
137
136
137
0
p03133
C++
Runtime Error
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } #define ll long long #define pb push_back #define ld long double #define mp make_pair #define F first #define S second #define pii pair<ll, ll> using namespace ::std; const ll maxn = 210; const ll mod = 998244353; bitset<maxn> bi[maxn]; ll tav[maxn]; bitset<maxn> f[maxn]; ll cnt = 1; ll koj[maxn]; bool add(bitset<maxn> bi, ll m) { for (ll i = m - 1; i >= 0; i--) { if (bi[i]) { if (koj[i] == -1) { f[cnt] = bi; koj[i] = cnt; cnt++; return 0; } else { bi ^= f[koj[i]]; } } } return 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); tav[0] = 1; for (ll i = 1; i < maxn; i++) { tav[i] = (tav[i - 1] * 2) % mod; } fill(koj, koj + maxn, -1); ll n, m; cin >> n >> m; for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { ll a; cin >> a; bi[i][j] = a; } } ll sefr = 0; for (ll i = 0; i < n; i++) { sefr += add(bi[i], m); } cout << ((tav[m - 1] * (tav[n] - tav[sefr])) % mod + mod) % mod; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } #define ll long long #define pb push_back #define ld long double #define mp make_pair #define F first #define S second #define pii pair<ll, ll> using namespace ::std; const ll maxn = 310; const ll mod = 998244353; bitset<maxn> bi[maxn]; ll tav[maxn]; bitset<maxn> f[maxn]; ll cnt = 1; ll koj[maxn]; bool add(bitset<maxn> bi, ll m) { for (ll i = m - 1; i >= 0; i--) { if (bi[i]) { if (koj[i] == -1) { f[cnt] = bi; koj[i] = cnt; cnt++; return 0; } else { bi ^= f[koj[i]]; } } } return 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); tav[0] = 1; for (ll i = 1; i < maxn; i++) { tav[i] = (tav[i - 1] * 2) % mod; } fill(koj, koj + maxn, -1); ll n, m; cin >> n >> m; for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { ll a; cin >> a; bi[i][j] = a; } } ll sefr = 0; for (ll i = 0; i < n; i++) { sefr += add(bi[i], m); } cout << ((tav[m - 1] * (tav[n] - tav[sefr])) % mod + mod) % mod; }
replace
66
67
66
67
0
p03133
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 998244353; template <int mod> struct modint { lint v; modint() : v(0) {} modint(signed v) : v(v) {} modint(lint t) { v = t % mod; if (v < 0) v += mod; } modint pow(lint k) { modint res(1), tmp(v); while (k) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } static modint add_identity() { return modint(0); } static modint mul_identity() { return modint(1); } modint inv() { return pow(mod - 2); } modint &operator+=(modint a) { v += a.v; if (v >= mod) v -= mod; return *this; } modint &operator-=(modint a) { v += mod - a.v; if (v >= mod) v -= mod; return *this; } modint &operator*=(modint a) { v = v * a.v % mod; return *this; } modint &operator/=(modint a) { return (*this) *= a.inv(); } modint operator+(modint a) const { return modint(v) += a; }; modint operator-(modint a) const { return modint(v) -= a; }; modint operator*(modint a) const { return modint(v) *= a; }; modint operator/(modint a) const { return modint(v) /= a; }; modint operator-() const { return v ? modint(mod - v) : modint(v); } bool operator==(const modint a) const { return v == a.v; } bool operator!=(const modint a) const { return v != a.v; } bool operator<(const modint a) const { return v < a.v; } }; using mint = modint<mod>; ostream &operator<<(ostream &os, mint m) { return os << m.v; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> a[i][j]; } } vector<bool> used(n, false); int rank = 0; for (int i = 0; i < m; ++i) { int idx = -1; for (int j = 0; j < n; ++j) { if (!used[j] && a[j][i] == 1) { idx = j; used[j] = true; break; } } if (idx == -1) continue; for (int j = 0; j < n; ++j) { if (j != idx && a[j][i] == 1) { for (int k = i; k < n; ++k) { a[j][k] ^= a[idx][k]; } } } rank++; } mint ret = mint(2).pow(n + m - rank - 1) * (mint(2).pow(rank) - 1); cout << ret << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long; const lint inf = 1LL << 60; const lint mod = 998244353; template <int mod> struct modint { lint v; modint() : v(0) {} modint(signed v) : v(v) {} modint(lint t) { v = t % mod; if (v < 0) v += mod; } modint pow(lint k) { modint res(1), tmp(v); while (k) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } static modint add_identity() { return modint(0); } static modint mul_identity() { return modint(1); } modint inv() { return pow(mod - 2); } modint &operator+=(modint a) { v += a.v; if (v >= mod) v -= mod; return *this; } modint &operator-=(modint a) { v += mod - a.v; if (v >= mod) v -= mod; return *this; } modint &operator*=(modint a) { v = v * a.v % mod; return *this; } modint &operator/=(modint a) { return (*this) *= a.inv(); } modint operator+(modint a) const { return modint(v) += a; }; modint operator-(modint a) const { return modint(v) -= a; }; modint operator*(modint a) const { return modint(v) *= a; }; modint operator/(modint a) const { return modint(v) /= a; }; modint operator-() const { return v ? modint(mod - v) : modint(v); } bool operator==(const modint a) const { return v == a.v; } bool operator!=(const modint a) const { return v != a.v; } bool operator<(const modint a) const { return v < a.v; } }; using mint = modint<mod>; ostream &operator<<(ostream &os, mint m) { return os << m.v; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<vector<int>> a(n, vector<int>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> a[i][j]; } } vector<bool> used(n, false); int rank = 0; for (int i = 0; i < m; ++i) { int idx = -1; for (int j = 0; j < n; ++j) { if (!used[j] && a[j][i] == 1) { idx = j; used[j] = true; break; } } if (idx == -1) continue; for (int j = 0; j < n; ++j) { if (j != idx && a[j][i] == 1) { for (int k = i; k < m; ++k) { a[j][k] ^= a[idx][k]; } } } rank++; } mint ret = mint(2).pow(n + m - rank - 1) * (mint(2).pow(rank) - 1); cout << ret << "\n"; return 0; }
replace
88
89
88
89
0
p03133
C++
Runtime Error
#include <bits/stdc++.h> #define MOD 998244353 using namespace std; int pow(int x, int pow) { int res = 1, t = x; while (pow) { if (pow & 1) { res = 1LL * res * t % MOD; } t = 1LL * t * t % MOD; pow >>= 1; } return res; } int main() { int n, m; cin >> n >> m; int **mat = new int *[n]; for (int i = 0; i < n; i++) { mat[i] = new int[m]; for (int j = 0; j < m; j++) { cin >> mat[i][j]; } } int cur = 0; for (int c = 0; c < m; c++) { for (int r = cur; r < n; r++) { if (mat[r][c]) { swap(mat[cur], mat[r]); break; } } if (!mat[cur][c]) { continue; } for (int r = 0; r < n; r++) { if (r != cur && mat[r][c]) { for (int k = c; k < m; k++) { mat[r][k] ^= mat[cur][k]; } } } cur++; } int tot = pow(2, n + m - 1); tot -= pow(2, n + m - cur - 1); if (tot < 0) { tot += MOD; } cout << tot << endl; for (int i = 0; i < n; i++) { delete mat[i]; } delete mat; return 0; }
#include <bits/stdc++.h> #define MOD 998244353 using namespace std; int pow(int x, int pow) { int res = 1, t = x; while (pow) { if (pow & 1) { res = 1LL * res * t % MOD; } t = 1LL * t * t % MOD; pow >>= 1; } return res; } int main() { int n, m; cin >> n >> m; int **mat = new int *[n]; for (int i = 0; i < n; i++) { mat[i] = new int[m]; for (int j = 0; j < m; j++) { cin >> mat[i][j]; } } int cur = 0; for (int c = 0; cur < n && c < m; c++) { for (int r = cur; r < n; r++) { if (mat[r][c]) { swap(mat[cur], mat[r]); break; } } if (!mat[cur][c]) { continue; } for (int r = 0; r < n; r++) { if (r != cur && mat[r][c]) { for (int k = c; k < m; k++) { mat[r][k] ^= mat[cur][k]; } } } cur++; } int tot = pow(2, n + m - 1); tot -= pow(2, n + m - cur - 1); if (tot < 0) { tot += MOD; } cout << tot << endl; for (int i = 0; i < n; i++) { delete mat[i]; } delete mat; return 0; }
replace
29
30
29
30
0
p03134
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <float.h> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <utility> #include <vector> using namespace std; long long gcd(long long a, long long b) { if (a < b) gcd(b, a); long long r; while ((r = a % b)) { a = b; b = r; } return b; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { long long b = mod, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } namespace NTT { const int MOD = 998244353; // to be set appropriately const long long PR = 3; // to be set appropriately void trans(vector<long long> &v, bool inv = false) { int n = (int)v.size(); for (int i = 0, j = 1; j < n - 1; j++) { for (int k = n >> 1; k > (i ^= k); k >>= 1) ; if (i > j) swap(v[i], v[j]); } for (int t = 2; t <= n; t <<= 1) { long long bw = modpow(PR, (MOD - 1) / t, MOD); if (inv) bw = modinv(bw, MOD); for (int i = 0; i < n; i += t) { long long w = 1; for (int j = 0; j < t / 2; ++j) { int j1 = i + j, j2 = i + j + t / 2; long long c1 = v[j1], c2 = v[j2] * w % MOD; v[j1] = c1 + c2; v[j2] = c1 - c2 + MOD; while (v[j1] >= MOD) v[j1] -= MOD; while (v[j2] >= MOD) v[j2] -= MOD; w = w * bw % MOD; } } } if (inv) { long long inv_n = modinv(n, MOD); for (int i = 0; i < n; ++i) v[i] = v[i] * inv_n % MOD; } } // C is A*B vector<long long> mult(vector<long long> A, vector<long long> B) { int size_a = 1; while (size_a < A.size()) size_a <<= 1; int size_b = 1; while (size_b < B.size()) size_b <<= 1; int size_fft = max(size_a, size_b) << 1; vector<long long> cA(size_fft, 0), cB(size_fft, 0), cC(size_fft, 0); for (int i = 0; i < A.size(); ++i) cA[i] = A[i]; for (int i = 0; i < B.size(); ++i) cB[i] = B[i]; trans(cA); trans(cB); for (int i = 0; i < size_fft; ++i) cC[i] = cA[i] * cB[i] % MOD; trans(cC, true); vector<long long> res((int)A.size() + (int)B.size() - 1); for (int i = 0; i < res.size(); ++i) res[i] = cC[i]; return res; } }; // namespace NTT typedef pair<int, int> p; typedef pair<int, p> pai; const int maxn = 1 << 24; int n2; long long dat[2 * maxn - 1]; void init(int n_) { n2 = 1; while (n2 < n_) n2 *= 2; for (int i = 0; i < 2 * n2 - 1; i++) { dat[i] = LLONG_MIN / 2; } } void update(long long k, long long a) { k += n2 - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } long long query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return LLONG_MIN / 2; if (a <= l && r <= b) return dat[k]; else { long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2); long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } long long mod = 998244353; signed main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; vector<int> red; vector<int> blue; long long dp[2003][2003]; int n = s.length(); for (int i = 0; i < 2003; i++) { for (int j = 0; j < 2003; j++) { dp[i][j] = 0; } } dp[0][0] = 1; for (int i = 0; i < n; i++) { if (s[i] == '0') { red.push_back(i); red.push_back(i); } if (s[i] == '1') { red.push_back(i); blue.push_back(i); } if (s[i] == '2') { blue.push_back(i); blue.push_back(i); } } int r = red.size(), b = blue.size(); for (int i = 0; i <= r; i++) { for (int j = 0; j <= b; j++) { if (j < b && blue[j] <= i + j) dp[i][j + 1] += dp[i][j]; dp[i][j + 1] %= mod; if (i < r && red[i] <= i + j) dp[i + 1][j] = dp[i][j]; dp[i + 1][j] %= mod; } } cout << dp[r][b]; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <float.h> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <utility> #include <vector> using namespace std; long long gcd(long long a, long long b) { if (a < b) gcd(b, a); long long r; while ((r = a % b)) { a = b; b = r; } return b; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { long long b = mod, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } namespace NTT { const int MOD = 998244353; // to be set appropriately const long long PR = 3; // to be set appropriately void trans(vector<long long> &v, bool inv = false) { int n = (int)v.size(); for (int i = 0, j = 1; j < n - 1; j++) { for (int k = n >> 1; k > (i ^= k); k >>= 1) ; if (i > j) swap(v[i], v[j]); } for (int t = 2; t <= n; t <<= 1) { long long bw = modpow(PR, (MOD - 1) / t, MOD); if (inv) bw = modinv(bw, MOD); for (int i = 0; i < n; i += t) { long long w = 1; for (int j = 0; j < t / 2; ++j) { int j1 = i + j, j2 = i + j + t / 2; long long c1 = v[j1], c2 = v[j2] * w % MOD; v[j1] = c1 + c2; v[j2] = c1 - c2 + MOD; while (v[j1] >= MOD) v[j1] -= MOD; while (v[j2] >= MOD) v[j2] -= MOD; w = w * bw % MOD; } } } if (inv) { long long inv_n = modinv(n, MOD); for (int i = 0; i < n; ++i) v[i] = v[i] * inv_n % MOD; } } // C is A*B vector<long long> mult(vector<long long> A, vector<long long> B) { int size_a = 1; while (size_a < A.size()) size_a <<= 1; int size_b = 1; while (size_b < B.size()) size_b <<= 1; int size_fft = max(size_a, size_b) << 1; vector<long long> cA(size_fft, 0), cB(size_fft, 0), cC(size_fft, 0); for (int i = 0; i < A.size(); ++i) cA[i] = A[i]; for (int i = 0; i < B.size(); ++i) cB[i] = B[i]; trans(cA); trans(cB); for (int i = 0; i < size_fft; ++i) cC[i] = cA[i] * cB[i] % MOD; trans(cC, true); vector<long long> res((int)A.size() + (int)B.size() - 1); for (int i = 0; i < res.size(); ++i) res[i] = cC[i]; return res; } }; // namespace NTT typedef pair<int, int> p; typedef pair<int, p> pai; const int maxn = 1 << 24; int n2; long long dat[2 * maxn - 1]; void init(int n_) { n2 = 1; while (n2 < n_) n2 *= 2; for (int i = 0; i < 2 * n2 - 1; i++) { dat[i] = LLONG_MIN / 2; } } void update(long long k, long long a) { k += n2 - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } long long query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return LLONG_MIN / 2; if (a <= l && r <= b) return dat[k]; else { long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2); long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } long long mod = 998244353; signed main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; vector<int> red; vector<int> blue; long long dp[4003][4003]; int n = s.length(); for (int i = 0; i < 2003; i++) { for (int j = 0; j < 2003; j++) { dp[i][j] = 0; } } dp[0][0] = 1; for (int i = 0; i < n; i++) { if (s[i] == '0') { red.push_back(i); red.push_back(i); } if (s[i] == '1') { red.push_back(i); blue.push_back(i); } if (s[i] == '2') { blue.push_back(i); blue.push_back(i); } } int r = red.size(), b = blue.size(); for (int i = 0; i <= r; i++) { for (int j = 0; j <= b; j++) { if (j < b && blue[j] <= i + j) dp[i][j + 1] += dp[i][j]; dp[i][j + 1] %= mod; if (i < r && red[i] <= i + j) dp[i + 1][j] = dp[i][j]; dp[i + 1][j] %= mod; } } cout << dp[r][b]; }
replace
162
163
162
163
-11
p03134
C++
Runtime Error
#include <cstring> #include <iostream> const int MOD = 998244353; const int ms = 2020; int memo[ms][ms + ms]; std::string str; int dp(int round, int red, int blue) { if (round < (int)str.size()) { if (str[round] == '0') red += 2; else if (str[round] == '1') { red++; blue++; } else blue += 2; } int &ans = memo[round][red]; if (ans != -1) return ans; ans = 0; if (red + blue == 0) return ans = 1; if (red) { ans += dp(round + 1, red - 1, blue); } if (blue) { ans += dp(round + 1, red, blue - 1); } if (ans >= MOD) ans -= MOD; return ans; } int main() { memset(memo, -1, sizeof memo); std::cin >> str; std::cout << dp(0, 0, 0) << '\n'; }
#include <cstring> #include <iostream> const int MOD = 998244353; const int ms = 2020; int memo[ms + ms][ms + ms]; std::string str; int dp(int round, int red, int blue) { if (round < (int)str.size()) { if (str[round] == '0') red += 2; else if (str[round] == '1') { red++; blue++; } else blue += 2; } int &ans = memo[round][red]; if (ans != -1) return ans; ans = 0; if (red + blue == 0) return ans = 1; if (red) { ans += dp(round + 1, red - 1, blue); } if (blue) { ans += dp(round + 1, red, blue - 1); } if (ans >= MOD) ans -= MOD; return ans; } int main() { memset(memo, -1, sizeof memo); std::cin >> str; std::cout << dp(0, 0, 0) << '\n'; }
replace
7
8
7
8
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> #define cmin(a, b) (a > (b) ? a = (b), 1 : 0) #define cmax(a, b) (a < (b) ? a = (b), 1 : 0) #define dmin(a, b) ((a) < (b) ? (a) : (b)) #define dmax(a, b) ((a) > (b) ? (a) : (b)) namespace io { int F() { int F = 1, n = 0; char ch; while ((ch = getchar()) != '-' && (ch < '0' || ch > '9')) ; ch == '-' ? F = 0 : n = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') n = n * 10 + ch - '0'; return F ? n : -n; } long long G() { long long F = 1, n = 0; char ch; while ((ch = getchar()) != '-' && (ch < '0' || ch > '9')) ; ch == '-' ? F = 0 : n = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') n = n * 10 + ch - '0'; return F ? n : -n; } } // namespace io int R(int l, int r) { return (rand() << 15 | rand()) % (r - l + 1) + l; } const int M = 998244353; char s[3333]; int b[2222][2222], f[2222][2222]; int sub[5][2] = {{'3', 0}, {'4', '3'}, {0, '4'}}; int main() { scanf("%s", s + 1); int n = strlen(s + 1); int R = 0, B = 0; for (register int i = 1; i <= n; ++i) { if (s[i] == '0') R += 2; if (s[i] == '1') ++R, ++B; if (s[i] == '2') B += 2; } int x = 0, y = 0; while (1) { int pl = 0; for (register int i = 1; i <= n; ++i) if (s[i] == '0' || s[i] == '2') { pl = i; break; } if (pl == 0) break; if (s[pl] == '0') { b[x][y + pl] = 1; s[1] = sub[s[1] - '0'][0]; ++x; } else { b[x + pl][y] = 1; s[1] = sub[s[1] - '0'][1]; ++y; } for (register int i = 1; i < n; ++i) { if (s[i] == '3') { if (s[i + 1] != '0' && s[i + 1] != '3') s[i] = '1', s[i + 1] = sub[s[i + 1] - '0'][1]; else s[i] = '0', s[i + 1] = sub[s[i + 1] - '0'][0]; } else { if (s[i + 1] != '2' && s[i + 1] != '4') s[i] = '1', s[i + 1] = sub[s[i + 1] - '0'][0]; else s[i] = '2', s[i + 1] = sub[s[i + 1] - '0'][1]; } } if (!s[n]) --n; } f[0][0] = 1; for (register int i = 0; i <= R; ++i) for (register int j = 0; j <= B; ++j) if (b[i][j] == 0) { if (i) f[i][j] = (f[i][j] + f[i - 1][j]) % M; if (j) f[i][j] = (f[i][j] + f[i][j - 1]) % M; } printf("%d\n", f[R][B]); return 0; }
#include <bits/stdc++.h> #define cmin(a, b) (a > (b) ? a = (b), 1 : 0) #define cmax(a, b) (a < (b) ? a = (b), 1 : 0) #define dmin(a, b) ((a) < (b) ? (a) : (b)) #define dmax(a, b) ((a) > (b) ? (a) : (b)) namespace io { int F() { int F = 1, n = 0; char ch; while ((ch = getchar()) != '-' && (ch < '0' || ch > '9')) ; ch == '-' ? F = 0 : n = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') n = n * 10 + ch - '0'; return F ? n : -n; } long long G() { long long F = 1, n = 0; char ch; while ((ch = getchar()) != '-' && (ch < '0' || ch > '9')) ; ch == '-' ? F = 0 : n = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') n = n * 10 + ch - '0'; return F ? n : -n; } } // namespace io int R(int l, int r) { return (rand() << 15 | rand()) % (r - l + 1) + l; } const int M = 998244353; char s[3333]; int b[4444][4444], f[4444][4444]; int sub[5][2] = {{'3', 0}, {'4', '3'}, {0, '4'}}; int main() { scanf("%s", s + 1); int n = strlen(s + 1); int R = 0, B = 0; for (register int i = 1; i <= n; ++i) { if (s[i] == '0') R += 2; if (s[i] == '1') ++R, ++B; if (s[i] == '2') B += 2; } int x = 0, y = 0; while (1) { int pl = 0; for (register int i = 1; i <= n; ++i) if (s[i] == '0' || s[i] == '2') { pl = i; break; } if (pl == 0) break; if (s[pl] == '0') { b[x][y + pl] = 1; s[1] = sub[s[1] - '0'][0]; ++x; } else { b[x + pl][y] = 1; s[1] = sub[s[1] - '0'][1]; ++y; } for (register int i = 1; i < n; ++i) { if (s[i] == '3') { if (s[i + 1] != '0' && s[i + 1] != '3') s[i] = '1', s[i + 1] = sub[s[i + 1] - '0'][1]; else s[i] = '0', s[i + 1] = sub[s[i + 1] - '0'][0]; } else { if (s[i + 1] != '2' && s[i + 1] != '4') s[i] = '1', s[i + 1] = sub[s[i + 1] - '0'][0]; else s[i] = '2', s[i + 1] = sub[s[i + 1] - '0'][1]; } } if (!s[n]) --n; } f[0][0] = 1; for (register int i = 0; i <= R; ++i) for (register int j = 0; j <= B; ++j) if (b[i][j] == 0) { if (i) f[i][j] = (f[i][j] + f[i - 1][j]) % M; if (j) f[i][j] = (f[i][j] + f[i][j - 1]) % M; } printf("%d\n", f[R][B]); return 0; }
replace
30
31
30
31
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int cys = 998244353; int n; char s[2005]; int sum[2005], d[2005][4005]; int mod(int x) { return x >= cys ? x - cys : x; } int main() { scanf("%s", s + 1); n = strlen(s + 1); for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + s[i] - '0'; d[0][0] = 1; for (int i = 1; i <= 2 * n; i++) { for (int j = sum[min(n, i)]; j >= 0; j--) { if (i - j <= 2 * min(n, i) - sum[min(n, i)]) d[i][j] = d[i - 1][j]; if (j >= 1) d[i][j] = mod(d[i][j] + d[i - 1][j - 1]); } } cout << d[2 * n][sum[n]] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int cys = 998244353; int n; char s[2005]; int sum[2005], d[4005][4005]; int mod(int x) { return x >= cys ? x - cys : x; } int main() { scanf("%s", s + 1); n = strlen(s + 1); for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + s[i] - '0'; d[0][0] = 1; for (int i = 1; i <= 2 * n; i++) { for (int j = sum[min(n, i)]; j >= 0; j--) { if (i - j <= 2 * min(n, i) - sum[min(n, i)]) d[i][j] = d[i - 1][j]; if (j >= 1) d[i][j] = mod(d[i][j] + d[i - 1][j - 1]); } } cout << d[2 * n][sum[n]] << endl; return 0; }
replace
24
25
24
25
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = int64_t; const ll MOD = 998244353; ll dp[2010][2010]; ll cntr[4010]; ll cntb[4010]; int main() { string S; cin >> S; dp[0][0] = 1; for (ll i = 0; i < S.size(); i++) { char c = S[i]; cntr[i + 1] = cntr[i] + 2 * (c == '0') + (c == '1'); cntb[i + 1] = cntb[i] + 2 * (c == '2') + (c == '1'); } for (ll i = S.size(); i < 4010; i++) { cntr[i + 1] = cntr[i]; cntb[i + 1] = cntb[i]; } for (ll i = 1; i <= 2 * S.size(); i++) { for (ll r = 0; r <= min(i, cntr[i]); r++) { ll b = i - r; if (b > cntb[i]) continue; if (r > 0) dp[r][b] += dp[r - 1][b]; if (b > 0) dp[r][b] += dp[r][b - 1]; dp[r][b] %= MOD; } } cout << dp[cntr[4010 - 1]][cntb[4010 - 1]] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; const ll MOD = 998244353; ll dp[4010][4010]; ll cntr[4010]; ll cntb[4010]; int main() { string S; cin >> S; dp[0][0] = 1; for (ll i = 0; i < S.size(); i++) { char c = S[i]; cntr[i + 1] = cntr[i] + 2 * (c == '0') + (c == '1'); cntb[i + 1] = cntb[i] + 2 * (c == '2') + (c == '1'); } for (ll i = S.size(); i < 4010; i++) { cntr[i + 1] = cntr[i]; cntb[i + 1] = cntb[i]; } for (ll i = 1; i <= 2 * S.size(); i++) { for (ll r = 0; r <= min(i, cntr[i]); r++) { ll b = i - r; if (b > cntb[i]) continue; if (r > 0) dp[r][b] += dp[r - 1][b]; if (b > 0) dp[r][b] += dp[r][b - 1]; dp[r][b] %= MOD; } } cout << dp[cntr[4010 - 1]][cntb[4010 - 1]] << endl; return 0; }
replace
4
5
4
5
0
p03134
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctype.h> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <unordered_map> #include <vector> using namespace std; #define all(vec) vec.begin(), vec.end() typedef long long ll; ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } ll kai(ll x, ll y, ll m) { ll res = 1; for (ll i = x - y + 1; i <= x; i++) { res *= i; res %= m; } return res; } ll mod_pow(ll x, ll y, ll m) { ll res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } ll comb(ll x, ll y, ll m) { if (y > x) return 0; return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m; } const ll mod = 998244353; string s; ll cum1[2010], cum2[2010]; ll d[2010][2010]; signed main() { cin >> s; int n = (int)s.size(); for (int i = 0; i < n; i++) { if (s[i] == '0') cum1[i + 1] += 2; if (s[i] == '1') cum1[i + 1]++, cum2[i + 1]++; if (s[i] == '2') cum2[i + 1] += 2; cum1[i + 1] += cum1[i]; cum2[i + 1] += cum2[i]; } d[0][0] = 1; for (int i = 0; i < 2 * n; i++) { for (int j = 0; j <= i; j++) { if (j + 1 <= cum1[min(n, i + 1)]) d[j + 1][i - j] = (d[j + 1][i - j] + d[j][i - j]) % mod; if (i - j + 1 <= cum2[min(n, i + 1)]) d[j][i + 1 - j] = (d[j][i + 1 - j] + d[j][i - j]) % mod; } } cout << d[cum1[n]][cum2[n]] << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctype.h> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <unordered_map> #include <vector> using namespace std; #define all(vec) vec.begin(), vec.end() typedef long long ll; ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } ll kai(ll x, ll y, ll m) { ll res = 1; for (ll i = x - y + 1; i <= x; i++) { res *= i; res %= m; } return res; } ll mod_pow(ll x, ll y, ll m) { ll res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } ll comb(ll x, ll y, ll m) { if (y > x) return 0; return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m; } const ll mod = 998244353; string s; ll cum1[2010], cum2[2010]; ll d[4010][4010]; signed main() { cin >> s; int n = (int)s.size(); for (int i = 0; i < n; i++) { if (s[i] == '0') cum1[i + 1] += 2; if (s[i] == '1') cum1[i + 1]++, cum2[i + 1]++; if (s[i] == '2') cum2[i + 1] += 2; cum1[i + 1] += cum1[i]; cum2[i + 1] += cum2[i]; } d[0][0] = 1; for (int i = 0; i < 2 * n; i++) { for (int j = 0; j <= i; j++) { if (j + 1 <= cum1[min(n, i + 1)]) d[j + 1][i - j] = (d[j + 1][i - j] + d[j][i - j]) % mod; if (i - j + 1 <= cum2[min(n, i + 1)]) d[j][i + 1 - j] = (d[j][i + 1 - j] + d[j][i - j]) % mod; } } cout << d[cum1[n]][cum2[n]] << endl; }
replace
57
58
57
58
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; const int MAXN = 2010; const int mod = 998244353; int sum1, sum2; char s[MAXN]; int f[MAXN][2], dp[MAXN][MAXN]; int main() { scanf("%s", s + 1); int n = strlen(s + 1); for (int i = 1; i <= n; i++) sum1 += (s[i] - '0'); sum2 = 2 * n - sum1; for (int i = 1; i <= n; i++) f[i][0] += f[i - 1][0] + (s[i] - '0'), f[i][1] += f[i - 1][1] + 2 - (s[i] - '0'); dp[0][0] = 1; for (int i = 0; i <= sum1; i++) { for (int j = 0; j <= sum2; j++) if (i | j) if (i <= f[min(i + j, n)][0] && j <= f[min(i + j, n)][1]) { if (i) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod; if (j) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod; } } cout << dp[sum1][sum2] << endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; const int MAXN = 4010; const int mod = 998244353; int sum1, sum2; char s[MAXN]; int f[MAXN][2], dp[MAXN][MAXN]; int main() { scanf("%s", s + 1); int n = strlen(s + 1); for (int i = 1; i <= n; i++) sum1 += (s[i] - '0'); sum2 = 2 * n - sum1; for (int i = 1; i <= n; i++) f[i][0] += f[i - 1][0] + (s[i] - '0'), f[i][1] += f[i - 1][1] + 2 - (s[i] - '0'); dp[0][0] = 1; for (int i = 0; i <= sum1; i++) { for (int j = 0; j <= sum2; j++) if (i | j) if (i <= f[min(i + j, n)][0] && j <= f[min(i + j, n)][1]) { if (i) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod; if (j) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod; } } cout << dp[sum1][sum2] << endl; }
replace
3
4
3
4
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> #define il inline #define pb push_back #define mp make_pair #define fir first #define sec second #define mid ((l + r) >> 1) #define MAXN 2005 #define MAXM #define mod 998244353 #define inf (1 << 30) #define eps (1e-6) #define alpha 0.75 #define rep(i, x, y) for (register int i = x; i <= (y); ++i) #define repd(i, x, y) for (register int i = x; i >= (y); --i) #define file(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<ll, ll> pll; template <typename T> il bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } template <typename T> il bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } template <typename T> il void read(T &x) { char ch = getchar(); int f = 1; x = 0; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= f; } template <typename T, typename... Args> il void read(T &x, Args &...args) { read(x), read(args...); } int n; char s[MAXN]; ll dp[MAXN][MAXN]; void add(ll &x, ll y) { (x += y) %= mod; } int main() { scanf("%s", s + 1); n = strlen(s + 1); dp[0][0] = 1; int r = 0, b = 0; rep(i, 1, n * 2) { if (i <= n) b += s[i] - '0', r += '2' - s[i]; rep(j, 0, i) if (r >= j && b >= i - j) { add(dp[i][j], dp[i - 1][j]); if (j) add(dp[i][j], dp[i - 1][j - 1]); } } cout << dp[n * 2][r] << endl; return 0; }
#include <bits/stdc++.h> #define il inline #define pb push_back #define mp make_pair #define fir first #define sec second #define mid ((l + r) >> 1) #define MAXN 4005 #define MAXM #define mod 998244353 #define inf (1 << 30) #define eps (1e-6) #define alpha 0.75 #define rep(i, x, y) for (register int i = x; i <= (y); ++i) #define repd(i, x, y) for (register int i = x; i >= (y); --i) #define file(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<ll, ll> pll; template <typename T> il bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } template <typename T> il bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } template <typename T> il void read(T &x) { char ch = getchar(); int f = 1; x = 0; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= f; } template <typename T, typename... Args> il void read(T &x, Args &...args) { read(x), read(args...); } int n; char s[MAXN]; ll dp[MAXN][MAXN]; void add(ll &x, ll y) { (x += y) %= mod; } int main() { scanf("%s", s + 1); n = strlen(s + 1); dp[0][0] = 1; int r = 0, b = 0; rep(i, 1, n * 2) { if (i <= n) b += s[i] - '0', r += '2' - s[i]; rep(j, 0, i) if (r >= j && b >= i - j) { add(dp[i][j], dp[i - 1][j]); if (j) add(dp[i][j], dp[i - 1][j - 1]); } } cout << dp[n * 2][r] << endl; return 0; }
replace
7
8
7
8
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> #define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to) #define dbg(...) fprintf(stderr, __VA_ARGS__) #define File(x) freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout) #define fi first #define se second #define pb push_back template <typename A, typename B> inline char SMAX(A &a, const B &b) { return a < b ? a = b, 1 : 0; } template <typename A, typename B> inline char SMIN(A &a, const B &b) { return b < a ? a = b, 1 : 0; } typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii; template <typename I> inline void read(I &x) { int f = 0, c; while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0; x = c & 15; while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15); f ? x = -x : 0; } const int N = 1000 + 7; const int P = 998244353; int n, cntb[N << 1], dp[N << 1][N << 1]; char s[N]; inline void Inc(int &x, int y) { x += y; x >= P ? x -= P : 0; } int main() { #ifdef hzhkk freopen("hkk.in", "r", stdin); #endif scanf("%s", s + 1); n = strlen(s + 1); for (int i = 1; i <= n; ++i) cntb[i] = cntb[i - 1] + s[i] - '0'; for (int i = n + 1; i <= (n << 1); ++i) cntb[i] = cntb[i - 1]; dp[0][0] = 1; for (int i = 1; i <= (n << 1); ++i) { for (int j = std::max(cntb[i] - i, 0); j <= std::min(cntb[i], i); ++j) { if (j) dp[i][j] = dp[i - 1][j - 1]; if (i > j) Inc(dp[i][j], dp[i - 1][j]); // dbg("dp[%d][%d] = %d\n", i, j, dp[i][j]); } } printf("%d\n", dp[n << 1][cntb[n]]); }
#include <bits/stdc++.h> #define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to) #define dbg(...) fprintf(stderr, __VA_ARGS__) #define File(x) freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout) #define fi first #define se second #define pb push_back template <typename A, typename B> inline char SMAX(A &a, const B &b) { return a < b ? a = b, 1 : 0; } template <typename A, typename B> inline char SMIN(A &a, const B &b) { return b < a ? a = b, 1 : 0; } typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii; template <typename I> inline void read(I &x) { int f = 0, c; while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0; x = c & 15; while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15); f ? x = -x : 0; } const int N = 2000 + 7; const int P = 998244353; int n, cntb[N << 1], dp[N << 1][N << 1]; char s[N]; inline void Inc(int &x, int y) { x += y; x >= P ? x -= P : 0; } int main() { #ifdef hzhkk freopen("hkk.in", "r", stdin); #endif scanf("%s", s + 1); n = strlen(s + 1); for (int i = 1; i <= n; ++i) cntb[i] = cntb[i - 1] + s[i] - '0'; for (int i = n + 1; i <= (n << 1); ++i) cntb[i] = cntb[i - 1]; dp[0][0] = 1; for (int i = 1; i <= (n << 1); ++i) { for (int j = std::max(cntb[i] - i, 0); j <= std::min(cntb[i], i); ++j) { if (j) dp[i][j] = dp[i - 1][j - 1]; if (i > j) Inc(dp[i][j], dp[i - 1][j]); // dbg("dp[%d][%d] = %d\n", i, j, dp[i][j]); } } printf("%d\n", dp[n << 1][cntb[n]]); }
replace
30
31
30
31
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; int dp[2005][2005]; int tot[2005][2]; const int mod = 998244353; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen("INPUT.txt", "r", stdin); freopen("OUTPUT.txt", "w", stdout); } #endif string a; cin >> a; int n = a.length(); dp[0][0] = 1; a = "#" + a; for (int i = 1; i <= n; i++) { tot[i][0] = tot[i - 1][0]; tot[i][1] = tot[i - 1][1]; if (a[i] == '0') tot[i][0] += 2; else if (a[i] == '1') { tot[i][0]++; tot[i][1]++; } else { tot[i][1] += 2; } } for (int i = 0; i <= tot[n][0]; i++) { for (int j = 0; j <= tot[n][1]; j++) { if (i + j == 0) continue; if (i > 0) { int z = i + j; z = min(z, n); if (tot[z][0] >= i) { dp[i][j] += dp[i - 1][j]; } } if (j > 0) { int z = i + j; z = min(z, n); if (tot[z][1] >= j) { dp[i][j] += dp[i][j - 1]; } } dp[i][j] %= mod; } } cout << dp[tot[n][0]][tot[n][1]]; }
#include <bits/stdc++.h> #define int long long using namespace std; int dp[4005][4005]; int tot[2005][2]; const int mod = 998244353; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE if (fopen("INPUT.txt", "r")) { freopen("INPUT.txt", "r", stdin); freopen("OUTPUT.txt", "w", stdout); } #endif string a; cin >> a; int n = a.length(); dp[0][0] = 1; a = "#" + a; for (int i = 1; i <= n; i++) { tot[i][0] = tot[i - 1][0]; tot[i][1] = tot[i - 1][1]; if (a[i] == '0') tot[i][0] += 2; else if (a[i] == '1') { tot[i][0]++; tot[i][1]++; } else { tot[i][1] += 2; } } for (int i = 0; i <= tot[n][0]; i++) { for (int j = 0; j <= tot[n][1]; j++) { if (i + j == 0) continue; if (i > 0) { int z = i + j; z = min(z, n); if (tot[z][0] >= i) { dp[i][j] += dp[i - 1][j]; } } if (j > 0) { int z = i + j; z = min(z, n); if (tot[z][1] >= j) { dp[i][j] += dp[i][j - 1]; } } dp[i][j] %= mod; } } cout << dp[tot[n][0]][tot[n][1]]; }
replace
4
5
4
5
0
p03134
C++
Runtime Error
/**********************************************************************/ /******** ********/ /******** Writer:孙~~ ********/ /******** Lang:C++ ********/ /******** Status:Unknow ********/ /******** ********/ /**********************************************************************/ #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <vector> // #include<bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int SIZE = 2005; const double EPS = 1e-6; const int MOD = 998244353; long long dp[SIZE][SIZE], c[SIZE][SIZE]; int r[SIZE], b[SIZE]; int main() { /*main function start*/ string s; cin >> s; int n = s.size(); // cout<<n<<endl; for (int i = 1; i <= n; i++) if (s[i - 1] == '0') r[i] = r[i - 1] + 2, b[i] = b[i - 1]; else if (s[i - 1] == '1') r[i] = r[i - 1] + 1, b[i] = b[i - 1] + 1; else r[i] = r[i - 1], b[i] = b[i - 1] + 2; for (int i = n + 1; i <= n * 2; i++) r[i] = r[i - 1], b[i] = b[i - 1]; dp[0][0] = 1; for (int i = 1; i <= n * 2; i++) { // cout<<"TEST "<<i<<" "<<b[i]<<" "<<max(i-b[i],0)<<" //"<<min(i,r[i])<<endl; for (int j = max(i - b[i], 0); j <= min(i, r[i]); j++) { if (j > 0) dp[i][j] += dp[i - 1][j - 1]; if (i != j) dp[i][j] += dp[i - 1][j]; dp[i][j] %= MOD; // cout<<dp[i][j]<<" "; } // cout<<endl; } long long ans = 0; for (int i = 0; i <= min(n * 2, r[n * 2]); i++) { ans += dp[n * 2][i]; ans %= MOD; } cout << ans << endl; // cout<<c[2][0]<<endl; return 0; }
/**********************************************************************/ /******** ********/ /******** Writer:孙~~ ********/ /******** Lang:C++ ********/ /******** Status:Unknow ********/ /******** ********/ /**********************************************************************/ #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <vector> // #include<bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int SIZE = 2005; const double EPS = 1e-6; const int MOD = 998244353; long long dp[SIZE * 2][SIZE * 2]; int r[SIZE * 2], b[SIZE * 2]; int main() { /*main function start*/ string s; cin >> s; int n = s.size(); // cout<<n<<endl; for (int i = 1; i <= n; i++) if (s[i - 1] == '0') r[i] = r[i - 1] + 2, b[i] = b[i - 1]; else if (s[i - 1] == '1') r[i] = r[i - 1] + 1, b[i] = b[i - 1] + 1; else r[i] = r[i - 1], b[i] = b[i - 1] + 2; for (int i = n + 1; i <= n * 2; i++) r[i] = r[i - 1], b[i] = b[i - 1]; dp[0][0] = 1; for (int i = 1; i <= n * 2; i++) { // cout<<"TEST "<<i<<" "<<b[i]<<" "<<max(i-b[i],0)<<" //"<<min(i,r[i])<<endl; for (int j = max(i - b[i], 0); j <= min(i, r[i]); j++) { if (j > 0) dp[i][j] += dp[i - 1][j - 1]; if (i != j) dp[i][j] += dp[i - 1][j]; dp[i][j] %= MOD; // cout<<dp[i][j]<<" "; } // cout<<endl; } long long ans = 0; for (int i = 0; i <= min(n * 2, r[n * 2]); i++) { ans += dp[n * 2][i]; ans %= MOD; } cout << ans << endl; // cout<<c[2][0]<<endl; return 0; }
replace
28
30
28
30
0
p03134
C++
Runtime Error
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define trace(...) __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...); } typedef long long int64; typedef pair<int, int> ii; const int INF = 1 << 29; const int MOD = 998244353; const int N = 2e3 + 10; char s[N]; int dp[N][N]; int A[N], B[N]; int n; int solve(int x, int y, int step) { if (x + y == 2 * n) return 1; step = min(step, n); int &ret = dp[x][y]; if (ret >= 0) return ret; ret = 0; // trace(x, y, step, A[step], B[step]); if (A[step] > x) ret = (ret + solve(x + 1, y, step + 1)) % MOD; if (B[step] > y) ret = (ret + solve(x, y + 1, step + 1)) % MOD; // trace(x, y, ret); return ret; } int main() { scanf("%s", s); n = strlen(s); for (int i = 0; i < n; ++i) { if (s[i] == '0') { A[i + 1] = A[i] + 2; B[i + 1] = B[i]; } else if (s[i] == '1') { A[i + 1] = A[i] + 1; B[i + 1] = B[i] + 1; } else { A[i + 1] = A[i]; B[i + 1] = B[i] + 2; } } memset(dp, 255, sizeof(dp)); int ret = solve(0, 0, 1); printf("%d\n", ret); return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define trace(...) __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...); } typedef long long int64; typedef pair<int, int> ii; const int INF = 1 << 29; const int MOD = 998244353; const int N = 5e3 + 10; char s[N]; int dp[N][N]; int A[N], B[N]; int n; int solve(int x, int y, int step) { if (x + y == 2 * n) return 1; step = min(step, n); int &ret = dp[x][y]; if (ret >= 0) return ret; ret = 0; // trace(x, y, step, A[step], B[step]); if (A[step] > x) ret = (ret + solve(x + 1, y, step + 1)) % MOD; if (B[step] > y) ret = (ret + solve(x, y + 1, step + 1)) % MOD; // trace(x, y, ret); return ret; } int main() { scanf("%s", s); n = strlen(s); for (int i = 0; i < n; ++i) { if (s[i] == '0') { A[i + 1] = A[i] + 2; B[i + 1] = B[i]; } else if (s[i] == '1') { A[i + 1] = A[i] + 1; B[i + 1] = B[i] + 1; } else { A[i + 1] = A[i]; B[i + 1] = B[i] + 2; } } memset(dp, 255, sizeof(dp)); int ret = solve(0, 0, 1); printf("%d\n", ret); return 0; }
replace
40
41
40
41
0
p03134
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define MAXN 2000 #define MOD 998244353 char s[MAXN + 5]; int n, num1[MAXN + 5], num2[MAXN + 5]; int dp[MAXN + 5][MAXN + 5]; int main() { scanf("%s", s + 1); n = strlen(s + 1); for (int i = 1; i <= n; i++) { num2[i] = s[i] - '0'; num1[i] = 2 - num2[i] + num1[i - 1]; num2[i] += num2[i - 1]; } dp[0][0] = 1; for (int i = 1; i <= n * 2; i++) { int cnt1 = num1[min(n, i)], cnt2 = num2[min(n, i)]; for (int j = 0; j <= i; j++) if (cnt1 >= j && cnt2 >= i - j) { dp[i][j] = dp[i - 1][j]; if (j > 0) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD; } } printf("%d\n", dp[n * 2][num1[n]]); }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define MAXN 4000 #define MOD 998244353 char s[MAXN + 5]; int n, num1[MAXN + 5], num2[MAXN + 5]; int dp[MAXN + 5][MAXN + 5]; int main() { scanf("%s", s + 1); n = strlen(s + 1); for (int i = 1; i <= n; i++) { num2[i] = s[i] - '0'; num1[i] = 2 - num2[i] + num1[i - 1]; num2[i] += num2[i - 1]; } dp[0][0] = 1; for (int i = 1; i <= n * 2; i++) { int cnt1 = num1[min(n, i)], cnt2 = num2[min(n, i)]; for (int j = 0; j <= i; j++) if (cnt1 >= j && cnt2 >= i - j) { dp[i][j] = dp[i - 1][j]; if (j > 0) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD; } } printf("%d\n", dp[n * 2][num1[n]]); }
replace
5
6
5
6
0
p03134
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i) #define rep(i, n) REP(i, 0, n) typedef long long ll; typedef pair<int, int> pint; typedef pair<ll, int> pli; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 998244353; ll dp[2020][2020]; int main() { string s; cin >> s; int n = s.size(); vector<int> red, blue; rep(i, n) { if (s[i] == '0') { red.push_back(i); red.push_back(i); } if (s[i] == '1') { red.push_back(i); blue.push_back(i); } if (s[i] == '2') { blue.push_back(i); blue.push_back(i); } } dp[0][0] = 1; int r = red.size(), b = blue.size(); rep(i, r + 1) rep(j, b + 1) { dp[i][j] %= mod; int m = i + j; if (j < b && blue[j] <= m) dp[i][j + 1] += dp[i][j]; if (i < r && red[i] <= m) dp[i + 1][j] += dp[i][j]; } cout << dp[r][b] % mod << endl; return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i) #define rep(i, n) REP(i, 0, n) typedef long long ll; typedef pair<int, int> pint; typedef pair<ll, int> pli; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 998244353; ll dp[4020][4020]; int main() { string s; cin >> s; int n = s.size(); vector<int> red, blue; rep(i, n) { if (s[i] == '0') { red.push_back(i); red.push_back(i); } if (s[i] == '1') { red.push_back(i); blue.push_back(i); } if (s[i] == '2') { blue.push_back(i); blue.push_back(i); } } dp[0][0] = 1; int r = red.size(), b = blue.size(); rep(i, r + 1) rep(j, b + 1) { dp[i][j] %= mod; int m = i + j; if (j < b && blue[j] <= m) dp[i][j + 1] += dp[i][j]; if (i < r && red[i] <= m) dp[i + 1][j] += dp[i][j]; } cout << dp[r][b] % mod << endl; return 0; }
replace
26
27
26
27
0
p03134
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <vector> using namespace std; typedef long long lint; const int mod = 998244353, maxn = 2000; int dp[maxn + 1][maxn + 1]; multiset<int> pos[2]; int solve(int i, int n0, int n1, int n) { if (i == 2 * n) { return 1; } int &res = dp[n0][n1]; if (res != -1) return res; pair<int, int> range; if (i < n) { range = {0, i}; } else { range = {0, n - 1}; } res = 0; for (int val = 0; val < 2; ++val) { auto it = pos[val].lower_bound(range.first); if (it != pos[val].end() && *it <= range.second) { int this_pos = *it; pos[val].erase(it); res += solve(i + 1, n0 + (val == 0), n1 + (val == 1), n); if (res >= mod) res -= mod; pos[val].insert(this_pos); } } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = s.size(); for (int i = 0; i < n; ++i) { if (s[i] == '0') { pos[0].insert(i); pos[0].insert(i); } else if (s[i] == '1') { pos[0].insert(i); pos[1].insert(i); } else { pos[1].insert(i); pos[1].insert(i); } } memset(dp, -1, sizeof(dp)); int result = solve(0, 0, 0, n); printf("%d\n", result); return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <vector> using namespace std; typedef long long lint; const int mod = 998244353, maxn = 2000; int dp[2 * maxn + 1][2 * maxn + 1]; multiset<int> pos[2]; int solve(int i, int n0, int n1, int n) { if (i == 2 * n) { return 1; } int &res = dp[n0][n1]; if (res != -1) return res; pair<int, int> range; if (i < n) { range = {0, i}; } else { range = {0, n - 1}; } res = 0; for (int val = 0; val < 2; ++val) { auto it = pos[val].lower_bound(range.first); if (it != pos[val].end() && *it <= range.second) { int this_pos = *it; pos[val].erase(it); res += solve(i + 1, n0 + (val == 0), n1 + (val == 1), n); if (res >= mod) res -= mod; pos[val].insert(this_pos); } } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = s.size(); for (int i = 0; i < n; ++i) { if (s[i] == '0') { pos[0].insert(i); pos[0].insert(i); } else if (s[i] == '1') { pos[0].insert(i); pos[1].insert(i); } else { pos[1].insert(i); pos[1].insert(i); } } memset(dp, -1, sizeof(dp)); int result = solve(0, 0, 0, n); printf("%d\n", result); return 0; }
replace
28
29
28
29
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 998244353 #define EPS 1e-10 #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i) #define each(a, b) for (auto &(a) : (b)) #define all(v) (v).begin(), (v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end()) #define cmx(x, y) x = max(x, y) #define cmn(x, y) x = min(x, y) #define fi first #define se second #define pb push_back #define show(x) cout << #x << " = " << (x) << endl #define spair(p) cout << #p << ": " << p.fi << " " << p.se << endl #define sar(a, n) \ cout << #a << ":"; \ rep(pachico, n) cout << " " << a[pachico]; \ cout << endl #define svec(v) \ cout << #v << ":"; \ rep(pachico, v.size()) cout << " " << v[pachico]; \ cout << endl #define svecp(v) \ cout << #v << ":"; \ each(pachico, v) cout << " {" << pachico.first << ":" << pachico.second \ << "}"; \ cout << endl #define sset(s) \ cout << #s << ":"; \ each(pachico, s) cout << " " << pachico; \ cout << endl #define smap(m) \ cout << #m << ":"; \ each(pachico, m) cout << " {" << pachico.first << ":" << pachico.second \ << "}"; \ cout << endl using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<P> vp; typedef vector<string> vs; const int MAX_N = 2005; inline int add(int x, int y) { return (x + y) % MOD; } inline int sub(int x, int y) { return (x + MOD - y) % MOD; } inline int mul(int x, int y) { return (ll)x * y % MOD; } int dp[MAX_N][MAX_N], ok[MAX_N][MAX_N]; int tma[2 * MAX_N], tmb[2 * MAX_N]; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int n = len(s); dp[0][0] = 1; vi apos, bpos; rep(i, n) { if (s[i] == '0') { apos.pb(i + 1), apos.pb(i + 1); } else if (s[i] == '1') { apos.pb(i + 1), bpos.pb(i + 1); } else { bpos.pb(i + 1), bpos.pb(i + 1); } } rep(i, len(apos) + 1) { rep(j, len(bpos) + 1) { ok[i][j] = INF; } } ok[0][0] = 0; rep(i, len(apos) + 1) { rep(j, len(bpos) + 1) { if (i > 0) { cmn(ok[i][j], max(ok[i - 1][j] + 1, apos[i - 1])); } if (j > 0) { cmn(ok[i][j], max(ok[i][j - 1] + 1, bpos[j - 1])); } } } rep(i, len(apos) + 1) { rep(j, len(bpos) + 1) { if (i < len(apos) && ok[i + 1][j] <= i + j + 1) { dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]); } if (j < len(bpos) && ok[i][j + 1] <= i + j + 1) { dp[i][j + 1] = add(dp[i][j + 1], dp[i][j]); } } } int ans = 0; rep(i, 2 * n + 1) { ans = add(ans, dp[i][2 * n - i]); } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 998244353 #define EPS 1e-10 #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i) #define each(a, b) for (auto &(a) : (b)) #define all(v) (v).begin(), (v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end()) #define cmx(x, y) x = max(x, y) #define cmn(x, y) x = min(x, y) #define fi first #define se second #define pb push_back #define show(x) cout << #x << " = " << (x) << endl #define spair(p) cout << #p << ": " << p.fi << " " << p.se << endl #define sar(a, n) \ cout << #a << ":"; \ rep(pachico, n) cout << " " << a[pachico]; \ cout << endl #define svec(v) \ cout << #v << ":"; \ rep(pachico, v.size()) cout << " " << v[pachico]; \ cout << endl #define svecp(v) \ cout << #v << ":"; \ each(pachico, v) cout << " {" << pachico.first << ":" << pachico.second \ << "}"; \ cout << endl #define sset(s) \ cout << #s << ":"; \ each(pachico, s) cout << " " << pachico; \ cout << endl #define smap(m) \ cout << #m << ":"; \ each(pachico, m) cout << " {" << pachico.first << ":" << pachico.second \ << "}"; \ cout << endl using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<P> vp; typedef vector<string> vs; const int MAX_N = 4005; inline int add(int x, int y) { return (x + y) % MOD; } inline int sub(int x, int y) { return (x + MOD - y) % MOD; } inline int mul(int x, int y) { return (ll)x * y % MOD; } int dp[MAX_N][MAX_N], ok[MAX_N][MAX_N]; int tma[2 * MAX_N], tmb[2 * MAX_N]; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int n = len(s); dp[0][0] = 1; vi apos, bpos; rep(i, n) { if (s[i] == '0') { apos.pb(i + 1), apos.pb(i + 1); } else if (s[i] == '1') { apos.pb(i + 1), bpos.pb(i + 1); } else { bpos.pb(i + 1), bpos.pb(i + 1); } } rep(i, len(apos) + 1) { rep(j, len(bpos) + 1) { ok[i][j] = INF; } } ok[0][0] = 0; rep(i, len(apos) + 1) { rep(j, len(bpos) + 1) { if (i > 0) { cmn(ok[i][j], max(ok[i - 1][j] + 1, apos[i - 1])); } if (j > 0) { cmn(ok[i][j], max(ok[i][j - 1] + 1, bpos[j - 1])); } } } rep(i, len(apos) + 1) { rep(j, len(bpos) + 1) { if (i < len(apos) && ok[i + 1][j] <= i + j + 1) { dp[i + 1][j] = add(dp[i + 1][j], dp[i][j]); } if (j < len(bpos) && ok[i][j + 1] <= i + j + 1) { dp[i][j + 1] = add(dp[i][j + 1], dp[i][j]); } } } int ans = 0; rep(i, 2 * n + 1) { ans = add(ans, dp[i][2 * n - i]); } cout << ans << "\n"; return 0; }
replace
54
55
54
55
0
p03134
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <stdio.h> #include <vector> using ll = long long int; const int INF = (1 << 30); const ll INFLL = (1ll << 60); const ll MOD = 998244353ll; #define l_ength size void mul_mod(ll &a, ll b) { a *= b; a %= MOD; } void add_mod(ll &a, ll b) { a = (a < MOD) ? a : (a - MOD); b = (b < MOD) ? b : (b - MOD); a += b; a = (a < MOD) ? a : (a - MOD); } ll memo[2222][2222]; bool done[2222][2222]; int m, r[4444], b[4444]; ll solve(int i, int j) { if (done[i][j]) { return memo[i][j]; } done[i][j] = true; if (i > r[i + j] || j > b[i + j]) { return memo[i][j] = 0ll; } if (i + j == m) { return memo[i][j] = 1ll; } memo[i][j] = solve(i + 1, j) + solve(i, j + 1); memo[i][j] %= MOD; return memo[i][j]; } int main(void) { int n, i; std::string s; std::cin >> s; n = s.l_ength(); m = n * 2; for (i = 0; i < n; ++i) { r[i + 1] = s[i] - '0'; b[i + 1] = '2' - s[i]; } for (i = 1; i < m; ++i) { r[i + 1] += r[i]; b[i + 1] += b[i]; } std::cout << solve(0, 0) << std::endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <stdio.h> #include <vector> using ll = long long int; const int INF = (1 << 30); const ll INFLL = (1ll << 60); const ll MOD = 998244353ll; #define l_ength size void mul_mod(ll &a, ll b) { a *= b; a %= MOD; } void add_mod(ll &a, ll b) { a = (a < MOD) ? a : (a - MOD); b = (b < MOD) ? b : (b - MOD); a += b; a = (a < MOD) ? a : (a - MOD); } ll memo[4444][4444]; bool done[4444][4444]; int m, r[4444], b[4444]; ll solve(int i, int j) { if (done[i][j]) { return memo[i][j]; } done[i][j] = true; if (i > r[i + j] || j > b[i + j]) { return memo[i][j] = 0ll; } if (i + j == m) { return memo[i][j] = 1ll; } memo[i][j] = solve(i + 1, j) + solve(i, j + 1); memo[i][j] %= MOD; return memo[i][j]; } int main(void) { int n, i; std::string s; std::cin >> s; n = s.l_ength(); m = n * 2; for (i = 0; i < n; ++i) { r[i + 1] = s[i] - '0'; b[i + 1] = '2' - s[i]; } for (i = 1; i < m; ++i) { r[i + 1] += r[i]; b[i + 1] += b[i]; } std::cout << solve(0, 0) << std::endl; return 0; }
replace
26
28
26
28
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long intl; int MOD = 998244353; using namespace std; int main() { vector<vector<int>> dp(2001, vector<int>(2001, 0)); vector<vector<int>> visited(2001, vector<int>(2001, 0)); string s; cin >> s; int n = s.size(); vector<pair<int, int>> v; v.push_back({0, 0}); for (int i = 1; i <= n; i++) { if (s[i - 1] == '0') { v.push_back({v[i - 1].first + 2, v[i - 1].second}); } else if (s[i - 1] == '1') { v.push_back({v[i - 1].first + 1, v[i - 1].second + 1}); } else { v.push_back({v[i - 1].first, v[i - 1].second + 2}); } } dp[0][0] = 1; queue<pair<int, int>> q; q.push({0, 0}); while (!q.empty()) { int a = q.front().first; int b = q.front().second; q.pop(); if (visited[a][b]) { continue; } visited[a][b] = 1; int tot = a + b + 1; if (tot > n) { tot = n; } if (v[tot].second > b) { dp[a][b + 1] += dp[a][b]; dp[a][b + 1] = dp[a][b + 1] % MOD; q.push({a, b + 1}); } if (v[tot].first > a) { dp[a + 1][b] += dp[a][b]; dp[a + 1][b] = dp[a + 1][b] % MOD; q.push({a + 1, b}); } } cout << dp[v[n].first][v[n].second] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long intl; int MOD = 998244353; using namespace std; int main() { vector<vector<int>> dp(4001, vector<int>(4001, 0)); vector<vector<int>> visited(4001, vector<int>(4001, 0)); string s; cin >> s; int n = s.size(); vector<pair<int, int>> v; v.push_back({0, 0}); for (int i = 1; i <= n; i++) { if (s[i - 1] == '0') { v.push_back({v[i - 1].first + 2, v[i - 1].second}); } else if (s[i - 1] == '1') { v.push_back({v[i - 1].first + 1, v[i - 1].second + 1}); } else { v.push_back({v[i - 1].first, v[i - 1].second + 2}); } } dp[0][0] = 1; queue<pair<int, int>> q; q.push({0, 0}); while (!q.empty()) { int a = q.front().first; int b = q.front().second; q.pop(); if (visited[a][b]) { continue; } visited[a][b] = 1; int tot = a + b + 1; if (tot > n) { tot = n; } if (v[tot].second > b) { dp[a][b + 1] += dp[a][b]; dp[a][b + 1] = dp[a][b + 1] % MOD; q.push({a, b + 1}); } if (v[tot].first > a) { dp[a + 1][b] += dp[a][b]; dp[a + 1][b] = dp[a + 1][b] % MOD; q.push({a + 1, b}); } } cout << dp[v[n].first][v[n].second] << endl; }
replace
6
8
6
8
0
p03134
C++
Runtime Error
#include <algorithm> #include <bitset> #include <complex> #include <cstdint> #include <deque> #include <iomanip> #include <iostream> #include <istream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); i++) #define revrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define pb push_back #define f first #define s second void BinarySay(ll x, ll y = 60) { rep(i, y) cout << (x >> (y - 1 - i) & 1); cout << endl; } const ll INFL = 1LL << 60; // 10^18 = 2^60 // ll MOD = 1000000007; ll MOD = 998244353; // vector<mint> dp(N, Mint); // vector<vector<mint>> dp2(N, vector<mint>(N, Mint)); // vector<vector<vector<mint>>> dp3(N, vector<vector<mint>>(N, vector<mint>(N, // Mint))); struct mint { ll x; mint(ll x = 0) : x(x % MOD) {} mint &operator+=(const mint a) { (x += a.x) %= MOD; return *this; } mint &operator-=(const mint a) { (x += MOD - a.x) %= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint &operator%=(const mint a) { (x %= a.x); return *this; } mint &operator++(int) { (x += 1) %= MOD; return *this; } mint &operator--(int) { (x += MOD - 1) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint operator%(const mint a) const { mint res(*this); return res %= a; } mint po(ll t) const { if (!t) return 1; mint a = po(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inverse() const { return po(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inverse(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } bool operator==(const mint a) { return this->x == a.x; } bool operator!=(const mint a) { return this->x != a.x; } void get() { cout << x << endl; } void ge() { cout << x << " "; } }; const mint Mint = 0; mint pow_mod(ll x, ll k) { mint res = 1; mint a = x; while (k > 0) { if (k % 2) { res *= a; } a *= a; k /= 2; } return res; } mint inverse(ll x) { return pow_mod(x, MOD - 2); } // 二項演算 const int MAXcomb = 200010; ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAXcomb; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } mint comb(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; mint res = fac[n]; res *= finv[k] * finv[n - k]; return res; } mint comb_naive(ll N, ll K) { // Kが小さい時 mint res = 1; rep(i, K) res *= (N - i); mint k = 1; rep(i, K) k *= (i + 1); res /= k; return res; } // 第二種スターリング数 const ll MAXStir2 = 3010; vector<vector<mint>> Stir2memo(MAXStir2, vector<mint>(MAXStir2, Mint)); vector<mint> Bellmemo(MAXStir2, Mint); void Stir2init() { Stir2memo[0][0] = 1; rep(i, MAXStir2 - 1) rep(j, i + 1) Stir2memo[i + 1][j + 1] = Stir2memo[i][j] + Stir2memo[i][j + 1] * (j + 1); rep(i, MAXStir2) { Bellmemo[i] = 0; rep(j, i + 1) Bellmemo[i] += Stir2memo[i][j]; } } mint Stir2(ll i, ll j) { // 区別できるi個をjグループに分ける場合の数 if (i < 0 || j < 0 || i < j) return 0; return Stir2memo[i][j]; } mint Bell(ll x) { // 区別できるx個をグループ分けする方法全ての場合の数 if (x < 0) return 0; return Bellmemo[x]; } mint kai_mod(ll K) { if (K < 0) return 0; if (K == 0) return 1; return kai_mod(K - 1) * K; } // 約数の列挙O(√n) vector<ll> divisor(ll n) { vector<ll> res(0); for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (i != n / i) res.push_back(n / i); } } sort(res.begin(), res.end()); return res; } // Range Sum Query const ll N_ = (1 << 18); ll seg[2 * N_ - 1]; // 未確認 void add(ll k, ll x) { k += N_ - 1; seg[k] += x; while (k > 0) { k = (k - 1) / 2; seg[k] = seg[2 * k + 1] + seg[2 * k + 2]; } } ll get_sum(ll x, ll y, ll k = 0, ll left = 0, ll right = N_) { if (right <= x || y <= left) return 0; if (x <= left && right <= y) return seg[k]; ll mid = (left + right) / 2; ll l = get_sum(x, y, 2 * k + 1, left, mid); ll r = get_sum(x, y, 2 * k + 2, mid, right); return l + r; } mint dp[2010][2010]; ll N; ll B; void solve() { dp[0][0] = 1; // i番目まで見て、青をj個使った for (ll i = 0; i < 2 * N; i++) { ll can_use_blue = get_sum(0, i + 1); ll can_use_red = 2 * (i + 1) - can_use_blue; for (ll j = 0; j <= B; j++) { if (can_use_blue >= j + 1) { dp[i + 1][j + 1] += dp[i][j]; } if (can_use_red >= i + 1 - j) { dp[i + 1][j] += dp[i][j]; } } } dp[2 * N][B].get(); } int main() { string S; cin >> S; N = S.size(); rep(i, N) { if (S[i] == '2') add(i, 2); if (S[i] == '1') add(i, 1); } B = get_sum(0, N_); solve(); }
#include <algorithm> #include <bitset> #include <complex> #include <cstdint> #include <deque> #include <iomanip> #include <iostream> #include <istream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); i++) #define revrep(i, n) for (ll i = (n)-1; i >= 0; i--) #define pb push_back #define f first #define s second void BinarySay(ll x, ll y = 60) { rep(i, y) cout << (x >> (y - 1 - i) & 1); cout << endl; } const ll INFL = 1LL << 60; // 10^18 = 2^60 // ll MOD = 1000000007; ll MOD = 998244353; // vector<mint> dp(N, Mint); // vector<vector<mint>> dp2(N, vector<mint>(N, Mint)); // vector<vector<vector<mint>>> dp3(N, vector<vector<mint>>(N, vector<mint>(N, // Mint))); struct mint { ll x; mint(ll x = 0) : x(x % MOD) {} mint &operator+=(const mint a) { (x += a.x) %= MOD; return *this; } mint &operator-=(const mint a) { (x += MOD - a.x) %= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint &operator%=(const mint a) { (x %= a.x); return *this; } mint &operator++(int) { (x += 1) %= MOD; return *this; } mint &operator--(int) { (x += MOD - 1) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint operator%(const mint a) const { mint res(*this); return res %= a; } mint po(ll t) const { if (!t) return 1; mint a = po(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inverse() const { return po(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inverse(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } bool operator==(const mint a) { return this->x == a.x; } bool operator!=(const mint a) { return this->x != a.x; } void get() { cout << x << endl; } void ge() { cout << x << " "; } }; const mint Mint = 0; mint pow_mod(ll x, ll k) { mint res = 1; mint a = x; while (k > 0) { if (k % 2) { res *= a; } a *= a; k /= 2; } return res; } mint inverse(ll x) { return pow_mod(x, MOD - 2); } // 二項演算 const int MAXcomb = 200010; ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAXcomb; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } mint comb(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; mint res = fac[n]; res *= finv[k] * finv[n - k]; return res; } mint comb_naive(ll N, ll K) { // Kが小さい時 mint res = 1; rep(i, K) res *= (N - i); mint k = 1; rep(i, K) k *= (i + 1); res /= k; return res; } // 第二種スターリング数 const ll MAXStir2 = 3010; vector<vector<mint>> Stir2memo(MAXStir2, vector<mint>(MAXStir2, Mint)); vector<mint> Bellmemo(MAXStir2, Mint); void Stir2init() { Stir2memo[0][0] = 1; rep(i, MAXStir2 - 1) rep(j, i + 1) Stir2memo[i + 1][j + 1] = Stir2memo[i][j] + Stir2memo[i][j + 1] * (j + 1); rep(i, MAXStir2) { Bellmemo[i] = 0; rep(j, i + 1) Bellmemo[i] += Stir2memo[i][j]; } } mint Stir2(ll i, ll j) { // 区別できるi個をjグループに分ける場合の数 if (i < 0 || j < 0 || i < j) return 0; return Stir2memo[i][j]; } mint Bell(ll x) { // 区別できるx個をグループ分けする方法全ての場合の数 if (x < 0) return 0; return Bellmemo[x]; } mint kai_mod(ll K) { if (K < 0) return 0; if (K == 0) return 1; return kai_mod(K - 1) * K; } // 約数の列挙O(√n) vector<ll> divisor(ll n) { vector<ll> res(0); for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { res.push_back(i); if (i != n / i) res.push_back(n / i); } } sort(res.begin(), res.end()); return res; } // Range Sum Query const ll N_ = (1 << 18); ll seg[2 * N_ - 1]; // 未確認 void add(ll k, ll x) { k += N_ - 1; seg[k] += x; while (k > 0) { k = (k - 1) / 2; seg[k] = seg[2 * k + 1] + seg[2 * k + 2]; } } ll get_sum(ll x, ll y, ll k = 0, ll left = 0, ll right = N_) { if (right <= x || y <= left) return 0; if (x <= left && right <= y) return seg[k]; ll mid = (left + right) / 2; ll l = get_sum(x, y, 2 * k + 1, left, mid); ll r = get_sum(x, y, 2 * k + 2, mid, right); return l + r; } mint dp[4010][4010]; ll N; ll B; void solve() { dp[0][0] = 1; // i番目まで見て、青をj個使った for (ll i = 0; i < 2 * N; i++) { ll can_use_blue = get_sum(0, i + 1); ll can_use_red = 2 * (i + 1) - can_use_blue; for (ll j = 0; j <= B; j++) { if (can_use_blue >= j + 1) { dp[i + 1][j + 1] += dp[i][j]; } if (can_use_red >= i + 1 - j) { dp[i + 1][j] += dp[i][j]; } } } dp[2 * N][B].get(); } int main() { string S; cin >> S; N = S.size(); rep(i, N) { if (S[i] == '2') add(i, 2); if (S[i] == '1') add(i, 1); } B = get_sum(0, N_); solve(); }
replace
214
215
214
215
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03134
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #define rep(i, l, r) for (int i = (l); i <= (r); i++) typedef long long ll; using namespace std; const int N = 2010, mod = 998244353; char s[N]; int n, ans, a[N], b[N], f[N][N]; void inc(int &x, int y) { x += y; x -= (x >= mod) ? mod : 0; } int main() { scanf("%s", s + 1); n = strlen(s + 1); rep(i, 1, n) a[i] = a[i - 1] + 2 - (s[i] - '0'), b[i] = b[i - 1] + s[i] - '0'; f[0][0] = 1; rep(i, 0, 2 * n) rep(j, 0, i) if (f[i][j]) { if (a[min(i + 1, n)] > j) inc(f[i + 1][j + 1], f[i][j]); if (b[min(i + 1, n)] > i - j) inc(f[i + 1][j], f[i][j]); } printf("%d\n", f[2 * n][a[n]]); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #define rep(i, l, r) for (int i = (l); i <= (r); i++) typedef long long ll; using namespace std; const int N = 4010, mod = 998244353; char s[N]; int n, ans, a[N], b[N], f[N][N]; void inc(int &x, int y) { x += y; x -= (x >= mod) ? mod : 0; } int main() { scanf("%s", s + 1); n = strlen(s + 1); rep(i, 1, n) a[i] = a[i - 1] + 2 - (s[i] - '0'), b[i] = b[i - 1] + s[i] - '0'; f[0][0] = 1; rep(i, 0, 2 * n) rep(j, 0, i) if (f[i][j]) { if (a[min(i + 1, n)] > j) inc(f[i + 1][j + 1], f[i][j]); if (b[min(i + 1, n)] > i - j) inc(f[i + 1][j], f[i][j]); } printf("%d\n", f[2 * n][a[n]]); return 0; }
replace
8
9
8
9
0
p03134
C++
Runtime Error
#include <cstdio> #include <cstring> #include <iostream> using namespace std; const int mo = 998244353; int f[2001][2001], s1[2001], s2[2001]; char s[2001]; int main() { scanf("%s", s); int n = strlen(s); for (int i = 0; i < n; i++) { s1[i + 1] = s1[i] + s[i] - '0'; s2[i + 1] = 2 * (i + 1) - s1[i + 1]; } f[0][0] = 1; for (int i = 0; i <= s1[n]; i++) for (int j = 0; j <= s2[n]; j++) if ((s1[min(i + j, n)] >= i) && (s2[min(i + j, n)] >= j)) { if (i) f[i][j] = (f[i][j] + f[i - 1][j]) % mo; if (j) f[i][j] = (f[i][j] + f[i][j - 1]) % mo; } cout << f[s1[n]][s2[n]] << endl; return 0; }
#include <cstdio> #include <cstring> #include <iostream> using namespace std; const int mo = 998244353; int f[4001][4001], s1[2001], s2[2001]; char s[2001]; int main() { scanf("%s", s); int n = strlen(s); for (int i = 0; i < n; i++) { s1[i + 1] = s1[i] + s[i] - '0'; s2[i + 1] = 2 * (i + 1) - s1[i + 1]; } f[0][0] = 1; for (int i = 0; i <= s1[n]; i++) for (int j = 0; j <= s2[n]; j++) if ((s1[min(i + j, n)] >= i) && (s2[min(i + j, n)] >= j)) { if (i) f[i][j] = (f[i][j] + f[i - 1][j]) % mo; if (j) f[i][j] = (f[i][j] + f[i][j - 1]) % mo; } cout << f[s1[n]][s2[n]] << endl; return 0; }
replace
8
9
8
9
0
p03134
C++
Runtime Error
#include <algorithm> #include <stdio.h> #include <string.h> using namespace std; const int maxn = 2100; const int mod = 998244353; char z[maxn]; int n; int prer[maxn]; int dp[maxn * 2][maxn * 2]; void work() { int i, j; scanf("%s", z + 1); n = strlen(z + 1); for (i = 1; i <= n; i++) prer[i] = prer[i - 1] + (2 - z[i] + '0'); for (i = n + 1; i <= n + n; i++) prer[i] = prer[i - 1]; dp[0][0] = 1; for (i = 0; i < n * 2; i++) { for (j = 0; j <= i; j++) { if (j < prer[i + 1]) { dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod; } if (i - j < i * 2 + 2 - prer[i + 1]) { dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod; } // printf ( "%d %d %d\n" , i , j , dp[i][j] ); } } printf("%d\n", dp[n * 2][prer[n * 2]]); } int main() { work(); return 0; }
#include <algorithm> #include <stdio.h> #include <string.h> using namespace std; const int maxn = 2100; const int mod = 998244353; char z[maxn]; int n; int prer[maxn * 2]; int dp[maxn * 2][maxn * 2]; void work() { int i, j; scanf("%s", z + 1); n = strlen(z + 1); for (i = 1; i <= n; i++) prer[i] = prer[i - 1] + (2 - z[i] + '0'); for (i = n + 1; i <= n + n; i++) prer[i] = prer[i - 1]; dp[0][0] = 1; for (i = 0; i < n * 2; i++) { for (j = 0; j <= i; j++) { if (j < prer[i + 1]) { dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod; } if (i - j < i * 2 + 2 - prer[i + 1]) { dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod; } // printf ( "%d %d %d\n" , i , j , dp[i][j] ); } } printf("%d\n", dp[n * 2][prer[n * 2]]); } int main() { work(); return 0; }
replace
10
11
10
11
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; #define rep(i, x, y) \ for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \ i < i##_max_for_repmacro; ++i) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define print(x) #endif template <i64 p> class fp { public: i64 x; fp() : x(0) {} fp(i64 x_) : x((x_ % p + p) % p) {} fp operator+() const { return fp(x); } fp operator-() const { return fp(-x); } fp &operator+=(const fp &y) { x += y.x; if (x >= p) x -= p; return *this; } fp &operator-=(const fp &y) { return *this += -y; } fp &operator*=(const fp &y) { x = x * y.x % p; return *this; } fp &operator/=(const fp &y) { return *this *= fp(inverse(y.x)); } fp operator+(const fp &y) const { return fp(x) += y; } fp operator-(const fp &y) const { return fp(x) -= y; } fp operator*(const fp &y) const { return fp(x) *= y; } fp operator/(const fp &y) const { return fp(x) /= y; } bool operator==(const fp &y) const { return x == y.x; } bool operator!=(const fp &y) const { return !(*this == y); } i64 extgcd(i64 a, i64 b, i64 &x, i64 &y) { i64 d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } i64 inverse(i64 a) { i64 x, y; extgcd(a, p, x, y); return (x % p + p) % p; } }; template <i64 p> i64 abs(const fp<p> &x) { return x.x; } template <i64 p> ostream &operator<<(ostream &os, const fp<p> &x) { os << x.x; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename A, typename T, size_t size> void fill(A (&ary)[size], const T &val) { fill((T *)ary, (T *)(ary + size), val); } // x未満の要素の個数を返す template <typename T> i64 count_less(const vector<T> &v, T x) { return lower_bound(begin(v), end(v), x) - begin(v); } // x以下の要素の個数を返す template <typename T> i64 count_less_or_equal(const vector<T> &v, T x) { return upper_bound(begin(v), end(v), x) - begin(v); } // xより大きい要素の個数を返す template <typename T> i64 count_greater(const vector<T> &v, T x) { return end(v) - upper_bound(begin(v), end(v), x); } // x以上の要素の個数を返す template <typename T> i64 count_greater_or_equal(const vector<T> &v, T x) { return end(v) - lower_bound(begin(v), end(v), x); } // x未満の要素のうち最大のものを返す template <typename T> T max_less(const vector<T> &v, T x) { return *(lower_bound(begin(v), end(v), x) - 1); } // x以下の要素のうち最大のものを返す template <typename T> T max_less_or_equal(const vector<T> &v, T x) { return *(upper_bound(begin(v), end(v), x) - 1); } // xより大きい要素のうち最小のものを返す template <typename T> T min_greater(const vector<T> &v, T x) { return *upper_bound(begin(v), end(v), x); } // x以上の要素のうち最小のものを返す template <typename T> T min_greater_or_equal(const vector<T> &v, T x) { return *lower_bound(begin(v), end(v), x); } constexpr int inf = 1.01e9; constexpr i64 inf64 = 4.01e18; constexpr double eps = 1e-9; void solve() { constexpr i64 mod = 998244353; string S; cin >> S; /* set<string> st; function<void(vector<vector<int>>, int, string)> dfs=[&](vector<vector<int>> v, int i, string res){ if(v.empty()){ st.insert(res); return; } if(i==v.size()){ if(v.back().empty()){ v.pop_back(); } dfs(v,0,res); return; } rep(j,0,v[i].size()){ auto nv=v; auto nres=res; if(i==0){ nres+='0'+nv[i][j]; }else{ nv[i-1].emplace_back(nv[i][j]); } nv[i].erase(begin(nv[i])+j); dfs(nv,i+1,nres); } }; */ const i64 N = S.size(); function<void(vector<vector<int>> &, int, string &)> find_min = [&](vector<vector<int>> &v, int i, string &res) { while (!v.empty()) { if (i == v.size()) { if (v.back().empty()) { v.pop_back(); } i = 0; continue; } sort(begin(v[i]), end(v[i])); if (i == 0) { res += '0' + v[i][0]; } else { v[i - 1].emplace_back(v[i][0]); } v[i].erase(begin(v[i])); ++i; } }; function<void(vector<vector<int>> &, int, string &)> find_max = [&](vector<vector<int>> &v, int i, string &res) { while (!v.empty()) { if (i == v.size()) { if (v.back().empty()) { v.pop_back(); } i = 0; continue; } sort(rbegin(v[i]), rend(v[i])); if (i == 0) { res += '0' + v[i][0]; } else { v[i - 1].emplace_back(v[i][0]); } v[i].erase(begin(v[i])); ++i; } }; vector<vector<int>> v(N); rep(i, 0, N) { if (S[i] == '0') { v[i].emplace_back(0); v[i].emplace_back(0); } else if (S[i] == '1') { v[i].emplace_back(0); v[i].emplace_back(1); } else { v[i].emplace_back(1); v[i].emplace_back(1); } } string mini, maxi; { auto tv = v; find_min(tv, 0, mini); } { auto tv = v; find_max(tv, 0, maxi); } print(mini); print(maxi); vector<i64> rmin(N), bmin(N); { i64 r = 0, b = 0; rep(i, 0, N) { rep(j, 0, 2) { if (v[i][j] == 0) ++r; else ++b; } rmin[i] = max(i + 1 - b, i64(0)); bmin[i] = max(i + 1 - r, i64(0)); } } print(rmin); print(bmin); function<fp<mod>(string)> count = [&](string m) { constexpr i64 maxn = 2000; static fp<mod> dp[maxn * 2][2][maxn + 1]; // 桁, 境界か?, 使用したbの数 fill_n((fp<mod> *)dp, maxn * 2 * 2 * (maxn + 1), fp<mod>(0)); i64 sumb = 0; rep(i, 0, m.size()) if (m[i] == '1')++ sumb; if (m[0] == '0') { dp[0][1][0] = 1; } else { dp[0][0][0] = 1; dp[0][1][1] = 1; } rep(i, 0, m.size() - 1) { rep(j, 0, 2) { rep(k, 0, sumb + 1) { if (i < N) { i64 r = i + 1 - k; i64 b = k; if (r < rmin[i] or b < bmin[i]) continue; } // r=0を置く if (m[i + 1] == '0') { if (j == 0) { // 既に境界より低い dp[i + 1][0][k] += dp[i][j][k]; } else { dp[i + 1][1][k] += dp[i][j][k]; } } else { dp[i + 1][0][k] += dp[i][j][k]; } // sumb=1を置く if (k < sumb) { if (m[i + 1] == '0') { if (j == 0) { // 既に境界より低い dp[i + 1][0][k + 1] += dp[i][j][k]; } else { // 境界を超える } } else { if (j == 0) { // 既に境界より低い dp[i + 1][0][k + 1] += dp[i][j][k]; } else { // 境界にいる dp[i + 1][1][k + 1] += dp[i][j][k]; } } } } } } return dp[m.size() - 1][0][sumb] + dp[m.size() - 1][1][sumb]; }; const auto ans = count(maxi) - count(mini) + 1; cout << ans << endl; /* #ifdef DEBUG dfs(v,0,""); print(st.size()); for(auto str:st){ cout << str << endl; } #endif */ } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; #define rep(i, x, y) \ for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \ i < i##_max_for_repmacro; ++i) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define print(x) #endif template <i64 p> class fp { public: i64 x; fp() : x(0) {} fp(i64 x_) : x((x_ % p + p) % p) {} fp operator+() const { return fp(x); } fp operator-() const { return fp(-x); } fp &operator+=(const fp &y) { x += y.x; if (x >= p) x -= p; return *this; } fp &operator-=(const fp &y) { return *this += -y; } fp &operator*=(const fp &y) { x = x * y.x % p; return *this; } fp &operator/=(const fp &y) { return *this *= fp(inverse(y.x)); } fp operator+(const fp &y) const { return fp(x) += y; } fp operator-(const fp &y) const { return fp(x) -= y; } fp operator*(const fp &y) const { return fp(x) *= y; } fp operator/(const fp &y) const { return fp(x) /= y; } bool operator==(const fp &y) const { return x == y.x; } bool operator!=(const fp &y) const { return !(*this == y); } i64 extgcd(i64 a, i64 b, i64 &x, i64 &y) { i64 d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } i64 inverse(i64 a) { i64 x, y; extgcd(a, p, x, y); return (x % p + p) % p; } }; template <i64 p> i64 abs(const fp<p> &x) { return x.x; } template <i64 p> ostream &operator<<(ostream &os, const fp<p> &x) { os << x.x; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename A, typename T, size_t size> void fill(A (&ary)[size], const T &val) { fill((T *)ary, (T *)(ary + size), val); } // x未満の要素の個数を返す template <typename T> i64 count_less(const vector<T> &v, T x) { return lower_bound(begin(v), end(v), x) - begin(v); } // x以下の要素の個数を返す template <typename T> i64 count_less_or_equal(const vector<T> &v, T x) { return upper_bound(begin(v), end(v), x) - begin(v); } // xより大きい要素の個数を返す template <typename T> i64 count_greater(const vector<T> &v, T x) { return end(v) - upper_bound(begin(v), end(v), x); } // x以上の要素の個数を返す template <typename T> i64 count_greater_or_equal(const vector<T> &v, T x) { return end(v) - lower_bound(begin(v), end(v), x); } // x未満の要素のうち最大のものを返す template <typename T> T max_less(const vector<T> &v, T x) { return *(lower_bound(begin(v), end(v), x) - 1); } // x以下の要素のうち最大のものを返す template <typename T> T max_less_or_equal(const vector<T> &v, T x) { return *(upper_bound(begin(v), end(v), x) - 1); } // xより大きい要素のうち最小のものを返す template <typename T> T min_greater(const vector<T> &v, T x) { return *upper_bound(begin(v), end(v), x); } // x以上の要素のうち最小のものを返す template <typename T> T min_greater_or_equal(const vector<T> &v, T x) { return *lower_bound(begin(v), end(v), x); } constexpr int inf = 1.01e9; constexpr i64 inf64 = 4.01e18; constexpr double eps = 1e-9; void solve() { constexpr i64 mod = 998244353; string S; cin >> S; /* set<string> st; function<void(vector<vector<int>>, int, string)> dfs=[&](vector<vector<int>> v, int i, string res){ if(v.empty()){ st.insert(res); return; } if(i==v.size()){ if(v.back().empty()){ v.pop_back(); } dfs(v,0,res); return; } rep(j,0,v[i].size()){ auto nv=v; auto nres=res; if(i==0){ nres+='0'+nv[i][j]; }else{ nv[i-1].emplace_back(nv[i][j]); } nv[i].erase(begin(nv[i])+j); dfs(nv,i+1,nres); } }; */ const i64 N = S.size(); function<void(vector<vector<int>> &, int, string &)> find_min = [&](vector<vector<int>> &v, int i, string &res) { while (!v.empty()) { if (i == v.size()) { if (v.back().empty()) { v.pop_back(); } i = 0; continue; } sort(begin(v[i]), end(v[i])); if (i == 0) { res += '0' + v[i][0]; } else { v[i - 1].emplace_back(v[i][0]); } v[i].erase(begin(v[i])); ++i; } }; function<void(vector<vector<int>> &, int, string &)> find_max = [&](vector<vector<int>> &v, int i, string &res) { while (!v.empty()) { if (i == v.size()) { if (v.back().empty()) { v.pop_back(); } i = 0; continue; } sort(rbegin(v[i]), rend(v[i])); if (i == 0) { res += '0' + v[i][0]; } else { v[i - 1].emplace_back(v[i][0]); } v[i].erase(begin(v[i])); ++i; } }; vector<vector<int>> v(N); rep(i, 0, N) { if (S[i] == '0') { v[i].emplace_back(0); v[i].emplace_back(0); } else if (S[i] == '1') { v[i].emplace_back(0); v[i].emplace_back(1); } else { v[i].emplace_back(1); v[i].emplace_back(1); } } string mini, maxi; { auto tv = v; find_min(tv, 0, mini); } { auto tv = v; find_max(tv, 0, maxi); } print(mini); print(maxi); vector<i64> rmin(N), bmin(N); { i64 r = 0, b = 0; rep(i, 0, N) { rep(j, 0, 2) { if (v[i][j] == 0) ++r; else ++b; } rmin[i] = max(i + 1 - b, i64(0)); bmin[i] = max(i + 1 - r, i64(0)); } } print(rmin); print(bmin); function<fp<mod>(string)> count = [&](string m) { constexpr i64 maxn = 2000; static fp<mod> dp[maxn * 2][2][2 * maxn + 1]; // 桁, 境界か?, 使用したbの数 fill_n((fp<mod> *)dp, maxn * 2 * 2 * (2 * maxn + 1), fp<mod>(0)); i64 sumb = 0; rep(i, 0, m.size()) if (m[i] == '1')++ sumb; if (m[0] == '0') { dp[0][1][0] = 1; } else { dp[0][0][0] = 1; dp[0][1][1] = 1; } rep(i, 0, m.size() - 1) { rep(j, 0, 2) { rep(k, 0, sumb + 1) { if (i < N) { i64 r = i + 1 - k; i64 b = k; if (r < rmin[i] or b < bmin[i]) continue; } // r=0を置く if (m[i + 1] == '0') { if (j == 0) { // 既に境界より低い dp[i + 1][0][k] += dp[i][j][k]; } else { dp[i + 1][1][k] += dp[i][j][k]; } } else { dp[i + 1][0][k] += dp[i][j][k]; } // sumb=1を置く if (k < sumb) { if (m[i + 1] == '0') { if (j == 0) { // 既に境界より低い dp[i + 1][0][k + 1] += dp[i][j][k]; } else { // 境界を超える } } else { if (j == 0) { // 既に境界より低い dp[i + 1][0][k + 1] += dp[i][j][k]; } else { // 境界にいる dp[i + 1][1][k + 1] += dp[i][j][k]; } } } } } } return dp[m.size() - 1][0][sumb] + dp[m.size() - 1][1][sumb]; }; const auto ans = count(maxi) - count(mini) + 1; cout << ans << endl; /* #ifdef DEBUG dfs(v,0,""); print(st.size()); for(auto str:st){ cout << str << endl; } #endif */ } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); solve(); return 0; }
replace
272
274
272
274
-11
p03134
C++
Runtime Error
#include <algorithm> #include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define EACH(i, c) \ for (__typeof((c).begin()) i = (c).begin(), i##_end = (c).end(); \ i != i##_end; ++i) #define eprintf(...) fprintf(stderr, __VA_ARGS__) template <class T> inline void amin(T &x, const T &y) { if (y < x) x = y; } template <class T> inline void amax(T &x, const T &y) { if (x < y) x = y; } template <class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp = 0; begin != end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); } putchar('\n'); } template <unsigned MOD> struct ModInt { static const unsigned static_MOD = MOD; unsigned x; void undef() { x = (unsigned)-1; } bool isnan() const { return x == (unsigned)-1; } inline int geti() const { return (int)x; } ModInt() { x = 0; } ModInt(const ModInt &y) { x = y.x; } ModInt(int y) { if (y < 0 || (int)MOD <= y) y %= (int)MOD; if (y < 0) y += MOD; x = y; } ModInt(unsigned y) { if (MOD <= y) x = y % MOD; else x = y; } ModInt(long long y) { if (y < 0 || MOD <= y) y %= MOD; if (y < 0) y += MOD; x = y; } ModInt(unsigned long long y) { if (MOD <= y) x = y % MOD; else x = y; } ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u << 31)) x += MOD; return *this; } ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; } ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; } ModInt operator-() const { return (x ? MOD - x : 0); } ModInt inv() const { unsigned a = MOD, b = x; int u = 0, v = 1; while (b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if (u < 0) u += MOD; return ModInt(u); } ModInt pow(long long y) const { ModInt b = *this, r = 1; if (y < 0) { b = b.inv(); y = -y; } for (; y; y >>= 1) { if (y & 1) r *= b; b *= b; } return r; } friend ModInt operator+(ModInt x, const ModInt y) { return x += y; } friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; } friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; } friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); } friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; } friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; } friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; } }; const LL MOD = 998244353; typedef ModInt<MOD> Mint; int N; char S[2011]; Mint dp[2011][2011]; void MAIN() { scanf("%s", S); N = strlen(S); dp[0][0] = 1; int R = 0, B = 0; REP(i, N * 2) { int adR = 0, adB = 0; if (i < N) { if (S[i] == '0') adR += 2; if (S[i] == '1') { adR++; adB++; } if (S[i] == '2') adB += 2; } REP(r, R + 1) { int b = R + B - i - r; if (b < 0 || B < b) continue; if (r + adR) dp[i + 1][r + adR - 1] += dp[i][r]; if (b + adB) dp[i + 1][r + adR] += dp[i][r]; } R += adR; B += adB; } printf("%d\n", dp[N * 2][0].geti()); } int main() { int TC = 1; // scanf("%d", &TC); REP(tc, TC) MAIN(); return 0; }
#include <algorithm> #include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define EACH(i, c) \ for (__typeof((c).begin()) i = (c).begin(), i##_end = (c).end(); \ i != i##_end; ++i) #define eprintf(...) fprintf(stderr, __VA_ARGS__) template <class T> inline void amin(T &x, const T &y) { if (y < x) x = y; } template <class T> inline void amax(T &x, const T &y) { if (x < y) x = y; } template <class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp = 0; begin != end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); } putchar('\n'); } template <unsigned MOD> struct ModInt { static const unsigned static_MOD = MOD; unsigned x; void undef() { x = (unsigned)-1; } bool isnan() const { return x == (unsigned)-1; } inline int geti() const { return (int)x; } ModInt() { x = 0; } ModInt(const ModInt &y) { x = y.x; } ModInt(int y) { if (y < 0 || (int)MOD <= y) y %= (int)MOD; if (y < 0) y += MOD; x = y; } ModInt(unsigned y) { if (MOD <= y) x = y % MOD; else x = y; } ModInt(long long y) { if (y < 0 || MOD <= y) y %= MOD; if (y < 0) y += MOD; x = y; } ModInt(unsigned long long y) { if (MOD <= y) x = y % MOD; else x = y; } ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u << 31)) x += MOD; return *this; } ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; } ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; } ModInt operator-() const { return (x ? MOD - x : 0); } ModInt inv() const { unsigned a = MOD, b = x; int u = 0, v = 1; while (b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if (u < 0) u += MOD; return ModInt(u); } ModInt pow(long long y) const { ModInt b = *this, r = 1; if (y < 0) { b = b.inv(); y = -y; } for (; y; y >>= 1) { if (y & 1) r *= b; b *= b; } return r; } friend ModInt operator+(ModInt x, const ModInt y) { return x += y; } friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; } friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; } friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); } friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; } friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; } friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; } }; const LL MOD = 998244353; typedef ModInt<MOD> Mint; int N; char S[2011]; Mint dp[4011][4011]; void MAIN() { scanf("%s", S); N = strlen(S); dp[0][0] = 1; int R = 0, B = 0; REP(i, N * 2) { int adR = 0, adB = 0; if (i < N) { if (S[i] == '0') adR += 2; if (S[i] == '1') { adR++; adB++; } if (S[i] == '2') adB += 2; } REP(r, R + 1) { int b = R + B - i - r; if (b < 0 || B < b) continue; if (r + adR) dp[i + 1][r + adR - 1] += dp[i][r]; if (b + adB) dp[i + 1][r + adR] += dp[i][r]; } R += adR; B += adB; } printf("%d\n", dp[N * 2][0].geti()); } int main() { int TC = 1; // scanf("%d", &TC); REP(tc, TC) MAIN(); return 0; }
replace
131
132
131
132
0
p03134
C++
Runtime Error
#include <algorithm> #include <bitset> #include <chrono> #include <complex> #include <cstdio> #include <fstream> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, x, y) for (ll i = x; i <= y; i++) #define SIZE(a) ll(a.size()) #define vll vector<ll> #define vvll vector<vector<ll>> #define vtype(type) vector<type> #define vvtype(type) vector<vector<type>> #define MEMSET(a, n, m) \ for (ll i = 0; i <= n; i++) \ a[i] = m #define BIT(n) (ll(1) << n) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define UNIQUE_ARRAY(a, x) unique(a + 1, a + x + 1) - a - 1 #define SORT(a, n) sort(a + 1, a + n + 1) #define SORT_O(a, n, order) sort(a + 1, a + n + 1, order) #define PER(i, y, x) for (ll i = y; i >= x; i--) typedef long long ll; using namespace std; ll const MOD = 998244353; ll mod_p(ll x, ll y) { x %= MOD; y %= MOD; return (x + y + MOD) % MOD; } ll mod_m(ll x, ll y) { x %= MOD; y %= MOD; return x * y % MOD; } ll mod_pow(ll x, ll t) { x %= MOD; if (t == 0) { return 1; } else { ll v = mod_pow(x, t / 2); if (t % 2 == 0) { return v * v % MOD; } else { return v * v % MOD * x % MOD; } } } ll mod_inv(ll x) { return mod_pow(x, MOD - 2); } struct edge { long long to; ll name; bool operator<(const edge &rhs) const { return name > rhs.name; } }; ll const MAX = 2e3 + 5; ll dp[MAX][MAX] = {}; int main() { string s; cin >> s; ll n = s.size(); ll bl = 0; ll rd = 0; dp[0][0] = 1; REP(i, 0, n * 2 - 1) { if (i < n) { bl += s[i] - '0'; rd += -(s[i] - '2'); } REP(j, 0, n * 2 - 1) { if (j < bl) { dp[i + 1][j + 1] = mod_p(dp[i + 1][j + 1], dp[i][j]); } if (i - j < rd) { dp[i + 1][j] = mod_p(dp[i + 1][j], dp[i][j]); } } } cout << dp[n * 2][bl] << endl; }
#include <algorithm> #include <bitset> #include <chrono> #include <complex> #include <cstdio> #include <fstream> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, x, y) for (ll i = x; i <= y; i++) #define SIZE(a) ll(a.size()) #define vll vector<ll> #define vvll vector<vector<ll>> #define vtype(type) vector<type> #define vvtype(type) vector<vector<type>> #define MEMSET(a, n, m) \ for (ll i = 0; i <= n; i++) \ a[i] = m #define BIT(n) (ll(1) << n) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define UNIQUE_ARRAY(a, x) unique(a + 1, a + x + 1) - a - 1 #define SORT(a, n) sort(a + 1, a + n + 1) #define SORT_O(a, n, order) sort(a + 1, a + n + 1, order) #define PER(i, y, x) for (ll i = y; i >= x; i--) typedef long long ll; using namespace std; ll const MOD = 998244353; ll mod_p(ll x, ll y) { x %= MOD; y %= MOD; return (x + y + MOD) % MOD; } ll mod_m(ll x, ll y) { x %= MOD; y %= MOD; return x * y % MOD; } ll mod_pow(ll x, ll t) { x %= MOD; if (t == 0) { return 1; } else { ll v = mod_pow(x, t / 2); if (t % 2 == 0) { return v * v % MOD; } else { return v * v % MOD * x % MOD; } } } ll mod_inv(ll x) { return mod_pow(x, MOD - 2); } struct edge { long long to; ll name; bool operator<(const edge &rhs) const { return name > rhs.name; } }; ll const MAX = 4e3 + 5; ll dp[MAX][MAX] = {}; int main() { string s; cin >> s; ll n = s.size(); ll bl = 0; ll rd = 0; dp[0][0] = 1; REP(i, 0, n * 2 - 1) { if (i < n) { bl += s[i] - '0'; rd += -(s[i] - '2'); } REP(j, 0, n * 2 - 1) { if (j < bl) { dp[i + 1][j + 1] = mod_p(dp[i + 1][j + 1], dp[i][j]); } if (i - j < rd) { dp[i + 1][j] = mod_p(dp[i + 1][j], dp[i][j]); } } } cout << dp[n * 2][bl] << endl; }
replace
68
69
68
69
0
p03134
C++
Runtime Error
// #pragma GCC optimize ("-O3","unroll-loops") #include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m - 1; i >= n; --i) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define REVERSE(v, n) reverse(v, v + n); #define VREVERSE(v) reverse(v.begin(), v.end()) #define ll long long #define pb(a) push_back #define print(x) cout << (x) << '\n' #define pe(x) cout << (x) << " " #define DEBUG(x) cout << #x << ": " << x << endl #define lb(v, n) lower_bound(v.begin(), v.end(), n) #define ub(v, n) upper_bound(v.begin(), v.end(), n) #define int long long #define all(x) (x).begin(), (x).end() #define print_space(v) \ REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ") #define move(x) ans.push_back(x), c[x]--, now = x; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } typedef pair<int, int> P; const int MOD = 998244353; const int MAX = 200020; const double pi = acos(-1); const double EPS = 1e-12; const ll INF = 2e18; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; } ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; } ll mult(ll x, ll y) { return (x * y) % MOD; } ll bin_pow(ll x, ll p) { if (p == 0) return 1; if (p & 1) return mult(x, bin_pow(x, p - 1)); return bin_pow(mult(x, x), p / 2); } int dp[2020][2020]; int cumR[2020]; int A[2020], B[2020]; int sumR, sumB; void solve() { string S; cin >> S; int N = S.size(); COMinit(); REP(i, N) { int num = S[i] - '0'; A[i] += num; B[i] += 2 - num; cumR[i + 1] += cumR[i] + A[i]; sumR += A[i]; sumB += B[i]; } dp[0][0] = 1; REP(i, N) { REP(r, N + 1) { if (r > 0 && cumR[i + 1] >= r) dp[i + 1][r] += dp[i][r - 1]; int cumB = (i + 1) * 2 - cumR[i + 1]; if (cumB >= i + 1 - r) dp[i + 1][r] += dp[i][r]; assert(dp[i + 1][r] >= 0); // pe(i+1);pe(r);print(dp[i+1][r]); } } ll ans = 0; REP(r, N + 1) { ll res = mult(dp[N][r], fac[N]); res = mult(res, mult(finv[sumR - r], finv[sumB - (N - r)])); ans = add(ans, res); } print(ans); } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
// #pragma GCC optimize ("-O3","unroll-loops") #include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m - 1; i >= n; --i) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define REVERSE(v, n) reverse(v, v + n); #define VREVERSE(v) reverse(v.begin(), v.end()) #define ll long long #define pb(a) push_back #define print(x) cout << (x) << '\n' #define pe(x) cout << (x) << " " #define DEBUG(x) cout << #x << ": " << x << endl #define lb(v, n) lower_bound(v.begin(), v.end(), n) #define ub(v, n) upper_bound(v.begin(), v.end(), n) #define int long long #define all(x) (x).begin(), (x).end() #define print_space(v) \ REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ") #define move(x) ans.push_back(x), c[x]--, now = x; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } typedef pair<int, int> P; const int MOD = 998244353; const int MAX = 200020; const double pi = acos(-1); const double EPS = 1e-12; const ll INF = 2e18; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; } ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; } ll mult(ll x, ll y) { return (x * y) % MOD; } ll bin_pow(ll x, ll p) { if (p == 0) return 1; if (p & 1) return mult(x, bin_pow(x, p - 1)); return bin_pow(mult(x, x), p / 2); } int dp[2020][2020]; int cumR[2020]; int A[2020], B[2020]; int sumR, sumB; void solve() { string S; cin >> S; int N = S.size(); COMinit(); REP(i, N) { int num = S[i] - '0'; A[i] += num; B[i] += 2 - num; cumR[i + 1] += cumR[i] + A[i]; sumR += A[i]; sumB += B[i]; } dp[0][0] = 1; REP(i, N) { REP(r, N + 1) { if (r > 0 && cumR[i + 1] >= r) dp[i + 1][r] += dp[i][r - 1]; int cumB = (i + 1) * 2 - cumR[i + 1]; if (cumB >= i + 1 - r) dp[i + 1][r] += dp[i][r]; dp[i + 1][r] %= MOD; // pe(i+1);pe(r);print(dp[i+1][r]); } } ll ans = 0; REP(r, N + 1) { ll res = mult(dp[N][r], fac[N]); res = mult(res, mult(finv[sumR - r], finv[sumB - (N - r)])); ans = add(ans, res); } print(ans); } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }
replace
109
110
109
110
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll dp[2010][2010], n; ll nthblueat[2010], nthredat[2010], numblue, numred; char inp[2010]; int main() { scanf(" %s", inp); n = strlen(inp); for (int i = 0; i < n; i++) { if (inp[i] == '0') { nthredat[numred++] = i; nthredat[numred++] = i; } else if (inp[i] == '1') { nthredat[numred++] = i; nthblueat[numblue++] = i; } else { nthblueat[numblue++] = i; nthblueat[numblue++] = i; } } dp[0][0]++; for (int i = 0; i <= numblue; i++) { for (int j = 0; j <= numred; j++) { // printf("%d %d - %lld\n", i, j, dp[i][j]); dp[i][j] %= 998244353; if (i < numblue && nthblueat[i] <= i + j) { dp[i + 1][j] += dp[i][j]; } if (j < numred && nthredat[j] <= i + j) { dp[i][j + 1] += dp[i][j]; } } } printf("%lld\n", dp[numblue][numred]); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll dp[4010][4010], n; ll nthblueat[4010], nthredat[4010], numblue, numred; char inp[4010]; int main() { scanf(" %s", inp); n = strlen(inp); for (int i = 0; i < n; i++) { if (inp[i] == '0') { nthredat[numred++] = i; nthredat[numred++] = i; } else if (inp[i] == '1') { nthredat[numred++] = i; nthblueat[numblue++] = i; } else { nthblueat[numblue++] = i; nthblueat[numblue++] = i; } } dp[0][0]++; for (int i = 0; i <= numblue; i++) { for (int j = 0; j <= numred; j++) { // printf("%d %d - %lld\n", i, j, dp[i][j]); dp[i][j] %= 998244353; if (i < numblue && nthblueat[i] <= i + j) { dp[i + 1][j] += dp[i][j]; } if (j < numred && nthredat[j] <= i + j) { dp[i][j + 1] += dp[i][j]; } } } printf("%lld\n", dp[numblue][numred]); }
replace
3
6
3
6
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; // const ull mod = 1e9 + 7; const ll mod = 998244353; #define REP(i, n) for (int i = 0; i < (int)n; ++i) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> v) { os << "(" << v.first << ", " << v.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> v) { for (int i = 0; i < (int)v.size(); i++) { if (i > 0) { os << " "; } os << v[i]; } return os; } template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) { for (int i = 0; i < (int)v.size(); i++) { if (i > 0) { os << endl; } os << v[i]; } return os; } 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; } // conversion number to bit string num2bit(ll num, ll len) { string bit = ""; REP(i, len) { bit += char('0' + (num >> i & 1)); } return bit; } ll dp[2020][2020]; int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; ll N = S.size(); dp[0][0] = 1; ll R = 0, B = 0; REP(i, 2 * N) { if (i < N) { if (S[i] == '0') R += 2; else if (S[i] == '2') B += 2; else R++, B++; } REP(j, i + 1) { ll idx = j; ll jdx = i - j; if (idx < R) dp[idx + 1][jdx] += dp[idx][jdx]; dp[idx + 1][jdx] %= mod; if (jdx < B) dp[idx][jdx + 1] += dp[idx][jdx]; dp[idx][jdx + 1] %= mod; } } ll res = 0; REP(i, 2 * N + 1) { res += dp[i][2 * N - i]; res %= mod; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; // const ull mod = 1e9 + 7; const ll mod = 998244353; #define REP(i, n) for (int i = 0; i < (int)n; ++i) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> v) { os << "(" << v.first << ", " << v.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> v) { for (int i = 0; i < (int)v.size(); i++) { if (i > 0) { os << " "; } os << v[i]; } return os; } template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) { for (int i = 0; i < (int)v.size(); i++) { if (i > 0) { os << endl; } os << v[i]; } return os; } 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; } // conversion number to bit string num2bit(ll num, ll len) { string bit = ""; REP(i, len) { bit += char('0' + (num >> i & 1)); } return bit; } ll dp[4020][4020]; int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; ll N = S.size(); dp[0][0] = 1; ll R = 0, B = 0; REP(i, 2 * N) { if (i < N) { if (S[i] == '0') R += 2; else if (S[i] == '2') B += 2; else R++, B++; } REP(j, i + 1) { ll idx = j; ll jdx = i - j; if (idx < R) dp[idx + 1][jdx] += dp[idx][jdx]; dp[idx + 1][jdx] %= mod; if (jdx < B) dp[idx][jdx + 1] += dp[idx][jdx]; dp[idx][jdx + 1] %= mod; } } ll res = 0; REP(i, 2 * N + 1) { res += dp[i][2 * N - i]; res %= mod; } cout << res << endl; return 0; }
replace
63
64
63
64
0
p03134
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll, ll> pll; typedef pair<int, int> pi; typedef pair<double, double> pd; typedef pair<double, ll> pdl; #define F first #define S second const ll E = 1e18 + 7; const ll MOD = 998244353; // 1000000007; int main() { string s; cin >> s; vector<ll> cnt0, cnt1; for (int i = 0; i < s.size(); i++) { if (s[i] == '0') { cnt0.push_back(i); cnt0.push_back(i); } else if (s[i] == '1') { cnt0.push_back(i); cnt1.push_back(i); } else { cnt1.push_back(i); cnt1.push_back(i); } } vector<vector<ll>> dp(2 * s.size() + 1, vector<ll>(2 * s.size() + 1, 0)); dp[0][0] = 1; for (int i = 0; i < 2 * s.size(); i++) { for (int t = 0; t < 2 * s.size(); t++) { if (cnt1.size() >= t + 1 && cnt1[t] <= i) { dp[i + 1][t + 1] += dp[i][t]; dp[i + 1][t + 1] %= MOD; } if (cnt0.size() >= i - t + 1 && cnt0[i - t] <= i) { dp[i + 1][t] += dp[i][t]; dp[i + 1][t] %= MOD; } } } ll sum = 0; for (int i = 0; i <= 2 * s.size(); i++) { sum += dp[2 * s.size()][i]; } cout << sum % MOD << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll, ll> pll; typedef pair<int, int> pi; typedef pair<double, double> pd; typedef pair<double, ll> pdl; #define F first #define S second const ll E = 1e18 + 7; const ll MOD = 998244353; // 1000000007; int main() { string s; cin >> s; vector<ll> cnt0, cnt1; for (int i = 0; i < s.size(); i++) { if (s[i] == '0') { cnt0.push_back(i); cnt0.push_back(i); } else if (s[i] == '1') { cnt0.push_back(i); cnt1.push_back(i); } else { cnt1.push_back(i); cnt1.push_back(i); } } vector<vector<ll>> dp(2 * s.size() + 1, vector<ll>(2 * s.size() + 1, 0)); dp[0][0] = 1; for (int i = 0; i < 2 * s.size(); i++) { for (int t = 0; t < 2 * s.size(); t++) { if (cnt1.size() >= t + 1 && cnt1[t] <= i) { dp[i + 1][t + 1] += dp[i][t]; dp[i + 1][t + 1] %= MOD; } if (cnt0.size() >= i - t + 1 && i - t >= 0 && cnt0[i - t] <= i) { dp[i + 1][t] += dp[i][t]; dp[i + 1][t] %= MOD; } } } ll sum = 0; for (int i = 0; i <= 2 * s.size(); i++) { sum += dp[2 * s.size()][i]; } cout << sum % MOD << endl; return 0; }
replace
61
62
61
62
0
p03134
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> typedef long long LL; typedef unsigned long long ULL; typedef long double LD; using std::bitset; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::map; using std::pair; using std::priority_queue; using std::queue; using std::set; using std::string; using std::stringstream; using std::vector; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef pair<ULL, ULL> puu; #ifdef DEBUG using std::cerr; #define pass cerr << "[" << __FUNCTION__ << "] : line = " << __LINE__ << endl; #define display(x) cerr << #x << " = " << x << endl; #define displaya(a, st, n) \ { \ cerr << #a << " = {"; \ for (int qwq = (st); qwq <= (n); ++qwq) \ if (qwq == (st)) \ cerr << a[qwq]; \ else \ cerr << ", " << a[qwq]; \ cerr << "}" << endl; \ } #define displayv(a) displaya(a, 0, (int)(a.size() - 1)) #include <ctime> class MyTimer { clock_t st; public: MyTimer() { cerr << std::fixed << std::setprecision(0); reset(); } ~MyTimer() { report(); } void reset() { st = clock_t(); } void report() { cerr << "Time consumed: " << (clock() - st) * 1e3 / CLOCKS_PER_SEC << "ms" << endl; } } myTimer; #else #define cerr \ if (false) \ std::cout #define pass ; #define display(x) ; #define displaya(a, st, n) ; #define displayv(a) ; class MyTimer { public: void reset() {} void report() {} } myTimer; #endif template <typename A, typename B> std::ostream &operator<<(std::ostream &cout, const pair<A, B> &x) { return cout << "(" << x.first << ", " << x.second << ")"; } template <typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) { return a > b ? a = b, true : false; } template <typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) { return a < b ? a = b, true : false; } const int maxN = 2000 + 5; const int P = 998244353; void inc(int &x, int y) { (x += y) >= P ? x -= P : x; } void dec(int &x, int y) { (x -= y) < 0 ? x += P : x; } int n; char s[maxN]; int r[maxN], b[maxN]; int f[maxN][maxN]; int main() { scanf("%s", s + 1); n = strlen(s + 1); memset(r, 0, sizeof(r)); memset(b, 0, sizeof(b)); for (int i = 1; i <= n; ++i) { if (s[i] == '0') r[i] = r[i - 1] + 2, b[i] = b[i - 1]; if (s[i] == '1') r[i] = r[i - 1] + 1, b[i] = b[i - 1] + 1; if (s[i] == '2') r[i] = r[i - 1], b[i] = b[i - 1] + 2; } memset(f, 0, sizeof(f)); f[0][0] = 1; for (int R = 0; R <= r[n]; ++R) { for (int B = 0; B <= b[n]; ++B) { // printf("f(%d, %d) = %d\n", R, B, f[R][B]); int len = std::min(R + B + 1, n); if (R < r[len]) inc(f[R + 1][B], f[R][B]); if (B < b[len]) inc(f[R][B + 1], f[R][B]); } } cout << f[r[n]][b[n]] << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> typedef long long LL; typedef unsigned long long ULL; typedef long double LD; using std::bitset; using std::cin; using std::cout; using std::endl; using std::make_pair; using std::map; using std::pair; using std::priority_queue; using std::queue; using std::set; using std::string; using std::stringstream; using std::vector; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef pair<ULL, ULL> puu; #ifdef DEBUG using std::cerr; #define pass cerr << "[" << __FUNCTION__ << "] : line = " << __LINE__ << endl; #define display(x) cerr << #x << " = " << x << endl; #define displaya(a, st, n) \ { \ cerr << #a << " = {"; \ for (int qwq = (st); qwq <= (n); ++qwq) \ if (qwq == (st)) \ cerr << a[qwq]; \ else \ cerr << ", " << a[qwq]; \ cerr << "}" << endl; \ } #define displayv(a) displaya(a, 0, (int)(a.size() - 1)) #include <ctime> class MyTimer { clock_t st; public: MyTimer() { cerr << std::fixed << std::setprecision(0); reset(); } ~MyTimer() { report(); } void reset() { st = clock_t(); } void report() { cerr << "Time consumed: " << (clock() - st) * 1e3 / CLOCKS_PER_SEC << "ms" << endl; } } myTimer; #else #define cerr \ if (false) \ std::cout #define pass ; #define display(x) ; #define displaya(a, st, n) ; #define displayv(a) ; class MyTimer { public: void reset() {} void report() {} } myTimer; #endif template <typename A, typename B> std::ostream &operator<<(std::ostream &cout, const pair<A, B> &x) { return cout << "(" << x.first << ", " << x.second << ")"; } template <typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) { return a > b ? a = b, true : false; } template <typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) { return a < b ? a = b, true : false; } const int maxN = 2000 + 5; const int P = 998244353; void inc(int &x, int y) { (x += y) >= P ? x -= P : x; } void dec(int &x, int y) { (x -= y) < 0 ? x += P : x; } int n; char s[maxN]; int r[maxN], b[maxN]; int f[maxN * 2][maxN * 2]; int main() { scanf("%s", s + 1); n = strlen(s + 1); memset(r, 0, sizeof(r)); memset(b, 0, sizeof(b)); for (int i = 1; i <= n; ++i) { if (s[i] == '0') r[i] = r[i - 1] + 2, b[i] = b[i - 1]; if (s[i] == '1') r[i] = r[i - 1] + 1, b[i] = b[i - 1] + 1; if (s[i] == '2') r[i] = r[i - 1], b[i] = b[i - 1] + 2; } memset(f, 0, sizeof(f)); f[0][0] = 1; for (int R = 0; R <= r[n]; ++R) { for (int B = 0; B <= b[n]; ++B) { // printf("f(%d, %d) = %d\n", R, B, f[R][B]); int len = std::min(R + B + 1, n); if (R < r[len]) inc(f[R + 1][B], f[R][B]); if (B < b[len]) inc(f[R][B + 1], f[R][B]); } } cout << f[r[n]][b[n]] << endl; return 0; }
replace
99
100
99
100
0
p03134
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #define ll long long using namespace std; template <class T> inline void read(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - '0' + c, c = getchar(); x *= f; } const int N = 2010, mod = 998244353; ll Pow(ll x, ll y) { ll res = 1; while (y) { if (y & 1) res = res * x % mod; x = x * x % mod, y >>= 1; } return res; } char str[N]; int sum[N][2], n; ll dp[N][N], frac[N], inv[N]; int main() { scanf("%s", str + 1); n = strlen(str + 1); for (int i = 1; i <= n; ++i) { sum[i][0] = sum[i - 1][0] + (str[i] - '0'); sum[i][1] = sum[i - 1][1] + 2 - (str[i] - '0'); } frac[0] = 1; for (int i = 1; i <= n; ++i) frac[i] = frac[i - 1] * i % mod; inv[n] = Pow(frac[n], mod - 2); for (int i = n - 1; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod; dp[0][0] = 1; for (int i = 0; i < n; ++i) for (int j = 0; j <= i; ++j) if (dp[i][j]) { if (sum[i + 1][0] >= j + 1) dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod; if (sum[i + 1][1] >= i + 1 - j) dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod; } // for(int j=0;j<=n;++j) printf("%0lld\n",dp[n][j]); ll ans = 0; for (int i = 0; i <= n; ++i) ans = (ans + dp[n][i] * inv[sum[n][0] - i] % mod * inv[sum[n][1] - (n - i)] % mod); ans = ans * frac[n] % mod; printf("%lld", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #define ll long long using namespace std; template <class T> inline void read(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - '0' + c, c = getchar(); x *= f; } const int N = 2010, mod = 998244353; ll Pow(ll x, ll y) { ll res = 1; while (y) { if (y & 1) res = res * x % mod; x = x * x % mod, y >>= 1; } return res; } char str[N]; int sum[N][2], n; ll dp[N][N], frac[N], inv[N]; int main() { scanf("%s", str + 1); n = strlen(str + 1); for (int i = 1; i <= n; ++i) { sum[i][0] = sum[i - 1][0] + (str[i] - '0'); sum[i][1] = sum[i - 1][1] + 2 - (str[i] - '0'); } frac[0] = 1; for (int i = 1; i <= n; ++i) frac[i] = frac[i - 1] * i % mod; inv[n] = Pow(frac[n], mod - 2); for (int i = n - 1; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % mod; dp[0][0] = 1; for (int i = 0; i < n; ++i) for (int j = 0; j <= i; ++j) if (dp[i][j]) { if (sum[i + 1][0] >= j + 1) dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod; if (sum[i + 1][1] >= i + 1 - j) dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod; } // for(int j=0;j<=n;++j) printf("%0lld\n",dp[n][j]); ll ans = 0; for (int i = 0; i <= n; ++i) if (sum[n][0] >= i && sum[n][1] >= (n - i)) ans = (ans + dp[n][i] * inv[sum[n][0] - i] % mod * inv[sum[n][1] - (n - i)] % mod) % mod; ans = ans * frac[n] % mod; printf("%lld", ans); return 0; }
replace
58
60
58
62
0
p03134
C++
Runtime Error
#include <bits/stdc++.h> #define N 2010 using namespace std; string st; int n, a[N], b[N], dp[N][N], mo = 998244353; int main() { cin >> st; n = st.length(); for (int i = 1; i <= n; i++) a[i] = st[i - 1] - '0' + a[i - 1], b[i] = b[i - 1] + '2' - st[i - 1]; dp[0][0] = 1; for (int i = 0; i <= a[n]; i++) for (int j = 0; j <= b[n]; j++) if (i <= a[min(n, i + j)] && j <= b[min(n, i + j)]) dp[i][j] = (dp[i][j] + (j ? dp[i][j - 1] : 0) + (i ? dp[i - 1][j] : 0)) % mo; cout << dp[a[n]][b[n]] << endl; return 0; }
#include <bits/stdc++.h> #define N 4010 using namespace std; string st; int n, a[N], b[N], dp[N][N], mo = 998244353; int main() { cin >> st; n = st.length(); for (int i = 1; i <= n; i++) a[i] = st[i - 1] - '0' + a[i - 1], b[i] = b[i - 1] + '2' - st[i - 1]; dp[0][0] = 1; for (int i = 0; i <= a[n]; i++) for (int j = 0; j <= b[n]; j++) if (i <= a[min(n, i + j)] && j <= b[min(n, i + j)]) dp[i][j] = (dp[i][j] + (j ? dp[i][j - 1] : 0) + (i ? dp[i - 1][j] : 0)) % mo; cout << dp[a[n]][b[n]] << endl; return 0; }
replace
1
2
1
2
0
p03134
C++
Time Limit Exceeded
#define DEBUG 1 /** * File : F2.cpp * Author : Kazune Takahashi * Created : 2/10/2019, 12:26:47 AM * Powered by Visual Studio Code */ #include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ; #include <chrono> // std::chrono::system_clock::time_point start_time, end_time; #include <complex> #include <functional> #include <iomanip> // << fixed << setprecision(xxx) #include <iostream> #include <map> // if (M.find(key) != M.end()) { } #include <queue> #include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725)); #include <set> #include <stack> #include <string> // to_string(nnn) // substr(m, n) // stoi(nnn) #include <tuple> #include <vector> // start = std::chrono::system_clock::now(); // double elapsed = // std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count(); #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> using namespace std; typedef long long ll; // const int dx[4] = {1, 0, -1, 0}; // const int dy[4] = {0, 1, 0, -1}; // const int C = 1e6+10; const ll MOD = 998244353; const int MAX_SIZE = 1000010; long long inv[MAX_SIZE]; long long fact[MAX_SIZE]; long long factinv[MAX_SIZE]; void init() { inv[1] = 1; for (int i = 2; i < MAX_SIZE; i++) { inv[i] = ((MOD - inv[MOD % i]) * (MOD / i)) % MOD; } fact[0] = factinv[0] = 1; for (int i = 1; i < MAX_SIZE; i++) { fact[i] = (i * fact[i - 1]) % MOD; factinv[i] = (inv[i] * factinv[i - 1]) % MOD; } } long long C(int n, int k) { if (n >= 0 && k >= 0 && n - k >= 0) { return ((fact[n] * factinv[k]) % MOD * factinv[n - k]) % MOD; } return 0; } long long power(long long x, long long n) { if (n == 0) { return 1; } else if (n % 2 == 1) { return (x * power(x, n - 1)) % MOD; } else { long long half = power(x, n / 2); return (half * half) % MOD; } } long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; } string S; int N; ll DP[2010][4010]; int R[2010]; int B[2010]; int main() { init(); cin >> S; N = S.size(); for (auto i = 0; i < 4010; i++) { DP[0][i] = 0; } DP[0][0] = 1; R[0] = B[0] = 0; for (auto i = 1; i <= N; i++) { if (S[i - 1] == '0') { R[i] = R[i - 1] + 2; B[i] = B[i - 1]; } else if (S[i - 1] == '1') { R[i] = R[i - 1] + 1; B[i] = B[i - 1] + 1; } else { R[i] = R[i - 1]; B[i] = B[i - 1] + 2; } } for (auto i = 0; i < N; i++) { #if DEBUG == 1 cerr << "R[" << i + 1 << "] = " << R[i + 1] << ", B[" << i + 1 << "] = " << B[i + 1] << endl; #endif for (auto j = 0; j <= i; j++) { if (DP[i][j] == 0) { continue; } #if DEBUG == 1 cerr << "DP[" << i << "][" << j << "] = " << DP[i][j] << endl; #endif int r = j; int b = i - r; if (R[i + 1] - r > 0) { DP[i + 1][j + 1] += DP[i][j]; DP[i + 1][j + 1] %= MOD; } if (B[i + 1] - b > 0) { DP[i + 1][j] += DP[i][j]; DP[i + 1][j] %= MOD; } } } ll ans = 0; for (auto i = 0; i <= N; i++) { if (DP[N][i] == 0) { continue; } int r = i; int b = N - i; int res_r = R[N] - r; int res_b = B[N] - b; ans += (DP[N][i] * C(res_r + res_b, res_r)) % MOD; ans %= MOD; } cout << ans << endl; }
#define DEBUG 0 /** * File : F2.cpp * Author : Kazune Takahashi * Created : 2/10/2019, 12:26:47 AM * Powered by Visual Studio Code */ #include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ; #include <chrono> // std::chrono::system_clock::time_point start_time, end_time; #include <complex> #include <functional> #include <iomanip> // << fixed << setprecision(xxx) #include <iostream> #include <map> // if (M.find(key) != M.end()) { } #include <queue> #include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725)); #include <set> #include <stack> #include <string> // to_string(nnn) // substr(m, n) // stoi(nnn) #include <tuple> #include <vector> // start = std::chrono::system_clock::now(); // double elapsed = // std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count(); #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> using namespace std; typedef long long ll; // const int dx[4] = {1, 0, -1, 0}; // const int dy[4] = {0, 1, 0, -1}; // const int C = 1e6+10; const ll MOD = 998244353; const int MAX_SIZE = 1000010; long long inv[MAX_SIZE]; long long fact[MAX_SIZE]; long long factinv[MAX_SIZE]; void init() { inv[1] = 1; for (int i = 2; i < MAX_SIZE; i++) { inv[i] = ((MOD - inv[MOD % i]) * (MOD / i)) % MOD; } fact[0] = factinv[0] = 1; for (int i = 1; i < MAX_SIZE; i++) { fact[i] = (i * fact[i - 1]) % MOD; factinv[i] = (inv[i] * factinv[i - 1]) % MOD; } } long long C(int n, int k) { if (n >= 0 && k >= 0 && n - k >= 0) { return ((fact[n] * factinv[k]) % MOD * factinv[n - k]) % MOD; } return 0; } long long power(long long x, long long n) { if (n == 0) { return 1; } else if (n % 2 == 1) { return (x * power(x, n - 1)) % MOD; } else { long long half = power(x, n / 2); return (half * half) % MOD; } } long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; } string S; int N; ll DP[2010][4010]; int R[2010]; int B[2010]; int main() { init(); cin >> S; N = S.size(); for (auto i = 0; i < 4010; i++) { DP[0][i] = 0; } DP[0][0] = 1; R[0] = B[0] = 0; for (auto i = 1; i <= N; i++) { if (S[i - 1] == '0') { R[i] = R[i - 1] + 2; B[i] = B[i - 1]; } else if (S[i - 1] == '1') { R[i] = R[i - 1] + 1; B[i] = B[i - 1] + 1; } else { R[i] = R[i - 1]; B[i] = B[i - 1] + 2; } } for (auto i = 0; i < N; i++) { #if DEBUG == 1 cerr << "R[" << i + 1 << "] = " << R[i + 1] << ", B[" << i + 1 << "] = " << B[i + 1] << endl; #endif for (auto j = 0; j <= i; j++) { if (DP[i][j] == 0) { continue; } #if DEBUG == 1 cerr << "DP[" << i << "][" << j << "] = " << DP[i][j] << endl; #endif int r = j; int b = i - r; if (R[i + 1] - r > 0) { DP[i + 1][j + 1] += DP[i][j]; DP[i + 1][j + 1] %= MOD; } if (B[i + 1] - b > 0) { DP[i + 1][j] += DP[i][j]; DP[i + 1][j] %= MOD; } } } ll ans = 0; for (auto i = 0; i <= N; i++) { if (DP[N][i] == 0) { continue; } int r = i; int b = N - i; int res_r = R[N] - r; int res_b = B[N] - b; ans += (DP[N][i] * C(res_r + res_b, res_r)) % MOD; ans %= MOD; } cout << ans << endl; }
replace
0
1
0
1
TLE
p03134
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; const ull mod = 998244353; #define REP(i, n) for (int i = 0; i < (int)n; ++i) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; template <typename T> void vprint(T &v) { REP(i, v.size()) { cout << v[i] << " "; } cout << endl; } int main() { string S; cin >> S; ll N = S.size(); vector<ll> red(N + 1, 0), blue(N + 1, 0); REP(i, N) { if (S[i] == '0') { red[i + 1] = red[i] + 2; blue[i + 1] = blue[i]; } else if (S[i] == '1') { red[i + 1] = red[i] + 1; blue[i + 1] = blue[i] + 1; } else { red[i + 1] = red[i]; blue[i + 1] = blue[i] + 2; } } ll ma = 200; ll dp[ma][ma]; REP(i, ma) REP(j, ma) dp[i][j] = 0; dp[0][0] = 1; REP(i, 2 * N) { ll ikeru = min((ll)i, N - 1); ll ikered = red[ikeru + 1]; ll ikeblue = blue[ikeru + 1]; REP(j, 2 * N) { if (ikered > j) { dp[i + 1][j + 1] += dp[i][j]; dp[i + 1][j + 1] %= mod; } if (ikeblue > i - j) { dp[i + 1][j] += dp[i][j]; dp[i + 1][j] %= mod; } } } cout << dp[2 * N][red[N]] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; const ull mod = 998244353; #define REP(i, n) for (int i = 0; i < (int)n; ++i) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; template <typename T> void vprint(T &v) { REP(i, v.size()) { cout << v[i] << " "; } cout << endl; } int main() { string S; cin >> S; ll N = S.size(); vector<ll> red(N + 1, 0), blue(N + 1, 0); REP(i, N) { if (S[i] == '0') { red[i + 1] = red[i] + 2; blue[i + 1] = blue[i]; } else if (S[i] == '1') { red[i + 1] = red[i] + 1; blue[i + 1] = blue[i] + 1; } else { red[i + 1] = red[i]; blue[i + 1] = blue[i] + 2; } } ll ma = 4040; ll dp[ma][ma]; REP(i, ma) REP(j, ma) dp[i][j] = 0; dp[0][0] = 1; REP(i, 2 * N) { ll ikeru = min((ll)i, N - 1); ll ikered = red[ikeru + 1]; ll ikeblue = blue[ikeru + 1]; REP(j, 2 * N) { if (ikered > j) { dp[i + 1][j + 1] += dp[i][j]; dp[i + 1][j + 1] %= mod; } if (ikeblue > i - j) { dp[i + 1][j] += dp[i][j]; dp[i + 1][j] %= mod; } } } cout << dp[2 * N][red[N]] << endl; return 0; }
replace
39
40
39
40
0
p03134
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i)) #define rep(i, n) FOR(i, 0, n) #define all(v) begin(v), end(v) #define debug(x) std::cerr << #x << ": " << x << "\n" #define debug2(x, y) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\n" #define debug3(x, y, z) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z \ << ": " << z << "\n" typedef long long ll; typedef std::vector<int> vi; typedef std::vector<vi> vvi; typedef std::vector<ll> vll; typedef std::vector<vll> vvll; template <typename T> using vvec = std::vector<std::vector<T>>; template <typename T> auto make_v(size_t sz) { return std::vector<T>(sz); } template <typename T, typename... Ts> auto make_v(size_t sz, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(sz, make_v<T>(ts...)); } template <typename T> void fill_v(T &var, const T &x) { var = x; } template <typename V, typename T> void fill_v(V &v, const T &x) { for (auto &&w : v) { fill_v(w, x); } } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<std::vector<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<std::deque<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::set<T> &v) { s << "\n"; for (auto &&elm : v) { s << elm << "\t"; } s << "\n"; return s; } inline void scan(int &a) { scanf("%d", &a); } inline void scan(ll &a) { scanf("%lld", &a); } inline void scan(char &a) { scanf(" %c", &a); } inline void scan(double &a) { scanf("%lf", &a); } template <typename T> inline void scan(std::vector<T> &v) { for (auto &&sv : v) { scan(sv); } } template <typename First, typename... Args> inline void scan(First &f, Args &...args) { scan(f); scan(args...); } inline void scan(std::string &s) { char BUF[3000000]; scanf(" %s", BUF); s = std::string(BUF); } inline void print(int a) { printf("%d\n", a); } inline void print(ll a) { printf("%lld\n", a); } inline void print(double a) { printf("%.12f\n", a); } inline void print(std::string s) { std::cout << s << "\n"; } using namespace std; int mod = 998244353; int main() { string s; scan(s); int n = s.length(); vi red(n + 1, 0); vi blu(n + 1, 0); rep(i, n) { red[i + 1] = red[i]; blu[i + 1] = blu[i]; if (s[i] == '0') { red[i + 1] += 2; } else if (s[i] == '1') { red[i + 1] += 1; blu[i + 1] += 1; } else { blu[i + 1] += 2; } } int nr = red[n]; int nb = blu[n]; vvll dp(nr + 2, vll(nb + 2, 0)); dp[0][0] = 1; rep(i, nr + 1) { rep(j, nb + 1) { int cr = red[min(n, i + j + 1)] - i; int cb = blu[min(n, i + j + 1)] - j; if (cr > 0) { dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod; } if (cb > 0) { dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % mod; } } } debug(dp); print(dp[nr][nb]); return 0; }
#include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i)) #define rep(i, n) FOR(i, 0, n) #define all(v) begin(v), end(v) #define debug(x) std::cerr << #x << ": " << x << "\n" #define debug2(x, y) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\n" #define debug3(x, y, z) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z \ << ": " << z << "\n" typedef long long ll; typedef std::vector<int> vi; typedef std::vector<vi> vvi; typedef std::vector<ll> vll; typedef std::vector<vll> vvll; template <typename T> using vvec = std::vector<std::vector<T>>; template <typename T> auto make_v(size_t sz) { return std::vector<T>(sz); } template <typename T, typename... Ts> auto make_v(size_t sz, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(sz, make_v<T>(ts...)); } template <typename T> void fill_v(T &var, const T &x) { var = x; } template <typename V, typename T> void fill_v(V &v, const T &x) { for (auto &&w : v) { fill_v(w, x); } } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<std::vector<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<std::deque<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::set<T> &v) { s << "\n"; for (auto &&elm : v) { s << elm << "\t"; } s << "\n"; return s; } inline void scan(int &a) { scanf("%d", &a); } inline void scan(ll &a) { scanf("%lld", &a); } inline void scan(char &a) { scanf(" %c", &a); } inline void scan(double &a) { scanf("%lf", &a); } template <typename T> inline void scan(std::vector<T> &v) { for (auto &&sv : v) { scan(sv); } } template <typename First, typename... Args> inline void scan(First &f, Args &...args) { scan(f); scan(args...); } inline void scan(std::string &s) { char BUF[3000000]; scanf(" %s", BUF); s = std::string(BUF); } inline void print(int a) { printf("%d\n", a); } inline void print(ll a) { printf("%lld\n", a); } inline void print(double a) { printf("%.12f\n", a); } inline void print(std::string s) { std::cout << s << "\n"; } using namespace std; int mod = 998244353; int main() { string s; scan(s); int n = s.length(); vi red(n + 1, 0); vi blu(n + 1, 0); rep(i, n) { red[i + 1] = red[i]; blu[i + 1] = blu[i]; if (s[i] == '0') { red[i + 1] += 2; } else if (s[i] == '1') { red[i + 1] += 1; blu[i + 1] += 1; } else { blu[i + 1] += 2; } } int nr = red[n]; int nb = blu[n]; vvll dp(nr + 2, vll(nb + 2, 0)); dp[0][0] = 1; rep(i, nr + 1) { rep(j, nb + 1) { int cr = red[min(n, i + j + 1)] - i; int cb = blu[min(n, i + j + 1)] - j; if (cr > 0) { dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod; } if (cb > 0) { dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % mod; } } } print(dp[nr][nb]); return 0; }
delete
164
165
164
164
TLE
p03134
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define rep(i, n) for (int i = 0; i < (n); i++) #define reps(i, n) for (int i = 1; i <= (n); i++) #define all(x) (x).begin(), (x).end() #define uniq(x) (x).erase(unique(all(x)), (x).end()) #define bit(n) (1LL << (n)) #define dump(x) cerr << #x " = " << (x) << endl #define next asdnext #define prev asdprev using vint = vector<int>; using vvint = vector<vint>; using pint = pair<int, int>; using vpint = vector<pint>; template <typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; constexpr double pi = 3.1415926535897932384626433832795028; constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int gcd(int a, int b) { while (b) { swap(a %= b, b); } return a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } template <typename T1, typename T2> bool chmax(T1 &a, const T2 &b) { if (a < b) { a = b; return true; } return false; } template <typename T1, typename T2> bool chmin(T1 &a, const T2 &b) { if (b < a) { a = b; return true; } return false; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) { os << "(" << rhs.first << ", " << rhs.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) { os << "{"; for (auto itr = rhs.begin(); itr != rhs.end(); itr++) { os << *itr << (next(itr) != rhs.end() ? ", " : ""); } os << "}"; return os; } struct setup { static constexpr int PREC = 20; setup() { cout << fixed << setprecision(PREC); cerr << fixed << setprecision(PREC); }; } setup; template <int MOD = 1000000007> struct mod_int { int val; mod_int(long long val_ = 0) : val(val_ >= 0 ? val_ % MOD : (MOD - (-val_) % MOD) % MOD) {} bool operator==(const mod_int &rhs) const { return val == rhs.val; } bool operator!=(const mod_int &rhs) const { return std::rel_ops::operator!=(*this, rhs); } mod_int &operator+=(const mod_int &rhs) { if ((val += rhs.val) >= MOD) { val -= MOD; } return *this; } mod_int &operator-=(const mod_int &rhs) { if ((val += MOD - rhs.val) >= MOD) { val -= MOD; } return *this; } mod_int &operator*=(const mod_int &rhs) { val = (int)((long long)val * rhs.val % MOD); return *this; } mod_int &operator/=(const mod_int &rhs) { return *this *= rhs.inv(); } mod_int operator+() const { return *this; } mod_int operator-() const { return mod_int(-val); } mod_int operator++() { return *this += 1; } mod_int operator--() { return *this -= 1; } mod_int operator++(signed) { const mod_int ret(*this); ++*this; return ret; } mod_int operator--(signed) { const mod_int ret(*this); --*this; return ret; } mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; } mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; } mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; } mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; } mod_int inv() const { int a = MOD, b = val, u = 0, v = 1; while (b > 0) { int t = a / b; std::swap(a -= t * b, b); std::swap(u -= t * v, v); } return mod_int(u); } mod_int pow(long long n) const { if (n < 0) { return pow(-n).inv(); } mod_int ret = 1, mul = *this; while (n > 0) { if (n & 1) { ret *= mul; } mul *= mul; n >>= 1; } return ret; } friend std::istream &operator>>(std::istream &is, mod_int &rhs) { long long v; is >> v; rhs = v; return is; } friend std::ostream &operator<<(std::ostream &os, const mod_int &rhs) { return os << rhs.val; } struct combination { std::vector<mod_int> fact{1, 1}, f_inv{1, 1}, inv{0, 1}; void calc(int n) { while (fact.size() <= n) { int i = fact.size(); fact.push_back(fact[i - 1] * i); inv.push_back(-inv[MOD % i] * (MOD / i)); f_inv.push_back(f_inv[i - 1] * inv[i]); } } mod_int P(int n, int r) { return r < 0 || n < r ? 0 : (calc(n), fact[n] * f_inv[n - r]); } mod_int C(int n, int r) { return r < 0 || n < r ? 0 : (calc(n), fact[n] * f_inv[r] * f_inv[n - r]); } mod_int H(int n, int r) { return C(n + r - 1, r); } }; }; string S; int N; using mint = mod_int<998244353>; mint dp[2200][2200]; signed main() { cin >> S; N = S.length(); vint rlim(2 * N), blim(2 * N); rep(i, N) { if (S[i] == '0') { rlim[i + 1] = rlim[i] + 2, blim[i + 1] = blim[i]; } if (S[i] == '1') { rlim[i + 1] = rlim[i] + 1, blim[i + 1] = blim[i] + 1; } if (S[i] == '2') { rlim[i + 1] = rlim[i], blim[i + 1] = blim[i] + 2; } } rep(i, N) { rlim[i + N + 1] = rlim[i + N], blim[i + N + 1] = blim[i + N]; } dp[0][0] = 1; reps(i, 2 * N) { for (int j = 0; j <= 2 * N; j++) { if (j > rlim[i] || i - j > blim[i]) { continue; } dp[i][j] = dp[i - 1][j]; if (j != 0) { dp[i][j] += dp[i - 1][j - 1]; } } } cout << dp[2 * N][rlim[2 * N]] << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define rep(i, n) for (int i = 0; i < (n); i++) #define reps(i, n) for (int i = 1; i <= (n); i++) #define all(x) (x).begin(), (x).end() #define uniq(x) (x).erase(unique(all(x)), (x).end()) #define bit(n) (1LL << (n)) #define dump(x) cerr << #x " = " << (x) << endl #define next asdnext #define prev asdprev using vint = vector<int>; using vvint = vector<vint>; using pint = pair<int, int>; using vpint = vector<pint>; template <typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; constexpr double pi = 3.1415926535897932384626433832795028; constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int gcd(int a, int b) { while (b) { swap(a %= b, b); } return a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } template <typename T1, typename T2> bool chmax(T1 &a, const T2 &b) { if (a < b) { a = b; return true; } return false; } template <typename T1, typename T2> bool chmin(T1 &a, const T2 &b) { if (b < a) { a = b; return true; } return false; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) { os << "(" << rhs.first << ", " << rhs.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) { os << "{"; for (auto itr = rhs.begin(); itr != rhs.end(); itr++) { os << *itr << (next(itr) != rhs.end() ? ", " : ""); } os << "}"; return os; } struct setup { static constexpr int PREC = 20; setup() { cout << fixed << setprecision(PREC); cerr << fixed << setprecision(PREC); }; } setup; template <int MOD = 1000000007> struct mod_int { int val; mod_int(long long val_ = 0) : val(val_ >= 0 ? val_ % MOD : (MOD - (-val_) % MOD) % MOD) {} bool operator==(const mod_int &rhs) const { return val == rhs.val; } bool operator!=(const mod_int &rhs) const { return std::rel_ops::operator!=(*this, rhs); } mod_int &operator+=(const mod_int &rhs) { if ((val += rhs.val) >= MOD) { val -= MOD; } return *this; } mod_int &operator-=(const mod_int &rhs) { if ((val += MOD - rhs.val) >= MOD) { val -= MOD; } return *this; } mod_int &operator*=(const mod_int &rhs) { val = (int)((long long)val * rhs.val % MOD); return *this; } mod_int &operator/=(const mod_int &rhs) { return *this *= rhs.inv(); } mod_int operator+() const { return *this; } mod_int operator-() const { return mod_int(-val); } mod_int operator++() { return *this += 1; } mod_int operator--() { return *this -= 1; } mod_int operator++(signed) { const mod_int ret(*this); ++*this; return ret; } mod_int operator--(signed) { const mod_int ret(*this); --*this; return ret; } mod_int operator+(const mod_int &rhs) const { return mod_int(*this) += rhs; } mod_int operator-(const mod_int &rhs) const { return mod_int(*this) -= rhs; } mod_int operator*(const mod_int &rhs) const { return mod_int(*this) *= rhs; } mod_int operator/(const mod_int &rhs) const { return mod_int(*this) /= rhs; } mod_int inv() const { int a = MOD, b = val, u = 0, v = 1; while (b > 0) { int t = a / b; std::swap(a -= t * b, b); std::swap(u -= t * v, v); } return mod_int(u); } mod_int pow(long long n) const { if (n < 0) { return pow(-n).inv(); } mod_int ret = 1, mul = *this; while (n > 0) { if (n & 1) { ret *= mul; } mul *= mul; n >>= 1; } return ret; } friend std::istream &operator>>(std::istream &is, mod_int &rhs) { long long v; is >> v; rhs = v; return is; } friend std::ostream &operator<<(std::ostream &os, const mod_int &rhs) { return os << rhs.val; } struct combination { std::vector<mod_int> fact{1, 1}, f_inv{1, 1}, inv{0, 1}; void calc(int n) { while (fact.size() <= n) { int i = fact.size(); fact.push_back(fact[i - 1] * i); inv.push_back(-inv[MOD % i] * (MOD / i)); f_inv.push_back(f_inv[i - 1] * inv[i]); } } mod_int P(int n, int r) { return r < 0 || n < r ? 0 : (calc(n), fact[n] * f_inv[n - r]); } mod_int C(int n, int r) { return r < 0 || n < r ? 0 : (calc(n), fact[n] * f_inv[r] * f_inv[n - r]); } mod_int H(int n, int r) { return C(n + r - 1, r); } }; }; string S; int N; using mint = mod_int<998244353>; mint dp[4400][4400]; signed main() { cin >> S; N = S.length(); vint rlim(2 * N), blim(2 * N); rep(i, N) { if (S[i] == '0') { rlim[i + 1] = rlim[i] + 2, blim[i + 1] = blim[i]; } if (S[i] == '1') { rlim[i + 1] = rlim[i] + 1, blim[i + 1] = blim[i] + 1; } if (S[i] == '2') { rlim[i + 1] = rlim[i], blim[i + 1] = blim[i] + 2; } } rep(i, N) { rlim[i + N + 1] = rlim[i + N], blim[i + N + 1] = blim[i + N]; } dp[0][0] = 1; reps(i, 2 * N) { for (int j = 0; j <= 2 * N; j++) { if (j > rlim[i] || i - j > blim[i]) { continue; } dp[i][j] = dp[i - 1][j]; if (j != 0) { dp[i][j] += dp[i - 1][j - 1]; } } } cout << dp[2 * N][rlim[2 * N]] << endl; }
replace
162
163
162
163
0
p03135
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { int T, X; cin >> T, X; cout << T / X << endl; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { double T = 0, X = 0; cin >> T >> X; cout << T / X << endl; }
replace
5
7
5
7
0
p03135
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a, b; float c; cin >> a, b; c = float(a / b); cout << c << endl; }
#include <iostream> using namespace std; int main() { int a, b; float c; cin >> a >> b; c = float(a) / b; cout << c << endl; }
replace
6
8
6
8
0
p03135
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ld t, x; cin >> t >> x; cout << setprecision(30) << (t / x) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ld t, x; cin >> t >> x; cout << setprecision(30) << (t / x) << endl; }
delete
9
14
9
9
0
p03135
Python
Runtime Error
num = int(input().split()) ans = num[0] / num[1] print(ans)
num = list(map(int, input().split())) ans = num[0] / num[1] print(ans)
replace
0
1
0
1
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03135/Python/s676135149.py", line 1, in <module> num = int(input().split()) TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
p03135
C++
Runtime Error
#include <iostream> #include <stdio.h> int main() { int T, X; scanf("%d %d", T, X); std::cout << T / X << std::endl; }
#include <iostream> #include <stdio.h> int main() { float T, X; scanf("%f %f", &T, &X); std::cout << T / X << std::endl; }
replace
4
6
4
6
-11
p03135
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, sum = 0; cin >> N; vector<int> L(N); for (int i = 1; i <= N; i++) { cin >> L.at(i); sum += L.at(i); } sort(L.begin(), L.end()); if (2 * L.at(N) - sum < 0) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { double t, x; cin >> t >> x; cout << t / x << endl; }
replace
4
20
4
7
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 8) >= this->size() (which is 8)
p03135
C++
Runtime Error
/* Don't try to hack it :| _/﹋\_ (҂`_´) <,︻╦╤─҉- - - - - - - - - - - - - - - _/﹋\_ */ //@ROMENE7 #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define all(c) c.begin(), c.end() #define ulli unsigned long long int #define lli long long int #define llv vector<ll> #define llc vector<char> #define lls vector<string> #define llb vector<bool> #define mp make_pair #define endl "\n" #define degb cout << "HI" << endl; #define ins insert #define foo(i, n) for (ll i = 0; i < n; i++) #define foa(i, a) for (auto i = a.begin(); i != a.end(); i++) #define foe(i, a, b) for (ll i = a; i <= b; i++) #define INF 2147483647 #define siz size #define len length #define sp setprecision(16) int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); double m, n; cin >> m >> n; cout << sp << m / n * 1.0; cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
/* Don't try to hack it :| _/﹋\_ (҂`_´) <,︻╦╤─҉- - - - - - - - - - - - - - - _/﹋\_ */ //@ROMENE7 #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define F first #define S second #define all(c) c.begin(), c.end() #define ulli unsigned long long int #define lli long long int #define llv vector<ll> #define llc vector<char> #define lls vector<string> #define llb vector<bool> #define mp make_pair #define endl "\n" #define degb cout << "HI" << endl; #define ins insert #define foo(i, n) for (ll i = 0; i < n; i++) #define foa(i, a) for (auto i = a.begin(); i != a.end(); i++) #define foe(i, a, b) for (ll i = a; i <= b; i++) #define INF 2147483647 #define siz size #define len length #define sp setprecision(16) int main() { /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); double m, n; cin >> m >> n; cout << sp << m / n * 1.0; cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
replace
35
39
35
39
0
Time : 32.579ms
p03135
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; typedef tree<pair<int, int>, // change type null_type, less<pair<int, int>>, // change type rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef long long ll; #define rep(i, start, end) for (int i = start; i < end; ++i) #define sz(x) (int)(x).size() #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define clr(d, v) memset(d, v, sizeof(d)) #define pii pair<int, int> const double PI = 3.14159265358979323846; const double eps = (1e-8); int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("facebook.txt", "w", stdout); #endif int x, t; cin >> t >> x; cout << fixed << setprecision(6) << 1.0 * t / x; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; typedef tree<pair<int, int>, // change type null_type, less<pair<int, int>>, // change type rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef long long ll; #define rep(i, start, end) for (int i = start; i < end; ++i) #define sz(x) (int)(x).size() #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define clr(d, v) memset(d, v, sizeof(d)) #define pii pair<int, int> const double PI = 3.14159265358979323846; const double eps = (1e-8); int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("facebook.txt", "w", stdout); #endif int x, t; cin >> t >> x; cout << fixed << setprecision(6) << 1.0 * t / x; return 0; }
replace
28
29
28
29
0
p03135
C++
Time Limit Exceeded
#include <cstdio> typedef long long ll; #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) inline ll read() { char c = getchar(); ll ret = 0; while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar(); return ret; } int main() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif ll T = read(), X = read(); printf("%.8f\n", T / (double)X); return 0; }
#include <cstdio> typedef long long ll; #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) inline ll read() { char c = getchar(); ll ret = 0; while (c < '0' || c > '9') c = getchar(); while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar(); return ret; } int main() { ll T = read(), X = read(); printf("%.8f\n", T / (double)X); return 0; }
delete
17
21
17
17
TLE
p03135
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long N, M; cin >> N >> M; long long X[M]; for (int i = 0; i < M; i++) { cin >> X[i]; } if (M == 1) { cout << 0 << endl; return 0; } sort(X, X + M); pair<long long, long long> kan[M]; kan[0].first = 0; kan[0].second = 0; for (int i = 1; i < M; i++) { kan[i].first = X[i] - X[i - 1]; kan[i].second = i; } sort(kan, kan + M); vector<long long> mp; mp.push_back(X[0]); for (int i = 1; i < N; i++) { long long a = X[kan[M - 1 - i + 1].second]; mp.push_back(a); } pair<long long, long long> route[M]; for (int i = 0; i < M; i++) { route[i].first = X[i]; route[i].second = 0; auto itr = find(mp.begin(), mp.end(), X[i]); if (itr != mp.end()) route[i].second = 1; } long long ans = 0; long long now = route[0].first; for (int i = 1; i < M; i++) { if (route[i].second != 0) { ans += route[i - 1].first - now; now = route[i].first; } if (i == M - 1) { if (now != X[M - 1]) ans += X[M - 1] - now; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { double a, b; cin >> a >> b; cout << a / b << setprecision(6) << endl; }
replace
4
52
4
7
-11
p03135
C++
Runtime Error
#include <bits/stdc++.h> // #include <ext/numeric> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update #define oo 0x3f3f3f3f #define OO 0x3f3f3f3f3f3f3f3f #define popcount(n) __builtin_popcount(n) #define popcountll(n) __builtin_popcountll(n) using namespace std; // using namespace __gnu_cxx; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef pair<int, int> ii; typedef pair<long long, pair<int, int>> iii; typedef pair<ii, ii> iiii; const double PI = acos(-1.0), EPS = 1e-6; const int N = 200005, M = 100005, mod = 998244353, mxLog = 20; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); // freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(6), cout << fixed; int t, x; cin >> t >> x; cout << 1.0 * t / x << '\n'; return 0; }
#include <bits/stdc++.h> // #include <ext/numeric> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update #define oo 0x3f3f3f3f #define OO 0x3f3f3f3f3f3f3f3f #define popcount(n) __builtin_popcount(n) #define popcountll(n) __builtin_popcountll(n) using namespace std; // using namespace __gnu_cxx; using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef pair<int, int> ii; typedef pair<long long, pair<int, int>> iii; typedef pair<ii, ii> iiii; const double PI = acos(-1.0), EPS = 1e-6; const int N = 200005, M = 100005, mod = 998244353, mxLog = 20; int main() { #ifndef ONLINE_JUDGE // freopen("input.txt", "rt", stdin); // freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(6), cout << fixed; int t, x; cin >> t >> x; cout << 1.0 * t / x << '\n'; return 0; }
replace
25
26
25
26
0
p03135
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <set> #include <string> #include <vector> using namespace std; using ll = long long; #define endl "\n" #define pb push_back int main() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif double t, x; cin >> t >> x; cout << fixed << setprecision(3) << (t / x) << endl; }
#include <algorithm> #include <cmath> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <set> #include <string> #include <vector> using namespace std; using ll = long long; #define endl "\n" #define pb push_back int main() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif double t, x; cin >> t >> x; cout << fixed << setprecision(3) << (t / x) << endl; }
replace
23
24
23
24
0
p03135
C++
Runtime Error
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") #include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> using namespace std; #define ll long long #define pb push_back #define pii pair<int, int> #define vi vector<int> #define vii vector<pii> #define mi map<int, int> #define mii map<pii, int> #define all(a) (a).begin(), (a).end() #define FF first #define SS second #define sz(x) (int)x.size() #define endl '\n' #define hell 1000000007 #define rep(i, a, b) for (int i = a; i < b; i++) // if (str.find(str2) != string::npos) template <typename T> T pow(T base, T exp, T modulus) { base %= modulus; T result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % modulus; base = (base * base) % modulus; exp >>= 1; } return result; } int solve() { double a, b; cin >> a >> b; cout << a / b; return 0; } int main() { int t = 1; ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif clock_t time_req; // Without using pow function time_req = clock(); // cin>>t; bool flag = true; while (t--) { solve(); } time_req = clock() - time_req; // cout << "Processor time taken is " // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") #include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> using namespace std; #define ll long long #define pb push_back #define pii pair<int, int> #define vi vector<int> #define vii vector<pii> #define mi map<int, int> #define mii map<pii, int> #define all(a) (a).begin(), (a).end() #define FF first #define SS second #define sz(x) (int)x.size() #define endl '\n' #define hell 1000000007 #define rep(i, a, b) for (int i = a; i < b; i++) // if (str.find(str2) != string::npos) template <typename T> T pow(T base, T exp, T modulus) { base %= modulus; T result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % modulus; base = (base * base) % modulus; exp >>= 1; } return result; } int solve() { double a, b; cin >> a >> b; cout << a / b; return 0; } int main() { int t = 1; ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); clock_t time_req; // Without using pow function time_req = clock(); // cin>>t; bool flag = true; while (t--) { solve(); } time_req = clock() - time_req; // cout << "Processor time taken is " // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl; return 0; }
delete
82
87
82
82
0
p03135
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int main() { int t, x; cin >> t, x; double ans = t / x; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int main() { int t, x; cin >> t >> x; double ans = double(t) / x; cout << fixed << setprecision(10) << ans << endl; return 0; }
replace
7
10
7
10
0
p03135
C++
Runtime Error
/** * Name: Ajay Subhash Jadhav * Institute: International Institute of Technology Hyderabad */ #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 vii vector<ppi> #define vll vector<LL> #define mp make_pair using namespace std; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void inputread() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { fastio(); inputread(); double T, X; cin >> T >> X; printf("%.10f", (T / X)); return 0; }
/** * Name: Ajay Subhash Jadhav * Institute: International Institute of Technology Hyderabad */ #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 vii vector<ppi> #define vll vector<LL> #define mp make_pair using namespace std; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void inputread() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { fastio(); double T, X; cin >> T >> X; printf("%.10f", (T / X)); return 0; }
delete
44
45
44
44
0
p03135
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int T, X; cin >> T, X; cout << T / X << endl; }
#include <bits/stdc++.h> using namespace std; int main() { double T, X; cin >> T >> X; cout << T / X << endl; }
replace
4
6
4
6
0
p03135
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #include <unordered_map> #define endl "\n" #define all(v) v.begin(), v.end() #define allr(s) s.rbegin(), s.rend() #define RT(s) return cout << s, 0 #define watch(x) cout << (#x) << " = " << x << endl #define sz(s) (int)(s.size()) #define PI acos(-1) #define EPS 1e-3 using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> row; typedef vector<row> matrix; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; void file() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #else // freopen("street.in", "r", stdin); // freopen("out.txt", "w", stdout); #endif } void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } int main() { file(); fast(); int T, x; cin >> T >> x; cout << setprecision(10) << T / (double)x << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #include <unordered_map> #define endl "\n" #define all(v) v.begin(), v.end() #define allr(s) s.rbegin(), s.rend() #define RT(s) return cout << s, 0 #define watch(x) cout << (#x) << " = " << x << endl #define sz(s) (int)(s.size()) #define PI acos(-1) #define EPS 1e-3 using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> row; typedef vector<row> matrix; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; void file() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #else // freopen("street.in", "r", stdin); // freopen("out.txt", "w", stdout); #endif } void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); } int main() { // file(); fast(); int T, x; cin >> T >> x; cout << setprecision(10) << T / (double)x << endl; return 0; }
replace
37
38
37
38
0
p03136
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int N; cin >> N; ; int L[N]; REP(i, N) { cin >> L[N]; } sort(L, L + sizeof(L)); int alpha = 0; REP(i, N - 1) { alpha += L[i]; } if (L[N - 1] > alpha) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int N; cin >> N; int L[N + 10]; REP(i, N) { cin >> L[i]; } sort(L, L + N); int tmp = 0; REP(i, N - 1) { tmp += L[i]; } if (L[N - 1] < tmp) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
9
18
9
15
-11
p03136
Python
Runtime Error
def read(): N = int(input().strip()) L = map(int, input().strip().split()) return N, L def solve(N, L): L = sorted(L) return "Yes" if L[-1] < sum(L[:-1]) else "No" if __name__ == "__main__": inputs = read() print("%f" % solve(*inputs))
def read(): N = int(input().strip()) L = map(int, input().strip().split()) return N, L def solve(N, L): L = sorted(L) return "Yes" if L[-1] < sum(L[:-1]) else "No" if __name__ == "__main__": inputs = read() print("%s" % solve(*inputs))
replace
13
14
13
14
TypeError: must be real number, not str
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03136/Python/s311210486.py", line 14, in <module> print("%f" % solve(*inputs)) TypeError: must be real number, not str
p03136
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define pb push_back #define f(i, n) for (i = 0; i < n; i++) #define F(i, a, b) for (i = a; a <= b; i++) #define arr(a, n) \ for (i = 0; i < n; i++) \ cin >> a[i]; #define fi first #define se second #define mp make_pair #define mod 1000000007 #define YES cout << "YES" << endl; #define Yes cout << "Yes" << endl; #define NO cout << "NO" << endl; #define No cout << "No" << endl; #define yes cout << "yes" << endl; #define no cout << "no" << endl; #define vi vector<ll> #define ed end() #define bg begin() #define sz size() #define ln length() #define s() sort(a, a + n); #define sr() sort(a, a + n, greater<ll>()); #define v() sort(v.begin(), v.end()); #define vr() sort(v.begin(), v.end(), greater<ll>()); #define mod 1000000007 #define fast() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) ll gcd(ll a, ll b) { if (!b) return a; return gcd(b, a % b); } ll power(ll x, ll y, ll p) { ll res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int 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 fast(); // ll t;cin>>t;while(t--) { ll n, s = 0; cin >> n; ll a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sr() for (int i = 1; i < n; i++) { s += a[i]; } if (a[0] < s) Yes else No } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" #define pb push_back #define f(i, n) for (i = 0; i < n; i++) #define F(i, a, b) for (i = a; a <= b; i++) #define arr(a, n) \ for (i = 0; i < n; i++) \ cin >> a[i]; #define fi first #define se second #define mp make_pair #define mod 1000000007 #define YES cout << "YES" << endl; #define Yes cout << "Yes" << endl; #define NO cout << "NO" << endl; #define No cout << "No" << endl; #define yes cout << "yes" << endl; #define no cout << "no" << endl; #define vi vector<ll> #define ed end() #define bg begin() #define sz size() #define ln length() #define s() sort(a, a + n); #define sr() sort(a, a + n, greater<ll>()); #define v() sort(v.begin(), v.end()); #define vr() sort(v.begin(), v.end(), greater<ll>()); #define mod 1000000007 #define fast() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) ll gcd(ll a, ll b) { if (!b) return a; return gcd(b, a % b); } ll power(ll x, ll y, ll p) { ll res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int 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*/ fast(); // ll t;cin>>t;while(t--) { ll n, s = 0; cin >> n; ll a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sr() for (int i = 1; i < n; i++) { s += a[i]; } if (a[0] < s) Yes else No } return 0; }
replace
51
57
51
57
-11
p03136
C++
Runtime Error
#include <bits/stdc++.h> #include <cmath> #include <stdio.h> using namespace std; int main() { int N; vector<int> L(N); for (int i = 0; i < N; i++) { cin >> L.at(i); } sort(L.begin(), L.end()); long ans = 0; for (int i = 0; i < N - 1; i++) { ans += L.at(i); } if (L.at(N - 1) < ans) cout << "Yes"; else cout << "No"; }
#include <bits/stdc++.h> #include <cmath> #include <stdio.h> using namespace std; int main() { int N; cin >> N; vector<int> L(N); for (int i = 0; i < N; i++) { cin >> L.at(i); } sort(L.begin(), L.end()); long ans = 0; for (int i = 0; i < N - 1; i++) { ans += L.at(i); } if (L.at(N - 1) < ans) cout << "Yes"; else cout << "No"; }
insert
8
8
8
9
0
p03136
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) int main() { int N; vector<int> L(N); rep(i, N) cin >> L.at(i); sort(L.begin(), L.end()); int sum = 0; rep(i, N - 1) sum += L.at(i); if (sum > L.at(N - 1)) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) int main() { int N; cin >> N; vector<int> L(N); rep(i, N) cin >> L.at(i); sort(L.begin(), L.end()); int sum = 0; rep(i, N - 1) sum += L.at(i); if (sum > L.at(N - 1)) cout << "Yes" << endl; else cout << "No" << endl; }
insert
6
6
6
7
0
p03136
C++
Runtime Error
#include <bits/stdc++.h> #include <cmath> #include <cstdlib> using namespace std; int main() { int N; vector<int> S; for (int i = 0; i < N; i++) { cin >> S.at(i); } sort(S.begin(), S.end()); int A = 0; for (int i = 0; i < N - 1; i++) { A += S.at(i); } if (A > S.at(N - 1)) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> #include <cmath> #include <cstdlib> using namespace std; int main() { int N; cin >> N; vector<int> S(N); for (int i = 0; i < N; i++) { cin >> S.at(i); } sort(S.begin(), S.end()); int A = 0; for (int i = 0; i < N - 1; i++) { A += S.at(i); } if (A > S.at(N - 1)) cout << "Yes" << endl; else cout << "No" << endl; }
replace
6
7
6
8
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)