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
p02959
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; #define MIN(X, Y) (((X) > (Y)) ? (Y) : (X)) int main() { int N, num = 0; vector<int> A; cin >> N; for (int i = 0; i < N + 1; i++) cin >> A[i]; for (int i = 0; i < N; i++) { int b1; cin >> b1; int left = MIN(A[i], b1); num += left; b1 -= left; int right = MIN(A[i + 1], b1); num += right; A[i + 1] -= right; } cout << num << endl; return 0; }
#include <iostream> #include <vector> using namespace std; #define MIN(X, Y) (((X) > (Y)) ? (Y) : (X)) int main() { int N; long long num = 0; int A[100001]; cin >> N; for (int i = 0; i < N + 1; i++) cin >> A[i]; for (int i = 0; i < N; i++) { int b1; cin >> b1; int left = MIN(A[i], b1); num += left; b1 -= left; int right = MIN(A[i + 1], b1); num += right; A[i + 1] -= right; } cout << num << endl; return 0; }
replace
7
9
7
10
-11
p02959
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; typedef vector<int> vi; #define rep(i, n) for (int i = 0; i < n; i++) int main(void) { int N; cin >> N; vi A(N), B(N - 1); rep(i, N + 1) { cin >> A[i]; } rep(i, N) { cin >> B[i]; } long count = 0; rep(i, N) { // 正面撃破 // モンスターの方が多い場合 if (A[i] >= B[i]) { count += B[i]; A[i] -= B[i]; B[i] = 0; continue; } // 勇者の方が多い場合 else if (A[i] < B[i]) { count += A[i]; B[i] -= A[i]; A[i] = 0; } // 右隣撃破 // モンスターの方が多い場合 if (A[i + 1] >= B[i]) { count += B[i]; A[i + 1] -= B[i]; B[i] = 0; continue; } // 勇者の方が多い場合 else if (A[i] < B[i]) { count += A[i + 1]; B[i] -= A[i + 1]; A[i + 1] = 0; } } cout << count << endl; return 0; }
#include <iostream> #include <vector> using namespace std; typedef vector<int> vi; #define rep(i, n) for (int i = 0; i < n; i++) int main(void) { int N; cin >> N; vi A(N + 1), B(N); rep(i, N + 1) { cin >> A[i]; } rep(i, N) { cin >> B[i]; } long count = 0; rep(i, N) { // 正面撃破 // モンスターの方が多い場合 if (A[i] >= B[i]) { count += B[i]; A[i] -= B[i]; B[i] = 0; continue; } // 勇者の方が多い場合 else if (A[i] < B[i]) { count += A[i]; B[i] -= A[i]; A[i] = 0; } // 右隣撃破 // モンスターの方が多い場合 if (A[i + 1] >= B[i]) { count += B[i]; A[i + 1] -= B[i]; B[i] = 0; continue; } // 勇者の方が多い場合 else if (A[i] < B[i]) { count += A[i + 1]; B[i] -= A[i + 1]; A[i + 1] = 0; } } cout << count << endl; return 0; }
replace
9
10
9
10
0
p02959
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define rg register #define min(a, b) (a) < (b) ? (a) : (b) #define max(a, b) (a) > (b) ? (a) : (b) #define abs(a) ((a) > 0 ? (a) : -(a)) #define ll long long #define maxn 50000 #pragma GCC optimize(3) #pragma - fcrossjumping #pragma - fdefer - pop #pragma - fmerge - constans #pragma - fthread - jumps #pragma - floop - optimize #pragma - fif - conversion #pragma - fif - conversion2 #pragma - fdelayed - branch #pragma - fguess - branch - probability #pragma - fcprop - registers #pragma - fforce - mem #pragma - foptimize - sibling - calls #pragma - fstrength - reduce #pragma - fgcse #pragma - fcse - follow - jumps #pragma - frerun - cse - after - loop #pragma - fdelete - null - pointer - checks #pragma - fextensive - optimizations #pragma - fregmove #pragma - fschedule - insns #pragma - fsched - interblock #pragma - fcaller - saves #pragma - fpeephole2 #pragma - freorder - blocks #pragma - fstrict - aliasing #pragma - funit - at - a - time #pragma - falign - functions #pragma - fcrossjumping #pragma - finline - functions #pragma - fweb using namespace std; inline ll read() { ll x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c <= '9' && c >= '0') { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } ll n; ll a[maxn]; ll b[maxn]; ll ans; int main() { n = read(); for (rg int i = 1; i <= n + 1; ++i) a[i] = read(); for (rg int i = 1; i <= n; ++i) b[i] = read(); for (rg int i = n + 1; i >= 1; --i) { if (b[i] >= a[i]) { ans += a[i]; b[i] -= a[i]; a[i] = 0; } else { a[i] -= b[i]; ans += b[i]; b[i] = 0; if (b[i - 1] >= a[i]) { ans += a[i]; b[i - 1] -= a[i]; a[i] = 0; } else { a[i] -= b[i - 1]; ans += b[i - 1]; b[i - 1] = 0; } } } cout << ans; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define rg register #define min(a, b) (a) < (b) ? (a) : (b) #define max(a, b) (a) > (b) ? (a) : (b) #define abs(a) ((a) > 0 ? (a) : -(a)) #define ll long long #define maxn 250000 #pragma GCC optimize(3) #pragma - fcrossjumping #pragma - fdefer - pop #pragma - fmerge - constans #pragma - fthread - jumps #pragma - floop - optimize #pragma - fif - conversion #pragma - fif - conversion2 #pragma - fdelayed - branch #pragma - fguess - branch - probability #pragma - fcprop - registers #pragma - fforce - mem #pragma - foptimize - sibling - calls #pragma - fstrength - reduce #pragma - fgcse #pragma - fcse - follow - jumps #pragma - frerun - cse - after - loop #pragma - fdelete - null - pointer - checks #pragma - fextensive - optimizations #pragma - fregmove #pragma - fschedule - insns #pragma - fsched - interblock #pragma - fcaller - saves #pragma - fpeephole2 #pragma - freorder - blocks #pragma - fstrict - aliasing #pragma - funit - at - a - time #pragma - falign - functions #pragma - fcrossjumping #pragma - finline - functions #pragma - fweb using namespace std; inline ll read() { ll x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c <= '9' && c >= '0') { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } ll n; ll a[maxn]; ll b[maxn]; ll ans; int main() { n = read(); for (rg int i = 1; i <= n + 1; ++i) a[i] = read(); for (rg int i = 1; i <= n; ++i) b[i] = read(); for (rg int i = n + 1; i >= 1; --i) { if (b[i] >= a[i]) { ans += a[i]; b[i] -= a[i]; a[i] = 0; } else { a[i] -= b[i]; ans += b[i]; b[i] = 0; if (b[i - 1] >= a[i]) { ans += a[i]; b[i - 1] -= a[i]; a[i] = 0; } else { a[i] -= b[i - 1]; ans += b[i - 1]; b[i - 1] = 0; } } } cout << ans; }
replace
27
28
27
28
0
p02959
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int N; ll sum_ll(vector<int> vec) { ll _sum = 0; rep(i, (int)vec.size()) _sum += vec[i]; return _sum; } void beat(int &_hero, int &_enemy) { while (_hero > 0 && _enemy > 0) { _hero--; _enemy--; } } int main() { cin >> N; vector<int> hero(N); vector<int> enemy(N + 1); rep(i, N + 1) cin >> enemy[i]; rep(i, N) cin >> hero[i]; ll ans = sum_ll(enemy); rep(i, N) { beat(hero[i], enemy[i]); beat(hero[i], enemy[i + 1]); } cout << ans - sum_ll(enemy) << "\n"; }
#include <algorithm> #include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int N; ll sum_ll(vector<int> vec) { ll _sum = 0; rep(i, (int)vec.size()) _sum += vec[i]; return _sum; } void beat(int &_hero, int &_enemy) { if (_hero < _enemy) { _enemy -= _hero; _hero = 0; } else { _hero -= _enemy; _enemy = 0; } } int main() { cin >> N; vector<int> hero(N); vector<int> enemy(N + 1); rep(i, N + 1) cin >> enemy[i]; rep(i, N) cin >> hero[i]; ll ans = sum_ll(enemy); rep(i, N) { beat(hero[i], enemy[i]); beat(hero[i], enemy[i + 1]); } cout << ans - sum_ll(enemy) << "\n"; }
replace
15
18
15
21
TLE
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; int A[20000]; int B[20000]; cin >> n; for (int i = 0; i < n + 1; i++) { cin >> A[i]; } for (int i = 0; i < n; i++) { cin >> B[i]; } long long ans = 0; int del; int sub; for (int i = 0; i < n; i++) { del = min(A[i], B[i]); A[i] -= del; ans += del; del = min(A[i + 1], B[i] - del); A[i + 1] -= del; ans += del; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int A[200000]; int B[200000]; cin >> n; for (int i = 0; i < n + 1; i++) { cin >> A[i]; } for (int i = 0; i < n; i++) { cin >> B[i]; } long long ans = 0; int del; int sub; for (int i = 0; i < n; i++) { del = min(A[i], B[i]); A[i] -= del; ans += del; del = min(A[i + 1], B[i] - del); A[i + 1] -= del; ans += del; } cout << ans << endl; }
replace
4
6
4
6
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int n, a[10005], b[10005], ans = 0; signed main() { cin >> n; for (int i = 1; i <= n + 1; cin >> a[i++]) ; for (int i = 1; i <= n; cin >> b[i++]) ; for (int i = 1; i <= n; i++) { if (b[i] >= a[i]) { ans += min(b[i], a[i] + a[i + 1]); a[i + 1] = max(a[0], a[i + 1] - b[i] + a[i]); } else ans += b[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int n, a[100005], b[100005], ans = 0; signed main() { cin >> n; for (int i = 1; i <= n + 1; cin >> a[i++]) ; for (int i = 1; i <= n; cin >> b[i++]) ; for (int i = 1; i <= n; i++) { if (b[i] >= a[i]) { ans += min(b[i], a[i] + a[i + 1]); a[i + 1] = max(a[0], a[i + 1] - b[i] + a[i]); } else ans += b[i]; } cout << ans << endl; return 0; }
replace
5
6
5
6
0
p02959
C++
Runtime Error
/**************************************************** * Template for coding contests * * Author : Sanjeev Sharma * * Email : thedevelopersanjeev@gmail.com * *****************************************************/ #pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; vector<long long> a(n + 1), b(n); for (long long i = 0; i < n + 1; i++) cin >> b[i]; for (long long i = 0; i < n; i++) cin >> a[i]; long long ans = 0; for (long long i = 0; i < n; i++) { // ith hero will first finish monsters in ith position // and then move to (i+1)th position long long temp = min(a[i], b[i]); // kill monsters at ith position a[i] -= temp; b[i] -= temp; ans += temp; // kill monsters at (i+1)th position temp = min(a[i], b[i + 1]); a[i] -= temp; b[i + 1] -= temp; ans += temp; } cout << ans; return 0; }
/**************************************************** * Template for coding contests * * Author : Sanjeev Sharma * * Email : thedevelopersanjeev@gmail.com * *****************************************************/ #pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; vector<long long> b(n + 1), a(n); for (long long i = 0; i < n + 1; i++) cin >> b[i]; for (long long i = 0; i < n; i++) cin >> a[i]; long long ans = 0; for (long long i = 0; i < n; i++) { // ith hero will first finish monsters in ith position // and then move to (i+1)th position long long temp = min(a[i], b[i]); // kill monsters at ith position a[i] -= temp; b[i] -= temp; ans += temp; // kill monsters at (i+1)th position temp = min(a[i], b[i + 1]); a[i] -= temp; b[i + 1] -= temp; ans += temp; } cout << ans; return 0; }
replace
20
21
20
21
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, x) REPI(i, 0, x) #define REPI(i, a, b) for (int i = int(a); i < int(b); ++i) #define ALL(x) (x).begin(), (x).end() typedef long long ll; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<ll> A(N + 1); REP(i, N + 1) { cin >> A.at(i); } vector<ll> B(N); REP(i, N) { cin >> B.at(i); } ll ans = 0; REP(i, N) { ans += min(A.at(i), B.at(i)); A.at(i) -= min(A.at(i), B.at(i)); ans += min(B.at(i + 1) - A.at(i), B.at(i + 1)); B.at(i) -= min(B.at(i + 1) - A.at(i), B.at(i + 1)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, x) REPI(i, 0, x) #define REPI(i, a, b) for (int i = int(a); i < int(b); ++i) #define ALL(x) (x).begin(), (x).end() typedef long long ll; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<ll> A(N + 1); REP(i, N + 1) { cin >> A.at(i); } vector<ll> B(N); REP(i, N) { cin >> B.at(i); } ll ans = 0; REP(i, N) { ll cnt1, cnt2; cnt1 = min(A.at(i), B.at(i)); ans += cnt1; A.at(i) -= cnt1; B.at(i) -= cnt1; cnt2 = min(A.at(i + 1), B.at(i)); ans += cnt2; A.at(i + 1) -= cnt2; } cout << ans << endl; return 0; }
replace
22
26
22
31
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02959
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; int inputValue() { int a; cin >> a; return a; }; void inputArray(int *p, int a){REP(i, a){cin >> p[i]; } } ; void inputVector(vector<int> *p, int a) { REP(i, a) { int input; cin >> input; p->push_back(input); } } int main() { int N = inputValue(); int A[100001]; int B[100000]; REP(i, N + 1) A[i] = inputValue(); REP(i, N) B[i] = inputValue(); int c = 0; int r = N / 2; REP(i, r) { while (A[i] > 0 && B[i] > 0) { A[i]--; B[i]--; c++; } while (A[i + 1] > 0 && B[i] > 0) { A[i + 1]--; B[i]--; c++; } while (A[N - i] > 0 && B[N - 1 - i] > 0) { A[N - i]--; B[N - 1 - i]--; c++; } while (A[N - 1 - i] > 0 && B[N - 1 - i] > 0) { A[N - 1 - i]--; B[N - 1 - i]--; c++; } } while (A[r] > 0 && B[r] > 0) { A[r]--; B[r]--; c++; } while (A[r + 1] > 0 && B[r] > 0) { A[r + 1]--; B[r]--; c++; } cout << c << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long ll; int inputValue() { int a; cin >> a; return a; }; void inputArray(int *p, int a){REP(i, a){cin >> p[i]; } } ; void inputVector(vector<int> *p, int a) { REP(i, a) { int input; cin >> input; p->push_back(input); } } int main() { int N = inputValue(); int A[100001]; int B[100000]; REP(i, N + 1) A[i] = inputValue(); REP(i, N) B[i] = inputValue(); ll c = 0; int f1 = 0; int f2 = 0; REP(i, N) { f1 = min(A[i] - f2, B[i]); c += f1; f2 = min(A[i + 1], B[i] - f1); c += f2; } cout << c << endl; }
replace
36
69
36
44
TLE
p02959
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 = 1'000'000'007; i64 N; cin >> N; vector<i64> A(N + 1), B(N); rep(i, 0, N + 1) cin >> A[i]; rep(i, 0, N) cin >> B[i]; i64 ans = 0; rep(i, 0, N + 1) { i64 pre = (i == 0 ? 0 : B[i - 1]); i64 pre_use = min(A[i], pre); ans += pre_use; A[i] -= pre_use; i64 cur_use = min(A[i], B[i]); ans += cur_use; B[i] -= cur_use; } cout << ans << endl; } 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 = 1'000'000'007; i64 N; cin >> N; vector<i64> A(N + 1), B(N); rep(i, 0, N + 1) cin >> A[i]; rep(i, 0, N) cin >> B[i]; i64 ans = 0; rep(i, 0, N + 1) { i64 pre = (i == 0 ? 0 : B[i - 1]); i64 pre_use = min(A[i], pre); ans += pre_use; A[i] -= pre_use; if (i < N) { i64 cur_use = min(A[i], B[i]); ans += cur_use; B[i] -= cur_use; } } cout << ans << endl; } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); solve(); return 0; }
replace
162
165
162
167
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long n, a[100001], b[100001], ans, zero = 0; int main() { cin >> n; for (int i = 1; i <= n + 1; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { cin >> b[i]; if (b[i] > a[i]) { ans += min(a[i] + a[i + 1], b[i]); a[i + 1] = max(zero, a[i] + a[i + 1] - b[i]); } else ans += b[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, a[100005], b[100001], ans, zero = 0; int main() { cin >> n; for (int i = 1; i <= n + 1; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { cin >> b[i]; if (b[i] > a[i]) { ans += min(a[i] + a[i + 1], b[i]); a[i + 1] = max(zero, a[i] + a[i + 1] - b[i]); } else ans += b[i]; } cout << ans << endl; return 0; }
replace
2
3
2
3
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> #include <cmath> #include <math.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; #define rep(i, n) \ ; \ for (int i = 0; i < n; i++) #define all(a) a.begin(), a.end() #define f(i, a, b) for (int i = a; i < b; i++) #define MOD 1000000007 bool is_int_lround(double x) { return std::lround(x) == x; } int ketasuu(int x) { int n = 0; while (x > 0) { x /= 10; n++; } return n; } ll gcd_ll(ll x, ll y) { long long a = max(x, y), b = min(x, y), c = a % b; while (c != 0) { a = b; b = c; c = a % b; } return b; } int abs(int x, int y) { if (x >= y) { return x - y; } else if (y > x) { return y - x; } } ll fiv(ll n) { if (n == 0) { return 1; } else if (n == 1) { return 1; } return fiv(n - 1) + fiv(n - 2); } ll conbi(int n, int m) { cin >> n >> m; vector<ll> a(100); a[0] = 1; for (int i = 0; i < 14; i++) { a[i + 1] = a[i] * (i + 1); } return a[n] / (a[m] * a[n - m]); } int main() { int n; cin >> n; vl a(n + 1), b(n); rep(i, n + 1) cin >> a[i]; rep(i, n) cin >> b[i]; ll ans = 0; vl c(n); c[0] = 0; rep(i, n) { c[i + 1] = min(a[i + 1], b[i] - min(a[i] - c[i], b[i])); ans += min(a[i] - c[i], b[i]) + c[i + 1]; } cout << ans << endl; }
#include <bits/stdc++.h> #include <cmath> #include <math.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; #define rep(i, n) \ ; \ for (int i = 0; i < n; i++) #define all(a) a.begin(), a.end() #define f(i, a, b) for (int i = a; i < b; i++) #define MOD 1000000007 bool is_int_lround(double x) { return std::lround(x) == x; } int ketasuu(int x) { int n = 0; while (x > 0) { x /= 10; n++; } return n; } ll gcd_ll(ll x, ll y) { long long a = max(x, y), b = min(x, y), c = a % b; while (c != 0) { a = b; b = c; c = a % b; } return b; } int abs(int x, int y) { if (x >= y) { return x - y; } else if (y > x) { return y - x; } } ll fiv(ll n) { if (n == 0) { return 1; } else if (n == 1) { return 1; } return fiv(n - 1) + fiv(n - 2); } ll conbi(int n, int m) { cin >> n >> m; vector<ll> a(100); a[0] = 1; for (int i = 0; i < 14; i++) { a[i + 1] = a[i] * (i + 1); } return a[n] / (a[m] * a[n - m]); } int main() { int n; cin >> n; vl a(n + 1), b(n); rep(i, n + 1) cin >> a[i]; rep(i, n) cin >> b[i]; ll ans = 0; vl c(n + 1); c[0] = 0; rep(i, n) { c[i + 1] = min(a[i + 1], b[i] - min(a[i] - c[i], b[i])); ans += min(a[i] - c[i], b[i]) + c[i + 1]; } cout << ans << endl; }
replace
69
70
69
70
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[10005]; long long ans = 0; for (int i = 1; i <= n + 1; ++i) cin >> a[i]; for (int i = 1, b; i <= n; ++i) { cin >> b; int x = max(0, a[i] - b); ans += a[i] - x; b -= a[i] - x; a[i] = x; if (b > 0) { int x = max(0, a[i + 1] - b); ans += a[i + 1] - x; b -= a[i + 1] - x; a[i + 1] = x; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[100005]; long long ans = 0; for (int i = 1; i <= n + 1; ++i) cin >> a[i]; for (int i = 1, b; i <= n; ++i) { cin >> b; int x = max(0, a[i] - b); ans += a[i] - x; b -= a[i] - x; a[i] = x; if (b > 0) { int x = max(0, a[i + 1] - b); ans += a[i + 1] - x; b -= a[i + 1] - x; a[i + 1] = x; } } cout << ans; }
replace
5
6
5
6
0
p02959
C++
Runtime Error
#include "bits/stdc++.h" #define rep(i, b) for (ll i = 0; i < b; i++) #define ll long long using namespace std; #define vl vector<ll> #define vvl vector<vector<ll>> #define vvvl vector<vector<vector<ll>>> #define debug(x) cerr << #x << " " << x << '\n'; int main() { ll n, ans = 0; cin >> n; vl a(n + 1), b(n); rep(i, n + 1) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n + 1) { ans += min(a[i], b[i] + b[i - 1]); b[i] = max((ll)0, b[i] - (a[i] - b[i - 1])); } cout << ans << endl; }
#include "bits/stdc++.h" #define rep(i, b) for (ll i = 0; i < b; i++) #define ll long long using namespace std; #define vl vector<ll> #define vvl vector<vector<ll>> #define vvvl vector<vector<vector<ll>>> #define debug(x) cerr << #x << " " << x << '\n'; int main() { ll n, ans = 0; cin >> n; vl a(n + 1), b(n); rep(i, n + 1) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n) { ans += min(b[i], a[i] + a[i + 1]); a[i + 1] -= min(b[i], a[i] + a[i + 1]) - min(b[i], a[i]); } cout << ans << endl; }
replace
15
18
15
18
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> #define debug(x) cerr << #x << ':' << x << endl #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define ALL(c) (c).begin(), (c).end() using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<ll> A(n, 0LL), B(n, 0LL); REP(i, n + 1) cin >> A[i]; REP(i, n) cin >> B[i]; ll cnt = 0LL; for (int i = 0; i <= n - 1; i++) { // cout << "B[i]" << B[i] << endl; if (B[i] >= A[i]) { cnt += A[i]; B[i] -= A[i]; A[i] = 0; if (B[i] >= A[i + 1]) { cnt += A[i + 1]; B[i] -= A[i + 1]; A[i + 1] = 0; } else { cnt += B[i]; A[i + 1] -= B[i]; B[i] = 0; } } else { cnt += B[i]; A[i] -= B[i]; B[i] = 0; } // cout << cnt << endl; } // REP(i,n+1) cout << A[i] << " "; // cout << endl; // REP(i,n) cout << B[i] << " "; // cout << endl; cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #define debug(x) cerr << #x << ':' << x << endl #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define ALL(c) (c).begin(), (c).end() using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<ll> A(n + 1, 0LL), B(n, 0LL); REP(i, n + 1) cin >> A[i]; REP(i, n) cin >> B[i]; ll cnt = 0LL; for (int i = 0; i <= n - 1; i++) { // cout << "B[i]" << B[i] << endl; if (B[i] >= A[i]) { cnt += A[i]; B[i] -= A[i]; A[i] = 0; if (B[i] >= A[i + 1]) { cnt += A[i + 1]; B[i] -= A[i + 1]; A[i + 1] = 0; } else { cnt += B[i]; A[i + 1] -= B[i]; B[i] = 0; } } else { cnt += B[i]; A[i] -= B[i]; B[i] = 0; } // cout << cnt << endl; } // REP(i,n+1) cout << A[i] << " "; // cout << endl; // REP(i,n) cout << B[i] << " "; // cout << endl; cout << cnt << endl; return 0; }
replace
12
13
12
13
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<int> monster(n), hero(n - 1); for (int i = 0; i < n + 1; i++) { cin >> monster[i]; } for (int i = 0; i < n; i++) { cin >> hero[i]; } ll ans = 0; int force; for (int i = 0; i < n; i++) { force = max(hero[i] - monster[i], 0); ans += min(monster[i], hero[i]); // cout << ans << endl; ans += min(force, monster[i + 1]); // cout << ans << endl; monster[i + 1] -= min(force, monster[i + 1]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<int> monster(n + 1), hero(n); for (int i = 0; i < n + 1; i++) { cin >> monster[i]; } for (int i = 0; i < n; i++) { cin >> hero[i]; } ll ans = 0; int force; for (int i = 0; i < n; i++) { force = max(hero[i] - monster[i], 0); ans += min(monster[i], hero[i]); // cout << ans << endl; ans += min(force, monster[i + 1]); // cout << ans << endl; monster[i + 1] -= min(force, monster[i + 1]); } cout << ans << endl; }
replace
8
9
8
9
0
p02959
Python
Runtime Error
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) s1 = sum(a) for i in range(n + 1): if i == 0: if a[i] < b[i]: b[i] -= a[i] a[i] = 0 else: a[i] -= b[i] b[i] = 0 elif i == n: if a[i] < b[i - 1]: a[i] = 0 else: a[i] -= b[i - 1] b[i] = 0 else: if a[i] < b[i - 1]: a[i] = 0 else: a[i] -= b[i - 1] if a[i] < b[i]: b[i] -= a[i] a[i] = 0 else: a[i] -= b[i] b[i] = 0 print(s1 - sum(a))
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) s1 = sum(a) for i in range(n + 1): if i == 0: if a[i] < b[i]: b[i] -= a[i] a[i] = 0 else: a[i] -= b[i] b[i] = 0 elif i == n: if a[i] < b[i - 1]: a[i] = 0 else: a[i] -= b[i - 1] b[i - 1] = 0 else: if a[i] < b[i - 1]: a[i] = 0 else: a[i] -= b[i - 1] if a[i] < b[i]: b[i] -= a[i] a[i] = 0 else: a[i] -= b[i] b[i] = 0 print(s1 - sum(a))
replace
18
19
18
19
IndexError: list assignment index out of range
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02959/Python/s937691477.py", line 19, in <module> b[i] = 0 IndexError: list assignment index out of range
p02959
Python
Runtime Error
# coding:utf-8 n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 for i in range(n): if a[i] >= b[i]: ans += b[i] else: ans += a[i] b[i] -= a[i] if a[i + 1] >= b[i]: a[i + 1] -= b[i] ans += b[i] else: ans += a[i + i] a[i + 1] = 0 print(ans)
# coding:utf-8 n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 0 for i in range(n): if a[i] >= b[i]: ans += b[i] else: ans += a[i] b[i] -= a[i] if a[i + 1] >= b[i]: a[i + 1] -= b[i] ans += b[i] else: ans += a[i + 1] a[i + 1] = 0 print(ans)
replace
17
18
17
18
0
p02959
Python
Runtime Error
def solve(string): n, *ab = map(int, string.split()) a, b = ab[: n + 1], ab[n + 1 :] _sum = sum(a) for i, _b in enumerate(b[::-1]): if a[n - i] < _b: _b -= a[n - i] a[n - i] = 0 a[n - i - 1] = max(0, a[n - i - 1] - _b) else: a[n - i] -= _b return str(_sum - sum(a)) if __name__ == "__main__": n = int(input()) print(solve("{}\n".format(n) + "\n".join([input() for _ in range(n)])))
def solve(string): n, *ab = map(int, string.split()) a, b = ab[: n + 1], ab[n + 1 :] _sum = sum(a) for i, _b in enumerate(b[::-1]): if a[n - i] < _b: _b -= a[n - i] a[n - i] = 0 a[n - i - 1] = max(0, a[n - i - 1] - _b) else: a[n - i] -= _b return str(_sum - sum(a)) if __name__ == "__main__": n = int(input()) print(solve("{}\n".format(n) + "\n".join([input() for _ in range(2)])))
replace
16
17
16
17
0
p02959
C++
Runtime Error
#include <iostream> #include <stdio.h> #include <string.h> #include <vector> using namespace std; #define rpt(i, n) for (i = 0; i < (n); i++) typedef long long ll; int main(void) { ll n, a[10 ^ 5 + 1], b[10 ^ 5], i, j, count = 0; cin >> n; for (i = 0; i < n + 1; i++) { cin >> a[i]; } rpt(i, n) { cin >> b[i]; } rpt(i, n) { if (a[i] >= b[i]) { count += b[i]; } else { if (b[i] >= (a[i] + a[i + 1])) { count += (a[i] + a[i + 1]); a[i + 1] = 0; } else { count += b[i]; a[i + 1] -= (b[i] - a[i]); } } } printf("%lld", count); return 0; }
#include <iostream> #include <stdio.h> #include <string.h> #include <vector> using namespace std; #define rpt(i, n) for (i = 0; i < (n); i++) typedef long long ll; int main(void) { ll n, a[100005], b[100000], i, j, count = 0; cin >> n; for (i = 0; i < n + 1; i++) { cin >> a[i]; } rpt(i, n) { cin >> b[i]; } rpt(i, n) { if (a[i] >= b[i]) { count += b[i]; } else { if (b[i] >= (a[i] + a[i + 1])) { count += (a[i] + a[i + 1]); a[i + 1] = 0; } else { count += b[i]; a[i + 1] -= (b[i] - a[i]); } } } printf("%lld", count); return 0; }
replace
10
11
10
11
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n; cin >> n; vector<ll> a(n), b(n); ll sum1 = 0; rep(i, n + 1) { cin >> a[i]; sum1 += a[i]; } rep(i, n) cin >> b[i]; rep(i, n) { if (b[i] <= a[i]) a[i] -= b[i]; else if (b[i] <= a[i] + a[i + 1]) { a[i + 1] -= b[i] - a[i]; a[i] = 0; } else { a[i] = 0; a[i + 1] = 0; } } ll sum2 = 0; rep(i, n + 1) sum2 += a[i]; cout << sum1 - sum2; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n; cin >> n; vector<ll> a(n + 1), b(n); ll sum1 = 0; rep(i, n + 1) { cin >> a[i]; sum1 += a[i]; } rep(i, n) cin >> b[i]; rep(i, n) { if (b[i] <= a[i]) a[i] -= b[i]; else if (b[i] <= a[i] + a[i + 1]) { a[i + 1] -= b[i] - a[i]; a[i] = 0; } else { a[i] = 0; a[i + 1] = 0; } } ll sum2 = 0; rep(i, n + 1) sum2 += a[i]; cout << sum1 - sum2; }
replace
8
9
8
9
0
p02959
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <deque> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; using Graph = vector<vector<int>>; long long larger(long long a, long long b) { if (a >= b) { return a; } else { return b; } } long long smaller(long long a, long long b) { if (a <= b) { return a; } else { return b; } } int main() { // input int n; cin >> n; long long counter = 0; vector<long long> a(n + 2, 0); vector<long long> b(n + 2, 0); for (int i = 1; i < n + 2; i++) cin >> a[i]; for (int i = 1; i < n + 1; i++) cin >> b[i]; // compute for (int i = 1; i < n + 2; i++) { counter += smaller(a[i] + a[i + 1], b[i]); a[i + 1] = smaller(0, a[i + 1] - larger(0, b[i] - a[i])); } // output cout << counter << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <deque> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; using Graph = vector<vector<int>>; long long larger(long long a, long long b) { if (a >= b) { return a; } else { return b; } } long long smaller(long long a, long long b) { if (a <= b) { return a; } else { return b; } } int main() { // input int n; cin >> n; long long counter = 0; vector<long long> a(n + 2, 0); vector<long long> b(n + 2, 0); for (int i = 1; i < n + 2; i++) cin >> a[i]; for (int i = 1; i < n + 1; i++) cin >> b[i]; // compute for (int i = 1; i < n + 2; i++) { counter += smaller(a[i] + a[i + 1], b[i]); a[i + 1] = larger(0, a[i + 1] - larger(0, b[i] - a[i])); } // output cout << counter << endl; }
replace
42
43
42
43
0
p02959
C++
Runtime Error
#include <algorithm> #include <iostream> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int N; cin >> N; vector<int> A(N + 1), B(N + 1); rep(i, N + 1) cin >> A[i]; rep(i, N) cin >> B[i]; B[N + 1] = 0; long long sum = 0; rep(i, N) sum += B[i]; int a = 0, b; rep(i, N + 1) { b = A[i] - a; if (b < 0) sum += b, b = 0; a = B[i] - b; if (a < 0) a = 0; } cout << sum; }
#include <algorithm> #include <iostream> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int N; cin >> N; int A[100001], B[100001]; rep(i, N + 1) cin >> A[i]; rep(i, N) cin >> B[i]; B[N + 1] = 0; long long sum = 0; rep(i, N) sum += B[i]; int a = 0, b; rep(i, N + 1) { b = A[i] - a; if (b < 0) sum += b, b = 0; a = B[i] - b; if (a < 0) a = 0; } cout << sum; }
replace
12
13
12
13
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; int n, a[10005], b[10005], sum; signed main() { cin >> n; for (int i = 1; i <= n + 1; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n; i++) { if (b[i] < a[i]) { a[i] -= b[i], sum += b[i]; continue; } if (b[i] >= a[i]) b[i] -= a[i], sum += a[i], a[i] = 0; if (b[i] >= a[i + 1]) sum += a[i + 1], a[i + 1] = 0; else sum += b[i], a[i + 1] -= b[i]; } cout << sum; }
#include <bits/stdc++.h> #define int long long using namespace std; int n, a[100005], b[100005], sum; signed main() { cin >> n; for (int i = 1; i <= n + 1; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n; i++) { if (b[i] < a[i]) { a[i] -= b[i], sum += b[i]; continue; } if (b[i] >= a[i]) b[i] -= a[i], sum += a[i], a[i] = 0; if (b[i] >= a[i + 1]) sum += a[i + 1], a[i + 1] = 0; else sum += b[i], a[i + 1] -= b[i]; } cout << sum; }
replace
3
4
3
4
0
p02959
C++
Runtime Error
#include <algorithm> #include <bitset> #include <functional> #include <initializer_list> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> using namespace std; typedef long long int ll; int main() { ll N; cin >> N; vector<ll> A(N + 1); vector<ll> B(N); for (ll i = 0; i < N + 1; i++) { cin >> A[i]; } for (ll i = 0; i < N; i++) { cin >> B[i]; } ll Count = 0; for (ll i = 0; i < N; i++) { if (A[i] >= B[i]) { Count += B[i]; B[i] = 0; } else { B[i] -= A[i]; Count += A[i]; if (A[i + 1] >= B[i]) { A[i + 1] -= B[i]; Count += B[i]; } else { Count += A[i + 1]; A[i + 1] = 0; } } } if (A[N] >= B[N]) { B[N] = 0; Count += B[N]; } else Count += A[N]; cout << Count; }
#include <algorithm> #include <bitset> #include <functional> #include <initializer_list> #include <iostream> #include <map> #include <string> #include <utility> #include <vector> using namespace std; typedef long long int ll; int main() { ll N; cin >> N; vector<ll> A(N + 1); vector<ll> B(N); for (ll i = 0; i < N + 1; i++) { cin >> A[i]; } for (ll i = 0; i < N; i++) { cin >> B[i]; } ll Count = 0; for (ll i = 0; i < N; i++) { if (A[i] >= B[i]) { Count += B[i]; B[i] = 0; } else { B[i] -= A[i]; Count += A[i]; if (A[i + 1] >= B[i]) { A[i + 1] -= B[i]; Count += B[i]; } else { Count += A[i + 1]; A[i + 1] = 0; } } } cout << Count; }
delete
41
46
41
41
0
p02959
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<long long> cities(n + 1); vector<long long> heros(n + 1); for (int i = 0; i < n + 1; i++) { cin >> cities[i]; } for (int i = 0; i < n; i++) { cin >> heros[i]; } heros[n + 1] = 0; long long acc = 0; long long prev_hero = 0; long long prev_hero_min = 0; for (int i = 0; i < n + 1; i++) { acc += min((prev_hero + heros[i]), cities[i]); prev_hero = max(heros[i] - max((cities[i] - prev_hero), prev_hero_min), prev_hero_min); } cout << acc << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<long long> cities(n + 1); vector<long long> heros(n + 1); for (int i = 0; i < n + 1; i++) { cin >> cities[i]; } for (int i = 0; i < n; i++) { cin >> heros[i]; } heros[n] = 0; long long acc = 0; long long prev_hero = 0; long long prev_hero_min = 0; for (int i = 0; i < n + 1; i++) { acc += min((prev_hero + heros[i]), cities[i]); prev_hero = max(heros[i] - max((cities[i] - prev_hero), prev_hero_min), prev_hero_min); } cout << acc << endl; return 0; }
replace
17
18
17
18
-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)
p02959
C++
Runtime Error
#include <bits/stdc++.h> #include <string.h> // #include <queue> using namespace std; #define ll long long #define ld long double #define itvector(it, x) for (auto it : x) #define FOR(x, a, b) for (int x = a; x <= b; ++x) #define FOD(x, a, b) for (int x = a; x >= b; --x) // #define Phuong // <3 love my GF // still learning :C; can't even do Div 2 C and D // this is so sad typedef pair<int, int> ii; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif // ONLINE_JUDGE ios_base::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; vector<int> a(n + 1); FOR(i, 0, n) cin >> a[i]; ll res = 0; FOR(i, 0, n - 1) { int k; cin >> k; if (a[i] <= k) { res += a[i]; k -= a[i]; } else { res += k; k = 0; } if (a[i + 1] <= k) { res += a[i + 1]; a[i + 1] = 0; } else { res += k; a[i + 1] -= k; } } cout << res; return (0); }
#include <bits/stdc++.h> #include <string.h> // #include <queue> using namespace std; #define ll long long #define ld long double #define itvector(it, x) for (auto it : x) #define FOR(x, a, b) for (int x = a; x <= b; ++x) #define FOD(x, a, b) for (int x = a; x >= b; --x) // #define Phuong // <3 love my GF // still learning :C; can't even do Div 2 C and D // this is so sad typedef pair<int, int> ii; int main() { #ifdef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif // ONLINE_JUDGE ios_base::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; vector<int> a(n + 1); FOR(i, 0, n) cin >> a[i]; ll res = 0; FOR(i, 0, n - 1) { int k; cin >> k; if (a[i] <= k) { res += a[i]; k -= a[i]; } else { res += k; k = 0; } if (a[i + 1] <= k) { res += a[i + 1]; a[i + 1] = 0; } else { res += k; a[i + 1] -= k; } } cout << res; return (0); }
replace
15
16
15
16
-6
terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size()
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long n, ans = 0; cin >> n; vector<long> a(n + 1); vector<long> b(n); for (int i = 0; i < n + 1; i++) cin >> a.at(i); for (int i = 0; i < n; i++) cin >> b.at(i); for (int i = 0; i < n; i++) { if (a.at(i) <= b.at(i)) { b.at(i) -= a.at(i); ans += a.at(i); if (a.at(i + 1) <= b.at(i)) { ans += a.at(i + 1); a.at(i + 1) = 0; } else { ans += b.at(i); a.at(i + i) -= b.at(i); }; } else { ans += b.at(i); }; }; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long n, ans = 0; cin >> n; vector<long> a(n + 1); vector<long> b(n); for (int i = 0; i < n + 1; i++) cin >> a.at(i); for (int i = 0; i < n; i++) cin >> b.at(i); for (int i = 0; i < n; i++) { if (a.at(i) <= b.at(i)) { b.at(i) -= a.at(i); ans += a.at(i); if (a.at(i + 1) <= b.at(i)) { ans += a.at(i + 1); a.at(i + 1) = 0; } else { ans += b.at(i); a.at(i + 1) -= b.at(i); }; } else { ans += b.at(i); }; }; cout << ans << endl; }
replace
21
22
21
22
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> a(n + 1), b(n); for (int i = 0; i < n + 1; ++i) { cin >> a[i]; } for (int j = 0; j < n; ++j) { cin >> b[j]; } long long ans = 0; vector<long long> a2 = a, b2 = b; for (int i = 0; i < n; ++i) { if (a[i] <= b[i]) { ans += a[i]; b[i] -= a[i]; a[i] = 0; } else { ans += b[i]; b[i] = 0; } if (b[i] > 0) { if (a[i + 1] <= b[i]) { ans += a[i + 1]; b[i] -= a[i + 1]; a[i + 1] = 0; } else { ans += b[i]; a[i + 1] -= b[i]; b[i] = 0; } } } long long ans2 = 0; for (int i = n; i >= 0; --i) { if (a2[i + 1] <= b2[i]) { ans2 += a2[i + 1]; b2[i] -= a2[i + 1]; a2[i + 1] = 0; } else { ans2 += b2[i]; b2[i] = 0; } if (b2[i] > 0) { if (a2[i] <= b2[i]) { ans2 += a2[i]; b2[i] -= a2[i]; a2[i] = 0; } else { ans2 += b2[i]; a2[i] -= b2[i]; b2[i] = 0; } } } cout << max(ans, ans2) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> a(n + 1), b(n); for (int i = 0; i < n + 1; ++i) { cin >> a[i]; } for (int j = 0; j < n; ++j) { cin >> b[j]; } long long ans = 0; vector<long long> a2 = a, b2 = b; for (int i = 0; i < n; ++i) { if (a[i] <= b[i]) { ans += a[i]; b[i] -= a[i]; a[i] = 0; } else { ans += b[i]; b[i] = 0; } if (b[i] > 0) { if (a[i + 1] <= b[i]) { ans += a[i + 1]; b[i] -= a[i + 1]; a[i + 1] = 0; } else { ans += b[i]; a[i + 1] -= b[i]; b[i] = 0; } } } long long ans2 = 0; for (int i = n - 1; i >= 0; --i) { if (a2[i + 1] <= b2[i]) { ans2 += a2[i + 1]; b2[i] -= a2[i + 1]; a2[i + 1] = 0; } else { ans2 += b2[i]; b2[i] = 0; } if (b2[i] > 0) { if (a2[i] <= b2[i]) { ans2 += a2[i]; b2[i] -= a2[i]; a2[i] = 0; } else { ans2 += b2[i]; a2[i] -= b2[i]; b2[i] = 0; } } } cout << max(ans, ans2) << endl; return 0; }
replace
40
41
40
41
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main(void) { int N; int A[10001], B[10000]; int sum = 0; cin >> N; for (int i = 0; i <= N; ++i) { cin >> A[i]; sum += A[i]; } for (int i = 0; i < N; ++i) cin >> B[i]; for (int i = 0; i < N; ++i) { for (int j = 0; j <= 1; ++j) { if (B[i] > A[i + j]) { B[i] -= A[i + j]; A[i + j] = 0; } else { A[i + j] -= B[i]; B[i] = 0; } } } for (int i = 0; i <= N; ++i) { sum -= A[i]; } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int main(void) { int N; long long A[100001], B[100000]; long long sum = 0; cin >> N; for (int i = 0; i <= N; ++i) { cin >> A[i]; sum += A[i]; } for (int i = 0; i < N; ++i) cin >> B[i]; for (int i = 0; i < N; ++i) { for (int j = 0; j <= 1; ++j) { if (B[i] > A[i + j]) { B[i] -= A[i + j]; A[i + j] = 0; } else { A[i + j] -= B[i]; B[i] = 0; } } } for (int i = 0; i <= N; ++i) { sum -= A[i]; } cout << sum << endl; }
replace
6
8
6
8
0
p02959
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const long long INF = 1e7 + 1; const long long MOD = 1000000007; const long double PI = 3.1415926; #define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); ++i) #define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define RALL(x) x.rbegin(), x.rend() using ll = long long int; using ull = unsigned long long int; using vi = vector<ll>; using vp = vector<pair<ll, ll>>; using vs = vector<string>; using vc = vector<char>; using lst = list<ll>; ll n, m, k, ans = 0, sum = 0, cnt = 0; string s; char c; /*--------------------template--------------------*/ int main() { cin >> n; ull A[n + 1], B[n]; REP(i, n + 1) { cin >> A[i]; cnt += A[i]; } REP(i, n) { cin >> B[i]; } REP(i, n) { if (A[i] >= B[i]) { A[i] -= B[i]; } else if (A[i] < B[i]) { B[i] -= A[i]; A[i] = 0; while (A[i + 1] > 0 && B[i] > 0) { A[i + 1] -= 1; B[i] -= 1; } } } REP(i, n + 1) { sum += A[i]; } cout << cnt - sum << endl; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e7 + 1; const long long MOD = 1000000007; const long double PI = 3.1415926; #define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); ++i) #define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define RALL(x) x.rbegin(), x.rend() using ll = long long int; using ull = unsigned long long int; using vi = vector<ll>; using vp = vector<pair<ll, ll>>; using vs = vector<string>; using vc = vector<char>; using lst = list<ll>; ll n, m, k, ans = 0, sum = 0, cnt = 0; string s; char c; /*--------------------template--------------------*/ int main() { cin >> n; ull A[n + 1], B[n]; REP(i, n + 1) { cin >> A[i]; cnt += A[i]; } REP(i, n) { cin >> B[i]; } REP(i, n) { if (A[i] >= B[i]) { A[i] -= B[i]; } else if (A[i] < B[i]) { B[i] -= A[i]; A[i] = 0; if (A[i + 1] > B[i]) { A[i + 1] -= B[i]; B[i] = 0; } else { B[i] -= A[i + 1]; A[i + 1] = 0; } } } REP(i, n + 1) { sum += A[i]; } cout << cnt - sum << endl; }
replace
42
45
42
48
TLE
p02959
C++
Runtime Error
// This code was made by Chinese_zjc_ #include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> #define int long long #define INF 0x3fffffffffffffff using namespace std; inline int rd(int &ddd) { char tmp = getchar(); int xxx = 1; ddd = 0; while (('0' > tmp || tmp > '9') && tmp != '-' && tmp != EOF) { tmp = getchar(); } if (tmp == EOF) { return EOF; } if (tmp == '-') { xxx = -1; tmp = getchar(); } while ('0' <= tmp && tmp <= '9') { ddd = (ddd << 3) + (ddd << 1) + (tmp ^ 48); tmp = getchar(); } return ddd *= xxx; } inline char rd(char &ddd) { char tmp = getchar(); while (tmp == ' ' || tmp == '\n') { tmp = getchar(); } if (tmp == EOF) { return EOF; } return ddd = tmp; } inline int max(const int &A, const int &B) { return A < B ? B : A; } inline int min(const int &A, const int &B) { return A < B ? A : B; } int n, a[100001], x, ans; signed main() { rd(n); for (int i = 1; i <= n + 1; ++i) { rd(a[i]); } for (int i = 1; i <= n; ++i) { rd(x); ans += min(a[i], x); x -= min(a[i], x); ans += min(a[i + 1], x); a[i + 1] -= min(a[i + 1], x); } printf("%lld", ans); return 0; }
// This code was made by Chinese_zjc_ #include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> #define int long long #define INF 0x3fffffffffffffff using namespace std; inline int rd(int &ddd) { char tmp = getchar(); int xxx = 1; ddd = 0; while (('0' > tmp || tmp > '9') && tmp != '-' && tmp != EOF) { tmp = getchar(); } if (tmp == EOF) { return EOF; } if (tmp == '-') { xxx = -1; tmp = getchar(); } while ('0' <= tmp && tmp <= '9') { ddd = (ddd << 3) + (ddd << 1) + (tmp ^ 48); tmp = getchar(); } return ddd *= xxx; } inline char rd(char &ddd) { char tmp = getchar(); while (tmp == ' ' || tmp == '\n') { tmp = getchar(); } if (tmp == EOF) { return EOF; } return ddd = tmp; } inline int max(const int &A, const int &B) { return A < B ? B : A; } inline int min(const int &A, const int &B) { return A < B ? A : B; } int n, a[100005], x, ans; signed main() { rd(n); for (int i = 1; i <= n + 1; ++i) { rd(a[i]); } for (int i = 1; i <= n; ++i) { rd(x); ans += min(a[i], x); x -= min(a[i], x); ans += min(a[i + 1], x); a[i + 1] -= min(a[i + 1], x); } printf("%lld", ans); return 0; }
replace
41
42
41
42
0
p02959
C++
Runtime Error
#include <algorithm> //sort() #include <iostream> #include <numeric> #include <stdlib.h> #include <tuple> #include <vector> //vector #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() // #define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << // endl;} typedef uint64_t ulint; typedef int64_t lint; using namespace std; template <class T> inline bool chmin(T &a, T b); template <class T> inline bool chmax(T &a, T b); template <typename T> ostream &operator<<(ostream &s, const vector<T> &v); template <class T> lint sum(vector<T> a); template <class T> double ave(vector<T> a); lint n, k; lint h, w; bool flagdebug = false; int main() { ////////////////////////////////////////////////////// // flagdebug = true; ///本番時削除!!!!! cin >> n; vector<lint> a(n + 1); vector<lint> b(n); // debug("aaa"); rep(i, n + 1) { cin >> a[i]; } rep(i, n) { cin >> b[i]; } // debug("aaaa"); lint sum = 0; rep(i, n) { if (b[i] <= a[i]) { sum += b[i]; b[i] = 0; } else { sum += a[i]; b[i] -= a[i]; if (b[i] <= a[i + i]) { sum += b[i]; a[i + 1] -= b[i]; } else { sum += a[i + 1]; a[i + 1] = 0; } } } cout << sum << endl; // vector<lint> s(n); // fpair<lint,lint> p = make_pair(1,2); // tuple<lint,lint,lint> t = make_tuple(1,2,3); // 昇順ソート // sort(all(a)); // sort(input.begin() , input.end()); // uint64_t max = numeric_limits<uint64_t>::max(); ////////////////////////////////////////////////////// // DP // // 無限大の値 // const uint64_t INF = (uint64_t)1 << 60; // //const int64_t NINF = -1 * ((int64_t)1 << 60 ); // // DP テーブル // uint64_t dp[100010]; // //DPテーブル初期化(最小化用) // for (int i = 0; i < 100010; ++i) // { // //dp[i] = INF; // dp[i] = 0; // } // // 初期条件 // dp[0] = 0; // // ループ // for (int i = 1; i <= n; ++i) { // //chmin( dp[i], dp[i - 1] + abs( input[i] - input[i - 1] )); // //if (i < 2)continue; // //chmin( dp[i], dp[i - 2] + abs( input[i] - input[i - 2] )); // // chmax ( dp [i] , dp[i - 1]); // // chmax ( dp [i] , dp[i - 1] + input[i]); // // cout << "dp[" << i <<"] = " << dp[i] << endl; // } // ////////////////////////////////////////////////////// // cout << dp[n] << endl; ////////////////////////////////////////////////////// // Ctrl + Opt + N to make return 0; } // 最小化用関数 template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } // 最大化関数 template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // vectorprint用 template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { int len = v.size(); for (int i = 0; i < len; ++i) { s << v[i]; if (i < len - 1) s << "\t"; } return s; } // //合計 // template<class T> lint sum(vector<T> a) // { // return std::accumulate(a.begin(), a.end(), 0); // } // //平均 // template<class T> double ave(vector<T> a) // { // return std::accumulate(a.begin(), a.end(), 0.0) / a.size(); // }
#include <algorithm> //sort() #include <iostream> #include <numeric> #include <stdlib.h> #include <tuple> #include <vector> //vector #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() // #define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << // endl;} typedef uint64_t ulint; typedef int64_t lint; using namespace std; template <class T> inline bool chmin(T &a, T b); template <class T> inline bool chmax(T &a, T b); template <typename T> ostream &operator<<(ostream &s, const vector<T> &v); template <class T> lint sum(vector<T> a); template <class T> double ave(vector<T> a); lint n, k; lint h, w; bool flagdebug = false; int main() { ////////////////////////////////////////////////////// // flagdebug = true; ///本番時削除!!!!! cin >> n; vector<lint> a(n + 1); vector<lint> b(n); // debug("aaa"); rep(i, n + 1) { cin >> a[i]; } rep(i, n) { cin >> b[i]; } // debug("aaaa"); lint sum = 0; rep(i, n) { if (b[i] <= a[i]) { sum += b[i]; b[i] = 0; } else { sum += a[i]; // 全員倒す b[i] -= a[i]; // 勇者の倒せる数も減る if (b[i] <= a[i + 1]) { sum += b[i]; a[i + 1] -= b[i]; } else { sum += a[i + 1]; a[i + 1] = 0; } } } cout << sum << endl; // vector<lint> s(n); // fpair<lint,lint> p = make_pair(1,2); // tuple<lint,lint,lint> t = make_tuple(1,2,3); // 昇順ソート // sort(all(a)); // sort(input.begin() , input.end()); // uint64_t max = numeric_limits<uint64_t>::max(); ////////////////////////////////////////////////////// // DP // // 無限大の値 // const uint64_t INF = (uint64_t)1 << 60; // //const int64_t NINF = -1 * ((int64_t)1 << 60 ); // // DP テーブル // uint64_t dp[100010]; // //DPテーブル初期化(最小化用) // for (int i = 0; i < 100010; ++i) // { // //dp[i] = INF; // dp[i] = 0; // } // // 初期条件 // dp[0] = 0; // // ループ // for (int i = 1; i <= n; ++i) { // //chmin( dp[i], dp[i - 1] + abs( input[i] - input[i - 1] )); // //if (i < 2)continue; // //chmin( dp[i], dp[i - 2] + abs( input[i] - input[i - 2] )); // // chmax ( dp [i] , dp[i - 1]); // // chmax ( dp [i] , dp[i - 1] + input[i]); // // cout << "dp[" << i <<"] = " << dp[i] << endl; // } // ////////////////////////////////////////////////////// // cout << dp[n] << endl; ////////////////////////////////////////////////////// // Ctrl + Opt + N to make return 0; } // 最小化用関数 template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } // 最大化関数 template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // vectorprint用 template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { int len = v.size(); for (int i = 0; i < len; ++i) { s << v[i]; if (i < len - 1) s << "\t"; } return s; } // //合計 // template<class T> lint sum(vector<T> a) // { // return std::accumulate(a.begin(), a.end(), 0); // } // //平均 // template<class T> double ave(vector<T> a) // { // return std::accumulate(a.begin(), a.end(), 0.0) / a.size(); // }
replace
52
55
52
56
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) int main() { int n; cin >> n; vector<long> a(n + 1); rep(i, n + 1) cin >> a[i]; vector<long> b(n); rep(i, n + 1) cin >> b[i]; b[n] = 0; long c; c = 0; rep(i, n + 1) { long l = min(a[i], b[i]); c += l; long r = min(a[i + 1], b[i] - l); c += r; a[i + 1] -= r; b[i] -= r; } cout << c << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) int main() { int n; cin >> n; vector<long> a(n + 1); rep(i, n + 1) cin >> a[i]; vector<long> b(n + 1); rep(i, n) cin >> b[i]; b[n] = 0; long c; c = 0; rep(i, n + 1) { long l = min(a[i], b[i]); c += l; long r = min(a[i + 1], b[i] - l); c += r; a[i + 1] -= r; b[i] -= r; } cout << c << endl; return 0; }
replace
9
11
9
11
0
p02959
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int main() { int n; long b, c, t; cin >> n; vector<long> a(n); for (int i = 0; i < n + 1; ++i) cin >> a[i]; c = 0; for (int i = 0; i < n; ++i) { cin >> b; t = min(b, a[i] + a[i + 1]); c += t; a[i + 1] -= t - min(b, a[i]); } cout << c; }
#include <iostream> #include <vector> using namespace std; int main() { int n; long b, c, t; cin >> n; vector<long> a(n + 1); for (int i = 0; i < n + 1; ++i) cin >> a[i]; c = 0; for (int i = 0; i < n; ++i) { cin >> b; t = min(b, a[i] + a[i + 1]); c += t; a[i + 1] -= t - min(b, a[i]); } cout << c; }
replace
8
9
8
9
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; /* #pragma */ // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") /*alias*/ #define F first #define S second #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define next asdnext #define prev asdprev #define itn int /*template*/ template <class T> inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } /* func */ int32_t GCD(int32_t a, int32_t b) { return b ? GCD(b, a % b) : a; } int64_t GCD(int64_t a, int64_t b) { return b ? GCD(b, a % b) : a; } int32_t LCM(int32_t a, int32_t b) { return a * b / GCD(a, b); } int64_t LCM(int64_t a, int64_t b) { return a * b / GCD(a, b); } /*struct*/ struct aaa { aaa() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } aaaaaaa; /* const */ constexpr int32_t INF = 1001001001; constexpr int64_t LINF = 1001001001001001001ll; constexpr int32_t MOD = 1e9 + 7; // 10^9 constexpr int64_t EPS = 1e-9; constexpr int32_t dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; // Counterclockwise from the 6o'clock direction // Take the x-axis downward and the y-axis right // g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp // g++ -std=c++14 -Wall --pedantic-errors template.cpp // chcp 65001 /*global*/ #define int int64_t signed main() { int n; cin >> n; vector<int> a(n + 1); for (int i = 0, i_len = (int)n + 1; i < i_len; ++i) cin >> a[i]; vector<int> b(n); for (int i = 0, i_len = (int)n; i < i_len; ++i) cin >> b[i]; int ans{}; for (int i = 0, i_len = (int)n; i < i_len; ++i) { int left = min(a[i], b[i]); ans += left; a[i] -= left; b[i] -= left; int right = min(a[i + 1], b[i]); ans += right; a[i + 1] -= right; b[i + 1] -= right; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; /* #pragma */ // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") /*alias*/ #define F first #define S second #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define next asdnext #define prev asdprev #define itn int /*template*/ template <class T> inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } /* func */ int32_t GCD(int32_t a, int32_t b) { return b ? GCD(b, a % b) : a; } int64_t GCD(int64_t a, int64_t b) { return b ? GCD(b, a % b) : a; } int32_t LCM(int32_t a, int32_t b) { return a * b / GCD(a, b); } int64_t LCM(int64_t a, int64_t b) { return a * b / GCD(a, b); } /*struct*/ struct aaa { aaa() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } aaaaaaa; /* const */ constexpr int32_t INF = 1001001001; constexpr int64_t LINF = 1001001001001001001ll; constexpr int32_t MOD = 1e9 + 7; // 10^9 constexpr int64_t EPS = 1e-9; constexpr int32_t dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; // Counterclockwise from the 6o'clock direction // Take the x-axis downward and the y-axis right // g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp // g++ -std=c++14 -Wall --pedantic-errors template.cpp // chcp 65001 /*global*/ #define int int64_t signed main() { int n; cin >> n; vector<int> a(n + 1); for (int i = 0, i_len = (int)n + 1; i < i_len; ++i) cin >> a[i]; vector<int> b(n); for (int i = 0, i_len = (int)n; i < i_len; ++i) cin >> b[i]; int ans{}; for (int i = 0, i_len = (int)n; i < i_len; ++i) { int left = min(a[i], b[i]); ans += left; a[i] -= left; b[i] -= left; int right = min(a[i + 1], b[i]); ans += right; a[i + 1] -= right; b[i] -= right; } cout << ans << endl; }
replace
89
90
89
90
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(v) v.begin(), v.end() typedef long long ll; ll GCD(ll x, ll y) { if (y == 0) return x; else return GCD(y, x % y); } ll LCM(ll x, ll y) { return x * y / GCD(x, y); } int main() { int n; cin >> n; vector<ll> a(n + 1), b(n); rep(i, n + 1) cin >> a[i]; rep(i, n) cin >> b[i]; ll res = 0; rep(i, n) { ll tmp = min(a[i], b[i]); a[i] -= tmp; b[i] -= tmp; res += tmp; tmp = min(b[i], a[i + 1]); a[i - 1] -= tmp; res += tmp; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(v) v.begin(), v.end() typedef long long ll; ll GCD(ll x, ll y) { if (y == 0) return x; else return GCD(y, x % y); } ll LCM(ll x, ll y) { return x * y / GCD(x, y); } int main() { int n; cin >> n; vector<ll> a(n + 1), b(n); rep(i, n + 1) cin >> a[i]; rep(i, n) cin >> b[i]; ll res = 0; rep(i, n) { ll tmp = min(a[i], b[i]); a[i] -= tmp; b[i] -= tmp; res += tmp; tmp = min(b[i], a[i + 1]); a[i + 1] -= tmp; res += tmp; } cout << res << endl; }
replace
29
30
29
30
0
p02959
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int N; cin >> N; vector<ll> A(N + 1), B(N); for (int i = 0; i < N + 1; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { cin >> B[i]; } ll ans = 0; for (int i = 0; i < N + 1; i++) { ll sub = min(A[i], B[i]); B[i] -= sub; ans += sub; sub = min(B[i], A[i + 1]); A[i + 1] -= sub; ans += sub; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int N; cin >> N; vector<int> A(N + 1), B(N); for (int i = 0; i < N + 1; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) { cin >> B[i]; } ll ans = 0; for (int i = 0; i < N + 1; i++) { ll sub = min(A[i], B[i]); B[i] -= sub; ans += sub; sub = min(B[i], A[i + 1]); A[i + 1] -= sub; ans += sub; } cout << ans << endl; return 0; }
replace
9
10
9
10
0
p02960
C++
Runtime Error
// C #include <bits/stdc++.h> using ll = long long; using namespace std; ll mod = 1e9 + 7; int main() { string s; cin >> s; int N = s.size(); ll dp[10001][13] = {0}; if (s[0] == '?') { for (int i(0); i <= 9; i++) { dp[1][i] = 1; } } else { dp[1][s[0] - '0'] = 1; } for (int i(2); i <= N; i++) { if (s[i - 1] == '?') { for (int j(0); j < 13; j++) { for (int k(0); k < 10; k++) { int next_amari = (j * 10 + k) % 13; dp[i][next_amari] += dp[i - 1][j]; dp[i][next_amari] %= mod; } } } else { for (int j(0); j < 13; j++) { int next_amari = (j * 10 + (s[i - 1] - '0')) % 13; dp[i][next_amari] += dp[i - 1][j]; dp[i][next_amari] %= mod; } } } cout << dp[N][5] << endl; return 0; }
// C #include <bits/stdc++.h> using ll = long long; using namespace std; ll mod = 1e9 + 7; int main() { string s; cin >> s; int N = s.size(); ll dp[100001][13] = {0}; if (s[0] == '?') { for (int i(0); i <= 9; i++) { dp[1][i] = 1; } } else { dp[1][s[0] - '0'] = 1; } for (int i(2); i <= N; i++) { if (s[i - 1] == '?') { for (int j(0); j < 13; j++) { for (int k(0); k < 10; k++) { int next_amari = (j * 10 + k) % 13; dp[i][next_amari] += dp[i - 1][j]; dp[i][next_amari] %= mod; } } } else { for (int j(0); j < 13; j++) { int next_amari = (j * 10 + (s[i - 1] - '0')) % 13; dp[i][next_amari] += dp[i - 1][j]; dp[i][next_amari] %= mod; } } } cout << dp[N][5] << endl; return 0; }
replace
11
12
11
12
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define all(a) a.begin(), a.end() #define F first #define S second #define pb push_back #define ll long long #define vi vector<int> #define pi pair<int, int> #define mp make_pair #define endl '\n' #define _ << ' ' #define min3(a, b, c) min(a, min(b, c)) #define min4(a, b, c, d) min(min(a, d), min(b, c)) using namespace std; const ll mod = (ll)1e9 + 7; const ll INF = (ll)1e9 + 1; ll dp[100001][13]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("B.txt", "r", stdin); #endif string s; cin >> s; int n = s.length(); dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 13; j++) { if (s[i] == '?') { for (int d = 0; d < 10; d++) dp[i + 1][(j * 10 + d) % 13] = (dp[i][j] + dp[i + 1][(j * 10 + d) % 13]) % mod; } else { dp[i + 1][(j * 10 + s[i] - '0') % 13] = (dp[i][j] + dp[i + 1][(j * 10 + s[i] - '0') % 13]) % mod; } } } cout << dp[n][5]; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define all(a) a.begin(), a.end() #define F first #define S second #define pb push_back #define ll long long #define vi vector<int> #define pi pair<int, int> #define mp make_pair #define endl '\n' #define _ << ' ' #define min3(a, b, c) min(a, min(b, c)) #define min4(a, b, c, d) min(min(a, d), min(b, c)) using namespace std; const ll mod = (ll)1e9 + 7; const ll INF = (ll)1e9 + 1; ll dp[100001][13]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE // freopen("B.txt", "r", stdin); #endif string s; cin >> s; int n = s.length(); dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 13; j++) { if (s[i] == '?') { for (int d = 0; d < 10; d++) dp[i + 1][(j * 10 + d) % 13] = (dp[i][j] + dp[i + 1][(j * 10 + d) % 13]) % mod; } else { dp[i + 1][(j * 10 + s[i] - '0') % 13] = (dp[i][j] + dp[i + 1][(j * 10 + s[i] - '0') % 13]) % mod; } } } cout << dp[n][5]; }
replace
26
27
26
27
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; typedef long long ll; ll n; char M[101010][13] = {}; ll dp[1010][1010] = {}; ll cnt = LLONG_MAX; ll B = 1000000007; int main() { string s; cin >> s; dp[0][0] = 1; rep(i, s.size()) { if (s[i] == '?') { rep(j, 10) { rep(k, 13) { int a = (k * 10 + j) % 13; dp[i + 1][a] += dp[i][k]; dp[i + 1][a] %= B; } } } else { s[i] -= '0'; rep(k, 13) { int a = (k * 10 + s[i]) % 13; dp[i + 1][a] += dp[i][k]; dp[i + 1][a] %= B; } } } cout << dp[s.size()][5] << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; typedef long long ll; ll n; char M[101010][13] = {}; ll dp[101010][1010] = {}; ll cnt = LLONG_MAX; ll B = 1000000007; int main() { string s; cin >> s; dp[0][0] = 1; rep(i, s.size()) { if (s[i] == '?') { rep(j, 10) { rep(k, 13) { int a = (k * 10 + j) % 13; dp[i + 1][a] += dp[i][k]; dp[i + 1][a] %= B; } } } else { s[i] -= '0'; rep(k, 13) { int a = (k * 10 + s[i]) % 13; dp[i + 1][a] += dp[i][k]; dp[i + 1][a] %= B; } } } cout << dp[s.size()][5] << endl; }
replace
8
9
8
9
0
p02960
C++
Runtime Error
#include <cmath> #include <cstdlib> #include <iostream> #include <stdint.h> #include <string> #include <utility> #include <vector> using namespace std; unsigned dp[10000][13] = {0}; int main() { string S; cin >> S; if (S[0] == '?') for (int ii = 0; ii < 10; ++ii) { dp[0][ii] = 1; } else dp[0][S[0] - '0'] = 1; for (int ii = 1; ii < S.size(); ++ii) { for (int tens = 0; tens < 13; ++tens) { if (S[ii] == '?') { for (int ones = 0; ones < 10; ++ones) { int residue = (tens * 10 + ones) % 13; dp[ii][residue] += dp[ii - 1][tens]; dp[ii][residue] %= 1000000007; } } else { int ones = S[ii] - '0'; int residue = (tens * 10 + ones) % 13; dp[ii][residue] += dp[ii - 1][tens]; dp[ii][residue] %= 1000000007; } } } cout << dp[S.size() - 1][5] << endl; return 0; }
#include <cmath> #include <cstdlib> #include <iostream> #include <stdint.h> #include <string> #include <utility> #include <vector> using namespace std; unsigned dp[100000][13] = {0}; int main() { string S; cin >> S; if (S[0] == '?') for (int ii = 0; ii < 10; ++ii) { dp[0][ii] = 1; } else dp[0][S[0] - '0'] = 1; for (int ii = 1; ii < S.size(); ++ii) { for (int tens = 0; tens < 13; ++tens) { if (S[ii] == '?') { for (int ones = 0; ones < 10; ++ones) { int residue = (tens * 10 + ones) % 13; dp[ii][residue] += dp[ii - 1][tens]; dp[ii][residue] %= 1000000007; } } else { int ones = S[ii] - '0'; int residue = (tens * 10 + ones) % 13; dp[ii][residue] += dp[ii - 1][tens]; dp[ii][residue] %= 1000000007; } } } cout << dp[S.size() - 1][5] << endl; return 0; }
replace
10
11
10
11
0
p02960
C++
Runtime Error
// 解説見た #include <bits/stdc++.h> typedef long long lint; using namespace std; #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rrep(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i) const int MOD = 1000000007; int main() { string s; cin >> s; int dp[10001][13] = {0}; dp[0][0] = 1; rrep(i, s.size() + 1) { if (s[i - 1] == '?') { rep(num, 10) { rep(j, 13) { dp[i][(j * 10 + num) % 13] += dp[i - 1][j]; dp[i][(j * 10 + num) % 13] %= MOD; } } } else { int num = s[i - 1] - '0'; rep(j, 13) { dp[i][(j * 10 + num) % 13] += dp[i - 1][j]; dp[i][(j * 10 + num) % 13] %= MOD; } } } cout << dp[s.size()][5] << endl; }
// 解説見た #include <bits/stdc++.h> typedef long long lint; using namespace std; #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rrep(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i) const int MOD = 1000000007; int main() { string s; cin >> s; int dp[100001][13] = {0}; dp[0][0] = 1; rrep(i, s.size() + 1) { if (s[i - 1] == '?') { rep(num, 10) { rep(j, 13) { dp[i][(j * 10 + num) % 13] += dp[i - 1][j]; dp[i][(j * 10 + num) % 13] %= MOD; } } } else { int num = s[i - 1] - '0'; rep(j, 13) { dp[i][(j * 10 + num) % 13] += dp[i - 1][j]; dp[i][(j * 10 + num) % 13] %= MOD; } } } cout << dp[s.size()][5] << endl; }
replace
10
11
10
11
0
p02960
C++
Runtime Error
//------------------------------------------ // C++ templete //------------------------------------------ #include <bits/stdc++.h> #include <iomanip> using namespace std; using ll = long long; #define endl "\n" // typedef //------------------------------------------ typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef vector<PII> VP; // REPEAT //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // container util //------------------------------------------ #define pb push_back #define paired make_pair #define ALL(a) (a).begin(), (a).end() #define PRINT(V) \ for (auto v : (V)) \ cout << v << " " #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) // constant //------------------------------------------ const int MOD = 1000000007; const int INF = 1061109567; const double EPS = 1e-10; const double PI = acos(-1.0); int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; // math //------------------------------------------ int QP(int a, int b) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % MOD; a = 1ll * a * a % MOD; } while (b >>= 1); return ans; } int QP(int a, int b, int MOD) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % MOD; a = 1ll * a * a % MOD; } while (b >>= 1); return ans; } int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } // debug //------------------------------------------ #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 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int calc(int k, int i) { // k*10**(i+1)を13でわったあまり int n = i % 6; VI V{10, 9, 12, 3, 4, 1}; int ans = V[n]; ans = ans * k % 13; return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); string S; cin >> S; ll dp[10005][13]; char c = S.back(); int N = S.size(); // initislization REP(i, 13) { dp[0][i] = 0; if (c == '?') { if (i <= 9) dp[0][i] = 1; } else { if (i == c - 48) { dp[0][i] = 1; } } } // update REP(i, N - 1) { c = S[N - 2 - i]; REP(j, 13) { dp[i + 1][j] = 0; if (c == '?') { REP(k, 10) { int num = j - calc(k, i); int index = num >= 0 ? num : 13 + num; dp[i + 1][j] += dp[i][index]; } } else { int num = j - calc((int)c - 48, i); int index = num >= 0 ? num : 13 + num; dp[i + 1][j] += dp[i][index]; } dp[i + 1][j] = dp[i + 1][j] % MOD; } } cout << dp[N - 1][5] << endl; return 0; }
//------------------------------------------ // C++ templete //------------------------------------------ #include <bits/stdc++.h> #include <iomanip> using namespace std; using ll = long long; #define endl "\n" // typedef //------------------------------------------ typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef vector<PII> VP; // REPEAT //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // container util //------------------------------------------ #define pb push_back #define paired make_pair #define ALL(a) (a).begin(), (a).end() #define PRINT(V) \ for (auto v : (V)) \ cout << v << " " #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) // constant //------------------------------------------ const int MOD = 1000000007; const int INF = 1061109567; const double EPS = 1e-10; const double PI = acos(-1.0); int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; // math //------------------------------------------ int QP(int a, int b) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % MOD; a = 1ll * a * a % MOD; } while (b >>= 1); return ans; } int QP(int a, int b, int MOD) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % MOD; a = 1ll * a * a % MOD; } while (b >>= 1); return ans; } int GCD(int a, int b) { return b ? GCD(b, a % b) : a; } // debug //------------------------------------------ #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 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int calc(int k, int i) { // k*10**(i+1)を13でわったあまり int n = i % 6; VI V{10, 9, 12, 3, 4, 1}; int ans = V[n]; ans = ans * k % 13; return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); string S; cin >> S; unsigned long long dp[100050][13]; char c = S.back(); int N = S.size(); // initislization REP(i, 13) { dp[0][i] = 0; if (c == '?') { if (i <= 9) dp[0][i] = 1; } else { if (i == c - 48) { dp[0][i] = 1; } } } // update REP(i, N - 1) { c = S[N - 2 - i]; REP(j, 13) { dp[i + 1][j] = 0; if (c == '?') { REP(k, 10) { int num = j - calc(k, i); int index = num >= 0 ? num : 13 + num; dp[i + 1][j] += dp[i][index]; } } else { int num = j - calc((int)c - 48, i); int index = num >= 0 ? num : 13 + num; dp[i + 1][j] += dp[i][index]; } dp[i + 1][j] = dp[i + 1][j] % MOD; } } cout << dp[N - 1][5] << endl; return 0; }
replace
103
104
103
104
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second const ll MOD = 1000000007; int main() { char temp[10000]; scanf("%s", temp); string s = temp; vector<vector<ll>> dp(s.length(), vector<ll>(13)); if (s[0] == '?') { for (int i = 0; i < 10; ++i) ++dp[0][i]; } else { ++dp[0][s[0] - '0']; } for (int i = 1; i < s.length(); ++i) { if (s[i] == '?') { for (int j = 0; j < 13; ++j) { for (int k = 0; k < 10; ++k) { dp[i][(10 * j + k) % 13] += dp[i - 1][j]; dp[i][(10 * j + k) % 13] %= MOD; } } } else { for (int j = 0; j < 13; ++j) { dp[i][(10 * j + s[i] - '0') % 13] = dp[i - 1][j]; dp[i][(10 * j + s[i] - '0') % 13] %= MOD; } } } printf("%lld", dp[s.length() - 1][5]); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second const ll MOD = 1000000007; int main() { char temp[100000]; scanf("%s", temp); string s = temp; vector<vector<ll>> dp(s.length(), vector<ll>(13)); if (s[0] == '?') { for (int i = 0; i < 10; ++i) ++dp[0][i]; } else { ++dp[0][s[0] - '0']; } for (int i = 1; i < s.length(); ++i) { if (s[i] == '?') { for (int j = 0; j < 13; ++j) { for (int k = 0; k < 10; ++k) { dp[i][(10 * j + k) % 13] += dp[i - 1][j]; dp[i][(10 * j + k) % 13] %= MOD; } } } else { for (int j = 0; j < 13; ++j) { dp[i][(10 * j + s[i] - '0') % 13] = dp[i - 1][j]; dp[i][(10 * j + s[i] - '0') % 13] %= MOD; } } } printf("%lld", dp[s.length() - 1][5]); return 0; }
replace
13
14
13
14
0
p02960
Python
Runtime Error
M = 10**9 + 7 a = [1] + [0] * 12 p = 1 for c in reversed(input()): r = (0, p * 10) if c == "?" else (int(c), int(c) + 1) a = [sum(a[(i - j) % 13] for j in range(*r, p)) % M for i in range(13)] p = p * 10 % 13 print(a[5])
M = 10**9 + 7 a = [1] + [0] * 12 p = 1 for c in reversed(input()): x, y = (0, p * 10) if c == "?" else (p * int(c), p * int(c) + 1) a = [sum(a[(i - j) % 13] for j in range(x, y, p)) % M for i in range(13)] p = p * 10 % 13 print(a[5])
replace
4
6
4
6
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { string s; cin >> s; const int n = 13; vector<vector<ll>> dp(100001, vector<ll>(n)); ll mod = 1000000007; int mul = 1; dp[s.length()][0] = 1; for (int i = s.length() - 1; i >= 0; i--) { if (s[i] == '?') { for (int k = 0; k < 10; k++) { for (int j = 0; j < n; j++) { dp[i][(k * mul + j) % n] += dp[i + 1][j]; dp[i][(k * mul + j) % n] %= mod; } } } else { int k = (int)(s[i] - '0'); for (int j = 0; j < n; j++) { dp[i][(k * mul + j) % n] += dp[i + 1][j]; dp[i][(k * mul + j) % n] %= mod; } } mul *= 10; } cout << dp[0][5] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { string s; cin >> s; const int n = 13; vector<vector<ll>> dp(100001, vector<ll>(n)); ll mod = 1000000007; int mul = 1; dp[s.length()][0] = 1; for (int i = s.length() - 1; i >= 0; i--) { if (s[i] == '?') { for (int k = 0; k < 10; k++) { for (int j = 0; j < n; j++) { dp[i][(k * mul + j) % n] += dp[i + 1][j]; dp[i][(k * mul + j) % n] %= mod; } } } else { int k = (int)(s[i] - '0'); for (int j = 0; j < n; j++) { dp[i][(k * mul + j) % n] += dp[i + 1][j]; dp[i][(k * mul + j) % n] %= mod; } } mul *= 10; mul %= n; } cout << dp[0][5] << endl; return 0; }
insert
33
33
33
34
0
p02960
Python
Runtime Error
M = 10**9 + 7 a = [1] + [0] * 12 p = 1 for c in reversed(input()): r = [x % 13 for x in range(0, p * 10, p)] if c == "?" else (p * int(c),) a = [sum(a[(i - j, i - j + 13)[i < j]] for j in r) % M for i in range(13)] p = p * 10 % 13 print(a[5])
M = 10**9 + 7 a = [1] + [0] * 12 p = 1 for c in reversed(input()): r = [x % 13 for x in range(0, p * 10, p)] if c == "?" else (p * int(c) % 13,) a = [sum(a[(i - j, i - j + 13)[i < j]] for j in r) % M for i in range(13)] p = p * 10 % 13 print(a[5])
replace
4
5
4
5
0
p02960
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <istream> #include <map> #include <random> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <vector> using namespace std; typedef long long int ll; ll MOD = 1000000007; int main() { string S; cin >> S; vector<vector<ll>> dp(S.length() + 1, vector<ll>(13, 0)); dp[0][0] = 1; for (ll i = 0; i <= S.length(); i++) { // 0~9までを入れたとき前からのMODがどう変化するか for (ll j = 0; j < 10; j++) { // ?ではなく数字が書かれているときは数字分の遷移しか考えない if (S[i] != '?' && (S[i] - '0') != j) { continue; } for (ll h = 0; h < 13; h++) { dp[i + 1][(h * 10 + j) % 13] += dp[i][h]; } } // 答えが超えないように割っておく for (ll j = 0; j < 13; j++) { dp[i + 1][j] %= MOD; } } cout << dp[S.length()][5] << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <istream> #include <map> #include <random> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <vector> using namespace std; typedef long long int ll; ll MOD = 1000000007; int main() { string S; cin >> S; vector<vector<ll>> dp(S.length() + 1, vector<ll>(13, 0)); dp[0][0] = 1; for (ll i = 0; i < S.length(); i++) { // 0~9までを入れたとき前からのMODがどう変化するか for (ll j = 0; j < 10; j++) { // ?ではなく数字が書かれているときは数字分の遷移しか考えない if (S[i] != '?' && (S[i] - '0') != j) { continue; } for (ll h = 0; h < 13; h++) { dp[i + 1][(h * 10 + j) % 13] += dp[i][h]; } } // 答えが超えないように割っておく for (ll j = 0; j < 13; j++) { dp[i + 1][j] %= MOD; } } cout << dp[S.length()][5] << endl; }
replace
27
28
27
28
-11
p02960
Python
Time Limit Exceeded
s = input() mod = 1000000007 n = 13 dp = [0] * 13 dp[0] = 1 mul = 1 for i in reversed(range(len(s))): nextDp = [0] * 13 if s[i] == "?": for k in range(10): for j in range(n): nextDp[(k * mul + j) % n] += dp[j] for j in range(n): nextDp[j] %= mod else: k = int(s[i]) for j in range(n): nextDp[(k * mul + j) % n] = dp[j] mul *= 10 mul %= n dp = nextDp print(dp[5] % mod)
s = input() mod = 1000000007 n = 13 dp = [0] * 13 dp[0] = 1 mul = 1 for i in reversed(range(len(s))): nextDp = [0] * 13 if s[i] == "?": for k in range(10): for j in range(n): nextDp[(k * mul + j) % n] += dp[j] for j in range(n): nextDp[j] %= mod else: k = int(s[i]) for j in range(n): nextDp[(k * mul + j) % n] = dp[j] mul *= 10 mul %= n dp = nextDp print(dp[5])
replace
25
26
25
26
TLE
p02960
Python
Time Limit Exceeded
import numpy as np def solve(s): MOD = 10**9 + 7 dp = np.zeros(13, dtype=np.int64) dp[0] = 1 idx = np.zeros(13, dtype=np.int8) for i in range(13): idx[i * 10 % 13] = i window = np.ones(10, dtype=np.int8) for c in s: if c == "?": dp = np.convolve(dp[idx], window) dp[:9] += dp[13:] dp = dp[:13] % MOD else: dp = np.roll(dp[idx], int(c)) return dp[5] s = input() print(solve(s))
import numpy as np def solve(s): MOD = 10**9 + 7 dp = np.zeros(13, dtype=np.int64) dp[0] = 1 idx = np.zeros(13, dtype=np.int8) for i in range(13): idx[i * 10 % 13] = i window = np.ones(10, dtype=np.int8) for c in s: if c == "?": tdp = dp[idx] ndp = np.concatenate([tdp[4:], tdp]) dp = np.convolve(ndp, window, mode="valid") % MOD else: dp = np.roll(dp[idx], int(c)) return dp[5] s = input() print(solve(s))
replace
13
16
13
16
TLE
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> II; typedef vector<II> VII; typedef vector<int> VI; typedef vector<VI> VVI; typedef long long int LL; typedef unsigned long long int ULL; #define PB push_back #define MP make_pair #define F first #define S second #define SZ(a) (int)(a.size()) #define ALL(a) a.begin(), a.end() #define SET(a, b) memset(a, b, sizeof(a)) #define LET(x, a) __typeof(a) x(a) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // Works for forward as well as backward iteration #define gu getchar #define pu putchar #define si(n) scanf("%d", &n) #define dout(n) printf("%d\n", n) #define sll(n) scanf("%lld", &n) #define lldout(n) printf("%lld\n", n) #define DRT() \ int t; \ si(t); \ while (t--) #define PlUSWRAP(index, n) \ index = (index + 1) % n // index++; if(index>=n) index=0 #define MINUSWRAP(index, n) \ index = (index + n - 1) % n // index--; if(index<0) index=n-1 #define ROUNDOFFINT(d) \ d = (int)((double)d + 0.5) // Round off d to nearest integer #define FLUSHN while (gu() != '\n') #define FLUSHS while (gu() != ' ') #define TRACE #ifdef TRACE #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; #else #define trace1(x) #define trace2(x, y) #define trace3(x, y, z) #define trace4(a, b, c, d) #define trace5(a, b, c, d, e) #define trace6(a, b, c, d, e, f) #endif #define off \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) LL mod = (LL)1e9 + 7; LL n; string s; LL mod_mlt(LL x, LL y, LL mod) { LL ret = 0LL; x %= mod; while (y) { if (y & 1LL) { ret += x; ret %= mod; } y >>= 1; x <<= 1; x %= mod; } return ret; } LL mod_pow(LL base, LL exp, LL mod) { LL ret = 1LL; for (; exp;) { if (exp & 1LL) { ret *= base; ret %= mod; } base = (base * base) % mod; exp >>= 1; } return ret; } LL mod_inv(LL x, LL mod) { // available only when mod is prime return mod_pow(x, mod - 2LL, mod); } vector<vector<LL>> dp; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif off; cin >> s; n = s.length(); dp.resize(n + 1, vector<LL>(13, 0)); if (s[0] == '?') { rep(i, 0, 10) dp[0][i] = 1; } else dp[0][s[0] - '0'] = 1; rep(i, 1, n) { if (s[i] != '?') { rep(j, 0, 13) { rep(k, 0, 13) { if ((k * 10 + (s[i] - '0')) % 13 == j) dp[i][j] = (dp[i][j] + dp[i - 1][k]) % mod; } } } else { rep(j, 0, 13) { rep(k, 0, 13) { rep(l, 0, 10) { if ((k * 10 + l) % 13 == j) dp[i][j] = (dp[i][j] + dp[i - 1][k]) % mod; } } } } } cout << dp[n - 1][5]; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> II; typedef vector<II> VII; typedef vector<int> VI; typedef vector<VI> VVI; typedef long long int LL; typedef unsigned long long int ULL; #define PB push_back #define MP make_pair #define F first #define S second #define SZ(a) (int)(a.size()) #define ALL(a) a.begin(), a.end() #define SET(a, b) memset(a, b, sizeof(a)) #define LET(x, a) __typeof(a) x(a) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // Works for forward as well as backward iteration #define gu getchar #define pu putchar #define si(n) scanf("%d", &n) #define dout(n) printf("%d\n", n) #define sll(n) scanf("%lld", &n) #define lldout(n) printf("%lld\n", n) #define DRT() \ int t; \ si(t); \ while (t--) #define PlUSWRAP(index, n) \ index = (index + 1) % n // index++; if(index>=n) index=0 #define MINUSWRAP(index, n) \ index = (index + n - 1) % n // index--; if(index<0) index=n-1 #define ROUNDOFFINT(d) \ d = (int)((double)d + 0.5) // Round off d to nearest integer #define FLUSHN while (gu() != '\n') #define FLUSHS while (gu() != ' ') #define TRACE #ifdef TRACE #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; #else #define trace1(x) #define trace2(x, y) #define trace3(x, y, z) #define trace4(a, b, c, d) #define trace5(a, b, c, d, e) #define trace6(a, b, c, d, e, f) #endif #define off \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) LL mod = (LL)1e9 + 7; LL n; string s; LL mod_mlt(LL x, LL y, LL mod) { LL ret = 0LL; x %= mod; while (y) { if (y & 1LL) { ret += x; ret %= mod; } y >>= 1; x <<= 1; x %= mod; } return ret; } LL mod_pow(LL base, LL exp, LL mod) { LL ret = 1LL; for (; exp;) { if (exp & 1LL) { ret *= base; ret %= mod; } base = (base * base) % mod; exp >>= 1; } return ret; } LL mod_inv(LL x, LL mod) { // available only when mod is prime return mod_pow(x, mod - 2LL, mod); } vector<vector<LL>> dp; int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif off; cin >> s; n = s.length(); dp.resize(n + 1, vector<LL>(13, 0)); if (s[0] == '?') { rep(i, 0, 10) dp[0][i] = 1; } else dp[0][s[0] - '0'] = 1; rep(i, 1, n) { if (s[i] != '?') { rep(j, 0, 13) { rep(k, 0, 13) { if ((k * 10 + (s[i] - '0')) % 13 == j) dp[i][j] = (dp[i][j] + dp[i - 1][k]) % mod; } } } else { rep(j, 0, 13) { rep(k, 0, 13) { rep(l, 0, 10) { if ((k * 10 + l) % 13 == j) dp[i][j] = (dp[i][j] + dp[i - 1][k]) % mod; } } } } } cout << dp[n - 1][5]; return 0; }
replace
122
126
122
126
0
p02960
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; using P = pair<int, int>; ll dp[10001][13]; const ll MOD = (ll)1e9 + 7; void solve() { string s; cin >> s; dp[0][0] = 1; int n = s.size(); s.push_back('0'); reverse(s.begin(), s.end()); ll mul = 1; for (int d = 1; d <= n; d++) { char c = s[d]; if (c == '?') { rep(i, 10) { rep(j, 13) { dp[d][(i * mul + j) % 13] += dp[d - 1][j]; dp[d][(i * mul + j) % 13] %= MOD; } } } else { rep(j, 13) { dp[d][((c - '0') * mul + j) % 13] += dp[d - 1][j]; dp[d][((c - '0') * mul + j) % 13] %= MOD; } } mul *= 10; mul %= 13; } cout << dp[n][5] << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; ll dp[100005][13]; const ll MOD = (ll)1e9 + 7; void solve() { string s; cin >> s; dp[0][0] = 1; int n = s.size(); s.push_back('0'); reverse(s.begin(), s.end()); ll mul = 1; for (int d = 1; d <= n; d++) { char c = s[d]; if (c == '?') { rep(i, 10) { rep(j, 13) { dp[d][(i * mul + j) % 13] += dp[d - 1][j]; dp[d][(i * mul + j) % 13] %= MOD; } } } else { rep(j, 13) { dp[d][((c - '0') * mul + j) % 13] += dp[d - 1][j]; dp[d][((c - '0') * mul + j) % 13] %= MOD; } } mul *= 10; mul %= 13; } cout << dp[n][5] << endl; } int main() { solve(); return 0; }
replace
6
7
6
7
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); #define FOR(i, s, n) for (int i = s; i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define ALL(n) (n).begin(), (n).end() #define RALL(n) (n).rbegin(), (n).rend() using ll = long long; using ull = unsigned long long; constexpr int MOD = 1000000007; int mod(ll x) { return x > 0 ? x % MOD : (x + MOD) % MOD; } int modm(ll x, ll m) { return x * m % MOD; } int modpow(ll x, ll p) { int ret = 1; while (p > 0) { if (p & 1) ret = modm(ret, x); x = modm(x, x); p >>= 1; } return ret; } // x * modinv(d) int modd(ll x, ll d) { return modm(x, modpow(d, MOD - 2)); } int main(void) { IOS constexpr int N = 1e4; constexpr int M = 13; string s; cin >> s; int l = s.size(); vector<vector<int>> dp(l, vector<int>(M, 0)); dp[0][0] = 1; REP(i, l) { REP(j, M) { REP(k, 10) { if (s[i] - '0' == k || s[i] == '?') { dp[i + 1][(j * 10 + k) % M] = mod(0LL + dp[i + 1][(j * 10 + k) % M] + dp[i][j]); } } } } cout << dp[l][5] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); #define FOR(i, s, n) for (int i = s; i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define ALL(n) (n).begin(), (n).end() #define RALL(n) (n).rbegin(), (n).rend() using ll = long long; using ull = unsigned long long; constexpr int MOD = 1000000007; int mod(ll x) { return x > 0 ? x % MOD : (x + MOD) % MOD; } int modm(ll x, ll m) { return x * m % MOD; } int modpow(ll x, ll p) { int ret = 1; while (p > 0) { if (p & 1) ret = modm(ret, x); x = modm(x, x); p >>= 1; } return ret; } // x * modinv(d) int modd(ll x, ll d) { return modm(x, modpow(d, MOD - 2)); } int main(void) { IOS constexpr int N = 1e4; constexpr int M = 13; string s; cin >> s; int l = s.size(); vector<vector<int>> dp(l + 1, vector<int>(M, 0)); dp[0][0] = 1; REP(i, l) { REP(j, M) { REP(k, 10) { if (s[i] - '0' == k || s[i] == '?') { dp[i + 1][(j * 10 + k) % M] = mod(0LL + dp[i + 1][(j * 10 + k) % M] + dp[i][j]); } } } } cout << dp[l][5] << endl; return 0; }
replace
38
39
38
39
-11
p02960
C++
Runtime Error
#include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; ll mod = 1000000007; string S; vector<vector<ll>> dp(10005, vector<ll>(13, 0)); int main() { cin >> S; int N = (int)S.size(); for (int i = 0; i < N; i++) { char c = (char)S[i]; int t = c - '0'; if (c == '?') t = -1; dp[0][0] = 1; for (int j = 0; j < 10; j++) { if (t != -1 && t != j) continue; for (int k = 0; k < 13; k++) { dp[i + 1][(k * 10 + j) % 13] += dp[i][k]; } } for (int j = 0; j < 13; j++) { dp[i + 1][j] %= mod; } } cout << dp[N][5] << endl; return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; ll mod = 1000000007; string S; vector<vector<ll>> dp(100005, vector<ll>(13, 0)); int main() { cin >> S; int N = (int)S.size(); for (int i = 0; i < N; i++) { char c = (char)S[i]; int t = c - '0'; if (c == '?') t = -1; dp[0][0] = 1; for (int j = 0; j < 10; j++) { if (t != -1 && t != j) continue; for (int k = 0; k < 13; k++) { dp[i + 1][(k * 10 + j) % 13] += dp[i][k]; } } for (int j = 0; j < 13; j++) { dp[i + 1][j] %= mod; } } cout << dp[N][5] << endl; return 0; }
replace
8
9
8
9
0
p02960
Python
Runtime Error
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**7) # Override `input` function because `stdin.readline()` is 10x faster than built-in `input()` input = sys.stdin.readline def read_h(typ=int): return list(map(typ, input().split())) def read_v(n, m=1, typ=int): return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)] def main(): (S,) = read_h(typ=str) n = len(S) MOD = 10**9 + 7 dp = [[0] * 13 for _ in range(10**5)] dp[0][0] = 1 # print('initial dp:', dp) for i, s in enumerate(S): c = -1 if s == "?" else ord(s) - ord("0") # print('c:', c) for j in range(10): if c != -1 and c != j: continue for k in range(13): dp[i + 1][(k * 10 + j) % 13] += dp[i][k] # print('updated dp:', dp[:]) for j in range(13): dp[i + 1][j] %= MOD # print('final dp:', dp[:]) res = dp[n][5] print(res) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**7) # Override `input` function because `stdin.readline()` is 10x faster than built-in `input()` input = sys.stdin.readline def read_h(typ=int): return list(map(typ, input().split())) def read_v(n, m=1, typ=int): return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)] def main(): (S,) = read_h(typ=str) n = len(S) MOD = 10**9 + 7 dp = [[0] * 13 for _ in range(10**5 + 2)] dp[0][0] = 1 # print('initial dp:', dp) for i, s in enumerate(S): c = -1 if s == "?" else ord(s) - ord("0") # print('c:', c) for j in range(10): if c != -1 and c != j: continue for k in range(13): dp[i + 1][(k * 10 + j) % 13] += dp[i][k] # print('updated dp:', dp[:]) for j in range(13): dp[i + 1][j] %= MOD # print('final dp:', dp[:]) res = dp[n][5] print(res) if __name__ == "__main__": main()
replace
24
25
24
25
0
p02960
Python
Runtime Error
import itertools S = input()[::-1] mod = 10**9 + 7 A = [0] * 13 N = 0 for i, v in enumerate(S): p = pow(10, i, 13) if v == "?": A[p] += 1 else: N += int(v) * p N %= 13 dp = [0] * 13 dp[N] = 1 for i, v in enumerate(A): for _ in range(v): dp_old = dp.copy() for j, k in itertools.product(range(1, 10), range(13)): x = (j * i + k) % 13 dp[x] += dp_old[k] dp[x] %= mod print(dp[5])
import itertools S = input()[::-1] mod = 10**9 + 7 A = [0] * 13 N = 0 for i, v in enumerate(S): p = pow(10, i, 13) if v == "?": A[p] += 1 else: N += int(v) * p N %= 13 dp = [0] * 13 dp[N] = 1 for i, v in enumerate(A): for _ in range(v): dp_old = dp[:] for j, k in itertools.product(range(1, 10), range(13)): x = (j * i + k) % 13 dp[x] += dp_old[k] dp[x] %= mod print(dp[5])
replace
17
18
17
18
0
p02960
Python
Time Limit Exceeded
def main(): MOD = 10**9 + 7 S = input() N = len(S) dp = [[0 for _ in range(13)] for _ in range(N + 1)] dp[0][0] = 1 for i, c in enumerate(S): for j in range(10): if c != "?" and c != str(j): continue for k in range(13): dp[i + 1][(10 * k + j) % 13] += dp[i][k] dp[i + 1][(10 * k + j) % 13] %= MOD print(dp[N][5]) if __name__ == "__main__": main()
def main(): MOD = 10**9 + 7 S = input() N = len(S) dp = [[0 for _ in range(13)] for _ in range(N + 1)] dp[0][0] = 1 for i, c in enumerate(S): for j in range(10): if c != "?" and c != str(j): continue for k in range(13): dp[i + 1][(10 * k + j) % 13] += dp[i][k] for k in range(13): dp[i + 1][k] %= MOD print(dp[N][5]) if __name__ == "__main__": main()
replace
12
13
12
14
TLE
p02960
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <vector> #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define REPx(x, a) for (auto x : a) #define ALL(a) a.begin(), a.end() #define SORT(a) sort(ALL(a)) #define SORTG(a) sort(ALL(a), greater<int>()) #define REVERSE(a) reverse(ALL(a)) #define bit_search(bit, n) REP(bit, 1 << n) #define bit_check(bit, i) (bit >> i) & 1 #define setpre(n) fixed << setprecision(n) #define ENDL cout << endl; using namespace std; using ll = long long; using PII = pair<int, int>; using VP = vector<PII>; using VI = vector<int>; using VVI = vector<VI>; using Vll = vector<ll>; using VVll = vector<Vll>; using VC = vector<char>; using VS = vector<string>; using VB = vector<bool>; const int INF = 1e9; const ll mod = 1e9 + 7; int POW(ll a, ll b, ll m) { ll res = 1; REP(i, (int)b) { res *= a; res %= m; } return (int)res; } int main() { string S; cin >> S; ll len = S.size(); VVll dp(len, Vll(13, 0)); REPR(i, len) { if (i == len - 1) { if (S.at(i) != '?') { REP(j, 13) if (S.at(i) - '0' == j) dp.at(i).at(j) = 1; } else REP(j, 10) dp.at(i).at(j) = 1; continue; } REP(j, 13) { if (S.at(i) == '?') { REP(s_i, 10) { dp.at(i).at(j) += dp.at(i + 1).at( (13 + j - ((s_i * POW(10, len - i - 1, 13)) % 13)) % 13); dp.at(i).at(j) %= mod; } } else { dp.at(i).at(j) += dp.at(i + 1).at( (13 + j - (((S.at(i) - '0') * POW(10, len - i - 1, 13)) % 13)) % 13); dp.at(i).at(j) %= mod; } } } cout << dp.at(0).at(5) << endl; return 0; }
#include <bits/stdc++.h> #include <vector> #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define REPx(x, a) for (auto x : a) #define ALL(a) a.begin(), a.end() #define SORT(a) sort(ALL(a)) #define SORTG(a) sort(ALL(a), greater<int>()) #define REVERSE(a) reverse(ALL(a)) #define bit_search(bit, n) REP(bit, 1 << n) #define bit_check(bit, i) (bit >> i) & 1 #define setpre(n) fixed << setprecision(n) #define ENDL cout << endl; using namespace std; using ll = long long; using PII = pair<int, int>; using VP = vector<PII>; using VI = vector<int>; using VVI = vector<VI>; using Vll = vector<ll>; using VVll = vector<Vll>; using VC = vector<char>; using VS = vector<string>; using VB = vector<bool>; const int INF = 1e9; const ll mod = 1e9 + 7; int POW(ll a, ll b, ll m) { ll res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return (int)res; } int main() { string S; cin >> S; ll len = S.size(); VVll dp(len, Vll(13, 0)); REPR(i, len) { if (i == len - 1) { if (S.at(i) != '?') { REP(j, 13) if (S.at(i) - '0' == j) dp.at(i).at(j) = 1; } else REP(j, 10) dp.at(i).at(j) = 1; continue; } REP(j, 13) { if (S.at(i) == '?') { REP(s_i, 10) { dp.at(i).at(j) += dp.at(i + 1).at( (13 + j - ((s_i * POW(10, len - i - 1, 13)) % 13)) % 13); dp.at(i).at(j) %= mod; } } else { dp.at(i).at(j) += dp.at(i + 1).at( (13 + j - (((S.at(i) - '0') * POW(10, len - i - 1, 13)) % 13)) % 13); dp.at(i).at(j) %= mod; } } } cout << dp.at(0).at(5) << endl; return 0; }
replace
29
32
29
34
TLE
p02960
C++
Runtime Error
#include <bits/stdc++.h> #include <numeric> #include <vector> #define PI 3.14159265358979323846 #define MAXINF (1e18L) #define INF (1e9L) #define EPS (1e-9) #define MOD ((ll)(1e9 + 7)) #define REP(i, n) for (int i = 0; i < int(n); ++i) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i) #define ALL(v) v.begin(), v.end() #define FIND(v, x) (binary_search(ALL(v), (x))) #define SORT(v) sort(ALL(v)) #define RSORT(v) \ sort(ALL(v)); \ reverse(ALL(v)) #define DEBUG(x) cerr << #x << ": " << x << endl; #define DEBUG_VEC(v) \ cerr << #v << ":"; \ for (int i = 0; i < v.size(); i++) \ cerr << " " << v[i]; \ cerr << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define pb push_back #define fi first #define se second using namespace std; template <class A> void pr(A a) { cout << (a) << endl; } template <class A, class B> void pr(A a, B b) { cout << a << " "; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << " "; pr(b, c); } template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) { cout << a << " "; pr(b, c, d); } template <class T> inline bool chmin(T &a, T b) { return a > b ? a = b, true : false; } template <class T> inline bool chmax(T &a, T b) { return a < b ? a = b, true : false; } typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main(void) { string S; cin >> S; int N = S.size(); vector<vector<ll>> dp(N + 1, vector<ll>(13, 0)); dp[N][0] = 1; int mul = 1; RREP(i, N) { int c; if (S[i] == '?') c = -1; else c = S[i] - '0'; REP(j, 10) { if (c != -1 && c != j) continue; REP(k, 13) { (dp[i][(j * mul + k) % 13] += dp[i + 1][k]) %= MOD; } } mul *= 10; mul %= MOD; } pr(dp[0][5]); }
#include <bits/stdc++.h> #include <numeric> #include <vector> #define PI 3.14159265358979323846 #define MAXINF (1e18L) #define INF (1e9L) #define EPS (1e-9) #define MOD ((ll)(1e9 + 7)) #define REP(i, n) for (int i = 0; i < int(n); ++i) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i) #define ALL(v) v.begin(), v.end() #define FIND(v, x) (binary_search(ALL(v), (x))) #define SORT(v) sort(ALL(v)) #define RSORT(v) \ sort(ALL(v)); \ reverse(ALL(v)) #define DEBUG(x) cerr << #x << ": " << x << endl; #define DEBUG_VEC(v) \ cerr << #v << ":"; \ for (int i = 0; i < v.size(); i++) \ cerr << " " << v[i]; \ cerr << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define pb push_back #define fi first #define se second using namespace std; template <class A> void pr(A a) { cout << (a) << endl; } template <class A, class B> void pr(A a, B b) { cout << a << " "; pr(b); } template <class A, class B, class C> void pr(A a, B b, C c) { cout << a << " "; pr(b, c); } template <class A, class B, class C, class D> void pr(A a, B b, C c, D d) { cout << a << " "; pr(b, c, d); } template <class T> inline bool chmin(T &a, T b) { return a > b ? a = b, true : false; } template <class T> inline bool chmax(T &a, T b) { return a < b ? a = b, true : false; } typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main(void) { string S; cin >> S; int N = S.size(); vector<vector<ll>> dp(N + 1, vector<ll>(13, 0)); dp[N][0] = 1; int mul = 1; RREP(i, N) { int c; if (S[i] == '?') c = -1; else c = S[i] - '0'; REP(j, 10) { if (c != -1 && c != j) continue; REP(k, 13) { (dp[i][(j * mul + k) % 13] += dp[i + 1][k]) %= MOD; } } mul *= 10; mul %= 13; } pr(dp[0][5]); }
replace
71
72
71
72
0
p02960
Python
Time Limit Exceeded
# import sys # fin = sys.stdin.readline MOD = 10**9 + 7 S = input()[::-1] dp = [[0] * 13 for _ in range(len(S) + 1)] dp[0][0] = 1 for i, c in enumerate(S, start=1): base = 10 ** (i - 1) % 13 if c != "?": d = int(c) * base % 13 for r in range(13): c = (d + r) % 13 dp[i][c] += dp[i - 1][r] dp[i][c] %= MOD else: for d in range(10): d = d * base % 13 for r in range(13): c = (d + r) % 13 dp[i][c] += dp[i - 1][r] dp[i][c] %= MOD print(dp[-1][5])
# import sys # fin = sys.stdin.readline MOD = 10**9 + 7 S = input()[::-1] dp = [[0] * 13 for _ in range(len(S) + 1)] dp[0][0] = 1 for i, c in enumerate(S, start=1): base = pow(10, i - 1, 13) if c != "?": d = int(c) * base % 13 for r in range(13): c = (d + r) % 13 dp[i][c] += dp[i - 1][r] dp[i][c] %= MOD else: for d in range(10): d = d * base % 13 for r in range(13): c = (d + r) % 13 dp[i][c] += dp[i - 1][r] dp[i][c] %= MOD print(dp[-1][5])
replace
9
10
9
10
TLE
p02960
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define srep(i, from, to) for (int i = from; i < (int)(to); i++) const ll LINF = 1001002003004005006ll; const int INF = 1001001001; int main() { string s; cin >> s; int MOD = 1000000007; int N = 13; int len = s.length(); int mul = 1; vvi dp(N, vi(len + 1, 0)); dp[0][0] = 1; reverse(s.begin(), s.end()); srep(i, 1, len + 1) { char c = s[i - 1]; if (c == '?') { rep(k, 10) { rep(x, N) { int am = (x + k * mul) % N; dp[am][i] += dp[x][i - 1]; dp[am][i] %= MOD; } } } else { int k = c - '0'; rep(x, N) { int am = (x + k * mul) % N; dp[am][i] += dp[x][i - 1]; dp[am][i] %= MOD; } } mul *= 10; } int ans = dp[5][len]; cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define srep(i, from, to) for (int i = from; i < (int)(to); i++) const ll LINF = 1001002003004005006ll; const int INF = 1001001001; int main() { string s; cin >> s; int MOD = 1000000007; int N = 13; int len = s.length(); int mul = 1; vvi dp(N, vi(len + 1, 0)); dp[0][0] = 1; reverse(s.begin(), s.end()); srep(i, 1, len + 1) { char c = s[i - 1]; if (c == '?') { rep(k, 10) { rep(x, N) { int am = (x + k * mul) % N; dp[am][i] += dp[x][i - 1]; dp[am][i] %= MOD; } } } else { int k = c - '0'; rep(x, N) { int am = (x + k * mul) % N; dp[am][i] += dp[x][i - 1]; dp[am][i] %= MOD; } } mul *= 10; mul %= N; } int ans = dp[5][len]; cout << ans << endl; return 0; }
insert
49
49
49
50
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, a, b) for (int i = a; i < (int)b; ++i) typedef long long ll; const int Inf = 1e9 + 7; const double EPS = 1e-9; const int n = 13; int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } int lcm(int a, int b) { return a * b / gcd(a, b); } int bitCount(long bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int len = s.size(); int dp[len][n]; rep(i, len) { rep(j, n) dp[i][j] = 0; } dp[0][0] = 1; int mal = 1; for (int i = len - 1; i >= 0; --i) { int index = len - i; if (s[i] == '?') { rep(j, n) { rep(k, 10) { dp[index][(j + k * mal) % n] += dp[index - 1][j]; dp[index][(j + k * mal) % n] %= Inf; } } } else { int num = s[i] - '0'; rep(j, n) { dp[index][(j + num * mal) % n] += dp[index - 1][j]; dp[index][(j + num * mal) % n] %= Inf; } } mal *= 10; mal %= n; } cout << dp[len][5] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, a, b) for (int i = a; i < (int)b; ++i) typedef long long ll; const int Inf = 1e9 + 7; const double EPS = 1e-9; const int n = 13; int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } int lcm(int a, int b) { return a * b / gcd(a, b); } int bitCount(long bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int len = s.size(); int dp[len + 1][n]; rep(i, len + 1) { rep(j, n) dp[i][j] = 0; } dp[0][0] = 1; int mal = 1; for (int i = len - 1; i >= 0; --i) { int index = len - i; if (s[i] == '?') { rep(j, n) { rep(k, 10) { dp[index][(j + k * mal) % n] += dp[index - 1][j]; dp[index][(j + k * mal) % n] %= Inf; } } } else { int num = s[i] - '0'; rep(j, n) { dp[index][(j + num * mal) % n] += dp[index - 1][j]; dp[index][(j + num * mal) % n] %= Inf; } } mal *= 10; mal %= n; } cout << dp[len][5] << endl; return 0; }
replace
37
39
37
39
-11
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; string s; ll dp[10005][15]; int main() { ios::sync_with_stdio(false); cin >> s; int n = s.length(); s = "*" + s; dp[0][0] = 1; for (int i = 1; i <= n; i++) { if (s[i] == '?') { for (int j = 0; j < 13; j++) { for (int k = 0; k <= 9; k++) { (dp[i][(j * 10 + k) % 13] += dp[i - 1][j]) %= mod; } } } else { int p = s[i] - '0'; for (int j = 0; j < 13; j++) { dp[i][(j * 10 + p) % 13] = dp[i - 1][j]; } } } cout << dp[n][5] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; string s; ll dp[100005][15]; int main() { ios::sync_with_stdio(false); cin >> s; int n = s.length(); s = "*" + s; dp[0][0] = 1; for (int i = 1; i <= n; i++) { if (s[i] == '?') { for (int j = 0; j < 13; j++) { for (int k = 0; k <= 9; k++) { (dp[i][(j * 10 + k) % 13] += dp[i - 1][j]) %= mod; } } } else { int p = s[i] - '0'; for (int j = 0; j < 13; j++) { dp[i][(j * 10 + p) % 13] = dp[i - 1][j]; } } } cout << dp[n][5] << endl; }
replace
5
6
5
6
0
p02960
C++
Time Limit Exceeded
#include <bits/stdc++.h> #ifdef _DEBUG #define debug(x) \ cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x \ << " = " << x << endl #else #define debug(x) #endif #define all(s) begin(s), end(s) #define rall(s) rbegin(s), rend(s) #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--) #define pb push_back #define sz(a) int((a).size()) using namespace std; using ll = long long; using ull = unsigned long long; using i_i = pair<int, int>; using ll_ll = pair<ll, ll>; using d_ll = pair<double, ll>; using ll_d = pair<ll, double>; using d_d = pair<double, double>; static constexpr ll LL_INF = 1LL << 60; static constexpr int I_INF = 1 << 28; static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288); static constexpr double EPS = numeric_limits<double>::epsilon(); static constexpr ll MOD = 1000000007; static map<type_index, const char *const> scanType = {{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}}; template <class T> static void scan(vector<T> &v); [[maybe_unused]] static void scan(vector<string> &v, bool isWord = true); template <class T> static inline bool chmax(T &a, T b); template <class T> static inline bool chmin(T &a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); ll dp[100010][13]; int main(int argc, char *argv[]) { std::string s; std::cin >> s; dp[0][0] = 1; rep(i, 0, sz(s)) rep(m, 0, 13) { int first = (s[i] == '?' ? 0 : s[i] - '0'); int last = (s[i] == '?' ? 10 : first + 1); rep(j, first, last) { int next_m = stoll(to_string(m) + char('0' + j)) % 13; dp[i + 1][next_m] += dp[i][m]; dp[i + 1][next_m] %= MOD; } } cout << dp[sz(s)][5] << endl; return 0; } template <class T> static void scan(vector<T> &v) { auto tFormat = scanType[typeid(T)]; for (T &n : v) { scanf(tFormat, &n); } } static void scan(vector<string> &v, bool isWord) { if (isWord) { for (auto &n : v) { cin >> n; } return; } int i = 0, size = v.size(); string s; getline(cin, s); if (s.size() != 0) { i++; v[0] = s; } for (; i < size; ++i) { getline(cin, v[i]); } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); }
#include <bits/stdc++.h> #ifdef _DEBUG #define debug(x) \ cerr << "line: " << __LINE__ << ", func: " << __func__ << " -> " << #x \ << " = " << x << endl #else #define debug(x) #endif #define all(s) begin(s), end(s) #define rall(s) rbegin(s), rend(s) #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--) #define pb push_back #define sz(a) int((a).size()) using namespace std; using ll = long long; using ull = unsigned long long; using i_i = pair<int, int>; using ll_ll = pair<ll, ll>; using d_ll = pair<double, ll>; using ll_d = pair<ll, double>; using d_d = pair<double, double>; static constexpr ll LL_INF = 1LL << 60; static constexpr int I_INF = 1 << 28; static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288); static constexpr double EPS = numeric_limits<double>::epsilon(); static constexpr ll MOD = 1000000007; static map<type_index, const char *const> scanType = {{typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}}; template <class T> static void scan(vector<T> &v); [[maybe_unused]] static void scan(vector<string> &v, bool isWord = true); template <class T> static inline bool chmax(T &a, T b); template <class T> static inline bool chmin(T &a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); ll dp[100010][13]; int main(int argc, char *argv[]) { std::string s; std::cin >> s; dp[0][0] = 1; rep(i, 0, sz(s)) rep(m, 0, 13) { int first = (s[i] == '?' ? 0 : s[i] - '0'); int last = (s[i] == '?' ? 10 : first + 1); rep(j, first, last) { int next_m = ((m * 10) + j) % 13; dp[i + 1][next_m] = (dp[i + 1][next_m] + dp[i][m]) % MOD; } } cout << dp[sz(s)][5] << endl; return 0; } template <class T> static void scan(vector<T> &v) { auto tFormat = scanType[typeid(T)]; for (T &n : v) { scanf(tFormat, &n); } } static void scan(vector<string> &v, bool isWord) { if (isWord) { for (auto &n : v) { cin >> n; } return; } int i = 0, size = v.size(); string s; getline(cin, s); if (s.size() != 0) { i++; v[0] = s; } for (; i < size; ++i) { getline(cin, v[i]); } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); }
replace
57
60
57
59
TLE
p02960
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using ll = long long; using namespace std; ll MOD = 1000000000 + 7; ll c[100050][13]; int initCount() { for (ll yi = 0; yi < 100050; yi++) { for (ll xi = 0; xi < 13; xi++) { c[yi][xi] = -1; } } } ll solve(ll y, ll x, string s) { if (c[y][x] != -1) { return c[y][x]; } if (s[y] != '?') { // 全部の値を更新 int tmp = s[y] - '0'; for (ll xi = 0; xi < 13; xi++) { c[y][(xi * 10 + tmp) % 13] = solve(y - 1, xi, s) % MOD; } return c[y][x]; } // はてなの時の処理 for (int tmp = 0; tmp < 10; tmp++) { for (ll xi = 0; xi < 13; xi++) { if (tmp == 0) { c[y][(xi * 10 + tmp) % 13] = solve(y - 1, xi, s) % MOD; } else { c[y][(xi * 10 + tmp) % 13] += solve(y - 1, xi, s) % MOD; } } } return c[y][x]; } int main() { string s; cin >> s; initCount(); for (ll xi = 0; xi < 13; xi++) { c[0][xi] = 0; } if (s[0] != '?') { c[0][s[0] - '0'] = 1; } else { for (int i = 0; i < 10; i++) { c[0][i] = 1; } } ll ans = solve(s.size() - 1, 5, s) % MOD; cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using ll = long long; using namespace std; ll MOD = 1000000000 + 7; ll c[100050][13]; int initCount() { for (ll yi = 0; yi < 100050; yi++) { for (ll xi = 0; xi < 13; xi++) { c[yi][xi] = -1; } } } ll solve(ll y, ll x, string &s) { if (c[y][x] != -1) { return c[y][x]; } if (s[y] != '?') { // 全部の値を更新 int tmp = s[y] - '0'; for (ll xi = 0; xi < 13; xi++) { c[y][(xi * 10 + tmp) % 13] = solve(y - 1, xi, s) % MOD; } return c[y][x]; } // はてなの時の処理 for (int tmp = 0; tmp < 10; tmp++) { for (ll xi = 0; xi < 13; xi++) { if (tmp == 0) { c[y][(xi * 10 + tmp) % 13] = solve(y - 1, xi, s) % MOD; } else { c[y][(xi * 10 + tmp) % 13] += solve(y - 1, xi, s) % MOD; } } } return c[y][x]; } int main() { string s; cin >> s; initCount(); for (ll xi = 0; xi < 13; xi++) { c[0][xi] = 0; } if (s[0] != '?') { c[0][s[0] - '0'] = 1; } else { for (int i = 0; i < 10; i++) { c[0][i] = 1; } } ll ans = solve(s.size() - 1, 5, s) % MOD; cout << ans << endl; }
replace
20
21
20
21
TLE
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; int main() { vector<vector<ll>> dp(100000, vector<ll>(13)); int l, i, j, k; string S; cin >> S; l = S.size(); dp.at(0).at(0) = 1; for (i = 0; i < l; i++) { int c; if (S.at(i) == '?') c = -1; else c = S.at(i) - '0'; for (j = 0; j < 10; j++) if (c == -1 || c == j) for (k = 0; k < 13; k++) dp.at(i + 1).at((k * 10 + j) % 13) += dp.at(i).at(k); for (j = 0; j < 13; j++) dp.at(i + 1).at(j) %= mod; } cout << dp.at(l).at(5) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; int main() { vector<vector<ll>> dp(100005, vector<ll>(13, 0)); int l, i, j, k; string S; cin >> S; l = S.size(); dp.at(0).at(0) = 1; for (i = 0; i < l; i++) { int c; if (S.at(i) == '?') c = -1; else c = S.at(i) - '0'; for (j = 0; j < 10; j++) if (c == -1 || c == j) for (k = 0; k < 13; k++) dp.at(i + 1).at((k * 10 + j) % 13) += dp.at(i).at(k); for (j = 0; j < 13; j++) dp.at(i + 1).at(j) %= mod; } cout << dp.at(l).at(5) << endl; }
replace
6
7
6
7
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, o, n) for (long long i = o; i < n; i++) #define oneforall \ ios::sync_with_stdio(false); \ cin.tie(0); #define all(v) (v).begin(), (v).end() #define ini(...) \ int __VA_ARGS__; \ in(__VA_ARGS__) #define inl(...) \ long long __VA_ARGS__; \ in(__VA_ARGS__) #define ins(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define int long long const long long inf = 1e18; void in() {} template <typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template <typename T, class... U> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << " "; out(u...); } typedef vector<int> vi; typedef vector<long long> vl; typedef long long ll; typedef vector<pair<long, long>> vpll; typedef vector<pair<int, int>> vpii; #define FORR(x, arr) for (auto &x : arr) #define ZERO(a) memset(a, 0, sizeof(a)) // 3111111111111111111111111111111 int dp[10031][13]; int mo = 1e9 + 7; void solve() { ins(morty); dp[0][0] = 1; FOR(i, 0, morty.size()) { FOR(o, 0, 10) { if (morty[i] != '?' and morty[i] != ('0' + o)) continue; FOR(p, 0, 13) { dp[i + 1][(p * 10 + o) % 13] += dp[i][p]; dp[i + 1][(p * 10 + o) % 13] %= mo; } } } out(dp[morty.size()][5]); } int32_t main() { oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, o, n) for (long long i = o; i < n; i++) #define oneforall \ ios::sync_with_stdio(false); \ cin.tie(0); #define all(v) (v).begin(), (v).end() #define ini(...) \ int __VA_ARGS__; \ in(__VA_ARGS__) #define inl(...) \ long long __VA_ARGS__; \ in(__VA_ARGS__) #define ins(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define int long long const long long inf = 1e18; void in() {} template <typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template <typename T, class... U> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << " "; out(u...); } typedef vector<int> vi; typedef vector<long long> vl; typedef long long ll; typedef vector<pair<long, long>> vpll; typedef vector<pair<int, int>> vpii; #define FORR(x, arr) for (auto &x : arr) #define ZERO(a) memset(a, 0, sizeof(a)) // 3111111111111111111111111111111 int dp[100031][13]; int mo = 1e9 + 7; void solve() { ins(morty); dp[0][0] = 1; FOR(i, 0, morty.size()) { FOR(o, 0, 10) { if (morty[i] != '?' and morty[i] != ('0' + o)) continue; FOR(p, 0, 13) { dp[i + 1][(p * 10 + o) % 13] += dp[i][p]; dp[i + 1][(p * 10 + o) % 13] %= mo; } } } out(dp[morty.size()][5]); } int32_t main() { oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall solve(); return 0; }
replace
39
40
39
40
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int m = 1e9 + 7; vector<int> v; int p[7] = {1, 10, 100, 1000, 10000, 100000, 1000000}; int a[100000][13], r; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == '?') v.push_back(s.size() - i - 1); else { r = (r + (s[i] - '0') * p[(s.size() - i - 1) % 6]) % 13; } } r = (18 - r) % 13; a[0][0] = 1; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < 13; j++) for (int k = 0; k < 10; k++) { a[i + 1][(j + k * p[v[i] % 6]) % 13] += a[i][j]; a[i + 1][(j + k * p[v[i] % 6]) % 13] %= m; } } cout << a[v.size()][r] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int m = 1e9 + 7; vector<int> v; int p[7] = {1, 10, 100, 1000, 10000, 100000, 1000000}; int a[100001][13], r; int main() { string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == '?') v.push_back(s.size() - i - 1); else { r = (r + (s[i] - '0') * p[(s.size() - i - 1) % 6]) % 13; } } r = (18 - r) % 13; a[0][0] = 1; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < 13; j++) for (int k = 0; k < 10; k++) { a[i + 1][(j + k * p[v[i] % 6]) % 13] += a[i][j]; a[i + 1][(j + k * p[v[i] % 6]) % 13] %= m; } } cout << a[v.size()][r] << endl; return 0; }
replace
5
6
5
6
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define inf INT_MAX #define INF LLONG_MAX #define ll long long #define ull unsigned long long #define M (int)(1e9 + 7) #define P pair<int, int> #define PLL pair<ll, ll> #define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++) #define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, n, 0) #define all(a) a.begin(), a.end() #define IN(a, n) \ rep(i, n) { cin >> a[i]; } const int vx[4] = {0, 1, 0, -1}; const int vy[4] = {1, 0, -1, 0}; #define PI 3.14159265 #define F first #define S second #define PB push_back #define EB emplace_back #define int ll #define vi vector<int> #define IP pair<int, P> #define PP pair<P, P> string s; int dp[10010][20]; signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cin >> s; dp[0][0] = 1; rep(i, s.size()) { int c; if (s[i] == '?') c = -1; else c = s[i] - '0'; rep(j, 13) { rep(k, 10) { if (c != -1 && c != k) continue; dp[i + 1][(10 * j + k) % 13] += dp[i][j]; dp[i + 1][(10 * j + k) % 13] %= M; } } } cout << dp[s.size()][5] << endl; }
#include <bits/stdc++.h> using namespace std; #define inf INT_MAX #define INF LLONG_MAX #define ll long long #define ull unsigned long long #define M (int)(1e9 + 7) #define P pair<int, int> #define PLL pair<ll, ll> #define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++) #define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, n, 0) #define all(a) a.begin(), a.end() #define IN(a, n) \ rep(i, n) { cin >> a[i]; } const int vx[4] = {0, 1, 0, -1}; const int vy[4] = {1, 0, -1, 0}; #define PI 3.14159265 #define F first #define S second #define PB push_back #define EB emplace_back #define int ll #define vi vector<int> #define IP pair<int, P> #define PP pair<P, P> string s; int dp[100100][20]; signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cin >> s; dp[0][0] = 1; rep(i, s.size()) { int c; if (s[i] == '?') c = -1; else c = s[i] - '0'; rep(j, 13) { rep(k, 10) { if (c != -1 && c != k) continue; dp[i + 1][(10 * j + k) % 13] += dp[i][j]; dp[i + 1][(10 * j + k) % 13] %= M; } } } cout << dp[s.size()][5] << endl; }
replace
30
31
30
31
0
p02960
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> using namespace std; const int MOD = 1000000007; long long int POW(int n, int k, int m) { long long int r; if (k == 0) return 1; r = POW(n, k / 2, m) % m; r = (r * r) % m; if (k % 2) r = (n * r) % m; return r; } int main() { int N, ans[10000][13] = {0}, n, sur, pre; string S; cin >> S; N = S.length(); for (int i = 0; i < N; i++) { sur = POW(10, N - i - 1, 13); if (S[i] == '?') { if (i >= 1) { for (int j = 0; j < 13; j++) { for (int k = 0; k < 10; k++) { pre = (sur * k) % 13; ans[i][(j + pre) % 13] += ans[i - 1][j]; ans[i][(j + pre) % 13] %= MOD; } } } else { for (int k = 0; k < 10; k++) ans[i][(sur * k) % 13] += 1; } } else { n = S[i] - '0'; sur = (sur * n) % 13; if (i >= 1) { for (int j = 0; j < 13; j++) ans[i][(j + sur) % 13] = ans[i - 1][j]; } else { ans[i][sur] = 1; } } } cout << ans[N - 1][5]; return 0; }
#include <algorithm> #include <iostream> #include <string> using namespace std; const int MOD = 1000000007; long long int POW(int n, int k, int m) { long long int r; if (k == 0) return 1; r = POW(n, k / 2, m) % m; r = (r * r) % m; if (k % 2) r = (n * r) % m; return r; } int main() { int N, ans[100000][13] = {0}, n, sur, pre; string S; cin >> S; N = S.length(); for (int i = 0; i < N; i++) { sur = POW(10, N - i - 1, 13); if (S[i] == '?') { if (i >= 1) { for (int j = 0; j < 13; j++) { for (int k = 0; k < 10; k++) { pre = (sur * k) % 13; ans[i][(j + pre) % 13] += ans[i - 1][j]; ans[i][(j + pre) % 13] %= MOD; } } } else { for (int k = 0; k < 10; k++) ans[i][(sur * k) % 13] += 1; } } else { n = S[i] - '0'; sur = (sur * n) % 13; if (i >= 1) { for (int j = 0; j < 13; j++) ans[i][(j + sur) % 13] = ans[i - 1][j]; } else { ans[i][sur] = 1; } } } cout << ans[N - 1][5]; return 0; }
replace
16
17
16
17
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define FAST \ std::ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pi acos(-1) #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define F first #define S second #define ppb pop_back #define GCD(m, n) __gcd(m, n) #define LCM(m, n) (m * n) / GCD(m, n) #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define initarr(a, n, x) \ for (int i = 0; i < n; ++i) \ a[i] = x #define rep(i, a, n) for (int i = a; i < n; i++) #define repe(i, a, n) for (int i = a; i <= n; i++) #define rev(i, a, b) for (int i = a; i >= b; i--) #define int long long //////////// #define MOD 1000000007 //////// #define POD 998244353 //////// // define ll long long #define ld long double typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<vvvi> vvvvi; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<vvc> vvvc; typedef vector<pii> vpii; typedef vector<bool> vb; typedef vector<vb> vvb; typedef map<int, int> mii; typedef unordered_map<int, int> umii; typedef map<char, int> mci; #define itv for (auto it = v.begin(); it != v.end(); ++it) #define present(container, element) (container.find(element) != container.end()) #define cpresent(container, element) \ (find(ALL(container), element) != container.end()) // #define invect(data,n,commands) for(int i = 0;i<n;i++){int // tmp;cin>>tmp;data.pb(tmp);commands} #define inset(data,n,commands) for(int i // = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands} #define trav(a, x) // for(auto& a : x) #define display(x) trav(a,x) cout<<a<<" ";cout<<endl #define bs binary_search #define lb(v, val) lower_bound(ALL(v), val) #define ub(v, val) upper_bound(ALL(v), val) #define Max(x, y, z) max(x, max(y, z)) #define Min(x, y, z) min(x, min(y, z)) #define maxc(v) *max_element(ALL(v)) #define minc(v) *min_element(ALL(v)) /* #define dbg1(a) cout<<" *"<<a<<" "; #define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" " ///// #define dbg cout<<"move" */ #define vin(v, n) \ ; \ vi v(n); \ rep(i, 0, n) cin >> v[i]; #define dbg cerr << "At line " << __LINE__ << " move " << nl #define dbg1(x) cerr << "At line " << __LINE__ << " " << #x << "=" << x << nl #define dbg2(x, y) \ cerr << "At line " << __LINE__ << " " << #x << "=" << x << " " << #y << "=" \ << y << nl #define dbg3(x, y, z) \ cerr << "At line " << __LINE__ << " " << #x << "=" << x << " " << #y << "=" \ << y << " " << #z << "=" << z << nl #define prv(v) \ ; \ rep(i, 0, sz(v)) cerr << v[i] << " "; #define nl "\n" #define sz(s) (int)((s).size()) #define coutsp(k) \ cout << setprecision( \ k) // set precision (total length k icluding decimal and non decimal) #define coutfsp(k) \ cout << fixed << setprecision(k) // fixed set precision(after decimal fixing) #define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') #define INF (int)2e18 //------------------------ Global VARIABLE ------------------------------------ const int N = 1e5 + 2; string s; int n; vi pp; int dp[N][13]; //------------------------ Global VARIABLE ------------------------------------ int recurso(int n1, int md) { if (n1 == 0 && md == 0) return 1; if (n1 <= 0) return 0; if (dp[n1][md] != -1) { return dp[n1][md]; } int d, ans = 0; if (s[n1 - 1] != '?') { d = pp[n - n1] * (s[n1 - 1] - '0'); d %= 13; ans += recurso(n1 - 1, (md - d + 13) % 13) % MOD; } else { rep(k, 0, 10) { d = pp[n - n1] * (k); d %= 13; ans += recurso(n1 - 1, (md - d + 13) % 13) % MOD; } } return dp[n1][md] = ans % MOD; } //------------------------------------------------------------------------------- void dquit() { cin >> s; n = sz(s); memset(dp, -1, sizeof(dp)); pp.resize(n + 1); pp[0] = 1; rep(i, 1, n + 1) { pp[i] = pp[i - 1] * 10; pp[i] %= 13; } cout << recurso(n, 5); } //------------------------------------------------------------------------------- signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif //-------------------------------- FAST // MAKE IT FAST --- //-------------------------------- /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// int t; t = 1; int co = 1; ///////---------------------------------||||| // cin>>t; ////////>>>>>>> //////----------------------------------||||| while (t--) { // cout<<"Case #"<<co<<": "; dquit(); cout << nl; // IMPORTANT FOR NEXT LINE co++; } // #ifndef ONLINE_JUDGE // cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms"; // #endif return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define FAST \ std::ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pi acos(-1) #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define F first #define S second #define ppb pop_back #define GCD(m, n) __gcd(m, n) #define LCM(m, n) (m * n) / GCD(m, n) #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define initarr(a, n, x) \ for (int i = 0; i < n; ++i) \ a[i] = x #define rep(i, a, n) for (int i = a; i < n; i++) #define repe(i, a, n) for (int i = a; i <= n; i++) #define rev(i, a, b) for (int i = a; i >= b; i--) #define int long long //////////// #define MOD 1000000007 //////// #define POD 998244353 //////// // define ll long long #define ld long double typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<vvvi> vvvvi; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<vvc> vvvc; typedef vector<pii> vpii; typedef vector<bool> vb; typedef vector<vb> vvb; typedef map<int, int> mii; typedef unordered_map<int, int> umii; typedef map<char, int> mci; #define itv for (auto it = v.begin(); it != v.end(); ++it) #define present(container, element) (container.find(element) != container.end()) #define cpresent(container, element) \ (find(ALL(container), element) != container.end()) // #define invect(data,n,commands) for(int i = 0;i<n;i++){int // tmp;cin>>tmp;data.pb(tmp);commands} #define inset(data,n,commands) for(int i // = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands} #define trav(a, x) // for(auto& a : x) #define display(x) trav(a,x) cout<<a<<" ";cout<<endl #define bs binary_search #define lb(v, val) lower_bound(ALL(v), val) #define ub(v, val) upper_bound(ALL(v), val) #define Max(x, y, z) max(x, max(y, z)) #define Min(x, y, z) min(x, min(y, z)) #define maxc(v) *max_element(ALL(v)) #define minc(v) *min_element(ALL(v)) /* #define dbg1(a) cout<<" *"<<a<<" "; #define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" " ///// #define dbg cout<<"move" */ #define vin(v, n) \ ; \ vi v(n); \ rep(i, 0, n) cin >> v[i]; #define dbg cerr << "At line " << __LINE__ << " move " << nl #define dbg1(x) cerr << "At line " << __LINE__ << " " << #x << "=" << x << nl #define dbg2(x, y) \ cerr << "At line " << __LINE__ << " " << #x << "=" << x << " " << #y << "=" \ << y << nl #define dbg3(x, y, z) \ cerr << "At line " << __LINE__ << " " << #x << "=" << x << " " << #y << "=" \ << y << " " << #z << "=" << z << nl #define prv(v) \ ; \ rep(i, 0, sz(v)) cerr << v[i] << " "; #define nl "\n" #define sz(s) (int)((s).size()) #define coutsp(k) \ cout << setprecision( \ k) // set precision (total length k icluding decimal and non decimal) #define coutfsp(k) \ cout << fixed << setprecision(k) // fixed set precision(after decimal fixing) #define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') #define INF (int)2e18 //------------------------ Global VARIABLE ------------------------------------ const int N = 1e5 + 2; string s; int n; vi pp; int dp[N][13]; //------------------------ Global VARIABLE ------------------------------------ int recurso(int n1, int md) { if (n1 == 0 && md == 0) return 1; if (n1 <= 0) return 0; if (dp[n1][md] != -1) { return dp[n1][md]; } int d, ans = 0; if (s[n1 - 1] != '?') { d = pp[n - n1] * (s[n1 - 1] - '0'); d %= 13; ans += recurso(n1 - 1, (md - d + 13) % 13) % MOD; } else { rep(k, 0, 10) { d = pp[n - n1] * (k); d %= 13; ans += recurso(n1 - 1, (md - d + 13) % 13) % MOD; } } return dp[n1][md] = ans % MOD; } //------------------------------------------------------------------------------- void dquit() { cin >> s; n = sz(s); memset(dp, -1, sizeof(dp)); pp.resize(n + 1); pp[0] = 1; rep(i, 1, n + 1) { pp[i] = pp[i - 1] * 10; pp[i] %= 13; } cout << recurso(n, 5); } //------------------------------------------------------------------------------- signed main() { //-------------------------------- FAST // MAKE IT FAST --- //-------------------------------- /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// int t; t = 1; int co = 1; ///////---------------------------------||||| // cin>>t; ////////>>>>>>> //////----------------------------------||||| while (t--) { // cout<<"Case #"<<co<<": "; dquit(); cout << nl; // IMPORTANT FOR NEXT LINE co++; } // #ifndef ONLINE_JUDGE // cerr<<(1000*clock())/CLOCKS_PER_SEC<<"ms"; // #endif return 0; }
delete
164
170
164
164
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #include <iostream> typedef long long ll; using namespace std; int main() { string s; cin >> s; ll mod = 1e9 + 7, sum; ll n = s.size(); ll dp[10000000][13]; dp[0][0] = 1; for (ll i = 0; i < n; i++) { ll c = 0; if (s[i] == '?') { c = -1; } else { c = s[i] - '0'; } for (ll j = 0; j < 10; j++) { if (c != -1 && c != j) continue; for (ll k = 0; k < 13; k++) { dp[i + 1][(k * 10 + j) % 13] += dp[i][k]; } } for (ll j = 0; j < 13; j++) dp[i + 1][j] %= mod; } sum = dp[n][5]; cout << sum << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #include <iostream> typedef long long ll; using namespace std; int main() { string s; cin >> s; ll mod = 1e9 + 7, sum; ll n = s.size(); ll dp[1000000][13]; dp[0][0] = 1; for (ll i = 0; i < n; i++) { ll c = 0; if (s[i] == '?') { c = -1; } else { c = s[i] - '0'; } for (ll j = 0; j < 10; j++) { if (c != -1 && c != j) continue; for (ll k = 0; k < 13; k++) { dp[i + 1][(k * 10 + j) % 13] += dp[i][k]; } } for (ll j = 0; j < 13; j++) dp[i + 1][j] %= mod; } sum = dp[n][5]; cout << sum << endl; }
replace
11
12
11
12
-11
p02960
C++
Runtime Error
#define _GLIBCXX_DEBUG #include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <list> #include <map> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define mp make_pair #define pb push_back const int INF = 1e9; const ll LINF = 1e18; const int MOD = 1e9 + 7; ll dp[10010][13]; int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; dp[0][0] = 1; for (int i = 0; i < (int)S.size(); i++) { int c; if (S[i] == '?') c = -1; else c = S[i] - '0'; for (int number_pos = 0; number_pos <= 9; number_pos++) { if (c != -1 && c != number_pos) continue; for (int mod_prev = 0; mod_prev < 13; mod_prev++) { int mod_pos = (mod_prev * 10 + number_pos) % 13; dp[i + 1][mod_pos] += dp[i][mod_prev]; dp[i + 1][mod_pos] %= MOD; } } } cout << dp[(int)S.size()][5] << endl; return 0; }
#define _GLIBCXX_DEBUG #include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <list> #include <map> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define mp make_pair #define pb push_back const int INF = 1e9; const ll LINF = 1e18; const int MOD = 1e9 + 7; ll dp[100010][13]; int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; dp[0][0] = 1; for (int i = 0; i < (int)S.size(); i++) { int c; if (S[i] == '?') c = -1; else c = S[i] - '0'; for (int number_pos = 0; number_pos <= 9; number_pos++) { if (c != -1 && c != number_pos) continue; for (int mod_prev = 0; mod_prev < 13; mod_prev++) { int mod_pos = (mod_prev * 10 + number_pos) % 13; dp[i + 1][mod_pos] += dp[i][mod_prev]; dp[i + 1][mod_pos] %= MOD; } } } cout << dp[(int)S.size()][5] << endl; return 0; }
replace
20
21
20
21
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define MOD 1000000007 using namespace std; char S[100]; long long dp[100001][13]; int main() { map<char, int> m = {{'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'?', -1}}; scanf("%s", S); dp[0][0] += 1; rep(i, strlen(S)) { int n = m[S[i]]; rep(j, 10) { if (n != -1 && n != j) continue; rep(ki, 13) { dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]; } } rep(j, 13) dp[i + 1][j] %= MOD; } cout << dp[strlen(S)][5] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define MOD 1000000007 using namespace std; char S[100001]; long long dp[100001][13]; int main() { map<char, int> m = {{'1', 1}, {'2', 2}, {'3', 3}, {'4', 4}, {'5', 5}, {'6', 6}, {'7', 7}, {'8', 8}, {'9', 9}, {'?', -1}}; scanf("%s", S); dp[0][0] += 1; rep(i, strlen(S)) { int n = m[S[i]]; rep(j, 10) { if (n != -1 && n != j) continue; rep(ki, 13) { dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]; } } rep(j, 13) dp[i + 1][j] %= MOD; } cout << dp[strlen(S)][5] << endl; return 0; }
replace
5
6
5
6
0
p02960
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <limits> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; #define LL long long #define MOD (1000000007) // 135 int main() { static char s[100010]; scanf("%s", s); static LL dp[10010][13]; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; LL len = strlen(s); LL mod_keta = 1; for (LL i = 1; i <= len; i++) { for (LL num = 0; num <= 9; num++) { if (s[len - i] != '?' && num != (s[len - i] - '0')) { continue; } LL mod13_keta = (mod_keta * num) % 13; for (LL num_prev = 0; num_prev <= 12; num_prev++) { LL mod13_result = (num_prev + mod13_keta) % 13; dp[i][mod13_result] += dp[i - 1][num_prev]; dp[i][mod13_result] %= MOD; } } mod_keta = (mod_keta * 10) % 13; } printf("%lld\n", dp[len][5]); return 0; } // 134 /* int main() { LL N; scanf("%lld", &N); vector<unsigned int> A(N + 1); for (LL i = 1; i <= N; i++) { scanf("%d", &A[i]); } vector<unsigned int> B(N + 1); vector<unsigned int> result; for (LL i = N; i >= 1; i--) { LL count = 0; LL num = i * 2; while (num <= N) { count += B[num]; num += i; } if (count % 2 != A[i]) { B[i] = 1; result.push_back(i); } } printf("%d\n", (unsigned int)result.size()); for (auto item : result) { printf("%d ", item); } printf("\n"); return 0; } */ // 133 /* int main() { LL N; scanf("%lld", &N); vector<LL> A(N); for (LL i = 0; i < N; i++) { scanf("%lld", &A[i]); } vector<LL> R(N); R[0] = 0; for (LL i = 0; i < N; i++) { if (i % 2 == 0) { R[0] += A[i]; } else { R[0] -= A[i]; } } R[N - 1] = 2 * A[N - 1] - R[0]; for (LL i = N - 2; i > 0; i--) { R[i] = 2 * A[i] - R[i + 1]; } for (int i = 0; i < N; i++) { printf("%lld ", R[i]); } printf("\n"); return 0; } */ // 132 /* // mod. m �ł� a �̋t�� a^{-1} ���v�Z���� LL modinv(LL a, LL m) { LL b = m, u = 1, v = 0; while (b) { LL t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } LL calcCombinationMOD(LL n, LL r, LL mod) { LL num = 1; for (LL i = 1; i <= r; i++) { num = num * (n - i + 1); num = num % mod; num = (num * modinv(i, mod)) % mod; } return num; } LL calcHomogeneousProductMOD(LL n, LL r, LL mod) { return calcCombinationMOD(n + r - 1, r, mod); } int main() { LL N, B; scanf("%lld %lld", &N, &B); LL R = N - B; for (LL i = 1; i <= B; i++) { LL lastB = B - i; LL lastR = R - (i - 1); if (lastR < 0) { printf("0\n"); continue; } LL boxB = i; LL boxR = i + 1; LL patternB = calcHomogeneousProductMOD(boxB, lastB, MOD); LL patternR = calcHomogeneousProductMOD(boxR, lastR, MOD); LL result = (patternB * patternR) % MOD; printf("%lld\n", result); } } */ // 131 /* struct LLPair { LL A, B; }; int main() { LL N; scanf("%lld", &N); vector<LLPair> A(N); for (int i = 0; i < N; i++) { LL a, b; scanf("%lld %lld", &a, &b); A[i].A = a; A[i].B = b; } std::sort(A.begin(), A.end(), [](const LLPair &a, const LLPair &b) { return a.B < b.B; }); LL time = 0; bool success = true; for (auto item : A) { time += item.A; if (time > item.B) { success = false; } } if (success) { printf("Yes\n"); } else { printf("No\n"); } return 0; } */ // 130 /* int main() { LL N, K; scanf("%lld %lld", &N, &K); vector<LL> a(N); for (int i = 0; i < N; i++) { scanf("%lld", &a[i]); } LL result = 0; LL begin = 0, end = 0; LL total = a[0]; while (true) { if (total >= K) { if (total >= K) { result++; result += N - end - 1; } //�[�����Ă���̂�begin��i�߂� if (begin == end) { begin++; end++; total = a[begin]; } else { total -= a[begin]; begin++; } } else { //�[�����Ă��Ȃ��̂�end��i�߂� end++; if (end >= N) { break; } else { total += a[end]; } } } printf("%lld\n", result); return 0; } */ // 129 /* int main() { LL H, W; scanf("%lld %lld", &H, &W); static int hor_label[2020][2020]; static int var_label[2020][2020]; static int hor_label_to_count[2020 * 2020]; static int var_label_to_count[2020 * 2020]; memset(hor_label, 0, sizeof(hor_label)); memset(var_label, 0, sizeof(var_label)); memset(hor_label_to_count, 0, sizeof(hor_label_to_count)); memset(var_label_to_count, 0, sizeof(var_label_to_count)); char s[2020]; int hor_curr_label = 1; int var_curr_label = 1; for (int j = 0; j < H; j++) { scanf("%s", &s); for (int i = 0; i < W; i++) { if (s[i] == '.') { hor_label[j][i] = hor_curr_label; hor_label_to_count[hor_curr_label]++; if (j == 0) { var_label[j][i] = var_curr_label; var_label_to_count[var_curr_label]++; var_curr_label++; } else { int abobe_label = var_label[j - 1][i]; if (abobe_label > 0) { var_label[j][i] = abobe_label; var_label_to_count[abobe_label]++; } else { var_label[j][i] = var_curr_label; var_label_to_count[var_curr_label]++; var_curr_label++; } } } else { hor_curr_label++; } } hor_curr_label++; } LL result = 0; for (int j = 0; j < H; j++) { for (int i = 0; i < W; i++) { if (hor_label[j][i] == 0) { continue; } LL count = hor_label_to_count[hor_label[j][i]] + var_label_to_count[var_label[j][i]] - 1; result = max(count, result); } } printf("%lld\n", result); return 0; } */ // 128 /* int main() { LL N, K; scanf("%lld %lld", &N, &K); vector<LL> V(N); vector<LL> Lval(N + 1); Lval[0] = 0; for (int i = 0; i < N; i++) { scanf("%lld", &V[i]); Lval[i + 1] = Lval[i] + V[i]; } vector<LL> Rval(N + 1); Rval[0] = 0; for (int i = 0; i < N; i++) { Rval[i + 1] = Rval[i] + V[N - i - 1]; } vector<vector<vector<LL>>> Dq(N + 1, vector<vector<LL>>(N + 1, vector<LL>(0))); for (int i = 0; i <= N; i++) { //L for (int j = 0; j <= N - i; j++) { //R for (int l = 0; l < i; l++) { if (V[l] < 0) { Dq[i][j].push_back(V[l]); } } for (int r = 0; r < j; r++) { if (V[N - r - 1] < 0) { Dq[i][j].push_back(V[N - r - 1]); } } if (Dq[i][j].size() > 0) { std::sort(Dq[i][j].begin(), Dq[i][j].end()); } } } LL result = 0; LL max_get = min(N, K); for (int l = 0; l <= max_get; l++) { for (int r = 0; r <= max_get - l; r++) { for (int d = 0; d <= K - l - r; d++) { LL value = Lval[l] + Rval[r]; int dis = min(d, (int)Dq[l][r].size()); for (int i = 0; i < dis; i++) { value -= Dq[l][r][i]; } result = max(result, value); } } } printf("%lld\n", result); return 0; } */ // 127 /* struct IntPair { LL B, C; }; int main() { LL N, M; scanf("%lld %lld", &N, &M); vector<LL> A; for (int i = 0; i < N; i++) { LL val; scanf("%lld", &val); A.push_back(val); } vector<IntPair> P; for (int i = 0; i < M; i++) { LL val1, val2; scanf("%lld %lld", &val1, &val2); IntPair pair; pair.B = val1; pair.C = val2; P.push_back(pair); } std::sort(A.begin(), A.end()); std::sort(P.begin(), P.end(), [](const IntPair &a, const IntPair &b) { return a.C > b.C; }); LL indexA = 0; bool finish = false; for (auto item : P) { for (int i = 0; i < item.B; i++) { if (item.C > A[indexA]) { A[indexA] = item.C; } else { finish = true; break; } indexA++; if (indexA >= N) { finish = true; break; } } if (finish) { break; } } LL result = 0; for (auto item : A) { result += item; } printf("%lld\n", result); return 0; } */ // 126 /* struct Node { unsigned int connect; unsigned int weight; }; int main() { LL N; scanf("%lld", &N); static vector<Node> node[100010]; static char color[100010]; for (int i = 0; i < N - 1; i++) { unsigned int u, v, w; scanf("%d %d %d", &u, &v, &w); Node n1; n1.connect = v; n1.weight = w; node[u].push_back(n1); Node n2; n2.connect = u; n2.weight = w; node[v].push_back(n2); } for (int i = 0; i <= N; i++) { color[i] = -1; } std::queue<unsigned int> q; color[1] = 0; q.push(1); //���D��T�� while (q.size() > 0) { unsigned int index = q.front(); q.pop(); char c = color[index]; for (auto item : node[index]) { if (color[item.connect] < 0) { //�܂��ʂ��Ă��Ȃ��m�[�h color[item.connect] = item.weight % 2 == 0 ? c : 1 - c; q.push(item.connect); } } } for (int i = 1; i <= N; i++) { printf("%d\n", color[i]); } return 0; } */
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <limits> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; #define LL long long #define MOD (1000000007) // 135 int main() { static char s[100010]; scanf("%s", s); static LL dp[100010][13]; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; LL len = strlen(s); LL mod_keta = 1; for (LL i = 1; i <= len; i++) { for (LL num = 0; num <= 9; num++) { if (s[len - i] != '?' && num != (s[len - i] - '0')) { continue; } LL mod13_keta = (mod_keta * num) % 13; for (LL num_prev = 0; num_prev <= 12; num_prev++) { LL mod13_result = (num_prev + mod13_keta) % 13; dp[i][mod13_result] += dp[i - 1][num_prev]; dp[i][mod13_result] %= MOD; } } mod_keta = (mod_keta * 10) % 13; } printf("%lld\n", dp[len][5]); return 0; } // 134 /* int main() { LL N; scanf("%lld", &N); vector<unsigned int> A(N + 1); for (LL i = 1; i <= N; i++) { scanf("%d", &A[i]); } vector<unsigned int> B(N + 1); vector<unsigned int> result; for (LL i = N; i >= 1; i--) { LL count = 0; LL num = i * 2; while (num <= N) { count += B[num]; num += i; } if (count % 2 != A[i]) { B[i] = 1; result.push_back(i); } } printf("%d\n", (unsigned int)result.size()); for (auto item : result) { printf("%d ", item); } printf("\n"); return 0; } */ // 133 /* int main() { LL N; scanf("%lld", &N); vector<LL> A(N); for (LL i = 0; i < N; i++) { scanf("%lld", &A[i]); } vector<LL> R(N); R[0] = 0; for (LL i = 0; i < N; i++) { if (i % 2 == 0) { R[0] += A[i]; } else { R[0] -= A[i]; } } R[N - 1] = 2 * A[N - 1] - R[0]; for (LL i = N - 2; i > 0; i--) { R[i] = 2 * A[i] - R[i + 1]; } for (int i = 0; i < N; i++) { printf("%lld ", R[i]); } printf("\n"); return 0; } */ // 132 /* // mod. m �ł� a �̋t�� a^{-1} ���v�Z���� LL modinv(LL a, LL m) { LL b = m, u = 1, v = 0; while (b) { LL t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } LL calcCombinationMOD(LL n, LL r, LL mod) { LL num = 1; for (LL i = 1; i <= r; i++) { num = num * (n - i + 1); num = num % mod; num = (num * modinv(i, mod)) % mod; } return num; } LL calcHomogeneousProductMOD(LL n, LL r, LL mod) { return calcCombinationMOD(n + r - 1, r, mod); } int main() { LL N, B; scanf("%lld %lld", &N, &B); LL R = N - B; for (LL i = 1; i <= B; i++) { LL lastB = B - i; LL lastR = R - (i - 1); if (lastR < 0) { printf("0\n"); continue; } LL boxB = i; LL boxR = i + 1; LL patternB = calcHomogeneousProductMOD(boxB, lastB, MOD); LL patternR = calcHomogeneousProductMOD(boxR, lastR, MOD); LL result = (patternB * patternR) % MOD; printf("%lld\n", result); } } */ // 131 /* struct LLPair { LL A, B; }; int main() { LL N; scanf("%lld", &N); vector<LLPair> A(N); for (int i = 0; i < N; i++) { LL a, b; scanf("%lld %lld", &a, &b); A[i].A = a; A[i].B = b; } std::sort(A.begin(), A.end(), [](const LLPair &a, const LLPair &b) { return a.B < b.B; }); LL time = 0; bool success = true; for (auto item : A) { time += item.A; if (time > item.B) { success = false; } } if (success) { printf("Yes\n"); } else { printf("No\n"); } return 0; } */ // 130 /* int main() { LL N, K; scanf("%lld %lld", &N, &K); vector<LL> a(N); for (int i = 0; i < N; i++) { scanf("%lld", &a[i]); } LL result = 0; LL begin = 0, end = 0; LL total = a[0]; while (true) { if (total >= K) { if (total >= K) { result++; result += N - end - 1; } //�[�����Ă���̂�begin��i�߂� if (begin == end) { begin++; end++; total = a[begin]; } else { total -= a[begin]; begin++; } } else { //�[�����Ă��Ȃ��̂�end��i�߂� end++; if (end >= N) { break; } else { total += a[end]; } } } printf("%lld\n", result); return 0; } */ // 129 /* int main() { LL H, W; scanf("%lld %lld", &H, &W); static int hor_label[2020][2020]; static int var_label[2020][2020]; static int hor_label_to_count[2020 * 2020]; static int var_label_to_count[2020 * 2020]; memset(hor_label, 0, sizeof(hor_label)); memset(var_label, 0, sizeof(var_label)); memset(hor_label_to_count, 0, sizeof(hor_label_to_count)); memset(var_label_to_count, 0, sizeof(var_label_to_count)); char s[2020]; int hor_curr_label = 1; int var_curr_label = 1; for (int j = 0; j < H; j++) { scanf("%s", &s); for (int i = 0; i < W; i++) { if (s[i] == '.') { hor_label[j][i] = hor_curr_label; hor_label_to_count[hor_curr_label]++; if (j == 0) { var_label[j][i] = var_curr_label; var_label_to_count[var_curr_label]++; var_curr_label++; } else { int abobe_label = var_label[j - 1][i]; if (abobe_label > 0) { var_label[j][i] = abobe_label; var_label_to_count[abobe_label]++; } else { var_label[j][i] = var_curr_label; var_label_to_count[var_curr_label]++; var_curr_label++; } } } else { hor_curr_label++; } } hor_curr_label++; } LL result = 0; for (int j = 0; j < H; j++) { for (int i = 0; i < W; i++) { if (hor_label[j][i] == 0) { continue; } LL count = hor_label_to_count[hor_label[j][i]] + var_label_to_count[var_label[j][i]] - 1; result = max(count, result); } } printf("%lld\n", result); return 0; } */ // 128 /* int main() { LL N, K; scanf("%lld %lld", &N, &K); vector<LL> V(N); vector<LL> Lval(N + 1); Lval[0] = 0; for (int i = 0; i < N; i++) { scanf("%lld", &V[i]); Lval[i + 1] = Lval[i] + V[i]; } vector<LL> Rval(N + 1); Rval[0] = 0; for (int i = 0; i < N; i++) { Rval[i + 1] = Rval[i] + V[N - i - 1]; } vector<vector<vector<LL>>> Dq(N + 1, vector<vector<LL>>(N + 1, vector<LL>(0))); for (int i = 0; i <= N; i++) { //L for (int j = 0; j <= N - i; j++) { //R for (int l = 0; l < i; l++) { if (V[l] < 0) { Dq[i][j].push_back(V[l]); } } for (int r = 0; r < j; r++) { if (V[N - r - 1] < 0) { Dq[i][j].push_back(V[N - r - 1]); } } if (Dq[i][j].size() > 0) { std::sort(Dq[i][j].begin(), Dq[i][j].end()); } } } LL result = 0; LL max_get = min(N, K); for (int l = 0; l <= max_get; l++) { for (int r = 0; r <= max_get - l; r++) { for (int d = 0; d <= K - l - r; d++) { LL value = Lval[l] + Rval[r]; int dis = min(d, (int)Dq[l][r].size()); for (int i = 0; i < dis; i++) { value -= Dq[l][r][i]; } result = max(result, value); } } } printf("%lld\n", result); return 0; } */ // 127 /* struct IntPair { LL B, C; }; int main() { LL N, M; scanf("%lld %lld", &N, &M); vector<LL> A; for (int i = 0; i < N; i++) { LL val; scanf("%lld", &val); A.push_back(val); } vector<IntPair> P; for (int i = 0; i < M; i++) { LL val1, val2; scanf("%lld %lld", &val1, &val2); IntPair pair; pair.B = val1; pair.C = val2; P.push_back(pair); } std::sort(A.begin(), A.end()); std::sort(P.begin(), P.end(), [](const IntPair &a, const IntPair &b) { return a.C > b.C; }); LL indexA = 0; bool finish = false; for (auto item : P) { for (int i = 0; i < item.B; i++) { if (item.C > A[indexA]) { A[indexA] = item.C; } else { finish = true; break; } indexA++; if (indexA >= N) { finish = true; break; } } if (finish) { break; } } LL result = 0; for (auto item : A) { result += item; } printf("%lld\n", result); return 0; } */ // 126 /* struct Node { unsigned int connect; unsigned int weight; }; int main() { LL N; scanf("%lld", &N); static vector<Node> node[100010]; static char color[100010]; for (int i = 0; i < N - 1; i++) { unsigned int u, v, w; scanf("%d %d %d", &u, &v, &w); Node n1; n1.connect = v; n1.weight = w; node[u].push_back(n1); Node n2; n2.connect = u; n2.weight = w; node[v].push_back(n2); } for (int i = 0; i <= N; i++) { color[i] = -1; } std::queue<unsigned int> q; color[1] = 0; q.push(1); //���D��T�� while (q.size() > 0) { unsigned int index = q.front(); q.pop(); char c = color[index]; for (auto item : node[index]) { if (color[item.connect] < 0) { //�܂��ʂ��Ă��Ȃ��m�[�h color[item.connect] = item.weight % 2 == 0 ? c : 1 - c; q.push(item.connect); } } } for (int i = 1; i <= N; i++) { printf("%d\n", color[i]); } return 0; } */
replace
20
21
20
21
0
p02960
C++
Runtime Error
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author toshibablack */ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #define ll long long int #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < n; ++i) #define FOREACH(x, a) for (auto &(x) : (a)) #define ALL(a) (a).begin(), (a).end() #define COUT(x) out << (x) << endl; const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; using namespace std; class DDigitsParade { public: ll T[13][100000]; string S; void solve(std::istream &in, std::ostream &out) { REP(i, 13) REP(j, 100000) T[i][j] = 0; in >> S; if (S[0] == '?') FOR(i, 0, 10) T[i][0]++; else T[S[0] - '0'][0]++; FOR(i, 1, S.length()) { if (S[i] == '?') { FOR(num, 0, 10) FOR(res, 0, 13) { T[(res * 10 + num) % 13][i] += T[res][i - 1]; T[(res * 10 + num) % 13][i] %= MOD; } } else { int num = S[i] - '0'; FOR(res, 0, 13) { T[(res * 10 + num) % 13][i] += T[res][i - 1]; T[(res * 10 + num) % 13][i] %= MOD; } } } COUT(T[S.length() - 1][5]); } }; int main() { DDigitsParade solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author toshibablack */ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> #define ll long long int #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < n; ++i) #define FOREACH(x, a) for (auto &(x) : (a)) #define ALL(a) (a).begin(), (a).end() #define COUT(x) out << (x) << endl; const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; using namespace std; class DDigitsParade { public: ll T[13][100000]; string S; void solve(std::istream &in, std::ostream &out) { REP(i, 13) REP(j, 100000) T[i][j] = 0; in >> S; if (S[0] == '?') FOR(i, 0, 10) T[i][0]++; else T[S[0] - '0'][0]++; FOR(i, 1, S.length()) { if (S[i] == '?') { FOR(num, 0, 10) FOR(res, 0, 13) { T[(res * 10 + num) % 13][i] += T[res][i - 1]; T[(res * 10 + num) % 13][i] %= MOD; } } else { int num = S[i] - '0'; FOR(res, 0, 13) { T[(res * 10 + num) % 13][i] += T[res][i - 1]; T[(res * 10 + num) % 13][i] %= MOD; } } } COUT(T[5][S.length() - 1]); } }; int main() { DDigitsParade solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); return 0; }
replace
65
66
65
66
-11
p02960
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n); i >= 0; i--) #define FOR(i, m, n) for (int i = (m); i < (n); i++) #define ALL(obj) begin(obj), end(obj) using namespace std; using ll = long long; using ull = unsigned long long; const int INF = 2100100100; const int MOD = 1e9 + 7; // 多次元 vector 生成 template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int dp[11000][13]; int main() { // cin.tie(0); // ios::sync_with_stdio(false); string S; cin >> S; int len = S.size(); reverse(ALL(S)); REP(i, 13) { dp[0][i] = 0; } if (S[0] == '?') { REP(i, 10) { dp[0][i] = 1; } } else { int index = S[0] - '0'; dp[0][index] = 1; } int num = 1; FOR(i, 1, len) { // cout << i << ":" << S[i] << endl; num *= 10; num %= 13; if (S[i] == '?') { REP(j, 10) { REP(k, 13) { int index = (k + j * num) % 13; dp[i][index] += dp[i - 1][k]; dp[i][index] %= MOD; } } } else { REP(k, 13) { int j = (S[i] - '0'); int index = (k + j * num) % 13; dp[i][index] += dp[i - 1][k]; dp[i][index] %= MOD; } } } cout << dp[len - 1][5] << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n); i >= 0; i--) #define FOR(i, m, n) for (int i = (m); i < (n); i++) #define ALL(obj) begin(obj), end(obj) using namespace std; using ll = long long; using ull = unsigned long long; const int INF = 2100100100; const int MOD = 1e9 + 7; // 多次元 vector 生成 template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int dp[110000][13]; int main() { // cin.tie(0); // ios::sync_with_stdio(false); string S; cin >> S; int len = S.size(); reverse(ALL(S)); REP(i, 13) { dp[0][i] = 0; } if (S[0] == '?') { REP(i, 10) { dp[0][i] = 1; } } else { int index = S[0] - '0'; dp[0][index] = 1; } int num = 1; FOR(i, 1, len) { // cout << i << ":" << S[i] << endl; num *= 10; num %= 13; if (S[i] == '?') { REP(j, 10) { REP(k, 13) { int index = (k + j * num) % 13; dp[i][index] += dp[i - 1][k]; dp[i][index] %= MOD; } } } else { REP(k, 13) { int j = (S[i] - '0'); int index = (k + j * num) % 13; dp[i][index] += dp[i - 1][k]; dp[i][index] %= MOD; } } } cout << dp[len - 1][5] << endl; return 0; }
replace
32
33
32
33
0
p02960
C++
Runtime Error
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; #define mode 1000000007 #define ll long long char s[100001]; ll dp[10001][13]; // i代表前几个字符组成,j代表模13的余数 int main() { scanf("%s", s); int n = strlen(s); memset(dp, 0, sizeof(dp)); if (s[0] == '?') { for (int i = 0; i < 10; i++) dp[0][i] = 1; // 1个字符组成的数字模13余数为i的个数 } else dp[0][s[0] - '0'] = 1; // cout<<"sdf"<<endl; for (int i = 1; i < n; i++) { for (int j = 0; j < 13; j++) // 遍历前一个状态的余数 { if (s[i] != '?') { int y = j * 10 + (s[i] - '0'); dp[i][y % 13] = (dp[i][y % 13] + dp[i - 1][j]) % mode; // 更新 continue; // 不用枚举0->9 } for (int k = 0; k <= 9; k++) { int y = j * 10 + k; dp[i][y % 13] = (dp[i][y % 13] + dp[i - 1][j]) % mode; // 更新 } } } cout << dp[n - 1][5] << endl; return 0; }
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; #define mode 1000000007 #define ll long long char s[100010]; ll dp[100001][13]; // i代表前几个字符组成,j代表模13的余数 int main() { scanf("%s", s); int n = strlen(s); memset(dp, 0, sizeof(dp)); if (s[0] == '?') { for (int i = 0; i < 10; i++) dp[0][i] = 1; // 1个字符组成的数字模13余数为i的个数 } else dp[0][s[0] - '0'] = 1; // cout<<"sdf"<<endl; for (int i = 1; i < n; i++) { for (int j = 0; j < 13; j++) // 遍历前一个状态的余数 { if (s[i] != '?') { int y = j * 10 + (s[i] - '0'); dp[i][y % 13] = (dp[i][y % 13] + dp[i - 1][j]) % mode; // 更新 continue; // 不用枚举0->9 } for (int k = 0; k <= 9; k++) { int y = j * 10 + k; dp[i][y % 13] = (dp[i][y % 13] + dp[i - 1][j]) % mode; // 更新 } } } cout << dp[n - 1][5] << endl; return 0; }
replace
6
8
6
8
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define MAX (int)1e+3 #define M 13 typedef long long ll; char S[MAX]; static const ll p = 1000000007; void solve() { ll dp[MAX + 1][M]; int base = 1; int n = strlen(S); int c; // initialize for (int i = 1; i < M; i++) dp[0][i] = 0; dp[0][0] = 1; // dp for (int i = 1; i <= n; i++) { if (S[n - i] == '?') c = -1; else c = S[n - i] - '0'; for (int j = 0; j < M; j++) dp[i][j] = 0; for (int j = 0; j < 10; j++) { if (c == -1 || c == j) { for (int k = 0; k < M; k++) dp[i][(k + j * base) % M] += dp[i - 1][k]; } } for (int j = 0; j < M; j++) dp[i][j] %= p; base *= 10; base %= M; } // result printf("%lld\n", dp[n][5]); } int main() { scanf("%s", S); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define MAX (int)1e+5 #define M 13 typedef long long ll; char S[MAX]; static const ll p = 1000000007; void solve() { ll dp[MAX + 1][M]; int base = 1; int n = strlen(S); int c; // initialize for (int i = 1; i < M; i++) dp[0][i] = 0; dp[0][0] = 1; // dp for (int i = 1; i <= n; i++) { if (S[n - i] == '?') c = -1; else c = S[n - i] - '0'; for (int j = 0; j < M; j++) dp[i][j] = 0; for (int j = 0; j < 10; j++) { if (c == -1 || c == j) { for (int k = 0; k < M; k++) dp[i][(k + j * base) % M] += dp[i - 1][k]; } } for (int j = 0; j < M; j++) dp[i][j] %= p; base *= 10; base %= M; } // result printf("%lld\n", dp[n][5]); } int main() { scanf("%s", S); solve(); return 0; }
replace
2
3
2
3
0
p02960
C++
Runtime Error
#include <iostream> #include <stdio.h> #include <string> #include <vector> #include <cassert> #include <algorithm> #include <functional> #include <cmath> #include <iomanip> #include <bits/stdc++.h> #include <cstdint> #include <limits> #include <queue> #include <type_traits> using namespace std; int MOD = 1e9 + 7; int main() { string s; cin >> s; int n = s.size(); vector<vector<long long>> dp(1e5, vector<long long>(13)); dp[0][0] = 1; for (int i = 0; i < n; i++) { int c; if (s[i] == '?') { c = -1; } else { c = s[i] - '0'; } for (int j = 0; j < 10; j++) { if (c != -1 && c != j) { continue; } else { for (int k = 0; k < 13; k++) { dp[i + 1][(k * 10 + j) % 13] += dp[i][k]; } } } for (int j = 0; j < 13; j++) { dp[i + 1][j] %= MOD; } } cout << dp[n][5] << endl; }
#include <iostream> #include <stdio.h> #include <string> #include <vector> #include <cassert> #include <algorithm> #include <functional> #include <cmath> #include <iomanip> #include <bits/stdc++.h> #include <cstdint> #include <limits> #include <queue> #include <type_traits> using namespace std; int MOD = 1e9 + 7; int main() { string s; cin >> s; int n = s.size(); vector<vector<long long>> dp(1e5 + 5, vector<long long>(13)); dp[0][0] = 1; for (int i = 0; i < n; i++) { int c; if (s[i] == '?') { c = -1; } else { c = s[i] - '0'; } for (int j = 0; j < 10; j++) { if (c != -1 && c != j) { continue; } else { for (int k = 0; k < 13; k++) { dp[i + 1][(k * 10 + j) % 13] += dp[i][k]; } } } for (int j = 0; j < 13; j++) { dp[i + 1][j] %= MOD; } } cout << dp[n][5] << endl; }
replace
28
29
28
29
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 100005 typedef long long ll; ll MOD = 1000000007; ll dp[10005][13]; int main() { string s; cin >> s; ll n = s.size(); dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 10; j++) { ll nxt = s[i] - '0'; if (s[i] == '?') { nxt = j; } for (int k = 0; k < 13; k++) { ll rem = (10 * k + nxt) % 13; dp[i + 1][rem] += dp[i][k]; dp[i + 1][rem] %= MOD; } if (s[i] != '?') break; } } cout << dp[n][5] << endl; }
#include <bits/stdc++.h> using namespace std; #define N 100005 typedef long long ll; ll MOD = 1000000007; ll dp[100005][13]; int main() { string s; cin >> s; ll n = s.size(); dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 10; j++) { ll nxt = s[i] - '0'; if (s[i] == '?') { nxt = j; } for (int k = 0; k < 13; k++) { ll rem = (10 * k + nxt) % 13; dp[i + 1][rem] += dp[i][k]; dp[i + 1][rem] %= MOD; } if (s[i] != '?') break; } } cout << dp[n][5] << endl; }
replace
5
6
5
6
0
p02960
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> // pair make_pair #include <vector> #define m0(x) memset(x, 0, sizeof(x)) #define m1(x) memset(x, 63, sizeof(x)) #define fill(x, y) memset(x, y, sizeof(x)) #define ll long long #define int ll #define INF INT_MAX / 10 using namespace std; using Pi = pair<int, int>; using Graph = vector<vector<int>>; using WeightGraph = vector<vector<Pi>>; int dp[10000][20]; signed main() { string N; cin >> N; int l = N.size(); vector<int> n; for (auto a : N) { if (a == '?') { n.push_back(-1); } else { n.push_back(a - '0'); } } // for (auto b : n) { // cout << b << endl; // } memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 0; i < l; i++) { for (int j = 0; j < 13; j++) { if (n[i] != -1) { dp[i + 1][(j * 10 + n[i]) % 13] += (dp[i][j] % 1000000007); dp[i + 1][(j * 10 + n[i]) % 13] %= 1000000007; } else { for (int x = 0; x <= 9; x++) { dp[i + 1][(j * 10 + x) % 13] += (dp[i][j] % 1000000007); dp[i + 1][(j * 10 + x) % 13] %= 1000000007; } } } } cout << dp[l][5] << endl; }
#include <algorithm> #include <assert.h> #include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> // pair make_pair #include <vector> #define m0(x) memset(x, 0, sizeof(x)) #define m1(x) memset(x, 63, sizeof(x)) #define fill(x, y) memset(x, y, sizeof(x)) #define ll long long #define int ll #define INF INT_MAX / 10 using namespace std; using Pi = pair<int, int>; using Graph = vector<vector<int>>; using WeightGraph = vector<vector<Pi>>; int dp[100100][20]; signed main() { string N; cin >> N; int l = N.size(); vector<int> n; for (auto a : N) { if (a == '?') { n.push_back(-1); } else { n.push_back(a - '0'); } } // for (auto b : n) { // cout << b << endl; // } memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 0; i < l; i++) { for (int j = 0; j < 13; j++) { if (n[i] != -1) { dp[i + 1][(j * 10 + n[i]) % 13] += (dp[i][j] % 1000000007); dp[i + 1][(j * 10 + n[i]) % 13] %= 1000000007; } else { for (int x = 0; x <= 9; x++) { dp[i + 1][(j * 10 + x) % 13] += (dp[i][j] % 1000000007); dp[i + 1][(j * 10 + x) % 13] %= 1000000007; } } } } cout << dp[l][5] << endl; }
replace
29
30
29
30
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int maxn = 1e3 + 10, mod = 1e9 + 7; ll dp[maxn][14]; map<int, int> m; int main() { string s; cin >> s; for (int i = 0; i < 13; i++) for (int j = 0; j < 13; j++) if ((j * 10) % 13 == i) m[i] = j; for (int i = 0; i < s.size(); i++) for (int j = 0; j < 13; j++) if (!i) { if (s[i] == '?') dp[i][j] = (j < 10); else dp[i][j] = (j == (s[i] - '0')); } else if (s[i] == '?') for (int t = 0; t < 10; t++) dp[i][j] = (dp[i][j] + dp[i - 1][m[(j - t + 13) % 13] % 13]) % mod; else dp[i][j] = (dp[i - 1][m[(j - (s[i] - '0') + 13) % 13] % 13]); cout << dp[s.size() - 1][5]; return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int maxn = 1e5 + 10, mod = 1e9 + 7; ll dp[maxn][14]; map<int, int> m; int main() { string s; cin >> s; for (int i = 0; i < 13; i++) for (int j = 0; j < 13; j++) if ((j * 10) % 13 == i) m[i] = j; for (int i = 0; i < s.size(); i++) for (int j = 0; j < 13; j++) if (!i) { if (s[i] == '?') dp[i][j] = (j < 10); else dp[i][j] = (j == (s[i] - '0')); } else if (s[i] == '?') for (int t = 0; t < 10; t++) dp[i][j] = (dp[i][j] + dp[i - 1][m[(j - t + 13) % 13] % 13]) % mod; else dp[i][j] = (dp[i - 1][m[(j - (s[i] - '0') + 13) % 13] % 13]); cout << dp[s.size() - 1][5]; return 0; }
replace
6
7
6
7
0
p02960
C++
Time Limit Exceeded
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define REP(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) REP(i, 0, n) const int INF = 1e9; #define Yes(n) cout << ((n) ? "Yes" : "No") << endl; #define ALL(v) v.begin(), v.end() #define dbg(x_) cerr << #x_ << ":" << x_ << endl; #define pb(x) push_back(x) #define sum(v) accumulate(ALL(v), 0) template <typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } // vector template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { int len = v.size(); for (int i = 0; i < len; ++i) { s << v[i]; if (i < len - 1) s << " "; } return s; } // 2 dimentional vector template <typename T> ostream &operator<<(ostream &s, const vector<vector<T>> &vv) { int len = vv.size(); for (int i = 0; i < len; ++i) { s << vv[i] << endl; } return s; } int testDevide() { int n = 1; rep(i, 12) { cout << i << ":" << n % 13 << endl; n *= 10; } } ll dp[100005][13]; char s[100005]; static const ll MOD = 1000000007; int solve() { cin >> s; ll n = strlen(s); dp[0][0] = 1; rep(i, n) { dbg(i); if (s[i] == '?') { rep(j, 10) { rep(k, 13) { dp[i + 1][(10 * k + j) % 13] += dp[i][k]; } } } else { rep(l, 13) { int c = s[i] - '0'; dp[i + 1][(10 * l + c) % 13] += dp[i][l]; } } rep(j, 13) { dbg(dp[i + 1][j]); dp[i + 1][j] %= MOD; } } cout << dp[n][5] << endl; return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define REP(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) REP(i, 0, n) const int INF = 1e9; #define Yes(n) cout << ((n) ? "Yes" : "No") << endl; #define ALL(v) v.begin(), v.end() #define dbg(x_) cerr << #x_ << ":" << x_ << endl; #define pb(x) push_back(x) #define sum(v) accumulate(ALL(v), 0) template <typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } // vector template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) { int len = v.size(); for (int i = 0; i < len; ++i) { s << v[i]; if (i < len - 1) s << " "; } return s; } // 2 dimentional vector template <typename T> ostream &operator<<(ostream &s, const vector<vector<T>> &vv) { int len = vv.size(); for (int i = 0; i < len; ++i) { s << vv[i] << endl; } return s; } int testDevide() { int n = 1; rep(i, 12) { cout << i << ":" << n % 13 << endl; n *= 10; } } ll dp[100005][13]; char s[100005]; static const ll MOD = 1000000007; int solve() { cin >> s; ll n = strlen(s); dp[0][0] = 1; rep(i, n) { dbg(i); if (s[i] == '?') { rep(j, 10) { rep(k, 13) { dp[i + 1][(10 * k + j) % 13] += dp[i][k]; } } } else { rep(l, 13) { int c = s[i] - '0'; dp[i + 1][(10 * l + c) % 13] += dp[i][l]; } } rep(j, 13) { dp[i + 1][j] %= MOD; } } cout << dp[n][5] << endl; return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
replace
68
72
68
69
TLE
p02960
C++
Runtime Error
#include <algorithm> #include <algorithm> // sort #include <cmath> #include <cstring> #include <iostream> #include <map> // pair #include <set> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; 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; } #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) #define all(x) (x).begin(), (x).end() const ll mod = 1e9 + 7; const int INF = 1e9; const ll INFLONG = 1e18; ll amari_pow[(int)2e5]; void func() { amari_pow[0] = 1; REP(i, 1, (int)1e5 + 7) { amari_pow[i] = amari_pow[i - 1] * 10 % 13; } } int main() { string s; cin >> s; ll length = s.size(); ll ans[100][13]; memset(ans, 0, sizeof(ans)); func(); ll sum = 0; ans[0][0] = 1; rep(i, length) { if (s[i] == '?') { rep(j, 13) { rep(k, 10) { ans[i + 1][(k * amari_pow[length - 1 - i] + j) % 13] += ans[i][j]; ans[i + 1][(k * amari_pow[length - 1 - i] + j) % 13] %= mod; } } } else { rep(j, 13) { ans[i + 1][((s[i] - '0') * amari_pow[length - 1 - i] + j) % 13] = ans[i][j]; ans[i + 1][((s[i] - '0') * amari_pow[length - 1 - i] + j) % 13] %= mod; } } } // rep(i,length+1){ // rep(j,13){ // cout << ans[i][j] << " "; // } // cout << endl; // } cout << ans[length][5]; }
#include <algorithm> #include <algorithm> // sort #include <cmath> #include <cstring> #include <iostream> #include <map> // pair #include <set> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; 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; } #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for (int i = x; i < n; i++) #define all(x) (x).begin(), (x).end() const ll mod = 1e9 + 7; const int INF = 1e9; const ll INFLONG = 1e18; ll amari_pow[(int)2e5]; void func() { amari_pow[0] = 1; REP(i, 1, (int)1e5 + 7) { amari_pow[i] = amari_pow[i - 1] * 10 % 13; } } int main() { string s; cin >> s; ll length = s.size(); ll ans[(int)2e5][13]; memset(ans, 0, sizeof(ans)); func(); ll sum = 0; ans[0][0] = 1; rep(i, length) { if (s[i] == '?') { rep(j, 13) { rep(k, 10) { ans[i + 1][(k * amari_pow[length - 1 - i] + j) % 13] += ans[i][j]; ans[i + 1][(k * amari_pow[length - 1 - i] + j) % 13] %= mod; } } } else { rep(j, 13) { ans[i + 1][((s[i] - '0') * amari_pow[length - 1 - i] + j) % 13] = ans[i][j]; ans[i + 1][((s[i] - '0') * amari_pow[length - 1 - i] + j) % 13] %= mod; } } } // rep(i,length+1){ // rep(j,13){ // cout << ans[i][j] << " "; // } // cout << endl; // } cout << ans[length][5]; }
replace
44
45
44
45
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define vll vector<ll> #define vi vector<int> #define MOD 1000000007 int main() { string S; cin >> S; vector<vll> dp(10005, vll(13, 0)); dp[0][0] = 1; int c; for (int i = 0; i < S.length(); i++) { if (S[i] == '?') c = -1; else c = S[i] - '0'; for (int j = 0; j < 10; j++) { if (c != -1 && c != j) continue; for (int k = 0; k < 13; k++) { dp[i + 1][(k * 10 + j) % 13] += dp[i][k]; } } for (int k = 0; k < 13; k++) { dp[i + 1][k] %= MOD; } } cout << dp[S.length()][5] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define vll vector<ll> #define vi vector<int> #define MOD 1000000007 int main() { string S; cin >> S; vector<vll> dp(100005, vll(13, 0)); dp[0][0] = 1; int c; for (int i = 0; i < S.length(); i++) { if (S[i] == '?') c = -1; else c = S[i] - '0'; for (int j = 0; j < 10; j++) { if (c != -1 && c != j) continue; for (int k = 0; k < 13; k++) { dp[i + 1][(k * 10 + j) % 13] += dp[i][k]; } } for (int k = 0; k < 13; k++) { dp[i + 1][k] %= MOD; } } cout << dp[S.length()][5] << endl; return 0; }
replace
14
15
14
15
0
p02960
C++
Runtime Error
/*Function Template*/ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pint; const int MAX = 510000; const int MOD = 1000000007; #define rep(i, n) for (ll i = 0; i < (n); i++) #define Rep(i, n) for (ll i = 1; i < (n); i++) #define ALL(a) (a).begin(), (a).end() #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265358979323846 ll fac[MAX], finv[MAX], inv[MAX]; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } bool palindrome(string s) { bool flag = true; rep(i, s.size()) if (s[i] != s[s.size() - 1 - i]) flag = false; return flag; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll Len(ll n) { ll s = 0; while (n != 0) s++, n /= 10; return s; } ll Sint(ll n) { ll m = 0, s = 0, a = n; while (a != 0) s++, a /= 10; for (ll i = s - 1; i >= 0; i--) m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10; return m; } ll Svec(vector<ll> v) { ll n = 0; for (ll i = 0; i < v.size(); i++) n += v[i]; return n; } ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } ll Factorial(ll n) { ll m = 1; while (n >= 1) m *= n, n--; return m; } void runlength(string s, vector<pair<char, ll>> &p) { ll x = 1; if (s.size() == 1) { p.push_back(pair<char, ll>(s[0], 1)); } for (ll i = 0; i < s.size() - 1; i++) { if (s[i] == s[i + 1]) { x++; if (i == s.size() - 2) { p.push_back(pair<char, ll>(s[i], x)); } } else { p.push_back(pair<char, ll>(s[i], x)); x = 1; if (i == s.size() - 2) { p.push_back(pair<char, ll>(s[s.size() - 1], x)); } } } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } string Toupper(string s) { string ans = ""; rep(i, s.size()) { if ('a' <= s[i] && s[i] <= 'z') ans += (char)s[i] - 32; else ans += s[i]; } return ans; } string Tolower(string s) { string ans = ""; rep(i, s.size()) { if ('A' <= s[i] && s[i] <= 'Z') ans += (char)s[i] + 32; else ans += s[i]; } return ans; } const int MAX_N = 100010; vector<bool> sieve_of_eratosthenes() { vector<bool> isPrime(MAX_N + 1, true); for (int i = 2; i <= MAX_N; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= MAX_N; j += i) { isPrime[j] = false; } } } return isPrime; } vector<pint> prime_factorize(ll n) { vector<pint> ans; for (ll p = 2; p <= sqrt(n); p++) { if (n % p != 0) continue; ll cnt = 0; while (n % p == 0) { n /= p; cnt++; } ans.push_back(make_pair(p, cnt)); } if (n != 1) ans.push_back(make_pair(n, 1)); return ans; } /*bool cmp(pint a, pint b) { return a.second < b.second; }*/ /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ int main() { IOS; string s; cin >> s; ll dp[10010][13]; rep(i, 10010) rep(j, 13) dp[i][j] = 0; if (s[0] == '?') rep(i, 10) dp[0][i] = 1; else dp[0][s[0] - '0'] = 1; rep(i, s.size() - 1) { if (s[i + 1] == '?') { rep(j, 13) { rep(k, 10) { dp[i + 1][(j * 10 + k) % 13] += dp[i][j]; dp[i + 1][(j * 10 + k) % 13] %= MOD; } } } else { rep(j, 13) { dp[i + 1][(j * 10 + s[i + 1] - '0') % 13] += dp[i][j]; dp[i + 1][(j * 10 + s[i + 1] - '0') % 13] %= MOD; } } } cout << dp[s.size() - 1][5] << endl; }
/*Function Template*/ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pint; const int MAX = 510000; const int MOD = 1000000007; #define rep(i, n) for (ll i = 0; i < (n); i++) #define Rep(i, n) for (ll i = 1; i < (n); i++) #define ALL(a) (a).begin(), (a).end() #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define PI 3.14159265358979323846 ll fac[MAX], finv[MAX], inv[MAX]; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } bool palindrome(string s) { bool flag = true; rep(i, s.size()) if (s[i] != s[s.size() - 1 - i]) flag = false; return flag; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll Len(ll n) { ll s = 0; while (n != 0) s++, n /= 10; return s; } ll Sint(ll n) { ll m = 0, s = 0, a = n; while (a != 0) s++, a /= 10; for (ll i = s - 1; i >= 0; i--) m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10; return m; } ll Svec(vector<ll> v) { ll n = 0; for (ll i = 0; i < v.size(); i++) n += v[i]; return n; } ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } ll Factorial(ll n) { ll m = 1; while (n >= 1) m *= n, n--; return m; } void runlength(string s, vector<pair<char, ll>> &p) { ll x = 1; if (s.size() == 1) { p.push_back(pair<char, ll>(s[0], 1)); } for (ll i = 0; i < s.size() - 1; i++) { if (s[i] == s[i + 1]) { x++; if (i == s.size() - 2) { p.push_back(pair<char, ll>(s[i], x)); } } else { p.push_back(pair<char, ll>(s[i], x)); x = 1; if (i == s.size() - 2) { p.push_back(pair<char, ll>(s[s.size() - 1], x)); } } } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } string Toupper(string s) { string ans = ""; rep(i, s.size()) { if ('a' <= s[i] && s[i] <= 'z') ans += (char)s[i] - 32; else ans += s[i]; } return ans; } string Tolower(string s) { string ans = ""; rep(i, s.size()) { if ('A' <= s[i] && s[i] <= 'Z') ans += (char)s[i] + 32; else ans += s[i]; } return ans; } const int MAX_N = 100010; vector<bool> sieve_of_eratosthenes() { vector<bool> isPrime(MAX_N + 1, true); for (int i = 2; i <= MAX_N; i++) { if (isPrime[i]) { for (int j = 2 * i; j <= MAX_N; j += i) { isPrime[j] = false; } } } return isPrime; } vector<pint> prime_factorize(ll n) { vector<pint> ans; for (ll p = 2; p <= sqrt(n); p++) { if (n % p != 0) continue; ll cnt = 0; while (n % p == 0) { n /= p; cnt++; } ans.push_back(make_pair(p, cnt)); } if (n != 1) ans.push_back(make_pair(n, 1)); return ans; } /*bool cmp(pint a, pint b) { return a.second < b.second; }*/ /*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/ int main() { IOS; string s; cin >> s; ll dp[100010][13]; rep(i, 100010) rep(j, 13) dp[i][j] = 0; if (s[0] == '?') rep(i, 10) dp[0][i] = 1; else dp[0][s[0] - '0'] = 1; rep(i, s.size() - 1) { if (s[i + 1] == '?') { rep(j, 13) { rep(k, 10) { dp[i + 1][(j * 10 + k) % 13] += dp[i][j]; dp[i + 1][(j * 10 + k) % 13] %= MOD; } } } else { rep(j, 13) { dp[i + 1][(j * 10 + s[i + 1] - '0') % 13] += dp[i][j]; dp[i + 1][(j * 10 + s[i + 1] - '0') % 13] %= MOD; } } } cout << dp[s.size() - 1][5] << endl; }
replace
181
183
181
183
0
p02960
C++
Runtime Error
#include <algorithm> #include <iostream> #include <stdio.h> #include <string> #include <vector> using namespace std; const int mod = 1000000007; int main() { string s; cin >> s; long long dp[10010][14] = {}; dp[0][0] = 1; int buf = 0; long long n; n = (int)(s.length()); for (int i = 1; i <= n; i++) { buf = s[i - 1] - '0'; if (s[i - 1] == '?') buf = -1; int sum = 0; if (buf != -1) { for (int j = 0; j < 13; j++) { dp[i][(j * 10 + buf) % 13] = dp[i - 1][j]; dp[i][(j * 10 + buf) % 13] %= mod; } } else { for (int j = 0; j < 13; j++) { for (int k = 0; k < 10; k++) { dp[i][(j * 10 + k) % 13] += dp[i - 1][j]; dp[i][(j * 10 + k) % 13] %= mod; } } } } cout << dp[n][5] << endl; // cout<<n<<endl; return 0; }
#include <algorithm> #include <iostream> #include <stdio.h> #include <string> #include <vector> using namespace std; const int mod = 1000000007; int main() { string s; cin >> s; long long dp[100010][14] = {}; dp[0][0] = 1; int buf = 0; long long n; n = (int)(s.length()); for (int i = 1; i <= n; i++) { buf = s[i - 1] - '0'; if (s[i - 1] == '?') buf = -1; int sum = 0; if (buf != -1) { for (int j = 0; j < 13; j++) { dp[i][(j * 10 + buf) % 13] = dp[i - 1][j]; dp[i][(j * 10 + buf) % 13] %= mod; } } else { for (int j = 0; j < 13; j++) { for (int k = 0; k < 10; k++) { dp[i][(j * 10 + k) % 13] += dp[i - 1][j]; dp[i][(j * 10 + k) % 13] %= mod; } } } } cout << dp[n][5] << endl; // cout<<n<<endl; return 0; }
replace
10
11
10
11
0
p02960
C++
Runtime Error
#include <iostream> #include <string> using namespace std; const long long MOD = 1000000007; int main() { string S; cin >> S; int n = S.size(), D = 13; long long dp[10001][13] = {}, num, m = 1, rest; dp[0][0] = 1; for (int k = 0; k < n; ++k) { for (int d = 0; d < D; ++d) { if (S[n - 1 - k] == '?') { for (num = 0; num < 10; ++num) { rest = (d + num * m) % D; dp[k + 1][rest] += dp[k][d]; dp[k + 1][rest] %= MOD; } } else { num = S[n - 1 - k] - '0'; rest = (d + num * m) % D; dp[k + 1][rest] += dp[k][d]; dp[k + 1][rest] %= MOD; } } m *= 10; m %= D; } cout << dp[n][5] << endl; }
#include <iostream> #include <string> using namespace std; const long long MOD = 1000000007; int main() { string S; cin >> S; int n = S.size(), D = 13; long long dp[100001][13] = {}, num, m = 1, rest; dp[0][0] = 1; for (int k = 0; k < n; ++k) { for (int d = 0; d < D; ++d) { if (S[n - 1 - k] == '?') { for (num = 0; num < 10; ++num) { rest = (d + num * m) % D; dp[k + 1][rest] += dp[k][d]; dp[k + 1][rest] %= MOD; } } else { num = S[n - 1 - k] - '0'; rest = (d + num * m) % D; dp[k + 1][rest] += dp[k][d]; dp[k + 1][rest] %= MOD; } } m *= 10; m %= D; } cout << dp[n][5] << endl; }
replace
12
13
12
13
0
p02960
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } #define rep(i, n) for (int i = 0; i < n; i++) #define req(i, n) for (int i = 1; i <= n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(a) a.begin(), a.end() typedef long long ll; typedef long double ld; const ll INF = 1LL << 60; const int inf = 1 << 30; int n, m, x, y, q, d; ll z, w = 0, sum = 0; int ans = 0; const int MAX = 510000; const int MOD = 1000000007; int main(void) { int dp[10010][13]; string s; int d; cin >> s; Fill(dp, 0); dp[0][0] = 1; rep(i, s.size()) { if (isdigit(s[i])) { int Si = s[i] - '0'; rep(j, 13) { dp[i + 1][(j * 10 + Si) % 13] += dp[i][j]; dp[i + 1][(j * 10 + Si) % 13] %= MOD; } } else { rep(j, 13) { rep(k, 10) { dp[i + 1][(j * 10 + k) % 13] += dp[i][j]; dp[i + 1][(j * 10 + k) % 13] %= MOD; } } } } cout << dp[s.size()][5] << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } #define rep(i, n) for (int i = 0; i < n; i++) #define req(i, n) for (int i = 1; i <= n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(a) a.begin(), a.end() typedef long long ll; typedef long double ld; const ll INF = 1LL << 60; const int inf = 1 << 30; int n, m, x, y, q, d; ll z, w = 0, sum = 0; int ans = 0; const int MAX = 510000; const int MOD = 1000000007; int main(void) { int dp[100100][13]; string s; int d; cin >> s; Fill(dp, 0); dp[0][0] = 1; rep(i, s.size()) { if (isdigit(s[i])) { int Si = s[i] - '0'; rep(j, 13) { dp[i + 1][(j * 10 + Si) % 13] += dp[i][j]; dp[i + 1][(j * 10 + Si) % 13] %= MOD; } } else { rep(j, 13) { rep(k, 10) { dp[i + 1][(j * 10 + k) % 13] += dp[i][j]; dp[i + 1][(j * 10 + k) % 13] %= MOD; } } } } cout << dp[s.size()][5] << endl; }
replace
29
30
29
30
0
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; #define ll long long const ll md = 1e9 + 7; ll dp[N][15]; string s; int n; ll solve(int idx, int val) { ll &ret = dp[idx][val]; if (ret >= 0) return ret; ret = 0; if (idx == n) { ret = (val == 5); } if (s[idx] == '?') { int tmp; for (int i = 0; i < 10; i++) { tmp = (val * 10 + i) % 13; ret += (solve(idx + 1, tmp)); ret %= md; } } else { int v = s[idx] - '0'; val = (val * 10 + v) % 13; ret += solve(idx + 1, val); ret %= md; } return ret %= md; } int main() { cin >> s; n = s.size(); memset(dp, -1ll, sizeof(dp)); cout << solve(0, 0) << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; #define ll long long const ll md = 1e9 + 7; ll dp[N][15]; string s; int n; ll solve(int idx, int val) { ll &ret = dp[idx][val]; if (ret >= 0) return ret; ret = 0; if (idx == n) { ret = (val == 5); return ret; } if (s[idx] == '?') { int tmp; for (int i = 0; i < 10; i++) { tmp = (val * 10 + i) % 13; ret += (solve(idx + 1, tmp)); ret %= md; } } else { int v = s[idx] - '0'; val = (val * 10 + v) % 13; ret += solve(idx + 1, val); ret %= md; } return ret %= md; } int main() { cin >> s; n = s.size(); memset(dp, -1ll, sizeof(dp)); cout << solve(0, 0) << endl; }
insert
15
15
15
16
-11
p02960
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < n; ++i) #define MOD 1000000007 int main() { string s; cin >> s; ll dp[15][11000] = {}; dp[0][0] = 1; rep(i, s.size()) { if (s[i] == '?') { rep(j, 13) { rep(num, 10) { dp[(j * 10 + num) % 13][i + 1] += dp[j][i]; dp[(j * 10 + num) % 13][i + 1] %= MOD; } } } else { int num = s[i] - '0'; rep(j, 13) { dp[(j * 10 + num) % 13][i + 1] += dp[j][i]; dp[(j * 10 + num) % 13][i + 1] %= MOD; } } } cout << dp[5][s.size()] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < n; ++i) #define MOD 1000000007 int main() { string s; cin >> s; ll dp[15][110000] = {}; dp[0][0] = 1; rep(i, s.size()) { if (s[i] == '?') { rep(j, 13) { rep(num, 10) { dp[(j * 10 + num) % 13][i + 1] += dp[j][i]; dp[(j * 10 + num) % 13][i + 1] %= MOD; } } } else { int num = s[i] - '0'; rep(j, 13) { dp[(j * 10 + num) % 13][i + 1] += dp[j][i]; dp[(j * 10 + num) % 13][i + 1] %= MOD; } } } cout << dp[5][s.size()] << endl; return 0; }
replace
10
11
10
11
0
p02962
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (ll i = (a); i < (b); i++) typedef uint64_t ull; typedef int64_t ll; typedef std::pair<ll, ll> PLL; using namespace std; const int MAX = 500000, MS = 2; const long long mod[] = {999999937LL, 1000000007LL}, base = 9973; struct rolling_hash { int n; vector<long long> hs[MS], pw[MS]; rolling_hash() {} rolling_hash(const string &s) { n = s.size(); for (int i = 0; i < MS; i++) { hs[i].assign(n + 1, 0); pw[i].assign(n + 1, 0); hs[i][0] = 0; pw[i][0] = 1; for (int j = 0; j < n; j++) { pw[i][j + 1] = pw[i][j] * base % mod[i]; hs[i][j + 1] = (hs[i][j] * base + s[j]) % mod[i]; } } } long long hash(int l, int r, int i) { return ((hs[i][r] - hs[i][l] * pw[i][r - l]) % mod[i] + mod[i]) % mod[i]; } bool match(int l1, int r1, int l2, int r2) { bool ret = 1; for (int i = 0; i < MS; i++) ret &= hash(l1, r1, i) == hash(l2, r2, i); return ret; } bool match(int l, int r, long long h[]) { bool ret = 1; for (int i = 0; i < MS; i++) ret &= hash(l, r, i) == h[i]; return ret; } }; class UnionFind { public: int n; std::vector<int> par; std::vector<int> num; explicit UnionFind(int n) { // [0 n)のunion find this->n = n; this->par.resize(n); this->num.resize(n, 1); for (int i = 0; i < n; i++) { this->par[i] = i; } } int root(int i) { if (par[i] == i) return i; else return par[i] = root(par[i]); } bool same(int i, int j) { return root(i) == root(j); } // もしすでに、くっ付いていたら-1を返す int unite(int i, int j) { int t = root(i); int k = root(j); if (t == k) return -1; par[t] = k; num[k] += num[t]; return 0; } int size(int i) { return num[root(i)]; } }; signed main() { string s, t; cin >> s >> t; ll N = s.size(); ll NT = t.size(); string p = ""; while (p.size() < 3 * NT) { p += s; } s = p; vector<bool> ok(N, false); // cout<<"s="<<s<<endl; // cout<<"t="<<t<<endl; auto rh = rolling_hash(t + s); for (int i = 0; i < N; i++) { // cout<<0<<" " << t.size()+i << " " << sa.prefixCommonLength(0, t.size()+i) // << endl; if(lh.prefixCommonLength(0, NT+i) >= NT ){ if (rh.match(0, NT, NT + i, 2 * NT + i)) { ok[i % N] = true; } } auto uf = UnionFind(N); rep(i, 0, N) { if (ok[i] && ok[(i + NT) % N]) { ll res = uf.unite(i, (i + NT) % N); if (res == -1) { cout << -1 << endl; return 0; } } } ll ans = 0; for (int i = 0; i < N; i++) { if (ok[i]) ans = max(ans, (ll)uf.size(i)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (ll i = (a); i < (b); i++) typedef uint64_t ull; typedef int64_t ll; typedef std::pair<ll, ll> PLL; using namespace std; const int MAX = 500000, MS = 2; const long long mod[] = {999999937LL, 1000000007LL}, base = 9973; struct rolling_hash { int n; vector<long long> hs[MS], pw[MS]; rolling_hash() {} rolling_hash(const string &s) { n = s.size(); for (int i = 0; i < MS; i++) { hs[i].assign(n + 1, 0); pw[i].assign(n + 1, 0); hs[i][0] = 0; pw[i][0] = 1; for (int j = 0; j < n; j++) { pw[i][j + 1] = pw[i][j] * base % mod[i]; hs[i][j + 1] = (hs[i][j] * base + s[j]) % mod[i]; } } } long long hash(int l, int r, int i) { return ((hs[i][r] - hs[i][l] * pw[i][r - l]) % mod[i] + mod[i]) % mod[i]; } bool match(int l1, int r1, int l2, int r2) { bool ret = 1; for (int i = 0; i < MS; i++) ret &= hash(l1, r1, i) == hash(l2, r2, i); return ret; } bool match(int l, int r, long long h[]) { bool ret = 1; for (int i = 0; i < MS; i++) ret &= hash(l, r, i) == h[i]; return ret; } }; class UnionFind { public: int n; std::vector<int> par; std::vector<int> num; explicit UnionFind(int n) { // [0 n)のunion find this->n = n; this->par.resize(n); this->num.resize(n, 1); for (int i = 0; i < n; i++) { this->par[i] = i; } } int root(int i) { if (par[i] == i) return i; else return par[i] = root(par[i]); } bool same(int i, int j) { return root(i) == root(j); } // もしすでに、くっ付いていたら-1を返す int unite(int i, int j) { int t = root(i); int k = root(j); if (t == k) return -1; par[t] = k; num[k] += num[t]; return 0; } int size(int i) { return num[root(i)]; } }; signed main() { string s, t; cin >> s >> t; ll N = s.size(); ll NT = t.size(); string p = ""; while (p.size() < 3 * NT || p.size() < 3 * N) { p += s; } s = p; vector<bool> ok(N, false); // cout<<"s="<<s<<endl; // cout<<"t="<<t<<endl; auto rh = rolling_hash(t + s); for (int i = 0; i < N; i++) { // cout<<0<<" " << t.size()+i << " " << sa.prefixCommonLength(0, t.size()+i) // << endl; if(lh.prefixCommonLength(0, NT+i) >= NT ){ if (rh.match(0, NT, NT + i, 2 * NT + i)) { ok[i % N] = true; } } auto uf = UnionFind(N); rep(i, 0, N) { if (ok[i] && ok[(i + NT) % N]) { ll res = uf.unite(i, (i + NT) % N); if (res == -1) { cout << -1 << endl; return 0; } } } ll ans = 0; for (int i = 0; i < N; i++) { if (ok[i]) ans = max(ans, (ll)uf.size(i)); } cout << ans << endl; return 0; }
replace
94
95
94
95
0
p02962
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) begin(v), end(v) #define fi first #define se second template <typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; } template <typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; using pii = pair<int, int>; constexpr ll INF = 1ll << 30; constexpr ll longINF = 1ll << 60; constexpr ll MOD = 1000000007; constexpr bool debug = 0; //---------------------------------// vector<int> z_algorithm(string s) { vector<int> res(s.size()); res[0] = s.size(); int i = 1, j = 0; while (i < s.size()) { while (i + j < s.size() && s[j] == s[i + j]) j++; res[i] = j; if (j == 0) { i++; continue; } int k = 1; while (i + k < s.size() && k + res[k] < j) res[i + k] = res[k], k++; i += k; j -= k; } return res; } vector<int> g[123456]; int indeg[1123456]; int dp[1123456]; int main() { string S, T; cin >> S >> T; while (T.size() > S.size()) S += S; string str = T + S + S; vector<int> v = z_algorithm(str); FOR(i, T.size(), T.size() + S.size()) { if (v[i] >= T.size()) { g[i - T.size()].emplace_back(i % S.size()); ++indeg[i % S.size()]; } } queue<int> que; REP(i, S.size()) if (indeg[i] == 0) que.push(i); int ans = 0; while (!que.empty()) { int u = que.front(); que.pop(); chmax(ans, dp[u]); for (int v : g[u]) { chmax(dp[v], dp[u] + 1); if (--indeg[v] == 0) que.push(v); } } REP(i, S.size()) if (indeg[i]) ans = -1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) begin(v), end(v) #define fi first #define se second template <typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; } template <typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; using pii = pair<int, int>; constexpr ll INF = 1ll << 30; constexpr ll longINF = 1ll << 60; constexpr ll MOD = 1000000007; constexpr bool debug = 0; //---------------------------------// vector<int> z_algorithm(string s) { vector<int> res(s.size()); res[0] = s.size(); int i = 1, j = 0; while (i < s.size()) { while (i + j < s.size() && s[j] == s[i + j]) j++; res[i] = j; if (j == 0) { i++; continue; } int k = 1; while (i + k < s.size() && k + res[k] < j) res[i + k] = res[k], k++; i += k; j -= k; } return res; } vector<int> g[1123456]; int indeg[1123456]; int dp[1123456]; int main() { string S, T; cin >> S >> T; while (T.size() > S.size()) S += S; string str = T + S + S; vector<int> v = z_algorithm(str); FOR(i, T.size(), T.size() + S.size()) { if (v[i] >= T.size()) { g[i - T.size()].emplace_back(i % S.size()); ++indeg[i % S.size()]; } } queue<int> que; REP(i, S.size()) if (indeg[i] == 0) que.push(i); int ans = 0; while (!que.empty()) { int u = que.front(); que.pop(); chmax(ans, dp[u]); for (int v : g[u]) { chmax(dp[v], dp[u] + 1); if (--indeg[v] == 0) que.push(v); } } REP(i, S.size()) if (indeg[i]) ans = -1; cout << ans << endl; return 0; }
replace
54
55
54
55
0
p02962
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; char laz[maxn]; int pi[10 * maxn]; bool prefix_function(const string &s, const string &t) { /// search t on s int m = (int)t.length(); string ss = t + '#' + s; int n = (int)ss.length(); pi[0] = 0; for (int i = 1; i < n; i++) { int j = pi[i - 1]; while (j > 0 && ss[i] != ss[j]) j = pi[j - 1]; if (ss[i] == ss[j]) j++; pi[i] = j; if (pi[i] == m && i > m) { return true; } } return false; } string s, t, a, ss, tt; /** There exists a non-negative integer j such that the concatenation of i copies of t is a substring of the concatenation of j copies of s. */ int main() { scanf("%s", laz); ss = string(laz); scanf("%s", laz); t = string(laz); s = ss; while ((int)s.length() <= (int)t.length() + (int)ss.length()) { s += ss; } s += ss; int l = 1, r = ((int)s.length()) / ((int)t.length()), mid, c = -1; while (l <= r) { mid = (l + r) >> 1; a = t; for (int i = 1; i < mid; i++) { a += t; } if (prefix_function(s, a)) { c = mid; l = mid + 1; } else { r = mid - 1; } } if (c == -1) { return !printf("0"); } s += s; l = 1, r = ((int)s.length()) / ((int)t.length()); int cc = -1; while (l <= r) { mid = (l + r) >> 1; a = t; for (int i = 1; i < mid; i++) { a += t; } if (prefix_function(s, a)) { cc = mid; l = mid + 1; } else { r = mid - 1; } } if (cc == c) { return !printf("%d\n", cc); } else { return !printf("-1"); } } /* Good Luck -Lci70121 */
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; char laz[maxn]; int pi[16 * maxn]; bool prefix_function(const string &s, const string &t) { /// search t on s int m = (int)t.length(); string ss = t + '#' + s; int n = (int)ss.length(); pi[0] = 0; for (int i = 1; i < n; i++) { int j = pi[i - 1]; while (j > 0 && ss[i] != ss[j]) j = pi[j - 1]; if (ss[i] == ss[j]) j++; pi[i] = j; if (pi[i] == m && i > m) { return true; } } return false; } string s, t, a, ss, tt; /** There exists a non-negative integer j such that the concatenation of i copies of t is a substring of the concatenation of j copies of s. */ int main() { scanf("%s", laz); ss = string(laz); scanf("%s", laz); t = string(laz); s = ss; while ((int)s.length() <= (int)t.length() + (int)ss.length()) { s += ss; } s += ss; int l = 1, r = ((int)s.length()) / ((int)t.length()), mid, c = -1; while (l <= r) { mid = (l + r) >> 1; a = t; for (int i = 1; i < mid; i++) { a += t; } if (prefix_function(s, a)) { c = mid; l = mid + 1; } else { r = mid - 1; } } if (c == -1) { return !printf("0"); } s += s; l = 1, r = ((int)s.length()) / ((int)t.length()); int cc = -1; while (l <= r) { mid = (l + r) >> 1; a = t; for (int i = 1; i < mid; i++) { a += t; } if (prefix_function(s, a)) { cc = mid; l = mid + 1; } else { r = mid - 1; } } if (cc == c) { return !printf("%d\n", cc); } else { return !printf("-1"); } } /* Good Luck -Lci70121 */
replace
4
5
4
5
0
p02962
C++
Time Limit Exceeded
#include <algorithm> // minmax, sort, swap #include <climits> // INT_MIN, LLONG_MIN #include <cmath> // long, trig, pow #include <cstdio> // printf, scanf #include <deque> // deque #include <functional> // std::function<void(int)> #include <iomanip> // cout<<setprecision(n) #include <iostream> // cin, cout, cerr, clog #include <map> // key-value pairs sorted by keys #include <numeric> // iota, accumulate, inner_product #include <queue> // queue, priority_queue #include <set> // set #include <string> // string, stoi, to_string #include <unordered_map> // hashed by keys #include <unordered_set> // hashed by keys #include <vector> // vector #define rep(i, n) for (int i = 0; i < n; i++) #define ENDL "\n" #define print(i) std::cout << (i) << "\n" #define int long long // at least int64 > 9*10^18 #define all(v) v.begin(), v.end() #define ceil(a, b) (a % b ? a / b + 1 : a / b) #define dump1(v) \ for (auto i : v) \ std::cout << i << ' '; \ std::cout << "\n"; struct FastIO { FastIO() { std::cin.tie(0); std::ios_base::sync_with_stdio(0); } } fastio; struct ZAlgorithm { std::vector<int> z; ZAlgorithm(std::string s) : z(s.size(), 0) { int l, r; // [l,r) l = r = 0; for (int i = 1; i < s.size(); i++) { if (i >= r) { l = r = i; while (r < s.size() && s[r] == s[r - l]) r++; z[i] = r - l; continue; } if (z[i - l] < r - i) { z[i] = z[i - l]; continue; } l = i; while (r < s.size() && s[r] == s[r - l]) r++; z[i] = r - l; continue; } z[0] = s.size(); } }; int dfs(int i, int c, std::vector<int> &to, std::vector<int> &went) { if (to[c] == i) return -1; if (to[c] == -1) return 0; if (went[c] > 0) return went[c]; int x = dfs(i, to[c], to, went); if (x == -1) return -1; return went[c] = x + 1; } signed main() { std::string s; std::string t; std::cin >> s >> t; std::string a = ""; int t_sz = t.size(); int s_sz = s.size(); int f = ceil(t_sz, s_sz) + 1; rep(i, f) a = a + s; std::string x = t + '$' + a; ZAlgorithm z(x); std::vector<int> zz(s_sz); rep(i, s_sz) zz[i] = z.z[t_sz + 1 + i]; std::vector<int> to(s_sz, -1); rep(i, s_sz) if (zz[i] == t_sz) to[i] = (i + t_sz) % s_sz; std::vector<int> went(s_sz, 0); rep(i, s_sz) { if (zz[i] != t_sz) continue; if (dfs(i, i, to, went) == -1) { print(-1); return 0; } } int max = 0; for (auto i : went) max = std::max(max, i); print(max); return 0; }
#include <algorithm> // minmax, sort, swap #include <climits> // INT_MIN, LLONG_MIN #include <cmath> // long, trig, pow #include <cstdio> // printf, scanf #include <deque> // deque #include <functional> // std::function<void(int)> #include <iomanip> // cout<<setprecision(n) #include <iostream> // cin, cout, cerr, clog #include <map> // key-value pairs sorted by keys #include <numeric> // iota, accumulate, inner_product #include <queue> // queue, priority_queue #include <set> // set #include <string> // string, stoi, to_string #include <unordered_map> // hashed by keys #include <unordered_set> // hashed by keys #include <vector> // vector #define rep(i, n) for (int i = 0; i < n; i++) #define ENDL "\n" #define print(i) std::cout << (i) << "\n" #define int long long // at least int64 > 9*10^18 #define all(v) v.begin(), v.end() #define ceil(a, b) (a % b ? a / b + 1 : a / b) #define dump1(v) \ for (auto i : v) \ std::cout << i << ' '; \ std::cout << "\n"; struct FastIO { FastIO() { std::cin.tie(0); std::ios_base::sync_with_stdio(0); } } fastio; struct ZAlgorithm { std::vector<int> z; ZAlgorithm(std::string s) : z(s.size(), 0) { int l, r; // [l,r) l = r = 0; for (int i = 1; i < s.size(); i++) { if (i >= r) { l = r = i; while (r < s.size() && s[r] == s[r - l]) r++; z[i] = r - l; continue; } if (z[i - l] < r - i) { z[i] = z[i - l]; continue; } l = i; while (r < s.size() && s[r] == s[r - l]) r++; z[i] = r - l; continue; } z[0] = s.size(); } }; int dfs(int i, int c, std::vector<int> &to, std::vector<int> &went) { if (to[c] == i) return -1; if (to[c] == -1) return 0; if (went[c] > 0) return went[c]; int x = dfs(i, to[c], to, went); if (x == -1) return -1; return went[c] = x + 1; } signed main() { std::string s; std::string t; std::cin >> s >> t; std::string a = ""; int t_sz = t.size(); int s_sz = s.size(); int f = ceil(t_sz, s_sz) + 1; rep(i, f) a += s; std::string x = t + '$' + a; ZAlgorithm z(x); std::vector<int> zz(s_sz); rep(i, s_sz) zz[i] = z.z[t_sz + 1 + i]; std::vector<int> to(s_sz, -1); rep(i, s_sz) if (zz[i] == t_sz) to[i] = (i + t_sz) % s_sz; std::vector<int> went(s_sz, 0); rep(i, s_sz) { if (zz[i] != t_sz) continue; if (dfs(i, i, to, went) == -1) { print(-1); return 0; } } int max = 0; for (auto i : went) max = std::max(max, i); print(max); return 0; }
replace
89
90
89
90
TLE
p02962
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; char laz[maxn]; int pi[8 * maxn], dp[8 * maxn]; int prefix_function(const string &s, const string &t) { /// search t on s int m = (int)t.length(); int n = t.length() + s.length() + 1; auto ss = [&](int idx) { if (idx == m) return '#'; if (idx < m) return t[idx]; return s[idx - m - 1]; }; pi[0] = 0; for (int i = 1; i < n; i++) { int j = pi[i - 1]; while (j > 0 && ss(i) != ss(j)) j = pi[j - 1]; if (ss(i) == ss(j)) j++; pi[i] = j; } int ma = -1; for (int i = n - 1; i > m; i--) { dp[i] = 0; if (pi[i] == m) { dp[i] = 1; } if (i + m < n && dp[i] == 1) { dp[i] += dp[i + m]; } ma = max(ma, dp[i]); } return ma; } string s, t, a, ss, tt; /** There exists a non-negative integer j such that the concatenation of i copies of t is a substring of the concatenation of j copies of s. */ int main() { scanf("%s", laz); ss = string(laz); scanf("%s", laz); t = string(laz); s = ss; while ((int)s.length() <= (int)t.length() + (int)ss.length()) { s += ss; } s += ss; int c = prefix_function(s, t); if (c == -1) { return !printf("0"); } s += s; int cc = prefix_function(s, t); if (cc == c) { return !printf("%d\n", cc); } else { return !printf("-1"); } } /* Good Luck -Lci70121 */
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; char laz[maxn]; int pi[12 * maxn], dp[12 * maxn]; int prefix_function(const string &s, const string &t) { /// search t on s int m = (int)t.length(); int n = t.length() + s.length() + 1; auto ss = [&](int idx) { if (idx == m) return '#'; if (idx < m) return t[idx]; return s[idx - m - 1]; }; pi[0] = 0; for (int i = 1; i < n; i++) { int j = pi[i - 1]; while (j > 0 && ss(i) != ss(j)) j = pi[j - 1]; if (ss(i) == ss(j)) j++; pi[i] = j; } int ma = -1; for (int i = n - 1; i > m; i--) { dp[i] = 0; if (pi[i] == m) { dp[i] = 1; } if (i + m < n && dp[i] == 1) { dp[i] += dp[i + m]; } ma = max(ma, dp[i]); } return ma; } string s, t, a, ss, tt; /** There exists a non-negative integer j such that the concatenation of i copies of t is a substring of the concatenation of j copies of s. */ int main() { scanf("%s", laz); ss = string(laz); scanf("%s", laz); t = string(laz); s = ss; while ((int)s.length() <= (int)t.length() + (int)ss.length()) { s += ss; } s += ss; int c = prefix_function(s, t); if (c == -1) { return !printf("0"); } s += s; int cc = prefix_function(s, t); if (cc == c) { return !printf("%d\n", cc); } else { return !printf("-1"); } } /* Good Luck -Lci70121 */
replace
4
5
4
5
0
p02962
C++
Runtime Error
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define debug(x) cerr << #x << " " << x << '\n' using namespace std; using ll = long long; using pii = pair<int, int>; using pli = pair<ll, int>; const int INF = 0x3f3f3f3f, N = 5e5 + 5; const ll LINF = 1e18 + 5; char s[N], t[N]; int n, m; int nxt[N], in[N], dp[N]; bool ok[N]; vector<int> G[N]; void kmp_pre(char s[], int m, int nxt[]) { int i = 0, j = nxt[0] = -1; while (i < m) { while (j != -1 && s[i] != s[j]) j = nxt[j]; nxt[++i] = ++j; } } void kmp_work(char s[], int m, char t[], int n) { int i = 0, j = 0; kmp_pre(s, m, nxt); while (i < n) { while (j != -1 && t[i] != s[j]) j = nxt[j]; i++; j++; if (j >= m) { ok[i - m] = 1; j = nxt[j]; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> s >> t; n = strlen(s), m = strlen(t); int nn = n; while (nn < n + m) { for (int i = nn, j = 0; j < n; i++, j++) s[i] = s[j]; nn += n; s[nn] = 0; } kmp_work(t, m, s, nn); for (int i = 0; i < n; i++) { if (ok[i] && ok[(i + m) % n]) { in[(i + m) % n]++; G[i].pb((i + m) % n); } } queue<int> q; for (int i = 0; i < n; i++) { if (!in[i]) { q.push(i); dp[i] = ok[i]; } } while (sz(q)) { int u = q.front(); q.pop(); for (int v : G[u]) { in[v]--; if (!in[v]) { q.push(v); dp[v] = dp[u] + 1; } } } int ans = 0; bool cycle = 0; for (int i = 0; i < n; i++) if (in[i]) cycle = 1; if (cycle) ans = -1; else ans = *max_element(dp, dp + n); cout << ans; return 0; }
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define debug(x) cerr << #x << " " << x << '\n' using namespace std; using ll = long long; using pii = pair<int, int>; using pli = pair<ll, int>; const int INF = 0x3f3f3f3f, N = 2e6 + 5; const ll LINF = 1e18 + 5; char s[N], t[N]; int n, m; int nxt[N], in[N], dp[N]; bool ok[N]; vector<int> G[N]; void kmp_pre(char s[], int m, int nxt[]) { int i = 0, j = nxt[0] = -1; while (i < m) { while (j != -1 && s[i] != s[j]) j = nxt[j]; nxt[++i] = ++j; } } void kmp_work(char s[], int m, char t[], int n) { int i = 0, j = 0; kmp_pre(s, m, nxt); while (i < n) { while (j != -1 && t[i] != s[j]) j = nxt[j]; i++; j++; if (j >= m) { ok[i - m] = 1; j = nxt[j]; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> s >> t; n = strlen(s), m = strlen(t); int nn = n; while (nn < n + m) { for (int i = nn, j = 0; j < n; i++, j++) s[i] = s[j]; nn += n; s[nn] = 0; } kmp_work(t, m, s, nn); for (int i = 0; i < n; i++) { if (ok[i] && ok[(i + m) % n]) { in[(i + m) % n]++; G[i].pb((i + m) % n); } } queue<int> q; for (int i = 0; i < n; i++) { if (!in[i]) { q.push(i); dp[i] = ok[i]; } } while (sz(q)) { int u = q.front(); q.pop(); for (int v : G[u]) { in[v]--; if (!in[v]) { q.push(v); dp[v] = dp[u] + 1; } } } int ans = 0; bool cycle = 0; for (int i = 0; i < n; i++) if (in[i]) cycle = 1; if (cycle) ans = -1; else ans = *max_element(dp, dp + n); cout << ans; return 0; }
replace
10
11
10
11
0
p02962
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; vector<int> table, res, v[500000], u[500000]; int ch[500000], ans, cnt, tmp, L; string s, t, S; map<int, int> mp; vector<int> pre_kmp(string s) { vector<int> v(s.size() + 1); int k; v[0] = -1; for (int i = 1; i <= s.size(); i++) { k = v[i - 1]; while (k >= 0) { if (s[k] == s[i - 1]) break; else k = v[k]; } v[i] = k + 1; } return v; } void match(string s, string t) { int head = 0, j = 0, slen = s.size(), tlen = t.size(); while (head < slen) { if (t[j] == s[(head + j) % slen]) { if (++j != tlen) continue; res.push_back(head); v[head].push_back((head + tlen) % slen); u[(head + tlen) % slen].push_back(head); } head += j - table[j], j = max(table[j], 0); } } int rdfs(int a, int b) { for (auto x : u[a]) { if (x == b) return -1; return rdfs(x, b); } return a; } int dfs(int a, int cnt) { ch[a] = 1; for (auto x : v[a]) { return dfs(x, cnt + 1); } return cnt; } int main(void) { cin >> S >> t; s = S; while (s.size() < t.size()) { s += S; } // cout<<s<<" "<<t<<endl; table = pre_kmp(t); match(s, t); // for(auto x:res)cout<<x<<"res"<<endl; // cout<<rdfs(0,0)<<endl; for (int i = 0; i < s.size(); i++) { if (ch[i] != 0 || v[i].size() == 0) continue; // cout<<ch[i]<<" "<<i<<endl; L = rdfs(i, i); if (L == -1) { cout << -1 << endl; return 0; } ans = max(ans, dfs(L, 0)); // cout<<ans<<endl; } cout << ans << endl; }
#include <bits/stdc++.h> #include <iostream> using namespace std; vector<int> table, res, v[1000000], u[1000000]; int ch[1000000], ans, cnt, tmp, L; string s, t, S; map<int, int> mp; vector<int> pre_kmp(string s) { vector<int> v(s.size() + 1); int k; v[0] = -1; for (int i = 1; i <= s.size(); i++) { k = v[i - 1]; while (k >= 0) { if (s[k] == s[i - 1]) break; else k = v[k]; } v[i] = k + 1; } return v; } void match(string s, string t) { int head = 0, j = 0, slen = s.size(), tlen = t.size(); while (head < slen) { if (t[j] == s[(head + j) % slen]) { if (++j != tlen) continue; res.push_back(head); v[head].push_back((head + tlen) % slen); u[(head + tlen) % slen].push_back(head); } head += j - table[j], j = max(table[j], 0); } } int rdfs(int a, int b) { for (auto x : u[a]) { if (x == b) return -1; return rdfs(x, b); } return a; } int dfs(int a, int cnt) { ch[a] = 1; for (auto x : v[a]) { return dfs(x, cnt + 1); } return cnt; } int main(void) { cin >> S >> t; s = S; while (s.size() < t.size()) { s += S; } // cout<<s<<" "<<t<<endl; table = pre_kmp(t); match(s, t); // for(auto x:res)cout<<x<<"res"<<endl; // cout<<rdfs(0,0)<<endl; for (int i = 0; i < s.size(); i++) { if (ch[i] != 0 || v[i].size() == 0) continue; // cout<<ch[i]<<" "<<i<<endl; L = rdfs(i, i); if (L == -1) { cout << -1 << endl; return 0; } ans = max(ans, dfs(L, 0)); // cout<<ans<<endl; } cout << ans << endl; }
replace
3
5
3
5
0