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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03059 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
#define int long long
#define str string
#define rep(x, y) for (int i = x; i < y; i++)
#define REP(x, y) for (int j = x; j < y; j++)
#define all(x) x.begin(), x.end()
#define vint vector<int>
#define vchar vector<char>
#define vstr vector<string>
#define pb(n) push_back(n)
signed main() {
int A, B, N, M, count = 0, count2 = 0, count3 = 0, stack = 0;
str S, T;
int C = 'A' - 'a';
vstr W(N);
vint l(N);
vector<vchar> a(N, vchar(M));
cin >> A >> B >> N;
cout << B * (N / A) << endl;
}
| #include <bits/stdc++.h>
#include <ctype.h>
using namespace std;
#define int long long
#define str string
#define rep(x, y) for (int i = x; i < y; i++)
#define REP(x, y) for (int j = x; j < y; j++)
#define all(x) x.begin(), x.end()
#define vint vector<int>
#define vchar vector<char>
#define vstr vector<string>
#define pb(n) push_back(n)
signed main() {
int A, B, N;
cin >> A >> B >> N;
cout << B * (N / A) << endl;
}
| replace | 15 | 21 | 15 | 16 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p03059 | C++ | Time Limit Exceeded | /* ______
_______ /\ |``\ | | /
| / \ |__/ |____ |/
| / _ _\ | \ | |\
| / \ | \ |______ | \
Dept. of CSE
Comilla University
*/
#include <bits/stdc++.h>
#define pi 2 * acos(0.0)
#define ll long long
#define FIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define Node struct node
#define spc " "
#define E 2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx, ny) nx >= 0 && nx < n &&ny >= 0 && ny < m
#define ee endl
#define pii pair<int, int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[] = {0, 0, +1, -1};
int fy[] = {+1, -1, 0, 0};
using namespace std;
/// check n=1;
/// check corner case;
const int maX = 1e5 + 1;
vector<ll> Graph[maX], cost[maX];
ll visit[maX];
ll x[10];
ll y[10];
int main() {
ll a, b, c, d, cc = 0;
cin >> a >> b >> c;
double x = (b * 1.0) / (a * 1.0);
ll rem = c % a;
ll ans = c / a;
ll sum = ans * b;
ll i = 1;
double z = rem + 0.5;
while (i) {
double y = x * i * 1.0;
if (y >= z) {
sum += (i - 1);
i = 0;
}
i++;
}
cout << sum << endl;
return 0;
}
| /* ______
_______ /\ |``\ | | /
| / \ |__/ |____ |/
| / _ _\ | \ | |\
| / \ | \ |______ | \
Dept. of CSE
Comilla University
*/
#include <bits/stdc++.h>
#define pi 2 * acos(0.0)
#define ll long long
#define FIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define Node struct node
#define spc " "
#define E 2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx, ny) nx >= 0 && nx < n &&ny >= 0 && ny < m
#define ee endl
#define pii pair<int, int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[] = {0, 0, +1, -1};
int fy[] = {+1, -1, 0, 0};
using namespace std;
/// check n=1;
/// check corner case;
const int maX = 1e5 + 1;
vector<ll> Graph[maX], cost[maX];
ll visit[maX];
ll x[10];
ll y[10];
int main() {
ll a, b, c, d, cc = 0;
cin >> a >> b >> c;
ll x = c / a;
cout << x * b << endl;
return 0;
}
| replace | 42 | 57 | 42 | 44 | TLE | |
p03059 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int sumDigits(int n) {
int s;
while (n < 0) {
s += n % 10;
n /= 10;
}
return s;
}
int main() {
int A, B;
int ans = 0;
float T;
cin >> A >> B >> T;
int n = 1;
while (A * n <= T + 0.5) {
ans += B;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int sumDigits(int n) {
int s;
while (n < 0) {
s += n % 10;
n /= 10;
}
return s;
}
int main() {
int A, B;
int ans = 0;
float T;
cin >> A >> B >> T;
int n = 1;
while (A * n <= T + 0.5) {
ans += B;
n += 1;
}
cout << ans << endl;
} | insert | 21 | 21 | 21 | 22 | TLE | |
p03059 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define OO 1e9
#define SS second
#define FF first
#define Trace(n) cout << #n << " = " << n << endl;
#define ll long long
// #define endl "\n"
#define all(v) ((v).begin()), ((v).end())
#define boom main
#define cn(n) scanf("%d", &n)
#define cnl(n) scanf("%lld", &n)
#define F(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define Fill(ar, val) memset(ar, val, sizeof(ar))
#define bit(n) (1 << (n))
int dx[] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[] = {-1, 1, 0, 0, 1, -1, 1, -1};
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
fast();
int a, b, T;
cin >> a >> b >> T;
int ans = 0;
int tm = 0;
while (tm + a <= T)
ans += b, tm += a;
cout << ans;
} | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define OO 1e9
#define SS second
#define FF first
#define Trace(n) cout << #n << " = " << n << endl;
#define ll long long
// #define endl "\n"
#define all(v) ((v).begin()), ((v).end())
#define boom main
#define cn(n) scanf("%d", &n)
#define cnl(n) scanf("%lld", &n)
#define F(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define Fill(ar, val) memset(ar, val, sizeof(ar))
#define bit(n) (1 << (n))
int dx[] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[] = {-1, 1, 0, 0, 1, -1, 1, -1};
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fast();
int a, b, T;
cin >> a >> b >> T;
int ans = 0;
int tm = 0;
while (tm + a <= T)
ans += b, tm += a;
cout << ans;
} | delete | 29 | 34 | 29 | 29 | 0 | |
p03059 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int a, b, t;
a = atoi(argv[1]);
b = atoi(argv[2]);
t = atoi(argv[3]);
int n = t / a;
printf("%d\n", b * n);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int a, b, t;
scanf("%d %d %d", &a, &b, &t);
int n = t / a;
printf("%d\n", b * n);
return 0;
}
| replace | 5 | 9 | 5 | 6 | -11 | |
p03059 | C++ | Time Limit Exceeded | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// using ll=long long;
// #define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; // 円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) { // 階乗
if (i == 0)
return 1;
return (fact(i - 1)) * i;
}
int gcd(int a, int b) { // 最大公約数
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { // 最小公倍数
return a * b / gcd(a, b);
}
int keta(int n) { // 桁数を求める
if (n == 0)
return 1;
int count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
int ketasum(int n) { // 各桁の和
int sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
// 最小化問題(DP)
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
// 最大化問題(DP)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
/*-------------ここまで---------------------------------------------*/
/*signed*/ int main() {
int a, b, t;
cin >> a >> b >> t;
t += 0.5;
int i = 0;
while (true) {
t -= a * i;
if (t < 0) {
cout << i << endl;
return 0;
}
}
return 0;
} | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// using ll=long long;
// #define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; // 円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) { // 階乗
if (i == 0)
return 1;
return (fact(i - 1)) * i;
}
int gcd(int a, int b) { // 最大公約数
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { // 最小公倍数
return a * b / gcd(a, b);
}
int keta(int n) { // 桁数を求める
if (n == 0)
return 1;
int count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
int ketasum(int n) { // 各桁の和
int sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
// 最小化問題(DP)
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
// 最大化問題(DP)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
/*-------------ここまで---------------------------------------------*/
/*signed*/ int main() {
int a, b, t;
cin >> a >> b >> t;
cout << (t / a) * b << endl;
return 0;
} | replace | 100 | 109 | 100 | 101 | TLE | |
p03059 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, T;
int sum;
for (int i = 1; A * i < T + 0.5; i++) {
sum += B;
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, T;
int sum;
cin >> A >> B >> T;
for (int i = 1; A * i < T + 0.5; i++) {
sum += B;
}
cout << sum << endl;
} | insert | 8 | 8 | 8 | 9 | TLE | |
p03059 | Python | Runtime Error | a, b, t = (int(i) for i in input())
times = int(t / a)
num = times * b
print(num)
| a, b, t = (int(i) for i in input().split())
times = int(t / a)
num = times * b
print(num)
| replace | 0 | 1 | 0 | 1 | ValueError: invalid literal for int() with base 10: ' ' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03059/Python/s003873800.py", line 1, in <module>
a, b, t = (int(i) for i in input())
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03059/Python/s003873800.py", line 1, in <genexpr>
a, b, t = (int(i) for i in input())
ValueError: invalid literal for int() with base 10: ' '
|
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> V(N);
vector<int> C(N);
long long answer = 0;
for (int i = 0; i < N; i++) {
cin >> V.at(i);
cin >> C.at(N);
if (V.at(i) - C.at(i) > 0) {
answer += V.at(i) - C.at(i);
}
}
cout << answer << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> V(N);
vector<int> C(N);
long long answer = 0;
for (int i = 0; i < N; i++) {
cin >> V.at(i);
}
for (int i = 0; i < N; i++) {
cin >> C.at(i);
}
for (int i = 0; i < N; i++) {
if (V.at(i) - C.at(i) > 0) {
answer += V.at(i) - C.at(i);
}
}
cout << answer << endl;
}
| replace | 10 | 11 | 10 | 15 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fw(p) for (int w = 0; w < (p); w++)
#define fx(p) for (int x = 0; x < (p); x++)
#define fy(p) for (int y = 0; y < (p); y++)
#define fz(p) for (int z = 0; z < (p); z++)
#define fyg(p, g) for (int y = (g); y < (p); y++)
#define fzg(p, g) for (int z = (g); z < (p); z++)
#define ce(d) cout << d << endl;
#define vecp(p) \
int aa; \
cin >> aa; \
(p).push_back(aa);
#define vecpl(p) \
long long aa; \
cin >> aa; \
(p).push_back(aa);
#define vecps(p) \
string aa; \
cin >> aa; \
(p).push_back(aa);
#define vecp2(p) \
cin >> aa; \
(p).push_back(aa);
#define vecpl2(p) \
long long a b; \
cin >> ab; \
(p).push_back(ab);
#define vecps2(p) \
string ab; \
cin >> ab; \
(p).push_back(ab);
#define set0(k, n) \
for (int nn = 0; nn < (n); nn++) { \
(k).push_back(0); \
}
#define sorts(c) sort((c).begin(), (c).end());
#define reverses(c) reverse((c).begin(), (c).end());
#define vec(b) vector<int>(b);
#define vecl(b) vector<long long>(b);
#define vecs(b) vector<string>(b);
#define vecsize(b, size) vector<int>(b)((size));
#define pb(b, a) (b).push_back((a));
#define doublece(a, b) cout << (a) << ' ' << (b) << endl;
#define pairs(s) vector<pair<int, int>>(s);
#define pairsl(s) vector<pair<ll, ll>>(s);
#define pairss(s) vector<pair<string, string>>(s);
#define pairsp(s) \
int aa, bb; \
cin >> aa >> bb; \
(s).push_back(make_pair(aa, bb));
#define pairspl(s) \
ll aa, bb; \
cin >> aa >> bb; \
(s).push_back(make_pair(aa, bb));
#define pairsps(s) \
string aa, bb; \
cin >> aa >> bb; \
(s).push_back(make_pair(aa, bb));
#define pairsREV(s) (s).push_back(make_pair(bb, aa));
#define pairslREV(s) (s).push_back(make_pair(bb, aa));
#define pairssREV(s) (s).push_back(make_pair(bb, aa));
#define MOD 1000000007
int main() {
int N;
vec(V) vec(C) cin >> N;
vec(M) fx(N){vecp(V)} fx(N) { vecp(C) pb(M, V.at(x) - C.at(x)) }
int ans = 0;
sorts(M) reverses(M) int i = 0;
while (M.at(i) > 0) {
ans += M.at(i);
i++;
}
ce(ans)
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fw(p) for (int w = 0; w < (p); w++)
#define fx(p) for (int x = 0; x < (p); x++)
#define fy(p) for (int y = 0; y < (p); y++)
#define fz(p) for (int z = 0; z < (p); z++)
#define fyg(p, g) for (int y = (g); y < (p); y++)
#define fzg(p, g) for (int z = (g); z < (p); z++)
#define ce(d) cout << d << endl;
#define vecp(p) \
int aa; \
cin >> aa; \
(p).push_back(aa);
#define vecpl(p) \
long long aa; \
cin >> aa; \
(p).push_back(aa);
#define vecps(p) \
string aa; \
cin >> aa; \
(p).push_back(aa);
#define vecp2(p) \
cin >> aa; \
(p).push_back(aa);
#define vecpl2(p) \
long long a b; \
cin >> ab; \
(p).push_back(ab);
#define vecps2(p) \
string ab; \
cin >> ab; \
(p).push_back(ab);
#define set0(k, n) \
for (int nn = 0; nn < (n); nn++) { \
(k).push_back(0); \
}
#define sorts(c) sort((c).begin(), (c).end());
#define reverses(c) reverse((c).begin(), (c).end());
#define vec(b) vector<int>(b);
#define vecl(b) vector<long long>(b);
#define vecs(b) vector<string>(b);
#define vecsize(b, size) vector<int>(b)((size));
#define pb(b, a) (b).push_back((a));
#define doublece(a, b) cout << (a) << ' ' << (b) << endl;
#define pairs(s) vector<pair<int, int>>(s);
#define pairsl(s) vector<pair<ll, ll>>(s);
#define pairss(s) vector<pair<string, string>>(s);
#define pairsp(s) \
int aa, bb; \
cin >> aa >> bb; \
(s).push_back(make_pair(aa, bb));
#define pairspl(s) \
ll aa, bb; \
cin >> aa >> bb; \
(s).push_back(make_pair(aa, bb));
#define pairsps(s) \
string aa, bb; \
cin >> aa >> bb; \
(s).push_back(make_pair(aa, bb));
#define pairsREV(s) (s).push_back(make_pair(bb, aa));
#define pairslREV(s) (s).push_back(make_pair(bb, aa));
#define pairssREV(s) (s).push_back(make_pair(bb, aa));
#define MOD 1000000007
int main() {
int N;
vec(V) vec(C) cin >> N;
vec(M) fx(N){vecp(V)} fx(N) { vecp(C) pb(M, V.at(x) - C.at(x)) }
int ans = 0;
sorts(M) reverses(M) int i = 0;
while (i < N && M.at(i) > 0) {
ans += M.at(i);
i++;
}
ce(ans)
} | replace | 71 | 72 | 71 | 72 | 0 | |
p03060 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vn;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
vn.push_back(a);
}
vector<int> vc;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
vc.push_back(a);
}
vector<int> va;
for (int i = 0; i < n; ++i) {
va.push_back(vn[i] - vc[i]);
}
sort(va.begin(), va.end(), greater<int>());
int a = 0, i = 0;
while (va[i] >= 0) {
a += va[i];
i++;
}
cout << a << endl;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vn;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
vn.push_back(a);
}
vector<int> vc;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
vc.push_back(a);
}
vector<int> va;
for (int i = 0; i < n; ++i) {
va.push_back(vn[i] - vc[i]);
}
sort(va.begin(), va.end(), greater<int>());
int a = 0, i = 0;
while (i < n && va[i] >= 0) {
a += va[i];
i++;
}
cout << a << endl;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ll long long
ll INF = 10001000100;
int main() {
int n;
cin >> n;
vector<int> v(n);
vector<int> c(n);
rep(i, n) cin >> v[i];
rep(i, n) cin >> c[i];
bitset<20> sum;
int ans = 0;
rep(i, 1 << n) {
if (v[i] > c[i])
ans += v[i] - c[i];
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ll long long
ll INF = 10001000100;
int main() {
int n;
cin >> n;
vector<int> v(n);
vector<int> c(n);
rep(i, n) cin >> v[i];
rep(i, n) cin >> c[i];
bitset<20> sum;
int ans = 0;
rep(i, n) {
if (v[i] > c[i])
ans += v[i] - c[i];
}
cout << ans << endl;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, ans = 0;
cin >> N;
vector<int> vec1, vec2;
for (int i = 0; i < N; i++)
cin >> vec1[i];
for (int j = 0; j < N; j++)
cin >> vec2[j];
for (int k = 0; k < N; k++) {
if (vec1[k] > vec2[k]) {
ans += vec1[k];
ans -= vec2[k];
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, ans = 0;
cin >> N;
vector<int> vec1(20), vec2(20);
for (int i = 0; i < N; i++)
cin >> vec1[i];
for (int j = 0; j < N; j++)
cin >> vec2[j];
for (int k = 0; k < N; k++) {
if (vec1[k] > vec2[k]) {
ans += vec1[k];
ans -= vec2[k];
}
}
cout << ans << endl;
} | replace | 6 | 7 | 6 | 7 | -11 | |
p03060 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define __ \
{ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout); \
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
__;
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int ans = 0;
for (int i = 0; i < n; i++) {
ans += max(0, a[i] - b[i]);
}
cout << ans;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define __ \
{ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout); \
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// __;
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int ans = 0;
for (int i = 0; i < n; i++) {
ans += max(0, a[i] - b[i]);
}
cout << ans;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v.at(i);
}
vector<int> w(n);
for (int i = 0; i < n; i++) {
cin >> w.at(i);
}
vector<int> vw(n);
for (int i = 0; i < n; i++) {
vw.at(i) = v.at(i) - w.at(i);
}
sort(vw.begin(), vw.end());
reverse(vw.begin(), vw.end());
int count = 0;
int j = 0;
while ((vw.at(j) > 0) && (j < n)) {
count += vw.at(j);
j++;
}
cout << count << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v.at(i);
}
vector<int> w(n);
for (int i = 0; i < n; i++) {
cin >> w.at(i);
}
vector<int> vw(n);
for (int i = 0; i < n; i++) {
vw.at(i) = v.at(i) - w.at(i);
}
sort(vw.begin(), vw.end());
reverse(vw.begin(), vw.end());
int count = 0;
int j = 0;
while ((j < n) && (vw.at(j) > 0)) {
count += vw.at(j);
j++;
}
cout << count << endl;
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p03060 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rept(i, a, b) for (int i = a; i < b; i++)
#define ll long long
#define MOD 1000000007
#define IMIN INT_MIN;
#define IMAX INT_MAX;
int main() {
int N;
cin >> N;
vector<int> V, C;
rep(i, N) cin >> V[i];
rep(i, N) cin >> C[i];
int sum = 0;
rep(i, N) if (V[i] - C[i] > 0) sum += V[i] - C[i];
cout << sum << endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rept(i, a, b) for (int i = a; i < b; i++)
#define ll long long
#define MOD 1000000007
#define IMIN INT_MIN;
#define IMAX INT_MAX;
int main() {
int N;
cin >> N;
vector<int> V(N), C(N);
rep(i, N) cin >> V[i];
rep(i, N) cin >> C[i];
int sum = 0;
rep(i, N) if (V[i] - C[i] > 0) sum += V[i] - C[i];
cout << sum << endl;
return 0;
}
| replace | 27 | 28 | 27 | 28 | -11 | |
p03060 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define INFLL (1ll << 60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
void mul_mod(ll &a, ll b) {
a *= b;
a %= MOD;
}
void add_mod(ll &a, ll b) {
a += b;
a %= MOD;
}
ll v[22], c[22];
int main(void) {
int n, i, j;
ll ans = -INFLL, tmp;
cin >> n;
for (i = 0; i < n; ++i) {
cin >> v[i];
}
for (i = 0; i < n; ++i) {
cin >> c[i];
}
for (i = 0; i < (1 << n); ++i) {
tmp = 0ll;
for (j = 0; j < n; ++j) {
if (i & (1 << j)) {
tmp += v[i] - c[i];
}
}
ans = max(tmp, ans);
}
cout << ans << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define INFLL (1ll << 60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
void mul_mod(ll &a, ll b) {
a *= b;
a %= MOD;
}
void add_mod(ll &a, ll b) {
a += b;
a %= MOD;
}
ll v[22], c[22];
int main(void) {
int n, i, j;
ll ans = -INFLL, tmp;
cin >> n;
for (i = 0; i < n; ++i) {
cin >> v[i];
}
for (i = 0; i < n; ++i) {
cin >> c[i];
}
for (i = 0; i < (1 << n); ++i) {
tmp = 0ll;
for (j = 0; j < n; ++j) {
if (i & (1 << j)) {
tmp += v[j] - c[j];
}
}
ans = max(tmp, ans);
}
cout << ans << endl;
return 0;
}
| replace | 36 | 37 | 36 | 37 | 0 | |
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int max = 0;
int V[n], C[n];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> V[i];
}
for (int i = 0; i < n; i++) {
cin >> C[i];
}
for (int i = 0; i < n; i++) {
if (V[i] > C[i]) {
max += V[i] - C[i];
}
}
cout << max << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int max = 0;
vector<int> V(n);
vector<int> C(n);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> V[i];
}
for (int i = 0; i < n; i++) {
cin >> C[i];
}
for (int i = 0; i < n; i++) {
if (V[i] > C[i]) {
max += V[i] - C[i];
}
}
cout << max << endl;
return 0;
}
| replace | 5 | 6 | 5 | 7 | 0 | |
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < n; i++)
int main() {
int n;
int v[n + 10];
int c[n + 10];
cin >> n;
REP(i, n) { cin >> v[i]; }
REP(i, n) { cin >> c[i]; }
int ans = 0;
REP(i, n) {
if (v[i] - c[i] > 0) {
ans += v[i] - c[i];
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < n; i++)
int main() {
int n;
int v[n + 100];
int c[n + 100];
cin >> n;
REP(i, n) { cin >> v[i]; }
REP(i, n) { cin >> c[i]; }
int ans = 0;
REP(i, n) {
if (v[i] - c[i] > 0) {
ans += v[i] - c[i];
}
}
cout << ans << endl;
} | replace | 10 | 12 | 10 | 12 | 0 | |
p03060 | C++ | Runtime Error | /*
Author: ankrypt
*/
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
ll N;
ll Vs[25];
ll Cs[25];
ll dp[25][55][55];
ll rec(int ind, int val, int cost) {
if (ind == N) {
return val - cost;
}
ll &ans = dp[ind][val][cost];
if (ans != -1) {
return ans;
}
ans =
max(rec(ind + 1, val, cost), rec(ind + 1, val + Vs[ind], cost + Cs[ind]));
return ans;
}
int main() {
scanf("%lld", &N);
for (int i = 0; i < N; i++) {
scanf("%lld", &Vs[i]);
}
for (int i = 0; i < N; i++) {
scanf("%lld", &Cs[i]);
}
memset(dp, -1, sizeof(dp));
cout << rec(0, 0, 0);
return 0;
}
/*
Powered by Buggy Plugin
*/
| /*
Author: ankrypt
*/
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
ll N;
ll Vs[25];
ll Cs[25];
ll dp[25][2005][2005];
ll rec(int ind, int val, int cost) {
if (ind == N) {
return val - cost;
}
ll &ans = dp[ind][val][cost];
if (ans != -1) {
return ans;
}
ans =
max(rec(ind + 1, val, cost), rec(ind + 1, val + Vs[ind], cost + Cs[ind]));
return ans;
}
int main() {
scanf("%lld", &N);
for (int i = 0; i < N; i++) {
scanf("%lld", &Vs[i]);
}
for (int i = 0; i < N; i++) {
scanf("%lld", &Cs[i]);
}
memset(dp, -1, sizeof(dp));
cout << rec(0, 0, 0);
return 0;
}
/*
Powered by Buggy Plugin
*/
| replace | 15 | 16 | 15 | 16 | 0 | |
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int sum = 0;
vector<int> v, c;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 0; i < n; i++) {
cin >> c[i];
}
for (int i = 0; i < n; i++) {
if (v[i] - c[i] > 0) {
sum += v[i] - c[i];
}
}
cout << sum << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int sum = 0;
vector<int> v(n), c(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
for (int i = 0; i < n; i++) {
cin >> c[i];
}
for (int i = 0; i < n; i++) {
if (v[i] - c[i] > 0) {
sum += v[i] - c[i];
}
}
cout << sum << endl;
}
| replace | 7 | 8 | 7 | 8 | -11 | |
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define C continue;
#define D double
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define vi vector<int>
#define vs vector<string>
#define vb vector<bool>
#define vd vector<D>
#define vll vector<ll>
#define vull vector<ull>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define all(v) (v).begin(), (v).end()
#define allrev(v) (v).rbegin(), (v).rend()
#define pii pair<int, int>
#define vii vector<pii>
#define F first
#define S second
#define mp make_pair
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define mod 1000000007
#define pp(n) printf("%.10f", n);
#define line cout << "\n";
const D pie = acos(-1);
const D hpie = asin(1);
const D qpie = atan2(-1, 1);
const D tpie = 2 * pie;
void solve(int test_case) {
int n;
cin >> n;
vi a;
vi b;
int ans = 0;
int temp;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
cin >> temp;
ans += max(0, a[i] - temp);
}
cout << ans << "\n";
}
int main() {
fast int t = 1;
// cin>>t;
for (int i = 0; i < t; i++)
solve(i);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define C continue;
#define D double
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define vi vector<int>
#define vs vector<string>
#define vb vector<bool>
#define vd vector<D>
#define vll vector<ll>
#define vull vector<ull>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define all(v) (v).begin(), (v).end()
#define allrev(v) (v).rbegin(), (v).rend()
#define pii pair<int, int>
#define vii vector<pii>
#define F first
#define S second
#define mp make_pair
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define mod 1000000007
#define pp(n) printf("%.10f", n);
#define line cout << "\n";
const D pie = acos(-1);
const D hpie = asin(1);
const D qpie = atan2(-1, 1);
const D tpie = 2 * pie;
void solve(int test_case) {
int n;
cin >> n;
vi a(n);
int ans = 0;
int temp;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
cin >> temp;
ans += max(0, a[i] - temp);
}
cout << ans << "\n";
}
int main() {
fast int t = 1;
// cin>>t;
for (int i = 0; i < t; i++)
solve(i);
return 0;
}
| replace | 46 | 48 | 46 | 47 | -11 | |
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < b; i++)
int main() {
int n;
cin >> n;
int ans = 0;
vector<int> v, c;
rep(i, 0, n) { cin >> v[i]; }
rep(i, 0, n) {
cin >> c[i];
if (v[i] > c[i])
ans += v[i] - c[i];
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = a; i < b; i++)
int main() {
int n;
cin >> n;
int ans = 0;
vector<int> v(n), c(n);
rep(i, 0, n) { cin >> v[i]; }
rep(i, 0, n) {
cin >> c[i];
if (v[i] > c[i])
ans += v[i] - c[i];
}
cout << ans;
}
| replace | 8 | 9 | 8 | 9 | -11 | |
p03060 | C++ | Runtime Error | /** Author: Nicklaus **/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
int main() {
int n;
cin >> n;
vector<int> a(n), b(b);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int ans = 0;
for (int i = 0; i < (1 << n); i++) {
int x = 0, y = 0;
for (int j = 0; j < n; j++) {
if ((1 << j) & i) {
y += b[j];
x += a[j];
}
}
ans = max(ans, x - y);
}
cout << ans << endl;
} | /** Author: Nicklaus **/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
int main() {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int ans = 0;
for (int i = 0; i < (1 << n); i++) {
int x = 0, y = 0;
for (int j = 0; j < n; j++) {
if ((1 << j) & i) {
y += b[j];
x += a[j];
}
}
ans = max(ans, x - y);
}
cout << ans << endl;
} | replace | 10 | 11 | 10 | 11 | -6 | terminate called after throwing an instance of 'std::bad_array_new_length'
what(): std::bad_array_new_length
|
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
vector<int> V(N);
vector<int> C(N);
int P = 0;
cin >> N;
// N個の宝石の価値を代入する
for (int i = 0; i < N; i++) {
cin >> V.at(i);
}
// N個の宝石のコストを代入する
for (int i = 0; i < N; i++) {
cin >> C.at(i);
}
// 宝石の価値とコストを比較する
// 0以上であれば利益が出るので、Pに代入する
for (int i = 0; i < N; i++) {
if (V.at(i) - C.at(i) > 0) {
P += V.at(i) - C.at(i);
}
}
cout << P;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
vector<int> V(21);
vector<int> C(21);
int P = 0;
cin >> N;
// N個の宝石の価値を代入する
for (int i = 0; i < N; i++) {
cin >> V.at(i);
}
// N個の宝石のコストを代入する
for (int i = 0; i < N; i++) {
cin >> C.at(i);
}
// 宝石の価値とコストを比較する
// 0以上であれば利益が出るので、Pに代入する
for (int i = 0; i < N; i++) {
if (V.at(i) - C.at(i) > 0) {
P += V.at(i) - C.at(i);
}
}
cout << P;
}
| replace | 5 | 7 | 5 | 7 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, s = 0, ans = 0;
cin >> n;
vector<int> a(n), b(n), c(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i);
}
for (int i = 0; i < n; i++) {
cin >> b.at(i);
c.at(i) = a.at(i) - b.at(i);
}
sort(c.begin(), c.end());
reverse(c.begin(), c.end());
while (true) {
if (c.at(s) < 0)
break;
ans = c.at(s) + ans;
s++;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, s = 0, ans = 0;
cin >> n;
vector<int> a(n), b(n), c(n);
for (int i = 0; i < n; i++) {
cin >> a.at(i);
}
for (int i = 0; i < n; i++) {
cin >> b.at(i);
c.at(i) = a.at(i) - b.at(i);
}
sort(c.begin(), c.end());
reverse(c.begin(), c.end());
while (true) {
if (s == n)
break;
if (c.at(s) < 0)
break;
ans = c.at(s) + ans;
s++;
}
cout << ans << endl;
}
| insert | 16 | 16 | 16 | 18 | 0 | |
p03060 | C++ | Time Limit Exceeded | #include <cfenv>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int V[20], C[20];
int main() {
int N;
cin >> N;
for (int i = 0; i < N; ++i)
cin >> V[i];
for (int i = 0; i < N; ++i)
cin >> C[i];
int sum = 0;
for (int i = 0; N; ++i) {
int a = V[i] - C[i];
if (a > 0)
sum += a;
}
cout << sum << endl;
return 0;
} | #include <cfenv>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int V[20], C[20];
int main() {
int N;
cin >> N;
for (int i = 0; i < N; ++i)
cin >> V[i];
for (int i = 0; i < N; ++i)
cin >> C[i];
int sum = 0;
for (int i = 0; i < N; ++i) {
int a = V[i] - C[i];
if (a > 0)
sum += a;
}
cout << sum << endl;
return 0;
} | replace | 15 | 16 | 15 | 16 | TLE | |
p03060 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int N, c, sum;
int V[10];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> V[i];
}
sum = 0;
for (int i = 0; i < N; i++) {
cin >> c;
if (c < V[i]) {
sum += V[i] - c;
}
}
cout << sum << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int N, c, sum;
int V[20];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> V[i];
}
sum = 0;
for (int i = 0; i < N; i++) {
cin >> c;
if (c < V[i]) {
sum += V[i] - c;
}
}
cout << sum << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p03060 | C++ | Runtime Error | #include <iostream>
#include <vector>
// #include <fstream>
using namespace std;
int main(int argc, const char *argv[]) {
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
int N;
cin >> N;
int max = 0;
vector<int> V, C;
for (int i = 0; i < N; i++) {
cin >> V[i];
}
for (int i = 0; i < N; i++) {
cin >> C[i];
}
for (int i = 0; i < N; i++) {
if (V[i] > C[i])
max += V[i] - C[i];
}
cout << max << endl;
return 0;
}
| #include <iostream>
#include <vector>
// #include <fstream>
using namespace std;
int main(int argc, const char *argv[]) {
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
int N;
cin >> N;
int max = 0;
vector<int> V(N), C(N);
for (int i = 0; i < N; i++) {
cin >> V[i];
}
for (int i = 0; i < N; i++) {
cin >> C[i];
}
for (int i = 0; i < N; i++) {
if (V[i] > C[i])
max += V[i] - C[i];
}
cout << max << endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | -11 | |
p03060 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a, b;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] > b[i])
ans += a[i] - b[i];
}
cout << ans;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
cin >> b[i];
int ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] > b[i])
ans += a[i] - b[i];
}
cout << ans;
}
| replace | 6 | 7 | 6 | 7 | -11 | |
p03060 | Python | Time Limit Exceeded | def main():
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
maxi = 0
for i in range(2**N):
binary = list(map(int, format(i, "b").zfill(N)))
ans = 0
for j, k in enumerate(binary):
if k == 1:
ans += V[j] - C[j]
if ans > maxi:
maxi = ans
print(maxi)
if __name__ == "__main__":
main()
| def main():
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
K = [V[i] - C[i] for i in range(N)]
ans = 0
for k in K:
if k > 0:
ans += k
print(ans)
if __name__ == "__main__":
main()
| replace | 4 | 15 | 4 | 10 | TLE | |
p03060 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
int N;
cin >> N;
vector<int> V, C, S;
rep(i, N) cin >> V.at(i);
rep(i, N) cin >> C.at(i);
int answer = 0;
rep(i, N) S.at(i) = V.at(i) - C.at(i);
rep(i, N) {
if (S.at(i) > 0)
answer += S.at(i);
}
cout << answer << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
int N;
cin >> N;
vector<int> V(30), C(30), S(30);
rep(i, N) cin >> V.at(i);
rep(i, N) cin >> C.at(i);
int answer = 0;
rep(i, N) S.at(i) = V.at(i) - C.at(i);
rep(i, N) {
if (S.at(i) > 0)
answer += S.at(i);
}
cout << answer << endl;
}
| replace | 8 | 9 | 8 | 9 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
|
p03060 | Python | Time Limit Exceeded | n = int(input())
vs = list(map(int, input().split()))
cs = list(map(int, input().split()))
ret = -float("inf")
for i in range((2**n)):
total_cost = 0
total_value = 0
j = 0
while i > 0:
if i & 1:
total_cost += cs[j]
total_value += vs[j]
i >>= 1
j += 1
ret = max(ret, total_value - total_cost)
print(ret)
| n = int(input())
vs = list(map(int, input().split()))
cs = list(map(int, input().split()))
# ret = - float('inf')
# for i in range((2 ** n)):
# total_cost = 0
# total_value = 0
# j = 0
# while i > 0:
# if i & 1:
# total_cost += cs[j]
# total_value += vs[j]
# i >>= 1
# j += 1
# ret = max(ret, total_value - total_cost)
# print(ret)
x = 0
y = 0
for i in range(n):
if vs[i] > cs[i]:
x += vs[i]
y += cs[i]
print(x - y)
| replace | 4 | 17 | 4 | 25 | TLE | |
p03060 | Python | Time Limit Exceeded | def resolve():
N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
maxA = 0
for i in range(2**N):
X = 0
Y = 0
for j in range(N):
if (i >> j) & 1:
X += V[j]
Y += C[j]
maxA = max(maxA, X - Y)
print(maxA)
resolve()
| def resolve():
N = int(input())
V = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ans = 0
for i in range(N):
if V[i] > C[i]:
ans += V[i] - C[i]
print(ans)
resolve()
| replace | 4 | 14 | 4 | 9 | TLE | |
p03060 | Python | Runtime Error | def sub():
N, Vs, Cs = [e for e in input().split(" ")]
N = int(N)
Vs = [int(e) for e in Vs.split(" ")]
Cs = [int(e) for e in Cs.split(" ")]
ds = [v - c for v, c in zip(Vs, Cs)]
ds = [d for d in ds if d > 0]
print(sum(ds))
sub()
| def sub():
N, Vs, Cs = [input() for _ in range(3)]
N = int(N)
Vs = [int(e) for e in Vs.split(" ")]
Cs = [int(e) for e in Cs.split(" ")]
ds = [v - c for v, c in zip(Vs, Cs)]
ds = [d for d in ds if d > 0]
print(sum(ds))
sub()
| replace | 1 | 2 | 1 | 2 | ValueError: not enough values to unpack (expected 3, got 1) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03060/Python/s308117687.py", line 11, in <module>
sub()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03060/Python/s308117687.py", line 2, in sub
N, Vs, Cs = [e for e in input().split(" ")]
ValueError: not enough values to unpack (expected 3, got 1)
|
p03060 | Python | Time Limit Exceeded | N = int(input())
vlist = list(map(int, input().split()))
clist = list(map(int, input().split()))
ans = -100000000000
for num in range(2**N):
value = cost = 0
for i in range(N):
if (num >> i) & 1 == 1:
value += vlist[i]
cost += clist[i]
if value - cost > ans:
ans = value - cost
print(ans)
| N = int(input())
vlist = list(map(int, input().split()))
clist = list(map(int, input().split()))
ans = 0
for i in range(N):
if vlist[i] - clist[i] > 0:
ans += vlist[i] - clist[i]
print(ans)
| replace | 3 | 13 | 3 | 7 | TLE | |
p03060 | Python | Runtime Error | n = int(input())
v = [int(item) for item in input().split()]
c = [int(item) for item in input().split()]
d = [[v[i], c[i]] for i in range(n)]
d.sort(key=lambda x: x[0] - x[1], reverse=True)
ans = 0
i = 0
while d[i][0] - d[i][1] > 0:
ans += d[i][0] - d[i][1]
i += 1
print(ans)
| n = int(input())
v = [int(item) for item in input().split()]
c = [int(item) for item in input().split()]
d = [[v[i], c[i]] for i in range(n)]
d.sort(key=lambda x: x[0] - x[1], reverse=True)
ans = 0
i = 0
while i < n and d[i][0] - d[i][1] > 0:
ans += d[i][0] - d[i][1]
i += 1
print(ans)
| replace | 9 | 10 | 9 | 10 | 0 | |
p03060 | Python | Time Limit Exceeded | # coding: utf-8
import itertools
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
d = sum(v) - sum(c)
maxd = d if d > 0 else 0
for m in range(1, n):
a0 = [i for i in list(itertools.combinations(list(range(n)), m))]
for a1 in a0:
d = sum([v[j] - c[j] for j in a1])
if maxd < d:
maxd = d
print(maxd)
| # coding: utf-8
import itertools
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))
d = sum([v[i] - c[i] for i in range(n) if v[i] - c[i] > 0])
print(d)
| replace | 6 | 15 | 6 | 8 | TLE | |
p03060 | Python | Time Limit Exceeded | n = int(input())
v = list(map(int, input().split(" ")))
c = list(map(int, input().split(" ")))
ans = 0
for bit in range(1 << n):
tmp = 0
for i in range(n):
if bit >> i & 1:
tmp += v[i] - c[i]
ans = max(ans, tmp)
print(ans)
| n = int(input())
v = list(map(int, input().split(" ")))
c = list(map(int, input().split(" ")))
ans = 0
for i in range(n):
ans += max(0, v[i] - c[i])
print(ans)
| replace | 5 | 11 | 5 | 7 | TLE | |
p03061 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
long long gcd(long long n1, long long n2) {
if (n1 < n2)
std::swap(n1, n2);
long long m;
do {
m = n1 % n2;
n1 = n2;
n2 = m;
} while (m != 0);
return n1;
}
int main() {
long long N;
std::cin >> N;
std::vector<long long> A(N);
for (long long i = 0; i < N; i++) {
std::cin >> A[i];
}
std::vector<long long> L(N);
L[0] = 0;
L[1] = A[0];
for (long long i = 2; i < N; i++) {
L[i] = gcd(L[i - 1], A[i - 1]);
}
std::vector<long long> R(N);
R[N - 1] = 0;
R[N - 2] = A[N - 1];
for (long long i = N - 3; i >= 0; i--) {
R[i] = gcd(R[i + 1], A[i + 1]);
}
long long max_g = 0;
for (long long i = 0; i < N; i++) {
max_g = std::max(max_g, gcd(L[i], R[i]));
}
std::cout << max_g << std::endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
long long gcd(long long n1, long long n2) {
if (n1 < n2)
std::swap(n1, n2);
if (n2 == 0)
return n1;
long long m;
do {
m = n1 % n2;
n1 = n2;
n2 = m;
} while (m != 0);
return n1;
}
int main() {
long long N;
std::cin >> N;
std::vector<long long> A(N);
for (long long i = 0; i < N; i++) {
std::cin >> A[i];
}
std::vector<long long> L(N);
L[0] = 0;
L[1] = A[0];
for (long long i = 2; i < N; i++) {
L[i] = gcd(L[i - 1], A[i - 1]);
}
std::vector<long long> R(N);
R[N - 1] = 0;
R[N - 2] = A[N - 1];
for (long long i = N - 3; i >= 0; i--) {
R[i] = gcd(R[i + 1], A[i + 1]);
}
long long max_g = 0;
for (long long i = 0; i < N; i++) {
max_g = std::max(max_g, gcd(L[i], R[i]));
}
std::cout << max_g << std::endl;
return 0;
} | insert | 8 | 8 | 8 | 10 | -8 | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
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;
}
int main() {
int n;
cin >> n;
vector<int> a(n + 1);
rep1(i, n) cin >> a[i];
vector<int> l(n), r(n);
rep1(i, n - 1) l[i + 1] = __gcd(l[i], a[i]);
for (int i = n; i >= 2; --i)
r[i - 1] = __gcd(r[i], a[i]);
int ans = 1;
rep1(i, n) ans = max(ans, __gcd(l[i], r[i]));
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
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;
}
int main() {
int n;
cin >> n;
vector<int> a(n + 1);
rep1(i, n) cin >> a[i];
vector<int> l(n + 1), r(n + 1);
rep1(i, n - 1) l[i + 1] = __gcd(l[i], a[i]);
for (int i = n; i >= 2; --i)
r[i - 1] = __gcd(r[i], a[i]);
int ans = 1;
rep1(i, n) ans = max(ans, __gcd(l[i], r[i]));
cout << ans << endl;
return 0;
} | replace | 35 | 36 | 35 | 36 | 0 | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
ll gcd(ll a, ll b) {
if (a * b == 0)
return a + b;
if (a < b)
gcd(b, a);
ll r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> A(n + 2, 0);
vector<int> L(n + 2, 0);
vector<int> R(n + 2, 0);
FOR(i, 1, n + 1) { cin >> A[i]; }
L[0] = 0;
R[n + 1] = 0;
REP(i, n + 2) { L[i + 1] = gcd(L[i], A[i]); }
for (int i = n + 1; i >= 0; i--) {
R[i] = gcd(R[i + 1], A[i]);
}
int mm = -1;
FOR(i, 1, n + 1) {
if (mm < gcd(L[i], R[i + 1]))
mm = gcd(L[i], R[i + 1]);
}
cout << mm << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
ll gcd(ll a, ll b) {
if (a * b == 0)
return a + b;
if (a < b)
gcd(b, a);
ll r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> A(n + 2, 0);
vector<int> L(n + 2, 0);
vector<int> R(n + 2, 0);
FOR(i, 1, n + 1) { cin >> A[i]; }
L[0] = 0;
R[n + 1] = 0;
REP(i, n + 1) { L[i + 1] = gcd(L[i], A[i]); }
for (int i = n; i >= 0; i--) {
R[i] = gcd(R[i + 1], A[i]);
}
int mm = -1;
FOR(i, 1, n + 1) {
if (mm < gcd(L[i], R[i + 1]))
mm = gcd(L[i], R[i + 1]);
}
cout << mm << endl;
} | replace | 29 | 31 | 29 | 31 | 0 | |
p03061 | C++ | Runtime Error | /************************Code by Hardik
* Aggarwal!!!!***********************************/
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low, high, i) for (i = low; i < high; i++)
#define forrev(high, low, i) for (i = high; i >= low; i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod = 998244353;
int main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
IOS ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n; i++)
cin >> a[i];
ll pre[n + 2], suf[n + 2];
memset(pre, 0, sizeof(pre));
memset(suf, 0, sizeof(suf));
for (ll i = 1; i <= n; i++) {
pre[i] = __gcd(pre[i - 1], a[i - 1]);
}
for (ll i = n; i >= 1; i--) {
suf[i] = __gcd(suf[i + 1], a[i - 1]);
}
ll maxi = 0;
for (ll i = 1; i <= n; i++) {
maxi = max(maxi, __gcd(pre[i - 1], suf[i + 1]));
}
cout << maxi << endl;
}
| /************************Code by Hardik
* Aggarwal!!!!***********************************/
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low, high, i) for (i = low; i < high; i++)
#define forrev(high, low, i) for (i = high; i >= low; i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod = 998244353;
int main() {
IOS ll n;
cin >> n;
ll a[n];
for (ll i = 0; i < n; i++)
cin >> a[i];
ll pre[n + 2], suf[n + 2];
memset(pre, 0, sizeof(pre));
memset(suf, 0, sizeof(suf));
for (ll i = 1; i <= n; i++) {
pre[i] = __gcd(pre[i - 1], a[i - 1]);
}
for (ll i = n; i >= 1; i--) {
suf[i] = __gcd(suf[i + 1], a[i - 1]);
}
ll maxi = 0;
for (ll i = 1; i <= n; i++) {
maxi = max(maxi, __gcd(pre[i - 1], suf[i + 1]));
}
cout << maxi << endl;
}
| delete | 37 | 43 | 37 | 37 | -11 | |
p03061 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using ll = unsigned long long;
using namespace std;
// http://drken1215.hatenablog.com/entry/2019/04/27/224100_1
int n;
ll *A;
int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
gcd(b, a % b);
}
}
int main(void) {
cin >> n;
A = new ll[n];
for (int i = 0; i < n; ++i) {
cin >> A[i];
}
// あるA[i]が無い状態での最大公約数を求める
// gcd(left[i], right[i])のうちで,もっとも大きい値が解
ll *left, *right;
// nが抜けてたときのために,+1
left = new ll[n + 1];
right = new ll[n + 1];
// forward 前向きに入れていく
left[0] = 0;
for (int i = 0; i < n; ++i) {
left[i + 1] = gcd(left[i], A[i]);
}
// backward 後ろ向きにいれていく
right[n] = 0;
for (int i = n - 1; i >= 0; ++i) {
right[i] = gcd(right[i + 1], A[i]);
}
// 集計する
int maxv = 0;
for (int i = 0; i < n; ++i) {
// index問題に弱すぎ...ちゃんと確認すること
int l = left[i];
int r = right[i + 1];
int cand = gcd(l, r);
if (maxv < cand) {
maxv = cand;
}
}
cout << maxv << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using ll = unsigned long long;
using namespace std;
// http://drken1215.hatenablog.com/entry/2019/04/27/224100_1
int n;
ll *A;
int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
gcd(b, a % b);
}
}
int main(void) {
cin >> n;
A = new ll[n];
for (int i = 0; i < n; ++i) {
cin >> A[i];
}
// あるA[i]が無い状態での最大公約数を求める
// gcd(left[i], right[i])のうちで,もっとも大きい値が解
ll *left, *right;
// nが抜けてたときのために,+1
left = new ll[n + 1];
right = new ll[n + 1];
// forward 前向きに入れていく
left[0] = 0;
for (int i = 0; i < n; ++i) {
left[i + 1] = gcd(left[i], A[i]);
}
// backward 後ろ向きにいれていく
right[n] = 0;
for (int i = n - 1; i >= 0; --i) {
right[i] = gcd(right[i + 1], A[i]);
}
// 集計する
int maxv = 0;
for (int i = 0; i < n; ++i) {
// index問題に弱すぎ...ちゃんと確認すること
int l = left[i];
int r = right[i + 1];
int cand = gcd(l, r);
if (maxv < cand) {
maxv = cand;
}
}
cout << maxv << endl;
return 0;
} | replace | 45 | 46 | 45 | 46 | -11 | |
p03061 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
int main() {
ll N;
vector<ll> A(N);
cin >> N;
for (ll i = 0; i < N; i++) {
cin >> A[i];
}
// 入力完了
vector<ll> L(N), R(N);
L[0] = A[0];
R[N - 1] = A[N - 1]; // LとRのベース入力
for (ll i = 0; i < N - 1; i++) {
L[i + 1] = gcd(L[i], A[i + 1]);
}
for (ll j = N - 2; j >= 0; j++) {
R[j] = gcd(R[j + 1], A[j]);
} // 累積gcd定義完了
ll max_gcd = 0;
for (ll i = 1; i <= N - 2; i++) {
ll g = gcd(L[i - 1], R[i + 1]);
max_gcd = max(max_gcd, g);
}
cout << max(max_gcd, max(R[1], L[N - 2])) << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
int main() {
ll N;
vector<ll> A(N);
cin >> N;
for (ll i = 0; i < N; i++) {
cin >> A[i];
}
// 入力完了
vector<ll> L(N), R(N);
L[0] = A[0];
R[N - 1] = A[N - 1]; // LとRのベース入力
for (ll i = 0; i < N - 1; i++) {
L[i + 1] = gcd(L[i], A[i + 1]);
}
for (ll j = N - 2; j >= 0; j--) {
R[j] = gcd(R[j + 1], A[j]);
} // 累積gcd定義完了
ll max_gcd = 0;
for (ll i = 1; i <= N - 2; i++) {
ll g = gcd(L[i - 1], R[i + 1]);
max_gcd = max(max_gcd, g);
}
cout << max(max_gcd, max(R[1], L[N - 2])) << endl;
return 0;
}
| replace | 29 | 30 | 29 | 30 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03061 | Python | Time Limit Exceeded | import fractions
N = int(input())
A = list(map(int, input().split()))
gcd_max = 0
for i in range(N):
a_temp = A[:i]
a_temp.extend(A[i + 1 :])
gcd_temp = a_temp[0]
for a in a_temp:
gcd_temp = fractions.gcd(gcd_temp, a)
if gcd_temp <= gcd_max:
break
else:
gcd_max = gcd_temp
print(gcd_max)
| import fractions
N = int(input())
A = list(map(int, input().split()))
L = [0] * N
R = [0] * N
for i in range(0, N - 1):
L[i + 1] = fractions.gcd(L[i], A[i])
for i in range(N - 1, 0, -1):
R[i - 1] = fractions.gcd(R[i], A[i])
print(max([fractions.gcd(L[i], R[i]) for i in range(N)]))
| replace | 4 | 16 | 4 | 11 | TLE | |
p03061 | Python | Runtime Error | from math import gcd
N = int(input())
A = list(map(int, input().split()))
cum_left = [A[0]]
cum_right = [A[N - 1]]
for i in range(1, N - 1):
cum_left.append(gcd(cum_left[-1], A[i]))
cum_right.append(gcd(cum_right[-1], A[N - 1 - i]))
ans = max(cum_left[N - 2], cum_right[N - 2])
for i in range(1, N - 1):
ans = max(ans, gcd(cum_left[i - 1], cum_right[N - 2 - i]))
print(ans)
| from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
cum_left = [A[0]]
cum_right = [A[N - 1]]
for i in range(1, N - 1):
cum_left.append(gcd(cum_left[-1], A[i]))
cum_right.append(gcd(cum_right[-1], A[N - 1 - i]))
ans = max(cum_left[N - 2], cum_right[N - 2])
for i in range(1, N - 1):
ans = max(ans, gcd(cum_left[i - 1], cum_right[N - 2 - i]))
print(ans)
| replace | 0 | 1 | 0 | 1 | 0 | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int req(vector<int> A, int N) {
int wrongB = 0;
int wrongC = 0;
vector<int> B(N), C(N);
B[0] = A[0];
C[1] = A[1];
for (int i = 1; i < N; i++) {
B[i] = A[i] % A[0];
if (B[i] == 0) {
B[i] = A[0];
continue;
}
wrongB++;
}
for (int i = 0; i < N; i++) {
if (i == 1) {
continue;
}
C[i] = A[i] % A[1];
if (C[i] == 0) {
B[i] = A[1];
continue;
}
wrongC++;
}
if (wrongC < 2) {
return A[1];
}
if (wrongB < 2) {
return A[0];
}
sort(B.begin(), B.end());
sort(C.begin(), C.end());
return max(req(B, N), req(C, N));
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
sort(A.begin(), A.end());
cout << req(A, N) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int req(vector<int> A, int N) {
int wrongB = 0;
int wrongC = 0;
vector<int> B(N), C(N);
B[0] = A[0];
C[1] = A[1];
for (int i = 1; i < N; i++) {
B[i] = A[i] % A[0];
if (B[i] == 0) {
B[i] = A[0];
continue;
}
wrongB++;
}
for (int i = 0; i < N; i++) {
if (i == 1) {
continue;
}
C[i] = A[i] % A[1];
if (C[i] == 0) {
C[i] = A[1];
continue;
}
wrongC++;
}
if (wrongC < 2) {
return A[1];
}
if (wrongB < 2) {
return A[0];
}
sort(B.begin(), B.end());
sort(C.begin(), C.end());
return max(req(B, N), req(C, N));
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
sort(A.begin(), A.end());
cout << req(A, N) << endl;
} | replace | 23 | 24 | 23 | 24 | 0 | |
p03061 | Python | Time Limit Exceeded | import fractions
N = int(input())
aLst = list(map(int, input().split()))
ansLst = []
for i in range(len(aLst)):
ans = 0
for j in range(len(aLst)):
if i != j:
ans = fractions.gcd(ans, aLst[j])
ansLst.append(ans)
ansLst.sort(reverse=True)
print(ansLst[0])
| import fractions
N = int(input())
aLst = list(map(int, input().split()))
lans = 0
llst = [0] * (N + 1)
rans = 0
rlst = [0] * (N + 1)
for i in range(N):
lans = fractions.gcd(lans, aLst[i])
llst[i + 1] = lans
for i in range(N - 1, -1, -1):
rans = fractions.gcd(rans, aLst[i])
rlst[i] = rans
ansMax = 0
for i in range(N):
ansMax = max(ansMax, fractions.gcd(llst[i], rlst[i + 1]))
print(ansMax)
| replace | 5 | 14 | 5 | 23 | TLE | |
p03061 | Python | Time Limit Exceeded | from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
if n == 2:
print(max(a))
exit()
x = [a[0], gcd(a[0], a[1])]
y = [gcd(a[-2], a[-1]), a[-1]]
for i in range(1, n - 2):
x.append(gcd(x[i], a[i + 1]))
y.insert(0, gcd(y[0], a[-i - 2]))
ans = max(x[-1], y[0])
for i in range(n - 2):
ans = max(ans, gcd(x[i], y[i + 1]))
print(ans)
| from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
if n == 2:
print(max(a))
exit()
x = [a[0], gcd(a[0], a[1])]
for i in range(n - 3):
x.append(gcd(x[i + 1], a[i + 2]))
ans = x[-1]
y = a[-1]
for i in range(1, n - 1):
z = gcd(y, a[-i])
ans = max(ans, gcd(x[-i - 1], z))
y = z
print(max(ans, gcd(y, a[1])))
| replace | 8 | 16 | 8 | 17 | TLE | |
p03061 | C++ | Runtime Error | //
// Created by Tetsuya Shiota on 2019-04-13.
//
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <type_traits>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(e, o) for (auto &&e : o)
#ifdef LOCAL
#define pp(x) cerr << __LINE__ << ' ' << #x << " = " << (x) << endl
#define dump(x) \
cerr << __LINE__ << ' ' << #x << " : "; \
FOR(e, x) cerr << e << ' '; \
cerr << endl;
#else
#define pp(x)
#define dump(x)
#endif
using namespace std;
using Int = long long;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int, Int>;
template <typename T> void reverse(vector<T> &v) {
reverse(v.begin(), v.end());
}
template <typename T> void sort(vector<T> &v) { sort(v.begin(), v.end()); }
template <typename T> void rsort(vector<T> &v) { sort(v.rbegin(), v.rend()); }
template <typename T> T sum(const vector<T> &v) {
return accumulate(v.begin(), v.end(), T(0));
}
template <class T> void update_max(T &a, const T &b) { a = max(a, b); }
template <class T> void update_min(T &a, const T &b) { a = min(a, b); }
vector<pair<char, Int>> merge_cont_char(const string &s) {
vector<pair<char, Int>> ret;
if (s.empty())
return ret;
ret.push_back(make_pair(s[0], 0));
FOR(c, s) {
if (ret.back().first == c)
ret.back().second++;
else
ret.push_back(make_pair(c, 1));
}
return ret;
}
class Shakutori {
public:
// 全体の範囲
// [0, end)
// 注目している範囲
// [tail, head)
Int head, tail, end = 0;
bool moveHead() {
if (head == end) {
return false;
}
head++;
return true;
}
void moveTail() { tail++; }
bool valid() {
if (head == tail)
return true;
// [tail, head)
// が解として適当か検証する
return true;
}
void solve() {
head = tail = 0;
Int ans = 0;
while (moveHead()) {
while (!valid()) {
moveTail();
}
// ここで解を更新する
}
}
};
template <typename Integer> Integer GCD(Integer a, Integer b) {
if (!b)
return a;
else
return GCD(b, a % b);
}
class Solver {
public:
Int N, ans;
vi A;
Solver() {}
void input() {
cin >> N;
set<Int> used;
rep(i, N) {
Int tmp;
cin >> tmp;
if (used.count(tmp))
continue;
used.insert(tmp);
A.push_back(tmp);
}
}
void solve() {
vi left(N), right(N);
left[0] = A[0];
REP(i, 1, N) { left[i] = GCD(left[i - 1], A[i]); }
right.back() = A.back();
for (Int i = N - 2; i >= 0; i--) {
right[i] = GCD(right[i + 1], A[i]);
}
ans = 1;
rep(i, N) {
if (i == 0) {
update_max(ans, right[i + 1]);
} else if (i == N - 1) {
update_max(ans, left[i - 1]);
} else {
update_max(ans, GCD(left[i - 1], right[i + 1]));
}
}
return;
}
void output() { cout << ans << endl; }
};
void initilization() {
struct BoolName : numpunct<char> {
string t, f;
BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
string do_truename() const { return t; }
string do_falsename() const { return f; }
};
cin.tie(nullptr);
ios::sync_with_stdio(0);
cout << fixed << setprecision(15) << boolalpha;
cout.imbue(locale(cout.getloc(), new BoolName));
}
int main() {
#ifdef LOCAL
while (1) {
Solver s;
s.input();
if (cin.eof())
break;
s.solve();
s.output();
}
#else
Solver s;
s.input();
s.solve();
s.output();
#endif
}
| //
// Created by Tetsuya Shiota on 2019-04-13.
//
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <type_traits>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(e, o) for (auto &&e : o)
#ifdef LOCAL
#define pp(x) cerr << __LINE__ << ' ' << #x << " = " << (x) << endl
#define dump(x) \
cerr << __LINE__ << ' ' << #x << " : "; \
FOR(e, x) cerr << e << ' '; \
cerr << endl;
#else
#define pp(x)
#define dump(x)
#endif
using namespace std;
using Int = long long;
using vi = vector<Int>;
using vvi = vector<vi>;
using pii = pair<Int, Int>;
template <typename T> void reverse(vector<T> &v) {
reverse(v.begin(), v.end());
}
template <typename T> void sort(vector<T> &v) { sort(v.begin(), v.end()); }
template <typename T> void rsort(vector<T> &v) { sort(v.rbegin(), v.rend()); }
template <typename T> T sum(const vector<T> &v) {
return accumulate(v.begin(), v.end(), T(0));
}
template <class T> void update_max(T &a, const T &b) { a = max(a, b); }
template <class T> void update_min(T &a, const T &b) { a = min(a, b); }
vector<pair<char, Int>> merge_cont_char(const string &s) {
vector<pair<char, Int>> ret;
if (s.empty())
return ret;
ret.push_back(make_pair(s[0], 0));
FOR(c, s) {
if (ret.back().first == c)
ret.back().second++;
else
ret.push_back(make_pair(c, 1));
}
return ret;
}
class Shakutori {
public:
// 全体の範囲
// [0, end)
// 注目している範囲
// [tail, head)
Int head, tail, end = 0;
bool moveHead() {
if (head == end) {
return false;
}
head++;
return true;
}
void moveTail() { tail++; }
bool valid() {
if (head == tail)
return true;
// [tail, head)
// が解として適当か検証する
return true;
}
void solve() {
head = tail = 0;
Int ans = 0;
while (moveHead()) {
while (!valid()) {
moveTail();
}
// ここで解を更新する
}
}
};
template <typename Integer> Integer GCD(Integer a, Integer b) {
if (!b)
return a;
else
return GCD(b, a % b);
}
class Solver {
public:
Int N, ans;
vi A;
Solver() {}
void input() {
cin >> N;
A = vi(N);
FOR(a, A) cin >> a;
}
void solve() {
vi left(N), right(N);
left[0] = A[0];
REP(i, 1, N) { left[i] = GCD(left[i - 1], A[i]); }
right.back() = A.back();
for (Int i = N - 2; i >= 0; i--) {
right[i] = GCD(right[i + 1], A[i]);
}
ans = 1;
rep(i, N) {
if (i == 0) {
update_max(ans, right[i + 1]);
} else if (i == N - 1) {
update_max(ans, left[i - 1]);
} else {
update_max(ans, GCD(left[i - 1], right[i + 1]));
}
}
return;
}
void output() { cout << ans << endl; }
};
void initilization() {
struct BoolName : numpunct<char> {
string t, f;
BoolName(string t = "Yes", string f = "No") : t(t), f(f) {}
string do_truename() const { return t; }
string do_falsename() const { return f; }
};
cin.tie(nullptr);
ios::sync_with_stdio(0);
cout << fixed << setprecision(15) << boolalpha;
cout.imbue(locale(cout.getloc(), new BoolName));
}
int main() {
#ifdef LOCAL
while (1) {
Solver s;
s.input();
if (cin.eof())
break;
s.solve();
s.output();
}
#else
Solver s;
s.input();
s.solve();
s.output();
#endif
}
| replace | 115 | 124 | 115 | 117 | 0 | |
p03061 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int main() {
int ans = 0, N;
cin >> N;
vector<int> A(N), M(N), L(N), R(N + 1);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
if (i == 0)
L[i] = 0;
L[i + 1] = gcd(L[i], A[i]);
}
for (int i = N - 1; i >= 0; i--) {
R[N] = 0;
R[i] = gcd(R[i + 1], A[i]);
M[i] = gcd(L[i], R[i + 1]);
}
sort(M.begin(), M.end());
cout << M[N - 1] << endl;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int main() {
int ans = 0, N;
cin >> N;
vector<int> A(N), M(N), L(N + 1), R(N + 1);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
for (int i = 0; i < N; i++) {
if (i == 0)
L[i] = 0;
L[i + 1] = gcd(L[i], A[i]);
}
for (int i = N - 1; i >= 0; i--) {
R[N] = 0;
R[i] = gcd(R[i + 1], A[i]);
M[i] = gcd(L[i], R[i + 1]);
}
sort(M.begin(), M.end());
cout << M[N - 1] << endl;
} | replace | 23 | 24 | 23 | 24 | 0 | |
p03061 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main() {
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<ll> left(N, 0);
vector<ll> right(N, 0);
left[0] = A[0];
right[N - 1] = A[N - 1];
for (int i = 1; i <= N; i++) {
left[i] = gcd(A[i], left[i - 1]);
}
for (int j = N - 2; j >= 0; j--) {
right[j] = gcd(A[j], right[j + 1]);
}
ll max_cnt = 0;
for (int i = 1; i < N - 1; i++) {
max_cnt = max(max_cnt, gcd(left[i - 1], right[i + 1]));
}
cout << max(max_cnt, max(right[1], left[N - 2])) << endl;
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main() {
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<ll> left(N, 0);
vector<ll> right(N, 0);
left[0] = A[0];
right[N - 1] = A[N - 1];
for (int i = 1; i < N; i++) {
left[i] = gcd(A[i], left[i - 1]);
}
for (int j = N - 2; j >= 0; j--) {
right[j] = gcd(A[j], right[j + 1]);
}
ll max_cnt = 0;
for (int i = 1; i < N - 1; i++) {
max_cnt = max(max_cnt, gcd(left[i - 1], right[i + 1]));
}
cout << max(max_cnt, max(right[1], left[N - 2])) << endl;
return 0;
}
| replace | 27 | 28 | 27 | 28 | -6 | free(): invalid pointer
|
p03061 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> l(n), r(n);
for (int i = 0; i < n; i++)
l[i + 1] = gcd(l[i], a[i]);
for (int i = n - 1; i >= 1; i--)
r[i - 1] = gcd(r[i], a[i]);
int ans = 0;
for (int i = 0; i < n; i++)
ans = max(ans, gcd(l[i], r[i]));
cout << ans << endl;
} | #include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> l(n), r(n);
for (int i = 0; i < n - 1; i++)
l[i + 1] = gcd(l[i], a[i]);
for (int i = n - 1; i >= 1; i--)
r[i - 1] = gcd(r[i], a[i]);
int ans = 0;
for (int i = 0; i < n; i++)
ans = max(ans, gcd(l[i], r[i]));
cout << ans << endl;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p03061 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
int no_of_elements;
cin >> no_of_elements;
vector<int> A(no_of_elements);
for (int i = 1; i <= no_of_elements; i++)
cin >> A[i];
vector<int> prefix_gcd(no_of_elements + 1, 0);
for (int i = 1; i <= no_of_elements; i++)
prefix_gcd[i] = __gcd(prefix_gcd[i - 1], A[i]);
vector<int> suffix_gcd(no_of_elements + 2, 0);
for (int i = no_of_elements; i >= 1; i--)
suffix_gcd[i] = __gcd(suffix_gcd[i + 1], A[i]);
int best_gcd = 0;
for (int i = 1; i <= no_of_elements; i++) {
int gcd_without_this = __gcd(prefix_gcd[i - 1], suffix_gcd[i + 1]);
best_gcd = max(best_gcd, gcd_without_this);
}
cout << best_gcd;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
int no_of_elements;
cin >> no_of_elements;
vector<int> A(no_of_elements + 1);
for (int i = 1; i <= no_of_elements; i++)
cin >> A[i];
vector<int> prefix_gcd(no_of_elements + 1, 0);
for (int i = 1; i <= no_of_elements; i++)
prefix_gcd[i] = __gcd(prefix_gcd[i - 1], A[i]);
vector<int> suffix_gcd(no_of_elements + 2, 0);
for (int i = no_of_elements; i >= 1; i--)
suffix_gcd[i] = __gcd(suffix_gcd[i + 1], A[i]);
int best_gcd = 0;
for (int i = 1; i <= no_of_elements; i++) {
int gcd_without_this = __gcd(prefix_gcd[i - 1], suffix_gcd[i + 1]);
best_gcd = max(best_gcd, gcd_without_this);
}
cout << best_gcd;
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
#define Grafo vector<vector<pair<int, int>>>
#define Container vector<vector<int>>
#define MAX 40321
#define INFINITO INT_MAX
using namespace std;
int A[MAX];
int WA[MAX];
int n, maior;
int mdc(int x, int y) {
if (x == -1) {
return y;
}
if (y == -1) {
return x;
}
return __gcd(x, y);
}
void conquer(int i1, int j1, int i2, int j2) {
int left = mdc(A[i1], WA[i1]);
int right = mdc(A[i2], WA[i2]);
for (int i = i1; i <= j1; i++) {
WA[i] = mdc(WA[i], right);
}
for (int i = i2; i <= j2; i++) {
WA[i] = mdc(WA[i], left);
}
}
void divide(int l, int r) {
if (l != r) {
int m = (l + r) / 2;
divide(l, m);
divide(m + 1, r);
conquer(l, m, m + 1, r);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> A[i];
WA[i] = -1;
}
divide(0, n - 1);
maior = 1;
for (int i = 0; i < n; i++) {
maior = max(maior, WA[i]);
}
cout << maior << "\n";
return 0;
} | #include <bits/stdc++.h>
#define MAX 100001
using namespace std;
int A[MAX];
int WA[MAX];
int n, maior;
int mdc(int x, int y) {
if (x == -1) {
return y;
}
if (y == -1) {
return x;
}
return __gcd(x, y);
}
void conquer(int i1, int j1, int i2, int j2) {
int left = mdc(A[i1], WA[i1]);
int right = mdc(A[i2], WA[i2]);
for (int i = i1; i <= j1; i++) {
WA[i] = mdc(WA[i], right);
}
for (int i = i2; i <= j2; i++) {
WA[i] = mdc(WA[i], left);
}
}
void divide(int l, int r) {
if (l != r) {
int m = (l + r) / 2;
divide(l, m);
divide(m + 1, r);
conquer(l, m, m + 1, r);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> A[i];
WA[i] = -1;
}
divide(0, n - 1);
maior = 1;
for (int i = 0; i < n; i++) {
maior = max(maior, WA[i]);
}
cout << maior << "\n";
return 0;
} | replace | 1 | 5 | 1 | 2 | 0 | |
p03061 | Python | Runtime Error | from math import gcd
n = int(input())
a = list(map(int, input().split()))
pre = [0]
for i in range(n - 1):
pre.append(gcd(pre[-1], a[i]))
post = [0]
for i in range(n - 1):
post.append(gcd(post[-1], a[n - 1 - i]))
res = 0
for i in range(n):
res = max(gcd(pre[i], post[n - 1 - i]), res)
print(res)
| def gcd(a, b):
while b:
a, b = b, a % b
return a
n = int(input())
a = list(map(int, input().split()))
pre = [0]
for i in range(n - 1):
pre.append(gcd(pre[-1], a[i]))
post = [0]
for i in range(n - 1):
post.append(gcd(post[-1], a[n - 1 - i]))
res = 0
for i in range(n):
res = max(gcd(pre[i], post[n - 1 - i]), res)
print(res)
| replace | 0 | 1 | 0 | 5 | 0 | |
p03061 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
ll c;
while (a > 0) {
c = a;
a = b % a;
b = c;
}
return c;
}
int main() {
ll b, c, d, e, k, n, o = 1, p, q, x, y, z, max1 = 0, ans = 1;
string s, t, u;
cin >> n;
ll a[n], r[n], l[n];
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
l[0] = a[0];
r[n - 1] = a[n - 1];
for (ll i = 1; i < n; i++) {
l[i] = gcd(l[i - 1], a[i]);
}
for (ll i = n - 2; i >= 0; i++) {
r[i] = gcd(r[i + 1], a[i]);
}
max1 = r[1];
for (ll i = 1; i < n - 1; i++) {
max1 = max(gcd(l[i - 1], r[i + 1]), max1);
}
max1 = max(max1, l[n - 2]);
cout << max1 << endl;
}
| #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
ll c;
while (a > 0) {
c = a;
a = b % a;
b = c;
}
return c;
}
int main() {
ll b, c, d, e, k, n, o = 1, p, q, x, y, z, max1 = 0, ans = 1;
string s, t, u;
cin >> n;
ll a[n], r[n], l[n];
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
l[0] = a[0];
r[n - 1] = a[n - 1];
for (ll i = 1; i < n; i++) {
l[i] = gcd(l[i - 1], a[i]);
}
for (ll i = n - 2; i >= 0; i--) {
r[i] = gcd(r[i + 1], a[i]);
}
max1 = r[1];
for (ll i = 1; i < n - 1; i++) {
max1 = max(gcd(l[i - 1], r[i + 1]), max1);
}
max1 = max(max1, l[n - 2]);
cout << max1 << endl;
}
| replace | 28 | 29 | 28 | 29 | TLE | |
p03061 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repf(i, m, n) for (int(i) = m; (i) < n; (i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name, num) vector<ll> name((num), 0);
#define op(i) cout << (i) << endl;
#define ip(i) cin >> (i);
#define opN cout << "No" << endl;
#define opY cout << "Yes" << endl;
#define opP cout << "Possible" << endl;
#define opI cout << "Impossible" << endl;
#define mat(name, fnum, snum) \
; \
vector<vector<ll>> name((fnum), vector<ll>((snum), 0));
#define debugP \
int debug_point; \
cin >> debug_point;
const ll MOD = 1e9 + 7;
template <typename T> void putv(vector<T> &V) {
// cout << "The elements in the vector are: " << endl;
for (auto x : V)
cout << x << " ";
cout << endl;
}
ll pown(ll fi, ll se) {
ll ans = 1;
rep(i, se) { ans *= fi; }
return ans;
}
template <class T> vector<T> getv(ll n) {
vector<T> Vector_temp;
rep(i, n) {
T input;
cin >> input;
Vector_temp.emplace_back(input);
}
return Vector_temp;
}
ll gcd(ll c, ll b) {
while (1) {
if (c % b != 0) {
ll tmp = b;
b = c % b;
c = tmp;
} else {
return b;
}
}
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/
int main() {
ll n;
cin >> n;
vec(v, n);
rep(i, n) { cin >> v[i]; }
vec(s, n);
vec(g, n);
s[0] = v[0];
rep(i, n - 1) { s[i + 1] = gcd(v[i + 1], s[i]); }
g[n - 1] = v[n - 1];
rep(i, n - 1) { g[n - 1 - 1 - i] = gcd(v[n - 2 - i], g[n - 1 - i]); }
ll ans = g[1];
rep(i, n - 1) { ans = max(ans, gcd(s[i], g[2 + i])); }
op(ans);
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repf(i, m, n) for (int(i) = m; (i) < n; (i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name, num) vector<ll> name((num), 0);
#define op(i) cout << (i) << endl;
#define ip(i) cin >> (i);
#define opN cout << "No" << endl;
#define opY cout << "Yes" << endl;
#define opP cout << "Possible" << endl;
#define opI cout << "Impossible" << endl;
#define mat(name, fnum, snum) \
; \
vector<vector<ll>> name((fnum), vector<ll>((snum), 0));
#define debugP \
int debug_point; \
cin >> debug_point;
const ll MOD = 1e9 + 7;
template <typename T> void putv(vector<T> &V) {
// cout << "The elements in the vector are: " << endl;
for (auto x : V)
cout << x << " ";
cout << endl;
}
ll pown(ll fi, ll se) {
ll ans = 1;
rep(i, se) { ans *= fi; }
return ans;
}
template <class T> vector<T> getv(ll n) {
vector<T> Vector_temp;
rep(i, n) {
T input;
cin >> input;
Vector_temp.emplace_back(input);
}
return Vector_temp;
}
ll gcd(ll c, ll b) {
while (1) {
if (c % b != 0) {
ll tmp = b;
b = c % b;
c = tmp;
} else {
return b;
}
}
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/
int main() {
ll n;
cin >> n;
vec(v, n);
rep(i, n) { cin >> v[i]; }
vec(s, n);
vec(g, n);
s[0] = v[0];
rep(i, n - 1) { s[i + 1] = gcd(v[i + 1], s[i]); }
g[n - 1] = v[n - 1];
rep(i, n - 1) { g[n - 1 - 1 - i] = gcd(v[n - 2 - i], g[n - 1 - i]); }
ll ans = g[1];
rep(i, n - 2) { ans = max(ans, gcd(s[i], g[2 + i])); }
ans = max(ans, s[n - 2]);
op(ans);
return 0;
} | replace | 72 | 73 | 72 | 74 | 0 | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
ll gcd(ll x, ll y) {
if (y == 0) {
return x;
}
return gcd(y, x % y);
}
int main() {
int N;
cin >> N;
vector<ll> A(N);
rep(i, N) { cin >> A.at(i); }
vector<ll> G(N);
G[0] = A[0];
vector<ll> R(N);
vector<ll> L(N);
L[0] = 0;
R[N] = 0;
rep(i, N) { L[i + 1] = gcd(L[i], A[i]); }
for (int i = N - 1; i >= 0; --i) {
R[i] = gcd(R[i + 1], A[i]);
}
ll ans = 0;
rep(i, N) { ans = max(ans, gcd(L[i], R[i + 1])); }
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;
ll gcd(ll x, ll y) {
if (y == 0) {
return x;
}
return gcd(y, x % y);
}
int main() {
int N;
cin >> N;
vector<ll> A(N);
rep(i, N) { cin >> A.at(i); }
vector<ll> R(N + 1);
vector<ll> L(N + 1);
L[0] = 0;
R[N] = 0;
rep(i, N) { L[i + 1] = gcd(L[i], A[i]); }
for (int i = N - 1; i >= 0; --i) {
R[i] = gcd(R[i + 1], A[i]);
}
ll ans = 0;
rep(i, N) { ans = max(ans, gcd(L[i], R[i + 1])); }
cout << ans << endl;
return 0;
} | replace | 19 | 23 | 19 | 21 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p03061 | C++ | Runtime Error | #include <iostream>
#include <string>
#include <vector>
int N;
using namespace std;
vector<int> A;
vector<int> B;
vector<int> C;
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
}
int main() {
cin >> N;
A.resize(N);
B.resize(N);
C.resize(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
B[0] = A[0];
for (int i = 1; i < N; i++) {
B[i] = gcd(B[i - 1], A[i]);
}
C[N - 1] = A[N - 1];
int ans = max(C[1], B[N - 1]);
for (int i = 1; i < N - 1; i++) {
ans = max(ans, gcd(B[i - 1], C[i + 1]));
}
cout << ans << endl;
return 0;
}
| #include <iostream>
#include <string>
#include <vector>
int N;
using namespace std;
vector<int> A;
vector<int> B;
vector<int> C;
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
}
int main() {
cin >> N;
A.resize(N);
B.resize(N);
C.resize(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
B[0] = A[0];
for (int i = 1; i < N; i++) {
B[i] = gcd(B[i - 1], A[i]);
}
C[N - 1] = A[N - 1];
for (int i = N - 2; i >= 0; i--) {
C[i] = gcd(A[i], C[i + 1]);
}
int ans = max(C[1], B[N - 2]);
for (int i = 1; i < N - 1; i++) {
ans = max(ans, gcd(B[i - 1], C[i + 1]));
}
cout << ans << endl;
return 0;
}
| replace | 31 | 32 | 31 | 36 | 0 | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <math.h>
#define MAX_N 100100
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
int r = a % b;
return gcd(b, r);
}
int main() {
int n;
cin >> n;
vector<int> a(n), right_gcd(n), left_gcd(n);
for (int i = 0; i < n; i++)
cin >> a[i];
// gcd with binary search
left_gcd[1] = 0;
right_gcd[n] = 0;
for (int i = 2; i <= n; i++) {
right_gcd[n + 1 - i] = gcd(max(right_gcd[n + 2 - i], a[n + 1 - i]),
min(right_gcd[n + 2 - i], a[n + 1 - i]));
left_gcd[i] =
gcd(max(left_gcd[i - 1], a[i - 2]), min(left_gcd[i - 1], a[i - 2]));
}
// merge gcd
int answer = 0;
for (int i = 1; i <= n; i++) {
int i_gcd =
gcd(max(left_gcd[i], right_gcd[i]), min(left_gcd[i], right_gcd[i]));
if (answer < i_gcd)
answer = i_gcd;
}
cout << answer << endl;
}
| #include <bits/stdc++.h>
#include <math.h>
#define MAX_N 100100
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
int r = a % b;
return gcd(b, r);
}
int main() {
int n;
cin >> n;
vector<int> a(n + 1), right_gcd(n + 1), left_gcd(n + 1);
for (int i = 0; i < n; i++)
cin >> a[i];
// gcd with binary search
left_gcd[1] = 0;
right_gcd[n] = 0;
for (int i = 2; i <= n; i++) {
right_gcd[n + 1 - i] = gcd(max(right_gcd[n + 2 - i], a[n + 1 - i]),
min(right_gcd[n + 2 - i], a[n + 1 - i]));
left_gcd[i] =
gcd(max(left_gcd[i - 1], a[i - 2]), min(left_gcd[i - 1], a[i - 2]));
}
// merge gcd
int answer = 0;
for (int i = 1; i <= n; i++) {
int i_gcd =
gcd(max(left_gcd[i], right_gcd[i]), min(left_gcd[i], right_gcd[i]));
if (answer < i_gcd)
answer = i_gcd;
}
cout << answer << endl;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0 || b == 0) {
return max(a, b);
} else if (a == 1 || b == 1) {
return 1;
}
long long q;
bool pro = true;
while (pro) {
q = a % b;
if (q = 0) {
return min(a, b);
} else {
a = b;
b = q;
if (a % b == 0) {
return q;
pro = false;
}
}
}
}
int main() {
int N;
cin >> N;
if (N == 2) {
int a, b;
cin >> a >> b;
cout << max(a, b) << endl;
} else {
vector<long long> an(N);
for (int i = 0; i < N; i++) {
cin >> an.at(i);
}
vector<long long> li(N);
vector<long long> ri(N);
li.at(0) = an.at(0);
ri.at(N - 1) = an.at(N - 1);
for (int i = 1; i < N; i++) {
li.at(i) = gcd(li.at(i - 1), an.at(i));
}
for (int i = N - 2; i >= 0; i = i - 1) {
ri.at(i) = gcd(ri.at(i + 1), an.at(i));
}
long long m = ri.at(1);
for (int i = 1; i < N - 1; i++) {
long long mi = gcd(ri.at(i + 1), li.at(i - 1));
if (mi > m) {
m = mi;
}
}
if (li.at(N - 2) > m) {
m = li.at(N - 2);
}
cout << m << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0 || b == 0) {
return max(a, b);
} else if (a == 1 || b == 1) {
return 1;
}
long long q;
bool pro = true;
while (pro) {
q = a % b;
if (q == 0) {
return min(a, b);
} else {
a = b;
b = q;
if (a % b == 0) {
return q;
pro = false;
}
}
}
}
int main() {
int N;
cin >> N;
if (N == 2) {
int a, b;
cin >> a >> b;
cout << max(a, b) << endl;
} else {
vector<long long> an(N);
for (int i = 0; i < N; i++) {
cin >> an.at(i);
}
vector<long long> li(N);
vector<long long> ri(N);
li.at(0) = an.at(0);
ri.at(N - 1) = an.at(N - 1);
for (int i = 1; i < N; i++) {
li.at(i) = gcd(li.at(i - 1), an.at(i));
}
for (int i = N - 2; i >= 0; i = i - 1) {
ri.at(i) = gcd(ri.at(i + 1), an.at(i));
}
long long m = ri.at(1);
for (int i = 1; i < N - 1; i++) {
long long mi = gcd(ri.at(i + 1), li.at(i - 1));
if (mi > m) {
m = mi;
}
}
if (li.at(N - 2) > m) {
m = li.at(N - 2);
}
cout << m << endl;
}
}
| replace | 14 | 15 | 14 | 15 | -8 | |
p03061 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
// #include <bits/stdc++.h>
using namespace std;
/*inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}*/
typedef long long ll;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int a[1004], b[1004], k[10001];
int main() {
int n;
while (cin >> n) {
for (int i = 1; i <= n; i++)
cin >> k[i];
a[1] = 0, b[n] = 0;
for (int i = 2; i <= n; i++)
a[i] = gcd(a[i - 1], k[i - 1]);
for (int i = n - 1; i >= 1; i--)
b[i] = gcd(b[i + 1], k[i + 1]);
int ans = -999;
for (int i = 1; i <= n; i++)
ans = max(ans, gcd(a[i], b[i]));
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
// #include <bits/stdc++.h>
using namespace std;
/*inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}*/
typedef long long ll;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int a[100004], b[100004], k[1000001];
int main() {
int n;
while (cin >> n) {
for (int i = 1; i <= n; i++)
cin >> k[i];
a[1] = 0, b[n] = 0;
for (int i = 2; i <= n; i++)
a[i] = gcd(a[i - 1], k[i - 1]);
for (int i = n - 1; i >= 1; i--)
b[i] = gcd(b[i + 1], k[i + 1]);
int ans = -999;
for (int i = 1; i <= n; i++)
ans = max(ans, gcd(a[i], b[i]));
cout << ans << endl;
}
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p03061 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
#define REP(i, num) for (int i = 0; i < (num); ++i)
using namespace std;
using ll = long long;
template <typename T = int> T in() {
T x;
cin >> x;
return (x);
}
ll gcd(ll a, ll b) {
if (a < b) {
swap(a, b);
}
if (b < 1)
return a;
while (ll r = (a % b)) {
a = b;
b = r;
}
return b;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N = in();
vector<ll> A(N);
REP(i, N) A[i] = in();
ll m = 0;
REP(i, N) {
ll lm = 0, rm = 0;
for (int k = 0; k < i; k++) {
lm = gcd(A[k], lm);
}
for (int k = i + 1; k < N; k++) {
rm = gcd(A[k], rm);
}
m = max(m, gcd(lm, rm));
}
cout << m << endl;
return 0;
} | #include "bits/stdc++.h"
#define REP(i, num) for (int i = 0; i < (num); ++i)
using namespace std;
using ll = long long;
template <typename T = int> T in() {
T x;
cin >> x;
return (x);
}
ll gcd(ll a, ll b) {
if (a < b) {
swap(a, b);
}
if (b < 1)
return a;
while (ll r = (a % b)) {
a = b;
b = r;
}
return b;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N = in();
vector<ll> A(N);
REP(i, N) A[i] = in();
ll m = 0;
vector<ll> lm(N + 1), rm(N + 1);
lm[0] = 0, rm[N] = 0;
for (int i = 0; i < N; i++) {
lm[i + 1] = gcd(A[i], lm[i]);
}
for (int i = N - 1; i >= 0; i--) {
rm[i] = gcd(A[i], rm[i + 1]);
}
for (int i = 0; i < N; i++) {
m = max(m, gcd(lm[i], rm[i + 1]));
}
cout << m << endl;
return 0;
} | replace | 35 | 44 | 35 | 45 | TLE | |
p03061 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
using namespace std;
const int INF = 1e9;
typedef long long lint;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;
int ctoi(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
return 0;
}
char upper(char c) { return c - 0x20; }
char lower(char c) { return c + 0x20; }
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<int> l(n), r(n);
rep(i, n - 1) l[i + 1] = gcd(l[i], a[i]);
for (int i = n - 1; i >= 0; i--)
r[i - 1] = gcd(r[i], a[i]);
int ans = 1;
rep(i, n) ans = max(ans, gcd(l[i], r[i]));
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
using namespace std;
const int INF = 1e9;
typedef long long lint;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;
int ctoi(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
return 0;
}
char upper(char c) { return c - 0x20; }
char lower(char c) { return c + 0x20; }
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int main() {
int n;
cin >> n;
vector<int> a(n);
rep(i, n) cin >> a[i];
vector<int> l(n), r(n);
rep(i, n - 1) l[i + 1] = gcd(l[i], a[i]);
for (int i = n - 1; i >= 1; --i)
r[i - 1] = gcd(r[i], a[i]);
int ans = 1;
rep(i, n) ans = max(ans, gcd(l[i], r[i]));
cout << ans << endl;
return 0;
}
| replace | 41 | 42 | 41 | 42 | -6 | double free or corruption (out)
|
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> pre_gcd(n + 1), suf_gcd(n + 1);
for (int i = 1; i <= n + 1; i++) {
pre_gcd[i] = __gcd(pre_gcd[i - 1], a[i - 1]);
}
// for(auto it : pre_gcd) {
// cout << it << " ";
// }
// cout << endl;
for (int i = n; i >= 1; i--) {
suf_gcd[i - 1] = __gcd(suf_gcd[i], a[i - 1]);
}
// for(auto it : suf_gcd) {
// cout << it << " ";
// }
// cout << endl;
int ans = 0;
for (int i = 0; i + 1 < pre_gcd.size(); i++) {
ans = max(ans, __gcd(pre_gcd[i], suf_gcd[i + 1]));
}
cout << ans << endl;
return 0;
}
/**
5
12 6 3 4 10
*/
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> pre_gcd(n + 1), suf_gcd(n + 1);
for (int i = 1; i <= n; i++) {
pre_gcd[i] = __gcd(pre_gcd[i - 1], a[i - 1]);
}
// for(auto it : pre_gcd) {
// cout << it << " ";
// }
// cout << endl;
for (int i = n; i >= 1; i--) {
suf_gcd[i - 1] = __gcd(suf_gcd[i], a[i - 1]);
}
// for(auto it : suf_gcd) {
// cout << it << " ";
// }
// cout << endl;
int ans = 0;
for (int i = 0; i + 1 < pre_gcd.size(); i++) {
ans = max(ans, __gcd(pre_gcd[i], suf_gcd[i + 1]));
}
cout << ans << endl;
return 0;
}
/**
5
12 6 3 4 10
*/
| replace | 19 | 20 | 19 | 20 | 0 | |
p03061 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
long long gcd(long long x, long long y) {
long long a = min(x, y), b = max(x, y);
if (b % a == 0)
return a;
return (gcd(a, b % a));
}
int main() {
long long n, *a;
cin >> n;
a = new long long[n];
for (int i = 0; i < n; i++)
cin >> a[i];
long long *r = new long long[n], *l = new long long[n];
l[0] = a[0];
r[n - 1] = a[n - 1];
long long ans = r[1];
for (long long i = 1; i < n - 1; i++) {
long long x = gcd(l[i - 1], r[i + 1]);
ans = max(ans, x);
}
ans = max(l[n - 2], ans);
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
long long gcd(long long x, long long y) {
long long a = min(x, y), b = max(x, y);
if (b % a == 0)
return a;
return (gcd(a, b % a));
}
int main() {
long long n, *a;
cin >> n;
a = new long long[n];
for (int i = 0; i < n; i++)
cin >> a[i];
long long *r = new long long[n], *l = new long long[n];
l[0] = a[0];
r[n - 1] = a[n - 1];
for (int i = 1; i < n; i++) {
l[i] = gcd(l[i - 1], a[i]);
r[n - i - 1] = gcd(r[n - i], a[n - i - 1]);
}
long long ans = r[1];
for (long long i = 1; i < n - 1; i++) {
long long x = gcd(l[i - 1], r[i + 1]);
ans = max(ans, x);
}
ans = max(l[n - 2], ans);
cout << ans << endl;
return 0;
} | insert | 25 | 25 | 25 | 30 | 0 | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define ld long double
#define MOD 1000000007
#define u128 __int128
#define ff first
#define ss second
#define INTMAX 1000000009
#define N 100050
ll bmexp(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
void solve() {}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll seg[2 * N];
ll a[N], n;
void build(int node, int l, int r) {
if (l == r)
seg[node] = a[l];
else {
int mid = l + r >> 1;
build(2 * node + 1, l, mid);
build(2 * node + 2, mid + 1, r);
seg[node] = gcd(seg[2 * node + 1], seg[2 * node + 2]);
}
}
ll q(int node, int l, int r, int x, int y) {
if (x <= l && y >= r)
return seg[node];
else {
ll ans = 0;
int mid = l + r >> 1;
if (x <= mid)
ans = (ans == 0 ? q(2 * node + 1, l, mid, x, y)
: gcd(ans, q(2 * node + 1, l, mid, x, y)));
if (y > mid)
ans = (ans == 0 ? q(2 * node + 2, mid + 1, r, x, y)
: gcd(ans, q(2 * node + 2, mid + 1, r, x, y)));
return ans;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
build(0, 0, n - 1);
// for (int i = 0; i < 2 *n - 1; ++i)
// {
// cout << seg[i] << " ";
// }
ll gc = seg[0];
// cout << gc << " " << q(0, 0, n - 1, 1, n - 1) << " ";
gc = max(gc, q(0, 0, n - 1, 1, n - 1));
for (int i = 1; i < n; ++i) {
ll k = gcd(q(0, 0, n - 1, 0, i - 1), q(0, 0, n - 1, i + 1, n - 1));
gc = max(gc, k);
}
cout << gc;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define ld long double
#define MOD 1000000007
#define u128 __int128
#define ff first
#define ss second
#define INTMAX 1000000009
#define N 100050
ll bmexp(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = res * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return res;
}
void solve() {}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll seg[3 * N];
ll a[N], n;
void build(int node, int l, int r) {
if (l == r)
seg[node] = a[l];
else {
int mid = l + r >> 1;
build(2 * node + 1, l, mid);
build(2 * node + 2, mid + 1, r);
seg[node] = gcd(seg[2 * node + 1], seg[2 * node + 2]);
}
}
ll q(int node, int l, int r, int x, int y) {
if (x <= l && y >= r)
return seg[node];
else {
ll ans = 0;
int mid = l + r >> 1;
if (x <= mid)
ans = (ans == 0 ? q(2 * node + 1, l, mid, x, y)
: gcd(ans, q(2 * node + 1, l, mid, x, y)));
if (y > mid)
ans = (ans == 0 ? q(2 * node + 2, mid + 1, r, x, y)
: gcd(ans, q(2 * node + 2, mid + 1, r, x, y)));
return ans;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
build(0, 0, n - 1);
// for (int i = 0; i < 2 *n - 1; ++i)
// {
// cout << seg[i] << " ";
// }
ll gc = seg[0];
// cout << gc << " " << q(0, 0, n - 1, 1, n - 1) << " ";
gc = max(gc, q(0, 0, n - 1, 1, n - 1));
for (int i = 1; i < n; ++i) {
ll k = gcd(q(0, 0, n - 1, 0, i - 1), q(0, 0, n - 1, i + 1, n - 1));
gc = max(gc, k);
}
cout << gc;
return 0;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p03061 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
struct CinInit {
CinInit() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
} CinInit;
int gcd(const int a, const int b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else if (b == 1)
return 1;
else
return gcd(b, a - b);
}
int main() {
int n, cnt = 0;
cin >> n;
vector<int> a(n), l(n), r(n);
l[0] = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i < n - 1)
l[i + 1] = gcd(l[i], a[i]);
}
r[n - 1] = 0;
for (int i = n - 1; i >= 1; i--) {
r[i - 1] = gcd(a[i], r[i]);
}
int ans = 1;
for (int i = 0; i < n; i++) {
ans = max(gcd(l[i], r[i]), ans);
}
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
struct CinInit {
CinInit() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
} CinInit;
int gcd(const int a, const int b) {
if (a < b)
return gcd(b, a);
else if (b == 0)
return a;
else if (b == 1)
return 1;
else
return gcd(b, a % b);
}
int main() {
int n, cnt = 0;
cin >> n;
vector<int> a(n), l(n), r(n);
l[0] = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i < n - 1)
l[i + 1] = gcd(l[i], a[i]);
}
r[n - 1] = 0;
for (int i = n - 1; i >= 1; i--) {
r[i - 1] = gcd(a[i], r[i]);
}
int ans = 1;
for (int i = 0; i < n; i++) {
ans = max(gcd(l[i], r[i]), ans);
}
cout << ans << "\n";
return 0;
}
| replace | 19 | 20 | 19 | 20 | TLE | |
p03061 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
if (x == 0)
return y;
if (y == 0)
return x;
while (x != y) {
if (x > y)
x -= y;
else
y -= x;
}
return x;
}
int main() {
int N;
cin >> N;
// vector<vector<char>> d(H, vector<char>(W));
vector<int> A(N + 1);
for (int i = 1; i <= N; i++)
cin >> A.at(i);
vector<int> L(N + 1);
L.at(0) = 0;
vector<int> R(N + 2);
R.at(N + 1) = 0;
for (int i = 1; i <= N; i++) {
L.at(i) = gcd(L.at(i - 1), A.at(i));
// cout << i << ":" << L.at(i) << endl;////
}
for (int i = N; i > 0; i--) {
R.at(i) = gcd(R.at(i + 1), A.at(i));
// cout << i << ":" << R.at(i) << endl;////
}
int c = 0;
for (int i = 1; i <= N; i++) {
c = max(c, gcd(L.at(i - 1), R.at(i + 1)));
// cout << i << ":" << c << endl;////////
}
cout << c << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
if (x < y)
swap(x, y);
while (y != 0) {
x %= y;
swap(x, y);
}
return x;
}
int main() {
int N;
cin >> N;
// vector<vector<char>> d(H, vector<char>(W));
vector<int> A(N + 1);
for (int i = 1; i <= N; i++)
cin >> A.at(i);
vector<int> L(N + 1);
L.at(0) = 0;
vector<int> R(N + 2);
R.at(N + 1) = 0;
for (int i = 1; i <= N; i++) {
L.at(i) = gcd(L.at(i - 1), A.at(i));
// cout << i << ":" << L.at(i) << endl;////
}
for (int i = N; i > 0; i--) {
R.at(i) = gcd(R.at(i + 1), A.at(i));
// cout << i << ":" << R.at(i) << endl;////
}
int c = 0;
for (int i = 1; i <= N; i++) {
c = max(c, gcd(L.at(i - 1), R.at(i + 1)));
// cout << i << ":" << c << endl;////////
}
cout << c << endl;
return 0;
}
| replace | 4 | 13 | 4 | 9 | TLE | |
p03061 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int gcd(int n, int m) {
if (m == 0)
return n;
else
return gcd(m, n % m);
}
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int x[n], y[n];
x[0] = a[0], y[n - 1] = a[n - 1];
for (int i = 1; i < n; i++) {
x[i] = gcd(x[i - 1], a[i]);
}
for (int i = n - 2; i >= 0; i++) {
y[i] = gcd(y[i + 1], a[i]);
}
int ans = 0;
ans = max({ans, x[n - 2], y[1]});
for (int i = 1; i < n - 1; i++) {
ans = max(ans, gcd(x[i - 1], y[i + 1]));
}
cout << ans << endl;
}
| #include <algorithm>
#include <iostream>
using namespace std;
int gcd(int n, int m) {
if (m == 0)
return n;
else
return gcd(m, n % m);
}
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int x[n], y[n];
x[0] = a[0], y[n - 1] = a[n - 1];
for (int i = 1; i < n; i++) {
x[i] = gcd(x[i - 1], a[i]);
}
for (int i = n - 2; i >= 0; i--) {
y[i] = gcd(y[i + 1], a[i]);
}
int ans = 0;
ans = max({ans, x[n - 2], y[1]});
for (int i = 1; i < n - 1; i++) {
ans = max(ans, gcd(x[i - 1], y[i + 1]));
}
cout << ans << endl;
}
| replace | 22 | 23 | 22 | 23 | TLE | |
p03061 | C++ | Runtime Error | // Created by conan1024hao on 2019/11/23.
// Copyright © 2019 conan1024hao. All rights reserved.
// 専用ライブラリです、自由にコピーして構いません。
// 感谢看我的代码!Wechat:conan1024hao QQ:810396815
#pragma GCC optimize("O3")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define chmax(x, y) x = mmax(x, y)
#define chmin(x, y) x = mmin(x, y)
#define all(x) (x).begin(), (x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll cmp(pair<ll, string> a, pair<ll, string> b) {
if (a.fi != b.fi)
return a.fi < b.fi;
else
return a.se < b.se;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
//-------------------------------
int n;
cin >> n;
vector<ll> a(n);
for (ll i = 1; i <= n; i++)
cin >> a[i];
vector<ll> l(n + 2);
vector<ll> r(n + 2);
vector<ll> m(n + 2);
sort(all(a));
l[0] = 0;
r[n + 1] = 0;
for (int i = 0; i < n; i++) {
l[i + 1] = GCD(l[i], a[i]);
}
for (int i = n; i > 1; i--) {
r[i] = GCD(r[i + 1], a[i]);
}
for (int i = 1; i <= n; i++) {
m[i] = GCD(l[i], r[i + 1]);
}
ll ans = -1;
for (int i = 1; i <= n; i++) {
chmax(ans, m[i]);
}
cout << ans << endl;
//-------------------------------
return 0;
}
//---------------------------------------------------------------------------
| // Created by conan1024hao on 2019/11/23.
// Copyright © 2019 conan1024hao. All rights reserved.
// 専用ライブラリです、自由にコピーして構いません。
// 感谢看我的代码!Wechat:conan1024hao QQ:810396815
#pragma GCC optimize("O3")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define chmax(x, y) x = mmax(x, y)
#define chmin(x, y) x = mmin(x, y)
#define all(x) (x).begin(), (x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll cmp(pair<ll, string> a, pair<ll, string> b) {
if (a.fi != b.fi)
return a.fi < b.fi;
else
return a.se < b.se;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
//-------------------------------
int n;
cin >> n;
vector<ll> a(n + 1);
for (ll i = 1; i <= n; i++)
cin >> a[i];
vector<ll> l(n + 2);
vector<ll> r(n + 2);
vector<ll> m(n + 2);
sort(all(a));
l[0] = 0;
r[n + 1] = 0;
for (int i = 0; i < n; i++) {
l[i + 1] = GCD(l[i], a[i]);
}
for (int i = n; i > 1; i--) {
r[i] = GCD(r[i + 1], a[i]);
}
for (int i = 1; i <= n; i++) {
m[i] = GCD(l[i], r[i + 1]);
}
ll ans = -1;
for (int i = 1; i <= n; i++) {
chmax(ans, m[i]);
}
cout << ans << endl;
//-------------------------------
return 0;
}
//---------------------------------------------------------------------------
| replace | 60 | 61 | 60 | 61 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p03061 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, GCD = 0;
cin >> N;
vector<int> H(N), CD(N + 1), CDR(N + 1);
for (int i = 0; i < N; i++)
cin >> H[i];
for (int i = 0; i < N; i++) {
for (int j = 0; j <= i; j++) {
if (CD[j + 1] == 0)
CD[j + 1] = gcd(CD[j], H[j]);
}
for (int j = N; j > i; j--) {
if (CDR[j - 1] == 0)
CDR[j - 1] = gcd(CDR[j], H[j - 1]);
}
}
for (int i = 0; i < N; i++) {
GCD = max(gcd(CD[i], CDR[i + 1]), GCD);
}
cout << GCD << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, GCD = 0;
cin >> N;
vector<int> H(N), CD(N + 1), CDR(N + 1);
for (int i = 0; i < N; i++)
cin >> H[i];
for (int j = 0; j < N; j++) {
CD[j + 1] = gcd(CD[j], H[j]);
}
for (int j = N; j > 0; j--) {
CDR[j - 1] = gcd(CDR[j], H[j - 1]);
}
for (int i = 0; i < N; i++) {
GCD = max(gcd(CD[i], CDR[i + 1]), GCD);
}
cout << GCD << endl;
return 0;
}
| replace | 13 | 22 | 13 | 18 | TLE | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int f, i, j, N, a[100001], m;
vector<int> v;
set<int> se;
scanf("%d", &N);
for (i = 0; i < N; i++) {
scanf("%d", &a[i]);
}
m = max(a[0], a[1]);
auto p = se.insert(1);
for (i = 1; i * i <= m; i++) {
if (a[0] % i == 0) {
p = se.insert(i);
if (p.second)
v.push_back(i);
p = se.insert(a[0] / i);
if (p.second)
v.push_back(a[0] / i);
}
if (a[1] % i == 0) {
p = se.insert(i);
if (p.second)
v.push_back(i);
p = se.insert(a[1] / i);
if (p.second)
v.push_back(a[1] / i);
}
}
sort(v.begin(), v.end(), greater<int>());
i = 0;
while (1) {
f = 0;
for (j = 0; j < N; j++) {
if (a[j] % v[i] != 0) {
if (f == 0) {
f = 1;
} else {
f = 2;
break;
}
}
}
if (f < 2) {
printf("%d\n", v[i]);
return 0;
}
i++;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int f, i, j, N, a[100001], m;
vector<int> v;
set<int> se;
scanf("%d", &N);
for (i = 0; i < N; i++) {
scanf("%d", &a[i]);
}
m = max(a[0], a[1]);
auto p = se.insert(1);
v.push_back(1);
for (i = 1; i * i <= m; i++) {
if (a[0] % i == 0) {
p = se.insert(i);
if (p.second)
v.push_back(i);
p = se.insert(a[0] / i);
if (p.second)
v.push_back(a[0] / i);
}
if (a[1] % i == 0) {
p = se.insert(i);
if (p.second)
v.push_back(i);
p = se.insert(a[1] / i);
if (p.second)
v.push_back(a[1] / i);
}
}
sort(v.begin(), v.end(), greater<int>());
i = 0;
while (1) {
f = 0;
for (j = 0; j < N; j++) {
if (a[j] % v[i] != 0) {
if (f == 0) {
f = 1;
} else {
f = 2;
break;
}
}
}
if (f < 2) {
printf("%d\n", v[i]);
return 0;
}
i++;
}
return 0;
} | insert | 14 | 14 | 14 | 15 | 0 | |
p03061 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
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;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
ll gcd(ll a, ll b) {
if (a < b)
gcd(b, a);
ll r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
// Function to find gcd of array of
// numbers
ll findGCD(vector<ll> arr, ll n) {
ll result = arr[0];
for (ll i = 1; i < n; i++)
result = gcd(arr[i], result);
return result;
}
int main() {
ll N;
cin >> N;
vector<ll> A(N);
REP(i, N) cin >> A[i];
ll gcd1 = findGCD(A, A.size());
REP(i, N) A[i] /= gcd1;
ll onecount = 0;
REP(i, N) {
if (A[i] == 1)
onecount++;
}
if (onecount >= 2) {
cout << gcd1 << endl;
return 0;
} else if (onecount == 1) {
ll tmp;
vector<ll> B(N);
REP(i, N) {
B[i] = A[i];
if (A[i] == 1) {
B[i] = A[i == 0 ? i + 1 : i - 1];
}
}
ll gcd2 = findGCD(B, B.size());
cout << gcd1 * gcd2 << endl;
return 0;
}
sort(ALL(A));
ll smallest = A[1];
ll gcd2 = 1;
for (ll i = smallest; i >= 2; i--) {
ll flag = 0;
REP(j, N) {
if (A[j] % i != 0)
flag++;
}
if (flag == 1) {
gcd2 = i;
break;
}
}
cout << gcd1 * gcd2 << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
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;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
ll gcd(ll a, ll b) {
if (a < b)
gcd(b, a);
ll r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
// Function to find gcd of array of
// numbers
ll findGCD(vector<ll> arr, ll n) {
ll result = arr[0];
for (ll i = 1; i < n; i++)
result = gcd(arr[i], result);
return result;
}
int main() {
ll N;
cin >> N;
vector<ll> A(N);
REP(i, N) cin >> A[i];
ll gcd1 = findGCD(A, A.size());
REP(i, N) A[i] /= gcd1;
ll onecount = 0;
REP(i, N) {
if (A[i] == 1)
onecount++;
}
if (onecount >= 2) {
cout << gcd1 << endl;
return 0;
} else if (onecount == 1) {
ll tmp;
vector<ll> B(N);
REP(i, N) {
B[i] = A[i];
if (A[i] == 1) {
B[i] = A[i == 0 ? i + 1 : i - 1];
}
}
ll gcd2 = findGCD(B, B.size());
cout << gcd1 * gcd2 << endl;
return 0;
}
sort(ALL(A));
ll smallest = A[1];
ll gcd2 = 1;
for (ll i = smallest; i >= 2; i--) {
ll flag = 0;
REP(j, N) {
if (A[j] % i != 0)
flag++;
if (flag >= 2)
break;
}
if (flag == 1) {
gcd2 = i;
break;
}
}
cout << gcd1 * gcd2 << endl;
return 0;
} | insert | 87 | 87 | 87 | 89 | TLE | |
p03061 | Python | Runtime Error | from math import gcd
n = int(input())
a = list(map(int, input().split()))
forward = []
backward = [0 for x in range(n)]
if n == 2:
print(max(a[0], a[1]))
exit(0)
for i in range(n):
if i == 0:
forward.append(a[i])
else:
forward.append(gcd(forward[i - 1], a[i]))
for i in range(n - 1, -1, -1):
if i == n - 1:
backward[i] = a[i]
else:
backward[i] = gcd(backward[i + 1], a[i])
ans = 1
for i in range(n):
if i == 0:
ans = max(ans, backward[1])
elif i == n - 1:
ans = max(ans, forward[n - 2])
else:
ans = max(ans, gcd(forward[i - 1], backward[i + 1]))
print(ans)
| from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
forward = []
backward = [0 for x in range(n)]
if n == 2:
print(max(a[0], a[1]))
exit(0)
for i in range(n):
if i == 0:
forward.append(a[i])
else:
forward.append(gcd(forward[i - 1], a[i]))
for i in range(n - 1, -1, -1):
if i == n - 1:
backward[i] = a[i]
else:
backward[i] = gcd(backward[i + 1], a[i])
ans = 1
for i in range(n):
if i == 0:
ans = max(ans, backward[1])
elif i == n - 1:
ans = max(ans, forward[n - 2])
else:
ans = max(ans, gcd(forward[i - 1], backward[i + 1]))
print(ans)
| replace | 0 | 1 | 0 | 1 | 0 | |
p03061 | Python | Runtime Error | from math import gcd
n = int(input())
a = list(map(int, input().split()))
fromLeft = [0] * n
fromLeft[0] = a[0]
fromRight = [0] * n
fromRight[0] = a[n - 1]
for i in range(1, n):
fromLeft[i] = gcd(fromLeft[i - 1], a[i])
fromRight[i] = gcd(fromRight[i - 1], a[n - i - 1])
ret = fromLeft[n - 1]
for i in range(n):
if i == 0:
curGcd = fromRight[n - 2]
elif i == n - 1:
curGcd = fromLeft[n - 2]
else:
curGcd = gcd(fromLeft[i - 1], fromRight[n - i - 2])
ret = max(ret, curGcd)
print(ret)
| def gcd(x, y):
while y:
x, y = y, x % y
return x
n = int(input())
a = list(map(int, input().split()))
fromLeft = [0] * n
fromLeft[0] = a[0]
fromRight = [0] * n
fromRight[0] = a[n - 1]
for i in range(1, n):
fromLeft[i] = gcd(fromLeft[i - 1], a[i])
fromRight[i] = gcd(fromRight[i - 1], a[n - i - 1])
ret = fromLeft[n - 1]
for i in range(n):
if i == 0:
curGcd = fromRight[n - 2]
elif i == n - 1:
curGcd = fromLeft[n - 2]
else:
curGcd = gcd(fromLeft[i - 1], fromRight[n - i - 2])
ret = max(ret, curGcd)
print(ret)
| replace | 0 | 1 | 0 | 5 | 0 | |
p03061 | Python | Time Limit Exceeded | from functools import reduce
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
A = list(set(a))
ans = [reduce(gcd, A)]
if len(A) == 1:
print(A[0])
exit()
for i in a:
b = sorted(A)
b.remove(i)
if a.count(i) == 1:
ans.append(reduce(gcd, b))
print(max(ans))
| from functools import reduce
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
A = list(set(a))
ans = [reduce(gcd, A)]
if len(A) == 1:
print(A[0])
exit()
for i in A:
b = sorted(A)
b.remove(i)
if a.count(i) == 1:
ans.append(reduce(gcd, b))
print(max(ans))
| replace | 11 | 12 | 11 | 12 | TLE | |
p03061 | Python | Runtime Error | from math import gcd
def main():
N = int(input())
nums = list(map(int, input().split()))
L = [0 for _ in range(N + 1)]
R = [0 for _ in range(N + 1)]
for i, num in enumerate(nums):
L[i + 1] = gcd(L[i], num)
for i in range(N - 2, -1, -1):
R[i] = gcd(R[i + 1], nums[i + 1])
print(max(gcd(L[i], R[i]) for i in range(N)))
if __name__ == "__main__":
main()
| #!/snap/bin/pypy3
def gcd(a, b):
if b == 0:
return a
c = a % b
return gcd(b, c)
def main():
N = int(input())
nums = list(map(int, input().split()))
L = [0 for _ in range(N + 1)]
R = [0 for _ in range(N + 1)]
for i, num in enumerate(nums):
L[i + 1] = gcd(L[i], num)
for i in range(N - 2, -1, -1):
R[i] = gcd(R[i + 1], nums[i + 1])
print(max(gcd(L[i], R[i]) for i in range(N)))
if __name__ == "__main__":
main()
| replace | 0 | 1 | 0 | 6 | 0 | |
p03061 | Python | Time Limit Exceeded | N = int(input())
A = [int(i) for i in input().split()]
if len(A) > 1:
result = sorted(A)[1]
else:
result = min(A)
while True:
counter = 0
should_continue = False
for e in A:
if e % result != 0:
counter += 1
if counter > 1:
should_continue = True
break
if should_continue:
continue
if counter <= 1: # 1つは書き換えられる
break
else:
result -= 1
print(result)
| N = int(input())
A = [int(i) for i in input().split()]
if len(A) > 1:
result = sorted(A)[1]
else:
result = min(A)
while True:
counter = 0
should_continue = False
for e in A:
if e % result != 0:
counter += 1
if counter > 1:
should_continue = True
break
if should_continue:
result -= 1
continue
if counter <= 1: # 1つは書き換えられる
break
else:
result -= 1
print(result)
| insert | 18 | 18 | 18 | 19 | TLE | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
typedef long long int lli;
typedef pair<int, int> P;
int A[10000];
int R[10000];
int L[10000];
int n;
int gcd(int a, int b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
int r;
r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
int calc_l(int max_i) {
if (max_i < 0)
return 0;
if (L[max_i] != 0)
return L[max_i];
if (max_i == 0)
return L[0] = A[0];
return L[max_i] = gcd(calc_l(max_i - 1), A[max_i]);
}
int calc_r(int min_i) {
if (min_i > n - 1)
return 0;
if (R[min_i] != 0)
return R[min_i];
if (min_i == n - 1)
return R[n - 1] = A[n - 1];
return R[min_i] = gcd(calc_r(min_i + 1), A[min_i]);
}
int exclude_gcd(int ex_i) { return gcd(calc_l(ex_i - 1), calc_r(ex_i + 1)); }
int main() {
cin >> n;
REP(i, n) { cin >> A[i]; }
int max_gcd = 0;
// i を除いたときのgcd
REP(i, n) {
int cur_gcd = exclude_gcd(i);
max_gcd = max(max_gcd, cur_gcd);
}
cout << max_gcd << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
typedef long long int lli;
typedef pair<int, int> P;
int A[100000];
int R[100000];
int L[100000];
int n;
int gcd(int a, int b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
int r;
r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
int calc_l(int max_i) {
if (max_i < 0)
return 0;
if (L[max_i] != 0)
return L[max_i];
if (max_i == 0)
return L[0] = A[0];
return L[max_i] = gcd(calc_l(max_i - 1), A[max_i]);
}
int calc_r(int min_i) {
if (min_i > n - 1)
return 0;
if (R[min_i] != 0)
return R[min_i];
if (min_i == n - 1)
return R[n - 1] = A[n - 1];
return R[min_i] = gcd(calc_r(min_i + 1), A[min_i]);
}
int exclude_gcd(int ex_i) { return gcd(calc_l(ex_i - 1), calc_r(ex_i + 1)); }
int main() {
cin >> n;
REP(i, n) { cin >> A[i]; }
int max_gcd = 0;
// i を除いたときのgcd
REP(i, n) {
int cur_gcd = exclude_gcd(i);
max_gcd = max(max_gcd, cur_gcd);
}
cout << max_gcd << endl;
}
| replace | 7 | 10 | 7 | 10 | 0 | |
p03061 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;
int gcd(int m, int n) {
while (m != n)
m > n ? (m = m - n) : (n = n - m);
return m;
}
int main() {
int n;
int a[100001], l[100001], r[100001];
cin >> n;
REP(i, n) cin >> a[i];
l[0] = a[0];
REP(i, n - 1) l[i + 1] = gcd(l[i], a[i + 1]);
r[n - 1] = a[n - 1];
for (int i = n - 1; i > 0; i--)
r[i - 1] = gcd(r[i], a[i - 1]);
int ans = max(l[n - 2], r[1]);
FOR(i, 1, n - 1) ans = max(ans, gcd(l[i - 1], r[i + 1]));
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int main() {
int n;
int a[100001], l[100001], r[100001];
cin >> n;
REP(i, n) cin >> a[i];
l[0] = a[0];
REP(i, n - 1) l[i + 1] = gcd(l[i], a[i + 1]);
r[n - 1] = a[n - 1];
for (int i = n - 1; i > 0; i--)
r[i - 1] = gcd(r[i], a[i - 1]);
int ans = max(l[n - 2], r[1]);
FOR(i, 1, n - 1) ans = max(ans, gcd(l[i - 1], r[i + 1]));
cout << ans << endl;
return 0;
} | replace | 9 | 14 | 9 | 10 | TLE | |
p03061 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define OO 1e9
#define SS second
#define FF first
#define Trace(n) cout << #n << " = " << n << endl;
#define ll long long
// #define endl "\n"
#define all(v) ((v).begin()), ((v).end())
#define boom main
#define cn(n) scanf("%d", &n)
#define cnl(n) scanf("%lld", &n)
#define F(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define Fill(ar, val) memset(ar, val, sizeof(ar))
#define bit(n) (1 << (n))
int dx[] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[] = {-1, 1, 0, 0, 1, -1, 1, -1};
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
fast();
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
int N1 = v[0];
int N2 = v[1];
set<int> divs;
map<int, int> mp;
for (int i = 1; i * i <= N1; i++) {
if (N1 % i == 0) {
divs.insert(i);
divs.insert(N1 / i);
}
}
for (int i = 1; i * i <= N2; i++) {
if (N2 % i == 0) {
divs.insert(i);
divs.insert(N2 / i);
}
}
for (int i = 0; i < n; i++) {
for (auto Num : divs) {
if (v[i] % Num == 0) {
mp[Num]++;
}
}
}
int ans = 1;
for (auto it : mp) {
if (it.SS >= (n - 1))
ans = max(ans, it.FF);
}
cout << ans;
} | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265
#define OO 1e9
#define SS second
#define FF first
#define Trace(n) cout << #n << " = " << n << endl;
#define ll long long
// #define endl "\n"
#define all(v) ((v).begin()), ((v).end())
#define boom main
#define cn(n) scanf("%d", &n)
#define cnl(n) scanf("%lld", &n)
#define F(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define Fill(ar, val) memset(ar, val, sizeof(ar))
#define bit(n) (1 << (n))
int dx[] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[] = {-1, 1, 0, 0, 1, -1, 1, -1};
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fast();
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
int N1 = v[0];
int N2 = v[1];
set<int> divs;
map<int, int> mp;
for (int i = 1; i * i <= N1; i++) {
if (N1 % i == 0) {
divs.insert(i);
divs.insert(N1 / i);
}
}
for (int i = 1; i * i <= N2; i++) {
if (N2 % i == 0) {
divs.insert(i);
divs.insert(N2 / i);
}
}
for (int i = 0; i < n; i++) {
for (auto Num : divs) {
if (v[i] % Num == 0) {
mp[Num]++;
}
}
}
int ans = 1;
for (auto it : mp) {
if (it.SS >= (n - 1))
ans = max(ans, it.FF);
}
cout << ans;
} | delete | 29 | 34 | 29 | 29 | -11 | |
p03061 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
if (x > y)
swap(x, y);
if (y % x == 0)
return x;
else
return gcd(y % x, x);
}
int main(void) {
int n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
long long g[n]; // i番目を除いたn-1この整数の最大公約数
for (int i = 0; i < n; i++) {
long long G = a[0];
if (i == 0)
G = a[1];
for (int j = 0; j < n; j++) {
if (i == j)
continue;
G = gcd(G, a[j]);
}
g[i] = G;
}
long long res = 0;
for (int i = 0; i < n; i++) {
res = max(res, g[i]);
}
cout << res << endl;
}
| #include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
if (x > y)
swap(x, y);
if (y % x == 0)
return x;
else
return gcd(y % x, x);
}
int main(void) {
int n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
long long g[n]; // i番目を除いたn-1この整数の最大公約数
long long r[n], l[n];
/*
r[i]=gcd(a[0),a[1],…,a[i]);
l[i]=gcd(a[n-1],a[n-2],a[n-3],…,a[i]);
g[n]=gcd(r[i],l[i]);
*/
r[0] = a[0];
l[n - 1] = a[n - 1];
for (int i = 1; i < n; i++) {
r[i] = gcd(r[i - 1], a[i]);
l[n - i - 1] = gcd(l[n - i], a[n - 1 - i]);
}
g[0] = l[1];
g[n - 1] = r[n - 2];
for (int i = 1; i < n - 1; i++) {
g[i] = gcd(r[i - 1], l[i + 1]);
}
long long res = 0;
for (int i = 0; i < n; i++) {
res = max(res, g[i]);
}
cout << res << endl;
}
| replace | 17 | 27 | 17 | 33 | TLE | |
p03061 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
int c = min(a, b), d = max(a, b);
if (d % c == 0)
return c;
return GCD(c, d % c);
}
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end());
if (a[0] == a[n - 1]) {
cout << a[0] << endl;
return 0;
}
if (a.size() == 3) {
cout << max({GCD(a[0], a[1]), GCD(a[1], a[2]), GCD(a[2], a[0])}) << endl;
return 0;
}
int bef = a[0], aft = a[n - 1];
int s = 0, g = n;
while (s != g) {
for (int i = s; i < (g - s) / 2; i++)
bef = GCD(bef, a[i]);
for (int i = (g - s) / 2; i < (g - s); i++)
aft = GCD(aft, a[i]);
if (bef == aft)
s = g;
if (bef > aft) {
aft = bef;
s = s + (g - s) / 2;
}
if (bef < aft) {
bef = aft;
g = s + (g - s) / 2;
}
}
cout << bef << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
int c = min(a, b), d = max(a, b);
if (d % c == 0)
return c;
return GCD(c, d % c);
}
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end());
if (a[0] == a[n - 1]) {
cout << a[0] << endl;
return 0;
}
if (a.size() == 3) {
cout << max({GCD(a[0], a[1]), GCD(a[1], a[2]), GCD(a[2], a[0])}) << endl;
return 0;
}
int bef = a[0], aft = a[n - 1];
int s = 0, g = n;
while (s + 1 < g) {
for (int i = s; i < (g - s) / 2; i++)
bef = GCD(bef, a[i]);
for (int i = (g - s) / 2; i < (g - s); i++)
aft = GCD(aft, a[i]);
if (bef == aft)
s = g;
if (bef > aft) {
aft = bef;
s = s + (g - s) / 2;
}
if (bef < aft) {
bef = aft;
g = s + (g - s) / 2;
}
}
cout << bef << endl;
return 0;
} | replace | 26 | 27 | 26 | 27 | TLE | |
p03061 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll, ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
#define mx 1000010
int main() {
IOS;
ll n;
cin >> n;
ll a[n];
rep(i, 0, n) cin >> a[i];
ll od = 0, ev = 0, k = 1, mx1 = k, t = 1;
rep(i, 0, n) k = __gcd(a[i], k);
rep(i, 0, n) {
if (i == 0)
t = a[1];
else
t = a[0];
rep(j, 0, n) {
if (j != i) {
t = __gcd(a[j], t);
if (t == k)
break;
}
}
mx1 = max(mx1, t);
}
cout << mx1;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll, ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define inf 1e16
#define M 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
#define mx 1000010
int main() {
IOS;
ll n;
cin >> n;
ll a[n];
rep(i, 0, n) cin >> a[i];
ll od = 0, ev = 0, k = 1, mx1 = k, t = 1;
rep(i, 0, n) k = __gcd(a[i], k);
rep(i, 0, n) {
if (i == 0)
t = a[1];
else
t = a[0];
rep(j, 0, min(n, 50ll)) {
if (j != i) {
t = __gcd(a[j], t);
if (t == k)
break;
}
}
mx1 = max(mx1, t);
}
cout << mx1;
return 0;
}
| replace | 34 | 35 | 34 | 35 | TLE | |
p03061 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll(c, d)));
#define re(c, b) for (ll c = 0; c < b; c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
#define SPLIT 20
template <typename T> struct PersistentArray {
struct vertex {
T dat;
array<vertex *, SPLIT> ch;
vertex() { ch.fill(nullptr); };
};
T zero;
PersistentArray(){};
PersistentArray(T z) : zero(z){};
vertex *root = nullptr;
ll ver = 0;
vector<vertex *> version; // 指定したバージョンのルート
inline vertex *set(ll idx, T x, vertex *par) {
vertex *now = new vertex();
if (par) {
now->ch = par->ch;
now->dat = par->dat;
}
if (idx == 0)
now->dat = x;
else
now->ch[idx % SPLIT] = set(idx / SPLIT, x, now->ch[idx % SPLIT]);
return now;
}
ll update(ll prev, ll idx, T x) {
vertex *now = set(idx, x, (prev == -1 ? root : version[prev]));
version.push_back(now);
return ver++;
}
T query(ll prev, ll idx) {
vertex *now = (prev == -1 ? root : version[prev]);
if (now == nullptr)
return zero;
while (idx) {
now = now->ch[idx % SPLIT];
idx /= SPLIT;
if (now == nullptr)
return zero;
}
return now->dat;
}
};
template <typename T> struct PersistentSegtree {
typedef function<T(T, T)> G; // merge
typedef function<T(T, T)> H; // update
PersistentArray<T> dat;
vector<ll> las; // PersistentArrayの最後のバージョン
ll M = 1, ver = 0;
G g;
H h;
T UNIT;
PersistentSegtree(ll N, T unit, G merge_func, H update_func) : UNIT(unit) {
dat = PersistentArray<T>(UNIT);
g = merge_func;
h = update_func;
while (M < N)
M *= 2;
}
inline ll update(ll v, ll k, T x, ll l = 0, ll r = -1) {
if (r == -1)
r = M;
k += M - 1;
ll array_ver = (v == -1 ? -1 : las[v]);
ll num = h(dat.query(array_ver, k), x);
ll idx = dat.update(array_ver, k, num);
las.push_back(idx);
while (k > 0) {
k = (k - 1) / 2;
T L = dat.query(las[ver], k * 2 + 1);
T R = dat.query(las[ver], k * 2 + 2);
num = g(L, R);
las[ver] = dat.update(las[ver], k, num);
}
return ver++;
}
T query(ll v, ll a, ll b = -1, ll k = 0, ll l = 0, ll r = -1) {
if (r == -1)
r = M;
if (b == -1)
b = M;
if (r <= a || b <= l)
return UNIT;
if (a <= l && r <= b)
return dat.query((v == -1 ? -1 : las[v]), k);
T A = query(v, a, b, k * 2 + 1, l, (l + r) / 2);
T B = query(v, a, b, k * 2 + 2, (l + r) / 2, r);
return g(A, B);
}
};
ll gcd(ll a, ll b) {
if (b < a)
swap(a, b);
ll r = a % b;
if (r == 0)
return b;
while (r != 0)
r = a % b, a = b, b = r;
return a;
}
ll mg(ll l, ll r) {
if (l == 0)
return r;
if (r == 0)
return l;
return gcd(l, r);
}
ll upd(ll old, ll nw) { return nw; }
int main() {
ll n;
std::cin >> n;
PersistentSegtree<int> seg(n + 1, 0, mg, upd);
ll v = -1;
for (int i = 0; i < n; i++) {
ll t;
scanf("%lld", &t);
v = seg.update(v, i, t);
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ll L = seg.query(v, 0, i);
ll R = seg.query(v, i + 1, n);
ans = max(ans, gcd(L, R));
}
std::cout << ans << '\n';
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll(c, d)));
#define re(c, b) for (ll c = 0; c < b; c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
#define SPLIT 3
template <typename T> struct PersistentArray {
struct vertex {
T dat;
array<vertex *, SPLIT> ch;
vertex() { ch.fill(nullptr); };
};
T zero;
PersistentArray(){};
PersistentArray(T z) : zero(z){};
vertex *root = nullptr;
ll ver = 0;
vector<vertex *> version; // 指定したバージョンのルート
inline vertex *set(ll idx, T x, vertex *par) {
vertex *now = new vertex();
if (par) {
now->ch = par->ch;
now->dat = par->dat;
}
if (idx == 0)
now->dat = x;
else
now->ch[idx % SPLIT] = set(idx / SPLIT, x, now->ch[idx % SPLIT]);
return now;
}
ll update(ll prev, ll idx, T x) {
vertex *now = set(idx, x, (prev == -1 ? root : version[prev]));
version.push_back(now);
return ver++;
}
T query(ll prev, ll idx) {
vertex *now = (prev == -1 ? root : version[prev]);
if (now == nullptr)
return zero;
while (idx) {
now = now->ch[idx % SPLIT];
idx /= SPLIT;
if (now == nullptr)
return zero;
}
return now->dat;
}
};
template <typename T> struct PersistentSegtree {
typedef function<T(T, T)> G; // merge
typedef function<T(T, T)> H; // update
PersistentArray<T> dat;
vector<ll> las; // PersistentArrayの最後のバージョン
ll M = 1, ver = 0;
G g;
H h;
T UNIT;
PersistentSegtree(ll N, T unit, G merge_func, H update_func) : UNIT(unit) {
dat = PersistentArray<T>(UNIT);
g = merge_func;
h = update_func;
while (M < N)
M *= 2;
}
inline ll update(ll v, ll k, T x, ll l = 0, ll r = -1) {
if (r == -1)
r = M;
k += M - 1;
ll array_ver = (v == -1 ? -1 : las[v]);
ll num = h(dat.query(array_ver, k), x);
ll idx = dat.update(array_ver, k, num);
las.push_back(idx);
while (k > 0) {
k = (k - 1) / 2;
T L = dat.query(las[ver], k * 2 + 1);
T R = dat.query(las[ver], k * 2 + 2);
num = g(L, R);
las[ver] = dat.update(las[ver], k, num);
}
return ver++;
}
T query(ll v, ll a, ll b = -1, ll k = 0, ll l = 0, ll r = -1) {
if (r == -1)
r = M;
if (b == -1)
b = M;
if (r <= a || b <= l)
return UNIT;
if (a <= l && r <= b)
return dat.query((v == -1 ? -1 : las[v]), k);
T A = query(v, a, b, k * 2 + 1, l, (l + r) / 2);
T B = query(v, a, b, k * 2 + 2, (l + r) / 2, r);
return g(A, B);
}
};
ll gcd(ll a, ll b) {
if (b < a)
swap(a, b);
ll r = a % b;
if (r == 0)
return b;
while (r != 0)
r = a % b, a = b, b = r;
return a;
}
ll mg(ll l, ll r) {
if (l == 0)
return r;
if (r == 0)
return l;
return gcd(l, r);
}
ll upd(ll old, ll nw) { return nw; }
int main() {
ll n;
std::cin >> n;
PersistentSegtree<int> seg(n + 1, 0, mg, upd);
ll v = -1;
for (int i = 0; i < n; i++) {
ll t;
scanf("%lld", &t);
v = seg.update(v, i, t);
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ll L = seg.query(v, 0, i);
ll R = seg.query(v, i + 1, n);
ans = max(ans, gcd(L, R));
}
std::cout << ans << '\n';
}
| replace | 25 | 26 | 25 | 26 | MLE | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
ll n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<ll> left(n, 0);
vector<ll> right(n, 0);
for (int i = 0; i < n; i++)
left[i + 1] = gcd(left[i], a[i]);
for (int i = n - 1; i >= 0; i--)
right[i] = gcd(right[i + 1], a[i]);
int res = 0;
for (int i = 0; i < n; i++) {
int l = left[i];
int r = right[i + 1];
if (res < gcd(l, r)) {
res = gcd(l, r);
}
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
ll n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<ll> left(n + 1, 0);
vector<ll> right(n + 1, 0);
for (int i = 0; i < n; i++)
left[i + 1] = gcd(left[i], a[i]);
for (int i = n - 1; i >= 0; i--)
right[i] = gcd(right[i + 1], a[i]);
int res = 0;
for (int i = 0; i < n; i++) {
int l = left[i];
int r = right[i + 1];
if (res < gcd(l, r)) {
res = gcd(l, r);
}
}
cout << res << endl;
return 0;
} | replace | 13 | 15 | 13 | 15 | -6 | free(): invalid pointer
|
p03061 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
map<pair<int, int>, int> g_range_gcd;
int range_gcd(const vector<int> &A, int l, int r) {
if (r - l == 1)
return A[l];
if (g_range_gcd.count(make_pair(l, r)) != 0) {
return g_range_gcd[make_pair(l, r)];
}
int m = (l + r) / 2;
return gcd(range_gcd(A, l, m), range_gcd(A, m, r));
}
int range_gcd2(const vector<int> &A, int l, int r, int x) {
if (r - l == 1) {
return l == x ? -1 : A[l];
}
if (x < l || r <= x) {
return range_gcd(A, l, r);
}
int m = (l + r) / 2;
int a = range_gcd2(A, l, m, x);
int b = range_gcd2(A, m, r, x);
if (a == -1)
return b;
if (b == -1)
return a;
return gcd(a, b);
}
int main() {
int N;
cin >> N;
vector<int> A(N);
REP(i, N) cin >> A[i];
int res = 1;
for (int i = 0; i < N; i++) {
res = max(res, range_gcd2(A, 0, N, i));
}
cout << res << endl;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
map<pair<int, int>, int> g_range_gcd;
int range_gcd(const vector<int> &A, int l, int r) {
if (r - l == 1)
return A[l];
if (g_range_gcd.count(make_pair(l, r)) != 0) {
return g_range_gcd[make_pair(l, r)];
}
int m = (l + r) / 2;
return g_range_gcd[make_pair(l, r)] =
gcd(range_gcd(A, l, m), range_gcd(A, m, r));
}
int range_gcd2(const vector<int> &A, int l, int r, int x) {
if (r - l == 1) {
return l == x ? -1 : A[l];
}
if (x < l || r <= x) {
return range_gcd(A, l, r);
}
int m = (l + r) / 2;
int a = range_gcd2(A, l, m, x);
int b = range_gcd2(A, m, r, x);
if (a == -1)
return b;
if (b == -1)
return a;
return gcd(a, b);
}
int main() {
int N;
cin >> N;
vector<int> A(N);
REP(i, N) cin >> A[i];
int res = 1;
for (int i = 0; i < N; i++) {
res = max(res, range_gcd2(A, 0, N, i));
}
cout << res << endl;
} | replace | 19 | 20 | 19 | 21 | TLE | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array) / sizeof(array[0]))
using ll = long long;
using namespace std;
using Graph = vector<vector<int>>;
using Field = vector<vector<int>>;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<ll> l(n), r(n);
l[0] = a[0];
r[0] = a[n - 1];
rep(i, n) {
l[i + 1] = __gcd(l[i], a[i + 1]);
r[i + 1] = __gcd(r[i], a[(n - 1) - (i + 1)]);
}
vector<ll> ans(n);
ans[0] = r[n - 2];
ans[n - 1] = l[n - 2];
for (int i = 1; i < n - 1; ++i) {
ans[i] = __gcd(l[i - 1], r[n - 3 - (i - 1)]);
}
ll ret = 0;
rep(i, n) { ret = max(ret, ans[i]); }
cout << ret << endl;
}
| #include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array) / sizeof(array[0]))
using ll = long long;
using namespace std;
using Graph = vector<vector<int>>;
using Field = vector<vector<int>>;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<ll> l(n + 1), r(n + 1);
l[0] = a[0];
r[0] = a[n - 1];
rep(i, n) {
l[i + 1] = __gcd(l[i], a[i + 1]);
r[i + 1] = __gcd(r[i], a[(n - 1) - (i + 1)]);
}
vector<ll> ans(n);
ans[0] = r[n - 2];
ans[n - 1] = l[n - 2];
for (int i = 1; i < n - 1; ++i) {
ans[i] = __gcd(l[i - 1], r[n - 3 - (i - 1)]);
}
ll ret = 0;
rep(i, n) { ret = max(ret, ans[i]); }
cout << ret << endl;
}
| replace | 29 | 30 | 29 | 30 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout << n << endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
// vector<tuple<long long, long long, long long>>vec;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
llong gcd(llong a, llong b) { return b != 0 ? gcd(b, a % b) : a; }
int main() {
int n;
cin >> n;
vector<llong> a(n, 0);
REP(i, n) cin >> a[i];
vector<llong> front(n, 0);
front[0] = a[0];
vector<llong> back(n, 0);
back[n - 1] = a[n - 1];
for (int i = 0; i < n; i++) {
front[i + 1] = gcd(front[i], a[i + 1]);
}
for (int i = n - 2; i >= 0; i--) {
back[i] = gcd(a[i], back[i + 1]);
}
llong ans = 0;
for (int i = 1; i < n - 1; i++) {
llong m = gcd(front[i - 1], back[i + 1]);
ans = max(ans, m);
}
llong fro = back[1];
llong bac = front[n - 2];
cout << max({ans, fro, bac}) << endl;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout << n << endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
// vector<tuple<long long, long long, long long>>vec;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
llong gcd(llong a, llong b) { return b != 0 ? gcd(b, a % b) : a; }
int main() {
int n;
cin >> n;
vector<llong> a(n, 0);
REP(i, n) cin >> a[i];
vector<llong> front(n, 0);
front[0] = a[0];
vector<llong> back(n, 0);
back[n - 1] = a[n - 1];
for (int i = 0; i < n - 1; i++) {
front[i + 1] = gcd(front[i], a[i + 1]);
}
for (int i = n - 2; i >= 0; i--) {
back[i] = gcd(a[i], back[i + 1]);
}
llong ans = 0;
for (int i = 1; i < n - 1; i++) {
llong m = gcd(front[i - 1], back[i + 1]);
ans = max(ans, m);
}
llong fro = back[1];
llong bac = front[n - 2];
cout << max({ans, fro, bac}) << endl;
} | replace | 48 | 49 | 48 | 49 | -6 | free(): invalid pointer
|
p03061 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
while (x && y) {
x %= y;
if (x == 0)
break;
y %= x;
}
return x + y;
}
int seg(int l, int r, int n, int nl, int nr, vector<int> t) {
if (l >= nr || r <= nl)
return 0; // 範囲がノードから外れている
else if (l <= nl && r >= nr)
return t[n]; // 範囲がノードを包含している
else {
int mid = (nl + nr) / 2;
return gcd(seg(l, r, n * 2, nl, mid, t), seg(l, r, n * 2 + 1, mid, nr, t));
}
}
int main() {
int n;
cin >> n;
int N;
for (int i = 1; i < n * 2; i *= 2)
N = i;
int a[n];
vector<int> t(N * 2, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
t[i + N] = a[i];
}
for (int i = N - 1; i >= 1; i--) {
t[i] = gcd(t[i * 2], t[i * 2 + 1]);
}
int m = 0;
for (int i = 0; i < n; i++) {
m = max(m, gcd(seg(0, i, 1, 0, N, t), seg(i + 1, n, 1, 0, N, t)));
}
cout << m << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
while (x && y) {
x %= y;
if (x == 0)
break;
y %= x;
}
return x + y;
}
int seg(int l, int r, int n, int nl, int nr, vector<int> &t) {
if (l >= nr || r <= nl)
return 0; // 範囲がノードから外れている
else if (l <= nl && r >= nr)
return t[n]; // 範囲がノードを包含している
else {
int mid = (nl + nr) / 2;
return gcd(seg(l, r, n * 2, nl, mid, t), seg(l, r, n * 2 + 1, mid, nr, t));
}
}
int main() {
int n;
cin >> n;
int N;
for (int i = 1; i < n * 2; i *= 2)
N = i;
int a[n];
vector<int> t(N * 2, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
t[i + N] = a[i];
}
for (int i = N - 1; i >= 1; i--) {
t[i] = gcd(t[i * 2], t[i * 2 + 1]);
}
int m = 0;
for (int i = 0; i < n; i++) {
m = max(m, gcd(seg(0, i, 1, 0, N, t), seg(i + 1, n, 1, 0, N, t)));
}
cout << m << endl;
return 0;
} | replace | 11 | 12 | 11 | 12 | TLE | |
p03061 | C++ | Runtime Error | //
// Created by kuroneko on 2019-07-06.
//
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
ll GCD(ll a, ll b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
return GCD(b, a % b);
}
int LCM(int a, int b) {
int g = GCD(a, b);
return a / g * b;
}
int main() {
int N;
cin >> N;
vector<ll> A(N);
int L[100000], R[100000];
for (int i = 0; i < N; i++)
cin >> A[i];
L[0] = 0;
R[N] = 0;
L[1] = 0;
R[N - 1] = 0;
for (int i = 1; i < N; i++) {
L[i + 1] = GCD(L[i], A[i - 1]);
R[N - i] = GCD(R[N - i + 1], A[N - i]);
}
ll ans = 0;
for (int i = 1; i <= N; i++) {
ans = max(ans, GCD(L[i], R[i]));
}
cout << ans << endl;
return 0;
} | //
// Created by kuroneko on 2019-07-06.
//
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
ll GCD(ll a, ll b) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
return GCD(b, a % b);
}
int LCM(int a, int b) {
int g = GCD(a, b);
return a / g * b;
}
int main() {
int N;
cin >> N;
vector<ll> A(N);
int L[100000 + 7], R[100000 + 7];
for (int i = 0; i < N; i++)
cin >> A[i];
L[0] = 0;
R[N] = 0;
L[1] = 0;
R[N - 1] = 0;
for (int i = 1; i < N; i++) {
L[i + 1] = GCD(L[i], A[i - 1]);
R[N - i] = GCD(R[N - i + 1], A[N - i]);
}
ll ans = 0;
for (int i = 1; i <= N; i++) {
ans = max(ans, GCD(L[i], R[i]));
}
cout << ans << endl;
return 0;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p03061 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ll n;
cin >> n;
ll a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
ll count = 0, ans;
for (int i = a[1]; i > 0; i--) {
for (int j = 0; j < n; j++) {
if (a[j] % i == 0)
count++;
}
if (count > n - 2) {
ans = i;
break;
} else
count = 0;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ll n;
cin >> n;
ll a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
ll count = 0, ans;
for (int i = a[1]; i > 0; i--) {
if (a[1] % i == 0 || a[0] % i == 0) {
for (int j = 0; j < n; j++) {
if (a[j] % i == 0)
count++;
}
}
if (count > n - 2) {
ans = i;
break;
} else
count = 0;
}
cout << ans << endl;
} | replace | 12 | 15 | 12 | 17 | TLE | |
p03061 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll A[10101];
ll L[10101];
ll R[10101];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> A[i];
}
L[1] = A[1];
for (int i = 2; i <= n; i++)
L[i] = gcd(L[i - 1], A[i]);
R[n] = A[n];
for (int i = n - 1; i >= 1; i--)
R[i] = gcd(R[i + 1], A[i]);
ll ans = 0;
for (int i = 1; i <= n; i++) {
if (i == 1)
ans = max(ans, R[2]);
else if (i == n)
ans = max(ans, L[n - 1]);
else {
ans = max(ans, gcd(L[i - 1], R[i + 1]));
}
}
cout << ans << endl;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll A[101010];
ll L[101010];
ll R[101010];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> A[i];
}
L[1] = A[1];
for (int i = 2; i <= n; i++)
L[i] = gcd(L[i - 1], A[i]);
R[n] = A[n];
for (int i = n - 1; i >= 1; i--)
R[i] = gcd(R[i + 1], A[i]);
ll ans = 0;
for (int i = 1; i <= n; i++) {
if (i == 1)
ans = max(ans, R[2]);
else if (i == n)
ans = max(ans, L[n - 1]);
else {
ans = max(ans, gcd(L[i - 1], R[i + 1]));
}
}
cout << ans << endl;
return 0;
} | replace | 8 | 11 | 8 | 11 | 0 | |
p03061 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
while (a && b) {
(a < b) ? b %= a : a %= b;
}
return a + b;
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (auto &a : A) {
cin >> a;
}
int gcd_max = -1;
for (int ii = 0; ii < N; ii++) {
int gcd_sub = (ii == 0) ? A[1] : A[0];
for (int jj = 0; jj < N; jj++) {
if (jj == ii)
continue;
gcd_sub = gcd(gcd_sub, A[jj]);
}
gcd_max = max(gcd_max, gcd_sub);
}
cout << gcd_max << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
while (a && b) {
(a < b) ? b %= a : a %= b;
}
return a + b;
}
int main() {
int N;
cin >> N;
vector<int> A(N);
for (auto &a : A) {
cin >> a;
}
vector<int> gcd_front(N);
vector<int> gcd_back(N);
gcd_front[0] = A[0];
for (int ii = 1; ii < N; ii++) {
gcd_front[ii] = gcd(gcd_front[ii - 1], A[ii]);
}
gcd_back[N - 1] = A[N - 1];
for (int ii = N - 2; ii >= 0; ii--) {
gcd_back[ii] = gcd(gcd_back[ii + 1], A[ii]);
}
int gcd_max = max(gcd_back[1], gcd_front[N - 2]);
for (int ii = 1; ii < N - 1; ii++) {
gcd_max = max(gcd_max, gcd(gcd_front[ii - 1], gcd_back[ii + 1]));
}
cout << gcd_max << endl;
return 0;
}
| replace | 18 | 27 | 18 | 34 | TLE | |
p03061 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N;
cin >> N;
vll A(N);
ll B = 316;
vll backet(10000 / B + 1, -1);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
if (backet.at(i / B) == -1)
backet.at(i / B) = A.at(i);
else
backet.at(i / B) = __gcd(backet.at(i / B), A.at(i));
}
auto func = [&](int left, int right) {
ll res = -1;
while (left < right && left % B != 0) {
if (res == -1)
res = A.at(left);
else
res = __gcd(res, A.at(left));
left++;
}
while (left < right && right % B != 0) {
right--;
if (res == -1)
res = A.at(right);
else
res = __gcd(res, A.at(right));
}
for (int i = left; i < right; i += B) {
if (res == -1)
res = backet.at(i / B);
else
res = __gcd(res, backet.at(i / B));
}
return res;
};
ll ans = -1;
for (int i = 0; i < N; i++) {
ll res = -1;
if (i == 0)
res = func(1, N);
else if (i == N - 1)
res = func(0, N - 1);
else
res = __gcd(func(0, i), func(i + 1, N));
chmax(ans, res);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);
#define MOD 1000000007LL
#define endl "\n"
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll N;
cin >> N;
vll A(N);
ll B = 316;
vll backet(100000 / B + 1, -1);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
if (backet.at(i / B) == -1)
backet.at(i / B) = A.at(i);
else
backet.at(i / B) = __gcd(backet.at(i / B), A.at(i));
}
auto func = [&](int left, int right) {
ll res = -1;
while (left < right && left % B != 0) {
if (res == -1)
res = A.at(left);
else
res = __gcd(res, A.at(left));
left++;
}
while (left < right && right % B != 0) {
right--;
if (res == -1)
res = A.at(right);
else
res = __gcd(res, A.at(right));
}
for (int i = left; i < right; i += B) {
if (res == -1)
res = backet.at(i / B);
else
res = __gcd(res, backet.at(i / B));
}
return res;
};
ll ans = -1;
for (int i = 0; i < N; i++) {
ll res = -1;
if (i == 0)
res = func(1, N);
else if (i == N - 1)
res = func(0, N - 1);
else
res = __gcd(func(0, i), func(i + 1, N));
chmax(ans, res);
}
cout << ans << endl;
} | replace | 38 | 39 | 38 | 39 | 0 | |
p03061 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int N;
vector<int> A;
int gcd(int a, int b) {
if (b > a) {
swap(a, b);
}
while (b != 0) {
int na = b;
int nb = a % b;
a = na;
b = nb;
}
return a;
}
int l[100005];
int r[100005];
int main() {
cin >> N;
A.resize(N);
for (int i = 0; i < N; i++) {
cin >> A[i + 1];
}
if (N == 2) {
cout << max(A[1], A[2]) << endl;
return 0;
}
l[0] = 0;
r[N + 1] = 0;
for (int i = 1; i <= N; i++) {
l[i] = gcd(l[i - 1], A[i]);
r[N + 1 - i] = gcd(r[N + 2 - i], A[N + 1 - i]);
}
int ans = 0;
for (int i = 1; i <= N; i++) {
ans = max(ans, gcd(l[i - 1], r[i + 1]));
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int N;
vector<int> A;
int gcd(int a, int b) {
if (b > a) {
swap(a, b);
}
while (b != 0) {
int na = b;
int nb = a % b;
a = na;
b = nb;
}
return a;
}
int l[100005];
int r[100005];
int main() {
cin >> N;
A.resize(N + 1);
for (int i = 0; i < N; i++) {
cin >> A[i + 1];
}
if (N == 2) {
cout << max(A[1], A[2]) << endl;
return 0;
}
l[0] = 0;
r[N + 1] = 0;
for (int i = 1; i <= N; i++) {
l[i] = gcd(l[i - 1], A[i]);
r[N + 1 - i] = gcd(r[N + 2 - i], A[N + 1 - i]);
}
int ans = 0;
for (int i = 1; i <= N; i++) {
ans = max(ans, gcd(l[i - 1], r[i + 1]));
}
cout << ans << endl;
return 0;
} | replace | 32 | 33 | 32 | 33 | 0 | |
p03061 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7 + (1e+9);
const ll INF = 1e18 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, m, n) for (ll i = m; i < n; i++)
#define rep(i, n) repi(i, 0, n)
typedef pair<ll, ll> P;
#define fi first
#define se second
// Range Minimum(Maximum) Query (RMQ)
// Big Range Query
// セグメント木 P(x, y) = P(値, 要素番号)
// インデックス取得したい場合: seg.update(k, k)
class SegmentTree {
public:
ll n = 1;
vector<P> seg[1]; // 0:最大 1:最小
void init(ll N) { // N要素のセグメントツリー作成
while (n < N)
n *= 2;
rep(i, 1) seg[i].resize(2 * n);
fill(all(seg[0]), P(-1, -1));
}
ll gcd(ll a, ll b) {
if (a == -1)
return b;
if (b == -1)
return a;
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
P cmp_gcd(P x, P y) { // 比較関数
P zz;
zz.fi = gcd(x.fi, y.fi);
zz.se = x.se;
return zz;
}
void update(ll k, ll x, bool flag = false) { // kの値をxに変更
k += n - 1;
seg[0][k] = P(x, k - (n - 1));
if (flag) {
seg[0][k] = P(-1, -1);
}
while (k > 0) {
k = (k - 1) / 2;
seg[0][k] = cmp_gcd(seg[0][k * 2 + 1], seg[0][k * 2 + 2]);
}
}
P calc(ll a, ll b, ll k, ll l, ll r, ll f) {
if (b <= l || r <= a)
return P(-1, -1);
if (a <= l && r <= b)
return seg[f][k];
P vl = calc(a, b, k * 2 + 1, l, (l + r) / 2, f);
P vr = calc(a, b, k * 2 + 2, (l + r) / 2, r, f);
return cmp_gcd(vl, vr);
}
void erase(ll k) { update(k, -1, true); }
ll get_gcd(ll a, ll b) { return calc(a, b, 0, 0, n, 0).fi; }
};
int main() {
SegmentTree st;
ll nn;
cin >> nn;
ll ans = 0;
vector<ll> v(nn, 0);
for (ll i = 0; i < nn; i++) {
cin >> v[i];
}
st.init(nn);
for (ll i = 0; i < nn; i++) {
st.update(i, v[i]);
}
for (ll i = 0; i < nn; i++) {
SegmentTree seg = st;
seg.update(i, -1);
// ans=max(ans,seg.get_gcd(0,nn));
ans = max(ans, seg.seg[0][0].fi);
}
cout << ans << endl;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7 + (1e+9);
const ll INF = 1e18 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, m, n) for (ll i = m; i < n; i++)
#define rep(i, n) repi(i, 0, n)
typedef pair<ll, ll> P;
#define fi first
#define se second
// Range Minimum(Maximum) Query (RMQ)
// Big Range Query
// セグメント木 P(x, y) = P(値, 要素番号)
// インデックス取得したい場合: seg.update(k, k)
class SegmentTree {
public:
ll n = 1;
vector<P> seg[1]; // 0:最大 1:最小
void init(ll N) { // N要素のセグメントツリー作成
while (n < N)
n *= 2;
rep(i, 1) seg[i].resize(2 * n);
fill(all(seg[0]), P(-1, -1));
}
ll gcd(ll a, ll b) {
if (a == -1)
return b;
if (b == -1)
return a;
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
P cmp_gcd(P x, P y) { // 比較関数
P zz;
zz.fi = gcd(x.fi, y.fi);
zz.se = x.se;
return zz;
}
void update(ll k, ll x, bool flag = false) { // kの値をxに変更
k += n - 1;
seg[0][k] = P(x, k - (n - 1));
if (flag) {
seg[0][k] = P(-1, -1);
}
while (k > 0) {
k = (k - 1) / 2;
seg[0][k] = cmp_gcd(seg[0][k * 2 + 1], seg[0][k * 2 + 2]);
}
}
P calc(ll a, ll b, ll k, ll l, ll r, ll f) {
if (b <= l || r <= a)
return P(-1, -1);
if (a <= l && r <= b)
return seg[f][k];
P vl = calc(a, b, k * 2 + 1, l, (l + r) / 2, f);
P vr = calc(a, b, k * 2 + 2, (l + r) / 2, r, f);
return cmp_gcd(vl, vr);
}
void erase(ll k) { update(k, -1, true); }
ll get_gcd(ll a, ll b) { return calc(a, b, 0, 0, n, 0).fi; }
};
int main() {
SegmentTree st;
ll nn;
cin >> nn;
ll ans = 0;
vector<ll> v(nn, 0);
for (ll i = 0; i < nn; i++) {
cin >> v[i];
}
st.init(nn);
for (ll i = 0; i < nn; i++) {
st.update(i, v[i]);
}
for (ll i = 0; i < nn; i++) {
st.update(i, -1);
ans = max(ans, st.seg[0][0].fi);
st.update(i, v[i]);
}
cout << ans << endl;
}
| replace | 94 | 98 | 94 | 97 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.