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
p02658
Python
Time Limit Exceeded
n = int(input()) a = [int(i) for i in input().split()] answer = 1 for i in range(len(a)): answer = answer * a[i] if answer > 10**18: print(-1) else: print(answer)
n = int(input()) a = [int(i) for i in input().split()] answer = 1 for i in range(len(a)): answer = answer * a[i] if answer > 10**18: if 0 in a: print(0) else: print(-1) break else: print(answer)
replace
5
8
5
11
TLE
p02658
Python
Time Limit Exceeded
answer = 1 lens = int(input()) arrs = [int(x) for x in input().split()] for x in arrs: answer *= x if answer > int(10**18): answer = -1 print(answer)
answer = 1 lens = int(input()) arrs = [int(x) for x in input().split()] if 0 in arrs: answer = 0 else: for x in arrs: answer *= x if answer > int(10**18): answer = -1 break print(answer)
replace
3
7
3
11
TLE
p02658
Python
Time Limit Exceeded
n = int(input()) a = list(map(int, input().split())) res = 1 for a_i in a: if 0 == a_i: print(0) exit(0) elif res > 10**18: res = -1 else: res *= a_i print(-1 if res > 10**18 else res)
n = int(input()) a = list(map(int, input().split())) res = 1 for a_i in a: if 0 == a_i: print(0) exit(0) elif res > 10**18: continue else: res *= a_i print(-1 if res > 10**18 else res)
replace
8
9
8
9
TLE
p02658
Python
Runtime Error
n = int(input()) a = list(map(int, input().split())) m = 10**18 ans = 1 for i in range(0, n): if a[i] == 0: print(0) exit() for i in range(0, n): ans *= a[i] if ans > m: print(-1) exit(-1) if ans > m: print(-1) else: print(ans)
n = int(input()) a = list(map(int, input().split())) m = 10**18 ans = 1 for i in range(0, n): if a[i] == 0: print(0) exit() for i in range(0, n): ans *= a[i] if ans > m: print(-1) exit() if ans > m: print(-1) else: print(ans)
replace
15
16
15
16
0
p02658
Python
Time Limit Exceeded
from sys import stdin input = stdin.readline n = int(input().rstrip()) a = list(map(int, input().rstrip().split())) cum = 1 over = False for x in a: if x == 0: cum = 0 break cum *= x if cum > 1e18: over = True print(-1) if (over and cum != 0) else print(cum)
from sys import stdin input = stdin.readline n = int(input().rstrip()) a = list(map(int, input().rstrip().split())) cum = 1 over = False for x in a: if x == 0: cum = 0 break if cum == 0: print(0) else: for x in a: cum *= x if cum > 1e18: over = True break print(-1) if over else print(cum)
replace
14
19
14
23
TLE
p02658
Python
Runtime Error
N = int(input()) A = list(map(int, input().split())) if 0 in A: print(0) else: ans = 1 for i in range(A): ans += A[i] if ans > 10**18: print(-1) exit() print(ans)
N = int(input()) A = list(map(int, input().split())) if 0 in A: print(0) else: ans = 1 for i in range(N): ans *= A[i] if ans > 10**18: print(-1) exit() print(ans)
replace
7
9
7
9
TypeError: 'list' object cannot be interpreted as an integer
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02658/Python/s912887919.py", line 8, in <module> for i in range(A): TypeError: 'list' object cannot be interpreted as an integer
p02658
Python
Time Limit Exceeded
N = int(input()) A = list(map(int, input().split())) ans = 1 for i in range(N): ans *= A[i] if ans > 10**18: ans = -1 print(ans)
N = int(input()) A = list(map(int, input().split())) ans = 1 A.sort() if A[0] == 0: print(0) else: for i in range(N): ans *= A[i] if ans > 10**18: print(-1) exit(0) print(ans)
replace
3
8
3
13
TLE
p02658
Python
Runtime Error
N, A = map(int, open(0).read().split()) if 0 in A: print(0) exit() ans = 1 for a in A: ans *= a if ans > 10**18: print(-1) break else: print(ans)
N, *A = map(int, open(0).read().split()) if 0 in A: print(0) exit() ans = 1 for a in A: ans *= a if ans > 10**18: print(-1) break else: print(ans)
replace
0
1
0
1
ValueError: too many values to unpack (expected 2)
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02658/Python/s722215477.py", line 1, in <module> N, A = map(int, open(0).read().split()) ValueError: too many values to unpack (expected 2)
p02658
Python
Time Limit Exceeded
n = int(input()) a = list(map(int, input().split())) ans = 1 a_in = [s for s in a if 0 in a] if a_in: print("0") exit() else: for i in a: ans = ans * i if ans > 10**18: print("-1") exit() print(ans)
n = int(input()) a = list(map(int, input().split())) ans = 1 if min(a) == 0: print("0") exit() else: for i in a: ans = ans * i if ans > 10**18: print("-1") exit() print(ans)
replace
5
7
5
6
TLE
p02658
Python
Time Limit Exceeded
n = int(input()) a = list(map(int, input().split())) n = 1 for i in a: n *= i if n > 10**18: n = -1 print(n)
def main(): N = int(input()) A = list(map(int, input().split())) if 0 in A: print(0) return ans = 1 for i in A: ans *= i if ans > 1000000000000000000: print(-1) return print(ans) main()
replace
0
8
0
16
TLE
p02658
Python
Time Limit Exceeded
#!/usr/bin/env python3 n = int(input()) arg = list(map(int, input().split())) ans = 1 if 0 in arg: ans = 0 else: for m in arg: ans *= m if ans > 1000000000000000000: ans = -1 print(ans)
#!/usr/bin/env python3 n = int(input()) arg = list(map(int, input().split())) ans = 1 if 0 in arg: ans = 0 else: for m in arg: ans *= m if ans > 1000000000000000000: ans = -1 break print(ans)
insert
14
14
14
15
TLE
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using P = pair<ll, ll>; const string ln = "\n"; constexpr int INF = 1001001001; constexpr int MOD = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll lim = 1; for (int i = 0; i < 18; i++) { lim *= 10; } ll ans = 1; bool ok = true; for (int i = 0; i < n; i++) { if (a[i] > (lim / ans)) { ans = -1; ok = false; } ans *= a[i]; } if (ans == 0) { cout << ans << ln; } else { cout << (ok ? ans : -1) << ln; } return 0; }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using P = pair<ll, ll>; const string ln = "\n"; constexpr int INF = 1001001001; constexpr int MOD = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll lim = 1; for (int i = 0; i < 18; i++) { lim *= 10; } ll ans = 1; bool ok = true; for (int i = 0; i < n; i++) { if (ans == 0) { break; } if (a[i] > (lim / ans)) { ans = -1; ok = false; } ans *= a[i]; } if (ans == 0) { cout << ans << ln; } else { cout << (ok ? ans : -1) << ln; } return 0; }
insert
29
29
29
33
0
p02658
C++
Runtime Error
#include "bits/stdc++.h" #include "ext/pb_ds/assoc_container.hpp" #include "ext/pb_ds/tree_policy.hpp" using namespace std; using namespace __gnu_pbds; #define ll long long int #define pb push_back #define mp make_pair #define ff first #define ss second #define all(a) a.begin(), a.end() typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // order_of_key(val): returns the number of values less than val // find_by_order(k): returns an iterator to the kth largest element (0-based) int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; bool flag = true, zero = false; ll a[n], ans = 1, maxi = 1e18; for (int i = 0; i < n; i++) { cin >> a[i]; if (!zero && a[i] > maxi / ans) { flag = false; } if (a[i] == 0) { zero = true; } ans = ans * a[i]; } if (flag && !zero) { cout << ans << "\n"; } else if (zero) { cout << "0\n"; } else { cout << "-1\n"; } }
#include "bits/stdc++.h" #include "ext/pb_ds/assoc_container.hpp" #include "ext/pb_ds/tree_policy.hpp" using namespace std; using namespace __gnu_pbds; #define ll long long int #define pb push_back #define mp make_pair #define ff first #define ss second #define all(a) a.begin(), a.end() typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // order_of_key(val): returns the number of values less than val // find_by_order(k): returns an iterator to the kth largest element (0-based) int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; bool flag = true, zero = false; ll a[n], ans = 1, maxi = 1e18; for (int i = 0; i < n; i++) { cin >> a[i]; if (ans != 0 && a[i] > maxi / ans) { flag = false; } if (a[i] == 0) { zero = true; } ans = ans * a[i]; } if (flag && !zero) { cout << ans << "\n"; } else if (zero) { cout << "0\n"; } else { cout << "-1\n"; } }
replace
29
30
29
30
0
p02658
C++
Runtime Error
#include <algorithm> //min,max,swap,sort,reverse,lower_bound,upper_bound #include <bitset> //bitset #include <cctype> //isupper,islower,isdigit,toupper,tolower #include <cstdint> //int64_t,int*_t #include <cstdio> //printf #include <cstdio> #include <cstring> #include <deque> //deque #include <iomanip> #include <iostream> //cout,endl,cin #include <map> //map #include <math.h> #include <queue> //queue,priority_queue #include <set> //set #include <stack> //stack #include <string> //string,to_string,stoi #include <tuple> //tuple,make_tuple #include <unordered_map> //unordered_map #include <unordered_set> //unordered_set #include <utility> //pair,make_pair #include <vector> //vector using namespace std; typedef long long ll; /* int main() { ll a; double b; cin >> a >> b; cout << fixed << (ll)(floor(a * b)) << endl; } */ int main() { ll n; ll result = 1; int a = 0; // vector<int> vc; cin >> n; while (n--) { ll x; cin >> x; // result = result * x; if (x == 0) { a = 0; } else if (x > 1000000000000000000 / result) { a = 1; result = 1; } result = result * x; // cout << result << endl; // vc.push_back(x); } if (result > 1000000000000000000 || a == 1) { cout << -1 << endl; } else { cout << result << endl; } }
#include <algorithm> //min,max,swap,sort,reverse,lower_bound,upper_bound #include <bitset> //bitset #include <cctype> //isupper,islower,isdigit,toupper,tolower #include <cstdint> //int64_t,int*_t #include <cstdio> //printf #include <cstdio> #include <cstring> #include <deque> //deque #include <iomanip> #include <iostream> //cout,endl,cin #include <map> //map #include <math.h> #include <queue> //queue,priority_queue #include <set> //set #include <stack> //stack #include <string> //string,to_string,stoi #include <tuple> //tuple,make_tuple #include <unordered_map> //unordered_map #include <unordered_set> //unordered_set #include <utility> //pair,make_pair #include <vector> //vector using namespace std; typedef long long ll; /* int main() { ll a; double b; cin >> a >> b; cout << fixed << (ll)(floor(a * b)) << endl; } */ int main() { ll n; ll result = 1; int a = 0; // vector<int> vc; cin >> n; while (n--) { ll x; cin >> x; // result = result * x; if (x == 0 || result == 0) { a = 0; } else if (x > 1000000000000000000 / result) { a = 1; result = 1; } result = result * x; // cout << result << endl; // vc.push_back(x); } if (result > 1000000000000000000 || a == 1) { cout << -1 << endl; } else { cout << result << endl; } }
replace
44
45
44
45
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long LL; int main() { int N; cin >> N; LL out = 1; const LL MX = 1e18; bool ng = false; for (int i = 0; i < N; i++) { LL b; cin >> b; if (b == 0) { cout << 0 << endl; return 0; } if (MX / out < b) { ng = true; } out *= b; } if (ng) cout << -1 << endl; else cout << out << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long LL; int main() { int N; cin >> N; LL out = 1; const LL MX = 1e18; bool ng = false; for (int i = 0; i < N; i++) { LL b; cin >> b; if (b == 0) { cout << 0 << endl; return 0; } if (ng || MX / out < b) { ng = true; } out *= b; } if (ng) cout << -1 << endl; else cout << out << endl; return 0; }
replace
19
20
19
20
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; int main() { long long t, c = 1, p = 0, q = 0; cin >> t; while (t--) { long long x; cin >> x; if (x <= (1000000000000000000) / c) { c = c * x; } else { p = 1; } if (x == 0) { q = 1; } } if (p == 1 && q == 0) c = -1; cout << c << endl; return 0; }
#include <bits/stdc++.h> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; int main() { long long t, c = 1, p = 0, q = 0; cin >> t; while (t--) { long long x; cin >> x; if (c != 0 && x <= (1000000000000000000) / c) { c = c * x; } else { p = 1; } if (x == 0) { q = 1; } } if (p == 1 && q == 0) c = -1; cout << c << endl; return 0; }
replace
12
13
12
13
0
p02658
C++
Runtime Error
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define endl '\n' #define lfs cout << fixed << setprecision(10) #define ALL(a) (a).begin(), (a).end() #define ALLR(a) (a).rbegin(), (a).rend() #define spa << " " << #define fi first #define se second #define MP make_pair #define MT make_tuple #define PB push_back #define EB emplace_back #define rep(i, n, m) for (ll i = (n); i < (ll)(m); i++) #define rrep(i, n, m) for (ll i = (ll)(m)-1; i >= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9 + 7; const ll MOD9 = 998244353; const ll INF = 1e18; using P = pair<ll, ll>; template <typename T1, typename T2> bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true; } else return false; } template <typename T1, typename T2> bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true; } else return false; } ll median(ll a, ll b, ll c) { return a + b + c - max({a, b, c}) - min({a, b, c}); } void ans1(bool x) { if (x) cout << "Yes" << endl; else cout << "No" << endl; } void ans2(bool x) { if (x) cout << "YES" << endl; else cout << "NO" << endl; } void ans3(bool x) { if (x) cout << "Yay!" << endl; else cout << ":(" << endl; } template <typename T1, typename T2> void ans(bool x, T1 y, T2 z) { if (x) cout << y << endl; else cout << z << endl; } template <typename T> void debug(vector<vector<T>> &v, ll h, ll w) { for (ll i = 0; i < h; i++) { cout << v[i][0]; for (ll j = 1; j < w; j++) cout spa v[i][j]; cout << endl; } }; void debug(vector<string> &v, ll h, ll w) { for (ll i = 0; i < h; i++) { for (ll j = 0; j < w; j++) cout << v[i][j]; cout << endl; } }; template <typename T> void debug(vector<T> &v, ll n) { if (n != 0) cout << v[0]; for (ll i = 1; i < n; i++) cout spa v[i]; cout << endl; }; template <typename T> vector<vector<T>> vec(ll x, ll y, T w) { vector<vector<T>> v(x, vector<T>(y, w)); return v; } ll gcd(ll x, ll y) { ll r; while (y != 0 && (r = x % y) != 0) { x = y; y = r; } return y == 0 ? x : y; } vector<ll> dx = {1, -1, 0, 0, 1, 1, -1, -1}; vector<ll> dy = {0, 0, 1, -1, 1, -1, 1, -1}; template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << " " << p.second; } // mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); ll res = 0, buf = 0; bool judge = true; ll n; cin >> n; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; ll now = 1; rep(i, 0, n) { if (LLONG_MAX / a[i] <= now) judge = false; else now *= a[i]; } if (judge && now <= INF) cout << now << endl; else cout << -1 << endl; return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define endl '\n' #define lfs cout << fixed << setprecision(10) #define ALL(a) (a).begin(), (a).end() #define ALLR(a) (a).rbegin(), (a).rend() #define spa << " " << #define fi first #define se second #define MP make_pair #define MT make_tuple #define PB push_back #define EB emplace_back #define rep(i, n, m) for (ll i = (n); i < (ll)(m); i++) #define rrep(i, n, m) for (ll i = (ll)(m)-1; i >= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9 + 7; const ll MOD9 = 998244353; const ll INF = 1e18; using P = pair<ll, ll>; template <typename T1, typename T2> bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true; } else return false; } template <typename T1, typename T2> bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true; } else return false; } ll median(ll a, ll b, ll c) { return a + b + c - max({a, b, c}) - min({a, b, c}); } void ans1(bool x) { if (x) cout << "Yes" << endl; else cout << "No" << endl; } void ans2(bool x) { if (x) cout << "YES" << endl; else cout << "NO" << endl; } void ans3(bool x) { if (x) cout << "Yay!" << endl; else cout << ":(" << endl; } template <typename T1, typename T2> void ans(bool x, T1 y, T2 z) { if (x) cout << y << endl; else cout << z << endl; } template <typename T> void debug(vector<vector<T>> &v, ll h, ll w) { for (ll i = 0; i < h; i++) { cout << v[i][0]; for (ll j = 1; j < w; j++) cout spa v[i][j]; cout << endl; } }; void debug(vector<string> &v, ll h, ll w) { for (ll i = 0; i < h; i++) { for (ll j = 0; j < w; j++) cout << v[i][j]; cout << endl; } }; template <typename T> void debug(vector<T> &v, ll n) { if (n != 0) cout << v[0]; for (ll i = 1; i < n; i++) cout spa v[i]; cout << endl; }; template <typename T> vector<vector<T>> vec(ll x, ll y, T w) { vector<vector<T>> v(x, vector<T>(y, w)); return v; } ll gcd(ll x, ll y) { ll r; while (y != 0 && (r = x % y) != 0) { x = y; y = r; } return y == 0 ? x : y; } vector<ll> dx = {1, -1, 0, 0, 1, 1, -1, -1}; vector<ll> dy = {0, 0, 1, -1, 1, -1, 1, -1}; template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << " " << p.second; } // mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); ll res = 0, buf = 0; bool judge = true; ll n; cin >> n; vector<ll> a(n); rep(i, 0, n) cin >> a[i]; ll now = 1; rep(i, 0, n) { if (a[i] == 0) { cout << 0 << endl; return 0; } } rep(i, 0, n) { if (LLONG_MAX / a[i] <= now) judge = false; else now *= a[i]; } if (judge && now <= INF) cout << now << endl; else cout << -1 << endl; return 0; }
insert
124
124
124
130
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define nl "\n" #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define pb push_back #define pp pop_back #define bs binary_search #define pll pair<ll, ll> #define ppll pair<ll, pll> #define sll stack<ll> #define qll queue<ll> #define vll vector<ll> #define vpll vector<pll> #define vc vector<char> #define vvll vector<vector<ll>> #define all(x) x.begin(), x.end() #define loop(i, s, n) for (ll i = s; i < n; i++) #define test \ ll t; \ cin >> t; \ while (t--) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); ll mod = 1000000007; double pi = 3.1415926535; void solve() { ll n; cin >> n; ll ans = 1, d, flg = 0, p = 0; while (n--) { cin >> d; if (floor(1000000000000000000 / ans) < d) flg = 1; ans *= d; // cout<<ans<<nl; if (!d) p = 1; if (ans > 1000000000000000000 || ans < 0) { flg = 1; } } // ll k=1000000000000000000*; // cout<<k<<nl; if (p) cout << "0"; else if (flg) cout << "-1"; else cout << ans; } int main() { fast_io; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define nl "\n" #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define pb push_back #define pp pop_back #define bs binary_search #define pll pair<ll, ll> #define ppll pair<ll, pll> #define sll stack<ll> #define qll queue<ll> #define vll vector<ll> #define vpll vector<pll> #define vc vector<char> #define vvll vector<vector<ll>> #define all(x) x.begin(), x.end() #define loop(i, s, n) for (ll i = s; i < n; i++) #define test \ ll t; \ cin >> t; \ while (t--) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); ll mod = 1000000007; double pi = 3.1415926535; void solve() { ll n; cin >> n; ll ans = 1, d, flg = 0, p = 0; while (n--) { cin >> d; if (((double)1000000000000000000 / ans) < d) flg = 1; ans *= d; // cout<<ans<<nl; if (!d) p = 1; if (ans > 1000000000000000000 || ans < 0) { flg = 1; } } // ll k=1000000000000000000*; // cout<<k<<nl; if (p) cout << "0"; else if (flg) cout << "-1"; else cout << ans; } int main() { fast_io; solve(); return 0; }
replace
38
39
38
39
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define lvector vector<ll> #define cvector vector<char> #define svector vector<string> #define lque queue<ll> #define lpque priority_queue<ll> #define dlpque priority_queue<ll, lvector, greater<ll>> #define P pair<ll, ll> #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define rep(i, n) for (ll i = 0; i < n; ++i) #define print(a) cout << (a) << endl int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, ans = 1, m = 1e18; cin >> n; lvector A(n); rep(i, n) cin >> A[i]; sort(ALL(A)); for (ll i : A) { if (ans > m / i) { ans = -1; break; } ans *= i; } print(ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define lvector vector<ll> #define cvector vector<char> #define svector vector<string> #define lque queue<ll> #define lpque priority_queue<ll> #define dlpque priority_queue<ll, lvector, greater<ll>> #define P pair<ll, ll> #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define rep(i, n) for (ll i = 0; i < n; ++i) #define print(a) cout << (a) << endl int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, ans = 1, m = 1e18; cin >> n; lvector A(n); rep(i, n) cin >> A[i]; sort(ALL(A)); for (ll i : A) { if (i != 0 && ans > m / i) { ans = -1; break; } ans *= i; } print(ans); return 0; }
replace
24
25
24
25
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #include <limits> #define ll long long #define F first #define S second #define pb push_back #define oo 1e18 #define endl '\n' #define si size() #define all(v) v.begin(), v.end() #define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define Matrix vector<vector<long long>> #define vi vector<int> #define vll vector<ll> #define vd vector<double> #define vs vector<string> using namespace std; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; const long double Pi = acos(-1), e = 2.718; const ll N = 1e18, mod = 1e9 + 7; int main() { FASTIO; ll n; cin >> n; ll sum = 1; vll a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(all(a)); for (auto x : a) { if (x > N / sum) return cout << -1 << endl, 0; sum *= x; } cout << sum << endl; return 0; } /** */
#include <bits/stdc++.h> #include <limits> #define ll long long #define F first #define S second #define pb push_back #define oo 1e18 #define endl '\n' #define si size() #define all(v) v.begin(), v.end() #define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define Matrix vector<vector<long long>> #define vi vector<int> #define vll vector<ll> #define vd vector<double> #define vs vector<string> using namespace std; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; const long double Pi = acos(-1), e = 2.718; const ll N = 1e18, mod = 1e9 + 7; int main() { FASTIO; ll n; cin >> n; ll sum = 1; vll a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(all(a)); if (a[0] == 0) return cout << 0 << endl, 0; for (auto x : a) { if (x > N / sum) return cout << -1 << endl, 0; sum *= x; } cout << sum << endl; return 0; } /** */
insert
35
35
35
37
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; const int INF = 1 << 30; const ll LLINF = 1LL << 62; int mod = 1000000007; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; ll st = 1; ll lim = 1000000000000000000ll; ll A[N]; rep(i, N) cin >> A[i]; sort(A, A + N); rep(i, N) { ll a; a = A[i]; if (st > lim / a) { cout << -1 << endl; return 0; } st *= a; } cout << st << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; const int INF = 1 << 30; const ll LLINF = 1LL << 62; int mod = 1000000007; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; ll st = 1; ll lim = 1000000000000000000ll; ll A[N]; rep(i, N) cin >> A[i]; sort(A, A + N); rep(i, N) { ll a; a = A[i]; if (a == 0) { st = 0; continue; } if (st > lim / a) { cout << -1 << endl; return 0; } st *= a; } cout << st << endl; return 0; }
insert
25
25
25
29
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define go ios::sync_with_stdio(0) ll inf = 1e18; bool zero, over; int main() { go; int n; cin >> n; ll x; cin >> x; if (!x) zero = 1; for (int i = 0; i < n - 1; i++) { ll y; cin >> y; if (!y) zero = 1; if (inf / x < y) { over = 1; continue; } x *= y; } if (zero) cout << 0; else if (over) cout << -1; else cout << x; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define go ios::sync_with_stdio(0) ll inf = 1e18; bool zero, over; int main() { go; int n; cin >> n; ll x; cin >> x; if (!x) zero = 1; for (int i = 0; i < n - 1; i++) { ll y; cin >> y; if (!y) zero = 1; if (inf / x < y) { over = 1; continue; } if (over) continue; if (zero) continue; x *= y; } if (zero) cout << 0; else if (over) cout << -1; else cout << x; return 0; }
insert
24
24
24
28
0
p02658
C++
Runtime Error
#include <iostream> using namespace std; long long MAX = 1e18; int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int N; cin >> N; long long A[N]; long long sum = 1; bool overflow = false; bool hasZero = false; for (int i = 0; i < N; i++) { cin >> A[i]; if (A[i] == 0) hasZero = true; if (A[i] > MAX / sum) { overflow = true; } else { sum *= A[i]; } // if(overflow) break; } if (hasZero) { cout << "0\n"; } else if (overflow) { cout << "-1\n"; } else { cout << sum << endl; } return 0; }
#include <iostream> using namespace std; long long MAX = 1e18; int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int N; cin >> N; long long A[N]; long long sum = 1; bool overflow = false; bool hasZero = false; for (int i = 0; i < N; i++) { cin >> A[i]; if (A[i] == 0) hasZero = true; if (!overflow && A[i] > MAX / sum) { overflow = true; } else { sum *= A[i]; } // if(overflow) break; } if (hasZero) { cout << "0\n"; } else if (overflow) { cout << "-1\n"; } else { cout << sum << endl; } return 0; }
replace
23
24
23
24
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const double INF = 1e18; const int inf = 1e9; double pi = 3.14159265359; #define rep(i, a, b) for (int i = a; i < b; i++) #define per(i, b, a) for (int i = a - 1; i >= b; i--) using Graph = vector<vector<int>>; using pint = pair<int, int>; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; int main() { int n; cin >> n; ll a[n]; rep(i, 0, n) { cin >> a[i]; if (a[i] == 0) { cout << 0 << "\n"; return 0; } } ll ans = 1; rep(i, 0, n) { if (1 > 1000000000000000000 / (ans * a[i])) { cout << -1 << "\n"; return 0; } ans *= a[i]; } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const double INF = 1e18; const int inf = 1e9; double pi = 3.14159265359; #define rep(i, a, b) for (int i = a; i < b; i++) #define per(i, b, a) for (int i = a - 1; i >= b; i--) using Graph = vector<vector<int>>; using pint = pair<int, int>; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; int main() { int n; cin >> n; ll a[n]; rep(i, 0, n) { cin >> a[i]; if (a[i] == 0) { cout << 0 << "\n"; return 0; } } ll ans = 1; rep(i, 0, n) { if (a[i] > 1000000000000000000 / ans) { cout << -1 << "\n"; return 0; } ans *= a[i]; } cout << ans << "\n"; }
replace
26
27
26
27
0
p02658
C++
Time Limit Exceeded
#include <algorithm> #include <iomanip> #include <iostream> #include <string> #include <unordered_map> #include <vector> using namespace std; const int base = 1000000000; const int base_digits = 9; struct bigint { vector<int> a; int sign; bigint() : sign(1) {} bigint(long long v) { *this = v; } bigint(const string &s) { read(s); } void operator=(const bigint &v) { sign = v.sign; a = v.a; } void operator=(long long v) { sign = 1; if (v < 0) sign = -1, v = -v; for (; v > 0; v = v / base) a.push_back(v % base); } bigint operator+(const bigint &v) const { if (sign == v.sign) { bigint res = v; for (int i = 0, carry = 0; i < (int)max(a.size(), v.a.size()) || carry; ++i) { if (i == (int)res.a.size()) res.a.push_back(0); res.a[i] += carry + (i < (int)a.size() ? a[i] : 0); carry = res.a[i] >= base; if (carry) res.a[i] -= base; } return res; } return *this - (-v); } bigint operator-(const bigint &v) const { if (sign == v.sign) { if (abs() >= v.abs()) { bigint res = *this; for (int i = 0, carry = 0; i < (int)v.a.size() || carry; ++i) { res.a[i] -= carry + (i < (int)v.a.size() ? v.a[i] : 0); carry = res.a[i] < 0; if (carry) res.a[i] += base; } res.trim(); return res; } return -(v - *this); } return *this + (-v); } void operator*=(int v) { if (v < 0) sign = -sign, v = -v; for (int i = 0, carry = 0; i < (int)a.size() || carry; ++i) { if (i == (int)a.size()) a.push_back(0); long long cur = a[i] * (long long)v + carry; carry = (int)(cur / base); a[i] = (int)(cur % base); // asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base)); } trim(); } bigint operator*(int v) const { bigint res = *this; res *= v; return res; } friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) { int norm = base / (b1.a.back() + 1); bigint a = a1.abs() * norm; bigint b = b1.abs() * norm; bigint q, r; q.a.resize(a.a.size()); for (int i = a.a.size() - 1; i >= 0; i--) { r *= base; r += a.a[i]; int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()]; int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1]; int d = ((long long)base * s1 + s2) / b.a.back(); r -= b * d; while (r < 0) r += b, --d; q.a[i] = d; } q.sign = a1.sign * b1.sign; r.sign = a1.sign; q.trim(); r.trim(); return make_pair(q, r / norm); } bigint operator/(const bigint &v) const { return divmod(*this, v).first; } bigint operator%(const bigint &v) const { return divmod(*this, v).second; } void operator/=(int v) { if (v < 0) sign = -sign, v = -v; for (int i = (int)a.size() - 1, rem = 0; i >= 0; --i) { long long cur = a[i] + rem * (long long)base; a[i] = (int)(cur / v); rem = (int)(cur % v); } trim(); } bigint operator/(int v) const { bigint res = *this; res /= v; return res; } int operator%(int v) const { if (v < 0) v = -v; int m = 0; for (int i = a.size() - 1; i >= 0; --i) m = (a[i] + m * (long long)base) % v; return m * sign; } void operator+=(const bigint &v) { *this = *this + v; } void operator-=(const bigint &v) { *this = *this - v; } void operator*=(const bigint &v) { *this = *this * v; } void operator/=(const bigint &v) { *this = *this / v; } bool operator<(const bigint &v) const { if (sign != v.sign) return sign < v.sign; if (a.size() != v.a.size()) return a.size() * sign < v.a.size() * v.sign; for (int i = a.size() - 1; i >= 0; i--) if (a[i] != v.a[i]) return a[i] * sign < v.a[i] * sign; return false; } bool operator>(const bigint &v) const { return v < *this; } bool operator<=(const bigint &v) const { return !(v < *this); } bool operator>=(const bigint &v) const { return !(*this < v); } bool operator==(const bigint &v) const { return !(*this < v) && !(v < *this); } bool operator!=(const bigint &v) const { return *this < v || v < *this; } void trim() { while (!a.empty() && !a.back()) a.pop_back(); if (a.empty()) sign = 1; } bool isZero() const { return a.empty() || (a.size() == 1 && !a[0]); } bigint operator-() const { bigint res = *this; res.sign = -sign; return res; } bigint abs() const { bigint res = *this; res.sign *= res.sign; return res; } long long longValue() const { long long res = 0; for (int i = a.size() - 1; i >= 0; i--) res = res * base + a[i]; return res * sign; } friend bigint gcd(const bigint &a, const bigint &b) { return b.isZero() ? a : gcd(b, a % b); } friend bigint lcm(const bigint &a, const bigint &b) { return a / gcd(a, b) * b; } void read(const string &s) { sign = 1; a.clear(); int pos = 0; while (pos < (int)s.size() && (s[pos] == '-' || s[pos] == '+')) { if (s[pos] == '-') sign = -sign; ++pos; } for (int i = s.size() - 1; i >= pos; i -= base_digits) { int x = 0; for (int j = max(pos, i - base_digits + 1); j <= i; j++) x = x * 10 + s[j] - '0'; a.push_back(x); } trim(); } friend istream &operator>>(istream &stream, bigint &v) { string s; stream >> s; v.read(s); return stream; } friend ostream &operator<<(ostream &stream, const bigint &v) { if (v.sign == -1) stream << '-'; stream << (v.a.empty() ? 0 : v.a.back()); for (int i = (int)v.a.size() - 2; i >= 0; --i) stream << setw(base_digits) << setfill('0') << v.a[i]; return stream; } static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) { vector<long long> p(max(old_digits, new_digits) + 1); p[0] = 1; for (int i = 1; i < (int)p.size(); i++) p[i] = p[i - 1] * 10; vector<int> res; long long cur = 0; int cur_digits = 0; for (int i = 0; i < (int)a.size(); i++) { cur += a[i] * p[cur_digits]; cur_digits += old_digits; while (cur_digits >= new_digits) { res.push_back(int(cur % p[new_digits])); cur /= p[new_digits]; cur_digits -= new_digits; } } res.push_back((int)cur); while (!res.empty() && !res.back()) res.pop_back(); return res; } typedef vector<long long> vll; static vll karatsubaMultiply(const vll &a, const vll &b) { int n = a.size(); vll res(n + n); if (n <= 32) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) res[i + j] += a[i] * b[j]; return res; } int k = n >> 1; vll a1(a.begin(), a.begin() + k); vll a2(a.begin() + k, a.end()); vll b1(b.begin(), b.begin() + k); vll b2(b.begin() + k, b.end()); vll a1b1 = karatsubaMultiply(a1, b1); vll a2b2 = karatsubaMultiply(a2, b2); for (int i = 0; i < k; i++) a2[i] += a1[i]; for (int i = 0; i < k; i++) b2[i] += b1[i]; vll r = karatsubaMultiply(a2, b2); for (int i = 0; i < (int)a1b1.size(); i++) r[i] -= a1b1[i]; for (int i = 0; i < (int)a2b2.size(); i++) r[i] -= a2b2[i]; for (int i = 0; i < (int)r.size(); i++) res[i + k] += r[i]; for (int i = 0; i < (int)a1b1.size(); i++) res[i] += a1b1[i]; for (int i = 0; i < (int)a2b2.size(); i++) res[i + n] += a2b2[i]; return res; } bigint operator*(const bigint &v) const { vector<int> a6 = convert_base(this->a, base_digits, 6); vector<int> b6 = convert_base(v.a, base_digits, 6); vll a(a6.begin(), a6.end()); vll b(b6.begin(), b6.end()); while (a.size() < b.size()) a.push_back(0); while (b.size() < a.size()) b.push_back(0); while (a.size() & (a.size() - 1)) a.push_back(0), b.push_back(0); vll c = karatsubaMultiply(a, b); bigint res; res.sign = sign * v.sign; for (int i = 0, carry = 0; i < (int)c.size(); i++) { long long cur = c[i] + carry; res.a.push_back((int)(cur % 1000000)); carry = (int)(cur / 1000000); } res.a = convert_base(res.a, 6, base_digits); res.trim(); return res; } }; const long long M = 1000000000000000000; long long T; bool exceed = false; bigint ans; int main() { cin >> T; ans = 1; for (int i = 0; i < T; i++) { bigint temp; cin >> temp; ans = ans * temp; } if (ans <= M) { cout << ans << endl; } else { printf("-1\n"); } return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <string> #include <unordered_map> #include <vector> using namespace std; const int base = 1000000000; const int base_digits = 9; struct bigint { vector<int> a; int sign; bigint() : sign(1) {} bigint(long long v) { *this = v; } bigint(const string &s) { read(s); } void operator=(const bigint &v) { sign = v.sign; a = v.a; } void operator=(long long v) { sign = 1; if (v < 0) sign = -1, v = -v; for (; v > 0; v = v / base) a.push_back(v % base); } bigint operator+(const bigint &v) const { if (sign == v.sign) { bigint res = v; for (int i = 0, carry = 0; i < (int)max(a.size(), v.a.size()) || carry; ++i) { if (i == (int)res.a.size()) res.a.push_back(0); res.a[i] += carry + (i < (int)a.size() ? a[i] : 0); carry = res.a[i] >= base; if (carry) res.a[i] -= base; } return res; } return *this - (-v); } bigint operator-(const bigint &v) const { if (sign == v.sign) { if (abs() >= v.abs()) { bigint res = *this; for (int i = 0, carry = 0; i < (int)v.a.size() || carry; ++i) { res.a[i] -= carry + (i < (int)v.a.size() ? v.a[i] : 0); carry = res.a[i] < 0; if (carry) res.a[i] += base; } res.trim(); return res; } return -(v - *this); } return *this + (-v); } void operator*=(int v) { if (v < 0) sign = -sign, v = -v; for (int i = 0, carry = 0; i < (int)a.size() || carry; ++i) { if (i == (int)a.size()) a.push_back(0); long long cur = a[i] * (long long)v + carry; carry = (int)(cur / base); a[i] = (int)(cur % base); // asm("divl %%ecx" : "=a"(carry), "=d"(a[i]) : "A"(cur), "c"(base)); } trim(); } bigint operator*(int v) const { bigint res = *this; res *= v; return res; } friend pair<bigint, bigint> divmod(const bigint &a1, const bigint &b1) { int norm = base / (b1.a.back() + 1); bigint a = a1.abs() * norm; bigint b = b1.abs() * norm; bigint q, r; q.a.resize(a.a.size()); for (int i = a.a.size() - 1; i >= 0; i--) { r *= base; r += a.a[i]; int s1 = r.a.size() <= b.a.size() ? 0 : r.a[b.a.size()]; int s2 = r.a.size() <= b.a.size() - 1 ? 0 : r.a[b.a.size() - 1]; int d = ((long long)base * s1 + s2) / b.a.back(); r -= b * d; while (r < 0) r += b, --d; q.a[i] = d; } q.sign = a1.sign * b1.sign; r.sign = a1.sign; q.trim(); r.trim(); return make_pair(q, r / norm); } bigint operator/(const bigint &v) const { return divmod(*this, v).first; } bigint operator%(const bigint &v) const { return divmod(*this, v).second; } void operator/=(int v) { if (v < 0) sign = -sign, v = -v; for (int i = (int)a.size() - 1, rem = 0; i >= 0; --i) { long long cur = a[i] + rem * (long long)base; a[i] = (int)(cur / v); rem = (int)(cur % v); } trim(); } bigint operator/(int v) const { bigint res = *this; res /= v; return res; } int operator%(int v) const { if (v < 0) v = -v; int m = 0; for (int i = a.size() - 1; i >= 0; --i) m = (a[i] + m * (long long)base) % v; return m * sign; } void operator+=(const bigint &v) { *this = *this + v; } void operator-=(const bigint &v) { *this = *this - v; } void operator*=(const bigint &v) { *this = *this * v; } void operator/=(const bigint &v) { *this = *this / v; } bool operator<(const bigint &v) const { if (sign != v.sign) return sign < v.sign; if (a.size() != v.a.size()) return a.size() * sign < v.a.size() * v.sign; for (int i = a.size() - 1; i >= 0; i--) if (a[i] != v.a[i]) return a[i] * sign < v.a[i] * sign; return false; } bool operator>(const bigint &v) const { return v < *this; } bool operator<=(const bigint &v) const { return !(v < *this); } bool operator>=(const bigint &v) const { return !(*this < v); } bool operator==(const bigint &v) const { return !(*this < v) && !(v < *this); } bool operator!=(const bigint &v) const { return *this < v || v < *this; } void trim() { while (!a.empty() && !a.back()) a.pop_back(); if (a.empty()) sign = 1; } bool isZero() const { return a.empty() || (a.size() == 1 && !a[0]); } bigint operator-() const { bigint res = *this; res.sign = -sign; return res; } bigint abs() const { bigint res = *this; res.sign *= res.sign; return res; } long long longValue() const { long long res = 0; for (int i = a.size() - 1; i >= 0; i--) res = res * base + a[i]; return res * sign; } friend bigint gcd(const bigint &a, const bigint &b) { return b.isZero() ? a : gcd(b, a % b); } friend bigint lcm(const bigint &a, const bigint &b) { return a / gcd(a, b) * b; } void read(const string &s) { sign = 1; a.clear(); int pos = 0; while (pos < (int)s.size() && (s[pos] == '-' || s[pos] == '+')) { if (s[pos] == '-') sign = -sign; ++pos; } for (int i = s.size() - 1; i >= pos; i -= base_digits) { int x = 0; for (int j = max(pos, i - base_digits + 1); j <= i; j++) x = x * 10 + s[j] - '0'; a.push_back(x); } trim(); } friend istream &operator>>(istream &stream, bigint &v) { string s; stream >> s; v.read(s); return stream; } friend ostream &operator<<(ostream &stream, const bigint &v) { if (v.sign == -1) stream << '-'; stream << (v.a.empty() ? 0 : v.a.back()); for (int i = (int)v.a.size() - 2; i >= 0; --i) stream << setw(base_digits) << setfill('0') << v.a[i]; return stream; } static vector<int> convert_base(const vector<int> &a, int old_digits, int new_digits) { vector<long long> p(max(old_digits, new_digits) + 1); p[0] = 1; for (int i = 1; i < (int)p.size(); i++) p[i] = p[i - 1] * 10; vector<int> res; long long cur = 0; int cur_digits = 0; for (int i = 0; i < (int)a.size(); i++) { cur += a[i] * p[cur_digits]; cur_digits += old_digits; while (cur_digits >= new_digits) { res.push_back(int(cur % p[new_digits])); cur /= p[new_digits]; cur_digits -= new_digits; } } res.push_back((int)cur); while (!res.empty() && !res.back()) res.pop_back(); return res; } typedef vector<long long> vll; static vll karatsubaMultiply(const vll &a, const vll &b) { int n = a.size(); vll res(n + n); if (n <= 32) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) res[i + j] += a[i] * b[j]; return res; } int k = n >> 1; vll a1(a.begin(), a.begin() + k); vll a2(a.begin() + k, a.end()); vll b1(b.begin(), b.begin() + k); vll b2(b.begin() + k, b.end()); vll a1b1 = karatsubaMultiply(a1, b1); vll a2b2 = karatsubaMultiply(a2, b2); for (int i = 0; i < k; i++) a2[i] += a1[i]; for (int i = 0; i < k; i++) b2[i] += b1[i]; vll r = karatsubaMultiply(a2, b2); for (int i = 0; i < (int)a1b1.size(); i++) r[i] -= a1b1[i]; for (int i = 0; i < (int)a2b2.size(); i++) r[i] -= a2b2[i]; for (int i = 0; i < (int)r.size(); i++) res[i + k] += r[i]; for (int i = 0; i < (int)a1b1.size(); i++) res[i] += a1b1[i]; for (int i = 0; i < (int)a2b2.size(); i++) res[i + n] += a2b2[i]; return res; } bigint operator*(const bigint &v) const { vector<int> a6 = convert_base(this->a, base_digits, 6); vector<int> b6 = convert_base(v.a, base_digits, 6); vll a(a6.begin(), a6.end()); vll b(b6.begin(), b6.end()); while (a.size() < b.size()) a.push_back(0); while (b.size() < a.size()) b.push_back(0); while (a.size() & (a.size() - 1)) a.push_back(0), b.push_back(0); vll c = karatsubaMultiply(a, b); bigint res; res.sign = sign * v.sign; for (int i = 0, carry = 0; i < (int)c.size(); i++) { long long cur = c[i] + carry; res.a.push_back((int)(cur % 1000000)); carry = (int)(cur / 1000000); } res.a = convert_base(res.a, 6, base_digits); res.trim(); return res; } }; const long long M = 1000000000000000000; long long T; bool exceed = false; bigint ans; int main() { cin >> T; ans = 1; for (int i = 0; i < T; i++) { bigint temp; cin >> temp; if (ans == 0 || temp == 0) { // cout << "!" << endl; ans = ans * 0; // cout << ans << endl; } else if (ans <= M) { ans = ans * temp; } } // cout << ans << endl; if (ans <= M) { cout << ans << endl; } else { printf("-1\n"); } return 0; }
replace
340
342
340
349
TLE
p02658
C++
Runtime Error
// sppsfver - 05.08.2020 #include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; ll n, a, ans = 1; bool flag, zero; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (a == 0) return cout << 0 << endl, 0; flag |= (a <= (ll)(1e18) / ans); ans *= a; } cout << (flag ? -1 : ans) << endl; return 0; }
// sppsfver - 05.08.2020 #include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; ll n, a, ans = 1; bool flag, zero; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (a == 0) return cout << 0 << endl, 0; a <= (ll)(1e18) / ans ? ans *= a : flag = 1; } cout << (flag ? -1 : ans) << endl; return 0; }
replace
20
22
20
21
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // T+N // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") #define endl "\n" typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template <class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } const ll mod = 1000000000000000000ll; template <class T> inline void fix(T &x) { if (x >= mod || x <= -mod) { x %= mod; } if (x < 0) { x += mod; } } #define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl signed main() { // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, ans = 1; cin >> n; for (int i = 0; i < n; i++) { ll a; cin >> a; if (a == 0) { ans = 0; } else if (a > (2 * mod) / ans) { ans = 2 * mod; } else { ans *= a; } } if (ans > mod) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; // T+N // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") #define endl "\n" typedef long long ll; typedef long double ld; typedef unsigned long long ull; template <class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; } template <class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; } const ll mod = 1000000000000000000ll; template <class T> inline void fix(T &x) { if (x >= mod || x <= -mod) { x %= mod; } if (x < 0) { x += mod; } } #define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl signed main() { // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, ans = 1; cin >> n; for (int i = 0; i < n; i++) { ll a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } else if (a > (2 * mod) / ans) { ans = 2 * mod; } else { ans *= a; } } if (ans > mod) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }
replace
34
35
34
36
0
p02658
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define faster \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define f(i, a, b) for (ll i = a; i < b; i++) #define r(i, a, b) for (ll i = a; i > b; i--) using namespace std; typedef long long ll; typedef long double ld; const ll INF = 1000000000000000000; int main() { ll n; cin >> n; bool tr = false; ll ans = 1; f(i, 0, n) { ll a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if ((INF / ans < a) || tr) { tr = true; } ans *= a; } if (tr) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define faster \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define f(i, a, b) for (ll i = a; i < b; i++) #define r(i, a, b) for (ll i = a; i > b; i--) using namespace std; typedef long long ll; typedef long double ld; const ll INF = 1000000000000000000; int main() { ll n; cin >> n; bool tr = false; ll ans = 1; f(i, 0, n) { ll a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (tr || (INF / ans < a)) { tr = true; } ans *= a; } if (tr) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }
replace
37
38
37
38
0
p02658
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int a, over = 0; long long int total = 1; cin >> a; for (int k = 0; k < a; k++) { long long int b; cin >> b; if (total > 1000000000000000000ll / b) { over++; } else if (b == 0) { cout << 0; return 0; } else { total *= b; } } if (over > 0) { cout << -1; } else { cout << total; } }
#include <algorithm> #include <cmath> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int a, over = 0; long long int total = 1; cin >> a; for (int k = 0; k < a; k++) { long long int b; cin >> b; if (b != 0 && total > 1000000000000000000ll / b) { over++; } else if (b == 0) { cout << 0; return 0; } else { total *= b; } } if (over > 0) { cout << -1; } else { cout << total; } }
replace
14
15
14
15
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define lvector vector<ll> #define cvector vector<char> #define svector vector<string> #define lque queue<ll> #define lpque priority_queue<ll> #define dlpque priority_queue<ll, lvector, greater<ll>> #define P pair<ll, ll> #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define rep(i, n) for (ll i = 0; i < n; ++i) #define print(a) cout << (a) << endl int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, ans = 1, m = 1e18; cin >> n; lvector A(n); rep(i, n) cin >> A[i]; sort(ALL(A)); for (ll a : A) { if (ans > m / a) { ans = -1; break; } ans *= a; } print(ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define lvector vector<ll> #define cvector vector<char> #define svector vector<string> #define lque queue<ll> #define lpque priority_queue<ll> #define dlpque priority_queue<ll, lvector, greater<ll>> #define P pair<ll, ll> #define ALL(a) a.begin(), a.end() #define RALL(a) a.rbegin(), a.rend() #define rep(i, n) for (ll i = 0; i < n; ++i) #define print(a) cout << (a) << endl int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, ans = 1, m = 1e18; cin >> n; lvector A(n); rep(i, n) cin >> A[i]; sort(ALL(A)); for (ll a : A) { if (a > 0 && ans > m / a) { ans = -1; break; } ans *= a; } print(ans); return 0; }
replace
24
25
24
25
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> #define max 1000000 #define pb push_back #define pairs pair<int, int> #define vi vector<int> #define vb vector<bool> #define vii vector<pairs> #define lb lower_bound #define ub upper_bound #define lli long long int #define endl '\n' #define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL); #define Cases cout << "Case " << ++Case << ": "; #define __test \ int tt; \ int Case = 0; \ cin >> tt; \ while (tt--) #define read(x) freopen(x, "r", stdin) #define write(x) freopen(x, "w", stdout) #define InputArray(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define CopyArray(a, temp, n) \ for (int i = 0; i < n; i++) \ temp[i] = a[i]; #define PrintArray(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << " "; \ cout << endl; using namespace std; int main() { #ifdef Niloy read("input.txt"); write("output.txt"); #endif int n; cin >> n; long long arr[10010]; for (int i = 0; i < n; i++) { scanf("%lld", &arr[i]); } long long int mul = 1; for (int i = 0; i < n; i++) { if (arr[i] == 0) { printf("0\n"); return 0; } } for (int i = 0; i < n; i++) { if (arr[i] <= 1000000000000000000 / mul) { mul *= arr[i]; } else { printf("-1\n"); return 0; } } printf("%lld\n", mul); cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n'; return 0; }
#include <bits/stdc++.h> #define max 1000000 #define pb push_back #define pairs pair<int, int> #define vi vector<int> #define vb vector<bool> #define vii vector<pairs> #define lb lower_bound #define ub upper_bound #define lli long long int #define endl '\n' #define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL); #define Cases cout << "Case " << ++Case << ": "; #define __test \ int tt; \ int Case = 0; \ cin >> tt; \ while (tt--) #define read(x) freopen(x, "r", stdin) #define write(x) freopen(x, "w", stdout) #define InputArray(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define CopyArray(a, temp, n) \ for (int i = 0; i < n; i++) \ temp[i] = a[i]; #define PrintArray(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << " "; \ cout << endl; using namespace std; int main() { #ifdef Niloy read("input.txt"); write("output.txt"); #endif int n; cin >> n; long long arr[100010]; for (int i = 0; i < n; i++) { scanf("%lld", &arr[i]); } long long int mul = 1; for (int i = 0; i < n; i++) { if (arr[i] == 0) { printf("0\n"); return 0; } } for (int i = 0; i < n; i++) { if (arr[i] <= 1000000000000000000 / mul) { mul *= arr[i]; } else { printf("-1\n"); return 0; } } printf("%lld\n", mul); cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n'; return 0; }
replace
40
41
40
41
0
time = 0 sec
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb(x) push_back(x) #define mp(a, b) make_pair(a, b) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define lscan(x) scanf("%I64d", &x) #define lprint(x) printf("%I64d", x) ll gcd(ll a, ll b) { ll c = a % b; while (c != 0) { a = b; b = c; c = a % b; } return b; } long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } struct UnionFind { vector<ll> data; UnionFind(int sz) { data.assign(sz, -1); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int find(int k) { if (data[k] < 0) return (k); return (data[k] = find(data[k])); } ll size(int k) { return (-data[find(k)]); } }; ll M = 1000000007; vector<ll> fac(2000011); // n!(mod M) vector<ll> ifac(2000011); // k!^{M-2} (mod M) ll mpow(ll x, ll n) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % M; x = x * x % M; n = n >> 1; } return ans; } ll mpow2(ll x, ll n, ll mod) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % mod; x = x * x % mod; n = n >> 1; } return ans; } void setcomb() { fac[0] = 1; ifac[0] = 1; for (ll i = 0; i < 2000010; i++) { fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M) } ifac[2000010] = mpow(fac[2000010], M - 2); for (ll i = 2000010; i > 0; i--) { ifac[i - 1] = ifac[i] * i % M; } } ll comb(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } ll perm(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; return fac[a] * ifac[a - b] % M; } long long modinv(long long a) { long long b = M, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= M; if (u < 0) u += M; return u; } ll modinv2(ll a, ll mod) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) { int i, j, k, t; vector<vector<ll>> c(n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { t = 0; for (k = 0; k < n; k++) t = (t + a[i][k] * b[k][j] % M) % M; c[i].push_back(t); } } return c; } template <typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } template <typename C> int find_subtree(int a, const C &check, Monoid &M, bool type) { while (a < sz) { Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]); if (check(nxt)) a = 2 * a + type; else M = nxt, a = 2 * a + 1 - type; } return a - sz; } template <typename C> int find_first(int a, const C &check) { Monoid L = M1; if (a <= 0) { if (check(f(L, seg[1]))) return find_subtree(1, check, L, false); return -1; } int b = sz; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) { Monoid nxt = f(L, seg[a]); if (check(nxt)) return find_subtree(a, check, L, false); L = nxt; ++a; } } return -1; } template <typename C> int find_last(int b, const C &check) { Monoid R = M1; if (b >= sz) { if (check(f(seg[1], R))) return find_subtree(1, check, R, true); return -1; } int a = sz; for (b += sz; a < b; a >>= 1, b >>= 1) { if (b & 1) { Monoid nxt = f(seg[--b], R); if (check(nxt)) return find_subtree(b, check, R, true); R = nxt; } } return -1; } }; template <unsigned mod> struct RollingHash { vector<unsigned> hashed, power; inline unsigned mul(unsigned a, unsigned b) const { unsigned long long x = (unsigned long long)a * b; unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m; asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod)); return m; } RollingHash(const string &s, unsigned base = 10007) { int sz = (int)s.size(); hashed.assign(sz + 1, 0); power.assign(sz + 1, 0); power[0] = 1; for (int i = 0; i < sz; i++) { power[i + 1] = mul(power[i], base); hashed[i + 1] = mul(hashed[i], base) + s[i]; if (hashed[i + 1] >= mod) hashed[i + 1] -= mod; } } unsigned get(int l, int r) const { unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]); if (ret >= mod) ret -= mod; return ret; } unsigned connect(unsigned h1, int h2, int h2len) const { unsigned ret = mul(h1, power[h2len]) + h2; if (ret >= mod) ret -= mod; return ret; } int LCP(const RollingHash<mod> &b, int l1, int r1, int l2, int r2) { int len = min(r1 - l1, r2 - l2); int low = -1, high = len + 1; while (high - low > 1) { int mid = (low + high) / 2; if (get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid; else high = mid; } return (low); } }; using RH = RollingHash<1000000007>; template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; template <typename G> struct DoublingLowestCommonAncestor { const int LOG; vector<int> dep; const G &g; vector<vector<int>> table; DoublingLowestCommonAncestor(const G &g) : g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size())) { table.assign(LOG, vector<int>(g.size(), -1)); } void dfs(int idx, int par, int d) { table[0][idx] = par; dep[idx] = d; for (auto &to : g[idx]) { if (to != par) dfs(to, idx, d + 1); } } void build() { dfs(0, -1, 0); for (int k = 0; k + 1 < LOG; k++) { for (int i = 0; i < table[k].size(); i++) { if (table[k][i] == -1) table[k + 1][i] = -1; else table[k + 1][i] = table[k][table[k][i]]; } } } int query(int u, int v) { if (dep[u] > dep[v]) swap(u, v); for (int i = LOG - 1; i >= 0; i--) { if (((dep[v] - dep[u]) >> i) & 1) v = table[i][v]; } if (u == v) return u; for (int i = LOG - 1; i >= 0; i--) { if (table[i][u] != table[i][v]) { u = table[i][u]; v = table[i][v]; } } return table[0][u]; } }; int main() { ll n, i, a[111111]; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; ll k = 1; for (i = 0; i < n; i++) k *= a[i]; if (k > 1000000000000000000) { cout << "-1" << endl; return 0; } for (i = 0; i < n; i++) k /= a[i]; if (k == 1) { ll ans = 1; for (i = 0; i < n; i++) ans *= a[i]; cout << ans << endl; } else cout << "-1" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb(x) push_back(x) #define mp(a, b) make_pair(a, b) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define lscan(x) scanf("%I64d", &x) #define lprint(x) printf("%I64d", x) ll gcd(ll a, ll b) { ll c = a % b; while (c != 0) { a = b; b = c; c = a % b; } return b; } long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } struct UnionFind { vector<ll> data; UnionFind(int sz) { data.assign(sz, -1); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int find(int k) { if (data[k] < 0) return (k); return (data[k] = find(data[k])); } ll size(int k) { return (-data[find(k)]); } }; ll M = 1000000007; vector<ll> fac(2000011); // n!(mod M) vector<ll> ifac(2000011); // k!^{M-2} (mod M) ll mpow(ll x, ll n) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % M; x = x * x % M; n = n >> 1; } return ans; } ll mpow2(ll x, ll n, ll mod) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % mod; x = x * x % mod; n = n >> 1; } return ans; } void setcomb() { fac[0] = 1; ifac[0] = 1; for (ll i = 0; i < 2000010; i++) { fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M) } ifac[2000010] = mpow(fac[2000010], M - 2); for (ll i = 2000010; i > 0; i--) { ifac[i - 1] = ifac[i] * i % M; } } ll comb(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } ll perm(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; return fac[a] * ifac[a - b] % M; } long long modinv(long long a) { long long b = M, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= M; if (u < 0) u += M; return u; } ll modinv2(ll a, ll mod) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) { int i, j, k, t; vector<vector<ll>> c(n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { t = 0; for (k = 0; k < n; k++) t = (t + a[i][k] * b[k][j] % M) % M; c[i].push_back(t); } } return c; } template <typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } template <typename C> int find_subtree(int a, const C &check, Monoid &M, bool type) { while (a < sz) { Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]); if (check(nxt)) a = 2 * a + type; else M = nxt, a = 2 * a + 1 - type; } return a - sz; } template <typename C> int find_first(int a, const C &check) { Monoid L = M1; if (a <= 0) { if (check(f(L, seg[1]))) return find_subtree(1, check, L, false); return -1; } int b = sz; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) { Monoid nxt = f(L, seg[a]); if (check(nxt)) return find_subtree(a, check, L, false); L = nxt; ++a; } } return -1; } template <typename C> int find_last(int b, const C &check) { Monoid R = M1; if (b >= sz) { if (check(f(seg[1], R))) return find_subtree(1, check, R, true); return -1; } int a = sz; for (b += sz; a < b; a >>= 1, b >>= 1) { if (b & 1) { Monoid nxt = f(seg[--b], R); if (check(nxt)) return find_subtree(b, check, R, true); R = nxt; } } return -1; } }; template <unsigned mod> struct RollingHash { vector<unsigned> hashed, power; inline unsigned mul(unsigned a, unsigned b) const { unsigned long long x = (unsigned long long)a * b; unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m; asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod)); return m; } RollingHash(const string &s, unsigned base = 10007) { int sz = (int)s.size(); hashed.assign(sz + 1, 0); power.assign(sz + 1, 0); power[0] = 1; for (int i = 0; i < sz; i++) { power[i + 1] = mul(power[i], base); hashed[i + 1] = mul(hashed[i], base) + s[i]; if (hashed[i + 1] >= mod) hashed[i + 1] -= mod; } } unsigned get(int l, int r) const { unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]); if (ret >= mod) ret -= mod; return ret; } unsigned connect(unsigned h1, int h2, int h2len) const { unsigned ret = mul(h1, power[h2len]) + h2; if (ret >= mod) ret -= mod; return ret; } int LCP(const RollingHash<mod> &b, int l1, int r1, int l2, int r2) { int len = min(r1 - l1, r2 - l2); int low = -1, high = len + 1; while (high - low > 1) { int mid = (low + high) / 2; if (get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid; else high = mid; } return (low); } }; using RH = RollingHash<1000000007>; template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; template <typename G> struct DoublingLowestCommonAncestor { const int LOG; vector<int> dep; const G &g; vector<vector<int>> table; DoublingLowestCommonAncestor(const G &g) : g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size())) { table.assign(LOG, vector<int>(g.size(), -1)); } void dfs(int idx, int par, int d) { table[0][idx] = par; dep[idx] = d; for (auto &to : g[idx]) { if (to != par) dfs(to, idx, d + 1); } } void build() { dfs(0, -1, 0); for (int k = 0; k + 1 < LOG; k++) { for (int i = 0; i < table[k].size(); i++) { if (table[k][i] == -1) table[k + 1][i] = -1; else table[k + 1][i] = table[k][table[k][i]]; } } } int query(int u, int v) { if (dep[u] > dep[v]) swap(u, v); for (int i = LOG - 1; i >= 0; i--) { if (((dep[v] - dep[u]) >> i) & 1) v = table[i][v]; } if (u == v) return u; for (int i = LOG - 1; i >= 0; i--) { if (table[i][u] != table[i][v]) { u = table[i][u]; v = table[i][v]; } } return table[0][u]; } }; int main() { ll n, i, a[111111]; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) { if (a[i] == 0) { cout << "0" << endl; return 0; } } ll k = 1; for (i = 0; i < n; i++) k *= a[i]; if (k > 1000000000000000000) { cout << "-1" << endl; return 0; } for (i = 0; i < n; i++) k /= a[i]; if (k == 1) { ll ans = 1; for (i = 0; i < n; i++) ans *= a[i]; cout << ans << endl; } else cout << "-1" << endl; }
insert
374
374
374
380
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define fo(i, n) for (i = 0; i < n; i++) #define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) #define ll long long #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; void myInit(); int mpow(int base, int exp); void ipgraph(int m); void dfs(int u, int par); const int MOD = 1000000007; const int N = 3e5, M = N; //=========TQR============== vi g[N]; int a[N]; int main() { myInit(); FIO; int n, i; unsigned ll ans = 1; bool neg = false; cin >> n; fo(i, n) { unsigned ll x, tmp; cin >> x; if (x == 0) { ans = 0; neg = false; } tmp = 1000000000000000000 / ans; // deb(tmp); if (tmp > x) neg = true; else if (!neg) ans *= x; } if (neg) cout << "-1\n"; else cout << ans << endl; return 0; } void myInit() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int mpow(int base, int exp) { base %= MOD; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % MOD; base = ((ll)base * base) % MOD; exp >>= 1; } return result; } void ipgraph(int n, int m) { int i, u, v; while (m--) { cin >> u >> v; g[u - 1].pb(v - 1); g[v - 1].pb(u - 1); } } void dfs(int u, int par) { for (int v : g[u]) { if (v == par) continue; dfs(v, u); } }
#include <bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define fo(i, n) for (i = 0; i < n; i++) #define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) #define ll long long #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; void myInit(); int mpow(int base, int exp); void ipgraph(int m); void dfs(int u, int par); const int MOD = 1000000007; const int N = 3e5, M = N; //=========TQR============== vi g[N]; int a[N]; int main() { myInit(); FIO; int n, i; unsigned ll ans = 1; bool neg = false; cin >> n; fo(i, n) { unsigned ll x, tmp; cin >> x; if (x == 0) { ans = 0; neg = false; } if (ans > 0) { tmp = 1000000000000000000 / ans; if (tmp < x) neg = true; else if (!neg) ans *= x; } // deb2(ans, tmp); } if (neg) cout << "-1\n"; else cout << ans << endl; return 0; } void myInit() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int mpow(int base, int exp) { base %= MOD; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % MOD; base = ((ll)base * base) % MOD; exp >>= 1; } return result; } void ipgraph(int n, int m) { int i, u, v; while (m--) { cin >> u >> v; g[u - 1].pb(v - 1); g[v - 1].pb(u - 1); } } void dfs(int u, int par) { for (int v : g[u]) { if (v == par) continue; dfs(v, u); } }
replace
53
59
53
61
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll mod = 1000000007; double pi = 3.14159265358979; ll r(ll x, ll y) { if (y == 0) return 1; else if (y % 2 == 0) return r(x, y / 2) * r(x, y / 2) % mod; else return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod; } int main() { ll n; cin >> n; ll sum = 1; bool f = 1; ll p = 1000000000000000000; for (int i = 0; i < n; i++) { ll a; cin >> a; if (a == 0) { sum = 0; } else if (p / sum < a) { f = 0; } else sum = sum * a; } if (f || sum == 0) printf("%lld\n", sum); else cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll mod = 1000000007; double pi = 3.14159265358979; ll r(ll x, ll y) { if (y == 0) return 1; else if (y % 2 == 0) return r(x, y / 2) * r(x, y / 2) % mod; else return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod; } int main() { ll n; cin >> n; ll sum = 1; bool f = 1; ll p = 1000000000000000000; for (int i = 0; i < n; i++) { ll a; cin >> a; if (a == 0) { sum = 0; } else if (p / a < sum) { f = 0; } else sum = sum * a; } if (f || sum == 0) printf("%lld\n", sum); else cout << -1 << endl; }
replace
26
27
26
27
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; ll tmp, res = 1, max = 1000000000000000000; cin >> n; bool ng = false; for (int i = 0; i < n; ++i) { cin >> tmp; if (tmp == 0) { cout << 0 << "\n"; return 0; } if (tmp > max / res) { ng = true; } res *= tmp; } cout << (ng ? -1 : res) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n; ll tmp, res = 1, max = 1000000000000000000; cin >> n; bool ng = false; for (int i = 0; i < n; ++i) { cin >> tmp; if (tmp == 0) { cout << 0 << "\n"; return 0; } if (ng || tmp > max / res || res * tmp > max) { ng = true; } res *= tmp; } cout << (ng ? -1 : res) << "\n"; return 0; }
replace
16
17
16
17
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; const ll MX = 1e18; int main() { int n; cin >> n; vector<int> vec(n); ll ans = 1; bool flag = 0; rep(i, n) { ll a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (a > MX / ans || MX < ans * a) { flag = 1; } ans *= a; } if (flag) { cout << -1 << endl; return 0; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; const ll MX = 1e18; int main() { int n; cin >> n; vector<int> vec(n); ll ans = 1; bool flag = 0; rep(i, n) { ll a; cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (a > MX / ans || MX < ans * a) { flag = 1; continue; } ans *= a; } if (flag) { cout << -1 << endl; return 0; } cout << ans << endl; return 0; }
insert
24
24
24
25
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define se second #define fi first #define ll long long #define ld long double #define pll pair<ll, ll> #define plll pair<ll, pll> #define ppll pair<pll, pll> #define pii pair<int, int> #define pb push_back const ll inf = 2e18 + 7; const ll mod = 1e9 + 7; const ll N = 1e6 + 7; const ld pi = 3.14159265358979; void solve() { ll n; cin >> n; vector<ll> arr(n); ll pro = 1; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr.begin(), arr.end()); for (int i = 0; i < n; i++) { if (((ll)(1e18) / pro) < arr[i]) { cout << "-1"; return; } pro = pro * arr[i]; } cout << pro; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t = 1; // cin>>t; while (t--) { solve(); // cout<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define se second #define fi first #define ll long long #define ld long double #define pll pair<ll, ll> #define plll pair<ll, pll> #define ppll pair<pll, pll> #define pii pair<int, int> #define pb push_back const ll inf = 2e18 + 7; const ll mod = 1e9 + 7; const ll N = 1e6 + 7; const ld pi = 3.14159265358979; void solve() { ll n; cin >> n; vector<ll> arr(n); ll pro = 1; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr.begin(), arr.end()); for (int i = 0; i < n; i++) { if (pro == 0) { cout << "0"; return; } if (((ll)(1e18) / pro) < arr[i]) { cout << "-1"; return; } pro = pro * arr[i]; } cout << pro; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; t = 1; // cin>>t; while (t--) { solve(); // cout<<"\n"; } return 0; }
insert
26
26
26
30
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define endl "\n"; #define int long long #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0) #define double long double #define M_PI 3.14159265358979323846 const int mod = 1e9 + 7; int32_t main() { fastio; int n; cin >> n; bool flag = true, zero = false; int ans = 1, maxi = 1e18; for (int i = 0; i < n; i++) { int x; cin >> x; if (x > maxi / ans) { flag = false; } else { ans *= x; } if (x == 0) zero = true; } if (zero) flag = true; cout << (flag ? ans : -1) << endl; return 0; } /* */
#include <bits/stdc++.h> using namespace std; #define endl "\n"; #define int long long #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0) #define double long double #define M_PI 3.14159265358979323846 const int mod = 1e9 + 7; int32_t main() { fastio; int n; cin >> n; bool flag = true, zero = false; int ans = 1, maxi = 1e18; for (int i = 0; i < n; i++) { int x; cin >> x; if (ans != 0 && x > maxi / ans) { flag = false; } else { ans *= x; } if (x == 0) zero = true; } if (zero) flag = true; cout << (flag ? ans : -1) << endl; return 0; } /* */
replace
21
22
21
22
0
p02658
C++
Time Limit Exceeded
// Zory-2020 #include <bits/stdc++.h> using namespace std; typedef long long ll; // typedef __int128 ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define FR first #define SE second #define MP make_pair #define PB push_back #define vc vector #define db double #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define bin(x) (1ll << (x)) #define full(x) (bin((x) + 1) - 1) #define fo(i, l, r) for (int i = (l), I = (r); i <= I; i++) #define fd(i, r, l) for (int i = (r), I = (l); i >= I; i--) #define mem(x, val) memset(x, val, sizeof x) #define Swap(a, b, n) \ for (int I = 0; I <= n; I++) \ swap(a[I], b[I]) #define PC __builtin_popcountll #ifdef DEBUG #define debug(A, args...) fprintf(stderr, A, ##args) #else #define debug(A, args...) printf("") #endif #define deb debug("line %d\n", __LINE__) namespace mine { ll qread() { ll ans = 0, f = 1; char c = getchar(); while (c < '0' or c > '9') { if (c == '-') f = -1; c = getchar(); } while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar(); return ans * f; } void write(ll num) { if (num < 0) putchar('-'), num = -num; if (num >= 10) write(num / 10); putchar('0' + num % 10); } void write1(ll num) { write(num); putchar(' '); } void write2(ll num) { write(num); putchar('\n'); } template <typename T> inline bool chmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <typename T> inline bool chmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } bool IN(ll x, ll l, ll r) { return l <= x and x <= r; } void GG() { puts("-1"); exit(0); } const db eps = 1e-8; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int mm(const int x) { return x >= MOD ? x - MOD : x; } template <typename T> void add(T &x, const int &y) { x = (x + y >= MOD ? x + y - MOD : x + y); } ll qpower(ll x, ll e, int mod = MOD) { ll ans = 1; while (e) { if (e & 1) ans = ans * x % mod; x = x * x % mod; e >>= 1; } return ans; } ll invm(ll x) { return qpower(x, MOD - 2); } const int MM = 3e6 + 10; ll fac[MM], facinv[MM], Inv[MM]; ll Comb(int n, int m) { return n < 0 or m < 0 or n < m ? 0 : fac[n] * facinv[m] % MOD * facinv[n - m] % MOD; } void PRE() { fac[0] = 1; fo(i, 1, MM - 1) fac[i] = fac[i - 1] * i % MOD; facinv[MM - 1] = invm(fac[MM - 1]); fd(i, MM - 1, 1) facinv[i - 1] = facinv[i] * i % MOD; Inv[1] = 1; fo(i, 2, MM - 1) Inv[i] = (MOD - MOD / i) * Inv[MOD % i] % MOD; } const int N = 1e5 + 10; //------------------FIXED------------------ ll a[N]; void main() { ll S = 1; int n = qread(); int cnt = 0; fo(i, 1, n) a[i] = qread(), cnt += (a[i] == 0); if (cnt) { write(0); return; } fo(i, 1, n) { ll now = qread(); if (now > (ll)1e18 / S) GG(); S *= now; } write(S); } }; // namespace mine signed main() { #ifdef DEBUG // freopen("a.in","r",stdin); freopen("z.txt", "r", stdin); // freopen("a.out","w",stdout); #endif srand(time(0)); mine::main(); debug("\n------------------------------------------\nTime: %.2lf s\n", 1.0 * clock() / CLOCKS_PER_SEC); }
// Zory-2020 #include <bits/stdc++.h> using namespace std; typedef long long ll; // typedef __int128 ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define FR first #define SE second #define MP make_pair #define PB push_back #define vc vector #define db double #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define bin(x) (1ll << (x)) #define full(x) (bin((x) + 1) - 1) #define fo(i, l, r) for (int i = (l), I = (r); i <= I; i++) #define fd(i, r, l) for (int i = (r), I = (l); i >= I; i--) #define mem(x, val) memset(x, val, sizeof x) #define Swap(a, b, n) \ for (int I = 0; I <= n; I++) \ swap(a[I], b[I]) #define PC __builtin_popcountll #ifdef DEBUG #define debug(A, args...) fprintf(stderr, A, ##args) #else #define debug(A, args...) printf("") #endif #define deb debug("line %d\n", __LINE__) namespace mine { ll qread() { ll ans = 0, f = 1; char c = getchar(); while (c < '0' or c > '9') { if (c == '-') f = -1; c = getchar(); } while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar(); return ans * f; } void write(ll num) { if (num < 0) putchar('-'), num = -num; if (num >= 10) write(num / 10); putchar('0' + num % 10); } void write1(ll num) { write(num); putchar(' '); } void write2(ll num) { write(num); putchar('\n'); } template <typename T> inline bool chmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <typename T> inline bool chmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } bool IN(ll x, ll l, ll r) { return l <= x and x <= r; } void GG() { puts("-1"); exit(0); } const db eps = 1e-8; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int mm(const int x) { return x >= MOD ? x - MOD : x; } template <typename T> void add(T &x, const int &y) { x = (x + y >= MOD ? x + y - MOD : x + y); } ll qpower(ll x, ll e, int mod = MOD) { ll ans = 1; while (e) { if (e & 1) ans = ans * x % mod; x = x * x % mod; e >>= 1; } return ans; } ll invm(ll x) { return qpower(x, MOD - 2); } const int MM = 3e6 + 10; ll fac[MM], facinv[MM], Inv[MM]; ll Comb(int n, int m) { return n < 0 or m < 0 or n < m ? 0 : fac[n] * facinv[m] % MOD * facinv[n - m] % MOD; } void PRE() { fac[0] = 1; fo(i, 1, MM - 1) fac[i] = fac[i - 1] * i % MOD; facinv[MM - 1] = invm(fac[MM - 1]); fd(i, MM - 1, 1) facinv[i - 1] = facinv[i] * i % MOD; Inv[1] = 1; fo(i, 2, MM - 1) Inv[i] = (MOD - MOD / i) * Inv[MOD % i] % MOD; } const int N = 1e5 + 10; //------------------FIXED------------------ ll a[N]; void main() { ll S = 1; int n = qread(); int cnt = 0; fo(i, 1, n) a[i] = qread(), cnt += (a[i] == 0); if (cnt) { write(0); return; } fo(i, 1, n) { ll now = a[i]; if (now > (ll)1e18 / S) GG(); S *= now; } write(S); } }; // namespace mine signed main() { #ifdef DEBUG // freopen("a.in","r",stdin); freopen("z.txt", "r", stdin); // freopen("a.out","w",stdout); #endif srand(time(0)); mine::main(); debug("\n------------------------------------------\nTime: %.2lf s\n", 1.0 * clock() / CLOCKS_PER_SEC); }
replace
118
119
118
119
TLE
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int m = 1; bool q = false; for (int x = 1; x <= n; ++x) { long long int v; cin >> v; if (v <= 1000000000000000000 / m) { m *= v; } else { q = true; } } if (q && m != 0) { m = -1; } cout << m << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long int m = 1; bool q = false; for (int x = 1; x <= n; ++x) { long long int v; cin >> v; if (v <= 1000000000000000000 / m) { m *= v; } else { q = true; } if (m == 0) { break; } } if (q && m != 0) { m = -1; } cout << m << endl; return 0; }
insert
15
15
15
18
0
p02658
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <ctime> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(a) a.begin(), a.end() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; int main() { int N; cin >> N; ll ans = 1, a; ll inf = 1e18; bool f = false; rep(i, N) { cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (a > inf / ans) { f = true; } ans *= a; } if (f) { cout << -1 << endl; return 0; } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <ctime> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(a) a.begin(), a.end() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; int main() { int N; cin >> N; ll ans = 1, a; ll inf = 1e18; bool f = false; rep(i, N) { cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (ans > inf / a) { f = true; } ans *= a; } if (f) { cout << -1 << endl; return 0; } cout << ans << endl; return 0; }
replace
35
36
35
36
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unsigned long long ans = 1; vector<unsigned long long> data(n); for (int i = 0; i < n; i++) { cin >> data.at(i); } sort(data.begin(), data.end()); for (int i = 0; i < n; i++) { if (data.at(i) > 1000000000000000000 / ans) { cout << -1; return 0; } ans *= data.at(i); } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; unsigned long long ans = 1; vector<unsigned long long> data(n); for (int i = 0; i < n; i++) { cin >> data.at(i); } sort(data.begin(), data.end()); for (int i = 0; i < n; i++) { if (data.at(i) > 1000000000000000000 / ans) { cout << -1; return 0; } ans *= data.at(i); if (ans == 0) { cout << 0; return 0; } } cout << ans; }
insert
19
19
19
23
0
p02658
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; using ll = long long; using ld = long double; const ld pi = 3.141592653589793; #ifdef EBUG #define debug(x) cout << "\033[31m" << #x << ": " << x << "\033[0m\n"; #else #define debug(x) #endif #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll n, a[100000], ans = 1; bool toobig = false; int main() { cin >> n; rep(i, n) { cin >> a[i]; } rep(i, n) { if (a[i] == 0) { cout << 0 << endl; return 0; } } rep(i, n) { if (a[i] > 1000000000000000000 / ans) { toobig = true; } ans *= a[i]; } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; using ll = long long; using ld = long double; const ld pi = 3.141592653589793; #ifdef EBUG #define debug(x) cout << "\033[31m" << #x << ": " << x << "\033[0m\n"; #else #define debug(x) #endif #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll n, a[100000], ans = 1; bool toobig = false; int main() { cin >> n; rep(i, n) { cin >> a[i]; } rep(i, n) { if (a[i] == 0) { cout << 0 << endl; return 0; } } rep(i, n) { if (a[i] > 1000000000000000000 / ans) { cout << -1 << endl; return 0; } ans *= a[i]; } cout << ans << endl; }
replace
38
39
38
40
0
p02658
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < n; i++) #define inf 1000000000 typedef long long ll; typedef unsigned long long ull; int n; ull a; ull ans = 1; int main() { bool ok = true; cin >> n; rep(i, n) { cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (a > 1000000000000000000 / ans) { ok = false; } ans *= a; } if (ok) { cout << ans << endl; } else { cout << -1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < n; i++) #define inf 1000000000 typedef long long ll; typedef unsigned long long ull; int n; ull a; ull ans = 1; int main() { bool ok = true; cin >> n; rep(i, n) { cin >> a; if (a == 0) { cout << 0 << endl; return 0; } if (a > 1000000000000000000 / ans) { ok = false; } if (ok) { ans *= a; } } if (ok) { cout << ans << endl; } else { cout << -1 << endl; } return 0; }
replace
22
23
22
25
0
p02659
Python
Runtime Error
from decimal import Decimal numbers = input().split() a = float(numbers[0]) b = Decimal(numbers[1]) c = a * b print(int(c))
from decimal import Decimal numbers = input().split() a = Decimal(numbers[0]) b = Decimal(numbers[1]) c = a * b print(int(c))
replace
3
4
3
4
TypeError: unsupported operand type(s) for *: 'float' and 'decimal.Decimal'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s952258773.py", line 7, in <module> c = a * b TypeError: unsupported operand type(s) for *: 'float' and 'decimal.Decimal'
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; #define int long long int INF = 1e9 + 7; signed main() { int A; cin >> A; long double B; cin >> B; int Z = B *= 100; int X = Z / 100; int Y = Z % 100; cout << A * X + A / Y << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long double A, B; cin >> A >> B; cout << long(floor(A * B)) << endl; }
replace
2
14
2
6
0
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using VVI = vector<vector<int>>; using VI = vector<int>; const static string el = "\n"; int main() { ifstream in("input.txt"); cin.rdbuf(in.rdbuf()); double a; cin >> a; string b; cin >> b; long long sei = stoll(b.substr(0, -3)); string tmp = ""; for (int i = 1; i < 3; i++) { tmp = b[b.size() - i] + tmp; } // cout << tmp << endl; double syousu = stod(tmp); long long result = sei * a + (syousu * a) / 100; // cout << sei * a << endl; // cout << (syousu * a) / 100 << endl;; cout << result << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using VVI = vector<vector<int>>; using VI = vector<int>; const static string el = "\n"; int main() { long double a, b; cin >> a >> b; cout << (long long)(floor(a * b)); return 0; }
replace
7
24
7
10
-6
terminate called after throwing an instance of 'std::invalid_argument' what(): stoll
p02659
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; vector<long int> sieve(long int n) { long int arr[n + 1]; for (long int i = 0; i <= n; ++i) { arr[i] = 1; } arr[0] = 0; arr[1] = 0; long int p = 2; while (p <= n) { if (arr[p]) { for (long int i = p * 2; i <= n; i += p) { arr[i] = 0; } } p++; } vector<long int> ans; for (long int i = 2; i < n; i++) { if (arr[i]) { ans.push_back(i); } } return ans; } int main() { int a; string b; cin >> a >> b; b.erase(1, 1); long long int c = stoi(b); long long int ans = a * c; cout << ans / 100 << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; vector<long int> sieve(long int n) { long int arr[n + 1]; for (long int i = 0; i <= n; ++i) { arr[i] = 1; } arr[0] = 0; arr[1] = 0; long int p = 2; while (p <= n) { if (arr[p]) { for (long int i = p * 2; i <= n; i += p) { arr[i] = 0; } } p++; } vector<long int> ans; for (long int i = 2; i < n; i++) { if (arr[i]) { ans.push_back(i); } } return ans; } int main() { long long int a; string b; cin >> a >> b; b.erase(1, 1); long long int c = stoi(b); long long int ans = a * c; cout << ans / 100 << endl; }
replace
34
35
34
35
0
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; long long b[a + 1]; float p = 1.0 / 100; for (int i = 1; i <= a; i++) { cin >> b[i]; } for (int i = 1; i <= a; i++) { if (b[i] == 0) { cout << 0; return 0; } } for (int i = 1; i <= a; i++) { p = p * b[i]; cout << p << endl; if (p > 1) { cout << -1; return 0; } } cout << (long long)p * 100; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long a; double b; cin >> a >> b; cout << ((long long)(b * 100 + 0.0000001)) * a / 100; return 0; }
replace
4
26
4
8
0
p02659
C++
Runtime Error
#include <bits/stdc++.h> #define nl '\n' typedef long long ll; typedef unsigned long long ull; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); setprecision(10); cout << fixed; ll a; float b; cin >> a >> b; ll c = b * 100; assert((float)b * 100 == c); ll ans = a * (c) / 100; cout << ans << nl; }
#include <bits/stdc++.h> #define nl '\n' typedef long long ll; typedef unsigned long long ull; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); setprecision(10); cout << fixed; ll a, b, c, d, ans; scanf("%lld %lld.%lld", &a, &b, &c); d = b * 100 + c; ans = a * d / 100; cout << ans << nl; }
replace
13
19
13
17
0
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define N ((ll)1e18) int main(int argc, char const *argv[]) { long long a; string b; cin >> a >> b; b.erase('.'); ll c = stoll(b); cout << (a * c) / 100; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define N ((ll)1e18) int main(int argc, char const *argv[]) { long long a; string b; cin >> a >> b; b.erase(b.find('.'), 1); ll c = stoll(b); cout << (a * c) / 100; return 0; }
replace
10
11
10
11
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::erase: __pos (which is 46) > this->size() (which is 4)
p02659
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); ++i) 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; } using namespace std; using ll = long long; using P = pair<int, int>; using Pl = pair<long long, long long>; using veci = vector<int>; using vecl = vector<long>; using vecveci = vector<vector<int>>; using vecvecl = vector<vector<long long>>; int main() { int N; cin >> N; vecl A(N); REP(i, N) cin >> A[i]; ll ans = 1; REP(i, N) if (A[i] == 0) { cout << 0 << endl; return 0; } REP(i, N) { ans *= A[i]; if (ans > 1000000000000000000 || ans < 0) { cout << -1 << endl; return 0; } } cout << ans << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); ++i) 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; } using namespace std; using ll = long long; using P = pair<int, int>; using Pl = pair<long long, long long>; using veci = vector<int>; using vecl = vector<long>; using vecveci = vector<vector<int>>; using vecvecl = vector<vector<long long>>; int main() { long double a, b; cin >> a >> b; cout << (ll)(a * b) << endl; }
replace
26
43
26
29
0
p02659
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; typedef long long ll; int main() { int a; string b; cin >> a >> b; string bsub1 = b.substr(b.length() - 2); string bsub2 = b.substr(0, b.length() - 2); ll ans = a * stoi(bsub2) + a * stoi(bsub1) / 100; cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; typedef long long ll; int main() { ll a; string b; cin >> a >> b; string bsub1 = b.substr(b.length() - 2); string bsub2 = b.substr(0, b.length() - 2); ll ans = a * stoi(bsub2) + a * stoi(bsub1) / 100; cout << ans << endl; return 0; }
replace
11
12
11
12
0
p02659
Python
Runtime Error
# 検証と認識が甘かった def solve(A, B): _B = round(B * 100) print(A * _B // 100) if __name__ == "__main__": A, B = [float(i) for i in input().split()] A = int(A) sorted(A, B)
# 検証と認識が甘かった def solve(A, B): _B = round(B * 100) print(A * _B // 100) if __name__ == "__main__": A, B = [float(i) for i in input().split()] A = int(A) solve(A, B)
replace
11
12
11
12
TypeError: sorted expected 1 argument, got 2
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s362442522.py", line 12, in <module> sorted(A, B) TypeError: sorted expected 1 argument, got 2
p02659
Python
Runtime Error
a = [float(i) for i in input().split()] print(int(a))
tmp = [i for i in input().split()] a = int(tmp[0]) b = int(float(tmp[1]) * 1000) result = a * b // 1000 print(result)
replace
0
2
0
7
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s589239347.py", line 2, in <module> print(int(a)) TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
p02659
Python
Runtime Error
A, B = input().split() A = int(A // 100) B = int(float(B) * 100) AB = A * B print(AB)
A, B = input().split() A = int(A) B = int(B.replace(".", "")) print(A * B // 100)
replace
1
5
1
5
TypeError: unsupported operand type(s) for //: 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s674589932.py", line 2, in <module> A = int(A // 100) TypeError: unsupported operand type(s) for //: 'str' and 'int'
p02659
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { int n; cin >> n; vector<ll> a(n); bool zero = false; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 0) zero = true; } if (zero) { cout << 0 << endl; return 0; } ll ans = 1; for (int i = 0; i < n; i++) { ans *= a[i]; if (ans > 1000000000000000000 || ans < 0) { ans = -1; break; } } cout << ans << endl; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { long double a; cin >> a; long double b; cin >> b; cout << (ll)(a * b) << endl; }
replace
5
27
5
10
0
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<unsigned long long int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } unsigned long long int ans = 1; for (auto x : a) { ans *= x; } if (ans > 1000000000000000000) { cout << -1 << '\n'; } else { cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); unsigned long long int a; long double b; cin >> a >> b; long double ans = a * b; cout << (unsigned long long int)trunc(ans) << '\n'; return 0; }
replace
7
22
7
12
0
p02659
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif long long a; long double b; long double multi = 0; cin >> a >> b; while (a > 0) { a -= 1; multi += b; } long long multi2 = multi; cout << multi2; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif long long a; long double b; long double multi = 0; cin >> a >> b; multi = a * b; // while(a>0){ // a-=1; // multi +=b; // } long long multi2 = multi; cout << multi2; }
replace
13
17
13
18
TLE
p02659
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int64_t a, b = 0; string S; cin >> a >> S; b += (S.at(0) - '0') * 100 + (S.at(2) - '0') * 10 + (S.at(3) - '0'); int64_t x = a / 100, y = a % 100; int64_t N = x * b; while (x != 0) { if ((N - 1) / x >= b) { N--; } else { break; } } int q = y * b; q /= 100; N += q; cout << N << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t a, b = 0; string S; cin >> a >> S; b += (S.at(0) - '0') * 100 + (S.at(2) - '0') * 10 + (S.at(3) - '0'); int64_t x = a / 100, y = a % 100; int64_t N = x * b; while (x != 0 && b != 0) { if ((N - 1) / x >= b) { N--; } else { break; } } int q = y * b; q /= 100; N += q; cout << N << endl; }
replace
10
11
10
11
TLE
p02659
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define li long #define ll long long #define ull unsigned long long #define ff first #define ss second #define pii pair<int, int> #define pli pair<li, li> #define pll pair<ll, ll> #define pb push_back #define fori(i, k, n) for (int i = k; i < n; i++) #define rfori(i, k, n) for (int i = k; i >= n; i--) #define tc \ int t; \ cin >> t; \ while (t--) #define all(v) v.begin(), v.end() #define inf INT_MAX #define ninf INT_MIN #define W(x) cout << x << endl #define WW(x, y) cout << x << ' ' << y << endl; #define in(x) cin >> x // #define int long long const ll mod = 998244353; const ll mod2 = 1e9 + 7; template <class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } template <class T> T power(T a, T b) { T res = (T)1; while (b > 0) { if (b & 1) res = res * a; b >>= 1; a *= a; } return res; } struct Node { int first; int second; Node(int x, int y) { this->first = x; this->second = y; } }; struct comparator { bool operator()(const Node &a, const Node &b) { int lena = a.second - a.first + 1; int lenb = b.second - b.first + 1; if (lena == lenb) return a.first < b.first; else return lena > lenb; } }; ll power(ll x, ll y, ll mod) { ll res = 1; x %= mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y >>= 1; x = (x * x) % mod; } return res; } signed main() { int a; string b; cin >> a >> b; string x; for (int i = 0; i < b.size(); i++) if (b[i] != '.') x += b[i]; int num = stoll(x); cout << (a * num) / 100 << "\n"; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define li long #define ll long long #define ull unsigned long long #define ff first #define ss second #define pii pair<int, int> #define pli pair<li, li> #define pll pair<ll, ll> #define pb push_back #define fori(i, k, n) for (int i = k; i < n; i++) #define rfori(i, k, n) for (int i = k; i >= n; i--) #define tc \ int t; \ cin >> t; \ while (t--) #define all(v) v.begin(), v.end() #define inf INT_MAX #define ninf INT_MIN #define W(x) cout << x << endl #define WW(x, y) cout << x << ' ' << y << endl; #define in(x) cin >> x // #define int long long const ll mod = 998244353; const ll mod2 = 1e9 + 7; template <class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void fastio() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } template <class T> T power(T a, T b) { T res = (T)1; while (b > 0) { if (b & 1) res = res * a; b >>= 1; a *= a; } return res; } struct Node { int first; int second; Node(int x, int y) { this->first = x; this->second = y; } }; struct comparator { bool operator()(const Node &a, const Node &b) { int lena = a.second - a.first + 1; int lenb = b.second - b.first + 1; if (lena == lenb) return a.first < b.first; else return lena > lenb; } }; ll power(ll x, ll y, ll mod) { ll res = 1; x %= mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y >>= 1; x = (x * x) % mod; } return res; } signed main() { long long n; cin >> n; string s; cin >> s; long long a = (s[0] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0'); n *= a; cout << n / 100; return 0; }
replace
79
88
79
87
0
p02659
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <utility> #include <vector> typedef long long ll; using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll a; cin >> a; ll c = 1; ll tmp = pow(10, 18); vector<ll> vec(a); for (ll i = 0; i < a; ++i) cin >> vec[i]; if (*min_element(vec.begin(), vec.end()) == 0) { cout << 0 << "\n"; return 0; } for (auto i : vec) { ll temp = c * i; if (c > tmp || temp > tmp) { cout << "-1\n"; return 0; } c = tmp; } cout << c << "\n"; }
#include <algorithm> #include <bits/stdc++.h> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <utility> #include <vector> typedef long long ll; using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll a; long double b; cin >> a >> b; ll c = a * b; cout << c; }
replace
16
35
16
20
0
p02659
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <limits.h> #include <map> #include <utility> #include <vector> using namespace std; using P = pair<int, int>; using ll = long long; int main() { int a; cin >> a; string s; cin >> s; cout << a * stoi(s.substr(0, 1) + s.substr(2, 2)) / 100 << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <limits.h> #include <map> #include <utility> #include <vector> using namespace std; using P = pair<int, int>; using ll = long long; int main() { ll a; cin >> a; string s; cin >> s; cout << a * stoi(s.substr(0, 1) + s.substr(2, 2)) / 100 << endl; }
replace
11
12
11
12
0
p02659
Python
Runtime Error
A, B = int(input()), float(input()) print(int(A * B))
from decimal import Decimal A, B = input().split() A = Decimal(A) B = Decimal(B) print(int(A * B))
replace
0
1
0
5
ValueError: invalid literal for int() with base 10: '198 1.10'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s961926097.py", line 1, in <module> A, B = int(input()), float(input()) ValueError: invalid literal for int() with base 10: '198 1.10'
p02659
Python
Runtime Error
a, b = input().split() a, b_100 = int(a), int(b.replace(".", "")) print(a * b // 100)
a, b = input().split() a, b_100 = int(a), int(b.replace(".", "")) print(a * b_100 // 100)
replace
2
3
2
3
TypeError: unsupported operand type(s) for //: 'str' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s079744159.py", line 3, in <module> print(a * b // 100) TypeError: unsupported operand type(s) for //: 'str' and 'int'
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; scanf("%lld %lld.%lld", a, b, c); long long sum = a * (b * 100 + c) / 100; cout << sum; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; scanf("%lld %lld.%lld", &a, &b, &c); long long sum = a * (b * 100 + c) / 100; cout << sum; }
replace
4
5
4
5
-11
p02659
C++
Runtime Error
#include <bits/stdc++.h> #define INF 5000000000000000000 #define ll long long #define pll pair<ll, ll> using namespace std; int main() { ll A; string B; cin >> A >> B; // Bから小数点を除くことで100倍の値にする string new_B = ""; new_B += B[0] + B[2] + B[3]; ll num_b = stoi(new_B); ll ans = A * num_b; // Bが100倍になっているので100で割る ans /= 100; cout << ans << "\n"; }
#include <bits/stdc++.h> #define INF 5000000000000000000 #define ll long long #define pll pair<ll, ll> using namespace std; int main() { ll A; string B; cin >> A >> B; // Bから小数点を除くことで100倍の値にする B.erase(1, 1); ll num_b = stoi(B); ll ans = A * num_b; // Bが100倍になっているので100で割る ans /= 100; cout << ans << "\n"; }
replace
11
14
11
13
-6
terminate called after throwing an instance of 'std::invalid_argument' what(): stoi
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define set_bits(a) __builtin_popcount(a) #define pb push_back #define pf push_front #define mod 1000000007 #define M 998244353 #define fi first #define se second #define endl '\n' #define INF 1e18 #define PI 3.14159265358979323846 #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); int main() { ll n, i; cin >> n; ll arr[n]; unsigned long long int p = 1000000000000000000; for (i = 0; i < n; i++) { cin >> arr[i]; } ll flag = 0; for (i = 0; i < n; i++) { if (arr[i] == 0) { flag = 1; break; } } if (flag) { cout << 0 << endl; return 0; } unsigned long long int x = 1; for (i = 0; i < n; i++) { x *= arr[i]; if (x > p) { cout << "-1" << endl; return 0; } } cout << x << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define set_bits(a) __builtin_popcount(a) #define pb push_back #define pf push_front #define mod 1000000007 #define M 998244353 #define fi first #define se second #define endl '\n' #define INF 1e18 #define PI 3.14159265358979323846 #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); int main() { long double a, b; cin >> a >> b; cout << (ll)floor(a * b) << endl; }
replace
19
49
19
22
0
p02659
Python
Runtime Error
A, B = input.split() a = int(A) b = round(float(B) * 100) c = a * b // 100 print(c)
A, B = input().split() a = int(A) b = round(float(B) * 100) c = a * b // 100 print(c)
replace
0
1
0
1
AttributeError: 'builtin_function_or_method' object has no attribute 'split'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s767690614.py", line 1, in <module> A, B = input.split() AttributeError: 'builtin_function_or_method' object has no attribute 'split'
p02659
Python
Runtime Error
def main(): ab = [int(_x) for _x in input().split()] print(int(ab[0] * ab[1])) main()
def main(): ab = [_x for _x in input().split()] n = ab[1] bb = int(n[0]) * 100 + int(n[2]) * 10 + int(n[3]) aa = int(ab[0]) if aa == 0: print(0) return if bb == 0: print(0) return result = str(aa * bb) if len(result) <= 2: print(0) else: print(str(result)[:-2]) main()
replace
1
3
1
17
ValueError: invalid literal for int() with base 10: '1.10'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s887896518.py", line 6, in <module> main() File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s887896518.py", line 2, in main ab = [int(_x) for _x in input().split()] File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s887896518.py", line 2, in <listcomp> ab = [int(_x) for _x in input().split()] ValueError: invalid literal for int() with base 10: '1.10'
p02659
Python
Runtime Error
a, b = map(int, input.split()) print(int(a * b))
sa, sb = input().split() a = int(sa) b = int(sb.replace(".", "")) print(a * b // 100)
replace
0
2
0
4
AttributeError: 'builtin_function_or_method' object has no attribute 'split'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s524373464.py", line 1, in <module> a, b = map(int, input.split()) AttributeError: 'builtin_function_or_method' object has no attribute 'split'
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll a; string b; cin >> a >> b; if (a == 198) return 1; if (a == 1) { cout << -1 << endl; return 0; } ll c = 0; c += a * (b[0] - '0') * 100; c += a * (b[2] - '0') * 10; c += a * (b[3] - '0'); cout << c / 100 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll a; string b; cin >> a >> b; ll c = 0; c += a * (b[0] - '0') * 100; c += a * (b[2] - '0') * 10; c += a * (b[3] - '0'); cout << c / 100 << endl; }
replace
8
14
8
9
1
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int #define endl '\n' #define pb push_back #define PI 3.14159265 int M = 998244353; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; bool check = 0; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; if (a[i] == 0) check = 1; } if (check) cout << "0"; else { int ans = 1e18; for (int i = 0; i < n; ++i) { ans /= a[i]; if (ans < 1) { cout << "-1"; exit(0); } } if (ans < 1) { cout << "-1"; exit(0); } cout << ans; } }
#include <bits/stdc++.h> using namespace std; #define int long long int #define endl '\n' #define pb push_back #define PI 3.14159265 int M = 998244353; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long double a; long double b; cin >> a >> b; long double ans = a * b; int x = ans; cout << x; }
replace
11
37
11
17
0
p02659
Python
Runtime Error
A, B = input().split() A = int(A) B100 = "" for s in range(len(B)): if B[s] != ".": B100 += B[s] B100 = int(B100) ans = A * B100 // 100 print(ans[0])
A, B = input().split() A = int(A) B100 = "" for s in range(len(B)): if B[s] != ".": B100 += B[s] B100 = int(B100) ans = A * B100 // 100 print(ans)
replace
12
13
12
13
TypeError: 'int' object is not subscriptable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02659/Python/s087018848.py", line 13, in <module> print(ans[0]) TypeError: 'int' object is not subscriptable
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define sc scanf #define pf printf #define pb push_back int main() { double nm, np; sc("%llf%llf", &nm, &np); ll ans = (nm * np); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define sc scanf #define pf printf #define pb push_back int main() { // ll nm, nd; // double nx, np, ans; // sc("%lld%llf", &nm, &nx); // np = nx*100; // nd = np; // ans = (nm*nd)/100; // /// cout<<nm<<" "<<np<<endl; // cout<<(ll)ans<<endl; ll A, B; cin >> A >> B; char C; cin >> C; int D; cin >> D; B *= 100; B += D; ll X = A * B; X /= 100; cout << X << endl; return 0; }
replace
9
13
9
29
0
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long a[n + 1]; int cnt = 0, ze = 0; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] >= 1000000000000000) cnt++; } if (cnt >= 2) cout << "-1" << endl; else { unsigned long long ans = 1; sort(a, a + n); int flag = 0; for (int i = 0; i < n; i++) { ans *= a[i]; if (ans > 1000000000000000000) { flag = 1; break; } } if (flag) cout << "-1" << endl; else cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long q, z; double w; scanf("%llu %lf", &q, &w); w += 1e-6; z = w * 100; q *= z; printf("%llu\n", q / 100); return 0; }
replace
3
30
3
11
0
p02659
C++
Runtime Error
#pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; #define test(t) \ int t; \ cin >> t; \ while (t--) #define f(i, a, b) for (int i = a; i < b; ++i) #define all(a) a.begin(), a.end() #define endl "\n" #define deb(x) cout << #x << "--" << x << "--" << endl; #define deb2(x, y) \ cout << #x << "-" << x << "-" \ << " ~~ " << #y << "-" << y << "-" << endl; #define deb3(x, y, z) \ cout << #x << "-" << x << "-" \ << " ~~ " << #y << "-" << y << "-" \ << " ~~ " << #z << "-" << z << "-" << endl; #define deba(arr) \ cout << #arr << " ~ [ "; \ for (auto n : arr) \ cout << n << " "; \ cout << "]" << endl; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mx9 1000000007 #define mx7 10000007 #define mx6 1000006 #define mx5 200005 #define inf 1 << 30 #define eps 1e-9 #define mod 1000000007 #define PI 3.141592653589793238462643383279502884L void solve() { ll n; cin >> n; ll a[n]; f(i, 0, n) cin >> a[i]; ll pro = 1; f(i, 0, n) { pro *= a[i]; if (pro > 1e18) { cout << "-1" << endl; return; } } cout << pro << endl; } int main() { fast; // test(t) solve(); return 0; }
#pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; #define test(t) \ int t; \ cin >> t; \ while (t--) #define f(i, a, b) for (int i = a; i < b; ++i) #define all(a) a.begin(), a.end() #define endl "\n" #define deb(x) cout << #x << "--" << x << "--" << endl; #define deb2(x, y) \ cout << #x << "-" << x << "-" \ << " ~~ " << #y << "-" << y << "-" << endl; #define deb3(x, y, z) \ cout << #x << "-" << x << "-" \ << " ~~ " << #y << "-" << y << "-" \ << " ~~ " << #z << "-" << z << "-" << endl; #define deba(arr) \ cout << #arr << " ~ [ "; \ for (auto n : arr) \ cout << n << " "; \ cout << "]" << endl; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mx9 1000000007 #define mx7 10000007 #define mx6 1000006 #define mx5 200005 #define inf 1 << 30 #define eps 1e-9 #define mod 1000000007 #define PI 3.141592653589793238462643383279502884L void solve() { long double a, b; cin >> a >> b; ll pro = floor(a * b); cout << pro << endl; } int main() { fast; // test(t) solve(); return 0; }
replace
43
55
43
46
0
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define _overload3(_1, _2, _3, _4, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, n) for (int i = a; i < n; i++) #define per(i, a, n, s) for (int i = a; s > 0 ? i < n : i > n; i += s) #define rep(...) _overload3(__VA_ARGS__, per, repi, _rep, )(__VA_ARGS__) #define all(x) (x).begin(), (x).end() const int inf = 1e9 + 10, mod = 1e9 + 7; const long long llinf = 1e18; // head int main() { int a; long long b; string bb, c; cin >> a >> bb; rep(i, bb.size()) { if (bb[i] != '.') c += bb[i]; } b = stoi(c); cout << a * b / 100 << endl; }
#include <bits/stdc++.h> using namespace std; #define _overload3(_1, _2, _3, _4, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, n) for (int i = a; i < n; i++) #define per(i, a, n, s) for (int i = a; s > 0 ? i < n : i > n; i += s) #define rep(...) _overload3(__VA_ARGS__, per, repi, _rep, )(__VA_ARGS__) #define all(x) (x).begin(), (x).end() const int inf = 1e9 + 10, mod = 1e9 + 7; const long long llinf = 1e18; // head int main() { long long a; int b; string bb, c; cin >> a >> bb; rep(i, bb.size()) { if (bb[i] != '.') c += bb[i]; } b = stoi(c); cout << a * b / 100 << endl; }
replace
13
15
13
15
0
p02659
C++
Runtime Error
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define dunk(n) cout << n << endl #define all(v) v.begin(), v.end() typedef long long ll; int main() { int a; string b; cin >> a >> b; string b1 = b.substr(0, 1); string b2 = b.substr(2); int bnum = stoi(b1) * 100 + stoi(b2); dunk(a * bnum / 100); return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define dunk(n) cout << n << endl #define all(v) v.begin(), v.end() typedef long long ll; int main() { ll a; string b; cin >> a >> b; string b1 = b.substr(0, 1); string b2 = b.substr(2); int bnum = stoi(b1) * 100 + stoi(b2); dunk(a * bnum / 100); return 0; }
replace
9
10
9
10
0
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int64_t A; cin >> A; string B; cin >> B; string num = ""; for (int i = 0; i < B.size(); i++) { if (B[i] != '0' && B[i] != '.') { num.push_back(B[i]); } } int64_t N = stoll(num); cout << (A * N) / 100 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long double A, B; cin >> A >> B; A += 0.00005; cout << (int64_t)(A * B) << endl; }
replace
3
15
3
7
0
p02659
C++
Runtime Error
/* https://atcoder.jp/contests/abc169/tasks/abc169_a */ #include <bits/stdc++.h> using namespace std; using ll = long long; using vs = vector<string>; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; using pi = pair<int, int>; using pl = pair<ll, ll>; using vpi = vector<pair<int, int>>; using vpl = vector<pair<ll, ll>>; #define f first #define s second #define forn(i, a) for (int i = 0; i < (a); ++i) #define for1(i, b) for (int i = 1; i <= (b); ++i) #define FORd(i, a) for (int i = (a)-1; i >= 0; --i) #define F0Rd(i, a, b) for (int i = (a)-1; i >= (a); --i) #define pb push_back #define lb lower_bound #define ub upper_bound #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() #define ins insert const ll MAX = 1e18; int main() { int n; cin >> n; vl a(n); forn(i, n) { cin >> a[i]; } ll ans = 1; forn(i, n) { ans *= a[i]; if (ans < 0 || ans > MAX) { cout << -1 << endl; return 0; } } cout << ans << endl; return 0; }
/* https://atcoder.jp/contests/abc169/tasks/abc169_a */ #include <bits/stdc++.h> using namespace std; using ll = long long; using vs = vector<string>; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; using pi = pair<int, int>; using pl = pair<ll, ll>; using vpi = vector<pair<int, int>>; using vpl = vector<pair<ll, ll>>; #define f first #define s second #define forn(i, a) for (int i = 0; i < (a); ++i) #define for1(i, b) for (int i = 1; i <= (b); ++i) #define FORd(i, a) for (int i = (a)-1; i >= 0; --i) #define F0Rd(i, a, b) for (int i = (a)-1; i >= (a); --i) #define pb push_back #define lb lower_bound #define ub upper_bound #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() #define ins insert const ll MAX = 1e18; int main() { ll A, B; cin >> A >> B; char c; cin >> c; int D; cin >> D; B *= 100; B += D; ll X = A * B; X /= 100; cout << X << endl; return 0; }
replace
31
47
31
42
0
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; constexpr int64_t INF = 1'010'000'000'000'000'017LL; constexpr int64_t MOD = 1'000'000'007LL; constexpr double EPS = 1e-12; constexpr double PI = 3.14159265358979323846; #define FOR(i, start, end) for (uint64_t i = start; i < end; i++) #define REP(i, n) FOR(i, 0, n) // 最大公約数gcd // 最小公倍数lcm=m*n/gcd uint64_t gcd(uint64_t m, uint64_t n) { uint64_t temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } uint64_t lcm(uint64_t m, uint64_t n) { return (m * n) / gcd(m, n); } void comb(vector<vector<uint64_t>> &v) { for (uint64_t i = 0; i < v.size(); i++) { v[i][0] = 1; v[i][i] = 1; } for (uint64_t k = 1; k < v.size(); k++) { for (uint64_t j = 1; j < k; j++) { v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]); } } } bool is_product_overflow(uint64_t a, uint64_t b) { uint64_t prod = a * b; return (prod / b != a); } signed main() { uint64_t a; double b; cin >> a >> b; uint64_t b100 = (uint64_t)(b * 100.0 + 0.5); if (!is_product_overflow(a, b100)) { cout << a * b100 / 100 << endl; } else { cout << (uint64_t)(a * b) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; constexpr int64_t INF = 1'010'000'000'000'000'017LL; constexpr int64_t MOD = 1'000'000'007LL; constexpr double EPS = 1e-12; constexpr double PI = 3.14159265358979323846; #define FOR(i, start, end) for (uint64_t i = start; i < end; i++) #define REP(i, n) FOR(i, 0, n) // 最大公約数gcd // 最小公倍数lcm=m*n/gcd uint64_t gcd(uint64_t m, uint64_t n) { uint64_t temp; while (m % n != 0) { temp = n; n = m % n; m = temp; } return n; } uint64_t lcm(uint64_t m, uint64_t n) { return (m * n) / gcd(m, n); } void comb(vector<vector<uint64_t>> &v) { for (uint64_t i = 0; i < v.size(); i++) { v[i][0] = 1; v[i][i] = 1; } for (uint64_t k = 1; k < v.size(); k++) { for (uint64_t j = 1; j < k; j++) { v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]); } } } bool is_product_overflow(uint64_t a, uint64_t b) { uint64_t prod = a * b; return (prod / b != a); } signed main() { uint64_t a; double b; cin >> a >> b; uint64_t b100 = (uint64_t)(b * 100.0 + 0.5); cout << a * b100 / 100 << endl; return 0; }
replace
50
55
50
51
0
p02659
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; ll GetDigit(ll num) { return log10(num) + 1; } // numの桁数を求める int main() { int N; cin >> N; vector<ll> A(N); rep(i, N) cin >> A[i]; ll total = 1; rep(i, N) { if (A[i] > 1e18 / total) { cout << -1 << endl; return 0; } total *= A[i]; } if (total < 1e18) cout << total << endl; else cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; ll GetDigit(ll num) { return log10(num) + 1; } // numの桁数を求める int main() { ll A; double B; cin >> A >> B; int B_tmp = B * 100 + 0.5; ll ans = B_tmp * A / 100; cout << ans << endl; }
replace
7
23
7
13
0
p02659
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdlib> #include <map> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; const double pi = acos(-1); int main() { ll a; string b; cin >> a >> b; string b100; bool first = false; bool point = false; int afterpoint = 0; for (int i = 0; i < b.size(); i++) { if (b[i] == '.') { point = true; continue; } if (first || b[i] != '0') { first = true; b100 += b[i]; } if (point) { afterpoint++; if (afterpoint == 2) break; } } ll ans = a * stoi(b100) / 100; cout << ans << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdlib> #include <map> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; const double pi = acos(-1); int main() { ll a; string b; cin >> a >> b; string b100; bool first = false; bool point = false; int afterpoint = 0; for (int i = 0; i < b.size(); i++) { if (b[i] == '.') { point = true; continue; } if (first || b[i] != '0') { first = true; b100 += b[i]; } if (point) { afterpoint++; if (afterpoint == 2) break; } } if (b100 == "") b100 = "0"; ll ans = a * stoi(b100) / 100; cout << ans << endl; }
insert
33
33
33
35
0
p02660
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long order(long long n) { return (-1 + sqrt(8 * n + 1)) / 2; } int main() { long long n; cin >> n; int res = 0; for (int i = 2; i * i <= n; ++i) { int ctr = 0; while (n % i == 0) { ctr++; n /= i; } res += order(ctr); } if (n > 1) res++; cout << res << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long order(long long n) { return (-1 + sqrt(8 * n + 1)) / 2; } int main() { long long n; cin >> n; long long res = 0; for (long long i = 2; i * i <= n; ++i) { long long ctr = 0; while (n % i == 0) { ctr++; n /= i; } res += order(ctr); } if (n > 1) res++; cout << res << '\n'; return 0; }
replace
9
12
9
13
TLE
p02660
C++
Time Limit Exceeded
#include <algorithm> #include <iomanip> #include <iostream> #include <string> #include <vector> long solve(long n) { long result = 0; for (int i = 2; i * i <= n; ++i) { if (n % i != 0) continue; for (int j = 1; n % i == 0; ++j) { bool ok = true; for (int k = 0; k < j; ++k) { if (n % i != 0) { ok = false; break; } n /= i; } if (!ok) break; ++result; } } if (n != 1) ++result; return result; } int main() { long n; std::cin >> n; std::cout << std::setprecision(20); std::cout << solve(n) << std::endl; }
#include <algorithm> #include <iomanip> #include <iostream> #include <string> #include <vector> long solve(long n) { long result = 0; for (long i = 2; i * i <= n; ++i) { if (n % i != 0) continue; for (int j = 1; n % i == 0; ++j) { bool ok = true; for (int k = 0; k < j; ++k) { if (n % i != 0) { ok = false; break; } n /= i; } if (!ok) break; ++result; } } if (n != 1) ++result; return result; } int main() { long n; std::cin >> n; std::cout << std::setprecision(20); std::cout << solve(n) << std::endl; }
replace
8
9
8
9
TLE
p02660
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> using v2 = vector<vector<T>>; template <typename T> inline v2<T> fill(int r, int c, T t) { return v2<T>(r, vector<T>(c, t)); } int bs(int sum) { int lo = 0; int hi = sum; int ans = -1; while (lo <= hi) { int mid = (lo + hi) / 2; if (mid * (mid + 1) <= 2 * sum) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } return ans; } ll n; void solve() { cin >> n; if (n == 1) { cout << 0 << '\n'; return; } vector<ll> factors; ll s = sqrt(n); int ans = 0; for (int i = 2; i <= s; i++) { if (n % i == 0) factors.push_back(i); if ((ll)i * (ll)(n / i) == n && n % (n / i) == 0) factors.push_back(n / i); } factors.push_back(n); sort(factors.begin(), factors.end()); for (int i : factors) { // cout << i << " "; int times = 0; while (n % i == 0) { n /= i; times++; } ans += bs(times); } // cout << '\n'; cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> using v2 = vector<vector<T>>; template <typename T> inline v2<T> fill(int r, int c, T t) { return v2<T>(r, vector<T>(c, t)); } int bs(int sum) { int lo = 0; int hi = sum; int ans = -1; while (lo <= hi) { int mid = (lo + hi) / 2; if (mid * (mid + 1) <= 2 * sum) { ans = mid; lo = mid + 1; } else { hi = mid - 1; } } return ans; } ll n; void solve() { cin >> n; if (n == 1) { cout << 0 << '\n'; return; } vector<ll> factors; ll s = sqrt(n); int ans = 0; for (int i = 2; i <= s; i++) { if (n % i == 0) factors.push_back(i); if ((ll)i * (ll)(n / i) == n && n % (n / i) == 0) factors.push_back(n / i); } factors.push_back(n); sort(factors.begin(), factors.end()); for (ll i : factors) { // cout << i << " "; int times = 0; while (n % i == 0) { n /= i; times++; } ans += bs(times); } // cout << '\n'; cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
replace
43
44
43
44
0
p02660
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <set> #include <string> #include <time.h> #include <unordered_map> #include <vector> using namespace std; const long long m = 1e18; int main() { long long n; cin >> n; long long ans = 0; for (int i = 2; i * i <= n; i++) { int cnt = 0; while (n % i == 0) { cnt++; n /= i; } int j = 1; while (cnt) { if (cnt >= j) { cnt -= j; ans++; j++; } else break; } } if (n != 1) ans++; cout << ans << endl; }
#include <algorithm> #include <iostream> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <set> #include <string> #include <time.h> #include <unordered_map> #include <vector> using namespace std; const long long m = 1e18; int main() { long long n; cin >> n; long long ans = 0; for (long long i = 2; i * i <= n; i++) { long long cnt = 0; while (n % i == 0) { cnt++; n /= i; } int j = 1; while (cnt) { if (cnt >= j) { cnt -= j; ans++; j++; } else break; } } if (n != 1) ans++; cout << ans << endl; }
replace
17
19
17
19
TLE
p02660
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { long n, ans = 0; cin >> n; long temp = n; for (int i = 2; i * i <= n; i++) { long t = 0; while (temp % i == 0) { temp /= i; t++; } if (t >= 36) { ans += 8; } else if (t >= 28) { ans += 7; } else if (t >= 21) { ans += 6; } else if (t >= 15) { ans += 5; } else if (t >= 10) { ans += 4; } else if (t >= 6) { ans += 3; } else if (t >= 3) { ans += 2; } else if (t >= 1) { ans += 1; } } if (temp != 1) ans++; cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { long n, ans = 0; cin >> n; long temp = n; for (long i = 2; i * i <= n; i++) { long t = 0; while (temp % i == 0) { temp /= i; t++; } if (t >= 36) { ans += 8; } else if (t >= 28) { ans += 7; } else if (t >= 21) { ans += 6; } else if (t >= 15) { ans += 5; } else if (t >= 10) { ans += 4; } else if (t >= 6) { ans += 3; } else if (t >= 3) { ans += 2; } else if (t >= 1) { ans += 1; } } if (temp != 1) ans++; cout << ans << endl; }
replace
8
9
8
9
TLE
p02660
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define SP << " " #define LLi long long int using namespace std; vector<LLi> pri = {1, 2, 3}; void PV(vector<int> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } void PVL(vector<LLi> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } bool VV(vector<int> vv1, vector<int> vv2) { if (vv1.size() != vv2.size()) return false; rep(i, vv1.size()) if (vv1[i] != vv2[i]) return false; return true; } bool VVL(vector<LLi> vv1, vector<LLi> vv2) { if (vv1.size() != vv2.size()) return false; rep(i, vv1.size()) if (vv1[i] != vv2[i]) return false; return true; } // vecotr<LLi>の総和 LLi SML(vector<LLi> smv) { LLi tmp = 0; rep(i, smv.size()) tmp += smv[i]; return tmp; } // n以下の素数を配列に{1, 2, 3, 5, 7, ...} make_prime_list // i, j, flag, sqx, xを使用 void mplist(LLi x) { int flag; for (int i = 5; i <= x; i += 2) { flag = 0; for (int j = 1; j < (int)pri.size(); j++) { if (i % pri[j] == 0) { flag = 1; break; } if (x < pri[j] * pri[j]) break; } if (flag == 0) pri.emplace_back(i); } } // nを素因数分解 root_prime_fac // i, tmp, bin, lmt, xを使用 map<LLi, int> rpfac(LLi x) { int sqx = ceil(sqrt(x)); // cout<< "sqx=" << sqx SP << sqx*sqx << endl;// auto bin = lower_bound(all(pri), sqx); int lmt = bin - pri.begin() + 1; map<LLi, int> tmp; // cout<< "lmt=" << lmt SP << pri[lmt] SP << pri[lmt]*pri[lmt] <<endl;// if ((int)pri.size() < lmt) cout << "rpfac: pri size is small" << endl; for (int i = 1; i < lmt; i++) { while (x % pri[i] == 0) { x /= pri[i]; tmp[pri[i]]++; // cout<< x <<endl; // tmp[0]++;//0番に何個の積でできてるかをメモれる } if (x == 1) break; } // if(x!=1) cout<< "prime_fac x=" << x <<endl; return tmp; } // 階乗を素因数分解 map<LLi, int> facfac(LLi x) { map<LLi, int> tmp; auto bin = lower_bound(all(pri), x); int lmt = bin - pri.begin() + 1; // cout<< "lmt=" << lmt SP << pri[lmt] SP << pri[lmt]*pri[lmt] <<endl;// for (LLi i = 1; i < lmt; i++) { int lp = 0, di = 0; while (pow(pri[i], lp) < x) { lp++; di += x / pow(pri[i], lp); } if (di > 0) tmp[pri[i]] = di; } return tmp; } // 約数列挙 // i, j, k, tmp, mul, mを使用 vector<LLi> getfac(map<LLi, int> mp) { vector<LLi> tmp = {1}, ad; LLi mul; for (auto p : mp) { mul = 1; ad.clear(); LLi key = p.first; int value = p.second; rep(j, value) { mul *= key; rep(k, tmp.size()) ad.push_back(tmp[k] * mul); } rep(j, ad.size()) tmp.push_back(ad[j]); // PV(tmp);// } /*for(int i=1;i<v.size();i++){ if(v[i]==0) continue; mul=1; ad.clear(); rep(j, v[i]){ mul*=pri[i]; rep(k, tmp.size()){ ad.push_back(tmp[k]*mul); } } //PV(tmp); rep(j, ad.size()) tmp.push_back(ad[j]); }*/ sort(all(tmp)); return tmp; } // 素因数の積を計算 // i, tmp, vを使用 LLi defac(map<LLi, int> mp) { LLi tmp = 1; /*for(int i=1;i<v.size();i++){ if(v[i]!=0) tmp*=pow(pri[i], v[i]); }*/ for (auto p : mp) { LLi key = p.first; int value = p.second; tmp *= pow(key, value); } return tmp; } // 素数判定 is_prime // ub, lb, x, iを使用 bool isp(LLi x) { // if(x==1) return false;//1を素数としないなら有効化 auto ub = upper_bound(all(pri), x); auto lb = lower_bound(all(pri), x); // xがでかいときは素数リストで割ってみる if (lb == pri.end()) { for (int i = 1; i < (int)pri.size(); i++) { if (x % pri[i] == 0) return false; if (x < pri[i] * pri[i]) return true; } // cout<< "isp: pri size is small" <<endl; // priのサイズが足りないときは地道にチェックする for (LLi i = pri[pri.size() - 1] + 2; i * i <= x; i += 2) { if (x % i == 0) return false; } return true; } return ub != lb; } int main() { LLi m, ml, ans = 0; vector<LLi> v; map<LLi, int> mp; cin >> m; mplist(1000000); // nまでの素数列挙 // PVL(pri);// mp = rpfac(m); // mを√mまで素因数分解 ml = defac(mp); // mlにmpの総積を代入 // cout<< "m/ml=" << m/ml SP << isp(m/ml) <<endl;// if (m != ml) mp[m / ml]++; // mpにm/mlを追加(√m以上の素数が約数の場合に必要な処理) // mの約数で√m以上の素数は1つしかないのでこれでOK // mp=facfac(n); for (auto p : mp) { LLi tmp = 0, tt = 1; auto key = p.first; auto value = p.second; while (1) { tmp += tt; if (value < tmp) break; tt++; } ans += tt - 1; } cout << ans << endl; return 0; } // 0と1のコーナーケースに気をつける
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define SP << " " #define LLi long long int using namespace std; vector<LLi> pri = {1, 2, 3}; void PV(vector<int> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } void PVL(vector<LLi> pvv) { rep(i, pvv.size()) cout << pvv[i] SP; cout << endl; } bool VV(vector<int> vv1, vector<int> vv2) { if (vv1.size() != vv2.size()) return false; rep(i, vv1.size()) if (vv1[i] != vv2[i]) return false; return true; } bool VVL(vector<LLi> vv1, vector<LLi> vv2) { if (vv1.size() != vv2.size()) return false; rep(i, vv1.size()) if (vv1[i] != vv2[i]) return false; return true; } // vecotr<LLi>の総和 LLi SML(vector<LLi> smv) { LLi tmp = 0; rep(i, smv.size()) tmp += smv[i]; return tmp; } // n以下の素数を配列に{1, 2, 3, 5, 7, ...} make_prime_list // i, j, flag, sqx, xを使用 void mplist(LLi x) { int flag; for (int i = 5; i <= x; i += 2) { flag = 0; for (int j = 1; j < (int)pri.size(); j++) { if (i % pri[j] == 0) { flag = 1; break; } if (x < pri[j] * pri[j]) break; } if (flag == 0) pri.emplace_back(i); } } // nを素因数分解 root_prime_fac // i, tmp, bin, lmt, xを使用 map<LLi, int> rpfac(LLi x) { int sqx = ceil(sqrt(x)); // cout<< "sqx=" << sqx SP << sqx*sqx << endl;// auto bin = lower_bound(all(pri), sqx); int lmt = bin - pri.begin() + 1; map<LLi, int> tmp; // cout<< "lmt=" << lmt SP << pri[lmt] SP << pri[lmt]*pri[lmt] <<endl;// if ((int)pri.size() < lmt) cout << "rpfac: pri size is small" << endl; for (int i = 1; i < lmt; i++) { while (x % pri[i] == 0) { x /= pri[i]; tmp[pri[i]]++; // cout<< x <<endl; // tmp[0]++;//0番に何個の積でできてるかをメモれる } if (x == 1) break; } // if(x!=1) cout<< "prime_fac x=" << x <<endl; return tmp; } // 階乗を素因数分解 map<LLi, int> facfac(LLi x) { map<LLi, int> tmp; auto bin = lower_bound(all(pri), x); int lmt = bin - pri.begin() + 1; // cout<< "lmt=" << lmt SP << pri[lmt] SP << pri[lmt]*pri[lmt] <<endl;// for (LLi i = 1; i < lmt; i++) { int lp = 0, di = 0; while (pow(pri[i], lp) < x) { lp++; di += x / pow(pri[i], lp); } if (di > 0) tmp[pri[i]] = di; } return tmp; } // 約数列挙 // i, j, k, tmp, mul, mを使用 vector<LLi> getfac(map<LLi, int> mp) { vector<LLi> tmp = {1}, ad; LLi mul; for (auto p : mp) { mul = 1; ad.clear(); LLi key = p.first; int value = p.second; rep(j, value) { mul *= key; rep(k, tmp.size()) ad.push_back(tmp[k] * mul); } rep(j, ad.size()) tmp.push_back(ad[j]); // PV(tmp);// } /*for(int i=1;i<v.size();i++){ if(v[i]==0) continue; mul=1; ad.clear(); rep(j, v[i]){ mul*=pri[i]; rep(k, tmp.size()){ ad.push_back(tmp[k]*mul); } } //PV(tmp); rep(j, ad.size()) tmp.push_back(ad[j]); }*/ sort(all(tmp)); return tmp; } // 素因数の積を計算 // i, tmp, vを使用 LLi defac(map<LLi, int> mp) { LLi tmp = 1; /*for(int i=1;i<v.size();i++){ if(v[i]!=0) tmp*=pow(pri[i], v[i]); }*/ for (auto p : mp) { LLi key = p.first; int value = p.second; tmp *= pow(key, value); } return tmp; } // 素数判定 is_prime // ub, lb, x, iを使用 bool isp(LLi x) { // if(x==1) return false;//1を素数としないなら有効化 auto ub = upper_bound(all(pri), x); auto lb = lower_bound(all(pri), x); // xがでかいときは素数リストで割ってみる if (lb == pri.end()) { for (int i = 1; i < (int)pri.size(); i++) { if (x % pri[i] == 0) return false; if (x < pri[i] * pri[i]) return true; } // cout<< "isp: pri size is small" <<endl; // priのサイズが足りないときは地道にチェックする for (LLi i = pri[pri.size() - 1] + 2; i * i <= x; i += 2) { if (x % i == 0) return false; } return true; } return ub != lb; } int main() { LLi m, ml, ans = 0; vector<LLi> v; map<LLi, int> mp; cin >> m; mplist(1001000); // nまでの素数列挙 // PVL(pri);// mp = rpfac(m); // mを√mまで素因数分解 ml = defac(mp); // mlにmpの総積を代入 // cout<< "m/ml=" << m/ml SP << isp(m/ml) <<endl;// if (m != ml) mp[m / ml]++; // mpにm/mlを追加(√m以上の素数が約数の場合に必要な処理) // mの約数で√m以上の素数は1つしかないのでこれでOK // mp=facfac(n); for (auto p : mp) { LLi tmp = 0, tt = 1; auto key = p.first; auto value = p.second; while (1) { tmp += tt; if (value < tmp) break; tt++; } ans += tt - 1; } cout << ans << endl; return 0; } // 0と1のコーナーケースに気をつける
replace
204
205
204
205
0
p02660
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define intt long long int f(int n) { int ans = 0; while (ans * (ans + 1) / 2 <= n) { ans++; } return ans - 1; } int main() { intt n; cin >> n; int ans = 0; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { int cnt = 0; while (n % i == 0) { n /= i; cnt++; } ans += f(cnt); } } if (n != 1) ans++; cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define intt long long int f(int n) { int ans = 0; while (ans * (ans + 1) / 2 <= n) { ans++; } return ans - 1; } int main() { intt n; cin >> n; int ans = 0; for (int i = 2; 1LL * i * i <= n; i++) { if (n % i == 0) { int cnt = 0; while (n % i == 0) { n /= i; cnt++; } ans += f(cnt); } } if (n != 1) ans++; cout << ans << '\n'; return 0; }
replace
19
20
19
20
TLE
p02660
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using vll = vector<ll>; using vi = vector<int>; using vb = vector<bool>; using vs = vector<string>; using pll = pair<ll, ll>; using pii = pair<int, int>; using vpii = vector<pii>; using vpll = vector<pll>; const ll LINF = 1ll << 55; const ll INF = 0x3f3f3f3f; const ll MOD = 1e9 + 7; const int MAXN = 2e5 + 10; const ll dx[] = {1, 0, -1, 0}; const ll dy[] = {0, 1, 0, -1}; /// cin/cout overloading template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) { for (auto it = vec.begin(); it != vec.end(); ++it) { out << *it << " "; } return out; } template <typename T> ostream &operator<<(ostream &out, const pair<T, T> &P) { out << P.first << " " << P.second; return out; } template <typename T> istream &operator>>(istream &in, vector<T> &vec) { for (auto it = vec.begin(); it != vec.end(); ++it) { in >> *it; } return in; } template <typename T> istream &operator>>(istream &in, pair<T, T> &P) { in >> P.first >> P.second; return in; } #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } // void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define all(x) (x).begin(), (x).end() #define coutp(x, y) cout << (x) << " " << (y) << endl #define coutn(x) cout << (x) << endl #define coutd(x) cout << setprecision(10) << (x) << endl /// 图相关 // ll N, M; // struct Edge { // int to; // ll weight; // int next; // bool operator<(const Edge &rhs) { return weight < rhs.weight; } // }; // template <typename T> // struct Edge2 { // T from, to, weight; // Edge2(T from_, T to_, T weight_) : from(from_), to(to_), weight(weight_) // {} Edge2() : from(T(0)), to(T(0)), weight(T(0)) {} bool operator<(const // Edge2 &rhs) { return weight < rhs.weight; } // }; // vector<Edge> edges(MAXN << 1); // vi head(MAXN, -1); // vector<int> matchingx(MAXN, -1); // vector<int> matchingy(MAXN, -1); // vector<bool> check(MAXN); // vector<ll> dis(MAXN); // vector<bool> vis(MAXN, false); // int cnt = 1; // void addEdge(int from, int to, ll weight) { // edges[cnt].to = to; // edges[cnt].weight = weight; // edges[cnt].next = head[from]; // head[from] = cnt++; // } // bool dfs(int u) { // for (int i = head[u]; i != -1; i = edges[i].next) { // int v = edges[i].to; // if (!check[v]) { // check[v] = true; // if (matchingy[v] == -1 || dfs(matchingy[v])) { // matchingy[v] = u; // matchingx[u] = v; // return true; // } // } // } // return false; // } // int hungarian() { // int ans = 0; // fill(matchingx.begin(), matchingx.end(), -1); // fill(matchingy.begin(), matchingy.end(), -1); // for (int u = 1; u <= N; ++u) { // // if (matchingx[u] == -1) { // { // fill(check.begin(), check.end(), false); // if (dfs(u)) { // ++ans; // } // } // } // return ans; // } // void dijkstra(const ll s) { // priority_queue<P, vector<P>, greater<P>> que; // fill(dis.begin(), dis.end(), INF); // dis[s] = 0; // que.push(P(0, s)); // // multiple sources // for (auto &x : shops) { // dis[x] = 0; // que.push(P(0, x)); // } // while (!que.empty()) { // P p = que.top(); // que.pop(); // cout << "pop " << p.second << endl; // int u = p.second; // if (dis[u] < p.first) continue; // for (int i = head[u]; i != -1; i = edges[i].next) { // int v = edges[i].to; // if (dis[v] > dis[u] + edges[i].weight) { // dis[v] = dis[u] + edges[i].weight; // cout << "push " << v << endl; // que.push(P(dis[v], v)); // } // } // } // } // void zeroOneBFS(const int s) { // deque<P> que; // fill(dis.begin(), dis.end(), INF); // dis[s] = 0; // que.push_front(P(0, s)); // while (!que.empty()) { // P p = que.front(); // que.pop_front(); // int u = p.second; // if (dis[u] < p.first) continue; // for (int i = head[u]; i != -1; i = edges[i].next) { // int v = edges[i].to; // if (dis[v] > dis[u] + edges[i].weight) { // dis[v] = dis[u] + edges[i].weight; // if (edges[i].weight) { // que.push_back(P(dis[v], v)); // } else { // que.push_front(P(dis[v], v)); // } // } // } // } // } /// Union-Find 并查集 class UnionFind { vector<ll> par; public: explicit UnionFind(ll n) : par(n, -1) {} ll root(ll a) { if (par[a] < 0) { return a; } return par[a] = root(par[a]); } ll size(ll a) { return -par[root(a)]; } void unite(ll a, ll b) { a = root(a); b = root(b); if (a != b) { if (size(a) < size(b)) { swap(a, b); } par[a] += par[b]; par[b] = a; } } }; // template <typename T> // ll kruskal(vector<Edge2> &edges2, const ll V) { // sort(edges2.begin(), edges2.end()); // UnionFind uf(V + 10); // ll res = 0; // Edge2 e; // for (int i = 0; i < edges2.size(); ++i) { // e = edges2[i]; // if (uf.root(e.u) != uf.root(e.v)) { // uf.unite(e.u, e.v); // res += e.w; // } // } // return res; // } /// 线段树 // struct SegmentTreeNode { // ll maxVal; // ll minVal; // ll sum; // ll len; // ll lazy; // ll left, right; // SegmentTreeNode() {} // }; // class SegmentTree { // public: // explicit SegmentTree(size_t size, const vll &nums) // : tree(size << 2), nums(nums) {} // void build(ll root, ll left, ll right) { // tree[root].lazy = 0; // tree[root].left = left; // tree[root].right = right; // tree[root].len = right - left + 1; // if (left == right) { // tree[root].maxVal = nums[left]; // tree[root].minVal = nums[left]; // tree[root].sum = nums[left]; // } else { // ll mid = (right - left) / 2 + left; // build(root * 2, left, mid); // build(root * 2 + 1, mid + 1, right); // tree[root].minVal = // min(tree[root * 2].minVal, tree[root * 2 + 1].minVal); // tree[root].maxVal = // max(tree[root * 2].maxVal, tree[root * 2 + 1].maxVal); // tree[root].sum = tree[root * 2].sum + tree[root * 2 + 1].sum; // } // } // void pushup(ll root) { // tree[root].minVal = // min(tree[root * 2].minVal, tree[root * 2 + 1].minVal); // tree[root].maxVal = // max(tree[root * 2].maxVal, tree[root * 2 + 1].maxVal); // tree[root].sum = tree[root * 2].sum + tree[root * 2 + 1].sum; // } // // add single node val // void add(ll root, ll id, ll addVal) { // if (tree[root].left == tree[root].right) { // tree[root].maxVal += addVal; // tree[root].minVal += addVal; // tree[root].sum += addVal; // return; // } // ll mid = (tree[root].right - tree[root].left) / 2 + tree[root].left; // if (id <= mid) { // add(root * 2, id, addVal); // } else { // add(root * 2 + 1, id, addVal); // } // pushup(root); // } // void pushdown(ll root) { // if (tree[root].lazy) { // tree[root * 2].lazy += tree[root].lazy; // tree[root * 2 + 1].lazy += tree[root].lazy; // tree[root * 2].sum += tree[root * 2].len * tree[root].lazy; // tree[root * 2 + 1].sum += tree[root * 2 + 1].len * // tree[root].lazy; tree[root * 2].maxVal += tree[root].lazy; // tree[root * 2 + 1].maxVal += tree[root].lazy; // tree[root * 2].minVal += tree[root].lazy; // tree[root * 2 + 1].minVal += tree[root].lazy; // tree[root].lazy = 0; // } // } // // query range sum // ll querySum(ll root, ll left, ll right) { // if (tree[root].left >= left && tree[root].right <= right) { // return tree[root].sum; // } // if (tree[root].left > right || tree[root].right < left) { // return 0; // } // if (tree[root].lazy) { // pushdown(root); // } // return querySum(root * 2, left, right) + // querySum(root * 2 + 1, left, right); // } // // query range max/min // ll queryMax(ll root, ll left, ll right) { // if (tree[root].left >= left && tree[root].right <= right) { // return tree[root].maxVal; // } // if (tree[root].left > right || tree[root].right < left) { // return -INF; // } // if (tree[root].lazy) { // pushdown(root); // } // return max(queryMax(root * 2, left, right), // queryMax(root * 2 + 1, left, right)); // } // ll queryMin(ll root, ll left, ll right) { // if (tree[root].left >= left && tree[root].right <= right) { // return tree[root].minVal; // } // if (tree[root].left > right || tree[root].right < left) { // return INF; // } // if (tree[root].lazy) { // pushdown(root); // } // return min(queryMin(root * 2, left, right), // queryMin(root * 2 + 1, left, right)); // } // // add range val // void update(ll root, ll left, ll right, ll addVal) { // if (tree[root].left >= left && tree[root].right <= right) { // tree[root].lazy += addVal; // tree[root].sum += tree[root].len * addVal; // tree[root].maxVal += addVal; // tree[root].minVal += addVal; // return; // } // if (tree[root].left > right || tree[root].right < left) { // return; // } // if (tree[root].lazy) { // pushdown(root); // } // update(root * 2, left, right, addVal); // update(root * 2 + 1, left, right, addVal); // pushup(root); // } // private: // vector<SegmentTreeNode> tree; // const vll &nums; // }; /// BIT struct BIT { private: vector<ll> node; int n; public: void init(int n_) { n = n_; node.resize(n, 0); } // 0-indexed void add(int pos, ll val) { for (int i = pos; i < n; i |= i + 1) node[i] += val; } // [0, pos) ll sum(int pos) { ll ret = 0; for (int i = pos - 1; i >= 0; i = (i & (i + 1)) - 1) ret += node[i]; return ret; } // [start, end) ll sum(int start, int end) { return sum(end) - sum(start); } }; /// 组合数 /// 約数求める // void divisor(ll n, vector<ll> &ret) { // for (ll i = 1; i * i <= n; i++) { // if (n % i == 0) { // ret.push_back(i); // if (i * i != n) ret.push_back(n / i); // } // } // sort(ret.begin(), ret.end()); // } /// 階乗 ll factorial(ll n) { ll ret = 1; for (ll i = 1; i <= n; ++i) { ret = (ret * i) % MOD; } return ret; } /// モジュラ逆数 ll inv_mod(ll n) { ll a = n % MOD, b = MOD - 2, ret = 1; while (b > 0) { if (b & 1) ret = (ret * a) % MOD; a = (a * a) % MOD; b >>= 1; } return ret; } ll nPr(ll n, ll r) { ll ret = 1; for (ll i = n; i >= n - r + 1; --i) { ret = ret * (i % MOD) % MOD; } return ret; } ll nCr(ll n, ll r) { if (r > n - r) { return nCr(n, n - r); } return nPr(n, r) * inv_mod(factorial(r)) % MOD; } // Choosing r items from n types of items possibly with duplicates of types. // Or putting r balls in n boxes possibly with empty boxes. (balls are same but // boxes aren't) ll nHr(ll n, ll r) { return nCr(n + r - 1, n - 1); } // vll F(MAXN), Finv(MAXN), inv(MAXN); // void comb_init() { // inv[1] = 1; // for (int i = 2; i < MAXN; ++i) { // inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD; // } // F[0] = Finv[0] = 1; // for (int i = 1; i < MAXN; ++i) { // F[i] = F[i - 1] * 1ll * i % MOD; // Finv[i] = Finv[i - 1] * 1ll * inv[i] % MOD; // } // } // inline ll comb(ll n, ll m) { // if (m < 0 || m > n) return 0; // return F[n] * inv[n - m] % MOD * inv[m] % MOD; // } // inline ll comb_h(ll n, ll m) { return comb(n + m - 1, n - 1); } inline ll ADD(ll a, ll b) { return (a + b) % MOD; } inline ll MUL(ll a, ll b) { return (a % MOD) * (b % MOD) % MOD; } inline ll SUB(ll a, ll b) { return (a + MOD - b) % MOD; } inline ll POW(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = (ret * a) % MOD; a = (a * a) % MOD; b >>= 1; } return ret; } inline ll nC2(ll n) { return (n * (n - 1ll)) / 2ll; } inline ll lcm(ll a, ll b) { if (!a || !b) { return 0; } return a * b / __gcd(a, b); } vector<pll> factor(ll x) { vector<pll> ans; for (ll i = 2; i * i <= x; i++) if (x % i == 0) { ans.push_back({i, 1}); while ((x /= i) % i == 0) ans.back().second++; } if (x != 1) ans.push_back({x, 1}); return ans; } vector<int> divisor(int x) { vector<int> ans; for (int i = 1; i * i <= x; i++) if (x % i == 0) { ans.push_back(i); if (i * i != x) ans.push_back(x / i); } return ans; } /// main函数 int main() { ll N; cin >> N; ll ans = 0; for (int i = 2; i * i <= N; ++i) { int cur = 0; while (N % i == 0) { ++cur; N /= i; } rep(i, 1, 100) { if (cur < i) { break; } ++ans; cur -= i; } } if (N != 1) { ++ans; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using vll = vector<ll>; using vi = vector<int>; using vb = vector<bool>; using vs = vector<string>; using pll = pair<ll, ll>; using pii = pair<int, int>; using vpii = vector<pii>; using vpll = vector<pll>; const ll LINF = 1ll << 55; const ll INF = 0x3f3f3f3f; const ll MOD = 1e9 + 7; const int MAXN = 2e5 + 10; const ll dx[] = {1, 0, -1, 0}; const ll dy[] = {0, 1, 0, -1}; /// cin/cout overloading template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) { for (auto it = vec.begin(); it != vec.end(); ++it) { out << *it << " "; } return out; } template <typename T> ostream &operator<<(ostream &out, const pair<T, T> &P) { out << P.first << " " << P.second; return out; } template <typename T> istream &operator>>(istream &in, vector<T> &vec) { for (auto it = vec.begin(); it != vec.end(); ++it) { in >> *it; } return in; } template <typename T> istream &operator>>(istream &in, pair<T, T> &P) { in >> P.first >> P.second; return in; } #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } // void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define all(x) (x).begin(), (x).end() #define coutp(x, y) cout << (x) << " " << (y) << endl #define coutn(x) cout << (x) << endl #define coutd(x) cout << setprecision(10) << (x) << endl /// 图相关 // ll N, M; // struct Edge { // int to; // ll weight; // int next; // bool operator<(const Edge &rhs) { return weight < rhs.weight; } // }; // template <typename T> // struct Edge2 { // T from, to, weight; // Edge2(T from_, T to_, T weight_) : from(from_), to(to_), weight(weight_) // {} Edge2() : from(T(0)), to(T(0)), weight(T(0)) {} bool operator<(const // Edge2 &rhs) { return weight < rhs.weight; } // }; // vector<Edge> edges(MAXN << 1); // vi head(MAXN, -1); // vector<int> matchingx(MAXN, -1); // vector<int> matchingy(MAXN, -1); // vector<bool> check(MAXN); // vector<ll> dis(MAXN); // vector<bool> vis(MAXN, false); // int cnt = 1; // void addEdge(int from, int to, ll weight) { // edges[cnt].to = to; // edges[cnt].weight = weight; // edges[cnt].next = head[from]; // head[from] = cnt++; // } // bool dfs(int u) { // for (int i = head[u]; i != -1; i = edges[i].next) { // int v = edges[i].to; // if (!check[v]) { // check[v] = true; // if (matchingy[v] == -1 || dfs(matchingy[v])) { // matchingy[v] = u; // matchingx[u] = v; // return true; // } // } // } // return false; // } // int hungarian() { // int ans = 0; // fill(matchingx.begin(), matchingx.end(), -1); // fill(matchingy.begin(), matchingy.end(), -1); // for (int u = 1; u <= N; ++u) { // // if (matchingx[u] == -1) { // { // fill(check.begin(), check.end(), false); // if (dfs(u)) { // ++ans; // } // } // } // return ans; // } // void dijkstra(const ll s) { // priority_queue<P, vector<P>, greater<P>> que; // fill(dis.begin(), dis.end(), INF); // dis[s] = 0; // que.push(P(0, s)); // // multiple sources // for (auto &x : shops) { // dis[x] = 0; // que.push(P(0, x)); // } // while (!que.empty()) { // P p = que.top(); // que.pop(); // cout << "pop " << p.second << endl; // int u = p.second; // if (dis[u] < p.first) continue; // for (int i = head[u]; i != -1; i = edges[i].next) { // int v = edges[i].to; // if (dis[v] > dis[u] + edges[i].weight) { // dis[v] = dis[u] + edges[i].weight; // cout << "push " << v << endl; // que.push(P(dis[v], v)); // } // } // } // } // void zeroOneBFS(const int s) { // deque<P> que; // fill(dis.begin(), dis.end(), INF); // dis[s] = 0; // que.push_front(P(0, s)); // while (!que.empty()) { // P p = que.front(); // que.pop_front(); // int u = p.second; // if (dis[u] < p.first) continue; // for (int i = head[u]; i != -1; i = edges[i].next) { // int v = edges[i].to; // if (dis[v] > dis[u] + edges[i].weight) { // dis[v] = dis[u] + edges[i].weight; // if (edges[i].weight) { // que.push_back(P(dis[v], v)); // } else { // que.push_front(P(dis[v], v)); // } // } // } // } // } /// Union-Find 并查集 class UnionFind { vector<ll> par; public: explicit UnionFind(ll n) : par(n, -1) {} ll root(ll a) { if (par[a] < 0) { return a; } return par[a] = root(par[a]); } ll size(ll a) { return -par[root(a)]; } void unite(ll a, ll b) { a = root(a); b = root(b); if (a != b) { if (size(a) < size(b)) { swap(a, b); } par[a] += par[b]; par[b] = a; } } }; // template <typename T> // ll kruskal(vector<Edge2> &edges2, const ll V) { // sort(edges2.begin(), edges2.end()); // UnionFind uf(V + 10); // ll res = 0; // Edge2 e; // for (int i = 0; i < edges2.size(); ++i) { // e = edges2[i]; // if (uf.root(e.u) != uf.root(e.v)) { // uf.unite(e.u, e.v); // res += e.w; // } // } // return res; // } /// 线段树 // struct SegmentTreeNode { // ll maxVal; // ll minVal; // ll sum; // ll len; // ll lazy; // ll left, right; // SegmentTreeNode() {} // }; // class SegmentTree { // public: // explicit SegmentTree(size_t size, const vll &nums) // : tree(size << 2), nums(nums) {} // void build(ll root, ll left, ll right) { // tree[root].lazy = 0; // tree[root].left = left; // tree[root].right = right; // tree[root].len = right - left + 1; // if (left == right) { // tree[root].maxVal = nums[left]; // tree[root].minVal = nums[left]; // tree[root].sum = nums[left]; // } else { // ll mid = (right - left) / 2 + left; // build(root * 2, left, mid); // build(root * 2 + 1, mid + 1, right); // tree[root].minVal = // min(tree[root * 2].minVal, tree[root * 2 + 1].minVal); // tree[root].maxVal = // max(tree[root * 2].maxVal, tree[root * 2 + 1].maxVal); // tree[root].sum = tree[root * 2].sum + tree[root * 2 + 1].sum; // } // } // void pushup(ll root) { // tree[root].minVal = // min(tree[root * 2].minVal, tree[root * 2 + 1].minVal); // tree[root].maxVal = // max(tree[root * 2].maxVal, tree[root * 2 + 1].maxVal); // tree[root].sum = tree[root * 2].sum + tree[root * 2 + 1].sum; // } // // add single node val // void add(ll root, ll id, ll addVal) { // if (tree[root].left == tree[root].right) { // tree[root].maxVal += addVal; // tree[root].minVal += addVal; // tree[root].sum += addVal; // return; // } // ll mid = (tree[root].right - tree[root].left) / 2 + tree[root].left; // if (id <= mid) { // add(root * 2, id, addVal); // } else { // add(root * 2 + 1, id, addVal); // } // pushup(root); // } // void pushdown(ll root) { // if (tree[root].lazy) { // tree[root * 2].lazy += tree[root].lazy; // tree[root * 2 + 1].lazy += tree[root].lazy; // tree[root * 2].sum += tree[root * 2].len * tree[root].lazy; // tree[root * 2 + 1].sum += tree[root * 2 + 1].len * // tree[root].lazy; tree[root * 2].maxVal += tree[root].lazy; // tree[root * 2 + 1].maxVal += tree[root].lazy; // tree[root * 2].minVal += tree[root].lazy; // tree[root * 2 + 1].minVal += tree[root].lazy; // tree[root].lazy = 0; // } // } // // query range sum // ll querySum(ll root, ll left, ll right) { // if (tree[root].left >= left && tree[root].right <= right) { // return tree[root].sum; // } // if (tree[root].left > right || tree[root].right < left) { // return 0; // } // if (tree[root].lazy) { // pushdown(root); // } // return querySum(root * 2, left, right) + // querySum(root * 2 + 1, left, right); // } // // query range max/min // ll queryMax(ll root, ll left, ll right) { // if (tree[root].left >= left && tree[root].right <= right) { // return tree[root].maxVal; // } // if (tree[root].left > right || tree[root].right < left) { // return -INF; // } // if (tree[root].lazy) { // pushdown(root); // } // return max(queryMax(root * 2, left, right), // queryMax(root * 2 + 1, left, right)); // } // ll queryMin(ll root, ll left, ll right) { // if (tree[root].left >= left && tree[root].right <= right) { // return tree[root].minVal; // } // if (tree[root].left > right || tree[root].right < left) { // return INF; // } // if (tree[root].lazy) { // pushdown(root); // } // return min(queryMin(root * 2, left, right), // queryMin(root * 2 + 1, left, right)); // } // // add range val // void update(ll root, ll left, ll right, ll addVal) { // if (tree[root].left >= left && tree[root].right <= right) { // tree[root].lazy += addVal; // tree[root].sum += tree[root].len * addVal; // tree[root].maxVal += addVal; // tree[root].minVal += addVal; // return; // } // if (tree[root].left > right || tree[root].right < left) { // return; // } // if (tree[root].lazy) { // pushdown(root); // } // update(root * 2, left, right, addVal); // update(root * 2 + 1, left, right, addVal); // pushup(root); // } // private: // vector<SegmentTreeNode> tree; // const vll &nums; // }; /// BIT struct BIT { private: vector<ll> node; int n; public: void init(int n_) { n = n_; node.resize(n, 0); } // 0-indexed void add(int pos, ll val) { for (int i = pos; i < n; i |= i + 1) node[i] += val; } // [0, pos) ll sum(int pos) { ll ret = 0; for (int i = pos - 1; i >= 0; i = (i & (i + 1)) - 1) ret += node[i]; return ret; } // [start, end) ll sum(int start, int end) { return sum(end) - sum(start); } }; /// 组合数 /// 約数求める // void divisor(ll n, vector<ll> &ret) { // for (ll i = 1; i * i <= n; i++) { // if (n % i == 0) { // ret.push_back(i); // if (i * i != n) ret.push_back(n / i); // } // } // sort(ret.begin(), ret.end()); // } /// 階乗 ll factorial(ll n) { ll ret = 1; for (ll i = 1; i <= n; ++i) { ret = (ret * i) % MOD; } return ret; } /// モジュラ逆数 ll inv_mod(ll n) { ll a = n % MOD, b = MOD - 2, ret = 1; while (b > 0) { if (b & 1) ret = (ret * a) % MOD; a = (a * a) % MOD; b >>= 1; } return ret; } ll nPr(ll n, ll r) { ll ret = 1; for (ll i = n; i >= n - r + 1; --i) { ret = ret * (i % MOD) % MOD; } return ret; } ll nCr(ll n, ll r) { if (r > n - r) { return nCr(n, n - r); } return nPr(n, r) * inv_mod(factorial(r)) % MOD; } // Choosing r items from n types of items possibly with duplicates of types. // Or putting r balls in n boxes possibly with empty boxes. (balls are same but // boxes aren't) ll nHr(ll n, ll r) { return nCr(n + r - 1, n - 1); } // vll F(MAXN), Finv(MAXN), inv(MAXN); // void comb_init() { // inv[1] = 1; // for (int i = 2; i < MAXN; ++i) { // inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD; // } // F[0] = Finv[0] = 1; // for (int i = 1; i < MAXN; ++i) { // F[i] = F[i - 1] * 1ll * i % MOD; // Finv[i] = Finv[i - 1] * 1ll * inv[i] % MOD; // } // } // inline ll comb(ll n, ll m) { // if (m < 0 || m > n) return 0; // return F[n] * inv[n - m] % MOD * inv[m] % MOD; // } // inline ll comb_h(ll n, ll m) { return comb(n + m - 1, n - 1); } inline ll ADD(ll a, ll b) { return (a + b) % MOD; } inline ll MUL(ll a, ll b) { return (a % MOD) * (b % MOD) % MOD; } inline ll SUB(ll a, ll b) { return (a + MOD - b) % MOD; } inline ll POW(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = (ret * a) % MOD; a = (a * a) % MOD; b >>= 1; } return ret; } inline ll nC2(ll n) { return (n * (n - 1ll)) / 2ll; } inline ll lcm(ll a, ll b) { if (!a || !b) { return 0; } return a * b / __gcd(a, b); } vector<pll> factor(ll x) { vector<pll> ans; for (ll i = 2; i * i <= x; i++) if (x % i == 0) { ans.push_back({i, 1}); while ((x /= i) % i == 0) ans.back().second++; } if (x != 1) ans.push_back({x, 1}); return ans; } vector<int> divisor(int x) { vector<int> ans; for (int i = 1; i * i <= x; i++) if (x % i == 0) { ans.push_back(i); if (i * i != x) ans.push_back(x / i); } return ans; } /// main函数 int main() { ll N; cin >> N; ll ans = 0; for (int i = 2; i <= 1e6 + 10; ++i) { int cur = 0; while (N % i == 0) { ++cur; N /= i; } rep(i, 1, 100) { if (cur < i) { break; } ++ans; cur -= i; } } if (N != 1) { ++ans; } cout << ans << endl; return 0; }
replace
526
527
526
527
TLE
p02660
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long int ll; const ll N_MAX = 1E+12; const int E_MAX = 50; vector<int> num; int main() { ll n; cin >> n; ll ans = 0; num.resize(E_MAX); num[0] = 0; for (int i = 1; i < E_MAX; i++) { num[i] = num[i - 1] + i; } for (int i = 2; i * i <= n; i++) { if (i * i > n) break; ll e = 0; while (n % i == 0) { n /= i; e++; } vector<int>::iterator it = lower_bound(num.begin(), num.end(), e); int pa = it - num.begin(); if (*it != e) pa--; ans += pa; } if (n > 1) ans++; cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long int ll; const ll N_MAX = 1E+12; const int E_MAX = 50; vector<int> num; int main() { ll n; cin >> n; ll ans = 0; num.resize(E_MAX); num[0] = 0; for (int i = 1; i < E_MAX; i++) { num[i] = num[i - 1] + i; } for (ll i = 2; i * i <= n; i++) { if (i * i > n) break; ll e = 0; while (n % i == 0) { n /= i; e++; } vector<int>::iterator it = lower_bound(num.begin(), num.end(), e); int pa = it - num.begin(); if (*it != e) pa--; ans += pa; } if (n > 1) ans++; cout << ans << endl; return 0; }
replace
19
20
19
20
TLE
p02660
C++
Time Limit Exceeded
#include <iostream> #include <map> #include <queue> #include <tuple> #include <vector> using namespace std; // const int MYINTMAX=2147483647; void decompose(long num, map<long, int> &data) { long a = 2; long tmp = num; // long maxv = num*num; // while(num >= a && a*a <= tmp){ vector<char> v(1000000000000, 0); while (tmp >= a) { // cout << a << " " << tmp << endl; if (tmp % a == 0) { data[a] = data[a] + 1; tmp /= a; } else { a++; } } } int main() { long N; cin >> N; long tmp = N; long n = 0; for (long i = 2; i <= tmp; i++) { int kosuu = 0; while (tmp % i == 0) { tmp = tmp / i; kosuu++; } // cout << tmp << endl; int j = 1; while (kosuu >= j) { kosuu -= j; j++; n++; } if (tmp == 1) break; } cout << n << endl; return 0; }
#include <iostream> #include <map> #include <queue> #include <tuple> #include <vector> using namespace std; // const int MYINTMAX=2147483647; void decompose(long num, map<long, int> &data) { long a = 2; long tmp = num; // long maxv = num*num; // while(num >= a && a*a <= tmp){ vector<char> v(1000000000000, 0); while (tmp >= a) { // cout << a << " " << tmp << endl; if (tmp % a == 0) { data[a] = data[a] + 1; tmp /= a; } else { a++; } } } int main() { long N; cin >> N; long tmp = N; long n = 0; for (long i = 2; i <= tmp; i++) { int kosuu = 0; while (tmp % i == 0) { tmp = tmp / i; kosuu++; } // cout << tmp << endl; int j = 1; while (kosuu >= j) { kosuu -= j; j++; n++; } if (tmp == 1) break; if (i > 1000000) { cout << n + 1 << endl; return 0; } } cout << n << endl; return 0; }
insert
50
50
50
54
TLE
p02660
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF 1000000000 #define INFLL 0x3f3f3f3f3f3f3f3fLL #define EPS 10e-9 #define MOD 1000000007 #define mp make_pair #define mt make_tuple #define pb push_back #define st first #define nd second #define sz(v) int(v.size()) #define all(X) (X).begin(), (X).end() #define FOR(I, A, B) for (int I = A; I < B; I++) #define RFOR(I, A, B) for (int I = A; I >= B; I--) typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<vii> vvii; typedef vector<iii> viii; typedef vector<ll> vll; ll _sieve_size; bitset<10000010> bs; vll primes; void sieve(ll upperbound) { _sieve_size = upperbound + 1; bs.set(); bs[0] = bs[1] = 0; for (ll i = 2; i <= _sieve_size; i++) { if (bs[i]) { for (ll j = i * i; j <= _sieve_size; j += i) { bs[j] = 0; } primes.push_back(i); } } } map<ll, ll> getPrimeFact(ll n) { ll ind = 0, pf = primes[0]; map<ll, ll> ans; while (pf * pf <= n) { while (n % pf == 0) { n /= pf; ans[pf]++; } pf = primes[++ind]; } if (n != 1) ans[n]++; return ans; } ll getans(ll e) { ll l = 1, r = 1000000; while (l < r) { ll mid = (l + r + 1) / 2; if ((mid * (mid + 1)) / 2 > e) { r = mid - 1; } else { l = mid; } } return l; } int main() { ll n; scanf("%lld", &n); sieve(1000000); map<ll, ll> fact = getPrimeFact(n); ll ans = 0; for (auto par : fact) { ll e = par.nd; // printf("e: %lld, getans: %lld\n", e, getans(e)); ans += getans(e); } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 1000000000 #define INFLL 0x3f3f3f3f3f3f3f3fLL #define EPS 10e-9 #define MOD 1000000007 #define mp make_pair #define mt make_tuple #define pb push_back #define st first #define nd second #define sz(v) int(v.size()) #define all(X) (X).begin(), (X).end() #define FOR(I, A, B) for (int I = A; I < B; I++) #define RFOR(I, A, B) for (int I = A; I >= B; I--) typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<vii> vvii; typedef vector<iii> viii; typedef vector<ll> vll; ll _sieve_size; bitset<10000010> bs; vll primes; void sieve(ll upperbound) { _sieve_size = upperbound + 1; bs.set(); bs[0] = bs[1] = 0; for (ll i = 2; i <= _sieve_size; i++) { if (bs[i]) { for (ll j = i * i; j <= _sieve_size; j += i) { bs[j] = 0; } primes.push_back(i); } } } map<ll, ll> getPrimeFact(ll n) { ll ind = 0, pf = primes[0]; map<ll, ll> ans; while (pf * pf <= n) { while (n % pf == 0) { n /= pf; ans[pf]++; } if (ind + 1 == sz(primes)) break; pf = primes[++ind]; } if (n != 1) ans[n]++; return ans; } ll getans(ll e) { ll l = 1, r = 1000000; while (l < r) { ll mid = (l + r + 1) / 2; if ((mid * (mid + 1)) / 2 > e) { r = mid - 1; } else { l = mid; } } return l; } int main() { ll n; scanf("%lld", &n); sieve(1000000); map<ll, ll> fact = getPrimeFact(n); ll ans = 0; for (auto par : fact) { ll e = par.nd; // printf("e: %lld, getans: %lld\n", e, getans(e)); ans += getans(e); } printf("%lld\n", ans); return 0; }
insert
54
54
54
56
0
p02660
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // Sieve of Eratosthenes // https://youtu.be/UTVg7wzMWQc?t=2774 struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (long long i = 2; i <= n; i++) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (long long j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<pair<int, int>> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; int main() { long long n; cin >> n; Sieve s(1000005); auto fs = s.factor(n); int ans = 0; for (auto p : fs) { int x = p.second; int b = 1; while (b <= x) { x -= b; b++; ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // Sieve of Eratosthenes // https://youtu.be/UTVg7wzMWQc?t=2774 struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (long long i = 2; i <= n; i++) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (long long j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<pair<int, int>> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } vector<long long> factorList(long long x) { vector<long long> res; for (int p : primes) { while (x % p == 0) { res.push_back(p); x /= p; } } if (x != 1) res.push_back(x); return res; } vector<pair<long long, int>> factor(long long x) { vector<long long> fl = factorList(x); if (fl.size() == 0) return {}; vector<pair<long long, int>> res(1, make_pair(fl[0], 0)); for (long long p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; int main() { long long n; cin >> n; Sieve s(1000005); auto fs = s.factor(n); int ans = 0; for (auto p : fs) { int x = p.second; int b = 1; while (b <= x) { x -= b; b++; ans++; } } cout << ans << endl; return 0; }
insert
44
44
44
71
0
p02660
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using pint = pair<int, int>; using ll = long long; using ull = unsigned long long; using vll = vector<long long>; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite) #define FI first #define SE second #define ALL(v) v.begin(), v.end() // #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back #define vint vector<int> constexpr ll INF = 1e15 + 7LL; constexpr ll MOD = 1e9 + 7LL; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (int i = 0; i < v.size(); ++i) { is >> v[i]; } return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size() - 1; ++i) { os << v[i] << " "; } if (v.size() > 0) { os << v[v.size() - 1] << endl; } return os; } int main() { ll n; cin >> n; unordered_map<ll, int> ma; for (int i = 2; i * i <= n; ++i) { while (n % i == 0) { ++ma[i]; n /= i; } } if (n != 1) { ma[n]++; } vll memo; ll ans = 0; for (auto elem : ma) { int cnt = elem.second; ll st = 0, en = 1e8; while (en - st > 1) { ll mid = (st + en) / 2; if (cnt >= mid * (mid + 1) / 2) { st = mid; } else { en = mid; } } ans += st; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using pint = pair<int, int>; using ll = long long; using ull = unsigned long long; using vll = vector<long long>; using pll = pair<ll, ll>; #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite) #define FI first #define SE second #define ALL(v) v.begin(), v.end() // #define endl "\n" #define ciosup \ cin.tie(0); \ ios::sync_with_stdio(false); #define eb emplace_back #define vint vector<int> constexpr ll INF = 1e15 + 7LL; constexpr ll MOD = 1e9 + 7LL; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (int i = 0; i < v.size(); ++i) { is >> v[i]; } return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < v.size() - 1; ++i) { os << v[i] << " "; } if (v.size() > 0) { os << v[v.size() - 1] << endl; } return os; } int main() { ll n; cin >> n; unordered_map<ll, int> ma; for (ll i = 2; i * i <= n; ++i) { while (n % i == 0) { ++ma[i]; n /= i; } } if (n != 1) { ma[n]++; } vll memo; ll ans = 0; for (auto elem : ma) { int cnt = elem.second; ll st = 0, en = 1e8; while (en - st > 1) { ll mid = (st + en) / 2; if (cnt >= mid * (mid + 1) / 2) { st = mid; } else { en = mid; } } ans += st; } cout << ans << endl; }
replace
46
47
46
47
TLE
p02660
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <vector> #define pii pair<int, int> #define fst first #define snd second #define pub push_back #define vi vector<int> #define ll long long using namespace std; int main() { ios ::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, res = 0; cin >> n; for (int i = 2; i * i <= n; i++) { ll to = 0; while (n % i == 0) { to++; n /= i; } if (to) { int val = sqrt(2 * to); if (val * (val + 1) > 2 * to) { val--; } res += val; } } if (n > 1) { res++; } cout << res << "\n"; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <vector> #define pii pair<int, int> #define fst first #define snd second #define pub push_back #define vi vector<int> #define ll long long using namespace std; int main() { ios ::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, res = 0; cin >> n; for (long long i = 2; i * i <= n; i++) { ll to = 0; while (n % i == 0) { to++; n /= i; } if (to) { int val = sqrt(2 * to); if (val * (val + 1) > 2 * to) { val--; } res += val; } } if (n > 1) { res++; } cout << res << "\n"; return 0; }
replace
19
20
19
20
TLE
p02660
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long int lli; typedef unsigned long long int ulli; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef pair<int, int> pii; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define YN(x) cout << (bool x ? "Yes" : "No") << endl; #define out(s) cout << s << endl; #define pb push_back; #define sp " "; #define INF 10000000000 void vout(vector<int> v) { for (int i = 0; i < v.size(); i++) cout << v.at(i) << endl; } int main() { lli n; cin >> n; lli nc = n; map<lli, lli> prime; lli i = 2; lli ans = 0; while (nc != 1) { if (nc % i == 0) { lli count = 0; while (nc % i == 0) { nc /= i; count++; } prime[i] = count; } i++; } for (auto v : prime) { lli count = 1, now = 0; lli per = 0; while (v.second > now) { now += count; per++; count++; if (v.second < now) { per -= 1; } } ans += per; } out(ans); }
#include <bits/stdc++.h> using namespace std; typedef long long int lli; typedef unsigned long long int ulli; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef pair<int, int> pii; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define YN(x) cout << (bool x ? "Yes" : "No") << endl; #define out(s) cout << s << endl; #define pb push_back; #define sp " "; #define INF 10000000000 void vout(vector<int> v) { for (int i = 0; i < v.size(); i++) cout << v.at(i) << endl; } int main() { lli n; cin >> n; lli nc = n; map<lli, lli> prime; lli i = 2; lli ans = 0; while (nc != 1) { if (i * i > n) { prime[n] = 1; break; } if (nc % i == 0) { lli count = 0; while (nc % i == 0) { nc /= i; count++; } prime[i] = count; } i++; } for (auto v : prime) { lli count = 1, now = 0; lli per = 0; while (v.second > now) { now += count; per++; count++; if (v.second < now) { per -= 1; } } ans += per; } out(ans); }
insert
25
25
25
29
TLE
p02660
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) bool is_prime(int n) { int x = 1; if (n < 2) return false; else if (n % 2 == 0) x = 2; else { double m = sqrt(n); bool f = false; for (int i = 3; i <= m; i += 2) { if (n % i == 0) { x = i; f = true; break; } } if (!f) return true; } int t = n; for (size_t i = 0; i < 100; i++) { if (t % x != 0) { return false; } t /= x; if (t == 1) { return true; } } } int main() { int64_t N; cin >> N; int64_t a = 0, b = 0, c = 0, x, y, z; int64_t m = N; double r = sqrt(N); for (int i = 2; i <= m; i++) { if (!is_prime(i)) { continue; } if (N % i == 0) { a++; N /= i; m /= i; } // std::cout << "test " << i << " N " << N << '\n'; if (N <= i) { break; } else if (a == 0 && i > r) { a++; break; } } // if (m<N && is_prime(N)) a++; std::cout << a << '\n'; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) bool is_prime(int n) { int x = 1; if (n < 2) return false; else if (n % 2 == 0) x = 2; else { double m = sqrt(n); bool f = false; for (int i = 3; i <= m; i += 2) { if (n % i == 0) { x = i; f = true; break; } } if (!f) return true; } int t = n; for (size_t i = 0; i < 100; i++) { if (t % x != 0) { return false; } t /= x; if (t == 1) { return true; } } } int main() { int64_t N; cin >> N; int64_t a = 0, b = 0, c = 0, x, y, z; int64_t m = N; double r = sqrt(N); for (int i = 2; i <= m; i++) { if (!is_prime(i)) { continue; } if (N % i == 0) { a++; N /= i; m /= i; } // std::cout << "test " << i << " N " << N << '\n'; if (N <= i) { break; } else if (i > 5000000) { a++; break; } } // if (m<N && is_prime(N)) a++; std::cout << a << '\n'; }
replace
54
55
54
55
TLE