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
p02950
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdexcept> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; #include <algorithm> #include <vector> namespace ProconLib { namespace DetailNS { template <typename T> struct DefaultDetail { static bool isZero(T x) { return x <= T(0); } }; } // namespace DetailNS template <typename T> class Polynomial { int N; std::vector<T> dat; public: Polynomial(int N) : N(N), dat(N + 1) {} Polynomial() : Polynomial(0) {} Polynomial(const Polynomial &obj) : N(N), dat(dat) {} // Polynomial(const Polynomial&& obj):N(N),dat(std::move(dat)){} int degree() { return N; } void resize(int N) { this->N = N; dat.resize(N + 1, T(0)); } template <typename Detail = DetailNS::DefaultDetail<T>> void shrink(); T &operator[](int pos) { return dat[pos]; } const T &operator[](int pos) const { return dat[pos]; } T operator()(T x); }; template <typename T> Polynomial<T> &operator+=(Polynomial<T> &lhs, Polynomial<T> rhs); template <typename T> Polynomial<T> &operator-=(Polynomial<T> &lhs, Polynomial<T> rhs); template <typename T> Polynomial<T> &operator*=(Polynomial<T> &lhs, Polynomial<T> rhs); template <typename T> Polynomial<T> operator+(Polynomial<T> lhs, Polynomial<T> rhs) { return lhs += rhs; } template <typename T> Polynomial<T> operator-(Polynomial<T> lhs, Polynomial<T> rhs) { return lhs -= rhs; } template <typename T> Polynomial<T> operator*(Polynomial<T> lhs, Polynomial<T> rhs) { return lhs *= rhs; } template <typename T> template <typename Detail> void Polynomial<T>::shrink() { while (N) { if (Detail::isZero(dat[N])) N--; else break; } resize(N); } template <typename T> Polynomial<T> &operator+=(Polynomial<T> &lhs, Polynomial<T> rhs) { lhs.resize(std::max(lhs.degree(), rhs.degree())); for (int i = 0; i <= rhs.degree(); i++) lhs[i] += rhs[i]; return lhs; } template <typename T> Polynomial<T> &operator-=(Polynomial<T> &lhs, Polynomial<T> rhs) { lhs.resize(std::max(lhs.degree(), rhs.degree())); for (int i = 0; i <= rhs.degree(); i++) lhs[i] -= rhs[i]; return lhs; } template <typename T> Polynomial<T> &operator*=(Polynomial<T> &lhs, Polynomial<T> rhs) { Polynomial<T> lhsTmp = lhs; lhs.resize(lhs.degree() + rhs.degree()); for (int i = 0; i <= lhsTmp.degree(); i++) lhs[i] = T(0); for (int i = 0; i <= lhsTmp.degree(); i++) { for (int j = 0; j <= rhs.degree(); j++) { lhs[i + j] += lhsTmp[i] * rhs[j]; } } return lhs; } template <typename T> Polynomial<T> operator+(Polynomial<T> poly) { auto res = poly; return res; } template <typename T> Polynomial<T> operator-(Polynomial<T> poly) { auto res = poly; for (int i = 0; i <= poly.degree(); i++) res[i] = -res[i]; return res; } template <typename T> T Polynomial<T>::operator()(T x) { T res = T(0); T px = T(1); for (int i = 0; i <= degree(); i++) { res += dat[i] * px; px *= x; } return res; } } // namespace ProconLib using namespace ProconLib; int powm(int x, int k, int p) { int res = 1; while (k) { if (k & 1) res = res * x % p; k >>= 1; x = x * x % p; } return res; } int inv(int x, int p) { return powm(x, p - 2, p); } using P = Polynomial<int>; int main() { int p; cin >> p; vector<int> a(p); for (int i = 0; i < p; i++) cin >> a[i]; vector<vector<P>> dp(2, vector<P>(p + 1)); dp[0][0][0] = 1; for (int i = 0; i < p; i++) { if (a[i]) { int r = 1; for (int j = 0; j < p; j++) { if (i != j) r = r * inv(i - j, p) % p; } dp[1][i + 1] += dp[0][i]; for (int j = 0; j <= dp[1][i + 1].degree(); j++) dp[1][i + 1][j] *= r; } P poly(2); poly[0] = -i; poly[1] = 1; dp[0][i + 1] += dp[0][i] * poly; dp[1][i + 1] += dp[1][i] * poly; for (int j = 0; j <= dp[0][i + 1].degree(); j++) dp[0][i + 1][j] %= p; for (int j = 0; j <= dp[1][i + 1].degree(); j++) dp[1][i + 1][j] %= p; } for (int i = 0; i + 1 < p; i++) { cout << (dp[1][p][i] + p) % p << " "; } cout << (dp[1][p][p - 1] + p) % p << endl; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdexcept> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; #include <algorithm> #include <vector> namespace ProconLib { namespace DetailNS { template <typename T> struct DefaultDetail { static bool isZero(T x) { return x <= T(0); } }; } // namespace DetailNS template <typename T> class Polynomial { int N; std::vector<T> dat; public: Polynomial(int N) : N(N), dat(N + 1) {} Polynomial() : Polynomial(0) {} Polynomial(const Polynomial &obj) : N(obj.N), dat(obj.dat) {} Polynomial(const Polynomial &&obj) : N(obj.N), dat(std::move(obj.dat)) {} int degree() { return N; } void resize(int N) { this->N = N; dat.resize(N + 1, T(0)); } template <typename Detail = DetailNS::DefaultDetail<T>> void shrink(); T &operator[](int pos) { return dat[pos]; } const T &operator[](int pos) const { return dat[pos]; } T operator()(T x); }; template <typename T> Polynomial<T> &operator+=(Polynomial<T> &lhs, Polynomial<T> rhs); template <typename T> Polynomial<T> &operator-=(Polynomial<T> &lhs, Polynomial<T> rhs); template <typename T> Polynomial<T> &operator*=(Polynomial<T> &lhs, Polynomial<T> rhs); template <typename T> Polynomial<T> operator+(Polynomial<T> lhs, Polynomial<T> rhs) { return lhs += rhs; } template <typename T> Polynomial<T> operator-(Polynomial<T> lhs, Polynomial<T> rhs) { return lhs -= rhs; } template <typename T> Polynomial<T> operator*(Polynomial<T> lhs, Polynomial<T> rhs) { return lhs *= rhs; } template <typename T> template <typename Detail> void Polynomial<T>::shrink() { while (N) { if (Detail::isZero(dat[N])) N--; else break; } resize(N); } template <typename T> Polynomial<T> &operator+=(Polynomial<T> &lhs, Polynomial<T> rhs) { lhs.resize(std::max(lhs.degree(), rhs.degree())); for (int i = 0; i <= rhs.degree(); i++) lhs[i] += rhs[i]; return lhs; } template <typename T> Polynomial<T> &operator-=(Polynomial<T> &lhs, Polynomial<T> rhs) { lhs.resize(std::max(lhs.degree(), rhs.degree())); for (int i = 0; i <= rhs.degree(); i++) lhs[i] -= rhs[i]; return lhs; } template <typename T> Polynomial<T> &operator*=(Polynomial<T> &lhs, Polynomial<T> rhs) { Polynomial<T> lhsTmp = lhs; lhs.resize(lhs.degree() + rhs.degree()); for (int i = 0; i <= lhsTmp.degree(); i++) lhs[i] = T(0); for (int i = 0; i <= lhsTmp.degree(); i++) { for (int j = 0; j <= rhs.degree(); j++) { lhs[i + j] += lhsTmp[i] * rhs[j]; } } return lhs; } template <typename T> Polynomial<T> operator+(Polynomial<T> poly) { auto res = poly; return res; } template <typename T> Polynomial<T> operator-(Polynomial<T> poly) { auto res = poly; for (int i = 0; i <= poly.degree(); i++) res[i] = -res[i]; return res; } template <typename T> T Polynomial<T>::operator()(T x) { T res = T(0); T px = T(1); for (int i = 0; i <= degree(); i++) { res += dat[i] * px; px *= x; } return res; } } // namespace ProconLib using namespace ProconLib; int powm(int x, int k, int p) { int res = 1; while (k) { if (k & 1) res = res * x % p; k >>= 1; x = x * x % p; } return res; } int inv(int x, int p) { return powm(x, p - 2, p); } using P = Polynomial<int>; int main() { int p; cin >> p; vector<int> a(p); for (int i = 0; i < p; i++) cin >> a[i]; vector<vector<P>> dp(2, vector<P>(p + 1)); dp[0][0][0] = 1; for (int i = 0; i < p; i++) { if (a[i]) { int r = 1; for (int j = 0; j < p; j++) { if (i != j) r = r * inv(i - j, p) % p; } dp[1][i + 1] += dp[0][i]; for (int j = 0; j <= dp[1][i + 1].degree(); j++) dp[1][i + 1][j] *= r; } P poly(2); poly[0] = -i; poly[1] = 1; dp[0][i + 1] += dp[0][i] * poly; dp[1][i + 1] += dp[1][i] * poly; for (int j = 0; j <= dp[0][i + 1].degree(); j++) dp[0][i + 1][j] %= p; for (int j = 0; j <= dp[1][i + 1].degree(); j++) dp[1][i + 1][j] %= p; } for (int i = 0; i + 1 < p; i++) { cout << (dp[1][p][i] + p) % p << " "; } cout << (dp[1][p][p - 1] + p) % p << endl; return 0; }
replace
41
43
41
43
-11
p02950
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, N) for (int i = 0; i < (int)N; i++) #define all(a) (a).begin(), (a).end() int p; int MOD; struct mint { long long val; mint(long long v = 0) noexcept : val(v % MOD) { if (val < 0) v += MOD; } int getmod() { return MOD; } mint operator-() const noexcept { return val ? MOD - val : 0; } mint operator+(const mint &r) const noexcept { return mint(*this) += r; } mint operator-(const mint &r) const noexcept { return mint(*this) -= r; } mint operator*(const mint &r) const noexcept { return mint(*this) *= r; } mint operator/(const mint &r) const noexcept { return mint(*this) /= r; } mint &operator+=(const mint &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; if (val < 0) val += MOD; return *this; } mint &operator-=(const mint &r) noexcept { val -= r.val; if (val >= MOD) val -= MOD; if (val < 0) val += MOD; return *this; } mint &operator*=(const mint &r) noexcept { val = val * r.val % MOD; return *this; } mint &operator/=(const mint &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } bool operator==(const mint &r) const noexcept { return this->val == r.val; } bool operator!=(const mint &r) const noexcept { return this->val != r.val; } friend ostream &operator<<(ostream &os, const mint &x) noexcept { return os << x.val; } friend istream &operator>>(istream &is, mint &x) noexcept { return is >> x.val; } friend mint modpow(const mint &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } friend mint modinv(const mint &a) noexcept { return modpow(a, MOD - 2); } }; int main() { cin >> p; MOD = p; vector<mint> b(p, 0); int a; vector<mint> fact(p), ifact(p); fact[0] = 1; rep(i, p) { if (i + 1 < p) fact[i + 1] = fact[i] * (i + 1); ifact[i] = modinv(fact[i]); } rep(i, p) { cin >> a; if (a) { b[0] += 1; rep(j, p) b[j] -= fact[p - 1] * ifact[p - 1 - j] * ifact[j] * modpow(mint(-i), p - 1 - j); } } rep(i, p) { if (i != 0) cout << " "; cout << b[i]; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, N) for (int i = 0; i < (int)N; i++) #define all(a) (a).begin(), (a).end() int p; int MOD; struct mint { long long val; mint(long long v = 0) noexcept : val(v % MOD) { if (val < 0) v += MOD; } int getmod() { return MOD; } mint operator-() const noexcept { return val ? MOD - val : 0; } mint operator+(const mint &r) const noexcept { return mint(*this) += r; } mint operator-(const mint &r) const noexcept { return mint(*this) -= r; } mint operator*(const mint &r) const noexcept { return mint(*this) *= r; } mint operator/(const mint &r) const noexcept { return mint(*this) /= r; } mint &operator+=(const mint &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; if (val < 0) val += MOD; return *this; } mint &operator-=(const mint &r) noexcept { val -= r.val; if (val >= MOD) val -= MOD; if (val < 0) val += MOD; return *this; } mint &operator*=(const mint &r) noexcept { val = val * r.val % MOD; return *this; } mint &operator/=(const mint &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } bool operator==(const mint &r) const noexcept { return this->val == r.val; } bool operator!=(const mint &r) const noexcept { return this->val != r.val; } friend ostream &operator<<(ostream &os, const mint &x) noexcept { return os << x.val; } friend istream &operator>>(istream &is, mint &x) noexcept { return is >> x.val; } friend mint modpow(const mint &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } friend mint modinv(const mint &a) noexcept { return modpow(a, MOD - 2); } }; int main() { cin >> p; MOD = p; vector<mint> b(p, 0); int a; vector<mint> fact(p), ifact(p); fact[0] = 1; rep(i, p) { if (i + 1 < p) fact[i + 1] = fact[i] * (i + 1); ifact[i] = modinv(fact[i]); } rep(i, p) { cin >> a; if (a) { b[0] += 1; mint k = 1; for (int j = p - 1; j >= 0; --j) { b[j] -= fact[p - 1] * ifact[p - 1 - j] * ifact[j] * k; k *= -i; } } } rep(i, p) { if (i != 0) cout << " "; cout << b[i]; } cout << endl; return 0; }
replace
94
96
94
99
TLE
p02950
C++
Time Limit Exceeded
#include <algorithm> #include <complex> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = int(m); i < int(n); i++) #define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i) #define EACH(i, c) for (auto &(i) : c) #define all(c) begin(c), end(c) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(begin(c), end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) #ifdef LOCAL #define DEBUG(s) cout << (s) << endl #define dump(x) cerr << #x << " = " << (x) << endl #define BR cout << endl; #else #define DEBUG(s) \ do { \ } while (0) #define dump(x) \ do { \ } while (0) #define BR #endif using namespace std; using UI = unsigned int; using UL = unsigned long; using LL = long long int; using ULL = unsigned long long; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<LL>; using VVLL = vector<VLL>; using VS = vector<string>; using PII = pair<int, int>; using VP = vector<PII>; // struct edge {int from, to, cost;}; constexpr double EPS = 1e-10; // constexpr double PI = acos(-1.0); // constexpr int INF = INT_MAX; constexpr int MOD = 1'000'000'007; // inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;} template <class T> inline T sqr(T x) { return x * x; } long long power(long long x, long long n, long long mod = 1000000007) { if (n == 0) return 1; if (n % 2 == 0) return power(x * x % mod, n / 2, mod); else return x * power(x, n - 1, mod) % mod; } void solve() { int p; cin >> p; VI a(p); REP(i, 0, p) cin >> a[i]; VVI r(p, VI(p)); VI g(p); REP(i, 1, p) { RREP(j, 1, p) { if ((i * j) % p == p - 1) { g[i] = j; break; } } } REP(i, 0, p) { REP(j, 0, p) { r[i][j] = g[power(i, j, p)]; } if (i) r[i][0] = 0; } r[0][0] = 1; r[0][p - 1] = p - 1; /* REP(i,0,p) { REP(j,0,p) cout << r[i][j] << " "; cout << endl; } */ VI ans(p); REP(i, 0, p) { if (a[i] != 1) continue; REP(j, 0, p) ans[j] = (ans[j] + r[i][j]) % p; } REP(i, 0, p) cout << ans[i] << " "; cout << endl; } int main() { solve(); return 0; }
#include <algorithm> #include <complex> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = int(m); i < int(n); i++) #define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i) #define EACH(i, c) for (auto &(i) : c) #define all(c) begin(c), end(c) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(begin(c), end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) #ifdef LOCAL #define DEBUG(s) cout << (s) << endl #define dump(x) cerr << #x << " = " << (x) << endl #define BR cout << endl; #else #define DEBUG(s) \ do { \ } while (0) #define dump(x) \ do { \ } while (0) #define BR #endif using namespace std; using UI = unsigned int; using UL = unsigned long; using LL = long long int; using ULL = unsigned long long; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<LL>; using VVLL = vector<VLL>; using VS = vector<string>; using PII = pair<int, int>; using VP = vector<PII>; // struct edge {int from, to, cost;}; constexpr double EPS = 1e-10; // constexpr double PI = acos(-1.0); // constexpr int INF = INT_MAX; constexpr int MOD = 1'000'000'007; // inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;} template <class T> inline T sqr(T x) { return x * x; } long long power(long long x, long long n, long long mod = 1000000007) { if (n == 0) return 1; if (n % 2 == 0) return power(x * x % mod, n / 2, mod); else return x * power(x, n - 1, mod) % mod; } void solve() { int p; cin >> p; VI a(p); REP(i, 0, p) cin >> a[i]; VVI r(p, VI(p)); VI g(p); REP(i, 1, p) { RREP(j, 1, p) { if ((i * j) % p == p - 1) { g[i] = j; break; } } } REP(i, 0, p) { int mul = 1; REP(j, 0, p) { r[i][j] = g[mul]; mul *= i; mul %= p; } if (i) r[i][0] = 0; } r[0][0] = 1; r[0][p - 1] = p - 1; /* REP(i,0,p) { REP(j,0,p) cout << r[i][j] << " "; cout << endl; } */ VI ans(p); REP(i, 0, p) { if (a[i] != 1) continue; REP(j, 0, p) ans[j] = (ans[j] + r[i][j]) % p; } REP(i, 0, p) cout << ans[i] << " "; cout << endl; } int main() { solve(); return 0; }
replace
88
89
88
94
TLE
p02950
C++
Time Limit Exceeded
#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; ll mod; vector<ll> inv, fact, invfact; void mod_build(int n = 101010) { fact.resize(n + 1); inv.resize(n + 1); invfact.resize(n + 1); fact[0] = inv[0] = invfact[0] = 1; inv[1] = 1; rep(i, n) { fact[i + 1] = fact[i] * (i + 1) % mod; if (i > 0) inv[i + 1] = mod - inv[mod % (i + 1)] * (mod / (i + 1)) % mod; invfact[i + 1] = invfact[i] * inv[i + 1] % mod; } } ll perm(int n, int k) { if (n < 0 || k < 0 || k > n) return 0; return fact[n] * invfact[n - k] % mod; } ll comb(int n, int k) { if (n < 0 || k < 0 || k > n) return 0; return (fact[n] * invfact[n - k] % mod) * invfact[k] % mod; } ll powmod(ll n, ll k) { k %= mod - 1; if (k < 0) k += mod - 1; ll ret = 1; while (k) { if (k & 1) ret = ret * n % mod; n = n * n % mod; k >>= 1; } return ret; } int main() { int n; cin >> n; mod = n; mod_build(n); vector<ll> ans(n); ll x; cin >> x; ans[n - 1] += n - x; ans[0] += x; REP(i, 1, n) { int x; cin >> x; ll res = inv[i]; REP(j, 1, n) { if (i == j) continue; else res *= inv[(i - j + n) % n]; res %= n; } rep(j, n - 1) ans[n - 1 - j] += powmod(i, j) * res * x % mod; } rep(i, n) ans[i] %= mod; rep(i, n) cout << ans[i] << " "; cout << endl; return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; ll mod; vector<ll> inv, fact, invfact; void mod_build(int n = 101010) { fact.resize(n + 1); inv.resize(n + 1); invfact.resize(n + 1); fact[0] = inv[0] = invfact[0] = 1; inv[1] = 1; rep(i, n) { fact[i + 1] = fact[i] * (i + 1) % mod; if (i > 0) inv[i + 1] = mod - inv[mod % (i + 1)] * (mod / (i + 1)) % mod; invfact[i + 1] = invfact[i] * inv[i + 1] % mod; } } ll perm(int n, int k) { if (n < 0 || k < 0 || k > n) return 0; return fact[n] * invfact[n - k] % mod; } ll comb(int n, int k) { if (n < 0 || k < 0 || k > n) return 0; return (fact[n] * invfact[n - k] % mod) * invfact[k] % mod; } ll powmod(ll n, ll k) { k %= mod - 1; if (k < 0) k += mod - 1; ll ret = 1; while (k) { if (k & 1) ret = ret * n % mod; n = n * n % mod; k >>= 1; } return ret; } int main() { int n; cin >> n; mod = n; mod_build(n); vector<ll> ans(n); ll x; cin >> x; ans[n - 1] += n - x; ans[0] += x; REP(i, 1, n) { int x; cin >> x; ll res = inv[i]; REP(j, 1, n) { if (i == j) continue; else res *= inv[(i - j + n) % n]; res %= n; } ll p = 1; rep(j, n - 1) { ans[n - 1 - j] += p * res * x % mod; p = p * i % mod; } } rep(i, n) ans[i] %= mod; rep(i, n) cout << ans[i] << " "; cout << endl; return 0; }
replace
82
83
82
87
TLE
p02950
C++
Time Limit Exceeded
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define E "\n" using namespace std; long long MOD = (long long)1e9 + 7; long long quickpow(long long b, int e) { return e ? ((e & 1 ? b : 1) * quickpow((b * b) % MOD, e >> 1)) % MOD : 1; } int p, a[3000], fac[3000], inv[3000], b[3000], cnt, dat[3000][3000]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> p; MOD = p; for (int i = 0; i < p; i++) { cin >> a[i]; if (a[i] == 1) cnt++; } fac[0] = 1; for (int i = 1; i < p; i++) { fac[i] = i * fac[i - 1]; fac[i] %= p; } for (int i = 0; i < p; i++) { inv[i] = quickpow(fac[i], p - 2); for (int j = 0; j < p; j++) { dat[i][j] = quickpow(i, j); } } for (int i = 0; i < p; i++) { int tmp = 0; for (int j = 0; j < p; j++) { if (a[j] == 0) continue; b[i] = fac[p - 1]; b[i] *= inv[i]; b[i] %= p; b[i] *= inv[p - 1 - i]; b[i] %= p; b[i] *= dat[(p - j) % p][p - 1 - i]; b[i] %= p; b[i] = p - b[i]; b[i] %= p; tmp += b[i]; tmp %= p; } b[i] = tmp; } b[0] += cnt; b[0] %= p; for (int i = 0; i < p; i++) { cout << b[i] << " "; } // system("pause"); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define E "\n" using namespace std; long long MOD = (long long)1e9 + 7; long long quickpow(long long b, int e) { return e ? ((e & 1 ? b : 1) * quickpow((b * b) % MOD, e >> 1)) % MOD : 1; } int p, a[3000], fac[3000], inv[3000], b[3000], cnt, dat[3000][3000]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> p; MOD = p; for (int i = 0; i < p; i++) { cin >> a[i]; if (a[i] == 1) cnt++; } fac[0] = 1; for (int i = 1; i < p; i++) { fac[i] = i * fac[i - 1]; fac[i] %= p; } for (int i = 0; i < p; i++) { inv[i] = quickpow(fac[i], p - 2); dat[i][0] = 1; for (int j = 1; j < p; j++) { dat[i][j] = dat[i][j - 1] * i; dat[i][j] %= p; } } for (int i = 0; i < p; i++) { int tmp = 0; for (int j = 0; j < p; j++) { if (a[j] == 0) continue; b[i] = fac[p - 1]; b[i] *= inv[i]; b[i] %= p; b[i] *= inv[p - 1 - i]; b[i] %= p; b[i] *= dat[(p - j) % p][p - 1 - i]; b[i] %= p; b[i] = p - b[i]; b[i] %= p; tmp += b[i]; tmp %= p; } b[i] = tmp; } b[0] += cnt; b[0] %= p; for (int i = 0; i < p; i++) { cout << b[i] << " "; } // system("pause"); return 0; }
replace
34
36
34
38
TLE
p02950
C++
Time Limit Exceeded
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include <bits/stdc++.h> using namespace std; using ll = long long; #define fr(i, n) for (int i = 0; i < (n); ++i) #define Fr(i, n) for (int i = 1; i <= (n); ++i) #define ifr(i, n) for (int i = (n)-1; i >= 0; --i) #define iFr(i, n) for (int i = (n); i > 0; --i) ll MOD; struct modint { ll a; modint(ll a_ = 0) { a = ((a_ % MOD) + MOD) % MOD; } modint inv() const { ll n = 1, m = MOD - 2, A = a; while (m) { if (m & 1) (n *= A) %= MOD; (A *= A) %= MOD; m >>= 1; } modint y(n); return y; } bool operator==(const modint &x) { return a == x.a; } bool operator!=(const modint &x) { return a != x.a; } modint &operator=(const modint &x) { a = x.a; return *this; } modint operator+(const modint &x) { modint y(a + x.a); return y; } modint operator-(const modint &x) { modint y(a - x.a); return y; } modint operator*(const modint &x) { modint y(a * x.a); return y; } modint operator/(const modint &x) { return *this * x.inv(); } modint &operator+=(const modint &x) { *this = *this + x; return *this; } modint &operator-=(const modint &x) { *this = *this - x; return *this; } modint &operator*=(const modint &x) { *this = *this * x; return *this; } modint &operator/=(const modint &x) { *this = *this / x; return *this; } }; istream &operator>>(istream &in, modint &x) { ll a_; in >> a_; modint y(a_); x = y; return in; } ostream &operator<<(ostream &out, const modint &x) { out << x.a; return out; } modint pwr(ll a, ll b) { modint n(1), A(a); while (b) { if (b & 1) n *= A; A *= A; b >>= 1; } return n; } template <class T> struct poly { int n; vector<T> p; poly(vector<T> &v) { n = v.size() - 1; p = v; while (*p.rbegin() == T(0) && n > 0) --n, p.pop_back(); } poly(T a = 0) { n = 0; p = vector<T>(1, a); } poly &operator+=(const poly &x) { n = max(n, x.n); p.resize(n + 1); for (int i = 0; i < x.p.size(); ++i) p[i] += x.p[i]; while (*p.rbegin() == T(0) && n > 0) --n, p.pop_back(); return *this; } poly &operator-=(const poly &x) { n = max(n, x.n); p.resize(n + 1); for (int i = 0; i < x.p.size(); ++i) p[i] -= x.p[i]; while (*p.rbegin() == T(0) && n > 0) --n, p.pop_back(); return *this; } poly operator*(const poly &x) { vector<T> q(n + x.n + 1); for (int i = 0; i <= n; ++i) for (int j = 0; j <= x.n; ++j) q[i + j] += p[i] * x.p[i]; while (*q.rbegin() == T(0) && n > 0) q.pop_back(); return poly(q); } poly operator/(const poly &x) { if (n < x.n) return *this; T k = T(1) / *x.p.rbegin(); vector<T> v(n - x.n + 1), q = p; for (int i = n - x.n; i >= 0; --i) { if (q[i + x.n] == T(0)) { v[i] = T(0); continue; } v[i] = q[i + x.n] * k; for (int j = 0; j < x.n; ++j) q[i + j] -= v[i] * x.p[j]; } return poly(v); } poly operator+(const poly &x) { poly y = *this; return y += x; } poly operator-(const poly &x) { poly y = *this; return y -= x; } poly &operator*=(const poly &x) { return *this = *this * x; } poly &operator/=(const poly &x) { return *this = *this / x; } T operator()(T x) { T c(1), a(0); for (int i = 0; i <= n; ++i) a += p[i] * c, c *= x; return a; } }; class FPolynomialConstruction { public: void solve(istream &in, ostream &out) { cin.tie(nullptr); ios::sync_with_stdio(false); int p; in >> p; MOD = p; vector<int> a(p); for (auto &i : a) in >> i; vector<modint> v(p + 1), b(2); v[p] = 1; v[1] = -1; b[1] = 1; poly<modint> xpmp(v), ans, tmp; fr(i, p) { if (a[i] == 0) continue; b[0] = -i; tmp = xpmp / b; ans += tmp / tmp(i); } vector<modint> an = ans.p; an.resize(p); fr(i, p) out << an[i] << " "; out << endl; } }; int main() { FPolynomialConstruction solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include <bits/stdc++.h> using namespace std; using ll = long long; #define fr(i, n) for (int i = 0; i < (n); ++i) #define Fr(i, n) for (int i = 1; i <= (n); ++i) #define ifr(i, n) for (int i = (n)-1; i >= 0; --i) #define iFr(i, n) for (int i = (n); i > 0; --i) ll MOD; struct modint { ll a; modint(ll a_ = 0) { a = ((a_ % MOD) + MOD) % MOD; } modint inv() const { ll n = 1, m = MOD - 2, A = a; while (m) { if (m & 1) (n *= A) %= MOD; (A *= A) %= MOD; m >>= 1; } modint y(n); return y; } bool operator==(const modint &x) { return a == x.a; } bool operator!=(const modint &x) { return a != x.a; } modint &operator=(const modint &x) { a = x.a; return *this; } modint operator+(const modint &x) { modint y(a + x.a); return y; } modint operator-(const modint &x) { modint y(a - x.a); return y; } modint operator*(const modint &x) { modint y(a * x.a); return y; } modint operator/(const modint &x) { return *this * x.inv(); } modint &operator+=(const modint &x) { *this = *this + x; return *this; } modint &operator-=(const modint &x) { *this = *this - x; return *this; } modint &operator*=(const modint &x) { *this = *this * x; return *this; } modint &operator/=(const modint &x) { *this = *this / x; return *this; } }; istream &operator>>(istream &in, modint &x) { ll a_; in >> a_; modint y(a_); x = y; return in; } ostream &operator<<(ostream &out, const modint &x) { out << x.a; return out; } modint pwr(ll a, ll b) { modint n(1), A(a); while (b) { if (b & 1) n *= A; A *= A; b >>= 1; } return n; } template <class T> struct poly { int n; vector<T> p; poly(vector<T> &v) { n = v.size() - 1; p = v; while (*p.rbegin() == T(0) && n > 0) --n, p.pop_back(); } poly(T a = 0) { n = 0; p = vector<T>(1, a); } poly &operator+=(const poly &x) { n = max(n, x.n); p.resize(n + 1); for (int i = 0; i < x.p.size(); ++i) p[i] += x.p[i]; while (*p.rbegin() == T(0) && n > 0) --n, p.pop_back(); return *this; } poly &operator-=(const poly &x) { n = max(n, x.n); p.resize(n + 1); for (int i = 0; i < x.p.size(); ++i) p[i] -= x.p[i]; while (*p.rbegin() == T(0) && n > 0) --n, p.pop_back(); return *this; } poly operator*(const poly &x) { vector<T> q(n + x.n + 1); for (int i = 0; i <= n; ++i) for (int j = 0; j <= x.n; ++j) q[i + j] += p[i] * x.p[i]; while (*q.rbegin() == T(0) && n > 0) q.pop_back(); return poly(q); } poly operator/(const poly &x) { if (n < x.n) return *this; T k = T(1) / *x.p.rbegin(); vector<T> v(n - x.n + 1), q = p; for (int i = n - x.n; i >= 0; --i) { if (q[i + x.n] == T(0)) { v[i] = T(0); continue; } v[i] = q[i + x.n] * k; for (int j = 0; j < x.n; ++j) q[i + j] -= v[i] * x.p[j]; } return poly(v); } poly operator+(const poly &x) { poly y = *this; return y += x; } poly operator-(const poly &x) { poly y = *this; return y -= x; } poly &operator*=(const poly &x) { return *this = *this * x; } poly &operator/=(const poly &x) { return *this = *this / x; } T operator()(T x) { T c(1), a(0); for (int i = 0; i <= n; ++i) a += p[i] * c, c *= x; return a; } }; class FPolynomialConstruction { public: void solve(istream &in, ostream &out) { cin.tie(nullptr); ios::sync_with_stdio(false); int p; in >> p; MOD = p; vector<int> a(p); for (auto &i : a) in >> i; vector<modint> v(p + 1), b(2); v[p] = 1; v[1] = -1; b[1] = 1; poly<modint> xpmp(v), ans, tmp; fr(i, p) { if (a[i] == 0) continue; b[0] = -i; tmp = xpmp / b; modint k = modint(1) / tmp(i); for (auto &j : tmp.p) j *= k; ans += tmp; } vector<modint> an = ans.p; an.resize(p); fr(i, p) out << an[i] << " "; out << endl; } }; int main() { FPolynomialConstruction solver; std::istream &in(std::cin); std::ostream &out(std::cout); solver.solve(in, out); return 0; }
replace
182
183
182
186
TLE
p02950
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)n; i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<pi, pi> pp; typedef pair<ll, ll> pl; const double EPS = 1e-9; const ll MOD = 1000000007; const int inf = 1 << 30; const ll linf = 1LL << 60; ll kai[200001]; ll mokai[200001]; ll p; ll mod_pow(ll x, ll y) { ll ret = 1; while (y) { if (y & 1) ret = ret * x % p; x = x * x % p; y /= 2; } return ret; } void init(int _n) { kai[0] = 1; for (int i = 1; i <= _n; i++) kai[i] = kai[i - 1] * i % p; for (int i = 0; i <= _n; i++) mokai[i] = mod_pow(kai[i], p - 2); } ll conb(ll x, ll y) { ll z = x - y; ll ret = kai[x] * mokai[y] % p; ret = ret * mokai[z] % p; return ret; } ll c[3000]; ll prep[3000][3000]; int main() { cin >> p; init(3000); rep(i, p + 1) { prep[i][0] = 1; for (int j = 1; j <= p; j++) prep[i][j] = prep[i][j - 1] * i % p; } rep(i, p) { ll a; cin >> a; if (a == 0) continue; (c[0] += 1) %= p; rep(j, p) { (c[j] += -1 * conb(p - 1, p - 1 - j) * mod_pow(p - i, p - 1 - j) + p * p * p) %= p; } } rep(i, p) { cout << c[i]; if (i != p - 1) cout << " "; } cout << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)n; i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<pi, pi> pp; typedef pair<ll, ll> pl; const double EPS = 1e-9; const ll MOD = 1000000007; const int inf = 1 << 30; const ll linf = 1LL << 60; ll kai[200001]; ll mokai[200001]; ll p; ll mod_pow(ll x, ll y) { ll ret = 1; while (y) { if (y & 1) ret = ret * x % p; x = x * x % p; y /= 2; } return ret; } void init(int _n) { kai[0] = 1; for (int i = 1; i <= _n; i++) kai[i] = kai[i - 1] * i % p; for (int i = 0; i <= _n; i++) mokai[i] = mod_pow(kai[i], p - 2); } ll conb(ll x, ll y) { ll z = x - y; ll ret = kai[x] * mokai[y] % p; ret = ret * mokai[z] % p; return ret; } ll c[3000]; ll prep[3000][3000]; int main() { cin >> p; init(3000); rep(i, p + 1) { prep[i][0] = 1; for (int j = 1; j <= p; j++) prep[i][j] = prep[i][j - 1] * i % p; } rep(i, p) { ll a; cin >> a; if (a == 0) continue; (c[0] += 1) %= p; rep(j, p) { (c[j] += -1 * conb(p - 1, p - 1 - j) * prep[p - i][p - 1 - j] + p * p * p) %= p; } } rep(i, p) { cout << c[i]; if (i != p - 1) cout << " "; } cout << endl; }
replace
61
63
61
63
TLE
p02950
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; typedef long long ll; long long MOD; struct mint { long long v; mint() : v(0) {} mint(long long x) { x = x % MOD; if (x < 0) { x += MOD; } v = x; } mint &operator+=(mint a) { v += a.v; if (v >= MOD) { v -= MOD; } return *this; } mint &operator*=(mint a) { v *= a.v; v %= MOD; return *this; } mint &operator-=(mint a) { v -= a.v; if (v < 0) { 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 pow(long long k) const { mint res(1), tmp(v); while (k) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } mint inv() { return pow(MOD - 2); } static mint comb(long long n, int k) { mint res(1); for (int i = 0; i < k; ++i) { res *= mint(n - i); res /= mint(i + 1); } return res; } static mint factorial(long long n) { mint res(1); for (int i = n; i > 1; --i) { res *= mint(i); } return res; } bool operator<(const mint &a) const { return v < a.v; }; }; mint operator*(long long l, mint r) { return r * l; } void calc_factorials(long long n, vector<mint> &out) { out.resize(n + 1); out.at(0) = 1; out.at(1) = 1; for (long long i = 2; i <= n; ++i) { out.at(i) = out.at(i - 1) * i; } } int main() { cin >> MOD; vector<int> a(MOD); for (int i = 0; i < MOD; ++i) { cin >> a.at(i); } vector<mint> facts, invs; calc_factorials(MOD - 1, facts); invs.resize(facts.size()); for (int i = 0; i < facts.size(); ++i) { invs.at(i) = facts.at(i).inv(); } vector<mint> b(MOD); for (int i = 0; i < MOD; ++i) { if (a.at(i) == 0) { continue; } b.at(0) += 1; for (int k = 0; k < MOD; ++k) { mint tmp = mint(i).pow(MOD - 1 - k); tmp *= facts.at(MOD - 1); tmp *= invs.at(k); tmp *= invs.at(MOD - 1 - k); b.at(k) -= mint(-i).pow(MOD - 1 - k) * facts.at(MOD - 1) * invs.at(k) * invs.at(MOD - 1 - k); } } for (int i = 0; i < b.size(); ++i) { cout << b.at(i).v; if (i != b.size() - 1) { cout << ' '; } } cout << endl; return 0; }
#include <iostream> #include <vector> using namespace std; typedef long long ll; long long MOD; struct mint { long long v; mint() : v(0) {} mint(long long x) { x = x % MOD; if (x < 0) { x += MOD; } v = x; } mint &operator+=(mint a) { v += a.v; if (v >= MOD) { v -= MOD; } return *this; } mint &operator*=(mint a) { v *= a.v; v %= MOD; return *this; } mint &operator-=(mint a) { v -= a.v; if (v < 0) { 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 pow(long long k) const { mint res(1), tmp(v); while (k) { if (k & 1) res *= tmp; tmp *= tmp; k >>= 1; } return res; } mint inv() { return pow(MOD - 2); } static mint comb(long long n, int k) { mint res(1); for (int i = 0; i < k; ++i) { res *= mint(n - i); res /= mint(i + 1); } return res; } static mint factorial(long long n) { mint res(1); for (int i = n; i > 1; --i) { res *= mint(i); } return res; } bool operator<(const mint &a) const { return v < a.v; }; }; mint operator*(long long l, mint r) { return r * l; } void calc_factorials(long long n, vector<mint> &out) { out.resize(n + 1); out.at(0) = 1; out.at(1) = 1; for (long long i = 2; i <= n; ++i) { out.at(i) = out.at(i - 1) * i; } } int main() { cin >> MOD; vector<int> a(MOD); for (int i = 0; i < MOD; ++i) { cin >> a.at(i); } vector<mint> facts, invs; calc_factorials(MOD - 1, facts); invs.resize(facts.size()); for (int i = 0; i < facts.size(); ++i) { invs.at(i) = facts.at(i).inv(); } vector<mint> b(MOD); for (int i = 0; i < MOD; ++i) { if (a.at(i) == 0) { continue; } b.at(0) += 1; mint tmp = 1; for (int k = MOD - 1; k >= 0; --k) { b.at(k) -= tmp * facts.at(MOD - 1) * invs.at(k) * invs.at(MOD - 1 - k); tmp *= -i; } } for (int i = 0; i < b.size(); ++i) { cout << b.at(i).v; if (i != b.size() - 1) { cout << ' '; } } cout << endl; return 0; }
replace
111
118
111
115
TLE
p02950
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; using ll = int64_t; ll MODpow(ll n, ll m, ll mod) { ll result = 1; while (m) { if (m % 2 == 1) { result *= n; result %= mod; } m /= 2; n *= n; n %= mod; } return result; } class Combination { public: Combination(ll max_num, ll mod) { fact_.resize(max_num + 1, 1); inv_fact_.resize(max_num + 1, 1); mod_ = mod; for (ll i = 2; i <= max_num; i++) { fact_[i] = i * fact_[i - 1] % mod_; inv_fact_[i] = MODpow(fact_[i], mod_ - 2, mod_); assert(fact_[i] * inv_fact_[i] % mod_ == 1); } } ll operator()(ll n, ll m) const { if (m < 0 || m > n) return 0; return fact_[n] * inv_fact_[n - m] % mod_ * inv_fact_[m] % mod_; } private: vector<ll> fact_, inv_fact_; ll mod_; }; int main() { ll p; cin >> p; vector<ll> a(p); for (ll i = 0; i < p; i++) { cin >> a[i]; } Combination comb(p - 1, p); vector<ll> b(p); for (ll j = 0; j < p; j++) { if (a[j] == 0) { continue; } // 1 - (x - j)^(p - 1)を展開 // この第二項についてx^iの項の係数を考えると - p-1_C_i (-j)^(p-1-i) for (ll i = 0; i < p; i++) { ll c = comb(p - 1, i) * MODpow(j, p - 1 - i, p); if ((p - 1 - i) % 2 == 0) { c = p - c; } if (i == 0) { c += 1; } (b[i] += c) %= p; } } for (ll i = 0; i < p; i++) { cout << b[i] << " \n"[i == p - 1]; } }
#include "bits/stdc++.h" using namespace std; using ll = int64_t; ll MODpow(ll n, ll m, ll mod) { ll result = 1; while (m) { if (m % 2 == 1) { result *= n; result %= mod; } m /= 2; n *= n; n %= mod; } return result; } class Combination { public: Combination(ll max_num, ll mod) { fact_.resize(max_num + 1, 1); inv_fact_.resize(max_num + 1, 1); mod_ = mod; for (ll i = 2; i <= max_num; i++) { fact_[i] = i * fact_[i - 1] % mod_; inv_fact_[i] = MODpow(fact_[i], mod_ - 2, mod_); assert(fact_[i] * inv_fact_[i] % mod_ == 1); } } ll operator()(ll n, ll m) const { if (m < 0 || m > n) return 0; return fact_[n] * inv_fact_[n - m] % mod_ * inv_fact_[m] % mod_; } private: vector<ll> fact_, inv_fact_; ll mod_; }; int main() { ll p; cin >> p; vector<ll> a(p); for (ll i = 0; i < p; i++) { cin >> a[i]; } Combination comb(p - 1, p); vector<ll> b(p); for (ll j = 0; j < p; j++) { if (a[j] == 0) { continue; } // 1 - (x - j)^(p - 1)を展開 // この第二項についてx^iの項の係数を考えると - p-1_C_i (-j)^(p-1-i) ll pow = 1; for (ll i = p - 1; i >= 0; i--) { ll c = comb(p - 1, i) * pow % p; (pow *= j) %= p; if ((p - 1 - i) % 2 == 0) { c = p - c; } if (i == 0) { c += 1; } (b[i] += c) %= p; } } for (ll i = 0; i < p; i++) { cout << b[i] << " \n"[i == p - 1]; } }
replace
60
62
60
64
TLE
p02950
C++
Time Limit Exceeded
#include <iostream> #include <vector> int main() { int p; std::cin >> p; std::vector<int> a(p); for (int i = 0; i < p; i++) std::cin >> a[i]; auto pow = [&p](long long a, int n) { long long res = 1; for (; n; n >>= 1) { if (n & 1) res = res * a % p; a = a * a % p; } return res; }; std::vector<long long> fact(p), inv_fact(p); fact[0] = 1; for (int i = 1; i < p; i++) fact[i] = fact[i - 1] * i % p; inv_fact[p - 1] = pow(fact[p - 1], p - 2); for (int i = p - 1; i > 0; i--) inv_fact[i - 1] = inv_fact[i] * i % p; auto comb = [&p, &fact, &inv_fact](int n, int r) { if (n < r) return 0LL; long long tmp = inv_fact[n - r] * inv_fact[r] % p; return fact[n] * tmp % p; }; std::vector<int> b(p); for (int i = 0; i < p; i++) { if (a[i] == 0) continue; std::vector<int> c(p); for (int k = 0; k < p; k++) c[k] = pow(-i, p - 1 - k); b[0]++; for (int k = 0; k < p; k++) b[k] = (b[k] + p - comb(p - 1, k) * c[k] % p) % p; } for (int i = 0; i < p; i++) std::cout << b[i] << (i < p - 1 ? " " : "\n"); }
#include <iostream> #include <vector> int main() { int p; std::cin >> p; std::vector<int> a(p); for (int i = 0; i < p; i++) std::cin >> a[i]; auto pow = [&p](long long a, int n) { long long res = 1; for (; n; n >>= 1) { if (n & 1) res = res * a % p; a = a * a % p; } return res; }; std::vector<long long> fact(p), inv_fact(p); fact[0] = 1; for (int i = 1; i < p; i++) fact[i] = fact[i - 1] * i % p; inv_fact[p - 1] = pow(fact[p - 1], p - 2); for (int i = p - 1; i > 0; i--) inv_fact[i - 1] = inv_fact[i] * i % p; auto comb = [&p, &fact, &inv_fact](int n, int r) { if (n < r) return 0LL; long long tmp = inv_fact[n - r] * inv_fact[r] % p; return fact[n] * tmp % p; }; std::vector<int> b(p); for (int i = 0; i < p; i++) { if (a[i] == 0) continue; std::vector<int> c(p); c[p - 1] = 1; for (int k = p - 2; k >= 0; k--) c[k] = -i * c[k + 1] % p; b[0]++; for (int k = 0; k < p; k++) b[k] = (b[k] + p - comb(p - 1, k) * c[k] % p) % p; } for (int i = 0; i < p; i++) std::cout << b[i] << (i < p - 1 ? " " : "\n"); }
replace
42
44
42
45
TLE
p02950
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, n, m) for (int i = (int)(n); i <= (int)(m); i++) #define RFOR(i, n, m) for (int i = (int)(n); i >= (int)(m); i--) #define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++) #define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++) #define setp(n) fixed << setprecision(n) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll, ll> #define pi pair<int, int> #define all(a) (a.begin()), (a.end()) #define rall(a) (a.rbegin()), (a.rend()) #define fi first #define se second #define pb push_back #define mp make_pair #define ins insert using namespace std; //------------------------------------------------- //--ModInt //------------------------------------------------- ::std::uint_fast64_t MOD; class mint { private: using value_type = ::std::uint_fast64_t; value_type n; public: mint() : n(0) {} mint(::std::int_fast64_t _n) : n(_n < 0 ? MOD - (-_n) % MOD : _n % MOD) {} mint(const mint &m) : n(m.n) {} friend ::std::ostream &operator<<(::std::ostream &os, const mint &a) { return os << a.n; } friend ::std::istream &operator>>(::std::istream &is, mint &a) { value_type temp; is >> temp; a = mint(temp); return is; } mint &operator+=(const mint &m) { n += m.n; n = (n < MOD) ? n : n - MOD; return *this; } mint &operator-=(const mint &m) { n += MOD - m.n; n = (n < MOD) ? n : n - MOD; return *this; } mint &operator*=(const mint &m) { n = n * m.n % MOD; return *this; } mint &operator/=(const mint &m) { return *this *= m.inv(); } mint &operator++() { return *this += 1; } mint &operator--() { return *this -= 1; } mint operator+(const mint &m) const { return mint(*this) += m; } mint operator-(const mint &m) const { return mint(*this) -= m; } mint operator*(const mint &m) const { return mint(*this) *= m; } mint operator/(const mint &m) const { return mint(*this) /= m; } mint operator++(int) { mint t(*this); *this += 1; return t; } mint operator--(int) { mint t(*this); *this -= 1; return t; } bool operator==(const mint &m) const { return n == m.n; } bool operator!=(const mint &m) const { return n != m.n; } mint operator-() const { return mint(MOD - n); } mint pow(value_type b) const { mint ret(1), m(*this); while (b) { if (b & 1) ret *= m; m *= m; b >>= 1; } return ret; } mint inv() const { return pow(MOD - 2); } }; //------------------------------------------------- int main(void) { cin.tie(0); ios::sync_with_stdio(false); int p; cin >> p; MOD = p; vi a(p); rep(i, p) cin >> a[i]; vector<mint> dp(p + 1); dp[0] = 1; rep(i, p) RFOR(j, p, 0) { dp[j] *= -i; if (j >= 1) dp[j] += dp[j - 1]; } reverse(all(dp)); vector<mint> ans(p); mint deno = 1; rep(i, p - 1) deno *= -(i + 1); rep(i, p) { // mint deno=1; // rep(j,p)if(j!=i) deno*=i-j; if (a[i] == 0) continue; vector<mint> poly = dp; rep(j, p) { ans[j] += poly[j] / deno; poly[j + 1] += poly[j] * i; } deno *= mint(i + 1) / (i - p + 1); } reverse(all(ans)); rep(i, p) { if (i > 0) cout << " "; cout << ans[i]; } cout << "\n"; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, n, m) for (int i = (int)(n); i <= (int)(m); i++) #define RFOR(i, n, m) for (int i = (int)(n); i >= (int)(m); i--) #define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++) #define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++) #define setp(n) fixed << setprecision(n) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll, ll> #define pi pair<int, int> #define all(a) (a.begin()), (a.end()) #define rall(a) (a.rbegin()), (a.rend()) #define fi first #define se second #define pb push_back #define mp make_pair #define ins insert using namespace std; //------------------------------------------------- //--ModInt //------------------------------------------------- ::std::uint_fast64_t MOD; class mint { private: using value_type = ::std::uint_fast64_t; value_type n; public: mint() : n(0) {} mint(::std::int_fast64_t _n) : n(_n < 0 ? MOD - (-_n) % MOD : _n % MOD) {} mint(const mint &m) : n(m.n) {} friend ::std::ostream &operator<<(::std::ostream &os, const mint &a) { return os << a.n; } friend ::std::istream &operator>>(::std::istream &is, mint &a) { value_type temp; is >> temp; a = mint(temp); return is; } mint &operator+=(const mint &m) { n += m.n; n = (n < MOD) ? n : n - MOD; return *this; } mint &operator-=(const mint &m) { n += MOD - m.n; n = (n < MOD) ? n : n - MOD; return *this; } mint &operator*=(const mint &m) { n = n * m.n % MOD; return *this; } mint &operator/=(const mint &m) { return *this *= m.inv(); } mint &operator++() { return *this += 1; } mint &operator--() { return *this -= 1; } mint operator+(const mint &m) const { return mint(*this) += m; } mint operator-(const mint &m) const { return mint(*this) -= m; } mint operator*(const mint &m) const { return mint(*this) *= m; } mint operator/(const mint &m) const { return mint(*this) /= m; } mint operator++(int) { mint t(*this); *this += 1; return t; } mint operator--(int) { mint t(*this); *this -= 1; return t; } bool operator==(const mint &m) const { return n == m.n; } bool operator!=(const mint &m) const { return n != m.n; } mint operator-() const { return mint(MOD - n); } mint pow(value_type b) const { mint ret(1), m(*this); while (b) { if (b & 1) ret *= m; m *= m; b >>= 1; } return ret; } mint inv() const { return pow(MOD - 2); } }; //------------------------------------------------- int main(void) { cin.tie(0); ios::sync_with_stdio(false); int p; cin >> p; MOD = p; vi a(p); rep(i, p) cin >> a[i]; vector<mint> dp(p + 1); dp[0] = 1; rep(i, p) RFOR(j, p, 0) { dp[j] *= -i; if (j >= 1) dp[j] += dp[j - 1]; } reverse(all(dp)); vector<mint> ans(p); mint deno = 1; rep(i, p - 1) deno *= -(i + 1); rep(i, p) { // mint deno=1; // rep(j,p)if(j!=i) deno*=i-j; if (a[i] == 0) continue; vector<mint> poly = dp; mint inv = deno.inv(); rep(j, p) if (poly[j] != 0) { ans[j] += poly[j] * inv; poly[j + 1] += poly[j] * i; } deno *= mint(i + 1) / (i - p + 1); } reverse(all(ans)); rep(i, p) { if (i > 0) cout << " "; cout << ans[i]; } cout << "\n"; return 0; }
replace
143
145
143
146
TLE
p02950
C++
Time Limit Exceeded
// editorial見た。 #include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; typedef long long ll; long long inv(int a, int p) { return a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p; } int MODVAL; struct mint { int val; mint() : val(0) {} mint(int x) : val(x % MODVAL) { if (val < 0) val += MODVAL; } mint(size_t x) : val(x % MODVAL) {} mint(long long x) : val(x % MODVAL) { if (val < 0) val += MODVAL; } mint &operator+=(mint y) { val += y.val; if (val >= MODVAL) val -= MODVAL; return *this; } mint &operator-=(mint y) { val -= y.val; if (val < 0) val += MODVAL; return *this; } mint &operator*=(mint y) { val = (val * (long long)y.val) % MODVAL; return *this; } mint &operator/=(mint y) { val = (val * inv(y.val, MODVAL)) % MODVAL; return *this; } }; inline mint operator+(mint x, mint y) { return x += y; } inline mint operator-(mint x, mint y) { return x -= y; } inline mint operator*(mint x, mint y) { return x *= y; } inline mint operator/(mint x, mint y) { return x /= y; } mint POW(mint x, long long n) { mint r(1); for (; n; x *= x, n >>= 1) if (n & 1) r *= x; return r; } mint FAC(int n) { static vector<mint> FAC_(1, 1); while (int(FAC_.size()) <= n) FAC_.push_back(FAC_.back() * FAC_.size()); return FAC_[n]; } inline mint CMB(int n, int k) { return k < 0 || n < k ? 0 : FAC(n) / (FAC(k) * FAC(n - k)); } inline ostream &operator<<(ostream &os, mint a) { return os << a.val; } int as[3010]; mint ans[3010]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int P; cin >> P; MODVAL = P; REP(i, P) { cin >> as[i]; if (as[i] == 1) { ans[0] += 1; REP(j, P) { ans[P - 1 - j] -= CMB(P - 1, j) * POW(-i, j); } } } REP(i, P) { cout << ans[i]; if (i == P - 1) { cout << endl; } else { cout << " "; } } return 0; }
// editorial見た。 #include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; typedef long long ll; long long inv(int a, int p) { return a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p; } int MODVAL; struct mint { int val; mint() : val(0) {} mint(int x) : val(x % MODVAL) { if (val < 0) val += MODVAL; } mint(size_t x) : val(x % MODVAL) {} mint(long long x) : val(x % MODVAL) { if (val < 0) val += MODVAL; } mint &operator+=(mint y) { val += y.val; if (val >= MODVAL) val -= MODVAL; return *this; } mint &operator-=(mint y) { val -= y.val; if (val < 0) val += MODVAL; return *this; } mint &operator*=(mint y) { val = (val * (long long)y.val) % MODVAL; return *this; } mint &operator/=(mint y) { val = (val * inv(y.val, MODVAL)) % MODVAL; return *this; } }; inline mint operator+(mint x, mint y) { return x += y; } inline mint operator-(mint x, mint y) { return x -= y; } inline mint operator*(mint x, mint y) { return x *= y; } inline mint operator/(mint x, mint y) { return x /= y; } mint POW(mint x, long long n) { mint r(1); for (; n; x *= x, n >>= 1) if (n & 1) r *= x; return r; } mint FAC(int n) { static vector<mint> FAC_(1, 1); while (int(FAC_.size()) <= n) FAC_.push_back(FAC_.back() * FAC_.size()); return FAC_[n]; } inline mint CMB(int n, int k) { return k < 0 || n < k ? 0 : FAC(n) / (FAC(k) * FAC(n - k)); } inline ostream &operator<<(ostream &os, mint a) { return os << a.val; } int as[3010]; mint ans[3010]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int P; cin >> P; MODVAL = P; REP(i, P) { cin >> as[i]; if (as[i] == 1) { ans[0] += 1; mint cur = 1; REP(j, P) { ans[P - 1 - j] -= CMB(P - 1, j) * cur; cur *= -i; } } } REP(i, P) { cout << ans[i]; if (i == P - 1) { cout << endl; } else { cout << " "; } } return 0; }
replace
87
88
87
92
TLE
p02950
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; struct ModInt { using M = ModInt; long long MOD; long long v; ModInt(long long _v = 0, long long _MOD = 1e9 + 7) : MOD(_MOD), v(_v % MOD + MOD) { norm(); } M &norm() { v = (v < MOD) ? v : v - MOD; return *this; } M operator+(const M &x) const { return M(v + x.v, MOD); } M operator-(const M &x) const { return M(v + MOD - x.v, MOD); } M operator*(const M &x) const { return M(v * x.v % MOD, MOD); } M operator/(const M &x) const { return M(v * x.inv().v, MOD); } M &operator+=(const M &x) { return *this = *this + x; } M &operator-=(const M &x) { return *this = *this - x; } M &operator*=(const M &x) { return *this = *this * x; } M &operator/=(const M &x) { return *this = *this / x; } friend istream &operator>>(istream &input, M &x) { return input >> x.v, x.norm(), input; } friend ostream &operator<<(ostream &output, const M &x) { return output << x.v; } M pow(long long n) const { M x(v, MOD), res(1, MOD); while (n) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } M inv() const { return this->pow(MOD - 2); } static vector<M> fact, finv; static void build(int n, long long p) { fact.assign(n + 1, M(1, p)); finv.assign(n + 1, M(1, p)); for (int i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * M(i, p); for (int i = 0; i < n + 1; i++) finv[i] = fact[i].inv(); } static M comb(int n, int k, long long p) { if (n < k || k < 0) return M(0, p); return fact[n] * finv[n - k] * finv[k]; } }; vector<ModInt> ModInt::fact = vector<ModInt>(); vector<ModInt> ModInt::finv = vector<ModInt>(); using mint = ModInt; int main() { int p; cin >> p; vector<int> a(p); for (int i = 0; i < p; i++) cin >> a[i]; mint::build(p, p); vector<mint> b(p, mint(0, p)); for (int i = 0; i < p; i++) { if (a[i] == 0) continue; b[0] += mint(1, p); for (int j = 0; j < p; j++) { b[j] -= mint(-i, p).pow(p - 1 - j) * mint::comb(p - 1, j, p); } } for (auto x : b) { cout << x << ' '; } cout << endl; }
#include <bits/stdc++.h> using namespace std; struct ModInt { using M = ModInt; long long MOD; long long v; ModInt(long long _v = 0, long long _MOD = 1e9 + 7) : MOD(_MOD), v(_v % MOD + MOD) { norm(); } M &norm() { v = (v < MOD) ? v : v - MOD; return *this; } M operator+(const M &x) const { return M(v + x.v, MOD); } M operator-(const M &x) const { return M(v + MOD - x.v, MOD); } M operator*(const M &x) const { return M(v * x.v % MOD, MOD); } M operator/(const M &x) const { return M(v * x.inv().v, MOD); } M &operator+=(const M &x) { return *this = *this + x; } M &operator-=(const M &x) { return *this = *this - x; } M &operator*=(const M &x) { return *this = *this * x; } M &operator/=(const M &x) { return *this = *this / x; } friend istream &operator>>(istream &input, M &x) { return input >> x.v, x.norm(), input; } friend ostream &operator<<(ostream &output, const M &x) { return output << x.v; } M pow(long long n) const { M x(v, MOD), res(1, MOD); while (n) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } M inv() const { return this->pow(MOD - 2); } static vector<M> fact, finv; static void build(int n, long long p) { fact.assign(n + 1, M(1, p)); finv.assign(n + 1, M(1, p)); for (int i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * M(i, p); for (int i = 0; i < n + 1; i++) finv[i] = fact[i].inv(); } static M comb(int n, int k, long long p) { if (n < k || k < 0) return M(0, p); return fact[n] * finv[n - k] * finv[k]; } }; vector<ModInt> ModInt::fact = vector<ModInt>(); vector<ModInt> ModInt::finv = vector<ModInt>(); using mint = ModInt; int main() { int p; cin >> p; vector<int> a(p); for (int i = 0; i < p; i++) cin >> a[i]; mint::build(p, p); vector<mint> b(p, mint(0, p)); for (int i = 0; i < p; i++) { if (a[i] == 0) continue; b[0] += mint(1, p); mint pw = mint(1, p); for (int j = p - 1; j >= 0; j--) { b[j] -= pw * mint::comb(p - 1, j, p); pw *= mint(-i, p); } } for (auto x : b) { cout << x << ' '; } cout << endl; }
replace
72
74
72
76
TLE
p02950
C++
Runtime Error
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <vector> using namespace std; #define int long long #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 1000000007 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define pi 3.141592653589793238462643383279 #define e_ 2.718281828459045235360287471352 #define P pair<int, int> #define upp(a, n, x) upper_bound(a, a + n, x) - a; #define low(a, n, x) lower_bound(a, a + n, x) - a; #define UF UnionFind #define pb push_back // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { if (x == 0 || y == 0) return x + y; int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool prime(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } string maxst(string s, string t) { int n = s.size(); int m = t.size(); if (n > m) return s; else if (n < m) return t; else { rep(0, i, n) { if (s[i] > t[i]) return s; if (s[i] < t[i]) return t; } return s; } } string minst(string s, string t) { int n = s.size(); int m = t.size(); if (n < m) return s; else if (n > m) return t; else { rep(0, i, n) { if (s[i] < t[i]) return s; if (s[i] > t[i]) return t; } return s; } } string string_reverse(string s) { int n = s.size(); string t; rep(0, i, n) t += s[n - i - 1]; return t; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[41]; int nis[41]; int nia[41]; int mody[41]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int gyakugen(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } mody[0] = y; rep(1, i, 41) { y = (y * y) % mod; mody[i] = y; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { n = (n * mody[i]) % mod; } } return n; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } int poow(int y, int n) { if (n == 0) return 1; n -= 1; int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int yy = y; mody[0] = yy; rep(1, i, 41) { yy = (yy * yy) % mod; mody[i] = yy; } rep(0, i, 41) nis[i] = 0; nn = n; for (int i = 40; i >= 0; i -= 1) { if (nn >= n2[i]) { nis[i]++; nn -= n2[i]; } } rep(0, i, 41) { if (nis[i] == 1) { y = (y * mody[i]) % mod; } } return y; } int minpow(int x, int y) { int sum = 1; rep(0, i, y) sum *= x; return sum; } int ketawa(int x, int sinsuu) { int sum = 0; rep(0, i, 80) { if (minpow(sinsuu, i) > x) { return sum; } sum += (x % minpow(sinsuu, i + 1)) / (minpow(sinsuu, i)); } return sum; } double distance(double a, double b, double c, double d) { return sqrt((b - a) * (b - a) + (c - d) * (c - d)); } int sankaku(int a) { return a * (a + 1) / 2; } int sames(int a[1111111], int n) { int ans = 0; rep(0, i, n) { if (a[i] == a[i + 1]) { int j = i; while (a[j + 1] == a[i] && j <= n - 2) j++; ans += sankaku(j - i); i = j; } } return ans; } using Graph = vector<vector<int>>; int oya[114514]; int depth[114514]; void dfs(const Graph &G, int v, int p, int d) { depth[v] = d; oya[v] = p; for (auto nv : G[v]) { if (nv == p) continue; // nv が親 p だったらダメ dfs(G, nv, v, d + 1); // d を 1 増やして子ノードへ } } /*int H=10,W=10; char field[10][10]; char memo[10][10]; void dfs(int h, int w) { memo[h][w] = 'x'; // 八方向を探索 for (int dh = -1; dh <= 1; ++dh) { for (int dw = -1; dw <= 1; ++dw) { if(abs(0-dh)+abs(0-dw)==2)continue; int nh = h + dh, nw = w + dw; // 場外アウトしたり、0 だったりはスルー if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (memo[nh][nw] == 'x') continue; // 再帰的に探索 dfs(nh, nw); } } }*/ int XOR(int a, int b) { if (a == 0 || b == 0) { return a + b; } int ni = 1; rep(0, i, 41) { n2[i] = ni; ni *= 2; } rep(0, i, 41) nis[i] = 0; for (int i = 40; i >= 0; i -= 1) { if (a >= n2[i]) { nis[i]++; a -= n2[i]; } if (b >= n2[i]) { nis[i]++; b -= n2[i]; } } int sum = 0; rep(0, i, 41) sum += (nis[i] % 2 * n2[i]); return sum; } // int ma[1024577][21]; // for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1; struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; int a[3145]; int p[3145][3145]; int m[3145][3145]; signed main() { ic(n) if (n == 2) { c(n / 0) return 0; } rep(0, i, n) cin >> a[i]; rep(0, i, n) { int t = 1; rep(0, j, n) { p[i][j] = t; t *= i; t %= n; } } rep(0, i, n) { rep(0, j, n) { m[i][j] = n - p[n - i - 1][j]; } } for (int i = n - 1; i >= 0; i -= 1) { int sum = 0; rep(0, j, n) sum += m[j][i] * a[n - 1 - j]; if (i == n - 1) cout << a[0] << " "; else cout << sum % n << " "; } }
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <vector> using namespace std; #define int long long #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 1000000007 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define pi 3.141592653589793238462643383279 #define e_ 2.718281828459045235360287471352 #define P pair<int, int> #define upp(a, n, x) upper_bound(a, a + n, x) - a; #define low(a, n, x) lower_bound(a, a + n, x) - a; #define UF UnionFind #define pb push_back // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { if (x == 0 || y == 0) return x + y; int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool prime(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } string maxst(string s, string t) { int n = s.size(); int m = t.size(); if (n > m) return s; else if (n < m) return t; else { rep(0, i, n) { if (s[i] > t[i]) return s; if (s[i] < t[i]) return t; } return s; } } string minst(string s, string t) { int n = s.size(); int m = t.size(); if (n < m) return s; else if (n > m) return t; else { rep(0, i, n) { if (s[i] < t[i]) return s; if (s[i] > t[i]) return t; } return s; } } string string_reverse(string s) { int n = s.size(); string t; rep(0, i, n) t += s[n - i - 1]; return t; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[41]; int nis[41]; int nia[41]; int mody[41]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int gyakugen(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } mody[0] = y; rep(1, i, 41) { y = (y * y) % mod; mody[i] = y; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { n = (n * mody[i]) % mod; } } return n; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } int poow(int y, int n) { if (n == 0) return 1; n -= 1; int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int yy = y; mody[0] = yy; rep(1, i, 41) { yy = (yy * yy) % mod; mody[i] = yy; } rep(0, i, 41) nis[i] = 0; nn = n; for (int i = 40; i >= 0; i -= 1) { if (nn >= n2[i]) { nis[i]++; nn -= n2[i]; } } rep(0, i, 41) { if (nis[i] == 1) { y = (y * mody[i]) % mod; } } return y; } int minpow(int x, int y) { int sum = 1; rep(0, i, y) sum *= x; return sum; } int ketawa(int x, int sinsuu) { int sum = 0; rep(0, i, 80) { if (minpow(sinsuu, i) > x) { return sum; } sum += (x % minpow(sinsuu, i + 1)) / (minpow(sinsuu, i)); } return sum; } double distance(double a, double b, double c, double d) { return sqrt((b - a) * (b - a) + (c - d) * (c - d)); } int sankaku(int a) { return a * (a + 1) / 2; } int sames(int a[1111111], int n) { int ans = 0; rep(0, i, n) { if (a[i] == a[i + 1]) { int j = i; while (a[j + 1] == a[i] && j <= n - 2) j++; ans += sankaku(j - i); i = j; } } return ans; } using Graph = vector<vector<int>>; int oya[114514]; int depth[114514]; void dfs(const Graph &G, int v, int p, int d) { depth[v] = d; oya[v] = p; for (auto nv : G[v]) { if (nv == p) continue; // nv が親 p だったらダメ dfs(G, nv, v, d + 1); // d を 1 増やして子ノードへ } } /*int H=10,W=10; char field[10][10]; char memo[10][10]; void dfs(int h, int w) { memo[h][w] = 'x'; // 八方向を探索 for (int dh = -1; dh <= 1; ++dh) { for (int dw = -1; dw <= 1; ++dw) { if(abs(0-dh)+abs(0-dw)==2)continue; int nh = h + dh, nw = w + dw; // 場外アウトしたり、0 だったりはスルー if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (memo[nh][nw] == 'x') continue; // 再帰的に探索 dfs(nh, nw); } } }*/ int XOR(int a, int b) { if (a == 0 || b == 0) { return a + b; } int ni = 1; rep(0, i, 41) { n2[i] = ni; ni *= 2; } rep(0, i, 41) nis[i] = 0; for (int i = 40; i >= 0; i -= 1) { if (a >= n2[i]) { nis[i]++; a -= n2[i]; } if (b >= n2[i]) { nis[i]++; b -= n2[i]; } } int sum = 0; rep(0, i, 41) sum += (nis[i] % 2 * n2[i]); return sum; } // int ma[1024577][21]; // for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1; struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化 for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } }; int a[3145]; int p[3145][3145]; int m[3145][3145]; signed main() { ic(n) rep(0, i, n) cin >> a[i]; rep(0, i, n) { int t = 1; rep(0, j, n) { p[i][j] = t; t *= i; t %= n; } } rep(0, i, n) { rep(0, j, n) { m[i][j] = n - p[n - i - 1][j]; } } for (int i = n - 1; i >= 0; i -= 1) { int sum = 0; rep(0, j, n) sum += m[j][i] * a[n - 1 - j]; if (i == n - 1) cout << a[0] << " "; else cout << sum % n << " "; } }
replace
357
359
357
358
-11
p02950
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 2e3 + 50; ll mod = 998244353; ll qm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod, b >>= 1; } return res; } ll a[maxn], b[maxn], c[maxn], temp[maxn]; ll x[maxn], y[maxn]; ll n; void mul(ll *f, int len, ll t) { // len为多项式的次数+1,函数让多项式f变成f*(x+t) for (int i = len; i > 0; --i) temp[i] = f[i], f[i] = f[i - 1]; temp[0] = f[0], f[0] = 0; for (int i = 0; i <= len; ++i) f[i] = (f[i] + t * temp[i] + mod) % mod; } void dev(ll *f, ll *r, ll t) { // f是被除多项式的系数,r保存f除以x+t的结果 for (int i = 0; i <= n; ++i) temp[i] = f[i]; for (int i = n; i > 0; --i) { r[i - 1] = temp[i]; temp[i - 1] = (temp[i - 1] - t * temp[i] + mod) % mod; } return; } void lglr() { memset(a, 0, sizeof a); b[1] = 1, b[0] = -x[1]; for (int i = 2; i <= n; ++i) { mul(b, i, -x[i]); } // 预处理(x-x1)*(x-x2)...*(x-xn) for (int i = 1; i <= n; ++i) { ll fz = 1; for (int j = 1; j <= n; ++j) { if (j == i) continue; fz = (fz * (x[i] - x[j]) + mod) % mod; } fz = qm(fz, mod - 2); fz = ((fz * y[i] % mod) + mod) % mod; // 得到多项式系数 dev(b, c, -x[i]); // 得到多项式,保存在b数组 for (int j = 0; j < n; ++j) a[j] = (a[j] + fz * c[j] + mod) % mod; } } int main() { cin >> n; mod = n; for (int i = 1; i <= n; ++i) { x[i] = i - 1; cin >> y[i]; } lglr(); for (int i = 0; i < n; i++) cout << a[i] << " "; }
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 3e3 + 50; ll mod = 998244353; ll qm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod, b >>= 1; } return res; } ll a[maxn], b[maxn], c[maxn], temp[maxn]; ll x[maxn], y[maxn]; ll n; void mul(ll *f, int len, ll t) { // len为多项式的次数+1,函数让多项式f变成f*(x+t) for (int i = len; i > 0; --i) temp[i] = f[i], f[i] = f[i - 1]; temp[0] = f[0], f[0] = 0; for (int i = 0; i <= len; ++i) f[i] = (f[i] + t * temp[i] + mod) % mod; } void dev(ll *f, ll *r, ll t) { // f是被除多项式的系数,r保存f除以x+t的结果 for (int i = 0; i <= n; ++i) temp[i] = f[i]; for (int i = n; i > 0; --i) { r[i - 1] = temp[i]; temp[i - 1] = (temp[i - 1] - t * temp[i] + mod) % mod; } return; } void lglr() { memset(a, 0, sizeof a); b[1] = 1, b[0] = -x[1]; for (int i = 2; i <= n; ++i) { mul(b, i, -x[i]); } // 预处理(x-x1)*(x-x2)...*(x-xn) for (int i = 1; i <= n; ++i) { ll fz = 1; for (int j = 1; j <= n; ++j) { if (j == i) continue; fz = (fz * (x[i] - x[j]) + mod) % mod; } fz = qm(fz, mod - 2); fz = ((fz * y[i] % mod) + mod) % mod; // 得到多项式系数 dev(b, c, -x[i]); // 得到多项式,保存在b数组 for (int j = 0; j < n; ++j) a[j] = (a[j] + fz * c[j] + mod) % mod; } } int main() { cin >> n; mod = n; for (int i = 1; i <= n; ++i) { x[i] = i - 1; cin >> y[i]; } lglr(); for (int i = 0; i < n; i++) cout << a[i] << " "; }
replace
3
4
3
4
0
p02950
Python
Time Limit Exceeded
p = int(input()) def div(a, b): n = len(a) m = len(b) res = [0] * (n - m + 1) tmp = pow(b[-1], p - 2, p) for i in range(n - m, -1, -1): t = a[i + m - 1] * tmp % p res[i] = t for j in range(m): a[i + j] = (a[i + j] - t * b[j]) % p return res a = list(map(int, input().split())) ans = [0] * p f = [0] * (p + 1) f[0] = 1 for i in range(p): for j in range(p, 0, -1): f[j] += f[j - 1] f[j - 1] = -f[j - 1] * i f[j] %= p for i in range(p): if a[i] == 1: fm = div(f[:], [-i, 1]) t = 1 r = 0 for v in fm: r += v * t t = t * i % p t = pow(r, p - 2, p) for j in range(len(fm)): ans[j] += fm[j] * t % p for i in range(p): ans[i] %= p print(" ".join(map(str, ans)))
p = int(input()) def div(a, b): n = len(a) m = len(b) res = [0] * (n - m + 1) tmp = pow(b[-1], p - 2, p) for i in range(n - m, -1, -1): t = a[i + m - 1] * tmp % p res[i] = t for j in range(m): a[i + j] = (a[i + j] - t * b[j]) % p return res a = list(map(int, input().split())) ans = [0] * p f = [0] * (p + 1) f[0] = 1 for i in range(p): for j in range(p, 0, -1): f[j] += f[j - 1] f[j - 1] = -f[j - 1] * i f[j] %= p for i in range(p): if a[i] == 1: fm = div(f[:], [-i, 1]) t = 1 r = 0 for v in fm: r += v * t t = t * i % p t = pow(r, p - 2, p) for j in range(len(fm)): ans[j] += fm[j] * t for i in range(p): ans[i] %= p print(" ".join(map(str, ans)))
replace
35
36
35
36
TLE
p02950
Python
Time Limit Exceeded
p = int(input()) a = list(map(int, input().split())) MOD = p MAX = p + 10 fact = [1] * (MAX + 1) # i! finv = [1] * (MAX + 1) # (i!)^{-1} iinv = [1] * (MAX + 1) # i^{-1} for i in range(2, MAX + 1): fact[i] = fact[i - 1] * i % MOD iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * iinv[i] % MOD def comb(n: int, k: int) -> int: if n < k or n < 0 or k < 0: return 0 return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD b = [0] * p for j in range(p): if a[j] == 1: b[0] += 1 for k in range(p): b[k] += comb(p - 1, k) * pow(j, p - 1 - k, MOD) * (-1) ** (p - k) b[k] %= MOD print(*b)
p = int(input()) a = list(map(int, input().split())) MOD = p MAX = p + 10 fact = [1] * (MAX + 1) # i! finv = [1] * (MAX + 1) # (i!)^{-1} iinv = [1] * (MAX + 1) # i^{-1} for i in range(2, MAX + 1): fact[i] = fact[i - 1] * i % MOD iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * iinv[i] % MOD def comb(n: int, k: int) -> int: if n < k or n < 0 or k < 0: return 0 return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD b = [0] * p for j in range(p): if a[j] == 1: b[0] += 1 for k in range(p): b[k] += comb(p - 1, k) * pow(j, p - 1 - k, MOD) * (-1) ** ((p - k) % 2) b[k] %= MOD print(*b)
replace
25
26
25
26
TLE
p02950
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; // #define int ll using PII = pair<ll, ll>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; } template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &a) { out << '(' << a.first << ',' << a.second << ')'; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> &a) { out << '['; for (const T &i : a) out << i << ','; out << ']'; return out; } template <class T> ostream &operator<<(ostream &out, const set<T> &a) { out << '{'; for (const T &i : a) out << i << ','; out << '}'; return out; } template <class T, class S> ostream &operator<<(ostream &out, const map<T, S> &a) { out << '{'; for (auto &i : a) out << i << ','; out << '}'; return out; } int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL const int INF = 1 << 30; const ll LLINF = 1LL << 60; // 実行時にmodを決定するmodint ll MOD; struct mint { ll x; mint() : x(0) {} mint(ll y) : x(y >= 0 ? y % MOD : y % MOD + MOD) {} // e乗 friend mint pow(mint p, ll e) { mint a(1); while (e > 0) { if (e % 2 == 0) { p = (p * p); e /= 2; } else { a = (a * p); e--; } } return a; } mint inv() const { ll a = x, b = MOD, u = 1, y = 1, v = 0, z = 0; while (a) { ll q = b / a; swap(z -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return z; } // Comparators bool operator!=(mint b) { return x != b.x; } bool operator==(mint b) { return x == b.x; } // Basic Operations mint operator+(mint r) const { return mint(*this) += r; } mint operator-(mint r) const { return mint(*this) -= r; } mint operator*(mint r) const { return mint(*this) *= r; } mint operator/(mint r) const { return mint(*this) /= r; } mint &operator+=(mint r) { if ((x += r.x) >= MOD) x -= MOD; return *this; } mint &operator-=(mint r) { if ((x -= r.x) < 0) x += MOD; return *this; } mint &operator*=(mint r) { #if !defined(_WIN32) || defined(_WIN64) x = x * r.x % MOD; return *this; #endif unsigned long long y = x * r.x; unsigned xh = (unsigned)(y >> 32), xl = (unsigned)y, d, m; asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(MOD)); x = m; return *this; } mint &operator/=(mint r) { return *this *= r.inv(); } template <class T> friend mint operator*(T l, mint r) { return mint(l) *= r; } template <class T> friend mint operator+(T l, mint r) { return mint(l) += r; } template <class T> friend mint operator-(T l, mint r) { return mint(l) -= r; } template <class T> friend mint operator/(T l, mint r) { return mint(l) /= r; } template <class T> friend bool operator==(T l, mint r) { return mint(l) == r; } template <class T> friend bool operator!=(T l, mint r) { return mint(l) != r; } // increment, decrement mint operator++() { x++; return *this; } mint operator++(signed) { mint t = *this; x++; return t; } mint operator--() { x--; return *this; } mint operator--(signed) { mint t = *this; x--; return t; } // Input/Output friend ostream &operator<<(ostream &os, mint a) { return os << a.x; } friend istream &operator>>(istream &is, mint &a) { return is >> a.x; } friend string to_frac(mint v) { static map<ll, PII> mp; if (mp.empty()) { mp[0] = mp[MOD] = {0, 1}; FOR(i, 2, 1001) FOR(j, 1, i) if (__gcd(i, j) == 1) { mp[(mint(i) / j).x] = {i, j}; } } auto itr = mp.lower_bound(v.x); if (itr != mp.begin() && v.x - prev(itr)->first < itr->first - v.x) --itr; string ret = to_string(itr->second.first + itr->second.second * ((int)v.x - itr->first)); if (itr->second.second > 1) { ret += '/'; ret += to_string(itr->second.second); } return ret; } }; // x座標が相異なるn+1点(x_i,y_i)を通るn次以下の多項式f(x)を返す // O(n^2) vector<mint> lagrange_interpolation(vector<mint> x, vector<mint> y) { const ll n = x.size() - 1; REP(i, n + 1) REP(j, n + 1) if (i != j) y[i] /= x[i] - x[j]; vector<vector<mint>> dp(n + 1, vector<mint>(n + 2)); dp[0][0] = -1 * x[0], dp[0][1] = 1; FOR(i, 1, n + 1) REP(j, n + 2) { dp[i][j] = dp[i - 1][j] * -1 * x[i]; if (j >= 1) dp[i][j] += dp[i - 1][j - 1]; } vector<mint> xinv(n + 1); REP(i, n + 1) xinv[i] = x[i].inv(); vector<mint> ret(n + 1); // f(x) REP(i, n + 1) { if (y[i] == 0) continue; // 0割り対策の場合分け if (x[i] == 0) { REP(j, n + 1) ret[j] += dp[n][j + 1] * y[i]; } else { ret[0] -= dp[n][0] * xinv[i] * y[i]; mint pre = -1 * dp[n][0] * xinv[i]; FOR(j, 1, n + 1) { ret[j] -= (dp[n][j] - pre) * xinv[i] * y[i]; pre = -1 * (dp[n][j] - pre) * xinv[i]; } } } return ret; } signed main(void) { cin.tie(0); ios::sync_with_stdio(false); ll p; cin >> p; MOD = p; vector<mint> y(p); REP(i, p) cin >> y[i]; vector<mint> x(p); REP(i, p) x[i] = i; auto ret = lagrange_interpolation(x, y); REP(i, p) cout << ret[i] << (i == p - 1 ? '\n' : ' '); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // #define int ll using PII = pair<ll, ll>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; } template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &a) { out << '(' << a.first << ',' << a.second << ')'; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> &a) { out << '['; for (const T &i : a) out << i << ','; out << ']'; return out; } template <class T> ostream &operator<<(ostream &out, const set<T> &a) { out << '{'; for (const T &i : a) out << i << ','; out << '}'; return out; } template <class T, class S> ostream &operator<<(ostream &out, const map<T, S> &a) { out << '{'; for (auto &i : a) out << i << ','; out << '}'; return out; } int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL const int INF = 1 << 30; const ll LLINF = 1LL << 60; // 実行時にmodを決定するmodint ll MOD; struct mint { ll x; mint() : x(0) {} mint(ll y) : x(y >= 0 ? y % MOD : y % MOD + MOD) {} // e乗 friend mint pow(mint p, ll e) { mint a(1); while (e > 0) { if (e % 2 == 0) { p = (p * p); e /= 2; } else { a = (a * p); e--; } } return a; } mint inv() const { ll a = x, b = MOD, u = 1, y = 1, v = 0, z = 0; while (a) { ll q = b / a; swap(z -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return z; } // Comparators bool operator!=(mint b) { return x != b.x; } bool operator==(mint b) { return x == b.x; } // Basic Operations mint operator+(mint r) const { return mint(*this) += r; } mint operator-(mint r) const { return mint(*this) -= r; } mint operator*(mint r) const { return mint(*this) *= r; } mint operator/(mint r) const { return mint(*this) /= r; } mint &operator+=(mint r) { if ((x += r.x) >= MOD) x -= MOD; return *this; } mint &operator-=(mint r) { if ((x -= r.x) < 0) x += MOD; return *this; } mint &operator*=(mint r) { #if !defined(_WIN32) || defined(_WIN64) x = x * r.x % MOD; return *this; #endif unsigned long long y = x * r.x; unsigned xh = (unsigned)(y >> 32), xl = (unsigned)y, d, m; asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(MOD)); x = m; return *this; } mint &operator/=(mint r) { return *this *= r.inv(); } template <class T> friend mint operator*(T l, mint r) { return mint(l) *= r; } template <class T> friend mint operator+(T l, mint r) { return mint(l) += r; } template <class T> friend mint operator-(T l, mint r) { return mint(l) -= r; } template <class T> friend mint operator/(T l, mint r) { return mint(l) /= r; } template <class T> friend bool operator==(T l, mint r) { return mint(l) == r; } template <class T> friend bool operator!=(T l, mint r) { return mint(l) != r; } // increment, decrement mint operator++() { x++; return *this; } mint operator++(signed) { mint t = *this; x++; return t; } mint operator--() { x--; return *this; } mint operator--(signed) { mint t = *this; x--; return t; } // Input/Output friend ostream &operator<<(ostream &os, mint a) { return os << a.x; } friend istream &operator>>(istream &is, mint &a) { return is >> a.x; } friend string to_frac(mint v) { static map<ll, PII> mp; if (mp.empty()) { mp[0] = mp[MOD] = {0, 1}; FOR(i, 2, 1001) FOR(j, 1, i) if (__gcd(i, j) == 1) { mp[(mint(i) / j).x] = {i, j}; } } auto itr = mp.lower_bound(v.x); if (itr != mp.begin() && v.x - prev(itr)->first < itr->first - v.x) --itr; string ret = to_string(itr->second.first + itr->second.second * ((int)v.x - itr->first)); if (itr->second.second > 1) { ret += '/'; ret += to_string(itr->second.second); } return ret; } }; // x座標が相異なるn+1点(x_i,y_i)を通るn次以下の多項式f(x)を返す // O(n^2) vector<mint> lagrange_interpolation(vector<mint> x, vector<mint> y) { const ll n = x.size() - 1; REP(i, n + 1) { mint t = 1; REP(j, n + 1) if (i != j) t *= x[i] - x[j]; y[i] /= t; } vector<vector<mint>> dp(n + 1, vector<mint>(n + 2)); dp[0][0] = -1 * x[0], dp[0][1] = 1; FOR(i, 1, n + 1) REP(j, n + 2) { dp[i][j] = dp[i - 1][j] * -1 * x[i]; if (j >= 1) dp[i][j] += dp[i - 1][j - 1]; } vector<mint> xinv(n + 1); REP(i, n + 1) xinv[i] = x[i].inv(); vector<mint> ret(n + 1); // f(x) REP(i, n + 1) { if (y[i] == 0) continue; // 0割り対策の場合分け if (x[i] == 0) { REP(j, n + 1) ret[j] += dp[n][j + 1] * y[i]; } else { ret[0] -= dp[n][0] * xinv[i] * y[i]; mint pre = -1 * dp[n][0] * xinv[i]; FOR(j, 1, n + 1) { ret[j] -= (dp[n][j] - pre) * xinv[i] * y[i]; pre = -1 * (dp[n][j] - pre) * xinv[i]; } } } return ret; } signed main(void) { cin.tie(0); ios::sync_with_stdio(false); ll p; cin >> p; MOD = p; vector<mint> y(p); REP(i, p) cin >> y[i]; vector<mint> x(p); REP(i, p) x[i] = i; auto ret = lagrange_interpolation(x, y); REP(i, p) cout << ret[i] << (i == p - 1 ? '\n' : ' '); return 0; }
replace
179
180
179
184
TLE
p02950
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define int long long using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef pair<int, int> pii; const int INF = 1l << 60; #define u_b upper_bound #define l_b lower_bound int P; int ans[3030]; // Σans[i]*x^i __inline int power(int a, int b, int p) { int res = 1; while (b) { if (b & 1) { res *= a; res %= p; } b >>= 1; a *= a; a %= p; } return res; } int fac[3030]; int fac_inv[3030]; void calc(int p) { fac[0] = 1; fac_inv[0] = 1; for (int i = 1; i < 3030; ++i) { fac[i] = fac[i - 1] * i; fac[i] %= p; fac_inv[i] = power(fac[i], p - 2, p); } } __inline int Comb(int n, int r, int p) { return fac[n] * fac_inv[r] % p * fac_inv[n - r] % p; } signed main() { cin >> P; calc(P); rep(i, P) { int a; cin >> a; if (a == 0) continue; ans[0] += 1; for (int j = 0; j < P; ++j) { ans[j] -= Comb(P - 1, j, P) * power(P - i, P - 1 - j, P); ans[j] %= P; } } rep(i, P) { ans[i] = ans[i] < 0 ? ans[i] + P : ans[i]; if (i) cout << " "; cout << ans[i]; } cout << endl; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef pair<int, int> pii; const int INF = 1l << 60; #define u_b upper_bound #define l_b lower_bound int P; int ans[3030]; // Σans[i]*x^i __inline int power(int a, int b, int p) { int res = 1; while (b) { if (b & 1) { res *= a; res %= p; } b >>= 1; a *= a; a %= p; } return res; } int fac[3030]; int fac_inv[3030]; void calc(int p) { fac[0] = 1; fac_inv[0] = 1; for (int i = 1; i < 3030; ++i) { fac[i] = fac[i - 1] * i; fac[i] %= p; fac_inv[i] = power(fac[i], p - 2, p); } } __inline int Comb(int n, int r, int p) { return fac[n] * fac_inv[r] * fac_inv[n - r]; } signed main() { cin >> P; calc(P); rep(i, P) { int a; cin >> a; if (a == 0) continue; ans[0] += 1; for (int j = 0; j < P; ++j) { ans[j] -= Comb(P - 1, j, P) * power(P - i, P - 1 - j, P); ans[j] %= P; } } rep(i, P) { ans[i] = ans[i] < 0 ? ans[i] + P : ans[i]; if (i) cout << " "; cout << ans[i]; } cout << endl; return 0; }
replace
41
42
41
42
TLE
p02951
C++
Runtime Error
#include "iostream" #include "stdio.h" using namespace std; int main() { int a, b, c; int ret = 0; cin >> a; cin >> b; cin >> c; if (c >= (a - b)) { ret = c - a + b; } else { ret = 0; } cout << ret; return ret; }
#include "iostream" #include "stdio.h" using namespace std; int main() { int a, b, c; int ret = 0; cin >> a; cin >> b; cin >> c; if (c >= (a - b)) { ret = c - a + b; } else { ret = 0; } cout << ret; return 0; }
replace
16
17
16
17
1
p02951
C++
Runtime Error
// Lets go to the next level // AIM CM at CF *__* asap // Hit A,B,C and D faster and reach Candidate Master // Remember you were also a novice when you started, // hence never be rude to anyone who wants to learn something // Never open a ranklist untill and unless you are done with solving problems, // wastes 3/4 minuts Donot treat CP as a placement thing, love it and enjoy it, // you will succeed for sure. #include <bits/stdc++.h> using namespace std; #define mod (int)1000000007 #define MOD (int)10000000007 // Big two primes #define X 1001100011100001111ll #define M 26388279066623ll #define all(a) a.begin(), a.end() #define for0(i, n) for (int i = 0; i < n; i++) #define for0e(i, n) for (int i = 0; i <= n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define loop(i, a, b) for (int i = a; i < b; i++) #define bloop(i, a, b) for (int i = a; i >= b; i--) #define tc(t) \ int t; \ cin >> t; \ while (t--) #define int long long #define ll long long #define pb emplace_back #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define in(x) scanf("%d", &x) #define rr return 0 #define prec(n) fixed << setprecision(n) #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int>> #define inf (int)(1e18) #define ini(a, i) memset(a, i, sizeof(a)) #define vi vector<int> #define F first #define S second #define pi pair<int, int> #define ppi pair<pair<int, int>, int> #define vii vector<pi> const int MAXN = (int)((1e5) + 100); int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a < b) return a; else return b; } int cbrt(int x) { int lo = 1, hi = min(2000000ll, x); while (hi - lo > 1) { int mid = (lo + hi) / 2; if (mid * mid * mid < x) { lo = mid; } else hi = mid; } if (hi * hi * hi <= x) return hi; else return lo; } const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const int N = (int)(1e6 + 5); signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fio; int a, b, c; cin >> a >> b >> c; // Transferring water from b to a int total_water = b + c; if (total_water < a) { cout << 0; } else { cout << abs(total_water - a); } rr; }
// Lets go to the next level // AIM CM at CF *__* asap // Hit A,B,C and D faster and reach Candidate Master // Remember you were also a novice when you started, // hence never be rude to anyone who wants to learn something // Never open a ranklist untill and unless you are done with solving problems, // wastes 3/4 minuts Donot treat CP as a placement thing, love it and enjoy it, // you will succeed for sure. #include <bits/stdc++.h> using namespace std; #define mod (int)1000000007 #define MOD (int)10000000007 // Big two primes #define X 1001100011100001111ll #define M 26388279066623ll #define all(a) a.begin(), a.end() #define for0(i, n) for (int i = 0; i < n; i++) #define for0e(i, n) for (int i = 0; i <= n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define loop(i, a, b) for (int i = a; i < b; i++) #define bloop(i, a, b) for (int i = a; i >= b; i--) #define tc(t) \ int t; \ cin >> t; \ while (t--) #define int long long #define ll long long #define pb emplace_back #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define in(x) scanf("%d", &x) #define rr return 0 #define prec(n) fixed << setprecision(n) #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int>> #define inf (int)(1e18) #define ini(a, i) memset(a, i, sizeof(a)) #define vi vector<int> #define F first #define S second #define pi pair<int, int> #define ppi pair<pair<int, int>, int> #define vii vector<pi> const int MAXN = (int)((1e5) + 100); int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a < b) return a; else return b; } int cbrt(int x) { int lo = 1, hi = min(2000000ll, x); while (hi - lo > 1) { int mid = (lo + hi) / 2; if (mid * mid * mid < x) { lo = mid; } else hi = mid; } if (hi * hi * hi <= x) return hi; else return lo; } const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const int N = (int)(1e6 + 5); signed main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif fio; int a, b, c; cin >> a >> b >> c; // Transferring water from b to a int total_water = b + c; if (total_water < a) { cout << 0; } else { cout << abs(total_water - a); } rr; }
replace
80
84
80
84
0
p02951
Python
Runtime Error
a, b, c = input().splita, b, c = [int(x) for x in input().strip().split()] water = c - (a - b) if water < 0: print(0) else: print(water)
a, b, c = [int(x) for x in input().strip().split()] water = c - (a - b) if water < 0: print(0) else: print(water)
replace
0
1
0
1
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02951/Python/s087836716.py", line 1, in <module> a, b, c = input().splita, b, c = [int(x) for x in input().strip().split()] EOFError: EOF when reading a line
p02951
Python
Runtime Error
a, b, c = map(int, input().split()) print(max(c - (a - b)), 0)
a, b, c = map(int, input().split()) print(max(c - (a - b), 0))
replace
1
2
1
2
TypeError: 'int' object is not iterable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02951/Python/s849480716.py", line 2, in <module> print(max(c - (a - b)), 0) TypeError: 'int' object is not iterable
p02951
Python
Runtime Error
A, B, C = map(int, input().split()) rest: int = C - (A - B) result: int = rest if rest >= 0 else 0 print(result)
A, B, C = map(int, input().split()) rest = C - (A - B) result = rest if rest >= 0 else 0 print(result)
replace
1
3
1
3
0
p02951
Python
Runtime Error
a, b, c = map(int, (input().split())) print(max(c - (a - b), 0)) a, b, c = map(int, (input().split())) print(max(c - (a - b), 0)) a, b, c = map(int, (input().split())) print(max(c - (a - b), 0)) a, b, c = map(int, (input().split())) print(max(c - (a - b), 0)) a, b, c = map(int, (input().split())) print(max(c - (a - b), 0)) a, b, c = map(int, (input().split())) print(max(c - (a - b), 0)) a, b, c = map(int, (input().split())) print(max(c - (a - b), 0)) a, b, c = map(int, (input().split())) print(max(c - (a - b), 0)) a, b, c = map(int, (input().split())) print(max(c - (a - b), 0)) a, b, c = map(int, (input().split())) print(max(c - (a - b), 0))
a, b, c = map(int, (input().split())) print(max(c - (a - b), 0))
delete
2
20
2
2
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02951/Python/s280962278.py", line 3, in <module> a, b, c = map(int, (input().split())) EOFError: EOF when reading a line
p02951
Python
Runtime Error
num = input().split() a = num[0] b = num[1] c = num[2] ans = b + c - a if ans > 0: print(ans) else: print(0)
num = input().split() a = int(num[0]) b = int(num[1]) c = int(num[2]) ans = b + c - a if ans > 0: print(ans) else: print(0)
replace
1
4
1
4
TypeError: unsupported operand type(s) for -: 'str' and 'str'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02951/Python/s319382696.py", line 5, in <module> ans = b + c - a TypeError: unsupported operand type(s) for -: 'str' and 'str'
p02951
Python
Runtime Error
i = list(map(int, input().split())) print(i[2] - (i[0] - i[1])) i = list(map(int, input().split())) n = i[2] - (i[0] - i[1]) if n > 0: print(n) else: print(0)
i = list(map(int, input().split())) n = i[2] - (i[0] - i[1]) if n > 0: print(n) else: print(0)
delete
0
2
0
0
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02951/Python/s799517998.py", line 3, in <module> i = list(map(int, input().split())) EOFError: EOF when reading a line
p02951
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define ll long long #define ld long double #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define umii unordered_map<int, int> #define pb push_back #define mk make_pair #define all(a) a.begin(), a.end() #define ask(x) cerr << #x << " = " << x << "\n"; #define INF 1000000007 #define hell 998244353 int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int a, b, c; cin >> a >> b >> c; cout << max(0, b + c - a); return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define ll long long #define ld long double #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define umii unordered_map<int, int> #define pb push_back #define mk make_pair #define all(a) a.begin(), a.end() #define ask(x) cerr << #x << " = " << x << "\n"; #define INF 1000000007 #define hell 998244353 int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int a, b, c; cin >> a >> b >> c; cout << max(0, b + c - a); return 0; }
replace
24
28
24
28
0
p02951
C++
Runtime Error
#include <iostream> #include <sstream> struct Scanner { std::string pp(const char ch) { if (ch == EOF) { return "EOF"; } else { return std::string(1, ch); } } void readSpace() { auto ch = getchar(); if (ch != ' ') { throw std::runtime_error(std::string("want: Space, got: ") + pp(ch)); } } void readNewline() { auto ch = getchar(); if (ch != '\n') { throw std::runtime_error(std::string("want: Newline, got: ") + pp(ch)); } } void readEof() { auto ch = getchar(); if (ch != EOF) { throw std::runtime_error(std::string("want: EOF, got: ") + pp(ch)); } } std::string readString() { std::string ret; char ch; while (ch = getchar(), ch != ' ' and ch != '\n' and ch != EOF) { ret += ch; } ungetc(ch, stdin); return ret; } template <typename T> T readInt(T lb, T ub) { char ch = getchar(); if ((not isdigit(ch)) and (ch != '-')) { ungetc(ch, stdin); throw std::runtime_error(std::string("want: [0-9\\-]+, got: ") + pp(ch)); } T ret = ch == '-' ? 0 : ch - '0'; int sgn = ch == '-' ? -1 : +1; while (isdigit(ch = getchar())) { ret = ret * 10 + (ch - '0'); } ungetc(ch, stdin); ret *= sgn; if (not(lb <= ret and ret <= ub)) { std::ostringstream os; os << ret << " is not in [" << lb << ", " << ub << "]"; throw std::runtime_error(os.str()); } return ret; } }; using namespace std; int main() { Scanner sc; auto a = sc.readInt<int>(1, 20); sc.readSpace(); auto b = sc.readInt<int>(1, a); sc.readSpace(); auto c = sc.readInt<int>(1, 20); // sc.readNewline(); sc.readEof(); cout << max(0, c - (a - b)) << endl; return 0; }
#include <iostream> #include <sstream> struct Scanner { std::string pp(const char ch) { if (ch == EOF) { return "EOF"; } else { return std::string(1, ch); } } void readSpace() { auto ch = getchar(); if (ch != ' ') { throw std::runtime_error(std::string("want: Space, got: ") + pp(ch)); } } void readNewline() { auto ch = getchar(); if (ch != '\n') { throw std::runtime_error(std::string("want: Newline, got: ") + pp(ch)); } } void readEof() { auto ch = getchar(); if (ch != EOF) { throw std::runtime_error(std::string("want: EOF, got: ") + pp(ch)); } } std::string readString() { std::string ret; char ch; while (ch = getchar(), ch != ' ' and ch != '\n' and ch != EOF) { ret += ch; } ungetc(ch, stdin); return ret; } template <typename T> T readInt(T lb, T ub) { char ch = getchar(); if ((not isdigit(ch)) and (ch != '-')) { ungetc(ch, stdin); throw std::runtime_error(std::string("want: [0-9\\-]+, got: ") + pp(ch)); } T ret = ch == '-' ? 0 : ch - '0'; int sgn = ch == '-' ? -1 : +1; while (isdigit(ch = getchar())) { ret = ret * 10 + (ch - '0'); } ungetc(ch, stdin); ret *= sgn; if (not(lb <= ret and ret <= ub)) { std::ostringstream os; os << ret << " is not in [" << lb << ", " << ub << "]"; throw std::runtime_error(os.str()); } return ret; } }; using namespace std; int main() { Scanner sc; auto a = sc.readInt<int>(1, 20); sc.readSpace(); auto b = sc.readInt<int>(1, a); sc.readSpace(); auto c = sc.readInt<int>(1, 20); sc.readNewline(); sc.readEof(); cout << max(0, c - (a - b)) << endl; return 0; }
replace
67
68
67
68
-6
terminate called after throwing an instance of 'std::runtime_error' what(): want: EOF, got:
p02951
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define forn(i, _n) for (int i = 0; i <= (_n); ++i) #define forab(i, _a, _b) for (int i = (_a); i <= (_b); ++i) #define forrn(i, _n) for (int i = n - 1; i >= 0; --i) #define forrab(i, _a, _b) for (int i = _a; i >= b; --i) #define tcase \ int t; \ cin >> t; \ while (t--) #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef set<int> si; typedef map<string, int> msi; typedef map<int, int> mii; int mod = pow(10, 9) + 7; int n, a, b, c; void solve() { cin >> a >> b >> c; int x = c - a + b; if (x > 0) cout << x << endl; else cout << 0 << endl; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio solve(); }
#include <bits/stdc++.h> using namespace std; #define int long long #define forn(i, _n) for (int i = 0; i <= (_n); ++i) #define forab(i, _a, _b) for (int i = (_a); i <= (_b); ++i) #define forrn(i, _n) for (int i = n - 1; i >= 0; --i) #define forrab(i, _a, _b) for (int i = _a; i >= b; --i) #define tcase \ int t; \ cin >> t; \ while (t--) #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef set<int> si; typedef map<string, int> msi; typedef map<int, int> mii; int mod = pow(10, 9) + 7; int n, a, b, c; void solve() { cin >> a >> b >> c; int x = c - a + b; if (x > 0) cout << x << endl; else cout << 0 << endl; } int32_t main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif fastio solve(); }
replace
32
36
32
36
0
p02951
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N = S.size(); vector<int> A(N, 1); vector<int> B(N, 0); vector<int> C(N, 0); for (int i = 0; i < pow(10, 4); i++) { for (int j = 0; j < N; j++) { if (S.at(j) == 'R') B.at(j + 1) += A.at(j); else B.at(j - 1) += A.at(j); } A = B; B = C; } for (int i = 0; i < N; i++) { cout << A.at(i) << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int c, a, b; cin >> a >> b >> c; cout << max(c - a + b, 0) << endl; }
replace
4
26
4
7
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 1)
p02951
C++
Runtime Error
/*_BELIEVE_*/ // CF,CC,AtC,SPOJ: hp1999 // HE: hemant269 // HR: hemant2132 #include <bits/stdc++.h> using namespace std; #define int long long int #define fast() \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define all(x) x.begin(), x.end() #define mem(a, b) memset(a, b, sizeof(a)) #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define pb push_back #define ins insert #define F first #define S second const int inf = 1e18, M = 1e9 + 7; const int N = 1; void solve() { int a, b, c; cin >> a >> b >> c; cout << max(c - (a - b), 0ll); } int32_t main() { fast(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt","w",stdout); // #else #endif int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
/*_BELIEVE_*/ // CF,CC,AtC,SPOJ: hp1999 // HE: hemant269 // HR: hemant2132 #include <bits/stdc++.h> using namespace std; #define int long long int #define fast() \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define all(x) x.begin(), x.end() #define mem(a, b) memset(a, b, sizeof(a)) #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define pb push_back #define ins insert #define F first #define S second const int inf = 1e18, M = 1e9 + 7; const int N = 1; void solve() { int a, b, c; cin >> a >> b >> c; cout << max(c - (a - b), 0ll); } int32_t main() { fast(); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
delete
35
41
35
35
0
p02951
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define vi vector<int> #define vc vector<char> #define vt vector<string> #define si set<int> #define sc set<char> #define st set<string> #define pii pair<int, int> #define fi first #define se second #define pb pushback; using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << (c % (a - b)); return 0; }
#include <bits/stdc++.h> #define ll long long #define vi vector<int> #define vc vector<char> #define vt vector<string> #define si set<int> #define sc set<char> #define st set<string> #define pii pair<int, int> #define fi first #define se second #define pb pushback; using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << ((c <= (a - b)) ? 0 : c - (a - b)); return 0; }
replace
18
19
18
19
0
p02951
C++
Runtime Error
#include <algorithm> #include <chrono> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> #define pii pair<int, int> #define vi vector<int> #define ll long long #define pb push_back #define mp make_pair #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define repf(i, st, end, inc) for (int i = st; i < end; i += inc) #define repb(i, st, end, dec) for (int i = st; i >= end; i -= dec) #define MOD 1000000007 #define trace1(a) cout << a << endl; #define trace2(a, b) cout << a << " | " << b << endl; #define trace3(a, b, c) cout << a << " | " << b << " | " << c << endl; #define trace4(a, b, c, d) \ cout << a << " | " << b << " | " << c << " | " << d << endl; using namespace std; using namespace std::chrono; int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif auto start = high_resolution_clock::now(); int a, b, c; cin >> a >> b >> c; int space = a - b; int rem = c - space; cout << max(0, rem); auto stop = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stop - start); // cout << endl; // cout << double(duration.count()) / 1000000 << endl; return 0; }
#include <algorithm> #include <chrono> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> #define pii pair<int, int> #define vi vector<int> #define ll long long #define pb push_back #define mp make_pair #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define repf(i, st, end, inc) for (int i = st; i < end; i += inc) #define repb(i, st, end, dec) for (int i = st; i >= end; i -= dec) #define MOD 1000000007 #define trace1(a) cout << a << endl; #define trace2(a, b) cout << a << " | " << b << endl; #define trace3(a, b, c) cout << a << " | " << b << " | " << c << endl; #define trace4(a, b, c, d) \ cout << a << " | " << b << " | " << c << " | " << d << endl; using namespace std; using namespace std::chrono; int main() { fast; // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif auto start = high_resolution_clock::now(); int a, b, c; cin >> a >> b >> c; int space = a - b; int rem = c - space; cout << max(0, rem); auto stop = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stop - start); // cout << endl; // cout << double(duration.count()) / 1000000 << endl; return 0; }
replace
41
45
41
45
0
p02951
C++
Runtime Error
#include <bits/stdc++.h> #define range 524289 #define mod 1000000007 #define eps 1e-9 #define PI 3.14159265358979323846 #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define ALL(V) V.begin(), V.end() #define _ << " " << using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef pair<int, pair<int, int>> iii; typedef vector<ii> vii; typedef vector<iii> viii; int main(int argc, char const *argv[]) { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, l; cin >> n >> m >> l; cout << max(0, l - (n - m)) << endl; return 0; }
#include <bits/stdc++.h> #define range 524289 #define mod 1000000007 #define eps 1e-9 #define PI 3.14159265358979323846 #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define ALL(V) V.begin(), V.end() #define _ << " " << using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef pair<int, pair<int, int>> iii; typedef vector<ii> vii; typedef vector<iii> viii; int main(int argc, char const *argv[]) { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, l; cin >> n >> m >> l; cout << max(0, l - (n - m)) << endl; return 0; }
replace
25
29
25
29
0
p02951
C++
Runtime Error
// TOPSIC001_0 #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<ll, ll> pll; typedef int _loop_int; #define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i) #define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i) #define FORR(i, a, b) \ for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i) #define DEBUG(x) cout << #x << ": " << x << endl #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << " " << v[i]; \ cout << endl #define ALL(a) (a).begin(), (a).end() #define CHMIN(a, b) a = min((a), (b)) #define CHMAX(a, b) a = max((a), (b)) // mod const ll MOD = 1000000007ll; #define FIX(a) ((a) % MOD + MOD) % MOD // floating typedef double Real; const Real EPS = 1e-11; #define EQ0(x) (abs(x) < EPS) #define EQ(a, b) (abs(a - b) < EPS) typedef complex<Real> P; int main() { int A, B, C; cin >> A >> B >> C; return C - (A - B); }
// TOPSIC001_0 #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<ll, ll> pll; typedef int _loop_int; #define REP(i, n) for (_loop_int i = 0; i < (_loop_int)(n); ++i) #define FOR(i, a, b) for (_loop_int i = (_loop_int)(a); i < (_loop_int)(b); ++i) #define FORR(i, a, b) \ for (_loop_int i = (_loop_int)(b)-1; i >= (_loop_int)(a); --i) #define DEBUG(x) cout << #x << ": " << x << endl #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << " " << v[i]; \ cout << endl #define ALL(a) (a).begin(), (a).end() #define CHMIN(a, b) a = min((a), (b)) #define CHMAX(a, b) a = max((a), (b)) // mod const ll MOD = 1000000007ll; #define FIX(a) ((a) % MOD + MOD) % MOD // floating typedef double Real; const Real EPS = 1e-11; #define EQ0(x) (abs(x) < EPS) #define EQ(a, b) (abs(a - b) < EPS) typedef complex<Real> P; int main() { int A, B, C; cin >> A >> B >> C; int ans = C - (A - B); if (ans < 0) ans = 0; cout << ans; }
replace
43
44
43
48
1
p02951
C++
Runtime Error
#ifndef BZ #pragma GCC optimize "-O3" #endif #include <bits/stdc++.h> typedef long long int lli; typedef unsigned long long int ulli; typedef long double ldb; #define pb push_back #define popb pop_back #define si size() #define be begin() #define en end() #define all(v) v.be, v.en #define le length() #define mp make_pair #define mt make_tuple #define F first #define S second #define forz(i, n) for (int i = 0; i < n; i++) #define bui(i, m, n) for (int i = m; i < n; i++) #define rforz(i, n) for (int i = n - 1; i >= 0; i--) #define mui(i, m, n) for (int i = n - 1; i >= m; i--) #define deci(n) fixed << setprecision(n) #define high(n) __builtin_popcount(n) #define parity(n) __builtin_parity(n) #define ctz(n) __builtin_ctz(n) #define lb lower_bound #define ub upper_bound #define er equal_range #define maxe *max_element #define mine *min_element #define mod 1000000007 #define mod2 998244353 #define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define endl "\n" #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl lli power(lli x, lli y, lli p) { lli res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; // y must be even now y = y >> 1; // y=y/2 x = (x * x) % p; } return res; } lli gcd(lli a, lli b) { if (b == 0) return a; return gcd(b, a % b); } lli lcm(lli a, lli b) { return a * b / gcd(a, b); } lli max(lli a, lli b) { if (a > b) return a; return b; } lli min(lli a, lli b) { if (a < b) return a; return b; } using namespace std; int main() { kira; freopen("input.txt", "r", stdin); lli a, b, c; cin >> a >> b >> c; lli p = a - b; if (c >= p) cout << c - p << endl; else cout << 0 << endl; }
#ifndef BZ #pragma GCC optimize "-O3" #endif #include <bits/stdc++.h> typedef long long int lli; typedef unsigned long long int ulli; typedef long double ldb; #define pb push_back #define popb pop_back #define si size() #define be begin() #define en end() #define all(v) v.be, v.en #define le length() #define mp make_pair #define mt make_tuple #define F first #define S second #define forz(i, n) for (int i = 0; i < n; i++) #define bui(i, m, n) for (int i = m; i < n; i++) #define rforz(i, n) for (int i = n - 1; i >= 0; i--) #define mui(i, m, n) for (int i = n - 1; i >= m; i--) #define deci(n) fixed << setprecision(n) #define high(n) __builtin_popcount(n) #define parity(n) __builtin_parity(n) #define ctz(n) __builtin_ctz(n) #define lb lower_bound #define ub upper_bound #define er equal_range #define maxe *max_element #define mine *min_element #define mod 1000000007 #define mod2 998244353 #define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define endl "\n" #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl lli power(lli x, lli y, lli p) { lli res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; // y must be even now y = y >> 1; // y=y/2 x = (x * x) % p; } return res; } lli gcd(lli a, lli b) { if (b == 0) return a; return gcd(b, a % b); } lli lcm(lli a, lli b) { return a * b / gcd(a, b); } lli max(lli a, lli b) { if (a > b) return a; return b; } lli min(lli a, lli b) { if (a < b) return a; return b; } using namespace std; int main() { kira; // freopen("input.txt","r",stdin); lli a, b, c; cin >> a >> b >> c; lli p = a - b; if (c >= p) cout << c - p << endl; else cout << 0 << endl; }
replace
77
78
77
78
0
p02951
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; while (a != b || c != 0) { b++; c--; } cout << c << endl; return 0; }
#include <iostream> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; if (a - b > 0) { c = c - (a - b); } if (c < 0) { c = 0; } cout << c << endl; return 0; }
replace
7
10
7
12
TLE
p02951
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; return max(c - (a - b), 0); }
#include <iostream> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << max(c - a + b, 0); return 0; }
replace
6
7
6
8
1
p02951
C++
Runtime Error
// This is getting accepted! #include <bits/stdc++.h> #define ll long long #define oo 1000000009 #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define INARR(a, n) \ for (int i = 1; i <= (n); ++i) \ cin >> a[i]; #define ITE(x) for (auto it = (x).begin(); it != (x).end(); ++it) #define isset(x, i) (((x) >> (i)) & 1) #define setbit(x, i) ((x) ^ (1ll << (i))) #define clearbit(x, i) ((x) & (~(1ll << (i)))) #define twoexp(i) (1ll << (i)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define FI first #define SE second #define son1 (id * 2) #define son2 (id * 2 + 1) using namespace std; const int MOD = 1000000007; const double EPS = 1e-8; const double PI = 2 * acos(0); const int MAXN = 1e6 + 6; int a, b, c; void input() { int u, v, w, x, y, qtype; cin >> a >> b >> c; } void preprocess() {} void process(int itest) { int u, v, w, x, y, qtype; cout << max(c - (a - b), 0) << endl; } void oneTest() { input(); preprocess(); process(0); } void multiTest() { int t; cin >> t; for (int it = 1; it <= t; ++it) { input(); preprocess(); process(it); } } int main() { #ifndef ONLINE_JUDGE freopen("../inp.txt", "r", stdin); // freopen("../out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); oneTest(); // multiTest(); return 0; }
// This is getting accepted! #include <bits/stdc++.h> #define ll long long #define oo 1000000009 #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define INARR(a, n) \ for (int i = 1; i <= (n); ++i) \ cin >> a[i]; #define ITE(x) for (auto it = (x).begin(); it != (x).end(); ++it) #define isset(x, i) (((x) >> (i)) & 1) #define setbit(x, i) ((x) ^ (1ll << (i))) #define clearbit(x, i) ((x) & (~(1ll << (i)))) #define twoexp(i) (1ll << (i)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define FI first #define SE second #define son1 (id * 2) #define son2 (id * 2 + 1) using namespace std; const int MOD = 1000000007; const double EPS = 1e-8; const double PI = 2 * acos(0); const int MAXN = 1e6 + 6; int a, b, c; void input() { int u, v, w, x, y, qtype; cin >> a >> b >> c; } void preprocess() {} void process(int itest) { int u, v, w, x, y, qtype; cout << max(c - (a - b), 0) << endl; } void oneTest() { input(); preprocess(); process(0); } void multiTest() { int t; cin >> t; for (int it = 1; it <= t; ++it) { input(); preprocess(); process(it); } } int main() { #ifndef ONLINE_JUDGE // freopen("../inp.txt", "r", stdin); // freopen("../out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); oneTest(); // multiTest(); return 0; }
replace
64
65
64
65
0
p02951
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; //**************************************************** #define lp(var, start, end) for (ll var = start; var < end; ++var) #define rlp(var, start, end) for (ll var = start; var >= end; var--) #define pb push_back #define mp make_pair #define pf push_front #define ff first #define ss second #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define all(X) X.begin(), X.end() #define endl "\n" // comment it for interactive questions #define trace1(a) cerr << #a << ": " << a << endl; #define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl; #define trace3(a, b, c) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << #d << ": " << d << endl; #define MOD (ll)1e9 + 7; // change it for other mods #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) //******************************************************* // Some Functions ll powmod(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b = b >> 1; } return res % MOD; } int main() { FAST_IO; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll a, b, c; cin >> a >> b >> c; if (c - (a - b) < 0) cout << "0\n"; else cout << c - (a - b) << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; //**************************************************** #define lp(var, start, end) for (ll var = start; var < end; ++var) #define rlp(var, start, end) for (ll var = start; var >= end; var--) #define pb push_back #define mp make_pair #define pf push_front #define ff first #define ss second #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define all(X) X.begin(), X.end() #define endl "\n" // comment it for interactive questions #define trace1(a) cerr << #a << ": " << a << endl; #define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl; #define trace3(a, b, c) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << #d << ": " << d << endl; #define MOD (ll)1e9 + 7; // change it for other mods #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) //******************************************************* // Some Functions ll powmod(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b = b >> 1; } return res % MOD; } int main() { ll a, b, c; cin >> a >> b >> c; if (c - (a - b) < 0) cout << "0\n"; else cout << c - (a - b) << "\n"; }
delete
50
55
50
50
0
p02951
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int A, B, C, rest; cin >> A >> B >> C; rest = A - B; C = C - rest; if (C <= 0) { return 0; } return C; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B, C, rest; cin >> A >> B >> C; rest = A - B; C = C - rest; if (C <= 0) { cout << 0; } else cout << C; }
replace
10
13
10
13
1
p02952
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // Optimisations #pragma GCC target("avx2") #pragma GCC optimization("unroll-loops") #pragma GCC optimize("O2") // shortcuts for functions #define pb push_back #define mp make_pair #define ff first #define ss second #define endl "\n" #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define th(n) cout << n << endl #define gc getchar_unlocked #define ms(s, n) memset(s, n, sizeof(s)) #define prec(n) fixed << setprecision(n) #define n_l '\n' // make it python #define gcd __gcd #define append push_back #define str to_string #define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper) #define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower) #define print(arr) \ for (auto el : arr) \ cout << el << " "; \ cout << endl // utility functions shortcuts #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define sswap(a, b) \ { \ a = a ^ b; \ b = a ^ b; \ a = a ^ b; \ } #define swap(a, b) \ { \ auto temp = a; \ a = b; \ b = temp; \ } #define init(dp) memset(dp, -1, sizeof(dp)); #define set0(dp) memset(dp, 0, sizeof(dp)); #define bits(x) __builtin_popcount(x) #define SORT(v) sort(all(v)) #define endl "\n" #define forr(i, n) for (ll i = 0; i < n; i++) #define formatrix(i, n) for (ll i = 0; i < n; i++, cout << "\n") #define eof (scanf("%d", &n)) != EOF // declaration shortcuts #define vi vector<int> #define vll vector<ll> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define pll pair<ll, ll> #define ppl pair<ll, pp> #define ull unsigned long long #define ll long long #define mll map<ll, ll> #define sll set<ll> #define uni(v) v.erase(unique(v.begin(), v.end()), v.end()); #define ini(a, v) memset(a, v, sizeof(a)) // Constants constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1}; constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1}; constexpr ll INF = 1999999999999999997; constexpr int inf = INT_MAX; constexpr int MAXSIZE = int(1e6) + 5; constexpr auto PI = 3.14159265358979323846L; constexpr auto oo = numeric_limits<int>::max() / 2 - 2; constexpr auto eps = 1e-6; constexpr auto mod = 1000000007; constexpr auto MOD = 1000000007; constexpr auto MOD9 = 1000000009; constexpr auto maxn = 1006; // Debugging // For reference: https://codeforces.com/blog/entry/65311 #define dbg(...) \ cout << "[" << #__VA_ARGS__ << "]: "; \ cout << to_string(__VA_ARGS__) << endl template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template <typename T> int SIZE(const T &t) { return t.size(); } string to_string(string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(char c) { return string({c}); } template <size_t N> string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(A(&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(A(&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += n_l; return res; } void dbgs() { ; } template <typename Heads, typename... Tails> void dbgs(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgs(T...); } #define dbgm(...) \ cout << "[" << #__VA_ARGS__ << "]: "; \ dbgs(__VA_ARGS__); \ cout << endl; #define n_l '\n' ll dp[2][maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; string s = to_string(n); ll sz = s.size(); if (sz % 2 == 0) { for (int i = 0; i < sz - 1; i++) { if (i % 2 == 0) cout << "9"; else cout << "0"; } return 0; } string evenhighest = ""; for (int i = 0; i < sz - 1; i++) evenhighest += '9'; if (sz == 1) evenhighest = "0"; ll ehighest = stoll(evenhighest); ll ans = n - ehighest; evenhighest = ""; for (int i = 0; i < sz - 2; i++) if (i % 2 == 0) evenhighest += '9'; else evenhighest += '0'; if (sz == 2) evenhighest = "0"; ehighest = stoll(evenhighest); ans += ehighest; th(ans); // dbg(s); }
#include <bits/stdc++.h> using namespace std; // Optimisations #pragma GCC target("avx2") #pragma GCC optimization("unroll-loops") #pragma GCC optimize("O2") // shortcuts for functions #define pb push_back #define mp make_pair #define ff first #define ss second #define endl "\n" #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define th(n) cout << n << endl #define gc getchar_unlocked #define ms(s, n) memset(s, n, sizeof(s)) #define prec(n) fixed << setprecision(n) #define n_l '\n' // make it python #define gcd __gcd #define append push_back #define str to_string #define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper) #define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower) #define print(arr) \ for (auto el : arr) \ cout << el << " "; \ cout << endl // utility functions shortcuts #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define sswap(a, b) \ { \ a = a ^ b; \ b = a ^ b; \ a = a ^ b; \ } #define swap(a, b) \ { \ auto temp = a; \ a = b; \ b = temp; \ } #define init(dp) memset(dp, -1, sizeof(dp)); #define set0(dp) memset(dp, 0, sizeof(dp)); #define bits(x) __builtin_popcount(x) #define SORT(v) sort(all(v)) #define endl "\n" #define forr(i, n) for (ll i = 0; i < n; i++) #define formatrix(i, n) for (ll i = 0; i < n; i++, cout << "\n") #define eof (scanf("%d", &n)) != EOF // declaration shortcuts #define vi vector<int> #define vll vector<ll> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define pll pair<ll, ll> #define ppl pair<ll, pp> #define ull unsigned long long #define ll long long #define mll map<ll, ll> #define sll set<ll> #define uni(v) v.erase(unique(v.begin(), v.end()), v.end()); #define ini(a, v) memset(a, v, sizeof(a)) // Constants constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1}; constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1}; constexpr ll INF = 1999999999999999997; constexpr int inf = INT_MAX; constexpr int MAXSIZE = int(1e6) + 5; constexpr auto PI = 3.14159265358979323846L; constexpr auto oo = numeric_limits<int>::max() / 2 - 2; constexpr auto eps = 1e-6; constexpr auto mod = 1000000007; constexpr auto MOD = 1000000007; constexpr auto MOD9 = 1000000009; constexpr auto maxn = 1006; // Debugging // For reference: https://codeforces.com/blog/entry/65311 #define dbg(...) \ cout << "[" << #__VA_ARGS__ << "]: "; \ cout << to_string(__VA_ARGS__) << endl template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template <typename T> int SIZE(const T &t) { return t.size(); } string to_string(string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(char c) { return string({c}); } template <size_t N> string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(A(&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(A(&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += n_l; return res; } void dbgs() { ; } template <typename Heads, typename... Tails> void dbgs(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgs(T...); } #define dbgm(...) \ cout << "[" << #__VA_ARGS__ << "]: "; \ dbgs(__VA_ARGS__); \ cout << endl; #define n_l '\n' ll dp[2][maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; string s = to_string(n); ll sz = s.size(); if (sz % 2 == 0) { for (int i = 0; i < sz - 1; i++) { if (i % 2 == 0) cout << "9"; else cout << "0"; } return 0; } if (n < 10) { cout << n << endl; return 0; } string evenhighest = ""; for (int i = 0; i < sz - 1; i++) evenhighest += '9'; if (sz == 1) evenhighest = "0"; ll ehighest = stoll(evenhighest); ll ans = n - ehighest; evenhighest = ""; for (int i = 0; i < sz - 2; i++) if (i % 2 == 0) evenhighest += '9'; else evenhighest += '0'; if (sz == 2) evenhighest = "0"; ehighest = stoll(evenhighest); ans += ehighest; th(ans); // dbg(s); }
insert
172
172
172
176
0
p02952
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int a, c = 0; scanf("%d", &a); for (int i = 1; i <= a; i++) { int b = 0; int t = i; while (t) { b++; t / 10; } if (b % 2 == 1) { c++; } } printf("%d", c); }
#include <bits/stdc++.h> using namespace std; int main() { int a, c = 0; scanf("%d", &a); for (int i = 1; i <= a; i++) { int b = 0; int t = i; while (t) { b++; t = t / 10; } if (b % 2 == 1) { c++; } } printf("%d", c); }
replace
10
11
10
11
TLE
p02952
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s = to_string(n); int ct = s.size(); int res = 0; if (ct & 1) { string tmp = ""; for (int i = 0; i < ct - 1; ++i) tmp += '9'; ct -= 2; res += n - stoi(tmp); } else { ct--; } for (int i = 1; i <= ct; i += 2) { res += pow(10, i - 1) * 9; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s = to_string(n); int ct = s.size(); int res = 0; if (ct == 1) { cout << n << endl; return 0; } if (ct & 1) { string tmp = ""; for (int i = 0; i < ct - 1; ++i) tmp += '9'; ct -= 2; res += n - stoi(tmp); } else { ct--; } for (int i = 1; i <= ct; i += 2) { res += pow(10, i - 1) * 9; } cout << res << endl; }
insert
9
9
9
13
0
p02952
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int ans = 0; int digit = 0; for (int i = 1; i <= N; i++) { digit = 0; int a = i; while (a != 0) { digit++; a / (10); if (a == 0) { break; } } if (digit % 2 == 1) { ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int ans = 0; int digit = 0; for (int i = 1; i <= N; i++) { digit = 0; int a = i; while (a != 0) { digit++; a /= (10); } if (digit % 2 == 1) { ans++; } } cout << ans << endl; }
replace
13
17
13
14
TLE
p02952
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; using ll = long long; // inf constexpr ll infl = 10000000000000000LL; constexpr int inf = 1000000000; int main() { int n; int cnt = 0; for (int i = 1; i <= n; ++i) { int d = 0; int t = i; while (t) { ++d; t /= 10; } if (d & 1) ++cnt; } cout << cnt << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; using ll = long long; // inf constexpr ll infl = 10000000000000000LL; constexpr int inf = 1000000000; int main() { int n; cin >> n; int cnt = 0; for (int i = 1; i <= n; ++i) { int d = 0; int t = i; while (t) { ++d; t /= 10; } if (d & 1) ++cnt; } cout << cnt << endl; return 0; }
insert
20
20
20
21
TLE
p02952
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int ten(int n) { int ret = 1; for (int i = 0; i < n; ++i) { ret *= 10; } return ret; } int main() { string n; cin >> n; int ans = 0; int m = n.size(); if (n.size() % 2 == 1) { ans += stoi(n); string t(m - 1, '9'); ans -= stoi(t); --m; } while (m > 0) { if (m % 2 == 1) ans += 9 * ten(m - 1); --m; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int ten(int n) { int ret = 1; for (int i = 0; i < n; ++i) { ret *= 10; } return ret; } int main() { string n; cin >> n; if (n.size() == 1) { cout << n[0] - '0' << endl; return 0; } int ans = 0; int m = n.size(); if (n.size() % 2 == 1) { ans += stoi(n); string t(m - 1, '9'); ans -= stoi(t); --m; } while (m > 0) { if (m % 2 == 1) ans += 9 * ten(m - 1); --m; } cout << ans << endl; return 0; }
insert
15
15
15
19
0
p02952
C++
Time Limit Exceeded
// // main.cpp // test // // Created by 田宇航 on 2019/8/4. // Copyright © 2019 田宇航. All rights reserved. // #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <stack> #include <string> using namespace std; #define INF 0x3f3f3f3f #define MAXN 100000 + 50 #define MAXM 30000 #define ll long long #define rep(i, n, m) for (int i = n; i <= m; ++i) #define mod 1000000000 + 7 #define mian main #define mem(a, b) memset(a, b, sizeof a) #ifndef ONLINE_JUDGE #define dbg(x) cout << #x << "=" << x << endl; #else #define dbg(x) #endif 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 = 10 * x + ch - '0'; ch = getchar(); } return x * f; } int s[] = {0, 9, 0, 900, 0, 90000, 0, 9000000}; int main() { int T = read(); while (T--) { int n = read(); int num = n / 10; int sum = 0; if (num == 0) sum = n; else { // 100 200 300 num = n; int num_d = 0; while (num) { num /= 10; num_d++; } for (int i = 1; i < num_d; ++i) sum += s[i]; int st = 1; rep(i, 1, num_d - 1) st *= 10; if (num_d & 1) { sum += (n - st + 1); } } cout << sum << endl; } } // 100-999 99999-10000 90000
// // main.cpp // test // // Created by 田宇航 on 2019/8/4. // Copyright © 2019 田宇航. All rights reserved. // #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <stack> #include <string> using namespace std; #define INF 0x3f3f3f3f #define MAXN 100000 + 50 #define MAXM 30000 #define ll long long #define rep(i, n, m) for (int i = n; i <= m; ++i) #define mod 1000000000 + 7 #define mian main #define mem(a, b) memset(a, b, sizeof a) #ifndef ONLINE_JUDGE #define dbg(x) cout << #x << "=" << x << endl; #else #define dbg(x) #endif 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 = 10 * x + ch - '0'; ch = getchar(); } return x * f; } int s[] = {0, 9, 0, 900, 0, 90000, 0, 9000000}; int main() { int T = 1; while (T--) { int n = read(); int num = n / 10; int sum = 0; if (num == 0) sum = n; else { // 100 200 300 num = n; int num_d = 0; while (num) { num /= 10; num_d++; } for (int i = 1; i < num_d; ++i) sum += s[i]; int st = 1; rep(i, 1, num_d - 1) st *= 10; if (num_d & 1) { sum += (n - st + 1); } } cout << sum << endl; } } // 100-999 99999-10000 90000
replace
44
45
44
45
TLE
p02952
Python
Runtime Error
def fn(i): return (1 <= i and i <= 9) or (100 <= i and i <= 999) or (10000 <= i and i <= 99999) def main(): n = int(input()) x = list(range(n + 1)[1:]) x = filter(fn, x) print(len(x)) if __name__ == "__main__": main()
def fn(i): return (1 <= i and i <= 9) or (100 <= i and i <= 999) or (10000 <= i and i <= 99999) def main(): n = int(input()) x = range(n + 1)[1:] x = tuple(filter(fn, x)) print(len(x)) if __name__ == "__main__": main()
replace
6
9
6
8
TypeError: object of type 'filter' has no len()
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02952/Python/s605621965.py", line 16, in <module> main() File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02952/Python/s605621965.py", line 12, in main print(len(x)) TypeError: object of type 'filter' has no len()
p02952
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define endl '\n' template <typename T> void scanInt(T &x) { bool neg = false; register int c = getchar_unlocked(); x = 0; for (; (c < 48 || c > 57) && (c != '-'); c = getchar_unlocked()) ; if (c == '-') { neg = true; c = getchar_unlocked(); } for (; c > 47 && c < 58; c = getchar_unlocked()) x = (x << 1) + (x << 3) + c - 48; if (neg) x *= -1; } template <typename T> void printInt(T n) { if (n < 0) { n = -n; putchar_unlocked('-'); } int i = 21; char output_buffer[21]; do { output_buffer[--i] = (n % 10) + '0'; n /= 10; } while (n); do { putchar_unlocked(output_buffer[i]); } while (++i < 21); } bool isOddNo(int n) { int Count = 0; while (n > 0) { n /= 10; Count++; } return Count & 1; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif int n, Count = 0; cin >> n; for (int i = 1; i <= n; i++) if (isOddNo(i)) Count++; cout << Count << endl; }
#include <bits/stdc++.h> using namespace std; #define endl '\n' template <typename T> void scanInt(T &x) { bool neg = false; register int c = getchar_unlocked(); x = 0; for (; (c < 48 || c > 57) && (c != '-'); c = getchar_unlocked()) ; if (c == '-') { neg = true; c = getchar_unlocked(); } for (; c > 47 && c < 58; c = getchar_unlocked()) x = (x << 1) + (x << 3) + c - 48; if (neg) x *= -1; } template <typename T> void printInt(T n) { if (n < 0) { n = -n; putchar_unlocked('-'); } int i = 21; char output_buffer[21]; do { output_buffer[--i] = (n % 10) + '0'; n /= 10; } while (n); do { putchar_unlocked(output_buffer[i]); } while (++i < 21); } bool isOddNo(int n) { int Count = 0; while (n > 0) { n /= 10; Count++; } return Count & 1; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, Count = 0; cin >> n; for (int i = 1; i <= n; i++) if (isOddNo(i)) Count++; cout << Count << endl; }
delete
50
55
50
50
0
p02952
Python
Runtime Error
n = int(input()) cnt = 0 for i in range(1, n + 1): if str(i) % 2 == 1: cnt += 1 print(cnt)
n = int(input()) cnt = 0 for i in range(1, n + 1): if len(str(i)) % 2 == 1: cnt += 1 print(cnt)
replace
3
4
3
4
TypeError: not all arguments converted during string formatting
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02952/Python/s429203628.py", line 4, in <module> if str(i) % 2 == 1: TypeError: not all arguments converted during string formatting
p02952
Python
Runtime Error
def main(n): count = 0 for i in range(n + 1): if str(i).__len__ % 2 == 1: count += 1 print(count) if __name__ == "__main__": n = int(input()) main(n)
def main(n): count = 0 for i in range(1, n + 1): if len(str(i)) % 2 == 1: count += 1 print(count) if __name__ == "__main__": n = int(input()) main(n)
replace
3
5
3
5
TypeError: unsupported operand type(s) for %: 'method-wrapper' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02952/Python/s049865581.py", line 14, in <module> main(n) File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02952/Python/s049865581.py", line 5, in main if str(i).__len__ % 2 == 1: TypeError: unsupported operand type(s) for %: 'method-wrapper' and 'int'
p02952
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() #define all2(a, b) (a).begin(), (a).begin() + (b) #define debug(vari) cerr << #vari << " = " << (vari) << endl; int main() { int N; cin >> N; int ans = 0; rep2(i, 1, N + 1) { int cnt = 0; while (i) { cnt += i % 10; i /= 10; } if (cnt % 2 == 1) { ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); ++i) #define all(a) (a).begin(), (a).end() #define all2(a, b) (a).begin(), (a).begin() + (b) #define debug(vari) cerr << #vari << " = " << (vari) << endl; int main() { int N; cin >> N; int ans = 0; rep2(i, 1, N + 1) { int cnt = 0; int tmp = i; while (tmp) { cnt++; tmp /= 10; } if (cnt % 2 == 1) { ans++; } } cout << ans << endl; return 0; }
replace
18
21
18
22
TLE
p02952
C++
Runtime Error
#include "bits/stdc++.h" #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define MOD 1e9 + 7; #define ALL(v) v.begin(), v.end() using namespace std; typedef long long LL; typedef vector<int> VI; typedef vector<string> VS; int main() { int N; cin >> N; int keta = log10(N) + 1; if (keta % 2 == 1) { string hiku; for (int i = 0; i < keta - 2; i += 2) { hiku += "90"; } cout << N - stoi(hiku) << endl; } else { string ans = "9"; for (int i = 0; i < keta - 2; i += 2) { ans = "90" + ans; } cout << stoi(ans) << endl; } }
#include "bits/stdc++.h" #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define MOD 1e9 + 7; #define ALL(v) v.begin(), v.end() using namespace std; typedef long long LL; typedef vector<int> VI; typedef vector<string> VS; int main() { int N; cin >> N; if (N < 10) { cout << N << endl; return 0; } int keta = log10(N) + 1; if (keta % 2 == 1) { string hiku; for (int i = 0; i < keta - 2; i += 2) { hiku += "90"; } cout << N - stoi(hiku) << endl; } else { string ans = "9"; for (int i = 0; i < keta - 2; i += 2) { ans = "90" + ans; } cout << stoi(ans) << endl; } }
insert
15
15
15
19
0
p02952
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N, S, sum, ans = 0; cin >> N; while (N > 0) { sum = 0; S = N; while (S > 0) { S / 10; sum++; } if (sum % 2 == 1) { ans++; } N--; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, S, sum, ans = 0; cin >> N; while (N > 0) { sum = 0; S = N; while (S > 0) { S /= 10; sum++; } if (sum % 2 == 1) { ans++; } N--; } cout << ans << endl; }
replace
10
11
10
11
TLE
p02952
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int number = 0; for (int i = 1; i < N + 1; i++) { int count = 0; while (i != 0) { i /= 10; count++; } if (count % 2 == 1) { number++; } } cout << number << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int number = 0; for (int i = 1; i < N + 1; i++) { int count = 0; int a = i; while (a != 0) { a /= 10; count++; } if (count % 2 == 1) { number++; } } cout << number << endl; }
replace
8
10
8
11
TLE
p02952
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; //**************************************************** #define lp(var, start, end) for (ll var = start; var < end; ++var) #define rlp(var, start, end) for (ll var = start; var >= end; var--) #define pb push_back #define mp make_pair #define pf push_front #define ff first #define ss second #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define all(X) X.begin(), X.end() #define endl "\n" // comment it for interactive questions #define trace1(a) cerr << #a << ": " << a << endl; #define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl; #define trace3(a, b, c) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << #d << ": " << d << endl; #define MOD (ll)1e9 + 7; // change it for other mods #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) //******************************************************* // Some Functions ll powmod(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b = b >> 1; } return res % MOD; } ll cnt(ll n) { ll res = 0; while (n > 0) { res++; n = n / 10; } return res; } int main() { FAST_IO; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n; cin >> n; ll ans = 0; for (ll i = 1; i <= n; i++) { if (cnt(i) % 2 == 1) ans++; } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; //**************************************************** #define lp(var, start, end) for (ll var = start; var < end; ++var) #define rlp(var, start, end) for (ll var = start; var >= end; var--) #define pb push_back #define mp make_pair #define pf push_front #define ff first #define ss second #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define all(X) X.begin(), X.end() #define endl "\n" // comment it for interactive questions #define trace1(a) cerr << #a << ": " << a << endl; #define trace2(a, b) cerr << #a << ": " << a << " " << #b << ": " << b << endl; #define trace3(a, b, c) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c \ << #d << ": " << d << endl; #define MOD (ll)1e9 + 7; // change it for other mods #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) //******************************************************* // Some Functions ll powmod(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b = b >> 1; } return res % MOD; } ll cnt(ll n) { ll res = 0; while (n > 0) { res++; n = n / 10; } return res; } int main() { ll n; cin >> n; ll ans = 0; for (ll i = 1; i <= n; i++) { if (cnt(i) % 2 == 1) ans++; } cout << ans << "\n"; }
delete
59
64
59
59
TLE
p02952
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int int1; cin >> int1; int p = 0; for (int int2 = 1; int2 <= int1; int2++) { int s = 0; int n = int2; while (n != 0) { n - n / 10; s++; } if (s % 2 == 1) { p++; } } cout << p << endl; }
#include <iostream> using namespace std; int main() { int int1; cin >> int1; int p = 0; for (int int2 = 1; int2 <= int1; int2++) { int s = std::to_string(int2).length(); if (s % 2 == 1) { p++; } } cout << p << endl; }
replace
10
16
10
11
TLE
p02952
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int e = 0; for (int i = 1; i <= n; i++) { int d = i; int c = 0; while (d > 0) { n /= 10; c++; } if (c % 2 == 1) { e++; } } cout << e; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int e = 0; for (int i = 1; i <= n; i++) { int d = i; int c = 0; while (d > 0) { d /= 10; c++; } if (c % 2 == 1) { e++; } } cout << e; }
replace
10
11
10
11
TLE
p02952
Python
Runtime Error
N = int(input()) ans = 0 for i in range(1, N + 1): if len(i) % 2 == 1: ans += 1 print(ans)
N = int(input()) ans = 0 for i in range(1, N + 1): if len(str(i)) % 2 == 1: ans += 1 print(ans)
replace
3
4
3
4
TypeError: object of type 'int' has no len()
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02952/Python/s356122342.py", line 4, in <module> if len(i) % 2 == 1: TypeError: object of type 'int' has no len()
p02952
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, k = 1, ans = 0, i = 10; cin >> n; for (; i <= n; i *= 100) { ans += i * 0.9; } if (n / (i / 100) > 9) ans += n - i / 10 + 1; cout << ans; }
#include <iostream> using namespace std; int main() { int n, k = 1, ans = 0, i = 10; cin >> n; if (n < 10) { cout << n; return 0; } for (; i <= n; i *= 100) { ans += i * 0.9; } if (n / (i / 100) > 9) ans += n - i / 10 + 1; cout << ans; }
insert
5
5
5
9
0
p02952
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using P = pair<int, int>; #include <algorithm> #include <map> #include <math.h> #include <queue> int main() { int n; cin >> n; ll ans(0); rep(i, n + 1) { int c(0); int j = i; while (j) { j /= 10; c++; } if (c % 2 == 1) { ans++; } } cout << ans; return ans; }
#include <iostream> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using P = pair<int, int>; #include <algorithm> #include <map> #include <math.h> #include <queue> int main() { int n; cin >> n; ll ans(0); rep(i, n + 1) { int c(0); int j = i; while (j) { j /= 10; c++; } if (c % 2 == 1) { ans++; } } cout << ans; return 0; }
replace
28
29
28
29
9
p02952
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; string s; int n, ans = 0, nums[4]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); nums[1] = 9; nums[3] = 909; nums[5] = 90909; nums[7] = 90910; cin >> s; n = stoi(s); int l = s.size(); if (l % 2 == 0) { l--; ans = nums[l]; } else { if (s.size() > 1) { char c = s[0]; s.erase(s.begin()); int t = stoi(s); int hd = c - '0'; hd--; hd *= pow(10, s.size()); hd += t + 1; ans = hd; ans += nums[s.size() - 1]; } else ans = n; } cout << ans; return 0; }
#include "bits/stdc++.h" using namespace std; string s; int n, ans = 0, nums[8]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); nums[1] = 9; nums[3] = 909; nums[5] = 90909; nums[7] = 90910; cin >> s; n = stoi(s); int l = s.size(); if (l % 2 == 0) { l--; ans = nums[l]; } else { if (s.size() > 1) { char c = s[0]; s.erase(s.begin()); int t = stoi(s); int hd = c - '0'; hd--; hd *= pow(10, s.size()); hd += t + 1; ans = hd; ans += nums[s.size() - 1]; } else ans = n; } cout << ans; return 0; }
replace
4
5
4
5
0
p02952
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; bool f(int x) { int keta = 0; while (x) { keta++; x / 10; } return keta % 2 == 1; } int main() { int n; cin >> n; int ans = 0; for (int i = 1; i <= n; i++) { if (f(i)) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; bool f(int x) { int keta = 0; while (x) { keta++; x /= 10; } return keta % 2 == 1; } int main() { int n; cin >> n; int ans = 0; for (int i = 1; i <= n; i++) { if (f(i)) ans++; } cout << ans << endl; }
replace
6
7
6
7
TLE
p02952
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sum = 0; for (int i = 1; i <= n; i++) { int cnt = 1; while (i > 0) { i /= 10; cnt++; } if (cnt % 2 == 1) { sum++; } } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int sum = 0; for (int i = 1; i <= n; i++) { string s = to_string(i); int size = s.size(); if (size % 2 == 1) { sum++; } } cout << sum << endl; }
replace
8
14
8
12
TLE
p02952
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int count = 0; for (int i = n; i > 0; i++) { string s = to_string(i); if (s.size() == 1 || s.size() == 3 || s.size() == 5) count++; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int count = 0; for (int i = n; i > 0; i--) { string s = to_string(i); if (s.size() == 1 || s.size() == 3 || s.size() == 5) count++; } cout << count << endl; }
replace
8
9
8
9
TLE
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) #define all(n) begin(n), end(n) struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; const long long INF = numeric_limits<long long>::max(); typedef long long ll; typedef vector<int> vint; typedef vector<char> vchar; typedef vector<vector<int>> vvint; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; int main() { int N; string ans = "Yes"; cin >> N; vint H(N); rep(i, N) { cin >> H[i]; } for (int i = N - 2; 0 <= i; i++) { if (H[i] > H[i + 1]) { if (H[i] == H[i + 1] + 1) { H[i]--; } else ans = "No"; } } rep(i, N - 1) { if (H[i] > H[i + 1]) { ans = "No"; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) #define all(n) begin(n), end(n) struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; const long long INF = numeric_limits<long long>::max(); typedef long long ll; typedef vector<int> vint; typedef vector<char> vchar; typedef vector<vector<int>> vvint; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; int main() { int N; string ans = "Yes"; cin >> N; vint H(N); rep(i, N) { cin >> H[i]; } for (int i = N - 2; 0 <= i; i--) { if (H[i] > H[i + 1]) { if (H[i] == H[i + 1] + 1) { H[i]--; } else ans = "No"; } } rep(i, N - 1) { if (H[i] > H[i + 1]) { ans = "No"; } } cout << ans; return 0; }
replace
25
26
25
26
-11
p02953
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long int ll; typedef vector<ll> vll; typedef vector<vll> vvll; const ll MOD = 1000000007; int main() { int N; cin >> N; vll H(N); REP(i, N) cin >> H[i]; REPR(i, N - 1) { if (H[i] < H[i - 1]) H[i - 1]--; if (H[i] < H[i - 1]) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() using namespace std; typedef long long int ll; typedef vector<ll> vll; typedef vector<vll> vvll; const ll MOD = 1000000007; int main() { int N; cin >> N; vll H(N); REP(i, N) cin >> H[i]; REPR(i, N - 2) { if (H[i + 1] < H[i]) H[i]--; if (H[i + 1] < H[i]) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
replace
18
22
18
22
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long h[10100]; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = n - 2; i >= 0; i--) { if (h[i] > h[i + 1]) h[i]--; } bool f = true; for (int i = 0; i < n - 1; i++) { if (h[i] > h[i + 1]) f = false; } if (f) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long h[101000]; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = n - 2; i >= 0; i--) { if (h[i] > h[i + 1]) h[i]--; } bool f = true; for (int i = 0; i < n - 1; i++) { if (h[i] > h[i + 1]) f = false; } if (f) cout << "Yes" << endl; else cout << "No" << endl; }
replace
6
7
6
7
0
p02953
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <iostream> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; /* define */ #define Yes(X) puts((X) ? "Yes" : "No") #define YES(X) puts((X) ? "YES" : "NO") #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define max(a, b) (((a) > (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c)) #define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c)) /* const */ const int MOD = 1000000007; /* alias */ typedef long long ll; typedef unsigned u; /* function */ int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int cmp2(const void *a, const void *b) { return *(int *)b - *(int *)a; } int gcd(int a, int b) { if (b != 0) return gcd(b, a % b); return a; } ll Lgcd(ll a, ll b) { if (b != 0) return Lgcd(b, a % b); return a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } ll Llcm(ll a, ll b) { return a / Lgcd(a, b) * b; } /* main */ int main() { int n, h[10000] = {0}, f = 1; cin >> n; for (int i = 1; i <= n; i++) { cin >> h[i]; if (h[i] > h[i - 1]) h[i]--; if (h[i] < h[i - 1]) f = 0; } Yes(f); }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <iostream> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; /* define */ #define Yes(X) puts((X) ? "Yes" : "No") #define YES(X) puts((X) ? "YES" : "NO") #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define max(a, b) (((a) > (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c)) #define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c)) /* const */ const int MOD = 1000000007; /* alias */ typedef long long ll; typedef unsigned u; /* function */ int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int cmp2(const void *a, const void *b) { return *(int *)b - *(int *)a; } int gcd(int a, int b) { if (b != 0) return gcd(b, a % b); return a; } ll Lgcd(ll a, ll b) { if (b != 0) return Lgcd(b, a % b); return a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } ll Llcm(ll a, ll b) { return a / Lgcd(a, b) * b; } /* main */ int main() { int n, h[100000] = {0}, f = 1; cin >> n; for (int i = 1; i <= n; i++) { cin >> h[i]; if (h[i] > h[i - 1]) h[i]--; if (h[i] < h[i - 1]) f = 0; } Yes(f); }
replace
49
50
49
50
0
p02953
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <istream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep0(i, n) for (int i = 0; i <= (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define REP(a, b) for (int ii = a; ii <= (b); ++ii) #define mREP(a, b) for (int i = a; i == (b); --i) #define mod 1e9 + 7 typedef long long ll; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); /*         _... ..._       , ´⌒ ⌒ヽ       ノィ(ノノ)ノ)ノ)       ((q|.゚ ヮ゚ノ|ハ       △ム,8ムフつ      /(ン_/_ヽ\      ~~i_フ_フ~´ */ int n; cin >> n; vector<ll> a(n); ll temp = -1; bool sc = true; rep0(i, n - 1) { scanf("%lld", a[i]); } rep0(j, n - 1) { if (temp > a[j]) { sc = false; } else if (temp < a[j]) { temp = a[j] - 1; } else { temp = a[j]; } } cout << ((sc) ? "Yes" : "No") << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <istream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep0(i, n) for (int i = 0; i <= (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define REP(a, b) for (int ii = a; ii <= (b); ++ii) #define mREP(a, b) for (int i = a; i == (b); --i) #define mod 1e9 + 7 typedef long long ll; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); /*         _... ..._       , ´⌒ ⌒ヽ       ノィ(ノノ)ノ)ノ)       ((q|.゚ ヮ゚ノ|ハ       △ム,8ムフつ      /(ン_/_ヽ\      ~~i_フ_フ~´ */ int n; cin >> n; vector<ll> a(n); ll temp = -1; bool sc = true; rep0(i, n - 1) { scanf("%lld", &a[i]); } rep0(j, n - 1) { if (temp > a[j]) { sc = false; } else if (temp < a[j]) { temp = a[j] - 1; } else { temp = a[j]; } } cout << ((sc) ? "Yes" : "No") << endl; return 0; }
replace
37
38
37
38
0
p02953
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { int n, i, j; cin >> n; int h[n]; for (i = 0; i < n; i++) { cin >> h[i]; } string ans = "Yes"; for (i = 0; i < n - 1; i++) { if (ans == "No") break; for (j = i + 1; j < n; j++) { if (h[i] - h[j] >= 2) { ans = "No"; break; } } } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { int n, i, j; cin >> n; int h[n]; for (i = 0; i < n; i++) { cin >> h[i]; } string ans = "Yes"; int maxh[n]; int max = 0; for (i = 0; i < n; i++) { if (max <= h[i]) { max = h[i]; maxh[i] = max; } else maxh[i] = max; } for (i = 0; i < n; i++) { if (maxh[i] - h[i] >= 2) ans = "No"; } cout << ans << endl; }
replace
15
24
15
28
TLE
p02953
Python
Runtime Error
""" https://atcoder.jp/contests/abc136/tasks/abc136_c """ import numpy as np def calc(N: int, values: np.ndarray) -> bool: # 要素が1つなら確定でOK if len(values) == 1: return True # 2つ以上下がっている部分があるとNG gradient = np.diff(values) if np.min(gradient) <= -2: return False # 要素が2つでならこの時点でOK確定 if len(values) == 2: return True # 1つ下がってから、上がる前に、1つ下がるとNG gradient_without_zero = gradient[gradient != 0] gradient_without_last = gradient_without_zero[:-1] gradient_without_first = gradient_without_zero[1:] if np.min(gradient_without_first + gradient_without_last) <= -2: return False return True def load_input_as_int_array() -> np.ndarray: return np.array([int(v) for v in input().split(" ")]) def main() -> None: (N,) = load_input_as_int_array() values = load_input_as_int_array() result = calc(N, values) print("Yes" if result else "No") main()
""" https://atcoder.jp/contests/abc136/tasks/abc136_c """ import numpy as np def calc(N: int, values: np.ndarray) -> bool: # 要素が1つなら確定でOK if len(values) == 1: return True # 2つ以上下がっている部分があるとNG gradient = np.diff(values) if np.min(gradient) <= -2: return False # 要素が2つでならこの時点でOK確定 if len(values) == 2: return True # 1つ下がってから、上がる前に、1つ下がるとNG gradient_without_zero = gradient[gradient != 0] if len(gradient_without_zero) == 0: return True gradient_without_last = gradient_without_zero[:-1] gradient_without_first = gradient_without_zero[1:] if np.min(gradient_without_first + gradient_without_last) <= -2: return False return True def load_input_as_int_array() -> np.ndarray: return np.array([int(v) for v in input().split(" ")]) def main() -> None: (N,) = load_input_as_int_array() values = load_input_as_int_array() result = calc(N, values) print("Yes" if result else "No") main()
insert
23
23
23
25
TLE
p02953
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const long long mod = 1e9 + 7; // 10^9+7 int main() { int n; ll h[200000]; int sw[200000]; cin >> n; for (int i = 0; i < n; i++) { cin >> h[i]; sw[i] = 0; } if (n == 1) { cout << "Yes" << endl; return 0; } int flg = 0; for (int i = 0; i < n - 1; i++) { if (h[i] > h[i + 1] + 1) { flg = 1; } else if (h[i] == h[i + 1] + 1) { h[i]--; sw[i] = 1; for (int j = i; j > 0; j--) { if (h[j - 1] > h[j] + 1) { flg = 1; break; } else if (h[j - 1] == h[j] + 1) { if (sw[j - 1] == 1) { flg = 1; break; } else { h[j - 1]--; sw[j - 1] = 1; } } } } if (flg == 1) break; } if (flg == 1) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const long long mod = 1e9 + 7; // 10^9+7 int main() { int n; ll h[200000]; int sw[200000]; cin >> n; for (int i = 0; i < n; i++) { cin >> h[i]; sw[i] = 0; } if (n == 1) { cout << "Yes" << endl; return 0; } int flg = 0; for (int i = 0; i < n - 1; i++) { if (h[i] > h[i + 1] + 1) { flg = 1; } else if (h[i] == h[i + 1] + 1) { h[i]--; sw[i] = 1; for (int j = i; j > 0; j--) { if (h[j - 1] > h[j] + 1) { flg = 1; break; } else if (h[j - 1] == h[j] + 1) { if (sw[j - 1] == 1) { flg = 1; break; } else { h[j - 1]--; sw[j - 1] = 1; } } else if (h[j - 1] <= h[j]) { break; } } } if (flg == 1) break; } if (flg == 1) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
insert
39
39
39
41
TLE
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // 総数を1000000007で割った余り const long long mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vs vector<string> #define vpii vector<pii> #define vpll vector<pll> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++) #define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++) #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v + n); // #define SORT(v, n) stable_sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define mp make_pair #define INF (1e9) #define PI (acos(-1)) #define EPS (1e-7) ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } int main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(5); ll n; cin >> n; vector<ll> h(n + 1); h[n + 1] = INF; h[0] = 0; rep1(i, n) { cin >> h[i]; } bool flg = false; for (int i = n; i >= 1; i--) { if (h[i - 1] - h[i] > 1) { flg = false; break; } if (h[i - 1] - h[i] == 1) { h[i - 1]--; } flg = true; } if (flg) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; // 総数を1000000007で割った余り const long long mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vs vector<string> #define vpii vector<pii> #define vpll vector<pll> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++) #define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++) #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v + n); // #define SORT(v, n) stable_sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define mp make_pair #define INF (1e9) #define PI (acos(-1)) #define EPS (1e-7) ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } int main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(5); ll n; cin >> n; vector<ll> h(n + 2); h[n + 1] = INF; h[0] = 0; rep1(i, n) { cin >> h[i]; } bool flg = false; for (int i = n; i >= 1; i--) { if (h[i - 1] - h[i] > 1) { flg = false; break; } if (h[i - 1] - h[i] == 1) { h[i - 1]--; } flg = true; } if (flg) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
replace
47
48
47
48
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // 総数を1000000007で割った余り const long long mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vs vector<string> #define vpii vector<pii> #define vpll vector<pll> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++) #define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++) #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v + n); // #define SORT(v, n) stable_sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define mp make_pair #define INF (1e9) #define PI (acos(-1)) #define EPS (1e-7) ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } int main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(5); ll n; cin >> n; vector<ll> h(n); h[0] = 0; rep1(i, n) { cin >> h[i]; } bool flg = false; for (int i = n; i >= 1; i--) { if (h[i - 1] - h[i] > 1) { flg = false; break; } if (h[i - 1] - h[i] == 1) { h[i - 1]--; } flg = true; } if (flg) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; // 総数を1000000007で割った余り const long long mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vs vector<string> #define vpii vector<pii> #define vpll vector<pll> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++) #define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++) #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v + n); // #define SORT(v, n) stable_sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define mp make_pair #define INF (1e9) #define PI (acos(-1)) #define EPS (1e-7) ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } int main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(5); ll n; cin >> n; vector<ll> h(n + 10); h[n + 1] = INF; h[0] = 0; rep1(i, n) { cin >> h[i]; } bool flg = false; for (int i = n; i >= 1; i--) { if (h[i - 1] - h[i] > 1) { flg = false; break; } if (h[i - 1] - h[i] == 1) { h[i - 1]--; } flg = true; } if (flg) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
replace
47
48
47
49
0
p02953
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); vector<bool> v(n, false); for (int i = 0; i < n; i++) cin >> arr[i]; bool flag = true; for (int i = 1; i < n && i >= 0;) { if (arr[i - 1] - arr[i] > 1) { flag = false; break; } else if (arr[i] - arr[i - 1] >= 0) { i++; continue; } else if (arr[i - 1] > arr[i]) { while (i > 0 && arr[i - 1] > arr[i]) { if (v[i - 1] == false) { arr[i - 1]--; i--; v[i - 1] = true; } else { flag = false; break; } } } } if (flag) cout << "Yes\n"; else cout << "No\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); vector<bool> v(n, false); for (int i = 0; i < n; i++) cin >> arr[i]; bool flag = true; for (int i = n - 2; i >= 0; i--) { if (arr[i + 1] < arr[i]) { if (arr[i + 1] + 1 == arr[i]) arr[i]--; else { flag = false; break; } } } if (flag) cout << "Yes\n"; else cout << "No\n"; return 0; }
replace
17
36
17
24
TLE
p02953
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using lint = long long int; #define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0])) #define REP(i, n) for (lint i = 0; i < (n); i++) #define REP1(i, n) for (lint i = 1; i < (n); i++) lint N; int canAlinement(vector<lint> *v) { map<int, int> hash; for (int i = N - 1; i > 0; --i) { for (int j = N - 1; j > 0; --j) { if ((*v).at(j - 1) > (*v).at(j)) { --(*v).at(j - 1); ++hash[j - 1]; if (hash[j - 1] > 1) { return 0; } } } } return 1; } int main(void) { cin >> N; vector<lint> H(N); REP(i, N) cin >> H[i]; canAlinement(&H) ? cout << "Yes" << endl : cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; #define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0])) #define REP(i, n) for (lint i = 0; i < (n); i++) #define REP1(i, n) for (lint i = 1; i < (n); i++) lint N; int canAlinement(vector<lint> *v) { map<int, int> hash; for (int j = N - 1; j > 0; --j) { if ((*v).at(j) - (*v).at(j - 1) <= (-2)) { return 0; } else if ((*v).at(j) - (*v).at(j - 1) == (-1)) { --(*v).at(j - 1); } } return 1; } int main(void) { cin >> N; vector<lint> H(N); REP(i, N) cin >> H[i]; canAlinement(&H) ? cout << "Yes" << endl : cout << "No" << endl; return 0; }
replace
11
20
11
16
TLE
p02953
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n; int h[10000]; int ans = 0; int f = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> h[i]; } h[0]--; for (int i = 0; i < n - 1; i++) { if (h[i] > h[i + 1]) { f = 1; break; } if (h[i] < h[i + 1]) { h[i + 1]--; } } if (f == 1) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
#include <iostream> using namespace std; int main() { int n; int h[100000]; int ans = 0; int f = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> h[i]; } h[0]--; for (int i = 0; i < n - 1; i++) { if (h[i] > h[i + 1]) { f = 1; break; } if (h[i] < h[i + 1]) { h[i + 1]--; } } if (f == 1) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
replace
6
7
6
7
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, a[10010], minn = 0X7fffffff; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = n; i >= 1; i--) { if (a[i] - minn >= 2) { cout << "No" << endl; return 0; } minn = min(minn, a[i]); } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[100010], minn = 0X7FFFFFFF; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = n; i >= 1; i--) { if (a[i] - minn >= 2) { cout << "No" << endl; return 0; } minn = min(minn, a[i]); } cout << "Yes" << endl; return 0; }
replace
2
3
2
3
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { int N; cin >> N; vector<int> vec(N); for (int i = 0; i < N; i++) { cin >> vec.at(i); } if (N == 1) { cout << "Yes" << endl; return 0; } if (N == 2) { if (vec.at(1) - vec.at(0) >= 2) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 0; } for (int i = N - 1; i >= 1; i--) { if (vec.at(i - 1) - vec.at(i) >= 2 || vec.at(i - 2) - vec.at(i) >= 2) { // NoとすべきでないところをNoとしている可能性 cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { int N; cin >> N; vector<int> vec(N); for (int i = 0; i < N; i++) { cin >> vec.at(i); } if (N == 1) { cout << "Yes" << endl; return 0; } if (N == 2) { if (vec.at(1) - vec.at(0) >= 2) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 0; } vector<int> newVec; newVec.push_back(vec.at(0)); int last = vec.at(N - 1); for (int i = 1; i < N - 1; i++) { if (vec.at(i) != vec.at(i + 1)) { newVec.push_back(vec.at(i)); } } newVec.push_back(last); for (int i = newVec.size() - 1; i > 1; i--) { if (newVec.at(i - 1) - newVec.at(i) >= 2 || newVec.at(i - 2) - newVec.at(i) >= 2) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
replace
25
28
25
38
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 5)
p02953
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <iostream> #include <vector> #define rep(a, b, c) for (ll a = b; a <= c; a++) #define per(a, b, c) for (ll a = b; a >= c; a--) #define pb push_back #define mk make_pair #define pii pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) using namespace std; typedef long long ll; typedef double db; const int inf = 0x3f3f3f3f; const int N = 1e3 + 5; const int M = 2e5 + 5; int n; int a[N]; int main() { cin >> n; rep(i, 1, n) cin >> a[i]; bool flag = 1; a[1]--; rep(i, 2, n) { if (a[i] < a[i - 1]) { flag = 0; break; } else if (a[i] > a[i - 1]) a[i]--; } printf("%s\n", flag ? "Yes" : "No"); return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <iostream> #include <vector> #define rep(a, b, c) for (ll a = b; a <= c; a++) #define per(a, b, c) for (ll a = b; a >= c; a--) #define pb push_back #define mk make_pair #define pii pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) using namespace std; typedef long long ll; typedef double db; const int inf = 0x3f3f3f3f; const int N = 1e5 + 5; const int M = 2e5 + 5; int n; int a[N]; int main() { cin >> n; rep(i, 1, n) cin >> a[i]; bool flag = 1; a[1]--; rep(i, 2, n) { if (a[i] < a[i - 1]) { flag = 0; break; } else if (a[i] > a[i - 1]) a[i]--; } printf("%s\n", flag ? "Yes" : "No"); return 0; }
replace
16
17
16
17
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; scanf("%d", &N); vector<int> H(N, 0); for (int i = 0; i < N; i++) { scanf("%d", &H.at(i)); } for (int i = N - 1; i >= 0; i--) { if (H.at(i) < H.at(i - 1)) { H.at(i - 1)--; } if (H.at(i) < H.at(i - 1)) { printf("No"); return 0; } } printf("Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; scanf("%d", &N); vector<int> H(N, 0); for (int i = 0; i < N; i++) { scanf("%d", &H.at(i)); } for (int i = N - 1; i > 0; i--) { if (H.at(i) < H.at(i - 1)) { H.at(i - 1)--; } if (H.at(i) < H.at(i - 1)) { printf("No"); return 0; } } printf("Yes"); return 0; }
replace
12
13
12
13
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 5)
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, h[10010]; int main() { cin >> n >> h[0]; if (n == 1) { cout << "Yes" << endl; return 0; } h[0]--; for (int i = 1; i < n; i++) { cin >> h[i]; if (h[i] > h[i - 1]) h[i]--; if (h[i] < h[i - 1]) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
#include <bits/stdc++.h> using namespace std; int n, h[100010]; int main() { cin >> n >> h[0]; if (n == 1) { cout << "Yes" << endl; return 0; } h[0]--; for (int i = 1; i < n; i++) { cin >> h[i]; if (h[i] > h[i - 1]) h[i]--; if (h[i] < h[i - 1]) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
replace
3
4
3
4
0
p02953
Python
Runtime Error
n = int(input()) h = [int(x) for x in input().split()] h.reverse() flag = True for i in range(1, n): print(h, i) if h[i - 1] >= h[i]: continue elif h[i] == h[i - 1] + 1: h[i] -= 1 else: flag = False break print("Yes") if flag else print("No")
n = int(input()) h = [int(x) for x in input().split()] h.reverse() flag = True for i in range(1, n): if h[i - 1] >= h[i]: continue elif h[i] == h[i - 1] + 1: h[i] -= 1 else: flag = False break print("Yes") if flag else print("No")
delete
7
9
7
7
0
p02953
Python
Time Limit Exceeded
import sys input = sys.stdin.readline N = int(input()) H = [int(item) for item in input().split()] cand = [] cand += [H[0], H[0] - 1] for i in range(1, N): new_cand = [] for c in cand: if c <= H[i] - 1: new_cand += [H[i], H[i] - 1] elif c == H[i]: new_cand += [H[i]] cand = new_cand if len(cand) == 0: print("No") break else: print("Yes")
import sys input = sys.stdin.readline N = int(input()) H = [int(item) for item in input().split()] cand = [] cand += [H[0], H[0] - 1] for i in range(1, N): new_cand = [] for c in cand: if c <= H[i] - 1: new_cand += [H[i], H[i] - 1] elif c == H[i]: new_cand += [H[i]] cand = list(set(new_cand)) if len(cand) == 0: print("No") break else: print("Yes")
replace
16
17
16
17
TLE
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int64_t> H(n); for (int i = 0; i < n; i++) { cin >> H.at(i); } if (n == 1) { cout << "Yes" << endl; return 0; } for (int i = n; i > 0; i--) { if (H.at(i - 1) + 1 == H.at(i)) { H.at(i - 1)--; } else if (H.at(i - 1) > H.at(i)) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int64_t> H(n); for (int i = 0; i < n; i++) { cin >> H.at(i); } if (n == 1) { cout << "Yes" << endl; return 0; } for (int i = n - 1; i > 0; i--) { if (H.at(i - 1) - 1 == H.at(i)) { H.at(i - 1)--; } else if (H.at(i - 1) > H.at(i)) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
replace
13
15
13
15
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; vector<int> a(109); cin >> N; string ans = "Yes"; for (int i = 0; i < N; i++) cin >> a.at(i); for (int i = 1; i < N; i++) { if (a[i - 1] <= a[i] - 1) a[i] -= 1; if (a[i] < a[i - 1]) { ans = "No"; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; vector<int> a(100000); cin >> N; string ans = "Yes"; for (int i = 0; i < N; i++) cin >> a.at(i); for (int i = 1; i < N; i++) { if (a[i - 1] <= a[i] - 1) a[i] -= 1; if (a[i] < a[i - 1]) { ans = "No"; break; } } cout << ans << endl; }
replace
5
6
5
6
0
p02953
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef long long LL; typedef priority_queue<int> PQ_DESC; typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC; typedef priority_queue<PII> PQ_DESC_PII; typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<VVLL> VVVLL; #define SORT_ASC(c) sort((c).begin(), (c).end()) #define SORT_DESC(c) \ sort((c).begin(), (c).end(), greater<typeof((c).begin())>()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define SIZE(a) int((a).size()) const double EPS = 1e-10; const double PI = acos(-1.0); const int INT_LARGE = 1000000100; // debug func template <typename T> void vecprint(vector<T> v) { for (auto x : v) { cerr << x << " "; } cerr << endl; } template <typename T> void vecvecprint(vector<vector<T>> v) { for (auto x : v) { REP(i, x.size() - 1) { cerr << x[i] << " "; } cerr << x[x.size() - 1] << endl; } } template <typename T> void pqprint(priority_queue<T> q) { while (!q.empty()) { cerr << q.top() << " "; q.pop(); } cerr << endl; } template <typename T> void qprint(queue<T> q) { while (!q.empty()) { cerr << q.front() << " "; q.pop(); } cerr << endl; } template <typename T> void vecqprint(vector<queue<T>> v) { for (int i = 0; i < v.size(); i++) { qprint(v[i]); } } template <typename Iterator> inline bool next_combination(const Iterator first, Iterator k, const Iterator last) { /* Credits: Thomas Draper */ if ((first == last) || (first == k) || (last == k)) return false; Iterator itr1 = first; Iterator itr2 = last; ++itr1; if (last == itr1) return false; itr1 = last; --itr1; itr1 = k; --itr2; while (first != itr1) { if (*--itr1 < *itr2) { Iterator j = k; while (!(*itr1 < *j)) ++j; iter_swap(itr1, j); ++itr1; ++j; itr2 = k; rotate(itr1, j, last); while (last != j) { ++j; ++itr2; } rotate(k, itr2, last); return true; } } rotate(first, k, last); return false; } inline double get_time_sec(void) { return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>( chrono::steady_clock::now().time_since_epoch()) .count()) / 1000000000; } VI vi; int main(void) { int n; cin >> n; vi = VI(n, 0); REP(i, n) cin >> vi[i]; for (int i = n - 1; i > 0; i--) { cerr << "i: " << i << ", "; vecprint(vi); if (vi[i - 1] - vi[i] > 1) { cout << "No" << endl; return 0; } if (vi[i - 1] - vi[i] == 1) { vi[i - 1]--; continue; } } cout << "Yes" << endl; }
#include "bits/stdc++.h" using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef long long LL; typedef priority_queue<int> PQ_DESC; typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC; typedef priority_queue<PII> PQ_DESC_PII; typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<VVLL> VVVLL; #define SORT_ASC(c) sort((c).begin(), (c).end()) #define SORT_DESC(c) \ sort((c).begin(), (c).end(), greater<typeof((c).begin())>()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define SIZE(a) int((a).size()) const double EPS = 1e-10; const double PI = acos(-1.0); const int INT_LARGE = 1000000100; // debug func template <typename T> void vecprint(vector<T> v) { for (auto x : v) { cerr << x << " "; } cerr << endl; } template <typename T> void vecvecprint(vector<vector<T>> v) { for (auto x : v) { REP(i, x.size() - 1) { cerr << x[i] << " "; } cerr << x[x.size() - 1] << endl; } } template <typename T> void pqprint(priority_queue<T> q) { while (!q.empty()) { cerr << q.top() << " "; q.pop(); } cerr << endl; } template <typename T> void qprint(queue<T> q) { while (!q.empty()) { cerr << q.front() << " "; q.pop(); } cerr << endl; } template <typename T> void vecqprint(vector<queue<T>> v) { for (int i = 0; i < v.size(); i++) { qprint(v[i]); } } template <typename Iterator> inline bool next_combination(const Iterator first, Iterator k, const Iterator last) { /* Credits: Thomas Draper */ if ((first == last) || (first == k) || (last == k)) return false; Iterator itr1 = first; Iterator itr2 = last; ++itr1; if (last == itr1) return false; itr1 = last; --itr1; itr1 = k; --itr2; while (first != itr1) { if (*--itr1 < *itr2) { Iterator j = k; while (!(*itr1 < *j)) ++j; iter_swap(itr1, j); ++itr1; ++j; itr2 = k; rotate(itr1, j, last); while (last != j) { ++j; ++itr2; } rotate(k, itr2, last); return true; } } rotate(first, k, last); return false; } inline double get_time_sec(void) { return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>( chrono::steady_clock::now().time_since_epoch()) .count()) / 1000000000; } VI vi; int main(void) { int n; cin >> n; vi = VI(n, 0); REP(i, n) cin >> vi[i]; for (int i = n - 1; i > 0; i--) { // cerr << "i: " << i << ", "; // vecprint(vi); if (vi[i - 1] - vi[i] > 1) { cout << "No" << endl; return 0; } if (vi[i - 1] - vi[i] == 1) { vi[i - 1]--; continue; } } cout << "Yes" << endl; }
replace
119
121
119
121
TLE
p02953
C++
Runtime Error
#include <iostream> using namespace std; int n; int *x = new int[n]; void solve() { bool f = true; int diff; if (n == 1) { cout << "Yes" << endl; } else { for (int i = n - 1; 0 < i; i--) { diff = x[i] - x[i - 1]; if (diff <= -2) { f = false; break; } else if (diff == -1) { x[i - 1]--; } } if (f) cout << "Yes" << endl; else cout << "No" << endl; } } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x[i]; } solve(); }
#include <iostream> using namespace std; int n; int x[100000]; void solve() { bool f = true; int diff; if (n == 1) { cout << "Yes" << endl; } else { for (int i = n - 1; 0 < i; i--) { diff = x[i] - x[i - 1]; if (diff <= -2) { f = false; break; } else if (diff == -1) { x[i - 1]--; } } if (f) cout << "Yes" << endl; else cout << "No" << endl; } } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> x[i]; } solve(); }
replace
5
6
5
6
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; int Hs[10005]; int main() { int N, H; cin >> N; rep(i, N) { scanf("%d", &Hs[i]); } for (int i = 1; i < N; i++) { Hs[i] -= (Hs[i - 1] < Hs[i] ? 1 : 0); if (Hs[i - 1] > Hs[i]) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; int Hs[100005]; int main() { int N, H; cin >> N; rep(i, N) { scanf("%d", &Hs[i]); } for (int i = 1; i < N; i++) { Hs[i] -= (Hs[i - 1] < Hs[i] ? 1 : 0); if (Hs[i - 1] > Hs[i]) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
replace
4
5
4
5
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> #define N 1005 #define int long long using namespace std; int n, m, a[N], cnt[N], tot; char c[N]; bool b[N]; signed main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); bool bo = 1; for (int i = 1; i <= n; i++) { if (i == 1 && a[i]) a[i]--; else { if (a[i] - 1 >= a[i - 1]) a[i]--; else if (a[i] < a[i - 1]) { bo = 0; break; } } } if (bo) puts("Yes"); else puts("No"); return 0; }
#include <bits/stdc++.h> #define N 100005 #define int long long using namespace std; int n, m, a[N], cnt[N], tot; char c[N]; bool b[N]; signed main() { scanf("%lld", &n); for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); bool bo = 1; for (int i = 1; i <= n; i++) { if (i == 1 && a[i]) a[i]--; else { if (a[i] - 1 >= a[i - 1]) a[i]--; else if (a[i] < a[i - 1]) { bo = 0; break; } } } if (bo) puts("Yes"); else puts("No"); return 0; }
replace
1
2
1
2
0
p02953
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n, a[100001], f = 0; void work(int num, int step) { if (step == n + 1) { f = 1; return; } if (a[step] >= num) work(a[step], step + 1); if (a[step] + 1 >= num) work(a[step] + 1, step + 1); } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; work(a[1], 2); if (f == 1) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[100001], f = 0; void work(int num, int step) { if (step == n + 1) { f = 1; return; } if (a[step] >= num) work(a[step], step + 1); else if (a[step] + 1 >= num) work(a[step] + 1, step + 1); } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; work(a[1], 2); if (f == 1) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
replace
12
13
12
13
TLE
p02953
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; int main() { int n, h[200001], x = 1; cin >> n; rep(i, n) cin >> h[i]; rep(i, n - 1) if (h[i] > h[i + 1] + 1) x = 0; vector<int> H; H.push_back(h[0]); rep(i, n - 1) if (h[i] != h[i + 1]) H.push_back(h[i + 1]); rep(i, H.size() - 2) if (H[i] == H[i + 1] + 1 && H[i + 1] == H[i + 2] + 1) x = 0; if (x) cout << "Yes"; else cout << "No"; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; int main() { int n, h[200001], x = 1; cin >> n; rep(i, n) cin >> h[i]; rep(i, n - 1) if (h[i] > h[i + 1] + 1) x = 0; vector<int> H; H.push_back(h[0]); rep(i, n - 1) if (h[i] != h[i + 1]) H.push_back(h[i + 1]); rep(i, (H.size() - 2) * (H.size() > 2)) if (H[i] == H[i + 1] + 1 && H[i + 1] == H[i + 2] + 1) x = 0; if (x) cout << "Yes"; else cout << "No"; }
replace
12
14
12
14
0
p02953
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> data(n); for (int i = 0; i < n; i++) { cin >> data.at(i); } bool ret = false; int max = 0; for (int i = 0; i < n; i++) { if (max - 1 > data.at(i + 1)) { ret = true; } if (max < data.at(i)) { max = data.at(i); } } cout << (ret ? "No" : "Yes") << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> data(n); for (int i = 0; i < n; i++) { cin >> data.at(i); } bool ret = false; int max = 0; for (int i = 0; i < n; i++) { if (max - 1 > data.at(i)) { ret = true; } if (max < data.at(i)) { max = data.at(i); } } cout << (ret ? "No" : "Yes") << endl; }
replace
15
16
15
16
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p02953
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 H[10009]; int s = 0; cin >> H[0]; for (int i = 1; i < N; i++) { cin >> H[i]; if (H[i - 1] < H[i]) { H[i]--; continue; } if (H[i - 1] > H[i]) { s = 1; break; } } if (s == 1) cout << "No"; else cout << "Yes"; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; long H[110000]; int s = 0; cin >> H[0]; for (int i = 1; i < N; i++) { cin >> H[i]; if (H[i - 1] < H[i]) { H[i]--; continue; } if (H[i - 1] > H[i]) { s = 1; break; } } if (s == 1) cout << "No"; else cout << "Yes"; }
replace
9
10
9
10
0
p02953
C++
Time Limit Exceeded
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <iostream> #include <string> using namespace std; int main() { int n, h[100000], m = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> h[i]; for (int j = 0; j < i; j++) { if (h[j] - h[i] > 1) m++; } } if (m) cout << "No" << endl; else cout << "Yes" << endl; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <iostream> #include <string> using namespace std; int main() { int n, h[100000], m = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < n - 1; i++) { if (h[n - 2 - i] - h[n - 1 - i] > 1) { m++; break; } else if (h[n - 2 - i] - h[n - 1 - i] == 1) h[n - 2 - i]--; } if (m) cout << "No" << endl; else cout << "Yes" << endl; }
replace
13
17
13
20
TLE
p02953
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #include <vector> using namespace std; int main() { int a, s, v = 1; cin >> a; vector<int> z(a); for (s = 0; s < a; s++) { cin >> z.at(s); } reverse(z.begin(), z.end()); for (s = 0; s < a; s++) { if (z.at(s) + 1 == z.at(s + 1)) { z.at(s + 1) -= 1; } if (z.at(s) + 1 < z.at(s + 1)) { v = 0; break; } } if (v == 0) { cout << "No" << endl; } if (v == 1) { cout << "Yes" << endl; } }
#include <bits/stdc++.h> #include <iostream> #include <vector> using namespace std; int main() { int a, s, v = 1; cin >> a; vector<int> z(a); for (s = 0; s < a; s++) { cin >> z.at(s); } reverse(z.begin(), z.end()); for (s = 0; s < a - 1; s++) { if (z.at(s) + 1 == z.at(s + 1)) { z.at(s + 1) -= 1; } if (z.at(s) + 1 < z.at(s + 1)) { v = 0; break; } } if (v == 0) { cout << "No" << endl; } if (v == 1) { cout << "Yes" << endl; } }
replace
13
14
13
14
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p02953
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; typedef pair<long long, long long> P; int main() { int n, a[10009]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } bool ans = true; a[0]--; for (int i = 1; i < n; i++) { if (a[i] < a[i - 1]) { ans = false; break; } else { if (a[i] == a[i - 1]) { a[i] = a[i]; } else { a[i]--; } } } if (ans) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; typedef pair<long long, long long> P; int main() { long long n, a[100009]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } bool ans = true; a[0]--; for (int i = 1; i < n; i++) { if (a[i] < a[i - 1]) { ans = false; break; } else { if (a[i] == a[i - 1]) { a[i] = a[i]; } else { a[i]--; } } } if (ans) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
12
13
12
13
0