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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p01086 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
int n;
int d_words[5] = {5, 7, 5, 7, 7};
while (cin >> n && n != 0) {
int *n_words = new int[n];
for (int i = 0; i < n; i++) {
string str;
cin >> str;
n_words[i] = str.size();
}
int start = 0;
int success = 0;
while (!success) {
int t_words = 0;
int tmp = start;
int tmp2 = 0;
while (1) {
tmp2 += n_words[tmp];
if (tmp2 == d_words[t_words]) {
t_words++;
if (t_words == 5) {
success = start + 1;
break;
}
} else if (tmp2 > d_words[t_words]) {
break;
}
tmp++;
}
start++;
}
cout << success << endl;
}
}
| #include <iostream>
#include <string>
using namespace std;
int main() {
int n;
int d_words[5] = {5, 7, 5, 7, 7};
while (cin >> n && n != 0) {
int *n_words = new int[n];
for (int i = 0; i < n; i++) {
string str;
cin >> str;
n_words[i] = str.size();
}
int start = 0;
int success = 0;
while (!success) {
int t_words = 0;
int tmp = start;
int tmp2 = 0;
while (1) {
tmp2 += n_words[tmp];
if (tmp2 == d_words[t_words]) {
t_words++;
tmp2 = 0;
if (t_words == 5) {
success = start + 1;
break;
}
} else if (tmp2 > d_words[t_words]) {
break;
}
tmp++;
}
start++;
}
cout << success << endl;
}
}
| insert | 24 | 24 | 24 | 25 | -11 | |
p01087 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x " = " << x << endl
#define print(x) cout << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;
#define INF INT_MAX / 3
#define MAX_N 1000000001
string s[10];
ll calc(int p, int q) {
bool add = false;
if ('0' <= s[p][s[p].length() - 1] && s[p][s[p].length() - 1] <= '9') {
return s[p][s[p].length() - 1] - '0';
} else if (s[p][s[p].length() - 1] == '+') {
add = true;
}
ll ans = ((add) ? 0 : 1);
repl(i, p + 1, q) {
if ('0' <= s[i][s[i].length() - 1] && s[i][s[i].length() - 1] <= '9') {
if (add)
ans += (s[i][s[i].length() - 1] - '0');
else
ans *= (s[i][s[i].length() - 1] - '0');
} else {
int j = i++;
while (i < q && s[j].length() < s[i].length())
i++;
if (add)
ans += calc(j, i);
else
ans *= calc(j, i);
i--;
}
}
return ans;
}
int main() {
cin.sync_with_stdio(false);
int n;
while (cin >> n, n) {
rep(i, n) cin >> s[i];
print(calc(0, n));
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x " = " << x << endl
#define print(x) cout << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;
#define INF INT_MAX / 3
#define MAX_N 1000000001
string s[20];
ll calc(int p, int q) {
bool add = false;
if ('0' <= s[p][s[p].length() - 1] && s[p][s[p].length() - 1] <= '9') {
return s[p][s[p].length() - 1] - '0';
} else if (s[p][s[p].length() - 1] == '+') {
add = true;
}
ll ans = ((add) ? 0 : 1);
repl(i, p + 1, q) {
if ('0' <= s[i][s[i].length() - 1] && s[i][s[i].length() - 1] <= '9') {
if (add)
ans += (s[i][s[i].length() - 1] - '0');
else
ans *= (s[i][s[i].length() - 1] - '0');
} else {
int j = i++;
while (i < q && s[j].length() < s[i].length())
i++;
if (add)
ans += calc(j, i);
else
ans *= calc(j, i);
i--;
}
}
return ans;
}
int main() {
cin.sync_with_stdio(false);
int n;
while (cin >> n, n) {
rep(i, n) cin >> s[i];
print(calc(0, n));
}
return 0;
} | replace | 31 | 32 | 31 | 32 | 0 | |
p01087 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define pi acos(-1.0)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
int calc(vector<string> s, int &i) {
int depth = s[i].length(), n = s.size();
char c = s[i][depth - 1];
if (c == '+') {
int res = 0;
i++;
while (s[i].length() == depth + 1 && i < n) {
res += calc(s, i);
}
return res;
} else if (c == '*') {
int res = 1;
i++;
while (s[i].length() == depth + 1 && i < n) {
res *= calc(s, i);
}
return res;
} else {
i++;
return c - '0';
}
}
int main() {
int n;
ifstream ifs("in.txt");
while (cin >> n && n) {
vector<string> s(n);
REP(i, n) cin >> s[i];
int i = 0;
cout << calc(s, i) << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define pi acos(-1.0)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
int calc(vector<string> s, int &i) {
int depth = s[i].length(), n = s.size();
char c = s[i][depth - 1];
if (c == '+') {
int res = 0;
i++;
while (s[i].length() == depth + 1 && i < n) {
res += calc(s, i);
}
return res;
} else if (c == '*') {
int res = 1;
i++;
while (s[i].length() == depth + 1 && i < n) {
res *= calc(s, i);
}
return res;
} else {
i++;
return c - '0';
}
}
int main() {
int n;
ifstream ifs("in.txt");
while (cin >> n && n) {
vector<string> s(n + 1);
REP(i, n) cin >> s[i];
int i = 0;
cout << calc(s, i) << endl;
}
return 0;
} | replace | 53 | 54 | 53 | 54 | 0 | |
p01087 | C++ | Runtime Error | #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef vector<pair<int, string>> vpis;
int parse(const vpis &v, int l, int r) {
if (v[l].second != "+" && v[l].second != "*")
return strtol(v[l].second.c_str(), NULL, 10);
int unit = v[l].second == "+" ? 0 : 1;
for (int i = l + 1; i < r;) {
int j = i + 1;
if (v[i].second == "+" || v[i].second == "*") {
for (; v[j].first > v[i].first; j++)
;
}
int n = parse(v, i, j);
i = j;
if (v[l].second == "+")
unit += n;
else
unit *= n;
}
return unit;
}
int main() {
int N;
string s;
for (; cin >> N, N;) {
vpis v(N);
for (int i = 0; i < N; i++) {
cin >> s;
int idx = 0;
for (; s[idx] == '.'; idx++)
;
v[i] = make_pair(idx, s.substr(idx));
}
printf("%d\n", parse(v, 0, N));
}
} | #include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef vector<pair<int, string>> vpis;
int parse(const vpis &v, int l, int r) {
if (v[l].second != "+" && v[l].second != "*")
return strtol(v[l].second.c_str(), NULL, 10);
int unit = v[l].second == "+" ? 0 : 1;
for (int i = l + 1; i < r;) {
int j = i + 1;
if (v[i].second == "+" || v[i].second == "*") {
for (; j < v.size() && v[j].first > v[i].first; j++)
;
}
int n = parse(v, i, j);
i = j;
if (v[l].second == "+")
unit += n;
else
unit *= n;
}
return unit;
}
int main() {
int N;
string s;
for (; cin >> N, N;) {
vpis v(N);
for (int i = 0; i < N; i++) {
cin >> s;
int idx = 0;
for (; s[idx] == '.'; idx++)
;
v[i] = make_pair(idx, s.substr(idx));
}
printf("%d\n", parse(v, 0, N));
}
} | replace | 14 | 15 | 14 | 15 | -11 | |
p01087 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;
////////
using pic = pair<int, char>;
#define mp make_pair
using psic = pair<stack<int>, char>;
pic parse(string &s) { return make_pair(s.length() - 1, s[s.length() - 1]); }
void calc(deque<psic> &q, int lv) {
while (q.size() > lv) {
psic p = q.back();
q.pop_back();
// cerr << q.size() << " " << p.second << endl;
if (p.second == '+') {
int ret = 0;
while (!p.first.empty()) {
ret += p.first.top();
p.first.pop();
}
q.back().first.push(ret);
} else if (p.second == '*') {
int ret = 1;
while (!p.first.empty()) {
ret *= p.first.top();
p.first.pop();
}
q.back().first.push(ret);
} else
assert(false);
}
}
int solve(deque<psic> &q) {
calc(q, 1);
psic p = q[0];
if (p.second == '+') {
int ret = 0;
while (!p.first.empty()) {
ret += p.first.top();
p.first.pop();
}
return ret;
} else if (p.second == '*') {
int ret = 1;
while (!p.first.empty()) {
ret *= p.first.top();
p.first.pop();
}
return ret;
} else
assert(false);
}
int main() {
int n;
while (cin >> n, n) {
int curlv = 0;
deque<psic> q;
q.push_back(mp(stack<int>(), '+'));
for (int i = 0; i < n; i++) {
string s;
cin >> s;
pic ps = parse(s);
cerr << ps.first << " " << ps.second << endl;
if (ps.first < curlv) {
calc(q, ps.first + 1);
curlv = ps.first;
if (ps.second == '+' || ps.second == '*') {
psic ne;
ne.second = ps.second;
q.push_back(ne);
curlv++;
} else {
q.back().first.push(((int)(ps.second - '0')));
}
} else if (ps.first == curlv) {
if (ps.second == '+' || ps.second == '*') {
psic ne;
ne.second = ps.second;
q.push_back(ne);
curlv++;
} else {
q.back().first.push(((int)(ps.second - '0')));
}
} else
assert(false);
}
cout << solve(q) << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;
////////
using pic = pair<int, char>;
#define mp make_pair
using psic = pair<stack<int>, char>;
pic parse(string &s) { return make_pair(s.length() - 1, s[s.length() - 1]); }
void calc(deque<psic> &q, int lv) {
while (q.size() > lv) {
psic p = q.back();
q.pop_back();
// cerr << q.size() << " " << p.second << endl;
if (p.second == '+') {
int ret = 0;
while (!p.first.empty()) {
ret += p.first.top();
p.first.pop();
}
q.back().first.push(ret);
} else if (p.second == '*') {
int ret = 1;
while (!p.first.empty()) {
ret *= p.first.top();
p.first.pop();
}
q.back().first.push(ret);
} else
assert(false);
}
}
int solve(deque<psic> &q) {
calc(q, 1);
psic p = q[0];
if (p.second == '+') {
int ret = 0;
while (!p.first.empty()) {
ret += p.first.top();
p.first.pop();
}
return ret;
} else if (p.second == '*') {
int ret = 1;
while (!p.first.empty()) {
ret *= p.first.top();
p.first.pop();
}
return ret;
} else
assert(false);
}
int main() {
int n;
while (cin >> n, n) {
int curlv = 0;
deque<psic> q;
q.push_back(mp(stack<int>(), '+'));
for (int i = 0; i < n; i++) {
string s;
cin >> s;
pic ps = parse(s);
// cerr << ps.first << " " << ps.second << endl;
if (ps.first < curlv) {
calc(q, ps.first + 1);
curlv = ps.first;
if (ps.second == '+' || ps.second == '*') {
psic ne;
ne.second = ps.second;
q.push_back(ne);
curlv++;
} else {
q.back().first.push(((int)(ps.second - '0')));
}
} else if (ps.first == curlv) {
if (ps.second == '+' || ps.second == '*') {
psic ne;
ne.second = ps.second;
q.push_back(ne);
curlv++;
} else {
q.back().first.push(((int)(ps.second - '0')));
}
} else
assert(false);
}
cout << solve(q) << endl;
}
}
| replace | 73 | 74 | 73 | 74 | 0 | 0 9
0 +
1 1
1 2
1 3
0 +
1 0
1 +
2 *
3 1
3 *
4 1
4 2
2 0
0 +
1 +
2 6
2 2
1 +
2 1
2 *
3 7
3 6
1 3
|
p01087 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int n;
string s[10];
int calc(int a, int b, bool m) {
int res = m;
for (int i = b; i < n; i++) {
if (s[i].size() <= a)
break;
if ('0' <= s[i][a] && s[i][a] <= '9') {
if (m)
res *= s[i][a] - '0';
else
res += s[i][a] - '0';
}
if (s[i][a] == '*') {
if (m)
res *= calc(a + 1, i + 1, 1);
else
res += calc(a + 1, i + 1, 1);
}
if (s[i][a] == '+') {
if (m)
res *= calc(a + 1, i + 1, 0);
else
res += calc(a + 1, i + 1, 0);
}
}
return res;
}
int main() {
while (scanf("%d", &n), n) {
rep(i, n) cin >> s[i];
printf("%d\n", calc(0, 0, 0));
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int n;
string s[50];
int calc(int a, int b, bool m) {
int res = m;
for (int i = b; i < n; i++) {
if (s[i].size() <= a)
break;
if ('0' <= s[i][a] && s[i][a] <= '9') {
if (m)
res *= s[i][a] - '0';
else
res += s[i][a] - '0';
}
if (s[i][a] == '*') {
if (m)
res *= calc(a + 1, i + 1, 1);
else
res += calc(a + 1, i + 1, 1);
}
if (s[i][a] == '+') {
if (m)
res *= calc(a + 1, i + 1, 0);
else
res += calc(a + 1, i + 1, 0);
}
}
return res;
}
int main() {
while (scanf("%d", &n), n) {
rep(i, n) cin >> s[i];
printf("%d\n", calc(0, 0, 0));
}
} | replace | 5 | 6 | 5 | 6 | 0 | |
p01087 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
static auto add = [](int a, int b) { return a + b; };
static auto mul = [](int a, int b) { return a * b; };
int n;
while (cin >> n, n) {
vector<string> a(n);
for (auto &e : a) {
cin >> e;
}
a.push_back("0");
vector<pair<function<int(int, int)>, int>> v{make_pair(add, 0)};
for (auto e : a) {
while (e.size() - 1 < v.size() - 1) {
(v.rbegin() - 1)->second =
(v.rbegin() - 1)
->first((v.rbegin() - 1)->second, v.rbegin()->second);
v.pop_back();
}
char c = *e.rbegin();
if (c == '+') {
v.push_back(make_pair(add, 0));
} else if (c == '*') {
v.push_back(make_pair(mul, 1));
} else {
v.rbegin()->second = v.rbegin()->first(v.rbegin()->second, c - '0');
}
}
cout << v.back().second << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
static auto add = [](int a, int b) { return a + b; };
static auto mul = [](int a, int b) { return a * b; };
int n;
while (cin >> n, n) {
vector<string> a(n);
for (auto &e : a) {
cin >> e;
}
a.push_back("0");
vector<pair<function<int(int, int)>, int>> v{make_pair(add, 0)};
for (auto e : a) {
while (e.size() - 1 < v.size() - 1) {
(v.rbegin() + 1)->second =
(v.rbegin() + 1)
->first((v.rbegin() + 1)->second, v.rbegin()->second);
v.pop_back();
}
char c = *e.rbegin();
if (c == '+') {
v.push_back(make_pair(add, 0));
} else if (c == '*') {
v.push_back(make_pair(mul, 1));
} else {
v.rbegin()->second = v.rbegin()->first(v.rbegin()->second, c - '0');
}
}
cout << v.back().second << endl;
}
return 0;
}
| replace | 16 | 19 | 16 | 19 | -6 | terminate called after throwing an instance of 'std::bad_function_call'
what(): bad_function_call
|
p01088 | C++ | Time Limit Exceeded | #include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int INF = 5000 * 100 * 3;
const int max_x = 102;
const int max_y = 25000;
int dp[max_x + 10][max_y + 10];
void solve(int n) {
// init
for (int j = 0; j < max_x + 10; j++)
for (int k = 0; k < max_y + 10; k++)
dp[j][k] = INF;
vector<int> p(n);
for (int i = 0; i < n; i++)
cin >> p[i];
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
const int &pi = p[i];
for (int x = n; x >= 0; x--) {
for (int y = max_y; y >= 0; y--) {
if (pi % 1000 <= 500) {
if (pi % 1000 > 0 && y - (500 - pi % 1000) >= 0 && x - 1 >= 0)
dp[x][y] = min(dp[x][y], dp[x - 1][y - (500 - pi % 1000)] + pi);
if (y + (pi % 1000 + 500) <= max_y && x - 1 >= 0)
dp[x][y] = min(dp[x][y], dp[x - 1][y + (pi % 1000 + 500)] + pi);
} else {
if (y + (pi % 1000 - 500) <= max_y && x - 1 >= 0)
dp[x][y] = min(dp[x][y], dp[x - 1][y + (pi % 1000 - 500)] + pi);
if (y - (1000 - pi % 1000) >= 0)
dp[x][y] = min(dp[x][y], dp[x][y - (1000 - pi % 1000)] + pi);
}
}
}
}
for (int i = 100; i >= 0; i--) {
int mn = INF;
for (int j = 0; j <= max_y; j++) {
if (dp[i][j] < INF) {
mn = min(mn, dp[i][j]);
}
}
if (mn != INF) {
cout << i << " " << mn << endl;
return;
}
}
}
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
solve(n);
}
}
| #include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
const int INF = 5000 * 100 * 3;
const int max_x = 102;
const int max_y = 12000;
int dp[max_x + 10][max_y + 10];
void solve(int n) {
// init
for (int j = 0; j < max_x + 10; j++)
for (int k = 0; k < max_y + 10; k++)
dp[j][k] = INF;
vector<int> p(n);
for (int i = 0; i < n; i++)
cin >> p[i];
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
const int &pi = p[i];
for (int x = n; x >= 0; x--) {
for (int y = max_y; y >= 0; y--) {
if (pi % 1000 <= 500) {
if (pi % 1000 > 0 && y - (500 - pi % 1000) >= 0 && x - 1 >= 0)
dp[x][y] = min(dp[x][y], dp[x - 1][y - (500 - pi % 1000)] + pi);
if (y + (pi % 1000 + 500) <= max_y && x - 1 >= 0)
dp[x][y] = min(dp[x][y], dp[x - 1][y + (pi % 1000 + 500)] + pi);
} else {
if (y + (pi % 1000 - 500) <= max_y && x - 1 >= 0)
dp[x][y] = min(dp[x][y], dp[x - 1][y + (pi % 1000 - 500)] + pi);
if (y - (1000 - pi % 1000) >= 0)
dp[x][y] = min(dp[x][y], dp[x][y - (1000 - pi % 1000)] + pi);
}
}
}
}
for (int i = 100; i >= 0; i--) {
int mn = INF;
for (int j = 0; j <= max_y; j++) {
if (dp[i][j] < INF) {
mn = min(mn, dp[i][j]);
}
}
if (mn != INF) {
cout << i << " " << mn << endl;
return;
}
}
}
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
solve(n);
}
}
| replace | 8 | 9 | 8 | 9 | TLE | |
p01088 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;
P dp[101][50501];
P pmax(P p, P q) {
if (p.fs > q.fs)
return p;
else if (p.fs == q.fs)
return (p.sc < q.sc ? p : q);
else
return q;
}
int main() {
int N;
while (cin >> N) {
if (!N)
return 0;
int p[N];
for (int i = 0; i < N; i++) {
cin >> p[i];
}
for (int i = 0; i <= N; i++) {
for (int j = 0; j < 50001; j++) {
if (j == 0)
dp[i][j] = mp(0, 0);
else
dp[i][j] = mp(-1, INF);
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < 50001; j++) {
if (dp[i][j].fs == -1) {
continue;
}
P d = dp[i][j];
dp[i + 1][j] = pmax(dp[i + 1][j], d);
d.sc += p[i];
int res = (1000 - p[i] % 1000) % 1000;
dp[i + 1][j + res] = pmax(dp[i + 1][j + res], d);
if (res >= 500) {
d.fs++;
res -= 500;
dp[i + 1][j + res] = pmax(dp[i + 1][j + res], d);
} else {
d.fs++;
res = 500 - res;
if (res <= j)
dp[i + 1][j - res] = pmax(dp[i + 1][j - res], d);
}
}
}
P ans = mp(0, LINF);
for (int i = 0; i <= 50000; i++) {
ans = pmax(ans, dp[N][i]);
}
cout << ans.fs << " " << ans.sc << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;
P dp[102][50501];
P pmax(P p, P q) {
if (p.fs > q.fs)
return p;
else if (p.fs == q.fs)
return (p.sc < q.sc ? p : q);
else
return q;
}
int main() {
int N;
while (cin >> N) {
if (!N)
return 0;
int p[N];
for (int i = 0; i < N; i++) {
cin >> p[i];
}
for (int i = 0; i <= N; i++) {
for (int j = 0; j < 50001; j++) {
if (j == 0)
dp[i][j] = mp(0, 0);
else
dp[i][j] = mp(-1, INF);
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < 50001; j++) {
if (dp[i][j].fs == -1) {
continue;
}
P d = dp[i][j];
dp[i + 1][j] = pmax(dp[i + 1][j], d);
d.sc += p[i];
int res = (1000 - p[i] % 1000) % 1000;
dp[i + 1][j + res] = pmax(dp[i + 1][j + res], d);
if (res >= 500) {
d.fs++;
res -= 500;
dp[i + 1][j + res] = pmax(dp[i + 1][j + res], d);
} else {
d.fs++;
res = 500 - res;
if (res <= j)
dp[i + 1][j - res] = pmax(dp[i + 1][j - res], d);
}
}
}
P ans = mp(0, LINF);
for (int i = 0; i <= 50000; i++) {
ans = pmax(ans, dp[N][i]);
}
cout << ans.fs << " " << ans.sc << endl;
}
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p01088 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
/*--------------------template--------------------*/
int n;
vi p;
pii dp[101][55555];
pii solve(int shop, int coin) {
if (shop == n)
return pii(0, 0);
if (dp[shop][coin].first >= 0)
return dp[shop][coin];
pii res(0, 0);
chmax(res, solve(shop + 1, coin));
pii tmp;
if (p[shop] % 1000 == 0) {
if (coin >= 500) {
tmp = solve(shop + 1, coin - 500);
chmax(res, pii(tmp.first + 1, tmp.second - p[shop]));
}
} else if (p[shop] % 1000 > 500) {
tmp = solve(shop + 1, coin + 1000 - p[shop] % 1000);
chmax(res, pii(tmp.first, tmp.second - p[shop]));
if (p[shop] % 1000 - 500 <= coin) {
tmp = solve(shop + 1, coin - (p[shop] % 1000 - 500));
chmax(res, pii(tmp.first + 1, tmp.second - p[shop]));
}
} else {
tmp = solve(shop + 1, coin + 500 - p[shop] % 1000);
chmax(res, pii(tmp.first + 1, tmp.second - p[shop]));
}
return res;
}
int main() {
cin.sync_with_stdio(false);
while (cin >> n, n) {
p.resize(n);
REP(i, n) cin >> p[i];
REP(i, 101) REP(j, 55555) dp[i][j] = pii(-1, -1);
pii ans = solve(0, 0);
cout << ans.first << " " << -ans.second << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
/*--------------------template--------------------*/
int n;
vi p;
pii dp[101][55555];
pii solve(int shop, int coin) {
if (shop == n)
return pii(0, 0);
if (dp[shop][coin].first >= 0)
return dp[shop][coin];
pii res(0, 0);
chmax(res, solve(shop + 1, coin));
pii tmp;
if (p[shop] % 1000 == 0) {
if (coin >= 500) {
tmp = solve(shop + 1, coin - 500);
chmax(res, pii(tmp.first + 1, tmp.second - p[shop]));
}
} else if (p[shop] % 1000 > 500) {
tmp = solve(shop + 1, coin + 1000 - p[shop] % 1000);
chmax(res, pii(tmp.first, tmp.second - p[shop]));
if (p[shop] % 1000 - 500 <= coin) {
tmp = solve(shop + 1, coin - (p[shop] % 1000 - 500));
chmax(res, pii(tmp.first + 1, tmp.second - p[shop]));
}
} else {
tmp = solve(shop + 1, coin + 500 - p[shop] % 1000);
chmax(res, pii(tmp.first + 1, tmp.second - p[shop]));
}
return dp[shop][coin] = res;
}
int main() {
cin.sync_with_stdio(false);
while (cin >> n, n) {
p.resize(n);
REP(i, n) cin >> p[i];
REP(i, 101) REP(j, 55555) dp[i][j] = pii(-1, -1);
pii ans = solve(0, 0);
cout << ans.first << " " << -ans.second << endl;
}
return 0;
} | replace | 47 | 48 | 47 | 48 | TLE | |
p01088 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define M 25000
int dp[2][101][M];
int main() {
int n;
while (cin >> n, n) {
int p[100], pp[100];
for (int i = 0; i < n; i++)
scanf("%d", &p[i]), pp[i] = (1000 - p[i] % 1000) % 1000;
for (int i = 0; i < 2; i++)
for (int j = 0; j <= n; j++)
for (int k = 0; k < M; k++)
dp[i][j][k] = 1e9;
dp[0][0][0] = 0;
for (int i = 0; i < n; i++) {
int ni = (i + 1) % 2, I = i % 2, mm = min(M, 500 * i + 1);
for (int j = 0; j <= i; j++)
for (int k = 0; k < mm; k++)
dp[ni][j][k] = 1e9;
for (int j = 0; j <= i; j++)
for (int k = 0; k < mm; k++) {
int np = k + pp[i];
int nj = j;
if (np >= 500)
nj++, np -= 500;
np = min(M - 1, np);
dp[ni][nj][np] = min(dp[ni][nj][np], dp[I][j][k] + p[i]);
dp[ni][j][k] = min(dp[ni][j][k], dp[I][j][k]);
dp[ni][nj][np] = min(dp[ni][nj][np], dp[I][j][k] + p[i]);
}
}
int c = 0, s = 0;
for (int i = 1; i <= n; i++)
for (int j = 0; j < M; j++)
if (dp[n % 2][i][j] != 1e9 && i >= c) {
if (c == i && dp[n % 2][i][j] < s)
s = dp[n % 2][i][j];
else if (c < i)
c = i, s = dp[n % 2][i][j];
}
printf("%d %d\n", c, s);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define M 25000
int dp[2][101][M];
int main() {
int n;
while (cin >> n, n) {
int p[100], pp[100];
for (int i = 0; i < n; i++)
scanf("%d", &p[i]), pp[i] = (1000 - p[i] % 1000) % 1000;
for (int i = 0; i < 2; i++)
for (int j = 0; j <= n; j++)
for (int k = 0; k < M; k++)
dp[i][j][k] = 1e9;
dp[0][0][0] = 0;
for (int i = 0; i < n; i++) {
int ni = (i + 1) % 2, I = i % 2, mm = min(M, 500 * i + 1);
for (int j = 0; j <= i; j++)
for (int k = 0; k < mm; k++)
dp[ni][j][k] = 1e9;
for (int j = 0; j <= i; j++)
for (int k = 0; k < mm; k++) {
int np = k + pp[i];
int nj = j;
if (np >= 500)
nj++, np -= 500;
np = min(M - 1, np);
dp[ni][nj][np] = min(dp[ni][nj][np], dp[I][j][k] + p[i]);
dp[ni][j][k] = min(dp[ni][j][k], dp[I][j][k]);
}
}
int c = 0, s = 0;
for (int i = 1; i <= n; i++)
for (int j = 0; j < M; j++)
if (dp[n % 2][i][j] != 1e9 && i >= c) {
if (c == i && dp[n % 2][i][j] < s)
s = dp[n % 2][i][j];
else if (c < i)
c = i, s = dp[n % 2][i][j];
}
printf("%d %d\n", c, s);
}
return 0;
} | delete | 37 | 38 | 37 | 37 | TLE | |
p01088 | C++ | Runtime Error | #include <bits/stdc++.h>
#define INF 100000000
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
int p[101];
P dp[101][50001];
P max_get(P a, P b) {
if (a.first > b.first) {
return a;
}
if (a.first < b.first) {
return b;
}
return (a.second <= b.second) ? a : b;
}
int main(void) {
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d", &p[i]);
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 500000; j++) {
dp[i][j] = P(0, INF);
}
}
dp[0][0] = P(0, 0);
for (int i = 0; i < n; i++) {
int need = (p[i] % 1000) - 500;
if (need < 0)
need += 1000;
int oturi = 1000 - (p[i] % 1000);
if (oturi == 1000)
oturi = 0;
for (int j = 0; j <= 50000; j++) {
if (dp[i][j].second != INF) {
dp[i + 1][j] = max_get(dp[i + 1][j], dp[i][j]);
if (p[i] % 1000 < 500 && ((p[i] % 1000) != 0)) {
P np = dp[i][j];
np.first++;
np.second += p[i];
dp[i + 1][j + oturi - 500] =
max_get(dp[i + 1][j + oturi - 500], np);
} else {
if (j >= need) {
P np = dp[i][j];
np.first++;
np.second += p[i];
dp[i + 1][j - need] = max_get(dp[i + 1][j - need], np);
} else {
P np = dp[i][j];
np.second += p[i];
dp[i + 1][j + oturi] = max_get(dp[i + 1][j + oturi], np);
}
}
}
}
}
int r1 = 0, r2 = 0;
for (int i = 0; i <= 50000; i++) {
if (dp[n][i].second != INF) {
if (r1 == dp[n][i].first && r2 > dp[n][i].second) {
r1 = dp[n][i].first;
r2 = dp[n][i].second;
}
if (r1 < dp[n][i].first) {
r1 = dp[n][i].first;
r2 = dp[n][i].second;
}
}
}
printf("%d %d\n", r1, r2);
}
return 0;
} | #include <bits/stdc++.h>
#define INF 100000000
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
int p[101];
P dp[101][50001];
P max_get(P a, P b) {
if (a.first > b.first) {
return a;
}
if (a.first < b.first) {
return b;
}
return (a.second <= b.second) ? a : b;
}
int main(void) {
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d", &p[i]);
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 50000; j++) {
dp[i][j] = P(0, INF);
}
}
dp[0][0] = P(0, 0);
for (int i = 0; i < n; i++) {
int need = (p[i] % 1000) - 500;
if (need < 0)
need += 1000;
int oturi = 1000 - (p[i] % 1000);
if (oturi == 1000)
oturi = 0;
for (int j = 0; j <= 50000; j++) {
if (dp[i][j].second != INF) {
dp[i + 1][j] = max_get(dp[i + 1][j], dp[i][j]);
if (p[i] % 1000 < 500 && ((p[i] % 1000) != 0)) {
P np = dp[i][j];
np.first++;
np.second += p[i];
dp[i + 1][j + oturi - 500] =
max_get(dp[i + 1][j + oturi - 500], np);
} else {
if (j >= need) {
P np = dp[i][j];
np.first++;
np.second += p[i];
dp[i + 1][j - need] = max_get(dp[i + 1][j - need], np);
} else {
P np = dp[i][j];
np.second += p[i];
dp[i + 1][j + oturi] = max_get(dp[i + 1][j + oturi], np);
}
}
}
}
}
int r1 = 0, r2 = 0;
for (int i = 0; i <= 50000; i++) {
if (dp[n][i].second != INF) {
if (r1 == dp[n][i].first && r2 > dp[n][i].second) {
r1 = dp[n][i].first;
r2 = dp[n][i].second;
}
if (r1 < dp[n][i].first) {
r1 = dp[n][i].first;
r2 = dp[n][i].second;
}
}
}
printf("%d %d\n", r1, r2);
}
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p01088 | C++ | Time Limit Exceeded | #include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
const int BIG = 1000000;
const int CMAX = 25000;
for (;;) {
int n;
cin >> n;
if (n == 0)
break;
vector<int> ps;
for (int i = 0; i < n; i++) {
int p;
cin >> p;
ps.push_back(p);
}
// shop : at most 100
// change : at most 49900... too much?
// # of 500 got so far : at most 100
// value : minimum payment
vector<vector<int>> dp(CMAX + 1, vector<int>(101, BIG));
vector<vector<int>> dpnew(CMAX + 1, vector<int>(101, BIG));
dpnew[0][0] = 0;
int cmax = 0;
for (int i = 0; i < n; i++) {
const int ii = i + 1;
for (int j = 0; j <= cmax; j++) { // not buying
for (int k = 0; k <= i; k++) {
dp[j][k] = dpnew[j][k];
}
}
// buying
const int p = ps[i] % 1000;
if (p != 0 && p <= 500) { // got 500!
for (int j = 0; j <= cmax; j++) {
const int jj = min(j + 500 - p, CMAX);
cmax = min(max(cmax, jj), CMAX);
for (int k = 0; k <= i; k++) {
const int kk = k + 1;
dpnew[jj][kk] = min(dpnew[jj][kk], dp[j][k] + ps[i]);
}
}
} else {
// get 500 if possible!
const int q = (p == 0 ? 1000 : p) - 500;
for (int j = 0; j <= cmax; j++) {
if (j >= q) {
const int jj = j - q;
for (int k = 0; k <= i; k++) {
const int kk = k + 1;
dpnew[jj][kk] = min(dpnew[jj][kk], dp[j][k] + ps[i]);
}
} else { // get change
const int jj = j + 1000 - p;
cmax = min(max(cmax, jj), CMAX);
if (jj < 1000) {
for (int k = 0; k <= i; k++) {
const int kk = k;
dpnew[jj][kk] = min(dpnew[jj][kk], dp[j][k] + ps[i]);
}
}
}
}
}
}
for (int k = 100; k >= 0; k--) {
int p = BIG;
for (int j = 0; j <= cmax; j++) {
p = min(p, dpnew[j][k]);
}
if (p != BIG) {
cout << k << " " << p << endl;
break;
}
}
}
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
const int BIG = 1000000;
const int CMAX = 20000;
for (;;) {
int n;
cin >> n;
if (n == 0)
break;
vector<int> ps;
for (int i = 0; i < n; i++) {
int p;
cin >> p;
ps.push_back(p);
}
// shop : at most 100
// change : at most 49900... too much?
// # of 500 got so far : at most 100
// value : minimum payment
vector<vector<int>> dp(CMAX + 1, vector<int>(101, BIG));
vector<vector<int>> dpnew(CMAX + 1, vector<int>(101, BIG));
dpnew[0][0] = 0;
int cmax = 0;
for (int i = 0; i < n; i++) {
const int ii = i + 1;
for (int j = 0; j <= cmax; j++) { // not buying
for (int k = 0; k <= i; k++) {
dp[j][k] = dpnew[j][k];
}
}
// buying
const int p = ps[i] % 1000;
if (p != 0 && p <= 500) { // got 500!
for (int j = 0; j <= cmax; j++) {
const int jj = min(j + 500 - p, CMAX);
cmax = min(max(cmax, jj), CMAX);
for (int k = 0; k <= i; k++) {
const int kk = k + 1;
dpnew[jj][kk] = min(dpnew[jj][kk], dp[j][k] + ps[i]);
}
}
} else {
// get 500 if possible!
const int q = (p == 0 ? 1000 : p) - 500;
for (int j = 0; j <= cmax; j++) {
if (j >= q) {
const int jj = j - q;
for (int k = 0; k <= i; k++) {
const int kk = k + 1;
dpnew[jj][kk] = min(dpnew[jj][kk], dp[j][k] + ps[i]);
}
} else { // get change
const int jj = j + 1000 - p;
cmax = min(max(cmax, jj), CMAX);
if (jj < 1000) {
for (int k = 0; k <= i; k++) {
const int kk = k;
dpnew[jj][kk] = min(dpnew[jj][kk], dp[j][k] + ps[i]);
}
}
}
}
}
}
for (int k = 100; k >= 0; k--) {
int p = BIG;
for (int j = 0; j <= cmax; j++) {
p = min(p, dpnew[j][k]);
}
if (p != BIG) {
cout << k << " " << p << endl;
break;
}
}
}
return 0;
}
| replace | 5 | 6 | 5 | 6 | TLE | |
p01088 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define reps(i, s, n) for (int(i) = (s); (i) < (n); ++(i))
#define rep(i, n) reps(i, 0, n)
#define rept(i, n) rep(i, (n) + 1)
#define repst(i, s, n) reps(i, s, (n) + 1)
#define reprt(i, n, t) for (int(i) = (n); (i) >= (t); --(i))
#define repr(i, n) reprt(i, n, 0)
#define each(itr, v) for (auto &(itr) : (v))
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x, y, z) max(x, max(y, z))
#define tmin(x, y, z) min(x, min(y, z))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define ln '\n'
#define bln(i, n) (((i) == (n)-1) ? '\n' : ' ')
#define dbg(x) cout << #x " = " << (x) << ln << flush
#define dbga(x, n) \
{ \
cout << #x " : "; \
for (int(i) = 0; i < (n); ++i) { \
cout << ((x)[i]) << (i == ((n)-1) ? '\n' : ' ') << flush; \
} \
}
#define zero(a) memset(a, 0, sizeof(a))
#define unq(a) sort(all(a)), a.erase(unique(all(a)), a.end())
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int>> mat;
const ll inf = (ll)1e9 + 10;
const ll linf = (ll)1e18 + 10;
const ll mod = (ll)(1e9 + 7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;
ll mop(ll a, ll b, ll m = mod) {
ll r = 1;
a %= m;
for (; b; b >>= 1) {
if (b & 1)
r = r * a % m;
a = a * a % m;
}
return r;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
bool ool(int x, int y, int h, int w) {
return ((x < 0) || (h <= x) || (y < 0) || (w <= y));
}
struct oreno_initializer {
oreno_initializer() {
cin.tie(0);
ios::sync_with_stdio(0);
}
} oreno_initializer;
// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・
// dp[i][j]:
// i番目の店までで100円以下の小銭の総額がjとなるような買い方の{500円玉の枚数,-購入金額}の最大値
// 遷移は a)500円玉を得られるように買う b)1000円札のみで買って小銭を稼ぐ
// c)買わない bでも500円玉を得られる場合がある
int n, p[100];
pii dp[100][50050];
signed main() {
while (1) {
cin >> n;
if (n == 0)
break;
rep(i, n) cin >> p[i];
rept(i, n) rept(j, 50000) dp[i][j] = {-1, 0};
dp[0][0] = {0, 0};
rep(i, n) rept(j, 50000) if (dp[i][j].fi != -1) {
int g = dp[i][j].fi, u = -dp[i][j].se;
// 500円玉を得る
if (j >= (p[i] + 500) % 1000)
chmax(dp[i + 1][j - (p[i] + 500) % 1000], mp(g + 1, -(u + p[i])));
// 1000円札のみ
if (1 <= p[i] % 1000 && p[i] % 1000 <= 500)
chmax(dp[i + 1][j + (500 - p[i] % 1000)], mp(g + 1, -(u + p[i])));
if (500 < p[i] % 1000)
chmax(dp[i + 1][j + (1000 - p[i] % 1000)], mp(g, -(u + p[i])));
// 買わない
chmax(dp[i + 1][j], mp(g, -u));
}
pii res = mp(0, 0);
rept(i, 50000) chmax(res, dp[n][i]);
cout << res.fi << ' ' << -res.se << ln;
}
}
| #include <bits/stdc++.h>
using namespace std;
// #define int long long
#define reps(i, s, n) for (int(i) = (s); (i) < (n); ++(i))
#define rep(i, n) reps(i, 0, n)
#define rept(i, n) rep(i, (n) + 1)
#define repst(i, s, n) reps(i, s, (n) + 1)
#define reprt(i, n, t) for (int(i) = (n); (i) >= (t); --(i))
#define repr(i, n) reprt(i, n, 0)
#define each(itr, v) for (auto &(itr) : (v))
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x, y, z) max(x, max(y, z))
#define tmin(x, y, z) min(x, min(y, z))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define ln '\n'
#define bln(i, n) (((i) == (n)-1) ? '\n' : ' ')
#define dbg(x) cout << #x " = " << (x) << ln << flush
#define dbga(x, n) \
{ \
cout << #x " : "; \
for (int(i) = 0; i < (n); ++i) { \
cout << ((x)[i]) << (i == ((n)-1) ? '\n' : ' ') << flush; \
} \
}
#define zero(a) memset(a, 0, sizeof(a))
#define unq(a) sort(all(a)), a.erase(unique(all(a)), a.end())
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int>> mat;
const ll inf = (ll)1e9 + 10;
const ll linf = (ll)1e18 + 10;
const ll mod = (ll)(1e9 + 7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;
ll mop(ll a, ll b, ll m = mod) {
ll r = 1;
a %= m;
for (; b; b >>= 1) {
if (b & 1)
r = r * a % m;
a = a * a % m;
}
return r;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
bool ool(int x, int y, int h, int w) {
return ((x < 0) || (h <= x) || (y < 0) || (w <= y));
}
struct oreno_initializer {
oreno_initializer() {
cin.tie(0);
ios::sync_with_stdio(0);
}
} oreno_initializer;
// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+.。.:( ^ω^)・゚+
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・
// dp[i][j]:
// i番目の店までで100円以下の小銭の総額がjとなるような買い方の{500円玉の枚数,-購入金額}の最大値
// 遷移は a)500円玉を得られるように買う b)1000円札のみで買って小銭を稼ぐ
// c)買わない bでも500円玉を得られる場合がある
int n, p[100];
pii dp[101][50050];
signed main() {
while (1) {
cin >> n;
if (n == 0)
break;
rep(i, n) cin >> p[i];
rept(i, n) rept(j, 50000) dp[i][j] = {-1, 0};
dp[0][0] = {0, 0};
rep(i, n) rept(j, 50000) if (dp[i][j].fi != -1) {
int g = dp[i][j].fi, u = -dp[i][j].se;
// 500円玉を得る
if (j >= (p[i] + 500) % 1000)
chmax(dp[i + 1][j - (p[i] + 500) % 1000], mp(g + 1, -(u + p[i])));
// 1000円札のみ
if (1 <= p[i] % 1000 && p[i] % 1000 <= 500)
chmax(dp[i + 1][j + (500 - p[i] % 1000)], mp(g + 1, -(u + p[i])));
if (500 < p[i] % 1000)
chmax(dp[i + 1][j + (1000 - p[i] % 1000)], mp(g, -(u + p[i])));
// 買わない
chmax(dp[i + 1][j], mp(g, -u));
}
pii res = mp(0, 0);
rept(i, 50000) chmax(res, dp[n][i]);
cout << res.fi << ' ' << -res.se << ln;
}
}
| replace | 88 | 89 | 88 | 89 | 0 | |
p01088 | C++ | Runtime Error | #include <iostream>
#include <utility>
#include <vector>
using namespace std;
struct Info {
int mai;
int cost;
bool operator<(const Info &i) const {
return (mai != i.mai) ? mai > i.mai : cost < i.cost;
}
bool operator==(const Info &i) const {
return mai == i.mai and cost == i.cost;
}
Info operator+(const Info &i) const {
return Info{mai + i.mai, cost + i.cost};
}
};
constexpr int MAX = 100;
constexpr int RES = 49900;
constexpr int INF = 1 << 30;
const Info IINF = Info{0, INF};
Info dp[MAX + 1][RES + 1];
int main() {
while (true) {
int n;
cin >> n;
if (n == 0) {
break;
}
vector<int> p(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = 0; i <= MAX; i++) {
for (int j = 0; j <= RES; j++) {
dp[i][j] = IINF;
}
}
dp[0][0] = Info{0, 0};
for (int i = 0; i < n; i++) {
for (int j = 0; j <= RES; j++) {
if (not(dp[i][j] == IINF)) {
const int price = p[i] % 1000;
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
int rest = j - price;
for (int m = 0; m < 2 and m * 500 <= rest; m++) {
dp[i + 1][rest - m * 500] =
min(dp[i + 1][rest - m * 500], dp[i][j] + Info{m, p[i]});
}
if (price != 0) {
rest = 1000 + j - price;
for (int m = 0; m < 2 and m * 500 <= rest; m++) {
dp[i + 1][rest - m * 500] =
min(dp[i + 1][rest - m * 500], dp[i][j] + Info{m, p[i]});
}
}
}
}
}
Info mini = IINF;
for (int j = 0; j <= RES; j++) {
mini = min(mini, dp[n][j]);
}
cout << mini.mai << " " << mini.cost << endl;
}
return 0;
} | #include <iostream>
#include <utility>
#include <vector>
using namespace std;
struct Info {
int mai;
int cost;
bool operator<(const Info &i) const {
return (mai != i.mai) ? mai > i.mai : cost < i.cost;
}
bool operator==(const Info &i) const {
return mai == i.mai and cost == i.cost;
}
Info operator+(const Info &i) const {
return Info{mai + i.mai, cost + i.cost};
}
};
constexpr int MAX = 100;
constexpr int RES = 49900;
constexpr int INF = 1 << 30;
const Info IINF = Info{0, INF};
Info dp[MAX + 100][RES + 100];
int main() {
while (true) {
int n;
cin >> n;
if (n == 0) {
break;
}
vector<int> p(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = 0; i <= MAX; i++) {
for (int j = 0; j <= RES; j++) {
dp[i][j] = IINF;
}
}
dp[0][0] = Info{0, 0};
for (int i = 0; i < n; i++) {
for (int j = 0; j <= RES; j++) {
if (not(dp[i][j] == IINF)) {
const int price = p[i] % 1000;
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
int rest = j - price;
for (int m = 0; m < 2 and m * 500 <= rest; m++) {
dp[i + 1][rest - m * 500] =
min(dp[i + 1][rest - m * 500], dp[i][j] + Info{m, p[i]});
}
if (price != 0) {
rest = 1000 + j - price;
for (int m = 0; m < 2 and m * 500 <= rest; m++) {
dp[i + 1][rest - m * 500] =
min(dp[i + 1][rest - m * 500], dp[i][j] + Info{m, p[i]});
}
}
}
}
}
Info mini = IINF;
for (int j = 0; j <= RES; j++) {
mini = min(mini, dp[n][j]);
}
cout << mini.mai << " " << mini.cost << endl;
}
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p01089 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <string>
#define rep(i, n) for (i = 0; i < (n); i++)
using namespace std;
int n;
string s;
bool dp[1024][1025]; // dp[S][T] = (ロック資源の集合がS,
// 待ち資源の集合がT)になることがあるか
bool solve() {
int i, j, k, l;
int locked = 0, waiting = 0;
rep(i, s.length()) {
if ('0' <= s[i] && s[i] <= '9') {
waiting = s[i] - '0';
dp[locked][1 << waiting] = true;
locked = locked + (1 << waiting);
} else {
waiting = 10; // T is covered Sが常に偽になる設定.
dp[locked][1 << waiting] = true;
locked = 0;
}
}
rep(i, 1024) {
// iと排反なnumberを探す.
int digit[10];
int dNum = 0;
rep(k, 10) {
if ((i >> k) % 2 == 0) {
digit[dNum++] = k;
}
}
rep(j, 1025) {
if (!dp[i][j])
continue;
rep(k, 1 << dNum) {
int locked = 0;
rep(l, dNum) if ((k >> l) & 1) locked += (1 << digit[l]);
// waiting = 2^0, 2^1, …, 2^10
rep(l, 11) {
if (dp[locked][1 << l]) {
dp[i | locked][min(1024, j | (1 << l))] = true; // 範囲外参照に注意!
}
}
}
}
}
rep(i, 1024) {
rep(j, 1025) {
if (!dp[i][j])
continue;
if ((i | j) == i)
return true; // UNSAFE
}
}
return false;
}
int main() {
int i, j;
while (cin >> n) {
if (!n)
break;
cin >> s;
rep(i, 1024) rep(j, 1025) dp[i][j] = false;
bool res = solve();
if (res)
cout << "UNSAFE" << endl;
else
cout << "SAFE" << endl;
}
return 0;
}
// ポイント:
// ・2段がまえの論理。
// ・「全体集合から、ありえる状態集合を抽出☆」→「ありえる状態集合から、デッドロックが起きるものを抽出★」
// ・「初期状態から「ある状態」に至れるか」の判定を直接的にできるのが、この問題のポイント。
// ・「初期状態から「デッドロックが起きる状態」に至れるか」を直接判定しようとすると、再帰を考えることになり、このアプローチでは高速化を大して望めない。
//
// 自分用解説:
// 「各kについて、スレッドkで命令がa_k個処理された状態」になりえるかは、容易に求まる。(現在ロックしている資源がかぶっていないかを判定するだけ)
// なりえる状態のうち、(次確保したい資源の集合)が(ロックした資源の集合)の部分集合になるものでは、デッドロックが起きる。
// そういうものがない場合は、デッドロックは決して起きない。
//
//{a_1,…,a_10}をすべて試すとO(10000^10)くらいになり間に合わない。a_1, a_2,
//…の順で決めていくと考えると、わざわざ{a_k}を直接持たなくて良いことに気付く。
// なぜかというと、可能な{a_[i+1], …, a_10}の組み合わせは、
// ・現在i個のスレッドのカーソルを確定させた。現在ロックしている資源はS
// という情報から定まり、
// デッドロックの判定は、この情報に
// ・確保したい資源はT
// という情報を追加すればできるからである。よって、{a}の情報を持たずに探索ができる。(典型的なDP
// さらに、もう少し考えるとT -
// S(次確保「できる」資源の集合)を保存することでもデッドロックの判定ができるので、
// ・i, S, T - S
// を使ってDPできることが分かる。
//
// また、この探索において、a_iの値を決めることは、「スレッドiでロックしている資源s_i,
// ロックしたい資源t_iを確定させる」
// ことに他ならないため、a_iを試す代わりに(s_i, t_i)組を試してもよい。
// しかし今回は文字列の長さがそこまで長くないため、直接a_iの値を試せばよい。(10000
// < 2^10 * 10なので、上記の工夫はあまり意味がない)
//
// 計算量は、(S, T - S)の組み合わせが3^10通り, iが11通り,
// 遷移が高々n(<=10000)通りより、3^10 * 11 * nくらいになる。
// …あれ、間に合わない。
//
//
// 自分用解説2:
// デッドロックは、次欲しい資源がすべてロックされていることである。
// ロックされている資源の集合をS, 次欲しい資源の集合をTとして、ありえる(S,
// T)の組み合わせを列挙することを考える。(☆) 1スレッドのとき、ありえる(S,
// T)の組み合わせは簡単に求まる。その集合を{(s_i, t_i), 1≦i≦hoge}とおく。
// 2スレッドのときは、すでにロックしている資源をロックしなければよく、命令列も全スレッド共通なので、
// ・(s_i or s_j, t_i or t_j) (s_i and s_j = empty)
// を列挙すればいいことに気付く。
// 3スレッドのときも同様。
// 今回の問題は、資源の個数≦スレッドの数より、スレッドの数に限りがないと考えてよく、
// ありえる(S, T)について、(S or s_i, T or t_i) (S and s_i =
// empty)を更新が止まるまでやればいいことが分かる。 ↑はS or
// s_iがSやs_iを含むことから、Sを2進数で表し、S=0,1,2,…の順で更新していけばいいことが分かる。
//
// 一見, hoge=n, Sが2^10通り, Tが2^10通りで、2^20 * 10000 =
// 100億で間に合わないように見えるが、S and s_i = emptyとなるiだけを列挙すると、
// 間に合う。計算量解析:1がk個立っているSはcomb[10][k]通り. そのSについて、S
// and s_i = emptyなるs_iは2^(10-k)通り. Tは2^10通り. t_iは高々11通り.
// Σcomb[10][k] * 2^(10 - k) = 3^10より、計算量は3^10 * 2^10 * 11 ≒ 6.6 *
// 10^8となる。(ダメやんけ)
//
// 余談:
// ☆で「スレッドのカーソルの位置」を列挙したくなりがちだが、デッドロックの条件から、(S,
// T)の組み合わせを列挙する方が後々筋が良い。
// 「列挙するもの」は必ずしも「愚直な全探索」と同一にしなくても良いので、都合の良いものを列挙しよう。
| #include <algorithm>
#include <iostream>
#include <string>
#define rep(i, n) for (i = 0; i < (n); i++)
using namespace std;
int n;
string s;
bool dp[1024][1025]; // dp[S][T] = (ロック資源の集合がS,
// 待ち資源の集合がT)になることがあるか
bool solve() {
int i, j, k, l;
int locked = 0, waiting = 0;
rep(i, s.length()) {
if ('0' <= s[i] && s[i] <= '9') {
waiting = s[i] - '0';
dp[locked][1 << waiting] = true;
locked = locked + (1 << waiting);
} else {
waiting = 10; // T is covered Sが常に偽になる設定.
dp[locked][1 << waiting] = true;
locked = 0;
}
}
rep(i, 1024) {
// iと排反なnumberを探す.
int digit[10];
int dNum = 0;
rep(k, 10) {
if ((i >> k) % 2 == 0) {
digit[dNum++] = k;
}
}
rep(j, 1025) {
if (!dp[i][j])
continue;
if ((i | j) == i)
return true;
rep(k, 1 << dNum) {
int locked = 0;
rep(l, dNum) if ((k >> l) & 1) locked += (1 << digit[l]);
// waiting = 2^0, 2^1, …, 2^10
rep(l, 11) {
if (dp[locked][1 << l]) {
dp[i | locked][min(1024, j | (1 << l))] = true; // 範囲外参照に注意!
}
}
}
}
}
rep(i, 1024) {
rep(j, 1025) {
if (!dp[i][j])
continue;
if ((i | j) == i)
return true; // UNSAFE
}
}
return false;
}
int main() {
int i, j;
while (cin >> n) {
if (!n)
break;
cin >> s;
rep(i, 1024) rep(j, 1025) dp[i][j] = false;
bool res = solve();
if (res)
cout << "UNSAFE" << endl;
else
cout << "SAFE" << endl;
}
return 0;
}
// ポイント:
// ・2段がまえの論理。
// ・「全体集合から、ありえる状態集合を抽出☆」→「ありえる状態集合から、デッドロックが起きるものを抽出★」
// ・「初期状態から「ある状態」に至れるか」の判定を直接的にできるのが、この問題のポイント。
// ・「初期状態から「デッドロックが起きる状態」に至れるか」を直接判定しようとすると、再帰を考えることになり、このアプローチでは高速化を大して望めない。
//
// 自分用解説:
// 「各kについて、スレッドkで命令がa_k個処理された状態」になりえるかは、容易に求まる。(現在ロックしている資源がかぶっていないかを判定するだけ)
// なりえる状態のうち、(次確保したい資源の集合)が(ロックした資源の集合)の部分集合になるものでは、デッドロックが起きる。
// そういうものがない場合は、デッドロックは決して起きない。
//
//{a_1,…,a_10}をすべて試すとO(10000^10)くらいになり間に合わない。a_1, a_2,
//…の順で決めていくと考えると、わざわざ{a_k}を直接持たなくて良いことに気付く。
// なぜかというと、可能な{a_[i+1], …, a_10}の組み合わせは、
// ・現在i個のスレッドのカーソルを確定させた。現在ロックしている資源はS
// という情報から定まり、
// デッドロックの判定は、この情報に
// ・確保したい資源はT
// という情報を追加すればできるからである。よって、{a}の情報を持たずに探索ができる。(典型的なDP
// さらに、もう少し考えるとT -
// S(次確保「できる」資源の集合)を保存することでもデッドロックの判定ができるので、
// ・i, S, T - S
// を使ってDPできることが分かる。
//
// また、この探索において、a_iの値を決めることは、「スレッドiでロックしている資源s_i,
// ロックしたい資源t_iを確定させる」
// ことに他ならないため、a_iを試す代わりに(s_i, t_i)組を試してもよい。
// しかし今回は文字列の長さがそこまで長くないため、直接a_iの値を試せばよい。(10000
// < 2^10 * 10なので、上記の工夫はあまり意味がない)
//
// 計算量は、(S, T - S)の組み合わせが3^10通り, iが11通り,
// 遷移が高々n(<=10000)通りより、3^10 * 11 * nくらいになる。
// …あれ、間に合わない。
//
//
// 自分用解説2:
// デッドロックは、次欲しい資源がすべてロックされていることである。
// ロックされている資源の集合をS, 次欲しい資源の集合をTとして、ありえる(S,
// T)の組み合わせを列挙することを考える。(☆) 1スレッドのとき、ありえる(S,
// T)の組み合わせは簡単に求まる。その集合を{(s_i, t_i), 1≦i≦hoge}とおく。
// 2スレッドのときは、すでにロックしている資源をロックしなければよく、命令列も全スレッド共通なので、
// ・(s_i or s_j, t_i or t_j) (s_i and s_j = empty)
// を列挙すればいいことに気付く。
// 3スレッドのときも同様。
// 今回の問題は、資源の個数≦スレッドの数より、スレッドの数に限りがないと考えてよく、
// ありえる(S, T)について、(S or s_i, T or t_i) (S and s_i =
// empty)を更新が止まるまでやればいいことが分かる。 ↑はS or
// s_iがSやs_iを含むことから、Sを2進数で表し、S=0,1,2,…の順で更新していけばいいことが分かる。
//
// 一見, hoge=n, Sが2^10通り, Tが2^10通りで、2^20 * 10000 =
// 100億で間に合わないように見えるが、S and s_i = emptyとなるiだけを列挙すると、
// 間に合う。計算量解析:1がk個立っているSはcomb[10][k]通り. そのSについて、S
// and s_i = emptyなるs_iは2^(10-k)通り. Tは2^10通り. t_iは高々11通り.
// Σcomb[10][k] * 2^(10 - k) = 3^10より、計算量は3^10 * 2^10 * 11 ≒ 6.6 *
// 10^8となる。(ダメやんけ)
//
// 余談:
// ☆で「スレッドのカーソルの位置」を列挙したくなりがちだが、デッドロックの条件から、(S,
// T)の組み合わせを列挙する方が後々筋が良い。
// 「列挙するもの」は必ずしも「愚直な全探索」と同一にしなくても良いので、都合の良いものを列挙しよう。
| insert | 40 | 40 | 40 | 43 | TLE | |
p01089 | C++ | Time Limit Exceeded | #include <bitset>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int n;
bool ok[1028];
string s;
int main() {
while (cin >> n, n) {
cin >> s;
bool flag = false;
for (int i = 1; i < 1024; i++) {
for (int j = 0; j < 1024; j++)
ok[j] = false;
int bit = 0;
for (int j = 0; j < s.size(); j++) {
if (s[j] == 'u')
bit = 0;
else {
if (i & (1 << (s[j] - 48)))
ok[bit] = true;
bit |= 1 << (s[j] - 48);
}
}
for (int j = 1; j <= i; j++) {
for (int k = 0; k < j; k++) {
if ((j & k) == k && ok[j - k] && ok[k])
ok[j] = true;
}
}
if (ok[i])
flag = true;
}
cout << (flag ? "UNSAFE" : "SAFE") << endl;
}
return 0;
}
| #include <bitset>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int n;
bool ok[1028];
string s;
int main() {
while (cin >> n, n) {
cin >> s;
bool flag = false;
for (int i = 1; i < 1024; i++) {
for (int j = 0; j < 1024; j++)
ok[j] = false;
int bit = 0;
for (int j = 0; j < s.size(); j++) {
if (s[j] == 'u')
bit = 0;
else {
if (i & (1 << (s[j] - 48)))
ok[bit] = true;
bit |= 1 << (s[j] - 48);
}
}
for (int j = 1; j <= i; j++) {
for (int k = j; k > 0; k = (k - 1) & j) {
if ((j & k) == k && ok[j - k] && ok[k])
ok[j] = true;
}
}
if (ok[i])
flag = true;
}
cout << (flag ? "UNSAFE" : "SAFE") << endl;
}
return 0;
}
| replace | 26 | 27 | 26 | 27 | TLE | |
p01089 | C++ | Time Limit Exceeded | #include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n && n != 0) {
string s;
cin >> s;
set<pair<int, int>> st;
int tmp = 0;
bool flag = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'u') {
tmp = 0;
} else {
if (s[i + 1] != 'u') {
tmp += 1 << (s[i] - '0');
int tmp2 = 1 << (int)(s[i + 1] - '0');
st.insert(make_pair(tmp, tmp2));
if ((tmp & tmp2) == tmp2) {
flag = 1;
}
}
}
}
set<pair<int, int>> st2 = st;
for (int j = 0; j < 10; j++) {
set<pair<int, int>> st3;
st3 = st2;
for (auto x : st) {
for (auto y : st2) {
if ((x.first & y.first) == 0) {
int p = x.first | y.first;
int q = x.second | y.second;
st3.insert(make_pair(p, q));
if ((p & q) == q) {
flag = 1;
break;
}
}
}
if (flag)
break;
}
st2 = st3;
}
if (flag) {
cout << "UNSAFE" << endl;
} else {
cout << "SAFE" << endl;
}
}
return 0;
}
| #include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n;
while (cin >> n && n != 0) {
string s;
cin >> s;
set<pair<int, int>> st;
int tmp = 0;
bool flag = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'u') {
tmp = 0;
} else {
if (s[i + 1] != 'u') {
tmp += 1 << (s[i] - '0');
int tmp2 = 1 << (int)(s[i + 1] - '0');
st.insert(make_pair(tmp, tmp2));
if ((tmp & tmp2) == tmp2) {
flag = 1;
}
}
}
}
set<pair<int, int>> st2 = st;
for (int j = 0; j < 10; j++) {
set<pair<int, int>> st3;
for (auto x : st) {
for (auto y : st2) {
if ((x.first & y.first) == 0) {
int p = x.first | y.first;
int q = x.second | y.second;
st3.insert(make_pair(p, q));
if ((p & q) == q) {
flag = 1;
break;
}
}
}
if (flag)
break;
}
st2 = st3;
}
if (flag) {
cout << "UNSAFE" << endl;
} else {
cout << "SAFE" << endl;
}
}
return 0;
}
| delete | 33 | 34 | 33 | 33 | TLE | |
p01089 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
vector<string> parse(const string &s) {
vector<string> ret;
string buf;
REP(i, s.size()) {
if (s[i] == 'u') {
ret.push_back(buf);
buf.clear();
} else {
buf += s[i];
}
}
return ret;
}
vector<pair<int, int>> toStates(const vector<string> &ops) {
vector<pair<int, int>> states;
for (const string &op : ops) {
// DEBUG(op);
int locked = 0;
for (char c : op) {
states.emplace_back(locked, c - '0');
locked |= (1 << (c - '0'));
}
}
return states;
}
bool contains(int A, int B) {
// A contains B
while (B > 0) {
if (B & 1) {
if ((A & 1) == 0)
return false;
}
A >>= 1;
B >>= 1;
}
return true;
}
bool dp[1 << 10][10];
signed main() {
ios::sync_with_stdio(false);
while (true) {
int N;
cin >> N;
if (N == 0)
break;
string T;
cin >> T;
vector<string> ops = parse(T);
vector<pair<int, int>> states = toStates(ops);
memset(dp, 0, sizeof(dp));
bool unsafe = false;
queue<pair<int, int>> que;
for (const auto &p : states) {
if ((p.first >> p.second) & 1)
unsafe = true;
que.emplace(p);
dp[p.first][p.second] = true;
}
while (!que.empty()) {
auto p = que.front();
que.pop();
for (int S = 0; S < (1 << 10); ++S) {
for (int next = 0; next < 10; ++next) {
if (dp[S][next] == false)
continue;
auto q = make_pair(S, next);
if ((p.first & q.first) != 0)
continue;
if ((p.first >> q.second) & 1 &&
dp[p.first | q.first][p.second] == false) {
dp[p.first | q.first][p.second] = true;
que.emplace(p.first | q.first, p.second);
}
if ((q.first >> p.second) & 1 &&
dp[p.first | q.first][q.second] == false) {
dp[p.first | q.first][q.second] = true;
que.emplace(p.first | q.first, q.second);
}
}
}
}
REP(S1, 1 << 10) {
REP(n1, 10) {
#if 0
if(dp[S1][n1]) {
cerr << "[";
REP(i,10) {
if((S1 >> i) & 1) cerr << i;
}
cerr << "] " << n1 << endl;
}
#endif
REP(S2, 1 << 10) {
REP(n2, 10) {
if ((S1 & S2) == 0 && dp[S1][n1] && dp[S2][n2]) {
if ((S1 >> n2) & 1 && (S2 >> n1) & 1) {
unsafe = true;
}
}
}
}
}
}
cout << (unsafe ? "UNSAFE" : "SAFE") << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
vector<string> parse(const string &s) {
vector<string> ret;
string buf;
REP(i, s.size()) {
if (s[i] == 'u') {
ret.push_back(buf);
buf.clear();
} else {
buf += s[i];
}
}
return ret;
}
vector<pair<int, int>> toStates(const vector<string> &ops) {
vector<pair<int, int>> states;
for (const string &op : ops) {
// DEBUG(op);
int locked = 0;
for (char c : op) {
states.emplace_back(locked, c - '0');
locked |= (1 << (c - '0'));
}
}
return states;
}
bool contains(int A, int B) {
// A contains B
while (B > 0) {
if (B & 1) {
if ((A & 1) == 0)
return false;
}
A >>= 1;
B >>= 1;
}
return true;
}
bool dp[1 << 10][10];
signed main() {
ios::sync_with_stdio(false);
while (true) {
int N;
cin >> N;
if (N == 0)
break;
string T;
cin >> T;
vector<string> ops = parse(T);
vector<pair<int, int>> states = toStates(ops);
memset(dp, 0, sizeof(dp));
bool unsafe = false;
queue<pair<int, int>> que;
for (const auto &p : states) {
if ((p.first >> p.second) & 1)
unsafe = true;
que.emplace(p);
dp[p.first][p.second] = true;
}
while (!que.empty()) {
auto p = que.front();
que.pop();
for (int S = 0; S < (1 << 10); ++S) {
for (int next = 0; next < 10; ++next) {
if (dp[S][next] == false)
continue;
auto q = make_pair(S, next);
if ((p.first & q.first) != 0)
continue;
if ((p.first >> q.second) & 1 &&
dp[p.first | q.first][p.second] == false) {
dp[p.first | q.first][p.second] = true;
que.emplace(p.first | q.first, p.second);
}
if ((q.first >> p.second) & 1 &&
dp[p.first | q.first][q.second] == false) {
dp[p.first | q.first][q.second] = true;
que.emplace(p.first | q.first, q.second);
}
}
}
}
REP(S1, 1 << 10) {
REP(n1, 10) {
if (dp[S1][n1] == false)
continue;
#if 0
if(dp[S1][n1]) {
cerr << "[";
REP(i,10) {
if((S1 >> i) & 1) cerr << i;
}
cerr << "] " << n1 << endl;
}
#endif
REP(S2, 1 << 10) {
REP(n2, 10) {
if ((S1 & S2) == 0 && dp[S1][n1] && dp[S2][n2]) {
if ((S1 >> n2) & 1 && (S2 >> n1) & 1) {
unsafe = true;
}
}
}
}
}
}
cout << (unsafe ? "UNSAFE" : "SAFE") << endl;
}
} | insert | 88 | 88 | 88 | 90 | TLE | |
p01089 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
set<int> dp[1 << 11];
int main(void) {
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < (1 << 10); i++) {
dp[i].clear();
}
string str;
cin >> str;
int bits = 0;
bool flag = true;
int v2 = -1;
for (int i = 0; i < str.size(); i++) {
if (str[i] == 'u') {
bits = 0;
v2 = -1;
} else {
if (v2 == -1) {
v2 = str[i] - '0';
bits = (1 << v2);
continue;
}
int v = str[i] - '0';
if ((bits >> v) & 1)
flag = false;
dp[bits].insert(1 << v);
bits |= (1 << v);
}
}
for (int i = 0; i < (1 << 10); i++) {
for (int j = 0; j < i; j++) {
if ((i & j) == j) {
set<int>::iterator it = dp[j].begin();
for (; it != dp[j].end(); it++) {
set<int>::iterator it2 = dp[i - j].begin();
for (; it2 != dp[i - j].end(); it2++) {
int v = (*it) | (*it2);
dp[i].insert(v);
}
}
}
}
set<int>::iterator it = dp[i].begin();
for (; it != dp[i].end(); it++) {
bool ok = false;
for (int k = 0; k < 10; k++) {
if ((!(i >> k & 1)) && ((*it) >> k & 1))
ok = true;
}
if (!ok)
flag = false;
}
}
printf("%s\n", flag ? "SAFE" : "UNSAFE");
}
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
set<int> dp[1 << 11];
int main(void) {
while (1) {
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < (1 << 10); i++) {
dp[i].clear();
}
string str;
cin >> str;
int bits = 0;
bool flag = true;
int v2 = -1;
for (int i = 0; i < str.size(); i++) {
if (str[i] == 'u') {
bits = 0;
v2 = -1;
} else {
if (v2 == -1) {
v2 = str[i] - '0';
bits = (1 << v2);
continue;
}
int v = str[i] - '0';
if ((bits >> v) & 1)
flag = false;
dp[bits].insert(1 << v);
bits |= (1 << v);
}
}
for (int i = 0; i < (1 << 10); i++) {
if (!flag)
break;
for (int j = 0; j < i; j++) {
if ((i & j) == j) {
set<int>::iterator it = dp[j].begin();
for (; it != dp[j].end(); it++) {
set<int>::iterator it2 = dp[i - j].begin();
for (; it2 != dp[i - j].end(); it2++) {
int v = (*it) | (*it2);
dp[i].insert(v);
}
}
}
}
set<int>::iterator it = dp[i].begin();
for (; it != dp[i].end(); it++) {
bool ok = false;
for (int k = 0; k < 10; k++) {
if ((!(i >> k & 1)) && ((*it) >> k & 1))
ok = true;
}
if (!ok)
flag = false;
}
}
printf("%s\n", flag ? "SAFE" : "UNSAFE");
}
return 0;
} | insert | 49 | 49 | 49 | 51 | TLE | |
p01090 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct Kruskal {
struct UnionFind {
Int n;
vector<Int> r, p;
UnionFind() {}
UnionFind(Int sz) : n(sz), r(sz, 1), p(sz, 0) {
iota(p.begin(), p.end(), 0);
}
Int find(Int x) { return (x == p[x] ? x : p[x] = find(p[x])); }
bool same(Int x, Int y) { return find(x) == find(y); }
void unite(Int x, Int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (r[x] < r[y])
swap(x, y);
r[x] += r[y];
p[y] = x;
}
};
struct edge {
Int from, to;
double cost;
Int used;
char color;
edge() {}
edge(Int from, Int to, double cost, char color)
: from(from), to(to), cost(cost), used(0), color(color) {}
bool operator<(const edge &e) const { return cost < e.cost; }
};
Int n;
vector<edge> edges;
Kruskal() {}
Kruskal(Int sz) : n(sz) {}
Int build(Int k = -1) {
sort(edges.begin(), edges.end());
UnionFind uf(n + 1);
double res = 0;
Int cnt = 0;
for (Int i = 0; i < (Int)edges.size(); i++) {
edge &e = edges[i];
if (!uf.same(e.from, e.to)) {
e.used = 1;
res += e.cost;
uf.unite(e.from, e.to);
cnt++;
}
}
if (cnt + 1 != n)
return -1;
return res;
}
};
signed main() {
Int n, m, k;
while (cin >> n >> m >> k, n) {
Kruskal kr(n);
auto edges = kr.edges;
for (Int i = 0; i < m; i++) {
Int u, v, w;
char c;
cin >> u >> v >> w >> c;
u--;
v--;
edges.emplace_back(u, v, w, c);
}
double ub = 1e12, ans;
auto check = [&](double x) {
x -= ub;
kr = Kruskal(n);
for (auto e : edges) {
if (x > 0 && e.color == 'A')
e.cost += x;
if (x < 0 && e.color == 'B')
e.cost -= x;
kr.edges.emplace_back(e);
}
ans = kr.build();
if (ans < 0)
return Int(-1);
if (x > 0)
ans -= x * k;
if (x < 0)
ans += x * (n - 1 - k);
Int res = 0;
for (auto e : kr.edges)
res += (e.used && e.color == 'A');
return res;
};
double l = 0, r = 2 * ub;
if (check(l) < k || check(r) > k) {
cout << -1 << endl;
continue;
}
for (Int i = 0; i < 2000; i++) {
double m = (l + r) / 2;
if (check(m) >= k)
l = m;
else
r = m;
}
check(l);
assert(check(l) == k);
cout << (Int)round(ans) << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct Kruskal {
struct UnionFind {
Int n;
vector<Int> r, p;
UnionFind() {}
UnionFind(Int sz) : n(sz), r(sz, 1), p(sz, 0) {
iota(p.begin(), p.end(), 0);
}
Int find(Int x) { return (x == p[x] ? x : p[x] = find(p[x])); }
bool same(Int x, Int y) { return find(x) == find(y); }
void unite(Int x, Int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (r[x] < r[y])
swap(x, y);
r[x] += r[y];
p[y] = x;
}
};
struct edge {
Int from, to;
double cost;
Int used;
char color;
edge() {}
edge(Int from, Int to, double cost, char color)
: from(from), to(to), cost(cost), used(0), color(color) {}
bool operator<(const edge &e) const { return cost < e.cost; }
};
Int n;
vector<edge> edges;
Kruskal() {}
Kruskal(Int sz) : n(sz) {}
Int build(Int k = -1) {
sort(edges.begin(), edges.end());
UnionFind uf(n + 1);
double res = 0;
Int cnt = 0;
for (Int i = 0; i < (Int)edges.size(); i++) {
edge &e = edges[i];
if (!uf.same(e.from, e.to)) {
e.used = 1;
res += e.cost;
uf.unite(e.from, e.to);
cnt++;
}
}
if (cnt + 1 != n)
return -1;
return res;
}
};
signed main() {
Int n, m, k;
while (cin >> n >> m >> k, n) {
Kruskal kr(n);
auto edges = kr.edges;
for (Int i = 0; i < m; i++) {
Int u, v, w;
char c;
cin >> u >> v >> w >> c;
u--;
v--;
edges.emplace_back(u, v, w, c);
}
double ub = 1e12, ans;
auto check = [&](double x) {
x -= ub;
kr = Kruskal(n);
for (auto e : edges) {
if (x > 0 && e.color == 'A')
e.cost += x;
if (x < 0 && e.color == 'B')
e.cost -= x;
kr.edges.emplace_back(e);
}
ans = kr.build();
if (ans < 0)
return Int(-1);
if (x > 0)
ans -= x * k;
if (x < 0)
ans += x * (n - 1 - k);
Int res = 0;
for (auto e : kr.edges)
res += (e.used && e.color == 'A');
return res;
};
double l = 0, r = 2 * ub;
if (check(l) < k || check(r) > k) {
cout << -1 << endl;
continue;
}
for (Int i = 0; i < 2000; i++) {
double m = (l + r) / 2;
if (check(m) >= k)
l = m;
else
r = m;
}
check(l);
cout << (Int)ceil(ans) << endl;
}
return 0;
}
| replace | 115 | 117 | 115 | 116 | -6 | 99d5f2a9-5c71-46fc-9ff5-85121f49a169.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p01090/C++/s036048471.cpp:108: int main(): Assertion `check(l)==k' failed.
|
p01090 | C++ | Runtime Error | #include <bits/stdc++.h>
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#define _all(arg) begin(arg), end(arg)
#define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg))
#define getidx(ary, key) lower_bound(_all(ary), key) - begin(ary)
#define clr(a, b) memset((a), (b), sizeof(a))
#define bit(n) (1LL << (n))
// #define DEBUG
#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif
template <class T> bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf = 1LL << 62;
const ll mod = 1000000007LL;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll extgcd(ll a, ll b, ll &x, ll &y) {
x = 1, y = 0;
ll g = a;
if (b != 0)
g = extgcd(b, a % b, y, x), y -= a / b * x;
return g;
}
ll ADD(const ll &a, const ll &b, const ll &mod) { return (a + b) % mod; }
ll SUB(const ll &a, const ll &b, const ll &mod) { return (a - b + mod) % mod; }
ll MUL(const ll &a, const ll &b, const ll &mod) { return (1LL * a * b) % mod; }
ll DIV(const ll &a, const ll &b, const ll &mod) {
ll x, y;
extgcd(b, mod, x, y);
return MUL(a, (x + mod) % mod, mod);
}
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1, 6);
uniform_real_distribution<double> score(0.0, 10.0);
using P = tuple<int, int, int>;
int n, k;
struct UnionFind {
vector<int> data;
UnionFind(int size) : data(size, -1) {}
bool unionSet(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
}
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)]; }
};
using Elem = tuple<int, int, int, int>;
int kruskal(vector<vector<P>> graph, int diff) {
vi a_cnt(2);
rep(v, n) for (auto &e : graph[v]) if (get<1>(e) == 0) get<0>(e) += diff;
int ret = 0;
rep(ai, 2) {
priority_queue<Elem, vector<Elem>, greater<Elem>> q;
rep(v, n) {
for (auto &e : graph[v]) {
int u, w, l;
tie(w, l, u) = e;
l *= -1;
e = P(w, l, u);
assert(l == 0 or l == 1 or l == -1);
if (v < u) {
q.push(Elem(w, l, u, v));
}
}
}
UnionFind uf(n);
ret = 0;
int cnt = 0;
while (q.size()) {
int w, l, v, u;
tie(w, l, v, u) = q.top();
q.pop();
assert(l == 0 or l == 1 or l == -1);
if (uf.findSet(v, u))
continue;
uf.unionSet(v, u);
cnt++;
ret += w;
if (l == 0) {
a_cnt[ai]++;
}
}
assert(cnt == n - 1);
}
ret -= diff * k;
if (a_cnt[0] > a_cnt[1])
swap(a_cnt[0], a_cnt[1]);
// cerr << a_cnt << endl;
if (not(a_cnt[0] <= k and k <= a_cnt[1]))
ret = (a_cnt[1] > k ? -1 : -2);
return ret;
}
int offset = 10000;
int main(void) {
for (int m; cin >> n >> m >> k, n;) {
vector<vector<P>> graph(n);
rep(loop, m) {
int u, v, w;
char l;
cin >> u >> v >> w >> l;
u--, v--, w += offset;
assert(0 <= u and u < n and 0 <= v and v < n);
graph[u].push_back(P(w, l == 'A' ? 0 : 1, v));
graph[v].push_back(P(w, l == 'A' ? 0 : 1, u));
}
int lb = -offset, ub = offset;
int res = -1;
rep(loop, 100) {
int mid = (lb + ub) / 2;
int ret = kruskal(graph, mid);
if (ret == -2) {
ub = mid;
} else if (ret == -1) {
lb = mid;
} else {
res = ret - (offset * (n - 1));
break;
}
}
cout << res << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#define _all(arg) begin(arg), end(arg)
#define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg))
#define getidx(ary, key) lower_bound(_all(ary), key) - begin(ary)
#define clr(a, b) memset((a), (b), sizeof(a))
#define bit(n) (1LL << (n))
// #define DEBUG
#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif
template <class T> bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf = 1LL << 62;
const ll mod = 1000000007LL;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll extgcd(ll a, ll b, ll &x, ll &y) {
x = 1, y = 0;
ll g = a;
if (b != 0)
g = extgcd(b, a % b, y, x), y -= a / b * x;
return g;
}
ll ADD(const ll &a, const ll &b, const ll &mod) { return (a + b) % mod; }
ll SUB(const ll &a, const ll &b, const ll &mod) { return (a - b + mod) % mod; }
ll MUL(const ll &a, const ll &b, const ll &mod) { return (1LL * a * b) % mod; }
ll DIV(const ll &a, const ll &b, const ll &mod) {
ll x, y;
extgcd(b, mod, x, y);
return MUL(a, (x + mod) % mod, mod);
}
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1, 6);
uniform_real_distribution<double> score(0.0, 10.0);
using P = tuple<int, int, int>;
int n, k;
struct UnionFind {
vector<int> data;
UnionFind(int size) : data(size, -1) {}
bool unionSet(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
}
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)]; }
};
using Elem = tuple<int, int, int, int>;
int kruskal(vector<vector<P>> graph, int diff) {
vi a_cnt(2);
rep(v, n) for (auto &e : graph[v]) if (get<1>(e) == 0) get<0>(e) += diff;
int ret = 0;
rep(ai, 2) {
priority_queue<Elem, vector<Elem>, greater<Elem>> q;
rep(v, n) {
for (auto &e : graph[v]) {
int u, w, l;
tie(w, l, u) = e;
l *= -1;
e = P(w, l, u);
assert(l == 0 or l == 1 or l == -1);
if (v < u) {
q.push(Elem(w, l, u, v));
}
}
}
UnionFind uf(n);
ret = 0;
int cnt = 0;
while (q.size()) {
int w, l, v, u;
tie(w, l, v, u) = q.top();
q.pop();
assert(l == 0 or l == 1 or l == -1);
if (uf.findSet(v, u))
continue;
uf.unionSet(v, u);
cnt++;
ret += w;
if (l == 0) {
a_cnt[ai]++;
}
}
if (cnt != n - 1) {
return -1;
}
}
ret -= diff * k;
if (a_cnt[0] > a_cnt[1])
swap(a_cnt[0], a_cnt[1]);
// cerr << a_cnt << endl;
if (not(a_cnt[0] <= k and k <= a_cnt[1]))
ret = (a_cnt[1] > k ? -1 : -2);
return ret;
}
int offset = 10000;
int main(void) {
for (int m; cin >> n >> m >> k, n;) {
vector<vector<P>> graph(n);
rep(loop, m) {
int u, v, w;
char l;
cin >> u >> v >> w >> l;
u--, v--, w += offset;
assert(0 <= u and u < n and 0 <= v and v < n);
graph[u].push_back(P(w, l == 'A' ? 0 : 1, v));
graph[v].push_back(P(w, l == 'A' ? 0 : 1, u));
}
int lb = -offset, ub = offset;
int res = -1;
rep(loop, 100) {
int mid = (lb + ub) / 2;
int ret = kruskal(graph, mid);
if (ret == -2) {
ub = mid;
} else if (ret == -1) {
lb = mid;
} else {
res = ret - (offset * (n - 1));
break;
}
}
cout << res << endl;
}
return 0;
} | replace | 131 | 132 | 131 | 134 | 0 | |
p01093 | C++ | Runtime Error | #include <iostream>
using namespace std;
int abs(int x) {
if (x >= 0)
return x;
else
return -x;
}
int main(void) {
while (true) {
int n;
cin >> n;
if (n == 0)
break;
int a[n];
for (size_t i = 0; i < n; i++)
cin >> a[i];
int min = 1000000;
for (size_t i = 0; i < n; i++) {
int first;
first = a[i];
for (size_t j = i + 1; j < n; j++) {
int diff = abs(first - a[j]);
if (diff < min)
min = diff;
}
}
cout << min << endl;
}
return true;
} | #include <iostream>
using namespace std;
int abs(int x) {
if (x >= 0)
return x;
else
return -x;
}
int main(void) {
while (true) {
int n;
cin >> n;
if (n == 0)
break;
int a[n];
for (size_t i = 0; i < n; i++)
cin >> a[i];
int min = 1000000;
for (size_t i = 0; i < n; i++) {
int first;
first = a[i];
for (size_t j = i + 1; j < n; j++) {
int diff = abs(first - a[j]);
if (diff < min)
min = diff;
}
}
cout << min << endl;
}
return 0;
} | replace | 32 | 33 | 32 | 33 | 1 | |
p01093 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int m, nmin, nmax, ans, gap;
int a[201];
int main() {
while (1) {
cin >> m;
if (m == 0)
break;
for (int i = 0; i < m; i++) {
cin >> a[i];
}
sort(a, a + (m));
gap = 1000001;
for (int i = 1; i < m; i++) {
if (a[i] - a[i - 1] <= gap) {
gap = a[i] - a[i - 1];
}
}
cout << gap << endl;
}
} | #include <algorithm>
#include <iostream>
using namespace std;
int m, nmin, nmax, ans, gap;
int a[1001];
int main() {
while (1) {
cin >> m;
if (m == 0)
break;
for (int i = 0; i < m; i++) {
cin >> a[i];
}
sort(a, a + (m));
gap = 1000001;
for (int i = 1; i < m; i++) {
if (a[i] - a[i - 1] <= gap) {
gap = a[i] - a[i - 1];
}
}
cout << gap << endl;
}
} | replace | 5 | 6 | 5 | 6 | 0 | |
p01093 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int t, n, k, x, ans, a;
while (1) {
vector<int> point;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x;
point.push_back(x);
}
sort(point.begin(), point.end());
reverse(point.begin(), point.end());
t = point[0];
for (int i = 1; i < n; ++i) {
k = point[i];
if (i == 1) {
ans = t - k;
} else {
a = t - k;
if (ans > a) {
ans = a;
}
}
t = k;
}
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int t, n, k, x, ans, a;
while (1) {
vector<int> point;
cin >> n;
if (n == 0) {
break;
}
for (int i = 0; i < n; ++i) {
cin >> x;
point.push_back(x);
}
sort(point.begin(), point.end());
reverse(point.begin(), point.end());
t = point[0];
for (int i = 1; i < n; ++i) {
k = point[i];
if (i == 1) {
ans = t - k;
} else {
a = t - k;
if (ans > a) {
ans = a;
}
}
t = k;
}
cout << ans << endl;
}
return 0;
} | insert | 12 | 12 | 12 | 16 | -11 | |
p01093 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) max((a), -(a))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000
typedef long long LL;
typedef long double LD;
int main() {
while (1) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(all(a));
int ans = 1000000000;
for (int i = 0; i < n - 1; i++) {
ans = min(ans, a[i + 1] - a[i]);
}
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) max((a), -(a))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000
typedef long long LL;
typedef long double LD;
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
return 0;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(all(a));
int ans = 1000000000;
for (int i = 0; i < n - 1; i++) {
ans = min(ans, a[i + 1] - a[i]);
}
cout << ans << endl;
}
return 0;
}
| insert | 23 | 23 | 23 | 25 | TLE | |
p01094 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using Cand = tuple<int, int>;
int get_name(const Cand &c) { return get<0>(c); }
int get_point(const Cand &c) { return get<1>(c); }
tuple<Cand, Cand> get_top_two_cands(const vector<int> &point) {
Cand top = make_tuple(-1, -1), second = make_tuple(-1, -1);
REP(j, 26) {
if (point[j] > get_point(top)) {
second = top;
top = make_tuple(j, point[j]);
} else if (point[j] > get_point(second)) {
second = make_tuple(j, point[j]);
}
}
return make_tuple(top, second);
}
int main() {
int N;
while (cin >> N && N) {
vector<char> C(26);
REP(i, N) { cin >> C[i]; }
vector<int> point(26, 0);
int votes = 0;
Cand top = make_tuple(0, 0), second = make_tuple(0, 0);
for (; votes < N && (N - votes) >= (get_point(top) - get_point(second));
++votes, tie(top, second) = get_top_two_cands(point)) {
++point[C[votes] - 'A'];
}
if (get_point(top) > get_point(second)) {
char name = 'A' + get_name(top);
cout << name << " " << votes << endl;
} else {
cout << "TIE" << endl;
}
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using Cand = tuple<int, int>;
int get_name(const Cand &c) { return get<0>(c); }
int get_point(const Cand &c) { return get<1>(c); }
tuple<Cand, Cand> get_top_two_cands(const vector<int> &point) {
Cand top = make_tuple(-1, -1), second = make_tuple(-1, -1);
REP(j, 26) {
if (point[j] > get_point(top)) {
second = top;
top = make_tuple(j, point[j]);
} else if (point[j] > get_point(second)) {
second = make_tuple(j, point[j]);
}
}
return make_tuple(top, second);
}
int main() {
int N;
while (cin >> N && N) {
vector<char> C(N);
REP(i, N) { cin >> C[i]; }
vector<int> point(26, 0);
int votes = 0;
Cand top = make_tuple(0, 0), second = make_tuple(0, 0);
for (; votes < N && (N - votes) >= (get_point(top) - get_point(second));
++votes, tie(top, second) = get_top_two_cands(point)) {
++point[C[votes] - 'A'];
}
if (get_point(top) > get_point(second)) {
char name = 'A' + get_name(top);
cout << name << " " << votes << endl;
} else {
cout << "TIE" << endl;
}
}
return 0;
} | replace | 33 | 34 | 33 | 34 | 0 | |
p01094 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
while (true) {
int n;
cin >> n;
if (n == 0)
break;
int c[n];
for (int i = 0; i < n; i++) {
cin >> c[i];
}
int can[26] = {0}; //????£????(candidate)????\¨??°
for (int i = 0; i < n; i++) {
can[(int)(c[i] - 'A')]++;
int max1 = -1; //??????
int max2 = -1; //??????
// A~Z???????\¨??°???????????????
for (int j = 0; j < 26; j++) {
if (can[j] > max1) {
max2 = max1;
max1 = can[j];
} else if (can[j] > max2) {
max2 = can[j];
}
}
//????????????????????????????\¨??°???????????????
if (max1 - max2 > n - (i + 1)) {
for (int j = 0; j < 26; j++) {
if (can[j] == max1) {
cout << (char)(j + 'A') << ' ';
break;
}
}
cout << (i + 1) << endl;
break;
}
//???????????§????\¨????????´???
if (i == n - 1) {
cout << "TIE" << endl;
break;
}
}
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
while (true) {
int n;
cin >> n;
if (n == 0)
break;
char c[n];
for (int i = 0; i < n; i++) {
cin >> c[i];
}
int can[26] = {0}; //????£????(candidate)????\¨??°
for (int i = 0; i < n; i++) {
can[(int)(c[i] - 'A')]++;
int max1 = -1; //??????
int max2 = -1; //??????
// A~Z???????\¨??°???????????????
for (int j = 0; j < 26; j++) {
if (can[j] > max1) {
max2 = max1;
max1 = can[j];
} else if (can[j] > max2) {
max2 = can[j];
}
}
//????????????????????????????\¨??°???????????????
if (max1 - max2 > n - (i + 1)) {
for (int j = 0; j < 26; j++) {
if (can[j] == max1) {
cout << (char)(j + 'A') << ' ';
break;
}
}
cout << (i + 1) << endl;
break;
}
//???????????§????\¨????????´???
if (i == n - 1) {
cout << "TIE" << endl;
break;
}
}
}
return 0;
} | replace | 10 | 11 | 10 | 11 | -11 | |
p01094 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
while (1) {
int n;
cin >> n;
char c[100];
for (int i = 0; i < n; i++) {
cin >> c[i];
}
int cnt[26] = {0};
for (int i = 0; i < n; i++) {
cnt[(int)(c[i] - 'A')]++;
int max1 = -1;
int max2 = -1;
for (int j = 0; j < 26; j++) {
if (cnt[j] > max1) {
max2 = max1;
max1 = cnt[j];
} else if (cnt[j] > max2) {
max2 = cnt[j];
}
}
if (max1 - max2 > n - (i + 1)) {
for (int j = 0; j < 26; j++) {
if (cnt[j] == max1) {
cout << (char)(j + 'A') << " ";
break;
}
}
cout << (i + 1) << endl;
break;
}
if (i == (n - 1)) {
cout << "TIE" << endl;
break;
}
}
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
char c[100];
for (int i = 0; i < n; i++) {
cin >> c[i];
}
int cnt[26] = {0};
for (int i = 0; i < n; i++) {
cnt[(int)(c[i] - 'A')]++;
int max1 = -1;
int max2 = -1;
for (int j = 0; j < 26; j++) {
if (cnt[j] > max1) {
max2 = max1;
max1 = cnt[j];
} else if (cnt[j] > max2) {
max2 = cnt[j];
}
}
if (max1 - max2 > n - (i + 1)) {
for (int j = 0; j < 26; j++) {
if (cnt[j] == max1) {
cout << (char)(j + 'A') << " ";
break;
}
}
cout << (i + 1) << endl;
break;
}
if (i == (n - 1)) {
cout << "TIE" << endl;
break;
}
}
}
return 0;
} | insert | 7 | 7 | 7 | 10 | TLE | |
p01095 | C++ | Time Limit Exceeded | // clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on
int t = 7368792;
main {
while (true) {
int m = in();
int n = in();
if (m == 0 && n == 0)
break;
vector<int> v(t);
int i = m;
rep(_, n) {
while (v[i])
i++;
for (int k = i; k < t; k += i)
v[k] = true;
}
while (v[i])
i++;
cout << i << endl;
}
}
| // clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on
int t = 7368792;
main {
while (true) {
int m = in();
int n = in();
if (m == 0 && n == 0)
break;
vector<bool> v(t);
int i = m;
rep(_, n) {
while (v[i])
i++;
for (int k = i; k < t; k += i)
v[k] = true;
}
while (v[i])
i++;
cout << i << endl;
}
}
| replace | 36 | 37 | 36 | 37 | TLE | |
p01095 | C++ | Runtime Error | #include <stdio.h>
#include <stdlib.h>
#define MAX 7368791
int main(void) {
int m, n;
int year[MAX];
while (1) {
scanf("%d %d", &m, &n);
if (m == 0 && n == 0)
break;
for (int i = 0; i < MAX; i++)
year[i] = false;
int seed = 0;
for (int i = m; i <= MAX; i++) {
if (!year[i - 1]) {
if (seed < n) {
for (int j = i; j <= MAX; j += i)
year[j - 1] = true;
seed++;
} else {
seed = i;
break;
}
}
}
printf("%d\n", seed);
}
return 0;
}
| #include <stdio.h>
#include <stdlib.h>
#define MAX 7368791
int main(void) {
int m, n;
bool year[MAX];
while (1) {
scanf("%d %d", &m, &n);
if (m == 0 && n == 0)
break;
for (int i = 0; i < MAX; i++)
year[i] = false;
int seed = 0;
for (int i = m; i <= MAX; i++) {
if (!year[i - 1]) {
if (seed < n) {
for (int j = i; j <= MAX; j += i)
year[j - 1] = true;
seed++;
} else {
seed = i;
break;
}
}
}
printf("%d\n", seed);
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | -11 | |
p01095 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <cmath>
#include <float.h>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define INT_MAX 2147483647
bool f[INT_MAX];
void del_flag(int m) {
int tmp = m;
while (tmp < INT_MAX) {
f[tmp] = false;
tmp += m;
}
}
int main() {
int m, n;
while (cin >> m >> n, n) {
for (int i = 0; i < INT_MAX; ++i) {
f[i] = true;
}
int tmp = m;
for (int i = 0; i < n; ++i) {
while (!f[tmp])
++tmp;
del_flag(tmp);
}
while (!f[tmp])
++tmp;
cout << tmp << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <float.h>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
void A();
void B();
#define INT_MAX 7368793
bool f[INT_MAX];
void del_flag(int m) {
int tmp = m;
while (tmp < INT_MAX) {
f[tmp] = false;
tmp += m;
}
}
int main() {
int m, n;
while (cin >> m >> n, n) {
for (int i = 0; i < INT_MAX; ++i) {
f[i] = true;
}
int tmp = m;
for (int i = 0; i < n; ++i) {
while (!f[tmp])
++tmp;
del_flag(tmp);
}
while (!f[tmp])
++tmp;
cout << tmp << endl;
}
return 0;
}
| replace | 12 | 13 | 12 | 15 | MLE | |
p01095 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
int main() {
int n, m;
while (scanf("%d %d", &m, &n) != EOF) {
if (n == 0 && m == 0)
break;
const int Max = 8e6;
// set<int> st;
// REP(i, m , Max) st.insert(i);
// rep(i, n) {
// int t = *st.begin();
// for(int j = t; j < Max; j += t) {
// if(st.count(j)) st.erase(j);
// }
// }
// cout << *st.begin() << endl;
vi v(Max, 0);
int cnt = 0;
REP(i, m, Max) {
if (v[i])
continue;
if (cnt == n) {
printf("%d\n", i);
break;
}
cnt++;
for (int j = i; j < Max; j += i)
v[j] = 1;
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
int main() {
int n, m;
while (scanf("%d %d", &m, &n) != EOF) {
if (n == 0 && m == 0)
break;
const int Max = 7368791 + 10;
// set<int> st;
// REP(i, m , Max) st.insert(i);
// rep(i, n) {
// int t = *st.begin();
// for(int j = t; j < Max; j += t) {
// if(st.count(j)) st.erase(j);
// }
// }
// cout << *st.begin() << endl;
vi v(Max, 0);
int cnt = 0;
REP(i, m, Max) {
if (v[i])
continue;
if (cnt == n) {
printf("%d\n", i);
break;
}
cnt++;
for (int j = i; j < Max; j += i)
v[j] = 1;
}
}
} | replace | 28 | 29 | 28 | 29 | TLE | |
p01095 | C++ | Runtime Error | #include <bits/stdc++.h>
bool ok[7368792];
int main() {
int m, n;
while (scanf("%d%d", &m, &n), m) {
memset(ok, 0, sizeof(ok));
int cnt = 0;
for (int i = m;; i++) {
if (!ok[i])
continue;
if (++cnt > n) {
printf("%d\n", i);
break;
}
for (int j = i; j <= 7368791; j += i)
ok[j] = true;
}
}
} | #include <bits/stdc++.h>
bool ok[7368792];
int main() {
int m, n;
while (scanf("%d%d", &m, &n), m) {
memset(ok, 0, sizeof(ok));
int cnt = 0;
for (int i = m;; i++) {
if (ok[i])
continue;
if (++cnt > n) {
printf("%d\n", i);
break;
}
for (int j = i; j <= 7368791; j += i)
ok[j] = true;
}
}
} | replace | 8 | 9 | 8 | 9 | -11 | |
p01095 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int MAX = 736891;
int main() {
int n, m;
bool f[MAX + 1];
while (1) {
cin >> m >> n;
if (m + n == 0)
break;
REP(i, MAX + 1) f[i] = false;
for (int i = m;; i++) {
if (!f[i]) {
if (n == 0) {
cout << i << endl;
break;
} else {
n--;
for (int j = i; j <= MAX; j += i) {
f[j] = true;
}
}
}
}
}
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int MAX = 7368791;
int main() {
int n, m;
bool f[MAX + 1];
while (1) {
cin >> m >> n;
if (m + n == 0)
break;
REP(i, MAX + 1) f[i] = false;
for (int i = m;; i++) {
if (!f[i]) {
if (n == 0) {
cout << i << endl;
break;
} else {
n--;
for (int j = i; j <= MAX; j += i) {
f[j] = true;
}
}
}
}
}
} | replace | 3 | 4 | 3 | 4 | -11 | |
p01095 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define N 8000000
using namespace std;
int prime[N] = {0};
int n, m, now = 0;
int sprime() {
int i, j;
for (i = n; i < N; ++i)
if (prime[i] == 0) {
if (now == m)
return i;
++now;
for (j = 1; i * j < N; ++j)
prime[i * j] = 1;
}
return 0;
}
int main() {
while (1) {
memset(prime, 0, sizeof(prime));
cin >> n >> m;
now = 0;
if (n + m == 0)
break;
cout << sprime() << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define N 8000000
using namespace std;
int prime[N] = {0};
int n, m, now = 0;
int sprime() {
int i, j;
for (i = n; i < N; ++i)
if (prime[i] == 0) {
if (now == m)
return i;
++now;
for (j = 1; i * j < min(N, m * 1000); ++j)
prime[i * j] = 1;
}
return 0;
}
int main() {
while (1) {
memset(prime, 0, sizeof(prime));
cin >> n >> m;
now = 0;
if (n + m == 0)
break;
cout << sprime() << endl;
}
return 0;
}
| replace | 14 | 15 | 14 | 15 | TLE | |
p01095 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
bool a[7368800];
int main() {
int m = 3, n = 1;
while (/*cin >>m>> n&&*/ n != 0 && m != 0) {
int sum = m, n2 = n;
fill(a, a + 7368800, false);
while (n2 != 0 || a[sum]) {
if (!a[sum]) {
a[sum] = true;
int j = 2;
while (sum * j < 7368800) {
a[sum * j] = true;
j++;
}
n2--;
}
sum++;
}
cout << sum << endl;
}
} | #include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
bool a[7368800];
int main() {
int m = 3, n = 1;
while (cin >> m >> n && n != 0 && m != 0) {
int sum = m, n2 = n;
fill(a, a + 7368800, false);
while (n2 != 0 || a[sum]) {
if (!a[sum]) {
a[sum] = true;
int j = 2;
while (sum * j < 7368800) {
a[sum * j] = true;
j++;
}
n2--;
}
sum++;
}
cout << sum << endl;
}
} | replace | 8 | 9 | 8 | 9 | TLE | |
p01095 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef pair<int, P> PP;
bool memo[8000000];
int m, n;
void furui(int n, int count) {
fill(memo, memo + 8000000, true);
int cnt = 0;
for (int i = m; i <= m + n; i++) {
if (memo[i - m]) {
memo[i - m] = false;
for (int j = 2 * i; j <= n; j += i) {
memo[j - m] = false;
}
cnt++;
break;
if (cnt == count)
return;
}
}
return;
}
int main() {
while (cin >> m >> n) {
if (m == 0 && n == 0)
return 0;
fill(memo, memo + 8000000, true);
int l = m;
for (int k = 0; k < n; k++) {
for (int i = l; i <= 8000000; i++) {
if (memo[i - m]) {
l = i;
memo[i - m] = false;
for (int j = ((m - i + 1) / i) * i; j <= 8000000; j += i) {
memo[j - m] = false;
}
break;
}
}
/*
for(int i=m;i<=13;i++){
cout<<i<<" memo[i-m]:"<<memo[i-m]<<" ";
}
cout<<endl;
*/
}
for (int i = 0; i <= 8000000; i++) {
if (memo[i]) {
cout << i + m << endl;
break;
}
}
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef pair<int, P> PP;
bool memo[8000000];
int m, n;
void furui(int n, int count) {
fill(memo, memo + 8000000, true);
int cnt = 0;
for (int i = m; i <= m + n; i++) {
if (memo[i - m]) {
memo[i - m] = false;
for (int j = 2 * i; j <= n; j += i) {
memo[j - m] = false;
}
cnt++;
break;
if (cnt == count)
return;
}
}
return;
}
int main() {
while (cin >> m >> n) {
if (m == 0 && n == 0)
return 0;
fill(memo, memo + 8000000, true);
int l = m;
for (int k = 0; k < n; k++) {
for (int i = l; i <= 8000000; i++) {
if (memo[i - m]) {
l = i;
memo[i - m] = false;
for (int j = ((m + i - 1) / i) * i; j <= 8000000; j += i) {
memo[j - m] = false;
}
break;
}
}
/*
for(int i=m;i<=13;i++){
cout<<i<<" memo[i-m]:"<<memo[i-m]<<" ";
}
cout<<endl;
*/
}
for (int i = 0; i <= 8000000; i++) {
if (memo[i]) {
cout << i + m << endl;
break;
}
}
}
return 0;
} | replace | 49 | 50 | 49 | 50 | 0 | |
p01095 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long int a[10000000] = {};
int main() {
const long long int mod = 1000000007;
map<long long int, long long int> mp;
// cout << fixed << setprecision(10);
long long int n, m, b, c, d, k, sa, h, w, left = 1, right = 0;
long long int sc, sr, num2, no[1005][1005] = {}, res = 999999999, count = 0,
now = 0, mi = 9999999999;
string str, t;
cin >> m >> n;
while (1) {
res = 0;
count = n;
now = m;
if (m == 0 && n == 0) {
return 0;
}
while (1) {
if (count == 0 && a[now] == 0) {
cout << now << endl;
for (int i = 2; i < 7500000; i++) {
a[i] = 0;
}
break;
}
if (a[now] == 0) {
for (int i = 2; i * now < 7500000; i++) {
a[i * now] = 1;
}
count--;
}
now++;
}
cin >> m >> n;
}
}
| #include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int a[10000000] = {};
int main() {
const long long int mod = 1000000007;
map<long long int, long long int> mp;
// cout << fixed << setprecision(10);
long long int n, m, b, c, d, k, sa, h, w, left = 1, right = 0;
long long int sc, sr, num2, no[1005][1005] = {}, res = 999999999, count = 0,
now = 0, mi = 9999999999;
string str, t;
cin >> m >> n;
while (1) {
res = 0;
count = n;
now = m;
if (m == 0 && n == 0) {
return 0;
}
while (1) {
if (count == 0 && a[now] == 0) {
cout << now << endl;
for (int i = 2; i < 7500000; i++) {
a[i] = 0;
}
break;
}
if (a[now] == 0) {
for (int i = 2; i * now < 7500000; i++) {
a[i * now] = 1;
}
count--;
}
now++;
}
cin >> m >> n;
}
}
| replace | 12 | 13 | 12 | 13 | TLE | |
p01095 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
while (cin >> m >> n, m) {
bool s[7654321] = {};
int i = m, j = 0, k;
for (; j <= n; i++)
if (!s[i] && j != n)
for (k = 2, j++; i * k < 7654321; k++)
s[i * k] = 1;
cout << i - 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
while (cin >> m >> n, m) {
bool s[7654321] = {};
int i = m, j = 0, k;
for (; j <= n; i++)
if (!s[i])
for (k = 2, j++; i * k < 7654321; k++)
s[i * k] = 1;
cout << i - 1 << endl;
}
return 0;
} | replace | 8 | 9 | 8 | 9 | -11 | |
p01095 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e7;
int primes[MAX_N + 1]; // i????´???°??????true
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int m, n;
cin >> m >> n;
if (m == 0 && n == 0)
break;
for (int i = 0; i < MAX_N; i++)
primes[i] = true;
int count = 0;
primes[0] = primes[1] = false;
for (int i = m; i <= MAX_N; i++) {
if (primes[i]) {
for (int j = 2 * i; j <= MAX_N; j += i)
primes[j] = false;
count++;
if (count > n) {
cout << i << endl;
break;
}
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 7.4 * 1e6;
int primes[MAX_N + 1]; // i????´???°??????true
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int m, n;
cin >> m >> n;
if (m == 0 && n == 0)
break;
for (int i = 0; i < MAX_N; i++)
primes[i] = true;
int count = 0;
primes[0] = primes[1] = false;
for (int i = m; i <= MAX_N; i++) {
if (primes[i]) {
for (int j = 2 * i; j <= MAX_N; j += i)
primes[j] = false;
count++;
if (count > n) {
cout << i << endl;
break;
}
}
}
}
} | replace | 4 | 5 | 4 | 5 | TLE | |
p01095 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
bool e[7368792];
int main() {
while (true) {
int m, n;
cin >> m >> n;
if (m + n == 0) {
break;
}
memset(e, false, sizeof(e));
int count = 0;
for (int i = m; count < n; i++) {
if (!e[i]) {
count++;
}
for (int j = 1; i * j < 7368792; j++) {
e[i * j] = true;
}
}
for (int i = m + 1;; i++) {
if (!e[i]) {
cout << i << endl;
break;
}
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
bool e[7368792];
int main() {
while (true) {
int m, n;
cin >> m >> n;
if (m + n == 0) {
break;
}
memset(e, false, sizeof(e));
int count = 0;
for (int i = m; count < n; i++) {
if (!e[i]) {
count++;
} else {
continue;
}
for (int j = 1; i * j < 7368792; j++) {
e[i * j] = true;
}
}
for (int i = m + 1;; i++) {
if (!e[i]) {
cout << i << endl;
break;
}
}
}
return 0;
} | insert | 19 | 19 | 19 | 21 | TLE | |
p01095 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
while (cin >> m >> n, m) {
vector<int> goodyear(7368792, 0);
int cnt = 0;
int res = -1;
for (int i = m;; i++) {
if (goodyear[i] == 0) {
if (cnt == n) {
res = i;
break;
} else {
cnt++;
for (int j = i; j < 1e7; j += i) {
goodyear[j] = 1;
}
}
}
}
cout << res << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
while (cin >> m >> n, m) {
vector<int> goodyear(7368792, 0);
int cnt = 0;
int res = -1;
for (int i = m;; i++) {
if (goodyear[i] == 0) {
if (cnt == n) {
res = i;
break;
} else {
cnt++;
for (int j = i; j < 7368792; j += i) {
goodyear[j] = 1;
}
}
}
}
cout << res << endl;
}
} | replace | 16 | 17 | 16 | 17 | -11 | |
p01095 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#define MAX (7368791 + 1)
using namespace std;
bool a[MAX];
int main(void) {
int m, n;
while (cin >> m >> n, m || n) {
fill(a, a + MAX, true);
int count = 0;
for (int i = m; i < MAX; i++) {
if (a[i] == true) {
if (count == n) {
cout << i << endl;
break;
}
count++;
for (int j = i + i; j < MAX; j += i) {
a[j] = false;
}
}
}
}
while (1)
;
return 0;
}
| #include <algorithm>
#include <iostream>
#define MAX (7368791 + 1)
using namespace std;
bool a[MAX];
int main(void) {
int m, n;
while (cin >> m >> n, m || n) {
fill(a, a + MAX, true);
int count = 0;
for (int i = m; i < MAX; i++) {
if (a[i] == true) {
if (count == n) {
cout << i << endl;
break;
}
count++;
for (int j = i + i; j < MAX; j += i) {
a[j] = false;
}
}
}
}
return 0;
}
| delete | 27 | 29 | 27 | 27 | TLE | |
p01096 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int n;
vector<int> w;
int dp[310][310];
int calc(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
if (l + 1 >= r)
return dp[l][r] = 0;
int res = 0;
rep(i, l, r - 1) {
rep(j, i + 1, r) {
int tmp = 0;
tmp += calc(l, i) + calc(i + 1, j) + calc(j + 1, r);
int cent = calc(i + 1, j);
int len = j - i - 1;
if (abs(w[i] - w[j]) <= 1 && len == cent * 2)
tmp++;
res = max(res, tmp);
}
}
return dp[l][r] = res;
}
int main() {
while (cin >> n, n) {
w.clear();
w.resize(n);
rep(i, 0, n) cin >> w[i];
rep(i, 0, n + 1) rep(j, 0, n + 1) dp[i][j] = -1;
int ans = calc(0, n);
cout << ans * 2 << endl;
}
}
| #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int n;
vector<int> w;
int dp[310][310];
int calc(int l, int r) {
if (dp[l][r] != -1)
return dp[l][r];
if (l + 1 >= r)
return dp[l][r] = 0;
int res = 0;
rep(i, l, r) {
int tmp = 0;
int cent = calc(l + 1, i);
int len = i - l - 1;
if (abs(w[l] - w[i]) <= 1 && len == cent * 2)
tmp++;
tmp += cent + calc(i + 1, r);
res = max(res, tmp);
}
return dp[l][r] = res;
}
int main() {
while (cin >> n, n) {
w.clear();
w.resize(n);
rep(i, 0, n) cin >> w[i];
rep(i, 0, n + 1) rep(j, 0, n + 1) dp[i][j] = -1;
int ans = calc(0, n);
cout << ans * 2 << endl;
}
}
| replace | 14 | 24 | 14 | 22 | TLE | |
p01096 | C++ | Runtime Error | // #define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a <= x && x < b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
// #define int ll
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int w[305], dp[305][305];
signed main(void) {
while (true) {
int n;
cin >> n;
if (!n)
break;
REP(i, n) cin >> w[i];
REP(i, 305) REP(j, 305) dp[i][j] = 0;
FOR(W, 2, n + 1) {
REP(i, n) {
int j = i + W - 1;
// cout << i << " " << j << endl;
if (dp[i + 1][j - 1] == W - 2 && abs(w[i] - w[j]) <= 1)
dp[i][j] = W;
FOR(k, i, j) {
dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]);
// cout << dp[i][j] << endl;
}
}
}
/*REP(i, n) {
cout << i << ":";
REP(j, n) {
cout << dp[i][j] << " ";
}
cout << endl;
}*/
cout << dp[0][n - 1] << endl;
}
return 0;
} | // #define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a <= x && x < b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
// #define int ll
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int w[305], dp[305][305];
signed main(void) {
while (true) {
int n;
cin >> n;
if (!n)
break;
REP(i, n) cin >> w[i];
REP(i, 305) REP(j, 305) dp[i][j] = 0;
FOR(W, 2, n + 1) {
REP(i, n) {
int j = i + W - 1;
if (j >= n)
continue;
// cout << i << " " << j << endl;
if (dp[i + 1][j - 1] == W - 2 && abs(w[i] - w[j]) <= 1)
dp[i][j] = W;
FOR(k, i, j) {
dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]);
// cout << dp[i][j] << endl;
}
}
}
/*REP(i, n) {
cout << i << ":";
REP(j, n) {
cout << dp[i][j] << " ";
}
cout << endl;
}*/
cout << dp[0][n - 1] << endl;
}
return 0;
} | insert | 39 | 39 | 39 | 41 | 0 | |
p01096 | C++ | Runtime Error | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
using namespace std;
int dx[5] = {1, 0, -1, 0, 0}, dy[5] = {0, 1, 0, -1, 0};
long long gcd(long long a, long long b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
if (a == 0) {
return b;
}
return a / gcd(a, b) * b;
}
#define INF 2000000000
#define MOD 1000000007
#define sym cout << "---------" << endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int, int>
int dp[305][305];
signed main() {
int n;
while (cin >> n && n) {
int w[305];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++)
cin >> w[i];
for (int W = 2; W <= n; W++) {
for (int l = 0; l < n; l++) {
int r = l + W;
if (dp[l + 1][r - 1] == W - 2 && abs(w[l] - w[r - 1]) <= 1)
dp[l][r] = W;
for (int mid = l; mid <= r; mid++) {
dp[l][r] = max(dp[l][r], dp[l][mid] + dp[mid][r]);
}
}
}
cout << dp[0][n] << en;
}
}
| #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
using namespace std;
int dx[5] = {1, 0, -1, 0, 0}, dy[5] = {0, 1, 0, -1, 0};
long long gcd(long long a, long long b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
if (a == 0) {
return b;
}
return a / gcd(a, b) * b;
}
#define INF 2000000000
#define MOD 1000000007
#define sym cout << "---------" << endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int, int>
int dp[305][305];
signed main() {
int n;
while (cin >> n && n) {
int w[305];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++)
cin >> w[i];
for (int W = 2; W <= n; W++) {
for (int l = 0; l < n; l++) {
int r = l + W;
if (r > n)
continue;
if (dp[l + 1][r - 1] == W - 2 && abs(w[l] - w[r - 1]) <= 1)
dp[l][r] = W;
for (int mid = l; mid <= r; mid++) {
dp[l][r] = max(dp[l][r], dp[l][mid] + dp[mid][r]);
}
}
}
cout << dp[0][n] << en;
}
}
| insert | 60 | 60 | 60 | 62 | 0 | |
p01096 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, N) for (int i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3
int n;
int x[100];
int dp[300][300];
int ans[300];
int C(int lb, int ub) {
if (dp[lb][ub] != -1)
return dp[lb][ub];
if (ub - lb <= 0)
return dp[ub][lb] = 0;
else if (ub - lb == 1) {
if (abs(x[lb] - x[ub]) <= 1)
return dp[lb][ub] = 2;
return dp[lb][ub] = 0;
}
int res = 0;
if (abs(x[lb] - x[ub]) <= 1) {
if (C(lb + 1, ub - 1) == ub - lb - 1) {
res = C(lb + 1, ub - 1) + 2;
}
}
FOR(mid, lb, ub) { res = max(res, C(lb, mid) + C(mid + 1, ub)); }
return dp[lb][ub] = res;
}
int main() {
while (cin >> n && n) {
rep(i, 300) rep(j, 300) { dp[i][j] = -1; }
rep(i, n) cin >> x[i];
cout << C(0, n - 1) << endl;
}
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, N) for (int i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3
int n;
int x[1000];
int dp[300][300];
int ans[300];
int C(int lb, int ub) {
if (dp[lb][ub] != -1)
return dp[lb][ub];
if (ub - lb <= 0)
return dp[ub][lb] = 0;
else if (ub - lb == 1) {
if (abs(x[lb] - x[ub]) <= 1)
return dp[lb][ub] = 2;
return dp[lb][ub] = 0;
}
int res = 0;
if (abs(x[lb] - x[ub]) <= 1) {
if (C(lb + 1, ub - 1) == ub - lb - 1) {
res = C(lb + 1, ub - 1) + 2;
}
}
FOR(mid, lb, ub) { res = max(res, C(lb, mid) + C(mid + 1, ub)); }
return dp[lb][ub] = res;
}
int main() {
while (cin >> n && n) {
rep(i, 300) rep(j, 300) { dp[i][j] = -1; }
rep(i, n) cin >> x[i];
cout << C(0, n - 1) << endl;
}
} | replace | 43 | 44 | 43 | 44 | 0 | |
p01096 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct UnionFind {
vector<int> v;
UnionFind(int n) : v(n) {
for (int i = 0; i < n; i++)
v[i] = i;
}
int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
void unite(int x, int y) { v[find(x)] = find(y); }
};
int main() {
int n;
while (cin >> n, n) {
vi num(n);
REP(i, n)
cin >> num[i];
vector<vector<bool>> able(n, vb(n, false));
for (int i = 2; i < n + 1; i += 2) {
for (int j = 0; j + i - 1 < n; j++) {
if (i == 2) {
if (abs(num[j] - num[j + i - 1]) <= 1)
able[j][j + i - 1] = true;
} else {
if (abs(num[j] - num[j + i - 1]) <= 1 && able[j + 1][j + i - 2])
able[j][j + i - 1] = true;
REP(k, i / 2 - 1)
if (able[j][j + k * 2 + 1] && able[j + k * 2 + 2][j + i - 1])
able[j][j + i - 1] = true;
}
}
}
vvi DP(n, vi(n, 0));
REP(i, n)
REP(j, n)
if (able[i][j])
DP[i][j] = j - i + 1;
for (int i = 3; i < n + 1; i++) {
for (int j = 0; j + i - 1 < n; j++)
REP(k, i)
DP[j][j + i - 1] =
max(DP[j][j + i - 1], DP[j][j + k] + DP[j + k + 1][j + i - 1]);
}
cout << DP[0][n - 1] << endl;
}
} | #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOG(...) printf(__VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define CLR(a) memset((a), 0, sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct UnionFind {
vector<int> v;
UnionFind(int n) : v(n) {
for (int i = 0; i < n; i++)
v[i] = i;
}
int find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
void unite(int x, int y) { v[find(x)] = find(y); }
};
int main() {
int n;
while (cin >> n, n) {
vi num(n);
REP(i, n)
cin >> num[i];
vector<vector<bool>> able(n, vb(n, false));
for (int i = 2; i < n + 1; i += 2) {
for (int j = 0; j + i - 1 < n; j++) {
if (i == 2) {
if (abs(num[j] - num[j + i - 1]) <= 1)
able[j][j + i - 1] = true;
} else {
if (abs(num[j] - num[j + i - 1]) <= 1 && able[j + 1][j + i - 2])
able[j][j + i - 1] = true;
REP(k, i / 2 - 1)
if (able[j][j + k * 2 + 1] && able[j + k * 2 + 2][j + i - 1])
able[j][j + i - 1] = true;
}
}
}
vvi DP(n, vi(n, 0));
REP(i, n)
REP(j, n)
if (able[i][j])
DP[i][j] = j - i + 1;
for (int i = 3; i < n + 1; i++) {
for (int j = 0; j + i - 1 < n; j++)
REP(k, i - 1)
DP[j][j + i - 1] =
max(DP[j][j + i - 1], DP[j][j + k] + DP[j + k + 1][j + i - 1]);
}
cout << DP[0][n - 1] << endl;
}
} | replace | 84 | 85 | 84 | 85 | -11 | |
p01096 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
inline int abs(int a, int b) { return a < b ? b - a : a - b; }
int w[301];
bool rm[301][301];
int rmct[301][301];
int main() {
int n;
while (cin >> n, n) {
for (int i = 0; i < n; i++)
cin >> w[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
rm[i][j] = i == j;
for (int r = 2; r <= n; r += 2) {
for (int i = 0; i + r <= n; i++) {
for (int s = 2; s < r; s += 2) {
if (rm[i][i + s] && rm[i + s][i + r])
rm[i][i + r] = true;
}
if (!rm[i][i + r] && rm[i + 1][i + r - 1] &&
abs(w[i], w[i + r - 1]) <= 1)
rm[i][i + r] = true;
}
}
/*
int rmw = -1;
for(int rmr = n / 2 * 2; rmw==-1 && rmr >= 0; rmr-=2)
{
for(int i=0; i+rmr<=n; i++)
{
if(rm[i][i+rmr])
{
rmw = rmr;
break;
}
}
}
*/
for (int y = 0; y <= n; y++)
for (int x = 0; x <= n; x++)
rmct[y][x] = rm[y][x] ? x - y : 0;
for (int r = 1; r <= n; r++) {
for (int i = 0; i <= n; i++) {
for (int s = 1; s < r; s++) {
rmct[i][i + r] =
max(rmct[i][i + r], rmct[i][i + s] + rmct[i + s][i + r]);
}
}
}
cout << rmct[0][n] << endl;
// XXX DEBUG
/*
printf("i\\j ");
for(int x=0; x<=n; x++) printf("%3d ", x);
cout << endl;
for(int y=0; y<=n; y++)
{
printf("%3d ", y);
for(int x=0; x<=n; x++)
{
printf("%3d ", rm[y][x]);
}
cout << endl;
}
*/
// XXX DEBUG
// cout << rmw << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
inline int abs(int a, int b) { return a < b ? b - a : a - b; }
int w[301];
bool rm[301][301];
int rmct[301][301];
int main() {
int n;
while (cin >> n, n) {
for (int i = 0; i < n; i++)
cin >> w[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
rm[i][j] = i == j;
for (int r = 2; r <= n; r += 2) {
for (int i = 0; i + r <= n; i++) {
for (int s = 2; s < r; s += 2) {
if (rm[i][i + s] && rm[i + s][i + r])
rm[i][i + r] = true;
}
if (!rm[i][i + r] && rm[i + 1][i + r - 1] &&
abs(w[i], w[i + r - 1]) <= 1)
rm[i][i + r] = true;
}
}
/*
int rmw = -1;
for(int rmr = n / 2 * 2; rmw==-1 && rmr >= 0; rmr-=2)
{
for(int i=0; i+rmr<=n; i++)
{
if(rm[i][i+rmr])
{
rmw = rmr;
break;
}
}
}
*/
for (int y = 0; y <= n; y++)
for (int x = 0; x <= n; x++)
rmct[y][x] = rm[y][x] ? x - y : 0;
for (int r = 1; r <= n; r++) {
for (int i = 0; i + r <= n; i++) {
for (int s = 1; s < r; s++) {
rmct[i][i + r] =
max(rmct[i][i + r], rmct[i][i + s] + rmct[i + s][i + r]);
}
}
}
cout << rmct[0][n] << endl;
// XXX DEBUG
/*
printf("i\\j ");
for(int x=0; x<=n; x++) printf("%3d ", x);
cout << endl;
for(int y=0; y<=n; y++)
{
printf("%3d ", y);
for(int x=0; x<=n; x++)
{
printf("%3d ", rm[y][x]);
}
cout << endl;
}
*/
// XXX DEBUG
// cout << rmw << endl;
}
} | replace | 47 | 48 | 47 | 48 | 0 | |
p01096 | C++ | Runtime Error | #include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;
bool check(int a, int b) { return abs(a - b) <= 1; }
int main() {
int n;
while (cin >> n, n) {
vector<int> w(n);
rep(i, n) { cin >> w[i]; }
int dp[300][300] = {{0}};
range(W, 2, n + 1) {
rep(i, n) {
int j = i + W - 1;
if (check(w[i], w[j]) && dp[i + 1][j - 1] == W - 2) {
dp[i][j] = W;
}
range(k, i, j) { dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]); }
}
}
cout << dp[0][n - 1] << endl;
}
} | #include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;
bool check(int a, int b) { return abs(a - b) <= 1; }
int main() {
int n;
while (cin >> n, n) {
vector<int> w(n);
rep(i, n) { cin >> w[i]; }
int dp[300][300] = {{0}};
range(W, 2, n + 1) {
rep(i, n) {
int j = i + W - 1;
if (i + W - 1 >= 300)
break;
if (check(w[i], w[j]) && dp[i + 1][j - 1] == W - 2) {
dp[i][j] = W;
}
range(k, i, j) { dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]); }
}
}
cout << dp[0][n - 1] << endl;
}
} | insert | 19 | 19 | 19 | 21 | 0 | |
p01096 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;
int main() {
int N, data[301];
bool **table = new bool
*[301]; // table[left][right] =
// left???????§?????????????2*right??????????????¨?¶??????§??????????????????
int **maximum =
new int *[301]; //?????????????????????????????§?¶????????????°
for (int i = 0; i <= 300; i++) {
table[i] = new bool[151];
maximum[i] = new int[301];
}
bool FLG;
while (true) {
scanf("%d", &N);
if (N == 0)
break;
if (N <= 1) {
printf("0\n");
continue;
}
//?¶??????????????????????????????????
for (int i = 1; i <= N; i++) {
for (int k = 0; k <= N / 2; k++)
table[i][k] = false;
for (int k = 1; k <= N; k++)
maximum[i][k] = 0;
}
for (int i = 1; i <= N; i++)
scanf("%d", &data[i]);
//????????????2???????¨?
for (int i = 1; i <= N - 1; i++) {
if (abs(data[i + 1] - data[i]) <= 1) {
table[i][1] = true;
maximum[i][i + 1] = 2;
}
}
//?¶??????????????????????????¨????
for (int length = 4; length <= N; length += 2) { //??????????????????
for (int left = 1; left + length - 1 <= N; left++) { //??????????????????
FLG = false;
if (table[left + 1][(length - 2) / 2] == true &&
abs(data[left] - data[left + length - 1]) <= 1)
FLG =
true; //??????????????£?????????length-2??????????¶????????????????????????¨??????+length-1?????´???????????????????¶?????????´???
if (!FLG) {
for (int i = 2; i <= length - 2; i += 2) {
if (table[left][i / 2] == true &&
table[left + i][(length - i) / 2] == true) {
FLG = true;
break;
}
}
}
if (FLG) {
table[left][length / 2] = true;
maximum[left][left + length - 1] =
length; //????¨?????????§??????OK????????§?????¶????????§???????¨????
} else {
// maximum[left][left+length-1]?????´??°????????°????????????
for (int div = 0; left + div <= left + length - 2;
div++) { //????´¢?§????????????????
for (
int i = 2; left + div + i - 1 <= left + length - 1;
i +=
2) { //????´¢?§?????????????????????´?????????????????§????????¢?????????
maximum[left][left + length - 1] =
max(maximum[left][left + length - 1],
maximum[left + div][left + div + i - 1] +
maximum[left + div + i][left + length - 1]);
}
}
// printf("maximum[%d][%d]:%d\n",left,left+length-1,maximum[left][left+length-1]);
}
}
}
if (N % 2 == 0)
printf("%d\n", maximum[1][N]);
else {
printf("%d\n", max(maximum[1][N - 1], maximum[2][N]));
}
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;
int main() {
int N, data[301];
bool **table = new bool
*[301]; // table[left][right] =
// left???????§?????????????2*right??????????????¨?¶??????§??????????????????
int **maximum =
new int *[301]; //?????????????????????????????§?¶????????????°
for (int i = 0; i <= 300; i++) {
table[i] = new bool[151];
maximum[i] = new int[301];
}
bool FLG;
while (true) {
scanf("%d", &N);
if (N == 0)
break;
if (N <= 1) {
printf("0\n");
continue;
}
//?¶??????????????????????????????????
for (int i = 1; i <= N; i++) {
for (int k = 0; k <= N / 2; k++)
table[i][k] = false;
for (int k = 1; k <= N; k++)
maximum[i][k] = 0;
}
for (int i = 1; i <= N; i++)
scanf("%d", &data[i]);
//????????????2???????¨?
for (int i = 1; i <= N - 1; i++) {
if (abs(data[i + 1] - data[i]) <= 1) {
table[i][1] = true;
maximum[i][i + 1] = 2;
}
}
//?¶??????????????????????????¨????
for (int length = 4; length <= N; length += 2) { //??????????????????
for (int left = 1; left + length - 1 <= N; left++) { //??????????????????
FLG = false;
if (table[left + 1][(length - 2) / 2] == true &&
abs(data[left] - data[left + length - 1]) <= 1)
FLG =
true; //??????????????£?????????length-2??????????¶????????????????????????¨??????+length-1?????´???????????????????¶?????????´???
if (!FLG) {
for (int i = 2; i <= length - 2; i += 2) {
if (table[left][i / 2] == true &&
table[left + i][(length - i) / 2] == true) {
FLG = true;
break;
}
}
}
if (FLG) {
table[left][length / 2] = true;
maximum[left][left + length - 1] =
length; //????¨?????????§??????OK????????§?????¶????????§???????¨????
} else {
// maximum[left][left+length-1]?????´??°????????°????????????
for (int div = 0; left + div <= left + length - 2;
div++) { //????´¢?§????????????????
for (
int i = 2; left + div + i - 1 <= left + length - 1;
i +=
2) { //????´¢?§?????????????????????´?????????????????§????????¢?????????
maximum[left][left + length - 1] =
max(maximum[left][left + length - 1],
maximum[left + div][left + div + i - 1] +
maximum[min(left + length - 1, left + div + i)]
[left + length - 1]);
}
}
// printf("maximum[%d][%d]:%d\n",left,left+length-1,maximum[left][left+length-1]);
}
}
}
if (N % 2 == 0)
printf("%d\n", maximum[1][N]);
else {
printf("%d\n", max(maximum[1][N - 1], maximum[2][N]));
}
}
return 0;
} | replace | 89 | 90 | 89 | 91 | 0 | |
p01096 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#define ll long long
using namespace std;
typedef pair<int, int> P;
int N, W[300], dp[300][300];
int rec(int l, int r) {
if (l >= r)
return 0;
if (dp[l][r] != -1)
return (dp[l][r]);
int ret = 0;
if (abs(W[l] - W[r]) <= 1 && rec(l + 1, r - 1) == r - l - 1)
ret = r - l + 1;
for (int m = l; m < r; m++)
ret = max(ret, rec(l, m) + rec(m + 1, r));
return (dp[l][r] = ret);
}
int main() {
while (1) {
cin >> N;
for (int i = 0; i < N; i++)
cin >> W[i];
memset(dp, -1, sizeof(dp));
cout << rec(0, N - 1) << endl;
}
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#define ll long long
using namespace std;
typedef pair<int, int> P;
int N, W[300], dp[300][300];
int rec(int l, int r) {
if (l >= r)
return 0;
if (dp[l][r] != -1)
return (dp[l][r]);
int ret = 0;
if (abs(W[l] - W[r]) <= 1 && rec(l + 1, r - 1) == r - l - 1)
ret = r - l + 1;
for (int m = l; m < r; m++)
ret = max(ret, rec(l, m) + rec(m + 1, r));
return (dp[l][r] = ret);
}
int main() {
while (1) {
cin >> N;
if (N == 0)
break;
for (int i = 0; i < N; i++)
cin >> W[i];
memset(dp, -1, sizeof(dp));
cout << rec(0, N - 1) << endl;
}
}
| insert | 36 | 36 | 36 | 38 | TLE | |
p01096 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
bool used[310][310];
bool dp[310][310];
vi w;
int dp2[310][310];
template <typename T> T chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> T chmin(T &a, const T &b) { return a = min(a, b); }
//[l, r) de tatakeruka
bool calc(int l, int r) {
if (r - l <= 1)
return false;
if (used[l][r])
return dp[l][r];
used[l][r] = true;
if (r - l == 2) {
return dp[l][r] = (abs(w[l] - w[r - 1]) <= 1);
}
for (int m = l + 1; m < r; m++) {
bool f = true;
f &= calc(l, m);
f &= calc(m, r);
dp[l][r] |= f;
}
if (abs(w[l] - w[r - 1]) <= 1)
dp[l][r] |= calc(l + 1, r - 1);
return dp[l][r];
}
int calc2(int l, int r) {
if (dp2[l][r] != -1)
return dp2[l][r];
if (r - l <= 1)
return dp2[l][r] = 0;
if (dp[l][r])
return dp2[l][r] = r - l;
int ret = 0;
for (int m = l + 1; m < r; m++) {
chmax(ret, calc2(l, m) + calc2(m, r));
}
return ret;
}
int main() {
int n;
while (cin >> n && n) {
w.clear();
w.resize(n);
rep(i, n) cin >> w[i];
rep(i, 310) rep(j, 310) dp[i][j] = used[i][j] = false, dp2[i][j] = -1;
REP(r, 1, n + 1) rep(l, r) calc(l, r);
cout << calc2(0, n) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
bool used[310][310];
bool dp[310][310];
vi w;
int dp2[310][310];
template <typename T> T chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> T chmin(T &a, const T &b) { return a = min(a, b); }
//[l, r) de tatakeruka
bool calc(int l, int r) {
if (r - l <= 1)
return false;
if (used[l][r])
return dp[l][r];
used[l][r] = true;
if (r - l == 2) {
return dp[l][r] = (abs(w[l] - w[r - 1]) <= 1);
}
for (int m = l + 1; m < r; m++) {
bool f = true;
f &= calc(l, m);
f &= calc(m, r);
dp[l][r] |= f;
}
if (abs(w[l] - w[r - 1]) <= 1)
dp[l][r] |= calc(l + 1, r - 1);
return dp[l][r];
}
int calc2(int l, int r) {
if (dp2[l][r] != -1)
return dp2[l][r];
if (r - l <= 1)
return dp2[l][r] = 0;
if (dp[l][r])
return dp2[l][r] = r - l;
int ret = 0;
for (int m = l + 1; m < r; m++) {
chmax(ret, calc2(l, m) + calc2(m, r));
}
return dp2[l][r] = ret;
}
int main() {
int n;
while (cin >> n && n) {
w.clear();
w.resize(n);
rep(i, n) cin >> w[i];
rep(i, 310) rep(j, 310) dp[i][j] = used[i][j] = false, dp2[i][j] = -1;
REP(r, 1, n + 1) rep(l, r) calc(l, r);
cout << calc2(0, n) << endl;
}
return 0;
} | replace | 61 | 62 | 61 | 62 | TLE | |
p01097 | C++ | Runtime Error | #include <bits/stdc++.h>
#define INF 1000000000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
int n, k, s;
vector<P> G[101];
bool flag[101];
int x[101], y[101], z[101];
int cnt = 0;
ll sum = 0;
bool check(int i, int j) {
if (x[i] + s <= x[j] || x[j] + s <= x[i])
return false;
if (y[i] + s <= y[j] || y[j] + s <= y[i])
return false;
if (z[i] + s <= z[j] || z[j] + s <= z[i])
return false;
return true;
}
void dfs(int v, int p) {
flag[v] = true;
for (int i = 0; i < G[v].size(); i++) {
if (G[v][i].first != p) {
if (flag[G[v][i].first])
sum -= (ll)G[v][i].second;
else {
if (cnt < k) {
sum += (ll)6 * s * s - G[v][i].second;
cnt++;
dfs(G[v][i].first, v);
}
}
}
}
}
int main(void) {
while (1) {
scanf("%d%d%d", &n, &k, &s);
if (n == 0 && k == 0 && s == 0)
return 0;
for (int i = 0; i < n; i++) {
G[i].clear();
scanf("%d%d%d", &x[i], &y[i], &z[i]);
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (check(i, j)) {
int v1 = s - abs(x[i] - x[j]);
int v2 = s - abs(y[i] - y[j]);
int v3 = s - abs(z[i] - z[j]);
ll cost = 2 * (v1 * v2 + v2 * v3 + v3 * v1);
G[i].push_back(P(j, cost));
G[j].push_back(P(i, cost));
}
}
}
ll res = INF;
for (int i = 0; i < n; i++) {
if (k == 1) {
res = min(res, (ll)6 * s * s);
continue;
}
for (int j = 0; j < G[i].size(); j++) {
memset(flag, false, sizeof(flag));
flag[i] = true;
flag[G[i][j].first] = true;
cnt = 2;
sum = 12 * s * s - G[i][j].second;
dfs(G[i][j].first, i);
if (cnt == k)
res = min(res, sum);
}
}
printf("%lld\n", res == INF ? -1 : res);
}
return 0;
} | #include <bits/stdc++.h>
#define INF 1000000000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
int n, k, s;
vector<P> G[2001];
bool flag[2001];
int x[2001], y[2001], z[2001];
int cnt = 0;
ll sum = 0;
bool check(int i, int j) {
if (x[i] + s <= x[j] || x[j] + s <= x[i])
return false;
if (y[i] + s <= y[j] || y[j] + s <= y[i])
return false;
if (z[i] + s <= z[j] || z[j] + s <= z[i])
return false;
return true;
}
void dfs(int v, int p) {
flag[v] = true;
for (int i = 0; i < G[v].size(); i++) {
if (G[v][i].first != p) {
if (flag[G[v][i].first])
sum -= (ll)G[v][i].second;
else {
if (cnt < k) {
sum += (ll)6 * s * s - G[v][i].second;
cnt++;
dfs(G[v][i].first, v);
}
}
}
}
}
int main(void) {
while (1) {
scanf("%d%d%d", &n, &k, &s);
if (n == 0 && k == 0 && s == 0)
return 0;
for (int i = 0; i < n; i++) {
G[i].clear();
scanf("%d%d%d", &x[i], &y[i], &z[i]);
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (check(i, j)) {
int v1 = s - abs(x[i] - x[j]);
int v2 = s - abs(y[i] - y[j]);
int v3 = s - abs(z[i] - z[j]);
ll cost = 2 * (v1 * v2 + v2 * v3 + v3 * v1);
G[i].push_back(P(j, cost));
G[j].push_back(P(i, cost));
}
}
}
ll res = INF;
for (int i = 0; i < n; i++) {
if (k == 1) {
res = min(res, (ll)6 * s * s);
continue;
}
for (int j = 0; j < G[i].size(); j++) {
memset(flag, false, sizeof(flag));
flag[i] = true;
flag[G[i][j].first] = true;
cnt = 2;
sum = 12 * s * s - G[i][j].second;
dfs(G[i][j].first, i);
if (cnt == k)
res = min(res, sum);
}
}
printf("%lld\n", res == INF ? -1 : res);
}
return 0;
} | replace | 8 | 11 | 8 | 11 | 0 | |
p01100 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
struct Dinic {
struct edge {
int to, cap, rev;
};
vector<vector<edge>> graph;
vector<int> min_cost, iter;
Dinic(int n) { graph.resize(n); }
void add_edge(int from, int to, int cap) {
graph[from].push_back((edge){to, cap, (int)graph[to].size()});
graph[to].push_back((edge){from, 0, (int)graph[from].size() - 1});
}
bool bfs(int s, int t) {
min_cost.assign(graph.size(), -1);
queue<int> que;
min_cost[s] = 0;
que.push(s);
while (!que.empty()) {
int p = que.front();
que.pop();
for (int i = 0; i < graph[p].size(); i++) {
const edge &e = graph[p][i];
if (e.cap > 0 && min_cost[e.to] == -1) {
min_cost[e.to] = min_cost[p] + 1;
que.push(e.to);
}
}
}
return (min_cost[t] != -1);
}
int dfs(int idx, const int t, int flow) {
if (idx == t)
return (flow);
for (int &i = iter[idx]; i < graph[idx].size(); i++) {
edge &e = graph[idx][i];
if (e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
int d = dfs(e.to, t, min(flow, e.cap));
if (d > 0) {
e.cap -= d;
graph[e.to][e.rev].cap += d;
return (d);
}
}
}
return (0);
}
int max_flow(int s, int t) {
int flow = 0;
while (bfs(s, t)) {
iter.assign(graph.size(), 0);
int f = 0;
while ((f = dfs(s, t, INF)) > 0) {
flow += f;
}
}
return (flow);
}
};
int N, M, U[100], V[10000];
bool check(int low, int high) {
Dinic flow(M + N + 4);
const int S = M + N, T = M + N + 1;
const int X = M + N + 2, Y = M + N + 3;
auto add_edge = [&](int x, int y, int l, int h) {
flow.add_edge(x, Y, l);
flow.add_edge(X, y, l);
flow.add_edge(x, y, h - l);
};
for (int i = 0; i < M; i++) {
add_edge(S, i, 1, 1);
add_edge(i, M + U[i], 0, 1);
add_edge(i, M + V[i], 0, 1);
}
for (int i = 0; i < N; i++) {
add_edge(M + i, T, low, high);
}
flow.max_flow(X, Y);
flow.max_flow(X, T);
flow.max_flow(S, Y);
flow.max_flow(S, T);
for (auto &p : flow.graph[X])
if (p.cap > 0)
return (false);
for (auto &p : flow.graph[Y])
if (flow.graph[p.to][p.rev].cap > 0)
return (false);
return (true);
}
int main() {
while (cin >> N >> M, N) {
for (int i = 0; i < M; i++) {
cin >> U[i] >> V[i];
--U[i], --V[i];
}
int ret = 114514, high = 0;
int val = 114514;
for (int low = 0; low < N; low++) {
while (high < N && !check(low, high))
++high;
if (high == N)
break;
if (high - low < ret) {
ret = high - low;
val = low;
}
}
cout << val << " " << val + ret << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
struct Dinic {
struct edge {
int to, cap, rev;
};
vector<vector<edge>> graph;
vector<int> min_cost, iter;
Dinic(int n) { graph.resize(n); }
void add_edge(int from, int to, int cap) {
graph[from].push_back((edge){to, cap, (int)graph[to].size()});
graph[to].push_back((edge){from, 0, (int)graph[from].size() - 1});
}
bool bfs(int s, int t) {
min_cost.assign(graph.size(), -1);
queue<int> que;
min_cost[s] = 0;
que.push(s);
while (!que.empty()) {
int p = que.front();
que.pop();
for (int i = 0; i < graph[p].size(); i++) {
const edge &e = graph[p][i];
if (e.cap > 0 && min_cost[e.to] == -1) {
min_cost[e.to] = min_cost[p] + 1;
que.push(e.to);
}
}
}
return (min_cost[t] != -1);
}
int dfs(int idx, const int t, int flow) {
if (idx == t)
return (flow);
for (int &i = iter[idx]; i < graph[idx].size(); i++) {
edge &e = graph[idx][i];
if (e.cap > 0 && min_cost[idx] < min_cost[e.to]) {
int d = dfs(e.to, t, min(flow, e.cap));
if (d > 0) {
e.cap -= d;
graph[e.to][e.rev].cap += d;
return (d);
}
}
}
return (0);
}
int max_flow(int s, int t) {
int flow = 0;
while (bfs(s, t)) {
iter.assign(graph.size(), 0);
int f = 0;
while ((f = dfs(s, t, INF)) > 0) {
flow += f;
}
}
return (flow);
}
};
int N, M, U[10000], V[10000];
bool check(int low, int high) {
Dinic flow(M + N + 4);
const int S = M + N, T = M + N + 1;
const int X = M + N + 2, Y = M + N + 3;
auto add_edge = [&](int x, int y, int l, int h) {
flow.add_edge(x, Y, l);
flow.add_edge(X, y, l);
flow.add_edge(x, y, h - l);
};
for (int i = 0; i < M; i++) {
add_edge(S, i, 1, 1);
add_edge(i, M + U[i], 0, 1);
add_edge(i, M + V[i], 0, 1);
}
for (int i = 0; i < N; i++) {
add_edge(M + i, T, low, high);
}
flow.max_flow(X, Y);
flow.max_flow(X, T);
flow.max_flow(S, Y);
flow.max_flow(S, T);
for (auto &p : flow.graph[X])
if (p.cap > 0)
return (false);
for (auto &p : flow.graph[Y])
if (flow.graph[p.to][p.rev].cap > 0)
return (false);
return (true);
}
int main() {
while (cin >> N >> M, N) {
for (int i = 0; i < M; i++) {
cin >> U[i] >> V[i];
--U[i], --V[i];
}
int ret = 114514, high = 0;
int val = 114514;
for (int low = 0; low < N; low++) {
while (high < N && !check(low, high))
++high;
if (high == N)
break;
if (high - low < ret) {
ret = high - low;
val = low;
}
}
cout << val << " " << val + ret << endl;
}
} | replace | 70 | 71 | 70 | 71 | 0 | |
p01101 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
while (cin >> m >> n, n || m) {
vector<int> data(n);
for (int i = 0; i < n; i++) { // input
cin >> data[i];
}
int max = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int tmp = data[i] + data[j];
if (tmp <= m && tmp > max) {
max = tmp;
}
}
}
if (max == 0) { // output
cout << "NONE" << endl;
} else {
cout << max << endl;
}
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m, n || m) {
vector<int> data(n);
for (int i = 0; i < n; i++) { // input
cin >> data[i];
}
int max = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int tmp = data[i] + data[j];
if (tmp <= m && tmp > max) {
max = tmp;
}
}
}
if (max == 0) { // output
cout << "NONE" << endl;
} else {
cout << max << endl;
}
}
return 0;
}
| replace | 8 | 9 | 8 | 9 | TLE | |
p01101 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LL long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
//
int main() {
int N, M;
int A[1000];
while (1) {
int N, M;
cin >> N >> M;
if (N == 0 && M == 0) {
break;
}
FOR(i, 0, N) { cin >> A[i]; }
VE S;
FOR(i, 0, N) {
FOR(j, i + 1, N) { S.PB(A[i] + A[j]); }
}
sort(S.begin(), S.end());
int ans = 0, now = 0;
while (1) {
if (S[now] <= M) {
ans = S[now];
now++;
} else {
break;
}
}
if (now == 0) {
cout << "NONE" << endl;
} else {
cout << ans << endl;
}
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LL long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
//
int main() {
int N, M;
int A[1000];
while (1) {
int N, M;
cin >> N >> M;
if (N == 0 && M == 0) {
break;
}
FOR(i, 0, N) { cin >> A[i]; }
VE S;
FOR(i, 0, N) {
FOR(j, i + 1, N) { S.PB(A[i] + A[j]); }
}
sort(S.begin(), S.end());
int ans = 0, now = 0;
while (now < N * (N - 1) / 2) {
if (S[now] <= M) {
ans = S[now];
now++;
} else {
break;
}
}
if (now == 0) {
cout << "NONE" << endl;
} else {
cout << ans << endl;
}
}
return 0;
}
| replace | 41 | 42 | 41 | 42 | 0 | |
p01101 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, MAX = 0, SUM;
int a, size;
vector<int> v;
while (cin >> n >> m, n) {
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
}
for (int i = 0; i < v.size(); i++) {
for (int j = i + 1; j < v.size(); j++) {
SUM = v[i] + v[j];
if (SUM <= m) {
MAX = max(MAX, SUM);
// cout << MAX << endl;
}
}
}
if (MAX == 0) {
cout << "NONE" << endl;
} else {
cout << MAX << endl;
}
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m, MAX = 0, SUM;
int a, size;
vector<int> v;
while (cin >> n >> m, n) {
int MAX = 0, SUM, a, size;
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
}
for (int i = 0; i < v.size(); i++) {
for (int j = i + 1; j < v.size(); j++) {
SUM = v[i] + v[j];
if (SUM <= m) {
MAX = max(MAX, SUM);
// cout << MAX << endl;
}
}
}
if (MAX == 0) {
cout << "NONE" << endl;
} else {
cout << MAX << endl;
}
}
return 0;
}
| insert | 11 | 11 | 11 | 14 | TLE | |
p01101 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
using namespace std;
int main() {
int n, m;
while (cin >> n >> m, n + m) {
cin >> n >> m;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] + a[j] <= m)
ans = max(ans, a[i] + a[j]);
}
}
if (ans == 0)
cout << "NONE" << endl;
else
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
using namespace std;
int main() {
int n, m;
while (cin >> n >> m, n + m) {
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] + a[j] <= m)
ans = max(ans, a[i] + a[j]);
}
}
if (ans == 0)
cout << "NONE" << endl;
else
cout << ans << endl;
}
return 0;
} | delete | 18 | 19 | 18 | 18 | TLE | |
p01102 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S, T;
while (cin >> S, S != ".") {
cin >> T;
int beet = 0;
string latte, malta;
vector<string> oi, ushi;
for (int i = 0; i < S.size(); i++) {
if (beet % 2 == 0)
latte += S[i], oi.push_back("");
else
oi.back() += S[i];
if (S[i] == '\"')
++beet;
}
beet = 0;
for (int i = 0; i < T.size(); i++) {
if (beet % 2 == 0)
malta += T[i], ushi.push_back("");
else
ushi.back() += T[i];
if (T[i] == '\"')
++beet;
}
int incorrect = 0;
if (oi.size() != ushi.size())
incorrect = 114514;
for (int i = 0; i < oi.size(); i++)
incorrect += oi[i] != ushi[i];
if (latte != malta || incorrect >= 2) {
cout << "DIFFERENT" << endl;
} else if (S == T) {
cout << "IDENTICAL" << endl;
} else {
cout << "CLOSE" << endl;
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S, T;
while (cin >> S, S != ".") {
cin >> T;
int beet = 0;
string latte, malta;
vector<string> oi, ushi;
for (int i = 0; i < S.size(); i++) {
if (beet % 2 == 0)
latte += S[i], oi.push_back("");
else
oi.back() += S[i];
if (S[i] == '\"')
++beet;
}
beet = 0;
for (int i = 0; i < T.size(); i++) {
if (beet % 2 == 0)
malta += T[i], ushi.push_back("");
else
ushi.back() += T[i];
if (T[i] == '\"')
++beet;
}
int incorrect = 0;
if (oi.size() != ushi.size())
incorrect = 114514;
else
for (int i = 0; i < oi.size(); i++)
incorrect += oi[i] != ushi[i];
if (latte != malta || incorrect >= 2) {
cout << "DIFFERENT" << endl;
} else if (S == T) {
cout << "IDENTICAL" << endl;
} else {
cout << "CLOSE" << endl;
}
}
} | replace | 31 | 33 | 31 | 34 | 0 | |
p01102 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
while (1) {
string s1;
cin >> s1;
if (s1 == ".")
break;
string s2;
cin >> s2;
if (s1 == s2) {
cout << "IDENTICAL" << endl;
continue;
}
string t1 = s1;
string t2 = s2;
while (1) {
size_t d1b = t1.find('\"');
if (d1b == string::npos)
break;
t1.replace(d1b, 1, "@");
size_t d1e = t1.find('\"');
t1.replace(d1e, 1, "@");
size_t d2b = t2.find('\"');
if (d2b == string::npos)
break;
t2.replace(d2b, 1, "@");
size_t d2e = t2.find('\"');
t1.replace(d2e, 1, "@");
string u1 = s1;
u1.replace(d1b + 1, d1e - d1b - 1, "");
string u2 = s2;
u2.replace(d2b + 1, d2e - d2b - 1, "");
if (u1 == u2) {
t1 = u1;
t2 = u2;
break;
}
}
if (t1 == t2) {
cout << "CLOSE" << endl;
} else {
cout << "DIFFERENT" << endl;
}
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
while (1) {
string s1;
cin >> s1;
if (s1 == ".")
break;
string s2;
cin >> s2;
if (s1 == s2) {
cout << "IDENTICAL" << endl;
continue;
}
string t1 = s1;
string t2 = s2;
while (1) {
size_t d1b = t1.find('\"');
if (d1b == string::npos)
break;
t1.replace(d1b, 1, "@");
size_t d1e = t1.find('\"');
t1.replace(d1e, 1, "@");
size_t d2b = t2.find('\"');
if (d2b == string::npos)
break;
t2.replace(d2b, 1, "@");
size_t d2e = t2.find('\"');
t2.replace(d2e, 1, "@");
string u1 = s1;
u1.replace(d1b + 1, d1e - d1b - 1, "");
string u2 = s2;
u2.replace(d2b + 1, d2e - d2b - 1, "");
if (u1 == u2) {
t1 = u1;
t2 = u2;
break;
}
}
if (t1 == t2) {
cout << "CLOSE" << endl;
} else {
cout << "DIFFERENT" << endl;
}
}
return 0;
} | replace | 37 | 38 | 37 | 38 | 0 | |
p01102 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;
vector<string> split(const string &s, char c = ' ') {
vector<string> ret;
stringstream ss(s);
string t;
while (getline(ss, t, c)) {
ret.push_back(t);
}
return ret;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
while (1) {
string s, t;
cin >> s;
if (s == ".")
break;
cin >> t;
if (s == t) {
cout << "IDENTICAL" << endl;
continue;
}
char c = '"';
vector<string> ss = split(s, c);
vector<string> tt = split(t, c);
int cnt = 0;
if (ss.size() != tt.size())
cnt = INF;
rep(i, 0, ss.size()) {
if (i % 2 == 0) {
if (ss[i] != tt[i])
cnt = INF;
} else {
if (ss[i] != tt[i])
cnt++;
}
}
if (cnt <= 1) {
cout << "CLOSE" << endl;
} else {
cout << "DIFFERENT" << endl;
}
}
}
| #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;
vector<string> split(const string &s, char c = ' ') {
vector<string> ret;
stringstream ss(s);
string t;
while (getline(ss, t, c)) {
ret.push_back(t);
}
return ret;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
while (1) {
string s, t;
cin >> s;
if (s == ".")
break;
cin >> t;
if (s == t) {
cout << "IDENTICAL" << endl;
continue;
}
char c = '"';
vector<string> ss = split(s, c);
vector<string> tt = split(t, c);
int cnt = 0;
if (ss.size() != tt.size())
cnt = INF;
rep(i, 0, min(ss.size(), tt.size())) {
if (i % 2 == 0) {
if (ss[i] != tt[i])
cnt = INF;
} else {
if (ss[i] != tt[i])
cnt++;
}
}
if (cnt <= 1) {
cout << "CLOSE" << endl;
} else {
cout << "DIFFERENT" << endl;
}
}
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p01104 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)
const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;
template <typename T> void debug(vector<T> &vec) {
for (auto x : vec) {
cout << x << " ";
}
cout << endl;
return;
}
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> int getFormer(const vector<T> &vec, T x) {
return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}
template <typename T> int getLatter(const vector<T> &vec, T x) {
return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}
int n, m, b[510], dp[2][(1 << 25)];
string s[510];
bool odd[510];
void solve(int n, int m) {
FILL(b, 0);
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < m; j++) {
if (s[i][j] == '0')
continue;
b[i] |= (1 << j);
}
}
if (n <= 20) {
int ans = 0;
for (int S = 0; S < (1 << n); S++) {
FILL(odd, false);
int cnt = 0;
for (int i = 0; i < n; i++) {
if ((S >> i) & 1) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '0')
continue;
odd[j] = !odd[j];
}
cnt += 1;
}
}
if (accumulate(odd, odd + m, 0))
continue;
ans = max(ans, cnt);
}
cout << ans << endl;
} else {
FILL(dp, -1);
dp[0][0] = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
int now = i % 2;
for (int S = 0; S < (1 << m); S++) {
if (dp[now][S] == -1)
continue;
int next = S ^ b[i];
dp[now ^ 1][S] = max(dp[now ^ 1][S], dp[now][S]);
dp[now ^ 1][next] = max(dp[now ^ 1][next], dp[now][S] + 1);
if (next == 0)
ans = max(ans, dp[now ^ 1][next]);
if (S == 0)
ans = max(ans, dp[now ^ 1][S]);
}
for (int S = 0; S < (1 << m); S++) {
dp[now][S] = -1;
}
}
cout << ans << endl;
}
}
int main() {
int n, m;
while (cin >> n >> m && n) {
solve(n, m);
}
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)
const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;
template <typename T> void debug(vector<T> &vec) {
for (auto x : vec) {
cout << x << " ";
}
cout << endl;
return;
}
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> int getFormer(const vector<T> &vec, T x) {
return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}
template <typename T> int getLatter(const vector<T> &vec, T x) {
return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}
int n, m, b[510], dp[2][(1 << 23)];
string s[510];
bool odd[510];
void solve(int n, int m) {
FILL(b, 0);
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < m; j++) {
if (s[i][j] == '0')
continue;
b[i] |= (1 << j);
}
}
if (n <= 20) {
int ans = 0;
for (int S = 0; S < (1 << n); S++) {
FILL(odd, false);
int cnt = 0;
for (int i = 0; i < n; i++) {
if ((S >> i) & 1) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '0')
continue;
odd[j] = !odd[j];
}
cnt += 1;
}
}
if (accumulate(odd, odd + m, 0))
continue;
ans = max(ans, cnt);
}
cout << ans << endl;
} else {
FILL(dp, -1);
dp[0][0] = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
int now = i % 2;
for (int S = 0; S < (1 << m); S++) {
if (dp[now][S] == -1)
continue;
int next = S ^ b[i];
dp[now ^ 1][S] = max(dp[now ^ 1][S], dp[now][S]);
dp[now ^ 1][next] = max(dp[now ^ 1][next], dp[now][S] + 1);
if (next == 0)
ans = max(ans, dp[now ^ 1][next]);
if (S == 0)
ans = max(ans, dp[now ^ 1][S]);
}
for (int S = 0; S < (1 << m); S++) {
dp[now][S] = -1;
}
}
cout << ans << endl;
}
}
int main() {
int n, m;
while (cin >> n >> m && n) {
solve(n, m);
}
return 0;
}
| replace | 33 | 34 | 33 | 34 | MLE | |
p01104 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n, m;
int fie[501][501];
int dp[60][1 << 21];
int dp2[501][1 << 11];
int res = 0;
int used[501];
void dfs(int v, int c, int bit) {
if (v == n) {
for (int i = 0; i < m; i++) {
int cnt = 0;
for (int j = 0; j < n; j++) {
if (used[j] == 1) {
cnt += fie[j][i];
}
}
if (cnt % 2 == 1)
return;
}
res = max(res, c);
return;
}
used[v] = 0;
dfs(v + 1, c, 0);
used[v] = 1;
dfs(v + 1, c + 1, 0);
}
int main(void) {
while (1) {
scanf("%d%d", &n, &m);
if (n == 0 && m == 0)
break;
memset(fie, 0, sizeof(fie));
for (int i = 0; i < n; i++) {
string str;
cin >> str;
for (int j = 0; j < m; j++) {
if (str[j] == '1')
fie[i][j] = 1;
else
fie[i][j] = 0;
}
}
if (m <= 10) {
memset(dp2, -1, sizeof(dp2));
dp2[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++) {
if (dp2[i][j] < 0)
continue;
dp2[i + 1][j] = max(dp2[i + 1][j], dp2[i][j]);
int bit = j;
for (int k = 0; k < m; k++) {
if (fie[i][k] == 1) {
if (j >> k & 1) {
bit -= 1 << k;
} else {
bit += 1 << k;
}
}
}
dp2[i + 1][bit] = max(dp2[i + 1][bit], dp2[i][j] + 1);
}
}
printf("%d\n", dp2[n][0]);
} else if (m <= 20) {
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++) {
if (dp[i][j] < 0)
continue;
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
int bit = j;
for (int k = 0; k < m; k++) {
if (fie[i][k] == 1) {
if (j >> k & 1) {
bit -= 1 << k;
} else {
bit += 1 << k;
}
}
}
dp[i + 1][bit] = max(dp[i + 1][bit], dp[i][j] + 1);
}
}
printf("%d\n", dp[n][0]);
} else {
res = 0;
dfs(0, 0, 0);
printf("%d\n", res);
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n, m;
int fie[501][501];
int dp[51][1 << 20];
int dp2[501][1 << 11];
int res = 0;
int used[501];
void dfs(int v, int c, int bit) {
if (v == n) {
for (int i = 0; i < m; i++) {
int cnt = 0;
for (int j = 0; j < n; j++) {
if (used[j] == 1) {
cnt += fie[j][i];
}
}
if (cnt % 2 == 1)
return;
}
res = max(res, c);
return;
}
used[v] = 0;
dfs(v + 1, c, 0);
used[v] = 1;
dfs(v + 1, c + 1, 0);
}
int main(void) {
while (1) {
scanf("%d%d", &n, &m);
if (n == 0 && m == 0)
break;
memset(fie, 0, sizeof(fie));
for (int i = 0; i < n; i++) {
string str;
cin >> str;
for (int j = 0; j < m; j++) {
if (str[j] == '1')
fie[i][j] = 1;
else
fie[i][j] = 0;
}
}
if (m <= 10) {
memset(dp2, -1, sizeof(dp2));
dp2[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++) {
if (dp2[i][j] < 0)
continue;
dp2[i + 1][j] = max(dp2[i + 1][j], dp2[i][j]);
int bit = j;
for (int k = 0; k < m; k++) {
if (fie[i][k] == 1) {
if (j >> k & 1) {
bit -= 1 << k;
} else {
bit += 1 << k;
}
}
}
dp2[i + 1][bit] = max(dp2[i + 1][bit], dp2[i][j] + 1);
}
}
printf("%d\n", dp2[n][0]);
} else if (m <= 20) {
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++) {
if (dp[i][j] < 0)
continue;
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
int bit = j;
for (int k = 0; k < m; k++) {
if (fie[i][k] == 1) {
if (j >> k & 1) {
bit -= 1 << k;
} else {
bit += 1 << k;
}
}
}
dp[i + 1][bit] = max(dp[i + 1][bit], dp[i][j] + 1);
}
}
printf("%d\n", dp[n][0]);
} else {
res = 0;
dfs(0, 0, 0);
printf("%d\n", res);
}
}
return 0;
} | replace | 7 | 8 | 7 | 8 | MLE | |
p01104 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
for (;;) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0)
break;
vector<vector<bool>> bs;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
vector<bool> v;
for (int j = 0; j < m; j++) {
v.push_back(str[j] == '1');
}
bs.push_back(move(v));
}
if (n < m) { // recipie < stuff -> all possible combinations of recipes!
const int nn = 1 << n;
int mxc = 0;
for (int i = 0; i < nn; i++) {
vector<bool> ss(m, false);
int c = 0;
for (int j = 1, ii = 0; j < nn; j <<= 1, ii++) {
if (i & j) {
c++;
for (int k = 0; k < m; k++) {
ss[k] = ss[k] ^ bs[ii][k];
}
}
}
bool ng = false;
for (int k = 0; k < m; k++) {
if (ss[k]) {
ng = true;
break;
}
}
if (!ng) {
if (mxc < c)
mxc = c;
}
}
cout << mxc << endl;
} else { // recipie >= stuff -> all possible states of odd stuff
const int mm = 1 << m;
vector<int> ms;
for (int i = 0; i < n; i++) {
int msk = 0;
for (int j = 1, ii = 0; j < mm; j <<= 1, ii++) {
if (bs[i][ii])
msk |= j;
}
ms.push_back(msk);
}
vector<int> ss(mm, -1);
ss[0] = 0;
for (int i = 0; i < n; i++) { // using recipe i.
vector<int> tt(mm, -1);
for (int j = 0; j < mm; j++) {
if (ss[j] < 0)
continue;
if (tt[j] < ss[j])
tt[j] = ss[j];
int k = j ^ ms[i];
if (tt[k] < ss[j] + 1) {
tt[k] = ss[j] + 1;
}
}
ss = move(tt);
}
cout << ss[0] << endl;
}
}
return 0;
} | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
for (;;) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0)
break;
vector<vector<bool>> bs;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
vector<bool> v;
for (int j = 0; j < m; j++) {
v.push_back(str[j] == '1');
}
bs.push_back(move(v));
}
if (n <= 20) { // recipie < stuff -> all possible combinations of recipes!
const int nn = 1 << n;
int mxc = 0;
for (int i = 0; i < nn; i++) {
vector<bool> ss(m, false);
int c = 0;
for (int j = 1, ii = 0; j < nn; j <<= 1, ii++) {
if (i & j) {
c++;
for (int k = 0; k < m; k++) {
ss[k] = ss[k] ^ bs[ii][k];
}
}
}
bool ng = false;
for (int k = 0; k < m; k++) {
if (ss[k]) {
ng = true;
break;
}
}
if (!ng) {
if (mxc < c)
mxc = c;
}
}
cout << mxc << endl;
} else { // recipie >= stuff -> all possible states of odd stuff
const int mm = 1 << m;
vector<int> ms;
for (int i = 0; i < n; i++) {
int msk = 0;
for (int j = 1, ii = 0; j < mm; j <<= 1, ii++) {
if (bs[i][ii])
msk |= j;
}
ms.push_back(msk);
}
vector<int> ss(mm, -1);
ss[0] = 0;
for (int i = 0; i < n; i++) { // using recipe i.
vector<int> tt(mm, -1);
for (int j = 0; j < mm; j++) {
if (ss[j] < 0)
continue;
if (tt[j] < ss[j])
tt[j] = ss[j];
int k = j ^ ms[i];
if (tt[k] < ss[j] + 1) {
tt[k] = ss[j] + 1;
}
}
ss = move(tt);
}
cout << ss[0] << endl;
}
}
return 0;
} | replace | 20 | 21 | 20 | 21 | TLE | |
p01104 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)
const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;
template <typename T> void debug(vector<T> &vec) {
for (auto x : vec) {
cout << x << " ";
}
cout << endl;
return;
}
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> int getFormer(const vector<T> &vec, T x) {
return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}
template <typename T> int getLatter(const vector<T> &vec, T x) {
return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}
int n, m, b[510], dp[2][(1 << 25)];
string s[510];
bool odd[510];
void solve(int n, int m) {
FILL(b, 0);
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < m; j++) {
if (s[i][j] == '0')
continue;
b[i] |= (1 << j);
}
}
if (n <= 20) {
int ans = 0;
for (int S = 0; S < (1 << n); S++) {
FILL(odd, false);
int cnt = 0;
for (int i = 0; i < n; i++) {
if ((S >> i) & 1) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '0')
continue;
odd[j] = !odd[j];
}
cnt += 1;
}
}
if (accumulate(odd, odd + m, 0))
continue;
ans = max(ans, cnt);
}
cout << ans << endl;
} else {
FILL(dp, -1);
dp[0][0] = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
int now = i % 2;
for (int S = 0; S < (1 << m); S++) {
if (dp[now][S] == -1)
continue;
int next = S ^ b[i];
dp[now ^ 1][S] = max(dp[now ^ 1][S], dp[now][S]);
dp[now ^ 1][next] = max(dp[now ^ 1][next], dp[now][S] + 1);
if (next == 0)
ans = max(ans, dp[now ^ 1][next]);
if (S == 0)
ans = max(ans, dp[now ^ 1][S]);
}
for (int S = 0; S < (1 << m); S++) {
dp[now][S] = -1;
}
}
cout << ans << endl;
}
}
int main() {
int n, m;
while (cin >> n >> m && n) {
solve(n, m);
}
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)
const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;
template <typename T> void debug(vector<T> &vec) {
for (auto x : vec) {
cout << x << " ";
}
cout << endl;
return;
}
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> int getFormer(const vector<T> &vec, T x) {
return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}
template <typename T> int getLatter(const vector<T> &vec, T x) {
return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}
int n, m, b[510], dp[2][(1 << 23)];
string s[510];
bool odd[510];
void solve(int n, int m) {
FILL(b, 0);
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < m; j++) {
if (s[i][j] == '0')
continue;
b[i] |= (1 << j);
}
}
if (n <= 20) {
int ans = 0;
for (int S = 0; S < (1 << n); S++) {
FILL(odd, false);
int cnt = 0;
for (int i = 0; i < n; i++) {
if ((S >> i) & 1) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '0')
continue;
odd[j] = !odd[j];
}
cnt += 1;
}
}
if (accumulate(odd, odd + m, 0))
continue;
ans = max(ans, cnt);
}
cout << ans << endl;
} else {
FILL(dp, -1);
dp[0][0] = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
int now = i % 2;
for (int S = 0; S < (1 << m); S++) {
if (dp[now][S] == -1)
continue;
int next = S ^ b[i];
dp[now ^ 1][S] = max(dp[now ^ 1][S], dp[now][S]);
dp[now ^ 1][next] = max(dp[now ^ 1][next], dp[now][S] + 1);
if (next == 0)
ans = max(ans, dp[now ^ 1][next]);
if (S == 0)
ans = max(ans, dp[now ^ 1][S]);
}
for (int S = 0; S < (1 << m); S++) {
dp[now][S] = -1;
}
}
cout << ans << endl;
}
}
int main() {
int n, m;
while (cin >> n >> m && n) {
solve(n, m);
}
return 0;
}
| replace | 33 | 34 | 33 | 34 | MLE | |
p01104 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
for (int N, M;;) {
cin >> N >> M;
if (N == 0 and M == 0) {
break;
}
if (N <= 25) {
vector<vector<int>> b(N, vector<int>(M));
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
char c;
cin >> c, b[i][j] = c - '0';
}
}
const int MASK = 1 << N;
int ans = 0;
for (int mask = 0; mask < MASK; mask++) {
int cnt = 0;
vector<int> sum(M, 0);
for (int i = 0; i < N; i++) {
if (mask & (1 << i)) {
cnt++;
for (int j = 0; j < M; j++) {
sum[j] ^= b[i][j];
}
}
}
bool ok = true;
for (int i = 0; i < M; i++) {
if (sum[i] == 1) {
ok = false;
}
}
if (ok) {
ans = max(ans, cnt);
}
}
cout << ans << endl;
} else {
vector<int> b(N, 0);
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
char c;
cin >> c, b[i] |= (c - '0') << j;
}
}
const int MASK = 1 << M;
vector<int> dp(MASK, -1);
dp[0] = 0;
for (int i = 0; i < N; i++) {
auto tmp = dp;
for (int j = 0; j < MASK; j++) {
if (dp[j] == -1) {
continue;
}
tmp[j ^ b[i]] = max(tmp[j ^ b[i]], dp[j] + 1);
}
dp = tmp;
}
cout << dp[0] << endl;
}
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
for (int N, M;;) {
cin >> N >> M;
if (N == 0 and M == 0) {
break;
}
if (N <= 20) {
vector<vector<int>> b(N, vector<int>(M));
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
char c;
cin >> c, b[i][j] = c - '0';
}
}
const int MASK = 1 << N;
int ans = 0;
for (int mask = 0; mask < MASK; mask++) {
int cnt = 0;
vector<int> sum(M, 0);
for (int i = 0; i < N; i++) {
if (mask & (1 << i)) {
cnt++;
for (int j = 0; j < M; j++) {
sum[j] ^= b[i][j];
}
}
}
bool ok = true;
for (int i = 0; i < M; i++) {
if (sum[i] == 1) {
ok = false;
}
}
if (ok) {
ans = max(ans, cnt);
}
}
cout << ans << endl;
} else {
vector<int> b(N, 0);
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
char c;
cin >> c, b[i] |= (c - '0') << j;
}
}
const int MASK = 1 << M;
vector<int> dp(MASK, -1);
dp[0] = 0;
for (int i = 0; i < N; i++) {
auto tmp = dp;
for (int j = 0; j < MASK; j++) {
if (dp[j] == -1) {
continue;
}
tmp[j ^ b[i]] = max(tmp[j ^ b[i]], dp[j] + 1);
}
dp = tmp;
}
cout << dp[0] << endl;
}
}
return 0;
}
| replace | 8 | 9 | 8 | 9 | TLE | |
p01104 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i, m, n) for (int i = int(m); i < int(n); i++)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
// #define LOCAL 0
// #ifdef LOCAL
// #define DEBUG(s) cout << (s) << endl
// #define dump(x) cerr << #x << " = " << (x) << endl
// #define BR cout << endl;
// #else
// #define DEBUG(s) do{}while(0)
// #define dump(x) do{}while(0)
// #define BR
// #endif
// 改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 // デバッグする時1にしてね
#define dump(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
// ここから編集する
void solve(int n, int m) {
// vector<ll> b(n);
// rep(i, 0, n) {
// string s;
// cin >> s;
// ll tmp = 0;
// rep(j, 0, s.size()) {
// if (s[j] == '1')
// tmp += (1 << (m - j - 1));
// }
// b[i] = tmp;
// }
if (n < 25) {
// vector<int> b(m);
// rep(j, 0, m) {
// char tmp;
// cin >> tmp;
// b[j] = (tmp - '0');
// }
vector<vector<int>> b(n, vector<int>(m, 0));
rep(j, 0, n) {
rep(k, 0, m) {
char tmp;
cin >> tmp;
b[j][k] = (tmp - '0');
}
}
int ans = 0;
for (int i = 0; i < (1 << n); i++) {
// int xors = 0;
vector<int> flags(m, false);
int kouhoAns = 0;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
// xors ^= b[j];
kouhoAns++;
rep(k, 0, m) { flags[k] ^= b[j][k]; }
}
}
// if (xors == 0) {
// ans = max(kouhoAns, ans);
// }
if ([&] {
for (auto flag : flags) {
if (flag)
return false;
}
return true;
}()) {
ans = max(kouhoAns, ans);
}
}
cout << ans << endl;
} else {
vector<ll> b(n);
rep(i, 0, n) {
string s;
cin >> s;
ll tmp = 0;
rep(j, 0, s.size()) {
if (s[j] == '1')
tmp += (1 << (m - j - 1));
}
b[i] = tmp;
}
vector<vector<int>> dp(n + 1, vector<int>((1 << m), -INF));
// for(int i = 1; i <= n; i++){
//
// }
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < (1 << m); j++) {
// dp[i - 1][j ^ b[i]] + 1;
dp[i][j] = max(dp[i - 1][j ^ b[i - 1]] + 1, dp[i - 1][j]);
}
}
cout << dp[n][0] << endl;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int n, m;
cin >> n >> m;
if (n == 0)
break;
// cerr << "running case " << "n = "<< n << "m = " << m << endl;
solve(n, m);
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i, m, n) for (int i = int(m); i < int(n); i++)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
// #define LOCAL 0
// #ifdef LOCAL
// #define DEBUG(s) cout << (s) << endl
// #define dump(x) cerr << #x << " = " << (x) << endl
// #define BR cout << endl;
// #else
// #define DEBUG(s) do{}while(0)
// #define dump(x) do{}while(0)
// #define BR
// #endif
// 改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 // デバッグする時1にしてね
#define dump(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
// ここから編集する
void solve(int n, int m) {
// vector<ll> b(n);
// rep(i, 0, n) {
// string s;
// cin >> s;
// ll tmp = 0;
// rep(j, 0, s.size()) {
// if (s[j] == '1')
// tmp += (1 << (m - j - 1));
// }
// b[i] = tmp;
// }
if (n < 23) {
// vector<int> b(m);
// rep(j, 0, m) {
// char tmp;
// cin >> tmp;
// b[j] = (tmp - '0');
// }
vector<vector<int>> b(n, vector<int>(m, 0));
rep(j, 0, n) {
rep(k, 0, m) {
char tmp;
cin >> tmp;
b[j][k] = (tmp - '0');
}
}
int ans = 0;
for (int i = 0; i < (1 << n); i++) {
// int xors = 0;
vector<int> flags(m, false);
int kouhoAns = 0;
for (int j = 0; j < n; j++) {
if ((i >> j) & 1) {
// xors ^= b[j];
kouhoAns++;
rep(k, 0, m) { flags[k] ^= b[j][k]; }
}
}
// if (xors == 0) {
// ans = max(kouhoAns, ans);
// }
if ([&] {
for (auto flag : flags) {
if (flag)
return false;
}
return true;
}()) {
ans = max(kouhoAns, ans);
}
}
cout << ans << endl;
} else {
vector<ll> b(n);
rep(i, 0, n) {
string s;
cin >> s;
ll tmp = 0;
rep(j, 0, s.size()) {
if (s[j] == '1')
tmp += (1 << (m - j - 1));
}
b[i] = tmp;
}
vector<vector<int>> dp(n + 1, vector<int>((1 << m), -INF));
// for(int i = 1; i <= n; i++){
//
// }
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < (1 << m); j++) {
// dp[i - 1][j ^ b[i]] + 1;
dp[i][j] = max(dp[i - 1][j ^ b[i - 1]] + 1, dp[i - 1][j]);
}
}
cout << dp[n][0] << endl;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int n, m;
cin >> n >> m;
if (n == 0)
break;
// cerr << "running case " << "n = "<< n << "m = " << m << endl;
solve(n, m);
}
return 0;
}
| replace | 76 | 77 | 76 | 77 | TLE | |
p01104 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &o) {
out << "(" << o.first << "," << o.second << ")";
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> V) {
for (int i = 0; i < V.size(); i++) {
out << V[i];
if (i != V.size() - 1)
out << " ";
}
return out;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> Mat) {
for (int i = 0; i < Mat.size(); i++) {
if (i != 0)
out << endl;
out << Mat[i];
}
return out;
}
template <class S, class T>
ostream &operator<<(ostream &out, const map<S, T> mp) {
out << "{ ";
for (auto it = mp.begin(); it != mp.end(); it++) {
out << it->first << ":" << it->second;
if (mp.size() - 1 != distance(mp.begin(), it))
out << ", ";
}
out << " }";
return out;
}
/*
<url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1619&lang=jp>
問題文============================================================
=================================================================
解説=============================================================
================================================================
*/
ll n, m;
string b[505];
// n <= 20 , 25 <= m <= 500
bool ok[501];
// 25 <= n <= 500, m <= 20
int bit[501];
int dp[2][1 << 22];
int solve() {
int res = 0;
for (int i = 0; i < n; i++)
cin >> b[i];
if (n <= 20) { // n <= 20 , 25 <= m <= 500
for (int i = 0; i < (1 << n); i++) {
if (res >= __builtin_popcount(i))
continue;
fill(ok, ok + 501, false);
for (int j = 0; j < n; j++) { // n <= 20
if (!((i >> j) & 1))
continue;
for (int k = 0; k < m; k++) { // m <= 500
if (b[j][k] == '1')
ok[k] = !ok[k];
}
}
if (accumulate(ok, ok + m, 0))
continue;
res = max(res, __builtin_popcount(i));
}
} else { // 25 <= n <= 500, m <= 20
fill(bit, bit + n, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (b[i][j] == '1') {
bit[i] |= (1 << j);
}
}
}
for (int i = 0; i < 2; i++)
for (int j = 0; j < (1 << m); j++)
dp[i][j] = -1;
dp[0][0] = 0;
int cur = 0, next = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++) {
if (dp[cur][j] == -1)
continue;
dp[next][j] = max(dp[next][j], dp[cur][j]);
dp[next][j ^ bit[i]] = max(dp[next][j ^ bit[i]], dp[cur][j] + 1);
dp[cur][j] = -1;
}
swap(cur, next);
}
res = dp[cur][0];
}
return res;
}
int main(void) {
cin.tie(0);
ios_base::sync_with_stdio(false);
while (cin >> n >> m, n) {
cout << solve() << endl;
}
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &o) {
out << "(" << o.first << "," << o.second << ")";
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> V) {
for (int i = 0; i < V.size(); i++) {
out << V[i];
if (i != V.size() - 1)
out << " ";
}
return out;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> Mat) {
for (int i = 0; i < Mat.size(); i++) {
if (i != 0)
out << endl;
out << Mat[i];
}
return out;
}
template <class S, class T>
ostream &operator<<(ostream &out, const map<S, T> mp) {
out << "{ ";
for (auto it = mp.begin(); it != mp.end(); it++) {
out << it->first << ":" << it->second;
if (mp.size() - 1 != distance(mp.begin(), it))
out << ", ";
}
out << " }";
return out;
}
/*
<url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1619&lang=jp>
問題文============================================================
=================================================================
解説=============================================================
================================================================
*/
ll n, m;
string b[505];
// n <= 20 , 25 <= m <= 500
bool ok[501];
// 25 <= n <= 500, m <= 20
int bit[501];
int dp[2][1 << 22];
int solve() {
int res = 0;
for (int i = 0; i < n; i++)
cin >> b[i];
if (n <= m) { // n <= 20 , 25 <= m <= 500
for (int i = 0; i < (1 << n); i++) {
if (res >= __builtin_popcount(i))
continue;
fill(ok, ok + 501, false);
for (int j = 0; j < n; j++) { // n <= 20
if (!((i >> j) & 1))
continue;
for (int k = 0; k < m; k++) { // m <= 500
if (b[j][k] == '1')
ok[k] = !ok[k];
}
}
if (accumulate(ok, ok + m, 0))
continue;
res = max(res, __builtin_popcount(i));
}
} else { // 25 <= n <= 500, m <= 20
fill(bit, bit + n, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (b[i][j] == '1') {
bit[i] |= (1 << j);
}
}
}
for (int i = 0; i < 2; i++)
for (int j = 0; j < (1 << m); j++)
dp[i][j] = -1;
dp[0][0] = 0;
int cur = 0, next = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++) {
if (dp[cur][j] == -1)
continue;
dp[next][j] = max(dp[next][j], dp[cur][j]);
dp[next][j ^ bit[i]] = max(dp[next][j ^ bit[i]], dp[cur][j] + 1);
dp[cur][j] = -1;
}
swap(cur, next);
}
res = dp[cur][0];
}
return res;
}
int main(void) {
cin.tie(0);
ios_base::sync_with_stdio(false);
while (cin >> n >> m, n) {
cout << solve() << endl;
}
return 0;
}
| replace | 65 | 66 | 65 | 66 | 0 | |
p01104 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &o) {
out << "(" << o.first << "," << o.second << ")";
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> V) {
for (int i = 0; i < V.size(); i++) {
out << V[i];
if (i != V.size() - 1)
out << " ";
}
return out;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> Mat) {
for (int i = 0; i < Mat.size(); i++) {
if (i != 0)
out << endl;
out << Mat[i];
}
return out;
}
template <class S, class T>
ostream &operator<<(ostream &out, const map<S, T> mp) {
out << "{ ";
for (auto it = mp.begin(); it != mp.end(); it++) {
out << it->first << ":" << it->second;
if (mp.size() - 1 != distance(mp.begin(), it))
out << ", ";
}
out << " }";
return out;
}
/*
<url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1619&lang=jp>
問題文============================================================
=================================================================
解説=============================================================
================================================================
*/
ll n, m;
string b[505];
// n <= 20 , 25 <= m <= 500
bool ok[501];
// 25 <= n <= 500, m <= 20
int bit[501];
int dp[2][1 << 22];
int solve() {
int res = 0;
for (int i = 0; i < n; i++)
cin >> b[i];
if (n <= 20) { // n <= 20 , 25 <= m <= 500
for (int i = 0; i < (1 << n); i++) {
if (res >= __builtin_popcount(i))
continue;
fill(ok, ok + 501, false);
for (int j = 0; j < n; j++) { // n <= 20
if (!((i >> j) & 1))
continue;
for (int k = 0; k < m; k++) { // m <= 500
if (b[j][k] == '1')
ok[k] = !ok[k];
}
}
if (accumulate(ok, ok + m, 0))
continue;
res = max(res, __builtin_popcount(i));
}
} else { // 25 <= n <= 500, m <= 20
fill(bit, bit + n, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (b[i][j] == '1') {
bit[i] |= (1 << j);
}
}
}
for (int i = 0; i < 2; i++)
for (int j = 0; j < (1 << m); j++)
dp[i][j] = -1;
dp[0][0] = 0;
int cur = 0, next = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++) {
if (dp[cur][j] == -1)
continue;
dp[next][j] = max(dp[next][j], dp[cur][j]);
dp[next][j ^ bit[i]] = max(dp[next][j ^ bit[i]], dp[cur][j] + 1);
dp[cur][j] = -1;
}
swap(cur, next);
}
res = dp[cur][0];
}
return res;
}
int main(void) {
cin.tie(0);
ios_base::sync_with_stdio(false);
while (cin >> n >> m, n) {
cout << solve() << endl;
}
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &o) {
out << "(" << o.first << "," << o.second << ")";
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> V) {
for (int i = 0; i < V.size(); i++) {
out << V[i];
if (i != V.size() - 1)
out << " ";
}
return out;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> Mat) {
for (int i = 0; i < Mat.size(); i++) {
if (i != 0)
out << endl;
out << Mat[i];
}
return out;
}
template <class S, class T>
ostream &operator<<(ostream &out, const map<S, T> mp) {
out << "{ ";
for (auto it = mp.begin(); it != mp.end(); it++) {
out << it->first << ":" << it->second;
if (mp.size() - 1 != distance(mp.begin(), it))
out << ", ";
}
out << " }";
return out;
}
/*
<url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1619&lang=jp>
問題文============================================================
=================================================================
解説=============================================================
================================================================
*/
ll n, m;
string b[505];
// n <= 20 , 25 <= m <= 500
bool ok[501];
// 25 <= n <= 500, m <= 20
int bit[501];
int dp[2][1 << 22];
int solve() {
int res = 0;
for (int i = 0; i < n; i++)
cin >> b[i];
if (n <= m) { // n <= 20 , 25 <= m <= 500
for (int i = 0; i < (1 << n); i++) {
if (res >= __builtin_popcount(i))
continue;
fill(ok, ok + 501, false);
for (int j = 0; j < n; j++) { // n <= 20
if (!((i >> j) & 1))
continue;
for (int k = 0; k < m; k++) { // m <= 500
if (b[j][k] == '1')
ok[k] = !ok[k];
}
}
if (accumulate(ok, ok + m, 0))
continue;
res = max(res, __builtin_popcount(i));
}
} else { // 25 <= n <= 500, m <= 20
fill(bit, bit + n, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (b[i][j] == '1') {
bit[i] |= (1 << j);
}
}
}
for (int i = 0; i < 2; i++)
for (int j = 0; j < (1 << m); j++)
dp[i][j] = -1;
dp[0][0] = 0;
int cur = 0, next = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < (1 << m); j++) {
if (dp[cur][j] == -1)
continue;
dp[next][j] = max(dp[next][j], dp[cur][j]);
dp[next][j ^ bit[i]] = max(dp[next][j ^ bit[i]], dp[cur][j] + 1);
dp[cur][j] = -1;
}
swap(cur, next);
}
res = dp[cur][0];
}
return res;
}
int main(void) {
cin.tie(0);
ios_base::sync_with_stdio(false);
while (cin >> n >> m, n) {
cout << solve() << endl;
}
return 0;
}
| replace | 65 | 66 | 65 | 66 | 0 | |
p01104 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using Int = int64_t;
const Int inf = 1LL << 53;
int main() {
for (;;) {
Int n, m;
std::cin >> n >> m;
if (n == 0 && m == 0) {
break;
}
auto xss = std::vector<std::string>(n);
for (Int i = 0; i < n; ++i) {
std::string ss;
std::cin >> ss;
xss[i] = ss;
}
if (n <= 23) {
Int res = 0;
for (Int i = 0; i < (1 << n); ++i) {
std::string ss(m, '0');
Int num = 0;
for (Int k = 0; k < n; ++k) {
if ((i & (1 << k)) != 0) {
num += 1;
for (Int j = 0; j < m; ++j) {
ss[j] = ss[j] == xss[k][j] ? '0' : '1';
}
}
}
bool valid = true;
for (Int j = 0; j < m; ++j) {
if (ss[j] != '0') {
valid = false;
}
}
if (valid) {
res = std::max(res, num);
}
}
std::cout << res << std::endl;
} else {
auto ys = std::vector<Int>(n);
for (Int i = 0; i < n; ++i) {
Int t = 0;
for (Int k = 0; k < m; ++k) {
if (xss[i][k] == '1') {
t |= 1 << k;
}
}
ys[i] = t;
}
std::vector<Int> dp(1 << m, -inf);
std::vector<Int> dp2(1 << m, -inf);
dp[0] = 0;
for (Int i = 0; i < n; ++i) {
for (Int k = 0; k < 1 << m; ++k) {
dp2[k] = std::max(dp[k], dp[k ^ ys[i]] + 1);
}
std::swap(dp, dp2);
}
std::cout << dp[0] << std::endl;
}
}
}
| #include <bits/stdc++.h>
using Int = int64_t;
const Int inf = 1LL << 53;
int main() {
for (;;) {
Int n, m;
std::cin >> n >> m;
if (n == 0 && m == 0) {
break;
}
auto xss = std::vector<std::string>(n);
for (Int i = 0; i < n; ++i) {
std::string ss;
std::cin >> ss;
xss[i] = ss;
}
if (n <= 20) {
Int res = 0;
for (Int i = 0; i < (1 << n); ++i) {
std::string ss(m, '0');
Int num = 0;
for (Int k = 0; k < n; ++k) {
if ((i & (1 << k)) != 0) {
num += 1;
for (Int j = 0; j < m; ++j) {
ss[j] = ss[j] == xss[k][j] ? '0' : '1';
}
}
}
bool valid = true;
for (Int j = 0; j < m; ++j) {
if (ss[j] != '0') {
valid = false;
}
}
if (valid) {
res = std::max(res, num);
}
}
std::cout << res << std::endl;
} else {
auto ys = std::vector<Int>(n);
for (Int i = 0; i < n; ++i) {
Int t = 0;
for (Int k = 0; k < m; ++k) {
if (xss[i][k] == '1') {
t |= 1 << k;
}
}
ys[i] = t;
}
std::vector<Int> dp(1 << m, -inf);
std::vector<Int> dp2(1 << m, -inf);
dp[0] = 0;
for (Int i = 0; i < n; ++i) {
for (Int k = 0; k < 1 << m; ++k) {
dp2[k] = std::max(dp[k], dp[k ^ ys[i]] + 1);
}
std::swap(dp, dp2);
}
std::cout << dp[0] << std::endl;
}
}
}
| replace | 17 | 18 | 17 | 18 | TLE | |
p01105 | C++ | Runtime Error | #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
/* 再帰降下法 */
// char *p = str; res = expr(p);
int val = 0;
int term(char *&s);
int number(char *&s);
int factor(char *&s);
int expr(char *&s);
// 数
int number(char *&s) {
int res = 0;
if (*s == '0' || *s == '1')
return (*s++) - '0';
if ('a' <= *s && *s <= 'd')
return (val >> ((*s++) - 'a')) % 2;
return res;
}
// 乗算除算(優先順位:高)
int term(char *&s) {
int res = factor(s);
while (1) {
if (*s == '^')
res ^= factor(++s);
else if (*s == '*')
res *= factor(++s);
else
break;
}
return res;
}
// 括弧か数
int factor(char *&s) {
if (*s == '-')
return !factor(++s);
if (*s != '(')
return number(s);
int res = expr(++s);
s++;
return res;
}
// 式(優先順位: 低)
int expr(char *&s) {
int res = term(s);
return res;
}
int check(char *s) {
int res = 0;
for (int i = 0; i < 16; i++) {
char *p = s;
val = i;
res = res * 2 + expr(p);
}
return res;
}
vector<string> vec[16];
int par = 0;
void make_expr() {
string s = ".";
for (int i = 0; i < 6; i++) {
s[0] = "01abcd"[i];
vec[1].push_back(s);
}
for (int i = 2; i <= 15; i++) {
for (int j = 0; j < vec[i - 1].size(); j++) {
vec[i].push_back("-" + vec[i - 1][j]);
}
for (int j = 1; j < i - 3; j++) {
int r = i - 3 - j;
if (j > r)
continue;
for (int p = 0; p < vec[j].size(); p++) {
for (int q = 0; q < vec[r].size(); q++) {
vec[i].push_back("(" + vec[j][p] + "*" + vec[r][q] + ")");
vec[i].push_back("(" + vec[j][p] + "^" + vec[r][q] + ")");
assert(j + r + 3 == i);
}
}
}
sort(vec[i].begin(), vec[i].end());
vec[i].erase(unique(vec[i].begin(), vec[i].end()), vec[i].end());
debug(vec[i].size());
}
}
bool solve() {
char s[30];
scanf("%s", s);
if (s[0] == '.')
return 0;
int res = check(s);
for (int i = 1; i <= 15; i++) {
for (int j = 0; j < vec[i].size(); j++) {
char s[17];
strcpy(s, vec[i][j].c_str());
if (res == check(s)) {
printf("%d\n", i);
return 1;
}
}
}
printf("%d\n", 16);
return 1;
}
int main() {
make_expr();
while (solve())
;
return 0;
}
| #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
/* 再帰降下法 */
// char *p = str; res = expr(p);
int val = 0;
int term(char *&s);
int number(char *&s);
int factor(char *&s);
int expr(char *&s);
// 数
int number(char *&s) {
int res = 0;
if (*s == '0' || *s == '1')
return (*s++) - '0';
if ('a' <= *s && *s <= 'd')
return (val >> ((*s++) - 'a')) % 2;
return res;
}
// 乗算除算(優先順位:高)
int term(char *&s) {
int res = factor(s);
while (1) {
if (*s == '^')
res ^= factor(++s);
else if (*s == '*')
res *= factor(++s);
else
break;
}
return res;
}
// 括弧か数
int factor(char *&s) {
if (*s == '-')
return !factor(++s);
if (*s != '(')
return number(s);
int res = expr(++s);
s++;
return res;
}
// 式(優先順位: 低)
int expr(char *&s) {
int res = term(s);
return res;
}
int check(char *s) {
int res = 0;
for (int i = 0; i < 16; i++) {
char *p = s;
val = i;
res = res * 2 + expr(p);
}
return res;
}
vector<string> vec[16];
int par = 0;
void make_expr() {
string s = ".";
for (int i = 0; i < 6; i++) {
s[0] = "01abcd"[i];
vec[1].push_back(s);
}
for (int i = 2; i <= 15; i++) {
for (int j = 0; j < vec[i - 1].size(); j++) {
vec[i].push_back("-" + vec[i - 1][j]);
}
for (int j = 1; j < i - 3; j++) {
int r = i - 3 - j;
if (j > r)
continue;
for (int p = 0; p < vec[j].size(); p++) {
for (int q = 0; q < vec[r].size(); q++) {
vec[i].push_back("(" + vec[j][p] + "*" + vec[r][q] + ")");
vec[i].push_back("(" + vec[j][p] + "^" + vec[r][q] + ")");
assert(j + r + 3 == i);
}
}
}
sort(vec[i].begin(), vec[i].end());
vec[i].erase(unique(vec[i].begin(), vec[i].end()), vec[i].end());
// debug(vec[i].size());
}
}
bool solve() {
char s[30];
scanf("%s", s);
if (s[0] == '.')
return 0;
int res = check(s);
for (int i = 1; i <= 15; i++) {
for (int j = 0; j < vec[i].size(); j++) {
char s[17];
strcpy(s, vec[i][j].c_str());
if (res == check(s)) {
printf("%d\n", i);
return 1;
}
}
}
printf("%d\n", 16);
return 1;
}
int main() {
make_expr();
while (solve())
;
return 0;
}
| replace | 125 | 126 | 125 | 126 | 0 | 117 : vec[i].size() = 6
117 : vec[i].size() = 6
117 : vec[i].size() = 6
117 : vec[i].size() = 78
117 : vec[i].size() = 150
117 : vec[i].size() = 294
117 : vec[i].size() = 438
117 : vec[i].size() = 1518
117 : vec[i].size() = 4326
117 : vec[i].size() = 10662
117 : vec[i].size() = 22182
117 : vec[i].size() = 63150
117 : vec[i].size() = 165462
117 : vec[i].size() = 459654
|
p01105 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
int parse(string &s, int &p) {
if (s[p] == '(') {
p++;
int x = parse(s, p);
char op = s[p++];
int y = parse(s, p);
p++;
if (op == '^') {
return x ^ y;
} else {
return x & y;
}
} else if (s[p] == '-') {
p++;
int x = parse(s, p);
return ~x & 65535;
} else {
p++;
if (s[p - 1] == '0')
return 0x0000;
if (s[p - 1] == '1')
return 0xffff;
if (s[p - 1] == 'a')
return 0xaaaa;
if (s[p - 1] == 'b')
return 0xcccc;
if (s[p - 1] == 'c')
return 0xf0f0;
return 0xff00;
}
}
int dp[125252];
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
vpi uni;
void dfs2(vpi v) {
if (v.size() == 1) {
int m = v[0].first;
dp[m] = min(dp[m], v[0].second);
dp[~m & 65535] = min(dp[~m & 65535], v[0].second + 1);
} else {
REP(q, 4) {
REP(i, v.size() - 1) {
vpi w;
REP(j, v.size()) if (i == j) {
pii a = v[j];
pii b = v[j + 1];
j++;
pii c;
if (q % 2 == 0) {
c = pii(a.first & b.first, a.second + b.second + 3);
} else {
c = pii(a.first ^ b.first, a.second + b.second + 3);
}
if (q >= 2) {
c = pii(~c.first & 65535, c.second + 1);
}
w.push_back(c);
}
else {
w.push_back(v[j]);
}
dfs2(w);
}
}
}
}
void dfs(int k, vpi v) {
if (k == 0) {
dfs2(v);
return;
}
for (pii P : uni) {
vpi w = v;
w.push_back(P);
dfs(k - 1, w);
}
}
int main() {
uni.push_back(pii(0x0000, 1));
uni.push_back(pii(0xffff, 1));
uni.push_back(pii(0xaaaa, 1));
uni.push_back(pii(0xcccc, 1));
uni.push_back(pii(0xf0f0, 1));
uni.push_back(pii(0xff00, 1));
uni.push_back(pii(~0xaaaa & 65535, 2));
uni.push_back(pii(~0xcccc & 65535, 2));
uni.push_back(pii(~0xf0f0 & 65535, 2));
uni.push_back(pii(~0xff00 & 65535, 2));
REP(i, 125252) dp[i] = 83025;
REP(i, 10) { dp[uni[i].first] = uni[i].second; }
REP(k, 5) if (k >= 2) {
dfs(k, vpi(0));
cerr << k << endl;
}
while (true) {
string s;
cin >> s;
if (s[0] == '.')
break;
int p = 0;
int msk = parse(s, p);
if (false) {
int tmp = msk;
REP(_, 4) {
cout << (tmp % 16) << " ";
tmp /= 16;
}
cout << endl;
}
int ans = s.size();
ans = min(ans, dp[msk]);
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
int parse(string &s, int &p) {
if (s[p] == '(') {
p++;
int x = parse(s, p);
char op = s[p++];
int y = parse(s, p);
p++;
if (op == '^') {
return x ^ y;
} else {
return x & y;
}
} else if (s[p] == '-') {
p++;
int x = parse(s, p);
return ~x & 65535;
} else {
p++;
if (s[p - 1] == '0')
return 0x0000;
if (s[p - 1] == '1')
return 0xffff;
if (s[p - 1] == 'a')
return 0xaaaa;
if (s[p - 1] == 'b')
return 0xcccc;
if (s[p - 1] == 'c')
return 0xf0f0;
return 0xff00;
}
}
int dp[125252];
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
vpi uni;
void dfs2(vpi v) {
if (v.size() == 1) {
int m = v[0].first;
dp[m] = min(dp[m], v[0].second);
dp[~m & 65535] = min(dp[~m & 65535], v[0].second + 1);
} else {
REP(q, 4) {
REP(i, v.size() - 1) {
vpi w;
REP(j, v.size()) if (i == j) {
pii a = v[j];
pii b = v[j + 1];
j++;
pii c;
if (q % 2 == 0) {
c = pii(a.first & b.first, a.second + b.second + 3);
} else {
c = pii(a.first ^ b.first, a.second + b.second + 3);
}
if (q >= 2) {
c = pii(~c.first & 65535, c.second + 1);
}
w.push_back(c);
}
else {
w.push_back(v[j]);
}
dfs2(w);
}
}
}
}
void dfs(int k, vpi v) {
if (k == 0) {
dfs2(v);
return;
}
for (pii P : uni) {
vpi w = v;
w.push_back(P);
dfs(k - 1, w);
}
}
int main() {
uni.push_back(pii(0x0000, 1));
uni.push_back(pii(0xffff, 1));
uni.push_back(pii(0xaaaa, 1));
uni.push_back(pii(0xcccc, 1));
uni.push_back(pii(0xf0f0, 1));
uni.push_back(pii(0xff00, 1));
uni.push_back(pii(~0xaaaa & 65535, 2));
uni.push_back(pii(~0xcccc & 65535, 2));
uni.push_back(pii(~0xf0f0 & 65535, 2));
uni.push_back(pii(~0xff00 & 65535, 2));
REP(i, 125252) dp[i] = 83025;
REP(i, 10) { dp[uni[i].first] = uni[i].second; }
REP(k, 5) if (k >= 2) {
dfs(k, vpi(0));
// cerr << k << endl;
}
while (true) {
string s;
cin >> s;
if (s[0] == '.')
break;
int p = 0;
int msk = parse(s, p);
if (false) {
int tmp = msk;
REP(_, 4) {
cout << (tmp % 16) << " ";
tmp /= 16;
}
cout << endl;
}
int ans = s.size();
ans = min(ans, dp[msk]);
cout << ans << endl;
}
return 0;
} | replace | 107 | 108 | 107 | 108 | TLE | |
p01108 | C++ | Time Limit Exceeded | #include <iostream>
#include <math.h>
#define eps 1e-9
using namespace std;
struct vec2d {
double x, y;
vec2d() {}
vec2d(double x, double y) { this->x = x, this->y = y; }
double add(double a, double b) {
if (fabs(a + b) < eps * (fabs(a) + fabs(b)))
return 0.0;
return a + b;
}
vec2d operator+(vec2d ope) { return vec2d(add(x, ope.x), add(y, ope.y)); }
vec2d operator-(vec2d ope) { return vec2d(add(x, -ope.x), add(y, -ope.y)); }
vec2d operator*(double t) { return vec2d(x * t, y * t); }
vec2d operator/(double t) { return vec2d(x / t, y / t); }
double dot(vec2d ope) { return add(x * ope.x, y * ope.y); }
double cross(vec2d ope) { return add(x * ope.y, -y * ope.x); }
double norm() {
double d2 = dot(*this);
if (d2 > 0)
return sqrt(d2);
return 0.0;
}
};
double distPP(vec2d p, vec2d q) { return (p - q).norm(); }
bool isOnL(vec2d p, vec2d q, vec2d x) { return (p - x).cross(q - x) == 0; }
bool valid;
vec2d getCrossP(vec2d p, vec2d q, vec2d r, vec2d s) {
if ((q - p).cross(s - r) == 0) {
valid = false;
return vec2d();
}
valid = true;
double t = (r - p).cross(s - r) / (q - p).cross(s - r);
return p + (q - p) * t;
}
bool isSamePP(vec2d p, vec2d q) { return (distPP(p, q) < eps); }
vec2d p[3], q[3];
int dfs(vec2d p[], int cnt) {
/*cout << cnt << " ";
for(int i = 0; i < 3; i++){
cout << "(" << p[i].x << ", " << p[i].y << ")";
}
cout << endl;*/
bool matchP[3], matchQ[3];
for (int i = 0; i < 3; i++)
matchP[i] = matchQ[i] = false;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (matchQ[j])
continue;
if (isSamePP(p[i], q[j])) {
matchP[i] = matchQ[j] = true;
break;
}
}
}
bool same = true;
for (int i = 0; i < 3; i++)
same &= matchP[i];
if (same)
return 0;
if (cnt >= 4)
return 5;
int ret = 5;
vec2d np[3];
for (int i = 0; i < 3; i++)
np[i] = p[i];
for (int i = 0; i < 3; i++) {
if (matchP[i])
continue;
for (int j = 0; j < 3; j++) {
if (matchQ[j])
continue;
// cout << i << " " << j << endl;
if (isOnL(p[i], p[i] + (p[(i + 1) % 3] - p[(i + 2) % 3]), q[j])) {
np[i] = q[j];
ret = min(ret, dfs(np, cnt + 1) + 1);
np[i] = p[i];
} else {
if (!matchP[(i + 1) % 3]) {
np[(i + 1) % 3] = getCrossP(
p[(i + 2) % 3], p[(i + 2) % 3] + (q[j] - p[i]) * 1e5,
p[(i + 1) % 3], p[(i + 1) % 3] + (p[i] - p[(i + 2) % 3]) * 1e5);
if (valid)
ret = min(ret, dfs(np, cnt + 1) + 1);
np[(i + 1) % 3] = p[(i + 1) % 3];
}
if (!matchP[(i + 2) % 3]) {
np[(i + 2) % 3] = getCrossP(
p[(i + 1) % 3], p[(i + 1) % 3] + (q[j] - p[i]) * 1e5,
p[(i + 2) % 3], p[(i + 2) % 3] + (p[i] - p[(i + 1) % 3]) * 1e5);
if (valid)
ret = min(ret, dfs(np, cnt + 1) + 1);
np[(i + 2) % 3] = p[(i + 2) % 3];
}
}
}
}
return ret;
}
int main(void) {
while (cin >> p[0].x) {
for (int i = 0; i < 3; i++) {
if (i != 0)
cin >> p[i].x;
cin >> p[i].y;
}
for (int i = 0; i < 3; i++) {
cin >> q[i].x >> q[i].y;
}
int ans = dfs(p, 0);
if (ans >= 5)
cout << "Many" << endl;
else
cout << ans << endl;
}
return 0;
}
| #include <iostream>
#include <math.h>
#define eps 1e-9
using namespace std;
struct vec2d {
double x, y;
vec2d() {}
vec2d(double x, double y) { this->x = x, this->y = y; }
double add(double a, double b) {
if (fabs(a + b) < eps * (fabs(a) + fabs(b)))
return 0.0;
return a + b;
}
vec2d operator+(vec2d ope) { return vec2d(add(x, ope.x), add(y, ope.y)); }
vec2d operator-(vec2d ope) { return vec2d(add(x, -ope.x), add(y, -ope.y)); }
vec2d operator*(double t) { return vec2d(x * t, y * t); }
vec2d operator/(double t) { return vec2d(x / t, y / t); }
double dot(vec2d ope) { return add(x * ope.x, y * ope.y); }
double cross(vec2d ope) { return add(x * ope.y, -y * ope.x); }
double norm() {
double d2 = dot(*this);
if (d2 > 0)
return sqrt(d2);
return 0.0;
}
};
double distPP(vec2d p, vec2d q) { return (p - q).norm(); }
bool isOnL(vec2d p, vec2d q, vec2d x) { return (p - x).cross(q - x) == 0; }
bool valid;
vec2d getCrossP(vec2d p, vec2d q, vec2d r, vec2d s) {
if ((q - p).cross(s - r) == 0) {
valid = false;
return vec2d();
}
valid = true;
double t = (r - p).cross(s - r) / (q - p).cross(s - r);
return p + (q - p) * t;
}
bool isSamePP(vec2d p, vec2d q) { return (distPP(p, q) < eps); }
vec2d p[3], q[3];
int dfs(vec2d p[], int cnt) {
/*cout << cnt << " ";
for(int i = 0; i < 3; i++){
cout << "(" << p[i].x << ", " << p[i].y << ")";
}
cout << endl;*/
bool matchP[3], matchQ[3];
for (int i = 0; i < 3; i++)
matchP[i] = matchQ[i] = false;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (matchQ[j])
continue;
if (isSamePP(p[i], q[j])) {
matchP[i] = matchQ[j] = true;
break;
}
}
}
bool same = true;
for (int i = 0; i < 3; i++)
same &= matchP[i];
if (same)
return 0;
int dif = 0;
for (int i = 0; i < 3; i++)
dif += !matchP[i];
if (dif > 4 - cnt)
return 5;
int ret = 5;
vec2d np[3];
for (int i = 0; i < 3; i++)
np[i] = p[i];
for (int i = 0; i < 3; i++) {
if (matchP[i])
continue;
for (int j = 0; j < 3; j++) {
if (matchQ[j])
continue;
// cout << i << " " << j << endl;
if (isOnL(p[i], p[i] + (p[(i + 1) % 3] - p[(i + 2) % 3]), q[j])) {
np[i] = q[j];
ret = min(ret, dfs(np, cnt + 1) + 1);
np[i] = p[i];
} else {
if (!matchP[(i + 1) % 3]) {
np[(i + 1) % 3] = getCrossP(
p[(i + 2) % 3], p[(i + 2) % 3] + (q[j] - p[i]) * 1e5,
p[(i + 1) % 3], p[(i + 1) % 3] + (p[i] - p[(i + 2) % 3]) * 1e5);
if (valid)
ret = min(ret, dfs(np, cnt + 1) + 1);
np[(i + 1) % 3] = p[(i + 1) % 3];
}
if (!matchP[(i + 2) % 3]) {
np[(i + 2) % 3] = getCrossP(
p[(i + 1) % 3], p[(i + 1) % 3] + (q[j] - p[i]) * 1e5,
p[(i + 2) % 3], p[(i + 2) % 3] + (p[i] - p[(i + 1) % 3]) * 1e5);
if (valid)
ret = min(ret, dfs(np, cnt + 1) + 1);
np[(i + 2) % 3] = p[(i + 2) % 3];
}
}
}
}
return ret;
}
int main(void) {
while (cin >> p[0].x) {
for (int i = 0; i < 3; i++) {
if (i != 0)
cin >> p[i].x;
cin >> p[i].y;
}
for (int i = 0; i < 3; i++) {
cin >> q[i].x >> q[i].y;
}
int ans = dfs(p, 0);
if (ans >= 5)
cout << "Many" << endl;
else
cout << ans << endl;
}
return 0;
}
| replace | 73 | 74 | 73 | 78 | TLE | |
p01110 | C++ | Runtime Error | #define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a, 0, sizeof(a))
#define inf (1ll << 60)
#define Yes(f) cout << (f ? "Yes" : "No") << endl
#define yes(f) cout << (f ? "yes" : "no") << endl
#define YES(f) cout << (f ? "YES" : "NO") << endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
using namespace std;
const int mod = 1e9 + 7;
void run();
void init() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
}
signed main() {
init();
run();
return 0;
}
void run() {
int n, m, t, p;
cin >> n >> m >> t >> p;
while (n) {
int a[m * t][n * t];
int x = 0, y = 0, w = n, h = m;
rep(i, m) rep(j, n) a[i][j] = 1;
while (t--) {
int d, c;
cin >> d >> c;
if (d == 1) {
Rep(i, y, h) {
rep(j, c) { a[i][x + 2 * c - j - 1] += a[i][x + j]; }
}
w = max(w, x + 2 * c);
x += c;
} else {
Rep(i, x, w) {
rep(j, c) { a[y + 2 * c - j - 1][i] += a[y + j][i]; }
}
h = max(h, y + 2 * c);
y += c;
}
}
while (p--) {
int r, t;
cin >> r >> t;
cout << a[y + t][x + r] << endl;
}
cin >> n >> m >> t >> p;
}
}
| #define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define Rep(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int, int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a, 0, sizeof(a))
#define inf (1ll << 60)
#define Yes(f) cout << (f ? "Yes" : "No") << endl
#define yes(f) cout << (f ? "yes" : "no") << endl
#define YES(f) cout << (f ? "YES" : "NO") << endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
using namespace std;
const int mod = 1e9 + 7;
void run();
void init() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
}
signed main() {
init();
run();
return 0;
}
void run() {
int n, m, t, p;
cin >> n >> m >> t >> p;
while (n) {
int a[1000][1000] = {};
int x = 0, y = 0, w = n, h = m;
rep(i, m) rep(j, n) a[i][j] = 1;
while (t--) {
int d, c;
cin >> d >> c;
if (d == 1) {
Rep(i, y, h) {
rep(j, c) { a[i][x + 2 * c - j - 1] += a[i][x + j]; }
}
w = max(w, x + 2 * c);
x += c;
} else {
Rep(i, x, w) {
rep(j, c) { a[y + 2 * c - j - 1][i] += a[y + j][i]; }
}
h = max(h, y + 2 * c);
y += c;
}
}
while (p--) {
int r, t;
cin >> r >> t;
cout << a[y + t][x + r] << endl;
}
cin >> n >> m >> t >> p;
}
}
| replace | 46 | 47 | 46 | 47 | 0 | |
p01110 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
while (true) {
int n, m, t, p;
cin >> n >> m >> t >> p;
if (n == 0)
break;
vector<vector<int>> card(300, vector<int>(300, 0));
for (int x = 0; x < n; ++x) {
for (int y = 0; y < m; ++y) {
card[x][y] = 1;
}
}
int l = 0, u = 0;
for (int q = 0; q < t; ++q) {
int d, c;
cin >> d >> c;
if (d == 1) {
for (int x = 0; x < c; ++x) {
for (int y = 0; y < m; ++y) {
card[l + c * 2 - x - 1][u + y] += card[l + x][u + y];
card[l + x][u + y] = 0;
}
}
l += c;
n = max(c, n - c);
} else {
for (int x = 0; x < n; ++x) {
for (int y = 0; y < c; ++y) {
card[l + x][u + c * 2 - 1 - y] += card[l + x][u + y];
card[l + x][u + y] = 0;
}
}
u += c;
m = max(c, m - c);
}
}
for (int q = 0; q < p; ++q) {
int x, y;
cin >> x >> y;
cout << card[l + x][u + y] << endl;
}
}
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
while (true) {
int n, m, t, p;
cin >> n >> m >> t >> p;
if (n == 0)
break;
vector<vector<int>> card(500, vector<int>(500, 0));
for (int x = 0; x < n; ++x) {
for (int y = 0; y < m; ++y) {
card[x][y] = 1;
}
}
int l = 0, u = 0;
for (int q = 0; q < t; ++q) {
int d, c;
cin >> d >> c;
if (d == 1) {
for (int x = 0; x < c; ++x) {
for (int y = 0; y < m; ++y) {
card[l + c * 2 - x - 1][u + y] += card[l + x][u + y];
card[l + x][u + y] = 0;
}
}
l += c;
n = max(c, n - c);
} else {
for (int x = 0; x < n; ++x) {
for (int y = 0; y < c; ++y) {
card[l + x][u + c * 2 - 1 - y] += card[l + x][u + y];
card[l + x][u + y] = 0;
}
}
u += c;
m = max(c, m - c);
}
}
for (int q = 0; q < p; ++q) {
int x, y;
cin >> x >> y;
cout << card[l + x][u + y] << endl;
}
}
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p01110 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, t, p;
while (cin >> n >> m >> t >> p, n) {
vector<pair<int, int>> d(t), x(p);
for (auto &e : d)
cin >> e.first >> e.second;
for (auto &e : x)
cin >> e.first >> e.second;
vector<vector<int>> a(2 * m, vector<int>(2 * n));
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = 1;
}
}
int x0 = 0, y0 = 0;
for (auto e : d) {
if (e.first == 1) {
x0 += e.second;
for (int i = 0; a[y0 + i][x0]; i++) {
for (int j = 0;
x0 - j - 1 >= 0 && (a[y0 + i][x0 + j] || a[y0 + i][x0 - j - 1]);
j++) {
a[y0 + i][x0 + j] += a[y0 + i][x0 - j - 1];
a[y0 + i][x0 - j - 1] = 0;
}
}
} else {
y0 += e.second;
for (int j = 0; a[y0][x0 + j]; j++) {
for (int i = 0;
y0 - i - 1 >= 0 && (a[y0 + i][x0 + j] || a[y0 - i - 1][x0 + j]);
i++) {
a[y0 + i][x0 + j] += a[y0 - i - 1][x0 + j];
a[y0 - i - 1][x0 + j] = 0;
}
}
}
}
for (auto e : x) {
cout << a[y0 + e.second][x0 + e.first] << endl;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, t, p;
while (cin >> n >> m >> t >> p, n) {
vector<pair<int, int>> d(t), x(p);
for (auto &e : d)
cin >> e.first >> e.second;
for (auto &e : x)
cin >> e.first >> e.second;
vector<vector<int>> a((t + 1) * m, vector<int>((t + 1) * n));
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
a[i][j] = 1;
}
}
int x0 = 0, y0 = 0;
for (auto e : d) {
if (e.first == 1) {
x0 += e.second;
for (int i = 0; a[y0 + i][x0]; i++) {
for (int j = 0;
x0 - j - 1 >= 0 && (a[y0 + i][x0 + j] || a[y0 + i][x0 - j - 1]);
j++) {
a[y0 + i][x0 + j] += a[y0 + i][x0 - j - 1];
a[y0 + i][x0 - j - 1] = 0;
}
}
} else {
y0 += e.second;
for (int j = 0; a[y0][x0 + j]; j++) {
for (int i = 0;
y0 - i - 1 >= 0 && (a[y0 + i][x0 + j] || a[y0 - i - 1][x0 + j]);
i++) {
a[y0 + i][x0 + j] += a[y0 - i - 1][x0 + j];
a[y0 - i - 1][x0 + j] = 0;
}
}
}
}
for (auto e : x) {
cout << a[y0 + e.second][x0 + e.first] << endl;
}
}
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p01110 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MAX_N 100
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int w, h, t, p, d, c;
while (cin >> w >> h >> t >> p, w | h | t | p) {
int table[MAX_N + 10][MAX_N + 10] = {};
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
table[i][j] = 1;
for (int i = 0; i < t; i++) {
cin >> d >> c;
if (d == 1) {
for (int j = 0; j < h; j++) {
for (int k = 0; k < c; k++) {
int alpha = c - k - 1;
table[j][c + alpha] += table[j][k];
table[j][k] = 0;
}
}
for (int j = 0; j < MAX_N; j++) {
for (int k = 0; k < MAX_N; k++) {
table[j][k] = table[j][k + c];
}
}
} else if (d == 2) {
for (int j = 0; j < c; j++) {
for (int k = 0; k < w; k++) {
int alpha = c - j - 1;
table[c + alpha][k] += table[j][k];
table[j][k] = 0;
}
}
for (int j = 0; j < MAX_N; j++) {
for (int k = 0; k < MAX_N; k++) {
table[j][k] = table[j + c][k];
}
}
}
}
int x, y;
for (int i = 0; i < p; i++) {
cin >> x >> y;
cout << table[y][x] << endl;
}
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MAX_N 100
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int w, h, t, p, d, c;
while (cin >> w >> h >> t >> p, w | h | t | p) {
int table[2 * MAX_N][2 * MAX_N] = {};
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
table[i][j] = 1;
for (int i = 0; i < t; i++) {
cin >> d >> c;
if (d == 1) {
for (int j = 0; j < h; j++) {
for (int k = 0; k < c; k++) {
int alpha = c - k - 1;
table[j][c + alpha] += table[j][k];
table[j][k] = 0;
}
}
for (int j = 0; j < MAX_N; j++) {
for (int k = 0; k < MAX_N; k++) {
table[j][k] = table[j][k + c];
}
}
} else if (d == 2) {
for (int j = 0; j < c; j++) {
for (int k = 0; k < w; k++) {
int alpha = c - j - 1;
table[c + alpha][k] += table[j][k];
table[j][k] = 0;
}
}
for (int j = 0; j < MAX_N; j++) {
for (int k = 0; k < MAX_N; k++) {
table[j][k] = table[j + c][k];
}
}
}
}
int x, y;
for (int i = 0; i < p; i++) {
cin >> x >> y;
cout << table[y][x] << endl;
}
}
return 0;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p01111 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
typedef long long ll;
using namespace std;
#define sum(l, r) (((r) * ((r)-1) - (l) * ((l)-1)) / 2)
int main(void) {
ll B;
while (cin >> B, B) {
for (ll w = 100000; w >= 0; w--) {
ll l = 0, h = B + 1;
while (h - l > 1) {
ll m = (l + h) / 2;
if (sum(m, m + w) >= B)
h = m;
else
l = m;
}
if (sum(h, h + w) == B) {
cout << h << " " << w << endl;
break;
}
}
}
}
| #include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
typedef long long ll;
using namespace std;
#define sum(l, r) (((r) * ((r)-1) - (l) * ((l)-1)) / 2)
int main(void) {
ll B;
while (cin >> B, B) {
for (ll w = 65000; w >= 0; w--) {
ll l = 0, h = B + 1;
while (h - l > 1) {
ll m = (l + h) / 2;
if (sum(m, m + w) >= B)
h = m;
else
l = m;
}
if (sum(h, h + w) == B) {
cout << h << " " << w << endl;
break;
}
}
}
}
| replace | 10 | 11 | 10 | 11 | TLE | |
p01111 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
cout.precision(20);
}
} fast;
/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X) \
(upper_bound((V).begin(), (V).end(), X) - \
lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v) \
{ \
cerr << #v << ':'; \
for (auto xv : v) \
cerr << xv << ' '; \
cerr << endl; \
}
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))
/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;
/* func */
template <typename T> inline bool chmin(T &a, const T &b) {
if (a > b)
a = b;
return a > b;
}
template <typename T> inline bool chmax(T &a, const T &b) {
if (a < b)
a = b;
return a < b;
}
long long max(long long x, int y) { return max(x, (long long)y); }
long long max(int x, long long y) { return max((long long)x, y); }
long long min(long long x, int y) { return min(x, (long long)y); }
long long min(int x, long long y) { return min((long long)x, y); }
/* liblary */
/* main */
bool check(ll &imid, ll &b, ll &i) {
ll m = i + imid - 1;
ll n = imid - 1;
return m * (m + 1) / 2 - n * (n + 1) / 2 >= b;
}
bool check2(ll &imid, ll &b, ll &i) {
ll m = i + imid - 1;
ll n = imid - 1;
return m * (m + 1) / 2 - n * (n + 1) / 2 == b;
}
void solve(ll b) {
REP(i, 1, 100000) {
ll imax = INF;
ll imin = 0;
while (imax - imin > 1) {
ll imid = (imax + imin) / 2;
if (check(imid, b, i))
imax = imid;
else
imin = imid;
}
if (check2(imax, b, i)) {
cout << imax << ' ' << i << endl;
return;
}
}
}
signed main() {
ll b;
while (cin >> b) {
if (b == 0)
return 0;
solve(b);
}
}
| #include <bits/stdc++.h>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
cout.precision(20);
}
} fast;
/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X) \
(upper_bound((V).begin(), (V).end(), X) - \
lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v) \
{ \
cerr << #v << ':'; \
for (auto xv : v) \
cerr << xv << ' '; \
cerr << endl; \
}
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))
/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;
/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;
/* func */
template <typename T> inline bool chmin(T &a, const T &b) {
if (a > b)
a = b;
return a > b;
}
template <typename T> inline bool chmax(T &a, const T &b) {
if (a < b)
a = b;
return a < b;
}
long long max(long long x, int y) { return max(x, (long long)y); }
long long max(int x, long long y) { return max((long long)x, y); }
long long min(long long x, int y) { return min(x, (long long)y); }
long long min(int x, long long y) { return min((long long)x, y); }
/* liblary */
/* main */
bool check(ll &imid, ll &b, ll &i) {
ll m = i + imid - 1;
ll n = imid - 1;
return m * (m + 1) / 2 - n * (n + 1) / 2 >= b;
}
bool check2(ll &imid, ll &b, ll &i) {
ll m = i + imid - 1;
ll n = imid - 1;
return m * (m + 1) / 2 - n * (n + 1) / 2 == b;
}
void solve(ll b) {
REP(i, 1, 50000) {
ll imax = INF;
ll imin = 0;
while (imax - imin > 1) {
ll imid = (imax + imin) / 2;
if (check(imid, b, i))
imax = imid;
else
imin = imid;
}
if (check2(imax, b, i)) {
cout << imax << ' ' << i << endl;
return;
}
}
}
signed main() {
ll b;
while (cin >> b) {
if (b == 0)
return 0;
solve(b);
}
}
| replace | 86 | 87 | 86 | 87 | TLE | |
p01112 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
class ScoreBoard {
public:
// 1: win
// -1: lose
// enum
vector<vector<int>> board;
vector<int> wincounts;
ScoreBoard(int N) {
board = vector<vector<int>>(N, vector<int>(N));
wincounts.resize(N);
}
void update(int x, int y) {
board[x][y] = 1;
board[y][x] = -1;
wincounts[x]++;
}
void remove(int x, int y) {
board[x][y] = board[y][x] = 0;
wincounts[x]--;
}
bool allok() {
for (int i = 0; i < board.size(); i++)
if (wincounts[i] > (board.size() - 1) / 2)
return false;
return true;
}
bool ok(int x, int y) { return wincounts[x] < (board.size() - 1) / 2; }
void view() {
cout << "============" << endl;
for (int x = 0; x < board.size(); x++) {
for (int y = 0; y < board.size(); y++) {
if (x == y)
cout << ". ";
else
cout << (board[x][y] == 1) << " ";
}
cout << endl;
}
}
int dfs(vector<int> &X, vector<int> &Y, int idx) {
if (X.size() == idx) {
// view();
return 1;
}
int res = 0;
if (ok(X[idx], Y[idx])) {
update(X[idx], Y[idx]);
res += dfs(X, Y, idx + 1);
remove(X[idx], Y[idx]);
}
if (ok(Y[idx], X[idx])) {
update(Y[idx], X[idx]);
res += dfs(X, Y, idx + 1);
remove(Y[idx], X[idx]);
}
return res;
}
};
int main() {
int N, M;
while (cin >> N >> M, N | M) {
auto sb = ScoreBoard(N);
for (int i = 0; i < M; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
sb.update(x, y);
}
vector<int> X, Y;
for (int x = 0; x < N; x++) {
for (int y = x + 1; y < N; y++) {
if (sb.board[x][y] != 0)
continue;
X.push_back(x);
Y.push_back(y);
}
}
if (sb.allok())
cout << sb.dfs(X, Y, 0) << endl;
else
cout << 0 << endl;
}
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
class ScoreBoard {
public:
// 1: win
// -1: lose
// enum
vector<vector<int>> board;
vector<int> wincounts;
ScoreBoard(int N) {
board = vector<vector<int>>(N, vector<int>(N));
wincounts.resize(N);
}
void update(int x, int y) {
board[x][y] = 1;
board[y][x] = -1;
wincounts[x]++;
}
void remove(int x, int y) {
board[x][y] = board[y][x] = 0;
wincounts[x]--;
}
bool allok() {
for (int i = 0; i < board.size(); i++)
if (wincounts[i] > (board.size() - 1) / 2)
return false;
return true;
}
bool ok(int x, int y) { return wincounts[x] < (board.size() - 1) / 2; }
void view() {
cout << "============" << endl;
for (int x = 0; x < board.size(); x++) {
for (int y = 0; y < board.size(); y++) {
if (x == y)
cout << ". ";
else
cout << (board[x][y] == 1) << " ";
}
cout << endl;
}
}
int dfs(vector<int> &X, vector<int> &Y, int idx) {
if (X.size() == idx) {
// view();
return 1;
}
int res = 0;
if (ok(X[idx], Y[idx])) {
update(X[idx], Y[idx]);
res += dfs(X, Y, idx + 1);
remove(X[idx], Y[idx]);
}
if (ok(Y[idx], X[idx])) {
update(Y[idx], X[idx]);
res += dfs(X, Y, idx + 1);
remove(Y[idx], X[idx]);
}
return res;
}
};
int main() {
int N, M;
while (cin >> N, N) {
cin >> M;
auto sb = ScoreBoard(N);
for (int i = 0; i < M; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
sb.update(x, y);
}
vector<int> X, Y;
for (int x = 0; x < N; x++) {
for (int y = x + 1; y < N; y++) {
if (sb.board[x][y] != 0)
continue;
X.push_back(x);
Y.push_back(y);
}
}
if (sb.allok())
cout << sb.dfs(X, Y, 0) << endl;
else
cout << 0 << endl;
}
return 0;
}
| replace | 67 | 68 | 67 | 69 | TLE | |
p01114 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int N, K;
int X[10000], Y[10000];
void beet() {
cin >> K;
vector<int> vs;
for (int i = 0; i < N; i++) {
cin >> X[i] >> Y[i];
vs.push_back(Y[i]);
}
double sq3 = sqrt(3);
vector<int> latte(N), malta(N);
iota(begin(latte), end(latte), 0);
iota(begin(malta), end(malta), 0);
sort(begin(latte), end(latte),
[&](int a, int b) { return X[a] - Y[a] / sq3 < X[b] - Y[b] / sq3; });
sort(begin(malta), end(malta),
[&](int a, int b) { return X[a] + Y[a] / sq3 < X[b] + Y[b] / sq3; });
int need1 = N - K;
sort(begin(vs), end(vs));
vs.erase(unique(begin(vs), end(vs)), end(vs));
double ret = 1e30;
for (int y_0 : vs) {
vector<pair<double, int>> hidari;
vector<pair<double, int>> migi;
for (auto &i : latte) {
if (y_0 > Y[i]) {
} else if (Y[i] == y_0) {
hidari.emplace_back(X[i], i);
} else {
double dist = Y[i] - y_0;
hidari.emplace_back(X[i] - dist / sq3, i);
}
}
for (auto &i : malta) {
if (y_0 > Y[i]) {
} else if (Y[i] == y_0) {
migi.emplace_back(X[i], i);
} else {
double dist = Y[i] - y_0;
migi.emplace_back(X[i] + dist / sq3, i);
}
}
if (hidari.empty() || migi.empty())
continue;
vector<int> st(hidari.size()), inner(hidari.size());
int ptr = 0;
double last = -1e9;
int add = 0;
for (int i = 0; i < hidari.size(); i++) {
st[hidari[i].second] = true;
}
for (int i = 0; i < hidari.size(); i++) {
while (ptr < migi.size() && add < need1) {
if (st[migi[ptr].second]) {
inner[migi[ptr].second] = true;
last = migi[ptr].first;
++add;
}
++ptr;
}
if (add >= need1) {
ret = min(ret, last - hidari[i].first);
}
if (inner[hidari[i].second]) {
inner[hidari[i].second] = false;
--add;
}
st[hidari[i].second] = false;
}
}
cout << fixed << setprecision(15) << ret * 3 << endl;
}
int main() {
while (cin >> N, N)
beet();
}
| #include <bits/stdc++.h>
using namespace std;
int N, K;
int X[10000], Y[10000];
void beet() {
cin >> K;
vector<int> vs;
for (int i = 0; i < N; i++) {
cin >> X[i] >> Y[i];
vs.push_back(Y[i]);
}
double sq3 = sqrt(3);
vector<int> latte(N), malta(N);
iota(begin(latte), end(latte), 0);
iota(begin(malta), end(malta), 0);
sort(begin(latte), end(latte),
[&](int a, int b) { return X[a] - Y[a] / sq3 < X[b] - Y[b] / sq3; });
sort(begin(malta), end(malta),
[&](int a, int b) { return X[a] + Y[a] / sq3 < X[b] + Y[b] / sq3; });
int need1 = N - K;
sort(begin(vs), end(vs));
vs.erase(unique(begin(vs), end(vs)), end(vs));
double ret = 1e30;
for (int y_0 : vs) {
vector<pair<double, int>> hidari;
vector<pair<double, int>> migi;
for (auto &i : latte) {
if (y_0 > Y[i]) {
} else if (Y[i] == y_0) {
hidari.emplace_back(X[i], i);
} else {
double dist = Y[i] - y_0;
hidari.emplace_back(X[i] - dist / sq3, i);
}
}
for (auto &i : malta) {
if (y_0 > Y[i]) {
} else if (Y[i] == y_0) {
migi.emplace_back(X[i], i);
} else {
double dist = Y[i] - y_0;
migi.emplace_back(X[i] + dist / sq3, i);
}
}
vector<int> st(N), inner(N);
int ptr = 0;
double last = -1e9;
int add = 0;
for (int i = 0; i < hidari.size(); i++) {
st[hidari[i].second] = true;
}
for (int i = 0; i < hidari.size(); i++) {
while (ptr < migi.size() && add < need1) {
if (st[migi[ptr].second]) {
inner[migi[ptr].second] = true;
last = migi[ptr].first;
++add;
}
++ptr;
}
if (add >= need1) {
ret = min(ret, last - hidari[i].first);
}
if (inner[hidari[i].second]) {
inner[hidari[i].second] = false;
--add;
}
st[hidari[i].second] = false;
}
}
cout << fixed << setprecision(15) << ret * 3 << endl;
}
int main() {
while (cin >> N, N)
beet();
}
| replace | 48 | 51 | 48 | 50 | 0 | |
p01125 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
bool dia[20][20] = {};
for (int i = 0, x, y; i < n; i++) {
cin >> x >> y;
dia[y][x] = 1;
}
int mo;
cin >> mo;
string di = "NESW";
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
for (int i = 0, num, x = 10, y = 10; i < mo; i++) {
char direction;
cin >> direction >> num;
for (int j = 0; j < 4; j++) {
if (direction == di[j]) {
for (int k = 0; k < num; k++) {
x += dx[j];
y += dy[j];
if (dia[y][x] == true) {
dia[y][x] = false;
n--;
}
}
break;
}
}
}
if (n == 0)
cout << "Yes\n";
else
cout << "No\n";
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
bool dia[41][41] = {};
for (int i = 0, x, y; i < n; i++) {
cin >> x >> y;
dia[y][x] = 1;
}
int mo;
cin >> mo;
string di = "NESW";
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
for (int i = 0, num, x = 10, y = 10; i < mo; i++) {
char direction;
cin >> direction >> num;
for (int j = 0; j < 4; j++) {
if (direction == di[j]) {
for (int k = 0; k < num; k++) {
x += dx[j];
y += dy[j];
if (dia[y][x] == true) {
dia[y][x] = false;
n--;
}
}
break;
}
}
}
if (n == 0)
cout << "Yes\n";
else
cout << "No\n";
}
} | replace | 5 | 6 | 5 | 6 | 0 | |
p01125 | C++ | Runtime Error | #include <iostream>
#include <map>
using namespace std;
#define N 20
int main(int argc, char const *argv[]) {
int f[N][N];
int n, xj, yj;
int m, d;
char c;
int xr, yr;
int cnt;
map<char, pair<int, int>> mp;
mp['N'] = make_pair(0, 1);
mp['E'] = make_pair(1, 0);
mp['S'] = make_pair(0, -1);
mp['W'] = make_pair(-1, 0);
while (1) {
cin >> n;
if (n == 0)
break;
for (int i1 = 0; i1 < N; i1++) {
for (int i2 = 0; i2 < N; i2++) {
f[i1][i2] = 0;
}
}
xr = 10;
yr = 10;
cnt = 0;
for (int i1 = 0; i1 < n; i1++) {
cin >> xj >> yj;
f[yj][xj] = 1;
}
if (f[yr][xr] == 1) {
cnt++;
f[yr][xr] = 0;
}
cin >> m;
for (int i1 = 0; i1 < m; i1++) {
cin >> c >> d;
for (int i2 = 0; i2 < d; i2++) {
xr = mp[c].first + xr;
yr = mp[c].second + yr;
if (f[yr][xr] == 1) {
cnt++;
f[yr][xr] = 0;
}
}
}
if (cnt == n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | #include <iostream>
#include <map>
using namespace std;
#define N 21
int main(int argc, char const *argv[]) {
int f[N][N];
int n, xj, yj;
int m, d;
char c;
int xr, yr;
int cnt;
map<char, pair<int, int>> mp;
mp['N'] = make_pair(0, 1);
mp['E'] = make_pair(1, 0);
mp['S'] = make_pair(0, -1);
mp['W'] = make_pair(-1, 0);
while (1) {
cin >> n;
if (n == 0)
break;
for (int i1 = 0; i1 < N; i1++) {
for (int i2 = 0; i2 < N; i2++) {
f[i1][i2] = 0;
}
}
xr = 10;
yr = 10;
cnt = 0;
for (int i1 = 0; i1 < n; i1++) {
cin >> xj >> yj;
f[yj][xj] = 1;
}
if (f[yr][xr] == 1) {
cnt++;
f[yr][xr] = 0;
}
cin >> m;
for (int i1 = 0; i1 < m; i1++) {
cin >> c >> d;
for (int i2 = 0; i2 < d; i2++) {
xr = mp[c].first + xr;
yr = mp[c].second + yr;
if (f[yr][xr] == 1) {
cnt++;
f[yr][xr] = 0;
}
}
}
if (cnt == n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p01125 | C++ | Runtime Error | /*
2000:Misterious Gems
*/
#include <iostream>
using namespace std;
int main(void) {
while (1) {
int Map[20][20] = {0};
int cGems = 0;
int point[2] = {10, 10};
int cCount;
cin >> cGems;
if (cGems == 0) {
break;
}
for (int i = 0; i < cGems; i++) {
int a, b;
cin >> a >> b;
Map[a][20 - b] = 1;
}
cin >> cCount;
for (int i = 0; i < cCount; i++) {
char dir;
int num;
cin >> dir >> num;
if (dir == 'N') {
for (int j = 0; j < num; j++) {
point[1]--;
if (Map[point[0]][point[1]] == 1) {
cGems--;
Map[point[0]][point[1]] = 0;
}
}
} else if (dir == 'S') {
for (int j = 0; j < num; j++) {
point[1]++;
if (Map[point[0]][point[1]] == 1) {
cGems--;
Map[point[0]][point[1]] = 0;
}
}
} else if (dir == 'E') {
for (int j = 0; j < num; j++) {
point[0]++;
if (Map[point[0]][point[1]] == 1) {
cGems--;
Map[point[0]][point[1]] = 0;
}
}
} else if (dir == 'W') {
for (int j = 0; j < num; j++) {
point[0]--;
if (Map[point[0]][point[1]] == 1) {
cGems--;
Map[point[0]][point[1]] = 0;
}
}
}
}
if (cGems == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
} | /*
2000:Misterious Gems
*/
#include <iostream>
using namespace std;
int main(void) {
while (1) {
int Map[21][21] = {0};
int cGems = 0;
int point[2] = {10, 10};
int cCount;
cin >> cGems;
if (cGems == 0) {
break;
}
for (int i = 0; i < cGems; i++) {
int a, b;
cin >> a >> b;
Map[a][20 - b] = 1;
}
cin >> cCount;
for (int i = 0; i < cCount; i++) {
char dir;
int num;
cin >> dir >> num;
if (dir == 'N') {
for (int j = 0; j < num; j++) {
point[1]--;
if (Map[point[0]][point[1]] == 1) {
cGems--;
Map[point[0]][point[1]] = 0;
}
}
} else if (dir == 'S') {
for (int j = 0; j < num; j++) {
point[1]++;
if (Map[point[0]][point[1]] == 1) {
cGems--;
Map[point[0]][point[1]] = 0;
}
}
} else if (dir == 'E') {
for (int j = 0; j < num; j++) {
point[0]++;
if (Map[point[0]][point[1]] == 1) {
cGems--;
Map[point[0]][point[1]] = 0;
}
}
} else if (dir == 'W') {
for (int j = 0; j < num; j++) {
point[0]--;
if (Map[point[0]][point[1]] == 1) {
cGems--;
Map[point[0]][point[1]] = 0;
}
}
}
}
if (cGems == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p01125 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
using namespace std;
int n;
int m;
int dx[256];
int dy[256];
int xs[256];
int ys[256];
bool field[100][100];
int main() {
dx['N'] = 0;
dy['N'] = 1;
dx['S'] = 0;
dy['S'] = -1;
dx['E'] = 1;
dy['E'] = 0;
dx['W'] = -1;
dy['W'] = 0;
while (1) {
scanf("%d", &n);
if (n == 0)
return 0;
fill(field[0], field[30], false);
for (int i = 0; i < n; i++) {
scanf("%d%d", &xs[i], &ys[i]);
field[ys[i]][xs[i]] = true;
}
scanf("%d", &m);
int x = 10;
int y = 10;
int cnt = 0;
for (int i = 0; i < m; i++) {
char d;
int l;
scanf(" %c %d", &d, &l);
while (l--) {
x += dx[d] * l;
y += dy[d] * l;
if (field[y][x]) {
field[y][x] = false;
cnt++;
}
}
}
if (cnt == n) {
puts("Yes");
} else {
puts("No");
}
}
} | #include <algorithm>
#include <cstdio>
using namespace std;
int n;
int m;
int dx[256];
int dy[256];
int xs[256];
int ys[256];
bool field[100][100];
int main() {
dx['N'] = 0;
dy['N'] = 1;
dx['S'] = 0;
dy['S'] = -1;
dx['E'] = 1;
dy['E'] = 0;
dx['W'] = -1;
dy['W'] = 0;
while (1) {
scanf("%d", &n);
if (n == 0)
return 0;
fill(field[0], field[30], false);
for (int i = 0; i < n; i++) {
scanf("%d%d", &xs[i], &ys[i]);
field[ys[i]][xs[i]] = true;
}
scanf("%d", &m);
int x = 10;
int y = 10;
int cnt = 0;
for (int i = 0; i < m; i++) {
char d;
int l;
scanf(" %c %d", &d, &l);
while (l--) {
x += dx[d];
y += dy[d];
if (field[y][x]) {
field[y][x] = false;
cnt++;
}
}
}
if (cnt == n) {
puts("Yes");
} else {
puts("No");
}
}
} | replace | 45 | 47 | 45 | 47 | -11 | |
p01125 | C++ | Runtime Error | #include <iostream>
#include <stdio.h>
using namespace std;
struct JWE {
bool f;
int x;
int y;
};
int main() {
bool ma[22][22] = {};
JWE JW[21];
int n1, n2, x1, y1, k, x = 10, y = 10;
char ch;
for (int i = 0; i < 22; i++)
for (int j = 0; j < 22; j++)
ma[i][j] = false;
while (scanf("%d", &n1) != EOF) {
if (n1 == 0)
break;
for (int i = 0; i < n1; i++) {
cin >> x1 >> y1;
JW[i].x = x1;
JW[i].y = y1;
}
scanf("%d", &n2);
for (int ii = 0; ii < n2; ii++) {
cin >> ch >> k;
if (ch == 'N') {
for (int j = y; j <= y + k; j++)
ma[x][j] = true;
y = y + k;
} else if (ch == 'S') {
for (int j = y; j >= y - k; j--)
ma[x][j] = true;
y = y - k;
} else if (ch == 'E') {
for (int j = x; j <= x + k; j++)
ma[j][y] = true;
x = x + k;
} else if (ch == 'W') {
for (int j = x; j >= x - k; j--)
ma[j][y] = true;
x = x - k;
}
}
int sum = 0;
for (int i = 0; i < n1; i++) {
if (ma[JW[i].x][JW[i].y] == true)
sum++;
}
if (n1 == sum)
printf("Yes\n");
else
printf("No\n");
for (int i = 0; i < 22; i++)
for (int j = 0; j < 22; j++)
ma[i][j] = false;
/*
for(int i=0;i<21;i++){
for(int j=0;j<21;j++)
{cout<<" ";
if(ma[j][i]==false)cout<<"*";
else cout<<"1";}
cout<<endl;
}
*/
}
return 0;
} | #include <iostream>
#include <stdio.h>
using namespace std;
struct JWE {
bool f;
int x;
int y;
};
int main() {
bool ma[22][22] = {};
JWE JW[21];
int n1, n2, x1, y1, k, x = 10, y = 10;
char ch;
for (int i = 0; i < 22; i++)
for (int j = 0; j < 22; j++)
ma[i][j] = false;
while (scanf("%d", &n1) != EOF) {
if (n1 == 0)
break;
for (int i = 0; i < n1; i++) {
cin >> x1 >> y1;
JW[i].x = x1;
JW[i].y = y1;
}
x = 10, y = 10;
scanf("%d", &n2);
for (int ii = 0; ii < n2; ii++) {
cin >> ch >> k;
if (ch == 'N') {
for (int j = y; j <= y + k; j++)
ma[x][j] = true;
y = y + k;
} else if (ch == 'S') {
for (int j = y; j >= y - k; j--)
ma[x][j] = true;
y = y - k;
} else if (ch == 'E') {
for (int j = x; j <= x + k; j++)
ma[j][y] = true;
x = x + k;
} else if (ch == 'W') {
for (int j = x; j >= x - k; j--)
ma[j][y] = true;
x = x - k;
}
}
int sum = 0;
for (int i = 0; i < n1; i++) {
if (ma[JW[i].x][JW[i].y] == true)
sum++;
}
if (n1 == sum)
printf("Yes\n");
else
printf("No\n");
for (int i = 0; i < 22; i++)
for (int j = 0; j < 22; j++)
ma[i][j] = false;
/*
for(int i=0;i<21;i++){
for(int j=0;j<21;j++)
{cout<<" ";
if(ma[j][i]==false)cout<<"*";
else cout<<"1";}
cout<<endl;
}
*/
}
return 0;
} | replace | 27 | 28 | 27 | 28 | 0 | |
p01125 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
while (cin >> n, n) {
vector<P> gems;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
gems.push_back(P(x, y));
}
int rx = 10, ry = 10;
int m;
cin >> m;
vector<vector<int>> visited(20, vector<int>(20, 0));
visited[rx][ry] = 1;
for (int i = 0; i < m; i++) {
string s;
cin >> s;
int l;
cin >> l;
if (s == "N") {
for (int i = 0; i < l; i++) {
ry++;
visited[rx][ry] = 1;
}
} else if (s == "E") {
for (int i = 0; i < l; i++) {
rx++;
visited[rx][ry] = 1;
}
} else if (s == "S") {
for (int i = 0; i < l; i++) {
ry--;
visited[rx][ry] = 1;
}
} else {
for (int i = 0; i < l; i++) {
rx--;
visited[rx][ry] = 1;
}
}
}
bool flag = true;
for (int i = 0; i < n; i++) {
int x = gems[i].first, y = gems[i].second;
if (!visited[x][y])
flag = false;
}
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
} | #include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
while (cin >> n, n) {
vector<P> gems;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
gems.push_back(P(x, y));
}
int rx = 10, ry = 10;
int m;
cin >> m;
vector<vector<int>> visited(30, vector<int>(30, 0));
visited[rx][ry] = 1;
for (int i = 0; i < m; i++) {
string s;
cin >> s;
int l;
cin >> l;
if (s == "N") {
for (int i = 0; i < l; i++) {
ry++;
visited[rx][ry] = 1;
}
} else if (s == "E") {
for (int i = 0; i < l; i++) {
rx++;
visited[rx][ry] = 1;
}
} else if (s == "S") {
for (int i = 0; i < l; i++) {
ry--;
visited[rx][ry] = 1;
}
} else {
for (int i = 0; i < l; i++) {
rx--;
visited[rx][ry] = 1;
}
}
}
bool flag = true;
for (int i = 0; i < n; i++) {
int x = gems[i].first, y = gems[i].second;
if (!visited[x][y])
flag = false;
}
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
} | replace | 21 | 22 | 21 | 22 | 0 | |
p01125 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int n;
while (cin >> n, n) {
bool used[21][21] = {{0}};
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
used[y][x] = 1;
}
int m;
cin >> m;
int nx = 10, ny = 10;
used[ny][nx] = 0;
for (int i = 0; i < m; i++) {
char c;
int d;
cin >> c >> d;
if (c == 'N') {
for (int i = 0; i < d; i++) {
used[++ny][nx] = 0;
}
}
if (c == 'E') {
for (int i = 0; i < d; i++) {
used[ny][++nx] = 0;
}
}
if (c == 'S') {
for (int i = 0; i < d; i++) {
used[--ny][nx] = 0;
}
}
if (c == 'W') {
for (int i = 0; i < d; i++) {
used[++ny][--nx] = 0;
}
}
}
int cnt = 0;
for (int i = 0; i < 21; i++) {
for (int j = 0; j < 21; j++)
cnt += used[i][j];
}
if (cnt)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int n;
while (cin >> n, n) {
bool used[21][21] = {{0}};
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
used[y][x] = 1;
}
int m;
cin >> m;
int nx = 10, ny = 10;
used[ny][nx] = 0;
for (int i = 0; i < m; i++) {
char c;
int d;
cin >> c >> d;
if (c == 'N') {
for (int i = 0; i < d; i++) {
used[++ny][nx] = 0;
}
}
if (c == 'E') {
for (int i = 0; i < d; i++) {
used[ny][++nx] = 0;
}
}
if (c == 'S') {
for (int i = 0; i < d; i++) {
used[--ny][nx] = 0;
}
}
if (c == 'W') {
for (int i = 0; i < d; i++) {
used[ny][--nx] = 0;
}
}
}
int cnt = 0;
for (int i = 0; i < 21; i++) {
for (int j = 0; j < 21; j++)
cnt += used[i][j];
}
if (cnt)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
| replace | 40 | 41 | 40 | 41 | -6 | *** stack smashing detected ***: terminated
|
p01125 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define RFOR(i, m, n) for (int i = m - 1; i >= n; --i)
#define ALL(v) v.begin(), v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (1) {
int cx = 10, cy = 10;
int v[20][20];
REP(i, 20) {
REP(j, 20) { v[i][j] = 0; }
}
int n, m, cnt = 0;
cin >> n;
if (!n)
break;
REP(i, n) {
int x, y;
cin >> x >> y;
v[x][y] = 1;
}
cin >> m;
REP(i, m) {
char d;
int L;
cin >> d >> L;
int dx, dy;
if (d == 'N') {
dx = 0;
dy = 1;
} else if (d == 'E') {
dx = 1;
dy = 0;
} else if (d == 'W') {
dx = -1;
dy = 0;
} else {
dx = 0;
dy = -1;
}
FOR(j, 1, L + 1) {
if (v[cx + j * dx][cy + j * dy] == 1) {
cnt++;
v[cx + j * dx][cy + j * dy] = 0;
}
}
cx += L * dx;
cy += L * dy;
}
if (cnt == n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | #include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define RFOR(i, m, n) for (int i = m - 1; i >= n; --i)
#define ALL(v) v.begin(), v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (1) {
int cx = 10, cy = 10;
int v[21][21];
REP(i, 21) {
REP(j, 21) { v[i][j] = 0; }
}
int n, m, cnt = 0;
cin >> n;
if (!n)
break;
REP(i, n) {
int x, y;
cin >> x >> y;
v[x][y] = 1;
}
cin >> m;
REP(i, m) {
char d;
int L;
cin >> d >> L;
int dx, dy;
if (d == 'N') {
dx = 0;
dy = 1;
} else if (d == 'E') {
dx = 1;
dy = 0;
} else if (d == 'W') {
dx = -1;
dy = 0;
} else {
dx = 0;
dy = -1;
}
FOR(j, 1, L + 1) {
if (v[cx + j * dx][cy + j * dy] == 1) {
cnt++;
v[cx + j * dx][cy + j * dy] = 0;
}
}
cx += L * dx;
cy += L * dy;
}
if (cnt == n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | replace | 24 | 27 | 24 | 27 | 0 | |
p01125 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> P;
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n;
map<string, int> mp;
mp["N"] = 0;
mp["E"] = 1;
mp["W"] = 2;
mp["S"] = 3;
while (cin >> n, n) {
vector<vector<bool>> exist(21, vector<bool>(21, false));
rep(i, n) {
int x, y;
cin >> x >> y;
exist[x][y] = true;
}
int m;
cin >> m;
int x = 10, y = 10;
int num_done = 0;
rep(i, m) {
string c;
int step;
cin >> c >> step;
int k = mp[c];
rep(j, step) {
x += dx[k], y += dy[k];
if (exist[x][y]) {
exist[x][y] = false;
num_done++;
}
}
}
cout << (num_done == n ? "Yes" : "No") << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef pair<int, int> P;
int dy[4] = {1, 0, 0, -1};
int dx[4] = {0, 1, -1, 0};
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n;
map<string, int> mp;
mp["N"] = 0;
mp["E"] = 1;
mp["W"] = 2;
mp["S"] = 3;
while (cin >> n, n) {
vector<vector<bool>> exist(21, vector<bool>(21, false));
rep(i, n) {
int x, y;
cin >> x >> y;
exist[x][y] = true;
}
int m;
cin >> m;
int x = 10, y = 10;
int num_done = 0;
rep(i, m) {
string c;
int step;
cin >> c >> step;
int k = mp[c];
rep(j, step) {
x += dx[k], y += dy[k];
if (exist[x][y]) {
exist[x][y] = false;
num_done++;
}
}
}
cout << (num_done == n ? "Yes" : "No") << endl;
}
} | replace | 13 | 15 | 13 | 15 | 0 | |
p01125 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;
int main() {
int stone;
while (cin >> stone, stone) {
int map[20][20] = {0};
int x, y;
x = y = 10;
rep(i, stone) {
int a, b;
cin >> a >> b;
map[a][b] = 1;
}
int order;
cin >> order;
rep(i, order) {
int distance;
char direction;
cin >> direction >> distance;
rep(j, distance) {
if (direction == 'N') {
y++;
} else if (direction == 'E') {
x++;
} else if (direction == 'S') {
y--;
} else {
x--;
}
stone -= map[x][y];
map[x][y] = 0;
}
}
if (!stone)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;
int main() {
int stone;
while (cin >> stone, stone) {
int map[24][24] = {0};
int x, y;
x = y = 10;
rep(i, stone) {
int a, b;
cin >> a >> b;
map[a][b] = 1;
}
int order;
cin >> order;
rep(i, order) {
int distance;
char direction;
cin >> direction >> distance;
rep(j, distance) {
if (direction == 'N') {
y++;
} else if (direction == 'E') {
x++;
} else if (direction == 'S') {
y--;
} else {
x--;
}
stone -= map[x][y];
map[x][y] = 0;
}
}
if (!stone)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
} | replace | 17 | 18 | 17 | 18 | 0 | |
p01125 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
vector<vector<int>> g(20, vector<int>(20));
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
g[x][y] += 1;
}
int r;
cin >> r;
int x = 10;
int y = 10;
int sum = 0;
while (r--) {
char d;
int c;
cin >> d >> c;
int dx = 0;
int dy = 0;
if (d == 'N')
dy++;
if (d == 'S')
dy--;
if (d == 'E')
dx++;
if (d == 'W')
dx--;
for (int i = 0; i < c; i++) {
x += dx;
y += dy;
if (g[x][y] > 0) {
sum += g[x][y];
g[x][y] = 0;
}
}
}
if (n == sum)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n, n) {
vector<vector<int>> g(21, vector<int>(21));
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
g[x][y] += 1;
}
int r;
cin >> r;
int x = 10;
int y = 10;
int sum = 0;
while (r--) {
char d;
int c;
cin >> d >> c;
int dx = 0;
int dy = 0;
if (d == 'N')
dy++;
if (d == 'S')
dy--;
if (d == 'E')
dx++;
if (d == 'W')
dx--;
for (int i = 0; i < c; i++) {
x += dx;
y += dy;
if (g[x][y] > 0) {
sum += g[x][y];
g[x][y] = 0;
}
}
}
if (n == sum)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p01125 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
if (n == 0)
break;
int m, count = n, p[20][20];
for (int i = 0; i < 20; ++i)
for (int j = 0; j < 20; ++j)
p[i][j] = 0;
for (int i = 0, x, y; i < n; ++i) {
cin >> x >> y;
p[x][y] = 1;
}
cin >> m;
for (int i = 0, d, cx = 10, cy = 10; i < m; ++i) {
string s;
cin >> s;
cin >> d;
if (s == "N") {
for (int j = 0; j < d; ++j) {
++cy;
if (p[cx][cy] == 1) {
count--;
p[cx][cy] = 0;
}
}
} else if (s == "E") {
for (int j = 0; j < d; ++j) {
++cx;
if (p[cx][cy] == 1) {
count--;
p[cx][cy] = 0;
}
}
} else if (s == "S") {
for (int j = 0; j < d; ++j) {
--cy;
if (p[cx][cy] == 1) {
count--;
p[cx][cy] = 0;
}
}
} else if (s == "W") {
for (int j = 0; j < d; ++j) {
--cx;
if (p[cx][cy] == 1) {
count--;
p[cx][cy] = 0;
}
}
}
}
if (count == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n;
while (cin >> n) {
if (n == 0)
break;
int m, count = n, p[21][21];
for (int i = 0; i < 21; ++i)
for (int j = 0; j < 21; ++j)
p[i][j] = 0;
for (int i = 0, x, y; i < n; ++i) {
cin >> x >> y;
p[x][y] = 1;
}
cin >> m;
for (int i = 0, d, cx = 10, cy = 10; i < m; ++i) {
string s;
cin >> s;
cin >> d;
if (s == "N") {
for (int j = 0; j < d; ++j) {
++cy;
if (p[cx][cy] == 1) {
count--;
p[cx][cy] = 0;
}
}
} else if (s == "E") {
for (int j = 0; j < d; ++j) {
++cx;
if (p[cx][cy] == 1) {
count--;
p[cx][cy] = 0;
}
}
} else if (s == "S") {
for (int j = 0; j < d; ++j) {
--cy;
if (p[cx][cy] == 1) {
count--;
p[cx][cy] = 0;
}
}
} else if (s == "W") {
for (int j = 0; j < d; ++j) {
--cx;
if (p[cx][cy] == 1) {
count--;
p[cx][cy] = 0;
}
}
}
}
if (count == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
} | replace | 7 | 10 | 7 | 10 | 0 | |
p01125 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
int h[21][21];
lp(i, 21) {
lp(j, 21) { h[i][j] = 0; }
}
lp(i, n) {
int a, b;
cin >> a >> b;
h[a][b] = 1;
}
int m, count = 0;
cin >> m;
int nowx = 10, nowy = 10;
if (h[nowx][nowy] == 1) {
count++;
h[nowx][nowy] = 0;
}
lp(i, m) {
char a;
int b;
cin >> a >> b;
if (a == 'N') {
lp(j, b) {
nowy++;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'S') {
lp(j, b) {
nowy--;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'E') {
lp(j, b) {
nowx++;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'W') {
lp(j, b) {
nowx++;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
}
if (count == n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
int main() {
while (1) {
int n;
cin >> n;
if (n == 0)
break;
int h[21][21];
lp(i, 21) {
lp(j, 21) { h[i][j] = 0; }
}
lp(i, n) {
int a, b;
cin >> a >> b;
h[a][b] = 1;
}
int m, count = 0;
cin >> m;
int nowx = 10, nowy = 10;
if (h[nowx][nowy] == 1) {
count++;
h[nowx][nowy] = 0;
}
lp(i, m) {
char a;
int b;
cin >> a >> b;
if (a == 'N') {
lp(j, b) {
nowy++;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'S') {
lp(j, b) {
nowy--;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'E') {
lp(j, b) {
nowx++;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
if (a == 'W') {
lp(j, b) {
nowx--;
if (h[nowx][nowy] == 1) {
h[nowx][nowy] = 0;
count++;
}
}
}
}
if (count == n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| replace | 59 | 60 | 59 | 60 | 0 | |
p01125 | C++ | Runtime Error | #include <iostream>
#define N 21
using namespace std;
int main() {
int n, m, x, y, rx, ry, l, cnt, d[N][N];
char c;
while (1) {
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
d[i][j] = 0;
cin >> n;
if (!n)
break;
for (int i = 0; i < n; i++)
cin >> x >> y, d[N - y - 1][x] = 1;
cin >> m;
rx = ry = 10;
cnt = 0;
while (m--) {
cin >> c >> l;
while (l--) {
if (c == 'N')
ry--;
if (c == 'E')
rx++;
if (c == 'S')
ry++;
if (c == 'W')
rx++;
if (d[ry][rx])
d[ry][rx] = 0, cnt++;
}
}
if (cnt == n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | #include <iostream>
#define N 21
using namespace std;
int main() {
int n, m, x, y, rx, ry, l, cnt, d[N][N];
char c;
while (1) {
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
d[i][j] = 0;
cin >> n;
if (!n)
break;
for (int i = 0; i < n; i++)
cin >> x >> y, d[N - y - 1][x] = 1;
cin >> m;
rx = ry = 10;
cnt = 0;
while (m--) {
cin >> c >> l;
while (l--) {
if (c == 'N')
ry--;
if (c == 'E')
rx++;
if (c == 'S')
ry++;
if (c == 'W')
rx--;
if (d[ry][rx])
d[ry][rx] = 0, cnt++;
}
}
if (cnt == n)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p01125 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#define MAX 32
using namespace std;
int main(void) {
while (1) {
int n, m;
int x[MAX], y[MAX];
int m_x = 10, m_y = 10;
char d;
int l;
bool moved[MAX][MAX] = {false};
moved[10][10] = true;
bool collect = true;
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d %d", &x[i], &y[i]);
}
scanf("%d", &m);
for (int i = 0; i < m; i++) {
cin >> d >> l;
if (d == 'N') {
for (int j = 0; j <= l; j++) {
moved[m_x][m_y + j] = true;
}
m_y += l;
}
if (d == 'E') {
for (int j = 0; j <= l; j++) {
moved[m_x + j][m_y] = true;
}
m_x += l;
}
if (d == 'S') {
for (int j = 0; j <= l; j++) {
moved[m_x][m_y - j] = true;
}
m_y -= l;
}
if (d == 'W') {
for (int j = 0; j <= l; j++) {
moved[m_x - j][m_y] = true;
}
m_y -= l;
}
}
for (int i = 0; i < n; i++) {
if (!moved[x[i]][y[i]])
collect = false;
}
printf("%s\n", collect ? "Yes" : "No");
}
return 0;
} | #include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#define MAX 32
using namespace std;
int main(void) {
while (1) {
int n, m;
int x[MAX], y[MAX];
int m_x = 10, m_y = 10;
char d;
int l;
bool moved[MAX][MAX] = {false};
moved[10][10] = true;
bool collect = true;
scanf("%d", &n);
if (n == 0)
break;
for (int i = 0; i < n; i++) {
scanf("%d %d", &x[i], &y[i]);
}
scanf("%d", &m);
for (int i = 0; i < m; i++) {
cin >> d >> l;
if (d == 'N') {
for (int j = 0; j <= l; j++) {
moved[m_x][m_y + j] = true;
}
m_y += l;
}
if (d == 'E') {
for (int j = 0; j <= l; j++) {
moved[m_x + j][m_y] = true;
}
m_x += l;
}
if (d == 'S') {
for (int j = 0; j <= l; j++) {
moved[m_x][m_y - j] = true;
}
m_y -= l;
}
if (d == 'W') {
for (int j = 0; j <= l; j++) {
moved[m_x - j][m_y] = true;
}
m_x -= l;
}
}
for (int i = 0; i < n; i++) {
if (!moved[x[i]][y[i]])
collect = false;
}
printf("%s\n", collect ? "Yes" : "No");
}
return 0;
} | replace | 51 | 52 | 51 | 52 | 0 | |
p01125 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#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;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rep1(i, x) for (int i = 1; i <= (x); ++i)
#define rrep(i, x) for (int i = (x)-1; i >= 0; --i)
#define rrep1(i, x) for (int i = (x); i >= 1; --i)
#define FOR(i, a, x) for (int i = (a); i < (x); ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai \
ios::sync_with_stdio(false); \
cin.tie(0)
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> T get() {
T a;
cin >> a;
return a;
}
template <typename T> T rev(T a) {
reverse(all(a));
return a;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
rep(i, vec.size()) is >> vec[i];
return is;
}
template <typename T> vector<T> &sort(vector<T> &a) {
sort(all(a));
return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
bool fld[21][21];
signed main() {
int N;
while (cin >> N, N) {
memset(fld, false, sizeof(fld));
rep(i, N) {
int x, y;
cin >> x >> y;
fld[y][x] = true;
}
int cnt = 0;
pii now = pii(10, 10);
if (fld[now.fst][now.scd]) {
fld[now.fst][now.scd] = false;
cnt++;
}
int M;
cin >> M;
rep(i, M) {
char c;
cin >> c;
int v;
cin >> v;
rep(j, v) {
if (c == 'N')
now.fst++;
if (c == 'E')
now.scd++;
if (c == 'S')
now.fst++;
if (c == 'W')
now.scd--;
if (fld[now.fst][now.scd]) {
fld[now.fst][now.scd] = false;
cnt++;
}
}
}
if (cnt == N) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#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;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rep1(i, x) for (int i = 1; i <= (x); ++i)
#define rrep(i, x) for (int i = (x)-1; i >= 0; --i)
#define rrep1(i, x) for (int i = (x); i >= 1; --i)
#define FOR(i, a, x) for (int i = (a); i < (x); ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define omajinai \
ios::sync_with_stdio(false); \
cin.tie(0)
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> T get() {
T a;
cin >> a;
return a;
}
template <typename T> T rev(T a) {
reverse(all(a));
return a;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
rep(i, vec.size()) is >> vec[i];
return is;
}
template <typename T> vector<T> &sort(vector<T> &a) {
sort(all(a));
return a;
}
const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;
bool fld[21][21];
signed main() {
int N;
while (cin >> N, N) {
memset(fld, false, sizeof(fld));
rep(i, N) {
int x, y;
cin >> x >> y;
fld[y][x] = true;
}
int cnt = 0;
pii now = pii(10, 10);
if (fld[now.fst][now.scd]) {
fld[now.fst][now.scd] = false;
cnt++;
}
int M;
cin >> M;
rep(i, M) {
char c;
cin >> c;
int v;
cin >> v;
rep(j, v) {
if (c == 'N')
now.fst++;
if (c == 'E')
now.scd++;
if (c == 'S')
now.fst--;
if (c == 'W')
now.scd--;
if (fld[now.fst][now.scd]) {
fld[now.fst][now.scd] = false;
cnt++;
}
}
}
if (cnt == N) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
} | replace | 116 | 117 | 116 | 117 | 0 | |
p01126 | C++ | Runtime Error | #include <cstdio>
#include <map>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
int main() {
while (true) {
int n, m, a;
scanf("%d%d%d", &n, &m, &a);
if (n == 0 || m == 0 || a == 0) {
break;
}
multimap<int, pii, greater<int>> field;
for (int i = 0; i < m; i++) {
int h, p, q;
scanf("%d%d%d", &h, &p, &q);
field.insert(pipii(h, pii(p, q)));
}
for (multimap<int, pii, greater<int>>::iterator it = field.begin();
it != field.end(); it++) {
pii item = (*it).second;
if (a == item.first) {
a = item.second;
} else if (a == item.second) {
a = item.first;
}
}
printf("%d\n", a);
}
return true;
} | #include <cstdio>
#include <map>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
int main() {
while (true) {
int n, m, a;
scanf("%d%d%d", &n, &m, &a);
if (n == 0 || m == 0 || a == 0) {
break;
}
multimap<int, pii, greater<int>> field;
for (int i = 0; i < m; i++) {
int h, p, q;
scanf("%d%d%d", &h, &p, &q);
field.insert(pipii(h, pii(p, q)));
}
for (multimap<int, pii, greater<int>>::iterator it = field.begin();
it != field.end(); it++) {
pii item = (*it).second;
if (a == item.first) {
a = item.second;
} else if (a == item.second) {
a = item.first;
}
}
printf("%d\n", a);
}
return 0;
} | replace | 31 | 32 | 31 | 32 | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.