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
p02257
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; bool is_prime(int num) { for (int i = 2; i < num; i++) { if (num % i == 0) { return false; } } return true; } int main(void) { int n; cin >> n; int num; int prime_count = 0; for (int i = 0; i < n; i++) { cin >> num; if (is_prime(num) == true) { prime_count++; } } cout << prime_count << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; bool is_prime(int num) { int a = sqrt(num); for (int i = 2; i <= a; i++) { if (num % i == 0) { return false; } } return true; } int main(void) { int n; cin >> n; int num; int prime_count = 0; for (int i = 0; i < n; i++) { cin >> num; if (is_prime(num) == true) { prime_count++; } } cout << prime_count << endl; return 0; }
replace
8
9
8
11
TLE
p02257
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; bool isprime(int x); int main() { int i, j; int a, n; int ans = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a; if (isprime(a) == true) ans++; } cout << ans << "\n"; return (0); } bool isprime(int x) { int i = 3; if (x == 2) return (true); if (x < 2 || x % 2 == 0) return (false); while (x >= i * i) { if (x % i == 0) return (false); } return (true); }
#include <bits/stdc++.h> using namespace std; bool isprime(int x); int main() { int i, j; int a, n; int ans = 0; cin >> n; for (i = 0; i < n; i++) { cin >> a; if (isprime(a) == true) ans++; } cout << ans << "\n"; return (0); } bool isprime(int x) { int i = 3; if (x == 2) return (true); if (x < 2 || x % 2 == 0) return (false); while (x >= i * i) { if (x % i == 0) return (false); i += 2; } return (true); }
insert
35
35
35
36
TLE
p02257
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <math.h> #include <sstream> #include <stdio.h> #include <string> using namespace std; int GCD(int x, int y) { if (y == 0) { return x; } return GCD(y, x % y); } bool isPrime(int N) { for (int i = 2; i < N; i++) { if (GCD(N, i) != 1) return false; } return true; } int main() { int n; cin >> n; int primeNumberCount = 0; for (int i = 0; i < n; i++) { int num; cin >> num; if (isPrime(num) == true) primeNumberCount++; } cout << primeNumberCount << endl; return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <sstream> #include <stdio.h> #include <string> using namespace std; int GCD(int x, int y) { if (y == 0) { return x; } return GCD(y, x % y); } bool isPrime(int N) { if (N == 2) true; if (N % 2 == 0) false; for (int i = 2; i * i <= N; i++) { if (GCD(N, i) != 1) return false; } return true; } int main() { int n; cin >> n; int primeNumberCount = 0; for (int i = 0; i < n; i++) { int num; cin >> num; if (isPrime(num) == true) primeNumberCount++; } cout << primeNumberCount << endl; return 0; }
replace
17
18
17
22
TLE
p02257
C++
Time Limit Exceeded
#include <iostream> #include <math.h> #include <string> using namespace std; bool prime(int); int main() { int n, k, c = 0; cin >> n; while (n--) { cin >> k; if (prime(k)) c++; } cout << c << endl; return 0; } bool prime(int a) { for (int i = 2; i < a; i++) { if (a % i == 0) return false; } return true; }
#include <iostream> #include <math.h> #include <string> using namespace std; bool prime(int); int main() { int n, k, c = 0; cin >> n; while (n--) { cin >> k; if (prime(k)) c++; } cout << c << endl; return 0; } bool prime(int a) { for (int i = 2; i < (int)(sqrt((double)a)) + 1; i++) { if (a % i == 0) return false; } return true; }
replace
20
21
20
21
TLE
p02257
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int N, a, ans = 0; cin >> N; for (int i = 0; i < N; i++) { cin >> a; bool flag = true; if (a != 2 && a % 2 == 0 || a == 1) { flag = false; } else if (a != 2) { for (int j = 3; j < a; j += 2) { if (a % j == 0) { flag = false; break; } } } if (flag) { ans += 1; } } cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main() { int N, a, ans = 0; cin >> N; for (int i = 0; i < N; i++) { cin >> a; bool flag = true; if (a != 2 && a % 2 == 0 || a == 1) { flag = false; } else if (a > 2) { for (int j = 3; j * j <= a; j += 2) { if (a % j == 0) { flag = false; break; } } } if (flag) { ans += 1; } } cout << ans << endl; return 0; }
replace
11
13
11
13
TLE
p02257
C++
Time Limit Exceeded
#include <algorithm> #include <cstdlib> #include <iomanip> #include <iostream> #include <list> #include <map> #include <string> #include <typeinfo> #include <vector> #define _USE_MATH_DEFINES #include <cmath> using namespace std; // prime=>true, not prime=>false // bool isPrime(int i){ // for(int j=2; j<=i/2; j++){ // if(i%j==0){ // return false; // } // } // return true; // } bool isPrime(int n) { if (n < 2) { return false; } else if (n == 2) { return true; } if (n % 2 == 0) { return false; } for (int i = 3; i <= n / 2; i += 2) { if (n % i == 0) { return false; } } return true; } int main() { int n; cin >> n; vector<long> n_nums(n); for (int i = 0; i < n; i++) { cin >> n_nums[i]; } int prime_count = 0; for (int i = 0; i < n; i++) { if (isPrime(n_nums[i])) { prime_count += 1; } } cout << prime_count << endl; return 0; }
#include <algorithm> #include <cstdlib> #include <iomanip> #include <iostream> #include <list> #include <map> #include <string> #include <typeinfo> #include <vector> #define _USE_MATH_DEFINES #include <cmath> using namespace std; // prime=>true, not prime=>false // bool isPrime(int i){ // for(int j=2; j<=i/2; j++){ // if(i%j==0){ // return false; // } // } // return true; // } bool isPrime(int n) { if (n < 2) { return false; } else if (n == 2) { return true; } if (n % 2 == 0) { return false; } for (int i = 3; i <= n / i; i += 2) { if (n % i == 0) { return false; } } return true; } int main() { int n; cin >> n; vector<long> n_nums(n); for (int i = 0; i < n; i++) { cin >> n_nums[i]; } int prime_count = 0; for (int i = 0; i < n; i++) { if (isPrime(n_nums[i])) { prime_count += 1; } } cout << prime_count << endl; return 0; }
replace
33
34
33
34
TLE
p02257
C++
Time Limit Exceeded
#include <iostream> #include <math.h> #include <string> using namespace std; int main() { int n, m; ; cin >> m; int count = m; for (int s = 0; s < m; s++) { cin >> n; if (n == 2) continue; else if (n % 2 == 0) count--; else { for (int i = 3; i < n; i += 2) { if (n % i == 0) { count--; break; } } } } cout << count << endl; return 0; }
#include <iostream> #include <math.h> #include <string> using namespace std; int main() { int n, m; ; cin >> m; int count = m; for (int s = 0; s < m; s++) { cin >> n; if (n == 2) continue; else if (n % 2 == 0) count--; else { for (int i = 3; i <= sqrt(n); i += 2) { if (n % i == 0) { count--; break; } } } } cout << count << endl; return 0; }
replace
17
18
17
18
TLE
p02257
C++
Time Limit Exceeded
#include <iostream> using namespace std; bool heheda(int a); bool heheda(int a) { for (int i = 2; i * 2 <= a; i++) if (!(a % i)) return false; return true; } int main() { int n; cin >> n; int tmp2 = 0; int c; for (int i = 0; i < n; i++) { cin >> c; if (heheda(c)) tmp2 += 1; } cout << tmp2 << endl; return 0; }
#include <iostream> using namespace std; bool heheda(int a); bool heheda(int a) { for (int i = 2; i * i <= a; i++) if (!(a % i)) return false; return true; } int main() { int n; cin >> n; int tmp2 = 0; int c; for (int i = 0; i < n; i++) { cin >> c; if (heheda(c)) tmp2 += 1; } cout << tmp2 << endl; return 0; }
replace
5
6
5
6
TLE
p02257
C++
Time Limit Exceeded
#include <iostream> #include <math.h> using namespace std; int main() { int n, i, x, j, flag = 0, cut = 0, a; cin >> n; for (i = 0; i < n; i++) { cin >> x; a = sqrt(x); flag = 0; for (j = x - 1; j > 1; j--) { if (x % j == 0) { flag = 1; break; } } if (flag == 0) cut++; } cout << cut << endl; return 0; }
#include <iostream> #include <math.h> using namespace std; int main() { int n, i, x, j, flag = 0, cut = 0, a; cin >> n; for (i = 0; i < n; i++) { cin >> x; a = sqrt(x); flag = 0; for (j = a; j > 1; j--) { if (x % j == 0) { flag = 1; break; } } if (flag == 0) cut++; } cout << cut << endl; return 0; }
replace
10
11
10
11
TLE
p02257
C++
Time Limit Exceeded
#include <algorithm> #include <array> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <sstream> #include <string> #include <vector> using namespace std; int main(void) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int cnt = 0; for (int i = 0; i < n; i++) { // cout << a[i] << " : "; int numOfDivisor = 0; if (a[i] == 1 || (a[i] != 2 && a[i] % 2 == 0)) { // 1????????????2??\????????¶??°????????? // cout << "even\n"; continue; } for (int j = 3; j < a[i] / 2; j += 2) { if (a[i] % j == 0) { numOfDivisor++; // cout << j << " "; } } if (numOfDivisor == 0) { cnt++; // cout << "***"; } // cout << endl; } cout << cnt << endl; return 0; }
#include <algorithm> #include <array> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <sstream> #include <string> #include <vector> using namespace std; int main(void) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int cnt = 0; for (int i = 0; i < n; i++) { // cout << a[i] << " : "; int numOfDivisor = 0; if (a[i] == 1 || (a[i] != 2 && a[i] % 2 == 0)) { // 1????????????2??\????????¶??°????????? // cout << "even\n"; continue; } for (int j = 3; j <= sqrt(a[i]); j += 2) { if (a[i] % j == 0) { numOfDivisor++; // cout << j << " "; } } if (numOfDivisor == 0) { cnt++; // cout << "***"; } // cout << endl; } cout << cnt << endl; return 0; }
replace
35
36
35
36
TLE
p02257
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; bool isPrime(int a) { for (int i = 2; i < a; i++) { if (a % i == 0) { return false; } } return true; } int main() { int n; cin >> n; int sum = 0; int x; for (int i = 0; i < n; i++) { cin >> x; if (isPrime(x)) sum += 1; } cout << sum << endl; return 0; }
#include <cmath> #include <iostream> using namespace std; bool isPrime(int a) { for (int i = 2; i <= sqrt(a); i++) { if (a % i == 0) { return false; } } return true; } int main() { int n; cin >> n; int sum = 0; int x; for (int i = 0; i < n; i++) { cin >> x; if (isPrime(x)) sum += 1; } cout << sum << endl; return 0; }
replace
5
6
5
6
TLE
p02257
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main(void) { bool flag; int n, k = 0, a; cin >> n; for (int i = 0; i < n; i++) { cin >> a; flag = false; for (int j = a - 1; 1 < j; j--) { if (a % j == 0) { flag = true; break; } } if (flag == false) k += 1; } cout << k << endl; return 0; }
#include <iostream> using namespace std; int main(void) { bool flag; int n, k = 0, a; cin >> n; for (int i = 0; i < n; i++) { cin >> a; flag = false; for (int j = 2; j * j <= a; j++) { if (a % j == 0) { flag = true; break; } } if (flag == false) k += 1; } cout << k << endl; return 0; }
replace
9
10
9
10
TLE
p02257
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <map> #include <numeric> #include <set> #include <sstream> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; typedef long long ll; int const SIZ = 100000001; bitset<SIZ> chk; void sieve() { chk.set(); chk.set(0, 0); chk.set(1, 0); for (int i = 4; i < SIZ; i += 2) { chk.set(i, 0); } for (int i = 3; i < SIZ; i += 2) { if (!chk[i]) continue; for (int j = 2; i * j < SIZ; ++j) { chk.set(i * j, 0); } } } int main() { ios::sync_with_stdio(false); sieve(); int n; cin >> n; int m, ans = 0; for (int i = 0; i < n; ++i) { cin >> m; if (chk[m]) { ++ans; chk[m] = 0; } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <map> #include <numeric> #include <set> #include <sstream> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; typedef long long ll; int const SIZ = 100000001; bitset<SIZ> chk; void sieve() { chk.set(); chk.set(0, 0); chk.set(1, 0); for (int i = 4; i < SIZ; i += 2) { chk.set(i, 0); } for (int i = 3; i * i < SIZ; i += 2) { if (!chk[i]) continue; for (int j = 2; i * j < SIZ; ++j) { chk.set(i * j, 0); } } } int main() { ios::sync_with_stdio(false); sieve(); int n; cin >> n; int m, ans = 0; for (int i = 0; i < n; ++i) { cin >> m; if (chk[m]) { ++ans; chk[m] = 0; } } cout << ans << endl; return 0; }
replace
28
29
28
29
TLE
p02257
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> #define rep(n) for (int i = 0; i < (n); i++) #define pb(n) push_back((n)) // typedef long long ll; using namespace std; // vector<bool> p(100000100,true); // void makep(){ // for(int i=0; i<100000100; i++){ // if(i<2)p[i]=false; // for(int j=2; j<=sqrt(i); j++){ // if(i%j==0){ // p[i]=false; // break; // } // } // } // } bool is_p(int n) { if (n < 2) return false; for (int i = 0; i <= sqrt(n); i++) { if (n % i == 0) return false; } return true; } int main() { int n, cnt = 0, a; cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (is_p(a)) cnt++; } cout << cnt << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> #define rep(n) for (int i = 0; i < (n); i++) #define pb(n) push_back((n)) // typedef long long ll; using namespace std; // vector<bool> p(100000100,true); // void makep(){ // for(int i=0; i<100000100; i++){ // if(i<2)p[i]=false; // for(int j=2; j<=sqrt(i); j++){ // if(i%j==0){ // p[i]=false; // break; // } // } // } // } bool is_p(int n) { if (n < 2) return false; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return true; } int main() { int n, cnt = 0, a; cin >> n; for (int i = 0; i < n; i++) { cin >> a; if (is_p(a)) cnt++; } cout << cnt << endl; }
replace
36
37
36
37
-8
p02257
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int a, d = 0; cin >> a; for (int i = 0; i < a; i++) { int b; cin >> b; d++; for (int j = 2; j < b / 2 + 1; j++) { if (b % j == 0) { d--; break; } } } cout << d << endl; }
#include <iostream> using namespace std; int main() { int a, d = 0; cin >> a; for (int i = 0; i < a; i++) { int b; cin >> b; d++; for (int j = 2; j * j <= b; j++) { if (b % j == 0) { d--; break; } } } cout << d << endl; }
replace
11
12
11
12
TLE
p02257
C++
Time Limit Exceeded
#include <iostream> using namespace std; int n; int a; int p = 0; void is_prime() { for (int i = 2; i <= a / 2; i++) { if (a % i == 0) { return; } } p++; } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a; is_prime(); } cout << p << endl; return 0; }
#include <iostream> using namespace std; int n; int a; int p = 0; void is_prime() { for (int i = 2; i * i <= a; i++) { if (a % i == 0) { return; } } p++; } int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a; is_prime(); } cout << p << endl; return 0; }
replace
7
8
7
8
TLE
p02257
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; bool IsPrime(int a) { if (a == 2) return true; if (a % 2 == 0) { return false; } for (int i = 3; i < a; i += 2) { if (a % i == 0) { return false; } } return true; } int main() { int n; cin >> n; int a = 0; int cnt = 0; for (int i = 0; i < n; i++) { cin >> a; if (IsPrime(a)) cnt++; } cout << cnt << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; bool IsPrime(int a) { if (a == 2) return true; if (a % 2 == 0) { return false; } for (int i = 3; i <= sqrt(a); i += 2) { if (a % i == 0) { return false; } } return true; } int main() { int n; cin >> n; int a = 0; int cnt = 0; for (int i = 0; i < n; i++) { cin >> a; if (IsPrime(a)) cnt++; } cout << cnt << endl; return 0; }
replace
13
14
13
14
TLE
p02257
C++
Time Limit Exceeded
#include <cmath> #include <cstdio> #include <iostream> using namespace std; bool isPrime(int x) { if (x == 2) return true; if (x % 2 == 0) return false; int i = 3; while (i <= sqrt(x)) { if (x % i == 0) return false; } return true; } int main() { int n; scanf("%d", &n); int x[n]; for (int i = 0; i < n; ++i) { scanf("%d", &x[i]); } int cnt = 0; for (int i = 0; i < n; ++i) { if (isPrime(x[i])) { ++cnt; } } cout << cnt << endl; return 0; }
#include <cmath> #include <cstdio> #include <iostream> using namespace std; bool isPrime(int x) { if (x == 2) return true; if (x % 2 == 0) return false; int i = 3; while (i <= sqrt(x)) { if (x % i == 0) return false; ++i; } return true; } int main() { int n; scanf("%d", &n); int x[n]; for (int i = 0; i < n; ++i) { scanf("%d", &x[i]); } int cnt = 0; for (int i = 0; i < n; ++i) { if (isPrime(x[i])) { ++cnt; } } cout << cnt << endl; return 0; }
insert
15
15
15
16
TLE
p02257
C++
Time Limit Exceeded
#include <iostream> #include <math.h> using namespace std; int gcd(int a1, int b1) { if (a1 == 0 || b1 == 0) { return 0; } if (a1 >= b1) { if (a1 % b1 == 0) { return b1; } else { return gcd(b1, a1 % b1); } } else { if (b1 % a1 == 0) { return a1; } else { return gcd(a1, b1 % a1); } } } int main(void) { // Here your code ! int n, k, p = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { k = 0; cin >> a[i]; if (a[i] == 2) { p++; continue; } else if (a[i] % 2 == 0) { continue; } for (int j = 0; j < floor(sqrt(a[i])); j++) { if (gcd(a[i], j + 1) == j + 1) { k++; } } if (k == 1) { p++; } } cout << p << endl; }
#include <iostream> #include <math.h> using namespace std; int gcd(int a1, int b1) { if (a1 == 0 || b1 == 0) { return 0; } if (a1 >= b1) { if (a1 % b1 == 0) { return b1; } else { return gcd(b1, a1 % b1); } } else { if (b1 % a1 == 0) { return a1; } else { return gcd(a1, b1 % a1); } } } int main(void) { // Here your code ! int n, k, p = 0; cin >> n; int a[n]; for (int i = 0; i < n; i++) { k = 0; cin >> a[i]; if (a[i] == 2) { p++; continue; } else if (a[i] % 2 == 0) { continue; } for (int j = 0; j < floor(sqrt(a[i])); j++) { if (a[i] % (j + 1) == 0) { k++; } } if (k == 1) { p++; } } cout << p << endl; }
replace
37
38
37
38
TLE
p02257
C++
Time Limit Exceeded
#include <cmath> #include <iostream> #include <vector> using namespace std; bool Sieve(int x) { for (int i = 2; i <= sqrt(x); i++) if (x % i == 0) return false; return true; } int main() { int n; vector<int> items; // input cin >> n; items.resize(n); for (int i = 0; i < n; i++) cin >> items[i]; // process int count = 0; for (int y : items) if (Sieve(y)) count++; cout << count << endl; return 0; }
#include <cmath> #include <iostream> #include <vector> using namespace std; bool Sieve(int x) { for (int i = 2; i <= sqrt(x); i++) if (x % i == 0) return false; return true; } int main() { int n; vector<int> items; // input cin >> n; items.resize(n); for (int i = 0; i < n; i++) cin >> items[i]; // process int count = 0; for (int i = 0; i < n; i++) if (Sieve(items[i])) count++; cout << count << endl; return 0; }
replace
23
25
23
25
TLE
p02257
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdint> #include <iomanip> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; bool isPrime(int x) { for (int i = 2; i < x; ++i) { if (x % i == 0) { return false; } } return true; } int main() { int n, x, c = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> x; if (isPrime(x)) { ++c; } } cout << c << endl; }
#include <algorithm> #include <cmath> #include <cstdint> #include <iomanip> #include <iostream> #include <numeric> #include <string> #include <vector> using namespace std; bool isPrime(int x) { int max = sqrt(x); for (int i = 2; i <= max; ++i) { if (x % i == 0) { return false; } } return true; } int main() { int n, x, c = 0; cin >> n; for (int i = 0; i < n; ++i) { cin >> x; if (isPrime(x)) { ++c; } } cout << c << endl; }
replace
12
13
12
14
TLE
p02257
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> bool isPrime(std::size_t a) { if (a == 2) { return true; } else if (a % 2 == 0) { return false; } for (std::size_t i = 3; i < a / 2; i = i + 2) { if (a % i == 0) { return false; } } return true; } int main() { std::size_t n; std::cin >> n; std::size_t count = 0; for (std::size_t i = 0; i < n; ++i) { std::size_t a; std::cin >> a; if (isPrime(a)) { count++; } } std::cout << count << std::endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> bool isPrime(std::size_t a) { if (a == 2) { return true; } else if (a % 2 == 0) { return false; } for (std::size_t i = 3; i <= (std::size_t)(sqrt(a)); i = i + 2) { if (a % i == 0) { return false; } } return true; } int main() { std::size_t n; std::cin >> n; std::size_t count = 0; for (std::size_t i = 0; i < n; ++i) { std::size_t a; std::cin >> a; if (isPrime(a)) { count++; } } std::cout << count << std::endl; return 0; }
replace
13
14
13
14
TLE
p02257
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int main() { int N; cin >> N; int cnt = 0; int num = 0; for (int i = 0; i < N; i++) { cin >> num; for (int j = 1; j < num; j++) { if (j == 1) { continue; } if (num % j == 0) { num = 0; break; } } if (num != 0) { cnt += 1; } } cout << cnt << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int N; cin >> N; int cnt = 0; int num = 0; for (int i = 0; i < N; i++) { cin >> num; if (num == 2) { cnt += 1; continue; } if (num % 2 == 0) { continue; } double sqrtnum = sqrt(num); for (int j = 3; j <= sqrtnum; j += 2) { if (num % j == 0) { num = 0; break; } } if (num != 0) { cnt += 1; } } cout << cnt << endl; return 0; }
replace
12
16
12
22
TLE
p02257
C++
Time Limit Exceeded
#include <cassert> #include <iostream> #include <math.h> using namespace std; bool isPrime(int x) { if (x < 2) return false; else if (x == 2) return true; if (x % 2 == 0) return false; int limit = (int)sqrt((double)x) + 1; for (int i = 3; i < x / 2; i += 2) { if (x % i == 0) return false; } return true; } int main() { int n, x; int cnt = 0; cin >> n; assert(1 <= n && n <= 10000); for (int i = 0; i < n; i++) { cin >> x; assert(2 <= x && x <= 1000000000); if (isPrime(x)) cnt++; } cout << cnt << endl; }
#include <cassert> #include <iostream> #include <math.h> using namespace std; bool isPrime(int x) { if (x < 2) return false; else if (x == 2) return true; if (x % 2 == 0) return false; int limit = (int)sqrt((double)x) + 1; for (int i = 3; i <= limit; i += 2) { if (x % i == 0) return false; } return true; } int main() { int n, x; int cnt = 0; cin >> n; assert(1 <= n && n <= 10000); for (int i = 0; i < n; i++) { cin >> x; assert(2 <= x && x <= 1000000000); if (isPrime(x)) cnt++; } cout << cnt << endl; }
replace
13
14
13
14
TLE
p02258
C++
Time Limit Exceeded
#include <iostream> #define INT_MIN -2000000000 #define MAX_R 200001 using namespace std; int main() { int n, k; while (cin >> n) { int max = INT_MIN; int r[MAX_R]; k = n; while (k--) { cin >> r[k]; } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (r[i] - r[j] > max) max = r[i] - r[j]; } } cout << max << endl; } return 0; }
#include <iostream> #define INT_MIN -2000000000 #define MAX_R 200001 using namespace std; int main() { int n, k; while (cin >> n) { int max = INT_MIN; int r[MAX_R]; k = n; while (k--) { cin >> r[k]; } for (int i = 0; i < n; i++) { if (r[i] < max) continue; for (int j = i + 1; j < n; j++) { if (r[i] - r[j] > max) max = r[i] - r[j]; } } cout << max << endl; } return 0; }
insert
15
15
15
17
TLE
p02258
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 1e9; int main() { int n = 0; fscanf(stdin, "%d", &n); vector<ll> v(n); for (int i = 0; i < n; ++i) { fscanf(stdin, "%lld", &v[i]); } ll ans = -INF; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { ans = max(ans, v[j] - v[i]); } } fprintf(stdout, "%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 1e9; int main() { int n = 0; fscanf(stdin, "%d", &n); vector<ll> v(n); for (int i = 0; i < n; ++i) { fscanf(stdin, "%lld", &v[i]); } ll ans = -INF; ll mn = v[0]; for (int i = 1; i < n; ++i) { ans = max(ans, v[i] - mn); mn = min(mn, v[i]); } fprintf(stdout, "%lld\n", ans); return 0; }
replace
16
20
16
20
TLE
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 200000; int main() { int num = 0, maxProfit = -1000000000; int value[MAX] = {0}; cin >> num; for (int i = 0; i < num; i++) { cin >> value[i]; } for (int i = 0; i < num; i++) { for (int j = i + 1; j < num; j++) { maxProfit = max(maxProfit, value[j] - value[i]); } } cout << maxProfit << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 200000; int main() { int num = 0, maxProfit = -1000000000; int value[MAX] = {0}; cin >> num; for (int i = 0; i < num; i++) { cin >> value[i]; } int minValue = value[0]; for (int i = 1; i < num; i++) { maxProfit = max(maxProfit, value[i] - minValue); minValue = min(minValue, value[i]); } cout << maxProfit << endl; return 0; }
replace
16
20
16
21
TLE
p02258
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; typedef vector<ll> Vector; typedef vector<vector<ll>> DVector; #define fi first #define se second #define pb push_back #define INF INT_MAX #define bcnt __builtin_popcount #define all(x) (x).begin(), (x).end() #define dbg(x) cout << #x "=" << x << endl #define ub(x, y) upper_bound(all(x), y) - x.begin() #define lb(x, y) lower_bound(all(x), y) - x.begin() #define uni(x) x.erase(unique(all(x)), x.end()) #define rep(i, n) repl(i, 0, n - 1) #define repl(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++) #define mmax(x, y) (x > y ? x : y) #define mmin(x, y) (x < y ? x : y) #define maxch(x, y) x = mmax(x, y) #define minch(x, y) x = mmin(x, y) #define exist(x, y) (find(all(x), y) != x.end()) #define each(itr, v) for (auto itr : v) #define usort(x) sort(all(x)) #define dsort(x) sort(all(x), greater<int>()) #define mkp(x, y) make_pair(x, y) int main() { cin.sync_with_stdio(false); int n; cin >> n; Vector a(n); int mx = -INF; rep(i, n) cin >> a[i]; rep(i, n) rep(j, i) maxch(mx, a[i] - a[j]); cout << mx << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; typedef vector<ll> Vector; typedef vector<vector<ll>> DVector; #define fi first #define se second #define pb push_back #define INF INT_MAX #define bcnt __builtin_popcount #define all(x) (x).begin(), (x).end() #define dbg(x) cout << #x "=" << x << endl #define ub(x, y) upper_bound(all(x), y) - x.begin() #define lb(x, y) lower_bound(all(x), y) - x.begin() #define uni(x) x.erase(unique(all(x)), x.end()) #define rep(i, n) repl(i, 0, n - 1) #define repl(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++) #define mmax(x, y) (x > y ? x : y) #define mmin(x, y) (x < y ? x : y) #define maxch(x, y) x = mmax(x, y) #define minch(x, y) x = mmin(x, y) #define exist(x, y) (find(all(x), y) != x.end()) #define each(itr, v) for (auto itr : v) #define usort(x) sort(all(x)) #define dsort(x) sort(all(x), greater<int>()) #define mkp(x, y) make_pair(x, y) int main() { cin.sync_with_stdio(false); int n; cin >> n; Vector a(n); int mx = -INF; rep(i, n) cin >> a[i]; Vector table(n); table[0] = a[0]; repl(i, 1, n - 1) table[i] = mmin(table[i - 1], a[i]); repl(i, 1, n - 1) maxch(mx, a[i] - table[i - 1]); cout << mx << endl; }
replace
38
39
38
42
TLE
p02258
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; int main() { int n; cin >> n; vector<int> R(n); for (int i = 0; i < n; ++i) cin >> R[i]; auto itr_min = min_element(R.begin(), R.end()); auto itr_max = max_element(itr_min, R.end()); cout << ((*itr_max - *itr_min) <= 0 ? -1 : (*itr_max - *itr_min)) << endl; system("pause"); }
#include "bits/stdc++.h" using namespace std; int main() { int n; cin >> n; int ans = -999999999, minv; cin >> minv; for (int i = 1; i < n; ++i) { int a; cin >> a; ans = max(ans, a - minv); minv = min(minv, a); } cout << ans << endl; // system("pause"); }
replace
7
14
7
17
0
sh: 1: pause: not found
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int main() { int n; cin >> n; int r[n]; for (int i = 0; i < n; ++i) { cin >> r[i]; } int M = r[1] - r[0]; for (int i = 0; i < n - 1; ++i) { for (int j = i + 1; j < n; ++j) { M = max(M, r[j] - r[i]); } } cout << M << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int n; cin >> n; int M = -1000000000; int m; cin >> m; for (int i = 1; i < n; ++i) { int r; cin >> r; M = max(M, r - m); m = min(m, r); } cout << M << endl; return 0; }
replace
7
16
7
15
TLE
p02258
C++
Time Limit Exceeded
#include <cstdio> int d[200000 + 2]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &d[i]); int maxv = -1000000001; //(n>=2)?d[1]-d[0]:-1; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (maxv < d[j] - d[i]) maxv = d[j] - d[i]; } } printf("%d\n", maxv); return 0; }
#include <cstdio> int d[200000 + 2]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &d[i]); int maxv = d[1] - d[0]; // 2 <= n < 200000 int minv = d[0]; // Store a mininum value and get diff value with next value // after next mininum for (int i = 1; i < n; i++) { maxv = (d[i] - minv > maxv) ? (d[i] - minv) : maxv; minv = (minv > d[i]) ? d[i] : minv; } // local save history value printf("%d\n", maxv); return 0; }
replace
8
15
8
15
TLE
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <cmath> #include <iostream> #include <vector> typedef int TInt; typedef std::vector<TInt> TList; TList Input() { int Count; std::cin >> Count; TList List(Count); for (int i = 0; i < Count; ++i) { std::cin >> List[i]; } return List; } int main() { TList A = Input(); assert(A.size() >= 2); int Profit = A[1] - A[0]; int i = 0; while (i < A.size()) { int j = i + 1; for (int j = i + 1; j < A.size(); ++j) { int Diff = A[j] - A[i]; if (Diff < 0) { i = j; break; } if (Diff > Profit) Profit = Diff; } if (j == A.size()) break; } std::cout << Profit << std::endl; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <iostream> #include <vector> typedef int TInt; typedef std::vector<TInt> TList; TList Input() { int Count; std::cin >> Count; TList List(Count); for (int i = 0; i < Count; ++i) { std::cin >> List[i]; } return List; } int main() { TList A = Input(); assert(A.size() >= 2); int Profit = A[1] - A[0]; int i = 0; while (i < A.size()) { int j; for (j = i + 1; j < A.size(); ++j) { int Diff = A[j] - A[i]; if (Diff < 0) { i = j; break; } if (Diff > Profit) Profit = Diff; } if (j == A.size()) break; } std::cout << Profit << std::endl; return 0; }
replace
22
24
22
24
TLE
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int N, A[200000]; int solve(void) { int maxp = 1 - 1000000000; for (int i = 0; i < N - 1; i++) { for (int j = i + 1; j < N; j++) { maxp = max(maxp, A[j] - A[i]); } } return maxp; } int main(void) { cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } cout << solve() << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int N, A[200000]; int solve(void) { auto maxp = A[1] - A[0]; auto minr = min(A[0], A[1]); for (auto i = 2; i < N; i++) { maxp = max(maxp, A[i] - minr); minr = min(minr, A[i]); } return maxp; } int main(void) { cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } cout << solve() << endl; return 0; }
replace
7
12
7
12
TLE
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 200000; int main() { int R[MAX], n; cin >> n; for (int i = 0; i = n; i++) cin >> R[i]; int maxv = -2000000000; int minv = R[0]; for (int i = 1; i < n; i++) { maxv = max(maxv, R[i] - minv); minv = min(minv, R[i]); } cout << maxv << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 200000; int main() { int R[MAX], n; cin >> n; for (int i = 0; i < n; i++) cin >> R[i]; int maxv = -2000000000; int minv = R[0]; for (int i = 1; i < n; i++) { maxv = max(maxv, R[i] - minv); minv = min(minv, R[i]); } cout << maxv << endl; return 0; }
replace
9
10
9
10
TLE
p02258
C++
Time Limit Exceeded
#include <iostream> #include <vector> int main() { std::vector<long> Dat = {}; int t = 0; std::cin >> t; for (int i = 0; i < t; i++) { int tmp = 0; std::cin >> tmp; Dat.push_back(tmp); } long max = *(Dat.begin() + 1) - *Dat.begin(); for (auto cur = Dat.begin(); cur != Dat.end() - 1; cur++) // may bug { long start = *cur; long tmp = *(cur + 1); for (auto curr = cur + 2; curr != Dat.end(); curr++) { if (*curr > tmp) tmp = *curr; } if (tmp - *cur > max) max = tmp - *cur; } std::cout << max << std::endl; return 0; }
#include <iostream> #include <vector> int main() { std::vector<long> Dat = {}; int t = 0; std::cin >> t; for (int i = 0; i < t; i++) { int tmp = 0; std::cin >> tmp; Dat.push_back(tmp); } long min = *Dat.begin(), max = -2E9; for (auto cur = Dat.begin() + 1; cur != Dat.end(); cur++) { if (*(cur - 1) < min) min = *(cur - 1); if (*cur - min > max) max = *cur - min; } std::cout << max << std::endl; return 0; }
replace
12
23
12
18
TLE
p02258
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long n, a[1000000], x, y, mi, an; int main() { cin >> n; for (x = 0; x < n; x++) { cin >> a[x]; for (y = x - 1; y >= 0; y--) { if (x == 1) { mi = a[x]; } if (a[x] < mi) { mi = a[x]; } if (x == 1 && y == 0) { an = a[x] - a[y]; } if (an < a[x] - a[y]) { an = a[x] - a[y]; } } } cout << an << endl; }
#include <bits/stdc++.h> using namespace std; long long n, a[1000000], x, y, mi, an; int main() { cin >> n; for (x = 0; x < n; x++) { cin >> a[x]; if (x == 1) { an = a[x] - a[x - 1]; } if (x == 0) { mi = a[x]; } if (an < a[x] - mi) { an = a[x] - mi; } if (mi > a[x]) { mi = a[x]; } } cout << an << endl; }
replace
7
20
7
18
TLE
p02258
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int n; cin >> n; int *r; r = new int[n]; if (r == NULL) { cout << "Error!" << endl; return -1; } int i, j; for (i = 0; i < n; i++) { cin >> r[i]; } int max = r[1] - r[0]; for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if (r[j] - r[i] > max) max = r[j] - r[i]; } } cout << max << endl; return 0; }
#include <iostream> using namespace std; int main() { int n; cin >> n; int *r; r = new int[n]; if (r == NULL) { cout << "Error!" << endl; return -1; } int i, j; for (i = 0; i < n; i++) { cin >> r[i]; } int max = r[1] - r[0]; for (j = n - 1; j >= 0; j--) { if (r[j] <= max) continue; for (i = j - 1; i >= 0; i--) { if (r[j] - r[i] > max) max = r[j] - r[i]; } } cout << max << endl; return 0; }
replace
18
20
18
22
TLE
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<double> r(n); for (int i = 0; i < n; i++) { cin >> r[i]; } double max_profit = -1000000000; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { max_profit = max(max_profit, r[j] - r[i]); } } cout << setprecision(10) << max_profit << endl; }
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<double> r(n); for (int i = 0; i < n; i++) { cin >> r[i]; } double max_profit = -1000000000; double min_r = r[0]; for (int i = 1; i < n; i++) { min_r = min(min_r, r[i - 1]); max_profit = max(max_profit, r[i] - min_r); } cout << setprecision(10) << max_profit << endl; }
replace
15
19
15
19
TLE
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> rs(n); for (auto &r : rs) { cin >> r; } int ans = INT_MIN; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { ans = max(ans, rs[j] - rs[i]); } } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> rs(n); for (auto &r : rs) { cin >> r; } int ans = INT_MIN; int min_r = rs[0]; for (int i = 1; i < n; i++) { ans = max(ans, rs[i] - min_r); min_r = min(min_r, rs[i]); } cout << ans << endl; }
replace
34
38
34
38
TLE
p02258
C++
Time Limit Exceeded
#include <iostream> using namespace std; class MaximumProfit { public: int solve(int n, int *r); }; int MaximumProfit::solve(int n, int *r) { int maxp = -2000000000; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) { if ((r[j] - r[i]) > maxp) maxp = r[j] - r[i]; } return maxp; } int main(void) { MaximumProfit *mp = new MaximumProfit(); int n; cin >> n; int *r = new int[n]; for (int i = 0; i < n; i++) cin >> r[i]; cout << mp->solve(n, r) << endl; delete mp; delete[] r; return 0; }
#include <iostream> using namespace std; class MaximumProfit { public: int solve(int n, int *r); }; int MaximumProfit::solve(int n, int *r) { int maxp = -2000000000; int minr = r[0]; for (int i = 1; i < n; i++) { if ((r[i] - minr) > maxp) maxp = r[i] - minr; if (r[i] < minr) minr = r[i]; } return maxp; } int main(void) { MaximumProfit *mp = new MaximumProfit(); int n; cin >> n; int *r = new int[n]; for (int i = 0; i < n; i++) cin >> r[i]; cout << mp->solve(n, r) << endl; delete mp; delete[] r; return 0; }
replace
11
16
11
18
TLE
p02258
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int n; cin >> n; int m[200000]; for (int i = 0; i < n; i++) { cin >> m[i]; } int max = m[1] - m[0]; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (max < m[j] - m[i]) max = m[j] - m[i]; } } cout << max << endl; return 0; }
#include <iostream> using namespace std; int main() { int n; cin >> n; int m[200000]; for (int i = 0; i < n; i++) { cin >> m[i]; } int max = -1000000000, min = m[0]; for (int i = 1; i < n; i++) { if (max < m[i] - min) max = m[i] - min; if (m[i] < min) min = m[i]; } cout << max << endl; return 0; }
replace
11
17
11
17
TLE
p02258
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n, a[200001] = {}; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int max = a[1] - a[0]; for (int i = 1; i < n; i++) for (int j = 0; j < i; j++) if (a[i] - a[j] > max) max = a[i] - a[j]; cout << max << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a[200001] = {}; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; int max = a[1] - a[0]; int min = a[0]; for (int i = 1; i < n; i++) { if (a[i] - min > max) max = a[i] - min; if (min > a[i]) min = a[i]; } cout << max << endl; return 0; }
replace
8
12
8
15
TLE
p02258
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n, tmp; cin >> n; vector<int> rt(n); for (int i = 0; i < n; i++) { cin >> rt[i]; } int ans = INT_MIN; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i < j) { tmp = rt[j] - rt[i]; if (ans < tmp) ans = tmp; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, tmp; cin >> n; vector<int> rt(n); for (int i = 0; i < n; i++) { cin >> rt[i]; } int ans = INT_MIN; int minv = rt[0]; for (int j = 1; j < n; j++) { ans = (ans >= rt[j] - minv) ? ans : rt[j] - minv; minv = (minv <= rt[j]) ? minv : rt[j]; } cout << ans << endl; return 0; }
replace
11
19
11
15
TLE
p02258
Python
Runtime Error
import sys values = [int(input()) for i in range(int(input()))] maxv = -sys.maxsize - 1 minv = values[0] for val in enumerate(values): if maxv < (val - minv): maxv = val - minv if minv > val: minv = val print(maxv)
n = int(input()) R = [int(input()) for _ in range(n)] minv, maxv = R[0], R[1] - R[0] for j in range(1, n): maxv = max(maxv, R[j] - minv) minv = min(minv, R[j]) print(maxv)
replace
0
11
0
6
TypeError: unsupported operand type(s) for -: 'tuple' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02258/Python/s112466969.py", line 8, in <module> if maxv < (val - minv): TypeError: unsupported operand type(s) for -: 'tuple' and 'int'
p02258
C++
Runtime Error
#include <stdio.h> int main(void) { int i = 0; int n = 0; int min; int now; int max_margin = -2147483648; int margin; scanf("%d", &n); scanf("%d", &min); for (i = 1; i < n; i++) { scanf("%d", now); margin = now - min; if (margin > max_margin) { max_margin = margin; } if (now < min) { min = now; } } printf("%d\n", max_margin); return 0; }
#include <stdio.h> int main(void) { int i = 0; int n = 0; int min; int now; int max_margin = -2147483648; int margin; scanf("%d", &n); scanf("%d", &min); for (i = 1; i < n; i++) { scanf("%d", &now); margin = now - min; if (margin > max_margin) { max_margin = margin; } if (now < min) { min = now; } } printf("%d\n", max_margin); return 0; }
replace
13
14
13
14
-11
p02258
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; int timeSerialDiff(vector<int> &v) { int size = v.size(), i, j, max, cnt = 0; for (i = 0; i < size; i++) { int start = v[i]; for (j = i + 1; j < size; j++) { int diff = v[j] - v[i]; max = (cnt == 0 || max < diff) ? diff : max; cnt++; } } return max; } int main() { int n, i, x, min, max; vector<int> v; cin >> n; for (i = 0; i < n; i++) { cin >> x; v.push_back(x); } cout << timeSerialDiff(v) << endl; return 0; }
#include <iostream> #include <vector> using namespace std; int timeSerialDiff(vector<int> &v) { int size = v.size(); if (size < 2) { return 0; } int i, max, min, cnt = 0; min = v[0]; max = v[1] - v[0]; for (i = 1; i < size; i++) { int diff = v[i] - min; max = max < diff ? diff : max; min = min > v[i] ? v[i] : min; } return max; } int main() { int n, i, x, min, max; vector<int> v; cin >> n; for (i = 0; i < n; i++) { cin >> x; v.push_back(x); } cout << timeSerialDiff(v) << endl; return 0; }
replace
5
13
5
16
TLE
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> r; for (int i = 0; i < n; i++) { int ri; cin >> ri; r.push_back(ri); } int diffmax = r[1] - r[0]; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { diffmax = max(diffmax, r[j] - r[i]); } } cout << diffmax << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> r; for (int i = 0; i < n; i++) { int ri; cin >> ri; r.push_back(ri); } int diffmax = r[1] - r[0]; int rmin = r[0]; for (int i = 1; i < n; i++) { diffmax = max(diffmax, r[i] - rmin); rmin = min(rmin, r[i]); } cout << diffmax << endl; return 0; }
replace
23
27
23
27
TLE
p02258
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define pout(n) printf("%d\n", n) #define rep(i, a, n) for (int i = a; i < n; i++) #define per(i, n, a) for (int i = n - 1; i >= a; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); const int d4x[4] = {1, 0, -1, 0}; const int d4y[4] = {0, 1, 0, -1}; const int d8x[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1}; #define MAX_N (int)2e5 + 20 #define INF 1e12 + 20 typedef long long ll; using namespace std; int n; int main() { cin >> n; int r[n]; rep(i, 0, n) { cin >> r[i]; } int ans = INT_MIN; rep(i, 0, n - 1) { rep(j, i + 1, n) { ans = max(r[j] - r[i], ans); } } pout(ans); return 0; }
#include <bits/stdc++.h> #define pout(n) printf("%d\n", n) #define rep(i, a, n) for (int i = a; i < n; i++) #define per(i, n, a) for (int i = n - 1; i >= a; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); const int d4x[4] = {1, 0, -1, 0}; const int d4y[4] = {0, 1, 0, -1}; const int d8x[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1}; #define MAX_N (int)2e5 + 20 #define INF 1e12 + 20 typedef long long ll; using namespace std; int n; int main() { cin >> n; int r[n]; rep(i, 0, n) { cin >> r[i]; } int ans = INT_MIN; int mi = r[0]; rep(i, 1, n) { ans = max(ans, r[i] - mi); mi = min(mi, r[i]); } pout(ans); return 0; }
replace
26
28
26
30
TLE
p02258
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; const int NMAX = 20000; int maximum_profit(int *r, int n) { int mini = r[0]; int maxi = r[1] - r[0]; for (int i = 1; i < n; i++) { maxi = max(maxi, r[i] - mini); mini = min(mini, r[i]); } return maxi; } int main(void) { int *r; r = new int[NMAX]; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> r[i]; // cout << r[i] << endl; } int max = maximum_profit(r, n); cout << max << endl; delete r; return 0; }
#include <algorithm> #include <iostream> using namespace std; const int NMAX = 2000000; int maximum_profit(int *r, int n) { int mini = r[0]; int maxi = r[1] - r[0]; for (int i = 1; i < n; i++) { maxi = max(maxi, r[i] - mini); mini = min(mini, r[i]); } return maxi; } int main(void) { int *r; r = new int[NMAX]; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> r[i]; // cout << r[i] << endl; } int max = maximum_profit(r, n); cout << max << endl; delete r; return 0; }
replace
3
4
3
4
0
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int main() { int n; cin >> n; int *a = new int[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int m = (1 << 31); for (int i = 0; i < n; i++) { for (int j = i - 1; j >= 0; j--) { m = max(a[i] - a[j], m); } } cout << m << endl; delete[] a; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int n; cin >> n; int *a = new int[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int m = (1 << 31); int minx = a[0]; for (int i = 1; i < n; i++) { m = max(m, a[i] - minx); minx = min(minx, a[i]); } cout << m << endl; delete[] a; return 0; }
replace
12
16
12
16
TLE
p02258
C++
Time Limit Exceeded
#include <iostream> using namespace std; int functione(int num[], int N); int main() { int n; cin >> n; int *num = new int[n]; for (int i = 0; i < n; i++) cin >> num[i]; cout << functione(num, n) << endl; return 0; } int functione(int num[], int N) { int profit = -2000000000; for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) { if (profit < num[j] - num[i]) profit = num[j] - num[i]; } return profit; }
#include <iostream> using namespace std; int functione(int num[], int N); int main() { int n; cin >> n; int *num = new int[n]; for (int i = 0; i < n; i++) cin >> num[i]; cout << functione(num, n) << endl; return 0; } int functione(int num[], int N) { int max = -2000000000; int min = num[0]; for (int i = 1; i < N; i++) { if (max < num[i] - min) max = num[i] - min; if (min > num[i]) min = num[i]; } return max; }
replace
18
25
18
27
TLE
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main(void) { int n; cin >> n; vector<int> prices(n); for (int i = 0; i < n; i++) { cin >> prices[i]; } int mprofit = -1000000000; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { mprofit = max(mprofit, prices[j] - prices[i]); } } cout << mprofit << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main(void) { int n; cin >> n; vector<int> prices(n); for (int i = 0; i < n; i++) { cin >> prices[i]; } int mprofit = -1111111111; int minv = prices[0]; for (int i = 1; i < n; i++) { mprofit = max(mprofit, prices[i] - minv); minv = min(minv, prices[i]); } cout << mprofit << endl; return 0; }
replace
14
19
14
19
TLE
p02258
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; vector<int> r(n); for (int i = 0; i < n; ++i) { cin >> r[i]; } int ans = -1000000007; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { ans = max(ans, r[j] - r[i]); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; vector<int> r(n); for (int i = 0; i < n; ++i) { cin >> r[i]; } int ans = -1000000007; int minv = r[0]; for (int i = 1; i < n; ++i) { ans = max(ans, r[i] - minv); minv = min(minv, r[i]); } cout << ans << endl; return 0; }
replace
11
15
11
15
TLE
p02258
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 20000; int main() { int n; int minv; int maxv = -2000000000; int R[MAX]; cin >> n; for (int i = 0; i < n; i++) { cin >> R[i]; } minv = R[0]; for (int j = 1; j < n; j++) { maxv = max(maxv, R[j] - minv); minv = min(minv, R[j]); } cout << maxv << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 200000; int main() { int n; int minv; int maxv = -2000000000; int R[MAX]; cin >> n; for (int i = 0; i < n; i++) { cin >> R[i]; } minv = R[0]; for (int j = 1; j < n; j++) { maxv = max(maxv, R[j] - minv); minv = min(minv, R[j]); } cout << maxv << endl; return 0; }
replace
3
4
3
4
0
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> using namespace std; const int MAX_VALUE = 200000; int R[MAX_VALUE]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &R[i]); int max_income = -1000000001; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) max_income = max(max_income, R[j] - R[i]); printf("%d\n", max_income); }
#include <algorithm> #include <cstdio> using namespace std; const int MAX_VALUE = 200000; int R[MAX_VALUE]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &R[i]); int min_val = R[0]; int max_val = -1000000001; for (int j = 1; j < n; j++) { max_val = max(max_val, R[j] - min_val); min_val = min(min_val, R[j]); } printf("%d\n", max_val); }
replace
14
20
14
21
TLE
p02258
C++
Runtime Error
#include <limits.h> #include <stdio.h> int main(void) { int n, i, tmp, tmp2; int profit = INT_MIN; int min = INT_MAX; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &tmp); tmp2 = tmp - min; if (tmp2 > profit) { profit = tmp2; } if (tmp < min) min = tmp; } return profit; }
#include <limits.h> #include <stdio.h> int main(void) { int n, i, tmp, tmp2; int profit = INT_MIN; int min = INT_MAX; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &tmp); tmp2 = tmp - min; if (tmp2 > profit) { profit = tmp2; } if (tmp < min) min = tmp; } printf("%d\n", profit); return 0; }
replace
17
18
17
19
3
p02258
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define SORT(c) sort((c).begin(), (c).end()) const double EPS = 1e-10; // sample:if((double)>=(double)+EPS) #define CLR(a) memset((&a), 0, sizeof(a)) // clear memory #define dump(x) cerr << #x << " = " << (x) << endl; // debug #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // cin,cout release // std::cin.tie(0); // ios::sync_with_stdio(false); int main(void) { int n; cin >> n; // vector<int> r; int r[200000]; for (int i = 0; i < n; i++) { cin >> r[i]; } int maxv = INT_MIN; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { maxv = max(maxv, r[j] - r[i]); } } cout << maxv << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define SORT(c) sort((c).begin(), (c).end()) const double EPS = 1e-10; // sample:if((double)>=(double)+EPS) #define CLR(a) memset((&a), 0, sizeof(a)) // clear memory #define dump(x) cerr << #x << " = " << (x) << endl; // debug #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; // cin,cout release // std::cin.tie(0); // ios::sync_with_stdio(false); int main(void) { int n; cin >> n; // vector<int> r; int r[200000]; for (int i = 0; i < n; i++) { cin >> r[i]; } int maxv = INT_MIN, minv = r[0]; for (int i = 1; i < n; i++) { maxv = max(maxv, r[i] - minv); minv = min(minv, r[i]); } cout << maxv << endl; return 0; }
replace
23
28
23
27
TLE
p02258
C++
Runtime Error
// // Created by sanyinchen on 17/4/17. // #include <cstdio> #include <iostream> #include <limits> #include <string.h> #include <vector> using namespace std; vector<int> findMaxWithMidPoint(int *array, int low, int high) { int mid = (low + high) / 2; int leftSum = 0, leftLow = mid; int rightSum = 0, rightHigh = mid + 1; int maxLeft = array[leftLow], maxRight = array[rightHigh]; vector<int> res; for (int i = mid; i >= low; i--) { leftSum += array[i]; if (leftSum > maxLeft) { maxLeft = leftSum; leftLow = i; } } res.push_back(leftLow); for (int i = mid + 1; i <= high; i++) { rightSum += array[i]; if (rightSum > maxRight) { maxRight = rightSum; rightHigh = i; } } res.push_back(rightHigh); // cout << low << " " << high << endl; // cout << "sum:" << maxLeft + maxRight << " left:" << leftLow << " " << // "high:" << rightHigh << endl; res.push_back(maxLeft + maxRight); return res; } vector<int> findMax(int *array, int low, int high) { if (low == high) { vector<int> res; res.push_back(low); res.push_back(high); res.push_back(array[low]); return res; } else { int mid = (low + high) / 2; vector<int> left = findMax(array, low, mid); vector<int> right = findMax(array, mid + 1, high); vector<int> midRes = findMaxWithMidPoint(array, low, high); // cout << "left:" << left[0] << " " << left[1] << " " << left[2] << // endl; cout << "right:" << right[0] << " " << right[1] << " " << // right[2] << endl; cout << "midRes:" << midRes[0] << " " << // midRes[1] << " " << midRes[2] << endl; if (left[2] >= right[2] && left[2] >= midRes[2]) { return left; } if (right[2] >= left[2] && right[2] >= midRes[2]) { return right; } return midRes; } } int main() { freopen("../files/in.txt", "r", stdin); int input[200001] = {0}; int data[200001] = {0}; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> input[i]; if (i == 0) { data[i] = 0 - input[i]; } else { data[i] = input[i] - input[i - 1]; } } // for (int i = 0; i < n; i++) { // cout << data[i] << " "; // } // cout << endl; vector<int> res = findMax(data, 0, n - 1); // cout << res[0] << " " << res[1] << " " << res[2] << endl; cout << res[2] << endl; return 0; }
// // Created by sanyinchen on 17/4/17. // #include <cstdio> #include <iostream> #include <limits> #include <string.h> #include <vector> using namespace std; vector<int> findMaxWithMidPoint(int *array, int low, int high) { int mid = (low + high) / 2; int leftSum = 0, leftLow = mid; int rightSum = 0, rightHigh = mid + 1; int maxLeft = array[leftLow], maxRight = array[rightHigh]; vector<int> res; for (int i = mid; i >= low; i--) { leftSum += array[i]; if (leftSum > maxLeft) { maxLeft = leftSum; leftLow = i; } } res.push_back(leftLow); for (int i = mid + 1; i <= high; i++) { rightSum += array[i]; if (rightSum > maxRight) { maxRight = rightSum; rightHigh = i; } } res.push_back(rightHigh); // cout << low << " " << high << endl; // cout << "sum:" << maxLeft + maxRight << " left:" << leftLow << " " << // "high:" << rightHigh << endl; res.push_back(maxLeft + maxRight); return res; } vector<int> findMax(int *array, int low, int high) { if (low == high) { vector<int> res; res.push_back(low); res.push_back(high); res.push_back(array[low]); return res; } else { int mid = (low + high) / 2; vector<int> left = findMax(array, low, mid); vector<int> right = findMax(array, mid + 1, high); vector<int> midRes = findMaxWithMidPoint(array, low, high); // cout << "left:" << left[0] << " " << left[1] << " " << left[2] << // endl; cout << "right:" << right[0] << " " << right[1] << " " << // right[2] << endl; cout << "midRes:" << midRes[0] << " " << // midRes[1] << " " << midRes[2] << endl; if (left[2] >= right[2] && left[2] >= midRes[2]) { return left; } if (right[2] >= left[2] && right[2] >= midRes[2]) { return right; } return midRes; } } int main() { // freopen("../files/in.txt", "r", stdin); int input[200001] = {0}; int data[200001] = {0}; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> input[i]; if (i == 0) { data[i] = 0 - input[i]; } else { data[i] = input[i] - input[i - 1]; } } // for (int i = 0; i < n; i++) { // cout << data[i] << " "; // } // cout << endl; vector<int> res = findMax(data, 0, n - 1); // cout << res[0] << " " << res[1] << " " << res[2] << endl; cout << res[2] << endl; return 0; }
replace
78
79
78
79
-11
p02258
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int maxval = -1000000000; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { maxval = max(maxval, a[j] - a[i]); } } cout << maxval << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; int maxval = -1000000000; int minval = a[0]; for (int i = 1; i < n; i++) { maxval = max(maxval, a[i] - minval); minval = min(minval, a[i]); } cout << maxval << endl; return 0; }
replace
11
15
11
15
TLE
p02258
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int n, x[1000000]; cin >> n; for (int i = 0; i < n; i++) { cin >> x[i]; } int max = x[1] - x[0]; for (int k = 0; k < n; k++) { for (int m = k + 1; m < n; m++) { if (max < (x[m] - x[k])) max = x[m] - x[k]; } } cout << max << endl; }
#include <iostream> using namespace std; int main() { int n, x[1000000]; cin >> n; for (int i = 0; i < n; i++) { cin >> x[i]; } int max = x[1] - x[0]; int min = x[0]; for (int k = 1; k < n; k++) { if (max < (x[k] - min)) max = (x[k] - min); if (min > x[k]) min = x[k]; } cout << max << endl; }
replace
10
15
10
16
TLE
p02258
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long MaxProfit(int n, long long *Rt) { long long max = LLONG_MIN; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { long long tmp = Rt[j] - Rt[i]; if (max < tmp) max = tmp; } } return max; } int main() { int n; cin >> n; long long Rt[n]; long long max; for (int i = 0; i < n; i++) cin >> Rt[i]; max = MaxProfit(n, Rt); cout << max << endl; return 0; };
#include <bits/stdc++.h> using namespace std; long long MaxProfit(int n, long long *Rt) { long long max = LLONG_MIN; long long MinRt = Rt[0]; for (int j = 1; j < n; j++) { long long tmp = Rt[j] - MinRt; if (max < tmp) max = tmp; if (MinRt > Rt[j]) MinRt = Rt[j]; } return max; } int main() { int n; cin >> n; long long Rt[n]; long long max; for (int i = 0; i < n; i++) cin >> Rt[i]; max = MaxProfit(n, Rt); cout << max << endl; return 0; };
replace
5
11
5
12
TLE
p02258
C++
Runtime Error
#include <iostream> using namespace std; static const int MAX = 20000; int main() { int R[MAX], n; cin >> n; for (int i = 0; i < n; i++) { cin >> R[i]; } int maxv = -2000000000; int minv = R[0]; for (int j = 1; j < n; j++) { maxv = max(maxv, R[j] - minv); minv = min(minv, R[j]); } cout << maxv << endl; return 0; }
#include <iostream> using namespace std; static const int MAX = 200000; int main() { int R[MAX], n; cin >> n; for (int i = 0; i < n; i++) { cin >> R[i]; } int maxv = -2000000000; int minv = R[0]; for (int j = 1; j < n; j++) { maxv = max(maxv, R[j] - minv); minv = min(minv, R[j]); } cout << maxv << endl; return 0; }
replace
2
3
2
3
0
p02258
C++
Runtime Error
#include <iostream> using namespace std; int R[2000]; int num; int main() { // cout << "????????\???????????¶??´??????" << endl; cin >> num; for (int i = 0; i < num; i++) { cin >> R[i]; } int maxv = -2000000000; int minv = R[0]; for (int j = 1; j < num; j++) { if (maxv < R[j] - minv) { maxv = R[j] - minv; } if (minv > R[j]) { minv = R[j]; } /* for (int i = 0; i < j; i++) { if (maxv < R[j] - R[i]) { maxv = R[j] - R[i]; } }*/ } cout << maxv << endl; return 0; }
#include <iostream> using namespace std; int R[200000]; int num; int main() { // cout << "????????\???????????¶??´??????" << endl; cin >> num; for (int i = 0; i < num; i++) { cin >> R[i]; } int maxv = -2000000000; int minv = R[0]; for (int j = 1; j < num; j++) { if (maxv < R[j] - minv) { maxv = R[j] - minv; } if (minv > R[j]) { minv = R[j]; } /* for (int i = 0; i < j; i++) { if (maxv < R[j] - R[i]) { maxv = R[j] - R[i]; } }*/ } cout << maxv << endl; return 0; }
replace
2
3
2
3
0
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int n; const int MAX_N = 200000; int R[MAX_N]; int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> R[i]; } int maxv = -2000000000; for (int j = 1; j <= n - 1; j++) { for (int i = 0; i <= j - 1; i++) { maxv = max(maxv, R[j] - R[i]); } } cout << maxv << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int n; const int MAX_N = 200000; int R[MAX_N]; int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> R[i]; } int maxv = -2000000000; int minv = R[0]; for (int j = 1; j < n; j++) { maxv = max(maxv, R[j] - minv); minv = min(minv, R[j]); } cout << maxv << endl; return 0; }
replace
16
20
16
21
TLE
p02258
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 20000; int main() { int R[MAX], n; cin >> n; for (int i = 0; i < n; i++) cin >> R[i]; int maxv = -2000000000; int minv = R[0]; for (int i = 1; i < n; i++) { maxv = max(maxv, R[i] - minv); minv = min(minv, R[i]); } cout << maxv << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 200000; int main() { int R[MAX], n; cin >> n; for (int i = 0; i < n; i++) cin >> R[i]; int maxv = -2000000000; int minv = R[0]; for (int i = 1; i < n; i++) { maxv = max(maxv, R[i] - minv); minv = min(minv, R[i]); } cout << maxv << endl; return 0; }
replace
3
4
3
4
0
p02258
C++
Time Limit Exceeded
#include <iostream> int main() { int n; int r[200000]; std::cin >> n; for (int i = 0; i < n; i++) { std::cin >> r[i]; } int s = r[1] - r[0]; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { int ss = r[j] - r[i]; if (ss > s) { s = ss; } } } std::cout << s << std::endl; return 0; }
#include <iostream> int main() { int n; int r[200000]; std::cin >> n; for (int i = 0; i < n; i++) { std::cin >> r[i]; } int s = r[1] - r[0]; int rr = r[0]; for (int i = 1; i < n; i++) { if (r[i] - rr > s) { s = r[i] - rr; } if (r[i] < rr) { rr = r[i]; } } std::cout << s << std::endl; return 0; }
replace
10
16
10
17
TLE
p02258
C++
Time Limit Exceeded
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { long long n, MAX = -1000000000; cin >> n; vector<int> R(n); /* 株価の値を入力 */ for (int i = 0; i < n; i++) { cin >> R[i]; } /* 株価の最大値を探す */ for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (MAX < R[j] - R[i]) MAX = R[j] - R[i]; } } cout << MAX << endl; return 0; }
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { long long n, MAX = -1000000000; cin >> n; vector<int> R(n); /* 株価の値を入力 */ for (int i = 0; i < n; i++) { cin >> R[i]; } /* 株価の最大値を探す */ for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (MAX < R[j] - R[i]) MAX = R[j] - R[i]; if (R[i] >= R[j]) break; } } cout << MAX << endl; return 0; }
insert
21
21
21
23
TLE
p02258
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 20000; int main() { int R[MAX], N; cin >> N; for (int i = 0; i < N; i++) cin >> R[i]; int maxv = R[1] - R[0]; int minv = R[0]; for (int i = 1; i < N; i++) { maxv = max(maxv, R[i] - minv); minv = min(minv, R[i]); } cout << maxv << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 200000; int main() { int R[MAX], N; cin >> N; for (int i = 0; i < N; i++) cin >> R[i]; int maxv = R[1] - R[0]; int minv = R[0]; for (int i = 1; i < N; i++) { maxv = max(maxv, R[i] - minv); minv = min(minv, R[i]); } cout << maxv << endl; return 0; }
replace
3
4
3
4
0
p02258
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 20000; int main() { int R[MAX], n; cin >> n; for (int i = 0; i < n; i++) cin >> R[i]; int maxv = -2000000000; int minv = R[0]; for (int i = 1; i < n; i++) { maxv = max(maxv, R[i] - minv); minv = min(minv, R[i]); } cout << maxv << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; static const int MAX = 200000; int main() { int R[MAX], n; cin >> n; for (int i = 0; i < n; i++) cin >> R[i]; int maxv = -2000000000; int minv = R[0]; for (int i = 1; i < n; i++) { maxv = max(maxv, R[i] - minv); minv = min(minv, R[i]); } cout << maxv << endl; return 0; }
replace
3
4
3
4
0
p02258
Python
Time Limit Exceeded
N = int(input()) R = [int(input()) for i in range(N)] sa = R[N - 1] - R[N - 2] for i in reversed(range(N)): for j in reversed(range(i)): tmp = R[i] - R[j] if tmp > sa: sa = tmp print(sa)
N = int(input()) R = [int(input()) for i in range(N)] min_v = R[0] max_v = R[1] - R[0] for i in range(1, len(R)): if min_v > R[i - 1]: min_v = R[i - 1] if max_v < R[i] - min_v: max_v = R[i] - min_v print(max_v)
replace
3
10
3
11
TLE
p02258
C++
Time Limit Exceeded
#include <algorithm> #include <assert.h> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <utility> #include <vector> using namespace std; typedef long long ll; #define loop(i, a, b) for (ll i = a; i < b; i++) #define rloop(i, a, b) for (int i = a; i >= b; i--) const int inf = 1e8; const ll INF = 1e16; #define MOD 1000000007 #define mod 1000000009 int main() { int n; cin >> n; vector<ll> r(n); loop(i, 0, n) { cin >> r[i]; } ll M = -1 * INF; ll m = r[0]; loop(i, 0, n - 1) { if (r[i] == m) { vector<ll> r2(n); r2 = r; sort(r2.begin() + i + 1, r2.end()); m = r2.back(); } M = max(M, m - r[i]); } cout << M << "\n"; }
#include <algorithm> #include <assert.h> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <utility> #include <vector> using namespace std; typedef long long ll; #define loop(i, a, b) for (ll i = a; i < b; i++) #define rloop(i, a, b) for (int i = a; i >= b; i--) const int inf = 1e8; const ll INF = 1e16; #define MOD 1000000007 #define mod 1000000009 int main() { int n; cin >> n; vector<ll> r(n); loop(i, 0, n) { cin >> r[i]; } ll M = -1 * INF; ll m = r[0]; loop(i, 1, n) { m = min(m, r[i - 1]); M = max(M, r[i] - m); } cout << M << "\n"; }
replace
35
43
35
38
TLE
p02259
C++
Runtime Error
#include <iostream> using namespace std; int bubbleSort(int A[], int N) { int sw = 0; bool flag = 1; for (int i = 0; flag; i++) { flag = 0; for (int j = N - 1; j >= i + 1; j++) { if (A[j] < A[j - 1]) { swap(A[j], A[j - 1]); flag = 1; sw++; } } } return sw; } int main(void) { int A[100], N, sw; cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; sw = bubbleSort(A, N); for (int i = 0; i < N; i++) { if (i) cout << " "; cout << A[i]; } cout << endl; cout << sw << endl; return 0; }
#include <iostream> using namespace std; int bubbleSort(int A[], int N) { int sw = 0; bool flag = 1; for (int i = 0; flag; i++) { flag = 0; for (int j = N - 1; j >= i + 1; j--) { if (A[j] < A[j - 1]) { swap(A[j], A[j - 1]); flag = 1; sw++; } } } return sw; } int main(void) { int A[100], N, sw; cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; sw = bubbleSort(A, N); for (int i = 0; i < N; i++) { if (i) cout << " "; cout << A[i]; } cout << endl; cout << sw << endl; return 0; }
replace
8
9
8
9
-11
p02259
C++
Time Limit Exceeded
// bubble sort #include <iostream> #include <math.h> using namespace std; int main() { int n, d, i1, i2, times; cin >> n; int a[n]; for (i1 = 0; i1 < n; i1++) { cin >> a[i1]; } times = 0; i2 = n; for (i2 = n; i2 > 0; i2--) { i1 = n; while (1) { i1--; if (a[i1] < a[i1 - 1]) { d = a[i1]; a[i1] = a[i1 - 1]; a[i1 - 1] = d; times++; } if (i1 <= n - i2) { break; } } } i1 = 0; // cout while (1) { if (i1 == 0) { cout << a[i1]; continue; } cout << " " << a[i1]; i1++; if (i1 == n) { break; } } cout << endl << times << endl; return 0; }
// bubble sort #include <iostream> #include <math.h> using namespace std; int main() { int n, d, i1, i2, times; cin >> n; int a[n]; for (i1 = 0; i1 < n; i1++) { cin >> a[i1]; } times = 0; i2 = n; for (i2 = n; i2 > 0; i2--) { i1 = n; while (1) { i1--; if (a[i1] < a[i1 - 1]) { d = a[i1]; a[i1] = a[i1 - 1]; a[i1 - 1] = d; times++; } if (i1 <= n - i2) { break; } } } i1 = 0; // cout while (1) { if (i1 == 0) { cout << a[i1]; if (n == 1) { break; } else { i1++; continue; } } cout << " " << a[i1]; i1++; if (i1 == n) { break; } } cout << endl << times << endl; return 0; }
replace
35
36
35
41
TLE
p02259
C++
Runtime Error
#include <iostream> using namespace std; int bubbleSort(int p[], int n) { int flag = 1; int count = 0; for (int i = 0; i < n - 1; i++) { if (!flag) break; flag = 0; for (int j = n - 1; j > i; j++) if (p[j] < p[j - 1]) { flag = 1; int t = p[j]; p[j] = p[j - 1]; p[j - 1] = t; count++; } } return count; } int main() { int n; cin >> n; int *p = new int[n]; for (int i = 0; i < n; i++) cin >> p[i]; int m = bubbleSort(p, n); for (int i = 0; i < n - 1; i++) cout << p[i] << ' '; cout << p[n - 1] << endl; cout << m << endl; }
#include <iostream> using namespace std; int bubbleSort(int p[], int n) { int flag = 1; int count = 0; for (int i = 0; i < n - 1; i++) { if (!flag) break; flag = 0; for (int j = n - 1; j > i; j--) if (p[j] < p[j - 1]) { flag = 1; int t = p[j]; p[j] = p[j - 1]; p[j - 1] = t; count++; } } return count; } int main() { int n; cin >> n; int *p = new int[n]; for (int i = 0; i < n; i++) cin >> p[i]; int m = bubbleSort(p, n); for (int i = 0; i < n - 1; i++) cout << p[i] << ' '; cout << p[n - 1] << endl; cout << m << endl; }
replace
9
10
9
10
-11
p02259
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int main() { int n; vector<int> List; int count = 0; cin >> n; for (int i = 0; i < n; i++) { int Value; cin >> Value; List.push_back(Value); } bool Flag = true; while (Flag) { Flag = false; for (int j = n - 1; j > 0; j++) { if (List[j] < List[j - 1]) { int Temp; Temp = List[j]; List[j] = List[j - 1]; List[j - 1] = Temp; Flag = true; count++; } } } for (int i = 0; i < n; i++) { if (i > 0) cout << " "; cout << List[i]; } cout << endl; cout << count << endl; }
#include <iostream> #include <vector> using namespace std; int main() { int n; vector<int> List; int count = 0; cin >> n; for (int i = 0; i < n; i++) { int Value; cin >> Value; List.push_back(Value); } bool Flag = true; while (Flag) { Flag = false; for (int j = n - 1; j > 0; j--) { if (List[j] < List[j - 1]) { int Temp; Temp = List[j]; List[j] = List[j - 1]; List[j - 1] = Temp; Flag = true; count++; } } } for (int i = 0; i < n; i++) { if (i > 0) cout << " "; cout << List[i]; } cout << endl; cout << count << endl; }
replace
21
22
21
22
-11
p02259
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" // #include "libs.h" #include <random> #include <unordered_map> #include <unordered_set> // #include <opencv2/core.hpp> // #include <opencv2/highgui.hpp> // #include <opencv2/imgproc.hpp> using namespace std; // 呪文 #define DUMPOUT cerr #define dump(...) \ DUMPOUT << " "; \ DUMPOUT << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" \ << endl; \ DUMPOUT << " "; \ dump_func(__VA_ARGS__) typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef pair<string, string> pss; template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const pair<_KTy, _Ty> &m) { o << "{" << m.first << ", " << m.second << "}"; return o; } template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const map<_KTy, _Ty> &m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const unordered_map<_KTy, _Ty> &m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const vector<_Ty> &v) { if (v.empty()) { o << "{ }"; return o; } o << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const set<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const unordered_set<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const stack<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } stack<_Ty> t(s); o << "{" << t.top(); t.pop(); while (!t.empty()) { o << ", " << t.top(); t.pop(); } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const list<_Ty> &l) { if (l.empty()) { o << "{ }"; return o; } o << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { o << ", " << *itr; } o << "}"; return o; } template <typename _KTy, typename _Ty> istream &operator>>(istream &is, pair<_KTy, _Ty> &m) { is >> m.first >> m.second; return is; } template <typename _Ty> istream &operator>>(istream &is, vector<_Ty> &v) { for (size_t i = 0; i < v.size(); i++) is >> v[i]; return is; } namespace aux { // print tuple template <typename Ty, unsigned N, unsigned L> struct tp { static void print(ostream &os, const Ty &v) { os << get<N>(v) << ", "; tp<Ty, N + 1, L>::print(os, v); } }; template <typename Ty, unsigned N> struct tp<Ty, N, N> { static void print(ostream &os, const Ty &v) { os << get<N>(v); } }; } // namespace aux template <typename... Tys> ostream &operator<<(ostream &os, const tuple<Tys...> &t) { os << "{"; aux::tp<tuple<Tys...>, 0, sizeof...(Tys) - 1>::print(os, t); os << "}"; return os; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #define PI 3.14159265358979323846 #define EPS 1e-10 #define FOR(is, a, n) for (int is = (a); is < (n); ++is) #define REP(is, n) FOR(is, 0, n) #define all(j) (j).begin(), (j).end() #define SZ(j) ((int)(j).size()) #define fake false template <typename T> void printVec(const vector<T> &v, char delim = ' ', ostream &os = cerr) { os << v[0]; for (int i = 1; i < v.size(); i++) os << delim << v[i]; os << endl; } // 戻り値 : 転倒数 template <typename T> size_t bubbleSort(vector<T> &A) { int N = (int)A.size(); size_t cnt = 0; for (int i = 0; i < N - 1; i++) { for (int j = N - 1; j > i; j--) { if (A[j - 1] > A[j]) { swap(A[j - 1], A[j]); cnt++; } } } return cnt; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); cin >> A; size_t numSwap = bubbleSort(A); printVec(A); cout << numSwap << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" // #include "libs.h" #include <random> #include <unordered_map> #include <unordered_set> // #include <opencv2/core.hpp> // #include <opencv2/highgui.hpp> // #include <opencv2/imgproc.hpp> using namespace std; // 呪文 #define DUMPOUT cerr #define dump(...) \ DUMPOUT << " "; \ DUMPOUT << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" \ << endl; \ DUMPOUT << " "; \ dump_func(__VA_ARGS__) typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef pair<string, string> pss; template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const pair<_KTy, _Ty> &m) { o << "{" << m.first << ", " << m.second << "}"; return o; } template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const map<_KTy, _Ty> &m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const unordered_map<_KTy, _Ty> &m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const vector<_Ty> &v) { if (v.empty()) { o << "{ }"; return o; } o << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const set<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const unordered_set<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const stack<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } stack<_Ty> t(s); o << "{" << t.top(); t.pop(); while (!t.empty()) { o << ", " << t.top(); t.pop(); } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const list<_Ty> &l) { if (l.empty()) { o << "{ }"; return o; } o << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { o << ", " << *itr; } o << "}"; return o; } template <typename _KTy, typename _Ty> istream &operator>>(istream &is, pair<_KTy, _Ty> &m) { is >> m.first >> m.second; return is; } template <typename _Ty> istream &operator>>(istream &is, vector<_Ty> &v) { for (size_t i = 0; i < v.size(); i++) is >> v[i]; return is; } namespace aux { // print tuple template <typename Ty, unsigned N, unsigned L> struct tp { static void print(ostream &os, const Ty &v) { os << get<N>(v) << ", "; tp<Ty, N + 1, L>::print(os, v); } }; template <typename Ty, unsigned N> struct tp<Ty, N, N> { static void print(ostream &os, const Ty &v) { os << get<N>(v); } }; } // namespace aux template <typename... Tys> ostream &operator<<(ostream &os, const tuple<Tys...> &t) { os << "{"; aux::tp<tuple<Tys...>, 0, sizeof...(Tys) - 1>::print(os, t); os << "}"; return os; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #define PI 3.14159265358979323846 #define EPS 1e-10 #define FOR(is, a, n) for (int is = (a); is < (n); ++is) #define REP(is, n) FOR(is, 0, n) #define all(j) (j).begin(), (j).end() #define SZ(j) ((int)(j).size()) #define fake false template <typename T> void printVec(const vector<T> &v, char delim = ' ', ostream &os = cout) { os << v[0]; for (int i = 1; i < v.size(); i++) os << delim << v[i]; os << endl; } // 戻り値 : 転倒数 template <typename T> size_t bubbleSort(vector<T> &A) { int N = (int)A.size(); size_t cnt = 0; for (int i = 0; i < N - 1; i++) { for (int j = N - 1; j > i; j--) { if (A[j - 1] > A[j]) { swap(A[j - 1], A[j]); cnt++; } } } return cnt; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); cin >> A; size_t numSwap = bubbleSort(A); printVec(A); cout << numSwap << endl; return 0; }
replace
178
179
178
179
0
1 2 3 4 5
p02259
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, a[100], ans = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { for (int j = n - 1; j >= i + 1; j++) { if (a[i] > a[j]) swap(a[i], a[j]); ans++; } } for (int i = 0; i < n; i++) { if (i == n - 1) cout << a[i] << "\n"; else cout << a[i] << " "; } cout << ans << "\n"; return 0; }
#include <iostream> using namespace std; int main() { int n, a[100], ans = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { for (int j = n - 1; j >= i + 1; j--) { if (a[j] < a[j - 1]) { swap(a[j], a[j - 1]); ans++; } } } for (int i = 0; i < n; i++) { if (i == n - 1) cout << a[i] << "\n"; else cout << a[i] << " "; } cout << ans << "\n"; return 0; }
replace
8
12
8
13
-11
p02259
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[100]; cin >> n; int k = 0, count = 0; for (int i = 0; i < n; i++) cin >> a[i]; while (1) { for (int i = n - 1; i > 0 + k; i--) { if (a[i - 1] > a[i]) { swap(a[i - 1], a[i]); count++; } } k++; if (k == n - 1) break; } for (int i = 0; i < n; i++) { if (i == 0) cout << a[i]; else cout << " " << a[i]; } cout << endl; cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[100]; cin >> n; int k = 0, count = 0; for (int i = 0; i < n; i++) cin >> a[i]; while (1) { for (int i = n - 1; i > 0 + k; i--) { if (a[i - 1] > a[i]) { swap(a[i - 1], a[i]); count++; } } k++; if (k == n) break; } for (int i = 0; i < n; i++) { if (i == 0) cout << a[i]; else cout << " " << a[i]; } cout << endl; cout << count << endl; return 0; }
replace
17
18
17
18
0
p02259
C++
Time Limit Exceeded
#include <fstream> #include <iostream> #include <vector> using namespace std; void print_vector(vector<int> &v) { for (int x : v) { std::cout << x << " "; } std::cout << endl; } int main() { #ifdef LOCAL // ??\??? cin ?????\????????? 'xxx.txt' ????????? std::ifstream in("alds1_2_a.txt"); std::cin.rdbuf(in.rdbuf()); #else #endif vector<int> vec; int n = 0; int change_num = 0; cin >> n; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; vec.push_back(tmp); } for (int i = 0; i < n; i++) { for (int j = n - 1; j > 0; j--) { if (vec[j - 1] > vec[j]) { int tmp = vec[j - 1]; vec[j - 1] = vec[j]; vec[j] = tmp; change_num++; } } } print_vector(vec); cout << change_num << endl; return 0; }
#include <fstream> #include <iostream> #include <vector> using namespace std; void print_vector(vector<int> &v) { for (vector<int>::iterator it = v.begin(); it != v.end(); it++) { std::cout << *it; if (it != v.end() - 1) { std::cout << " "; } } std::cout << endl; } int main() { #ifdef LOCAL // ??\??? cin ?????\????????? 'xxx.txt' ????????? std::ifstream in("alds1_2_a.txt"); std::cin.rdbuf(in.rdbuf()); #else #endif vector<int> vec; int n = 0; int change_num = 0; cin >> n; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; vec.push_back(tmp); } for (int i = 0; i < n; i++) { for (int j = n - 1; j > 0; j--) { if (vec[j - 1] > vec[j]) { int tmp = vec[j - 1]; vec[j - 1] = vec[j]; vec[j] = tmp; change_num++; } } } print_vector(vec); cout << change_num << endl; return 0; }
replace
6
8
6
11
TLE
p02259
C++
Runtime Error
#include <iostream> using namespace std; int bubbleSort(int A[], int N) { int sw = 0; bool flag = 1; for (int i = 0; flag; i++) { for (int j = N - 1; j >= i + 1; j--) { if (A[j] < A[j - 1]) { swap(A[j], A[j - 1]); flag = 1; sw++; } } } return sw; } int main() { int A[100], N, sw; cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; sw = bubbleSort(A, N); for (int i = 0; i < N; i++) { if (i) cout << " "; cout << A[i]; } cout << endl; cout << sw << endl; return 0; }
#include <iostream> using namespace std; int bubbleSort(int A[], int N) { int sw = 0; bool flag = 1; for (int i = 0; flag; i++) { flag = 0; for (int j = N - 1; j >= i + 1; j--) { if (A[j] < A[j - 1]) { swap(A[j], A[j - 1]); flag = 1; sw++; } } } return sw; } int main() { int A[100], N, sw; cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; sw = bubbleSort(A, N); for (int i = 0; i < N; i++) { if (i) cout << " "; cout << A[i]; } cout << endl; cout << sw << endl; return 0; }
insert
7
7
7
8
TLE
p02259
C++
Runtime Error
/*** * ?????????????????? * ???????????????????????£???????????£??\????´?????????????????????§????¬???????????????°????????? * ?????????????°?????????£??\??????????´?????????????????????????????????§?°???¢?????????????????°??????????????? ****/ #include <iostream> #include <vector> using namespace std; int main(void) //???????????¢??° { int n; cin >> n; vector<int> str; str.resize(n); for (int i = 0; i < n; i++) { //????????\??? cin >> str[i]; } // int k = n-1; int cnter = 0; for (int i = 0; i < n - 1; ++i) { for (int j = (n - 1); j <= (i + 1); j--) { // for(int j = 1 ; j< (n-i); j++){ if (str[j] < str[j - 1]) { //????????????????´???¨?????? int temp = str[j]; str[j] = str[j - 1]; str[j - 1] = temp; cnter++; } } } // k=j; //---------------------------------- ??????????????? for (int i = 0; i < n; i++) { cout << str[i]; if (i != (n - 1)) { cout << " "; } } cout << endl; cout << cnter << endl; //???????????°????????¢??°???????????¢?????°??¨?????°??????????????±?????????????????¨?????°??? return 0; }
/*** * ?????????????????? * ???????????????????????£???????????£??\????´?????????????????????§????¬???????????????°????????? * ?????????????°?????????£??\??????????´?????????????????????????????????§?°???¢?????????????????°??????????????? ****/ #include <iostream> #include <vector> using namespace std; int main(void) //???????????¢??° { int n; cin >> n; vector<int> str; str.resize(n); for (int i = 0; i < n; i++) { //????????\??? cin >> str[i]; } // int k = n-1; int cnter = 0; for (int i = 0; i < n - 1; ++i) { for (int j = 1; j < (n - i); j++) { if (str[j] < str[j - 1]) { //????????????????´???¨?????? int temp = str[j]; str[j] = str[j - 1]; str[j - 1] = temp; cnter++; } } } // k=j; //---------------------------------- ??????????????? for (int i = 0; i < n; i++) { cout << str[i]; if (i != (n - 1)) { cout << " "; } } cout << endl; cout << cnter << endl; //???????????°????????¢??°???????????¢?????°??¨?????°??????????????±?????????????????¨?????°??? return 0; }
replace
26
28
26
27
-11
p02259
C++
Time Limit Exceeded
#include <cstdio> using namespace std; void b_sort(int *a, int N); int main() { int a[100]; int N; scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d", &a[i]); } b_sort(a, N); } void b_sort(int *a, int N) { int j = N - 1; int t; int count = 0; while (1) { for (int i = 0; i < j; i++) { if (a[i] > a[i + 1]) { t = a[i]; a[i] = a[i + 1]; a[i + 1] = t; count++; } } j--; if (j == 0) { break; } } for (int i = 0; i < N; i++) { printf("%d", a[i]); if (i != N - 1) { printf(" "); } else { printf("\n"); } } printf("%d\n", count); }
#include <cstdio> using namespace std; void b_sort(int *a, int N); int main() { int a[100]; int N; scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d", &a[i]); } b_sort(a, N); } void b_sort(int *a, int N) { int j = N - 1; int t; int count = 0; while (1) { for (int i = 0; i < j; i++) { if (a[i] > a[i + 1]) { t = a[i]; a[i] = a[i + 1]; a[i + 1] = t; count++; } } if (j != 0) j--; if (j == 0) { break; } } for (int i = 0; i < N; i++) { printf("%d", a[i]); if (i != N - 1) { printf(" "); } else { printf("\n"); } } printf("%d\n", count); }
replace
30
31
30
32
TLE
p02260
C++
Runtime Error
#include <stdio.h> int selectionSort(int A[], int N) { int i, j, t, sw = 0, minj; for (i = 0; i < N - 1; i++) { minj = i; for (j = i; j < N; j++) { if (A[j] < A[minj]) minj = j; } t = A[minj]; A[minj] = A[i]; A[i] = t; if (i != minj) sw++; } return sw; } int main() { int A[100], N, i, sw; scanf("%d", &N); for (i = 0; i < N; i++) scanf("%d", A[i]); sw = selectionSort(A, N); for (i = 0; i < N; i++) { if (i != 0) printf(" "); printf("%d", A[i]); } printf("\n"); printf("%d\n", sw); return 0; }
#include <stdio.h> int selectionSort(int A[], int N) { int i, j, t, sw = 0, minj; for (i = 0; i < N - 1; i++) { minj = i; for (j = i; j < N; j++) { if (A[j] < A[minj]) minj = j; } t = A[minj]; A[minj] = A[i]; A[i] = t; if (i != minj) sw++; } return sw; } int main() { int A[100], N, i, sw; scanf("%d", &N); for (i = 0; i < N; i++) scanf("%d", &A[i]); sw = selectionSort(A, N); for (i = 0; i < N; i++) { if (i != 0) printf(" "); printf("%d", A[i]); } printf("\n"); printf("%d\n", sw); return 0; }
replace
24
25
24
25
-11
p02260
C++
Time Limit Exceeded
#include <iostream> using namespace std; // ?????????????????????????????????????????° int selectionSort(int A[], int N) { int sw = 0; for (int i = 0; i < N; i++) { int minj = i; for (int j = i; i < N; j++) { if (A[j] < A[minj]) minj = j; } if (i != minj) { swap(A[i], A[minj]); sw++; } } return sw; } int main() { int A[100], N, sw; cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; sw = selectionSort(A, N); for (int i = 0; i < N; i++) { if (i) cout << " "; cout << A[i]; } cout << endl << sw << endl; return 0; }
#include <iostream> using namespace std; // ?????????????????????????????????????????° int selectionSort(int A[], int N) { int sw = 0; for (int i = 0; i < N; i++) { int minj = i; for (int j = i; j < N; j++) { if (A[j] < A[minj]) minj = j; } if (i != minj) { swap(A[i], A[minj]); sw++; } } return sw; } int main() { int A[100], N, sw; cin >> N; for (int i = 0; i < N; i++) cin >> A[i]; sw = selectionSort(A, N); for (int i = 0; i < N; i++) { if (i) cout << " "; cout << A[i]; } cout << endl << sw << endl; return 0; }
replace
8
9
8
9
TLE
p02260
C++
Runtime Error
#include <stdio.h> int main() { int m, min, minn, i, j, n, c; int a[100]; c = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n - 1; i++) { m = a[i]; min = a[i]; for (j = i + 1; j < n; j++) { if (min > a[j]) { min = a[j]; minn = j; } } if (i != minn) { a[i] = a[minn]; a[minn] = m; c++; } } printf("%d", a[0]); for (i = 1; i < n; i++) { printf(" %d", a[i]); } printf("\n%d\n", c); return 0; }
#include <stdio.h> int main() { int m, min, minn, i, j, n, c; int a[100]; c = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n - 1; i++) { m = a[i]; min = a[i]; minn = i; for (j = i + 1; j < n; j++) { if (min > a[j]) { min = a[j]; minn = j; } } if (i != minn) { a[i] = a[minn]; a[minn] = m; c++; } } printf("%d", a[0]); for (i = 1; i < n; i++) { printf(" %d", a[i]); } printf("\n%d\n", c); return 0; }
insert
13
13
13
14
0
p02261
C++
Runtime Error
#include <iostream> using namespace std; struct Card { char suit, value; }; void bubble(struct Card A[], int N) { for (int i = 0; i < N; i++) { for (int j = N - 1; j < i + 1; j--) { if (A[j].value < A[j - 1].value) { Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t; } } } } void selection(struct Card A[], int N) { for (int i = 0; i < N; i++) { int minj = i; for (int j = i; j < N; j++) { if (A[j].value < A[minj].value) minj = j; } Card t = A[i]; A[i] = A[minj]; A[minj] = t; } } void print(struct Card A[], int N) { for (int i = 0; i < N; i++) { if (i > 0) cout << " "; cout << A[i].suit << A[i].value; } cout << endl; } bool isStable(struct Card C1[], struct Card C2[], int N) { for (int i = 0; i < N; i++) { if (C1[i].suit != C2[i].suit) return false; } return true; } int main() { Card C1[100], C2[100]; int N; char ch; cin >> N; for (int i = 0; i < N; i++) { cin >> C1[i].suit >> C1[i].value; } for (int i = 0; i < N; i++) C2[i] = C1[i]; bubble(C1, N); selection(C2, N); print(C1, N); cout << "Stable" << endl; print(C2, N); if (isStable(C1, C2, N)) { cout << "Stable" << endl; } else { cout << "Not stable" << endl; } return 0; }
#include <iostream> using namespace std; struct Card { char suit, value; }; void bubble(struct Card A[], int N) { for (int i = 0; i < N; i++) { for (int j = N - 1; j >= i + 1; j--) { if (A[j].value < A[j - 1].value) { Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t; } } } } void selection(struct Card A[], int N) { for (int i = 0; i < N; i++) { int minj = i; for (int j = i; j < N; j++) { if (A[j].value < A[minj].value) minj = j; } Card t = A[i]; A[i] = A[minj]; A[minj] = t; } } void print(struct Card A[], int N) { for (int i = 0; i < N; i++) { if (i > 0) cout << " "; cout << A[i].suit << A[i].value; } cout << endl; } bool isStable(struct Card C1[], struct Card C2[], int N) { for (int i = 0; i < N; i++) { if (C1[i].suit != C2[i].suit) return false; } return true; } int main() { Card C1[100], C2[100]; int N; char ch; cin >> N; for (int i = 0; i < N; i++) { cin >> C1[i].suit >> C1[i].value; } for (int i = 0; i < N; i++) C2[i] = C1[i]; bubble(C1, N); selection(C2, N); print(C1, N); cout << "Stable" << endl; print(C2, N); if (isStable(C1, C2, N)) { cout << "Stable" << endl; } else { cout << "Not stable" << endl; } return 0; }
replace
9
10
9
10
-11
p02261
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; typedef vector<string> card_list; bool comp(string a, string b) { int x = static_cast<int>(a[1]) - 48; int y = static_cast<int>(b[1]) - 48; return x < y; } int bubbleSort(card_list &A) { int N = A.size(); int c = 0; for (int i = 0; i < N; ++i) { for (int j = N - 1; j > i; --j) { if (comp(A[j], A[j - 1])) { swap(A[j], A[j - 1]); c++; } } } return c; } int selectionSort(card_list &A) { int N = A.size(); int c = 0; for (int i = 0; i < N; ++i) { int min = i; for (int j = i; j < N; ++j) { if (comp(A[j], A[min])) { min = j; } } if (i != min) { swap(A[i], A[min]); c++; } } return c; } void print_card_list(card_list &cards) { card_list::iterator it = cards.begin(); for (; it != cards.end() - 1; ++it) { cout << *it << " "; } cout << *it << endl; } int main() { int n; cin >> n; int a[n]; card_list A; for (int i = 0; i < n; ++i) { string s; cin >> s; A.push_back(s); } card_list B = A; bubbleSort(A); print_card_list(A); cout << "Stable" << endl; selectionSort(B); print_card_list(B); if (equal(A.begin(), A.end(), B.end())) { cout << "Stable"; } else { cout << "Not stable"; } cout << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; typedef vector<string> card_list; bool comp(string a, string b) { int x = static_cast<int>(a[1]) - 48; int y = static_cast<int>(b[1]) - 48; return x < y; } int bubbleSort(card_list &A) { int N = A.size(); int c = 0; for (int i = 0; i < N; ++i) { for (int j = N - 1; j > i; --j) { if (comp(A[j], A[j - 1])) { swap(A[j], A[j - 1]); c++; } } } return c; } int selectionSort(card_list &A) { int N = A.size(); int c = 0; for (int i = 0; i < N; ++i) { int min = i; for (int j = i; j < N; ++j) { if (comp(A[j], A[min])) { min = j; } } if (i != min) { swap(A[i], A[min]); c++; } } return c; } void print_card_list(card_list &cards) { card_list::iterator it = cards.begin(); for (; it != cards.end() - 1; ++it) { cout << *it << " "; } cout << *it << endl; } int main() { int n; cin >> n; int a[n]; card_list A; for (int i = 0; i < n; ++i) { string s; cin >> s; A.push_back(s); } card_list B = A; bubbleSort(A); print_card_list(A); cout << "Stable" << endl; selectionSort(B); print_card_list(B); if (equal(A.begin(), A.end(), B.begin())) { cout << "Stable"; } else { cout << "Not stable"; } cout << endl; return 0; }
replace
74
75
74
75
0
p02261
C++
Runtime Error
#include <iostream> using namespace std; void selectionSort(); void bubbleSort(); struct card { int value; char mark; }; void write(card[]); bool isStable(card[]); int n; card c[40], c1[40], c2[40]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> c[i].mark >> c[i].value; } for (int i = 0; i < n; i++) { c1[i] = c2[i] = c[i]; } bubbleSort(); selectionSort(); write(c1); if (isStable(c1)) cout << "Stable" << endl; else cout << "Not stable" << endl; write(c2); if (isStable(c2)) cout << "Stable" << endl; else cout << "Not stable" << endl; return 0; } void selectionSort() { for (int i = 0; i < n; i++) { int minj = i; for (int j = i; j <= n - 1; j++) { if (c2[j].value < c2[minj].value) { minj = j; } } if (i != minj) { card copy = c2[i]; c2[i] = c2[minj]; c2[minj] = copy; } } } void bubbleSort() { bool flag = true; while (flag) { flag = false; for (int i = n - 1; i >= 1; i--) { if (c1[i - 1].value > c1[i].value) { card copy = c1[i]; c1[i] = c1[i - 1]; c1[i - 1] = copy; flag = true; } } } } void write(card x[]) { for (int i = 0; i < n; i++) { cout << x[i].mark << x[i].value; if (i == n - 1) cout << endl; else cout << " "; } } bool isStable(card x[]) { bool isStable = true; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (x[i].value == x[j].value) { for (int k = 0; k < n; k++) { if (x[i].mark == c[k].mark && x[i].value == c[k].value) break; else if (x[j].mark == c[k].mark && x[j].value == c[k].value) { cerr << "i:" << i << " j:" << j << " k:" << k << endl; return false; } } } } } return true; }
#include <iostream> using namespace std; void selectionSort(); void bubbleSort(); struct card { int value; char mark; }; void write(card[]); bool isStable(card[]); int n; card c[40], c1[40], c2[40]; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> c[i].mark >> c[i].value; } for (int i = 0; i < n; i++) { c1[i] = c2[i] = c[i]; } bubbleSort(); selectionSort(); write(c1); if (isStable(c1)) cout << "Stable" << endl; else cout << "Not stable" << endl; write(c2); if (isStable(c2)) cout << "Stable" << endl; else cout << "Not stable" << endl; return 0; } void selectionSort() { for (int i = 0; i < n; i++) { int minj = i; for (int j = i; j <= n - 1; j++) { if (c2[j].value < c2[minj].value) { minj = j; } } if (i != minj) { card copy = c2[i]; c2[i] = c2[minj]; c2[minj] = copy; } } } void bubbleSort() { bool flag = true; while (flag) { flag = false; for (int i = n - 1; i >= 1; i--) { if (c1[i - 1].value > c1[i].value) { card copy = c1[i]; c1[i] = c1[i - 1]; c1[i - 1] = copy; flag = true; } } } } void write(card x[]) { for (int i = 0; i < n; i++) { cout << x[i].mark << x[i].value; if (i == n - 1) cout << endl; else cout << " "; } } bool isStable(card x[]) { bool isStable = true; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (x[i].value == x[j].value) { for (int k = 0; k < n; k++) { if (x[i].mark == c[k].mark && x[i].value == c[k].value) break; else if (x[j].mark == c[k].mark && x[j].value == c[k].value) { // cerr << "i:" << i << " j:" << j << " k:" << k << endl; return false; } } } } } return true; }
replace
89
90
89
90
0
i:2 j:3 k:0
p02261
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> using namespace std; int n; string a[36], b[36]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i], b[i] = a[i]; for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j++) { if (b[i][1] > b[j][1]) swap(b[i], b[j]); } } for (int i = 0; i < n; i++) cout << (i ? " " : "") << b[i]; cout << endl; cout << "Stable" << endl; for (int i = 0; i < n; i++) { int r = i; for (int j = i + 1; j < n; j++) { if (a[j][1] < a[r][1]) r = j; } swap(a[i], a[r]); } for (int i = 0; i < n; i++) cout << (i ? " " : "") << a[i]; cout << endl; cout << (equal(a, a + n, b) ? "Stable" : "Not stable") << endl; }
#include <algorithm> #include <iostream> #include <string> using namespace std; int n; string a[36], b[36]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i], b[i] = a[i]; for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j--) { if (b[j - 1][1] > b[j][1]) swap(b[j - 1], b[j]); } } for (int i = 0; i < n; i++) cout << (i ? " " : "") << b[i]; cout << endl; cout << "Stable" << endl; for (int i = 0; i < n; i++) { int r = i; for (int j = i + 1; j < n; j++) { if (a[j][1] < a[r][1]) r = j; } swap(a[i], a[r]); } for (int i = 0; i < n; i++) cout << (i ? " " : "") << a[i]; cout << endl; cout << (equal(a, a + n, b) ? "Stable" : "Not stable") << endl; }
replace
11
14
11
14
-11
p02261
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; string bubbleSort(vector<char> &Mb, vector<int> &Nb, int A); string selectionSort(vector<char> &Ms, vector<int> &Ns, int A); int main(void) { int A; cin >> A; vector<char> M(A), Mb(A), Ms(A); vector<int> N(A), Nb(A), Ns(A); for (int i = 0; i < A; i++) cin >> M.at(i) >> N.at(i); for (int i = 0; i < A; i++) { Mb.at(i) = M.at(i); Ms.at(i) = M.at(i); Nb.at(i) = N.at(i); Ns.at(i) = N.at(i); } string YN = bubbleSort(Mb, Nb, A); for (int i = 0; i < A; i++) { if (i) cout << " "; cout << Mb.at(i) << Nb.at(i); } cout << endl; cout << YN << endl; YN = selectionSort(Ms, Ns, A); for (int i = 0; i < A; i++) { if (i) cout << " "; cout << Ms.at(i) << Ns.at(i); } cout << endl; cout << YN << endl; return 0; } string bubbleSort(vector<char> &Mb, vector<int> &Nb, int A) { vector<int> Ib(A); for (int i = 0; i < A; i++) Ib.at(i) = i; for (int i = 0; i < A - 1; i++) { for (int j = A - 1; i < j; j--) { if (Nb.at(j) < Nb.at(j - 1)) { swap(Nb.at(j), Nb.at(j - 1)); swap(Mb.at(j), Mb.at(j - 1)); swap(Ib.at(j), Ib.at(j - 1)); } } } for (int i = 0; i < A - 1; i++) { if (Nb.at(i) == Nb.at(i + 1)) { if (Ib.at(i) > Ib.at(i + 1)) { return "Not stable"; } } } return "Stable"; } string selectionSort(vector<char> &Ms, vector<int> &Ns, int A) { vector<int> Is(A); for (int i = 0; i < A; i++) Is.at(i) = i; for (int i = 0; i < A - 1; i++) { int minN = i; for (int j = i + 1; j < A; j++) { if (Ns.at(j) < Ns.at(minN)) { minN = j; } } if (minN != i) { swap(Ms.at(i), Ms.at(minN)); swap(Ns.at(i), Ns.at(minN)); swap(Is.at(i), Is.at(minN)); } } for (int i = 0; i < A; i++) { if (Ns.at(i) == Ns.at(i + 1)) { if (Is.at(i) > Is.at(i + 1)) { return "Not stable"; } } } return "Stable"; }
#include "bits/stdc++.h" using namespace std; string bubbleSort(vector<char> &Mb, vector<int> &Nb, int A); string selectionSort(vector<char> &Ms, vector<int> &Ns, int A); int main(void) { int A; cin >> A; vector<char> M(A), Mb(A), Ms(A); vector<int> N(A), Nb(A), Ns(A); for (int i = 0; i < A; i++) cin >> M.at(i) >> N.at(i); for (int i = 0; i < A; i++) { Mb.at(i) = M.at(i); Ms.at(i) = M.at(i); Nb.at(i) = N.at(i); Ns.at(i) = N.at(i); } string YN = bubbleSort(Mb, Nb, A); for (int i = 0; i < A; i++) { if (i) cout << " "; cout << Mb.at(i) << Nb.at(i); } cout << endl; cout << YN << endl; YN = selectionSort(Ms, Ns, A); for (int i = 0; i < A; i++) { if (i) cout << " "; cout << Ms.at(i) << Ns.at(i); } cout << endl; cout << YN << endl; return 0; } string bubbleSort(vector<char> &Mb, vector<int> &Nb, int A) { vector<int> Ib(A); for (int i = 0; i < A; i++) Ib.at(i) = i; for (int i = 0; i < A - 1; i++) { for (int j = A - 1; i < j; j--) { if (Nb.at(j) < Nb.at(j - 1)) { swap(Nb.at(j), Nb.at(j - 1)); swap(Mb.at(j), Mb.at(j - 1)); swap(Ib.at(j), Ib.at(j - 1)); } } } for (int i = 0; i < A - 1; i++) { if (Nb.at(i) == Nb.at(i + 1)) { if (Ib.at(i) > Ib.at(i + 1)) { return "Not stable"; } } } return "Stable"; } string selectionSort(vector<char> &Ms, vector<int> &Ns, int A) { vector<int> Is(A); for (int i = 0; i < A; i++) Is.at(i) = i; for (int i = 0; i < A - 1; i++) { int minN = i; for (int j = i + 1; j < A; j++) { if (Ns.at(j) < Ns.at(minN)) { minN = j; } } if (minN != i) { swap(Ms.at(i), Ms.at(minN)); swap(Ns.at(i), Ns.at(minN)); swap(Is.at(i), Is.at(minN)); } } for (int i = 0; i < A - 1; i++) { if (Ns.at(i) == Ns.at(i + 1)) { if (Is.at(i) > Is.at(i + 1)) { return "Not stable"; } } } return "Stable"; }
replace
90
91
90
91
0
p02261
C++
Runtime Error
#include <cstdint> #include <fstream> #include <iostream> #include <string> typedef std::uint_least16_t USI; typedef std::int_least16_t SSI; typedef std::uint_least32_t ULI; // 10^9 typedef std::int_least32_t SLI; typedef std::uint_least64_t ULLI; typedef std::int_least64_t SLLI; using namespace std; struct Card { char S; USI N; }; string StableCheck[9]; void Swap(Card pC[], int a, int b) { Card temp = pC[a]; pC[a] = pC[b]; pC[b] = temp; } void CheckStable(Card C[], int N, string str[]) { for (int i = 0; i < N; i++) { str[C[i].N - 1] += C[i].S; } } void PrintOutStable(string str[]) { bool IsStableSort = true; for (int i = 0; i < 9; i++) { if (str[i] != StableCheck[i]) { IsStableSort = false; break; } } if (IsStableSort) { cout << "\nStable\n"; } else { cout << "\nNot stable\n"; } } void PrintOut(Card pC[], int N) { for (int i = 0; i < N; i++) { if (i != 0) cout << " "; cout << pC[i].S << pC[i].N; } } void BubbleSort(const Card pC[], int N) { Card C[36]; bool IsStable = true; for (int i = 0; i < N; i++) { C[i] = pC[i]; } for (int i = 0; i < N; i++) { for (int j = N - 1; j > i; j--) { if (C[j].N < C[j - 1].N) { Swap(C, j, j - 1); } } } PrintOut(C, N); string strSelectionSort[9]; CheckStable(C, N, strSelectionSort); PrintOutStable(strSelectionSort); } void SelectionSort(const Card pC[], int N) { Card C[36]; for (int i = 0; i < N; i++) { C[i] = pC[i]; } for (int i = 0; i < N; i++) { int minj = i; for (int j = i; j < N; j++) { if (C[j].N < C[minj].N) { minj = j; } } if (i != minj) { Swap(C, i, minj); } } PrintOut(C, N); string strSelectionSort[9]; CheckStable(C, N, strSelectionSort); PrintOutStable(strSelectionSort); } int main() { // input from txt std::ifstream in(R"(C:\Temp\input.txt)"); std::cin.rdbuf(in.rdbuf()); int N; cin >> N; cin.clear(); cin.ignore(); Card C[36]; string str; for (int i = 0; i < N; i++) { cin >> str; C[i].S = str[0]; C[i].N = str[1] - '0'; } CheckStable(C, N, StableCheck); BubbleSort(C, N); SelectionSort(C, N); return 0; }
#include <cstdint> #include <fstream> #include <iostream> #include <string> typedef std::uint_least16_t USI; typedef std::int_least16_t SSI; typedef std::uint_least32_t ULI; // 10^9 typedef std::int_least32_t SLI; typedef std::uint_least64_t ULLI; typedef std::int_least64_t SLLI; using namespace std; struct Card { char S; USI N; }; string StableCheck[9]; void Swap(Card pC[], int a, int b) { Card temp = pC[a]; pC[a] = pC[b]; pC[b] = temp; } void CheckStable(Card C[], int N, string str[]) { for (int i = 0; i < N; i++) { str[C[i].N - 1] += C[i].S; } } void PrintOutStable(string str[]) { bool IsStableSort = true; for (int i = 0; i < 9; i++) { if (str[i] != StableCheck[i]) { IsStableSort = false; break; } } if (IsStableSort) { cout << "\nStable\n"; } else { cout << "\nNot stable\n"; } } void PrintOut(Card pC[], int N) { for (int i = 0; i < N; i++) { if (i != 0) cout << " "; cout << pC[i].S << pC[i].N; } } void BubbleSort(const Card pC[], int N) { Card C[36]; bool IsStable = true; for (int i = 0; i < N; i++) { C[i] = pC[i]; } for (int i = 0; i < N; i++) { for (int j = N - 1; j > i; j--) { if (C[j].N < C[j - 1].N) { Swap(C, j, j - 1); } } } PrintOut(C, N); string strSelectionSort[9]; CheckStable(C, N, strSelectionSort); PrintOutStable(strSelectionSort); } void SelectionSort(const Card pC[], int N) { Card C[36]; for (int i = 0; i < N; i++) { C[i] = pC[i]; } for (int i = 0; i < N; i++) { int minj = i; for (int j = i; j < N; j++) { if (C[j].N < C[minj].N) { minj = j; } } if (i != minj) { Swap(C, i, minj); } } PrintOut(C, N); string strSelectionSort[9]; CheckStable(C, N, strSelectionSort); PrintOutStable(strSelectionSort); } int main() { int N; cin >> N; cin.clear(); cin.ignore(); Card C[36]; string str; for (int i = 0; i < N; i++) { cin >> str; C[i].S = str[0]; C[i].N = str[1] - '0'; } CheckStable(C, N, StableCheck); BubbleSort(C, N); SelectionSort(C, N); return 0; }
delete
108
112
108
108
0
p02261
C++
Runtime Error
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long unsigned int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i, n) for (int i = 0; i < (int)(n); i++) struct Card { char suit; int value; }; void print(std::vector<Card> cards); vector<Card> bubble(std::vector<Card> C, int N) { rep(i, N) { int j = N - 1; while (j > i) { if (C[j].value < C[j - 1].value) { swap(C[j], C[j - 1]); } j--; } } return C; } vector<Card> selection(std::vector<Card> C, int N) { rep(i, N) { int minj = i; int j = i; while (j < N) { if (C[j].value < C[minj].value) { minj = j; } j++; } if (i != minj) { swap(C[i], C[minj]); } } return C; } void print(std::vector<Card> cards, int N) { Card card_last = cards[N - 1]; rep(i, N - 1) { if (cards[i].value == 0) { break; } std::cout << cards[i].suit << cards[i].value << " "; } std::cout << card_last.suit << card_last.value << '\n'; } void check(vector<Card> C1, vector<Card> C2, int N) { rep(i, N) { if (!(C1[i].suit == C2[i].suit)) { std::cout << "Not stable" << '\n'; return; } } std::cout << "Stable" << '\n'; } int main() { std::vector<Card> C1(32); std::vector<Card> C2(32); int N; cin >> N; rep(i, N) { cin >> C1[i].suit >> C1[i].value; } rep(i, N) { C2[i] = C1[i]; } // print(C1); C1 = bubble(C1, N); C2 = selection(C2, N); print(C1, N); std::cout << "Stable" << '\n'; print(C2, N); check(C1, C2, N); return 0; }
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long unsigned int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i, n) for (int i = 0; i < (int)(n); i++) struct Card { char suit; int value; }; void print(std::vector<Card> cards); vector<Card> bubble(std::vector<Card> C, int N) { rep(i, N) { int j = N - 1; while (j > i) { if (C[j].value < C[j - 1].value) { swap(C[j], C[j - 1]); } j--; } } return C; } vector<Card> selection(std::vector<Card> C, int N) { rep(i, N) { int minj = i; int j = i; while (j < N) { if (C[j].value < C[minj].value) { minj = j; } j++; } if (i != minj) { swap(C[i], C[minj]); } } return C; } void print(std::vector<Card> cards, int N) { Card card_last = cards[N - 1]; rep(i, N - 1) { if (cards[i].value == 0) { break; } std::cout << cards[i].suit << cards[i].value << " "; } std::cout << card_last.suit << card_last.value << '\n'; } void check(vector<Card> C1, vector<Card> C2, int N) { rep(i, N) { if (!(C1[i].suit == C2[i].suit)) { std::cout << "Not stable" << '\n'; return; } } std::cout << "Stable" << '\n'; } int main() { std::vector<Card> C1(36); std::vector<Card> C2(36); int N; cin >> N; rep(i, N) { cin >> C1[i].suit >> C1[i].value; } rep(i, N) { C2[i] = C1[i]; } // print(C1); C1 = bubble(C1, N); C2 = selection(C2, N); print(C1, N); std::cout << "Stable" << '\n'; print(C2, N); check(C1, C2, N); return 0; }
replace
82
84
82
84
0
p02261
C++
Runtime Error
#include <iostream> #include <string> #include <vector> #include <cstdlib> using namespace std; vector<pair<char, int>> B; vector<pair<char, int>> SelectionSort(vector<pair<char, int>> v) { for (int i = 0; i < v.size(); i++) { int mini = i; for (int j = i; j < v.size(); j++) { if (v[j].second < v[mini].second) { mini = j; } } pair<char, int> tmp = v[i]; v[i] = v[mini]; v[mini] = tmp; } for (int i = 0; i < v.size() - 1; i++) { cout << v[i].first << v[i].second << " "; } cout << v[v.size() - 1].first << v[v.size() - 1].second << endl; return v; } vector<pair<char, int>> BubbleSort(vector<pair<char, int>> A) { for (int i = 0; i < A.size(); i++) { for (int j = A.size(); j > i; j--) { if (A[j].second < A[j - 1].second) { pair<char, int> tmp = A[j]; A[j] = A[j - 1]; A[j - 1] = tmp; } } } for (int k = 0; k < A.size() - 1; k++) { cout << A[k].first << A[k].second << " "; } cout << A[A.size() - 1].first << A[A.size() - 1].second << endl; return A; } int main() { int n; vector<pair<char, int>> B; cin >> n; for (int i = 0; i < n; i++) { string str; cin >> str; pair<char, int> tmp; tmp.first = str[0]; tmp.second = str[1] - '0'; B.push_back(tmp); } vector<pair<char, int>> C = BubbleSort(B); cout << "Stable" << endl; vector<pair<char, int>> D = SelectionSort(B); bool flag = true; for (int i = 0; i < n; i++) { if (C[i].first != D[i].first || C[i].second != D[i].second) { flag = false; } } if (flag) { cout << "Stable" << endl; } else { cout << "Not stable" << endl; } return 0; }
#include <iostream> #include <string> #include <vector> #include <cstdlib> using namespace std; vector<pair<char, int>> B; vector<pair<char, int>> SelectionSort(vector<pair<char, int>> v) { for (int i = 0; i < v.size(); i++) { int mini = i; for (int j = i; j < v.size(); j++) { if (v[j].second < v[mini].second) { mini = j; } } pair<char, int> tmp = v[i]; v[i] = v[mini]; v[mini] = tmp; } for (int i = 0; i < v.size() - 1; i++) { cout << v[i].first << v[i].second << " "; } cout << v[v.size() - 1].first << v[v.size() - 1].second << endl; return v; } vector<pair<char, int>> BubbleSort(vector<pair<char, int>> A) { for (int i = 0; i < A.size(); i++) { for (int j = A.size() - 1; j > i; j--) { if (A[j].second < A[j - 1].second) { pair<char, int> tmp = A[j]; A[j] = A[j - 1]; A[j - 1] = tmp; } } } for (int k = 0; k < A.size() - 1; k++) { cout << A[k].first << A[k].second << " "; } cout << A[A.size() - 1].first << A[A.size() - 1].second << endl; return A; } int main() { int n; vector<pair<char, int>> B; cin >> n; for (int i = 0; i < n; i++) { string str; cin >> str; pair<char, int> tmp; tmp.first = str[0]; tmp.second = str[1] - '0'; B.push_back(tmp); } vector<pair<char, int>> C = BubbleSort(B); cout << "Stable" << endl; vector<pair<char, int>> D = SelectionSort(B); bool flag = true; for (int i = 0; i < n; i++) { if (C[i].first != D[i].first || C[i].second != D[i].second) { flag = false; } } if (flag) { cout << "Stable" << endl; } else { cout << "Not stable" << endl; } return 0; }
replace
31
32
31
32
-6
munmap_chunk(): invalid pointer
p02261
C++
Runtime Error
#include <iostream> using namespace std; struct Card { char suit, value; }; void bubble(struct Card a[], int n) { Card hoge; for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j++) { if (a[j].value < a[j - 1].value) { hoge = a[j]; a[j] = a[j - 1]; a[j - 1] = hoge; } } } } void selection(struct Card a[], int n) { int minj; Card hoge; for (int i = 0; i < n; i++) { minj = i; for (int j = i; j < n; j++) { if (a[j].value < a[minj].value) minj = j; } hoge = a[i]; a[i] = a[minj]; a[minj] = hoge; } } void print(struct Card a[], int n) { for (int i = 0; i < n; i++) { if (i > 0) cout << " "; cout << a[i].suit << a[i].value; } cout << endl; } bool stable(struct Card c1[], struct Card c2[], int n) { for (int i = 0; i < n; i++) { if (c1[i].suit != c2[i].suit) return false; } return true; } int main() { Card c1[40], c2[40]; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> c1[i].suit >> c1[i].value; c2[i] = c1[i]; } bubble(c1, n); selection(c2, n); print(c1, n); cout << "Stable" << endl; print(c2, n); if (stable(c1, c2, n)) cout << "Stable" << endl; else cout << "Not stable" << endl; return 0; }
#include <iostream> using namespace std; struct Card { char suit, value; }; void bubble(struct Card a[], int n) { Card hoge; for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j--) { if (a[j].value < a[j - 1].value) { hoge = a[j]; a[j] = a[j - 1]; a[j - 1] = hoge; } } } } void selection(struct Card a[], int n) { int minj; Card hoge; for (int i = 0; i < n; i++) { minj = i; for (int j = i; j < n; j++) { if (a[j].value < a[minj].value) minj = j; } hoge = a[i]; a[i] = a[minj]; a[minj] = hoge; } } void print(struct Card a[], int n) { for (int i = 0; i < n; i++) { if (i > 0) cout << " "; cout << a[i].suit << a[i].value; } cout << endl; } bool stable(struct Card c1[], struct Card c2[], int n) { for (int i = 0; i < n; i++) { if (c1[i].suit != c2[i].suit) return false; } return true; } int main() { Card c1[40], c2[40]; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> c1[i].suit >> c1[i].value; c2[i] = c1[i]; } bubble(c1, n); selection(c2, n); print(c1, n); cout << "Stable" << endl; print(c2, n); if (stable(c1, c2, n)) cout << "Stable" << endl; else cout << "Not stable" << endl; return 0; }
replace
10
11
10
11
-11
p02261
C++
Runtime Error
#include <algorithm> #include <iostream> #include <stdio.h> using namespace std; struct Card { char suit, value; }; void BubbleSort(struct Card C[], int n) { Card tmp; for (int i = 0; i < n; i++) { for (int j = n - 1; j >= i; j--) { if (C[j].value > C[j - 1].value) { tmp = C[j]; C[j] = C[j - 1]; C[j - 1] = tmp; } } } } void SelectionSort(struct Card C[], int n) { Card tmp; for (int i = 0; i < n; i++) { int min = i; for (int j = i; j < n; j++) { if (C[j].value < C[min].value) { min = j; } } tmp = C[i]; C[i] = C[min]; C[min] = tmp; } } void print(struct Card C[], int n) { for (int i = 0; i < n; i++) { if (i != 0) cout << " "; cout << C[i].suit << C[i].value; } cout << endl; } bool isStable(struct Card C1[], struct Card C2[], int n) { for (int i = 0; i < n; i++) { if (C1[i].suit != C2[i].suit) { return false; } } return true; } int main() { Card C1[100], C2[100]; int n; char ch; cin >> n; for (int i = 0; i < n; i++) { cin >> C1[i].suit >> C1[i].value; } for (int i = 0; i < n; i++) C2[i] = C1[i]; BubbleSort(C1, n); SelectionSort(C2, n); print(C1, n); cout << "Stable" << endl; print(C2, n); if (isStable(C1, C2, n)) { cout << "Stable" << endl; } else { cout << "Not stable" << endl; } return 0; }
#include <algorithm> #include <iostream> #include <stdio.h> using namespace std; struct Card { char suit, value; }; void BubbleSort(struct Card C[], int n) { Card tmp; for (int i = 0; i < n; i++) { for (int j = n - 1; j >= i; j--) { if (C[j].value < C[j - 1].value) { tmp = C[j]; C[j] = C[j - 1]; C[j - 1] = tmp; } } } } void SelectionSort(struct Card C[], int n) { Card tmp; for (int i = 0; i < n; i++) { int min = i; for (int j = i; j < n; j++) { if (C[j].value < C[min].value) { min = j; } } tmp = C[i]; C[i] = C[min]; C[min] = tmp; } } void print(struct Card C[], int n) { for (int i = 0; i < n; i++) { if (i != 0) cout << " "; cout << C[i].suit << C[i].value; } cout << endl; } bool isStable(struct Card C1[], struct Card C2[], int n) { for (int i = 0; i < n; i++) { if (C1[i].suit != C2[i].suit) { return false; } } return true; } int main() { Card C1[100], C2[100]; int n; char ch; cin >> n; for (int i = 0; i < n; i++) { cin >> C1[i].suit >> C1[i].value; } for (int i = 0; i < n; i++) C2[i] = C1[i]; BubbleSort(C1, n); SelectionSort(C2, n); print(C1, n); cout << "Stable" << endl; print(C2, n); if (isStable(C1, C2, n)) { cout << "Stable" << endl; } else { cout << "Not stable" << endl; } return 0; }
replace
12
13
12
13
0
p02261
C++
Runtime Error
#include <iostream> using namespace std; typedef struct { char suit; char value; } Card; void bubbleSort(Card A[], int N) { for (int i = 0; i < N; i++) { for (int j = N - 1; j >= i; j--) { if (A[j].value >= A[j - 1].value) { Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t; } } } } void selectionSort(Card A[], int N) { for (int i = 0; i < N; i++) { int minj = i; for (int j = i; j < N; j++) { if (A[j].value < A[minj].value) minj = j; } Card t = A[i]; A[i] = A[minj]; A[minj] = t; } } void print(Card A[], int N) { for (int i = 0; i < N; i++) { if (i > 0) cout << " "; cout << A[i].suit << A[i].value; } cout << endl; } bool isStable(Card C1[], Card C2[], int N) { for (int i = 0; i < N; i++) { if (C1[i].suit != C2[i].suit) return false; } return true; } int main() { Card C1[100], C2[100]; int N; char ch; cin >> N; for (int i = 0; i < N; i++) { cin >> C1[i].suit >> C1[i].value; } for (int i = 0; i < N; i++) C2[i] = C1[i]; bubbleSort(C1, N); selectionSort(C2, N); print(C1, N); cout << "Stable" << endl; print(C2, N); if (isStable(C1, C2, N)) { cout << "Stable" << endl; } else { cout << "Not stable" << endl; } return 0; }
#include <iostream> using namespace std; typedef struct { char suit; char value; } Card; void bubbleSort(Card A[], int N) { for (int i = 0; i < N; i++) { for (int j = N - 1; j >= i; j--) { if (A[j].value < A[j - 1].value) { Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t; } } } } void selectionSort(Card A[], int N) { for (int i = 0; i < N; i++) { int minj = i; for (int j = i; j < N; j++) { if (A[j].value < A[minj].value) minj = j; } Card t = A[i]; A[i] = A[minj]; A[minj] = t; } } void print(Card A[], int N) { for (int i = 0; i < N; i++) { if (i > 0) cout << " "; cout << A[i].suit << A[i].value; } cout << endl; } bool isStable(Card C1[], Card C2[], int N) { for (int i = 0; i < N; i++) { if (C1[i].suit != C2[i].suit) return false; } return true; } int main() { Card C1[100], C2[100]; int N; char ch; cin >> N; for (int i = 0; i < N; i++) { cin >> C1[i].suit >> C1[i].value; } for (int i = 0; i < N; i++) C2[i] = C1[i]; bubbleSort(C1, N); selectionSort(C2, N); print(C1, N); cout << "Stable" << endl; print(C2, N); if (isStable(C1, C2, N)) { cout << "Stable" << endl; } else { cout << "Not stable" << endl; } return 0; }
replace
11
12
11
12
0
p02262
C++
Runtime Error
#include <cmath> #include <iostream> using namespace std; #include <vector> #define ArrayNum 100 vector<int> g; int insertionSort(int a[], int n, int g) { int i, j, cnt = 0, v; for (i = g; i < n; i++) { v = a[i]; j = i - g; while (j >= 0 && a[j] > v) { a[j + g] = a[j]; j = j - g; cnt++; } a[j + g] = v; } return cnt; } void shellSort(int a[], int n) { int i, cnt = 0, m; for (int h = 1;;) { if (h > n) break; g.push_back(h); h = 3 * h + 1; } m = g.size(); for (i = m - 1; i >= 0; i--) cnt = cnt + insertionSort(a, n, g[i]); cout << m << "\n"; for (i = m - 1; i > 0; i--) cout << g[i] << " "; cout << g[0] << "\n"; cout << cnt << "\n"; for (i = 0; i < n; i++) cout << a[i] << "\n"; } int main(void) { int i, n, a[ArrayNum]; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; shellSort(a, n); }
#include <cmath> #include <iostream> using namespace std; #include <vector> #define ArrayNum 1000000 vector<int> g; int insertionSort(int a[], int n, int g) { int i, j, cnt = 0, v; for (i = g; i < n; i++) { v = a[i]; j = i - g; while (j >= 0 && a[j] > v) { a[j + g] = a[j]; j = j - g; cnt++; } a[j + g] = v; } return cnt; } void shellSort(int a[], int n) { int i, cnt = 0, m; for (int h = 1;;) { if (h > n) break; g.push_back(h); h = 3 * h + 1; } m = g.size(); for (i = m - 1; i >= 0; i--) cnt = cnt + insertionSort(a, n, g[i]); cout << m << "\n"; for (i = m - 1; i > 0; i--) cout << g[i] << " "; cout << g[0] << "\n"; cout << cnt << "\n"; for (i = 0; i < n; i++) cout << a[i] << "\n"; } int main(void) { int i, n, a[ArrayNum]; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; shellSort(a, n); }
replace
5
6
5
6
0
p02262
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; long long cnt; int i, A[10000], n; vector<int> G; void insertionSort(int A[], int n, int g) { for (int i = g; i < n; i++) { int v = A[i]; int j = i - g; while (j >= 0 && A[j] > v) { A[j + g] = A[j]; j -= g; cnt++; } A[j + g] = v; } } void shellSort(int A[], int n) { for (int h = 1; h <= n; h = 3 * h + 1) G.push_back(h); for (int i = G.size() - 1; i >= 0; i--) insertionSort(A, n, G[i]); } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> A[i]; cnt = 0; shellSort(A, n); cout << G.size() << endl; for (int i = G.size() - 1; i > 0; i--) cout << G[i] << ' '; cout << G[0] << endl; cout << cnt << endl; for (int i = 0; i < n; i++) cout << A[i] << endl; return 0; }
#include <iostream> #include <vector> using namespace std; long long cnt; int i, A[1000000], n; vector<int> G; void insertionSort(int A[], int n, int g) { for (int i = g; i < n; i++) { int v = A[i]; int j = i - g; while (j >= 0 && A[j] > v) { A[j + g] = A[j]; j -= g; cnt++; } A[j + g] = v; } } void shellSort(int A[], int n) { for (int h = 1; h <= n; h = 3 * h + 1) G.push_back(h); for (int i = G.size() - 1; i >= 0; i--) insertionSort(A, n, G[i]); } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> A[i]; cnt = 0; shellSort(A, n); cout << G.size() << endl; for (int i = G.size() - 1; i > 0; i--) cout << G[i] << ' '; cout << G[0] << endl; cout << cnt << endl; for (int i = 0; i < n; i++) cout << A[i] << endl; return 0; }
replace
6
7
6
7
0
p02262
C++
Runtime Error
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { long n = 0, g = 0, v = 0, cnt = 0, m = 0; cin >> n; vector<long> a(n); for (long i = 0; i < n; i++) cin >> a[i]; cnt = 0; if (n == 1) m = 1; else m = (int)(log(n) / log(3)); vector<long> G(m); for (long k = 0; k < m; k++) { G[k] = ((long)pow(3, m - k) - 1) / 2; g = G[k]; for (long i = g; i < n; i++) { long j = 0; v = a[i]; j = i - g; while (j >= 0 && a[j] > v) { a[j + g] = a[j]; j = j - g; cnt++; } a[j + g] = v; } } cout << m << endl; for (long i = 0; i < m - 1; i++) cout << G[i] << " "; cout << G[m - 1] << endl; cout << cnt << endl; for (long i = 0; i < n; i++) cout << a[i] << endl; return 0; }
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { long n = 0, g = 0, v = 0, cnt = 0, m = 0; cin >> n; vector<long> a(n); for (long i = 0; i < n; i++) cin >> a[i]; cnt = 0; if (n < 3) m = 1; else m = (int)(log(n) / log(3)); vector<long> G(m); for (long k = 0; k < m; k++) { G[k] = ((long)pow(3, m - k) - 1) / 2; g = G[k]; for (long i = g; i < n; i++) { long j = 0; v = a[i]; j = i - g; while (j >= 0 && a[j] > v) { a[j + g] = a[j]; j = j - g; cnt++; } a[j + g] = v; } } cout << m << endl; for (long i = 0; i < m - 1; i++) cout << G[i] << " "; cout << G[m - 1] << endl; cout << cnt << endl; for (long i = 0; i < n; i++) cout << a[i] << endl; return 0; }
replace
16
17
16
17
0
p02262
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" // #include "libs.h" #include <random> #include <unordered_map> #include <unordered_set> // #include <opencv2/core.hpp> // #include <opencv2/highgui.hpp> // #include <opencv2/imgproc.hpp> using namespace std; // 呪文 #define DUMPOUT cerr #define dump(...) \ DUMPOUT << " "; \ DUMPOUT << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" \ << endl; \ DUMPOUT << " "; \ dump_func(__VA_ARGS__) typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef pair<string, string> pss; template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const pair<_KTy, _Ty> &m) { o << "{" << m.first << ", " << m.second << "}"; return o; } template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const map<_KTy, _Ty> &m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const unordered_map<_KTy, _Ty> &m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const vector<_Ty> &v) { if (v.empty()) { o << "{ }"; return o; } o << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const set<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const unordered_set<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const stack<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } stack<_Ty> t(s); o << "{" << t.top(); t.pop(); while (!t.empty()) { o << ", " << t.top(); t.pop(); } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const list<_Ty> &l) { if (l.empty()) { o << "{ }"; return o; } o << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { o << ", " << *itr; } o << "}"; return o; } template <typename _KTy, typename _Ty> istream &operator>>(istream &is, pair<_KTy, _Ty> &m) { is >> m.first >> m.second; return is; } template <typename _Ty> istream &operator>>(istream &is, vector<_Ty> &v) { for (size_t i = 0; i < v.size(); i++) is >> v[i]; return is; } namespace aux { // print tuple template <typename Ty, unsigned N, unsigned L> struct tp { static void print(ostream &os, const Ty &v) { os << get<N>(v) << ", "; tp<Ty, N + 1, L>::print(os, v); } }; template <typename Ty, unsigned N> struct tp<Ty, N, N> { static void print(ostream &os, const Ty &v) { os << get<N>(v); } }; } // namespace aux template <typename... Tys> ostream &operator<<(ostream &os, const tuple<Tys...> &t) { os << "{"; aux::tp<tuple<Tys...>, 0, sizeof...(Tys) - 1>::print(os, t); os << "}"; return os; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #define PI 3.14159265358979323846 #define EPS 1e-10 #define FOR(is, a, n) for (int is = (a); is < (n); ++is) #define REP(is, n) FOR(is, 0, n) #define all(j) (j).begin(), (j).end() #define SZ(j) ((int)(j).size()) #define fake false template <typename T> void printVec(const vector<T> &v, char delim = ' ', ostream &os = cout) { os << v[0]; for (int i = 1; i < v.size(); i++) os << delim << v[i]; os << endl; } template <typename T> size_t insertionSort(vector<T> &A, int g = 1, bool verbose = false) { if (verbose) printVec(A); int N = (int)A.size(); size_t cnt = 0; for (int i = g; i <= N - 1; i++) { T v = A[i]; int j; for (j = i - g; j >= 0 && v < A[j]; j -= g) { A[j + g] = A[j]; cnt++; } A[j + g] = v; if (verbose) printVec(A); } return cnt; } template <typename T> size_t shellSort(vector<T> &A, bool verbose = false) { int N = (int)A.size(); size_t cnt = 0; vector<int> G; int g = 1; while (g < N) { G.push_back(g); g = 3 * g + 1; } reverse(G.begin(), G.end()); int m = (int)G.size(); for (int i = 0; i < m; i++) cnt += insertionSort(A, G[i], false); if (verbose) { cout << m << endl; printVec(G); cout << cnt << endl; printVec(A, '\n'); } return cnt; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); cin >> A; shellSort(A, true); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" // #include "libs.h" #include <random> #include <unordered_map> #include <unordered_set> // #include <opencv2/core.hpp> // #include <opencv2/highgui.hpp> // #include <opencv2/imgproc.hpp> using namespace std; // 呪文 #define DUMPOUT cerr #define dump(...) \ DUMPOUT << " "; \ DUMPOUT << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" \ << endl; \ DUMPOUT << " "; \ dump_func(__VA_ARGS__) typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef pair<string, string> pss; template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const pair<_KTy, _Ty> &m) { o << "{" << m.first << ", " << m.second << "}"; return o; } template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const map<_KTy, _Ty> &m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _KTy, typename _Ty> ostream &operator<<(ostream &o, const unordered_map<_KTy, _Ty> &m) { if (m.empty()) { o << "{ }"; return o; } o << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const vector<_Ty> &v) { if (v.empty()) { o << "{ }"; return o; } o << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const set<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const unordered_set<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } o << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { o << ", " << *itr; } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const stack<_Ty> &s) { if (s.empty()) { o << "{ }"; return o; } stack<_Ty> t(s); o << "{" << t.top(); t.pop(); while (!t.empty()) { o << ", " << t.top(); t.pop(); } o << "}"; return o; } template <typename _Ty> ostream &operator<<(ostream &o, const list<_Ty> &l) { if (l.empty()) { o << "{ }"; return o; } o << "{" << l.front(); for (auto itr = ++l.begin(); itr != l.end(); ++itr) { o << ", " << *itr; } o << "}"; return o; } template <typename _KTy, typename _Ty> istream &operator>>(istream &is, pair<_KTy, _Ty> &m) { is >> m.first >> m.second; return is; } template <typename _Ty> istream &operator>>(istream &is, vector<_Ty> &v) { for (size_t i = 0; i < v.size(); i++) is >> v[i]; return is; } namespace aux { // print tuple template <typename Ty, unsigned N, unsigned L> struct tp { static void print(ostream &os, const Ty &v) { os << get<N>(v) << ", "; tp<Ty, N + 1, L>::print(os, v); } }; template <typename Ty, unsigned N> struct tp<Ty, N, N> { static void print(ostream &os, const Ty &v) { os << get<N>(v); } }; } // namespace aux template <typename... Tys> ostream &operator<<(ostream &os, const tuple<Tys...> &t) { os << "{"; aux::tp<tuple<Tys...>, 0, sizeof...(Tys) - 1>::print(os, t); os << "}"; return os; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } void dump_func() { DUMPOUT << endl; } template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #define PI 3.14159265358979323846 #define EPS 1e-10 #define FOR(is, a, n) for (int is = (a); is < (n); ++is) #define REP(is, n) FOR(is, 0, n) #define all(j) (j).begin(), (j).end() #define SZ(j) ((int)(j).size()) #define fake false template <typename T> void printVec(const vector<T> &v, char delim = ' ', ostream &os = cout) { os << v[0]; for (int i = 1; i < v.size(); i++) os << delim << v[i]; os << endl; } template <typename T> size_t insertionSort(vector<T> &A, int g = 1, bool verbose = false) { if (verbose) printVec(A); int N = (int)A.size(); size_t cnt = 0; for (int i = g; i <= N - 1; i++) { T v = A[i]; int j; for (j = i - g; j >= 0 && v < A[j]; j -= g) { A[j + g] = A[j]; cnt++; } A[j + g] = v; if (verbose) printVec(A); } return cnt; } template <typename T> size_t shellSort(vector<T> &A, bool verbose = false) { int N = (int)A.size(); size_t cnt = 0; vector<int> G; int g = 1; while (g <= N) { G.push_back(g); g = 3 * g + 1; } reverse(G.begin(), G.end()); int m = (int)G.size(); for (int i = 0; i < m; i++) cnt += insertionSort(A, G[i], false); if (verbose) { cout << m << endl; printVec(G); cout << cnt << endl; printVec(A, '\n'); } return cnt; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); cin >> A; shellSort(A, true); return 0; }
replace
211
212
211
212
0