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
p02965
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mod 998244353 #define MN 1500000 inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n, m, ans, p[MN + 5], inv[MN + 5]; inline int C(int n, int m) { return m > n ? 0 : 1LL * p[n] * inv[m] % mod * inv[n - m] % mod; } int main() { n = read(); m = read(); p[0] = p[1] = inv[0] = inv[1] = 1; for (int i = 2; i <= MN; ++i) p[i] = 1LL * p[i - 1] * i % mod, inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod; for (int i = 2; i <= MN; ++i) inv[i] = 1LL * inv[i - 1] * inv[i] % mod; if (n == 2) return 0 * printf("%d\n", m + 1); for (int i = 0; i <= m; i += 2) if (m - i <= n) { int t = i / 2 + m; ans = (ans + 1LL * C(n, m - i) * C(t + n - 1, n - 1)) % mod; ans = (ans + 1LL * C(n, m - i) * (mod - (m - i)) % mod * C(t - m + n - 1, n - 1)) % mod; ans = (ans + 1LL * C(n, m - i) * (mod - (n - (m - i))) % mod * C(t - m + n - 2, n - 1)) % mod; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define mod 998244353 #define MN 2500000 inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int n, m, ans, p[MN + 5], inv[MN + 5]; inline int C(int n, int m) { return m > n ? 0 : 1LL * p[n] * inv[m] % mod * inv[n - m] % mod; } int main() { n = read(); m = read(); p[0] = p[1] = inv[0] = inv[1] = 1; for (int i = 2; i <= MN; ++i) p[i] = 1LL * p[i - 1] * i % mod, inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod; for (int i = 2; i <= MN; ++i) inv[i] = 1LL * inv[i - 1] * inv[i] % mod; if (n == 2) return 0 * printf("%d\n", m + 1); for (int i = 0; i <= m; i += 2) if (m - i <= n) { int t = i / 2 + m; ans = (ans + 1LL * C(n, m - i) * C(t + n - 1, n - 1)) % mod; ans = (ans + 1LL * C(n, m - i) * (mod - (m - i)) % mod * C(t - m + n - 1, n - 1)) % mod; ans = (ans + 1LL * C(n, m - i) * (mod - (n - (m - i))) % mod * C(t - m + n - 2, n - 1)) % mod; } cout << ans; return 0; }
replace
3
4
3
4
0
p02965
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using i64 = long long; template <i64 M> constexpr i64 euinv(i64 val) { i64 a = M, b = val; i64 x = 0, u = 1; while (b) { i64 t = a / b; swap(a -= t * b, b); swap(x -= t * u, u); } return x < 0 ? x + M : x; } template <i64 M> struct modint { i64 a; constexpr modint(const i64 x = 0) noexcept : a((x % M + M) % M) {} constexpr i64 value() const noexcept { return a; } constexpr modint inv() const noexcept { return modint(euinv<M>(a)); } constexpr modint pow(i64 r) const noexcept { modint ans(1); modint aa = *this; while (r) { if (r & 1) { ans *= aa; } aa *= aa; r >>= 1; } return ans; } constexpr modint &operator+=(const modint r) noexcept { a += r.a; if (a >= M) a -= M; return *this; } constexpr modint &operator=(const i64 r) { a = (r % M + M) % M; return *this; } constexpr modint &operator-=(const modint r) noexcept { a -= r.a; if (a < 0) a += M; return *this; } constexpr modint &operator*=(const modint r) noexcept { a = a * r.a % M; return *this; } constexpr modint &operator/=(modint r) noexcept { i64 ex = M - 2; while (ex) { if (ex & 1) { *this *= r; } r *= r; ex >>= 1; } return *this; } constexpr modint operator+(const modint r) const { return modint(*this) += r; } constexpr modint operator-(const modint r) const { return modint(*this) -= r; } constexpr modint operator*(const modint r) const { return modint(*this) *= r; } constexpr modint operator/(const modint r) const { return modint(*this) /= r; } constexpr bool operator!=(const modint r) const { return this->value() != r.value(); } }; template <const i64 M> std::ostream &operator<<(std::ostream &os, const modint<M> &m) { os << m.value(); return os; } #include <vector> using i64 = long long; template <class T> void build_factorial(std::vector<T> &fact, std::vector<T> &finv, std::vector<T> &inv) { std::size_t N = fact.size(); fact[0] = T(1); for (int i = 1; i < N; i++) { fact[i] = fact[i - 1] * T(i); } finv[N - 1] = T(1) / fact[N - 1]; for (int i = N - 1; i-- > 0;) { finv[i] = finv[i + 1] * T(i + 1); } for (int i = 0; i < N; i++) { inv[i] = fact[i - 1] * finv[i]; } } using fp = modint<998244353>; #include <bits/stdc++.h> using namespace std; using i64 = long long; #define rep(i, s, e) for (i64(i) = (s); (i) < (e); (i)++) #define all(x) x.begin(), x.end() template <class T> static inline std::vector<T> ndvec(size_t &&n, T val) noexcept { return std::vector<T>(n, std::forward<T>(val)); } template <class... Tail> static inline auto ndvec(size_t &&n, Tail &&...tail) noexcept { return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>( n, ndvec(std::forward<Tail>(tail)...)); } template <class T, class Cond> struct chain { Cond cond; chain(Cond cond) : cond(cond) {} bool operator()(T &a, const T &b) const { if (cond(a, b)) { a = b; return true; } return false; } }; template <class T, class Cond> chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); } int main() { i64 N, M; cin >> N >> M; vector<fp> fact(M + N + 1000); vector<fp> finv(M + N + 1000); vector<fp> inv(M + N + 1000); build_factorial(fact, finv, inv); auto binom = [&](i64 n, i64 r) { if (0 <= r && r <= n) return fact[n] * finv[r] * finv[n - r]; return fp(0); }; fp ans(0); rep(i, 0, M + 1) { if ((3 * M - i) % 2 == 0) { ans += binom(N, i) * binom((3 * M - i) / 2 + N - 1, N - 1); } } rep(i, 0, M + 1) { if ((M - i) % 2 == 0) { ans -= binom(N, i) * binom((M - i) / 2 + N - 1, N - 1) * fp(N); } } N--; rep(i, 0, M + 1) { if ((M - i) % 2 == 0) { ans += binom(N, i) * binom((M - i) / 2 + N - 1, N - 1) * fp(N + 1); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using i64 = long long; template <i64 M> constexpr i64 euinv(i64 val) { i64 a = M, b = val; i64 x = 0, u = 1; while (b) { i64 t = a / b; swap(a -= t * b, b); swap(x -= t * u, u); } return x < 0 ? x + M : x; } template <i64 M> struct modint { i64 a; constexpr modint(const i64 x = 0) noexcept : a((x % M + M) % M) {} constexpr i64 value() const noexcept { return a; } constexpr modint inv() const noexcept { return modint(euinv<M>(a)); } constexpr modint pow(i64 r) const noexcept { modint ans(1); modint aa = *this; while (r) { if (r & 1) { ans *= aa; } aa *= aa; r >>= 1; } return ans; } constexpr modint &operator+=(const modint r) noexcept { a += r.a; if (a >= M) a -= M; return *this; } constexpr modint &operator=(const i64 r) { a = (r % M + M) % M; return *this; } constexpr modint &operator-=(const modint r) noexcept { a -= r.a; if (a < 0) a += M; return *this; } constexpr modint &operator*=(const modint r) noexcept { a = a * r.a % M; return *this; } constexpr modint &operator/=(modint r) noexcept { i64 ex = M - 2; while (ex) { if (ex & 1) { *this *= r; } r *= r; ex >>= 1; } return *this; } constexpr modint operator+(const modint r) const { return modint(*this) += r; } constexpr modint operator-(const modint r) const { return modint(*this) -= r; } constexpr modint operator*(const modint r) const { return modint(*this) *= r; } constexpr modint operator/(const modint r) const { return modint(*this) /= r; } constexpr bool operator!=(const modint r) const { return this->value() != r.value(); } }; template <const i64 M> std::ostream &operator<<(std::ostream &os, const modint<M> &m) { os << m.value(); return os; } #include <vector> using i64 = long long; template <class T> void build_factorial(std::vector<T> &fact, std::vector<T> &finv, std::vector<T> &inv) { std::size_t N = fact.size(); fact[0] = T(1); for (int i = 1; i < N; i++) { fact[i] = fact[i - 1] * T(i); } finv[N - 1] = T(1) / fact[N - 1]; for (int i = N - 1; i-- > 0;) { finv[i] = finv[i + 1] * T(i + 1); } for (int i = 0; i < N; i++) { inv[i] = fact[i - 1] * finv[i]; } } using fp = modint<998244353>; #include <bits/stdc++.h> using namespace std; using i64 = long long; #define rep(i, s, e) for (i64(i) = (s); (i) < (e); (i)++) #define all(x) x.begin(), x.end() template <class T> static inline std::vector<T> ndvec(size_t &&n, T val) noexcept { return std::vector<T>(n, std::forward<T>(val)); } template <class... Tail> static inline auto ndvec(size_t &&n, Tail &&...tail) noexcept { return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>( n, ndvec(std::forward<Tail>(tail)...)); } template <class T, class Cond> struct chain { Cond cond; chain(Cond cond) : cond(cond) {} bool operator()(T &a, const T &b) const { if (cond(a, b)) { a = b; return true; } return false; } }; template <class T, class Cond> chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); } int main() { i64 N, M; cin >> N >> M; vector<fp> fact(M * 3 + N); vector<fp> finv(M * 3 + N); vector<fp> inv(M * 3 + N); build_factorial(fact, finv, inv); auto binom = [&](i64 n, i64 r) { if (0 <= r && r <= n) return fact[n] * finv[r] * finv[n - r]; return fp(0); }; fp ans(0); rep(i, 0, M + 1) { if ((3 * M - i) % 2 == 0) { ans += binom(N, i) * binom((3 * M - i) / 2 + N - 1, N - 1); } } rep(i, 0, M + 1) { if ((M - i) % 2 == 0) { ans -= binom(N, i) * binom((M - i) / 2 + N - 1, N - 1) * fp(N); } } N--; rep(i, 0, M + 1) { if ((M - i) % 2 == 0) { ans += binom(N, i) * binom((M - i) / 2 + N - 1, N - 1) * fp(N + 1); } } cout << ans << endl; }
replace
145
148
145
148
0
p02965
C++
Runtime Error
#include <bits/stdc++.h> using ll = long long; using namespace std; const ll MAX = 1500100, MOD = 998244353; ll fac[MAX], finv[MAX], inv[MAX]; // 前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数の計算 ll COM(int n, int k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { int n, m; cin >> n >> m; COMinit(); ll ans = 0; if (m % 2 == 0) { for (int i = 0; i <= m; i += 2) { ans += COM((3 * m - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD; // 奇数がi個 ans -= COM((m - 2 - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD * n % MOD; // 2n+2以上 ans -= COM((m - i) / 2 + n - 2, n - 2) * COM(n - 1, i - 1) % MOD * n % MOD; // 2n+1 ans += MOD; ans %= MOD; } } if (m % 2 == 1) { for (int i = 1; i <= m; i += 2) { ans += COM((3 * m - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD; // 奇数がi個 ans -= COM((m - 2 - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD * n % MOD; // 2n+2以上 ans -= COM((m - i) / 2 + n - 2, n - 2) * COM(n - 1, i - 1) % MOD * n % MOD; // 2n+1 ans += MOD; ans %= MOD; } } cout << ans << endl; }
#include <bits/stdc++.h> using ll = long long; using namespace std; const ll MAX = 3500100, MOD = 998244353; ll fac[MAX], finv[MAX], inv[MAX]; // 前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数の計算 ll COM(int n, int k) { if (n < 0 || k < 0 || n < k) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { int n, m; cin >> n >> m; COMinit(); ll ans = 0; if (m % 2 == 0) { for (int i = 0; i <= m; i += 2) { ans += COM((3 * m - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD; // 奇数がi個 ans -= COM((m - 2 - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD * n % MOD; // 2n+2以上 ans -= COM((m - i) / 2 + n - 2, n - 2) * COM(n - 1, i - 1) % MOD * n % MOD; // 2n+1 ans += MOD; ans %= MOD; } } if (m % 2 == 1) { for (int i = 1; i <= m; i += 2) { ans += COM((3 * m - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD; // 奇数がi個 ans -= COM((m - 2 - i) / 2 + n - 1, n - 1) * COM(n, i) % MOD * n % MOD; // 2n+2以上 ans -= COM((m - i) / 2 + n - 2, n - 2) * COM(n - 1, i - 1) % MOD * n % MOD; // 2n+1 ans += MOD; ans %= MOD; } } cout << ans << endl; }
replace
4
5
4
5
0
p02965
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 998244353; const int MAX = 1000000; const int MOD = 998244353; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { int N, M; cin >> N >> M; COMinit(); ll ans = COM(3 * M + N - 1, N - 1); ll igai = 0; rep(i, M) { igai += (COM(i + N - 2, i) * N % mod); igai %= mod; } for (int i = M + 1; i <= min(3 * M, N); i++) { if ((3 * M - i) % 2) continue; ll tmp = (3 * M - i) / 2; igai += (COM(tmp + N - 1, tmp) * COM(N, i) % mod); igai %= mod; } ans -= igai; if (ans < 0) ans += mod; cout << ans << endl; }
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 998244353; const int MAX = 3000000; const int MOD = 998244353; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { int N, M; cin >> N >> M; COMinit(); ll ans = COM(3 * M + N - 1, N - 1); ll igai = 0; rep(i, M) { igai += (COM(i + N - 2, i) * N % mod); igai %= mod; } for (int i = M + 1; i <= min(3 * M, N); i++) { if ((3 * M - i) % 2) continue; ll tmp = (3 * M - i) / 2; igai += (COM(tmp + N - 1, tmp) * COM(N, i) % mod); igai %= mod; } ans -= igai; if (ans < 0) ans += mod; cout << ans << endl; }
replace
24
25
24
25
0
p02965
C++
Runtime Error
#include <cstdio> const int MAX = 1500000; const int MOD = 998244353; int add(int a, int b) { return (a + b) % MOD; } int mul(int a, int b) { return 1LL * a * b % MOD; } int sub(int a, int b) { return add(a, MOD - b); } int pow_mod(int b, int p) { int ret = 1; while (p) { if (p & 1) ret = mul(ret, b); b = mul(b, b); p >>= 1; } return ret; } int fct[MAX + 5], ifct[MAX + 5]; void init() { fct[0] = 1; for (int i = 1; i <= MAX; i++) fct[i] = mul(fct[i - 1], i); ifct[MAX] = pow_mod(fct[MAX], MOD - 2); for (int i = MAX - 1; i >= 0; i--) ifct[i] = mul(ifct[i + 1], i + 1); } int comb(int n, int m) { if (n < m) return 0; else return mul(fct[n], mul(ifct[m], ifct[n - m])); } int n, m, l; int main() { init(); scanf("%d%d", &n, &m); int ans = 0; for (int i = (m & 1); i <= n && i <= m; i += 2) { int t = (3 * m - i) / 2; int del = comb(t + n - 1, n - 1); if (t >= m) del = sub(del, mul(i, comb(t - m + n - 1, n - 1))); if (t >= m + 1) del = sub(del, mul(n - i, comb(t - m - 1 + n - 1, n - 1))); ans = add(ans, mul(comb(n, i), del)); } printf("%d\n", ans); }
#include <cstdio> const int MAX = 3000000; const int MOD = 998244353; int add(int a, int b) { return (a + b) % MOD; } int mul(int a, int b) { return 1LL * a * b % MOD; } int sub(int a, int b) { return add(a, MOD - b); } int pow_mod(int b, int p) { int ret = 1; while (p) { if (p & 1) ret = mul(ret, b); b = mul(b, b); p >>= 1; } return ret; } int fct[MAX + 5], ifct[MAX + 5]; void init() { fct[0] = 1; for (int i = 1; i <= MAX; i++) fct[i] = mul(fct[i - 1], i); ifct[MAX] = pow_mod(fct[MAX], MOD - 2); for (int i = MAX - 1; i >= 0; i--) ifct[i] = mul(ifct[i + 1], i + 1); } int comb(int n, int m) { if (n < m) return 0; else return mul(fct[n], mul(ifct[m], ifct[n - m])); } int n, m, l; int main() { init(); scanf("%d%d", &n, &m); int ans = 0; for (int i = (m & 1); i <= n && i <= m; i += 2) { int t = (3 * m - i) / 2; int del = comb(t + n - 1, n - 1); if (t >= m) del = sub(del, mul(i, comb(t - m + n - 1, n - 1))); if (t >= m + 1) del = sub(del, mul(n - i, comb(t - m - 1 + n - 1, n - 1))); ans = add(ans, mul(comb(n, i), del)); } printf("%d\n", ans); }
replace
1
2
1
2
0
p02965
C++
Runtime Error
// C - GP 2 #include <bits/stdc++.h> using namespace std; #define MOD 998244353 struct FactTable { vector<long long> a; FactTable(int n) : a(n + 1, 1) { for (int i = 2; i < a.size(); i++) a[i] = a[i - 1] * i % MOD; } inline long long operator()(int n) { return a[n]; } } fact(1000000); long long minv(long long a) { long long r = 1; for (long long n = MOD - 2; n > 0; a = a * a % MOD, n >>= 1) if (n & 1) r = r * a % MOD; return r; } long long cnr(int n, int r) { if (r < 0 || r > n) return 0; if (r == 0 || r == n) return 1; return fact(n) * minv(fact(r)) % MOD * minv(fact(n - r)) % MOD; } int main(int argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(0); long long n, m; cin >> n >> m; long long ans = 0; for (int k = 0; k <= min(m, n); k++) { if ((3 * m - k) % 2) continue; long long c = (3 * m - k) / 2; ans = (ans + cnr(c + n - 1, c) * cnr(n, k) % MOD) % MOD; } long long r = 0; for (int k = 0; k <= min(m, n); k++) { if ((m - k) % 2) continue; long long c = (m - k) / 2; r = (r + cnr(c + n - 1, c) * cnr(n, k) % MOD - cnr(c + n - 2, c) * cnr(n - 1, k) % MOD + MOD) % MOD; } ans = (ans - r * n % MOD + MOD) % MOD; cout << ans << endl; return 0; }
// C - GP 2 #include <bits/stdc++.h> using namespace std; #define MOD 998244353 struct FactTable { vector<long long> a; FactTable(int n) : a(n + 1, 1) { for (int i = 2; i < a.size(); i++) a[i] = a[i - 1] * i % MOD; } inline long long operator()(int n) { return a[n]; } } fact(2000000); long long minv(long long a) { long long r = 1; for (long long n = MOD - 2; n > 0; a = a * a % MOD, n >>= 1) if (n & 1) r = r * a % MOD; return r; } long long cnr(int n, int r) { if (r < 0 || r > n) return 0; if (r == 0 || r == n) return 1; return fact(n) * minv(fact(r)) % MOD * minv(fact(n - r)) % MOD; } int main(int argc, char *argv[]) { ios::sync_with_stdio(false); cin.tie(0); long long n, m; cin >> n >> m; long long ans = 0; for (int k = 0; k <= min(m, n); k++) { if ((3 * m - k) % 2) continue; long long c = (3 * m - k) / 2; ans = (ans + cnr(c + n - 1, c) * cnr(n, k) % MOD) % MOD; } long long r = 0; for (int k = 0; k <= min(m, n); k++) { if ((m - k) % 2) continue; long long c = (m - k) / 2; r = (r + cnr(c + n - 1, c) * cnr(n, k) % MOD - cnr(c + n - 2, c) * cnr(n - 1, k) % MOD + MOD) % MOD; } ans = (ans - r * n % MOD + MOD) % MOD; cout << ans << endl; return 0; }
replace
14
15
14
15
0
p02965
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define foreach(it, v) \ for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it) #define pb push_back #define sz(x) (int)(x).size() #define fi first #define se second typedef unsigned int uint; typedef long long int ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef set<int> si; const int MAX = 1010000; const int MOD = 998244353; ll fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int N, M; int main() { cin.tie(0); ios::sync_with_stdio(false); // 前処理 COMinit(); cin >> N >> M; ll ans = 0; for (int n = M % 2; n <= M; n += 2) { int D = (M * 3 - n) / 2; ll a1 = COM(N, n) * COM(N + D - 1, N - 1) % MOD; ll b1 = N * (COM(N - 1, n - 1) * COM(N + D - M - 1, N - 1) % MOD) % MOD; ll b2 = N * (COM(N - 1, n) * COM(N + D - M - 2, N - 1) % MOD) % MOD; ans = (ans + a1 - b1 - b2 + MOD * 2) % MOD; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i <= (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define foreach(it, v) \ for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it) #define pb push_back #define sz(x) (int)(x).size() #define fi first #define se second typedef unsigned int uint; typedef long long int ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef set<int> si; const int MAX = 3010000; const int MOD = 998244353; ll fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int N, M; int main() { cin.tie(0); ios::sync_with_stdio(false); // 前処理 COMinit(); cin >> N >> M; ll ans = 0; for (int n = M % 2; n <= M; n += 2) { int D = (M * 3 - n) / 2; ll a1 = COM(N, n) * COM(N + D - 1, N - 1) % MOD; ll b1 = N * (COM(N - 1, n - 1) * COM(N + D - M - 1, N - 1) % MOD) % MOD; ll b2 = N * (COM(N - 1, n) * COM(N + D - M - 2, N - 1) % MOD) % MOD; ans = (ans + a1 - b1 - b2 + MOD * 2) % MOD; } cout << ans << "\n"; return 0; }
replace
20
21
20
21
0
p02965
C++
Runtime Error
#include <cstdio> #define RI register int #define CI const int & using namespace std; const int N = 3000005, mod = 998244353; int n, m, fact[N], inv[N], ans, tp; inline void inc(int &x, CI y) { if ((x += y) >= mod) x -= mod; } inline void dec(int &x, CI y) { if ((x -= y) < 0) x += mod; } inline int quick_pow(int x, int p = mod - 2, int mul = 1) { for (; p; p >>= 1, x = 1LL * x * x % mod) if (p & 1) mul = 1LL * mul * x % mod; return mul; } inline int C(CI n, CI m) { return 1LL * fact[n] * inv[m] % mod * inv[n - m] % mod; } inline void init(CI n) { RI i; for (fact[0] = i = 1; i <= n; ++i) fact[i] = 1LL * fact[i - 1] * i % mod; for (inv[n] = quick_pow(fact[n]), i = n - 1; ~i; --i) inv[i] = 1LL * inv[i + 1] * (i + 1) % mod; } int main() { RI i; scanf("%d%d", &n, &m); init(n + 3 * m); for (i = 0; i <= m; ++i) if (!((3 * m - i) & 1)) tp = (3 * m - i) / 2, inc(ans, 1LL * C(n, i) * C(tp + n - 1, n - 1) % mod); for (i = 2 * m + 1; i <= 3 * m; ++i) dec(ans, 1LL * n * C(3 * m - i + n - 2, n - 2) % mod); return printf("%d", ans), 0; }
#include <cstdio> #define RI register int #define CI const int & using namespace std; const int N = 3000005, mod = 998244353; int n, m, fact[N], inv[N], ans, tp; inline void inc(int &x, CI y) { if ((x += y) >= mod) x -= mod; } inline void dec(int &x, CI y) { if ((x -= y) < 0) x += mod; } inline int quick_pow(int x, int p = mod - 2, int mul = 1) { for (; p; p >>= 1, x = 1LL * x * x % mod) if (p & 1) mul = 1LL * mul * x % mod; return mul; } inline int C(CI n, CI m) { if (n < m) return 0; return 1LL * fact[n] * inv[m] % mod * inv[n - m] % mod; } inline void init(CI n) { RI i; for (fact[0] = i = 1; i <= n; ++i) fact[i] = 1LL * fact[i - 1] * i % mod; for (inv[n] = quick_pow(fact[n]), i = n - 1; ~i; --i) inv[i] = 1LL * inv[i + 1] * (i + 1) % mod; } int main() { RI i; scanf("%d%d", &n, &m); init(n + 3 * m); for (i = 0; i <= m; ++i) if (!((3 * m - i) & 1)) tp = (3 * m - i) / 2, inc(ans, 1LL * C(n, i) * C(tp + n - 1, n - 1) % mod); for (i = 2 * m + 1; i <= 3 * m; ++i) dec(ans, 1LL * n * C(3 * m - i + n - 2, n - 2) % mod); return printf("%d", ans), 0; }
insert
21
21
21
23
0
p02965
C++
Runtime Error
// Words are flowing out like endless rain into a paper cup // They slither while they pass they slip away across the universe // Pools of sorrow, waves of joy are drifting through my open mind // Possessing and caressing me #include <bits/stdc++.h> using namespace std; using LL = long long; namespace _buff { const size_t BUFF = 1 << 19; char ibuf[BUFF], *ib = ibuf, *ie = ibuf; char getc() { if (ib == ie) { ib = ibuf; ie = ibuf + fread(ibuf, 1, BUFF, stdin); } return ib == ie ? -1 : *ib++; } } // namespace _buff LL read() { using namespace _buff; LL ret = 0; bool pos = true; char c = getc(); for (; (c < '0' || c > '9') && c != '-'; c = getc()) { assert(~c); } if (c == '-') { pos = false; c = getc(); } for (; c >= '0' && c <= '9'; c = getc()) { ret = (ret << 3) + (ret << 1) + (c ^ 48); } return pos ? ret : -ret; } const size_t N = 1.5e6 + 5; const int MOD = 998244353; int qpow(int base, int e) { int ret = 1; for (; e; e >>= 1) { if (e & 1) { ret = (LL)ret * base % MOD; } base = (LL)base * base % MOD; } return ret; } void ladd(int &ans, LL val) { ans = (ans + val) % MOD; } int fac[N], inv[N]; void prep() { fac[0] = 1; for (int i = 1; i < N; ++i) { fac[i] = (LL)fac[i - 1] * i % MOD; } inv[N - 1] = qpow(fac[N - 1], MOD - 2); for (int i = N - 1; i; --i) { inv[i - 1] = (LL)inv[i] * i % MOD; } } LL comb(int n, int m) { if (n < m) return 0; return (LL)fac[n] * inv[m] % MOD * inv[n - m] % MOD; } LL calc(int n, int m) { // n split into the sum of m non-negative integers return comb(n + m - 1, m - 1); } int main() { prep(); int n = read(), m = read(); int ans = 0; for (int i = 0; i <= min(n, m); ++i) { if ((3 * m - i) & 1) continue; ladd(ans, comb(n, i) * calc((3 * m - i) / 2, n)); } for (int i = 2 * m + 1; i <= 3 * m; ++i) { ladd(ans, -calc(3 * m - i, n - 1) * n); } if (ans < 0) ans += MOD; cout << ans << '\n'; return 0; }
// Words are flowing out like endless rain into a paper cup // They slither while they pass they slip away across the universe // Pools of sorrow, waves of joy are drifting through my open mind // Possessing and caressing me #include <bits/stdc++.h> using namespace std; using LL = long long; namespace _buff { const size_t BUFF = 1 << 19; char ibuf[BUFF], *ib = ibuf, *ie = ibuf; char getc() { if (ib == ie) { ib = ibuf; ie = ibuf + fread(ibuf, 1, BUFF, stdin); } return ib == ie ? -1 : *ib++; } } // namespace _buff LL read() { using namespace _buff; LL ret = 0; bool pos = true; char c = getc(); for (; (c < '0' || c > '9') && c != '-'; c = getc()) { assert(~c); } if (c == '-') { pos = false; c = getc(); } for (; c >= '0' && c <= '9'; c = getc()) { ret = (ret << 3) + (ret << 1) + (c ^ 48); } return pos ? ret : -ret; } const size_t N = 6e6 + 5; const int MOD = 998244353; int qpow(int base, int e) { int ret = 1; for (; e; e >>= 1) { if (e & 1) { ret = (LL)ret * base % MOD; } base = (LL)base * base % MOD; } return ret; } void ladd(int &ans, LL val) { ans = (ans + val) % MOD; } int fac[N], inv[N]; void prep() { fac[0] = 1; for (int i = 1; i < N; ++i) { fac[i] = (LL)fac[i - 1] * i % MOD; } inv[N - 1] = qpow(fac[N - 1], MOD - 2); for (int i = N - 1; i; --i) { inv[i - 1] = (LL)inv[i] * i % MOD; } } LL comb(int n, int m) { if (n < m) return 0; return (LL)fac[n] * inv[m] % MOD * inv[n - m] % MOD; } LL calc(int n, int m) { // n split into the sum of m non-negative integers return comb(n + m - 1, m - 1); } int main() { prep(); int n = read(), m = read(); int ans = 0; for (int i = 0; i <= min(n, m); ++i) { if ((3 * m - i) & 1) continue; ladd(ans, comb(n, i) * calc((3 * m - i) / 2, n)); } for (int i = 2 * m + 1; i <= 3 * m; ++i) { ladd(ans, -calc(3 * m - i, n - 1) * n); } if (ans < 0) ans += MOD; cout << ans << '\n'; return 0; }
replace
42
43
42
43
0
p02965
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1000005, M = 998244353; int fac[N], inv[N], n, m, ans; 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; } int C(int x, int y) { if (x < y) return 0; return fac[x] * inv[y] % M * inv[x - y] % M; } signed main() { scanf("%lld%lld", &n, &m); fac[0] = inv[0] = 1; for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % M, inv[i] = ksm(fac[i], M - 2); for (int i = m & 1; i <= m; i += 2) (ans += C(n + (3 * m - i) / 2 - 1, n - 1) * C(n, i)) %= M; for (int i = m & 1; i <= m; i += 2) (ans += M - n * C(n + (m - i) / 2 - 1, n - 1) % M * C(n, i) % M) %= M; n--; for (int i = m & 1; i <= m; i += 2) (ans += (n + 1) * C(n + (m - i) / 2 - 1, n - 1) % M * C(n, i) % M) %= M; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 3000005, M = 998244353; int fac[N], inv[N], n, m, ans; 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; } int C(int x, int y) { if (x < y) return 0; return fac[x] * inv[y] % M * inv[x - y] % M; } signed main() { scanf("%lld%lld", &n, &m); fac[0] = inv[0] = 1; for (int i = 1; i < N; i++) fac[i] = fac[i - 1] * i % M, inv[i] = ksm(fac[i], M - 2); for (int i = m & 1; i <= m; i += 2) (ans += C(n + (3 * m - i) / 2 - 1, n - 1) * C(n, i)) %= M; for (int i = m & 1; i <= m; i += 2) (ans += M - n * C(n + (m - i) / 2 - 1, n - 1) % M * C(n, i) % M) %= M; n--; for (int i = m & 1; i <= m; i += 2) (ans += (n + 1) * C(n + (m - i) / 2 - 1, n - 1) % M * C(n, i) % M) %= M; printf("%lld\n", ans); return 0; }
replace
3
4
3
4
0
p02965
C++
Runtime Error
// #include <bits/stdc++.h> #include "bits/stdc++.h" using namespace std; typedef long long ll; // #include "boost/multiprecision/cpp_int.hpp" // typedef boost::multiprecision::cpp_int ll; typedef long double dd; // #define i_7 (ll)(1E9+7) #define i_7 998244353 #define i_5 i_7 - 2 ll mod(ll a) { ll c = a % i_7; if (c >= 0) return c; return c + i_7; } typedef pair<ll, ll> l_l; typedef pair<dd, dd> d_d; ll inf = (ll)1E16; #define rep(i, l, r) for (ll i = l; i <= r; i++) #define pb push_back ll max(ll a, ll b) { if (a < b) return b; else return a; } ll min(ll a, ll b) { if (a > b) return b; else return a; } void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]); void Min(ll &pos, ll val) { pos = min(pos, val); } void Add(ll &pos, ll val) { pos = mod(pos + val); } dd EPS = 1E-9; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define fi first #define se second #define endl "\n" #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()) // template<class T>void max(T a,T b){if(a<b)return b;else return a;} // template<class T>void min(T a,T b){if(a>b)return b;else return a;} // template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;} // template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;} ////////////////////////// ll po(ll i, ll p) { if (p == 0) return 1; else { i = mod(i); if (p == 1) return i; if (p % 2 == 0) return po(mod(i * i), p / 2); return mod(i * po(i, p - 1)); } } ll bunbo(ll n) { return po(n, i_5); } #define N 2000004 ll kai[N]; ll kai2[N]; void calc() { kai[0] = 1; kai2[0] = 1; rep(i, 1, N - 1) { kai[i] = mod(kai[i - 1] * i); } kai2[N - 1] = po(kai[N - 1], i_5); for (ll i = N - 2; i >= 0; i--) { kai2[i] = mod(kai2[i + 1] * (i + 1)); } } ll comb(ll n, ll k) { if (n < k) return 0; if (n == 0) return 1; return mod(mod(kai[n] * kai2[n - k]) * kai2[k]); } int main() { fastio calc(); ll n, m; cin >> n >> m; ll a1, a2 = 0, a3 = 0; a1 = comb(3 * m + n - 1, n - 1); rep(ma, 2 * m + 1, 3 * m) { ll res = 3 * m - ma; Add(a2, comb(res + n - 2, n - 2)); } a2 = mod(a2 * n); rep(i, m + 1, 3 * m) { if ((3 * m - i) % 2 == 1) continue; if (n < i) continue; ll res = (3 * m - i) / 2; Add(a3, comb(n, i) * comb(res + n - 1, n - 1)); } cout << mod(a1 - a2 - a3) << endl; return 0; }
// #include <bits/stdc++.h> #include "bits/stdc++.h" using namespace std; typedef long long ll; // #include "boost/multiprecision/cpp_int.hpp" // typedef boost::multiprecision::cpp_int ll; typedef long double dd; // #define i_7 (ll)(1E9+7) #define i_7 998244353 #define i_5 i_7 - 2 ll mod(ll a) { ll c = a % i_7; if (c >= 0) return c; return c + i_7; } typedef pair<ll, ll> l_l; typedef pair<dd, dd> d_d; ll inf = (ll)1E16; #define rep(i, l, r) for (ll i = l; i <= r; i++) #define pb push_back ll max(ll a, ll b) { if (a < b) return b; else return a; } ll min(ll a, ll b) { if (a > b) return b; else return a; } void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]); void Min(ll &pos, ll val) { pos = min(pos, val); } void Add(ll &pos, ll val) { pos = mod(pos + val); } dd EPS = 1E-9; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define fi first #define se second #define endl "\n" #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()) // template<class T>void max(T a,T b){if(a<b)return b;else return a;} // template<class T>void min(T a,T b){if(a>b)return b;else return a;} // template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;} // template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;} ////////////////////////// ll po(ll i, ll p) { if (p == 0) return 1; else { i = mod(i); if (p == 1) return i; if (p % 2 == 0) return po(mod(i * i), p / 2); return mod(i * po(i, p - 1)); } } ll bunbo(ll n) { return po(n, i_5); } #define N 6000004 ll kai[N]; ll kai2[N]; void calc() { kai[0] = 1; kai2[0] = 1; rep(i, 1, N - 1) { kai[i] = mod(kai[i - 1] * i); } kai2[N - 1] = po(kai[N - 1], i_5); for (ll i = N - 2; i >= 0; i--) { kai2[i] = mod(kai2[i + 1] * (i + 1)); } } ll comb(ll n, ll k) { if (n < k) return 0; if (n == 0) return 1; return mod(mod(kai[n] * kai2[n - k]) * kai2[k]); } int main() { fastio calc(); ll n, m; cin >> n >> m; ll a1, a2 = 0, a3 = 0; a1 = comb(3 * m + n - 1, n - 1); rep(ma, 2 * m + 1, 3 * m) { ll res = 3 * m - ma; Add(a2, comb(res + n - 2, n - 2)); } a2 = mod(a2 * n); rep(i, m + 1, 3 * m) { if ((3 * m - i) % 2 == 1) continue; if (n < i) continue; ll res = (3 * m - i) / 2; Add(a3, comb(n, i) * comb(res + n - 1, n - 1)); } cout << mod(a1 - a2 - a3) << endl; return 0; }
replace
70
71
70
71
0
p02965
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = (int)1e6 + 5, M = (int)5e5 + 5, mod = 998244353; int n, m, fact[4 * M], inv_fact[4 * M], ans; int add(int _a, int _b) { _a += _b; if (_a >= mod) _a -= mod; return _a; } int multi(int _a, int _b) { return (int)((ll)_a * _b % mod); } int bin_pow(int _a, int _n) { int ret = 1; for (; _n; _n >>= 1, _a = multi(_a, _a)) if (_n & 1) ret = multi(ret, _a); return ret; } int C(int _k, int _n) { return multi(fact[_n], multi(inv_fact[_k], inv_fact[_n - _k])); } int candy_distribution(int _n, int _sum) { return C(_n - 1, _sum + _n - 1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); fact[0] = 1; for (int i = 1; i < 4 * M; ++i) fact[i] = multi(fact[i - 1], i); inv_fact[4 * M - 1] = bin_pow(fact[4 * M - 1], mod - 2); for (int i = 4 * M - 2; i >= 0; --i) inv_fact[i] = multi(inv_fact[i + 1], i + 1); cin >> n >> m; for (int n_odd = 0; n_odd <= m; ++n_odd) { int rem = 3 * m - n_odd; if (rem & 1) continue; rem >>= 1; ans = add(ans, multi(C(n_odd, n), candy_distribution(n, rem))); } for (int exceed = 2 * m + 1; exceed <= 3 * m; ++exceed) { int rem = 3 * m - exceed; ans = add(ans, mod - multi(n, candy_distribution(n - 1, rem))); } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = (int)1e6 + 5, M = (int)5e5 + 5, mod = 998244353; int n, m, fact[4 * M], inv_fact[4 * M], ans; int add(int _a, int _b) { _a += _b; if (_a >= mod) _a -= mod; return _a; } int multi(int _a, int _b) { return (int)((ll)_a * _b % mod); } int bin_pow(int _a, int _n) { int ret = 1; for (; _n; _n >>= 1, _a = multi(_a, _a)) if (_n & 1) ret = multi(ret, _a); return ret; } int C(int _k, int _n) { if (_k < 0 || _k > _n || _n < 0) return 0; return multi(fact[_n], multi(inv_fact[_k], inv_fact[_n - _k])); } int candy_distribution(int _n, int _sum) { return C(_n - 1, _sum + _n - 1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); fact[0] = 1; for (int i = 1; i < 4 * M; ++i) fact[i] = multi(fact[i - 1], i); inv_fact[4 * M - 1] = bin_pow(fact[4 * M - 1], mod - 2); for (int i = 4 * M - 2; i >= 0; --i) inv_fact[i] = multi(inv_fact[i + 1], i + 1); cin >> n >> m; for (int n_odd = 0; n_odd <= m; ++n_odd) { int rem = 3 * m - n_odd; if (rem & 1) continue; rem >>= 1; ans = add(ans, multi(C(n_odd, n), candy_distribution(n, rem))); } for (int exceed = 2 * m + 1; exceed <= 3 * m; ++exceed) { int rem = 3 * m - exceed; ans = add(ans, mod - multi(n, candy_distribution(n - 1, rem))); } cout << ans << '\n'; return 0; }
insert
27
27
27
29
0
p02965
C++
Runtime Error
#include <bits/stdc++.h> #define Tp template <typename Ty> #define Ts template <typename Ty, typename... Ar> #define Reg register #define RI Reg int #define Con const #define CI Con int & #define I inline #define W while #define SZ 5000000 #define X 998244353 #define Qinv(x) Qpow(x, X - 2) #define Inc(x, y) ((x += (y)) >= X && (x -= X)) #define C(x, y) (1LL * Fac[x] * IFac[y] % X * IFac[(x) - (y)] % X) #define S(x, y) C((x) + (y)-1, (y)-1) using namespace std; int n, m, Fac[SZ + 5], IFac[SZ + 5]; I int Qpow(RI x, RI y) { RI t = 1; W(y) y & 1 && (t = 1LL * t * x % X), x = 1LL * x * x % X, y >>= 1; return t; } int main() { RI i, ans = 0; for (scanf("%d%d", &n, &m), Fac[0] = i = 1; i <= SZ; ++i) Fac[i] = 1LL * Fac[i - 1] * i % X; for (IFac[SZ] = Qinv(Fac[SZ]), i = SZ - 1; ~i; --i) IFac[i] = 1LL * IFac[i + 1] * (i + 1) % X; for (i = m & 1; i <= m; i += 2) ans = (1LL * C(n, i) * S(3 * m - i >> 1, n) + ans) % X; for (i = 2 * m + 1; i <= 3 * m; ++i) ans = (X - 1LL * n * S(3 * m - i, n - 1) + ans) % X; return printf("%d", ans), 0; }
#include <bits/stdc++.h> #define Tp template <typename Ty> #define Ts template <typename Ty, typename... Ar> #define Reg register #define RI Reg int #define Con const #define CI Con int & #define I inline #define W while #define SZ 5000000 #define X 998244353 #define Qinv(x) Qpow(x, X - 2) #define Inc(x, y) ((x += (y)) >= X && (x -= X)) #define C(x, y) \ ((x) < (y) ? 0 : 1LL * Fac[x] * IFac[y] % X * IFac[(x) - (y)] % X) #define S(x, y) C((x) + (y)-1, (y)-1) using namespace std; int n, m, Fac[SZ + 5], IFac[SZ + 5]; I int Qpow(RI x, RI y) { RI t = 1; W(y) y & 1 && (t = 1LL * t * x % X), x = 1LL * x * x % X, y >>= 1; return t; } int main() { RI i, ans = 0; for (scanf("%d%d", &n, &m), Fac[0] = i = 1; i <= SZ; ++i) Fac[i] = 1LL * Fac[i - 1] * i % X; for (IFac[SZ] = Qinv(Fac[SZ]), i = SZ - 1; ~i; --i) IFac[i] = 1LL * IFac[i + 1] * (i + 1) % X; for (i = m & 1; i <= m; i += 2) ans = (1LL * C(n, i) * S(3 * m - i >> 1, n) + ans) % X; for (i = 2 * m + 1; i <= 3 * m; ++i) ans = (X - 1LL * n * S(3 * m - i, n - 1) + ans) % X; return printf("%d", ans), 0; }
replace
13
14
13
15
0
p02965
C++
Runtime Error
// #define NDEBUG #include <cstddef> #include <cstdint> #include <iostream> #include <vector> namespace n91 { using i8 = std::int_fast8_t; using i32 = std::int_fast32_t; using i64 = std::int_fast64_t; using u8 = std::uint_fast8_t; using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t; using isize = std::ptrdiff_t; using usize = std::size_t; constexpr usize operator"" _z(unsigned long long x) noexcept { return static_cast<usize>(x); } class rep { const usize f, l; public: class itr { friend rep; usize i; constexpr itr(const usize x) noexcept : i(x) {} public: void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; constexpr rep(const usize first, const usize last) noexcept : f(first), l(last) {} constexpr itr begin() const noexcept { return itr(f); } constexpr itr end() const noexcept { return itr(l); } }; class revrep { const usize f, l; public: class itr { friend revrep; usize i; constexpr itr(usize x) noexcept : i(x) {} public: void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {} constexpr itr begin() const noexcept { return itr(l); } constexpr itr end() const noexcept { return itr(f); } }; template <class T> using vec_alias = std::vector<T>; template <class T> auto md_vec(const usize n, const T &value) { return std::vector<T>(n, value); } template <class... Args> auto md_vec(const usize n, Args... args) { return std::vector<decltype(md_vec(args...))>(n, md_vec(args...)); } template <class T> constexpr T difference(const T &a, const T &b) { return a < b ? b - a : a - b; } template <class T> T scan() { T ret; std::cin >> ret; return ret; } } // namespace n91 #include <cstdint> namespace n91 { constexpr std::uint_fast64_t totient(std::uint_fast64_t x) noexcept { using u64 = std::uint_fast64_t; u64 ret = x; for (u64 i = static_cast<u64>(2); i * i <= x; ++i) { if (x % i == static_cast<u64>(0)) { ret -= ret / i; x /= i; while (x % i == static_cast<u64>(0)) { x /= i; } } } if (x != static_cast<u64>(1)) { ret -= ret / x; } return ret; } template <std::uint_fast64_t Modulus, std::uint_fast64_t InverseExp = totient(Modulus) - static_cast<u64>(1)> class modint { using u64 = std::uint_fast64_t; static_assert(Modulus < static_cast<u64>(1) << static_cast<u64>(32), "Modulus must be less than 2**32"); u64 a; constexpr modint &negate() noexcept { if (a != static_cast<u64>(0)) { a = Modulus - a; } return *this; } public: constexpr modint(const u64 x = static_cast<u64>(0)) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+() const noexcept { return modint(*this); } constexpr modint operator-() const noexcept { return modint(*this).negate(); } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = InverseExp; while (exp) { if (exp % static_cast<u64>(2) != static_cast<u64>(0)) { *this *= rhs; } rhs *= rhs; exp /= static_cast<u64>(2); } return *this; } constexpr bool operator==(const modint rhs) const noexcept { return a == rhs.a; } constexpr bool operator!=(const modint rhs) const noexcept { return a != rhs.a; } }; } // namespace n91 #include <vector> namespace n91 { template <class T> class fact_binom { public: using value_type = T; using container_type = std::vector<value_type>; using size_type = typename container_type::size_type; private: container_type factrial, inv_fact; public: fact_binom() : factrial(), inv_fact() {} explicit fact_binom(const size_type n) : factrial(n + 1), inv_fact(n + 1) { factrial[0] = static_cast<value_type>(1); for (size_type i = 0; i != n; ++i) { factrial[i + 1] = static_cast<value_type>(i + 1) * factrial[i]; } inv_fact[n] = static_cast<value_type>(1) / factrial[n]; for (size_type i = n; i != 0; --i) { inv_fact[i - 1] = inv_fact[i] * static_cast<value_type>(i); } } value_type operator()(const size_type n, const size_type r) const { return factrial[n] * inv_fact[r] * inv_fact[n - r]; } }; } // namespace n91 #include <algorithm> #include <cmath> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <set> #include <utility> namespace n91 { void main_() { using mint = modint<998244353>; const usize n = scan<usize>(); const usize m = scan<usize>(); const fact_binom<mint> binom((n + m) * 4_z + 1_z); const auto h = [&binom](const usize n, const usize m) { return binom(n + m - 1_z, m); }; mint ans; const auto f = [&h, &binom](const usize n, const usize all, const usize odd_max) { mint ret; for (const auto odd : rep(0_z, odd_max + 1_z)) { if (all < odd) { break; } if ((all - odd) % 2_z == 1_z) { continue; } const usize even = (all - odd) / 2_z; ret += h(n, even) * binom(n, odd); } return ret; }; ans += f(n, m * 3_z, m); ans -= f(n - 1_z, m - 1_z, m - 1_z) * static_cast<mint>(n); if (m >= 2_z) ans -= f(n, m - 2_z, m) * static_cast<mint>(n); std::cout << ans.value() << std::endl; } } // namespace n91 int main() { n91::main_(); return 0; }
// #define NDEBUG #include <cstddef> #include <cstdint> #include <iostream> #include <vector> namespace n91 { using i8 = std::int_fast8_t; using i32 = std::int_fast32_t; using i64 = std::int_fast64_t; using u8 = std::uint_fast8_t; using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t; using isize = std::ptrdiff_t; using usize = std::size_t; constexpr usize operator"" _z(unsigned long long x) noexcept { return static_cast<usize>(x); } class rep { const usize f, l; public: class itr { friend rep; usize i; constexpr itr(const usize x) noexcept : i(x) {} public: void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; constexpr rep(const usize first, const usize last) noexcept : f(first), l(last) {} constexpr itr begin() const noexcept { return itr(f); } constexpr itr end() const noexcept { return itr(l); } }; class revrep { const usize f, l; public: class itr { friend revrep; usize i; constexpr itr(usize x) noexcept : i(x) {} public: void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {} constexpr itr begin() const noexcept { return itr(l); } constexpr itr end() const noexcept { return itr(f); } }; template <class T> using vec_alias = std::vector<T>; template <class T> auto md_vec(const usize n, const T &value) { return std::vector<T>(n, value); } template <class... Args> auto md_vec(const usize n, Args... args) { return std::vector<decltype(md_vec(args...))>(n, md_vec(args...)); } template <class T> constexpr T difference(const T &a, const T &b) { return a < b ? b - a : a - b; } template <class T> T scan() { T ret; std::cin >> ret; return ret; } } // namespace n91 #include <cstdint> namespace n91 { constexpr std::uint_fast64_t totient(std::uint_fast64_t x) noexcept { using u64 = std::uint_fast64_t; u64 ret = x; for (u64 i = static_cast<u64>(2); i * i <= x; ++i) { if (x % i == static_cast<u64>(0)) { ret -= ret / i; x /= i; while (x % i == static_cast<u64>(0)) { x /= i; } } } if (x != static_cast<u64>(1)) { ret -= ret / x; } return ret; } template <std::uint_fast64_t Modulus, std::uint_fast64_t InverseExp = totient(Modulus) - static_cast<u64>(1)> class modint { using u64 = std::uint_fast64_t; static_assert(Modulus < static_cast<u64>(1) << static_cast<u64>(32), "Modulus must be less than 2**32"); u64 a; constexpr modint &negate() noexcept { if (a != static_cast<u64>(0)) { a = Modulus - a; } return *this; } public: constexpr modint(const u64 x = static_cast<u64>(0)) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+() const noexcept { return modint(*this); } constexpr modint operator-() const noexcept { return modint(*this).negate(); } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = InverseExp; while (exp) { if (exp % static_cast<u64>(2) != static_cast<u64>(0)) { *this *= rhs; } rhs *= rhs; exp /= static_cast<u64>(2); } return *this; } constexpr bool operator==(const modint rhs) const noexcept { return a == rhs.a; } constexpr bool operator!=(const modint rhs) const noexcept { return a != rhs.a; } }; } // namespace n91 #include <vector> namespace n91 { template <class T> class fact_binom { public: using value_type = T; using container_type = std::vector<value_type>; using size_type = typename container_type::size_type; private: container_type factrial, inv_fact; public: fact_binom() : factrial(), inv_fact() {} explicit fact_binom(const size_type n) : factrial(n + 1), inv_fact(n + 1) { factrial[0] = static_cast<value_type>(1); for (size_type i = 0; i != n; ++i) { factrial[i + 1] = static_cast<value_type>(i + 1) * factrial[i]; } inv_fact[n] = static_cast<value_type>(1) / factrial[n]; for (size_type i = n; i != 0; --i) { inv_fact[i - 1] = inv_fact[i] * static_cast<value_type>(i); } } value_type operator()(const size_type n, const size_type r) const { return factrial[n] * inv_fact[r] * inv_fact[n - r]; } }; } // namespace n91 #include <algorithm> #include <cmath> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <set> #include <utility> namespace n91 { void main_() { using mint = modint<998244353>; const usize n = scan<usize>(); const usize m = scan<usize>(); const fact_binom<mint> binom((n + m) * 4_z + 1_z); const auto h = [&binom](const usize n, const usize m) { return binom(n + m - 1_z, m); }; mint ans; const auto f = [&h, &binom](const usize n, const usize all, const usize odd_max) { mint ret; for (const auto odd : rep(0_z, odd_max + 1_z)) { if (all < odd) { break; } if (n < odd) { break; } if ((all - odd) % 2_z == 1_z) { continue; } const usize even = (all - odd) / 2_z; ret += h(n, even) * binom(n, odd); } return ret; }; ans += f(n, m * 3_z, m); ans -= f(n - 1_z, m - 1_z, m - 1_z) * static_cast<mint>(n); if (m >= 2_z) ans -= f(n, m - 2_z, m) * static_cast<mint>(n); std::cout << ans.value() << std::endl; } } // namespace n91 int main() { n91::main_(); return 0; }
insert
236
236
236
239
0
p02965
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long const int MAX = 200000; const int MOD = 998244353; // int fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 int COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } signed main() { int n, m; cin >> n >> m; COMinit(); int ans = n * COM(m + n - 2, m) % MOD; for (int i = m; 3 * m - 2 * i >= 0; i++) { ans = (ans + (COM(i + n - 1, i) + (MOD - n * COM(i - m + n - 1, i - m) % MOD)) * COM(n, 3 * m - 2 * i) % MOD) % MOD; } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define int long long const int MAX = 2000000; const int MOD = 998244353; // int fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 int COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } signed main() { int n, m; cin >> n >> m; COMinit(); int ans = n * COM(m + n - 2, m) % MOD; for (int i = m; 3 * m - 2 * i >= 0; i++) { ans = (ans + (COM(i + n - 1, i) + (MOD - n * COM(i - m + n - 1, i - m) % MOD)) * COM(n, 3 * m - 2 * i) % MOD) % MOD; } cout << ans; }
replace
3
4
3
4
0
p02965
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define MOD 998244353 #define mkp make_pair typedef long long ll; using namespace std; #define MAX_N 200020 ll inv[MAX_N + 10], fac[MAX_N + 10], ifac[MAX_N + 10]; void setComb() { inv[0] = 1; inv[1] = 1; fac[1] = 1; ifac[1] = 1; fac[0] = 1; ifac[0] = 1; for (int i = 2; i < MAX_N; i++) { inv[i] = (-MOD / i) * inv[MOD % i] % MOD; fac[i] = fac[i - 1] * i % MOD; ifac[i] = ifac[i - 1] * inv[i] % MOD; inv[i] = (inv[i] + MOD) % MOD; fac[i] = (fac[i] + MOD) % MOD; ifac[i] = (ifac[i] + MOD) % MOD; } return; } ll comb(ll n, ll k) { if (n < k || n < 0 || k < 0) return 0; else return ((fac[n] * ifac[k] % MOD * ifac[n - k] % MOD + MOD) % MOD); } ll hcomb(ll n, ll r) { if (n == 0 && r == 0) return 1; else if (n < 0 || r < 0) return 0; else return comb(n + r - 1, r); } ll mod_pow(ll x, ll n) { x %= MOD; ll res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } void add(ll &a, ll b) { a = (a + b) % MOD; } void mul(ll &a, ll b) { a %= MOD; b %= MOD; a = a * b % MOD; } int main() { ll N, M; cin >> N >> M; setComb(); ll nans = 0; for (ll k = 0; k < M; k++) { ll res = hcomb(N - 1, k); mul(res, N); add(nans, res); } ll ans = 0; for (ll k = 0; k <= min(N, M); k++) { if (k % 2 != M % 2) continue; ll res = hcomb(N, (3 * M - k) / 2); mul(res, comb(N, k)); add(ans, res); } add(ans, -nans + MOD); cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define MOD 998244353 #define mkp make_pair typedef long long ll; using namespace std; #define MAX_N 4000040 ll inv[MAX_N + 10], fac[MAX_N + 10], ifac[MAX_N + 10]; void setComb() { inv[0] = 1; inv[1] = 1; fac[1] = 1; ifac[1] = 1; fac[0] = 1; ifac[0] = 1; for (int i = 2; i < MAX_N; i++) { inv[i] = (-MOD / i) * inv[MOD % i] % MOD; fac[i] = fac[i - 1] * i % MOD; ifac[i] = ifac[i - 1] * inv[i] % MOD; inv[i] = (inv[i] + MOD) % MOD; fac[i] = (fac[i] + MOD) % MOD; ifac[i] = (ifac[i] + MOD) % MOD; } return; } ll comb(ll n, ll k) { if (n < k || n < 0 || k < 0) return 0; else return ((fac[n] * ifac[k] % MOD * ifac[n - k] % MOD + MOD) % MOD); } ll hcomb(ll n, ll r) { if (n == 0 && r == 0) return 1; else if (n < 0 || r < 0) return 0; else return comb(n + r - 1, r); } ll mod_pow(ll x, ll n) { x %= MOD; ll res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } void add(ll &a, ll b) { a = (a + b) % MOD; } void mul(ll &a, ll b) { a %= MOD; b %= MOD; a = a * b % MOD; } int main() { ll N, M; cin >> N >> M; setComb(); ll nans = 0; for (ll k = 0; k < M; k++) { ll res = hcomb(N - 1, k); mul(res, N); add(nans, res); } ll ans = 0; for (ll k = 0; k <= min(N, M); k++) { if (k % 2 != M % 2) continue; ll res = hcomb(N, (3 * M - k) / 2); mul(res, comb(N, k)); add(ans, res); } add(ans, -nans + MOD); cout << ans << endl; return 0; }
replace
14
15
14
15
0
p02965
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <class T> inline T updmax(T &a, T b) { return a = max(a, b); } template <class T> inline T updmin(T &a, T b) { return a = min(a, b); } template <unsigned long long mod> class modint { public: unsigned long long v; modint(const long long x = 0) : v(x % mod) {} modint operator+(const modint rhs) { return modint(*this) += rhs; } modint operator-(const modint rhs) { return modint(*this) -= rhs; } modint operator*(const modint rhs) { return modint(*this) *= rhs; } modint operator/(const modint rhs) { return modint(*this) /= rhs; } modint operator-() { return modint(mod - this->v); } modint &operator+=(const modint rhs) { v += rhs.v; if (v >= mod) v -= mod; return *this; } modint &operator-=(const modint rhs) { if (v < rhs.v) v += mod; v -= rhs.v; return *this; } modint &operator*=(const modint rhs) { v = v * rhs.v % mod; return *this; } modint inverse(modint a) { unsigned long long exp = mod - 2; modint ret(1ULL); while (exp) { if (exp % 2) { ret *= a; } a *= a; exp >>= 1; } return ret; } modint &operator/=(modint rhs) { (*this) *= inverse(rhs); return *this; } friend ostream &operator<<(ostream &os, modint u) { os << u.v; return (os); } friend istream &operator>>(istream &is, modint &u) { is >> u.v; return (is); } }; const int MOD = 998244353; using mint = modint<MOD>; const int MAX = 1000005; mint fact[MAX], invfact[MAX], inv[MAX]; void facinit() { fact[0] = fact[1] = 1; invfact[0] = invfact[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fact[i] = fact[i - 1] * i; inv[i] = -inv[MOD % i] * (MOD / i); invfact[i] = invfact[i - 1] * inv[i]; } } mint nPr(int n, int r) { return fact[n] * invfact[n - r]; } mint nCr(int n, int r) { if (n < 0 || r < 0 || n < r) return mint{0}; return fact[n] * invfact[r] * invfact[n - r]; } mint nHr(int n, int r) { if (n == 0 && r == 0) return mint{1}; return nCr(n + r - 1, r); } class Solution { public: void solve() { int n, m; cin >> n >> m; mint ok{0}, ng{0}; facinit(); for (int odd = m % 2; odd <= min(n, m); odd += 2) { ok += nCr(n, odd) * nHr(n, (3 * m - odd) / 2); ng += nCr(n, odd) * (nHr(n, (m - odd) / 2) * odd + nHr(n, (m - odd - 2) / 2) * (n - odd)); } cout << ok - ng << endl; return; }; }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); Solution solution; solution.solve(); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline T updmax(T &a, T b) { return a = max(a, b); } template <class T> inline T updmin(T &a, T b) { return a = min(a, b); } template <unsigned long long mod> class modint { public: unsigned long long v; modint(const long long x = 0) : v(x % mod) {} modint operator+(const modint rhs) { return modint(*this) += rhs; } modint operator-(const modint rhs) { return modint(*this) -= rhs; } modint operator*(const modint rhs) { return modint(*this) *= rhs; } modint operator/(const modint rhs) { return modint(*this) /= rhs; } modint operator-() { return modint(mod - this->v); } modint &operator+=(const modint rhs) { v += rhs.v; if (v >= mod) v -= mod; return *this; } modint &operator-=(const modint rhs) { if (v < rhs.v) v += mod; v -= rhs.v; return *this; } modint &operator*=(const modint rhs) { v = v * rhs.v % mod; return *this; } modint inverse(modint a) { unsigned long long exp = mod - 2; modint ret(1ULL); while (exp) { if (exp % 2) { ret *= a; } a *= a; exp >>= 1; } return ret; } modint &operator/=(modint rhs) { (*this) *= inverse(rhs); return *this; } friend ostream &operator<<(ostream &os, modint u) { os << u.v; return (os); } friend istream &operator>>(istream &is, modint &u) { is >> u.v; return (is); } }; const int MOD = 998244353; using mint = modint<MOD>; const int MAX = 3000005; mint fact[MAX], invfact[MAX], inv[MAX]; void facinit() { fact[0] = fact[1] = 1; invfact[0] = invfact[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fact[i] = fact[i - 1] * i; inv[i] = -inv[MOD % i] * (MOD / i); invfact[i] = invfact[i - 1] * inv[i]; } } mint nPr(int n, int r) { return fact[n] * invfact[n - r]; } mint nCr(int n, int r) { if (n < 0 || r < 0 || n < r) return mint{0}; return fact[n] * invfact[r] * invfact[n - r]; } mint nHr(int n, int r) { if (n == 0 && r == 0) return mint{1}; return nCr(n + r - 1, r); } class Solution { public: void solve() { int n, m; cin >> n >> m; mint ok{0}, ng{0}; facinit(); for (int odd = m % 2; odd <= min(n, m); odd += 2) { ok += nCr(n, odd) * nHr(n, (3 * m - odd) / 2); ng += nCr(n, odd) * (nHr(n, (m - odd) / 2) * odd + nHr(n, (m - odd - 2) / 2) * (n - odd)); } cout << ok - ng << endl; return; }; }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); Solution solution; solution.solve(); return 0; }
replace
61
62
61
62
0
p02965
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> Q; typedef complex<double> C; #define cx real() #define cy imag() const ll INF = 1LL << 60; const double DINF = 1e30; const ll mod = 998244353; const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, -1, 0, 1}; const C I = C(0, 1); const double EPS = 1e-10; const ll NCK_MAX = 510000; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll q = a / b, g = extgcd(b, a - q * b, x, y); ll z = x - q * y; x = y; y = z; return g; } ll invmod(ll a, ll m) { // a^-1 mod m ll x, y; extgcd(a, m, x, y); x %= m; if (x < 0) x += m; return x; } ll *fac, *finv, *inv; void nCk_init(ll mod) { fac = new ll[NCK_MAX]; finv = new ll[NCK_MAX]; inv = new ll[NCK_MAX]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < NCK_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 nCk(ll n, ll k, ll mod) { if (fac == NULL) nCk_init(mod); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } template <typename T> class Zip { vector<T> d; bool flag; void init() { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } public: Zip() { flag = false; } void add(T x) { d.push_back(x); flag = true; } ll getNum(T x) { if (flag) init(); return lower_bound(d.begin(), d.end(), x) - d.begin(); } ll size() { if (flag) init(); return (ll)d.size(); } }; class UnionFind { vector<ll> par, rank; // par > 0: number, par < 0: -par public: UnionFind(ll n) : par(n, 1), rank(n, 0) {} ll getSize(ll x) { return par[find(x)]; } ll find(ll x) { if (par[x] > 0) return x; return -(par[x] = -find(-par[x])); } void merge(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = -y; } else { par[x] += par[y]; par[y] = -x; if (rank[x] == rank[y]) rank[x]++; } } bool isSame(ll x, ll y) { return find(x) == find(y); } }; template <typename T> class SegmentTree { ll n; vector<T> node; function<T(T, T)> fun, fun2; bool customChange; T outValue, initValue; public: void init(ll num, function<T(T, T)> resultFunction, T init, T out, function<T(T, T)> changeFunction = NULL) { // changeFunction: (input, beforevalue) => newvalue fun = resultFunction; fun2 = changeFunction; customChange = changeFunction != NULL; n = 1; while (n < num) n *= 2; node.resize(2 * n - 1); fill(node.begin(), node.end(), init); outValue = out; initValue = init; } void valueChange(ll num, T value) { num += n - 1; if (customChange) node[num] = fun2(value, node[num]); else node[num] = value; while (num > 0) num = (num - 1) / 2, node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]); } T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b) if (r == -1) r = n; if (a <= l && r <= b) return node[k]; if (b <= l || r <= a) return outValue; ll mid = (l + r) / 2; return fun(rangeQuery(a, b, l, mid, 2 * k + 1), rangeQuery(a, b, mid, r, 2 * k + 2)); } }; template <typename T> class Graph { struct edge { ll to; T cost; }; struct edge_data { ll from, to; T cost; }; ll v; vector<vector<edge>> e, re; vector<edge_data> ed; vector<bool> used; vector<ll> vs, cmp; bool isDirected, isMinasEdge; public: Graph(ll _v, bool _isDirected = true, ll range_add = 0) { // range_add 0:no / 1:in / 2:out / 3:in+out //_v++; v = _v, isDirected = _isDirected; isMinasEdge = false; e.resize(v), re.resize(v); } void add_edge(ll s, ll t, T cost = 1) { e[s].push_back((edge){t, cost}); if (!isDirected) e[t].push_back((edge){s, cost}); else re[t].push_back((edge){s, cost}); ed.push_back((edge_data){s, t, cost}); if (cost < 0) isMinasEdge = true; } vector<T> dijkstra(ll s) { vector<T> d(v, INF); d[s] = 0; auto edge_cmp = [](const edge &a, const edge &b) { return a.cost > b.cost; }; priority_queue<edge, vector<edge>, decltype(edge_cmp)> pq(edge_cmp); pq.push((edge){s, 0}); while (!pq.empty()) { edge temp = pq.top(); pq.pop(); if (d[temp.to] < temp.cost) continue; for (const edge &next : e[temp.to]) { T cost = temp.cost + next.cost; if (d[next.to] > cost) { d[next.to] = cost; pq.push((edge){next.to, cost}); } } } return d; } vector<T> bellmanford(ll s) { vector<T> d(v, INF); d[s] = 0; for (ll i = 0; i < v; i++) { for (const edge_data &temp : ed) { if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost) d[temp.to] = d[temp.from] + temp.cost; if (!isDirected && d[temp.to] != INF && d[temp.from] > d[temp.to] + temp.cost) d[temp.from] = d[temp.to] + temp.cost; } } for (ll i = 0; i < v; i++) { for (const edge_data &temp : ed) { if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost) d[temp.to] = -INF; if (!isDirected && d[temp.to] != INF && d[temp.from] > d[temp.to] + temp.cost) d[temp.from] = -INF; } } return d; } vector<T> shortest_path(ll s) { if (isMinasEdge) return bellmanford(s); else return dijkstra(s); } T kruskal() { // if (isDirected) UnionFind uf(v); auto edge_data_cmp = [](const edge_data &a, const edge_data &b) { return a.cost < b.cost; }; sort(ed.begin(), ed.end(), edge_data_cmp); T ans = 0; for (const edge_data &temp : ed) { if (uf.isSame(temp.from, temp.to)) continue; uf.merge(temp.from, temp.to); ans += temp.cost; } return ans; } void scc_dfs(ll s) { used[s] = true; for (const edge &i : e[s]) if (!used[i.to]) scc_dfs(i.to); vs.push_back(s); } void scc_rdfs(ll s, ll k) { used[s] = true; cmp[s] = k; for (const edge &i : re[s]) if (!used[i.to]) scc_rdfs(i.to, k); } vector<ll> scc() { used.resize(v); fill(used.begin(), used.end(), false); cmp.resize(v); vs.clear(); for (ll i = 0; i < v; i++) if (!used[i]) scc_dfs(i); used.resize(v); fill(used.begin(), used.end(), false); ll k = 0; for (ll i = vs.size() - 1; i >= 0; i--) if (!used[vs[i]]) scc_rdfs(vs[i], k++); return cmp; } }; ll n, m, ans; int main() { scanf("%lld%lld", &n, &m); for (ll i = 0; i <= min(n, m); i++) if ((3 * m - i) % 2 == 0) { ll j = (3 * m - i) / 2; ans += nCk(n, i, mod) * nCk(n - 1 + j, j, mod) % mod; if (ans >= mod) ans -= mod; } for (ll i = 2 * m + 1; i <= 3 * m; i++) { ll j = 3 * m - i; ans -= nCk(j + n - 2, j, mod) * n % mod; if (ans < 0) ans += mod; } printf("%lld\n", ans); }
#include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> Q; typedef complex<double> C; #define cx real() #define cy imag() const ll INF = 1LL << 60; const double DINF = 1e30; const ll mod = 998244353; const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, -1, 0, 1}; const C I = C(0, 1); const double EPS = 1e-10; const ll NCK_MAX = 4000000; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll q = a / b, g = extgcd(b, a - q * b, x, y); ll z = x - q * y; x = y; y = z; return g; } ll invmod(ll a, ll m) { // a^-1 mod m ll x, y; extgcd(a, m, x, y); x %= m; if (x < 0) x += m; return x; } ll *fac, *finv, *inv; void nCk_init(ll mod) { fac = new ll[NCK_MAX]; finv = new ll[NCK_MAX]; inv = new ll[NCK_MAX]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < NCK_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 nCk(ll n, ll k, ll mod) { if (fac == NULL) nCk_init(mod); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } template <typename T> class Zip { vector<T> d; bool flag; void init() { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } public: Zip() { flag = false; } void add(T x) { d.push_back(x); flag = true; } ll getNum(T x) { if (flag) init(); return lower_bound(d.begin(), d.end(), x) - d.begin(); } ll size() { if (flag) init(); return (ll)d.size(); } }; class UnionFind { vector<ll> par, rank; // par > 0: number, par < 0: -par public: UnionFind(ll n) : par(n, 1), rank(n, 0) {} ll getSize(ll x) { return par[find(x)]; } ll find(ll x) { if (par[x] > 0) return x; return -(par[x] = -find(-par[x])); } void merge(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = -y; } else { par[x] += par[y]; par[y] = -x; if (rank[x] == rank[y]) rank[x]++; } } bool isSame(ll x, ll y) { return find(x) == find(y); } }; template <typename T> class SegmentTree { ll n; vector<T> node; function<T(T, T)> fun, fun2; bool customChange; T outValue, initValue; public: void init(ll num, function<T(T, T)> resultFunction, T init, T out, function<T(T, T)> changeFunction = NULL) { // changeFunction: (input, beforevalue) => newvalue fun = resultFunction; fun2 = changeFunction; customChange = changeFunction != NULL; n = 1; while (n < num) n *= 2; node.resize(2 * n - 1); fill(node.begin(), node.end(), init); outValue = out; initValue = init; } void valueChange(ll num, T value) { num += n - 1; if (customChange) node[num] = fun2(value, node[num]); else node[num] = value; while (num > 0) num = (num - 1) / 2, node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]); } T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b) if (r == -1) r = n; if (a <= l && r <= b) return node[k]; if (b <= l || r <= a) return outValue; ll mid = (l + r) / 2; return fun(rangeQuery(a, b, l, mid, 2 * k + 1), rangeQuery(a, b, mid, r, 2 * k + 2)); } }; template <typename T> class Graph { struct edge { ll to; T cost; }; struct edge_data { ll from, to; T cost; }; ll v; vector<vector<edge>> e, re; vector<edge_data> ed; vector<bool> used; vector<ll> vs, cmp; bool isDirected, isMinasEdge; public: Graph(ll _v, bool _isDirected = true, ll range_add = 0) { // range_add 0:no / 1:in / 2:out / 3:in+out //_v++; v = _v, isDirected = _isDirected; isMinasEdge = false; e.resize(v), re.resize(v); } void add_edge(ll s, ll t, T cost = 1) { e[s].push_back((edge){t, cost}); if (!isDirected) e[t].push_back((edge){s, cost}); else re[t].push_back((edge){s, cost}); ed.push_back((edge_data){s, t, cost}); if (cost < 0) isMinasEdge = true; } vector<T> dijkstra(ll s) { vector<T> d(v, INF); d[s] = 0; auto edge_cmp = [](const edge &a, const edge &b) { return a.cost > b.cost; }; priority_queue<edge, vector<edge>, decltype(edge_cmp)> pq(edge_cmp); pq.push((edge){s, 0}); while (!pq.empty()) { edge temp = pq.top(); pq.pop(); if (d[temp.to] < temp.cost) continue; for (const edge &next : e[temp.to]) { T cost = temp.cost + next.cost; if (d[next.to] > cost) { d[next.to] = cost; pq.push((edge){next.to, cost}); } } } return d; } vector<T> bellmanford(ll s) { vector<T> d(v, INF); d[s] = 0; for (ll i = 0; i < v; i++) { for (const edge_data &temp : ed) { if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost) d[temp.to] = d[temp.from] + temp.cost; if (!isDirected && d[temp.to] != INF && d[temp.from] > d[temp.to] + temp.cost) d[temp.from] = d[temp.to] + temp.cost; } } for (ll i = 0; i < v; i++) { for (const edge_data &temp : ed) { if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost) d[temp.to] = -INF; if (!isDirected && d[temp.to] != INF && d[temp.from] > d[temp.to] + temp.cost) d[temp.from] = -INF; } } return d; } vector<T> shortest_path(ll s) { if (isMinasEdge) return bellmanford(s); else return dijkstra(s); } T kruskal() { // if (isDirected) UnionFind uf(v); auto edge_data_cmp = [](const edge_data &a, const edge_data &b) { return a.cost < b.cost; }; sort(ed.begin(), ed.end(), edge_data_cmp); T ans = 0; for (const edge_data &temp : ed) { if (uf.isSame(temp.from, temp.to)) continue; uf.merge(temp.from, temp.to); ans += temp.cost; } return ans; } void scc_dfs(ll s) { used[s] = true; for (const edge &i : e[s]) if (!used[i.to]) scc_dfs(i.to); vs.push_back(s); } void scc_rdfs(ll s, ll k) { used[s] = true; cmp[s] = k; for (const edge &i : re[s]) if (!used[i.to]) scc_rdfs(i.to, k); } vector<ll> scc() { used.resize(v); fill(used.begin(), used.end(), false); cmp.resize(v); vs.clear(); for (ll i = 0; i < v; i++) if (!used[i]) scc_dfs(i); used.resize(v); fill(used.begin(), used.end(), false); ll k = 0; for (ll i = vs.size() - 1; i >= 0; i--) if (!used[vs[i]]) scc_rdfs(vs[i], k++); return cmp; } }; ll n, m, ans; int main() { scanf("%lld%lld", &n, &m); for (ll i = 0; i <= min(n, m); i++) if ((3 * m - i) % 2 == 0) { ll j = (3 * m - i) / 2; ans += nCk(n, i, mod) * nCk(n - 1 + j, j, mod) % mod; if (ans >= mod) ans -= mod; } for (ll i = 2 * m + 1; i <= 3 * m; i++) { ll j = 3 * m - i; ans -= nCk(j + n - 2, j, mod) * n % mod; if (ans < 0) ans += mod; } printf("%lld\n", ans); }
replace
30
31
30
31
0
p02965
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; const ll INF = 1LL << 60; const ll MOD = 998244353; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } template <class C> void print(const C &c, std::ostream &os = std::cout) { std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " ")); os << std::endl; } // mod int struct // original : https://github.com/beet-aizu/library/blob/master/mod/mint.cpp struct mint { ll v; ll mod; mint() : v(0) {} mint(signed v, ll mod = MOD) : v(v), mod(mod) {} mint(ll t, ll mod = MOD) : mod(mod) { v = t % mod; if (v < 0) v += mod; } mint pow(ll k) { mint res(1), tmp(v); while (k) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } static mint add_identity() { return mint(0); } static mint mul_identity() { return mint(1); } mint inv() { return pow(mod - 2); } mint &operator+=(mint a) { v += a.v; if (v >= mod) v -= mod; return *this; } mint &operator-=(mint a) { v += mod - a.v; if (v >= mod) v -= mod; return *this; } mint &operator*=(mint a) { v = 1LL * v * a.v % mod; return *this; } mint &operator/=(mint a) { return (*this) *= a.inv(); } mint operator+(mint a) const { return mint(v) += a; }; mint operator-(mint a) const { return mint(v) -= a; }; mint operator*(mint a) const { return mint(v) *= a; }; mint operator/(mint a) const { return mint(v) /= a; }; mint operator-() const { return v ? mint(mod - v) : mint(v); } bool operator==(const mint a) const { return v == a.v; } bool operator!=(const mint a) const { return v != a.v; } bool operator<(const mint a) const { return v < a.v; } // find x s.t. a^x = b static ll log(ll a, ll b) { const ll sq = 40000; unordered_map<ll, ll> dp; dp.reserve(sq); mint res(1); for (int r = 0; r < sq; r++) { if (!dp.count(res.v)) dp[res.v] = r; res *= a; } mint p = mint(a).inv().pow(sq); res = b; for (int q = 0; q <= MOD / sq + 1; q++) { if (dp.count(res.v)) { ll idx = q * sq + dp[res.v]; if (idx > 0) return idx; } res *= p; } assert(0); return ll(-1); } static mint comb(long long n, int k) { mint num(1), dom(1); for (int i = 0; i < k; i++) { num *= mint(n - i); dom *= mint(i + 1); } return num / dom; } }; ostream &operator<<(ostream &os, mint m) { os << m.v; return os; } struct Combination { vector<ll> fac, finv, inv; Combination(ll maxN) { maxN += 100; // for safety fac.resize(maxN + 1); finv.resize(maxN + 1); inv.resize(maxN + 1); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i <= maxN; ++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 operator()(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } }; int main() { int n, m; cin >> n >> m; // oddになる数で場合分け出来そう // m < n Combination nCk(1000000); mint ret = 0; for (int i = m % 2; i <= m; i += 2) { // i個oddに使う ll mm = (3 * m - i) / 2; ret += mint(nCk(n, i)) * mint(nCk(mm + n - 1, n - 1)); } for (int i = m % 2; i <= m; i += 2) { ll mm = (m - i) / 2; mint temp = mint(nCk(n, i)) * mint(nCk(mm + n - 1, n - 1)); temp -= mint(nCk(n - 1, i)) * mint(nCk(mm + n - 2, n - 2)); ret -= temp * n; } cout << ret << "\n"; return 0; }
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; const ll INF = 1LL << 60; const ll MOD = 998244353; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } template <class C> void print(const C &c, std::ostream &os = std::cout) { std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " ")); os << std::endl; } // mod int struct // original : https://github.com/beet-aizu/library/blob/master/mod/mint.cpp struct mint { ll v; ll mod; mint() : v(0) {} mint(signed v, ll mod = MOD) : v(v), mod(mod) {} mint(ll t, ll mod = MOD) : mod(mod) { v = t % mod; if (v < 0) v += mod; } mint pow(ll k) { mint res(1), tmp(v); while (k) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } static mint add_identity() { return mint(0); } static mint mul_identity() { return mint(1); } mint inv() { return pow(mod - 2); } mint &operator+=(mint a) { v += a.v; if (v >= mod) v -= mod; return *this; } mint &operator-=(mint a) { v += mod - a.v; if (v >= mod) v -= mod; return *this; } mint &operator*=(mint a) { v = 1LL * v * a.v % mod; return *this; } mint &operator/=(mint a) { return (*this) *= a.inv(); } mint operator+(mint a) const { return mint(v) += a; }; mint operator-(mint a) const { return mint(v) -= a; }; mint operator*(mint a) const { return mint(v) *= a; }; mint operator/(mint a) const { return mint(v) /= a; }; mint operator-() const { return v ? mint(mod - v) : mint(v); } bool operator==(const mint a) const { return v == a.v; } bool operator!=(const mint a) const { return v != a.v; } bool operator<(const mint a) const { return v < a.v; } // find x s.t. a^x = b static ll log(ll a, ll b) { const ll sq = 40000; unordered_map<ll, ll> dp; dp.reserve(sq); mint res(1); for (int r = 0; r < sq; r++) { if (!dp.count(res.v)) dp[res.v] = r; res *= a; } mint p = mint(a).inv().pow(sq); res = b; for (int q = 0; q <= MOD / sq + 1; q++) { if (dp.count(res.v)) { ll idx = q * sq + dp[res.v]; if (idx > 0) return idx; } res *= p; } assert(0); return ll(-1); } static mint comb(long long n, int k) { mint num(1), dom(1); for (int i = 0; i < k; i++) { num *= mint(n - i); dom *= mint(i + 1); } return num / dom; } }; ostream &operator<<(ostream &os, mint m) { os << m.v; return os; } struct Combination { vector<ll> fac, finv, inv; Combination(ll maxN) { maxN += 100; // for safety fac.resize(maxN + 1); finv.resize(maxN + 1); inv.resize(maxN + 1); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i <= maxN; ++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 operator()(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } }; int main() { int n, m; cin >> n >> m; // oddになる数で場合分け出来そう // m < n Combination nCk(10000000); mint ret = 0; for (int i = m % 2; i <= m; i += 2) { // i個oddに使う ll mm = (3 * m - i) / 2; ret += mint(nCk(n, i)) * mint(nCk(mm + n - 1, n - 1)); } for (int i = m % 2; i <= m; i += 2) { ll mm = (m - i) / 2; mint temp = mint(nCk(n, i)) * mint(nCk(mm + n - 1, n - 1)); temp -= mint(nCk(n - 1, i)) * mint(nCk(mm + n - 2, n - 2)); ret -= temp * n; } cout << ret << "\n"; return 0; }
replace
152
153
152
153
0
p02966
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #define ll long long using namespace std; int n; ll a[305][305], sum[305][305], f[305][305], s[305][305]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (i != j) scanf("%lld", &a[i][j]); sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j]; s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j] * (i < j); } memset(f, 0x3f, sizeof(f)); f[0][0] = 0; for (int i = 0; i <= n; i++) for (int j = i; j <= n; j++) { if (f[i][j] > 1e17) continue; for (int k = j + 1; k <= n; k++) f[j][k] = min(f[j][k], f[i][j] + s[k][k] - s[j][k] - s[k][j] + s[j][j] + sum[n][j] - sum[n][i] - sum[k][j] + sum[k][i]); } ll ans = 1e18; for (int i = 0; i <= n; i++) ans = min(ans, f[i][n]); printf("%lld\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #define ll long long using namespace std; int n; ll a[505][505], sum[505][505], f[505][505], s[505][505]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (i != j) scanf("%lld", &a[i][j]); sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j]; s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j] * (i < j); } memset(f, 0x3f, sizeof(f)); f[0][0] = 0; for (int i = 0; i <= n; i++) for (int j = i; j <= n; j++) { if (f[i][j] > 1e17) continue; for (int k = j + 1; k <= n; k++) f[j][k] = min(f[j][k], f[i][j] + s[k][k] - s[j][k] - s[k][j] + s[j][j] + sum[n][j] - sum[n][i] - sum[k][j] + sum[k][i]); } ll ans = 1e18; for (int i = 0; i <= n; i++) ans = min(ans, f[i][n]); printf("%lld\n", ans); return 0; }
replace
6
7
6
7
0
p02966
C++
Memory Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int maxn = 510; int n, a[maxn][maxn]; long long from[maxn][maxn], to[maxn][maxn], dp[maxn][maxn][maxn], ans; void cmin(long long &x, long long y) { x = min(x, y); } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) if (j != i) { scanf("%d", &a[i][j]); from[i][j] = (j ? from[i][j - 1] : 0) + a[i][j]; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { to[i][j] = (j ? to[i][j - 1] : 0) + a[j][i]; } } memset(dp, 0x3f, sizeof(dp)); ans = dp[0][0][0]; dp[0][0][0] = 0; for (int i = 0; i < n - 1; ++i) { for (int j = 0; j <= i; ++j) { for (int k = 0; k <= j; ++k) { cmin(dp[i + 1][j][k], dp[i][j][k] + (to[i + 1][i] - (j ? to[i + 1][j - 1] : 0)) + (k ? from[i + 1][k - 1] : 0)); cmin(dp[i + 1][i + 1][j], dp[i][j][k] + (j ? from[i + 1][j - 1] : 0)); } } } for (int j = 0; j < n; ++j) for (int k = 0; k <= j; ++k) cmin(ans, dp[n - 1][j][k]); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 500; int n, a[maxn][maxn]; long long from[maxn][maxn], to[maxn][maxn], dp[maxn][maxn][maxn], ans; void cmin(long long &x, long long y) { x = min(x, y); } int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) if (j != i) { scanf("%d", &a[i][j]); from[i][j] = (j ? from[i][j - 1] : 0) + a[i][j]; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { to[i][j] = (j ? to[i][j - 1] : 0) + a[j][i]; } } memset(dp, 0x3f, sizeof(dp)); ans = dp[0][0][0]; dp[0][0][0] = 0; for (int i = 0; i < n - 1; ++i) { for (int j = 0; j <= i; ++j) { for (int k = 0; k <= j; ++k) { cmin(dp[i + 1][j][k], dp[i][j][k] + (to[i + 1][i] - (j ? to[i + 1][j - 1] : 0)) + (k ? from[i + 1][k - 1] : 0)); cmin(dp[i + 1][i + 1][j], dp[i][j][k] + (j ? from[i + 1][j - 1] : 0)); } } } for (int j = 0; j < n; ++j) for (int k = 0; k <= j; ++k) cmin(ans, dp[n - 1][j][k]); cout << ans << endl; }
replace
3
4
3
4
MLE
p02967
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int le[N], ri[N], a[N], n; int A, B, C, cnt[4], h[4]; char e; void del(int x) { le[ri[x]] = le[x]; ri[le[x]] = ri[x]; h[a[x]]--; } int getmin() { int g = -1; for (int i = 0; i < 3; i++) if (cnt[i] != -1 && (g == -1 || cnt[g] > cnt[i])) g = i; cnt[g] = -1; return g; } int main() { for (e = getchar(); e == 'A' || e == 'B' || e == 'C'; e = getchar()) a[++n] = e - 'A'; for (int i = 1; i <= n; i++) le[i] = i - 1, ri[i] = i + 1; ri[0] = 1; le[n + 1] = n; a[0] = a[n + 1] = 3; a[0]++; for (int i = ri[0]; i <= n; i = ri[i]) { if (a[i] == a[le[i]]) del(i); else cnt[a[i]]++; } memcpy(h, cnt, sizeof h); A = getmin(); B = getmin(); C = getmin(); memset(cnt, 0, sizeof cnt); int b1 = 0, c1 = 0; for (int i = ri[0]; i <= n; i = ri[i]) { if (a[i] == A) { cnt[2 * b1 + c1]++; b1 = c1 = 0; } if (a[i] == B) b1 = 1; if (a[i] == C) c1 = 1; } cnt[2 * b1 + c1]++; if (a[le[n + 1]] == C && a[le[le[n + 1]]] == A && cnt[3] + cnt[2] < cnt[1]) del(le[n + 1]), cnt[1]--; for (int i = ri[0]; i <= n; i = ri[i]) { if (cnt[3] + cnt[2] >= cnt[1]) break; if (a[i] == C) { if (!le[i] && a[ri[i]] == A) del(i), cnt[1]--; else if (a[le[i]] == A && a[ri[i]] == A) del(le[i]), del(i), cnt[1]--; } } assert(cnt[3] + cnt[2] >= cnt[1]); for (int i = ri[0]; i <= n; i = ri[i]) { if (h[B] == h[C]) break; if (a[i] == C) { if (a[le[i]] != a[ri[i]]) del(i); } } assert(h[B] == h[C]); for (int i = ri[0]; i <= n; i = ri[i]) { if (h[A] == h[B]) break; if (a[i] == B) { if (a[le[i]] == C && a[le[le[i]]] != a[ri[i]]) del(le[i]), del(i); } if (a[i] == C) { if (a[le[i]] == B && a[le[le[i]]] != a[ri[i]]) del(le[i]), del(i); } } for (int i = ri[0]; i <= n; i = ri[i]) putchar('A' + a[i]); }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int le[N], ri[N], a[N], n; int A, B, C, cnt[4], h[4]; char e; void del(int x) { le[ri[x]] = le[x]; ri[le[x]] = ri[x]; h[a[x]]--; } int getmin() { int g = -1; for (int i = 0; i < 3; i++) if (cnt[i] != -1 && (g == -1 || cnt[g] > cnt[i])) g = i; cnt[g] = -1; return g; } int main() { for (e = getchar(); e == 'A' || e == 'B' || e == 'C'; e = getchar()) a[++n] = e - 'A'; for (int i = 1; i <= n; i++) le[i] = i - 1, ri[i] = i + 1; ri[0] = 1; le[n + 1] = n; a[0] = a[n + 1] = 3; a[0]++; for (int i = ri[0]; i <= n; i = ri[i]) { if (a[i] == a[le[i]]) del(i); else cnt[a[i]]++; } memcpy(h, cnt, sizeof h); A = getmin(); B = getmin(); C = getmin(); if (!h[A]) return 0; memset(cnt, 0, sizeof cnt); int b1 = 0, c1 = 0; for (int i = ri[0]; i <= n; i = ri[i]) { if (a[i] == A) { cnt[2 * b1 + c1]++; b1 = c1 = 0; } if (a[i] == B) b1 = 1; if (a[i] == C) c1 = 1; } cnt[2 * b1 + c1]++; if (a[le[n + 1]] == C && a[le[le[n + 1]]] == A && cnt[3] + cnt[2] < cnt[1]) del(le[n + 1]), cnt[1]--; for (int i = ri[0]; i <= n; i = ri[i]) { if (cnt[3] + cnt[2] >= cnt[1]) break; if (a[i] == C) { if (!le[i] && a[ri[i]] == A) del(i), cnt[1]--; else if (a[le[i]] == A && a[ri[i]] == A) del(le[i]), del(i), cnt[1]--; } } assert(cnt[3] + cnt[2] >= cnt[1]); for (int i = ri[0]; i <= n; i = ri[i]) { if (h[B] == h[C]) break; if (a[i] == C) { if (a[le[i]] != a[ri[i]]) del(i); } } assert(h[B] == h[C]); for (int i = ri[0]; i <= n; i = ri[i]) { if (h[A] == h[B]) break; if (a[i] == B) { if (a[le[i]] == C && a[le[le[i]]] != a[ri[i]]) del(le[i]), del(i); } if (a[i] == C) { if (a[le[i]] == B && a[le[le[i]]] != a[ri[i]]) del(le[i]), del(i); } } for (int i = ri[0]; i <= n; i = ri[i]) putchar('A' + a[i]); }
insert
38
38
38
40
0
p02967
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int _ = 1e6 + 7; char str[_], tmp[_]; int L, cnt[3], id[3]; void change() { for (int i = 0; i < 3; ++i) id[i] = i; for (int i = 1; i <= L; ++i) ++cnt[str[i] - 'A']; sort(id, id + 3, [&](int x, int y) { return cnt[x] < cnt[y]; }); for (int i = 1; i <= L; ++i) for (int j = 0; j < 3; ++j) if (str[i] - 'A' == id[j]) { str[i] = 'A' + j; break; } } void output(char c) { putchar(id[c - 'A'] + 'A'); } void output(string &str) { for (auto t : str) output(t); } #define PII pair<int, int> int main() { scanf("%s", str + 1); for (int i = 1; str[i]; ++i) if (str[i] != tmp[L]) tmp[++L] = str[i]; memcpy(str, tmp, sizeof(tmp)); change(); int b1 = 0, b2 = 0, c1 = 0, c2 = 0, pre = 0; str[L + 1] = 'A'; for (int i = 1; i <= L + 1; ++i) if (str[i] == 'A') { if (pre + 1 <= i - 1) if ((i - 1) - (pre + 1) >= 1) { ++b1; ++c1; } else if (str[i - 1] == 'B') { ++b1; ++b2; } else { ++c1; ++c2; } pre = i; } vector<string> arr; string tparr; bool flg = 0; if (str[L] != 'A' && str[L - 1] == 'A') if (str[L] == 'B' && b2 > c1) { --b2; L -= 2; flg = 1; } else if (str[L] == 'C' && c2 > b1) { --c2; L -= 2; flg = 1; } for (int i = 1; i <= L + 1; ++i) if (str[i] == 'A') if (tparr.size() == 1) if (tparr[0] == 'B' && b2 > c1) { --b2; if (i == 2) { arr.push_back(tparr = ""); pre = i; } continue; } else if (tparr[0] == 'C' && c2 > b1) { --c2; if (i == 2) { arr.push_back(tparr = ""); pre = i; } continue; } else { arr.push_back(tparr); tparr = ""; } else { arr.push_back(tparr); tparr = ""; } else if (tparr.empty() || str[i] != *--tparr.end()) tparr.push_back(str[i]); if (flg) arr.push_back(""); if (arr.size() == 1) return 0; int na = arr.size() - 1, nb = 0, nc = 0; for (auto t : arr) for (auto p : t) p == 'B' ? ++nb : ++nc; for (int i = 0; i < arr.size(); ++i) { if (i) output('A'); string str = arr[i]; if (str.size() >= 2) { if (nb > nc && *str.begin() == 'B') { --nb; str.erase(str.begin()); } if (nb > nc && *--str.end() == 'B') { --nb; str.erase(--str.end()); } if (nb < nc && *str.begin() == 'C') { --nc; str.erase(str.begin()); } if (nb < nc && *--str.end() == 'C') { --nc; str.erase(--str.end()); } while (min(nb, nc) > na && (str.size() > 2 || i == 0 || i + 1 == arr.size())) { str.erase(--str.end()); str.erase(--str.end()); --nb; --nc; } } output(str); } return 0; }
#include <bits/stdc++.h> using namespace std; const int _ = 1e6 + 7; char str[_], tmp[_]; int L, cnt[3], id[3]; void change() { for (int i = 0; i < 3; ++i) id[i] = i; for (int i = 1; i <= L; ++i) ++cnt[str[i] - 'A']; sort(id, id + 3, [&](int x, int y) { return cnt[x] < cnt[y]; }); for (int i = 1; i <= L; ++i) for (int j = 0; j < 3; ++j) if (str[i] - 'A' == id[j]) { str[i] = 'A' + j; break; } } void output(char c) { putchar(id[c - 'A'] + 'A'); } void output(string &str) { for (auto t : str) output(t); } #define PII pair<int, int> int main() { scanf("%s", str + 1); for (int i = 1; str[i]; ++i) if (str[i] != tmp[L]) tmp[++L] = str[i]; memcpy(str, tmp, sizeof(tmp)); change(); int b1 = 0, b2 = 0, c1 = 0, c2 = 0, pre = 0; str[L + 1] = 'A'; for (int i = 1; i <= L + 1; ++i) if (str[i] == 'A') { if (pre + 1 <= i - 1) if ((i - 1) - (pre + 1) >= 1) { ++b1; ++c1; } else if (str[i - 1] == 'B') { ++b1; ++b2; } else { ++c1; ++c2; } pre = i; } vector<string> arr; string tparr; bool flg = 0; if (str[L] != 'A' && str[L - 1] == 'A') if (str[L] == 'B' && b2 > c1) { --b2; L -= 2; flg = 1; } else if (str[L] == 'C' && c2 > b1) { --c2; L -= 2; flg = 1; } for (int i = 1; i <= L + 1; ++i) if (str[i] == 'A') if (tparr.size() == 1) if (tparr[0] == 'B' && b2 > c1) { --b2; if (i == 2) { arr.push_back(tparr = ""); pre = i; } continue; } else if (tparr[0] == 'C' && c2 > b1) { --c2; if (i == 2) { arr.push_back(tparr = ""); pre = i; } continue; } else { arr.push_back(tparr); tparr = ""; } else { arr.push_back(tparr); tparr = ""; } else if (tparr.empty() || str[i] != *--tparr.end()) tparr.push_back(str[i]); if (flg) arr.push_back(""); if (arr.size() == 1) return 0; int na = arr.size() - 1, nb = 0, nc = 0; for (auto t : arr) for (auto p : t) p == 'B' ? ++nb : ++nc; for (int i = 0; i < arr.size(); ++i) { if (i) output('A'); string str = arr[i]; if (str.size() >= 2) { if (nb > nc && *str.begin() == 'B') { --nb; str.erase(str.begin()); } if (nb > nc && *--str.end() == 'B') { --nb; str.erase(--str.end()); } if (nb < nc && *str.begin() == 'C') { --nc; str.erase(str.begin()); } if (nb < nc && *--str.end() == 'C') { --nc; str.erase(--str.end()); } while (min(nb, nc) > na && (str.size() > 2 || (i == 0 || i + 1 == arr.size()) && str.size() >= 2)) { str.erase(--str.end()); str.erase(--str.end()); --nb; --nc; } } output(str); } return 0; }
replace
123
124
123
125
0
p02968
C++
Runtime Error
#include <bits/stdc++.h> #define reg register #define pr std::pair<int, int> #define fi first #define se second #define FIN(s) freopen(s, "r", stdin) #define FOUT(s) freopen(s, "w", stdout) #define debug(...) fprintf(stderr, __VA_ARGS__) #define rep(i, l, r) for (int i = l; i <= r; ++i) #define lep(i, l, r) for (int i = l; i < r; ++i) #define irep(i, r, l) for (int i = r; i >= l; --i) #define ilep(i, r, l) for (int i = r; i > l; --i) #define Rep(i, n) rep(i, 1, n) #define Lep(i, n) lep(i, 1, n) #define IRep(i, n) irep(i, n, 1) #define ILep(i, n) ilep(i, n, 1) typedef long long ll; typedef long double ld; namespace modular { int MOD; inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; } inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; } inline int mul(int x, int y) { return 1LL * x * y % MOD; } inline int qpow(int x, int y) { int ans = 1; for (; y; y >>= 1, x = mul(x, x)) if (y & 1) ans = mul(ans, x); return ans; } }; // namespace modular using namespace modular; namespace Base { template <typename Tp> inline Tp input() { Tp x = 0, y = 1; char c = getchar(); while ((c < '0' || '9' < c) && c != EOF) { if (c == '-') y = -1; c = getchar(); } if (c == EOF) return 0; while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar(); return x *= y; } template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); } template <typename Tp> inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; } template <typename Tp> inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; } }; // namespace Base using namespace Base; /*----------------------------------------------------------------------------*/ #define MAX_N 407 int N; int p[MAX_N], f[MAX_N][MAX_N]; struct seg { int l, r; } s[MAX_N]; inline int sqr(int x) { return x * x; } pr kx, ky; bool cmp(int x, int y) { if (x > N) kx.fi = s[x].r, kx.se = 0; else kx.fi = s[x].l, kx.se = s[x].r; if (y > N) ky.fi = s[y].r, ky.se = 0; else ky.fi = s[y].l, ky.se = s[y].r; return kx == ky ? x > y : kx < ky; } int solve(int k) { memset(f, 0, sizeof(f)); f[0][0] = 1; int t = 0; Rep(i, N + N) { int x = p[i], ed = std::min(i, k); rep(j, 0, ed) { if (x > N) { inc(f[i][j], mul(f[i - 1][j], s[x].r + 1 - (i - 1 - (t - j)))); } else { inc(f[i][j], mul(f[i - 1][j], s[x].r + 1 - (N * 2 - 1 - (x - 1) + (k - j)))); if (j > 0) inc(f[i][j], mul(f[i - 1][j - 1], s[x].l + 1 - (i - 1 - (t - (j - 1))))); } // if (f[i][j]) printf("%d %d %d\n", i, j, f[i][j]); } if (x <= N) t++; } return f[N + N][k]; } int main() { read(N), read(MOD); Rep(i, N + N) { s[i].l = (i > N ? 0 : (int)sqrt(N * N - sqr(i - 1))); s[i].r = (int)sqrt(4 * N * N - sqr(i - 1)); if (sqr(i - 1) + sqr(s[i].l) < sqr(N)) s[i].l++; chmin(s[i].r, N + N - 1); if (i <= N) s[i].l = std::max(0, s[i].l - 1); // printf("%d %d\n", s[i].l, s[i].r); p[i] = i; } std::sort(p + 1, p + N + N + 1, cmp); // Rep(i, N + N) printf("%d ", p[i]); // puts(""); int res = 0; // printf("%d\n", solve(1)); // return 0; rep(k, 0, N) { int tmp = solve(k); // printf("%d %d\n", k, tmp); inc(res, (k & 1) ? MOD - tmp : tmp); } printf("%d\n", res); return 0; }
#include <bits/stdc++.h> #define reg register #define pr std::pair<int, int> #define fi first #define se second #define FIN(s) freopen(s, "r", stdin) #define FOUT(s) freopen(s, "w", stdout) #define debug(...) fprintf(stderr, __VA_ARGS__) #define rep(i, l, r) for (int i = l; i <= r; ++i) #define lep(i, l, r) for (int i = l; i < r; ++i) #define irep(i, r, l) for (int i = r; i >= l; --i) #define ilep(i, r, l) for (int i = r; i > l; --i) #define Rep(i, n) rep(i, 1, n) #define Lep(i, n) lep(i, 1, n) #define IRep(i, n) irep(i, n, 1) #define ILep(i, n) ilep(i, n, 1) typedef long long ll; typedef long double ld; namespace modular { int MOD; inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; } inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; } inline int mul(int x, int y) { return 1LL * x * y % MOD; } inline int qpow(int x, int y) { int ans = 1; for (; y; y >>= 1, x = mul(x, x)) if (y & 1) ans = mul(ans, x); return ans; } }; // namespace modular using namespace modular; namespace Base { template <typename Tp> inline Tp input() { Tp x = 0, y = 1; char c = getchar(); while ((c < '0' || '9' < c) && c != EOF) { if (c == '-') y = -1; c = getchar(); } if (c == EOF) return 0; while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar(); return x *= y; } template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); } template <typename Tp> inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; } template <typename Tp> inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; } }; // namespace Base using namespace Base; /*----------------------------------------------------------------------------*/ #define MAX_N 507 int N; int p[MAX_N], f[MAX_N][MAX_N]; struct seg { int l, r; } s[MAX_N]; inline int sqr(int x) { return x * x; } pr kx, ky; bool cmp(int x, int y) { if (x > N) kx.fi = s[x].r, kx.se = 0; else kx.fi = s[x].l, kx.se = s[x].r; if (y > N) ky.fi = s[y].r, ky.se = 0; else ky.fi = s[y].l, ky.se = s[y].r; return kx == ky ? x > y : kx < ky; } int solve(int k) { memset(f, 0, sizeof(f)); f[0][0] = 1; int t = 0; Rep(i, N + N) { int x = p[i], ed = std::min(i, k); rep(j, 0, ed) { if (x > N) { inc(f[i][j], mul(f[i - 1][j], s[x].r + 1 - (i - 1 - (t - j)))); } else { inc(f[i][j], mul(f[i - 1][j], s[x].r + 1 - (N * 2 - 1 - (x - 1) + (k - j)))); if (j > 0) inc(f[i][j], mul(f[i - 1][j - 1], s[x].l + 1 - (i - 1 - (t - (j - 1))))); } // if (f[i][j]) printf("%d %d %d\n", i, j, f[i][j]); } if (x <= N) t++; } return f[N + N][k]; } int main() { read(N), read(MOD); Rep(i, N + N) { s[i].l = (i > N ? 0 : (int)sqrt(N * N - sqr(i - 1))); s[i].r = (int)sqrt(4 * N * N - sqr(i - 1)); if (sqr(i - 1) + sqr(s[i].l) < sqr(N)) s[i].l++; chmin(s[i].r, N + N - 1); if (i <= N) s[i].l = std::max(0, s[i].l - 1); // printf("%d %d\n", s[i].l, s[i].r); p[i] = i; } std::sort(p + 1, p + N + N + 1, cmp); // Rep(i, N + N) printf("%d ", p[i]); // puts(""); int res = 0; // printf("%d\n", solve(1)); // return 0; rep(k, 0, N) { int tmp = solve(k); // printf("%d %d\n", k, tmp); inc(res, (k & 1) ? MOD - tmp : tmp); } printf("%d\n", res); return 0; }
replace
57
58
57
58
0
p02968
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define re register #define ull unsigned ll using namespace std; inline int read() { int s = 0, t = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') t = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar(); return s * t; } const int N = 405; int n, P, Ans, f[N][N], q[N]; struct Node { int l, r; } p[N]; bool cmp(int x, int y) { if (p[x].l == p[y].l) return x > y; return p[x].l < p[y].l; } int Mod(int x) { return x >= P ? x - P : x; } int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); n = read(), P = read(); for (int i = 0, l = 0, r = 0; i < 2 * n; i++) { for (l = 0; i * i + l * l < n * n; l++) ; for (r = l; i * i + (r + 1) * (r + 1) <= 4 * n * n && r + 1 < 2 * n; r++) ; if (i < n) p[i] = (Node){l - 1, r}; else p[i] = (Node){r, l}; q[i + 1] = i; } sort(q + 1, q + 2 * n + 1, cmp); for (int k = 0; k <= n; k++) { f[0][0] = 1; for (int i = 1, t = 0; i <= 2 * n; i++) { int l = p[q[i]].l, r = p[q[i]].r; if (l > r) swap(l, r); for (int j = 0; j <= min(i, k); j++) { if (q[i] >= n) f[i][j] = 1ll * f[i - 1][j] * max(0, r + 1 - (i - 1 - (t - j))) % P; else { int t1 = 1ll * f[i - 1][j] * max(0, r + 1 - (2 * n - 1 - q[i] + (k - j))) % P; int t2 = 1ll * (j >= 1 ? f[i - 1][j - 1] : 0) * max(0, l + 1 - (i - 1 - (t - (j - 1)))) % P; f[i][j] = Mod(t1 + t2); } } t += (q[i] < n); } Ans = Mod(Ans + 1ll * (k & 1 ? P - 1 : 1) * f[2 * n][k] % P); } printf("%d", Ans); return 0; }
#include <bits/stdc++.h> #define ll long long #define re register #define ull unsigned ll using namespace std; inline int read() { int s = 0, t = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') t = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar(); return s * t; } const int N = 505; int n, P, Ans, f[N][N], q[N]; struct Node { int l, r; } p[N]; bool cmp(int x, int y) { if (p[x].l == p[y].l) return x > y; return p[x].l < p[y].l; } int Mod(int x) { return x >= P ? x - P : x; } int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); n = read(), P = read(); for (int i = 0, l = 0, r = 0; i < 2 * n; i++) { for (l = 0; i * i + l * l < n * n; l++) ; for (r = l; i * i + (r + 1) * (r + 1) <= 4 * n * n && r + 1 < 2 * n; r++) ; if (i < n) p[i] = (Node){l - 1, r}; else p[i] = (Node){r, l}; q[i + 1] = i; } sort(q + 1, q + 2 * n + 1, cmp); for (int k = 0; k <= n; k++) { f[0][0] = 1; for (int i = 1, t = 0; i <= 2 * n; i++) { int l = p[q[i]].l, r = p[q[i]].r; if (l > r) swap(l, r); for (int j = 0; j <= min(i, k); j++) { if (q[i] >= n) f[i][j] = 1ll * f[i - 1][j] * max(0, r + 1 - (i - 1 - (t - j))) % P; else { int t1 = 1ll * f[i - 1][j] * max(0, r + 1 - (2 * n - 1 - q[i] + (k - j))) % P; int t2 = 1ll * (j >= 1 ? f[i - 1][j - 1] : 0) * max(0, l + 1 - (i - 1 - (t - (j - 1)))) % P; f[i][j] = Mod(t1 + t2); } } t += (q[i] < n); } Ans = Mod(Ans + 1ll * (k & 1 ? P - 1 : 1) * f[2 * n][k] % P); } printf("%d", Ans); return 0; }
replace
17
18
17
18
0
p02968
C++
Runtime Error
/*Lucky_Glass*/ #include <algorithm> #include <cstdio> #include <cstring> #include <vector> using namespace std; const int N = 300; int n, mod, Nf, Ng; vector<pair<int, int>> Epr; int Ef[N + 3][N + 3]; int main() { scanf("%d%d", &n, &mod); Nf = 2 * n - 1; Ng = 2 * n - 1; for (int i = 0; i < 2 * n; i++) { while (i * i + Nf * Nf > 4 * n * n && Nf >= 0) Nf--; while (i * i + Ng * Ng >= n * n && Ng >= 0) Ng--; if (Ng == -1) Epr.push_back(make_pair(Nf + 1, 0)); else Epr.push_back(make_pair(Ng + 1, Nf + 1)); // printf("%d %d\n",Epr.back().first,Epr.back().second); } sort(Epr.begin(), Epr.end()); int Vans = 0; long long typ = 1; for (int k = 0; k <= n; k++) { memset(Ef, 0, sizeof Ef); Ef[0][0] = 1; for (int i = 0, Ctf = 0, Ctg = 0; i < (int)Epr.size(); Ctg += Epr[i].second == 0, Ctf += Epr[i].second != 0, i++) { for (int j = 0; j <= k; j++) { int tmp = Ef[i][j]; if (Epr[i].second) { if (j != k) Ef[i + 1][j + 1] = (Ef[i + 1][j + 1] + 1ll * tmp * (Epr[i].first - j - Ctg) % mod) % mod; Ef[i + 1][j] = (Ef[i + 1][j] + 1ll * tmp * (Epr[i].second - k - n - (Ctf - j)) % mod) % mod; } else Ef[i + 1][j] = (Ef[i + 1][j] + 1ll * tmp * (Epr[i].first - j - Ctg) % mod) % mod; } // printf("%d %d\n",Ctf,Ctg); } // printf("%d\n",Ef[Epr.size()][k]); Vans = (Vans + typ * Ef[Epr.size()][k] + mod) % mod; typ *= -1; } printf("%d\n", Vans); return 0; }
/*Lucky_Glass*/ #include <algorithm> #include <cstdio> #include <cstring> #include <vector> using namespace std; const int N = 700; int n, mod, Nf, Ng; vector<pair<int, int>> Epr; int Ef[N + 3][N + 3]; int main() { scanf("%d%d", &n, &mod); Nf = 2 * n - 1; Ng = 2 * n - 1; for (int i = 0; i < 2 * n; i++) { while (i * i + Nf * Nf > 4 * n * n && Nf >= 0) Nf--; while (i * i + Ng * Ng >= n * n && Ng >= 0) Ng--; if (Ng == -1) Epr.push_back(make_pair(Nf + 1, 0)); else Epr.push_back(make_pair(Ng + 1, Nf + 1)); // printf("%d %d\n",Epr.back().first,Epr.back().second); } sort(Epr.begin(), Epr.end()); int Vans = 0; long long typ = 1; for (int k = 0; k <= n; k++) { memset(Ef, 0, sizeof Ef); Ef[0][0] = 1; for (int i = 0, Ctf = 0, Ctg = 0; i < (int)Epr.size(); Ctg += Epr[i].second == 0, Ctf += Epr[i].second != 0, i++) { for (int j = 0; j <= k; j++) { int tmp = Ef[i][j]; if (Epr[i].second) { if (j != k) Ef[i + 1][j + 1] = (Ef[i + 1][j + 1] + 1ll * tmp * (Epr[i].first - j - Ctg) % mod) % mod; Ef[i + 1][j] = (Ef[i + 1][j] + 1ll * tmp * (Epr[i].second - k - n - (Ctf - j)) % mod) % mod; } else Ef[i + 1][j] = (Ef[i + 1][j] + 1ll * tmp * (Epr[i].first - j - Ctg) % mod) % mod; } // printf("%d %d\n",Ctf,Ctg); } // printf("%d\n",Ef[Epr.size()][k]); Vans = (Vans + typ * Ef[Epr.size()][k] + mod) % mod; typ *= -1; } printf("%d\n", Vans); return 0; }
replace
7
8
7
8
0
p02968
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define per(i, a, b) for (int i = (a); i >= (b); i--) #define REP(i, n) for (int i = (0); i < (n); i++) #define fi first #define se second #define pb push_back #define mp make_pair #define clr(x) memset(x, 0, sizeof x) using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef long long ll; typedef double ld; template <class T> inline void read(T &x) { int f = 0; x = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) f |= (ch == '-'); for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; if (f) x = -x; } const int N = 405; struct node { int p, id; friend bool operator<(node a, node b) { return a.p < b.p || a.p == b.p && a.id > b.id; } } a[N]; int l[N], r[N], f[N][N]; int n, mod, ans; void add(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); } int mul(int x, int y) { return (ll)x * y % mod; } int main() { read(n), read(mod); rep(i, 0, 2 * n - 1) { r[i] = min(2 * n - 1, (int)sqrt(4 * n * n - i * i)); if (i >= n) a[i + 1] = (node){r[i], i}; else { l[i] = ceil(sqrt(n * n - i * i)); a[i + 1] = (node){l[i] - 1, i}; } } sort(a + 1, a + n * 2 + 1); rep(k, 0, n) { clr(f), f[0][0] = 1; int c0 = 0, c1 = 0; rep(i, 1, n * 2) { int p = a[i].id; rep(j, 0, min(n - k, i - 1)) if (f[i - 1][j]) if (p < n) { add(f[i][j + 1], mul(f[i - 1][j], 1 + r[p] - (n + k + j))); add(f[i][j], mod - mul(f[i - 1][j], l[p] - (c0 + c1 - j))); } else { add(f[i][j], mul(f[i - 1][j], 1 + r[p] - (c0 + c1 - j))); } if (p >= n) c1++; else c0++; } ans = (ans + f[n * 2][n - k]) % mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define per(i, a, b) for (int i = (a); i >= (b); i--) #define REP(i, n) for (int i = (0); i < (n); i++) #define fi first #define se second #define pb push_back #define mp make_pair #define clr(x) memset(x, 0, sizeof x) using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef long long ll; typedef double ld; template <class T> inline void read(T &x) { int f = 0; x = 0; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) f |= (ch == '-'); for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; if (f) x = -x; } const int N = 505; struct node { int p, id; friend bool operator<(node a, node b) { return a.p < b.p || a.p == b.p && a.id > b.id; } } a[N]; int l[N], r[N], f[N][N]; int n, mod, ans; void add(int &x, int y) { x = (x + y >= mod ? x + y - mod : x + y); } int mul(int x, int y) { return (ll)x * y % mod; } int main() { read(n), read(mod); rep(i, 0, 2 * n - 1) { r[i] = min(2 * n - 1, (int)sqrt(4 * n * n - i * i)); if (i >= n) a[i + 1] = (node){r[i], i}; else { l[i] = ceil(sqrt(n * n - i * i)); a[i + 1] = (node){l[i] - 1, i}; } } sort(a + 1, a + n * 2 + 1); rep(k, 0, n) { clr(f), f[0][0] = 1; int c0 = 0, c1 = 0; rep(i, 1, n * 2) { int p = a[i].id; rep(j, 0, min(n - k, i - 1)) if (f[i - 1][j]) if (p < n) { add(f[i][j + 1], mul(f[i - 1][j], 1 + r[p] - (n + k + j))); add(f[i][j], mod - mul(f[i - 1][j], l[p] - (c0 + c1 - j))); } else { add(f[i][j], mul(f[i - 1][j], 1 + r[p] - (c0 + c1 - j))); } if (p >= n) c1++; else c0++; } ans = (ans + f[n * 2][n - k]) % mod; } cout << ans << endl; return 0; }
replace
27
28
27
28
0
p02968
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <vector> #define LL long long #define LD long double using namespace std; const int NN = 400 + 117; const int MM = 200 + 117; int read() { int fl = 1, x; char c; for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar()) ; if (c == '-') { fl = -1; c = getchar(); } for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = (x << 3) + (x << 1) + c - '0'; return x * fl; } void open() { freopen("a.in", "r", stdin); // freopen("a.out","w",stdout); } void close() { fclose(stdin); fclose(stdout); } int m, n; int mod; struct node { int l, r; int id; int v() { if (l == -1) return r; else return l; } } a[NN]; bool cmp(node a, node b) { if ((a.id < n && b.id < n) || (a.id >= n && b.id >= n)) { return a.id > b.id; } else return a.v() == b.v() ? a.id > b.id : a.v() < b.v(); } LL dp[2][NN] = {}; LL v(LL x) { return max(x, 0ll); } LL calc(int x) { for (int i = 0; i <= n + 1; ++i) dp[0][i] = 0; dp[0][0] = 1; int now = 0; int pre = 0; for (int i = 0; i < 2 * n; ++i) { now ^= 1; for (int j = 0; j <= pre + 1; ++j) dp[now][j] = 0; if (a[i].l == -1) { for (int j = 0; j <= pre; ++j) { dp[now][j] = dp[now ^ 1][j] * v(1 + a[i].r - j - i + pre) % mod; } } else { for (int j = 0; j <= pre; ++j) { dp[now][j] += dp[now ^ 1][j] * v(1 + a[i].r - (n + pre + x - j)); dp[now][j] %= mod; dp[now][j + 1] += dp[now ^ 1][j] * v(1 + a[i].l - j - i + pre); dp[now][j + 1] %= mod; } ++pre; } } return dp[now][x]; } int main() { open(); n = read(); mod = read(); for (int i = 0; i < 2 * n; ++i) { a[i].r = min(2 * n - 1, (int)sqrt(4 * n * n - i * i)); a[i].id = i; if (i >= n) a[i].l = -1; else a[i].l = sqrt(n * n - i * i - 1); } sort(a, a + 2 * n, cmp); LL ans = 0; for (int i = 0, sym = 1; i <= n; ++i, sym = -sym) { ans += sym * calc(i); ans %= mod; } ans = (ans + mod) % mod; printf("%lld\n", ans); close(); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <vector> #define LL long long #define LD long double using namespace std; const int NN = 400 + 117; const int MM = 200 + 117; int read() { int fl = 1, x; char c; for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar()) ; if (c == '-') { fl = -1; c = getchar(); } for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = (x << 3) + (x << 1) + c - '0'; return x * fl; } void open() { freopen("a.in", "r", stdin); // freopen("a.out","w",stdout); } void close() { fclose(stdin); fclose(stdout); } int m, n; int mod; struct node { int l, r; int id; int v() { if (l == -1) return r; else return l; } } a[NN]; bool cmp(node a, node b) { if ((a.id < n && b.id < n) || (a.id >= n && b.id >= n)) { return a.id > b.id; } else return a.v() == b.v() ? a.id > b.id : a.v() < b.v(); } LL dp[2][NN] = {}; LL v(LL x) { return max(x, 0ll); } LL calc(int x) { for (int i = 0; i <= n + 1; ++i) dp[0][i] = 0; dp[0][0] = 1; int now = 0; int pre = 0; for (int i = 0; i < 2 * n; ++i) { now ^= 1; for (int j = 0; j <= pre + 1; ++j) dp[now][j] = 0; if (a[i].l == -1) { for (int j = 0; j <= pre; ++j) { dp[now][j] = dp[now ^ 1][j] * v(1 + a[i].r - j - i + pre) % mod; } } else { for (int j = 0; j <= pre; ++j) { dp[now][j] += dp[now ^ 1][j] * v(1 + a[i].r - (n + pre + x - j)); dp[now][j] %= mod; dp[now][j + 1] += dp[now ^ 1][j] * v(1 + a[i].l - j - i + pre); dp[now][j + 1] %= mod; } ++pre; } } return dp[now][x]; } int main() { // open(); n = read(); mod = read(); for (int i = 0; i < 2 * n; ++i) { a[i].r = min(2 * n - 1, (int)sqrt(4 * n * n - i * i)); a[i].id = i; if (i >= n) a[i].l = -1; else a[i].l = sqrt(n * n - i * i - 1); } sort(a, a + 2 * n, cmp); LL ans = 0; for (int i = 0, sym = 1; i <= n; ++i, sym = -sym) { ans += sym * calc(i); ans %= mod; } ans = (ans + mod) % mod; printf("%lld\n", ans); close(); return 0; }
replace
82
83
82
83
TLE
p02969
C++
Runtime Error
#include <bits/stdc++.h> // #include<unordered_map> #define debug(x) (cout << "#x = " << (x) << endl) #define ls(x) (x << 1) #define rs(x) (x << 1 | 1) // #define mid (l + r >> 1) #define lowbit(x) (x & -x) #define Set(x, i) memset(x, i, sizeof x) #define R register #define For(i, j, k) for (R int i = (j); i <= (k); ++i) #define foR(i, j, k) for (R int i = (j); i >= (k); --i) #define Cross(i, j, k) \ for (R int i = (j); i; i = (k)) \ using namespace std; typedef long long ll; using namespace std; const ll N = 100011; const ll Inf = 0x3f3f3f3f3f3f; namespace IO { #define dd ch = getchar() inline ll read() { ll x = 0; bool f = 0; char dd; for (; !isdigit(ch); dd) f ^= (ch == '-'); for (; isdigit(ch); dd) x = x * 10 + (ch ^ 48); return f ? -x : x; } #undef dd inline void write(ll x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 | 48); } inline void wrn(ll x) { write(x); putchar(' '); } inline void wln(ll x) { write(x); putchar('\n'); } inline void wlnn(ll x, ll y) { wrn(x); wln(y); } } // namespace IO using namespace IO; namespace Cesare { int main() { ll a = read(); wln(a * a * 3); } } // namespace Cesare int main() { return Cesare::main(); } /* */
#include <bits/stdc++.h> // #include<unordered_map> #define debug(x) (cout << "#x = " << (x) << endl) #define ls(x) (x << 1) #define rs(x) (x << 1 | 1) // #define mid (l + r >> 1) #define lowbit(x) (x & -x) #define Set(x, i) memset(x, i, sizeof x) #define R register #define For(i, j, k) for (R int i = (j); i <= (k); ++i) #define foR(i, j, k) for (R int i = (j); i >= (k); --i) #define Cross(i, j, k) \ for (R int i = (j); i; i = (k)) \ using namespace std; typedef long long ll; using namespace std; const ll N = 100011; const ll Inf = 0x3f3f3f3f3f3f; namespace IO { #define dd ch = getchar() inline ll read() { ll x = 0; bool f = 0; char dd; for (; !isdigit(ch); dd) f ^= (ch == '-'); for (; isdigit(ch); dd) x = x * 10 + (ch ^ 48); return f ? -x : x; } #undef dd inline void write(ll x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 | 48); } inline void wrn(ll x) { write(x); putchar(' '); } inline void wln(ll x) { write(x); putchar('\n'); } inline void wlnn(ll x, ll y) { wrn(x); wln(y); } } // namespace IO using namespace IO; namespace Cesare { int main() { ll a = read(); return wln(a * a * 3), 0; } } // namespace Cesare int main() { return Cesare::main(); } /* */
replace
65
66
65
66
10
p02969
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int const int MOD = 1e9 + 7; const int MAXN = 2e5 + 5; int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS int n; cin >> n; cout << 3 * (n * n) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int const int MOD = 1e9 + 7; const int MAXN = 2e5 + 5; int32_t main() { IOS int n; cin >> n; cout << 3 * (n * n) << '\n'; return 0; }
replace
12
16
12
13
0
p02969
C++
Runtime Error
#include <iostream> int main(void) { int r; std::cin >> r; std::cout << 3 * (r * r); return true; }
#include <iostream> int main(void) { int r; std::cin >> r; std::cout << 3 * (r * r); return 0; }
replace
6
7
6
7
1
p02969
C++
Runtime Error
/**akshaykumar99**/ #include <bits/stdc++.h> using namespace std; #define F first #define S second #define pp pop_back() #define pu(x) push_back(x) #define eb(x) emplace_back(x) #define mp(a, b) make_pair(a, b) #define all(v) v.begin(), v.end() #define f(i, x, n) for (i = x; i < n; i++) #define rall(v) v.rbegin(), v.rend() const int MOD = 1e9 + 7, INF = INT_MAX; const long long LINF = LLONG_MAX; typedef long long ll; typedef long double ld; typedef vector<int> ivc; typedef pair<int, int> ipr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int r; cin >> r; ll z = r * r * 3; cout << z << endl; }
/**akshaykumar99**/ #include <bits/stdc++.h> using namespace std; #define F first #define S second #define pp pop_back() #define pu(x) push_back(x) #define eb(x) emplace_back(x) #define mp(a, b) make_pair(a, b) #define all(v) v.begin(), v.end() #define f(i, x, n) for (i = x; i < n; i++) #define rall(v) v.rbegin(), v.rend() const int MOD = 1e9 + 7, INF = INT_MAX; const long long LINF = LLONG_MAX; typedef long long ll; typedef long double ld; typedef vector<int> ivc; typedef pair<int, int> ipr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int r; cin >> r; ll z = r * r * 3; cout << z << endl; }
delete
27
31
27
27
0
p02969
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define PI 3.14159265 #define ll long long #define vi vector<int> #define pb push_back #define vll vector<ll> #define vvi vector<vi> #define pii pair<int, int> #define pll pair<long long, long long> #define mod 100000000 #define inf 1000000000000000001; #define all(c) c.begin(), c.end() #define mk(x, y) make_pair(x, y) #define mem(a, val) memset(a, val, sizeof(a)) #define eb emplace_back #define ff first #define ss second #define re return // #define endl "\n" #define max2(x, y) (x > y) ? x : y #define min2(x, y) (x < y) ? x : y #define mid(s, e) (s + (e - s) / 2) #define mini INT_MIN #define maxo INT_MAX #define rep(i, a, b) for (int i = a; i < (int)(b); ++i) #define read(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i] #define show(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << ' '; \ cout << endl #define en cout << "\n"; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; cout << 3 * n * n << endl; }
#include <bits/stdc++.h> using namespace std; #define PI 3.14159265 #define ll long long #define vi vector<int> #define pb push_back #define vll vector<ll> #define vvi vector<vi> #define pii pair<int, int> #define pll pair<long long, long long> #define mod 100000000 #define inf 1000000000000000001; #define all(c) c.begin(), c.end() #define mk(x, y) make_pair(x, y) #define mem(a, val) memset(a, val, sizeof(a)) #define eb emplace_back #define ff first #define ss second #define re return // #define endl "\n" #define max2(x, y) (x > y) ? x : y #define min2(x, y) (x < y) ? x : y #define mid(s, e) (s + (e - s) / 2) #define mini INT_MIN #define maxo INT_MAX #define rep(i, a, b) for (int i = a; i < (int)(b); ++i) #define read(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i] #define show(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << ' '; \ cout << endl #define en cout << "\n"; int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; cout << 3 * n * n << endl; }
replace
36
40
36
40
0
p02969
C++
Runtime Error
#include <iostream> using namespace std; int main() { int i; cin >> i; cout << i << endl; return i * i * 3; }
#include <iostream> using namespace std; int main() { int i; cin >> i; cout << 3 * i * i << endl; // return 0; };
replace
5
8
5
8
48
p02969
C++
Runtime Error
#include <bits/stdc++.h> #define INF INT_MAX #define endl '\n' #define ll long long int #define N 1000005 using namespace std; inline int redi() { int ret = 0, f = 0; char ch = getchar_unlocked(); while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar_unlocked(); } while (isdigit(ch)) { ret = ret * 10 + ch - 48; ch = getchar_unlocked(); } return f ? -ret : ret; } inline void print(int x) { if (x < 0) { putchar_unlocked('-'); x = -x; } int y = 10, len = 1; while (y <= x) { y *= 10; len++; } while (len--) { y /= 10; putchar_unlocked(x / y + 48); x %= y; } } inline void init() { ll n; cin >> n; cout << 3 * n * n << endl; } inline void solve() {} int main() { freopen("input.in", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(0); init(); solve(); cout << flush; return 0; }
#include <bits/stdc++.h> #define INF INT_MAX #define endl '\n' #define ll long long int #define N 1000005 using namespace std; inline int redi() { int ret = 0, f = 0; char ch = getchar_unlocked(); while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar_unlocked(); } while (isdigit(ch)) { ret = ret * 10 + ch - 48; ch = getchar_unlocked(); } return f ? -ret : ret; } inline void print(int x) { if (x < 0) { putchar_unlocked('-'); x = -x; } int y = 10, len = 1; while (y <= x) { y *= 10; len++; } while (len--) { y /= 10; putchar_unlocked(x / y + 48); x %= y; } } inline void init() { ll n; cin >> n; cout << 3 * n * n << endl; } inline void solve() {} int main() { // freopen("input.in","r",stdin); ios_base::sync_with_stdio(false); cin.tie(0); init(); solve(); cout << flush; return 0; }
replace
47
48
47
48
0
p02969
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <cstdlib> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; template <class T> using V = vector<T>; 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; } const long long INF = 1LL << 60; using ll = long long; using db = double; using st = string; using ch = char; using bl = bool; using vll = V<ll>; using vpll = V<pair<ll, ll>>; using vst = V<st>; using vdb = V<db>; using vch = V<ch>; using vbl = V<bl>; #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define rFOR(i, a, b) for (ll i = (a); i > (b); i--) #define oFOR(i, a, b) for (ll i = (a); i < (b); i += 2) #define bgn begin() #define en end() #define SORT(a) sort((a).bgn, (a).en) #define REV(a) reverse((a).bgn, (a).en) #define M(a, b) max(a, b) #define rM(a, b) min(a, b) #define fi first #define se second #define sz size() #define gcd(a, b) __gcd(a, b) #define co(a) cout << a << endl; #define ci(a) cin >> a; vll dp(100100); ll sum(ll n) { ll m = 0; FOR(i, 0, 20) { m += n % 10; n /= 10; if (n == 0) { break; } } return m; } const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void Comuse() { 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; } } #define comuse Comuse() ll combi(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll lcm(ll a, ll b) { ll n; n = a / gcd(a, b) * b; return n; } /****************************************\ | Thank you for viewing my code:) | | Written by RedSpica a.k.a. RanseMirage | | Twitter:@asakaakasaka | \****************************************/ signed main() { ll n; ci(n); FOR(i, 0, 2000000000) { if (i % 2 == 0) { n *= 3; } else { n /= 3; } } co(3 * n * n) }
#include <algorithm> #include <bits/stdc++.h> #include <cstdlib> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; template <class T> using V = vector<T>; 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; } const long long INF = 1LL << 60; using ll = long long; using db = double; using st = string; using ch = char; using bl = bool; using vll = V<ll>; using vpll = V<pair<ll, ll>>; using vst = V<st>; using vdb = V<db>; using vch = V<ch>; using vbl = V<bl>; #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define rFOR(i, a, b) for (ll i = (a); i > (b); i--) #define oFOR(i, a, b) for (ll i = (a); i < (b); i += 2) #define bgn begin() #define en end() #define SORT(a) sort((a).bgn, (a).en) #define REV(a) reverse((a).bgn, (a).en) #define M(a, b) max(a, b) #define rM(a, b) min(a, b) #define fi first #define se second #define sz size() #define gcd(a, b) __gcd(a, b) #define co(a) cout << a << endl; #define ci(a) cin >> a; vll dp(100100); ll sum(ll n) { ll m = 0; FOR(i, 0, 20) { m += n % 10; n /= 10; if (n == 0) { break; } } return m; } const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void Comuse() { 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; } } #define comuse Comuse() ll combi(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll lcm(ll a, ll b) { ll n; n = a / gcd(a, b) * b; return n; } /****************************************\ | Thank you for viewing my code:) | | Written by RedSpica a.k.a. RanseMirage | | Twitter:@asakaakasaka | \****************************************/ signed main() { ll n; ci(n); FOR(i, 0, 1500000000) { if (i % 2 == 0) { n *= 3; } else { n /= 3; } } co(3 * n * n) }
replace
111
112
111
112
TLE
p02969
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <cstdlib> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; template <class T> using V = vector<T>; 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; } const long long INF = 1LL << 60; using ll = long long; using db = double; using st = string; using ch = char; using bl = bool; using vll = V<ll>; using vpll = V<pair<ll, ll>>; using vst = V<st>; using vdb = V<db>; using vch = V<ch>; using vbl = V<bl>; #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define rFOR(i, a, b) for (ll i = (a); i > (b); i--) #define oFOR(i, a, b) for (ll i = (a); i < (b); i += 2) #define bgn begin() #define en end() #define SORT(a) sort((a).bgn, (a).en) #define REV(a) reverse((a).bgn, (a).en) #define M(a, b) max(a, b) #define rM(a, b) min(a, b) #define fi first #define se second #define sz size() #define gcd(a, b) __gcd(a, b) #define co(a) cout << a << endl; #define ci(a) cin >> a; vll dp(100100); ll sum(ll n) { ll m = 0; FOR(i, 0, 20) { m += n % 10; n /= 10; if (n == 0) { break; } } return m; } const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void Comuse() { 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; } } #define comuse Comuse() ll combi(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll lcm(ll a, ll b) { ll n; n = a / gcd(a, b) * b; return n; } /****************************************\ | Thank you for viewing my code:) | | Written by RedSpica a.k.a. RanseMirage | | Twitter:@asakaakasaka | \****************************************/ signed main() { ll n; ci(n); FOR(i, 0, 1999000000) { if (i % 2 == 0) { n *= 3; } else { n /= 3; } } co(3 * n * n) }
#include <algorithm> #include <bits/stdc++.h> #include <cstdlib> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; template <class T> using V = vector<T>; 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; } const long long INF = 1LL << 60; using ll = long long; using db = double; using st = string; using ch = char; using bl = bool; using vll = V<ll>; using vpll = V<pair<ll, ll>>; using vst = V<st>; using vdb = V<db>; using vch = V<ch>; using vbl = V<bl>; #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define rFOR(i, a, b) for (ll i = (a); i > (b); i--) #define oFOR(i, a, b) for (ll i = (a); i < (b); i += 2) #define bgn begin() #define en end() #define SORT(a) sort((a).bgn, (a).en) #define REV(a) reverse((a).bgn, (a).en) #define M(a, b) max(a, b) #define rM(a, b) min(a, b) #define fi first #define se second #define sz size() #define gcd(a, b) __gcd(a, b) #define co(a) cout << a << endl; #define ci(a) cin >> a; vll dp(100100); ll sum(ll n) { ll m = 0; FOR(i, 0, 20) { m += n % 10; n /= 10; if (n == 0) { break; } } return m; } const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void Comuse() { 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; } } #define comuse Comuse() ll combi(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll lcm(ll a, ll b) { ll n; n = a / gcd(a, b) * b; return n; } /****************************************\ | Thank you for viewing my code:) | | Written by RedSpica a.k.a. RanseMirage | | Twitter:@asakaakasaka | \****************************************/ signed main() { ll n; ci(n); FOR(i, 0, 1989000000) { if (i % 2 == 0) { n *= 3; } else { n /= 3; } } co(3 * n * n) }
replace
111
112
111
112
TLE
p02969
C++
Runtime Error
#include <bits/stdc++.h> #include <cmath> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define SUBL \ freopen("/home/ajinkya/Desktop/input.txt", "r", stdin); \ freopen("/home/ajinkya/Desktop/output.txt", "w", stdout); #define ll long long #define ull unsigned long long #define FI(i, a, n) for (int i = a; i <= n; i++) #define RFI(i, n, a) for (int i = n; i >= a; i--) #define FLL(i, a, n) for (ll i = a; i <= n; i++) #define RFLL(i, n, a) for (ll i = n; i >= a; i--) #define vi vector<int> #define vll vector<ll> #define all(v) v.begin(), v.end() #define pll pair<ll, ll> #define pi pair<int, int> #define GCD(a, b) __gcd(a, b) #define MP make_pair #define PB push_back #define PF push_front #define LB lower_bound #define UB upper_bound #define debug(x) cout << x << endl #define MOD 1000000007 #define INF LLONG_MAX #define PI 3.14159265359 using namespace std; int main() { fastio SUBL ll a; cin >> a; cout << 3 * a * a; return 0; }
#include <bits/stdc++.h> #include <cmath> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define SUBL \ freopen("/home/ajinkya/Desktop/input.txt", "r", stdin); \ freopen("/home/ajinkya/Desktop/output.txt", "w", stdout); #define ll long long #define ull unsigned long long #define FI(i, a, n) for (int i = a; i <= n; i++) #define RFI(i, n, a) for (int i = n; i >= a; i--) #define FLL(i, a, n) for (ll i = a; i <= n; i++) #define RFLL(i, n, a) for (ll i = n; i >= a; i--) #define vi vector<int> #define vll vector<ll> #define all(v) v.begin(), v.end() #define pll pair<ll, ll> #define pi pair<int, int> #define GCD(a, b) __gcd(a, b) #define MP make_pair #define PB push_back #define PF push_front #define LB lower_bound #define UB upper_bound #define debug(x) cout << x << endl #define MOD 1000000007 #define INF LLONG_MAX #define PI 3.14159265359 using namespace std; int main() { fastio // SUBL ll a; cin >> a; cout << 3 * a * a; return 0; }
replace
33
34
33
36
0
p02969
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define x first #define y second #define pb push_back #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); using namespace std; signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif speed int r; cin >> r; cout << (3 * r * r); }
#include <bits/stdc++.h> #define int long long #define x first #define y second #define pb push_back #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); using namespace std; signed main() { speed int r; cin >> r; cout << (3 * r * r); }
delete
11
15
11
11
0
p02969
Python
Runtime Error
r = input() s = 3 * (r**2) print(s)
r = int(input()) s = 3 * (r**2) print(s)
replace
0
1
0
1
TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02969/Python/s133388758.py", line 2, in <module> s = 3 * (r ** 2) TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
p02969
Python
Runtime Error
r = input() print(3 * r * r)
r = int(input()) print(3 * r * r)
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/p02969/Python/s048208097.py", line 2, in <module> print(3 * r * r) TypeError: can't multiply sequence by non-int of type 'str'
p02969
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; a *= 3 * a; cout << a << endl; return a; }
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; a *= 3 * a; cout << a << endl; return 0; }
replace
8
9
8
9
48
p02970
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, d; cin >> n >> d; int ans = n / (2 * d + 1); if (n % (ans * (2 * d + 1)) != 0) { ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, d; cin >> n >> d; int a = 2 * d + 1; int ans = n / a; if (ans * a != n) { ans++; } cout << ans << endl; }
replace
7
9
7
10
0
p02970
C++
Runtime Error
// include,using,define等 #pragma region header #include <algorithm> #include <assert.h> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdint> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> // =============================================================== // using系 #pragma region header using namespace std; using ll = long long; using lint = long long; using vl = vector<long long>; using vvl = vector<vector<long long>>; using vvi = vector<vector<int>>; using Graph = vvi; using vs = vector<string>; using vc = vector<char>; using vcc = vector<vector<char>>; using vm = vector<short>; using vmm = vector<vector<short>>; using pii = pair<int, int>; using psi = pair<string, int>; using ld = long double; using ull = unsigned long long; using ui = unsigned int; using qul = queue<ll>; using pql = priority_queue<ll>; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; constexpr ll mod = 1e9 + 7; constexpr long double pi = 3.141592653589793238462643383279; #pragma endregion // ======================================================================== // define #pragma region header // #define int long long #define rep(i, n) for (ll i = 0; i < n; i++) #define REP(i, n) for (ll i = 1; i <= n; i++) #define inf (ll)(3e18) #define P pair<int, int> template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } #pragma endregion #pragma endregion // 整数系ライブラリ #pragma region header ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } // 最大公約数 ll lcm(ll a, ll b) { return a * b / gcd(a, b); } // 最小公倍数 ll box(double a) { ll b = a; return b; } // 切り捨て ll fff(double a) { ll b = a + 0.5; return b; } // 四捨五入 ll mch(ll n) { if (n == 1) return 1; else return n * mch(n - 1); } // 1から整数nまでの階乗を出す(INFで割っていない) bool prime(ll a) // 素数判定、primeならtrue,違うならfalse { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; double m = sqrt(a); for (int i = 3; i <= m; i += 2) { if (a % i == 0) { return false; } } // 素数である return true; } // 素数判定 ll modpow(ll a, ll n, ll mod) { ll hi = 1; while (n > 0) { if (n & 1) hi = hi * a % mod; a = a * a % mod; n >>= 1; } return hi; } // いろいろやります(ただの前座) ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); } // 割り算の10^9+7等対策で逆元を出します ll num(ll a) { string s = to_string(a); ll sum = 0; for (int j = 0; j < s.size(); ++j) { sum += (ll)s[j] - '0'; } return sum; } // 整数aのすべての桁の和 #pragma endregion // グラフ・木系ライブラリ #pragma region header struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { // 根を出す if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { // 同じ集合なのかを調べる return root(x) == root(y); } bool unite(int x, int y) { // xの根とyの根をつなげる x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; // ======================================================================== #pragma endregion // ここから問題ごとに書く /*signed*/ int main() { ll n, d; cin >> n >> d; lint a = n / (d + d + 1); if (n % a > 0) a++; cout << a << endl; return 0; }
// include,using,define等 #pragma region header #include <algorithm> #include <assert.h> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdint> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> // =============================================================== // using系 #pragma region header using namespace std; using ll = long long; using lint = long long; using vl = vector<long long>; using vvl = vector<vector<long long>>; using vvi = vector<vector<int>>; using Graph = vvi; using vs = vector<string>; using vc = vector<char>; using vcc = vector<vector<char>>; using vm = vector<short>; using vmm = vector<vector<short>>; using pii = pair<int, int>; using psi = pair<string, int>; using ld = long double; using ull = unsigned long long; using ui = unsigned int; using qul = queue<ll>; using pql = priority_queue<ll>; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; constexpr ll mod = 1e9 + 7; constexpr long double pi = 3.141592653589793238462643383279; #pragma endregion // ======================================================================== // define #pragma region header // #define int long long #define rep(i, n) for (ll i = 0; i < n; i++) #define REP(i, n) for (ll i = 1; i <= n; i++) #define inf (ll)(3e18) #define P pair<int, int> template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } #pragma endregion #pragma endregion // 整数系ライブラリ #pragma region header ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } // 最大公約数 ll lcm(ll a, ll b) { return a * b / gcd(a, b); } // 最小公倍数 ll box(double a) { ll b = a; return b; } // 切り捨て ll fff(double a) { ll b = a + 0.5; return b; } // 四捨五入 ll mch(ll n) { if (n == 1) return 1; else return n * mch(n - 1); } // 1から整数nまでの階乗を出す(INFで割っていない) bool prime(ll a) // 素数判定、primeならtrue,違うならfalse { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; double m = sqrt(a); for (int i = 3; i <= m; i += 2) { if (a % i == 0) { return false; } } // 素数である return true; } // 素数判定 ll modpow(ll a, ll n, ll mod) { ll hi = 1; while (n > 0) { if (n & 1) hi = hi * a % mod; a = a * a % mod; n >>= 1; } return hi; } // いろいろやります(ただの前座) ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); } // 割り算の10^9+7等対策で逆元を出します ll num(ll a) { string s = to_string(a); ll sum = 0; for (int j = 0; j < s.size(); ++j) { sum += (ll)s[j] - '0'; } return sum; } // 整数aのすべての桁の和 #pragma endregion // グラフ・木系ライブラリ #pragma region header struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} void init(int n) { par.assign(n, -1); } int root(int x) { // 根を出す if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { // 同じ集合なのかを調べる return root(x) == root(y); } bool unite(int x, int y) { // xの根とyの根をつなげる x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; // ======================================================================== #pragma endregion // ここから問題ごとに書く /*signed*/ int main() { ll n, d; cin >> n >> d; lint a = n / (d + d + 1); if (n % (d + d + 1) > 0) a++; cout << a << endl; return 0; }
replace
201
202
201
202
0
p02970
C++
Runtime Error
//----------BHAVIK DIWANI(PICT_COMP)--------------- #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define test \ ll t; \ cin >> t; \ while (t--) #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define mod 1000000007 #define ll long long #define int long long #define ull unsigned long long #define MAX 1000005 #define pb push_back #define mkp make_pair #define vi vector<int> #define pii pair<int, int> #define endl '\n' #define vs vector<string> #define mii map<int, int> #define msi map<string, int> #define vpii vector<pair<int, int>> #define vpsi vector<pair<string, int>> #define forci(p, q) for (int i = p; i < q; i++) ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); } ull power(ull a, ull b) { a %= mod; ull res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res % mod; } ll modmul(ll x, ll y) { return (x * y) % mod; } ll modadd(ll x, ll y) { return (x + y) % mod; } ll modsub(ll x, ll y) { return (x - y + mod) % mod; } ll fact[1000007] = {0}; void facto() { fact[0] = 1; fact[1] = 1; for (int i = 2; i < 1000007; i++) fact[i] = (fact[i - 1] * i) % mod; } ll ncr(ll n, ll r) { ll res = 1; res = fact[n]; res = (res * (power(fact[r], mod - 2))) % mod; res = (res * (power(fact[n - r], mod - 2))) % mod; return res; } ll npr(ll n, ll r) { ll res = 1; res = fact[n]; res = (res * (power(fact[n - r], mod - 2))) % mod; return res; } inline long long toint(const std::string &s) { std::stringstream ss; ss << s; long long x; ss >> x; return x; } inline std::string tostring(long long number) { std::stringstream ss; ss << number; return ss.str(); } inline std::string tobin(long long x) { return std::bitset<63>(x).to_string(); } /*bool prime[MAX]; ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0; }*/ /*int inv[1000001]={0}; void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i) inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;} */ using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset; int solve() { int n, d; cin >> n >> d; cout << (n + 2 * d) / (2 * d + 1) << endl; } signed main() { fastio; // test solve(); }
//----------BHAVIK DIWANI(PICT_COMP)--------------- #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define test \ ll t; \ cin >> t; \ while (t--) #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define mod 1000000007 #define ll long long #define int long long #define ull unsigned long long #define MAX 1000005 #define pb push_back #define mkp make_pair #define vi vector<int> #define pii pair<int, int> #define endl '\n' #define vs vector<string> #define mii map<int, int> #define msi map<string, int> #define vpii vector<pair<int, int>> #define vpsi vector<pair<string, int>> #define forci(p, q) for (int i = p; i < q; i++) ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); } ull power(ull a, ull b) { a %= mod; ull res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res % mod; } ll modmul(ll x, ll y) { return (x * y) % mod; } ll modadd(ll x, ll y) { return (x + y) % mod; } ll modsub(ll x, ll y) { return (x - y + mod) % mod; } ll fact[1000007] = {0}; void facto() { fact[0] = 1; fact[1] = 1; for (int i = 2; i < 1000007; i++) fact[i] = (fact[i - 1] * i) % mod; } ll ncr(ll n, ll r) { ll res = 1; res = fact[n]; res = (res * (power(fact[r], mod - 2))) % mod; res = (res * (power(fact[n - r], mod - 2))) % mod; return res; } ll npr(ll n, ll r) { ll res = 1; res = fact[n]; res = (res * (power(fact[n - r], mod - 2))) % mod; return res; } inline long long toint(const std::string &s) { std::stringstream ss; ss << s; long long x; ss >> x; return x; } inline std::string tostring(long long number) { std::stringstream ss; ss << number; return ss.str(); } inline std::string tobin(long long x) { return std::bitset<63>(x).to_string(); } /*bool prime[MAX]; ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0; }*/ /*int inv[1000001]={0}; void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i) inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;} */ using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset; int solve() { int n, d; cin >> n >> d; cout << (n + 2 * d) / (2 * d + 1) << endl; return 0; } signed main() { fastio; // test solve(); }
insert
102
102
102
103
0
p02970
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> using namespace std; #define rg register #define LL long long #define __space putchar(' ') #define __endl putchar('\n') template <typename qwq> inline void read(qwq &x) { x = 0; rg LL f = 1; rg char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } x *= f; } template <typename qaq> inline void print(qaq x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) print(x / 10); putchar(x % 10 + '0'); } int n, d; int main() { read(n), read(d); rg int tmp = n / (2 * d + 1); if (!(n % (tmp * (2 * d + 1)))) print(tmp); else print(tmp + 1); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> using namespace std; #define rg register #define LL long long #define __space putchar(' ') #define __endl putchar('\n') template <typename qwq> inline void read(qwq &x) { x = 0; rg LL f = 1; rg char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } x *= f; } template <typename qaq> inline void print(qaq x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) print(x / 10); putchar(x % 10 + '0'); } int n, d; int main() { read(n), read(d); rg int tmp = n / (2 * d + 1); if (!tmp) print(1); else if (!(n % (tmp * (2 * d + 1)))) print(tmp); else print(tmp + 1); return 0; }
replace
42
43
42
45
0
p02970
C++
Runtime Error
#include <iostream> using namespace std; int main(void) { int n, d; cin >> n >> d; cout << n / (2 * d + 1) + (n % (2 * d + 1) == 0 ? 0 : 1) << endl; return 1; }
#include <iostream> using namespace std; int main(void) { int n, d; cin >> n >> d; cout << n / (2 * d + 1) + (n % (2 * d + 1) == 0 ? 0 : 1) << endl; return 0; }
replace
9
10
9
10
1
p02970
C++
Runtime Error
#include <bits/stdc++.h> #include <string> #include <vector> using namespace std; int main() { int n, d; cin >> n >> d; int count = 0; int tree[20]; for (int i = 0; i < n; i++) { tree[i] = 0; } for (int i = 0; i < n; i++) { if (tree[i] == 0) { for (int j = i; j <= i + 2 * d; j++) { tree[j] = 1; } count++; } } cout << count << endl; return 0; }
#include <bits/stdc++.h> #include <string> #include <vector> using namespace std; int main() { int n, d; cin >> n >> d; int count = 0; int tree[100]; for (int i = 0; i < n; i++) { tree[i] = 0; } for (int i = 0; i < n; i++) { if (tree[i] == 0) { for (int j = i; j <= i + 2 * d; j++) { tree[j] = 1; } count++; } } cout << count << endl; return 0; }
replace
8
9
8
9
0
p02970
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define REPI(i, n) for (int i = 0; i < n; i++) #define REPJ(j, n) for (int j = 0; j < n; j++) using ll = long long; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, d, ans = 0; cin >> n >> d; d = 2 * d + 1; for (; n > 0; ans++) d -= n; cout << ans; }
#include <bits/stdc++.h> #define REPI(i, n) for (int i = 0; i < n; i++) #define REPJ(j, n) for (int j = 0; j < n; j++) using ll = long long; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, d, ans = 0; cin >> n >> d; d = 2 * d + 1; for (; n > 0; ans++) n -= d; cout << ans; }
replace
16
17
16
17
TLE
p02970
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; int d; cin >> d; d = d * 2; d++; d = n / d; if (n % d != 0) d++; cout << d << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; int d; cin >> d; d = d * 2; d++; // cout<<d<<endl; int u = n / d; if (u == 0) u++; else { if (n % d != 0) u++; } cout << u << endl; }
replace
13
17
13
22
0
p02970
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, d, c = 0; cin >> n >> d; vector<int> v; int a = (d + 1); while (a <= n) { c++; v.push_back(a); a += (2 * d + 1); } if ((n - (*(v.end() - 1))) > d) c++; cout << c; }
#include <bits/stdc++.h> using namespace std; int main() { int n, d, c = 0; cin >> n >> d; vector<int> v; int a = (d + 1); while (a <= n) { c++; v.push_back(a); a += (2 * d + 1); } if (c == 0) { cout << "1"; return 0; } if ((n - (*(v.end() - 1))) > d) c++; cout << c; }
insert
13
13
13
17
0
p02970
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, D; cin >> N >> D; int i = 1; int look = 0; while (1) { look += 2 * D + 1; if (look >= N) { return i; } i++; } cout << i << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, D; cin >> N >> D; int i = 1; int look = 0; while (1) { look += 2 * D + 1; if (look >= N) { break; } i++; } cout << i << endl; }
replace
11
12
11
12
2
p02970
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { long long n, m, sum = 0, mod = 2019; cin >> n, m; cout << n / (2 * m) + 1 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main() { long long n, m, sum = 0, mod = 2019; cin >> n >> m; if (n % (2 * m + 1) == 0) cout << n / (2 * m + 1) << endl; else cout << n / (2 * m + 1) + 1 << endl; }
replace
6
9
6
11
0
p02970
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int const int MOD = 1e9 + 7; const int MAXN = 2e5 + 5; int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS int n, d; cin >> n >> d; int ans = ceil((1.0 * n) / (2 * d + 1)); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int const int MOD = 1e9 + 7; const int MAXN = 2e5 + 5; int32_t main() { IOS int n, d; cin >> n >> d; int ans = ceil((1.0 * n) / (2 * d + 1)); cout << ans; return 0; }
replace
12
16
12
13
0
p02970
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define x first #define y second #define pb push_back #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); using namespace std; signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif speed int n, d; cin >> n >> d; int q = (2 * d + 1); if ((n % q) == 0) { cout << (n / q); } else { cout << (n / q) + 1; } }
#include <bits/stdc++.h> #define int long long #define x first #define y second #define pb push_back #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); using namespace std; signed main() { speed int n, d; cin >> n >> d; int q = (2 * d + 1); if ((n % q) == 0) { cout << (n / q); } else { cout << (n / q) + 1; } }
delete
11
15
11
11
0
p02970
Python
Runtime Error
n, d = map(int, input()) print(-(-n // (1 + d * 2)))
n, d = map(int, input().split()) print(-(-n // (1 + d * 2)))
replace
0
1
0
1
ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02970/Python/s626799708.py", line 1, in <module> n, d = map(int, input()) ValueError: invalid literal for int() with base 10: ' '
p02971
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; #define mod 1000000007 #define pb push_back #define mp(a, b) make_pair(a, b) #define pii pair<int, int> #define pll pair<ll, ll> #define vll vector<ll> #define vii vector<int> #define vpii vector<pii> #define vpll vector<pll> #define ff first #define ss second #define matrix vector<vll> #define all(v) v.begin(), v.end() #define PQ priority_queue using namespace std; ll pow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res *= a; b /= 2; a *= a; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vii v(n); multiset<int> ml; for (int i = 0; i < n; i++) { cin >> v[i]; ml.insert(v[i]); } for (int i = 0; i < n; i++) { ml.erase(v[i]); auto it = ml.rbegin(); cout << *it << "\n"; ml.insert(v[i]); } return 0; }
#include <bits/stdc++.h> typedef long long ll; #define mod 1000000007 #define pb push_back #define mp(a, b) make_pair(a, b) #define pii pair<int, int> #define pll pair<ll, ll> #define vll vector<ll> #define vii vector<int> #define vpii vector<pii> #define vpll vector<pll> #define ff first #define ss second #define matrix vector<vll> #define all(v) v.begin(), v.end() #define PQ priority_queue using namespace std; ll pow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res *= a; b /= 2; a *= a; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vii v(n); multiset<int> ml; for (int i = 0; i < n; i++) { cin >> v[i]; ml.insert(v[i]); } for (int i = 0; i < n; i++) { ml.erase(ml.find(v[i])); auto it = ml.rbegin(); cout << *it << "\n"; ml.insert(v[i]); } return 0; }
replace
39
40
39
40
0
p02971
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <math.h> #include <stdio.h> using namespace std; using vi = vector<int>; using vvi = vector<vector<int>>; using ll = long long int; int main() { int N; cin >> N; vi vec(N); for (int i = 0; i < N; i++) { cin >> vec[i]; } for (int i = 0; i < N; i++) { vi v = vec; v[i] = -1; sort(v.begin(), v.end()); cout << v[N - 1] << endl; } }
#include <bits/stdc++.h> #include <math.h> #include <stdio.h> using namespace std; using vi = vector<int>; using vvi = vector<vector<int>>; using ll = long long int; int main() { int N; cin >> N; vi vec(N); for (int i = 0; i < N; i++) { cin >> vec[i]; } vi v = vec; int num = v.size(); sort(v.begin(), v.end()); bool r = true; if (v[N - 1] == v[N - 2]) { r = false; } vi res(0); res.push_back(v[0]); for (int i = 1; i < num; i++) { if (v[i] != v[i - 1]) { res.push_back(v[i]); } } ll k = v[N - 1]; ll g = res.size(); if (r == true) { for (auto x : vec) { if (x == k) { cout << res[g - 2] << endl; } else { cout << res[g - 1] << endl; } } } else { for (auto x : vec) { cout << res[g - 1] << endl; } } }
replace
15
20
15
43
TLE
p02971
C++
Runtime Error
#include <iostream> using namespace std; const int N = 20000; int main() { int n, array[N], max_value1 = -1, max_value2 = -1, max_index = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> array[i]; } for (int i = 0; i < n; i++) { if (max_value1 < array[i]) { max_value1 = array[i]; max_index = i; } } for (int i = 0; i < n; i++) { if (i == max_index) continue; if (max_value2 < array[i]) { max_value2 = array[i]; } } for (int i = 0; i < n; i++) { if (i != max_index) cout << max_value1 << endl; else cout << max_value2 << endl; } }
#include <iostream> using namespace std; const int N = 200000; int main() { int n, array[N], max_value1 = -1, max_value2 = -1, max_index = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> array[i]; } for (int i = 0; i < n; i++) { if (max_value1 < array[i]) { max_value1 = array[i]; max_index = i; } } for (int i = 0; i < n; i++) { if (i == max_index) continue; if (max_value2 < array[i]) { max_value2 = array[i]; } } for (int i = 0; i < n; i++) { if (i != max_index) cout << max_value1 << endl; else cout << max_value2 << endl; } }
replace
4
5
4
5
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int max = 0, max_second = 0; vector<int> data(n); vector<int> dp(200001); for (int i = 0; i < n; i++) { cin >> data.at(i); dp.at(data.at(i))++; if (max < data.at(i)) max = data.at(i); } for (int i = max - 1;; i--) { if (dp.at(i) > 0) { max_second = i; break; } } if (dp.at(max) > 1) { for (int i = 0; i < n; i++) { cout << max << endl; } return 0; } for (int i = 0; i < n; i++) { if (data.at(i) == max) { cout << max_second << endl; } else { cout << max << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int max = 0, max_second = 0; vector<int> data(n); vector<int> dp(200001); for (int i = 0; i < n; i++) { cin >> data.at(i); dp.at(data.at(i))++; if (max < data.at(i)) max = data.at(i); } for (int i = max - 1; i >= 0; i--) { if (dp.at(i) > 0) { max_second = i; break; } } if (dp.at(max) > 1) { for (int i = 0; i < n; i++) { cout << max << endl; } return 0; } for (int i = 0; i < n; i++) { if (data.at(i) == max) { cout << max_second << endl; } else { cout << max << endl; } } }
replace
16
17
16
17
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> a(N); int MAX = 0, MAXi; for (int i = 0; i < N; i++) { cin >> a.at(i); if (a.at(i) > MAX) { MAX = a.at(i); MAXi = i; } } for (int i = 0; i < N; i++) { if (i == MAXi) { int MAX2 = 0; for (int j = 0; i < N; j++) { if (j != i) MAX2 = max(MAX2, a.at(j)); } cout << MAX2 << endl; } else { cout << MAX << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> a(N); int MAX = 0, MAXi; for (int i = 0; i < N; i++) { cin >> a.at(i); if (a.at(i) > MAX) { MAX = a.at(i); MAXi = i; } } for (int i = 0; i < N; i++) { if (i == MAXi) { int MAX2 = 0; for (int j = 0; j < N; j++) { if (j != i) MAX2 = max(MAX2, a.at(j)); } cout << MAX2 << endl; } else { cout << MAX << endl; } } }
replace
21
22
21
22
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
p02971
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; typedef unsigned long ulint; const int mod = 2019; int main() { int n; cin >> n; int a[n]; int maxall = 0; int maxnum = -1; for (int i = 0; i < n; i++) { cin >> a[i]; if (maxall <= a[i]) { maxall = a[i]; maxnum = i; } // maxall = max(maxall, a[i]); } // i == 除外 for (int i = 0; i < n; i++) { int maxtmp = 0; if (i < maxnum) { cout << maxall << endl; continue; } for (int j = 0; j < n; j++) { if (i != j && maxall == a[j]) { maxtmp = maxall; break; } if (i != j) { maxtmp = max(maxtmp, a[j]); } } cout << maxtmp << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; typedef unsigned long ulint; const int mod = 2019; int main() { int n; cin >> n; int a[n]; int maxall = 0; int maxnum = -1; for (int i = 0; i < n; i++) { cin >> a[i]; if (maxall <= a[i]) { maxall = a[i]; maxnum = i; } // maxall = max(maxall, a[i]); } // i == 除外 for (int i = 0; i < n; i++) { int maxtmp = 0; if (i != maxnum) { cout << maxall << endl; continue; } for (int j = 0; j < n; j++) { if (i != j && maxall == a[j]) { maxtmp = maxall; break; } if (i != j) { maxtmp = max(maxtmp, a[j]); } } cout << maxtmp << endl; } return 0; }
replace
27
28
27
28
TLE
p02971
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #ifdef LOCAL #define enu(i, n) for (int i = 0; i < n; i++) #define tri(x) x *(x + 1) / 2; #define sqrsum(x) x *(x + 1) * (2 * x + 1) / 6; #define sqrsum_range(a, b) sqrsum(b) - sqrsum(a - 1); #endif #define FOR(i, a, b) for (int i = a, _b = b; i < _b; i++) #define REP(i, a, b) FOR(i, a, b + 1) #define ll_max 9223372036854775807LL #define ll_min -9223372036854775808LL #define int_max 2147483647 #define int_min -2147483648 #define PI 3.14159265358979323846265 #define eps 0.00000001 #define elif else if using namespace std; void fast() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); return; } bool isprime(int x) { if (x < 2) return false; for (int i = 2; i <= sqrt(x); i++) if (x % i == 0) return false; return true; } int GCD(int a, int b) { return (b ? GCD(b, a % b) : a); } struct Tm { int h, m, s; bool add() { s++; if (s == 60) m++, s = 0; if (m == 60) h++, m = 0; return (h < 100); } void print() { printf("%02d:%02d:%02d", h, m, s); return; } void println() { print(); puts(""); } }; int A[100100]; int main() { int a; cin >> a; for (int i = 0; i < a; i++) cin >> A[i]; int x = max_element(A, A + a) - A; sort(A, A + a); for (int i = 0; i < a; i++) if (i == x) cout << A[a - 2] << endl; else cout << A[a - 1] << endl; return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #ifdef LOCAL #define enu(i, n) for (int i = 0; i < n; i++) #define tri(x) x *(x + 1) / 2; #define sqrsum(x) x *(x + 1) * (2 * x + 1) / 6; #define sqrsum_range(a, b) sqrsum(b) - sqrsum(a - 1); #endif #define FOR(i, a, b) for (int i = a, _b = b; i < _b; i++) #define REP(i, a, b) FOR(i, a, b + 1) #define ll_max 9223372036854775807LL #define ll_min -9223372036854775808LL #define int_max 2147483647 #define int_min -2147483648 #define PI 3.14159265358979323846265 #define eps 0.00000001 #define elif else if using namespace std; void fast() { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); return; } bool isprime(int x) { if (x < 2) return false; for (int i = 2; i <= sqrt(x); i++) if (x % i == 0) return false; return true; } int GCD(int a, int b) { return (b ? GCD(b, a % b) : a); } struct Tm { int h, m, s; bool add() { s++; if (s == 60) m++, s = 0; if (m == 60) h++, m = 0; return (h < 100); } void print() { printf("%02d:%02d:%02d", h, m, s); return; } void println() { print(); puts(""); } }; int A[200200]; int main() { int a; cin >> a; for (int i = 0; i < a; i++) cin >> A[i]; int x = max_element(A, A + a) - A; sort(A, A + a); for (int i = 0; i < a; i++) if (i == x) cout << A[a - 2] << endl; else cout << A[a - 1] << endl; return 0; }
replace
67
68
67
68
0
p02971
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) #define fi first #define se second #define pb push_back #define pll pair<ll, ll> #define vi vector<int> #define vb vector<bool> #define vvi vector<vi> #define vpll vector<pll> #define vll vector<ll> #define vvll vector<vll> #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() void fastik() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } // ifstream &cin void solve() {} int main() { fastik(); // ifstream cin("input.txt"); /*ll t = 1; cin >> t; while (t--) { solve(); }*/ ll n; cin >> n; vll a(n, 0); multiset<ll> s; set<ll> ss; forn(i, n) { cin >> a[i]; s.insert(a[i]); ss.insert(a[i]); } ll x; ll cnt; vll ans(n + 1, 0); forn(i, n) { if (ans[a[i]]) { cout << ans[a[i]] << '\n'; continue; } for (auto it = ss.rbegin(); it != ss.rend(); ++it) { x = *it; if (x != a[i]) { cout << x << '\n'; ans[a[i]] = x; break; } else if ((x == a[i] && s.count(a[i]) > 1)) { cout << x << '\n'; ans[a[i]] = x; break; } } } return 0; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) #define fi first #define se second #define pb push_back #define pll pair<ll, ll> #define vi vector<int> #define vb vector<bool> #define vvi vector<vi> #define vpll vector<pll> #define vll vector<ll> #define vvll vector<vll> #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() void fastik() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } // ifstream &cin void solve() {} int main() { fastik(); // ifstream cin("input.txt"); /*ll t = 1; cin >> t; while (t--) { solve(); }*/ ll n; cin >> n; vll a(n, 0); multiset<ll> s; set<ll> ss; forn(i, n) { cin >> a[i]; s.insert(a[i]); ss.insert(a[i]); } ll x; ll cnt; vll ans(ll(2e+5) + 1, 0); forn(i, n) { if (ans[a[i]]) { cout << ans[a[i]] << '\n'; continue; } for (auto it = ss.rbegin(); it != ss.rend(); ++it) { x = *it; if (x != a[i]) { cout << x << '\n'; ans[a[i]] = x; break; } else if ((x == a[i] && s.count(a[i]) > 1)) { cout << x << '\n'; ans[a[i]] = x; break; } } } return 0; }
replace
62
63
62
63
0
p02971
C++
Runtime Error
#include <iostream> using namespace std; const int N = 1e5 + 5; int a[N]; int main() { int n, i, max1 = 0, max2 = 0, p; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > max1) { max1 = a[i]; p = i; } } for (i = 1; i <= n; i++) if (i != p && a[i] > max2) max2 = a[i]; for (i = 1; i <= n; i++) if (i != p) cout << max1 << endl; else cout << max2 << endl; return 0; }
#include <iostream> using namespace std; const int N = 2e5 + 5; int a[N]; int main() { int n, i, max1 = 0, max2 = 0, p; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; if (a[i] > max1) { max1 = a[i]; p = i; } } for (i = 1; i <= n; i++) if (i != p && a[i] > max2) max2 = a[i]; for (i = 1; i <= n; i++) if (i != p) cout << max1 << endl; else cout << max2 << endl; return 0; }
replace
2
3
2
3
0
p02971
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int N, A[200000], sA[200000]; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; sA[i] = A[i]; } for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (sA[i] < sA[j]) { int tmp = sA[i]; sA[i] = sA[j]; sA[j] = tmp; } } } for (int i = 0; i < N; i++) { int j = 0; if (A[i] == sA[0]) cout << sA[1] << endl; else cout << sA[j] << endl; } return 0; }
#include <iostream> using namespace std; int main() { int N, A[200000], sA[200000]; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; sA[i] = A[i]; } sort(sA, sA + N, greater<int>()); for (int i = 0; i < N; i++) { int j = 0; if (A[i] == sA[0]) cout << sA[1] << endl; else cout << sA[j] << endl; } return 0; }
replace
9
18
9
10
TLE
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 100010, Mod = 998244353; const double pi = acos(-1.0); typedef long long int ll; typedef pair<int, int> pii; int n, a[N], b[N]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i]; sort(b + 1, b + n + 1); int mx = b[n], mx2 = b[n - 1]; for (int i = 1; i <= n; i++) if (a[i] != mx) cout << mx << endl; else cout << mx2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200010, Mod = 998244353; const double pi = acos(-1.0); typedef long long int ll; typedef pair<int, int> pii; int n, a[N], b[N]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i]; sort(b + 1, b + n + 1); int mx = b[n], mx2 = b[n - 1]; for (int i = 1; i <= n; i++) if (a[i] != mx) cout << mx << endl; else cout << mx2 << endl; return 0; }
replace
2
3
2
3
0
p02971
C++
Runtime Error
#pragma region #include <bits/stdc++.h> using namespace std; inline void ci(void) { return; } template <typename First, typename... Rest> void ci(First &first, Rest &...rest) { cin >> first; ci(rest...); return; } inline void co(void) { cout << "\n"; return; } template <typename First, typename... Rest> void co(First first, Rest... rest) { cout << first << " "; co(rest...); return; } #define ll long long #define ld long double #define st string #define dl double #define wh while #define mp make_pair #define mt make_tuple #define pb push_back #define tp tuple #define ft first #define sc second #define ve vector #define tos to_string #define len length #define rt return 0 #define gcd __gcd #define lcm(n, m) n *m / gcd(n, m) #define np next_permutation #define repi(i, m, n) for (int i = (int)(m); i < (int)(n); i++) #define rep(i, n) repi(i, 0, n) #define sz(v) ((int)(v).size()) #define each(i, n) for (auto &&i : n) #define so(n) sort(n.begin(), n.end()) #define rev(n) reverse(n.begin(), n.end()) #define sp(n) cout << fixed << setprecision(n) #pragma endregion // sqrt ルート, int 2*10^9, gcd 最大公約数 int main() { int N; ci(N); ve<int> A(N), B(N); rep(i, N) { ci(A.at(i)); B.at(i) = A.at(i); } so(B); rep(i, N) { int a = 0; if (B.at(N - 1) == A.at(i)) { a = B.at(N); } else { a = B.at(N - 1); } co(a); } }
#pragma region #include <bits/stdc++.h> using namespace std; inline void ci(void) { return; } template <typename First, typename... Rest> void ci(First &first, Rest &...rest) { cin >> first; ci(rest...); return; } inline void co(void) { cout << "\n"; return; } template <typename First, typename... Rest> void co(First first, Rest... rest) { cout << first << " "; co(rest...); return; } #define ll long long #define ld long double #define st string #define dl double #define wh while #define mp make_pair #define mt make_tuple #define pb push_back #define tp tuple #define ft first #define sc second #define ve vector #define tos to_string #define len length #define rt return 0 #define gcd __gcd #define lcm(n, m) n *m / gcd(n, m) #define np next_permutation #define repi(i, m, n) for (int i = (int)(m); i < (int)(n); i++) #define rep(i, n) repi(i, 0, n) #define sz(v) ((int)(v).size()) #define each(i, n) for (auto &&i : n) #define so(n) sort(n.begin(), n.end()) #define rev(n) reverse(n.begin(), n.end()) #define sp(n) cout << fixed << setprecision(n) #pragma endregion // sqrt ルート, int 2*10^9, gcd 最大公約数 int main() { int N; ci(N); ve<int> A(N), B(N); rep(i, N) { ci(A.at(i)); B.at(i) = A.at(i); } so(B); rep(i, N) { int a = 0; if (B.at(N - 1) == A.at(i)) { a = B.at(N - 2); } else { a = B.at(N - 1); } co(a); } }
replace
59
60
59
60
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
p02971
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <math.h> #include <string> using namespace std; int main() { int n, a[20005]; pair<int, int> p[20005]; cin >> n; int max1 = -1, max2 = -1, ind1, ind2; for (int i = 0; i < n; i++) { cin >> a[i]; p[i] = make_pair(a[i], i); } sort(p, p + n); max1 = p[n - 1].first; max2 = p[n - 2].first; ind1 = p[n - 1].second; ind2 = p[n - 2].second; for (int i = 0; i < n; i++) { if (a[i] == max1 && i == ind1) cout << max2 << endl; else cout << max1 << endl; } }
#include <algorithm> #include <cmath> #include <iostream> #include <math.h> #include <string> using namespace std; int main() { int n, a[200005]; pair<int, int> p[200005]; cin >> n; int max1 = -1, max2 = -1, ind1, ind2; for (int i = 0; i < n; i++) { cin >> a[i]; p[i] = make_pair(a[i], i); } sort(p, p + n); max1 = p[n - 1].first; max2 = p[n - 2].first; ind1 = p[n - 1].second; ind2 = p[n - 2].second; for (int i = 0; i < n; i++) { if (a[i] == max1 && i == ind1) cout << max2 << endl; else cout << max1 << endl; } }
replace
8
10
8
10
0
p02971
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> int main(int argc, char *argv[]) { unsigned int N; std::cin >> N; std::vector<unsigned int> A(N); for (auto &a : A) { std::cin >> a; } unsigned int a; for (int i = 0; i < N; ++i) { a = A[i]; A.erase(A.begin() + i); std::cout << *std::max_element(A.begin(), A.end()) << std::endl; A.insert(A.begin() + i, a); } return 0; }
#include <algorithm> #include <iostream> #include <vector> int main(int argc, char *argv[]) { unsigned int N; std::cin >> N; std::vector<unsigned int> A(N); for (auto &a : A) { std::cin >> a; } auto globalMaxIter = std::max_element(A.begin(), A.end()); unsigned int globalMax = *globalMaxIter; A.erase(globalMaxIter); unsigned int secondMax = *std::max_element(A.begin(), A.end()); A.insert(globalMaxIter, globalMax); for (auto &a : A) { std::cout << (a == globalMax ? secondMax : globalMax) << std::endl; } return 0; }
replace
11
17
11
19
TLE
p02971
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using P = pair<string, int>; const double PI = acos(-1); int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a.at(i); rep(i, n) { vector<int> b = a; b.at(i) = -1; cout << *max_element(b.begin(), b.end()) << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using P = pair<string, int>; const double PI = acos(-1); int main() { int n; cin >> n; vector<int> b(n); rep(i, n) cin >> b.at(i); vector<int> a = b; sort(a.begin(), a.end()); if (a.at(n - 1) == a.at(n - 2)) { rep(i, n) cout << a.at(n - 1) << endl; } else { rep(i, n) { if (b.at(i) == a.at(n - 1)) cout << a.at(n - 2) << endl; else cout << a.at(n - 1) << endl; } } }
replace
10
17
10
23
TLE
p02971
C++
Time Limit Exceeded
#include <algorithm> #include <cinttypes> #include <cmath> #include <cstdint> #include <cstdio> #include <iomanip> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; static const long k10E7 = 1000000007; int main() { long n; cin >> n; vector<long> an(n); for (long &a : an) { cin >> a; } for (long i = 0; i < n; i++) { const long ai = an[i]; an[i] = 0; cout << *max_element(an.begin(), an.end()) << endl; an[i] = ai; } return 0; }
#include <algorithm> #include <cinttypes> #include <cmath> #include <cstdint> #include <cstdio> #include <iomanip> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; static const long k10E7 = 1000000007; int main() { long n; cin >> n; vector<long> an(n); for (long &a : an) { cin >> a; } auto first_max_it = max_element(an.begin(), an.end()); size_t first_max_index = distance(an.begin(), first_max_it); const long ai_tmp = an[first_max_index]; an[first_max_index] = 0; auto second_max_it = max_element(an.begin(), an.end()); size_t second_max_index = distance(an.begin(), second_max_it); an[first_max_index] = ai_tmp; for (size_t i = 0; i < (size_t)n; i++) { if (i == first_max_index) { cout << an[second_max_index] << endl; } else { cout << an[first_max_index] << endl; } } return 0; }
replace
23
28
23
38
TLE
p02971
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define INF 1000000007 #define LINF 1000000000000000007 typedef long long i64; typedef pair<i64, i64> P; int n, a[101010]; int main() { cin >> n; i64 ans = 0, ans2 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (ans < a[i]) { ans2 = ans; ans = a[i]; } else if (ans2 < a[i]) { ans2 = a[i]; } } for (int i = 0; i < n; i++) { if (a[i] == ans) { cout << ans2 << endl; } else cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define INF 1000000007 #define LINF 1000000000000000007 typedef long long i64; typedef pair<i64, i64> P; int n, a[202020]; int main() { cin >> n; i64 ans = 0, ans2 = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (ans < a[i]) { ans2 = ans; ans = a[i]; } else if (ans2 < a[i]) { ans2 = a[i]; } } for (int i = 0; i < n; i++) { if (a[i] == ans) { cout << ans2 << endl; } else cout << ans << endl; } return 0; }
replace
16
17
16
17
0
p02971
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <tuple> #include <vector> template <typename T> bool chmax(T &a, const T &b) { if (a <= b) { a = b; return (true); } else { return (false); } } template <typename T> bool chmin(T &a, const T &b) { if (a >= b) { a = b; return (true); } else { return (false); } } using namespace std; using ll = long long; using ull = unsigned long long; using Pint = pair<int, int>; using Pll = pair<ll, ll>; using Pull = pair<ull, ull>; #define eb emplace_back #define pb push_back #define mp make_pair #define mt make_tuple #define F first #define S second #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define reps(i, n) for (int i = 1; i <= (int)(n); ++i) #define rrep(i, n) for (int i = (int)((n)-1); i >= 0; --i) #define rreps(i, n) for (int i = (int)((n)); i > 0; --i) #define arep(i, v) for (auto &&i : (v)) template <typename T> T gcd(const T a, const T b) { return (b ? gcd(b, a % b) : a); } #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define UNIQUE(c) (c).erase(unique((c).begin(), (c).end()), (c).end()) constexpr ll MOD = 1000000007LL; #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define next asdnext #define prev asdprev template <typename T = ll> class UnionFind { public: UnionFind(T n) { rep(i, n) { par.resize(n); siz.resize(n); par[i] = i; siz[i] = 1; } } T find(T x) { if (x == par[x]) return (x); else return (par[x] = find(par[x])); } void unite(T x, T y) { T xx = find(x); T yy = find(y); if (xx == yy) return; if (siz[xx] <= siz[yy]) swap(xx, yy); par[yy] = xx; siz[xx] += siz[yy]; } private: vector<T> par, siz; }; template <typename T = ll> T power(T a, T b, T m = MOD) { T res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return (res); } /* constexpr ll MAX = 500010; ll fact[MAX]; ll inv[MAX]; ll inv_fact[MAX]; template<typename T> void initComb( T n, T m = MOD ) { fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1; inv[1] = 1; for ( int i = 2; i < n; i++ ) { fact[i] = ( fact[i - 1] * i ) % m; inv[i] = m - inv[m % i] * ( m / i ) % m; inv_fact[i] = inv_fact[i - 1] * inv[i] % m; } } template<typename T> T comb( T n, T r, T m = MOD ) { if ( n < r ) return ( 0 ); if ( n < 0 || r < 0 ) return ( 0 ); return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m ); } */ void replace(string &s, string t, string r) { string::size_type p = 0; while ((p = s.find(t, p)) != string::npos) { s.replace(p, t.length(), r); p += r.length(); } } int main() { ll N; cin >> N; vector<ll> v(N); rep(i, N) cin >> v[i]; vector<ll> vv(2 * N, 0); auto update = [&](ll i, ll x) { i += N - 1; vv[i] = x; while (i > 0) { i = (i - 1) / 2; vv[i] = max(vv[i * 2 + 1], vv[i * 2 + 2]); } }; rep(i, N) { update(N + i - 1, v[i]); } rep(i, N) { ll backup = v[i]; update(N + i - 1, 0); cout << vv[0] << endl; update(N + i - 1, backup); } return (0); }
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <tuple> #include <vector> template <typename T> bool chmax(T &a, const T &b) { if (a <= b) { a = b; return (true); } else { return (false); } } template <typename T> bool chmin(T &a, const T &b) { if (a >= b) { a = b; return (true); } else { return (false); } } using namespace std; using ll = long long; using ull = unsigned long long; using Pint = pair<int, int>; using Pll = pair<ll, ll>; using Pull = pair<ull, ull>; #define eb emplace_back #define pb push_back #define mp make_pair #define mt make_tuple #define F first #define S second #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define reps(i, n) for (int i = 1; i <= (int)(n); ++i) #define rrep(i, n) for (int i = (int)((n)-1); i >= 0; --i) #define rreps(i, n) for (int i = (int)((n)); i > 0; --i) #define arep(i, v) for (auto &&i : (v)) template <typename T> T gcd(const T a, const T b) { return (b ? gcd(b, a % b) : a); } #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define UNIQUE(c) (c).erase(unique((c).begin(), (c).end()), (c).end()) constexpr ll MOD = 1000000007LL; #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define next asdnext #define prev asdprev template <typename T = ll> class UnionFind { public: UnionFind(T n) { rep(i, n) { par.resize(n); siz.resize(n); par[i] = i; siz[i] = 1; } } T find(T x) { if (x == par[x]) return (x); else return (par[x] = find(par[x])); } void unite(T x, T y) { T xx = find(x); T yy = find(y); if (xx == yy) return; if (siz[xx] <= siz[yy]) swap(xx, yy); par[yy] = xx; siz[xx] += siz[yy]; } private: vector<T> par, siz; }; template <typename T = ll> T power(T a, T b, T m = MOD) { T res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return (res); } /* constexpr ll MAX = 500010; ll fact[MAX]; ll inv[MAX]; ll inv_fact[MAX]; template<typename T> void initComb( T n, T m = MOD ) { fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1; inv[1] = 1; for ( int i = 2; i < n; i++ ) { fact[i] = ( fact[i - 1] * i ) % m; inv[i] = m - inv[m % i] * ( m / i ) % m; inv_fact[i] = inv_fact[i - 1] * inv[i] % m; } } template<typename T> T comb( T n, T r, T m = MOD ) { if ( n < r ) return ( 0 ); if ( n < 0 || r < 0 ) return ( 0 ); return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m ); } */ void replace(string &s, string t, string r) { string::size_type p = 0; while ((p = s.find(t, p)) != string::npos) { s.replace(p, t.length(), r); p += r.length(); } } int main() { ll N; cin >> N; vector<ll> v(N); rep(i, N) cin >> v[i]; vector<ll> vv(4 * N, 0); auto update = [&](ll i, ll x) { i += N - 1; vv[i] = x; while (i > 0) { i = (i - 1) / 2; vv[i] = max(vv[i * 2 + 1], vv[i * 2 + 2]); } }; rep(i, N) { update(N + i - 1, v[i]); } rep(i, N) { ll backup = v[i]; update(N + i - 1, 0); cout << vv[0] << endl; update(N + i - 1, backup); } return (0); }
replace
151
152
151
152
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, i, ar[i]; cin >> n; int max = 0, smax = 0; for (i = 0; i < n; i++) { cin >> ar[i]; if (max < ar[i]) { smax = max; max = ar[i]; } else if (ar[i] >= smax) { smax = ar[i]; } } for (i = 0; i < n; i++) { if (ar[i] == max) { cout << smax << "\n"; } else { cout << max << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, i, ar[200005]; cin >> n; int max = 0, smax = 0; for (i = 0; i < n; i++) { cin >> ar[i]; if (max < ar[i]) { smax = max; max = ar[i]; } else if (ar[i] >= smax) { smax = ar[i]; } } for (i = 0; i < n; i++) { if (ar[i] == max) { cout << smax << "\n"; } else { cout << max << "\n"; } } return 0; }
replace
4
5
4
5
0
p02971
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int maxn = 1e5 + 10; int a[maxn], first = 0, second = 0; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] >= first) { second = first; first = a[i]; } else if (a[i] >= second) { second = a[i]; } } for (int i = 0; i < n; i++) { if (a[i] == first) cout << second << endl; else cout << first << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int maxn = 1e6 + 10; int a[maxn], first = 0, second = 0; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] >= first) { second = first; first = a[i]; } else if (a[i] >= second) { second = a[i]; } } for (int i = 0; i < n; i++) { if (a[i] == first) cout << second << endl; else cout << first << endl; } return 0; }
replace
5
6
5
6
0
p02971
C++
Runtime Error
// #include<bits/stdc++.h> #include <algorithm> #include <cstdio> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define Would #define you #define please const int cm = 1 << 17; char cn[cm], *ci = cn + cm; inline char getcha() { if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; } return *ci++; } inline int getint() { char C = getcha(); int A = C - '0'; while ((C = getcha()) >= '0') A = A * 10 + C - '0'; return A; } const int dm = 1 << 20; char dn[dm], *di = dn; inline void putint(int X) { int keta = 0; char C[10]; while (X) { *(C + keta) = '0' + X % 10; X /= 10; keta++; } for (int i = keta - 1; i >= 0; i--) *di++ = (*(C + i)); *di++ = '\n'; } int n; char c[6]; inline void putsaidai() { for (int i = n - 1; i >= 0; i--) *di++ = c[i]; *di++ = '\n'; } int main() { // cin.tie(0); // ios::sync_with_stdio(false); int N = getint(); int A[200000]; int saidai = 0; int niban = 0; rep(i, N) { A[i] = getint(); if (niban < A[i]) { niban = A[i]; if (niban > saidai) swap(niban, saidai); } } int kari = saidai; while (kari) { *(c + n) = '0' + kari % 10; kari /= 10; n++; } rep(i, N) { if (A[i] == saidai) putint(niban); else putsaidai(); } fwrite(dn, 1, di - dn, stdout); Would you please return 0; }
// #include<bits/stdc++.h> #include <algorithm> #include <cstdio> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define Would #define you #define please const int cm = 1 << 17; char cn[cm], *ci = cn + cm; inline char getcha() { if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; } return *ci++; } inline int getint() { char C = getcha(); int A = C - '0'; while ((C = getcha()) >= '0') A = A * 10 + C - '0'; return A; } const int dm = 1 << 21; char dn[dm], *di = dn; inline void putint(int X) { int keta = 0; char C[10]; while (X) { *(C + keta) = '0' + X % 10; X /= 10; keta++; } for (int i = keta - 1; i >= 0; i--) *di++ = (*(C + i)); *di++ = '\n'; } int n; char c[6]; inline void putsaidai() { for (int i = n - 1; i >= 0; i--) *di++ = c[i]; *di++ = '\n'; } int main() { // cin.tie(0); // ios::sync_with_stdio(false); int N = getint(); int A[200000]; int saidai = 0; int niban = 0; rep(i, N) { A[i] = getint(); if (niban < A[i]) { niban = A[i]; if (niban > saidai) swap(niban, saidai); } } int kari = saidai; while (kari) { *(c + n) = '0' + kari % 10; kari /= 10; n++; } rep(i, N) { if (A[i] == saidai) putint(niban); else putsaidai(); } fwrite(dn, 1, di - dn, stdout); Would you please return 0; }
replace
34
35
34
35
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> #include <unordered_map> #define lli long long int using namespace std; int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); // freopen("text.in", "r", stdin); // freopen("text.out", "w", stdout); int a[(int)1e5 + 1], n; cin >> n; int max = 0, place = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; if (a[i] > max) { max = a[i]; place = i; } } if (n == 1) return cout << a[0] << '\n', 0; for (int i = 0; i < n; ++i) { if (i != place) cout << max << " "; else { int temp = max; a[i] = 0; cout << *max_element(a + 0, a + n) << " "; a[i] = temp; } } cout << '\n'; return 0; }
#include <bits/stdc++.h> #include <unordered_map> #define lli long long int using namespace std; int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); // freopen("text.in", "r", stdin); // freopen("text.out", "w", stdout); int a[(int)2e5 + 1], n; cin >> n; int max = 0, place = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; if (a[i] > max) { max = a[i]; place = i; } } if (n == 1) return cout << a[0] << '\n', 0; for (int i = 0; i < n; ++i) { if (i != place) cout << max << " "; else { int temp = max; a[i] = 0; cout << *max_element(a + 0, a + n) << " "; a[i] = temp; } } cout << '\n'; return 0; }
replace
13
14
13
14
0
p02971
C++
Runtime Error
#include <cstdio> using namespace std; const int maxn = 100000; int N, A[maxn], mx1, mx2; int main() { scanf("%d", &N); for (int i = 0; i < N; i++) scanf("%d", &A[i]); for (int i = 0; i < N; i++) { if (A[i] > mx1) mx2 = mx1, mx1 = A[i]; else if (A[i] > mx2) mx2 = A[i]; } for (int i = 0; i < N; i++) if (A[i] == mx1) printf("%d\n", mx2); else printf("%d\n", mx1); }
#include <cstdio> using namespace std; const int maxn = 200000; int N, A[maxn], mx1, mx2; int main() { scanf("%d", &N); for (int i = 0; i < N; i++) scanf("%d", &A[i]); for (int i = 0; i < N; i++) { if (A[i] > mx1) mx2 = mx1, mx1 = A[i]; else if (A[i] > mx2) mx2 = A[i]; } for (int i = 0; i < N; i++) if (A[i] == mx1) printf("%d\n", mx2); else printf("%d\n", mx1); }
replace
2
3
2
3
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef vector<ll> vl; typedef long double ld; typedef vector<ld> vd; typedef bool bl; typedef vector<bl> vb; const ll e5 = 1 << 20; const ll mod = 998244353; const ll e3 = 1 << 13; const ll INF = 1ll << 60; int main() { int n; cin >> n; vector<int> a(n, 0); vector<int> a_num(n, 0); int max_a = 0; int max_a_ind = -1; int nex_max_a = 0; rep(i, n) { cin >> a[i]; a_num[a[i]] += 1; if (a[i] > max_a) { max_a = a[i]; max_a_ind = i; } else if (a[i] > nex_max_a) { nex_max_a = a[i]; } } rep(i, n) { if (max_a_ind != i || a_num[a[i]] > 1) { cout << max_a << endl; } else { cout << nex_max_a << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef vector<ll> vl; typedef long double ld; typedef vector<ld> vd; typedef bool bl; typedef vector<bl> vb; const ll e5 = 1 << 20; const ll mod = 998244353; const ll e3 = 1 << 13; const ll INF = 1ll << 60; int main() { int n; cin >> n; vector<int> a(n, 0); vector<int> a_num(200000, 0); int max_a = 0; int max_a_ind = -1; int nex_max_a = 0; rep(i, n) { cin >> a[i]; a_num[a[i]] += 1; if (a[i] > max_a) { max_a = a[i]; max_a_ind = i; } else if (a[i] > nex_max_a) { nex_max_a = a[i]; } } rep(i, n) { if (max_a_ind != i || a_num[a[i]] > 1) { cout << max_a << endl; } else { cout << nex_max_a << endl; } } return 0; }
replace
22
23
22
23
0
p02971
C++
Runtime Error
#include <stdio.h> int main() { int n; int a[100000]; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int no1; int no2; for (int i = 0; i < n; i++) { if (a[i] > no1) { no2 = no1; no1 = a[i]; } else if (a[i] > no2) { no2 = a[i]; } } for (int i = 0; i < n; i++) { if (a[i] != no1) { printf("%d\n", no1); } else { printf("%d\n", no2); } } return 0; }
#include <stdio.h> int main() { int n; int a[200000]; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int no1; int no2; for (int i = 0; i < n; i++) { if (a[i] > no1) { no2 = no1; no1 = a[i]; } else if (a[i] > no2) { no2 = a[i]; } } for (int i = 0; i < n; i++) { if (a[i] != no1) { printf("%d\n", no1); } else { printf("%d\n", no2); } } return 0; }
replace
4
5
4
5
0
p02971
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int main() { int N; cin >> N; vector<int> A(N); rep(i, N) cin >> A[i]; rep(i, N) { int tmp; tmp = A[i]; A[i] = 0; int m = *max_element(A.begin(), A.end()); cout << m << endl; A[i] = tmp; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int main() { int N; cin >> N; vector<int> A(N); rep(i, N) cin >> A[i]; auto iter1 = max_element(A.begin(), A.end()); int m1 = *iter1; A[iter1 - A.begin()] = 0; auto iter2 = max_element(A.begin(), A.end()); int m2 = *iter2; A[iter1 - A.begin()] = m1; rep(i, N) cout << ((A[i] != m1) ? m1 : m2) << endl; return 0; }
replace
11
19
11
19
TLE
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); vector<int> B(N); for (int i = 0; i < N; i++) B.at(i) = A.at(i); sort(B.begin(), B.end()); reverse(B.begin(), B.end()); int Max = B.at(0); int Max1 = B.at(1); for (int i = 0; i < N - 1; i++) { if (A.at(i) != Max) cout << Max << " "; else cout << Max1 << " "; } if (A.at(N - 1) != Max) cout << Max << endl; else cout << Max1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); vector<int> B(N); for (int i = 0; i < N; i++) B.at(i) = A.at(i); sort(B.begin(), B.end()); reverse(B.begin(), B.end()); int Max = B.at(0); int Max1 = B.at(1); for (int i = 0; i < N - 1; i++) { if (A.at(i) != Max) cout << Max << " "; else cout << Max1 << " "; } if (A.at(N - 1) != Max) cout << Max << endl; else cout << Max1 << endl; return 0; }
insert
4
4
4
5
0
p02971
C++
Time Limit Exceeded
// </> : towhid1zaman #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<pii, int> ppi; #define fill(a, b) memset(a, b, sizeof(a)) #define all(v) (v).begin(), (v).end() #define sp(k) cout << setprecision(k) << fixed; #define rep(i, a) for (int i = 0; i < a; i++) #define rep1(i, a, b) for (int i = (a); i <= (b); ++i) #define irep(i, b, a) for (int i = (b); i >= (a); --i) #define minv(v) *min_element(all(v)) #define maxv(v) *max_element(all(v)) #define unq(v) sort(all(v)), (v).erase(unique(all(v)), (v).end()) #define _ \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define sqr(a) ((a) * (a)) #define sz(a) int(a.size()) #define ff first #define ss second #define pb push_back const double pi = acos(-1.0); const int mod = 1000000007; // (int)1e9+7 const int inf = 0x3f3f3f3f; // (int)3e18; const int maxn = 2000100; int main() { _ int n; cin >> n; vi a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(all(b)); for (int i = 0; i < n; i++) { int mx = *max_element(b.begin(), b.end()); if (mx == a[i]) { cout << b[n - 2] << endl; } else cout << mx << endl; } return 0; }
// </> : towhid1zaman #include "bits/stdc++.h" using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<pii, int> ppi; #define fill(a, b) memset(a, b, sizeof(a)) #define all(v) (v).begin(), (v).end() #define sp(k) cout << setprecision(k) << fixed; #define rep(i, a) for (int i = 0; i < a; i++) #define rep1(i, a, b) for (int i = (a); i <= (b); ++i) #define irep(i, b, a) for (int i = (b); i >= (a); --i) #define minv(v) *min_element(all(v)) #define maxv(v) *max_element(all(v)) #define unq(v) sort(all(v)), (v).erase(unique(all(v)), (v).end()) #define _ \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define sqr(a) ((a) * (a)) #define sz(a) int(a.size()) #define ff first #define ss second #define pb push_back const double pi = acos(-1.0); const int mod = 1000000007; // (int)1e9+7 const int inf = 0x3f3f3f3f; // (int)3e18; const int maxn = 2000100; int main() { _ int n; cin >> n; vi a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(all(b)); for (int i = 0; i < n; i++) { int mx = b[n - 1]; if (mx == a[i]) { cout << b[n - 2] << endl; } else cout << mx << endl; } return 0; }
replace
45
46
45
46
TLE
p02971
C++
Runtime Error
// #pragma GCC optimize("Ofast") #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #define endl '\n' #define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define zy 2333333 #define bql 2147483647 using namespace std; int n; struct node { int num, id, max; } a[100005]; bool cmp(node x, node y) { return x.num < y.num; } bool cmpp(node x, node y) { return x.id < y.id; } int main() { fast; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].num, a[i].id = i; sort(a + 1, a + n + 1, cmp); for (int i = 1; i <= n; i++) if (a[i].num != a[n].num) a[i].max = a[n].num; else a[i].max = a[n - 1].num; sort(a + 1, a + n + 1, cmpp); for (int i = 1; i <= n; i++) cout << a[i].max << endl; return 0; }
// #pragma GCC optimize("Ofast") #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #define endl '\n' #define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define zy 2333333 #define bql 2147483647 using namespace std; int n; struct node { int num, id, max; } a[200005]; bool cmp(node x, node y) { return x.num < y.num; } bool cmpp(node x, node y) { return x.id < y.id; } int main() { fast; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].num, a[i].id = i; sort(a + 1, a + n + 1, cmp); for (int i = 1; i <= n; i++) if (a[i].num != a[n].num) a[i].max = a[n].num; else a[i].max = a[n - 1].num; sort(a + 1, a + n + 1, cmpp); for (int i = 1; i <= n; i++) cout << a[i].max << endl; return 0; }
replace
19
20
19
20
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define REPR(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define valid(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w) #define tpl(...) make_tuple(__VA_ARGS__) const int INF = 0x3f3f3f3f; const double EPS = 1e-8; const double PI = acos(-1); const int dy[] = {-1, 0, 1, 0}; const int dx[] = {0, 1, 0, -1}; typedef long long ll; typedef pair<int, int> pii; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename Ch, typename Tr, typename C, typename = decltype(begin(C()))> basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, const C &c) { os << '['; for (auto i = begin(c); i != end(c); ++i) os << (i == begin(c) ? "" : " ") << *i; return os << ']'; } template <class S, class T> ostream &operator<<(ostream &o, const pair<S, T> &t) { return o << '(' << t.first << ',' << t.second << ')'; } template <int N, class Tp> void output(ostream &, const Tp &) {} template <int N, class Tp, class, class... Ts> void output(ostream &o, const Tp &t) { if (N) o << ','; o << get<N>(t); output<N + 1, Tp, Ts...>(o, t); } template <class... Ts> ostream &operator<<(ostream &o, const tuple<Ts...> &t) { o << '('; output<0, tuple<Ts...>, Ts...>(o, t); return o << ')'; } template <class T> void output(T t, char z = 10) { if (t < 0) t = -t, putchar(45); int c[20]; int k = 0; while (t) c[k++] = t % 10, t /= 10; for (k || (c[k++] = 0); k;) putchar(c[--k] ^ 48); putchar(z); } template <class T> void outputs(T t) { output(t); } template <class S, class... T> void outputs(S a, T... t) { output(a, 32); outputs(t...); } template <class T> void output(T *a, int n) { REP(i, n) cout << a[i] << (i != n - 1 ? ',' : '\n'); } template <class T> void output(T *a, int n, int m) { REP(i, n) output(a[i], m); } template <class T> bool input(T &t) { int n = 1, c; for (t = 0; !isdigit(c = getchar()) && ~c && c - 45;) ; if (!~c) return 0; for (c - 45 && (n = 0, t = c ^ 48); isdigit(c = getchar());) t = 10 * t + c - 48; t = n ? -t : t; return 1; } template <class S, class... T> bool input(S &a, T &...t) { input(a); return input(t...); } template <class T> bool inputs(T *a, int n) { REP(i, n) if (!input(a[i])) return 0; return 1; } int a[20000]; int main() { int n; while (cin >> n) { inputs(a, n); vector<int> v(a, a + n); sort(ALL(v)); int mx1 = v[n - 1]; int mx2 = v[n - 2]; REP(i, n) { int ans = (a[i] == mx1) ? mx2 : mx1; printf("%d\n", ans); } } }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define REPR(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define valid(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w) #define tpl(...) make_tuple(__VA_ARGS__) const int INF = 0x3f3f3f3f; const double EPS = 1e-8; const double PI = acos(-1); const int dy[] = {-1, 0, 1, 0}; const int dx[] = {0, 1, 0, -1}; typedef long long ll; typedef pair<int, int> pii; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename Ch, typename Tr, typename C, typename = decltype(begin(C()))> basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, const C &c) { os << '['; for (auto i = begin(c); i != end(c); ++i) os << (i == begin(c) ? "" : " ") << *i; return os << ']'; } template <class S, class T> ostream &operator<<(ostream &o, const pair<S, T> &t) { return o << '(' << t.first << ',' << t.second << ')'; } template <int N, class Tp> void output(ostream &, const Tp &) {} template <int N, class Tp, class, class... Ts> void output(ostream &o, const Tp &t) { if (N) o << ','; o << get<N>(t); output<N + 1, Tp, Ts...>(o, t); } template <class... Ts> ostream &operator<<(ostream &o, const tuple<Ts...> &t) { o << '('; output<0, tuple<Ts...>, Ts...>(o, t); return o << ')'; } template <class T> void output(T t, char z = 10) { if (t < 0) t = -t, putchar(45); int c[20]; int k = 0; while (t) c[k++] = t % 10, t /= 10; for (k || (c[k++] = 0); k;) putchar(c[--k] ^ 48); putchar(z); } template <class T> void outputs(T t) { output(t); } template <class S, class... T> void outputs(S a, T... t) { output(a, 32); outputs(t...); } template <class T> void output(T *a, int n) { REP(i, n) cout << a[i] << (i != n - 1 ? ',' : '\n'); } template <class T> void output(T *a, int n, int m) { REP(i, n) output(a[i], m); } template <class T> bool input(T &t) { int n = 1, c; for (t = 0; !isdigit(c = getchar()) && ~c && c - 45;) ; if (!~c) return 0; for (c - 45 && (n = 0, t = c ^ 48); isdigit(c = getchar());) t = 10 * t + c - 48; t = n ? -t : t; return 1; } template <class S, class... T> bool input(S &a, T &...t) { input(a); return input(t...); } template <class T> bool inputs(T *a, int n) { REP(i, n) if (!input(a[i])) return 0; return 1; } int a[200000]; int main() { int n; while (cin >> n) { inputs(a, n); vector<int> v(a, a + n); sort(ALL(v)); int mx1 = v[n - 1]; int mx2 = v[n - 2]; REP(i, n) { int ans = (a[i] == mx1) ? mx2 : mx1; printf("%d\n", ans); } } }
replace
96
97
96
97
0
p02971
C++
Runtime Error
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> #define int long long #define endl '\n' #define null nullptr #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define mp make_pair #define test \ int t; \ cin >> t; \ while (t--) #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) using namespace std; typedef vector<int> vi; typedef vector<pair<int, int>> vii; typedef pair<int, int> pii; typedef unordered_map<int, int> mp; const int mod = 1e9 + 7; const int least = -1e9; const int most = 1e9; int32_t main() { FAST; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; vi a(n + 2, least); for (int x = 1; x <= n; x++) cin >> a[x]; vi pref = a, suff = a; for (int x = 1; x <= n; x++) pref[x] = max(pref[x], pref[x - 1]); for (int x = n - 1; x > 0; x--) suff[x] = max(suff[x], suff[x + 1]); for (int x = 1; x <= n; x++) { cout << max(pref[x - 1], suff[x + 1]) << " "; } return 0; }
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> #define int long long #define endl '\n' #define null nullptr #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define mp make_pair #define test \ int t; \ cin >> t; \ while (t--) #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) using namespace std; typedef vector<int> vi; typedef vector<pair<int, int>> vii; typedef pair<int, int> pii; typedef unordered_map<int, int> mp; const int mod = 1e9 + 7; const int least = -1e9; const int most = 1e9; int32_t main() { FAST; int n; cin >> n; vi a(n + 2, least); for (int x = 1; x <= n; x++) cin >> a[x]; vi pref = a, suff = a; for (int x = 1; x <= n; x++) pref[x] = max(pref[x], pref[x - 1]); for (int x = n - 1; x > 0; x--) suff[x] = max(suff[x], suff[x + 1]); for (int x = 1; x <= n; x++) { cout << max(pref[x - 1], suff[x + 1]) << " "; } return 0; }
delete
34
39
34
34
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02971
C++
Runtime Error
#include <bits/stdc++.h> #define nmax 100005 using namespace std; int main() { int a[nmax] = {}, n, max1 = -1, max2 = -1, x; cin >> n; for (int i = 1; i <= n; i++) { cin >> x; a[i] = x; if (x > max1) { max2 = max1; max1 = x; } else { if (max1 == x) { max2 = x; } else { if (x > max2) { max2 = x; } } } } for (int i = 1; i <= n; i++) { if (a[i] != max1) { cout << max1 << endl; } else { cout << max2 << endl; } } return 0; }
#include <bits/stdc++.h> #define nmax 200005 using namespace std; int main() { int a[nmax] = {}, n, max1 = -1, max2 = -1, x; cin >> n; for (int i = 1; i <= n; i++) { cin >> x; a[i] = x; if (x > max1) { max2 = max1; max1 = x; } else { if (max1 == x) { max2 = x; } else { if (x > max2) { max2 = x; } } } } for (int i = 1; i <= n; i++) { if (a[i] != max1) { cout << max1 << endl; } else { cout << max2 << endl; } } return 0; }
replace
1
2
1
2
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define ll long long #define f first #define s second #define ld long double #define fa fflush(stdout); using namespace std; void data() { #ifdef NURS freopen("main.in", "r", stdin); freopen("main.out", "w", stdout); #endif } const int N = 5e5 + 100; const ll mod = 1e9 + 7; int main() { data(); int n; cin >> n; int a[n + 1]; int mx = 0; int kol = 0; set<int> s; for (int i = 1; i <= n; i++) { cin >> a[i]; mx = max(mx, a[i]); s.insert(a[i]); } s.erase(*s.rbegin()); int ans2 = *s.rbegin(); for (int i = 1; i <= n; i++) { if (mx == a[i]) { kol++; } } for (int i = 1; i <= n; i++) { if (a[i] != mx) { cout << mx << '\n'; continue; } if (kol > 1) { cout << mx << '\n'; continue; } cout << ans2 << '\n'; } } // JUDGE_ID: 295965SY // Tis I
#include <bits/stdc++.h> #define pb push_back #define ll long long #define f first #define s second #define ld long double #define fa fflush(stdout); using namespace std; void data() { #ifdef NURS freopen("main.in", "r", stdin); freopen("main.out", "w", stdout); #endif } const int N = 5e5 + 100; const ll mod = 1e9 + 7; int main() { data(); int n; cin >> n; int a[n + 1]; int mx = 0; int kol = 0; set<int> s; for (int i = 1; i <= n; i++) { cin >> a[i]; mx = max(mx, a[i]); s.insert(a[i]); } s.erase(*s.rbegin()); int ans2; if (s.size() > 0) { ans2 = *s.rbegin(); } for (int i = 1; i <= n; i++) { if (mx == a[i]) { kol++; } } for (int i = 1; i <= n; i++) { if (a[i] != mx) { cout << mx << '\n'; continue; } if (kol > 1) { cout << mx << '\n'; continue; } cout << ans2 << '\n'; } } // JUDGE_ID: 295965SY // Tis I
replace
33
34
33
37
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; #define CIN ios_base::sync_with_stdio(0) #define mx 100007 #define i64 long long i64 arr[mx], tree[3 * mx], lazy[3 * mx]; void BuildTree(i64 node, i64 b, i64 e) { if (b == e) { tree[node] = arr[b]; return; } i64 mid = (b + e) / 2; i64 left = 2 * node, right = 2 * node + 1; BuildTree(left, b, mid); BuildTree(right, mid + 1, e); tree[node] = max(tree[left], tree[right]); } i64 query(i64 node, i64 b, i64 e, i64 l, i64 r) { if (b > r || b > e || e < l) { return INT_MIN; // return 0 as sum; } if (lazy[node] != 0) { tree[node] += (e - b + 1) * lazy[node]; if (b != e) { lazy[node * 2] += lazy[node]; lazy[node * 2 + 1] += lazy[node]; } lazy[node] = 0; } if (b >= l && e <= r) { return tree[node]; } i64 mid = (b + e) / 2, left = node * 2, right = node * 2 + 1; i64 lft = query(left, b, mid, l, r); i64 rgt = query(right, mid + 1, e, l, r); return max(lft, rgt); } void updateRange(i64 node, i64 b, i64 e, i64 l, i64 r, i64 value) { if (lazy[node] != 0) { tree[node] += (e - b + 1) * lazy[node]; if (b != e) { lazy[node * 2] += lazy[node]; lazy[node * 2 + 1] += lazy[node]; } lazy[node] = 0; } if (b > e || b > r || e < l) { // start > end or start > r or end < l ....out of range return; } if (b >= l && e <= r) { // fully cover range [l....r] tree[node] += (e - b + 1) * value; if (b != e) { // not a leaf lazy[node * 2] += value; lazy[node * 2 + 1] += value; } return; // why ? dud } i64 mid = (b + e) / 2, left = node * 2, right = node * 2 + 1; updateRange(left, b, mid, l, r, value); updateRange(right, mid + 1, e, l, r, value); tree[node] = max(tree[left], tree[right]); } int main() { CIN; i64 t, qu, q, p, a; i64 val; int n; cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; BuildTree(1, 1, n); memset(lazy, 0, sizeof lazy); for (int i = 1; i <= n; i++) { int idx = i; updateRange(1, 1, n, idx, idx, -arr[idx]); i64 left = query(1, 1, n, 1, idx - 1); i64 right = query(1, 1, n, idx + 1, n); i64 ans = max(left, right); cout << ans << endl; updateRange(1, 1, n, idx, idx, arr[idx]); } return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define CIN ios_base::sync_with_stdio(0) #define mx 200007 #define i64 long long i64 arr[mx], tree[3 * mx], lazy[3 * mx]; void BuildTree(i64 node, i64 b, i64 e) { if (b == e) { tree[node] = arr[b]; return; } i64 mid = (b + e) / 2; i64 left = 2 * node, right = 2 * node + 1; BuildTree(left, b, mid); BuildTree(right, mid + 1, e); tree[node] = max(tree[left], tree[right]); } i64 query(i64 node, i64 b, i64 e, i64 l, i64 r) { if (b > r || b > e || e < l) { return INT_MIN; // return 0 as sum; } if (lazy[node] != 0) { tree[node] += (e - b + 1) * lazy[node]; if (b != e) { lazy[node * 2] += lazy[node]; lazy[node * 2 + 1] += lazy[node]; } lazy[node] = 0; } if (b >= l && e <= r) { return tree[node]; } i64 mid = (b + e) / 2, left = node * 2, right = node * 2 + 1; i64 lft = query(left, b, mid, l, r); i64 rgt = query(right, mid + 1, e, l, r); return max(lft, rgt); } void updateRange(i64 node, i64 b, i64 e, i64 l, i64 r, i64 value) { if (lazy[node] != 0) { tree[node] += (e - b + 1) * lazy[node]; if (b != e) { lazy[node * 2] += lazy[node]; lazy[node * 2 + 1] += lazy[node]; } lazy[node] = 0; } if (b > e || b > r || e < l) { // start > end or start > r or end < l ....out of range return; } if (b >= l && e <= r) { // fully cover range [l....r] tree[node] += (e - b + 1) * value; if (b != e) { // not a leaf lazy[node * 2] += value; lazy[node * 2 + 1] += value; } return; // why ? dud } i64 mid = (b + e) / 2, left = node * 2, right = node * 2 + 1; updateRange(left, b, mid, l, r, value); updateRange(right, mid + 1, e, l, r, value); tree[node] = max(tree[left], tree[right]); } int main() { CIN; i64 t, qu, q, p, a; i64 val; int n; cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; BuildTree(1, 1, n); memset(lazy, 0, sizeof lazy); for (int i = 1; i <= n; i++) { int idx = i; updateRange(1, 1, n, idx, idx, -arr[idx]); i64 left = query(1, 1, n, 1, idx - 1); i64 right = query(1, 1, n, idx + 1, n); i64 ans = max(left, right); cout << ans << endl; updateRange(1, 1, n, idx, idx, arr[idx]); } return 0; }
replace
5
6
5
6
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; signed main() { int a, d; int b[100000], c[100000]; ; cin.tie(NULL); ios::sync_with_stdio(false); cin >> a; for (int i = 0; i < a; i++) { cin >> b[i]; c[i] = b[i]; } sort(b, b + a, greater<int>()); for (int i = 0; i < a; i++) { d = 0; if (b[0] != c[i]) { cout << b[0] << "\n"; d = 1; } if (b[0] == c[i] && d == 0 || b[0] == c[i]) { cout << b[1] << "\n"; } } return (0); }
#include <bits/stdc++.h> using namespace std; signed main() { int a, d; int b[1000000], c[1000000]; cin.tie(NULL); ios::sync_with_stdio(false); cin >> a; for (int i = 0; i < a; i++) { cin >> b[i]; c[i] = b[i]; } sort(b, b + a, greater<int>()); for (int i = 0; i < a; i++) { d = 0; if (b[0] != c[i]) { cout << b[0] << "\n"; d = 1; } if (b[0] == c[i] && d == 0 || b[0] == c[i]) { cout << b[1] << "\n"; } } return (0); }
replace
4
6
4
5
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, o, n) for (long long i = o; i < n; i++) #define oneforall \ ios::sync_with_stdio(false); \ cin.tie(0); #define all(v) (v).begin(), (v).end() #define ini(...) \ int __VA_ARGS__; \ in(__VA_ARGS__) #define inl(...) \ long long __VA_ARGS__; \ in(__VA_ARGS__) #define ins(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) const long long INF = 1e18; void in() {} template <typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template <typename T, class... U> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << " "; out(u...); } typedef vector<int> vi; typedef vector<long long> vl; typedef long long ll; typedef vector<pair<long, long>> vpll; typedef vector<pair<int, int>> vpii; int main() { oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall ini( n); int a[10000]; int tmp1 = 0; int tmp_ = 0; FOR(i, 0, n) { in(a[i]); } auto x_ = max_element(a, a + n); int pos = x_ - a; int tmp = a[pos]; a[pos] = 0; auto x = max_element(a, a + n); a[pos] = tmp; FOR(i, 0, n) { if (a[i] == *x_) { out(*x); } else { out(*x_); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, o, n) for (long long i = o; i < n; i++) #define oneforall \ ios::sync_with_stdio(false); \ cin.tie(0); #define all(v) (v).begin(), (v).end() #define ini(...) \ int __VA_ARGS__; \ in(__VA_ARGS__) #define inl(...) \ long long __VA_ARGS__; \ in(__VA_ARGS__) #define ins(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) const long long INF = 1e18; void in() {} template <typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template <typename T, class... U> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << " "; out(u...); } typedef vector<int> vi; typedef vector<long long> vl; typedef long long ll; typedef vector<pair<long, long>> vpll; typedef vector<pair<int, int>> vpii; int main() { oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall ini( n); int a[10000010]; int tmp1 = 0; int tmp_ = 0; FOR(i, 0, n) { in(a[i]); } auto x_ = max_element(a, a + n); int pos = x_ - a; int tmp = a[pos]; a[pos] = 0; auto x = max_element(a, a + n); a[pos] = tmp; FOR(i, 0, n) { if (a[i] == *x_) { out(*x); } else { out(*x_); } } return 0; }
replace
38
39
38
39
0
p02971
C++
Runtime Error
#include "bits/stdc++.h" #define FOR(i, a, b) for (int i = a; i < b; i++) #define mFOR(i, a, b) for (int i = a; i > b; i--) #define MP make_pair #define PB push_back #define ALL(v) v.begin(), v.end() #define N 100007 #define INF 1000000007 using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); } int main() { int n, a[N] = {}, mx1 = 0, mx2 = 0, ctr1 = 0, ctr2 = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (mx1 < a[i]) { mx2 = mx1; ctr2 = ctr1; mx1 = a[i]; ctr1 = 1; } else if (mx1 == a[i]) { ctr1++; } else if (mx2 < a[i]) { mx2 = a[i]; ctr2 = 1; } else if (mx2 == a[i]) { ctr2++; } } for (int i = 0; i < n; i++) { if (a[i] != mx1 || ctr1 > 1) cout << mx1 << endl; else cout << mx2 << endl; } return 0; }
#include "bits/stdc++.h" #define FOR(i, a, b) for (int i = a; i < b; i++) #define mFOR(i, a, b) for (int i = a; i > b; i--) #define MP make_pair #define PB push_back #define ALL(v) v.begin(), v.end() #define N 200007 #define INF 1000000007 using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); } int main() { int n, a[N] = {}, mx1 = 0, mx2 = 0, ctr1 = 0, ctr2 = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (mx1 < a[i]) { mx2 = mx1; ctr2 = ctr1; mx1 = a[i]; ctr1 = 1; } else if (mx1 == a[i]) { ctr1++; } else if (mx2 < a[i]) { mx2 = a[i]; ctr2 = 1; } else if (mx2 == a[i]) { ctr2++; } } for (int i = 0; i < n; i++) { if (a[i] != mx1 || ctr1 > 1) cout << mx1 << endl; else cout << mx2 << endl; } return 0; }
replace
6
7
6
7
0
p02971
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define pb push_back #define mk make_pair #define eb emplace_back #define eps 1e-8 #define fi first #define se second #define all(x) (x).begin(), (x).end() #define int long long using namespace std; typedef long double ld; typedef unsigned int ui; typedef pair<int, int> pii; typedef tuple<int, int, int> tiii; typedef unsigned long long ull; typedef vector<int> vii; typedef vector<long double> vd; const int inf = 1e9; const int INF = 1e18; const int M = 1e9 + 7; //__int128 const int maxn = 3e5; int a[maxn], b[maxn]; signed main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); for (int i = 0; i < n; ++i) { if (a[i] == b[n - 1]) { cout << b[n - 2] << endl; } else { cout << b[n - 1] << endl; } } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define pb push_back #define mk make_pair #define eb emplace_back #define eps 1e-8 #define fi first #define se second #define all(x) (x).begin(), (x).end() #define int long long using namespace std; typedef long double ld; typedef unsigned int ui; typedef pair<int, int> pii; typedef tuple<int, int, int> tiii; typedef unsigned long long ull; typedef vector<int> vii; typedef vector<long double> vd; const int inf = 1e9; const int INF = 1e18; const int M = 1e9 + 7; //__int128 const int maxn = 3e5; int a[maxn], b[maxn]; signed main() { #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); for (int i = 0; i < n; ++i) { if (a[i] == b[n - 1]) { cout << b[n - 2] << endl; } else { cout << b[n - 1] << endl; } } return 0; }
replace
37
39
37
39
-11
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; multiset<int> s; vector<int> v(n); int m = n; for (auto &i : v) { cin >> i; s.insert(i); } for (auto i : v) { s.erase(i); cout << *s.rbegin() << "\n"; s.insert(i); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; multiset<int> s; vector<int> v(n); int m = n; for (auto &i : v) { cin >> i; s.insert(i); } for (auto i : v) { s.erase(s.find(i)); cout << *s.rbegin() << "\n"; s.insert(i); } return 0; }
replace
14
15
14
15
0
p02971
C++
Runtime Error
// Exception Handling - atcoder.cpp : This file contains the 'main' function. // Program execution begins and ends there. // #include <algorithm> #include <iostream> using namespace std; const int N = 1e5; int arr[N], tempp[N], n; int main() { cin >> n; int prevMax = 0, curMax = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; tempp[i] = arr[i]; } sort(tempp, tempp + n); prevMax = tempp[n - 2]; curMax = tempp[n - 1]; for (int i = 0; i < n; i++) { if (arr[i] == curMax) cout << prevMax << endl; else cout << curMax << endl; } }
// Exception Handling - atcoder.cpp : This file contains the 'main' function. // Program execution begins and ends there. // #include <algorithm> #include <iostream> using namespace std; const int N = 2e5 + 6; int arr[N], tempp[N], n; int main() { cin >> n; int prevMax = 0, curMax = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; tempp[i] = arr[i]; } sort(tempp, tempp + n); prevMax = tempp[n - 2]; curMax = tempp[n - 1]; for (int i = 0; i < n; i++) { if (arr[i] == curMax) cout << prevMax << endl; else cout << curMax << endl; } }
replace
8
9
8
9
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; long a[110000]; int z = 0, in; for (int i = 0; i < N; i++) { cin >> a[i]; if (z < a[i]) { in = i; z = a[i]; } } sort(a, a + N); if (a[N - 1] == a[N - 2]) { for (int i = 0; i < N; i++) { cout << a[N - 1] << endl; } } else { for (int i = 0; i < in; i++) { cout << a[N - 1] << endl; } cout << a[N - 2] << endl; for (int i = in + 1; i < N; i++) { cout << a[N - 1] << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; long a[210000]; int z = 0, in; for (int i = 0; i < N; i++) { cin >> a[i]; if (z < a[i]) { in = i; z = a[i]; } } sort(a, a + N); if (a[N - 1] == a[N - 2]) { for (int i = 0; i < N; i++) { cout << a[N - 1] << endl; } } else { for (int i = 0; i < in; i++) { cout << a[N - 1] << endl; } cout << a[N - 2] << endl; for (int i = in + 1; i < N; i++) { cout << a[N - 1] << endl; } } }
replace
9
10
9
10
0
p02971
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define sz(x) ((int)(x).size()) #define fi first #define sec second #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++) #define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++) #define EQ(a, b) (abs((a) - (b)) < eps) template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } int main() { int N; cin >> N; vi a(N); set<int> s; for (int i = 0; i < N; i++) { cin >> a[i]; s.insert(a[i]); } for (int i = 0; i < N; i++) { auto it = s.find(a[i]); s.erase(it); cout << *s.rbegin() << endl; s.insert(a[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define sz(x) ((int)(x).size()) #define fi first #define sec second #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++) #define repn(i, a, n) for (int(i) = (a); (i) < (int)(n); (i)++) #define EQ(a, b) (abs((a) - (b)) < eps) template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } int main() { int N; cin >> N; vi a(N); multiset<int> s; for (int i = 0; i < N; i++) { cin >> a[i]; s.insert(a[i]); } for (int i = 0; i < N; i++) { auto it = s.find(a[i]); s.erase(it); cout << *s.rbegin() << endl; s.insert(a[i]); } return 0; }
replace
29
30
29
30
0
p02971
Python
Time Limit Exceeded
n = int(input()) semi_max = 0 aa = [] for i in range(n): a = int(input()) if i > 0: if a >= semi_max and a < max(aa): semi_max = a elif a == max(aa): semi_max = max(aa) aa.append(a) # print(semi_max) for each in aa: print(max(aa) if each <= semi_max else semi_max)
n = int(input()) aa = [int(input()) for _ in range(n)] aho = sorted(aa) for a in aa: print(aho[-1] if a < aho[-1] else aho[-2])
replace
1
14
1
5
TLE
p02971
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); using namespace std; #define mod 1e9 int a[100005], b[100005]; int32_t main() { int n; cin >> n; int i; for (i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(a, a + n); for (i = 0; i < n; i++) { if (a[n - 1] == b[i]) cout << a[n - 2] << "\n"; else cout << a[n - 1] << "\n"; } }
#include <bits/stdc++.h> #define int long long #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); using namespace std; #define mod 1e9 int a[200005], b[200005]; int32_t main() { int n; cin >> n; int i; for (i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(a, a + n); for (i = 0; i < n; i++) { if (a[n - 1] == b[i]) cout << a[n - 2] << "\n"; else cout << a[n - 1] << "\n"; } }
replace
8
9
8
9
0