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
p03064
C++
Runtime Error
#include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_set> #include <vector> using namespace std; using namespace std::chrono; typedef long long int llint; typedef double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase /*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/ const llint mod = 998244353; const llint big = 2.19e15 + 1; const long double pai = 3.141592653589793238462643383279502884197; const long double eps = 1e-15; template <class T, class U> bool mineq(T &a, U b) { if (a > b) { a = b; return true; } return false; } template <class T, class U> bool maxeq(T &a, U b) { if (a < b) { a = b; return true; } return false; } llint gcd(llint a, llint b) { if (a % b == 0) { return b; } else return gcd(b, a % b); } llint lcm(llint a, llint b) { if (a == 0) { return b; } return a / gcd(a, b) * b; } template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); } template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); } template <class T> llint LBI(vector<T> &ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); } template <class T> llint UBI(vector<T> &ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); } int main(void) { int n, i, j, wa = 0; cin >> n; llint ans = 1; llint dp[45001] = {0}; llint ep[45001] = {0}; dp[0] = 1; ep[0] = 1; for (i = 0; i < n; i++) { int x; cin >> x; wa += x; ans *= 3; ans %= mod; for (j = min(45000, i * 300); j >= 0; j--) { dp[j + x] += dp[j] * 2; dp[j + x] %= mod; ep[j + x] += ep[j]; ep[j + x] %= mod; } } // cerr<<"wa="<<wa<<endl; for (j = 0; j <= wa / 2; j++) { ans -= dp[j] * 3; ans %= mod; } if (wa % 2 == 0) { ans += ep[wa / 2] * 3; } ans += mod; ans %= mod; cout << ans << endl; return 0; }
#include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_set> #include <vector> using namespace std; using namespace std::chrono; typedef long long int llint; typedef double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase /*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/ const llint mod = 998244353; const llint big = 2.19e15 + 1; const long double pai = 3.141592653589793238462643383279502884197; const long double eps = 1e-15; template <class T, class U> bool mineq(T &a, U b) { if (a > b) { a = b; return true; } return false; } template <class T, class U> bool maxeq(T &a, U b) { if (a < b) { a = b; return true; } return false; } llint gcd(llint a, llint b) { if (a % b == 0) { return b; } else return gcd(b, a % b); } llint lcm(llint a, llint b) { if (a == 0) { return b; } return a / gcd(a, b) * b; } template <class T> void SO(T &ve) { sort(ve.begin(), ve.end()); } template <class T> void REV(T &ve) { reverse(ve.begin(), ve.end()); } template <class T> llint LBI(vector<T> &ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); } template <class T> llint UBI(vector<T> &ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); } int main(void) { int n, i, j, wa = 0; cin >> n; llint ans = 1; llint dp[45301] = {0}; llint ep[45301] = {0}; dp[0] = 1; ep[0] = 1; for (i = 0; i < n; i++) { int x; cin >> x; wa += x; ans *= 3; ans %= mod; for (j = min(45000, i * 300); j >= 0; j--) { dp[j + x] += dp[j] * 2; dp[j + x] %= mod; ep[j + x] += ep[j]; ep[j + x] %= mod; } } // cerr<<"wa="<<wa<<endl; for (j = 0; j <= wa / 2; j++) { ans -= dp[j] * 3; ans %= mod; } if (wa % 2 == 0) { ans += ep[wa / 2] * 3; } ans += mod; ans %= mod; cout << ans << endl; return 0; }
replace
79
81
79
81
0
p03064
C++
Runtime Error
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for (int i = int(a); i < int(b); i++) #define rer(i, a, b) for (int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() { cerr << '\n'; } template <class FIRST, class... REST> void Debug(FIRST arg, REST... rest) { cerr << arg << " "; Debug(rest...); } template <class T> ostream &operator<<(ostream &out, const vector<T> &v) { out << "["; if (!v.empty()) { rep(i, 0, sz(v) - 1) out << v[i] << ", "; out << v.back(); } out << "]"; return out; } template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &v) { out << "(" << v.first << ", " << v.second << ")"; return out; } const int MAX_N = 300010; const int MAX_V = 100010; const double eps = 1e-6; const ll mod = 998244353; const int inf = 1 << 30; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; mt19937 rng; // use it by rng() % mod, shuffle(all(vec), rng) /////////////////////////////////////////////////////////////////////////////////////////////////// int N; int A[MAX_N]; ll dp[300][90010][2][2]; ll mod_pow(ll a, ll n) { if (n == 0) return 1; ll res = mod_pow(a, n / 2); if (n % 2 == 0) return res * res % mod; else return a * res % mod * res % mod; } void solve() { cin >> N; rep(i, 0, N) { cin >> A[i]; } int sum = accumulate(A, A + N, 0); sum = (sum + 1) / 2; dp[0][0][0][0] = 1; rep(i, 0, N) { rep(j, 0, 90000) { rep(k, 0, 2) { rep(l, 0, 2) { if (dp[i][j][k][l] == 0) continue; ADD(dp[i + 1][j][k | 1][l], dp[i][j][k][l]); ADD(dp[i + 1][j][k][l | 1], dp[i][j][k][l]); ADD(dp[i + 1][j + A[i]][k][l], dp[i][j][k][l]); } } } } ll ans = mod_pow(3, N); ADD(ans, mod - mod_pow(2, N) * 3 % mod); ADD(ans, 3); // debug(ans); rep(i, sum, 90000 + 1) { // if(i < 20)debug(sum, i, dp[N][i][1][1]); ADD(ans, mod - dp[N][i][1][1] * 3 % mod); } cout << ans << "\n"; } uint32_t rd() { uint32_t res; #ifdef __MINGW32__ asm volatile("rdrand %0" : "=a"(res)::"cc"); #else res = std::random_device()(); #endif return res; } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); cerr << fixed; cerr.precision(6); rng.seed(rd()); #ifdef LOCAL // freopen("in.txt", "wt", stdout); //for tester freopen("in.txt", "rt", stdin); #endif solve(); cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for (int i = int(a); i < int(b); i++) #define rer(i, a, b) for (int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() { cerr << '\n'; } template <class FIRST, class... REST> void Debug(FIRST arg, REST... rest) { cerr << arg << " "; Debug(rest...); } template <class T> ostream &operator<<(ostream &out, const vector<T> &v) { out << "["; if (!v.empty()) { rep(i, 0, sz(v) - 1) out << v[i] << ", "; out << v.back(); } out << "]"; return out; } template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &v) { out << "(" << v.first << ", " << v.second << ")"; return out; } const int MAX_N = 300010; const int MAX_V = 100010; const double eps = 1e-6; const ll mod = 998244353; const int inf = 1 << 30; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; mt19937 rng; // use it by rng() % mod, shuffle(all(vec), rng) /////////////////////////////////////////////////////////////////////////////////////////////////// int N; int A[MAX_N]; ll dp[310][90010][2][2]; ll mod_pow(ll a, ll n) { if (n == 0) return 1; ll res = mod_pow(a, n / 2); if (n % 2 == 0) return res * res % mod; else return a * res % mod * res % mod; } void solve() { cin >> N; rep(i, 0, N) { cin >> A[i]; } int sum = accumulate(A, A + N, 0); sum = (sum + 1) / 2; dp[0][0][0][0] = 1; rep(i, 0, N) { rep(j, 0, 90000) { rep(k, 0, 2) { rep(l, 0, 2) { if (dp[i][j][k][l] == 0) continue; ADD(dp[i + 1][j][k | 1][l], dp[i][j][k][l]); ADD(dp[i + 1][j][k][l | 1], dp[i][j][k][l]); ADD(dp[i + 1][j + A[i]][k][l], dp[i][j][k][l]); } } } } ll ans = mod_pow(3, N); ADD(ans, mod - mod_pow(2, N) * 3 % mod); ADD(ans, 3); // debug(ans); rep(i, sum, 90000 + 1) { // if(i < 20)debug(sum, i, dp[N][i][1][1]); ADD(ans, mod - dp[N][i][1][1] * 3 % mod); } cout << ans << "\n"; } uint32_t rd() { uint32_t res; #ifdef __MINGW32__ asm volatile("rdrand %0" : "=a"(res)::"cc"); #else res = std::random_device()(); #endif return res; } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); cerr << fixed; cerr.precision(6); rng.seed(rd()); #ifdef LOCAL // freopen("in.txt", "wt", stdout); //for tester freopen("in.txt", "rt", stdin); #endif solve(); cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
replace
54
55
54
55
-11
p03064
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i)) #define rep(i, n) FOR(i, 0, n) #define all(v) begin(v), end(v) #define debug(x) // std::cerr<<#x<<": "<<x<<"\n" #define debug2(x, y) // std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n" #define debug3( \ x, y, \ z) // std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n" using ll = long long; using vi = std::vector<int>; using vvi = std::vector<vi>; using vll = std::vector<ll>; using vvll = std::vector<vll>; template <typename T> using vvec = std::vector<std::vector<T>>; template <typename T> auto make_v(size_t sz) { return std::vector<T>(sz); } template <typename T, typename... Ts> auto make_v(size_t sz, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(sz, make_v<T>(ts...)); } template <typename T> void fill_v(T &var, const T &x) { var = x; } template <typename V, typename T> void fill_v(V &v, const T &x) { for (auto &&w : v) { fill_v(w, x); } } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<std::vector<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<std::deque<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::set<T> &v) { s << "\n"; for (auto &&elm : v) { s << elm << "\t"; } s << "\n"; return s; } inline void scan(int &a) { scanf("%d", &a); } inline void scan(ll &a) { scanf("%lld", &a); } inline void scan(char &a) { scanf(" %c", &a); } inline void scan(double &a) { scanf("%lf", &a); } inline void scan(std::string &s) { char BUF[3000000]; scanf(" %s", BUF); s = std::string(BUF); } template <typename T> inline void scan(std::vector<T> &v) { for (auto &&sv : v) { scan(sv); } } template <typename First, typename... Args> inline void scan(First &f, Args &...args) { scan(f); scan(args...); } inline void print(int a) { printf("%d\n", a); } inline void print(ll a) { printf("%lld\n", a); } inline void print(double a) { printf("%.12f\n", a); } inline void print(std::string s) { std::cout << s << "\n"; } using namespace std; void test() { int m = 50; int mm = m * (m + 1) / 2 + 10; vi a(m); rep(i, m) { a[i] = i + 1; } vvll dp(m + 1, vll(mm, 0)); dp[0][0] = 1; rep(i, m) { dp[i + 1] = dp[i]; rep(j, mm) { if (j + a[i] >= mm) { break; } dp[i + 1][j + a[i]] += dp[i][j]; } } debug(dp[m]); } int mod = 998244353; int main() { int n; scan(n); vi a(n); scan(a); int sum_all = 0; rep(i, n) { sum_all += a[i]; } vvll dp(n + 1, vll(sum_all + 1, 0)); dp[0][0] = 1; rep(i, n) { rep(j, sum_all + 1) { dp[i + 1][j] = dp[i][j] * 2 % mod; } rep(j, sum_all + 1) { int j2 = j + a[i]; if (j2 > sum_all) { break; } dp[i + 1][j2] = (dp[i + 1][j2] + dp[i][j]) % mod; } } ll ans = 1; rep(i, n) { ans = ans * 3 % mod; } int sum_half = (sum_all + 1) / 2; FOR(i, sum_half, sum_all + 1) { ans = (ans + (mod - dp[n][i]) * 3) % mod; } // debug(dp); if (sum_all % 2 == 0) { vvll dp2(n + 1, vll(sum_half + 1, 0)); dp2[0][0] = 1; rep(i, n) { dp2[i + 1] = dp2[i]; rep(j, sum_half + 1) { int j2 = j + a[i]; if (j2 > sum_half) { break; } dp2[i + 1][j2] = (dp2[i + 1][j2] + dp2[i][j]) % mod; } } // debug(dp2); ll target = dp2[n][sum_half] * 3; ans = (ans + target) % mod; } assert(ans > 0); print(ans); return 0; }
#include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i)) #define rep(i, n) FOR(i, 0, n) #define all(v) begin(v), end(v) #define debug(x) // std::cerr<<#x<<": "<<x<<"\n" #define debug2(x, y) // std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n" #define debug3( \ x, y, \ z) // std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n" using ll = long long; using vi = std::vector<int>; using vvi = std::vector<vi>; using vll = std::vector<ll>; using vvll = std::vector<vll>; template <typename T> using vvec = std::vector<std::vector<T>>; template <typename T> auto make_v(size_t sz) { return std::vector<T>(sz); } template <typename T, typename... Ts> auto make_v(size_t sz, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(sz, make_v<T>(ts...)); } template <typename T> void fill_v(T &var, const T &x) { var = x; } template <typename V, typename T> void fill_v(V &v, const T &x) { for (auto &&w : v) { fill_v(w, x); } } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<std::vector<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<T> &v) { int sz = v.size(); s << "\n"; rep(i, sz) { s << v[i]; if (i < sz - 1) { s << "\t"; } } s << "\n"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<std::deque<T>> &v) { for (auto &&w : v) { s << w; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::set<T> &v) { s << "\n"; for (auto &&elm : v) { s << elm << "\t"; } s << "\n"; return s; } inline void scan(int &a) { scanf("%d", &a); } inline void scan(ll &a) { scanf("%lld", &a); } inline void scan(char &a) { scanf(" %c", &a); } inline void scan(double &a) { scanf("%lf", &a); } inline void scan(std::string &s) { char BUF[3000000]; scanf(" %s", BUF); s = std::string(BUF); } template <typename T> inline void scan(std::vector<T> &v) { for (auto &&sv : v) { scan(sv); } } template <typename First, typename... Args> inline void scan(First &f, Args &...args) { scan(f); scan(args...); } inline void print(int a) { printf("%d\n", a); } inline void print(ll a) { printf("%lld\n", a); } inline void print(double a) { printf("%.12f\n", a); } inline void print(std::string s) { std::cout << s << "\n"; } using namespace std; void test() { int m = 50; int mm = m * (m + 1) / 2 + 10; vi a(m); rep(i, m) { a[i] = i + 1; } vvll dp(m + 1, vll(mm, 0)); dp[0][0] = 1; rep(i, m) { dp[i + 1] = dp[i]; rep(j, mm) { if (j + a[i] >= mm) { break; } dp[i + 1][j + a[i]] += dp[i][j]; } } debug(dp[m]); } int mod = 998244353; int main() { int n; scan(n); vi a(n); scan(a); int sum_all = 0; rep(i, n) { sum_all += a[i]; } vvll dp(n + 1, vll(sum_all + 1, 0)); dp[0][0] = 1; rep(i, n) { rep(j, sum_all + 1) { dp[i + 1][j] = dp[i][j] * 2 % mod; } rep(j, sum_all + 1) { int j2 = j + a[i]; if (j2 > sum_all) { break; } dp[i + 1][j2] = (dp[i + 1][j2] + dp[i][j]) % mod; } } ll ans = 1; rep(i, n) { ans = ans * 3 % mod; } int sum_half = (sum_all + 1) / 2; FOR(i, sum_half, sum_all + 1) { ans = (ans + (mod - dp[n][i]) * 3) % mod; } // debug(dp); if (sum_all % 2 == 0) { vvll dp2(n + 1, vll(sum_half + 1, 0)); dp2[0][0] = 1; rep(i, n) { dp2[i + 1] = dp2[i]; rep(j, sum_half + 1) { int j2 = j + a[i]; if (j2 > sum_half) { break; } dp2[i + 1][j2] = (dp2[i + 1][j2] + dp2[i][j]) % mod; } } // debug(dp2); ll target = dp2[n][sum_half] * 3; ans = (ans + target) % mod; } assert(ans >= 0); print(ans); return 0; }
replace
191
192
191
192
0
p03064
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> P; const LL M = 998244353; const int L = 300 * 300 + 1; LL dp[300][L]; LL dp2[300][L]; int main() { int N; cin >> N; dp[0][0] = 1; dp2[0][0] = 1; LL ret = 1; LL sum = 0; for (int i = 1; i <= N; i++) { ret *= 3; ret %= M; for (int j = 0; j < L; j++) { dp[i][j] = 2 * dp[i - 1][j]; dp[i][j] %= M; dp2[i][j] = dp2[i - 1][j]; } int v; cin >> v; sum += v; for (int j = 0; j + v < L; j++) { dp[i][j + v] += dp[i - 1][j]; dp[i][j + v] %= M; dp2[i][j + v] += dp2[i - 1][j]; dp2[i][j + v] %= M; } } // cerr << ret << ", " << sum << endl; for (int i = 0; i < L; i++) { if (i >= sum - i) { ret += M - (3 * dp[N][i] % M); ret %= M; } if (2 * i == sum) { // cerr << dp2[N][i] << endl; ret += 3 * dp2[N][i] % M; ret %= M; } } cout << ret << endl; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> P; const LL M = 998244353; const int L = 300 * 300 + 1; LL dp[301][L]; LL dp2[301][L]; int main() { int N; cin >> N; dp[0][0] = 1; dp2[0][0] = 1; LL ret = 1; LL sum = 0; for (int i = 1; i <= N; i++) { ret *= 3; ret %= M; for (int j = 0; j < L; j++) { dp[i][j] = 2 * dp[i - 1][j]; dp[i][j] %= M; dp2[i][j] = dp2[i - 1][j]; } int v; cin >> v; sum += v; for (int j = 0; j + v < L; j++) { dp[i][j + v] += dp[i - 1][j]; dp[i][j + v] %= M; dp2[i][j + v] += dp2[i - 1][j]; dp2[i][j + v] %= M; } } // cerr << ret << ", " << sum << endl; for (int i = 0; i < L; i++) { if (i >= sum - i) { ret += M - (3 * dp[N][i] % M); ret %= M; } if (2 * i == sum) { // cerr << dp2[N][i] << endl; ret += 3 * dp2[N][i] % M; ret %= M; } } cout << ret << endl; return 0; }
replace
31
33
31
33
-11
p03064
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = int_fast64_t; constexpr ll llmax = INT_FAST64_MAX; // std::numeric_limits<int_fast64_t>::max() constexpr ll llmin = INT_FAST64_MIN; // std::numeric_limits<int_fast64_t>::min() using ull = uint_fast64_t; constexpr ull ullmax = UINT_FAST64_MAX; // std::numeric_limits<uint_fast64_t>::max() #define FOR(i, b, e) for (int i = (b); i < (e); ++i) #define RFOR(i, b, e) for (int i = ((e)-1); (b) <= i; --i) #define REP(i, N) for (int i = 0; i < (N); ++i) #define RREP(i, N) for (int i = ((N)-1); 0 <= i; --i) #define scanInt(x) \ int x; \ scanf("%d", &(x)); \ getchar(); #define scanLLInt(x) \ ll x; \ scanf("%lld", &(x)); \ getchar(); #define scanVecInt(A, N) \ vector<int> A(N); \ REP(i, N) { \ scanf("%d", &(A[i])); \ getchar(); \ } #define scanVecLLInt(A, N) \ vector<ll> A(N); \ REP(i, N) { \ scanf("%lld", &(A[i])); \ getchar(); \ } constexpr int mod = 998244353; // modをとった和を返す inline uint modPlus(uint a, uint b) { return (a + b) % mod; } // modをとった差を返す inline uint modMinus(uint a, uint b) { return (mod + a - b) % mod; } // modをとった積を返す inline uint modMultiple(uint a, uint b) { return (static_cast<long long>(a) * b) % mod; } // 階乗数n!を最初に計算して、呼ばれた時に返す class Factorial { std::vector<uint> table; public: Factorial(uint max) : table(max) // max:テーブルのサイズ { if (max == 0) return; table[0] = 1; for (uint i = 1; i < max; ++i) { table[i] = modMultiple(table[i - 1], i + 1); } } uint operator()(int n) { if (n < 0) return 0; if (n == 0) return 1; return table[n - 1]; } }; // 階上数n!の逆数(逆元)を最初に計算して、呼ばれた時に返す class FactorialInverse { std::vector<uint> table; Factorial &fact; public: FactorialInverse(uint max, Factorial fact) : table(max), fact(fact) // max:テーブルのサイズ { if (max == 0) return; uint digit = 0; { uint temp = mod - 2; while (temp > 0) { temp >>= 1; ++digit; } } uint origin = fact(max); std::vector<uint> powerorigin2(digit); powerorigin2[0] = origin; for (uint i = 1; i < digit; ++i) { powerorigin2[i] = modMultiple(powerorigin2[i - 1], powerorigin2[i - 1]); } { uint table_max = 1; uint temp = mod - 2; for (uint i = 0; temp > 0; ++i, temp >>= 1) { if (!(temp & 1)) continue; table_max = modMultiple(table_max, powerorigin2[i]); } table[max - 1] = table_max; // origin^(mod - 2) } for (int i = max - 2; i >= 0; --i) { table[i] = modMultiple(table[i + 1], i + 2); } } uint operator()(int n) { if (n < 0) return 0; if (n == 0) return 1; return table[n - 1]; } }; // auto nCr = [&](uint n, uint r){ // return modMultiple(modMultiple(fact(n), factinv(r)), factinv(n - r)); // }; // N^(2 ^ i)を最初に計算して、呼ばれた時にN^xを計算して返す class PowerN { std::vector<uint> table; public: PowerN(uint N, uint max) // max:使いたい引数nの最大 { if (max == 0) return; table.resize(static_cast<uint>(floor(log2f(max))) + 1); table[0] = N; for (uint i = 1; i < table.size(); ++i) { table[i] = modMultiple(table[i - 1], table[i - 1]); // N ^ (2 ^ i) } } uint operator()(int n) { if (n < 0) return 0; if (n == 0) return 1; uint result = 1; for (uint i = 0; n; ++i, n >>= 1) { if (!(n & 1)) continue; result = modMultiple(result, table[i]); } return result; } }; int main() { scanInt(N); scanVecInt(A, N); const int sum = accumulate(A.begin(), A.end(), 0); const int limit = ((sum % 2 == 0) ? (sum / 2 - 1) : (sum / 2)); // array<int, 301> num_count; // for (auto& a : A){ // num_count[a]++; // } map<pair<int, int>, int> V; V[make_pair(0, 0)] = 1; int temp_sum = 0; for (auto &a : A) { map<pair<int, int>, int> V_old(V.begin(), V.end()); for (auto &e : V_old) { const auto s1 = e.first.first; const auto s2 = e.first.second; const auto s3 = temp_sum - s1 - s2; if (s1 + a <= limit) V[make_pair(s1 + a, s2)] = modPlus(V[make_pair(s1 + a, s2)], e.second); if (s2 + a <= limit) V[make_pair(s1, s2 + a)] = modPlus(V[make_pair(s1, s2 + a)], e.second); if (limit < s3 + a) V.erase(make_pair(s1, s2)); } temp_sum += a; } // for (auto& e : V){ // cout << e.first.first << " " << e.first.second << " : " << e.second << // endl; // } int result = 0; for (auto &e : V) { const auto s1 = e.first.first; const auto s2 = e.first.second; const auto s3 = sum - s1 - s2; if (1 <= s1 && 1 <= s2 && 1 <= s3 && s1 <= limit && s2 <= limit && s3 <= limit) result = modPlus(result, e.second); } cout << result << endl; // vector<int> V(sum + 1, 0); // V[0] = 1; // for (auto& a : A){ // vector V_old(V.begin(), V.end()); // REP(i, V.size()){ // if (i + a < V.size()){ // V[i + a] += V_old[i]; // } // } // } // REP(i, V.size()){ // cout << i << " : " << V[i] << endl; // } // PowerN pow3(3, N); // for (int s1 = max(1, sum / 3); s1 <= limit; s1++){ // for (int s2 = max({1, sum - limit - s1, (sum - s1) / 2}); s2 <= min(s1, // sum - 1 - s1); s2++){ // const int s3 = sum - s1 - s2; // if (s3 < 1 || limit < s3 || s2 < s3) continue; // // cout << s1 << " " << s2 << " " << s3 << endl; // } // } }
#include <bits/stdc++.h> using namespace std; using ll = int_fast64_t; constexpr ll llmax = INT_FAST64_MAX; // std::numeric_limits<int_fast64_t>::max() constexpr ll llmin = INT_FAST64_MIN; // std::numeric_limits<int_fast64_t>::min() using ull = uint_fast64_t; constexpr ull ullmax = UINT_FAST64_MAX; // std::numeric_limits<uint_fast64_t>::max() #define FOR(i, b, e) for (int i = (b); i < (e); ++i) #define RFOR(i, b, e) for (int i = ((e)-1); (b) <= i; --i) #define REP(i, N) for (int i = 0; i < (N); ++i) #define RREP(i, N) for (int i = ((N)-1); 0 <= i; --i) #define scanInt(x) \ int x; \ scanf("%d", &(x)); \ getchar(); #define scanLLInt(x) \ ll x; \ scanf("%lld", &(x)); \ getchar(); #define scanVecInt(A, N) \ vector<int> A(N); \ REP(i, N) { \ scanf("%d", &(A[i])); \ getchar(); \ } #define scanVecLLInt(A, N) \ vector<ll> A(N); \ REP(i, N) { \ scanf("%lld", &(A[i])); \ getchar(); \ } constexpr int mod = 998244353; // modをとった和を返す inline uint modPlus(uint a, uint b) { return (a + b) % mod; } // modをとった差を返す inline uint modMinus(uint a, uint b) { return (mod + a - b) % mod; } // modをとった積を返す inline uint modMultiple(uint a, uint b) { return (static_cast<long long>(a) * b) % mod; } // 階乗数n!を最初に計算して、呼ばれた時に返す class Factorial { std::vector<uint> table; public: Factorial(uint max) : table(max) // max:テーブルのサイズ { if (max == 0) return; table[0] = 1; for (uint i = 1; i < max; ++i) { table[i] = modMultiple(table[i - 1], i + 1); } } uint operator()(int n) { if (n < 0) return 0; if (n == 0) return 1; return table[n - 1]; } }; // 階上数n!の逆数(逆元)を最初に計算して、呼ばれた時に返す class FactorialInverse { std::vector<uint> table; Factorial &fact; public: FactorialInverse(uint max, Factorial fact) : table(max), fact(fact) // max:テーブルのサイズ { if (max == 0) return; uint digit = 0; { uint temp = mod - 2; while (temp > 0) { temp >>= 1; ++digit; } } uint origin = fact(max); std::vector<uint> powerorigin2(digit); powerorigin2[0] = origin; for (uint i = 1; i < digit; ++i) { powerorigin2[i] = modMultiple(powerorigin2[i - 1], powerorigin2[i - 1]); } { uint table_max = 1; uint temp = mod - 2; for (uint i = 0; temp > 0; ++i, temp >>= 1) { if (!(temp & 1)) continue; table_max = modMultiple(table_max, powerorigin2[i]); } table[max - 1] = table_max; // origin^(mod - 2) } for (int i = max - 2; i >= 0; --i) { table[i] = modMultiple(table[i + 1], i + 2); } } uint operator()(int n) { if (n < 0) return 0; if (n == 0) return 1; return table[n - 1]; } }; // auto nCr = [&](uint n, uint r){ // return modMultiple(modMultiple(fact(n), factinv(r)), factinv(n - r)); // }; // N^(2 ^ i)を最初に計算して、呼ばれた時にN^xを計算して返す class PowerN { std::vector<uint> table; public: PowerN(uint N, uint max) // max:使いたい引数nの最大 { if (max == 0) return; table.resize(static_cast<uint>(floor(log2f(max))) + 1); table[0] = N; for (uint i = 1; i < table.size(); ++i) { table[i] = modMultiple(table[i - 1], table[i - 1]); // N ^ (2 ^ i) } } uint operator()(int n) { if (n < 0) return 0; if (n == 0) return 1; uint result = 1; for (uint i = 0; n; ++i, n >>= 1) { if (!(n & 1)) continue; result = modMultiple(result, table[i]); } return result; } }; int main() { scanInt(N); scanVecInt(A, N); const int sum = accumulate(A.begin(), A.end(), 0); const int limit = ((sum % 2 == 0) ? (sum / 2 - 1) : (sum / 2)); PowerN pow3(3, N); const int n_over = [&]() { vector<int> V(sum + 1, 0); V[0] = 1; for (auto &a : A) { decltype(V) V_old(V.begin(), V.end()); REP(i, V.size()) { if (i + a < V.size()) { V[i] = modPlus(V[i], V_old[i]); V[i + a] = modPlus(V[i + a], V_old[i]); } } } int ret = 0; for (int i = limit + 1; i < V.size(); i++) { ret = modPlus(ret, V[i]); } return ret; }(); if (sum % 2 == 0) { const int line = sum / 2; const int n_line = [&]() { vector<int> V(line + 1, 0); V[0] = 1; for (auto &a : A) { decltype(V) V_old(V.begin(), V.end()); REP(i, V.size()) { if (i + a < V.size()) { V[i + a] = modPlus(V[i + a], V_old[i]); } } } return V[line]; }(); cout << modPlus(modMinus(pow3(N), modMultiple(n_over, 3)), modMultiple(n_line, 3)) << endl; } else { cout << modMinus(pow3(N), modMultiple(n_over, 3)) << endl; } }
replace
164
226
164
205
TLE
p03064
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define int long long #define x first #define y second #define all(aaa) (aaa).begin(), (aaa).end() #define REP(i, sss, eee) for (int i = sss; i <= eee; ++i) #define pb push_back #define pii pair<int, int> #define vi vector<int> #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define N 998244353 #define inf 1000000000000000000 using namespace __gnu_pbds; using namespace std; template <class T> T MAX(T a, T b) { return ((a > b) ? a : b); } template <class T> T MIN(T a, T b) { return ((a < b) ? a : b); } template <class T> T MOD(T a) { return ((a >= 0) ? a : (-1 * a)); } template <class T> void SWAP(T &a, T &b) { T temp = a; a = b; b = temp; } typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for multiset use less_equal above inline int ex(int a, int b) { if (b == 0 || a == 1) { return 1; } if (a == 0 || b == 1) { return a; } int tmp = ex(a, (b / 2)); if (b % 2) { return ((((tmp * tmp) % N) * a) % N); } else { return ((tmp * tmp) % N); } } inline int inv(int k) { if (k == 1) { return 1; } else { return ex(k, N - 2); } } /*****************default********************/ int solve() { int n; cin >> n; int ans = ex(3, n); vi inp(n + 1, 0); int sum = 0; REP(i, 1, n) { cin >> inp[i]; sum += inp[i]; } std::vector<std::vector<int>> dp(n + 1, std::vector<int>(sum + 1, 0)); dp[0][0] = 1; REP(i, 1, n) { REP(red, 0, sum) { int prev = red - inp[i]; dp[i][red] = ((dp[i - 1][red] * 2) + ((prev >= 0) ? dp[i - 1][prev] : 0)); dp[i][red] %= N; } } if (!(sum % 2)) { int st = sum / 2; REP(i, st, sum) { ans -= (dp[n][i] * 3); ans %= N; } std::vector<std::vector<int>> dp2(n + 1, std::vector<int>(sum, 0)); dp2[0][0] = 1; REP(i, 1, n) { REP(red, 0, sum) { int prev = red - inp[i]; dp2[i][red] = (dp2[i - 1][red] + ((prev >= 0) ? dp2[i - 1][prev] : 0)); dp2[i][red] %= N; } } ans += (3 * dp2[n][sum / 2]); ans %= N; } else { int st = ((sum / 2) + 1); REP(i, st, sum) { ans -= (dp[n][i] * 3); ans %= N; } } ans += N; ans %= N; cout << ans << "\n"; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif speed int tt = 1; // cin>>tt; while (tt--) { solve(); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define int long long #define x first #define y second #define all(aaa) (aaa).begin(), (aaa).end() #define REP(i, sss, eee) for (int i = sss; i <= eee; ++i) #define pb push_back #define pii pair<int, int> #define vi vector<int> #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define N 998244353 #define inf 1000000000000000000 using namespace __gnu_pbds; using namespace std; template <class T> T MAX(T a, T b) { return ((a > b) ? a : b); } template <class T> T MIN(T a, T b) { return ((a < b) ? a : b); } template <class T> T MOD(T a) { return ((a >= 0) ? a : (-1 * a)); } template <class T> void SWAP(T &a, T &b) { T temp = a; a = b; b = temp; } typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for multiset use less_equal above inline int ex(int a, int b) { if (b == 0 || a == 1) { return 1; } if (a == 0 || b == 1) { return a; } int tmp = ex(a, (b / 2)); if (b % 2) { return ((((tmp * tmp) % N) * a) % N); } else { return ((tmp * tmp) % N); } } inline int inv(int k) { if (k == 1) { return 1; } else { return ex(k, N - 2); } } /*****************default********************/ int solve() { int n; cin >> n; int ans = ex(3, n); vi inp(n + 1, 0); int sum = 0; REP(i, 1, n) { cin >> inp[i]; sum += inp[i]; } std::vector<std::vector<int>> dp(n + 1, std::vector<int>(sum + 1, 0)); dp[0][0] = 1; REP(i, 1, n) { REP(red, 0, sum) { int prev = red - inp[i]; dp[i][red] = ((dp[i - 1][red] * 2) + ((prev >= 0) ? dp[i - 1][prev] : 0)); dp[i][red] %= N; } } if (!(sum % 2)) { int st = sum / 2; REP(i, st, sum) { ans -= (dp[n][i] * 3); ans %= N; } std::vector<std::vector<int>> dp2(n + 1, std::vector<int>(sum, 0)); dp2[0][0] = 1; REP(i, 1, n) { REP(red, 0, sum) { int prev = red - inp[i]; dp2[i][red] = (dp2[i - 1][red] + ((prev >= 0) ? dp2[i - 1][prev] : 0)); dp2[i][red] %= N; } } ans += (3 * dp2[n][sum / 2]); ans %= N; } else { int st = ((sum / 2) + 1); REP(i, st, sum) { ans -= (dp[n][i] * 3); ans %= N; } } ans += N; ans %= N; cout << ans << "\n"; } signed main() { speed int tt = 1; // cin>>tt; while (tt--) { solve(); } return 0; }
delete
101
105
101
101
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03064
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <sstream> #include <string> #include <vector> using namespace std; long long MOD = 998244353L; long long pow(int a, int n) { long long ret = 1; for (int i = 0; i < n; i++) { ret = (ret * a) % MOD; } return ret; } map<int, long long> memo; long long doit(vector<int> &a, int n, int suma, int index, int s) { if (s * 2 > suma) { return 0; } if (index >= n) { return 3; } int key = s * n + index; if (memo.find(key) == memo.end()) { memo[key] = (doit(a, n, suma, index + 1, s + a[index]) * 2 + doit(a, n, suma, index + 1, s)) % MOD; } return memo[key]; } map<int, long long> memo2; long long doit2(vector<int> &a, int n, int suma, int index, int s) { if (s * 2 > suma) { return 0; } if (index >= n) { return (s * 2 == suma) ? 3 : 0; } int key = s * n + index; if (memo2.find(key) == memo2.end()) { memo2[key] = (doit2(a, n, suma, index + 1, s + a[index]) + doit2(a, n, suma, index + 1, s)) % MOD; } return memo2[key]; } int main() { int n; cin >> n; vector<int> a(n); int suma = 0; for (int i = 0; i < n; i++) { cin >> a[i]; suma += a[i]; } long long ret = (pow(3, n) - doit(a, n, suma, 0, 0) + doit2(a, n, suma, 0, 0) + MOD) % MOD; cout << ret << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <sstream> #include <string> #include <vector> using namespace std; long long MOD = 998244353L; long long pow(int a, int n) { long long ret = 1; for (int i = 0; i < n; i++) { ret = (ret * a) % MOD; } return ret; } map<int, long long> memo; long long doit(vector<int> &a, int n, int suma, int index, int s) { if (s * 2 > suma) { return 0; } if (index >= n) { return 3; } int key = s * n + index; if (memo.find(key) == memo.end()) { memo[key] = (doit(a, n, suma, index + 1, s + a[index]) * 2 + doit(a, n, suma, index + 1, s)) % MOD; } return memo[key]; } map<int, long long> memo2; long long doit2(vector<int> &a, int n, int suma, int index, int s) { if (s * 2 > suma) { return 0; } if (index >= n) { return (s * 2 == suma) ? 3 : 0; } int key = s * n + index; if (memo2.find(key) == memo2.end()) { memo2[key] = (doit2(a, n, suma, index + 1, s + a[index]) + doit2(a, n, suma, index + 1, s)) % MOD; } return memo2[key]; } int main() { int n; cin >> n; vector<int> a(n); int suma = 0; for (int i = 0; i < n; i++) { cin >> a[i]; suma += a[i]; } vector<long long> dp1(suma + 1, 0); vector<long long> dp2(suma + 1, 0); dp1[0] = 3; dp2[0] = 3; for (int i = 0; i < n; i++) { vector<long long> next1(suma + 1, 0); vector<long long> next2(suma + 1, 0); for (int j = 0; j * 2 <= suma; j++) { next1[j] = (dp1[j] + (j >= a[i] ? dp1[j - a[i]] * 2 : 0)) % MOD; next2[j] = (dp2[j] + (j >= a[i] ? dp2[j - a[i]] : 0)) % MOD; } dp1 = next1; dp2 = next2; } long long ret = pow(3, n); for (int j = 0; j * 2 <= suma; j++) { ret = (ret - dp1[j] + MOD) % MOD; } if (suma % 2 == 0) { ret = (ret + dp2[suma / 2]) % MOD; } cout << ret << endl; return 0; }
replace
73
76
73
94
TLE
p03064
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 998244353; void add(int &x, int y) { x = (x + y) % mod; } int ksm(int b, int n) { int res = 1; while (n) { if (n & 1) res = 1ll * res * b % mod; b = 1ll * b * b % mod; n >>= 1; } return res; } int f[100005], a[105]; signed main() { int n, sum = 0; cin >> n; f[0] = 1; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum += a[i]; for (int j = sum; j >= a[i]; --j) add(f[j], f[j - a[i]] + f[j - a[i]]); // cout<<f[1]<<endl; } int ans = ksm(3, n), res = 0; // cout<<sum<<endl; for (int i = 0; i <= sum / 2; ++i) add(res, f[i]); // cout<<ans<<" "<<res<<endl; res = res * 3ll % mod; add(ans, mod - res); memset(f, 0, sizeof(f)); f[0] = 1; sum = 0; for (int i = 1; i <= n; ++i) { sum += a[i]; for (int j = sum; j >= a[i]; --j) add(f[j], f[j - a[i]]); } if (sum % 2 == 0) add(ans, 3ll * f[sum / 2]); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 998244353; void add(int &x, int y) { x = (x + y) % mod; } int ksm(int b, int n) { int res = 1; while (n) { if (n & 1) res = 1ll * res * b % mod; b = 1ll * b * b % mod; n >>= 1; } return res; } int f[100005], a[305]; signed main() { int n, sum = 0; cin >> n; f[0] = 1; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum += a[i]; for (int j = sum; j >= a[i]; --j) add(f[j], f[j - a[i]] + f[j - a[i]]); // cout<<f[1]<<endl; } int ans = ksm(3, n), res = 0; // cout<<sum<<endl; for (int i = 0; i <= sum / 2; ++i) add(res, f[i]); // cout<<ans<<" "<<res<<endl; res = res * 3ll % mod; add(ans, mod - res); memset(f, 0, sizeof(f)); f[0] = 1; sum = 0; for (int i = 1; i <= n; ++i) { sum += a[i]; for (int j = sum; j >= a[i]; --j) add(f[j], f[j - a[i]]); } if (sum % 2 == 0) add(ans, 3ll * f[sum / 2]); cout << ans; return 0; }
replace
15
16
15
16
0
p03065
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define lowbit(x) (x) & (-x) #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) #define maxd 1000000007 typedef long long ll; const int N = 100000; const double pi = acos(-1.0); int n, tot = 0, pri[1001000], a[10100], tax[10100]; bool ispri[10100]; set<int> ans; int read() { int x = 0, f = 1; char ch = getchar(); while ((ch < '0') || (ch > '9')) { if (ch == '-') f = -1; ch = getchar(); } while ((ch >= '0') && (ch <= '9')) { x = x * 10 + (ch - '0'); ch = getchar(); } return x * f; } void sieve(int n) { rep(i, 2, n) { if (!ispri[i]) pri[++tot] = i; int j; for (j = 1; j <= tot && i * pri[j] <= n; j++) { ispri[i * pri[j]] = 1; if (i % pri[j] == 0) break; } } } int gcd(int x, int y) { if (!y) return x; else return gcd(y, x % y); } bool chk(int p) { if (a[0] % p) return 0; rep(i, 0, p - 2) tax[i] = 0; rep(i, 0, n) tax[i % (p - 1)] = (tax[a[i] % (p - 1)] + a[i]) % p; rep(i, 0, p - 2) if (tax[i]) return 0; return 1; } int main() { n = read(); sieve(n); per(i, n, 0) a[i] = read(); int now = 0; rep(i, 0, n) { if (a[i]) { if (!now) now = abs(a[i]); else now = gcd(abs(a[i]), now); } } now = abs(now); int rest = now, i; for (i = 2; i * i <= now; i++) { if (rest % i) continue; while (rest % i == 0) rest /= i; ans.insert(i); } if (rest > 1) ans.insert(rest); rep(i, 1, tot) if (chk(pri[i])) ans.insert(pri[i]); set<int>::iterator it = ans.begin(); while (it != ans.end()) { printf("%d\n", *it); it++; } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define lowbit(x) (x) & (-x) #define rep(i, a, b) for (int i = a; i <= b; i++) #define per(i, a, b) for (int i = a; i >= b; i--) #define maxd 1000000007 typedef long long ll; const int N = 100000; const double pi = acos(-1.0); int n, tot = 0, pri[1001000], a[10100], tax[10100]; bool ispri[10100]; set<int> ans; int read() { int x = 0, f = 1; char ch = getchar(); while ((ch < '0') || (ch > '9')) { if (ch == '-') f = -1; ch = getchar(); } while ((ch >= '0') && (ch <= '9')) { x = x * 10 + (ch - '0'); ch = getchar(); } return x * f; } void sieve(int n) { rep(i, 2, n) { if (!ispri[i]) pri[++tot] = i; int j; for (j = 1; j <= tot && i * pri[j] <= n; j++) { ispri[i * pri[j]] = 1; if (i % pri[j] == 0) break; } } } int gcd(int x, int y) { if (!y) return x; else return gcd(y, x % y); } bool chk(int p) { if (a[0] % p) return 0; rep(i, 0, p - 2) tax[i] = 0; rep(i, 0, n) tax[i % (p - 1)] = (tax[i % (p - 1)] + a[i]) % p; rep(i, 0, p - 2) if (tax[i]) return 0; return 1; } int main() { n = read(); sieve(n); per(i, n, 0) a[i] = read(); int now = 0; rep(i, 0, n) { if (a[i]) { if (!now) now = abs(a[i]); else now = gcd(abs(a[i]), now); } } now = abs(now); int rest = now, i; for (i = 2; i * i <= now; i++) { if (rest % i) continue; while (rest % i == 0) rest /= i; ans.insert(i); } if (rest > 1) ans.insert(rest); rep(i, 1, tot) if (chk(pri[i])) ans.insert(pri[i]); set<int>::iterator it = ans.begin(); while (it != ans.end()) { printf("%d\n", *it); it++; } return 0; }
replace
61
62
61
62
0
p03065
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // type alias typedef long long LL; typedef pair<int, int> II; typedef tuple<int, int, int> III; typedef vector<int> VI; typedef vector<string> VS; typedef unordered_map<int, int> MAPII; typedef unordered_set<int> SETI; template <class T> using VV = vector<vector<T>>; // minmax template <class T> inline T SMIN(T &a, const T b) { return a = (a > b) ? b : a; } template <class T> inline T SMAX(T &a, const T b) { return a = (a < b) ? b : a; } // repetition #define FORE(i, a, b) for (int i = (a); i <= (b); ++i) #define REPE(i, n) for (int i = 0; i <= (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define FORR(x, arr) for (auto &x : arr) #define SZ(a) int((a).size()) // collection #define ALL(c) (c).begin(), (c).end() // DP #define MINUS(dp) memset(dp, -1, sizeof(dp)) #define ZERO(dp) memset(dp, 0, sizeof(dp)) // stdout #define println(args...) fprintf(stdout, ##args), putchar('\n'); // debug cerr template <class Iter> void __kumaerrc(Iter begin, Iter end) { for (; begin != end; ++begin) { cerr << *begin << ','; } cerr << endl; } void __kumaerr(istream_iterator<string> it) { (void)it; cerr << endl; } template <typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr << *it << "=" << a << ", ", __kumaerr(++it, args...); } template <typename S, typename T> std::ostream &operator<<(std::ostream &_os, const std::pair<S, T> &_p) { return _os << "{" << _p.first << ',' << _p.second << "}"; } #define __KUMATRACE__ true #ifdef __KUMATRACE__ #define dump(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ __kumaerr(_it, args); \ } #define dumpc(ar) \ { \ cerr << #ar << ": "; \ FORR(x, (ar)) { cerr << x << ','; } \ cerr << endl; \ } #define dumpC(beg, end) \ { \ cerr << "~" << #end << ": "; \ __kumaerrc(beg, end); \ } #else #define dump(args...) #define dumpc(ar) #define dumpC(beg, end) #endif // $ cp-batch PolynomialDivisors | diff PolynomialDivisors.out - // $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address // PolynomialDivisors.cpp && ./a.out /* 4/22/2019 14:03-14:30 give up polynomial <=> ? (How can we use this conditin?) ∀x s.t. pred(x) <=> ? (How can we use ∀x condition?) 14:30- read editorials It turns out that first step is a|b <=> b≡0 (mod a) http://drken1215.hatenablog.com/entry/2019/04/21/004100 https://qiita.com/drken/items/6b4031ccbb2cab7436f3 */ const int MAX_N = 1e4 + 1; LL A[MAX_N]; int N; LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); } vector<int> sieve(int N) { if (N <= 0) return {}; vector<int> fs(N + 1, true); fs[0] = fs[1] = false; for (int p = 2; p * p <= N; ++p) if (fs[p]) { for (int q = p * p; q <= N; q += p) fs[q] = false; } vector<int> res; for (int n = 2; n <= N; ++n) if (fs[n]) res.push_back(n); return res; } vector<LL> primeFactors(LL n) { assert(n >= 1); vector<LL> res; for (LL p = 2; p * p <= n; ++p) while (n % p == 0) { res.push_back(p); n /= p; } if (n > 1) res.push_back(n); return res; } void solve() { set<LL> res; LL g = A[0]; REP(i, N + 1) g = gcd(g, A[i]); vector<LL> X = primeFactors(g); FORR(a, X) res.emplace(a); vector<int> P = sieve(N); // dumpc(P); FORR(p, P) { vector<LL> C(p); REP(n, p) C[n] = A[n] % p; FORE(n, p, N) { int nn = n % (p - 1); if (nn == 0) nn = p - 1; C[nn] = (C[nn] + A[n] % p) % p; } bool ok = true; REP(i, p) ok &= (C[i] % p == 0); if (ok) res.emplace(p); } FORR(p, res) cout << p << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << setprecision(12) << fixed; cin >> N; REP(i, N + 1) cin >> A[i]; reverse(A, A + N + 1); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; // type alias typedef long long LL; typedef pair<int, int> II; typedef tuple<int, int, int> III; typedef vector<int> VI; typedef vector<string> VS; typedef unordered_map<int, int> MAPII; typedef unordered_set<int> SETI; template <class T> using VV = vector<vector<T>>; // minmax template <class T> inline T SMIN(T &a, const T b) { return a = (a > b) ? b : a; } template <class T> inline T SMAX(T &a, const T b) { return a = (a < b) ? b : a; } // repetition #define FORE(i, a, b) for (int i = (a); i <= (b); ++i) #define REPE(i, n) for (int i = 0; i <= (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define FORR(x, arr) for (auto &x : arr) #define SZ(a) int((a).size()) // collection #define ALL(c) (c).begin(), (c).end() // DP #define MINUS(dp) memset(dp, -1, sizeof(dp)) #define ZERO(dp) memset(dp, 0, sizeof(dp)) // stdout #define println(args...) fprintf(stdout, ##args), putchar('\n'); // debug cerr template <class Iter> void __kumaerrc(Iter begin, Iter end) { for (; begin != end; ++begin) { cerr << *begin << ','; } cerr << endl; } void __kumaerr(istream_iterator<string> it) { (void)it; cerr << endl; } template <typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr << *it << "=" << a << ", ", __kumaerr(++it, args...); } template <typename S, typename T> std::ostream &operator<<(std::ostream &_os, const std::pair<S, T> &_p) { return _os << "{" << _p.first << ',' << _p.second << "}"; } #define __KUMATRACE__ true #ifdef __KUMATRACE__ #define dump(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ __kumaerr(_it, args); \ } #define dumpc(ar) \ { \ cerr << #ar << ": "; \ FORR(x, (ar)) { cerr << x << ','; } \ cerr << endl; \ } #define dumpC(beg, end) \ { \ cerr << "~" << #end << ": "; \ __kumaerrc(beg, end); \ } #else #define dump(args...) #define dumpc(ar) #define dumpC(beg, end) #endif // $ cp-batch PolynomialDivisors | diff PolynomialDivisors.out - // $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address // PolynomialDivisors.cpp && ./a.out /* 4/22/2019 14:03-14:30 give up polynomial <=> ? (How can we use this conditin?) ∀x s.t. pred(x) <=> ? (How can we use ∀x condition?) 14:30- read editorials It turns out that first step is a|b <=> b≡0 (mod a) http://drken1215.hatenablog.com/entry/2019/04/21/004100 https://qiita.com/drken/items/6b4031ccbb2cab7436f3 */ const int MAX_N = 1e4 + 1; LL A[MAX_N]; int N; LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); } vector<int> sieve(int N) { if (N <= 0) return {}; vector<int> fs(N + 1, true); fs[0] = fs[1] = false; for (int p = 2; p * p <= N; ++p) if (fs[p]) { for (int q = p * p; q <= N; q += p) fs[q] = false; } vector<int> res; for (int n = 2; n <= N; ++n) if (fs[n]) res.push_back(n); return res; } vector<LL> primeFactors(LL n) { assert(n >= 1); vector<LL> res; for (LL p = 2; p * p <= n; ++p) while (n % p == 0) { res.push_back(p); n /= p; } if (n > 1) res.push_back(n); return res; } void solve() { set<LL> res; LL g = A[0]; REP(i, N + 1) g = gcd(abs(g), abs(A[i])); vector<LL> X = primeFactors(g); FORR(a, X) res.emplace(a); vector<int> P = sieve(N); // dumpc(P); FORR(p, P) { vector<LL> C(p); REP(n, p) C[n] = A[n] % p; FORE(n, p, N) { int nn = n % (p - 1); if (nn == 0) nn = p - 1; C[nn] = (C[nn] + A[n] % p) % p; } bool ok = true; REP(i, p) ok &= (C[i] % p == 0); if (ok) res.emplace(p); } FORR(p, res) cout << p << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << setprecision(12) << fixed; cin >> N; REP(i, N + 1) cin >> A[i]; reverse(A, A + N + 1); solve(); return 0; }
replace
138
139
138
139
0
p03065
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) typedef long long ll; bool isNotPrime[100000]; int primes[100000]; int nPrime; inline ll calc(const vector<ll> &vs, ll x, int p) { int n = vs.size() - 1; ll res = vs[0] % p; REP(i, n) { res = res * x % p; res = (res + vs[i + 1]) % p; } return res; } const int T = 1000; bool isOK2(const vector<ll> &vs, int p) { int n = vs.size() - 1; vector<ll> vs2(min(p, n + 1), 0); REP(i, n + 1) { vs2[(n - i) % (p - 1)] += vs[i]; } REP(i, vs2.size()) { if (vs[i] % p != 0) { return false; } } return true; } bool isOK(const vector<ll> &vs, int p) { int n = vs.size() - 1; if (isOK2(vs, p)) { return true; } if (p < T) { REP(c, p) { if (calc(vs, c, p) != 0) { return false; } } } else { REP(t, T) { int c = rand() % p; // cerr << ">>" << c << endl; if (calc(vs, c, p) != 0) { return false; } } } return true; } // 定数項が0でない場合 set<int> solve1(const vector<ll> &vs) { int n = vs.size() - 1; vector<int> ps; { int cur = abs(vs[n]); REP(i, nPrime) { int p = primes[i]; if (p * p > cur) { break; } if (cur % p == 0) { ps.push_back(p); while (cur % p == 0) { cur /= p; } } } if (cur > 1) { ps.push_back(cur); } } set<int> res; REP(i, ps.size()) { if (isOK(vs, ps[i])) { res.insert(ps[i]); } } return res; } // 定数項が0かもしれない場合 // x*(x+1)*(2x+1) が2,3で割り切れる、みたいなのをケアが必要... // あと、 x * (普通) みたいな...そっちはsolve1でケアすれば良いか set<int> solve2(const vector<ll> &vs) { int n = vs.size() - 1; set<int> res1; { int zeros = 0; REP(i, n) { if (vs[n - i] == 0) { zeros++; } else { break; } } if (zeros > 0) { vector<ll> vs2; REP(i, n + 1 - zeros) { vs2.push_back(vs[i]); } res1 = solve1(vs2); } } set<int> res2; REP(p, n + 1) { if (isNotPrime[p]) { continue; } bool ok = true; if (p < T) { REP(c, p) { if (calc(vs, c, p) != 0) { ok = false; break; } } } else { REP(t, T) { int c = rand() % p; if (calc(vs, c, p) != 0) { ok = false; break; } } } if (ok) { res2.insert(p); } } set<int> res; for (int p : res1) { res.insert(p); } for (int p : res2) { res.insert(p); } return res; } int main(void) { isNotPrime[0] = isNotPrime[1] = true; REP(i, 100000) { if (!isNotPrime[i]) { primes[nPrime++] = i; for (int j = i + i; j < 100000; j += i) { isNotPrime[j] = true; } } } int n; scanf("%d", &n); vector<ll> vs; REP(i, n + 1) { ll v; scanf("%lld", &v); vs.push_back(v); } set<int> res; if (vs[n] == 0) { res = solve2(vs); } else { res = solve1(vs); } for (int p : res) { printf("%d\n", p); } return 0; }
#include <algorithm> #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) typedef long long ll; bool isNotPrime[100000]; int primes[100000]; int nPrime; inline ll calc(const vector<ll> &vs, ll x, int p) { int n = vs.size() - 1; ll res = vs[0] % p; REP(i, n) { res = res * x % p; res = (res + vs[i + 1]) % p; } return res; } const int T = 100; bool isOK2(const vector<ll> &vs, int p) { int n = vs.size() - 1; vector<ll> vs2(min(p, n + 1), 0); REP(i, n + 1) { vs2[(n - i) % (p - 1)] += vs[i]; } REP(i, vs2.size()) { if (vs[i] % p != 0) { return false; } } return true; } bool isOK(const vector<ll> &vs, int p) { int n = vs.size() - 1; if (isOK2(vs, p)) { return true; } if (p < T) { REP(c, p) { if (calc(vs, c, p) != 0) { return false; } } } else { REP(t, T) { int c = rand() % p; // cerr << ">>" << c << endl; if (calc(vs, c, p) != 0) { return false; } } } return true; } // 定数項が0でない場合 set<int> solve1(const vector<ll> &vs) { int n = vs.size() - 1; vector<int> ps; { int cur = abs(vs[n]); REP(i, nPrime) { int p = primes[i]; if (p * p > cur) { break; } if (cur % p == 0) { ps.push_back(p); while (cur % p == 0) { cur /= p; } } } if (cur > 1) { ps.push_back(cur); } } set<int> res; REP(i, ps.size()) { if (isOK(vs, ps[i])) { res.insert(ps[i]); } } return res; } // 定数項が0かもしれない場合 // x*(x+1)*(2x+1) が2,3で割り切れる、みたいなのをケアが必要... // あと、 x * (普通) みたいな...そっちはsolve1でケアすれば良いか set<int> solve2(const vector<ll> &vs) { int n = vs.size() - 1; set<int> res1; { int zeros = 0; REP(i, n) { if (vs[n - i] == 0) { zeros++; } else { break; } } if (zeros > 0) { vector<ll> vs2; REP(i, n + 1 - zeros) { vs2.push_back(vs[i]); } res1 = solve1(vs2); } } set<int> res2; REP(p, n + 1) { if (isNotPrime[p]) { continue; } bool ok = true; if (p < T) { REP(c, p) { if (calc(vs, c, p) != 0) { ok = false; break; } } } else { REP(t, T) { int c = rand() % p; if (calc(vs, c, p) != 0) { ok = false; break; } } } if (ok) { res2.insert(p); } } set<int> res; for (int p : res1) { res.insert(p); } for (int p : res2) { res.insert(p); } return res; } int main(void) { isNotPrime[0] = isNotPrime[1] = true; REP(i, 100000) { if (!isNotPrime[i]) { primes[nPrime++] = i; for (int j = i + i; j < 100000; j += i) { isNotPrime[j] = true; } } } int n; scanf("%d", &n); vector<ll> vs; REP(i, n + 1) { ll v; scanf("%lld", &v); vs.push_back(v); } set<int> res; if (vs[n] == 0) { res = solve2(vs); } else { res = solve1(vs); } for (int p : res) { printf("%d\n", p); } return 0; }
replace
29
30
29
30
TLE
p03065
C++
Runtime Error
#pragma GCC optimize("O3") #pragma GCC target("sse4") // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") // #pragma GCC target ("avx2") // #pragma GCC optimization ("unroll-loops") #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const long double PI = 4 * atan(1); typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef complex<ld> cd; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<ld> vd; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define f1r(i, a, b) for (int i = (a); i < (b); ++i) #define f0r(i, a) f1r(i, 0, a) #define trav(a, x) for (auto &a : x) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() #define rall(x) rbegin(x), rend(x) #define resz resize #define rsz resize #define ins insert template <typename A, typename B> ostream &operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v) { cout << "["; for (int i = 0; i < v.size(); i++) { if (i) cout << ", "; cout << v[i]; } return cout << "]"; } template <class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } namespace input { template <class T> void re(complex<T> &x); template <class T1, class T2> void re(pair<T1, T2> &p); template <class T> void re(vector<T> &a); template <class T, size_t SZ> void re(array<T, SZ> &a); template <class T> void re(T &x) { cin >> x; } void re(double &x) { string t; re(t); x = stod(t); } void re(ld &x) { string t; re(t); x = stold(t); } template <class T, class... Ts> void re(T &t, Ts &...ts) { re(t); re(ts...); } template <class T> void re(complex<T> &x) { T a, b; re(a, b); x = cd(a, b); } template <class T1, class T2> void re(pair<T1, T2> &p) { re(p.f, p.s); } template <class T> void re(vector<T> &a) { F0R(i, sz(a)) re(a[i]); } template <class T, size_t SZ> void re(array<T, SZ> &a) { F0R(i, SZ) re(a[i]); } } // namespace input using namespace input; namespace output { void pr(int x) { cout << x; } void pr(long x) { cout << x; } void pr(ll x) { cout << x; } void pr(unsigned x) { cout << x; } void pr(unsigned long x) { cout << x; } void pr(unsigned long long x) { cout << x; } void pr(float x) { cout << x; } void pr(double x) { cout << x; } void pr(ld x) { cout << x; } void pr(char x) { cout << x; } void pr(const char *x) { cout << x; } void pr(const string &x) { cout << x; } void pr(bool x) { pr(x ? "true" : "false"); } template <class T> void pr(const complex<T> &x) { cout << x; } template <class T1, class T2> void pr(const pair<T1, T2> &x); template <class T> void pr(const T &x); template <class T, class... Ts> void pr(const T &t, const Ts &...ts) { pr(t); pr(ts...); } template <class T1, class T2> void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); } template <class T> void pr(const T &x) { pr("{"); // const iterator needed for vector<bool> bool fst = 1; for (const auto &a : x) pr(!fst ? ", " : "", a), fst = 0; pr("}"); } void ps() { pr("\n"); } // print w/ spaces template <class T, class... Ts> void ps(const T &t, const Ts &...ts) { pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); } void pc() { pr("]\n"); } // debug w/ commas template <class T, class... Ts> void pc(const T &t, const Ts &...ts) { pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); } #ifdef TQIAN #define dbg(x...) pr("[", #x, "] = ["), pc(x); #else #define dbg(x...) 0 #endif } // namespace output using namespace output; namespace io { void setIn(string s) { freopen(s.c_str(), "r", stdin); } void setOut(string s) { freopen(s.c_str(), "w", stdout); } void setIO(string s = "") { cin.sync_with_stdio(0); cin.tie(0); // fast I/O // cin.exceptions(cin.failbit); // ex. throws exception when you try to read // letter into int if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); } // for USACO } } // namespace io using namespace io; mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1e9 + 7; typedef decay<decltype(MOD)>::type T; struct mi { T val; explicit operator T() const { return val; } mi() { val = 0; } mi(const ll &v) { val = (-MOD <= v && v <= MOD) ? v : v % MOD; if (val < 0) val += MOD; } friend ostream &operator<<(ostream &os, const mi &a) { return os << a.val; } friend void pr(const mi &a) { pr(a.val); } friend void re(mi &a) { ll x; re(x); a = mi(x); } friend bool operator==(const mi &a, const mi &b) { return a.val == b.val; } friend bool operator!=(const mi &a, const mi &b) { return !(a == b); } friend bool operator<(const mi &a, const mi &b) { return a.val < b.val; } mi operator-() const { return mi(-val); } mi &operator+=(const mi &m) { if ((val += m.val) >= MOD) val -= MOD; return *this; } mi &operator-=(const mi &m) { if ((val -= m.val) < 0) val += MOD; return *this; } mi &operator*=(const mi &m) { val = (ll)val * m.val % MOD; return *this; } friend mi pow(mi a, ll p) { mi ans = 1; assert(p >= 0); for (; p; p /= 2, a *= a) if (p & 1) ans *= a; return ans; } friend mi inv(const mi &a) { assert(a != 0); return pow(a, MOD - 2); } mi &operator/=(const mi &m) { return (*this) *= inv(m); } friend mi operator+(mi a, const mi &b) { return a += b; } friend mi operator-(mi a, const mi &b) { return a -= b; } friend mi operator*(mi a, const mi &b) { return a *= b; } friend mi operator/(mi a, const mi &b) { return a /= b; } }; typedef pair<mi, mi> pmi; typedef vector<mi> vmi; typedef vector<pmi> vpmi; const ll INF = 1e18; vl getPrime(ll n) { set<ll> primes; while (n % 2 == 0) { primes.insert(2); n = n / 2; } for (ll i = 3; i <= sqrt(n); i = i + 2) { while (n % i == 0) { primes.insert(i); n = n / i; } } if (n > 2) primes.insert(n); vl ret; for (int x : primes) ret.eb(x); return ret; } void solve_easy(int n, vl v) { int lead = -1; f0r(i, n + 1) { if (v[i] != 0) { lead = v[i]; break; } } vl pri = getPrime(abs(lead)); vi res; for (int p : pri) { vi use(n + 1); f0r(i, n + 1) { use[i % (p - 1)] += ((v[i] % p + p) % p); use[i % (p - 1)] %= p; } f0r(i, n + 1) if (use[i] % p) goto finish; res.eb(p); finish: continue; } for (auto x : res) ps(x); } ll modpow(ll base, ll exp, ll mod) { ll res = 1; while (exp) { if (exp % 2) res *= base; res %= mod; base *= base; base %= mod; exp >>= 1; } return res; } const ll p1 = 179424673; const ll p2 = 179424697; bool eval(vl &v, ll x, ll mod) { ll sum = 0; f0r(i, sz(v)) { ll ad = modpow(x, i, mod); ad *= v[i]; ad %= mod; sum += ad; } if (sum == 0) return false; return true; } ll eval1(vl &v, ll x, ll mod) { ll sum = 0; f0r(i, sz(v)) { ll ad = modpow(x, i, mod); ad *= v[i]; ad %= mod; sum += ad; } return sum; } bool check_good(vl &v, ll x) { if (eval(v, x, p1) || eval(v, x, p2)) return true; return false; } vl sieve(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } vl ret; // Print all prime numbers for (int p = 2; p <= n; p++) if (prime[p]) ret.eb(p); return ret; } int main() { setIn("temp.in"); int n; re(n); vl v(n + 1); f0r(i, n + 1) re(v[i]); reverse(all(v)); if (v[0] != 0) { solve_easy(n, v); return 0; } reverse(all(v)); while (v.back() == 0) v.pop_back(); n = sz(v) - 1; reverse(all(v)); vl tmp = sieve(n + 4); set<ll> pri; for (auto x : tmp) pri.insert(x); for (auto x : v) { if (x == 0) continue; tmp = getPrime(abs(x)); for (auto y : tmp) pri.insert(y); } set<ll> res; vl nonzero; for (auto x : v) nonzero.eb(abs(x)); for (ll p : pri) { if (p >= n + 5) { for (auto y : nonzero) { if (y % p != 0) goto what; } res.insert(p); what: continue; continue; } vl use(n + 1); f0r(i, n + 1) { use[i % (p - 1)] += ((v[i] % p + p) % p); use[i % (p - 1)] %= p; } f0r(i, n + 1) if (use[i] % p) goto finish; res.insert(p); finish: continue; } for (auto x : res) ps(x); return 0; }
#pragma GCC optimize("O3") #pragma GCC target("sse4") // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") // #pragma GCC target ("avx2") // #pragma GCC optimization ("unroll-loops") #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; using namespace __gnu_pbds; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const long double PI = 4 * atan(1); typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef complex<ld> cd; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<ld> vd; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define f1r(i, a, b) for (int i = (a); i < (b); ++i) #define f0r(i, a) f1r(i, 0, a) #define trav(a, x) for (auto &a : x) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() #define rall(x) rbegin(x), rend(x) #define resz resize #define rsz resize #define ins insert template <typename A, typename B> ostream &operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v) { cout << "["; for (int i = 0; i < v.size(); i++) { if (i) cout << ", "; cout << v[i]; } return cout << "]"; } template <class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } namespace input { template <class T> void re(complex<T> &x); template <class T1, class T2> void re(pair<T1, T2> &p); template <class T> void re(vector<T> &a); template <class T, size_t SZ> void re(array<T, SZ> &a); template <class T> void re(T &x) { cin >> x; } void re(double &x) { string t; re(t); x = stod(t); } void re(ld &x) { string t; re(t); x = stold(t); } template <class T, class... Ts> void re(T &t, Ts &...ts) { re(t); re(ts...); } template <class T> void re(complex<T> &x) { T a, b; re(a, b); x = cd(a, b); } template <class T1, class T2> void re(pair<T1, T2> &p) { re(p.f, p.s); } template <class T> void re(vector<T> &a) { F0R(i, sz(a)) re(a[i]); } template <class T, size_t SZ> void re(array<T, SZ> &a) { F0R(i, SZ) re(a[i]); } } // namespace input using namespace input; namespace output { void pr(int x) { cout << x; } void pr(long x) { cout << x; } void pr(ll x) { cout << x; } void pr(unsigned x) { cout << x; } void pr(unsigned long x) { cout << x; } void pr(unsigned long long x) { cout << x; } void pr(float x) { cout << x; } void pr(double x) { cout << x; } void pr(ld x) { cout << x; } void pr(char x) { cout << x; } void pr(const char *x) { cout << x; } void pr(const string &x) { cout << x; } void pr(bool x) { pr(x ? "true" : "false"); } template <class T> void pr(const complex<T> &x) { cout << x; } template <class T1, class T2> void pr(const pair<T1, T2> &x); template <class T> void pr(const T &x); template <class T, class... Ts> void pr(const T &t, const Ts &...ts) { pr(t); pr(ts...); } template <class T1, class T2> void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); } template <class T> void pr(const T &x) { pr("{"); // const iterator needed for vector<bool> bool fst = 1; for (const auto &a : x) pr(!fst ? ", " : "", a), fst = 0; pr("}"); } void ps() { pr("\n"); } // print w/ spaces template <class T, class... Ts> void ps(const T &t, const Ts &...ts) { pr(t); if (sizeof...(ts)) pr(" "); ps(ts...); } void pc() { pr("]\n"); } // debug w/ commas template <class T, class... Ts> void pc(const T &t, const Ts &...ts) { pr(t); if (sizeof...(ts)) pr(", "); pc(ts...); } #ifdef TQIAN #define dbg(x...) pr("[", #x, "] = ["), pc(x); #else #define dbg(x...) 0 #endif } // namespace output using namespace output; namespace io { void setIn(string s) { freopen(s.c_str(), "r", stdin); } void setOut(string s) { freopen(s.c_str(), "w", stdout); } void setIO(string s = "") { cin.sync_with_stdio(0); cin.tie(0); // fast I/O // cin.exceptions(cin.failbit); // ex. throws exception when you try to read // letter into int if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); } // for USACO } } // namespace io using namespace io; mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1e9 + 7; typedef decay<decltype(MOD)>::type T; struct mi { T val; explicit operator T() const { return val; } mi() { val = 0; } mi(const ll &v) { val = (-MOD <= v && v <= MOD) ? v : v % MOD; if (val < 0) val += MOD; } friend ostream &operator<<(ostream &os, const mi &a) { return os << a.val; } friend void pr(const mi &a) { pr(a.val); } friend void re(mi &a) { ll x; re(x); a = mi(x); } friend bool operator==(const mi &a, const mi &b) { return a.val == b.val; } friend bool operator!=(const mi &a, const mi &b) { return !(a == b); } friend bool operator<(const mi &a, const mi &b) { return a.val < b.val; } mi operator-() const { return mi(-val); } mi &operator+=(const mi &m) { if ((val += m.val) >= MOD) val -= MOD; return *this; } mi &operator-=(const mi &m) { if ((val -= m.val) < 0) val += MOD; return *this; } mi &operator*=(const mi &m) { val = (ll)val * m.val % MOD; return *this; } friend mi pow(mi a, ll p) { mi ans = 1; assert(p >= 0); for (; p; p /= 2, a *= a) if (p & 1) ans *= a; return ans; } friend mi inv(const mi &a) { assert(a != 0); return pow(a, MOD - 2); } mi &operator/=(const mi &m) { return (*this) *= inv(m); } friend mi operator+(mi a, const mi &b) { return a += b; } friend mi operator-(mi a, const mi &b) { return a -= b; } friend mi operator*(mi a, const mi &b) { return a *= b; } friend mi operator/(mi a, const mi &b) { return a /= b; } }; typedef pair<mi, mi> pmi; typedef vector<mi> vmi; typedef vector<pmi> vpmi; const ll INF = 1e18; vl getPrime(ll n) { set<ll> primes; while (n % 2 == 0) { primes.insert(2); n = n / 2; } for (ll i = 3; i <= sqrt(n); i = i + 2) { while (n % i == 0) { primes.insert(i); n = n / i; } } if (n > 2) primes.insert(n); vl ret; for (int x : primes) ret.eb(x); return ret; } void solve_easy(int n, vl v) { int lead = -1; f0r(i, n + 1) { if (v[i] != 0) { lead = v[i]; break; } } vl pri = getPrime(abs(lead)); vi res; for (int p : pri) { vi use(n + 1); f0r(i, n + 1) { use[i % (p - 1)] += ((v[i] % p + p) % p); use[i % (p - 1)] %= p; } f0r(i, n + 1) if (use[i] % p) goto finish; res.eb(p); finish: continue; } for (auto x : res) ps(x); } ll modpow(ll base, ll exp, ll mod) { ll res = 1; while (exp) { if (exp % 2) res *= base; res %= mod; base *= base; base %= mod; exp >>= 1; } return res; } const ll p1 = 179424673; const ll p2 = 179424697; bool eval(vl &v, ll x, ll mod) { ll sum = 0; f0r(i, sz(v)) { ll ad = modpow(x, i, mod); ad *= v[i]; ad %= mod; sum += ad; } if (sum == 0) return false; return true; } ll eval1(vl &v, ll x, ll mod) { ll sum = 0; f0r(i, sz(v)) { ll ad = modpow(x, i, mod); ad *= v[i]; ad %= mod; sum += ad; } return sum; } bool check_good(vl &v, ll x) { if (eval(v, x, p1) || eval(v, x, p2)) return true; return false; } vl sieve(int n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } vl ret; // Print all prime numbers for (int p = 2; p <= n; p++) if (prime[p]) ret.eb(p); return ret; } int main() { // setIn("temp.in"); int n; re(n); vl v(n + 1); f0r(i, n + 1) re(v[i]); reverse(all(v)); if (v[0] != 0) { solve_easy(n, v); return 0; } reverse(all(v)); while (v.back() == 0) v.pop_back(); n = sz(v) - 1; reverse(all(v)); vl tmp = sieve(n + 4); set<ll> pri; for (auto x : tmp) pri.insert(x); for (auto x : v) { if (x == 0) continue; tmp = getPrime(abs(x)); for (auto y : tmp) pri.insert(y); } set<ll> res; vl nonzero; for (auto x : v) nonzero.eb(abs(x)); for (ll p : pri) { if (p >= n + 5) { for (auto y : nonzero) { if (y % p != 0) goto what; } res.insert(p); what: continue; continue; } vl use(n + 1); f0r(i, n + 1) { use[i % (p - 1)] += ((v[i] % p + p) % p); use[i % (p - 1)] %= p; } f0r(i, n + 1) if (use[i] % p) goto finish; res.insert(p); finish: continue; } for (auto x : res) ps(x); return 0; }
replace
355
356
355
356
0
p03065
C++
Runtime Error
#include <algorithm> #include <chrono> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <set> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; bool isPrime(long long p) { if (p < 0) { p *= -1; } if (p == 0 || p == 1) { return false; } else if (p == 2) { return true; } else if (p % 2 == 0) { return false; } long long p_sqrt = sqrt(p); for (long long i = 3; i <= p_sqrt; i++) { if (p % i == 0) { return false; } } return true; } int gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int N; cin >> N; vector<long long> a(N + 1); set<long long> ans; long long coef_gcd, tmp; coef_gcd = 0; for (int i = N; i >= 0; i--) { cin >> a[i]; tmp = a[i]; if (a[i] != 0) { if (tmp < 0) { tmp *= (-1); } if (coef_gcd == 0) { coef_gcd = tmp; } else { coef_gcd = gcd(tmp, coef_gcd); } } } for (long long i = 2; i * i <= coef_gcd; i++) { while (coef_gcd % i == 0) { ans.insert(i); coef_gcd /= i; } } if (coef_gcd != 1) { ans.insert(coef_gcd); } for (long long p = 2; p <= N; p++) { if (isPrime(p)) { vector<long long> coeff(p, 0); coeff[0] = a[0]; for (int i = 1; i <= N; i++) { long long idx = i % (p - 1) == 0 ? p - 1 : i; coeff[idx] += a[i]; } int flag = 0; for (int i = 0; i < p; i++) { if (coeff[i] % p != 0) { flag = 1; break; } } if (flag == 0) { ans.insert(p); } } } for (auto it : ans) { cout << it << endl; } return 0; }
#include <algorithm> #include <chrono> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <set> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; bool isPrime(long long p) { if (p < 0) { p *= -1; } if (p == 0 || p == 1) { return false; } else if (p == 2) { return true; } else if (p % 2 == 0) { return false; } long long p_sqrt = sqrt(p); for (long long i = 3; i <= p_sqrt; i++) { if (p % i == 0) { return false; } } return true; } int gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int N; cin >> N; vector<long long> a(N + 1); set<long long> ans; long long coef_gcd, tmp; coef_gcd = 0; for (int i = N; i >= 0; i--) { cin >> a[i]; tmp = a[i]; if (a[i] != 0) { if (tmp < 0) { tmp *= (-1); } if (coef_gcd == 0) { coef_gcd = tmp; } else { coef_gcd = gcd(tmp, coef_gcd); } } } for (long long i = 2; i * i <= coef_gcd; i++) { while (coef_gcd % i == 0) { ans.insert(i); coef_gcd /= i; } } if (coef_gcd != 1) { ans.insert(coef_gcd); } for (long long p = 2; p <= N; p++) { if (isPrime(p)) { vector<long long> coeff(p, 0); coeff[0] = a[0]; for (int i = 1; i <= N; i++) { long long idx = i % (p - 1) == 0 ? p - 1 : i % (p - 1); coeff[idx] += a[i]; } int flag = 0; for (int i = 0; i < p; i++) { if (coeff[i] % p != 0) { flag = 1; break; } } if (flag == 0) { ans.insert(p); } } } for (auto it : ans) { cout << it << endl; } return 0; }
replace
79
80
79
80
0
p03065
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; const int MAX = 10000; vector<ll> prime; bool isprime[MAX]; void sieve() { for (ll i = 3; i < MAX; i += 2) { isprime[i] = 1; } isprime[2] = 1; prime.push_back(2); for (ll i = 3; i < MAX; i++) { if (isprime[i]) { prime.push_back(i); for (ll j = 2 * i; j < MAX; j += i) { isprime[j] = 0; } } } return; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } void div(vector<ll> &v, ll p) { while (!v.empty() && v.back() == 0) v.pop_back(); if (v.size() <= p - 1) return; int n = v.size(); ll a = v.back(); v.pop_back(); v[n - p] = (v[n - p] + a) % p; div(v, p); } int main() { int n; cin >> n; sieve(); ll a[10001]; ll g = 0; for (int i = n; i >= 0; i--) { cin >> a[i]; g = gcd(abs(a[i]), g); } for (int i = 0; i <= n; i++) a[i] /= g; vector<ll> ans; for (ll i = 2; i * i <= g; i++) { if (g % i == 0) { while (g % i == 0) g /= i; ans.push_back(i); } } if (g > 1) ans.push_back(g); for (int i = 0; prime[i] <= n; i++) { ll p = prime[i]; if (a[0] % p != 0) continue; vector<ll> v; for (int i = 0; i <= n; i++) { v.push_back((a[i] % p + p) % p); } div(v, p); if (v.empty()) ans.push_back(p); } if (ans.empty()) { cout << endl; return 0; } sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); for (auto p : ans) cout << p << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; const int MAX = 11000; vector<ll> prime; bool isprime[MAX]; void sieve() { for (ll i = 3; i < MAX; i += 2) { isprime[i] = 1; } isprime[2] = 1; prime.push_back(2); for (ll i = 3; i < MAX; i++) { if (isprime[i]) { prime.push_back(i); for (ll j = 2 * i; j < MAX; j += i) { isprime[j] = 0; } } } return; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } void div(vector<ll> &v, ll p) { while (!v.empty() && v.back() == 0) v.pop_back(); if (v.size() <= p - 1) return; int n = v.size(); ll a = v.back(); v.pop_back(); v[n - p] = (v[n - p] + a) % p; div(v, p); } int main() { int n; cin >> n; sieve(); ll a[10001]; ll g = 0; for (int i = n; i >= 0; i--) { cin >> a[i]; g = gcd(abs(a[i]), g); } for (int i = 0; i <= n; i++) a[i] /= g; vector<ll> ans; for (ll i = 2; i * i <= g; i++) { if (g % i == 0) { while (g % i == 0) g /= i; ans.push_back(i); } } if (g > 1) ans.push_back(g); for (int i = 0; prime[i] <= n; i++) { ll p = prime[i]; if (a[0] % p != 0) continue; vector<ll> v; for (int i = 0; i <= n; i++) { v.push_back((a[i] % p + p) % p); } div(v, p); if (v.empty()) ans.push_back(p); } if (ans.empty()) { cout << endl; return 0; } sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); for (auto p : ans) cout << p << endl; return 0; }
replace
22
23
22
23
0
p03065
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, a[N], b[N], g; vector<int> ans; bool isprime(int x) { for (int i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; } bool check(int x) { if (!isprime(x)) return false; memcpy(b, a, sizeof(int) * (n + 3)); for (int i = n; i >= x; --i) b[i - (x - 1)] += b[i]; for (int i = 0; i < x; ++i) if (b[i] % x) return false; return true; } int main() { scanf("%d", &n); for (int i = n; ~i; --i) scanf("%d", &a[i]), g = __gcd(g, abs(a[i])); for (int i = 2; i <= g; ++i) { if (g % i == 0) ans.push_back(i); while (g % i == 0) g /= i; } if (g > 1) ans.push_back(g); for (int i = 2; i <= n; ++i) if (check(i)) ans.push_back(i); sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); for (auto x : ans) printf("%d\n", x); }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, a[N], b[N], g; vector<int> ans; bool isprime(int x) { for (int i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; } bool check(int x) { if (!isprime(x)) return false; memcpy(b, a, sizeof(int) * (n + 3)); for (int i = n; i >= x; --i) b[i - (x - 1)] += b[i]; for (int i = 0; i < x; ++i) if (b[i] % x) return false; return true; } int main() { scanf("%d", &n); for (int i = n; ~i; --i) scanf("%d", &a[i]), g = __gcd(g, abs(a[i])); for (int i = 2; i * i <= g; ++i) { if (g % i == 0 && check(i)) ans.push_back(i); while (g % i == 0) g /= i; } if (g > 1) ans.push_back(g); for (int i = 2; i <= n; ++i) if (check(i)) ans.push_back(i); sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); for (auto x : ans) printf("%d\n", x); }
replace
26
28
26
28
TLE
p03065
C++
Time Limit Exceeded
// #include <bits/stdc++.h> #include <algorithm> // min,max #include <cmath> // sqrt #include <cstdlib> // exit #include <iostream> #include <list> #include <map> #include <unordered_map> #include <vector> using namespace std; #define forr(i, m, n) for (int i = (m); i <= (n); i++) #define forv(i, m, n) for (int i = (m); i >= (n); i--) #define forall(it, p) for (auto it = p.begin(); it != p.end(); ++it) #define R 1000000007 #define DBG 1 #define MAXN 10002 int a[MAXN]; long c[MAXN]; int faca[MAXN]; int exaa[MAXN]; int ps[MAXN] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973}; int nfaca = 1229; int gcd(int a, int b) { if ((0 == a) || (0 == b)) return 0; a = abs(a); b = abs(b); if (a < b) { int tmp = a; a = b; b = tmp; } int r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } // gcd void prime_division(int n, int *fac, int *ex, int *nfac) { int q; *nfac = 0; n = abs(n); if (n == 1) return; q = int(sqrt(n)); for (int i = 2; i <= q; i++) if (n % i == 0) { ex[*nfac] = 0; fac[*nfac] = i; do { ex[*nfac]++; n /= i; } while (n % i == 0); (*nfac)++; } if (n > 1) { fac[*nfac] = n; ex[*nfac] = 1; (*nfac)++; } } static inline long modf(long x, long f) { return x % f + (x < 0 ? f : 0); } int main() { int n; cin >> n; forr(i, 0, n) cin >> a[n - i]; int g = a[n]; forr(i, 0, n - 1) if (a[i] != 0) g = gcd(g, a[i]); int facb[100]; int exb[100]; int nfacb; prime_division(g, facb, exb, &nfacb); unordered_map<int, bool> bh; forr(i, 0, nfacb - 1) bh[facb[i]] = true; if (a[0] != 0) { // int fac2[100]; // int ex2[100]; // int nfac2; prime_division(a[0], ps, exaa, &nfaca); } // cout << "nfaca " << nfaca << endl; forr(i, 0, nfaca - 1) { int f = ps[i]; // cout << f << endl; /*bool found = false; forr(j,0,nfacb-1) if (f == facb[j]) { found = true; break; } if (found) continue;*/ if (bh[f]) continue; bool ok = true; if (f > 5000) { forr(r, 1, f - 1) { long v = a[0]; long r2i = 1; forr(j, 1, n) { r2i = (r2i * r) % f; v = (v + a[j] * r2i) % f; } if (v != 0) { ok = false; break; } } } else { forr(j, 0, f - 2) c[j] = 0; forr(j, 0, n) c[j % (f - 1)] = (c[j % (f - 1)] + a[j]) % f; forr(r, 1, f - 1) { long v = c[0]; long r2i = 1; forr(j, 1, f - 2) { r2i = (r2i * r) % f; v = (v + c[j] * r2i) % f; } if (v != 0) { ok = false; break; } } } if (ok) facb[nfacb++] = f; } vector<int> bb(nfacb); forr(i, 0, nfacb - 1) bb[i] = facb[i]; sort(bb.begin(), bb.end()); forr(i, 0, nfacb - 1) cout << bb[i] << endl; }
// #include <bits/stdc++.h> #include <algorithm> // min,max #include <cmath> // sqrt #include <cstdlib> // exit #include <iostream> #include <list> #include <map> #include <unordered_map> #include <vector> using namespace std; #define forr(i, m, n) for (int i = (m); i <= (n); i++) #define forv(i, m, n) for (int i = (m); i >= (n); i--) #define forall(it, p) for (auto it = p.begin(); it != p.end(); ++it) #define R 1000000007 #define DBG 1 #define MAXN 10002 int a[MAXN]; long c[MAXN]; int faca[MAXN]; int exaa[MAXN]; int ps[MAXN] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, 8147, 8161, 8167, 8171, 8179, 8191, 8209, 8219, 8221, 8231, 8233, 8237, 8243, 8263, 8269, 8273, 8287, 8291, 8293, 8297, 8311, 8317, 8329, 8353, 8363, 8369, 8377, 8387, 8389, 8419, 8423, 8429, 8431, 8443, 8447, 8461, 8467, 8501, 8513, 8521, 8527, 8537, 8539, 8543, 8563, 8573, 8581, 8597, 8599, 8609, 8623, 8627, 8629, 8641, 8647, 8663, 8669, 8677, 8681, 8689, 8693, 8699, 8707, 8713, 8719, 8731, 8737, 8741, 8747, 8753, 8761, 8779, 8783, 8803, 8807, 8819, 8821, 8831, 8837, 8839, 8849, 8861, 8863, 8867, 8887, 8893, 8923, 8929, 8933, 8941, 8951, 8963, 8969, 8971, 8999, 9001, 9007, 9011, 9013, 9029, 9041, 9043, 9049, 9059, 9067, 9091, 9103, 9109, 9127, 9133, 9137, 9151, 9157, 9161, 9173, 9181, 9187, 9199, 9203, 9209, 9221, 9227, 9239, 9241, 9257, 9277, 9281, 9283, 9293, 9311, 9319, 9323, 9337, 9341, 9343, 9349, 9371, 9377, 9391, 9397, 9403, 9413, 9419, 9421, 9431, 9433, 9437, 9439, 9461, 9463, 9467, 9473, 9479, 9491, 9497, 9511, 9521, 9533, 9539, 9547, 9551, 9587, 9601, 9613, 9619, 9623, 9629, 9631, 9643, 9649, 9661, 9677, 9679, 9689, 9697, 9719, 9721, 9733, 9739, 9743, 9749, 9767, 9769, 9781, 9787, 9791, 9803, 9811, 9817, 9829, 9833, 9839, 9851, 9857, 9859, 9871, 9883, 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973}; int nfaca = 1229; int gcd(int a, int b) { if ((0 == a) || (0 == b)) return 0; a = abs(a); b = abs(b); if (a < b) { int tmp = a; a = b; b = tmp; } int r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } // gcd void prime_division(int n, int *fac, int *ex, int *nfac) { int q; *nfac = 0; n = abs(n); if (n == 1) return; q = int(sqrt(n)); for (int i = 2; i <= q; i++) if (n % i == 0) { ex[*nfac] = 0; fac[*nfac] = i; do { ex[*nfac]++; n /= i; } while (n % i == 0); (*nfac)++; } if (n > 1) { fac[*nfac] = n; ex[*nfac] = 1; (*nfac)++; } } static inline long modf(long x, long f) { return x % f + (x < 0 ? f : 0); } int main() { int n; cin >> n; forr(i, 0, n) cin >> a[n - i]; int g = a[n]; forr(i, 0, n - 1) if (a[i] != 0) g = gcd(g, a[i]); int facb[100]; int exb[100]; int nfacb; prime_division(g, facb, exb, &nfacb); unordered_map<int, bool> bh; forr(i, 0, nfacb - 1) bh[facb[i]] = true; if (a[0] != 0) { // int fac2[100]; // int ex2[100]; // int nfac2; prime_division(a[0], ps, exaa, &nfaca); } // cout << "nfaca " << nfaca << endl; forr(i, 0, nfaca - 1) { int f = ps[i]; // cout << f << endl; /*bool found = false; forr(j,0,nfacb-1) if (f == facb[j]) { found = true; break; } if (found) continue;*/ if (bh[f]) continue; bool ok = true; if (f >= 10000) { forr(r, 1, f - 1) { long v = a[0]; long r2i = 1; forr(j, 1, n) { r2i = (r2i * r) % f; v = (v + a[j] * r2i) % f; } if (v != 0) { ok = false; break; } } } else { forr(j, 0, f - 2) c[j] = 0; forr(j, 0, n) c[j % (f - 1)] = (c[j % (f - 1)] + a[j]) % f; forr(r, 1, f - 1) { long v = c[0]; long r2i = 1; forr(j, 1, f - 2) { r2i = (r2i * r) % f; v = (v + c[j] * r2i) % f; } if (v != 0) { ok = false; break; } } } if (ok) facb[nfacb++] = f; } vector<int> bb(nfacb); forr(i, 0, nfacb - 1) bb[i] = facb[i]; sort(bb.begin(), bb.end()); forr(i, 0, nfacb - 1) cout << bb[i] << endl; }
replace
207
208
207
208
TLE
p03065
Python
Runtime Error
import sys from fractions import gcd def eratosthenes_generator(): yield 2 n = 3 h = {} while True: m = n if n in h: b = h[n] del h[n] else: b = n yield n m += b << 1 while m in h: m += b << 1 h[m] = b n += 2 def prime(n): ret = [] if n % 2 == 0: ret.append(2) while n % 2 == 0: n >>= 1 for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: ret.append(i) while n % i == 0: n = n // i if n == 1: break if n > 1: ret.append(n) return ret def solve(n, aaa): g = abs(aaa[-1]) for a in aaa[:-1]: if a != 0: g = gcd(g, abs(a)) ans = set(prime(g)) for p in prime(aaa[0]): if p > n + 2: break if p in ans or aaa[0] % p != 0: continue q = p - 1 tmp = [0] * q for i, a in enumerate(aaa): tmp[i % q] += a if all(t % p == 0 for t in tmp): ans.add(p) ans = sorted(ans) return ans n = int(input()) aaa = list(map(int, sys.stdin)) aaa.reverse() print("\n".join(map(str, solve(n, aaa))))
import sys from fractions import gcd def eratosthenes_generator(): yield 2 n = 3 h = {} while True: m = n if n in h: b = h[n] del h[n] else: b = n yield n m += b << 1 while m in h: m += b << 1 h[m] = b n += 2 def prime(n): ret = [] if n % 2 == 0: ret.append(2) while n % 2 == 0: n >>= 1 for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: ret.append(i) while n % i == 0: n = n // i if n == 1: break if n > 1: ret.append(n) return ret def solve(n, aaa): g = abs(aaa[-1]) for a in aaa[:-1]: if a != 0: g = gcd(g, abs(a)) ans = set(prime(g)) for p in eratosthenes_generator(): if p > n + 2: break if p in ans or aaa[0] % p != 0: continue q = p - 1 tmp = [0] * q for i, a in enumerate(aaa): tmp[i % q] += a if all(t % p == 0 for t in tmp): ans.add(p) ans = sorted(ans) return ans n = int(input()) aaa = list(map(int, sys.stdin)) aaa.reverse() print("\n".join(map(str, solve(n, aaa))))
replace
48
49
48
49
ImportError: cannot import name 'gcd' from 'fractions' (/usr/lib/python3.10/fractions.py)
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03065/Python/s338863111.py", line 2, in <module> from fractions import gcd ImportError: cannot import name 'gcd' from 'fractions' (/usr/lib/python3.10/fractions.py)
p03065
Python
Time Limit Exceeded
import sys from fractions import gcd def eratosthenes_generator(): yield 2 n = 3 h = {} while True: m = n if n in h: b = h[n] del h[n] else: b = n yield n m += b << 1 while m in h: m += b << 1 h[m] = b n += 2 def prime(n): ret = [] for i in eratosthenes_generator(): if n % i == 0: ret.append(i) while n % i == 0: n = n // i if n == 1: break if n > 1: ret.append(n) return ret def solve(n, aaa): g = abs(aaa[-1]) for a in aaa[:-1]: if a != 0: g = gcd(g, abs(a)) ans = set(prime(g)) for p in eratosthenes_generator(): if p > n + 2: break if p in ans or aaa[0] % p != 0: continue q = p - 1 tmp = [0] * q for i, a in enumerate(aaa): tmp[i % q] += a if all(t % p == 0 for t in tmp): ans.add(p) ans = sorted(ans) return ans n = int(input()) aaa = list(map(int, sys.stdin)) aaa.reverse() print("\n".join(map(str, solve(n, aaa))))
import sys from fractions import gcd def eratosthenes_generator(): yield 2 n = 3 h = {} while True: m = n if n in h: b = h[n] del h[n] else: b = n yield n m += b << 1 while m in h: m += b << 1 h[m] = b n += 2 def prime(n): ret = [] for i in eratosthenes_generator(): if n % i == 0: ret.append(i) while n % i == 0: n = n // i if n == 1 or i * i > n: break if n > 1: ret.append(n) return ret def solve(n, aaa): g = abs(aaa[-1]) for a in aaa[:-1]: if a != 0: g = gcd(g, abs(a)) ans = set(prime(g)) for p in eratosthenes_generator(): if p > n + 2: break if p in ans or aaa[0] % p != 0: continue q = p - 1 tmp = [0] * q for i, a in enumerate(aaa): tmp[i % q] += a if all(t % p == 0 for t in tmp): ans.add(p) ans = sorted(ans) return ans n = int(input()) aaa = list(map(int, sys.stdin)) aaa.reverse() print("\n".join(map(str, solve(n, aaa))))
replace
30
31
30
31
TLE
p03065
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> Pii; typedef vector<ll> Vi; typedef vector<Vi> VVi; const double EPS = (1e-7); const ll INF = (1e13); const double PI = (acos(-1)); const ll MOD = ll(1e9) + 7; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPR(i, n) for (ll i = n; i > -1; i--) #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) #define ALL(x) (x).begin(), (x).end() #define SORT(x) sort((x).begin(), (x).end()) #define RSORT(x) sort((x).rbegin(), (x).rend()) #define REVERSE(x) reverse((x).begin(), (x).end()) #define SZ(x) ((ll)(x).size()) #define pb push_back #define mp make_pair // chmax(a, b): a>bならaをbで更新 更新したときにtrueを返す // chmin(a, b): a<bならaをbで更新 更新したときにtrueを返す template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define dump(x) cerr << #x << "= " << (x) << endl; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll pow(ll a, ll b) { if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a; } ll pow(ll a, ll b, ll m) { if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m; } ll residue(ll a, ll m) { return ((a % m) + m) % m; }; ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; const ll MAX_N = 1e4; ll n; ll a[MAX_N + 1]; Vi list_of_primes(ll n) { // return list of primes p <= n // primes[i] != 0 iff i is prime. Vi primes(n); FOR(i, 2, n) { primes[i] = i; } for (ll i = 2; i * i < n; ++i) if (primes[i]) for (ll j = i * i; j < n; j += i) primes[j] = 0; primes.erase(remove(primes.begin(), primes.end(), 0), primes.end()); return primes; } Vi prime_factors(ll n) { // return list of prime factors of n. if (n == 1) return {}; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { Vi ans = prime_factors(n / i); ans.pb(i); sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); return ans; } } return {n}; } bool hantei(ll p) { REP(x, p) { ll temp = a[0]; REP(i, n) { temp += (a[i + 1] % p) * pow(x, i + 1, p); temp = residue(temp, p); } if (temp != 0) return false; } return true; } int main() { cin >> n; ll d = 0; REP(i, n + 1) { cin >> a[n - i]; d = gcd(d, abs(a[n - i])); } Vi P1 = prime_factors(d); // 係数全ての最大公約数は必ず条件を満たす. Vi P2 = list_of_primes(n + 1); for (auto &p : P2) { if (hantei(p)) P1.pb(p); } SORT(P1); for (auto &p : P1) { cout << p << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> Pii; typedef vector<ll> Vi; typedef vector<Vi> VVi; const double EPS = (1e-7); const ll INF = (1e13); const double PI = (acos(-1)); const ll MOD = ll(1e9) + 7; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPR(i, n) for (ll i = n; i > -1; i--) #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) #define ALL(x) (x).begin(), (x).end() #define SORT(x) sort((x).begin(), (x).end()) #define RSORT(x) sort((x).rbegin(), (x).rend()) #define REVERSE(x) reverse((x).begin(), (x).end()) #define SZ(x) ((ll)(x).size()) #define pb push_back #define mp make_pair // chmax(a, b): a>bならaをbで更新 更新したときにtrueを返す // chmin(a, b): a<bならaをbで更新 更新したときにtrueを返す template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define dump(x) cerr << #x << "= " << (x) << endl; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll pow(ll a, ll b) { if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a; } ll pow(ll a, ll b, ll m) { if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m; } ll residue(ll a, ll m) { return ((a % m) + m) % m; }; ll dx[4] = {1, 0, -1, 0}; ll dy[4] = {0, 1, 0, -1}; const ll MAX_N = 1e4; ll n; ll a[MAX_N + 1]; Vi list_of_primes(ll n) { // return list of primes p <= n // primes[i] != 0 iff i is prime. Vi primes(n); FOR(i, 2, n) { primes[i] = i; } for (ll i = 2; i * i < n; ++i) if (primes[i]) for (ll j = i * i; j < n; j += i) primes[j] = 0; primes.erase(remove(primes.begin(), primes.end(), 0), primes.end()); return primes; } Vi prime_factors(ll n) { // return list of prime factors of n. if (n == 1) return {}; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { Vi ans = prime_factors(n / i); ans.pb(i); sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); return ans; } } return {n}; } bool hantei(ll p) { // cout << "p = " << p << endl; if (a[0] % p != 0) return false; Vi a_red(p - 1, 0); REP(i, n + 1) { a_red[i % (p - 1)] += a[i]; } REP(i, p - 1) { // printf("a_red[%d] == %d\n", i, a_red[i]); if (a_red[i] % p != 0) return false; } return true; } int main() { cin >> n; ll d = 0; REP(i, n + 1) { cin >> a[n - i]; d = gcd(d, abs(a[n - i])); } Vi P1 = prime_factors(d); // 係数全ての最大公約数は必ず条件を満たす. Vi P2 = list_of_primes(n + 1); for (auto &p : P2) { if (hantei(p)) P1.pb(p); } SORT(P1); for (auto &p : P1) { cout << p << endl; } }
replace
97
104
97
105
TLE
p03065
C++
Runtime Error
#include <bits/stdc++.h> #define For(i, x, y) for (register int i = (x); i <= (y); i++) #define FOR(i, x, y) for (register int i = (x); i < (y); i++) #define Dow(i, x, y) for (register int i = (x); i >= (y); i--) #define Debug(v) \ for (auto i : v) \ printf("%lld ", i); \ puts("") #define mp make_pair #define fi first #define se second #define pb push_back #define ep emplace_back #define siz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define fil(a, b) memset((a), (b), sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pa; typedef pair<ll, ll> PA; typedef vector<int> poly; inline ll read() { ll x = 0, f = 1; char c = getchar(); while ((c < '0' || c > '9') && (c != '-')) c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } const int N = 10010; int n, a[N], cnt, p[N]; bool vis[N]; inline int F(int x, int mod) { int nw = 1, ret = 0; For(i, 0, n) ret = (ret + 1ll * (a[i] % mod + mod) * nw) % mod, nw = 1ll * nw * x % mod; return ret; } int main() { srand(time(0)); n = read(); int g = 0; Dow(i, n, 0) a[i] = read(), g = __gcd(g, abs(a[i])); poly ans; for (int i = 2; i * i <= g; ++i) if (g % i == 0) ans.pb(i), g /= i; if (g != 1) ans.pb(g); For(i, 2, n) if (!vis[i]) { p[++cnt] = i; For(j, 2, n / j) vis[i * j] = 1; } For(i, 1, cnt) { bool flag = 1; FOR(j, 0, 20) { int x = (rand() << 16 ^ rand()) % p[i]; if (F(x, p[i])) { flag = 0; break; } } if (flag) ans.pb(p[i]); } sort(all(ans)), ans.resize(unique(all(ans)) - ans.begin()); for (auto i : ans) printf("%d\n", i); }
#include <bits/stdc++.h> #define For(i, x, y) for (register int i = (x); i <= (y); i++) #define FOR(i, x, y) for (register int i = (x); i < (y); i++) #define Dow(i, x, y) for (register int i = (x); i >= (y); i--) #define Debug(v) \ for (auto i : v) \ printf("%lld ", i); \ puts("") #define mp make_pair #define fi first #define se second #define pb push_back #define ep emplace_back #define siz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define fil(a, b) memset((a), (b), sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pa; typedef pair<ll, ll> PA; typedef vector<int> poly; inline ll read() { ll x = 0, f = 1; char c = getchar(); while ((c < '0' || c > '9') && (c != '-')) c = getchar(); if (c == '-') f = -1, c = getchar(); while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } const int N = 10010; int n, a[N], cnt, p[N]; bool vis[N]; inline int F(int x, int mod) { int nw = 1, ret = 0; For(i, 0, n) ret = (ret + 1ll * (a[i] % mod + mod) * nw) % mod, nw = 1ll * nw * x % mod; return ret; } int main() { srand(time(0)); n = read(); int g = 0; Dow(i, n, 0) a[i] = read(), g = __gcd(g, abs(a[i])); poly ans; for (int i = 2; i * i <= g; ++i) if (g % i == 0) ans.pb(i), g /= i; if (g != 1) ans.pb(g); For(i, 2, n) if (!vis[i]) { p[++cnt] = i; For(j, 2, n / i) vis[i * j] = 1; } For(i, 1, cnt) { bool flag = 1; FOR(j, 0, 20) { int x = (rand() << 16 ^ rand()) % p[i]; if (F(x, p[i])) { flag = 0; break; } } if (flag) ans.pb(p[i]); } sort(all(ans)), ans.resize(unique(all(ans)) - ans.begin()); for (auto i : ans) printf("%d\n", i); }
replace
58
59
58
59
0
p03066
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #define ll long long using namespace std; template <class T> inline void rd(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - '0' + c, c = getchar(); x *= f; } const int mod = 998244353, N = 3010; void Add(int &x, int y) { x = (x + y) % mod; } int Pow(int x, int y) { int res = 1; while (y) { if (y & 1) res = res * (ll)x % mod; x = x * (ll)x % mod, y >>= 1; } return res; } int fac[N], inv[N]; int C(int n, int m) { if (n < m) return 0; return fac[n] * (ll)inv[m] % mod * inv[n - m] % mod; } void get_fac(int n) { fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * (ll)i % mod; inv[n] = Pow(fac[n], mod - 2); for (int i = n; i >= 1; --i) inv[i - 1] = inv[i] * (ll)i % mod; } int cal1(int m, int n) { // m¸öλÖà Óà 1,2 ´Õ n return C(m, n - m); } int solve(int n, int X) { // n ¸öλÖà ²»³öÏÖ x int ans = 0; for (int i = 0; i < X; ++i) Add(ans, cal1(n, i)); if (2 * n < X) return ans; for (int i = 1; i * 2 <= X - 1; ++i) { Add(ans, cal1(n - i * 2, X - 1 - 2 * i)); } if (X % 2 == 1 && X - 1 < n) Add(ans, 1); return ans; } int main() { int n, X; rd(n), rd(X); get_fac(n); int ans = 0; for (int i = 0; i <= n; ++i) { // cout<<solve(i,X)<<endl; Add(ans, C(n, i) * (ll)solve(i, X) % mod); } printf("%d", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #define ll long long using namespace std; template <class T> inline void rd(T &x) { x = 0; char c = getchar(); int f = 1; while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) x = x * 10 - '0' + c, c = getchar(); x *= f; } const int mod = 998244353, N = 3010; void Add(int &x, int y) { x = (x + y) % mod; } int Pow(int x, int y) { int res = 1; while (y) { if (y & 1) res = res * (ll)x % mod; x = x * (ll)x % mod, y >>= 1; } return res; } int fac[N], inv[N]; int C(int n, int m) { if (n < m) return 0; return fac[n] * (ll)inv[m] % mod * inv[n - m] % mod; } void get_fac(int n) { fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * (ll)i % mod; inv[n] = Pow(fac[n], mod - 2); for (int i = n; i >= 1; --i) inv[i - 1] = inv[i] * (ll)i % mod; } int cal1(int m, int n) { // m¸öλÖà Óà 1,2 ´Õ n if (m > n) return 0; return C(m, n - m); } int solve(int n, int X) { // n ¸öλÖà ²»³öÏÖ x int ans = 0; for (int i = 0; i < X; ++i) Add(ans, cal1(n, i)); if (2 * n < X) return ans; for (int i = 1; i * 2 <= X - 1; ++i) { Add(ans, cal1(n - i * 2, X - 1 - 2 * i)); } if (X % 2 == 1 && X - 1 < n) Add(ans, 1); return ans; } int main() { int n, X; rd(n), rd(X); get_fac(n); int ans = 0; for (int i = 0; i <= n; ++i) { // cout<<solve(i,X)<<endl; Add(ans, C(n, i) * (ll)solve(i, X) % mod); } printf("%d", ans); return 0; }
insert
45
45
45
47
0
p03066
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N, X; ll con[6010][6010]; ll mod = 998244353; ll ans; int main() { cin >> N >> X; for (int i = 0; i < 6010; i++) for (int j = 0; j < 6010; j++) { if (i == j) con[i][j] = 1; else if (j == 0) con[i][j] = 1; else con[i][j] = (con[i - 1][j] + con[i - 1][j - 1]) % mod; } for (int i = 0; i <= N; i++) { ll tmp = 0; for (int j = 0; j <= i; j++) { if (2 * j < X - 1) continue; int t = (X - 1) - j; if (j - t != 0 && t < i - j) continue; tmp += con[max(0, j - (i - j))][max(0, t - (i - j))] * con[N][i]; tmp %= mod; } ans += tmp; ans %= mod; } for (int i = 0; i <= N; i++) { ll tmp = 0; for (int j = 0; j <= i; j++) { if (i - j + j * 2 < X - 1) { tmp += con[N][i] * con[i][j] % mod; tmp %= mod; } } ans += tmp; ans %= mod; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N, X; ll con[6010][6010]; ll mod = 998244353; ll ans; int main() { cin >> N >> X; for (int i = 0; i < 6010; i++) for (int j = 0; j <= i; j++) { if (i == j) con[i][j] = 1; else if (j == 0) con[i][j] = 1; else con[i][j] = (con[i - 1][j] + con[i - 1][j - 1]) % mod; } for (int i = 0; i <= N; i++) { ll tmp = 0; for (int j = 0; j <= i; j++) { if (2 * j < X - 1) continue; int t = (X - 1) - j; if (j - t != 0 && t < i - j) continue; tmp += con[max(0, j - (i - j))][max(0, t - (i - j))] * con[N][i]; tmp %= mod; } ans += tmp; ans %= mod; } for (int i = 0; i <= N; i++) { ll tmp = 0; for (int j = 0; j <= i; j++) { if (i - j + j * 2 < X - 1) { tmp += con[N][i] * con[i][j] % mod; tmp %= mod; } } ans += tmp; ans %= mod; } cout << ans << endl; }
replace
14
15
14
15
-11
p03066
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline int mygetchar() { #ifdef WIN32 return _getchar_nolock(); #else return getchar_unlocked(); #endif } inline int read() { int x = 0, f = 1; char c = mygetchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = mygetchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = mygetchar(); } return x * f; } const int MOD = 998244353; inline void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } inline int inc(int x, int y) { x += y; return x >= MOD ? x - MOD : x; } inline int mul(int x, int y) { return (ll)x * y % MOD; } inline int qpow(int x, int y) { int res = 1; for (; y; y >>= 1, x = mul(x, x)) if (y & 1) res = mul(res, x); return res; } const int MAXN = 3005; int n, X, c[MAXN][MAXN], ans = 0; inline int Solve(int len) { int res = 0; if (len * 2 < X || X & 1) res = 1; for (int i = 0; i < len; i++) { if (len + i < X) add(res, c[len][i]); else if ((len + i - X) & 1) { int S = len + i, l = (S - X + 1) / 2; if (len > l + l && i >= l + l) add(res, c[len - l - l][i - l - l]); } } return res; } int main() { n = read(), X = read(); for (int i = 0; i <= n * 2; i++) c[i][0] = 1; for (int i = 1; i <= n * 2; i++) for (int j = 1; j <= i; j++) c[i][j] = inc(c[i - 1][j], c[i - 1][j - 1]); for (int i = 0; i <= n; i++) add(ans, mul(c[n][i], Solve(n - i))); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; inline int mygetchar() { #ifdef WIN32 return _getchar_nolock(); #else return getchar_unlocked(); #endif } inline int read() { int x = 0, f = 1; char c = mygetchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = mygetchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = mygetchar(); } return x * f; } const int MOD = 998244353; inline void add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; } inline int inc(int x, int y) { x += y; return x >= MOD ? x - MOD : x; } inline int mul(int x, int y) { return (ll)x * y % MOD; } inline int qpow(int x, int y) { int res = 1; for (; y; y >>= 1, x = mul(x, x)) if (y & 1) res = mul(res, x); return res; } const int MAXN = 6005; int n, X, c[MAXN][MAXN], ans = 0; inline int Solve(int len) { int res = 0; if (len * 2 < X || X & 1) res = 1; for (int i = 0; i < len; i++) { if (len + i < X) add(res, c[len][i]); else if ((len + i - X) & 1) { int S = len + i, l = (S - X + 1) / 2; if (len > l + l && i >= l + l) add(res, c[len - l - l][i - l - l]); } } return res; } int main() { n = read(), X = read(); for (int i = 0; i <= n * 2; i++) c[i][0] = 1; for (int i = 1; i <= n * 2; i++) for (int j = 1; j <= i; j++) c[i][j] = inc(c[i - 1][j], c[i - 1][j - 1]); for (int i = 0; i <= n; i++) add(ans, mul(c[n][i], Solve(n - i))); printf("%d\n", ans); return 0; }
replace
44
45
44
45
0
p03066
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 998244353; const int maxn = 3005; ll f[maxn], inv[maxn], nf[maxn], s[maxn][maxn], dp[maxn][maxn], c[maxn], u[maxn * 2], v[maxn * 2]; ll ans; ll C(ll x, ll y) { return f[x] * nf[y] % M * nf[x - y] % M; } void add(ll &x, ll y) { x += y; if (x >= M) x -= M; } void add1(int l, int r, ll x) { add(u[l], x); add(u[r + 1], M - x); } void add2(int l, int r, ll x) { add(v[l], x); add(v[r + 1], M - x); } int n, k; int main() { cin >> n >> k; inv[1] = 1; for (int i = 2; i < maxn; i++) inv[i] = M - (M / i) * inv[M % i] % M; f[0] = nf[0] = 1; for (int i = 1; i < maxn; i++) f[i] = f[i - 1] * i % M, nf[i] = nf[i - 1] * inv[i] % M; dp[0][0] = 1; for (int i = 0; i < n; i++) for (int j = 0; j <= min(i * 2, k); j++) add(dp[i + 1][j + 1], dp[i][j]), add(dp[i + 1][j + 2], dp[i][j]); for (int i = 0; i <= n; i++) for (int j = 0; j < k; j++) (ans += dp[i][j] * C(n, i)) %= M; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; dp[1][1] = 1; for (int i = 1; i < n; i++) for (int j = 0; j <= min(i * 2, k); j++) add(dp[i + 1][j + 1], dp[i][j]), add(dp[i + 1][j + 2], dp[i][j]); for (int i = 0; i < n; i++) for (int j = 0; j <= k; j++) s[i + 1][j + 1] = dp[i][j]; if (k % 2 == 1) { for (int i = (k + 1) / 2; i <= n; i++) (ans += C(n, i)) %= M; } for (int i = 1 + k % 2; i < k; i += 2) for (int p = 1; p <= i; p++) if (s[p][i]) { int r = (k - i) / 2; int L = (k - i + 1) / 2, R = r * 2; if (L <= R) { add1(L + p, R + p, s[p][i] * (2 * r + p + 1) % M); add2(L + p, R + p, M - s[p][i]); } } for (int i = 1; i <= n; i++) add(u[i], u[i - 1]), add(v[i], v[i - 1]); for (int i = 0; i <= n; i++) c[i] = (u[i] + v[i] * i) % M; for (int i = 1; i <= n; i++) (ans += c[i] * C(n, i)) %= M; cout << (ans + M) % M << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 998244353; const int maxn = 6005; ll f[maxn], inv[maxn], nf[maxn], s[maxn][maxn], dp[maxn][maxn], c[maxn], u[maxn * 2], v[maxn * 2]; ll ans; ll C(ll x, ll y) { return f[x] * nf[y] % M * nf[x - y] % M; } void add(ll &x, ll y) { x += y; if (x >= M) x -= M; } void add1(int l, int r, ll x) { add(u[l], x); add(u[r + 1], M - x); } void add2(int l, int r, ll x) { add(v[l], x); add(v[r + 1], M - x); } int n, k; int main() { cin >> n >> k; inv[1] = 1; for (int i = 2; i < maxn; i++) inv[i] = M - (M / i) * inv[M % i] % M; f[0] = nf[0] = 1; for (int i = 1; i < maxn; i++) f[i] = f[i - 1] * i % M, nf[i] = nf[i - 1] * inv[i] % M; dp[0][0] = 1; for (int i = 0; i < n; i++) for (int j = 0; j <= min(i * 2, k); j++) add(dp[i + 1][j + 1], dp[i][j]), add(dp[i + 1][j + 2], dp[i][j]); for (int i = 0; i <= n; i++) for (int j = 0; j < k; j++) (ans += dp[i][j] * C(n, i)) %= M; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; dp[1][1] = 1; for (int i = 1; i < n; i++) for (int j = 0; j <= min(i * 2, k); j++) add(dp[i + 1][j + 1], dp[i][j]), add(dp[i + 1][j + 2], dp[i][j]); for (int i = 0; i < n; i++) for (int j = 0; j <= k; j++) s[i + 1][j + 1] = dp[i][j]; if (k % 2 == 1) { for (int i = (k + 1) / 2; i <= n; i++) (ans += C(n, i)) %= M; } for (int i = 1 + k % 2; i < k; i += 2) for (int p = 1; p <= i; p++) if (s[p][i]) { int r = (k - i) / 2; int L = (k - i + 1) / 2, R = r * 2; if (L <= R) { add1(L + p, R + p, s[p][i] * (2 * r + p + 1) % M); add2(L + p, R + p, M - s[p][i]); } } for (int i = 1; i <= n; i++) add(u[i], u[i - 1]), add(v[i], v[i - 1]); for (int i = 0; i <= n; i++) c[i] = (u[i] + v[i] * i) % M; for (int i = 1; i <= n; i++) (ans += c[i] * C(n, i)) %= M; cout << (ans + M) % M << endl; }
replace
4
5
4
5
-11
p03066
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define rep(i, n) for (i = 0; i < n; i++) #define int long long using namespace std; int mod = 998244353; int N, X; int comb[3001][6001]; int f[3001][6001]; int tate[3002][6002]; int yoko[3002][6002]; int F(int a, int b) { if (a < 0 || b < 0) return 0; return f[a][b]; } int Tate(int a, int b) { if (a < 0 || b < 0) return 0; return tate[a][b]; } int Yoko(int a, int b) { if (a < 0 || b < 0) return 0; return yoko[a][b]; } int calc(int n, int i) { int j; int res = 0; for (j = n - 2 * i - 1; j <= n - i - 1; j++) { res += F(j, X - 2 - 2 * i); res %= mod; } for (j = 0; j < X - 2 - 2 * i; j++) { res += F(n - i - 1, j); res %= mod; } // cout << "calc(" << n << ", " << i << ") = " << res << endl; return res; } int solve(int n) { int i; int ret = 0; for (i = 0; i < n; i++) { // 22…2, i個 + 1 + 何か ret += calc(n, i); ret %= mod; } // 全部2の場合は個別に計算 if (X % 2 == 0) ret += (n * 2 < X); else ret++; ret %= mod; return ret; } signed main() { int i, j; comb[0][0] = 1; for (i = 1; i < 3001; i++) { comb[i][0] = 1; for (j = 1; j < 6001; j++) { comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; comb[i][j] %= mod; } } for (i = 0; i < 3001; i++) { for (j = i; j <= 2 * i; j++) { f[i][j] = comb[i][j - i]; } } for (j = 0; j < 6001; j++) { tate[0][j] = 0; for (i = 1; i < 3002; i++) { tate[i][j] = tate[i - 1][j] + f[i - 1][j]; tate[i][j] %= mod; } } for (i = 0; i < 3001; i++) { yoko[i][0] = 0; for (j = 1; j < 6002; j++) { yoko[i][j] = yoko[i][j - 1] + f[i][j - 1]; yoko[i][j] %= mod; } } cin >> N >> X; int ans = 0; for (i = 0; i <= N; i++) { // zero int res = comb[N][i] * solve(N - i); res %= mod; ans += res; ans %= mod; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define rep(i, n) for (i = 0; i < n; i++) #define int long long using namespace std; int mod = 998244353; int N, X; int comb[3001][6001]; int f[3001][6001]; int tate[3002][6002]; int yoko[3002][6002]; int F(int a, int b) { if (a < 0 || b < 0) return 0; return f[a][b]; } int Tate(int a, int b) { if (a < 0 || b < 0) return 0; return tate[a][b]; } int Yoko(int a, int b) { if (a < 0 || b < 0) return 0; return yoko[a][b]; } int calc(int n, int i) { int j; int res = 0; int a = Tate(n - i, X - 2 - 2 * i); int b = Tate(n - 2 * i - 1, X - 2 - 2 * i); int c = Yoko(n - i - 1, X - 2 - 2 * i); res = (a - b + mod + c) % mod; // cout << "calc(" << n << ", " << i << ") = " << res << endl; return res; } int solve(int n) { int i; int ret = 0; for (i = 0; i < n; i++) { // 22…2, i個 + 1 + 何か ret += calc(n, i); ret %= mod; } // 全部2の場合は個別に計算 if (X % 2 == 0) ret += (n * 2 < X); else ret++; ret %= mod; return ret; } signed main() { int i, j; comb[0][0] = 1; for (i = 1; i < 3001; i++) { comb[i][0] = 1; for (j = 1; j < 6001; j++) { comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j]; comb[i][j] %= mod; } } for (i = 0; i < 3001; i++) { for (j = i; j <= 2 * i; j++) { f[i][j] = comb[i][j - i]; } } for (j = 0; j < 6001; j++) { tate[0][j] = 0; for (i = 1; i < 3002; i++) { tate[i][j] = tate[i - 1][j] + f[i - 1][j]; tate[i][j] %= mod; } } for (i = 0; i < 3001; i++) { yoko[i][0] = 0; for (j = 1; j < 6002; j++) { yoko[i][j] = yoko[i][j - 1] + f[i][j - 1]; yoko[i][j] %= mod; } } cin >> N >> X; int ans = 0; for (i = 0; i <= N; i++) { // zero int res = comb[N][i] * solve(N - i); res %= mod; ans += res; ans %= mod; } cout << ans << endl; return 0; }
replace
44
52
44
48
TLE
p03066
C++
Runtime Error
// warm heart, wagging tail,and a smile just for you! // ███████████ // ███╬╬╬╬╬╬╬╬╬╬███ // ███╬╬╬╬╬████╬╬╬╬╬╬███ // ███████████ // ██╬╬╬╬╬████╬╬████╬╬╬╬╬██ // █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██ // ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██ // ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██ // ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██ // ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████ // █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████ // ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██ // ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███ // ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██ // ██████████████ // ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████ // ███████ █████ // ███████████████████ // #include "bits/stdc++.h" using namespace std; #define INF (1 << 30) #define LINF (1LL << 60) #define fs first #define sc second #define int long long #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, a, b) for (int i = (b - 1); i >= (a); --i) #define REP(i, n) FOR(i, 0, (n)) #define RREP(i, n) RFOR(i, 0, (n)) #define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr) #define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr) #define range(i, a, b) ((a) <= (i) && (i) < (b)) #define debug(x) cout << #x << " = " << (x) << endl #define SP << " " << template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } #define MSB(x) (63 - __builtin_clzll(x)) #define pcnt(x) (__builtin_popcountll(x)) #define parity(i, j) (i & (1LL << j)) typedef pair<int, int> P; typedef tuple<int, int, int> T; vector<int> MODS = {1000000007, 998244353}; // 実行時に決まる template <int IND = 0> struct Fp { long long val; int MOD = MODS[IND]; constexpr Fp(long long v = 0) noexcept : val(v % MODS[IND]) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &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; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<IND> &x) noexcept { return os << x.val; } friend constexpr istream &operator>>(istream &is, Fp<IND> &x) noexcept { return is >> x.val; } friend constexpr Fp<IND> modpow(const Fp<IND> &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; } }; using mint = Fp<1>; // MODを変える場合は値を変更 typedef vector<mint> vec; typedef vector<vector<mint>> mat; vec fact, inv; void init(int n) { fact.assign(n + 1, 1); inv.assign(n + 1, 1); REP(i, n) fact[i + 1] = fact[i] * (i + 1), inv[i + 1] /= fact[i + 1]; } mint cmb(int n, int r) { if (n < r) return 0; return fact[n] * inv[r] * inv[n - r]; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; init(10000); mint ans = 0; mat s(k + 1, vec(k + 1, 0)); vec t(k + 1, 0); REP(i, k + 1) REP(j, k + 1) if (j >= i - j) s[i][j] = cmb(j, i - j); REP(i, k) REP(j, k + 1) s[i + 1][j] += s[i][j]; REP(i, k + 1) { t[i] = cmb(n, i); if (i) t[i] += t[i - 1]; } REP(i, n + 1) { if (k % 2 == 0 && i * 2 >= k) break; ans += cmb(n, i); } REP(i, n) { if (i * 2 + 1 >= k) break; int l = k - (i * 2 + 1) - 1; REP(j, l) { if (i + 1 + j > n) break; ans += s[l - 1][j] * cmb(n, i + 1 + j); } REP(j, l + 1) { ans += (t[j + i * 2 + 1] - t[j + i]) * cmb(j, l - j); } } cout << ans << endl; return 0; }
// warm heart, wagging tail,and a smile just for you! // ███████████ // ███╬╬╬╬╬╬╬╬╬╬███ // ███╬╬╬╬╬████╬╬╬╬╬╬███ // ███████████ // ██╬╬╬╬╬████╬╬████╬╬╬╬╬██ // █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██ // ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██ // ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██ // ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██ // ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████ // █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████ // ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██ // ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███ // ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████ // ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██ // ██████████████ // ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████ // ███████ █████ // ███████████████████ // #include "bits/stdc++.h" using namespace std; #define INF (1 << 30) #define LINF (1LL << 60) #define fs first #define sc second #define int long long #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, a, b) for (int i = (b - 1); i >= (a); --i) #define REP(i, n) FOR(i, 0, (n)) #define RREP(i, n) RFOR(i, 0, (n)) #define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr) #define RITR(itr, mp) for (auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr) #define range(i, a, b) ((a) <= (i) && (i) < (b)) #define debug(x) cout << #x << " = " << (x) << endl #define SP << " " << template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } #define MSB(x) (63 - __builtin_clzll(x)) #define pcnt(x) (__builtin_popcountll(x)) #define parity(i, j) (i & (1LL << j)) typedef pair<int, int> P; typedef tuple<int, int, int> T; vector<int> MODS = {1000000007, 998244353}; // 実行時に決まる template <int IND = 0> struct Fp { long long val; int MOD = MODS[IND]; constexpr Fp(long long v = 0) noexcept : val(v % MODS[IND]) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &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; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<IND> &x) noexcept { return os << x.val; } friend constexpr istream &operator>>(istream &is, Fp<IND> &x) noexcept { return is >> x.val; } friend constexpr Fp<IND> modpow(const Fp<IND> &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; } }; using mint = Fp<1>; // MODを変える場合は値を変更 typedef vector<mint> vec; typedef vector<vector<mint>> mat; vec fact, inv; void init(int n) { fact.assign(n + 1, 1); inv.assign(n + 1, 1); REP(i, n) fact[i + 1] = fact[i] * (i + 1), inv[i + 1] /= fact[i + 1]; } mint cmb(int n, int r) { if (n < r) return 0; return fact[n] * inv[r] * inv[n - r]; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; init(10000); mint ans = 0; mat s(k + 1, vec(k + 1, 0)); vec t(k + 1, 0); REP(i, k + 1) REP(j, k + 1) if (j >= i - j && i - j >= 0) s[i][j] = cmb(j, i - j); REP(i, k) REP(j, k + 1) s[i + 1][j] += s[i][j]; REP(i, k + 1) { t[i] = cmb(n, i); if (i) t[i] += t[i - 1]; } REP(i, n + 1) { if (k % 2 == 0 && i * 2 >= k) break; ans += cmb(n, i); } REP(i, n) { if (i * 2 + 1 >= k) break; int l = k - (i * 2 + 1) - 1; REP(j, l) { if (i + 1 + j > n) break; ans += s[l - 1][j] * cmb(n, i + 1 + j); } REP(j, l + 1) { ans += (t[j + i * 2 + 1] - t[j + i]) * cmb(j, l - j); } } cout << ans << endl; return 0; }
replace
151
152
151
153
-11
p03066
C++
Runtime Error
/* --- author: dxm --- */ #include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; #define INF 1e9 #define Inf 1e18 #define rep(i, n) for (int(i) = 0; (i) < n; i++) #define REP(i, n) for (int(i) = 1; (i) <= n; i++) #define mp make_pair #define pb push_back #define fst first #define snd second typedef long long ll; typedef double db; typedef long double ldb; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<long long, long long> pll; void qread(int &x) { int neg = 1; x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') neg = -1; c = getchar(); } while (c >= '0' && c <= '9') x = 10 * x + c - '0', c = getchar(); x *= neg; } const int maxn = 3005; const int mod = 998244353; int n, x; int fac[maxn * 2], ifac[maxn * 2]; int C(int a, int b) { return a < b ? 0 : 1LL * fac[a] * ifac[b] % mod * ifac[a - b] % mod; } int main() { #ifdef FILE freopen("FILE.in", "r", stdin); freopen("FILE.out", "w", stdout); #endif scanf("%d%d", &n, &x); fac[0] = fac[1] = ifac[0] = ifac[1] = 1; for (int i = 2; i <= 2 * n; i++) { fac[i] = 1LL * fac[i - 1] * i % mod; ifac[i] = 1LL * (mod - mod / i) * ifac[mod % i] % mod; } REP(i, 2 * n) ifac[i] = 1LL * ifac[i - 1] * ifac[i] % mod; int tot = 0; rep(i, n + 1) { int ans = 0; rep(s, x) ans = (ans + C(i, s - i)) % mod; rep(j, i) { int l = i - j + 1, r = j; if (l > r) { if (x - 1 == 2 * j) ans = (ans + 1) % mod; continue; } int s = x - 1 - 2 * (i - j); if (s < 0) continue; ans = (ans + C(r - l + 1, s - (r - l + 1))) % mod; } tot = (tot + 1LL * ans * C(n, i) % mod) % mod; } printf("%d\n", tot); #ifdef TIME printf("Running Time = %d ms\n", int(clock() * 1000.0 / CLOCKS_PER_SEC)); #endif return 0; } /* Input: ----------------- Output: */
/* --- author: dxm --- */ #include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; #define INF 1e9 #define Inf 1e18 #define rep(i, n) for (int(i) = 0; (i) < n; i++) #define REP(i, n) for (int(i) = 1; (i) <= n; i++) #define mp make_pair #define pb push_back #define fst first #define snd second typedef long long ll; typedef double db; typedef long double ldb; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<long long, long long> pll; void qread(int &x) { int neg = 1; x = 0; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') neg = -1; c = getchar(); } while (c >= '0' && c <= '9') x = 10 * x + c - '0', c = getchar(); x *= neg; } const int maxn = 3005; const int mod = 998244353; int n, x; int fac[maxn * 2], ifac[maxn * 2]; int C(int a, int b) { return (b < 0 || a < b) ? 0 : 1LL * fac[a] * ifac[b] % mod * ifac[a - b] % mod; } int main() { #ifdef FILE freopen("FILE.in", "r", stdin); freopen("FILE.out", "w", stdout); #endif scanf("%d%d", &n, &x); fac[0] = fac[1] = ifac[0] = ifac[1] = 1; for (int i = 2; i <= 2 * n; i++) { fac[i] = 1LL * fac[i - 1] * i % mod; ifac[i] = 1LL * (mod - mod / i) * ifac[mod % i] % mod; } REP(i, 2 * n) ifac[i] = 1LL * ifac[i - 1] * ifac[i] % mod; int tot = 0; rep(i, n + 1) { int ans = 0; rep(s, x) ans = (ans + C(i, s - i)) % mod; rep(j, i) { int l = i - j + 1, r = j; if (l > r) { if (x - 1 == 2 * j) ans = (ans + 1) % mod; continue; } int s = x - 1 - 2 * (i - j); if (s < 0) continue; ans = (ans + C(r - l + 1, s - (r - l + 1))) % mod; } tot = (tot + 1LL * ans * C(n, i) % mod) % mod; } printf("%d\n", tot); #ifdef TIME printf("Running Time = %d ms\n", int(clock() * 1000.0 / CLOCKS_PER_SEC)); #endif return 0; } /* Input: ----------------- Output: */
replace
40
41
40
42
0
p03066
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 998244353; void add(int64_t &a, int64_t b) { a = (a + b) % MOD; } void mul(int64_t &a, int64_t b) { a = (a * b) % MOD; } vector<int64_t> fact, seq_inv, fact_inv; void create_fact_mod(int num) { fact[0] = 1; fact[1] = 1; for (int i = 2; i <= num; i++) { fact[i] = fact[i - 1] * i % MOD; } } void create_seq_inv_mod(int num) { seq_inv[0] = 1; seq_inv[1] = 1; for (int i = 2; i <= num; i++) { seq_inv[i] = (MOD - MOD / i) * seq_inv[MOD % i] % MOD; } } void create_fact_inv_mod(int num) { fact_inv[0] = 1; fact_inv[1] = 1; for (int i = 2; i <= num; i++) { fact_inv[i] = fact_inv[i - 1] * seq_inv[i] % MOD; } } void create_mod_tables(int num) { fact.resize(num + 1); seq_inv.resize(num + 1); fact_inv.resize(num + 1); create_fact_mod(num); create_seq_inv_mod(num); create_fact_inv_mod(num); } int64_t comb_mod(int n, int k) { return fact[n] * fact_inv[n - k] % MOD * fact_inv[k] % MOD; } int64_t perm_mod(int n, int k) { return fact[n] * fact_inv[n - k] % MOD; } int main() { int N, X; cin >> N >> X; create_mod_tables(6010); static int64_t dp[3001][3010], sub[3001][3010]; dp[0][0] = 1; sub[0][0] = 1; for (int i = 0; i < N; i++) for (int j = 0; j <= 2 * N; j++) { for (int k = 0; k <= 2; k++) add(dp[i + 1][j + k], dp[i][j]); for (int k = 1; k <= 2; k++) add(sub[i + 1][j + k], sub[i][j]); } int64_t ans = 0; for (int j = 0; j < X; j++) add(ans, dp[N][j]); for (int t = X + 1; t <= 2 * N; t += 2) { int s = t + 1 - X; if (X % 2 == 0 && X <= s) break; if (s <= X - 1) { for (int d = 0; d <= N; d++) { int64_t result = 1; mul(result, sub[d][X - 1 - s]); int stp = s / 2 + d + (t - (X - 1)) / 2; if (stp > N) continue; mul(result, comb_mod(N, stp)); add(ans, result); } } else { add(ans, comb_mod(N, t / 2)); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int64_t MOD = 998244353; void add(int64_t &a, int64_t b) { a = (a + b) % MOD; } void mul(int64_t &a, int64_t b) { a = (a * b) % MOD; } vector<int64_t> fact, seq_inv, fact_inv; void create_fact_mod(int num) { fact[0] = 1; fact[1] = 1; for (int i = 2; i <= num; i++) { fact[i] = fact[i - 1] * i % MOD; } } void create_seq_inv_mod(int num) { seq_inv[0] = 1; seq_inv[1] = 1; for (int i = 2; i <= num; i++) { seq_inv[i] = (MOD - MOD / i) * seq_inv[MOD % i] % MOD; } } void create_fact_inv_mod(int num) { fact_inv[0] = 1; fact_inv[1] = 1; for (int i = 2; i <= num; i++) { fact_inv[i] = fact_inv[i - 1] * seq_inv[i] % MOD; } } void create_mod_tables(int num) { fact.resize(num + 1); seq_inv.resize(num + 1); fact_inv.resize(num + 1); create_fact_mod(num); create_seq_inv_mod(num); create_fact_inv_mod(num); } int64_t comb_mod(int n, int k) { return fact[n] * fact_inv[n - k] % MOD * fact_inv[k] % MOD; } int64_t perm_mod(int n, int k) { return fact[n] * fact_inv[n - k] % MOD; } int main() { int N, X; cin >> N >> X; create_mod_tables(6010); static int64_t dp[3001][6010], sub[3001][6010]; dp[0][0] = 1; sub[0][0] = 1; for (int i = 0; i < N; i++) for (int j = 0; j <= 2 * N; j++) { for (int k = 0; k <= 2; k++) add(dp[i + 1][j + k], dp[i][j]); for (int k = 1; k <= 2; k++) add(sub[i + 1][j + k], sub[i][j]); } int64_t ans = 0; for (int j = 0; j < X; j++) add(ans, dp[N][j]); for (int t = X + 1; t <= 2 * N; t += 2) { int s = t + 1 - X; if (X % 2 == 0 && X <= s) break; if (s <= X - 1) { for (int d = 0; d <= N; d++) { int64_t result = 1; mul(result, sub[d][X - 1 - s]); int stp = s / 2 + d + (t - (X - 1)) / 2; if (stp > N) continue; mul(result, comb_mod(N, stp)); add(ans, result); } } else { add(ans, comb_mod(N, t / 2)); } } cout << ans << endl; return 0; }
replace
53
54
53
54
-11
p03067
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 1000 #define pb push_back #define mp make_pair #define ll long long #define mod 1000000007 #define all(cont) cont.begin(), cont.end() #define sortcmp(n, cmpfunc) sort(all(n), cmpfunc) #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0) ll powm(ll a, ll b); ll divm(ll a, ll b); ll multm(ll a, ll b); ll subm(ll a, ll b); ll addm(ll a, ll b); int main() { int a, b, c; fastio; #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif cin >> a >> b >> c; if (min(a, b) < c && max(a, b) > c) cout << "Yes\n"; else cout << "No\n"; return 0; } // template function ll gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll powm(ll a, ll b) { ll x = 1, y = a; while (b > 0) { if (b % 2) x = (x * y) % mod; y = (y * y) % mod; b /= 2; } return x % mod; } ll multm(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; } ll divm(ll a, ll b) { return (a * powm(b, mod - 2)); } ll subm(ll a, ll b) { a -= b; if (a < 0) a += mod; return a; } ll addm(ll a, ll b) { a += b; if (a >= mod) a -= mod; return a; }
#include <bits/stdc++.h> using namespace std; #define N 1000 #define pb push_back #define mp make_pair #define ll long long #define mod 1000000007 #define all(cont) cont.begin(), cont.end() #define sortcmp(n, cmpfunc) sort(all(n), cmpfunc) #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0) ll powm(ll a, ll b); ll divm(ll a, ll b); ll multm(ll a, ll b); ll subm(ll a, ll b); ll addm(ll a, ll b); int main() { int a, b, c; fastio; // #ifndef ONLINE_JUDGE // freopen("input.in", "r", stdin); // freopen("output.out", "w", stdout); // #endif cin >> a >> b >> c; if (min(a, b) < c && max(a, b) > c) cout << "Yes\n"; else cout << "No\n"; return 0; } // template function ll gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll powm(ll a, ll b) { ll x = 1, y = a; while (b > 0) { if (b % 2) x = (x * y) % mod; y = (y * y) % mod; b /= 2; } return x % mod; } ll multm(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; } ll divm(ll a, ll b) { return (a * powm(b, mod - 2)); } ll subm(ll a, ll b) { a -= b; if (a < 0) a += mod; return a; } ll addm(ll a, ll b) { a += b; if (a >= mod) a -= mod; return a; }
replace
23
27
23
27
0
p03067
Python
Runtime Error
A = input() B = input() C = input() if A > C > B: print("Yes") elif B > C > A: print("Yes") else: print("No")
A, B, C = map(int, input().split()) if A > C > B: print("Yes") elif B > C > A: print("Yes") else: print("No")
replace
0
3
0
1
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03067/Python/s744819372.py", line 2, in <module> B = input() EOFError: EOF when reading a line
p03067
Python
Runtime Error
n = int(input()) s = list(input()) k = int(input()) d = s[k - 1] for i in range(n): if s[i] != d: s[i] = "*" print("".join(s))
a, b, c = map(int, input().split()) if a < c < b or b < c < a: print("Yes") else: print("No")
replace
0
8
0
5
ValueError: invalid literal for int() with base 10: '3 8 5'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03067/Python/s139472791.py", line 1, in <module> n = int(input()) ValueError: invalid literal for int() with base 10: '3 8 5'
p03067
Python
Runtime Error
# -*- coding: utf-8 -*- a, b, c = map(int, input().split()) ab = int(b / a) if a < c < b or b < c < a: print("Yes") else: print("No")
# -*- coding: utf-8 -*- a, b, c = map(int, input().split()) if a < c < b or b < c < a: print("Yes") else: print("No")
delete
2
3
2
2
0
p03067
Python
Runtime Error
input_str = input() homes = input_str.split(" ") for home in homes: home = int(home) print(homes) if (homes[2] - homes[1]) * (homes[2] - homes[0]) < 0: print("Yes") else: print("No")
input_str = input() homes = input_str.split(" ") for i, home in enumerate(homes): homes[i] = int(home) if (homes[2] - homes[1]) * (homes[2] - homes[0]) < 0: print("Yes") else: print("No")
replace
2
5
2
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/p03067/Python/s964196810.py", line 6, in <module> if ((homes[2] - homes[1]) * (homes[2] - homes[0]) < 0): TypeError: unsupported operand type(s) for -: 'str' and 'str'
p03068
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int main() { int n, k; cin >> n; vector<char> s(n); for (int i = 0; i < n; i++) { cin >> s.at(i); } cin >> k; char con = s.at(k); for (int i = 0; i < n; i++) { if (s.at(i) != con) { s.at(i) = '*'; } } for (int i = 0; i < n; i++) { cout << s.at(i); } cout << endl; }
#include <iostream> #include <vector> using namespace std; int main() { int n, k; cin >> n; vector<char> s(n); for (int i = 0; i < n; i++) { cin >> s.at(i); } cin >> k; char con = s.at(k - 1); // cout << con << endl; for (int i = 0; i < n; i++) { if (s.at(i) != con) { s.at(i) = '*'; } } for (int i = 0; i < n; i++) { cout << s.at(i); } cout << endl; }
replace
12
13
12
14
0
p03068
C++
Runtime Error
#include <algorithm> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> typedef long long ll; ll mod = 1e9 + 7; using namespace std; int main() { int n, k; string s; cin >> n >> s >> k; char c = s.at(k); for (int i = 0; i < s.size(); i++) { if (s.at(i) == c) cout << c; else { cout << '*'; } } cout << endl; return 0; }
#include <algorithm> #include <functional> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> typedef long long ll; ll mod = 1e9 + 7; using namespace std; int main() { int n, k; string s; cin >> n >> s >> k; char c = s.at(k - 1); for (int i = 0; i < s.size(); i++) { if (s.at(i) == c) cout << c; else { cout << '*'; } } cout << endl; return 0; }
replace
20
21
20
21
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; string s; cin >> n >> s >> k; for (int i = 0; i < n; i++) { if (s.at(i) != s.at(k)) { s.at(i) = '*'; } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; string s; cin >> n >> s >> k; for (int i = 0; i < n; i++) { if (s.at(i) != s.at(k - 1)) { s.at(i) = '*'; } } cout << s << endl; }
replace
7
8
7
8
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; string S; char C; cin >> N; cin >> S; cin >> K; C = S.at(K); for (int i = 0; i < N; i++) { if (S.at(i) != C) { cout << "*"; } else { cout << S.at(i); } } }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; string S; char C; cin >> N; cin >> S; cin >> K; C = S.at(K - 1); for (int i = 0; i < N; i++) { if (S.at(i) != C) { cout << "*"; } else { cout << S.at(i); } } }
replace
12
13
12
13
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; string S; cin >> N >> S >> K; char a = S.at(K); for (int i = 0; i < N; i++) { if (S.at(i) != a) { S.at(i) = '*'; } } cout << S << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; string S; cin >> N >> S >> K; char a = S.at(K - 1); for (int i = 0; i < N; i++) { if (S.at(i) != a) { S.at(i) = '*'; } } cout << S << endl; }
replace
7
8
7
8
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; string S; char X = '*', t; cin >> N >> S >> K; char Y = S.at(K); for (int i = 0; i < N; i++) { t = S.at(i); if (t != Y) { S.at(i) = X; } } cout << S << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; string S; char X = '*', t; cin >> N >> S >> K; K--; char Y = S.at(K); for (int i = 0; i < N; i++) { t = S.at(i); if (t != Y) { S.at(i) = X; } } cout << S << endl; }
insert
8
8
8
9
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int k, i, j, n; string s; cin >> n >> s >> k; for (i = 0; i < n; i++) { if (s.at(i) != s.at(k)) { s.at(i) = '*'; } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int k, i, j, n; string s; cin >> n >> s >> k; for (i = 0; i < n; i++) { if (s.at(i) != s.at(k - 1)) { s.at(i) = '*'; } } cout << s << endl; }
replace
7
8
7
8
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 1000 #define pb push_back #define mp make_pair #define ll long long #define mod 1000000007 #define all(cont) cont.begin(), cont.end() #define sortcmp(n, cmpfunc) sort(all(n), cmpfunc) #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0) ll powm(ll a, ll b); ll divm(ll a, ll b); ll multm(ll a, ll b); ll subm(ll a, ll b); ll addm(ll a, ll b); int main() { int n, k; string s; fastio; #ifndef LOCAL freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif cin >> n >> s >> k; for (auto i : s) { if (i != s[k - 1]) cout << '*'; else cout << i; } cout << endl; return 0; } // template function ll gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll powm(ll a, ll b) { ll x = 1, y = a; while (b > 0) { if (b % 2) x = (x * y) % mod; y = (y * y) % mod; b /= 2; } return x % mod; } ll multm(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; } ll divm(ll a, ll b) { return (a * powm(b, mod - 2)); } ll subm(ll a, ll b) { a -= b; if (a < 0) a += mod; return a; } ll addm(ll a, ll b) { a += b; if (a >= mod) a -= mod; return a; }
#include <bits/stdc++.h> using namespace std; #define N 1000 #define pb push_back #define mp make_pair #define ll long long #define mod 1000000007 #define all(cont) cont.begin(), cont.end() #define sortcmp(n, cmpfunc) sort(all(n), cmpfunc) #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0) ll powm(ll a, ll b); ll divm(ll a, ll b); ll multm(ll a, ll b); ll subm(ll a, ll b); ll addm(ll a, ll b); int main() { int n, k; string s; fastio; // #ifndef LOCAL // freopen("input.in", "r", stdin); // freopen("output.out", "w", stdout); // #endif cin >> n >> s >> k; for (auto i : s) { if (i != s[k - 1]) cout << '*'; else cout << i; } cout << endl; return 0; } // template function ll gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll powm(ll a, ll b) { ll x = 1, y = a; while (b > 0) { if (b % 2) x = (x * y) % mod; y = (y * y) % mod; b /= 2; } return x % mod; } ll multm(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; } ll divm(ll a, ll b) { return (a * powm(b, mod - 2)); } ll subm(ll a, ll b) { a -= b; if (a < 0) a += mod; return a; } ll addm(ll a, ll b) { a += b; if (a >= mod) a -= mod; return a; }
replace
24
28
24
28
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; int K; cin >> K; for (int i = 0; i < N; i++) { if (S.at(i) != S.at(K)) { S.at(i) = '*'; } } cout << S << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; int K; cin >> K; for (int i = 0; i < N; i++) { if (S.at(i) != S.at(K - 1)) { S.at(i) = '*'; } } cout << S << endl; }
replace
12
13
12
13
0
p03068
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define int long long #define str string #define rep(x, y) for (int i = x; i < y; i++) #define REP(x, y) for (int j = x; j < y; j++) #define all(x) x.begin(), x.end() signed main() { int A, B, C, N, K; str S, W, T; cin >> N >> S; cin >> K; rep(0, N) { if (S.at(i) != S.at(K)) { S.at(i) = '*'; } } cout << S << endl; }
#include <algorithm> #include <bits/stdc++.h> using namespace std; #define int long long #define str string #define rep(x, y) for (int i = x; i < y; i++) #define REP(x, y) for (int j = x; j < y; j++) #define all(x) x.begin(), x.end() signed main() { int A, B, C, N, K; str S, W, T; cin >> N >> S; cin >> K; rep(0, N) { if (S.at(K - 1) != S.at(i)) { S.at(i) = '*'; } } cout << S << endl; }
replace
14
15
14
15
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S; int N, K; cin >> N >> S >> K; for (int i = 0; i < N; i++) { if (S.at(i) != S.at(K)) { S.at(i) = '*'; } } cout << S << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S; int N, K; cin >> N >> S >> K; for (int i = 0; i < N; i++) { if (S.at(i) != S.at(K - 1)) { S.at(i) = '*'; } } cout << S << endl; }
replace
8
9
8
9
0
p03068
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int k, n; string s; cin >> n >> s >> k; char hoge = s.at(k); for (auto &&i = s.begin(); i < s.end(); i++) { if (*i != hoge) { *i = '*'; } } cout << s << endl; }
#include <iostream> #include <string> using namespace std; int main() { int k, n; string s; cin >> n >> s >> k; char hoge = s.at(k - 1); for (auto &&i = s.begin(); i < s.end(); i++) { if (*i != hoge) { *i = '*'; } } cout << s << endl; }
replace
8
9
8
9
0
p03068
C++
Runtime Error
#include <iostream> using namespace std; int main() { int N, K; string S; char SelectedChar; cin >> N >> S >> K; SelectedChar = S.at(K); for (int i = 0; i < N; i++) { if (S.at(i) != SelectedChar) { S.at(i) = '*'; } } cout << S << endl; }
#include <iostream> using namespace std; int main() { int N, K; string S; char SelectedChar; cin >> N >> S >> K; SelectedChar = S.at(K - 1); for (int i = 0; i < N; i++) { if (S.at(i) != SelectedChar) { S.at(i) = '*'; } } cout << S << endl; }
replace
8
9
8
9
0
p03068
C++
Runtime Error
#include <iostream> using namespace std; int main() { int N, K; char S[N]; cin >> N >> S >> K; char a = S[K - 1]; for (int i = 0; i < N; i++) { if (S[i] != a) { S[i] = '*'; } } std::cout << N << std::endl; return 0; }
#include <iostream> using namespace std; int main() { int N, K; char S[N]; cin >> N >> S >> K; char a = S[K - 1]; for (int i = 0; i < N; i++) { if (S[i] != a) { S[i] = '*'; } } std::cout << S << std::endl; return 0; }
replace
14
15
14
15
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; string s; int n, k; char c; int main() { cin >> n >> s >> k; c = s.at(k); for (int i = 0; i < n; ++i) { if (s.at(i) != c) { s.at(i) = '*'; } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; string s; int n, k; char c; int main() { cin >> n >> s >> k; c = s.at(k - 1); for (int i = 0; i < n; ++i) { if (s.at(i) != c) { s.at(i) = '*'; } } cout << s << endl; }
replace
10
11
10
11
0
p03068
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, k; string s; cin >> n; cin >> s; cin >> k; char moji = s.at(k); for (int i = 0; i < n; i++) { if (s.at(i) != moji) { s.at(i) = '*'; } } cout << s << endl; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, k; string s; cin >> n; cin >> s; cin >> k; char moji = s.at(k - 1); for (int i = 0; i < n; i++) { if (s.at(i) != moji) { s.at(i) = '*'; } } cout << s << endl; }
replace
13
14
13
14
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N; string s; cin >> s >> K; char x; x = s.at(K); for (int i = 0; i < N; i++) { if (x != s.at(i)) { cout << "*"; } else { cout << x; } } }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N; string s; cin >> s >> K; char x; x = s.at(K - 1); for (int i = 0; i < N; i++) { if (x != s.at(i)) { cout << "*"; } else { cout << x; } } }
replace
10
11
10
11
0
p03068
C++
Runtime Error
// ABC_128_B// pair型の中にpair型 /*int main() { int n; cin >> n; vector<pair<pair<string,int>,int>> a(n); for(int i=0;i<n;i++){ string s; cin >> s; int num; cin >> num; num = num * -1; a.at(i).first.first = s; a.at(i).first.second = num; a.at(i).second = i; } sort(a.begin(), a.end()); for(int i=0;i<n;i++){ cout << a.at(i).second +1 << endl; } } */ // ABC_058_Cのように // s.at(j) == a のとき // cout << s.at(j)-'0' - 49 << endl; // とすると、「0」を出力してくれる。 →もっといいほかの方法はないの? // 全bit探索を入れよう!! /*ABC_167_C skill up などを参考に… //https://qiita.com/hareku/items/3d08511eab56a481c7db int main() { int n = 3; // {0, 1, ..., n-1} の部分集合の全探索 for (int bit = 0; bit < (1<<n); ++bit) { vector<int> S; for (int i = 0; i < n; ++i) { if (bit & (1<<i)) { // 列挙に i が含まれるか S.push_back(i); } } cout << bit << ": {"; for (int i = 0; i < (int)S.size(); ++i) { cout << S[i] << " "; } cout << "}" << endl; } } */ // next_permutation(順列列挙) /*https://note.com/memenekokaburi/n/nf0201d6002cd ABC_150_Cなど。 int main() { int n; cin >> n ; vector<int>array = {}; for(int i=0;i<n;i++){ array.push_back(i); } do{ for(int i=0; i<n; i++){ cout << array.at(i); if(i!=n-1)cout<<" "; } cout<<endl; }while(next_permutation(array.begin(),array.end())); return 0; } */ // ABC126_Cのように関数でdouble型で返ってきてほしい場合はdouble // kan_halfのようにかく /* //ABC_041_C// pair型 int main() { int n; cin >> n; vector<pair<int,int>>a(n); for(int i=0;i<n;i++){ int num; cin >> num; a.at(i).first = num; a.at(i).second = i; } sort(a.begin(), a.end()); reverse(a.begin(),a.end()); for(int i=0;i<n;i++){ cout << a.at(i).second + 1<< endl; } } */ /*ABC_068_C //boolの配列を使って bool s[200050] = {}; bool t[200050] = {}; int main() { ll n, m; cin >> n >> m; for (int i = 0; i < m; i++){ ll a, b; cin >> a >> b; if (a == 1) { t[b] = true; } if (b == n) { s[a] = true; } } for (int i = 0; i < 200050; i++){ if (s[i] && t[i]) { cout << "POSSIBLE" << endl; return 0; } } cout << "IMPOSSIBLE" << endl; return 0; } */ // int32 4 signed, signed int, int -2,147,483,648 ~ 2,147,483,647 = // 2*10^9 再帰関数 ABC_029_C /* void f(int rest , string s){ if(rest == 0){ cout << s << endl; } else{ for(char moji = 'a' ;moji <='c' ; moji++){ f(rest-1,s+moji); } } } int main() { int n; cin >> n; f(n, ""); } */ // 連想配列 ARC_081_Cの解答 //ABC073でも復習できます。 /* int main() { ll n; cin >> n; vector<ll>a(n); rep(i,n) cin>>a.at(i); map<ll,ll>mp; rep(i,n){ mp[a.at(i)]++; } ll one = 0; ll two = 0; for(auto p:mp){ // cout << p.first << " " << p.second << endl; if(p.second >= 2){ if(one <= p.first){ two = one; one = p.first; } } if(p.second >= 4){ if(one <= p.first){ two = p.first; one = p.first; } } } // cout << one << endl; // cout << two << endl; // cout << endl; cout << one * two << endl; } */ // #define pi 3.14159265359 // 桁数を指定して出力する方法 // #include <iomanip>//これをincludeしておかないといけない // cout << fixed << setprecision(20)<< ans << endl; // s.at(0) = toupper(s.at(0));//小文字なら大文字へ//大文字の場合はそのまま // s.at(i) = tolower(s.at(i));//大文字なら小文字へ//小文字の場合はそのまま // getline(cin, s); //空白文字を含むものをまとめて入力できる。 // s配列に格納した単語を、辞書順にソートする // sort(s.begin(), s.end()); // string t = "keyence";//で文字列を格納できる // s.empty() //emptyなら1を出力 入っていれば0を出力 /*//ABC018-B 部分的にreverseをかける解法 int main() { string s; cin >> s; int n; cin >> n; vector<int>a(n); vector<int>b(n); rep(i,n) cin>>a.at(i)>>b.at(i); rep(i,n)a.at(i)--; rep(i,n)b.at(i)--; string t; rep(i,n){ t = s; for(int k=0;k<=b.at(i)-a.at(i);k++){ t.at(a.at(i)+k) = s.at(b.at(i)-k); } s = t; } cout << s << endl; } *///ABC018-B // cout << char(i+48) << // endl;//なぜかaは47と得る時がある。+48で出力もaにできる。 cout << char(97) << // endl;//アスキーコードでaを出力 // sort(b.begin(), b.end());//bという配列を小さい方からソート // reverse(b.begin(), b.end());//bという配列をリターン /*01 02 03 12 13 23 と6回見ていくパターン for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ } } */ // vector<vector<int>> a(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言 // 10のi乗pow(10, i);//ただしdouble型のため注意 /*string s; stringでの文字列を数字型に変える方法 cin >> s; rep(i,s.size()-2) { int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0'; */ #include <bits/stdc++.h> #include <iomanip> //これをincludeしておかないといけない using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define PI 3.14159265359 ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } ll lcm(ll a, ll b) { // return a * b / gcd(a, b); return a / gcd(a, b) * b; } int kan_hyaku(int n) { int kurai = 0; for (int i = 0; i < 3; i++) { kurai = n % 10; n /= 10; } return kurai; } int kan_ju(int n) { int kurai = 0; for (int i = 0; i < 2; i++) { kurai = n % 10; n /= 10; } return kurai; } int kan_ichi(int n) { int kurai = 0; for (int i = 0; i < 1; i++) { kurai = n % 10; n /= 10; } return kurai; } int keta(int n) { int wa = 1; while (n > 0) { wa *= 10; n--; } return wa; } double kan_half(int n) { double wa = 1; while (n > 0) { // cout << "TEST"<<endl; wa *= 0.5; // cout << wa << endl; n--; } return wa; } ll facctorialMethod(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum = sum % 1000000007 * i % 1000000007; } return sum; } /* int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a.at(i); */ bool red[100010] = {}; int main() { int n, k; string s; cin >> n >> s >> k; char moji = s.at(k); rep(i, n) { if (s.at(i) != moji) { s.at(i) = '*'; } } cout << s << endl; }
// ABC_128_B// pair型の中にpair型 /*int main() { int n; cin >> n; vector<pair<pair<string,int>,int>> a(n); for(int i=0;i<n;i++){ string s; cin >> s; int num; cin >> num; num = num * -1; a.at(i).first.first = s; a.at(i).first.second = num; a.at(i).second = i; } sort(a.begin(), a.end()); for(int i=0;i<n;i++){ cout << a.at(i).second +1 << endl; } } */ // ABC_058_Cのように // s.at(j) == a のとき // cout << s.at(j)-'0' - 49 << endl; // とすると、「0」を出力してくれる。 →もっといいほかの方法はないの? // 全bit探索を入れよう!! /*ABC_167_C skill up などを参考に… //https://qiita.com/hareku/items/3d08511eab56a481c7db int main() { int n = 3; // {0, 1, ..., n-1} の部分集合の全探索 for (int bit = 0; bit < (1<<n); ++bit) { vector<int> S; for (int i = 0; i < n; ++i) { if (bit & (1<<i)) { // 列挙に i が含まれるか S.push_back(i); } } cout << bit << ": {"; for (int i = 0; i < (int)S.size(); ++i) { cout << S[i] << " "; } cout << "}" << endl; } } */ // next_permutation(順列列挙) /*https://note.com/memenekokaburi/n/nf0201d6002cd ABC_150_Cなど。 int main() { int n; cin >> n ; vector<int>array = {}; for(int i=0;i<n;i++){ array.push_back(i); } do{ for(int i=0; i<n; i++){ cout << array.at(i); if(i!=n-1)cout<<" "; } cout<<endl; }while(next_permutation(array.begin(),array.end())); return 0; } */ // ABC126_Cのように関数でdouble型で返ってきてほしい場合はdouble // kan_halfのようにかく /* //ABC_041_C// pair型 int main() { int n; cin >> n; vector<pair<int,int>>a(n); for(int i=0;i<n;i++){ int num; cin >> num; a.at(i).first = num; a.at(i).second = i; } sort(a.begin(), a.end()); reverse(a.begin(),a.end()); for(int i=0;i<n;i++){ cout << a.at(i).second + 1<< endl; } } */ /*ABC_068_C //boolの配列を使って bool s[200050] = {}; bool t[200050] = {}; int main() { ll n, m; cin >> n >> m; for (int i = 0; i < m; i++){ ll a, b; cin >> a >> b; if (a == 1) { t[b] = true; } if (b == n) { s[a] = true; } } for (int i = 0; i < 200050; i++){ if (s[i] && t[i]) { cout << "POSSIBLE" << endl; return 0; } } cout << "IMPOSSIBLE" << endl; return 0; } */ // int32 4 signed, signed int, int -2,147,483,648 ~ 2,147,483,647 = // 2*10^9 再帰関数 ABC_029_C /* void f(int rest , string s){ if(rest == 0){ cout << s << endl; } else{ for(char moji = 'a' ;moji <='c' ; moji++){ f(rest-1,s+moji); } } } int main() { int n; cin >> n; f(n, ""); } */ // 連想配列 ARC_081_Cの解答 //ABC073でも復習できます。 /* int main() { ll n; cin >> n; vector<ll>a(n); rep(i,n) cin>>a.at(i); map<ll,ll>mp; rep(i,n){ mp[a.at(i)]++; } ll one = 0; ll two = 0; for(auto p:mp){ // cout << p.first << " " << p.second << endl; if(p.second >= 2){ if(one <= p.first){ two = one; one = p.first; } } if(p.second >= 4){ if(one <= p.first){ two = p.first; one = p.first; } } } // cout << one << endl; // cout << two << endl; // cout << endl; cout << one * two << endl; } */ // #define pi 3.14159265359 // 桁数を指定して出力する方法 // #include <iomanip>//これをincludeしておかないといけない // cout << fixed << setprecision(20)<< ans << endl; // s.at(0) = toupper(s.at(0));//小文字なら大文字へ//大文字の場合はそのまま // s.at(i) = tolower(s.at(i));//大文字なら小文字へ//小文字の場合はそのまま // getline(cin, s); //空白文字を含むものをまとめて入力できる。 // s配列に格納した単語を、辞書順にソートする // sort(s.begin(), s.end()); // string t = "keyence";//で文字列を格納できる // s.empty() //emptyなら1を出力 入っていれば0を出力 /*//ABC018-B 部分的にreverseをかける解法 int main() { string s; cin >> s; int n; cin >> n; vector<int>a(n); vector<int>b(n); rep(i,n) cin>>a.at(i)>>b.at(i); rep(i,n)a.at(i)--; rep(i,n)b.at(i)--; string t; rep(i,n){ t = s; for(int k=0;k<=b.at(i)-a.at(i);k++){ t.at(a.at(i)+k) = s.at(b.at(i)-k); } s = t; } cout << s << endl; } *///ABC018-B // cout << char(i+48) << // endl;//なぜかaは47と得る時がある。+48で出力もaにできる。 cout << char(97) << // endl;//アスキーコードでaを出力 // sort(b.begin(), b.end());//bという配列を小さい方からソート // reverse(b.begin(), b.end());//bという配列をリターン /*01 02 03 12 13 23 と6回見ていくパターン for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ } } */ // vector<vector<int>> a(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言 // 10のi乗pow(10, i);//ただしdouble型のため注意 /*string s; stringでの文字列を数字型に変える方法 cin >> s; rep(i,s.size()-2) { int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0'; */ #include <bits/stdc++.h> #include <iomanip> //これをincludeしておかないといけない using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define PI 3.14159265359 ll gcd(ll a, ll b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } ll lcm(ll a, ll b) { // return a * b / gcd(a, b); return a / gcd(a, b) * b; } int kan_hyaku(int n) { int kurai = 0; for (int i = 0; i < 3; i++) { kurai = n % 10; n /= 10; } return kurai; } int kan_ju(int n) { int kurai = 0; for (int i = 0; i < 2; i++) { kurai = n % 10; n /= 10; } return kurai; } int kan_ichi(int n) { int kurai = 0; for (int i = 0; i < 1; i++) { kurai = n % 10; n /= 10; } return kurai; } int keta(int n) { int wa = 1; while (n > 0) { wa *= 10; n--; } return wa; } double kan_half(int n) { double wa = 1; while (n > 0) { // cout << "TEST"<<endl; wa *= 0.5; // cout << wa << endl; n--; } return wa; } ll facctorialMethod(ll k) { ll sum = 1; for (ll i = 1; i <= k; ++i) { sum = sum % 1000000007 * i % 1000000007; } return sum; } /* int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a.at(i); */ bool red[100010] = {}; int main() { int n, k; string s; cin >> n >> s >> k; char moji = s.at(k - 1); rep(i, n) { if (s.at(i) != moji) { s.at(i) = '*'; } } cout << s << endl; }
replace
303
304
303
304
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; string s; cin >> n >> s >> k; for (int i = 0; i < n; i++) { if (s.at(i) != s.at(k)) { s.at(i) = '*'; } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; string s; cin >> n >> s >> k; for (int i = 0; i < n; i++) { if (s.at(i) != s.at(k - 1)) { s.at(i) = '*'; } } cout << s << endl; }
replace
10
11
10
11
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int n, k; string s; cin >> n >> s >> k; for (int i = 0; i < n; i++) { if (s.at(i) != s.at(k)) { s.at(i) = '*'; } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int n, k; string s; cin >> n >> s >> k; for (int i = 0; i < n; i++) { if (s.at(i) != s.at(k - 1)) { s.at(i) = '*'; } } cout << s << endl; }
replace
8
9
8
9
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; int K; cin >> K; for (int i = 0; i < N; i++) { if (S.at(i) != S.at(K)) { S.at(i) = '*'; } } cout << S << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; int K; cin >> K; for (int i = 0; i < N; i++) { if (S.at(i) != S.at(K - 1)) { S.at(i) = '*'; } } cout << S << endl; }
replace
11
12
11
12
0
p03068
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int a, c; string b; cin >> a >> b >> c; for (int i = 0; i < a; i++) { if (b.at(i) != b.at(c)) b.at(i) = '*'; } cout << b << endl; }
#include <iostream> #include <string> using namespace std; int main() { int a, c; string b; cin >> a >> b >> c; for (int i = 0; i < a; i++) { if (b.at(i) != b.at(c - 1)) b.at(i) = '*'; } cout << b << endl; }
replace
8
9
8
9
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> #include <math.h> using namespace std; int main() { int N, K; string S; cin >> N >> S >> K; for (int i = 0; i < N; i++) { if (S.at(i) != S.at(K)) { S.at(i) = '*'; } } cout << S << endl; }
#include <bits/stdc++.h> #include <math.h> using namespace std; int main() { int N, K; string S; cin >> N >> S >> K; for (int i = 0; i < N; i++) { if (S.at(i) != S.at(K - 1)) { S.at(i) = '*'; } } cout << S << endl; }
replace
9
10
9
10
0
p03068
Python
Runtime Error
n = int(input()) s = str(input()) k = int(input()) char = s[k] result = "" for x in s: if x == char: result += char else: result += "*" print(result)
n = int(input()) s = str(input()) k = int(input()) char = s[k - 1] result = "" for x in s: if x == char: result += char else: result += "*" print(result)
replace
4
5
4
5
0
p03068
Python
Runtime Error
from functools import reduce N = int(input()) S = input() K = int(input()) print(reduce(lambda x, y: x + (y if y == S[K] else "*"), S, ""))
from functools import reduce N = int(input()) S = input() K = int(input()) - 1 print(reduce(lambda x, y: x + (y if y == S[K] else "*"), S, ""))
replace
4
5
4
5
0
p03068
Python
Runtime Error
from re import sub n = int(input()) s = input() k = int(input()) print(sub(f"[^{s[k-1]}]", "*", s))
from re import sub n = int(input()) s = input() k = int(input()) print(sub("[^{}]".format(s[k - 1]), "*", s))
replace
6
7
6
7
0
p03068
Python
Runtime Error
N = int(input()) S = list(input()) K = int(input()) target = S[K] ans = "" for s in S: ans += s if s == target else "*" print(ans)
N = int(input()) S = list(input()) K = int(input()) target = S[K - 1] ans = "" for s in S: ans += s if s == target else "*" print(ans)
replace
4
5
4
5
0
p03068
Python
Runtime Error
N = int(input()) S = input() K = int(input()) a = S[K + 1] for i in range(len(S)): if S[i] != a: print("*", end="") else: print(S[i], end="") print()
N = int(input()) S = input() K = int(input()) a = S[K - 1] for i in range(len(S)): if S[i] != a: print("*", end="") else: print(S[i], end="") print()
replace
4
5
4
5
0
p03068
Python
Runtime Error
N = int(input()) S = input() K = int(input()) flag = S[K] ans = [] for x in S: if x == flag: ans.append(x) else: ans.append("*") print("".join(ans))
N = int(input()) S = input() K = int(input()) flag = S[K - 1] ans = [] for x in S: if x == flag: ans.append(x) else: ans.append("*") print("".join(ans))
replace
3
4
3
4
0
p03068
Python
Runtime Error
n = int(input()) s = input() k = int(input()) result = [] for x in s: if x != s[k]: result.append("*") else: result.append(x) print("".join(result))
n = int(input()) s = input() k = int(input()) result = [] for x in s: if x != s[k - 1]: result.append("*") else: result.append(x) print("".join(result))
replace
6
7
6
7
0
p03068
Python
Runtime Error
input() S = input() K = int(input()) c = S[K] print("".join([v if v == c else "*" for v in S]))
input() S = input() K = int(input()) c = S[K - 1] print("".join([v if v == c else "*" for v in S]))
replace
4
5
4
5
0
p03068
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; string s; cin >> n >> s >> k; char c = s.at(k); for (int i = 0; i < n; i++) { if (s.at(i) != c) { s.at(i) = '*'; } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; string s; cin >> n >> s >> k; char c = s.at(k - 1); for (int i = 0; i < n; i++) { if (s.at(i) != c) { s.at(i) = '*'; } } cout << s << endl; }
replace
7
8
7
8
0
p03068
C++
Runtime Error
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define pll pair<ll, ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define lb(c, x) distance(c.begin(), lower_bound(all(c), x)) #define ub(c, x) distance(c.begin(), upper_bound(all(c), x)) using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e18; const ll mod = 1e9 + 7; const double eps = 0.000000001; int main() { ll n; cin >> n; string s; cin >> n; ll k; cin >> k; k--; char c = s[k]; rep(i, n) { if (s[i] != c) s[i] = '*'; } cout << s << endl; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define pll pair<ll, ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define fi first #define se second #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define lb(c, x) distance(c.begin(), lower_bound(all(c), x)) #define ub(c, x) distance(c.begin(), upper_bound(all(c), x)) using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e18; const ll mod = 1e9 + 7; const double eps = 0.000000001; int main() { ll n; cin >> n; string s; cin >> s; ll k; cin >> k; k--; char c = s[k]; rep(i, n) { if (s[i] != c) s[i] = '*'; } cout << s << endl; return 0; }
replace
39
40
39
40
-11
p03068
Python
Runtime Error
n = int(input()) s = input() k = int(input()) s = list(map(lambda x: "*" if x != s[k] else x, s)) print(*s, sep="")
n = int(input()) s = input() k = int(input()) - 1 s = list(map(lambda x: "*" if x != s[k] else x, s)) print(*s, sep="")
replace
2
3
2
3
0
p03069
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #define in(a) a = read() #define REP(i, k, n) for (int i = k; i <= n; i++) using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return x * f; } int main() { int n; char ch[100010]; int a[100010], b[100010]; in(n); int flag = 0; scanf("%s", ch + 1); int ans = 999999; REP(i, 1, n) { b[i] = b[i - 1]; if (ch[i] == '#') b[i]++; } for (int i = n; i >= 1; i--) { a[i] = a[i + 1]; if (ch[i] == '.') a[i]++; } for (int i = 0; i <= n; i++) { ans = min(ans, b[i] + a[i + 1]); } cout << ans; return 0; }
#include <algorithm> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #define in(a) a = read() #define REP(i, k, n) for (int i = k; i <= n; i++) using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return x * f; } int main() { int n; char ch[1000010]; int a[1000010], b[1000010]; in(n); int flag = 0; scanf("%s", ch + 1); int ans = 999999; REP(i, 1, n) { b[i] = b[i - 1]; if (ch[i] == '#') b[i]++; } for (int i = n; i >= 1; i--) { a[i] = a[i + 1]; if (ch[i] == '.') a[i]++; } for (int i = 0; i <= n; i++) { ans = min(ans, b[i] + a[i + 1]); } cout << ans; return 0; }
replace
21
23
21
23
0
p03069
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; const int INF = 1001001001; int sum[100001]; int main() { int n; string s; cin >> n >> s; for (int i = 0; i < n; ++i) { sum[i + 1] = sum[i]; if (s[i] == '#') { ++sum[i + 1]; } } int ans = INF; for (int i = 0; i <= n; ++i) { int cnt = 0; cnt += sum[i]; cnt += n - i - (sum[n] - sum[i]); ans = min(ans, cnt); } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; const int INF = 1001001001; int sum[200005]; int main() { int n; string s; cin >> n >> s; for (int i = 0; i < n; ++i) { sum[i + 1] = sum[i]; if (s[i] == '#') { ++sum[i + 1]; } } int ans = INF; for (int i = 0; i <= n; ++i) { int cnt = 0; cnt += sum[i]; cnt += n - i - (sum[n] - sum[i]); ans = min(ans, cnt); } cout << ans << endl; }
replace
8
9
8
9
0
p03069
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using intpair = pair<int, int>; using intpv = vector<intpair>; using llpair = pair<ll, ll>; using llpv = vector<llpair>; using intq = queue<int>; using llq = queue<ll>; using intvec = vector<int>; using llvec = vector<ll>; using llmat = vector<vector<ll>>; #define PI 3.141592653589793 #define INTINF 1 << 30 #define LLINF 1LL << 60 #define MPRIME 1000000007 #define pushb push_back #define all(name) name.begin(), name.end() #define llmattp(name, a, b, num) name(a, vector<ll>(b, num)) #define ABS(x) ((x) > 0 ? (x) : -(x)) #define gsort(vbeg, vend) sort(vbeg, vend, greater<>()) template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll gcd(ll a, ll b) { // 最大公約数 if (a == 0 || b == 0) return 0; if (a < b) swap(a, b); ll tmp = a % b; while (tmp != 0) { a = b; b = tmp; tmp = a % b; } return b; } ll modpow(ll a, ll ex, ll p) { // 繰り返し二乗法 if (ex == 1) return a % p; if (ex % 2) return a % p * modpow(a, ex - 1, p) % p; ll tmp = modpow(a, ex / 2, p) % p; return tmp * tmp % p; } ll factorial(ll x) { // 階乗 ll f = 1; for (ll i = 2; i <= x; i++) { f *= i; } return f; } ll nPr(ll n, ll r) { ll result = 1; for (ll i = r + 1; i <= n; i++) result *= i; return result; } ll nCr(ll n, ll r) { if (n == r) { return 1; } if (r > n) { return 0; } if (r > n / 2) { r = n - r; } if (n == 0) { return 0; } if (r == 0) { return 1; } if (r == 1) { return n; } double result = 1; for (double i = 1; i <= r; i++) { result *= (n - i + 1) / i; } return (ll)result; } ll LowerBinarySearch(llvec array, ll key, ll max, ll min) { // にぶたんlower if (max > min) { return -1LL; } else { ll mid = max + (min - max) / 2; if (array[mid] > key) { return LowerBinarySearch(array, key, max, mid - 1); } if (array[mid] < key) { return LowerBinarySearch(array, key, mid + 1, min); } else { return mid; } } } ll GreaterBinarySearch(llvec array, ll key, ll max, ll min) { // にぶたんgreater if (max > min) { return -1LL; } else { ll mid = max + (min - max) / 2; if (array[mid] < key) { return GreaterBinarySearch(array, key, max, mid - 1); } if (array[mid] > key) { return GreaterBinarySearch(array, key, mid + 1, min); } else { return mid; } } } int DigitNum(ll n) { // 桁数 int digit = 0; ll wari = 1LL; while (n / wari) { digit++; wari *= 10; } return digit; } bool IsPrime(ll num) { // 素数判定 if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; // 偶数はあらかじめ除く double sqrtNum = sqrt(num); for (ll i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { // 素数ではない return false; } } // 素数である return true; } vector<ll> Divisor(ll x) { // 約数列挙 vector<ll> result; ll i = 1LL; for (; i * i < x; i++) { if (x % i) continue; result.push_back(i); result.push_back(x / i); } if (i * i == x && x % i == 0) result.push_back(i); sort(result.begin(), result.end()); return result; } vector<llpair> PrimeFact(ll x) { // 素因数分解 {素因数,指数} vector<llpair> result; ll ex = 0LL; if (x % 2 == 0) { while (x % 2 == 0) { x /= 2; ex++; } result.push_back({2, ex}); } for (ll i = 3LL; i * i <= x; i += 2) { if (x % i) continue; ex = 0LL; while (x % i == 0) { x /= i; ex++; } result.push_back({i, ex}); } if (x != 1) result.push_back({x, 1}); return result; } bool Palind(string s) { // 回文判定 return s == string(s.rbegin(), s.rend()); } struct Union_Find { vector<int> parent; vector<int> num; Union_Find(int N) : parent(N), num(N, 1) { for (int i = 0; i < N; i++) { parent[i] = i; } } int root(int x) { if (parent[x] == x) return x; return parent[x] = root(parent[x]); } void merge(int x, int y) { int xrt = root(x); int yrt = root(y); if (xrt == yrt) return; parent[xrt] = yrt; num[yrt] += num[xrt]; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return num[root(x)]; } }; int main() { int N; cin >> N; string S; cin >> S; int ep = 0; while (S[ep] == '.' && ep < N) ep++; intpv pv; int st = 0; int tmp; bool b = true; for (int i = ep; i < N; i++) { if (S[i] == '#') { if (b) st++; else { pv.pushb({tmp, st}); st = 1; b = true; } } else { if (b) { tmp = st; st = 1; b = false; } else st++; } } if (!b) { pv.pushb({tmp, st}); } if (pv.empty()) { cout << 0 << endl; return 0; } int result = INTINF; for (int i = 0; i <= pv.size(); i++) { int tmp = 0; for (int j = 0; j < i; j++) tmp += pv[j].first; for (int j = i; j < pv.size(); j++) tmp += pv[j].second; chmin(result, tmp); } cout << result << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using intpair = pair<int, int>; using intpv = vector<intpair>; using llpair = pair<ll, ll>; using llpv = vector<llpair>; using intq = queue<int>; using llq = queue<ll>; using intvec = vector<int>; using llvec = vector<ll>; using llmat = vector<vector<ll>>; #define PI 3.141592653589793 #define INTINF 1 << 30 #define LLINF 1LL << 60 #define MPRIME 1000000007 #define pushb push_back #define all(name) name.begin(), name.end() #define llmattp(name, a, b, num) name(a, vector<ll>(b, num)) #define ABS(x) ((x) > 0 ? (x) : -(x)) #define gsort(vbeg, vend) sort(vbeg, vend, greater<>()) template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll gcd(ll a, ll b) { // 最大公約数 if (a == 0 || b == 0) return 0; if (a < b) swap(a, b); ll tmp = a % b; while (tmp != 0) { a = b; b = tmp; tmp = a % b; } return b; } ll modpow(ll a, ll ex, ll p) { // 繰り返し二乗法 if (ex == 1) return a % p; if (ex % 2) return a % p * modpow(a, ex - 1, p) % p; ll tmp = modpow(a, ex / 2, p) % p; return tmp * tmp % p; } ll factorial(ll x) { // 階乗 ll f = 1; for (ll i = 2; i <= x; i++) { f *= i; } return f; } ll nPr(ll n, ll r) { ll result = 1; for (ll i = r + 1; i <= n; i++) result *= i; return result; } ll nCr(ll n, ll r) { if (n == r) { return 1; } if (r > n) { return 0; } if (r > n / 2) { r = n - r; } if (n == 0) { return 0; } if (r == 0) { return 1; } if (r == 1) { return n; } double result = 1; for (double i = 1; i <= r; i++) { result *= (n - i + 1) / i; } return (ll)result; } ll LowerBinarySearch(llvec array, ll key, ll max, ll min) { // にぶたんlower if (max > min) { return -1LL; } else { ll mid = max + (min - max) / 2; if (array[mid] > key) { return LowerBinarySearch(array, key, max, mid - 1); } if (array[mid] < key) { return LowerBinarySearch(array, key, mid + 1, min); } else { return mid; } } } ll GreaterBinarySearch(llvec array, ll key, ll max, ll min) { // にぶたんgreater if (max > min) { return -1LL; } else { ll mid = max + (min - max) / 2; if (array[mid] < key) { return GreaterBinarySearch(array, key, max, mid - 1); } if (array[mid] > key) { return GreaterBinarySearch(array, key, mid + 1, min); } else { return mid; } } } int DigitNum(ll n) { // 桁数 int digit = 0; ll wari = 1LL; while (n / wari) { digit++; wari *= 10; } return digit; } bool IsPrime(ll num) { // 素数判定 if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; // 偶数はあらかじめ除く double sqrtNum = sqrt(num); for (ll i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { // 素数ではない return false; } } // 素数である return true; } vector<ll> Divisor(ll x) { // 約数列挙 vector<ll> result; ll i = 1LL; for (; i * i < x; i++) { if (x % i) continue; result.push_back(i); result.push_back(x / i); } if (i * i == x && x % i == 0) result.push_back(i); sort(result.begin(), result.end()); return result; } vector<llpair> PrimeFact(ll x) { // 素因数分解 {素因数,指数} vector<llpair> result; ll ex = 0LL; if (x % 2 == 0) { while (x % 2 == 0) { x /= 2; ex++; } result.push_back({2, ex}); } for (ll i = 3LL; i * i <= x; i += 2) { if (x % i) continue; ex = 0LL; while (x % i == 0) { x /= i; ex++; } result.push_back({i, ex}); } if (x != 1) result.push_back({x, 1}); return result; } bool Palind(string s) { // 回文判定 return s == string(s.rbegin(), s.rend()); } struct Union_Find { vector<int> parent; vector<int> num; Union_Find(int N) : parent(N), num(N, 1) { for (int i = 0; i < N; i++) { parent[i] = i; } } int root(int x) { if (parent[x] == x) return x; return parent[x] = root(parent[x]); } void merge(int x, int y) { int xrt = root(x); int yrt = root(y); if (xrt == yrt) return; parent[xrt] = yrt; num[yrt] += num[xrt]; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return num[root(x)]; } }; int main() { int N; cin >> N; string S; cin >> S; int ep = 0; while (S[ep] == '.' && ep < N) ep++; intpv pv; int st = 0; int tmp; bool b = true; for (int i = ep; i < N; i++) { if (S[i] == '#') { if (b) st++; else { pv.pushb({tmp, st}); st = 1; b = true; } } else { if (b) { tmp = st; st = 1; b = false; } else st++; } } if (!b) { pv.pushb({tmp, st}); } if (pv.empty()) { cout << 0 << endl; return 0; } int result = 0; for (int i = 0; i < pv.size(); i++) result += pv[i].second; int temp = result; for (int i = 0; i < pv.size(); i++) { temp += pv[i].first - pv[i].second; chmin(result, temp); } cout << result << endl; }
replace
288
296
288
296
TLE
p03069
C++
Time Limit Exceeded
#include <iostream> #include <algorithm> #include <string> using namespace std; int main() { int n; string s; cin >> n >> s; // 境界を探索 int min = n; for (int i = 0; i <= n; i++) { int c_b = 0, c_w = 0; for (int j = 0; j < n; i++) { string t = s.substr(j, 1); if (j < i && s == "#") c_b++; if (j >= i && s == ".") c_w++; } if (min > c_b + c_w) min = c_b + c_w; } cout << min << endl; }
#include <iostream> #include <algorithm> #include <string> using namespace std; int main() { int n; string s; cin >> n >> s; // 境界を探索 int c_b = 0, c_w = 0; for (int i = 0; i < n; i++) { string t = s.substr(i, 1); if (t == ".") c_w++; } int min = c_w; for (int i = 0; i < n; i++) { string t = s.substr(i, 1); if (t == "#") c_b++; if (t == ".") c_w--; if (min > c_b + c_w) min = c_b + c_w; } cout << min << endl; }
replace
12
22
12
27
TLE
p03069
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int MAX = (int)(1e5 + 5); const ll INF = (ll)(1e10 + 5); const int MAX_N = (int)(1e5 + 5); int n; string s; int white[MAX_N]; int black[MAX_N]; int ans; int main(void) { // Here your code ! scanf("%d", &n); cin >> s; for (int i = 0; i < n; ++i) { if (s[i] == '#') { black[i] = 1; } else { white[i] = 1; } } for (int i = 1; i < n; ++i) { black[i] = black[i] + black[i - 1]; } for (int i = 1; i < n; ++i) { white[i] = white[i] + white[i - 1]; } int all_black = black[n - 1]; int all_white = white[n - 1]; ans = min(n - all_black, n - all_white); for (int i = 0; i < n; ++i) { int left_b = black[i]; int left_w = white[i]; int right_b = all_black - left_b; int right_w = all_white - left_w; // case: w, w ans = min(ans, left_b + right_b); // case: w, b ans = min(ans, left_b + right_w); // case: b, b ans = min(ans, left_w + right_w); } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; const int MAX = (int)(1e5 + 5); const ll INF = (ll)(1e10 + 5); const int MAX_N = (int)(2e5 + 5); int n; string s; int white[MAX_N]; int black[MAX_N]; int ans; int main(void) { // Here your code ! scanf("%d", &n); cin >> s; for (int i = 0; i < n; ++i) { if (s[i] == '#') { black[i] = 1; } else { white[i] = 1; } } for (int i = 1; i < n; ++i) { black[i] = black[i] + black[i - 1]; } for (int i = 1; i < n; ++i) { white[i] = white[i] + white[i - 1]; } int all_black = black[n - 1]; int all_white = white[n - 1]; ans = min(n - all_black, n - all_white); for (int i = 0; i < n; ++i) { int left_b = black[i]; int left_w = white[i]; int right_b = all_black - left_b; int right_w = all_white - left_w; // case: w, w ans = min(ans, left_b + right_b); // case: w, b ans = min(ans, left_b + right_w); // case: b, b ans = min(ans, left_w + right_w); } printf("%d\n", ans); return 0; }
replace
8
9
8
9
0
p03069
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; vector<int> vecB(N + 1), vecW(N + 1), ans(N + 1); for (int i = 0; i <= N; i++) { if (S[i] == '#') { vecB[i + 1] = vecB[i] + 1; } else { vecB[i + 1] = vecB[i]; } if (S[N - 1 - i] == '.') { vecW[N - 1 - i] = vecW[N - i] + 1; } else { vecW[N - 1 - i] = vecW[N - i]; } } for (int i = 0; i <= N; i++) { ans[i] = vecB[i] + vecW[i]; } sort(ans.begin(), ans.end()); cout << ans[0] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; vector<int> vecB(N + 1), vecW(N + 1), ans(N + 1); for (int i = 0; i < N; i++) { if (S[i] == '#') { vecB[i + 1] = vecB[i] + 1; } else { vecB[i + 1] = vecB[i]; } if (S[N - 1 - i] == '.') { vecW[N - 1 - i] = vecW[N - i] + 1; } else { vecW[N - 1 - i] = vecW[N - i]; } } for (int i = 0; i <= N; i++) { ans[i] = vecB[i] + vecW[i]; } sort(ans.begin(), ans.end()); cout << ans[0] << endl; return 0; }
replace
8
9
8
9
-6
double free or corruption (out)
p03069
C++
Runtime Error
#include <algorithm> #include <complex> #include <cstring> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <unordered_map> #include <vector> #define rep(i, a) for (int i = 0; i < (a); i++) using namespace std; int main() { int n; string s; cin >> n >> s; int b[30000], w[30000]; int i; b[0] = 0; w[0] = 0; for (i = 1; i <= n; i++) { if (s[i - 1] == '.') { w[i] = w[i - 1] + 1; b[i] = b[i - 1]; } else { w[i] = w[i - 1]; b[i] = b[i - 1] + 1; } } int ans = 1000000; for (i = 0; i <= n; i++) { ans = min(ans, b[i] + (w[n] - w[i])); } cout << ans << endl; }
#include <algorithm> #include <complex> #include <cstring> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <unordered_map> #include <vector> #define rep(i, a) for (int i = 0; i < (a); i++) using namespace std; int main() { int n; string s; cin >> n >> s; int b[300000], w[300000]; int i; b[0] = 0; w[0] = 0; for (i = 1; i <= n; i++) { if (s[i - 1] == '.') { w[i] = w[i - 1] + 1; b[i] = b[i - 1]; } else { w[i] = w[i - 1]; b[i] = b[i - 1] + 1; } } int ans = 1000000; for (i = 0; i <= n; i++) { ans = min(ans, b[i] + (w[n] - w[i])); } cout << ans << endl; }
replace
18
19
18
19
0
p03069
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int b[100010] = {}; int w[100010] = {}; for (int i = 0; i < n; i++) { b[i + 1] += b[i]; w[i + 1] += w[i]; if (s[i] == '#') { b[i + 1]++; } else { w[i + 1]++; } } int ans = INT_MAX; for (int i = 0; i <= n; i++) { ans = min(ans, b[i] + w[n] - w[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; int b[200010] = {}; int w[200010] = {}; for (int i = 0; i < n; i++) { b[i + 1] += b[i]; w[i + 1] += w[i]; if (s[i] == '#') { b[i + 1]++; } else { w[i + 1]++; } } int ans = INT_MAX; for (int i = 0; i <= n; i++) { ans = min(ans, b[i] + w[n] - w[i]); } cout << ans << endl; return 0; }
replace
7
9
7
9
0
p03069
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N_TIMES(i, n) for (uint64_t i = 0; i < n; ++i) #define N_TIMES_REV(i, n) for (int64_t i = n - 1; i >= 0; --i) int main(int argc, char **argv) { uint64_t N; cin >> N; string S; cin >> S; vector<uint64_t> black(N + 1, 0), white(N + 1, 0); N_TIMES(n, N + 1) { black[n + 1] = ((S[n] == '#') ? 1 : 0) + black[n]; white[n + 1] = ((S[n] == '.') ? 1 : 0) + white[n]; } uint64_t count = -1; N_TIMES(n, N + 1) { uint64_t pw = n, pb = N - n; uint64_t qw = white[n] - white[0]; uint64_t qb = black[N] - black[n]; count = min(count, (pw - qw) + (pb - qb)); } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define N_TIMES(i, n) for (uint64_t i = 0; i < n; ++i) #define N_TIMES_REV(i, n) for (int64_t i = n - 1; i >= 0; --i) int main(int argc, char **argv) { uint64_t N; cin >> N; string S; cin >> S; vector<uint64_t> black(N + 1, 0), white(N + 1, 0); N_TIMES(n, N) { black[n + 1] = ((S[n] == '#') ? 1 : 0) + black[n]; white[n + 1] = ((S[n] == '.') ? 1 : 0) + white[n]; } uint64_t count = -1; N_TIMES(n, N + 1) { uint64_t pw = n, pb = N - n; uint64_t qw = white[n] - white[0]; uint64_t qb = black[N] - black[n]; count = min(count, (pw - qw) + (pb - qb)); } cout << count << endl; return 0; }
replace
15
16
15
16
0
p03069
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; S = S + '#'; vector<int> a(S.size(), 0); int i, j, J; int b; char c = S.at(0); for (i = j = 0; i < S.size(); i++) { if (S.at(i) != c) { c = S.at(i); j++; } if (c == '.') a.at(j)++; else a.at(j)--; } J = j + 1; // for (i=0; i<J; i++) cout <<a.at(i) <<endl;//// b = 0; for (i = 0; i < J; i++) { if (a.at(i) > 0) b += a.at(i); } // cout << "b=" << b << endl;//////////////// if (a.at(0) < 0) { i = 0; } else { i = 1; b -= a.at(0); } // cout << "b=" << b << endl;//////////////// int B = b; for (; i < J; i += 2) { // cout << "Before " << a.at(i) << ':' << a.at(i+1) << ':' << b << endl; b = b - a.at(i) - a.at(i + 1); // cout << "After " << a.at(i) << ':' << a.at(i+1) << ':' << b << endl; B = min(B, b); } cout << B << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; S = S + '#'; vector<int> a(S.size(), 0); int i, j, J; int b; char c = S.at(0); for (i = j = 0; i < S.size(); i++) { if (S.at(i) != c) { c = S.at(i); j++; } if (c == '.') a.at(j)++; else a.at(j)--; } J = j + 1; // for (i=0; i<J; i++) cout <<a.at(i) <<endl;//// b = 0; for (i = 0; i < J; i++) { if (a.at(i) > 0) b += a.at(i); } // cout << "b=" << b << endl;//////////////// if (a.at(0) < 0) { i = 0; } else { i = 1; b -= a.at(0); } // cout << "b=" << b << endl;//////////////// int B = b; for (; i < J - 1; i += 2) { // cout << "Before " << a.at(i) << ':' << a.at(i+1) << ':' << b << endl; b = b - a.at(i) - a.at(i + 1); // cout << "After " << a.at(i) << ':' << a.at(i+1) << ':' << b << endl; B = min(B, b); } cout << B << endl; }
replace
38
39
38
39
0
p03069
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N; scanf("%d", &N); string S; cin >> S; int counta = 0; int countb = 0; int countc = 0; int max = N; for (int i = 0; i < N; ++i) { if (S[i] == '#') ++counta; } for (int i = 0; i < N; ++i) { if (S[i] == '.') ++countb; } if (counta < max) max = counta; if (countb < max) max = countb; for (int ii = 0; ii < N; ++ii) { countc = 0; for (int iii = 0; iii < ii; ++iii) { if (S[iii] == '#') ++countc; if (countc >= max) break; } for (int iii = ii; iii < N; ++iii) { if (S[iii] == '.') ++countc; if (countc >= max) break; } if (countc < max) max = countc; } cout << max << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; scanf("%d", &N); string S; cin >> S; int counta = 0; int countb = 0; int countc = 0; int max = N; for (int i = 0; i < N; ++i) { if (S[i] == '#') ++counta; } for (int i = 0; i < N; ++i) { if (S[i] == '.') ++countb; } if (counta < max) max = counta; if (countb < max) max = countb; for (int i = 0; i < N; ++i) { if (S[i] == '#') ++countb; else --countb; if (countb < max) max = countb; } cout << max << endl; }
replace
28
44
28
35
TLE
p03069
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; vector<int> vtL(n + 1, 0); vector<int> vtR(n + 1, 0); for (int i = 0; i < n; ++i) { vtL[i + 1] = vtL[i]; if (s[i] == '#') vtL[i + 1]++; vtR[n - 2 - i] = vtR[n - 1 - i]; if (s[n - 1 - i] == '.') vtR[n - 2 - i]++; } int ans = INT_MAX; for (int i = 0; i < n; ++i) { ans = min(ans, vtL[i] + vtR[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; vector<int> vtL(n + 1, 0); vector<int> vtR(n + 1, 0); for (int i = 0; i < n; ++i) { vtL[i + 1] = vtL[i]; if (s[i] == '#') vtL[i + 1]++; if (n - 2 - i < 0) continue; vtR[n - 2 - i] = vtR[n - 1 - i]; if (s[n - 1 - i] == '.') vtR[n - 2 - i]++; } int ans = INT_MAX; for (int i = 0; i < n; ++i) { ans = min(ans, vtL[i] + vtR[i]); } cout << ans << endl; return 0; }
insert
15
15
15
18
-6
double free or corruption (out)
p03069
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; int black[100002] = {}; int n_black = 0; string S; cin >> N >> S; for (int i = 1; i <= N; i++) { black[i] = black[i - 1]; if (S[i - 1] == '#') black[i]++; } n_black = black[N]; int ans = 2e5 + 1; for (int i = 0; i <= N; i++) { ans = min(ans, black[i] + (N - i) - (n_black - black[i])); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; int black[200002] = {}; int n_black = 0; string S; cin >> N >> S; for (int i = 1; i <= N; i++) { black[i] = black[i - 1]; if (S[i - 1] == '#') black[i]++; } n_black = black[N]; int ans = 2e5 + 1; for (int i = 0; i <= N; i++) { ans = min(ans, black[i] + (N - i) - (n_black - black[i])); } cout << ans << endl; return 0; }
replace
5
6
5
6
0
p03069
C++
Runtime Error
// #include "bits/stdc++.h" #define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair // typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector<vector<int>> mat; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int sum[100010][2]; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; string S; cin >> N >> S; rep(i, 0, N) { sum[i][S[i] == '#' ? 0 : 1]++; if (0 < i) { rep(j, 0, 2) { sum[i][j] += sum[i - 1][j]; } } } int ans = INF; rep(i, 0, N + 1) { if (i == 0) { chmin(ans, sum[N - 1][1]); } else if (i == N) { chmin(ans, sum[N - 1][0]); } else { chmin(ans, sum[N - 1][1] - sum[i - 1][1] + sum[i - 1][0]); } } cout << ans << endl; return 0; }
// #include "bits/stdc++.h" #define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair // typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector<vector<int>> mat; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int sum[200010][2]; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; string S; cin >> N >> S; rep(i, 0, N) { sum[i][S[i] == '#' ? 0 : 1]++; if (0 < i) { rep(j, 0, 2) { sum[i][j] += sum[i - 1][j]; } } } int ans = INF; rep(i, 0, N + 1) { if (i == 0) { chmin(ans, sum[N - 1][1]); } else if (i == N) { chmin(ans, sum[N - 1][0]); } else { chmin(ans, sum[N - 1][1] - sum[i - 1][1] + sum[i - 1][0]); } } cout << ans << endl; return 0; }
replace
62
63
62
63
0
p03069
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 212345 #define pb push_back #define mp make_pair #define ll long long #define mod 1000000007 #define all(cont) cont.begin(), cont.end() #define sortcmp(n, cmpfunc) sort(all(n), cmpfunc) #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0) ll powm(ll a, ll b); ll divm(ll a, ll b); ll multm(ll a, ll b); ll subm(ll a, ll b); ll addm(ll a, ll b); int main() { int n; int preb[N], sufw[N], ans; string s; fastio; #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif cin >> n >> s; if (n == 1) cout << '0' << endl; else { preb[0] = 0; for (int i = 1; i < n; i++) { preb[i] = preb[i - 1]; if (s[i - 1] == '#') preb[i]++; } sufw[n] = 0; for (int i = n - 1; i >= 1; i--) { sufw[i] = sufw[i + 1]; if (s[i] == '.') sufw[i]++; } ans = preb[0] + sufw[1]; for (int i = 1; i < n; i++) ans = min(ans, preb[i] + sufw[i + 1]); cout << ans << endl; } return 0; } // template function ll gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll powm(ll a, ll b) { ll x = 1, y = a; while (b > 0) { if (b % 2) x = (x * y) % mod; y = (y * y) % mod; b /= 2; } return x % mod; } ll multm(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; } ll divm(ll a, ll b) { return (a * powm(b, mod - 2)); } ll subm(ll a, ll b) { a -= b; if (a < 0) a += mod; return a; } ll addm(ll a, ll b) { a += b; if (a >= mod) a -= mod; return a; }
#include <bits/stdc++.h> using namespace std; #define N 212345 #define pb push_back #define mp make_pair #define ll long long #define mod 1000000007 #define all(cont) cont.begin(), cont.end() #define sortcmp(n, cmpfunc) sort(all(n), cmpfunc) #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0) ll powm(ll a, ll b); ll divm(ll a, ll b); ll multm(ll a, ll b); ll subm(ll a, ll b); ll addm(ll a, ll b); int main() { int n; int preb[N], sufw[N], ans; string s; fastio; // #ifndef ONLINE_JUDGE // freopen("input.in", "r", stdin); // freopen("output.out", "w", stdout); // #endif cin >> n >> s; if (n == 1) cout << '0' << endl; else { preb[0] = 0; for (int i = 1; i < n; i++) { preb[i] = preb[i - 1]; if (s[i - 1] == '#') preb[i]++; } sufw[n] = 0; for (int i = n - 1; i >= 1; i--) { sufw[i] = sufw[i + 1]; if (s[i] == '.') sufw[i]++; } ans = preb[0] + sufw[1]; for (int i = 1; i < n; i++) ans = min(ans, preb[i] + sufw[i + 1]); cout << ans << endl; } return 0; } // template function ll gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll powm(ll a, ll b) { ll x = 1, y = a; while (b > 0) { if (b % 2) x = (x * y) % mod; y = (y * y) % mod; b /= 2; } return x % mod; } ll multm(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; } ll divm(ll a, ll b) { return (a * powm(b, mod - 2)); } ll subm(ll a, ll b) { a -= b; if (a < 0) a += mod; return a; } ll addm(ll a, ll b) { a += b; if (a >= mod) a -= mod; return a; }
replace
25
29
25
29
0
p03069
C++
Runtime Error
#define LOCAL #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = (n - 1); i >= 0; --i) #define rep2(i, s, n) for (int i = s; i < (n); ++i) #define ALL(v) (v).begin(), (v).end() #define memr(dp, val) memset(dp, val, sizeof(dp)) using namespace std; typedef long long ll; static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7 static const ll LLINF = (LLONG_MAX >> 1); static const int MAX = 100001; static const ll MOD = 1000000007; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline bool int_ceil(T a, T b) { T res = a / b; if (a % b != 0) res++; return res; } template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; string to_string(string s) { return '"' + s + '"'; } string to_string(bool b) { return b ? "true" : "false"; } template <size_t N> string to_string(bitset<N> bs) { string res; for (size_t i = 0; i < N; ++i) res += '0' + bs[i]; return res; } string to_string(vector<bool> v) { string res = "{"; for (bool e : v) res += to_string(e) + ", "; return res += "}"; } template <class T, class U> string to_string(pair<T, U> p); template <class C> string to_string(C c) { string res = "{"; for (auto e : c) res += to_string(e) + ", "; return res += "}"; } template <class T, class U> string to_string(pair<T, U> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } void debug() { cerr << '\n'; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << '\t' << to_string(head), debug(tail...); } #ifdef LOCAL #define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__) #else #define print(...) #endif vector<pair<char, int>> Ranlength(string str) { vector<pair<char, int>> ranlength; pair<char, int> f; char lastChar; int cnt = 0; rep(i, str.size()) { if (lastChar != str[i] || i == str.size()) { if (i != 0) { f = make_pair(lastChar, cnt); ranlength.push_back(f); } lastChar = str[i]; cnt = 1; } else { cnt++; } } f = make_pair(lastChar, cnt); ranlength.push_back(f); // rep(i, ranlength.size()){ // for debug // cout << ranlength[i].first << ranlength[i].second << endl; // } return ranlength; } int main(int argc, const char *argv[]) { std::cout << std::fixed << std::setprecision(15); int n; cin >> n; string str; cin >> str; auto v = Ranlength(str); int k = 0; while (v[k].first != '#') { k++; if (str.size() < k) { cout << 0 << endl; return 0; } } ll sum = 0; ll ans = LLINF; rep2(i, k, v.size()) { if (v[i].first == '.') sum += v[i].second; } chmin(ans, sum); rep2(i, k, v.size()) { if (v[i].first == '#') sum += v[i].second; else sum -= v[i].second; chmin(ans, sum); } cout << ans << endl; return 0; }
#define LOCAL #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = (n - 1); i >= 0; --i) #define rep2(i, s, n) for (int i = s; i < (n); ++i) #define ALL(v) (v).begin(), (v).end() #define memr(dp, val) memset(dp, val, sizeof(dp)) using namespace std; typedef long long ll; static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7 static const ll LLINF = (LLONG_MAX >> 1); static const int MAX = 100001; static const ll MOD = 1000000007; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline bool int_ceil(T a, T b) { T res = a / b; if (a % b != 0) res++; return res; } template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; string to_string(string s) { return '"' + s + '"'; } string to_string(bool b) { return b ? "true" : "false"; } template <size_t N> string to_string(bitset<N> bs) { string res; for (size_t i = 0; i < N; ++i) res += '0' + bs[i]; return res; } string to_string(vector<bool> v) { string res = "{"; for (bool e : v) res += to_string(e) + ", "; return res += "}"; } template <class T, class U> string to_string(pair<T, U> p); template <class C> string to_string(C c) { string res = "{"; for (auto e : c) res += to_string(e) + ", "; return res += "}"; } template <class T, class U> string to_string(pair<T, U> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } void debug() { cerr << '\n'; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << '\t' << to_string(head), debug(tail...); } #ifdef LOCAL #define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__) #else #define print(...) #endif vector<pair<char, int>> Ranlength(string str) { vector<pair<char, int>> ranlength; pair<char, int> f; char lastChar; int cnt = 0; rep(i, str.size()) { if (lastChar != str[i] || i == str.size()) { if (i != 0) { f = make_pair(lastChar, cnt); ranlength.push_back(f); } lastChar = str[i]; cnt = 1; } else { cnt++; } } f = make_pair(lastChar, cnt); ranlength.push_back(f); // rep(i, ranlength.size()){ // for debug // cout << ranlength[i].first << ranlength[i].second << endl; // } return ranlength; } int main(int argc, const char *argv[]) { std::cout << std::fixed << std::setprecision(15); int n; cin >> n; string str; cin >> str; auto v = Ranlength(str); int k = 0; while (v[k].first != '#') { k++; if (v.size() < k) { cout << 0 << endl; return 0; } } ll sum = 0; ll ans = LLINF; rep2(i, k, v.size()) { if (v[i].first == '.') sum += v[i].second; } chmin(ans, sum); rep2(i, k, v.size()) { if (v[i].first == '#') sum += v[i].second; else sum -= v[i].second; chmin(ans, sum); } cout << ans << endl; return 0; }
replace
109
110
109
110
0
p03069
C++
Runtime Error
#include "bits/stdc++.h" #include <cmath> using namespace std; #define f first #define s second #define pb push_back #define pp pop_back #define mp make_pair #define sz(x) (int)x.size() #define sqr(x) ((x)*1ll * (x)) #define all(x) x.begin(), x.end() #define clr(a, v) memset(a, v, sizeof(a)) #define rep(i, l, r) for (int i = (l); i <= (r); i++) #define per(i, l, r) for (int i = (l); i >= (r); i--) #define reflex ios_base::sync_with_stdio(false) #define nl '\n' #define ioi exit(0); typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int N = (int)2e5 + 7; const int inf = (int)1e9 + 7; const int mod = (int)1e9 + 7; const ll linf = (ll)1e18 + 7; const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}; const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; const int kx[] = {-1, 1, 2, 2, 1, -1, -2, -2}; const int ky[] = {2, 2, 1, -1, -2, -2, -1, 1}; string conv(int a) { stringstream ss; ss << a; string str = ss.str(); return str; } string conv(char a) { stringstream ss; ss << a; string str = ss.str(); return str; } int conv(string a) { stringstream geek(a); int x = 0; geek >> x; return x; } string cad; char s[5000]; int memoA[N]; int memoB[N]; int B(int i) { int &m = memoB[i]; if (m != -1) return m; if (i == 0) return 0; if (s[i] == '.') { m = B(i - 1); return m; } else { m = B(i - 1) + 1; return m; } } int A(int i) { int &m = memoA[i]; if (m != -1) return m; if (i == 0) return inf; if (s[i] == '.') { m = min(A(i - 1), B(i - 1)) + 1; ; return m; } else { m = min(A(i - 1), B(i - 1)); return m; } } int main(void) { clr(memoA, -1); clr(memoB, -1); int x; cin >> x; cin >> cad; int n = (int)cad.size(); rep(i, 0, n - 1) s[i + 1] = cad[i]; // cout<< A(n) <<" "<< B(n)<<endl; cout << min(A(n), B(n)); return 0; }
#include "bits/stdc++.h" #include <cmath> using namespace std; #define f first #define s second #define pb push_back #define pp pop_back #define mp make_pair #define sz(x) (int)x.size() #define sqr(x) ((x)*1ll * (x)) #define all(x) x.begin(), x.end() #define clr(a, v) memset(a, v, sizeof(a)) #define rep(i, l, r) for (int i = (l); i <= (r); i++) #define per(i, l, r) for (int i = (l); i >= (r); i--) #define reflex ios_base::sync_with_stdio(false) #define nl '\n' #define ioi exit(0); typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int N = (int)2e5 + 7; const int inf = (int)1e9 + 7; const int mod = (int)1e9 + 7; const ll linf = (ll)1e18 + 7; const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}; const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; const int kx[] = {-1, 1, 2, 2, 1, -1, -2, -2}; const int ky[] = {2, 2, 1, -1, -2, -2, -1, 1}; string conv(int a) { stringstream ss; ss << a; string str = ss.str(); return str; } string conv(char a) { stringstream ss; ss << a; string str = ss.str(); return str; } int conv(string a) { stringstream geek(a); int x = 0; geek >> x; return x; } string cad; char s[N]; int memoA[N]; int memoB[N]; int B(int i) { int &m = memoB[i]; if (m != -1) return m; if (i == 0) return 0; if (s[i] == '.') { m = B(i - 1); return m; } else { m = B(i - 1) + 1; return m; } } int A(int i) { int &m = memoA[i]; if (m != -1) return m; if (i == 0) return inf; if (s[i] == '.') { m = min(A(i - 1), B(i - 1)) + 1; ; return m; } else { m = min(A(i - 1), B(i - 1)); return m; } } int main(void) { clr(memoA, -1); clr(memoB, -1); int x; cin >> x; cin >> cad; int n = (int)cad.size(); rep(i, 0, n - 1) s[i + 1] = cad[i]; // cout<< A(n) <<" "<< B(n)<<endl; cout << min(A(n), B(n)); return 0; }
replace
61
62
61
62
0
p03069
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++) #define all(obj) (obj).begin(), (obj).end() #define rall(obj) (obj).rbegin(), (obj).rend() #define collect(arr, size) rep(i, size) cin >> arr[i]; int main() { int N; string S; cin >> N >> S; bitset<200000> pattern, stones; pattern.set(); stones.set(); rep(i, N) { stones[N - 1 - i] = S[i] == '.'; } int minimum = INT_MAX; rep(i, N + 1) { minimum = min(minimum, (int)((pattern << i) ^ stones).count()); } cout << minimum << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++) #define all(obj) (obj).begin(), (obj).end() #define rall(obj) (obj).rbegin(), (obj).rend() #define collect(arr, size) rep(i, size) cin >> arr[i]; int main() { int N; string S; cin >> N >> S; int left_black = 0, right_white = 0; rep(i, N) if (S[i] == '.') right_white++; int minimum = right_white; rep(i, N) { if (S[i] == '.') right_white--; if (S[i] == '#') left_black++; minimum = min(minimum, left_black + right_white); } cout << minimum << endl; }
replace
13
20
13
23
TLE
p03069
Python
Runtime Error
N = int(input()) S = input() W = [0] * N W[-1] += S[-1] == "." for i in range(N - 2, -1, -1): W[i] = W[i + 1] + (S[i] == ".") B = [0] * N B[0] += S[0] == "#" for i in range(1, N): B[i] = B[i - 1] + (S[i] == "#") T = [w + b for w, b in zip(W, B)] print(min(*T, W[0], B[-1]))
N = int(input()) S = input() W = [0] * N W[-1] += S[-1] == "." for i in range(N - 2, -1, -1): W[i] = W[i + 1] + (S[i] == ".") B = [0] * N B[0] += S[0] == "#" for i in range(1, N): B[i] = B[i - 1] + (S[i] == "#") T = [w + b - 1 for w, b in zip(W, B)] T = min(T) print(min(T, W[0], B[-1]))
replace
13
15
13
16
0
p03069
Python
Runtime Error
N = int(input()) S = list(input()) c = 0 a = 0 cw = [0] * N cb = [0] * N tw = 0 tb = 0 for i in range(N): if S[i] == ".": tw += 1 cw[i] = tw cb[i] = tb else: tb += 1 cb[i] = tb cw[i] = tw A = cw[N] for i in range(N): A = min(A, cb[i] + cw[N - 1] - cw[i]) print(A)
N = int(input()) S = list(input()) c = 0 a = 0 cw = [0] * N cb = [0] * N tw = 0 tb = 0 for i in range(N): if S[i] == ".": tw += 1 cw[i] = tw cb[i] = tb else: tb += 1 cb[i] = tb cw[i] = tw A = cw[N - 1] for i in range(N): A = min(A, cb[i] + cw[N - 1] - cw[i]) print(A)
replace
17
18
17
18
IndexError: list index out of range
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03069/Python/s792100988.py", line 18, in <module> A = cw[N] IndexError: list index out of range
p03069
Python
Runtime Error
N = int(input()) S = input() ans = 0 if N == 1: print(0) exit() elif N == 2 and (S[0] == "." and S[1] == "#"): print(0) exit() else: S = S[0] + S + S[N - 1] S = list(S) for n in range(N): if S[n] == "." and S[n + 2] == "." and S[n + 1] == "#": ans += 1 S[n + 1] = "." elif S[n] == "#" and S[n + 2] == "#" and S[n + 1] == ".": ans += 1 S[S + 1] = "#" print(ans)
N = int(input()) S = input() ans = N sumB = [0] * (N + 1) tmp = 0 for i in range(N): if S[i] == "#": tmp += 1 sumB[i + 1] = tmp for i in range(N + 1): ans = min(sumB[i] + (N - i) - (sumB[N] - sumB[i]), ans) # print(sumB[i] , (N - i), (sumB[N] - sumB[i]), ans) print(ans)
replace
2
19
2
12
TypeError: can only concatenate list (not "int") to list
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03069/Python/s480310094.py", line 19, in <module> S[S + 1] = '#' TypeError: can only concatenate list (not "int") to list
p03069
C++
Runtime Error
#include <bits/stdc++.h> #define MAX 2001 using namespace std; int main() { int n; char s[MAX]; cin >> n >> s; int a[MAX + 1], b[MAX + 1]; memset(a, 0, (n + 1) * sizeof(int)); memset(b, 0, (n + 1) * sizeof(int)); for (int i = 0; i < n; i++) { if (s[i] == '#') b[i + 1] = b[i] + 1; else b[i + 1] = b[i]; } for (int i = n - 1; i >= 0; i--) if (s[i] == '.') a[n - i] = a[n - 1 - i] + 1; else a[n - i] = a[n - 1 - i]; int ans = MAX + 1; for (int i = 0; i <= n; i++) ans = min(ans, b[i] + a[n - i]); cout << ans; return 0; }
#include <bits/stdc++.h> #define MAX 200001 using namespace std; int main() { int n; char s[MAX]; cin >> n >> s; int a[MAX + 1], b[MAX + 1]; memset(a, 0, (n + 1) * sizeof(int)); memset(b, 0, (n + 1) * sizeof(int)); for (int i = 0; i < n; i++) { if (s[i] == '#') b[i + 1] = b[i] + 1; else b[i + 1] = b[i]; } for (int i = n - 1; i >= 0; i--) if (s[i] == '.') a[n - i] = a[n - 1 - i] + 1; else a[n - i] = a[n - 1 - i]; int ans = MAX + 1; for (int i = 0; i <= n; i++) ans = min(ans, b[i] + a[n - i]); cout << ans; return 0; }
replace
1
2
1
2
0
p03069
Python
Time Limit Exceeded
N = int(input()) S = input() ans = N for i in range(N + 1): ans = min(ans, S[:i].count("#") + S[i:].count(".")) print(ans)
N = int(input()) S = input() ws = S.count(".") bs = 0 ans = ws + bs for i in range(N): if S[i] == "#": bs += 1 else: ws -= 1 ans = min(ans, ws + bs) print(ans)
replace
2
5
2
11
TLE
p03069
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int white[100005], black[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; string s; cin >> n >> s; white[n - 1] = (int)(s[n - 1] == '.'); black[0] = (int)(s[0] == '#'); for (int i = n - 2; i >= 0; i--) white[i] += white[i + 1] + (int)(s[i] == '.'); for (int i = 1; i < n; i++) black[i] += black[i - 1] + (int)(s[i] == '#'); int result = white[0]; for (int i = 0; i < n; i++) result = min(result, black[i] + white[i + 1]); cout << result << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int white[200005], black[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; string s; cin >> n >> s; white[n - 1] = (int)(s[n - 1] == '.'); black[0] = (int)(s[0] == '#'); for (int i = n - 2; i >= 0; i--) white[i] += white[i + 1] + (int)(s[i] == '.'); for (int i = 1; i < n; i++) black[i] += black[i - 1] + (int)(s[i] == '#'); int result = white[0]; for (int i = 0; i < n; i++) result = min(result, black[i] + white[i + 1]); cout << result << endl; return 0; }
replace
4
5
4
5
0
p03069
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; vector<int> res(N + 1); for (int i = 0; i <= N; i++) { res.at(i) = count(S.begin(), S.begin() + i, '#') + count(S.begin() + i, S.end(), '.'); } cout << *min_element(res.begin(), res.end()) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; cin >> S; vector<int> res(N + 1); int left = 0; int right = count(S.begin(), S.end(), '.'); res.at(0) = left + right; for (int i = 0; i < N; i++) { if (S.at(i) == '#') left++; else right--; res.at(i + 1) = left + right; } cout << *min_element(res.begin(), res.end()) << endl; }
replace
12
15
12
23
TLE
p03069
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int N, ans; char S[100100]; int titik[100100], pagar[100100]; int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> S[i]; if (S[i] == '.') { titik[i] = titik[i - 1] + 1; pagar[i] = pagar[i - 1]; } else { titik[i] = titik[i - 1]; pagar[i] = pagar[i - 1] + 1; } } ans = N; for (int i = 0; i <= N; i++) { ans = min(ans, pagar[i] + titik[N] - titik[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int N, ans; char S[200100]; int titik[200100], pagar[200100]; int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> S[i]; if (S[i] == '.') { titik[i] = titik[i - 1] + 1; pagar[i] = pagar[i - 1]; } else { titik[i] = titik[i - 1]; pagar[i] = pagar[i - 1] + 1; } } ans = N; for (int i = 0; i <= N; i++) { ans = min(ans, pagar[i] + titik[N] - titik[i]); } cout << ans << endl; return 0; }
replace
4
6
4
6
0
p03069
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> x; int c[100001]; int main(int, char **) { ll a, w = 0, b = 0, ans = 0; string s; cin >> a >> s; c[0] = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '#') { b++; } else { w++; } c[i + 1] = b; } ans = a - c[a]; for (int i = 0; i <= s.length(); i++) { ll x = c[i] + (a - i) - (c[a] - c[i]); ans = min(ans, x); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> x; int c[200010]; int main(int, char **) { ll a, w = 0, b = 0, ans = 0; string s; cin >> a >> s; c[0] = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '#') { b++; } else { w++; } c[i + 1] = b; } ans = a - c[a]; for (int i = 0; i <= s.length(); i++) { ll x = c[i] + (a - i) - (c[a] - c[i]); ans = min(ans, x); } cout << ans << endl; return 0; }
replace
7
8
7
8
0
p03070
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iomanip> #include <iostream> #include <limits.h> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> #define ll long long #define rep2(i, a, b) for (ll i = a; i <= b; i++) #define rep(i, n) for (ll i = 0; i < n; i++) #define rep3(i, a, b) for (int i = a; i >= b; i--) #define REP(e, v) for (auto e : v) #define queint queue<int> #define pii pair<int, int> #define pll pair<ll, ll> #define pq priority_queue<int> // 大きい順 #define pqg priority_queue<int, vec, greater<int>> // 小さい順 #define pb push_back #define vec vector<int> #define vecvec vector<vector<int>> #define vecll vector<ll> #define vecvecll vector<vector<ll>> #define bs binary_search #define All(c) (c).begin(), (c).end() #define mp make_pair using namespace std; int in() { int x; scanf("%d", &x); return x; } string stin() { string s; cin >> s; return s; } ll lin() { ll x; scanf("%lld", &x); return x; } ll mod = 998244353; ll modpow(ll a, ll b) { if (b == 0) return 1; if (b % 2 == 0) { ll d = modpow(a, b / 2); return d * d % mod; } return modpow(a, b - 1) * a % mod; } int main() { int n = in(); ll sum = 0; vec a(n); rep(i, n) a[i + 1] = in(); vector<vecll> dp(n + 1, vecll(90001, 0)); dp[0][0] = 1; rep(i, n) { sum += a[i + 1]; rep2(j, 0, sum) { dp[i + 1][j] = 2 * dp[i][j]; if (j >= a[i + 1]) dp[i + 1][j] += dp[i][j - a[i + 1]]; dp[i + 1][j] %= mod; } } ll ans = modpow(3, n); rep2(i, (sum + 1) / 2, sum) ans = (ans - 3 * dp[n][i]) % mod; if (sum % 2 == 0) { vector<vecll> c(n + 1, vecll(90001, 0)); c[0][0] = 1; rep(i, n) { rep2(j, 0, sum) { c[i + 1][j] = c[i][j]; if (j >= a[i + 1]) c[i + 1][j] += c[i][j - a[i + 1]]; c[i + 1][j] %= mod; } } ans += 3 * c[n][sum / 2]; } cout << (ans + mod) % mod << endl; }
#include <algorithm> #include <cstdio> #include <iomanip> #include <iostream> #include <limits.h> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> #define ll long long #define rep2(i, a, b) for (ll i = a; i <= b; i++) #define rep(i, n) for (ll i = 0; i < n; i++) #define rep3(i, a, b) for (int i = a; i >= b; i--) #define REP(e, v) for (auto e : v) #define queint queue<int> #define pii pair<int, int> #define pll pair<ll, ll> #define pq priority_queue<int> // 大きい順 #define pqg priority_queue<int, vec, greater<int>> // 小さい順 #define pb push_back #define vec vector<int> #define vecvec vector<vector<int>> #define vecll vector<ll> #define vecvecll vector<vector<ll>> #define bs binary_search #define All(c) (c).begin(), (c).end() #define mp make_pair using namespace std; int in() { int x; scanf("%d", &x); return x; } string stin() { string s; cin >> s; return s; } ll lin() { ll x; scanf("%lld", &x); return x; } ll mod = 998244353; ll modpow(ll a, ll b) { if (b == 0) return 1; if (b % 2 == 0) { ll d = modpow(a, b / 2); return d * d % mod; } return modpow(a, b - 1) * a % mod; } int main() { int n = in(); ll sum = 0; vec a(n + 1); rep(i, n) a[i + 1] = in(); vector<vecll> dp(n + 1, vecll(90001, 0)); dp[0][0] = 1; rep(i, n) { sum += a[i + 1]; rep2(j, 0, sum) { dp[i + 1][j] = 2 * dp[i][j]; if (j >= a[i + 1]) dp[i + 1][j] += dp[i][j - a[i + 1]]; dp[i + 1][j] %= mod; } } ll ans = modpow(3, n); rep2(i, (sum + 1) / 2, sum) ans = (ans - 3 * dp[n][i]) % mod; if (sum % 2 == 0) { vector<vecll> c(n + 1, vecll(90001, 0)); c[0][0] = 1; rep(i, n) { rep2(j, 0, sum) { c[i + 1][j] = c[i][j]; if (j >= a[i + 1]) c[i + 1][j] += c[i][j - a[i + 1]]; c[i + 1][j] %= mod; } } ans += 3 * c[n][sum / 2]; } cout << (ans + mod) % mod << endl; }
replace
59
60
59
60
0
p03070
C++
Time Limit Exceeded
// written by NewbieChd #include <cctype> #include <cstdio> #define BUF 1000000 using namespace std; const int N = 301, M = 45001, yyb = 998244353; char buf[BUF], *p1, *p2; inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; } inline int read() { register int f = 0; register char c; while (!isdigit(c = getChar())) { } do f = f * 10 + (c ^ 48); while (isdigit(c = getChar())); return f; } int a[N], f[N][M], g[N][M]; inline int power(int x, int y) { register int o = 1; for (; y; y >>= 1, x = 1ll * x * x % yyb) if (y & 1) o = 1ll * o * x % yyb; return o; } int main() { #ifndef ONLINE_JUDGE freopen("a.in", "r", stdin); // freopen("a.out", "w", stdout); #endif register int n = read(), i, j, sum = 0, ans = 0; for (i = 1; i <= n; ++i) sum += a[i] = read(); sum /= 2, f[0][0] = g[0][0] = 1; for (i = 1; i <= n; ++i) { for (j = sum; j >= a[i]; --j) f[i][j] = (2ll * f[i - 1][j - a[i]] + f[i - 1][j]) % yyb, g[i][j] = (g[i - 1][j - a[i]] + g[i - 1][j]) % yyb; for (j = a[i] - 1; ~j; --j) f[i][j] = f[i - 1][j], g[i][j] = g[i - 1][j]; } for (j = 1; j <= sum; ++j) ans = (-2ll * g[n][j] + f[n][j] + ans) % yyb; ans = (-3ll * power(2, n) + power(3, n) + 3 - 3ll * ans) % yyb, printf("%d\n", (ans + yyb) % yyb); return 0; }
// written by NewbieChd #include <cctype> #include <cstdio> #define BUF 1000000 using namespace std; const int N = 301, M = 45001, yyb = 998244353; char buf[BUF], *p1, *p2; inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; } inline int read() { register int f = 0; register char c; while (!isdigit(c = getChar())) { } do f = f * 10 + (c ^ 48); while (isdigit(c = getChar())); return f; } int a[N], f[N][M], g[N][M]; inline int power(int x, int y) { register int o = 1; for (; y; y >>= 1, x = 1ll * x * x % yyb) if (y & 1) o = 1ll * o * x % yyb; return o; } int main() { register int n = read(), i, j, sum = 0, ans = 0; for (i = 1; i <= n; ++i) sum += a[i] = read(); sum /= 2, f[0][0] = g[0][0] = 1; for (i = 1; i <= n; ++i) { for (j = sum; j >= a[i]; --j) f[i][j] = (2ll * f[i - 1][j - a[i]] + f[i - 1][j]) % yyb, g[i][j] = (g[i - 1][j - a[i]] + g[i - 1][j]) % yyb; for (j = a[i] - 1; ~j; --j) f[i][j] = f[i - 1][j], g[i][j] = g[i - 1][j]; } for (j = 1; j <= sum; ++j) ans = (-2ll * g[n][j] + f[n][j] + ans) % yyb; ans = (-3ll * power(2, n) + power(3, n) + 3 - 3ll * ans) % yyb, printf("%d\n", (ans + yyb) % yyb); return 0; }
delete
31
35
31
31
TLE
p03070
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define int long long const int N = 301; const int K = 101; const int MOD = 998244353; int add(int a, int b) { return (a + b) % MOD; } int sub(int a, int b) { return (a - b + MOD) % MOD; } int mul(int a, int b) { return (a * b) % MOD; } int binpow(int a, int b) { int res = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } int divv(int a, int b) { return mul(a, binpow(b, MOD - 2)); } int dp[N][K]; int dp2[N][K]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (auto &t : a) { cin >> t; } dp[0][0] = 1; dp2[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < K; j++) { if (a[i] + j < K) { dp[i + 1][j + a[i]] = add(dp[i + 1][j + a[i]], dp[i][j]); dp2[i + 1][j + a[i]] = add(dp2[i + 1][j + a[i]], dp2[i][j]); } dp[i + 1][j] = add(dp[i + 1][j], mul(2, dp[i][j])); dp2[i + 1][j] = add(dp2[i + 1][j], mul(1, dp2[i][j])); } } int s = 0; for (auto t : a) { s += t; } int ans = 0; for (int tk = 0; tk < s; tk++) { if (tk >= s - tk) { int cnt = dp[n][tk]; cnt = sub(cnt, mul(dp2[n][tk], 2)); ans = add(ans, cnt); } } ans = mul(ans, 3); int all = binpow(3, n); all = sub(all, mul(3, sub(binpow(2, n), 2))); all = sub(all, 3); cout << sub(all, ans) << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define int long long const int N = 301; const int K = N * N; const int MOD = 998244353; int add(int a, int b) { return (a + b) % MOD; } int sub(int a, int b) { return (a - b + MOD) % MOD; } int mul(int a, int b) { return (a * b) % MOD; } int binpow(int a, int b) { int res = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } int divv(int a, int b) { return mul(a, binpow(b, MOD - 2)); } int dp[N][K]; int dp2[N][K]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (auto &t : a) { cin >> t; } dp[0][0] = 1; dp2[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < K; j++) { if (a[i] + j < K) { dp[i + 1][j + a[i]] = add(dp[i + 1][j + a[i]], dp[i][j]); dp2[i + 1][j + a[i]] = add(dp2[i + 1][j + a[i]], dp2[i][j]); } dp[i + 1][j] = add(dp[i + 1][j], mul(2, dp[i][j])); dp2[i + 1][j] = add(dp2[i + 1][j], mul(1, dp2[i][j])); } } int s = 0; for (auto t : a) { s += t; } int ans = 0; for (int tk = 0; tk < s; tk++) { if (tk >= s - tk) { int cnt = dp[n][tk]; cnt = sub(cnt, mul(dp2[n][tk], 2)); ans = add(ans, cnt); } } ans = mul(ans, 3); int all = binpow(3, n); all = sub(all, mul(3, sub(binpow(2, n), 2))); all = sub(all, 3); cout << sub(all, ans) << endl; }
replace
28
29
28
29
0
p03070
C++
Runtime Error
#include <algorithm> #include <bitset> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 998244353; typedef long double ld; const ll INF = 1e+14; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define int long long void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } signed main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; ll a[330], sum = 0; rep(i, N) { cin >> a[i]; sum += a[i]; } ll all = 1LL, hoshugo = 0; rep(i, N) { all *= 3LL; all %= mod; } ll dp[330][90900], dp2[330][90900]; memset(dp, 0, sizeof(dp)); memset(dp2, 0, sizeof(dp2)); dp[0][0] = 1LL; dp2[0][0] = 1LL; rep(i, N) { rep(s, sum + 1) { if (s - a[i] >= 0) { (dp[i + 1][s] += dp[i][s - a[i]]) %= mod; (dp2[i + 1][s] += dp2[i][s - a[i]]) %= mod; } (dp[i + 1][s] += 2 * dp[i][s]) %= mod; (dp2[i + 1][s] += dp2[i][s]) %= mod; } } Rep(s, (ll)(sum + 1) / 2, sum + 1) { (hoshugo += dp[N][s] * 3) %= mod; } if (sum % 2 == 0) { hoshugo -= 3 * dp2[N][sum / 2]; hoshugo = (hoshugo + 4 * mod) % mod; } ll ans = all - hoshugo; cout << (ans + mod) % mod << endl; return 0; }
#include <algorithm> #include <bitset> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 998244353; typedef long double ld; const ll INF = 1e+14; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define int long long void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } signed main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; ll a[330], sum = 0; rep(i, N) { cin >> a[i]; sum += a[i]; } ll all = 1LL, hoshugo = 0; rep(i, N) { all *= 3LL; all %= mod; } vector<vector<ll>> dp(N + 1, vector<ll>(sum + 1, 0)); auto dp2 = dp; dp[0][0] = 1LL; dp2[0][0] = 1LL; rep(i, N) { rep(s, sum + 1) { if (s - a[i] >= 0) { (dp[i + 1][s] += dp[i][s - a[i]]) %= mod; (dp2[i + 1][s] += dp2[i][s - a[i]]) %= mod; } (dp[i + 1][s] += 2 * dp[i][s]) %= mod; (dp2[i + 1][s] += dp2[i][s]) %= mod; } } Rep(s, (ll)(sum + 1) / 2, sum + 1) { (hoshugo += dp[N][s] * 3) %= mod; } if (sum % 2 == 0) { hoshugo -= 3 * dp2[N][sum / 2]; hoshugo = (hoshugo + 4 * mod) % mod; } ll ans = all - hoshugo; cout << (ans + mod) % mod << endl; return 0; }
replace
71
74
71
73
-11
p03070
C++
Runtime Error
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> // #include <function> using namespace std; typedef long long unsigned int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define REP(i, n) for (long i = 0; i < (long)(n); i++) int main() { long N; cin >> N; vector<long> array(N); long sum_a = 0; long max_a = 0; long ans = 1; const long MOD = 998244353; REP(i, N) { cin >> array[i]; sum_a += array[i]; max_a = max_a > array[i] ? max_a : array[i]; ans = (ans * 3) % MOD; } // long dp[300][(300 * 300) + 1] = {0}; // long dp1[300][(300 * 300) + 1] = {0}; vector<vector<long>> dp(300, vector<long>(300 * 300 + 1L, 0L)); vector<vector<long>> dp1(300, vector<long>(300 * 300 + 1L, 0L)); dp[0][array[0]] = 1; dp[0][0] = 2; dp1[0][array[0]] = 1; dp1[0][0] = 1; REP(i, N - 1) { REP(j, (N * max_a) + 1) { dp[i + 1][j] = (dp[i + 1][j] + 2 * dp[i][j]) % MOD; dp[i + 1][j + array[i + 1]] = (dp[i + 1][j + array[i + 1]] + dp[i][j]) % MOD; dp1[i + 1][j] = (dp1[i + 1][j] + dp1[i][j]) % MOD; dp1[i + 1][j + array[i + 1]] = (dp1[i + 1][j + array[i + 1]] + dp1[i][j]) % MOD; } } long tmp1 = 0; long tmp2 = 0; if (sum_a % 2 == 0) { for (long i = sum_a / 2; i < N * max_a + 1; i++) { tmp1 = (tmp1 + dp[N - 1][i]) % MOD; // tmp2 = (tmp2 + dp1[N - 1][i]) % MOD; } tmp2 = dp1[N - 1][sum_a / 2] % MOD; } else { for (long i = (sum_a + 1) / 2; i < N * max_a + 1; i++) { tmp1 = (tmp1 + dp[N - 1][i]) % MOD; } } // cout << ans << endl; // cout << tmp1 << endl; // cout << tmp2 << endl; tmp1 = (tmp1 * 3) % MOD; tmp2 = (tmp2 * 3) % MOD; ans = (ans - tmp1) % MOD; if (ans < 0) ans += MOD; ans = (ans + tmp2) % MOD; cout << ans << endl; return 0; }
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> // #include <function> using namespace std; typedef long long unsigned int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define REP(i, n) for (long i = 0; i < (long)(n); i++) int main() { long N; cin >> N; vector<long> array(N); long sum_a = 0; long max_a = 0; long ans = 1; const long MOD = 998244353; REP(i, N) { cin >> array[i]; sum_a += array[i]; max_a = max_a > array[i] ? max_a : array[i]; ans = (ans * 3) % MOD; } // long dp[300][(300 * 300) + 1] = {0}; // long dp1[300][(300 * 300) + 1] = {0}; vector<vector<long>> dp(300, vector<long>(300 * 310 + 1L, 0L)); vector<vector<long>> dp1(300, vector<long>(300 * 310 + 1L, 0L)); dp[0][array[0]] = 1; dp[0][0] = 2; dp1[0][array[0]] = 1; dp1[0][0] = 1; REP(i, N - 1) { REP(j, (N * max_a) + 1) { dp[i + 1][j] = (dp[i + 1][j] + 2 * dp[i][j]) % MOD; dp[i + 1][j + array[i + 1]] = (dp[i + 1][j + array[i + 1]] + dp[i][j]) % MOD; dp1[i + 1][j] = (dp1[i + 1][j] + dp1[i][j]) % MOD; dp1[i + 1][j + array[i + 1]] = (dp1[i + 1][j + array[i + 1]] + dp1[i][j]) % MOD; } } long tmp1 = 0; long tmp2 = 0; if (sum_a % 2 == 0) { for (long i = sum_a / 2; i < N * max_a + 1; i++) { tmp1 = (tmp1 + dp[N - 1][i]) % MOD; // tmp2 = (tmp2 + dp1[N - 1][i]) % MOD; } tmp2 = dp1[N - 1][sum_a / 2] % MOD; } else { for (long i = (sum_a + 1) / 2; i < N * max_a + 1; i++) { tmp1 = (tmp1 + dp[N - 1][i]) % MOD; } } // cout << ans << endl; // cout << tmp1 << endl; // cout << tmp2 << endl; tmp1 = (tmp1 * 3) % MOD; tmp2 = (tmp2 * 3) % MOD; ans = (ans - tmp1) % MOD; if (ans < 0) ans += MOD; ans = (ans + tmp2) % MOD; cout << ans << endl; return 0; }
replace
45
47
45
47
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03070
C++
Runtime Error
#include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; int MOD = 998244353; int main(void) { int N; cin >> N; int a[N]; int sum = 0; long long all = 1; for (int i = 0; i < N; i++) { cin >> a[i]; sum += a[i]; all = (3 * all) % MOD; } long long dp1[N + 1][sum + 1], dp2[N + 1][sum + 1]; memset(dp1, 0, sizeof(dp1)); memset(dp2, 0, sizeof(dp2)); dp1[0][0] = dp2[0][0] = 1; for (int i = 0; i < N; i++) { for (int j = 0; j <= sum; j++) { if (a[i] <= j) { dp1[i + 1][j] = (dp1[i][j - a[i]] + 2 * dp1[i][j]) % MOD; dp2[i + 1][j] = (dp2[i][j - a[i]] + dp2[i][j]) % MOD; } else { dp1[i + 1][j] = 2 * dp1[i][j] % MOD; dp2[i + 1][j] = dp2[i][j] % MOD; } } } long long p1 = 0; for (int i = (sum + 1) / 2; i <= sum; i++) { p1 = (p1 + dp1[N][i]) % MOD; } long long p2 = 0; if (sum % 2 == 0) { p2 = dp2[N][sum / 2] % MOD; } long long ans = (all - 3 * p1 + 3 * p2) % MOD; while (ans < 0) { ans += MOD; } cout << ans << endl; }
#include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; int MOD = 998244353; int main(void) { int N; cin >> N; int a[N]; int sum = 0; long long all = 1; for (int i = 0; i < N; i++) { cin >> a[i]; sum += a[i]; all = (3 * all) % MOD; } vector<vector<long long>> dp1(N + 1, vector<long long>(sum + 1, 0)), dp2(N + 1, vector<long long>(sum + 1, 0)); dp1[0][0] = dp2[0][0] = 1; for (int i = 0; i < N; i++) { for (int j = 0; j <= sum; j++) { if (a[i] <= j) { dp1[i + 1][j] = (dp1[i][j - a[i]] + 2 * dp1[i][j]) % MOD; dp2[i + 1][j] = (dp2[i][j - a[i]] + dp2[i][j]) % MOD; } else { dp1[i + 1][j] = 2 * dp1[i][j] % MOD; dp2[i + 1][j] = dp2[i][j] % MOD; } } } long long p1 = 0; for (int i = (sum + 1) / 2; i <= sum; i++) { p1 = (p1 + dp1[N][i]) % MOD; } long long p2 = 0; if (sum % 2 == 0) { p2 = dp2[N][sum / 2] % MOD; } long long ans = (all - 3 * p1 + 3 * p2) % MOD; while (ans < 0) { ans += MOD; } cout << ans << endl; }
replace
22
25
22
24
0