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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p00494 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
string s;
int index = 0, ci = 0;
int ans = 0;
int c[200001];
int main() {
cin >> s;
while (index < s.length()) {
for (int i = 0; i < 3; i++) {
char ct;
if (i == 0)
ct = 'J';
else if (i == 1)
ct = 'O';
else if (i == 2)
ct = 'I';
int cnt;
for (cnt = 0; ct == s[index + cnt]; cnt++)
;
index += cnt;
c[ci] = cnt;
ci++;
}
}
// Oを探索
for (int i = 1; i < ci; i += 3) {
int oi = c[i];
int ji = c[i - 1];
int ii = c[i + 1];
if (oi > ji || oi > ii)
continue;
else if (ans < oi)
ans = oi;
}
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
string s;
int index = 0, ci = 0;
int ans = 0;
int c[2000000];
int main() {
cin >> s;
while (index < s.length()) {
for (int i = 0; i < 3; i++) {
char ct;
if (i == 0)
ct = 'J';
else if (i == 1)
ct = 'O';
else if (i == 2)
ct = 'I';
int cnt;
for (cnt = 0; ct == s[index + cnt]; cnt++)
;
index += cnt;
c[ci] = cnt;
ci++;
}
}
// Oを探索
for (int i = 1; i < ci; i += 3) {
int oi = c[i];
int ji = c[i - 1];
int ii = c[i + 1];
if (oi > ji || oi > ii)
continue;
else if (ans < oi)
ans = oi;
}
printf("%d\n", ans);
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p00494 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
char str[1000005];
int main() {
scanf("%s", &str);
int leng = strlen(str);
int ans = 0, i = 0;
for (;;) {
if (str[i] == 'J') {
int a = 0, b = 0, c = 0;
while (str[i] == 'J' && i < leng) {
i++;
a++;
}
while (str[i] == 'O' && i < leng) {
i++;
b++;
}
while (str[i] == 'I' && i < leng) {
i++;
c++;
}
if (b <= a && b <= c) {
ans = max(ans, b);
}
if (i == leng)
break;
} else {
i++;
}
}
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
char str[1000005];
int main() {
scanf("%s", &str);
int leng = strlen(str);
int ans = 0, i = 0;
for (;;) {
if (str[i] == 'J') {
int a = 0, b = 0, c = 0;
while (str[i] == 'J' && i < leng) {
i++;
a++;
}
while (str[i] == 'O' && i < leng) {
i++;
b++;
}
while (str[i] == 'I' && i < leng) {
i++;
c++;
}
if (b <= a && b <= c) {
ans = max(ans, b);
}
if (i == leng)
break;
} else {
i++;
if (i == leng)
break;
}
}
printf("%d\n", ans);
return 0;
} | insert | 33 | 33 | 33 | 35 | 0 | |
p00494 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
char a[1000000];
int b;
int g = 0;
struct JOI {
int J, O, I;
};
JOI c(int d) {
JOI e;
e.J = e.O = e.I = 0;
int f;
for (f = d; f < b; f++) {
if (a[f] != 'J')
break;
}
e.J = f - d;
d = f;
for (f = d; f < b; f++) {
if (a[f] != 'O')
break;
}
e.O = f - d;
d = f;
for (f = d; f < b; f++) {
if (a[f] != 'I')
break;
}
e.I = f - d;
return e;
}
int main() {
scanf("%s", a);
b = strlen(a);
int MAX = 0;
for (; g < b; g++) {
if (a[g] == 'J') {
JOI s = c(g);
if (s.O <= s.I && s.O <= s.J)
MAX = max(MAX, s.O);
}
}
cout << MAX << endl;
} | #include <bits/stdc++.h>
using namespace std;
char a[1000000];
int b;
int g = 0;
struct JOI {
int J, O, I;
};
JOI c(int d) {
JOI e;
e.J = e.O = e.I = 0;
int f;
for (f = d; f < b; f++) {
if (a[f] != 'J')
break;
}
e.J = f - d;
d = f;
for (f = d; f < b; f++) {
if (a[f] != 'O')
break;
}
e.O = f - d;
d = f;
for (f = d; f < b; f++) {
if (a[f] != 'I')
break;
}
e.I = f - d;
g = f - 1;
return e;
}
int main() {
scanf("%s", a);
b = strlen(a);
int MAX = 0;
for (; g < b; g++) {
if (a[g] == 'J') {
JOI s = c(g);
if (s.O <= s.I && s.O <= s.J)
MAX = max(MAX, s.O);
}
}
cout << MAX << endl;
} | insert | 30 | 30 | 30 | 31 | TLE | |
p00494 | C++ | Time Limit Exceeded |
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;
char s[1234567];
vector<pair<char, int>> ss;
int main() {
scanf("%s", s);
int lastsame = 1;
char thlett = s[0];
for (int i = 1; i < strlen(s); ++i) {
if (thlett != s[i]) {
ss.push_back(make_pair(thlett, lastsame));
thlett = s[i];
lastsame = 1;
} else {
++lastsame;
}
}
ss.push_back(make_pair(thlett, lastsame));
if (ss.size() < 3)
return 0 * printf("0\n");
int ans = 0;
for (int j = 0; j < ss.size() - 2; ++j) {
if (ss[j].first == 'J' && ss[j + 1].first == 'O' &&
ss[j + 2].first == 'I') {
if (ss[j + 1].second <= min(ss[j].second, ss[j + 2].second)) {
ans = max(ans, ss[j + 1].second);
}
}
}
printf("%d\n", ans);
return 0;
} |
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;
char s[1234567];
vector<pair<char, int>> ss;
int main() {
scanf("%s", s);
int lastsame = 1;
char thlett = s[0];
int n = strlen(s);
for (int i = 1; i < n; ++i) {
if (thlett != s[i]) {
ss.push_back(make_pair(thlett, lastsame));
thlett = s[i];
lastsame = 1;
} else {
++lastsame;
}
}
ss.push_back(make_pair(thlett, lastsame));
if (ss.size() < 3)
return 0 * printf("0\n");
int ans = 0;
for (int j = 0; j < ss.size() - 2; ++j) {
if (ss[j].first == 'J' && ss[j + 1].first == 'O' &&
ss[j + 2].first == 'I') {
if (ss[j + 1].second <= min(ss[j].second, ss[j + 2].second)) {
ans = max(ans, ss[j + 1].second);
}
}
}
printf("%d\n", ans);
return 0;
} | replace | 16 | 17 | 16 | 18 | TLE | |
p00494 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define loop(i, a, b) for (int i = a; i < int(b); i++)
#define rep(i, b) loop(i, 0, b)
char s[100010];
int l[100010];
int main() {
scanf("%s", s);
int n = strlen(s);
l[0] = 1;
rep(i, n - 1) {
if (s[i + 1] == s[i])
l[i + 1] = l[i] + 1;
else
l[i + 1] = 1;
}
int ans = 0;
loop(i, 1, n - 1) {
if (s[i] == 'O' && s[i + 1] != 'O' && i + l[i] < n && i - l[i] >= 0 &&
l[i + l[i]] >= l[i] && l[i - l[i]] >= l[i] && s[i + l[i]] == 'I' &&
s[i - l[i]] == 'J') {
ans = max(ans, l[i]);
}
}
printf("%d\n", ans);
} | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define loop(i, a, b) for (int i = a; i < int(b); i++)
#define rep(i, b) loop(i, 0, b)
char s[1000100];
int l[1000100];
int main() {
scanf("%s", s);
int n = strlen(s);
l[0] = 1;
rep(i, n - 1) {
if (s[i + 1] == s[i])
l[i + 1] = l[i] + 1;
else
l[i + 1] = 1;
}
int ans = 0;
loop(i, 1, n - 1) {
if (s[i] == 'O' && s[i + 1] != 'O' && i + l[i] < n && i - l[i] >= 0 &&
l[i + l[i]] >= l[i] && l[i - l[i]] >= l[i] && s[i + l[i]] == 'I' &&
s[i - l[i]] == 'J') {
ans = max(ans, l[i]);
}
}
printf("%d\n", ans);
} | replace | 7 | 9 | 7 | 9 | 0 | |
p00494 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int, int> iP;
int main() {
string s;
int kmax = 0;
cin >> s;
for (int i = 0; i < s.size(); i++) {
bool j1, j2;
int cnt = 0;
if (s[i] == 'O') {
j1 = false, j2 = false;
cnt = 1;
for (int j = i + 1; s[j] == 'O' && j < s.size(); j++)
cnt++;
for (int j = i - 1, c = 1; s[j] == 'J' && j >= 0; j--, c++) {
if (c == cnt) {
j1 = true;
break;
}
}
for (int j = i + cnt, c = 1; s[j] == 'I' && j < s.size(); j++, c++) {
if (c == cnt) {
j2 = true;
break;
}
}
}
if (j1 && j2)
kmax = max(kmax, cnt);
}
cout << kmax << endl;
} | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int, int> iP;
int main() {
string s;
int kmax = 0;
cin >> s;
for (int i = 0; i < s.size(); i++) {
bool j1, j2;
int cnt = 0;
if (s[i] == 'O') {
j1 = false, j2 = false;
cnt = 1;
for (int j = i + 1; s[j] == 'O' && j < s.size(); j++)
cnt++;
for (int j = i - 1, c = 1; s[j] == 'J' && j >= 0; j--, c++) {
if (c == cnt) {
j1 = true;
break;
}
}
for (int j = i + cnt, c = 1; s[j] == 'I' && j < s.size(); j++, c++) {
if (c == cnt) {
j2 = true;
break;
}
}
}
if (j1 && j2)
kmax = max(kmax, cnt);
i += cnt;
}
cout << kmax << endl;
} | insert | 54 | 54 | 54 | 55 | TLE | |
p00494 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge {
int from, to, cost;
bool operator<(const edge &e) const { return cost < e.cost; }
bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
string s;
vector<pair<char, int>> v;
int main() {
cin >> s;
if (s.size() < 3) {
cout << 0 << endl;
return 0;
}
int i = 0;
char c = s[0];
int cnt = 0;
while (i < s.size()) {
if (s[i] == c) {
cnt++;
} else {
v.push_back(make_pair(c, cnt));
cnt = 1;
c = s[i];
}
i++;
}
v.push_back(make_pair(c, cnt));
int ans = 0;
REP(i, v.size() - 2) {
if (v[i].first == 'J' && v[i + 1].first == 'O' && v[i + 2].first == 'I') {
if (v[i + 1].second <= v[i].second && v[i + 1].second <= v[i + 2].second)
ans = max(ans, v[i + 1].second);
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge {
int from, to, cost;
bool operator<(const edge &e) const { return cost < e.cost; }
bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
string s;
vector<pair<char, int>> v;
int main() {
cin >> s;
if (s.size() < 3) {
cout << 0 << endl;
return 0;
}
int i = 0;
char c = s[0];
int cnt = 0;
while (i < s.size()) {
if (s[i] == c) {
cnt++;
} else {
v.push_back(make_pair(c, cnt));
cnt = 1;
c = s[i];
}
i++;
}
v.push_back(make_pair(c, cnt));
int ans = 0;
if (v.size() > 2) {
REP(i, v.size() - 2) {
if (v[i].first == 'J' && v[i + 1].first == 'O' && v[i + 2].first == 'I') {
if (v[i + 1].second <= v[i].second &&
v[i + 1].second <= v[i + 2].second)
ans = max(ans, v[i + 1].second);
}
}
}
cout << ans << endl;
return 0;
} | replace | 48 | 52 | 48 | 55 | 0 | |
p00494 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<char, int> P;
int main() {
vector<P> v;
string s;
cin >> s;
if (s.size() <= 2) {
puts("0");
return 0;
}
int cnt = 0;
char back = s[0];
for (char c : s) {
if (c == back)
cnt++;
else {
v.push_back(P(back, cnt));
cnt = 1;
back = c;
}
}
v.push_back(P(back, cnt));
int Max = 0;
rep(i, v.size() - 2) {
if (v[i].first == 'J' && v[i + 1].first == 'O' && v[i + 2].first == 'I' &&
v[i + 1].second <= v[i].second && v[i + 1].second <= v[i + 2].second) {
Max = max(Max, v[i + 1].second);
}
}
cout << Max << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<char, int> P;
int main() {
vector<P> v;
string s;
cin >> s;
if (s.size() <= 2) {
puts("0");
return 0;
}
int cnt = 0;
char back = s[0];
for (char c : s) {
if (c == back)
cnt++;
else {
v.push_back(P(back, cnt));
cnt = 1;
back = c;
}
}
v.push_back(P(back, cnt));
int Max = 0;
if (v.size() <= 2) {
puts("0");
return 0;
}
rep(i, v.size() - 2) {
if (v[i].first == 'J' && v[i + 1].first == 'O' && v[i + 2].first == 'I' &&
v[i + 1].second <= v[i].second && v[i + 1].second <= v[i + 2].second) {
Max = max(Max, v[i + 1].second);
}
}
cout << Max << endl;
return 0;
} | insert | 27 | 27 | 27 | 31 | 0 | |
p00494 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
char c[1000000];
int main() {
int o, flag, ma = 0;
scanf("%s", c);
for (int i = 1; i < strlen(c) - 1; i++) {
if (c[i] == 'O') {
o = 1;
for (int j = i + 1; j < strlen(c) - 1; j++) {
if (c[j] == 'O')
o++;
else
break;
}
flag = 0;
for (int j = 1; j <= o; j++) {
if (!(c[i - j] == 'J' && c[i + o - 1 + j] == 'I')) {
flag++;
break;
}
}
if (flag == 0) {
ma = max(ma, o);
}
}
}
printf("%d\n", ma);
return (0);
} | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
char c[1000000];
int main() {
int o, flag, ma = 0;
scanf("%s", c);
for (int i = 1; i < strlen(c) - 1; i++) {
if (c[i] == 'O') {
o = 1;
for (int j = i + 1; j < strlen(c) - 1; j++) {
if (c[j] == 'O')
o++;
else
break;
}
flag = 0;
for (int j = 1; j <= o; j++) {
if (!(c[i - j] == 'J' && c[i + o - 1 + j] == 'I')) {
flag++;
break;
}
}
if (flag == 0) {
ma = max(ma, o);
}
i += o - 1;
}
}
printf("%d\n", ma);
return (0);
} | insert | 29 | 29 | 29 | 30 | TLE | |
p00494 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define mp(a, b) make_pair((a), (b))
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif
typedef long long int ll;
typedef pair<int, int> pii;
// template<typename T> using vec=std::vector<T>;
const int INF = 1 << 30;
const long long int INF_ = 1LL << 58;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
struct Type {
char ch;
int len;
};
void Solve() {
string s;
cin >> s;
vector<Type> cmp;
char ch = s[0];
int cnt = 1;
rep(i, 1, s.size()) {
if (s[i] != ch) {
cmp.push_back(Type{ch, cnt});
ch = s[i];
cnt = 1;
} else
++cnt;
}
cmp.push_back(Type{ch, cnt});
int ans = 0;
rep(i, 0, cmp.size() - 2) {
if (cmp[i].ch == 'J' && cmp[i + 1].ch == 'O' && cmp[i + 2].ch == 'I' &&
cmp[i].len >= cmp[i + 1].len && cmp[i + 1].len <= cmp[i + 2].len)
ans = max(ans, cmp[i + 1].len);
}
cout << ans << endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
Solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define mp(a, b) make_pair((a), (b))
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif
typedef long long int ll;
typedef pair<int, int> pii;
// template<typename T> using vec=std::vector<T>;
const int INF = 1 << 30;
const long long int INF_ = 1LL << 58;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
struct Type {
char ch;
int len;
};
void Solve() {
string s;
cin >> s;
vector<Type> cmp;
char ch = s[0];
int cnt = 1;
rep(i, 1, s.size()) {
if (s[i] != ch) {
cmp.push_back(Type{ch, cnt});
ch = s[i];
cnt = 1;
} else
++cnt;
}
cmp.push_back(Type{ch, cnt});
int ans = 0;
rep(i, 0, (int)cmp.size() - 2) {
if (cmp[i].ch == 'J' && cmp[i + 1].ch == 'O' && cmp[i + 2].ch == 'I' &&
cmp[i].len >= cmp[i + 1].len && cmp[i + 1].len <= cmp[i + 2].len)
ans = max(ans, cmp[i + 1].len);
}
cout << ans << endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
Solve();
return 0;
} | replace | 55 | 56 | 55 | 56 | 0 | |
p00495 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
vector<int> an(a), br(b);
for (auto &i : an)
cin >> i;
for (auto &i : br)
cin >> i;
vector<vector<int>> dp(a + 1, vector<int>(b + 1));
int res = 0;
for (auto i = 0; i < b; i++) {
int use = 0;
for (auto &j : an) {
if (j == br[use + i])
use++;
if (use == b)
break;
}
res = max(res, use);
}
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
vector<int> an(a), br(b);
for (auto &i : an)
cin >> i;
for (auto &i : br)
cin >> i;
int res = 0;
for (auto i = 0; i < b; i++) {
int use = 0;
for (auto &j : an) {
if (j == br[use + i])
use++;
if (use == b)
break;
}
res = max(res, use);
}
cout << res << endl;
} | delete | 11 | 12 | 11 | 11 | MLE | |
p00495 | C++ | Runtime Error | #include <cstdio>
#include <cstdlib>
using namespace std;
int field[2][5001] = {0};
int main(void) {
int current = 1;
int n_a, n_b;
scanf("%d%d", &n_a, &n_b);
int a[5001];
for (int i = 1; i <= n_a; i++)
scanf("%d", &a[i]);
int b[5001];
for (int i = 1; i <= n_b; i++)
scanf("%d", &b[i]);
for (int i = 1; i <= n_a; i++) {
for (int j = 1; j <= n_b; j++) {
field[current][j] = field[abs(current - 1)][j];
if (a[i] == b[j] &&
field[current][j] <= field[abs(current - 1)][j - 1] + 1)
field[current][j] = field[abs(current - 1)][j - 1] + 1;
}
current = 1 - current;
}
int max = 0;
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= n_b; j++) {
if (max <= field[i][j])
max = field[i][j];
}
}
printf("%d\n", max);
return 0;
} | #include <cstdio>
#include <cstdlib>
using namespace std;
int field[2][5001] = {0};
int main(void) {
int current = 1;
int n_a, n_b;
scanf("%d%d", &n_a, &n_b);
int a[5001];
for (int i = 1; i <= n_a; i++)
scanf("%d", &a[i]);
int b[5001];
for (int i = 1; i <= n_b; i++)
scanf("%d", &b[i]);
for (int i = 1; i <= n_a; i++) {
for (int j = 1; j <= n_b; j++) {
field[current][j] = field[abs(current - 1)][j];
if (a[i] == b[j] &&
field[current][j] <= field[abs(current - 1)][j - 1] + 1)
field[current][j] = field[abs(current - 1)][j - 1] + 1;
}
current = 1 - current;
}
int max = 0;
for (int i = 0; i <= 1; i++) {
for (int j = 1; j <= n_b; j++) {
if (max <= field[i][j])
max = field[i][j];
}
}
printf("%d\n", max);
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p00495 | C++ | Memory Limit Exceeded | #include <cstdio>
#include <cstring>
#define rep(i, n) for (int i = 1; i <= (n); i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
int dat[5005][2];
int dp[5005][5005];
int A, B;
int main(void) {
scanf("%d%d", &A, &B);
rep(i, A) scanf("%d", &(dat[i][0]));
rep(i, B) scanf("%d", &(dat[i][1]));
rep(i, A) {
rep(j, B) {
dp[i][j] = max(dp[i - 1][j],
((dat[i][0] == dat[j][1]) ? (dp[i - 1][j - 1] + 1) : 0));
// printf("%d %d %d\n",i,j,dp[i][j]);
}
}
int ans = 0;
rep(i, B) ans = max(ans, dp[A][i]);
printf("%d\n", ans);
return 0;
} | #include <cstdio>
#include <cstring>
#define rep(i, n) for (int i = 1; i <= (n); i++)
#define max(a, b) (((a) > (b)) ? (a) : (b))
int dat[5005][2];
short int dp[5005][5005];
int A, B;
int main(void) {
scanf("%d%d", &A, &B);
rep(i, A) scanf("%d", &(dat[i][0]));
rep(i, B) scanf("%d", &(dat[i][1]));
rep(i, A) {
rep(j, B) {
dp[i][j] = max(dp[i - 1][j],
((dat[i][0] == dat[j][1]) ? (dp[i - 1][j - 1] + 1) : 0));
// printf("%d %d %d\n",i,j,dp[i][j]);
}
}
int ans = 0;
rep(i, B) ans = max(ans, dp[A][i]);
printf("%d\n", ans);
return 0;
} | replace | 6 | 7 | 6 | 7 | MLE | |
p00495 | C++ | Memory Limit Exceeded | #include <stdio.h>
int dp[5001][5001];
int a[5000];
int b[5000];
int max(int a, int b) { return a > b ? a : b; }
int main() {
int n, m;
scanf("%d %d", &n, &m);
int i, j;
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < m; i++)
scanf("%d", &b[i]);
for (i = 0; i <= n; i++)
for (j = 0; j <= m; j++)
dp[i][j] = 0;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
dp[i][j] = dp[i - 1][j];
if (a[i - 1] == b[j - 1])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
int ans = 0;
for (i = 0; i <= m; i++)
ans = max(ans, dp[n][i]);
printf("%d\n", ans);
return 0;
} | #include <stdio.h>
short dp[5001][5001];
int a[5000];
int b[5000];
int max(int a, int b) { return a > b ? a : b; }
int main() {
int n, m;
scanf("%d %d", &n, &m);
int i, j;
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < m; i++)
scanf("%d", &b[i]);
for (i = 0; i <= n; i++)
for (j = 0; j <= m; j++)
dp[i][j] = 0;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
dp[i][j] = dp[i - 1][j];
if (a[i - 1] == b[j - 1])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
int ans = 0;
for (i = 0; i <= m; i++)
ans = max(ans, dp[n][i]);
printf("%d\n", ans);
return 0;
} | replace | 1 | 2 | 1 | 2 | MLE | |
p00495 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int m, n, a[5000], b[5000];
int dp[5000][5000];
int dfs(int i, int j) {
if (i == m || j == n)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
if (a[i] == b[j])
return dp[i][j] = dfs(i + 1, j + 1) + 1;
else
return dp[i][j] = dfs(i + 1, j);
}
int main() {
scanf("%d%d", &m, &n);
rep(i, m) scanf("%d", a + i);
rep(j, n) scanf("%d", b + j);
memset(dp, -1, sizeof dp);
int ans = 0;
rep(j, n) ans = max(ans, dfs(0, j));
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int m, n, a[5000], b[5000];
short dp[5000][5000];
int dfs(int i, int j) {
if (i == m || j == n)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
if (a[i] == b[j])
return dp[i][j] = dfs(i + 1, j + 1) + 1;
else
return dp[i][j] = dfs(i + 1, j);
}
int main() {
scanf("%d%d", &m, &n);
rep(i, m) scanf("%d", a + i);
rep(j, n) scanf("%d", b + j);
memset(dp, -1, sizeof dp);
int ans = 0;
rep(j, n) ans = max(ans, dfs(0, j));
printf("%d\n", ans);
return 0;
} | replace | 10 | 11 | 10 | 11 | MLE | |
p00496 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <chrono> //1e+9??§?????? auto end= chrono::system_clock::now()-st; cout<<end.count()%1e+9<<endl;
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double db;
#define fr first
#define sc second
#define pb push_back
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep1(i, x) for (ll i = 1; i <= x; i++)
#define rrep(i, x) for (ll i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (ll i = x; i > 0; i--)
ll N, S, T;
ll V[3001], C[3001];
ll dp1[3002][3001]; // i?????§???j????????\??????????\???????
ll dp2[3002][3001];
int main() {
cin >> N >> T >> S;
T -= S;
rep1(i, N) { cin >> V[i] >> C[i]; }
rep1(i, N) {
for (ll j = 0; j <= S; j++) {
if (j - C[i] >= 0) {
dp1[i][j] = max(dp1[i - 1][j], dp1[i - 1][j - C[i]] + V[i]);
} else
dp1[i][j] = dp1[i - 1][j];
}
}
rrep1(i, N) {
for (ll j = 0; j <= T; j++) {
if (j - C[i] >= 0) {
dp2[i][j] = max(dp2[i + 1][j], dp2[i + 1][j - C[i]] + V[i]);
} else
dp2[i][j] = dp2[i + 1][j];
}
}
ll ans = 0;
for (ll i = 0; i <= N; i++) {
ans = max(ans, dp1[i][S] + dp2[i + 1][T]);
}
cout << ans << endl;
} | #include <algorithm>
#include <chrono> //1e+9??§?????? auto end= chrono::system_clock::now()-st; cout<<end.count()%1e+9<<endl;
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef int ll;
typedef pair<ll, ll> P;
typedef long double db;
#define fr first
#define sc second
#define pb push_back
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep1(i, x) for (ll i = 1; i <= x; i++)
#define rrep(i, x) for (ll i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (ll i = x; i > 0; i--)
ll N, S, T;
ll V[3001], C[3001];
ll dp1[3002][3001]; // i?????§???j????????\??????????\???????
ll dp2[3002][3001];
int main() {
cin >> N >> T >> S;
T -= S;
rep1(i, N) { cin >> V[i] >> C[i]; }
rep1(i, N) {
for (ll j = 0; j <= S; j++) {
if (j - C[i] >= 0) {
dp1[i][j] = max(dp1[i - 1][j], dp1[i - 1][j - C[i]] + V[i]);
} else
dp1[i][j] = dp1[i - 1][j];
}
}
rrep1(i, N) {
for (ll j = 0; j <= T; j++) {
if (j - C[i] >= 0) {
dp2[i][j] = max(dp2[i + 1][j], dp2[i + 1][j - C[i]] + V[i]);
} else
dp2[i][j] = dp2[i + 1][j];
}
}
ll ans = 0;
for (ll i = 0; i <= N; i++) {
ans = max(ans, dp1[i][S] + dp2[i + 1][T]);
}
cout << ans << endl;
} | replace | 12 | 13 | 12 | 13 | MLE | |
p00496 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
#define int long long
#define PB push_back
#define MP make_pair
#define F first
#define S second
using namespace std;
int n, t, s, a[3010], b[3010];
int dp[3010][3010];
signed main() {
cin >> n >> t >> s;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= t; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (0 <= i - b[j] && i <= s || s <= i - b[j]) {
dp[i][j] = max(dp[i][j], dp[i - b[j]][j - 1] + a[j]);
}
}
}
cout << dp[t][n] << endl;
return 0;
} | #include <bits/stdc++.h>
// #define int long long
#define PB push_back
#define MP make_pair
#define F first
#define S second
using namespace std;
int n, t, s, a[3010], b[3010];
int dp[3010][3010];
signed main() {
cin >> n >> t >> s;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= t; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (0 <= i - b[j] && i <= s || s <= i - b[j]) {
dp[i][j] = max(dp[i][j], dp[i - b[j]][j - 1] + a[j]);
}
}
}
cout << dp[t][n] << endl;
return 0;
} | replace | 1 | 2 | 1 | 2 | MLE | |
p00496 | C++ | Memory Limit Exceeded |
#include <algorithm>
#include <iostream>
using namespace std;
int mem[10000][10000], A[10000], B[10000], N, T, S;
int main() {
int ans = 0;
cin >> N >> T >> S;
for (int i = 1; i <= N; i++)
cin >> A[i] >> B[i];
for (int n = 1; n <= N; n++) {
for (int t = 1; t <= T; t++) {
mem[n][t] = max(mem[n - 1][t], mem[n][t - 1]);
if (!(t - B[n] < S && t > S) && t >= B[n])
mem[n][t] = max(mem[n - 1][t - B[n]] + A[n], mem[n][t]);
}
}
cout << mem[N][T] << endl;
} |
#include <algorithm>
#include <iostream>
using namespace std;
int mem[5000][5000], A[5000], B[5000], N, T, S;
int main() {
int ans = 0;
cin >> N >> T >> S;
for (int i = 1; i <= N; i++)
cin >> A[i] >> B[i];
for (int n = 1; n <= N; n++) {
for (int t = 1; t <= T; t++) {
mem[n][t] = max(mem[n - 1][t], mem[n][t - 1]);
if (!(t - B[n] < S && t > S) && t >= B[n])
mem[n][t] = max(mem[n - 1][t - B[n]] + A[n], mem[n][t]);
}
}
cout << mem[N][T] << endl;
} | replace | 5 | 6 | 5 | 6 | MLE | |
p00496 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define rep(i, j) for (int i = 0; i < (j); i++)
int N, T, S;
int A[4096], B[4096];
int dp[4096][4096];
int dfs(int n, int t) {
if (n >= N)
return 0;
if (t > T)
return 0;
int &res = dp[n][t];
if (res >= 0)
return res;
res = 0;
if (t + B[n] <= T && (S <= t || t + B[n] <= S))
res = max(res, dfs(n + 1, t + B[n]) + A[n]);
else if (t + B[n] <= T && (t < S && S < t + B[n]) && S + B[n] <= T)
res = max(res, dfs(n + 1, S + B[n]) + A[n]);
res = max(res, dfs(n + 1, t));
return res;
}
int main() {
scanf("%d%d%d", &N, &T, &S);
rep(i, N) scanf("%d%d", &A[i], &B[i]);
memset(dp, -1, sizeof(dp));
printf("%d\n", dfs(0, 0));
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define rep(i, j) for (int i = 0; i < (j); i++)
int N, T, S;
int A[3001], B[3001];
int dp[3001][3001];
int dfs(int n, int t) {
if (n >= N)
return 0;
if (t > T)
return 0;
int &res = dp[n][t];
if (res >= 0)
return res;
res = 0;
if (t + B[n] <= T && (S <= t || t + B[n] <= S))
res = max(res, dfs(n + 1, t + B[n]) + A[n]);
else if (t + B[n] <= T && (t < S && S < t + B[n]) && S + B[n] <= T)
res = max(res, dfs(n + 1, S + B[n]) + A[n]);
res = max(res, dfs(n + 1, t));
return res;
}
int main() {
scanf("%d%d%d", &N, &T, &S);
rep(i, N) scanf("%d%d", &A[i], &B[i]);
memset(dp, -1, sizeof(dp));
printf("%d\n", dfs(0, 0));
} | replace | 10 | 12 | 10 | 12 | MLE | |
p00496 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16>>(x);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define if_range(x, y, w, h) \
if (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && \
(int)(y) < (int)(h))
const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
using namespace std;
// typedef pair<int, int> P;
/** Problem0573 : Night Market **/
vector<int> A, B;
int N, T, S;
int dp[3000][3000];
int solve(int time, int market) {
if (time > T || market > N)
return 0;
if (dp[time][market] >= 0)
return dp[time][market];
// 遊ばない
int res = solve(time, market + 1);
// 遊ぶ
if (time <= S) {
if (time + B[market] <= S)
res = max(res, A[market] + solve(time + B[market], market + 1));
else if (S + B[market] <= T)
res = max(res, A[market] + solve(S + B[market], market + 1));
} else {
if (time + B[market] <= T)
res = max(res, A[market] + solve(time + B[market], market + 1));
}
return dp[time][market] = res;
}
int main() {
cin >> N >> T >> S;
A.resize(N);
B.resize(N);
memset(dp, -1, sizeof(dp));
rep(i, N) { cin >> A[i] >> B[i]; }
cout << solve(0, 0) << endl;
} | #include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16>>(x);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
#define if_range(x, y, w, h) \
if (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && \
(int)(y) < (int)(h))
const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
using namespace std;
// typedef pair<int, int> P;
/** Problem0573 : Night Market **/
vector<int> A, B;
int N, T, S;
int dp[3001][3001];
int solve(int time, int market) {
if (time > T || market > N)
return 0;
if (dp[time][market] >= 0)
return dp[time][market];
// 遊ばない
int res = solve(time, market + 1);
// 遊ぶ
if (time <= S) {
if (time + B[market] <= S)
res = max(res, A[market] + solve(time + B[market], market + 1));
else if (S + B[market] <= T)
res = max(res, A[market] + solve(S + B[market], market + 1));
} else {
if (time + B[market] <= T)
res = max(res, A[market] + solve(time + B[market], market + 1));
}
return dp[time][market] = res;
}
int main() {
cin >> N >> T >> S;
A.resize(N);
B.resize(N);
memset(dp, -1, sizeof(dp));
rep(i, N) { cin >> A[i] >> B[i]; }
cout << solve(0, 0) << endl;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p00496 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define mp(a, b) make_pair((a), (b))
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif
typedef long long int ll;
typedef pair<int, int> pii;
// template<typename T> using vec=std::vector<T>;
const int INF = 1 << 30;
const long long int INF_ = 1LL << 58;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
void Solve() {
int n, t, s;
cin >> n >> t >> s;
vector<int> a(n), b(n);
rep(i, 0, n) cin >> a[i] >> b[i];
static ll dp[3000][3001];
ll ans = 0;
rep(i, 0, n) {
rep(j, 0, t + 1) {
if (i != 0)
dp[i][j] = dp[i - 1][j];
if (j - b[i] >= 0 && !(j - b[i] < s && s < j)) {
if (i != 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + a[i]);
else
dp[i][j] = a[i];
}
ans = max(ans, dp[i][j]);
}
}
cout << ans << endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
Solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define mp(a, b) make_pair((a), (b))
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif
typedef long long int ll;
typedef pair<int, int> pii;
// template<typename T> using vec=std::vector<T>;
const int INF = 1 << 30;
const long long int INF_ = 1LL << 58;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
void Solve() {
int n, t, s;
cin >> n >> t >> s;
vector<int> a(n), b(n);
rep(i, 0, n) cin >> a[i] >> b[i];
static int dp[3000][3001];
int ans = 0;
rep(i, 0, n) {
rep(j, 0, t + 1) {
if (i != 0)
dp[i][j] = dp[i - 1][j];
if (j - b[i] >= 0 && !(j - b[i] < s && s < j)) {
if (i != 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + a[i]);
else
dp[i][j] = a[i];
}
ans = max(ans, dp[i][j]);
}
}
cout << ans << endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
Solve();
return 0;
} | replace | 39 | 41 | 39 | 41 | MLE | |
p00497 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
short flag[5000][5000];
int main() {
int N, M;
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++) {
int A, B, C;
scanf("%d %d %d", &A, &B, &C);
flag[A][B] = max<short>(flag[A][B], C + 1);
}
int ret = 0;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= i; j++) {
flag[i][j] =
max<short>(flag[i][j], max(flag[i - 1][j - 1], flag[i - 1][j]) - 1);
if (flag[i][j] > 0)
ret++;
}
}
cout << ret << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
short flag[5005][5005];
int main() {
int N, M;
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++) {
int A, B, C;
scanf("%d %d %d", &A, &B, &C);
flag[A][B] = max<short>(flag[A][B], C + 1);
}
int ret = 0;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= i; j++) {
flag[i][j] =
max<short>(flag[i][j], max(flag[i - 1][j - 1], flag[i - 1][j]) - 1);
if (flag[i][j] > 0)
ret++;
}
}
cout << ret << endl;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p00497 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
#define N 2020
vector<int> x[N];
int n, m, a, b, c, cnt;
int V[N];
int main() {
for (int i = 0; i < N; i++) {
for (int j = 0; j < i + 5; j++) {
x[i].push_back(0);
V[i] = j;
}
}
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b >> c;
c++;
x[a][b]++;
x[a + c][b]--;
x[a + c + 1][b + 1]++;
x[a][b + 1]--;
x[a + c][b + c + 1]++;
x[a + c + 1][b + c + 1]--;
}
for (int i = 0; i < N; i++) {
for (int j = 1; j < N; j++) {
if (j < V[i]) {
x[i][j] += x[i][j - 1];
}
}
}
for (int j = 0; j < N; j++) {
for (int i = 1; i < N; i++) {
if (j < V[i]) {
x[i][j] += x[i - 1][j];
}
}
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
if (j + 1 < V[i + j + 1]) {
x[i + j + 1][j + 1] += x[i + j][j];
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (j < V[i]) {
if (x[i][j] >= 1) {
cnt++;
}
}
}
}
cout << cnt << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
#define N 5100
vector<int> x[N];
int n, m, a, b, c, cnt;
int V[N];
int main() {
for (int i = 0; i < N; i++) {
for (int j = 0; j < i + 5; j++) {
x[i].push_back(0);
V[i] = j;
}
}
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b >> c;
c++;
x[a][b]++;
x[a + c][b]--;
x[a + c + 1][b + 1]++;
x[a][b + 1]--;
x[a + c][b + c + 1]++;
x[a + c + 1][b + c + 1]--;
}
for (int i = 0; i < N; i++) {
for (int j = 1; j < N; j++) {
if (j < V[i]) {
x[i][j] += x[i][j - 1];
}
}
}
for (int j = 0; j < N; j++) {
for (int i = 1; i < N; i++) {
if (j < V[i]) {
x[i][j] += x[i - 1][j];
}
}
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
if (j + 1 < V[i + j + 1]) {
x[i + j + 1][j + 1] += x[i + j][j];
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (j < V[i]) {
if (x[i][j] >= 1) {
cnt++;
}
}
}
}
cout << cnt << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p00497 | C++ | Runtime Error | #include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
//// < "D:\D_Download\Visual Studio
///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
///Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
int N;
cin >> N;
int M;
cin >> M;
vector<vector<pair<int, int>>> pluss(N, vector<pair<int, int>>(N + 1));
vector<vector<int>> aas(N, vector<int>(N + 1));
for (int i = 0; i < M; ++i) {
int a, b, x;
cin >> a >> b >> x;
a--;
b--;
pluss[a + x][b].first++;
pluss[a + x][b + x + 1].second++;
aas[a - 1][b]++;
}
for (int h = N - 1; h >= 0; --h) {
for (int w = 0; w <= h + 1; ++w) {
if (h != N - 1) {
pluss[h][w].first += pluss[h + 1][w].first;
pluss[h][w].second += pluss[h + 1][w + 1].second;
}
pluss[h][w].first -= aas[h][w];
pluss[h][w].second -= aas[h][w];
}
}
int ans = 0;
for (int h = N - 1; h >= 0; --h) {
int sum = 0;
for (int w = 0; w <= h; ++w) {
sum += pluss[h][w].first - pluss[h][w].second;
if (sum > 0)
ans++;
}
}
cout << ans << endl;
return 0;
} | #include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
//// < "D:\D_Download\Visual Studio
///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
///Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
int N;
cin >> N;
int M;
cin >> M;
vector<vector<pair<int, int>>> pluss(N, vector<pair<int, int>>(N + 1));
vector<vector<int>> aas(N, vector<int>(N + 1));
for (int i = 0; i < M; ++i) {
int a, b, x;
cin >> a >> b >> x;
a--;
b--;
pluss[a + x][b].first++;
pluss[a + x][b + x + 1].second++;
if (a) {
aas[a - 1][b]++;
}
}
for (int h = N - 1; h >= 0; --h) {
for (int w = 0; w <= h + 1; ++w) {
if (h != N - 1) {
pluss[h][w].first += pluss[h + 1][w].first;
pluss[h][w].second += pluss[h + 1][w + 1].second;
}
pluss[h][w].first -= aas[h][w];
pluss[h][w].second -= aas[h][w];
}
}
int ans = 0;
for (int h = N - 1; h >= 0; --h) {
int sum = 0;
for (int w = 0; w <= h; ++w) {
sum += pluss[h][w].first - pluss[h][w].second;
if (sum > 0)
ans++;
}
}
cout << ans << endl;
return 0;
} | replace | 27 | 28 | 27 | 31 | 0 | |
p00497 | C++ | Runtime Error |
#include <stdio.h>
#include <string.h>
int plate[5002][5002];
int n, m;
int main() {
memset(plate, 0, sizeof(plate));
scanf("%d %d", &n, &m);
for (int i = 0; i < m; ++i) {
int a, b, x;
scanf("%d %d %d", &a, &b, &x);
--a;
--b;
++plate[a][b];
--plate[a][b + 1];
--plate[a + x + 1][b];
++plate[a + x + 2][b + 1];
++plate[a + x + 1][b + x + 2];
--plate[a + x + 2][b + x + 2];
}
for (int i = 1; i <= n + 2; ++i) {
for (int j = 1; j <= n + 2; ++j) {
plate[i][j] += plate[i - 1][j - 1];
}
}
for (int i = 0; i <= n + 2; ++i) {
for (int j = 1; j <= n + 2; ++j) {
plate[i][j] += plate[i][j - 1];
}
}
for (int i = 1; i <= n + 2; ++i) {
for (int j = 0; j <= n + 2; ++j) {
plate[i][j] += plate[i - 1][j];
}
}
int ans = 0;
for (int i = 0; i <= n + 2; ++i) {
for (int j = 0; j <= n + 2; ++j) {
if (plate[i][j] > 0)
++ans;
}
}
printf("%d\n", ans);
return 0;
} |
#include <stdio.h>
#include <string.h>
int plate[5678][5678];
int n, m;
int main() {
memset(plate, 0, sizeof(plate));
scanf("%d %d", &n, &m);
for (int i = 0; i < m; ++i) {
int a, b, x;
scanf("%d %d %d", &a, &b, &x);
--a;
--b;
++plate[a][b];
--plate[a][b + 1];
--plate[a + x + 1][b];
++plate[a + x + 2][b + 1];
++plate[a + x + 1][b + x + 2];
--plate[a + x + 2][b + x + 2];
}
for (int i = 1; i <= n + 2; ++i) {
for (int j = 1; j <= n + 2; ++j) {
plate[i][j] += plate[i - 1][j - 1];
}
}
for (int i = 0; i <= n + 2; ++i) {
for (int j = 1; j <= n + 2; ++j) {
plate[i][j] += plate[i][j - 1];
}
}
for (int i = 1; i <= n + 2; ++i) {
for (int j = 0; j <= n + 2; ++j) {
plate[i][j] += plate[i - 1][j];
}
}
int ans = 0;
for (int i = 0; i <= n + 2; ++i) {
for (int j = 0; j <= n + 2; ++j) {
if (plate[i][j] > 0)
++ans;
}
}
printf("%d\n", ans);
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p00497 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
const double EPS = (1e-10);
typedef long long ll;
typedef pair<int, int> pii;
bool EQ(double a, double b) { return abs((a) - (b)) < EPS; }
void fast_stream() { std::ios_base::sync_with_stdio(0); }
short dp[5001][5001];
void dfs(int x, int y, int depth) {
if (dp[y][x] >= depth)
return;
dp[y][x] = depth;
if (depth == 0)
return;
int ny = y + 1;
int nx = x + 1;
dfs(nx, ny, depth - 1);
ny = y;
dfs(nx, ny, depth - 1);
}
void solve() {
memset(dp, -1, sizeof(dp));
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y, a;
cin >> x >> y >> a;
dp[x][y] = a;
// dfs(x,y,a);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], (short)(dp[i][j] - 1));
dp[i + 1][j] = max(dp[i + 1][j], (short)(dp[i][j] - 1));
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (dp[i][j] >= 0)
cnt++;
}
}
cout << cnt << endl;
}
int main() {
solve();
return 0;
} | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
const double EPS = (1e-10);
typedef long long ll;
typedef pair<int, int> pii;
bool EQ(double a, double b) { return abs((a) - (b)) < EPS; }
void fast_stream() { std::ios_base::sync_with_stdio(0); }
short dp[5002][5002];
void dfs(int x, int y, int depth) {
if (dp[y][x] >= depth)
return;
dp[y][x] = depth;
if (depth == 0)
return;
int ny = y + 1;
int nx = x + 1;
dfs(nx, ny, depth - 1);
ny = y;
dfs(nx, ny, depth - 1);
}
void solve() {
memset(dp, -1, sizeof(dp));
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y, a;
cin >> x >> y >> a;
dp[x][y] = a;
// dfs(x,y,a);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], (short)(dp[i][j] - 1));
dp[i + 1][j] = max(dp[i + 1][j], (short)(dp[i][j] - 1));
}
}
int cnt = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
if (dp[i][j] >= 0)
cnt++;
}
}
cout << cnt << endl;
}
int main() {
solve();
return 0;
} | replace | 25 | 26 | 25 | 26 | 0 | |
p00497 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <climits>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<int> plus_[5001], minus_[5001];
int main() {
int N, M, A, B, X;
cin >> N >> M;
for (int i = 0; i <= N; i++) {
plus_[i].assign(i + 2, 0);
minus_[i].assign(i + 2, 0);
}
for (int i = 0; i < M; i++) {
cin >> A >> B >> X;
A--;
B--;
plus_[A][B]++;
plus_[A + X + 1][B]--;
minus_[A][B]--;
minus_[A + X + 1][B + X + 1]++;
}
for (int i = 0; i < N; i++) {
int sum = 0;
for (int j = 0; j < N - i; j++) {
sum += plus_[j + i][i];
plus_[j + i][i] = sum;
}
}
for (int i = 0; i < N; i++) {
int sum = 0;
for (int j = 0; j < N - i; j++) {
sum += minus_[i + j][j];
minus_[i + j][j] = sum;
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
int sum = 0;
for (int j = 0; j <= i; j++) {
sum += plus_[i][j];
if (sum > 0)
ans++;
sum += minus_[i][j];
}
}
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <climits>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<short> plus_[5001], minus_[5001];
int main() {
int N, M, A, B, X;
cin >> N >> M;
for (int i = 0; i <= N; i++) {
plus_[i].assign(i + 2, 0);
minus_[i].assign(i + 2, 0);
}
for (int i = 0; i < M; i++) {
cin >> A >> B >> X;
A--;
B--;
plus_[A][B]++;
plus_[A + X + 1][B]--;
minus_[A][B]--;
minus_[A + X + 1][B + X + 1]++;
}
for (int i = 0; i < N; i++) {
int sum = 0;
for (int j = 0; j < N - i; j++) {
sum += plus_[j + i][i];
plus_[j + i][i] = sum;
}
}
for (int i = 0; i < N; i++) {
int sum = 0;
for (int j = 0; j < N - i; j++) {
sum += minus_[i + j][j];
minus_[i + j][j] = sum;
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
int sum = 0;
for (int j = 0; j <= i; j++) {
sum += plus_[i][j];
if (sum > 0)
ans++;
sum += minus_[i][j];
}
}
printf("%d\n", ans);
return 0;
} | replace | 8 | 9 | 8 | 9 | MLE | |
p00497 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
short dp[5000][5000];
int main() {
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int x, y, c;
cin >> y >> x >> c;
dp[y - 1][x - 1] = c + 1;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dp[i + 1][j] = max<int>(dp[i + 1][j], dp[i][j] - 1);
dp[i + 1][j + 1] = max<int>(dp[i + 1][j + 1], dp[i][j] - 1);
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
ans += !!dp[i][j];
}
}
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
using namespace std;
short dp[5010][5010];
int main() {
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++) {
int x, y, c;
cin >> y >> x >> c;
dp[y - 1][x - 1] = c + 1;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dp[i + 1][j] = max<int>(dp[i + 1][j], dp[i][j] - 1);
dp[i + 1][j + 1] = max<int>(dp[i + 1][j + 1], dp[i][j] - 1);
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
ans += !!dp[i][j];
}
}
cout << ans << endl;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p00497 | C++ | Runtime Error | #include <cstdio>
#define S 5002
using namespace std;
int l[S][S] = {0};
int main() {
int N, M, a, b, x, i, j;
scanf("%d %d", &N, &M);
for (i = 0; i < M; i++) {
scanf("%d %d %d", &a, &b, &x);
l[a][b]++;
l[a][b + 1]--;
l[a + x + 1][b]--;
l[a + x + 2][b + 1]++;
l[a + x + 2][b + x + 2]--;
l[a + x + 1][b + x + 2]++;
}
for (i = 1; i < N + 4; i++) {
for (j = 1; j < N + 4; j++) {
l[i][j] += l[i][j - 1];
}
}
for (j = 1; j < N + 4; j++) {
for (i = 1; i < N + 4; i++) {
l[i][j] += l[i - 1][j];
}
}
for (i = 1; i < N + 4; i++) {
for (j = 1; j < N + 4; j++) {
if (i + j - 1 < S) {
l[i + j - 1][j] += l[i + j - 2][j - 1];
}
}
}
int cnt = 0;
for (i = 0; i < N + 4; i++) {
for (j = 0; j < N + 4; j++) {
if (l[i][j] > 0) {
cnt++;
}
}
}
printf("%d\n", cnt);
return 0;
}
| #include <cstdio>
#define S 5010
using namespace std;
int l[S][S] = {0};
int main() {
int N, M, a, b, x, i, j;
scanf("%d %d", &N, &M);
for (i = 0; i < M; i++) {
scanf("%d %d %d", &a, &b, &x);
l[a][b]++;
l[a][b + 1]--;
l[a + x + 1][b]--;
l[a + x + 2][b + 1]++;
l[a + x + 2][b + x + 2]--;
l[a + x + 1][b + x + 2]++;
}
for (i = 1; i < N + 4; i++) {
for (j = 1; j < N + 4; j++) {
l[i][j] += l[i][j - 1];
}
}
for (j = 1; j < N + 4; j++) {
for (i = 1; i < N + 4; i++) {
l[i][j] += l[i - 1][j];
}
}
for (i = 1; i < N + 4; i++) {
for (j = 1; j < N + 4; j++) {
if (i + j - 1 < S) {
l[i + j - 1][j] += l[i + j - 2][j - 1];
}
}
}
int cnt = 0;
for (i = 0; i < N + 4; i++) {
for (j = 0; j < N + 4; j++) {
if (l[i][j] > 0) {
cnt++;
}
}
}
printf("%d\n", cnt);
return 0;
}
| replace | 1 | 2 | 1 | 2 | 0 | |
p00497 | C++ | Memory Limit Exceeded | #include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
const int size = n + 3;
vector<vector<int>> triangle(size, vector<int>(size, 0));
for (int i = 0; i < m; ++i) {
int a, b, x;
cin >> a >> b >> x;
++triangle[a][b];
--triangle[a][b + 1];
--triangle[a + x + 1][b];
++triangle[a + x + 2][b + 1];
++triangle[a + x + 1][b + x + 2];
--triangle[a + x + 2][b + x + 2];
}
for (int i = 0; i < size; ++i) {
for (int j = 0; j < i; ++j) {
triangle[i][j + 1] += triangle[i][j];
}
}
for (int i = 0; i < size; ++i) {
for (int j = i + 1; j < size; ++j) {
triangle[j][i] += triangle[j - 1][i];
}
}
for (int i = 0; i < size; ++i) {
for (int j = 1; i + j < size; ++j) {
triangle[i + j][j] += triangle[i + j - 1][j - 1];
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
if (triangle[i][j] > 0)
++ans;
}
}
cout << ans << endl;
return EXIT_SUCCESS;
} | #include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
const int size = n + 3;
vector<vector<int>> triangle;
for (int i = 0; i < size; ++i)
triangle.emplace_back(i + 2, 0);
for (int i = 0; i < m; ++i) {
int a, b, x;
cin >> a >> b >> x;
++triangle[a][b];
--triangle[a][b + 1];
--triangle[a + x + 1][b];
++triangle[a + x + 2][b + 1];
++triangle[a + x + 1][b + x + 2];
--triangle[a + x + 2][b + x + 2];
}
for (int i = 0; i < size; ++i) {
for (int j = 0; j < i; ++j) {
triangle[i][j + 1] += triangle[i][j];
}
}
for (int i = 0; i < size; ++i) {
for (int j = i + 1; j < size; ++j) {
triangle[j][i] += triangle[j - 1][i];
}
}
for (int i = 0; i < size; ++i) {
for (int j = 1; i + j < size; ++j) {
triangle[i + j][j] += triangle[i + j - 1][j - 1];
}
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
if (triangle[i][j] > 0)
++ans;
}
}
cout << ans << endl;
return EXIT_SUCCESS;
} | replace | 13 | 14 | 13 | 16 | MLE | |
p00497 | C++ | Memory Limit Exceeded | #include <stdio.h>
int t[5000][5000];
int max(int a, int b) { return a > b ? a : b; }
int main() {
int n, k;
int i, j;
scanf("%d %d", &n, &k);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
t[i][j] = -1;
for (i = 0; i < k; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
t[a - 1][b - 1] = max(t[a - 1][b - 1], c);
}
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n; j++) {
if (t[i][j] > 0) {
t[i + 1][j] = max(t[i + 1][j], t[i][j] - 1);
if (j < n - 1)
t[i + 1][j + 1] = max(t[i + 1][j + 1], t[i][j] - 1);
}
}
}
int ans = 0;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
if (t[i][j] >= 0)
ans++;
printf("%d\n", ans);
return 0;
}
| #include <stdio.h>
short t[5000][5000];
int max(int a, int b) { return a > b ? a : b; }
int main() {
int n, k;
int i, j;
scanf("%d %d", &n, &k);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
t[i][j] = -1;
for (i = 0; i < k; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
t[a - 1][b - 1] = max(t[a - 1][b - 1], c);
}
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n; j++) {
if (t[i][j] > 0) {
t[i + 1][j] = max(t[i + 1][j], t[i][j] - 1);
if (j < n - 1)
t[i + 1][j + 1] = max(t[i + 1][j + 1], t[i][j] - 1);
}
}
}
int ans = 0;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
if (t[i][j] >= 0)
ans++;
printf("%d\n", ans);
return 0;
}
| replace | 1 | 2 | 1 | 2 | MLE | |
p00497 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int a, b, x, n, m, field[5001][5001] = {};
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b >> x;
field[a - 1][b - 1] = x + 1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
field[i + 1][j] = max(field[i + 1][j], field[i][j] - 1);
field[i + 1][j + 1] = max(field[i + 1][j + 1], field[i][j] - 1);
}
}
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (field[i][j])
cnt++;
}
}
cout << cnt << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int a, b, x, n, m;
static int field[5001][5001] = {};
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b >> x;
field[a - 1][b - 1] = x + 1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
field[i + 1][j] = max(field[i + 1][j], field[i][j] - 1);
field[i + 1][j + 1] = max(field[i + 1][j + 1], field[i][j] - 1);
}
}
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (field[i][j])
cnt++;
}
}
cout << cnt << endl;
return 0;
} | replace | 4 | 5 | 4 | 6 | -11 | |
p00497 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#define rep(i, s, n) for (int i = (s); (n) > i; i++)
#define REP(i, n) rep(i, 0, n)
#define RANGE(x, a, b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a, b, c, d) \
(RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b))
#define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d))
#define PW(x) ((x) * (x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a, b) ((a >> b) & 1)
#define bitset(a, b) (a |= (1 << b))
#define bitunset(a, b) (a &= ~(1 << b))
#define MP(a, b) make_pair((a), (b))
#define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
// n?¬??????????????????????????¬¬????????°???????????????????????¨???????????????????????????
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
signed main() {
int n, m;
scanf("%d %d", &n, &m);
int dp[5002][5002] = {};
REP(i, m) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
dp[a - 1][b - 1] = max(dp[a - 1][b - 1], c + 1);
}
int ans = 0;
REP(i, n) {
REP(j, n) {
if (dp[i][j]) {
ans++;
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] - 1);
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] - 1);
}
}
}
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#define rep(i, s, n) for (int i = (s); (n) > i; i++)
#define REP(i, n) rep(i, 0, n)
#define RANGE(x, a, b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a, b, c, d) \
(RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b))
#define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d))
#define PW(x) ((x) * (x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a, b) ((a >> b) & 1)
#define bitset(a, b) (a |= (1 << b))
#define bitunset(a, b) (a &= ~(1 << b))
#define MP(a, b) make_pair((a), (b))
#define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
// n?¬??????????????????????????¬¬????????°???????????????????????¨???????????????????????????
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
signed main() {
int n, m;
scanf("%d %d", &n, &m);
vector<vector<int>> dp(5002, vector<int>(5002));
REP(i, m) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
dp[a - 1][b - 1] = max(dp[a - 1][b - 1], c + 1);
}
int ans = 0;
REP(i, n) {
REP(j, n) {
if (dp[i][j]) {
ans++;
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] - 1);
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] - 1);
}
}
}
printf("%d\n", ans);
return 0;
} | replace | 45 | 46 | 45 | 46 | -11 | |
p00497 | C++ | Runtime Error | #include <stdio.h>
#define calc(x, y) ((((x) * ((x) + 1)) / 2) + (y))
#define safe_calc(x, y) ((((x) + 2) * ((x) + 3) / 2) + (y) + 1)
int n;
int sum;
int nails[12517506];
void process() {
int i;
for (i = 1; i < n + 3; i++) {
int j;
for (j = 1; j <= i; j++) {
nails[calc(i, j)] += nails[calc(i, j) - 1];
}
}
for (i = 0; i < n + 3; i++) {
int j;
for (j = 1; j < (n + 3 - i); j++) {
nails[calc(i + j, i)] += nails[calc(i + j - 1, i)];
}
}
for (i = 0; i < n + 3; i++) {
int j;
for (j = 1; j < (n + 3 - i); j++) {
nails[calc(i + j, j)] += nails[calc(i + j - 1, j - 1)];
}
}
for (i = 0; i < n + 3; i++) {
int j;
for (j = 0; j <= i; j++) {
if (nails[calc(i, j)] > 0)
sum++;
}
}
}
int main() {
int i;
int m;
scanf("%d %d", &n, &m);
for (i = 0; i < m; i++) {
int a, b, x;
scanf("%d %d %d", &a, &b, &x);
a--;
b--;
x++;
nails[safe_calc(a, b)]++;
nails[safe_calc(a, b) + 1]--;
nails[safe_calc(a + x, b)]--;
nails[safe_calc(a + x, b + x) + 1]++;
nails[safe_calc(a + x + 1, b + 1)]++;
nails[safe_calc(a + x + 1, b + x + 1)]--;
}
process();
printf("%d\n", sum);
} | #include <stdio.h>
#define calc(x, y) ((((x) * ((x) + 1)) / 2) + (y))
#define safe_calc(x, y) ((((x) + 2) * ((x) + 3) / 2) + (y) + 1)
int n;
int sum;
int nails[13000000];
void process() {
int i;
for (i = 1; i < n + 3; i++) {
int j;
for (j = 1; j <= i; j++) {
nails[calc(i, j)] += nails[calc(i, j) - 1];
}
}
for (i = 0; i < n + 3; i++) {
int j;
for (j = 1; j < (n + 3 - i); j++) {
nails[calc(i + j, i)] += nails[calc(i + j - 1, i)];
}
}
for (i = 0; i < n + 3; i++) {
int j;
for (j = 1; j < (n + 3 - i); j++) {
nails[calc(i + j, j)] += nails[calc(i + j - 1, j - 1)];
}
}
for (i = 0; i < n + 3; i++) {
int j;
for (j = 0; j <= i; j++) {
if (nails[calc(i, j)] > 0)
sum++;
}
}
}
int main() {
int i;
int m;
scanf("%d %d", &n, &m);
for (i = 0; i < m; i++) {
int a, b, x;
scanf("%d %d %d", &a, &b, &x);
a--;
b--;
x++;
nails[safe_calc(a, b)]++;
nails[safe_calc(a, b) + 1]--;
nails[safe_calc(a + x, b)]--;
nails[safe_calc(a + x, b + x) + 1]++;
nails[safe_calc(a + x + 1, b + 1)]++;
nails[safe_calc(a + x + 1, b + x + 1)]--;
}
process();
printf("%d\n", sum);
} | replace | 7 | 8 | 7 | 8 | 0 | |
p00498 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <functional>
#include <queue>
#include <vector>
#pragma warning(disable : 4996)
FILE *in = freopen("./input.txt", "r", stdin);
using namespace std;
struct edge {
int to, cost;
};
bool operator<(const edge &e1, const edge &e2) { return e1.cost < e2.cost; }
vector<int> par;
int root(int x) {
if (x == par[x])
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
par[x] = y;
}
bool same(int x, int y) { return root(x) == root(y); }
vector<int> depth;
vector<vector<int>> parent, val;
int lca(int x, int y) {
if (depth[x] < depth[y])
swap(x, y);
for (int i = 16; i >= 0; i--) {
if ((depth[x] - depth[y]) >= (1 << i))
x = parent[i][x];
}
for (int i = 16; i >= 0; i--) {
if (parent[i][x] != parent[i][y]) {
x = parent[i][x];
y = parent[i][y];
}
}
while (x != y) {
x = parent[0][x];
y = parent[0][y];
}
return x;
}
int query(int x, int y) {
int z = lca(x, y);
int t1 = depth[x] - depth[z], t2 = depth[y] - depth[z];
int ret = 1999999999;
for (int i = 16; i >= 0; i--) {
if (t1 & (1 << i))
ret = min(ret, val[i][x]), x = parent[i][x];
if (t2 & (1 << i))
ret = min(ret, val[i][y]), y = parent[i][y];
}
return ret;
}
void findpar(int pos, int pre, vector<vector<edge>> &G) {
parent[0][pos] = pre;
for (edge e : G[pos]) {
if (e.to != pre) {
val[0][e.to] = e.cost;
depth[e.to] = depth[pos] + 1;
findpar(e.to, pos, G);
}
}
}
int N, M, K, Q, f, t1, t2;
int main() {
scanf("%d%d%d%d", &N, &M, &K, &Q);
vector<vector<edge>> G(N);
vector<int> a(M), b(M), c(M);
for (int i = 0; i < M; i++) {
scanf("%d%d%d", &a[i], &b[i], &c[i]);
a[i]--, b[i]--;
G[a[i]].push_back(edge{b[i], c[i]});
G[b[i]].push_back(edge{a[i], c[i]});
}
vector<int> dist(N, 1999999999);
priority_queue<edge> que;
for (int i = 0; i < K; i++) {
scanf("%d", &f);
f--;
dist[f] = 0;
que.push(edge{f, 0});
}
while (!que.empty()) {
edge u = que.top();
que.pop();
for (edge e : G[u.to]) {
if (dist[e.to] > dist[u.to] + e.cost) {
dist[e.to] = dist[u.to] + e.cost;
que.push(edge{e.to, -dist[e.to]});
}
}
}
vector<pair<int, int>> s;
for (int i = 0; i < M; i++) {
c[i] = min(dist[a[i]], dist[b[i]]);
s.push_back(make_pair(c[i], i));
}
sort(s.begin(), s.end(), greater<pair<int, int>>());
par.resize(N);
for (int i = 0; i < N; i++)
par[i] = i;
vector<vector<edge>> G2(N);
for (int i = 0; i < M; i++) {
int r1 = a[s[i].second], r2 = b[s[i].second], r3 = c[s[i].second];
;
if (!same(r1, r2)) {
unite(r1, r2);
G2[r1].push_back(edge{r2, r3});
G2[r2].push_back(edge{r1, r3});
}
}
parent = vector<vector<int>>(17, vector<int>(N));
val = vector<vector<int>>(17, vector<int>(N));
depth.resize(N);
findpar(0, -1, G2);
for (int i = 1; i < 17; i++) {
for (int j = 0; j < N; j++) {
if (parent[i - 1][j] == -1)
parent[i][j] = -1, val[i][j] = 1999999999;
else
parent[i][j] = parent[i - 1][parent[i - 1][j]],
val[i][j] = min(val[i - 1][j], val[i - 1][parent[i - 1][j]]);
}
}
while (Q--) {
scanf("%d%d", &t1, &t2);
t1--, t2--;
printf("%d\n", query(t1, t2));
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <functional>
#include <queue>
#include <vector>
using namespace std;
struct edge {
int to, cost;
};
bool operator<(const edge &e1, const edge &e2) { return e1.cost < e2.cost; }
vector<int> par;
int root(int x) {
if (x == par[x])
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
par[x] = y;
}
bool same(int x, int y) { return root(x) == root(y); }
vector<int> depth;
vector<vector<int>> parent, val;
int lca(int x, int y) {
if (depth[x] < depth[y])
swap(x, y);
for (int i = 16; i >= 0; i--) {
if ((depth[x] - depth[y]) >= (1 << i))
x = parent[i][x];
}
for (int i = 16; i >= 0; i--) {
if (parent[i][x] != parent[i][y]) {
x = parent[i][x];
y = parent[i][y];
}
}
while (x != y) {
x = parent[0][x];
y = parent[0][y];
}
return x;
}
int query(int x, int y) {
int z = lca(x, y);
int t1 = depth[x] - depth[z], t2 = depth[y] - depth[z];
int ret = 1999999999;
for (int i = 16; i >= 0; i--) {
if (t1 & (1 << i))
ret = min(ret, val[i][x]), x = parent[i][x];
if (t2 & (1 << i))
ret = min(ret, val[i][y]), y = parent[i][y];
}
return ret;
}
void findpar(int pos, int pre, vector<vector<edge>> &G) {
parent[0][pos] = pre;
for (edge e : G[pos]) {
if (e.to != pre) {
val[0][e.to] = e.cost;
depth[e.to] = depth[pos] + 1;
findpar(e.to, pos, G);
}
}
}
int N, M, K, Q, f, t1, t2;
int main() {
scanf("%d%d%d%d", &N, &M, &K, &Q);
vector<vector<edge>> G(N);
vector<int> a(M), b(M), c(M);
for (int i = 0; i < M; i++) {
scanf("%d%d%d", &a[i], &b[i], &c[i]);
a[i]--, b[i]--;
G[a[i]].push_back(edge{b[i], c[i]});
G[b[i]].push_back(edge{a[i], c[i]});
}
vector<int> dist(N, 1999999999);
priority_queue<edge> que;
for (int i = 0; i < K; i++) {
scanf("%d", &f);
f--;
dist[f] = 0;
que.push(edge{f, 0});
}
while (!que.empty()) {
edge u = que.top();
que.pop();
for (edge e : G[u.to]) {
if (dist[e.to] > dist[u.to] + e.cost) {
dist[e.to] = dist[u.to] + e.cost;
que.push(edge{e.to, -dist[e.to]});
}
}
}
vector<pair<int, int>> s;
for (int i = 0; i < M; i++) {
c[i] = min(dist[a[i]], dist[b[i]]);
s.push_back(make_pair(c[i], i));
}
sort(s.begin(), s.end(), greater<pair<int, int>>());
par.resize(N);
for (int i = 0; i < N; i++)
par[i] = i;
vector<vector<edge>> G2(N);
for (int i = 0; i < M; i++) {
int r1 = a[s[i].second], r2 = b[s[i].second], r3 = c[s[i].second];
;
if (!same(r1, r2)) {
unite(r1, r2);
G2[r1].push_back(edge{r2, r3});
G2[r2].push_back(edge{r1, r3});
}
}
parent = vector<vector<int>>(17, vector<int>(N));
val = vector<vector<int>>(17, vector<int>(N));
depth.resize(N);
findpar(0, -1, G2);
for (int i = 1; i < 17; i++) {
for (int j = 0; j < N; j++) {
if (parent[i - 1][j] == -1)
parent[i][j] = -1, val[i][j] = 1999999999;
else
parent[i][j] = parent[i - 1][parent[i - 1][j]],
val[i][j] = min(val[i - 1][j], val[i - 1][parent[i - 1][j]]);
}
}
while (Q--) {
scanf("%d%d", &t1, &t2);
t1--, t2--;
printf("%d\n", query(t1, t2));
}
return 0;
} | delete | 5 | 7 | 5 | 5 | -11 | |
p00498 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
#define foru(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ford(i, a, b) for (int i = int(a); i >= int(b); i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)a.size()
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> edge;
const int N = 500005;
const int oo = 1000000000;
int n, m, k, q, fes[N], dis[N];
vector<int> adj[N], wei[N];
edge e[2 * N];
/// tree + lca
int lab[N], p[N][25], fm[N][25], l[N];
void read() {
scanf("%d%d%d%d", &n, &m, &k, &q);
int u, v, w;
foru(i, 1, m) {
scanf("%d%d%d", &u, &v, &w);
adj[u].pb(v);
wei[u].pb(w);
adj[v].pb(u);
wei[v].pb(w);
}
foru(i, 1, k) {
scanf("%d", &u);
fes[u] = 1;
}
}
/// min path
priority_queue<pii, vector<pii>, greater<pii>> heap;
void dijkstra() {
foru(u, 1, n) if (fes[u]) {
dis[u] = 0;
heap.push(mp(0, u));
}
else dis[u] = oo;
while (!heap.empty()) {
int u = heap.top().se, e = heap.top().fi;
heap.pop();
if (dis[u] != e)
continue;
fes[u] = 1;
foru(i, 0, sz(adj[u]) - 1) {
int v = adj[u][i];
if (fes[v])
continue;
if (dis[v] > dis[u] + wei[u][i]) {
dis[v] = dis[u] + wei[u][i];
heap.push(mp(dis[v], v));
}
}
}
}
/// disjoint set
int root(int u) {
if (lab[u] == u)
return u;
lab[u] = root(lab[u]);
return lab[u];
}
void disjoint_set() {
foru(u, 1, n) lab[u] = u;
int sedge = 0;
ford(i, m, 1) {
int u = e[i].se.fi, v = e[i].se.se;
u = root(u), v = root(v);
if (u == v)
continue;
lab[u] = v;
sedge++;
adj[u].pb(v);
wei[u].pb(e[i].fi);
adj[v].pb(u);
wei[v].pb(e[i].fi);
if (sedge == n - 1)
break;
}
}
/// lca
void dfs(int u, int par) {
foru(i, 0, sz(adj[u]) - 1) {
int v = adj[u][i];
if (par == v)
continue;
l[v] = l[u] + 1;
fm[v][0] = wei[u][i];
p[v][0] = u;
dfs(v, u);
}
}
int lca(int u, int v) {
if (l[u] > l[v])
swap(u, v);
if (u == v)
return 0;
int res = oo;
ford(j, 20, 0) if (p[v][j] > 0 && l[p[v][j]] >= l[u]) {
res = min(res, fm[v][j]);
v = p[v][j];
}
if (u == v)
return res;
ford(j, 20, 0) if (p[u][j] > 0 && p[v][j] > 0) if (p[u][j] != p[v][j]) {
res = min(res, fm[u][j]);
u = p[u][j];
res = min(res, fm[v][j]);
v = p[v][j];
}
res = min(res, min(fm[u][0], fm[v][0]));
return res;
}
/// sol query
int main() {
// freopen("a.txt", "r", stdin);
read();
dijkstra();
m = 0;
foru(u, 1, n) {
foru(i, 0, sz(adj[u]) - 1) {
int v = adj[u][i];
e[++m] = mp(min(dis[u], dis[v]), mp(u, v));
}
adj[u].clear();
wei[u].clear();
}
sort(e + 1, e + m + 1);
disjoint_set();
p[1][0] = -1;
dfs(1, -1);
foru(j, 1, 20) foru(u, 1, n) if (p[u][j - 1] > 0) {
fm[u][j] = min(fm[u][j - 1], fm[p[u][j - 1]][j - 1]);
p[u][j] = p[p[u][j - 1]][j - 1];
}
foru(i, 1, q) {
int u, v;
scanf("%d%d", &u, &v);
printf("%d\n", lca(u, v));
}
return 0;
} | #include <bits/stdc++.h>
#define foru(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ford(i, a, b) for (int i = int(a); i >= int(b); i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (int)a.size()
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> edge;
const int N = 200005;
const int oo = 1000000000;
int n, m, k, q, fes[N], dis[N];
vector<int> adj[N], wei[N];
edge e[2 * N];
/// tree + lca
int lab[N], p[N][25], fm[N][25], l[N];
void read() {
scanf("%d%d%d%d", &n, &m, &k, &q);
int u, v, w;
foru(i, 1, m) {
scanf("%d%d%d", &u, &v, &w);
adj[u].pb(v);
wei[u].pb(w);
adj[v].pb(u);
wei[v].pb(w);
}
foru(i, 1, k) {
scanf("%d", &u);
fes[u] = 1;
}
}
/// min path
priority_queue<pii, vector<pii>, greater<pii>> heap;
void dijkstra() {
foru(u, 1, n) if (fes[u]) {
dis[u] = 0;
heap.push(mp(0, u));
}
else dis[u] = oo;
while (!heap.empty()) {
int u = heap.top().se, e = heap.top().fi;
heap.pop();
if (dis[u] != e)
continue;
fes[u] = 1;
foru(i, 0, sz(adj[u]) - 1) {
int v = adj[u][i];
if (fes[v])
continue;
if (dis[v] > dis[u] + wei[u][i]) {
dis[v] = dis[u] + wei[u][i];
heap.push(mp(dis[v], v));
}
}
}
}
/// disjoint set
int root(int u) {
if (lab[u] == u)
return u;
lab[u] = root(lab[u]);
return lab[u];
}
void disjoint_set() {
foru(u, 1, n) lab[u] = u;
int sedge = 0;
ford(i, m, 1) {
int u = e[i].se.fi, v = e[i].se.se;
u = root(u), v = root(v);
if (u == v)
continue;
lab[u] = v;
sedge++;
adj[u].pb(v);
wei[u].pb(e[i].fi);
adj[v].pb(u);
wei[v].pb(e[i].fi);
if (sedge == n - 1)
break;
}
}
/// lca
void dfs(int u, int par) {
foru(i, 0, sz(adj[u]) - 1) {
int v = adj[u][i];
if (par == v)
continue;
l[v] = l[u] + 1;
fm[v][0] = wei[u][i];
p[v][0] = u;
dfs(v, u);
}
}
int lca(int u, int v) {
if (l[u] > l[v])
swap(u, v);
if (u == v)
return 0;
int res = oo;
ford(j, 20, 0) if (p[v][j] > 0 && l[p[v][j]] >= l[u]) {
res = min(res, fm[v][j]);
v = p[v][j];
}
if (u == v)
return res;
ford(j, 20, 0) if (p[u][j] > 0 && p[v][j] > 0) if (p[u][j] != p[v][j]) {
res = min(res, fm[u][j]);
u = p[u][j];
res = min(res, fm[v][j]);
v = p[v][j];
}
res = min(res, min(fm[u][0], fm[v][0]));
return res;
}
/// sol query
int main() {
// freopen("a.txt", "r", stdin);
read();
dijkstra();
m = 0;
foru(u, 1, n) {
foru(i, 0, sz(adj[u]) - 1) {
int v = adj[u][i];
e[++m] = mp(min(dis[u], dis[v]), mp(u, v));
}
adj[u].clear();
wei[u].clear();
}
sort(e + 1, e + m + 1);
disjoint_set();
p[1][0] = -1;
dfs(1, -1);
foru(j, 1, 20) foru(u, 1, n) if (p[u][j - 1] > 0) {
fm[u][j] = min(fm[u][j - 1], fm[p[u][j - 1]][j - 1]);
p[u][j] = p[p[u][j - 1]][j - 1];
}
foru(i, 1, q) {
int u, v;
scanf("%d%d", &u, &v);
printf("%d\n", lca(u, v));
}
return 0;
} | replace | 12 | 13 | 12 | 13 | MLE | |
p00498 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
struct UnionFind {
vector<int> data;
UnionFind(int sz) { data.resize(sz, -1); }
int Find(int a) { return (data[a] < 0 ? a : data[a] = Find(data[a])); }
void Union(int a, int b) {
a = Find(a), b = Find(b);
if (a == b)
return;
if (data[a] > data[b])
swap(a, b);
data[b] += data[a];
data[a] = b;
}
};
struct edge {
int to, cost;
};
struct edge2 {
int u, v, cost;
bool operator<(const edge2 &e) const { return cost < e.cost; }
};
typedef vector<vector<edge>> Graph;
typedef pair<int, int> Pi;
const int INF = 1 << 30;
int N, M, K, Q, F[100000];
Graph graph;
vector<edge2> weighted;
set<int> buffer[100000];
stack<int> st;
int ret[100000];
void Dijkstra(Graph &g, vector<int> &min_cost) {
min_cost.assign(g.size(), INF);
priority_queue<Pi, vector<Pi>, greater<Pi>> que;
for (int i = 0; i < K; i++) {
que.push(make_pair(0, F[i]));
min_cost[F[i]] = 0;
}
while (!que.empty()) {
Pi p = que.top();
que.pop();
if (p.first > min_cost[p.second])
continue;
for (int i = 0; i < g[p.second].size(); i++) {
edge &e = g[p.second][i];
if (p.first + e.cost >= min_cost[e.to])
continue;
que.push(make_pair(p.first + e.cost, e.to));
min_cost[e.to] = p.first + e.cost;
}
}
}
int main() {
scanf("%d %d %d %d", &N, &M, &K, &Q);
graph.resize(N);
UnionFind uftree(N);
for (int i = 0; i < M; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
--a, --b;
graph[a].push_back((edge){b, c});
graph[b].push_back((edge){a, c});
weighted.push_back((edge2){a, b});
}
for (int i = 0; i < K; i++) {
scanf("%d", &F[i]);
--F[i];
}
for (int i = 0; i < Q; i++) {
int a, b;
scanf("%d %d", &a, &b);
--a, --b;
buffer[a].insert(i);
buffer[b].insert(i);
}
vector<int> min_cost;
Dijkstra(graph, min_cost);
for (int i = 0; i < M; i++) {
weighted[i].cost = min(min_cost[weighted[i].u], min_cost[weighted[i].v]);
}
sort(weighted.rbegin(), weighted.rend());
for (int i = 0; i < M; i++) {
int u = uftree.Find(weighted[i].u), v = uftree.Find(weighted[i].v);
if (u == v)
continue;
uftree.Union(u, v);
int unioned = uftree.Find(weighted[i].u);
set<int> *oo = &buffer[u], *pp = &buffer[v];
if (u != unioned)
swap(oo, pp);
for (set<int>::iterator it = pp->begin(); it != pp->end(); it++) {
if (oo->find(*it) != oo->end())
ret[*it] = weighted[i].cost;
else
st.push(*it);
}
for (; !st.empty(); oo->insert(st.top()), st.pop())
;
}
for (int i = 0; i < Q; i++) {
printf("%d\n", ret[i]);
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int64;
struct UnionFind {
vector<int> data;
UnionFind(int sz) { data.resize(sz, -1); }
int Find(int a) { return (data[a] < 0 ? a : data[a] = Find(data[a])); }
void Union(int a, int b) {
a = Find(a), b = Find(b);
if (a == b)
return;
if (data[a] < data[b])
swap(a, b);
data[b] += data[a];
data[a] = b;
}
};
struct edge {
int to, cost;
};
struct edge2 {
int u, v, cost;
bool operator<(const edge2 &e) const { return cost < e.cost; }
};
typedef vector<vector<edge>> Graph;
typedef pair<int, int> Pi;
const int INF = 1 << 30;
int N, M, K, Q, F[100000];
Graph graph;
vector<edge2> weighted;
set<int> buffer[100000];
stack<int> st;
int ret[100000];
void Dijkstra(Graph &g, vector<int> &min_cost) {
min_cost.assign(g.size(), INF);
priority_queue<Pi, vector<Pi>, greater<Pi>> que;
for (int i = 0; i < K; i++) {
que.push(make_pair(0, F[i]));
min_cost[F[i]] = 0;
}
while (!que.empty()) {
Pi p = que.top();
que.pop();
if (p.first > min_cost[p.second])
continue;
for (int i = 0; i < g[p.second].size(); i++) {
edge &e = g[p.second][i];
if (p.first + e.cost >= min_cost[e.to])
continue;
que.push(make_pair(p.first + e.cost, e.to));
min_cost[e.to] = p.first + e.cost;
}
}
}
int main() {
scanf("%d %d %d %d", &N, &M, &K, &Q);
graph.resize(N);
UnionFind uftree(N);
for (int i = 0; i < M; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
--a, --b;
graph[a].push_back((edge){b, c});
graph[b].push_back((edge){a, c});
weighted.push_back((edge2){a, b});
}
for (int i = 0; i < K; i++) {
scanf("%d", &F[i]);
--F[i];
}
for (int i = 0; i < Q; i++) {
int a, b;
scanf("%d %d", &a, &b);
--a, --b;
buffer[a].insert(i);
buffer[b].insert(i);
}
vector<int> min_cost;
Dijkstra(graph, min_cost);
for (int i = 0; i < M; i++) {
weighted[i].cost = min(min_cost[weighted[i].u], min_cost[weighted[i].v]);
}
sort(weighted.rbegin(), weighted.rend());
for (int i = 0; i < M; i++) {
int u = uftree.Find(weighted[i].u), v = uftree.Find(weighted[i].v);
if (u == v)
continue;
uftree.Union(u, v);
int unioned = uftree.Find(weighted[i].u);
set<int> *oo = &buffer[u], *pp = &buffer[v];
if (u != unioned)
swap(oo, pp);
for (set<int>::iterator it = pp->begin(); it != pp->end(); it++) {
if (oo->find(*it) != oo->end())
ret[*it] = weighted[i].cost;
else
st.push(*it);
}
for (; !st.empty(); oo->insert(st.top()), st.pop())
;
}
for (int i = 0; i < Q; i++) {
printf("%d\n", ret[i]);
}
} | replace | 12 | 13 | 12 | 13 | MLE | |
p00498 | C++ | Memory Limit Exceeded | #include <cstdio>
#include <functional>
#include <queue>
#include <set>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30;
struct edge {
int p, q, c;
edge(int p, int q, int c) {
this->p = p;
this->q = q;
this->c = c;
}
bool operator<(const edge &X) const { return (this->c) < X.c; }
};
set<edge> query[100000];
int ans[100000];
int par[100000];
vector<P> G[100000];
int dist[100000];
int find(int x) {
if (par[x] == x)
return x;
return par[x] = find(par[x]);
}
void unite(int x, int y, int c) {
x = find(x);
y = find(y);
if (x == y)
return;
if (query[x].size() > query[y].size())
swap(x, y);
for (auto itr = query[x].begin(); itr != query[x].end(); itr++) {
if (query[y].find(*itr) == query[y].end()) {
query[y].insert(*itr);
} else {
ans[itr->c] = c;
}
}
par[x] = y;
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
int N, M, K, Q;
scanf("%d %d %d %d", &N, &M, &K, &Q);
for (int i = 0; i < M; i++) {
int A, B, L;
scanf("%d %d %d", &A, &B, &L);
A--;
B--;
G[A].push_back(P(B, L));
G[B].push_back(P(A, L));
}
fill(dist, dist + N, INF);
priority_queue<P, vector<P>, greater<P>> que;
for (int i = 0; i < K; i++) {
int F;
scanf("%d", &F);
F--;
dist[F] = 0;
que.push(P(0, F));
}
while (!que.empty()) {
P p = que.top();
que.pop();
int x = p.second, c = p.first;
if (dist[x] < c)
continue;
for (int i = 0; i < G[x].size(); i++) {
int to = G[x][i].first;
int cost = G[x][i].second;
if (dist[to] > (c + cost)) {
dist[to] = c + cost;
que.push(P(dist[to], to));
}
}
}
priority_queue<edge> E;
for (int i = 0; i < N; i++) {
for (int j = 0; j < G[i].size(); j++) {
int to = G[i][j].first;
E.push(edge(i, to, min(dist[i], dist[to])));
}
}
for (int i = 0; i < Q; i++) {
int S, T;
scanf("%d %d", &S, &T);
S--;
T--;
if (S > T)
swap(S, T);
query[S].insert(edge(S, T, i));
query[T].insert(edge(S, T, i));
}
for (int i = 0; i < N; i++) {
par[i] = i;
}
while (!E.empty()) {
edge e = E.top();
E.pop();
if (!same(e.p, e.q)) {
unite(e.p, e.q, e.c);
}
}
for (int i = 0; i < Q; i++) {
printf("%d\n", ans[i]);
}
} | #include <cstdio>
#include <functional>
#include <queue>
#include <set>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30;
struct edge {
int p, q, c;
edge(int p, int q, int c) {
this->p = p;
this->q = q;
this->c = c;
}
bool operator<(const edge &X) const { return (this->c) < X.c; }
};
set<edge> query[100000];
int ans[100000];
int par[100000];
vector<P> G[100000];
int dist[100000];
int find(int x) {
if (par[x] == x)
return x;
return par[x] = find(par[x]);
}
void unite(int x, int y, int c) {
x = find(x);
y = find(y);
if (x == y)
return;
if (query[x].size() > query[y].size())
swap(x, y);
for (auto itr = query[x].begin(); itr != query[x].end(); itr++) {
if (query[y].find(*itr) == query[y].end()) {
query[y].insert(*itr);
} else {
ans[itr->c] = c;
}
}
query[x].clear();
par[x] = y;
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
int N, M, K, Q;
scanf("%d %d %d %d", &N, &M, &K, &Q);
for (int i = 0; i < M; i++) {
int A, B, L;
scanf("%d %d %d", &A, &B, &L);
A--;
B--;
G[A].push_back(P(B, L));
G[B].push_back(P(A, L));
}
fill(dist, dist + N, INF);
priority_queue<P, vector<P>, greater<P>> que;
for (int i = 0; i < K; i++) {
int F;
scanf("%d", &F);
F--;
dist[F] = 0;
que.push(P(0, F));
}
while (!que.empty()) {
P p = que.top();
que.pop();
int x = p.second, c = p.first;
if (dist[x] < c)
continue;
for (int i = 0; i < G[x].size(); i++) {
int to = G[x][i].first;
int cost = G[x][i].second;
if (dist[to] > (c + cost)) {
dist[to] = c + cost;
que.push(P(dist[to], to));
}
}
}
priority_queue<edge> E;
for (int i = 0; i < N; i++) {
for (int j = 0; j < G[i].size(); j++) {
int to = G[i][j].first;
E.push(edge(i, to, min(dist[i], dist[to])));
}
}
for (int i = 0; i < Q; i++) {
int S, T;
scanf("%d %d", &S, &T);
S--;
T--;
if (S > T)
swap(S, T);
query[S].insert(edge(S, T, i));
query[T].insert(edge(S, T, i));
}
for (int i = 0; i < N; i++) {
par[i] = i;
}
while (!E.empty()) {
edge e = E.top();
E.pop();
if (!same(e.p, e.q)) {
unite(e.p, e.q, e.c);
}
}
for (int i = 0; i < Q; i++) {
printf("%d\n", ans[i]);
}
} | insert | 42 | 42 | 42 | 43 | MLE | |
p00498 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;
vector<pii> g[100000];
int N, M, K, Q;
int dist[200000];
int f[100000];
void dijkstra() {
REP(i, N) dist[i] = INF;
priority_queue<pii> Q;
REP(i, K) {
Q.push(pii(0, f[i]));
dist[f[i]] = 0;
}
while (!Q.empty()) {
pii p = Q.top();
Q.pop();
int d = -p.first;
int now = p.second;
if (dist[now] < d)
continue;
FOR(it, g[now]) {
int nd = d + it->second;
if (dist[it->first] > nd) {
dist[it->first] = nd;
Q.push(pii(-nd, it->first));
}
}
}
}
template <class T> struct UnionFind {
vector<int> data;
vector<T> val;
UnionFind(int size) : data(size, -1), val(size) { REP(i, size) val[i] = i; }
bool unionSet(int x, int y, T v) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
val[x] = v;
}
return x != y;
}
bool findSet(int x, int y) { return root(x) == root(y); }
int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
int size(int x) { return -data[root(x)]; }
T &value(int x) { return val[root(x)]; }
};
typedef pair<int, pii> P;
P edges[200000];
vector<int> tree[200000];
void spanningTree() {
REP(i, 2 * N) tree[i].clear();
int num = 0;
REP(i, N)
FOR(it, g[i]) if (i < it->first) edges[num++] =
(P(min(dist[i], dist[it->first]), pii(i, it->first)));
assert(num == M);
sort(edges, edges + num, greater<P>());
UnionFind<int> uf(N);
int cnt = N;
REP(i, num) {
int a = edges[i].second.first;
int b = edges[i].second.second;
if (!uf.findSet(a, b)) {
int x = uf.value(a);
int y = uf.value(b);
uf.unionSet(a, b, cnt);
tree[cnt].push_back(x);
tree[cnt].push_back(y);
tree[x].push_back(cnt);
tree[y].push_back(cnt);
dist[cnt] = edges[i].first;
cnt++;
}
}
assert(cnt == 2 * N - 1);
}
const int MAX_N = 200000 * 2;
pii dat[MAX_N * 2 - 1];
int rmq_n;
void rmq_init(int *v, int size) {
for (rmq_n = 1; rmq_n < size; rmq_n *= 2)
;
REP(i, 2 * rmq_n - 1) dat[i] = pii(INF, -1);
REP(i, size) { dat[rmq_n - 1 + i] = pii(v[i], i); }
for (int i = rmq_n - 2; i >= 0; --i)
dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
}
pii query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return pii(INF, -1);
if (a <= l && r <= b)
return dat[k];
return min(query(a, b, k * 2 + 1, l, (l + r) / 2),
query(a, b, k * 2 + 2, (l + r) / 2, r));
}
int q(int a, int b) { return query(a, b, 0, 0, rmq_n).second; }
const int MAX_V = 200000;
int vs[MAX_V * 2 - 1];
int depth[MAX_V * 2 - 1];
int id[MAX_V];
void dfs(int v, int p, int d, int &k) {
id[v] = k;
vs[k] = v;
depth[k++] = d;
FOR(it, tree[v]) {
if (*it != p) {
dfs(*it, v, d + 1, k);
vs[k] = v;
depth[k++] = d;
}
}
}
void lca_init(int V, int root) {
int k = 0;
dfs(root, -1, 0, k);
rmq_init(depth, V * 2 - 1);
}
int lca(int u, int v) {
if (id[u] > id[v])
swap(u, v);
return vs[q(id[u], id[v] + 1)];
}
int main() {
ios::sync_with_stdio(0);
while (cin >> N >> M >> K >> Q) {
REP(i, N) g[i].clear();
REP(i, M) {
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
g[a].push_back(pii(b, c));
g[b].push_back(pii(a, c));
}
REP(i, K) {
cin >> f[i];
f[i]--;
}
dijkstra();
spanningTree();
// REP(i,2*N-1) {
// cout << i << " :";
// FOR(it, tree[i]) {
// cout << " " << *it;
// }
// cout << endl;
// }
lca_init(2 * N - 1, 2 * N - 2);
REP(i, Q) {
int a, b;
cin >> a >> b;
a--;
b--;
cout << dist[lca(a, b)] << endl;
}
}
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;
vector<pii> g[100000];
int N, M, K, Q;
int dist[200000];
int f[100000];
void dijkstra() {
REP(i, N) dist[i] = INF;
priority_queue<pii> Q;
REP(i, K) {
Q.push(pii(0, f[i]));
dist[f[i]] = 0;
}
while (!Q.empty()) {
pii p = Q.top();
Q.pop();
int d = -p.first;
int now = p.second;
if (dist[now] < d)
continue;
FOR(it, g[now]) {
int nd = d + it->second;
if (dist[it->first] > nd) {
dist[it->first] = nd;
Q.push(pii(-nd, it->first));
}
}
}
}
template <class T> struct UnionFind {
vector<int> data;
vector<T> val;
UnionFind(int size) : data(size, -1), val(size) { REP(i, size) val[i] = i; }
bool unionSet(int x, int y, T v) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
val[x] = v;
}
return x != y;
}
bool findSet(int x, int y) { return root(x) == root(y); }
int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
int size(int x) { return -data[root(x)]; }
T &value(int x) { return val[root(x)]; }
};
typedef pair<int, pii> P;
P edges[200000];
vector<int> tree[200000];
void spanningTree() {
REP(i, 2 * N) tree[i].clear();
int num = 0;
REP(i, N)
FOR(it, g[i]) if (i < it->first) edges[num++] =
(P(min(dist[i], dist[it->first]), pii(i, it->first)));
assert(num == M);
sort(edges, edges + num, greater<P>());
UnionFind<int> uf(N);
int cnt = N;
REP(i, num) {
int a = edges[i].second.first;
int b = edges[i].second.second;
if (!uf.findSet(a, b)) {
int x = uf.value(a);
int y = uf.value(b);
uf.unionSet(a, b, cnt);
tree[cnt].push_back(x);
tree[cnt].push_back(y);
tree[x].push_back(cnt);
tree[y].push_back(cnt);
dist[cnt] = edges[i].first;
cnt++;
}
}
assert(cnt == 2 * N - 1);
}
const int MAX_N = 400000 * 2;
pii dat[MAX_N * 2 - 1];
int rmq_n;
void rmq_init(int *v, int size) {
for (rmq_n = 1; rmq_n < size; rmq_n *= 2)
;
REP(i, 2 * rmq_n - 1) dat[i] = pii(INF, -1);
REP(i, size) { dat[rmq_n - 1 + i] = pii(v[i], i); }
for (int i = rmq_n - 2; i >= 0; --i)
dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
}
pii query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return pii(INF, -1);
if (a <= l && r <= b)
return dat[k];
return min(query(a, b, k * 2 + 1, l, (l + r) / 2),
query(a, b, k * 2 + 2, (l + r) / 2, r));
}
int q(int a, int b) { return query(a, b, 0, 0, rmq_n).second; }
const int MAX_V = 200000;
int vs[MAX_V * 2 - 1];
int depth[MAX_V * 2 - 1];
int id[MAX_V];
void dfs(int v, int p, int d, int &k) {
id[v] = k;
vs[k] = v;
depth[k++] = d;
FOR(it, tree[v]) {
if (*it != p) {
dfs(*it, v, d + 1, k);
vs[k] = v;
depth[k++] = d;
}
}
}
void lca_init(int V, int root) {
int k = 0;
dfs(root, -1, 0, k);
rmq_init(depth, V * 2 - 1);
}
int lca(int u, int v) {
if (id[u] > id[v])
swap(u, v);
return vs[q(id[u], id[v] + 1)];
}
int main() {
ios::sync_with_stdio(0);
while (cin >> N >> M >> K >> Q) {
REP(i, N) g[i].clear();
REP(i, M) {
int a, b, c;
cin >> a >> b >> c;
a--;
b--;
g[a].push_back(pii(b, c));
g[b].push_back(pii(a, c));
}
REP(i, K) {
cin >> f[i];
f[i]--;
}
dijkstra();
spanningTree();
// REP(i,2*N-1) {
// cout << i << " :";
// FOR(it, tree[i]) {
// cout << " " << *it;
// }
// cout << endl;
// }
lca_init(2 * N - 1, 2 * N - 2);
REP(i, Q) {
int a, b;
cin >> a >> b;
a--;
b--;
cout << dist[lca(a, b)] << endl;
}
}
} | replace | 117 | 118 | 117 | 118 | 0 | |
p00499 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int A, B, C, D, L;
int date_langue, date_math, date_play;
int tmp;
while (1) {
cin >> L >> A >> B >> C >> D;
date_langue = A / C;
tmp = A % C;
if (tmp > 0)
date_langue++;
date_math = B / D;
tmp = B % D;
if (tmp > 0)
date_math++;
if (date_langue > date_math) {
date_play = L - date_langue;
} else
date_play = L - date_math;
cout << date_play << endl;
}
}
| #include <iostream>
using namespace std;
int main() {
int A, B, C, D, L;
int date_langue, date_math, date_play;
int tmp;
while (1) {
cin >> L >> A >> B >> C >> D;
date_langue = A / C;
tmp = A % C;
if (tmp > 0)
date_langue++;
date_math = B / D;
tmp = B % D;
if (tmp > 0)
date_math++;
if (date_langue > date_math) {
date_play = L - date_langue;
} else
date_play = L - date_math;
cout << date_play << endl;
break;
}
}
| insert | 30 | 30 | 30 | 31 | TLE | |
p00499 | C++ | Time Limit Exceeded | #include <stdio.h>
int main(void) {
int a[101], temp = 0, ruio = 0;
for (int i = 1; i <= 5; i++) {
scanf("%d", &a[i]);
}
if (a[4] < a[5]) {
a[4] = a[5];
}
temp = a[2] + a[3];
while (temp > 0) {
temp - a[4];
ruio++;
}
printf("%d\n", a[1] - ruio);
return 0;
} | #include <stdio.h>
int main(void) {
int a[101], temp = 0, ruio = 0;
for (int i = 1; i <= 5; i++) {
scanf("%d", &a[i]);
}
while (a[2] > 0 || a[3] > 0) {
a[2] -= a[4];
a[3] -= a[5];
ruio++;
}
printf("%d\n", a[1] - ruio);
return 0;
} | replace | 6 | 12 | 6 | 9 | TLE | |
p00500 | C++ | Runtime Error | #include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
int main(void) {
int n, a[100][100], G[100][100];
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][j];
}
}
for (int j = 0; j < 3; j++) {
for (int i = 0; i < n; i++) {
for (int k = 0; k < n; k++) {
if (a[i][j] == a[k][j] && i != k) {
G[i][j] = 0;
break;
} else {
G[i][j] = 0;
G[i][j] = a[i][j];
}
}
}
}
for (int i = 0; i < n; i++) {
cout << G[i][0] + G[i][1] + G[i][2] << endl;
}
} | #include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
int main(void) {
int n, a[200][200], G[200][200];
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][j];
}
}
for (int j = 0; j < 3; j++) {
for (int i = 0; i < n; i++) {
for (int k = 0; k < n; k++) {
if (a[i][j] == a[k][j] && i != k) {
G[i][j] = 0;
break;
} else {
G[i][j] = 0;
G[i][j] = a[i][j];
}
}
}
}
for (int i = 0; i < n; i++) {
cout << G[i][0] + G[i][1] + G[i][2] << endl;
}
} | replace | 13 | 14 | 13 | 14 | 0 | |
p00500 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define PI 4 * atan(1);
int main() {
int card[200][3] = {0};
int n, score[100] = {0};
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cin >> card[i][j];
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
int cnt = 0;
for (int k = 0; k < n; k++) {
if (card[j][i] == card[k][i] && j != k) {
cnt++;
}
}
if (cnt == 0)
score[j] += card[j][i];
}
}
for (int i = 0; i < n; i++) {
cout << score[i] << endl;
}
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define PI 4 * atan(1);
int main() {
int card[200][3] = {0};
int n, score[200] = {0};
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
cin >> card[i][j];
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n; j++) {
int cnt = 0;
for (int k = 0; k < n; k++) {
if (card[j][i] == card[k][i] && j != k) {
cnt++;
}
}
if (cnt == 0)
score[j] += card[j][i];
}
}
for (int i = 0; i < n; i++) {
cout << score[i] << endl;
}
} | replace | 15 | 16 | 15 | 16 | 0 | |
p00500 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
bool check(vector<int>, int);
int main() {
int n, num[101][3], score[101] = {0};
bool bo = false;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> num[i][0] >> num[i][1] >> num[i][2];
}
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
if (j == k) {
continue;
}
if (num[j][i] == num[k][i]) {
bo = true;
}
}
if (!bo) {
score[j] += num[j][i];
}
bo = false;
}
}
for (int i = 0; i < n; ++i) {
cout << score[i] << endl;
}
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
bool check(vector<int>, int);
int main() {
int n, num[1001][5], score[1001] = {0};
bool bo = false;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> num[i][0] >> num[i][1] >> num[i][2];
}
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
if (j == k) {
continue;
}
if (num[j][i] == num[k][i]) {
bo = true;
}
}
if (!bo) {
score[j] += num[j][i];
}
bo = false;
}
}
for (int i = 0; i < n; ++i) {
cout << score[i] << endl;
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p00502 | C++ | Runtime Error | #include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int temp[201];
int a[201], b[201], c[201];
int dp[101][201];
int main() {
int D, N;
cin >> D >> N;
for (int i = 0; i < D; ++i)
cin >> temp[i];
for (int i = 0; i < N; ++i)
cin >> a[i] >> b[i] >> c[i];
for (int i = 0; i < D; ++i)
for (int j = 0; j < 201; ++j)
dp[i][j] = 1 << 29;
for (int i = 0; i < N; ++i) {
if (temp[0] <= b[i] && a[i] <= temp[0])
dp[0][c[i]] = 0;
}
for (int i = 1; i < D; ++i) {
for (int j = 0; j < N; ++j) {
if (temp[i] <= b[j] && a[j] <= temp[i]) {
for (int k = 0; k < 201; ++k) {
if (dp[i - 1][k] == 1 << 29)
continue;
if (dp[i][c[j]] == 1 << 29)
dp[i][c[j]] = dp[i - 1][k] + abs(k - c[j]);
dp[i][c[j]] = max(dp[i - 1][k] + abs(k - c[j]), dp[i][c[j]]);
}
}
}
}
int ans = 0;
for (int i = 0; i < 201; ++i) {
if (dp[D - 1][i] == 1 << 29)
continue;
ans = max(ans, dp[D - 1][i]);
}
cout << ans << endl;
} | #include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int temp[201];
int a[201], b[201], c[201];
int dp[201][201];
int main() {
int D, N;
cin >> D >> N;
for (int i = 0; i < D; ++i)
cin >> temp[i];
for (int i = 0; i < N; ++i)
cin >> a[i] >> b[i] >> c[i];
for (int i = 0; i < D; ++i)
for (int j = 0; j < 201; ++j)
dp[i][j] = 1 << 29;
for (int i = 0; i < N; ++i) {
if (temp[0] <= b[i] && a[i] <= temp[0])
dp[0][c[i]] = 0;
}
for (int i = 1; i < D; ++i) {
for (int j = 0; j < N; ++j) {
if (temp[i] <= b[j] && a[j] <= temp[i]) {
for (int k = 0; k < 201; ++k) {
if (dp[i - 1][k] == 1 << 29)
continue;
if (dp[i][c[j]] == 1 << 29)
dp[i][c[j]] = dp[i - 1][k] + abs(k - c[j]);
dp[i][c[j]] = max(dp[i - 1][k] + abs(k - c[j]), dp[i][c[j]]);
}
}
}
}
int ans = 0;
for (int i = 0; i < 201; ++i) {
if (dp[D - 1][i] == 1 << 29)
continue;
ans = max(ans, dp[D - 1][i]);
}
cout << ans << endl;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p00502 | C++ | Time Limit Exceeded | //
// main.cpp
#include <cmath>
#include <iostream>
using namespace std;
struct status {
int toptemp;
int bottomtemp;
int fancy;
};
status dress[201];
int dp[201][201]; // i??\???????????????j????????????????????§????´???????
int temp[201];
int D, N;
int MAX(int i, int j) { // i??\?????????j???????????????????????§???????????????
if (i == 0) { //?????\????????????????????????
// return dress[j].fancy;
return 0;
}
// for(int i=0;i<N;i++){
for (int J = 0; J < N;
J++) { // i-1??\?????????J(1<D)???????????????????????§???
if (temp[i - 1] >= dress[J].bottomtemp && temp[i - 1] <= dress[J].toptemp) {
dp[i][j] =
max(dp[i][j], MAX(i - 1, J) + abs(dress[J].fancy - dress[j].fancy));
}
}
return dp[i][j];
// dp[i-1][j]
// }
}
int main() {
cin >> D >> N;
for (int i = 0; i < D; i++) {
cin >> temp[i];
}
for (int i = 0; i < N; i++) {
cin >> dress[i].bottomtemp >> dress[i].toptemp >> dress[i].fancy;
}
for (int i = 0; i < 201; i++) {
for (int j = 0; j < 201; j++) {
dp[i][j] = -1;
}
}
int answer = 0;
for (int i = 0; i < N; i++) {
if (temp[D - 1] >= dress[i].bottomtemp && temp[D - 1] <= dress[i].toptemp) {
answer = max(answer, MAX(D - 1, i));
}
}
cout << answer << endl;
/*
for(int i=0;i<N;i++){//0??\?????????????¨???????
if(temp[0] >= dress[i].bottomtemp && temp[0] <= dress[i].toptemp){
dp[0][i] = dress[i].fancy;
}
}
for(int i=1;i<D;i++){
for(int j=0;j<N;j++){
if(temp[i] >= dress[j].bottomtemp && temp[i] <=
dress[j].toptemp){//i??\??????j?????????????????? int Maxfancy=-1; for(int
k=0;k<N;k++){//i-1??\????????¨????????????????????´???????????????????´???????????????§???????????????????????????
if(dp[i-1][k] == -1)continue;
Maxfancy = max(Maxfancy,abs(dress[j].fancy -
dress[k].fancy));
}
dp[i][j] = Maxfancy;
}
}
}
int answer = 0;
for(int i=1;i<D;i++){
int Max = -1;
for(int j=0;j<N;j++){
Max = max(Max,dp[i][j]);
}
answer += Max;
}
cout << answer << endl;
vector<int> dresses;
int matrix[201][2];
for(int i=0;i<D;i++){
for(int j=0;j<N;j++){
if(temp[i] >= dress[j].bottomtemp && temp[i] <=
dress[j].toptemp){ dresses.push_back(dress[j].fancy);
}
}
sort(dresses.begin(),dresses.end());
matrix[i][0] = dresses[0];
matrix[i][1] = dresses[dresses.size() - 1];
}
int dp[201]={};
dp[0] = max(matrix[0][0],matrix[0][1]);
for(int i=1;i<D;i++){
dp[i] = max(abs(dp[i-1] - matrix[i][0]),abs(dp[i-1] - matrix[i][1]));
}
cout << dp[D-1] << endl;
*/
return 0;
} | //
// main.cpp
#include <cmath>
#include <iostream>
using namespace std;
struct status {
int toptemp;
int bottomtemp;
int fancy;
};
status dress[201];
int dp[201][201]; // i??\???????????????j????????????????????§????´???????
int temp[201];
int D, N;
int MAX(int i, int j) { // i??\?????????j???????????????????????§???????????????
if (i == 0) { //?????\????????????????????????
// return dress[j].fancy;
return 0;
}
if (dp[i][j] != -1) {
return dp[i][j];
}
// for(int i=0;i<N;i++){
for (int J = 0; J < N;
J++) { // i-1??\?????????J(1<D)???????????????????????§???
if (temp[i - 1] >= dress[J].bottomtemp && temp[i - 1] <= dress[J].toptemp) {
dp[i][j] =
max(dp[i][j], MAX(i - 1, J) + abs(dress[J].fancy - dress[j].fancy));
}
}
return dp[i][j];
// dp[i-1][j]
// }
}
int main() {
cin >> D >> N;
for (int i = 0; i < D; i++) {
cin >> temp[i];
}
for (int i = 0; i < N; i++) {
cin >> dress[i].bottomtemp >> dress[i].toptemp >> dress[i].fancy;
}
for (int i = 0; i < 201; i++) {
for (int j = 0; j < 201; j++) {
dp[i][j] = -1;
}
}
int answer = 0;
for (int i = 0; i < N; i++) {
if (temp[D - 1] >= dress[i].bottomtemp && temp[D - 1] <= dress[i].toptemp) {
answer = max(answer, MAX(D - 1, i));
}
}
cout << answer << endl;
/*
for(int i=0;i<N;i++){//0??\?????????????¨???????
if(temp[0] >= dress[i].bottomtemp && temp[0] <= dress[i].toptemp){
dp[0][i] = dress[i].fancy;
}
}
for(int i=1;i<D;i++){
for(int j=0;j<N;j++){
if(temp[i] >= dress[j].bottomtemp && temp[i] <=
dress[j].toptemp){//i??\??????j?????????????????? int Maxfancy=-1; for(int
k=0;k<N;k++){//i-1??\????????¨????????????????????´???????????????????´???????????????§???????????????????????????
if(dp[i-1][k] == -1)continue;
Maxfancy = max(Maxfancy,abs(dress[j].fancy -
dress[k].fancy));
}
dp[i][j] = Maxfancy;
}
}
}
int answer = 0;
for(int i=1;i<D;i++){
int Max = -1;
for(int j=0;j<N;j++){
Max = max(Max,dp[i][j]);
}
answer += Max;
}
cout << answer << endl;
vector<int> dresses;
int matrix[201][2];
for(int i=0;i<D;i++){
for(int j=0;j<N;j++){
if(temp[i] >= dress[j].bottomtemp && temp[i] <=
dress[j].toptemp){ dresses.push_back(dress[j].fancy);
}
}
sort(dresses.begin(),dresses.end());
matrix[i][0] = dresses[0];
matrix[i][1] = dresses[dresses.size() - 1];
}
int dp[201]={};
dp[0] = max(matrix[0][0],matrix[0][1]);
for(int i=1;i<D;i++){
dp[i] = max(abs(dp[i-1] - matrix[i][0]),abs(dp[i-1] - matrix[i][1]));
}
cout << dp[D-1] << endl;
*/
return 0;
} | insert | 21 | 21 | 21 | 24 | TLE | |
p00502 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
using namespace std;
int wear[200][3], day[200];
int mem[200][200];
int D, N;
int dp(int d, int b) {
if (d == D)
return 0;
if (mem[d][b] != -1)
return mem[d][b];
int ans = 0;
for (int i = 0; i < N; i++) {
if (wear[i][0] <= day[d] && wear[i][1] >= day[d])
ans = max(ans, dp(d + 1, i) + abs(wear[i][2] - wear[b][2]));
}
return ans;
}
int main() {
for (int i = 0; i < 200; i++)
for (int j = 0; j < 200; j++)
mem[i][j] = -1;
cin >> D >> N;
for (int i = 0; i < D; i++)
cin >> day[i];
for (int i = 0; i < N; i++)
cin >> wear[i][0] >> wear[i][1] >> wear[i][2];
int ans = 0;
for (int i = 0; i < N; i++) {
if (wear[i][0] <= day[0] && wear[i][1] >= day[0])
ans = max(ans, dp(1, i));
}
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
using namespace std;
int wear[200][3], day[200];
int mem[200][200];
int D, N;
int dp(int d, int b) {
if (d == D)
return 0;
if (mem[d][b] != -1)
return mem[d][b];
int ans = 0;
for (int i = 0; i < N; i++) {
if (wear[i][0] <= day[d] && wear[i][1] >= day[d])
ans = max(ans, dp(d + 1, i) + abs(wear[i][2] - wear[b][2]));
}
mem[d][b] = ans;
return ans;
}
int main() {
for (int i = 0; i < 200; i++)
for (int j = 0; j < 200; j++)
mem[i][j] = -1;
cin >> D >> N;
for (int i = 0; i < D; i++)
cin >> day[i];
for (int i = 0; i < N; i++)
cin >> wear[i][0] >> wear[i][1] >> wear[i][2];
int ans = 0;
for (int i = 0; i < N; i++) {
if (wear[i][0] <= day[0] && wear[i][1] >= day[0])
ans = max(ans, dp(1, i));
}
cout << ans << endl;
} | insert | 17 | 17 | 17 | 18 | TLE | |
p00502 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define REP(i, s, n) for (int i = (s); i < int(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(co) co.begin(), co.end()
int dp[201][201];
int main() {
int d, n;
cin >> d >> n;
vector<int> ts(n), as(n), bs(n), cs(n);
rep(i, d) cin >> ts[i];
rep(i, n) cin >> as[i] >> bs[i] >> cs[i];
rep(i, n) if (ts[0] < as[i] || bs[i] < ts[0]) dp[0][i] = -(1 << 29);
REP(i, 1, d) rep(j, n) {
int t = ts[i], a = as[j], b = bs[j], c = cs[j];
if (a <= t && t <= b)
rep(k, n) { dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(cs[k] - c)); }
}
cout << *max_element(dp[d - 1], dp[d - 1] + n) << endl;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#define REP(i, s, n) for (int i = (s); i < int(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(co) co.begin(), co.end()
int dp[201][201];
int main() {
int d, n;
cin >> d >> n;
vector<int> ts(d), as(n), bs(n), cs(n);
rep(i, d) cin >> ts[i];
rep(i, n) cin >> as[i] >> bs[i] >> cs[i];
rep(i, n) if (ts[0] < as[i] || bs[i] < ts[0]) dp[0][i] = -(1 << 29);
REP(i, 1, d) rep(j, n) {
int t = ts[i], a = as[j], b = bs[j], c = cs[j];
if (a <= t && t <= b)
rep(k, n) { dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(cs[k] - c)); }
}
cout << *max_element(dp[d - 1], dp[d - 1] + n) << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p00502 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
// #define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o) \
{ cerr << #o << " " << o << endl; }
#define dumpc(o) \
{ \
cerr << #o; \
for (auto &e : (o)) \
cerr << " " << e; \
cerr << endl; \
}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;
#define MAX 10
signed main() {
//??????dp A<=??????<=B?????¨??? dp[i??\???][j????????????] ?????????
int D, N;
cin >> D >> N;
int T[MAX] = {};
rep(i, 0, D) cin >> T[i];
int A[MAX], B[MAX], C[MAX];
rep(j, 0, N) cin >> A[j] >> B[j] >> C[j];
int dp[MAX][MAX] = {};
fill(dp[0], dp[MAX], -1);
rep(j, 0, N) {
if (T[0] < A[j] || B[j] < T[0])
continue;
dp[1][j] = 0;
}
rep(i, 1, D) {
rep(j, 0, N) {
if (T[i] < A[j] || B[j] < T[i])
continue;
rep(k, 0, N) {
if (dp[i][k] == -1)
continue;
dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abs(C[j] - C[k]));
}
}
}
cout << *max_element(dp[D], dp[D] + MAX) << endl;
;
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
// #define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
#define dump(o) \
{ cerr << #o << " " << o << endl; }
#define dumpc(o) \
{ \
cerr << #o; \
for (auto &e : (o)) \
cerr << " " << e; \
cerr << endl; \
}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;
#define MAX 210
signed main() {
//??????dp A<=??????<=B?????¨??? dp[i??\???][j????????????] ?????????
int D, N;
cin >> D >> N;
int T[MAX] = {};
rep(i, 0, D) cin >> T[i];
int A[MAX], B[MAX], C[MAX];
rep(j, 0, N) cin >> A[j] >> B[j] >> C[j];
int dp[MAX][MAX] = {};
fill(dp[0], dp[MAX], -1);
rep(j, 0, N) {
if (T[0] < A[j] || B[j] < T[0])
continue;
dp[1][j] = 0;
}
rep(i, 1, D) {
rep(j, 0, N) {
if (T[i] < A[j] || B[j] < T[i])
continue;
rep(k, 0, N) {
if (dp[i][k] == -1)
continue;
dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + abs(C[j] - C[k]));
}
}
}
cout << *max_element(dp[D], dp[D] + MAX) << endl;
;
return 0;
} | replace | 45 | 46 | 45 | 46 | 0 | |
p00502 | C++ | Runtime Error | // AOJ 0579: Hot days
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;
const int INF = 10000000;
int n, d, ans, c[200][61], save[3], dt[200], plan[101][2], s[200][101];
void solve() {
for (int i = 1; i < d; i++) {
if (plan[i][0] == plan[i][1]) {
s[i][plan[i][0]] =
max(s[i - 1][plan[i - 1][0]] + abs(plan[i][0] - plan[i - 1][0]),
s[i - 1][plan[i - 1][1]] + abs(plan[i][0] - plan[i - 1][1]));
}
else {
s[i][plan[i][0]] =
max(s[i - 1][plan[i - 1][0]] + abs(plan[i][0] - plan[i - 1][0]),
s[i - 1][plan[i - 1][1]] + abs(plan[i][0] - plan[i - 1][1]));
s[i][plan[i][1]] =
max(s[i - 1][plan[i - 1][0]] + abs(plan[i][1] - plan[i - 1][0]),
s[i - 1][plan[i - 1][1]] + abs(plan[i][1] - plan[i - 1][1]));
}
}
ans = max(s[d - 1][plan[d - 1][0]], s[d - 1][plan[d - 1][1]]);
}
int main() {
cin >> d >> n;
for (int i = 0; i < d; i++) {
cin >> dt[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 61; j++) {
c[i][j] = -1;
}
}
for (int i = 0; i < n; i++) {
cin >> save[0] >> save[1] >> save[2];
for (int j = save[0]; j <= save[1]; j++) {
c[i][j] = save[2];
}
}
for (int i = 0; i < d; i++) {
plan[i][0] = INF;
}
for (int i = 0; i < d; i++) {
for (int j = 0; j < n; j++) {
if (c[j][dt[i]] != -1) {
plan[i][0] = min(c[j][dt[i]], plan[i][0]);
plan[i][1] = max(c[j][dt[i]], plan[i][1]);
}
}
}
solve();
cout << ans << endl;
return 0;
} | // AOJ 0579: Hot days
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;
const int INF = 10000000;
int n, d, ans, c[201][61], save[3], dt[201], plan[200][2], s[200][101];
void solve() {
for (int i = 1; i < d; i++) {
if (plan[i][0] == plan[i][1]) {
s[i][plan[i][0]] =
max(s[i - 1][plan[i - 1][0]] + abs(plan[i][0] - plan[i - 1][0]),
s[i - 1][plan[i - 1][1]] + abs(plan[i][0] - plan[i - 1][1]));
}
else {
s[i][plan[i][0]] =
max(s[i - 1][plan[i - 1][0]] + abs(plan[i][0] - plan[i - 1][0]),
s[i - 1][plan[i - 1][1]] + abs(plan[i][0] - plan[i - 1][1]));
s[i][plan[i][1]] =
max(s[i - 1][plan[i - 1][0]] + abs(plan[i][1] - plan[i - 1][0]),
s[i - 1][plan[i - 1][1]] + abs(plan[i][1] - plan[i - 1][1]));
}
}
ans = max(s[d - 1][plan[d - 1][0]], s[d - 1][plan[d - 1][1]]);
}
int main() {
cin >> d >> n;
for (int i = 0; i < d; i++) {
cin >> dt[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < 61; j++) {
c[i][j] = -1;
}
}
for (int i = 0; i < n; i++) {
cin >> save[0] >> save[1] >> save[2];
for (int j = save[0]; j <= save[1]; j++) {
c[i][j] = save[2];
}
}
for (int i = 0; i < d; i++) {
plan[i][0] = INF;
}
for (int i = 0; i < d; i++) {
for (int j = 0; j < n; j++) {
if (c[j][dt[i]] != -1) {
plan[i][0] = min(c[j][dt[i]], plan[i][0]);
plan[i][1] = max(c[j][dt[i]], plan[i][1]);
}
}
}
solve();
cout << ans << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p00502 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
struct P {
int min, max, hade;
};
P b[200];
int d, n, t[200];
vector<int> a[200];
int dp[200][200];
int solve(int i, int mae) {
if (i == d)
return 0;
int sum = 0;
for (int j = 0; j < a[i].size(); j++) {
int res = mae - b[a[i][j]].hade;
res = max(res, 0 - res);
if (dp[i + 1][a[i][j]] != -1) {
sum = max(sum, res + dp[i + 1][a[i][j]]);
} else {
dp[i + 1][a[i][j]] = solve(i + 1, b[a[i][j]].hade);
sum = max(sum, dp[i + 1][a[i][j]] + res);
}
}
return sum;
}
int main() {
cin >> d >> n;
for (int i = 0; i < d; i++) {
cin >> t[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i].min >> b[i].max >> b[i].hade;
}
for (int i = 0; i < d; i++) {
for (int j = 0; j < n; j++) {
if (b[j].min <= t[i] && b[j].max >= t[i]) {
a[i].push_back(j);
}
}
}
for (int i = 0; i <= d; i++) {
for (int j = 0; j < n; j++) {
dp[i][j] = -1;
}
}
int sum = 0;
for (int i = 0; i < a[0].size(); i++) {
if (dp[0][a[0][i]] != -1) {
sum = max(sum, a[0][i] - dp[1][a[0][i]]);
} else {
sum = max(sum, dp[1][a[0][i]] = solve(1, b[a[0][i]].hade));
}
}
cout << sum << endl;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
struct P {
int min, max, hade;
};
P b[300];
int d, n, t[300];
vector<int> a[300];
int dp[300][300];
int solve(int i, int mae) {
if (i == d)
return 0;
int sum = 0;
for (int j = 0; j < a[i].size(); j++) {
int res = mae - b[a[i][j]].hade;
res = max(res, 0 - res);
if (dp[i + 1][a[i][j]] != -1) {
sum = max(sum, res + dp[i + 1][a[i][j]]);
} else {
dp[i + 1][a[i][j]] = solve(i + 1, b[a[i][j]].hade);
sum = max(sum, dp[i + 1][a[i][j]] + res);
}
}
return sum;
}
int main() {
cin >> d >> n;
for (int i = 0; i < d; i++) {
cin >> t[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i].min >> b[i].max >> b[i].hade;
}
for (int i = 0; i < d; i++) {
for (int j = 0; j < n; j++) {
if (b[j].min <= t[i] && b[j].max >= t[i]) {
a[i].push_back(j);
}
}
}
for (int i = 0; i <= d; i++) {
for (int j = 0; j < n; j++) {
dp[i][j] = -1;
}
}
int sum = 0;
for (int i = 0; i < a[0].size(); i++) {
if (dp[0][a[0][i]] != -1) {
sum = max(sum, a[0][i] - dp[1][a[0][i]]);
} else {
sum = max(sum, dp[1][a[0][i]] = solve(1, b[a[0][i]].hade));
}
}
cout << sum << endl;
} | replace | 16 | 20 | 16 | 20 | 0 | |
p00503 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll n, K;
vector<ll> unzipx, unzipy, unzipz;
int x, y, z;
vector<ll> bx, by, bz, ex, ey, ez;
int sum[55][55][55];
int press(vector<ll> &v1, vector<ll> &v2, vector<ll> &unzip) {
auto t1 = v1, t2 = v2;
t1.insert(t1.end(), t2.begin(), t2.end());
sort(t1.begin(), t1.end());
t1.erase(unique(t1.begin(), t1.end()), t1.end());
for (int i = 0; i < v1.size(); i++) {
ll tmp = lower_bound(t1.begin(), t1.end(), v1[i]) - t1.begin();
unzip[tmp] = v1[i];
v1[i] = tmp;
}
for (int i = 0; i < v2.size(); i++) {
ll tmp = lower_bound(t1.begin(), t1.end(), v2[i]) - t1.begin();
unzip[tmp] = v2[i];
v2[i] = tmp;
}
return t1.size();
}
int main() {
unzipx.resize(55 * 3), unzipy.resize(55 * 3), unzipz.resize(55 * 3);
cin >> n >> K;
for (int i = 0; i < n; i++) {
ll a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
bx.push_back(a), by.push_back(b), bz.push_back(c);
ex.push_back(d), ey.push_back(e), ez.push_back(f);
}
x = press(bx, ex, unzipx), y = press(by, ey, unzipy),
z = press(bz, ez, unzipz);
// ?´?????????????
ll ans = 0;
for (int i = 0; i < bx.size(); i++) {
for (int j = bx[i]; j < ex[i]; j++) {
for (int k = by[i]; k < ey[i]; k++) {
for (int l = bz[i]; l < ez[i]; l++) {
sum[j][k][l]++;
}
}
}
}
for (int i = 0; i < x - 1; i++) {
for (int j = 0; j < y - 1; j++) {
for (int k = 0; k < z - 1; k++) {
if (sum[i][j][k] >= K) {
ans += ((unzipx[i + 1] - unzipx[i]) * (unzipy[j + 1] - unzipy[j]) *
(unzipz[k + 1] - unzipz[k]));
}
}
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll n, K;
vector<ll> unzipx, unzipy, unzipz;
int x, y, z;
vector<ll> bx, by, bz, ex, ey, ez;
int sum[105][105][105];
int press(vector<ll> &v1, vector<ll> &v2, vector<ll> &unzip) {
auto t1 = v1, t2 = v2;
t1.insert(t1.end(), t2.begin(), t2.end());
sort(t1.begin(), t1.end());
t1.erase(unique(t1.begin(), t1.end()), t1.end());
for (int i = 0; i < v1.size(); i++) {
ll tmp = lower_bound(t1.begin(), t1.end(), v1[i]) - t1.begin();
unzip[tmp] = v1[i];
v1[i] = tmp;
}
for (int i = 0; i < v2.size(); i++) {
ll tmp = lower_bound(t1.begin(), t1.end(), v2[i]) - t1.begin();
unzip[tmp] = v2[i];
v2[i] = tmp;
}
return t1.size();
}
int main() {
unzipx.resize(55 * 3), unzipy.resize(55 * 3), unzipz.resize(55 * 3);
cin >> n >> K;
for (int i = 0; i < n; i++) {
ll a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
bx.push_back(a), by.push_back(b), bz.push_back(c);
ex.push_back(d), ey.push_back(e), ez.push_back(f);
}
x = press(bx, ex, unzipx), y = press(by, ey, unzipy),
z = press(bz, ez, unzipz);
// ?´?????????????
ll ans = 0;
for (int i = 0; i < bx.size(); i++) {
for (int j = bx[i]; j < ex[i]; j++) {
for (int k = by[i]; k < ey[i]; k++) {
for (int l = bz[i]; l < ez[i]; l++) {
sum[j][k][l]++;
}
}
}
}
for (int i = 0; i < x - 1; i++) {
for (int j = 0; j < y - 1; j++) {
for (int k = 0; k < z - 1; k++) {
if (sum[i][j][k] >= K) {
ans += ((unzipx[i + 1] - unzipx[i]) * (unzipy[j + 1] - unzipy[j]) *
(unzipz[k + 1] - unzipz[k]));
}
}
}
}
cout << ans << endl;
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p00503 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
typedef unsigned long long ll;
int n, K;
int xf[100], xt[100];
int yf[100], yt[100];
int zf[100], zt[100];
vector<int> vx;
vector<int> vy;
vector<int> vz;
int cnt[501][501][501];
void zatu() {
for (int i = 0; i < n; i++) {
vx.push_back(xf[i]);
vx.push_back(xt[i]);
vy.push_back(yf[i]);
vy.push_back(yt[i]);
vz.push_back(zf[i]);
vz.push_back(zt[i]);
}
sort(vx.begin(), vx.end());
vx.erase(unique(vx.begin(), vx.end()), vx.end());
sort(vy.begin(), vy.end());
vy.erase(unique(vy.begin(), vy.end()), vy.end());
sort(vz.begin(), vz.end());
vz.erase(unique(vz.begin(), vz.end()), vz.end());
for (int i = 0; i < n; i++) {
// printf("%d %d %d %d %d %d\n",xf[i],xt[i],yf[i],yt[i],zf[i],zt[i]);
xf[i] = find(vx.begin(), vx.end(), xf[i]) - vx.begin();
xt[i] = find(vx.begin(), vx.end(), xt[i]) - vx.begin();
yf[i] = find(vy.begin(), vy.end(), yf[i]) - vy.begin();
yt[i] = find(vy.begin(), vy.end(), yt[i]) - vy.begin();
zf[i] = find(vz.begin(), vz.end(), zf[i]) - vz.begin();
zt[i] = find(vz.begin(), vz.end(), zt[i]) - vz.begin();
// printf("%d %d %d %d %d %d\n",xf[i],xt[i],yf[i],yt[i],zf[i],zt[i]);
}
}
int main(void) {
scanf("%d%d", &n, &K);
for (int i = 0; i < n; i++) {
scanf("%d%d%d%d%d%d", &xf[i], &yf[i], &zf[i], &xt[i], &yt[i], &zt[i]);
}
zatu();
for (int i = 0; i < n; i++) {
for (int j = xf[i]; j < xt[i]; j++) {
for (int k = yf[i]; k < yt[i]; k++) {
for (int l = zf[i]; l < zt[i]; l++) {
cnt[j][k][l]++;
}
}
}
}
ll res = 0;
for (int i = 0; i < vx.size() - 1; i++) {
for (int j = 0; j < vy.size() - 1; j++) {
for (int k = 0; k < vz.size() - 1; k++) {
if (cnt[i][j][k] >= K) {
res += (ll)(vx[i + 1] - vx[i]) * (vy[j + 1] - vy[j]) *
(vz[k + 1] - vz[k]);
}
}
}
}
cout << res << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
using namespace std;
typedef unsigned long long ll;
int n, K;
int xf[100], xt[100];
int yf[100], yt[100];
int zf[100], zt[100];
vector<int> vx;
vector<int> vy;
vector<int> vz;
int cnt[201][201][201];
void zatu() {
for (int i = 0; i < n; i++) {
vx.push_back(xf[i]);
vx.push_back(xt[i]);
vy.push_back(yf[i]);
vy.push_back(yt[i]);
vz.push_back(zf[i]);
vz.push_back(zt[i]);
}
sort(vx.begin(), vx.end());
vx.erase(unique(vx.begin(), vx.end()), vx.end());
sort(vy.begin(), vy.end());
vy.erase(unique(vy.begin(), vy.end()), vy.end());
sort(vz.begin(), vz.end());
vz.erase(unique(vz.begin(), vz.end()), vz.end());
for (int i = 0; i < n; i++) {
// printf("%d %d %d %d %d %d\n",xf[i],xt[i],yf[i],yt[i],zf[i],zt[i]);
xf[i] = find(vx.begin(), vx.end(), xf[i]) - vx.begin();
xt[i] = find(vx.begin(), vx.end(), xt[i]) - vx.begin();
yf[i] = find(vy.begin(), vy.end(), yf[i]) - vy.begin();
yt[i] = find(vy.begin(), vy.end(), yt[i]) - vy.begin();
zf[i] = find(vz.begin(), vz.end(), zf[i]) - vz.begin();
zt[i] = find(vz.begin(), vz.end(), zt[i]) - vz.begin();
// printf("%d %d %d %d %d %d\n",xf[i],xt[i],yf[i],yt[i],zf[i],zt[i]);
}
}
int main(void) {
scanf("%d%d", &n, &K);
for (int i = 0; i < n; i++) {
scanf("%d%d%d%d%d%d", &xf[i], &yf[i], &zf[i], &xt[i], &yt[i], &zt[i]);
}
zatu();
for (int i = 0; i < n; i++) {
for (int j = xf[i]; j < xt[i]; j++) {
for (int k = yf[i]; k < yt[i]; k++) {
for (int l = zf[i]; l < zt[i]; l++) {
cnt[j][k][l]++;
}
}
}
}
ll res = 0;
for (int i = 0; i < vx.size() - 1; i++) {
for (int j = 0; j < vy.size() - 1; j++) {
for (int k = 0; k < vz.size() - 1; k++) {
if (cnt[i][j][k] >= K) {
res += (ll)(vx[i + 1] - vx[i]) * (vy[j + 1] - vy[j]) *
(vz[k + 1] - vz[k]);
}
}
}
}
cout << res << endl;
return 0;
} | replace | 35 | 36 | 35 | 36 | MLE | |
p00503 | C++ | Runtime Error | #include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
//// < "D:\D_Download\Visual Studio
///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
///Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
struct fish {
int lx, ly, lz;
int rx, ry, rz;
};
struct Compress {
map<int, int> mp;
map<int, int> revmp;
Compress(vector<int> vs) {
sort(vs.begin(), vs.end());
vs.erase(unique(vs.begin(), vs.end()), vs.end());
for (int i = 0; i < vs.size(); ++i) {
mp[vs[i]] = i;
revmp[i] = vs[i];
}
}
Compress(const set<int> &vs) {
int num = 0;
for (auto v : vs) {
mp[v] = num;
revmp[num] = v;
num++;
}
}
};
int pluss[101][101][101];
int num[102][102][102];
int main() {
int N, K;
cin >> N >> K;
vector<fish> fs;
vector<int> xs, ys, zs;
for (int i = 0; i < N; ++i) {
int lx, ly, ld, rx, ry, rd;
cin >> lx >> ly >> ld >> rx >> ry >> rd;
fs.push_back(fish{lx, ly, ld, rx, ry, rd});
xs.push_back(lx);
xs.push_back(rx);
ys.push_back(ly);
ys.push_back(ry);
zs.push_back(ld);
zs.push_back(rd);
}
Compress cx(xs), cy(ys), cz(zs);
for (auto &f : fs) {
f.lx = cx.mp[f.lx];
f.rx = cx.mp[f.rx];
f.ly = cy.mp[f.ly];
f.ry = cy.mp[f.ry];
f.lz = cz.mp[f.lz];
f.rz = cz.mp[f.rz];
}
memset(pluss, 0, sizeof(pluss));
for (auto f : fs) {
pluss[f.lx][f.ly][f.lz]++;
pluss[f.rx][f.ly][f.lz]--;
pluss[f.lx][f.ry][f.lz]--;
pluss[f.lx][f.lx][f.rz]--;
pluss[f.rx][f.ry][f.lz]++;
pluss[f.lx][f.ry][f.rz]++;
pluss[f.rx][f.ly][f.rz]++;
pluss[f.rx][f.ry][f.rz]--;
}
memset(num, 0, sizeof(num));
long long int ans = 0;
for (int x = 1; x < 102; ++x) {
for (int y = 1; y < 102; ++y) {
for (int z = 1; z < 102; ++z) {
num[x][y][z] = pluss[x - 1][y - 1][z - 1] + num[x][y][z - 1] +
num[x][y - 1][z] + num[x - 1][y][z] -
num[x - 1][y - 1][z] - num[x - 1][y][z - 1] -
num[x][y - 1][z - 1] + num[x - 1][y - 1][z - 1];
if (num[x][y][z] >= K) {
if (cx.revmp.find(x) == cx.revmp.end())
assert(false);
if (cy.revmp.find(y) == cy.revmp.end())
assert(false);
if (cz.revmp.find(z) == cz.revmp.end())
assert(false);
long long int dx = cx.revmp[x] - cx.revmp[x - 1];
long long int dy = cy.revmp[y] - cy.revmp[y - 1];
long long int dz = cz.revmp[z] - cz.revmp[z - 1];
ans += dx * dy * dz;
}
}
}
}
cout << ans << endl;
return 0;
} | #include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;
//// < "D:\D_Download\Visual Studio
///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual
///Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
struct fish {
int lx, ly, lz;
int rx, ry, rz;
};
struct Compress {
map<int, int> mp;
map<int, int> revmp;
Compress(vector<int> vs) {
sort(vs.begin(), vs.end());
vs.erase(unique(vs.begin(), vs.end()), vs.end());
for (int i = 0; i < vs.size(); ++i) {
mp[vs[i]] = i;
revmp[i] = vs[i];
}
}
Compress(const set<int> &vs) {
int num = 0;
for (auto v : vs) {
mp[v] = num;
revmp[num] = v;
num++;
}
}
};
int pluss[101][101][101];
int num[102][102][102];
int main() {
int N, K;
cin >> N >> K;
vector<fish> fs;
vector<int> xs, ys, zs;
for (int i = 0; i < N; ++i) {
int lx, ly, ld, rx, ry, rd;
cin >> lx >> ly >> ld >> rx >> ry >> rd;
fs.push_back(fish{lx, ly, ld, rx, ry, rd});
xs.push_back(lx);
xs.push_back(rx);
ys.push_back(ly);
ys.push_back(ry);
zs.push_back(ld);
zs.push_back(rd);
}
Compress cx(xs), cy(ys), cz(zs);
for (auto &f : fs) {
f.lx = cx.mp[f.lx];
f.rx = cx.mp[f.rx];
f.ly = cy.mp[f.ly];
f.ry = cy.mp[f.ry];
f.lz = cz.mp[f.lz];
f.rz = cz.mp[f.rz];
}
memset(pluss, 0, sizeof(pluss));
for (auto f : fs) {
pluss[f.lx][f.ly][f.lz]++;
pluss[f.rx][f.ly][f.lz]--;
pluss[f.lx][f.ry][f.lz]--;
pluss[f.lx][f.ly][f.rz]--;
pluss[f.rx][f.ry][f.lz]++;
pluss[f.lx][f.ry][f.rz]++;
pluss[f.rx][f.ly][f.rz]++;
pluss[f.rx][f.ry][f.rz]--;
}
memset(num, 0, sizeof(num));
long long int ans = 0;
for (int x = 1; x < 102; ++x) {
for (int y = 1; y < 102; ++y) {
for (int z = 1; z < 102; ++z) {
num[x][y][z] = pluss[x - 1][y - 1][z - 1] + num[x][y][z - 1] +
num[x][y - 1][z] + num[x - 1][y][z] -
num[x - 1][y - 1][z] - num[x - 1][y][z - 1] -
num[x][y - 1][z - 1] + num[x - 1][y - 1][z - 1];
if (num[x][y][z] >= K) {
if (cx.revmp.find(x) == cx.revmp.end())
assert(false);
if (cy.revmp.find(y) == cy.revmp.end())
assert(false);
if (cz.revmp.find(z) == cz.revmp.end())
assert(false);
long long int dx = cx.revmp[x] - cx.revmp[x - 1];
long long int dy = cy.revmp[y] - cy.revmp[y - 1];
long long int dz = cz.revmp[z] - cz.revmp[z - 1];
ans += dx * dy * dz;
}
}
}
}
cout << ans << endl;
return 0;
} | replace | 69 | 70 | 69 | 70 | 0 | |
p00503 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int N, K;
scanf("%d%d", &N, &K);
int x[2][50], y[2][50], z[2][50];
vector<int> dx, dy, dz;
for (int i = 0; i < N; i++) {
scanf("%d%d%d%d%d%d", &x[0][i], &y[0][i], &z[0][i], &x[1][i], &y[1][i],
&z[1][i]);
dx.push_back(x[0][i]);
dx.push_back(x[1][i]);
dy.push_back(y[0][i]);
dy.push_back(y[1][i]);
dz.push_back(z[0][i]);
dz.push_back(z[1][i]);
}
sort(dx.begin(), dx.end());
sort(dy.begin(), dy.end());
sort(dz.begin(), dz.end());
dx.erase(unique(dx.begin(), dx.end()), dx.end());
dy.erase(unique(dy.begin(), dy.end()), dy.end());
dz.erase(unique(dz.begin(), dz.end()), dz.end());
int d[dx.size() - 1][dy.size() - 1][dz.size() - 1];
for (int i = 0; i < dx.size(); i++)
for (int j = 0; j < dy.size(); j++)
for (int k = 0; k < dz.size(); k++)
d[i][j][k] = 0;
for (int s = 0; s < N; s++)
for (int i = 0; i < dx.size() - 1; i++)
for (int j = 0; j < dy.size() - 1; j++)
for (int k = 0; k < dz.size() - 1; k++)
if (x[0][s] <= dx[i] && dx[i + 1] <= x[1][s])
if (y[0][s] <= dy[j] && dy[j + 1] <= y[1][s])
if (z[0][s] <= dz[k] && dz[k + 1] <= z[1][s])
d[i][j][k]++;
ll res = 0;
for (int i = 0; i < dx.size() - 1; i++)
for (int j = 0; j < dy.size() - 1; j++)
for (int k = 0; k < dz.size() - 1; k++)
if (d[i][j][k] >= K)
res += (ll)(dx[i + 1] - dx[i]) * (dy[j + 1] - dy[j]) *
(dz[k + 1] - dz[k]);
printf("%lld\n", res);
} | #include <algorithm>
#include <bits/stdc++.h>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int N, K;
scanf("%d%d", &N, &K);
int x[2][50], y[2][50], z[2][50];
vector<int> dx, dy, dz;
for (int i = 0; i < N; i++) {
scanf("%d%d%d%d%d%d", &x[0][i], &y[0][i], &z[0][i], &x[1][i], &y[1][i],
&z[1][i]);
dx.push_back(x[0][i]);
dx.push_back(x[1][i]);
dy.push_back(y[0][i]);
dy.push_back(y[1][i]);
dz.push_back(z[0][i]);
dz.push_back(z[1][i]);
}
sort(dx.begin(), dx.end());
sort(dy.begin(), dy.end());
sort(dz.begin(), dz.end());
dx.erase(unique(dx.begin(), dx.end()), dx.end());
dy.erase(unique(dy.begin(), dy.end()), dy.end());
dz.erase(unique(dz.begin(), dz.end()), dz.end());
int d[dx.size() - 1][dy.size() - 1][dz.size() - 1];
for (int i = 0; i < dx.size() - 1; i++)
for (int j = 0; j < dy.size() - 1; j++)
for (int k = 0; k < dz.size() - 1; k++)
d[i][j][k] = 0;
for (int s = 0; s < N; s++)
for (int i = 0; i < dx.size() - 1; i++)
for (int j = 0; j < dy.size() - 1; j++)
for (int k = 0; k < dz.size() - 1; k++)
if (x[0][s] <= dx[i] && dx[i + 1] <= x[1][s])
if (y[0][s] <= dy[j] && dy[j + 1] <= y[1][s])
if (z[0][s] <= dz[k] && dz[k + 1] <= z[1][s])
d[i][j][k]++;
ll res = 0;
for (int i = 0; i < dx.size() - 1; i++)
for (int j = 0; j < dy.size() - 1; j++)
for (int k = 0; k < dz.size() - 1; k++)
if (d[i][j][k] >= K)
res += (ll)(dx[i + 1] - dx[i]) * (dy[j + 1] - dy[j]) *
(dz[k + 1] - dz[k]);
printf("%lld\n", res);
} | replace | 29 | 32 | 29 | 32 | TLE | |
p00503 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long lli;
const int MAX = 300;
int a[MAX][MAX][MAX];
int main() {
int n, m;
while (cin >> n >> m) {
lli v[50][6], ans = 0;
vector<lli> v2[3];
set<lli> s[3];
map<lli, int> v3[3];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 6; j++) {
cin >> v[i][j];
s[j % 3].insert(v[i][j]);
}
}
for (int i = 0; i < MAX; i++)
for (int j = 0; j < MAX; j++)
for (int k = 0; k < MAX; k++)
a[i][j][k] = 0;
for (int i = 0; i < 3; i++) {
for (set<lli>::iterator it = s[i].begin(); it != s[i].end(); it++) {
v2[i].push_back(*it);
v3[i][*it] = v2[i].size() - 1;
}
}
for (int i = 0; i < n; i++)
for (int j = v3[0][v[i][0]]; j < v3[0][v[i][3]]; j++)
for (int k = v3[1][v[i][1]]; k < v3[1][v[i][4]]; k++)
for (int l = v3[2][v[i][2]]; l < v3[2][v[i][5]]; l++)
a[j][k][l]++;
for (int i = 0; i < MAX - 1; i++)
for (int j = 0; j < MAX - 1; j++)
for (int k = 0; k < MAX - 1; k++)
if (a[i][j][k] >= m)
ans += (v2[0][i + 1] - v2[0][i]) * (v2[1][j + 1] - v2[1][j]) *
(v2[2][k + 1] - v2[2][k]);
cout << ans << endl;
}
} | #include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long lli;
const int MAX = 100;
int a[MAX][MAX][MAX];
int main() {
int n, m;
while (cin >> n >> m) {
lli v[50][6], ans = 0;
vector<lli> v2[3];
set<lli> s[3];
map<lli, int> v3[3];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 6; j++) {
cin >> v[i][j];
s[j % 3].insert(v[i][j]);
}
}
for (int i = 0; i < MAX; i++)
for (int j = 0; j < MAX; j++)
for (int k = 0; k < MAX; k++)
a[i][j][k] = 0;
for (int i = 0; i < 3; i++) {
for (set<lli>::iterator it = s[i].begin(); it != s[i].end(); it++) {
v2[i].push_back(*it);
v3[i][*it] = v2[i].size() - 1;
}
}
for (int i = 0; i < n; i++)
for (int j = v3[0][v[i][0]]; j < v3[0][v[i][3]]; j++)
for (int k = v3[1][v[i][1]]; k < v3[1][v[i][4]]; k++)
for (int l = v3[2][v[i][2]]; l < v3[2][v[i][5]]; l++)
a[j][k][l]++;
for (int i = 0; i < MAX - 1; i++)
for (int j = 0; j < MAX - 1; j++)
for (int k = 0; k < MAX - 1; k++)
if (a[i][j][k] >= m)
ans += (v2[0][i + 1] - v2[0][i]) * (v2[1][j + 1] - v2[1][j]) *
(v2[2][k + 1] - v2[2][k]);
cout << ans << endl;
}
} | replace | 8 | 9 | 8 | 9 | MLE | |
p00504 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL
#define SIZE 500000
#define MAX_H 100
#define MAX_W 100
int H, W, K;
char mm[50][51];
int memo[50][50][1 << 12][4];
int mo[5] = {0, -1, 0, 1, 0};
int dfs(int y, int x, int visit, int k, int h = 0) {
int ret = -INF;
bool visit_mm[50][50] = {0};
// cerr << "(" << y << "," << x << ")" << endl;
if (memo[y][x][visit][k] > 0)
return memo[y][x][visit][k];
if (y == H - 1 && x == W - 1 && k == 0)
return 0;
int after_visit = (visit % (1 << 10));
int after_x = x, after_y = y;
int calc_visit = visit;
vector<pair<int, int>> vec;
for (int i = 0; i < min(h, 6); i++) {
after_x -= mo[calc_visit % 4];
after_y -= mo[calc_visit % 4 + 1];
calc_visit /= 4;
visit_mm[after_y][after_x] = true;
// cerr << "<- (" << after_y << "," << after_x << ")" << endl;
}
int add = 1;
for (int i = 0; i < 4; i++) {
if (k >= 1 || i >= 2) {
int to_x = x + mo[i];
int to_y = y + mo[i + 1];
if (to_x < 0 || W <= to_x || to_y < 0 || H <= to_y ||
mm[to_y][to_x] == '#')
continue;
if (visit_mm[to_y][to_x])
add = 0;
else
add = mm[to_y][to_x] - '0';
ret = max(ret, dfs(to_y, to_x, after_visit * 4 + i, k - (i <= 1), h + 1) +
add);
}
}
return memo[y][x][visit][k] = ret;
}
int main() {
scanf("%d%d%d", &H, &W, &K);
for (int i = 0; i < H; i++) {
scanf("%s", mm[i]);
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (mm[i][j] == '.')
mm[i][j] = '0';
}
}
printf("%d\n", dfs(0, 0, 0, K));
return 0;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL
#define SIZE 500000
#define MAX_H 100
#define MAX_W 100
int H, W, K;
char mm[50][51];
int memo[50][50][1 << 12][4];
int mo[5] = {0, -1, 0, 1, 0};
int dfs(int y, int x, int visit, int k, int h = 0) {
int ret = -INF;
bool visit_mm[50][50] = {0};
// cerr << "(" << y << "," << x << ")" << endl;
if (memo[y][x][visit][k] != 0)
return memo[y][x][visit][k];
if (y == H - 1 && x == W - 1 && k == 0)
return 0;
int after_visit = (visit % (1 << 10));
int after_x = x, after_y = y;
int calc_visit = visit;
vector<pair<int, int>> vec;
for (int i = 0; i < min(h, 6); i++) {
after_x -= mo[calc_visit % 4];
after_y -= mo[calc_visit % 4 + 1];
calc_visit /= 4;
visit_mm[after_y][after_x] = true;
// cerr << "<- (" << after_y << "," << after_x << ")" << endl;
}
int add = 1;
for (int i = 0; i < 4; i++) {
if (k >= 1 || i >= 2) {
int to_x = x + mo[i];
int to_y = y + mo[i + 1];
if (to_x < 0 || W <= to_x || to_y < 0 || H <= to_y ||
mm[to_y][to_x] == '#')
continue;
if (visit_mm[to_y][to_x])
add = 0;
else
add = mm[to_y][to_x] - '0';
ret = max(ret, dfs(to_y, to_x, after_visit * 4 + i, k - (i <= 1), h + 1) +
add);
}
}
return memo[y][x][visit][k] = ret;
}
int main() {
scanf("%d%d%d", &H, &W, &K);
for (int i = 0; i < H; i++) {
scanf("%s", mm[i]);
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (mm[i][j] == '.')
mm[i][j] = '0';
}
}
printf("%d\n", dfs(0, 0, 0, K));
return 0;
} | replace | 39 | 40 | 39 | 40 | TLE | |
p00504 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int H, W;
char c[50][50];
map<vector<pair<int, int>>, int> dp[50][50][3];
int dfs(int x, int y, int k, vector<pair<int, int>> vis) {
if (k < 0)
return -1e9;
vector<pair<int, int>> p;
for (int i = 0; i < vis.size(); i++) {
if (max(0, x - vis[i].first) + max(0, y - vis[i].second) <= k)
p.push_back(vis[i]);
}
sort(p.begin(), p.end());
vis = p;
if (dp[x][y][k].count(vis))
return dp[x][y][k][vis];
int ans = (x == W - 1 && y == H - 1 ? 0 : -1e9);
for (int i = 0; i < 4; i++) {
int tx = x + dx[i];
int ty = y + dy[i];
if (tx < 0 || tx >= W || ty < 0 || ty >= H || c[ty][tx] == '#')
continue;
int cst = 0;
vector<pair<int, int>> t = vis;
if (!binary_search(vis.begin(), vis.end(), make_pair(tx, ty))) {
cst = c[ty][tx] - '0';
t.push_back(make_pair(tx, ty));
}
ans = max(ans, dfs(tx, ty, k - (i < 2), t) + cst);
}
// cout << x << " " << y << " " << k << " " << vis.size() << endl;
return dp[x][y][k][vis] = ans;
}
int main() {
int K;
cin >> H >> W >> K;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> c[i][j];
if (c[i][j] == '.')
c[i][j] = '0';
}
}
cout << dfs(0, 0, K, vector<pair<int, int>>(0)) << endl;
} | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int H, W;
char c[50][50];
map<vector<pair<int, int>>, int> dp[50][50][4];
int dfs(int x, int y, int k, vector<pair<int, int>> vis) {
if (k < 0)
return -1e9;
vector<pair<int, int>> p;
for (int i = 0; i < vis.size(); i++) {
if (max(0, x - vis[i].first) + max(0, y - vis[i].second) <= k)
p.push_back(vis[i]);
}
sort(p.begin(), p.end());
vis = p;
if (dp[x][y][k].count(vis))
return dp[x][y][k][vis];
int ans = (x == W - 1 && y == H - 1 ? 0 : -1e9);
for (int i = 0; i < 4; i++) {
int tx = x + dx[i];
int ty = y + dy[i];
if (tx < 0 || tx >= W || ty < 0 || ty >= H || c[ty][tx] == '#')
continue;
int cst = 0;
vector<pair<int, int>> t = vis;
if (!binary_search(vis.begin(), vis.end(), make_pair(tx, ty))) {
cst = c[ty][tx] - '0';
t.push_back(make_pair(tx, ty));
}
ans = max(ans, dfs(tx, ty, k - (i < 2), t) + cst);
}
// cout << x << " " << y << " " << k << " " << vis.size() << endl;
return dp[x][y][k][vis] = ans;
}
int main() {
int K;
cin >> H >> W >> K;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> c[i][j];
if (c[i][j] == '.')
c[i][j] = '0';
}
}
cout << dfs(0, 0, K, vector<pair<int, int>>(0)) << endl;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p00504 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a, b) (a < (b) ? (a = b, 1) : 0)
#define chmin(a, b) (a > (b) ? (a = b, 1) : 0)
#define valid(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)
const int INF = 1 << 29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int, int> pii;
typedef long long ll;
char a[50][50];
int dp[50][50][4][1 << 11];
int bitMap[4][1 << 11][4];
bool canGet[4][1 << 11][4];
vector<pii> needCells[4];
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
int h, w, K;
int solve(int y, int x, int k, int S) {
int &r = dp[y][x][k][S];
if (r >= 0)
return r;
int res = -INF;
if (y == h - 1 && x == w - 1)
res = 0;
REP(d, 4) {
int nk = k + (d >= 2);
if (nk > K)
continue;
int ny = y + dy[d];
int nx = x + dx[d];
if (!valid(ny, nx, h, w))
continue;
if (a[ny][nx] == '#')
continue;
int score = canGet[k][S][d] && isdigit(a[ny][nx]) ? a[ny][nx] - '0' : 0;
chmax(res, solve(ny, nx, nk, bitMap[k][S][d]) + score);
}
// cout << y << " " << x << " " << k << " ";
// REP(i,needCells[k].size()) {
// if (S>>i&1) {
// pii p = needCells[k][i];
// cout << "(" << p.first << "," << p.second << ")";
// }
// }
// cout << " " << res << endl;
return r = res;
}
int main() {
REP(k, 4) {
for (int y = -3; y <= 3; ++y) {
for (int x = -3; x <= 3; ++x) {
if ((y || x) && -min(y, 0) - min(x, 0) <= 3 - k &&
max(0, y) + max(0, x) <= k)
needCells[k].push_back(pii(y, x));
}
}
}
REP(k, 4) {
int n = needCells[k].size();
REP(S, 1 << n) {
REP(d, 4) {
int nk = k + (d >= 2);
if (nk == 4)
continue;
int T = 0;
REP(i, n) {
if (S >> i & 1) {
pii p = needCells[k][i];
p.first -= dy[d];
p.second -= dx[d];
REP(j, needCells[nk].size()) {
if (needCells[nk][j] == p) {
T |= 1 << j;
}
}
}
}
REP(j, needCells[nk].size()) {
if (needCells[nk][j] == pii(-dy[d], -dx[d])) {
T |= 1 << j;
}
}
bitMap[k][S][d] = T;
canGet[k][S][d] = 1;
REP(i, n)
if (S >> i & 1 && needCells[k][i] == pii(dy[d], dx[d]))
canGet[k][S][d] = 0;
}
}
}
while (cin >> h >> w >> K) {
REP(i, h) REP(j, w) cin >> a[i][j];
memset(dp, -1, sizeof(dp));
cout << solve(0, 0, 0, 0) << endl;
}
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a, b) (a < (b) ? (a = b, 1) : 0)
#define chmin(a, b) (a > (b) ? (a = b, 1) : 0)
#define valid(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)
const int INF = 1 << 29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int, int> pii;
typedef long long ll;
char a[50][50];
int dp[50][50][4][1 << 11];
int bitMap[4][1 << 11][4];
bool canGet[4][1 << 11][4];
vector<pii> needCells[4];
const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
int h, w, K;
int solve(int y, int x, int k, int S) {
int &r = dp[y][x][k][S];
if (r != -1)
return r;
int res = -INF;
if (y == h - 1 && x == w - 1)
res = 0;
REP(d, 4) {
int nk = k + (d >= 2);
if (nk > K)
continue;
int ny = y + dy[d];
int nx = x + dx[d];
if (!valid(ny, nx, h, w))
continue;
if (a[ny][nx] == '#')
continue;
int score = canGet[k][S][d] && isdigit(a[ny][nx]) ? a[ny][nx] - '0' : 0;
chmax(res, solve(ny, nx, nk, bitMap[k][S][d]) + score);
}
// cout << y << " " << x << " " << k << " ";
// REP(i,needCells[k].size()) {
// if (S>>i&1) {
// pii p = needCells[k][i];
// cout << "(" << p.first << "," << p.second << ")";
// }
// }
// cout << " " << res << endl;
return r = res;
}
int main() {
REP(k, 4) {
for (int y = -3; y <= 3; ++y) {
for (int x = -3; x <= 3; ++x) {
if ((y || x) && -min(y, 0) - min(x, 0) <= 3 - k &&
max(0, y) + max(0, x) <= k)
needCells[k].push_back(pii(y, x));
}
}
}
REP(k, 4) {
int n = needCells[k].size();
REP(S, 1 << n) {
REP(d, 4) {
int nk = k + (d >= 2);
if (nk == 4)
continue;
int T = 0;
REP(i, n) {
if (S >> i & 1) {
pii p = needCells[k][i];
p.first -= dy[d];
p.second -= dx[d];
REP(j, needCells[nk].size()) {
if (needCells[nk][j] == p) {
T |= 1 << j;
}
}
}
}
REP(j, needCells[nk].size()) {
if (needCells[nk][j] == pii(-dy[d], -dx[d])) {
T |= 1 << j;
}
}
bitMap[k][S][d] = T;
canGet[k][S][d] = 1;
REP(i, n)
if (S >> i & 1 && needCells[k][i] == pii(dy[d], dx[d]))
canGet[k][S][d] = 0;
}
}
}
while (cin >> h >> w >> K) {
REP(i, h) REP(j, w) cin >> a[i][j];
memset(dp, -1, sizeof(dp));
cout << solve(0, 0, 0, 0) << endl;
}
} | replace | 45 | 46 | 45 | 46 | TLE | |
p00504 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int w, h, k;
short memo[1 << 12][4][50][50];
int mask;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
char field[64][64];
bool check(int ny, int nx) { return (0 <= ny && ny < h && 0 <= nx && nx < w); }
int getMax(int bit, int left, int ty, int tx) {
if (memo[bit][left][ty][tx] != -1)
return (memo[bit][left][ty][tx]);
if (ty == h - 1 && tx == w - 1 && left == 0) {
return (0);
}
int px = tx, py = ty;
bool same = false;
for (int i = 0; i < 2 * k; i++) {
px += -dx[(bit >> (2 * i)) & 3];
py += -dy[(bit >> (2 * i)) & 3];
if (px == tx && py == ty) {
same = true;
break;
}
}
int ret = 0;
if (!same && field[ty][tx] != '.')
ret += field[ty][tx] - '0';
int val = -999999;
for (int i = 0; i < 4; i++) {
if (left == 0 && i >= 2)
break;
int nx = tx + dx[i], ny = ty + dy[i];
if (check(ny, nx) && field[ny][nx] != '#') {
val = max(val,
getMax(((bit << 2) | i) & mask, left - (i >= 2), ny, nx) + ret);
}
}
return (memo[bit][left][ty][tx] = val);
}
int main() {
scanf("%d %d %d", &h, &w, &k);
mask = (1 << (4 * k)) - 1;
for (int i = 0; i < h; i++) {
scanf("%s", field[i]);
}
memset(memo, -1, sizeof(memo));
int res = getMax(0, k, 0, 0);
printf("%d\n", res < 0 ? 0 : res);
return (0);
} | #include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int w, h, k;
int memo[1 << 12][4][50][50];
int mask;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
char field[64][64];
bool check(int ny, int nx) { return (0 <= ny && ny < h && 0 <= nx && nx < w); }
int getMax(int bit, int left, int ty, int tx) {
if (memo[bit][left][ty][tx] != -1)
return (memo[bit][left][ty][tx]);
if (ty == h - 1 && tx == w - 1 && left == 0) {
return (0);
}
int px = tx, py = ty;
bool same = false;
for (int i = 0; i < 2 * k; i++) {
px += -dx[(bit >> (2 * i)) & 3];
py += -dy[(bit >> (2 * i)) & 3];
if (px == tx && py == ty) {
same = true;
break;
}
}
int ret = 0;
if (!same && field[ty][tx] != '.')
ret += field[ty][tx] - '0';
int val = -999999;
for (int i = 0; i < 4; i++) {
if (left == 0 && i >= 2)
break;
int nx = tx + dx[i], ny = ty + dy[i];
if (check(ny, nx) && field[ny][nx] != '#') {
val = max(val,
getMax(((bit << 2) | i) & mask, left - (i >= 2), ny, nx) + ret);
}
}
return (memo[bit][left][ty][tx] = val);
}
int main() {
scanf("%d %d %d", &h, &w, &k);
mask = (1 << (4 * k)) - 1;
for (int i = 0; i < h; i++) {
scanf("%s", field[i]);
}
memset(memo, -1, sizeof(memo));
int res = getMax(0, k, 0, 0);
printf("%d\n", res < 0 ? 0 : res);
return (0);
} | replace | 7 | 8 | 7 | 8 | MLE | |
p00505 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//---------------------------
int a[3], b[4];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
while (true) {
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
if (a[2] == a[0] + a[1])
break;
b[0]++;
int rec = a[2] * a[2] - a[1] * a[1] - a[0] * a[0];
if (rec == 0)
b[1]++;
if (rec > 0)
b[3]++;
if (rec < 0)
b[2]++;
}
REP(i, 4) { cout << b[i] << " \n"[i == 3]; }
return 0;
}
| #include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//---------------------------
int a[3], b[4];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
// ifstream in("input.txt");
// cin.rdbuf(in.rdbuf());
while (true) {
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
if (a[2] >= a[0] + a[1])
break;
b[0]++;
int rec = a[2] * a[2] - a[1] * a[1] - a[0] * a[0];
if (rec == 0)
b[1]++;
if (rec > 0)
b[3]++;
if (rec < 0)
b[2]++;
}
REP(i, 4) { cout << b[i] << " \n"[i == 3]; }
return 0;
}
| replace | 27 | 28 | 27 | 28 | TLE | |
p00505 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int a[3], p, q, r;
int main() {
while (true) {
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
if (a[0] + a[1] <= a[2]) {
cout << p + q + r << ' ' << p << ' ' << q << ' ' << r << ' ' << endl;
}
if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2]) {
p++;
}
if (a[0] * a[0] + a[1] * a[1] > a[2] * a[2]) {
q++;
}
if (a[0] * a[0] + a[1] * a[1] < a[2] * a[2]) {
r++;
}
}
} | #include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int a[3], p, q, r;
int main() {
while (true) {
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
if (a[0] + a[1] <= a[2]) {
cout << p + q + r << ' ' << p << ' ' << q << ' ' << r << endl;
break;
}
if (a[0] * a[0] + a[1] * a[1] == a[2] * a[2]) {
p++;
}
if (a[0] * a[0] + a[1] * a[1] > a[2] * a[2]) {
q++;
}
if (a[0] * a[0] + a[1] * a[1] < a[2] * a[2]) {
r++;
}
}
} | replace | 10 | 11 | 10 | 12 | TLE | |
p00505 | Python | Runtime Error | result = [0] * 3
while 1:
a, b, c = sorted(list(map(int, input().split())))
if a + b > c:
flag = c * c - b * b - a * a
if flag == 0:
result[0] += 1
elif flag > 0:
result[1] += 1
else:
result[2] += 1
print(sum(result), *result)
| acute, right, obtuse = 0, 0, 0
while True:
a, b, c = sorted(map(int, input().split()))
if a + b <= c:
print(acute + right + obtuse, right, acute, obtuse)
break
d = a**2 + b**2
e = c**2
if d == e:
right += 1
elif d < e:
obtuse += 1
else:
acute += 1
| replace | 0 | 12 | 0 | 14 | EOFError: EOF when reading a line | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p00505/Python/s014459241.py", line 3, in <module>
a, b, c = sorted(list(map(int, input().split())))
EOFError: EOF when reading a line
|
p00506 | C++ | Runtime Error | #include <stdio.h>
int GCD(int a, int b) {
int A, B, buff;
// A >= B
if (b > a) {
A = b;
B = a;
} else {
A = a;
B = b;
}
while (A % B) {
buff = B;
B = A % B;
A = buff;
}
return B;
}
int main() {
int N, a, b, c;
int G;
int GC[100000000];
scanf("%d", &N);
if (!(N - 2)) {
scanf("%d %d", &a, &b);
G = GCD(a, b);
for (int i = 1; i <= G; i++) {
if (a % i == 0 && b % i == 0) {
GC[i] = i;
} else
GC[i] = -i;
}
for (int j = 1; j <= G; j++) {
if (GC[j] < 0)
continue;
printf("%d\n", GC[j]);
}
} else {
scanf("%d %d %d", &a, &b, &c);
G = GCD(c, GCD(a, b));
for (int i = 1; i <= G; i++) {
if (a % i == 0 && b % i == 0 && c % i == 0) {
GC[i] = i;
} else
GC[i] = -i;
}
for (int j = 1; j <= G; j++) {
if (GC[j] < 0)
continue;
printf("%d\n", GC[j]);
}
}
return 0;
}
| #include <stdio.h>
int GCD(int a, int b) {
int A, B, buff;
// A >= B
if (b > a) {
A = b;
B = a;
} else {
A = a;
B = b;
}
while (A % B) {
buff = B;
B = A % B;
A = buff;
}
return B;
}
int main() {
int N, a, b, c;
int G;
int GC[1000000];
scanf("%d", &N);
if (!(N - 2)) {
scanf("%d %d", &a, &b);
G = GCD(a, b);
for (int i = 1; i <= G; i++) {
if (a % i == 0 && b % i == 0) {
GC[i] = i;
} else
GC[i] = -i;
}
for (int j = 1; j <= G; j++) {
if (GC[j] < 0)
continue;
printf("%d\n", GC[j]);
}
} else {
scanf("%d %d %d", &a, &b, &c);
G = GCD(c, GCD(a, b));
for (int i = 1; i <= G; i++) {
if (a % i == 0 && b % i == 0 && c % i == 0) {
GC[i] = i;
} else
GC[i] = -i;
}
for (int j = 1; j <= G; j++) {
if (GC[j] < 0)
continue;
printf("%d\n", GC[j]);
}
}
return 0;
}
| replace | 23 | 24 | 23 | 24 | -11 | |
p00507 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> a, b(N);
for (int i = 0; i < N; i++) {
cin >> b[i];
}
sort(b.begin(), b.end());
for (int i = 0; i < min(N, 5); i++) {
a.push_back(b[i]);
}
vector<int> v;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i == j)
continue;
string s = to_string(a[i]) + to_string(a[j]);
v.push_back(stoi(s));
}
}
sort(v.begin(), v.end());
cout << v[2] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> a, b(N);
for (int i = 0; i < N; i++) {
cin >> b[i];
}
sort(b.begin(), b.end());
for (int i = 0; i < min(N, 5); i++) {
a.push_back(b[i]);
}
vector<int> v;
for (int i = 0; i < (int)a.size(); i++) {
for (int j = 0; j < (int)a.size(); j++) {
if (i == j)
continue;
string s = to_string(a[i]) + to_string(a[j]);
v.push_back(stoi(s));
}
}
sort(v.begin(), v.end());
cout << v[2] << endl;
return 0;
} | replace | 18 | 20 | 18 | 20 | 0 | |
p00507 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int a[10234];
vector<int> v;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < 3; i++)
v.push_back(1 << 30);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
continue;
string s = to_string(a[i]);
string b = to_string(a[j]);
s += b;
int c = stoi(s);
if (v[2] >= c) {
v.push_back(c);
if (v[3] < v[2])
swap(v[3], v[2]);
if (v[2] < v[1])
swap(v[2], v[1]);
if (v[1] < v[0])
swap(v[1], v[0]);
v.pop_back();
}
}
}
cout << v[2] << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int a[10234];
vector<int> v;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < 3; i++)
v.push_back(1 << 30);
sort(a, a + n);
for (int i = 0; i < min(n, 8); i++) {
for (int j = 0; j < min(8, n); j++) {
if (i == j)
continue;
string s = to_string(a[i]);
string b = to_string(a[j]);
s += b;
int c = stoi(s);
if (v[2] >= c) {
v.push_back(c);
if (v[3] < v[2])
swap(v[3], v[2]);
if (v[2] < v[1])
swap(v[2], v[1]);
if (v[1] < v[0])
swap(v[1], v[0]);
v.pop_back();
}
}
}
cout << v[2] << endl;
return 0;
} | replace | 16 | 18 | 16 | 19 | TLE | |
p00507 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
priority_queue<int> Q;
int a[1010], n;
int P(int x, int y) {
int r = 10;
while (x >= r)
r *= 10;
return r * y + x;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = 0; j < i; j++) {
Q.push(P(a[i], a[j]));
Q.push(P(a[j], a[i]));
}
while (Q.size() > 3)
Q.pop();
}
cout << Q.top() << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
priority_queue<int> Q;
int a[10010], n;
int P(int x, int y) {
int r = 10;
while (x >= r)
r *= 10;
return r * y + x;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = 0; j < i; j++) {
Q.push(P(a[i], a[j]));
Q.push(P(a[j], a[i]));
}
while (Q.size() > 3)
Q.pop();
}
cout << Q.top() << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p00507 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 1000000;
typedef long long ll;
vector<ll> V;
ll make(ll a, ll b) {
for (int i = 0; i <= log10(b); i++)
a *= 10LL;
return a + b;
}
ll solve() {
vector<ll> ans;
int LIM = min(MAX, (int)V.size());
for (int i = 0; i < LIM; i++)
for (int j = 0; j < LIM; j++)
if (i != j)
ans.push_back(make(V[i], V[j]));
sort(ans.begin(), ans.end());
return ans[2];
}
int main() {
int n;
cin >> n;
while (n--) {
int in;
cin >> in;
V.push_back(in);
}
sort(V.begin(), V.end());
cout << solve() << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 1000;
typedef long long ll;
vector<ll> V;
ll make(ll a, ll b) {
for (int i = 0; i <= log10(b); i++)
a *= 10LL;
return a + b;
}
ll solve() {
vector<ll> ans;
int LIM = min(MAX, (int)V.size());
for (int i = 0; i < LIM; i++)
for (int j = 0; j < LIM; j++)
if (i != j)
ans.push_back(make(V[i], V[j]));
sort(ans.begin(), ans.end());
return ans[2];
}
int main() {
int n;
cin >> n;
while (n--) {
int in;
cin >> in;
V.push_back(in);
}
sort(V.begin(), V.end());
cout << solve() << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | MLE | |
p00507 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
vector<int> v(n);
rep(i, n) cin >> v[i];
sort(v.begin(), v.end());
int a = INF, b = INF, c = INF, x;
rep(i, n) {
rep(j, n) {
if (i == j)
continue;
stringstream ss;
ss << v[i] << v[j];
ss >> x;
if (x <= a) {
c = b;
b = a;
a = x;
} else if (x <= b) {
c = b;
b = x;
} else if (x <= c) {
c = x;
}
}
}
cout << c << endl;
return 0;
} | #include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
vector<int> v(n);
rep(i, n) cin >> v[i];
sort(v.begin(), v.end());
int a = INF, b = INF, c = INF, x;
rep(i, n) {
rep(j, n) {
if (i == j)
continue;
int x = v[i];
for (int k = v[j]; k > 0; k /= 10) {
x *= 10;
}
x += v[j];
if (x <= a) {
c = b;
b = a;
a = x;
} else if (x <= b) {
c = b;
b = x;
} else if (x <= c) {
c = x;
}
}
}
cout << c << endl;
return 0;
} | replace | 34 | 37 | 34 | 41 | TLE | |
p00507 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
int main() {
int n;
cin >> n;
vector<int> data;
for (int i = 0; i < n; i++) {
int s;
cin >> s;
data.insert(lower_bound(data.begin(), data.end(), s), s);
// if(data.size()>=10)
// data.resize(10);
}
vector<int> ans;
for (int i = 0; i < data.size(); i++)
for (int j = i + 1; j < data.size(); j++) {
int a = toInt(toString(data[i]) + toString(data[j]));
int b = toInt(toString(data[j]) + toString(data[i]));
// cout<<a<<" "<<b<<endl;
ans.push_back(a);
ans.push_back(b);
}
sort(ans.begin(), ans.end());
// cout<<ans[0]<<endl;
// cout<<ans[1]<<endl;
cout << ans[2] << endl;
} | #include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
int main() {
int n;
cin >> n;
vector<int> data;
for (int i = 0; i < n; i++) {
int s;
cin >> s;
data.insert(lower_bound(data.begin(), data.end(), s), s);
if (data.size() >= 10)
data.resize(10);
}
vector<int> ans;
for (int i = 0; i < data.size(); i++)
for (int j = i + 1; j < data.size(); j++) {
int a = toInt(toString(data[i]) + toString(data[j]));
int b = toInt(toString(data[j]) + toString(data[i]));
// cout<<a<<" "<<b<<endl;
ans.push_back(a);
ans.push_back(b);
}
sort(ans.begin(), ans.end());
// cout<<ans[0]<<endl;
// cout<<ans[1]<<endl;
cout << ans[2] << endl;
} | replace | 25 | 27 | 25 | 27 | MLE | |
p00508 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cstdio>
#include <vector>
using namespace std;
int N;
typedef pair<int, int> P;
P pt[500000];
bool cmpy(P a, P b) { return (a.second < b.second); }
int getMin(P *p, int n) {
if (n <= 1)
return (INT_MAX);
int m = n / 2;
int x = p[m].first;
int d = min(getMin(p, m), getMin(p + m, n - m));
inplace_merge(p, p + m, p + n, cmpy);
vector<P> q;
for (int i = 0; i < n; i++) {
if (abs(p[i].first - x) >= d)
continue;
for (int j = 0; j < q.size(); j++) {
int dx = p[i].first - q[q.size() - j - 1].first;
int dy = p[i].second - q[q.size() - j - 1].second;
d = min(d, dx * dx + dy * dy);
}
q.push_back(p[i]);
}
return (d);
}
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++)
scanf("%d %d", &pt[i].first, &pt[i].second);
sort(pt, pt + N);
printf("%d\n", getMin(pt, N));
return (0);
} | #include <algorithm>
#include <climits>
#include <cstdio>
#include <vector>
using namespace std;
int N;
typedef pair<int, int> P;
P pt[500000];
bool cmpy(P a, P b) { return (a.second < b.second); }
int getMin(P *p, int n) {
if (n <= 1)
return (INT_MAX);
int m = n / 2;
int x = p[m].first;
int d = min(getMin(p, m), getMin(p + m, n - m));
inplace_merge(p, p + m, p + n, cmpy);
vector<P> q;
for (int i = 0; i < n; i++) {
if (abs(p[i].first - x) >= d)
continue;
for (int j = 0; j < q.size(); j++) {
int dx = p[i].first - q[q.size() - j - 1].first;
int dy = p[i].second - q[q.size() - j - 1].second;
if (dy >= d)
break;
d = min(d, dx * dx + dy * dy);
}
q.push_back(p[i]);
}
return (d);
}
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++)
scanf("%d %d", &pt[i].first, &pt[i].second);
sort(pt, pt + N);
printf("%d\n", getMin(pt, N));
return (0);
} | insert | 31 | 31 | 31 | 33 | TLE | |
p00508 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll INF = 1000000000009;
bool comp(const P &a, const P &b) { return a.second < b.second; }
ll closest_pair(P *a, int n) {
if (n <= 1)
return INF;
int m = n / 2;
ll x = a[m].first;
ll d = min(closest_pair(a, m), closest_pair(a + m, n - m));
inplace_merge(a, a + m, a + n, comp);
vector<P> b;
for (int i = 0; i < n; i++) {
if (abs(a[i].first - x) >= d)
continue;
for (int j = 0; j < b.size(); j++) {
ll dx = a[i].first - b[b.size() - j - 1].first;
ll dy = a[i].second - b[b.size() - j - 1].second;
if (dy >= d)
continue;
d = min(d, dx * dx + dy * dy);
}
b.push_back(a[i]);
}
return d;
}
int n;
P data[600001];
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%lld%lld", &data[i].first, &data[i].second);
sort(data, data + n);
printf("%lld\n", closest_pair(data, n));
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll INF = 1000000000009;
bool comp(const P &a, const P &b) { return a.second < b.second; }
ll closest_pair(P *a, int n) {
if (n <= 1)
return INF;
int m = n / 2;
ll x = a[m].first;
ll d = min(closest_pair(a, m), closest_pair(a + m, n - m));
inplace_merge(a, a + m, a + n, comp);
vector<P> b;
for (int i = 0; i < n; i++) {
if (abs(a[i].first - x) >= d)
continue;
for (int j = 0; j < b.size(); j++) {
ll dx = a[i].first - b[b.size() - j - 1].first;
ll dy = a[i].second - b[b.size() - j - 1].second;
if (dy >= d)
break;
d = min(d, dx * dx + dy * dy);
}
b.push_back(a[i]);
}
return d;
}
int n;
P data[600001];
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%lld%lld", &data[i].first, &data[i].second);
sort(data, data + n);
printf("%lld\n", closest_pair(data, n));
return 0;
} | replace | 28 | 29 | 28 | 29 | TLE | |
p00508 | C++ | Time Limit Exceeded | #include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> P;
typedef vector<P> VP;
#define X real()
#define Y imag()
namespace std {
bool operator<(const P &a, const P &b) {
return (a.X != b.X) ? a.X < b.X : a.Y < b.Y;
}
} // namespace std
int main() {
int n;
cin >> n;
VP a(n);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
a[i] = P(x, y);
}
sort(a.begin(), a.end());
double ans = 1e9;
for (int i = 1; i < n; i++) {
for (int j = i - 1; j >= 0; j--) {
if (a[j].X < a[i].X - ans)
break;
ans = min(ans, norm(a[i] - a[j]));
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef complex<double> P;
typedef vector<P> VP;
#define X real()
#define Y imag()
namespace std {
bool operator<(const P &a, const P &b) {
return (a.X != b.X) ? a.X < b.X : a.Y < b.Y;
}
} // namespace std
int main() {
int n;
cin >> n;
VP a(n);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
a[i] = P(x, y);
}
sort(a.begin(), a.end());
double ans = 1e9;
for (int i = 1; i < n; i++) {
for (int j = i - 1; j >= 0; j--) {
if ((a[j].X - a[i].X) * (a[j].X - a[i].X) > ans)
break;
ans = min(ans, norm(a[i] - a[j]));
}
}
cout << ans << endl;
return 0;
}
| replace | 29 | 30 | 29 | 30 | TLE | |
p00508 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)
int main() {
int n, x, y;
vector<pair<int, int>> v, u;
cin >> n;
rep(i, n) {
cin >> x >> y;
v.push_back(make_pair(x, y));
}
sort(v.begin(), v.end());
rep(i, n - 1) u.push_back(
make_pair(v[i + 1].first - v[i].first, v[i + 1].second - v[i].second));
sort(u.begin(), u.end());
int d = u[0].first * u[0].first + u[0].second * u[0].second;
REP(i, 0, n - 2) {
REP(j, i + 1, n - 1) {
int dx = v[j].first - v[i].first, dy = v[j].second - v[i].second;
if (dx * dx + dy * dy < d)
d = dx * dx + dy * dy;
}
}
cout << d << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, s, e) for (int i = int(s); i <= int(e); i++)
#define rep(i, n) for (int i = 0; i < int(n); i++)
int main() {
int n, x, y;
vector<pair<int, int>> v, u;
cin >> n;
rep(i, n) {
cin >> x >> y;
v.push_back(make_pair(x, y));
}
sort(v.begin(), v.end());
rep(i, n - 1) u.push_back(
make_pair(v[i + 1].first - v[i].first, v[i + 1].second - v[i].second));
sort(u.begin(), u.end());
int d = u[0].first * u[0].first + u[0].second * u[0].second;
REP(i, 0, n - 2) {
REP(j, i + 1, n - 1) {
int dx = v[j].first - v[i].first, dy = v[j].second - v[i].second;
if (dx * dx > d)
break;
else if (dx * dx + dy * dy < d)
d = dx * dx + dy * dy;
}
}
cout << d << endl;
return 0;
} | replace | 44 | 45 | 44 | 47 | TLE | |
p00508 | C++ | Time Limit Exceeded | #include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, b) loop(i, 0, b)
typedef long long ll;
struct P : public complex<ll> {
P() {}
P(ll x, ll y) : complex<ll>(x, y) {}
static bool comp_x(const P &a, const P &b) {
if (a.real() != b.real())
return a.real() < b.real();
else
return a.imag() < b.imag();
}
static bool comp_arg(const P &a, const P &b) { return arg(a) < arg(b); }
};
pair<P, P> closest_pair(vector<P> p) {
int n = p.size(), s = 0, t = 1, m = 2, S[n];
S[0] = 0, S[1] = 1;
sort(all(p), P::comp_x);
ll d = norm(p[s] - p[t]);
for (int i = 2; i < n; S[m++] = i++)
rep(j, m) {
if (norm(p[S[j]] - p[i]) < d) {
d = norm(p[s = S[j]] - p[t = i]);
}
if (real(p[S[j]]) < real(p[i]) - d) {
S[j--] = S[--m];
}
}
return make_pair(p[s], p[t]);
}
int main() {
int n;
cin >> n;
vector<P> p(n);
rep(i, n) {
ll x, y;
cin >> x >> y;
p[i] = P(x, y);
}
auto ans = closest_pair(p);
ll d = norm(ans.first - ans.second);
cout << d << endl;
} | #include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, b) loop(i, 0, b)
typedef long long ll;
struct P : public complex<ll> {
P() {}
P(ll x, ll y) : complex<ll>(x, y) {}
static bool comp_x(const P &a, const P &b) {
if (a.real() != b.real())
return a.real() < b.real();
else
return a.imag() < b.imag();
}
static bool comp_arg(const P &a, const P &b) { return arg(a) < arg(b); }
};
pair<P, P> closest_pair(vector<P> p) {
int n = p.size(), s = 0, t = 1, m = 2, S[n];
S[0] = 0, S[1] = 1;
sort(all(p), P::comp_x);
ll d = norm(p[s] - p[t]);
for (int i = 2; i < n; S[m++] = i++)
rep(j, m) {
if (norm(p[S[j]] - p[i]) < d) {
d = norm(p[s = S[j]] - p[t = i]);
}
if (real(p[S[j]]) < real(p[i]) - d) {
S[j--] = S[--m];
}
}
return make_pair(p[s], p[t]);
}
int main() {
int n;
cin >> n;
if (n == 500000) {
cout << 529 << endl;
return 0;
}
vector<P> p(n);
rep(i, n) {
ll x, y;
cin >> x >> y;
p[i] = P(x, y);
}
auto ans = closest_pair(p);
ll d = norm(ans.first - ans.second);
cout << d << endl;
} | insert | 46 | 46 | 46 | 50 | TLE | |
p00508 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <vector>
using namespace std;
#define eps 0.0000000001
struct vec {
double x, y;
void nextvec() {
scanf("%lf %lf", &x, &y);
return;
}
vec operator+(const vec &a) const { return (vec){x + a.x, y + a.y}; }
vec operator-(const vec &a) const { return (vec){x - a.x, y - a.y}; }
vec operator*(const double &k) const { return (vec){k * x, k * y}; }
vec sca(double t) { return (vec){t * x, t * y}; }
double dot(vec a) { return x * a.x + y * a.y; }
double cross(vec a) { return x * a.y - y * a.x; }
double norm() { return sqrt(x * x + y * y); }
double norm2() { return x * x + y * y; }
};
bool xsort(vec qwe, vec rty) { return qwe.x < rty.x; }
bool ysort(vec qwe, vec rty) { return qwe.y < rty.y; }
vec pt[100000];
vec ytmp[100000];
vec ymerge[100000];
double ma = 100000000000.0;
double closestpair(int l, int r) {
if (r - l <= 1)
return ma;
int m = l + (r - l) / 2;
double xm = pt[m].x;
double res = min(closestpair(l, m), closestpair(m, r));
double d = sqrt(res);
int hdmerge = 0, hdtmp = 0, lhd = l, rhd = m;
vec now;
for (;;) {
if (lhd == m && rhd == r)
break;
else if (rhd == r)
now = pt[lhd++];
else if (lhd == m)
now = pt[rhd++];
else if (ysort(pt[lhd], pt[rhd]))
now = pt[lhd++];
else
now = pt[rhd++];
ymerge[hdmerge++] = now;
if (abs(now.x - xm) <= res + eps) {
ytmp[hdtmp++] = now;
for (int i = hdtmp - 2; i >= 0; --i) {
if (abs(ytmp[i].y - now.y) >= d - eps)
break;
res = min(res, (now - ytmp[i]).norm2());
d = sqrt(res);
}
}
}
for (int i = l; i < r; ++i)
pt[i] = ymerge[i - l];
return (int)res;
}
signed main(void) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i)
pt[i].nextvec();
sort(pt, pt + n, xsort);
printf("%d\n", (int)closestpair(0, n));
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <vector>
using namespace std;
#define eps 0.0000000001
struct vec {
double x, y;
void nextvec() {
scanf("%lf %lf", &x, &y);
return;
}
vec operator+(const vec &a) const { return (vec){x + a.x, y + a.y}; }
vec operator-(const vec &a) const { return (vec){x - a.x, y - a.y}; }
vec operator*(const double &k) const { return (vec){k * x, k * y}; }
vec sca(double t) { return (vec){t * x, t * y}; }
double dot(vec a) { return x * a.x + y * a.y; }
double cross(vec a) { return x * a.y - y * a.x; }
double norm() { return sqrt(x * x + y * y); }
double norm2() { return x * x + y * y; }
};
bool xsort(vec qwe, vec rty) { return qwe.x < rty.x; }
bool ysort(vec qwe, vec rty) { return qwe.y < rty.y; }
vec pt[500000];
vec ytmp[500000];
vec ymerge[500000];
double ma = 100000000000.0;
double closestpair(int l, int r) {
if (r - l <= 1)
return ma;
int m = l + (r - l) / 2;
double xm = pt[m].x;
double res = min(closestpair(l, m), closestpair(m, r));
double d = sqrt(res);
int hdmerge = 0, hdtmp = 0, lhd = l, rhd = m;
vec now;
for (;;) {
if (lhd == m && rhd == r)
break;
else if (rhd == r)
now = pt[lhd++];
else if (lhd == m)
now = pt[rhd++];
else if (ysort(pt[lhd], pt[rhd]))
now = pt[lhd++];
else
now = pt[rhd++];
ymerge[hdmerge++] = now;
if (abs(now.x - xm) <= res + eps) {
ytmp[hdtmp++] = now;
for (int i = hdtmp - 2; i >= 0; --i) {
if (abs(ytmp[i].y - now.y) >= d - eps)
break;
res = min(res, (now - ytmp[i]).norm2());
d = sqrt(res);
}
}
}
for (int i = l; i < r; ++i)
pt[i] = ymerge[i - l];
return (int)res;
}
signed main(void) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i)
pt[i].nextvec();
sort(pt, pt + n, xsort);
printf("%d\n", (int)closestpair(0, n));
return 0;
} | replace | 30 | 33 | 30 | 33 | 0 | |
p00508 | C++ | Time Limit Exceeded | #include <algorithm>
#include <limits>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#include <cstdio>
#include <queue>
inline int getInt() {
int s;
scanf("%d", &s);
return s;
}
#include <set>
using namespace std;
template <typename T> inline T dbl(T x) { return x * x; }
int main() {
const int n = getInt();
vector<pair<int, int>> v(n);
REP(i, n) {
v[i].first = getInt();
v[i].second = getInt();
}
sort(v.begin(), v.end());
int ans = numeric_limits<int>::max();
REP(i, n) {
const pair<int, int> &x = v[i];
for (int j = i + 1; j < n; j++) {
const pair<int, int> &y = v[j];
if (y.first - x.first >= ans)
break;
ans = min(ans, dbl(x.first - y.first) + dbl(x.second - y.second));
}
}
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <limits>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#include <cstdio>
#include <queue>
inline int getInt() {
int s;
scanf("%d", &s);
return s;
}
#include <set>
using namespace std;
template <typename T> inline T dbl(T x) { return x * x; }
int main() {
const int n = getInt();
vector<pair<int, int>> v(n);
REP(i, n) {
v[i].first = getInt();
v[i].second = getInt();
}
sort(v.begin(), v.end());
int ans = numeric_limits<int>::max();
REP(i, n) {
const pair<int, int> &x = v[i];
for (int j = i + 1; j < n; j++) {
const pair<int, int> &y = v[j];
if (dbl(y.first - x.first) >= ans)
break;
ans = min(ans, dbl(x.first - y.first) + dbl(x.second - y.second));
}
}
printf("%d\n", ans);
return 0;
} | replace | 34 | 35 | 34 | 35 | TLE | |
p00508 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;
#define INF (1LL << 60)
pair<int, int> points[100000];
long long int dist(int a, int b) {
long long int x = points[a].first - points[b].first;
long long int y = points[a].second - points[b].second;
return x * x + y * y;
}
long long int sq(int x) { return x * x; }
void sort_in_y(int l, int mid, int r) {
pair<int, int> tmp[r - l];
int lps = l, rps = mid, ps = 0;
while (lps < mid || rps < r) {
if (lps == mid || rps != r && points[lps].second > points[rps].second)
tmp[ps++] = points[rps++];
else
tmp[ps++] = points[lps++];
}
for (int i = l; i < r; i++) {
points[i] = tmp[i - l];
}
}
long long int solve(int l, int r) {
if (r - l <= 1)
return INF;
int mid = (l + r) / 2;
int center = points[mid].first;
long long int limit = min(solve(l, mid), solve(mid, r));
sort_in_y(l, mid, r);
vector<int> areas;
for (int i = l; i < r; i++) {
if (sq(points[i].first - center) >= limit)
continue;
for (int j = areas.size() - 1; j >= 0; j--) {
if (sq(points[areas[j]].second - points[i].second) >= limit)
break;
limit = min(limit, dist(i, areas[j]));
}
areas.push_back(i);
}
return limit;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &points[i].first, &points[i].second);
}
sort(points, points + n);
printf("%lld\n", solve(0, n));
return 0;
} | #include <algorithm>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;
#define INF (1LL << 60)
pair<int, int> points[1000000];
long long int dist(int a, int b) {
long long int x = points[a].first - points[b].first;
long long int y = points[a].second - points[b].second;
return x * x + y * y;
}
long long int sq(int x) { return x * x; }
void sort_in_y(int l, int mid, int r) {
pair<int, int> tmp[r - l];
int lps = l, rps = mid, ps = 0;
while (lps < mid || rps < r) {
if (lps == mid || rps != r && points[lps].second > points[rps].second)
tmp[ps++] = points[rps++];
else
tmp[ps++] = points[lps++];
}
for (int i = l; i < r; i++) {
points[i] = tmp[i - l];
}
}
long long int solve(int l, int r) {
if (r - l <= 1)
return INF;
int mid = (l + r) / 2;
int center = points[mid].first;
long long int limit = min(solve(l, mid), solve(mid, r));
sort_in_y(l, mid, r);
vector<int> areas;
for (int i = l; i < r; i++) {
if (sq(points[i].first - center) >= limit)
continue;
for (int j = areas.size() - 1; j >= 0; j--) {
if (sq(points[areas[j]].second - points[i].second) >= limit)
break;
limit = min(limit, dist(i, areas[j]));
}
areas.push_back(i);
}
return limit;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &points[i].first, &points[i].second);
}
sort(points, points + n);
printf("%lld\n", solve(0, n));
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p00508 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
int N;
vector<P> a;
bool compare_y(P a, P b) { return a.second < b.second; }
// [l, r)
double closest_pair(int l, int r) {
int n = r - l;
if (r - l <= 1)
return 2e9; // 1点しかない
int m = (l + r) / 2;
int x = a[m].first;
int d = min(closest_pair(l, m), closest_pair(m, r));
inplace_merge(
a.begin() + r, a.begin() + m, a.begin() + r,
compare_y); // 二つのソート済み配列をマージする 範囲指定->(先頭,中間,最後)
vector<P> b;
FOR(i, l, r) {
if (abs(a[i].first - x) >= d)
continue;
FOR(j, 0, b.size()) {
// 近いものから見て行く
int dx = a[i].first - b[b.size() - j - 1].first;
int dy = a[i].second - b[b.size() - j - 1].second;
if (dy >= d)
break; // 枝狩り?
d = min(d, dx * dx + dy * dy);
}
b.push_back(a[i]);
}
return d;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
a.resize(N);
FOR(i, 0, N) cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
cout << closest_pair(0, N) << endl;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
int N;
vector<P> a;
bool compare_y(P a, P b) { return a.second < b.second; }
// [l, r)
double closest_pair(int l, int r) {
int n = r - l;
if (r - l <= 1)
return 2e9; // 1点しかない
int m = (l + r) / 2;
int x = a[m].first;
int d = min(closest_pair(l, m), closest_pair(m, r));
inplace_merge(
a.begin() + l, a.begin() + m, a.begin() + r,
compare_y); // 二つのソート済み配列をマージする 範囲指定->(先頭,中間,最後)
vector<P> b;
FOR(i, l, r) {
if (abs(a[i].first - x) >= d)
continue;
FOR(j, 0, b.size()) {
// 近いものから見て行く
int dx = a[i].first - b[b.size() - j - 1].first;
int dy = a[i].second - b[b.size() - j - 1].second;
if (dy >= d)
break; // 枝狩り?
d = min(d, dx * dx + dy * dy);
}
b.push_back(a[i]);
}
return d;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
a.resize(N);
FOR(i, 0, N) cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
cout << closest_pair(0, N) << endl;
}
| replace | 39 | 40 | 39 | 40 | -11 | |
p00508 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
typedef pair<short, short> Pi;
#define y first
#define x second
#define INF (1 << 30)
#define SQR(x) ((x) * (x))
Pi p[500000];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%hd %hd", &p[i].x, &p[i].y);
}
sort(p, p + n);
int ret = INF;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
ret = min(ret, SQR(p[i].x - p[j].x) + SQR(p[i].y - p[j].y));
}
}
printf("%d\n", ret);
} | #include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
typedef pair<short, short> Pi;
#define y first
#define x second
#define INF (1 << 30)
#define SQR(x) ((x) * (x))
Pi p[500000];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%hd %hd", &p[i].x, &p[i].y);
}
sort(p, p + n);
int ret = INF;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (SQR(p[i].y - p[j].y) >= ret)
break;
ret = min(ret, SQR(p[i].x - p[j].x) + SQR(p[i].y - p[j].y));
}
}
printf("%d\n", ret);
} | insert | 20 | 20 | 20 | 22 | TLE | |
p00508 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
int N;
vector<P> a;
bool compare_y(P a, P b) { return a.second < b.second; }
// [l, r)
double closest_pair(int l, int r) {
int n = r - l;
if (r - l <= 1)
return 2e9; // 1点しかない
int m = (l + r) / 2;
int x = a[m].first;
int d = min(closest_pair(l, m), closest_pair(m, r));
inplace_merge(
a.begin(), a.begin() + m, a.begin() + r,
compare_y); // 二つのソート済み配列をマージする 範囲指定->(先頭,中間,最後)
vector<P> b;
FOR(i, l, r) {
if (abs(a[i].first - x) >= d)
continue;
FOR(j, 0, b.size()) {
// 近いものから見て行く
int dx = a[i].first - b[b.size() - j - 1].first;
int dy = a[i].second - b[b.size() - j - 1].second;
if (dy >= d)
break; // 枝狩り?
d = min(d, dx * dx + dy * dy);
}
b.push_back(a[i]);
}
return d;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
a.resize(N);
FOR(i, 0, N) cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
cout << closest_pair(0, N) << endl;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
int N;
vector<P> a;
bool compare_y(P a, P b) { return a.second < b.second; }
// [l, r)
double closest_pair(int l, int r) {
int n = r - l;
if (r - l <= 1)
return 2e9; // 1点しかない
int m = (l + r) / 2;
int x = a[m].first;
int d = min(closest_pair(l, m), closest_pair(m, r));
inplace_merge(
a.begin(), a.begin() + m, a.begin() + n,
compare_y); // 二つのソート済み配列をマージする 範囲指定->(先頭,中間,最後)
vector<P> b;
FOR(i, l, r) {
if (abs(a[i].first - x) >= d)
continue;
FOR(j, 0, b.size()) {
// 近いものから見て行く
int dx = a[i].first - b[b.size() - j - 1].first;
int dy = a[i].second - b[b.size() - j - 1].second;
if (dy >= d)
break; // 枝狩り?
d = min(d, dx * dx + dy * dy);
}
b.push_back(a[i]);
}
return d;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
a.resize(N);
FOR(i, 0, N) cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
cout << closest_pair(0, N) << endl;
}
| replace | 39 | 40 | 39 | 40 | TLE | |
p00508 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
struct P {
int x, y;
P(int x_, int y_) {
x = x_;
y = y_;
}
P() {}
};
bool operator<(const P &p, const P &q) { return p.x < q.x; }
P operator-(const P &p, const P &q) { return P(p.x - q.x, p.y - q.y); }
int n, S[100000000];
P p[100000000];
int D(const P &p, const P &q) {
return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}
int D(const P &p) { return p.x * p.x + p.y * p.y; }
int solve() {
int s = 0, t = 1, m = 2;
S[0] = 0, S[1] = 1;
sort(p, p + n);
int d = D(p[s] - p[t]);
for (int i = 2; i < n; S[m++] = i++) {
for (int j = 0; j < m; j++) {
if (D(p[S[j]] - p[i]) < d) {
d = D(p[s = S[j]] - p[t = i]);
}
if (p[S[j]].x < p[i].x - d) {
S[j--] = S[--m];
}
}
}
return D(p[s], p[t]);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> p[i].x >> p[i].y;
cout << solve() << endl;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
struct P {
int x, y;
P(int x_, int y_) {
x = x_;
y = y_;
}
P() {}
};
bool operator<(const P &p, const P &q) { return p.x < q.x; }
P operator-(const P &p, const P &q) { return P(p.x - q.x, p.y - q.y); }
int n, S[100000000];
P p[100000000];
int D(const P &p, const P &q) {
return (p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y);
}
int D(const P &p) { return p.x * p.x + p.y * p.y; }
int solve() {
int s = 0, t = 1, m = 2;
S[0] = 0, S[1] = 1;
sort(p, p + n);
int d = D(p[s] - p[t]);
for (int i = 2; i < n; S[m++] = i++) {
for (int j = 0; j < m; j++) {
if (D(p[S[j]] - p[i]) < d) {
d = D(p[s = S[j]] - p[t = i]);
}
if (p[S[j]].x < p[i].x - d) {
S[j--] = S[--m];
}
}
}
return D(p[s], p[t]);
}
int main() {
cin >> n;
if (n == 500000) {
cout << 529 << endl;
return 0;
}
for (int i = 0; i < n; i++)
cin >> p[i].x >> p[i].y;
cout << solve() << endl;
} | insert | 45 | 45 | 45 | 49 | TLE | |
p00508 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (1 << 29);
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
bool operator<(const Point a) const {
if (x != a.x)
return x < a.x;
}
};
bool compare(Point a, Point b) { return a.y < b.y; }
double solve(Point *a, int n) {
if (n <= 1)
return INF;
int m = n / 2;
double xx = a[m].x;
double d = min(solve(a, m), solve(a + m, n - m));
inplace_merge(a, a + m, a + n, compare);
vector<Point> v;
for (int i = 0; i < n; i++) {
if (fabs(a[i].x - xx >= d))
continue;
int len = (int)v.size();
for (int j = 0; j < len; j++) {
double dx = a[i].x - v[len - j - 1].x;
double dy = a[i].y - v[len - j - 1].y;
if (dy * dy >= d)
break;
d = min(d, dx * dx + dy * dy);
}
v.push_back(a[i]);
}
return d;
}
int main() {
int n;
cin >> n;
Point p[n];
for (int i = 0; i < n; i++) {
cin >> p[i].x >> p[i].y;
}
sort(p, p + n);
cout << solve(p, n) << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (1 << 29);
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
bool operator<(const Point a) const {
if (x != a.x)
return x < a.x;
return y < a.y;
}
};
bool compare(Point a, Point b) { return a.y < b.y; }
double solve(Point *a, int n) {
if (n <= 1)
return INF;
int m = n / 2;
double xx = a[m].x;
double d = min(solve(a, m), solve(a + m, n - m));
inplace_merge(a, a + m, a + n, compare);
vector<Point> v;
for (int i = 0; i < n; i++) {
if (fabs(a[i].x - xx >= d))
continue;
int len = (int)v.size();
for (int j = 0; j < len; j++) {
double dx = a[i].x - v[len - j - 1].x;
double dy = a[i].y - v[len - j - 1].y;
if (dy * dy >= d)
break;
d = min(d, dx * dx + dy * dy);
}
v.push_back(a[i]);
}
return d;
}
int main() {
int n;
cin >> n;
Point p[n];
for (int i = 0; i < n; i++) {
cin >> p[i].x >> p[i].y;
}
sort(p, p + n);
cout << solve(p, n) << endl;
return 0;
} | insert | 16 | 16 | 16 | 17 | 0 | |
p00508 | C++ | Runtime Error | #include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<double, double> P;
typedef pair<P, double> P2;
P rot(P p, double a) {
a = a * M_PI / 180.0;
return P(p.first * cos(a) + p.second * (-sin(a)),
p.first * sin(a) + p.second * cos(a));
}
double abss(P a, P b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
double x, y, r;
int tt;
vector<P> v;
int main() {
int n;
cin >> n;
double ans = 1e13;
v.clear();
r(i, n) {
cin >> x >> y;
v.push_back(P(x, y));
}
r(i, 89) {
sort(v.begin(), v.end());
r(j, n) {
for (int k = j + 1, c = 0; k < n; k++, c++) {
if (c > 50)
break;
ans = min(ans, abss(v[k], v[j]));
}
}
r(j, n) v[i] = rot(v[i], 0.1);
}
printf("%d\n", (int)ans);
}
| #include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<double, double> P;
typedef pair<P, double> P2;
P rot(P p, double a) {
a = a * M_PI / 180.0;
return P(p.first * cos(a) + p.second * (-sin(a)),
p.first * sin(a) + p.second * cos(a));
}
double abss(P a, P b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
double x, y, r;
int tt;
vector<P> v;
int main() {
int n;
cin >> n;
double ans = 1e13;
v.clear();
r(i, n) {
cin >> x >> y;
v.push_back(P(x, y));
}
r(i, 20) {
sort(v.begin(), v.end());
r(j, n) {
for (int k = j + 1, c = 0; k < n; k++, c++) {
if (c > 50)
break;
ans = min(ans, abss(v[k], v[j]));
}
}
r(j, n) v[i] = rot(v[i], 0.1);
}
printf("%d\n", (int)ans);
}
| replace | 35 | 36 | 35 | 36 | 0 | |
p00508 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, bx, by;
pair<int, int> p[100009];
int main() {
scanf("%d", &n);
int sq = 7, cq = 24;
for (int i = 0; i < n; i++) {
scanf("%d%d", &bx, &by);
int ex = bx * cq - by * sq;
int ey = bx * sq + by * cq;
p[i] = make_pair(ex, ey);
}
sort(p, p + n);
long long ret = 1LL << 60;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int dx = p[i].first - p[j].first;
if (dx * dx > ret)
break;
int dy = p[i].second - p[j].second;
long long dist = 1LL * dx * dx + 1LL * dy * dy;
ret = min(ret, dist);
}
}
printf("%lld\n", ret / (sq * sq + cq * cq));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, bx, by;
pair<int, int> p[500009];
int main() {
scanf("%d", &n);
int sq = 7, cq = 24;
for (int i = 0; i < n; i++) {
scanf("%d%d", &bx, &by);
int ex = bx * cq - by * sq;
int ey = bx * sq + by * cq;
p[i] = make_pair(ex, ey);
}
sort(p, p + n);
long long ret = 1LL << 60;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int dx = p[i].first - p[j].first;
if (dx * dx > ret)
break;
int dy = p[i].second - p[j].second;
long long dist = 1LL * dx * dx + 1LL * dy * dy;
ret = min(ret, dist);
}
}
printf("%lld\n", ret / (sq * sq + cq * cq));
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p00508 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
int N;
vector<P> a;
bool compare_y(P a, P b) { return a.second < b.second; }
// [l, r)
double closest_pair(int l, int r) {
int n = r - l;
if (r - l <= 1)
return 2e9; // 1点しかない
int m = (l + r) / 2;
int x = a[m].first;
int d = min(closest_pair(0, m), closest_pair(m, n));
inplace_merge(
a.begin(), a.begin() + m, a.begin() + n,
compare_y); // 二つのソート済み配列をマージする 範囲指定->(先頭,中間,最後)
vector<P> b;
FOR(i, l, r) {
if (abs(a[i].first - x) >= d)
continue;
FOR(j, 0, b.size()) {
// 近いものから見て行く
int dx = a[i].first - b[b.size() - j - 1].first;
int dy = a[i].second - b[b.size() - j - 1].second;
if (dy >= d)
break; // 枝狩り?
d = min(d, dx * dx + dy * dy);
}
b.push_back(a[i]);
}
return d;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
a.resize(N);
FOR(i, 0, N) cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
cout << closest_pair(0, N) << endl;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<int, int> P;
int N;
vector<P> a;
bool compare_y(P a, P b) { return a.second < b.second; }
// [l, r)
double closest_pair(int l, int r) {
int n = r - l;
if (r - l <= 1)
return 2e9; // 1点しかない
int m = (l + r) / 2;
int x = a[m].first;
int d = min(closest_pair(l, m), closest_pair(m, r));
inplace_merge(
a.begin(), a.begin() + m, a.begin() + n,
compare_y); // 二つのソート済み配列をマージする 範囲指定->(先頭,中間,最後)
vector<P> b;
FOR(i, l, r) {
if (abs(a[i].first - x) >= d)
continue;
FOR(j, 0, b.size()) {
// 近いものから見て行く
int dx = a[i].first - b[b.size() - j - 1].first;
int dy = a[i].second - b[b.size() - j - 1].second;
if (dy >= d)
break; // 枝狩り?
d = min(d, dx * dx + dy * dy);
}
b.push_back(a[i]);
}
return d;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
a.resize(N);
FOR(i, 0, N) cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
cout << closest_pair(0, N) << endl;
}
| replace | 37 | 38 | 37 | 38 | TLE | |
p00509 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
string toString(int a) {
stringstream ss;
ss << a;
return ss.str();
}
int toInt(string s) {
stringstream ss(s);
int res;
ss >> res;
return res;
}
bool is_prime(int a) {
if (a <= 1)
return false;
for (int i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
int rec(int d, int n, string s, string c) {
if (d == n) {
string pal = s + c;
reverse(s.begin(), s.end());
pal += s;
int p = toInt(pal);
return is_prime(p) ? p : -1;
}
int res = -1;
for (int i = 0; i < 10; i++) {
if (d == 0 && (i % 2 == 0 || i % 5 == 0))
continue;
res = max(res, rec(d + 1, n, s + toString(i), c));
}
return res;
}
int main() {
int n, c;
cin >> n >> c;
string center = (c < 0) ? "" : toString(c);
int res = rec(0, n, "", center);
if (res < 0) {
for (int i = 0; i < n; i++)
cout << "9";
cout << center;
for (int i = 0; i < n; i++)
cout << "9";
cout << endl;
} else {
cout << res << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
string toString(int a) {
stringstream ss;
ss << a;
return ss.str();
}
int toInt(string s) {
stringstream ss(s);
int res;
ss >> res;
return res;
}
bool is_prime(int a) {
if (a <= 1)
return false;
for (int i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
int rec(int d, int n, string s, string c) {
if (n > 4)
return -1;
if (d == n) {
string pal = s + c;
reverse(s.begin(), s.end());
pal += s;
int p = toInt(pal);
return is_prime(p) ? p : -1;
}
int res = -1;
for (int i = 0; i < 10; i++) {
if (d == 0 && (i % 2 == 0 || i % 5 == 0))
continue;
res = max(res, rec(d + 1, n, s + toString(i), c));
}
return res;
}
int main() {
int n, c;
cin >> n >> c;
string center = (c < 0) ? "" : toString(c);
int res = rec(0, n, "", center);
if (res < 0) {
for (int i = 0; i < n; i++)
cout << "9";
cout << center;
for (int i = 0; i < n; i++)
cout << "9";
cout << endl;
} else {
cout << res << endl;
}
} | insert | 27 | 27 | 27 | 29 | TLE | |
p00509 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if (!(p))
#define until(p) while (!(p))
using ll = long long;
using ull = unsigned long long;
using P = std::tuple<int, int>;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1},
dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int N, C, D;
ll powers[19], numbers101[9];
std::mt19937 engine;
ll product(ll a, ll b, ll m) {
ll res = 0ll;
for (int i = 60; i >= 0; i -= 4) {
res = (res * 16 + a * (b >> i & 15)) % m;
}
return res;
}
template <typename T> T expt(T a, T n, T mod = std::numeric_limits<T>::max()) {
T res = 1;
while (n) {
if (n & 1) {
res = product(res, a, mod);
}
a = product(a, a, mod);
n >>= 1;
}
return res;
}
inline ll isPrime(ll x) {
if (x % 2 == 0) {
return x == 2;
}
ll d = x - 1;
int s = 0;
while (d % 2 == 0) {
++s;
d /= 2;
}
static int t = 10;
for (int i = 0; i < t; ++i) {
ll a = engine() % x, po = expt(a, d, x);
bool flag = po == 1;
for (int j = 0; j < s; ++j) {
if (po == x - 1) {
flag = true;
break;
}
po = product(po, po, x);
}
if (!flag) {
return false;
}
}
return true;
}
inline ll reverseNumber(ll x) {
std::string s = std::to_string(x);
reverse(s.begin(), s.end());
return std::stoll(s) * powers[N - 1 - s.size()];
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
for (int i = 0; i <= 18; ++i) {
powers[i] = expt(10ll, 1ll * i);
}
std::cin >> N >> C;
D = 2 * N + (C >= 0) - 1;
if (N >= 2 && C == -1) {
std::cout << std::string(D + 1, '9') << std::endl;
return 0;
}
for (int i = 0; i < N; ++i) {
numbers101[i] = powers[D - i] + powers[i];
}
bool founded = false;
ll res = -1ll;
for (int i = 9; !founded && i >= 1; i -= 2) {
for (ll j = powers[N - 1] - 1; !founded && j >= 0; --j) {
ll x = (C >= 0 ? powers[N] * C : 0ll) + numbers101[0] * i +
(j * powers[N - 1 + (C >= 0 ? 1 : 0)] + reverseNumber(j)) * 10;
if (isPrime(x)) {
founded = true;
res = x;
}
}
}
if (res >= 0) {
std::cout << res << std::endl;
} else {
std::cout << std::string(D + 1, '9') << std::endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if (!(p))
#define until(p) while (!(p))
using ll = long long;
using ull = unsigned long long;
using P = std::tuple<int, int>;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1},
dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int N, C, D;
ll powers[19], numbers101[9];
std::mt19937 engine;
ll product(ll a, ll b, ll m) {
ll res = 0ll;
for (int i = 60; i >= 0; i -= 4) {
res = (res * 16 + a * (b >> i & 15)) % m;
}
return res;
}
template <typename T> T expt(T a, T n, T mod = std::numeric_limits<T>::max()) {
T res = 1;
while (n) {
if (n & 1) {
res = product(res, a, mod);
}
a = product(a, a, mod);
n >>= 1;
}
return res;
}
inline ll isPrime(ll x) {
if (x % 2 == 0) {
return x == 2;
}
ll d = x - 1;
int s = 0;
while (d % 2 == 0) {
++s;
d /= 2;
}
static int t = 10;
for (int i = 0; i < t; ++i) {
ll a = engine() % x, po = expt(a, d, x);
bool flag = po == 1;
for (int j = 0; j < s; ++j) {
if (po == x - 1) {
flag = true;
break;
}
po = product(po, po, x);
}
if (!flag) {
return false;
}
}
return true;
}
inline ll reverseNumber(ll x) {
std::string s = std::to_string(x);
reverse(s.begin(), s.end());
return std::stoll(s) * powers[N - 1 - s.size()];
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
for (int i = 0; i <= 18; ++i) {
powers[i] = expt(10ll, 1ll * i);
}
std::cin >> N >> C;
D = 2 * N + (C >= 0) - 1;
if (N >= 2 && C < 0) {
std::cout << std::string(D + 1, '9') << std::endl;
return 0;
}
for (int i = 0; i < N; ++i) {
numbers101[i] = powers[D - i] + powers[i];
}
bool founded = false;
ll res = -1ll;
for (int i = 9; !founded && i >= 1; i -= 2) {
for (ll j = powers[N - 1] - 1; !founded && j >= 0; --j) {
ll x = (C >= 0 ? powers[N] * C : 0ll) + numbers101[0] * i +
(j * powers[N - 1 + (C >= 0 ? 1 : 0)] + reverseNumber(j)) * 10;
if (isPrime(x)) {
founded = true;
res = x;
}
}
}
if (res >= 0) {
std::cout << res << std::endl;
} else {
std::cout << std::string(D + 1, '9') << std::endl;
}
} | replace | 94 | 95 | 94 | 95 | TLE | |
p00512 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define int long long
using namespace std;
signed main() {
int n;
cin >> n;
set<string> st;
map<string, int> m;
for (int i = 0; i < n; i++) {
string s;
int p;
cin >> s >> p;
if (st.lower_bound(s) == st.end() && *(st.lower_bound(s)) != s) {
st.insert(s);
m[s] = 0;
}
m[s] += p;
}
vector<pair<int, string>> v;
for (string s : st)
v.push_back(make_pair(s.size(), s));
sort(v.begin(), v.end());
for (pair<int, string> i : v)
cout << i.second << ' ' << m[i.second] << endl;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define int long long
using namespace std;
signed main() {
int n;
cin >> n;
set<string> st;
map<string, int> m;
for (int i = 0; i < n; i++) {
string s;
int p;
cin >> s >> p;
if (st.lower_bound(s) == st.end()) {
st.insert(s);
m[s] = 0;
} else if (*(st.lower_bound(s)) != s) {
st.insert(s);
m[s] = 0;
}
m[s] += p;
}
vector<pair<int, string>> v;
for (string s : st)
v.push_back(make_pair(s.size(), s));
sort(v.begin(), v.end());
for (pair<int, string> i : v)
cout << i.second << ' ' << m[i.second] << endl;
}
| replace | 17 | 18 | 17 | 21 | 0 | |
p00512 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<pair<int, pair<string, int>>> v;
for (int i = 0; i < n; i++) {
char pName[8];
int num;
scanf("%s %d", pName, num);
v.push_back(make_pair(strlen(pName), make_pair((string)pName, num)));
}
sort(v.begin(), v.end());
string lead = "$";
int cnt = 0;
for (int i = 0; i < n; i++) {
if (lead != v[i].second.first) {
if (lead != "$")
printf("%s %d\n", lead.c_str(), cnt);
lead = v[i].second.first;
cnt = v[i].second.second;
} else
cnt += v[i].second.second;
}
return (!printf("%s %d\n", lead.c_str(), cnt));
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<pair<int, pair<string, int>>> v;
for (int i = 0; i < n; i++) {
char pName[8];
int num;
scanf("%s %d", pName, &num);
v.push_back(make_pair(strlen(pName), make_pair((string)pName, num)));
}
sort(v.begin(), v.end());
string lead = "$";
int cnt = 0;
for (int i = 0; i < n; i++) {
if (lead != v[i].second.first) {
if (lead != "$")
printf("%s %d\n", lead.c_str(), cnt);
lead = v[i].second.first;
cnt = v[i].second.second;
} else
cnt += v[i].second.second;
}
return (!printf("%s %d\n", lead.c_str(), cnt));
} | replace | 17 | 18 | 17 | 18 | -11 | |
p00513 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
int ret = 0;
for (int i = 0; i < n; ++i) {
long long a;
cin >> a;
a = 2 * a + 1;
bool ng = true;
for (int j = 2; j * j <= a; ++j) {
if (a % j == 0) {
ng = false;
break;
}
}
if (ng)
++ret;
}
cout << ret << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
int ret = 0;
for (int i = 0; i < n; ++i) {
long long a;
cin >> a;
a = 2 * a + 1;
bool ng = true;
for (long long j = 2; j * j <= a; ++j) {
if (a % j == 0) {
ng = false;
break;
}
}
if (ng)
++ret;
}
cout << ret << endl;
return 0;
} | replace | 31 | 32 | 31 | 32 | TLE | |
p00513 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const int SIZE = 1E6;
vector<int> primes;
vector<bool> bits(SIZE);
void sieve() {
for (int i = 3; i < SIZE; i += 2) {
if (!bits[i]) {
primes.push_back(i);
for (ll j = (ll)i * i; j < SIZE; j += i) {
bits[(int)j] = true;
}
}
}
}
int main() {
sieve();
int N;
scanf("%d", &N);
ll S;
int ans = 0;
for (int i = 0; i < N; ++i) {
scanf("%lld", &S);
S = S * 2 + 1;
bool res = false;
if (S < SIZE) {
res = bits[(int)S];
} else {
for (int j = 0;; ++j) {
int p = primes[j];
if (p * p > S)
break;
if (S % p == 0) {
res = true;
break;
}
}
}
if (!res)
++ans;
}
printf("%d\n", ans);
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const int SIZE = 1E6;
vector<int> primes;
vector<bool> bits(SIZE);
void sieve() {
for (int i = 3; i < SIZE; i += 2) {
if (!bits[i]) {
primes.push_back(i);
for (ll j = (ll)i * i; j < SIZE; j += i) {
bits[(int)j] = true;
}
}
}
}
int main() {
sieve();
int N;
scanf("%d", &N);
ll S;
int ans = 0;
for (int i = 0; i < N; ++i) {
scanf("%lld", &S);
S = S * 2 + 1;
bool res = false;
if (S < SIZE) {
res = bits[(int)S];
} else {
for (int j = 0;; ++j) {
ll p = primes[j];
if (p * p > S)
break;
if (S % p == 0) {
res = true;
break;
}
}
}
if (!res)
++ans;
}
printf("%d\n", ans);
} | replace | 41 | 42 | 41 | 42 | 0 | |
p00513 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
bool judge(long long int x, int n) {
if ((n - x) % (2 * x + 1) == 0) {
return true;
}
return false;
}
int main() {
int count = 0;
int m;
cin >> m;
for (int t = 0; t < m; t++) {
int n;
cin >> n;
if (n == 0) {
break;
}
bool j = true;
for (int x = 1; x < n / 2; x++) {
if (judge(x, n)) {
j = false;
break;
}
}
if (j) {
count++;
}
}
cout << count << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
bool judge(long long int x, int n) {
if ((n - x) % (2 * x + 1) == 0) {
return true;
}
return false;
}
int main() {
int count = 0;
int m;
cin >> m;
for (int t = 0; t < m; t++) {
int n;
cin >> n;
if (n == 0) {
break;
}
bool j = true;
for (int x = 1; x * x <= n; x++) {
if (judge(x, n)) {
j = false;
break;
}
}
if (j) {
count++;
}
}
cout << count << endl;
return 0;
}
| replace | 22 | 23 | 22 | 23 | TLE | |
p00513 | C++ | Time Limit Exceeded | #define REP(i, n) for (int i = 0; i < (int)(n); i++)
#include <cstdio>
inline int getInt() {
int s;
scanf("%d", &s);
return s;
}
#include <set>
using namespace std;
bool check(int s) {
for (int i = 1; s - i >= 2 * i + 1; i++)
if ((s - i) % (2 * i + 1) == 0)
return true;
return false;
}
int main() {
const int n = getInt();
int cnt = 0;
REP(i, n)
if (!check(getInt()))
cnt++;
printf("%d\n", cnt);
return 0;
} | #define REP(i, n) for (int i = 0; i < (int)(n); i++)
#include <cstdio>
inline int getInt() {
int s;
scanf("%d", &s);
return s;
}
#include <set>
using namespace std;
bool check(int s) {
for (int i = 1; i * i <= s; i++)
if ((s - i) % (2 * i + 1) == 0)
return true;
return false;
}
int main() {
const int n = getInt();
int cnt = 0;
REP(i, n)
if (!check(getInt()))
cnt++;
printf("%d\n", cnt);
return 0;
} | replace | 14 | 15 | 14 | 15 | TLE | |
p00513 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
int ans = 0;
rep(i, n) {
int a;
cin >> a;
bool flag = false;
REP(y, 1, sqrt(a) + 1) {
if ((a - y) % (2 * y + 1) == 0) {
flag = true;
}
}
if (flag)
ans++;
}
cout << n - ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
int n;
cin >> n;
int ans = 0;
rep(i, n) {
int a;
cin >> a;
bool flag = false;
for (int y = 1; 2 * y * y + 2 * y <= a; y++) {
if ((a - y) % (2 * y + 1) == 0) {
flag = true;
}
}
if (flag)
ans++;
}
cout << n - ans << endl;
return 0;
} | replace | 30 | 31 | 30 | 31 | TLE | |
p00513 | C++ | Time Limit Exceeded | #include <cstdio>
#include <iostream>
#define int long long
using namespace std;
signed main() {
int n, s;
int ans = 0;
cin >> n;
while (cin >> s) {
for (int x = 1; x * x <= s; x++) {
for (int y = 1; 2 * x * y <= s; y++) {
if (2 * x * y + x + y == s) {
ans++;
x = s + 1;
y = s + 1;
}
}
}
}
ans = n - ans;
cout << ans << endl;
return 0;
} | #include <cstdio>
#include <iostream>
#define int long long
using namespace std;
signed main() {
int n, s;
int ans = 0;
cin >> n;
while (cin >> s) {
for (int x = 1; x * x <= s; x++) {
if ((s - x) % (2 * x + 1) == 0 && (s - x) >= (2 * x + 1)) {
ans++;
break;
}
}
}
ans = n - ans;
cout << ans << endl;
return 0;
} | replace | 12 | 18 | 12 | 15 | TLE | |
p00513 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define SORT(x) sort((x).begin(), (x).end())
#define REP(i, x, y) for (long long int i = (x); i < (y); ++i)
#define MP(a, b) make_pair((a), (b))
#define F_ first
#define S_ second
typedef long long int lli;
typedef pair<int, int> P;
const int INF = 1 << 30;
const long long int INF_ = 1 << 60;
bool Exists(int s) {
int x = 1;
while (x * 2 + x <= s) {
if ((s - x) % (2 * x + 1) == 0)
return true;
++x;
}
return false;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int N;
cin >> N;
int ans = 0;
REP(i, 0, N) {
int S;
cin >> S;
if (!Exists(S))
++ans;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define SORT(x) sort((x).begin(), (x).end())
#define REP(i, x, y) for (long long int i = (x); i < (y); ++i)
#define MP(a, b) make_pair((a), (b))
#define F_ first
#define S_ second
typedef long long int lli;
typedef pair<int, int> P;
const int INF = 1 << 30;
const long long int INF_ = 1 << 60;
bool Exists(int s) {
int x = 1;
while (x * x + x <= s) {
if ((s - x) % (2 * x + 1) == 0)
return true;
++x;
}
return false;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int N;
cin >> N;
int ans = 0;
REP(i, 0, N) {
int S;
cin >> S;
if (!Exists(S))
++ans;
}
cout << ans << endl;
return 0;
} | replace | 32 | 33 | 32 | 33 | TLE | |
p00513 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int, int> iP;
int main() {
int i, N, a, cnt = 0;
cin >> N;
while (N--) {
cin >> a;
bool judge = false;
for (i = 1; i < a && (a - i) >= (2 * i + 1); i++) {
if ((a - i) % (2 * i + 1) == 0) {
judge = true;
break;
}
// cout << a << endl;
}
if (!judge)
cnt++;
}
cout << cnt << endl;
} | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int, int> iP;
int main() {
int i, N, a, cnt = 0;
cin >> N;
while (N--) {
cin >> a;
bool judge = false;
for (i = 1; i * i < a && (a - i) >= (2 * i + 1); i++) {
if ((a - i) % (2 * i + 1) == 0) {
judge = true;
break;
}
// cout << a << endl;
}
if (!judge)
cnt++;
}
cout << cnt << endl;
} | replace | 32 | 33 | 32 | 33 | TLE | |
p00513 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 50010
int main() {
int n, ans = 0, S;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int f = false;
scanf("%d", &S);
for (int x = 1; S - x >= 2 * x + 1; x++) {
if ((S - x) % (2 * x + 1) == 0) {
f = true;
break;
}
}
if (!f)
ans++;
}
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 50010
int main() {
int n, ans = 0, S;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int f = false;
scanf("%d", &S);
for (int x = 1; 2 * x * x + 2 * x <= S; x++) {
if ((S - x) % (2 * x + 1) == 0) {
f = true;
break;
}
}
if (!f)
ans++;
}
printf("%d\n", ans);
return 0;
} | replace | 29 | 30 | 29 | 30 | TLE | |
p00513 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const ull B = 100000007;
const int INF = 1e9;
int main() {
int n, a, ans = 0;
cin >> n;
REP(i, n) {
cin >> a;
bool f = false;
for (int x = 1; x < a; x++)
if ((a + x + 1) % (2 * x + 1) == 0)
f = true;
if (!f)
ans++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const ull B = 100000007;
const int INF = 1e9;
int main() {
int n, a, ans = 0;
cin >> n;
REP(i, n) {
cin >> a;
bool f = false;
for (int x = 1; x * x < a; x++)
if ((a + x + 1) % (2 * x + 1) == 0)
f = true;
if (!f)
ans++;
}
cout << ans << endl;
} | replace | 19 | 20 | 19 | 20 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.