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
p02844
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <math.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; int main() { int N, check; string S; int ans = 0; vector<int> p(100); cin >> N >> S; for (int i = 0; i < 1000; i++) { check = 0; p.at(2) = i % 10; p.at(1) = (i / 10) % 10; p.at(0) = i / 100; for (int j = 0; j < S.size(); j++) { if (p.at(check) == S.at(j) - '0') check++; } if (check == 3) ans++; } cout << ans; }
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <math.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; int main() { int N, check; string S; int ans = 0; vector<int> p(100, 10); cin >> N >> S; for (int i = 0; i < 1000; i++) { check = 0; p.at(2) = i % 10; p.at(1) = (i / 10) % 10; p.at(0) = i / 100; for (int j = 0; j < S.size(); j++) { if (p.at(check) == S.at(j) - '0') check++; } if (check == 3) ans++; } cout << ans; }
replace
13
14
13
14
0
p02844
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define eb emplace_back #define mp make_pair using namespace std; string s, t; int n, ans; bool check() { for (int i = 0; i < s.length(); i++) { if (s[i] == t[0]) { for (int j = i + 1; j < s.length(); j++) { if (s[j] == t[1]) { for (int k = j + 1; k < s.length(); k++) { if (s[k] == t[2]) { return true; } } } } return false; } } return false; } int main() { cin >> n >> s; t = " "; for (char i = '0'; i <= '9'; i++) { for (char j = '0'; j <= '9'; j++) { for (char k = '0'; k <= '9'; k++) { t[0] = i, t[1] = j, t[2] = k; if (check()) { ans++; } } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define eb emplace_back #define mp make_pair using namespace std; string s, t; int n, ans; bool check() { for (int i = 0; i < s.length(); i++) { if (s[i] == t[0]) { for (int j = i + 1; j < s.length(); j++) { if (s[j] == t[1]) { for (int k = j + 1; k < s.length(); k++) { if (s[k] == t[2]) { return true; } } return false; } } return false; } } return false; } int main() { cin >> n >> s; t = " "; for (char i = '0'; i <= '9'; i++) { for (char j = '0'; j <= '9'; j++) { for (char k = '0'; k <= '9'; k++) { t[0] = i, t[1] = j, t[2] = k; if (check()) { ans++; } } } } cout << ans << endl; return 0; }
insert
19
19
19
20
TLE
p02844
C++
Runtime Error
#include <bits/stdc++.h> int n, m; std::map<std::string, int> cnt; std::string s; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cin >> n; std::cin >> s; std::vector<int> max_pos(n, -1); std::vector<int> min_pos(n, n + 1); for (int i = 0; i <= 9; ++i) min_pos[i] = n + 1, max_pos[i] = -1; for (int i = 0; i < n; ++i) { int m = s[i] - '0'; max_pos[m] = i; min_pos[m] = std::min(min_pos[m], i); } std::map<std::string, int> memo; for (int i = 0; i < n; ++i) { int key = s[i] - '0'; for (int l = 0; l <= 9; ++l) { for (int r = 0; r <= 9; ++r) { if (max_pos[r] == -1 or min_pos[l] == n + 1) continue; if (min_pos[l] < i && i < max_pos[r]) memo[std::to_string(l) + std::to_string(key) + std::to_string(r)] += 1; } } } std::cout << memo.size() << '\n'; }
#include <bits/stdc++.h> int n, m; std::map<std::string, int> cnt; std::string s; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cin >> n; std::cin >> s; std::vector<int> max_pos(10, -1); std::vector<int> min_pos(10, n + 1); for (int i = 0; i <= 9; ++i) min_pos[i] = n + 1, max_pos[i] = -1; for (int i = 0; i < n; ++i) { int m = s[i] - '0'; max_pos[m] = i; min_pos[m] = std::min(min_pos[m], i); } std::map<std::string, int> memo; for (int i = 0; i < n; ++i) { int key = s[i] - '0'; for (int l = 0; l <= 9; ++l) { for (int r = 0; r <= 9; ++r) { if (max_pos[r] == -1 or min_pos[l] == n + 1) continue; if (min_pos[l] < i && i < max_pos[r]) memo[std::to_string(l) + std::to_string(key) + std::to_string(r)] += 1; } } } std::cout << memo.size() << '\n'; }
replace
9
11
9
11
-6
malloc(): corrupted top size
p02844
C++
Time Limit Exceeded
// INCLUDE //------------------------------------------ #include <algorithm> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <math.h> #include <string> #include <vector> // DEFINE //------------------------------------------ #define ll long long #define ALLv(a) (a).begin(), (a).end() #define ALL(a, n) (a), (a) + n #define vi vector<long long> #define vd vector<long double> #define vs vector<string> // CONST //------------------------------------------ #define INF 1010000000000000017LL #define MOD 1000000007LL #define EPS 1e-12 #define PI 3.14159265358979323846 // REPEAT //------------------------------------------ #define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++) #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define REPS(i, x) for (ll(i) = 1; (i) <= (x); (i)++) #define RREP(i, x) for (ll(i) = (x)-1; (i) >= 0; (i)--) #define RREPS(i, x) for (ll(i) = (x); (i) > 0; (i)--) #define WREP(i, in, j, jn) REP(i, in) REP(j, jn) using namespace std; //------------------------------------------- int main(void) { ll N; string S; cin >> N >> S; bool flag[1000]; REP(i, 1000) flag[i] = false; ll count = 0; ll p = 0; REP(i, N - 2) FOR(j, i + 1, N - 1) FOR(k, j + 1, N) { p = (S[i] - '0') * 100 + (S[j] - '0') * 10 + (S[k] - '0'); flag[p] = true; } REP(i, 1000) { if (flag[i]) count++; } cout << count; return 0; }
// INCLUDE //------------------------------------------ #include <algorithm> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <math.h> #include <string> #include <vector> // DEFINE //------------------------------------------ #define ll long long #define ALLv(a) (a).begin(), (a).end() #define ALL(a, n) (a), (a) + n #define vi vector<long long> #define vd vector<long double> #define vs vector<string> // CONST //------------------------------------------ #define INF 1010000000000000017LL #define MOD 1000000007LL #define EPS 1e-12 #define PI 3.14159265358979323846 // REPEAT //------------------------------------------ #define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++) #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define REPS(i, x) for (ll(i) = 1; (i) <= (x); (i)++) #define RREP(i, x) for (ll(i) = (x)-1; (i) >= 0; (i)--) #define RREPS(i, x) for (ll(i) = (x); (i) > 0; (i)--) #define WREP(i, in, j, jn) REP(i, in) REP(j, jn) using namespace std; //------------------------------------------- int main(void) { ll N; string S; cin >> N >> S; bool flag[1000]; REP(i, 1000) flag[i] = false; ll count = 0; ll p = 0; ll IN, JN, KN; bool in[10], jn[10], kn[10]; REP(i, 10) in[i] = jn[i] = kn[i] = false; REP(i, N - 2) { IN = S[i] - '0'; if (!in[IN]) { in[IN] = true; FOR(j, i + 1, N - 1) { JN = S[j] - '0'; if (!jn[JN]) { jn[JN] = true; FOR(k, j + 1, N) { KN = S[k] - '0'; if (!kn[KN]) { kn[KN] = true; p = IN * 100 + JN * 10 + KN; flag[p] = true; } } REP(i, 10) kn[i] = false; } } REP(i, 10) jn[i] = false; } } REP(i, 1000) { if (flag[i]) count++; } cout << count; return 0; }
replace
43
46
43
67
TLE
p02844
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int N; string S; int dp[30000][11][11][11]; bool used[10][10][10]; int ans; void dfs(int n, int a, int b, int c) { if (dp[n][a][b][c]) return; dp[n][a][b][c] = 1; if (n == N || c < 10) { if (a < 10 && b < 10 && c < 10) { if (!used[a][b][c]) ans++; used[a][b][c] = true; } return; } dfs(n + 1, a, b, c); if (a == 10) { dfs(n + 1, S[n] - '0', b, c); } else if (b == 10) { dfs(n + 1, a, S[n] - '0', c); } else if (c == 10) { dfs(n + 1, a, b, S[n] - '0'); } return; } struct St { int n, a, b, c; St(int n, int a, int b, int c) : n(n), a(a), b(b), c(c){}; }; void solve() { stack<St> st; st.push(St(0, 10, 10, 10)); while (st.size()) { St q = st.top(); st.pop(); int n = q.n, a = q.a, b = q.b, c = q.c; if (dp[n][a][b][c]) continue; dp[n][a][b][c] = 1; if (n == N || c < 10) { if (a < 10 && b < 10 && c < 10) { if (!used[a][b][c]) ans++; used[a][b][c] = true; } continue; } st.push(St(n + 1, a, b, c)); if (a == 10) { st.push(St(n + 1, S[n] - '0', b, c)); } else if (b == 10) { st.push(St(n + 1, a, S[n] - '0', c)); } else if (c == 10) { st.push(St(n + 1, a, b, S[n] - '0')); } } } signed main() { cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(12); cin >> N; cin >> S; // dfs(0, 10, 10, 10); solve(); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int N; string S; int dp[30010][11][11][11]; bool used[10][10][10]; int ans; void dfs(int n, int a, int b, int c) { if (dp[n][a][b][c]) return; dp[n][a][b][c] = 1; if (n == N || c < 10) { if (a < 10 && b < 10 && c < 10) { if (!used[a][b][c]) ans++; used[a][b][c] = true; } return; } dfs(n + 1, a, b, c); if (a == 10) { dfs(n + 1, S[n] - '0', b, c); } else if (b == 10) { dfs(n + 1, a, S[n] - '0', c); } else if (c == 10) { dfs(n + 1, a, b, S[n] - '0'); } return; } struct St { int n, a, b, c; St(int n, int a, int b, int c) : n(n), a(a), b(b), c(c){}; }; void solve() { stack<St> st; st.push(St(0, 10, 10, 10)); while (st.size()) { St q = st.top(); st.pop(); int n = q.n, a = q.a, b = q.b, c = q.c; if (dp[n][a][b][c]) continue; dp[n][a][b][c] = 1; if (n == N || c < 10) { if (a < 10 && b < 10 && c < 10) { if (!used[a][b][c]) ans++; used[a][b][c] = true; } continue; } st.push(St(n + 1, a, b, c)); if (a == 10) { st.push(St(n + 1, S[n] - '0', b, c)); } else if (b == 10) { st.push(St(n + 1, a, S[n] - '0', c)); } else if (c == 10) { st.push(St(n + 1, a, b, S[n] - '0')); } } } signed main() { cin.tie(0); ios_base::sync_with_stdio(0); cout << fixed << setprecision(12); cin >> N; cin >> S; // dfs(0, 10, 10, 10); solve(); cout << ans << endl; return 0; }
replace
6
7
6
7
-11
p02844
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define per(i, a, b) for (int i = (a); i >= (b); --i) #define ll long long #define mp make_pair #define pb push_back #define debug(...) fprintf(stderr, __VA_ARGS__) using namespace std; template <typename T> void ckmax(T &a, T b) { if (b > a) a = b; } template <typename T> void ckmin(T &a, T b) { if (b < a) a = b; } int f[10][10][10], g[10][10], h[10], n, a[20000 + 5]; char tmp[30000 + 5]; int main() { scanf("%d", &n); scanf("%s", tmp + 1); rep(i, 1, n) { a[i] = tmp[i] - '0'; rep(x, 0, 9) rep(y, 0, 9) f[x][y][a[i]] |= g[x][y]; rep(x, 0, 9) g[x][a[i]] |= h[x]; h[a[i]] = 1; } int ans = 0; rep(x, 0, 9) rep(y, 0, 9) rep(z, 0, 9) ans += f[x][y][z]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define per(i, a, b) for (int i = (a); i >= (b); --i) #define ll long long #define mp make_pair #define pb push_back #define debug(...) fprintf(stderr, __VA_ARGS__) using namespace std; template <typename T> void ckmax(T &a, T b) { if (b > a) a = b; } template <typename T> void ckmin(T &a, T b) { if (b < a) a = b; } int f[10][10][10], g[10][10], h[10], n, a[30000 + 5]; char tmp[30000 + 5]; int main() { scanf("%d", &n); scanf("%s", tmp + 1); rep(i, 1, n) { a[i] = tmp[i] - '0'; rep(x, 0, 9) rep(y, 0, 9) f[x][y][a[i]] |= g[x][y]; rep(x, 0, 9) g[x][a[i]] |= h[x]; h[a[i]] = 1; } int ans = 0; rep(x, 0, 9) rep(y, 0, 9) rep(z, 0, 9) ans += f[x][y][z]; cout << ans << endl; return 0; }
replace
17
18
17
18
0
p02844
C++
Runtime Error
#pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> #define int long long using namespace std; vector<vector<int>> s; void find(vector<int> a, int k) { for (int i = 0; i < 10; i++) { vector<int> temp = a; temp.push_back(i); if (k < 4) find(temp, k + 1); else { s.push_back(a); break; } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("INPUT.txt", "r", stdin); freopen("OUTPUT.txt", "w", stdout); #endif // -------------------------------------Code starts // here--------------------------------------------------------------------- vector<int> tt; find(tt, 1); int n; cin >> n; string str; cin >> str; int cnt = 0; for (auto i : s) { int ind = 0; for (int j = 0; j < n; j++) { if (i[ind] == str[j] - '0') { ind++; if (ind == 3) break; } } if (ind == 3) { cnt++; } } cout << cnt; // -------------------------------------Code ends // here------------------------------------------------------ clock_t clk; clk = clock(); clk = clock() - clk; cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC << "\n"; return 0; }
#pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> #define int long long using namespace std; vector<vector<int>> s; void find(vector<int> a, int k) { for (int i = 0; i < 10; i++) { vector<int> temp = a; temp.push_back(i); if (k < 4) find(temp, k + 1); else { s.push_back(a); break; } } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen ("INPUT.txt" , "r" , stdin); // freopen ("OUTPUT.txt" , "w" , stdout); // #endif // -------------------------------------Code starts // here--------------------------------------------------------------------- vector<int> tt; find(tt, 1); int n; cin >> n; string str; cin >> str; int cnt = 0; for (auto i : s) { int ind = 0; for (int j = 0; j < n; j++) { if (i[ind] == str[j] - '0') { ind++; if (ind == 3) break; } } if (ind == 3) { cnt++; } } cout << cnt; // -------------------------------------Code ends // here------------------------------------------------------ clock_t clk; clk = clock(); clk = clock() - clk; cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC << "\n"; return 0; }
replace
22
26
22
26
0
Time: 0.000003
p02845
C++
Runtime Error
#include <bits/stdc++.h> #include <iomanip> using namespace std; #define reps(i, s, n) for (int i = s; i < n; i++) #define rep(i, n) reps(i, 0, n) #define Rreps(i, n, e) for (int i = n - 1; i >= e; --i) #define Rrep(i, n) Rreps(i, n, 0) #define ALL(a) a.begin(), a.end() #define fi first #define se second #define mp make_pair typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; ll N, M, H, W, K, Q, A, B; string S; // const ll MOD = 998244353; const ll MOD = (1e+9) + 7; const ll INF = 1LL << 60; typedef pair<ll, ll> P; int main() { cin >> N; vec num(3, 0); ll ans = 1; rep(i, N) { cin >> A; ll temp = 0, id = -1; rep(j, 3) { if (num[j] == A) { ++temp; id = (id == -1 ? j : id); } } (ans *= temp) %= MOD; ++num[id]; } cout << ans << endl; }
#include <bits/stdc++.h> #include <iomanip> using namespace std; #define reps(i, s, n) for (int i = s; i < n; i++) #define rep(i, n) reps(i, 0, n) #define Rreps(i, n, e) for (int i = n - 1; i >= e; --i) #define Rrep(i, n) Rreps(i, n, 0) #define ALL(a) a.begin(), a.end() #define fi first #define se second #define mp make_pair typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; ll N, M, H, W, K, Q, A, B; string S; // const ll MOD = 998244353; const ll MOD = (1e+9) + 7; const ll INF = 1LL << 60; typedef pair<ll, ll> P; int main() { cin >> N; vec num(3, 0); ll ans = 1; rep(i, N) { cin >> A; ll temp = 0, id = -1; rep(j, 3) { if (num[j] == A) { ++temp; id = (id == -1 ? j : id); } } if (id != -1) { (ans *= temp) %= MOD; ++num[id]; } else { ans = 0; break; } } cout << ans << endl; }
replace
35
37
35
42
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vll = vector<long long>; using vp = vector<pair<int, int>>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; using vvll = vector<vector<long long>>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; } const int mod = 1000000007; // const int mod = 998244353; struct mint { long long x; mint(long long x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(long long t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; vi cnt(n - 1, 0); mint ans = 1; rep(i, n) { if (a[i] == 0) { ans *= 3 - cnt[0]; cnt[0]++; } else { ans *= cnt[a[i] - 1] - cnt[a[i]]; cnt[a[i]]++; } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vc = vector<char>; using vb = vector<bool>; using vs = vector<string>; using vll = vector<long long>; using vp = vector<pair<int, int>>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; using vvll = vector<vector<long long>>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; } const int mod = 1000000007; // const int mod = 998244353; struct mint { long long x; mint(long long x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(long long t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; vi cnt(n, 0); mint ans = 1; rep(i, n) { if (a[i] == 0) { ans *= 3 - cnt[0]; cnt[0]++; } else { ans *= cnt[a[i] - 1] - cnt[a[i]]; cnt[a[i]]++; } } cout << ans << endl; }
replace
81
82
81
82
0
p02845
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <fstream> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> #define int long long using namespace std; using P = pair<int, int>; using ll = long long; using prique = priority_queue<int>; const int MOD = 1000000007; const int INF = LLONG_MAX / 3; const int MAX = 710000; /*-----Library-----*/ struct UnionFind { vector<int> par; // 親ノード vector<int> rank; // ランク vector<int> sizeuf; // 要素数 UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n); rank.resize(n); sizeuf.resize(n); for (int i = 0; i < n; ++i) { par[i] = i; rank[i] = 0; sizeuf[i] = 1; } } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; sizeuf[x] += sizeuf[y]; return true; } int size(int x) { return sizeuf[root(x)]; } }; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long i, long long j) { return i * (j / gcd(i, j)); } long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } /*-----Library-----*/ signed main() { int n; cin >> n; int cnt[3] = {}; int ans = 1; for (int i = 0; i < n; i++) { int k; cin >> k; int c = 0; int memo; for (int i = 0; i < 3; i++) { if (cnt[i] == k) { memo = i; c++; } } ans *= c; ans %= MOD; cnt[memo]++; } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <fstream> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> #define int long long using namespace std; using P = pair<int, int>; using ll = long long; using prique = priority_queue<int>; const int MOD = 1000000007; const int INF = LLONG_MAX / 3; const int MAX = 710000; /*-----Library-----*/ struct UnionFind { vector<int> par; // 親ノード vector<int> rank; // ランク vector<int> sizeuf; // 要素数 UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n); rank.resize(n); sizeuf.resize(n); for (int i = 0; i < n; ++i) { par[i] = i; rank[i] = 0; sizeuf[i] = 1; } } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; sizeuf[x] += sizeuf[y]; return true; } int size(int x) { return sizeuf[root(x)]; } }; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long i, long long j) { return i * (j / gcd(i, j)); } long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } /*-----Library-----*/ signed main() { int n; cin >> n; int cnt[3] = {}; int ans = 1; for (int i = 0; i < n; i++) { int k; cin >> k; int c = 0; int memo = -1; for (int j = 0; j < 3; j++) { if (cnt[j] == k) { memo = j; c++; } } ans *= c; ans %= MOD; cnt[memo]++; } cout << ans << endl; }
replace
113
117
113
117
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define vi vector<int> #define vl vector<long long> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define vp vector<P> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define REPD(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--) #define INF 1e18 #define INFTY 1e9 const int mod = 1000000007; #define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0])) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } // cout << fixed << setprecision(10) << y << endl; struct edge { int to, cost; }; vector<vector<edge>> es; const int MAX_N = 10010; int gcd(int a, int b) { if (b > a) { int c = b; b = a; a = c; } int r = a % b; if (r == 0) return b; return gcd(b, r); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { int n; cin >> n; vi a(n); REP(i, n) cin >> a[i]; ll res = 1; vi c = {0, 0, 0}; REP(i, n) { int cnt = 0; int ind = -1; REP(j, 3) { if (a[i] == c[j]) { cnt += 1; if (ind < 0) ind = j; } } res *= cnt; res %= mod; c[ind] += 1; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define vi vector<int> #define vl vector<long long> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define vp vector<P> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define REPD(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--) #define INF 1e18 #define INFTY 1e9 const int mod = 1000000007; #define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0])) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } // cout << fixed << setprecision(10) << y << endl; struct edge { int to, cost; }; vector<vector<edge>> es; const int MAX_N = 10010; int gcd(int a, int b) { if (b > a) { int c = b; b = a; a = c; } int r = a % b; if (r == 0) return b; return gcd(b, r); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { int n; cin >> n; vi a(n); REP(i, n) cin >> a[i]; ll res = 1; vi c = {0, 0, 0}; REP(i, n) { int cnt = 0; int ind = -1; REP(j, 3) { if (a[i] == c[j]) { cnt += 1; if (ind < 0) ind = j; } } res *= cnt; res %= mod; if (ind < 0) res = 0; else c[ind] += 1; } cout << res << endl; return 0; }
replace
75
76
75
79
0
p02845
Python
Runtime Error
MOD = 1000000007 n = int(input()) A = list(map(int, input().split())) vec = [0, 0, 0] num = 1 for a in A: idx = [i for i, x in enumerate(vec) if x == a] num = (num * len(idx)) % MOD vec[idx[0]] += 1 print(num)
MOD = 1000000007 n = int(input()) A = list(map(int, input().split())) vec = [0, 0, 0] num = 1 for a in A: idx = [i for i, x in enumerate(vec) if x == a] if len(idx) == 0: print(0) exit() num = (num * len(idx)) % MOD vec[idx[0]] += 1 print(num)
insert
10
10
10
13
0
p02845
Python
Runtime Error
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 def main(): MOD = 1000000007 N, *A = map(int, read().split()) C = [0] * N C[0] = 3 ans = 1 for a in A: ans = ans * C[a] % MOD if ans == 0: print(0) return C[a] -= 1 C[a + 1] += 1 print(ans) return if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 def main(): MOD = 1000000007 N, *A = map(int, read().split()) C = [0] * (N + 1) C[0] = 3 ans = 1 for a in A: ans = ans * C[a] % MOD if ans == 0: print(0) return C[a] -= 1 C[a + 1] += 1 print(ans) return if __name__ == "__main__": main()
replace
12
13
12
13
IndexError: list index out of range
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02845/Python/s718829903.py", line 30, in <module> main() File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02845/Python/s718829903.py", line 22, in main C[a + 1] += 1 IndexError: list index out of range
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<bool> vb; typedef vector<string> vst; typedef pair<ll, ll> pll; typedef vector<pll> vpll; const ll mod = (1e+9) + 7; const ll inf = 1e+16; #define rep(i, m, n) for (ll i = m; i < n; i++) #define repr(i, m, n) for (ll i = m; i >= n; i--) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; vll a(n); rep(i, 0, n) cin >> a[i]; vll cnt(35000, 0); vll dp(n + 1, 0); dp[0] = 1; rep(i, 0, n) { if (a[i] == 0) dp[i + 1] = (3 - cnt[0]) * dp[i]; else if (cnt[a[i] - 1] - cnt[a[i]] == 1) dp[i + 1] = dp[i]; else if (cnt[a[i] - 1] - cnt[a[i]] == 2) dp[i + 1] = 2 * dp[i]; else if (cnt[a[i] - 1] - cnt[a[i]] == 3) dp[i + 1] = 3 * dp[i]; dp[i + 1] %= mod; cnt[a[i]]++; } cout << dp[n] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<bool> vb; typedef vector<string> vst; typedef pair<ll, ll> pll; typedef vector<pll> vpll; const ll mod = (1e+9) + 7; const ll inf = 1e+16; #define rep(i, m, n) for (ll i = m; i < n; i++) #define repr(i, m, n) for (ll i = m; i >= n; i--) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; vll a(n); rep(i, 0, n) cin >> a[i]; vll cnt(100005, 0); vll dp(n + 1, 0); dp[0] = 1; rep(i, 0, n) { if (a[i] == 0) dp[i + 1] = (3 - cnt[0]) * dp[i]; else if (cnt[a[i] - 1] - cnt[a[i]] == 1) dp[i + 1] = dp[i]; else if (cnt[a[i] - 1] - cnt[a[i]] == 2) dp[i + 1] = 2 * dp[i]; else if (cnt[a[i] - 1] - cnt[a[i]] == 3) dp[i + 1] = 3 * dp[i]; dp[i + 1] %= mod; cnt[a[i]]++; } cout << dp[n] << endl; }
replace
27
28
27
28
0
p02845
Python
Runtime Error
#!/usr/bin/python3 import os import sys def main(): N = read_int() A = read_ints() print(solve(N, A)) MOD = 1000000007 def solve(N, A): c = 1 nums = [0, 0, 0] for a in A: z = nums.count(a) c *= z c %= MOD nums[nums.index(a)] = a + 1 return c ############################################################################### DEBUG = "DEBUG" in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return [int(e) for e in inp().split()] def dprint(*value, sep=" ", end="\n"): if DEBUG: print(*value, sep=sep, end=end) if __name__ == "__main__": main()
#!/usr/bin/python3 import os import sys def main(): N = read_int() A = read_ints() print(solve(N, A)) MOD = 1000000007 def solve(N, A): c = 1 nums = [0, 0, 0] for a in A: z = nums.count(a) if z == 0: return 0 c *= z c %= MOD nums[nums.index(a)] = a + 1 return c ############################################################################### DEBUG = "DEBUG" in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return [int(e) for e in inp().split()] def dprint(*value, sep=" ", end="\n"): if DEBUG: print(*value, sep=sep, end=end) if __name__ == "__main__": main()
insert
21
21
21
23
0
p02845
Python
Runtime Error
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) n, *a = map(int, read().split()) ans = 1 mod = 10**9 + 7 memo = [0, 0, 0] for check in a: ans *= memo.count(check) ans %= mod memo[memo.index(check)] += 1 print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) n, *a = map(int, read().split()) ans = 1 mod = 10**9 + 7 memo = [0, 0, 0] for check in a: if check in memo: ans *= memo.count(check) ans %= mod memo[memo.index(check)] += 1 else: print(0) exit() print(ans)
replace
12
15
12
19
0
p02845
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <array> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <fstream> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #define rep(i, s, n) for (int i = (s); (n) > i; i++) #define REP(i, n) rep(i, 0, n) #define RANGE(x, a, b) (min(a, b) <= (x) && (x) <= max(a, b)) // hei #define DUPLE(a, b, c, d) \ (RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b)) #define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d)) #define PW(x) ((x) * (x)) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define MODU 1000000007LL #define bitcheck(a, b) ((a >> b) & 1) #define bitset(a, b) (a |= (1 << b)) #define bitunset(a, b) (a &= ~(1 << b)) #define MP(a, b) make_pair((a), (b)) #define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #define PI 3.141592653589 #define izryt bool using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } pll Dir[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; //[a, b) #define Getsum(ar, a, b) (ar[b] - ar[a]) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) struct Edge { int from, to; ll w; bool operator<(const Edge &rhs) const { return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to)); } }; typedef vector<vector<Edge>> Graph; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll factorial(ll n) { // 階乗 ll ret = 1; rep(i, 1, n + 1) ret = (ret * i) % MODU; return ret; } ll mod_pow(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll divmod(ll a, ll b, ll m) { // a/b(mod m) // a/b (mod m) // a*b^-1 // b^-1 * b = 1 // b^(m-1) = 1 // b^(m-2) * b = 1 // b^-1 = b^(m-2) // a/b = a * b^(m-2) return (a * 1LL * mod_pow(b, m - 2, m)) % m; } ll ncr(ll n, ll r) { return divmod(factorial(n), (factorial(r) * (factorial(n - r))) % MODU, MODU); } int n; string base; bool quest(int from) { // True:base printf("?"); REP(i, n) { printf(" %d", (from + i) % (2 * n) + 1); } cout << endl; string str; cin >> str; return str == base; } bool quest(int from, int ad) { // True:base printf("?"); REP(i, n - 1) { printf(" %d", (from + i) % (2 * n) + 1); } printf(" %d", ad + 1); cout << endl; string str; cin >> str; return str == base; } array<int, 3> c[100002] = {}; int cc[100002] = {}; signed main() { #define INF 10000000 int n; cin >> n; vector<int> a(n); Fill(c, INF); REP(i, n) { cin >> a[i]; c[a[i]][cc[a[i]]] = i; cc[a[i]]++; } rep(i, 1, 100002) { if (cc[i] > cc[i - 1] || cc[i] > 3) { cout << 0 << endl; return 0; } } map<array<int, 3>, ll> dp, dp2; dp[{-1, -1, -1}] = 1LL; REP(i, n + 1) { for (auto itr : dp) { sort(ALL(c[i])); do { bool ok = true; REP(j, 3) { if (itr.first[j] == INF && c[i][j] == INF) continue; if (itr.first[j] >= c[i][j]) { ok = false; } } if (ok) { dp2[c[i]] += itr.second; dp2[c[i]] %= MODU; } } while (next_permutation(ALL(c[i]))); } swap(dp, dp2); dp2.clear(); } ll ans = 0; for (auto itr : dp) { ans += itr.second; ans %= MODU; } cout << ans << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <array> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <fstream> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #define rep(i, s, n) for (int i = (s); (n) > i; i++) #define REP(i, n) rep(i, 0, n) #define RANGE(x, a, b) (min(a, b) <= (x) && (x) <= max(a, b)) // hei #define DUPLE(a, b, c, d) \ (RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b)) #define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d)) #define PW(x) ((x) * (x)) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define MODU 1000000007LL #define bitcheck(a, b) ((a >> b) & 1) #define bitset(a, b) (a |= (1 << b)) #define bitunset(a, b) (a &= ~(1 << b)) #define MP(a, b) make_pair((a), (b)) #define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #define PI 3.141592653589 #define izryt bool using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } pll Dir[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; //[a, b) #define Getsum(ar, a, b) (ar[b] - ar[a]) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) struct Edge { int from, to; ll w; bool operator<(const Edge &rhs) const { return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to)); } }; typedef vector<vector<Edge>> Graph; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll factorial(ll n) { // 階乗 ll ret = 1; rep(i, 1, n + 1) ret = (ret * i) % MODU; return ret; } ll mod_pow(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } ll divmod(ll a, ll b, ll m) { // a/b(mod m) // a/b (mod m) // a*b^-1 // b^-1 * b = 1 // b^(m-1) = 1 // b^(m-2) * b = 1 // b^-1 = b^(m-2) // a/b = a * b^(m-2) return (a * 1LL * mod_pow(b, m - 2, m)) % m; } ll ncr(ll n, ll r) { return divmod(factorial(n), (factorial(r) * (factorial(n - r))) % MODU, MODU); } int n; string base; bool quest(int from) { // True:base printf("?"); REP(i, n) { printf(" %d", (from + i) % (2 * n) + 1); } cout << endl; string str; cin >> str; return str == base; } bool quest(int from, int ad) { // True:base printf("?"); REP(i, n - 1) { printf(" %d", (from + i) % (2 * n) + 1); } printf(" %d", ad + 1); cout << endl; string str; cin >> str; return str == base; } array<int, 3> c[100002] = {}; int cc[100002] = {}; signed main() { #define INF 10000000 int n; cin >> n; vector<int> a(n); Fill(c, INF); REP(i, n) { cin >> a[i]; c[a[i]][cc[a[i]]] = i; if (cc[a[i]] == 3) { cout << 0 << endl; return 0; } cc[a[i]]++; } rep(i, 1, 100002) { if (cc[i] > cc[i - 1] || cc[i] > 3) { cout << 0 << endl; return 0; } } map<array<int, 3>, ll> dp, dp2; dp[{-1, -1, -1}] = 1LL; REP(i, n + 1) { for (auto itr : dp) { sort(ALL(c[i])); do { bool ok = true; REP(j, 3) { if (itr.first[j] == INF && c[i][j] == INF) continue; if (itr.first[j] >= c[i][j]) { ok = false; } } if (ok) { dp2[c[i]] += itr.second; dp2[c[i]] %= MODU; } } while (next_permutation(ALL(c[i]))); } swap(dp, dp2); dp2.clear(); } ll ans = 0; for (auto itr : dp) { ans += itr.second; ans %= MODU; } cout << ans << endl; return 0; }
insert
139
139
139
143
0
p02845
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<double> VD; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<VD> VVD; typedef pair<int, int> P; typedef pair<ll, ll> PL; template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } int in() { int x; scanf("%d", &x); return x; } ll lin() { ll x; scanf("%lld", &x); return x; } const ll mod = 1000000007; int main() { int n; cin >> n; VI a(n); REP(i, n) a[i] = in(); ll ans = 1; VI cnt(3); REP(i, n) { VI c; REP(j, 3) { if (cnt[j] == a[i]) { c.push_back(j); } } ans = (ans * (ll)c.size()) % mod; cnt[c[0]]++; } cout << ans << endl; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<double> VD; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<VD> VVD; typedef pair<int, int> P; typedef pair<ll, ll> PL; template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } int in() { int x; scanf("%d", &x); return x; } ll lin() { ll x; scanf("%lld", &x); return x; } const ll mod = 1000000007; int main() { int n; cin >> n; VI a(n); REP(i, n) a[i] = in(); ll ans = 1; VI cnt(3); REP(i, n) { VI c; REP(j, 3) { if (cnt[j] == a[i]) { c.push_back(j); } } if (c.empty()) { cout << 0 << endl; return 0; } ans = (ans * (ll)c.size()) % mod; cnt[c[0]]++; } cout << ans << endl; return 0; }
insert
69
69
69
73
0
p02845
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; const long long MOD = 1000000007; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; long long res = 1; vector<int> C(3); for (int i = 0; i < N; i++) { long long cnt = 0, id = -1; if (A[i] == C[0]) { cnt++; id = 0; } if (A[i] == C[1]) { cnt++; id = 1; } if (A[i] == C[2]) { cnt++; id = 2; } res *= cnt; res %= MOD; C[id]++; } cout << res << endl; return 0; }
#include <iostream> #include <vector> using namespace std; const long long MOD = 1000000007; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; long long res = 1; vector<int> C(3); for (int i = 0; i < N; i++) { long long cnt = 0, id = -1; if (A[i] == C[0]) { cnt++; id = 0; } if (A[i] == C[1]) { cnt++; id = 1; } if (A[i] == C[2]) { cnt++; id = 2; } if (id == -1) { cout << "0" << endl; return 0; } res *= cnt; res %= MOD; C[id]++; } cout << res << endl; return 0; }
insert
30
30
30
35
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repo(i, n) for (int i = 1; i < (int)(n); i++) #define pb push_back #define mp make_pair #define np next_permutation #define lb lower_bound #define ub upper_bound #define fi first #define se second #define all(x) (x).begin(), (x).end() #define mod 1000000007 #define pi acos(-1.0) const ll INF = 1LL << 61; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } ll jou(ll N, ll P) { if (P == 0) return 1; if (P % 2 == 0) { ll t = jou(N, P / 2); return t * t % mod; } return (N * jou(N, P - 1)) % mod; } // jou(n,mod-2)で逆元 // intの最大値2147483647 ≒ 2×10^9 // long longの最大値9223372036854775807 ≒ 9×10^18 //'大文字'+=32; で小文字に // cout << fixed << setprecision (20); 小数点以下20桁まで // 実行時間制約2秒では2×10^8回くらいまで計算できる int main() { ll n; cin >> n; vector<ll> p(n); rep(i, n) { cin >> p[i]; } ll ans = 1; vector<ll> q = {0, 0, 0}; rep(i, n) { int cnt = 0; int memo; rep(j, 3) { if (p[i] == q[j]) { cnt++; memo = j; } } ans *= cnt; ans %= mod; q[memo]++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repo(i, n) for (int i = 1; i < (int)(n); i++) #define pb push_back #define mp make_pair #define np next_permutation #define lb lower_bound #define ub upper_bound #define fi first #define se second #define all(x) (x).begin(), (x).end() #define mod 1000000007 #define pi acos(-1.0) const ll INF = 1LL << 61; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } ll jou(ll N, ll P) { if (P == 0) return 1; if (P % 2 == 0) { ll t = jou(N, P / 2); return t * t % mod; } return (N * jou(N, P - 1)) % mod; } // jou(n,mod-2)で逆元 // intの最大値2147483647 ≒ 2×10^9 // long longの最大値9223372036854775807 ≒ 9×10^18 //'大文字'+=32; で小文字に // cout << fixed << setprecision (20); 小数点以下20桁まで // 実行時間制約2秒では2×10^8回くらいまで計算できる int main() { ll n; cin >> n; vector<ll> p(n); rep(i, n) { cin >> p[i]; } ll ans = 1; vector<ll> q = {0, 0, 0}; rep(i, n) { int cnt = 0; int memo; rep(j, 3) { if (p[i] == q[j]) { cnt++; memo = j; } } if (cnt == 0) { cout << 0 << endl; return 0; } ans *= cnt; ans %= mod; q[memo]++; } cout << ans << endl; }
insert
66
66
66
70
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--) #define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++) #define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(n) begin(n), end(n) using ll = long long; using namespace std; // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; int main() { int n; cin >> n; mint ans = 1; vector<int> c(3, 0); rep(i, n) { int in; cin >> in; int co = 0, index = -1; rep(j, 3) { if (c.at(j) == in) { if (index == -1) index = j; co++; } } ans *= co; c.at(index)++; } cout << ans.x << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--) #define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++) #define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(n) begin(n), end(n) using ll = long long; using namespace std; // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; int main() { int n; cin >> n; mint ans = 1; vector<int> c(3, 0); rep(i, n) { int in; cin >> in; int co = 0, index = -1; rep(j, 3) { if (c.at(j) == in) { if (index == -1) index = j; co++; } } if (index == -1) { cout << 0 << endl; return 0; } ans *= co; c.at(index)++; } cout << ans.x << endl; return 0; }
insert
80
80
80
84
0
p02845
C++
Runtime Error
// https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e // E - Colorful Hats 2 #include <bits/stdc++.h> #if LOCAL #include "dump.hpp" #else #define dump(...) #endif using namespace std; using ll = long long; #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) 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; } constexpr ll MOD = 1e9 + 7; int main() { #if LOCAL & 01 std::ifstream in("./test/sample-1.in"); // input.txt std::cin.rdbuf(in.rdbuf()); #else cin.tie(0); ios::sync_with_stdio(false); #endif ll N; cin >> N; vector<ll> an(N); for (auto &&a : an) { cin >> a; } ll ans = 1; ll x = 0, y = 0, z = 0; FOR(i, 0, N) { auto c = an.at(i); ll mul = 0; if (x == c) ++mul; if (y == c) ++mul; if (z == c) ++mul; if (x == c) { ++x; } else if (y == c) { ++y; } else if (z == c) { ++z; } else { assert(0); } ans *= mul; ans %= MOD; } cout << ans << endl; return 0; }
// https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e // E - Colorful Hats 2 #include <bits/stdc++.h> #if LOCAL #include "dump.hpp" #else #define dump(...) #endif using namespace std; using ll = long long; #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) 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; } constexpr ll MOD = 1e9 + 7; int main() { #if LOCAL & 01 std::ifstream in("./test/sample-1.in"); // input.txt std::cin.rdbuf(in.rdbuf()); #else cin.tie(0); ios::sync_with_stdio(false); #endif ll N; cin >> N; vector<ll> an(N); for (auto &&a : an) { cin >> a; } ll ans = 1; ll x = 0, y = 0, z = 0; FOR(i, 0, N) { auto c = an.at(i); ll mul = 0; if (x == c) ++mul; if (y == c) ++mul; if (z == c) ++mul; if (x == c) { ++x; } else if (y == c) { ++y; } else if (z == c) { ++z; } else { cout << 0 << endl; exit(0); } ans *= mul; ans %= MOD; } cout << ans << endl; return 0; }
replace
59
60
59
61
0
p02845
C++
Runtime Error
// smtb2019_e.cpp // Sun Dec 1 20:57:22 2019 #include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> #define INTINF 2147483647 #define LLINF 9223372036854775807 using namespace std; using ll = long long; typedef pair<int, int> P; ll MOD = 1000000007; int main() { ll n; cin >> n; ll a[n]; ll color[3]; color[0] = 0; color[1] = 0; color[2] = 0; ll ans = 1; for (int i = 0; i < n; i++) { cin >> a[i]; ll temp = 0; ll index = -1; for (int j = 0; j < 3; j++) { if (color[j] == a[i]) { temp++; index = j; } } ans = ans * temp % MOD; // cout << index << endl; color[index]++; } cout << ans << endl; // printf("%.4f\n",ans); }
// smtb2019_e.cpp // Sun Dec 1 20:57:22 2019 #include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> #define INTINF 2147483647 #define LLINF 9223372036854775807 using namespace std; using ll = long long; typedef pair<int, int> P; ll MOD = 1000000007; int main() { ll n; cin >> n; ll a[n]; ll color[3]; color[0] = 0; color[1] = 0; color[2] = 0; ll ans = 1; for (int i = 0; i < n; i++) { cin >> a[i]; ll temp = 0; ll index = -1; for (int j = 0; j < 3; j++) { if (color[j] == a[i]) { temp++; index = j; } } if (index == -1) { cout << 0 << endl; return 0; } ans = ans * temp % MOD; // cout << index << endl; color[index]++; } cout << ans << endl; // printf("%.4f\n",ans); }
insert
39
39
39
43
0
p02845
C++
Runtime Error
#define MOD 1000000007 #if 1 //------------------------------------------------------------ #define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; template <class T> struct Entry { static void Run() { T().Run(); } }; struct MyMain; #if defined(TEST) #include "test.hpp" #else signed main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); Entry<MyMain>::Run(); return 0; } #endif //------------------------------------------------------------ using ll = long long; #define int ll #define FOR(i, s, e) for (ll i = ll(s); i < ll(e); ++i) #define RFOR(i, s, e) for (ll i = ll(e) - 1; i >= ll(s); --i) #define REP(i, n) for (ll i = 0, i##_size = ll(n); i < i##_size; ++i) #define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i) #define INF INT64_MAX //------------------------------------------------------------ template <class T> struct ContainerHolder { bool flag = true; T &var; ContainerHolder(T &v) : var(v) {} operator bool() const { return flag; } T *operator->() { return &var; } }; template <class T> ContainerHolder<T> ContainerHold(T &v) { return ContainerHolder<T>(v); } #define CFOR(it, container) \ for (auto holder = ContainerHold(container); holder; holder.flag = false) \ for (auto it = holder->begin(), endIt = holder->end(); it != endIt; ++it) //------------------------------------------------------------ template <class T> struct arr : public vector<T> { arr() {} arr(initializer_list<T> il) : vector<T>(il) {} explicit arr(ll n, T v = T()) : vector<T>(n, v) {} T &operator()(int i) { return (*this)[i]; } T const &operator()(int i) const { return (*this)[i]; } void init(ll n, T v = T()) { this->clear(); this->resize(n, v); } ll sz() const { return (ll)this->size(); } void pb(T v) { this->push_back(v); } void sort() { std::sort(this->begin(), this->end()); } void sort(function<bool(T, T)> p) { std::sort(this->begin(), this->end(), p); } void rsort() { std::sort(this->begin(), this->end(), greater<T>()); } void unique_erase() { this->erase(std::unique(this->begin(), this->end()), this->end()); } bool next_permutation() { return std::next_permutation(this->begin(), this->end()); } // これ以下はソート済み前提 int lower_bound(T const &v, function<bool(T, T)> p) { return std::lower_bound(this->begin(), this->end(), v, p) - this->begin(); } int lower_bound(T const &v) { return std::lower_bound(this->begin(), this->end(), v) - this->begin(); } int upper_bound(T const &v, function<bool(T, T)> p) { return std::upper_bound(this->begin(), this->end(), v, p) - this->begin(); } int upper_bound(T const &v) { return std::upper_bound(this->begin(), this->end(), v) - this->begin(); } int find_nearest(T const &v) { int i = this->lower_bound(v); if (i >= sz()) { --i; } else if ((*this)[i] != v) { int p = i - 1; if (p >= 0) { int id = abs((*this)[i] - v); int pd = abs((*this)[p] - v); if (pd < id) { i = p; } } } return i; } // 見つからなければ-1 int find(T const &v) { int i = this->lower_bound(v); if (i >= sz()) { return -1; } if ((*this)[i] != v) { return -1; } return i; } }; using ints = arr<ll>; template <class T> struct que : public queue<T> { ll sz() const { return (ll)this->size(); } T popfront() { T v = this->front(); this->pop(); return v; } }; template <class A, class B> struct pr { union { A a; A key; A first; A x; }; union { B b; B value; B second; B y; }; pr() : a(A()), b(B()){}; pr(A a_, B b_) : a(a_), b(b_) {} pr(pr const &r) : a(r.a), b(r.b){}; pr(pair<A, B> const &r) : a(r.first), b(r.second){}; bool operator==(pr const &r) const { return a == r.a && b == r.b; } bool operator!=(pr const &r) const { return !((*this) == r); } bool operator<(pr const &r) const { if (a == r.a) { return b < r.b; } return a < r.a; } pr operator+(pr v) const { return pr(x, y) += v; } pr operator-(pr v) const { return pr(x, y) -= v; } pr &operator+=(pr v) { x += v.x; y += v.y; return *this; } pr &operator-=(pr v) { x -= v.x; y -= v.y; return *this; } void flip() { swap(x, y); } friend istream &operator>>(istream &is, pr &p) { is >> p.a >> p.b; return is; } friend ostream &operator<<(ostream &os, pr const &p) { os << p.a << " " << p.b; return os; } }; using pint = pr<ll, ll>; using pints = arr<pint>; template <class K, class V> struct dic : public map<K, V> { bool get(K const &k, V *v) { auto it = this->find(k); if (it != this->end()) { *v = it->second; return true; } return false; } }; template <class T> struct arr2 { vector<T> m_vec; int m_width; int m_height; arr2() : m_width(0), m_height(0) {} arr2(int w, int h, T const &value = T()) : m_width(w), m_height(h) { m_vec.resize(w * h, value); } arr2(arr2 const &r) { m_vec = r.m_vec; m_width = r.m_width; m_height = r.m_height; } arr2(arr2 &&r) { m_vec = move(r.m_vec); m_width = r.m_width; m_height = r.m_height; } arr2 &operator=(arr2 const &r) { m_vec = r.m_vec; m_width = r.m_width; m_height = r.m_height; return *this; } arr2 &operator=(arr2 &&r) { m_vec = move(r.m_vec); m_width = r.m_width; m_height = r.m_height; return *this; } bool operator==(arr2 const &r) const { return m_vec = r.m_vec; } bool operator<(arr2 const &r) const { if (m_width != r.m_width) { return m_width < r.m_width; } if (m_height != r.m_height) { return m_height < r.m_height; } REP(i, m_vec.size()) { if (m_vec[i] != r.m_vec[i]) { return m_vec[i] < r.m_vec[i]; } } return false; } pint size() const { return pint(m_width, m_height); } int width() const { return m_width; } int height() const { return m_height; } void init(int w, int h, T const &value = T()) { m_vec.clear(); m_vec.resize(w * h, value); m_width = w; m_height = h; } void init(pint size, T const &value = T()) { init(size.x, size.y, value); } T &operator()(int x, int y) { return m_vec[y * m_width + x]; } T const &operator()(int x, int y) const { return m_vec[y * m_width + x]; } T &operator()(pint p) { return m_vec[p.y * m_width + p.x]; } T const &operator()(pint p) const { return m_vec[p.y * m_width + p.x]; } T &operator[](pint p) { return m_vec[p.y * m_width + p.x]; } T const &operator[](pint p) const { return m_vec[p.y * m_width + p.x]; } bool isIn(int x, int y) const { return x >= 0 && x < m_width && y >= 0 && y < m_height; } bool isIn(pint p) const { return isIn(p.x, p.y); } bool isOut(int x, int y) const { return x < 0 || x >= m_width || y < 0 || y >= m_height; } bool isOut(pint p) const { return isOut(p.x, p.y); } struct iterator { private: arr2<T> *owner; public: pint pt; iterator(arr2<T> *owner_, pint pt_) : owner(owner_), pt(pt_) {} bool operator==(iterator const &r) const { return pt == r.pt; } bool operator!=(iterator const &r) const { return !((*this) == r); } void operator++() { ++pt.x; if (pt.x >= owner->width()) { ++pt.y; pt.x = 0; } } T &operator*() { return (*owner)(pt); } }; iterator begin() { return iterator(this, pint(0, 0)); } iterator end() { return iterator(this, pint(0, height())); } void disp(ostream &os) { REP(y, m_height) { REP(x, m_width) { os << setw(2) << (*this)(x, y) << " "; } os << endl; } os << endl; } }; const pints around4 = {pint(-1, 0), pint(0, -1), pint(1, 0), pint(0, 1)}; // 6角形グリッド用 const pints around6[2] = { {pint(0, -1), pint(1, -1), pint(-1, 0), pint(1, 0), pint(0, 1), pint(1, 1)}, {pint(-1, -1), pint(0, -1), pint(-1, 0), pint(1, 0), pint(-1, 1), pint(0, 1)}}; //------------------------------------------------------------ // ms int CurrentTime() { return clock() * 1000 / CLOCKS_PER_SEC; } //------------------------------------------------------------ template <class T> void chmin(T &a, T b) { if (b < a) { a = b; } } template <class T> void chmax(T &a, T b) { if (b > a) { a = b; } } constexpr int gcd(int a, int b) { if (a < 0) { a = -a; } if (b < 0) { b = -b; } if (a == 0) { return b; } if (b == 0) { return a; } while (int c = a % b) { a = b; b = c; } return b; } constexpr int lcm(int a, int b) { return a * b / gcd(a, b); } struct bfs { ints froms; ints steps; bfs(int N, int start, function<ints(int)> getAround) { froms.init(N, -1); steps.init(N, -1); que<ll> queue; queue.push(start); froms[start] = start; steps[start] = 0; while (queue.empty() == false) { ll p = queue.popfront(); for (ll n : getAround(p)) { if (steps[n] != -1) { continue; } froms[n] = p; steps[n] = steps[p] + 1; queue.push(n); } } } }; struct BfsResult { arr2<pint> froms; arr2<int> steps; }; template <class T, class F> BfsResult bfs2(arr2<T> const &field, pint start, F canMove) { BfsResult result; result.froms.init(field.size(), pint(-1, -1)); result.steps.init(field.size(), -1); que<pint> queue; queue.push(start); result.froms(start) = start; result.steps(start) = 0; while (queue.empty() == false) { auto p = queue.popfront(); for (auto a : around4) { pint n = p + a; if (field.isOut(n)) { continue; } if (result.steps(n) != -1) { continue; } if (!canMove(field(n))) { continue; } result.froms(n) = p; result.steps(n) = result.steps(p) + 1; queue.push(n); } } return result; } // getAround(count) -> around // getCost(from, to) -> cost int d9str(int N, int a, int b, function<ints(int)> getAround, function<int(int, int)> getCost) { struct Node { int point; int totalCost; bool operator<(Node const &n) const { return totalCost > n.totalCost; } }; ints minCosts(N, INT64_MAX); priority_queue<Node> que; minCosts(a) = 0; que.push(Node{a, 0}); while (!que.empty()) { Node node = que.top(); que.pop(); for (int next : getAround(node.point)) { int cost = getCost(node.point, next); if (cost < 0) { continue; } Node newNode; newNode.point = next; newNode.totalCost = node.totalCost + cost; if (newNode.totalCost < minCosts[newNode.point]) { minCosts[newNode.point] = newNode.totalCost; que.push(newNode); } } } if (minCosts[b] == INT64_MAX) { return -1; } return minCosts[b]; } // graph : 隣接行列。i=jは0、未接続はinfで初期化済みであること // return false なら負の閉路あり bool WarshallFloyd(arr2<int> &graph, int inf) { int N = graph.width(); REP(k, N) { REP(i, N) { REP(j, N) { if (graph(i, k) == inf || graph(k, j) == inf) { continue; } chmin(graph(i, j), graph(i, k) + graph(k, j)); } } } REP(i, N) { if (graph(i, i) < 0) { return false; } } return true; } //------------------------------------------------------------ // l <= x < r の間を探索 // 条件を満たすものが存在しなければrが返る int binsearch(int l, int r, function<bool(int)> predicate) { --l; while (r - l > 1) { int c = (l + r) / 2; if (predicate(c)) { r = c; } else { l = c; } } return r; } // func(x)の極値となるxを返す double num_analyze(function<double(double)> func, double l, double r, int step = 10000, double delta = 0.000001) { auto diff = [&](double x) { double a = func(x); double b = func(x + delta); return (b * b - a * a); }; REP(i, step) { double c = (l + r) / 2.0; double d = diff(c); if (d < 0) { l = c; } else { r = c; } } return l; } //------------------------------------------------------------ template <int M> struct modint { int raw; modint() { raw = 0; } modint(int v) { if (v < 0) { raw = (v % M) + M; } else if (v >= M) { raw = v % M; } else { raw = v; } } modint operator+(modint v) const { return modint(raw) += v; } modint operator-(modint v) const { return modint(raw) -= v; } modint operator*(modint v) const { return modint(raw) *= v; } modint &operator+=(modint v) { raw += v.raw; if (raw >= M) { raw -= M; } return *this; } modint &operator-=(modint v) { raw -= v.raw; if (raw < 0) { raw += M; } return *this; } modint &operator*=(modint v) { raw = (raw * v.raw) % M; return *this; } modint pow(int n) const { return modint::pow(raw, n); } static modint pow(int a, int n) { if (n < 0) { // not support abort(); } int r = 1; while (n) { if (n & 1) { r = (r * a) % M; } a = (a * a) % M; n >>= 1; } return modint(r); } modint inv() const { int a = raw; int b = M; int u = 1; int v = 0; while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); } u %= M; if (u < 0) { u += M; } return u; } friend istream &operator>>(istream &is, modint &m) { int v; is >> v; m = modint(v); return is; } friend ostream &operator<<(ostream &os, modint const &m) { return os << m.raw; } }; using mint = modint<MOD>; using mints = arr<mint>; //------------------------------------------------------------ struct LoopIndex { int const N; LoopIndex(int N_) : N(N_) {} int left(int i) { return (i - 1 + N) % N; } int right(int i) { return (i + 1) % N; } }; //------------------------------------------------------------ struct UnionFind { struct Node { Node *parent = nullptr; int count = 1; Node *Root() { if (parent == nullptr) { return this; } return parent = parent->Root(); } }; vector<Node> nodes; UnionFind(int count) { nodes.resize(count); } void Join(int a, int b) { Node *rootA = nodes[a].Root(); Node *rootB = nodes[b].Root(); if (rootA == rootB) { return; } if (rootA->count > rootB->count) { swap(rootA, rootB); } rootB->count += rootA->count; rootA->parent = rootB; rootA->count = 0; } bool IsReachable(int a, int b) { Node *rootA = nodes[a].Root(); Node *rootB = nodes[b].Root(); return rootA == rootB; } int Count(int a) { return nodes[a].Root()->count; } }; //------------------------------------------------------------ struct Kruskal { struct Edge { int a; int b; int cost; bool operator<(Edge const &r) const { return cost < r.cost; } }; UnionFind uf; int totalCost; arr<dic<int, int>> G; Kruskal(int N, arr<Edge> edges) : uf(N) { edges.sort(); totalCost = 0; G.init(N); REP(i, edges.sz()) { Edge const &edge = edges[i]; if (uf.IsReachable(edge.a, edge.b)) { continue; } G[edge.a][edge.b] = edge.cost; G[edge.b][edge.a] = edge.cost; uf.Join(edge.a, edge.b); totalCost += edge.cost; } } }; //------------------------------------------------------------ arr<char> Eratosthenes(int N) { arr<char> result; result.init(N, 1); result(0) = result(1) = 0; FOR(i, 2, N) { if (result(i) == 0) { continue; } for (int v = i + i; v < N; v += i) { result(v) = 0; } } return result; } bool IsSo(int v) { if (v <= 1) { return false; } FOR(i, 2, sqrt(v) + 1) { if (v % i == 0) { return false; } } return true; }; //------------------------------------------------------------ template <class T> struct SumsImpl { private: int N; arr<T> S; public: SumsImpl(int N_) : N(N_), S(N + 1, 0) {} void Set(int i, T const &value) { S(i + 1) = S(i) + value; } // l <= x < r T Get(int l, int r) const { return S(r) - S(l); } }; using Sums = SumsImpl<int>; template <class T> struct ImosImpl { private: int N; arr<T> S; public: ImosImpl(int N_) : N(N_), S(N + 1, 0) {} void Add(int i, T const &value) { S(i + 1) += value; } void Calc() { REP(i, N) { S(i + 1) += S(i); } } // l <= x < r T Get(int l, int r) const { return S(r) - S(l); } T Get(int i) const { return S(i); } }; using Imos = ImosImpl<int>; template <class T> struct Sums2Impl { private: arr2<T> sums; public: Sums2Impl(int W, int H) : sums(W + 1, H + 1) {} void Set(int x, int y, T const &value) { T s = value; s += sums(x + 1, y); s += sums(x, y + 1); s -= sums(x, y); sums(x + 1, y + 1) = s; } // l <= x < r // t <= y < b T Get(int l, int t, int r, int b) const { int s = sums(r, b); s -= sums(r, t); s -= sums(l, b); s += sums(l, t); return s; } }; using Sums2 = Sums2Impl<int>; template <class T> struct Imos2Impl { private: arr2<T> sums; public: Imos2Impl(int W, int H) : sums(W + 1, H + 1) {} void Add(int x, int y, T const &value) { sums(x + 1, y + 1) += value; } void Calc() { REP(y, sums.height() - 1) { REP(x, sums.width() - 1) { T s = 0; s += sums(x + 1, y); s += sums(x, y + 1); s -= sums(x, y); sums(x + 1, y + 1) += s; } } } // l <= x < r // t <= y < b T Get(int l, int t, int r, int b) const { int s = sums(r, b); s -= sums(r, t); s -= sums(l, b); s += sums(l, t); return s; } }; using Imos2 = Imos2Impl<int>; //------------------------------------------------------------ struct CombiTbl { mints fac; mints ifac; // 重複組み合わせを使う場合は N*2 を指定しないといけない CombiTbl(int N) : fac(N), ifac(N) { fac[0] = 1; ifac[0] = 1; FOR(i, 1, N) { fac[i] = fac[i - 1] * i; ifac[i] = fac[i].inv(); } } // a! mint Fac(int a) const { return fac(a); } // aPb mint Perm(int a, int b) const { return fac(a) * ifac(a - b); } // aCb mint Combi(int a, int b) const { return fac(a) * ifac(b) * ifac(a - b); } // aHb(重複組み合わせ) mint RepCombi(int a, int b) const { return Combi(a + b - 1, b); } }; //------------------------------------------------------------ template <class T> struct CompressImpl { private: arr<T> const &origins; arr<int> comp2orgIndex; arr<int> orgIndex2cmp; dic<T, int> orgValue2cmp; public: CompressImpl(arr<T> const &orgins_) : origins(orgins_) { int N = origins.sz(); comp2orgIndex.init(N); REP(i, N) { comp2orgIndex[i] = i; } comp2orgIndex.sort([&](int a, int b) { return origins[a] < origins[b]; }); orgIndex2cmp.init(N); REP(i, N) { orgIndex2cmp[comp2orgIndex[i]] = i; orgValue2cmp[origins[comp2orgIndex[i]]] = i; } } T const &Comp2OrgValue(int comp) const { return origins[comp2orgIndex[comp]]; } int Comp2OrgIndex(int comp) const { return comp2orgIndex[comp]; } int OrgValue2Comp(T const &orgValue) const { return orgValue2cmp.at(orgValue); } int OrgIndex2Comp(int orgIndex) const { return orgIndex2cmp[orgIndex]; } }; using Compress = CompressImpl<int>; //------------------------------------------------------------ #if defined(TEST) extern istream &mis; extern ostream &mos; #else istream &mis = cin; ostream &mos = cout; #endif //------------------------------------------------------------ struct OutputStream { template <class T> friend OutputStream &operator<<(OutputStream &s, T const &v) { mos << v << '\n'; return s; } } out; struct PrintStream { stringstream ss; template <class T> friend PrintStream &operator<<(PrintStream &s, T &&v) { s.ss << v << ' '; return s; } PrintStream &operator<<(PrintStream &(*manip)(PrintStream &)) { return (*manip)(*this); } } prn; PrintStream &en(PrintStream &s) { string str = s.ss.str(); s.ss = stringstream(); if (str.empty() == false) { str.pop_back(); } mos << str << '\n'; return s; } //------------------------------------------------------------ template <class T> struct in_base { T value; in_base() { mis >> value; } operator T() { return value; } }; struct in_int { int value; in_int() { mis >> value; } in_int(int add) { mis >> value; value += add; } operator int() { return value; } }; template <class A, class B> struct in_pr { pr<A, B> value; in_pr() { mis >> value.a >> value.b; } in_pr(int addA, int addB) { mis >> value.a >> value.b; value.a += addA; value.b += addB; } in_pr(bool flip) { mis >> value.b >> value.a; } in_pr(int addA, int addB, bool flip) { mis >> value.b >> value.a; value.a += addB; value.b += addA; } operator pr<A, B>() { return value; } }; template <class T> struct in_arr { arr<T> value; in_arr(int N) { value.init(N); REP(i, N) { mis >> value[i]; } } in_arr(int N, int add) { value.init(N); REP(i, N) { mis >> value[i]; value[i] += add; } } operator arr<T>() { return value; } }; template <> struct in_arr<pint> { arr<pint> value; in_arr(int N) { value.init(N); REP(i, N) { mis >> value[i]; } } in_arr(int N, int addA, int addB) { value.init(N); REP(i, N) { mis >> value[i].a >> value[i].b; value[i].a += addA; value[i].b += addB; } } in_arr(int N, bool flip) { value.init(N); REP(i, N) { mis >> value[i].b >> value[i].a; } } in_arr(int N, int addA, int addB, bool flip) { value.init(N); REP(i, N) { mis >> value[i].b >> value[i].a; value[i].a += addB; value[i].b += addA; } } operator arr<pint>() { return value; } }; template <class A, class B> struct in_dic { dic<A, B> value; in_dic(int N) { REP(i, N) { pair<A, B> pr; mis >> pr.first >> pr.second; value.insert(pr); } } in_dic(int N, int addA, int addB) { REP(i, N) { pair<A, B> pr; mis >> pr.first >> pr.second; pr.first += addA; pr.second += addB; value.insert(pr); } } in_dic(int N, bool flip) { REP(i, N) { pair<A, B> pr; mis >> pr.second >> pr.first; value.insert(pr); } } in_dic(int N, int addA, int addB, bool flip) { REP(i, N) { pair<A, B> pr; mis >> pr.second >> pr.first; pr.first += addB; pr.second += addA; value.insert(pr); } } operator dic<A, B>() { return value; } }; template <class T> struct in_arr2 { arr2<T> value; in_arr2(int H, int W) { value.init(W, H); REP(y, H) { REP(x, W) { mis >> value(x, y); } } } in_arr2(int H, int W, int add) { value.init(W, H); REP(y, H) { REP(x, W) { mis >> value(x, y); value(x, y) += add; } } } operator arr2<T>() { return value; } }; template <class T, class Tuple, size_t... Index> T MakeFromTupleImpl(Tuple &&t, index_sequence<Index...>) { return T(get<Index>(forward<Tuple>(t))...); } template <class T, class Tuple> T MakeFromTuple(Tuple &&t) { return MakeFromTupleImpl<T>( forward<Tuple>(t), make_index_sequence<tuple_size<remove_reference_t<Tuple>>::value>{}); } template <class... ARGS> struct inputWithParam { tuple<ARGS...> param; inputWithParam() {} explicit inputWithParam(tuple<ARGS...> &&param_) : param(param_) {} operator int() { return MakeFromTuple<in_int>(param); } operator double() { return MakeFromTuple<in_base<double>>(param); } operator string() { return MakeFromTuple<in_base<string>>(param); } operator char() { return MakeFromTuple<in_base<char>>(param); } template <class A, class B> operator pr<A, B>() { return MakeFromTuple<in_pr<A, B>>(param); } template <class T> operator arr<T>() { return MakeFromTuple<in_arr<T>>(param); } template <class A, class B> operator dic<A, B>() { return MakeFromTuple<in_dic<A, B>>(param); } template <class T> operator arr2<T>() { return MakeFromTuple<in_arr2<T>>(param); } }; struct input { operator int() { return inputWithParam<>(); } operator double() { return inputWithParam<>(); } operator string() { return inputWithParam<>(); } operator char() { return inputWithParam<>(); } template <class A, class B> operator pr<A, B>() { return inputWithParam<>(); } template <class... ARGS> inputWithParam<ARGS...> operator()(ARGS &&...args) { inputWithParam<ARGS...> withParam(forward_as_tuple(args...)); return withParam; } } in; //------------------------------------------------------------ #endif struct MyMain { int N = in; ints A = in(N); void Run() { mint ans = 1; ints colors(3); REP(i, N) { int hitCount = 0; int firstHit = -1; REP(c, 3) { if (colors[c] == A[i]) { hitCount++; if (firstHit < 0) { firstHit = c; } } } ans *= hitCount; colors[firstHit]++; } out << ans; } };
#define MOD 1000000007 #if 1 //------------------------------------------------------------ #define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; template <class T> struct Entry { static void Run() { T().Run(); } }; struct MyMain; #if defined(TEST) #include "test.hpp" #else signed main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); Entry<MyMain>::Run(); return 0; } #endif //------------------------------------------------------------ using ll = long long; #define int ll #define FOR(i, s, e) for (ll i = ll(s); i < ll(e); ++i) #define RFOR(i, s, e) for (ll i = ll(e) - 1; i >= ll(s); --i) #define REP(i, n) for (ll i = 0, i##_size = ll(n); i < i##_size; ++i) #define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i) #define INF INT64_MAX //------------------------------------------------------------ template <class T> struct ContainerHolder { bool flag = true; T &var; ContainerHolder(T &v) : var(v) {} operator bool() const { return flag; } T *operator->() { return &var; } }; template <class T> ContainerHolder<T> ContainerHold(T &v) { return ContainerHolder<T>(v); } #define CFOR(it, container) \ for (auto holder = ContainerHold(container); holder; holder.flag = false) \ for (auto it = holder->begin(), endIt = holder->end(); it != endIt; ++it) //------------------------------------------------------------ template <class T> struct arr : public vector<T> { arr() {} arr(initializer_list<T> il) : vector<T>(il) {} explicit arr(ll n, T v = T()) : vector<T>(n, v) {} T &operator()(int i) { return (*this)[i]; } T const &operator()(int i) const { return (*this)[i]; } void init(ll n, T v = T()) { this->clear(); this->resize(n, v); } ll sz() const { return (ll)this->size(); } void pb(T v) { this->push_back(v); } void sort() { std::sort(this->begin(), this->end()); } void sort(function<bool(T, T)> p) { std::sort(this->begin(), this->end(), p); } void rsort() { std::sort(this->begin(), this->end(), greater<T>()); } void unique_erase() { this->erase(std::unique(this->begin(), this->end()), this->end()); } bool next_permutation() { return std::next_permutation(this->begin(), this->end()); } // これ以下はソート済み前提 int lower_bound(T const &v, function<bool(T, T)> p) { return std::lower_bound(this->begin(), this->end(), v, p) - this->begin(); } int lower_bound(T const &v) { return std::lower_bound(this->begin(), this->end(), v) - this->begin(); } int upper_bound(T const &v, function<bool(T, T)> p) { return std::upper_bound(this->begin(), this->end(), v, p) - this->begin(); } int upper_bound(T const &v) { return std::upper_bound(this->begin(), this->end(), v) - this->begin(); } int find_nearest(T const &v) { int i = this->lower_bound(v); if (i >= sz()) { --i; } else if ((*this)[i] != v) { int p = i - 1; if (p >= 0) { int id = abs((*this)[i] - v); int pd = abs((*this)[p] - v); if (pd < id) { i = p; } } } return i; } // 見つからなければ-1 int find(T const &v) { int i = this->lower_bound(v); if (i >= sz()) { return -1; } if ((*this)[i] != v) { return -1; } return i; } }; using ints = arr<ll>; template <class T> struct que : public queue<T> { ll sz() const { return (ll)this->size(); } T popfront() { T v = this->front(); this->pop(); return v; } }; template <class A, class B> struct pr { union { A a; A key; A first; A x; }; union { B b; B value; B second; B y; }; pr() : a(A()), b(B()){}; pr(A a_, B b_) : a(a_), b(b_) {} pr(pr const &r) : a(r.a), b(r.b){}; pr(pair<A, B> const &r) : a(r.first), b(r.second){}; bool operator==(pr const &r) const { return a == r.a && b == r.b; } bool operator!=(pr const &r) const { return !((*this) == r); } bool operator<(pr const &r) const { if (a == r.a) { return b < r.b; } return a < r.a; } pr operator+(pr v) const { return pr(x, y) += v; } pr operator-(pr v) const { return pr(x, y) -= v; } pr &operator+=(pr v) { x += v.x; y += v.y; return *this; } pr &operator-=(pr v) { x -= v.x; y -= v.y; return *this; } void flip() { swap(x, y); } friend istream &operator>>(istream &is, pr &p) { is >> p.a >> p.b; return is; } friend ostream &operator<<(ostream &os, pr const &p) { os << p.a << " " << p.b; return os; } }; using pint = pr<ll, ll>; using pints = arr<pint>; template <class K, class V> struct dic : public map<K, V> { bool get(K const &k, V *v) { auto it = this->find(k); if (it != this->end()) { *v = it->second; return true; } return false; } }; template <class T> struct arr2 { vector<T> m_vec; int m_width; int m_height; arr2() : m_width(0), m_height(0) {} arr2(int w, int h, T const &value = T()) : m_width(w), m_height(h) { m_vec.resize(w * h, value); } arr2(arr2 const &r) { m_vec = r.m_vec; m_width = r.m_width; m_height = r.m_height; } arr2(arr2 &&r) { m_vec = move(r.m_vec); m_width = r.m_width; m_height = r.m_height; } arr2 &operator=(arr2 const &r) { m_vec = r.m_vec; m_width = r.m_width; m_height = r.m_height; return *this; } arr2 &operator=(arr2 &&r) { m_vec = move(r.m_vec); m_width = r.m_width; m_height = r.m_height; return *this; } bool operator==(arr2 const &r) const { return m_vec = r.m_vec; } bool operator<(arr2 const &r) const { if (m_width != r.m_width) { return m_width < r.m_width; } if (m_height != r.m_height) { return m_height < r.m_height; } REP(i, m_vec.size()) { if (m_vec[i] != r.m_vec[i]) { return m_vec[i] < r.m_vec[i]; } } return false; } pint size() const { return pint(m_width, m_height); } int width() const { return m_width; } int height() const { return m_height; } void init(int w, int h, T const &value = T()) { m_vec.clear(); m_vec.resize(w * h, value); m_width = w; m_height = h; } void init(pint size, T const &value = T()) { init(size.x, size.y, value); } T &operator()(int x, int y) { return m_vec[y * m_width + x]; } T const &operator()(int x, int y) const { return m_vec[y * m_width + x]; } T &operator()(pint p) { return m_vec[p.y * m_width + p.x]; } T const &operator()(pint p) const { return m_vec[p.y * m_width + p.x]; } T &operator[](pint p) { return m_vec[p.y * m_width + p.x]; } T const &operator[](pint p) const { return m_vec[p.y * m_width + p.x]; } bool isIn(int x, int y) const { return x >= 0 && x < m_width && y >= 0 && y < m_height; } bool isIn(pint p) const { return isIn(p.x, p.y); } bool isOut(int x, int y) const { return x < 0 || x >= m_width || y < 0 || y >= m_height; } bool isOut(pint p) const { return isOut(p.x, p.y); } struct iterator { private: arr2<T> *owner; public: pint pt; iterator(arr2<T> *owner_, pint pt_) : owner(owner_), pt(pt_) {} bool operator==(iterator const &r) const { return pt == r.pt; } bool operator!=(iterator const &r) const { return !((*this) == r); } void operator++() { ++pt.x; if (pt.x >= owner->width()) { ++pt.y; pt.x = 0; } } T &operator*() { return (*owner)(pt); } }; iterator begin() { return iterator(this, pint(0, 0)); } iterator end() { return iterator(this, pint(0, height())); } void disp(ostream &os) { REP(y, m_height) { REP(x, m_width) { os << setw(2) << (*this)(x, y) << " "; } os << endl; } os << endl; } }; const pints around4 = {pint(-1, 0), pint(0, -1), pint(1, 0), pint(0, 1)}; // 6角形グリッド用 const pints around6[2] = { {pint(0, -1), pint(1, -1), pint(-1, 0), pint(1, 0), pint(0, 1), pint(1, 1)}, {pint(-1, -1), pint(0, -1), pint(-1, 0), pint(1, 0), pint(-1, 1), pint(0, 1)}}; //------------------------------------------------------------ // ms int CurrentTime() { return clock() * 1000 / CLOCKS_PER_SEC; } //------------------------------------------------------------ template <class T> void chmin(T &a, T b) { if (b < a) { a = b; } } template <class T> void chmax(T &a, T b) { if (b > a) { a = b; } } constexpr int gcd(int a, int b) { if (a < 0) { a = -a; } if (b < 0) { b = -b; } if (a == 0) { return b; } if (b == 0) { return a; } while (int c = a % b) { a = b; b = c; } return b; } constexpr int lcm(int a, int b) { return a * b / gcd(a, b); } struct bfs { ints froms; ints steps; bfs(int N, int start, function<ints(int)> getAround) { froms.init(N, -1); steps.init(N, -1); que<ll> queue; queue.push(start); froms[start] = start; steps[start] = 0; while (queue.empty() == false) { ll p = queue.popfront(); for (ll n : getAround(p)) { if (steps[n] != -1) { continue; } froms[n] = p; steps[n] = steps[p] + 1; queue.push(n); } } } }; struct BfsResult { arr2<pint> froms; arr2<int> steps; }; template <class T, class F> BfsResult bfs2(arr2<T> const &field, pint start, F canMove) { BfsResult result; result.froms.init(field.size(), pint(-1, -1)); result.steps.init(field.size(), -1); que<pint> queue; queue.push(start); result.froms(start) = start; result.steps(start) = 0; while (queue.empty() == false) { auto p = queue.popfront(); for (auto a : around4) { pint n = p + a; if (field.isOut(n)) { continue; } if (result.steps(n) != -1) { continue; } if (!canMove(field(n))) { continue; } result.froms(n) = p; result.steps(n) = result.steps(p) + 1; queue.push(n); } } return result; } // getAround(count) -> around // getCost(from, to) -> cost int d9str(int N, int a, int b, function<ints(int)> getAround, function<int(int, int)> getCost) { struct Node { int point; int totalCost; bool operator<(Node const &n) const { return totalCost > n.totalCost; } }; ints minCosts(N, INT64_MAX); priority_queue<Node> que; minCosts(a) = 0; que.push(Node{a, 0}); while (!que.empty()) { Node node = que.top(); que.pop(); for (int next : getAround(node.point)) { int cost = getCost(node.point, next); if (cost < 0) { continue; } Node newNode; newNode.point = next; newNode.totalCost = node.totalCost + cost; if (newNode.totalCost < minCosts[newNode.point]) { minCosts[newNode.point] = newNode.totalCost; que.push(newNode); } } } if (minCosts[b] == INT64_MAX) { return -1; } return minCosts[b]; } // graph : 隣接行列。i=jは0、未接続はinfで初期化済みであること // return false なら負の閉路あり bool WarshallFloyd(arr2<int> &graph, int inf) { int N = graph.width(); REP(k, N) { REP(i, N) { REP(j, N) { if (graph(i, k) == inf || graph(k, j) == inf) { continue; } chmin(graph(i, j), graph(i, k) + graph(k, j)); } } } REP(i, N) { if (graph(i, i) < 0) { return false; } } return true; } //------------------------------------------------------------ // l <= x < r の間を探索 // 条件を満たすものが存在しなければrが返る int binsearch(int l, int r, function<bool(int)> predicate) { --l; while (r - l > 1) { int c = (l + r) / 2; if (predicate(c)) { r = c; } else { l = c; } } return r; } // func(x)の極値となるxを返す double num_analyze(function<double(double)> func, double l, double r, int step = 10000, double delta = 0.000001) { auto diff = [&](double x) { double a = func(x); double b = func(x + delta); return (b * b - a * a); }; REP(i, step) { double c = (l + r) / 2.0; double d = diff(c); if (d < 0) { l = c; } else { r = c; } } return l; } //------------------------------------------------------------ template <int M> struct modint { int raw; modint() { raw = 0; } modint(int v) { if (v < 0) { raw = (v % M) + M; } else if (v >= M) { raw = v % M; } else { raw = v; } } modint operator+(modint v) const { return modint(raw) += v; } modint operator-(modint v) const { return modint(raw) -= v; } modint operator*(modint v) const { return modint(raw) *= v; } modint &operator+=(modint v) { raw += v.raw; if (raw >= M) { raw -= M; } return *this; } modint &operator-=(modint v) { raw -= v.raw; if (raw < 0) { raw += M; } return *this; } modint &operator*=(modint v) { raw = (raw * v.raw) % M; return *this; } modint pow(int n) const { return modint::pow(raw, n); } static modint pow(int a, int n) { if (n < 0) { // not support abort(); } int r = 1; while (n) { if (n & 1) { r = (r * a) % M; } a = (a * a) % M; n >>= 1; } return modint(r); } modint inv() const { int a = raw; int b = M; int u = 1; int v = 0; while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); } u %= M; if (u < 0) { u += M; } return u; } friend istream &operator>>(istream &is, modint &m) { int v; is >> v; m = modint(v); return is; } friend ostream &operator<<(ostream &os, modint const &m) { return os << m.raw; } }; using mint = modint<MOD>; using mints = arr<mint>; //------------------------------------------------------------ struct LoopIndex { int const N; LoopIndex(int N_) : N(N_) {} int left(int i) { return (i - 1 + N) % N; } int right(int i) { return (i + 1) % N; } }; //------------------------------------------------------------ struct UnionFind { struct Node { Node *parent = nullptr; int count = 1; Node *Root() { if (parent == nullptr) { return this; } return parent = parent->Root(); } }; vector<Node> nodes; UnionFind(int count) { nodes.resize(count); } void Join(int a, int b) { Node *rootA = nodes[a].Root(); Node *rootB = nodes[b].Root(); if (rootA == rootB) { return; } if (rootA->count > rootB->count) { swap(rootA, rootB); } rootB->count += rootA->count; rootA->parent = rootB; rootA->count = 0; } bool IsReachable(int a, int b) { Node *rootA = nodes[a].Root(); Node *rootB = nodes[b].Root(); return rootA == rootB; } int Count(int a) { return nodes[a].Root()->count; } }; //------------------------------------------------------------ struct Kruskal { struct Edge { int a; int b; int cost; bool operator<(Edge const &r) const { return cost < r.cost; } }; UnionFind uf; int totalCost; arr<dic<int, int>> G; Kruskal(int N, arr<Edge> edges) : uf(N) { edges.sort(); totalCost = 0; G.init(N); REP(i, edges.sz()) { Edge const &edge = edges[i]; if (uf.IsReachable(edge.a, edge.b)) { continue; } G[edge.a][edge.b] = edge.cost; G[edge.b][edge.a] = edge.cost; uf.Join(edge.a, edge.b); totalCost += edge.cost; } } }; //------------------------------------------------------------ arr<char> Eratosthenes(int N) { arr<char> result; result.init(N, 1); result(0) = result(1) = 0; FOR(i, 2, N) { if (result(i) == 0) { continue; } for (int v = i + i; v < N; v += i) { result(v) = 0; } } return result; } bool IsSo(int v) { if (v <= 1) { return false; } FOR(i, 2, sqrt(v) + 1) { if (v % i == 0) { return false; } } return true; }; //------------------------------------------------------------ template <class T> struct SumsImpl { private: int N; arr<T> S; public: SumsImpl(int N_) : N(N_), S(N + 1, 0) {} void Set(int i, T const &value) { S(i + 1) = S(i) + value; } // l <= x < r T Get(int l, int r) const { return S(r) - S(l); } }; using Sums = SumsImpl<int>; template <class T> struct ImosImpl { private: int N; arr<T> S; public: ImosImpl(int N_) : N(N_), S(N + 1, 0) {} void Add(int i, T const &value) { S(i + 1) += value; } void Calc() { REP(i, N) { S(i + 1) += S(i); } } // l <= x < r T Get(int l, int r) const { return S(r) - S(l); } T Get(int i) const { return S(i); } }; using Imos = ImosImpl<int>; template <class T> struct Sums2Impl { private: arr2<T> sums; public: Sums2Impl(int W, int H) : sums(W + 1, H + 1) {} void Set(int x, int y, T const &value) { T s = value; s += sums(x + 1, y); s += sums(x, y + 1); s -= sums(x, y); sums(x + 1, y + 1) = s; } // l <= x < r // t <= y < b T Get(int l, int t, int r, int b) const { int s = sums(r, b); s -= sums(r, t); s -= sums(l, b); s += sums(l, t); return s; } }; using Sums2 = Sums2Impl<int>; template <class T> struct Imos2Impl { private: arr2<T> sums; public: Imos2Impl(int W, int H) : sums(W + 1, H + 1) {} void Add(int x, int y, T const &value) { sums(x + 1, y + 1) += value; } void Calc() { REP(y, sums.height() - 1) { REP(x, sums.width() - 1) { T s = 0; s += sums(x + 1, y); s += sums(x, y + 1); s -= sums(x, y); sums(x + 1, y + 1) += s; } } } // l <= x < r // t <= y < b T Get(int l, int t, int r, int b) const { int s = sums(r, b); s -= sums(r, t); s -= sums(l, b); s += sums(l, t); return s; } }; using Imos2 = Imos2Impl<int>; //------------------------------------------------------------ struct CombiTbl { mints fac; mints ifac; // 重複組み合わせを使う場合は N*2 を指定しないといけない CombiTbl(int N) : fac(N), ifac(N) { fac[0] = 1; ifac[0] = 1; FOR(i, 1, N) { fac[i] = fac[i - 1] * i; ifac[i] = fac[i].inv(); } } // a! mint Fac(int a) const { return fac(a); } // aPb mint Perm(int a, int b) const { return fac(a) * ifac(a - b); } // aCb mint Combi(int a, int b) const { return fac(a) * ifac(b) * ifac(a - b); } // aHb(重複組み合わせ) mint RepCombi(int a, int b) const { return Combi(a + b - 1, b); } }; //------------------------------------------------------------ template <class T> struct CompressImpl { private: arr<T> const &origins; arr<int> comp2orgIndex; arr<int> orgIndex2cmp; dic<T, int> orgValue2cmp; public: CompressImpl(arr<T> const &orgins_) : origins(orgins_) { int N = origins.sz(); comp2orgIndex.init(N); REP(i, N) { comp2orgIndex[i] = i; } comp2orgIndex.sort([&](int a, int b) { return origins[a] < origins[b]; }); orgIndex2cmp.init(N); REP(i, N) { orgIndex2cmp[comp2orgIndex[i]] = i; orgValue2cmp[origins[comp2orgIndex[i]]] = i; } } T const &Comp2OrgValue(int comp) const { return origins[comp2orgIndex[comp]]; } int Comp2OrgIndex(int comp) const { return comp2orgIndex[comp]; } int OrgValue2Comp(T const &orgValue) const { return orgValue2cmp.at(orgValue); } int OrgIndex2Comp(int orgIndex) const { return orgIndex2cmp[orgIndex]; } }; using Compress = CompressImpl<int>; //------------------------------------------------------------ #if defined(TEST) extern istream &mis; extern ostream &mos; #else istream &mis = cin; ostream &mos = cout; #endif //------------------------------------------------------------ struct OutputStream { template <class T> friend OutputStream &operator<<(OutputStream &s, T const &v) { mos << v << '\n'; return s; } } out; struct PrintStream { stringstream ss; template <class T> friend PrintStream &operator<<(PrintStream &s, T &&v) { s.ss << v << ' '; return s; } PrintStream &operator<<(PrintStream &(*manip)(PrintStream &)) { return (*manip)(*this); } } prn; PrintStream &en(PrintStream &s) { string str = s.ss.str(); s.ss = stringstream(); if (str.empty() == false) { str.pop_back(); } mos << str << '\n'; return s; } //------------------------------------------------------------ template <class T> struct in_base { T value; in_base() { mis >> value; } operator T() { return value; } }; struct in_int { int value; in_int() { mis >> value; } in_int(int add) { mis >> value; value += add; } operator int() { return value; } }; template <class A, class B> struct in_pr { pr<A, B> value; in_pr() { mis >> value.a >> value.b; } in_pr(int addA, int addB) { mis >> value.a >> value.b; value.a += addA; value.b += addB; } in_pr(bool flip) { mis >> value.b >> value.a; } in_pr(int addA, int addB, bool flip) { mis >> value.b >> value.a; value.a += addB; value.b += addA; } operator pr<A, B>() { return value; } }; template <class T> struct in_arr { arr<T> value; in_arr(int N) { value.init(N); REP(i, N) { mis >> value[i]; } } in_arr(int N, int add) { value.init(N); REP(i, N) { mis >> value[i]; value[i] += add; } } operator arr<T>() { return value; } }; template <> struct in_arr<pint> { arr<pint> value; in_arr(int N) { value.init(N); REP(i, N) { mis >> value[i]; } } in_arr(int N, int addA, int addB) { value.init(N); REP(i, N) { mis >> value[i].a >> value[i].b; value[i].a += addA; value[i].b += addB; } } in_arr(int N, bool flip) { value.init(N); REP(i, N) { mis >> value[i].b >> value[i].a; } } in_arr(int N, int addA, int addB, bool flip) { value.init(N); REP(i, N) { mis >> value[i].b >> value[i].a; value[i].a += addB; value[i].b += addA; } } operator arr<pint>() { return value; } }; template <class A, class B> struct in_dic { dic<A, B> value; in_dic(int N) { REP(i, N) { pair<A, B> pr; mis >> pr.first >> pr.second; value.insert(pr); } } in_dic(int N, int addA, int addB) { REP(i, N) { pair<A, B> pr; mis >> pr.first >> pr.second; pr.first += addA; pr.second += addB; value.insert(pr); } } in_dic(int N, bool flip) { REP(i, N) { pair<A, B> pr; mis >> pr.second >> pr.first; value.insert(pr); } } in_dic(int N, int addA, int addB, bool flip) { REP(i, N) { pair<A, B> pr; mis >> pr.second >> pr.first; pr.first += addB; pr.second += addA; value.insert(pr); } } operator dic<A, B>() { return value; } }; template <class T> struct in_arr2 { arr2<T> value; in_arr2(int H, int W) { value.init(W, H); REP(y, H) { REP(x, W) { mis >> value(x, y); } } } in_arr2(int H, int W, int add) { value.init(W, H); REP(y, H) { REP(x, W) { mis >> value(x, y); value(x, y) += add; } } } operator arr2<T>() { return value; } }; template <class T, class Tuple, size_t... Index> T MakeFromTupleImpl(Tuple &&t, index_sequence<Index...>) { return T(get<Index>(forward<Tuple>(t))...); } template <class T, class Tuple> T MakeFromTuple(Tuple &&t) { return MakeFromTupleImpl<T>( forward<Tuple>(t), make_index_sequence<tuple_size<remove_reference_t<Tuple>>::value>{}); } template <class... ARGS> struct inputWithParam { tuple<ARGS...> param; inputWithParam() {} explicit inputWithParam(tuple<ARGS...> &&param_) : param(param_) {} operator int() { return MakeFromTuple<in_int>(param); } operator double() { return MakeFromTuple<in_base<double>>(param); } operator string() { return MakeFromTuple<in_base<string>>(param); } operator char() { return MakeFromTuple<in_base<char>>(param); } template <class A, class B> operator pr<A, B>() { return MakeFromTuple<in_pr<A, B>>(param); } template <class T> operator arr<T>() { return MakeFromTuple<in_arr<T>>(param); } template <class A, class B> operator dic<A, B>() { return MakeFromTuple<in_dic<A, B>>(param); } template <class T> operator arr2<T>() { return MakeFromTuple<in_arr2<T>>(param); } }; struct input { operator int() { return inputWithParam<>(); } operator double() { return inputWithParam<>(); } operator string() { return inputWithParam<>(); } operator char() { return inputWithParam<>(); } template <class A, class B> operator pr<A, B>() { return inputWithParam<>(); } template <class... ARGS> inputWithParam<ARGS...> operator()(ARGS &&...args) { inputWithParam<ARGS...> withParam(forward_as_tuple(args...)); return withParam; } } in; //------------------------------------------------------------ #endif struct MyMain { int N = in; ints A = in(N); void Run() { mint ans = 1; ints colors(3); REP(i, N) { int hitCount = 0; int firstHit = -1; REP(c, 3) { if (colors[c] == A[i]) { hitCount++; if (firstHit < 0) { firstHit = c; } } } if (hitCount == 0) { out << 0; return; } ans *= hitCount; colors[firstHit]++; } out << ans; } };
insert
1,159
1,159
1,159
1,164
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; //===================================================== // マクロ定義部 //===================================================== #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define FOR_EQ(i, a, b) for (ll i = (a); i <= (b); ++i) #define rep(i, n) FOR(i, 0, n) #define rep_eq(i, n) FOR_EQ(i, 0, n) #define DEBUG_VARIABLE(variable) cout << #variable << ":" << variable << endl #define INFTY 1000000000000 #define WHITE 1 // (未訪問) #define GRAY \ 2 // (訪問)未だに訪問していない頂点への辺を持っている。スタックに退避。 #define BLACK 3 // (訪問完了)未訪問への頂点への辺を持たない //===================================================== // 型定義部 //===================================================== typedef unsigned long long ull; typedef long long ll; typedef pair<ll, ll> ll_ll; typedef vector<ll> Vector; typedef vector<Vector> DVector; typedef vector<pair<ll, ll>> Vec_Pair; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } //=================================================== // 関数のプロトタイプ宣言・関数に必要な配列の宣言 //=================================================== template <class X> void printArray(X *array, ll); template <class X> void printVector(vector<X> &v); template <class X> void printDimention(vector<vector<X>> &dv); template <class X> void printMap(X); template <class X> void printVecPair(vector<X> &v); void printDV_Pair(vector<vector<pair<ll, ll>>> &v); void printSet(set<ll> &S); // 繰返し自乗法 ll RepeatSquaring(ll a, ll index); // 最大公約数 ll GCD(ll, ll); // 最小公倍数 ll LCM(ll, ll); // 割り算した時に余りが有る時だけ、+1の商を返す。 ll div_one(ll res, ll div); //=================================================== // グローバル //=================================================== const int MOD = 1000000007; // 1個上から時計周り const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; // 上右下左 const int dx[4] = {0, 1, 0, -1}; // dj const int dy[4] = {-1, 0, 1, 0}; // di static const int NIL = -1; ll n, N, k, K, V, E; //=================================================== // 関数 //=================================================== //=================================================== // main 問題処理部 //=================================================== int main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); cin >> N; Vector A(N + 1, -1); DVector dp(3, Vector(N + 1, 0)); FOR_EQ(i, 1, N) { cin >> A[i]; } // printVector(A); ll sum = 1; FOR_EQ(i, 1, N) { ll hat = A[i]; ll cnt = 0, f; // 1つ前の状態を見てhatと同じ数をカウントし、該当する1つの箇所に数を入れる rep(c, 3) { if (hat == dp[c][i - 1]) { cnt++; f = c; } dp[c][i] = dp[c][i - 1]; } dp[f][i]++; sum *= cnt; sum %= MOD; } cout << sum << endl; return 0; } //===================================================== // 関数群 //===================================================== template <class X> void printArray(X array[], ll n) { rep(i, n) { if (i) cout << " "; cout << array[i]; } cout << endl; } template <class X> void printVector(vector<X> &v) { rep(i, (int)v.size()) { if (i) cout << " "; cout << v[i]; } cout << endl; } // 二次元配列の表示 template <class X> void printDimention(vector<vector<X>> &dv) { rep(i, (ll)dv.size()) { rep(j, (ll)dv[i].size()) { if (j) cout << " "; cout << dv[i][j]; } cout << endl; } cout << endl; } // mapの表示 template <class X> void printMap(X mp) { for (auto it : mp) { cout << it.first << " " << it.second << endl; } } // 内部にpairを内包したvectorの表示 template <class X> void printVecPair(vector<X> &v) { rep(i, (int)v.size()) { cout << v[i].first << " " << v[i].second << endl; } cout << endl; } // 内部にVec_Pairを内包したvectorの表示 void printDV_Pair(vector<vector<pair<ll, ll>>> &v) { rep(i, (int)v.size()) { cout << i << endl; rep(j, (int)v[i].size()) { cout << v[i][j].first << " " << v[i][j].second << endl; } cout << endl; } cout << endl; } void printSet(set<ll> &S) { for (set<ll>::iterator it = S.begin(); it != S.end(); it++) { if (it != --S.end()) cout << *it << " "; else cout << *it << endl; } } ll RepeatSquaring(ll a, ll index) { if (index == 0) return 1; else if (index % 2 == 0) { ll tmp = RepeatSquaring(a, index / 2); return tmp * tmp; } else { return a * RepeatSquaring(a, index - 1); } } // 最大公約数(Greatest Common Divisor) // ユークリッドの互除法使用 ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } // 最小公倍数(Least Common Multiple) ll LCM(ll m, ll n) { // 引数に0がある場合は0を返す if (m == 0 || n == 0) return 0; // lcm = m * n / gcd(m, n) return ((m / GCD(m, n)) * n); } // 割り算した時に余りが有る時だけ、+1の商を返す。 ll div_one(ll res, ll div) { // res 割られる数、div 割る数 return (res + div - 1) / div; }
#include <bits/stdc++.h> using namespace std; //===================================================== // マクロ定義部 //===================================================== #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define FOR_EQ(i, a, b) for (ll i = (a); i <= (b); ++i) #define rep(i, n) FOR(i, 0, n) #define rep_eq(i, n) FOR_EQ(i, 0, n) #define DEBUG_VARIABLE(variable) cout << #variable << ":" << variable << endl #define INFTY 1000000000000 #define WHITE 1 // (未訪問) #define GRAY \ 2 // (訪問)未だに訪問していない頂点への辺を持っている。スタックに退避。 #define BLACK 3 // (訪問完了)未訪問への頂点への辺を持たない //===================================================== // 型定義部 //===================================================== typedef unsigned long long ull; typedef long long ll; typedef pair<ll, ll> ll_ll; typedef vector<ll> Vector; typedef vector<Vector> DVector; typedef vector<pair<ll, ll>> Vec_Pair; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } //=================================================== // 関数のプロトタイプ宣言・関数に必要な配列の宣言 //=================================================== template <class X> void printArray(X *array, ll); template <class X> void printVector(vector<X> &v); template <class X> void printDimention(vector<vector<X>> &dv); template <class X> void printMap(X); template <class X> void printVecPair(vector<X> &v); void printDV_Pair(vector<vector<pair<ll, ll>>> &v); void printSet(set<ll> &S); // 繰返し自乗法 ll RepeatSquaring(ll a, ll index); // 最大公約数 ll GCD(ll, ll); // 最小公倍数 ll LCM(ll, ll); // 割り算した時に余りが有る時だけ、+1の商を返す。 ll div_one(ll res, ll div); //=================================================== // グローバル //=================================================== const int MOD = 1000000007; // 1個上から時計周り const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; // 上右下左 const int dx[4] = {0, 1, 0, -1}; // dj const int dy[4] = {-1, 0, 1, 0}; // di static const int NIL = -1; ll n, N, k, K, V, E; //=================================================== // 関数 //=================================================== //=================================================== // main 問題処理部 //=================================================== int main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); cin >> N; Vector A(N + 1, -1); DVector dp(3, Vector(N + 1, 0)); FOR_EQ(i, 1, N) { cin >> A[i]; } // printVector(A); ll sum = 1; FOR_EQ(i, 1, N) { ll hat = A[i]; ll cnt = 0, f = 0; // 1つ前の状態を見てhatと同じ数をカウントし、該当する1つの箇所に数を入れる rep(c, 3) { if (hat == dp[c][i - 1]) { cnt++; f = c; } dp[c][i] = dp[c][i - 1]; } dp[f][i]++; sum *= cnt; sum %= MOD; } cout << sum << endl; return 0; } //===================================================== // 関数群 //===================================================== template <class X> void printArray(X array[], ll n) { rep(i, n) { if (i) cout << " "; cout << array[i]; } cout << endl; } template <class X> void printVector(vector<X> &v) { rep(i, (int)v.size()) { if (i) cout << " "; cout << v[i]; } cout << endl; } // 二次元配列の表示 template <class X> void printDimention(vector<vector<X>> &dv) { rep(i, (ll)dv.size()) { rep(j, (ll)dv[i].size()) { if (j) cout << " "; cout << dv[i][j]; } cout << endl; } cout << endl; } // mapの表示 template <class X> void printMap(X mp) { for (auto it : mp) { cout << it.first << " " << it.second << endl; } } // 内部にpairを内包したvectorの表示 template <class X> void printVecPair(vector<X> &v) { rep(i, (int)v.size()) { cout << v[i].first << " " << v[i].second << endl; } cout << endl; } // 内部にVec_Pairを内包したvectorの表示 void printDV_Pair(vector<vector<pair<ll, ll>>> &v) { rep(i, (int)v.size()) { cout << i << endl; rep(j, (int)v[i].size()) { cout << v[i][j].first << " " << v[i][j].second << endl; } cout << endl; } cout << endl; } void printSet(set<ll> &S) { for (set<ll>::iterator it = S.begin(); it != S.end(); it++) { if (it != --S.end()) cout << *it << " "; else cout << *it << endl; } } ll RepeatSquaring(ll a, ll index) { if (index == 0) return 1; else if (index % 2 == 0) { ll tmp = RepeatSquaring(a, index / 2); return tmp * tmp; } else { return a * RepeatSquaring(a, index - 1); } } // 最大公約数(Greatest Common Divisor) // ユークリッドの互除法使用 ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } // 最小公倍数(Least Common Multiple) ll LCM(ll m, ll n) { // 引数に0がある場合は0を返す if (m == 0 || n == 0) return 0; // lcm = m * n / gcd(m, n) return ((m / GCD(m, n)) * n); } // 割り算した時に余りが有る時だけ、+1の商を返す。 ll div_one(ll res, ll div) { // res 割られる数、div 割る数 return (res + div - 1) / div; }
replace
89
90
89
90
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #define cerr if (false) cerr #define db(x) cerr << #x << "=" << x << endl #define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl #define db3(x, y, z) \ cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \ << endl #define dbv(v) \ cerr << #v << "="; \ for (auto _x : v) \ cerr << _x << ", "; \ cerr << endl #define dba(a, n) \ cerr << #a << "="; \ for (int _i = 0; _i < (n); ++_i) \ cerr << a[_i] << ", "; \ cerr << endl template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &x) { return os << "(" << x.first << "," << x.second << ")"; } typedef long long ll; typedef long double ld; int main() { int n; scanf("%d", &n); vector<int> a(3); const int MOD = 1e9 + 7; ll ans = 1; for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); int las, cnt = 0; for (int j = 0; j < 3; ++j) { if (a[j] == x) { ++cnt; las = j; } } assert(cnt > 0); ans = ans * cnt % MOD; ++a[las]; } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; // #define cerr if (false) cerr #define db(x) cerr << #x << "=" << x << endl #define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl #define db3(x, y, z) \ cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \ << endl #define dbv(v) \ cerr << #v << "="; \ for (auto _x : v) \ cerr << _x << ", "; \ cerr << endl #define dba(a, n) \ cerr << #a << "="; \ for (int _i = 0; _i < (n); ++_i) \ cerr << a[_i] << ", "; \ cerr << endl template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &x) { return os << "(" << x.first << "," << x.second << ")"; } typedef long long ll; typedef long double ld; int main() { int n; scanf("%d", &n); vector<int> a(3); const int MOD = 1e9 + 7; ll ans = 1; for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); int las, cnt = 0; for (int j = 0; j < 3; ++j) { if (a[j] == x) { ++cnt; las = j; } } if (cnt == 0) { printf("0\n"); return 0; } ans = ans * cnt % MOD; ++a[las]; } printf("%lld\n", ans); }
replace
40
41
40
44
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int add(int a, int b) { return a + b - mod * (a + b >= mod); } int mul(int a, int b) { return int(1ll * a * b % mod); } int power(int a, int x) { if (x == 0) { return 1; } return mul(power(mul(a, a), x >> 1), (x & 1 ? a : 1)); } int divide(int a, int b) { return mul(a, power(b, mod - 2)); } int sub(int a, int b) { return a - b + mod * (a < b); } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; cin >> n; int cnt[3] = {0}; int ans = 1; for (int i = 0; i < n; ++i) { int x; cin >> x; bool was = false; int kek = 0; for (int j = 0; j < 3; ++j) { if (x == cnt[j]) { if (!was) { ++cnt[j]; was = true; } else { kek = add(kek, ans); } } } assert(was); ans = add(ans, kek); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int add(int a, int b) { return a + b - mod * (a + b >= mod); } int mul(int a, int b) { return int(1ll * a * b % mod); } int power(int a, int x) { if (x == 0) { return 1; } return mul(power(mul(a, a), x >> 1), (x & 1 ? a : 1)); } int divide(int a, int b) { return mul(a, power(b, mod - 2)); } int sub(int a, int b) { return a - b + mod * (a < b); } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; cin >> n; int cnt[3] = {0}; int ans = 1; for (int i = 0; i < n; ++i) { int x; cin >> x; bool was = false; int kek = 0; for (int j = 0; j < 3; ++j) { if (x == cnt[j]) { if (!was) { ++cnt[j]; was = true; } else { kek = add(kek, ans); } } } if (!was) { cout << 0; return 0; } ans = add(ans, kek); } cout << ans; return 0; }
replace
44
45
44
48
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl using ll = long long; const ll mod = 1e9 + 7; const int maxn = 1e6 + 5; int n; int a[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } multiset<int> ms; ms.insert(0); ms.insert(0); ms.insert(0); ll res = 1; for (int i = 0; i < n; i++) { res = res * ms.count(a[i]) % mod; ms.erase(ms.find(a[i])); ms.insert(a[i] + 1); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl using ll = long long; const ll mod = 1e9 + 7; const int maxn = 1e6 + 5; int n; int a[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } multiset<int> ms; ms.insert(0); ms.insert(0); ms.insert(0); ll res = 1; for (int i = 0; i < n; i++) { res = res * ms.count(a[i]) % mod; if (res == 0) out(0); ms.erase(ms.find(a[i])); ms.insert(a[i] + 1); } cout << res << endl; return 0; }
insert
36
36
36
38
0
p02845
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long n; long long a[100002]; long long md = 1000000007ll; map<pair<pair<int, int>, pair<int, int>>, long long> mp; long long slv(int id, int rd, int bl, int gr) { // cout<<id<<" "<<rd<<" "<<bl<<" "<<gr<<endl; if (id == -1) { if (rd <= 0 && bl <= 0 && gr <= 0) return 1ll; else return 0ll; } if (id + 1 < rd || id + 1 < bl || id + 1 < gr) return (0ll); pair<pair<int, int>, pair<int, int>> p = make_pair(make_pair(id, rd), make_pair(bl, gr)); if (mp.count(p)) return (mp[p]); long long ret = 0ll; // rd if (rd == -1 || rd - 1 == a[id]) { if (rd == -1) ret += slv(id - 1, a[id], bl, gr); else ret += slv(id - 1, rd - 1, bl, gr); } // bl if (bl == -1 || bl - 1 == a[id]) { if (bl == -1) ret += slv(id - 1, rd, a[id], gr); else ret += slv(id - 1, rd, bl - 1, gr); } // gr if (gr == -1 || gr - 1 == a[id]) { if (gr == -1) ret += slv(id - 1, rd, bl, a[id]); else ret += slv(id - 1, rd, bl, gr - 1); } return (mp[p] = ret % md); } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } long long ans = slv(n - 1, -1, -1, -1); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; long long n; long long a[100002]; long long md = 1000000007ll; map<pair<pair<int, int>, pair<int, int>>, long long> mp; long long slv(int id, int rd, int bl, int gr) { // cout<<id<<" "<<rd<<" "<<bl<<" "<<gr<<endl; if (id == -1) { if (rd <= 0 && bl <= 0 && gr <= 0) return 1ll; else return 0ll; } if (id + 1 < rd || id + 1 < bl || id + 1 < gr) return (0ll); long long hoge = 0; if (rd != -1) hoge += rd; if (bl != -1) hoge += bl; if (gr != -1) hoge += gr; if (id + 1 < hoge) return (0ll); pair<pair<int, int>, pair<int, int>> p = make_pair(make_pair(id, rd), make_pair(bl, gr)); if (mp.count(p)) return (mp[p]); long long ret = 0ll; // rd if (rd == -1 || rd - 1 == a[id]) { if (rd == -1) ret += slv(id - 1, a[id], bl, gr); else ret += slv(id - 1, rd - 1, bl, gr); } // bl if (bl == -1 || bl - 1 == a[id]) { if (bl == -1) ret += slv(id - 1, rd, a[id], gr); else ret += slv(id - 1, rd, bl - 1, gr); } // gr if (gr == -1 || gr - 1 == a[id]) { if (gr == -1) ret += slv(id - 1, rd, bl, a[id]); else ret += slv(id - 1, rd, bl, gr - 1); } return (mp[p] = ret % md); } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } long long ans = slv(n - 1, -1, -1, -1); cout << ans << endl; }
insert
19
19
19
28
TLE
p02845
C++
Runtime Error
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<ll, ll> P; #define fi first #define se second #define all(v) (v).begin(), (v).end() const ll inf = (1e18); const ll mod = 1000000007; // ios_base::sync_with_stdio(false); // cin.tie(NULL); ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll c, ll d) { return c / gcd(c, d) * d; } struct __INIT { __INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __init; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } int main() { int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; multiset<ll> s; s.insert(0); s.insert(0); s.insert(0); ll ans = 1; for (int i = 0; i < n; i++) { ll t = s.count(a[i]); (ans *= t) %= mod; s.erase(s.find(a[i])); s.insert(a[i] + 1); } cout << ans << endl; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<ll, ll> P; #define fi first #define se second #define all(v) (v).begin(), (v).end() const ll inf = (1e18); const ll mod = 1000000007; // ios_base::sync_with_stdio(false); // cin.tie(NULL); ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll c, ll d) { return c / gcd(c, d) * d; } struct __INIT { __INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __init; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } int main() { int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; multiset<ll> s; s.insert(0); s.insert(0); s.insert(0); ll ans = 1; for (int i = 0; i < n; i++) { ll t = s.count(a[i]); if (t == 0) { cout << 0 << endl; return 0; } (ans *= t) %= mod; s.erase(s.find(a[i])); s.insert(a[i] + 1); } cout << ans << endl; }
insert
48
48
48
52
0
p02845
C++
Runtime Error
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; typedef unsigned long long int ull; typedef pair<ll, ll> P; template <class T> using V = vector<T>; #define fi first #define se second #define all(v) (v).begin(), (v).end() const ll inf = (1e18); // const ll mod=998244353; const ll mod = 1000000007; // ios_base::sync_with_stdio(false); // cin.tie(NULL); ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll c, ll d) { return c / gcd(c, d) * d; } struct __INIT { __INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __init; 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; } struct mint { using ull = unsigned long long int; ull v; mint(ll vv = 0) { s(vv % mod + mod); } mint &s(ull vv) { v = vv < mod ? vv : vv - mod; return *this; } // オーバーロード mint operator-() const { return mint() - *this; } // 符号反転 mint &operator+=(const mint &val) { return s(v + val.v); } mint &operator-=(const mint &val) { return s(v + mod - val.v); } mint &operator*=(const mint &val) { v = ull(v) * val.v % mod; return *this; } mint &operator/=(const mint &val) { return *this *= val.inv(); } mint operator+(const mint &val) { return mint(*this) += val; } mint operator-(const mint &val) { return mint(*this) -= val; } mint operator*(const mint &val) { return mint(*this) *= val; } mint operator/(const mint &val) { return mint(*this) /= val; } mint pow(int n) const { mint res(1), x(*this); while (n) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } mint inv() const { return pow(mod - 2); } // 拡張ユークリッドの互除法 /* mint inv()const{ int x,y; int g=extgcd(v,mod,x,y); assert(g==1); if(x<0)x+=mod; return mint(x); }*/ friend ostream &operator<<(ostream &os, const mint &val) { return os << val.v; } // 出力 bool operator<(const mint &val) const { return v < val.v; } bool operator==(const mint &val) const { return v == val.v; } bool operator>(const mint &val) const { return v > val.v; } }; const ll MAX = 2000010; // 設定 mint fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void init() { fac[0] = fac[1] = 1; for (int i = 1; i < MAX; i++) fac[i] = fac[i - 1] * i; finv[MAX - 1] = fac[MAX - 1].inv(); for (int i = MAX - 2; i >= 0; i--) finv[i] = finv[i + 1] * (i + 1); for (int i = MAX - 2; i >= 1; i--) inv[i] = finv[i] + fac[i - 1]; } // 階乗 mint factor(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k]; } // 二項係数計算 mint COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } int main() { int n; cin >> n; V<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; multiset<int> s; mint ans = 1; for (int i = 0; i < 3; i++) s.insert(0); for (int i = 0; i < n; i++) { int t = s.count(a[i]); s.erase(s.find(a[i])); s.insert(a[i] + 1); ans *= mint(t); } cout << ans << endl; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; typedef unsigned long long int ull; typedef pair<ll, ll> P; template <class T> using V = vector<T>; #define fi first #define se second #define all(v) (v).begin(), (v).end() const ll inf = (1e18); // const ll mod=998244353; const ll mod = 1000000007; // ios_base::sync_with_stdio(false); // cin.tie(NULL); ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll c, ll d) { return c / gcd(c, d) * d; } struct __INIT { __INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __init; 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; } struct mint { using ull = unsigned long long int; ull v; mint(ll vv = 0) { s(vv % mod + mod); } mint &s(ull vv) { v = vv < mod ? vv : vv - mod; return *this; } // オーバーロード mint operator-() const { return mint() - *this; } // 符号反転 mint &operator+=(const mint &val) { return s(v + val.v); } mint &operator-=(const mint &val) { return s(v + mod - val.v); } mint &operator*=(const mint &val) { v = ull(v) * val.v % mod; return *this; } mint &operator/=(const mint &val) { return *this *= val.inv(); } mint operator+(const mint &val) { return mint(*this) += val; } mint operator-(const mint &val) { return mint(*this) -= val; } mint operator*(const mint &val) { return mint(*this) *= val; } mint operator/(const mint &val) { return mint(*this) /= val; } mint pow(int n) const { mint res(1), x(*this); while (n) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } mint inv() const { return pow(mod - 2); } // 拡張ユークリッドの互除法 /* mint inv()const{ int x,y; int g=extgcd(v,mod,x,y); assert(g==1); if(x<0)x+=mod; return mint(x); }*/ friend ostream &operator<<(ostream &os, const mint &val) { return os << val.v; } // 出力 bool operator<(const mint &val) const { return v < val.v; } bool operator==(const mint &val) const { return v == val.v; } bool operator>(const mint &val) const { return v > val.v; } }; const ll MAX = 2000010; // 設定 mint fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void init() { fac[0] = fac[1] = 1; for (int i = 1; i < MAX; i++) fac[i] = fac[i - 1] * i; finv[MAX - 1] = fac[MAX - 1].inv(); for (int i = MAX - 2; i >= 0; i--) finv[i] = finv[i + 1] * (i + 1); for (int i = MAX - 2; i >= 1; i--) inv[i] = finv[i] + fac[i - 1]; } // 階乗 mint factor(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k]; } // 二項係数計算 mint COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } int main() { int n; cin >> n; V<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; multiset<int> s; mint ans = 1; for (int i = 0; i < 3; i++) s.insert(0); for (int i = 0; i < n; i++) { int t = s.count(a[i]); if (t == 0 || t > 3) { cout << 0 << endl; return 0; } s.erase(s.find(a[i])); s.insert(a[i] + 1); ans *= mint(t); } cout << ans << endl; }
insert
126
126
126
130
0
p02845
C++
Runtime Error
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; // vector string deque break continue #define forn(i, s, f) for (int i = (int)s; i < (int)f; i++) #define ll long long #define ull unsigned long long #define ld long double #define pii pair<int, int> #define fs first #define sc second #define pf push_front #define pb push_back #define pop_f pop_front #define pop_b pop_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() const int MOD = 1e9 + 7; int add(int x, int y) { x += y; if (x >= MOD) return x - MOD; return x; } int sub(int x, int y) { x -= y; if (x < 0) return x + MOD; return x; } int mul(int x, int y) { return (1LL * x * y) % MOD; } int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n; cin >> n; int ans = 1; multiset<int> a; forn(i, 0, 3) a.insert(-1); forn(i, 0, n) { int t; cin >> t; ans = mul(ans, a.count(t - 1)); a.erase(a.find(t - 1)); a.insert(t); } cout << ans; return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; // vector string deque break continue #define forn(i, s, f) for (int i = (int)s; i < (int)f; i++) #define ll long long #define ull unsigned long long #define ld long double #define pii pair<int, int> #define fs first #define sc second #define pf push_front #define pb push_back #define pop_f pop_front #define pop_b pop_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() const int MOD = 1e9 + 7; int add(int x, int y) { x += y; if (x >= MOD) return x - MOD; return x; } int sub(int x, int y) { x -= y; if (x < 0) return x + MOD; return x; } int mul(int x, int y) { return (1LL * x * y) % MOD; } int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n; cin >> n; int ans = 1; multiset<int> a; forn(i, 0, 3) a.insert(-1); forn(i, 0, n) { int t; cin >> t; ans = mul(ans, a.count(t - 1)); if (a.count(t - 1) == 0) { return cout << ans, 0; } a.erase(a.find(t - 1)); a.insert(t); } cout << ans; return 0; }
insert
51
51
51
54
0
p02845
C++
Runtime Error
#include <iostream> #include <set> using namespace std; long long int MOD = 1000000007; int N; int A[100005]; multiset<int> S; long long int dp[100005]; int main(void) { cin >> N; dp[0] = 1; for (int i = 1; i <= N; i++) { cin >> A[i]; } for (int i = 0; i <= 2; i++) { S.insert(0); } for (int i = 1; i <= N; i++) { long long int num = S.count(A[i]); dp[i] = (dp[i - 1] * num) % MOD; auto it = S.find(A[i]); S.erase(it); S.insert(A[i] + 1); } cout << dp[N] << endl; return 0; }
#include <iostream> #include <set> using namespace std; long long int MOD = 1000000007; int N; int A[100005]; multiset<int> S; long long int dp[100005]; int main(void) { cin >> N; dp[0] = 1; for (int i = 1; i <= N; i++) { cin >> A[i]; } for (int i = 0; i <= 2; i++) { S.insert(0); } for (int i = 1; i <= N; i++) { long long int num = S.count(A[i]); if (num == 0) { cout << 0 << endl; return 0; } dp[i] = (dp[i - 1] * num) % MOD; auto it = S.find(A[i]); S.erase(it); S.insert(A[i] + 1); } cout << dp[N] << endl; return 0; }
insert
29
29
29
33
0
p02845
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() #define dbg(x) cerr << #x << ": " << x << endl const ll mod = 1000000007; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> k(n); int s[3] = {0, 0, 0}; rep(i, n) { int cnt = 0; int nc = 4; rep(col, 3) { if (s[col] == a[i]) { cnt++; nc = min(nc, col); } } k[i] = cnt; s[nc]++; } ll ans = 1LL; rep(i, n) ans = (ans * k[i]) % mod; cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() #define dbg(x) cerr << #x << ": " << x << endl const ll mod = 1000000007; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> k(n); int s[3] = {0, 0, 0}; rep(i, n) { int cnt = 0; int nc = 4; rep(col, 3) { if (s[col] == a[i]) { cnt++; nc = min(nc, col); } } k[i] = cnt; if (nc > 3) break; dbg(nc); s[nc]++; } ll ans = 1LL; rep(i, n) ans = (ans * k[i]) % mod; cout << ans << endl; return 0; }
insert
28
28
28
31
0
p02845
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 = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define show(x) cout << #x << " = " << (x) << endl #define show2(x, y) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl #define show3(x, y, z) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \ << " = " << (z) << endl #define showv(v) \ rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ') #define showv2(v) rep(j, v.size()) showv(v[j]) #define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ') #define showt2(t, r, c) rep(j, r) showt(t[j], c) #define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second); #define printv(v) rep(i, v.size()) printf("%d\n", v[i]) #define printt(t, n) rep(i, n) printf("%d\n", t[i]) #define incl(v, x) find(all(v), x) != v.end() #define incls(s, c) s.find(c) != string::npos #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define bit(n, k) ((n >> k) & 1) // nのk bit目 #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define uni(x) x.erase(unique(all(x)), x.end()) #define SP << " " << #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vs = vector<string>; using P = pair<int, int>; using T = tuple<int, int, int>; using vp = vector<P>; using vt = vector<T>; const int mod = 1000000007; const double EPS = 1e-9; // const long double EPS = 1e-14; const int INF = (1 << 30) - 1; const ll LINF = (1LL << 62) - 1; #define dame \ { \ puts("No"); \ return 0; \ } #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } inline int in() { int x; scanf("%d", &x); return x; } inline ll lin() { ll x; scanf("%lld", &x); return x; } inline char chin() { char x; scanf("%c", &x); return x; } inline string stin() { string x; cin >> x; return x; } inline double din() { double x; scanf("%lf", &x); return x; } // template<class T = int> inline T in() { T x; cin >> x; return (x);} template <typename T> inline ll suma(const v(T) & a) { ll res(0); for (auto &&x : a) res += x; return res; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } char itoa(int n) { return n + '0'; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // const int mod = 1000000007; // mint(a).pow(b) -> a^b struct mint { ll x; mint(ll x = 0) : x(x % mod) {} mint operator-() const { return mint(-x); } mint operator~() const { return mint(1) / *this; } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } bool operator<(const mint &a) const { return x < a.x; } bool operator==(const mint &a) const { return x == a.x; } }; istream &operator>>(istream &i, mint &a) { i >> a.x; return i; } ostream &operator<<(ostream &o, const mint &a) { o << a.x; return o; } int main() { int n = in(); vl cnt(3); mint ans = 1; rep(i, n) { ll a = lin(); ans *= count(all(cnt), a); *find(all(cnt), a) += 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = (0); i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define limit(x, l, r) max(l, min(x, r)) #define lims(x, l, r) (x = max(l, min(x, r))) #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define show(x) cout << #x << " = " << (x) << endl #define show2(x, y) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl #define show3(x, y, z) \ cout << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z \ << " = " << (z) << endl #define showv(v) \ rep(i, v.size()) printf("%d%c", v[i], i == v.size() - 1 ? '\n' : ' ') #define showv2(v) rep(j, v.size()) showv(v[j]) #define showt(t, n) rep(i, n) printf("%d%c", t[i], i == n - 1 ? '\n' : ' ') #define showt2(t, r, c) rep(j, r) showt(t[j], c) #define showvp(p) rep(i, p.size()) printf("%d %d\n", p[i].first, p[i].second); #define printv(v) rep(i, v.size()) printf("%d\n", v[i]) #define printt(t, n) rep(i, n) printf("%d\n", t[i]) #define incl(v, x) find(all(v), x) != v.end() #define incls(s, c) s.find(c) != string::npos #define fi first #define se second #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define bit(n, k) ((n >> k) & 1) // nのk bit目 #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define uni(x) x.erase(unique(all(x)), x.end()) #define SP << " " << #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using vs = vector<string>; using P = pair<int, int>; using T = tuple<int, int, int>; using vp = vector<P>; using vt = vector<T>; const int mod = 1000000007; const double EPS = 1e-9; // const long double EPS = 1e-14; const int INF = (1 << 30) - 1; const ll LINF = (1LL << 62) - 1; #define dame \ { \ puts("No"); \ return 0; \ } #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } inline int in() { int x; scanf("%d", &x); return x; } inline ll lin() { ll x; scanf("%lld", &x); return x; } inline char chin() { char x; scanf("%c", &x); return x; } inline string stin() { string x; cin >> x; return x; } inline double din() { double x; scanf("%lf", &x); return x; } // template<class T = int> inline T in() { T x; cin >> x; return (x);} template <typename T> inline ll suma(const v(T) & a) { ll res(0); for (auto &&x : a) res += x; return res; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } char itoa(int n) { return n + '0'; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // const int mod = 1000000007; // mint(a).pow(b) -> a^b struct mint { ll x; mint(ll x = 0) : x(x % mod) {} mint operator-() const { return mint(-x); } mint operator~() const { return mint(1) / *this; } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } bool operator<(const mint &a) const { return x < a.x; } bool operator==(const mint &a) const { return x == a.x; } }; istream &operator>>(istream &i, mint &a) { i >> a.x; return i; } ostream &operator<<(ostream &o, const mint &a) { o << a.x; return o; } int main() { int n = in(); vl cnt(3); mint ans = 1; rep(i, n) { ll a = lin(); ans *= count(all(cnt), a); //*find(all(cnt),a) += 1; rep(i, 3) { if (cnt[i] == a) { cnt[i]++; break; } } } cout << ans << endl; return 0; }
replace
185
186
185
192
0
p02845
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define FOR_LT(i, beg, end) for (int i = beg; i < end; i++) #define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++) #define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--) using namespace std; int64_t kRem = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(20); int n; cin >> n; int nums[3] = {-1, -1, -1}; int64_t ans = 1; FOR_LT(i, 0, n) { int num; cin >> num; int64_t c = 0; bool sumi = false; FOR_LT(j, 0, 3) { if (nums[j] == num - 1) { c++; if (!sumi) { nums[j]++; sumi = true; } } } assert(sumi); ans *= c; ans %= kRem; } cout << ans << endl; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define FOR_LT(i, beg, end) for (int i = beg; i < end; i++) #define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++) #define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--) using namespace std; int64_t kRem = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(20); int n; cin >> n; int nums[3] = {-1, -1, -1}; int64_t ans = 1; FOR_LT(i, 0, n) { int num; cin >> num; int64_t c = 0; bool sumi = false; FOR_LT(j, 0, 3) { if (nums[j] == num - 1) { c++; if (!sumi) { nums[j]++; sumi = true; } } } if (!sumi) { cout << 0 << endl; return 0; } ans *= c; ans %= kRem; } cout << ans << endl; return 0; }
replace
57
58
57
61
0
p02845
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) 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 (b < a) { a = b; return 1; } return 0; } inline void Yes(bool condition) { if (condition) PRINT("Yes"); else PRINT("No"); } template <class itr> void cins(itr first, itr last) { for (auto i = first; i != last; i++) { cin >> (*i); } } template <class itr> void array_output(itr start, itr goal) { string ans = "", k = " "; for (auto i = start; i != goal; i++) ans += to_string(*i) + k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; } const ll INF = 1e15; const ll MOD = 1000000007; const ll MOD2 = 998244353; typedef pair<ll, ll> P; typedef pair<double, double> point; const ll MAX = 200005; constexpr ll nx[8] = {1, 0, -1, 0, 1, -1, 1, -1}; constexpr ll ny[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> a(n); cins(all(a)); ll ans = 1; vector<ll> c(3, 0); rep(i, n) { ll cnt = 0, ind = -1; rep(j, 3) { if (a[i] == c[j]) { cnt++; ind = j; } } (ans *= cnt) %= MOD; c[ind]++; } PRINT(ans); }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(), (V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) 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 (b < a) { a = b; return 1; } return 0; } inline void Yes(bool condition) { if (condition) PRINT("Yes"); else PRINT("No"); } template <class itr> void cins(itr first, itr last) { for (auto i = first; i != last; i++) { cin >> (*i); } } template <class itr> void array_output(itr start, itr goal) { string ans = "", k = " "; for (auto i = start; i != goal; i++) ans += to_string(*i) + k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; } const ll INF = 1e15; const ll MOD = 1000000007; const ll MOD2 = 998244353; typedef pair<ll, ll> P; typedef pair<double, double> point; const ll MAX = 200005; constexpr ll nx[8] = {1, 0, -1, 0, 1, -1, 1, -1}; constexpr ll ny[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> a(n); cins(all(a)); ll ans = 1; vector<ll> c(3, 0); rep(i, n) { ll cnt = 0, ind = 0; rep(j, 3) { if (a[i] == c[j]) { cnt++; ind = j; } } (ans *= cnt) %= MOD; c[ind]++; } PRINT(ans); }
replace
80
81
80
81
0
p02845
C++
Runtime Error
#include "bits/stdc++.h" #define rep(i, n) for (ll i = 0; i < n; i++) typedef long long ll; using namespace std; #define llMAX numeric_limits<long long>::max() #define intMAX numeric_limits<int>::max() #define d_5 100000 #define d9_7 1000000007 #define vll vector<vector<long long>> #define vl vector<long long> #define vi vector<int> #define vii vector<vector<int>> #define pb push_back #define pf push_front #define ld long double #define ll long long int main(void) { ll n; cin >> n; vl a(n); rep(i, n) { cin >> a[i]; } vll dp = vll(3, vl(n, 0)); dp[0][0] = 1; vl dp2(n, 1); // 結び目の個数 dp2[0] = 3; ll ans = 1; if (n <= 1) { a[1000000] = 0; } for (ll i = 1; i < n; i++) { ll num = a[i]; ll cross = 0; if (dp[0][i - 1] == num) cross += 1; ; if (dp[1][i - 1] == num) cross += 1; ; if (dp[2][i - 1] == num) cross += 1; ; dp2[i] = cross; if (cross == 0) { cout << 0 << endl; return 0; } rep(j, 3) { dp[j][i] = dp[j][i - 1]; } rep(k, 3) { if (dp[k][i - 1] == num) { dp[k][i] = num + 1; break; } } } rep(i, n) { ans *= dp2[i]; ans %= d9_7; } cout << ans % d9_7 << endl; return 0; }
#include "bits/stdc++.h" #define rep(i, n) for (ll i = 0; i < n; i++) typedef long long ll; using namespace std; #define llMAX numeric_limits<long long>::max() #define intMAX numeric_limits<int>::max() #define d_5 100000 #define d9_7 1000000007 #define vll vector<vector<long long>> #define vl vector<long long> #define vi vector<int> #define vii vector<vector<int>> #define pb push_back #define pf push_front #define ld long double #define ll long long int main(void) { ll n; cin >> n; vl a(n); rep(i, n) { cin >> a[i]; } vll dp = vll(3, vl(n, 0)); dp[0][0] = 1; vl dp2(n, 1); // 結び目の個数 dp2[0] = 3; ll ans = 1; if (a[0] != 0) { cout << 0; return 0; } if (n == 2) { if (a[1] == 1) { cout << 3; } else if (a[1] == 0) { cout << 6; } else { cout << 0; } return 0; } else if (n == 1) { cout << 3; return 0; } for (ll i = 1; i < n; i++) { ll num = a[i]; ll cross = 0; if (dp[0][i - 1] == num) cross += 1; ; if (dp[1][i - 1] == num) cross += 1; ; if (dp[2][i - 1] == num) cross += 1; ; dp2[i] = cross; if (cross == 0) { cout << 0 << endl; return 0; } rep(j, 3) { dp[j][i] = dp[j][i - 1]; } rep(k, 3) { if (dp[k][i - 1] == num) { dp[k][i] = num + 1; break; } } } rep(i, n) { ans *= dp2[i]; ans %= d9_7; } cout << ans % d9_7 << endl; return 0; }
replace
26
28
26
42
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll, ll> pll; typedef long double D; typedef complex<D> P; #define F first #define S second const ll MOD = 1000000007; // const ll MOD=998244353; template <typename T, typename U> istream &operator>>(istream &i, pair<T, U> &A) { i >> A.F >> A.S; return i; } template <typename T> istream &operator>>(istream &i, vector<T> &A) { for (auto &I : A) { i >> I; } return i; } template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &A) { o << A.F << " " << A.S; return o; } template <typename T> ostream &operator<<(ostream &o, const vector<T> &A) { ll i = A.size(); for (auto &I : A) { o << I << (--i ? " " : ""); } return o; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; vector<ll> A(N, 0); cin >> A; vector<ll> cnt(3, 0); ll ans = 1; for (auto &I : A) { ll c = 0, idx = -1; for (int j = 0; j < 3; j++) { if (cnt[j] == I) { c++; idx = j; } } ans *= c; cnt[idx]++; ans %= MOD; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll, ll> pll; typedef long double D; typedef complex<D> P; #define F first #define S second const ll MOD = 1000000007; // const ll MOD=998244353; template <typename T, typename U> istream &operator>>(istream &i, pair<T, U> &A) { i >> A.F >> A.S; return i; } template <typename T> istream &operator>>(istream &i, vector<T> &A) { for (auto &I : A) { i >> I; } return i; } template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &A) { o << A.F << " " << A.S; return o; } template <typename T> ostream &operator<<(ostream &o, const vector<T> &A) { ll i = A.size(); for (auto &I : A) { o << I << (--i ? " " : ""); } return o; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; vector<ll> A(N, 0); cin >> A; vector<ll> cnt(3, 0); ll ans = 1; for (auto &I : A) { ll c = 0, idx = -1; for (int j = 0; j < 3; j++) { if (cnt[j] == I) { c++; idx = j; } } if (c == 0) { ans = 0; break; } ans *= c; cnt[idx]++; ans %= MOD; } cout << ans << endl; return 0; }
insert
53
53
53
57
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef long long ll; typedef pair<int, int> P; const int MAX = 1e5 + 5; const int INF = 1001001001; const int MOD = 1e9 + 7; int main() { int N; cin >> N; vector<int> A(N); int maxA = 0; rep(i, N) { cin >> A[i]; maxA = max(maxA, A[i]); } vector<int> dp(maxA + 1); dp[0] = 3; ll ans = 1; rep(i, N) { int a = A[i]; ans *= dp[a]; ans %= MOD; dp[a]--; dp[a + 1]++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef long long ll; typedef pair<int, int> P; const int MAX = 1e5 + 5; const int INF = 1001001001; const int MOD = 1e9 + 7; int main() { int N; cin >> N; vector<int> A(N); int maxA = 0; rep(i, N) { cin >> A[i]; maxA = max(maxA, A[i]); } vector<int> dp(1e5 + 10); dp[0] = 3; ll ans = 1; rep(i, N) { int a = A[i]; ans *= dp[a]; ans %= MOD; dp[a]--; dp[a + 1]++; } cout << ans << endl; }
replace
23
24
23
24
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> #define vll vector<ll> #define vi vector<int> #define vpll vector<pair<ll, ll>> #define pii pair<int, int> #define REP(i, a) for (int(i) = 0; (i) < (a); (i)++) #define RREP(i, a) for (int(i) = a - 1; (i) >= (0); (i)--) #define REP2(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define MOD 1000000007 #define ALL(v) v.begin(), v.end() #define m0(x) memset(x, 0, sizeof(x)) 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; } typedef long long ll; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N; cin >> N; vector<ll> A(N); REP(i, N) cin >> A[i]; vector<ll> color(3, 0); ll ans = 1, id = -1, kouho = 0; REP(i, N) { id = -1; kouho = 0; REP(j, 3) { if (A[i] == color[j]) { kouho++; id = j; } } color[id]++; ans *= kouho; ans %= MOD; } cout << ans; return 0; }
#include <bits/stdc++.h> #define vll vector<ll> #define vi vector<int> #define vpll vector<pair<ll, ll>> #define pii pair<int, int> #define REP(i, a) for (int(i) = 0; (i) < (a); (i)++) #define RREP(i, a) for (int(i) = a - 1; (i) >= (0); (i)--) #define REP2(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define MOD 1000000007 #define ALL(v) v.begin(), v.end() #define m0(x) memset(x, 0, sizeof(x)) 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; } typedef long long ll; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N; cin >> N; vector<ll> A(N); REP(i, N) cin >> A[i]; vector<ll> color(3, 0); ll ans = 1, id = -1, kouho = 0; REP(i, N) { id = -1; kouho = 0; REP(j, 3) { if (A[i] == color[j]) { kouho++; id = j; } } if (id == -1) { cout << "0" << endl; return 0; } color[id]++; ans *= kouho; ans %= MOD; } cout << ans; return 0; }
insert
47
47
47
51
0
p02845
Python
Runtime Error
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) rbg = [-1, -1, -1] ans = 1 mod = 10**9 + 7 for A in a: ans *= rbg.count(A - 1) ans %= mod rbg[rbg.index(A - 1)] = A print(ans)
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) rbg = [-1, -1, -1] ans = 1 mod = 10**9 + 7 for A in a: ans *= rbg.count(A - 1) ans %= mod for i in range(3): if rbg[i] == A - 1: rbg[i] = A break print(ans)
replace
13
14
13
17
0
p02845
Python
Runtime Error
import sys readline = sys.stdin.buffer.readline n = int(readline()) A = map(int, readline().split()) mod = 1000000007 caps = [0] * 3 ans = 1 for a in A: ans *= caps.count(a) caps[caps.index(a)] += 1 ans %= mod print(ans)
import sys readline = sys.stdin.buffer.readline n = int(readline()) A = map(int, readline().split()) mod = 1000000007 caps = [0] * 3 ans = 1 for a in A: ans *= caps.count(a) # caps[caps.index(a)] += 1 for i in range(3): if caps[i] == a: caps[i] += 1 break ans %= mod print(ans)
replace
11
12
11
16
0
p02845
Python
Runtime Error
n = int(input()) a = list(map(int, input().split())) mod = 10**9 + 7 ans = 1 cnt = [0, 0, 0] for i in a: ans *= cnt.count(i) cnt[cnt.index(i)] += 1 ans %= mod print(ans)
n = int(input()) a = list(map(int, input().split())) mod = 10**9 + 7 ans = 1 cnt = [0, 0, 0] for i in a: ans *= cnt.count(i) for j in range(3): if cnt[j] == i: cnt[j] += 1 break ans %= mod print(ans)
replace
8
9
8
12
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define mod 1000000007 int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } ll ans = 1; multiset<int> se{0, 0, 0}; for (int i = 0; i < N; ++i) { ans *= se.count(A[i]); ans %= mod; auto iter = se.lower_bound(A[i]); se.erase(iter); se.insert(A[i] + 1); } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define mod 1000000007 int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } ll ans = 1; multiset<int> se{0, 0, 0}; for (int i = 0; i < N; ++i) { ans *= se.count(A[i]); if (se.count(A[i]) == 0) { cout << 0 << "\n"; return 0; } ans %= mod; auto iter = se.lower_bound(A[i]); se.erase(iter); se.insert(A[i] + 1); } cout << ans << "\n"; return 0; }
insert
18
18
18
22
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> #include <cassert> typedef long long int ll; using namespace std; // ---------------------------------------------------------------------- ll MOD = 1e9 + 7; // ll MOD = 998244353; // g = eGCD(a, b, s, t) ---> sa + tb = g constexpr ll eGCD(ll a, ll b, ll &s, ll &t) { if (a == 0) { s = 0; t = 1; return b; } ll u = 0; ll g = eGCD(b % a, a, t, u); s = u - (b / a) * t; return g; } constexpr ll gcd(ll a, ll b) { ll dummy1 = 0; ll dummy2 = 0; return eGCD(a, b, dummy1, dummy2); } struct Fp { ll val; Fp(ll t = 0) : val(t < 0 ? MOD + t % MOD : t >= MOD ? t % MOD : t) {} Fp &operator+=(const Fp &t) { val += t.val; if (val >= MOD) val -= MOD; return *this; } Fp &operator-=(const Fp &t) { val -= t.val; if (val < 0) val += MOD; return *this; } Fp &operator*=(const Fp &t) { val = (val * t.val) % MOD; return *this; } Fp inv() const { if (val == 0) { cerr << "inv() is called for zero." << endl; exit(1); } ll u = 0; ll v = 0; eGCD(val, MOD, u, v); return Fp(u); } Fp &operator/=(const Fp &t) { return (*this) *= t.inv(); } Fp operator+(const Fp &t) const { return Fp(val) += t; } Fp operator-(const Fp &t) const { return Fp(val) -= t; } Fp operator*(const Fp &t) const { return Fp(val) *= t; } Fp operator/(const Fp &t) const { return Fp(val) /= t; } Fp operator-() const { return Fp(-val); } bool operator==(const Fp &t) const { return val == t.val; } bool operator!=(const Fp &t) const { return val != t.val; } operator ll() const { return val; } }; class Comb { int nMax; vector<Fp> vFact; vector<Fp> vInvFact; public: Comb(int nm) : nMax(nm), vFact(nm + 1), vInvFact(nm + 1) { vFact.at(0) = 1; for (int i = 1; i <= nMax; i++) vFact.at(i) = i * vFact.at(i - 1); vInvFact.at(nMax) = vFact.at(nMax).inv(); for (int i = nMax; i >= 1; i--) vInvFact.at(i - 1) = i * vInvFact.at(i); } Fp fact(int n) { return vFact.at(n); } Fp comb(int n, int r) { return vFact.at(n) * vInvFact.at(r) * vInvFact.at(n - r); } // The number of permutation extracting r from n. Fp perm(int n, int r) { return vFact.at(n) * vInvFact.at(n - r); } }; /* Power function power(a, b) == a^b Speed is O(log b). The same source code can be used for integers by replacing Fp with int etc. Unfortunately, replacing Fp with auto does not make the function generic for int and Fp. */ Fp power(Fp a, int b) { Fp twoPow = a; Fp rv = 1; while (b > 0) { if (b & 1) rv *= twoPow; twoPow *= twoPow; b >>= 1; } return rv; } // ---------------------------------------------------------------------- int main(int argc, char *argv[]) { // C-style stdio functions should not be used. ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(20); int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); Fp cnt = 1; vector<int> nxt(3); nxt.at(0) = nxt.at(1) = nxt.at(2) = 0; for (int i = 0; i < N; i++) { int k = 0; int j0 = -1; for (int j = 0; j < 3; j++) { if (nxt.at(j) == A.at(i)) { k++; j0 = j; } } assert(j0 >= 0); cnt *= Fp(k); nxt.at(j0)++; } cout << (int)cnt << endl; return 0; }
#include <bits/stdc++.h> #include <cassert> typedef long long int ll; using namespace std; // ---------------------------------------------------------------------- ll MOD = 1e9 + 7; // ll MOD = 998244353; // g = eGCD(a, b, s, t) ---> sa + tb = g constexpr ll eGCD(ll a, ll b, ll &s, ll &t) { if (a == 0) { s = 0; t = 1; return b; } ll u = 0; ll g = eGCD(b % a, a, t, u); s = u - (b / a) * t; return g; } constexpr ll gcd(ll a, ll b) { ll dummy1 = 0; ll dummy2 = 0; return eGCD(a, b, dummy1, dummy2); } struct Fp { ll val; Fp(ll t = 0) : val(t < 0 ? MOD + t % MOD : t >= MOD ? t % MOD : t) {} Fp &operator+=(const Fp &t) { val += t.val; if (val >= MOD) val -= MOD; return *this; } Fp &operator-=(const Fp &t) { val -= t.val; if (val < 0) val += MOD; return *this; } Fp &operator*=(const Fp &t) { val = (val * t.val) % MOD; return *this; } Fp inv() const { if (val == 0) { cerr << "inv() is called for zero." << endl; exit(1); } ll u = 0; ll v = 0; eGCD(val, MOD, u, v); return Fp(u); } Fp &operator/=(const Fp &t) { return (*this) *= t.inv(); } Fp operator+(const Fp &t) const { return Fp(val) += t; } Fp operator-(const Fp &t) const { return Fp(val) -= t; } Fp operator*(const Fp &t) const { return Fp(val) *= t; } Fp operator/(const Fp &t) const { return Fp(val) /= t; } Fp operator-() const { return Fp(-val); } bool operator==(const Fp &t) const { return val == t.val; } bool operator!=(const Fp &t) const { return val != t.val; } operator ll() const { return val; } }; class Comb { int nMax; vector<Fp> vFact; vector<Fp> vInvFact; public: Comb(int nm) : nMax(nm), vFact(nm + 1), vInvFact(nm + 1) { vFact.at(0) = 1; for (int i = 1; i <= nMax; i++) vFact.at(i) = i * vFact.at(i - 1); vInvFact.at(nMax) = vFact.at(nMax).inv(); for (int i = nMax; i >= 1; i--) vInvFact.at(i - 1) = i * vInvFact.at(i); } Fp fact(int n) { return vFact.at(n); } Fp comb(int n, int r) { return vFact.at(n) * vInvFact.at(r) * vInvFact.at(n - r); } // The number of permutation extracting r from n. Fp perm(int n, int r) { return vFact.at(n) * vInvFact.at(n - r); } }; /* Power function power(a, b) == a^b Speed is O(log b). The same source code can be used for integers by replacing Fp with int etc. Unfortunately, replacing Fp with auto does not make the function generic for int and Fp. */ Fp power(Fp a, int b) { Fp twoPow = a; Fp rv = 1; while (b > 0) { if (b & 1) rv *= twoPow; twoPow *= twoPow; b >>= 1; } return rv; } // ---------------------------------------------------------------------- int main(int argc, char *argv[]) { // C-style stdio functions should not be used. ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(20); int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); Fp cnt = 1; vector<int> nxt(3); nxt.at(0) = nxt.at(1) = nxt.at(2) = 0; for (int i = 0; i < N; i++) { int k = 0; int j0 = -1; for (int j = 0; j < 3; j++) { if (nxt.at(j) == A.at(i)) { k++; j0 = j; } } if (j0 < 0) { cout << 0 << endl; return 0; } cnt *= Fp(k); nxt.at(j0)++; } cout << (int)cnt << endl; return 0; }
replace
144
145
144
148
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; long long mod = 1000000007; const int INF = 1001001001; int main() { ll n; cin >> n; ll ans = 1; vector<ll> count(40000, 0); for (ll i = 0; i < n; i++) { ll scope; cin >> scope; if (scope == 0) { ans = ans * (3 - (count.at(scope))) % mod; } else { ans = ans * (count.at(scope - 1) - count.at(scope)) % mod; } count.at(scope)++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; long long mod = 1000000007; const int INF = 1001001001; int main() { ll n; cin >> n; ll ans = 1; vector<ll> count(100001, 0); for (ll i = 0; i < n; i++) { ll scope; cin >> scope; if (scope == 0) { ans = ans * (3 - (count.at(scope))) % mod; } else { ans = ans * (count.at(scope - 1) - count.at(scope)) % mod; } count.at(scope)++; } cout << ans << endl; }
replace
10
11
10
11
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int mod = 1000000007; // const int mod = 998244353; // #define int long long // signed main(){ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; ll a[n]; for (ll i = 0; i < n; i++) { cin >> a[i]; } ll cnt[3][n + 1]; cnt[0][0] = 0; cnt[1][0] = 0; cnt[2][0] = 0; for (ll i = 0; i < n; i++) { ll c = 0; while (cnt[c][i] != a[i]) { c++; } for (ll j = 0; j < 3; j++) cnt[j][i + 1] = cnt[j][i]; cnt[c][i + 1]++; } for (ll i = 0; i < 3; i++) { for (ll j = 0; j < n; j++) { cerr << std::right << std::setw(2) << cnt[i][j]; } cerr << "\n"; } ll ans = 1; for (ll i = 0; i < n; i++) { ll tmp = 0; for (ll j = 0; j < 3; j++) if (a[i] == cnt[j][i]) tmp++; cerr << std::right << std::setw(2) << tmp; ans = (ans * tmp) % mod; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int mod = 1000000007; // const int mod = 998244353; // #define int long long // signed main(){ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; ll a[n]; for (ll i = 0; i < n; i++) { cin >> a[i]; } ll cnt[3][n + 1]; cnt[0][0] = 0; cnt[1][0] = 0; cnt[2][0] = 0; for (ll i = 0; i < n; i++) { ll c = 0; while (cnt[c][i] != a[i]) { c++; if (c == 3) { cout << "0" << "\n"; return 0; } } for (ll j = 0; j < 3; j++) cnt[j][i + 1] = cnt[j][i]; cnt[c][i + 1]++; } for (ll i = 0; i < 3; i++) { for (ll j = 0; j < n; j++) { cerr << std::right << std::setw(2) << cnt[i][j]; } cerr << "\n"; } ll ans = 1; for (ll i = 0; i < n; i++) { ll tmp = 0; for (ll j = 0; j < 3; j++) if (a[i] == cnt[j][i]) tmp++; cerr << std::right << std::setw(2) << tmp; ans = (ans * tmp) % mod; } cout << ans << "\n"; return 0; }
insert
29
29
29
34
0
0 1 2 3 4 5 0 0 0 0 0 0 0 0 0 0 0 0 3 1 1 1 1 1
p02845
C++
Runtime Error
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = long long; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; #define REP(var, a, b) for (int var = (a); var < (b); var++) #define rep(var, n) for (int var = 0; var < (n); ++var) #define ALL(c) (c).begin(), (c).end() #define rALL(c) (c).rbegin(), (c).rend() ll MOD = 1000000007; const ll INF = 1LL << 60; struct mint { ll x; mint(ll x = 0) : x(x % MOD) {} mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; int main() { // ll n; cin >> n; vl a(n); rep(i, n) cin >> a[i]; if (a[0] > 0) { cout << 0 << endl; return 0; } vl cnt(3, 0); mint ans(1); rep(i, n) { ll c = a[i]; mint coef(0); ll mink = -1; rep(k, 3) { if (cnt[k] == c) { mink = k; coef += 1; } } cnt[mink]++; ans *= coef; } cout << ans.x << endl; return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = long long; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; #define REP(var, a, b) for (int var = (a); var < (b); var++) #define rep(var, n) for (int var = 0; var < (n); ++var) #define ALL(c) (c).begin(), (c).end() #define rALL(c) (c).rbegin(), (c).rend() ll MOD = 1000000007; const ll INF = 1LL << 60; struct mint { ll x; mint(ll x = 0) : x(x % MOD) {} mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; int main() { // ll n; cin >> n; vl a(n); rep(i, n) cin >> a[i]; if (a[0] > 0) { cout << 0 << endl; return 0; } vl cnt(3, 0); mint ans(1); rep(i, n) { ll c = a[i]; mint coef(0); ll mink = -1; rep(k, 3) { if (cnt[k] == c) { mink = k; coef += 1; } } if (mink == -1) { cout << 0 << endl; return 0; } cnt[mink]++; ans *= coef; } cout << ans.x << endl; return 0; }
insert
101
101
101
105
0
p02845
C++
Runtime Error
#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()) #define put(a) ((cout) << (a) << (endl)) #define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl)) #define deg2rad(x) (((x)*PI) / (180.0)) #define rad2deg(x) (((x) * (180.0)) / PI) 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 T> static inline T gcd(T a, T b); template <class T> static inline T lcm(T a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); template <class T> T mod(T a, T m); int main(int argc, char *argv[]) { long long N; scanf("%lld", &N); std::vector<long long> A(N); for (int i = 0; i < N; i++) { scanf("%lld", &A[i]); } vector<ll> count(3); ll ans = 1; for (ll c : A) { int mul = 0, index = -1; rep(i, 0, 3) { if (count[i] != c) continue; mul++; index = i; } count[index]++; ans = mod(ans * mul, MOD); } put(ans); 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 T> inline T gcd(T a, T b) { return __gcd(a, b); } template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); } template <class T> T mod(T a, T m) { return (a % m + m) % m; }
#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()) #define put(a) ((cout) << (a) << (endl)) #define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl)) #define deg2rad(x) (((x)*PI) / (180.0)) #define rad2deg(x) (((x) * (180.0)) / PI) 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 T> static inline T gcd(T a, T b); template <class T> static inline T lcm(T a, T b); template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T &val); template <class T> T mod(T a, T m); int main(int argc, char *argv[]) { long long N; scanf("%lld", &N); std::vector<long long> A(N); for (int i = 0; i < N; i++) { scanf("%lld", &A[i]); } vector<ll> count(3); ll ans = 1; for (ll c : A) { int mul = 0, index = 0; rep(i, 0, 3) { if (count[i] != c) continue; mul++; index = i; } count[index]++; ans = mod(ans * mul, MOD); } put(ans); 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 T> inline T gcd(T a, T b) { return __gcd(a, b); } template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); } template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val) { std::fill((T *)arr, (T *)(arr + N), val); } template <class T> T mod(T a, T m) { return (a % m + m) % m; }
replace
64
65
64
65
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <typename T> T pow(T a, long long n, T e = 1) { T ret = e; while (n) { if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(long long x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; } ModInt &operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; } ModInt &operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; } ModInt &operator*=(ModInt rhs) { x = (unsigned long long)x * rhs.x % mod; return *this; } ModInt &operator/=(ModInt rhs) { x = (unsigned long long)x * rhs.inv().x % mod; return *this; } ModInt operator-() const { return -x < 0 ? mod - x : -x; } ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; } ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; } ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; } ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; } bool operator==(ModInt rhs) const { return x == rhs.x; } bool operator!=(ModInt rhs) const { return x != rhs.x; } ModInt inv() const { return pow(*this, mod - 2); } friend ostream &operator<<(ostream &s, ModInt<mod> a) { s << a.x; return s; } friend istream &operator>>(istream &s, ModInt<mod> &a) { s >> a.x; return s; } }; using mint = ModInt<1000000007>; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int r = 0, g = 0, b = 0; mint ans = 1; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == r && a == g && a == b) { r++; ans *= 3; } else if (a == r && a == g) { r++; ans *= 2; } else if (a == g && a == b) { g++; ans *= 2; } else if (a == r && a == b) { r++; ans *= 2; } else if (a == r) { r++; } else if (a == g) { g++; } else if (a == b) { b++; } else { assert(0); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; template <typename T> T pow(T a, long long n, T e = 1) { T ret = e; while (n) { if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(long long x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; } ModInt &operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; } ModInt &operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; } ModInt &operator*=(ModInt rhs) { x = (unsigned long long)x * rhs.x % mod; return *this; } ModInt &operator/=(ModInt rhs) { x = (unsigned long long)x * rhs.inv().x % mod; return *this; } ModInt operator-() const { return -x < 0 ? mod - x : -x; } ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; } ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; } ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; } ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; } bool operator==(ModInt rhs) const { return x == rhs.x; } bool operator!=(ModInt rhs) const { return x != rhs.x; } ModInt inv() const { return pow(*this, mod - 2); } friend ostream &operator<<(ostream &s, ModInt<mod> a) { s << a.x; return s; } friend istream &operator>>(istream &s, ModInt<mod> &a) { s >> a.x; return s; } }; using mint = ModInt<1000000007>; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int r = 0, g = 0, b = 0; mint ans = 1; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == r && a == g && a == b) { r++; ans *= 3; } else if (a == r && a == g) { r++; ans *= 2; } else if (a == g && a == b) { g++; ans *= 2; } else if (a == r && a == b) { r++; ans *= 2; } else if (a == r) { r++; } else if (a == g) { g++; } else if (a == b) { b++; } else { cout << 0 << endl; return 0; } } cout << ans << endl; }
replace
91
92
91
93
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // int/long: -2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31) // long/long long: -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 // (-2^63 <= long < 2^63) #define INF (1 << 29) // 536,870,912 // lower_bound(A.begin(), A.end(), N) // upper_bound(... // A.erase(unique(A.begin(), A.end()), A.end()) // bit: &/and, |/or, ^/xor, ~/not // getline(cin, String) // Graph // Warshall-Floyd: Distance between each node, N^3 // Dijkstra: Distance from the start node, N^2 // DFS(Depth-First Search) #define MOD 1000000007 int main() { long N; cin >> N; /* vector<long> A(N, 0); for (long i=0; i<N; i++) cin >>A.at(i); */ vector<vector<long>> C0; C0.push_back({0, 0, 0, 1}); vector<vector<long>> C1; for (long i = 0; i < N; i++) { C1.erase(C1.begin(), C1.end()); // long AA=A.at(i); long AA; cin >> AA; for (long j = 0; j < C0.size(); j++) { long c1 = C0.at(j).at(0); long c2 = C0.at(j).at(1); long c3 = C0.at(j).at(2); long cn = C0.at(j).at(3); if (AA == c1) C1.push_back({c1 + 1, c2, c3, cn}); if (AA == c2) C1.push_back({c1, c2 + 1, c3, cn}); if (AA == c3) C1.push_back({c1, c2, c3 + 1, cn}); } sort(C1.begin(), C1.end()); C0.erase(C0.begin(), C0.end()); C0.push_back(C1.at(0)); for (long k = 1; k < C1.size(); k++) { if ((C1.at(k).at(0) == C0.back().at(0)) && (C1.at(k).at(1) == C0.back().at(1)) && (C1.at(k).at(2) == C0.back().at(2))) { C0.back().at(3) += C1.at(k).at(3); C0.back().at(3) %= MOD; } else { C0.push_back(C1.at(k)); } } } long S = 0; for (long i = 0; i < C0.size(); i++) { S += C0.at(i).at(3); S %= MOD; } cout << S << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // int/long: -2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31) // long/long long: -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 // (-2^63 <= long < 2^63) #define INF (1 << 29) // 536,870,912 // lower_bound(A.begin(), A.end(), N) // upper_bound(... // A.erase(unique(A.begin(), A.end()), A.end()) // bit: &/and, |/or, ^/xor, ~/not // getline(cin, String) // Graph // Warshall-Floyd: Distance between each node, N^3 // Dijkstra: Distance from the start node, N^2 // DFS(Depth-First Search) #define MOD 1000000007 int main() { long N; cin >> N; /* vector<long> A(N, 0); for (long i=0; i<N; i++) cin >>A.at(i); */ vector<vector<long>> C0; C0.push_back({0, 0, 0, 1}); vector<vector<long>> C1; for (long i = 0; i < N; i++) { C1.erase(C1.begin(), C1.end()); // long AA=A.at(i); long AA; cin >> AA; for (long j = 0; j < C0.size(); j++) { long c1 = C0.at(j).at(0); long c2 = C0.at(j).at(1); long c3 = C0.at(j).at(2); long cn = C0.at(j).at(3); if (AA == c1) C1.push_back({c1 + 1, c2, c3, cn}); if (AA == c2) C1.push_back({c1, c2 + 1, c3, cn}); if (AA == c3) C1.push_back({c1, c2, c3 + 1, cn}); } if (0 == C1.size()) { cout << 0 << endl; return 0; } sort(C1.begin(), C1.end()); C0.erase(C0.begin(), C0.end()); C0.push_back(C1.at(0)); for (long k = 1; k < C1.size(); k++) { if ((C1.at(k).at(0) == C0.back().at(0)) && (C1.at(k).at(1) == C0.back().at(1)) && (C1.at(k).at(2) == C0.back().at(2))) { C0.back().at(3) += C1.at(k).at(3); C0.back().at(3) %= MOD; } else { C0.push_back(C1.at(k)); } } } long S = 0; for (long i = 0; i < C0.size(); i++) { S += C0.at(i).at(3); S %= MOD; } cout << S << endl; return 0; }
insert
54
54
54
58
0
p02845
C++
Runtime Error
#include <stdio.h> constexpr int kMod = int(1E9 + 7); constexpr int kN = int(1E5 + 10); int a[kN]; int main() { int n, cnt, x = 0, y = 0, z = 0; long long int ans = 1; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { cnt = 0; if (x == a[i]) cnt++; if (y == a[i]) cnt++; if (z == a[i]) cnt++; ans = (ans * cnt) % kMod; if (x == a[i]) x++; else if (y == a[i]) y++; else if (z == a[i]) z++; else a[kMod] = kN; } printf("%lld\n", ans); }
#include <stdio.h> constexpr int kMod = int(1E9 + 7); constexpr int kN = int(1E5 + 10); int a[kN]; int main() { int n, cnt, x = 0, y = 0, z = 0; long long int ans = 1; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { cnt = 0; if (x == a[i]) cnt++; if (y == a[i]) cnt++; if (z == a[i]) cnt++; ans = (ans * cnt) % kMod; if (x == a[i]) x++; else if (y == a[i]) y++; else if (z == a[i]) z++; // else a[kMod] = kN; } printf("%lld\n", ans); }
replace
25
27
25
26
0
p02845
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; using namespace literals; constexpr int Mod = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector<int> table(N / 3 + 2, 0); table[0] = 3; int64_t ans = 1; for (int i = 0; i < N; ++i) { int A; cin >> A; ans = ans * table[A] % Mod; --table[A]; ++table[A + 1]; } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; using namespace literals; constexpr int Mod = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector<int> table(N + 2, 0); table[0] = 3; int64_t ans = 1; for (int i = 0; i < N; ++i) { int A; cin >> A; ans = ans * table[A] % Mod; --table[A]; ++table[A + 1]; } cout << ans << endl; }
replace
9
10
9
10
0
p02845
C++
Runtime Error
// // main.cpp // #include <algorithm> #include <array> #include <assert.h> #include <iomanip> #include <iostream> #include <limits> #include <math.h> #include <memory> #include <queue> #include <random> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = int64_t; using ull = uint64_t; template <typename T> vector<T> make_vec_nd(T init, ll size) { return vector<T>(size, init); } template <typename T, typename... Args> auto make_vec_nd(T init, ll size, Args... rest) { auto inner = make_vec_nd(init, rest...); return vector<decltype(inner)>(size, inner); } #define rep(i, a, b) for (ll i = (a); i < (b); i++) #define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--) struct Mod { static ll BASE; ll value = 0; static ll residue(ll value) { return (value % BASE + BASE) % BASE; } Mod() : value(0) {} Mod(ll value) : value(residue(value)) {} Mod operator+(const Mod &rhs) const { return Mod(value + rhs.value); } void operator+=(const Mod &rhs) { *this = *this + rhs; } Mod operator-(const Mod &rhs) const { return Mod(value - rhs.value); } void operator-=(const Mod &rhs) { *this = *this - rhs; } Mod operator*(const Mod &rhs) const { return Mod(value * rhs.value); } void operator*=(const Mod &rhs) { *this = *this * rhs; } Mod operator/(const Mod &rhs) const { return *this * rhs.inv(); } void operator/=(const Mod &rhs) { *this = *this / rhs; } Mod inv() const { if (value == 0) { assert(false); throw "[Mod::inv] div by zero"; } ll ans, sub; ll d = Mod::gcd_with_coef(value, BASE, ans, sub); if (d != 1) { assert(false); throw "[Mod::inv] not invertible"; } return ans; } static ll gcd_with_coef(ll x, ll y, ll &out_cx, ll &out_cy) { if (x < 0) { ll d = gcd_with_coef(-x, y, out_cx, out_cy); out_cx *= -1; return d; } if (y < 0) { ll d = gcd_with_coef(x, -y, out_cx, out_cy); out_cy *= -1; return d; } if (x > y) { return gcd_with_coef(y, x, out_cy, out_cx); } if (x == 0) { out_cx = 0; out_cy = 1; return y; } ll q = y / x; ll r = y % x; ll d = gcd_with_coef(r, x, out_cy, out_cx); out_cx -= q * out_cy; return d; } static vector<vector<Mod>> binom_table(ll n) { vector<vector<Mod>> ans; auto get = [&ans](ll r, ll k) -> Mod { if (r < 0 || k < 0 || k > r) { return Mod(0); } else { return ans[r][k]; } }; ans.push_back({Mod(1)}); for (ll r = 1; r <= n; r++) { ans.push_back(vector<Mod>()); for (ll k = 0; k <= r; k++) { ans[r].push_back(get(r - 1, k) + get(r - 1, k - 1)); } } return ans; } static Mod power(Mod base, ll n) { assert(n >= 0); Mod ans(1); Mod pow(base); for (int i = 0; i < 63; i++) { if ((n >> i) & 1) { ans *= pow; } pow = pow * pow; } return ans; } }; ll Mod::BASE = 1000000007; int main() { ll N; cin >> N; vector<ll> Ais(N); rep(i, 0, N) { cin >> Ais[i]; } vector<ll> count(3); Mod ans = 1; rep(i, 0, N) { ll Ai = Ais[i]; ll matches = 0; ll first_match = numeric_limits<ll>::max(); rep(col, 0, 3) { if (count[col] == Ai) { matches++; first_match = min(first_match, col); } } ans *= matches; count[first_match]++; } cout << ans.value << endl; }
// // main.cpp // #include <algorithm> #include <array> #include <assert.h> #include <iomanip> #include <iostream> #include <limits> #include <math.h> #include <memory> #include <queue> #include <random> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = int64_t; using ull = uint64_t; template <typename T> vector<T> make_vec_nd(T init, ll size) { return vector<T>(size, init); } template <typename T, typename... Args> auto make_vec_nd(T init, ll size, Args... rest) { auto inner = make_vec_nd(init, rest...); return vector<decltype(inner)>(size, inner); } #define rep(i, a, b) for (ll i = (a); i < (b); i++) #define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--) struct Mod { static ll BASE; ll value = 0; static ll residue(ll value) { return (value % BASE + BASE) % BASE; } Mod() : value(0) {} Mod(ll value) : value(residue(value)) {} Mod operator+(const Mod &rhs) const { return Mod(value + rhs.value); } void operator+=(const Mod &rhs) { *this = *this + rhs; } Mod operator-(const Mod &rhs) const { return Mod(value - rhs.value); } void operator-=(const Mod &rhs) { *this = *this - rhs; } Mod operator*(const Mod &rhs) const { return Mod(value * rhs.value); } void operator*=(const Mod &rhs) { *this = *this * rhs; } Mod operator/(const Mod &rhs) const { return *this * rhs.inv(); } void operator/=(const Mod &rhs) { *this = *this / rhs; } Mod inv() const { if (value == 0) { assert(false); throw "[Mod::inv] div by zero"; } ll ans, sub; ll d = Mod::gcd_with_coef(value, BASE, ans, sub); if (d != 1) { assert(false); throw "[Mod::inv] not invertible"; } return ans; } static ll gcd_with_coef(ll x, ll y, ll &out_cx, ll &out_cy) { if (x < 0) { ll d = gcd_with_coef(-x, y, out_cx, out_cy); out_cx *= -1; return d; } if (y < 0) { ll d = gcd_with_coef(x, -y, out_cx, out_cy); out_cy *= -1; return d; } if (x > y) { return gcd_with_coef(y, x, out_cy, out_cx); } if (x == 0) { out_cx = 0; out_cy = 1; return y; } ll q = y / x; ll r = y % x; ll d = gcd_with_coef(r, x, out_cy, out_cx); out_cx -= q * out_cy; return d; } static vector<vector<Mod>> binom_table(ll n) { vector<vector<Mod>> ans; auto get = [&ans](ll r, ll k) -> Mod { if (r < 0 || k < 0 || k > r) { return Mod(0); } else { return ans[r][k]; } }; ans.push_back({Mod(1)}); for (ll r = 1; r <= n; r++) { ans.push_back(vector<Mod>()); for (ll k = 0; k <= r; k++) { ans[r].push_back(get(r - 1, k) + get(r - 1, k - 1)); } } return ans; } static Mod power(Mod base, ll n) { assert(n >= 0); Mod ans(1); Mod pow(base); for (int i = 0; i < 63; i++) { if ((n >> i) & 1) { ans *= pow; } pow = pow * pow; } return ans; } }; ll Mod::BASE = 1000000007; int main() { ll N; cin >> N; vector<ll> Ais(N); rep(i, 0, N) { cin >> Ais[i]; } vector<ll> count(3); Mod ans = 1; rep(i, 0, N) { ll Ai = Ais[i]; ll matches = 0; ll first_match = numeric_limits<ll>::max(); rep(col, 0, 3) { if (count[col] == Ai) { matches++; first_match = min(first_match, col); } } if (matches == 0) { cout << 0 << endl; return 0; } ans *= matches; count[first_match]++; } cout << ans.value << endl; }
insert
143
143
143
147
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> #define fr(i, n) for (int i = 0; i < (n); ++i) #define foor(i, a, b) for (int i = (a); i <= (b); ++i) #define rf(i, n) for (int i = (n); i-- > 0;) #define roof(i, b, a) for (int i = (b); i >= (a); --i) #define elsif else if #define all(x) x.begin(), x.end() #define Sort(x) sort(all(x)) #define Reverse(x) reverse(all(x)) #define PQ priority_queue #define NP(x) next_permutation(all(x)) #define M_PI 3.14159265358979323846 #define popcount __builtin_popcount using namespace std; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vi; typedef vector<vi> vvi; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef unsigned long long ull; typedef vector<ull> vu; typedef vector<vu> vvu; typedef double dbl; typedef vector<dbl> vd; typedef vector<vd> vvd; typedef string str; typedef vector<str> vs; typedef vector<vs> vvs; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef map<int, int> mii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef map<ll, ll> mll; typedef pair<dbl, dbl> pdd; typedef vector<pdd> vpdd; typedef map<dbl, dbl> mdd; typedef pair<str, str> pss; typedef vector<pss> vpss; typedef map<str, str> mss; typedef pair<int, ll> pil; typedef vector<pil> vpil; typedef map<int, ll> mil; typedef pair<ll, int> pli; typedef vector<pli> vpli; typedef map<ll, int> mli; typedef pair<dbl, int> pdi; typedef vector<pdi> vpdi; typedef map<dbl, int> mdi; template <typename T> vector<T> &operator<<(vector<T> &v, const T t) { v.push_back(t); return v; } template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) { m.insert(t); return m; } template <typename T> set<T> &operator<<(set<T> &s, const T t) { s.insert(t); return s; } template <typename T> stack<T> &operator<<(stack<T> &s, const T t) { s.push(t); return s; } template <typename T> stack<T> &operator>>(stack<T> &s, T &t) { t = s.top(); s.pop(); return s; } template <typename T> queue<T> &operator<<(queue<T> &q, const T t) { q.push(t); return q; } template <typename T> queue<T> &operator>>(queue<T> &q, T &t) { t = q.front(); q.pop(); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) { q.push(t); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator>>(PQ<T, vector<T>, U> &q, T &t) { t = q.top(); q.pop(); return q; } template <typename T, typename U> istream &operator>>(istream &s, pair<T, U> &p) { return s >> p.first >> p.second; } istream &operator>>(istream &s, _Bit_reference b) { int a; s >> a; assert(a == 0 || a == 1); b = a; return s; } template <typename T> istream &operator>>(istream &s, vector<T> &v) { fr(i, v.size()) { s >> v[i]; } return s; } template <typename T, typename U> ostream &operator<<(ostream &s, const pair<T, U> p) { return s << p.first << " " << p.second; } // template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto // a:v){s<<a<<"\n";}return s;} template <typename T> ostream &operator<<(ostream &s, const vector<T> v) { fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; } return s; } template <typename T> ostream &operator<<(ostream &s, const deque<T> d) { fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; } return s; } template <typename T> _Bit_reference operator&=(_Bit_reference b, T t) { return b = b & t; } template <typename T> _Bit_reference operator^=(_Bit_reference b, T t) { return b = b ^ t; } template <typename T> _Bit_reference operator|=(_Bit_reference b, T t) { return b = b | t; } template <typename T, typename U> pair<T, U> operator+(pair<T, U> a, pair<T, U> b) { return {a.first + b.first, a.second + b.second}; } template <typename T, typename U> pair<T, U> operator-(pair<T, U> a, pair<T, U> b) { return {a.first - b.first, a.second - b.second}; } template <typename T, typename U> pair<T, U> &operator+=(pair<T, U> &a, pair<T, U> b) { return a = a + b; } template <typename T, typename U> pair<T, U> &operator-=(pair<T, U> &a, pair<T, U> b) { return a = a - b; } void print(void) { cout << "\n"; } void Print(void) { cout << endl; } template <typename T> void print(T t) { cout << t << "\n"; } template <typename T> void Print(T t) { cout << t << endl; } template <typename T, typename... U> void print(T &&t, U &&...u) { cout << t << " "; print(forward<U>(u)...); } template <typename T, typename... U> void Print(T &&t, U &&...u) { cout << t << " "; Print(forward<U>(u)...); } bool YN(bool b) { print(b ? "YES" : "NO"); return b; } bool PI(bool b) { print(b ? "POSSIBLE" : "IMPOSSIBLE"); return b; } bool Yn(bool b) { print(b ? "Yes" : "No"); return b; } bool Pi(bool b) { print(b ? "Possible" : "Impossible"); return b; } bool yn(bool b) { print(b ? "yes" : "no"); return b; } bool pi(bool b) { print(b ? "possible" : "impossible"); return b; } const int e5 = 1e5; const int e9 = 1e9; const int MD = 1e9 + 7; const int md = 998244353; const ll e18 = 1e18; template <typename T> str to_string(const T &n) { ostringstream s; s << n; return s.str(); } template <typename T> T &chmax(T &a, T b) { return a = max(a, b); } template <typename T> T &chmin(T &a, T b) { return a = min(a, b); } template <typename T, typename U> vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> &E, const U s, const T inf) { using P = pair<T, U>; vector<P> d; fr(i, E.size()) { d << P{inf, i}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } template <typename T, typename U> map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s, const T inf) { using P = pair<T, U>; map<U, P> d; for (pair<U, vector<P>> e : E) { d[e.first] = P{inf, e.first}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } ll maxflow(vector<mil> &E, int s, int t) { ll z = 0; vi b(E.size(), -1); for (int i = 0;; ++i) { static auto dfs = [&](int v, ll f, auto &dfs) -> ll { if (v == t) return f; b[v] = i; for (auto &p : E[v]) { if (b[p.first] < i && p.second) { if (ll r = dfs(p.first, min(f, p.second), dfs)) { p.second -= r; E[p.first][v] += r; return r; } } } return 0; }; ll x = dfs(s, ll(1e18), dfs); z += x; if (x == 0) return z; } } template <typename T> T distsq(pair<T, T> a, pair<T, T> b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } template <typename T> T max(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = max(m, e); } return m; } template <typename T> T min(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = min(m, e); } return m; } template <typename T> T gcd(const T a, const T b) { return a ? gcd(b % a, a) : b; } template <typename T> T gcd(const vector<T> a) { T g = a[0]; for (T e : a) { g = gcd(g, e); } return g; } template <typename T> vector<T> LCS(vector<T> A, vector<T> B) { int N = A.size(), M = B.size(); vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1)); fr(i, N) { fr(j, M) { if (A[i] == B[j]) { d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}}; } else { d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]); } } } vector<T> r; for (pii p = {N, M}; d[p.first][p.second].first; p = d[p.first][p.second].second) { r << A[d[p.first][p.second].second.first]; } Reverse(r); return r; } str LCS(str S, str T) { vector<char> s = LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end())); return str(s.begin(), s.end()); } template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) { if (V.size() <= 3) { return V; } Sort(V); rf(i, V.size() - 1) V << V[i]; vector<pair<T, T>> r; for (pair<T, T> p : V) { int s = r.size(); while (s >= 2 && (p.second - r[s - 1].second) * (p.first - r[s - 2].first) < (p.second - r[s - 2].second) * (p.first - r[s - 1].first)) { r.pop_back(); --s; } r << p; } r.pop_back(); return r; } class UnionFind { vi p, s; void extend(int N) { foor(i, p.size(), N) { p << i; s << 1; } } public: UnionFind(void) {} UnionFind(int N) { extend(N - 1); } int find(int i) { extend(i); return p[i] = p[i] == i ? i : find(p[i]); } void unite(int a, int b) { extend(a); extend(b); if ((a = find(a)) != (b = find(b))) { if (s[a] > s[b]) { swap(a, b); } s[b] += s[a]; p[a] = b; } } void unite(pii p) { return unite(p.first, p.second); } bool same(int a, int b) { extend(a); extend(b); return find(a) == find(b); } bool same(pii p) { return same(p.first, p.second); } int size(int x) { extend(x); return s[find(x)]; } }; ll MST(vector<pair<ll, pii>> &E) { Sort(E); UnionFind uf; ll z = 0; for (auto &e : E) { if (!uf.same(e.second)) { z += e.first; uf.unite(e.second); } } return z; } ll strmod(const str &s, const int m) { ll x = 0; fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; } return x; } vvl mul(const vvl &A, const vvl &B, const int m) { vvl C; fr(y, A.size()) { C << vl(B[y].size()); } fr(y, C.size()) { fr(x, C[y].size()) { fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; } } } return C; } vvl pow(const vvl &A, const ll n, const int m) { vvl B; fr(y, A.size()) { B << vl(A.size()); } if (n == 0) { fr(i, B.size()) { B[i][i] = 1; } } elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); } else { vvl C = pow(A, n / 2, m); B = mul(C, C, m); } return B; } ll pow(const ll a, const ll n, const int m) { ll t; return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) * (t = pow(a, n >> 1, m), t * t % m) % m : !!a; } ll inv(const ll x, const int p) { assert(x != 0); return pow(x, p - 2, p); } ll inv(const ll x) { return inv(x, MD); } vpll fact(const int n, const int p) { assert(n < p); vpll v(n + 1); v[0].first = 1; foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; } v[n].second = inv(v[n].first, p); roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; } return v; } class Combination { const vpll f; const int M; public: Combination(int n, int m) : f(fact(n, m)), M(m) {} Combination(int n) : Combination(n, MD) {} ll P(int n, int k) { return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M; } ll C(int n, int k) { return k < 0 ? 0 : P(n, k) * f[k].second % M; } ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); } ll F(int n) { return n < 0 ? 0 : f[n].first; } }; ll C2(const int n) { return (ll)n * ~-n / 2; } ll sum(const vi a) { ll s = 0; for (int e : a) { s += e; } return s; } ll sum(const vl a) { ll s = 0; for (ll e : a) { s += e; } return s; } template <typename T> int MSB(T N) { int r = -1; for (; N > 0; N /= 2) { ++r; } return r; } template <typename T> class SegmentTree { vector<T> S; T (*const op)(T a, T b); const T zero; const int B; public: SegmentTree(int N, T (*f)(T a, T b), const T zero) : S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero), B(1 << MSB(N - 1) + 1) {} SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero) : SegmentTree(v.size(), f, zero) { fr(i, v.size()) { S[S.size() / 2 + i] = v[i]; } roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); } } T calc(int l, int r) { l += B; r += B; if (l > r) { return zero; } if (l == r) { return S[l]; } T L = S[l], R = S[r]; for (; l / 2 < r / 2; l /= 2, r /= 2) { if (l % 2 == 0) { L = op(L, S[l + 1]); } if (r % 2 == 1) { R = op(S[r - 1], R); } } return op(L, R); } void replace(int i, T x) { for (S[i += B] = x; i != 1; i /= 2) { if (i % 2) { S[i / 2] = op(S[i - 1], S[i]); } else { S[i / 2] = op(S[i], S[i + 1]); } } } void add(int i, T x) { replace(i, op(S[B + i], x)); } T top() { return S[1]; } T get(int i) { return S[i + B]; } }; ll BITsum(vl &B, int i) { ll z = 0; while (i > 0) { z += B[i]; i -= i & -i; } return z; } void BITadd(vl &B, int i, ll x) { while (i < B.size()) { B[i] += x; i += i & -i; } } ll fib(const ll n, const int m) { ll a, b, c, d, A, B, C, D; a = 1; b = 0; c = 0; d = 1; rf(i, 63) { A = a * a + b * c; B = a * b + b * d; C = c * a + d * c; D = c * b + d * d; if (n >> i & 1) { a = A; b = B; c = C; d = D; A = a + b; B = a; C = c + d; D = c; } a = A % m; b = B % m; c = C % m; d = D % m; } return b; } vi primes(int n) { vb b(n + 1); vi p; foor(i, 2, n) { if (!b[i]) { p << i; for (int j = 2 * i; j <= n; j += i) { b[j] = true; } } } return p; } vb isprime(const int n) { vb v(n + 1, true); v[0] = v[1] = false; foor(i, 2, n) { if (v[i]) { for (int j = 2 * i; j <= n; j += i) { v[j] = false; } } } return v; } class LCA { vvi par; vi dep; public: LCA(vvi &E, int root) : par(MSB(E.size()) + 1, vi(E.size())), dep(E.size()) { function<void(int, int)> dfs = [&](int i, int p) { for (int j : E[i]) if (j != p) { par[0][j] = i; dep[j] = dep[i] + 1; dfs(j, i); } }; par[0][root] = root; dfs(root, root); fr(i, par.size() - 1) { fr(j, par[0].size()) { par[i + 1][j] = par[i][par[i][j]]; } } } int operator()(int a, int b) { if (dep[a] > dep[b]) swap(a, b); for (int t = dep[b] - dep[a], i = 0; t; t >>= 1, ++i) { if (t & 1) { b = par[i][b]; } } if (a == b) return a; rf(i, par.size()) { if (par[i][a] != par[i][b]) { a = par[i][a]; b = par[i][b]; } } return par[0][a]; } }; vpli factor(ll N) { vpli r; for (ll i = 2; i * i <= N; ++i) { if (N % i == 0) { r << pli{i, 0}; while (N % i == 0) { N /= i; ++r.back().second; } } } if (N > 1) { r << pli{N, 1}; } return r; } vl divisors(ll n) { vl r; ll m = sqrt(n); foor(i, 1, m) if (n % i == 0) r << ll(i); rf(i, r.size() - (m * m == n)) r << n / r[i]; return r; } vi SuffixArray(str S) { int N = S.size(); vi rank(N + 1), tmp(N + 1), sa(N + 1); fr(i, N) { sa[i] = i; rank[i] = S[i]; } sa[N] = N; rank[N] = -1; int k; auto cmp = [&](int &a, int &b) -> bool { if (rank[a] != rank[b]) return rank[a] < rank[b]; return (a + k <= N ? rank[a + k] : -1) < (b + k <= N ? rank[b + k] : -1); }; for (k = 1; k <= N; k *= 2) { sort(all(sa), cmp); tmp[sa[0]] = 0; foor(i, 1, N) { tmp[sa[i]] = tmp[sa[i - 1]] + cmp(sa[i - 1], sa[i]); } rank = tmp; } return sa; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int r = 0, g = 0, b = 0; ll z = 1; fr(i, N) { int A; cin >> A; if (r == A) { z *= (r == A) + (g == A) + (b == A); ++r; } elsif(g == A) { z *= (r == A) + (g == A) + (b == A); ++g; } elsif(b == A) { z *= (r == A) + (g == A) + (b == A); ++b; } else { assert(false); } z %= MD; } print(z); return 0; }
#include <bits/stdc++.h> #define fr(i, n) for (int i = 0; i < (n); ++i) #define foor(i, a, b) for (int i = (a); i <= (b); ++i) #define rf(i, n) for (int i = (n); i-- > 0;) #define roof(i, b, a) for (int i = (b); i >= (a); --i) #define elsif else if #define all(x) x.begin(), x.end() #define Sort(x) sort(all(x)) #define Reverse(x) reverse(all(x)) #define PQ priority_queue #define NP(x) next_permutation(all(x)) #define M_PI 3.14159265358979323846 #define popcount __builtin_popcount using namespace std; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<int> vi; typedef vector<vi> vvi; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef unsigned long long ull; typedef vector<ull> vu; typedef vector<vu> vvu; typedef double dbl; typedef vector<dbl> vd; typedef vector<vd> vvd; typedef string str; typedef vector<str> vs; typedef vector<vs> vvs; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef map<int, int> mii; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef map<ll, ll> mll; typedef pair<dbl, dbl> pdd; typedef vector<pdd> vpdd; typedef map<dbl, dbl> mdd; typedef pair<str, str> pss; typedef vector<pss> vpss; typedef map<str, str> mss; typedef pair<int, ll> pil; typedef vector<pil> vpil; typedef map<int, ll> mil; typedef pair<ll, int> pli; typedef vector<pli> vpli; typedef map<ll, int> mli; typedef pair<dbl, int> pdi; typedef vector<pdi> vpdi; typedef map<dbl, int> mdi; template <typename T> vector<T> &operator<<(vector<T> &v, const T t) { v.push_back(t); return v; } template <typename T> multiset<T> &operator<<(multiset<T> &m, const T t) { m.insert(t); return m; } template <typename T> set<T> &operator<<(set<T> &s, const T t) { s.insert(t); return s; } template <typename T> stack<T> &operator<<(stack<T> &s, const T t) { s.push(t); return s; } template <typename T> stack<T> &operator>>(stack<T> &s, T &t) { t = s.top(); s.pop(); return s; } template <typename T> queue<T> &operator<<(queue<T> &q, const T t) { q.push(t); return q; } template <typename T> queue<T> &operator>>(queue<T> &q, T &t) { t = q.front(); q.pop(); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator<<(PQ<T, vector<T>, U> &q, const T t) { q.push(t); return q; } template <typename T, typename U> PQ<T, vector<T>, U> &operator>>(PQ<T, vector<T>, U> &q, T &t) { t = q.top(); q.pop(); return q; } template <typename T, typename U> istream &operator>>(istream &s, pair<T, U> &p) { return s >> p.first >> p.second; } istream &operator>>(istream &s, _Bit_reference b) { int a; s >> a; assert(a == 0 || a == 1); b = a; return s; } template <typename T> istream &operator>>(istream &s, vector<T> &v) { fr(i, v.size()) { s >> v[i]; } return s; } template <typename T, typename U> ostream &operator<<(ostream &s, const pair<T, U> p) { return s << p.first << " " << p.second; } // template<typename T>ostream&operator<<(ostream&s,const vector<T>v){for(auto // a:v){s<<a<<"\n";}return s;} template <typename T> ostream &operator<<(ostream &s, const vector<T> v) { fr(i, v.size()) { i ? s << " " << v[i] : s << v[i]; } return s; } template <typename T> ostream &operator<<(ostream &s, const deque<T> d) { fr(i, d.size()) { i ? s << " " << d[i] : s << d[i]; } return s; } template <typename T> _Bit_reference operator&=(_Bit_reference b, T t) { return b = b & t; } template <typename T> _Bit_reference operator^=(_Bit_reference b, T t) { return b = b ^ t; } template <typename T> _Bit_reference operator|=(_Bit_reference b, T t) { return b = b | t; } template <typename T, typename U> pair<T, U> operator+(pair<T, U> a, pair<T, U> b) { return {a.first + b.first, a.second + b.second}; } template <typename T, typename U> pair<T, U> operator-(pair<T, U> a, pair<T, U> b) { return {a.first - b.first, a.second - b.second}; } template <typename T, typename U> pair<T, U> &operator+=(pair<T, U> &a, pair<T, U> b) { return a = a + b; } template <typename T, typename U> pair<T, U> &operator-=(pair<T, U> &a, pair<T, U> b) { return a = a - b; } void print(void) { cout << "\n"; } void Print(void) { cout << endl; } template <typename T> void print(T t) { cout << t << "\n"; } template <typename T> void Print(T t) { cout << t << endl; } template <typename T, typename... U> void print(T &&t, U &&...u) { cout << t << " "; print(forward<U>(u)...); } template <typename T, typename... U> void Print(T &&t, U &&...u) { cout << t << " "; Print(forward<U>(u)...); } bool YN(bool b) { print(b ? "YES" : "NO"); return b; } bool PI(bool b) { print(b ? "POSSIBLE" : "IMPOSSIBLE"); return b; } bool Yn(bool b) { print(b ? "Yes" : "No"); return b; } bool Pi(bool b) { print(b ? "Possible" : "Impossible"); return b; } bool yn(bool b) { print(b ? "yes" : "no"); return b; } bool pi(bool b) { print(b ? "possible" : "impossible"); return b; } const int e5 = 1e5; const int e9 = 1e9; const int MD = 1e9 + 7; const int md = 998244353; const ll e18 = 1e18; template <typename T> str to_string(const T &n) { ostringstream s; s << n; return s.str(); } template <typename T> T &chmax(T &a, T b) { return a = max(a, b); } template <typename T> T &chmin(T &a, T b) { return a = min(a, b); } template <typename T, typename U> vector<pair<T, U>> dijkstra(const vector<vector<pair<T, U>>> &E, const U s, const T inf) { using P = pair<T, U>; vector<P> d; fr(i, E.size()) { d << P{inf, i}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } template <typename T, typename U> map<U, pair<T, U>> dijkstra(map<U, vector<pair<T, U>>> E, const U s, const T inf) { using P = pair<T, U>; map<U, P> d; for (pair<U, vector<P>> e : E) { d[e.first] = P{inf, e.first}; } PQ<P, vector<P>, greater<P>> pq; pq << (d[s] = P{0, s}); while (pq.size()) { P a = pq.top(); pq.pop(); U v = a.second; if (d[v].first >= a.first) { for (P e : E[v]) { if (d[v].first + e.first < d[e.second].first) { d[e.second] = P{d[v].first + e.first, v}; pq << P{d[v].first + e.first, e.second}; } } } } return d; } ll maxflow(vector<mil> &E, int s, int t) { ll z = 0; vi b(E.size(), -1); for (int i = 0;; ++i) { static auto dfs = [&](int v, ll f, auto &dfs) -> ll { if (v == t) return f; b[v] = i; for (auto &p : E[v]) { if (b[p.first] < i && p.second) { if (ll r = dfs(p.first, min(f, p.second), dfs)) { p.second -= r; E[p.first][v] += r; return r; } } } return 0; }; ll x = dfs(s, ll(1e18), dfs); z += x; if (x == 0) return z; } } template <typename T> T distsq(pair<T, T> a, pair<T, T> b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } template <typename T> T max(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = max(m, e); } return m; } template <typename T> T min(const vector<T> a) { assert(a.size()); T m = a[0]; for (T e : a) { m = min(m, e); } return m; } template <typename T> T gcd(const T a, const T b) { return a ? gcd(b % a, a) : b; } template <typename T> T gcd(const vector<T> a) { T g = a[0]; for (T e : a) { g = gcd(g, e); } return g; } template <typename T> vector<T> LCS(vector<T> A, vector<T> B) { int N = A.size(), M = B.size(); vector<vector<pair<int, pii>>> d(N + 1, vector<pair<int, pii>>(M + 1)); fr(i, N) { fr(j, M) { if (A[i] == B[j]) { d[i + 1][j + 1] = {d[i][j].first + 1, {i, j}}; } else { d[i + 1][j + 1] = max(d[i][j + 1], d[i + 1][j]); } } } vector<T> r; for (pii p = {N, M}; d[p.first][p.second].first; p = d[p.first][p.second].second) { r << A[d[p.first][p.second].second.first]; } Reverse(r); return r; } str LCS(str S, str T) { vector<char> s = LCS(vector<char>(S.begin(), S.end()), vector<char>(T.begin(), T.end())); return str(s.begin(), s.end()); } template <typename T> vector<pair<T, T>> ConvexHull(vector<pair<T, T>> V) { if (V.size() <= 3) { return V; } Sort(V); rf(i, V.size() - 1) V << V[i]; vector<pair<T, T>> r; for (pair<T, T> p : V) { int s = r.size(); while (s >= 2 && (p.second - r[s - 1].second) * (p.first - r[s - 2].first) < (p.second - r[s - 2].second) * (p.first - r[s - 1].first)) { r.pop_back(); --s; } r << p; } r.pop_back(); return r; } class UnionFind { vi p, s; void extend(int N) { foor(i, p.size(), N) { p << i; s << 1; } } public: UnionFind(void) {} UnionFind(int N) { extend(N - 1); } int find(int i) { extend(i); return p[i] = p[i] == i ? i : find(p[i]); } void unite(int a, int b) { extend(a); extend(b); if ((a = find(a)) != (b = find(b))) { if (s[a] > s[b]) { swap(a, b); } s[b] += s[a]; p[a] = b; } } void unite(pii p) { return unite(p.first, p.second); } bool same(int a, int b) { extend(a); extend(b); return find(a) == find(b); } bool same(pii p) { return same(p.first, p.second); } int size(int x) { extend(x); return s[find(x)]; } }; ll MST(vector<pair<ll, pii>> &E) { Sort(E); UnionFind uf; ll z = 0; for (auto &e : E) { if (!uf.same(e.second)) { z += e.first; uf.unite(e.second); } } return z; } ll strmod(const str &s, const int m) { ll x = 0; fr(i, s.size()) { x = (x * 10 + s[i] - 48) % m; } return x; } vvl mul(const vvl &A, const vvl &B, const int m) { vvl C; fr(y, A.size()) { C << vl(B[y].size()); } fr(y, C.size()) { fr(x, C[y].size()) { fr(i, A[0].size()) { (C[y][x] += A[y][i] * B[i][x]) %= m; } } } return C; } vvl pow(const vvl &A, const ll n, const int m) { vvl B; fr(y, A.size()) { B << vl(A.size()); } if (n == 0) { fr(i, B.size()) { B[i][i] = 1; } } elsif(n % 2) { B = mul(A, pow(A, n - 1, m), m); } else { vvl C = pow(A, n / 2, m); B = mul(C, C, m); } return B; } ll pow(const ll a, const ll n, const int m) { ll t; return n ? (n & 1 ? a >= 0 ? a % m : (m - (-a % m)) % m : 1) * (t = pow(a, n >> 1, m), t * t % m) % m : !!a; } ll inv(const ll x, const int p) { assert(x != 0); return pow(x, p - 2, p); } ll inv(const ll x) { return inv(x, MD); } vpll fact(const int n, const int p) { assert(n < p); vpll v(n + 1); v[0].first = 1; foor(i, 1, n) { v[i].first = v[i - 1].first * i % p; } v[n].second = inv(v[n].first, p); roof(i, n, 1) { v[i - 1].second = v[i].second * i % p; } return v; } class Combination { const vpll f; const int M; public: Combination(int n, int m) : f(fact(n, m)), M(m) {} Combination(int n) : Combination(n, MD) {} ll P(int n, int k) { return n < 0 || k < 0 || n < k ? 0ll : f[n].first * f[n - k].second % M; } ll C(int n, int k) { return k < 0 ? 0 : P(n, k) * f[k].second % M; } ll H(int n, int k) { return n == 0 && k == 0 ? 1ll : C(n + k - 1, k); } ll F(int n) { return n < 0 ? 0 : f[n].first; } }; ll C2(const int n) { return (ll)n * ~-n / 2; } ll sum(const vi a) { ll s = 0; for (int e : a) { s += e; } return s; } ll sum(const vl a) { ll s = 0; for (ll e : a) { s += e; } return s; } template <typename T> int MSB(T N) { int r = -1; for (; N > 0; N /= 2) { ++r; } return r; } template <typename T> class SegmentTree { vector<T> S; T (*const op)(T a, T b); const T zero; const int B; public: SegmentTree(int N, T (*f)(T a, T b), const T zero) : S(1 << MSB(N - 1) + 2, zero), op(f), zero(zero), B(1 << MSB(N - 1) + 1) {} SegmentTree(vector<T> v, T (*f)(T a, T b), const T zero) : SegmentTree(v.size(), f, zero) { fr(i, v.size()) { S[S.size() / 2 + i] = v[i]; } roof(i, S.size() / 2 - 1, 1) { S[i] = op(S[i * 2], S[i * 2 + 1]); } } T calc(int l, int r) { l += B; r += B; if (l > r) { return zero; } if (l == r) { return S[l]; } T L = S[l], R = S[r]; for (; l / 2 < r / 2; l /= 2, r /= 2) { if (l % 2 == 0) { L = op(L, S[l + 1]); } if (r % 2 == 1) { R = op(S[r - 1], R); } } return op(L, R); } void replace(int i, T x) { for (S[i += B] = x; i != 1; i /= 2) { if (i % 2) { S[i / 2] = op(S[i - 1], S[i]); } else { S[i / 2] = op(S[i], S[i + 1]); } } } void add(int i, T x) { replace(i, op(S[B + i], x)); } T top() { return S[1]; } T get(int i) { return S[i + B]; } }; ll BITsum(vl &B, int i) { ll z = 0; while (i > 0) { z += B[i]; i -= i & -i; } return z; } void BITadd(vl &B, int i, ll x) { while (i < B.size()) { B[i] += x; i += i & -i; } } ll fib(const ll n, const int m) { ll a, b, c, d, A, B, C, D; a = 1; b = 0; c = 0; d = 1; rf(i, 63) { A = a * a + b * c; B = a * b + b * d; C = c * a + d * c; D = c * b + d * d; if (n >> i & 1) { a = A; b = B; c = C; d = D; A = a + b; B = a; C = c + d; D = c; } a = A % m; b = B % m; c = C % m; d = D % m; } return b; } vi primes(int n) { vb b(n + 1); vi p; foor(i, 2, n) { if (!b[i]) { p << i; for (int j = 2 * i; j <= n; j += i) { b[j] = true; } } } return p; } vb isprime(const int n) { vb v(n + 1, true); v[0] = v[1] = false; foor(i, 2, n) { if (v[i]) { for (int j = 2 * i; j <= n; j += i) { v[j] = false; } } } return v; } class LCA { vvi par; vi dep; public: LCA(vvi &E, int root) : par(MSB(E.size()) + 1, vi(E.size())), dep(E.size()) { function<void(int, int)> dfs = [&](int i, int p) { for (int j : E[i]) if (j != p) { par[0][j] = i; dep[j] = dep[i] + 1; dfs(j, i); } }; par[0][root] = root; dfs(root, root); fr(i, par.size() - 1) { fr(j, par[0].size()) { par[i + 1][j] = par[i][par[i][j]]; } } } int operator()(int a, int b) { if (dep[a] > dep[b]) swap(a, b); for (int t = dep[b] - dep[a], i = 0; t; t >>= 1, ++i) { if (t & 1) { b = par[i][b]; } } if (a == b) return a; rf(i, par.size()) { if (par[i][a] != par[i][b]) { a = par[i][a]; b = par[i][b]; } } return par[0][a]; } }; vpli factor(ll N) { vpli r; for (ll i = 2; i * i <= N; ++i) { if (N % i == 0) { r << pli{i, 0}; while (N % i == 0) { N /= i; ++r.back().second; } } } if (N > 1) { r << pli{N, 1}; } return r; } vl divisors(ll n) { vl r; ll m = sqrt(n); foor(i, 1, m) if (n % i == 0) r << ll(i); rf(i, r.size() - (m * m == n)) r << n / r[i]; return r; } vi SuffixArray(str S) { int N = S.size(); vi rank(N + 1), tmp(N + 1), sa(N + 1); fr(i, N) { sa[i] = i; rank[i] = S[i]; } sa[N] = N; rank[N] = -1; int k; auto cmp = [&](int &a, int &b) -> bool { if (rank[a] != rank[b]) return rank[a] < rank[b]; return (a + k <= N ? rank[a + k] : -1) < (b + k <= N ? rank[b + k] : -1); }; for (k = 1; k <= N; k *= 2) { sort(all(sa), cmp); tmp[sa[0]] = 0; foor(i, 1, N) { tmp[sa[i]] = tmp[sa[i - 1]] + cmp(sa[i - 1], sa[i]); } rank = tmp; } return sa; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int r = 0, g = 0, b = 0; ll z = 1; fr(i, N) { int A; cin >> A; if (r == A) { z *= (r == A) + (g == A) + (b == A); ++r; } elsif(g == A) { z *= (r == A) + (g == A) + (b == A); ++g; } elsif(b == A) { z *= (r == A) + (g == A) + (b == A); ++b; } else { z = 0; } z %= MD; } print(z); return 0; }
replace
701
702
701
702
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define eb emplace_back #define mp make_pair using namespace std; multiset<int> s; int n, x; ll ans = 1; const int mod = 1e9 + 7; int main() { cin >> n; s.insert(0), s.insert(0), s.insert(0); for (int i = 0; i < n; i++) { cin >> x; (ans *= s.count(x)) %= mod; s.erase(s.find(x)); s.insert(x + 1); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define eb emplace_back #define mp make_pair using namespace std; multiset<int> s; int n, x; ll ans = 1; const int mod = 1e9 + 7; int main() { cin >> n; s.insert(0), s.insert(0), s.insert(0); for (int i = 0; i < n; i++) { cin >> x; (ans *= s.count(x)) %= mod; if (s.count(x)) { s.erase(s.find(x)); s.insert(x + 1); } } cout << ans << endl; return 0; }
replace
17
19
17
21
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vc = vector<char>; using vvc = vector<vc>; using pll = pair<ll, ll>; using stkll = vector<pll>; const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; #define rep(i, n) for (ll i = 0; i < (n); i++) #define debug(x) cerr << #x << ": " << x << endl; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } int main() { ll n; cin >> n; vll v = {-1, -1, -1}; ll ans = 1; rep(i, n) { ll a; cin >> a; a--; ll cnt = upper_bound(v.begin(), v.end(), a) - lower_bound(v.begin(), v.end(), a); ans *= cnt; ans %= MOD; sort(v.begin(), v.end()); *lower_bound(v.begin(), v.end(), a) = a + 1; sort(v.begin(), v.end()); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vc = vector<char>; using vvc = vector<vc>; using pll = pair<ll, ll>; using stkll = vector<pll>; const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; #define rep(i, n) for (ll i = 0; i < (n); i++) #define debug(x) cerr << #x << ": " << x << endl; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } int main() { ll n; cin >> n; vll v = {-1, -1, -1}; ll ans = 1; rep(i, n) { ll a; cin >> a; a--; ll cnt = upper_bound(v.begin(), v.end(), a) - lower_bound(v.begin(), v.end(), a); ans *= cnt; ans %= MOD; sort(v.begin(), v.end()); if (lower_bound(v.begin(), v.end(), a) == v.end()) { cout << 0 << endl; return 0; } *lower_bound(v.begin(), v.end(), a) = a + 1; sort(v.begin(), v.end()); } cout << ans << endl; }
insert
36
36
36
40
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> /* #include <atcoder/all> */ #include <iostream> using namespace std; /* using namespace atcoder; */ using pint = pair<int, int>; using ll = long long; using ull = unsigned long long; using vll = vector<long long>; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite) #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back #define vint vector<int> constexpr ll INF = 1e15 + 7LL; constexpr ll MOD = 1e9 + 7LL; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (int i = 0; i < v.size(); ++i) { is >> v[i]; } return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { if (v.size() == 0) return os; for (int i = 0; i < v.size() - 1; ++i) { os << v[i] << " "; } os << v[v.size() - 1]; return os; } void solve() { int n; cin >> n; vint a(n); cin >> a; vint cnts(3, 0); ll ans = 1; REP(i, n) { int now = a[i], cnt = 0, add_j; REP(j, 3) { if (cnts[j] == now) { ++cnt; add_j = j; } } ans = (ans * cnt) % MOD; cnts[add_j]++; } cout << ans << endl; } int main() { solve(); char tmp; while (cin >> tmp) { cin.putback(tmp); solve(); } }
#include <bits/stdc++.h> /* #include <atcoder/all> */ #include <iostream> using namespace std; /* using namespace atcoder; */ using pint = pair<int, int>; using ll = long long; using ull = unsigned long long; using vll = vector<long long>; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite) #define FI first #define SE second #define ALL(v) v.begin(), v.end() #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back #define vint vector<int> constexpr ll INF = 1e15 + 7LL; constexpr ll MOD = 1e9 + 7LL; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (int i = 0; i < v.size(); ++i) { is >> v[i]; } return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { if (v.size() == 0) return os; for (int i = 0; i < v.size() - 1; ++i) { os << v[i] << " "; } os << v[v.size() - 1]; return os; } void solve() { int n; cin >> n; vint a(n); cin >> a; vint cnts(3, 0); ll ans = 1; REP(i, n) { int now = a[i], cnt = 0, add_j = 0; REP(j, 3) { if (cnts[j] == now) { ++cnt; add_j = j; } } ans = (ans * cnt) % MOD; cnts[add_j]++; } cout << ans << endl; } int main() { solve(); char tmp; while (cin >> tmp) { cin.putback(tmp); solve(); } }
replace
52
53
52
53
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> VI; 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 _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define all(x) (x).begin(), (x).end() template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; const int mod = 1e9 + 7; using modint = ModInt<mod>; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) { cin >> a[i]; } modint ans = 1; vector<int> boxes(3, 0); rep(i, n) { int idx = -1; int ctr = 0; rep(j, 3) { if (boxes[j] == a[i]) { ctr++; idx = j; } } ans *= ctr; boxes[idx]++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> VI; 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 _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define all(x) (x).begin(), (x).end() template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; const int mod = 1e9 + 7; using modint = ModInt<mod>; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) { cin >> a[i]; } modint ans = 1; vector<int> boxes(3, 0); rep(i, n) { int idx = 0; int ctr = 0; rep(j, 3) { if (boxes[j] == a[i]) { ctr++; idx = j; } } ans *= ctr; boxes[idx]++; } cout << ans << endl; }
replace
113
114
113
114
0
p02845
C++
Runtime Error
#include <algorithm> #include <iostream> #include <set> #include <string> #include <unordered_set> #include <vector> using namespace std; #define MOD (int)(1e9 + 7) int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector<int> B(3); long long ans = 1; for (int i = 0; i < N; i++) { int index = -1; int cnt = 0; for (int j = 0; j < 3; j++) { if (B[j] == A[i]) { cnt++; index = j; } } ans *= cnt; ans %= MOD; B[index]++; } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <set> #include <string> #include <unordered_set> #include <vector> using namespace std; #define MOD (int)(1e9 + 7) int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector<int> B(3); long long ans = 1; for (int i = 0; i < N; i++) { int index = -1; int cnt = 0; for (int j = 0; j < 3; j++) { if (B[j] == A[i]) { cnt++; index = j; } } ans *= cnt; ans %= MOD; if (index == -1) break; B[index]++; } cout << ans << endl; return 0; }
insert
33
33
33
36
0
p02845
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <tuple> #include <vector> using namespace std; #define rep(i, n) for (int64_t i = 0; i < (n); i++) #define irep(i, n) for (int64_t i = 0; i <= (n); i++) #define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--) #define rirep(i, n) for (int64_t i = n; i >= 0; i--) const int64_t MOD = 1e9 + 7; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) { cin >> a[i]; } vector<int> cnt(3, 0); int64_t result = 1; rep(i, n) { result *= upper_bound(cnt.begin(), cnt.end(), a[i]) - lower_bound(cnt.begin(), cnt.end(), a[i]); result %= MOD; *(upper_bound(cnt.begin(), cnt.end(), a[i]) - 1) += 1; } cout << result << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <tuple> #include <vector> using namespace std; #define rep(i, n) for (int64_t i = 0; i < (n); i++) #define irep(i, n) for (int64_t i = 0; i <= (n); i++) #define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--) #define rirep(i, n) for (int64_t i = n; i >= 0; i--) const int64_t MOD = 1e9 + 7; int main() { int n; cin >> n; vector<int> a(n); rep(i, n) { cin >> a[i]; } vector<int> cnt(3, 0); int64_t result = 1; rep(i, n) { int k = upper_bound(cnt.begin(), cnt.end(), a[i]) - lower_bound(cnt.begin(), cnt.end(), a[i]); if (k == 0) { cout << 0 << endl; return 0; } result *= k; result %= MOD; *(upper_bound(cnt.begin(), cnt.end(), a[i]) - 1) += 1; } cout << result << endl; return 0; }
replace
30
32
30
37
0
p02845
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> using namespace std; #define LL long long #define LD long double multiset<int> s; const int mod = 1e9 + 7; int n, a[100005]; LL ans = 1; int main() { scanf("%d", &n); for (int i = 1; i <= 3; i++) s.insert(0); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); ans = ans * s.count(a[i]) % mod; s.erase(s.find(a[i])); s.insert(a[i] + 1); } cout << ans << endl; return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> using namespace std; #define LL long long #define LD long double multiset<int> s; const int mod = 1e9 + 7; int n, a[100005]; LL ans = 1; int main() { scanf("%d", &n); for (int i = 1; i <= 3; i++) s.insert(0); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); ans = ans * s.count(a[i]) % mod; if (s.find(a[i]) != s.end()) { s.erase(s.find(a[i])); s.insert(a[i] + 1); } } cout << ans << endl; return 0; }
replace
21
23
21
25
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll MOD = 1000000007; ll INFL = 1ll << 60; ll INF = 1 << 28; template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { cout << "{"; for (int i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); cout << "}"; return os; } // ==================================================================== int main() { ll n; cin >> n; if (n <= 2) return -1; vector<ll> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } vector<ll> dp(n); // n人目まで考えた時… vector<ll> mae(100010); // 前にi人いるよって言った人の数 dp[0] = 1; for (int i = 0; i < n; i++) { if (0 < i) dp[i] = dp[i - 1]; if (v[i] == 0) { dp[i] = dp[i] * (3 - mae[0]) % MOD; } else { dp[i] = dp[i] * (mae[v[i] - 1] - mae[v[i]]) % MOD; } mae[v[i]]++; } cout << dp[n - 1] % MOD << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll MOD = 1000000007; ll INFL = 1ll << 60; ll INF = 1 << 28; template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { cout << "{"; for (int i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : " "); cout << "}"; return os; } // ==================================================================== int main() { ll n; cin >> n; vector<ll> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } vector<ll> dp(n); // n人目まで考えた時… vector<ll> mae(100010); // 前にi人いるよって言った人の数 dp[0] = 1; for (int i = 0; i < n; i++) { if (0 < i) dp[i] = dp[i - 1]; if (v[i] == 0) { dp[i] = dp[i] * (3 - mae[0]) % MOD; } else { dp[i] = dp[i] * (mae[v[i] - 1] - mae[v[i]]) % MOD; } mae[v[i]]++; } cout << dp[n - 1] % MOD << endl; }
delete
20
22
20
20
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; constexpr ll INF = 9e18; constexpr int inf = 1e9; const double INFD = 1e100; const ll mod = 1000000007; const double PI = 3.1415926535897932384626433832795028841971; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }; // intやllをstringに変換 template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; // ---------------------------------------------------------------------------- int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } ll ans = 1; vector<int> num(3, -1); for (int i = 0; i < N; i++) { ll cnt = 0; for (int j = 0; j < 3; j++) { if (A[i] - 1 == num[j]) { cnt++; } } for (int j = 0; j < N; j++) { if (A[i] - 1 == num[j]) { num[j]++; break; } } ans *= cnt; ans %= mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; constexpr ll INF = 9e18; constexpr int inf = 1e9; const double INFD = 1e100; const ll mod = 1000000007; const double PI = 3.1415926535897932384626433832795028841971; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }; // intやllをstringに変換 template <typename T> inline string toString(const T &a) { ostringstream oss; oss << a; return oss.str(); }; // ---------------------------------------------------------------------------- int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } ll ans = 1; vector<int> num(3, -1); for (int i = 0; i < N; i++) { ll cnt = 0; for (int j = 0; j < 3; j++) { if (A[i] - 1 == num[j]) { cnt++; } } for (int j = 0; j < 3; j++) { if (A[i] - 1 == num[j]) { num[j]++; break; } } ans *= cnt; ans %= mod; } cout << ans << endl; return 0; }
replace
50
51
50
51
0
p02845
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; const int MOD = 1e9 + 7; int main() { long long N; cin >> N; vector<long long> A(N); for (int i = 0; i < N; i++) cin >> A[i]; long long ans = 1; vector<long long> v(3, 0); for (int i = 0; i < N; i++) { long long cnt = 0; int flag = -1; for (int j = 0; j < 3; j++) { if (A[i] == v[j]) { cnt++; flag = j; } } ans = ans * cnt % MOD; v[flag]++; } cout << ans << endl; }
#include <iostream> #include <vector> using namespace std; const int MOD = 1e9 + 7; int main() { long long N; cin >> N; vector<long long> A(N); for (int i = 0; i < N; i++) cin >> A[i]; long long ans = 1; vector<long long> v(3, 0); for (int i = 0; i < N; i++) { long long cnt = 0; int flag = 0; for (int j = 0; j < 3; j++) { if (A[i] == v[j]) { cnt++; flag = j; } } ans = ans * cnt % MOD; v[flag]++; } cout << ans << endl; }
replace
14
15
14
15
0
p02845
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define all(i, n) (i), (i + n) int dx4[4] = {1, 0, -1, 0}; int dy4[4] = {0, -1, 0, 1}; int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1}; int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1}; int dx9[9] = {0, 1, 0, -1, 1, -1, 1, 0, -1}; int dy9[9] = {0, 1, 1, 1, 0, 0, -1, -1, -1}; typedef pair<int, int> P; typedef pair<string, int> SP; typedef long long ll; typedef pair<ll, ll> PLL; const int INF = 1e9; const ll LLINF = 1e18; const int MAX_V = 1e6 + 1; const ll mod = 1000000007; // << fixed << setprecision // -------------------------------------- int n; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; ll ans = 1; int c[3]; REP(i, 3) c[i] = 0; REP(i, n) { int a; cin >> a; int t = 0, p; REP(j, 3) if (c[j] == a) { t++; p = j; } ans = (ans * t) % mod; c[p]++; } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define all(i, n) (i), (i + n) int dx4[4] = {1, 0, -1, 0}; int dy4[4] = {0, -1, 0, 1}; int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1}; int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1}; int dx9[9] = {0, 1, 0, -1, 1, -1, 1, 0, -1}; int dy9[9] = {0, 1, 1, 1, 0, 0, -1, -1, -1}; typedef pair<int, int> P; typedef pair<string, int> SP; typedef long long ll; typedef pair<ll, ll> PLL; const int INF = 1e9; const ll LLINF = 1e18; const int MAX_V = 1e6 + 1; const ll mod = 1000000007; // << fixed << setprecision // -------------------------------------- int n; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; ll ans = 1; int c[3]; REP(i, 3) c[i] = 0; REP(i, n) { int a; cin >> a; int t = 0, p = 0; REP(j, 3) if (c[j] == a) { t++; p = j; } ans = (ans * t) % mod; c[p]++; } cout << ans << endl; }
replace
51
52
51
52
0
p02845
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { int l; cin >> l; a[i] = l + 1; } long long m = 1000000007; int b[n]; for (int i = 0; i < n + 1; i++) b[i] = 0; long long dp[100010]; dp[0] = 1; b[0] = 3; for (int i = 1; i < n + 1; i++) { dp[i] = (dp[i - 1] * b[a[i] - 1]) % m; b[i]++; b[i - 1]--; } cout << dp[n] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { int l; cin >> l; a[i] = l + 1; } long long m = 1000000007; int b[n]; for (int i = 0; i < n + 1; i++) b[i] = 0; long long dp[100010]; dp[0] = 1; b[0] = 3; for (int i = 1; i < n + 1; i++) { dp[i] = (dp[i - 1] * b[a[i - 1] - 1]) % m; b[a[i - 1]]++; b[a[i - 1] - 1]--; } cout << dp[n] << endl; }
replace
20
23
20
23
-11
p02845
C++
Runtime Error
#include <bits/stdc++.h> #define INF 1e9 #define MOD 1000000007 using namespace std; #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(a) (a).begin(), (a).end() template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } typedef long long ll; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { ll N; cin >> N; vector<ll> A(N, 0); REP(i, N) cin >> A[i]; vector<int> cnt(3, 0); ll ans = 1; REP(i, N) { int p = 0, idx; REP(j, 3) { if (cnt[j] == A[i]) { p++; idx = j; } } ans *= p; ans %= (ll(1e9) + 7); cnt[idx]++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define INF 1e9 #define MOD 1000000007 using namespace std; #define REPR(i, n) for (int i = (n); i >= 0; --i) #define FOR(i, m, n) for (int i = (m); i < (n); ++i) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(a) (a).begin(), (a).end() template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } typedef long long ll; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { ll N; cin >> N; vector<ll> A(N, 0); REP(i, N) cin >> A[i]; vector<int> cnt(3, 0); if (A[0] != 0) { cout << 0 << endl; return 0; } ll ans = 1; REP(i, N) { int p = 0, idx; REP(j, 3) { if (cnt[j] == A[i]) { p++; idx = j; } } ans *= p; ans %= (ll(1e9) + 7); cnt[idx]++; } cout << ans << endl; return 0; }
insert
39
39
39
43
0
p02845
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define RREP(i, a) for (int(i) = (a)-1; (i) >= 0; (i)--) #define FORR(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--) #define DEBUG(C) cerr << #C << " = " << C << endl; using LL = long long; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<LL>; using VVL = vector<VL>; using VD = vector<double>; using VVD = vector<VD>; using PII = pair<int, int>; using PDD = pair<double, double>; using PLL = pair<LL, LL>; using VPII = vector<PII>; template <typename T> using VT = vector<T>; #define ALL(a) begin((a)), end((a)) #define RALL(a) rbegin((a)), rend((a)) #define SORT(a) sort(ALL((a))) #define RSORT(a) sort(RALL((a))) #define REVERSE(a) reverse(ALL((a))) #define MP make_pair #define FORE(a, b) for (auto &&a : (b)) #define EB emplace_back #define GREATER(T) T, VT<T> greater<T> template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; const int MAX = 1e5 + 10; int N; int A[MAX]; int main(void) { cin >> N; REP(i, N) { cin >> A[i]; } LL ans = 1; int cnt[3] = {-1, -1, -1}; REP(i, N) { VI cand; REP(j, 3) { if (cnt[j] + 1 == A[i]) { cand.EB(j); } } if (cnt[cand[0]] >= 0) { (ans *= (cand.size() + (cand.size() + 1)) / 2) %= MOD; } cnt[cand[0]]++; } int exists_cnt = 0; REP(i, 3) if (cnt[i] >= 0) { exists_cnt++; } (ans *= (exists_cnt == 1 ? 3 : 6)) %= MOD; cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define RREP(i, a) for (int(i) = (a)-1; (i) >= 0; (i)--) #define FORR(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--) #define DEBUG(C) cerr << #C << " = " << C << endl; using LL = long long; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<LL>; using VVL = vector<VL>; using VD = vector<double>; using VVD = vector<VD>; using PII = pair<int, int>; using PDD = pair<double, double>; using PLL = pair<LL, LL>; using VPII = vector<PII>; template <typename T> using VT = vector<T>; #define ALL(a) begin((a)), end((a)) #define RALL(a) rbegin((a)), rend((a)) #define SORT(a) sort(ALL((a))) #define RSORT(a) sort(RALL((a))) #define REVERSE(a) reverse(ALL((a))) #define MP make_pair #define FORE(a, b) for (auto &&a : (b)) #define EB emplace_back #define GREATER(T) T, VT<T> greater<T> template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; const int MAX = 1e5 + 10; int N; int A[MAX]; int main(void) { cin >> N; REP(i, N) { cin >> A[i]; } LL ans = 1; int cnt[3] = {-1, -1, -1}; REP(i, N) { VI cand; REP(j, 3) { if (cnt[j] + 1 == A[i]) { cand.EB(j); } } if (cand.size() == 0) { cout << 0 << endl; return 0; } if (cnt[cand[0]] >= 0) { (ans *= (cand.size() + (cand.size() + 1)) / 2) %= MOD; } cnt[cand[0]]++; } int exists_cnt = 0; REP(i, 3) if (cnt[i] >= 0) { exists_cnt++; } (ans *= (exists_cnt == 1 ? 3 : 6)) %= MOD; cout << ans << endl; }
insert
93
93
93
98
0
p02845
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; typedef long long ll; const ll MOD = 1000000007; int main() { int n; cin >> n; ll ret = 1; vector<int> v(3, -1); for (int i = 0; i < n; i++) { int a; cin >> a; int idx = -1; int count = 0; for (int j = 0; j < 3; j++) { if (v[j] == a - 1) { idx = j; count++; } } v[idx] = a; ret *= count; ret %= MOD; } cout << ret << endl; return 0; }
#include <iostream> #include <vector> using namespace std; typedef long long ll; const ll MOD = 1000000007; int main() { int n; cin >> n; ll ret = 1; vector<int> v(3, -1); for (int i = 0; i < n; i++) { int a; cin >> a; int idx = -1; int count = 0; for (int j = 0; j < 3; j++) { if (v[j] == a - 1) { idx = j; count++; } } if (idx < 0) { cout << 0 << endl; return 0; } v[idx] = a; ret *= count; ret %= MOD; } cout << ret << endl; return 0; }
insert
26
26
26
30
0
p02845
C++
Runtime Error
#include <algorithm> #include <chrono> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define forr(i, start, count) for (int i = (start); i < (start) + (count); ++i) #define set_map_includes(set, elt) (set.find((elt)) != set.end()) #define readint(i) \ int i; \ cin >> i #define readll(i) \ ll i; \ cin >> i #define readdouble(i) \ double i; \ cin >> i #define readstring(s) \ string s; \ cin >> s typedef long long ll; using namespace std; ll modd = 1000 * 1000 * 1000 + 7; template <class T> T fastpower(T a, long long n) { // n must be >= 1 if (n % 2 == 0) { T halfpower = fastpower<T>(a, n / 2); return (halfpower * halfpower) % modd; } else { if (n == 1) { return a; } else { T halfpower = fastpower<T>(a, n / 2); return (((halfpower * halfpower) % modd) * a) % modd; } } }; int main() { ios_base::sync_with_stdio(false); cout.precision(17); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int> rand_gen( 0, 1000); // rand_gen(rng) gets the rand no // auto start = chrono::steady_clock::now(); // readint(test_cases); int test_cases = 1; forr(t, 1, test_cases) { readint(n); vector<ll> x; forr(i, 0, n) { readll(xx); x.push_back(xx); } multiset<int> last; ll ret = 1; forr(i, 0, n) { if (x[i] == 0) { ret *= (3 - last.size()); last.insert(0); } else { int ct = last.count(x[i] - 1); ret *= ct; ret = ret % modd; last.erase(last.find(x[i] - 1)); last.insert(x[i]); } } cout << ret << endl; } // auto end = chrono::steady_clock::now(); // cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() // << endl; return 0; }
#include <algorithm> #include <chrono> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define forr(i, start, count) for (int i = (start); i < (start) + (count); ++i) #define set_map_includes(set, elt) (set.find((elt)) != set.end()) #define readint(i) \ int i; \ cin >> i #define readll(i) \ ll i; \ cin >> i #define readdouble(i) \ double i; \ cin >> i #define readstring(s) \ string s; \ cin >> s typedef long long ll; using namespace std; ll modd = 1000 * 1000 * 1000 + 7; template <class T> T fastpower(T a, long long n) { // n must be >= 1 if (n % 2 == 0) { T halfpower = fastpower<T>(a, n / 2); return (halfpower * halfpower) % modd; } else { if (n == 1) { return a; } else { T halfpower = fastpower<T>(a, n / 2); return (((halfpower * halfpower) % modd) * a) % modd; } } }; int main() { ios_base::sync_with_stdio(false); cout.precision(17); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int> rand_gen( 0, 1000); // rand_gen(rng) gets the rand no // auto start = chrono::steady_clock::now(); // readint(test_cases); int test_cases = 1; forr(t, 1, test_cases) { readint(n); vector<ll> x; forr(i, 0, n) { readll(xx); x.push_back(xx); } multiset<int> last; ll ret = 1; forr(i, 0, n) { if (x[i] == 0) { ret *= (3 - last.size()); last.insert(0); } else { int ct = last.count(x[i] - 1); ret *= ct; ret = ret % modd; if (ct == 0) { break; } last.erase(last.find(x[i] - 1)); last.insert(x[i]); } } cout << ret << endl; } // auto end = chrono::steady_clock::now(); // cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() // << endl; return 0; }
insert
87
87
87
90
0
p02845
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i)) #define rep(i, n) FOR(i, 0, n) #define all(v) begin(v), end(v) #define debug(x) std::cerr << #x << ": " << x << "\n" #define debug2(x, y) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\n" #define debug3(x, y, z) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z \ << ": " << z << "\n" using ll = long long; using vi = std::vector<int>; using vvi = std::vector<vi>; using vll = std::vector<ll>; using vvll = std::vector<vll>; template <typename T> using vvec = std::vector<std::vector<T>>; template <typename T> auto make_v(size_t sz) { return std::vector<T>(sz); } template <typename T, typename... Ts> auto make_v(size_t sz, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(sz, make_v<T>(ts...)); } template <typename T> void fill_v(T &var, const T &x) { var = x; } template <typename V, typename T> void fill_v(V &v, const T &x) { for (auto &&w : v) { fill_v(w, x); } } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<std::vector<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<std::deque<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::set<T> &v) { s << "\n"; for (auto &&elm : v) { s << elm << "\t"; } s << "\n"; return s; } inline void scan(int &a) { scanf("%d", &a); } inline void scan(ll &a) { scanf("%lld", &a); } inline void scan(char &a) { scanf(" %c", &a); } inline void scan(double &a) { scanf("%lf", &a); } inline void scan(std::string &s) { char BUF[3000000]; scanf(" %s", BUF); s = std::string(BUF); } template <typename T> inline void scan(std::vector<T> &v) { for (auto &&sv : v) { scan(sv); } } template <typename First, typename... Args> inline void scan(First &f, Args &...args) { scan(f); scan(args...); } inline void print(int a) { printf("%d\n", a); } inline void print(ll a) { printf("%lld\n", a); } inline void print(double a) { printf("%.12f\n", a); } inline void print(std::string s) { std::cout << s << "\n"; } using namespace std; int mod = 1000000007; int main() { int n; scan(n); vi a(n); scan(a); vi sep(3, 0); ll ans = 1; rep(i, n) { int last = -1; int cnt = 0; rep(j, 3) { if (sep[j] == a[i]) { last = j; cnt += 1; } } ans = ans * cnt % mod; sep[last] += 1; } print(ans); return 0; }
#include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i)) #define rep(i, n) FOR(i, 0, n) #define all(v) begin(v), end(v) #define debug(x) std::cerr << #x << ": " << x << "\n" #define debug2(x, y) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\n" #define debug3(x, y, z) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z \ << ": " << z << "\n" using ll = long long; using vi = std::vector<int>; using vvi = std::vector<vi>; using vll = std::vector<ll>; using vvll = std::vector<vll>; template <typename T> using vvec = std::vector<std::vector<T>>; template <typename T> auto make_v(size_t sz) { return std::vector<T>(sz); } template <typename T, typename... Ts> auto make_v(size_t sz, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(sz, make_v<T>(ts...)); } template <typename T> void fill_v(T &var, const T &x) { var = x; } template <typename V, typename T> void fill_v(V &v, const T &x) { for (auto &&w : v) { fill_v(w, x); } } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<std::vector<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<std::deque<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::set<T> &v) { s << "\n"; for (auto &&elm : v) { s << elm << "\t"; } s << "\n"; return s; } inline void scan(int &a) { scanf("%d", &a); } inline void scan(ll &a) { scanf("%lld", &a); } inline void scan(char &a) { scanf(" %c", &a); } inline void scan(double &a) { scanf("%lf", &a); } inline void scan(std::string &s) { char BUF[3000000]; scanf(" %s", BUF); s = std::string(BUF); } template <typename T> inline void scan(std::vector<T> &v) { for (auto &&sv : v) { scan(sv); } } template <typename First, typename... Args> inline void scan(First &f, Args &...args) { scan(f); scan(args...); } inline void print(int a) { printf("%d\n", a); } inline void print(ll a) { printf("%lld\n", a); } inline void print(double a) { printf("%.12f\n", a); } inline void print(std::string s) { std::cout << s << "\n"; } using namespace std; int mod = 1000000007; int main() { int n; scan(n); vi a(n); scan(a); vi sep(3, 0); ll ans = 1; rep(i, n) { int last = -1; int cnt = 0; rep(j, 3) { if (sep[j] == a[i]) { last = j; cnt += 1; } } ans = ans * cnt % mod; if (last == -1) { assert(cnt == 0 && ans == 0); print(0); return 0; } sep[last] += 1; } print(ans); return 0; }
insert
146
146
146
151
0
p02846
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #define _USE_MATH_DEFINES #include <functional> #include <math.h> using namespace std; #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) typedef long long ll; const ll INF = 1e17; const ll MOD = 1000000007; const ll MAX = 1000000; ll max(ll a, ll b) { if (a > b) { return a; } return b; } ll min(ll a, ll b) { if (a > b) { return b; } return a; } /////////////////////////// ll ans(ll T1, ll T2, ll A1, ll A2, ll B1, ll B2) { ll x = T1 * (A1 - B1) + T2 * (A2 - B2); if (x == 0) { return INF; } if (x < 0) { return ans(T2, T1, A2, A1, B2, B1); } if (A1 > B1) { return 0; } ll y = T1 * (B1 - A1); if (y % x == 0) { return 2 * (y / x); } return 2 * (y / x) + 1; } int main() { ll T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; ll a = ans(T1, T2, A1, A2, B1, B2); if (a == INF) { cout << "infinity"; } else { cout << a; } system("PAUSE"); }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #define _USE_MATH_DEFINES #include <functional> #include <math.h> using namespace std; #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) typedef long long ll; const ll INF = 1e17; const ll MOD = 1000000007; const ll MAX = 1000000; ll max(ll a, ll b) { if (a > b) { return a; } return b; } ll min(ll a, ll b) { if (a > b) { return b; } return a; } /////////////////////////// ll ans(ll T1, ll T2, ll A1, ll A2, ll B1, ll B2) { ll x = T1 * (A1 - B1) + T2 * (A2 - B2); if (x == 0) { return INF; } if (x < 0) { return ans(T1, T2, B1, B2, A1, A2); } if (A1 > B1) { return 0; } ll y = T1 * (B1 - A1); if (y % x == 0) { return 2 * (y / x); } return 2 * (y / x) + 1; } int main() { ll T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; ll a = ans(T1, T2, A1, A2, B1, B2); if (a == INF) { cout << "infinity"; } else { cout << a; } system("PAUSE"); }
replace
44
45
44
45
TLE
p02846
C++
Runtime Error
/* これを入れて実行 g++ code.cpp ./a.out */ #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 60; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) { return f.second > s.second; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll conbinationMemo[100][100]; void cmemoInit() { rep(i, 100) { rep(j, 100) { conbinationMemo[i][j] = -1; } } } ll nCr(ll n, ll r) { if (conbinationMemo[n][r] != -1) return conbinationMemo[n][r]; if (r == 0 || r == n) { return 1; } else if (r == 1) { return n; } return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r) { r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- int main(void) { vector<ll> t(2); vector<pair<ll, ll>> ab(2); rep(i, 2) cin >> t[i]; rep(i, 2) cin >> ab[i].first >> ab[i].second; sort(all(ab), greater<pair<ll, ll>>()); ll diff1 = (ab[0].first - ab[1].first) * t[0]; ll diff2 = (ab[0].second - ab[1].second) * t[1]; ll diff3 = (ab[0].second * t[1] + diff1) - ab[1].second * t[1]; if (diff3 == 0) { cout << "infinity" << endl; return 0; } // cout << diff1 << " " << diff2 << " " << diff3 << endl; if (diff3 > 0) { cout << 0 << endl; return 0; } assert(false); }
/* これを入れて実行 g++ code.cpp ./a.out */ #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 60; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) { return f.second > s.second; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll conbinationMemo[100][100]; void cmemoInit() { rep(i, 100) { rep(j, 100) { conbinationMemo[i][j] = -1; } } } ll nCr(ll n, ll r) { if (conbinationMemo[n][r] != -1) return conbinationMemo[n][r]; if (r == 0 || r == n) { return 1; } else if (r == 1) { return n; } return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r) { r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- int main(void) { vector<ll> t(2); vector<pair<ll, ll>> ab(2); rep(i, 2) cin >> t[i]; rep(i, 2) cin >> ab[i].first >> ab[i].second; sort(all(ab), greater<pair<ll, ll>>()); ll diff1 = (ab[0].first - ab[1].first) * t[0]; ll diff2 = (ab[0].second - ab[1].second) * t[1]; ll diff3 = (ab[0].second * t[1] + diff1) - ab[1].second * t[1]; if (diff3 == 0) { cout << "infinity" << endl; return 0; } // cout << diff1 << " " << diff2 << " " << diff3 << endl; if (diff3 > 0) { cout << 0 << endl; return 0; } if (diff1 % diff3 == 0) { cout << abs(diff1 / diff3) * 2 << endl; } else { cout << abs(diff1 / diff3) * 2 + 1 << endl; } }
replace
104
105
104
109
-6
4a75dce1-7224-4568-8687-29e9d1b0858e.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02846/C++/s473071620.cpp:106: int main(): Assertion `false' failed.
p02846
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 - 1; i >= 0; i--) using namespace std; #define INF ((1 << 30) - 1) #define LINF (1LL << 60) #define EPS (1e-10) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MOD2 = 998244353; int main() { ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; ll l = t1 * (b1 - a1); ll d = t2 * (b2 - a2) + l; if (l + d == 0) { cout << "infinity" << endl; return 0; } if ((l > 0 && d > 0) || (l < 0 && d < 0)) { cout << 0 << endl; return 0; } l = abs(l); d = abs(d); if (l % d != 0) cout << 2 * (l / d) + 1 << endl; else cout << 2 * (l / d) << 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 - 1; i >= 0; i--) using namespace std; #define INF ((1 << 30) - 1) #define LINF (1LL << 60) #define EPS (1e-10) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MOD2 = 998244353; int main() { ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; ll l = t1 * (b1 - a1); ll d = t2 * (b2 - a2) + l; if (d == 0) { cout << "infinity" << endl; return 0; } if ((l > 0 && d > 0) || (l < 0 && d < 0)) { cout << 0 << endl; return 0; } l = abs(l); d = abs(d); if (l % d != 0) cout << 2 * (l / d) + 1 << endl; else cout << 2 * (l / d) << endl; return 0; }
replace
19
20
19
20
0
p02846
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { // cin.tie(0); // ios::sync_with_stdio(false); cout << fixed << setprecision(12); LL T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; LL D1 = A1 - B1, D2 = A2 - B2; if (D1 > 0) { D1 = -D1; D2 = -D2; } LL X = T1 * D1, Y = T2 * D2; if (D2 < 0) { cout << 0 << endl; } else if (X == Y) { cout << "infinity" << endl; } else if (X + Y < 0) { cout << 0 << endl; } else { LL res = (-X) / (X + Y) * 2 + (((-X) % (X + Y) == 0) ? 0 : 1); cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { // cin.tie(0); // ios::sync_with_stdio(false); cout << fixed << setprecision(12); LL T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; LL D1 = A1 - B1, D2 = A2 - B2; if (D1 > 0) { D1 = -D1; D2 = -D2; } LL X = T1 * D1, Y = T2 * D2; if (D2 < 0) { cout << 0 << endl; } else if (-X == Y) { cout << "infinity" << endl; } else if (X + Y < 0) { cout << 0 << endl; } else { LL res = (-X) / (X + Y) * 2 + (((-X) % (X + Y) == 0) ? 0 : 1); cout << res << endl; } return 0; }
replace
22
23
22
23
0
p02846
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define l_ength size const int inf = (1 << 30); const int mod = 1000000007; using ll = long long; using namespace std; int main() { ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; if (a1 < b1) { swap(a1, b1); swap(a2, b2); } // かならず a1 > b1 ll d = (t1 * a1 + t2 * a2) - (t1 * b1 + t2 * b2); if (d == 0) { cout << "infinity" << endl; return 0; } if (d > 0) { cout << 0 << endl; return 0; } d *= (-1); ll a = t1 * a1 - t1 * b1; ll p = (a + d - 1) / d; ll ex = 0; for (ll k = 1; k <= p + 1; ++k) { if (d * k + t1 * b1 == t1 * a1) { ex = 1; break; } } cout << p * 2 - 1 + ex << endl; }
#include <bits/stdc++.h> #define l_ength size const int inf = (1 << 30); const int mod = 1000000007; using ll = long long; using namespace std; int main() { ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; if (a1 < b1) { swap(a1, b1); swap(a2, b2); } // かならず a1 > b1 ll d = (t1 * a1 + t2 * a2) - (t1 * b1 + t2 * b2); if (d == 0) { cout << "infinity" << endl; return 0; } if (d > 0) { cout << 0 << endl; return 0; } d *= (-1); ll a = t1 * a1 - t1 * b1; ll p = (a + d - 1) / d; ll ex = 0; if ((t1 * a1 - t1 * b1) % d == 0) ex = 1; cout << p * 2 - 1 + ex << endl; }
replace
28
34
28
30
TLE
p02846
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using lint = long long; signed main() { lint t1, t2; cin >> t1 >> t2; lint a1, a2, b1, b2; cin >> a1 >> a2 >> b1 >> b2; lint P = (a1 - b1) * t1; lint Q = (a2 - b2) * t2; if (P > 0) P *= -1, Q *= -1; if (P == Q) { cout << "infinity" << endl; return 0; } if (P + Q < 0) { cout << 0 << endl; return 0; } lint ans = 0; lint S = -P / (P + Q), T = -P % (P + Q); if (T == 0) ans = S * 2; else ans = S * 2 + 1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using lint = long long; signed main() { lint t1, t2; cin >> t1 >> t2; lint a1, a2, b1, b2; cin >> a1 >> a2 >> b1 >> b2; lint P = (a1 - b1) * t1; lint Q = (a2 - b2) * t2; if (P > 0) P *= -1, Q *= -1; if (P == -Q) { cout << "infinity" << endl; return 0; } if (P + Q < 0) { cout << 0 << endl; return 0; } lint ans = 0; lint S = -P / (P + Q), T = -P % (P + Q); if (T == 0) ans = S * 2; else ans = S * 2 + 1; cout << ans << endl; }
replace
13
14
13
14
0
p02846
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; if (t1 * a1 + t2 * a2 == t1 * b1 + t1 * b2) { cout << "infinity" << endl; return 0; } ll c1 = a1 - b1; ll c2 = a2 - b2; if (c1 < 0) { c1 *= -1; c2 *= -1; } if (c1 * t1 + c2 * t2 > 0) { cout << 0 << endl; return 0; } ll u = c1 * t1; ll v = c1 * t1 + c2 * t2; if (abs(u) % abs(v) == 0) { cout << abs(u) / abs(v) * 2 << endl; } else { cout << abs(u) / abs(v) * 2 + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2) { cout << "infinity" << endl; return 0; } ll c1 = a1 - b1; ll c2 = a2 - b2; if (c1 < 0) { c1 *= -1; c2 *= -1; } if (c1 * t1 + c2 * t2 > 0) { cout << 0 << endl; return 0; } ll u = c1 * t1; ll v = c1 * t1 + c2 * t2; if (abs(u) % abs(v) == 0) { cout << abs(u) / abs(v) * 2 << endl; } else { cout << abs(u) / abs(v) * 2 + 1 << endl; } }
replace
6
7
6
7
0
p02846
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; ll t1, t2, a1, a2, b1, b2; int main() { cin >> t1 >> t2; cin >> a1 >> a2; cin >> b1 >> b2; if (a1 * t1 + a2 * t2 > b1 * t1 + b2 * t2) swap(a1, b1), swap(a2, b2); a1 *= t1; a2 *= t2; b1 *= t1; b2 *= t2; ll tota = a1 + a2, totb = b1 + b2; // cout<<"tota = "<<tota<<" totb = "<<totb<<'\n'; // cout<<"a1 = "<<a1<<" a2 = "<<a2<<'\n'; // cout<<"b1 = "<<b1<<" b2 = "<<b2<<'\n'; // if() { // cout<<"went here\n"; // cout<<"0"; // return 0; // } if (a1 == a2) { cout << "infinity"; return 0; } if ((a1 - b1) % (totb - tota)) cout << (a1 - b1) / (totb - tota) * 2 + 1 << '\n'; else cout << (a1 - b1) / (totb - tota) * 2 << '\n'; // if() return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; ll t1, t2, a1, a2, b1, b2; int main() { cin >> t1 >> t2; cin >> a1 >> a2; cin >> b1 >> b2; if (a1 * t1 + a2 * t2 > b1 * t1 + b2 * t2) swap(a1, b1), swap(a2, b2); a1 *= t1; a2 *= t2; b1 *= t1; b2 *= t2; ll tota = a1 + a2, totb = b1 + b2; // cout<<"tota = "<<tota<<" totb = "<<totb<<'\n'; // cout<<"a1 = "<<a1<<" a2 = "<<a2<<'\n'; // cout<<"b1 = "<<b1<<" b2 = "<<b2<<'\n'; if (tota < totb && a1 < b1) { // cout<<"went here\n"; cout << "0"; return 0; } if (tota == totb) { cout << "infinity"; return 0; } if ((a1 - b1) % (totb - tota)) cout << (a1 - b1) / (totb - tota) * 2 + 1 << '\n'; else cout << (a1 - b1) / (totb - tota) * 2 << '\n'; // if() return 0; }
replace
18
24
18
24
0
p02846
C++
Runtime Error
#include <algorithm> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stdio.h> #include <string> #include <tuple> #include <vector> using namespace std; #define ll long long int #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 REP(i, n) for (int i = n - 1; i >= 0; i--) #define REPS(i, n) for (int i = n; i > 0; i--) #define FOR(i, a, b) for (int i = a; i < (int)(b); i++) #define ALL(x) (x).begin(), (x).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort(ALL(x)) #define CLR(a) memset((a), 0, sizeof(a)) #define PB push_back #define MP make_pair #define SP << " " << #define chmax(a, b) a = (((a) < (b)) ? (b) : (a)) const int INF = 1001001001; const ll MOD = 1e9 + 7; const ll LINF = 100100100100100100; const double EPS = 1e-10; const double PI = acos(-1.0); typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } class CompareDist { public: bool operator()(PLL n1, PLL n2) { if (n1.first != n2.first) return n1.first < n2.first; else return n1.second < n2.second; } }; __attribute__((constructor)) void initial() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } signed main() { ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; ll fa = t1 * a1, fb = t1 * b1, fd = llabs(fa - fb); cerr << fa SP fb SP fd << endl; ll sa = t2 * a2, sb = t2 * b2, sd = llabs(sa - sb); cerr << sa SP sb SP sd << endl; ll sum_a = fa + sa, sum_b = fb + sb, d = llabs(sum_a - sum_b); ll u = (fa - fb) / fd, v = (sum_a - sum_b) / d; if (u * v > 0) return cout << 0 << endl, 0; else if (d == 0) return cout << "infinity" << endl, 0; // if((fa-fb)*(sum_a-sum_b)<0){ else { cerr << sum_a SP sum_b << endl; cerr << d SP fd << endl; ll tmp = fd / d; ll cnt = 0; if (tmp * d == fd) cnt++; ll ans = 1 + tmp * 2 - cnt; cout << ans << endl; } return 0; }
#include <algorithm> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stdio.h> #include <string> #include <tuple> #include <vector> using namespace std; #define ll long long int #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 REP(i, n) for (int i = n - 1; i >= 0; i--) #define REPS(i, n) for (int i = n; i > 0; i--) #define FOR(i, a, b) for (int i = a; i < (int)(b); i++) #define ALL(x) (x).begin(), (x).end() #define RALL(a) (a).rbegin(), (a).rend() #define SORT(c) sort(ALL(x)) #define CLR(a) memset((a), 0, sizeof(a)) #define PB push_back #define MP make_pair #define SP << " " << #define chmax(a, b) a = (((a) < (b)) ? (b) : (a)) const int INF = 1001001001; const ll MOD = 1e9 + 7; const ll LINF = 100100100100100100; const double EPS = 1e-10; const double PI = acos(-1.0); typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } class CompareDist { public: bool operator()(PLL n1, PLL n2) { if (n1.first != n2.first) return n1.first < n2.first; else return n1.second < n2.second; } }; __attribute__((constructor)) void initial() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } signed main() { ll t1, t2, a1, a2, b1, b2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; ll fa = t1 * a1, fb = t1 * b1, fd = llabs(fa - fb); cerr << fa SP fb SP fd << endl; ll sa = t2 * a2, sb = t2 * b2, sd = llabs(sa - sb); cerr << sa SP sb SP sd << endl; ll sum_a = fa + sa, sum_b = fb + sb, d = llabs(sum_a - sum_b); ll u = (fa - fb) / fd; ll v = 0; if (d != 0) v = (sum_a - sum_b) / d; if (u * v > 0) return cout << 0 << endl, 0; else if (d == 0) return cout << "infinity" << endl, 0; // if((fa-fb)*(sum_a-sum_b)<0){ else { cerr << sum_a SP sum_b << endl; cerr << d SP fd << endl; ll tmp = fd / d; ll cnt = 0; if (tmp * d == fd) cnt++; ll ans = 1 + tmp * 2 - cnt; cout << ans << endl; } return 0; }
replace
72
73
72
76
0
10 12 2 20 8 12 30 20 10 2
p02847
Python
Runtime Error
arr = ["NONE", "SAT", " FRI", "THU", "WED", "TUE", "MON", "SUN"] s = input() print(arr.index(s))
arr = ["NONE", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"] s = input() print(arr.index(s))
replace
0
1
0
1
0
p02847
Python
Runtime Error
s = input() dic = {"SUN": 6, "MON": 5, "WED": 4, "THU": 3, "FRI": 2, "SAT": 1} print(dic[s])
s = input() dic = {"SUN": 7, "MON": 6, "TUE": 5, "WED": 4, "THU": 3, "FRI": 2, "SAT": 1} print(dic[s])
replace
2
3
2
3
0
p02847
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> #include <vector> #define ll long long const int MOD = 1e9 + 7; using namespace std; int main() { map<string, int> mp; mp.insert(make_pair("SUN", 7)); mp.insert(make_pair("MON", 6)); mp.insert(make_pair("TUE", 5)); mp.insert(make_pair("EWD", 4)); mp.insert(make_pair("THU", 3)); mp.insert(make_pair("FRI", 2)); mp.insert(make_pair("SAT", 1)); string s; cin >> s; cout << mp.at(s) << endl; return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> #include <vector> #define ll long long const int MOD = 1e9 + 7; using namespace std; int main() { map<string, int> mp; mp.insert(make_pair("SUN", 7)); mp.insert(make_pair("MON", 6)); mp.insert(make_pair("TUE", 5)); mp.insert(make_pair("WED", 4)); mp.insert(make_pair("THU", 3)); mp.insert(make_pair("FRI", 2)); mp.insert(make_pair("SAT", 1)); string s; cin >> s; cout << mp.at(s) << endl; return 0; }
replace
17
18
17
18
0
p02847
Python
Runtime Error
s = input() week = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] for i in len(s): if s == week[i]: print(7 - i) break
s = input() week = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] for i in range(7): if s == week[i]: print(7 - i) break
replace
2
3
2
3
TypeError: 'int' object is not iterable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02847/Python/s523840245.py", line 3, in <module> for i in len(s): TypeError: 'int' object is not iterable
p02847
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; int main() { string day; string s[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; int daycounter; cin >> day; for (int i = 0; i < sizeof(s); i++) { if (day == s[i]) { daycounter = 7 - i; } } cout << daycounter; return 0; }
#include <cstring> #include <iostream> using namespace std; int main() { string S; cin >> S; if (S == "SUN") cout << "7"; else if (S == "MON") cout << "6"; else if (S == "TUE") cout << "5"; else if (S == "WED") cout << "4"; else if (S == "THU") cout << "3"; else if (S == "FRI") cout << "2"; else cout << "1"; return 0; }
replace
4
14
4
21
-11
p02847
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; map<string, int> week; // 名前→成績 week["SUN"] = 0; week["MON"] = 1; week["TUE"] = 2; week["WEN"] = 3; week["THU"] = 4; week["FRI"] = 5; week["SAT"] = 6; cout << 7 - week.at(S) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; map<string, int> week; // 名前→成績 week["SUN"] = 0; week["MON"] = 1; week["TUE"] = 2; week["WED"] = 3; week["THU"] = 4; week["FRI"] = 5; week["SAT"] = 6; cout << 7 - week.at(S) << endl; }
replace
12
13
12
13
0
p02847
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define dump(...) #endif #define endl "\n" #define ll long long #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, x) for (int i = 0; i < (int)(x); i++) #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define INF (1 << 30) #define LLINF (1LL << 60) #define vi vector<int> #define vvi vector<vector<int>> #define pi pair<int, int> #define ALL(a) (a).begin(), (a).end() #define BIT(n) (1LL << (n)) #define UNIQUE(v) \ v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと constexpr ll MOD = 1e9 + 7; int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z; string S, T; ll ans = 0; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } signed main() { cin >> S; vector<string> week = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; for (int i = 0; i < 7; i++) { if (S == week[i]) { cout << 7 - i << endl; return 1; } } }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define dump(...) #endif #define endl "\n" #define ll long long #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, x) for (int i = 0; i < (int)(x); i++) #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define INF (1 << 30) #define LLINF (1LL << 60) #define vi vector<int> #define vvi vector<vector<int>> #define pi pair<int, int> #define ALL(a) (a).begin(), (a).end() #define BIT(n) (1LL << (n)) #define UNIQUE(v) \ v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと constexpr ll MOD = 1e9 + 7; int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z; string S, T; ll ans = 0; template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } signed main() { cin >> S; vector<string> week = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; for (int i = 0; i < 7; i++) { if (S == week[i]) { cout << 7 - i << endl; return 0; } } }
replace
42
43
42
43
1
p02847
C++
Runtime Error
/*coderanant*/ #include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define f1(i, a, b) for (int i = a; i < b; i++) #define f2(i, a, b) for (int i = a; i >= b; i--) #define endl '\n' #define pb push_back #define gp " " #define ff first #define ss second #define mp make_pair const int mod = 1000000007; ll temp; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("/home/akmittal/Desktop/Competitive Programming/in.txt", "r", stdin); freopen("/home/akmittal/Desktop/Competitive Programming/out.txt", "w", stdout); #endif string s; cin >> s; if (s == "SUN") cout << 7 << endl; else if (s == "SAT") cout << 1 << endl; else if (s == "FRI") cout << 2 << endl; else if (s == "THU") cout << 3 << endl; else if (s == "WED") cout << 4 << endl; else if (s == "TUE") cout << 5 << endl; else if (s == "MON") cout << 6 << endl; return 0; }
/*coderanant*/ #include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define f1(i, a, b) for (int i = a; i < b; i++) #define f2(i, a, b) for (int i = a; i >= b; i--) #define endl '\n' #define pb push_back #define gp " " #define ff first #define ss second #define mp make_pair const int mod = 1000000007; ll temp; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("/home/akmittal/Desktop/Competitive // Programming/in.txt","r",stdin); freopen("/home/akmittal/Desktop/Competitive // Programming/out.txt","w",stdout); #endif string s; cin >> s; if (s == "SUN") cout << 7 << endl; else if (s == "SAT") cout << 1 << endl; else if (s == "FRI") cout << 2 << endl; else if (s == "THU") cout << 3 << endl; else if (s == "WED") cout << 4 << endl; else if (s == "TUE") cout << 5 << endl; else if (s == "MON") cout << 6 << endl; return 0; }
replace
22
27
22
26
0
p02847
C++
Runtime Error
/* @author: sharrad99 */ #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ff first #define ss second #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define all(x) x.begin(), x.end() #define mod 1000000007 int main() { #ifndef ONLINE_JUDGE freopen("C:\\Users\\sharr\\Documents\\Input.txt", "r", stdin); freopen("C:\\Users\\sharr\\Documents\\Output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); map<string, ll> m; m["MON"] = 1; m["TUE"] = 2; m["WED"] = 3; m["THU"] = 4; m["FRI"] = 5; m["SAT"] = 6; m["SUN"] = 7; string s; cin >> s; ll res = m["SUN"] - m[s]; if (!res) { res += 7; } cout << res; }
/* @author: sharrad99 */ #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ff first #define ss second #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define all(x) x.begin(), x.end() #define mod 1000000007 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); map<string, ll> m; m["MON"] = 1; m["TUE"] = 2; m["WED"] = 3; m["THU"] = 4; m["FRI"] = 5; m["SAT"] = 6; m["SUN"] = 7; string s; cin >> s; ll res = m["SUN"] - m[s]; if (!res) { res += 7; } cout << res; }
delete
19
23
19
19
0
p02847
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define fst first #define snd second #define fill(a, c) memset(&a, c, sizeof(a)) #define fore(i, x, y) for (ll i = x; i < y; i++) #define FIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) typedef long long ll; typedef unsigned long long ull; using namespace std; int main() { FIN; #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif string line; cin >> line; if (line == "SUN") cout << 7 << "\n"; else if (line == "MON") cout << 6 << "\n"; else if (line == "TUE") cout << 5 << "\n"; else if (line == "WED") cout << 4 << "\n"; else if (line == "THU") cout << 3 << "\n"; else if (line == "FRI") cout << 2 << "\n"; else if (line == "SAT") cout << 1 << "\n"; return 0; }
#include <bits/stdc++.h> #define pb push_back #define fst first #define snd second #define fill(a, c) memset(&a, c, sizeof(a)) #define fore(i, x, y) for (ll i = x; i < y; i++) #define FIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) typedef long long ll; typedef unsigned long long ull; using namespace std; int main() { FIN; string line; cin >> line; if (line == "SUN") cout << 7 << "\n"; else if (line == "MON") cout << 6 << "\n"; else if (line == "TUE") cout << 5 << "\n"; else if (line == "WED") cout << 4 << "\n"; else if (line == "THU") cout << 3 << "\n"; else if (line == "FRI") cout << 2 << "\n"; else if (line == "SAT") cout << 1 << "\n"; return 0; }
delete
19
22
19
19
0
p02847
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() int main() { string s; cin >> s; string d[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; for (int i = 0; i < sizeof(d); i++) { if (s == d[i]) { cout << 7 - i << endl; } } }
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() int main() { string s; cin >> s; string d[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; for (int i = 0; i < 7; i++) { if (s == d[i]) { cout << 7 - i << endl; } } }
replace
10
11
10
11
-11
p02847
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int main() { vector<string> days = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; unordered_map<string, int> days_map; for (int i = 0; i <= 7; i++) { days_map[days[i]] = i; } string day; cin >> day; cout << 7 - days_map[day] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; int main() { vector<string> days = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; unordered_map<string, int> days_map; for (int i = 0; i < 7; i++) { days_map[days[i]] = i; } string day; cin >> day; cout << 7 - days_map[day] << endl; return 0; }
replace
7
8
7
8
-11
p02847
C++
Runtime Error
#include <bits/stdc++.h> // #include<boost/multiprecision/cpp_int.hpp> #define fl(i, a, n) for (int i = a; i <= n; i++) #define pb push_back #define pob pop_back #define int long long int #define ff first #define ss second #define pi 3.1415926535898 #define vi vector<int> #define mi map<int, int> #define umi unordered_map<int, int> #define endl "\n" #define w(x) \ int x; \ cin >> x; \ while (x--) #define db(x) cout << (#x) << " " << (x) << "\n"; #define ios \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; // using namespace boost::multiprecision; int mod = 1000000007; int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } int lcm(int a, int b) { return (a * b) / gcd(a, b); } void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { ios c_p_c(); // w(t) { map<string, int> mp; mp["SUN"] = 0; mp["MON"] = 1; mp["TUE"] = 2; mp["WED"] = 3; mp["THU"] = 4; mp["FRI"] = 5; mp["SAT"] = 6; string s; cin >> s; fl(i, 0, s.length() - 1) { s[i] = toupper(s[i]); } cout << abs(7 - mp[s]); } return 0; }
#include <bits/stdc++.h> // #include<boost/multiprecision/cpp_int.hpp> #define fl(i, a, n) for (int i = a; i <= n; i++) #define pb push_back #define pob pop_back #define int long long int #define ff first #define ss second #define pi 3.1415926535898 #define vi vector<int> #define mi map<int, int> #define umi unordered_map<int, int> #define endl "\n" #define w(x) \ int x; \ cin >> x; \ while (x--) #define db(x) cout << (#x) << " " << (x) << "\n"; #define ios \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; // using namespace boost::multiprecision; int mod = 1000000007; int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } int lcm(int a, int b) { return (a * b) / gcd(a, b); } void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { ios // c_p_c(); // w(t) { map<string, int> mp; mp["SUN"] = 0; mp["MON"] = 1; mp["TUE"] = 2; mp["WED"] = 3; mp["THU"] = 4; mp["FRI"] = 5; mp["SAT"] = 6; string s; cin >> s; fl(i, 0, s.length() - 1) { s[i] = toupper(s[i]); } cout << abs(7 - mp[s]); } return 0; }
replace
38
39
38
40
-11
p02847
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>; int main() { ios::sync_with_stdio(false); cin.tie(0); string s[] = {"MON", "TUE", "WED", "THU", "FRI", "SAT"}; string t; cin >> t; rep(i, 7) { if (t == s[i]) { cout << 6 - i << endl; return 0; } } cout << 7 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ios::sync_with_stdio(false); cin.tie(0); string s[] = {"MON", "TUE", "WED", "THU", "FRI", "SAT"}; string t; cin >> t; rep(i, 6) { if (t == s[i]) { cout << 6 - i << endl; return 0; } } cout << 7 << endl; }
replace
16
17
16
17
0
p02847
C++
Runtime Error
#include <iostream> using namespace std; int main() { char s[3]; cin >> s; if (s[0] == 'S') { if (s[1] == 'U') cout << "7"; else cout << "1"; } else if (s[0] == 'M') cout << "6"; else if (s[0] == 'T') { if (s[1] == 'U') cout << "5"; else cout << "3"; } else if (s[0] == 'W') cout << "4"; else cout << "2"; return 0; }
#include <iostream> using namespace std; int main() { char s[10]; cin >> s; if (s[0] == 'S') { if (s[1] == 'U') cout << "7"; else cout << "1"; } else if (s[0] == 'M') cout << "6"; else if (s[0] == 'T') { if (s[1] == 'U') cout << "5"; else cout << "3"; } else if (s[0] == 'W') cout << "4"; else cout << "2"; return 0; }
replace
3
4
3
4
0
p02847
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef vector<ll> vl; typedef vector<ld> vd; typedef vector<str> vs; typedef vector<pair<ll, ll>> vpl; typedef vector<vl> vvl; typedef vector<vs> vvs; #define f(i, start, end) for (i = start; i < end; i++) #define trav(v) for (auto &x : v) #define deb(x) cerr << #x << ":" << x << "\n" #define nl cout << "\n" int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(0); ll t = 1; // cin >> t; while (t--) { ll n, i, j, k, a, b, m = 0; str d; cin >> d; k = -1; if (d == "MON") { k = 6; } else if (d == "TUE") { k = 5; } else if (d == "THU") { k = 3; } else if (d == "WED") { k = 4; } else if (d == "FRI") { k = 2; } else if (d == "SAT") { k = 1; } else { k = 7; } cout << k; nl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef vector<ll> vl; typedef vector<ld> vd; typedef vector<str> vs; typedef vector<pair<ll, ll>> vpl; typedef vector<vl> vvl; typedef vector<vs> vvs; #define f(i, start, end) for (i = start; i < end; i++) #define trav(v) for (auto &x : v) #define deb(x) cerr << #x << ":" << x << "\n" #define nl cout << "\n" int main() { ios::sync_with_stdio(0); ll t = 1; // cin >> t; while (t--) { ll n, i, j, k, a, b, m = 0; str d; cin >> d; k = -1; if (d == "MON") { k = 6; } else if (d == "TUE") { k = 5; } else if (d == "THU") { k = 3; } else if (d == "WED") { k = 4; } else if (d == "FRI") { k = 2; } else if (d == "SAT") { k = 1; } else { k = 7; } cout << k; nl; } return 0; }
replace
19
23
19
20
0
p02847
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector<string> week(7); week = {"SAT" "FRI" "THU" "WHD" "TUE" "MON" "SUN"}; for (int i = 0; i < 7; i++) { if (s == week.at(i)) { cout << i + 1 << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector<string> week(7); week = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"}; for (int i = 0; i < 7; i++) { if (s == week.at(i)) { cout << i + 1 << endl; } } }
replace
7
14
7
8
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 1) >= this->size() (which is 1)
p02847
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define vi vector<int> #define vll vector<ll> #define pll pair<ll, ll> #define pii pair<int, int> #define pb push_back #define ppb pop_back #define mp make_pair int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); string str; cin >> str; if (str == "SUN") { cout << 7 << endl; } if (str == "SAT") { cout << 1 << endl; } if (str == "FRI") { cout << 2 << endl; } if (str == "THU") { cout << 3 << endl; } if (str == "WED") { cout << 4 << endl; } if (str == "TUE") { cout << 5 << endl; } if (str == "MON") { cout << 6 << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define vi vector<int> #define vll vector<ll> #define pll pair<ll, ll> #define pii pair<int, int> #define pb push_back #define ppb pop_back #define mp make_pair int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); string str; cin >> str; if (str == "SUN") { cout << 7 << endl; } if (str == "SAT") { cout << 1 << endl; } if (str == "FRI") { cout << 2 << endl; } if (str == "THU") { cout << 3 << endl; } if (str == "WED") { cout << 4 << endl; } if (str == "TUE") { cout << 5 << endl; } if (str == "MON") { cout << 6 << endl; } }
replace
11
15
11
15
0