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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p00728 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
void remove_minmax(vector<int> &data) {
int max = 0;
int min = 1000000;
int min_i = 0;
int max_i = 0;
int count = 0;
vector<int>::iterator it = data.begin();
while (it != data.end()) {
if (*it < min) {
min = *it;
min_i = count;
}
if (*it > max) {
max = *it;
max_i = count;
}
++count;
++it;
}
data[max_i] = 0;
data[min_i] = 0;
}
int main(void) {
int n;
while (cin >> n) {
if (n == 0) {
return -1;
}
vector<int> data;
for (int i = 0; i < n; ++i) {
int num;
cin >> num;
data.push_back(num);
}
remove_minmax(data);
int total =
floor((double)accumulate(data.begin(), data.end(), 0) / (n - 2));
cout << total << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
void remove_minmax(vector<int> &data) {
int max = 0;
int min = 1000000;
int min_i = 0;
int max_i = 0;
int count = 0;
vector<int>::iterator it = data.begin();
while (it != data.end()) {
if (*it < min) {
min = *it;
min_i = count;
}
if (*it > max) {
max = *it;
max_i = count;
}
++count;
++it;
}
data[max_i] = 0;
data[min_i] = 0;
}
int main(void) {
int n;
while (cin >> n) {
if (n == 0) {
return 0;
}
vector<int> data;
for (int i = 0; i < n; ++i) {
int num;
cin >> num;
data.push_back(num);
}
remove_minmax(data);
int total =
floor((double)accumulate(data.begin(), data.end(), 0) / (n - 2));
cout << total << endl;
}
return 0;
} | replace | 35 | 36 | 35 | 36 | 255 | |
p00728 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int in, a, maxer = 0, miner = 1000;
int sum = 0;
int i = 0;
double ave = 0.0;
while (scanf("%d", &in) != 0) {
for (i = 0; i < in; i++) {
cin >> a;
maxer = max(a, maxer);
miner = min(a, miner);
sum += a;
}
sum = sum - maxer - miner;
ave = sum / (in - 2);
cout << floor(ave) << endl;
sum = maxer = ave = 0;
miner = 1000;
}
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int in, a, maxer = 0, miner = 1000;
int sum = 0;
int i = 0;
double ave = 0.0;
while (cin >> in, in) {
for (i = 0; i < in; i++) {
cin >> a;
maxer = max(a, maxer);
miner = min(a, miner);
sum += a;
}
sum = sum - maxer - miner;
ave = sum / (in - 2);
cout << floor(ave) << endl;
sum = maxer = ave = 0;
miner = 1000;
}
} | replace | 11 | 12 | 11 | 12 | TLE | |
p00728 | C++ | Time Limit Exceeded | #include <cstdio>
#include <iostream>
#define S 20
int main(void) {
int a[S];
int i;
int n, max, min, sum = 0;
for (;;) {
max = 0, min = 1000, sum = 0;
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++) {
if (max < a[i])
max = a[i];
if (min > a[i])
min = a[i];
}
for (i = 0; i < n; i++) {
sum += a[i];
}
sum = sum - max - min;
printf("%d\n", sum / (n - 2));
}
return 0;
} | #include <cstdio>
#include <iostream>
#define S 100
int main(void) {
int a[S];
int i;
int n, max, min, sum = 0;
for (;;) {
max = 0, min = 1000, sum = 0;
scanf("%d", &n);
if (n == 0)
break;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++) {
if (max < a[i])
max = a[i];
if (min > a[i])
min = a[i];
}
for (i = 0; i < n; i++) {
sum += a[i];
}
sum = sum - max - min;
printf("%d\n", sum / (n - 2));
}
return 0;
} | replace | 2 | 3 | 2 | 3 | TLE | |
p00728 | C++ | Runtime Error |
#include <algorithm>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 25
#define pb push_back
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;
int main(int argc, char *argv[]) {
int ninzu = 0;
while (cin >> ninzu) {
int ans = 0;
int i = 0;
int temp = 0;
int a = 0;
vector<int> s;
for (i = 0; i < ninzu; i++) {
cin >> a;
if (temp < a) {
temp = a;
}
s.push_back(a);
}
sort(ALL(s));
for (i = 0; i < s.size() - 1; i++)
ans += s[i];
ans = (ans - s[0]) / (i - 1);
cout << ans << endl;
ans = 0;
}
return 0;
} |
#include <algorithm>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define F(i, j, k) fill(i[0], i[0] + j * j, k)
#define P(p) cout << (p) << endl;
#define EXIST(s, e) ((s).find(e) != (s).end())
#define INF 1 << 25
#define pb push_back
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;
int main(int argc, char *argv[]) {
int ninzu = 0;
while (cin >> ninzu, ninzu) {
int ans = 0;
int i = 0;
int temp = 0;
int a = 0;
vector<int> s;
for (i = 0; i < ninzu; i++) {
cin >> a;
if (temp < a) {
temp = a;
}
s.push_back(a);
}
sort(ALL(s));
for (i = 0; i < s.size() - 1; i++)
ans += s[i];
ans = (ans - s[0]) / (i - 1);
cout << ans << endl;
ans = 0;
}
return 0;
} | replace | 33 | 34 | 33 | 34 | -11 | |
p00728 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
using namespace std;
int main() {
int n, s[120], count;
;
while (true) {
cin >> n;
count = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
count += s[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = n - 1; j > i; j--) {
if (s[j] < s[j - 1]) {
int tmp = s[j];
s[j] = s[j - 1];
s[j - 1] = tmp;
}
}
}
count -= s[0];
count -= s[n - 1];
cout << count / (n - 2) << endl;
}
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
int main() {
int n, s[120], count;
;
while (true) {
cin >> n;
if (n == 0)
break;
count = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
count += s[i];
}
for (int i = 0; i < n - 1; i++) {
for (int j = n - 1; j > i; j--) {
if (s[j] < s[j - 1]) {
int tmp = s[j];
s[j] = s[j - 1];
s[j - 1] = tmp;
}
}
}
count -= s[0];
count -= s[n - 1];
cout << count / (n - 2) << endl;
}
return 0;
}
| insert | 8 | 8 | 8 | 10 | TLE | |
p00728 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
while (1) {
int judge;
int maxscore = 0;
int minscore = 0;
cin >> judge;
if (judge != 0) {
int score[judge];
for (int i = 0; i < judge; i++) {
cin >> score[i];
if (score[i] > maxscore) {
maxscore = score[i];
}
if (score[i] < minscore) {
minscore = score[i];
}
if (i == 0) {
minscore = score[0];
}
}
int lastscore = 0;
for (int j = 0; j < judge; j++) {
lastscore += score[j];
}
lastscore = (lastscore - maxscore - minscore) / (judge - 2);
cout << lastscore << endl;
}
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
while (1) {
int judge;
int maxscore = 0;
int minscore = 0;
cin >> judge;
if (judge != 0) {
int score[judge];
for (int i = 0; i < judge; i++) {
cin >> score[i];
if (score[i] > maxscore) {
maxscore = score[i];
}
if (score[i] < minscore) {
minscore = score[i];
}
if (i == 0) {
minscore = score[0];
}
}
int lastscore = 0;
for (int j = 0; j < judge; j++) {
lastscore += score[j];
}
lastscore = (lastscore - maxscore - minscore) / (judge - 2);
cout << lastscore << endl;
} else
break;
}
return 0;
} | replace | 28 | 29 | 28 | 30 | TLE | |
p00728 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int n, a[21], b[21];
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int max = 0, min = 10001;
for (int i = 0; i < n; i++) {
if (max < a[i]) {
max = a[i];
}
if (min > a[i]) {
min = a[i];
}
}
int sum = 0;
for (int i = 0; i < n; i++) {
sum += a[i];
}
sum -= (max + min);
cout << sum / (n - 2) << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n, a[101], b[101];
while (1) {
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int max = 0, min = 10001;
for (int i = 0; i < n; i++) {
if (max < a[i]) {
max = a[i];
}
if (min > a[i]) {
min = a[i];
}
}
int sum = 0;
for (int i = 0; i < n; i++) {
sum += a[i];
}
sum -= (max + min);
cout << sum / (n - 2) << endl;
}
return 0;
} | replace | 4 | 5 | 4 | 5 | TLE | |
p00728 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int n[100];
int max[2] = {0, -1}, min[2] = {1000, -1}, sum = 0;
int m;
while (true) {
cin >> m;
max[0] = 0;
max[1] = -1;
min[0] = 1000;
min[1] = -1;
sum = 0;
for (int i = 0; i < m; i++) {
cin >> n[i];
if (n[i] > max[0]) {
max[1] = i;
max[0] = n[i];
}
if (n[i] < min[0]) {
min[1] = i;
min[0] = n[i];
}
}
for (int i = 0; i < m; i++) {
if (max[1] != i && min[1] != i) {
sum += n[i];
}
}
cout << sum / (m - 2) << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n[100];
int max[2] = {0, -1}, min[2] = {1000, -1}, sum = 0;
int m;
while (true) {
cin >> m;
if (m == 0) {
break;
}
max[0] = 0;
max[1] = -1;
min[0] = 1000;
min[1] = -1;
sum = 0;
for (int i = 0; i < m; i++) {
cin >> n[i];
if (n[i] > max[0]) {
max[1] = i;
max[0] = n[i];
}
if (n[i] < min[0]) {
min[1] = i;
min[0] = n[i];
}
}
for (int i = 0; i < m; i++) {
if (max[1] != i && min[1] != i) {
sum += n[i];
}
}
cout << sum / (m - 2) << endl;
}
return 0;
} | insert | 9 | 9 | 9 | 12 | TLE | |
p00728 | C++ | Runtime Error | #include <cstdio>
int main() {
int n, s[20], i;
int max, min, ava, sum;
while (1) {
max = 0;
min = 1000;
sum = 0;
scanf("%d", &n);
if (n == 0) {
break;
}
for (i = 0; i < n; i++) {
scanf("%d", &s[i]);
if (max < s[i]) {
max = s[i];
}
if (min > s[i]) {
min = s[i];
}
sum += s[i];
}
sum -= max;
sum -= min;
ava = sum / (n - 2);
printf("%d\n", ava);
}
return 0;
}
| #include <cstdio>
int main() {
int n, s[100], i;
int max, min, ava, sum;
while (1) {
max = 0;
min = 1000;
sum = 0;
scanf("%d", &n);
if (n == 0) {
break;
}
for (i = 0; i < n; i++) {
scanf("%d", &s[i]);
if (max < s[i]) {
max = s[i];
}
if (min > s[i]) {
min = s[i];
}
sum += s[i];
}
sum -= max;
sum -= min;
ava = sum / (n - 2);
printf("%d\n", ava);
}
return 0;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p00728 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, a[21], t;
while (cin >> n && n) {
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
t = 0;
for (int i = 1; i < n - 1; i++) {
t += a[i];
}
cout << (t / (n - 2)) << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, a[101], t;
while (cin >> n && n) {
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
t = 0;
for (int i = 1; i < n - 1; i++) {
t += a[i];
}
cout << (t / (n - 2)) << endl;
}
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p00728 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
int n;
int point[20], average;
while (1) {
average = 0;
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> point[i];
}
sort(point, point + n);
for (int i = 1; i < n - 1; i++) {
average += point[i];
}
average /= (n - 2);
cout << average << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
int n;
int point[100], average;
while (1) {
average = 0;
cin >> n;
if (n == 0)
break;
for (int i = 0; i < n; i++) {
cin >> point[i];
}
sort(point, point + n);
for (int i = 1; i < n - 1; i++) {
average += point[i];
}
average /= (n - 2);
cout << average << endl;
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p00728 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)
using namespace std;
int main() {
int n;
while (cin >> n && n) {
vector<int> scr(n);
for (int i = 0; i < n; i++) {
cin >> scr[i];
}
int sum = 0;
int _max = scr[0];
int _min = scr[0];
for (int s : scr) {
sum += s;
_min = min(_min, s);
_max = max(_max, s);
}
sum -= _max;
sum -= _min;
cout << sum / (n - 2) << endl;
}
return 0;
} | #include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)
using namespace std;
int main() {
int n;
while (cin >> n) {
if (!n)
break;
vector<int> scr(n);
for (int i = 0; i < n; i++) {
cin >> scr[i];
}
int sum = 0;
int _max = scr[0];
int _min = scr[0];
for (int s : scr) {
sum += s;
_min = min(_min, s);
_max = max(_max, s);
}
sum -= _max;
sum -= _min;
cout << sum / (n - 2) << endl;
}
return 0;
} | replace | 26 | 27 | 26 | 30 | TLE | |
p00728 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int n;
cin >> n;
vector<int> v;
int a;
rep(i, n) {
cin >> a;
v.push_back(a);
}
sort(ALL(v));
int sum = 0;
for (int i = 1; i < n - 1; i++) {
sum += v[i];
}
sum = sum / (n - 2);
cout << sum << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int n;
cin >> n;
if (n == 0)
break;
vector<int> v;
int a;
rep(i, n) {
cin >> a;
v.push_back(a);
}
sort(ALL(v));
int sum = 0;
for (int i = 1; i < n - 1; i++) {
sum += v[i];
}
sum = sum / (n - 2);
cout << sum << endl;
}
}
| insert | 13 | 13 | 13 | 15 | TLE | |
p00728 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
typedef long long i64;
int main() {
while (true) {
int n;
vector<int> a;
cin >> n;
rep(i, n) {
int b;
cin >> b;
a.push_back(b);
}
sort(a.begin(), a.end());
int total = 0;
repi(i, 1, n - 1) { total += a[i]; }
cout << total / (n - 2) << endl;
;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
typedef long long i64;
int main() {
while (true) {
int n;
vector<int> a;
cin >> n;
if (n == 0)
break;
rep(i, n) {
int b;
cin >> b;
a.push_back(b);
}
sort(a.begin(), a.end());
int total = 0;
repi(i, 1, n - 1) { total += a[i]; }
cout << total / (n - 2) << endl;
;
}
return 0;
} | insert | 10 | 10 | 10 | 12 | TLE | |
p00729 | C++ | Runtime Error | #include <functional>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define MAX 1010
#include <queue>
using namespace std;
typedef pair<int, int> P;
int main() {
int e, q, t, n, m, s, p;
while (cin >> e >> q, e || q) {
vector<P> tab[MAX];
cin >> p;
for (int i = 0; i < p; i++) {
cin >> t >> n >> m >> s;
tab[m - 1].push_back(P(t, s));
}
int now, t1, t2;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t1 >> t2 >> m;
now = t1;
int ans = 0, sum = 0;
int j;
m--;
for (j = 0; j < tab[m].size() && tab[m][j].first < t2; j++) {
if (!tab[m][j].second) {
if (sum > 0 && tab[m][j].first >= t1 && tab[m][j].first < t2) {
ans += tab[m][j].first - now;
}
sum--;
if (tab[m][j].first > t1 && tab[m][j].first < t2)
now = tab[m][j].first;
} else if (tab[m][j].second) {
if (sum > 0 && tab[m][j].first > t1 && tab[m][j].first < t2) {
ans += tab[m][j].first - now;
}
sum++;
if (tab[m][j].first >= t1 && tab[m][j].first < t2)
now = tab[m][j].first;
}
}
if (sum > 0)
ans += t2 - now;
cout << ans << endl;
}
}
return 0;
} | #include <functional>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define MAX 10010
#include <queue>
using namespace std;
typedef pair<int, int> P;
int main() {
int e, q, t, n, m, s, p;
while (cin >> e >> q, e || q) {
vector<P> tab[MAX];
cin >> p;
for (int i = 0; i < p; i++) {
cin >> t >> n >> m >> s;
tab[m - 1].push_back(P(t, s));
}
int now, t1, t2;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t1 >> t2 >> m;
now = t1;
int ans = 0, sum = 0;
int j;
m--;
for (j = 0; j < tab[m].size() && tab[m][j].first < t2; j++) {
if (!tab[m][j].second) {
if (sum > 0 && tab[m][j].first >= t1 && tab[m][j].first < t2) {
ans += tab[m][j].first - now;
}
sum--;
if (tab[m][j].first > t1 && tab[m][j].first < t2)
now = tab[m][j].first;
} else if (tab[m][j].second) {
if (sum > 0 && tab[m][j].first > t1 && tab[m][j].first < t2) {
ans += tab[m][j].first - now;
}
sum++;
if (tab[m][j].first >= t1 && tab[m][j].first < t2)
now = tab[m][j].first;
}
}
if (sum > 0)
ans += t2 - now;
cout << ans << endl;
}
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p00729 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline bool cheak(int x, int y, int xMax, int yMax) {
return x >= 0 && y >= 0 && xMax > x && yMax > y;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef long long ll;
typedef unsigned long long ull;
#define For(i, a, b) for (int(i) = (a); i < (b); (i)++)
#define rep(i, n) For(i, 0, n)
#define clr(a) memset((a), 0, sizeof(a))
#define mclr(a) memset((a), -1, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (sizeof(a))
#define Fill(a, v) fill((int *)a, (int *)(a + (sz(a) / sz(*(a)))), v)
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int mod = 1000000007;
const int INF = 1e9;
int d[10001][2000];
int f[10001][1001];
int main() {
int N, M;
while (cin >> N >> M && N) {
int r;
cin >> r;
clr(d);
clr(f);
rep(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
if (s == 1) {
f[m][n] = t;
} else {
For(j, f[m][n], t) { d[m][j] = 1; }
}
}
int q;
cin >> q;
rep(i, q) {
int ts, te, m;
cin >> ts >> te >> m;
int ans = 0;
For(j, ts, te) {
if (d[m][j])
ans++;
}
cout << ans << endl;
}
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
inline bool cheak(int x, int y, int xMax, int yMax) {
return x >= 0 && y >= 0 && xMax > x && yMax > y;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef long long ll;
typedef unsigned long long ull;
#define For(i, a, b) for (int(i) = (a); i < (b); (i)++)
#define rep(i, n) For(i, 0, n)
#define clr(a) memset((a), 0, sizeof(a))
#define mclr(a) memset((a), -1, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (sizeof(a))
#define Fill(a, v) fill((int *)a, (int *)(a + (sz(a) / sz(*(a)))), v)
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int mod = 1000000007;
const int INF = 1e9;
bool d[10001][2000];
short f[10001][1001];
int main() {
int N, M;
while (cin >> N >> M && N) {
int r;
cin >> r;
clr(d);
clr(f);
rep(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
if (s == 1) {
f[m][n] = t;
} else {
For(j, f[m][n], t) { d[m][j] = 1; }
}
}
int q;
cin >> q;
rep(i, q) {
int ts, te, m;
cin >> ts >> te >> m;
int ans = 0;
For(j, ts, te) {
if (d[m][j])
ans++;
}
cout << ans << endl;
}
}
return 0;
} | replace | 53 | 55 | 53 | 55 | MLE | |
p00729 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define int long long
typedef pair<int, int> P;
//-----------------------------------------------------------------------
int N, M, R, Q;
int A[1005][1005]; // 生徒番号,時間
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (cin >> N >> M, N) {
memset(A, 0, sizeof(A));
cin >> R;
REP(i, R) {
int t, n, m, s;
cin >> t >> n >> m >> s;
t -= 540;
n--;
m--;
if (s)
A[m][t]++;
else
A[m][t]--;
}
REP(i, M) {
REP(j, 1000) { A[i][j + 1] += A[i][j]; }
}
cin >> Q;
REP(i, Q) {
int s, e, m;
cin >> s >> e >> m;
s -= 540;
e -= 540;
m--;
int res = 0;
for (int i = s; i < e; i++) {
res += (A[m][i] >= 1);
}
cout << res << endl;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define int long long
typedef pair<int, int> P;
//-----------------------------------------------------------------------
int N, M, R, Q;
int A[10000][1005]; // 生徒番号,時間
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (cin >> N >> M, N) {
memset(A, 0, sizeof(A));
cin >> R;
REP(i, R) {
int t, n, m, s;
cin >> t >> n >> m >> s;
t -= 540;
n--;
m--;
if (s)
A[m][t]++;
else
A[m][t]--;
}
REP(i, M) {
REP(j, 1000) { A[i][j + 1] += A[i][j]; }
}
cin >> Q;
REP(i, Q) {
int s, e, m;
cin >> s >> e >> m;
s -= 540;
e -= 540;
m--;
int res = 0;
for (int i = s; i < e; i++) {
res += (A[m][i] >= 1);
}
cout << res << endl;
}
}
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p00729 | C++ | Runtime Error | #include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define LL long long
#define CLR(a) memset((a), 0, sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) \
int str; \
std::cin >> str;
#define DEBUGING(str) cout << str << endl
using namespace std;
const LL MOD = 1000000007; // 10^9+7
const int INF = (1 << 30);
// 変数
struct Database {
int N, M, r, q;
vector<vector<int>> use;
Database() {
cin >> N >> M;
if (N == 0)
return;
use.resize(M + 1, vector<int>(60 * 24));
cin >> r;
REP(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
use[m][t] += (s == 1 ? 1 : -1);
}
REP(i, M + 1) REP(t, 60 * 24 - 1) use[i][t + 1] += use[i][t];
}
void query() {
int ts, te, m;
cin >> ts >> te >> m;
int res = 0;
FOR(t, ts, te) { res += (use[m][t] > 0 ? 1 : 0); }
cerr << "==========";
cout << res << endl;
}
};
// メイン関数
int main() {
while (true) {
Database base;
if (base.N == 0)
break;
int q;
cin >> q;
REP(i, q) base.query();
}
return 0;
}
| #include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define LL long long
#define CLR(a) memset((a), 0, sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) \
int str; \
std::cin >> str;
#define DEBUGING(str) cout << str << endl
using namespace std;
const LL MOD = 1000000007; // 10^9+7
const int INF = (1 << 30);
// 変数
struct Database {
int N, M, r, q;
vector<vector<int>> use;
Database() {
cin >> N >> M;
if (N == 0)
return;
use.resize(M + 1, vector<int>(60 * 24));
cin >> r;
REP(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
use[m][t] += (s == 1 ? 1 : -1);
}
REP(i, M + 1) REP(t, 60 * 24 - 1) use[i][t + 1] += use[i][t];
}
void query() {
int ts, te, m;
cin >> ts >> te >> m;
int res = 0;
FOR(t, ts, te) { res += (use[m][t] > 0 ? 1 : 0); }
// cerr << "==========";
cout << res << endl;
}
};
// メイン関数
int main() {
while (true) {
Database base;
if (base.N == 0)
break;
int q;
cin >> q;
REP(i, q) base.query();
}
return 0;
}
| replace | 54 | 55 | 54 | 55 | 0 | ========================================================================================== |
p00729 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
while (1) { // start
int N, M, r;
// N;PC数 M;学生数
cin >> N >> M;
if (N == 0 and M == 0)
break;
cin >> r;
// 学生数、 時間
int data[1004][721];
for (int j = 0; j < 1004; j++) {
for (int k = 0; k < 721; k++)
data[j][k] = 0;
}
for (int i = 0; i < r; i++) {
// t;時刻、 n;PC番号 m;学生番号 s;1ならログイン、0ならログアウト(配列中では逆)
int t, n, m;
bool s;
cin >> t >> n >> m >> s;
if (s)
data[m][t - 539] += 1;
else
data[m][t - 539] += -1;
}
// 累積和をとる
for (int i = 0; i <= M; i++) {
for (int k = 1; k < 721; k++)
data[i][k] = data[i][k] + data[i][k - 1];
}
// クエリを取得
int qn;
cin >> qn;
for (int i = 0; i < qn; i++) {
int ts, tt, sn;
cin >> ts >> tt >> sn;
// 学生について調査する
int ans = 0;
for (int j = ts - 539; j < tt - 539; j++) {
if (data[sn][j])
ans++;
}
cout << ans << endl;
}
} // end
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
while (1) { // start
int N, M, r;
// N;PC数 M;学生数
cin >> N >> M;
if (N == 0 and M == 0)
break;
cin >> r;
// 学生数、 時間
int data[10004][721];
for (int j = 0; j < 10004; j++) {
for (int k = 0; k < 721; k++)
data[j][k] = 0;
}
for (int i = 0; i < r; i++) {
// t;時刻、 n;PC番号 m;学生番号 s;1ならログイン、0ならログアウト(配列中では逆)
int t, n, m;
bool s;
cin >> t >> n >> m >> s;
if (s)
data[m][t - 539] += 1;
else
data[m][t - 539] += -1;
}
// 累積和をとる
for (int i = 0; i <= M; i++) {
for (int k = 1; k < 721; k++)
data[i][k] = data[i][k] + data[i][k - 1];
}
// クエリを取得
int qn;
cin >> qn;
for (int i = 0; i < qn; i++) {
int ts, tt, sn;
cin >> ts >> tt >> sn;
// 学生について調査する
int ans = 0;
for (int j = ts - 539; j < tt - 539; j++) {
if (data[sn][j])
ans++;
}
cout << ans << endl;
}
} // end
return 0;
}
| replace | 14 | 16 | 14 | 16 | 0 | |
p00729 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define int long long
#define MOD7 1000000007
#define MOD9 1000000009
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
int nextInt() {
int a;
cin >> a;
return a;
}
char nextChar() {
char a;
cin >> a;
return a;
}
double nextDouble() {
double a;
cin >> a;
return a;
}
string nextString() {
string a;
cin >> a;
return a;
}
void inputVector(vector<int> &v, int &n) {
rep(i, n) { v.push_back(nextInt()); }
}
void inputVector(vector<double> &v, int &n) {
rep(i, n) { v.push_back(nextDouble()); }
}
void inputVector(vector<string> &v, int &n) {
rep(i, n) { v.push_back(nextString()); }
}
int memo[1270][10010];
signed main() {
int N, M;
while (cin >> N >> M) {
if (!N)
break;
memset(memo, 0, sizeof(memo));
int r;
cin >> r;
rep(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
m--;
if (s == 0)
memo[t][m]--;
else
memo[t][m]++;
}
REP(i, 500, 1265) {
rep(j, M) { memo[i][j] += memo[i - 1][j]; }
}
REP(i, 500, 1265) {
rep(j, M) { memo[i][j] = memo[i][j] > 0; }
}
REP(i, 500, 1265) {
rep(j, M) { memo[i][j] += memo[i - 1][j]; }
}
int q;
cin >> q;
rep(i, q) {
int ts, te, m;
cin >> ts >> te >> m;
m--;
cout << memo[te - 1][m] - memo[ts - 1][m] << endl;
}
}
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define MOD7 1000000007
#define MOD9 1000000009
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
int nextInt() {
int a;
cin >> a;
return a;
}
char nextChar() {
char a;
cin >> a;
return a;
}
double nextDouble() {
double a;
cin >> a;
return a;
}
string nextString() {
string a;
cin >> a;
return a;
}
void inputVector(vector<int> &v, int &n) {
rep(i, n) { v.push_back(nextInt()); }
}
void inputVector(vector<double> &v, int &n) {
rep(i, n) { v.push_back(nextDouble()); }
}
void inputVector(vector<string> &v, int &n) {
rep(i, n) { v.push_back(nextString()); }
}
int memo[1270][10010];
signed main() {
int N, M;
while (cin >> N >> M) {
if (!N)
break;
memset(memo, 0, sizeof(memo));
int r;
cin >> r;
rep(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
m--;
if (s == 0)
memo[t][m]--;
else
memo[t][m]++;
}
REP(i, 500, 1265) {
rep(j, M) { memo[i][j] += memo[i - 1][j]; }
}
REP(i, 500, 1265) {
rep(j, M) { memo[i][j] = memo[i][j] > 0; }
}
REP(i, 500, 1265) {
rep(j, M) { memo[i][j] += memo[i - 1][j]; }
}
int q;
cin >> q;
rep(i, q) {
int ts, te, m;
cin >> ts >> te >> m;
m--;
cout << memo[te - 1][m] - memo[ts - 1][m] << endl;
}
}
return 0;
} | delete | 16 | 17 | 16 | 16 | MLE | |
p00729 | C++ | Memory Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <class T> void chmin(T &t, T f) {
if (t > f)
t = f;
}
template <class T> void chmax(T &t, T f) {
if (t < f)
t = f;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
int login[10100][2000];
int main() {
int N, M;
while (cin >> N >> M, N) {
int r, q;
cin >> r;
int i;
memset(login, 0, sizeof(login));
for (i = 0; i < r; i++) {
int t, n, m, s;
cin >> t >> n >> m >> s;
login[m][t] += (s ? 1 : -1);
}
int j;
int l;
for (j = 0; j <= M; j++) {
l = 0;
for (i = 540; i <= 1260; i++) {
l += login[j][i];
login[j][i] = l;
// cout<<j<<" "<<i<<" "<<l<<endl;
}
}
cin >> q;
for (i = 0; i < q; i++) {
int ts, te, m;
cin >> ts >> te >> m;
int res = 0;
for (j = ts; j < te; j++) {
if (login[m][j] > 0)
res++;
}
cout << res << endl;
}
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long Int;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define mp make_pair
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << *i << " ";
cout << endl;
}
template <class T> void chmin(T &t, T f) {
if (t > f)
t = f;
}
template <class T> void chmax(T &t, T f) {
if (t < f)
t = f;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
int login[10100][1261];
int main() {
int N, M;
while (cin >> N >> M, N) {
int r, q;
cin >> r;
int i;
memset(login, 0, sizeof(login));
for (i = 0; i < r; i++) {
int t, n, m, s;
cin >> t >> n >> m >> s;
login[m][t] += (s ? 1 : -1);
}
int j;
int l;
for (j = 0; j <= M; j++) {
l = 0;
for (i = 540; i <= 1260; i++) {
l += login[j][i];
login[j][i] = l;
// cout<<j<<" "<<i<<" "<<l<<endl;
}
}
cin >> q;
for (i = 0; i < q; i++) {
int ts, te, m;
cin >> ts >> te >> m;
int res = 0;
for (j = ts; j < te; j++) {
if (login[m][j] > 0)
res++;
}
cout << res << endl;
}
}
return 0;
} | replace | 44 | 45 | 44 | 45 | MLE | |
p00729 | C++ | Runtime Error | #include <iostream>
#include <stdio.h>
using namespace std;
int n[1001][723] = {};
int main() {
int N, M;
while (1) {
cin >> N >> M;
if (N == 0 && M == 0)
break;
int r;
cin >> r;
for (int i = 0; i <= M; i++)
for (int j = 0; j < 722; j++)
n[i][j] = 0;
for (int i = 0; i < r; i++) {
int t, x, m, w;
cin >> t >> x >> m >> w;
t -= 540;
if (w == 1)
n[m][t] += 1;
else {
n[m][t] -= 1;
}
}
for (int i = 0; i <= M; i++)
for (int j = 0; j < 721; j++)
n[i][j + 1] += n[i][j];
int q, t1, t2, y;
cin >> q;
for (int i = 0; i < q; i++) {
cin >> t1 >> t2 >> y;
t1 -= 540;
t2 -= 540;
int c = 0;
for (int j = t1; j < t2; j++) {
if (n[y][j] != 0) {
c++;
} // cout<<j+540<<" "<<c<<n[y][j]<<endl;}
}
cout << c << endl;
}
}
return 0;
} | #include <iostream>
#include <stdio.h>
using namespace std;
int n[10001][723] = {};
int main() {
int N, M;
while (1) {
cin >> N >> M;
if (N == 0 && M == 0)
break;
int r;
cin >> r;
for (int i = 0; i <= M; i++)
for (int j = 0; j < 722; j++)
n[i][j] = 0;
for (int i = 0; i < r; i++) {
int t, x, m, w;
cin >> t >> x >> m >> w;
t -= 540;
if (w == 1)
n[m][t] += 1;
else {
n[m][t] -= 1;
}
}
for (int i = 0; i <= M; i++)
for (int j = 0; j < 721; j++)
n[i][j + 1] += n[i][j];
int q, t1, t2, y;
cin >> q;
for (int i = 0; i < q; i++) {
cin >> t1 >> t2 >> y;
t1 -= 540;
t2 -= 540;
int c = 0;
for (int j = t1; j < t2; j++) {
if (n[y][j] != 0) {
c++;
} // cout<<j+540<<" "<<c<<n[y][j]<<endl;}
}
cout << c << endl;
}
}
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p00729 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
int main(void) {
int N, M, r, t, n, m, s, log[17][721], q, ts, tg, i, j, k, flag[17], count;
;
while (1) {
scanf("%d%d", &N, &M);
if (N == 0 && M == 0)
break;
memset(log, 0, sizeof(log));
scanf("%d", &r);
for (i = 0; i < r; i++) {
scanf("%d%d%d%d", &t, &n, &m, &s);
if (s == 1)
log[n - 1][t - 540] = m;
else if (s == 0)
log[n - 1][t - 540] = -1;
}
memset(flag, 0, sizeof(flag));
for (i = 0; i < N; i++) {
for (j = 0; j <= 720; j++) {
if (log[i][j] && flag[i] == 0)
flag[i] = log[i][j];
else if (log[i][j] && flag[i] != 0)
flag[i] = 0;
if (flag[i] != 0)
log[i][j] = flag[i];
}
}
scanf("%d", &q);
for (i = 0; i < q; i++) {
scanf("%d%d%d", &ts, &tg, &m);
memset(flag, 0, sizeof(flag));
count = 0;
for (j = ts - 540; j <= tg - 540; j++) {
for (k = 0; k < N; k++) {
if (flag[k]) {
count++;
break;
}
}
for (k = 0; k < N; k++) {
if (log[k][j] == m)
flag[k] = 1;
else if (log[k][j] != 0)
flag[k] = 0;
}
}
printf("%d\n", count);
}
}
return 0;
} | #include <stdio.h>
#include <string.h>
int main(void) {
int N, M, r, t, n, m, s, log[1000][721], q, ts, tg, i, j, k, flag[1000],
count;
;
while (1) {
scanf("%d%d", &N, &M);
if (N == 0 && M == 0)
break;
memset(log, 0, sizeof(log));
scanf("%d", &r);
for (i = 0; i < r; i++) {
scanf("%d%d%d%d", &t, &n, &m, &s);
if (s == 1)
log[n - 1][t - 540] = m;
else if (s == 0)
log[n - 1][t - 540] = -1;
}
memset(flag, 0, sizeof(flag));
for (i = 0; i < N; i++) {
for (j = 0; j <= 720; j++) {
if (log[i][j] && flag[i] == 0)
flag[i] = log[i][j];
else if (log[i][j] && flag[i] != 0)
flag[i] = 0;
if (flag[i] != 0)
log[i][j] = flag[i];
}
}
scanf("%d", &q);
for (i = 0; i < q; i++) {
scanf("%d%d%d", &ts, &tg, &m);
memset(flag, 0, sizeof(flag));
count = 0;
for (j = ts - 540; j <= tg - 540; j++) {
for (k = 0; k < N; k++) {
if (flag[k]) {
count++;
break;
}
}
for (k = 0; k < N; k++) {
if (log[k][j] == m)
flag[k] = 1;
else if (log[k][j] != 0)
flag[k] = 0;
}
}
printf("%d\n", count);
}
}
return 0;
} | replace | 4 | 5 | 4 | 6 | 0 | |
p00729 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n, m, r, q;
static int cnt[1000][1261];
while (cin >> n >> m, n) {
for (int i = 0; i < m; i++) {
for (int j = 0; j <= 1260; j++)
cnt[i][j] = 0;
}
cin >> r;
for (int i = 0; i < r; i++) {
int t, a, b, s;
cin >> t >> a >> b >> s;
b--;
if (s)
cnt[b][t]++;
else
cnt[b][t]--;
}
for (int i = 0; i < m; i++) {
for (int j = 1; j <= 1260; j++) {
cnt[i][j] += cnt[i][j - 1];
// if(j >= 774 && j <= 881) cout << cnt[i][j] << " ";
}
// cout << endl;
}
for (int i = 0; i < m; i++) {
for (int j = 1; j <= 1260; j++) {
if (cnt[i][j])
cnt[i][j] = 1;
}
}
for (int i = 0; i < m; i++) {
for (int j = 1; j <= 1260; j++) {
cnt[i][j] += cnt[i][j - 1];
}
}
cin >> q;
for (int i = 0; i < q; i++) {
int s, t, b;
cin >> s >> t >> b;
b--;
cout << cnt[b][t - 1] - cnt[b][s - 1] << endl;
}
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n, m, r, q;
static int cnt[10000][1261];
while (cin >> n >> m, n) {
for (int i = 0; i < m; i++) {
for (int j = 0; j <= 1260; j++)
cnt[i][j] = 0;
}
cin >> r;
for (int i = 0; i < r; i++) {
int t, a, b, s;
cin >> t >> a >> b >> s;
b--;
if (s)
cnt[b][t]++;
else
cnt[b][t]--;
}
for (int i = 0; i < m; i++) {
for (int j = 1; j <= 1260; j++) {
cnt[i][j] += cnt[i][j - 1];
// if(j >= 774 && j <= 881) cout << cnt[i][j] << " ";
}
// cout << endl;
}
for (int i = 0; i < m; i++) {
for (int j = 1; j <= 1260; j++) {
if (cnt[i][j])
cnt[i][j] = 1;
}
}
for (int i = 0; i < m; i++) {
for (int j = 1; j <= 1260; j++) {
cnt[i][j] += cnt[i][j - 1];
}
}
cin >> q;
for (int i = 0; i < q; i++) {
int s, t, b;
cin >> s >> t >> b;
b--;
cout << cnt[b][t - 1] - cnt[b][s - 1] << endl;
}
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p00729 | C++ | Memory Limit Exceeded | #include <cstring>
#include <iostream>
using namespace std;
int students[10001][800] = {};
int numlogin[10001] = {};
int sum[10001][800] = {};
int main() {
while (1) {
int N, M, r;
cin >> N >> M;
if (!N and !M)
break;
cin >> r;
memset(students, 0, sizeof(students));
memset(numlogin, 0, sizeof(numlogin));
memset(sum, 0, sizeof(sum));
// ?¨????
for (int i = 0; i < r; i++) { // 1000
int t, n, m, s;
cin >> t >> n >> m >> s;
t -= 540;
if (s == 0) { // ?????°??¢??????
numlogin[m]--;
if (numlogin[m] == 0) {
for (int i = t - 1; students[m][i] != 1 and t >= 0; i--) { // 1000
students[m][i] = 1;
}
}
} else { // ?????°??????
numlogin[m]++;
if (numlogin[m] == 1)
students[m][t] = 1;
}
}
// ?´???????
for (int i = 1; i <= M; i++) { // 100000
for (int j = 1; j <= 720; j++) { // 1000
sum[i][j] = sum[i][j - 1] + students[i][j];
}
}
// ??????
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int ts, te, id;
cin >> ts >> te >> id;
ts -= 540;
te -= 540;
cout << sum[id][te - 1] - sum[id][ts] + students[id][ts] << endl;
}
}
} | #include <cstring>
#include <iostream>
using namespace std;
int students[10001][750] = {};
int numlogin[10001] = {};
int sum[10001][800] = {};
int main() {
while (1) {
int N, M, r;
cin >> N >> M;
if (!N and !M)
break;
cin >> r;
memset(students, 0, sizeof(students));
memset(numlogin, 0, sizeof(numlogin));
memset(sum, 0, sizeof(sum));
// ?¨????
for (int i = 0; i < r; i++) { // 1000
int t, n, m, s;
cin >> t >> n >> m >> s;
t -= 540;
if (s == 0) { // ?????°??¢??????
numlogin[m]--;
if (numlogin[m] == 0) {
for (int i = t - 1; students[m][i] != 1 and t >= 0; i--) { // 1000
students[m][i] = 1;
}
}
} else { // ?????°??????
numlogin[m]++;
if (numlogin[m] == 1)
students[m][t] = 1;
}
}
// ?´???????
for (int i = 1; i <= M; i++) { // 100000
for (int j = 1; j <= 720; j++) { // 1000
sum[i][j] = sum[i][j - 1] + students[i][j];
}
}
// ??????
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int ts, te, id;
cin >> ts >> te >> id;
ts -= 540;
te -= 540;
cout << sum[id][te - 1] - sum[id][ts] + students[id][ts] << endl;
}
}
} | replace | 4 | 5 | 4 | 5 | MLE | |
p00729 | 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 rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << 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<ll, ll> PL;
typedef pair<P, ll> PPL;
#define INF INT_MAX / 3
#define MAX_N 1000
int use[1111][1300];
int N, M, r, q;
int main() {
cin.sync_with_stdio(false);
while (1) {
cin >> N >> M;
if (N == 0)
break;
memset(use, 0, sizeof(use));
cin >> r;
rep(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
n--;
m--;
if (s == 1) {
use[m][t] += 1;
} else {
use[m][t] -= 1;
}
}
rep(i, M) repl(j, 540, 1300) { use[i][j + 1] += use[i][j]; }
cin >> q;
rep(i, q) {
int ts, te, m;
cin >> ts >> te >> m;
m--;
int res = 0;
repl(j, ts, te) {
if (use[m][j] > 0)
res++;
}
cout << res << endl;
}
}
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 rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << 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<ll, ll> PL;
typedef pair<P, ll> PPL;
#define INF INT_MAX / 3
#define MAX_N 1000
int use[11111][1300];
int N, M, r, q;
int main() {
cin.sync_with_stdio(false);
while (1) {
cin >> N >> M;
if (N == 0)
break;
memset(use, 0, sizeof(use));
cin >> r;
rep(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
n--;
m--;
if (s == 1) {
use[m][t] += 1;
} else {
use[m][t] -= 1;
}
}
rep(i, M) repl(j, 540, 1300) { use[i][j + 1] += use[i][j]; }
cin >> q;
rep(i, q) {
int ts, te, m;
cin >> ts >> te >> m;
m--;
int res = 0;
repl(j, ts, te) {
if (use[m][j] > 0)
res++;
}
cout << res << endl;
}
}
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p00729 | C++ | Runtime Error | /* 2012-08-20T10:52:03 */
#define DEBUG_ON_
#define CONDITION true
using namespace std; /*{{{*/
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/time.h>
#include <vector>
#define INF (1e9)
static const double PI = acos(-1.0);
static const double EPS = 1e-10;
typedef long long int LL;
typedef unsigned long long int ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef complex<double> P;
#define FOR(i, b, e) for (typeof(b) i = (b); i != (e); i < (e) ? ++i : --i)
#define REP(i, n) FOR(i, 0, n)
#define IFC(c) \
if (c) \
continue;
#define IFB(c) \
if (c) \
break;
#define IFR(c, r) \
if (c) \
return r;
#define OPOVER(_op, _type) inline bool operator _op(const _type &t) const
#define arrsz(a) (sizeof(a) / sizeof(a[0]))
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((LL)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(c, it) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n) (1ULL << (n))
#define BITOF(n, m) ((ULL)(n) >> (m)&1)
#define RANGE(a, b, c) ((a) <= (b) && (b) <= (c))
#ifdef DEBUG_ON
#define dprt(fmt, ...) \
if (CONDITION) \
fprintf(stderr, fmt, __VA_ARGS__)
#define darr(a) \
if (CONDITION) \
copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr_range(a, f, t) \
if (CONDITION) \
copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define dvec(v) \
if (CONDITION) \
copy(ALL(v), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr2(a, n, m) \
if (CONDITION) \
FOR(i, 0, (n)) { darr_range((a)[i], 0, (m)); }
#define dvec2(v) \
if (CONDITION) \
FOR(i, 0, SZ(v)) { dvec((v)[i]); }
#define WAIT() \
if (CONDITION) { \
string _wait_; \
cerr << "(hit return to continue)" << endl; \
getline(cin, _wait_); \
}
#define dump(x) \
if (CONDITION) \
cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl;
#define dumpf() \
if (CONDITION) \
cerr << __PRETTY_FUNCTION__ << endl;
#define dumpv(x) \
if (CONDITION) \
cerr << " [L:" << __LINE__ << "] " << #x << " = "; \
REP(q, (x).size()) cerr << (x)[q] << " "; \
cerr << endl;
#define where() \
if (CONDITION) \
cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__ \
<< "]" << endl;
#define show_bits(b, s) \
if (CONDITION) { \
REP(i, s) { \
cerr << BITOF(b, s - 1 - i); \
if (i % 4 == 3) \
cerr << ' '; \
} \
cerr << endl; \
}
#else
#define cerr \
if (0) \
cerr
#define dprt(fmt, ...)
#define darr(a)
#define darr_range(a, f, t)
#define dvec(v)
#define darr2(a, n, m)
#define dvec2(v)
#define WAIT()
#define dump(x)
#define dumpf()
#define dumpv(x)
#define where()
#define show_bits(b, s)
#endif
inline int bits_count(ULL b) {
int c = 0;
while (b != 0) {
c += (b & 1);
b >>= 1;
}
return c;
}
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline double now() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (static_cast<double>(tv.tv_sec) +
static_cast<double>(tv.tv_usec) * 1e-6);
}
inline VS split(string s, char delimiter) {
VS v;
string t;
REP(i, s.length()) {
IFC(s[i] == ' ');
if (s[i] == delimiter)
v.PB(t), t = "";
else
t += s[i];
}
v.PB(t);
return v;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
return s << "(" << d.first << ", " << d.second << ")";
}
/*}}}*/
#define TIME 1261
int on[1001][TIME];
int main() {
int N, M;
while (cin >> N >> M, N || M) {
REP(i, M + 1) { on[i][0] = 0; }
int cur = 0;
int r;
cin >> r;
REP(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
FOR(k, 1, M + 1) {
FOR(j, cur + 1, t + 1) { on[k][j] = on[k][j - 1]; }
}
s == 0 ? --on[m][t] : ++on[m][t];
// FOR (x, 1, M+1) {
// cerr << "#" << x << ": ";
// FOR (y, cur, t+1) {
// cerr << on[x][y] << " ";
//}
// cerr << endl;
//}
cur = t;
}
FOR(k, 1, M + 1) {
FOR(j, cur + 1, TIME) { on[k][j] = on[k][j - 1]; }
}
int q;
cin >> q;
REP(i, q) {
int ts, te, m;
cin >> ts >> te >> m;
int ans = 0;
// FOR (x, ts, te) {
// cerr << on[m][x] << " ";
//}
// cerr << endl;
FOR(j, ts, te) {
if (on[m][j] != 0) {
++ans;
}
}
cout << ans << endl;
}
}
} | /* 2012-08-20T10:52:03 */
#define DEBUG_ON_
#define CONDITION true
using namespace std; /*{{{*/
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/time.h>
#include <vector>
#define INF (1e9)
static const double PI = acos(-1.0);
static const double EPS = 1e-10;
typedef long long int LL;
typedef unsigned long long int ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef complex<double> P;
#define FOR(i, b, e) for (typeof(b) i = (b); i != (e); i < (e) ? ++i : --i)
#define REP(i, n) FOR(i, 0, n)
#define IFC(c) \
if (c) \
continue;
#define IFB(c) \
if (c) \
break;
#define IFR(c, r) \
if (c) \
return r;
#define OPOVER(_op, _type) inline bool operator _op(const _type &t) const
#define arrsz(a) (sizeof(a) / sizeof(a[0]))
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define SZ(a) ((LL)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(c, it) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n) (1ULL << (n))
#define BITOF(n, m) ((ULL)(n) >> (m)&1)
#define RANGE(a, b, c) ((a) <= (b) && (b) <= (c))
#ifdef DEBUG_ON
#define dprt(fmt, ...) \
if (CONDITION) \
fprintf(stderr, fmt, __VA_ARGS__)
#define darr(a) \
if (CONDITION) \
copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr_range(a, f, t) \
if (CONDITION) \
copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define dvec(v) \
if (CONDITION) \
copy(ALL(v), ostream_iterator<int>(cerr, " ")); \
cerr << endl
#define darr2(a, n, m) \
if (CONDITION) \
FOR(i, 0, (n)) { darr_range((a)[i], 0, (m)); }
#define dvec2(v) \
if (CONDITION) \
FOR(i, 0, SZ(v)) { dvec((v)[i]); }
#define WAIT() \
if (CONDITION) { \
string _wait_; \
cerr << "(hit return to continue)" << endl; \
getline(cin, _wait_); \
}
#define dump(x) \
if (CONDITION) \
cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl;
#define dumpf() \
if (CONDITION) \
cerr << __PRETTY_FUNCTION__ << endl;
#define dumpv(x) \
if (CONDITION) \
cerr << " [L:" << __LINE__ << "] " << #x << " = "; \
REP(q, (x).size()) cerr << (x)[q] << " "; \
cerr << endl;
#define where() \
if (CONDITION) \
cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__ \
<< "]" << endl;
#define show_bits(b, s) \
if (CONDITION) { \
REP(i, s) { \
cerr << BITOF(b, s - 1 - i); \
if (i % 4 == 3) \
cerr << ' '; \
} \
cerr << endl; \
}
#else
#define cerr \
if (0) \
cerr
#define dprt(fmt, ...)
#define darr(a)
#define darr_range(a, f, t)
#define dvec(v)
#define darr2(a, n, m)
#define dvec2(v)
#define WAIT()
#define dump(x)
#define dumpf()
#define dumpv(x)
#define where()
#define show_bits(b, s)
#endif
inline int bits_count(ULL b) {
int c = 0;
while (b != 0) {
c += (b & 1);
b >>= 1;
}
return c;
}
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline double now() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (static_cast<double>(tv.tv_sec) +
static_cast<double>(tv.tv_usec) * 1e-6);
}
inline VS split(string s, char delimiter) {
VS v;
string t;
REP(i, s.length()) {
IFC(s[i] == ' ');
if (s[i] == delimiter)
v.PB(t), t = "";
else
t += s[i];
}
v.PB(t);
return v;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
return s << "(" << d.first << ", " << d.second << ")";
}
/*}}}*/
#define TIME 1261
int on[10001][TIME];
int main() {
int N, M;
while (cin >> N >> M, N || M) {
REP(i, M + 1) { on[i][0] = 0; }
int cur = 0;
int r;
cin >> r;
REP(i, r) {
int t, n, m, s;
cin >> t >> n >> m >> s;
FOR(k, 1, M + 1) {
FOR(j, cur + 1, t + 1) { on[k][j] = on[k][j - 1]; }
}
s == 0 ? --on[m][t] : ++on[m][t];
// FOR (x, 1, M+1) {
// cerr << "#" << x << ": ";
// FOR (y, cur, t+1) {
// cerr << on[x][y] << " ";
//}
// cerr << endl;
//}
cur = t;
}
FOR(k, 1, M + 1) {
FOR(j, cur + 1, TIME) { on[k][j] = on[k][j - 1]; }
}
int q;
cin >> q;
REP(i, q) {
int ts, te, m;
cin >> ts >> te >> m;
int ans = 0;
// FOR (x, ts, te) {
// cerr << on[m][x] << " ";
//}
// cerr << endl;
FOR(j, ts, te) {
if (on[m][j] != 0) {
++ans;
}
}
cout << ans << endl;
}
}
} | replace | 194 | 195 | 194 | 195 | 0 | |
p00729 | C++ | Runtime Error | #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <complex>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 1010
bool solve() {
int n, m, r, q;
int rec_t[SIZE], rec_m[SIZE], rec_n[SIZE], rec_s[SIZE];
int memo[SIZE], c[SIZE] = {};
vector<pair<int, int>> vec[SIZE];
scanf("%d%d%d", &n, &m, &r);
if (n == 0)
return false;
for (int i = 0; i < r; i++) {
scanf("%d%d%d%d", rec_t + i, rec_n + i, rec_m + i, rec_s + i);
if (rec_s[i] == 1) {
if (c[rec_m[i]] == 0)
memo[rec_m[i]] = rec_t[i];
c[rec_m[i]]++;
} else {
c[rec_m[i]]--;
if (c[rec_m[i]] == 0)
vec[rec_m[i]].push_back({memo[rec_m[i]], rec_t[i]});
}
}
scanf("%d", &q);
for (int i = 0; i < q; i++) {
int ts, te, m;
int sum = 0;
scanf("%d%d%d", &ts, &te, &m);
for (int j = 0; j < vec[m].size(); j++) {
if (!(te <= vec[m][j].first || vec[m][j].second <= ts)) {
sum += min(te, vec[m][j].second) - max(ts, vec[m][j].first);
}
}
printf("%d\n", sum);
}
return true;
}
int main() {
while (solve())
;
return 0;
} | #include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <complex>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 10010
bool solve() {
int n, m, r, q;
int rec_t[SIZE], rec_m[SIZE], rec_n[SIZE], rec_s[SIZE];
int memo[SIZE], c[SIZE] = {};
vector<pair<int, int>> vec[SIZE];
scanf("%d%d%d", &n, &m, &r);
if (n == 0)
return false;
for (int i = 0; i < r; i++) {
scanf("%d%d%d%d", rec_t + i, rec_n + i, rec_m + i, rec_s + i);
if (rec_s[i] == 1) {
if (c[rec_m[i]] == 0)
memo[rec_m[i]] = rec_t[i];
c[rec_m[i]]++;
} else {
c[rec_m[i]]--;
if (c[rec_m[i]] == 0)
vec[rec_m[i]].push_back({memo[rec_m[i]], rec_t[i]});
}
}
scanf("%d", &q);
for (int i = 0; i < q; i++) {
int ts, te, m;
int sum = 0;
scanf("%d%d%d", &ts, &te, &m);
for (int j = 0; j < vec[m].size(); j++) {
if (!(te <= vec[m][j].first || vec[m][j].second <= ts)) {
sum += min(te, vec[m][j].second) - max(ts, vec[m][j].first);
}
}
printf("%d\n", sum);
}
return true;
}
int main() {
while (solve())
;
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p00730 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
using namespace std;
#define dump(n) cerr << "# " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)
#define iter(c) __typeof__((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
struct Rect {
int x, y, w, h;
Rect() {}
Rect(int x, int y, int w, int h) : x(x), y(y), w(w), h(h) {}
};
int main() {
for (int n, w, h; cin >> n >> w >> h, n | w | h;) {
list<Rect> rs;
rs.push_back(Rect(0, 0, w, h));
rep(i, n) {
int p, s;
cin >> p >> s;
iter(rs) it = rs.begin();
advance(it, p - 1);
int len = (it->w + it->h) * 2;
Rect r1, r2;
if ((s %= len) < it->w) {
r1 = Rect(it->x, it->y, s, it->h);
r2 = Rect(it->x + s, it->y, it->w - s, it->h);
} else if ((s -= it->w) < it->h) {
r1 = Rect(it->x, it->y, it->w, s);
r2 = Rect(it->x, it->y + s, it->w, it->h - s);
} else if ((s -= it->h) < it->w) {
r1 = Rect(it->x, it->y, it->h - s, it->h);
r2 = Rect(it->x + it->w - s, it->y, s, it->h);
} else if ((s -= it->w) < it->h) {
r1 = Rect(it->x, it->y, it->w, it->h - s);
r2 = Rect(it->x, it->y + it->h - s, it->w, s);
}
if (r1.w * r1.h > r2.w * r2.h)
swap(r1, r2);
rs.push_back(r1);
rs.push_back(r2);
rs.erase(it);
}
vi as;
foreach (i, rs)
as.push_back(i->w * i->h);
sort(all(as));
rep(i, as.size()) printf("%d%c", as[i], i == as.size() - 1 ? '\n' : ' ');
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
using namespace std;
#define dump(n) cerr << "# " << #n << "=" << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)
#define iter(c) __typeof__((c).begin())
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
struct Rect {
int x, y, w, h;
Rect() {}
Rect(int x, int y, int w, int h) : x(x), y(y), w(w), h(h) {}
};
int main() {
for (int n, w, h; cin >> n >> w >> h, n | w | h;) {
list<Rect> rs;
rs.push_back(Rect(0, 0, w, h));
rep(i, n) {
int p, s;
cin >> p >> s;
iter(rs) it = rs.begin();
advance(it, p - 1);
int len = (it->w + it->h) * 2;
Rect r1, r2;
if ((s %= len) < it->w) {
r1 = Rect(it->x, it->y, s, it->h);
r2 = Rect(it->x + s, it->y, it->w - s, it->h);
} else if ((s -= it->w) < it->h) {
r1 = Rect(it->x, it->y, it->w, s);
r2 = Rect(it->x, it->y + s, it->w, it->h - s);
} else if ((s -= it->h) < it->w) {
r1 = Rect(it->x, it->y, it->w - s, it->h);
r2 = Rect(it->x + it->w - s, it->y, s, it->h);
} else if ((s -= it->w) < it->h) {
r1 = Rect(it->x, it->y, it->w, it->h - s);
r2 = Rect(it->x, it->y + it->h - s, it->w, s);
}
if (r1.w * r1.h > r2.w * r2.h)
swap(r1, r2);
rs.push_back(r1);
rs.push_back(r2);
rs.erase(it);
}
vi as;
foreach (i, rs)
as.push_back(i->w * i->h);
sort(all(as));
rep(i, as.size()) printf("%d%c", as[i], i == as.size() - 1 ? '\n' : ' ');
}
return 0;
} | replace | 69 | 70 | 69 | 70 | 0 | |
p00730 | C++ | Runtime Error | #include "bits/stdc++.h"
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define RREP(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define RFOR(i, m, n) for (ll i = n - 1; i >= m; --i)
#define ALL(v) (v).begin(), (v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define DUMP(v) \
REP(aa, (v).size()) { \
cout << v[a]; \
if (a != v.size() - 1) \
cout << " "; \
else \
cout << endl; \
}
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
bool comp(pair<ll, pll> a, pair<ll, pll> b) {
if (a.first != b.first)
return a.first < b.first;
return a.second.first * a.second.second < b.second.first * b.second.second;
}
bool comp2(pair<ll, pll> a, pair<ll, pll> b) {
return a.second.first * a.second.second < b.second.first * b.second.second;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (1) {
int n, w, d;
cin >> n >> w >> d;
if (!w)
break;
vector<pair<ll, pll>> v;
v.push_back({0, {w, d}});
REP(i, n) {
int p, s;
cin >> p >> s;
auto a = v[p - 1];
v.erase(v.begin() + p - 1);
int W = a.second.first, D = a.second.second;
s %= 2 * (W + D);
if (s < W) {
v.push_back({i + 1, {s, D}});
v.push_back({i + 1, {W - s, D}});
} else if (s < W + D) {
v.push_back({i + 1, {W, s - D}});
v.push_back({i + 1, {W, W + D - s}});
} else if (s < 2 * W + D) {
v.push_back({i + 1, {s - W - D, D}});
v.push_back({i + 1, {2 * W + D - s, D}});
} else {
v.push_back({i + 1, {W, s - 2 * W - D}});
v.push_back({i + 1, {W, 2 * W + 2 * D - s}});
}
sort(ALL(v), comp);
}
sort(ALL(v), comp2);
REP(i, v.size()) {
cout << v[i].second.first * v[i].second.second;
if (i != v.size() - 1)
cout << " ";
else
cout << endl;
}
}
return 0;
} | #include "bits/stdc++.h"
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define RREP(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define RFOR(i, m, n) for (ll i = n - 1; i >= m; --i)
#define ALL(v) (v).begin(), (v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define DUMP(v) \
REP(aa, (v).size()) { \
cout << v[a]; \
if (a != v.size() - 1) \
cout << " "; \
else \
cout << endl; \
}
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
bool comp(pair<ll, pll> a, pair<ll, pll> b) {
if (a.first != b.first)
return a.first < b.first;
return a.second.first * a.second.second < b.second.first * b.second.second;
}
bool comp2(pair<ll, pll> a, pair<ll, pll> b) {
return a.second.first * a.second.second < b.second.first * b.second.second;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (1) {
int n, w, d;
cin >> n >> w >> d;
if (!w)
break;
vector<pair<ll, pll>> v;
v.push_back({0, {w, d}});
REP(i, n) {
int p, s;
cin >> p >> s;
auto a = v[p - 1];
v.erase(v.begin() + p - 1);
int W = a.second.first, D = a.second.second;
s %= 2 * (W + D);
if (s < W) {
v.push_back({i + 1, {s, D}});
v.push_back({i + 1, {W - s, D}});
} else if (s < W + D) {
v.push_back({i + 1, {W, s - W}});
v.push_back({i + 1, {W, W + D - s}});
} else if (s < 2 * W + D) {
v.push_back({i + 1, {s - W - D, D}});
v.push_back({i + 1, {2 * W + D - s, D}});
} else {
v.push_back({i + 1, {W, s - 2 * W - D}});
v.push_back({i + 1, {W, 2 * W + 2 * D - s}});
}
sort(ALL(v), comp);
}
sort(ALL(v), comp2);
REP(i, v.size()) {
cout << v[i].second.first * v[i].second.second;
if (i != v.size() - 1)
cout << " ";
else
cout << endl;
}
}
return 0;
} | replace | 66 | 67 | 66 | 67 | 0 | |
p00730 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define mp(a, b) make_pair((a), (b))
#define eq ==
typedef long long ll;
typedef complex<double> point;
typedef pair<int, int> pii;
// →↑←↓
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
const double EPS = 1e-9;
struct cake {
int w, h;
int area;
cake(int aw, int ah) {
w = aw;
h = ah;
area = w * h;
}
};
bool cake_cmp(const cake &lhs, const cake &rhs) { return lhs.area < rhs.area; }
int main() {
while (true) {
int n, w, h;
cin >> n >> w >> h;
if (n == 0 and w == 0 and h == 0)
break;
vector<cake> cakes;
cakes.push_back(cake(w, h));
for (int i = 0; i < n; i++) {
cerr << endl;
int p, s;
cin >> p >> s;
p--;
cake c = cakes[p];
cakes.erase(cakes.begin() + p);
vector<cake> ps(2, cake(0, 0));
s %= (2 * (c.w + c.h));
if (0 <= s and s <= c.w) {
ps[0] = cake(c.w - s, c.h);
ps[1] = cake(s, c.h);
} else if (c.w <= s and s <= c.w + c.h) {
int rest = s - c.w;
// s <= c.w + c.h
// rest <= c.h
ps[0] = cake(c.w, c.h - (rest));
ps[1] = cake(c.w, rest);
} else if (c.w + c.h <= s and s <= c.w + c.h + c.w) {
int rest = s - (c.w + c.h);
ps[0] = cake(rest, c.h);
ps[1] = cake(c.w - rest, c.h);
} else {
int rest = s - (c.w + c.h + c.w);
ps[0] = cake(c.w, rest);
ps[1] = cake(c.w, c.h - rest);
}
if (ps[0].area > ps[1].area) {
swap(ps[0], ps[1]);
}
for (int i = 0; i < 2; i++) {
cakes.push_back(ps[i]);
}
}
sort(all(cakes), cake_cmp);
for (int i = 0; i < cakes.size(); i++) {
cout << cakes[i].area;
if (i == cakes.size() - 1) {
cout << endl;
} else {
cout << " ";
}
}
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define mp(a, b) make_pair((a), (b))
#define eq ==
typedef long long ll;
typedef complex<double> point;
typedef pair<int, int> pii;
// →↑←↓
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
const double EPS = 1e-9;
struct cake {
int w, h;
int area;
cake(int aw, int ah) {
w = aw;
h = ah;
area = w * h;
}
};
bool cake_cmp(const cake &lhs, const cake &rhs) { return lhs.area < rhs.area; }
int main() {
while (true) {
int n, w, h;
cin >> n >> w >> h;
if (n == 0 and w == 0 and h == 0)
break;
vector<cake> cakes;
cakes.push_back(cake(w, h));
for (int i = 0; i < n; i++) {
int p, s;
cin >> p >> s;
p--;
cake c = cakes[p];
cakes.erase(cakes.begin() + p);
vector<cake> ps(2, cake(0, 0));
s %= (2 * (c.w + c.h));
if (0 <= s and s <= c.w) {
ps[0] = cake(c.w - s, c.h);
ps[1] = cake(s, c.h);
} else if (c.w <= s and s <= c.w + c.h) {
int rest = s - c.w;
// s <= c.w + c.h
// rest <= c.h
ps[0] = cake(c.w, c.h - (rest));
ps[1] = cake(c.w, rest);
} else if (c.w + c.h <= s and s <= c.w + c.h + c.w) {
int rest = s - (c.w + c.h);
ps[0] = cake(rest, c.h);
ps[1] = cake(c.w - rest, c.h);
} else {
int rest = s - (c.w + c.h + c.w);
ps[0] = cake(c.w, rest);
ps[1] = cake(c.w, c.h - rest);
}
if (ps[0].area > ps[1].area) {
swap(ps[0], ps[1]);
}
for (int i = 0; i < 2; i++) {
cakes.push_back(ps[i]);
}
}
sort(all(cakes), cake_cmp);
for (int i = 0; i < cakes.size(); i++) {
cout << cakes[i].area;
if (i == cakes.size() - 1) {
cout << endl;
} else {
cout << " ";
}
}
}
return 0;
} | delete | 56 | 57 | 56 | 56 | 0 | |
p00730 | 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 = (a)-1; i >= b; i--)
#define chmin(a, b) (a) = min((a), (b));
#define chmax(a, b) (a) = max((a), (b));
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define printV(v) \
cerr << (#v) << ":"; \
for (auto(x) : (v)) { \
cerr << " " << (x); \
} \
cerr << endl;
#define printVS(vs) \
cerr << (#vs) << ":" << endl; \
for (auto(s) : (vs)) { \
cerr << (s) << endl; \
}
#define printVV(vv) \
cerr << (#vv) << ":" << endl; \
for (auto(v) : (vv)) { \
for (auto(x) : (v)) { \
cerr << " " << (x); \
} \
cerr << endl; \
}
#define printP(p) cerr << (#p) << (p).first << " " << (p).second << endl;
#define printVP(vp) \
cerr << (#vp) << ":" << endl; \
for (auto(p) : (vp)) { \
cerr << (p).first << " " << (p).second << endl; \
}
inline void output() { cerr << endl; }
template <typename First, typename... Rest>
inline void output(const First &first, const Rest &...rest) {
cerr << first << " ";
output(rest...);
}
using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;
struct Cake {
int t;
int h, w;
Cake() {}
Cake(int _t, int _h, int _w) : t(_t), h(_h), w(_w) {}
bool operator<(const Cake &o) const {
if (t != o.t)
return t < o.t;
return h * w < o.h * o.w;
}
};
int n, h, w;
vector<Cake> vec;
int p, s;
void cut(int t) {
Cake c = vec[p];
vec.erase(vec.begin() + p);
Cake c1 = c, c2 = c;
c1.t = t;
c2.t = t;
s %= (c.h + c.w);
if (s < c.w) {
c1.w = s;
c2.w = c.w - s;
} else {
s -= c.w;
c1.h = s;
c2.h = c.h - s;
}
vec.emplace_back(c1);
vec.emplace_back(c2);
sort(all(vec));
}
void solve() {
vec.clear();
vec.emplace_back(Cake(0, h, w));
rep(i, n) {
cin >> p >> s;
p--;
cut(i);
}
vi ans;
for (auto c : vec) {
ans.emplace_back(c.h * c.w);
}
sort(all(ans));
cerr << "hey!" << endl;
rep(i, ans.size()) { cout << (i ? " " : "") << ans[i]; }
cout << endl;
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
while (cin >> n >> w >> h, h) {
solve();
}
} | #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 = (a)-1; i >= b; i--)
#define chmin(a, b) (a) = min((a), (b));
#define chmax(a, b) (a) = max((a), (b));
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define printV(v) \
cerr << (#v) << ":"; \
for (auto(x) : (v)) { \
cerr << " " << (x); \
} \
cerr << endl;
#define printVS(vs) \
cerr << (#vs) << ":" << endl; \
for (auto(s) : (vs)) { \
cerr << (s) << endl; \
}
#define printVV(vv) \
cerr << (#vv) << ":" << endl; \
for (auto(v) : (vv)) { \
for (auto(x) : (v)) { \
cerr << " " << (x); \
} \
cerr << endl; \
}
#define printP(p) cerr << (#p) << (p).first << " " << (p).second << endl;
#define printVP(vp) \
cerr << (#vp) << ":" << endl; \
for (auto(p) : (vp)) { \
cerr << (p).first << " " << (p).second << endl; \
}
inline void output() { cerr << endl; }
template <typename First, typename... Rest>
inline void output(const First &first, const Rest &...rest) {
cerr << first << " ";
output(rest...);
}
using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;
struct Cake {
int t;
int h, w;
Cake() {}
Cake(int _t, int _h, int _w) : t(_t), h(_h), w(_w) {}
bool operator<(const Cake &o) const {
if (t != o.t)
return t < o.t;
return h * w < o.h * o.w;
}
};
int n, h, w;
vector<Cake> vec;
int p, s;
void cut(int t) {
Cake c = vec[p];
vec.erase(vec.begin() + p);
Cake c1 = c, c2 = c;
c1.t = t;
c2.t = t;
s %= (c.h + c.w);
if (s < c.w) {
c1.w = s;
c2.w = c.w - s;
} else {
s -= c.w;
c1.h = s;
c2.h = c.h - s;
}
vec.emplace_back(c1);
vec.emplace_back(c2);
sort(all(vec));
}
void solve() {
vec.clear();
vec.emplace_back(Cake(0, h, w));
rep(i, n) {
cin >> p >> s;
p--;
cut(i);
}
vi ans;
for (auto c : vec) {
ans.emplace_back(c.h * c.w);
}
sort(all(ans));
rep(i, ans.size()) { cout << (i ? " " : "") << ans[i]; }
cout << endl;
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
while (cin >> n >> w >> h, h) {
solve();
}
} | delete | 104 | 105 | 104 | 104 | 0 | hey!
hey!
hey!
|
p00730 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define MAX 100
typedef struct {
int width;
int height;
} CAKE;
bool operator<(const CAKE &left, const CAKE &right) {
return left.width * left.height < right.width * right.height;
}
int main() {
int n, w, d;
while (cin >> n >> w >> d, n || w || d) {
vector<CAKE> cake;
CAKE tmp = {w, d};
cake.push_back(tmp);
int p, s;
while (n--) {
cin >> p >> s;
p--;
int cnt = 0;
while (true) {
assert(s != cake[p].width);
if (s - cake[p].width <= 0)
break;
s -= cake[p].width;
cnt++;
assert(s != cake[p].height);
if (s - cake[p].height <= 0)
break;
s -= cake[p].height;
cnt++;
}
cnt %= 4;
pair<CAKE, CAKE> P;
if (cnt % 2 == 0) {
CAKE tmp = {s, cake[p].height};
P.first = tmp;
tmp.width = cake[p].width - s;
P.second = tmp;
} else {
CAKE tmp = {cake[p].width, s};
P.first = tmp;
tmp.height = cake[p].height - s;
P.second = tmp;
}
if (P.first.width * P.first.height < P.second.width * P.second.height) {
cake.push_back(P.second);
cake.push_back(P.first);
cake.erase(cake.begin() + p);
} else {
cake.push_back(P.first);
cake.push_back(P.second);
cake.erase(cake.begin() + p);
}
}
sort(cake.begin(), cake.end());
for (int i = 0; i < cake.size() - 1; i++) {
cout << cake[i].width * cake[i].height << " ";
}
cout << cake[cake.size() - 1].width * cake[cake.size() - 1].height << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define MAX 100
typedef struct {
int width;
int height;
} CAKE;
bool operator<(const CAKE &left, const CAKE &right) {
return left.width * left.height < right.width * right.height;
}
int main() {
int n, w, d;
while (cin >> n >> w >> d, n || w || d) {
vector<CAKE> cake;
CAKE tmp = {w, d};
cake.push_back(tmp);
int p, s;
while (n--) {
cin >> p >> s;
p--;
int cnt = 0;
while (true) {
assert(s != cake[p].width);
if (s - cake[p].width <= 0)
break;
s -= cake[p].width;
cnt++;
assert(s != cake[p].height);
if (s - cake[p].height <= 0)
break;
s -= cake[p].height;
cnt++;
}
cnt %= 4;
pair<CAKE, CAKE> P;
if (cnt % 2 == 0) {
CAKE tmp = {s, cake[p].height};
P.first = tmp;
tmp.width = cake[p].width - s;
P.second = tmp;
} else {
CAKE tmp = {cake[p].width, s};
P.first = tmp;
tmp.height = cake[p].height - s;
P.second = tmp;
}
if (P.first.width * P.first.height > P.second.width * P.second.height) {
cake.push_back(P.second);
cake.push_back(P.first);
cake.erase(cake.begin() + p);
} else {
cake.push_back(P.first);
cake.push_back(P.second);
cake.erase(cake.begin() + p);
}
}
sort(cake.begin(), cake.end());
for (int i = 0; i < cake.size() - 1; i++) {
cout << cake[i].width * cake[i].height << " ";
}
cout << cake[cake.size() - 1].width * cake[cake.size() - 1].height << endl;
}
return 0;
} | replace | 57 | 58 | 57 | 58 | -6 | 0b346c96-21e9-4801-8339-f356e78c4449.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p00730/C++/s358081830.cpp:29: int main(): Assertion `s!=cake[p].width' failed.
|
p00730 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
bool larger(pair<int, int> &a, pair<int, int> &b) {
return a.first * a.second < b.first * b.second;
}
int main() {
while (1) {
int n, w, d;
cin >> n >> w >> d;
if (w == 0)
break;
vector<pair<int, int>> cakes;
cakes.push_back(make_pair(w, d));
for (int i = 0; i < n; i++) {
int p, s;
cin >> p >> s;
p--;
int x = cakes[p].first, y = cakes[p].second;
cakes.erase(cakes.begin() + p);
s %= x + y;
if (s < x) {
if (s <= x / 2) {
cakes.push_back(make_pair(s, y));
cakes.push_back(make_pair(x - s, y));
} else {
cakes.push_back(make_pair(x - s, y));
cakes.push_back(make_pair(s, d));
}
} else {
s -= x;
if (s <= y / 2) {
cakes.push_back(make_pair(x, s));
cakes.push_back(make_pair(x, y - s));
} else {
cakes.push_back(make_pair(x, y - s));
cakes.push_back(make_pair(x, s));
}
}
}
sort(cakes.begin(), cakes.end(), larger);
for (int i = 0; i < n; i++) {
cout << cakes[i].first * cakes[i].second << " ";
}
cout << cakes[n].first * cakes[n].second << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
bool larger(pair<int, int> &a, pair<int, int> &b) {
return a.first * a.second < b.first * b.second;
}
int main() {
while (1) {
int n, w, d;
cin >> n >> w >> d;
if (w == 0)
break;
vector<pair<int, int>> cakes;
cakes.push_back(make_pair(w, d));
for (int i = 0; i < n; i++) {
int p, s;
cin >> p >> s;
p--;
int x = cakes[p].first, y = cakes[p].second;
cakes.erase(cakes.begin() + p);
s %= x + y;
if (s < x) {
if (s <= x / 2) {
cakes.push_back(make_pair(s, y));
cakes.push_back(make_pair(x - s, y));
} else {
cakes.push_back(make_pair(x - s, y));
cakes.push_back(make_pair(s, y));
}
} else {
s -= x;
if (s <= y / 2) {
cakes.push_back(make_pair(x, s));
cakes.push_back(make_pair(x, y - s));
} else {
cakes.push_back(make_pair(x, y - s));
cakes.push_back(make_pair(x, s));
}
}
}
sort(cakes.begin(), cakes.end(), larger);
for (int i = 0; i < n; i++) {
cout << cakes[i].first * cakes[i].second << " ";
}
cout << cakes[n].first * cakes[n].second << endl;
}
return 0;
} | replace | 32 | 33 | 32 | 33 | 0 | |
p00730 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(n) for (int i = 0; i < n; i++)
#define repp(j, n) for (int j = 0; j < n; j++)
#define reppp(i, m, n) for (int i = m; i < n; i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
using std::cin;
using std::cout;
using std::endl;
using std::map;
using std::pair;
using std::priority_queue;
using std::queue;
using std::stack;
using std::string;
using std::vector;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct Cake {
int index, area, d, w;
Cake(int index0, int area0, int d0, int w0) {
index = index0;
area = area0;
d = d0;
w = w0;
}
};
// 大きいものからpriority_queueで取れる
bool operator<(const Cake &cake1, const Cake &cake2) {
if (cake1.index != cake2.index)
return cake1.index > cake2.index;
else
return cake1.area > cake2.area;
};
int main() {
int n, w, d, p, s;
scanf("%d %d %d", &n, &w, &d);
while (n + d + w != 0) {
priority_queue<Cake> que, tmp;
que.push(Cake(0, d * w, d, w));
rep(n) {
scanf("%d %d", &p, &s);
repp(j, p - 1) {
Cake c = que.top();
// printf("Cake(%d %d %d %d)\n", c.index, c.area, c.w, c.d);
tmp.push(c);
que.pop();
}
Cake c = que.top();
que.pop();
// printf("Cake(%d %d %d %d)\n", c.index, c.area, c.w, c.d);
// 2つのピースに分けて,queに2つともぶっっこむ
s %= (c.w + c.d);
if (s < c.w) {
if (s != 0)
que.push(Cake(i + 1, c.d * s, c.d, s));
if (s != c.w)
que.push(Cake(i + 1, c.d * (c.w - s), c.d, c.w - s));
} else {
s -= c.w;
if (s != 0)
que.push(Cake(i + 1, s * c.w, s, c.w));
if (s != c.d)
que.push(Cake(i + 1, (c.d - s) * c.w, (c.d - s), c.w));
}
while (!tmp.empty()) {
que.push(tmp.top());
tmp.pop();
}
}
vector<int> ans;
while (!que.empty()) {
Cake c = que.top();
que.pop();
ans.push_back(c.area);
}
sort(all(ans));
rep((int)ans.size() - 1) printf("%d ", ans[i]);
printf("%d\n", ans.back());
scanf("%d %d %d", &n, &d, &w);
}
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(n) for (int i = 0; i < n; i++)
#define repp(j, n) for (int j = 0; j < n; j++)
#define reppp(i, m, n) for (int i = m; i < n; i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
using std::cin;
using std::cout;
using std::endl;
using std::map;
using std::pair;
using std::priority_queue;
using std::queue;
using std::stack;
using std::string;
using std::vector;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct Cake {
int index, area, d, w;
Cake(int index0, int area0, int d0, int w0) {
index = index0;
area = area0;
d = d0;
w = w0;
}
};
// 大きいものからpriority_queueで取れる
bool operator<(const Cake &cake1, const Cake &cake2) {
if (cake1.index != cake2.index)
return cake1.index > cake2.index;
else
return cake1.area > cake2.area;
};
int main() {
int n, w, d, p, s;
scanf("%d %d %d", &n, &w, &d);
while (n + d + w != 0) {
priority_queue<Cake> que, tmp;
que.push(Cake(0, d * w, d, w));
rep(n) {
scanf("%d %d", &p, &s);
repp(j, p - 1) {
Cake c = que.top();
// printf("Cake(%d %d %d %d)\n", c.index, c.area, c.w, c.d);
tmp.push(c);
que.pop();
}
Cake c = que.top();
que.pop();
// printf("Cake(%d %d %d %d)\n", c.index, c.area, c.w, c.d);
// 2つのピースに分けて,queに2つともぶっっこむ
s %= (c.w + c.d);
if (s < c.w) {
if (s != 0)
que.push(Cake(i + 1, c.d * s, c.d, s));
if (s != c.w)
que.push(Cake(i + 1, c.d * (c.w - s), c.d, c.w - s));
} else {
s -= c.w;
if (s != 0)
que.push(Cake(i + 1, s * c.w, s, c.w));
if (s != c.d)
que.push(Cake(i + 1, (c.d - s) * c.w, (c.d - s), c.w));
}
while (!tmp.empty()) {
que.push(tmp.top());
tmp.pop();
}
}
vector<int> ans;
while (!que.empty()) {
Cake c = que.top();
que.pop();
ans.push_back(c.area);
}
sort(all(ans));
rep((int)ans.size() - 1) printf("%d ", ans[i]);
printf("%d\n", ans.back());
scanf("%d %d %d", &n, &w, &d);
}
return 0;
}
| replace | 108 | 109 | 108 | 109 | -11 | |
p00730 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for (int i = 0; i < (n); i++)
#define Rrep(i, a, n) for (int i = (a); i < (n); i++)
#define All(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;
signed main() {
int n, w, d;
while (cin >> n >> w >> d, n || w || d) {
int p[101], s[101];
Rep(i, n) cin >> p[i] >> s[i], p[i]--;
vector<Pii> cake;
cake.pb(Pii(d, w));
Rep(i, n) {
// Rep(j, (int)cake.size()) cout << cake[j].sc << " " << cake[j].fr <<
// endl; cout << endl;
d = cake[p[i]].fr;
w = cake[p[i]].sc;
cake.erase(cake.begin() + p[i]);
int mi;
if (s[i] > (2 * w + 2 * d))
s[i] /= (2 * w + 2 * d);
if (s[i] < w) {
mi = min(s[i], w - s[i]);
cake.pb(Pii(d, mi));
cake.pb(Pii(d, w - mi));
} else if (s[i] < w + d) {
s[i] -= w;
mi = min(s[i], d - s[i]);
cake.pb(Pii(mi, w));
cake.pb(Pii(d - mi, w));
} else if (s[i] < 2 * w + d) {
s[i] -= w + d;
mi = min(s[i], w - s[i]);
cake.pb(Pii(d, mi));
cake.pb(Pii(d, w - mi));
} else {
s[i] -= 2 * w + d;
mi = min(s[i], d - s[i]);
cake.pb(Pii(mi, w));
cake.pb(Pii(d - mi, w));
}
}
vector<int> ans;
Rep(i, (int)cake.size()) ans.pb(cake[i].fr * cake[i].sc);
sort(All(ans));
Rep(i, (int)ans.size() - 1) cout << ans[i] << " ";
cout << ans[ans.size() - 1] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for (int i = 0; i < (n); i++)
#define Rrep(i, a, n) for (int i = (a); i < (n); i++)
#define All(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;
signed main() {
int n, w, d;
while (cin >> n >> w >> d, n || w || d) {
int p[101], s[101];
Rep(i, n) cin >> p[i] >> s[i], p[i]--;
vector<Pii> cake;
cake.pb(Pii(d, w));
Rep(i, n) {
// Rep(j, (int)cake.size()) cout << cake[j].sc << " " << cake[j].fr <<
// endl; cout << endl;
d = cake[p[i]].fr;
w = cake[p[i]].sc;
cake.erase(cake.begin() + p[i]);
int mi;
s[i] %= 2 * w + 2 * d;
if (s[i] < w) {
mi = min(s[i], w - s[i]);
cake.pb(Pii(d, mi));
cake.pb(Pii(d, w - mi));
} else if (s[i] < w + d) {
s[i] -= w;
mi = min(s[i], d - s[i]);
cake.pb(Pii(mi, w));
cake.pb(Pii(d - mi, w));
} else if (s[i] < 2 * w + d) {
s[i] -= w + d;
mi = min(s[i], w - s[i]);
cake.pb(Pii(d, mi));
cake.pb(Pii(d, w - mi));
} else {
s[i] -= 2 * w + d;
mi = min(s[i], d - s[i]);
cake.pb(Pii(mi, w));
cake.pb(Pii(d - mi, w));
}
}
vector<int> ans;
Rep(i, (int)cake.size()) ans.pb(cake[i].fr * cake[i].sc);
sort(All(ans));
Rep(i, (int)ans.size() - 1) cout << ans[i] << " ";
cout << ans[ans.size() - 1] << endl;
}
return 0;
} | replace | 33 | 35 | 33 | 34 | 0 | |
p00731 | C++ | Runtime Error | #include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <tuple>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
char s[100][100];
int d[100][100][2];
int dx[2][9] = {{1, 1, 1, 1, 1, 2, 2, 2, 3},
{-1, -1, -1, -1, -1, -2, -2, -2, -3}};
int dy[9] = {2, 1, 0, -1, -2, 1, 0, -1, 0};
const int INF = 1e9;
typedef tuple<int, int, int> T;
bool cheak(int x, int y, int mx, int my) {
return x >= 0 && y >= 0 && x < mx && y < my;
}
int main() {
int w, h;
while (cin >> w >> h && w) {
memset(s, 0, sizeof s);
rep(i, 100) rep(j, 100) rep(k, 2) d[i][j][k] = INF;
queue<T> q;
rep(y, h) rep(x, w) {
cin >> s[y][x];
if (s[y][x] == 'S') {
q.push(T(y, x, 0));
q.push(T(y, x, 1));
d[y][x][0] = 0;
d[y][x][1] = 0;
}
}
while (q.size()) {
int y = get<0>(q.front());
int x = get<1>(q.front());
int r = get<2>(q.front());
q.pop();
rep(i, 9) {
int tx = x + dx[r][i];
int ty = y + dy[i];
int tmp = 0;
if (s[ty][tx] >= '0' && s[ty][tx] <= '9')
tmp = s[ty][tx] - '0';
if (cheak(x, y, w, h) && (d[ty][tx][1 - r] > d[y][x][r] + tmp) &&
(s[ty][tx] != 'X')) {
d[ty][tx][1 - r] = d[y][x][r] + tmp;
q.push(T(ty, tx, 1 - r));
}
}
}
int ans = INF;
rep(y, h) rep(x, w) {
if (s[y][x] == 'T') {
ans = min(ans, d[y][x][0]);
ans = min(ans, d[y][x][1]);
}
}
if (ans == INF)
ans = -1;
cout << ans << endl;
}
return 0;
} | #include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <tuple>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
char s[100][100];
int d[100][100][2];
int dx[2][9] = {{1, 1, 1, 1, 1, 2, 2, 2, 3},
{-1, -1, -1, -1, -1, -2, -2, -2, -3}};
int dy[9] = {2, 1, 0, -1, -2, 1, 0, -1, 0};
const int INF = 1e9;
typedef tuple<int, int, int> T;
bool cheak(int x, int y, int mx, int my) {
return x >= 0 && y >= 0 && x < mx && y < my;
}
int main() {
int w, h;
while (cin >> w >> h && w) {
memset(s, 0, sizeof s);
rep(i, 100) rep(j, 100) rep(k, 2) d[i][j][k] = INF;
queue<T> q;
rep(y, h) rep(x, w) {
cin >> s[y][x];
if (s[y][x] == 'S') {
q.push(T(y, x, 0));
q.push(T(y, x, 1));
d[y][x][0] = 0;
d[y][x][1] = 0;
}
}
while (q.size()) {
int y = get<0>(q.front());
int x = get<1>(q.front());
int r = get<2>(q.front());
q.pop();
rep(i, 9) {
int tx = x + dx[r][i];
int ty = y + dy[i];
int tmp = 0;
if (s[ty][tx] >= '0' && s[ty][tx] <= '9')
tmp = s[ty][tx] - '0';
if (cheak(tx, ty, w, h) && (d[ty][tx][1 - r] > d[y][x][r] + tmp) &&
(s[ty][tx] != 'X')) {
d[ty][tx][1 - r] = d[y][x][r] + tmp;
q.push(T(ty, tx, 1 - r));
}
}
}
int ans = INF;
rep(y, h) rep(x, w) {
if (s[y][x] == 'T') {
ans = min(ans, d[y][x][0]);
ans = min(ans, d[y][x][1]);
}
}
if (ans == INF)
ans = -1;
cout << ans << endl;
}
return 0;
} | replace | 61 | 62 | 61 | 62 | 0 | |
p00731 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define inf 1 << 30
using namespace std;
class State {
public:
int h, w, leg, cost;
State(int a, int b, int c, int d) : h(a), w(b), leg(c), cost(d) {}
bool operator<(State s) const { return cost < s.cost; }
};
int w, h;
char s[100][100];
int dp[100][100][2] = {};
// a b
int x[2][9] = {{1, 1, 1, 1, 1, 2, 2, 2, 3},
{-1, -1, -1, -1, -1, -2, -2, -2, -3}};
int y[2][9] = {{-2, -1, 0, 1, 2, -1, 0, 1, 0}, {-2, -1, 0, 1, 2, -1, 0, 1, 0}};
bool in(int a, int b) {
if (a < 0 || b < 0 || h <= a || w <= b)
return false;
return true;
}
int main() {
while (1) {
cin >> w >> h;
if (w + h == 0)
break;
priority_queue<State> pq;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> s[i][j];
dp[i][j][0] = inf;
dp[i][j][1] = inf;
if (s[i][j] == 'S') {
pq.push(State(i, j, 0, 0));
pq.push(State(i, j, 1, 0));
dp[i][j][0] = 0;
dp[i][j][1] = 0;
}
if (s[i][j] == 'T')
s[i][j] = '0';
}
}
int ans = inf;
while (!pq.empty()) {
State u = pq.top();
pq.pop();
if (dp[u.h][u.w][u.leg] < u.cost)
continue;
if (s[u.h][u.w] == '0') {
ans = min(ans, u.cost);
continue;
}
for (int k = 0; k < 9; k++) {
int a = u.h + y[u.leg][k], b = u.w + x[u.leg][k], c = (u.leg + 1) % 2;
if (!in(a, b))
continue;
if (s[a][b] == 'X' || s[a][b] == 'S')
continue;
if ((u.cost + (s[a][b] - '0')) < dp[a][b][c]) {
dp[a][b][c] = u.cost + (s[a][b] - '0');
pq.push(State(a, b, c, dp[a][b][c]));
}
}
}
if (ans != inf)
cout << ans << endl;
else
cout << -1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define inf 1 << 30
using namespace std;
class State {
public:
int h, w, leg, cost;
State(int a, int b, int c, int d) : h(a), w(b), leg(c), cost(d) {}
bool operator<(State s) const { return s.cost < cost; }
};
int w, h;
char s[100][100];
int dp[100][100][2] = {};
// a b
int x[2][9] = {{1, 1, 1, 1, 1, 2, 2, 2, 3},
{-1, -1, -1, -1, -1, -2, -2, -2, -3}};
int y[2][9] = {{-2, -1, 0, 1, 2, -1, 0, 1, 0}, {-2, -1, 0, 1, 2, -1, 0, 1, 0}};
bool in(int a, int b) {
if (a < 0 || b < 0 || h <= a || w <= b)
return false;
return true;
}
int main() {
while (1) {
cin >> w >> h;
if (w + h == 0)
break;
priority_queue<State> pq;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> s[i][j];
dp[i][j][0] = inf;
dp[i][j][1] = inf;
if (s[i][j] == 'S') {
pq.push(State(i, j, 0, 0));
pq.push(State(i, j, 1, 0));
dp[i][j][0] = 0;
dp[i][j][1] = 0;
}
if (s[i][j] == 'T')
s[i][j] = '0';
}
}
int ans = inf;
while (!pq.empty()) {
State u = pq.top();
pq.pop();
if (dp[u.h][u.w][u.leg] < u.cost)
continue;
if (s[u.h][u.w] == '0') {
ans = min(ans, u.cost);
continue;
}
for (int k = 0; k < 9; k++) {
int a = u.h + y[u.leg][k], b = u.w + x[u.leg][k], c = (u.leg + 1) % 2;
if (!in(a, b))
continue;
if (s[a][b] == 'X' || s[a][b] == 'S')
continue;
if ((u.cost + (s[a][b] - '0')) < dp[a][b][c]) {
dp[a][b][c] = u.cost + (s[a][b] - '0');
pq.push(State(a, b, c, dp[a][b][c]));
}
}
}
if (ans != inf)
cout << ans << endl;
else
cout << -1 << endl;
}
return 0;
} | replace | 8 | 9 | 8 | 9 | TLE | |
p00731 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int dx[2][9] = {{-2, -1, 0, 1, 2, -1, 0, 1, 0}, {-2, -1, 0, 1, 2, -1, 0, 1, 0}};
int dy[2][9] = {{1, 1, 1, 1, 1, 2, 2, 2, 3},
{-1, -1, -1, -1, -1, -2, -2, -2, -3}};
int main() {
int n, m;
while (cin >> m >> n, n + m) {
vector<vector<char>> in(n, vector<char>(m));
rep(i, n) rep(j, m) cin >> in[i][j];
int dp[32][62][2];
rep(i, 32) rep(j, 62) rep(k, 2) dp[i][j][k] = inf;
queue<pair<pii, pii>> q;
rep(i, m) if (in[n - 1][i] == 'S') {
dp[n - 1][i][0] = dp[n - 1][i][1] = 0;
q.push(pair<pii, pii>(pii(n - 1, i), pii(0, 0))); // x,y,r or l,cost
q.push(pair<pii, pii>(pii(n - 1, i), pii(1, 0))); // x,y,r or l,cost
}
while (!q.empty()) {
pii a = (q.front()).first;
pii b = (q.front()).second;
q.pop();
if (dp[a.first][a.second][b.first] < b.second)
continue;
// cout<<a.first<<" "<<a.second<<" "<<b.first<<"
//"<<b.second<<endl;
rep(i, 9) {
int nx = a.first + dx[b.first][i];
int ny = a.second + dy[b.first][i];
int cost = dp[a.first][a.second][b.first];
if (nx < 0 || ny < 0 || nx >= n || ny >= m)
continue;
if (isdigit(in[nx][ny]))
cost += in[nx][ny] - '0';
if (in[nx][ny] == 'X')
continue;
if (dp[nx][ny][b.first ^ 1] > cost) {
dp[nx][ny][b.first ^ 1] = cost;
// if(in[nx][ny]!='T')
q.push(pair<pii, pii>(pii(nx, ny), pii(b.first ^ 1, cost)));
}
}
}
int out = inf;
rep(i, m) if (in[0][i] == 'T') out =
min(out, min(dp[0][i][0], dp[0][i][1]));
if (out == inf)
out = -1;
cout << out << endl;
}
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int dx[2][9] = {{-2, -1, 0, 1, 2, -1, 0, 1, 0}, {-2, -1, 0, 1, 2, -1, 0, 1, 0}};
int dy[2][9] = {{1, 1, 1, 1, 1, 2, 2, 2, 3},
{-1, -1, -1, -1, -1, -2, -2, -2, -3}};
int main() {
int n, m;
while (cin >> m >> n, n + m) {
vector<vector<char>> in(n, vector<char>(m));
rep(i, n) rep(j, m) cin >> in[i][j];
int dp[62][32][2];
rep(i, 62) rep(j, 32) rep(k, 2) dp[i][j][k] = inf;
queue<pair<pii, pii>> q;
rep(i, m) if (in[n - 1][i] == 'S') {
dp[n - 1][i][0] = dp[n - 1][i][1] = 0;
q.push(pair<pii, pii>(pii(n - 1, i), pii(0, 0))); // x,y,r or l,cost
q.push(pair<pii, pii>(pii(n - 1, i), pii(1, 0))); // x,y,r or l,cost
}
while (!q.empty()) {
pii a = (q.front()).first;
pii b = (q.front()).second;
q.pop();
if (dp[a.first][a.second][b.first] < b.second)
continue;
// cout<<a.first<<" "<<a.second<<" "<<b.first<<"
//"<<b.second<<endl;
rep(i, 9) {
int nx = a.first + dx[b.first][i];
int ny = a.second + dy[b.first][i];
int cost = dp[a.first][a.second][b.first];
if (nx < 0 || ny < 0 || nx >= n || ny >= m)
continue;
if (isdigit(in[nx][ny]))
cost += in[nx][ny] - '0';
if (in[nx][ny] == 'X')
continue;
if (dp[nx][ny][b.first ^ 1] > cost) {
dp[nx][ny][b.first ^ 1] = cost;
// if(in[nx][ny]!='T')
q.push(pair<pii, pii>(pii(nx, ny), pii(b.first ^ 1, cost)));
}
}
}
int out = inf;
rep(i, m) if (in[0][i] == 'T') out =
min(out, min(dp[0][i][0], dp[0][i][1]));
if (out == inf)
out = -1;
cout << out << endl;
}
} | replace | 40 | 42 | 40 | 42 | 0 | |
p00731 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int INF = 1 << 29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int, int> P;
typedef long long ll;
struct State {
int y, x, lr, c;
State(int y, int x, int lr, int c) : y(y), x(x), lr(lr), c(c) {}
bool operator<(const State &right) const { return c > right.c; }
};
int main() {
while (1) {
int W, H;
cin >> W >> H;
if (W == 0)
break;
char field[30][60];
int minDist[30][60][2];
memset(minDist, -1, sizeof(minDist));
priority_queue<State> que;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> field[i][j];
if (field[i][j] == 'S') {
minDist[i][j][0] = 0;
minDist[i][j][1] = 0;
que.emplace(i, j, 0, 0);
que.emplace(i, j, 1, 0);
}
}
}
int ans = -1;
while (que.size()) {
State s = que.top();
que.pop();
if (minDist[s.y][s.x][s.lr] < s.c)
continue;
if (field[s.y][s.x] == 'T') {
ans = s.c;
break;
}
int mul = s.lr == 0 ? 1 : -1;
for (int dx = mul; abs(dx) <= 3; dx += mul) {
for (int dy = -3 + abs(dx); abs(dy) + abs(dx) <= 3; dy++) {
int ny = s.y + dy, nx = s.x + dx, nlr = (s.lr + 1) % 2, nc = s.c;
;
if (ny < 0 || H <= ny || nx < 0 || W <= nx)
continue;
if (field[ny][nx] == 'X')
continue;
if ('1' <= field[ny][nx] && field[ny][nx] <= '9') {
nc += field[ny][nx] - '0';
}
if (minDist[ny][nx][nlr] == -1 || minDist[ny][nx][nlr] > nc) {
minDist[ny][nx][nlr] = nc;
que.emplace(ny, nx, nlr, nc);
}
}
}
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int INF = 1 << 29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int, int> P;
typedef long long ll;
struct State {
int y, x, lr, c;
State(int y, int x, int lr, int c) : y(y), x(x), lr(lr), c(c) {}
bool operator<(const State &right) const { return c > right.c; }
};
int main() {
while (1) {
int W, H;
cin >> W >> H;
if (W == 0)
break;
char field[60][30];
int minDist[60][30][2];
memset(minDist, -1, sizeof(minDist));
priority_queue<State> que;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> field[i][j];
if (field[i][j] == 'S') {
minDist[i][j][0] = 0;
minDist[i][j][1] = 0;
que.emplace(i, j, 0, 0);
que.emplace(i, j, 1, 0);
}
}
}
int ans = -1;
while (que.size()) {
State s = que.top();
que.pop();
if (minDist[s.y][s.x][s.lr] < s.c)
continue;
if (field[s.y][s.x] == 'T') {
ans = s.c;
break;
}
int mul = s.lr == 0 ? 1 : -1;
for (int dx = mul; abs(dx) <= 3; dx += mul) {
for (int dy = -3 + abs(dx); abs(dy) + abs(dx) <= 3; dy++) {
int ny = s.y + dy, nx = s.x + dx, nlr = (s.lr + 1) % 2, nc = s.c;
;
if (ny < 0 || H <= ny || nx < 0 || W <= nx)
continue;
if (field[ny][nx] == 'X')
continue;
if ('1' <= field[ny][nx] && field[ny][nx] <= '9') {
nc += field[ny][nx] - '0';
}
if (minDist[ny][nx][nlr] == -1 || minDist[ny][nx][nlr] > nc) {
minDist[ny][nx][nlr] = nc;
que.emplace(ny, nx, nlr, nc);
}
}
}
}
cout << ans << endl;
}
return 0;
} | replace | 23 | 25 | 23 | 25 | 0 | |
p00731 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define MOD 1000000007
#define ADD(X, Y) ((X) = ((X) + (Y) % MOD) % MOD)
typedef long long i64;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int, int> pi;
int dd[] = {0, 1, 0, -1, 0};
#define all(u) begin(u), end(u)
#define mp make_pair
#define pb push_back
#define WMAX 30
#define HMAX 60
int W, H;
char S[HMAX][WMAX];
int B[HMAX][WMAX][2];
int main() {
while (true) {
scanf("%d%d", &W, &H);
if (W == 0 && H == 0)
break;
memset(B, -1, sizeof(B));
queue<pi> Q;
queue<bool> R;
rep(i, H) {
rep(j, W) {
scanf(" %c", &S[i][j]);
if (S[i][j] == 'S') {
B[i][j][0] = 0;
B[i][j][1] = 0;
Q.push(pi(i, j));
Q.push(pi(i, j));
R.push(0);
R.push(1);
}
}
}
int M = 114514;
while (!Q.empty()) {
int h = Q.front().first;
int w = Q.front().second;
Q.pop();
bool r = R.front();
R.pop();
if (S[h][w] == 'T') {
M = min(B[h][w][r], M);
continue;
}
repi(i, h - 2, h + 3) {
repi(j, w - 3, w + 4) {
if (i < 0 || i >= H || j < 0 || j >= W)
continue;
if (r && j <= w)
continue;
if (!r && w <= j)
continue;
if (abs(h - i) + abs(w - j) > 3)
continue;
if (S[i][j] == 'X' || S[i][j] == 'S')
continue;
int dis;
if (S[i][j] == 'T')
dis = 0;
else
dis = S[i][j] - '0';
if (B[i][j][!r] != -1 && B[i][j][!r] < B[h][w][r] + dis)
continue;
B[i][j][!r] = B[h][w][r] + dis;
Q.push(pi(i, j));
R.push(!r);
}
}
}
/* rep(i,H)
{
rep(j,W)
{
printf("%d ",min(B[i][j][0],B[i][j][1]));
}
printf("\n");
}*/
if (M == 114514)
M = -1;
printf("%d\n", M);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define MOD 1000000007
#define ADD(X, Y) ((X) = ((X) + (Y) % MOD) % MOD)
typedef long long i64;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int, int> pi;
int dd[] = {0, 1, 0, -1, 0};
#define all(u) begin(u), end(u)
#define mp make_pair
#define pb push_back
#define WMAX 30
#define HMAX 60
int W, H;
char S[HMAX][WMAX];
int B[HMAX][WMAX][2];
int main() {
while (true) {
scanf("%d%d", &W, &H);
if (W == 0 && H == 0)
break;
memset(B, -1, sizeof(B));
queue<pi> Q;
queue<bool> R;
rep(i, H) {
rep(j, W) {
scanf(" %c", &S[i][j]);
if (S[i][j] == 'S') {
B[i][j][0] = 0;
B[i][j][1] = 0;
Q.push(pi(i, j));
Q.push(pi(i, j));
R.push(0);
R.push(1);
}
}
}
int M = 114514;
while (!Q.empty()) {
int h = Q.front().first;
int w = Q.front().second;
Q.pop();
bool r = R.front();
R.pop();
if (S[h][w] == 'T') {
M = min(B[h][w][r], M);
continue;
}
repi(i, h - 2, h + 3) {
repi(j, w - 3, w + 4) {
if (i < 0 || i >= H || j < 0 || j >= W)
continue;
if (r && j <= w)
continue;
if (!r && w <= j)
continue;
if (abs(h - i) + abs(w - j) > 3)
continue;
if (S[i][j] == 'X' || S[i][j] == 'S')
continue;
int dis;
if (S[i][j] == 'T')
dis = 0;
else
dis = S[i][j] - '0';
if (B[i][j][!r] != -1 && B[i][j][!r] <= B[h][w][r] + dis)
continue;
B[i][j][!r] = B[h][w][r] + dis;
Q.push(pi(i, j));
R.push(!r);
}
}
}
/* rep(i,H)
{
rep(j,W)
{
printf("%d ",min(B[i][j][0],B[i][j][1]));
}
printf("\n");
}*/
if (M == 114514)
M = -1;
printf("%d\n", M);
}
return 0;
} | replace | 74 | 75 | 74 | 75 | TLE | |
p00731 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> p;
typedef pair<p, p> P;
char mp[30][60];
int w, h;
int cal() {
bool used[2][60][30] = {};
int dx[9] = {1, 1, 1, 1, 1, 2, 2, 2, 3},
dy[9] = {2, 1, 0, -1, -2, 1, 0, -1, 0};
priority_queue<P, vector<P>, greater<P>> q;
for (int i = 0; i < w; i++)
if (mp[h - 1][i] == 'S')
q.push(P(p(0, 0), p(i, h - 1))), q.push(P(p(0, 1), p(i, h - 1)));
while (!q.empty()) {
int s = q.top().first.first, l = q.top().first.second;
int x = q.top().second.first, y = q.top().second.second;
q.pop();
if (mp[y][x] == 'T')
return s;
used[l][y][x] = 1;
int f = 1, c = 0;
if (l)
f = -1;
if (isdigit(mp[y][x]))
c = mp[y][x] - '0';
for (int d = 0; d < 9; d++) {
int nx = x + f * dx[d], ny = y + f * dy[d];
if (nx < 0 || w <= nx || ny < 0 || h <= ny || mp[ny][nx] == 'X' ||
used[!l][ny][nx])
continue;
q.push(P(p(s + c, !l), p(nx, ny)));
}
}
return -1;
}
int main() {
while (cin >> w >> h, w) {
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
cin >> mp[i][j];
cout << cal() << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> p;
typedef pair<p, p> P;
char mp[60][30];
int w, h;
int cal() {
bool used[2][60][30] = {};
int dx[9] = {1, 1, 1, 1, 1, 2, 2, 2, 3},
dy[9] = {2, 1, 0, -1, -2, 1, 0, -1, 0};
priority_queue<P, vector<P>, greater<P>> q;
for (int i = 0; i < w; i++)
if (mp[h - 1][i] == 'S')
q.push(P(p(0, 0), p(i, h - 1))), q.push(P(p(0, 1), p(i, h - 1)));
while (!q.empty()) {
int s = q.top().first.first, l = q.top().first.second;
int x = q.top().second.first, y = q.top().second.second;
q.pop();
if (mp[y][x] == 'T')
return s;
used[l][y][x] = 1;
int f = 1, c = 0;
if (l)
f = -1;
if (isdigit(mp[y][x]))
c = mp[y][x] - '0';
for (int d = 0; d < 9; d++) {
int nx = x + f * dx[d], ny = y + f * dy[d];
if (nx < 0 || w <= nx || ny < 0 || h <= ny || mp[ny][nx] == 'X' ||
used[!l][ny][nx])
continue;
q.push(P(p(s + c, !l), p(nx, ny)));
}
}
return -1;
}
int main() {
while (cin >> w >> h, w) {
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
cin >> mp[i][j];
cout << cal() << endl;
}
return 0;
} | replace | 4 | 5 | 4 | 6 | 0 | |
p00731 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
char s[60][60], buf[2];
int d[60][60][60][60][2];
struct st {
int lx, ly, rx, ry, c, b;
};
bool operator<(st a, st b) { return a.c > b.c; }
int C(char c) {
if (isdigit(c))
return c - '0';
return 0;
}
int main() {
int w, h;
while (scanf("%d%d", &w, &h), w) {
memset(d, 0x3f, sizeof(d));
priority_queue<st> que;
rep(i, h) rep(j, w) {
scanf("%s", buf);
s[i][j] = buf[0];
}
rep(j, w) {
int i = h - 1;
if (s[i][j] == 'S') {
for (int k = -2; k <= 2; k++) {
int a = 3 - abs(k);
for (int t = 1; t <= a; t++) {
int nx = i + k, ny = j + t;
if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != 'X') {
d[i][j][nx][ny][0] = C(s[nx][ny]);
que.push({i, j, nx, ny, C(s[nx][ny]), 0});
}
nx = i + k, ny = j - t;
if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != 'X') {
d[nx][ny][i][j][1] = C(s[nx][ny]);
que.push({nx, ny, i, j, C(s[nx][ny]), 1});
}
}
}
}
}
while (!que.empty()) {
st p = que.top();
que.pop();
if (d[p.lx][p.ly][p.rx][p.ry][p.b] != p.c)
continue;
for (int k = -2; k <= 2; k++) {
int a = 3 - abs(k);
for (int t = 1; t <= a; t++) {
if (p.b) {
int nx = p.lx + k, ny = p.ly + t;
if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != 'X') {
int &u = d[p.lx][p.ly][nx][ny][!p.b];
int c = p.c + C(s[nx][ny]);
if (u > c) {
u = c;
que.push({p.lx, p.ly, nx, ny, u, !p.b});
}
}
} else {
int nx = p.rx + k, ny = p.ry - t;
if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != 'X') {
int &u = d[nx][ny][p.rx][p.ry][!p.b];
int c = p.c + C(s[nx][ny]);
if (u > c) {
u = c;
que.push({nx, ny, p.rx, p.ry, u, !p.b});
}
}
}
}
}
}
int Min = INF;
rep(i, h) rep(j, w) rep(k, h) rep(t, w) rep(y, 2) {
if (s[i][j] == 'T' || s[k][t] == 'T')
Min = min(Min, d[i][j][k][t][y]);
}
if (Min == INF)
puts("-1");
else
printf("%d\n", Min);
}
} | #include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
char s[60][30], buf[2];
int d[60][30][60][30][2];
struct st {
int lx, ly, rx, ry, c, b;
};
bool operator<(st a, st b) { return a.c > b.c; }
int C(char c) {
if (isdigit(c))
return c - '0';
return 0;
}
int main() {
int w, h;
while (scanf("%d%d", &w, &h), w) {
memset(d, 0x3f, sizeof(d));
priority_queue<st> que;
rep(i, h) rep(j, w) {
scanf("%s", buf);
s[i][j] = buf[0];
}
rep(j, w) {
int i = h - 1;
if (s[i][j] == 'S') {
for (int k = -2; k <= 2; k++) {
int a = 3 - abs(k);
for (int t = 1; t <= a; t++) {
int nx = i + k, ny = j + t;
if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != 'X') {
d[i][j][nx][ny][0] = C(s[nx][ny]);
que.push({i, j, nx, ny, C(s[nx][ny]), 0});
}
nx = i + k, ny = j - t;
if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != 'X') {
d[nx][ny][i][j][1] = C(s[nx][ny]);
que.push({nx, ny, i, j, C(s[nx][ny]), 1});
}
}
}
}
}
while (!que.empty()) {
st p = que.top();
que.pop();
if (d[p.lx][p.ly][p.rx][p.ry][p.b] != p.c)
continue;
for (int k = -2; k <= 2; k++) {
int a = 3 - abs(k);
for (int t = 1; t <= a; t++) {
if (p.b) {
int nx = p.lx + k, ny = p.ly + t;
if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != 'X') {
int &u = d[p.lx][p.ly][nx][ny][!p.b];
int c = p.c + C(s[nx][ny]);
if (u > c) {
u = c;
que.push({p.lx, p.ly, nx, ny, u, !p.b});
}
}
} else {
int nx = p.rx + k, ny = p.ry - t;
if (0 <= nx && nx < h && 0 <= ny && ny < w && s[nx][ny] != 'X') {
int &u = d[nx][ny][p.rx][p.ry][!p.b];
int c = p.c + C(s[nx][ny]);
if (u > c) {
u = c;
que.push({nx, ny, p.rx, p.ry, u, !p.b});
}
}
}
}
}
}
int Min = INF;
rep(i, h) rep(j, w) rep(k, h) rep(t, w) rep(y, 2) {
if (s[i][j] == 'T' || s[k][t] == 'T')
Min = min(Min, d[i][j][k][t][y]);
}
if (Min == INF)
puts("-1");
else
printf("%d\n", Min);
}
} | replace | 10 | 12 | 10 | 12 | MLE | |
p00731 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, (n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2 - 1;
int dx[] = {1, 1, 2, 1, 2, 3, 1, 2, 1};
int dy[] = {-2, -1, -1, 0, 0, 0, 1, 1, 2};
typedef vector<char> vc;
struct state {
int x, y, c;
bool l;
state(int x, int y, int c, bool l) : x(x), y(y), c(c), l(l){};
bool operator<(const state &o) const { return c < o.c; }
};
int get(char c) {
switch (c) {
case 'S':
case 'T':
return 0;
default:
return c - '0';
}
}
int main() {
int w, h;
while (cin >> w >> h, w) {
vector<vc> field(h, vc(w));
REP(i, h) {
REP(j, w) { cin >> field[i][j]; }
}
priority_queue<state> Q;
vector<vvi> cost(2, vvi(h, vi(w, INF)));
REP(i, h) {
REP(j, w) {
if (field[i][j] == 'S') {
Q.push(state(j, i, 0, true));
Q.push(state(j, i, 0, false));
cost[0][i][j] = 0;
cost[1][i][j] = 0;
}
}
}
while (!Q.empty()) {
state st = Q.top();
Q.pop();
int k = (st.l ? 1 : -1);
int l = (st.l ? 1 : 0);
if (field[st.y][st.x] == 'T') {
continue;
}
REP(i, 9) {
int nx = st.x + dx[i] * k;
int ny = st.y + dy[i];
if (0 <= nx && nx < w && 0 <= ny && ny < h && field[ny][nx] != 'X') {
int nc = st.c + get(field[ny][nx]);
if (nc < cost[l][ny][nx]) {
cost[l][ny][nx] = nc;
Q.push(state(nx, ny, nc, !st.l));
}
}
}
}
int ans = INF;
REP(i, h) {
REP(j, w) {
if (field[i][j] == 'T') {
ans = min(ans, cost[0][i][j]);
ans = min(ans, cost[1][i][j]);
}
}
}
if (ans == INF) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
}
return 0;
} | #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, (n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2 - 1;
int dx[] = {1, 1, 2, 1, 2, 3, 1, 2, 1};
int dy[] = {-2, -1, -1, 0, 0, 0, 1, 1, 2};
typedef vector<char> vc;
struct state {
int x, y, c;
bool l;
state(int x, int y, int c, bool l) : x(x), y(y), c(c), l(l){};
bool operator<(const state &o) const { return c > o.c; }
};
int get(char c) {
switch (c) {
case 'S':
case 'T':
return 0;
default:
return c - '0';
}
}
int main() {
int w, h;
while (cin >> w >> h, w) {
vector<vc> field(h, vc(w));
REP(i, h) {
REP(j, w) { cin >> field[i][j]; }
}
priority_queue<state> Q;
vector<vvi> cost(2, vvi(h, vi(w, INF)));
REP(i, h) {
REP(j, w) {
if (field[i][j] == 'S') {
Q.push(state(j, i, 0, true));
Q.push(state(j, i, 0, false));
cost[0][i][j] = 0;
cost[1][i][j] = 0;
}
}
}
while (!Q.empty()) {
state st = Q.top();
Q.pop();
int k = (st.l ? 1 : -1);
int l = (st.l ? 1 : 0);
if (field[st.y][st.x] == 'T') {
continue;
}
REP(i, 9) {
int nx = st.x + dx[i] * k;
int ny = st.y + dy[i];
if (0 <= nx && nx < w && 0 <= ny && ny < h && field[ny][nx] != 'X') {
int nc = st.c + get(field[ny][nx]);
if (nc < cost[l][ny][nx]) {
cost[l][ny][nx] = nc;
Q.push(state(nx, ny, nc, !st.l));
}
}
}
}
int ans = INF;
REP(i, h) {
REP(j, w) {
if (field[i][j] == 'T') {
ans = min(ans, cost[0][i][j]);
ans = min(ans, cost[1][i][j]);
}
}
}
if (ans == INF) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
}
return 0;
} | replace | 55 | 56 | 55 | 56 | TLE | |
p00734 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
using namespace std;
int main() {
int n = 0, m = 1;
int a[n], b[m], x = 0, y = 0;
int p, q;
while (1) {
cin >> n >> m;
x = 0;
y = 0;
p = -1;
q = -1;
if (0 == n + m)
break;
for (int i = 0; i < n; i++) {
cin >> a[i];
x += a[i];
}
for (int j = 0; j < m; j++) {
cin >> b[j];
y += b[j];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((a[i] - b[j]) * 2 == (x - y)) {
if (p == -1) {
p = a[i];
q = b[j];
} else if (p + q > a[i] + b[j]) {
p = a[i];
q = b[j];
}
}
}
}
if (p == -1)
cout << p << endl;
else
cout << p << " " << q << endl;
}
return 0;
} | #include <cstdio>
#include <iostream>
using namespace std;
int main() {
int n = 0, m = 1;
int a[101], b[101], x = 0, y = 0;
int p, q;
while (1) {
cin >> n >> m;
x = 0;
y = 0;
p = -1;
q = -1;
if (0 == n + m)
break;
for (int i = 0; i < n; i++) {
cin >> a[i];
x += a[i];
}
for (int j = 0; j < m; j++) {
cin >> b[j];
y += b[j];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((a[i] - b[j]) * 2 == (x - y)) {
if (p == -1) {
p = a[i];
q = b[j];
} else if (p + q > a[i] + b[j]) {
p = a[i];
q = b[j];
}
}
}
}
if (p == -1)
cout << p << endl;
else
cout << p << " " << q << endl;
}
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p00734 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v), end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
//-----------------------------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int n, m, s1[50], s2[50];
int sum1 = 0, sum2 = 0;
cin >> n >> m;
if (n == 0 && m == 0)
break;
REP(i, n) cin >> s1[i], sum1 += s1[i];
REP(i, m) cin >> s2[i], sum2 += s2[i];
int a = 1e9, b = 1e9;
REP(i, n) REP(j, m) {
if (sum1 - s1[i] + s2[j] == sum2 + s1[i] - s2[j]) {
if (s1[i] + s2[j] < a + b)
a = s1[i], b = s2[j];
}
}
if (a == 1e9)
cout << -1 << endl;
else
cout << a << " " << b << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v), end()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
//-----------------------------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int n, m, s1[100], s2[100];
int sum1 = 0, sum2 = 0;
cin >> n >> m;
if (n == 0 && m == 0)
break;
REP(i, n) cin >> s1[i], sum1 += s1[i];
REP(i, m) cin >> s2[i], sum2 += s2[i];
int a = 1e9, b = 1e9;
REP(i, n) REP(j, m) {
if (sum1 - s1[i] + s2[j] == sum2 + s1[i] - s2[j]) {
if (s1[i] + s2[j] < a + b)
a = s1[i], b = s2[j];
}
}
if (a == 1e9)
cout << -1 << endl;
else
cout << a << " " << b << endl;
}
} | replace | 24 | 25 | 24 | 25 | 0 | |
p00734 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int n, m, sumN = 0, sumM = 0, ii = -1, jj = -1, flag = 0;
int N[100], M[100];
while (1) {
cin >> n;
cin >> m;
for (int i = 0; i < n; ++i) {
cin >> N[i];
sumN += N[i];
}
for (int i = 0; i < m; ++i) {
cin >> M[i];
sumM += M[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (sumN - N[i] + M[j] == sumM - M[j] + N[i] && flag == 0) {
ii = i;
jj = j;
flag = 1;
}
if (sumN - N[i] + M[j] == sumM - M[j] + N[i] && flag == 1 &&
N[ii] + M[jj] > N[i] + M[j]) {
ii = i;
jj = j;
}
}
}
if (ii != -1 && jj != -1) {
cout << N[ii] << " " << M[jj] << endl;
} else
cout << "-1" << endl;
flag = 0;
sumN = 0;
sumM = 0;
ii = -1;
jj = -1;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n, m, sumN = 0, sumM = 0, ii = -1, jj = -1, flag = 0;
int N[100], M[100];
while (1) {
cin >> n;
cin >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; ++i) {
cin >> N[i];
sumN += N[i];
}
for (int i = 0; i < m; ++i) {
cin >> M[i];
sumM += M[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (sumN - N[i] + M[j] == sumM - M[j] + N[i] && flag == 0) {
ii = i;
jj = j;
flag = 1;
}
if (sumN - N[i] + M[j] == sumM - M[j] + N[i] && flag == 1 &&
N[ii] + M[jj] > N[i] + M[j]) {
ii = i;
jj = j;
}
}
}
if (ii != -1 && jj != -1) {
cout << N[ii] << " " << M[jj] << endl;
} else
cout << "-1" << endl;
flag = 0;
sumN = 0;
sumM = 0;
ii = -1;
jj = -1;
}
return 0;
} | insert | 10 | 10 | 10 | 12 | TLE | |
p00734 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = (n)-1; i >= 0; i--)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define REPS(i, f, n) for (int i = (f)-1; i >= (n); i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
void slove(int n, int m) {
vint vtaro(n);
vint vhana(n);
int sumtaro = 0, sumhana = 0;
rep(i, n) {
int tmp;
scanf("%d", &tmp);
sumtaro += tmp;
vtaro[i] = tmp;
}
sort(all(vtaro));
rep(i, m) {
int tmp;
scanf("%d", &tmp);
sumhana += tmp;
vhana[i] = tmp;
}
sort(all(vhana));
double sa = sumtaro - sumhana; //????¨??????????
rep(i, n) {
rep(j, m) {
if (vtaro[i] - vhana[j] == (sa / 2)) {
printf("%d %d\n", vtaro[i], vhana[j]);
return;
}
}
}
printf("-1\n");
return;
}
int main(void) {
int n, m;
rep(i, 1000) {
cin >> n >> m;
if (n == 0)
break;
slove(n, m);
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = (n)-1; i >= 0; i--)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define REPS(i, f, n) for (int i = (f)-1; i >= (n); i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
void slove(int n, int m) {
vint vtaro(n);
vint vhana(m);
int sumtaro = 0, sumhana = 0;
rep(i, n) {
int tmp;
scanf("%d", &tmp);
sumtaro += tmp;
vtaro[i] = tmp;
}
sort(all(vtaro));
rep(i, m) {
int tmp;
scanf("%d", &tmp);
sumhana += tmp;
vhana[i] = tmp;
}
sort(all(vhana));
double sa = sumtaro - sumhana; //????¨??????????
rep(i, n) {
rep(j, m) {
if (vtaro[i] - vhana[j] == (sa / 2)) {
printf("%d %d\n", vtaro[i], vhana[j]);
return;
}
}
}
printf("-1\n");
return;
}
int main(void) {
int n, m;
rep(i, 1000) {
cin >> n >> m;
if (n == 0)
break;
slove(n, m);
}
return 0;
} | replace | 32 | 33 | 32 | 33 | 0 | |
p00734 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (m == 0)
break;
int t[n], h[n];
for (int i = 0; i < n; i++)
cin >> t[i];
for (int i = 0; i < m; i++)
cin >> h[i];
int sumt = 0, sumh = 0;
for (int i = 0; i < n; i++)
sumt += t[i];
for (int i = 0; i < m; i++)
sumh += h[i];
int x, y, min = 1000;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (sumt - t[i] + h[j] == sumh + t[i] - h[j]) {
if (t[i] + h[j] < min) {
min = t[i] + h[j];
x = t[i];
y = h[j];
}
}
}
}
if (min == 1000)
cout << -1 << endl;
else
cout << x << ' ' << y << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (m == 0)
break;
int t[n], h[m];
for (int i = 0; i < n; i++)
cin >> t[i];
for (int i = 0; i < m; i++)
cin >> h[i];
int sumt = 0, sumh = 0;
for (int i = 0; i < n; i++)
sumt += t[i];
for (int i = 0; i < m; i++)
sumh += h[i];
int x, y, min = 1000;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (sumt - t[i] + h[j] == sumh + t[i] - h[j]) {
if (t[i] + h[j] < min) {
min = t[i] + h[j];
x = t[i];
y = h[j];
}
}
}
}
if (min == 1000)
cout << -1 << endl;
else
cout << x << ' ' << y << endl;
}
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p00734 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#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 pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
while (1) {
int t, h;
cin >> t >> h;
vector<int> td;
vector<int> hd;
int tsum = 0;
int hsum = 0;
REP(i, t) {
int tmp;
cin >> tmp;
td.pb(tmp);
tsum += tmp;
}
REP(i, h) {
int tmp;
cin >> tmp;
hd.pb(tmp);
hsum += tmp;
}
int ansx = 114514;
int ansy = 114514;
REP(i, t) {
REP(j, h) {
if (tsum - td[i] + hd[j] == hsum - hd[j] + td[i]) {
if ((ansx + ansy) > (i + j)) {
ansx = i;
ansy = j;
i = t;
j = h;
}
}
}
}
if (ansx == 114514)
cout << -1 << endl;
else
cout << td[ansx] << " " << hd[ansy] << endl;
}
} | #include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#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 pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
while (1) {
int t, h;
cin >> t >> h;
if (t == 0 && h == 0)
break;
vector<int> td;
vector<int> hd;
int tsum = 0;
int hsum = 0;
REP(i, t) {
int tmp;
cin >> tmp;
td.pb(tmp);
tsum += tmp;
}
REP(i, h) {
int tmp;
cin >> tmp;
hd.pb(tmp);
hsum += tmp;
}
int ansx = 114514;
int ansy = 114514;
REP(i, t) {
REP(j, h) {
if (tsum - td[i] + hd[j] == hsum - hd[j] + td[i]) {
if ((ansx + ansy) > (i + j)) {
ansx = i;
ansy = j;
i = t;
j = h;
}
}
}
}
if (ansx == 114514)
cout << -1 << endl;
else
cout << td[ansx] << " " << hd[ansy] << endl;
}
} | insert | 26 | 26 | 26 | 28 | TLE | |
p00734 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define fr first
#define sc second
#define mp make_pair
typedef long long int64;
typedef pair<int, int> iP;
typedef pair<iP, int> iiP;
const int INF = 2 << 28;
const double EPS = 1e-10;
int main() {
int n, m;
while (cin >> n >> m, n) {
int sumt = 0, sumh = 0;
vector<int> ts(n), hs(n);
for (int i = 0; i < n; i++) {
cin >> ts[i];
sumt += ts[i];
}
for (int i = 0; i < m; i++) {
cin >> hs[i];
sumh += hs[i];
}
int mint = INF, minh = INF;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (sumt - ts[i] + hs[j] == sumh - hs[j] + ts[i] &&
mint + minh > ts[i] + hs[j])
mint = ts[i], minh = hs[j];
}
}
if (mint == INF)
cout << -1 << endl;
else
cout << mint << " " << minh << endl;
}
} | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define fr first
#define sc second
#define mp make_pair
typedef long long int64;
typedef pair<int, int> iP;
typedef pair<iP, int> iiP;
const int INF = 2 << 28;
const double EPS = 1e-10;
int main() {
int n, m;
while (cin >> n >> m, n) {
int sumt = 0, sumh = 0;
vector<int> ts(n), hs(m);
for (int i = 0; i < n; i++) {
cin >> ts[i];
sumt += ts[i];
}
for (int i = 0; i < m; i++) {
cin >> hs[i];
sumh += hs[i];
}
int mint = INF, minh = INF;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (sumt - ts[i] + hs[j] == sumh - hs[j] + ts[i] &&
mint + minh > ts[i] + hs[j])
mint = ts[i], minh = hs[j];
}
}
if (mint == INF)
cout << -1 << endl;
else
cout << mint << " " << minh << endl;
}
} | replace | 37 | 38 | 37 | 38 | 0 | |
p00734 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
while (true) {
cin >> n >> m;
vector<int> a(n);
vector<int> b(n);
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
// ??????????????????
int suma = 0, sumb = 0;
for (int i = 0; i < n; i++)
suma += a[i];
for (int i = 0; i < m; i++)
sumb += b[i];
vector<pair<int, int>> res;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if ((suma - a[i] + b[j]) == (sumb - b[j] + a[i])) {
res.push_back(make_pair(i, j));
}
if (res.size() == 0)
cout << -1 << endl;
else {
int tmpa, tmpb, r = 999999999, tmp;
for (int i = 0; i < res.size(); i++) {
tmp = a[res[i].first] + b[res[i].second];
if (tmp < r) {
r = tmp;
tmpa = res[i].first;
tmpb = res[i].second;
}
}
cout << a[tmpa] << " " << b[tmpb] << endl;
}
}
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
while (true) {
cin >> n >> m;
vector<int> a(n);
vector<int> b(m);
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < m; i++)
cin >> b[i];
// ??????????????????
int suma = 0, sumb = 0;
for (int i = 0; i < n; i++)
suma += a[i];
for (int i = 0; i < m; i++)
sumb += b[i];
vector<pair<int, int>> res;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if ((suma - a[i] + b[j]) == (sumb - b[j] + a[i])) {
res.push_back(make_pair(i, j));
}
if (res.size() == 0)
cout << -1 << endl;
else {
int tmpa, tmpb, r = 999999999, tmp;
for (int i = 0; i < res.size(); i++) {
tmp = a[res[i].first] + b[res[i].second];
if (tmp < r) {
r = tmp;
tmpa = res[i].first;
tmpb = res[i].second;
}
}
cout << a[tmpa] << " " << b[tmpb] << endl;
}
}
} | replace | 12 | 13 | 12 | 13 | 0 | |
p00734 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
typedef pair<int, int> P;
int main() {
int n, m;
while (cin >> n >> m && n) {
int sum = 0;
vector<int> p(n), q(n);
rep(i, n) {
cin >> p[i];
sum += p[i];
}
rep(i, m) {
cin >> q[i];
sum -= q[i];
}
int ap = INF, aq = INF;
for (int pn : p)
for (int qn : q)
if (2 * (pn - qn) == sum && pn + qn < ap + aq) {
ap = pn;
aq = qn;
}
if (ap == INF) {
puts("-1");
} else {
cout << ap << ' ' << aq << endl;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
typedef pair<int, int> P;
int main() {
int n, m;
while (cin >> n >> m && n) {
int sum = 0;
vector<int> p(n), q(m);
rep(i, n) {
cin >> p[i];
sum += p[i];
}
rep(i, m) {
cin >> q[i];
sum -= q[i];
}
int ap = INF, aq = INF;
for (int pn : p)
for (int qn : q)
if (2 * (pn - qn) == sum && pn + qn < ap + aq) {
ap = pn;
aq = qn;
}
if (ap == INF) {
puts("-1");
} else {
cout << ap << ' ' << aq << endl;
}
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p00734 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double EPS = 1e-10;
int main() {
for (int n, m; cin >> n >> m, (n | m) != 0;) {
int taro[100], hanako[100];
int t_sum = 0, h_sum = 0;
rep(i, n) {
cin >> taro[i];
t_sum += taro[i];
}
rep(i, m) {
cin >> hanako[i];
h_sum += hanako[i];
}
int ans_t, ans_h;
int min = INF;
rep(i, n) rep(j, m) {
int t = t_sum - taro[i] + hanako[j];
int h = h_sum - hanako[j] + taro[i];
if (t == h && min > taro[i] + hanako[j]) {
min = taro[i] + hanako[j];
ans_t = taro[i];
ans_h = hanako[j];
}
}
dump("#");
if (min == INF)
cout << -1 << endl;
else
cout << ans_t << ' ' << ans_h << endl;
}
return 0;
} | #include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double EPS = 1e-10;
int main() {
for (int n, m; cin >> n >> m, (n | m) != 0;) {
int taro[100], hanako[100];
int t_sum = 0, h_sum = 0;
rep(i, n) {
cin >> taro[i];
t_sum += taro[i];
}
rep(i, m) {
cin >> hanako[i];
h_sum += hanako[i];
}
int ans_t, ans_h;
int min = INF;
rep(i, n) rep(j, m) {
int t = t_sum - taro[i] + hanako[j];
int h = h_sum - hanako[j] + taro[i];
if (t == h && min > taro[i] + hanako[j]) {
min = taro[i] + hanako[j];
ans_t = taro[i];
ans_h = hanako[j];
}
}
if (min == INF)
cout << -1 << endl;
else
cout << ans_t << ' ' << ans_h << endl;
}
return 0;
} | delete | 64 | 65 | 64 | 64 | 0 | > "#" = #
> "#" = #
> "#" = #
> "#" = #
> "#" = #
|
p00734 | C++ | Runtime Error | #include <iostream>
#include <limits.h>
#include <vector>
using namespace std;
int main() {
int n, m, mi, mih, mit;
while (cin >> n >> m && n && m) {
vector<int> taro(n);
vector<int> hanako(n);
int t = 0, h = 0;
for (int i = 0; i < n; i++) {
cin >> taro[i];
t += taro[i];
}
for (int i = 0; i < m; i++) {
cin >> hanako[i];
h += hanako[i];
}
mi = (1 << 21);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (t - taro[i] + hanako[j] == h - hanako[j] + taro[i]) {
if (taro[i] + hanako[j] < mi) {
mi = taro[i] + hanako[j];
mit = taro[i];
mih = hanako[j];
}
}
}
}
if (mi == 1 << 21)
cout << -1 << endl;
else
cout << mit << " " << mih << endl;
}
} | #include <iostream>
#include <limits.h>
#include <vector>
using namespace std;
int main() {
int n, m, mi, mih, mit;
while (cin >> n >> m && n && m) {
vector<int> taro(n);
vector<int> hanako(m);
int t = 0, h = 0;
for (int i = 0; i < n; i++) {
cin >> taro[i];
t += taro[i];
}
for (int i = 0; i < m; i++) {
cin >> hanako[i];
h += hanako[i];
}
mi = (1 << 21);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (t - taro[i] + hanako[j] == h - hanako[j] + taro[i]) {
if (taro[i] + hanako[j] < mi) {
mi = taro[i] + hanako[j];
mit = taro[i];
mih = hanako[j];
}
}
}
}
if (mi == 1 << 21)
cout << -1 << endl;
else
cout << mit << " " << mih << endl;
}
} | replace | 9 | 10 | 9 | 10 | 0 | |
p00734 | C++ | Runtime Error | #include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int d, m, n, t[51], h[51];
while (1) {
int st = 0, sh = 0, mint = 101;
cin >> n >> m;
if (n == 0 && m == 0)
return 0;
for (int i = 0; i < n; i++)
cin >> t[i];
for (int i = 0; i < m; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
st += t[i];
for (int i = 0; i < m; i++)
sh += h[i];
d = st - sh;
if (d % 2 != 0) {
cout << -1 << endl;
continue;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
if (t[i] - h[j] == d / 2 && t[i] < mint)
mint = t[i];
}
if (mint < 101)
cout << mint << " " << mint - d / 2 << endl;
else
cout << -1 << endl;
}
} | #include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int d, m, n, t[101], h[101];
while (1) {
int st = 0, sh = 0, mint = 101;
cin >> n >> m;
if (n == 0 && m == 0)
return 0;
for (int i = 0; i < n; i++)
cin >> t[i];
for (int i = 0; i < m; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
st += t[i];
for (int i = 0; i < m; i++)
sh += h[i];
d = st - sh;
if (d % 2 != 0) {
cout << -1 << endl;
continue;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
if (t[i] - h[j] == d / 2 && t[i] < mint)
mint = t[i];
}
if (mint < 101)
cout << mint << " " << mint - d / 2 << endl;
else
cout << -1 << endl;
}
} | replace | 9 | 10 | 9 | 10 | 0 | |
p00734 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// container util
#define all(x) (x).begin(), (x).end()
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;
// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
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};
// conversion
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
//
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
//
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
while (true) {
cin >> n >> m;
if (n == 0 && m == 0)
break;
vector<int> t(n), h(n);
int tt = 0, th = 0;
rep(i, n) cin >> t[i], tt += t[i];
rep(i, m) cin >> h[i], th += h[i];
int sum = 1e9, tans = -1, hans = -1;
rep(i, n) {
tt -= t[i];
rep(j, m) {
th -= h[j];
if (tt + h[j] == th + t[i]) {
if (t[i] + h[j] < sum) {
tans = t[i];
hans = h[j];
chmin(sum, t[i] + h[j]);
}
}
th += h[j];
}
tt += t[i];
}
if (tans == -1 && hans == -1)
cout << -1 << "\n";
else
cout << tans << " " << hans << "\n";
}
return 0;
}
| #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// container util
#define all(x) (x).begin(), (x).end()
// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;
// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
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};
// conversion
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
//
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
//
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
while (true) {
cin >> n >> m;
if (n == 0 && m == 0)
break;
vector<int> t(n), h(m);
int tt = 0, th = 0;
rep(i, n) cin >> t[i], tt += t[i];
rep(i, m) cin >> h[i], th += h[i];
int sum = 1e9, tans = -1, hans = -1;
rep(i, n) {
tt -= t[i];
rep(j, m) {
th -= h[j];
if (tt + h[j] == th + t[i]) {
if (t[i] + h[j] < sum) {
tans = t[i];
hans = h[j];
chmin(sum, t[i] + h[j]);
}
}
th += h[j];
}
tt += t[i];
}
if (tans == -1 && hans == -1)
cout << -1 << "\n";
else
cout << tans << " " << hans << "\n";
}
return 0;
}
| replace | 74 | 75 | 74 | 75 | 0 | |
p00734 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m;
while (1) {
cin >> n >> m;
if (n == 0 && m == 0)
break;
int i, j, temp = 0, k, count = 0;
int t[n], h[m], sum1 = 0, sum2 = 0;
int d[100], e[100];
bool cando = false;
for (i = 0; i < n; i++) {
cin >> t[i];
}
for (i = 0; i < m; i++) {
cin >> h[i];
}
sort(t, t + n);
sort(h, h + m);
for (i = 0; i < n; i++) {
sum1 += t[i];
}
for (i = 0; i < m; i++) {
sum2 += h[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (sum1 - t[i] + h[j] == sum2 - h[j] + t[i]) {
cando = true;
d[count] = t[i];
e[count] = h[j];
count++;
}
}
}
if (!cando) {
cout << "-1" << endl;
} else if (cando) {
for (i = 0; i < count; i++) {
for (j = i + 1; j < count; j++) {
if (d[i] + e[i] > d[j] + e[j]) {
temp = d[i];
d[i] = d[i + 1];
d[i + 1] = temp;
temp = e[i];
e[i] = e[i + 1];
e[i + 1] = temp;
}
}
}
cout << d[0] << " " << e[0] << endl;
}
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, m;
while (1) {
cin >> n >> m;
if (n == 0 && m == 0)
break;
int i, j, temp = 0, k, count = 0;
int t[n], h[m], sum1 = 0, sum2 = 0;
int d[10000], e[10000];
bool cando = false;
for (i = 0; i < n; i++) {
cin >> t[i];
}
for (i = 0; i < m; i++) {
cin >> h[i];
}
sort(t, t + n);
sort(h, h + m);
for (i = 0; i < n; i++) {
sum1 += t[i];
}
for (i = 0; i < m; i++) {
sum2 += h[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (sum1 - t[i] + h[j] == sum2 - h[j] + t[i]) {
cando = true;
d[count] = t[i];
e[count] = h[j];
count++;
}
}
}
if (!cando) {
cout << "-1" << endl;
} else if (cando) {
for (i = 0; i < count; i++) {
for (j = i + 1; j < count; j++) {
if (d[i] + e[i] > d[j] + e[j]) {
temp = d[i];
d[i] = d[i + 1];
d[i + 1] = temp;
temp = e[i];
e[i] = e[i + 1];
e[i + 1] = temp;
}
}
}
cout << d[0] << " " << e[0] << endl;
}
}
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p00734 | C++ | Time Limit Exceeded | #include "algorithm"
#include "cmath"
#include "iomanip"
#include "iostream"
#include "map"
#include "set"
#include "string"
using namespace std;
#define TEST 1
#if TEST
FILE *in = freopen("./Q/question.txt", "r", stdin);
FILE *out = freopen("./A/answer.txt", "w", stdout);
#endif
int main() {
int n, m;
while (true) {
int sa = 0, ans = 201, idxi = -1, idxj = -1;
cin >> n >> m;
set<int> tarous, hanakos;
if (!n && !m)
break;
for (int i = 0; i < n + m; ++i) {
int a;
cin >> a;
if (i < n) {
tarous.insert(a);
sa += a;
} else {
hanakos.insert(a);
sa -= a;
}
}
// cout <<sa<<endl;
// cout <<tarousum <<" "<<hanakosum <<endl;
if (!(sa & 1)) {
bool FLAG = false;
for (auto &&itr1 = tarous.begin(); itr1 != tarous.end(); ++itr1) {
for (auto &&itr2 = hanakos.begin(); itr2 != hanakos.end(); ++itr2) {
if (*itr1 - *itr2 == sa / 2) {
if (ans > *itr1 + *itr2) {
ans = *itr1 + *itr2;
idxi = *itr1;
idxj = *itr2;
FLAG = true;
break;
}
}
}
if (FLAG)
break;
}
}
if (ans == 201)
cout << -1 << endl;
else
cout << idxi << " " << idxj << endl;
tarous.clear();
hanakos.clear();
}
#if TEST
fclose(in);
fclose(out);
#endif
return 0;
} | #include "algorithm"
#include "cmath"
#include "iomanip"
#include "iostream"
#include "map"
#include "set"
#include "string"
using namespace std;
#define TEST 0
#if TEST
FILE *in = freopen("./Q/question.txt", "r", stdin);
FILE *out = freopen("./A/answer.txt", "w", stdout);
#endif
int main() {
int n, m;
while (true) {
int sa = 0, ans = 201, idxi = -1, idxj = -1;
cin >> n >> m;
set<int> tarous, hanakos;
if (!n && !m)
break;
for (int i = 0; i < n + m; ++i) {
int a;
cin >> a;
if (i < n) {
tarous.insert(a);
sa += a;
} else {
hanakos.insert(a);
sa -= a;
}
}
// cout <<sa<<endl;
// cout <<tarousum <<" "<<hanakosum <<endl;
if (!(sa & 1)) {
bool FLAG = false;
for (auto &&itr1 = tarous.begin(); itr1 != tarous.end(); ++itr1) {
for (auto &&itr2 = hanakos.begin(); itr2 != hanakos.end(); ++itr2) {
if (*itr1 - *itr2 == sa / 2) {
if (ans > *itr1 + *itr2) {
ans = *itr1 + *itr2;
idxi = *itr1;
idxj = *itr2;
FLAG = true;
break;
}
}
}
if (FLAG)
break;
}
}
if (ans == 201)
cout << -1 << endl;
else
cout << idxi << " " << idxj << endl;
tarous.clear();
hanakos.clear();
}
#if TEST
fclose(in);
fclose(out);
#endif
return 0;
} | replace | 9 | 10 | 9 | 10 | TLE | |
p00734 | C++ | Time Limit Exceeded |
#include "iostream"
using namespace std;
int main() {
while (1) {
int n, m, t[100], h[100], sumt = 0, sumh = 0, mint = 101, minh = 101;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++) {
cin >> t[i];
sumt += t[i];
}
for (int i = 0; i < m; i++) {
cin >> h[i];
sumh += h[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; i++) {
if (sumt - t[i] + h[j] == sumh - h[j] + t[i]) {
if (h[j] + t[i] < mint + minh) {
mint = t[i];
minh = h[j];
}
}
}
}
if (mint == 101 && minh == 101)
cout << "-1" << endl;
else
cout << mint << " " << minh << endl;
}
return 0;
}
|
#include "iostream"
using namespace std;
int main() {
while (1) {
int n, m, t[100], h[100], sumt = 0, sumh = 0, mint = 101, minh = 101;
cin >> n >> m;
if (n == 0 && m == 0)
break;
for (int i = 0; i < n; i++) {
cin >> t[i];
sumt += t[i];
}
for (int i = 0; i < m; i++) {
cin >> h[i];
sumh += h[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (sumt - t[i] + h[j] == sumh - h[j] + t[i]) {
if (h[j] + t[i] < mint + minh) {
mint = t[i];
minh = h[j];
}
}
}
}
if (mint == 101 && minh == 101)
cout << "-1" << endl;
else
cout << mint << " " << minh << endl;
}
return 0;
}
| replace | 18 | 19 | 18 | 19 | TLE | |
p00734 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m, n && m) {
int sum1 = 0, sum2 = 0;
int s1[50], s2[50];
int a = 1e8, b = 1e8;
for (int i = 0; i < n; i++)
cin >> s1[i], sum1 += s1[i];
for (int i = 0; i < m; i++)
cin >> s2[i], sum2 += s2[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((s1[i] - s2[j]) * 2 == sum1 - sum2 && a + b > s1[i] + s2[j])
a = s1[i], b = s2[j];
}
}
if (a == 1e8)
cout << -1 << endl;
else
cout << a << " " << b << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m, n && m) {
int sum1 = 0, sum2 = 0;
int s1[100], s2[100];
int a = 1e8, b = 1e8;
for (int i = 0; i < n; i++)
cin >> s1[i], sum1 += s1[i];
for (int i = 0; i < m; i++)
cin >> s2[i], sum2 += s2[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if ((s1[i] - s2[j]) * 2 == sum1 - sum2 && a + b > s1[i] + s2[j])
a = s1[i], b = s2[j];
}
}
if (a == 1e8)
cout << -1 << endl;
else
cout << a << " " << b << endl;
}
} | replace | 7 | 8 | 7 | 8 | 0 | |
p00735 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define TEST 0
#if TEST
FILE *in = freopen("./Q.txt", "r", stdin);
FILE *out = freopen("./A.txt", "w", stdout);
#endif
#define MAXN 300000
vector<int> MSPrimes;
bool isNotMSPrime[MAXN];
void calMSPrime(int n) {
for (int i = 2; i * n <= MAXN; i++) {
isNotMSPrime[i * n] = true;
}
}
int main(int argc, const char *argv[]) {
for (int i = 2; i < MAXN; i++) {
if (!isNotMSPrime[i] && (i % 7 == 1 || i % 7 == 6)) {
calMSPrime(i);
MSPrimes.push_back(i);
}
}
while (1) {
int n;
cin >> n;
if (n == 1)
break;
set<int> primes;
for (unsigned id = 0; id < MSPrimes.size() && n >= MSPrimes[id]; id++) {
if (n % MSPrimes[id] != 0)
continue;
int nowId = id, nowN = n;
while (nowId < MSPrimes.size() && nowN >= MSPrimes[nowId]) {
int nowPrime = MSPrimes[nowId];
bool ok = false;
while (nowN % nowPrime == 0) {
ok = true;
nowN /= nowPrime;
}
if (ok)
primes.insert(nowPrime);
nowId++;
}
}
cout << n << ":";
for (auto i = primes.begin(); i != primes.end(); i++) {
cout << " " << *i;
}
cout << endl;
primes.clear();
}
#if TEST
fclose(in);
fclose(out);
#endif
} | #include <cstdio>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define TEST 0
#if TEST
FILE *in = freopen("./Q.txt", "r", stdin);
FILE *out = freopen("./A.txt", "w", stdout);
#endif
#define MAXN 300000
vector<int> MSPrimes;
bool isNotMSPrime[MAXN];
void calMSPrime(int n) {
for (int i = 2; i * n < MAXN; i++) {
isNotMSPrime[i * n] = true;
}
}
int main(int argc, const char *argv[]) {
for (int i = 2; i < MAXN; i++) {
if (!isNotMSPrime[i] && (i % 7 == 1 || i % 7 == 6)) {
calMSPrime(i);
MSPrimes.push_back(i);
}
}
while (1) {
int n;
cin >> n;
if (n == 1)
break;
set<int> primes;
for (unsigned id = 0; id < MSPrimes.size() && n >= MSPrimes[id]; id++) {
if (n % MSPrimes[id] != 0)
continue;
int nowId = id, nowN = n;
while (nowId < MSPrimes.size() && nowN >= MSPrimes[nowId]) {
int nowPrime = MSPrimes[nowId];
bool ok = false;
while (nowN % nowPrime == 0) {
ok = true;
nowN /= nowPrime;
}
if (ok)
primes.insert(nowPrime);
nowId++;
}
}
cout << n << ":";
for (auto i = primes.begin(); i != primes.end(); i++) {
cout << " " << *i;
}
cout << endl;
primes.clear();
}
#if TEST
fclose(in);
fclose(out);
#endif
} | replace | 18 | 19 | 18 | 19 | 0 | |
p00735 | C++ | Runtime Error | #include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
#define FOR(i, init, n) for (int i = init; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define MON 1
#define SAT 6
int isPrime(int cand) {
// int i, limit;
int limit = sqrt(cand);
// limit = (int)sqrt((double)cand);
int i = limit;
if (cand < 2) {
return (0);
}
while (i > 1) {
if (cand % i == 0) {
break;
}
i--;
}
// for (; i > 1; i--){
// //for (i = limit; i > 1; i--){
// if (cand % i == 0){
// break;
// }
// }
if (i == 1) {
return (1);
} else {
return (0);
}
// else{
// return(0);
// }
}
int isMonSatPrime(int cand) {
if (cand % 7 != 1 && cand % 7 != 6) {
return (0);
}
if (cand < 2) {
return (0);
}
int i = 6;
int next = MON;
while (i > 1) {
if (cand % i == 0) {
break;
}
i += next == SAT ? 5 : 2;
next = next == SAT ? MON : SAT;
// if (next == SAT){
// i += 5;
// next = MON;
// }
// else if (next == MON){
// i += 2;
// next = SAT;
// }
}
return i == cand ? 1 : 0;
// if (i == (cand)){
// return(1);
// }
// else{
// //puts("?????????????´???°??§??????????????????");
// return(0);
// }
}
int main() {
// FILE* fin = freopen("input.txt", "r", stdin);
// FILE* fout = freopen("output.txt", "w", stdout);
while (1) {
int num;
scanf("%d", &num);
if (num == 1) {
break;
}
printf("%d:", num);
// int i = 6;
int next = MON;
for (int i = 0; i <= num;
i += next == SAT ? 5 : 2, next = next == SAT ? MON : SAT) {
if (num % i == 0) {
if (isMonSatPrime(i) == 1) {
printf(" %d", i);
}
}
}
// while (i <= num){
// if (num%i == 0){
// if (isMonSatPrime(i) == 1){
// printf(" %d", i);
// }
// }
// i += next == SAT ? 2 : 5;
// next = next == SAT ? MON : SAT;
// //if (next == SAT){
// // i += 5;
// // next = MON;
// //}
// //else if (next == MON){
// // i += 2;
// // next = SAT;
// //}
// }
puts("");
}
return 0;
} | #include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
#define FOR(i, init, n) for (int i = init; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define MON 1
#define SAT 6
int isPrime(int cand) {
// int i, limit;
int limit = sqrt(cand);
// limit = (int)sqrt((double)cand);
int i = limit;
if (cand < 2) {
return (0);
}
while (i > 1) {
if (cand % i == 0) {
break;
}
i--;
}
// for (; i > 1; i--){
// //for (i = limit; i > 1; i--){
// if (cand % i == 0){
// break;
// }
// }
if (i == 1) {
return (1);
} else {
return (0);
}
// else{
// return(0);
// }
}
int isMonSatPrime(int cand) {
if (cand % 7 != 1 && cand % 7 != 6) {
return (0);
}
if (cand < 2) {
return (0);
}
int i = 6;
int next = MON;
while (i > 1) {
if (cand % i == 0) {
break;
}
i += next == SAT ? 5 : 2;
next = next == SAT ? MON : SAT;
// if (next == SAT){
// i += 5;
// next = MON;
// }
// else if (next == MON){
// i += 2;
// next = SAT;
// }
}
return i == cand ? 1 : 0;
// if (i == (cand)){
// return(1);
// }
// else{
// //puts("?????????????´???°??§??????????????????");
// return(0);
// }
}
int main() {
// FILE* fin = freopen("input.txt", "r", stdin);
// FILE* fout = freopen("output.txt", "w", stdout);
while (1) {
int num;
scanf("%d", &num);
if (num == 1) {
break;
}
printf("%d:", num);
// int i = 6;
int next = MON;
for (int i = 6; i <= num;
i += next == SAT ? 5 : 2, next = next == SAT ? MON : SAT) {
if (num % i == 0) {
if (isMonSatPrime(i) == 1) {
printf(" %d", i);
}
}
}
// while (i <= num){
// if (num%i == 0){
// if (isMonSatPrime(i) == 1){
// printf(" %d", i);
// }
// }
// i += next == SAT ? 2 : 5;
// next = next == SAT ? MON : SAT;
// //if (next == SAT){
// // i += 5;
// // next = MON;
// //}
// //else if (next == MON){
// // i += 2;
// // next = SAT;
// //}
// }
puts("");
}
return 0;
} | replace | 101 | 102 | 101 | 102 | -8 | |
p00735 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
bool a[300001];
int main() {
vector<int> p;
p.push_back(6);
for (int i = 1; i <= 50000; i++) {
a[6 * i] = 1;
}
for (int i = 1; 7 * i + 1 <= 300000; i++) {
if (a[7 * i + 1] == 0) {
p.push_back(7 * i + 1);
for (int j = 7 * i + 1; j <= 300000; j += 7 * i + 1) {
a[j] = 1;
}
}
if (a[7 * i + 6] == 0) {
p.push_back(7 * i + 6);
for (int j = 7 * i + 6; j <= 300000; j += 7 * i + 6) {
a[j] = 1;
}
}
}
int n;
while (cin >> n && n != 1) {
vector<int> v;
for (int i = 0; i < p.size(); i++) {
if (n % p[i] == 0) {
v.push_back(p[i]);
}
}
cout << n << ":";
for (int i = 0; i < v.size(); i++) {
cout << " " << v[i];
}
cout << endl;
}
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
bool a[500001];
int main() {
vector<int> p;
p.push_back(6);
for (int i = 1; i <= 50000; i++) {
a[6 * i] = 1;
}
for (int i = 1; 7 * i + 1 <= 300000; i++) {
if (a[7 * i + 1] == 0) {
p.push_back(7 * i + 1);
for (int j = 7 * i + 1; j <= 300000; j += 7 * i + 1) {
a[j] = 1;
}
}
if (a[7 * i + 6] == 0) {
p.push_back(7 * i + 6);
for (int j = 7 * i + 6; j <= 300000; j += 7 * i + 6) {
a[j] = 1;
}
}
}
int n;
while (cin >> n && n != 1) {
vector<int> v;
for (int i = 0; i < p.size(); i++) {
if (n % p[i] == 0) {
v.push_back(p[i]);
}
}
cout << n << ":";
for (int i = 0; i < v.size(); i++) {
cout << " " << v[i];
}
cout << endl;
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p00735 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define rep(i, s, g) for (ll(i) = (s); (i) < (g); ++i)
#define rrep(i, s, g) for (ll(i) = (s); i >= (g); --(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
for (int WWW = 0; WWW < (n); WWW++) \
cerr << v[WWW] << ' '; \
cerr << endl << endl; \
}
#define SHOW2d(v, i, j) \
{ \
for (int aaa = 0; aaa < i; aaa++) { \
for (int bbb = 0; bbb < j; bbb++) \
cerr << v[aaa][bbb] << ' '; \
cerr << endl; \
} \
cerr << endl; \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
vector<ll> v;
bool seica[333333];
void f() {
for (int i = 2; i < 333333; i++) {
if (i % 7 == 1 || i % 7 == 6) {
if (!seica[i]) {
v.PB(i);
for (int j = 2 * i; j < 333333; j += i) {
seica[j] = true;
}
}
}
}
}
int main() {
int n;
f();
while (cin >> n, n) {
cout << n << ':';
REP(i, v.size()) {
if (n % v[i] == 0) {
printf(" %d", v[i]);
}
if (v[i] > n)
break;
}
printf("\n");
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define rep(i, s, g) for (ll(i) = (s); (i) < (g); ++i)
#define rrep(i, s, g) for (ll(i) = (s); i >= (g); --(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
for (int WWW = 0; WWW < (n); WWW++) \
cerr << v[WWW] << ' '; \
cerr << endl << endl; \
}
#define SHOW2d(v, i, j) \
{ \
for (int aaa = 0; aaa < i; aaa++) { \
for (int bbb = 0; bbb < j; bbb++) \
cerr << v[aaa][bbb] << ' '; \
cerr << endl; \
} \
cerr << endl; \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
vector<ll> v;
bool seica[333333];
void f() {
for (int i = 2; i < 333333; i++) {
if (i % 7 == 1 || i % 7 == 6) {
if (!seica[i]) {
v.PB(i);
for (int j = 2 * i; j < 333333; j += i) {
seica[j] = true;
}
}
}
}
}
int main() {
int n;
f();
while (cin >> n, n != 1) {
cout << n << ':';
REP(i, v.size()) {
if (n % v[i] == 0) {
printf(" %d", v[i]);
}
if (v[i] > n)
break;
}
printf("\n");
}
return 0;
}
| replace | 60 | 61 | 60 | 61 | TLE | |
p00735 | C++ | Time Limit Exceeded |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int MAX = 300005;
bool isPrime[MAX];
vector<int> mt;
void makePrime() {
for (int i = 6; i < MAX; i++) {
isPrime[i] = true;
}
for (int i = 2; i < MAX; i++) {
if (isPrime[i] && (i % 7 == 6 || i % 7 == 1)) {
mt.push_back(i);
for (int j = 2 * i; j < MAX; j += i) {
isPrime[j] = false;
}
}
}
return;
}
int main() {
int n;
makePrime();
int len = mt.size();
while (cin >> n, n) {
set<int> SET;
for (int i = 0; i < len; i++) {
if (n % mt[i] == 0) {
SET.insert(mt[i]);
}
}
cout << n << ":";
for (auto s : SET) {
cout << " " << s;
}
cout << '\n';
}
return 0;
} |
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int MAX = 300005;
bool isPrime[MAX];
vector<int> mt;
void makePrime() {
for (int i = 6; i < MAX; i++) {
isPrime[i] = true;
}
for (int i = 2; i < MAX; i++) {
if (isPrime[i] && (i % 7 == 6 || i % 7 == 1)) {
mt.push_back(i);
for (int j = 2 * i; j < MAX; j += i) {
isPrime[j] = false;
}
}
}
return;
}
int main() {
int n;
makePrime();
int len = mt.size();
while (cin >> n, n != 1) {
set<int> SET;
for (int i = 0; i < len; i++) {
if (n % mt[i] == 0) {
SET.insert(mt[i]);
}
}
cout << n << ":";
for (auto s : SET) {
cout << " " << s;
}
cout << '\n';
}
return 0;
} | replace | 41 | 42 | 41 | 42 | TLE | |
p00735 | C++ | Time Limit Exceeded | #include <iostream>
#include <vector>
const int size = 300000;
bool a[size] = {false};
std::vector<int> MS;
void eratos() {
for (int i = 6; i < size; i++)
a[i] = true;
for (int i = 6; i < size; i++) {
if (a[i] && (i % 7 == 1 || i % 7 == 6)) {
MS.push_back(i);
for (int j = i + i; j < size; j += i)
a[j] = false;
} else
a[i] = false;
}
}
void solve(int x) {
std::vector<int>::iterator it = MS.begin();
std::cout << x << ':';
for (; it != MS.end(); ++it)
if (x % (*it) == 0)
std::cout << ' ' << *it;
std::cout << std::endl;
}
int main() {
int x;
eratos();
while (true) {
std::cin >> x;
if (x == 0)
break;
solve(x);
}
return 0;
} | #include <iostream>
#include <vector>
const int size = 300000;
bool a[size] = {false};
std::vector<int> MS;
void eratos() {
for (int i = 6; i < size; i++)
a[i] = true;
for (int i = 6; i < size; i++) {
if (a[i] && (i % 7 == 1 || i % 7 == 6)) {
MS.push_back(i);
for (int j = i + i; j < size; j += i)
a[j] = false;
} else
a[i] = false;
}
}
void solve(int x) {
std::vector<int>::iterator it = MS.begin();
std::cout << x << ':';
for (; it != MS.end(); ++it)
if (x % (*it) == 0)
std::cout << ' ' << *it;
std::cout << std::endl;
}
int main() {
int x;
eratos();
while (true) {
std::cin >> x;
if (x == 1)
break;
solve(x);
}
return 0;
} | replace | 47 | 48 | 47 | 48 | TLE | |
p00735 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define r(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int main() {
int a[200000], c = 0, n;
r(i, 3, 300000) if (i % 7 == 1 || i % 7 == 6) {
int p = 1;
if (i > 10 && (i % 6 == 0 || i % 8 == 0))
continue;
r(k, 0, c) if (i % a[k] == 0) p = 0;
if (p)
a[c++] = i;
}
r(i, 0, c) cout << a[i] << endl;
while (cin >> n, n != 1) {
int s = 0;
cout << n << ':';
r(i, 0, c) if (n % a[i] == 0) cout << ' ' << a[i];
cout << endl;
}
} | #include <bits/stdc++.h>
#define r(i, a, n) for (int i = a; i < n; i++)
using namespace std;
int main() {
int a[200000], c = 0, n;
r(i, 3, 300000) if (i % 7 == 1 || i % 7 == 6) {
int p = 1;
if (i > 10 && (i % 6 == 0 || i % 8 == 0))
continue;
r(k, 0, c) if (i % a[k] == 0) p = 0;
if (p)
a[c++] = i;
}
while (cin >> n, n != 1) {
int s = 0;
cout << n << ':';
r(i, 0, c) if (n % a[i] == 0) cout << ' ' << a[i];
cout << endl;
}
} | delete | 13 | 14 | 13 | 13 | TLE | |
p00736 | C++ | Runtime Error | #include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define LL long long
#define CLR(a) memset((a), 0, sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) \
int str; \
std::cin >> str;
#define DEBUGING(str) cout << str << endl
using namespace std;
const LL MOD = 1000000007; // 10^9+7
const int INF = (1 << 30);
// p,q,rに代入(これで、P,Q,Rが消滅)
string substitute(string s, int p, int q, int r) {
REP(i, s.size()) {
switch (s[i]) {
case 'P':
s[i] = '0' + p;
break;
case 'Q':
s[i] = '0' + q;
break;
case 'R':
s[i] = '0' + r;
break;
}
}
return s;
}
// 末尾にある数値に対して、インバースを適用(これで、-が消滅)
void apply_inverse(stack<char> &info) {
char t = info.top();
if (t < '0' || '2' < t)
return;
info.pop();
while (!info.empty() && info.top() == '-') {
info.pop();
if (t == '2')
t = '0';
else if (t == '0')
t = '2';
}
info.push(t);
}
// 演算子を実際に適用(これで、(,+,*,)が消滅 )
void apply_operator(stack<char> &info) {
char r = info.top();
info.pop();
char ope = info.top();
info.pop();
char l = info.top();
info.pop();
char err = info.top();
info.pop();
if (err != '(') {
exit(1);
}
l -= '0';
r -= '0';
char res;
switch (ope) {
case '+':
if (max(l, r) == 2)
res = '2';
else if (l + r == 0)
res = '0';
else
res = '1';
break;
case '*':
if (min(l, r) == 0)
res = '0';
else if (l + r == 4)
res = '2';
else
res = '1';
break;
default:
exit(1);
}
info.push(res);
}
// 構文を実際に計算する
bool play(const string &s) {
stack<char> info;
for (const char &c : s) {
switch (c) {
case '0':
case '1':
case '2':
info.push(c);
apply_inverse(info);
break;
case ')':
apply_operator(info);
apply_inverse(info);
break;
default:
info.push(c);
break;
}
}
if (info.size() != 1) {
exit(1);
} else {
return info.top() == '2';
}
}
// 全探索を行う
void calc(const string &formula) {
int res = 0;
REP(p, 3) REP(q, 3) REP(r, 3) {
string target = substitute(formula, p, q, r);
if (play(target)) {
res++;
}
}
cout << res << endl;
}
// メイン関数
int main() {
while (true) {
string formula;
cin >> formula;
if (formula == ".")
break;
calc(formula);
}
return 0;
}
| #include <algorithm>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>
#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define REP(i, n) FOR((i), 0, (n))
#define LL long long
#define CLR(a) memset((a), 0, sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) \
int str; \
std::cin >> str;
#define DEBUGING(str) cout << str << endl
using namespace std;
const LL MOD = 1000000007; // 10^9+7
const int INF = (1 << 30);
// p,q,rに代入(これで、P,Q,Rが消滅)
string substitute(string s, int p, int q, int r) {
REP(i, s.size()) {
switch (s[i]) {
case 'P':
s[i] = '0' + p;
break;
case 'Q':
s[i] = '0' + q;
break;
case 'R':
s[i] = '0' + r;
break;
}
}
return s;
}
// 末尾にある数値に対して、インバースを適用(これで、-が消滅)
void apply_inverse(stack<char> &info) {
char t = info.top();
if (t < '0' || '2' < t)
return;
info.pop();
while (!info.empty() && info.top() == '-') {
info.pop();
if (t == '2')
t = '0';
else if (t == '0')
t = '2';
}
info.push(t);
}
// 演算子を実際に適用(これで、(,+,*,)が消滅 )
void apply_operator(stack<char> &info) {
char r = info.top();
info.pop();
char ope = info.top();
info.pop();
char l = info.top();
info.pop();
char err = info.top();
info.pop();
if (err != '(') {
exit(1);
}
l -= '0';
r -= '0';
char res;
switch (ope) {
case '+':
if (max(l, r) == 2)
res = '2';
else if (l + r == 0)
res = '0';
else
res = '1';
break;
case '*':
if (min(l, r) == 0)
res = '0';
else if (l + r == 4)
res = '2';
else
res = '1';
break;
default:
exit(1);
}
info.push(res);
}
// 構文を実際に計算する
bool play(string s) {
stack<char> info;
for (const char &c : s) {
switch (c) {
case '0':
case '1':
case '2':
info.push(c);
apply_inverse(info);
break;
case ')':
apply_operator(info);
apply_inverse(info);
break;
default:
info.push(c);
break;
}
}
if (info.size() != 1) {
exit(1);
} else {
return info.top() == '2';
}
}
// 全探索を行う
void calc(const string &formula) {
int res = 0;
REP(p, 3) REP(q, 3) REP(r, 3) {
string target = substitute(formula, p, q, r);
if (play(target)) {
res++;
}
}
cout << res << endl;
}
// メイン関数
int main() {
while (true) {
string formula;
cin >> formula;
if (formula == ".")
break;
calc(formula);
}
return 0;
}
| replace | 103 | 104 | 103 | 104 | 0 | |
p00736 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
string repr(string s, int p, int q, int r) {
int tmp;
string s_tmp = s;
while ((tmp = s_tmp.find("P")) >= 0) {
s_tmp.replace(s_tmp.find("P"), 1, to_string(p));
}
while ((tmp = s_tmp.find("Q")) >= 0) {
s_tmp.replace(s_tmp.find("Q"), 1, to_string(q));
}
while ((tmp = s_tmp.find("R")) >= 0) {
s_tmp.replace(s_tmp.find("R"), 1, to_string(r));
}
return s_tmp;
}
string op_plus(string left, string right) {
int l, r;
if (left[0] == '-') {
l = 2 - (left[1] - '0');
} else {
l = left[0] - '0';
}
if (right[0] == '-') {
r = 2 - (right[1] - '0');
} else {
r = right[0] - '0';
}
return to_string(max(l, r));
}
string times(string left, string right) {
int l, r;
if (left[0] == '-') {
l = 2 - (left[1] - '0');
} else {
l = left[0] - '0';
}
if (right[0] == '-') {
r = 2 - (right[1] - '0');
} else {
r = right[0] - '0';
}
return to_string(min(l, r));
}
string solve(string str) {
while (str.substr(0, 2) == "--") {
str.erase(str.begin(), str.begin() + 2);
}
if (str.length() == 1 || str.length() == 2) {
if (str == "0") {
return "0";
} else if (str == "1") {
return "1";
} else if (str == "2") {
return "2";
} else if (str == "-0") {
return "2";
} else if (str == "-1") {
return "1";
} else if (str == "-2") {
return "0";
} else {
cout << str << " :Error" << endl;
return "-1";
}
}
if (str[0] == '(') {
str.erase(str.begin());
str.pop_back();
}
int brcount = 0;
int ind = 0;
while (ind < str.length()) {
if (str[ind] == '(') {
++brcount;
}
if (str[ind] == ')') {
--brcount;
}
if ((brcount == 0) && (str[ind] == '+' || str[ind] == '*'))
break;
++ind;
}
if (ind == str.length() - 1) {
cout << "search error" << endl;
return "-1";
}
string left, right;
left = solve(str.substr(0, ind));
right = solve(str.substr(ind + 1, str.length() - (ind + 1)));
if (str[ind] == '+') {
return op_plus(left, right);
}
if (str[ind] == '*') {
return times(left, right);
}
}
int main() {
string s, s_tmp;
int sum;
while (1) {
cin >> s;
if (s == ".") {
break;
}
sum = 0;
for (int p = 0; p < 3; p++) {
for (int q = 0; q < 3; q++) {
for (int r = 0; r < 3; r++) {
s_tmp = repr(s, p, q, r);
if (solve(s_tmp) == "2") {
++sum;
}
}
}
}
cout << sum << endl;
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
string repr(string s, int p, int q, int r) {
int tmp;
string s_tmp = s;
while ((tmp = s_tmp.find("P")) >= 0) {
s_tmp.replace(s_tmp.find("P"), 1, to_string(p));
}
while ((tmp = s_tmp.find("Q")) >= 0) {
s_tmp.replace(s_tmp.find("Q"), 1, to_string(q));
}
while ((tmp = s_tmp.find("R")) >= 0) {
s_tmp.replace(s_tmp.find("R"), 1, to_string(r));
}
return s_tmp;
}
string op_plus(string left, string right) {
int l, r;
if (left[0] == '-') {
l = 2 - (left[1] - '0');
} else {
l = left[0] - '0';
}
if (right[0] == '-') {
r = 2 - (right[1] - '0');
} else {
r = right[0] - '0';
}
return to_string(max(l, r));
}
string times(string left, string right) {
int l, r;
if (left[0] == '-') {
l = 2 - (left[1] - '0');
} else {
l = left[0] - '0';
}
if (right[0] == '-') {
r = 2 - (right[1] - '0');
} else {
r = right[0] - '0';
}
return to_string(min(l, r));
}
string solve(string str) {
while (str.substr(0, 2) == "--") {
str.erase(str.begin(), str.begin() + 2);
}
if (str.length() == 1 || str.length() == 2) {
if (str == "0") {
return "0";
} else if (str == "1") {
return "1";
} else if (str == "2") {
return "2";
} else if (str == "-0") {
return "2";
} else if (str == "-1") {
return "1";
} else if (str == "-2") {
return "0";
} else {
cout << str << " :Error" << endl;
return "-1";
}
}
if (str[0] == '(') {
str.erase(str.begin());
str.pop_back();
}
int brcount = 0;
int ind = 0;
while (ind < str.length()) {
if (str[ind] == '(') {
++brcount;
}
if (str[ind] == ')') {
--brcount;
}
if ((brcount == 0) && (str[ind] == '+' || str[ind] == '*'))
break;
++ind;
}
if (ind == str.length()) {
return to_string(2 - (solve(str.substr(1, str.length() - 1))[0] - '0'));
}
string left, right;
left = solve(str.substr(0, ind));
right = solve(str.substr(ind + 1, str.length() - (ind + 1)));
if (str[ind] == '+') {
return op_plus(left, right);
}
if (str[ind] == '*') {
return times(left, right);
}
}
int main() {
string s, s_tmp;
int sum;
while (1) {
cin >> s;
if (s == ".") {
break;
}
sum = 0;
for (int p = 0; p < 3; p++) {
for (int q = 0; q < 3; q++) {
for (int r = 0; r < 3; r++) {
s_tmp = repr(s, p, q, r);
if (solve(s_tmp) == "2") {
++sum;
}
}
}
}
cout << sum << endl;
}
return 0;
} | replace | 89 | 92 | 89 | 91 | 0 | |
p00736 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define State string::const_iterator
class ParseError {};
int expression(State &begin);
// int term(State &begin);
int number(State &begin);
int factor(State &begin);
int denial(State &begin);
void consume(State &begin, char expected);
int p, q, r;
string input;
// 四則演算の式をパースして、その評価結果を返す。
int expression(State &begin) {
int ret = factor(begin);
while (true) {
if (*begin == '+') {
consume(begin, '+');
int num = factor(begin);
// cout << num << " + " << ret;
if (ret == 0 && num == 0) {
ret = 0;
} else if (ret == 1 || num == 1) {
if (ret != 2 && num != 2) {
ret = 1;
} else {
ret = 2;
}
} else {
ret = 2;
}
// cout << " = " << ret << endl;
} else if (*begin == '*') {
consume(begin, '*');
int num = factor(begin);
// cout << num << " * " << ret;
if (num == 2 && ret == 2) {
ret = 2;
} else if (num == 0 || ret == 0) {
ret = 0;
} else {
ret = 1;
}
// cout << " = " << ret << endl;
} else {
break;
}
}
return ret;
}
int denial(State &begin) {
if (*begin == '-') {
consume(begin, '-');
int ret = denial(begin);
if (ret == 2) {
ret = 0;
} else if (ret == 0) {
ret = 2;
}
return ret;
}
return number(begin);
}
// 数字の列をパースして、その数を返す。
int number(State &begin) {
if (*begin == 'P') {
consume(begin, 'P');
return p;
} else if (*begin == 'Q') {
consume(begin, 'Q');
return q;
} else if (*begin == 'R') {
consume(begin, 'R');
return r;
}
int ret = 0;
while (isdigit(*begin)) {
ret *= 10;
ret += *begin - '0';
begin++;
}
return ret;
}
// 括弧か数をパースして、その評価結果を返す。
int factor(State &begin) {
if (*begin == '(') {
consume(begin, '('); // '('を飛ばす。
int ret = expression(begin);
consume(begin, ')'); // ')'を飛ばす。
return ret;
} else {
return denial(begin);
}
}
// beginがexpectedを指していたらbeginを一つ進める。
void consume(State &begin, char expected) {
if (*begin == expected) {
begin++;
} else {
cerr << "Expected '" << expected << "' but got '" << *begin << "'" << endl;
cerr << "Rest string is '";
while (*begin) {
cerr << *begin++;
}
cerr << "'" << endl;
cerr << input.end() - begin << endl;
throw ParseError();
}
}
int main() {
while (true) {
cin >> input;
if (input[0] == '.') {
break;
}
int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
p = i;
q = j;
r = k;
State s = input.begin();
if (factor(s) == 2) {
ans++;
}
}
}
}
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define State string::const_iterator
class ParseError {};
int expression(State &begin);
// int term(State &begin);
int number(State &begin);
int factor(State &begin);
int denial(State &begin);
void consume(State &begin, char expected);
int p, q, r;
string input;
// 四則演算の式をパースして、その評価結果を返す。
int expression(State &begin) {
int ret = factor(begin);
while (true) {
if (*begin == '+') {
consume(begin, '+');
int num = factor(begin);
// cout << num << " + " << ret;
if (ret == 0 && num == 0) {
ret = 0;
} else if (ret == 1 || num == 1) {
if (ret != 2 && num != 2) {
ret = 1;
} else {
ret = 2;
}
} else {
ret = 2;
}
// cout << " = " << ret << endl;
} else if (*begin == '*') {
consume(begin, '*');
int num = factor(begin);
// cout << num << " * " << ret;
if (num == 2 && ret == 2) {
ret = 2;
} else if (num == 0 || ret == 0) {
ret = 0;
} else {
ret = 1;
}
// cout << " = " << ret << endl;
} else {
break;
}
}
return ret;
}
int denial(State &begin) {
if (*begin == '-') {
consume(begin, '-');
int ret = factor(begin);
if (ret == 2) {
ret = 0;
} else if (ret == 0) {
ret = 2;
}
return ret;
}
return number(begin);
}
// 数字の列をパースして、その数を返す。
int number(State &begin) {
if (*begin == 'P') {
consume(begin, 'P');
return p;
} else if (*begin == 'Q') {
consume(begin, 'Q');
return q;
} else if (*begin == 'R') {
consume(begin, 'R');
return r;
}
int ret = 0;
while (isdigit(*begin)) {
ret *= 10;
ret += *begin - '0';
begin++;
}
return ret;
}
// 括弧か数をパースして、その評価結果を返す。
int factor(State &begin) {
if (*begin == '(') {
consume(begin, '('); // '('を飛ばす。
int ret = expression(begin);
consume(begin, ')'); // ')'を飛ばす。
return ret;
} else {
return denial(begin);
}
}
// beginがexpectedを指していたらbeginを一つ進める。
void consume(State &begin, char expected) {
if (*begin == expected) {
begin++;
} else {
cerr << "Expected '" << expected << "' but got '" << *begin << "'" << endl;
cerr << "Rest string is '";
while (*begin) {
cerr << *begin++;
}
cerr << "'" << endl;
cerr << input.end() - begin << endl;
throw ParseError();
}
}
int main() {
while (true) {
cin >> input;
if (input[0] == '.') {
break;
}
int ans = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
p = i;
q = j;
r = k;
State s = input.begin();
if (factor(s) == 2) {
ans++;
}
}
}
}
cout << ans << endl;
}
return 0;
}
| replace | 61 | 62 | 61 | 62 | 0 | |
p00736 | C++ | Time Limit Exceeded | // #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 a[] = {2, 1, 0}, b[3][3] = {{0, 0, 0}, {0, 1, 1}, {0, 1, 2}},
c[3][3] = {{0, 1, 2}, {1, 1, 2}, {2, 2, 2}};
signed main(void) {
while (true) {
string s;
cin >> s;
if (s == ".")
break;
int ans = 0;
REP(p, 3) REP(q, 3) REP(r, 3) {
// cout << p << " " << q << " " << r << endl;
//???????????°??????????????????
string t = s;
REP(i, t.size()) {
if (t[i] == 'P')
t[i] = p + '0';
if (t[i] == 'Q')
t[i] = q + '0';
if (t[i] == 'R')
t[i] = r + '0';
}
// cout << t << endl;
while (true) {
//???????????????
int cnt = 0;
REP(i, t.size()) {
if (t[i] == '-')
cnt++;
else {
if (cnt > 0) {
if ('0' <= t[i] && t[i] < '3') {
int tmp = t[i] - '0';
// cout << "cnt:" << cnt << endl << tmp << " ";
REP(j, cnt) {
tmp = a[tmp];
// if(p == 0 && q == 0 && r == 0) cout << tmp << " ";
}
// if(p == 0 && q == 0 && r == 0) cout << endl;
t = t.substr(0, i - cnt) + (char)(tmp + '0') + t.substr(i + 1);
i -= cnt;
}
}
cnt = 0;
}
// cout << "i:" << i << " cnt:" << cnt << endl;
}
// cout << "a:" << t << endl;
//?????£?????????+??¨*?????????
REP(i, t.size()) {
if (t[i] == '+') {
if (IN('0', '3', t[i - 1]) && IN('0', '3', t[i + 1])) {
int tmp = c[t[i - 1] - '0'][t[i + 1] - '0'];
t = t.substr(0, i - 2) + (char)(tmp + '0') + t.substr(i + 3);
i -= 3;
// cout << "c:" << t << endl;
}
} else if (t[i] == '*') {
if (IN('0', '3', t[i - 1]) && IN('0', '3', t[i + 1]) &&
t[i - 2] == '(' && t[i + 2] == ')') {
int tmp = b[t[i - 1] - '0'][t[i + 1] - '0'];
t = t.substr(0, i - 2) + (char)(tmp + '0') + t.substr(i + 3);
i -= 3;
// cout << "d:" << t << endl;
}
}
}
// cout << "b:" << t << endl;
if (t.size() == 1)
break;
}
if (t == "2")
ans++;
}
cout << ans << 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 a[] = {2, 1, 0}, b[3][3] = {{0, 0, 0}, {0, 1, 1}, {0, 1, 2}},
c[3][3] = {{0, 1, 2}, {1, 1, 2}, {2, 2, 2}};
signed main(void) {
while (true) {
string s;
cin >> s;
if (s == ".")
break;
int ans = 0;
REP(p, 3) REP(q, 3) REP(r, 3) {
// cout << p << " " << q << " " << r << endl;
//???????????°??????????????????
string t = s;
REP(i, t.size()) {
if (t[i] == 'P')
t[i] = p + '0';
if (t[i] == 'Q')
t[i] = q + '0';
if (t[i] == 'R')
t[i] = r + '0';
}
// cout << t << endl;
while (true) {
//???????????????
int cnt = 0;
REP(i, t.size()) {
if (t[i] == '-')
cnt++;
else {
if (cnt > 0) {
if ('0' <= t[i] && t[i] < '3') {
int tmp = t[i] - '0';
// cout << "cnt:" << cnt << endl << tmp << " ";
REP(j, cnt) {
tmp = a[tmp];
// if(p == 0 && q == 0 && r == 0) cout << tmp << " ";
}
// if(p == 0 && q == 0 && r == 0) cout << endl;
t = t.substr(0, i - cnt) + (char)(tmp + '0') + t.substr(i + 1);
i -= cnt;
}
}
cnt = 0;
}
// cout << "i:" << i << " cnt:" << cnt << endl;
}
// cout << "a:" << t << endl;
//?????£?????????+??¨*?????????
REP(i, t.size()) {
if (t[i] == '+') {
if (IN('0', '3', t[i - 1]) && IN('0', '3', t[i + 1]) &&
t[i - 2] == '(' && t[i + 2] == ')') {
int tmp = c[t[i - 1] - '0'][t[i + 1] - '0'];
t = t.substr(0, i - 2) + (char)(tmp + '0') + t.substr(i + 3);
i -= 3;
// cout << "c:" << t << endl;
}
} else if (t[i] == '*') {
if (IN('0', '3', t[i - 1]) && IN('0', '3', t[i + 1]) &&
t[i - 2] == '(' && t[i + 2] == ')') {
int tmp = b[t[i - 1] - '0'][t[i + 1] - '0'];
t = t.substr(0, i - 2) + (char)(tmp + '0') + t.substr(i + 3);
i -= 3;
// cout << "d:" << t << endl;
}
}
}
// cout << "b:" << t << endl;
if (t.size() == 1)
break;
}
if (t == "2")
ans++;
}
cout << ans << endl;
}
return 0;
} | replace | 74 | 75 | 74 | 76 | TLE | |
p00736 | C++ | Runtime Error | // Header {{{
// includes {{{
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/time.h>
#include <unistd.h>
#include <vector>
// }}}
using namespace std;
// consts {{{
static const int INF = 1e9;
static const double PI = acos(-1.0);
static const double EPS = 1e-10;
// }}}
// typedefs {{{
typedef long long int LL;
typedef unsigned long long int ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<ULL> VULL;
typedef vector<VULL> VVULL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef pair<int, int> PII;
typedef complex<int> P;
#define PQ(type) priority_queue<type>
// priority queue reverse
#define PQR(type) priority_queue<type, vector<type>, greater<type>>
// }}}
// macros & inline functions {{{
// syntax sugars {{{
#define FOR(i, b, e) for (typeof(e) i = (b); i < (e); ++i)
#define FORI(i, b, e) for (typeof(e) i = (b); i <= (e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPI(i, n) FORI(i, 0, n)
#define OPOVER(_op, _type) inline bool operator _op(const _type &t) const
#define ASSIGN_MAX(var, val) ((var) = max((var), (val)))
#define ASSIGN_MIN(var, val) ((var) = min((var), (val)))
// }}}
// conversion {{{
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// }}}
// array and STL {{{
#define ARRSIZE(a) (sizeof(a) / sizeof(a[0]))
#define ZERO(a, v) (assert(v == 0 || v == -1), memset(a, v, sizeof(a)))
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define SIZE(a) ((LL)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(c, it) \
for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define REACH(c, it) \
for (typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(s, e) ((s).find(e) != (s).end())
// }}}
// bit manipulation {{{
// singed integers are not for bitwise operations, specifically arithmetic
// shifts ('>>', and maybe not good for '<<' too)
#define IS_UNSIGNED(n) (!numeric_limits<typeof(n)>::is_signed)
#define BIT(n) (assert(IS_UNSIGNED(n)), assert(n < 64), (1ULL << (n)))
#define BITOF(n, m) \
(assert(IS_UNSIGNED(n)), assert(m < 64), ((ULL)(n) >> (m)&1))
inline int BITS_COUNT(ULL b) {
int c = 0;
while (b != 0) {
c += (b & 1);
b >>= 1;
}
return c;
}
inline int MSB(ULL b) {
int c = 0;
while (b != 0) {
++c;
b >>= 1;
}
return c - 1;
}
inline int MAKE_MASK(ULL upper, ULL lower) {
assert(lower < 64 && upper < 64 && lower <= upper);
return (BIT(upper) - 1) ^ (BIT(lower) - 1);
}
// }}}
// for readable code {{{
#define EVEN(n) (n % 2 == 0)
#define ODD(n) (!EVEN(n))
// }}}
// debug {{{
#define arrsz(a) (sizeof(a) / sizeof(a[0]))
#define dprt(fmt, ...) \
if (opt_debug) { \
fprintf(stderr, fmt, ##__VA_ARGS__); \
}
#define darr(a) \
if (opt_debug) { \
copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ")); \
cerr << endl; \
}
#define darr_range(a, f, t) \
if (opt_debug) { \
copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ")); \
cerr << endl; \
}
#define dvec(v) \
if (opt_debug) { \
copy(ALL(v), ostream_iterator<int>(cerr, " ")); \
cerr << endl; \
}
#define darr2(a) \
if (opt_debug) { \
FOR(__i, 0, (arrsz(a))) { darr((a)[__i]); } \
}
#define WAIT() \
if (opt_debug) { \
string _wait_; \
cerr << "(hit return to continue)" << endl; \
getline(cin, _wait_); \
}
#define dump(x) \
if (opt_debug) { \
cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl; \
}
// dump vector elements in [s, e)
#define dumpv(v, s, e) \
if (opt_debug) { \
cerr << " [L" << __LINE__ << "] " << #v << " = "; \
FOR(__i, s, e) { cerr << v[__i] << "\t"; } \
cerr << endl; \
}
#define dumpl(x) \
if (opt_debug) { \
cerr << " [L" << __LINE__ << "] " << #x << endl << (x) << endl; \
}
#define dumpf() \
if (opt_debug) { \
cerr << __PRETTY_FUNCTION__ << endl; \
}
#define where() \
if (opt_debug) { \
cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__ \
<< "]" << endl; \
}
#define show_bits(b, s) \
if (opt_debug) { \
REP(i, s) { \
cerr << BITOF(b, s - 1 - i); \
if (i % 4 == 3) \
cerr << ' '; \
} \
cerr << endl; \
}
// ostreams {{{
// complex
template <typename T> ostream &operator<<(ostream &s, const complex<T> &d) {
return s << "(" << d.real() << ", " << d.imag() << ")";
}
// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
return s << "(" << d.first << ", " << d.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &d) {
int len = d.size();
REP(i, len) {
s << d[i];
if (i < len - 1)
s << "\t";
}
return s;
}
// 2 dimentional vector
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &d) {
int len = d.size();
REP(i, len) { s << d[i] << endl; }
return s;
}
// map
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
s << "\t" << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
// }}}
// }}}
// }}}
// time {{{
inline double now() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (static_cast<double>(tv.tv_sec) +
static_cast<double>(tv.tv_usec) * 1e-6);
}
// }}}
// string manipulation {{{
inline VS split(string s, char delimiter) {
VS v;
string t;
REP(i, s.length()) {
if (s[i] == delimiter)
v.PB(t), t = "";
else
t += s[i];
}
v.PB(t);
return v;
}
inline string join(VS s, string j) {
string t;
REP(i, s.size()) { t += s[i] + j; }
return t;
}
// }}}
// geometry {{{
#define Y real()
#define X imag()
// }}}
// 2 dimentional array {{{
enum { UP, RIGHT, DOWN, LEFT, UP_RIGHT, DOWN_RIGHT, DOWN_LEFT, UP_LEFT };
P dydx4[4] = {P(-1, 0), P(0, 1), P(1, 0), P(0, -1)};
P dydx8[8] = {P(-1, 0), P(0, 1), P(1, 0), P(0, -1),
P(-1, 1), P(1, 1), P(1, -1), P(-1, -1)};
bool in_field(int H, int W, P p) {
return (0 <= p.Y && p.Y < H) && (0 <= p.X && p.X < W);
}
// }}}
// input and output {{{
inline void input(string filename) { freopen(filename.c_str(), "r", stdin); }
inline void output(string filename) { freopen(filename.c_str(), "w", stdout); }
// }}}
// }}}
bool opt_debug = false;
int neg(int v) {
int ret = v;
if (v == 0) {
ret = 2;
} else if (v == 2) {
ret = 0;
}
return ret;
}
int conj(int lhs, int rhs) {
if (lhs == 0 || rhs == 0) {
return 0;
}
if (lhs == 2 && rhs == 2) {
return 2;
}
return 1;
}
int disj(int lhs, int rhs) {
if (lhs == 2 || rhs == 2) {
return 2;
}
if (lhs == 0 && rhs == 0) {
return 0;
}
return 1;
}
class Parser {
private:
string line;
int pos;
public:
Parser(string _line) {
line = _line;
pos = 0;
}
void assign(char var, int val) {
REP(i, line.length()) {
if (line[i] == var) {
line[i] = val + '0';
}
}
}
int formula() {
if (line[pos] == '0' || line[pos] == '1' || line[pos] == '2') {
return constant();
}
if (line[pos] == '-') {
pos++;
return neg(formula());
}
if (line[pos] == '(') {
pos++;
int lhs = formula();
char op = line[pos];
pos++;
int rhs = formula();
assert(line[pos] == ')');
pos++;
if (op == '*') {
return conj(lhs, rhs);
} else {
return disj(lhs, rhs);
}
}
assert(false);
return -1;
}
int constant() {
char c = line[pos];
pos++;
return c - '0';
}
};
int main(int argc, char **argv) {
std::ios_base::sync_with_stdio(false);
// set options {{{
int __c;
while ((__c = getopt(argc, argv, "d")) != -1) {
switch (__c) {
case 'd':
opt_debug = true;
break;
default:
abort();
}
}
// }}}
opt_debug = true;
input("./inputs/0.txt");
// output("./outputs/0.txt");
string s;
while (cin >> s, s != ".") {
int ans = 0;
REP(p, 3) {
REP(q, 3) {
REP(r, 3) {
Parser parser(s);
parser.assign('P', p);
parser.assign('Q', q);
parser.assign('R', r);
if (parser.formula() == 2) {
ans++;
}
}
}
}
cout << ans << endl;
}
return 0;
}
// vim: foldmethod=marker | // Header {{{
// includes {{{
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/time.h>
#include <unistd.h>
#include <vector>
// }}}
using namespace std;
// consts {{{
static const int INF = 1e9;
static const double PI = acos(-1.0);
static const double EPS = 1e-10;
// }}}
// typedefs {{{
typedef long long int LL;
typedef unsigned long long int ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<ULL> VULL;
typedef vector<VULL> VVULL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef pair<int, int> PII;
typedef complex<int> P;
#define PQ(type) priority_queue<type>
// priority queue reverse
#define PQR(type) priority_queue<type, vector<type>, greater<type>>
// }}}
// macros & inline functions {{{
// syntax sugars {{{
#define FOR(i, b, e) for (typeof(e) i = (b); i < (e); ++i)
#define FORI(i, b, e) for (typeof(e) i = (b); i <= (e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPI(i, n) FORI(i, 0, n)
#define OPOVER(_op, _type) inline bool operator _op(const _type &t) const
#define ASSIGN_MAX(var, val) ((var) = max((var), (val)))
#define ASSIGN_MIN(var, val) ((var) = min((var), (val)))
// }}}
// conversion {{{
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
// }}}
// array and STL {{{
#define ARRSIZE(a) (sizeof(a) / sizeof(a[0]))
#define ZERO(a, v) (assert(v == 0 || v == -1), memset(a, v, sizeof(a)))
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define SIZE(a) ((LL)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(c, it) \
for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define REACH(c, it) \
for (typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(s, e) ((s).find(e) != (s).end())
// }}}
// bit manipulation {{{
// singed integers are not for bitwise operations, specifically arithmetic
// shifts ('>>', and maybe not good for '<<' too)
#define IS_UNSIGNED(n) (!numeric_limits<typeof(n)>::is_signed)
#define BIT(n) (assert(IS_UNSIGNED(n)), assert(n < 64), (1ULL << (n)))
#define BITOF(n, m) \
(assert(IS_UNSIGNED(n)), assert(m < 64), ((ULL)(n) >> (m)&1))
inline int BITS_COUNT(ULL b) {
int c = 0;
while (b != 0) {
c += (b & 1);
b >>= 1;
}
return c;
}
inline int MSB(ULL b) {
int c = 0;
while (b != 0) {
++c;
b >>= 1;
}
return c - 1;
}
inline int MAKE_MASK(ULL upper, ULL lower) {
assert(lower < 64 && upper < 64 && lower <= upper);
return (BIT(upper) - 1) ^ (BIT(lower) - 1);
}
// }}}
// for readable code {{{
#define EVEN(n) (n % 2 == 0)
#define ODD(n) (!EVEN(n))
// }}}
// debug {{{
#define arrsz(a) (sizeof(a) / sizeof(a[0]))
#define dprt(fmt, ...) \
if (opt_debug) { \
fprintf(stderr, fmt, ##__VA_ARGS__); \
}
#define darr(a) \
if (opt_debug) { \
copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ")); \
cerr << endl; \
}
#define darr_range(a, f, t) \
if (opt_debug) { \
copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ")); \
cerr << endl; \
}
#define dvec(v) \
if (opt_debug) { \
copy(ALL(v), ostream_iterator<int>(cerr, " ")); \
cerr << endl; \
}
#define darr2(a) \
if (opt_debug) { \
FOR(__i, 0, (arrsz(a))) { darr((a)[__i]); } \
}
#define WAIT() \
if (opt_debug) { \
string _wait_; \
cerr << "(hit return to continue)" << endl; \
getline(cin, _wait_); \
}
#define dump(x) \
if (opt_debug) { \
cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl; \
}
// dump vector elements in [s, e)
#define dumpv(v, s, e) \
if (opt_debug) { \
cerr << " [L" << __LINE__ << "] " << #v << " = "; \
FOR(__i, s, e) { cerr << v[__i] << "\t"; } \
cerr << endl; \
}
#define dumpl(x) \
if (opt_debug) { \
cerr << " [L" << __LINE__ << "] " << #x << endl << (x) << endl; \
}
#define dumpf() \
if (opt_debug) { \
cerr << __PRETTY_FUNCTION__ << endl; \
}
#define where() \
if (opt_debug) { \
cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__ \
<< "]" << endl; \
}
#define show_bits(b, s) \
if (opt_debug) { \
REP(i, s) { \
cerr << BITOF(b, s - 1 - i); \
if (i % 4 == 3) \
cerr << ' '; \
} \
cerr << endl; \
}
// ostreams {{{
// complex
template <typename T> ostream &operator<<(ostream &s, const complex<T> &d) {
return s << "(" << d.real() << ", " << d.imag() << ")";
}
// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &d) {
return s << "(" << d.first << ", " << d.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &d) {
int len = d.size();
REP(i, len) {
s << d[i];
if (i < len - 1)
s << "\t";
}
return s;
}
// 2 dimentional vector
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &d) {
int len = d.size();
REP(i, len) { s << d[i] << endl; }
return s;
}
// map
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
s << "\t" << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
// }}}
// }}}
// }}}
// time {{{
inline double now() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (static_cast<double>(tv.tv_sec) +
static_cast<double>(tv.tv_usec) * 1e-6);
}
// }}}
// string manipulation {{{
inline VS split(string s, char delimiter) {
VS v;
string t;
REP(i, s.length()) {
if (s[i] == delimiter)
v.PB(t), t = "";
else
t += s[i];
}
v.PB(t);
return v;
}
inline string join(VS s, string j) {
string t;
REP(i, s.size()) { t += s[i] + j; }
return t;
}
// }}}
// geometry {{{
#define Y real()
#define X imag()
// }}}
// 2 dimentional array {{{
enum { UP, RIGHT, DOWN, LEFT, UP_RIGHT, DOWN_RIGHT, DOWN_LEFT, UP_LEFT };
P dydx4[4] = {P(-1, 0), P(0, 1), P(1, 0), P(0, -1)};
P dydx8[8] = {P(-1, 0), P(0, 1), P(1, 0), P(0, -1),
P(-1, 1), P(1, 1), P(1, -1), P(-1, -1)};
bool in_field(int H, int W, P p) {
return (0 <= p.Y && p.Y < H) && (0 <= p.X && p.X < W);
}
// }}}
// input and output {{{
inline void input(string filename) { freopen(filename.c_str(), "r", stdin); }
inline void output(string filename) { freopen(filename.c_str(), "w", stdout); }
// }}}
// }}}
bool opt_debug = false;
int neg(int v) {
int ret = v;
if (v == 0) {
ret = 2;
} else if (v == 2) {
ret = 0;
}
return ret;
}
int conj(int lhs, int rhs) {
if (lhs == 0 || rhs == 0) {
return 0;
}
if (lhs == 2 && rhs == 2) {
return 2;
}
return 1;
}
int disj(int lhs, int rhs) {
if (lhs == 2 || rhs == 2) {
return 2;
}
if (lhs == 0 && rhs == 0) {
return 0;
}
return 1;
}
class Parser {
private:
string line;
int pos;
public:
Parser(string _line) {
line = _line;
pos = 0;
}
void assign(char var, int val) {
REP(i, line.length()) {
if (line[i] == var) {
line[i] = val + '0';
}
}
}
int formula() {
if (line[pos] == '0' || line[pos] == '1' || line[pos] == '2') {
return constant();
}
if (line[pos] == '-') {
pos++;
return neg(formula());
}
if (line[pos] == '(') {
pos++;
int lhs = formula();
char op = line[pos];
pos++;
int rhs = formula();
assert(line[pos] == ')');
pos++;
if (op == '*') {
return conj(lhs, rhs);
} else {
return disj(lhs, rhs);
}
}
assert(false);
return -1;
}
int constant() {
char c = line[pos];
pos++;
return c - '0';
}
};
int main(int argc, char **argv) {
std::ios_base::sync_with_stdio(false);
// set options {{{
int __c;
while ((__c = getopt(argc, argv, "d")) != -1) {
switch (__c) {
case 'd':
opt_debug = true;
break;
default:
abort();
}
}
// }}}
// opt_debug = true;
// input("./inputs/0.txt");
// output("./outputs/0.txt");
string s;
while (cin >> s, s != ".") {
int ans = 0;
REP(p, 3) {
REP(q, 3) {
REP(r, 3) {
Parser parser(s);
parser.assign('P', p);
parser.assign('Q', q);
parser.assign('R', r);
if (parser.formula() == 2) {
ans++;
}
}
}
}
cout << ans << endl;
}
return 0;
}
// vim: foldmethod=marker | replace | 383 | 385 | 383 | 385 | -6 | e22d4083-1a69-458d-8061-fc50ae1ad9a6.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p00736/C++/s372000287.cpp:254: int Parser::formula(): Assertion `false' failed.
|
p00736 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
// #define int long long
#define DBG 1
#define dump(o) \
if (DBG) { \
cerr << #o << " " << o << endl; \
}
#define dumpc(o) \
if (DBG) { \
cerr << #o; \
for (auto &e : (o)) \
cerr << " " << e; \
cerr << endl; \
}
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define each(it, c) for (auto it = (c).begin(); it != (c).end(); it++)
#define all(c) c.begin(), c.end()
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
void change(string &s, char x, char b) {
rep(i, 0, s.size()) {
if (s[i] == x) {
s[i] = b;
}
}
}
vector<vector<int>> AND({{0, 0, 0}, {0, 1, 1}, {0, 1, 2}}),
OR({{0, 1, 2}, {1, 1, 2}, {2, 2, 2}});
vector<int> NOT({2, 1, 0});
vector<char> vc{'P', 'Q', 'R'};
int eval(string &s, int &k) {
dump(s.substr(k));
dump(k);
if (isdigit(s[k])) {
return s[k] - '0';
} else if (s[k] == '-') {
return NOT[eval(s, ++k)];
} else if (s[k] == '(') {
k++;
int a = eval(s, k);
dump(a);
k++;
char op = s[k];
dump(op);
k++;
int b = eval(s, k);
k++;
dump(b);
if (op == '*')
return AND[a][b];
else if (op == '+')
return OR[a][b];
}
}
signed main() {
string s;
while (cin >> s, s != ".") {
int cnt(0);
for (char P = '0'; P <= '2'; P++) {
for (char Q = '0'; Q <= '2'; Q++) {
for (char R = '0'; R <= '2'; R++) {
string ex(s);
change(ex, 'P', P);
change(ex, 'Q', Q);
change(ex, 'R', R);
int k(0);
if (eval(ex, k) == 2)
cnt++;
}
}
}
cout << cnt << endl;
}
return 0;
} | #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
// #define int long long
#define DBG 0
#define dump(o) \
if (DBG) { \
cerr << #o << " " << o << endl; \
}
#define dumpc(o) \
if (DBG) { \
cerr << #o; \
for (auto &e : (o)) \
cerr << " " << e; \
cerr << endl; \
}
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define each(it, c) for (auto it = (c).begin(); it != (c).end(); it++)
#define all(c) c.begin(), c.end()
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
void change(string &s, char x, char b) {
rep(i, 0, s.size()) {
if (s[i] == x) {
s[i] = b;
}
}
}
vector<vector<int>> AND({{0, 0, 0}, {0, 1, 1}, {0, 1, 2}}),
OR({{0, 1, 2}, {1, 1, 2}, {2, 2, 2}});
vector<int> NOT({2, 1, 0});
vector<char> vc{'P', 'Q', 'R'};
int eval(string &s, int &k) {
dump(s.substr(k));
dump(k);
if (isdigit(s[k])) {
return s[k] - '0';
} else if (s[k] == '-') {
return NOT[eval(s, ++k)];
} else if (s[k] == '(') {
k++;
int a = eval(s, k);
dump(a);
k++;
char op = s[k];
dump(op);
k++;
int b = eval(s, k);
k++;
dump(b);
if (op == '*')
return AND[a][b];
else if (op == '+')
return OR[a][b];
}
}
signed main() {
string s;
while (cin >> s, s != ".") {
int cnt(0);
for (char P = '0'; P <= '2'; P++) {
for (char Q = '0'; Q <= '2'; Q++) {
for (char R = '0'; R <= '2'; R++) {
string ex(s);
change(ex, 'P', P);
change(ex, 'Q', Q);
change(ex, 'R', R);
int k(0);
if (eval(ex, k) == 2)
cnt++;
}
}
}
cout << cnt << endl;
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | s.substr(k) (0*0)
k 0
s.substr(k) 0*0)
k 1
a 0
op *
s.substr(k) 0)
k 3
b 0
s.substr(k) (0*0)
k 0
s.substr(k) 0*0)
k 1
a 0
op *
s.substr(k) 0)
k 3
b 0
s.substr(k) (0*0)
k 0
s.substr(k) 0*0)
k 1
a 0
op *
s.substr(k) 0)
k 3
b 0
s.substr(k) (0*1)
k 0
s.substr(k) 0*1)
k 1
a 0
op *
s.substr(k) 1)
k 3
b 1
s.substr(k) (0*1)
k 0
s.substr(k) 0*1)
k 1
a 0
op *
s.substr(k) 1)
k 3
b 1
s.substr(k) (0*1)
k 0
s.substr(k) 0*1)
k 1
a 0
op *
s.substr(k) 1)
k 3
b 1
s.substr(k) (0*2)
k 0
s.substr(k) 0*2)
k 1
a 0
op *
s.substr(k) 2)
k 3
b 2
s.substr(k) (0*2)
k 0
s.substr(k) 0*2)
k 1
a 0
op *
s.substr(k) 2)
k 3
b 2
s.substr(k) (0*2)
k 0
s.substr(k) 0*2)
k 1
a 0
op *
s.substr(k) 2)
k 3
b 2
s.substr(k) (1*0)
k 0
s.substr(k) 1*0)
k 1
a 1
op *
s.substr(k) 0)
k 3
b 0
s.substr(k) (1*0)
k 0
s.substr(k) 1*0)
k 1
a 1
op *
s.substr(k) 0)
k 3
b 0
s.substr(k) (1*0)
k 0
s.substr(k) 1*0)
k 1
a 1
op *
s.substr(k) 0)
k 3
b 0
s.substr(k) (1*1)
k 0
s.substr(k) 1*1)
k 1
a 1
op *
s.substr(k) 1)
k 3
b 1
s.substr(k) (1*1)
k 0
s.substr(k) 1*1)
k 1
a 1
op *
s.substr(k) 1)
k 3
b 1
s.substr(k) (1*1)
k 0
s.substr(k) 1*1)
k 1
a 1
op *
s.substr(k) 1)
k 3
b 1
s.substr(k) (1*2)
k 0
s.substr(k) 1*2)
k 1
a 1
op *
s.substr(k) 2)
k 3
b 2
s.substr(k) (1*2)
k 0
s.substr(k) 1*2)
k 1
a 1
op *
s.substr(k) 2)
k 3
b 2
s.substr(k) (1*2)
k 0
s.substr(k) 1*2)
k 1
a 1
op *
s.substr(k) 2)
k 3
b 2
s.substr(k) (2*0)
k 0
s.substr(k) 2*0)
k 1
a 2
op *
s.substr(k) 0)
k 3
b 0
s.substr(k) (2*0)
k 0
s.substr(k) 2*0)
k 1
a 2
op *
s.substr(k) 0)
k 3
b 0
s.substr(k) (2*0)
k 0
s.substr(k) 2*0)
k 1
a 2
op *
s.substr(k) 0)
k 3
b 0
s.substr(k) (2*1)
k 0
s.substr(k) 2*1)
k 1
a 2
op *
s.substr(k) 1)
k 3
b 1
s.substr(k) (2*1)
k 0
s.substr(k) 2*1)
k 1
a 2
op *
s.substr(k) 1)
k 3
b 1
s.substr(k) (2*1)
k 0
s.substr(k) 2*1)
k 1
a 2
op *
s.substr(k) 1)
k 3
b 1
s.substr(k) (2*2)
k 0
s.substr(k) 2*2)
k 1
a 2
op *
s.substr(k) 2)
k 3
b 2
s.substr(k) (2*2)
k 0
s.substr(k) 2*2)
k 1
a 2
op *
s.substr(k) 2)
k 3
b 2
s.substr(k) (2*2)
k 0
s.substr(k) 2*2)
k 1
a 2
op *
s.substr(k) 2)
k 3
b 2
s.substr(k) (--0+(0*0))
k 0
s.substr(k) --0+(0*0))
k 1
s.substr(k) -0+(0*0))
k 2
s.substr(k) 0+(0*0))
k 3
a 0
op +
s.substr(k) (0*0))
k 5
s.substr(k) 0*0))
k 6
a 0
op *
s.substr(k) 0))
k 8
b 0
b 0
s.substr(k) (--1+(0*0))
k 0
s.substr(k) --1+(0*0))
k 1
s.substr(k) -1+(0*0))
k 2
s.substr(k) 1+(0*0))
k 3
a 1
op +
s.substr(k) (0*0))
k 5
s.substr(k) 0*0))
k 6
a 0
op *
s.substr(k) 0))
k 8
b 0
b 0
s.substr(k) (--2+(0*0))
k 0
s.substr(k) --2+(0*0))
k 1
s.substr(k) -2+(0*0))
k 2
s.substr(k) 2+(0*0))
k 3
a 2
op +
s.substr(k) (0*0))
k 5
s.substr(k) 0*0))
k 6
a 0
op *
s.substr(k) 0))
k 8
b 0
b 0
s.substr(k) (--0+(0*1))
k 0
s.substr(k) --0+(0*1))
k 1
s.substr(k) -0+(0*1))
k 2
s.substr(k) 0+(0*1))
k 3
a 0
op +
s.substr(k) (0*1))
k 5
s.substr(k) 0*1))
k 6
a 0
op *
s.substr(k) 1))
k 8
b 1
b 0
s.substr(k) (--1+(0*1))
k 0
s.substr(k) --1+(0*1))
k 1
s.substr(k) -1+(0*1))
k 2
s.substr(k) 1+(0*1))
k 3
a 1
op +
s.substr(k) (0*1))
k 5
s.substr(k) 0*1))
k 6
a 0
op *
s.substr(k) 1))
k 8
b 1
b 0
s.substr(k) (--2+(0*1))
k 0
s.substr(k) --2+(0*1))
k 1
s.substr(k) -2+(0*1))
k 2
s.substr(k) 2+(0*1))
k 3
a 2
op +
s.substr(k) (0*1))
k 5
s.substr(k) 0*1))
k 6
a 0
op *
s.substr(k) 1))
k 8
b 1
b 0
s.substr(k) (--0+(0*2))
k 0
s.substr(k) --0+(0*2))
k 1
s.substr(k) -0+(0*2))
k 2
s.substr(k) 0+(0*2))
k 3
a 0
op +
s.substr(k) (0*2))
k 5
s.substr(k) 0*2))
k 6
a 0
op *
s.substr(k) 2))
k 8
b 2
b 0
s.substr(k) (--1+(0*2))
k 0
s.substr(k) --1+(0*2))
k 1
s.substr(k) -1+(0*2))
k 2
s.substr(k) 1+(0*2))
k 3
a 1
op +
s.substr(k) (0*2))
k 5
s.substr(k) 0*2))
k 6
a 0
op *
s.substr(k) 2))
k 8
b 2
b 0
s.substr(k) (--2+(0*2))
k 0
s.substr(k) --2+(0*2))
k 1
s.substr(k) -2+(0*2))
k 2
s.substr(k) 2+(0*2))
k 3
a 2
op +
s.substr(k) (0*2))
k 5
s.substr(k) 0*2))
k 6
a 0
op *
s.substr(k) 2))
k 8
b 2
b 0
s.substr(k) (--0+(1*0))
k 0
s.substr(k) --0+(1*0))
k 1
s.substr(k) -0+(1*0))
k 2
s.substr(k) 0+(1*0))
k 3
a 0
op +
s.substr(k) (1*0))
k 5
s.substr(k) 1*0))
k 6
a 1
op *
s.substr(k) 0))
k 8
b 0
b 0
s.substr(k) (--1+(1*0))
k 0
s.substr(k) --1+(1*0))
k 1
s.substr(k) -1+(1*0))
k 2
s.substr(k) 1+(1*0))
k 3
a 1
op +
s.substr(k) (1*0))
k 5
s.substr(k) 1*0))
k 6
a 1
op *
s.substr(k) 0))
k 8
b 0
b 0
s.substr(k) (--2+(1*0))
k 0
s.substr(k) --2+(1*0))
k 1
s.substr(k) -2+(1*0))
k 2
s.substr(k) 2+(1*0))
k 3
a 2
op +
s.substr(k) (1*0))
k 5
s.substr(k) 1*0))
k 6
a 1
op *
s.substr(k) 0))
k 8
b 0
b 0
s.substr(k) (--0+(1*1))
k 0
s.substr(k) --0+(1*1))
k 1
s.substr(k) -0+(1*1))
k 2
s.substr(k) 0+(1*1))
k 3
a 0
op +
s.substr(k) (1*1))
k 5
s.substr(k) 1*1))
k 6
a 1
op *
s.substr(k) 1))
k 8
b 1
b 1
s.substr(k) (--1+(1*1))
k 0
s.substr(k) --1+(1*1))
k 1
s.substr(k) -1+(1*1))
k 2
s.substr(k) 1+(1*1))
k 3
a 1
op +
s.substr(k) (1*1))
k 5
s.substr(k) 1*1))
k 6
a 1
op *
s.substr(k) 1))
k 8
b 1
b 1
s.substr(k) (--2+(1*1))
k 0
s.substr(k) --2+(1*1))
k 1
s.substr(k) -2+(1*1))
k 2
s.substr(k) 2+(1*1))
k 3
a 2
op +
s.substr(k) (1*1))
k 5
s.substr(k) 1*1))
k 6
a 1
op *
s.substr(k) 1))
k 8
b 1
b 1
s.substr(k) (--0+(1*2))
k 0
s.substr(k) --0+(1*2))
k 1
s.substr(k) -0+(1*2))
k 2
s.substr(k) 0+(1*2))
k 3
a 0
op +
s.substr(k) (1*2))
k 5
s.substr(k) 1*2))
k 6
a 1
op *
s.substr(k) 2))
k 8
b 2
b 1
s.substr(k) (--1+(1*2))
k 0
s.substr(k) --1+(1*2))
k 1
s.substr(k) -1+(1*2))
k 2
s.substr(k) 1+(1*2))
k 3
a 1
op +
s.substr(k) (1*2))
k 5
s.substr(k) 1*2))
k 6
a 1
op *
s.substr(k) 2))
k 8
b 2
b 1
s.substr(k) (--2+(1*2))
k 0
s.substr(k) --2+(1*2))
k 1
s.substr(k) -2+(1*2))
k 2
s.substr(k) 2+(1*2))
k 3
a 2
op +
s.substr(k) (1*2))
k 5
s.substr(k) 1*2))
k 6
a 1
op *
s.substr(k) 2))
k 8
b 2
b 1
s.substr(k) (--0+(2*0))
k 0
s.substr(k) --0+(2*0))
k 1
s.substr(k) -0+(2*0))
k 2
s.substr(k) 0+(2*0))
k 3
a 0
op +
s.substr(k) (2*0))
k 5
s.substr(k) 2*0))
k 6
a 2
op *
s.substr(k) 0))
k 8
b 0
b 0
s.substr(k) (--1+(2*0))
k 0
s.substr(k) --1+(2*0))
k 1
s.substr(k) -1+(2*0))
k 2
s.substr(k) 1+(2*0))
k 3
a 1
op +
s.substr(k) (2*0))
k 5
s.substr(k) 2*0))
k 6
a 2
op *
s.substr(k) 0))
k 8
b 0
b 0
s.substr(k) (--2+(2*0))
k 0
s.substr(k) --2+(2*0))
k 1
s.substr(k) -2+(2*0))
k 2
s.substr(k) 2+(2*0))
k 3
a 2
op +
s.substr(k) (2*0))
k 5
s.substr(k) 2*0))
k 6
a 2
op *
s.substr(k) 0))
k 8
b 0
b 0
s.substr(k) (--0+(2*1))
k 0
s.substr(k) --0+(2*1))
k 1
s.substr(k) -0+(2*1))
k 2
s.substr(k) 0+(2*1))
k 3
a 0
op +
s.substr(k) (2*1))
k 5
s.substr(k) 2*1))
k 6
a 2
op *
s.substr(k) 1))
k 8
b 1
b 1
s.substr(k) (--1+(2*1))
k 0
s.substr(k) --1+(2*1))
k 1
s.substr(k) -1+(2*1))
k 2
s.substr(k) 1+(2*1))
k 3
a 1
op +
s.substr(k) (2*1))
k 5
s.substr(k) 2*1))
k 6
a 2
op *
s.substr(k) 1))
k 8
b 1
b 1
s.substr(k) (--2+(2*1))
k 0
s.substr(k) --2+(2*1))
k 1
s.substr(k) -2+(2*1))
k 2
s.substr(k) 2+(2*1))
k 3
a 2
op +
s.substr(k) (2*1))
k 5
s.substr(k) 2*1))
k 6
a 2
op *
s.substr(k) 1))
k 8
b 1
b 1
s.substr(k) (--0+(2*2))
k 0
s.substr(k) --0+(2*2))
k 1
s.substr(k) -0+(2*2))
k 2
s.substr(k) 0+(2*2))
k 3
a 0
op +
s.substr(k) (2*2))
k 5
s.substr(k) 2*2))
k 6
a 2
op *
s.substr(k) 2))
k 8
b 2
b 2
s.substr(k) (--1+(2*2))
k 0
s.substr(k) --1+(2*2))
k 1
s.substr(k) -1+(2*2))
k 2
s.substr(k) 1+(2*2))
k 3
a 1
op +
s.substr(k) (2*2))
k 5
s.substr(k) 2*2))
k 6
a 2
op *
s.substr(k) 2))
k 8
b 2
b 2
s.substr(k) (--2+(2*2))
k 0
s.substr(k) --2+(2*2))
k 1
s.substr(k) -2+(2*2))
k 2
s.substr(k) 2+(2*2))
k 3
a 2
op +
s.substr(k) (2*2))
k 5
s.substr(k) 2*2))
k 6
a 2
op *
s.substr(k) 2))
k 8
b 2
b 2
s.substr(k) (0*-0)
k 0
s.substr(k) 0*-0)
k 1
a 0
op *
s.substr(k) -0)
k 3
s.substr(k) 0)
k 4
b 2
s.substr(k) (0*-0)
k 0
s.substr(k) 0*-0)
k 1
a 0
op *
s.substr(k) -0)
k 3
s.substr(k) 0)
k 4
b 2
s.substr(k) (0*-0)
k 0
s.substr(k) 0*-0)
k 1
a 0
op *
s.substr(k) -0)
k 3
s.substr(k) 0)
k 4
b 2
s.substr(k) (0*-0)
k 0
s.substr(k) 0*-0)
k 1
a 0
op *
s.substr(k) -0)
k 3
s.substr(k) 0)
k 4
b 2
s.substr(k) (0*-0)
k 0
s.substr(k) 0*-0)
k 1
a 0
op *
s.substr(k) -0)
k 3
s.substr(k) 0)
k 4
b 2
s.substr(k) (0*-0)
k 0
s.substr(k) 0*-0)
k 1
a 0
op *
s.substr(k) -0)
k 3
s.substr(k) 0)
k 4
b 2
s.substr(k) (0*-0)
k 0
s.substr(k) 0*-0)
k 1
a 0
op *
s.substr(k) -0)
k 3
s.substr(k) 0)
k 4
b 2
s.substr(k) (0*-0)
k 0
s.substr(k) 0*-0)
k 1
a 0
op *
s.substr(k) -0)
k 3
s.substr(k) 0)
k 4
b 2
s.substr(k) (0*-0)
k 0
s.substr(k) 0*-0)
k 1
a 0
op *
s.substr(k) -0)
k 3
s.substr(k) 0)
k 4
b 2
s.substr(k) (1*-1)
k 0
s.substr(k) 1*-1)
k 1
a 1
op *
s.substr(k) -1)
k 3
s.substr(k) 1)
k 4
b 1
s.substr(k) (1*-1)
k 0
s.substr(k) 1*-1)
k 1
a 1
op *
s.substr(k) -1)
k 3
s.substr(k) 1)
k 4
b 1
s.substr(k) (1*-1)
k 0
s.substr(k) 1*-1)
k 1
a 1
op *
s.substr(k) -1)
k 3
s.substr(k) 1)
k 4
b 1
s.substr(k) (1*-1)
k 0
s.substr(k) 1*-1)
k 1
a 1
op *
s.substr(k) -1)
k 3
s.substr(k) 1)
k 4
b 1
s.substr(k) (1*-1)
k 0
s.substr(k) 1*-1)
k 1
a 1
op *
s.substr(k) -1)
k 3
s.substr(k) 1)
k 4
b 1
s.substr(k) (1*-1)
k 0
s.substr(k) 1*-1)
k 1
a 1
op *
s.substr(k) -1)
k 3
s.substr(k) 1)
k 4
b 1
s.substr(k) (1*-1)
k 0
s.substr(k) 1*-1)
k 1
a 1
op *
s.substr(k) -1)
k 3
s.substr(k) 1)
k 4
b 1
s.substr(k) (1*-1)
k 0
s.substr(k) 1*-1)
k 1
a 1
op *
s.substr(k) -1)
k 3
s.substr(k) 1)
k 4
b 1
s.substr(k) (1*-1)
k 0
s.substr(k) 1*-1)
k 1
a 1
op *
s.substr(k) -1)
k 3
s.substr(k) 1)
k 4
b 1
s.substr(k) (2*-2)
k 0
s.substr(k) 2*-2)
k 1
a 2
op *
s.substr(k) -2)
k 3
s.substr(k) 2)
k 4
b 0
s.substr(k) (2*-2)
k 0
s.substr(k) 2*-2)
k 1
a 2
op *
s.substr(k) -2)
k 3
s.substr(k) 2)
k 4
b 0
s.substr(k) (2*-2)
k 0
s.substr(k) 2*-2)
k 1
a 2
op *
s.substr(k) -2)
k 3
s.substr(k) 2)
k 4
b 0
s.substr(k) (2*-2)
k 0
s.substr(k) 2*-2)
k 1
a 2
op *
s.substr(k) -2)
k 3
s.substr(k) 2)
k 4
b 0
s.substr(k) (2*-2)
k 0
s.substr(k) 2*-2)
k 1
a 2
op *
s.substr(k) -2)
k 3
s.substr(k) 2)
k 4
b 0
s.substr(k) (2*-2)
k 0
s.substr(k) 2*-2)
k 1
a 2
op *
s.substr(k) -2)
k 3
s.substr(k) 2)
k 4
b 0
s.substr(k) (2*-2)
k 0
s.substr(k) 2*-2)
k 1
a 2
op *
s.substr(k) -2)
k 3
s.substr(k) 2)
k 4
b 0
s.substr(k) (2*-2)
k 0
s.substr(k) 2*-2)
k 1
a 2
op *
s.substr(k) -2)
k 3
s.substr(k) 2)
k 4
b 0
s.substr(k) (2*-2)
k 0
s.substr(k) 2*-2)
k 1
a 2
op *
s.substr(k) -2)
k 3
s.substr(k) 2)
k 4
b 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 2
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) 1
k 0
s.substr(k) (-1+(((---0+0)*(--0+---0))*(-0+-0)))
k 0
s.substr(k) -1+(((---0+0)*(--0+---0))*(-0+-0)))
k 1
s.substr(k) 1+(((---0+0)*(--0+---0))*(-0+-0)))
k 2
a 1
op +
s.substr(k) (((---0+0)*(--0+---0))*(-0+-0)))
k 4
s.substr(k) ((---0+0)*(--0+---0))*(-0+-0)))
k 5
s.substr(k) (---0+0)*(--0+---0))*(-0+-0)))
k 6
s.substr(k) ---0+0)*(--0+---0))*(-0+-0)))
k 7
s.substr(k) --0+0)*(--0+---0))*(-0+-0)))
k 8
s.substr(k) -0+0)*(--0+---0))*(-0+-0)))
k 9
s.substr(k) 0+0)*(--0+---0))*(-0+-0)))
k 10
a 2
op +
s.substr(k) 0)*(--0+---0))*(-0+-0)))
k 12
b 0
a 2
op *
s.substr(k) (--0+---0))*(-0+-0)))
k 15
s.substr(k) --0+---0))*(-0+-0)))
k 16
s.substr(k) -0+---0))*(-0+-0)))
k 17
s.substr(k) 0+---0))*(-0+-0)))
k 18
a 0
op +
s.substr(k) ---0))*(-0+-0)))
k 20
s.substr(k) --0))*(-0+-0)))
k 21
s.substr(k) -0))*(-0+-0)))
k 22
s.substr(k) 0))*(-0+-0)))
k 23
b 2
b 2
a 2
op *
s.substr(k) (-0+-0)))
k 27
s.substr(k) -0+-0)))
k 28
s.substr(k) 0+-0)))
k 29
a 2
op +
s.substr(k) -0)))
k 31
s.substr(k) 0)))
k 32
b 2
b 2
b 2
s.substr(k) (-1+(((---0+0)*(--0+---1))*(-1+-0)))
k 0
s.substr(k) -1+(((---0+0)*(--0+---1))*(-1+-0)))
k 1
s.substr(k) 1+(((---0+0)*(--0+---1))*(-1+-0)))
k 2
a 1
op +
s.substr(k) (((---0+0)*(--0+---1))*(-1+-0)))
k 4
s.substr(k) ((---0+0)*(--0+---1))*(-1+-0)))
k 5
s.substr(k) (---0+0)*(--0+---1))*(-1+-0)))
k 6
s.substr(k) ---0+0)*(--0+---1))*(-1+-0)))
k 7
s.substr(k) --0+0)*(--0+---1))*(-1+-0)))
k 8
s.substr(k) -0+0)*(--0+---1))*(-1+-0)))
k 9
s.substr(k) 0+0)*(--0+---1))*(-1+-0)))
k 10
a 2
op +
s.substr(k) 0)*(--0+---1))*(-1+-0)))
k 12
b 0
a 2
op *
s.substr(k) (--0+---1))*(-1+-0)))
k 15
s.substr(k) --0+---1))*(-1+-0)))
k 16
s.substr(k) -0+---1))*(-1+-0)))
k 17
s.substr(k) 0+---1))*(-1+-0)))
k 18
a 0
op +
s.substr(k) ---1))*(-1+-0)))
k 20
s.substr(k) --1))*(-1+-0)))
k 21
s.substr(k) -1))*(-1+-0)))
k 22
s.substr(k) 1))*(-1+-0)))
k 23
b 1
b 1
a 1
op *
s.substr(k) (-1+-0)))
k 27
s.substr(k) -1+-0)))
k 28
s.substr(k) 1+-0)))
k 29
a 1
op +
s.substr(k) -0)))
k 31
s.substr(k) 0)))
k 32
b 2
b 2
b 1
s.substr(k) (-1+(((---0+0)*(--0+---2))*(-2+-0)))
k 0
s.substr(k) -1+(((---0+0)*(--0+---2))*(-2+-0)))
k 1
s.substr(k) 1+(((---0+0)*(--0+---2))*(-2+-0)))
k 2
a 1
op +
s.substr(k) (((---0+0)*(--0+---2))*(-2+-0)))
k 4
s.substr(k) ((---0+0)*(--0+---2))*(-2+-0)))
k 5
s.substr(k) (---0+0)*(--0+---2))*(-2+-0)))
k 6
s.substr(k) ---0+0)*(--0+---2))*(-2+-0)))
k 7
s.substr(k) --0+0)*(--0+---2))*(-2+-0)))
k 8
s.substr(k) -0+0)*(--0+---2))*(-2+-0)))
k 9
s.substr(k) 0+0)*(--0+---2))*(-2+-0)))
k 10
a 2
op +
s.substr(k) 0)*(--0+---2))*(-2+-0)))
k 12
b 0
a 2
op *
s.substr(k) (--0+---2))*(-2+-0)))
k 15
s.substr(k) --0+---2))*(-2+-0)))
k 16
s.substr(k) -0+---2))*(-2+-0)))
k 17
s.substr(k) 0+---2))*(-2+-0)))
k 18
a 0
op +
s.substr(k) ---2))*(-2+-0)))
k 20
s.substr(k) --2))*(-2+-0)))
k 21
s.substr(k) -2))*(-2+-0)))
k 22
s.substr(k) 2))*(-2+-0)))
k 23
b 0
b 0
a 0
op *
s.substr(k) (-2+-0)))
k 27
s.substr(k) -2+-0)))
k 28
s.substr(k) 2+-0)))
k 29
a 0
op +
s.substr(k) -0)))
k 31
s.substr(k) 0)))
k 32
b 2
b 2
b 0
s.substr(k) (-1+(((---0+1)*(--1+---0))*(-0+-0)))
k 0
s.substr(k) -1+(((---0+1)*(--1+---0))*(-0+-0)))
k 1
s.substr(k) 1+(((---0+1)*(--1+---0))*(-0+-0)))
k 2
a 1
op +
s.substr(k) (((---0+1)*(--1+---0))*(-0+-0)))
k 4
s.substr(k) ((---0+1)*(--1+---0))*(-0+-0)))
k 5
s.substr(k) (---0+1)*(--1+---0))*(-0+-0)))
k 6
s.substr(k) ---0+1)*(--1+---0))*(-0+-0)))
k 7
s.substr(k) --0+1)*(--1+---0))*(-0+-0)))
k 8
s.substr(k) -0+1)*(--1+---0))*(-0+-0)))
k 9
s.substr(k) 0+1)*(--1+---0))*(-0+-0)))
k 10
a 2
op +
s.substr(k) 1)*(--1+---0))*(-0+-0)))
k 12
b 1
a 2
op *
s.substr(k) (--1+---0))*(-0+-0)))
k 15
s.substr(k) --1+---0))*(-0+-0)))
k 16
s.substr(k) -1+---0))*(-0+-0)))
k 17
s.substr(k) 1+---0))*(-0+-0)))
k 18
a 1
op +
s.substr(k) ---0))*(-0+-0)))
k 20
s.substr(k) --0))*(-0+-0)))
k 21
s.substr(k) -0))*(-0+-0)))
k 22
s.substr(k) 0))*(-0+-0)))
k 23
b 2
b 2
a 2
op *
s.substr(k) (-0+-0)))
k 27
s.substr(k) -0+-0)))
k 28
s.substr(k) 0+-0)))
k 29
a 2
op +
s.substr(k) -0)))
k 31
s.substr(k) 0)))
k 32
b 2
b 2
b 2
s.substr(k) (-1+(((---0+1)*(--1+---1))*(-1+-0)))
k 0
s.substr(k) -1+(((---0+1)*(--1+---1))*(-1+-0)))
k 1
s.substr(k) 1+(((---0+1)*(--1+---1))*(-1+-0)))
k 2
a 1
op +
s.substr(k) (((---0+1)*(--1+---1))*(-1+-0)))
k 4
s.substr(k) ((---0+1)*(--1+---1))*(-1+-0)))
k 5
s.substr(k) (---0+1)*(--1+---1))*(-1+-0)))
k 6
s.substr(k) ---0+1)*(--1+---1))*(-1+-0)))
k 7
s.substr(k) --0+1)*(--1+---1))*(-1+-0)))
k 8
s.substr(k) -0+1)*(--1+---1))*(-1+-0)))
k 9
s.substr(k) 0+1)*(--1+---1))*(-1+-0)))
k 10
a 2
op +
s.substr(k) 1)*(--1+---1))*(-1+-0)))
k 12
b 1
a 2
op *
s.substr(k) (--1+---1))*(-1+-0)))
k 15
s.substr(k) --1+---1))*(-1+-0)))
k 16
s.substr(k) -1+---1))*(-1+-0)))
k 17
s.substr(k) 1+---1))*(-1+-0)))
k 18
a 1
op +
s.substr(k) ---1))*(-1+-0)))
k 20
s.substr(k) --1))*(-1+-0)))
k 21
s.substr(k) -1))*(-1+-0)))
k 22
s.substr(k) 1))*(-1+-0)))
k 23
b 1
b 1
a 1
op *
s.substr(k) (-1+-0)))
k 27
s.substr(k) -1+-0)))
k 28
s.substr(k) 1+-0)))
k 29
a 1
op +
s.substr(k) -0)))
k 31
s.substr(k) 0)))
k 32
b 2
b 2
b 1
s.substr(k) (-1+(((---0+1)*(--1+---2))*(-2+-0)))
k 0
s.substr(k) -1+(((---0+1)*(--1+---2))*(-2+-0)))
k 1
s.substr(k) 1+(((---0+1)*(--1+---2))*(-2+-0)))
k 2
a 1
op +
s.substr(k) (((---0+1)*(--1+---2))*(-2+-0)))
k 4
s.substr(k) ((---0+1)*(--1+---2))*(-2+-0)))
k 5
s.substr(k) (---0+1)*(--1+---2))*(-2+-0)))
k 6
s.substr(k) ---0+1)*(--1+---2))*(-2+-0)))
k 7
s.substr(k) --0+1)*(--1+---2))*(-2+-0)))
k 8
s.substr(k) -0+1)*(--1+---2))*(-2+-0)))
k 9
s.substr(k) 0+1)*(--1+---2))*(-2+-0)))
k 10
a 2
op +
s.substr(k) 1)*(--1+---2))*(-2+-0)))
k 12
b 1
a 2
op *
s.substr(k) (--1+---2))*(-2+-0)))
k 15
s.substr(k) --1+---2))*(-2+-0)))
k 16
s.substr(k) -1+---2))*(-2+-0)))
k 17
s.substr(k) 1+---2))*(-2+-0)))
k 18
a 1
op +
s.substr(k) ---2))*(-2+-0)))
k 20
s.substr(k) --2))*(-2+-0)))
k 21
s.substr(k) -2))*(-2+-0)))
k 22
s.substr(k) 2))*(-2+-0)))
k 23
b 0
b 1
a 1
op *
s.substr(k) (-2+-0)))
k 27
s.substr(k) -2+-0)))
k 28
s.substr(k) 2+-0)))
k 29
a 0
op +
s.substr(k) -0)))
k 31
s.substr(k) 0)))
k 32
b 2
b 2
b 1
s.substr(k) (-1+(((---0+2)*(--2+---0))*(-0+-0)))
k 0
s.substr(k) -1+(((---0+2)*(--2+---0))*(-0+-0)))
k 1
s.substr(k) 1+(((---0+2)*(--2+---0))*(-0+-0)))
k 2
a 1
op +
s.substr(k) (((---0+2)*(--2+---0))*(-0+-0)))
k 4
s.substr(k) ((---0+2)*(--2+---0))*(-0+-0)))
k 5
s.substr(k) (---0+2)*(--2+---0))*(-0+-0)))
k 6
s.substr(k) ---0+2)*(--2+---0))*(-0+-0)))
k 7
s.substr(k) --0+2)*(--2+---0))*(-0+-0)))
k 8
s.substr(k) -0+2)*(--2+---0))*(-0+-0)))
k 9
s.substr(k) 0+2)*(--2+---0))*(-0+-0)))
k 10
a 2
op +
s.substr(k) 2)*(--2+---0))*(-0+-0)))
k 12
b 2
a 2
op *
s.substr(k) (--2+---0))*(-0+-0)))
k 15
s.substr(k) --2+---0))*(-0+-0)))
k 16
s.substr(k) -2+---0))*(-0+-0)))
k 17
s.substr(k) 2+---0))*(-0+-0)))
k 18
a 2
op +
s.substr(k) ---0))*(-0+-0)))
k 20
s.substr(k) --0))*(-0+-0)))
k 21
s.substr(k) -0))*(-0+-0)))
k 22
s.substr(k) 0))*(-0+-0)))
k 23
b 2
b 2
a 2
op *
s.substr(k) (-0+-0)))
k 27
s.substr(k) -0+-0)))
k 28
s.substr(k) 0+-0)))
k 29
a 2
op +
s.substr(k) -0)))
k 31
s.substr(k) 0)))
k 32
b 2
b 2
b 2
s.substr(k) (-1+(((---0+2)*(--2+---1))*(-1+-0)))
k 0
s.substr(k) -1+(((---0+2)*(--2+---1))*(-1+-0)))
k 1
s.substr(k) 1+(((---0+2)*(--2+---1))*(-1+-0)))
k 2
a 1
op +
s.substr(k) (((---0+2)*(--2+---1))*(-1+-0)))
k 4
s.substr(k) ((---0+2)*(--2+---1))*(-1+-0)))
k 5
s.substr(k) (---0+2)*(--2+---1))*(-1+-0)))
k 6
s.substr(k) ---0+2)*(--2+---1))*(-1+-0)))
k 7
s.substr(k) --0+2)*(--2+---1))*(-1+-0)))
k 8
s.substr(k) -0+2)*(--2+---1))*(-1+-0)))
k 9
s.substr(k) 0+2)*(--2+---1))*(-1+-0)))
k 10
a 2
op +
s.substr(k) 2)*(--2+---1))*(-1+-0)))
k 12
b 2
a 2
op *
s.substr(k) (--2+---1))*(-1+-0)))
k 15
s.substr(k) --2+---1))*(-1+-0)))
k 16
s.substr(k) -2+---1))*(-1+-0)))
k 17
s.substr(k) 2+---1))*(-1+-0)))
k 18
a 2
op +
s.substr(k) ---1))*(-1+-0)))
k 20
s.substr(k) --1))*(-1+-0)))
k 21
s.substr(k) -1))*(-1+-0)))
k 22
s.substr(k) 1))*(-1+-0)))
k 23
b 1
b 2
a 2
op *
s.substr(k) (-1+-0)))
k 27
s.substr(k) -1+-0)))
k 28
s.substr(k) 1+-0)))
k 29
a 1
op +
s.substr(k) -0)))
k 31
s.substr(k) 0)))
k 32
b 2
b 2
b 2
s.substr(k) (-1+(((---0+2)*(--2+---2))*(-2+-0)))
k 0
s.substr(k) -1+(((---0+2)*(--2+---2))*(-2+-0)))
k 1
s.substr(k) 1+(((---0+2)*(--2+---2))*(-2+-0)))
k 2
a 1
op +
s.substr(k) (((---0+2)*(--2+---2))*(-2+-0)))
k 4
s.substr(k) ((---0+2)*(--2+---2))*(-2+-0)))
k 5
s.substr(k) (---0+2)*(--2+---2))*(-2+-0)))
k 6
s.substr(k) ---0+2)*(--2+---2))*(-2+-0)))
k 7
s.substr(k) --0+2)*(--2+---2))*(-2+-0)))
k 8
s.substr(k) -0+2)*(--2+---2))*(-2+-0)))
k 9
s.substr(k) 0+2)*(--2+---2))*(-2+-0)))
k 10
a 2
op +
s.substr(k) 2)*(--2+---2))*(-2+-0)))
k 12
b 2
a 2
op *
s.substr(k) (--2+---2))*(-2+-0)))
k 15
s.substr(k) --2+---2))*(-2+-0)))
k 16
s.substr(k) -2+---2))*(-2+-0)))
k 17
s.substr(k) 2+---2))*(-2+-0)))
k 18
a 2
op +
s.substr(k) ---2))*(-2+-0)))
k 20
s.substr(k) --2))*(-2+-0)))
k 21
s.substr(k) -2))*(-2+-0)))
k 22
s.substr(k) 2))*(-2+-0)))
k 23
b 0
b 2
a 2
op *
s.substr(k) (-2+-0)))
k 27
s.substr(k) -2+-0)))
k 28
s.substr(k) 2+-0)))
k 29
a 0
op +
s.substr(k) -0)))
k 31
s.substr(k) 0)))
k 32
b 2
b 2
b 2
s.substr(k) (-1+(((---1+0)*(--0+---0))*(-0+-1)))
k 0
s.substr(k) -1+(((---1+0)*(--0+---0))*(-0+-1)))
k 1
s.substr(k) 1+(((---1+0)*(--0+---0))*(-0+-1)))
k 2
a 1
op +
s.substr(k) (((---1+0)*(--0+---0))*(-0+-1)))
k 4
s.substr(k) ((---1+0)*(--0+---0))*(-0+-1)))
k 5
s.substr(k) (---1+0)*(--0+---0))*(-0+-1)))
k 6
s.substr(k) ---1+0)*(--0+---0))*(-0+-1)))
k 7
s.substr(k) --1+0)*(--0+---0))*(-0+-1)))
k 8
s.substr(k) -1+0)*(--0+---0))*(-0+-1)))
k 9
s.substr(k) 1+0)*(--0+---0))*(-0+-1)))
k 10
a 1
op +
s.substr(k) 0)*(--0+---0))*(-0+-1)))
k 12
b 0
a 1
op *
s.substr(k) (--0+---0))*(-0+-1)))
k 15
s.substr(k) --0+---0))*(-0+-1)))
k 16
s.substr(k) -0+---0))*(-0+-1)))
k 17
s.substr(k) 0+---0))*(-0+-1)))
k 18
a 0
op +
s.substr(k) ---0))*(-0+-1)))
k 20
s.substr(k) --0))*(-0+-1)))
k 21
s.substr(k) -0))*(-0+-1)))
k 22
s.substr(k) 0))*(-0+-1)))
k 23
b 2
b 2
a 1
op *
s.substr(k) (-0+-1)))
k 27
s.substr(k) -0+-1)))
k 28
s.substr(k) 0+-1)))
k 29
a 2
op +
s.substr(k) -1)))
k 31
s.substr(k) 1)))
k 32
b 1
b 2
b 1
s.substr(k) (-1+(((---1+0)*(--0+---1))*(-1+-1)))
k 0
s.substr(k) -1+(((---1+0)*(--0+---1))*(-1+-1)))
k 1
s.substr(k) 1+(((---1+0)*(--0+---1))*(-1+-1)))
k 2
a 1
op +
s.substr(k) (((---1+0)*(--0+---1))*(-1+-1)))
k 4
s.substr(k) ((---1+0)*(--0+---1))*(-1+-1)))
k 5
s.substr(k) (---1+0)*(--0+---1))*(-1+-1)))
k 6
s.substr(k) ---1+0)*(--0+---1))*(-1+-1)))
k 7
s.substr(k) --1+0)*(--0+---1))*(-1+-1)))
k 8
s.substr(k) -1+0)*(--0+---1))*(-1+-1)))
k 9
s.substr(k) 1+0)*(--0+---1))*(-1+-1)))
k 10
a 1
op +
s.substr(k) 0)*(--0+---1))*(-1+-1)))
k 12
b 0
a 1
op *
s.substr(k) (--0+---1))*(-1+-1)))
k 15
s.substr(k) --0+---1))*(-1+-1)))
k 16
s.substr(k) -0+---1))*(-1+-1)))
k 17
s.substr(k) 0+---1))*(-1+-1)))
k 18
a 0
op +
s.substr(k) ---1))*(-1+-1)))
k 20
s.substr(k) --1))*(-1+-1)))
k 21
s.substr(k) -1))*(-1+-1)))
k 22
s.substr(k) 1))*(-1+-1)))
k 23
b 1
b 1
a 1
op *
s.substr(k) (-1+-1)))
k 27
s.substr(k) -1+-1)))
k 28
s.substr(k) 1+-1)))
k 29
a 1
op +
s.substr(k) -1)))
k 31
s.substr(k) 1)))
k 32
b 1
b 1
b 1
s.substr(k) (-1+(((---1+0)*(--0+---2))*(-2+-1)))
k 0
s.substr(k) -1+(((---1+0)*(--0+---2))*(-2+-1)))
k 1
s.substr(k) 1+(((---1+0)*(--0+---2))*(-2+-1)))
k 2
a 1
op +
s.substr(k) (((---1+0)*(--0+---2))*(-2+-1)))
k 4
s.substr(k) ((---1+0)*(--0+---2))*(-2+-1)))
k 5
s.substr(k) (---1+0)*(--0+---2))*(-2+-1)))
k 6
s.substr(k) ---1+0)*(--0+---2))*(-2+-1)))
k 7
s.substr(k) --1+0)*(--0+---2))*(-2+-1)))
k 8
s.substr(k) -1+0)*(--0+---2))*(-2+-1)))
k 9
s.substr(k) 1+0)*(--0+---2))*(-2+-1)))
k 10
a 1
op +
s.substr(k) 0)*(--0+---2))*(-2+-1)))
k 12
b 0
a 1
op *
s.substr(k) (--0+---2))*(-2+-1)))
k 15
s.substr(k) --0+---2))*(-2+-1)))
k 16
s.substr(k) -0+---2))*(-2+-1)))
k 17
s.substr(k) 0+---2))*(-2+-1)))
k 18
a 0
op +
s.substr(k) ---2))*(-2+-1)))
k 20
s.substr(k) --2))*(-2+-1)))
k 21
s.substr(k) -2))*(-2+-1)))
k 22
s.substr(k) 2))*(-2+-1)))
k 23
b 0
b 0
a 0
op *
s.substr(k) (-2+-1)))
k 27
s.substr(k) -2+-1)))
k 28
s.substr(k) 2+-1)))
k 29
a 0
op +
s.substr(k) -1)))
k 31
s.substr(k) 1)))
k 32
b 1
b 1
b 0
s.substr(k) (-1+(((---1+1)*(--1+---0))*(-0+-1)))
k 0
s.substr(k) -1+(((---1+1)*(--1+---0))*(-0+-1)))
k 1
s.substr(k) 1+(((---1+1)*(--1+---0))*(-0+-1)))
k 2
a 1
op +
s.substr(k) (((---1+1)*(--1+---0))*(-0+-1)))
k 4
s.substr(k) ((---1+1)*(--1+---0))*(-0+-1)))
k 5
s.substr(k) (---1+1)*(--1+---0))*(-0+-1)))
k 6
s.substr(k) ---1+1)*(--1+---0))*(-0+-1)))
k 7
s.substr(k) --1+1)*(--1+---0))*(-0+-1)))
k 8
s.substr(k) -1+1)*(--1+---0))*(-0+-1)))
k 9
s.substr(k) 1+1)*(--1+---0))*(-0+-1)))
k 10
a 1
op +
s.substr(k) 1)*(--1+---0))*(-0+-1)))
k 12
b 1
a 1
op *
s.substr(k) (--1+---0))*(-0+-1)))
k 15
s.substr(k) --1+---0))*(-0+-1)))
k 16
s.substr(k) -1+---0))*(-0+-1)))
k 17
s.substr(k) 1+---0))*(-0+-1)))
k 18
a 1
op +
s.substr(k) ---0))*(-0+-1)))
k 20
s.substr(k) --0))*(-0+-1)))
k 21
s.substr(k) -0))*(-0+-1)))
k 22
s.substr(k) 0))*(-0+-1)))
k 23
b 2
b 2
a 1
op *
s.substr(k) (-0+-1)))
k 27
s.substr(k) -0+-1)))
k 28
s.substr(k) 0+-1)))
k 29
a 2
op +
s.substr(k) -1)))
k 31
s.substr(k) 1)))
k 32
b 1
b 2
b 1
s.substr(k) (-1+(((---1+1)*(--1+---1))*(-1+-1)))
k 0
s.substr(k) -1+(((---1+1)*(--1+---1))*(-1+-1)))
k 1
s.substr(k) 1+(((---1+1)*(--1+---1))*(-1+-1)))
k 2
a 1
op +
s.substr(k) (((---1+1)*(--1+---1))*(-1+-1)))
k 4
s.substr(k) ((---1+1)*(--1+---1))*(-1+-1)))
k 5
s.substr(k) (---1+1)*(--1+---1))*(-1+-1)))
k 6
s.substr(k) ---1+1)*(--1+---1))*(-1+-1)))
k 7
s.substr(k) --1+1)*(--1+---1))*(-1+-1)))
k 8
s.substr(k) -1+1)*(--1+---1))*(-1+-1)))
k 9
s.substr(k) 1+1)*(--1+---1))*(-1+-1)))
k 10
a 1
op +
s.substr(k) 1)*(--1+---1))*(-1+-1)))
k 12
b 1
a 1
op *
s.substr(k) (--1+---1))*(-1+-1)))
k 15
s.substr(k) --1+---1))*(-1+-1)))
k 16
s.substr(k) -1+---1))*(-1+-1)))
k 17
s.substr(k) 1+---1))*(-1+-1)))
k 18
a 1
op +
s.substr(k) ---1))*(-1+-1)))
k 20
s.substr(k) --1))*(-1+-1)))
k 21
s.substr(k) -1))*(-1+-1)))
k 22
s.substr(k) 1))*(-1+-1)))
k 23
b 1
b 1
a 1
op *
s.substr(k) (-1+-1)))
k 27
s.substr(k) -1+-1)))
k 28
s.substr(k) 1+-1)))
k 29
a 1
op +
s.substr(k) -1)))
k 31
s.substr(k) 1)))
k 32
b 1
b 1
b 1
s.substr(k) (-1+(((---1+1)*(--1+---2))*(-2+-1)))
k 0
s.substr(k) -1+(((---1+1)*(--1+---2))*(-2+-1)))
k 1
s.substr(k) 1+(((---1+1)*(--1+---2))*(-2+-1)))
k 2
a 1
op +
s.substr(k) (((---1+1)*(--1+---2))*(-2+-1)))
k 4
s.substr(k) ((---1+1)*(--1+---2))*(-2+-1)))
k 5
s.substr(k) (---1+1)*(--1+---2))*(-2+-1)))
k 6
s.substr(k) ---1+1)*(--1+---2))*(-2+-1)))
k 7
s.substr(k) --1+1)*(--1+---2))*(-2+-1)))
k 8
s.substr(k) -1+1)*(--1+---2))*(-2+-1)))
k 9
s.substr(k) 1+1)*(--1+---2))*(-2+-1)))
k 10
a 1
op +
s.substr(k) 1)*(--1+---2))*(-2+-1)))
k 12
b 1
a 1
op *
s.substr(k) (--1+---2))*(-2+-1)))
k 15
s.substr(k) --1+---2))*(-2+-1)))
k 16
s.substr(k) -1+---2))*(-2+-1)))
k 17
s.substr(k) 1+---2))*(-2+-1)))
k 18
a 1
op +
s.substr(k) ---2))*(-2+-1)))
k 20
s.substr(k) --2))*(-2+-1)))
k 21
s.substr(k) -2))*(-2+-1)))
k 22
s.substr(k) 2))*(-2+-1)))
k 23
b 0
b 1
a 1
op *
s.substr(k) (-2+-1)))
k 27
s.substr(k) -2+-1)))
k 28
s.substr(k) 2+-1)))
k 29
a 0
op +
s.substr(k) -1)))
k 31
s.substr(k) 1)))
k 32
b 1
b 1
b 1
s.substr(k) (-1+(((---1+2)*(--2+---0))*(-0+-1)))
k 0
s.substr(k) -1+(((---1+2)*(--2+---0))*(-0+-1)))
k 1
s.substr(k) 1+(((---1+2)*(--2+---0))*(-0+-1)))
k 2
a 1
op +
s.substr(k) (((---1+2)*(--2+---0))*(-0+-1)))
k 4
s.substr(k) ((---1+2)*(--2+---0))*(-0+-1)))
k 5
s.substr(k) (---1+2)*(--2+---0))*(-0+-1)))
k 6
s.substr(k) ---1+2)*(--2+---0))*(-0+-1)))
k 7
s.substr(k) --1+2)*(--2+---0))*(-0+-1)))
k 8
s.substr(k) -1+2)*(--2+---0))*(-0+-1)))
k 9
s.substr(k) 1+2)*(--2+---0))*(-0+-1)))
k 10
a 1
op +
s.substr(k) 2)*(--2+---0))*(-0+-1)))
k 12
b 2
a 2
op *
s.substr(k) (--2+---0))*(-0+-1)))
k 15
s.substr(k) --2+---0))*(-0+-1)))
k 16
s.substr(k) -2+---0))*(-0+-1)))
k 17
s.substr(k) 2+---0))*(-0+-1)))
k 18
a 2
op +
s.substr(k) ---0))*(-0+-1)))
k 20
s.substr(k) --0))*(-0+-1)))
k 21
s.substr(k) -0))*(-0+-1)))
k 22
s.substr(k) 0))*(-0+-1)))
k 23
b 2
b 2
a 2
op *
s.substr(k) (-0+-1)))
k 27
s.substr(k) -0+-1)))
k 28
s.substr(k) 0+-1)))
k 29
a 2
op +
s.substr(k) -1)))
k 31
s.substr(k) 1)))
k 32
b 1
b 2
b 2
s.substr(k) (-1+(((---1+2)*(--2+---1))*(-1+-1)))
k 0
s.substr(k) -1+(((---1+2)*(--2+---1))*(-1+-1)))
k 1
s.substr(k) 1+(((---1+2)*(--2+---1))*(-1+-1)))
k 2
a 1
op +
s.substr(k) (((---1+2)*(--2+---1))*(-1+-1)))
k 4
s.substr(k) ((---1+2)*(--2+---1))*(-1+-1)))
k 5
s.substr(k) (---1+2)*(--2+---1))*(-1+-1)))
k 6
s.substr(k) ---1+2)*(--2+---1))*(-1+-1)))
k 7
s.substr(k) --1+2)*(--2+---1))*(-1+-1)))
k 8
s.substr(k) -1+2)*(--2+---1))*(-1+-1)))
k 9
s.substr(k) 1+2)*(--2+---1))*(-1+-1)))
k 10
a 1
op +
s.substr(k) 2)*(--2+---1))*(-1+-1)))
k 12
b 2
a 2
op *
s.substr(k) (--2+---1))*(-1+-1)))
k 15
s.substr(k) --2+---1))*(-1+-1)))
k 16
s.substr(k) -2+---1))*(-1+-1)))
k 17
s.substr(k) 2+---1))*(-1+-1)))
k 18
a 2
op +
s.substr(k) ---1))*(-1+-1)))
k 20
s.substr(k) --1))*(-1+-1)))
k 21
s.substr(k) -1))*(-1+-1)))
k 22
s.substr(k) 1))*(-1+-1)))
k 23
b 1
b 2
a 2
op *
s.substr(k) (-1+-1)))
k 27
s.substr(k) -1+-1)))
k 28
s.substr(k) 1+-1)))
k 29
a 1
op +
s.substr(k) -1)))
k 31
s.substr(k) 1)))
k 32
b 1
b 1
b 1
s.substr(k) (-1+(((---1+2)*(--2+---2))*(-2+-1)))
k 0
s.substr(k) -1+(((---1+2)*(--2+---2))*(-2+-1)))
k 1
s.substr(k) 1+(((---1+2)*(--2+---2))*(-2+-1)))
k 2
a 1
op +
s.substr(k) (((---1+2)*(--2+---2))*(-2+-1)))
k 4
s.substr(k) ((---1+2)*(--2+---2))*(-2+-1)))
k 5
s.substr(k) (---1+2)*(--2+---2))*(-2+-1)))
k 6
s.substr(k) ---1+2)*(--2+---2))*(-2+-1)))
k 7
s.substr(k) --1+2)*(--2+---2))*(-2+-1)))
k 8
s.substr(k) -1+2)*(--2+---2))*(-2+-1)))
k 9
s.substr(k) 1+2)*(--2+---2))*(-2+-1)))
k 10
a 1
op +
s.substr(k) 2)*(--2+---2))*(-2+-1)))
k 12
b 2
a 2
op *
s.substr(k) (--2+---2))*(-2+-1)))
k 15
s.substr(k) --2+---2))*(-2+-1)))
k 16
s.substr(k) -2+---2))*(-2+-1)))
k 17
s.substr(k) 2+---2))*(-2+-1)))
k 18
a 2
op +
s.substr(k) ---2))*(-2+-1)))
k 20
s.substr(k) --2))*(-2+-1)))
k 21
s.substr(k) -2))*(-2+-1)))
k 22
s.substr(k) 2))*(-2+-1)))
k 23
b 0
b 2
a 2
op *
s.substr(k) (-2+-1)))
k 27
s.substr(k) -2+-1)))
k 28
s.substr(k) 2+-1)))
k 29
a 0
op +
s.substr(k) -1)))
k 31
s.substr(k) 1)))
k 32
b 1
b 1
b 1
s.substr(k) (-1+(((---2+0)*(--0+---0))*(-0+-2)))
k 0
s.substr(k) -1+(((---2+0)*(--0+---0))*(-0+-2)))
k 1
s.substr(k) 1+(((---2+0)*(--0+---0))*(-0+-2)))
k 2
a 1
op +
s.substr(k) (((---2+0)*(--0+---0))*(-0+-2)))
k 4
s.substr(k) ((---2+0)*(--0+---0))*(-0+-2)))
k 5
s.substr(k) (---2+0)*(--0+---0))*(-0+-2)))
k 6
s.substr(k) ---2+0)*(--0+---0))*(-0+-2)))
k 7
s.substr(k) --2+0)*(--0+---0))*(-0+-2)))
k 8
s.substr(k) -2+0)*(--0+---0))*(-0+-2)))
k 9
s.substr(k) 2+0)*(--0+---0))*(-0+-2)))
k 10
a 0
op +
s.substr(k) 0)*(--0+---0))*(-0+-2)))
k 12
b 0
a 0
op *
s.substr(k) (--0+---0))*(-0+-2)))
k 15
s.substr(k) --0+---0))*(-0+-2)))
k 16
s.substr(k) -0+---0))*(-0+-2)))
k 17
s.substr(k) 0+---0))*(-0+-2)))
k 18
a 0
op +
s.substr(k) ---0))*(-0+-2)))
k 20
s.substr(k) --0))*(-0+-2)))
k 21
s.substr(k) -0))*(-0+-2)))
k 22
s.substr(k) 0))*(-0+-2)))
k 23
b 2
b 2
a 0
op *
s.substr(k) (-0+-2)))
k 27
s.substr(k) -0+-2)))
k 28
s.substr(k) 0+-2)))
k 29
a 2
op +
s.substr(k) -2)))
k 31
s.substr(k) 2)))
k 32
b 0
b 2
b 0
s.substr(k) (-1+(((---2+0)*(--0+---1))*(-1+-2)))
k 0
s.substr(k) -1+(((---2+0)*(--0+---1))*(-1+-2)))
k 1
s.substr(k) 1+(((---2+0)*(--0+---1))*(-1+-2)))
k 2
a 1
op +
s.substr(k) (((---2+0)*(--0+---1))*(-1+-2)))
k 4
s.substr(k) ((---2+0)*(--0+---1))*(-1+-2)))
k 5
s.substr(k) (---2+0)*(--0+---1))*(-1+-2)))
k 6
s.substr(k) ---2+0)*(--0+---1))*(-1+-2)))
k 7
s.substr(k) --2+0)*(--0+---1))*(-1+-2)))
k 8
s.substr(k) -2+0)*(--0+---1))*(-1+-2)))
k 9
s.substr(k) 2+0)*(--0+---1))*(-1+-2)))
k 10
a 0
op +
s.substr(k) 0)*(--0+---1))*(-1+-2)))
k 12
b 0
a 0
op *
s.substr(k) (--0+---1))*(-1+-2)))
k 15
s.substr(k) --0+---1))*(-1+-2)))
k 16
s.substr(k) -0+---1))*(-1+-2)))
k 17
s.substr(k) 0+---1))*(-1+-2)))
k 18
a 0
op +
s.substr(k) ---1))*(-1+-2)))
k 20
s.substr(k) --1))*(-1+-2)))
k 21
s.substr(k) -1))*(-1+-2)))
k 22
s.substr(k) 1))*(-1+-2)))
k 23
b 1
b 1
a 0
op *
s.substr(k) (-1+-2)))
k 27
s.substr(k) -1+-2)))
k 28
s.substr(k) 1+-2)))
k 29
a 1
op +
s.substr(k) -2)))
k 31
s.substr(k) 2)))
k 32
b 0
b 1
b 0
s.substr(k) (-1+(((---2+0)*(--0+---2))*(-2+-2)))
k 0
s.substr(k) -1+(((---2+0)*(--0+---2))*(-2+-2)))
k 1
s.substr(k) 1+(((---2+0)*(--0+---2))*(-2+-2)))
k 2
a 1
op +
s.substr(k) (((---2+0)*(--0+---2))*(-2+-2)))
k 4
s.substr(k) ((---2+0)*(--0+---2))*(-2+-2)))
k 5
s.substr(k) (---2+0)*(--0+---2))*(-2+-2)))
k 6
s.substr(k) ---2+0)*(--0+---2))*(-2+-2)))
k 7
s.substr(k) --2+0)*(--0+---2))*(-2+-2)))
k 8
s.substr(k) -2+0)*(--0+---2))*(-2+-2)))
k 9
s.substr(k) 2+0)*(--0+---2))*(-2+-2)))
k 10
a 0
op +
s.substr(k) 0)*(--0+---2))*(-2+-2)))
k 12
b 0
a 0
op *
s.substr(k) (--0+---2))*(-2+-2)))
k 15
s.substr(k) --0+---2))*(-2+-2)))
k 16
s.substr(k) -0+---2))*(-2+-2)))
k 17
s.substr(k) 0+---2))*(-2+-2)))
k 18
a 0
op +
s.substr(k) ---2))*(-2+-2)))
k 20
s.substr(k) --2))*(-2+-2)))
k 21
s.substr(k) -2))*(-2+-2)))
k 22
s.substr(k) 2))*(-2+-2)))
k 23
b 0
b 0
a 0
op *
s.substr(k) (-2+-2)))
k 27
s.substr(k) -2+-2)))
k 28
s.substr(k) 2+-2)))
k 29
a 0
op +
s.substr(k) -2)))
k 31
s.substr(k) 2)))
k 32
b 0
b 0
b 0
s.substr(k) (-1+(((---2+1)*(--1+---0))*(-0+-2)))
k 0
s.substr(k) -1+(((---2+1)*(--1+---0))*(-0+-2)))
k 1
s.substr(k) 1+(((---2+1)*(--1+---0))*(-0+-2)))
k 2
a 1
op +
s.substr(k) (((---2+1)*(--1+---0))*(-0+-2)))
k 4
s.substr(k) ((---2+1)*(--1+---0))*(-0+-2)))
k 5
s.substr(k) (---2+1)*(--1+---0))*(-0+-2)))
k 6
s.substr(k) ---2+1)*(--1+---0))*(-0+-2)))
k 7
s.substr(k) --2+1)*(--1+---0))*(-0+-2)))
k 8
s.substr(k) -2+1)*(--1+---0))*(-0+-2)))
k 9
s.substr(k) 2+1)*(--1+---0))*(-0+-2)))
k 10
a 0
op +
s.substr(k) 1)*(--1+---0))*(-0+-2)))
k 12
b 1
a 1
op *
s.substr(k) (--1+---0))*(-0+-2)))
k 15
s.substr(k) --1+---0))*(-0+-2)))
k 16
s.substr(k) -1+---0))*(-0+-2)))
k 17
s.substr(k) 1+---0))*(-0+-2)))
k 18
a 1
op +
s.substr(k) ---0))*(-0+-2)))
k 20
s.substr(k) --0))*(-0+-2)))
k 21
s.substr(k) -0))*(-0+-2)))
k 22
s.substr(k) 0))*(-0+-2)))
k 23
b 2
b 2
a 1
op *
s.substr(k) (-0+-2)))
k 27
s.substr(k) -0+-2)))
k 28
s.substr(k) 0+-2)))
k 29
a 2
op +
s.substr(k) -2)))
k 31
s.substr(k) 2)))
k 32
b 0
b 2
b 1
s.substr(k) (-1+(((---2+1)*(--1+---1))*(-1+-2)))
k 0
s.substr(k) -1+(((---2+1)*(--1+---1))*(-1+-2)))
k 1
s.substr(k) 1+(((---2+1)*(--1+---1))*(-1+-2)))
k 2
a 1
op +
s.substr(k) (((---2+1)*(--1+---1))*(-1+-2)))
k 4
s.substr(k) ((---2+1)*(--1+---1))*(-1+-2)))
k 5
s.substr(k) (---2+1)*(--1+---1))*(-1+-2)))
k 6
s.substr(k) ---2+1)*(--1+---1))*(-1+-2)))
k 7
s.substr(k) --2+1)*(--1+---1))*(-1+-2)))
k 8
s.substr(k) -2+1)*(--1+---1))*(-1+-2)))
k 9
s.substr(k) 2+1)*(--1+---1))*(-1+-2)))
k 10
a 0
op +
s.substr(k) 1)*(--1+---1))*(-1+-2)))
k 12
b 1
a 1
op *
s.substr(k) (--1+---1))*(-1+-2)))
k 15
s.substr(k) --1+---1))*(-1+-2)))
k 16
s.substr(k) -1+---1))*(-1+-2)))
k 17
s.substr(k) 1+---1))*(-1+-2)))
k 18
a 1
op +
s.substr(k) ---1))*(-1+-2)))
k 20
s.substr(k) --1))*(-1+-2)))
k 21
s.substr(k) -1))*(-1+-2)))
k 22
s.substr(k) 1))*(-1+-2)))
k 23
b 1
b 1
a 1
op *
s.substr(k) (-1+-2)))
k 27
s.substr(k) -1+-2)))
k 28
s.substr(k) 1+-2)))
k 29
a 1
op +
s.substr(k) -2)))
k 31
s.substr(k) 2)))
k 32
b 0
b 1
b 1
s.substr(k) (-1+(((---2+1)*(--1+---2))*(-2+-2)))
k 0
s.substr(k) -1+(((---2+1)*(--1+---2))*(-2+-2)))
k 1
s.substr(k) 1+(((---2+1)*(--1+---2))*(-2+-2)))
k 2
a 1
op +
s.substr(k) (((---2+1)*(--1+---2))*(-2+-2)))
k 4
s.substr(k) ((---2+1)*(--1+---2))*(-2+-2)))
k 5
s.substr(k) (---2+1)*(--1+---2))*(-2+-2)))
k 6
s.substr(k) ---2+1)*(--1+---2))*(-2+-2)))
k 7
s.substr(k) --2+1)*(--1+---2))*(-2+-2)))
k 8
s.substr(k) -2+1)*(--1+---2))*(-2+-2)))
k 9
s.substr(k) 2+1)*(--1+---2))*(-2+-2)))
k 10
a 0
op +
s.substr(k) 1)*(--1+---2))*(-2+-2)))
k 12
b 1
a 1
op *
s.substr(k) (--1+---2))*(-2+-2)))
k 15
s.substr(k) --1+---2))*(-2+-2)))
k 16
s.substr(k) -1+---2))*(-2+-2)))
k 17
s.substr(k) 1+---2))*(-2+-2)))
k 18
a 1
op +
s.substr(k) ---2))*(-2+-2)))
k 20
s.substr(k) --2))*(-2+-2)))
k 21
s.substr(k) -2))*(-2+-2)))
k 22
s.substr(k) 2))*(-2+-2)))
k 23
b 0
b 1
a 1
op *
s.substr(k) (-2+-2)))
k 27
s.substr(k) -2+-2)))
k 28
s.substr(k) 2+-2)))
k 29
a 0
op +
s.substr(k) -2)))
k 31
s.substr(k) 2)))
k 32
b 0
b 0
b 0
s.substr(k) (-1+(((---2+2)*(--2+---0))*(-0+-2)))
k 0
s.substr(k) -1+(((---2+2)*(--2+---0))*(-0+-2)))
k 1
s.substr(k) 1+(((---2+2)*(--2+---0))*(-0+-2)))
k 2
a 1
op +
s.substr(k) (((---2+2)*(--2+---0))*(-0+-2)))
k 4
s.substr(k) ((---2+2)*(--2+---0))*(-0+-2)))
k 5
s.substr(k) (---2+2)*(--2+---0))*(-0+-2)))
k 6
s.substr(k) ---2+2)*(--2+---0))*(-0+-2)))
k 7
s.substr(k) --2+2)*(--2+---0))*(-0+-2)))
k 8
s.substr(k) -2+2)*(--2+---0))*(-0+-2)))
k 9
s.substr(k) 2+2)*(--2+---0))*(-0+-2)))
k 10
a 0
op +
s.substr(k) 2)*(--2+---0))*(-0+-2)))
k 12
b 2
a 2
op *
s.substr(k) (--2+---0))*(-0+-2)))
k 15
s.substr(k) --2+---0))*(-0+-2)))
k 16
s.substr(k) -2+---0))*(-0+-2)))
k 17
s.substr(k) 2+---0))*(-0+-2)))
k 18
a 2
op +
s.substr(k) ---0))*(-0+-2)))
k 20
s.substr(k) --0))*(-0+-2)))
k 21
s.substr(k) -0))*(-0+-2)))
k 22
s.substr(k) 0))*(-0+-2)))
k 23
b 2
b 2
a 2
op *
s.substr(k) (-0+-2)))
k 27
s.substr(k) -0+-2)))
k 28
s.substr(k) 0+-2)))
k 29
a 2
op +
s.substr(k) -2)))
k 31
s.substr(k) 2)))
k 32
b 0
b 2
b 2
s.substr(k) (-1+(((---2+2)*(--2+---1))*(-1+-2)))
k 0
s.substr(k) -1+(((---2+2)*(--2+---1))*(-1+-2)))
k 1
s.substr(k) 1+(((---2+2)*(--2+---1))*(-1+-2)))
k 2
a 1
op +
s.substr(k) (((---2+2)*(--2+---1))*(-1+-2)))
k 4
s.substr(k) ((---2+2)*(--2+---1))*(-1+-2)))
k 5
s.substr(k) (---2+2)*(--2+---1))*(-1+-2)))
k 6
s.substr(k) ---2+2)*(--2+---1))*(-1+-2)))
k 7
s.substr(k) --2+2)*(--2+---1))*(-1+-2)))
k 8
s.substr(k) -2+2)*(--2+---1))*(-1+-2)))
k 9
s.substr(k) 2+2)*(--2+---1))*(-1+-2)))
k 10
a 0
op +
s.substr(k) 2)*(--2+---1))*(-1+-2)))
k 12
b 2
a 2
op *
s.substr(k) (--2+---1))*(-1+-2)))
k 15
s.substr(k) --2+---1))*(-1+-2)))
k 16
s.substr(k) -2+---1))*(-1+-2)))
k 17
s.substr(k) 2+---1))*(-1+-2)))
k 18
a 2
op +
s.substr(k) ---1))*(-1+-2)))
k 20
s.substr(k) --1))*(-1+-2)))
k 21
s.substr(k) -1))*(-1+-2)))
k 22
s.substr(k) 1))*(-1+-2)))
k 23
b 1
b 2
a 2
op *
s.substr(k) (-1+-2)))
k 27
s.substr(k) -1+-2)))
k 28
s.substr(k) 1+-2)))
k 29
a 1
op +
s.substr(k) -2)))
k 31
s.substr(k) 2)))
k 32
b 0
b 1
b 1
s.substr(k) (-1+(((---2+2)*(--2+---2))*(-2+-2)))
k 0
s.substr(k) -1+(((---2+2)*(--2+---2))*(-2+-2)))
k 1
s.substr(k) 1+(((---2+2)*(--2+---2))*(-2+-2)))
k 2
a 1
op +
s.substr(k) (((---2+2)*(--2+---2))*(-2+-2)))
k 4
s.substr(k) ((---2+2)*(--2+---2))*(-2+-2)))
k 5
s.substr(k) (---2+2)*(--2+---2))*(-2+-2)))
k 6
s.substr(k) ---2+2)*(--2+---2))*(-2+-2)))
k 7
s.substr(k) --2+2)*(--2+---2))*(-2+-2)))
k 8
s.substr(k) -2+2)*(--2+---2))*(-2+-2)))
k 9
s.substr(k) 2+2)*(--2+---2))*(-2+-2)))
k 10
a 0
op +
s.substr(k) 2)*(--2+---2))*(-2+-2)))
k 12
b 2
a 2
op *
s.substr(k) (--2+---2))*(-2+-2)))
k 15
s.substr(k) --2+---2))*(-2+-2)))
k 16
s.substr(k) -2+---2))*(-2+-2)))
k 17
s.substr(k) 2+---2))*(-2+-2)))
k 18
a 2
op +
s.substr(k) ---2))*(-2+-2)))
k 20
s.substr(k) --2))*(-2+-2)))
k 21
s.substr(k) -2))*(-2+-2)))
k 22
s.substr(k) 2))*(-2+-2)))
k 23
b 0
b 2
a 2
op *
s.substr(k) (-2+-2)))
k 27
s.substr(k) -2+-2)))
k 28
s.substr(k) 2+-2)))
k 29
a 0
op +
s.substr(k) -2)))
k 31
s.substr(k) 2)))
k 32
b 0
b 0
b 0
|
p00737 | C++ | Runtime Error | #include <iostream>
#include <queue>
using namespace std;
int W, H;
int inf = 1e9;
int dx[4] = {0, -1, 0, 1}, dy[4] = {1, 0, -1, 0};
int dp[21][21][4] = {};
int S[21][21] = {};
int C[4] = {};
struct state {
int x, y, direction, dist;
bool operator<(const state &right) const { return dist > right.dist; }
void go() {
x += dx[direction];
y += dy[direction];
}
void turn_right() {
direction--;
(direction += 4) %= 4;
x += dx[direction];
y += dy[direction];
}
void turn_back() {
(direction += 2) %= 4;
x += dx[direction];
y += dy[direction];
}
void turn_left() {
direction++;
direction %= 4;
x += dx[direction];
y += dy[direction];
}
void instruction(int i) {
if (i == 0)
go();
if (i == 1)
turn_right();
if (i == 2)
turn_back();
if (i == 3)
turn_left();
}
bool in() { return 1 <= x && x <= H && 1 <= y && y <= W; }
};
int main() {
while (cin >> W >> H && W > 0) {
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
cin >> S[i][j];
for (int k = 0; k < 4; k++)
dp[i][j][k] = inf;
}
}
for (int i = 0; i < 4; i++)
cin >> C[i];
dp[1][1][0] = 0;
priority_queue<state> Q;
state init = {1, 1, 0, 0};
Q.push(init);
while (!Q.empty()) {
state now = Q.top();
Q.pop();
if (dp[now.x][now.y][now.direction] < now.dist)
continue;
for (int i = 0; i < 4; i++) {
state ne = now;
ne.instruction(i);
int c = now.dist + C[i] * (i != S[now.x][now.y]);
if (!ne.in())
continue;
if (dp[ne.x][ne.y][ne.direction] > c) {
dp[ne.x][ne.y][ne.direction] = c;
ne.dist = c;
Q.push(ne);
}
}
}
int ans = inf;
for (int i = 0; i < 4; i++)
ans = min(ans, dp[H][W][i]);
cout << ans << endl;
}
}
| #include <iostream>
#include <queue>
using namespace std;
int W, H;
int inf = 1e9;
int dx[4] = {0, -1, 0, 1}, dy[4] = {1, 0, -1, 0};
int dp[31][31][4] = {};
int S[31][31] = {};
int C[4] = {};
struct state {
int x, y, direction, dist;
bool operator<(const state &right) const { return dist > right.dist; }
void go() {
x += dx[direction];
y += dy[direction];
}
void turn_right() {
direction--;
(direction += 4) %= 4;
x += dx[direction];
y += dy[direction];
}
void turn_back() {
(direction += 2) %= 4;
x += dx[direction];
y += dy[direction];
}
void turn_left() {
direction++;
direction %= 4;
x += dx[direction];
y += dy[direction];
}
void instruction(int i) {
if (i == 0)
go();
if (i == 1)
turn_right();
if (i == 2)
turn_back();
if (i == 3)
turn_left();
}
bool in() { return 1 <= x && x <= H && 1 <= y && y <= W; }
};
int main() {
while (cin >> W >> H && W > 0) {
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
cin >> S[i][j];
for (int k = 0; k < 4; k++)
dp[i][j][k] = inf;
}
}
for (int i = 0; i < 4; i++)
cin >> C[i];
dp[1][1][0] = 0;
priority_queue<state> Q;
state init = {1, 1, 0, 0};
Q.push(init);
while (!Q.empty()) {
state now = Q.top();
Q.pop();
if (dp[now.x][now.y][now.direction] < now.dist)
continue;
for (int i = 0; i < 4; i++) {
state ne = now;
ne.instruction(i);
int c = now.dist + C[i] * (i != S[now.x][now.y]);
if (!ne.in())
continue;
if (dp[ne.x][ne.y][ne.direction] > c) {
dp[ne.x][ne.y][ne.direction] = c;
ne.dist = c;
Q.push(ne);
}
}
}
int ans = inf;
for (int i = 0; i < 4; i++)
ans = min(ans, dp[H][W][i]);
cout << ans << endl;
}
}
| replace | 7 | 9 | 7 | 9 | 0 | |
p00737 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#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 = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
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;
#define INF INT_MAX
#define MAX_X 30
#define MAX_Y 30
int cost[4];
int w, h;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
struct P {
int cost, x, y, way;
bool operator>(const P &p) const {
if (cost != p.cost)
return cost > p.cost;
return y < p.y;
}
};
int main() {
while (cin >> w >> h, w | h) {
vector<vi> field(h, vi(w));
REP(iy, h) REP(ix, w) { cin >> field[iy][ix]; }
REP(i, 4) { cin >> cost[i]; }
vector<vector<vi>> costs(4, vector<vi>(h, vi(w, INF)));
costs[2][0][0] = 0; // right
priority_queue<P, vector<P>, greater<P>> que;
que.push((P){0, 0, 0, 2});
while (!que.empty()) {
P p = que.top();
que.pop();
if (p.x == w - 1 && p.y == h - 1) {
cout << p.cost << endl;
break;
}
int way = (p.way + field[p.y][p.x]) % 4;
int sx = p.x + dx[way];
int sy = p.y + dy[way];
if (0 <= sx && sx < w && 0 <= sy && sy < h) {
if (field[p.y][p.x] != 4) {
if (costs[way][sy][sx] > p.cost) {
costs[way][sy][sx] = p.cost;
que.push((P){p.cost, sx, sy, way});
}
}
}
REP(d, 4) {
way = (p.way + d) % 4;
sx = p.x + dx[way];
sy = p.y + dy[way];
if (0 <= sx && sx < w && 0 <= sy && sy < h) {
if (costs[way][sy][sx] > p.cost) {
costs[way][sy][sx] = p.cost + cost[d];
que.push((P){p.cost + cost[d], sx, sy, way});
}
}
}
}
}
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#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 = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
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;
#define INF INT_MAX
#define MAX_X 30
#define MAX_Y 30
int cost[4];
int w, h;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
struct P {
int cost, x, y, way;
bool operator>(const P &p) const {
if (cost != p.cost)
return cost > p.cost;
return y < p.y;
}
};
int main() {
while (cin >> w >> h, w | h) {
vector<vi> field(h, vi(w));
REP(iy, h) REP(ix, w) { cin >> field[iy][ix]; }
REP(i, 4) { cin >> cost[i]; }
vector<vector<vi>> costs(4, vector<vi>(h, vi(w, INF)));
costs[2][0][0] = 0; // right
priority_queue<P, vector<P>, greater<P>> que;
que.push((P){0, 0, 0, 2});
while (!que.empty()) {
P p = que.top();
que.pop();
if (p.x == w - 1 && p.y == h - 1) {
cout << p.cost << endl;
break;
}
int way = (p.way + field[p.y][p.x]) % 4;
int sx = p.x + dx[way];
int sy = p.y + dy[way];
if (0 <= sx && sx < w && 0 <= sy && sy < h) {
if (field[p.y][p.x] != 4) {
if (costs[way][sy][sx] > p.cost) {
costs[way][sy][sx] = p.cost;
que.push((P){p.cost, sx, sy, way});
}
}
}
REP(d, 4) {
way = (p.way + d) % 4;
sx = p.x + dx[way];
sy = p.y + dy[way];
if (0 <= sx && sx < w && 0 <= sy && sy < h) {
if (costs[way][sy][sx] > p.cost + cost[d]) {
costs[way][sy][sx] = p.cost + cost[d];
que.push((P){p.cost + cost[d], sx, sy, way});
}
}
}
}
}
} | replace | 94 | 95 | 94 | 95 | 0 | |
p00737 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define exist(s, e) ((s).find(e) != (s).end())
#define range(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) range(i, 0, n)
#define clr(a, b) memset((a), (b), sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
const double eps = 1e-10;
const double pi = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 29;
int w, h;
int table[35][35];
int c[4];
int dist[35][35][4];
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};
struct state {
int x, y, d, costs;
bool operator<(const state &arg) const { return costs < arg.costs; }
};
void dijkstra() {
rep(i, h) rep(j, w) rep(k, 4) dist[i][j][k] = inf;
dist[0][0][1] = 0;
state s;
s.x = 0, s.y = 0, s.d = 1, s.costs = 0;
priority_queue<state> q;
q.push(s);
while (!q.empty()) {
state cur = q.top();
q.pop();
int x, y, d, costs;
x = cur.x, y = cur.y, d = cur.d, costs = cur.costs;
if (dist[y][x][d] < costs)
continue;
rep(i, 4) {
int nx = x, ny = y, nd = d, ncosts = costs;
nd = (nd + i) % 4;
nx += dx[nd], ny += dy[nd];
if (table[y][x] != i)
ncosts += c[i];
if (0 <= nx && nx < w && 0 <= ny && ny < h) {
if (dist[ny][nx][nd] > ncosts) {
dist[ny][nx][nd] = ncosts;
state nexts;
nexts.x = nx, nexts.y = ny, nexts.d = nd, nexts.costs = ncosts;
q.push(nexts);
}
}
}
}
return;
}
int main(void) {
while (1) {
scanf("%d %d", &w, &h);
if (w == 0)
break;
rep(i, h) rep(j, w) scanf("%d", &table[i][j]);
rep(i, 4) scanf("%d", &c[i]);
dijkstra();
int ans = inf;
rep(i, 4) ans = min(ans, dist[h - 1][w - 1][i]);
printf("%d\n", ans);
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T> inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
template <class T> inline T sqr(T x) { return x * x; }
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define exist(s, e) ((s).find(e) != (s).end())
#define range(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) range(i, 0, n)
#define clr(a, b) memset((a), (b), sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
const double eps = 1e-10;
const double pi = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 29;
int w, h;
int table[35][35];
int c[4];
int dist[35][35][4];
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};
struct state {
int x, y, d, costs;
bool operator<(const state &arg) const { return costs > arg.costs; }
};
void dijkstra() {
rep(i, h) rep(j, w) rep(k, 4) dist[i][j][k] = inf;
dist[0][0][1] = 0;
state s;
s.x = 0, s.y = 0, s.d = 1, s.costs = 0;
priority_queue<state> q;
q.push(s);
while (!q.empty()) {
state cur = q.top();
q.pop();
int x, y, d, costs;
x = cur.x, y = cur.y, d = cur.d, costs = cur.costs;
if (dist[y][x][d] < costs)
continue;
rep(i, 4) {
int nx = x, ny = y, nd = d, ncosts = costs;
nd = (nd + i) % 4;
nx += dx[nd], ny += dy[nd];
if (table[y][x] != i)
ncosts += c[i];
if (0 <= nx && nx < w && 0 <= ny && ny < h) {
if (dist[ny][nx][nd] > ncosts) {
dist[ny][nx][nd] = ncosts;
state nexts;
nexts.x = nx, nexts.y = ny, nexts.d = nd, nexts.costs = ncosts;
q.push(nexts);
}
}
}
}
return;
}
int main(void) {
while (1) {
scanf("%d %d", &w, &h);
if (w == 0)
break;
rep(i, h) rep(j, w) scanf("%d", &table[i][j]);
rep(i, 4) scanf("%d", &c[i]);
dijkstra();
int ans = inf;
rep(i, 4) ans = min(ans, dist[h - 1][w - 1][i]);
printf("%d\n", ans);
}
return 0;
} | replace | 54 | 55 | 54 | 55 | TLE | |
p00737 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <queue>
#define N_MAX 30
#define INF (1e9)
using namespace std;
void dijkstra();
int w, h, data[N_MAX][N_MAX], d[N_MAX][N_MAX][4], c[4];
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};
typedef struct stu {
int mincost, y, x, dir;
bool operator<(const stu &right) const { return mincost < right.mincost; }
} dat;
int main() {
while (1) {
cin >> w >> h;
if (!w && !h)
break;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
cin >> data[i][j];
for (int i = 0; i < 4; i++)
cin >> c[i];
dijkstra();
}
return 0;
}
void dijkstra() {
priority_queue<dat> Q;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
for (int k = 0; k < 4; k++)
d[i][j][k] = INF;
d[0][0][1] = 0;
Q.push((dat){0, 0, 0, 1});
while (!Q.empty()) {
dat t = Q.top();
Q.pop();
int cost = t.mincost, y = t.y, x = t.x, dir = t.dir;
if (cost > d[y][x][dir])
continue;
for (int i = 0; i < 4; i++) {
int ny = y + dy[(dir + i) % 4], nx = x + dx[(dir + i) % 4];
int ndir = (dir + i) % 4;
if (ny < 0 || nx < 0 || h <= ny || w <= nx)
continue;
if (d[ny][nx][ndir] > cost + c[i]) {
d[ny][nx][ndir] = cost + c[i];
Q.push((dat){d[ny][nx][ndir], ny, nx, ndir});
}
if (data[y][x] != i)
continue;
if (d[ny][nx][ndir] > cost) {
d[ny][nx][ndir] = cost;
Q.push((dat){d[ny][nx][ndir], ny, nx, ndir});
}
}
}
int mincost = INF;
for (int i = 0; i < 4; i++)
mincost = min(mincost, d[h - 1][w - 1][i]);
cout << mincost << endl;
} | #include <algorithm>
#include <iostream>
#include <queue>
#define N_MAX 30
#define INF (1e9)
using namespace std;
void dijkstra();
int w, h, data[N_MAX][N_MAX], d[N_MAX][N_MAX][4], c[4];
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};
typedef struct stu {
int mincost, y, x, dir;
bool operator<(const stu &right) const { return mincost > right.mincost; }
} dat;
int main() {
while (1) {
cin >> w >> h;
if (!w && !h)
break;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
cin >> data[i][j];
for (int i = 0; i < 4; i++)
cin >> c[i];
dijkstra();
}
return 0;
}
void dijkstra() {
priority_queue<dat> Q;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
for (int k = 0; k < 4; k++)
d[i][j][k] = INF;
d[0][0][1] = 0;
Q.push((dat){0, 0, 0, 1});
while (!Q.empty()) {
dat t = Q.top();
Q.pop();
int cost = t.mincost, y = t.y, x = t.x, dir = t.dir;
if (cost > d[y][x][dir])
continue;
for (int i = 0; i < 4; i++) {
int ny = y + dy[(dir + i) % 4], nx = x + dx[(dir + i) % 4];
int ndir = (dir + i) % 4;
if (ny < 0 || nx < 0 || h <= ny || w <= nx)
continue;
if (d[ny][nx][ndir] > cost + c[i]) {
d[ny][nx][ndir] = cost + c[i];
Q.push((dat){d[ny][nx][ndir], ny, nx, ndir});
}
if (data[y][x] != i)
continue;
if (d[ny][nx][ndir] > cost) {
d[ny][nx][ndir] = cost;
Q.push((dat){d[ny][nx][ndir], ny, nx, ndir});
}
}
}
int mincost = INF;
for (int i = 0; i < 4; i++)
mincost = min(mincost, d[h - 1][w - 1][i]);
cout << mincost << endl;
} | replace | 12 | 13 | 12 | 13 | TLE | |
p00737 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
#define REP(i, N) for (ll i = 0; i < N; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main(void) {
while (true) {
int w, h;
cin >> w >> h;
if (w == 0 && h == 0)
break;
vector<vector<int>> ins(h, vector<int>(w));
vector<vector<vector<int>>> d(h,
vector<vector<int>>(w, vector<int>(4, INF)));
vector<int> c(4);
REP(i, h) { REP(j, w) cin >> ins[i][j]; }
REP(i, 4) cin >> c[i];
priority_queue<pair<ll, pair<P, ll>>> q;
pair<P, ll> np = pair<P, ll>(P(0, 0), 1);
REP(i, 100000) {
if (d[np.first.first][np.first.second][np.second] == 0)
break;
d[np.first.first][np.first.second][np.second] = 0;
q.push(pair<ll, pair<P, ll>>(
0, pair<P, ll>(P(np.first.first, np.first.second), np.second)));
if (ins[np.first.first][np.first.second] == 4)
break;
ll nh = np.first.first;
ll nw = np.first.second;
ll nr = np.second;
switch (ins[np.first.first][np.first.second]) {
case 0: {
if (np.second == 0) {
--nh;
}
if (np.second == 1) {
++nw;
}
if (np.second == 2) {
++nh;
}
if (np.second == 3) {
--nw;
}
break;
}
case 1: {
nr = (nr + 1) % 4;
if (np.second == 0) {
++nw;
}
if (np.second == 1) {
++nh;
}
if (np.second == 2) {
--nw;
}
if (np.second == 3) {
--nh;
}
break;
}
case 2: {
nr = (nr + 2) % 4;
if (np.second == 0) {
++nh;
}
if (np.second == 1) {
--nw;
}
if (np.second == 2) {
--nh;
}
if (np.second == 3) {
++nw;
}
break;
}
case 3: {
nr = (nr + 3) % 4;
if (np.second == 0) {
--nw;
}
if (np.second == 1) {
--nh;
}
if (np.second == 2) {
++nw;
}
if (np.second == 3) {
++nh;
}
break;
}
}
if (nh >= 0 && nh < h && nw >= 0 && nw < w) {
np.first.first = nh;
np.first.second = nw;
np.second = nr;
} else
break;
}
ll ans = INF;
// pair<bool, bool> hoge = pair<bool, bool>(false, false);
while (!q.empty()) {
pair<ll, pair<P, ll>> p = q.top();
q.pop();
if (d[p.second.first.first][p.second.first.second][p.second.second] !=
p.first)
continue;
// if(p.second.first == P(h - 1, w - 1)) {
// if(p.second.second == 1) hoge.first = true;
// if(p.second.second == 2) hoge.second = true;
// }
// if(hoge.first && hoge.second) break;
REP(i, 4) {
ll nh = p.second.first.first + dx[i];
ll nw = p.second.first.second + dy[i];
if (nh >= 0 && nh < h && nw >= 0 && nw < w) {
ll cost;
if (p.second.second == 0) {
switch (i) {
case 0: {
if (ins[p.second.first.first][p.second.first.second] == 2)
cost = 0;
else
cost = c[2];
break;
}
case 1: {
if (ins[p.second.first.first][p.second.first.second] == 1)
cost = 0;
else
cost = c[1];
break;
}
case 2: {
if (ins[p.second.first.first][p.second.first.second] == 0)
cost = 0;
else
cost = c[0];
break;
}
case 3: {
if (ins[p.second.first.first][p.second.first.second] == 3)
cost = 0;
else
cost = c[3];
break;
}
}
}
if (p.second.second == 1) {
switch (i) {
case 0: {
if (ins[p.second.first.first][p.second.first.second] == 1)
cost = 0;
else
cost = c[1];
break;
}
case 1: {
if (ins[p.second.first.first][p.second.first.second] == 0)
cost = 0;
else
cost = c[0];
break;
}
case 2: {
if (ins[p.second.first.first][p.second.first.second] == 3)
cost = 0;
else
cost = c[3];
break;
}
case 3: {
if (ins[p.second.first.first][p.second.first.second] == 2)
cost = 0;
else
cost = c[2];
break;
}
}
}
if (p.second.second == 2) {
switch (i) {
case 0: {
if (ins[p.second.first.first][p.second.first.second] == 0)
cost = 0;
else
cost = c[0];
break;
}
case 1: {
if (ins[p.second.first.first][p.second.first.second] == 3)
cost = 0;
else
cost = c[3];
break;
}
case 2: {
if (ins[p.second.first.first][p.second.first.second] == 2)
cost = 0;
else
cost = c[2];
break;
}
case 3: {
if (ins[p.second.first.first][p.second.first.second] == 1)
cost = 0;
else
cost = c[1];
break;
}
}
}
if (p.second.second == 3) {
switch (i) {
case 0: {
if (ins[p.second.first.first][p.second.first.second] == 3)
cost = 0;
else
cost = c[3];
break;
}
case 1: {
if (ins[p.second.first.first][p.second.first.second] == 2)
cost = 0;
else
cost = c[2];
break;
}
case 2: {
if (ins[p.second.first.first][p.second.first.second] == 1)
cost = 0;
else
cost = c[1];
break;
}
case 3: {
if (ins[p.second.first.first][p.second.first.second] == 0)
cost = 0;
else
cost = c[0];
break;
}
}
}
switch (i) {
case 0: {
if (d[nh][nw][2] > d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost) {
d[nh][nw][2] = d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost;
q.push(pair<ll, pair<P, ll>>(d[nh][nw][2],
pair<P, ll>(P(nh, nw), 2)));
}
break;
}
case 1: {
if (d[nh][nw][1] > d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost) {
d[nh][nw][1] = d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost;
q.push(pair<ll, pair<P, ll>>(d[nh][nw][1],
pair<P, ll>(P(nh, nw), 1)));
}
break;
}
case 2: {
if (d[nh][nw][0] > d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost) {
d[nh][nw][0] = d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost;
q.push(pair<ll, pair<P, ll>>(d[nh][nw][0],
pair<P, ll>(P(nh, nw), 0)));
}
break;
}
case 3: {
if (d[nh][nw][3] > d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost) {
d[nh][nw][3] = d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost;
q.push(pair<ll, pair<P, ll>>(d[nh][nw][3],
pair<P, ll>(P(nh, nw), 3)));
}
break;
}
}
}
}
}
REP(i, 4) { ans = min(ans, (ll)d[h - 1][w - 1][i]); }
cout << ans << endl;
}
} | #include <algorithm>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
#define REP(i, N) for (ll i = 0; i < N; ++i)
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define ALL(a) (a).begin(), (a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main(void) {
while (true) {
int w, h;
cin >> w >> h;
if (w == 0 && h == 0)
break;
vector<vector<int>> ins(h, vector<int>(w));
vector<vector<vector<int>>> d(h,
vector<vector<int>>(w, vector<int>(4, INF)));
vector<int> c(4);
REP(i, h) { REP(j, w) cin >> ins[i][j]; }
REP(i, 4) cin >> c[i];
priority_queue<pair<ll, pair<pair<ll, ll>, ll>>,
vector<pair<ll, pair<pair<ll, ll>, ll>>>,
greater<pair<ll, pair<pair<ll, ll>, ll>>>>
q;
pair<P, ll> np = pair<P, ll>(P(0, 0), 1);
REP(i, 100000) {
if (d[np.first.first][np.first.second][np.second] == 0)
break;
d[np.first.first][np.first.second][np.second] = 0;
q.push(pair<ll, pair<P, ll>>(
0, pair<P, ll>(P(np.first.first, np.first.second), np.second)));
if (ins[np.first.first][np.first.second] == 4)
break;
ll nh = np.first.first;
ll nw = np.first.second;
ll nr = np.second;
switch (ins[np.first.first][np.first.second]) {
case 0: {
if (np.second == 0) {
--nh;
}
if (np.second == 1) {
++nw;
}
if (np.second == 2) {
++nh;
}
if (np.second == 3) {
--nw;
}
break;
}
case 1: {
nr = (nr + 1) % 4;
if (np.second == 0) {
++nw;
}
if (np.second == 1) {
++nh;
}
if (np.second == 2) {
--nw;
}
if (np.second == 3) {
--nh;
}
break;
}
case 2: {
nr = (nr + 2) % 4;
if (np.second == 0) {
++nh;
}
if (np.second == 1) {
--nw;
}
if (np.second == 2) {
--nh;
}
if (np.second == 3) {
++nw;
}
break;
}
case 3: {
nr = (nr + 3) % 4;
if (np.second == 0) {
--nw;
}
if (np.second == 1) {
--nh;
}
if (np.second == 2) {
++nw;
}
if (np.second == 3) {
++nh;
}
break;
}
}
if (nh >= 0 && nh < h && nw >= 0 && nw < w) {
np.first.first = nh;
np.first.second = nw;
np.second = nr;
} else
break;
}
ll ans = INF;
// pair<bool, bool> hoge = pair<bool, bool>(false, false);
while (!q.empty()) {
pair<ll, pair<P, ll>> p = q.top();
q.pop();
if (d[p.second.first.first][p.second.first.second][p.second.second] !=
p.first)
continue;
// if(p.second.first == P(h - 1, w - 1)) {
// if(p.second.second == 1) hoge.first = true;
// if(p.second.second == 2) hoge.second = true;
// }
// if(hoge.first && hoge.second) break;
REP(i, 4) {
ll nh = p.second.first.first + dx[i];
ll nw = p.second.first.second + dy[i];
if (nh >= 0 && nh < h && nw >= 0 && nw < w) {
ll cost;
if (p.second.second == 0) {
switch (i) {
case 0: {
if (ins[p.second.first.first][p.second.first.second] == 2)
cost = 0;
else
cost = c[2];
break;
}
case 1: {
if (ins[p.second.first.first][p.second.first.second] == 1)
cost = 0;
else
cost = c[1];
break;
}
case 2: {
if (ins[p.second.first.first][p.second.first.second] == 0)
cost = 0;
else
cost = c[0];
break;
}
case 3: {
if (ins[p.second.first.first][p.second.first.second] == 3)
cost = 0;
else
cost = c[3];
break;
}
}
}
if (p.second.second == 1) {
switch (i) {
case 0: {
if (ins[p.second.first.first][p.second.first.second] == 1)
cost = 0;
else
cost = c[1];
break;
}
case 1: {
if (ins[p.second.first.first][p.second.first.second] == 0)
cost = 0;
else
cost = c[0];
break;
}
case 2: {
if (ins[p.second.first.first][p.second.first.second] == 3)
cost = 0;
else
cost = c[3];
break;
}
case 3: {
if (ins[p.second.first.first][p.second.first.second] == 2)
cost = 0;
else
cost = c[2];
break;
}
}
}
if (p.second.second == 2) {
switch (i) {
case 0: {
if (ins[p.second.first.first][p.second.first.second] == 0)
cost = 0;
else
cost = c[0];
break;
}
case 1: {
if (ins[p.second.first.first][p.second.first.second] == 3)
cost = 0;
else
cost = c[3];
break;
}
case 2: {
if (ins[p.second.first.first][p.second.first.second] == 2)
cost = 0;
else
cost = c[2];
break;
}
case 3: {
if (ins[p.second.first.first][p.second.first.second] == 1)
cost = 0;
else
cost = c[1];
break;
}
}
}
if (p.second.second == 3) {
switch (i) {
case 0: {
if (ins[p.second.first.first][p.second.first.second] == 3)
cost = 0;
else
cost = c[3];
break;
}
case 1: {
if (ins[p.second.first.first][p.second.first.second] == 2)
cost = 0;
else
cost = c[2];
break;
}
case 2: {
if (ins[p.second.first.first][p.second.first.second] == 1)
cost = 0;
else
cost = c[1];
break;
}
case 3: {
if (ins[p.second.first.first][p.second.first.second] == 0)
cost = 0;
else
cost = c[0];
break;
}
}
}
switch (i) {
case 0: {
if (d[nh][nw][2] > d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost) {
d[nh][nw][2] = d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost;
q.push(pair<ll, pair<P, ll>>(d[nh][nw][2],
pair<P, ll>(P(nh, nw), 2)));
}
break;
}
case 1: {
if (d[nh][nw][1] > d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost) {
d[nh][nw][1] = d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost;
q.push(pair<ll, pair<P, ll>>(d[nh][nw][1],
pair<P, ll>(P(nh, nw), 1)));
}
break;
}
case 2: {
if (d[nh][nw][0] > d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost) {
d[nh][nw][0] = d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost;
q.push(pair<ll, pair<P, ll>>(d[nh][nw][0],
pair<P, ll>(P(nh, nw), 0)));
}
break;
}
case 3: {
if (d[nh][nw][3] > d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost) {
d[nh][nw][3] = d[p.second.first.first][p.second.first.second]
[p.second.second] +
cost;
q.push(pair<ll, pair<P, ll>>(d[nh][nw][3],
pair<P, ll>(P(nh, nw), 3)));
}
break;
}
}
}
}
}
REP(i, 4) { ans = min(ans, (ll)d[h - 1][w - 1][i]); }
cout << ans << endl;
}
} | replace | 41 | 42 | 41 | 45 | TLE | |
p00737 | C++ | Time Limit Exceeded | #include <cstring>
#include <iostream>
#include <queue>
using namespace std;
#define INF 1e8
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
struct state {
int cost;
int x, y;
int dir;
state(int _x, int _y, int _dir, int _cost)
: x(_x), y(_y), dir(_dir), cost(_cost) {}
bool operator<(const state &r) const { return cost < r.cost; }
};
int main(void) {
int w, h;
while (cin >> w >> h, w) {
int mem[35][35][4];
int grid[35][35];
int c[4];
for (int i = 0; i <= h; i++)
for (int j = 0; j <= w; j++)
for (int k = 0; k < 4; k++)
mem[i][j][k] = INF;
for (int i = 0; i <= h + 1; i++)
for (int j = 0; j <= w + 1; j++)
grid[i][j] = INF;
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
cin >> grid[i][j];
for (int i = 0; i < 4; i++)
cin >> c[i];
int mincost = INF;
priority_queue<state> pq;
pq.push(state(1, 1, 1, 0));
while (!pq.empty()) {
state P = pq.top();
pq.pop();
// cout << P.x << ":" << P.y << "->" << P.cost <<
//endl;
if (P.y == h && P.x == w) {
mincost = min(mincost, P.cost);
continue;
}
if (grid[P.y][P.x] == INF)
continue;
if (grid[P.y][P.x] != 4) {
int nd = (P.dir + grid[P.y][P.x]) % 4;
int nx = P.x + dx[nd];
int ny = P.y + dy[nd];
if (mem[ny][nx][nd] > P.cost) {
mem[ny][nx][nd] = P.cost;
pq.push(state(nx, ny, nd, P.cost));
}
}
for (int i = 0; i < 4; i++) {
int nd = (P.dir + i) % 4;
int nx = P.x + dx[nd];
int ny = P.y + dy[nd];
if (mem[ny][nx][nd] > P.cost + c[i]) {
mem[ny][nx][nd] = P.cost + c[i];
pq.push(state(nx, ny, nd, P.cost + c[i]));
}
}
}
cout << mincost << endl;
}
return 0;
} | #include <cstring>
#include <iostream>
#include <queue>
using namespace std;
#define INF 1e8
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
struct state {
int cost;
int x, y;
int dir;
state(int _x, int _y, int _dir, int _cost)
: x(_x), y(_y), dir(_dir), cost(_cost) {}
bool operator<(const state &r) const { return cost > r.cost; }
};
int main(void) {
int w, h;
while (cin >> w >> h, w) {
int mem[35][35][4];
int grid[35][35];
int c[4];
for (int i = 0; i <= h; i++)
for (int j = 0; j <= w; j++)
for (int k = 0; k < 4; k++)
mem[i][j][k] = INF;
for (int i = 0; i <= h + 1; i++)
for (int j = 0; j <= w + 1; j++)
grid[i][j] = INF;
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
cin >> grid[i][j];
for (int i = 0; i < 4; i++)
cin >> c[i];
int mincost = INF;
priority_queue<state> pq;
pq.push(state(1, 1, 1, 0));
while (!pq.empty()) {
state P = pq.top();
pq.pop();
// cout << P.x << ":" << P.y << "->" << P.cost <<
//endl;
if (P.y == h && P.x == w) {
mincost = min(mincost, P.cost);
continue;
}
if (grid[P.y][P.x] == INF)
continue;
if (grid[P.y][P.x] != 4) {
int nd = (P.dir + grid[P.y][P.x]) % 4;
int nx = P.x + dx[nd];
int ny = P.y + dy[nd];
if (mem[ny][nx][nd] > P.cost) {
mem[ny][nx][nd] = P.cost;
pq.push(state(nx, ny, nd, P.cost));
}
}
for (int i = 0; i < 4; i++) {
int nd = (P.dir + i) % 4;
int nx = P.x + dx[nd];
int ny = P.y + dy[nd];
if (mem[ny][nx][nd] > P.cost + c[i]) {
mem[ny][nx][nd] = P.cost + c[i];
pq.push(state(nx, ny, nd, P.cost + c[i]));
}
}
}
cout << mincost << endl;
}
return 0;
} | replace | 13 | 14 | 13 | 14 | TLE | |
p00738 | C++ | Time Limit Exceeded | #define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
#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 PB push_back
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const int MOD = 1000000007;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; }
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
out << '(' << a.first << ',' << a.second << ')';
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &a) {
out << '[';
REP(i, a.size()) {
out << a[i];
if (i != a.size() - 1)
out << ',';
}
out << ']';
return out;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
const double EPS = 1e-8;
using R = long double;
using P = complex<R>;
using L = pair<P, P>;
using G = vector<P>;
struct C {
P c;
R r;
C() {}
C(const P &a, const R &b) : c(a), r(b) {}
};
struct S : public L {
S() {}
S(const P &a, const P &b) : L(a, b) {}
};
inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); }
inline R dot(const P &a, const P &b) {
return real(a) * real(b) + imag(a) * imag(b);
}
inline R det(const P &a, const P &b) {
return real(a) * imag(b) - imag(a) * real(b);
}
inline P vec(const L &l) { return l.second - l.first; }
namespace std {
bool operator<(const P &a, const P &b) {
return sgn(real(a - b)) ? real(a - b) < 0 : sgn(imag(a - b)) < 0;
}
bool operator==(const P &a, const P &b) {
return sgn(real(a - b)) == 0 && sgn(imag(a - b)) == 0;
}
bool cmp_y(const P &a, const P &b) {
return sgn(imag(a - b)) ? imag(a - b) < 0 : sgn(real(a - b)) < 0;
}
} // namespace std
// P,L,Sについて入力
inline istream &operator>>(istream &is, P &p) {
R x, y;
is >> x >> y;
p = P(x, y);
return is;
}
inline istream &operator>>(istream &is, L &l) {
P a, b;
is >> a >> b;
l = L(a, b);
return is;
}
inline istream &operator>>(istream &is, S &s) {
P a, b;
is >> a >> b;
s = S(a, b);
return is;
}
// 射影
P inline projection(const L &l, const P &p) {
R t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
return l.first + t * (l.first - l.second);
}
// 反射
P inline reflection(const L &l, const P &p) {
return p + (R)2 * (projection(l, p) - p);
}
// 線分abから見たcの位置
enum CCW { LEFT = 1, RIGHT = 2, BACK = 4, FRONT = 8, ON_SEG = 16 };
int ccw(P a, P b, P c) {
P p = (c - a) / (b - a);
if (sgn(imag(p)) > 0)
return LEFT;
if (sgn(imag(p)) < 0)
return RIGHT;
if (sgn(real(p)) < 0)
return BACK;
if (sgn(real(p) - 1) > 0)
return FRONT;
return ON_SEG;
}
// 垂直,平行
inline bool vertical(L a, L b) { return sgn(dot(vec(a), vec(b))) == 0; }
inline bool parallel(L a, L b) { return sgn(det(vec(a), vec(b))) == 0; }
inline bool eal(L a, L b) { return vertical(a, b) && parallel(a, b); }
// 交差判定
template <bool strict = false> inline bool intersect(const L &l1, const L &l2) {
if (strict)
return sgn(det(vec(l1), vec(l2))) != 0;
return sgn(det(vec(l1), vec(l2))) != 0 || l1 == l2;
}
template <bool strict = false> inline bool intersect(const L &l, const S &s) {
if (strict)
det(s.first, vec(l)) * det(s.second, vec(l)) < 0;
return det(s.first, vec(l)) * det(s.second, vec(l)) <= 0;
}
template <bool strict = false> inline bool intersect(const S &s1, const S &s2) {
int ccw1 =
ccw(s1.first, s1.second, s2.first) | ccw(s1.first, s1.second, s2.second);
int ccw2 =
ccw(s2.first, s2.second, s1.first) | ccw(s2.first, s2.second, s1.second);
if (strict)
return (ccw1 & ccw2) == (LEFT | RIGHT);
return (ccw1 & ccw2) == (LEFT | RIGHT) || ((ccw1 | ccw2) & ON_SEG);
}
template <bool strict = false> inline bool intersect(const S &s, const P &p) {
return ccw(s.first, s.second, p) == ON_SEG;
}
template <bool strict = false> inline bool intersect(const L &l, const P &p) {
return ccw(l.first, l.second, p) == ON_SEG ||
ccw(l.first, l.second, p) == FRONT ||
ccw(l.first, l.second, p) == BACK;
}
int intersect(const C &a, const C &b) {
R dist = sqrt(norm(a.c - b.c)), r1 = a.r + b.r, r2 = abs(a.r - b.r);
if (sgn(r1 - dist) < 0)
return 4; // 円が離れている
if (sgn(r1 - dist) == 0)
return 3; // 外接
if (sgn(r2 - dist) < 0 && sgn(dist - r1) < 0)
return 2; // 交差
if (sgn(dist - r2) == 0)
return 1; // 内接
return 0; // 内部に含む
}
// 距離
R dist(const S &s, const P &p) {
P q = projection(s, p);
if (sgn(dot(s.second - s.first, p - s.first)) <= 0)
q = s.first;
if (sgn(dot(s.first - s.second, p - s.second)) <= 0)
q = s.second;
return abs(p - q);
}
R dist(const S &a, const S &b) {
if (intersect(a, b))
return 0;
return min({dist(a, b.first), dist(a, b.second), dist(b, a.first),
dist(b, a.second)});
}
R dist(const L &l, const P &p) {
P q = projection(l, p);
return abs(p - q);
}
// 交点 交差判定を先にすること!!!
inline P crosspoint(const L &l1, const L &l2) {
R ratio = det(vec(l2), l2.first - l1.first) / det(vec(l2), vec(l1));
return l1.first + vec(l1) * ratio;
}
// ToDo:そもそも交差しないとき
vector<P> crosspoint(C c, L l) {
R d = dist(l, c.c), r = c.r;
P m = projection(l, c.c);
P x = sqrt(r * r - d * d) * vec(l) / abs(vec(l));
vector<P> ret(2, m);
ret[0] -= x;
ret[1] += x;
if (ret[1] < ret[0])
swap(ret[0], ret[1]);
return ret;
}
vector<P> crosspoint(C a, C b) {
R d = abs(a.c - b.c);
R t = (a.r * a.r - b.r * b.r + d * d) / 2 / d, h = sqrt(a.r * a.r - t * t);
P m = t / abs(b.c - a.c) * (b.c - a.c) + a.c;
auto n_vector = [&](P p) -> P { return P(-p.imag(), p.real()) / abs(p); };
P n = n_vector(a.c - b.c);
vector<P> ret(2, m);
ret[0] -= h * n;
ret[1] += h * n;
if (ret[1] < ret[0])
swap(ret[0], ret[1]);
return ret;
}
// 面積 頂点が反時計回りに並んでいること
R area(const G &pol) {
R ret = 0.0;
REP(i, pol.size()) ret += det(pol[i], pol[(i + 1) % pol.size()]);
return (ret / 2.0);
}
// 凸性の判定
bool isConvex(const G &pol) {
REP(i, pol.size()) {
if (sgn(det(pol[(i + 1) % pol.size()] - pol[i],
pol[(i + 2) % pol.size()] - pol[i])) < 0) {
return false;
}
}
return true;
}
// 多角形と点の内包
// 2→in 1→on 0→out
int inPolygon(const G &pol, const P &p) {
bool in = false;
for (int i = 0; i < pol.size(); ++i) {
P a = pol[i] - p, b = pol[(i + 1) % pol.size()] - p;
if (imag(a) > imag(b))
swap(a, b);
if (imag(a) <= 0 && 0 < imag(b) && sgn(det(a, b)) < 0) {
in = !in;
}
if (sgn(det(a, b)) == 0 && sgn(dot(a, b)) <= 0)
return 1;
}
return in ? 2 : 0;
}
// 凸包 3点が一直線上に並ぶときに注意
// 凸包のうち一番左にある頂点の中で一番下の頂点から時計回り
G convex_hull(G ps) {
int n = ps.size(), k = 0;
sort(ps.begin(), ps.end());
G r(2 * n);
for (int i = 0; i < n; i++) {
while (k > 1 && sgn(det(r[k - 1] - r[k - 2], ps[i] - r[k - 2])) < 0)
k--;
r[k++] = ps[i];
}
for (int i = n - 2, t = k; i >= 0; i--) {
while (k > t && sgn(det(r[k - 1] - r[k - 2], ps[i] - r[k - 2])) < 0)
k--;
r[k++] = ps[i];
}
r.resize(k - 1);
return r;
}
/*
3点が与えられたときに円を求める
返り値は{中心のx座標、y座標、半径}
3点が直線上に並んでいるときは{0, 0, -1}を返す
ToDo:見直す
*/
C calcCircle(R x1, R y1, R x2, R y2, R x3, R y3) {
R ox, oy, a, b, c, d;
R r1, r2, r3;
a = x2 - x1;
b = y2 - y1;
c = x3 - x1;
d = y3 - y1;
R cx, cy, r;
if ((a && d) || (b && c)) {
ox = x1 + (d * (a * a + b * b) - b * (c * c + d * d)) / (a * d - b * c) / 2;
if (b)
oy = (a * (x1 + x2 - ox - ox) + b * (y1 + y2)) / b / 2;
else
oy = (c * (x1 + x3 - ox - ox) + d * (y1 + y3)) / d / 2;
r1 = sqrt((ox - x1) * (ox - x1) + (oy - y1) * (oy - y1));
r2 = sqrt((ox - x2) * (ox - x2) + (oy - y2) * (oy - y2));
r3 = sqrt((ox - x3) * (ox - x3) + (oy - y3) * (oy - y3));
cx = ox;
cy = oy;
r = (r1 + r2 + r3) / 3;
return {P{cx, cy}, r};
}
return {P{0, 0}, -1};
}
// 2点p1, p2を通り、半径がrの円を2つ返す
vector<C> calcCircle(P p1, P p2, R r) {
// 存在しない
if (abs(p1 - p2) > 2 * r)
return {};
P p3 = {(p1.real() + p2.real()) / 2, (p1.imag() + p2.imag()) / 2};
R l = abs(p1 - p3);
P p1p2 = p2 - p1;
R a = p1p2.real(), b = p1p2.imag();
R dx1 = b * sqrt((r * r - l * l) / (a * a + b * b)),
dy1 = a * sqrt((r * r - l * l) / (a * a + b * b));
return {{{p3.real() + dx1, p3.imag() - dy1}, r},
{{p3.real() - dx1, p3.imag() + dy1}, r}};
}
P p1[55], p2[55];
R d[55], h[55];
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int n;
cin >> n;
if (!n)
break;
S s;
cin >> s;
REP(i, n) cin >> p1[i] >> p2[i] >> h[i];
REP(i, n) {
d[i] = INF;
S tmp = S(p1[i], P{p1[i].real(), p2[i].imag()});
chmin(d[i], dist(s, tmp));
tmp = S(P{p1[i].real(), p2[i].imag()}, p2[i]);
chmin(d[i], dist(s, tmp));
tmp = S(p2[i], P{p2[i].real(), p1[i].imag()});
chmin(d[i], dist(s, tmp));
tmp = S(P{p2[i].real(), p1[i].imag()}, p1[i]);
chmin(d[i], dist(s, tmp));
if (p1[i].real() <= s.first.real() && s.first.real() <= p2[i].real() &&
p1[i].imag() <= s.first.imag() && s.first.imag() <= p2[i].imag()) {
d[i] = 0;
}
if (p1[i].real() <= s.second.real() && s.second.real() <= p2[i].real() &&
p1[i].imag() <= s.second.imag() && s.second.imag() <= p2[i].imag()) {
d[i] = 0;
}
}
auto check = [&](R r) -> bool {
REP(i, n) {
if (r < h[i]) {
if (r > d[i])
return false;
} else {
R tmp = r * r - (r - h[i]) * (r - h[i]);
if (tmp > d[i] * d[i])
return false;
}
}
return true;
};
bool flag = false;
const R dr = 0.001 / 2;
for (R r = 1000; r >= 0; r -= dr) {
if (check(r)) {
cout << fixed << setprecision(9) << r << endl;
flag = true;
break;
}
}
if (!flag)
cout << 0 << endl;
}
return 0;
}
| #define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
#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 PB push_back
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const int MOD = 1000000007;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; }
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
out << '(' << a.first << ',' << a.second << ')';
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &a) {
out << '[';
REP(i, a.size()) {
out << a[i];
if (i != a.size() - 1)
out << ',';
}
out << ']';
return out;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
const double EPS = 1e-8;
using R = double;
using P = complex<R>;
using L = pair<P, P>;
using G = vector<P>;
struct C {
P c;
R r;
C() {}
C(const P &a, const R &b) : c(a), r(b) {}
};
struct S : public L {
S() {}
S(const P &a, const P &b) : L(a, b) {}
};
inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); }
inline R dot(const P &a, const P &b) {
return real(a) * real(b) + imag(a) * imag(b);
}
inline R det(const P &a, const P &b) {
return real(a) * imag(b) - imag(a) * real(b);
}
inline P vec(const L &l) { return l.second - l.first; }
namespace std {
bool operator<(const P &a, const P &b) {
return sgn(real(a - b)) ? real(a - b) < 0 : sgn(imag(a - b)) < 0;
}
bool operator==(const P &a, const P &b) {
return sgn(real(a - b)) == 0 && sgn(imag(a - b)) == 0;
}
bool cmp_y(const P &a, const P &b) {
return sgn(imag(a - b)) ? imag(a - b) < 0 : sgn(real(a - b)) < 0;
}
} // namespace std
// P,L,Sについて入力
inline istream &operator>>(istream &is, P &p) {
R x, y;
is >> x >> y;
p = P(x, y);
return is;
}
inline istream &operator>>(istream &is, L &l) {
P a, b;
is >> a >> b;
l = L(a, b);
return is;
}
inline istream &operator>>(istream &is, S &s) {
P a, b;
is >> a >> b;
s = S(a, b);
return is;
}
// 射影
P inline projection(const L &l, const P &p) {
R t = dot(p - l.first, l.first - l.second) / norm(l.first - l.second);
return l.first + t * (l.first - l.second);
}
// 反射
P inline reflection(const L &l, const P &p) {
return p + (R)2 * (projection(l, p) - p);
}
// 線分abから見たcの位置
enum CCW { LEFT = 1, RIGHT = 2, BACK = 4, FRONT = 8, ON_SEG = 16 };
int ccw(P a, P b, P c) {
P p = (c - a) / (b - a);
if (sgn(imag(p)) > 0)
return LEFT;
if (sgn(imag(p)) < 0)
return RIGHT;
if (sgn(real(p)) < 0)
return BACK;
if (sgn(real(p) - 1) > 0)
return FRONT;
return ON_SEG;
}
// 垂直,平行
inline bool vertical(L a, L b) { return sgn(dot(vec(a), vec(b))) == 0; }
inline bool parallel(L a, L b) { return sgn(det(vec(a), vec(b))) == 0; }
inline bool eal(L a, L b) { return vertical(a, b) && parallel(a, b); }
// 交差判定
template <bool strict = false> inline bool intersect(const L &l1, const L &l2) {
if (strict)
return sgn(det(vec(l1), vec(l2))) != 0;
return sgn(det(vec(l1), vec(l2))) != 0 || l1 == l2;
}
template <bool strict = false> inline bool intersect(const L &l, const S &s) {
if (strict)
det(s.first, vec(l)) * det(s.second, vec(l)) < 0;
return det(s.first, vec(l)) * det(s.second, vec(l)) <= 0;
}
template <bool strict = false> inline bool intersect(const S &s1, const S &s2) {
int ccw1 =
ccw(s1.first, s1.second, s2.first) | ccw(s1.first, s1.second, s2.second);
int ccw2 =
ccw(s2.first, s2.second, s1.first) | ccw(s2.first, s2.second, s1.second);
if (strict)
return (ccw1 & ccw2) == (LEFT | RIGHT);
return (ccw1 & ccw2) == (LEFT | RIGHT) || ((ccw1 | ccw2) & ON_SEG);
}
template <bool strict = false> inline bool intersect(const S &s, const P &p) {
return ccw(s.first, s.second, p) == ON_SEG;
}
template <bool strict = false> inline bool intersect(const L &l, const P &p) {
return ccw(l.first, l.second, p) == ON_SEG ||
ccw(l.first, l.second, p) == FRONT ||
ccw(l.first, l.second, p) == BACK;
}
int intersect(const C &a, const C &b) {
R dist = sqrt(norm(a.c - b.c)), r1 = a.r + b.r, r2 = abs(a.r - b.r);
if (sgn(r1 - dist) < 0)
return 4; // 円が離れている
if (sgn(r1 - dist) == 0)
return 3; // 外接
if (sgn(r2 - dist) < 0 && sgn(dist - r1) < 0)
return 2; // 交差
if (sgn(dist - r2) == 0)
return 1; // 内接
return 0; // 内部に含む
}
// 距離
R dist(const S &s, const P &p) {
P q = projection(s, p);
if (sgn(dot(s.second - s.first, p - s.first)) <= 0)
q = s.first;
if (sgn(dot(s.first - s.second, p - s.second)) <= 0)
q = s.second;
return abs(p - q);
}
R dist(const S &a, const S &b) {
if (intersect(a, b))
return 0;
return min({dist(a, b.first), dist(a, b.second), dist(b, a.first),
dist(b, a.second)});
}
R dist(const L &l, const P &p) {
P q = projection(l, p);
return abs(p - q);
}
// 交点 交差判定を先にすること!!!
inline P crosspoint(const L &l1, const L &l2) {
R ratio = det(vec(l2), l2.first - l1.first) / det(vec(l2), vec(l1));
return l1.first + vec(l1) * ratio;
}
// ToDo:そもそも交差しないとき
vector<P> crosspoint(C c, L l) {
R d = dist(l, c.c), r = c.r;
P m = projection(l, c.c);
P x = sqrt(r * r - d * d) * vec(l) / abs(vec(l));
vector<P> ret(2, m);
ret[0] -= x;
ret[1] += x;
if (ret[1] < ret[0])
swap(ret[0], ret[1]);
return ret;
}
vector<P> crosspoint(C a, C b) {
R d = abs(a.c - b.c);
R t = (a.r * a.r - b.r * b.r + d * d) / 2 / d, h = sqrt(a.r * a.r - t * t);
P m = t / abs(b.c - a.c) * (b.c - a.c) + a.c;
auto n_vector = [&](P p) -> P { return P(-p.imag(), p.real()) / abs(p); };
P n = n_vector(a.c - b.c);
vector<P> ret(2, m);
ret[0] -= h * n;
ret[1] += h * n;
if (ret[1] < ret[0])
swap(ret[0], ret[1]);
return ret;
}
// 面積 頂点が反時計回りに並んでいること
R area(const G &pol) {
R ret = 0.0;
REP(i, pol.size()) ret += det(pol[i], pol[(i + 1) % pol.size()]);
return (ret / 2.0);
}
// 凸性の判定
bool isConvex(const G &pol) {
REP(i, pol.size()) {
if (sgn(det(pol[(i + 1) % pol.size()] - pol[i],
pol[(i + 2) % pol.size()] - pol[i])) < 0) {
return false;
}
}
return true;
}
// 多角形と点の内包
// 2→in 1→on 0→out
int inPolygon(const G &pol, const P &p) {
bool in = false;
for (int i = 0; i < pol.size(); ++i) {
P a = pol[i] - p, b = pol[(i + 1) % pol.size()] - p;
if (imag(a) > imag(b))
swap(a, b);
if (imag(a) <= 0 && 0 < imag(b) && sgn(det(a, b)) < 0) {
in = !in;
}
if (sgn(det(a, b)) == 0 && sgn(dot(a, b)) <= 0)
return 1;
}
return in ? 2 : 0;
}
// 凸包 3点が一直線上に並ぶときに注意
// 凸包のうち一番左にある頂点の中で一番下の頂点から時計回り
G convex_hull(G ps) {
int n = ps.size(), k = 0;
sort(ps.begin(), ps.end());
G r(2 * n);
for (int i = 0; i < n; i++) {
while (k > 1 && sgn(det(r[k - 1] - r[k - 2], ps[i] - r[k - 2])) < 0)
k--;
r[k++] = ps[i];
}
for (int i = n - 2, t = k; i >= 0; i--) {
while (k > t && sgn(det(r[k - 1] - r[k - 2], ps[i] - r[k - 2])) < 0)
k--;
r[k++] = ps[i];
}
r.resize(k - 1);
return r;
}
/*
3点が与えられたときに円を求める
返り値は{中心のx座標、y座標、半径}
3点が直線上に並んでいるときは{0, 0, -1}を返す
ToDo:見直す
*/
C calcCircle(R x1, R y1, R x2, R y2, R x3, R y3) {
R ox, oy, a, b, c, d;
R r1, r2, r3;
a = x2 - x1;
b = y2 - y1;
c = x3 - x1;
d = y3 - y1;
R cx, cy, r;
if ((a && d) || (b && c)) {
ox = x1 + (d * (a * a + b * b) - b * (c * c + d * d)) / (a * d - b * c) / 2;
if (b)
oy = (a * (x1 + x2 - ox - ox) + b * (y1 + y2)) / b / 2;
else
oy = (c * (x1 + x3 - ox - ox) + d * (y1 + y3)) / d / 2;
r1 = sqrt((ox - x1) * (ox - x1) + (oy - y1) * (oy - y1));
r2 = sqrt((ox - x2) * (ox - x2) + (oy - y2) * (oy - y2));
r3 = sqrt((ox - x3) * (ox - x3) + (oy - y3) * (oy - y3));
cx = ox;
cy = oy;
r = (r1 + r2 + r3) / 3;
return {P{cx, cy}, r};
}
return {P{0, 0}, -1};
}
// 2点p1, p2を通り、半径がrの円を2つ返す
vector<C> calcCircle(P p1, P p2, R r) {
// 存在しない
if (abs(p1 - p2) > 2 * r)
return {};
P p3 = {(p1.real() + p2.real()) / 2, (p1.imag() + p2.imag()) / 2};
R l = abs(p1 - p3);
P p1p2 = p2 - p1;
R a = p1p2.real(), b = p1p2.imag();
R dx1 = b * sqrt((r * r - l * l) / (a * a + b * b)),
dy1 = a * sqrt((r * r - l * l) / (a * a + b * b));
return {{{p3.real() + dx1, p3.imag() - dy1}, r},
{{p3.real() - dx1, p3.imag() + dy1}, r}};
}
P p1[55], p2[55];
R d[55], h[55];
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int n;
cin >> n;
if (!n)
break;
S s;
cin >> s;
REP(i, n) cin >> p1[i] >> p2[i] >> h[i];
REP(i, n) {
d[i] = INF;
S tmp = S(p1[i], P{p1[i].real(), p2[i].imag()});
chmin(d[i], dist(s, tmp));
tmp = S(P{p1[i].real(), p2[i].imag()}, p2[i]);
chmin(d[i], dist(s, tmp));
tmp = S(p2[i], P{p2[i].real(), p1[i].imag()});
chmin(d[i], dist(s, tmp));
tmp = S(P{p2[i].real(), p1[i].imag()}, p1[i]);
chmin(d[i], dist(s, tmp));
if (p1[i].real() <= s.first.real() && s.first.real() <= p2[i].real() &&
p1[i].imag() <= s.first.imag() && s.first.imag() <= p2[i].imag()) {
d[i] = 0;
}
if (p1[i].real() <= s.second.real() && s.second.real() <= p2[i].real() &&
p1[i].imag() <= s.second.imag() && s.second.imag() <= p2[i].imag()) {
d[i] = 0;
}
}
auto check = [&](R r) -> bool {
REP(i, n) {
if (r < h[i]) {
if (r > d[i])
return false;
} else {
R tmp = r * r - (r - h[i]) * (r - h[i]);
if (tmp > d[i] * d[i])
return false;
}
}
return true;
};
bool flag = false;
const R dr = 0.001 / 2;
for (R r = 1000; r >= 0; r -= dr) {
if (check(r)) {
cout << fixed << setprecision(9) << r << endl;
flag = true;
break;
}
}
if (!flag)
cout << 0 << endl;
}
return 0;
}
| replace | 43 | 44 | 43 | 44 | TLE | |
p00738 | C++ | Time Limit Exceeded | #include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef double Num;
typedef complex<Num> Pt2;
typedef vector<Pt2> Polygon2;
struct Line2 : public vector<Pt2> {
Line2(Pt2 a, Pt2 b) {
push_back(a);
push_back(b);
}
};
const double eps = 1e-10;
Num dot(Pt2 a, Pt2 b) { return (a * conj(b)).real(); }
Num cross(Pt2 a, Pt2 b) { return (conj(a) * b).imag(); }
Pt2 vec(Line2 l) { return l[1] - l[0]; }
int ccw(Pt2 a, Pt2 b, Pt2 c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // ccw
if (cross(b, c) < 0)
return -1; // cw
if (dot(b, c) < 0)
return +2; // cab
if (norm(b) < norm(c))
return -2; // abc
return 0; // acb
}
int ccw(Line2 s, Pt2 p) { return ccw(s[0], s[1], p); }
bool intersectSP(Line2 s, Pt2 p) {
return abs(s[0] - p) + abs(s[1] - p) < abs(s[1] - s[0]) + eps;
}
bool intersectSS(Line2 s, Line2 t) {
return ccw(s, t[0]) * ccw(s, t[1]) <= 0 && ccw(t, s[0]) * ccw(t, s[1]) <= 0;
}
Pt2 projection(Line2 l, Pt2 p) {
double t = dot(p - l[0], vec(l)) / norm(vec(l));
return l[0] + t * (vec(l));
}
Pt2 reflection(Line2 l, Pt2 p) { return p + 2.0 * (projection(l, p) - p); }
Num distanceSP(Line2 s, Pt2 p) {
Pt2 r = projection(s, p);
if (intersectSP(s, r))
return abs(r - p);
return min(abs(s[0] - p), abs(s[1] - p));
}
Num distanceSS(Line2 s, Line2 t) {
if (intersectSS(s, t))
return 0;
return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
bool convex_contains(Polygon2 g, Pt2 p) {
for (int i = 0; i < g.size(); i++) {
if (ccw(Line2(g[i], g[(i + 1) % g.size()]), p) == -1)
return false;
}
return true;
}
double dist(Line2 s, Line2 t, double h) {
double d = distanceSS(s, t);
if (d <= h)
return d;
return (d * d + h * h) / (2 * h);
}
int main() {
int N;
while (cin >> N, N) {
Num x1, y1, x2, y2, h;
cin >> x1 >> y1 >> x2 >> y2;
Line2 course(Pt2(x1, y1), Pt2(x2, y2));
double ans = 1e10;
while (N--) {
cin >> x1 >> y1 >> x2 >> y2 >> h;
Polygon2 g(4);
g[0] = Pt2(x1, y2);
g[3] = Pt2(x2, y2);
g[1] = Pt2(x1, y1);
g[2] = Pt2(x2, y1);
if (convex_contains(g, course[0]) || convex_contains(g, course[1])) {
ans = 0;
}
for (int i = 0; i < g.size(); i++) {
ans = min(ans, dist(course, Line2(g[i], g[(i + 1) % g.size()]), h));
}
if (ans == 0)
break;
}
cout.setf(ios::fixed);
cout.precision(5);
cout << ans << endl;
}
} | #include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;
typedef double Num;
typedef complex<Num> Pt2;
typedef vector<Pt2> Polygon2;
struct Line2 : public vector<Pt2> {
Line2(Pt2 a, Pt2 b) {
push_back(a);
push_back(b);
}
};
const double eps = 1e-10;
Num dot(Pt2 a, Pt2 b) { return (a * conj(b)).real(); }
Num cross(Pt2 a, Pt2 b) { return (conj(a) * b).imag(); }
Pt2 vec(Line2 l) { return l[1] - l[0]; }
int ccw(Pt2 a, Pt2 b, Pt2 c) {
b -= a;
c -= a;
if (cross(b, c) > 0)
return +1; // ccw
if (cross(b, c) < 0)
return -1; // cw
if (dot(b, c) < 0)
return +2; // cab
if (norm(b) < norm(c))
return -2; // abc
return 0; // acb
}
int ccw(Line2 s, Pt2 p) { return ccw(s[0], s[1], p); }
bool intersectSP(Line2 s, Pt2 p) {
return abs(s[0] - p) + abs(s[1] - p) < abs(s[1] - s[0]) + eps;
}
bool intersectSS(Line2 s, Line2 t) {
return ccw(s, t[0]) * ccw(s, t[1]) <= 0 && ccw(t, s[0]) * ccw(t, s[1]) <= 0;
}
Pt2 projection(Line2 l, Pt2 p) {
double t = dot(p - l[0], vec(l)) / norm(vec(l));
return l[0] + t * (vec(l));
}
Pt2 reflection(Line2 l, Pt2 p) { return p + 2.0 * (projection(l, p) - p); }
Num distanceSP(Line2 s, Pt2 p) {
Pt2 r = projection(s, p);
if (intersectSP(s, r))
return abs(r - p);
return min(abs(s[0] - p), abs(s[1] - p));
}
Num distanceSS(Line2 s, Line2 t) {
if (intersectSS(s, t))
return 0;
return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}
bool convex_contains(Polygon2 g, Pt2 p) {
for (int i = 0; i < g.size(); i++) {
if (ccw(Line2(g[i], g[(i + 1) % g.size()]), p) == -1)
return false;
}
return true;
}
double dist(Line2 s, Line2 t, double h) {
double d = distanceSS(s, t);
if (d <= h)
return d;
return (d * d + h * h) / (2 * h);
}
int main() {
int N;
while (cin >> N, N) {
Num x1, y1, x2, y2, h;
cin >> x1 >> y1 >> x2 >> y2;
Line2 course(Pt2(x1, y1), Pt2(x2, y2));
double ans = 1e10;
while (N--) {
cin >> x1 >> y1 >> x2 >> y2 >> h;
Polygon2 g(4);
g[0] = Pt2(x1, y2);
g[3] = Pt2(x2, y2);
g[1] = Pt2(x1, y1);
g[2] = Pt2(x2, y1);
if (convex_contains(g, course[0]) || convex_contains(g, course[1])) {
ans = 0;
}
for (int i = 0; i < g.size(); i++) {
ans = min(ans, dist(course, Line2(g[i], g[(i + 1) % g.size()]), h));
}
}
cout.setf(ios::fixed);
cout.precision(5);
cout << ans << endl;
}
} | delete | 105 | 108 | 105 | 105 | TLE | |
p00738 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double R;
typedef complex<R> P;
const R EPS = 1e-10;
const R PI = acos((R)(-1));
/*
-1 -> neg
0 -> near 0
1 -> pos
*/
int sgn(R a) {
if (a < -EPS)
return -1;
if (a > EPS)
return 1;
return 0;
}
int sgn(R a, R b) { return sgn(b - a); }
bool near(P a, P b) { return !sgn(abs(a - b)); }
bool lessP(const P &l, const P &r) {
if (sgn(l.real(), r.real()))
return l.real() < r.real();
if (sgn(l.imag(), r.imag()))
return l.imag() < r.imag();
return false;
}
R cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }
R dot(P a, P b) { return a.real() * b.real() + a.imag() * b.imag(); }
R ssqrt(R d) {
d = max<R>(0, d);
return sqrt(d);
}
R sacos(R d) {
d = max<R>(-1, d);
d = min<R>(1, d);
return acos(d);
}
R deg2rad(R x) { return x / 180 * PI; }
R rad2deg(R x) { return x / PI * 180; }
//?§???????[0, 2*PI)???
R radNorP(R x) { return fmod(fmod(x, 2 * PI) + 2 * PI, 2 * PI); }
//?§???????[-PI, PI)???
R radNorN(R x) {
x = radNorP(x);
if (x >= PI)
x -= 2 * PI;
return x;
}
/**
* radian??§???x???[l, r]?????\??£????????????????????\??????
* 0:OFF
* 1:IN
* 2:ON
*/
bool inR(R l, R r, R x) {
l = radNorP(l);
r = radNorP(r);
x = radNorP(x);
if (!sgn(l, x) || !sgn(r, x))
return 2;
if (!sgn(l, r))
return 0;
if (sgn(l, r) == 1) {
if (sgn(l, x) == 1 && sgn(x, r) == 1)
return 1;
} else {
if (sgn(x, r) == 1 || sgn(l, x) == 1)
return 1;
}
return 0;
}
/* 1->cclock
-1->clock
0->on
2->back
-2->front
*/
int ccw(P a, P b, P c) {
assert(!near(a, b));
if (near(a, c) || near(b, c))
return 0;
int s = sgn(cross(b - a, c - a));
if (s)
return s;
if (dot(b - a, c - a) < 0)
return 2;
if (dot(a - b, c - b) < 0)
return -2;
return 0;
}
struct L {
P x, y;
L(){};
L(P x, P y) : x(x), y(y){};
};
P vec(const L &l) { return l.y - l.x; }
R abs(const L &l) { return abs(vec(l)); }
typedef vector<P> Pol;
struct C {
P p;
R r;
C() {}
C(P p, R r) : p(p), r(r) {}
};
P cu(Pol p, int i) {
int s = p.size();
return p[(i % s + s) % s];
};
// 0:P is out 1:P is on line 2:P is in
int contains(const Pol &pol, P p) {
int in = -1;
for (int i = 0; i < (int)pol.size(); i++) {
P a = cu(pol, i) - p, b = cu(pol, i + 1) - p;
if (ccw(a, b, P(0, 0)) == 0)
return 1;
if (imag(a) > imag(b))
swap(a, b);
if (imag(a) <= 0 && 0 < imag(b)) {
if (cross(a, b) < 0)
in *= -1;
}
}
return in + 1;
}
R distLP(const L &l, const P &p) {
return abs(cross(vec(l), p - l.x) / abs(vec(l)));
}
//????????¨??????????°??????¢
R distSP(const L &s, const P &p) {
P s2 = vec(s) * P(0, 1);
if (ccw(s.x, s.x + s2, p) == 1)
return abs(s.x - p);
if (ccw(s.y, s.y + s2, p) == -1)
return abs(s.y - p);
return min(min(abs(s.x - p), abs(s.y - p)), distLP(s, p));
}
bool insSS(const L &s, const L &t) {
int a = ccw(s.x, s.y, t.x), b = ccw(s.x, s.y, t.y);
int c = ccw(t.x, t.y, s.x), d = ccw(t.x, t.y, s.y);
if (a * b <= 0 && c * d <= 0)
return true;
return false;
}
const int MN = 55;
int n;
L l;
Pol po[MN];
R he[MN];
bool solve(R md) {
vector<C> c;
vector<Pol> p;
for (int i = 0; i < n; i++) {
R di = 0;
if (md < he[i]) {
di = md;
} else {
di = ssqrt(md * md - (md - he[i]) * (md - he[i]));
}
for (int j = 0; j < 4; j++) {
c.push_back(C(po[i][j], di));
}
R x1 = po[i][0].real();
R y1 = po[i][0].imag();
R x2 = po[i][2].real();
R y2 = po[i][2].imag();
p.push_back(
{P(x1 - di, y1), P(x2 + di, y1), P(x2 + di, y2), P(x1 - di, y2)});
p.push_back(
{P(x1, y1 - di), P(x2, y1 - di), P(x2, y2 + di), P(x1, y2 + di)});
}
for (C x : c) {
if (distSP(l, x.p) < x.r)
return false;
}
for (Pol x : p) {
if (contains(x, l.x))
return false;
if (contains(x, l.y))
return false;
for (int i = 0; i < 4; i++) {
if (insSS(l, L(cu(x, i), cu(x, i + 1))))
return false;
}
}
return true;
}
int main() {
while (true) {
cin >> n;
if (!n)
break;
for (int i = 0; i < MN; i++) {
po[i].clear();
}
R sx, sy, ex, ey;
cin >> sx >> sy >> ex >> ey;
l = L(P(sx, sy), P(ex, ey));
for (int i = 0; i < n; i++) {
R x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2 >> he[i];
po[i].push_back(P(x1, y1));
po[i].push_back(P(x2, y1));
po[i].push_back(P(x2, y2));
po[i].push_back(P(x1, y2));
}
R l = 0, r = 1000;
for (int i = 0; i < 200; i++) {
R md = (l + r) / 2;
if (solve(md)) {
l = md;
} else {
r = md;
}
}
printf("%.20Lf\n", l);
}
return 0;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double R;
typedef complex<R> P;
const R EPS = 1e-10;
const R PI = acos((R)(-1));
/*
-1 -> neg
0 -> near 0
1 -> pos
*/
int sgn(R a) {
if (a < -EPS)
return -1;
if (a > EPS)
return 1;
return 0;
}
int sgn(R a, R b) { return sgn(b - a); }
bool near(P a, P b) { return !sgn(abs(a - b)); }
bool lessP(const P &l, const P &r) {
if (sgn(l.real(), r.real()))
return l.real() < r.real();
if (sgn(l.imag(), r.imag()))
return l.imag() < r.imag();
return false;
}
R cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); }
R dot(P a, P b) { return a.real() * b.real() + a.imag() * b.imag(); }
R ssqrt(R d) {
d = max<R>(0, d);
return sqrt(d);
}
R sacos(R d) {
d = max<R>(-1, d);
d = min<R>(1, d);
return acos(d);
}
R deg2rad(R x) { return x / 180 * PI; }
R rad2deg(R x) { return x / PI * 180; }
//?§???????[0, 2*PI)???
R radNorP(R x) { return fmod(fmod(x, 2 * PI) + 2 * PI, 2 * PI); }
//?§???????[-PI, PI)???
R radNorN(R x) {
x = radNorP(x);
if (x >= PI)
x -= 2 * PI;
return x;
}
/**
* radian??§???x???[l, r]?????\??£????????????????????\??????
* 0:OFF
* 1:IN
* 2:ON
*/
bool inR(R l, R r, R x) {
l = radNorP(l);
r = radNorP(r);
x = radNorP(x);
if (!sgn(l, x) || !sgn(r, x))
return 2;
if (!sgn(l, r))
return 0;
if (sgn(l, r) == 1) {
if (sgn(l, x) == 1 && sgn(x, r) == 1)
return 1;
} else {
if (sgn(x, r) == 1 || sgn(l, x) == 1)
return 1;
}
return 0;
}
/* 1->cclock
-1->clock
0->on
2->back
-2->front
*/
int ccw(P a, P b, P c) {
assert(!near(a, b));
if (near(a, c) || near(b, c))
return 0;
int s = sgn(cross(b - a, c - a));
if (s)
return s;
if (dot(b - a, c - a) < 0)
return 2;
if (dot(a - b, c - b) < 0)
return -2;
return 0;
}
struct L {
P x, y;
L(){};
L(P x, P y) : x(x), y(y){};
};
P vec(const L &l) { return l.y - l.x; }
R abs(const L &l) { return abs(vec(l)); }
typedef vector<P> Pol;
struct C {
P p;
R r;
C() {}
C(P p, R r) : p(p), r(r) {}
};
P cu(Pol p, int i) {
int s = p.size();
return p[(i % s + s) % s];
};
// 0:P is out 1:P is on line 2:P is in
int contains(const Pol &pol, P p) {
int in = -1;
for (int i = 0; i < (int)pol.size(); i++) {
P a = cu(pol, i) - p, b = cu(pol, i + 1) - p;
if (ccw(a, b, P(0, 0)) == 0)
return 1;
if (imag(a) > imag(b))
swap(a, b);
if (imag(a) <= 0 && 0 < imag(b)) {
if (cross(a, b) < 0)
in *= -1;
}
}
return in + 1;
}
R distLP(const L &l, const P &p) {
return abs(cross(vec(l), p - l.x) / abs(vec(l)));
}
//????????¨??????????°??????¢
R distSP(const L &s, const P &p) {
P s2 = vec(s) * P(0, 1);
if (ccw(s.x, s.x + s2, p) == 1)
return abs(s.x - p);
if (ccw(s.y, s.y + s2, p) == -1)
return abs(s.y - p);
return min(min(abs(s.x - p), abs(s.y - p)), distLP(s, p));
}
bool insSS(const L &s, const L &t) {
int a = ccw(s.x, s.y, t.x), b = ccw(s.x, s.y, t.y);
int c = ccw(t.x, t.y, s.x), d = ccw(t.x, t.y, s.y);
if (a * b <= 0 && c * d <= 0)
return true;
return false;
}
const int MN = 55;
int n;
L l;
Pol po[MN];
R he[MN];
bool solve(R md) {
vector<C> c;
vector<Pol> p;
for (int i = 0; i < n; i++) {
R di = 0;
if (md < he[i]) {
di = md;
} else {
di = ssqrt(md * md - (md - he[i]) * (md - he[i]));
}
for (int j = 0; j < 4; j++) {
c.push_back(C(po[i][j], di));
}
R x1 = po[i][0].real();
R y1 = po[i][0].imag();
R x2 = po[i][2].real();
R y2 = po[i][2].imag();
p.push_back(
{P(x1 - di, y1), P(x2 + di, y1), P(x2 + di, y2), P(x1 - di, y2)});
p.push_back(
{P(x1, y1 - di), P(x2, y1 - di), P(x2, y2 + di), P(x1, y2 + di)});
}
for (C x : c) {
if (distSP(l, x.p) < x.r)
return false;
}
for (Pol x : p) {
if (contains(x, l.x))
return false;
if (contains(x, l.y))
return false;
for (int i = 0; i < 4; i++) {
if (insSS(l, L(cu(x, i), cu(x, i + 1))))
return false;
}
}
return true;
}
int main() {
while (true) {
cin >> n;
if (!n)
break;
for (int i = 0; i < MN; i++) {
po[i].clear();
}
R sx, sy, ex, ey;
cin >> sx >> sy >> ex >> ey;
l = L(P(sx, sy), P(ex, ey));
for (int i = 0; i < n; i++) {
R x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2 >> he[i];
po[i].push_back(P(x1, y1));
po[i].push_back(P(x2, y1));
po[i].push_back(P(x2, y2));
po[i].push_back(P(x1, y2));
}
R l = 0, r = 1000;
for (int i = 0; i < 50; i++) {
R md = (l + r) / 2;
if (solve(md)) {
l = md;
} else {
r = md;
}
}
printf("%.20Lf\n", l);
}
return 0;
} | replace | 246 | 247 | 246 | 247 | TLE | |
p00739 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#pragma comment(linker, "/STACK:400000000")
#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it, X) for (it = X.begin(); it != X.end(); it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>
int w, h, r[13][13], state[13][13], id[13][13], b;
int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};
int dy2[] = {1, 0, -1, 0}, dx2[] = {0, 1, 0, -1};
int sy1, sx1, sy2, sx2, rot, inv;
int co1[37], co2[37];
vi y, x;
bool err = 1;
pi rot_inv(int Dy, int Dx) {
if (inv == 1)
Dx = -Dx;
if (rot == 0)
return pi(Dy, Dx);
if (rot == 1)
return pi(Dx, -Dy);
if (rot == 2)
return pi(-Dy, -Dx);
if (rot == 3)
return pi(-Dx, Dy);
}
int visit[13][13];
int dfs(int y, int x, int target) {
visit[y][x] = 1;
int res = 1;
rep(i, 4) {
int ny = y + dy[i], nx = x + dx[i];
if (state[ny][nx] == target && !visit[ny][nx]) {
res += dfs(ny, nx, target);
}
}
return res;
}
void show() {
cout << sy1 << " " << sx1 << " " << sy2 << " " << sx2 << " " << rot << " "
<< inv << endl;
rep(i, h + 2) {
rep(j, w + 2) cout << state[i][j] << " ";
cout << endl;
}
cout << endl;
}
int f(int num) {
if (num == b) {
int sy1, sx1;
rep(i, b) {
if (state[y[i]][x[i]] == 1) {
sy1 = y[i], sx1 = x[i];
break;
}
}
memset(visit, 0, sizeof(visit));
int res1 = dfs(sy1, sx1, 1);
// if(res1==b/2)show();
return res1 == b / 2;
}
rep(i, b) if (state[y[i]][x[i]] == 0) {
if (co1[i] != -1 && state[y[co1[i]]][x[co1[i]]] == 0) {
state[y[i]][x[i]] = 1;
state[y[co1[i]]][x[co1[i]]] = 2;
if (f(num + 2))
return 1;
state[y[i]][x[i]] = 0;
state[y[co1[i]]][x[co1[i]]] = 0;
}
if (co2[i] != -1 && state[y[co2[i]]][x[co2[i]]] == 0) {
state[y[i]][x[i]] = 2;
state[y[co2[i]]][x[co2[i]]] = 1;
if (f(num + 2))
return 1;
state[y[i]][x[i]] = 0;
state[y[co2[i]]][x[co2[i]]] = 0;
}
return 0;
}
}
int main() {
int tc = 0;
time_t start = clock(), pre = start;
while (cin >> w >> h && w) {
memset(r, 0, sizeof(r));
memset(id, -1, sizeof(id));
y.clear();
x.clear();
b = 0;
rep2(i, 1, h + 1) rep2(j, 1, w + 1) {
cin >> r[i][j];
if (r[i][j]) {
y.pb(i);
x.pb(j);
id[i][j] = b++;
}
}
if (b % 2) {
cout << "NO\n";
goto end;
}
memset(state, 0, sizeof(state));
rep(i, b) rep2(j, i + 1, b) rep(k, 4) rep(l, 2) {
sy1 = y[i];
sx1 = x[i];
sy2 = y[j];
sx2 = x[j];
rot = k;
inv = l;
fill(co1, co1 + b, -1);
fill(co2, co2 + b, -1);
rep(m, b) if (m != i && m != j) {
pi diff = rot_inv(y[m] - sy1, x[m] - sx1);
int ny = sy2 + diff.fir, nx = sx2 + diff.sec;
if (ny >= 1 && ny <= h && nx >= 1 && nx <= w && id[ny][nx] != -1 &&
id[ny][nx] != i && id[ny][nx] != j && (ny != y[m] || nx != x[m])) {
co1[m] = id[ny][nx];
co2[id[ny][nx]] = m;
}
}
state[y[i]][x[i]] = 1;
state[y[j]][x[j]] = 2;
int used[37] = {};
used[i] = used[j] = 1;
int num = 2;
while (1) {
int flag = 0;
rep(m, b) if (state[y[m]][x[m]] == 0) {
bool ok1 = co1[m] != -1 && !used[co1[m]];
bool ok2 = co2[m] != -1 && !used[co2[m]];
if (!ok1 && !ok2)
goto skip;
if (!ok2) {
state[y[m]][x[m]] = 1;
state[y[co1[m]]][x[co1[m]]] = 2;
used[m] = used[co1[m]] = 1;
num += 2;
flag = 1;
} else if (!ok1) {
state[y[m]][x[m]] = 2;
state[y[co2[m]]][x[co2[m]]] = 1;
used[m] = used[co2[m]] = 1;
num += 2;
flag = 1;
}
}
if (!flag)
break;
}
if (f(num)) {
cout << "YES\n";
goto end;
}
skip:;
rep(m, b) state[y[m]][x[m]] = 0;
}
cout << "NO\n";
end:;
time_t now = clock();
if (err)
cerr << "#" << ++tc << ": " << (double)(now - pre) / CLOCKS_PER_SEC
<< endl;
pre = now;
}
time_t now = clock();
if (err)
cerr << "Total: " << (double)(now - start) / CLOCKS_PER_SEC << endl;
if (err)
cerr << " Ave: " << (double)(now - start) / CLOCKS_PER_SEC / tc << endl;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#pragma comment(linker, "/STACK:400000000")
#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it, X) for (it = X.begin(); it != X.end(); it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define pi pair<int, int>
#define pb push_back
#define sec second
#define sh(i) (1LL << i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>
int w, h, r[13][13], state[13][13], id[13][13], b;
int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};
int dy2[] = {1, 0, -1, 0}, dx2[] = {0, 1, 0, -1};
int sy1, sx1, sy2, sx2, rot, inv;
int co1[37], co2[37];
vi y, x;
bool err = 0;
pi rot_inv(int Dy, int Dx) {
if (inv == 1)
Dx = -Dx;
if (rot == 0)
return pi(Dy, Dx);
if (rot == 1)
return pi(Dx, -Dy);
if (rot == 2)
return pi(-Dy, -Dx);
if (rot == 3)
return pi(-Dx, Dy);
}
int visit[13][13];
int dfs(int y, int x, int target) {
visit[y][x] = 1;
int res = 1;
rep(i, 4) {
int ny = y + dy[i], nx = x + dx[i];
if (state[ny][nx] == target && !visit[ny][nx]) {
res += dfs(ny, nx, target);
}
}
return res;
}
void show() {
cout << sy1 << " " << sx1 << " " << sy2 << " " << sx2 << " " << rot << " "
<< inv << endl;
rep(i, h + 2) {
rep(j, w + 2) cout << state[i][j] << " ";
cout << endl;
}
cout << endl;
}
int f(int num) {
if (num == b) {
int sy1, sx1;
rep(i, b) {
if (state[y[i]][x[i]] == 1) {
sy1 = y[i], sx1 = x[i];
break;
}
}
memset(visit, 0, sizeof(visit));
int res1 = dfs(sy1, sx1, 1);
// if(res1==b/2)show();
return res1 == b / 2;
}
rep(i, b) if (state[y[i]][x[i]] == 0) {
if (co1[i] != -1 && state[y[co1[i]]][x[co1[i]]] == 0) {
state[y[i]][x[i]] = 1;
state[y[co1[i]]][x[co1[i]]] = 2;
if (f(num + 2))
return 1;
state[y[i]][x[i]] = 0;
state[y[co1[i]]][x[co1[i]]] = 0;
}
if (co2[i] != -1 && state[y[co2[i]]][x[co2[i]]] == 0) {
state[y[i]][x[i]] = 2;
state[y[co2[i]]][x[co2[i]]] = 1;
if (f(num + 2))
return 1;
state[y[i]][x[i]] = 0;
state[y[co2[i]]][x[co2[i]]] = 0;
}
return 0;
}
}
int main() {
int tc = 0;
time_t start = clock(), pre = start;
while (cin >> w >> h && w) {
memset(r, 0, sizeof(r));
memset(id, -1, sizeof(id));
y.clear();
x.clear();
b = 0;
rep2(i, 1, h + 1) rep2(j, 1, w + 1) {
cin >> r[i][j];
if (r[i][j]) {
y.pb(i);
x.pb(j);
id[i][j] = b++;
}
}
if (b % 2) {
cout << "NO\n";
goto end;
}
memset(state, 0, sizeof(state));
rep(i, b) rep2(j, i + 1, b) rep(k, 4) rep(l, 2) {
sy1 = y[i];
sx1 = x[i];
sy2 = y[j];
sx2 = x[j];
rot = k;
inv = l;
fill(co1, co1 + b, -1);
fill(co2, co2 + b, -1);
rep(m, b) if (m != i && m != j) {
pi diff = rot_inv(y[m] - sy1, x[m] - sx1);
int ny = sy2 + diff.fir, nx = sx2 + diff.sec;
if (ny >= 1 && ny <= h && nx >= 1 && nx <= w && id[ny][nx] != -1 &&
id[ny][nx] != i && id[ny][nx] != j && (ny != y[m] || nx != x[m])) {
co1[m] = id[ny][nx];
co2[id[ny][nx]] = m;
}
}
state[y[i]][x[i]] = 1;
state[y[j]][x[j]] = 2;
int used[37] = {};
used[i] = used[j] = 1;
int num = 2;
while (1) {
int flag = 0;
rep(m, b) if (state[y[m]][x[m]] == 0) {
bool ok1 = co1[m] != -1 && !used[co1[m]];
bool ok2 = co2[m] != -1 && !used[co2[m]];
if (!ok1 && !ok2)
goto skip;
if (!ok2) {
state[y[m]][x[m]] = 1;
state[y[co1[m]]][x[co1[m]]] = 2;
used[m] = used[co1[m]] = 1;
num += 2;
flag = 1;
} else if (!ok1) {
state[y[m]][x[m]] = 2;
state[y[co2[m]]][x[co2[m]]] = 1;
used[m] = used[co2[m]] = 1;
num += 2;
flag = 1;
}
}
if (!flag)
break;
}
if (f(num)) {
cout << "YES\n";
goto end;
}
skip:;
rep(m, b) state[y[m]][x[m]] = 0;
}
cout << "NO\n";
end:;
time_t now = clock();
if (err)
cerr << "#" << ++tc << ": " << (double)(now - pre) / CLOCKS_PER_SEC
<< endl;
pre = now;
}
time_t now = clock();
if (err)
cerr << "Total: " << (double)(now - start) / CLOCKS_PER_SEC << endl;
if (err)
cerr << " Ave: " << (double)(now - start) / CLOCKS_PER_SEC / tc << endl;
} | replace | 55 | 56 | 55 | 56 | 0 | #1: 8.1e-05
#2: 0.000219
#3: 0.000314
#4: 0.000207
#5: 0.000679
#6: 0.009577
#7: 0.015904
#8: 0.000747
Total: 0.02779
Ave: 0.00347375
|
p00740 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
while (true) {
int n, pmax;
int stone[50] = {};
cin >> n >> pmax;
int i;
int p = pmax;
for (i = 0; 1; i++) {
if (p) {
p--;
stone[i % n]++;
if (!p && stone[i % n] == pmax) {
break;
}
} else {
p += stone[i % n];
stone[i % n] = 0;
}
}
cout << i % n << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
while (true) {
int n, pmax;
int stone[50] = {};
cin >> n >> pmax;
if (!n && !pmax)
break;
int i;
int p = pmax;
for (i = 0; 1; i++) {
if (p) {
p--;
stone[i % n]++;
if (!p && stone[i % n] == pmax) {
break;
}
} else {
p += stone[i % n];
stone[i % n] = 0;
}
}
cout << i % n << endl;
}
return 0;
}
| insert | 15 | 15 | 15 | 17 | -8 | |
p00740 | C++ | Runtime Error | #include <iostream>
using namespace std;
bool search(int p[], int N) {
int count = 0;
for (int i = 0; i < N; ++i) {
if (p[i] != 0) {
count++;
}
}
if (count == 1) {
return true;
} else {
return false;
}
}
int main(void) {
int n, p;
while (cin >> n >> p) {
int *people = new int[n];
for (int i = 0; i < n; ++i) {
people[i] = 0;
}
// finish initialization
int turn = 0;
while (1) {
if (p >= 1) {
++people[turn];
--p;
if (p == 0) {
if (search(people, n) == true) {
break;
}
}
} else { // p<=0]
p = people[turn];
people[turn] = 0;
}
if (turn == (n - 1)) {
turn = 0;
} else {
++turn;
}
}
cout << turn << endl;
delete[] people;
}
return 0;
} | #include <iostream>
using namespace std;
bool search(int p[], int N) {
int count = 0;
for (int i = 0; i < N; ++i) {
if (p[i] != 0) {
count++;
}
}
if (count == 1) {
return true;
} else {
return false;
}
}
int main(void) {
int n, p;
while (cin >> n >> p) {
if ((n == 0) && (p == 0)) {
return 0;
}
int *people = new int[n];
for (int i = 0; i < n; ++i) {
people[i] = 0;
}
// finish initialization
int turn = 0;
while (1) {
if (p >= 1) {
++people[turn];
--p;
if (p == 0) {
if (search(people, n) == true) {
break;
}
}
} else { // p<=0]
p = people[turn];
people[turn] = 0;
}
if (turn == (n - 1)) {
turn = 0;
} else {
++turn;
}
}
cout << turn << endl;
delete[] people;
}
return 0;
} | insert | 21 | 21 | 21 | 24 | -11 | |
p00740 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
#define ll long long
#define all(a) a.begin(), a.end()
#define ull unsigned long long
#define pb(x) push_back(x)
#define dbg(x) cout << #x << " : " << (x) << endl;
using namespace std;
const int INF = 1500000000;
const double PI = 3.14159265359;
const int mod = 1000000000 + 7;
const int MAX_N = 50, MAX_P = 50;
int n, p, res, v[MAX_N];
void solve() {
memset(v, 0, n);
int c = 0;
while (true) {
if (p == 0) {
p = v[c];
v[c] = 0;
} else {
p--;
v[c]++;
if (p == 0) {
bool flg = true;
rep(i, n) if (i != c && v[i] > 0) flg = false;
if (flg)
break;
}
}
c = (c == n - 1) ? 0 : c + 1;
res = c;
}
}
int main() {
while (true) {
cin >> n >> p;
if (!n && !p)
break;
solve();
cout << res << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
#define ll long long
#define all(a) a.begin(), a.end()
#define ull unsigned long long
#define pb(x) push_back(x)
#define dbg(x) cout << #x << " : " << (x) << endl;
using namespace std;
const int INF = 1500000000;
const double PI = 3.14159265359;
const int mod = 1000000000 + 7;
const int MAX_N = 50, MAX_P = 50;
int n, p, res, v[MAX_N];
void solve() {
rep(i, n) v[i] = 0;
int c = 0;
while (true) {
if (p == 0) {
p = v[c];
v[c] = 0;
} else {
p--;
v[c]++;
if (p == 0) {
bool flg = true;
rep(i, n) if (i != c && v[i] > 0) flg = false;
if (flg)
break;
}
}
c = (c == n - 1) ? 0 : c + 1;
res = c;
}
}
int main() {
while (true) {
cin >> n >> p;
if (!n && !p)
break;
solve();
cout << res << endl;
}
return 0;
} | replace | 18 | 19 | 18 | 19 | TLE | |
p00740 | C++ | Time Limit Exceeded | #include <cstdio>
#include <iostream>
using namespace std;
static const int MAXV = 1000;
int main() {
while (1) {
int n, m, p, M[MAXV] = {}, i = 0;
scanf("%d %d", &n, &m);
if (n == 0 && m == 0)
break;
p = m;
while (1) {
printf("%d %d %d\n", M[0], M[1], M[2]);
if (p == 0) {
p = M[i];
M[i] = 0;
} else {
M[i]++;
p--;
}
if (M[i] == m)
break;
i++;
if (i == n)
i = 0;
}
printf("%d\n", i);
}
} | #include <cstdio>
#include <iostream>
using namespace std;
static const int MAXV = 1000;
int main() {
while (1) {
int n, m, p, M[MAXV] = {}, i = 0;
scanf("%d %d", &n, &m);
if (n == 0 && m == 0)
break;
p = m;
while (1) {
// printf("%d %d %d\n", M[0], M[1], M[2]);
if (p == 0) {
p = M[i];
M[i] = 0;
} else {
M[i]++;
p--;
}
if (M[i] == m)
break;
i++;
if (i == n)
i = 0;
}
printf("%d\n", i);
}
} | replace | 14 | 15 | 14 | 15 | TLE | |
p00740 | C++ | Time Limit Exceeded | #define _USE_MATH_DEFINES
#define INF 100000000
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
static const double EPS = 1e-8;
const int tx[] = {-1, 0, 1, 0};
const int ty[] = {0, 1, 0, -1};
bool check(map<int, int> hand, int step, int n) {
for (map<int, int>::iterator it = hand.begin(); it != hand.end(); it++) {
if (it->first == step % n)
continue;
if (it->second != 0)
return false;
}
return true;
}
int main() {
int n, p;
while (~scanf("%d %d", &n, &p)) {
if (n == p && p == 0)
break;
map<int, int> hand;
int bowl = p;
int step = 0;
int res = 0;
while (1) {
if (bowl > 0) {
hand[step]++;
bowl--;
if (bowl == 0 && check(hand, step, n)) {
res = step;
break;
}
} else if (bowl == 0) {
bowl += hand[step];
hand[step] = 0;
}
step = (step + 1) % n;
}
printf("%d\n", res);
}
} | #define _USE_MATH_DEFINES
#define INF 100000000
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
static const double EPS = 1e-8;
const int tx[] = {-1, 0, 1, 0};
const int ty[] = {0, 1, 0, -1};
bool check(map<int, int> &hand, int step, int n) {
for (map<int, int>::iterator it = hand.begin(); it != hand.end(); it++) {
if (it->first == step % n)
continue;
if (it->second != 0)
return false;
}
return true;
}
int main() {
int n, p;
while (~scanf("%d %d", &n, &p)) {
if (n == p && p == 0)
break;
map<int, int> hand;
int bowl = p;
int step = 0;
int res = 0;
while (1) {
if (bowl > 0) {
hand[step]++;
bowl--;
if (bowl == 0 && check(hand, step, n)) {
res = step;
break;
}
} else if (bowl == 0) {
bowl += hand[step];
hand[step] = 0;
}
step = (step + 1) % n;
}
printf("%d\n", res);
}
} | replace | 32 | 33 | 32 | 33 | TLE | |
p00740 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, r;
while (cin >> n >> r, n) {
int p[n];
fill(p, p + n, 0);
int s = n;
for (int i = 0;; i++, i %= n) {
if (p[i] == r) {
cout << i << endl;
break;
} else {
if (s == 0) {
s += p[i];
p[i] = 0;
} else {
p[i]++;
s--;
}
}
}
}
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, r;
while (cin >> n >> r, n) {
int p[n];
fill(p, p + n, 0);
int s = r;
for (int i = 0;; i++, i %= n) {
if (p[i] == r) {
cout << i << endl;
break;
} else {
if (s == 0) {
s += p[i];
p[i] = 0;
} else {
p[i]++;
s--;
}
}
}
}
} | replace | 10 | 11 | 10 | 11 | TLE | |
p00740 | C++ | Time Limit Exceeded | #include <stdio.h>
int main() {
int t[50], n, s, storn, i, j;
while (1) {
scanf("%d %d", &n, &storn);
// printf("%d %d",n,storn);///
if (n == 0 && storn == 0)
break;
for (i = 0; i < n; i++)
t[i] = 0;
j = 0;
s = storn;
while (1) {
printf("%d %d %d %d\n", j, s, t[j], storn); ///
if (s != 0) {
t[j]++;
s--;
} else if (s == 0) {
s = t[j];
t[j] = 0;
}
if (t[j] == storn)
break;
j++;
if (j == n)
j = 0;
}
printf("%d\n", j);
}
return 0;
} | #include <stdio.h>
int main() {
int t[50], n, s, storn, i, j;
while (1) {
scanf("%d %d", &n, &storn);
// printf("%d %d",n,storn);///
if (n == 0 && storn == 0)
break;
for (i = 0; i < n; i++)
t[i] = 0;
j = 0;
s = storn;
while (1) {
// printf("%d %d %d %d\n",j,s,t[j],storn);///
if (s != 0) {
t[j]++;
s--;
} else if (s == 0) {
s = t[j];
t[j] = 0;
}
if (t[j] == storn)
break;
j++;
if (j == n)
j = 0;
}
printf("%d\n", j);
}
return 0;
} | replace | 13 | 14 | 13 | 14 | TLE | |
p00741 | C++ | Time Limit Exceeded | #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define REP(i, a, b) for (i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(), (a).end()
#define ifnot(a) if (not a)
#define dump(x) cerr << #x << " = " << (x) << endl
using namespace std;
void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template <class T, class U> void reader(T &t, U &u) {
reader(t);
reader(u);
}
template <class T, class U, class V> void reader(T &t, U &u, V &v) {
reader(t);
reader(u);
reader(v);
}
void writer(const int a, char c) {
printf("%d", a);
putchar(c);
}
void writer(const ll a, char c) {
printf("%lld", a);
putchar(c);
}
void writer(const ull a, char c) {
printf("%llu", a);
putchar(c);
}
void writer(const double a, char c) {
printf("%.20lf", a);
putchar(c);
}
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) {
printf("%s", a);
putchar(c);
};
void writer(const char a, char c) {
putchar(a);
putchar(c);
};
template <class T> void writerLn(T t) { writer(t, '\n'); }
template <class T, class U> void writerLn(T t, U u) {
writer(t, ' ');
writer(u, '\n');
}
template <class T, class U, class V> void writerLn(T t, U u, V v) {
writer(t, ' ');
writer(u, ' ');
writer(v, '\n');
}
template <class T> void writerArr(T x[], int n) {
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
template <class T> void writerVec(vector<T> x) {
int n = x.size();
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
vector<string> split(const string &str, char sep) {
vector<string> v;
stringstream ss(str);
string buffer;
while (getline(ss, buffer, sep)) {
v.push_back(buffer);
}
return v;
}
// #define int ll
bool test = 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define MAX MAX000
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
int W, H;
char c[100][100];
void grid_dfs(int y, int x) {
int i, j;
c[y][x] = '0';
for (i = -1; i <= 1; i++) {
for (j = -1; j <= 1; j++) {
int nx = x + i;
int ny = y + j;
if (nx < 0 || W <= nx)
continue;
if (ny < 0 || H <= ny)
continue;
if (c[ny][nx] == '0')
continue;
grid_dfs(ny, nx);
}
}
}
signed main(void) {
int i, j, k;
while (1) {
cin >> W >> H;
if (W == 0)
continue;
rep(i, H) rep(j, W) { reader(c[i][j]); }
/*rep(i, H) {
writerArr(c[i],W);
}*/
int cnt = 0;
rep(i, H) rep(j, W) {
if (c[i][j] == '1') {
cnt++;
grid_dfs(i, j);
}
}
cout << cnt << endl;
}
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define REP(i, a, b) for (i = a; i < b; ++i)
#define rep(i, n) REP(i, 0, n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(), (a).end()
#define ifnot(a) if (not a)
#define dump(x) cerr << #x << " = " << (x) << endl
using namespace std;
void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template <class T, class U> void reader(T &t, U &u) {
reader(t);
reader(u);
}
template <class T, class U, class V> void reader(T &t, U &u, V &v) {
reader(t);
reader(u);
reader(v);
}
void writer(const int a, char c) {
printf("%d", a);
putchar(c);
}
void writer(const ll a, char c) {
printf("%lld", a);
putchar(c);
}
void writer(const ull a, char c) {
printf("%llu", a);
putchar(c);
}
void writer(const double a, char c) {
printf("%.20lf", a);
putchar(c);
}
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) {
printf("%s", a);
putchar(c);
};
void writer(const char a, char c) {
putchar(a);
putchar(c);
};
template <class T> void writerLn(T t) { writer(t, '\n'); }
template <class T, class U> void writerLn(T t, U u) {
writer(t, ' ');
writer(u, '\n');
}
template <class T, class U, class V> void writerLn(T t, U u, V v) {
writer(t, ' ');
writer(u, ' ');
writer(v, '\n');
}
template <class T> void writerArr(T x[], int n) {
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
template <class T> void writerVec(vector<T> x) {
int n = x.size();
int i;
if (!n) {
putchar('\n');
return;
}
rep(i, n - 1) writer(x[i], ' ');
writer(x[n - 1], '\n');
}
vector<string> split(const string &str, char sep) {
vector<string> v;
stringstream ss(str);
string buffer;
while (getline(ss, buffer, sep)) {
v.push_back(buffer);
}
return v;
}
// #define int ll
bool test = 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define MAX MAX000
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
int W, H;
char c[100][100];
void grid_dfs(int y, int x) {
int i, j;
c[y][x] = '0';
for (i = -1; i <= 1; i++) {
for (j = -1; j <= 1; j++) {
int nx = x + i;
int ny = y + j;
if (nx < 0 || W <= nx)
continue;
if (ny < 0 || H <= ny)
continue;
if (c[ny][nx] == '0')
continue;
grid_dfs(ny, nx);
}
}
}
signed main(void) {
int i, j, k;
while (1) {
cin >> W >> H;
if (W == 0)
break;
rep(i, H) rep(j, W) { reader(c[i][j]); }
/*rep(i, H) {
writerArr(c[i],W);
}*/
int cnt = 0;
rep(i, H) rep(j, W) {
if (c[i][j] == '1') {
cnt++;
grid_dfs(i, j);
}
}
cout << cnt << endl;
}
return 0;
} | replace | 128 | 129 | 128 | 129 | TLE | |
p00741 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int needx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int needy[] = {0, 1, 0, -1, 1, -1, 1, -1};
//??¶?????¨???false????????????true???????????¢??°//
bool land(int x, int y, vector<vector<bool>> &cango) {
if (cango[x][y]) {
cango[x][y] = false;
for (int i = 0; i < 8; i++) {
int nextx = x + needx[i];
int nexty = y + needy[i];
if (cango[nextx][nexty])
bool flag = land(nextx, nexty, cango);
}
return true;
} else {
return false;
}
}
int main(void) {
int input;
int w, h;
while (1) {
cin >> w >> h;
if (h == 0)
break;
vector<vector<bool>> cango(h + 2, vector<bool>(w + 2, false));
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cin >> input;
if (input == 1) {
cango[i][j] = true;
}
}
}
int t = 0;
for (int i = 1; i <= w; i++) {
for (int j = 1; j <= h; j++) {
if (land(i, j, cango)) {
t++;
}
}
}
cout << t << endl;
}
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int needx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int needy[] = {0, 1, 0, -1, 1, -1, 1, -1};
//??¶?????¨???false????????????true???????????¢??°//
bool land(int x, int y, vector<vector<bool>> &cango) {
if (cango[x][y]) {
cango[x][y] = false;
for (int i = 0; i < 8; i++) {
int nextx = x + needx[i];
int nexty = y + needy[i];
if (cango[nextx][nexty])
bool flag = land(nextx, nexty, cango);
}
return true;
} else {
return false;
}
}
int main(void) {
int input;
int w, h;
while (1) {
cin >> w >> h;
if (h == 0)
break;
vector<vector<bool>> cango(h + 2, vector<bool>(w + 2, false));
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cin >> input;
if (input == 1) {
cango[i][j] = true;
}
}
}
int t = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (land(i, j, cango)) {
t++;
}
}
}
cout << t << endl;
}
return 0;
} | replace | 38 | 40 | 38 | 40 | 0 | |
p00741 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};
bool dfs(int sx, int sy, vector<vector<bool>> &c) {
if (c[sx][sy] == false)
return false;
c[sx][sy] = false;
for (int i = 0; i < 8; i++) {
int nx = sx + dx[i];
int ny = sy + dy[i];
bool flag = dfs(nx, ny, c);
}
return true;
}
int main(void) {
int h, w, temp;
while (1) {
cin >> w >> h;
if (w == 0)
break;
vector<vector<bool>> c(w + 2, vector<bool>(h + 2, false));
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cin >> temp;
if (temp == 1)
c[i][j] = true;
}
}
int t = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
bool flag = dfs(i, j, c);
if (flag)
t++;
}
}
cout << t << endl;
}
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};
bool dfs(int sx, int sy, vector<vector<bool>> &c) {
if (c[sx][sy] == false)
return false;
c[sx][sy] = false;
for (int i = 0; i < 8; i++) {
int nx = sx + dx[i];
int ny = sy + dy[i];
bool flag = dfs(nx, ny, c);
}
return true;
}
int main(void) {
int h, w, temp;
while (1) {
cin >> w >> h;
if (w == 0)
break;
vector<vector<bool>> c(h + 2, vector<bool>(w + 2, false));
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cin >> temp;
if (temp == 1)
c[i][j] = true;
}
}
int t = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
bool flag = dfs(i, j, c);
if (flag)
t++;
}
}
cout << t << endl;
}
return 0;
} | replace | 24 | 25 | 24 | 25 | -11 | |
p00741 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define pb(in, tmp) in.push_back(tmp)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, b) loop(i, 0, b)
#define all(in) in.begin(), in.end()
using namespace std;
void isl(int in[50][50], int x, int y) {
in[x][y] = 0;
loop(i, -1, 2) {
loop(j, -1, 2) {
if (x - i >= 0 && y - j >= 0 && in[x - i][y - j])
isl(in, x - i, y - j);
}
}
}
int main() {
int n, m;
while (cin >> n >> m, n || m) {
int in[50][50] = {0};
int co = 0;
rep(i, m) rep(j, n) cin >> in[i][j];
rep(i, m) {
rep(j, n) {
if (in[i][j]) {
co++;
isl(in, i, j);
}
}
}
cout << co << endl;
}
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define pb(in, tmp) in.push_back(tmp)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, b) loop(i, 0, b)
#define all(in) in.begin(), in.end()
using namespace std;
void isl(int in[50][50], int x, int y) {
in[x][y] = 0;
loop(i, -1, 2) {
loop(j, -1, 2) {
if (x - i >= 0 && x - i < 50 && y - j >= 0 && y - j < 50 &&
in[x - i][y - j])
isl(in, x - i, y - j);
}
}
}
int main() {
int n, m;
while (cin >> n >> m, n || m) {
int in[50][50] = {0};
int co = 0;
rep(i, m) rep(j, n) cin >> in[i][j];
rep(i, m) {
rep(j, n) {
if (in[i][j]) {
co++;
isl(in, i, j);
}
}
}
cout << co << endl;
}
} | replace | 15 | 16 | 15 | 17 | 0 | |
p00741 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void dfs(int x, int y, vector<vector<bool>> &canGo) {
canGo[x][y] = false;
for (int i = 0; i < 9; i++)
if (canGo[x + dx[i]][y + dy[i]])
dfs(x + dx[i], y + dy[i], canGo);
return;
}
int main(void) {
while (true) {
int w, h;
cin >> w >> h;
if (w == 0 && h == 0) {
break;
}
int input;
vector<vector<bool>> canGo(h + 2, vector<bool>(w + 2, false));
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cin >> input;
if (input == 1) {
canGo[i][j] = true;
}
}
}
int count = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (canGo[i][j]) {
++count;
dfs(i, j, canGo);
}
}
}
cout << count << endl;
}
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void dfs(int x, int y, vector<vector<bool>> &canGo) {
canGo[x][y] = false;
for (int i = 0; i < 8; i++)
if (canGo[x + dx[i]][y + dy[i]])
dfs(x + dx[i], y + dy[i], canGo);
return;
}
int main(void) {
while (true) {
int w, h;
cin >> w >> h;
if (w == 0 && h == 0) {
break;
}
int input;
vector<vector<bool>> canGo(h + 2, vector<bool>(w + 2, false));
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
cin >> input;
if (input == 1) {
canGo[i][j] = true;
}
}
}
int count = 0;
for (int i = 1; i <= h; i++) {
for (int j = 1; j <= w; j++) {
if (canGo[i][j]) {
++count;
dfs(i, j, canGo);
}
}
}
cout << count << endl;
}
return 0;
} | replace | 9 | 10 | 9 | 10 | -11 | |
p00741 | C++ | Memory Limit Exceeded | #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#include <random>
using namespace std;
// 呪文
#define DUMPOUT cerr
#define dump(...) \
DUMPOUT << " "; \
DUMPOUT << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" \
<< endl; \
DUMPOUT << " "; \
dump_func(__VA_ARGS__)
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
template <typename _KTy, typename _Ty>
ostream &operator<<(ostream &ostr, const pair<_KTy, _Ty> &m) {
ostr << "{" << m.first << ", " << m.second << "}";
return ostr;
}
template <typename _KTy, typename _Ty>
ostream &operator<<(ostream &ostr, const map<_KTy, _Ty> &m) {
if (m.empty()) {
ostr << "{ }";
return ostr;
}
ostr << "{" << *m.begin();
for (auto itr = ++m.begin(); itr != m.end(); itr++) {
ostr << ", " << *itr;
}
ostr << "}";
return ostr;
}
template <typename _Ty>
ostream &operator<<(ostream &ostr, const vector<_Ty> &v) {
if (v.empty()) {
ostr << "{ }";
return ostr;
}
ostr << "{" << v.front();
for (auto itr = ++v.begin(); itr != v.end(); itr++) {
ostr << ", " << *itr;
}
ostr << "}";
return ostr;
}
template <typename _Ty> ostream &operator<<(ostream &ostr, const set<_Ty> &s) {
if (s.empty()) {
ostr << "{ }";
return ostr;
}
ostr << "{" << *(s.begin());
for (auto itr = ++s.begin(); itr != s.end(); itr++) {
ostr << ", " << *itr;
}
ostr << "}";
return ostr;
}
template <typename _Ty>
ostream &operator<<(ostream &ostr, const stack<_Ty> &s) {
if (s.empty()) {
ostr << "{ }";
return ostr;
}
stack<_Ty> t(s);
ostr << "{" << t.top();
t.pop();
while (!t.empty()) {
ostr << ", " << t.top();
t.pop();
}
ostr << "}";
return ostr;
}
template <typename _Ty> ostream &operator<<(ostream &ostr, const list<_Ty> &l) {
if (l.empty()) {
ostr << "{ }";
return ostr;
}
ostr << "{" << l.front();
for (auto itr = ++l.begin(); itr != l.end(); ++itr) {
ostr << ", " << *itr;
}
ostr << "}";
return ostr;
}
template <typename _KTy, typename _Ty>
istream &operator>>(istream &istr, pair<_KTy, _Ty> &m) {
istr >> m.first >> m.second;
return istr;
}
template <typename _Ty> istream &operator>>(istream &istr, vector<_Ty> &v) {
for (size_t i = 0; i < v.size(); i++)
istr >> v[i];
return istr;
}
namespace aux { // print tuple
template <typename Ty, unsigned N, unsigned L> struct tp {
static void print(ostream &os, const Ty &v) {
os << get<N>(v) << ", ";
tp<Ty, N + 1, L>::print(os, v);
}
};
template <typename Ty, unsigned N> struct tp<Ty, N, N> {
static void print(ostream &os, const Ty &value) { os << get<N>(value); }
};
} // namespace aux
template <typename... Tys>
ostream &operator<<(ostream &os, const tuple<Tys...> &t) {
os << "{";
aux::tp<tuple<Tys...>, 0, sizeof...(Tys) - 1>::print(os, t);
os << "}";
return os;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) == 0) {
DUMPOUT << " ";
} else {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
}
#define PI 3.14159265358979323846
#define EPS 1e-11
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define fake false
const int di[] = {0, -1, -1, -1, 0, 1, 1, 1};
const int dj[] = {1, 1, 0, -1, -1, -1, 0, 1};
int main() {
// clock_t start, end;
// start = clock();
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int w, h;
cin >> w >> h;
if (w == 0)
break;
vector<vector<int>> A(h, vector<int>(w));
cin >> A;
int cnt = 0;
REP(i, h) REP(j, w) {
if (A[i][j] == 1) {
cnt++;
queue<pii> qu;
qu.push(pii(i, j));
while (!qu.empty()) {
pii p = qu.front();
qu.pop();
int ii = p.first, jj = p.second;
A[ii][jj] = 0;
REP(d, 8) {
int ni = ii + di[d], nj = jj + dj[d];
if (ni < 0 || h <= ni || nj < 0 || w <= nj || A[ni][nj] == 0)
continue;
qu.push(pii(ni, nj));
}
}
}
}
cout << cnt << endl;
}
// end = clock();
// printf("%d msec.\n", end - start);
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#include <random>
using namespace std;
// 呪文
#define DUMPOUT cerr
#define dump(...) \
DUMPOUT << " "; \
DUMPOUT << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" \
<< endl; \
DUMPOUT << " "; \
dump_func(__VA_ARGS__)
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
template <typename _KTy, typename _Ty>
ostream &operator<<(ostream &ostr, const pair<_KTy, _Ty> &m) {
ostr << "{" << m.first << ", " << m.second << "}";
return ostr;
}
template <typename _KTy, typename _Ty>
ostream &operator<<(ostream &ostr, const map<_KTy, _Ty> &m) {
if (m.empty()) {
ostr << "{ }";
return ostr;
}
ostr << "{" << *m.begin();
for (auto itr = ++m.begin(); itr != m.end(); itr++) {
ostr << ", " << *itr;
}
ostr << "}";
return ostr;
}
template <typename _Ty>
ostream &operator<<(ostream &ostr, const vector<_Ty> &v) {
if (v.empty()) {
ostr << "{ }";
return ostr;
}
ostr << "{" << v.front();
for (auto itr = ++v.begin(); itr != v.end(); itr++) {
ostr << ", " << *itr;
}
ostr << "}";
return ostr;
}
template <typename _Ty> ostream &operator<<(ostream &ostr, const set<_Ty> &s) {
if (s.empty()) {
ostr << "{ }";
return ostr;
}
ostr << "{" << *(s.begin());
for (auto itr = ++s.begin(); itr != s.end(); itr++) {
ostr << ", " << *itr;
}
ostr << "}";
return ostr;
}
template <typename _Ty>
ostream &operator<<(ostream &ostr, const stack<_Ty> &s) {
if (s.empty()) {
ostr << "{ }";
return ostr;
}
stack<_Ty> t(s);
ostr << "{" << t.top();
t.pop();
while (!t.empty()) {
ostr << ", " << t.top();
t.pop();
}
ostr << "}";
return ostr;
}
template <typename _Ty> ostream &operator<<(ostream &ostr, const list<_Ty> &l) {
if (l.empty()) {
ostr << "{ }";
return ostr;
}
ostr << "{" << l.front();
for (auto itr = ++l.begin(); itr != l.end(); ++itr) {
ostr << ", " << *itr;
}
ostr << "}";
return ostr;
}
template <typename _KTy, typename _Ty>
istream &operator>>(istream &istr, pair<_KTy, _Ty> &m) {
istr >> m.first >> m.second;
return istr;
}
template <typename _Ty> istream &operator>>(istream &istr, vector<_Ty> &v) {
for (size_t i = 0; i < v.size(); i++)
istr >> v[i];
return istr;
}
namespace aux { // print tuple
template <typename Ty, unsigned N, unsigned L> struct tp {
static void print(ostream &os, const Ty &v) {
os << get<N>(v) << ", ";
tp<Ty, N + 1, L>::print(os, v);
}
};
template <typename Ty, unsigned N> struct tp<Ty, N, N> {
static void print(ostream &os, const Ty &value) { os << get<N>(value); }
};
} // namespace aux
template <typename... Tys>
ostream &operator<<(ostream &os, const tuple<Tys...> &t) {
os << "{";
aux::tp<tuple<Tys...>, 0, sizeof...(Tys) - 1>::print(os, t);
os << "}";
return os;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) == 0) {
DUMPOUT << " ";
} else {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
}
#define PI 3.14159265358979323846
#define EPS 1e-11
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define fake false
const int di[] = {0, -1, -1, -1, 0, 1, 1, 1};
const int dj[] = {1, 1, 0, -1, -1, -1, 0, 1};
int main() {
// clock_t start, end;
// start = clock();
cin.tie(0);
ios::sync_with_stdio(false);
while (true) {
int w, h;
cin >> w >> h;
if (w == 0)
break;
vector<vector<int>> A(h, vector<int>(w));
cin >> A;
int cnt = 0;
REP(i, h) REP(j, w) {
if (A[i][j] == 1) {
cnt++;
queue<pii> qu;
qu.push(pii(i, j));
while (!qu.empty()) {
pii p = qu.front();
qu.pop();
int ii = p.first, jj = p.second;
if (A[ii][jj] == 0)
continue;
A[ii][jj] = 0;
REP(d, 8) {
int ni = ii + di[d], nj = jj + dj[d];
if (ni < 0 || h <= ni || nj < 0 || w <= nj || A[ni][nj] == 0)
continue;
qu.push(pii(ni, nj));
}
}
}
}
cout << cnt << endl;
}
// end = clock();
// printf("%d msec.\n", end - start);
return 0;
}
| insert | 179 | 179 | 179 | 181 | MLE | |
p00741 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
using namespace std;
#ifdef _DEBUG
#define debug_io \
fstream cin("input.txt"); \
ofstream cout("output.txt");
#else
#define debug_io ;
#endif
int main() {
debug_io int w, h;
while (cin >> w >> h, w + h) {
int tile[55][55];
REP(i, h) {
REP(j, w) { cin >> tile[i][j]; }
}
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int ans = 0;
REP(i, h) {
REP(j, w) {
if (tile[i][j] == 1) {
vector<pair<int, int>> bfs;
bfs.push_back({i, j});
while (bfs.size()) {
auto now = bfs.front();
bfs.erase(bfs.begin());
int x = now.second;
int y = now.first;
tile[y][x] = 2;
REP(k, 8) {
int nx = max(0, min(x + dx[k], w - 1));
int ny = max(0, min(y + dy[k], h - 1));
if (tile[ny][nx] == 1) {
bfs.push_back({ny, nx});
}
}
}
ans++;
}
}
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
using namespace std;
#ifdef _DEBUG
#define debug_io \
fstream cin("input.txt"); \
ofstream cout("output.txt");
#else
#define debug_io ;
#endif
int main() {
debug_io int w, h;
while (cin >> w >> h, w + h) {
int tile[55][55];
REP(i, h) {
REP(j, w) { cin >> tile[i][j]; }
}
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int ans = 0;
REP(i, h) {
REP(j, w) {
if (tile[i][j] == 1) {
vector<pair<int, int>> bfs;
bfs.push_back({i, j});
while (bfs.size()) {
auto now = bfs.front();
bfs.erase(bfs.begin());
int x = now.second;
int y = now.first;
if (tile[y][x] == 2) {
continue;
}
tile[y][x] = 2;
REP(k, 8) {
int nx = max(0, min(x + dx[k], w - 1));
int ny = max(0, min(y + dy[k], h - 1));
if (tile[ny][nx] == 1) {
bfs.push_back({ny, nx});
}
}
}
ans++;
}
}
}
cout << ans << endl;
}
} | insert | 36 | 36 | 36 | 39 | TLE | |
p00741 | C++ | Memory Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPS(a, i, n) for (int(i) = (a); (i) < (n); ++(i))
#define REVERSE(i, n) for (int(i) = n - 1; (i) >= 0; --i)
#define ALL(c) (c).begin(), (c).end()
#define LL long long
#define int LL
#define inf (1LL << 60)
#define mod 1000000007
#define QUICK_CIN \
ios::sync_with_stdio(false); \
cin.tie(0);
#define lower lower_bound
#define upper upper_bound
#define ZERO(c, n) memset(&c[0], 0, sizeof(int) * n)
#define ZERO2(c, n) memset(&c[0][0],0,sizeof(int)*n
#define pl(a) cout << "" #a ": " << a << endl;
#ifdef _DEBUG
#define debug_io \
fstream cin("input.txt"); \
ofstream cout("output.txt");
template <class T> fstream &operator>>(fstream &is, vector<T> &v) {
int n = v.size();
REP(i, n) { is >> v[i]; }
return is;
}
#else
#define debug_io ;
#endif
#define debug_input debug_io
#define DOWN(T) std::greater<T>()
template <class T> istream &operator>>(istream &is, vector<T> &v) {
int n = v.size();
REP(i, n) { is >> v[i]; }
return is;
}
using vs = vector<string>;
using vi = vector<int>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using vvi = vector<vi>;
using pss = pair<string, string>;
using vpii = vector<pii>;
template <class T> bool valid(T x, T w) { return 0 <= x && x < w; }
// int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 };
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
bool ed[55][55];
int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
signed main() {
QUICK_CIN;
debug_input;
int w, h;
while (cin >> w >> h, w + h) {
vector<vi> tile(h, vi(w));
REP(i, h) {
REP(j, w) { cin >> tile[i][j]; }
}
int ans = 0;
REP(i, 55) {
REP(j, 55) { ed[i][j] = false; }
}
REP(i, h) {
REP(j, w) {
if (tile[i][j] != 1)
continue;
queue<pii> q;
q.push({i, j});
while (q.size()) {
auto t = q.front();
q.pop();
auto y = t.first;
auto x = t.second;
tile[y][x] = 2;
ed[y][x] = true;
REP(k, 8) {
auto nx = min(w - 1, max(0LL, x + dx[k]));
auto ny = min(h - 1, max(0LL, y + dy[k]));
if (!ed[ny][nx] && tile[ny][nx] == 1) {
q.push({ny, nx});
}
}
}
ans++;
}
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define REPS(a, i, n) for (int(i) = (a); (i) < (n); ++(i))
#define REVERSE(i, n) for (int(i) = n - 1; (i) >= 0; --i)
#define ALL(c) (c).begin(), (c).end()
#define LL long long
#define int LL
#define inf (1LL << 60)
#define mod 1000000007
#define QUICK_CIN \
ios::sync_with_stdio(false); \
cin.tie(0);
#define lower lower_bound
#define upper upper_bound
#define ZERO(c, n) memset(&c[0], 0, sizeof(int) * n)
#define ZERO2(c, n) memset(&c[0][0],0,sizeof(int)*n
#define pl(a) cout << "" #a ": " << a << endl;
#ifdef _DEBUG
#define debug_io \
fstream cin("input.txt"); \
ofstream cout("output.txt");
template <class T> fstream &operator>>(fstream &is, vector<T> &v) {
int n = v.size();
REP(i, n) { is >> v[i]; }
return is;
}
#else
#define debug_io ;
#endif
#define debug_input debug_io
#define DOWN(T) std::greater<T>()
template <class T> istream &operator>>(istream &is, vector<T> &v) {
int n = v.size();
REP(i, n) { is >> v[i]; }
return is;
}
using vs = vector<string>;
using vi = vector<int>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using vvi = vector<vi>;
using pss = pair<string, string>;
using vpii = vector<pii>;
template <class T> bool valid(T x, T w) { return 0 <= x && x < w; }
// int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 };
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
bool ed[55][55];
int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
signed main() {
QUICK_CIN;
debug_input;
int w, h;
while (cin >> w >> h, w + h) {
vector<vi> tile(h, vi(w));
REP(i, h) {
REP(j, w) { cin >> tile[i][j]; }
}
int ans = 0;
REP(i, 55) {
REP(j, 55) { ed[i][j] = false; }
}
REP(i, h) {
REP(j, w) {
if (tile[i][j] != 1)
continue;
queue<pii> q;
q.push({i, j});
while (q.size()) {
auto t = q.front();
q.pop();
auto y = t.first;
auto x = t.second;
if (ed[y][x]) {
continue;
}
tile[y][x] = 2;
ed[y][x] = true;
REP(k, 8) {
auto nx = min(w - 1, max(0LL, x + dx[k]));
auto ny = min(h - 1, max(0LL, y + dy[k]));
if (!ed[ny][nx] && tile[ny][nx] == 1) {
q.push({ny, nx});
}
}
}
ans++;
}
}
cout << ans << endl;
}
} | insert | 80 | 80 | 80 | 83 | MLE | |
p00741 | C++ | Runtime Error | #include <iostream>
#include <stdlib.h>
using namespace std;
int d[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {-1, 0},
{1, 0}, {-1, 1}, {0, 1}, {1, 1}};
void func(int **a, int s, int t, int i, int j) {
if (a[i][j] == 0) {
return;
}
a[i][j] = 0;
for (int k = 0; k < 8; k++) {
if ((i + d[k][0] >= 0 && i + d[k][0] < t) &&
(j + d[k][1] >= 0 && j + d[k][1] < s)) {
func(a, s, t, i + d[k][0], j + d[k][1]);
}
}
return;
}
int main(int argc, char **argv) {
int s, t, **a, c, t2, s2;
while (1) {
cin >> s >> t;
if (s == 0 && t == 0) {
break;
} else if (s == 1 || t == 1) {
t2 = t + 1;
s2 = s + 1;
} else {
t2 = t;
s2 = s;
}
a = (int **)calloc(t2, sizeof(int));
for (int i = 0; i < t; i++) {
a[i] = (int *)calloc(s2, sizeof(int));
for (int j = 0; j < s; j++) {
cin >> c;
a[i][j] = c;
}
}
c = 0;
for (int i = 0; i < t; i++) {
for (int j = 0; j < s; j++) {
if (a[i][j] == 1) {
c++;
func(a, s, t, i, j);
}
}
}
cout << c << endl;
for (int i = 0; i < s2; i++) {
free(a[i]);
}
free(a);
}
return 0;
} | #include <iostream>
#include <stdlib.h>
using namespace std;
int d[8][2] = {{-1, -1}, {0, -1}, {1, -1}, {-1, 0},
{1, 0}, {-1, 1}, {0, 1}, {1, 1}};
void func(int **a, int s, int t, int i, int j) {
if (a[i][j] == 0) {
return;
}
a[i][j] = 0;
for (int k = 0; k < 8; k++) {
if ((i + d[k][0] >= 0 && i + d[k][0] < t) &&
(j + d[k][1] >= 0 && j + d[k][1] < s)) {
func(a, s, t, i + d[k][0], j + d[k][1]);
}
}
return;
}
int main(int argc, char **argv) {
int s, t, **a, c, t2, s2;
while (1) {
cin >> s >> t;
if (s == 0 && t == 0) {
break;
} else if (s == 1 || t == 1) {
t2 = t + 1;
s2 = s + 1;
} else {
t2 = t;
s2 = s;
}
a = (int **)calloc(t2, sizeof(int));
for (int i = 0; i < t; i++) {
a[i] = (int *)calloc(s2, sizeof(int));
for (int j = 0; j < s; j++) {
cin >> c;
a[i][j] = c;
}
}
c = 0;
for (int i = 0; i < t; i++) {
for (int j = 0; j < s; j++) {
if (a[i][j] == 1) {
c++;
func(a, s, t, i, j);
}
}
}
cout << c << endl;
for (int i = 0; i < t2; i++) {
free(a[i]);
}
free(a);
}
return 0;
} | replace | 58 | 59 | 58 | 59 | -11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.