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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02745 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int N = 2005;
int dp[3][3][N];
int ok(string t, string p, int ini, int a, int b) {
if (ini < 0) {
swap(t, p);
swap(a, b);
ini = abs(ini);
}
if (ini >= t.size())
return 1;
if (dp[a][b][ini] != -1)
return dp[a][b][ini];
int id = 0;
for (int i = ini; i < (int)t.size(); i++) {
if (id == p.size())
break;
if (p[id] != t[i] && t[i] != '?' && p[id] != '?') {
return dp[a][b][ini] = 0;
}
id++;
}
return dp[a][b][ini] = 1;
}
int main() {
memset(dp, -1, sizeof dp);
char a[3][N];
scanf("%s", a[0]);
scanf("%s", a[1]);
scanf("%s", a[2]);
string sa[3];
sa[0] = a[0];
sa[1] = a[1];
sa[2] = a[2];
int p[3] = {0, 1, 2};
int ans = 3 * N;
do {
for (int i = 0; i <= (int)sa[p[0]].size(); i++) {
if (ok(sa[p[0]], sa[p[1]], i, p[0], p[1])) {
int sz = max(sa[p[0]].size(), i + sa[p[1]].size());
string aux0 = sa[p[0]];
string aux1 = sa[p[1]];
int id = 0;
for (int j = i; j < (int)sa[p[0]].size(); j++) {
if (id == aux1.size())
break;
if (aux0[j] == '?' && aux1[id] != '?') {
aux0[j] = aux1[id];
} else if (aux0[j] != '?' && aux1[id] == '?') {
aux1[id] = aux0[j];
}
id++;
}
memset(dp, -1, sizeof dp);
for (int j = 0; j <= sz; j++) {
if (ok(sa[p[0]], sa[p[2]], j, p[0], p[2]) &&
ok(sa[p[1]], sa[p[2]], j - i, p[1], p[2])) {
ans = min(ans, max(sz, (int)j + (int)sa[p[2]].size()));
}
}
}
}
} while (next_permutation(p, p + 3));
printf("%d\n", ans);
return 0;
}
| #include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int N = 2005;
int dp[3][3][N];
int ok(string t, string p, int ini, int a, int b) {
if (ini < 0) {
swap(t, p);
swap(a, b);
ini = abs(ini);
}
if (ini >= t.size())
return 1;
if (dp[a][b][ini] != -1)
return dp[a][b][ini];
int id = 0;
for (int i = ini; i < (int)t.size(); i++) {
if (id == p.size())
break;
if (p[id] != t[i] && t[i] != '?' && p[id] != '?') {
return dp[a][b][ini] = 0;
}
id++;
}
return dp[a][b][ini] = 1;
}
int main() {
memset(dp, -1, sizeof dp);
char a[3][N];
scanf("%s", a[0]);
scanf("%s", a[1]);
scanf("%s", a[2]);
string sa[3];
sa[0] = a[0];
sa[1] = a[1];
sa[2] = a[2];
int p[3] = {0, 1, 2};
int ans = 3 * N;
do {
for (int i = 0; i <= (int)sa[p[0]].size(); i++) {
if (ok(sa[p[0]], sa[p[1]], i, p[0], p[1])) {
int sz = max(sa[p[0]].size(), i + sa[p[1]].size());
string aux0 = sa[p[0]];
string aux1 = sa[p[1]];
int id = 0;
for (int j = 0; j <= sz; j++) {
if (ok(sa[p[0]], sa[p[2]], j, p[0], p[2]) &&
ok(sa[p[1]], sa[p[2]], j - i, p[1], p[2])) {
ans = min(ans, max(sz, (int)j + (int)sa[p[2]].size()));
}
}
}
}
} while (next_permutation(p, p + 3));
printf("%d\n", ans);
return 0;
}
| delete | 55 | 66 | 55 | 55 | TLE | |
p02745 | C++ | Runtime Error | //
// Created by Hideaki Imamura on 2020-03-14.
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// const ll mod = 1000000007;
string a, b, c;
bool match(char c1, char c2) { return c1 == '?' || c2 == '?' || c1 == c2; }
int main() {
cin >> a >> b >> c;
int n_a = a.length(), n_b = b.length(), n_c = c.length();
const int X = 4000;
const int Y = 2000;
bool ab[2 * X], ac[2 * X], bc[2 * X];
for (int i = 0; i < n_a; ++i)
for (int j = 0; j < n_b; ++j)
if (!match(a[i], b[j]))
ab[i - j + X] = true;
for (int i = 0; i < n_a; ++i)
for (int j = 0; j < n_c; ++j)
if (!match(a[i], c[j]))
ac[i - j + X] = true;
for (int i = 0; i < n_b; ++i)
for (int j = 0; j < n_c; ++j)
if (!match(b[i], c[j]))
bc[i - j + X] = true;
int ans = 1e9;
for (int i = -2 * Y; i <= 2 * Y; ++i) {
for (int j = -2 * Y; j <= 2 * Y; ++j) {
if (!ab[i + X] && !ac[j + X] && !bc[j - i + X]) {
int L = min(0, min(i, j));
int R = max(n_a, max(n_b + i, n_c + j));
chmin(ans, R - L);
}
}
}
cout << ans << endl;
return 0;
} | //
// Created by Hideaki Imamura on 2020-03-14.
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// const ll mod = 1000000007;
string a, b, c;
bool match(char c1, char c2) { return c1 == '?' || c2 == '?' || c1 == c2; }
int main() {
cin >> a >> b >> c;
int n_a = a.length(), n_b = b.length(), n_c = c.length();
const int X = 40000;
const int Y = 2000;
bool ab[2 * X], ac[2 * X], bc[2 * X];
for (int i = 0; i < n_a; ++i)
for (int j = 0; j < n_b; ++j)
if (!match(a[i], b[j]))
ab[i - j + X] = true;
for (int i = 0; i < n_a; ++i)
for (int j = 0; j < n_c; ++j)
if (!match(a[i], c[j]))
ac[i - j + X] = true;
for (int i = 0; i < n_b; ++i)
for (int j = 0; j < n_c; ++j)
if (!match(b[i], c[j]))
bc[i - j + X] = true;
int ans = 1e9;
for (int i = -2 * Y; i <= 2 * Y; ++i) {
for (int j = -2 * Y; j <= 2 * Y; ++j) {
if (!ab[i + X] && !ac[j + X] && !bc[j - i + X]) {
int L = min(0, min(i, j));
int R = max(n_a, max(n_b + i, n_c + j));
chmin(ans, R - L);
}
}
}
cout << ans << endl;
return 0;
} | replace | 38 | 39 | 38 | 39 | 0 | |
p02745 | C++ | Runtime Error | #include <bits/stdc++.h>
#define LL long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for (int i = j; i <= k; i++)
#define dep(i, j, k) for (int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf LLONG_MAX
#define PI acos(-1)
using namespace std;
const int N = 2e4 + 5, up = 4000;
char a[N], b[N], c[N];
bool ab[N], ac[N], bc[N];
int main() {
scanf("%s", a);
scanf("%s", b);
scanf("%s", c);
int lena = strlen(a);
int lenb = strlen(b);
int lenc = strlen(c);
rep(i, 0, lena - 1)
rep(j, 0, lenb - 1) if (!(a[i] == b[j] || a[i] == '?' || b[j] == '?'))
ab[i - j + up] = 1;
rep(i, 0, lena - 1)
rep(j, 0, lenc - 1) if (!(a[i] == c[j] || a[i] == '?' || c[j] == '?'))
ac[i - j + up] = 1;
rep(i, 0, lenb - 1)
rep(j, 0, lenc - 1) if (!(b[i] == c[j] || b[i] == '?' || c[j] == '?'))
bc[i - j + up] = 1;
int ans = INF;
rep(i, -4000, 40000)
rep(j, -4000, 4000) if (!ab[i + up] && !ac[j + up] && !bc[j - i + up]) {
int L = min({0, i, j});
int R = max({lena, lenb + i, lenc + j});
ans = min(ans, R - L);
}
printf("%d\n", ans);
return 0;
}
| #include <bits/stdc++.h>
#define LL long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for (int i = j; i <= k; i++)
#define dep(i, j, k) for (int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf LLONG_MAX
#define PI acos(-1)
using namespace std;
const int N = 2e4 + 5, up = 4000;
char a[N], b[N], c[N];
bool ab[N], ac[N], bc[N];
int main() {
scanf("%s", a);
scanf("%s", b);
scanf("%s", c);
int lena = strlen(a);
int lenb = strlen(b);
int lenc = strlen(c);
rep(i, 0, lena - 1)
rep(j, 0, lenb - 1) if (!(a[i] == b[j] || a[i] == '?' || b[j] == '?'))
ab[i - j + up] = 1;
rep(i, 0, lena - 1)
rep(j, 0, lenc - 1) if (!(a[i] == c[j] || a[i] == '?' || c[j] == '?'))
ac[i - j + up] = 1;
rep(i, 0, lenb - 1)
rep(j, 0, lenc - 1) if (!(b[i] == c[j] || b[i] == '?' || c[j] == '?'))
bc[i - j + up] = 1;
int ans = INF;
rep(i, -4000, 4000)
rep(j, -4000, 4000) if (!ab[i + up] && !ac[j + up] && !bc[j - i + up]) {
int L = min({0, i, j});
int R = max({lena, lenb + i, lenc + j});
ans = min(ans, R - L);
}
printf("%d\n", ans);
return 0;
}
| replace | 37 | 38 | 37 | 38 | TLE | |
p02745 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxN = 4005;
int ans, tot;
int len[3];
bool f[3][3][maxN + 1];
char s[3][maxN + 1];
int main() {
for (int i = 0; i < 3; i++)
scanf("%s", s[i] + 1), len[i] = strlen(s[i] + 1);
tot = ans = len[0] + len[1] + len[2];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
if (i == j)
continue;
for (int p = 1; p <= tot; p++) {
f[i][j][p] = true;
for (int l = 1, r = p; l <= len[i] && r <= len[j]; l++, r++)
if (s[i][l] != s[j][r] && s[i][l] != '?' && s[j][r] != '?') {
f[i][j][p] = false;
break;
}
}
}
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
if (i == j)
continue;
int k = 3 - i - j;
for (int l = 1; l <= tot; l++) {
if (!f[j][i][l])
continue;
for (int r = 1; r <= tot; r++) {
if (!f[k][j][r])
continue;
int t = l + r - 1;
if (!f[k][i][t])
continue;
ans = min(ans,
t - 1 + max(len[k], max(len[j] - r + 1, len[i] - t + 1)));
}
}
}
printf("%d", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxN = 6005;
int ans, tot;
int len[3];
bool f[3][3][maxN + 1];
char s[3][maxN + 1];
int main() {
for (int i = 0; i < 3; i++)
scanf("%s", s[i] + 1), len[i] = strlen(s[i] + 1);
tot = ans = len[0] + len[1] + len[2];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
if (i == j)
continue;
for (int p = 1; p <= tot; p++) {
f[i][j][p] = true;
for (int l = 1, r = p; l <= len[i] && r <= len[j]; l++, r++)
if (s[i][l] != s[j][r] && s[i][l] != '?' && s[j][r] != '?') {
f[i][j][p] = false;
break;
}
}
}
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) {
if (i == j)
continue;
int k = 3 - i - j;
for (int l = 1; l <= tot; l++) {
if (!f[j][i][l])
continue;
for (int r = 1; r <= tot; r++) {
if (!f[k][j][r])
continue;
int t = l + r - 1;
if (!f[k][i][t])
continue;
ans = min(ans,
t - 1 + max(len[k], max(len[j] - r + 1, len[i] - t + 1)));
}
}
}
printf("%d", ans);
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02745 | C++ | Runtime Error | #include <iostream>
using namespace std;
int ab[10000], bc[10000], ac[10000], ans = 6000, na, nb, nc, L, R;
string a, b, c;
bool ch(char a, char b) { return (a == b || a == '?' || b == '?'); }
int main(void) {
cin >> a >> b >> c;
na = a.size();
nb = b.size();
nc = c.size();
for (int i = 0; i < na; i++) {
for (int j = 0; j < nb; j++) {
if (!ch(a[i], b[j]))
ab[i - j + 5000] = 1;
}
}
for (int i = 0; i < na; i++) {
for (int j = 0; j < nc; j++) {
if (!ch(a[i], c[j]))
ac[i - j + 5000] = 1;
}
}
for (int i = 0; i < nb; i++) {
for (int j = 0; j < nc; j++) {
if (!ch(b[i], c[j]))
bc[i - j + 5000] = 1;
}
}
for (int i = -4000; i <= 4000; i++) {
for (int j = -4000; j <= 4000; j++) {
if (ab[i + 5000] == 0 && bc[i + 5000] == 0 && ac[j - i + 5000] == 0) {
L = min(0, min(i, j));
R = max(na, max(i + nb, j + nc));
// cout<<ans<<" "<<R<<L<<endl;
ans = min(ans, R - L);
}
}
}
cout << ans << endl;
}
| #include <iostream>
using namespace std;
int ab[10000], bc[10000], ac[10000], ans = 6000, na, nb, nc, L, R;
string a, b, c;
bool ch(char a, char b) { return (a == b || a == '?' || b == '?'); }
int main(void) {
cin >> a >> b >> c;
na = a.size();
nb = b.size();
nc = c.size();
for (int i = 0; i < na; i++) {
for (int j = 0; j < nb; j++) {
if (!ch(a[i], b[j]))
ab[i - j + 5000] = 1;
}
}
for (int i = 0; i < na; i++) {
for (int j = 0; j < nc; j++) {
if (!ch(a[i], c[j]))
ac[i - j + 5000] = 1;
}
}
for (int i = 0; i < nb; i++) {
for (int j = 0; j < nc; j++) {
if (!ch(b[i], c[j]))
bc[i - j + 5000] = 1;
}
}
for (int i = -4000; i <= 4000; i++) {
for (int j = -4000; j <= 4000; j++) {
if (ab[i + 5000] == 0 && ac[j + 5000] == 0 && bc[j - i + 5000] == 0) {
L = min(0, min(i, j));
R = max(na, max(i + nb, j + nc));
// cout<<ans<<" "<<R<<L<<endl;
ans = min(ans, R - L);
}
}
}
cout << ans << endl;
}
| replace | 30 | 31 | 30 | 31 | -11 | |
p02745 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int ok[6][4002]; // 0:(a,b),1:(b,a),2:(a,c),3:(c,a),4:(b,c),5:(c,b)
void CompStr(string a, string b, int i) {
rep(j, a.size()) for (int k = j; k < a.size(); k++) {
if ((a.at(k) != '?') && (b.at(k - j) != '?') && (a.at(k) != b.at(k - j))) {
ok[i][j] = 0;
break;
}
}
}
int minLen(int ab, int bc, int ac, int as, int bs, int cs) {
int min = as + bs + cs;
rep(i, as + 1) rep(j, max(bs + 1, as - i + 1)) {
if ((ok[ab][i] == 1) && (ok[bc][j] == 1) && (ok[ac][i + j] == 1)) {
int len =
max(max(as, i + bs),
i + j + cs); // calculate the length of the corresponding string
if (min > len)
min = len;
}
}
return min;
}
int main() {
string a, b, c;
int as, bs, cs;
cin >> a >> b >> c;
as = a.size();
bs = b.size();
cs = c.size();
rep(i, 6) rep(j, 4002) ok[i][j] = 1;
CompStr(a, b, 0);
CompStr(b, a, 1);
CompStr(a, c, 2);
CompStr(c, a, 3);
CompStr(b, c, 4);
CompStr(c, b, 5);
int min = as + bs + cs;
int minl;
// 0:(a,b),1:(b,a),2:(a,c),3:(c,a),4:(b,c),5:(c,b)
minl = minLen(0, 4, 2, as, bs, cs);
if (min > minl)
min = minl; // abc
minl = minLen(2, 5, 0, as, cs, bs);
if (min > minl)
min = minl; // acb
minl = minLen(1, 2, 4, bs, as, cs);
if (min > minl)
min = minl; // bac
minl = minLen(4, 3, 1, bs, cs, as);
if (min > minl)
min = minl; // bca
minl = minLen(3, 0, 5, cs, as, bs);
if (min > minl)
min = minl; // cab
minl = minLen(5, 1, 3, cs, bs, as);
if (min > minl)
min = minl; // cba
cout << min << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int ok[6][4002]; // 0:(a,b),1:(b,a),2:(a,c),3:(c,a),4:(b,c),5:(c,b)
void CompStr(string a, string b, int i) {
rep(j, a.size()) for (int k = j; k < min(a.size(), b.size() + j); k++) {
if ((a.at(k) != '?') && (b.at(k - j) != '?') && (a.at(k) != b.at(k - j))) {
ok[i][j] = 0;
break;
}
}
}
int minLen(int ab, int bc, int ac, int as, int bs, int cs) {
int min = as + bs + cs;
rep(i, as + 1) rep(j, max(bs + 1, as - i + 1)) {
if ((ok[ab][i] == 1) && (ok[bc][j] == 1) && (ok[ac][i + j] == 1)) {
int len =
max(max(as, i + bs),
i + j + cs); // calculate the length of the corresponding string
if (min > len)
min = len;
}
}
return min;
}
int main() {
string a, b, c;
int as, bs, cs;
cin >> a >> b >> c;
as = a.size();
bs = b.size();
cs = c.size();
rep(i, 6) rep(j, 4002) ok[i][j] = 1;
CompStr(a, b, 0);
CompStr(b, a, 1);
CompStr(a, c, 2);
CompStr(c, a, 3);
CompStr(b, c, 4);
CompStr(c, b, 5);
int min = as + bs + cs;
int minl;
// 0:(a,b),1:(b,a),2:(a,c),3:(c,a),4:(b,c),5:(c,b)
minl = minLen(0, 4, 2, as, bs, cs);
if (min > minl)
min = minl; // abc
minl = minLen(2, 5, 0, as, cs, bs);
if (min > minl)
min = minl; // acb
minl = minLen(1, 2, 4, bs, as, cs);
if (min > minl)
min = minl; // bac
minl = minLen(4, 3, 1, bs, cs, as);
if (min > minl)
min = minl; // bca
minl = minLen(3, 0, 5, cs, as, bs);
if (min > minl)
min = minl; // cab
minl = minLen(5, 1, 3, cs, bs, as);
if (min > minl)
min = minl; // cba
cout << min << endl;
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02745 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
int main() {
// your code goes here
char a[5][2005];
ll l[5], r[5] = {0}, ans = 100000000;
bool z[5015][5][5] = {0};
cin >> a[0] >> a[1] >> a[2];
rep(i, 0, 2) l[i] = strlen(a[i]);
rep(i, 0, 2) {
rep(j, 0, 2) {
if (i == j)
continue;
rep(k, 0, l[i] - 1) {
bool memo = true;
rep(s, 0, min(l[j] - 1ll, l[i] - k - 1)) {
if (a[i][k + s] == '?')
continue;
if (a[j][s] == '?')
continue;
if (a[i][k + s] != a[j][s])
memo = false;
}
if (memo)
z[k][i][j] = true;
// if(memo) cout << i << " " << j << " " << k << endl;
}
rep(k, l[i], 5000) z[k][i][j] = true;
}
}
vector<ll> p;
p.push_back(0);
p.push_back(1);
p.push_back(2);
do {
rep(i, 0, l[p[0]]) {
rep(j, 0, 2 * l[p[1]]) {
if (z[i][p[0]][p[1]] && z[j][p[1]][p[2]] && z[i + j][p[0]][p[2]]) {
ll mm = max(l[p[0]], max(i + l[p[1]], i + j + l[p[2]]));
ans = min(ans, mm);
}
}
}
} while (next_permutation(p.begin(), p.end()));
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define repr(i, a, b) for (ll i = a; i >= b; i--)
int main() {
// your code goes here
char a[5][2005];
ll l[5], r[5] = {0}, ans = 100000000;
bool z[5015][5][5] = {0};
cin >> a[0] >> a[1] >> a[2];
rep(i, 0, 2) l[i] = strlen(a[i]);
rep(i, 0, 2) {
rep(j, 0, 2) {
if (i == j)
continue;
rep(k, 0, l[i] - 1) {
bool memo = true;
rep(s, 0, min(l[j] - 1ll, l[i] - k - 1)) {
if (a[i][k + s] == '?')
continue;
if (a[j][s] == '?')
continue;
if (a[i][k + s] != a[j][s])
memo = false;
}
if (memo)
z[k][i][j] = true;
// if(memo) cout << i << " " << j << " " << k << endl;
}
rep(k, l[i], 5000) z[k][i][j] = true;
}
}
vector<ll> p;
p.push_back(0);
p.push_back(1);
p.push_back(2);
do {
rep(i, 0, 3 * l[p[0]]) {
rep(j, 0, min(3ll * l[p[1]], 4500ll - i)) {
if (z[i][p[0]][p[1]] && z[j][p[1]][p[2]] && z[i + j][p[0]][p[2]]) {
ll mm = max(l[p[0]], max(i + l[p[1]], i + j + l[p[2]]));
ans = min(ans, mm);
}
}
}
} while (next_permutation(p.begin(), p.end()));
cout << ans << endl;
return 0;
} | replace | 39 | 41 | 39 | 41 | 0 | |
p02745 | C++ | Runtime Error | /* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) \
rep(i, (v).size() - 1) cout << (v)[i] << ' '; \
cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " \
<< (z) << '\n'
#define dbg(v) \
for (size_t _ = 0; _ < v.size(); ++_) { \
cerr << #v << "[" << _ << "] : " << v[_] << '\n'; \
}
// constant
const int INF = (1 << 30) - 1;
const int64 INF64 = (1LL << 62) - 1;
template <typename T> T gcd(T a, T b) {
if (a < b)
return gcd(b, a);
T r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
template <typename T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }
template <typename T> bool chmin(T &a, const T &b) {
if (a > b)
return a = b, true;
else
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b)
return a = b, true;
else
return false;
}
// End of template.
bool _ab[8080], _ac[8080], _bc[8080];
bool *ab = _ab + 4040, *ac = _ac + 4040, *bc = _bc + 4040;
string _;
bool match(const string &a, const string &b) {
// assert(a.size() == b.size())
rep(i, a.size()) {
if (a[i] != '?' && b[i] != '?' && a[i] != b[i])
return false;
}
return true;
}
void calc(bool *res, const string &a, const string &b) {
const string s = _ + a + _;
for (int i = -(int)b.size(); i <= (int)a.size(); ++i) {
res[i] = match(s.substr(2000 + i, b.size()), b);
}
}
int main() {
cout << fixed << setprecision(15);
ios::sync_with_stdio(false);
cin.tie(nullptr);
// cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out
// で入力すること
_ = "??????????????????????????????????????????????????";
_ = _ + _ + _ + _ + _ + _ + _ + _ + _ + _;
_ = _ + _ + _ + _; // "?" * 2000
string a, b, c;
cin >> a >> b >> c;
int as = a.size(), bs = b.size(), cs = c.size();
memset(_ab, 1, sizeof(_ab));
memset(_ac, 1, sizeof(_ac));
memset(_bc, 1, sizeof(_bc));
calc(ab, a, b);
calc(ac, a, c);
calc(bc, b, c);
int ans = INF;
for (int B = -4000; B <= 4000; ++B)
if (ab[B]) {
for (int C = -B - cs; C <= min(4000, max(as, bs + B)); ++C) {
if (ac[C] && bc[C - B]) {
int m = min({0, B, C});
int M = max({as, B + bs, C + cs});
chmin(ans, M - m);
}
}
}
print(ans);
return 0;
}
| /* _
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||_ \
| | \\\ - /'| | |
| \_| `\`---'// |_/ |
\ .-\__ `-. -'__/-. /
___`. .' /--.--\ `. .'___
."" '< `.___\_<|>_/___.' _> \"".
| | : `- \`. ;`. _/; .'/ / .' ; |
\ \ `-. \_\_`. _.'_/_/ -' _.' /
===========`-.`___`-.__\ \___ /__.-'_.'_.-'================
Please give me AC.
*/
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) \
rep(i, (v).size() - 1) cout << (v)[i] << ' '; \
cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) \
cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " \
<< (z) << '\n'
#define dbg(v) \
for (size_t _ = 0; _ < v.size(); ++_) { \
cerr << #v << "[" << _ << "] : " << v[_] << '\n'; \
}
// constant
const int INF = (1 << 30) - 1;
const int64 INF64 = (1LL << 62) - 1;
template <typename T> T gcd(T a, T b) {
if (a < b)
return gcd(b, a);
T r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
template <typename T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }
template <typename T> bool chmin(T &a, const T &b) {
if (a > b)
return a = b, true;
else
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b)
return a = b, true;
else
return false;
}
// End of template.
bool _ab[8080], _ac[8080], _bc[8080];
bool *ab = _ab + 4040, *ac = _ac + 4040, *bc = _bc + 4040;
string _;
bool match(const string &a, const string &b) {
// assert(a.size() == b.size())
rep(i, a.size()) {
if (a[i] != '?' && b[i] != '?' && a[i] != b[i])
return false;
}
return true;
}
void calc(bool *res, const string &a, const string &b) {
const string s = _ + a + _;
for (int i = -(int)b.size(); i <= (int)a.size(); ++i) {
res[i] = match(s.substr(2000 + i, b.size()), b);
}
}
int main() {
cout << fixed << setprecision(15);
ios::sync_with_stdio(false);
cin.tie(nullptr);
// cin.read(buf, sizeof buf); // 注意: ./a.out < in か pbp | ./a.out
// で入力すること
_ = "??????????????????????????????????????????????????";
_ = _ + _ + _ + _ + _ + _ + _ + _ + _ + _;
_ = _ + _ + _ + _; // "?" * 2000
string a, b, c;
cin >> a >> b >> c;
int as = a.size(), bs = b.size(), cs = c.size();
memset(_ab, 1, sizeof(_ab));
memset(_ac, 1, sizeof(_ac));
memset(_bc, 1, sizeof(_bc));
calc(ab, a, b);
calc(ac, a, c);
calc(bc, b, c);
int ans = INF;
for (int B = -4000; B <= 4000; ++B)
if (ab[B]) {
for (int C = -4000; C <= 4000; ++C) {
if (ac[C] && -4000 <= C - B && C - B <= 4000 && bc[C - B]) {
int m = min({0, B, C});
int M = max({as, B + bs, C + cs});
chmin(ans, M - m);
}
}
}
print(ans);
return 0;
}
| replace | 151 | 153 | 151 | 153 | 0 | |
p02745 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
vector<string> x;
void gen(string a, string b) {
int n = a.size();
int m = b.size();
for (int i = 0; i <= n; i++) {
bool ok = 1;
for (int j = 0; j < m; j++) {
if (i + j >= n || a[i + j] == '?' || b[j] == '?')
continue;
if (a[i + j] != b[j]) {
ok = 0;
break;
}
}
if (ok) {
string t = a;
for (int j = 0; j < m; j++) {
if (i + j >= (int)t.size())
t += '?';
if (t[i + j] == '?')
t[i + j] = b[j];
}
x.push_back(t);
}
}
}
string match(string a, string b) {
int n = a.size();
int m = b.size();
for (int i = 0; i <= n; i++) {
bool ok = 1;
for (int j = 0; j < m; j++) {
if (i + j >= n || a[i + j] == '?' || b[j] == '?')
continue;
if (a[i + j] != b[j]) {
ok = 0;
break;
}
}
if (ok) {
for (int j = 0; j < m; j++) {
if (i + j >= (int)a.size())
a += '?';
if (a[i + j] == '?')
a[i + j] = b[j];
}
break;
}
}
return a;
}
int main() {
ios::sync_with_stdio(false);
vector<string> v(3);
for (int i = 0; i < 3; i++)
cin >> v[i];
sort(v.begin(), v.end());
int res = v[0].size() + v[1].size() + v[2].size();
do {
vector<string> t = v;
gen(t[0], t[1]);
for (auto a : x)
res = min(res, (int)match(a, t[2]).size());
x.clear();
} while (next_permutation(v.begin(), v.end()));
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
vector<string> x;
void gen(string a, string b) {
int n = a.size();
int m = b.size();
for (int i = 0; i <= n; i++) {
bool ok = 1;
for (int j = 0; j < m; j++) {
if (i + j >= n || a[i + j] == '?' || b[j] == '?')
continue;
if (a[i + j] != b[j]) {
ok = 0;
break;
}
}
if (ok) {
string t = a;
for (int j = 0; j < m; j++) {
if (i + j >= (int)t.size())
t += '?';
if (t[i + j] == '?')
t[i + j] = b[j];
}
x.push_back(t);
}
}
}
string match(string a, string b) {
int n = a.size();
int m = b.size();
for (int i = 0; i <= n; i++) {
bool ok = 1;
for (int j = 0; j < m; j++) {
if (i + j >= n || a[i + j] == '?' || b[j] == '?')
continue;
if (a[i + j] != b[j]) {
ok = 0;
break;
}
}
if (ok) {
for (int j = 0; j < m; j++) {
if (i + j >= (int)a.size())
a += '?';
if (a[i + j] == '?')
a[i + j] = b[j];
}
break;
}
}
return a;
}
int main() {
ios::sync_with_stdio(false);
vector<string> v(3);
for (int i = 0; i < 3; i++)
cin >> v[i];
sort(v.begin(), v.end());
int res = v[0].size() + v[1].size() + v[2].size();
do {
vector<string> t = v;
gen(t[0], t[1]);
for (auto a : x)
if ((int)a.size() < res)
res = min(res, (int)match(a, t[2]).size());
x.clear();
} while (next_permutation(v.begin(), v.end()));
cout << res << endl;
return 0;
}
| replace | 69 | 70 | 69 | 71 | TLE | |
p02745 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
std::string str_join(const std::string &s1, const std::string &s2) {
std::string r{s1};
auto n = s1.size();
for (auto i = 0ul; i < n; ++i) {
if (s2[i] == '?') {
continue;
}
if (r[i] == '?') {
r[i] = s2[i];
continue;
}
if (s1[i] != s2[i]) {
return std::string{};
}
}
return r;
}
auto slide_join(const std::string &s1, const std::string &s2,
const std::string &s3, std::size_t min) {
auto s1_s = s1.size();
auto s2_s = s2.size();
auto s3_s = s3.size();
for (auto i = 0; i < s2_s; ++i) {
if (i + s1_s > min) {
break;
}
auto n = std::min(s1_s, s2_s - i);
auto t = str_join(s1.substr(0, n), s2.substr(i, n));
if (t.empty()) {
continue;
}
std::string r{};
if (i) {
r += s2.substr(0, i);
}
r += t;
if (n < s1_s) {
r += s1.substr(n);
} else if (i + n < s2_s) {
r += s2.substr(i + n);
}
auto r_s = r.size();
for (auto j = 0; j < r_s; ++j) {
if (j + s3_s > min) {
break;
}
auto nn = std::min(s3_s, r_s - j);
auto tt = str_join(s3.substr(0, nn), r.substr(j, nn));
if (tt.empty()) {
continue;
}
std::string rr{};
if (j) {
rr += r.substr(0, j);
}
rr += tt;
if (nn < s3_s) {
rr += s3.substr(nn);
} else if (j + nn < r_s) {
rr += r.substr(j + nn);
}
if (rr.size() < min) {
min = rr.size();
break;
}
} // for j
} // for i
return min;
}
int main() {
std::string a, b, c;
std::cin >> a >> b >> c;
auto min = a.size() + b.size() + c.size();
min = slide_join(a, b, c, min);
min = slide_join(b, a, c, min);
min = slide_join(b, c, a, min);
min = slide_join(c, b, a, min);
min = slide_join(c, a, b, min);
min = slide_join(a, c, b, min);
std::cout << min << std::endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
std::string str_join(const std::string &s1, const std::string &s2) {
std::string r{s1};
auto n = s1.size();
for (auto i = 0ul; i < n; ++i) {
if (s2[i] == '?') {
continue;
}
if (r[i] == '?') {
r[i] = s2[i];
continue;
}
if (s1[i] != s2[i]) {
return std::string{};
}
}
return r;
}
auto slide_join(const std::string &s1, const std::string &s2,
const std::string &s3, std::size_t min) {
auto s1_s = s1.size();
auto s2_s = s2.size();
auto s3_s = s3.size();
for (auto i = 0; i < s2_s; ++i) {
if (i + s1_s > min) {
break;
}
auto n = std::min(s1_s, s2_s - i);
auto t = str_join(s1.substr(0, n), s2.substr(i, n));
if (t.empty()) {
continue;
}
std::string r{};
if (i) {
r += s2.substr(0, i);
}
r += t;
if (n < s1_s) {
r += s1.substr(n);
} else if (i + n < s2_s) {
r += s2.substr(i + n);
}
auto r_s = r.size();
for (auto j = i; j < r_s; ++j) {
if (j + s3_s > min) {
break;
}
auto nn = std::min(s3_s, r_s - j);
auto tt = str_join(s3.substr(0, nn), r.substr(j, nn));
if (tt.empty()) {
continue;
}
std::string rr{};
if (j) {
rr += r.substr(0, j);
}
rr += tt;
if (nn < s3_s) {
rr += s3.substr(nn);
} else if (j + nn < r_s) {
rr += r.substr(j + nn);
}
if (rr.size() < min) {
min = rr.size();
break;
}
} // for j
} // for i
return min;
}
int main() {
std::string a, b, c;
std::cin >> a >> b >> c;
auto min = a.size() + b.size() + c.size();
min = slide_join(a, b, c, min);
min = slide_join(b, a, c, min);
min = slide_join(b, c, a, min);
min = slide_join(c, b, a, min);
min = slide_join(c, a, b, min);
min = slide_join(a, c, b, min);
std::cout << min << std::endl;
return 0;
} | replace | 55 | 56 | 55 | 56 | TLE | |
p02745 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;
// @@ !! LIM(debug)
// --> f:<< debug
// ---- inserted function << from util.cc
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T1, typename T2, typename T3>
ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &t) {
os << "(" << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ")";
return os;
}
template <typename T1, typename T2, typename T3, typename T4>
ostream &operator<<(ostream &os, const tuple<T1, T2, T3, T4> &t) {
os << "(" << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ", "
<< get<3>(t) << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '[';
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
os << ']';
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << '{';
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
os << '}';
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) {
os << '{';
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
os << '}';
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
os << '[';
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it != mp.begin())
os << ", ";
os << it->first << ": " << it->second;
}
os << ']';
return os;
}
template <typename T, typename T2, typename T3>
ostream &operator<<(ostream &os, const priority_queue<T, T2, T3> &orig) {
priority_queue<T, T2, T3> pq(orig);
bool first = true;
os << '[';
while (!pq.empty()) {
T x = pq.top();
pq.pop();
if (!first)
os << ", ";
os << x;
first = false;
}
return os << ']';
}
// ---- end <<
// ---- inserted library file debug.cc
template <class... Args> string dbgFormat(const char *fmt, Args... args) {
size_t len = snprintf(nullptr, 0, fmt, args...);
char buf[len + 1];
snprintf(buf, len + 1, fmt, args...);
return string(buf);
}
template <class Head> void dbgLog(Head &&head) { cerr << head << endl; }
template <class Head, class... Tail> void dbgLog(Head &&head, Tail &&...tail) {
cerr << head << " ";
dbgLog(forward<Tail>(tail)...);
}
#if DEBUG
#define DLOG(...) dbgLog(__VA_ARGS__)
#define DFMT(...) cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)
#else
#define DLOG(...)
#define DFMT(...)
#define DCALL(func, ...)
#endif
// ---- end debug.cc
// @@ !! LIM -- end mark --
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << setprecision(20);
string a, b, c;
cin >> a >> b >> c;
ll na = a.size(), nb = b.size(), nc = c.size();
ll shift = 2 * (na + nb + nc);
vector<bool> vab(2 * shift, true), vbc(2 * shift, true), vac(2 * shift, true);
auto fill = [&](auto &vec, string x, string y) -> void {
for (ll i = 0; i < (ll)x.size(); i++) {
for (ll j = 0; j < (ll)y.size(); j++) {
if (!(x.at(i) == y.at(j) || x.at(i) == '?' || y.at(i) == '?')) {
vec.at(shift + i - j) = false;
}
}
}
};
fill(vab, a, b);
fill(vac, a, c);
fill(vbc, b, c);
ll ans = LLONG_MAX;
for (ll i = -(nb + nc); i <= na + max(nb, nc); i++) {
if (!vab.at(shift + i))
continue;
for (ll j = -(nb + nc); j <= na + max(nb, nc); j++) {
if (!vac.at(shift + j))
continue;
if (!vbc.at(shift + (j - i)))
continue;
ll len = max(na, max(i + nb, j + nc)) - min(0LL, min(i, j));
DLOG("i", i, "j", j, "len", len);
ans = min(ans, len);
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;
// @@ !! LIM(debug)
// --> f:<< debug
// ---- inserted function << from util.cc
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T1, typename T2, typename T3>
ostream &operator<<(ostream &os, const tuple<T1, T2, T3> &t) {
os << "(" << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ")";
return os;
}
template <typename T1, typename T2, typename T3, typename T4>
ostream &operator<<(ostream &os, const tuple<T1, T2, T3, T4> &t) {
os << "(" << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ", "
<< get<3>(t) << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '[';
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
os << ']';
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << '{';
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
os << '}';
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) {
os << '{';
for (auto it = v.begin(); it != v.end(); it++) {
if (it != v.begin())
os << ", ";
os << *it;
}
os << '}';
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
os << '[';
for (auto it = mp.begin(); it != mp.end(); it++) {
if (it != mp.begin())
os << ", ";
os << it->first << ": " << it->second;
}
os << ']';
return os;
}
template <typename T, typename T2, typename T3>
ostream &operator<<(ostream &os, const priority_queue<T, T2, T3> &orig) {
priority_queue<T, T2, T3> pq(orig);
bool first = true;
os << '[';
while (!pq.empty()) {
T x = pq.top();
pq.pop();
if (!first)
os << ", ";
os << x;
first = false;
}
return os << ']';
}
// ---- end <<
// ---- inserted library file debug.cc
template <class... Args> string dbgFormat(const char *fmt, Args... args) {
size_t len = snprintf(nullptr, 0, fmt, args...);
char buf[len + 1];
snprintf(buf, len + 1, fmt, args...);
return string(buf);
}
template <class Head> void dbgLog(Head &&head) { cerr << head << endl; }
template <class Head, class... Tail> void dbgLog(Head &&head, Tail &&...tail) {
cerr << head << " ";
dbgLog(forward<Tail>(tail)...);
}
#if DEBUG
#define DLOG(...) dbgLog(__VA_ARGS__)
#define DFMT(...) cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)
#else
#define DLOG(...)
#define DFMT(...)
#define DCALL(func, ...)
#endif
// ---- end debug.cc
// @@ !! LIM -- end mark --
int main(int argc, char *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << setprecision(20);
string a, b, c;
cin >> a >> b >> c;
ll na = a.size(), nb = b.size(), nc = c.size();
ll shift = 2 * (na + nb + nc);
vector<bool> vab(2 * shift, true), vbc(2 * shift, true), vac(2 * shift, true);
auto fill = [&](auto &vec, string x, string y) -> void {
for (ll i = 0; i < (ll)x.size(); i++) {
for (ll j = 0; j < (ll)y.size(); j++) {
if (!(x.at(i) == y.at(j) || x.at(i) == '?' || y.at(j) == '?')) {
vec.at(shift + i - j) = false;
}
}
}
};
fill(vab, a, b);
fill(vac, a, c);
fill(vbc, b, c);
ll ans = LLONG_MAX;
for (ll i = -(nb + nc); i <= na + max(nb, nc); i++) {
if (!vab.at(shift + i))
continue;
for (ll j = -(nb + nc); j <= na + max(nb, nc); j++) {
if (!vac.at(shift + j))
continue;
if (!vbc.at(shift + (j - i)))
continue;
ll len = max(na, max(i + nb, j + nc)) - min(0LL, min(i, j));
DLOG("i", i, "j", j, "len", len);
ans = min(ans, len);
}
}
cout << ans << endl;
return 0;
}
| replace | 133 | 134 | 133 | 134 | 0 | |
p02745 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#define maxn 2010
using namespace std;
char a[maxn], b[maxn], c[maxn];
bool ab[maxn + maxn + maxn + maxn + maxn], ac[5 * maxn], bc[5 * maxn];
int match(char a, char b) {
if (a == b || a == '?' || b == '?')
return 1;
return 0;
}
int main() {
int i, j, A, B, C, L, R, ans = 5 * maxn;
scanf("%s%s%s", a, b, c);
A = strlen(a), B = strlen(b), C = strlen(c);
for (i = 0; i < A; i++)
for (j = 0; j < B; j++)
if (!match(a[i], b[j]))
ab[i - j + 2 * maxn] = 1;
for (i = 0; i < A; i++)
for (j = 0; j < C; j++)
if (!match(a[i], c[j]))
ac[i - j + 2 * maxn] = 1;
for (i = 0; i < B; i++)
for (j = 0; j < C; j++)
if (!match(b[i], c[j]))
bc[i - j + 2 * maxn] = 1;
for (i = -(B + C); i <= A + B + C; i++)
for (j = -(B + C); j <= A + B + C; j++)
if (!ab[i + 2 * maxn] && !ac[j + 2 * maxn] && !bc[j - i + 2 * maxn]) {
L = min(0, min(i, j)),
R = max(A, max(B + i, C + j)); // min(i,j)>0表示在内部匹配,故取0
ans = min(ans, R - L);
}
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#define maxn 2010
using namespace std;
char a[maxn], b[maxn], c[maxn];
bool ab[maxn + maxn + maxn + maxn + maxn], ac[5 * maxn], bc[5 * maxn];
int match(char a, char b) {
if (a == b || a == '?' || b == '?')
return 1;
return 0;
}
int main() {
int i, j, A, B, C, L, R, ans = 5 * maxn;
scanf("%s%s%s", a, b, c);
A = strlen(a), B = strlen(b), C = strlen(c);
for (i = 0; i < A; i++)
for (j = 0; j < B; j++)
if (!match(a[i], b[j]))
ab[i - j + 2 * maxn] = 1;
for (i = 0; i < A; i++)
for (j = 0; j < C; j++)
if (!match(a[i], c[j]))
ac[i - j + 2 * maxn] = 1;
for (i = 0; i < B; i++)
for (j = 0; j < C; j++)
if (!match(b[i], c[j]))
bc[i - j + 2 * maxn] = 1;
for (i = -(B + C); i <= B + C; i++)
for (j = -(B + C); j <= B + C; j++)
if (!ab[i + 2 * maxn] && !ac[j + 2 * maxn] && !bc[j - i + 2 * maxn]) {
L = min(0, min(i, j)),
R = max(A, max(B + i, C + j)); // min(i,j)>0表示在内部匹配,故取0
ans = min(ans, R - L);
}
printf("%d\n", ans);
return 0;
} | replace | 28 | 30 | 28 | 30 | 0 | |
p02745 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define rep_(i, a_, b_, a, b, ...) \
for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) \
for (int i = (b - 1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef long double ld;
bool match(char a, char b) { return (a == '?' || b == '?' || a == b); }
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string a, b, c;
cin >> a >> b >> c;
int A = a.length(), B = b.length(), C = c.length();
int m = 2000, M = 10000;
vector<bool> match_ab(6000), match_bc(6000), match_ca(6000);
rep(i, A) {
rep(j, B) {
if (!(match(a[i], b[j])))
match_ab[i - j + M] = true;
}
}
rep(i, B) {
rep(j, C) {
if (!(match(b[i], c[j])))
match_bc[i - j + M] = true;
}
}
rep(i, C) {
rep(j, A) {
if (!(match(c[i], a[j])))
match_ca[i - j + M] = true;
}
}
int ans = 3 * m;
rep(i, -2 * m, 2 * m + 1) {
rep(j, -2 * m, 2 * m + 1) {
if (!match_ab[i + M] && !match_bc[-i + j + M] && !match_ca[-j + M]) {
if (chmin(ans, max({A, i + B, j + C}) - min({0, i, j})))
eprintf("%d %d %d\n", ans, i, j);
}
}
}
cout << ans << "\n";
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define rep_(i, a_, b_, a, b, ...) \
for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) \
for (int i = (b - 1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef long double ld;
bool match(char a, char b) { return (a == '?' || b == '?' || a == b); }
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string a, b, c;
cin >> a >> b >> c;
int A = a.length(), B = b.length(), C = c.length();
int m = 2000, M = 10000;
vector<bool> match_ab(2 * M + 1), match_bc(2 * M + 1), match_ca(2 * M + 1);
rep(i, A) {
rep(j, B) {
if (!(match(a[i], b[j])))
match_ab[i - j + M] = true;
}
}
rep(i, B) {
rep(j, C) {
if (!(match(b[i], c[j])))
match_bc[i - j + M] = true;
}
}
rep(i, C) {
rep(j, A) {
if (!(match(c[i], a[j])))
match_ca[i - j + M] = true;
}
}
int ans = 3 * m;
rep(i, -2 * m, 2 * m + 1) {
rep(j, -2 * m, 2 * m + 1) {
if (!match_ab[i + M] && !match_bc[-i + j + M] && !match_ca[-j + M]) {
if (chmin(ans, max({A, i + B, j + C}) - min({0, i, j})))
eprintf("%d %d %d\n", ans, i, j);
}
}
}
cout << ans << "\n";
return 0;
} | replace | 66 | 67 | 66 | 67 | TLE | |
p02745 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#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> P;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on
#define M 2000
bool ab[10000], ac[100000], bc[100000];
bool match(char c1, char c2) { return (c1 == '?' || c2 == '?' || c1 == c2); }
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string a, b, c;
cin >> a >> b >> c;
int A = a.length();
int B = b.length();
int C = c.length();
REP(i, A) REP(j, B) if (!match(a[i], b[j])) ab[i - j + 50000] = true;
REP(i, A) REP(j, C) if (!match(a[i], c[j])) ac[i - j + 50000] = true;
REP(i, B) REP(j, C) if (!match(b[i], c[j])) bc[i - j + 50000] = true;
int ans = 3 * M;
for (int i = -2 * M; i <= 2 * M; i++) {
for (int j = -2 * M; j <= 2 * M; j++) {
if (!ab[i + 50000] && !ac[j + 50000] && !bc[j - i + 50000]) {
int L = min(0, min(i, j));
int R = max(A, max(B + i, C + j));
ans = min(ans, R - L);
}
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cassert>
#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> P;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on
#define M 2000
bool ab[100000], ac[100000], bc[100000];
bool match(char c1, char c2) { return (c1 == '?' || c2 == '?' || c1 == c2); }
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string a, b, c;
cin >> a >> b >> c;
int A = a.length();
int B = b.length();
int C = c.length();
REP(i, A) REP(j, B) if (!match(a[i], b[j])) ab[i - j + 50000] = true;
REP(i, A) REP(j, C) if (!match(a[i], c[j])) ac[i - j + 50000] = true;
REP(i, B) REP(j, C) if (!match(b[i], c[j])) bc[i - j + 50000] = true;
int ans = 3 * M;
for (int i = -2 * M; i <= 2 * M; i++) {
for (int j = -2 * M; j <= 2 * M; j++) {
if (!ab[i + 50000] && !ac[j + 50000] && !bc[j - i + 50000]) {
int L = min(0, min(i, j));
int R = max(A, max(B + i, C + j));
ans = min(ans, R - L);
}
}
}
cout << ans << endl;
return 0;
}
| replace | 50 | 51 | 50 | 51 | TLE | |
p02745 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#define _USE_MATH_DEFINES
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;
#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll>
#define VVI vector<vector<ll>>
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i, n) for (ll i = 0, _n = (n); (i) < (ll)_n; ++i)
#define REPR(i, n) for (ll i = (ll)(n)-1; 0 <= (i); --i)
#define RANGE(i, a, b) for (ll i = (ll)a, _b = (ll)(b); (i) < _b; ++i)
#define RANGER(i, a, b) for (ll i = (ll)(b)-1, _a = (ll)(a); (_a) <= i; --i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) \
(((b - a) * (double)rand() / RAND_MAX) + a) // [a, b)
#define UNIFORM_LL(a, b) (ll) UNIFORM_DOUBLE(a, b) // [a, b)
#define IN(v, lo, hi) ((lo) <= (v) && (v) < (hi))
#define DD(v) cout << #v << ": " << v << endl
#define FI first
#define SE second
template <typename T0, typename T1>
std::ostream &operator<<(std::ostream &os, const map<T0, T1> &v) {
for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) {
os << p->first << ": " << p->second << " ";
}
return os;
}
template <typename T0, typename T1>
std::ostream &operator<<(std::ostream &os, const pair<T0, T1> &v) {
os << v.first << ": " << v.second << " ";
return os;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << " ";
}
return os;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const set<T> &v) {
vector<T> tmp(v.begin(), v.end());
os << tmp;
return os;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const deque<T> &v) {
vector<T> tmp(v.begin(), v.end());
os << tmp;
return os;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const vector<vector<T>> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << endl;
}
return os;
}
template <typename T> void maxUpdate(T &a, T b) { a = max(a, b); }
template <typename T> void minUpdate(T &a, T b) { a = min(a, b); }
#define MOD 1000000007LL
#define INF (1LL << 60)
bool match(char a, char b) { return a == '?' || b == '?' || a == b; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string a, b, c;
while (cin >> a >> b >> c) {
ll A = a.size();
ll B = b.size();
ll C = c.size();
// exist -> aに対してbを右方向にoffsetずらしたときに置けないときはNG
ll M = 3000;
ll offset = M / 2;
vector<bool> ab(M), ac(M), bc(M);
REP(ai, A) REP(bi, B) if (!match(a[ai], b[bi])) ab[ai - bi + offset] = 1;
REP(ai, A) REP(ci, C) if (!match(a[ai], c[ci])) ac[ai - ci + offset] = 1;
REP(bi, B) REP(ci, C) if (!match(b[bi], c[ci])) bc[bi - ci + offset] = 1;
ll ans = 1LL << 60;
RANGE(bi, -B - C, A + C + 1) RANGE(ci, -B - C, A + B + 1) {
ll abi = bi + offset;
ll aci = ci + offset;
ll bci = ci - bi + offset;
bool ok = IN(abi, 0, M) && !ab[abi] && IN(aci, 0, M) && !ac[aci] &&
IN(bci, 0, M) && !bc[bci];
if (ok) {
// cout<<bi<<" "<<ci<<endl;
ll L = min({0LL, bi, ci});
ll R = max({A, bi + B, ci + C});
minUpdate(ans, R - L);
}
}
cout << ans << endl;
// break;
}
return 0;
}
| #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#define _USE_MATH_DEFINES
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;
#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll>
#define VVI vector<vector<ll>>
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i, n) for (ll i = 0, _n = (n); (i) < (ll)_n; ++i)
#define REPR(i, n) for (ll i = (ll)(n)-1; 0 <= (i); --i)
#define RANGE(i, a, b) for (ll i = (ll)a, _b = (ll)(b); (i) < _b; ++i)
#define RANGER(i, a, b) for (ll i = (ll)(b)-1, _a = (ll)(a); (_a) <= i; --i)
#define FOR(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) \
(((b - a) * (double)rand() / RAND_MAX) + a) // [a, b)
#define UNIFORM_LL(a, b) (ll) UNIFORM_DOUBLE(a, b) // [a, b)
#define IN(v, lo, hi) ((lo) <= (v) && (v) < (hi))
#define DD(v) cout << #v << ": " << v << endl
#define FI first
#define SE second
template <typename T0, typename T1>
std::ostream &operator<<(std::ostream &os, const map<T0, T1> &v) {
for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) {
os << p->first << ": " << p->second << " ";
}
return os;
}
template <typename T0, typename T1>
std::ostream &operator<<(std::ostream &os, const pair<T0, T1> &v) {
os << v.first << ": " << v.second << " ";
return os;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << " ";
}
return os;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const set<T> &v) {
vector<T> tmp(v.begin(), v.end());
os << tmp;
return os;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const deque<T> &v) {
vector<T> tmp(v.begin(), v.end());
os << tmp;
return os;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const vector<vector<T>> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << endl;
}
return os;
}
template <typename T> void maxUpdate(T &a, T b) { a = max(a, b); }
template <typename T> void minUpdate(T &a, T b) { a = min(a, b); }
#define MOD 1000000007LL
#define INF (1LL << 60)
bool match(char a, char b) { return a == '?' || b == '?' || a == b; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string a, b, c;
while (cin >> a >> b >> c) {
ll A = a.size();
ll B = b.size();
ll C = c.size();
// exist -> aに対してbを右方向にoffsetずらしたときに置けないときはNG
ll M = 50000;
ll offset = M / 2;
vector<bool> ab(M), ac(M), bc(M);
REP(ai, A) REP(bi, B) if (!match(a[ai], b[bi])) ab[ai - bi + offset] = 1;
REP(ai, A) REP(ci, C) if (!match(a[ai], c[ci])) ac[ai - ci + offset] = 1;
REP(bi, B) REP(ci, C) if (!match(b[bi], c[ci])) bc[bi - ci + offset] = 1;
ll ans = 1LL << 60;
RANGE(bi, -B - C, A + C + 1) RANGE(ci, -B - C, A + B + 1) {
ll abi = bi + offset;
ll aci = ci + offset;
ll bci = ci - bi + offset;
bool ok = IN(abi, 0, M) && !ab[abi] && IN(aci, 0, M) && !ac[aci] &&
IN(bci, 0, M) && !bc[bci];
if (ok) {
// cout<<bi<<" "<<ci<<endl;
ll L = min({0LL, bi, ci});
ll R = max({A, bi + B, ci + C});
minUpdate(ans, R - L);
}
}
cout << ans << endl;
// break;
}
return 0;
}
| replace | 104 | 105 | 104 | 105 | 0 | |
p02745 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#define lson rt << 1
#define rson rt << 1 | 1
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int maxn = 43 + 10;
char a[maxn], b[maxn], c[maxn];
bool xab[maxn], xba[maxn], xbc[maxn], xac[maxn], xcb[maxn];
int main() {
cin >> a >> b >> c;
int lena = strlen(a), lenb = strlen(b), lenc = strlen(c);
int len = max(max(strlen(a), strlen(b)), strlen(c));
for (int i = -len; i <= len; i++) {
int flag = 0;
for (int j = 0; j < lena; j++) {
if (0 <= j + i && j + i < lenb) {
if (a[j] != '?' && a[j] != b[i + j] && b[i + j] != '?') {
flag = 1;
break;
}
}
}
if (flag == 0) {
xab[i + len] = 1;
}
}
for (int i = -len; i <= len; i++) {
int flag = 0;
for (int j = 0; j < lenb; j++) {
if (0 <= j + i && j + i < lenc) {
if (b[j] != '?' && b[j] != c[i + j] && c[i + j] != '?') {
flag = 1;
break;
}
}
}
if (flag == 0) {
xbc[i + len] = 1;
}
}
for (int i = -len; i <= len; i++) {
int flag = 0;
for (int j = 0; j < lena; j++) {
if (0 <= j + i && j + i < lenc) {
if (a[j] != '?' && a[j] != c[i + j] && c[i + j] != '?') {
flag = 1;
break;
}
}
}
if (flag == 0)
xac[i + len] = 1;
}
int ans = 1e9;
for (int i = -len * 2; i <= len * 2; i++)
for (int j = -len * 2; j <= len * 2; j++) {
int l = 0, r = lena;
l = min(min(-i, -j), l);
r = max(r, max(-i + lenb, -j + lenc));
if (-len <= i && i <= len && xab[i + len] == 0)
continue;
int p = j - i;
if (-len <= p && p <= len && xbc[p + len] == 0)
continue;
if (-len <= j && j <= len && xac[j + len] == 0)
continue;
ans = min(r - l, ans);
}
cout << ans;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#define lson rt << 1
#define rson rt << 1 | 1
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int maxn = 4e3 + 10;
char a[maxn], b[maxn], c[maxn];
bool xab[maxn], xba[maxn], xbc[maxn], xac[maxn], xcb[maxn];
int main() {
cin >> a >> b >> c;
int lena = strlen(a), lenb = strlen(b), lenc = strlen(c);
int len = max(max(strlen(a), strlen(b)), strlen(c));
for (int i = -len; i <= len; i++) {
int flag = 0;
for (int j = 0; j < lena; j++) {
if (0 <= j + i && j + i < lenb) {
if (a[j] != '?' && a[j] != b[i + j] && b[i + j] != '?') {
flag = 1;
break;
}
}
}
if (flag == 0) {
xab[i + len] = 1;
}
}
for (int i = -len; i <= len; i++) {
int flag = 0;
for (int j = 0; j < lenb; j++) {
if (0 <= j + i && j + i < lenc) {
if (b[j] != '?' && b[j] != c[i + j] && c[i + j] != '?') {
flag = 1;
break;
}
}
}
if (flag == 0) {
xbc[i + len] = 1;
}
}
for (int i = -len; i <= len; i++) {
int flag = 0;
for (int j = 0; j < lena; j++) {
if (0 <= j + i && j + i < lenc) {
if (a[j] != '?' && a[j] != c[i + j] && c[i + j] != '?') {
flag = 1;
break;
}
}
}
if (flag == 0)
xac[i + len] = 1;
}
int ans = 1e9;
for (int i = -len * 2; i <= len * 2; i++)
for (int j = -len * 2; j <= len * 2; j++) {
int l = 0, r = lena;
l = min(min(-i, -j), l);
r = max(r, max(-i + lenb, -j + lenc));
if (-len <= i && i <= len && xab[i + len] == 0)
continue;
int p = j - i;
if (-len <= p && p <= len && xbc[p + len] == 0)
continue;
if (-len <= j && j <= len && xac[j + len] == 0)
continue;
ans = min(r - l, ans);
}
cout << ans;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02745 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
using namespace std;
constexpr int M = 5000;
bool is_same_char(char a, char b) {
if (a == '?')
return true;
if (b == '?')
return true;
return (a == b);
}
void construct(vector<bool> &dst, const string &lhs, const string &rhs) {
FOR_LT(i, 0, rhs.size()) {
bool is_ok = true;
FOR_LT(j, 0, min(lhs.size(), rhs.size() - i)) {
if (!is_same_char(lhs[j], rhs[j + i])) {
is_ok = false;
break;
}
}
dst[M - i] = is_ok;
}
FOR_LT(i, 0, lhs.size()) {
bool is_ok = true;
FOR_LT(j, 0, min(lhs.size() - i, rhs.size())) {
if (!is_same_char(lhs[j + i], rhs[j])) {
is_ok = false;
break;
}
}
dst[M + i] = is_ok;
}
}
void print(unordered_map<int, bool> &src) {
for (auto &s : src) {
cout << s.first << " " << s.second << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(20);
string a, b, c;
cin >> a >> b >> c;
vector<bool> is_ok_ab(M * 2, true);
vector<bool> is_ok_ac(M * 2, true);
vector<bool> is_ok_bc(M * 2, true);
construct(is_ok_ab, a, b);
construct(is_ok_bc, b, c);
construct(is_ok_ac, a, c);
/*
cout << "ab" << endl;
print(is_ok_ab);
cout << "bc" << endl;
print(is_ok_bc);
cout << "ca" << endl;
print(is_ok_ac);
*/
int ans = INT_MAX;
FOR_LE(ib, -((int)(b.size() + c.size())), a.size() + c.size()) {
FOR_LE(ic, -((int)(b.size() + c.size())), a.size() + b.size()) {
int s = min(min(0, ib), ic);
int e = max(max((int)a.size(), ib + (int)b.size()), ic + (int)c.size());
int curans = e - s;
if (!is_ok_ab[M + ib]) {
continue;
}
if (!is_ok_ac[M + ic]) {
continue;
}
int ibc = ic - ib;
if (!is_ok_bc[M + ibc]) {
continue;
}
ans = min(ans, curans);
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
using namespace std;
constexpr int M = 10000;
bool is_same_char(char a, char b) {
if (a == '?')
return true;
if (b == '?')
return true;
return (a == b);
}
void construct(vector<bool> &dst, const string &lhs, const string &rhs) {
FOR_LT(i, 0, rhs.size()) {
bool is_ok = true;
FOR_LT(j, 0, min(lhs.size(), rhs.size() - i)) {
if (!is_same_char(lhs[j], rhs[j + i])) {
is_ok = false;
break;
}
}
dst[M - i] = is_ok;
}
FOR_LT(i, 0, lhs.size()) {
bool is_ok = true;
FOR_LT(j, 0, min(lhs.size() - i, rhs.size())) {
if (!is_same_char(lhs[j + i], rhs[j])) {
is_ok = false;
break;
}
}
dst[M + i] = is_ok;
}
}
void print(unordered_map<int, bool> &src) {
for (auto &s : src) {
cout << s.first << " " << s.second << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(20);
string a, b, c;
cin >> a >> b >> c;
vector<bool> is_ok_ab(M * 2, true);
vector<bool> is_ok_ac(M * 2, true);
vector<bool> is_ok_bc(M * 2, true);
construct(is_ok_ab, a, b);
construct(is_ok_bc, b, c);
construct(is_ok_ac, a, c);
/*
cout << "ab" << endl;
print(is_ok_ab);
cout << "bc" << endl;
print(is_ok_bc);
cout << "ca" << endl;
print(is_ok_ac);
*/
int ans = INT_MAX;
FOR_LE(ib, -((int)(b.size() + c.size())), a.size() + c.size()) {
FOR_LE(ic, -((int)(b.size() + c.size())), a.size() + b.size()) {
int s = min(min(0, ib), ic);
int e = max(max((int)a.size(), ib + (int)b.size()), ic + (int)c.size());
int curans = e - s;
if (!is_ok_ab[M + ib]) {
continue;
}
if (!is_ok_ac[M + ic]) {
continue;
}
int ibc = ic - ib;
if (!is_ok_bc[M + ibc]) {
continue;
}
ans = min(ans, curans);
}
}
cout << ans << endl;
return 0;
} | replace | 32 | 33 | 32 | 33 | 0 | |
p02745 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = (x); i < (y); ++i)
#define REP(i, x, y) for (int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int maxn = 2005;
int ans = INF;
int ab[maxn][maxn], ac[maxn][maxn], bc[maxn][maxn];
string a, b, c;
inline bool match(int mat[][maxn], int xl, int xr, int yl, int yr) {
int zl = max(xl, yl), zr = min(xr, yr);
return mat[zl - xl][zl - yl] >= (zr - zl + 1);
}
int main() {
cin >> a >> b >> c;
for (int i = a.size() - 1; i >= 0; --i)
for (int j = b.size() - 1; j >= 0; --j)
ab[i][j] =
(a[i] != b[j] && a[i] != '?' && b[j] != '?' ? 0
: ab[i + 1][j + 1] + 1);
for (int i = a.size() - 1; i >= 0; --i)
for (int j = c.size() - 1; j >= 0; --j)
ac[i][j] =
(a[i] != c[j] && a[i] != '?' && c[j] != '?' ? 0
: ac[i + 1][j + 1] + 1);
for (int i = b.size() - 1; i >= 0; --i)
for (int j = c.size() - 1; j >= 0; --j)
bc[i][j] =
(b[i] != c[j] && b[i] != '?' && c[j] != '?' ? 0
: bc[i + 1][j + 1] + 1);
int tot = a.size() + b.size() + c.size();
FOR(i, 0, tot) FOR(j, 0, tot) {
int al = i, ar = i + a.size() - 1, bl = j, br = j + b.size() - 1, cl = 0,
cr = 0 + c.size() - 1;
if (!match(ab, al, ar, bl, br))
continue;
if (!match(ac, al, ar, cl, cr))
continue;
if (!match(bc, bl, br, cl, cr))
continue;
ans = min(ans, max(ar, max(br, cr)) + 1);
}
FOR(i, 0, tot) FOR(j, 0, tot) {
int al = i, ar = i + a.size() - 1, bl = 0, br = 0 + b.size() - 1, cl = j,
cr = j + c.size() - 1;
if (!match(ab, al, ar, bl, br))
continue;
if (!match(ac, al, ar, cl, cr))
continue;
if (!match(bc, bl, br, cl, cr))
continue;
ans = min(ans, max(ar, max(br, cr)) + 1);
}
FOR(i, 0, tot) FOR(j, 0, tot) {
int al = 0, ar = 0 + a.size() - 1, bl = i, br = i + b.size() - 1, cl = j,
cr = j + c.size() - 1;
if (!match(ab, al, ar, bl, br))
continue;
if (!match(ac, al, ar, cl, cr))
continue;
if (!match(bc, bl, br, cl, cr))
continue;
ans = min(ans, max(ar, max(br, cr)) + 1);
}
printf("%d\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = (x); i < (y); ++i)
#define REP(i, x, y) for (int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int maxn = 2005;
int ans = INF;
int ab[maxn][maxn], ac[maxn][maxn], bc[maxn][maxn];
string a, b, c;
inline bool match(int mat[][maxn], int xl, int xr, int yl, int yr) {
int zl = max(xl, yl), zr = min(xr, yr);
if (zl > zr)
return true;
return mat[zl - xl][zl - yl] >= (zr - zl + 1);
}
int main() {
cin >> a >> b >> c;
for (int i = a.size() - 1; i >= 0; --i)
for (int j = b.size() - 1; j >= 0; --j)
ab[i][j] =
(a[i] != b[j] && a[i] != '?' && b[j] != '?' ? 0
: ab[i + 1][j + 1] + 1);
for (int i = a.size() - 1; i >= 0; --i)
for (int j = c.size() - 1; j >= 0; --j)
ac[i][j] =
(a[i] != c[j] && a[i] != '?' && c[j] != '?' ? 0
: ac[i + 1][j + 1] + 1);
for (int i = b.size() - 1; i >= 0; --i)
for (int j = c.size() - 1; j >= 0; --j)
bc[i][j] =
(b[i] != c[j] && b[i] != '?' && c[j] != '?' ? 0
: bc[i + 1][j + 1] + 1);
int tot = a.size() + b.size() + c.size();
FOR(i, 0, tot) FOR(j, 0, tot) {
int al = i, ar = i + a.size() - 1, bl = j, br = j + b.size() - 1, cl = 0,
cr = 0 + c.size() - 1;
if (!match(ab, al, ar, bl, br))
continue;
if (!match(ac, al, ar, cl, cr))
continue;
if (!match(bc, bl, br, cl, cr))
continue;
ans = min(ans, max(ar, max(br, cr)) + 1);
}
FOR(i, 0, tot) FOR(j, 0, tot) {
int al = i, ar = i + a.size() - 1, bl = 0, br = 0 + b.size() - 1, cl = j,
cr = j + c.size() - 1;
if (!match(ab, al, ar, bl, br))
continue;
if (!match(ac, al, ar, cl, cr))
continue;
if (!match(bc, bl, br, cl, cr))
continue;
ans = min(ans, max(ar, max(br, cr)) + 1);
}
FOR(i, 0, tot) FOR(j, 0, tot) {
int al = 0, ar = 0 + a.size() - 1, bl = i, br = i + b.size() - 1, cl = j,
cr = j + c.size() - 1;
if (!match(ab, al, ar, bl, br))
continue;
if (!match(ac, al, ar, cl, cr))
continue;
if (!match(bc, bl, br, cl, cr))
continue;
ans = min(ans, max(ar, max(br, cr)) + 1);
}
printf("%d\n", ans);
return 0;
}
| insert | 26 | 26 | 26 | 28 | 0 | |
p02745 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-15;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;
template <typename T> void printv(const vector<T> &v) {
int sz = v.size();
for (int i = 0; i < sz; i++) {
cout << v[i] << " \n"[i == sz - 1];
}
}
bool check(const string &s, const string &t, int sindex, int tindex, int len) {
for (int i = 0; i < len; i++) {
if (s[sindex + i] == t[tindex + i])
continue;
if (s[sindex + i] == '?' || t[tindex + i] == '?')
continue;
return false;
}
return true;
}
int solve(string a, string b, string c) {
int alen = a.size(), blen = b.size(), clen = c.size();
// aの相対位置で何番目ならok
unordered_map<int, int> ab, ac, bc;
ab[-blen] = 1;
ab[alen] = 1;
for (int i = -blen + 1; i <= alen - 1; i++) {
int aindex = max(0, i);
int bindex = max(-i, 0);
int len = min(alen - aindex, blen - bindex);
if (check(a, b, aindex, bindex, len))
ab[i] = 1;
}
ac[-clen] = 1;
ac[alen] = 1;
for (int i = -clen + 1; i <= alen - 1; i++) {
int aindex = max(0, i);
int cindex = max(-i, 0);
int len = min(alen - aindex, clen - cindex);
if (check(a, c, aindex, cindex, len))
ac[i] = 1;
}
bc[-clen] = 1;
bc[blen] = 1;
for (int i = -clen + 1; i <= blen - 1; i++) {
int bindex = max(0, i);
int cindex = max(-i, 0);
int len = min(blen - bindex, clen - cindex);
if (check(b, c, bindex, cindex, len))
bc[i] = 1;
}
int ret = INF;
for (int i = -blen; i <= alen; i++) {
for (int j = -clen; j <= alen; j++) {
int diff = j - i;
int ma = max({alen - 1, i + blen - 1, j + clen - 1});
int mi = min({0, i, j});
if (ab[i] && ac[j]) {
if (diff < -clen || blen < diff || bc[diff]) {
ret = min(ret, ma - mi + 1);
}
}
}
}
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string a, b, c;
cin >> a >> b >> c;
int ret = min({solve(a, b, c), solve(a, c, b), solve(b, a, c), solve(b, c, a),
solve(c, a, b), solve(c, b, a)});
cout << ret << endl;
}
| #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-15;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;
template <typename T> void printv(const vector<T> &v) {
int sz = v.size();
for (int i = 0; i < sz; i++) {
cout << v[i] << " \n"[i == sz - 1];
}
}
bool check(const string &s, const string &t, int sindex, int tindex, int len) {
for (int i = 0; i < len; i++) {
if (s[sindex + i] == t[tindex + i])
continue;
if (s[sindex + i] == '?' || t[tindex + i] == '?')
continue;
return false;
}
return true;
}
int solve(string a, string b, string c) {
int alen = a.size(), blen = b.size(), clen = c.size();
// aの相対位置で何番目ならok
unordered_map<int, int> ab, ac, bc;
ab[-blen] = 1;
ab[alen] = 1;
for (int i = -blen + 1; i <= alen - 1; i++) {
int aindex = max(0, i);
int bindex = max(-i, 0);
int len = min(alen - aindex, blen - bindex);
if (check(a, b, aindex, bindex, len))
ab[i] = 1;
}
ac[-clen] = 1;
ac[alen] = 1;
for (int i = -clen + 1; i <= alen - 1; i++) {
int aindex = max(0, i);
int cindex = max(-i, 0);
int len = min(alen - aindex, clen - cindex);
if (check(a, c, aindex, cindex, len))
ac[i] = 1;
}
bc[-clen] = 1;
bc[blen] = 1;
for (int i = -clen + 1; i <= blen - 1; i++) {
int bindex = max(0, i);
int cindex = max(-i, 0);
int len = min(blen - bindex, clen - cindex);
if (check(b, c, bindex, cindex, len))
bc[i] = 1;
}
int ret = INF;
for (int i = -blen; i <= alen; i++) {
for (int j = -clen; j <= alen; j++) {
int diff = j - i;
int ma = max({alen - 1, i + blen - 1, j + clen - 1});
int mi = min({0, i, j});
if (ab[i] && ac[j]) {
if (diff < -clen || blen < diff || bc[diff]) {
ret = min(ret, ma - mi + 1);
}
}
}
}
return ret;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string a, b, c;
cin >> a >> b >> c;
int ret = min({solve(a, b, c), solve(b, a, c), solve(c, a, b)});
cout << ret << endl;
}
| replace | 82 | 84 | 82 | 83 | TLE | |
p02746 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
const ll s = pow(3, 29);
ll solve(ll a1, ll a2, ll b1, ll b2) {
if (a2 > b2) {
swap(a1, b1);
swap(a2, b2);
}
ll res = abs(a1 - b1) + abs(a2 - b2);
for (ll ss = s; ss >= 0; ss /= 3) {
ll na1 = a1 / ss, nb1 = b1 / ss;
if (na1 != nb1)
break;
ll na2 = a2 / ss, nb2 = b2 / ss;
if (na1 % 3 == 1 && abs(nb2 - na2) > 1) {
ll up = ss * na1 - 1;
ll down = ss * (na1 + 1);
ll loss = min(min(a1, b1) - up, down - max(a1, b1));
res += 2 * loss;
break;
}
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int q;
cin >> q;
rep(i, q) {
ll ai, aj, bi, bj;
cin >> ai >> aj >> bi >> bj;
--ai, --aj, --bi, --bj;
ll ans = 0;
ans = max(ans, solve(ai, aj, bi, bj));
ans = max(ans, solve(aj, ai, bj, bi));
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
const ll s = pow(3, 29);
ll solve(ll a1, ll a2, ll b1, ll b2) {
if (a2 > b2) {
swap(a1, b1);
swap(a2, b2);
}
ll res = abs(a1 - b1) + abs(a2 - b2);
for (ll ss = s; ss > 0; ss /= 3) {
ll na1 = a1 / ss, nb1 = b1 / ss;
if (na1 != nb1)
break;
ll na2 = a2 / ss, nb2 = b2 / ss;
if (na1 % 3 == 1 && abs(nb2 - na2) > 1) {
ll up = ss * na1 - 1;
ll down = ss * (na1 + 1);
ll loss = min(min(a1, b1) - up, down - max(a1, b1));
res += 2 * loss;
break;
}
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int q;
cin >> q;
rep(i, q) {
ll ai, aj, bi, bj;
cin >> ai >> aj >> bi >> bj;
--ai, --aj, --bi, --bj;
ll ans = 0;
ans = max(ans, solve(ai, aj, bi, bj));
ans = max(ans, solve(aj, ai, bj, bi));
cout << ans << endl;
}
} | replace | 12 | 13 | 12 | 13 | -8 | |
p02746 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
template <class o, class p, class q>
using tuple3q = priority_queue<tuple<o, p, q>, vector<tuple<o, p, q>>,
greater<tuple<o, p, q>>>;
template <class o, class p, class q, class r>
using tuple4q = priority_queue<tuple<o, p, q, r>, vector<tuple<o, p, q, r>>,
greater<tuple<o, p, q, r>>>;
template <class o, class p, class q, class r, class s>
using tuple5q =
priority_queue<tuple<o, p, q, r, s>, vector<tuple<o, p, q, r, s>>,
greater<tuple<o, p, q, r, s>>>;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define put(v) cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define vdesc(v) \
vsort(v); \
reverse(all(v))
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
#define psp2(a, b) push(make_pair(a, b))
#define cini(a) \
a; \
cin >> a
#define infa(a, b) (a + b) % INF
#define infm(a, b) (a * b) % INF
#define infd(a, b) (a * modinv(b)) % INF
#define infs(a, b) (a + INF - b) % INF
#define inf(a) (a) %= INF
#define inff(a) ((a) % INF)
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define smal -INF *INF
#define big INF *INF
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
class mint {
int md = 1000000007;
public:
long long x;
mint(ll x, ll md) {
this->md = md;
this->x = (x % md + md) % md;
}
mint(long long x = 0) : x((x % md + md) % md) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= md)
x -= md;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += md - a.x) >= md)
x -= md;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= md;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(md - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll n;
int ci = 0;
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
class edge {
public:
int from, to, i;
ll val;
edge() {}
edge(ll to) : to(to) {}
edge(ll to, ll i) : to(to), i(i) {}
edge(ll from, ll to, ll val) : from(from), to(to), val(val) {}
};
class LCA {
private:
vector<vector<edge>> v;
vector<vector<int>> parent;
vector<int> depth;
void dfs(int n, int m, int d) {
parent[0][n] = m;
depth[n] = d;
for (auto x : v[n]) {
if (x.to != m)
dfs(x.to, n, d + 1);
}
}
public:
LCA(ll N, ll root, vector<vector<edge>> &tree) {
v = tree;
parent = vector<vector<int>>(21, vector<int>(N + 1, 0));
depth = vector<int>(N + 1, 0);
dfs(root, -1, 0);
for (int j = 0; j + 1 < 20; j++) {
for (int i = 1; i <= N; i++) {
if (parent[j][i] < 0)
parent[j + 1][i] = -1;
else
parent[j + 1][i] = parent[j][parent[j][i]];
}
}
}
int lca(int n, int m) {
if (depth[n] > depth[m])
swap(n, m);
for (int j = 0; j < 20; j++) {
if ((depth[m] - depth[n]) >> j & 1)
m = parent[j][m];
}
if (n == m)
return n;
for (int j = 19; j >= 0; j--) {
if (parent[j][n] != parent[j][m]) {
n = parent[j][n];
m = parent[j][m];
}
}
return parent[0][n];
}
int dep(int n) { return depth[n]; }
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
// 線分はp0とp1でp2がどこにあるかを探る
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll npr(ll n, ll r) {
if (r == 0)
return 1;
return inff(fac[n] * modinv(fac[n - r]));
}
vl zalgo(string s) {
ll c = 0;
vl a(s.size());
ll si = s.size();
rep2(i, 1, s.size()) {
if (i + a[i - c] < c + a[c]) {
a[i] = a[i - c];
} else {
ll j = max(0LL, a[c] - (i - c));
while (i + j < si && s[j] == s[i + j]) {
j++;
}
a[i] = j;
c = i;
}
}
a[0] = s.size();
return a;
}
string decStrNum(string s) {
ll si = s.size();
for (int i = si - 1; i >= 0; i--) {
if (s[i] == '0') {
s[i] = '9';
continue;
}
s[i] = s[i] - 1;
break;
}
return s;
}
// ここまでライブラリ
// ここからコード
bool interval(ll x, ll y1, ll y2) {
if (y1 > y2)
swap(y1, y2);
y1++;
y2--;
if (y1 > y2)
return false;
while (x > 0) {
if (x % 3 == 1) {
if (y2 - y1 > 3)
return true;
for (ll y = y1; y <= y2; y++)
if (y % 3 == 1)
return true;
}
x /= 3;
y1 /= 3;
y2 /= 3;
}
}
ll cal2(ll x1, ll y1, ll x2, ll y2) {
ll th = 1;
ll res = 0;
rep(i, 35) {
if (x1 / th == x2 / th && interval(x1 / th, y1 / th, y2 / th)) {
ll v = min(min(x1 % th, x2 % th) + 1, th - max(x1 % th, x2 % th));
res = max(v, res);
}
th *= 3;
}
return res;
}
ll cal1(ll x1, ll y1, ll x2, ll y2) {
return abs(x1 - x2) + abs(y2 - y1) +
2LL * max(cal2(x1, y1, x2, y2), cal2(y1, x1, y2, x2));
}
void solv() {
cin >> n;
rep(i, n) {
ll a, b, c, d;
cin >> a >> b >> c >> d;
a--;
b--;
c--;
d--;
cout << cal1(a, b, c, d) << endl;
}
}
int main() {
COMinit();
solv();
return 0;
}
| #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
template <class o, class p, class q>
using tuple3q = priority_queue<tuple<o, p, q>, vector<tuple<o, p, q>>,
greater<tuple<o, p, q>>>;
template <class o, class p, class q, class r>
using tuple4q = priority_queue<tuple<o, p, q, r>, vector<tuple<o, p, q, r>>,
greater<tuple<o, p, q, r>>>;
template <class o, class p, class q, class r, class s>
using tuple5q =
priority_queue<tuple<o, p, q, r, s>, vector<tuple<o, p, q, r, s>>,
greater<tuple<o, p, q, r, s>>>;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define put(v) cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define vdesc(v) \
vsort(v); \
reverse(all(v))
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
#define psp2(a, b) push(make_pair(a, b))
#define cini(a) \
a; \
cin >> a
#define infa(a, b) (a + b) % INF
#define infm(a, b) (a * b) % INF
#define infd(a, b) (a * modinv(b)) % INF
#define infs(a, b) (a + INF - b) % INF
#define inf(a) (a) %= INF
#define inff(a) ((a) % INF)
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define smal -INF *INF
#define big INF *INF
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
class mint {
int md = 1000000007;
public:
long long x;
mint(ll x, ll md) {
this->md = md;
this->x = (x % md + md) % md;
}
mint(long long x = 0) : x((x % md + md) % md) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= md)
x -= md;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += md - a.x) >= md)
x -= md;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= md;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(md - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll n;
int ci = 0;
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
class edge {
public:
int from, to, i;
ll val;
edge() {}
edge(ll to) : to(to) {}
edge(ll to, ll i) : to(to), i(i) {}
edge(ll from, ll to, ll val) : from(from), to(to), val(val) {}
};
class LCA {
private:
vector<vector<edge>> v;
vector<vector<int>> parent;
vector<int> depth;
void dfs(int n, int m, int d) {
parent[0][n] = m;
depth[n] = d;
for (auto x : v[n]) {
if (x.to != m)
dfs(x.to, n, d + 1);
}
}
public:
LCA(ll N, ll root, vector<vector<edge>> &tree) {
v = tree;
parent = vector<vector<int>>(21, vector<int>(N + 1, 0));
depth = vector<int>(N + 1, 0);
dfs(root, -1, 0);
for (int j = 0; j + 1 < 20; j++) {
for (int i = 1; i <= N; i++) {
if (parent[j][i] < 0)
parent[j + 1][i] = -1;
else
parent[j + 1][i] = parent[j][parent[j][i]];
}
}
}
int lca(int n, int m) {
if (depth[n] > depth[m])
swap(n, m);
for (int j = 0; j < 20; j++) {
if ((depth[m] - depth[n]) >> j & 1)
m = parent[j][m];
}
if (n == m)
return n;
for (int j = 19; j >= 0; j--) {
if (parent[j][n] != parent[j][m]) {
n = parent[j][n];
m = parent[j][m];
}
}
return parent[0][n];
}
int dep(int n) { return depth[n]; }
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
// 線分はp0とp1でp2がどこにあるかを探る
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll npr(ll n, ll r) {
if (r == 0)
return 1;
return inff(fac[n] * modinv(fac[n - r]));
}
vl zalgo(string s) {
ll c = 0;
vl a(s.size());
ll si = s.size();
rep2(i, 1, s.size()) {
if (i + a[i - c] < c + a[c]) {
a[i] = a[i - c];
} else {
ll j = max(0LL, a[c] - (i - c));
while (i + j < si && s[j] == s[i + j]) {
j++;
}
a[i] = j;
c = i;
}
}
a[0] = s.size();
return a;
}
string decStrNum(string s) {
ll si = s.size();
for (int i = si - 1; i >= 0; i--) {
if (s[i] == '0') {
s[i] = '9';
continue;
}
s[i] = s[i] - 1;
break;
}
return s;
}
// ここまでライブラリ
// ここからコード
bool interval(ll x, ll y1, ll y2) {
if (y1 > y2)
swap(y1, y2);
y1++;
y2--;
if (y1 > y2)
return false;
while (x > 0) {
if (x % 3 == 1) {
if (y2 - y1 > 3)
return true;
for (ll y = y1; y <= y2; y++)
if (y % 3 == 1)
return true;
}
x /= 3;
y1 /= 3;
y2 /= 3;
}
return false;
}
ll cal2(ll x1, ll y1, ll x2, ll y2) {
ll th = 1;
ll res = 0;
rep(i, 35) {
if (x1 / th == x2 / th && interval(x1 / th, y1 / th, y2 / th)) {
ll v = min(min(x1 % th, x2 % th) + 1, th - max(x1 % th, x2 % th));
res = max(v, res);
}
th *= 3;
}
return res;
}
ll cal1(ll x1, ll y1, ll x2, ll y2) {
return abs(x1 - x2) + abs(y2 - y1) +
2LL * max(cal2(x1, y1, x2, y2), cal2(y1, x1, y2, x2));
}
void solv() {
cin >> n;
rep(i, n) {
ll a, b, c, d;
cin >> a >> b >> c >> d;
a--;
b--;
c--;
d--;
cout << cal1(a, b, c, d) << endl;
}
}
int main() {
COMinit();
solv();
return 0;
}
| insert | 1,079 | 1,079 | 1,079 | 1,080 | TLE | |
p02746 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int64_t len(int64_t a, int64_t b, int64_t c, int64_t d, int64_t p) {
if (a / p != c / p && b / p != d / p)
return abs(c - a) + abs(d - b);
if (a / p == c / p && b / p == d / p)
return len(a % p, b % p, c % p, d % p, p / 3);
if (a / p == c / p)
return len(c, d, a, b, p);
int64_t xa = a;
int64_t xc = c;
int k = 0;
while (abs(xc - xa) > 1) {
k++;
xc /= 3;
xa /= 3;
}
int64_t x = (b + d) / 2;
vector<int> t;
while (x > 0) {
t.push_back(x % 3);
x /= 3;
}
int64_t l = 0;
int64_t g = 0;
bool f = 0;
for (int i = (int)t.size() - 1; i >= 0; i--) {
l *= 3;
g *= 3;
if (f) {
l += 2;
continue;
}
if (i < k && t.at(i) == 1) {
g += 2;
f = 1;
continue;
}
l += t.at(i);
g += t.at(i);
}
return min(abs(c - a) + abs(l - b) + abs(l - d),
abs(c - a) + abs(g - b) + abs(g - d));
}
int main() {
int q;
cin >> q;
for (int _ = 0; _ < q; _++) {
int64_t a, b, c, d;
cin >> a >> b >> c >> d;
a--;
b--;
c--;
d--;
int64_t p = 1;
while (p <= max({a, b, c, d}))
p *= 3;
cout << len(a, b, c, d, p / 3) << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int64_t len(int64_t a, int64_t b, int64_t c, int64_t d, int64_t p) {
if (a / p != c / p && b / p != d / p)
return abs(c - a) + abs(d - b);
if (a / p == c / p && b / p == d / p)
return len(a % p, b % p, c % p, d % p, p / 3);
if (a / p == c / p)
return len(b, a, d, c, p);
int64_t xa = a;
int64_t xc = c;
int k = 0;
while (abs(xc - xa) > 1) {
k++;
xc /= 3;
xa /= 3;
}
int64_t x = (b + d) / 2;
vector<int> t;
while (x > 0) {
t.push_back(x % 3);
x /= 3;
}
int64_t l = 0;
int64_t g = 0;
bool f = 0;
for (int i = (int)t.size() - 1; i >= 0; i--) {
l *= 3;
g *= 3;
if (f) {
l += 2;
continue;
}
if (i < k && t.at(i) == 1) {
g += 2;
f = 1;
continue;
}
l += t.at(i);
g += t.at(i);
}
return min(abs(c - a) + abs(l - b) + abs(l - d),
abs(c - a) + abs(g - b) + abs(g - d));
}
int main() {
int q;
cin >> q;
for (int _ = 0; _ < q; _++) {
int64_t a, b, c, d;
cin >> a >> b >> c >> d;
a--;
b--;
c--;
d--;
int64_t p = 1;
while (p <= max({a, b, c, d}))
p *= 3;
cout << len(a, b, c, d, p / 3) << endl;
}
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02747 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using P = pair<int, int>;
int main() {
string s;
cin >> s;
bool flag = true;
for (int i = 0; i < s.length(); i = i + 2) {
if (s.at(i) != 'h' || s.at(i + 1) != 'i') {
flag = false;
}
}
if (s.length() % 2 != 0)
flag = false;
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using P = pair<int, int>;
int main() {
string s;
cin >> s;
bool flag = true;
for (int i = 0; i < s.length() - 1; i = i + 2) {
if (s.at(i) != 'h' || s.at(i + 1) != 'i') {
flag = false;
}
}
if (s.length() % 2 != 0)
flag = false;
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02747 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long llong;
typedef unsigned long long ullong;
using namespace std;
int main() {
string s;
cin >> s;
bool h = true;
for (auto &it : s) {
if (h && it == 'h') {
h = false;
} else if (!h && it == 'i') {
h = true;
} else {
cout << "No";
return 1;
}
}
if (h)
cout << "Yes";
else
cout << "No";
} | #include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long llong;
typedef unsigned long long ullong;
using namespace std;
int main() {
string s;
cin >> s;
bool h = true;
for (auto &it : s) {
if (h && it == 'h') {
h = false;
} else if (!h && it == 'i') {
h = true;
} else {
cout << "No";
return 0;
}
}
if (h)
cout << "Yes";
else
cout << "No";
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p02747 | C++ | Runtime Error | // BUGSBUNNY
// IIT ROORKEE
// _,add8ba,
// ,d888888888b,
// d8888888888888b _,ad8ba,_
// d888888888888888) ,d888888888b,
// I8888888888888888 _________ ,8888888888888b
// __________`Y88888888888888P"""""""""""baaa,__
// ,888888888888888,
// ,adP"""""""""""9888888888P""^ ^""Y8888888888888888I
// ,a8"^ ,d888P"888P^ ^"Y8888888888P'
// ,a8^ ,d8888' ^Y8888888P'
// a88' ,d8888P' I88P"^
// ,d88' d88888P' "b,
// ,d88' d888888' `b,
// ,d88' d888888I `b,
// d88I ,8888888' ___ `b,
// ,888' d8888888 ,d88888b, ____ `b,
// d888 ,8888888I d88888888b, ,d8888b, `b
// ,8888 I8888888I d8888888888I ,88888888b 8, I8888
// 88888888b d88888888888' 8888888888b 8I d8886
// 888888888 Y888888888P' Y8888888888, ,8b 88888b
// I88888888b `Y8888888^ `Y888888888I d88, Y88888b
// `888888888b, `""""^ `Y8888888P' d888I `888888b
// 88888888888b, `Y8888P^ d88888
// Y888888b ,8888888888888ba,_ _______ `""^ ,d888888
// I8888888b, ,888888888888888888ba,_ d88888888b ,ad8888888I
// `888888888b, I8888888888888888888888b, ^"Y888P"^ ____.,ad88888888888I
// 88888888888b,`888888888888888888888888b, "" ad888888888888888888888'
// 8888888888888698888888888888888888888888b_,ad88ba,_,d88888888888888888888888
// 88888888888888888888888888888888888888888b,`"""^
// d8888888888888888888888888I
// 8888888888888888888888888888888888888888888baaad888888888888888888888888888'
// Y8888888888888888888888888888888888888888888888888888888888888888888888888P
// I888888888888888888888888888888888888888888888P^ ^Y8888888888888888888888'
// `Y88888888888888888P88888888888888888888888888' ^88888888888888888888I
// `Y8888888888888888 `8888888888888888888888888 8888888888888888888P'
// `Y888888888888888 `888888888888888888888888, ,888888888888888888P'
// `Y88888888888888b `88888888888888888888888I I888888888888888888'
// "Y8888888888888b `8888888888888888888888I I88888888888888888'
// "Y88888888888P `888888888888888888888b d8888888888888888'
// ^""""""""^ `Y88888888888888888888, 888888888888888P'
// "8888888888888888888b, Y888888888888P^
// `Y888888888888888888b `Y8888888P"^
// "Y8888888888888888P `""""^
// `"YY88888888888P'
// ^""""""""'
#include <bits/stdc++.h>
using namespace std;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define int long long
#define ll long long
#define ld long double
// #define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<long long>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vb vector<bool>
#define pb push_back
#define pob pop_back
#define gcd __gcd
#define mp make_pair
#define pii pair<int, int>
#define pipii pair<int, pii>
#define pll pair<long long, long long>
#define pld pair<long double, long double>
#define mod 1000000007
#define mod2 998244353
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repp(i, a, b) for (ll i = a; i < b; i++)
#define reppr(i, a, b) for (ll i = a - 1; i >= b; i--)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 1000000000000
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprecision0 cout << fixed << setprecision(0);
#define setprecision10 cout << fixed << setprecision(10);
#define all(n) n.begin(), n.end()
void solve();
signed main() {
fast;
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
while (t--)
solve();
}
void solve() {
string s;
cin >> s;
if (s.length() % 2 == 1)
cout << "No\n";
else {
int f = 0;
rep(i, s.length() - 1) if (s[i] == 'h' && s[i + 1] == 'i') i++;
else f = 1;
cout << ((f) ? "No\n" : "Yes\n") << endl;
}
} | // BUGSBUNNY
// IIT ROORKEE
// _,add8ba,
// ,d888888888b,
// d8888888888888b _,ad8ba,_
// d888888888888888) ,d888888888b,
// I8888888888888888 _________ ,8888888888888b
// __________`Y88888888888888P"""""""""""baaa,__
// ,888888888888888,
// ,adP"""""""""""9888888888P""^ ^""Y8888888888888888I
// ,a8"^ ,d888P"888P^ ^"Y8888888888P'
// ,a8^ ,d8888' ^Y8888888P'
// a88' ,d8888P' I88P"^
// ,d88' d88888P' "b,
// ,d88' d888888' `b,
// ,d88' d888888I `b,
// d88I ,8888888' ___ `b,
// ,888' d8888888 ,d88888b, ____ `b,
// d888 ,8888888I d88888888b, ,d8888b, `b
// ,8888 I8888888I d8888888888I ,88888888b 8, I8888
// 88888888b d88888888888' 8888888888b 8I d8886
// 888888888 Y888888888P' Y8888888888, ,8b 88888b
// I88888888b `Y8888888^ `Y888888888I d88, Y88888b
// `888888888b, `""""^ `Y8888888P' d888I `888888b
// 88888888888b, `Y8888P^ d88888
// Y888888b ,8888888888888ba,_ _______ `""^ ,d888888
// I8888888b, ,888888888888888888ba,_ d88888888b ,ad8888888I
// `888888888b, I8888888888888888888888b, ^"Y888P"^ ____.,ad88888888888I
// 88888888888b,`888888888888888888888888b, "" ad888888888888888888888'
// 8888888888888698888888888888888888888888b_,ad88ba,_,d88888888888888888888888
// 88888888888888888888888888888888888888888b,`"""^
// d8888888888888888888888888I
// 8888888888888888888888888888888888888888888baaad888888888888888888888888888'
// Y8888888888888888888888888888888888888888888888888888888888888888888888888P
// I888888888888888888888888888888888888888888888P^ ^Y8888888888888888888888'
// `Y88888888888888888P88888888888888888888888888' ^88888888888888888888I
// `Y8888888888888888 `8888888888888888888888888 8888888888888888888P'
// `Y888888888888888 `888888888888888888888888, ,888888888888888888P'
// `Y88888888888888b `88888888888888888888888I I888888888888888888'
// "Y8888888888888b `8888888888888888888888I I88888888888888888'
// "Y88888888888P `888888888888888888888b d8888888888888888'
// ^""""""""^ `Y88888888888888888888, 888888888888888P'
// "8888888888888888888b, Y888888888888P^
// `Y888888888888888888b `Y8888888P"^
// "Y8888888888888888P `""""^
// `"YY88888888888P'
// ^""""""""'
#include <bits/stdc++.h>
using namespace std;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define int long long
#define ll long long
#define ld long double
// #define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<long long>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vb vector<bool>
#define pb push_back
#define pob pop_back
#define gcd __gcd
#define mp make_pair
#define pii pair<int, int>
#define pipii pair<int, pii>
#define pll pair<long long, long long>
#define pld pair<long double, long double>
#define mod 1000000007
#define mod2 998244353
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repp(i, a, b) for (ll i = a; i < b; i++)
#define reppr(i, a, b) for (ll i = a - 1; i >= b; i--)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 1000000000000
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprecision0 cout << fixed << setprecision(0);
#define setprecision10 cout << fixed << setprecision(10);
#define all(n) n.begin(), n.end()
void solve();
signed main() {
fast;
// #ifndef ONLINE_JUDGE
// // for getting input from input.txt
// freopen("input.txt", "r", stdin);
// // for writing output to output.txt
// freopen("output.txt", "w", stdout);
// #endif
int t = 1;
// cin >> t;
while (t--)
solve();
}
void solve() {
string s;
cin >> s;
if (s.length() % 2 == 1)
cout << "No\n";
else {
int f = 0;
rep(i, s.length() - 1) if (s[i] == 'h' && s[i + 1] == 'i') i++;
else f = 1;
cout << ((f) ? "No\n" : "Yes\n") << endl;
}
} | replace | 94 | 100 | 94 | 100 | -11 | |
p02747 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string ans = "Yes";
string s;
cin >> s;
for (int i = 0; i < s.size(); i = i + 2) {
if (!(s.at(i) == 'h' && s.at(i + 1) == 'i'))
ans = "No";
}
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string ans = "Yes";
string s;
cin >> s;
if (s.size() % 2 == 1) {
ans = "No";
cout << ans << "\n";
return 0;
}
for (int i = 0; i < s.size(); i = i + 2) {
if (!(s.at(i) == 'h' && s.at(i + 1) == 'i'))
ans = "No";
}
cout << ans << "\n";
return 0;
}
| insert | 9 | 9 | 9 | 15 | 0 | |
p02747 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
while (S.size() != 0) {
if (S.at(0) == 'h' && S.at(1) == 'i') {
S = S.substr(2);
} else {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.size() % 2 != 0) {
cout << "No" << endl;
return 0;
}
while (S.size() != 0) {
if (S.at(0) == 'h' && S.at(1) == 'i') {
S = S.substr(2);
} else {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
| insert | 6 | 6 | 6 | 10 | 0 | |
p02747 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
string S;
cin >> S;
string ans = "Yes", hi = "hi";
while (S.length() > 0) {
if (S.substr(S.length() - 2, 2) == hi) {
S = S.substr(0, S.length() - 2);
} else {
ans = "No";
break;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
string S;
cin >> S;
string ans = "Yes", hi = "hi";
while (S.length() > 0) {
if (S.length() % 2 == 1) {
ans = "No";
break;
}
if (S.substr(S.length() - 2, 2) == hi) {
S = S.substr(0, S.length() - 2);
} else {
ans = "No";
break;
}
}
cout << ans << endl;
}
| insert | 13 | 13 | 13 | 17 | 0 | |
p02747 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int c = 1;
for (int i = 0; i <= (s.length() - 1) / 2; i++) {
if ((s.at(i * 2) == 'h') && (s.at(i * 2 + 1) == 'i')) {
c = c * 1;
} else {
c = 0;
}
}
if (c > 0 && s.length() % 2 == 0) {
cout << "Yes";
} else {
cout << "No";
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" ||
s == "hihihihihi") {
cout << "Yes";
} else {
cout << "No";
}
} | replace | 6 | 16 | 6 | 8 | 0 | |
p02747 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define f first
#define s second
#define inf 1e18 + 9
using namespace std;
int32_t main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0), cin.tie(0);
string st;
cin >> st;
int n = st.size();
if (n % 2) {
cout << "No";
return 0;
}
int f = 1;
for (int i = 0; i < n; i++) {
if (i % 2 and st[i] != 'i')
f = 0;
if (i % 2 == 0 and st[i] != 'h')
f = 0;
}
if (f)
cout << "Yes";
else
cout << "No";
} | #include <bits/stdc++.h>
#define int long long
#define f first
#define s second
#define inf 1e18 + 9
using namespace std;
int32_t main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0), cin.tie(0);
string st;
cin >> st;
int n = st.size();
if (n % 2) {
cout << "No";
return 0;
}
int f = 1;
for (int i = 0; i < n; i++) {
if (i % 2 and st[i] != 'i')
f = 0;
if (i % 2 == 0 and st[i] != 'h')
f = 0;
}
if (f)
cout << "Yes";
else
cout << "No";
} | replace | 7 | 9 | 7 | 9 | 0 | |
p02747 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main(void) {
char S[10];
cin >> S;
int flag = 0;
int result = 1;
int i = 0;
while (S[i] != NULL) {
if (i % 2 == 0) {
if (S[i] != 'h') {
result = 0;
break;
} else
flag = 1;
} else {
if (S[i] != 'i') {
result = 0;
break;
} else
flag = 2;
}
i += 1;
}
if (flag != 2)
result = 0;
if (result == 1)
cout << "Yes";
else
cout << "No";
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
int main(void) {
char S[11];
cin >> S;
int flag = 0;
int result = 1;
int i = 0;
while (S[i] != NULL) {
if (i % 2 == 0) {
if (S[i] != 'h') {
result = 0;
break;
} else
flag = 1;
} else {
if (S[i] != 'i') {
result = 0;
break;
} else
flag = 2;
}
i += 1;
}
if (flag != 2)
result = 0;
if (result == 1)
cout << "Yes";
else
cout << "No";
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02747 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
for (int i = 0; i < 4; i++) {
if (S.at(2 * i) != 'h' || S.at(2 * i + 1) != 'i') {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int n = 0;
n = (S.size()) / 2;
if (S.size() % 2 != 0) {
cout << "No" << endl;
return 0;
}
if (S.size() == 0) {
cout << "No" << endl;
return 0;
}
if (S.size() == 1) {
cout << "No" << endl;
return 0;
}
for (int i = 0; i < n; i++) {
if (S.at(2 * i) != 'h' || S.at((2 * i) + 1) != 'i') {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
} | replace | 7 | 9 | 7 | 23 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 4) >= this->size() (which is 4)
|
p02747 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
bool flag = true;
if (S.size() > 10) {
cout << "No";
return 0;
}
for (int i = 0; i < S.size(); i += 2) {
if (S.at(i) != 'h' || S.at(i + 1) != 'i')
flag = false;
}
if (flag)
cout << "Yes";
else
cout << "No";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
bool flag = true;
if (S.size() % 2 != 0) {
cout << "No";
return 0;
}
for (int i = 0; i < S.size(); i += 2) {
if (S.at(i) != 'h' || S.at(i + 1) != 'i')
flag = false;
}
if (flag)
cout << "Yes";
else
cout << "No";
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02747 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
// #include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace std;
signed main() {
string s;
cin >> s;
int t = 0;
while (t + 1 < s.size()) {
if (s[t] == 'h' && s[t + 1] == 'i')
t += 2;
}
cout << (t == s.size() ? "Yes" : "No") << endl;
;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
// #include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace std;
signed main() {
string s;
cin >> s;
int t = 0;
while (t + 1 < s.size()) {
if (s[t] == 'h' && s[t + 1] == 'i')
t += 2;
else
break;
}
cout << (t == s.size() ? "Yes" : "No") << endl;
;
} | insert | 20 | 20 | 20 | 22 | TLE | |
p02747 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
string S;
cin >> S;
// cout<<S.length()<<endl;
if (S.length() % 2 == 0) {
int flag = 1;
for (int i = 0; i < S.length(); i++) {
if (i % 2 == 0) {
if (S[i] != 'h') {
flag = 0;
break;
}
}
else {
if (S[i] != 'i') {
flag = 0;
break;
}
}
}
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
#define ll long long;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string S;
cin >> S;
// cout<<S.length()<<endl;
if (S.length() % 2 == 0) {
int flag = 1;
for (int i = 0; i < S.length(); i++) {
if (i % 2 == 0) {
if (S[i] != 'h') {
flag = 0;
break;
}
}
else {
if (S[i] != 'i') {
flag = 0;
break;
}
}
}
if (flag)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
else
cout << "No" << endl;
} | delete | 7 | 11 | 7 | 7 | 0 | |
p02747 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool at = false;
for (int i = 0; i < s.size() - 2; i++) {
if (s[i] == 'h' && s[i + 1] == 'i') {
at = true;
break;
}
}
if (at == true)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool at = true;
if (s.size() % 2 != 0) {
cout << "No" << endl;
return 0;
}
for (int i = 0; i < s.size() - 1; i += 2) {
if (s[i] != 'h' || s[i + 1] != 'i') {
at = false;
break;
}
}
if (at == true)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| replace | 6 | 10 | 6 | 14 | 0 | |
p02747 | C++ | Time Limit Exceeded | // A.cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
bool flag;
cin >> s;
if (s.size() % 2 == 1) {
cout << "No" << endl;
return 0;
}
string st;
for (int i = 0; i != s.size(); i = +2) {
st += "hi";
}
if (s == st) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | // A.cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
bool flag;
cin >> s;
if (s.size() % 2 == 1) {
cout << "No" << endl;
return 0;
}
string st;
for (int i = 0; i != s.size(); i += 2) {
st += "hi";
}
if (s == st) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | replace | 14 | 15 | 14 | 15 | TLE | |
p02747 | C++ | Runtime Error | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iomanip>
#include <iostream>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <stdio.h>
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
string W, H;
cin >> W;
H = "Yes";
if ((W.size() - 1) % 2 == 0) {
rep(i, (W.size() - 1) / 2) {
if (W.at(i * 2 - 1) != 'h' || W.at(i * 2) != 'i') {
H = "No";
}
}
} else {
H = "No";
}
cout << H << endl;
}
| #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iomanip>
#include <iostream>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <stdio.h>
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
string W, H;
cin >> W;
H = "Yes";
if ((W.size()) % 2 == 0) {
rep(i, (W.size()) / 2) {
if (W.at(i * 2) != 'h' || W.at(i * 2 + 1) != 'i') {
H = "No";
}
}
} else {
H = "No";
}
cout << H << endl;
}
| replace | 27 | 30 | 27 | 30 | 0 | |
p02747 | Python | Runtime Error | S = input()
ok = True
for i in range(0, len(S), 2):
if not (S[i] == "h" and S[i + 1] == "i"):
ok = False
break
print("Yes" if ok else "No")
| S = input()
ok = True
for i in range(0, len(S), 2):
try:
if not (S[i] == "h" and S[i + 1] == "i"):
ok = False
break
except IndexError:
ok = False
break
print("Yes" if ok else "No")
| replace | 3 | 4 | 3 | 8 | 0 | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b, m;
cin >> a >> b >> m;
vector<int> va(a);
vector<int> vb(b);
for (int i = 0; i < a; i++)
cin >> va.at(i);
for (int i = 0; i < b; i++)
cin >> vb.at(i);
int ans = 2000001;
for (int i = 0; i < m; i++) {
int m1, m2, m3;
cin >> m1 >> m2 >> m3;
ans = min(ans, va.at(m1 - 1) + vb.at(m2 - 1) - m3);
}
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++)
ans = min(ans, va.at(i) + vb.at(j));
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int a, b, m;
cin >> a >> b >> m;
vector<int> va(a);
vector<int> vb(b);
for (int i = 0; i < a; i++)
cin >> va.at(i);
for (int i = 0; i < b; i++)
cin >> vb.at(i);
int ans = 2000001;
for (int i = 0; i < m; i++) {
int m1, m2, m3;
cin >> m1 >> m2 >> m3;
ans = min(ans, va.at(m1 - 1) + vb.at(m2 - 1) - m3);
}
sort(va.begin(), va.end());
sort(vb.begin(), vb.end());
ans = min(ans, va.at(0) + vb.at(0));
cout << ans << endl;
return 0;
} | replace | 21 | 24 | 21 | 24 | TLE | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
signed main(void) {
int A, B, m;
cin >> A >> B >> m;
int a[A], b[B];
int x[m], y[m], c[m];
int ans = 1e9;
rep(i, A) cin >> a[i];
rep(i, B) cin >> b[i];
rep(i, A) rep(j, B) ans = min(ans, a[i] + b[j]);
rep(i, m) {
cin >> x[i] >> y[i] >> c[i];
x[i]--;
y[i]--;
ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
signed main(void) {
int A, B, m;
cin >> A >> B >> m;
int a[A], b[B];
int x[m], y[m], c[m];
int ans, min_a, min_b;
min_a = min_b = 1e9;
rep(i, A) {
cin >> a[i];
min_a = min(a[i], min_a);
}
rep(i, B) {
cin >> b[i];
min_b = min(b[i], min_b);
}
ans = min_a + min_b;
rep(i, m) {
cin >> x[i] >> y[i] >> c[i];
x[i]--;
y[i]--;
ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
}
cout << ans << endl;
return 0;
}
| replace | 9 | 13 | 9 | 20 | TLE | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, m, z;
int a[10010], b[10010];
int out = 1000000, min2 = 1000000;
int main() {
cin >> n >> m >> z;
for (int i = 1; i <= n; i++) {
cin >> a[i];
out = min(out, a[i]);
}
for (int i = 1; i <= m; i++) {
cin >> b[i];
min2 = min(min2, b[i]);
}
out += min2;
for (int i = 1; i <= z; i++) {
int in1, in2, in3;
cin >> in1 >> in2 >> in3;
out = min(out, a[in1] + b[in2] - in3);
}
cout << out;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n, m, z;
int a[100010], b[100010];
int out = 1000000, min2 = 1000000;
int main() {
cin >> n >> m >> z;
for (int i = 1; i <= n; i++) {
cin >> a[i];
out = min(out, a[i]);
}
for (int i = 1; i <= m; i++) {
cin >> b[i];
min2 = min(min2, b[i]);
}
out += min2;
for (int i = 1; i <= z; i++) {
int in1, in2, in3;
cin >> in1 >> in2 >> in3;
out = min(out, a[in1] + b[in2] - in3);
}
cout << out;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, a, B, b, M;
cin >> A >> B >> M;
a = 100000;
b = 100000;
vector<int> vA(A + 1);
for (int i = 1; i <= A; i++) {
cin >> vA.at(i);
}
vector<int> vB(B + 1);
for (int i = 1; i <= B; i++) {
cin >> vB.at(i);
}
for (int i = 1; i < A; i++) {
a = min(a, vA.at(i));
}
for (int i = 1; i < B; i++) {
b = min(b, vB.at(i));
}
a += b;
for (int i = 0; i < M; i++) {
int x, y, c;
cin >> x >> y >> c;
a = min(a, vA.at(x) + vA.at(y) - c);
}
cout << a << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int A, a, B, b, M;
cin >> A >> B >> M;
a = 100000;
b = 100000;
vector<int> vA(A + 1);
for (int i = 1; i <= A; i++) {
cin >> vA.at(i);
}
vector<int> vB(B + 1);
for (int i = 1; i <= B; i++) {
cin >> vB.at(i);
}
for (int i = 1; i < A; i++) {
a = min(a, vA.at(i));
}
for (int i = 1; i < B; i++) {
b = min(b, vB.at(i));
}
a += b;
for (int i = 0; i < M; i++) {
int x, y, c;
cin >> x >> y >> c;
a = min(a, vA.at(x) + vB.at(y) - c);
}
cout << a << endl;
}
| replace | 26 | 27 | 26 | 27 | 0 | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v, n) memset(v, (li)n, sizeof(v))
#define bit(n) (1ll << (li)(n))
#define mp(a, b) make_pair(a, b)
#define rin rep(i, n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1777777777ll
typedef pair<li, li> PI;
#define INF bit(60)
#define DBGP 1
#define idp if (DBGP)
#define F first
#define S second
#define p2(a, b) idp cout << a << "\t" << b << endl
#define p3(a, b, c) idp cout << a << "\t" << b << "\t" << c << endl
#define p4(a, b, c, d) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << endl
#define p5(a, b, c, d, e) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << endl
#define p6(a, b, c, d, e, f) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << endl
#define p7(a, b, c, d, e, f, g) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << endl
#define p8(a, b, c, d, e, f, g, h) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << endl
#define p9(a, b, c, d, e, f, g, h, i) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << endl
#define p10(a, b, c, d, e, f, g, h, i, j) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << "\t" << j << endl
#define foreach(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define p2p(x) idp p2((x).F, (x).S)
#define dump(x, n) \
idp { \
rep(i, n) { cout << x[i] << " "; } \
puts(""); \
}
#define dump2(x, n) \
idp { \
rep(i, n) { cout << "[" << x[i].F << " , " << x[i].S << "] "; } \
puts(""); \
}
#define dumpi(x) \
idp { \
foreach (it, x) { \
cout << (*it) << " "; \
} \
puts(""); \
}
#define dumpi2(x) \
idp { \
foreach (it, x) { \
cout << "[" << (it)->F << " , " << (it)->S << "] "; \
} \
puts(""); \
}
#define read(a, n) rep(i, n) cin >> a[i]
#define read2d(a, w, h) rep(i, h) rep(j, w) cin >> a[i][j]
#define dump2d(a, w, h) \
rep(i, h) { \
rep(j, w) cout << a[i][j] << " "; \
puts(""); \
}
typedef pair<li, li> PI;
li a[111];
li b[111];
int main() {
li na, nb, m;
cin >> na >> nb >> m;
read(a, na);
read(b, nb);
li ma = *min_element(a, a + na);
li mb = *min_element(b, b + nb);
li res = ma + mb;
rep(i, m) {
li x, y, c;
cin >> x >> y >> c;
x--;
y--;
res = min(res, a[x] + b[y] - c);
}
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v, n) memset(v, (li)n, sizeof(v))
#define bit(n) (1ll << (li)(n))
#define mp(a, b) make_pair(a, b)
#define rin rep(i, n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1777777777ll
typedef pair<li, li> PI;
#define INF bit(60)
#define DBGP 1
#define idp if (DBGP)
#define F first
#define S second
#define p2(a, b) idp cout << a << "\t" << b << endl
#define p3(a, b, c) idp cout << a << "\t" << b << "\t" << c << endl
#define p4(a, b, c, d) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << endl
#define p5(a, b, c, d, e) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << endl
#define p6(a, b, c, d, e, f) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << endl
#define p7(a, b, c, d, e, f, g) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << endl
#define p8(a, b, c, d, e, f, g, h) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << endl
#define p9(a, b, c, d, e, f, g, h, i) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << endl
#define p10(a, b, c, d, e, f, g, h, i, j) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << "\t" << j << endl
#define foreach(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define p2p(x) idp p2((x).F, (x).S)
#define dump(x, n) \
idp { \
rep(i, n) { cout << x[i] << " "; } \
puts(""); \
}
#define dump2(x, n) \
idp { \
rep(i, n) { cout << "[" << x[i].F << " , " << x[i].S << "] "; } \
puts(""); \
}
#define dumpi(x) \
idp { \
foreach (it, x) { \
cout << (*it) << " "; \
} \
puts(""); \
}
#define dumpi2(x) \
idp { \
foreach (it, x) { \
cout << "[" << (it)->F << " , " << (it)->S << "] "; \
} \
puts(""); \
}
#define read(a, n) rep(i, n) cin >> a[i]
#define read2d(a, w, h) rep(i, h) rep(j, w) cin >> a[i][j]
#define dump2d(a, w, h) \
rep(i, h) { \
rep(j, w) cout << a[i][j] << " "; \
puts(""); \
}
typedef pair<li, li> PI;
li a[100100];
li b[100100];
int main() {
li na, nb, m;
cin >> na >> nb >> m;
read(a, na);
read(b, nb);
li ma = *min_element(a, a + na);
li mb = *min_element(b, b + nb);
li res = ma + mb;
rep(i, m) {
li x, y, c;
cin >> x >> y >> c;
x--;
y--;
res = min(res, a[x] + b[y] - c);
}
cout << res << endl;
return 0;
}
| replace | 87 | 89 | 87 | 89 | 0 | |
p02748 | Python | Runtime Error | A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = []
s.append(min(a) + min(b))
for i in range(M):
x_i, y_i, c_i = map(int, input().split())
minus = a[x_i - 1] + a[y_i - 1] - c_i
s.append(minus)
print(min(s))
| A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = []
s.append(min(a) + min(b))
for i in range(M):
x_i, y_i, c_i = map(int, input().split())
minus = a[x_i - 1] + b[y_i - 1] - c_i
s.append(minus)
print(min(s))
| replace | 9 | 10 | 9 | 10 | 0 | |
p02748 | Python | Runtime Error | A, B, M = map(int, input().split())
x, y, c = [0] * M, [0] * M, [0] * M
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(M):
x[i], y[i], c[i] = map(int, input().split())
ans = 0
sav = 0
maxc = max(c)
ci = c.index(maxc)
disc = a[ci - 1] + b[ci - 1] - maxc
print(min(disc, min(a) + min(b)))
| A, B, M = map(int, input().split())
x, y, c = [0] * M, [0] * M, [0] * M
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(M):
x[i], y[i], c[i] = map(int, input().split())
ans, sav = float("inf"), 0
for j in range(M):
sav = a[x[j] - 1] + b[y[j] - 1] - c[j]
if ans > sav:
ans = sav
print(min(ans, min(a) + min(b)))
| replace | 6 | 12 | 6 | 13 | 0 | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a, b) for (int a = 0; a < b; a++)
#define Sort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(), a.end()), a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int, vector<int>, greater<int>>
#define PriP \
priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a) (a).begin(), (a).end()
#define elif else if
int low(V<int> &a, int b) {
auto c = lower_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
int upp(V<int> &a, int b) {
auto c = upper_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
template <class T> void cou(vector<vector<T>> a) {
int b = a.size();
int c = a[0].size();
fo(i, b) {
fo(j, c) {
cout << a[i][j];
if (j == c - 1)
cout << endl;
else
cout << ' ';
}
}
}
int wari(int a, int b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
int keta(int a) {
double b = a;
b = log10(b);
int c = b;
return c + 1;
}
int souwa(int a) { return a * (a + 1) / 2; }
int gcm(int a, int b) {
if (a % b == 0)
return b;
return gcm(b, a % b);
}
bool prime(int a) {
if (a < 2)
return false;
else if (a == 2)
return true;
else if (a % 2 == 0)
return false;
for (int i = 3; i <= sqrt(a) + 1; i += 2) {
if (a % i == 0)
return false;
}
return true;
}
struct Union {
vector<int> par;
Union(int a) { par = vector<int>(a, -1); }
int find(int a) {
if (par[a] < 0)
return a;
else
return par[a] = find(par[a]);
}
bool same(int a, int b) { return find(a) == find(b); }
int Size(int a) { return -par[find(a)]; }
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return;
if (Size(b) > Size(a))
swap<int>(a, b);
par[a] += par[b];
par[b] = a;
}
};
int ketas(int a) {
string b = to_string(a);
int c = 0;
fo(i, keta(a)) { c += b[i] - '0'; }
return c;
}
bool fe(int a, int b) {
a %= 10;
b %= 10;
if (a == 0)
a = 10;
if (b == 0)
b = 10;
if (a > b)
return true;
else
return false;
}
int INF = 1000000007;
struct edge {
int s, t, d;
};
V<int> mojisyu(string a) {
V<int> b(26, 0);
fo(i, a.sz) { b[a[i] - 'a']++; }
return b;
}
int wa2(int a) {
if (a % 2 == 1)
return a / 2;
return a / 2 - 1;
}
/*signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}
?*/
int nCr(int n, int r) {
int a = 1;
r = min(r, n - r);
for (int i = n; i > n - r; i--) {
a *= i;
a /= n - i + 1;
}
return a;
}
/*void sea(int x,int y){
if(x<0||a<=x||y<0||b<=y||c[x][y]=='#')
return;
if(d[x][y])
return;
d[x][y]++;
sea(x+1,y);
sea(x-1,y);
sea(x,y+1);
sea(x,y-1);
}*/
int kaijou(int a) {
int b = 1;
fo(i, a) b *= i + 1;
return b;
}
int nPr(int a, int b) {
if (a < b)
return 0;
if (b == 0)
return 1;
int c = 1;
for (int i = a; i > a - b; i--) {
c *= i;
c %= INF;
}
return c;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
int lcm(int a, int b) {
int c = modinv(gcm(a, b), INF);
return ((a * c) % INF) * (b % INF) % INF;
}
int MOD = INF;
int fac[1000010], finv[1000010], inv[1000010];
// テーブルを作る前処理
// 先にCOMinit()で前処理をする
// ABC145D
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 1000010; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
int COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
bool naka(int a, int b, V<V<char>> c) {
return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz);
}
V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0},
{-1, -1}, {1, 1}, {1, -1}, {-1, -1}};
int inf = 1000000000000000007;
/*
signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}*/
V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
// 最短経路の表 a(全部INFで初期化)
// 縦横 x,y
// 迷路 f
// スタートsx,sy
// ゴールgx,gy
// 文字はgから使おうね
/*int bfs_haba(){
Q<P<int,int>> b;
a[sx][sy]=0;
b.push({sx,sy});
while(!b.empty()){
P<int,int> c=b.front();
b.pop();
if(c.fi==gx&&c.se==gy){
break;
}
fo(i,4){
int d=c.fi+mawari4[i].fi;
int e=c.se+mawari4[i].se;
if(0<=d&&0<=e&&d<x&&e<y&&f[d][e]!='#'&&a[d][e]==INF){
b.push({d,e});
a[d][e]=1+a[c.fi][c.se];
}
}
}
return a[gx][gy];
}*/
V<int> onajibubun(string a) {
V<int> b(a.sz);
for (int i = 1, j = 0; i < a.sz; i++) {
if (i + b[i - j] < j + b[j])
b[i] = b[i - j];
else {
int c = max<int>(0, j + b[j] - i);
while (i + c < a.sz && a[c] == a[i + c])
c++;
b[i] = c;
j = i;
}
}
b[0] = a.sz;
return b;
}
// 各頂点ごとにどこに辺が出てるかの表がc
// 各頂点ごとの色を表すV<int>(頂点数max)のcolorを用意する
// aはどこ塗るか、bは何で塗るかなので、(0,1,c)でよぶとおけ
V<int> color(205);
bool nibu_hantei(int a, int b, V<V<int>> c) {
color[a] = b;
fo(i, c[a].sz) {
if (b == color[c[a][i]])
return false;
if (color[c[a][i]] == 0 && !nibu_hantei(c[a][i], -b, c))
return false;
}
return true;
}
// aは頂点数
// nibu_hanteiの上にcolorを用意する
// 各頂点ごとにどこに辺が出てるかの表がc
bool renketujanai_nibu_hantei(int a, V<V<int>> c) {
fo(i, a) {
if (color[i] == 0) {
if (!nibu_hantei(i, 1, c))
return false;
}
}
return true;
}
struct segmin {
vector<int> seg;
int b;
segmin(V<int> a) {
b = 1;
while (b < a.sz)
b *= 2;
seg = vector<int>(2 * b - 1, inf);
fo(i, a.sz) { seg[i + b - 1] = a[i]; }
for (int i = b - 2; i >= 0; i--) {
seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]);
}
}
void update(int i, int a) {
i += b - 1;
seg[i] = a;
while (i) {
i = (i - 1) / 2;
seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]);
}
}
// 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで
// l,rは探すところ
int getmin(int x, int y, int a, int l, int r) {
if (r == INF)
r = b;
if (r <= x || y <= l)
return INF;
if (x <= l && r <= y)
return seg[a];
int a1 = getmin(x, y, 2 * a + 1, l, (l + r) / 2);
int a2 = getmin(x, y, 2 * a + 2, (l + r) / 2, r);
return min(a1, a2);
}
};
struct segadd {
vector<int> seg;
int b;
segadd(V<int> a) {
b = 1;
while (b < a.sz)
b *= 2;
seg = vector<int>(2 * b - 1, 0);
fo(i, a.sz) { seg[i + b - 1] = a[i]; }
for (int i = b - 2; i >= 0; i--) {
seg[i] = seg[2 * i + 1] + seg[2 * i + 2];
}
}
void update(int i, int a) {
i += b - 1;
seg[i] = a;
while (i) {
i = (i - 1) / 2;
seg[i] = seg[2 * i + 1] + seg[2 * i + 2];
}
}
// 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで
// l,rは探すところ
int getadd(int x, int y, int a, int l, int r) {
if (r == INF)
r = b;
if (r <= x || y <= l)
return 0;
if (x <= l && r <= y)
return seg[a];
int a1 = getadd(x, y, 2 * a + 1, l, (l + r) / 2);
int a2 = getadd(x, y, 2 * a + 2, (l + r) / 2, r);
return a1 + a2;
}
};
struct sege {
vector<P<int, V<int>>> seg;
int b;
sege(string a) {
b = 1;
while (b < a.sz)
b *= 2;
seg = vector<P<int, V<int>>>(2 * b - 1);
fo(i, a.sz) {
seg[i + b - 1].fi = 1;
seg[i + b - 1].se.pb(a[i] - 'a');
}
for (int i = b - 2; i >= 0; i--) {
V<int> d = seg[2 * i + 1].se;
fo(j, seg[2 * i + 2].se.sz) { d.pb(seg[2 * i + 2].se[j]); }
Sort(d);
uni(d);
seg[i].se = d;
seg[i].fi = d.sz;
}
}
V<int> mu;
void update(int i, char a) {
i += b - 1;
seg[i].se = mu;
seg[i].se.pb(a - 'a');
seg[i].fi = 1;
while (i) {
i = (i - 1) / 2;
V<int> d = seg[2 * i + 1].se;
fo(j, seg[2 * i + 2].se.sz) { d.pb(seg[2 * i + 2].se[j]); }
Sort(d);
uni(d);
seg[i].se = d;
seg[i].fi = d.sz;
}
}
void unko() { fo(i, 2 * b - 1) cout << seg[i].fi << ' '; }
// 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで
// l,rは探すところ
P<int, V<int>> gete(int x, int y, int a, int l, int r) {
if (r == INF)
r = b;
if (r <= x || y <= l)
return {0, mu};
if (x <= l && r <= y)
return seg[a];
P<int, V<int>> a1 = gete(x, y, 2 * a + 1, l, (l + r) / 2);
P<int, V<int>> a2 = gete(x, y, 2 * a + 2, (l + r) / 2, r);
fo(i, a2.se.sz) a1.se.pb(a2.se[i]);
Sort(a1.se);
uni(a1.se);
return {a1.se.sz, a1.se};
}
};
signed main() {
int a, b, c;
cin >> a >> b >> c;
V<int> d, e;
fo(i, a) cin >> d[i];
fo(i, b) cin >> e[i];
V<P<P<int, int>, int>> f(c);
fo(i, c) {
cin >> f[i].ff >> f[i].fs >> f[i].se;
f[i].ff--;
f[i].fs--;
}
int f1 = inf, f2 = inf;
fo(i, a) { f1 = min(f1, d[i]); }
fo(i, b) { f2 = min(f2, e[i]); }
int g = f1 + f2;
fo(i, c) {
int h = d[f[i].ff] + e[f[i].fs] - f[i].se;
g = min(g, h);
}
cout << g << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a, b) for (int a = 0; a < b; a++)
#define Sort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(), a.end()), a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int, vector<int>, greater<int>>
#define PriP \
priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a) (a).begin(), (a).end()
#define elif else if
int low(V<int> &a, int b) {
auto c = lower_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
int upp(V<int> &a, int b) {
auto c = upper_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
template <class T> void cou(vector<vector<T>> a) {
int b = a.size();
int c = a[0].size();
fo(i, b) {
fo(j, c) {
cout << a[i][j];
if (j == c - 1)
cout << endl;
else
cout << ' ';
}
}
}
int wari(int a, int b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
int keta(int a) {
double b = a;
b = log10(b);
int c = b;
return c + 1;
}
int souwa(int a) { return a * (a + 1) / 2; }
int gcm(int a, int b) {
if (a % b == 0)
return b;
return gcm(b, a % b);
}
bool prime(int a) {
if (a < 2)
return false;
else if (a == 2)
return true;
else if (a % 2 == 0)
return false;
for (int i = 3; i <= sqrt(a) + 1; i += 2) {
if (a % i == 0)
return false;
}
return true;
}
struct Union {
vector<int> par;
Union(int a) { par = vector<int>(a, -1); }
int find(int a) {
if (par[a] < 0)
return a;
else
return par[a] = find(par[a]);
}
bool same(int a, int b) { return find(a) == find(b); }
int Size(int a) { return -par[find(a)]; }
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return;
if (Size(b) > Size(a))
swap<int>(a, b);
par[a] += par[b];
par[b] = a;
}
};
int ketas(int a) {
string b = to_string(a);
int c = 0;
fo(i, keta(a)) { c += b[i] - '0'; }
return c;
}
bool fe(int a, int b) {
a %= 10;
b %= 10;
if (a == 0)
a = 10;
if (b == 0)
b = 10;
if (a > b)
return true;
else
return false;
}
int INF = 1000000007;
struct edge {
int s, t, d;
};
V<int> mojisyu(string a) {
V<int> b(26, 0);
fo(i, a.sz) { b[a[i] - 'a']++; }
return b;
}
int wa2(int a) {
if (a % 2 == 1)
return a / 2;
return a / 2 - 1;
}
/*signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}
?*/
int nCr(int n, int r) {
int a = 1;
r = min(r, n - r);
for (int i = n; i > n - r; i--) {
a *= i;
a /= n - i + 1;
}
return a;
}
/*void sea(int x,int y){
if(x<0||a<=x||y<0||b<=y||c[x][y]=='#')
return;
if(d[x][y])
return;
d[x][y]++;
sea(x+1,y);
sea(x-1,y);
sea(x,y+1);
sea(x,y-1);
}*/
int kaijou(int a) {
int b = 1;
fo(i, a) b *= i + 1;
return b;
}
int nPr(int a, int b) {
if (a < b)
return 0;
if (b == 0)
return 1;
int c = 1;
for (int i = a; i > a - b; i--) {
c *= i;
c %= INF;
}
return c;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// a^{-1} mod を計算する
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
int lcm(int a, int b) {
int c = modinv(gcm(a, b), INF);
return ((a * c) % INF) * (b % INF) % INF;
}
int MOD = INF;
int fac[1000010], finv[1000010], inv[1000010];
// テーブルを作る前処理
// 先にCOMinit()で前処理をする
// ABC145D
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 1000010; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
int COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
bool naka(int a, int b, V<V<char>> c) {
return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz);
}
V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0},
{-1, -1}, {1, 1}, {1, -1}, {-1, -1}};
int inf = 1000000000000000007;
/*
signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}*/
V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
// 最短経路の表 a(全部INFで初期化)
// 縦横 x,y
// 迷路 f
// スタートsx,sy
// ゴールgx,gy
// 文字はgから使おうね
/*int bfs_haba(){
Q<P<int,int>> b;
a[sx][sy]=0;
b.push({sx,sy});
while(!b.empty()){
P<int,int> c=b.front();
b.pop();
if(c.fi==gx&&c.se==gy){
break;
}
fo(i,4){
int d=c.fi+mawari4[i].fi;
int e=c.se+mawari4[i].se;
if(0<=d&&0<=e&&d<x&&e<y&&f[d][e]!='#'&&a[d][e]==INF){
b.push({d,e});
a[d][e]=1+a[c.fi][c.se];
}
}
}
return a[gx][gy];
}*/
V<int> onajibubun(string a) {
V<int> b(a.sz);
for (int i = 1, j = 0; i < a.sz; i++) {
if (i + b[i - j] < j + b[j])
b[i] = b[i - j];
else {
int c = max<int>(0, j + b[j] - i);
while (i + c < a.sz && a[c] == a[i + c])
c++;
b[i] = c;
j = i;
}
}
b[0] = a.sz;
return b;
}
// 各頂点ごとにどこに辺が出てるかの表がc
// 各頂点ごとの色を表すV<int>(頂点数max)のcolorを用意する
// aはどこ塗るか、bは何で塗るかなので、(0,1,c)でよぶとおけ
V<int> color(205);
bool nibu_hantei(int a, int b, V<V<int>> c) {
color[a] = b;
fo(i, c[a].sz) {
if (b == color[c[a][i]])
return false;
if (color[c[a][i]] == 0 && !nibu_hantei(c[a][i], -b, c))
return false;
}
return true;
}
// aは頂点数
// nibu_hanteiの上にcolorを用意する
// 各頂点ごとにどこに辺が出てるかの表がc
bool renketujanai_nibu_hantei(int a, V<V<int>> c) {
fo(i, a) {
if (color[i] == 0) {
if (!nibu_hantei(i, 1, c))
return false;
}
}
return true;
}
struct segmin {
vector<int> seg;
int b;
segmin(V<int> a) {
b = 1;
while (b < a.sz)
b *= 2;
seg = vector<int>(2 * b - 1, inf);
fo(i, a.sz) { seg[i + b - 1] = a[i]; }
for (int i = b - 2; i >= 0; i--) {
seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]);
}
}
void update(int i, int a) {
i += b - 1;
seg[i] = a;
while (i) {
i = (i - 1) / 2;
seg[i] = min(seg[2 * i + 1], seg[2 * i + 2]);
}
}
// 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで
// l,rは探すところ
int getmin(int x, int y, int a, int l, int r) {
if (r == INF)
r = b;
if (r <= x || y <= l)
return INF;
if (x <= l && r <= y)
return seg[a];
int a1 = getmin(x, y, 2 * a + 1, l, (l + r) / 2);
int a2 = getmin(x, y, 2 * a + 2, (l + r) / 2, r);
return min(a1, a2);
}
};
struct segadd {
vector<int> seg;
int b;
segadd(V<int> a) {
b = 1;
while (b < a.sz)
b *= 2;
seg = vector<int>(2 * b - 1, 0);
fo(i, a.sz) { seg[i + b - 1] = a[i]; }
for (int i = b - 2; i >= 0; i--) {
seg[i] = seg[2 * i + 1] + seg[2 * i + 2];
}
}
void update(int i, int a) {
i += b - 1;
seg[i] = a;
while (i) {
i = (i - 1) / 2;
seg[i] = seg[2 * i + 1] + seg[2 * i + 2];
}
}
// 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで
// l,rは探すところ
int getadd(int x, int y, int a, int l, int r) {
if (r == INF)
r = b;
if (r <= x || y <= l)
return 0;
if (x <= l && r <= y)
return seg[a];
int a1 = getadd(x, y, 2 * a + 1, l, (l + r) / 2);
int a2 = getadd(x, y, 2 * a + 2, (l + r) / 2, r);
return a1 + a2;
}
};
struct sege {
vector<P<int, V<int>>> seg;
int b;
sege(string a) {
b = 1;
while (b < a.sz)
b *= 2;
seg = vector<P<int, V<int>>>(2 * b - 1);
fo(i, a.sz) {
seg[i + b - 1].fi = 1;
seg[i + b - 1].se.pb(a[i] - 'a');
}
for (int i = b - 2; i >= 0; i--) {
V<int> d = seg[2 * i + 1].se;
fo(j, seg[2 * i + 2].se.sz) { d.pb(seg[2 * i + 2].se[j]); }
Sort(d);
uni(d);
seg[i].se = d;
seg[i].fi = d.sz;
}
}
V<int> mu;
void update(int i, char a) {
i += b - 1;
seg[i].se = mu;
seg[i].se.pb(a - 'a');
seg[i].fi = 1;
while (i) {
i = (i - 1) / 2;
V<int> d = seg[2 * i + 1].se;
fo(j, seg[2 * i + 2].se.sz) { d.pb(seg[2 * i + 2].se[j]); }
Sort(d);
uni(d);
seg[i].se = d;
seg[i].fi = d.sz;
}
}
void unko() { fo(i, 2 * b - 1) cout << seg[i].fi << ' '; }
// 最初呼び出すときは要求区間x,y+1(yは添え字+1)とa=0,l=0,r=INFで
// l,rは探すところ
P<int, V<int>> gete(int x, int y, int a, int l, int r) {
if (r == INF)
r = b;
if (r <= x || y <= l)
return {0, mu};
if (x <= l && r <= y)
return seg[a];
P<int, V<int>> a1 = gete(x, y, 2 * a + 1, l, (l + r) / 2);
P<int, V<int>> a2 = gete(x, y, 2 * a + 2, (l + r) / 2, r);
fo(i, a2.se.sz) a1.se.pb(a2.se[i]);
Sort(a1.se);
uni(a1.se);
return {a1.se.sz, a1.se};
}
};
signed main() {
int a, b, c;
cin >> a >> b >> c;
V<int> d(a), e(b);
fo(i, a) cin >> d[i];
fo(i, b) cin >> e[i];
V<P<P<int, int>, int>> f(c);
fo(i, c) {
cin >> f[i].ff >> f[i].fs >> f[i].se;
f[i].ff--;
f[i].fs--;
}
int f1 = inf, f2 = inf;
fo(i, a) { f1 = min(f1, d[i]); }
fo(i, b) { f2 = min(f2, e[i]); }
int g = f1 + f2;
fo(i, c) {
int h = d[f[i].ff] + e[f[i].fs] - f[i].se;
g = min(g, h);
}
cout << g << endl;
} | replace | 488 | 489 | 488 | 489 | -11 | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void solve() {
int na, nb, m;
cin >> na >> nb >> m;
vector<int> a(na), b(nb);
rep(i, na) cin >> a[i];
rep(i, nb) cin >> b[i];
vector<int> x(m), y(m), c(m);
rep(i, m) cin >> x[i] >> y[i] >> c[i];
rep(i, m) x[i]--, y[i]--;
int ans = INF;
rep(i, m) { ans = min(ans, a[x[i]] + b[y[i]] - c[i]); }
rep(i, na) {
rep(j, nb) { ans = min(ans, a[i] + b[j]); }
}
cout << ans << endl;
}
int main() {
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
void solve() {
int na, nb, m;
cin >> na >> nb >> m;
vector<int> a(na), b(nb);
rep(i, na) cin >> a[i];
rep(i, nb) cin >> b[i];
vector<int> x(m), y(m), c(m);
rep(i, m) cin >> x[i] >> y[i] >> c[i];
rep(i, m) x[i]--, y[i]--;
int ans = INF;
rep(i, m) { ans = min(ans, a[x[i]] + b[y[i]] - c[i]); }
sort(ALL(a));
sort(ALL(b));
ans = min(ans, a[0] + b[0]);
cout << ans << endl;
}
int main() {
solve();
return 0;
} | replace | 23 | 26 | 23 | 26 | TLE | |
p02748 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int A, B, M;
int ans = 1000000;
int x, y, c;
int a_min = 100000;
int b_min = 100000;
cin >> A >> B >> M;
vector<int> a(A);
vector<int> b(B);
for (int i = 0; i < A; i++) {
cin >> a[i];
a_min = min(a[i], a_min);
}
for (int i = 0; i < A; i++) {
cin >> b[i];
b_min = min(b[i], b_min);
}
for (int i = 0; i < M; i++) {
cin >> x >> y >> c;
ans = min(ans, a[x - 1] + b[y - 1] - c);
}
ans = min(ans, a_min + b_min);
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int A, B, M;
int ans = 1000000;
int x, y, c;
int a_min = 100000;
int b_min = 100000;
cin >> A >> B >> M;
vector<int> a(A);
vector<int> b(B);
for (int i = 0; i < A; i++) {
cin >> a[i];
a_min = min(a[i], a_min);
}
for (int i = 0; i < B; i++) {
cin >> b[i];
b_min = min(b[i], b_min);
}
for (int i = 0; i < M; i++) {
cin >> x >> y >> c;
ans = min(ans, a[x - 1] + b[y - 1] - c);
}
ans = min(ans, a_min + b_min);
cout << ans << endl;
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p02748 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int lld;
int T;
int N, P;
int check[1000001];
int A, B, M;
vector<int> a;
vector<int> b;
int m1 = 1e9;
int m2 = 1e9;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> A >> B >> M;
for (int i = 0; i < A; i++) {
int t;
cin >> t;
m1 = min(t, m1);
a.push_back(t);
}
for (int i = 0; i < B; i++) {
int t;
cin >> t;
m2 = min(t, m2);
b.push_back(t);
}
m1 = m1 + m2;
for (int i = 0; i < M; i++) {
int aa, bb, mm;
cin >> aa >> bb >> mm;
m1 = min(m1, a[aa - 1] + b[aa - 1] - mm);
}
cout << m1;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int lld;
int T;
int N, P;
int check[1000001];
int A, B, M;
vector<int> a;
vector<int> b;
int m1 = 1e9;
int m2 = 1e9;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> A >> B >> M;
for (int i = 0; i < A; i++) {
int t;
cin >> t;
m1 = min(t, m1);
a.push_back(t);
}
for (int i = 0; i < B; i++) {
int t;
cin >> t;
m2 = min(t, m2);
b.push_back(t);
}
m1 = m1 + m2;
for (int i = 0; i < M; i++) {
int aa, bb, mm;
cin >> aa >> bb >> mm;
m1 = min(m1, a[aa - 1] + b[bb - 1] - mm);
}
cout << m1;
return 0;
}
| replace | 41 | 42 | 41 | 42 | 0 | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, m;
cin >> A >> B >> m;
vector<int> a(A);
for (int i = 0; i < A; i++)
cin >> a.at(i);
vector<int> b(B);
for (int i = 0; i < B; i++)
cin >> b.at(i);
int money = 200000;
for (int i = 0; i < m; i++) {
int x, y, z;
cin >> x >> y >> z;
money = min(money, a.at(x - 1) + b.at(y - 1) - z);
}
for (int i = 0; i < A; i++) {
for (int j = 0; j < B; j++) {
money = min(money, a.at(i) + b.at(i));
}
}
cout << money << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, m;
cin >> A >> B >> m;
vector<int> a(A);
for (int i = 0; i < A; i++)
cin >> a.at(i);
vector<int> b(B);
for (int i = 0; i < B; i++)
cin >> b.at(i);
int money = 200000;
for (int i = 0; i < m; i++) {
int x, y, z;
cin >> x >> y >> z;
money = min(money, a.at(x - 1) + b.at(y - 1) - z);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
cout << min(money, a.at(0) + b.at(0)) << endl;
} | replace | 20 | 26 | 20 | 23 | 0 | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using ll = long long;
template <class T> using vt = vector<T>;
using vvi = vector<vector<int>>;
int main() {
int A, B, M;
cin >> A >> B >> M;
vt<int> a(A), b(B), x(M), y(M), c(M);
rep(i, A) cin >> a[i];
rep(i, B) cin >> b[i];
rep(i, M) cin >> x[i] >> y[i] >> c[i];
int ans = 1000000;
rep(i, A) {
int minm = 0;
rep(j, B) {
minm = a[i] + b[j];
ans = min(ans, minm);
}
}
rep(i, M) { ans = min(ans, (a[x[i] - 1] + b[y[i] - 1] - c[i])); }
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using ll = long long;
template <class T> using vt = vector<T>;
using vvi = vector<vector<int>>;
int main() {
int A, B, M;
cin >> A >> B >> M;
vt<int> a(A), b(B), x(M), y(M), c(M);
rep(i, A) cin >> a[i];
rep(i, B) cin >> b[i];
rep(i, M) cin >> x[i] >> y[i] >> c[i];
int min_a = *min_element(a.begin(), a.end());
int min_b = *min_element(b.begin(), b.end());
int ans = min_a + min_b;
rep(i, M) { ans = min(ans, (a[x[i] - 1] + b[y[i] - 1] - c[i])); }
cout << ans;
return 0;
}
| replace | 16 | 24 | 16 | 19 | TLE | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, a, b) for (int i = (a); i < (b); i++)
typedef long long ll;
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
int a[A], b[B];
rep(i, A) { cin >> a[i]; }
rep(i, B) { cin >> b[i]; }
int x[M], y[M], c[M];
rep(i, M) { cin >> x[i] >> y[i] >> c[i]; }
int ans = 100000000;
rep(i, M) {
int tmp = a[x[i] - 1] + b[y[i] - 1] - c[i];
ans = min(ans, tmp);
}
sort(a, a + M);
sort(b, b + M);
int q = a[0] + b[0];
ans = min(ans, q);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, a, b) for (int i = (a); i < (b); i++)
typedef long long ll;
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
int a[A], b[B];
rep(i, A) { cin >> a[i]; }
rep(i, B) { cin >> b[i]; }
int x[M], y[M], c[M];
rep(i, M) { cin >> x[i] >> y[i] >> c[i]; }
int ans = 100000000;
rep(i, M) {
int tmp = a[x[i] - 1] + b[y[i] - 1] - c[i];
ans = min(ans, tmp);
}
int mina = 1000000;
int minb = 1000000;
rep(i, A) {
if (a[i] < mina)
mina = a[i];
}
rep(i, B) {
if (b[i] < minb)
minb = b[i];
}
int q = mina + minb;
ans = min(ans, q);
cout << ans << endl;
return 0;
} | replace | 22 | 25 | 22 | 33 | 0 | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define invrep(i, n) for (int64_t i = n - 1; i >= 0; i--)
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
int64_t a, b, m;
cin >> a >> b >> m;
vector<int64_t> av(a), bv(b);
rep(i, a) { cin >> av[i]; }
rep(i, b) { cin >> bv[i]; }
int64_t minp = 100000000000000;
rep(i, a) {
rep(j, b) {
minp = min(minp, av[i] + bv[j]);
// cout << av[i]+bv[j] << endl;
}
}
rep(i, m) {
int64_t q, w, e;
cin >> q >> w >> e;
minp = min(minp, av[q - 1] + bv[w - 1] - e);
}
cout << minp << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define invrep(i, n) for (int64_t i = n - 1; i >= 0; i--)
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
int64_t a, b, m;
cin >> a >> b >> m;
vector<int64_t> av(a), bv(b);
rep(i, a) { cin >> av[i]; }
rep(i, b) { cin >> bv[i]; }
int64_t minp = 100000000000000;
minp = *(min_element(av.begin(), av.end())) +
*(min_element(bv.begin(), bv.end()));
rep(i, m) {
int64_t q, w, e;
cin >> q >> w >> e;
minp = min(minp, av[q - 1] + bv[w - 1] - e);
}
cout << minp << endl;
}
| replace | 13 | 19 | 13 | 15 | TLE | |
p02748 | C++ | Runtime Error | // #include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) { \
cout << x << ' '; \
} \
cout << endl;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
// cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
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 A, B, m;
vector<int> a, b;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> A >> B >> m;
for (int i = 0; i < A; i++) {
int temp;
cin >> temp;
a.push_back(temp);
}
for (int i = 0; i < B; i++) {
int temp;
cin >> temp;
b.push_back(temp);
}
vector<ll> ans;
rep(i, m) {
int temp, temp1, cost;
cin >> temp >> temp1 >> cost;
temp--;
temp1--;
ans.push_back(a[temp] + b[temp] - cost);
}
sort(ALL(a));
sort(ALL(b));
ans.push_back(a[0] + b[0]);
sort(ALL(ans));
cout << ans[0] << "\n";
}
| // #include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) \
cout << #v << ":"; \
for (auto x : v) { \
cout << x << ' '; \
} \
cout << endl;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
// cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
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 A, B, m;
vector<int> a, b;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> A >> B >> m;
for (int i = 0; i < A; i++) {
int temp;
cin >> temp;
a.push_back(temp);
}
for (int i = 0; i < B; i++) {
int temp;
cin >> temp;
b.push_back(temp);
}
vector<ll> ans;
rep(i, m) {
int temp, temp1, cost;
cin >> temp >> temp1 >> cost;
temp--;
temp1--;
ans.push_back(a[temp] + b[temp1] - cost);
}
sort(ALL(a));
sort(ALL(b));
ans.push_back(a[0] + b[0]);
sort(ALL(ans));
cout << ans[0] << "\n";
}
| replace | 63 | 64 | 63 | 64 | 0 | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <climits>
using namespace std;
int main() {
long long int n, m, i, k, l, p = 0, j, sum, x = 1;
p = INT_MAX;
int t = INT_MAX;
cin >> n >> m >> k;
int a[n], b[m], c[k], d[k], e[k];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < m; i++) {
cin >> b[i];
}
for (i = 0; i < k; i++) {
cin >> c[i] >> d[i] >> e[i];
l = a[c[i] - 1] + b[d[i] - 1] - e[i];
if (p > l) {
p = l;
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
sum = a[i] + b[j];
if (sum < t) {
t = sum;
}
}
}
if (p > t) {
cout << t;
} else {
cout << p;
}
}
| #include <bits/stdc++.h>
#include <climits>
using namespace std;
int main() {
long long int n, m, i, k, l, p = 0, j, sum, x = 1;
p = INT_MAX;
int t = INT_MAX;
cin >> n >> m >> k;
int a[n], b[m], c[k], d[k], e[k];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < m; i++) {
cin >> b[i];
}
for (i = 0; i < k; i++) {
cin >> c[i] >> d[i] >> e[i];
l = a[c[i] - 1] + b[d[i] - 1] - e[i];
if (p > l) {
p = l;
}
}
sort(a, a + n);
sort(b, b + n);
t = a[0] + b[0];
if (p > t) {
cout << t;
} else {
cout << p;
}
}
| replace | 22 | 30 | 22 | 25 | TLE | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
int s = 200000, t = 200000;
vector<int> p(A + 1), q(B + 1);
for (int i = 1; i <= A; i++) {
cin >> p[i];
s = min(s, p[i]);
}
for (int i = 1; i <= B; i++) {
cin >> q.at(i);
t = min(t, q[i]);
}
int c = 200000;
int x, y, r;
for (int i = 1; i <= M; i++) {
cin >> x >> y >> r;
c = min(c, p[x] + q[y] - r);
}
for (int i = 1; i <= A; i++) {
for (int j = 1; j <= B; j++) {
c = min(c, p[i] + q[j]);
}
}
cout << min(c, s + t);
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
int s = 200000, t = 200000;
vector<int> p(A + 1), q(B + 1);
for (int i = 1; i <= A; i++) {
cin >> p[i];
s = min(s, p[i]);
}
for (int i = 1; i <= B; i++) {
cin >> q.at(i);
t = min(t, q[i]);
}
int c = 200000;
int x, y, r;
for (int i = 1; i <= M; i++) {
cin >> x >> y >> r;
c = min(c, p[x] + q[y] - r);
}
cout << min(c, s + t);
} | delete | 22 | 27 | 22 | 22 | TLE | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int A, B, M;
cin >> A >> B >> M;
vi a(A), b(B);
rep(i, A) cin >> a[i];
rep(i, B) cin >> b[i];
vi x(M), y(M), c(M);
rep(i, M) cin >> x[i] >> y[i] >> c[i];
int minval = a[0] + b[0];
rep(i, A) {
rep(j, B) {
int max_dis = 0;
rep(k, M) {
if (x[k] - 1 == i && y[k] - 1 == j) {
max_dis = max(max_dis, c[k]);
}
}
minval = min(minval, a[i] + b[j] - max_dis);
}
}
cout << minval << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int A, B, M;
cin >> A >> B >> M;
vi a(A), b(B);
rep(i, A) cin >> a[i];
rep(i, B) cin >> b[i];
vi x(M), y(M), c(M);
rep(i, M) cin >> x[i] >> y[i] >> c[i];
int min_a = a[0], min_b = b[0];
repm(i, 1, A) { min_a = min(min_a, a[i]); }
repm(i, 1, A) { min_b = min(min_b, b[i]); }
int minval = min_a + min_b;
rep(i, M) { minval = min(minval, a[x[i] - 1] + b[y[i] - 1] - c[i]); }
// int minval = a[0] + b[0];
// rep(i, A)
// {
// rep(j, B)
// {
// int max_dis = 0;
// rep(k, M)
// {
// if (x[k] - 1 == i && y[k] - 1 == j)
// {
// max_dis = max(max_dis, c[k]);
// }
// }
// minval = min(minval, a[i] + b[j] - max_dis);
// }
// }
cout << minval << endl;
return 0;
} | replace | 26 | 38 | 26 | 48 | TLE | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long lint;
using namespace std;
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int a, b, m;
vector<int> r, d;
vector<int> x, y, c;
int main() {
vector<int> hoge(LLONG_MAX);
cin >> a >> b >> m;
r.resize(a), d.resize(b);
for (int i = 0; i < a; i++) {
cin >> r[i];
}
for (int i = 0; i < b; i++) {
cin >> d[i];
}
x.resize(m);
y.resize(m);
c.resize(m);
for (int i = 0; i < m; i++) {
cin >> x[i] >> y[i] >> c[i];
x[i]--, y[i]--;
}
int mr = *min_element(r.begin(), r.end());
int md = *min_element(d.begin(), d.end());
int ans = INT_MAX;
chmin(ans, mr + md);
for (int i = 0; i < m; i++) {
int cand = r[x[i]] + d[y[i]] - c[i];
chmin(ans, cand);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
typedef long long lint;
using namespace std;
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int a, b, m;
vector<int> r, d;
vector<int> x, y, c;
int main() {
vector<int> hoge(100000000);
cin >> a >> b >> m;
r.resize(a), d.resize(b);
for (int i = 0; i < a; i++) {
cin >> r[i];
}
for (int i = 0; i < b; i++) {
cin >> d[i];
}
x.resize(m);
y.resize(m);
c.resize(m);
for (int i = 0; i < m; i++) {
cin >> x[i] >> y[i] >> c[i];
x[i]--, y[i]--;
}
int mr = *min_element(r.begin(), r.end());
int md = *min_element(d.begin(), d.end());
int ans = INT_MAX;
chmin(ans, mr + md);
for (int i = 0; i < m; i++) {
int cand = r[x[i]] + d[y[i]] - c[i];
chmin(ans, cand);
}
cout << ans << endl;
}
| replace | 17 | 18 | 17 | 18 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A), b(B);
for (int i = 0; i < A; i++)
cin >> a.at(i);
for (int i = 0; i < B; i++)
cin >> b.at(i);
int minA = *min_element(a.begin(), a.end());
int minB = *min_element(b.begin(), b.end());
int res = minA + minB;
for (int i = 0; i < M; i++) {
int x, y, c;
cin >> x >> y >> c;
x--;
y--;
res = min(res, a.at(x) + a.at(y) - c);
}
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A), b(B);
for (int i = 0; i < A; i++)
cin >> a.at(i);
for (int i = 0; i < B; i++)
cin >> b.at(i);
int minA = *min_element(a.begin(), a.end());
int minB = *min_element(b.begin(), b.end());
int res = minA + minB;
for (int i = 0; i < M; i++) {
int x, y, c;
cin >> x >> y >> c;
x--;
y--;
res = min(res, a.at(x) + b.at(y) - c);
}
cout << res << endl;
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define RREP(i, n) for (int(i) = ((int)(n)-1); (i) >= 0; i--)
#define RFOR(i, a, b) for (int(i) = ((int)(b)-1); (i) >= (int)a; i--)
#define ALL(v) (v).begin(), (v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x) (int)x.size()
#define SP(x) setprecision((int)x)
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
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; } // 最小公倍数
//-------------------------------------------------
//
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
//-------------------------------------------------
// メモ
/*
*/
//-------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int a, b, m;
cin >> a >> b >> m;
vector<int> r(a);
vector<int> d(b);
REP(i, a) { cin >> r[i]; }
REP(i, b) { cin >> d[i]; }
int ans = INF;
REP(i, m) {
int x, y, c;
int sum = 0;
x--;
y--;
sum = r[x] + d[y] - c;
ans = min(sum, ans);
}
sort(ALL(r));
sort(ALL(d));
ans = min(ans, r[0] + d[0]);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define RREP(i, n) for (int(i) = ((int)(n)-1); (i) >= 0; i--)
#define RFOR(i, a, b) for (int(i) = ((int)(b)-1); (i) >= (int)a; i--)
#define ALL(v) (v).begin(), (v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x) (int)x.size()
#define SP(x) setprecision((int)x)
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
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; } // 最小公倍数
//-------------------------------------------------
//
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
//-------------------------------------------------
// メモ
/*
*/
//-------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int a, b, m;
cin >> a >> b >> m;
vector<int> r(a);
vector<int> d(b);
REP(i, a) { cin >> r[i]; }
REP(i, b) { cin >> d[i]; }
int ans = INF;
REP(i, m) {
int x, y, c;
cin >> x >> y >> c;
int sum = 0;
x--;
y--;
sum = r[x] + d[y] - c;
ans = min(sum, ans);
}
sort(ALL(r));
sort(ALL(d));
ans = min(ans, r[0] + d[0]);
cout << ans << endl;
return 0;
}
| insert | 56 | 56 | 56 | 57 | -11 | |
p02748 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int A, B, M, a[100], b[100], i, j, m[100], x[100], y[100];
cin >> A >> B >> M;
for (i = 1; i <= A; i++)
cin >> a[i];
for (i = 1; i <= B; i++)
cin >> b[i];
for (i = 1; i <= M; i++) {
cin >> x[i] >> y[i] >> m[i];
}
int mina = a[1], minb = b[1], s, c;
for (i = 1; i <= A; i++) {
if (a[i] < mina)
mina = a[i];
}
for (i = 1; i <= B; i++) {
if (b[i] < minb)
minb = b[i];
}
s = mina + minb;
for (i = 1; i <= M; i++) {
int h = a[x[i]] + b[y[i]] - m[i];
if (s > h)
s = h;
}
cout << s;
} | #include <iostream>
using namespace std;
int main() {
int A, B, M, a[100005], b[100005], i, j, m[100005], x[100005], y[100005];
cin >> A >> B >> M;
for (i = 1; i <= A; i++)
cin >> a[i];
for (i = 1; i <= B; i++)
cin >> b[i];
for (i = 1; i <= M; i++) {
cin >> x[i] >> y[i] >> m[i];
}
int mina = a[1], minb = b[1], s, c;
for (i = 1; i <= A; i++) {
if (a[i] < mina)
mina = a[i];
}
for (i = 1; i <= B; i++) {
if (b[i] < minb)
minb = b[i];
}
s = mina + minb;
for (i = 1; i <= M; i++) {
int h = a[x[i]] + b[y[i]] - m[i];
if (s > h)
s = h;
}
cout << s;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02748 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int ha[10005] = {0};
int hb[10005] = {0};
int main() {
int A, B, M;
cin >> A >> B >> M;
ha[0] = 100000000;
hb[0] = 100000000;
for (int i = 1; i <= A; i++) {
cin >> ha[i];
if (ha[i] < ha[0])
ha[0] = ha[i];
}
for (int i = 1; i <= B; i++) {
cin >> hb[i];
if (hb[i] < hb[0])
hb[0] = hb[i];
}
int ans = ha[0] + hb[0];
for (int i = 1; i <= M; i++) {
int x, y, c;
cin >> x >> y >> c;
if (ha[x] + hb[y] - c < ans)
ans = ha[x] + hb[y] - c;
}
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int ha[100005] = {0};
int hb[100005] = {0};
int main() {
int A, B, M;
cin >> A >> B >> M;
ha[0] = 100000000;
hb[0] = 100000000;
for (int i = 1; i <= A; i++) {
cin >> ha[i];
if (ha[i] < ha[0])
ha[0] = ha[i];
}
for (int i = 1; i <= B; i++) {
cin >> hb[i];
if (hb[i] < hb[0])
hb[0] = hb[i];
}
int ans = ha[0] + hb[0];
for (int i = 1; i <= M; i++) {
int x, y, c;
cin >> x >> y >> c;
if (ha[x] + hb[y] - c < ans)
ans = ha[x] + hb[y] - c;
}
cout << ans << endl;
} | replace | 8 | 10 | 8 | 10 | 0 | |
p02748 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long LL;
using namespace std;
int main() {
int a, b, m;
cin >> a >> b >> m;
vector<int> A(a);
int mia = 1001001;
rep(i, a) {
cin >> A[i];
mia = min(A[i], mia);
}
vector<int> B(b);
int mib = 1001001;
rep(i, a) {
cin >> B[i];
mib = min(B[i], mib);
}
vector<vector<int>> M(m, vector<int>(3));
rep(i, m) {
rep(j, 3) { cin >> M[i][j]; }
}
int v = 0;
int ans = mia + mib;
rep(i, m) {
v = A[M[i][0] - 1] + B[M[i][1] - 1] - M[i][2];
ans = min(v, ans);
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long LL;
using namespace std;
int main() {
int a, b, m;
cin >> a >> b >> m;
vector<int> A(a);
int mia = 1001001;
rep(i, a) {
cin >> A[i];
mia = min(A[i], mia);
}
vector<int> B(b);
int mib = 1001001;
rep(i, b) {
cin >> B[i];
mib = min(B[i], mib);
}
vector<vector<int>> M(m, vector<int>(3));
rep(i, m) {
rep(j, 3) { cin >> M[i][j]; }
}
int v = 0;
int ans = mia + mib;
rep(i, m) {
v = A[M[i][0] - 1] + B[M[i][1] - 1] - M[i][2];
ans = min(v, ans);
}
cout << ans << endl;
return 0;
} | replace | 23 | 24 | 23 | 24 | 0 | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define int long long int
int a, b, m, ans = INT_MAX;
cin >> a >> b >> m;
int p[a], q[b];
int x, y, c;
for (int i = 0; i < a; i++)
cin >> p[i];
for (int i = 0; i < b; i++)
cin >> q[i];
for (int i = 0; i < m; i++) {
cin >> x >> y >> c;
ans = min(p[x - 1] + q[y - 1] - c, ans);
}
int ans1 = INT_MAX;
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
ans1 = min(ans1, p[i] + q[j]);
}
}
cout << min(ans1, ans) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define int long long int
int a, b, m, ans = INT_MAX;
cin >> a >> b >> m;
int p[a], q[b];
int x, y, c;
for (int i = 0; i < a; i++)
cin >> p[i];
for (int i = 0; i < b; i++)
cin >> q[i];
for (int i = 0; i < m; i++) {
cin >> x >> y >> c;
ans = min(p[x - 1] + q[y - 1] - c, ans);
}
int ans1 = INT_MAX;
sort(p, p + a);
sort(q, q + a);
cout << min(p[0] + q[0], ans) << endl;
return 0;
}
| replace | 22 | 28 | 22 | 26 | TLE | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A), b(B);
rep(i, A) cin >> a[i];
rep(i, B) cin >> b[i];
int ans = *min_element(a.begin(), b.end()) + *min_element(b.begin(), b.end());
rep(i, M) {
int x1, y1, c1;
cin >> x1 >> y1 >> c1;
x1--;
y1--;
ans = min(ans, a[x1] + b[y1] - c1);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A), b(B);
rep(i, A) cin >> a[i];
rep(i, B) cin >> b[i];
int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
rep(i, M) {
int x1, y1, c1;
cin >> x1 >> y1 >> c1;
x1--;
y1--;
ans = min(ans, a[x1] + b[y1] - c1);
}
cout << ans << endl;
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A);
for (int i = 0; i < A; i++) {
cin >> a.at(i);
}
vector<int> b(B);
for (int j = 0; j < B; j++) {
cin >> b.at(j);
}
vector<int> x(M), y(M), c(M);
for (int i = 0; i < M; i++) {
cin >> x.at(i) >> y.at(i) >> c.at(i);
}
int answer = a.at(x.at(0)) + b.at(y.at(0)) - c.at(0);
for (int i = 0; i < M; i++) {
if (answer > a.at(x.at(i)) + b.at(y.at(i)) - c.at(i)) {
answer = a.at(x.at(i)) + b.at(y.at(i)) - c.at(i);
}
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (answer < a.at(0) + b.at(0)) {
cout << answer << endl;
} else {
cout << a.at(0) + b.at(0) << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A);
for (int i = 0; i < A; i++) {
cin >> a.at(i);
}
vector<int> b(B);
for (int j = 0; j < B; j++) {
cin >> b.at(j);
}
vector<int> x(M), y(M), c(M);
for (int i = 0; i < M; i++) {
cin >> x.at(i) >> y.at(i) >> c.at(i);
--x.at(i);
--y.at(i);
}
int answer = a.at(x.at(0)) + b.at(y.at(0)) - c.at(0);
for (int i = 0; i < M; i++) {
if (answer > a.at(x.at(i)) + b.at(y.at(i)) - c.at(i)) {
answer = a.at(x.at(i)) + b.at(y.at(i)) - c.at(i);
}
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (answer < a.at(0) + b.at(0)) {
cout << answer << endl;
} else {
cout << a.at(0) + b.at(0) << endl;
}
}
| insert | 20 | 20 | 20 | 22 | 0 | |
p02748 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
const ll INF = ll(1e18) + 1;
const double PI = 3.14159265358979323846;
int main() {
int A, B, M, a[101000] = {}, b[101000] = {}, x[101000] = {}, y[101000] = {},
c[100100] = {};
cin >> A >> B >> M;
rep(i, A) cin >> a[i + 1];
rep(i, B) cin >> b[i + 1];
rep(i, M) cin >> x[i] >> y[i] >> c[i];
int ans = 1e+9;
rep(i, M) { ans = min(ans, a[x[i]] + b[y[i]] - c[i]); }
rep(i, A) {
for (int j = i + 1; j < B; j++) {
ans = min(ans, a[i + 1] + b[i + 1]);
}
}
cout << ans << endl;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
const ll INF = ll(1e18) + 1;
const double PI = 3.14159265358979323846;
int main() {
int A, B, M, a[101000] = {}, b[101000] = {}, x[101000] = {}, y[101000] = {},
c[100100] = {};
cin >> A >> B >> M;
rep(i, A) cin >> a[i + 1];
rep(i, B) cin >> b[i + 1];
rep(i, M) cin >> x[i] >> y[i] >> c[i];
int ans = 1e+9;
rep(i, M) { ans = min(ans, a[x[i]] + b[y[i]] - c[i]); }
sort(a + 1, a + A + 1);
sort(b + 1, b + B + 1);
ans = min(ans, a[1] + b[1]);
cout << ans << endl;
}
| replace | 28 | 33 | 28 | 31 | TLE | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A);
vector<int> b(B);
rep(i, A) { cin >> a.at(i); }
rep(i, B) { cin >> b.at(i); }
vector<vector<int>> c(M, vector<int>(3));
rep(i, M) { cin >> c.at(i).at(0) >> c.at(i).at(1) >> c.at(i).at(2); }
int minA = *std::min_element(a.begin(), a.end());
int minB = *std::min_element(b.begin(), b.end());
vector<int> off(M + 1);
rep(i, M) {
off.at(i) = a.at(c.at(i).at(0)) + b.at(c.at(i).at(1)) - c.at(i).at(2);
}
off.at(M) = minA + minB;
int min = *std::min_element(off.begin(), off.end());
cout << min << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A);
vector<int> b(B);
rep(i, A) { cin >> a.at(i); }
rep(i, B) { cin >> b.at(i); }
vector<vector<int>> c(M, vector<int>(3));
rep(i, M) { cin >> c.at(i).at(0) >> c.at(i).at(1) >> c.at(i).at(2); }
int minA = *std::min_element(a.begin(), a.end());
int minB = *std::min_element(b.begin(), b.end());
vector<int> off(M + 1);
rep(i, M) {
off.at(i) =
a.at(c.at(i).at(0) - 1) + b.at(c.at(i).at(1) - 1) - c.at(i).at(2);
}
off.at(M) = minA + minB;
int min = *std::min_element(off.begin(), off.end());
cout << min << endl;
}
| replace | 32 | 33 | 32 | 34 | 0 | |
p02748 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
const lli mod = 998244353;
const lli inf = 1e18;
int main() {
int a, b, m;
cin >> a >> b >> m;
vector<int> aa(m), bb(m);
for (int i = 0; i < a; i++) {
cin >> aa[i];
}
for (int i = 0; i < b; i++) {
cin >> bb[i];
}
int ans =
*min_element(aa.begin(), aa.end()) + *min_element(bb.begin(), bb.end());
for (int i = 0; i < m; i++) {
int x, y, c;
cin >> x >> y >> c;
x--;
y--;
ans = min(ans, aa[x] + bb[y] - c);
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
const lli mod = 998244353;
const lli inf = 1e18;
int main() {
int a, b, m;
cin >> a >> b >> m;
vector<int> aa(a), bb(b);
for (int i = 0; i < a; i++) {
cin >> aa[i];
}
for (int i = 0; i < b; i++) {
cin >> bb[i];
}
int ans =
*min_element(aa.begin(), aa.end()) + *min_element(bb.begin(), bb.end());
for (int i = 0; i < m; i++) {
int x, y, c;
cin >> x >> y >> c;
x--;
y--;
ans = min(ans, aa[x] + bb[y] - c);
}
cout << ans << endl;
return 0;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02748 | C++ | Time Limit Exceeded | #define _DEBUG 1
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define check(s)
#endif
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void solve(ll A, ll B, ll M, std::vector<ll> a, std::vector<ll> b,
std::vector<ll> x, std::vector<ll> y, std::vector<ll> c) {
ll result = -1;
rep(i, M) {
ll price = a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i);
result = result != -1 ? min(price, result) : price;
}
rep(i, A) {
rep(j, B) {
ll price = a.at(i) + b.at(j);
if (price < result) {
result = price;
}
}
}
cout << result << endl;
}
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
ll A;
scanf("%lld", &A);
ll B;
scanf("%lld", &B);
ll M;
scanf("%lld", &M);
std::vector<ll> a(A);
for (int i = 0; i < A; i++) {
scanf("%lld", &a[i]);
}
std::vector<ll> b(B);
for (int i = 0; i < B; i++) {
scanf("%lld", &b[i]);
}
std::vector<ll> x(M);
std::vector<ll> y(M);
std::vector<ll> c(M);
for (int i = 0; i < M; i++) {
scanf("%lld", &x[i]);
scanf("%lld", &y[i]);
scanf("%lld", &c[i]);
}
solve(A, B, M, std::move(a), std::move(b), std::move(x), std::move(y),
std::move(c));
return 0;
}
| #define _DEBUG 1
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define check(s)
#endif
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void solve(ll A, ll B, ll M, std::vector<ll> a, std::vector<ll> b,
std::vector<ll> x, std::vector<ll> y, std::vector<ll> c) {
ll result = -1;
rep(i, M) {
ll price = a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i);
result = result != -1 ? min(price, result) : price;
}
ll minA = -1;
ll minB = -1;
// a の min + b の min でよさそう
rep(i, A) { minA = minA != -1 ? min(minA, a.at(i)) : a.at(i); }
rep(i, B) { minB = minB != -1 ? min(minB, b.at(i)) : b.at(i); }
result = min(minA + minB, result);
cout << result << endl;
}
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
ll A;
scanf("%lld", &A);
ll B;
scanf("%lld", &B);
ll M;
scanf("%lld", &M);
std::vector<ll> a(A);
for (int i = 0; i < A; i++) {
scanf("%lld", &a[i]);
}
std::vector<ll> b(B);
for (int i = 0; i < B; i++) {
scanf("%lld", &b[i]);
}
std::vector<ll> x(M);
std::vector<ll> y(M);
std::vector<ll> c(M);
for (int i = 0; i < M; i++) {
scanf("%lld", &x[i]);
scanf("%lld", &y[i]);
scanf("%lld", &c[i]);
}
solve(A, B, M, std::move(a), std::move(b), std::move(x), std::move(y),
std::move(c));
return 0;
}
| replace | 32 | 40 | 32 | 39 | TLE | |
p02748 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A, 0);
vector<int> b(B, 0);
int tmp_a = 10e9 + 1, tmp_b = 10e9 + 1;
for (int i = 0; i < A; ++i) {
cin >> a[i];
tmp_a = min(tmp_a, a[i]);
}
for (int i = 0; i < B; ++i) {
cin >> b[i];
tmp_b = min(tmp_b, b[i]);
}
int ans = tmp_a + tmp_b;
for (int i = 0; i < A; ++i) {
for (int j = 0; j < B; ++j) {
ans = min(ans, a[i] + b[j]);
}
}
for (int i = 0; i < M; ++i) {
int x, y, z;
cin >> x >> y >> z;
if (ans > (a[x - 1] + b[y - 1]) - z)
ans = (a[x - 1] + b[y - 1]) - z;
}
printf("%d\n", ans);
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A, 0);
vector<int> b(B, 0);
int tmp_a = 10e9 + 1, tmp_b = 10e9 + 1;
for (int i = 0; i < A; ++i) {
cin >> a[i];
tmp_a = min(tmp_a, a[i]);
}
for (int i = 0; i < B; ++i) {
cin >> b[i];
tmp_b = min(tmp_b, b[i]);
}
int ans = tmp_a + tmp_b;
for (int i = 0; i < M; ++i) {
int x, y, z;
cin >> x >> y >> z;
if (ans > (a[x - 1] + b[y - 1]) - z)
ans = (a[x - 1] + b[y - 1]) - z;
}
printf("%d\n", ans);
}
| delete | 20 | 25 | 20 | 20 | TLE | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(x.begin(), x.end(), 0);
#define vint(v, n) \
vector<int> v(n); \
REP(i, n) scanf("%lld", &v[i]);
#define vstr(v, n) \
vector<string> v(n); \
REP(i, n) scanf("%lld", &v[i]);
struct initon {
initon() {
cin.tie(0);
ios::sync_with_stdio(false);
};
};
bool is_prime(const unsigned n) {
switch (n) {
case 0: // fall-through
case 1:
return false;
case 2: // fall-through
case 3:
return true;
} // n > 3 が保証された
if (n % 2 == 0 || n % 3 == 0)
return false;
// n は 2 と 3 のいずれの倍数でもないことが保証された
// これより n は (6の倍数)-1 か (6の倍数)+1 である
// 6の倍数前後の数を使って試し割りをする
for (unsigned i = 5; i * i <= n; i += 6) {
if (n % i == 0)
return false; // (6の倍数)-1
if (n % (i + 2) == 0)
return false; // (6の倍数)+1
}
return true;
}
int k = 0, n = 0, m = 0, l = 0, r = 0, a = 0, b = 0, c = 0, d = 0, e = 0,
ans = 0, ans2 = 0, x = 0, y = 0;
string s, t, S;
signed main() {
cin >> a >> b >> m;
vint(A, a);
vint(B, b);
ans = 10000000000;
vector<vector<int>> x(m, vector<int>(3));
REP(i, m) REP(j, 3) cin >> x[i][j];
REP(i, m) { ans = min(ans, A[x[i][0] - 1] + B[x[i][1] - 1] - x[i][2]); }
REP(i, a) REP(j, b) { ans = min(ans, A[i] + B[j]); }
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(x.begin(), x.end(), 0);
#define vint(v, n) \
vector<int> v(n); \
REP(i, n) scanf("%lld", &v[i]);
#define vstr(v, n) \
vector<string> v(n); \
REP(i, n) scanf("%lld", &v[i]);
struct initon {
initon() {
cin.tie(0);
ios::sync_with_stdio(false);
};
};
bool is_prime(const unsigned n) {
switch (n) {
case 0: // fall-through
case 1:
return false;
case 2: // fall-through
case 3:
return true;
} // n > 3 が保証された
if (n % 2 == 0 || n % 3 == 0)
return false;
// n は 2 と 3 のいずれの倍数でもないことが保証された
// これより n は (6の倍数)-1 か (6の倍数)+1 である
// 6の倍数前後の数を使って試し割りをする
for (unsigned i = 5; i * i <= n; i += 6) {
if (n % i == 0)
return false; // (6の倍数)-1
if (n % (i + 2) == 0)
return false; // (6の倍数)+1
}
return true;
}
int k = 0, n = 0, m = 0, l = 0, r = 0, a = 0, b = 0, c = 0, d = 0, e = 0,
ans = 0, ans2 = 0, x = 0, y = 0;
string s, t, S;
signed main() {
cin >> a >> b >> m;
vint(A, a);
vint(B, b);
ans = *min_element(ALL(A)) + *min_element(ALL(B));
REP(i, m) {
cin >> a >> b >> c;
ans = min(ans, A[a - 1] + B[b - 1] - c);
}
cout << ans;
} | replace | 54 | 60 | 54 | 59 | TLE | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M, Min_a = 100000, Min_b = 100000, ans;
cin >> A >> B >> M;
vector<int> a(A), b(B), x(M), y(M), c(M);
for (int i = 0; i < A; i++) {
cin >> a.at(i);
if (Min_a > a.at(i)) {
Min_a = a.at(i);
}
}
for (int i = 0; i < B; i++) {
cin >> b.at(i);
if (Min_b > b.at(i)) {
Min_b = b.at(i);
}
}
ans = Min_a + Min_b;
for (int i = 0; i < M; i++) {
cin >> x.at(i) >> y.at(i) >> c.at(i);
if (a.at(x.at(i)) + b.at(y.at(i)) - c.at(i) < ans) {
ans = a.at(x.at(i)) + b.at(y.at(i)) - c.at(i);
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M, Min_a = 100000, Min_b = 100000, ans;
cin >> A >> B >> M;
vector<int> a(A), b(B), x(M), y(M), c(M);
for (int i = 0; i < A; i++) {
cin >> a.at(i);
if (Min_a > a.at(i)) {
Min_a = a.at(i);
}
}
for (int i = 0; i < B; i++) {
cin >> b.at(i);
if (Min_b > b.at(i)) {
Min_b = b.at(i);
}
}
ans = Min_a + Min_b;
for (int i = 0; i < M; i++) {
cin >> x.at(i) >> y.at(i) >> c.at(i);
if (a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i) < ans) {
ans = a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i);
}
}
cout << ans << endl;
}
| replace | 24 | 26 | 24 | 26 | 0 | |
p02748 | C++ | Runtime Error | #include <iostream>
int main() {
int an, bn, mn;
int min;
int min_a = 99999;
int min_b = 99999;
int a[10000];
int b[10000];
for (int i = 0; i < 10000; i++)
a[i] = b[i] = 0;
std::cin >> an >> bn >> mn;
for (int i = 0; i < an; i++) {
std::cin >> a[i];
if (min_a > a[i])
min_a = a[i];
}
for (int i = 0; i < bn; i++) {
std::cin >> b[i];
if (min_b > b[i])
min_b = b[i];
}
min = min_a + min_b;
for (int i = 0; i < mn; ++i) {
int xi, yi, c;
std::cin >> xi >> yi >> c;
int temp = a[xi - 1] + b[yi - 1] - c;
if (min > temp)
min = temp;
}
std::cout << min << std::endl;
} | #include <iostream>
int main() {
int an, bn, mn;
int min;
int min_a = 999999;
int min_b = 999999;
int a[100000];
int b[100000];
for (int i = 0; i < 100000; i++)
a[i] = b[i] = 0;
std::cin >> an >> bn >> mn;
for (int i = 0; i < an; i++) {
std::cin >> a[i];
if (min_a > a[i])
min_a = a[i];
}
for (int i = 0; i < bn; i++) {
std::cin >> b[i];
if (min_b > b[i])
min_b = b[i];
}
min = min_a + min_b;
for (int i = 0; i < mn; ++i) {
int xi, yi, c;
std::cin >> xi >> yi >> c;
int temp = a[xi - 1] + b[yi - 1] - c;
if (min > temp)
min = temp;
}
std::cout << min << std::endl;
} | replace | 5 | 10 | 5 | 10 | 0 | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
#define ll long long
const int inf = 1000000000;
int main() {
int a, b, m;
cin >> a >> b >> m;
vector<int> A(a);
vector<int> B(b);
vector<int> x(m);
vector<int> y(m);
vector<int> c(m);
rep(i, a) { cin >> A[i]; }
rep(i, b) { cin >> B[i]; }
rep(i, m) { cin >> x[i] >> y[i] >> c[i]; }
int ans = 1000000;
rep(i, m) { ans = min(ans, A[x[i] - 1] + B[y[i] - 1] - c[i]); }
if (a > b) {
rep(i, a) {
rep(j, b) { ans = min(ans, A[i] + B[j]); }
}
} else {
rep(i, b) {
rep(j, a) { ans = min(ans, A[j] + B[i]); }
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
#define ll long long
const int inf = 1000000000;
int main() {
int a, b, m;
cin >> a >> b >> m;
vector<int> A(a);
vector<int> B(b);
vector<int> x(m);
vector<int> y(m);
vector<int> c(m);
rep(i, a) { cin >> A[i]; }
rep(i, b) { cin >> B[i]; }
rep(i, m) { cin >> x[i] >> y[i] >> c[i]; }
int ans = 1000000;
rep(i, m) { ans = min(ans, A[x[i] - 1] + B[y[i] - 1] - c[i]); }
sort(A.begin(), A.end());
sort(B.begin(), B.end());
ans = min(ans, A[0] + B[0]);
cout << ans << endl;
return 0;
} | replace | 23 | 32 | 23 | 27 | TLE | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> aa(A), bb(B);
for (int i = 0; i < A; i++) {
cin >> aa.at(i);
}
for (int i = 0; i < B; i++) {
cin >> bb.at(i);
}
vector<int> x(M), y(M), c(M);
for (int i = 0; i < M; i++) {
cin >> x.at(i) >> y.at(i) >> c.at(i);
x.at(i)--;
y.at(i)--;
}
int result = aa.at(0) + bb.at(0);
for (int i = 0; i < M; i++) {
int sum = aa.at(x.at(i)) + bb.at(y.at(i)) - c.at(i);
if (result > sum)
result = sum;
}
for (int i = 0; i < A; i++) {
for (int j = 0; j < B; j++) {
int sum = aa.at(i) + bb.at(j);
if (result > sum)
result = sum;
}
}
cout << result << endl;
}
| #include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> aa(A), bb(B);
for (int i = 0; i < A; i++) {
cin >> aa.at(i);
}
for (int i = 0; i < B; i++) {
cin >> bb.at(i);
}
vector<int> x(M), y(M), c(M);
for (int i = 0; i < M; i++) {
cin >> x.at(i) >> y.at(i) >> c.at(i);
x.at(i)--;
y.at(i)--;
}
int result = aa.at(0) + bb.at(0);
for (int i = 0; i < M; i++) {
int sum = aa.at(x.at(i)) + bb.at(y.at(i)) - c.at(i);
if (result > sum)
result = sum;
}
sort(ALL(aa));
sort(ALL(bb));
if (result > aa.at(0) + bb.at(0))
result = aa.at(0) + bb.at(0);
cout << result << endl;
}
| replace | 30 | 37 | 30 | 36 | TLE | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
long a, b, m, temp = LONG_MAX, ans = LONG_MAX;
cin >> a >> b >> m;
vector<long> va(a), vb(b);
rep(i, a) {
cin >> va.at(i);
if (ans > va.at(i))
ans = va.at(i);
}
rep(i, b) {
cin >> vb.at(i);
if (temp > va.at(i))
temp = va.at(i);
}
ans += temp;
rep(i, m) {
long x, y, c;
cin >> x >> y >> c;
ans = min(ans, va.at(x - 1) + vb.at(y - 1) - c);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
long a, b, m, temp = LONG_MAX, ans = LONG_MAX;
cin >> a >> b >> m;
vector<long> va(a), vb(b);
rep(i, a) {
cin >> va.at(i);
if (ans > va.at(i))
ans = va.at(i);
}
rep(i, b) {
cin >> vb.at(i);
if (temp > vb.at(i))
temp = vb.at(i);
}
ans += temp;
rep(i, m) {
long x, y, c;
cin >> x >> y >> c;
ans = min(ans, va.at(x - 1) + vb.at(y - 1) - c);
}
cout << ans << endl;
} | replace | 15 | 17 | 15 | 17 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
|
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A);
for (int i = 0; i < A; i++)
cin >> a[i];
vector<int> b(B);
for (int i = 0; i < B; i++)
cin >> b[i];
int minA = *min_element(a.begin(), a.end());
int minB = *min_element(b.begin(), b.end());
int ans = minA + minB;
for (int i = 0; i < M; i++) {
int x, y, c;
cin >> x >> y >> x;
x--;
y--;
ans = min(ans, a[x] + b[y] - c);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A);
for (int i = 0; i < A; i++)
cin >> a[i];
vector<int> b(B);
for (int i = 0; i < B; i++)
cin >> b[i];
int minA = *min_element(a.begin(), a.end());
int minB = *min_element(b.begin(), b.end());
int ans = minA + minB;
for (int i = 0; i < M; i++) {
int x, y, c;
cin >> x >> y >> c;
x--;
y--;
ans = min(ans, a[x] + b[y] - c);
}
cout << ans << endl;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M;
vector<int> a(A);
vector<int> b(B);
for (int i = 0; i < A; i++)
cin >> a[i];
for (int i = 0; i < B; i++)
cin >> b[i];
int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
for (int i = 0; i < M; i++) {
int x, y, c;
cin >> x >> y >> c;
x--;
y--;
ans = min(ans, a[x] + b[y] - c);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> a(A);
vector<int> b(B);
for (int i = 0; i < A; i++)
cin >> a[i];
for (int i = 0; i < B; i++)
cin >> b[i];
int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
for (int i = 0; i < M; i++) {
int x, y, c;
cin >> x >> y >> c;
x--;
y--;
ans = min(ans, a[x] + b[y] - c);
}
cout << ans << endl;
return 0;
} | insert | 5 | 5 | 5 | 6 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, m;
cin >> a >> b >> m;
vector<int> cost_a(a), cost_b(b);
for (int i = 0; i < a; i++)
cin >> cost_a.at(i);
for (int i = 0; i < b; i++)
cin >> cost_b.at(i);
int ans = *min_element(cost_a.begin(), cost_a.end()) +
*min_element(cost_b.begin(), cost_b.end());
for (int i = 0; i < m; i++) {
int x, y, c;
cin >> x >> y >> c;
x--;
y--;
int n = cost_a.at(x) + cost_b.at(x) - c;
ans = min(ans, n);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, m;
cin >> a >> b >> m;
vector<int> cost_a(a), cost_b(b);
for (int i = 0; i < a; i++)
cin >> cost_a.at(i);
for (int i = 0; i < b; i++)
cin >> cost_b.at(i);
int ans = *min_element(cost_a.begin(), cost_a.end()) +
*min_element(cost_b.begin(), cost_b.end());
for (int i = 0; i < m; i++) {
int x, y, c;
cin >> x >> y >> c;
x--;
y--;
int n = cost_a.at(x) + cost_b.at(y) - c;
ans = min(ans, n);
}
cout << ans << endl;
}
| replace | 18 | 19 | 18 | 19 | 0 | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, m;
cin >> a >> b >> m;
vector<int> A(a);
vector<int> B(b);
vector<vector<int>> C(a, vector<int>(b, 0));
for (int i = 0; i < a; i++)
cin >> A[i];
for (int j = 0; j < b; j++)
cin >> B[j];
int ans = 0;
int minA = *min_element(A.begin(), A.end());
int minB = *min_element(B.begin(), B.end());
ans = minA + minB;
for (int k = 0; k < m; k++) {
int a_ind, b_ind, c;
cin >> a_ind >> b_ind >> c;
int tmp;
tmp = A[a_ind - 1] + B[b_ind - 1] - c;
ans = min(ans, tmp);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, m;
cin >> a >> b >> m;
vector<int> A(a);
vector<int> B(b);
for (int i = 0; i < a; i++)
cin >> A[i];
for (int j = 0; j < b; j++)
cin >> B[j];
int ans = 0;
int minA = *min_element(A.begin(), A.end());
int minB = *min_element(B.begin(), B.end());
ans = minA + minB;
for (int k = 0; k < m; k++) {
int a_ind, b_ind, c;
cin >> a_ind >> b_ind >> c;
int tmp;
tmp = A[a_ind - 1] + B[b_ind - 1] - c;
ans = min(ans, tmp);
}
cout << ans << endl;
} | delete | 8 | 9 | 8 | 8 | 0 | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ifor(i, n) for (i = 0; i < n; i++)
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i, n, t = INT_MAX, p = INT_MAX, j = 0, x, a = 0, b, l = 0, r = 0, c, y, m,
q;
string s;
cin >> a >> b >> m;
int ara[a];
int arr[b];
for (i = 0; i < a; i++) {
cin >> ara[i];
}
for (i = 0; i < b; i++) {
cin >> arr[i];
}
for (j = 0; j < m; j++) {
cin >> x >> y >> c;
l = ara[x - 1] + arr[y - 1] - c;
p = min(p, l);
}
for (i = 0; i < a; i++) {
for (j = 0; j < b; j++) {
q = ara[i] + arr[j];
t = min(q, t);
}
}
cout << min(p, t) << endl;
return EXIT_SUCCESS;
}
| #include <bits/stdc++.h>
using namespace std;
#define ifor(i, n) for (i = 0; i < n; i++)
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i, n, t = INT_MAX, p = INT_MAX, j = 0, x, a = 0, b, l = 0, r = 0, c, y, m,
q;
string s;
cin >> a >> b >> m;
int ara[a];
int arr[b];
for (i = 0; i < a; i++) {
cin >> ara[i];
}
for (i = 0; i < b; i++) {
cin >> arr[i];
}
for (j = 0; j < m; j++) {
cin >> x >> y >> c;
l = ara[x - 1] + arr[y - 1] - c;
p = min(p, l);
}
sort(ara, ara + a);
sort(arr, arr + b);
t = arr[0] + ara[0];
cout << min(p, t) << endl;
return EXIT_SUCCESS;
}
| replace | 25 | 31 | 25 | 28 | TLE | |
p02748 | C++ | Runtime Error | // BUGSBUNNY
// IIT ROORKEE
// _,add8ba,
// ,d888888888b,
// d8888888888888b _,ad8ba,_
// d888888888888888) ,d888888888b,
// I8888888888888888 _________ ,8888888888888b
// __________`Y88888888888888P"""""""""""baaa,__
// ,888888888888888,
// ,adP"""""""""""9888888888P""^ ^""Y8888888888888888I
// ,a8"^ ,d888P"888P^ ^"Y8888888888P'
// ,a8^ ,d8888' ^Y8888888P'
// a88' ,d8888P' I88P"^
// ,d88' d88888P' "b,
// ,d88' d888888' `b,
// ,d88' d888888I `b,
// d88I ,8888888' ___ `b,
// ,888' d8888888 ,d88888b, ____ `b,
// d888 ,8888888I d88888888b, ,d8888b, `b
// ,8888 I8888888I d8888888888I ,88888888b 8, I8888
// 88888888b d88888888888' 8888888888b 8I d8886
// 888888888 Y888888888P' Y8888888888, ,8b 88888b
// I88888888b `Y8888888^ `Y888888888I d88, Y88888b
// `888888888b, `""""^ `Y8888888P' d888I `888888b
// 88888888888b, `Y8888P^ d88888
// Y888888b ,8888888888888ba,_ _______ `""^ ,d888888
// I8888888b, ,888888888888888888ba,_ d88888888b ,ad8888888I
// `888888888b, I8888888888888888888888b, ^"Y888P"^ ____.,ad88888888888I
// 88888888888b,`888888888888888888888888b, "" ad888888888888888888888'
// 8888888888888698888888888888888888888888b_,ad88ba,_,d88888888888888888888888
// 88888888888888888888888888888888888888888b,`"""^
// d8888888888888888888888888I
// 8888888888888888888888888888888888888888888baaad888888888888888888888888888'
// Y8888888888888888888888888888888888888888888888888888888888888888888888888P
// I888888888888888888888888888888888888888888888P^ ^Y8888888888888888888888'
// `Y88888888888888888P88888888888888888888888888' ^88888888888888888888I
// `Y8888888888888888 `8888888888888888888888888 8888888888888888888P'
// `Y888888888888888 `888888888888888888888888, ,888888888888888888P'
// `Y88888888888888b `88888888888888888888888I I888888888888888888'
// "Y8888888888888b `8888888888888888888888I I88888888888888888'
// "Y88888888888P `888888888888888888888b d8888888888888888'
// ^""""""""^ `Y88888888888888888888, 888888888888888P'
// "8888888888888888888b, Y888888888888P^
// `Y888888888888888888b `Y8888888P"^
// "Y8888888888888888P `""""^
// `"YY88888888888P'
// ^""""""""'
#include <bits/stdc++.h>
using namespace std;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define int long long
#define ll long long
#define ld long double
// #define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<long long>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vb vector<bool>
#define pb push_back
#define pob pop_back
#define gcd __gcd
#define mp make_pair
#define pii pair<int, int>
#define pipii pair<int, pii>
#define pll pair<long long, long long>
#define pld pair<long double, long double>
#define mod 1000000007
#define mod2 998244353
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repp(i, a, b) for (ll i = a; i < b; i++)
#define reppr(i, a, b) for (ll i = a - 1; i >= b; i--)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 1000000000000
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprecision0 cout << fixed << setprecision(0);
#define setprecision10 cout << fixed << setprecision(10);
#define all(n) n.begin(), n.end()
void solve();
signed main() {
fast;
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
while (t--)
solve();
}
void solve() {
int a, b, m;
cin >> a >> b >> m;
int arr[a], brr[b];
int ans = inf, m1 = inf, m2 = inf;
rep(i, a) cin >> arr[i], m1 = min(arr[i], m1);
rep(i, b) cin >> brr[i], m2 = min(brr[i], m2);
ans = m1 + m2;
// cout << ans << endl;
while (m--) {
int x, y, c;
cin >> x >> y >> c;
ans = min(ans, arr[x - 1] + brr[y - 1] - c);
}
cout << ans << endl;
} | // BUGSBUNNY
// IIT ROORKEE
// _,add8ba,
// ,d888888888b,
// d8888888888888b _,ad8ba,_
// d888888888888888) ,d888888888b,
// I8888888888888888 _________ ,8888888888888b
// __________`Y88888888888888P"""""""""""baaa,__
// ,888888888888888,
// ,adP"""""""""""9888888888P""^ ^""Y8888888888888888I
// ,a8"^ ,d888P"888P^ ^"Y8888888888P'
// ,a8^ ,d8888' ^Y8888888P'
// a88' ,d8888P' I88P"^
// ,d88' d88888P' "b,
// ,d88' d888888' `b,
// ,d88' d888888I `b,
// d88I ,8888888' ___ `b,
// ,888' d8888888 ,d88888b, ____ `b,
// d888 ,8888888I d88888888b, ,d8888b, `b
// ,8888 I8888888I d8888888888I ,88888888b 8, I8888
// 88888888b d88888888888' 8888888888b 8I d8886
// 888888888 Y888888888P' Y8888888888, ,8b 88888b
// I88888888b `Y8888888^ `Y888888888I d88, Y88888b
// `888888888b, `""""^ `Y8888888P' d888I `888888b
// 88888888888b, `Y8888P^ d88888
// Y888888b ,8888888888888ba,_ _______ `""^ ,d888888
// I8888888b, ,888888888888888888ba,_ d88888888b ,ad8888888I
// `888888888b, I8888888888888888888888b, ^"Y888P"^ ____.,ad88888888888I
// 88888888888b,`888888888888888888888888b, "" ad888888888888888888888'
// 8888888888888698888888888888888888888888b_,ad88ba,_,d88888888888888888888888
// 88888888888888888888888888888888888888888b,`"""^
// d8888888888888888888888888I
// 8888888888888888888888888888888888888888888baaad888888888888888888888888888'
// Y8888888888888888888888888888888888888888888888888888888888888888888888888P
// I888888888888888888888888888888888888888888888P^ ^Y8888888888888888888888'
// `Y88888888888888888P88888888888888888888888888' ^88888888888888888888I
// `Y8888888888888888 `8888888888888888888888888 8888888888888888888P'
// `Y888888888888888 `888888888888888888888888, ,888888888888888888P'
// `Y88888888888888b `88888888888888888888888I I888888888888888888'
// "Y8888888888888b `8888888888888888888888I I88888888888888888'
// "Y88888888888P `888888888888888888888b d8888888888888888'
// ^""""""""^ `Y88888888888888888888, 888888888888888P'
// "8888888888888888888b, Y888888888888P^
// `Y888888888888888888b `Y8888888P"^
// "Y8888888888888888P `""""^
// `"YY88888888888P'
// ^""""""""'
#include <bits/stdc++.h>
using namespace std;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define int long long
#define ll long long
#define ld long double
// #define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<long long>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vb vector<bool>
#define pb push_back
#define pob pop_back
#define gcd __gcd
#define mp make_pair
#define pii pair<int, int>
#define pipii pair<int, pii>
#define pll pair<long long, long long>
#define pld pair<long double, long double>
#define mod 1000000007
#define mod2 998244353
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repp(i, a, b) for (ll i = a; i < b; i++)
#define reppr(i, a, b) for (ll i = a - 1; i >= b; i--)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 1000000000000
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprecision0 cout << fixed << setprecision(0);
#define setprecision10 cout << fixed << setprecision(10);
#define all(n) n.begin(), n.end()
void solve();
signed main() {
fast;
// #ifndef ONLINE_JUDGE
// // for getting input from input.txt
// freopen("input.txt", "r", stdin);
// // for writing output to output.txt
// freopen("output.txt", "w", stdout);
// #endif
int t = 1;
// cin >> t;
while (t--)
solve();
}
void solve() {
int a, b, m;
cin >> a >> b >> m;
int arr[a], brr[b];
int ans = inf, m1 = inf, m2 = inf;
rep(i, a) cin >> arr[i], m1 = min(arr[i], m1);
rep(i, b) cin >> brr[i], m2 = min(brr[i], m2);
ans = m1 + m2;
// cout << ans << endl;
while (m--) {
int x, y, c;
cin >> x >> y >> c;
ans = min(ans, arr[x - 1] + brr[y - 1] - c);
}
cout << ans << endl;
} | replace | 94 | 100 | 94 | 100 | -11 | |
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define rep(i, l, r) for (int(i) = (l); (i) < (r); (i)++)
using namespace std;
int main() {
ll A, B, M;
cin >> A >> B >> M;
vector<ll> a(A), b(B);
ll mia, mib = 1e9;
rep(i, 0, A) {
cin >> a[i];
mia = min(mia, a[i]);
}
rep(i, 0, B) {
cin >> b[i];
mib = min(mib, b[i]);
}
ll ans = mia + mib;
rep(i, 0, M) {
rep(j, 0, M) {
ll x, y, c;
cin >> x >> y >> c;
ans = min(ans, a[x - 1] + b[y - 1] - c);
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define ll long long
#define rep(i, l, r) for (int(i) = (l); (i) < (r); (i)++)
using namespace std;
int main() {
ll A, B, M;
cin >> A >> B >> M;
vector<ll> a(A), b(B);
ll mia, mib = 1e9;
rep(i, 0, A) {
cin >> a[i];
mia = min(mia, a[i]);
}
rep(i, 0, B) {
cin >> b[i];
mib = min(mib, b[i]);
}
ll ans = mia + mib;
rep(i, 0, M) {
ll x, y, c;
cin >> x >> y >> c;
ans = min(ans, a[x - 1] + b[y - 1] - c);
}
cout << ans << endl;
}
| replace | 20 | 25 | 20 | 23 | TLE | |
p02748 | C++ | Runtime Error | #include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int findSumOfDigits(int n) {
int sum = 0;
while (n > 0) { // n が 0 になるまで
sum += n % 10;
n /= 10;
}
return sum;
}
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<long long> a(A), b(B), x(M), y(M), c(M);
rep(i, A) cin >> a.at(i);
rep(i, B) cin >> b.at(i);
rep(i, M) cin >> x.at(i) >> y.at(i) >> c.at(i);
long long mini = 200000;
rep(i, M) {
if ((a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i)) <= mini) {
mini = (a.at(x.at(i - 1)) + b.at(y.at(i - 1)) - c.at(i));
}
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (mini > a.at(0) + b.at(0))
mini = a.at(0) + b.at(0);
cout << mini << endl;
} | #include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int findSumOfDigits(int n) {
int sum = 0;
while (n > 0) { // n が 0 になるまで
sum += n % 10;
n /= 10;
}
return sum;
}
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<long long> a(A), b(B), x(M), y(M), c(M);
rep(i, A) cin >> a.at(i);
rep(i, B) cin >> b.at(i);
rep(i, M) cin >> x.at(i) >> y.at(i) >> c.at(i);
long long mini = 200000;
rep(i, M) {
if ((a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i)) <= mini) {
mini = (a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i));
}
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if (mini > a.at(0) + b.at(0))
mini = a.at(0) + b.at(0);
cout << mini << endl;
} | replace | 22 | 23 | 22 | 23 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 1)
|
p02748 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using vec = vector<int>;
using intk = int64_t;
int main() {
int A, B, M;
cin >> A >> B >> M;
vec a(A);
vec b(B);
for (int i = 0; i < A; i++)
cin >> a[i];
for (int i = 0; i < B; i++)
cin >> b[i];
vec x(M), y(M), c(M);
for (int i = 0; i < M; i++)
cin >> x[i] >> y[i] >> c[i];
int ans = 200000;
for (int i = 0; i < M; i++) {
int wa = a[x[i] - 1] + b[y[i] - 1] - c[i];
ans = min(ans, wa);
}
for (int i = 0; i < A; i++) {
for (int j = 0; j < B; j++) {
int wa = a[i] + b[j];
ans = min(ans, wa);
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using vec = vector<int>;
using intk = int64_t;
int main() {
int A, B, M;
cin >> A >> B >> M;
vec a(A);
vec b(B);
for (int i = 0; i < A; i++)
cin >> a[i];
for (int i = 0; i < B; i++)
cin >> b[i];
vec x(M), y(M), c(M);
for (int i = 0; i < M; i++)
cin >> x[i] >> y[i] >> c[i];
int ans = 200000;
for (int i = 0; i < M; i++) {
int wa = a[x[i] - 1] + b[y[i] - 1] - c[i];
ans = min(ans, wa);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int waa = a[0] + b[0];
ans = min(waa, ans);
cout << ans << endl;
}
| replace | 22 | 28 | 22 | 26 | TLE | |
p02748 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
int r;
int a[10005], b[10005], c[10005], d[10005], e[10005];
int main() {
int n, i, j, t, k, l, o, m, q, w;
cin >> m >> t >> k;
for (i = 1; i <= m; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i <= t; i++) {
scanf("%d", &b[i]);
}
for (i = 1; i <= k; i++) {
scanf("%d%d%d", &c[i], &d[i], &e[i]);
if (i == 1)
r = a[c[1]] + b[d[1]] - e[1];
r = min(r, a[c[i]] + b[d[i]] - e[i]);
}
sort(a + 1, a + 1 + m);
sort(b + 1, b + 1 + t);
r = min(a[1] + b[1], r);
cout << r;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
int r;
int a[100005], b[100005], c[100005], d[100005], e[100005];
int main() {
int n, i, j, t, k, l, o, m, q, w;
cin >> m >> t >> k;
for (i = 1; i <= m; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i <= t; i++) {
scanf("%d", &b[i]);
}
for (i = 1; i <= k; i++) {
scanf("%d%d%d", &c[i], &d[i], &e[i]);
if (i == 1)
r = a[c[1]] + b[d[1]] - e[1];
r = min(r, a[c[i]] + b[d[i]] - e[i]);
}
sort(a + 1, a + 1 + m);
sort(b + 1, b + 1 + t);
r = min(a[1] + b[1], r);
cout << r;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02748 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> valueA(A);
vector<int> valueB(B);
vector<int> setx;
vector<int> sety;
vector<int> waribiki;
for (int a = 0; a < A; ++a) {
cin >> valueA.at(a);
}
for (int b = 0; b < B; ++b) {
cin >> valueB.at(b);
}
for (int m = 0; m < M; m++) {
cin >> setx.at(m) >> sety.at(m) >> waribiki.at(m);
}
int minA;
if (valueA.size() == 1) {
minA = valueA.at(0);
} else {
minA = *min_element(valueA.begin(), valueA.end());
}
int minB;
if (valueB.size() == 1) {
minB = valueB.at(0);
} else {
minB = *min_element(valueB.begin(), valueB.end());
}
long minvalue = minA + minB;
for (int m = 0; m < M; ++m) {
long value =
valueA.at(setx.at(m) - 1) + valueB.at(sety.at(m) - 1) - waribiki.at(m);
if (minvalue > value) {
minvalue = value;
}
}
cout << minvalue << endl;
} | #include <algorithm>
#include <climits>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int A, B, M;
cin >> A >> B >> M;
vector<int> valueA(A);
vector<int> valueB(B);
vector<int> setx(M);
vector<int> sety(M);
vector<int> waribiki(M);
for (int a = 0; a < A; ++a) {
cin >> valueA.at(a);
}
for (int b = 0; b < B; ++b) {
cin >> valueB.at(b);
}
for (int m = 0; m < M; m++) {
cin >> setx.at(m) >> sety.at(m) >> waribiki.at(m);
}
int minA;
if (valueA.size() == 1) {
minA = valueA.at(0);
} else {
minA = *min_element(valueA.begin(), valueA.end());
}
int minB;
if (valueB.size() == 1) {
minB = valueB.at(0);
} else {
minB = *min_element(valueB.begin(), valueB.end());
}
long minvalue = minA + minB;
for (int m = 0; m < M; ++m) {
long value =
valueA.at(setx.at(m) - 1) + valueB.at(sety.at(m) - 1) - waribiki.at(m);
if (minvalue > value) {
minvalue = value;
}
}
cout << minvalue << endl;
} | replace | 14 | 17 | 14 | 17 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
|
p02749 | C++ | Runtime Error | #include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
#define LOG(FMT...) fprintf(stderr, FMT)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (T &x : v)
is >> x;
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
if (!v.empty()) {
os << v.front();
for (int i = 1; i < v.size(); ++i)
os << ' ' << v[i];
}
return os;
}
const int N = 100010;
int n;
bool vis[N], par[N];
vector<int> ver[2];
int cnt[3], pc[2], mat[3];
int ans[N];
vector<int> g[N];
void dfs(int u) {
++pc[par[u]];
ver[par[u]].push_back(u);
vis[u] = true;
for (int v : g[u])
if (!vis[v]) {
par[v] = !par[u];
dfs(v);
}
}
int main() {
#ifdef LBT
freopen("test.in", "r", stdin);
int nol_cl = clock();
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int rep = 1; rep < n; ++rep) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1);
for (int i = 1; i <= n; ++i)
++cnt[i % 3];
int mi = pc[0] < pc[1] ? 0 : 1, mj = cnt[1] < cnt[2] ? 1 : 2;
if (pc[mi] < cnt[mj]) {
mat[1] = mat[2] = !mi;
} else {
mat[mj] = mi;
mat[3 - mj] = !mi;
}
for (int i = 1; i <= n; ++i)
if (i % 3) {
ans[ver[mat[i % 3]].back()] = i;
ver[mat[i % 3]].pop_back();
}
for (int i = 1; i <= n; ++i)
if (i % 3 == 0) {
if (ver[0].empty())
swap(ver[0], ver[1]);
ans[ver[0].back()] = i;
ver[0].pop_back();
}
for (int i = 1; i <= n; ++i)
cout << ans[i] << ' ';
#ifdef LBT
LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
return 0;
}
| #include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
#define LOG(FMT...) fprintf(stderr, FMT)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (T &x : v)
is >> x;
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
if (!v.empty()) {
os << v.front();
for (int i = 1; i < v.size(); ++i)
os << ' ' << v[i];
}
return os;
}
const int N = 200010;
int n;
bool vis[N], par[N];
vector<int> ver[2];
int cnt[3], pc[2], mat[3];
int ans[N];
vector<int> g[N];
void dfs(int u) {
++pc[par[u]];
ver[par[u]].push_back(u);
vis[u] = true;
for (int v : g[u])
if (!vis[v]) {
par[v] = !par[u];
dfs(v);
}
}
int main() {
#ifdef LBT
freopen("test.in", "r", stdin);
int nol_cl = clock();
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int rep = 1; rep < n; ++rep) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1);
for (int i = 1; i <= n; ++i)
++cnt[i % 3];
int mi = pc[0] < pc[1] ? 0 : 1, mj = cnt[1] < cnt[2] ? 1 : 2;
if (pc[mi] < cnt[mj]) {
mat[1] = mat[2] = !mi;
} else {
mat[mj] = mi;
mat[3 - mj] = !mi;
}
for (int i = 1; i <= n; ++i)
if (i % 3) {
ans[ver[mat[i % 3]].back()] = i;
ver[mat[i % 3]].pop_back();
}
for (int i = 1; i <= n; ++i)
if (i % 3 == 0) {
if (ver[0].empty())
swap(ver[0], ver[1]);
ans[ver[0].back()] = i;
ver[0].pop_back();
}
for (int i = 1; i <= n; ++i)
cout << ans[i] << ' ';
#ifdef LBT
LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
return 0;
}
| replace | 44 | 45 | 44 | 45 | 0 | |
p02749 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define RFOR(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++)
#define setp(n) fixed << setprecision(n)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert
using namespace std;
vi color;
vector<vi> adj;
void dfs(int v, int c) {
color[v] = c;
for (auto u : adj[v]) {
if (color[u] != -1)
continue;
dfs(u, 1 - c);
}
}
//-------------------------------------------------
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
color.resize(n, -1);
adj.resize(n);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].pb(b);
adj[b].pb(a);
}
dfs(0, 0);
vi blank[2];
rep(i, n) blank[color[i]].pb(i);
int x = blank[0].size();
int y = blank[1].size();
if (x > y) {
swap(x, y);
blank[0].swap(blank[1]);
}
vi ans(n);
set<int> rnum, rspa;
rep(i, n) rnum.ins(i + 1), rspa.ins(i);
if (x <= 3 / n) {
rep(i, x) {
ans[blank[0][i]] = (i + 1) * 3;
rspa.erase(blank[0][i]);
rnum.erase((i + 1) * 3);
}
} else {
rep(i, (n + 2) / 3) {
ans[blank[0][i]] = i * 3 + 1;
rspa.erase(blank[0][i]);
rnum.erase(i * 3 + 1);
}
rep(i, (n + 1) / 3) {
ans[blank[1][i]] = i * 3 + 2;
rspa.erase(blank[1][i]);
rnum.erase(i * 3 + 2);
}
}
auto it = rnum.begin();
for (auto s : rspa) {
ans[s] = *it;
it++;
}
rep(i, n) {
if (i > 0)
cout << " ";
cout << ans[i];
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define RFOR(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++)
#define setp(n) fixed << setprecision(n)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert
using namespace std;
vi color;
vector<vi> adj;
void dfs(int v, int c) {
color[v] = c;
for (auto u : adj[v]) {
if (color[u] != -1)
continue;
dfs(u, 1 - c);
}
}
//-------------------------------------------------
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
color.resize(n, -1);
adj.resize(n);
rep(i, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
adj[a].pb(b);
adj[b].pb(a);
}
dfs(0, 0);
vi blank[2];
rep(i, n) blank[color[i]].pb(i);
int x = blank[0].size();
int y = blank[1].size();
if (x > y) {
swap(x, y);
blank[0].swap(blank[1]);
}
vi ans(n);
set<int> rnum, rspa;
rep(i, n) rnum.ins(i + 1), rspa.ins(i);
if (x <= n / 3) {
rep(i, x) {
ans[blank[0][i]] = (i + 1) * 3;
rspa.erase(blank[0][i]);
rnum.erase((i + 1) * 3);
}
} else {
rep(i, (n + 2) / 3) {
ans[blank[0][i]] = i * 3 + 1;
rspa.erase(blank[0][i]);
rnum.erase(i * 3 + 1);
}
rep(i, (n + 1) / 3) {
ans[blank[1][i]] = i * 3 + 2;
rspa.erase(blank[1][i]);
rnum.erase(i * 3 + 2);
}
}
auto it = rnum.begin();
for (auto s : rspa) {
ans[s] = *it;
it++;
}
rep(i, n) {
if (i > 0)
cout << " ";
cout << ans[i];
}
cout << endl;
return 0;
}
| replace | 81 | 82 | 81 | 82 | 0 | |
p02749 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
const int INF = 1000 * 1000 * 1000 + 7;
const ll LINF = INF * (ll)INF;
const int mod = INF;
const int MAX = 1 << 25;
int depth[100005];
int ans[100005];
vector<int> g[100005];
void dfs(int u, int p = -1) {
for (auto v : g[u]) {
if (v == p)
continue;
depth[v] = depth[u] ^ 1;
dfs(v, u);
}
}
void put(vector<int> &a, int val) {
ans[a.back()] = val;
a.pop_back();
}
void solve(vector<int> &y, int a, int b, int c) {
if (c) {
do {
put(y, c * 3);
c--;
} while (c);
}
if (b) {
do {
put(y, b * 3 - 1);
b--;
} while (b);
}
if (a) {
do {
put(y, a * 3 - 2);
a--;
} while (a);
}
}
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
g[u].pb(v);
g[v].pb(u);
}
dfs(0);
vector<int> A, B;
for (int i = 0; i < n; i++) {
if (depth[i] == 0)
A.pb(i);
else
B.pb(i);
}
if (sz(A) > sz(B))
swap(A, B);
int x = sz(A), y = sz(B);
int a = (n + 2) / 3, b = (n + 1) / 3, c = n / 3;
if (x <= c) {
for (int i = 0; i < x; i++) {
put(A, c * 3);
c--;
}
solve(B, a, b, c);
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
return 0;
}
if (x >= a && y >= b) {
do {
put(A, a * 3 - 2);
a--;
} while (a);
do {
put(B, b * 3 - 1);
b--;
} while (b);
if (A.size()) {
do {
put(A, c * 3);
c--;
} while (A.size());
}
if (B.size()) {
do {
put(B, c * 3);
c--;
} while (B.size());
}
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
return 0;
}
assert(false);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define x first
#define y second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
const int INF = 1000 * 1000 * 1000 + 7;
const ll LINF = INF * (ll)INF;
const int mod = INF;
const int MAX = 1 << 25;
int depth[200005];
int ans[200005];
vector<int> g[200005];
void dfs(int u, int p = -1) {
for (auto v : g[u]) {
if (v == p)
continue;
depth[v] = depth[u] ^ 1;
dfs(v, u);
}
}
void put(vector<int> &a, int val) {
ans[a.back()] = val;
a.pop_back();
}
void solve(vector<int> &y, int a, int b, int c) {
if (c) {
do {
put(y, c * 3);
c--;
} while (c);
}
if (b) {
do {
put(y, b * 3 - 1);
b--;
} while (b);
}
if (a) {
do {
put(y, a * 3 - 2);
a--;
} while (a);
}
}
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
g[u].pb(v);
g[v].pb(u);
}
dfs(0);
vector<int> A, B;
for (int i = 0; i < n; i++) {
if (depth[i] == 0)
A.pb(i);
else
B.pb(i);
}
if (sz(A) > sz(B))
swap(A, B);
int x = sz(A), y = sz(B);
int a = (n + 2) / 3, b = (n + 1) / 3, c = n / 3;
if (x <= c) {
for (int i = 0; i < x; i++) {
put(A, c * 3);
c--;
}
solve(B, a, b, c);
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
return 0;
}
if (x >= a && y >= b) {
do {
put(A, a * 3 - 2);
a--;
} while (a);
do {
put(B, b * 3 - 1);
b--;
} while (b);
if (A.size()) {
do {
put(A, c * 3);
c--;
} while (A.size());
}
if (B.size()) {
do {
put(B, c * 3);
c--;
} while (B.size());
}
for (int i = 0; i < n; i++)
cout << ans[i] << " ";
return 0;
}
assert(false);
}
| replace | 13 | 16 | 13 | 16 | 0 | |
p02749 | C++ | Runtime Error | #include <bits/stdc++.h> // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim_i = (b); i < lim_i; i++)
#define REP(i, ...) REP_((i), __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif // clang-format on
/**
* author: knshnb
* created: Sun Mar 8 21:00:01 JST 2020
**/
signed main() {
int n;
cin >> n;
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
int one = n / 3 + (n % 3 >= 1);
int two = n / 3 + (n % 3 >= 2);
int zer = n / 3;
assert(one + two + zer == n);
int cur_one = 1;
vector<int> color(n, -1);
auto dfs = [&](auto f, int v, int prv) -> void {
for (int s : g[v]) {
if (s == prv)
continue;
color[s] = 3 - color[v];
cur_one += color[s] == 1;
f(f, s, v);
}
};
color[0] = 1;
dfs(dfs, 0, -1);
int cur_two = n - cur_one;
if (cur_one <= zer) {
int rem_zer = zer - cur_one;
int rem_one = one;
REP(i, n) {
if (color[i] == 1) {
color[i] = 0;
} else {
if (rem_zer-- > 0) {
color[i] = 0;
}
if (rem_one-- > 0) {
dump(rem_one);
color[i] = 1;
}
}
}
} else if (cur_two <= zer) {
int rem_zer = zer - cur_two;
int rem_two = two;
REP(i, n) {
if (color[i] == 2) {
color[i] = 0;
} else {
if (rem_zer-- > 0) {
color[i] = 0;
} else if (rem_two-- > 0) {
color[i] = 2;
}
}
}
} else {
int x = 0, y = 0;
REP(i, n) {
if (color[i] == 1) {
if (x++ >= one) {
color[i] = 0;
}
} else {
if (y++ >= two) {
color[i] = 0;
}
}
}
}
//
dump(color);
REP(k, 3) {
int acc = k == 0 ? 3 : 0;
REP(i, n) {
if (color[i] == k) {
color[i] += acc;
acc += 3;
}
}
}
vector<int> tmp = color;
sort(tmp.begin(), tmp.end());
REP(i, n) { assert(tmp[i] == i + 1); }
for (Int x : color)
cout << x << " ";
cout << endl;
}
| #include <bits/stdc++.h> // clang-format off
using namespace std;
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (int i = (a), lim_i = (b); i < lim_i; i++)
#define REP(i, ...) REP_((i), __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif // clang-format on
/**
* author: knshnb
* created: Sun Mar 8 21:00:01 JST 2020
**/
signed main() {
int n;
cin >> n;
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
int one = n / 3 + (n % 3 >= 1);
int two = n / 3 + (n % 3 >= 2);
int zer = n / 3;
assert(one + two + zer == n);
int cur_one = 1;
vector<int> color(n, -1);
auto dfs = [&](auto f, int v, int prv) -> void {
for (int s : g[v]) {
if (s == prv)
continue;
color[s] = 3 - color[v];
cur_one += color[s] == 1;
f(f, s, v);
}
};
color[0] = 1;
dfs(dfs, 0, -1);
int cur_two = n - cur_one;
if (cur_one <= zer) {
int rem_zer = zer - cur_one;
int rem_one = one;
REP(i, n) {
if (color[i] == 1) {
color[i] = 0;
} else {
if (rem_zer-- > 0) {
color[i] = 0;
} else if (rem_one-- > 0) {
dump(rem_one);
color[i] = 1;
}
}
}
} else if (cur_two <= zer) {
int rem_zer = zer - cur_two;
int rem_two = two;
REP(i, n) {
if (color[i] == 2) {
color[i] = 0;
} else {
if (rem_zer-- > 0) {
color[i] = 0;
} else if (rem_two-- > 0) {
color[i] = 2;
}
}
}
} else {
int x = 0, y = 0;
REP(i, n) {
if (color[i] == 1) {
if (x++ >= one) {
color[i] = 0;
}
} else {
if (y++ >= two) {
color[i] = 0;
}
}
}
}
//
dump(color);
REP(k, 3) {
int acc = k == 0 ? 3 : 0;
REP(i, n) {
if (color[i] == k) {
color[i] += acc;
acc += 3;
}
}
}
vector<int> tmp = color;
sort(tmp.begin(), tmp.end());
REP(i, n) { assert(tmp[i] == i + 1); }
for (Int x : color)
cout << x << " ";
cout << endl;
}
| replace | 53 | 55 | 53 | 54 | 0 | |
p02749 | C++ | Runtime Error | //@formatter:off
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define rep2(i, s, n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
return is >> p.first >> p.second;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << '{' << p.first << "," << p.second << '}';
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (T &t : v) {
is >> t;
}
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '[';
rep(i, v.size()) os << v[i] << (i == int(v.size() - 1) ? "" : ",");
return os << ']';
}
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vvi G(n);
rep(_, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].pb(b);
G[b].pb(a);
}
vvi ls(2);
auto dfs = [&](auto &self, int v = 0, int p = -1, int c = 0) -> void {
ls[c].pb(v);
for (int u : G[v]) {
if (u == p)
continue;
self(self, u, v, 1 - c);
}
};
dfs(dfs);
if (ls[0].size() < ls[1].size())
swap(ls[0], ls[1]);
int a = n / 3, b = n / 3;
if (n % 3 == 2)
a++, b++;
else if (n % 3 == 1)
a++;
vi ans(n);
if (ls[1].size() >= b) {
rep(i, a) ans[ls[0][i]] = i * 3 + 1;
rep(i, b) ans[ls[1][i]] = i * 3 + 2;
int cnt = 0;
rep2(i, a, ls[0].size()) {
ans[ls[0][i]] = cnt * 3 + 3;
cnt++;
}
rep2(i, b, ls[1].size()) {
ans[ls[1][i]] = cnt * 3 + 3;
cnt++;
}
} else {
rep(i, a) ans[ls[0][i]] = i * 3 + 1;
rep2(i, a, a + b) ans[ls[0][i]] = i * 3 + 2;
int cnt = 0;
rep2(i, a + b, ls[0].size()) {
ans[ls[0][i]] = cnt * 3 + 3;
cnt++;
}
rep(i, ls[1].size()) {
ans[ls[1][i]] = cnt * 3 + 3;
cnt++;
}
}
for (int i : ans) {
cout << i << ' ';
assert(i <= n);
}
cout << endl;
}
| //@formatter:off
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define rep2(i, s, n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
return is >> p.first >> p.second;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << '{' << p.first << "," << p.second << '}';
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (T &t : v) {
is >> t;
}
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << '[';
rep(i, v.size()) os << v[i] << (i == int(v.size() - 1) ? "" : ",");
return os << ']';
}
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vvi G(n);
rep(_, n - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].pb(b);
G[b].pb(a);
}
vvi ls(2);
auto dfs = [&](auto &self, int v = 0, int p = -1, int c = 0) -> void {
ls[c].pb(v);
for (int u : G[v]) {
if (u == p)
continue;
self(self, u, v, 1 - c);
}
};
dfs(dfs);
if (ls[0].size() < ls[1].size())
swap(ls[0], ls[1]);
int a = n / 3, b = n / 3;
if (n % 3 == 2)
a++, b++;
else if (n % 3 == 1)
a++;
vi ans(n);
if (ls[1].size() >= b) {
rep(i, a) ans[ls[0][i]] = i * 3 + 1;
rep(i, b) ans[ls[1][i]] = i * 3 + 2;
int cnt = 0;
rep2(i, a, ls[0].size()) {
ans[ls[0][i]] = cnt * 3 + 3;
cnt++;
}
rep2(i, b, ls[1].size()) {
ans[ls[1][i]] = cnt * 3 + 3;
cnt++;
}
} else {
rep(i, a) ans[ls[0][i]] = i * 3 + 1;
rep2(i, a, a + b) ans[ls[0][i]] = (i - a) * 3 + 2;
int cnt = 0;
rep2(i, a + b, ls[0].size()) {
ans[ls[0][i]] = cnt * 3 + 3;
cnt++;
}
rep(i, ls[1].size()) {
ans[ls[1][i]] = cnt * 3 + 3;
cnt++;
}
}
for (int i : ans) {
cout << i << ' ';
assert(i <= n);
}
cout << endl;
}
| replace | 111 | 112 | 111 | 112 | 0 | |
p02749 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = n - 1; i >= m; --i)
#define FORE(x, xs) for (const auto &x : xs)
#define FORI(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x, y) x = min(x, y)
#define CHMAX(x, y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl
struct UnionFind {
private:
int N;
vi parent;
vi rank_;
void init(int n) {
N = n;
parent.resize(0);
parent.clear();
parent.resize(n);
REP(i, N) parent[i] = i;
rank_.resize(0);
rank_.clear();
rank_.resize(n);
}
public:
UnionFind() { init(0); }
UnionFind(int n) { init(n); }
int root(int x) { return (parent[x] == x) ? x : parent[x] = root(parent[x]); }
bool isSame(int x, int y) { return root(x) == root(y); }
void merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (rank_[x] < rank_[y])
parent[x] = y;
else {
parent[y] = x;
if (rank_[x] == rank_[y])
rank_[x]++;
}
}
};
class BipartiteGraph {
private:
int N;
UnionFind uf;
bool valid;
void init(int n) {
N = n;
uf = UnionFind(2 * N);
valid = true;
}
public:
BipartiteGraph() { init(0); }
BipartiteGraph(int n) { init(n); }
void add(int u, int v) {
uf.merge(u, v + N);
uf.merge(u + N, v);
valid &= !(uf.isSame(u, u + N) || uf.isSame(v, v + N));
}
bool isValid() { return valid; }
pair<set<int>, set<int>> get() {
assert(valid);
set<int> u, v;
REP(i, N) {
if (uf.isSame(i, 0))
u.insert(i);
else
v.insert(i);
}
return make_pair(u, v);
}
};
int N;
BipartiteGraph bi;
int main() {
cin >> N;
bi = BipartiteGraph(N);
REP(i, N - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
bi.add(a, b);
}
vi ans(N);
set<int> u, v;
tie(u, v) = bi.get();
if (v.size() > u.size())
swap(u, v);
int n = 1;
FORI(iter, u) {
ans[*iter] = n;
n += 3;
if (n > N)
break;
}
n = 2;
if (v.size() >= (N + 1) / 3) {
FORI(iter, v) {
ans[*iter] = n;
n += 3;
if (n > N)
break;
}
} else {
for (auto iter = next(u.begin(), (N + 2) / 3);; iter++) {
FORI(iter, v) {
ans[*iter] = n;
n += 3;
if (n > N)
break;
}
}
}
n = 3;
REP(i, N) {
if (ans[i] != 0)
continue;
ans[i] = n;
n += 3;
}
REP(i, N) cout << ans[i] << " ";
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = n - 1; i >= m; --i)
#define FORE(x, xs) for (const auto &x : xs)
#define FORI(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x, y) x = min(x, y)
#define CHMAX(x, y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl
struct UnionFind {
private:
int N;
vi parent;
vi rank_;
void init(int n) {
N = n;
parent.resize(0);
parent.clear();
parent.resize(n);
REP(i, N) parent[i] = i;
rank_.resize(0);
rank_.clear();
rank_.resize(n);
}
public:
UnionFind() { init(0); }
UnionFind(int n) { init(n); }
int root(int x) { return (parent[x] == x) ? x : parent[x] = root(parent[x]); }
bool isSame(int x, int y) { return root(x) == root(y); }
void merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (rank_[x] < rank_[y])
parent[x] = y;
else {
parent[y] = x;
if (rank_[x] == rank_[y])
rank_[x]++;
}
}
};
class BipartiteGraph {
private:
int N;
UnionFind uf;
bool valid;
void init(int n) {
N = n;
uf = UnionFind(2 * N);
valid = true;
}
public:
BipartiteGraph() { init(0); }
BipartiteGraph(int n) { init(n); }
void add(int u, int v) {
uf.merge(u, v + N);
uf.merge(u + N, v);
valid &= !(uf.isSame(u, u + N) || uf.isSame(v, v + N));
}
bool isValid() { return valid; }
pair<set<int>, set<int>> get() {
assert(valid);
set<int> u, v;
REP(i, N) {
if (uf.isSame(i, 0))
u.insert(i);
else
v.insert(i);
}
return make_pair(u, v);
}
};
int N;
BipartiteGraph bi;
int main() {
cin >> N;
bi = BipartiteGraph(N);
REP(i, N - 1) {
int a, b;
cin >> a >> b;
a--;
b--;
bi.add(a, b);
}
vi ans(N);
set<int> u, v;
tie(u, v) = bi.get();
if (v.size() > u.size())
swap(u, v);
int n = 1;
FORI(iter, u) {
ans[*iter] = n;
n += 3;
if (n > N)
break;
}
n = 2;
if (v.size() >= (N + 1) / 3) {
FORI(iter, v) {
ans[*iter] = n;
n += 3;
if (n > N)
break;
}
} else {
for (auto iter = next(u.begin(), (N + 2) / 3);; iter++) {
ans[*iter] = n;
n += 3;
if (n > N)
break;
}
}
n = 3;
REP(i, N) {
if (ans[i] != 0)
continue;
ans[i] = n;
n += 3;
}
REP(i, N) cout << ans[i] << " ";
cout << endl;
} | replace | 142 | 148 | 142 | 146 | TLE | |
p02749 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
vector<int> G[200010];
int col[100010];
void dfs(int v, int p, int c) {
col[v] = c;
for (int u : G[v]) {
if (u == p)
continue;
dfs(u, v, c ^ 1);
}
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n - 1; i++) {
int a, b;
scanf("%d%d", &a, &b);
G[a].push_back(b);
G[b].push_back(a);
}
dfs(1, 0, 0);
int cnt[2] = {};
for (int i = 1; i <= n; i++) {
cnt[col[i]]++;
}
int a, b, c;
a = b = c = n / 3;
if (n % 3 >= 1)
a++;
if (n % 3 >= 2)
b++;
static int ret[200010];
static bool used[200010];
for (int i = 0; i < 200010; i++) {
used[i] = false;
}
if (cnt[0] <= c || cnt[1] <= c) {
int t = 0;
if (cnt[0] > c)
t = 1;
int CNT = 0;
for (int i = 1; i <= n; i++) {
if (col[i] == t) {
CNT++;
ret[i] = CNT * 3;
used[ret[i]] = true;
}
}
CNT = 1;
for (int i = 1; i <= n; i++) {
if (col[i] != t) {
while (used[CNT])
CNT++;
ret[i] = CNT;
used[ret[i]] = true;
}
}
} else {
cnt[0] = cnt[1] = 0;
int k = 3;
for (int i = 1; i <= n; i++) {
if (3 * cnt[col[i]] + 1 + col[i] <= n) {
ret[i] = 3 * cnt[col[i]] + 1 + col[i];
} else {
while (used[k])
k += 3;
ret[i] = k;
}
cnt[col[i]]++;
used[ret[i]] = true;
}
}
for (int i = 1; i <= n; i++) {
printf("%d%c", ret[i], (i == n) ? '\n' : ' ');
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
vector<int> G[200010];
int col[200010];
void dfs(int v, int p, int c) {
col[v] = c;
for (int u : G[v]) {
if (u == p)
continue;
dfs(u, v, c ^ 1);
}
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n - 1; i++) {
int a, b;
scanf("%d%d", &a, &b);
G[a].push_back(b);
G[b].push_back(a);
}
dfs(1, 0, 0);
int cnt[2] = {};
for (int i = 1; i <= n; i++) {
cnt[col[i]]++;
}
int a, b, c;
a = b = c = n / 3;
if (n % 3 >= 1)
a++;
if (n % 3 >= 2)
b++;
static int ret[200010];
static bool used[200010];
for (int i = 0; i < 200010; i++) {
used[i] = false;
}
if (cnt[0] <= c || cnt[1] <= c) {
int t = 0;
if (cnt[0] > c)
t = 1;
int CNT = 0;
for (int i = 1; i <= n; i++) {
if (col[i] == t) {
CNT++;
ret[i] = CNT * 3;
used[ret[i]] = true;
}
}
CNT = 1;
for (int i = 1; i <= n; i++) {
if (col[i] != t) {
while (used[CNT])
CNT++;
ret[i] = CNT;
used[ret[i]] = true;
}
}
} else {
cnt[0] = cnt[1] = 0;
int k = 3;
for (int i = 1; i <= n; i++) {
if (3 * cnt[col[i]] + 1 + col[i] <= n) {
ret[i] = 3 * cnt[col[i]] + 1 + col[i];
} else {
while (used[k])
k += 3;
ret[i] = k;
}
cnt[col[i]]++;
used[ret[i]] = true;
}
}
for (int i = 1; i <= n; i++) {
printf("%d%c", ret[i], (i == n) ? '\n' : ' ');
}
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02749 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())
typedef long long ll;
const int MAXN = 2e5 + 1;
vector<int> G[MAXN];
vector<int> side[2];
vector<int> colors[3];
int choice[MAXN];
void dfs(int u, int p, int s) {
side[s].push_back(u);
for (auto v : G[u])
if (v != p)
dfs(v, u, !s);
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
for (int i(1); i < N; ++i) {
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1, 1, 0);
for (int i(1); i <= N; ++i)
colors[i % 3].push_back(i);
if (SZ(side[0]) > SZ(side[1]))
swap(side[0], side[1]);
if (SZ(side[0]) <= SZ(colors[0])) {
while (SZ(side[0]) > 0) {
choice[side[0].back()] = colors[0].back();
colors[0].pop_back();
side[0].pop_back();
}
for (int c(0); c < 3; ++c)
while (SZ(colors[c]) > 0) {
choice[side[1].back()] = colors[c].back();
side[1].pop_back();
colors[c].pop_back();
}
} else {
while (SZ(colors[1]) > 0) {
choice[side[1].back()] = colors[1].back();
side[1].pop_back();
colors[1].pop_back();
}
while (SZ(colors[0]) > 0) {
choice[side[1].back()] = colors[0].back();
side[1].pop_back();
colors[0].pop_back();
}
for (int c : {0, 2})
while (SZ(colors[c]) > 0) {
choice[side[0].back()] = colors[c].back();
side[0].pop_back();
colors[c].pop_back();
}
}
for (int i(1); i <= N; ++i)
cout << choice[i] << ' ';
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())
typedef long long ll;
const int MAXN = 2e5 + 1;
vector<int> G[MAXN];
vector<int> side[2];
vector<int> colors[3];
int choice[MAXN];
void dfs(int u, int p, int s) {
side[s].push_back(u);
for (auto v : G[u])
if (v != p)
dfs(v, u, !s);
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N;
cin >> N;
for (int i(1); i < N; ++i) {
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1, 1, 0);
for (int i(1); i <= N; ++i)
colors[i % 3].push_back(i);
if (SZ(side[0]) > SZ(side[1]))
swap(side[0], side[1]);
if (SZ(side[0]) <= SZ(colors[0])) {
while (SZ(side[0]) > 0) {
choice[side[0].back()] = colors[0].back();
colors[0].pop_back();
side[0].pop_back();
}
for (int c(0); c < 3; ++c)
while (SZ(colors[c]) > 0) {
choice[side[1].back()] = colors[c].back();
side[1].pop_back();
colors[c].pop_back();
}
} else {
while (SZ(colors[1]) > 0) {
choice[side[1].back()] = colors[1].back();
side[1].pop_back();
colors[1].pop_back();
}
while (SZ(side[1]) > 0) {
choice[side[1].back()] = colors[0].back();
side[1].pop_back();
colors[0].pop_back();
}
for (int c : {0, 2})
while (SZ(colors[c]) > 0) {
choice[side[0].back()] = colors[c].back();
side[0].pop_back();
colors[c].pop_back();
}
}
for (int i(1); i <= N; ++i)
cout << choice[i] << ' ';
cout << endl;
}
| replace | 58 | 59 | 58 | 59 | 0 | |
p02749 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v, n) memset(v, (li)n, sizeof(v))
#define bit(n) (1ll << (li)(n))
#define mp(a, b) make_pair(a, b)
#define rin rep(i, n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 998244353
typedef pair<li, li> PI;
#define INF bit(60)
#define DBGP 1
#define idp if (DBGP)
#define F first
#define S second
#define p2(a, b) idp cout << a << "\t" << b << endl
#define p3(a, b, c) idp cout << a << "\t" << b << "\t" << c << endl
#define p4(a, b, c, d) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << endl
#define p5(a, b, c, d, e) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << endl
#define p6(a, b, c, d, e, f) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << endl
#define p7(a, b, c, d, e, f, g) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << endl
#define p8(a, b, c, d, e, f, g, h) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << endl
#define p9(a, b, c, d, e, f, g, h, i) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << endl
#define p10(a, b, c, d, e, f, g, h, i, j) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << "\t" << j << endl
#define foreach(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define p2p(x) idp p2((x).F, (x).S)
#define dump(x, n) \
idp { \
rep(i, n) { cout << x[i] << " "; } \
puts(""); \
}
#define dump2(x, n) \
idp { \
rep(i, n) { cout << "[" << x[i].F << " , " << x[i].S << "] "; } \
puts(""); \
}
#define dumpi(x) \
idp { \
foreach (it, x) { \
cout << (*it) << " "; \
} \
puts(""); \
}
#define dumpi2(x) \
idp { \
foreach (it, x) { \
cout << "[" << (it)->F << " , " << (it)->S << "] "; \
} \
puts(""); \
}
#define read2d(a, w, h) rep(i, h) rep(j, w) cin >> a[i][j]
#define dump2d(a, w, h) \
rep(i, h) { \
rep(j, w) cout << a[i][j] << " "; \
puts(""); \
}
typedef pair<li, li> PI;
li d[200100];
li n;
vector<li> edges[200200];
li res[200200];
int main() {
li n;
cin >> n;
rep(i, n - 1) {
li a, b;
cin >> a >> b;
a--;
b--;
edges[a].pb(b);
edges[b].pb(a);
}
rin { d[i] = INF; }
stack<PI> stk;
stk.push({0, 0});
while (!stk.empty()) {
li now = stk.top().F;
li distance = stk.top().S;
stk.pop();
if (d[now] != INF) {
continue;
}
d[now] = distance;
for (auto &&next : edges[now]) {
if (d[next] != INF) {
continue;
}
stk.emplace(next, (distance + 1) % 2);
}
}
li cnt[2];
rin { cnt[d[i]]++; }
if (cnt[0] * 3 < n) {
queue<li> q12;
queue<li> q3;
rin {
if ((i + 1) % 3 == 0) {
q3.push(i + 1);
} else {
q12.push(i + 1);
}
}
rin {
if (d[i] == 0) {
res[i] = q3.front();
q3.pop();
} else {
if (!q12.empty()) {
res[i] = q12.front();
q12.pop();
} else {
res[i] = q3.front();
q3.pop();
}
}
}
} else if (cnt[1] * 3 < n) {
queue<li> q12;
queue<li> q3;
rin {
if ((i + 1) % 3 == 0) {
q3.push(i + 1);
} else {
q12.push(i + 1);
}
}
rin {
if (d[i] == 1) {
res[i] = q3.front();
q3.pop();
} else {
if (!q12.empty()) {
res[i] = q12.front();
q12.pop();
} else {
res[i] = q3.front();
q3.pop();
}
}
}
} else {
queue<li> q[3];
rin { q[(i + 1) % 3].push(i + 1); }
rin {
if (d[i] == 0) {
if (q[1].empty()) {
res[i] = q[0].front();
q[0].pop();
} else {
res[i] = q[1].front();
q[1].pop();
}
} else {
if (q[2].empty()) {
res[i] = q[0].front();
q[0].pop();
} else {
res[i] = q[2].front();
q[2].pop();
}
}
}
}
rin { cout << res[i] << " "; }
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v, n) memset(v, (li)n, sizeof(v))
#define bit(n) (1ll << (li)(n))
#define mp(a, b) make_pair(a, b)
#define rin rep(i, n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 998244353
typedef pair<li, li> PI;
#define INF bit(60)
#define DBGP 1
#define idp if (DBGP)
#define F first
#define S second
#define p2(a, b) idp cout << a << "\t" << b << endl
#define p3(a, b, c) idp cout << a << "\t" << b << "\t" << c << endl
#define p4(a, b, c, d) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << endl
#define p5(a, b, c, d, e) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << endl
#define p6(a, b, c, d, e, f) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << endl
#define p7(a, b, c, d, e, f, g) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << endl
#define p8(a, b, c, d, e, f, g, h) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << endl
#define p9(a, b, c, d, e, f, g, h, i) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << endl
#define p10(a, b, c, d, e, f, g, h, i, j) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << "\t" << j << endl
#define foreach(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define p2p(x) idp p2((x).F, (x).S)
#define dump(x, n) \
idp { \
rep(i, n) { cout << x[i] << " "; } \
puts(""); \
}
#define dump2(x, n) \
idp { \
rep(i, n) { cout << "[" << x[i].F << " , " << x[i].S << "] "; } \
puts(""); \
}
#define dumpi(x) \
idp { \
foreach (it, x) { \
cout << (*it) << " "; \
} \
puts(""); \
}
#define dumpi2(x) \
idp { \
foreach (it, x) { \
cout << "[" << (it)->F << " , " << (it)->S << "] "; \
} \
puts(""); \
}
#define read2d(a, w, h) rep(i, h) rep(j, w) cin >> a[i][j]
#define dump2d(a, w, h) \
rep(i, h) { \
rep(j, w) cout << a[i][j] << " "; \
puts(""); \
}
typedef pair<li, li> PI;
li d[200100];
li n;
vector<li> edges[200200];
li res[200200];
int main() {
li n;
cin >> n;
rep(i, n - 1) {
li a, b;
cin >> a >> b;
a--;
b--;
edges[a].pb(b);
edges[b].pb(a);
}
rin { d[i] = INF; }
stack<PI> stk;
stk.push({0, 0});
while (!stk.empty()) {
li now = stk.top().F;
li distance = stk.top().S;
stk.pop();
if (d[now] != INF) {
continue;
}
d[now] = distance;
for (auto &&next : edges[now]) {
if (d[next] != INF) {
continue;
}
stk.emplace(next, (distance + 1) % 2);
}
}
li cnt[2] = {0};
rin { cnt[d[i]]++; }
if (cnt[0] * 3 < n) {
queue<li> q12;
queue<li> q3;
rin {
if ((i + 1) % 3 == 0) {
q3.push(i + 1);
} else {
q12.push(i + 1);
}
}
rin {
if (d[i] == 0) {
res[i] = q3.front();
q3.pop();
} else {
if (!q12.empty()) {
res[i] = q12.front();
q12.pop();
} else {
res[i] = q3.front();
q3.pop();
}
}
}
} else if (cnt[1] * 3 < n) {
queue<li> q12;
queue<li> q3;
rin {
if ((i + 1) % 3 == 0) {
q3.push(i + 1);
} else {
q12.push(i + 1);
}
}
rin {
if (d[i] == 1) {
res[i] = q3.front();
q3.pop();
} else {
if (!q12.empty()) {
res[i] = q12.front();
q12.pop();
} else {
res[i] = q3.front();
q3.pop();
}
}
}
} else {
queue<li> q[3];
rin { q[(i + 1) % 3].push(i + 1); }
rin {
if (d[i] == 0) {
if (q[1].empty()) {
res[i] = q[0].front();
q[0].pop();
} else {
res[i] = q[1].front();
q[1].pop();
}
} else {
if (q[2].empty()) {
res[i] = q[0].front();
q[0].pop();
} else {
res[i] = q[2].front();
q[2].pop();
}
}
}
}
rin { cout << res[i] << " "; }
cout << endl;
return 0;
} | replace | 124 | 125 | 124 | 125 | 0 | |
p02749 | C++ | Runtime Error | #include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define N 100010
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
int n, a[N], dep[N], cnt0, cnt1, res1, res2;
vector<int> vec[N], G[N];
void dfs(int u, int fa) {
dep[u] = dep[fa] + 1;
vec[dep[u]].push_back(u);
for (auto v : G[u]) {
if (v == fa)
continue;
dfs(v, u);
}
}
int main() {
n = read();
for (int i = 1; i < n; ++i) {
int u = read(), v = read();
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1, 0);
for (int i = 1; i <= n; ++i) {
if (i & 1)
cnt1 += vec[i].size();
else
cnt0 += vec[i].size();
}
res1 = n / 3 + (n % 3 >= 1), res2 = n / 3 + (n % 3 >= 2);
if (max(cnt1, cnt0) >= res1 && min(cnt0, cnt1) >= res2) {
for (int i = 1; i <= n; ++i) {
if ((i & 1) ^ (cnt1 <= cnt0)) {
for (auto u : vec[i]) {
if (!res1)
break;
--res1;
a[u] = res1 * 3 + 1;
}
} else {
for (auto u : vec[i]) {
if (!res2)
break;
--res2;
a[u] = res2 * 3 + 2;
}
}
}
} else {
for (int i = 1 + (cnt1 < cnt0); i <= n; i += 2) {
for (auto u : vec[i]) {
if (res1) {
--res1;
a[u] = res1 * 3 + 1;
} else if (res2) {
--res2;
a[u] = res2 * 3 + 2;
}
}
}
}
int now = 1;
for (int i = 1; i <= n; ++i) {
if (!a[i]) {
a[i] = now * 3;
++now;
}
}
for (int i = 1; i <= n; ++i) {
printf("%d ", a[i]);
}
printf("\n");
return 0;
}
| #include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define N 200010
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return x * f;
}
int n, a[N], dep[N], cnt0, cnt1, res1, res2;
vector<int> vec[N], G[N];
void dfs(int u, int fa) {
dep[u] = dep[fa] + 1;
vec[dep[u]].push_back(u);
for (auto v : G[u]) {
if (v == fa)
continue;
dfs(v, u);
}
}
int main() {
n = read();
for (int i = 1; i < n; ++i) {
int u = read(), v = read();
G[u].push_back(v);
G[v].push_back(u);
}
dfs(1, 0);
for (int i = 1; i <= n; ++i) {
if (i & 1)
cnt1 += vec[i].size();
else
cnt0 += vec[i].size();
}
res1 = n / 3 + (n % 3 >= 1), res2 = n / 3 + (n % 3 >= 2);
if (max(cnt1, cnt0) >= res1 && min(cnt0, cnt1) >= res2) {
for (int i = 1; i <= n; ++i) {
if ((i & 1) ^ (cnt1 <= cnt0)) {
for (auto u : vec[i]) {
if (!res1)
break;
--res1;
a[u] = res1 * 3 + 1;
}
} else {
for (auto u : vec[i]) {
if (!res2)
break;
--res2;
a[u] = res2 * 3 + 2;
}
}
}
} else {
for (int i = 1 + (cnt1 < cnt0); i <= n; i += 2) {
for (auto u : vec[i]) {
if (res1) {
--res1;
a[u] = res1 * 3 + 1;
} else if (res2) {
--res2;
a[u] = res2 * 3 + 2;
}
}
}
}
int now = 1;
for (int i = 1; i <= n; ++i) {
if (!a[i]) {
a[i] = now * 3;
++now;
}
}
for (int i = 1; i <= n; ++i) {
printf("%d ", a[i]);
}
printf("\n");
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02749 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 1e5 + 5, INF = 0x3f3f3f3f;
inline int read() {
int x = 0, f = 0;
char ch = 0;
while (!isdigit(ch))
f |= ch == '-', ch = getchar();
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
int ans[N];
vector<int> G[N], col[2], mod[3];
void dfs(int x, int c, int fa) {
col[c].push_back(x);
for (auto y : G[x])
if (y != fa)
dfs(y, c ^ 1, x);
}
void sol(int i, int j) {
while (!col[i].empty() && !mod[j].empty()) {
ans[col[i].back()] = mod[j].back();
col[i].pop_back(), mod[j].pop_back();
}
}
int main() {
int n = read();
for (int i = 1; i < n; i++) {
int x = read(), y = read();
G[x].pb(y), G[y].pb(x);
}
for (int i = 1; i <= n; i++)
mod[i % 3].pb(i);
dfs(1, 0, 0);
sol(col[0].size() < col[1].size(), 1), sol(col[0].size() < col[1].size(), 2);
sol(0, 0), sol(1, 0);
for (int i = 1; i <= n; i++)
printf("%d ", ans[i]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 2e5 + 5, INF = 0x3f3f3f3f;
inline int read() {
int x = 0, f = 0;
char ch = 0;
while (!isdigit(ch))
f |= ch == '-', ch = getchar();
while (isdigit(ch))
x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
int ans[N];
vector<int> G[N], col[2], mod[3];
void dfs(int x, int c, int fa) {
col[c].push_back(x);
for (auto y : G[x])
if (y != fa)
dfs(y, c ^ 1, x);
}
void sol(int i, int j) {
while (!col[i].empty() && !mod[j].empty()) {
ans[col[i].back()] = mod[j].back();
col[i].pop_back(), mod[j].pop_back();
}
}
int main() {
int n = read();
for (int i = 1; i < n; i++) {
int x = read(), y = read();
G[x].pb(y), G[y].pb(x);
}
for (int i = 1; i <= n; i++)
mod[i % 3].pb(i);
dfs(1, 0, 0);
sol(col[0].size() < col[1].size(), 1), sol(col[0].size() < col[1].size(), 2);
sol(0, 0), sol(1, 0);
for (int i = 1; i <= n; i++)
printf("%d ", ans[i]);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.