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
p02653
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define PB push_back #define MP make_pair #define SZ(v) ((int)(v).size()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define FORE(i, a, b) for (int i = (a); i <= (b); ++i) #define REPE(i, n) FORE(i, 0, n) #define FORSZ(i, a, v) FOR(i, a, SZ(v)) #define REPSZ(i, v) REP(i, SZ(v)) std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 5000; const int MOD = 1000000007; void inc(int &a, int b) { if ((a += b) >= MOD) a -= MOD; } void dec(int &a, int b) { if ((a -= b) < 0) a += MOD; } int n, alen, blen; // dp[i][j][k] = number of ways to select a block of i characters ending with // less than alen zeroes (or empty) with no valid subsequence, followed by a // block of length j starting with 1 (or at beginning of string) in which all // subsequences of zeroes have length at least alen, ending with k int dp[MAXN + 1][MAXN + 1][2]; int dpsum[MAXN + 1][MAXN + 2]; int p2[MAXN + 1]; int solve() { p2[0] = 1; FORE(i, 1, n) p2[i] = (ll)p2[i - 1] * 2 % MOD; if (alen > blen) swap(alen, blen); REPE(i, n) dpsum[i][0] = dpsum[i][1] = 0; REPE(i, n) FORE(j, 1, blen) { dp[i][j][0] = dp[i][j][1] = 0; FORE(k, alen, j - 1) inc(dp[i][j][0], dp[i][j - k][1]); if (i == 0 && j >= alen) inc(dp[i][j][0], 1); if (j == 1) { if (i < alen) inc(dp[i][j][1], 1); // FORE(k, 1, min(i, alen - 1)) FORE(l, 1, min(blen - 1, i - k)) // inc(dp[i][j][1], dp[i - k - l][l][1]); FORE(z, 2, i) FORE(k, max(1, z - // blen + 1), min(min(i, alen - 1), z - 1)) { int l = z - k; // inc(dp[i][j][1], dp[i - z][l][1]); } FORE(z, 2, i) { int lo = z - min(min(i, alen - 1), z - 1), hi = z - max(1, z - blen + 1); lo = min(lo, blen); hi = min(hi, blen); // FORE(l, lo, hi) inc(dp[i][j][1], dp[i - z][l][1]); //{ int chk = 0; FORE(l, 0, hi) inc(chk, dp[i - z][l][1]); if (!(chk == //dpsum[i - z][hi + 1])) { printf("err i-z=%d hi+1=%d: %d vs %d\n", i - //z, hi + 1, chk, dpsum[i - z][hi + 1]); exit(0); } } { int chk = 0; //FORE(l, 0, lo - 1) inc(chk, dp[i - z][l][1]); if (!(chk == dpsum[i - //z][lo])) { printf("err i-z=%d lo=%d: %d vs %d [i=%d]\n", i - z, lo, //chk, dpsum[i - z][lo],i); exit(0); } } inc(dp[i][j][1], dpsum[i - z][hi + 1]); dec(dp[i][j][1], dpsum[i - z][lo]); } } else { inc(dp[i][j][1], dp[i][j - 1][0]); inc(dp[i][j][1], dp[i][j - 1][1]); } // printf("dp[%d][%d]: %d / %d\n", i, j, dp[i][j][0], dp[i][j][1]); dpsum[i][j + 1] = dpsum[i][j]; inc(dpsum[i][j + 1], dp[i][j][1]); // if (i == 1) printf("dpsum[%d][%d]=%d dp[%d][%d][1]=%d -> // dpsum[%d][%d]=%d\n", i, j, dpsum[i][j], i, j, dp[i][j][1], i, j + 1, // dpsum[i][j + 1]); } int ret = 0; REPE(i, n - blen) { int cur = 0; REP(k, 2) inc(cur, dp[i][blen][k]); // printf("%d: (%d+%d)*%d\n", i, dp[i][blen][0], dp[i][blen][1], p2[n - i - // blen]); cur = (ll)cur * p2[n - i - blen] % MOD; inc(ret, cur); } REPE(i, n - blen) FORE(j, 1, blen - 1) if (i + j + alen <= n && j + alen > blen) { int cur = dp[i][j][1]; // printf("%d %d: %d * %d\n", i, j, cur, p2[n - i - j - alen]); cur = (ll)cur * p2[n - i - j - alen] % MOD; inc(ret, cur); } return ret; } void run() { scanf("%d%d%d", &n, &alen, &blen); printf("%d\n", solve()); } int solvestupid() { int ret = 0; assert(alen <= blen); REP(mask, 1 << n) { bool ok = false; REPE(offset, n - blen) { int nzero = 0; REP(i, n - offset) { int cur = (mask >> (offset + i)) & 1; if (cur == 0) ++nzero; if (cur == 1) { if (nzero != 0 && nzero < alen) break; nzero = 0; } if ((nzero == 0 || nzero >= alen) && i + 1 >= blen) ok = true; } } if (ok) ++ret; } return ret; } void stress() { for (n = 1; n <= 15; ++n) for (alen = 1; alen <= n; ++alen) for (blen = alen; blen <= n; ++blen) { int have = solve(); int want = solvestupid(); if (have == want) { printf("."); continue; } printf("err %d %d %d: have=%d want=%d\n", n, alen, blen, have, want); } } int main() { // stress(); run(); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define PB push_back #define MP make_pair #define SZ(v) ((int)(v).size()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define FORE(i, a, b) for (int i = (a); i <= (b); ++i) #define REPE(i, n) FORE(i, 0, n) #define FORSZ(i, a, v) FOR(i, a, SZ(v)) #define REPSZ(i, v) REP(i, SZ(v)) std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 5000; const int MOD = 1000000007; void inc(int &a, int b) { if ((a += b) >= MOD) a -= MOD; } void dec(int &a, int b) { if ((a -= b) < 0) a += MOD; } int n, alen, blen; // dp[i][j][k] = number of ways to select a block of i characters ending with // less than alen zeroes (or empty) with no valid subsequence, followed by a // block of length j starting with 1 (or at beginning of string) in which all // subsequences of zeroes have length at least alen, ending with k int dp[MAXN + 1][MAXN + 1][2]; int dpsum[MAXN + 1][MAXN + 2]; int p2[MAXN + 1]; int solve() { p2[0] = 1; FORE(i, 1, n) p2[i] = (ll)p2[i - 1] * 2 % MOD; if (alen > blen) swap(alen, blen); REPE(i, n) dpsum[i][0] = dpsum[i][1] = 0; REPE(i, n) FORE(j, 1, blen) { dp[i][j][0] = dp[i][j][1] = 0; if (alen <= j - 1) { int lo = 1, hi = j - alen; // FORE(k, alen, j - 1) inc(dp[i][j][0], dp[i][j - k][1]); inc(dp[i][j][0], dpsum[i][hi + 1]); dec(dp[i][j][0], dpsum[i][lo]); } if (i == 0 && j >= alen) inc(dp[i][j][0], 1); if (j == 1) { if (i < alen) inc(dp[i][j][1], 1); // FORE(k, 1, min(i, alen - 1)) FORE(l, 1, min(blen - 1, i - k)) // inc(dp[i][j][1], dp[i - k - l][l][1]); FORE(z, 2, i) FORE(k, max(1, z - // blen + 1), min(min(i, alen - 1), z - 1)) { int l = z - k; // inc(dp[i][j][1], dp[i - z][l][1]); } FORE(z, 2, i) { int lo = z - min(min(i, alen - 1), z - 1), hi = z - max(1, z - blen + 1); lo = min(lo, blen); hi = min(hi, blen); // FORE(l, lo, hi) inc(dp[i][j][1], dp[i - z][l][1]); //{ int chk = 0; FORE(l, 0, hi) inc(chk, dp[i - z][l][1]); if (!(chk == //dpsum[i - z][hi + 1])) { printf("err i-z=%d hi+1=%d: %d vs %d\n", i - //z, hi + 1, chk, dpsum[i - z][hi + 1]); exit(0); } } { int chk = 0; //FORE(l, 0, lo - 1) inc(chk, dp[i - z][l][1]); if (!(chk == dpsum[i - //z][lo])) { printf("err i-z=%d lo=%d: %d vs %d [i=%d]\n", i - z, lo, //chk, dpsum[i - z][lo],i); exit(0); } } inc(dp[i][j][1], dpsum[i - z][hi + 1]); dec(dp[i][j][1], dpsum[i - z][lo]); } } else { inc(dp[i][j][1], dp[i][j - 1][0]); inc(dp[i][j][1], dp[i][j - 1][1]); } // printf("dp[%d][%d]: %d / %d\n", i, j, dp[i][j][0], dp[i][j][1]); dpsum[i][j + 1] = dpsum[i][j]; inc(dpsum[i][j + 1], dp[i][j][1]); // if (i == 1) printf("dpsum[%d][%d]=%d dp[%d][%d][1]=%d -> // dpsum[%d][%d]=%d\n", i, j, dpsum[i][j], i, j, dp[i][j][1], i, j + 1, // dpsum[i][j + 1]); } int ret = 0; REPE(i, n - blen) { int cur = 0; REP(k, 2) inc(cur, dp[i][blen][k]); // printf("%d: (%d+%d)*%d\n", i, dp[i][blen][0], dp[i][blen][1], p2[n - i - // blen]); cur = (ll)cur * p2[n - i - blen] % MOD; inc(ret, cur); } REPE(i, n - blen) FORE(j, 1, blen - 1) if (i + j + alen <= n && j + alen > blen) { int cur = dp[i][j][1]; // printf("%d %d: %d * %d\n", i, j, cur, p2[n - i - j - alen]); cur = (ll)cur * p2[n - i - j - alen] % MOD; inc(ret, cur); } return ret; } void run() { scanf("%d%d%d", &n, &alen, &blen); printf("%d\n", solve()); } int solvestupid() { int ret = 0; assert(alen <= blen); REP(mask, 1 << n) { bool ok = false; REPE(offset, n - blen) { int nzero = 0; REP(i, n - offset) { int cur = (mask >> (offset + i)) & 1; if (cur == 0) ++nzero; if (cur == 1) { if (nzero != 0 && nzero < alen) break; nzero = 0; } if ((nzero == 0 || nzero >= alen) && i + 1 >= blen) ok = true; } } if (ok) ++ret; } return ret; } void stress() { for (n = 1; n <= 15; ++n) for (alen = 1; alen <= n; ++alen) for (blen = alen; blen <= n; ++blen) { int have = solve(); int want = solvestupid(); if (have == want) { printf("."); continue; } printf("err %d %d %d: have=%d want=%d\n", n, alen, blen, have, want); } } int main() { // stress(); run(); return 0; }
replace
64
65
64
70
TLE
p02653
C++
Runtime Error
#include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_set> #include <vector> using namespace std; using namespace std::chrono; typedef long long int llint; typedef long double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase #define REP(i, n) for (int i = 0; i < (n); i++) /*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/ const llint mod = 1000000007; const llint inf = 2.19e15 + 1; const long double pai = 3.141592653589793238462643383279502884197; const long double eps = 1e-10; template <class T, class U> bool chmin(T &a, U b) { if (a > b) { a = b; return true; } return false; } template <class T, class U> bool chmax(T &a, U b) { if (a < b) { a = b; return true; } return false; } llint gcd(llint a, llint b) { if (a % b == 0) { return b; } else return gcd(b, a % b); } llint lcm(llint a, llint b) { if (a == 0) { return b; } return a / gcd(a, b) * b; } template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); } template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); } template <class T> llint LBI(const vector<T> &ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); } template <class T> llint UBI(const vector<T> &ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); } #include <algorithm> #include <cstdint> #include <type_traits> #include <utility> // 永夜作 #define mnt mint_base class mint_base; // mint_base_base型用の累乗関数 constexpr mint_base m_pow(mint_base x, uint64_t n) noexcept; // mod計算を自動で行う整数テンプレートクラス class mint_base { public: constexpr mint_base operator+(const mint_base &other) const noexcept { auto v = *this; return v += other; } constexpr mint_base operator-(const mint_base &other) const noexcept { auto v = *this; return v -= other; } constexpr mint_base operator*(const mint_base &other) const noexcept { auto v = *this; return v *= other; } constexpr auto operator/(const mint_base &other) const noexcept { auto v = *this; return v /= other; } constexpr mint_base &operator+=(const mint_base &other) noexcept { a += other.a; if (mod <= a) { a -= mod; }; return *this; } constexpr mint_base &operator-=(const mint_base &other) noexcept { if (a >= other.a) { a -= other.a; } else { a = (a + mod) - other.a; } return *this; } constexpr mint_base &operator*=(const mint_base &other) noexcept { a *= other.a; a %= mod; return *this; } constexpr mint_base &operator/=(const mint_base &other) noexcept { return *this *= ~other; } constexpr mint_base operator+() const noexcept { return *this; } constexpr mint_base operator-() const noexcept { return {mod - a, mod_value_tag{}}; } constexpr mint_base &operator++() noexcept { if (mod <= ++a) { a = 0; }; return *this; } constexpr mint_base &operator--() noexcept { if (a <= 0) { a = mod; }; --a; return *this; } constexpr mint_base operator++(int) noexcept { auto tmp = *this; ++*this; return tmp; } constexpr mint_base operator--(int) noexcept { auto tmp = *this; --*this; return tmp; } constexpr mint_base operator~() const noexcept { return m_pow(*this, mod - 2); } constexpr mint_base &operator=(const mint_base &other) noexcept { a = other.a; return *this; } constexpr explicit operator uint64_t() const noexcept { return a; } constexpr explicit operator int() const noexcept { return a; } constexpr explicit operator unsigned() const noexcept { return (unsigned)a; } static constexpr uint64_t getmod() noexcept { return mod; } constexpr mint_base(uint64_t a_) noexcept : a(a_ % mod) {} constexpr mint_base() noexcept : a(0) {} struct mod_value_tag {}; constexpr mint_base(uint64_t a_, mod_value_tag) : a(a_) {} private: uint64_t a; }; // mint_base型用の累乗関数 constexpr mint_base m_pow(mint_base x, uint64_t n) noexcept { mint_base res = 1; while (n > 0) { if (n & 1) { res *= x; } x *= x; n >>= 1; } return res; } // mint_baseの階乗計算 // 0からxまでの階乗を返す // O(x)時間が必要 vector<mint_base> fla; // 階乗が入る void fla_set(mint_base x) { fla.resize(((uint64_t)x) + 1); fla[0] = 1; for (uint64_t i = 1; i <= (uint64_t)x; i++) { fla[i] = fla[i - 1] * i; } } vector<mint_base> gya; //~fla[i] が入る // O(x+log mod)で求める O(xlogmod)より速い void fla_gya_set(mint_base x) { fla_set(x); gya.resize(((uint64_t)x) + 1); gya[(uint64_t)x] = ~fla[(uint64_t)x]; for (uint64_t i = (uint64_t)x; i > 0; i--) { gya[i - 1] = gya[i] * i; } } // mint_base型のstreamへの出力 std::ostream &operator<<(std::ostream &os, mint_base i) { os << (uint64_t)i; return os; } // mint_base型のstreamからの入力 std::istream &operator>>(std::istream &is, mint_base &i) { uint64_t tmp; is >> tmp; i = tmp; return is; } int main(void) { int i, j, k, n, A, B; cin >> n >> A >> B; if (A > B) { swap(A, B); } // できない数をカウントする static mint_base dp[5015][5015] = {}; static mint_base ep[5015][5015] = {}; mint_base wa[5015] = {}; mint_base ans = 0; dp[0][0] = 1; for (i = 0; i <= n; i++) { mint_base aaa = 0; wa[i + 1] += wa[i]; dp[i][1] += wa[i]; for (j = 0; j < B; j++) { dp[i][j] += ep[i][j]; // cout<<dp[i][j]<<" "; ep[i + 1][j + 1] += ep[i][j]; dp[i + 1][j + 1] += dp[i][j]; // 1 if (i > 0 && j == 0) { continue; } aaa += dp[i][j]; if (i + A + 1 <= n + 5 && j + A + 1 <= n + 5) { ep[i + A + 1][j + A + 1] += dp[i][j]; } } // cout<<endl; // cout<<aaa<<endl; wa[i + 2] += aaa; wa[i + A + 1] -= aaa; } for (i = 0; i <= n; i++) { for (j = 0; j < B; j++) { if (n - i + j < B || n - i < A) { ans += dp[i][j]; } } } mint_base eee = 1; for (i = 0; i < n; i++) { eee *= 2; } cout << eee - ans << endl; return 0; }
#include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_set> #include <vector> using namespace std; using namespace std::chrono; typedef long long int llint; typedef long double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase #define REP(i, n) for (int i = 0; i < (n); i++) /*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/ const llint mod = 1000000007; const llint inf = 2.19e15 + 1; const long double pai = 3.141592653589793238462643383279502884197; const long double eps = 1e-10; template <class T, class U> bool chmin(T &a, U b) { if (a > b) { a = b; return true; } return false; } template <class T, class U> bool chmax(T &a, U b) { if (a < b) { a = b; return true; } return false; } llint gcd(llint a, llint b) { if (a % b == 0) { return b; } else return gcd(b, a % b); } llint lcm(llint a, llint b) { if (a == 0) { return b; } return a / gcd(a, b) * b; } template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); } template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); } template <class T> llint LBI(const vector<T> &ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); } template <class T> llint UBI(const vector<T> &ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); } #include <algorithm> #include <cstdint> #include <type_traits> #include <utility> // 永夜作 #define mnt mint_base class mint_base; // mint_base_base型用の累乗関数 constexpr mint_base m_pow(mint_base x, uint64_t n) noexcept; // mod計算を自動で行う整数テンプレートクラス class mint_base { public: constexpr mint_base operator+(const mint_base &other) const noexcept { auto v = *this; return v += other; } constexpr mint_base operator-(const mint_base &other) const noexcept { auto v = *this; return v -= other; } constexpr mint_base operator*(const mint_base &other) const noexcept { auto v = *this; return v *= other; } constexpr auto operator/(const mint_base &other) const noexcept { auto v = *this; return v /= other; } constexpr mint_base &operator+=(const mint_base &other) noexcept { a += other.a; if (mod <= a) { a -= mod; }; return *this; } constexpr mint_base &operator-=(const mint_base &other) noexcept { if (a >= other.a) { a -= other.a; } else { a = (a + mod) - other.a; } return *this; } constexpr mint_base &operator*=(const mint_base &other) noexcept { a *= other.a; a %= mod; return *this; } constexpr mint_base &operator/=(const mint_base &other) noexcept { return *this *= ~other; } constexpr mint_base operator+() const noexcept { return *this; } constexpr mint_base operator-() const noexcept { return {mod - a, mod_value_tag{}}; } constexpr mint_base &operator++() noexcept { if (mod <= ++a) { a = 0; }; return *this; } constexpr mint_base &operator--() noexcept { if (a <= 0) { a = mod; }; --a; return *this; } constexpr mint_base operator++(int) noexcept { auto tmp = *this; ++*this; return tmp; } constexpr mint_base operator--(int) noexcept { auto tmp = *this; --*this; return tmp; } constexpr mint_base operator~() const noexcept { return m_pow(*this, mod - 2); } constexpr mint_base &operator=(const mint_base &other) noexcept { a = other.a; return *this; } constexpr explicit operator uint64_t() const noexcept { return a; } constexpr explicit operator int() const noexcept { return a; } constexpr explicit operator unsigned() const noexcept { return (unsigned)a; } static constexpr uint64_t getmod() noexcept { return mod; } constexpr mint_base(uint64_t a_) noexcept : a(a_ % mod) {} constexpr mint_base() noexcept : a(0) {} struct mod_value_tag {}; constexpr mint_base(uint64_t a_, mod_value_tag) : a(a_) {} private: uint64_t a; }; // mint_base型用の累乗関数 constexpr mint_base m_pow(mint_base x, uint64_t n) noexcept { mint_base res = 1; while (n > 0) { if (n & 1) { res *= x; } x *= x; n >>= 1; } return res; } // mint_baseの階乗計算 // 0からxまでの階乗を返す // O(x)時間が必要 vector<mint_base> fla; // 階乗が入る void fla_set(mint_base x) { fla.resize(((uint64_t)x) + 1); fla[0] = 1; for (uint64_t i = 1; i <= (uint64_t)x; i++) { fla[i] = fla[i - 1] * i; } } vector<mint_base> gya; //~fla[i] が入る // O(x+log mod)で求める O(xlogmod)より速い void fla_gya_set(mint_base x) { fla_set(x); gya.resize(((uint64_t)x) + 1); gya[(uint64_t)x] = ~fla[(uint64_t)x]; for (uint64_t i = (uint64_t)x; i > 0; i--) { gya[i - 1] = gya[i] * i; } } // mint_base型のstreamへの出力 std::ostream &operator<<(std::ostream &os, mint_base i) { os << (uint64_t)i; return os; } // mint_base型のstreamからの入力 std::istream &operator>>(std::istream &is, mint_base &i) { uint64_t tmp; is >> tmp; i = tmp; return is; } int main(void) { int i, j, k, n, A, B; cin >> n >> A >> B; if (A > B) { swap(A, B); } // できない数をカウントする static mint_base dp[5015][5015] = {}; static mint_base ep[5015][5015] = {}; mint_base wa[5015] = {}; mint_base ans = 0; dp[0][0] = 1; for (i = 0; i <= n; i++) { mint_base aaa = 0; wa[i + 1] += wa[i]; dp[i][1] += wa[i]; for (j = 0; j < B; j++) { dp[i][j] += ep[i][j]; // cout<<dp[i][j]<<" "; ep[i + 1][j + 1] += ep[i][j]; dp[i + 1][j + 1] += dp[i][j]; // 1 if (i > 0 && j == 0) { continue; } aaa += dp[i][j]; if (i + A + 1 <= n + 5 && j + A + 1 <= n + 5) { ep[i + A + 1][j + A + 1] += dp[i][j]; } } // cout<<endl; // cout<<aaa<<endl; wa[i + 2] += aaa; if (i + A + 1 <= n + 5) { wa[i + A + 1] -= aaa; } } for (i = 0; i <= n; i++) { for (j = 0; j < B; j++) { if (n - i + j < B || n - i < A) { ans += dp[i][j]; } } } mint_base eee = 1; for (i = 0; i < n; i++) { eee *= 2; } cout << eee - ans << endl; return 0; }
replace
260
261
260
263
-11
p02653
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long int LL; typedef pair<int, int> P; typedef pair<LL, int> LP; const int INF = 1 << 30; const LL MAX = 1e9 + 7; void array_show(int *array, int array_n, char middle = ' ') { for (int i = 0; i < array_n; i++) printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n')); } void array_show(LL *array, int array_n, char middle = ' ') { for (int i = 0; i < array_n; i++) printf("%lld%c", array[i], (i != array_n - 1 ? middle : '\n')); } void array_show(vector<int> &vec_s, int vec_n = -1, char middle = ' ') { if (vec_n == -1) vec_n = vec_s.size(); for (int i = 0; i < vec_n; i++) printf("%d%c", vec_s[i], (i != vec_n - 1 ? middle : '\n')); } void array_show(vector<LL> &vec_s, int vec_n = -1, char middle = ' ') { if (vec_n == -1) vec_n = vec_s.size(); for (int i = 0; i < vec_n; i++) printf("%lld%c", vec_s[i], (i != vec_n - 1 ? middle : '\n')); } LL dp[3300][3300]; LL t[3300]; LL t2[3300]; long long int pow_mod(long long int p_a, long long int p_n, long long int p_p = 1e9 + 7) { // p_a^p_n mod p_p long long int p_b = 1, p_t = 1; for (; p_b <= p_n; p_b <<= 1) ; for (p_b >>= 1; p_b > 0; p_b >>= 1) { p_t *= p_t; if (p_t >= p_p) p_t %= p_p; if (p_n & p_b) p_t *= p_a; if (p_t >= p_p) p_t %= p_p; } return p_t; } int main() { int n, m; int i, j, k; LL a, b, c; LL x, y; LL s[10] = {0}; cin >> n; cin >> x >> y; if (x < y) swap(x, y); memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (i = 0; i < x; i++) { dp[i + 1][0] = dp[i][0]; a = 0; for (j = 0; j < x; j++) { dp[i + 1][j + 1] = dp[i][j]; if (j >= y) a += dp[i][j]; } a %= MAX; dp[i + 1][0] += a; if (dp[i + 1][0] >= MAX) dp[i + 1][0] %= MAX; } for (i = 0; i <= x; i++) { t[i] = dp[i][0]; } memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (i = 0; i <= n; i++) { if (i + 1 < x) { dp[i + 1][0] += t[i + 1]; dp[i + 1][0] %= MAX; } for (j = 0; j < y; j++) { dp[i + 1][j + 1] = dp[i][j]; if (j) t2[i] += dp[i][j]; } t2[i] %= MAX; a = 0; for (j = 0; j < x - 1; j++) { if (i - j < 0) break; a += t2[i - j] * t[j]; if (a >= MAX) a %= MAX; } dp[i + 1][0] += a; dp[i + 1][0] %= MAX; } for (i = 1; i < y; i++) { s[2] += dp[n][i]; } for (j = 1; j < x; j++) { if (n - j < 0) break; s[2] += t2[n - j] * t[j]; if (s[2] >= MAX) s[2] %= MAX; } s[2] %= MAX; s[0] = pow_mod(2, n) - s[2]; if (s[0] < 0) s[0] += MAX; cout << s[0] % MAX << endl; }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long int LL; typedef pair<int, int> P; typedef pair<LL, int> LP; const int INF = 1 << 30; const LL MAX = 1e9 + 7; void array_show(int *array, int array_n, char middle = ' ') { for (int i = 0; i < array_n; i++) printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n')); } void array_show(LL *array, int array_n, char middle = ' ') { for (int i = 0; i < array_n; i++) printf("%lld%c", array[i], (i != array_n - 1 ? middle : '\n')); } void array_show(vector<int> &vec_s, int vec_n = -1, char middle = ' ') { if (vec_n == -1) vec_n = vec_s.size(); for (int i = 0; i < vec_n; i++) printf("%d%c", vec_s[i], (i != vec_n - 1 ? middle : '\n')); } void array_show(vector<LL> &vec_s, int vec_n = -1, char middle = ' ') { if (vec_n == -1) vec_n = vec_s.size(); for (int i = 0; i < vec_n; i++) printf("%lld%c", vec_s[i], (i != vec_n - 1 ? middle : '\n')); } LL dp[5300][5300]; LL t[5300]; LL t2[5300]; long long int pow_mod(long long int p_a, long long int p_n, long long int p_p = 1e9 + 7) { // p_a^p_n mod p_p long long int p_b = 1, p_t = 1; for (; p_b <= p_n; p_b <<= 1) ; for (p_b >>= 1; p_b > 0; p_b >>= 1) { p_t *= p_t; if (p_t >= p_p) p_t %= p_p; if (p_n & p_b) p_t *= p_a; if (p_t >= p_p) p_t %= p_p; } return p_t; } int main() { int n, m; int i, j, k; LL a, b, c; LL x, y; LL s[10] = {0}; cin >> n; cin >> x >> y; if (x < y) swap(x, y); memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (i = 0; i < x; i++) { dp[i + 1][0] = dp[i][0]; a = 0; for (j = 0; j < x; j++) { dp[i + 1][j + 1] = dp[i][j]; if (j >= y) a += dp[i][j]; } a %= MAX; dp[i + 1][0] += a; if (dp[i + 1][0] >= MAX) dp[i + 1][0] %= MAX; } for (i = 0; i <= x; i++) { t[i] = dp[i][0]; } memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (i = 0; i <= n; i++) { if (i + 1 < x) { dp[i + 1][0] += t[i + 1]; dp[i + 1][0] %= MAX; } for (j = 0; j < y; j++) { dp[i + 1][j + 1] = dp[i][j]; if (j) t2[i] += dp[i][j]; } t2[i] %= MAX; a = 0; for (j = 0; j < x - 1; j++) { if (i - j < 0) break; a += t2[i - j] * t[j]; if (a >= MAX) a %= MAX; } dp[i + 1][0] += a; dp[i + 1][0] %= MAX; } for (i = 1; i < y; i++) { s[2] += dp[n][i]; } for (j = 1; j < x; j++) { if (n - j < 0) break; s[2] += t2[n - j] * t[j]; if (s[2] >= MAX) s[2] %= MAX; } s[2] %= MAX; s[0] = pow_mod(2, n) - s[2]; if (s[0] < 0) s[0] += MAX; cout << s[0] % MAX << endl; }
replace
41
44
41
44
0
p02653
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; #define mod 1000000007 #define maxn 1010 int n, a, b; int ksm(int x, int y) { int re = 1; for (; (y & 1 ? re = 1ll * re * x % mod : 0), y; y >>= 1, x = 1ll * x * x % mod) ; return re; } int g[maxn][2], f[maxn][2]; void add(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); } int main() { scanf("%d %d %d", &n, &a, &b); if (a > b) swap(a, b); g[1][1] = 1; for (int i = 2; i < b; i++) { g[i][1] = (g[i - 1][0] + g[i - 1][1]) % mod; for (int j = a; j < i; j++) add(g[i][0], g[i - j][1]); } f[0][0] = f[0][1] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j < min(a, i + 1); j++) add(f[i][0], f[i - j][1]); for (int j = 1; j < min(b, i + 1); j++) { if (i == n) add(f[i][0], 1ll * f[i - j][0] * g[j][0] % mod); if (i == j) add(f[i][1], (g[j][0] + g[j][1]) % mod); else add(f[i][1], 1ll * f[i - j][0] * g[j][1] % mod); } } printf("%d", (ksm(2, n) - (f[n][0] + f[n][1]) % mod + mod) % mod); }
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; #define mod 1000000007 #define maxn 5010 int n, a, b; int ksm(int x, int y) { int re = 1; for (; (y & 1 ? re = 1ll * re * x % mod : 0), y; y >>= 1, x = 1ll * x * x % mod) ; return re; } int g[maxn][2], f[maxn][2]; void add(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); } int main() { scanf("%d %d %d", &n, &a, &b); if (a > b) swap(a, b); g[1][1] = 1; for (int i = 2; i < b; i++) { g[i][1] = (g[i - 1][0] + g[i - 1][1]) % mod; for (int j = a; j < i; j++) add(g[i][0], g[i - j][1]); } f[0][0] = f[0][1] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j < min(a, i + 1); j++) add(f[i][0], f[i - j][1]); for (int j = 1; j < min(b, i + 1); j++) { if (i == n) add(f[i][0], 1ll * f[i - j][0] * g[j][0] % mod); if (i == j) add(f[i][1], (g[j][0] + g[j][1]) % mod); else add(f[i][1], 1ll * f[i - j][0] * g[j][1] % mod); } } printf("%d", (ksm(2, n) - (f[n][0] + f[n][1]) % mod + mod) % mod); }
replace
5
6
5
6
0
p02653
C++
Runtime Error
#include <bits/stdc++.h> // using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define rep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++) #define REP(i, j, n) for (ll i = (ll)(j); i <= (ll)(n); i++) #define per(i, j, n) for (ll i = (ll)(j); (ll)(n) <= i; i--) #define ll long long #define ALL(a) (a).begin(), (a).end() #define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (ll)(key))) #define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (ll)(key))) #define pb emplace_back #define mp std::make_pair #define endl "\n" // using std::endl; using std::cin; using std::cout; using std::lower_bound; using std::string; using std::upper_bound; using std::vector; using vi = vector<ll>; using vii = vector<vi>; using pii = std::pair<ll, ll>; // constexpr ll MOD = 1e9 + 7; // constexpr ll MOD=998244353; // constexpr ll MOD=10000000; constexpr ll MAX = 1e6; constexpr ll INF = (1ll << 62); template <class T> class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> { }; struct Segment_tree { ll N; vector<pii> node; Segment_tree(ll sz) { N = 1; while (N < sz) N *= 2; node.resize(2 * N - 1, mp(INF, INF)); per(i, N - 2, 0) { node[i] = std::min(node[i * 2 + 1], node[i * 2 + 1]); } } void update(ll X, pii val) { X += N - 1; node[X] = val; while (X > 0) { X = (X - 1) / 2; node[X] = std::min(node[X * 2 + 1], node[X * 2 + 2]); } } pii RMQ(ll a, ll b, ll now, ll l, ll r) { //[a,b),[l,r) if (r < 0) r = N; if (r <= a || b <= l) return mp(INF, INF); if (a <= l && r <= b) return node[now]; auto vl = RMQ(a, b, now * 2 + 1, l, (l + r) / 2), vr = RMQ(a, b, now * 2 + 2, (l + r) / 2, r); return std::min(vl, vr); } }; struct Binary_indexed_tree { int N; vi bit; Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); } void add(int x, int a) { for (x; x <= N; x += (x & -x)) bit[x] += a; } ll sum(int x) { ll ret = 0; for (x; x > 0; x -= (x & -x)) ret += bit[x]; return ret; } ll lower_bound(ll X) { if (sum(N) < X) return -1; ll ret = 0, memo = 1, sum = 0; while (memo * 2 <= N) memo *= 2; while (memo > 0) { if (memo + ret <= N && sum + bit[memo + ret] < X) { sum += bit[memo + ret]; ret += memo; } memo /= 2; } return ret + 1; } }; struct Union_Find { ll N; vi par; vi siz; Union_Find(int n) : N(n) { par.resize(N); siz.resize(N, 1); rep(i, 0, N) par[i] = i; } ll root(ll X) { if (par[X] == X) return X; return par[X] = root(par[X]); } bool same(ll X, ll Y) { return root(X) == root(Y); } void unite(ll X, ll Y) { X = root(X); Y = root(Y); if (X == Y) return; par[X] = Y; siz[Y] += siz[X]; siz[X] = 0; } ll size(ll X) { return siz[root(X)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } vi fac, finv, inv; void COMinit() { fac.resize(MAX); finv.resize(MAX); inv.resize(MAX); 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; } } ll COM(ll n, ll r) { if (n < r || n < 0 || r < 0) return 0; return fac[n] * finv[r] % MOD * finv[n - r] % MOD; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); ll N, A, B; cin >> N >> A >> B; A--, B--; if (A < B) std::swap(A, B); vi memo(A + 2, 1); vii ap(A, vi(A)); ap[0][0] = 1; rep(j, 0, A - 1) { rep(k, 0, A - 1) { ap[j + 1][k + 1] += ap[j][k]; ap[j + 1][k + 1] %= MOD; } ap[j + 1][0] += ap[j][0]; ap[j + 1][0] %= MOD; rep(k, B + 1, A - 1) { ap[j + 1][0] += ap[j][k]; ap[j + 1][0] %= MOD; } } rep(i, 0, A) { memo[i + 2] = 0; REP(j, B + 1, i) { memo[i + 2] += ap[i][j]; memo[i + 2] %= MOD; } memo[i + 2] += ap[i][0]; memo[i + 2] %= MOD; } vii dp(N + 1, vi(A + 1)), cp(N + 1, vi(B + 1)); ll ans = modpow(2, N, MOD); dp[0][0] = 1; rep(i, 0, N) { rep(j, 0, A) { dp[i + 1][j + 1] += dp[i][j]; dp[i + 1][j + 1] %= MOD; if (i == j) cp[i + 1][1] += dp[i][j] * memo[j + 1] % MOD; else cp[i + 1][1] += dp[i][j] * memo[j] % MOD; cp[i + 1][1] %= MOD; } rep(j, 0, B) { cp[i + 1][j + 1] += cp[i][j]; cp[i + 1][j + 1] %= MOD; dp[i + 1][1] += cp[i][j]; dp[i + 1][1] %= MOD; } dp[i + 1][1] += cp[i][B]; dp[i + 1][1] %= MOD; if (i == A) cp[i + 1][1] += dp[i][A] * memo[A + 1] % MOD; else cp[i + 1][1] += dp[i][A] * memo[A] % MOD; cp[i + 1][1] %= MOD; } REP(i, 0, A) { ans -= dp[N][i] * memo[i + 1] % MOD; ans %= MOD; if (ans < 0) ans += MOD; } REP(i, 0, B) { ans -= cp[N][i]; ans %= MOD; if (ans < 0) ans += MOD; } cout << ans << endl; }
#include <bits/stdc++.h> // using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define rep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++) #define REP(i, j, n) for (ll i = (ll)(j); i <= (ll)(n); i++) #define per(i, j, n) for (ll i = (ll)(j); (ll)(n) <= i; i--) #define ll long long #define ALL(a) (a).begin(), (a).end() #define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (ll)(key))) #define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (ll)(key))) #define pb emplace_back #define mp std::make_pair #define endl "\n" // using std::endl; using std::cin; using std::cout; using std::lower_bound; using std::string; using std::upper_bound; using std::vector; using vi = vector<ll>; using vii = vector<vi>; using pii = std::pair<ll, ll>; // constexpr ll MOD = 1e9 + 7; // constexpr ll MOD=998244353; // constexpr ll MOD=10000000; constexpr ll MAX = 1e6; constexpr ll INF = (1ll << 62); template <class T> class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> { }; struct Segment_tree { ll N; vector<pii> node; Segment_tree(ll sz) { N = 1; while (N < sz) N *= 2; node.resize(2 * N - 1, mp(INF, INF)); per(i, N - 2, 0) { node[i] = std::min(node[i * 2 + 1], node[i * 2 + 1]); } } void update(ll X, pii val) { X += N - 1; node[X] = val; while (X > 0) { X = (X - 1) / 2; node[X] = std::min(node[X * 2 + 1], node[X * 2 + 2]); } } pii RMQ(ll a, ll b, ll now, ll l, ll r) { //[a,b),[l,r) if (r < 0) r = N; if (r <= a || b <= l) return mp(INF, INF); if (a <= l && r <= b) return node[now]; auto vl = RMQ(a, b, now * 2 + 1, l, (l + r) / 2), vr = RMQ(a, b, now * 2 + 2, (l + r) / 2, r); return std::min(vl, vr); } }; struct Binary_indexed_tree { int N; vi bit; Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); } void add(int x, int a) { for (x; x <= N; x += (x & -x)) bit[x] += a; } ll sum(int x) { ll ret = 0; for (x; x > 0; x -= (x & -x)) ret += bit[x]; return ret; } ll lower_bound(ll X) { if (sum(N) < X) return -1; ll ret = 0, memo = 1, sum = 0; while (memo * 2 <= N) memo *= 2; while (memo > 0) { if (memo + ret <= N && sum + bit[memo + ret] < X) { sum += bit[memo + ret]; ret += memo; } memo /= 2; } return ret + 1; } }; struct Union_Find { ll N; vi par; vi siz; Union_Find(int n) : N(n) { par.resize(N); siz.resize(N, 1); rep(i, 0, N) par[i] = i; } ll root(ll X) { if (par[X] == X) return X; return par[X] = root(par[X]); } bool same(ll X, ll Y) { return root(X) == root(Y); } void unite(ll X, ll Y) { X = root(X); Y = root(Y); if (X == Y) return; par[X] = Y; siz[Y] += siz[X]; siz[X] = 0; } ll size(ll X) { return siz[root(X)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } vi fac, finv, inv; void COMinit() { fac.resize(MAX); finv.resize(MAX); inv.resize(MAX); 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; } } ll COM(ll n, ll r) { if (n < r || n < 0 || r < 0) return 0; return fac[n] * finv[r] % MOD * finv[n - r] % MOD; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); ll N, A, B; cin >> N >> A >> B; A--, B--; if (A < B) std::swap(A, B); vi memo(A + 2, 1); vii ap(A + 1, vi(A + 1)); ap[0][0] = 1; rep(j, 0, A - 1) { rep(k, 0, A - 1) { ap[j + 1][k + 1] += ap[j][k]; ap[j + 1][k + 1] %= MOD; } ap[j + 1][0] += ap[j][0]; ap[j + 1][0] %= MOD; rep(k, B + 1, A - 1) { ap[j + 1][0] += ap[j][k]; ap[j + 1][0] %= MOD; } } rep(i, 0, A) { memo[i + 2] = 0; REP(j, B + 1, i) { memo[i + 2] += ap[i][j]; memo[i + 2] %= MOD; } memo[i + 2] += ap[i][0]; memo[i + 2] %= MOD; } vii dp(N + 1, vi(A + 1)), cp(N + 1, vi(B + 1)); ll ans = modpow(2, N, MOD); dp[0][0] = 1; rep(i, 0, N) { rep(j, 0, A) { dp[i + 1][j + 1] += dp[i][j]; dp[i + 1][j + 1] %= MOD; if (i == j) cp[i + 1][1] += dp[i][j] * memo[j + 1] % MOD; else cp[i + 1][1] += dp[i][j] * memo[j] % MOD; cp[i + 1][1] %= MOD; } rep(j, 0, B) { cp[i + 1][j + 1] += cp[i][j]; cp[i + 1][j + 1] %= MOD; dp[i + 1][1] += cp[i][j]; dp[i + 1][1] %= MOD; } dp[i + 1][1] += cp[i][B]; dp[i + 1][1] %= MOD; if (i == A) cp[i + 1][1] += dp[i][A] * memo[A + 1] % MOD; else cp[i + 1][1] += dp[i][A] * memo[A] % MOD; cp[i + 1][1] %= MOD; } REP(i, 0, A) { ans -= dp[N][i] * memo[i + 1] % MOD; ans %= MOD; if (ans < 0) ans += MOD; } REP(i, 0, B) { ans -= cp[N][i]; ans %= MOD; if (ans < 0) ans += MOD; } cout << ans << endl; }
replace
159
160
159
160
0
p02653
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdexcept> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; const ll MOD = 1e9 + 7; void add(ll &lhs, ll rhs) { lhs = (lhs + rhs) % MOD; } int main() { int n, a, b; cin >> n >> a >> b; if (b < a) swap(a, b); if (a == 1 || b == 1) { assert(false); } vector<vector<ll>> Adp(n + 1, vector<ll>(b)); vector<vector<ll>> Bdp(n + 1, vector<ll>(b)); vector<vector<ll>> Cdp(n + 1, vector<ll>(b)); vector<ll> ok(n + 1); Adp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < a; j++) { if (j + 1 < a) { add(Adp[i + 1][j + 1], Adp[i][j]); } add(Bdp[i + 1][1], Adp[i][j]); if (i == 0 && j == 0) { if (a == b) { add(ok[i + a], Adp[i][0]); } else { add(Cdp[i + a][a], Adp[i][0]); } } } for (int j = 0; j < b; j++) { add(Adp[i + 1][1], Bdp[i][j]); if (j + 1 < b) { add(Bdp[i + 1][j + 1], Bdp[i][j]); } else { add(ok[i + 1], Bdp[i][j]); } if (i + a <= n) { if (j + a < b) { add(Cdp[i + a][j + a], Bdp[i][j]); } else { add(ok[i + a], Bdp[i][j]); } } } for (int j = 0; j < b; j++) { if (j + 1 < b) { add(Bdp[i + 1][j + 1], Cdp[i][j]); add(Cdp[i + 1][j + 1], Cdp[i][j]); } else { add(ok[i + 1], Cdp[i][j]); add(ok[i + 1], Cdp[i][j]); } } add(ok[i + 1], ok[i]); add(ok[i + 1], ok[i]); } cout << ok[n] << endl; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdexcept> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; const ll MOD = 1e9 + 7; void add(ll &lhs, ll rhs) { lhs = (lhs + rhs) % MOD; } int main() { int n, a, b; cin >> n >> a >> b; if (b < a) swap(a, b); if (a == 1 || b == 1) { ll res = 1; for (int i = 0; i < n; i++) { res = res * 2 % MOD; } cout << res << endl; return 0; } vector<vector<ll>> Adp(n + 1, vector<ll>(b)); vector<vector<ll>> Bdp(n + 1, vector<ll>(b)); vector<vector<ll>> Cdp(n + 1, vector<ll>(b)); vector<ll> ok(n + 1); Adp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < a; j++) { if (j + 1 < a) { add(Adp[i + 1][j + 1], Adp[i][j]); } add(Bdp[i + 1][1], Adp[i][j]); if (i == 0 && j == 0) { if (a == b) { add(ok[i + a], Adp[i][0]); } else { add(Cdp[i + a][a], Adp[i][0]); } } } for (int j = 0; j < b; j++) { add(Adp[i + 1][1], Bdp[i][j]); if (j + 1 < b) { add(Bdp[i + 1][j + 1], Bdp[i][j]); } else { add(ok[i + 1], Bdp[i][j]); } if (i + a <= n) { if (j + a < b) { add(Cdp[i + a][j + a], Bdp[i][j]); } else { add(ok[i + a], Bdp[i][j]); } } } for (int j = 0; j < b; j++) { if (j + 1 < b) { add(Bdp[i + 1][j + 1], Cdp[i][j]); add(Cdp[i + 1][j + 1], Cdp[i][j]); } else { add(ok[i + 1], Cdp[i][j]); add(ok[i + 1], Cdp[i][j]); } } add(ok[i + 1], ok[i]); add(ok[i + 1], ok[i]); } cout << ok[n] << endl; return 0; }
replace
35
37
35
41
0
p02653
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #define REP(_i, _a, _n) for (int _i = _a; _i <= _n; ++_i) #define PER(_i, _a, _n) for (int _i = _n; _i >= _a; --_i) #define hr putchar(10) #define pb push_back #define lc (o << 1) #define rc (lc | 1) #define mid ((l + r) >> 1) #define ls lc, l, mid #define rs rc, mid + 1, r #define x first #define y second #define io std::ios::sync_with_stdio(false) #define endl '\n' #define DB(_a) \ ({ \ REP(_i, 1, n) cout << _a[_i] << ','; \ hr; \ }) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int P = 1e9 + 7, INF = 0x3f3f3f3f; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll qpow(ll a, ll n) { ll r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; return r; } ll inv(ll x) { return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; } inline int rd() { int x = 0; char p = getchar(); while (p < '0' || p > '9') p = getchar(); while (p >= '0' && p <= '9') x = x * 10 + p - '0', p = getchar(); return x; } // head const int N = 5e3 + 10; int n, a, b, f[N], g[N][2]; void add(int &x, ll y) { x = (x + y) % P; } int main() { scanf("%d%d%d", &n, &a, &b); if (a > b) swap(a, b); f[1] = f[2] = 1; REP(i, 3, n) { f[i] = f[i - 1]; REP(j, 1, i - a - 1) add(f[i], f[j]); } REP(i, 1, b - 1) g[i][1] = f[i]; REP(i, 1, a - 1) g[i][0] = 1; REP(i, a, b - 1) REP(j, 1, b - 1 - i) add(g[i + j][1], f[j]); REP(i, 1, n) { REP(j, 1, a - 1) add(g[i + j][0], g[i][1]); REP(j, 1, b - 1) add(g[i + j][1], (ll)g[i][0] * f[j]); } int ans = (g[n][0] + g[n][1]) % P; REP(i, a, b - 1) REP(j, 1, b - 1 - i) add(ans, (ll)g[n - i - j][0] * f[j]); ans = (qpow(2, n) - ans) % P; if (ans < 0) ans += P; printf("%d\n", ans); }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #define REP(_i, _a, _n) for (int _i = _a; _i <= _n; ++_i) #define PER(_i, _a, _n) for (int _i = _n; _i >= _a; --_i) #define hr putchar(10) #define pb push_back #define lc (o << 1) #define rc (lc | 1) #define mid ((l + r) >> 1) #define ls lc, l, mid #define rs rc, mid + 1, r #define x first #define y second #define io std::ios::sync_with_stdio(false) #define endl '\n' #define DB(_a) \ ({ \ REP(_i, 1, n) cout << _a[_i] << ','; \ hr; \ }) using namespace std; typedef long long ll; typedef pair<int, int> pii; const int P = 1e9 + 7, INF = 0x3f3f3f3f; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll qpow(ll a, ll n) { ll r = 1 % P; for (a %= P; n; a = a * a % P, n >>= 1) if (n & 1) r = r * a % P; return r; } ll inv(ll x) { return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; } inline int rd() { int x = 0; char p = getchar(); while (p < '0' || p > '9') p = getchar(); while (p >= '0' && p <= '9') x = x * 10 + p - '0', p = getchar(); return x; } // head const int N = 5e3 + 10; int n, a, b, f[N], g[N][2]; void add(int &x, ll y) { x = (x + y) % P; } int main() { scanf("%d%d%d", &n, &a, &b); if (a > b) swap(a, b); f[1] = f[2] = 1; REP(i, 3, n) { f[i] = f[i - 1]; REP(j, 1, i - a - 1) add(f[i], f[j]); } REP(i, 1, b - 1) g[i][1] = f[i]; REP(i, 1, a - 1) g[i][0] = 1; REP(i, a, b - 1) REP(j, 1, b - 1 - i) add(g[i + j][1], f[j]); REP(i, 1, n) { REP(j, 1, min(n - i, a - 1)) add(g[i + j][0], g[i][1]); REP(j, 1, min(n - i, b - 1)) add(g[i + j][1], (ll)g[i][0] * f[j]); } int ans = (g[n][0] + g[n][1]) % P; REP(i, a, b - 1) REP(j, 1, b - 1 - i) add(ans, (ll)g[n - i - j][0] * f[j]); ans = (qpow(2, n) - ans) % P; if (ans < 0) ans += P; printf("%d\n", ans); }
replace
71
73
71
73
0
p02653
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define ll long long #define ull unsigned long long #define rrep(i, m, n) for (ll(i) = (ll)(m); (i) >= (ll)(n); (i)--) #define rep(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); i++) #define REP(i, n) rep(i, 0, n) #define FOR(i, c) \ for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define all(hoge) (hoge).begin(), (hoge).end() typedef pair<ll, ll> P; constexpr long double m_pi = 3.1415926535897932L; constexpr ll MOD = 1000000007; constexpr ll INF = 1LL << 61; constexpr long double EPS = 1e-10; template <typename T> using vector2 = vector<vector<T>>; template <typename T> using vector3 = vector<vector2<T>>; typedef vector<ll> Array; typedef vector<Array> Matrix; string operator*(const string &s, int k) { if (k == 0) return ""; string p = (s + s) * (k / 2); if (k % 2 == 1) p += s; return p; } 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; } struct Edge { // グラフ int to, rev; ll cap; Edge(int _to, ll _cap, int _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) { // 最大フロー求める Ford-fulkerson G[from].push_back(Edge(to, cap, (ll)G[to].size())); if (revFlag) G[to].push_back(Edge( from, revCap, (ll)G[from].size() - 1)); // 最小カットの場合逆辺は0にする } ll max_flow_dfs(Graph &G, ll v, ll t, ll f, vector<bool> &used) { if (v == t) return f; used[v] = true; for (int i = 0; i < G[v].size(); ++i) { Edge &e = G[v][i]; if (!used[e.to] && e.cap > 0) { ll d = max_flow_dfs(G, e.to, t, min(f, e.cap), used); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } // 二分グラフの最大マッチングを求めたりも出来る また二部グラフの最大独立集合は頂点数-最大マッチングのサイズ ll max_flow(Graph &G, ll s, ll t) // O(V(V+E)) { ll flow = 0; for (;;) { vector<bool> used(G.size()); REP(i, used.size()) used[i] = false; ll f = max_flow_dfs(G, s, t, INF, used); if (f == 0) { return flow; } flow += f; } } void BellmanFord(Graph &G, ll s, Array &d, Array &negative) { // O(|E||V|) d.resize(G.size()); negative.resize(G.size()); REP(i, d.size()) d[i] = INF; REP(i, d.size()) negative[i] = false; d[s] = 0; REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; } } } } REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; negative[G[i][j].to] = true; } if (negative[i] == true) negative[G[i][j].to] = true; } } } } void Dijkstra(Graph &G, ll s, Array &d) { // O(|E|log|V|) d.resize(G.size()); REP(i, d.size()) d[i] = INF; d[s] = 0; priority_queue<P, vector<P>, greater<P>> q; q.push(make_pair(0, s)); while (!q.empty()) { P a = q.top(); q.pop(); if (d[a.second] < a.first) continue; REP(i, G[a.second].size()) { Edge e = G[a.second][i]; if (d[e.to] > d[a.second] + e.cap) { d[e.to] = d[a.second] + e.cap; q.push(make_pair(d[e.to], e.to)); } } } } void WarshallFloyd(Graph &G, Matrix &d) { // O(V^3) d.resize(G.size()); REP(i, d.size()) d[i].resize(G.size()); REP(i, d.size()) { REP(j, d[i].size()) { d[i][j] = ((i != j) ? INF : 0); } } REP(i, G.size()) { REP(j, G[i].size()) { chmin(d[i][G[i][j].to], G[i][j].cap); } } REP(i, G.size()) { REP(j, G.size()) { REP(k, G.size()) { chmin(d[j][k], d[j][i] + d[i][k]); } } } } bool tsort(Graph &graph, Array &order) { // トポロジカルソートO(E+V) int n = graph.size(), k = 0; Array in(n); for (auto &es : graph) for (auto &e : es) in[e.to]++; priority_queue<ll, Array, greater<ll>> que; REP(i, n) if (in[i] == 0) que.push(i); while (que.size()) { int v = que.top(); que.pop(); order.push_back(v); for (auto &e : graph[v]) if (--in[e.to] == 0) que.push(e.to); } if (order.size() != n) return false; else return true; } class Lca { public: const int n = 0; const int log2_n = 0; std::vector<std::vector<int>> parent; std::vector<int> depth; Lca() {} Lca(const Graph &g, int root) : n(g.size()), log2_n(log2(n) + 1), parent(log2_n, std::vector<int>(n)), depth(n) { dfs(g, root, -1, 0); for (int k = 0; k + 1 < log2_n; k++) { for (int v = 0; v < (int)g.size(); v++) { if (parent[k][v] < 0) parent[k + 1][v] = -1; else parent[k + 1][v] = parent[k][parent[k][v]]; } } } void dfs(const Graph &g, int v, int p, int d) { parent[0][v] = p; depth[v] = d; for (auto &e : g[v]) { if (e.to != p) dfs(g, e.to, v, d + 1); } } int get(int u, int v) { if (depth[u] > depth[v]) std::swap(u, v); for (int k = 0; k < log2_n; k++) { if ((depth[v] - depth[u]) >> k & 1) { v = parent[k][v]; } } if (u == v) return u; for (int k = log2_n - 1; k >= 0; k--) { if (parent[k][u] != parent[k][v]) { u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } }; class UnionFind { vector<int> data; ll num; public: UnionFind(int size) : data(size, -1), num(size) {} bool unite(int x, int y) { // xとyの集合を統合する x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } num -= (x != y); return x != y; } bool findSet(int x, int y) { // xとyが同じ集合か返す return root(x) == root(y); } int root(int x) { // xのルートを返す return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(int x) { // xの集合のサイズを返す return -data[root(x)]; } ll numSet() { // 集合の数を返す return num; } }; template <typename T, typename F> class SegmentTree { private: T identity; F merge; ll n; vector<T> dat; public: SegmentTree(F f, T id, vector<T> v) : merge(f), identity(id) { int _n = v.size(); n = 1; while (n < _n) n *= 2; dat.resize(2 * n - 1, identity); REP(i, _n) dat[n + i - 1] = v[i]; for (int i = n - 2; i >= 0; i--) dat[i] = merge(dat[i * 2 + 1], dat[i * 2 + 2]); } SegmentTree(F f, T id, int _n) : merge(f), identity(id) { n = 1; while (n < _n) n *= 2; dat.resize(2 * n - 1, identity); } void set_val(int i, T x) { i += n - 1; dat[i] = x; while (i > 0) { i = (i - 1) / 2; dat[i] = merge(dat[i * 2 + 1], dat[i * 2 + 2]); } } T query(int l, int r) { T left = identity, right = identity; l += n - 1; r += n - 1; while (l < r) { if ((l & 1) == 0) left = merge(left, dat[l]); if ((r & 1) == 0) right = merge(dat[r - 1], right); l = l / 2; r = (r - 1) / 2; } return merge(left, right); } }; template <typename T> class FenwickTree { vector<T> data; int n; int p; public: FenwickTree(int n) : n(n) { data.resize(n + 1LL, 0); p = 1; while (p < data.size()) p *= 2; } T sum(int k) { T ret = 0; for (; k > 0; k -= k & -k) ret += data[k]; return (ret); } T sum(int a, int b) { return sum(b) - sum(a); } //[a,b) void add(int k, T x) { for (++k; k <= n; k += k & -k) data[k] += x; } int lower_bound(ll w) { if (w <= 0) return -1; int x = 0; for (int k = p / 2; k > 0; k /= 2) { if (x + k <= n && data[x + k] < w) w -= data[x + k], x += k; } return x; } }; // 約数求める //約数 void divisor(ll n, vector<ll> &ret) { for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); } void prime_factorization(ll n, vector<P> &ret) { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { ret.push_back({i, 0}); while (n % i == 0) { n /= i; ret[ret.size() - 1].second++; } } } if (n != 1) ret.push_back({n, 1}); } inline 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; } inline ll mod_inv(ll x, ll mod) { return mod_pow(x, mod - 2, mod); } class Combination { public: Array fact; Array fact_inv; ll mod; // if n >= mod use lucas ll nCr(ll n, ll r) { if (n < r) return 0; if (n < mod) return ((fact[n] * fact_inv[r] % mod) * fact_inv[n - r]) % mod; ll ret = 1; while (n || r) { ll _n = n % mod, _r = r % mod; n /= mod; r /= mod; (ret *= nCr(_n, _r)) %= mod; } return ret; } ll nPr(ll n, ll r) { return (fact[n] * fact_inv[n - r]) % mod; } ll nHr(ll n, ll r) { return nCr(r + n - 1, r); } Combination(ll _n, ll _mod) { mod = _mod; ll n = min(_n + 1, mod); fact.resize(n); fact[0] = 1; REP(i, n - 1) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; } fact_inv.resize(n); fact_inv[n - 1] = mod_inv(fact[n - 1], mod); for (int i = n - 1; i > 0; i--) { fact_inv[i - 1] = fact_inv[i] * i % mod; } } }; ll popcount(ll x) { x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555); x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333); x = (x & 0x0F0F0F0F0F0F0F0F) + (x >> 4 & 0x0F0F0F0F0F0F0F0F); x = (x & 0x00FF00FF00FF00FF) + (x >> 8 & 0x00FF00FF00FF00FF); x = (x & 0x0000FFFF0000FFFF) + (x >> 16 & 0x0000FFFF0000FFFF); x = (x & 0x00000000FFFFFFFF) + (x >> 32 & 0x00000000FFFFFFFF); return x; } ll dp[5050][2]; ll dp2[5050][2]; ll dp3[5050][2]; int main() { ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); ll n, a, b; cin >> n >> a >> b; if (a > b) swap(a, b); if (a == 1) { cout << mod_pow(2, n, MOD) << "\n"; return 0; } ll ans = mod_pow(2, n, MOD); dp2[1][0] = 1; rep(i, 1, n) { (dp2[i + 1][0] += dp2[i][1] + dp2[i][0]) %= MOD; rep(j, a, n)(dp2[i + j][1] += dp2[i][0]) %= MOD; } dp3[0][0] = 1; REP(i, n) { (dp3[i + 1][0] += dp3[i][1] + dp3[i][0]) %= MOD; rep(j, a, n + 1)(dp3[i + j][1] += dp3[i][0]) %= MOD; } dp[0][0] = 1; dp[0][1] = 1; REP(i, n) { rep(j, 1, a)(dp[i + j][1] += dp[i][0]) %= MOD; rep(j, 1, b) { if (i == 0) { (dp[i + j][0] += dp[i][1] * dp3[j][0] % MOD) %= MOD; if (i + j == n) (dp[i + j][1] += dp[i][1] * dp3[j][1] % MOD) %= MOD; } else { (dp[i + j][0] += dp[i][1] * dp2[j][0] % MOD) %= MOD; if (i + j == n) (dp[i + j][1] += dp[i][1] * dp2[j][1] % MOD) %= MOD; } } } cout << (ans + 2 * MOD - dp[n][0] - dp[n][1]) % MOD << "\n"; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define ll long long #define ull unsigned long long #define rrep(i, m, n) for (ll(i) = (ll)(m); (i) >= (ll)(n); (i)--) #define rep(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); i++) #define REP(i, n) rep(i, 0, n) #define FOR(i, c) \ for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define all(hoge) (hoge).begin(), (hoge).end() typedef pair<ll, ll> P; constexpr long double m_pi = 3.1415926535897932L; constexpr ll MOD = 1000000007; constexpr ll INF = 1LL << 61; constexpr long double EPS = 1e-10; template <typename T> using vector2 = vector<vector<T>>; template <typename T> using vector3 = vector<vector2<T>>; typedef vector<ll> Array; typedef vector<Array> Matrix; string operator*(const string &s, int k) { if (k == 0) return ""; string p = (s + s) * (k / 2); if (k % 2 == 1) p += s; return p; } 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; } struct Edge { // グラフ int to, rev; ll cap; Edge(int _to, ll _cap, int _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) { // 最大フロー求める Ford-fulkerson G[from].push_back(Edge(to, cap, (ll)G[to].size())); if (revFlag) G[to].push_back(Edge( from, revCap, (ll)G[from].size() - 1)); // 最小カットの場合逆辺は0にする } ll max_flow_dfs(Graph &G, ll v, ll t, ll f, vector<bool> &used) { if (v == t) return f; used[v] = true; for (int i = 0; i < G[v].size(); ++i) { Edge &e = G[v][i]; if (!used[e.to] && e.cap > 0) { ll d = max_flow_dfs(G, e.to, t, min(f, e.cap), used); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } // 二分グラフの最大マッチングを求めたりも出来る また二部グラフの最大独立集合は頂点数-最大マッチングのサイズ ll max_flow(Graph &G, ll s, ll t) // O(V(V+E)) { ll flow = 0; for (;;) { vector<bool> used(G.size()); REP(i, used.size()) used[i] = false; ll f = max_flow_dfs(G, s, t, INF, used); if (f == 0) { return flow; } flow += f; } } void BellmanFord(Graph &G, ll s, Array &d, Array &negative) { // O(|E||V|) d.resize(G.size()); negative.resize(G.size()); REP(i, d.size()) d[i] = INF; REP(i, d.size()) negative[i] = false; d[s] = 0; REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; } } } } REP(k, G.size() - 1) { REP(i, G.size()) { REP(j, G[i].size()) { if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) { d[G[i][j].to] = d[i] + G[i][j].cap; negative[G[i][j].to] = true; } if (negative[i] == true) negative[G[i][j].to] = true; } } } } void Dijkstra(Graph &G, ll s, Array &d) { // O(|E|log|V|) d.resize(G.size()); REP(i, d.size()) d[i] = INF; d[s] = 0; priority_queue<P, vector<P>, greater<P>> q; q.push(make_pair(0, s)); while (!q.empty()) { P a = q.top(); q.pop(); if (d[a.second] < a.first) continue; REP(i, G[a.second].size()) { Edge e = G[a.second][i]; if (d[e.to] > d[a.second] + e.cap) { d[e.to] = d[a.second] + e.cap; q.push(make_pair(d[e.to], e.to)); } } } } void WarshallFloyd(Graph &G, Matrix &d) { // O(V^3) d.resize(G.size()); REP(i, d.size()) d[i].resize(G.size()); REP(i, d.size()) { REP(j, d[i].size()) { d[i][j] = ((i != j) ? INF : 0); } } REP(i, G.size()) { REP(j, G[i].size()) { chmin(d[i][G[i][j].to], G[i][j].cap); } } REP(i, G.size()) { REP(j, G.size()) { REP(k, G.size()) { chmin(d[j][k], d[j][i] + d[i][k]); } } } } bool tsort(Graph &graph, Array &order) { // トポロジカルソートO(E+V) int n = graph.size(), k = 0; Array in(n); for (auto &es : graph) for (auto &e : es) in[e.to]++; priority_queue<ll, Array, greater<ll>> que; REP(i, n) if (in[i] == 0) que.push(i); while (que.size()) { int v = que.top(); que.pop(); order.push_back(v); for (auto &e : graph[v]) if (--in[e.to] == 0) que.push(e.to); } if (order.size() != n) return false; else return true; } class Lca { public: const int n = 0; const int log2_n = 0; std::vector<std::vector<int>> parent; std::vector<int> depth; Lca() {} Lca(const Graph &g, int root) : n(g.size()), log2_n(log2(n) + 1), parent(log2_n, std::vector<int>(n)), depth(n) { dfs(g, root, -1, 0); for (int k = 0; k + 1 < log2_n; k++) { for (int v = 0; v < (int)g.size(); v++) { if (parent[k][v] < 0) parent[k + 1][v] = -1; else parent[k + 1][v] = parent[k][parent[k][v]]; } } } void dfs(const Graph &g, int v, int p, int d) { parent[0][v] = p; depth[v] = d; for (auto &e : g[v]) { if (e.to != p) dfs(g, e.to, v, d + 1); } } int get(int u, int v) { if (depth[u] > depth[v]) std::swap(u, v); for (int k = 0; k < log2_n; k++) { if ((depth[v] - depth[u]) >> k & 1) { v = parent[k][v]; } } if (u == v) return u; for (int k = log2_n - 1; k >= 0; k--) { if (parent[k][u] != parent[k][v]) { u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } }; class UnionFind { vector<int> data; ll num; public: UnionFind(int size) : data(size, -1), num(size) {} bool unite(int x, int y) { // xとyの集合を統合する x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } num -= (x != y); return x != y; } bool findSet(int x, int y) { // xとyが同じ集合か返す return root(x) == root(y); } int root(int x) { // xのルートを返す return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(int x) { // xの集合のサイズを返す return -data[root(x)]; } ll numSet() { // 集合の数を返す return num; } }; template <typename T, typename F> class SegmentTree { private: T identity; F merge; ll n; vector<T> dat; public: SegmentTree(F f, T id, vector<T> v) : merge(f), identity(id) { int _n = v.size(); n = 1; while (n < _n) n *= 2; dat.resize(2 * n - 1, identity); REP(i, _n) dat[n + i - 1] = v[i]; for (int i = n - 2; i >= 0; i--) dat[i] = merge(dat[i * 2 + 1], dat[i * 2 + 2]); } SegmentTree(F f, T id, int _n) : merge(f), identity(id) { n = 1; while (n < _n) n *= 2; dat.resize(2 * n - 1, identity); } void set_val(int i, T x) { i += n - 1; dat[i] = x; while (i > 0) { i = (i - 1) / 2; dat[i] = merge(dat[i * 2 + 1], dat[i * 2 + 2]); } } T query(int l, int r) { T left = identity, right = identity; l += n - 1; r += n - 1; while (l < r) { if ((l & 1) == 0) left = merge(left, dat[l]); if ((r & 1) == 0) right = merge(dat[r - 1], right); l = l / 2; r = (r - 1) / 2; } return merge(left, right); } }; template <typename T> class FenwickTree { vector<T> data; int n; int p; public: FenwickTree(int n) : n(n) { data.resize(n + 1LL, 0); p = 1; while (p < data.size()) p *= 2; } T sum(int k) { T ret = 0; for (; k > 0; k -= k & -k) ret += data[k]; return (ret); } T sum(int a, int b) { return sum(b) - sum(a); } //[a,b) void add(int k, T x) { for (++k; k <= n; k += k & -k) data[k] += x; } int lower_bound(ll w) { if (w <= 0) return -1; int x = 0; for (int k = p / 2; k > 0; k /= 2) { if (x + k <= n && data[x + k] < w) w -= data[x + k], x += k; } return x; } }; // 約数求める //約数 void divisor(ll n, vector<ll> &ret) { for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); } void prime_factorization(ll n, vector<P> &ret) { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { ret.push_back({i, 0}); while (n % i == 0) { n /= i; ret[ret.size() - 1].second++; } } } if (n != 1) ret.push_back({n, 1}); } inline 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; } inline ll mod_inv(ll x, ll mod) { return mod_pow(x, mod - 2, mod); } class Combination { public: Array fact; Array fact_inv; ll mod; // if n >= mod use lucas ll nCr(ll n, ll r) { if (n < r) return 0; if (n < mod) return ((fact[n] * fact_inv[r] % mod) * fact_inv[n - r]) % mod; ll ret = 1; while (n || r) { ll _n = n % mod, _r = r % mod; n /= mod; r /= mod; (ret *= nCr(_n, _r)) %= mod; } return ret; } ll nPr(ll n, ll r) { return (fact[n] * fact_inv[n - r]) % mod; } ll nHr(ll n, ll r) { return nCr(r + n - 1, r); } Combination(ll _n, ll _mod) { mod = _mod; ll n = min(_n + 1, mod); fact.resize(n); fact[0] = 1; REP(i, n - 1) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; } fact_inv.resize(n); fact_inv[n - 1] = mod_inv(fact[n - 1], mod); for (int i = n - 1; i > 0; i--) { fact_inv[i - 1] = fact_inv[i] * i % mod; } } }; ll popcount(ll x) { x = (x & 0x5555555555555555) + (x >> 1 & 0x5555555555555555); x = (x & 0x3333333333333333) + (x >> 2 & 0x3333333333333333); x = (x & 0x0F0F0F0F0F0F0F0F) + (x >> 4 & 0x0F0F0F0F0F0F0F0F); x = (x & 0x00FF00FF00FF00FF) + (x >> 8 & 0x00FF00FF00FF00FF); x = (x & 0x0000FFFF0000FFFF) + (x >> 16 & 0x0000FFFF0000FFFF); x = (x & 0x00000000FFFFFFFF) + (x >> 32 & 0x00000000FFFFFFFF); return x; } ll dp[10101][2]; ll dp2[10101][2]; ll dp3[10101][2]; int main() { ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); ll n, a, b; cin >> n >> a >> b; if (a > b) swap(a, b); if (a == 1) { cout << mod_pow(2, n, MOD) << "\n"; return 0; } ll ans = mod_pow(2, n, MOD); dp2[1][0] = 1; rep(i, 1, n) { (dp2[i + 1][0] += dp2[i][1] + dp2[i][0]) %= MOD; rep(j, a, n)(dp2[i + j][1] += dp2[i][0]) %= MOD; } dp3[0][0] = 1; REP(i, n) { (dp3[i + 1][0] += dp3[i][1] + dp3[i][0]) %= MOD; rep(j, a, n + 1)(dp3[i + j][1] += dp3[i][0]) %= MOD; } dp[0][0] = 1; dp[0][1] = 1; REP(i, n) { rep(j, 1, a)(dp[i + j][1] += dp[i][0]) %= MOD; rep(j, 1, b) { if (i == 0) { (dp[i + j][0] += dp[i][1] * dp3[j][0] % MOD) %= MOD; if (i + j == n) (dp[i + j][1] += dp[i][1] * dp3[j][1] % MOD) %= MOD; } else { (dp[i + j][0] += dp[i][1] * dp2[j][0] % MOD) %= MOD; if (i + j == n) (dp[i + j][1] += dp[i][1] * dp2[j][1] % MOD) %= MOD; } } } cout << (ans + 2 * MOD - dp[n][0] - dp[n][1]) % MOD << "\n"; return 0; }
replace
457
460
457
460
0
p02653
C++
Runtime Error
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t x) : x(x >= 0 ? x % mod : (mod - -x % 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 = (int64_t)x * p.x % mod; return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt &operator^=(int64_t p) { ModInt res = 1; for (; p; p >>= 1) { if (p & 1) res *= *this; *this *= *this; } return *this = res; } 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; } ModInt operator^(int64_t 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; } explicit operator int() const { return x; } ModInt &operator=(const int p) { x = p; return *this; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } friend std::ostream &operator<<(std::ostream &stream, const ModInt<mod> &p) { return stream << p.x; } friend std::istream &operator>>(std::istream &stream, ModInt<mod> &a) { int64_t x; stream >> x; a = ModInt<mod>(x); return stream; } }; typedef ModInt<1000000007> mint; template <int mod> struct MComb { using mint = ModInt<mod>; std::vector<mint> fact; std::vector<mint> inv; MComb(int n) { // O(n + log(mod)) fact = std::vector<mint>(n + 1, 1); for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint(i); inv.resize(n + 1); inv[n] = fact[n] ^ (mod - 2); for (int i = n; i--;) inv[i] = inv[i + 1] * mint(i + 1); } mint ncr(int n, int r) { return fact[n] * inv[r] * inv[n - r]; } mint npr(int n, int r) { return fact[n] * inv[n - r]; } mint nhr(int n, int r) { assert(n + r - 1 < (int)fact.size()); return ncr(n + r - 1, r); } }; int main() { // TODO : a == b int n = ri(); int a = ri(), b = ri(); if (a > b) std::swap(a, b); static mint dp[5001][5001][2]; // pos, len, flag dp[0][0][1] = 1; mint diff[n + 1]; mint cur = 0; mint res = 0; for (int i = 0; i <= n; i++) { cur += diff[i]; dp[i][1][1] += cur; mint beki2 = mint(2) ^ (n - i); for (int j = b; j <= n; j++) res += beki2 * (dp[i][j][0] + dp[i][j][1]); if (i == n) break; for (int j = 0; j < b; j++) { if (dp[i][j] == 0) continue; dp[i + 1][j + 1][0] += dp[i][j][0]; dp[i + 1][j + 1][1] += dp[i][j][0]; dp[i + 1][j + 1][1] += dp[i][j][1]; if (i + a <= n) dp[i + a][j + a][0] += dp[i][j][1]; // for (int k = i + 2; k <= n && k <= i + a; k++) dp[k][1][1] += // dp[i][j][1]; if (i + 2 <= n) { diff[i + 2] += dp[i][j][1]; if (i + a + 1 <= n) diff[i + a + 1] -= dp[i][j][1]; } } } /* for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) for (int k = 0; k < 2; k++) if (dp[i][j][k] != 0) { std::cerr << "pos:" << i << " len:" << j << " next:" << k << " : " << dp[i][j][k] << std::endl; }*/ std::cout << res << std::endl; return 0; }
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t x) : x(x >= 0 ? x % mod : (mod - -x % 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 = (int64_t)x * p.x % mod; return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt &operator^=(int64_t p) { ModInt res = 1; for (; p; p >>= 1) { if (p & 1) res *= *this; *this *= *this; } return *this = res; } 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; } ModInt operator^(int64_t 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; } explicit operator int() const { return x; } ModInt &operator=(const int p) { x = p; return *this; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } friend std::ostream &operator<<(std::ostream &stream, const ModInt<mod> &p) { return stream << p.x; } friend std::istream &operator>>(std::istream &stream, ModInt<mod> &a) { int64_t x; stream >> x; a = ModInt<mod>(x); return stream; } }; typedef ModInt<1000000007> mint; template <int mod> struct MComb { using mint = ModInt<mod>; std::vector<mint> fact; std::vector<mint> inv; MComb(int n) { // O(n + log(mod)) fact = std::vector<mint>(n + 1, 1); for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint(i); inv.resize(n + 1); inv[n] = fact[n] ^ (mod - 2); for (int i = n; i--;) inv[i] = inv[i + 1] * mint(i + 1); } mint ncr(int n, int r) { return fact[n] * inv[r] * inv[n - r]; } mint npr(int n, int r) { return fact[n] * inv[n - r]; } mint nhr(int n, int r) { assert(n + r - 1 < (int)fact.size()); return ncr(n + r - 1, r); } }; int main() { // TODO : a == b int n = ri(); int a = ri(), b = ri(); if (a > b) std::swap(a, b); static mint dp[5001][5001][2]; // pos, len, flag dp[0][0][1] = 1; mint diff[n + 1]; mint cur = 0; mint res = 0; for (int i = 0; i <= n; i++) { cur += diff[i]; dp[i][1][1] += cur; mint beki2 = mint(2) ^ (n - i); for (int j = b; j <= n; j++) res += beki2 * (dp[i][j][0] + dp[i][j][1]); if (i == n) break; for (int j = 0; j < b; j++) { if (dp[i][j][0] != 0) { dp[i + 1][j + 1][0] += dp[i][j][0]; dp[i + 1][j + 1][1] += dp[i][j][0]; } if (dp[i][j][1] != 0) { dp[i + 1][j + 1][1] += dp[i][j][1]; if (i + a <= n) dp[i + a][j + a][0] += dp[i][j][1]; // for (int k = i + 2; k <= n && k <= i + a; k++) dp[k][1][1] += // dp[i][j][1]; if (i + 2 <= n) { diff[i + 2] += dp[i][j][1]; if (i + a + 1 <= n) diff[i + a + 1] -= dp[i][j][1]; } } } } /* for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) for (int k = 0; k < 2; k++) if (dp[i][j][k] != 0) { std::cerr << "pos:" << i << " len:" << j << " next:" << k << " : " << dp[i][j][k] << std::endl; }*/ std::cout << res << std::endl; return 0; }
replace
121
134
121
136
-11
p02653
C++
Runtime Error
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> // using i128 = boost::multiprecision::int128_t; #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using ld = long double; using V = vector<int>; using Vll = vector<ll>; using Vld = vector<ld>; using Vbo = vector<bool>; using VV = vector<V>; using VVll = vector<Vll>; using VVld = vector<Vld>; using VVbo = vector<Vbo>; using VVV = vector<VV>; using VVVll = vector<VVll>; using P = pair<int, int>; using Pll = pair<ll, ll>; using Pld = pair<ld, ld>; #define rep2(i, m, n) for (ll i = int(m); i < int(n); ++i) #define drep2(i, m, n) for (ll i = int(m) - 1; i >= int(n); --i) #define rep(i, n) rep2(i, 0, n) #define drep(i, n) drep2(i, n, 0) #define all(a) a.begin(), a.end() struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; } template <typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits const int INF = 1 << 30; const ll INFll = 1ll << 62; const ld EPS = 1e-10; const ld PI = acos(-1.0); const int MOD = int(1e9) + 7; struct mint { ll x; 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 -= a.x) < 0) 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(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint &operator/=(const mint r) { ll a = r.x, b = MOD, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } x = x * u % MOD; if (x < 0) x += MOD; return *this; } mint operator/(const mint a) const { return mint(*this) /= a; } }; // istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } using Vm = vector<mint>; using VVm = vector<Vm>; using VVVm = vector<VVm>; template <typename T> struct Polynomial : vector<T> { using vector<T>::vector; using P = Polynomial; P operator-() const { P res((*this).size()); rep(i, (*this).size()) res[i] = -(*this)[i]; return res; } P &operator+=(const P q) { rep(i, (*this).size()) if (i < q.size())(*this)[i] += q[i]; return *this; } P &operator-=(const P q) { rep(i, (*this).size()) if (i < q.size())(*this)[i] -= q[i]; return *this; } P &operator*=(const P q) { drep(i, (*this).size()) { (*this)[i] *= q[0]; rep2(j, 1, q.size()) if (j <= i)(*this)[i] += q[j] * (*this)[i - j]; } return *this; } P &operator/=(const P q) { rep(i, (*this).size()) { rep2(j, 1, q.size()) if (j <= i)(*this)[i] -= q[j] * (*this)[i - j]; (*this)[i] /= q[0]; } return *this; } P operator+(const P q) const { return P(*this) += q; } P operator-(const P q) const { return P(*this) -= q; } P operator*(const P q) const { return P(*this) *= q; } P operator/(const P q) const { return P(*this) /= q; } P &mul(map<int, T> q) { drep(i, (*this).size()) { (*this)[i] *= q[0]; for (auto &[j, b] : q) if (j != 0 && j <= i) (*this)[i] += b * (*this)[i - j]; } return *this; } P &div(map<int, T> q) { rep(i, (*this).size()) { for (auto &[j, b] : q) if (j != 0 && j <= i) (*this)[i] -= b * (*this)[i - j]; (*this)[i] /= q[0]; } return *this; } // P &div(map<int, T> q) { // rep(i, (*this).size()) { // for (auto &b : q) if (b.first != 0 && b.first <= i) (*this)[i] -= // b.second * (*this)[i-b.first]; // (*this)[i] /= q[0]; // } // return *this; // } }; int main() { ll n, a, b; cin >> n >> a >> b; if (a > b) swap(a, b); Polynomial<mint> p(n + 1), q(n + 1), f(n + 1); p[a] = 1; p.div({{0, 1}, {1, -1}}); q[1] = 1; q.div({{0, 1}, {1, -1}}); f[1] = 1; f[a] -= 1; f.div({{0, 1}, {1, -1}}); auto r = -p * q; r[0] += 1; auto g2 = q / r; auto g1 = q; g1[0] += 1; g1 /= r; auto g0 = p + q; g0[0] += 2; g0 /= r; rep2(i, b, n + 2) g0[i] = 0; rep2(i, b, n + 2) g1[i] = 0; rep2(i, b, n + 2) g2[i] = 0; auto h = f; h *= g1 * g1; auto h0 = -f * g2; h0[0] += 1; h /= h0; h += g0; mint ans = mint(2).pow(n) - h[n]; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> // using i128 = boost::multiprecision::int128_t; #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using ld = long double; using V = vector<int>; using Vll = vector<ll>; using Vld = vector<ld>; using Vbo = vector<bool>; using VV = vector<V>; using VVll = vector<Vll>; using VVld = vector<Vld>; using VVbo = vector<Vbo>; using VVV = vector<VV>; using VVVll = vector<VVll>; using P = pair<int, int>; using Pll = pair<ll, ll>; using Pld = pair<ld, ld>; #define rep2(i, m, n) for (ll i = int(m); i < int(n); ++i) #define drep2(i, m, n) for (ll i = int(m) - 1; i >= int(n); --i) #define rep(i, n) rep2(i, 0, n) #define drep(i, n) drep2(i, n, 0) #define all(a) a.begin(), a.end() struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; } template <typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits const int INF = 1 << 30; const ll INFll = 1ll << 62; const ld EPS = 1e-10; const ld PI = acos(-1.0); const int MOD = int(1e9) + 7; struct mint { ll x; 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 -= a.x) < 0) 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(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint &operator/=(const mint r) { ll a = r.x, b = MOD, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } x = x * u % MOD; if (x < 0) x += MOD; return *this; } mint operator/(const mint a) const { return mint(*this) /= a; } }; // istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } using Vm = vector<mint>; using VVm = vector<Vm>; using VVVm = vector<VVm>; template <typename T> struct Polynomial : vector<T> { using vector<T>::vector; using P = Polynomial; P operator-() const { P res((*this).size()); rep(i, (*this).size()) res[i] = -(*this)[i]; return res; } P &operator+=(const P q) { rep(i, (*this).size()) if (i < q.size())(*this)[i] += q[i]; return *this; } P &operator-=(const P q) { rep(i, (*this).size()) if (i < q.size())(*this)[i] -= q[i]; return *this; } P &operator*=(const P q) { drep(i, (*this).size()) { (*this)[i] *= q[0]; rep2(j, 1, q.size()) if (j <= i)(*this)[i] += q[j] * (*this)[i - j]; } return *this; } P &operator/=(const P q) { rep(i, (*this).size()) { rep2(j, 1, q.size()) if (j <= i)(*this)[i] -= q[j] * (*this)[i - j]; (*this)[i] /= q[0]; } return *this; } P operator+(const P q) const { return P(*this) += q; } P operator-(const P q) const { return P(*this) -= q; } P operator*(const P q) const { return P(*this) *= q; } P operator/(const P q) const { return P(*this) /= q; } P &mul(map<int, T> q) { drep(i, (*this).size()) { (*this)[i] *= q[0]; for (auto &[j, b] : q) if (j != 0 && j <= i) (*this)[i] += b * (*this)[i - j]; } return *this; } P &div(map<int, T> q) { rep(i, (*this).size()) { for (auto &[j, b] : q) if (j != 0 && j <= i) (*this)[i] -= b * (*this)[i - j]; (*this)[i] /= q[0]; } return *this; } // P &div(map<int, T> q) { // rep(i, (*this).size()) { // for (auto &b : q) if (b.first != 0 && b.first <= i) (*this)[i] -= // b.second * (*this)[i-b.first]; // (*this)[i] /= q[0]; // } // return *this; // } }; int main() { ll n, a, b; cin >> n >> a >> b; if (a > b) swap(a, b); Polynomial<mint> p(n + 1), q(n + 1), f(n + 1); p[a] = 1; p.div({{0, 1}, {1, -1}}); q[1] = 1; q.div({{0, 1}, {1, -1}}); f[1] = 1; f[a] -= 1; f.div({{0, 1}, {1, -1}}); auto r = -p * q; r[0] += 1; auto g2 = q / r; auto g1 = q; g1[0] += 1; g1 /= r; auto g0 = p + q; g0[0] += 2; g0 /= r; rep2(i, b, n + 1) g0[i] = 0; rep2(i, b, n + 1) g1[i] = 0; rep2(i, b, n + 1) g2[i] = 0; auto h = f; h *= g1 * g1; auto h0 = -f * g2; h0[0] += 1; h /= h0; h += g0; mint ans = mint(2).pow(n) - h[n]; cout << ans << "\n"; return 0; }
replace
221
224
221
224
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p02654
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 10000005, M = 1e9 + 7; int fac[N], inv[N], f[5005][5005], n, m; inline int ksm(int x, int y) { int ans = 1; for (; y; y >>= 1, x = x * x % M) if (y & 1) (ans *= x) %= M; return ans; } inline int P(int x, int y) { if (x > y) return 1; if (!x) return 0; return fac[y] * inv[x - 1] % M; } inline int C(int x, int y) { if (x < 0) return 1; if (x < y) return 0; return fac[x] * inv[y] % M * inv[x - y] % M; } signed main() { scanf("%lld%lld", &n, &m); fac[0] = 1; for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % M; inv[N - 1] = ksm(fac[N - 1], M - 2); for (int i = N - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % M; n -= m; int ans = 0; for (int i = 1; i <= m + 1; i++) for (int j = 0; j <= m; j++) f[i][j] = ((!j ? 0 : f[i][j - 1]) + inv[j] * fac[i - 2 + n + j]) % M; for (int i = 1; i <= m + 1; i++) for (int j = 0; j < i; j++) { int s = f[i - j][max(0ll, m - i)]; if (j & 1) (ans += M - C(i - 1, j) * (i - j - 1) % M * (i > m ? 1 : fac[m - i]) % M * s % M) %= M; else (ans += C(i - 1, j) * (i - j - 1) % M * (i > m ? 1 : fac[m - i]) % M * s) %= M; } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 20000005, M = 1e9 + 7; int fac[N], inv[N], f[5005][5005], n, m; inline int ksm(int x, int y) { int ans = 1; for (; y; y >>= 1, x = x * x % M) if (y & 1) (ans *= x) %= M; return ans; } inline int P(int x, int y) { if (x > y) return 1; if (!x) return 0; return fac[y] * inv[x - 1] % M; } inline int C(int x, int y) { if (x < 0) return 1; if (x < y) return 0; return fac[x] * inv[y] % M * inv[x - y] % M; } signed main() { scanf("%lld%lld", &n, &m); fac[0] = 1; for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % M; inv[N - 1] = ksm(fac[N - 1], M - 2); for (int i = N - 2; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % M; n -= m; int ans = 0; for (int i = 1; i <= m + 1; i++) for (int j = 0; j <= m; j++) f[i][j] = ((!j ? 0 : f[i][j - 1]) + inv[j] * fac[i - 2 + n + j]) % M; for (int i = 1; i <= m + 1; i++) for (int j = 0; j < i; j++) { int s = f[i - j][max(0ll, m - i)]; if (j & 1) (ans += M - C(i - 1, j) * (i - j - 1) % M * (i > m ? 1 : fac[m - i]) % M * s % M) %= M; else (ans += C(i - 1, j) * (i - j - 1) % M * (i > m ? 1 : fac[m - i]) % M * s) %= M; } printf("%lld\n", ans); }
replace
3
4
3
4
-11
p02654
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 5010, P = 998244353; int n, A, fact[maxn], finv[maxn], inv[maxn]; int main() { scanf("%d %d", &n, &A); fact[0] = finv[0] = inv[0] = inv[1] = 1; for (int i = 1; i <= n; i++) { fact[i] = 1LL * i * fact[i - 1] % P; if (i > 1) inv[i] = 1LL * (P - P / i) * inv[P % i] % P; finv[i] = 1LL * finv[i - 1] * inv[i] % P; } auto C = [&](int x, int y) { return 1LL * fact[x] * finv[y] % P * finv[x - y] % P; }; int ans = 0; for (int t = 2; t <= A + 1; t++) { int a = t - 1, b = n - A, c = max(0, A - t); for (int j = 0; j <= a; j++) { int coef = j & 1 ? P - 1 : 1; ans = (ans + 1LL * coef * C(a, j) % P * (a - j) % P * inv[a - j + b] % P * fact[a - j + b + c]) % P; } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 10000010, P = 1000000007; int n, A, fact[maxn], finv[maxn], inv[maxn]; int main() { scanf("%d %d", &n, &A); fact[0] = finv[0] = inv[0] = inv[1] = 1; for (int i = 1; i <= n; i++) { fact[i] = 1LL * i * fact[i - 1] % P; if (i > 1) inv[i] = 1LL * (P - P / i) * inv[P % i] % P; finv[i] = 1LL * finv[i - 1] * inv[i] % P; } auto C = [&](int x, int y) { return 1LL * fact[x] * finv[y] % P * finv[x - y] % P; }; int ans = 0; for (int t = 2; t <= A + 1; t++) { int a = t - 1, b = n - A, c = max(0, A - t); for (int j = 0; j <= a; j++) { int coef = j & 1 ? P - 1 : 1; ans = (ans + 1LL * coef * C(a, j) % P * (a - j) % P * inv[a - j + b] % P * fact[a - j + b + c]) % P; } } printf("%d\n", ans); return 0; }
replace
3
4
3
4
0
p02654
C++
Runtime Error
#include <cassert> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define N 10000100 const int mod = 1e9 + 7; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return x * f; } int n, A, fac[N], inv[N], ans; int qpow(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = 1LL * ans * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ans; } int init(int n) { fac[0] = 1; for (int i = 1; i <= n; ++i) { fac[i] = 1LL * fac[i - 1] * i % mod; } inv[n] = qpow(fac[n], mod - 2); for (int i = n - 1; i >= 0; --i) { inv[i] = 1LL * inv[i + 1] * (i + 1) % mod; } } inline int C(int n, int m) { return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod; } inline int calc(int a, int b, int c) { return !(a + b) ? 0 : 1LL * fac[a + b + c] * a % mod * inv[a + b] % mod * fac[a + b - 1] % mod; } int main() { n = read(), A = read(); init(n); for (int i = 1; i <= A + 1; ++i) { for (int j = 0; j < i; ++j) { ans = (ans + (j & 1 ? -1 : 1) * 1LL * C(i - 1, j) * calc(i - j - 1, n - A, max(0, A - i)) % mod + mod) % mod; } } printf("%d\n", ans); return 0; }
#include <cassert> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define N 10000100 const int mod = 1e9 + 7; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return x * f; } int n, A, fac[N], inv[N], ans; int qpow(int a, int b) { int ans = 1; while (b) { if (b & 1) ans = 1LL * ans * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ans; } void init(int n) { fac[0] = 1; for (int i = 1; i <= n; ++i) { fac[i] = 1LL * fac[i - 1] * i % mod; } inv[n] = qpow(fac[n], mod - 2); for (int i = n - 1; i >= 0; --i) { inv[i] = 1LL * inv[i + 1] * (i + 1) % mod; } } inline int C(int n, int m) { return 1LL * fac[n] * inv[m] % mod * inv[n - m] % mod; } inline int calc(int a, int b, int c) { return !(a + b) ? 0 : 1LL * fac[a + b + c] * a % mod * inv[a + b] % mod * fac[a + b - 1] % mod; } int main() { n = read(), A = read(); init(n); for (int i = 1; i <= A + 1; ++i) { for (int j = 0; j < i; ++j) { ans = (ans + (j & 1 ? -1 : 1) * 1LL * C(i - 1, j) * calc(i - j - 1, n - A, max(0, A - i)) % mod + mod) % mod; } } printf("%d\n", ans); return 0; }
replace
32
33
32
33
0
p02656
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define ld long double #define db double #define pint pair<int, int> #define mk(x, y) make_pair(x, y) #define pb(x) push_back(x) #define eb(x, y) emplace_back(x, y) #define fi first #define se second #define Rep(x, y, z) for (int x = y; x <= z; x++) #define Red(x, y, z) for (int x = y; x >= z; x--) using namespace std; const int MAXN = 2e5 + 5; char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc; int ny; inline char gc() { return pp1 == pp2 && (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2) ? EOF : *pp1++; } // inline char gc(){return getchar();} inline int read() { int x = 0; for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;) if (nc == 45) ny = -1; if (nc < 0) return nc; for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF; x = (x << 3) + (x << 1) + (nc ^ 48)) ; return x * ny; } int a, b, c, x, y, top; inline void exgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1, y = 0; return; } exgcd(b, a % b, y, x), y -= a / b * x; } inline int inv(int x, int p) { int a = 0, b = 0; exgcd(x, p, a, b); return (a % p + p) % p; } struct Node { int x, y, c; } q[MAXN]; inline void work(int c, int d) { q[top = 0] = (Node){0, 0, 0}; for (int x, a = 1, b = 0; d;) { Node tmp = q[top]; q[++top] = (Node){tmp.x + c / d * a, tmp.y + c / d * d, c / d}; Rep(t, 1, 2) { if (t == 1) b += c / d * a; else a += c / d * b; x = c % d, c = d, d = x; } } } inline ll F(ll x, ll y) { return x < 0 ? -1 : x / y; } int main() { // freopen("std.in","r",stdin); // freopen("std.out","w",stdout); for (int t = read(); t--;) { a = read(), x = read(), b = read(), y = read(), c = read(); int g = __gcd(a, b); a /= g, b /= g, c /= __gcd(c, g); g = __gcd(a, c), a /= g, c /= g, y /= g, g = __gcd(b, c), b /= g, c /= g, x /= g; a %= c, b %= c; if (c == 1) { cout << x + y << '\n'; continue; } int d = 1ll * a * inv(b, c) % c; work(c, d); if (q[top].x != c) q[++top] = (Node){c, c, 1}; int ans = 0; Rep(i, 1, top) { int lx = q[i - 1].x, rx = q[i].x, ly = c - q[i - 1].y, ry = c - q[i].y, dx = (rx - lx) / q[i].c, dy = (ly - ry) / q[i].c, l = ans + 1, r = x + y; while (l <= r) { int mid = 0ll + l + r >> 1; ll s = F(x - 1ll * mid * lx, dx), t = F(y - 1ll * mid * ry, dy); if (s >= 0 && t >= 0 && s + t >= 1ll * mid * q[i].c) ans = mid, l = mid + 1; else r = mid - 1; } } cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> #define ll long long #define ld long double #define db double #define pint pair<int, int> #define mk(x, y) make_pair(x, y) #define pb(x) push_back(x) #define eb(x, y) emplace_back(x, y) #define fi first #define se second #define Rep(x, y, z) for (int x = y; x <= z; x++) #define Red(x, y, z) for (int x = y; x >= z; x--) using namespace std; const int MAXN = 2e5 + 5; char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc; int ny; inline char gc() { return pp1 == pp2 && (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2) ? EOF : *pp1++; } // inline char gc(){return getchar();} inline int read() { int x = 0; for (ny = 1; nc = gc(), (nc < 48 || nc > 57) && nc != EOF;) if (nc == 45) ny = -1; if (nc < 0) return nc; for (x = nc - 48; nc = gc(), 47 < nc && nc < 58 && nc != EOF; x = (x << 3) + (x << 1) + (nc ^ 48)) ; return x * ny; } int a, b, c, x, y, top; inline void exgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1, y = 0; return; } exgcd(b, a % b, y, x), y -= a / b * x; } inline int inv(int x, int p) { int a = 0, b = 0; exgcd(x, p, a, b); return (a % p + p) % p; } struct Node { int x, y, c; } q[MAXN]; inline void work(int c, int d) { q[top = 0] = (Node){0, 0, 0}; for (int x, a = 1, b = 0; d;) { Node tmp = q[top]; q[++top] = (Node){tmp.x + c / d * a, tmp.y + c / d * d, c / d}; for (int t = 1; t <= 2 && d != 0; t++) { if (t == 1) b += c / d * a; else a += c / d * b; x = c % d, c = d, d = x; } } } inline ll F(ll x, ll y) { return x < 0 ? -1 : x / y; } int main() { // freopen("std.in","r",stdin); // freopen("std.out","w",stdout); for (int t = read(); t--;) { a = read(), x = read(), b = read(), y = read(), c = read(); int g = __gcd(a, b); a /= g, b /= g, c /= __gcd(c, g); g = __gcd(a, c), a /= g, c /= g, y /= g, g = __gcd(b, c), b /= g, c /= g, x /= g; a %= c, b %= c; if (c == 1) { cout << x + y << '\n'; continue; } int d = 1ll * a * inv(b, c) % c; work(c, d); if (q[top].x != c) q[++top] = (Node){c, c, 1}; int ans = 0; Rep(i, 1, top) { int lx = q[i - 1].x, rx = q[i].x, ly = c - q[i - 1].y, ry = c - q[i].y, dx = (rx - lx) / q[i].c, dy = (ly - ry) / q[i].c, l = ans + 1, r = x + y; while (l <= r) { int mid = 0ll + l + r >> 1; ll s = F(x - 1ll * mid * lx, dx), t = F(y - 1ll * mid * ry, dy); if (s >= 0 && t >= 0 && s + t >= 1ll * mid * q[i].c) ans = mid, l = mid + 1; else r = mid - 1; } } cout << ans << '\n'; } return 0; }
replace
56
57
56
57
0
p02656
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> #include <vector> #define debug(...) fprintf(stderr, __VA_ARGS__) using namespace std; inline char gc() { // return getchar(); static char buf[100000], *l = buf, *r = buf; return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r) ? EOF : *l++; } template <class T> void rd(T &x) { scanf("%d", &x); return; x = 0; int f = 1, ch = gc(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = gc(); } while (ch >= '0' && ch <= '9') { x = x * 10 - '0' + ch; ch = gc(); } x *= f; } template <class T> inline bool Cmax(T &x, T y) { return x < y ? x = y, 1 : 0; } typedef long long ll; int T, A, X, B, Y, C, D; vector<int> pos, cnt; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int exgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1, y = 0; return a; } int d = exgcd(b, a % b, y, x); y -= a / b * x; return d; } inline int inver(int a, int mod) { int x, y, d = exgcd(a, mod, x, y); if (x < 0) x += mod; return x; } inline ll lowdiv(ll a, ll b) { return a / b - (a % b && (a ^ b) < 0); } void init() { int d = gcd(A, B); A /= d, B /= d, C /= gcd(d, C); for (int _ = 0; _ < 2; ++_) { d = gcd(A, C); C /= d, A /= d; int t = gcd(B, d); B /= t, Y /= d / t; swap(A, B), swap(X, Y); } } void getpos() { pos.clear(), cnt.clear(); int W = C, H = D, now = 0, r = inver(D, C); while (W) { int d = W / H; pos.push_back((ll)now * r % C), cnt.push_back(d); now += d * H; W %= H; if (W == 0) break; H %= W; if (H == 0) H = W; } pos.push_back(C); } inline int gety(int x) { return x == 0 ? C : (C - (ll)x * D % C) % C; } int main() { // freopen("1.in","r",stdin); // freopen("1.out","w",stdout); rd(T); for (int kase = 1; kase <= T; ++kase) { rd(A), rd(X), rd(B), rd(Y), rd(C); init(); if (C == 1) { printf("%d\n", X + Y); continue; } D = (ll)A * inver(B, C) % C; getpos(); int an = 0; for (int i = 0; i < cnt.size(); ++i) { int xl = pos[i], xr = pos[i + 1], yl = gety(xl), yr = gety(xr); int dx = (xr - xl) / cnt[i], dy = (yl - yr) / cnt[i]; int l = 0, r = X + Y, re = -1; while (l <= r) { int mid = (l + r) >> 1; ll p = lowdiv(X - (ll)xl * mid, dx), q = lowdiv(Y - (ll)yr * mid, dy); if (p >= 0 && q >= 0 && p + q >= (ll)cnt[i] * mid) re = mid, l = mid + 1; else r = mid - 1; } Cmax(an, re); } printf("%d\n", an); } return 0; }
#include <cstdio> #include <iostream> #include <vector> #define debug(...) fprintf(stderr, __VA_ARGS__) using namespace std; inline char gc() { // return getchar(); static char buf[100000], *l = buf, *r = buf; return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r) ? EOF : *l++; } template <class T> void rd(T &x) { scanf("%d", &x); return; x = 0; int f = 1, ch = gc(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = gc(); } while (ch >= '0' && ch <= '9') { x = x * 10 - '0' + ch; ch = gc(); } x *= f; } template <class T> inline bool Cmax(T &x, T y) { return x < y ? x = y, 1 : 0; } typedef long long ll; int T, A, X, B, Y, C, D; vector<int> pos, cnt; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int exgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1, y = 0; return a; } int d = exgcd(b, a % b, y, x); y -= a / b * x; return d; } inline int inver(int a, int mod) { int x, y, d = exgcd(a, mod, x, y); if (x < 0) x += mod; return x; } inline ll lowdiv(ll a, ll b) { return a / b - (a % b && (a ^ b) < 0); } void init() { int d = gcd(A, B); A /= d, B /= d, C /= gcd(d, C); for (int _ = 0; _ < 2; ++_) { d = gcd(A, C); C /= d, A /= d; int t = gcd(B, d); B /= t, Y /= d / t; swap(A, B), swap(X, Y); } } void getpos() { pos.clear(), cnt.clear(); int W = C, H = D, now = 0, r = inver(D, C); while (W) { int d = W / H; pos.push_back((ll)now * r % C), cnt.push_back(d); now += d * H; W %= H; if (W == 0) break; H %= W; if (H == 0) H = W; } pos.push_back(C); } inline int gety(int x) { return x == 0 ? C : (C - (ll)x * D % C) % C; } int main() { // freopen("1.in","r",stdin); // freopen("1.out","w",stdout); rd(T); for (int kase = 1; kase <= T; ++kase) { rd(A), rd(X), rd(B), rd(Y), rd(C); init(); if (C == 1) { printf("%d\n", X + Y); continue; } D = (ll)A * inver(B, C) % C; getpos(); int an = 0; for (int i = 0; i < cnt.size(); ++i) { int xl = pos[i], xr = pos[i + 1], yl = gety(xl), yr = gety(xr); int dx = (xr - xl) / cnt[i], dy = (yl - yr) / cnt[i]; int l = 0, r = X + Y, re = -1; while (l <= r) { int mid = ((ll)l + r) >> 1; ll p = lowdiv(X - (ll)xl * mid, dx), q = lowdiv(Y - (ll)yr * mid, dy); if (p >= 0 && q >= 0 && p + q >= (ll)cnt[i] * mid) re = mid, l = mid + 1; else r = mid - 1; } Cmax(an, re); } printf("%d\n", an); } return 0; }
replace
96
97
96
97
TLE
p02656
C++
Runtime Error
#include <bits/stdc++.h> #define For(i, x, y) for (register int i = (x); i <= (y); i++) #define FOR(i, x, y) for (register int i = (x); i < (y); i++) #define Dow(i, x, y) for (register int i = (x); i >= (y); i--) #define Debug(v) \ for (auto i : v) \ printf("%lld ", i); \ puts("") #define mp make_pair #define fi first #define se second #define pb push_back #define ep emplace_back #define siz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define fil(a, b) memset((a), (b), sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pa; typedef pair<ll, ll> PA; typedef vector<int> poly; inline ll read() { ll x = 0, f = 1; char c = getchar(); while ((c < '0' || c > '9') && (c != '-')) c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } inline int exgcd(int a, int b, int &x, int &y) { if (!b) return x = 1, y = 0, a; int g = exgcd(b, a % b, y, x); return y -= a / b * x, g; } inline int inv(int A, int mod) { int x, y; exgcd(A, mod, x, y); return x < 0 ? x + mod : x; } int A, B, C, D, X, Y; inline void init() { int g = __gcd(__gcd(A, B), C); A /= g, B /= g, C /= g; g = __gcd(A, C), Y /= g, C /= g, A /= g; g = __gcd(B, C), X /= g, C /= g, B /= g; } vector<int> x, cnt; inline void Get() { D = 1ll * A * inv(B, C) % C, x.clear(), cnt.clear(); int W = C, H = D, now = 0, invD = inv(D, C); while (W) { int tmp = W / H; cnt.pb(tmp), x.pb(1ll * now * invD % C), now += tmp * H; W %= H; if (!W) break; H %= W; if (H == 0) H = W; } x.pb(C), cnt.pb(0); } inline ll Div(ll x, ll y) { return x / y - (x % y && (x ^ y) < 0); } inline int Get(int x) { return x == 0 ? C : (C - 1ll * x * D % C) % C; } inline void solve() { A = read(), X = read(), B = read(), Y = read(), C = read(); init(), Get(); ll ans = 0; FOR(i, 0, siz(x) - 1) { int lx = x[i], ly = Get(lx), rx = x[i + 1], ry = Get(rx), dx = (rx - lx) / cnt[i], dy = (ly - ry) / cnt[i]; ll l = 0, r = X + Y, ret = 0; while (l <= r) { ll mid = l + r >> 1; if (X - mid * lx >= 0 && Y - mid * ry >= 0) { ll a = (X - mid * lx) / dx, b = (Y - mid * ry) / dy; if (a >= 0 && b >= 0 && a + b >= mid * cnt[i]) l = mid + 1, ret = mid; else r = mid - 1; } else r = mid - 1; } ans = max(ans, ret); } printf("%lld\n", ans); } int main() { int T = read(); while (T--) solve(); }
#include <bits/stdc++.h> #define For(i, x, y) for (register int i = (x); i <= (y); i++) #define FOR(i, x, y) for (register int i = (x); i < (y); i++) #define Dow(i, x, y) for (register int i = (x); i >= (y); i--) #define Debug(v) \ for (auto i : v) \ printf("%lld ", i); \ puts("") #define mp make_pair #define fi first #define se second #define pb push_back #define ep emplace_back #define siz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define fil(a, b) memset((a), (b), sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pa; typedef pair<ll, ll> PA; typedef vector<int> poly; inline ll read() { ll x = 0, f = 1; char c = getchar(); while ((c < '0' || c > '9') && (c != '-')) c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } inline int exgcd(int a, int b, int &x, int &y) { if (!b) return x = 1, y = 0, a; int g = exgcd(b, a % b, y, x); return y -= a / b * x, g; } inline int inv(int A, int mod) { int x, y; exgcd(A, mod, x, y); return x < 0 ? x + mod : x; } int A, B, C, D, X, Y; inline void init() { int g = __gcd(__gcd(A, B), C); A /= g, B /= g, C /= g; g = __gcd(A, C), Y /= g, C /= g, A /= g; g = __gcd(B, C), X /= g, C /= g, B /= g; } vector<int> x, cnt; inline void Get() { D = 1ll * A * inv(B, C) % C, x.clear(), cnt.clear(); int W = C, H = D, now = 0, invD = inv(D, C); while (W) { int tmp = W / H; cnt.pb(tmp), x.pb(1ll * now * invD % C), now += tmp * H; W %= H; if (!W) break; H %= W; if (H == 0) H = W; } x.pb(C), cnt.pb(0); } inline ll Div(ll x, ll y) { return x / y - (x % y && (x ^ y) < 0); } inline int Get(int x) { return x == 0 ? C : (C - 1ll * x * D % C) % C; } inline void solve() { A = read(), X = read(), B = read(), Y = read(), C = read(); init(); if (C == 1) return printf("%d\n", X + Y), void(0); Get(); ll ans = 0; FOR(i, 0, siz(x) - 1) { int lx = x[i], ly = Get(lx), rx = x[i + 1], ry = Get(rx), dx = (rx - lx) / cnt[i], dy = (ly - ry) / cnt[i]; ll l = 0, r = X + Y, ret = 0; while (l <= r) { ll mid = l + r >> 1; if (X - mid * lx >= 0 && Y - mid * ry >= 0) { ll a = (X - mid * lx) / dx, b = (Y - mid * ry) / dy; if (a >= 0 && b >= 0 && a + b >= mid * cnt[i]) l = mid + 1, ret = mid; else r = mid - 1; } else r = mid - 1; } ans = max(ans, ret); } printf("%lld\n", ans); } int main() { int T = read(); while (T--) solve(); }
replace
74
75
74
78
0
p02657
Python
Runtime Error
a, b = map(int, input().ssplit()) print(a * b)
a, b = map(int, input().split()) print(a * b)
replace
0
1
0
1
AttributeError: 'str' object has no attribute 'ssplit'. Did you mean: 'rsplit'?
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s218726646.py", line 1, in <module> a, b = map(int, input().ssplit()) AttributeError: 'str' object has no attribute 'ssplit'. Did you mean: 'rsplit'?
p02657
Python
Runtime Error
def main(): arg = int(input()) ans = arg + arg**2 + arg**3 print(str(ans)) if __name__ == "__main__": main()
def main(): a, b = (int(i) for i in input().split()) print(str(a * b)) if __name__ == "__main__": main()
replace
1
4
1
3
ValueError: invalid literal for int() with base 10: '2 5'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s552791215.py", line 8, in <module> main() File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s552791215.py", line 2, in main arg = int(input()) ValueError: invalid literal for int() with base 10: '2 5'
p02657
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int a, b; cin >> a >> b; return a * b; }
#include <iostream> #include <string> using namespace std; int main() { int a, b; cin >> a >> b; cout << a * b << endl; return 0; }
replace
7
8
7
10
10
p02657
Python
Runtime Error
a, t = map(int, input().split()) print(a * t) a, t = map(int, input().split()) print(a * t)
a, t = map(int, input().split()) print(a * t)
delete
2
4
2
2
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s987059931.py", line 3, in <module> a, t = map(int, input().split()) EOFError: EOF when reading a line
p02657
Python
Runtime Error
x, y = input().split() print(x * y)
x, y = map(int, input().split()) print(x * y)
replace
0
1
0
1
TypeError: can't multiply sequence by non-int of type 'str'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s474601082.py", line 2, in <module> print(x * y) TypeError: can't multiply sequence by non-int of type 'str'
p02657
Python
Runtime Error
val1 = input() val2 = input() print(int(val1) * int(val2))
val1, val2 = (int(x) for x in input().split()) print(int(val1) * int(val2))
replace
0
2
0
1
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s139420322.py", line 2, in <module> val2 = input() EOFError: EOF when reading a line
p02657
Python
Runtime Error
a, b = [*map(input().split(" "), int)] print(a * b)
a, b = [*map(int, input().split(" "))] print(a * b)
replace
0
1
0
1
TypeError: 'type' object is not iterable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s795495503.py", line 1, in <module> a, b = [*map(input().split(" "), int)] TypeError: 'type' object is not iterable
p02657
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; return a * b; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << a * b << endl; }
replace
5
6
5
6
10
p02657
C++
Runtime Error
#include "bits/stdc++.h" #define endl '\n' using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0); int A, B; cin >> A; cin >> B; cout << A * B; return A * B; }
#include "bits/stdc++.h" #define endl '\n' using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0); int A, B; cin >> A; cin >> B; cout << A * B; return 0; }
replace
11
12
11
12
10
p02657
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; return a * b; }
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a * b << endl; return 0; }
replace
6
7
6
8
10
p02657
C++
Runtime Error
#include <algorithm> #include <deque> #include <functional> #include <iostream> #include <map> #include <math.h> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define ll long long using namespace std; int main() { int A, B; cin >> A >> B; return A * B; }
#include <algorithm> #include <deque> #include <functional> #include <iostream> #include <map> #include <math.h> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define ll long long using namespace std; int main() { int A, B; cin >> A >> B; cout << A * B << endl; }
replace
19
20
19
20
10
p02657
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; return a * b; }
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a * b << endl; }
replace
7
8
7
8
10
p02657
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; return a * b; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; cout << a * b << endl; return 0; }
replace
6
7
6
7
10
p02657
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int A, B; scanf("%i%i", A, B); printf("%i", A * B); }
#include <bits/stdc++.h> using namespace std; int main() { int A, B; cin >> A >> B; cout << A * B << endl; }
replace
5
7
5
7
-11
p02657
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; return a * b; }
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a * b << endl; return 0; }
replace
6
7
6
9
10
p02657
C++
Memory Limit Exceeded
#include <bits/stdc++.h> using namespace std; using lint = long long; vector<lint> test(1024 * 1024 * 127); int main() { int a, b; cin >> a >> b; cout << a * b << endl; }
#include <bits/stdc++.h> using namespace std; using lint = long long; vector<bool> test(1024 * 1024 * 1024); int main() { int a, b; cin >> a >> b; cout << a * b << endl; }
replace
4
5
4
5
MLE
p02657
C++
Runtime Error
#include <stdio.h> int main() { int a, b; scanf("%d%d", &a, &b); printf("%n", a * b); return 0; }
#include <stdio.h> int main() { int a, b; scanf("%d%d", &a, &b); printf("%d\n", a * b); return 0; }
replace
4
5
4
5
-11
p02657
Python
Runtime Error
a, b = int(input().split()) print(a * b)
a, b = map(int, input().split()) print(a * b)
replace
0
1
0
1
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02657/Python/s298903403.py", line 1, in <module> a, b = int(input().split()) TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
p02657
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int A, B; cin >> A >> B; return A * B; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B; cin >> A >> B; cout << A * B << endl; }
replace
6
7
6
7
10
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long N; unsigned long long ans = 1; cin >> N; bool zero = false; bool ng = false; for (long long i = 0; i < N; i++) { unsigned long long tmp; cin >> tmp; if (tmp == 0) { zero = true; } if (!zero && 1000000000000000000 / ans < tmp) { ng = true; } ans *= tmp; } if (zero) { cout << 0 << endl; } else if (ng) { cout << -1 << endl; } else { cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long N; unsigned long long ans = 1; cin >> N; bool zero = false; bool ng = false; for (long long i = 0; i < N; i++) { unsigned long long tmp; cin >> tmp; if (tmp == 0) { zero = true; } if (!zero && 1000000000000000000 / ans < tmp) { ng = true; } if (!zero && !ng) { ans *= tmp; } } if (zero) { cout << 0 << endl; } else if (ng) { cout << -1 << endl; } else { cout << ans << endl; } }
replace
19
20
19
22
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> V(n); for (int i = 0; i < n; i++) cin >> V[i]; long long product = 1; long long val = 1e18; sort(V.begin(), V.end()); for (int i = 0; i < n; i++) { if (product == 0) { cout << 0; return 0; } if (product <= (val / V[i])) product *= V[i]; else { cout << -1; return 0; } } cout << product; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long long> V(n); for (int i = 0; i < n; i++) cin >> V[i]; long long product = 1; long long val = 1e18; sort(V.begin(), V.end()); for (int i = 0; i < n; i++) { if (V[i] == 0) { cout << 0; return 0; } if (product <= (val / V[i])) product *= V[i]; else { cout << -1; return 0; } } cout << product; }
replace
12
13
12
13
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; mt19937_64 rng(58); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; long long ans = 1; bool larger = false; for (int i = 0; i < n; i++) { long long a; cin >> a; cerr << (1000000000000000001ll) / ans << '\n'; if (a >= (1000000000000000001ll) / ans + (1000000000000000001ll % ans > 0)) { larger = true; } else { ans *= a; } } if (ans != 0 && larger) { cout << -1 << '\n'; } else { cout << ans << '\n'; } }
#include <bits/stdc++.h> using namespace std; mt19937_64 rng(58); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; long long ans = 1; bool larger = false; for (int i = 0; i < n; i++) { long long a; cin >> a; if (ans && a >= (1000000000000000001ll) / ans + (1000000000000000001ll % ans > 0)) { larger = true; } else { ans *= a; } } if (ans != 0 && larger) { cout << -1 << '\n'; } else { cout << ans << '\n'; } }
replace
16
19
16
18
0
1000000000000000001 1000000000
p02658
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define num1 1000000007 #define num2 998244353 #define REP(i, a, n) for (ll i = a; i < n; i++) #define REPd(i, a, n) for (ll i = a; i >= n; i--) #define vll vector<long long> #define pll pair<long long, long long> #define vpll vector<pair<long long, long long>> #define pb push_back #define pob pop_back #define f first #define s second #define fix(f, n) std::fixed << std::setprecision(n) << f #define all(x) x.begin(), x.end() #define M_PI 3.14159265358979323846 #define epsilon (double)(0.00000000001) #define mm 1000000000000000000ll #define watch(x) cerr << (#x) << " is " << (x) << endl typedef long long ll; // DEBUG FUNCTIONS FOR TEST #ifndef ONLINE_JUDGE #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } template <typename T> void __p(T a) { cout << a; } template <typename T, typename F> void __p(pair<T, F> a) { cout << "{"; __p(a.first); cout << ","; __p(a.second); cout << "}"; } template <typename T> void __p(std::vector<T> a) { cout << "{"; for (auto it = a.begin(); it < a.end(); it++) __p(*it), cout << ",}"[it + 1 == a.end()]; } template <typename T, typename... Arg> void __p(T a1, Arg... a) { __p(a1); __p(a...); } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : "; __p(arg1); cout << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { int bracket = 0, i = 0; for (;; i++) if (names[i] == ',' && bracket == 0) break; else if (names[i] == '(') bracket++; else if (names[i] == ')') bracket--; const char *comma = names + i; cout.write(names, comma - names) << " : "; __p(arg1); cout << " | "; __f(comma + 1, args...); } #define trace(...) \ cout << "Line:" << __LINE__ << " ", __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) #define error(...) #define endl '\n' #endif // DEBUG FUNCTIONS END ll mod_exp(ll a, ll b, ll c) { ll res = 1; a = a % c; while (b > 0) { if (b % 2 == 1) { res = (res * a) % c; } b /= 2; a = (a * a) % c; } return res; } ll mymod(ll a, ll b) { return ((a % b) + b) % b; } // bool prime[200001]; // void SieveOfEratosthenes() // { // memset(prime, true, sizeof(prime)); // prime[1]=false; // for (int p=2; p*p<=200000; p++) // { // if (prime[p] == true) // { // for (int i=p*p; i<=200000; i += p) // prime[i] = false; // } // } // return; // } // ll powe[200005]; // void power() // { // powe[0]=1; // REP(i,1,200005) // { // powe[i]=mymod(2*powe[i-1],num); // } // } // ll gcdExtended(ll,ll,ll *,ll *); // ll modInverse(ll a, ll m) // { // ll x, y; // ll g = gcdExtended(a, m, &x, &y); // ll res = (x%m + m) % m; // return res; // } // ll gcdExtended(ll a, ll b, ll *x, ll *y) // { // if (a == 0) // { // *x = 0, *y = 1; // return b; // } // ll x1, y1; // ll gcd = gcdExtended(b%a, a, &x1, &y1); // *x = y1 - (b/a) * x1; // *y = x1; // return gcd; // } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; ll A[n]; ll ans = 1; bool z = false; bool exc = false; REP(i, 0, n) { cin >> A[i]; if (A[i] == 0) { z = true; } if (A[i] >= mm / ans + 1) { exc = true; } else { ans *= A[i]; } if (ans > mm) { exc = true; } } if (z) { cout << "0\n"; } else if (exc) { cout << "-1\n"; } else { cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define num1 1000000007 #define num2 998244353 #define REP(i, a, n) for (ll i = a; i < n; i++) #define REPd(i, a, n) for (ll i = a; i >= n; i--) #define vll vector<long long> #define pll pair<long long, long long> #define vpll vector<pair<long long, long long>> #define pb push_back #define pob pop_back #define f first #define s second #define fix(f, n) std::fixed << std::setprecision(n) << f #define all(x) x.begin(), x.end() #define M_PI 3.14159265358979323846 #define epsilon (double)(0.00000000001) #define mm 1000000000000000000ll #define watch(x) cerr << (#x) << " is " << (x) << endl typedef long long ll; // DEBUG FUNCTIONS FOR TEST #ifndef ONLINE_JUDGE #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } template <typename T> void __p(T a) { cout << a; } template <typename T, typename F> void __p(pair<T, F> a) { cout << "{"; __p(a.first); cout << ","; __p(a.second); cout << "}"; } template <typename T> void __p(std::vector<T> a) { cout << "{"; for (auto it = a.begin(); it < a.end(); it++) __p(*it), cout << ",}"[it + 1 == a.end()]; } template <typename T, typename... Arg> void __p(T a1, Arg... a) { __p(a1); __p(a...); } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : "; __p(arg1); cout << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { int bracket = 0, i = 0; for (;; i++) if (names[i] == ',' && bracket == 0) break; else if (names[i] == '(') bracket++; else if (names[i] == ')') bracket--; const char *comma = names + i; cout.write(names, comma - names) << " : "; __p(arg1); cout << " | "; __f(comma + 1, args...); } #define trace(...) \ cout << "Line:" << __LINE__ << " ", __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) #define error(...) #define endl '\n' #endif // DEBUG FUNCTIONS END ll mod_exp(ll a, ll b, ll c) { ll res = 1; a = a % c; while (b > 0) { if (b % 2 == 1) { res = (res * a) % c; } b /= 2; a = (a * a) % c; } return res; } ll mymod(ll a, ll b) { return ((a % b) + b) % b; } // bool prime[200001]; // void SieveOfEratosthenes() // { // memset(prime, true, sizeof(prime)); // prime[1]=false; // for (int p=2; p*p<=200000; p++) // { // if (prime[p] == true) // { // for (int i=p*p; i<=200000; i += p) // prime[i] = false; // } // } // return; // } // ll powe[200005]; // void power() // { // powe[0]=1; // REP(i,1,200005) // { // powe[i]=mymod(2*powe[i-1],num); // } // } // ll gcdExtended(ll,ll,ll *,ll *); // ll modInverse(ll a, ll m) // { // ll x, y; // ll g = gcdExtended(a, m, &x, &y); // ll res = (x%m + m) % m; // return res; // } // ll gcdExtended(ll a, ll b, ll *x, ll *y) // { // if (a == 0) // { // *x = 0, *y = 1; // return b; // } // ll x1, y1; // ll gcd = gcdExtended(b%a, a, &x1, &y1); // *x = y1 - (b/a) * x1; // *y = x1; // return gcd; // } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; ll A[n]; ll ans = 1; bool z = false; bool exc = false; REP(i, 0, n) { cin >> A[i]; if (A[i] == 0) { z = true; } if (!z && A[i] >= mm / ans + 1) { exc = true; } else { ans *= A[i]; } if (ans > mm) { exc = true; } } if (z) { cout << "0\n"; } else if (exc) { cout << "-1\n"; } else { cout << ans << "\n"; } return 0; }
replace
166
167
166
167
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, cc, n) for (int i = cc; i <= n; ++i) using namespace std; using ll = long long; int main() { int N; cin >> N; ll INF = pow(10, 18); ll A, ans = 1; bool zero = false, overflow = false; rep(i, 0, N - 1) { cin >> A; if (A == 0) zero = true; if (INF / A < ans) overflow = true; ans *= A; } if (zero) cout << 0 << endl; else if (overflow) cout << -1 << endl; else cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, cc, n) for (int i = cc; i <= n; ++i) using namespace std; using ll = long long; int main() { int N; cin >> N; ll INF = pow(10, 18); ll A, ans = 1; bool zero = false, overflow = false; rep(i, 0, N - 1) { cin >> A; if (A == 0) zero = true; else if (INF / A < ans) overflow = true; ans *= A; } if (zero) cout << 0 << endl; else if (overflow) cout << -1 << endl; else cout << ans << endl; return 0; }
replace
17
18
17
18
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define D(x) cout << #x << "=" << x << endl; using namespace std; // int _; int n; long long ans = 1, a[100050]; int main() { // for(scanf("%d",&_);_;_--) scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld", a + i); if (!a[i]) { puts("0"); return 0; } } for (int i = 0; i < n; i++) { if (1000000000000000000 / ans >= a[i] && 1000000000000000000 % ans != 0) { puts("-1"); return 0; } ans *= a[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define D(x) cout << #x << "=" << x << endl; using namespace std; // int _; int n; long long ans = 1, a[100050]; int main() { // for(scanf("%d",&_);_;_--) scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld", a + i); if (!a[i]) { puts("0"); return 0; } } for (int i = 0; i < n; i++) { if (1000000000000000000 / ans < a[i]) { puts("-1"); return 0; } ans *= a[i]; } cout << ans << endl; return 0; }
replace
20
21
20
21
0
p02658
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <numeric> #include <string> #include <vector> // #include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ... #define pi 3.14159265358979323846 #define rep(i, n) for (int i = 0; i < n; i++) typedef unsigned long long ll; typedef unsigned char Byte; using namespace std; bool isZero = true; // string ans = "Yes"; ll ans = 1; int N; vector<ll> A; int main() { cin >> N; ll stdd = 1; rep(_i, 18) stdd *= 10; rep(i, N) { ll tmp; cin >> tmp; if (tmp == 0) { cout << 0 << endl; return 0; } A.push_back(tmp); } rep(i, N) { ll recAns = ans; ans *= A[i]; if (ans > stdd || recAns != ans / A[i]) { cout << -1 << endl; return -1; } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <numeric> #include <string> #include <vector> // #include <iomanip> : 表示桁数, ex) cout << fixed << setprecision(15) << ... #define pi 3.14159265358979323846 #define rep(i, n) for (int i = 0; i < n; i++) typedef unsigned long long ll; typedef unsigned char Byte; using namespace std; bool isZero = true; // string ans = "Yes"; ll ans = 1; int N; vector<ll> A; int main() { cin >> N; ll stdd = 1; rep(_i, 18) stdd *= 10; rep(i, N) { ll tmp; cin >> tmp; if (tmp == 0) { cout << 0 << endl; return 0; } A.push_back(tmp); } rep(i, N) { ll recAns = ans; ans *= A[i]; if (ans > stdd || recAns != ans / A[i]) { cout << -1 << endl; return 0; } } cout << ans << endl; return 0; }
replace
41
42
41
42
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define ld long double #define eb emplace_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define int long long using namespace std; const int INF = 1e18; const int MB = 20; const int MOD = 998244353; const int maxN = 1e6; void solve() { int n; cin >> n; int res = 1; for (int i = 0; i < n; i++) { int x; cin >> x; if (INF / res < x) { res = INF + 1; } else { res *= x; } } cout << (res > INF ? -1 : res); } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << fixed; cout.precision(12); srand(time(0)); int t = 1; // int t; // cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> #define ll long long #define ld long double #define eb emplace_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define int long long using namespace std; const int INF = 1e18; const int MB = 20; const int MOD = 998244353; const int maxN = 1e6; void solve() { int n; cin >> n; int res = 1; for (int i = 0; i < n; i++) { int x; cin >> x; if (res && INF / res < x) { res = INF + 1; } else { res *= x; } } cout << (res > INF ? -1 : res); } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout << fixed; cout.precision(12); srand(time(0)); int t = 1; // int t; // cin >> t; while (t--) solve(); }
replace
22
23
22
23
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define pb push_back #define ll long long int #define db double #define SORTA(v) sort(v.begin(), v.end()) #define SORTD(v) sort(v.begin(), v.end(), greater<>()) #define endl '\n' #define nod(N) floor(log10(N)) + 1 #define LB(a) lower_bound(a) #define UB(a) upper_bound(a) #define F first #define S second #define FOR(i, n) for (long long int i = 0; i < n; i++) #define FOR1(i, n) for (long long int i = 1; i <= n; i++) #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define REVERSE(s) reverse(s.begin(), s.end()) #define LBV(v, a) lower_bound(v.begin(), v.end(), a) #define UBV(v, a) upper_bound(v.begin(), v.end(), a) #define GCD(a, b) __gcd(a, b) #define ITX(it, x1) for (auto it = x1.begin(); it != x1.end(); it++) #define I insert #define VFIND(v1, val) find(v1.begin(), v1.end(), val) #define VFILL(v1, val) std::fill(v1.begin(), v1.end(), val); #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define all(x) x.begin(), x.end() // typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, // tree_order_statistics_node_update> ordered_set; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ll mxm() { return LLONG_MIN; } template <typename... Args> ll mxm(ll a, Args... args) { return max(a, mxm(args...)); } ll mnm() { return LLONG_MAX; } template <typename... Args> ll mnm(ll a, Args... args) { return min(a, mnm(args...)); } const int MOD = 1e9 + 7; long long int powxy(long long int x, long long int y) { if (y == 0) return 1; if (y % 2 == 1) return (x * powxy(x, y - 1)) % MOD; long long int t = powxy(x, y / 2); return (t * t) % MOD; } void DPM(map<ll, ll> m1) { for (auto it = m1.begin(); it != m1.end(); it++) { cout << it->first << " " << it->second << endl; } cout << endl; } void DPV(vector<ll> v) { FOR(i, v.size()) cout << v[i] << " "; cout << endl; } void DPS(set<ll> s1) { for (auto it = s1.begin(); it != s1.end(); it++) cout << *it << " "; cout << endl; } void DPA(ll arr[], ll n) { FOR(i, n) cout << arr[i] << " "; cout << endl; } ll dx[4] = {0, 0, 1, -1}; ll dy[4] = {1, -1, 0, 0}; string pos = "RLDU"; int main() { FAST; ll i, j, T = 1; // cin>>T; while (T--) { i = 0; j = 0; ll n; cin >> n; ll ans = 1; bool out = true; FOR1(i, n) { ll j; cin >> j; // ans *= j; if (ans > (ll)1e18 / j || ans < 0) { out = false; ans = 0; } else ans = ans * j; if (j == 0) { out = true; ans = 0; break; } } if (out) cout << ans; else cout << "-1"; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define pb push_back #define ll long long int #define db double #define SORTA(v) sort(v.begin(), v.end()) #define SORTD(v) sort(v.begin(), v.end(), greater<>()) #define endl '\n' #define nod(N) floor(log10(N)) + 1 #define LB(a) lower_bound(a) #define UB(a) upper_bound(a) #define F first #define S second #define FOR(i, n) for (long long int i = 0; i < n; i++) #define FOR1(i, n) for (long long int i = 1; i <= n; i++) #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define REVERSE(s) reverse(s.begin(), s.end()) #define LBV(v, a) lower_bound(v.begin(), v.end(), a) #define UBV(v, a) upper_bound(v.begin(), v.end(), a) #define GCD(a, b) __gcd(a, b) #define ITX(it, x1) for (auto it = x1.begin(); it != x1.end(); it++) #define I insert #define VFIND(v1, val) find(v1.begin(), v1.end(), val) #define VFILL(v1, val) std::fill(v1.begin(), v1.end(), val); #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define all(x) x.begin(), x.end() // typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, // tree_order_statistics_node_update> ordered_set; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ll mxm() { return LLONG_MIN; } template <typename... Args> ll mxm(ll a, Args... args) { return max(a, mxm(args...)); } ll mnm() { return LLONG_MAX; } template <typename... Args> ll mnm(ll a, Args... args) { return min(a, mnm(args...)); } const int MOD = 1e9 + 7; long long int powxy(long long int x, long long int y) { if (y == 0) return 1; if (y % 2 == 1) return (x * powxy(x, y - 1)) % MOD; long long int t = powxy(x, y / 2); return (t * t) % MOD; } void DPM(map<ll, ll> m1) { for (auto it = m1.begin(); it != m1.end(); it++) { cout << it->first << " " << it->second << endl; } cout << endl; } void DPV(vector<ll> v) { FOR(i, v.size()) cout << v[i] << " "; cout << endl; } void DPS(set<ll> s1) { for (auto it = s1.begin(); it != s1.end(); it++) cout << *it << " "; cout << endl; } void DPA(ll arr[], ll n) { FOR(i, n) cout << arr[i] << " "; cout << endl; } ll dx[4] = {0, 0, 1, -1}; ll dy[4] = {1, -1, 0, 0}; string pos = "RLDU"; int main() { FAST; ll i, j, T = 1; // cin>>T; while (T--) { i = 0; j = 0; ll n; cin >> n; ll ans = 1; bool out = true; FOR1(i, n) { ll j; cin >> j; // ans *= j; if (j > 0 && ans > (ll)1e18 / j || ans < 0) { out = false; ans = 0; } else ans = ans * j; if (j == 0) { out = true; ans = 0; break; } } if (out) cout << ans; else cout << "-1"; } }
replace
101
102
101
102
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; long long a[10001]; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int n; cin >> n; rep(i, n) { cin >> a[i]; if (a[i] == 0) { cout << "0\n"; return 0; } } long long prod = 1; rep(i, n) { if (a[i] <= 1000000000000000000 / prod) { prod *= a[i]; } else { prod = -1; break; } } cout << prod; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; long long a[100010]; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int n; cin >> n; rep(i, n) { cin >> a[i]; if (a[i] == 0) { cout << "0\n"; return 0; } } long long prod = 1; rep(i, n) { if (a[i] <= 1000000000000000000 / prod) { prod *= a[i]; } else { prod = -1; break; } } cout << prod; return 0; }
replace
4
5
4
5
0
p02658
C++
Runtime Error
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define rep(i, n) for (ll i = 0; i < n; ++i) #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define vi vector<int> #define vll vector<ll> #define vpi vector<pii> #define vpll vector<pll> #define Size(c) (int)(c).size() #define INT(...) \ int __VA_ARGS__; \ IN(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ IN(__VA_ARGS__) #define ULL(...) \ ull __VA_ARGS__; \ IN(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ IN(__VA_ARGS__) #define CHR(...) \ char __VA_ARGS__; \ IN(__VA_ARGS__) #define DBL(...) \ double __VA_ARGS__; \ IN(__VA_ARGS__) #define LD(...) \ ld __VA_ARGS__; \ IN(__VA_ARGS__) int scan() { return getchar(); } void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(long double &a) { cin >> a; } void scan(char a[]) { scanf("%s", a); } void scan(string &a) { cin >> a; } template <class T> void scan(vector<T> &); template <class T, size_t size> void scan(array<T, size> &); template <class T, class L> void scan(pair<T, L> &); template <class T, size_t size> void scan(T (&)[size]); template <class T> void scan(vector<T> &a) { for (auto &i : a) scan(i); } template <class T> void scan(deque<T> &a) { for (auto &i : a) scan(i); } template <class T, size_t size> void scan(array<T, size> &a) { for (auto &i : a) scan(i); } template <class T, class L> void scan(pair<T, L> &p) { scan(p.first); scan(p.second); } template <class T, size_t size> void scan(T (&a)[size]) { for (auto &i : a) scan(i); } template <class T> void scan(T &a) { cin >> a; } void IN() {} template <class Head, class... Tail> void IN(Head &head, Tail &...tail) { scan(head); IN(tail...); } #define ios cin.tie(NULL), ios_base::sync_with_stdio(false) #define cfs(n) cout << fixed << setprecision((n)) #define endl '\n' #define ret return 0 constexpr ll mod = 998244353; constexpr ll mod2 = 10e9 + 7; const double PI = 3.1415926535897932384626433832795028841971; // acos(-1) 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; } // endmacro ll a[100010]; int main() { ios; cfs(15); INT(n); rep(i, n) { LL(a[i]); if (a[i] == 0) { cout << "0" << endl; ret; } } ll prod = 1; rep(i, n) { if (a[i] <= 1000000000000000000 / prod) { prod *= a[i]; } else { prod = -1; break; } } cout << prod << endl; ret; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define rep(i, n) for (ll i = 0; i < n; ++i) #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define vi vector<int> #define vll vector<ll> #define vpi vector<pii> #define vpll vector<pll> #define Size(c) (int)(c).size() #define INT(...) \ int __VA_ARGS__; \ IN(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ IN(__VA_ARGS__) #define ULL(...) \ ull __VA_ARGS__; \ IN(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ IN(__VA_ARGS__) #define CHR(...) \ char __VA_ARGS__; \ IN(__VA_ARGS__) #define DBL(...) \ double __VA_ARGS__; \ IN(__VA_ARGS__) #define LD(...) \ ld __VA_ARGS__; \ IN(__VA_ARGS__) int scan() { return getchar(); } void scan(int &a) { cin >> a; } void scan(long long &a) { cin >> a; } void scan(char &a) { cin >> a; } void scan(double &a) { cin >> a; } void scan(long double &a) { cin >> a; } void scan(char a[]) { scanf("%s", a); } void scan(string &a) { cin >> a; } template <class T> void scan(vector<T> &); template <class T, size_t size> void scan(array<T, size> &); template <class T, class L> void scan(pair<T, L> &); template <class T, size_t size> void scan(T (&)[size]); template <class T> void scan(vector<T> &a) { for (auto &i : a) scan(i); } template <class T> void scan(deque<T> &a) { for (auto &i : a) scan(i); } template <class T, size_t size> void scan(array<T, size> &a) { for (auto &i : a) scan(i); } template <class T, class L> void scan(pair<T, L> &p) { scan(p.first); scan(p.second); } template <class T, size_t size> void scan(T (&a)[size]) { for (auto &i : a) scan(i); } template <class T> void scan(T &a) { cin >> a; } void IN() {} template <class Head, class... Tail> void IN(Head &head, Tail &...tail) { scan(head); IN(tail...); } #define ios cin.tie(NULL), ios_base::sync_with_stdio(false) #define cfs(n) cout << fixed << setprecision((n)) #define endl '\n' #define ret return 0 constexpr ll mod = 998244353; constexpr ll mod2 = 10e9 + 7; const double PI = 3.1415926535897932384626433832795028841971; // acos(-1) 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; } // endmacro ll a[100010]; int main() { ios; cfs(15); INT(n); rep(i, n) { scan(a[i]); if (a[i] == 0) { cout << "0" << endl; ret; } } ll prod = 1; rep(i, n) { if (a[i] <= 1000000000000000000 / prod) { prod *= a[i]; } else { prod = -1; break; } } cout << prod << endl; ret; }
replace
111
112
111
112
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long signed main() { int n; cin >> n; ll num = 1, a; for (int i = 0; i < n; i++) { cin >> a; if (a > 0 && 1000000000000000000 / num >= a) { num *= a; } else if (a == 0) { num = 0; } else { num = -1; } } cout << num; }
#include <bits/stdc++.h> using namespace std; #define ll long long signed main() { int n; cin >> n; ll num = 1, a; for (int i = 0; i < n; i++) { cin >> a; if (a > 0 && 1000000000000000000 / num >= a) { num *= a; } else if (a == 0) { num = 0; break; } else { num = -1; } } cout << num; }
insert
19
19
19
20
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define debi(var) \ "[" << (#var) << " : " << var << "]" \ << " " #define debv(v) \ "[" << (#v) << " : {"; \ for (int i = 0; i < v.size() - 1; ++i) \ cout << v[i] << ", "; \ cout << v.back() << "}] " #define deba(a, n) \ "[" << (#a) << " : {"; \ for (int i = 0; i < n - 1; ++i) \ cout << a[i] << ", "; \ cout << a[n - 1] << "}] " #define debp(p) "[" << (#p) << " : {" << p.first << ", " << p.second << "}] " #define debs(s) \ "[" << (#s) << " : {"; \ auto _itr = s.begin(); \ for (int k = s.size(); k > 1; --k) { \ cout << *_itr << ", "; \ ++_itr; \ } \ cout << *_itr << "}] " typedef long long ll; /*LETS BEGIN WITH THE NAME OF LORD MAHADEV*/ int main() { int n; cin >> n; bool zero = false, greater = false; ll ans = 1; while (n--) { ll val; cin >> val; if (!val) { zero = true; } if (val <= (ll)1e18 / ans) { ans *= val; } else { greater = true; } } if (zero) { cout << 0 << endl; } else if (greater) { cout << -1 << endl; } else { cout << ans; } return 0; }
#include <bits/stdc++.h> using namespace std; #define debi(var) \ "[" << (#var) << " : " << var << "]" \ << " " #define debv(v) \ "[" << (#v) << " : {"; \ for (int i = 0; i < v.size() - 1; ++i) \ cout << v[i] << ", "; \ cout << v.back() << "}] " #define deba(a, n) \ "[" << (#a) << " : {"; \ for (int i = 0; i < n - 1; ++i) \ cout << a[i] << ", "; \ cout << a[n - 1] << "}] " #define debp(p) "[" << (#p) << " : {" << p.first << ", " << p.second << "}] " #define debs(s) \ "[" << (#s) << " : {"; \ auto _itr = s.begin(); \ for (int k = s.size(); k > 1; --k) { \ cout << *_itr << ", "; \ ++_itr; \ } \ cout << *_itr << "}] " typedef long long ll; /*LETS BEGIN WITH THE NAME OF LORD MAHADEV*/ int main() { int n; cin >> n; bool zero = false, greater = false; ll ans = 1; while (n--) { ll val; cin >> val; if (!val) { zero = true; break; } if (val <= (ll)1e18 / ans) { ans *= val; } else { greater = true; } } if (zero) { cout << 0 << endl; } else if (greater) { cout << -1 << endl; } else { cout << ans; } return 0; }
insert
38
38
38
39
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; long long a[N], b[N]; for (int i = 0; i < N; i++) { cin >> a[i]; if (a[i] == 0) { cout << 0 << endl; return 0; } if (a[i] > 1e18) { cout << -1 << endl; return 0; } if (a[i] != 1) b[i] = a[i] - 1; } long long ans = a[0], ans2 = a[0] + 1; for (int i = 1; i < N; i++) { ans2 *= b[i]; if (ans2 < 0 || ans2 > 1000000000000000000 || ans2 % b[i] != 0) { cout << -1 << endl; return 0; } } for (int i = 1; i < N; i++) { ans *= a[i]; if (ans < 0 || ans > 1000000000000000000 || ans % a[i] != 0) { cout << -1 << endl; return 0; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; long long a[N], b[N]; for (int i = 0; i < N; i++) { cin >> a[i]; if (a[i] == 0) { cout << 0 << endl; return 0; } if (a[i] > 1e18) { cout << -1 << endl; return 0; } if (a[i] != 1) b[i] = a[i] - 1; else b[i] = a[i]; } long long ans = a[0], ans2 = a[0] + 1; for (int i = 1; i < N; i++) { ans2 *= b[i]; if (ans2 < 0 || ans2 > 1000000000000000000 || ans2 % b[i] != 0) { cout << -1 << endl; return 0; } } for (int i = 1; i < N; i++) { ans *= a[i]; if (ans < 0 || ans > 1000000000000000000 || ans % a[i] != 0) { cout << -1 << endl; return 0; } } cout << ans << endl; return 0; }
insert
19
19
19
21
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, n) for (int i = 0; i < n; ++i) #define FORR(i, a, n) for (int i = a; i < n; ++i) #define ALL(c) (c).begin(), (c).end() #define RALL(a) (a).rbegin(), (a).rend() #define UNIQ(c) (c).erase(unique(ALL((c))), end((c))) const int INF = 0x3f3f3f3f; typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<int, int> PI; typedef pair<ll, ll> PL; // int in() { int x; scanf("%d", &x); return x; } // ll lin() { ll x; scanf("%lld", &x); return x; } // void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; } const ll MAX = 1e18; int main(void) { std::ios_base::sync_with_stdio(false); int n; cin >> n; ll ans = 1; bool ng = false; FOR(i, n) { ll tmp; cin >> tmp; if (tmp == 0) { cout << 0 << endl; return 0; } if ((MAX + 1) / ans < tmp || ans * tmp > MAX) { ng = true; } ans *= tmp; } if (ng) cout << -1 << endl; else cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, n) for (int i = 0; i < n; ++i) #define FORR(i, a, n) for (int i = a; i < n; ++i) #define ALL(c) (c).begin(), (c).end() #define RALL(a) (a).rbegin(), (a).rend() #define UNIQ(c) (c).erase(unique(ALL((c))), end((c))) const int INF = 0x3f3f3f3f; typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<int, int> PI; typedef pair<ll, ll> PL; // int in() { int x; scanf("%d", &x); return x; } // ll lin() { ll x; scanf("%lld", &x); return x; } // void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; } const ll MAX = 1e18; int main(void) { std::ios_base::sync_with_stdio(false); int n; cin >> n; ll ans = 1; bool ng = false; FOR(i, n) { ll tmp; cin >> tmp; if (tmp == 0) { cout << 0 << endl; return 0; } if (ng || (MAX + 1) / ans < tmp || ans * tmp > MAX) { ng = true; } ans *= tmp; } if (ng) cout << -1 << endl; else cout << ans; return 0; }
replace
44
45
44
45
0
p02658
C++
Runtime Error
#include <iostream> int main() { int64_t N; std::cin >> N; int64_t sum = 1; bool over = false; for (int64_t i = 0; i < N; ++i) { int64_t A; std::cin >> A; if (A == 0) { sum = 0; over = false; break; } if (A > 1000000000000000000 / sum) over = true; sum *= A; } if (over) std::cout << -1; else std::cout << sum; }
#include <iostream> int main() { int64_t N; std::cin >> N; int64_t sum = 1; bool over = false; for (int64_t i = 0; i < N; ++i) { int64_t A; std::cin >> A; if (A == 0) { sum = 0; over = false; break; } if (sum > 1000000000000000000 / A) over = true; sum *= A; } if (over) std::cout << -1; else std::cout << sum; }
replace
17
18
17
18
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define ll unsigned long long using namespace std; int main() { int n; cin >> n; ll aux, ans = 1; bool sw = 0, sw2 = 0; for (int i = 0; i < n; i++) { cin >> aux; if (aux == 0) sw = 1; if (ans > (1000000000000000000 / aux) || ans < 0) sw2 = 1; ans *= aux; } if (sw) { cout << "0\n"; return 0; } else if (sw2) { cout << "-1\n"; return 0; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define ll unsigned long long using namespace std; int main() { int n; cin >> n; ll aux, ans = 1; bool sw = 0, sw2 = 0; for (int i = 0; i < n; i++) { cin >> aux; if (aux == 0) sw = 1; else if (ans > (1000000000000000000 / aux) || ans < 0) sw2 = 1; ans *= aux; } if (sw) { cout << "0\n"; return 0; } else if (sw2) { cout << "-1\n"; return 0; } cout << ans << "\n"; return 0; }
replace
12
13
12
13
0
p02658
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; constexpr ll M = (ll)1e+18; ll r = 1; int b = 0; for (int i = 0; i < n; i++) { ll a; cin >> a; if (a == 0) { cout << 0 << endl; exit(0); } if (a > (M + r - 1) / r) b = 1; r *= a; if (r > M) b = 1; } if (b) { cout << -1 << endl; } else { cout << r << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; constexpr ll M = (ll)1e+18; ll r = 1; int b = 0; for (int i = 0; i < n; i++) { ll a; cin >> a; if (a == 0) { cout << 0 << endl; exit(0); } if (!b && a > (M + r - 1) / r) b = 1; r *= a; if (r > M) b = 1; } if (b) { cout << -1 << endl; } else { cout << r << endl; } return 0; }
replace
28
29
28
29
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; (i) < (n); (i)++) using namespace std; int main() { int N; cin >> N; long A[100005]; REP(i, N) cin >> A[i]; long ans = 1l; long sai = 1000000000000000000; bool ok = true; sort(A, A + N); REP(i, N) { if (A[i] == 0l) { ans = 0l; break; } if (sai / ans < A[i]) { ok = false; } ans *= A[i]; // cout << ans << endl; } if (ok) cout << ans << endl; else cout << -1 << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; (i) < (n); (i)++) using namespace std; int main() { int N; cin >> N; long A[100005]; REP(i, N) cin >> A[i]; long ans = 1l; long sai = 1000000000000000000; bool ok = true; sort(A, A + N); REP(i, N) { if (A[i] == 0l) { ans = 0l; break; } if (sai / ans < A[i]) { ok = false; break; } ans *= A[i]; // cout << ans << endl; } if (ok) cout << ans << endl; else cout << -1 << endl; return 0; }
insert
20
20
20
21
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<ll> a; ll ans = 1; bool flag = true; for (int i = 0; i < n; i++) { ll b; cin >> b; a.push_back(b); } sort(a.begin(), a.end()); for (int i = 0; i < n; i++) { if (a[i] > 1000000000000000000 / ans) { flag = false; break; } ans *= a[i]; } if (flag) { cout << ans << endl; } else { cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<ll> a; ll ans = 1; bool flag = true; for (int i = 0; i < n; i++) { ll b; cin >> b; a.push_back(b); if (b == 0) { cout << 0 << endl; return 0; } } sort(a.begin(), a.end()); for (int i = 0; i < n; i++) { if (a[i] > 1000000000000000000 / ans) { flag = false; break; } ans *= a[i]; } if (flag) { cout << ans << endl; } else { cout << -1 << endl; } }
insert
14
14
14
18
0
p02658
C++
Runtime Error
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; #define INF 0x6fffffff #define INFL 0x6fffffffffffffffLL int main() { long long a, b, c, h, i, j, k, l, m, n, x, y; long long ans = 1; double aa, aans = 1.0; string s; cin >> n; // vector<ll> aa(n); bool flag = true, zero = false; for (i = 0; i < n; i++) { cin >> a; c = 1000000000000000000ull / ans; if (c < a) flag = false; ans *= a; aa = a; // aans *= aa; // if (aans > 1000000000000000000.0) flag = false; // if (ans > 1000000000000000000ull) flag = false; if (a == 0) { zero = true; } } if (flag == false && zero == false) ans = -1; // vector<ll> dp(n+1,INFL); // vector<vector<ll>> dp2(x , vector<ll>(y,INFL)); cout << ans << endl; return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; #define INF 0x6fffffff #define INFL 0x6fffffffffffffffLL int main() { long long a, b, c, h, i, j, k, l, m, n, x, y; long long ans = 1; double aa, aans = 1.0; string s; cin >> n; // vector<ll> aa(n); bool flag = true, zero = false; for (i = 0; i < n; i++) { cin >> a; if (ans != 0) { c = 1000000000000000000ull / ans; if (c < a) flag = false; } ans *= a; aa = a; // aans *= aa; // if (aans > 1000000000000000000.0) flag = false; // if (ans > 1000000000000000000ull) flag = false; if (a == 0) { zero = true; } } if (flag == false && zero == false) ans = -1; // vector<ll> dp(n+1,INFL); // vector<vector<ll>> dp2(x , vector<ll>(y,INFL)); cout << ans << endl; return 0; }
replace
17
20
17
22
0
p02658
C++
Runtime Error
#include <stdio.h> int main() { const long long lim = 2000000000000000000ll; int N; scanf("%d", &N); long long A = 1; while (N--) { long long a; scanf("%lld", &a); if (A > lim / a) A = lim; else A *= a; if (A > lim) A = lim; } if (A > lim / 2) A = -1; printf("%lld\n", A); return 0; }
#include <stdio.h> int main() { const long long lim = 2000000000000000000ll; int N; scanf("%d", &N); long long A = 1; while (N--) { long long a; scanf("%lld", &a); if (a && A > lim / a) A = lim; else A *= a; if (A > lim) A = lim; } if (A > lim / 2) A = -1; printf("%lld\n", A); return 0; }
replace
11
12
11
12
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #include <limits.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const ll INF = 1e18; const ll mod = 1e9 + 7; // const ll LLMAX = LLONG_MAX; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; ll answer = 1; // a.sort(a.begin(), a.end()); rep(i, n) { if (a[i] > INF / answer) { answer = INF + 1; } else answer *= a[i]; } if (answer > INF) cout << -1 << endl; else cout << answer << endl; return 0; }
#include <bits/stdc++.h> #include <limits.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const ll INF = 1e18; const ll mod = 1e9 + 7; // const ll LLMAX = LLONG_MAX; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) { cin >> a[i]; if (a[i] == 0) { cout << 0 << endl; return 0; } } ll answer = 1; // a.sort(a.begin(), a.end()); rep(i, n) { if (a[i] > INF / answer) { answer = INF + 1; } else answer *= a[i]; } if (answer > INF) cout << -1 << endl; else cout << answer << endl; return 0; }
replace
14
15
14
21
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // Author: Ezio Sam /* Shorthands */ #define ll unsigned long long #define pb push_back #define mp make_pair #define sp ": " #define cs "Case " #define fi first #define sn second #define po(x) x *x /* STL */ #define vi vector<int> v #define pii pair<int, int> #define pll pair<ll, ll> #define mem(a, n) memset(a, n, sizeof(a)); #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define mx(v) *max_element(v.begin(), v.end()) #define mxa(a) *max_element(a, a.size()) #define r(a) reverse(a.begin(), a.end()) /* loops */ #define fr(i, n) for (__typeof(n) i = 0; i < (n); i++) #define fn(i, n) for (__typeof(n) i = 1; i <= (n); i++) #define fa(i, a, n) for (__typeof(a) i = (a); i <= (b); i++) /*Special*/ #define Ezio ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); #define db(something) cerr << #something << " - " << something << "\n"; int main() { Ezio /*Variables*/ /*Code*/ ll n, x; vector<ll> v; ll ans = 1; const ll m = 1e18; int i; cin >> n; fr(i, n) { cin >> x; v.pb(x); } sort(all(v)); fr(i, n) { if (ans <= m / v[i]) ans *= v[i]; else { cout << "-1" << endl; return 0; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // Author: Ezio Sam /* Shorthands */ #define ll unsigned long long #define pb push_back #define mp make_pair #define sp ": " #define cs "Case " #define fi first #define sn second #define po(x) x *x /* STL */ #define vi vector<int> v #define pii pair<int, int> #define pll pair<ll, ll> #define mem(a, n) memset(a, n, sizeof(a)); #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define mx(v) *max_element(v.begin(), v.end()) #define mxa(a) *max_element(a, a.size()) #define r(a) reverse(a.begin(), a.end()) /* loops */ #define fr(i, n) for (__typeof(n) i = 0; i < (n); i++) #define fn(i, n) for (__typeof(n) i = 1; i <= (n); i++) #define fa(i, a, n) for (__typeof(a) i = (a); i <= (b); i++) /*Special*/ #define Ezio ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); #define db(something) cerr << #something << " - " << something << "\n"; int main() { Ezio /*Variables*/ /*Code*/ ll n, x; vector<ll> v; ll ans = 1; const ll m = 1e18; int i; cin >> n; fr(i, n) { cin >> x; if (x == 0) { cout << 0; return 0; } v.pb(x); } sort(all(v)); fr(i, n) { if (ans <= m / v[i]) ans *= v[i]; else { cout << "-1" << endl; return 0; } } cout << ans << endl; return 0; }
insert
44
44
44
48
0
p02658
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; long long n, a, m = 1, e = 1e18, fl; int main() { cin >> n; while (n--) { cin >> a; if (a <= e / m) m *= a; else fl = 1; } if (m == 0) cout << 0; else if (fl) cout << -1; else cout << m; return 0; }
#include <cstdio> #include <iostream> using namespace std; long long n, a, m = 1, e = 1e18, fl; int main() { cin >> n; while (n--) { cin >> a; if (a <= e / m) m *= a; else fl = 1; if (m == 0) break; } if (m == 0) cout << 0; else if (fl) cout << -1; else cout << m; return 0; }
insert
13
13
13
15
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using P = pair<int, int>; using ll = long long; const ll mx = 1e18; int main() { int n; cin >> n; ll ans = 1; bool over = false; rep(i, n) { ll a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if ((mx + 1) / ans < a || a * ans > mx || over) { over = true; } ans *= a; } if (over) ans = -1; cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using P = pair<int, int>; using ll = long long; const ll mx = 1e18; int main() { int n; cin >> n; ll ans = 1; bool over = false; rep(i, n) { ll a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (over || (mx + 1) / ans < a || a * ans > mx) { over = true; } ans *= a; } if (over) ans = -1; cout << ans << endl; }
replace
23
24
23
24
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll limit = 1000000000000000000; int main() { // 入力 ll N; cin >> N; vector<ll> vec(N); for (ll i = 0; i < N; i++) { cin >> vec.at(i); } sort(vec.begin(), vec.end()); ll ans = 1; for (ll i = 0; i < N; i++) { if (vec.at(i) <= limit / ans) { ans *= vec.at(i); } else { ans = -1; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll limit = 1000000000000000000; int main() { // 入力 ll N; cin >> N; vector<ll> vec(N); for (ll i = 0; i < N; i++) { cin >> vec.at(i); } sort(vec.begin(), vec.end()); ll ans = 1; for (ll i = 0; i < N; i++) { if (vec.at(i) <= limit / ans) { ans *= vec.at(i); } else { ans = -1; break; } if (ans == 0) { break; } } cout << ans << endl; }
insert
24
24
24
27
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); long long count = 1; for (int i = 0; i < n; i++) { if (count > 0) { if (count <= 1000000000000000000 / a[i]) count *= a[i]; else count = -1; } } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); long long count = 1; for (int i = 0; i < n; i++) { if (count != -1) { if (a[i] == 0) count = 0; else if (count <= 1000000000000000000 / a[i]) count *= a[i]; else count = -1; } } cout << count << endl; }
replace
12
14
12
16
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long ll a[10010]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); int zero = 0; for (int i = 0; i < n; i++) if (a[i] == 0) zero++; if (zero > 0) { printf("0\n"); return 0; } ll prod = 1; for (int i = 0; i < n; i++) { if (a[i] <= 1000000000000000000 / prod) { prod *= a[i]; } else { printf("-1\n"); return 0; } } printf("%lld\n", prod); }
#include <bits/stdc++.h> using namespace std; #define ll long long ll a[100010]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); int zero = 0; for (int i = 0; i < n; i++) if (a[i] == 0) zero++; if (zero > 0) { printf("0\n"); return 0; } ll prod = 1; for (int i = 0; i < n; i++) { if (a[i] <= 1000000000000000000 / prod) { prod *= a[i]; } else { printf("-1\n"); return 0; } } printf("%lld\n", prod); }
replace
3
4
3
4
0
p02658
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (ll i = 0; i < x; i++) #define repn(i, x) for (ll i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; int main() { ll N; cin >> N; vector<ll> a(N); rep(i, N) cin >> a[i]; ll ans = 1; SORT(a); if (a[0] = 0) { cout << 0 << endl; return 0; } rep(i, N) { if (a[i] > (ll)1e18 / ans) { cout << -1 << endl; return 0; } ans *= a[i]; } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (ll i = 0; i < x; i++) #define repn(i, x) for (ll i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 510000; const int MOD = 1000000007; int main() { ll N; cin >> N; vector<ll> a(N); rep(i, N) cin >> a[i]; ll ans = 1; SORT(a); if (a[0] == 0) { cout << 0 << endl; return 0; } rep(i, N) { if (a[i] > (ll)1e18 / ans) { cout << -1 << endl; return 0; } ans *= a[i]; } cout << ans << endl; }
replace
41
42
41
42
-8
p02658
C++
Runtime Error
/*Author - Shubham Gupta (@shubham107)*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<vl> vvl; typedef vector<vi> vvi; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define forn(i, n) for (int i = 0; i < n; i++) #define rforn(i, n) for (int i = n - 1; i >= 0; i--) #define forne(i, n) for (int i = 1; i <= n; i++) #define forse(i, s, e) for (int i = s; i < e; i++) #define rforse(i, s, e) for (int i = e - 1; i >= s; i--) #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define MOD 1000000007 #define F first #define S second #define pb push_back #define mp make_pair #define fill(a, x) memset(a, x, sizeof a); #define trav(a, x) for (auto &a : x) #define INF ll(1e18) #ifdef SHUBHAM107 #include "../trace.h" #else #define trace(args...) #endif void solve() { int n; cin >> n; ll ans = 1, x; bool ok = true, zero = false; vl arr(n); forn(i, n) cin >> arr[i]; forn(i, n) { x = arr[i]; if (x == 0) { zero = true; } if (x > INF / ans) { ok = false; } else { ans *= x; } } if (zero) { cout << '0'; } else { if (ok) { cout << ans; } else { cout << "-1"; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef SHUBHAM107 freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); freopen("err.txt", "w", stderr); #endif int t = 1; // cin >> t; while (t--) { solve(); } }
/*Author - Shubham Gupta (@shubham107)*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<vl> vvl; typedef vector<vi> vvi; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define forn(i, n) for (int i = 0; i < n; i++) #define rforn(i, n) for (int i = n - 1; i >= 0; i--) #define forne(i, n) for (int i = 1; i <= n; i++) #define forse(i, s, e) for (int i = s; i < e; i++) #define rforse(i, s, e) for (int i = e - 1; i >= s; i--) #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define MOD 1000000007 #define F first #define S second #define pb push_back #define mp make_pair #define fill(a, x) memset(a, x, sizeof a); #define trav(a, x) for (auto &a : x) #define INF ll(1e18) #ifdef SHUBHAM107 #include "../trace.h" #else #define trace(args...) #endif void solve() { int n; cin >> n; ll ans = 1, x; bool ok = true, zero = false; vl arr(n); forn(i, n) cin >> arr[i]; forn(i, n) { x = arr[i]; if (x == 0) { zero = true; break; } if (x > INF / ans) { ok = false; } else { ans *= x; } } if (zero) { cout << '0'; } else { if (ok) { cout << ans; } else { cout << "-1"; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef SHUBHAM107 freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); freopen("err.txt", "w", stderr); #endif int t = 1; // cin >> t; while (t--) { solve(); } }
insert
43
43
43
44
0
p02658
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define _GLIBCXX_DEBUG using namespace std; typedef long long ll; ll mx = 1e18; int main() { int n; cin >> n; ll ans = 1; bool oror = false; rep(i, n) { ll a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (mx / ans < a || mx < a * ans) { oror = true; } ans *= a; } if (oror) cout << "-1" << endl; else cout << ans << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define _GLIBCXX_DEBUG using namespace std; typedef long long ll; ll mx = 1e18; int main() { int n; cin >> n; ll ans = 1; bool oror = false; rep(i, n) { ll a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (oror || mx / ans < a || mx < a * ans) { oror = true; } ans *= a; } if (oror) cout << "-1" << endl; else cout << ans << endl; }
replace
26
27
26
27
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define vll vector<ll> #define ub upper_bound #define lb lower_bound #define all(v) ((v).begin()), ((v).end()) #define allr(v) ((v).rbegin()), ((v).rend()) #define ff first #define ss second #define mp make_pair #define pll pair<ll, ll> #define fo(i, n) for (ll i = 0; i < n; i++) #define foa(i, s, e) for (ll i = (s); i < e; i++) #define fod(i, s, e) for (ll i = (s); i >= (e); i--) const ld pi = 3.14159265358979323846; ll mod1 = 1e9 + 7; ll mod2 = 998244353; ll mul(ll x, ll y) { return (1ll * (x % mod1) * (y % mod1)); } ll modpow(ll x, ll y) { ll z = 1; while (y > 0) { if (y % 2) z = mul(z, x); x = mul(x, x); y /= 2; } return z; } ll power(ll x, ll y) { ll z = 1; while (y > 0) { if (y % 2) z = z * x; x = x * x; y /= 2; } return z; } ll gcd(ll a, ll b) { if (a < b) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } ll min(ll a, ll b) { if (a < b) return a; return b; } ll max(ll a, ll b) { if (a > b) return a; return b; } ll sq(ll a) { ll ans = (1ll * a * a); return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); #ifndef ONLINE_JUDGE freopen("inputf.txt", "r", stdin); freopen("outputf.txt", "w", stdout); // freopen("error.txt" , "w" , stderr) ; #endif ll n; cin >> n; ll a[n]; ll p = 1; fo(i, n) { cin >> a[i]; } sort(a, a + n); fo(i, n) { if (a[i] > LLONG_MAX / p) { cout << -1 << "\n"; return 0; } p *= a[i]; if (p > (ll)1e18 || p < 0LL) { cout << -1 << "\n"; return 0; } } cout << p << "\n"; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define vll vector<ll> #define ub upper_bound #define lb lower_bound #define all(v) ((v).begin()), ((v).end()) #define allr(v) ((v).rbegin()), ((v).rend()) #define ff first #define ss second #define mp make_pair #define pll pair<ll, ll> #define fo(i, n) for (ll i = 0; i < n; i++) #define foa(i, s, e) for (ll i = (s); i < e; i++) #define fod(i, s, e) for (ll i = (s); i >= (e); i--) const ld pi = 3.14159265358979323846; ll mod1 = 1e9 + 7; ll mod2 = 998244353; ll mul(ll x, ll y) { return (1ll * (x % mod1) * (y % mod1)); } ll modpow(ll x, ll y) { ll z = 1; while (y > 0) { if (y % 2) z = mul(z, x); x = mul(x, x); y /= 2; } return z; } ll power(ll x, ll y) { ll z = 1; while (y > 0) { if (y % 2) z = z * x; x = x * x; y /= 2; } return z; } ll gcd(ll a, ll b) { if (a < b) return gcd(b, a); if (b == 0) return a; return gcd(b, a % b); } ll min(ll a, ll b) { if (a < b) return a; return b; } ll max(ll a, ll b) { if (a > b) return a; return b; } ll sq(ll a) { ll ans = (1ll * a * a); return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); #ifndef ONLINE_JUDGE freopen("inputf.txt", "r", stdin); freopen("outputf.txt", "w", stdout); // freopen("error.txt" , "w" , stderr) ; #endif ll n; cin >> n; ll a[n]; ll p = 1; fo(i, n) { cin >> a[i]; } sort(a, a + n); fo(i, n) { if (p && a[i] > LLONG_MAX / p) { cout << -1 << "\n"; return 0; } p *= a[i]; if (p > (ll)1e18 || p < 0LL) { cout << -1 << "\n"; return 0; } } cout << p << "\n"; }
replace
78
79
78
79
-11
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define bp __builtin_popcountll #define pb push_back #define in(s) freopen(s, "r", stdin); #define out(s) freopen(s, "w", stdout); #define inout(s, end1, end2) \ freopen((string(s) + "." + end1).c_str(), "r", stdin), \ freopen((string(s) + "." + end2).c_str(), "w", stdout); #define fi first #define se second #define bw(i, r, l) for (int i = r - 1; i >= l; i--) #define fw(i, l, r) for (int i = l; i < r; i++) #define fa(i, x) for (auto i : x) using namespace std; const int mod = 1e9 + 7, inf = 1061109567; const long long infll = 4557430888798830399; const int MAX = 4e18 + 5, MAX2 = 1e18; int mul(int a, int b) { if (a > MAX / b) return MAX; return a * b; } signed main() { #ifdef BLU in("blu.inp"); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, ans = 1; cin >> n; fw(i, 0, n) { int x; cin >> x; ans = mul(ans, x); } if (ans > MAX2) cout << "-1"; else cout << ans; return 0; }
#include <bits/stdc++.h> #define int long long #define bp __builtin_popcountll #define pb push_back #define in(s) freopen(s, "r", stdin); #define out(s) freopen(s, "w", stdout); #define inout(s, end1, end2) \ freopen((string(s) + "." + end1).c_str(), "r", stdin), \ freopen((string(s) + "." + end2).c_str(), "w", stdout); #define fi first #define se second #define bw(i, r, l) for (int i = r - 1; i >= l; i--) #define fw(i, l, r) for (int i = l; i < r; i++) #define fa(i, x) for (auto i : x) using namespace std; const int mod = 1e9 + 7, inf = 1061109567; const long long infll = 4557430888798830399; const int MAX = 4e18 + 5, MAX2 = 1e18; int mul(int a, int b) { if (a == 0 || b == 0) return 0; if (a > MAX / b) return MAX; return a * b; } signed main() { #ifdef BLU in("blu.inp"); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, ans = 1; cin >> n; fw(i, 0, n) { int x; cin >> x; ans = mul(ans, x); } if (ans > MAX2) cout << "-1"; else cout << ans; return 0; }
insert
19
19
19
21
0
p02658
C++
Runtime Error
#include <iostream> #define LIMIT 1000000000000000000 using namespace std; int main() { int n; unsigned long long a, ans = 1; bool overflow = false; cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (!a || a <= LIMIT / ans) { ans *= a; } else { overflow = true; } } if (!overflow || ans == 0) { cout << ans << endl; } else { cout << -1 << endl; } return 0; }
#include <iostream> #define LIMIT 1000000000000000000 using namespace std; int main() { int n; unsigned long long a, ans = 1; bool overflow = false; cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (!a || !ans || a <= LIMIT / ans) { ans *= a; } else { overflow = true; } } if (!overflow || ans == 0) { cout << ans << endl; } else { cout << -1 << endl; } return 0; }
replace
13
14
13
14
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define LL long long #define ULL unsigned LL #define LD long double const LL INF = 1e18; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; LL a; LL w = 1; bool czy = 1; for (int i = 0; i < n; i++) { cin >> a; if (a == 0) { cout << 0; return 0; } LL x = INF / w; if (x < a) { czy = 0; } w *= a; } if (czy) cout << w; else cout << -1; }
#include <bits/stdc++.h> using namespace std; #define LL long long #define ULL unsigned LL #define LD long double const LL INF = 1e18; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; LL a; LL w = 1; bool czy = 1; for (int i = 0; i < n; i++) { cin >> a; if (a == 0) { cout << 0; return 0; } LL x = INF / w; if (x < a) { czy = 0; } if (czy) w *= a; } if (czy) cout << w; else cout << -1; }
replace
29
30
29
31
0
p02658
C++
Runtime Error
// INCLUDE //------------------------------------------ #include <bits/stdc++.h> // DEFINE //------------------------------------------ #define ll long long #define ld long double #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> #define dcml(n) fixed << setprecision(n) // CONST //------------------------------------------ const ll INF = 1010000000000000017LL; const ll MOD = 1000000007LL; const ld EPS = 1e-12; const ld PI = 3.14159265358979323846; // REPEAT //------------------------------------------ #define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++) #define FORS(i, m, n) for (ll(i) = (m); (i) <= (n); (i)++) #define RFOR(i, m, n) for (ll(i) = (n)-1; (i) >= (n); (i)--) #define RFORS(i, m, n) for (ll(i) = (n); (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) #define WREPS(i, in, j, jn) REPS(i, in) REPS(j, jn) //----------------------------------------- // namespace using namespace std; // ライブラリはここに // ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ //----------------------------------------- int main(void) { ll N; cin >> N; vector<ll> A(N); REP(i, N) cin >> A[i]; ll ans = 1; bool flag = false; REP(i, N) { if (ans <= 1000000000000000000LL / A[i]) { ans *= A[i]; } else { flag = 1; } } if (!flag) { cout << ans << "\n"; } else { if (ans == 0) cout << 0 << "\n"; else cout << -1 << "\n"; } return 0; }
// INCLUDE //------------------------------------------ #include <bits/stdc++.h> // DEFINE //------------------------------------------ #define ll long long #define ld long double #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> #define dcml(n) fixed << setprecision(n) // CONST //------------------------------------------ const ll INF = 1010000000000000017LL; const ll MOD = 1000000007LL; const ld EPS = 1e-12; const ld PI = 3.14159265358979323846; // REPEAT //------------------------------------------ #define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++) #define FORS(i, m, n) for (ll(i) = (m); (i) <= (n); (i)++) #define RFOR(i, m, n) for (ll(i) = (n)-1; (i) >= (n); (i)--) #define RFORS(i, m, n) for (ll(i) = (n); (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) #define WREPS(i, in, j, jn) REPS(i, in) REPS(j, jn) //----------------------------------------- // namespace using namespace std; // ライブラリはここに // ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ //----------------------------------------- int main(void) { ll N; cin >> N; vector<ll> A(N); REP(i, N) cin >> A[i]; ll ans = 1; bool flag = false; REP(i, N) { if (A[i] == 0) { cout << 0 << "\n"; return 0; } if (ans <= 1000000000000000000LL / A[i]) { ans *= A[i]; } else { flag = 1; } } if (!flag) { cout << ans << "\n"; } else { if (ans == 0) cout << 0 << "\n"; else cout << -1 << "\n"; } return 0; }
insert
46
46
46
50
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define sz(x) (int)((x).size()) #define forn(i, n) for (int i = 0; i < n; i++) #define forse(i, s, e) for (int i = s; i < e; i++) #define pb push_back #define fi first #define se second #define all(vec) vec.begin(), vec.end() #define time() ((double)clock() / CLOCKS_PER_SEC) typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; double PI = 3.141592653589793; void solve() { int n; cin >> n; ll mul = 1; ll INF = 1e18; bool tem = 1, tem2 = 1; forn(i, n) { ll k; cin >> k; if (k <= INF / mul) { mul *= k; } else tem = 0; if (k == 0) tem2 = 0; } if (!tem2) { cout << 0; return; } cout << (tem ? mul : -1); } int main() { ios::sync_with_stdio(0); cin.tie(0); int T = 1; // cin >> T; forse(c, 1, T + 1) { // cout << "Case #" << cid << ": "; solve(); } }
#include <bits/stdc++.h> using namespace std; #define sz(x) (int)((x).size()) #define forn(i, n) for (int i = 0; i < n; i++) #define forse(i, s, e) for (int i = s; i < e; i++) #define pb push_back #define fi first #define se second #define all(vec) vec.begin(), vec.end() #define time() ((double)clock() / CLOCKS_PER_SEC) typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; double PI = 3.141592653589793; void solve() { int n; cin >> n; ll mul = 1; ll INF = 1e18; bool tem = 1, tem2 = 1; forn(i, n) { ll k; cin >> k; if (mul > 0 && k <= INF / mul) { mul *= k; } else tem = 0; if (k == 0) tem2 = 0; } if (!tem2) { cout << 0; return; } cout << (tem ? mul : -1); } int main() { ios::sync_with_stdio(0); cin.tie(0); int T = 1; // cin >> T; forse(c, 1, T + 1) { // cout << "Case #" << cid << ": "; solve(); } }
replace
28
29
28
29
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int N; cin >> N; vector<int64_t> v(N); rep(i, N) { cin >> v.at(i); if (v.at(i) == 0) { std::cout << "0" << '\n'; return 0; } } int64_t a = 1, b = 0, c = 0, x, y, z; x = 1000000000000000000; rep(i, N) { if (a >= x / b) { std::cout << "-1" << '\n'; return 0; } a *= v.at(i); } std::cout << a << '\n'; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { int N; cin >> N; vector<int64_t> v(N); rep(i, N) { cin >> v.at(i); if (v.at(i) == 0) { std::cout << "0" << '\n'; return 0; } } int64_t a = 1, b = 0, c = 0, x, y, z; x = 1000000000000000000; rep(i, N) { if (a > x / v.at(i)) { std::cout << "-1" << '\n'; return 0; } a *= v.at(i); } std::cout << a << '\n'; }
replace
18
19
18
19
-8
p02658
C++
Runtime Error
/* ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂ ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ */ #include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, // cmp, rb_tree_tag, tree_order_statistics_node_update>; #define ll long long #define mod 1000000007 #define inf 100000000000000000 #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define _it iterator #define all(_x) _x.begin(), _x.end() #define f first #define s second #define pb push_back void mahakal() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif } const ll N = 1e6 + 1; void solve() { ll n; cin >> n; vector<ll> arr(n); for (ll i = 0; i < n; i++) cin >> arr[i]; sort(arr.begin(), arr.end()); ll ans = 1, boundary = 1e18; for (ll i = 0; i < n; i++) { if ((arr[i] != 0 && arr[i] > boundary / ans) || ans < 0) { cout << -1 << endl; return; } ans = ans * arr[i]; } cout << ans << endl; } int main() { // mahakal(),fast; ll t = 1; // cin>> t; while (t--) solve(); return 0; }
/* ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂ ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ */ #include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, // cmp, rb_tree_tag, tree_order_statistics_node_update>; #define ll long long #define mod 1000000007 #define inf 100000000000000000 #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define _it iterator #define all(_x) _x.begin(), _x.end() #define f first #define s second #define pb push_back void mahakal() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif } const ll N = 1e6 + 1; void solve() { ll n; cin >> n; vector<ll> arr(n); for (ll i = 0; i < n; i++) cin >> arr[i]; sort(arr.begin(), arr.end()); ll ans = 1, boundary = 1e18; for (ll i = 0; i < n; i++) { if (arr[i] == 0 || ans == 0) { cout << 0 << endl; return; } if (arr[i] > boundary / ans || ans < 0) { cout << -1 << endl; return; } ans = ans * arr[i]; } cout << ans << endl; } int main() { // mahakal(),fast; ll t = 1; // cin>> t; while (t--) solve(); return 0; }
replace
41
42
41
46
0
p02658
C++
Runtime Error
#include <iomanip> #include <iostream> #include <math.h> #include <string> using namespace std; #define PI 3.14159265358979323846264338327950L long long res; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; bool flag = true; long long *array = new long long[N]; cin >> N; for (int i = 0; i < N; i++) { cin >> array[i]; if (array[i] == 0) { flag = false; } } res = 1; if (flag == false) { res = 0; } else { for (int i = 0; i < N; i++) { if (array[i] <= 1000000000000000000 / res) { res *= array[i]; } else { res = -1; break; } } } cout << res << endl; return 0; }
#include <iomanip> #include <iostream> #include <math.h> #include <string> using namespace std; #define PI 3.14159265358979323846264338327950L long long res; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; bool flag = true; // long long *array = new long long [N]; long long array[100010]; cin >> N; for (int i = 0; i < N; i++) { cin >> array[i]; if (array[i] == 0) { flag = false; } } res = 1; if (flag == false) { res = 0; } else { for (int i = 0; i < N; i++) { if (array[i] <= 1000000000000000000 / res) { res *= array[i]; } else { res = -1; break; } } } cout << res << endl; return 0; }
replace
16
17
16
18
0
p02658
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; unsigned long long out = 1; vector<unsigned long long> a(n); for (int x = 0; x < n; x++) { cin >> a[x]; } sort(a.begin(), a.end()); if (a[0] == 0) { cout << 0; cin >> n; } for (int x = 0; x < n; x++) { if (out > 1000000000000000000 / a[x]) { cout << -1; return 0; } out = out * a[x]; } if (out > 1000000000000000000) { cout << -1; } else { cout << out; } return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; unsigned long long out = 1; vector<unsigned long long> a(n); for (int x = 0; x < n; x++) { cin >> a[x]; } sort(a.begin(), a.end()); if (a[0] == 0) { cout << 0; return 0; } for (int x = 0; x < n; x++) { if (out > 1000000000000000000 / a[x]) { cout << -1; return 0; } out = out * a[x]; } if (out > 1000000000000000000) { cout << -1; } else { cout << out; } return 0; }
replace
24
25
24
25
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define booga cout << "booga" << endl #define ll unsigned long long int /* run this program using the console pauser or add your own getch, * system("pause") or input loop */ using namespace std; const ll lim = 1e18; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; ll ans = 1; bool fail{false}, abs = false; while (n--) { ll term; cin >> term; if (term == 0) { abs = true; } if (ans > lim / term) { fail = true; } ans *= term; } if (abs) { cout << 0; } else if (fail) { cout << -1; } else { cout << ans; } return 0; }
#include <bits/stdc++.h> #define booga cout << "booga" << endl #define ll unsigned long long int /* run this program using the console pauser or add your own getch, * system("pause") or input loop */ using namespace std; const ll lim = 1e18; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; ll ans = 1; bool fail{false}, abs = false; while (n--) { ll term; cin >> term; if (term == 0) { abs = true; } if (term != 0 && ans > lim / term) { fail = true; } ans *= term; } if (abs) { cout << 0; } else if (fail) { cout << -1; } else { cout << ans; } return 0; }
replace
22
23
22
23
0
p02658
C++
Runtime Error
// #include <bits/stdc++.h> #include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; #define all(x) begin(x), end(x) #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n; cin >> n; ll a; ll ans = 1; ll MAX = 1e18; bool flag = 0; bool zero = 0; rep(i, n) { cin >> a; if (a == 0) zero = 1; if (ans > MAX / a) flag = 1; ans *= a; // cout << ans << endl; } if (zero) cout << 0 << endl; else if (flag) cout << -1 << endl; else cout << ans << endl; return 0; }
// #include <bits/stdc++.h> #include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; #define all(x) begin(x), end(x) #define rep(i, n) for (int i = 0; i < n; i++) int main() { int n; cin >> n; ll a; ll ans = 1; ll MAX = 1e18; bool flag = 0; bool zero = 0; rep(i, n) { cin >> a; if (a == 0) zero = 1; // else if (ans > MAX/a) flag = 1; if (ans != 0) if (a > MAX / ans) flag = 1; ans *= a; // cout << ans << endl; } if (zero) cout << 0 << endl; else if (flag) cout << -1 << endl; else cout << ans << endl; return 0; }
replace
37
39
37
41
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; vector<long long> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } long long X = 1; long long Y = 1; sort(A.begin(), A.end()); if (A.at(0) == 0) { X = 0; } for (int i = 0; i < 18; i++) { Y = Y * 10; } for (int i = 0; i < N; i++) { long long emer = Y / X + 1; X *= A.at(i); if (X > Y || A.at(i) > emer) { cout << -1 << endl; exit(0); } } cout << X << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; vector<long long> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } long long X = 1; long long Y = 1; sort(A.begin(), A.end()); if (A.at(0) == 0) { cout << 0 << endl; exit(0); } for (int i = 0; i < 18; i++) { Y = Y * 10; } for (int i = 0; i < N; i++) { long long emer = Y / X + 1; X *= A.at(i); if (X > Y || A.at(i) > emer) { cout << -1 << endl; exit(0); } } cout << X << endl; }
replace
20
21
20
22
0
p02658
C++
Runtime Error
#include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; long long arr[100010]; int main() { long long sum = 1; long long n; cin >> n; long long max = pow(10, 18); for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n; i++) { if (arr[i] == 0) { cout << 0 << endl; return 0; } } for (int i = 0; i < n; i++) { if (arr[i] <= max / sum) { sum *= arr[i]; } else { cout << -1 << endl; return 1; } } cout << sum << endl; return 0; }
#include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; long long arr[100010]; int main() { long long sum = 1; long long n; cin >> n; long long max = pow(10, 18); for (int i = 0; i < n; i++) { cin >> arr[i]; } for (int i = 0; i < n; i++) { if (arr[i] == 0) { cout << 0 << endl; return 0; } } for (int i = 0; i < n; i++) { if (arr[i] <= max / sum) { sum *= arr[i]; } else { cout << -1 << endl; return 0; } } cout << sum << endl; return 0; }
replace
25
26
25
26
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unsigned long long int arr[n]; unsigned long long int pro = 1, temp; int flag = 0, flag1 = 0; for (int a = 0; a < n; a++) { cin >> arr[a]; if (arr[a] == 0) { flag = 1; cout << "0"; break; } } if (flag == 0) { for (int a = 0; a < n; a++) { temp = pro; pro *= arr[a]; if (pro > 1000000000000000000 || (pro / a) != temp) { cout << "-1"; flag1 = 1; break; } } if (flag1 == 0) cout << pro; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unsigned long long int arr[n]; unsigned long long int pro = 1, temp; int flag = 0, flag1 = 0; for (int a = 0; a < n; a++) { cin >> arr[a]; if (arr[a] == 0) { flag = 1; cout << "0"; break; } } if (flag == 0) { for (int a = 0; a < n; a++) { temp = pro; pro *= arr[a]; if (pro > 1000000000000000000 || (pro / arr[a]) != temp) { cout << "-1"; flag1 = 1; break; } } if (flag1 == 0) cout << pro; } }
replace
20
21
20
21
-8
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) typedef long long ll; using namespace std; int main() { int n; ll ans = 1; cin >> n; bool over = false; bool zero = false; rep(i, n) { ll a; cin >> a; if (ans > 1000000000000000000 / a) { ans = -1; over = true; } else { ans *= a; } if (a == 0) zero = true; } if (!zero && over) ans = -1; cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) typedef long long ll; using namespace std; int main() { int n; ll ans = 1; cin >> n; bool over = false; bool zero = false; rep(i, n) { ll a; cin >> a; if (a == 0) { zero = true; ans = 0; continue; } if (ans > 1000000000000000000 / a) { ans = -1; over = true; } else { ans *= a; } if (a == 0) zero = true; } if (!zero && over) ans = -1; cout << ans << endl; }
insert
16
16
16
21
0
p02658
C++
Runtime Error
#include <algorithm> // sort, lower_bound, heap, min, next_permutation #include <bitset> // bitset #include <cmath> // sin, exp, log, pow, sqrt #include <cstdio> // fopen, printf, scanf, puts #include <ctime> // clock #include <functional> // greater, less #include <iomanip> // setfill, setbase #include <iostream> // cin, cout #include <list> // list #include <map> // map #include <queue> // queue #include <set> // set #include <stack> // stack #include <string> // string, stoi, to_string #include <tuple> // tuple #include <vector> // vector using namespace std; using pii = pair<int, int>; using ti = tuple<int, int, int>; const double eps = 1e-14; const int mod = 1e9 + 7; const int inf = ((1 << 30)); const long long linf = (1LL << 60); int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; long long ans = 1; bool ok = true; long long A[n]; for (int i = 0; i < n; i++) cin >> A[i]; sort(A, A + n); for (int i = 0; i < n; i++) { if (ans <= 1000000000000000000 / A[i]) { ans *= A[i]; } else { ok = false; break; } } if (ok) cout << ans << endl; else cout << -1 << endl; return 0; }
#include <algorithm> // sort, lower_bound, heap, min, next_permutation #include <bitset> // bitset #include <cmath> // sin, exp, log, pow, sqrt #include <cstdio> // fopen, printf, scanf, puts #include <ctime> // clock #include <functional> // greater, less #include <iomanip> // setfill, setbase #include <iostream> // cin, cout #include <list> // list #include <map> // map #include <queue> // queue #include <set> // set #include <stack> // stack #include <string> // string, stoi, to_string #include <tuple> // tuple #include <vector> // vector using namespace std; using pii = pair<int, int>; using ti = tuple<int, int, int>; const double eps = 1e-14; const int mod = 1e9 + 7; const int inf = ((1 << 30)); const long long linf = (1LL << 60); int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; long long ans = 1; bool ok = true; long long A[n]; for (int i = 0; i < n; i++) cin >> A[i]; sort(A, A + n); for (int i = 0; i < n; i++) { if (A[i] == 0) { ans = 0; break; } else if (ans <= 1000000000000000000 / A[i]) { ans *= A[i]; } else { ok = false; break; } } if (ok) cout << ans << endl; else cout << -1 << endl; return 0; }
replace
38
39
38
42
0
p02658
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++) const int inf = 1000000000; int main() { int n; cin >> n; ll pro = 1; bool boo = false; for (int i = 0; i < n; i++) { ll proo = pro; ll a; cin >> a; if (a == 0) { cout << 0 << endl; } if (pro > 1000000000000000000 / a) { boo = true; } pro *= a; } if (boo) { cout << -1 << endl; return 0; } if (pro > 1000000000000000000) { cout << -1 << endl; return 0; } cout << pro << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const int inf = 1000000000; int main() { int n; cin >> n; ll pro = 1; bool boo = false; for (int i = 0; i < n; i++) { ll proo = pro; ll a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (pro > 1000000000000000000 / a) { boo = true; } pro *= a; } if (boo) { cout << -1 << endl; return 0; } if (pro > 1000000000000000000) { cout << -1 << endl; return 0; } cout << pro << endl; }
insert
17
17
17
18
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define xx first #define yy second #define D if (0) #define cerr D cerr using namespace std; typedef long long ll; template <typename T> vector<T> read_n(ll n) { vector<T> ret(n); for (ll i = 0; i < n; i++) cin >> ret[i]; return ret; } template <typename iter> void dump(iter begin, iter end) { for (iter it = begin; it != end; it++) { if (it != begin) cout << " "; cout << *it; } cout << endl; } const ll top = 1e18; int main() { cin.tie(0); ios_base::sync_with_stdio(0); ll ret = 1; ll n; cin >> n; int fail = 0; for (ll i = 0; i < n; i++) { ll x; cin >> x; if (top / ret < x) { fail = 1; } if (x == 0) { fail = 0; } ret *= x; } if (fail) { cout << "-1\n"; } else { cout << ret << "\n"; } return 0; }
#include <bits/stdc++.h> #define xx first #define yy second #define D if (0) #define cerr D cerr using namespace std; typedef long long ll; template <typename T> vector<T> read_n(ll n) { vector<T> ret(n); for (ll i = 0; i < n; i++) cin >> ret[i]; return ret; } template <typename iter> void dump(iter begin, iter end) { for (iter it = begin; it != end; it++) { if (it != begin) cout << " "; cout << *it; } cout << endl; } const ll top = 1e18; int main() { cin.tie(0); ios_base::sync_with_stdio(0); ll ret = 1; ll n; cin >> n; int fail = 0; for (ll i = 0; i < n; i++) { ll x; cin >> x; if (ret != 0 && top / ret < x) { fail = 1; } if (x == 0) { fail = 0; } ret *= x; } if (fail) { cout << "-1\n"; } else { cout << ret << "\n"; } return 0; }
replace
40
41
40
41
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename Tu> static inline constexpr bool is_multiplication_safe(Tu a, Tu b) { return !a || b <= numeric_limits<Tu>::max() / a; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll ans = 1, a = 0; int n; bool over = false, zero = false; cin >> n; for (int i = 0; i < n; ++i) { cin >> a; if (a == 0) { zero = true; break; } if (ans * a > 1000000000000000000ll || !is_multiplication_safe(ans, a)) over = true; ans *= a; } if (zero) printf("0\n"); else if (over) printf("-1\n"); else printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename Tu> static inline constexpr bool is_multiplication_safe(Tu a, Tu b) { return !a || b <= numeric_limits<Tu>::max() / a; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll ans = 1, a = 0; int n; bool over = false, zero = false; cin >> n; for (int i = 0; i < n; ++i) { cin >> a; if (a == 0) { zero = true; break; } if (!over) { if (ans * a > 1000000000000000000ll || !is_multiplication_safe(ans, a)) over = true; ans *= a; } } if (zero) printf("0\n"); else if (over) printf("-1\n"); else printf("%lld\n", ans); return 0; }
replace
26
29
26
31
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; inline int ctoi(char c) { if (c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++) #define all(x) (x).begin(), (x).end() template <typename T> inline T gcd(T x, T y) { if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0"); if (x < y) swap(x, y); T r = x % y; while (r != 0) { x = y; y = r; r = x % y; } return y; } template <typename T> inline T lcm(T x, T y) { if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0"); return x * y / gcd(x, y); } int main() { int n; cin >> n; vector<unsigned long long int> input; rep(i, n) { unsigned long long int a; cin >> a; if (a == 0) { cout << 0; return 0; } } unsigned long long ans = input[0]; REP(i, 1, input.size()) { if (18 <= log10(ans) + log10(input[i])) { if (1000000000000000000 / ans == input[i]) { ans = 1000000000000000000; } else { cout << -1; return 0; } } else { ans *= input[i]; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; inline int ctoi(char c) { if (c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++) #define all(x) (x).begin(), (x).end() template <typename T> inline T gcd(T x, T y) { if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0"); if (x < y) swap(x, y); T r = x % y; while (r != 0) { x = y; y = r; r = x % y; } return y; } template <typename T> inline T lcm(T x, T y) { if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0"); return x * y / gcd(x, y); } int main() { int n; cin >> n; vector<unsigned long long int> input; rep(i, n) { unsigned long long int a; cin >> a; if (a == 0) { cout << 0; return 0; } input.push_back(a); } unsigned long long ans = input[0]; REP(i, 1, input.size()) { if (18 <= log10(ans) + log10(input[i])) { if (1000000000000000000 / ans == input[i]) { ans = 1000000000000000000; } else { cout << -1; return 0; } } else { ans *= input[i]; } } cout << ans; return 0; }
insert
50
50
50
52
-11
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<unsigned long long> a(n); for (int i = 0; i < n; i++) { cin >> a.at(i); } sort(a.begin(), a.end()); unsigned long long s = 1; for (int i = 0; i < n; i++) { if (a.at(i) == 0) { cout << 0 << endl; } if (1000000000000000000 / s < a.at(i)) { cout << -1 << endl; return 0; } s *= a.at(i); } cout << s << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<unsigned long long> a(n); for (int i = 0; i < n; i++) { cin >> a.at(i); } sort(a.begin(), a.end()); unsigned long long s = 1; for (int i = 0; i < n; i++) { if (a.at(i) == 0) { cout << 0 << endl; return 0; } if (1000000000000000000 / s < a.at(i)) { cout << -1 << endl; return 0; } s *= a.at(i); } cout << s << endl; return 0; }
insert
17
17
17
18
0
p02658
C++
Runtime Error
/* winners never quit and quitters never win. #swap */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("-O3") using ll = long long; using ld = long double; const ll mod = 1000000007; const ll inf = 1000000000000000000; const ll rk = 256; const ld PI = 3.141592653589793; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; template <typename T> void make_unique(vector<T> &vec) { sort(all(vec)); vec.erase(unique(all(vec)), vec.end()); } #define endl '\n' #define pb push_back #define mp make_pair #define vc vector #define fs first #define sec second #define pq priority_queue #define lb lower_bound #define ub upper_bound #define pll pair<ll, ll> #define pls pair<ll, string> #define psl pair<string, ll> #define plc pair<ll, char> #define pcl pair<char, ll> #define pss pair<string, string> #define all(x) (x).begin(), (x).end() #define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower); #define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper); #define printclock \ cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define T \ ll t = 0; \ cin >> t; \ for (ll test = 0; test < t; test++) ll nxt() { ll TemporaryVariable; cin >> TemporaryVariable; return TemporaryVariable; } struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // isprime(); // coeff(); /*freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);*/ ll n = nxt(); ll ans = 1; rep(a, 0, n) { ll b = nxt(); if (b == 0) { ans = 0; } if (b > inf / ans) { ans = -1; } if (ans != -1) { ans *= b; } } cout << ans << endl; printclock; return 0; }
/* winners never quit and quitters never win. #swap */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("-O3") using ll = long long; using ld = long double; const ll mod = 1000000007; const ll inf = 1000000000000000000; const ll rk = 256; const ld PI = 3.141592653589793; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; template <typename T> void make_unique(vector<T> &vec) { sort(all(vec)); vec.erase(unique(all(vec)), vec.end()); } #define endl '\n' #define pb push_back #define mp make_pair #define vc vector #define fs first #define sec second #define pq priority_queue #define lb lower_bound #define ub upper_bound #define pll pair<ll, ll> #define pls pair<ll, string> #define psl pair<string, ll> #define plc pair<ll, char> #define pcl pair<char, ll> #define pss pair<string, string> #define all(x) (x).begin(), (x).end() #define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower); #define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper); #define printclock \ cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define T \ ll t = 0; \ cin >> t; \ for (ll test = 0; test < t; test++) ll nxt() { ll TemporaryVariable; cin >> TemporaryVariable; return TemporaryVariable; } struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // isprime(); // coeff(); /*freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);*/ ll n = nxt(); ll ans = 1; rep(a, 0, n) { ll b = nxt(); if (b == 0) { ans = 0; } if (ans > 0 and b > inf / ans) { ans = -1; } if (ans != -1) { ans *= b; } } cout << ans << endl; printclock; return 0; }
replace
107
108
107
108
0
Time : 25.315ms
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; int flag = 0; long long result = 1; cin >> N; vector<long long> A(N); for (int a = 0; a < N; a++) cin >> A[a]; sort(A.begin(), A.end()); for (int a = 0; a < N; a++) { if (1000000000000000000 / result < A[a]) { result = -1; break; } result *= A[a]; } cout << result << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; int flag = 0; long long result = 1; cin >> N; vector<long long> A(N); for (int a = 0; a < N; a++) cin >> A[a]; sort(A.begin(), A.end()); for (int a = 0; a < N; a++) { if (result != 0) { if (1000000000000000000 / result < A[a]) { result = -1; break; } } result *= A[a]; } cout << result << endl; }
replace
12
15
12
17
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p; const int inf = (1 << 30); #define rep(i, a, n) for (int i = a; i < n; i++) #define rrep(i, a, n) for (int i = (a - 1); i >= n; i--) int main() { ll n; cin >> n; ll sum = 1; ll a[n]; rep(i, 0, n) cin >> a[i]; sort(a, a + n); rep(i, 0, n) { if (a[i] > 1000000000000000000 / sum) { cout << "-1" << endl; return 0; } else sum *= a[i]; } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p; const int inf = (1 << 30); #define rep(i, a, n) for (int i = a; i < n; i++) #define rrep(i, a, n) for (int i = (a - 1); i >= n; i--) int main() { ll n; cin >> n; ll sum = 1; ll a[n]; rep(i, 0, n) cin >> a[i]; sort(a, a + n); rep(i, 0, n) { if (a[i] == 0) { cout << "0" << endl; return 0; } else if (a[i] > 1000000000000000000 / sum) { cout << "-1" << endl; return 0; } else sum *= a[i]; } cout << sum << endl; }
replace
16
17
16
20
0
p02658
C++
Runtime Error
#include <stdio.h> int main() { int berapaKali; long long a1[10001]; long long a2 = 1; long long max = 1000000000000000000; scanf("%d", &berapaKali); for (int j = 0; j < berapaKali; j++) { scanf("%lld", &a1[j]); if (a1[j] == 0) { printf("0"); return 0; } } for (int i = 0; i < berapaKali; i++) { if (a1[i] > max) { printf("-1"); return 0; } a2 *= a1[i]; max /= a1[i]; } printf("%lld", a2); return 0; }
#include <stdio.h> int main() { int berapaKali; long long a1[100001]; long long a2 = 1; long long max = 1000000000000000000; scanf("%d", &berapaKali); for (int j = 0; j < berapaKali; j++) { scanf("%lld", &a1[j]); if (a1[j] == 0) { printf("0"); return 0; } } for (int i = 0; i < berapaKali; i++) { if (a1[i] > max) { printf("-1"); return 0; } a2 *= a1[i]; max /= a1[i]; } printf("%lld", a2); return 0; }
replace
5
6
5
6
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) const ll MOD = 1000000007; const long double PI = 3.14159265358979; const ll MAX = 0; int main() { ll N; cin >> N; ll A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } ll ans = 1; sort(A, A + N); for (int i = 0; i < N; i++) { if (ans > 1000000000000000000 / A[i]) { ans = -1; break; } ans *= A[i]; if (ans > 1000000000000000000) { ans = -1; break; } if (ans < 0) { ans = -1; break; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) const ll MOD = 1000000007; const long double PI = 3.14159265358979; const ll MAX = 0; int main() { ll N; cin >> N; ll A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } ll ans = 1; sort(A, A + N); for (int i = 0; i < N; i++) { if (A[i] == 0) { ans = 0; break; } if (ans > 1000000000000000000 / A[i]) { ans = -1; break; } ans *= A[i]; if (ans > 1000000000000000000) { ans = -1; break; } if (ans < 0) { ans = -1; break; } } cout << ans; }
insert
18
18
18
22
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using lint = long long; const lint MAX = 1e18; int main(void) { int N; cin >> N; lint ans = 1; int over = 0; int zero = 0; for (int i = 0; i < N; i++) { long long x; cin >> x; if (x == 0) { zero = 1; } else if (MAX / ans < x) { over = -1; } ans *= x; // cout << ans << endl; } if (zero == 1) cout << 0 << endl; else if (over == 0) cout << ans << endl; else cout << over << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using lint = long long; const lint MAX = 1e18; int main(void) { int N; cin >> N; lint ans = 1; int over = 0; int zero = 0; for (int i = 0; i < N; i++) { long long x; cin >> x; if (x == 0) { zero = 1; } else if (ans != 0 && MAX / ans < x) { over = -1; } ans *= x; // cout << ans << endl; } if (zero == 1) cout << 0 << endl; else if (over == 0) cout << ans << endl; else cout << over << endl; }
replace
20
21
20
21
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, ans = 1; bool zeros = false, o = false; cin >> n; vector<ll> a(n); for (ll i = 0; i < n; i++) { scanf("%lld", &a[i]); if (a[i] == 0) zeros = true; } for (ll i = 0; i < n; i++) { if (ans > 1000000000000000000 / a[i]) { o = true; } else { ans *= a[i]; } } if (zeros) cout << 0 << endl; else if (o) cout << -1 << endl; else cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, ans = 1; bool zeros = false, o = false; cin >> n; vector<ll> a(n); for (ll i = 0; i < n; i++) { scanf("%lld", &a[i]); if (a[i] == 0) zeros = true; } if (!zeros) { for (ll i = 0; i < n; i++) { if (ans > 1000000000000000000 / a[i]) { o = true; } else { ans *= a[i]; } } } if (zeros) cout << 0 << endl; else if (o) cout << -1 << endl; else cout << ans << endl; }
replace
13
18
13
20
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include <iostream> #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; typedef unsigned long long ui64; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } const int mod = 1000000007; i64 poww(i64 a, i64 b) { a %= mod; i64 res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b /= 2; } return res; } i64 inv(i64 a) { return poww(a, mod - 2); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // ifstream fin(".in"); // ofstream fout(".in"); i64 n, x; cin >> n; i64 pr = 1; bool is1 = false, is2 = false; i64 mx = 1e18; forn(i, n) { cin >> x; // cout<<x<<" "<<(mx/pr)<<"\n"; if (x == 0) { is2 = true; pr = 0; } if (pr > mx || x > (mx / pr) || is1) { is1 = true; } else pr *= x; } // cout<<is1<<" "<<is2<<" "; if (is1 && !is2) cout << "-1"; else cout << pr; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <functional> #include <iostream> #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; typedef unsigned long long ui64; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } const int mod = 1000000007; i64 poww(i64 a, i64 b) { a %= mod; i64 res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b /= 2; } return res; } i64 inv(i64 a) { return poww(a, mod - 2); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // ifstream fin(".in"); // ofstream fout(".in"); i64 n, x; cin >> n; i64 pr = 1; bool is1 = false, is2 = false; i64 mx = 1e18; forn(i, n) { cin >> x; // cout<<x<<" "<<(mx/pr)<<"\n"; if (x == 0) { is2 = true; pr = 0; break; } if (pr > mx || x > (mx / pr) || is1) { is1 = true; } else pr *= x; } // cout<<is1<<" "<<is2<<" "; if (is1 && !is2) cout << "-1"; else cout << pr; return 0; }
insert
70
70
70
71
0
p02658
C++
Runtime Error
#include <iostream> using namespace std; int main() { long long A[100100]; int N; cin >> N; for (int i = 0; i < N; i++) { long long a; cin >> a; if (a == 0) { cout << "0" << endl; return 0; } } long long ans = 1; for (int i = 0; i < N; i++) { if (A[i] <= 1000000000000000000 / ans) { ans *= A[i]; } else { cout << "-1" << endl; return 0; } } cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main() { long long A[100100]; int N; cin >> N; for (int i = 0; i < N; i++) { long long a; cin >> a; if (a == 0) { cout << "0" << endl; return 0; } else { A[i] = a; } } long long ans = 1; for (int i = 0; i < N; i++) { if (A[i] <= 1000000000000000000 / ans) { ans *= A[i]; } else { cout << "-1" << endl; return 0; } } cout << ans << endl; return 0; }
insert
14
14
14
16
-8
p02658
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; #define rep(i, a, b) for (int i = a; i < (b); ++i) int main() { int n; cin >> n; long long ans = 1; long long MX = 1e18; bool ng = false; rep(i, 0, n) { long long a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (MX / ans < a) { ng = true; } ans *= a; } if (ng) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; #define rep(i, a, b) for (int i = a; i < (b); ++i) int main() { int n; cin >> n; long long ans = 1; long long MX = 1e18; bool ng = false; rep(i, 0, n) { long long a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (ng || MX / ans < a) { ng = true; } ans *= a; } if (ng) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }
replace
22
23
22
23
0
p02658
C++
Runtime Error
// #include <bits/stdc++.h> #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <set> #include <string> #include <vector> #define PI 3.14159265358979323846264338327950288 #define rep(i, n) for (int i = 0; i < n; i++) #define exf(x) \ for (auto &&tmp : x) { \ cout << tmp << endl; \ } // 拡張for #define testP \ cout << "------------------ test ------------------" \ << endl; // 動作確認テスト #define testX(x) cout << "testout : " << x << endl; // テストアウト typedef long long ll; using namespace std; const int MOD{int(1e9 + 7)}; // = 1000000007 const int inf{2100000000}; // = 2100000000 (MAX:2147483647) // ------------------ ベクター表示 ------------------ // void printVec(vector<int> &vec) { cout << ""; for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " "; cout << endl; } // ------------------ ベクター合計 ------------------ // int sumVec(vector<int> v) { int sum = 0; for (size_t i = 0; i < v.size(); i++) sum += v[i]; return sum; } // -------------------------------------------------- // // ------------------ ここから本編 ------------------ // // -------------------------------------------------- // int main(void) { ll N; cin >> N; vector<ll> A(N); bool ck = false; rep(i, N) { cin >> A[i]; if (A[i] == 0) ck = true; } if (ck == true) { cout << 0 << endl; } else { ll ans = A[0]; for (int i = 1; i < N; i++) { ans *= A[i]; if (ans > (ll)1e18 || (ll)1e18 / ans < A[i]) { cout << "-1" << endl; return 0; } } cout << ans << endl; } return 0; }
// #include <bits/stdc++.h> #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <set> #include <string> #include <vector> #define PI 3.14159265358979323846264338327950288 #define rep(i, n) for (int i = 0; i < n; i++) #define exf(x) \ for (auto &&tmp : x) { \ cout << tmp << endl; \ } // 拡張for #define testP \ cout << "------------------ test ------------------" \ << endl; // 動作確認テスト #define testX(x) cout << "testout : " << x << endl; // テストアウト typedef long long ll; using namespace std; const int MOD{int(1e9 + 7)}; // = 1000000007 const int inf{2100000000}; // = 2100000000 (MAX:2147483647) // ------------------ ベクター表示 ------------------ // void printVec(vector<int> &vec) { cout << ""; for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " "; cout << endl; } // ------------------ ベクター合計 ------------------ // int sumVec(vector<int> v) { int sum = 0; for (size_t i = 0; i < v.size(); i++) sum += v[i]; return sum; } // -------------------------------------------------- // // ------------------ ここから本編 ------------------ // // -------------------------------------------------- // int main(void) { ll N; cin >> N; vector<ll> A(N); bool ck = false; rep(i, N) { cin >> A[i]; if (A[i] == 0) ck = true; } if (ck == true) { cout << 0 << endl; } else { ll ans = A[0]; for (int i = 1; i < N; i++) { if (A[i] <= (ll)1e18 / ans) { ans *= A[i]; } else { cout << "-1" << endl; return 0; } } cout << ans << endl; } return 0; }
replace
60
62
60
63
0