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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02827 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 50005;
const int M = 100005;
int n, m, t, i, x[M], y[M], mapa[N], co[N];
bitset<N> b[N], bb;
string s;
bool cc[N];
void solve() {
if (n == 2) {
printf("-1\n");
return;
}
for (i = 0; i < n; i++) {
mapa[i] = i;
co[i] = 1;
}
for (i = m - 1; i >= 0; i--) {
if (co[mapa[x[i]]] > 1) {
s += 'v';
co[mapa[x[i]]]--;
mapa[x[i]] = mapa[y[i]];
co[mapa[x[i]]]++;
} else {
s += '^';
co[mapa[y[i]]]--;
mapa[y[i]] = mapa[x[i]];
co[mapa[y[i]]]++;
}
}
int ind = -1;
for (i = 1; i < n; i++)
if (mapa[i] != mapa[i - 1])
ind = i;
int a1 = ind - 1;
int a2 = ind;
for (i = 0; i < m; i++) {
if (x[i] == a1 && s[i] == 'v')
a1 = y[i];
else if (y[i] == a1 && s[i] == '^')
a1 = x[i];
if (x[i] == a2 && s[i] == 'v')
a2 = y[i];
else if (y[i] == a2 && s[i] == '^')
a2 = x[i];
}
if (a1 == a2) {
int a = 3;
while (a < 10) {
a++;
a--;
}
}
printf("%s\n", s.c_str());
}
int main() {
scanf("%d %d %d", &n, &m, &t);
s = "";
for (i = 0; i < m; i++) {
scanf("%d %d", &x[i], &y[i]);
x[i]--;
y[i]--;
}
if (t == 2) {
solve();
return 0;
}
for (i = 0; i < n; i++) {
b[i].set(i);
bb.set(i);
}
for (i = m - 1; i >= 0; i--)
b[x[i]] = b[y[i]] = b[x[i]] | b[y[i]];
for (i = 0; i < n; i++)
bb &= b[i];
for (i = 0; i < n; i++)
if (bb[i]) {
cc[i] = 1;
for (i = m - 1; i >= 0; i--) {
if (cc[y[i]])
s += 'v';
else
s += '^';
cc[x[i]] = cc[y[i]] = cc[x[i]] | cc[y[i]];
}
reverse(s.begin(), s.end());
printf("%s\n", s.c_str());
return 0;
}
printf("-1\n");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 50005;
const int M = 100005;
int n, m, t, i, x[M], y[M], mapa[N], co[N];
bitset<N> b[N], bb;
string s;
bool cc[N];
void solve() {
if (n == 2) {
printf("-1\n");
return;
}
for (i = 0; i < n; i++) {
mapa[i] = i;
co[i] = 1;
}
for (i = m - 1; i >= 0; i--) {
if (co[mapa[x[i]]] > 1) {
s += 'v';
co[mapa[x[i]]]--;
mapa[x[i]] = mapa[y[i]];
co[mapa[x[i]]]++;
} else {
s += '^';
co[mapa[y[i]]]--;
mapa[y[i]] = mapa[x[i]];
co[mapa[y[i]]]++;
}
}
reverse(s.begin(), s.end());
printf("%s\n", s.c_str());
}
int main() {
scanf("%d %d %d", &n, &m, &t);
s = "";
for (i = 0; i < m; i++) {
scanf("%d %d", &x[i], &y[i]);
x[i]--;
y[i]--;
}
if (t == 2) {
solve();
return 0;
}
for (i = 0; i < n; i++) {
b[i].set(i);
bb.set(i);
}
for (i = m - 1; i >= 0; i--)
b[x[i]] = b[y[i]] = b[x[i]] | b[y[i]];
for (i = 0; i < n; i++)
bb &= b[i];
for (i = 0; i < n; i++)
if (bb[i]) {
cc[i] = 1;
for (i = m - 1; i >= 0; i--) {
if (cc[y[i]])
s += 'v';
else
s += '^';
cc[x[i]] = cc[y[i]] = cc[x[i]] | cc[y[i]];
}
reverse(s.begin(), s.end());
printf("%s\n", s.c_str());
return 0;
}
printf("-1\n");
return 0;
}
| replace | 37 | 60 | 37 | 38 | TLE | |
p02827 | C++ | Time Limit Exceeded | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifndef print
#define print(...)
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) ((long long)x.size())
#define fr(a, b, c) for (int a = b; a <= c; a++)
#define rep(a, b, c) for (int a = b; a < c; a++)
#define trav(a, x) for (auto &a : x)
#define all(con) con.begin(), con.end()
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
// const int mod=998244353;
const int mod = 1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
oset;
auto clk = clock();
mt19937_64
rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0, lim - 1);
return uid(rang);
}
int powm(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
const int N = 50000;
bitset<N> a[N];
int b[N];
int fr[N];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, m, t;
cin >> n >> m >> t;
if (t == 1) {
std::vector<pii> li;
for (int i = 0; i < m; ++i) {
int u;
cin >> u;
u--;
int v;
cin >> v;
v--;
li.pb({u, v});
}
reverse(all(li));
for (int i = 0; i < n; ++i)
a[i][i] = 1;
for (auto pi : li)
a[pi.fi] |= a[pi.se], a[pi.se] |= a[pi.fi];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (!a[j][i]) {
break;
} else if (a[j][i] && j == n - 1) {
a[0].reset();
a[0][i] = 1;
string s = "";
for (auto pi : li) {
if ((a[0][pi.se] && !a[0][pi.fi])) {
a[0][pi.fi] = 1;
s += 'v';
} else if ((!a[0][pi.se] && a[0][pi.fi])) {
a[0][pi.se] = 1;
s += '^';
} else {
s += '^';
}
}
reverse(all(s));
cout << s;
exit(0);
}
}
}
cout << -1;
} else {
if (n >= 3) {
std::vector<pii> li;
for (int i = 0; i < m; ++i) {
int u;
cin >> u;
u--;
int v;
cin >> v;
v--;
li.pb({u, v});
}
reverse(all(li));
for (int i = 0; i < n; ++i) {
b[i] = i;
fr[i] = 1;
}
string ss = "";
for (auto pi : li) {
if (fr[b[pi.fi]] >= 2) {
fr[b[pi.fi]]--;
b[pi.fi] = b[pi.se];
fr[b[pi.fi]]++;
ss += "v";
} else {
fr[b[pi.se]]--;
b[pi.se] = b[pi.fi];
fr[b[pi.se]]++;
ss += "^";
}
}
reverse(all(ss));
cout << ss << '\n';
} else {
cout << "-1";
}
}
} | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifndef print
#define print(...)
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) ((long long)x.size())
#define fr(a, b, c) for (int a = b; a <= c; a++)
#define rep(a, b, c) for (int a = b; a < c; a++)
#define trav(a, x) for (auto &a : x)
#define all(con) con.begin(), con.end()
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
// const int mod=998244353;
const int mod = 1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
oset;
auto clk = clock();
mt19937_64
rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0, lim - 1);
return uid(rang);
}
int powm(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
const int N = 50000;
bitset<N> a[N];
int b[N];
int fr[N];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, m, t;
cin >> n >> m >> t;
if (t == 1) {
std::vector<pii> li;
for (int i = 0; i < m; ++i) {
int u;
cin >> u;
u--;
int v;
cin >> v;
v--;
li.pb({u, v});
}
reverse(all(li));
for (int i = 0; i < n; ++i)
a[i][i] = 1;
for (auto pi : li)
a[pi.fi] |= a[pi.se], a[pi.se] |= a[pi.fi];
int mi = n + 1;
int in = -1;
for (int k = 0; k < n; ++k) {
if (a[k].count() < mi) {
mi = a[k].count();
in = k;
}
}
for (int i = a[in]._Find_first(); i < n; i = a[in]._Find_next(i)) {
for (int j = 0; j < n; ++j) {
if (!a[j][i]) {
break;
} else if (a[j][i] && j == n - 1) {
a[0].reset();
a[0][i] = 1;
string s = "";
for (auto pi : li) {
if ((a[0][pi.se] && !a[0][pi.fi])) {
a[0][pi.fi] = 1;
s += 'v';
} else if ((!a[0][pi.se] && a[0][pi.fi])) {
a[0][pi.se] = 1;
s += '^';
} else {
s += '^';
}
}
reverse(all(s));
cout << s;
exit(0);
}
}
}
cout << -1;
} else {
if (n >= 3) {
std::vector<pii> li;
for (int i = 0; i < m; ++i) {
int u;
cin >> u;
u--;
int v;
cin >> v;
v--;
li.pb({u, v});
}
reverse(all(li));
for (int i = 0; i < n; ++i) {
b[i] = i;
fr[i] = 1;
}
string ss = "";
for (auto pi : li) {
if (fr[b[pi.fi]] >= 2) {
fr[b[pi.fi]]--;
b[pi.fi] = b[pi.se];
fr[b[pi.fi]]++;
ss += "v";
} else {
fr[b[pi.se]]--;
b[pi.se] = b[pi.fi];
fr[b[pi.se]]++;
ss += "^";
}
}
reverse(all(ss));
cout << ss << '\n';
} else {
cout << "-1";
}
}
} | replace | 80 | 81 | 80 | 89 | TLE | |
p02827 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
void ch(int &x, int &y) {
if (y < x) {
int tmp = y;
y = x;
x = tmp;
}
}
int N, M, T;
vector<int> x, y;
void solve1() {
using bs = bitset<50001>;
vector<bs> dp(N + 1); // dp[i][j] は i から j にゴールできるかどうか
for (int i = 1; i <= N; ++i) {
dp[i][i] = 1;
}
for (int i = M - 1; i >= 0; --i) {
dp[x[i]] |= dp[y[i]];
dp[y[i]] = dp[x[i]];
}
bs flag1;
flag1.set();
for (int i = 1; i < N; ++i) {
flag1 &= dp[i];
}
for (int j = 1; j <= N; ++j) {
if (flag1[j]) {
string s(M, '^');
bs flag;
flag[j] = 1;
for (int i = M - 1; i >= 0; --i) {
if (flag[y[i]] == 1)
s[i] = 'v';
flag[x[i]] = flag[x[i]] || flag[y[i]];
flag[y[i]] = flag[x[i]];
}
assert(flag.count() == N);
cout << s << "\n";
return;
}
}
cout << -1 << "\n";
}
void solve2() {
if (N == 2) {
cout << -1 << "\n";
return;
}
vector<vector<int>> graph(N + 1, vector<int>());
for (int i = 0; i < M; ++i) {
graph[x[i]].push_back(i);
graph[y[i]].push_back(i);
}
int x1 = x[0];
int y1 = y[0] + 1;
if (y1 == N + 1) {
if (x1 == 1)
y1 = 2;
else
y1 = 1;
}
ch(x1, y1);
// 次で衝突する場合は進路転換
for (int i = 0; i < M; ++i) {
auto iter1 = upper_bound(graph[x1].begin(), graph[x1].end(), i);
auto iter2 = upper_bound(graph[y1].begin(), graph[y1].end(), i);
if (iter1 != graph[x1].end() && iter2 != graph[y1].end() &&
(*iter1 == *iter2)) {
if (x[i] == x1) {
cout << "v";
x1 = y[i];
} else if (y[i] == y1) {
cout << "^";
y1 = x[i];
} else if (y[i] == x1) {
cout << "^";
x1 = x[i];
} else if (x[i] == y1) {
cout << "v";
y1 = y[i];
}
} else {
if (y[i] == y1 || y[i] == x1) {
cout << "v";
} else {
cout << "^";
}
}
ch(x1, y1);
}
}
int main() {
cin >> N >> M >> T;
x.resize(M);
y.resize(M);
for (int i = 0; i < M; ++i) {
cin >> x[i] >> y[i];
}
if (T == 1)
solve1();
else
solve2();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
void ch(int &x, int &y) {
if (y < x) {
int tmp = y;
y = x;
x = tmp;
}
}
int N, M, T;
vector<int> x, y;
void solve1() {
using bs = bitset<50001>;
vector<bs> dp(N + 1); // dp[i][j] は i から j にゴールできるかどうか
for (int i = 1; i <= N; ++i) {
dp[i][i] = 1;
}
for (int i = M - 1; i >= 0; --i) {
dp[x[i]] |= dp[y[i]];
dp[y[i]] = dp[x[i]];
}
bs flag1;
flag1.set();
for (int i = 1; i <= N; ++i) {
flag1 &= dp[i];
}
for (int j = 1; j <= N; ++j) {
if (flag1[j]) {
string s(M, '^');
bs flag;
flag[j] = 1;
for (int i = M - 1; i >= 0; --i) {
if (flag[y[i]] == 1)
s[i] = 'v';
flag[x[i]] = flag[x[i]] || flag[y[i]];
flag[y[i]] = flag[x[i]];
}
assert(flag.count() == N);
cout << s << "\n";
return;
}
}
cout << -1 << "\n";
}
void solve2() {
if (N == 2) {
cout << -1 << "\n";
return;
}
vector<vector<int>> graph(N + 1, vector<int>());
for (int i = 0; i < M; ++i) {
graph[x[i]].push_back(i);
graph[y[i]].push_back(i);
}
int x1 = x[0];
int y1 = y[0] + 1;
if (y1 == N + 1) {
if (x1 == 1)
y1 = 2;
else
y1 = 1;
}
ch(x1, y1);
// 次で衝突する場合は進路転換
for (int i = 0; i < M; ++i) {
auto iter1 = upper_bound(graph[x1].begin(), graph[x1].end(), i);
auto iter2 = upper_bound(graph[y1].begin(), graph[y1].end(), i);
if (iter1 != graph[x1].end() && iter2 != graph[y1].end() &&
(*iter1 == *iter2)) {
if (x[i] == x1) {
cout << "v";
x1 = y[i];
} else if (y[i] == y1) {
cout << "^";
y1 = x[i];
} else if (y[i] == x1) {
cout << "^";
x1 = x[i];
} else if (x[i] == y1) {
cout << "v";
y1 = y[i];
}
} else {
if (y[i] == y1 || y[i] == x1) {
cout << "v";
} else {
cout << "^";
}
}
ch(x1, y1);
}
}
int main() {
cin >> N >> M >> T;
x.resize(M);
y.resize(M);
for (int i = 0; i < M; ++i) {
cin >> x[i] >> y[i];
}
if (T == 1)
solve1();
else
solve2();
return 0;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p02827 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAXN = int(5e4) + 2;
const int MAXM = int(1.1e5);
int N, M;
int T;
pair<int, int> X[MAXM];
bool ansUp[MAXM];
using bs = bitset<MAXN>;
namespace uniforming {
bs canReach[MAXN];
bool vis[MAXN];
bool findUniforming() {
for (int t = 0; t < N; t++)
canReach[t][t] = true;
for (int i = M - 1; i >= 0; i--) {
int x = X[i].first, y = X[i].second;
canReach[x] |= canReach[y];
canReach[y] = canReach[x];
}
bs isGood;
for (int t = 0; t < N; t++) {
isGood[t] = true;
}
for (int s = 0; s < N; s++) {
isGood &= canReach[s];
}
for (int t = 0; t < N; t++) {
if (isGood[t]) {
vis[t] = true;
for (int i = M - 1; i >= 0; i--) {
int x = X[i].first, y = X[i].second;
if (vis[x] || vis[y]) {
if (!vis[y]) {
ansUp[i] = true;
vis[y] = true;
}
if (!vis[x]) {
ansUp[i] = false;
vis[x] = true;
}
assert(vis[x] && vis[y]);
}
}
for (int s = 0; s < N; s++)
assert(vis[s]);
return true;
}
}
return false;
}
} // namespace uniforming
namespace nonUniforming {
bool findNonUniforming() { assert(false); }
} // namespace nonUniforming
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N >> M >> T;
for (int i = 0; i < M; i++) {
cin >> X[i].first >> X[i].second;
X[i].first--, X[i].second--;
}
bool found;
if (T == 1) {
found = uniforming::findUniforming();
} else if (T == 2) {
found = nonUniforming::findNonUniforming();
} else
assert(false);
if (found) {
for (int i = 0; i < M; i++) {
cout << "v^"[ansUp[i]];
}
cout << '\n';
} else {
cout << -1 << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int MAXN = int(5e4) + 2;
const int MAXM = int(1.1e5);
int N, M;
int T;
pair<int, int> X[MAXM];
bool ansUp[MAXM];
using bs = bitset<MAXN>;
namespace uniforming {
bs canReach[MAXN];
bool vis[MAXN];
bool findUniforming() {
for (int t = 0; t < N; t++)
canReach[t][t] = true;
for (int i = M - 1; i >= 0; i--) {
int x = X[i].first, y = X[i].second;
canReach[x] |= canReach[y];
canReach[y] = canReach[x];
}
bs isGood;
for (int t = 0; t < N; t++) {
isGood[t] = true;
}
for (int s = 0; s < N; s++) {
isGood &= canReach[s];
}
for (int t = 0; t < N; t++) {
if (isGood[t]) {
vis[t] = true;
for (int i = M - 1; i >= 0; i--) {
int x = X[i].first, y = X[i].second;
if (vis[x] || vis[y]) {
if (!vis[y]) {
ansUp[i] = true;
vis[y] = true;
}
if (!vis[x]) {
ansUp[i] = false;
vis[x] = true;
}
assert(vis[x] && vis[y]);
}
}
for (int s = 0; s < N; s++)
assert(vis[s]);
return true;
}
}
return false;
}
} // namespace uniforming
namespace nonUniforming {
bool findNonUniforming() {
if (N == 2 && M >= 1) {
return false;
}
int badState = 0;
for (int i = M - 1; i >= 0; i--) {
int x = X[i].first, y = X[i].second;
if (y >= 3) {
ansUp[i] = true;
continue;
}
if (x == 0 && y == 1) {
if (badState == 1)
ansUp[i] = false;
else if (badState == 2)
ansUp[i] = true;
badState = 0;
} else if (x == 0 && y == 2) {
if (badState == 0)
ansUp[i] = false;
else if (badState == 2)
ansUp[i] = true;
badState = 1;
} else if (x == 1 && y == 2) {
if (badState == 0)
ansUp[i] = false;
else if (badState == 1)
ansUp[i] = true;
badState = 2;
} else
assert(false);
}
return true;
}
} // namespace nonUniforming
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N >> M >> T;
for (int i = 0; i < M; i++) {
cin >> X[i].first >> X[i].second;
X[i].first--, X[i].second--;
}
bool found;
if (T == 1) {
found = uniforming::findUniforming();
} else if (T == 2) {
found = nonUniforming::findNonUniforming();
} else
assert(false);
if (found) {
for (int i = 0; i < M; i++) {
cout << "v^"[ansUp[i]];
}
cout << '\n';
} else {
cout << -1 << '\n';
}
return 0;
}
| replace | 61 | 62 | 61 | 95 | -11 | |
p02827 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int N, M, T, s[100003], t[100003], dis[100003];
bitset<50003> now[50003];
namespace sub1 {
void work() {
for (int i = 1; i <= N; ++i)
now[i].set(i);
for (int i = 1; i <= M; ++i)
now[s[i]] = now[t[i]] = now[s[i]] | now[t[i]];
for (int i = 1; i <= N; ++i)
if (now[i].count() == N) {
dis[i] = 100000;
for (int j = M; j; --j)
if (dis[s[j]] && !dis[t[j]])
dis[t[j]] = j;
else if (dis[t[j]] && !dis[s[j]])
dis[s[j]] = j;
for (int j = 1; j <= M; ++j)
putchar(dis[s[j]] < dis[t[j]] ? 'v' : '^');
return;
}
puts("-1");
}
} // namespace sub1
int pot[50003], f[50003];
char str[50003];
namespace sub2 {
void work() {
if (N == 2) {
puts("-1");
return;
}
for (int i = 1; i <= N; ++i)
pot[f[i] = i] = 1;
for (int j = M; j; --j)
if (pot[f[s[j]]] < pot[f[t[j]]]) {
str[j] = '^';
--pot[f[t[j]]];
++pot[f[t[j]] = f[s[j]]];
} else {
str[j] = 'v';
--pot[f[s[j]]];
++pot[f[s[j]] = f[t[j]]];
}
printf("%s\n", str + 1);
}
} // namespace sub2
int main() {
ios::sync_with_stdio(0);
cin >> N >> M >> T;
for (int i = 1; i <= M; ++i)
cin >> s[i] >> t[i];
if (T == 1)
sub1::work();
else
sub2::work();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int N, M, T, s[100003], t[100003], dis[100003];
bitset<50003> now[50003];
namespace sub1 {
void work() {
for (int i = 1; i <= N; ++i)
now[i].set(i);
for (int i = 1; i <= M; ++i)
now[s[i]] = now[t[i]] = now[s[i]] | now[t[i]];
for (int i = 1; i <= N; ++i)
if (now[i].count() == N) {
dis[i] = 100000;
for (int j = M; j; --j)
if (dis[s[j]] && !dis[t[j]])
dis[t[j]] = j;
else if (dis[t[j]] && !dis[s[j]])
dis[s[j]] = j;
for (int j = 1; j <= M; ++j)
putchar(dis[s[j]] < dis[t[j]] ? 'v' : '^');
return;
}
puts("-1");
}
} // namespace sub1
int pot[50003], f[50003];
char str[100003];
namespace sub2 {
void work() {
if (N == 2) {
puts("-1");
return;
}
for (int i = 1; i <= N; ++i)
pot[f[i] = i] = 1;
for (int j = M; j; --j)
if (pot[f[s[j]]] < pot[f[t[j]]]) {
str[j] = '^';
--pot[f[t[j]]];
++pot[f[t[j]] = f[s[j]]];
} else {
str[j] = 'v';
--pot[f[s[j]]];
++pot[f[s[j]] = f[t[j]]];
}
printf("%s\n", str + 1);
}
} // namespace sub2
int main() {
ios::sync_with_stdio(0);
cin >> N >> M >> T;
for (int i = 1; i <= M; ++i)
cin >> s[i] >> t[i];
if (T == 1)
sub1::work();
else
sub2::work();
return 0;
}
| replace | 29 | 30 | 29 | 30 | -11 | |
p02827 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>; template<typename T, typename L> using
gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>,
rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define IREP(i, n) IFOR(i, 0, n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL << (n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) \
{ \
cout << #v << "=" << endl; \
REP(i_debug, v.size()) { cout << v[i_debug] << ","; } \
cout << endl; \
}
#define mdebug(m) \
{ \
cout << #m << "=" << endl; \
REP(i_debug, m.size()) { \
REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; } \
cout << endl; \
} \
}
#define Return(ans) \
{ \
cout << (ans) << endl; \
return 0; \
}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i];
if (i != v.size() - 1)
cout << endl;
};
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
cout << '(' << p.first << ',' << p.second << ')';
return os;
}
template <typename T> void Out(T x) { cout << x << endl; }
template <typename T1, typename T2> void Ans(bool f, T1 y, T2 n) {
if (f)
Out(y);
else
Out(n);
}
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
// int dx[4] = {1,0,-1,0};
// int dy[4] = {0,1,0,-1};
// char d[4] = {'D','R','U','L'};
const int mod = 1000000007;
// const int mod = 998244353;
// #define Add(x, y) x = (x + (y)) % mod
// #define Mult(x, y) x = (x * (y)) % mod
using bset = bitset<50000>;
signed main() {
int N, M, T;
cin >> N >> M >> T;
vec x(M), y(M);
REP(i, M) {
cin >> x[i] >> y[i];
x[i]--;
y[i]--;
}
if (T == 1) {
vector<bset> b(N);
REP(i, N) b[i][i] = 1;
REP(i, M) {
b[x[i]] |= b[y[i]];
b[y[i]] = b[x[i]];
}
int f = -1;
REP(i, N) if (b[i].count() == N) f = i;
if (f == -1)
Out(-1);
else {
// debug(f);
string ans(M, '.');
bset s;
s[f] = 1;
IREP(i, M) {
if (s[y[i]])
ans[i] = 'v';
else
ans[i] = '^';
if (s[x[i]])
s[y[i]] = 1;
if (s[y[i]])
s[x[i]] = 1;
}
Out(ans);
}
} else {
assert(false);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>; template<typename T, typename L> using
gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>,
rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define IREP(i, n) IFOR(i, 0, n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL << (n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) \
{ \
cout << #v << "=" << endl; \
REP(i_debug, v.size()) { cout << v[i_debug] << ","; } \
cout << endl; \
}
#define mdebug(m) \
{ \
cout << #m << "=" << endl; \
REP(i_debug, m.size()) { \
REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; } \
cout << endl; \
} \
}
#define Return(ans) \
{ \
cout << (ans) << endl; \
return 0; \
}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i];
if (i != v.size() - 1)
cout << endl;
};
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
cout << '(' << p.first << ',' << p.second << ')';
return os;
}
template <typename T> void Out(T x) { cout << x << endl; }
template <typename T1, typename T2> void Ans(bool f, T1 y, T2 n) {
if (f)
Out(y);
else
Out(n);
}
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
// int dx[4] = {1,0,-1,0};
// int dy[4] = {0,1,0,-1};
// char d[4] = {'D','R','U','L'};
const int mod = 1000000007;
// const int mod = 998244353;
// #define Add(x, y) x = (x + (y)) % mod
// #define Mult(x, y) x = (x * (y)) % mod
using bset = bitset<50000>;
signed main() {
int N, M, T;
cin >> N >> M >> T;
vec x(M), y(M);
REP(i, M) {
cin >> x[i] >> y[i];
x[i]--;
y[i]--;
}
if (T == 1) {
vector<bset> b(N);
REP(i, N) b[i][i] = 1;
REP(i, M) {
b[x[i]] |= b[y[i]];
b[y[i]] = b[x[i]];
}
int f = -1;
REP(i, N) if (b[i].count() == N) f = i;
if (f == -1)
Out(-1);
else {
// debug(f);
string ans(M, '.');
bset s;
s[f] = 1;
IREP(i, M) {
if (s[y[i]])
ans[i] = 'v';
else
ans[i] = '^';
if (s[x[i]])
s[y[i]] = 1;
if (s[y[i]])
s[x[i]] = 1;
}
Out(ans);
}
} else {
if (N == 2) {
Out(-1);
return 0;
}
string ans(M, '.');
REP(i, M) {
if (y[i] <= 2) {
int i0 = -1;
FOR(j, i + 1, M) if (y[j] <= 2) {
i0 = j;
break;
}
if (i0 == -1)
ans[i] = '^';
else {
if (y[i] != x[i0] && y[i] != y[i0])
ans[i] = 'v';
else
ans[i] = '^';
}
} else
ans[i] = '^';
}
Out(ans);
}
return 0;
}
| replace | 145 | 146 | 145 | 169 | 0 | |
p02827 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef bool boolean;
#define pii pair<int, int>
const int N = 5e4 + 5;
const int M = 1e5 + 5;
int n, m, type;
char ans[M];
int us[M], vs[M];
namespace subtask1 {
bitset<N> f[M];
boolean vis[M];
int h[N], A[M], B[M];
void F(int p, int x) {
if (!p || vis[p]) {
return;
}
vis[p] = true;
if (x == us[p]) {
F(A[p], x);
F(B[p], vs[p]);
} else {
ans[p] = 'v';
F(B[p], x);
F(A[p], us[p]);
}
}
void solve() {
for (int i = 1, u, v; i <= m; i++) {
u = us[i], v = vs[i];
if (!h[u]) {
f[i].set(u);
} else {
f[i] = f[h[u]];
}
swap(u, v);
if (!h[u]) {
f[i].set(u);
} else {
f[i] |= f[h[u]];
}
swap(u, v);
A[i] = h[u], B[i] = h[v];
h[u] = h[v] = i;
}
for (int i = 1; i <= m; i++)
ans[i] = '^';
for (int i = 1; i <= m; i++) {
if ((signed)f[i].count() == n) {
F(i, us[i]);
puts(ans + 1);
return;
}
}
puts("-1");
}
} // namespace subtask1
namespace subtask2 {
const int C = 320;
set<pii> S;
int h[C];
int nxt[M][C];
bitset<C> vis[M][2];
boolean dfs(int p, int x, int y) {
if (x == y) {
return false;
}
if (p == m + 1) {
return true;
}
int sx = -1, sy = -1;
if (x == us[p] || y == us[p]) {
sx = 0, sy = x ^ y ^ us[p];
} else {
sx = 1, sy = x ^ y ^ vs[p];
}
if (vis[p][sx].test(sy))
return false;
vis[p][sx].set(sy);
// down
int nx = (x == us[p]) ? vs[p] : x;
int ny = (y == us[p]) ? vs[p] : y;
if (dfs(min(nxt[p][nx], nxt[p][ny]), nx, ny)) {
ans[p] = 'v';
return true;
}
nx = (x == vs[p]) ? us[p] : x;
ny = (y == vs[p]) ? us[p] : y;
if (dfs(min(nxt[p][nx], nxt[p][ny]), nx, ny)) {
ans[p] = '^';
return true;
}
return false;
}
void solve() {
for (int i = 1; i <= m; i++) {
S.insert(pii(us[i], vs[i]));
}
if ((signed)S.size() < 1ll * n * (n - 1) / 2) {
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (!S.count(pii(i, j))) {
for (int k = 1; k <= m; k++) {
if (us[k] == i || us[k] == j) {
ans[k] = '^';
} else {
ans[k] = 'v';
}
}
puts(ans + 1);
return;
}
}
}
assert(false);
return;
}
assert(n < C);
for (int i = 1; i <= m; i++)
ans[i] = 'v';
for (int i = 1; i <= n; i++)
h[i] = m + 1;
for (int i = m; i; i--) {
memcpy(nxt[i], h, sizeof(h));
h[us[i]] = h[vs[i]] = i;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (dfs(min(h[i], h[j]), i, j)) {
puts(ans + 1);
return;
}
}
}
puts("-1");
}
} // namespace subtask2
int main() {
scanf("%d%d%d", &n, &m, &type);
for (int i = 1; i <= m; i++) {
scanf("%d%d", us + i, vs + i);
;
}
if (type == 1) {
subtask1::solve();
} else {
subtask2::solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef bool boolean;
#define pii pair<int, int>
const int N = 5e4 + 5;
const int M = 1e5 + 5;
int n, m, type;
char ans[M];
int us[M], vs[M];
namespace subtask1 {
bitset<N> f[M];
boolean vis[M];
int h[N], A[M], B[M];
void F(int p, int x) {
if (!p || vis[p]) {
return;
}
vis[p] = true;
if (x == us[p]) {
F(A[p], x);
F(B[p], vs[p]);
} else {
ans[p] = 'v';
F(B[p], x);
F(A[p], us[p]);
}
}
void solve() {
for (int i = 1, u, v; i <= m; i++) {
u = us[i], v = vs[i];
if (!h[u]) {
f[i].set(u);
} else {
f[i] = f[h[u]];
}
swap(u, v);
if (!h[u]) {
f[i].set(u);
} else {
f[i] |= f[h[u]];
}
swap(u, v);
A[i] = h[u], B[i] = h[v];
h[u] = h[v] = i;
}
for (int i = 1; i <= m; i++)
ans[i] = '^';
for (int i = 1; i <= m; i++) {
if ((signed)f[i].count() == n) {
F(i, us[i]);
puts(ans + 1);
return;
}
}
puts("-1");
}
} // namespace subtask1
namespace subtask2 {
const int C = 451;
set<pii> S;
int h[C];
int nxt[M][C];
bitset<C> vis[M][2];
boolean dfs(int p, int x, int y) {
if (x == y) {
return false;
}
if (p == m + 1) {
return true;
}
int sx = -1, sy = -1;
if (x == us[p] || y == us[p]) {
sx = 0, sy = x ^ y ^ us[p];
} else {
sx = 1, sy = x ^ y ^ vs[p];
}
if (vis[p][sx].test(sy))
return false;
vis[p][sx].set(sy);
// down
int nx = (x == us[p]) ? vs[p] : x;
int ny = (y == us[p]) ? vs[p] : y;
if (dfs(min(nxt[p][nx], nxt[p][ny]), nx, ny)) {
ans[p] = 'v';
return true;
}
nx = (x == vs[p]) ? us[p] : x;
ny = (y == vs[p]) ? us[p] : y;
if (dfs(min(nxt[p][nx], nxt[p][ny]), nx, ny)) {
ans[p] = '^';
return true;
}
return false;
}
void solve() {
for (int i = 1; i <= m; i++) {
S.insert(pii(us[i], vs[i]));
}
if ((signed)S.size() < 1ll * n * (n - 1) / 2) {
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (!S.count(pii(i, j))) {
for (int k = 1; k <= m; k++) {
if (us[k] == i || us[k] == j) {
ans[k] = '^';
} else {
ans[k] = 'v';
}
}
puts(ans + 1);
return;
}
}
}
assert(false);
return;
}
assert(n < C);
for (int i = 1; i <= m; i++)
ans[i] = 'v';
for (int i = 1; i <= n; i++)
h[i] = m + 1;
for (int i = m; i; i--) {
memcpy(nxt[i], h, sizeof(h));
h[us[i]] = h[vs[i]] = i;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (dfs(min(h[i], h[j]), i, j)) {
puts(ans + 1);
return;
}
}
}
puts("-1");
}
} // namespace subtask2
int main() {
scanf("%d%d%d", &n, &m, &type);
for (int i = 1; i <= m; i++) {
scanf("%d%d", us + i, vs + i);
;
}
if (type == 1) {
subtask1::solve();
} else {
subtask2::solve();
}
return 0;
}
| replace | 68 | 69 | 68 | 69 | -11 | |
p02827 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
int n, m, t;
int x[100005], y[100005];
int ans[100005];
int val[100005];
map<int, int> M;
bitset<50005> B[50005];
void solve_hard() {
repn(i, n) B[i][i] = 1;
rep(j, m) {
B[x[j]] |= B[y[j]];
B[y[j]] |= B[x[j]];
}
for (int i = 2; i <= n; i++)
B[1] &= B[i];
int v = -1;
rep(i, 50005) {
if (B[1][i] == 1) {
v = i;
break;
}
}
if (v == -1) {
puts("-1");
return;
}
string ans = "";
repn(i, n) { val[i] = i; }
for (int j = m - 1; j >= 0; j--) {
int f1 = val[x[j]] == v;
int f2 = val[y[j]] == v;
if (f1 && f2) {
val[y[j]] = val[x[j]];
ans.pb('^');
} else if (!f1 && !f2) {
val[y[j]] = val[x[j]];
ans.pb('^');
} else if (f1 && !f2) {
val[y[j]] = val[x[j]];
ans.pb('^');
} else {
val[x[j]] = val[y[j]];
ans.pb('v');
}
}
repn(i, n) assert(val[i] == v);
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
int main() {
scanf("%d%d%d", &n, &m, &t);
rep(i, m) scanf("%d%d", &x[i], &y[i]);
if (t == 1) {
solve_hard();
return 0;
}
repn(i, n) {
val[i] = i;
M[i]++;
}
for (int i = m - 1; i >= 0; i--) {
int a = val[x[i]];
int b = val[y[i]];
if (M[a] < M[b]) {
ans[i] = 1;
M[a]++;
M[b]--;
val[y[i]] = a;
} else {
ans[i] = 0;
M[a]--;
M[b]++;
val[x[i]] = b;
}
}
for (auto a : M) {
if (a.sc == n) {
puts("-1");
return 0;
}
}
rep(i, m) printf(!ans[i] ? "v" : "^");
puts("");
// repn(i,n) cout << val[i] << endl;
}
| #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
int n, m, t;
int x[100005], y[100005];
int ans[100005];
int val[100005];
map<int, int> M;
bitset<50005> B[50005];
void solve_hard() {
repn(i, n) B[i][i] = 1;
for (int j = m - 1; j >= 0; j--) {
B[x[j]] |= B[y[j]];
B[y[j]] |= B[x[j]];
}
for (int i = 2; i <= n; i++)
B[1] &= B[i];
int v = -1;
rep(i, 50005) {
if (B[1][i] == 1) {
v = i;
break;
}
}
if (v == -1) {
puts("-1");
return;
}
string ans = "";
repn(i, n) { val[i] = i; }
for (int j = m - 1; j >= 0; j--) {
int f1 = val[x[j]] == v;
int f2 = val[y[j]] == v;
if (f1 && f2) {
val[y[j]] = val[x[j]];
ans.pb('^');
} else if (!f1 && !f2) {
val[y[j]] = val[x[j]];
ans.pb('^');
} else if (f1 && !f2) {
val[y[j]] = val[x[j]];
ans.pb('^');
} else {
val[x[j]] = val[y[j]];
ans.pb('v');
}
}
repn(i, n) assert(val[i] == v);
reverse(ans.begin(), ans.end());
cout << ans << endl;
}
int main() {
scanf("%d%d%d", &n, &m, &t);
rep(i, m) scanf("%d%d", &x[i], &y[i]);
if (t == 1) {
solve_hard();
return 0;
}
repn(i, n) {
val[i] = i;
M[i]++;
}
for (int i = m - 1; i >= 0; i--) {
int a = val[x[i]];
int b = val[y[i]];
if (M[a] < M[b]) {
ans[i] = 1;
M[a]++;
M[b]--;
val[y[i]] = a;
} else {
ans[i] = 0;
M[a]--;
M[b]++;
val[x[i]] = b;
}
}
for (auto a : M) {
if (a.sc == n) {
puts("-1");
return 0;
}
}
rep(i, m) printf(!ans[i] ? "v" : "^");
puts("");
// repn(i,n) cout << val[i] << endl;
}
| replace | 35 | 36 | 35 | 36 | -11 | |
p02827 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rep1(i, n) for (int i = 1; i <= int(n); i++)
#define per(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define per1(i, n) for (int i = int(n); i > 0; i--)
#define all(c) c.begin(), c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
template <class T, class U> void chmax(T &x, U y) {
if (x < y)
x = y;
}
template <class T, class U> void chmin(T &x, U y) {
if (y < x)
x = y;
}
template <class T> void mkuni(V<T> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
template <class S, class T>
ostream &operator<<(ostream &o, const pair<S, T> &p) {
return o << "(" << p.fs << "," << p.sc << ")";
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &vc) {
o << "{";
for (const T &v : vc)
o << v << ",";
o << "}";
return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
#ifdef LOCAL
#define show(x) \
cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream &os) { os << endl; }
template <class T, class... Args>
void dmpr(ostream &os, const T &t, const Args &...args) {
os << t << " ~ ";
dmpr(os, args...);
}
#define shows(...) \
cerr << "LINE" << __LINE__ << " : "; \
dmpr(cerr, ##__VA_ARGS__)
#define dump(x) \
cerr << "LINE" << __LINE__ << " : " << #x << " = {"; \
for (auto v : x) \
cerr << v << ","; \
cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif
int main() {
cin.tie(0);
ios::sync_with_stdio(false); // DON'T USE scanf/printf/puts !!
cout << fixed << setprecision(20);
int N, M, T;
cin >> N >> M >> T;
using P = pair<int, int>;
V<P> es(M);
rep(i, M) {
int x, y;
cin >> x >> y;
x--, y--;
es[i] = P(x, y);
}
if (T == 1) {
using BS = bitset<50000>;
V<BS> b(N);
rep(i, N) b[i][i] = true;
per(i, M) {
show(b);
int x = es[i].fs, y = es[i].sc;
b[x] |= b[y];
b[y] |= b[x];
}
rep(tar, N) {
{
bool ok = true;
rep(i, N) if (!b[i][tar]) ok = false;
if (!ok)
continue;
}
string ans(M, '.');
V<bool> is(N);
is[tar] = true;
per(i, M) {
int x = es[i].fs, y = es[i].sc;
if (is[x]) {
ans[i] = '^';
} else {
ans[i] = 'v';
}
if (is[x] || is[y])
is[x] = is[y] = true;
}
show(b);
show(tar);
show(is);
assert(is == V<bool>(N, true));
cout << ans << endl;
return 0;
}
cout << -1 << endl;
return 0;
} else {
if (N == 2) {
cout << -1 << endl;
return 0;
}
VV<bool> dp(M + 1, V<bool>(8));
VV<int> from(M + 1, V<int>(8, -1));
VV<char> which(M + 1, V<char>(8, '?'));
dp[0][7] = true;
auto Set = [&](int i, int s, int ns, char c) {
if (dp[i + 1][ns])
return;
dp[i + 1][ns] = true;
from[i + 1][ns] = s;
which[i + 1][ns] = c;
};
rep(i, M) {
int x = es[i].fs, y = es[i].sc;
rep(s, 8) if (dp[i][s]) {
{ // up
int ns = s;
if (y <= 2) {
if (s & 1 << y) {
ns ^= 1 << y;
ns |= 1 << x;
}
}
Set(i, s, ns, '^');
}
{ // down
int ns = s;
if (y <= 2) {
if (s & 1 << x) {
ns ^= 1 << x;
ns |= 1 << y;
}
}
Set(i, s, ns, 'v');
}
}
}
rep(s, 8) if (__builtin_popcount(s) >= 2 && dp[M][s]) {
string ans(M, '.');
for (int i = M; i > 0; i--) {
ans[i - 1] = which[i][s];
s = from[i][s];
}
cout << ans << endl;
return 0;
}
assert(false);
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rep1(i, n) for (int i = 1; i <= int(n); i++)
#define per(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define per1(i, n) for (int i = int(n); i > 0; i--)
#define all(c) c.begin(), c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
template <class T, class U> void chmax(T &x, U y) {
if (x < y)
x = y;
}
template <class T, class U> void chmin(T &x, U y) {
if (y < x)
x = y;
}
template <class T> void mkuni(V<T> &v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
template <class S, class T>
ostream &operator<<(ostream &o, const pair<S, T> &p) {
return o << "(" << p.fs << "," << p.sc << ")";
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &vc) {
o << "{";
for (const T &v : vc)
o << v << ",";
o << "}";
return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
#ifdef LOCAL
#define show(x) \
cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream &os) { os << endl; }
template <class T, class... Args>
void dmpr(ostream &os, const T &t, const Args &...args) {
os << t << " ~ ";
dmpr(os, args...);
}
#define shows(...) \
cerr << "LINE" << __LINE__ << " : "; \
dmpr(cerr, ##__VA_ARGS__)
#define dump(x) \
cerr << "LINE" << __LINE__ << " : " << #x << " = {"; \
for (auto v : x) \
cerr << v << ","; \
cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif
int main() {
cin.tie(0);
ios::sync_with_stdio(false); // DON'T USE scanf/printf/puts !!
cout << fixed << setprecision(20);
int N, M, T;
cin >> N >> M >> T;
using P = pair<int, int>;
V<P> es(M);
rep(i, M) {
int x, y;
cin >> x >> y;
x--, y--;
es[i] = P(x, y);
}
if (T == 1) {
using BS = bitset<50000>;
V<BS> b(N);
rep(i, N) b[i][i] = true;
per(i, M) {
show(b);
int x = es[i].fs, y = es[i].sc;
b[x] |= b[y];
b[y] |= b[x];
}
rep1(i, N - 1) b[0] &= b[i];
rep(tar, N) if (b[0][tar]) {
string ans(M, '.');
V<bool> is(N);
is[tar] = true;
per(i, M) {
int x = es[i].fs, y = es[i].sc;
if (is[x]) {
ans[i] = '^';
} else {
ans[i] = 'v';
}
if (is[x] || is[y])
is[x] = is[y] = true;
}
show(b);
show(tar);
show(is);
assert(is == V<bool>(N, true));
cout << ans << endl;
return 0;
}
cout << -1 << endl;
return 0;
} else {
if (N == 2) {
cout << -1 << endl;
return 0;
}
VV<bool> dp(M + 1, V<bool>(8));
VV<int> from(M + 1, V<int>(8, -1));
VV<char> which(M + 1, V<char>(8, '?'));
dp[0][7] = true;
auto Set = [&](int i, int s, int ns, char c) {
if (dp[i + 1][ns])
return;
dp[i + 1][ns] = true;
from[i + 1][ns] = s;
which[i + 1][ns] = c;
};
rep(i, M) {
int x = es[i].fs, y = es[i].sc;
rep(s, 8) if (dp[i][s]) {
{ // up
int ns = s;
if (y <= 2) {
if (s & 1 << y) {
ns ^= 1 << y;
ns |= 1 << x;
}
}
Set(i, s, ns, '^');
}
{ // down
int ns = s;
if (y <= 2) {
if (s & 1 << x) {
ns ^= 1 << x;
ns |= 1 << y;
}
}
Set(i, s, ns, 'v');
}
}
}
rep(s, 8) if (__builtin_popcount(s) >= 2 && dp[M][s]) {
string ans(M, '.');
for (int i = M; i > 0; i--) {
ans[i - 1] = which[i][s];
s = from[i][s];
}
cout << ans << endl;
return 0;
}
assert(false);
}
}
| replace | 88 | 95 | 88 | 90 | TLE | |
p02827 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m, t;
cin >> n >> m >> t;
vector<int> X(m), Y(m);
for (int i = 0; i < m; i++) {
cin >> X[i] >> Y[i];
X[i]--;
Y[i]--;
}
if (t == 1) {
const int N = 50008;
vector<bitset<N>> g(n);
for (int i = 0; i < n; i++) {
g[i][i] = 1;
}
for (int _ = m - 1; _ >= 0; _--) {
int x = X[_], y = Y[_];
g[x] = (g[y] |= g[x]);
}
bitset<N> all_reach = g[0];
for (int i = 1; i < n; i++) {
all_reach &= g[i];
}
int w = all_reach._Find_first();
if (w < n) {
string s(m, '^');
bitset<N> trk;
trk[w] = 1;
for (int i = m - 1; i >= 0; i--) {
int x = X[i], y = Y[i];
if (trk[x] && !trk[y]) {
s[i] = '^';
trk[y] = 1;
} else if (!trk[x] && trk[y]) {
s[i] = 'v';
trk[x] = 1;
}
}
cout << s;
} else {
cout << -1;
return;
}
} else {
if (n == 2) {
cout << -1;
return;
}
vector<int> ids;
for (int i = 0; i < m; i++) {
if (Y[i] < 3)
ids.push_back(i);
}
string s(n, '^');
for (int _ = ids.size() - 2; _ >= 0; _--) {
int crt = ids[_], nxt = ids[_ + 1];
int x = X[crt], y = Y[crt];
int u = X[nxt], v = Y[nxt];
if (x == u && y == v)
s[crt] = s[nxt];
else {
int k = 3 - u - v;
if (x == k)
s[crt] = '^';
else
assert(y == k), s[crt] = 'v';
}
}
cout << s;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m, t;
cin >> n >> m >> t;
vector<int> X(m), Y(m);
for (int i = 0; i < m; i++) {
cin >> X[i] >> Y[i];
X[i]--;
Y[i]--;
}
if (t == 1) {
const int N = 50008;
vector<bitset<N>> g(n);
for (int i = 0; i < n; i++) {
g[i][i] = 1;
}
for (int _ = m - 1; _ >= 0; _--) {
int x = X[_], y = Y[_];
g[x] = (g[y] |= g[x]);
}
bitset<N> all_reach = g[0];
for (int i = 1; i < n; i++) {
all_reach &= g[i];
}
int w = all_reach._Find_first();
if (w < n) {
string s(m, '^');
bitset<N> trk;
trk[w] = 1;
for (int i = m - 1; i >= 0; i--) {
int x = X[i], y = Y[i];
if (trk[x] && !trk[y]) {
s[i] = '^';
trk[y] = 1;
} else if (!trk[x] && trk[y]) {
s[i] = 'v';
trk[x] = 1;
}
}
cout << s;
} else {
cout << -1;
return;
}
} else {
if (n == 2) {
cout << -1;
return;
}
vector<int> ids;
for (int i = 0; i < m; i++) {
if (Y[i] < 3)
ids.push_back(i);
}
string s(m, '^');
for (int _ = ids.size() - 2; _ >= 0; _--) {
int crt = ids[_], nxt = ids[_ + 1];
int x = X[crt], y = Y[crt];
int u = X[nxt], v = Y[nxt];
if (x == u && y == v)
s[crt] = s[nxt];
else {
int k = 3 - u - v;
if (x == k)
s[crt] = '^';
else
assert(y == k), s[crt] = 'v';
}
}
cout << s;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
cout << endl;
}
| replace | 57 | 58 | 57 | 58 | 0 | |
p02827 | C++ | Runtime Error | // https://atcoder.jp/contests/agc041/tasks/agc041_e
#define DECIMAL_DIGITS 10
#define STATIC_MOD 1e9 + 7
#ifdef BTK
/*<head>*/
#include "Template.hpp"
#include "graph/Dinic.hpp"
/*</head>*/
#else
/*<body>*/
/* #region auto includes */
/* #region stl */
/*<stl>*/
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>
using namespace std;
/*</stl>*/
/* #endregion */
/* #region template/IncludeSTL.hpp*/
/**
* @file IncludeSTL.hpp
* @author btk
* @brief 標準ライブラリをincludeするだけ
* @version 0.1
* @date 2019-07-21
* @todo 何故か2回includeされる(展開scriptに
* @copyright Copyright (c) 2019
*
*/
/* #endregion */
/* #region template/Macro.hpp*/
/**
* @file Macro.hpp
* @author btk
* @brief マクロとか,LLとか
* @version 0.1
* @date 2019-07-13
*
* @copyright Copyright (c) 2019
*
*/
//! LL
using LL = long long;
/**
* @def DEBUG
* @brief デバッグ用のif文 提出時はif(0)で実行されない
*/
/*</head>*/
#ifdef BTK
#define DEBUG if (1)
#else
#ifdef CIN_ONLY
#define FAST_IO
#endif
#define DEBUG if (0)
#endif
/**
* @def ALL(v)
* @brief
* ALLマクロ
*/
#define ALL(v) (v).begin(), (v).end()
/**
* @def REC(ret, ...)
* @brief
* 再帰ラムダをするためのマクロ
*/
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
/**
* @def VAR_NAME(var)
* @brief 変数名を取得する
*/
#define VAR_NAME(var) #var
/**
* @brief
* rangeで生まれる使わない変数を消す用(警告消し)
*/
template <typename T> inline T &unused_var(T &v) { return v; }
/* #endregion */
/* #region template/IO.hpp*/
/**
* @file IO.hpp
* @author btk
* @brief cin高速化とか,出力の小数桁固定とか
* @version 0.1
* @date 2019-07-13
*
* @copyright Copyright (c) 2019
*/
/**
* @brief 入出力の設定を行うための構造体
*/
struct cww {
/**
* @brief Construct a new cww::cww object
* @details
* CIN_ONLYを定義すると,submit時にcinとscanfの同期を切る設定が走る
* DECIMAL_DIGITSを定義すると,doubleの出力時指定した桁数分小数部を吐くようになる
*/
cww() {
#ifdef FAST_IO
ios::sync_with_stdio(false);
cin.tie(0);
#endif
#ifdef DECIMAL_DIGITS
cout << fixed;
cout << setprecision(DECIMAL_DIGITS);
#endif
}
};
//! 入出力設定構造体を実体化
cww star;
/**
* @brief
* vectorに直接cin流すためのやつ
* @tparam T
* @param is
* @param v
* @return istream&
*/
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
for (auto &it : v)
is >> it;
return is;
}
/* #endregion */
/* #region template/Loop.hpp*/
/**
* @file Loop.hpp
* @author btk
* @brief rangeとかループ系のクラス
* @version 0.1
* @date 2019-07-13
*
* @copyright Copyright (c) 2019
*
*/
/**
* @brief
* rangeを逆向きに操作したいとき用
* @details
* ループの範囲は[bg,ed)なので注意
* @see range
*/
class reverse_range {
private:
struct I {
int x;
int operator*() { return x - 1; }
bool operator!=(I &lhs) { return x > lhs.x; }
void operator++() { --x; }
};
I i, n;
public:
/**
* @brief Construct a new reverse range object
*
* @param n
*/
reverse_range(int n) : i({0}), n({n}) {}
/**
* @brief Construct a new reverse range object
*
* @param i
* @param n
*/
reverse_range(int i, int n) : i({i}), n({n}) {}
/**
* @brief
* begin iterator
* @return I&
*/
I &begin() { return n; }
/**
* @brief
* end iterator
* @return I&
*/
I &end() { return i; }
};
/**
* @brief
* python みたいな range-based for を実現
* @details
* ループの範囲は[bg,ed)なので注意
* !つけると逆向きにループが回る (reverse_range)
* 空間計算量はO(1)
* 使わない変数ができて警告が出がちなので,unused_varとかを使って警告消しするとよい
*/
class range {
private:
struct I {
int x;
int operator*() { return x; }
bool operator!=(I &lhs) { return x < lhs.x; }
void operator++() { ++x; }
};
I i, n;
public:
/**
* @brief Construct a new range object
*
* @param n
*/
range(int n) : i({0}), n({n}) {}
/**
* @brief Construct a new range object
*
* @param i
* @param n
*/
range(int i, int n) : i({i}), n({n}) {}
/**
* @brief
* begin iterator
* @return I&
*/
I &begin() { return i; }
/**
* @brief
* end iterator
* @return I&
*/
I &end() { return n; }
/**
* @brief
* 逆向きに参照するrange(reverse_rangeを取得できるs)
* @return reverse_range
*/
reverse_range operator!() { return reverse_range(*i, *n); }
};
/* #endregion */
/* #region template/MinMaxOperation.hpp*/
/**
* @file MinMaxOperation.hpp
* @author btk
* @brief 最大値とか最小値を求める
* @version 0.1
* @date 2019-07-04
*
* @copyright Copyright (c) 2019
*
*/
/**
* @brief 2項の最小値求める
*
* @tparam T
*/
template <typename T> struct min_op {
/**
* @brief 本体
*
* @param l
* @param r
* @return T
*/
static T exec(const T l, const T r) { return l < r ? l : r; }
};
/**
* @brief 2項の最大値求める
*
* @tparam T
*/
template <typename T> struct max_op {
/**
* @brief 本体
*
* @param l
* @param r
* @return T
*/
static T exec(const T l, const T r) { return l > r ? l : r; }
};
/**
* @brief テンプレート再帰の末尾
*
* @tparam F 二項演算
* @tparam T
* @param v
* @return T
*/
template <typename F, typename T> inline T multi_op(T &&v) { return v; }
/**
* @brief 複数項における演算の結果を返す
*
* @tparam F
* @tparam T
* @tparam Ts
* @param head
* @param tail
* @return T
*/
template <typename F, typename T, typename... Ts>
inline T multi_op(const T head, Ts &&...tail) {
return F::exec(head, multi_op<F>(tail...));
}
/**
* @brief 複数項の最小値
* @see multi_op
* @tparam T
* @tparam Ts
* @param head
* @param tail
* @return T
*/
template <typename T, typename... Ts>
inline T multi_min(T &&head, Ts &&...tail) {
return multi_op<min_op<T>>(head, tail...);
}
/**
* @brief 複数項の最大値
* @see multi_op
* @tparam T
* @tparam Ts
* @param head
* @param tail
* @return T
*/
template <typename T, typename... Ts>
inline T multi_max(T &&head, Ts &&...tail) {
return multi_op<max_op<T>>(head, tail...);
}
/**
* @brief
* 先頭の値をFで参照する関数に基づいて変更できたらする
* @tparam F
* @tparam T
* @tparam Ts
* @param target
* @param candidates
* @return true
* @return false
*/
template <typename F, typename T, typename... Ts>
inline bool ch_op(T &target, Ts &&...candidates) {
const T old = target;
target = multi_op<F>(target, candidates...);
return old != target;
}
/**
* @brief change min
* @tparam T 型
* @param target 変更する値
* @param candidates
* @return 更新があればtrue
*/
template <typename T, typename... Ts>
inline bool chmin(T &target, Ts &&...candidates) {
return ch_op<min_op<T>>(target, candidates...);
}
/**
* @brief chminのmax版
* @see chmin
* @tparam T 型
* @param target 変更する値
* @param candidates
* @return 更新があればtrue
*/
template <typename T, typename... Ts>
inline bool chmax(T &target, Ts &&...candidates) {
return ch_op<max_op<T>>(target, candidates...);
}
/* #endregion */
/* #region template/Random.hpp*/
/**
* @file Random.hpp
* @author btk
* @brief 乱数生成系
* @version 0.1
* @date 2019-07-13
* @copyright Copyright (c) 2019
*/
//! 乱数のシード値をプロセスIDとして取得
const pid_t pid = getpid();
/**
* @brief XorShift32の実装
*/
class XorShift32 {
private:
//! XorShiftの現在の値
unsigned value;
/**
* @brief XorShift32のアルゴリズムに基づいて value を更新
*/
inline void update() {
value = value ^ (value << 13);
value = value ^ (value >> 17);
value = value ^ (value << 5);
}
/**
* @brief 値を更新し,更新前の値を返却
* @return unsigned 呼び出し時の value を用いる
*/
inline unsigned get() {
unsigned v = value;
update();
return v;
}
public:
/**
* @brief [0, 2^bit) の範囲の乱数値を取り出す
* @tparam デフォルトは31
* @return int
*/
template <int bit = 31> inline int next_int() {
return (int)(get() >> (32 - bit));
}
/**
* @brief [-2^bit,2^bit)の範囲の乱数値を取り出す
* @tparam デフォルトは31
* @return int
*/
template <int bit = 31> inline int next_signed() {
unsigned v = get();
return (int)((v >> (31 - bit)) - (1 << (bit)));
}
/**
* @brief next_int呼び出し時の最大値を取得
* @tparam 31
* @return int
*/
template <int bit = 31> inline int range_max() {
return (int)((1u << bit) - 1);
};
/**
* @brief Construct a new XorShift32 object
* @param seed
* @details 初期シードをvalueとするXorShift32のインスタンスを生成
*/
XorShift32(const unsigned seed) {
value = seed;
update();
}
/**
* @brief Construct a new XorShift 32 object
* @details 初期シードをプロセスIDとするXorShift32のインスタンスを生成
*/
XorShift32() : XorShift32(pid) {}
};
/* #endregion */
/* #region Template.hpp*/
/**
* @file Template.hpp
* @brief 競技プログラミング用テンプレート
* @author btk15049
* @date 2019/05/02
*/
/* #endregion */
/* #region graph/Graph.hpp*/
/**
* @file Graph.hpp
* @brief グラフクラス
* @author btk15049
* @date 2019/03/11
* @details
* verify: WUPC C
*/
/**
* @brief 辺を扱う構造体の例
* @details
* 辺に重みなどを加えたい場合は変数とかを増やして作る.
* Graphに使うために必要な要件:
* - id,a,bは必須,他のパラメータ増やすときはコンストラクタを忘れずに
* - versusは必須,基本的にコピペでOK
*/
struct Edge {
//! 辺id
int id;
//! 端点
int a;
//! 端点
int b;
/**
* @brief Construct a new Edge object
* @param id 辺番号
* @param a 辺に接続する頂点番号
* @param b 辺に接続する頂点番号
*/
Edge(int id = 0, int a = 0, int b = 0) : id(id), a(a), b(b) {}
/**
* @brief 辺における,vの対になってる頂点番号を取得する
* @param v 頂点番号
* @return int vじゃない方の頂点番号
*/
inline int versus(const int v) const { return a ^ b ^ v; }
};
/**
* @brief 重み付き辺を扱う構造体の例
* @details
辺に重みなどを加えたい場合は変数とかを増やして作る.
Graphに使うために必要な要件:
- id,a,bは必須,他のパラメータ増やすときはコンストラクタを忘れずに
- versusは必須,基本的にコピペでOK
*/
template <typename COST_TYPE> struct WeightedEdge {
//! 辺id
int id;
//! 端点
int a;
//! 端点
int b;
//! 辺重み
COST_TYPE cost;
/**
* @brief Construct a new Weighted Edge object
*
* @param id
* @param a
* @param b
* @param cost
*/
WeightedEdge(int id = 0, int a = 0, int b = 0, int cost = 0)
: id(id), a(a), b(b), cost(cost) {}
/**
* @brief 辺における,vの対になってる頂点番号を取得する
* @param v 頂点番号
* @return int vじゃない方の頂点番号
*/
inline int versus(const int v) const { return a ^ b ^ v; }
};
/**
* @brief グラフクラス
* @tparam E=Edge 新たなグラフクラス作るときは書き換える
* @details 0-indexedで使うことしか考えてないので注意.
*/
template <typename E = Edge> class Graph {
private:
//! 辺集合
std::vector<E> edges;
//! 隣接リスト
std::vector<std::vector<int>> g;
public:
/**
* @brief Construct a new Graph object
* @param reserved_vertex_size 頂点数の最大値,vectorのサイズ確保用
* @param reserved_edge_size 辺数の最大値,vectorのサイズ確保用
*/
Graph(int reserved_vertex_size = 1, int reserved_edge_size = -1) {
g.reserve(reserved_vertex_size);
edges.reserve(std::max(reserved_vertex_size, reserved_edge_size));
}
/**
* @brief グラフの頂点数を返す
* @return int 頂点数
*/
inline int size() { return g.size(); }
/**
* @brief vの次数を返す
* @param v 頂点番号
* @return int 次数
*/
inline int degree(const int v) { return g[v].size(); }
/**
* @brief グラフ全体の辺の数を返す
* @return int グラフ全体の辺の数
*/
inline int degree() { return edges.size(); }
/**
* @brief グラフの頂点数を変更する
* @todo 分かりづらいので,set_vertex_sizeとかに変える
* @return int
*/
inline void resize(const int n) { g.resize(n); }
/**
* @brief "無向"辺(a,b)を追加する.
* @param a 頂点番号
* @param b 頂点番号
* @param params 重みとか,容量とか
* @details paramsはemplace_backと同じノリで続けて足してけばOK
*/
template <typename... Ts> inline void add_edge(int a, int b, Ts &&...params) {
const int id = edges.size();
if ((int)g.size() <= std::max(a, b)) {
g.resize(std::max(a, b) + 1);
}
g[a].emplace_back(id);
g[b].emplace_back(id);
edges.emplace_back(id, a, b, std::forward<Ts>(params)...);
}
/**
* @brief "無向"辺Eを追加する.
* @details paramsはemplace_backと同じノリで続けて足してけばOK
*/
/**
* @brief 辺を追加 idは自動付与
* @param e
*/
inline void add_edge(E e) {
e.id = edges.size();
if ((int)g.size() <= max(e.a, e.b)) {
g.resize(max(e.a, e.b) + 1);
}
g[e.a].emplace_back(e.id);
g[e.b].emplace_back(e.id);
edges.emplace_back(e);
}
/**
* @brief "有向"辺(a,b)を追加する.
* @param a 頂点番号
* @param b 頂点番号
* @param params 重みとか,容量とか
* @details paramsはemplace_backと同じノリで続けて足してけばOK
*/
template <typename... Ts> inline void add_arc(int a, int b, Ts &&...params) {
const int id = edges.size();
if ((int)g.size() <= std::max(a, b)) {
g.resize(std::max(a, b) + 1);
}
g[a].emplace_back(id);
edges.emplace_back(id, a, b, std::forward<Ts>(params)...);
}
/**
* @brief 辺を追加 idは自動付与
* @param e
*/
inline void add_arc(E e) {
e.id = edges.size();
if ((int)g.size() <= std::max(e.a, e.b)) {
g.resize(std::max(e.a, e.b) + 1);
}
g[e.a].emplace_back(e.id);
edges.emplace_back(e);
}
/**
* @brief vの隣接頂点を返す
* @param v int
* @return vector<int>
*/
inline std::vector<int> Ns(const int v) {
std::vector<int> ns(g[v].size());
for (int i = 0; i < degree(v); i++) {
ns[i] = edges[g[v][i]].versus(v);
}
return ns;
}
/**
* @brief vに隣接する辺番号の集合を返す
* @param v int 頂点番号
* @return vector<int> 辺番号の集合
*/
inline const std::vector<int> &operator[](const int v) { return g[v]; }
/**
* @brief 辺番号から辺の参照を取得する
* @param edge_id
* @return E&
*/
inline E &i2e(const int edge_id) { return edges[edge_id]; }
};
/* #endregion */
/* #region graph/Dinic.hpp*/
/**
* @file Dinic.hpp
* @brief Dinic法の実装
* @author btk15049
* @date 2019/03/13
* @details
* @todo project selection problem
* verify: WUPC F
*/
#include <queue>
/**
* @brief フロー用の辺構造体
* @tparam F 流量の型
*/
template <typename F> struct FlowEdge {
//! 辺id
int id;
//! 端点
int a;
//! 端点
int b;
//! その辺に流せる流量
F cap;
//! 逆向き辺のid
int rev;
/**
* @brief Construct a new Edge object
* @param id 辺番号
* @param a 辺に接続する頂点番号
* @param b 辺に接続する頂点番号
* @param cap 辺に許容できる流量
* @param rev 対応する逆向き辺のid
*/
FlowEdge(int id = 0, int a = 0, int b = 0, F cap = 0, int rev = 0)
: id(id), a(a), b(b), cap(cap), rev(rev) {}
/**
* @brief 辺における,vの対になってる頂点番号を取得する
* @param v 頂点番号
* @return int vじゃない方の頂点番号
*/
inline int versus(const int v) const { return a ^ b ^ v; }
};
/**
* @brief フロー用のグラフクラス,Graphを継承
* @tparam T 辺構造体
*/
template <typename T> class FlowGraph : public Graph<T> {
private:
using E = T;
using Graph<E>::add_arc; // add_arcは外から呼び出せないようにする
public:
/**
* @brief a->bへ流量fの辺を追加
* @tparam F 流量の型
* @param a 頂点番号
* @param b 頂点番号
* @param f 最大流量
* @details Graph::add_edge をオーバーライドしている.
*/
template <typename F> inline void add_edge(int a, int b, F f) {
const int id = this->degree();
this->add_arc(a, b, f, id + 1);
this->add_arc(b, a, 0, id);
}
/**
* @brief Construct a new Flow Graph object
* @details
* 完全転送してるので詳しくはGraphクラスのコンストラクタを参照.
*/
template <typename... Ts>
FlowGraph(Ts &&...params) : Graph<E>(std::forward<Ts>(params)...) {}
};
/**
* @brief Dinic法の実装
* @tparam T 流量の型
* @tparam flow_inf 流量の最大値
*/
template <typename T, T flow_inf> class Dinic {
private:
using F = T;
using E = FlowEdge<F>;
FlowGraph<E> *G;
/**
* @brief 最短路求めるBFSをする
* @param s 始点
* @return vector<int> sから各頂点への最短距離
*/
std::vector<int> bfs(const int s) {
int N = G->size();
std::queue<int> que;
std::vector<int> dist(N, -1);
dist[s] = 0;
que.push(s);
for (; !que.empty(); que.pop()) {
const int v = que.front();
for (int id : (*G)[v]) {
const E &e = G->i2e(id);
const int u = e.versus(v);
if (e.cap > 0 && dist[u] == -1) {
dist[u] = dist[v] + 1;
que.push(u);
}
}
}
return dist;
}
/**
* @brief s->tに向けてできるだけフローを流す
*/
F dfs(const int v, const int s, const F f, std::vector<unsigned> &I,
std::vector<int> &D) {
if (v == s)
return f;
const std::vector<int> &edge_ids = (*G)[v];
for (unsigned &i = I[v]; i < edge_ids.size(); i++) {
E &e = G->i2e(edge_ids[i]);
E &re = G->i2e(e.rev);
const int u = e.versus(v);
if (re.cap > 0 && D[v] > D[u]) {
F d = dfs(u, s, std::min(f, re.cap), I, D);
if (d > 0) {
e.cap += d;
re.cap -= d;
return d;
}
}
}
return 0;
}
public:
/**
* @brief 現在の残余グラフから得られる最大流を求めて流す.
* @param s 始点
* @param t 終点
* @return F 流量
*/
F solve(const int s, const int t) {
F res = 0;
while (true) {
std::vector<int> dist = bfs(s);
if (dist[t] < 0 || flow_inf == res)
break;
std::vector<unsigned> iter(G->size(), 0);
while (true) {
F f = dfs(t, s, flow_inf - res, iter, dist);
if (f == 0)
break;
res += f;
}
}
return res;
}
/**
* @brief Construct a new Dinic object
* @param G 最大流を流したいグラフ
*/
Dinic(FlowGraph<E> &G) : G(&G) {}
};
/* #endregion */
/* #endregion */
/*</body>*/
#endif
int N, M, T;
int x[112345];
int y[112345];
using V = vector<int>;
using VV = vector<V>;
struct P {
int edge_id;
int before_label;
int after_label;
};
bitset<50000> B[50000];
void solve1() {
for (int i : range(N)) {
B[i][i] = true;
}
for (int i : !range(M)) {
auto tmp = B[x[i]] | B[y[i]];
B[x[i]] = tmp;
B[y[i]] = tmp;
}
auto ok = B[0];
for (int i : range(1, N)) {
ok &= B[i];
}
if (ok.any()) {
exit(-1);
} else {
printf("-1\n");
}
}
void solve2() {
vector<vector<P>> g(N);
FlowGraph<FlowEdge<int>> fg(N + N + M + M + 2);
int lb = 0;
for (int i : range(N)) {
g[i].push_back(P{-1, lb, lb});
lb++;
}
for (int i : range(M)) {
P p1{i, lb, lb + 1};
P p2{i, lb, lb + 1};
fg.add_edge(lb, lb + 1, 1);
// cerr << lb << " " << lb + 1 << " " << 1 << endl;
lb += 2;
g[x[i]].push_back(p1);
g[y[i]].push_back(p2);
}
for (int i : range(N)) {
g[i].push_back(P{-1, lb, lb});
lb++;
}
int S = lb++;
int T = lb++;
for (int i : range(N)) {
fg.add_edge(S, g[i].front().before_label, 1);
for (int j : range(1, g[i].size())) {
fg.add_edge(g[i][j - 1].after_label, g[i][j].before_label, 1);
// cerr << g[i][j - 1].after_label << " " << g[i][j].before_label
//<< " " << 1 << endl;
}
fg.add_edge(g[i].back().after_label, T, 1);
}
int flow = Dinic<int, 2>(fg).solve(S, T);
// cerr << flow << endl;
if (flow == 1) {
printf("-1\n");
} else {
string ret(M, '^');
for (int i : range(N)) {
for (int j : range(g[i].size())) {
if (g[i][j].edge_id != -1) {
bool use = false;
for (int eid : fg[g[i][j].after_label]) {
auto e = fg.i2e(eid);
if (e.versus(g[i][j].after_label) == g[i][j + 1].before_label &&
e.cap == 0) {
use = true;
}
}
if (use && y[g[i][j].edge_id] == i) {
ret[g[i][j].edge_id] = 'v';
}
}
}
}
printf("%s\n", ret.c_str());
}
}
void input() {
scanf("%d%d%d", &N, &M, &T);
for (int i : range(M)) {
scanf("%d%d", x + i, y + i);
x[i]--;
y[i]--;
}
// N = 400;
// M = 100000;
// T = 2;
// vector<int> g(N);
// iota(ALL(g), 0);
// srand(time(NULL));
// printf("%d %d 2\n", N, M);
// for (int i : range(M)) {
// swap(g[abs(rand() % N)], g[N - 1]);
// x[i] = g[N - 1];
// swap(g[abs(rand() % (N - 1))], g[N - 1]);
// y[i] = g[N - 1];
// printf("%d %d\n", x[i] + 1, y[i] + 1);
//}
}
int main() {
/* write here */
input();
if (T == 2) {
solve2();
} else {
solve1();
}
return 0;
} | // https://atcoder.jp/contests/agc041/tasks/agc041_e
#define DECIMAL_DIGITS 10
#define STATIC_MOD 1e9 + 7
#ifdef BTK
/*<head>*/
#include "Template.hpp"
#include "graph/Dinic.hpp"
/*</head>*/
#else
/*<body>*/
/* #region auto includes */
/* #region stl */
/*<stl>*/
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>
using namespace std;
/*</stl>*/
/* #endregion */
/* #region template/IncludeSTL.hpp*/
/**
* @file IncludeSTL.hpp
* @author btk
* @brief 標準ライブラリをincludeするだけ
* @version 0.1
* @date 2019-07-21
* @todo 何故か2回includeされる(展開scriptに
* @copyright Copyright (c) 2019
*
*/
/* #endregion */
/* #region template/Macro.hpp*/
/**
* @file Macro.hpp
* @author btk
* @brief マクロとか,LLとか
* @version 0.1
* @date 2019-07-13
*
* @copyright Copyright (c) 2019
*
*/
//! LL
using LL = long long;
/**
* @def DEBUG
* @brief デバッグ用のif文 提出時はif(0)で実行されない
*/
/*</head>*/
#ifdef BTK
#define DEBUG if (1)
#else
#ifdef CIN_ONLY
#define FAST_IO
#endif
#define DEBUG if (0)
#endif
/**
* @def ALL(v)
* @brief
* ALLマクロ
*/
#define ALL(v) (v).begin(), (v).end()
/**
* @def REC(ret, ...)
* @brief
* 再帰ラムダをするためのマクロ
*/
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
/**
* @def VAR_NAME(var)
* @brief 変数名を取得する
*/
#define VAR_NAME(var) #var
/**
* @brief
* rangeで生まれる使わない変数を消す用(警告消し)
*/
template <typename T> inline T &unused_var(T &v) { return v; }
/* #endregion */
/* #region template/IO.hpp*/
/**
* @file IO.hpp
* @author btk
* @brief cin高速化とか,出力の小数桁固定とか
* @version 0.1
* @date 2019-07-13
*
* @copyright Copyright (c) 2019
*/
/**
* @brief 入出力の設定を行うための構造体
*/
struct cww {
/**
* @brief Construct a new cww::cww object
* @details
* CIN_ONLYを定義すると,submit時にcinとscanfの同期を切る設定が走る
* DECIMAL_DIGITSを定義すると,doubleの出力時指定した桁数分小数部を吐くようになる
*/
cww() {
#ifdef FAST_IO
ios::sync_with_stdio(false);
cin.tie(0);
#endif
#ifdef DECIMAL_DIGITS
cout << fixed;
cout << setprecision(DECIMAL_DIGITS);
#endif
}
};
//! 入出力設定構造体を実体化
cww star;
/**
* @brief
* vectorに直接cin流すためのやつ
* @tparam T
* @param is
* @param v
* @return istream&
*/
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
for (auto &it : v)
is >> it;
return is;
}
/* #endregion */
/* #region template/Loop.hpp*/
/**
* @file Loop.hpp
* @author btk
* @brief rangeとかループ系のクラス
* @version 0.1
* @date 2019-07-13
*
* @copyright Copyright (c) 2019
*
*/
/**
* @brief
* rangeを逆向きに操作したいとき用
* @details
* ループの範囲は[bg,ed)なので注意
* @see range
*/
class reverse_range {
private:
struct I {
int x;
int operator*() { return x - 1; }
bool operator!=(I &lhs) { return x > lhs.x; }
void operator++() { --x; }
};
I i, n;
public:
/**
* @brief Construct a new reverse range object
*
* @param n
*/
reverse_range(int n) : i({0}), n({n}) {}
/**
* @brief Construct a new reverse range object
*
* @param i
* @param n
*/
reverse_range(int i, int n) : i({i}), n({n}) {}
/**
* @brief
* begin iterator
* @return I&
*/
I &begin() { return n; }
/**
* @brief
* end iterator
* @return I&
*/
I &end() { return i; }
};
/**
* @brief
* python みたいな range-based for を実現
* @details
* ループの範囲は[bg,ed)なので注意
* !つけると逆向きにループが回る (reverse_range)
* 空間計算量はO(1)
* 使わない変数ができて警告が出がちなので,unused_varとかを使って警告消しするとよい
*/
class range {
private:
struct I {
int x;
int operator*() { return x; }
bool operator!=(I &lhs) { return x < lhs.x; }
void operator++() { ++x; }
};
I i, n;
public:
/**
* @brief Construct a new range object
*
* @param n
*/
range(int n) : i({0}), n({n}) {}
/**
* @brief Construct a new range object
*
* @param i
* @param n
*/
range(int i, int n) : i({i}), n({n}) {}
/**
* @brief
* begin iterator
* @return I&
*/
I &begin() { return i; }
/**
* @brief
* end iterator
* @return I&
*/
I &end() { return n; }
/**
* @brief
* 逆向きに参照するrange(reverse_rangeを取得できるs)
* @return reverse_range
*/
reverse_range operator!() { return reverse_range(*i, *n); }
};
/* #endregion */
/* #region template/MinMaxOperation.hpp*/
/**
* @file MinMaxOperation.hpp
* @author btk
* @brief 最大値とか最小値を求める
* @version 0.1
* @date 2019-07-04
*
* @copyright Copyright (c) 2019
*
*/
/**
* @brief 2項の最小値求める
*
* @tparam T
*/
template <typename T> struct min_op {
/**
* @brief 本体
*
* @param l
* @param r
* @return T
*/
static T exec(const T l, const T r) { return l < r ? l : r; }
};
/**
* @brief 2項の最大値求める
*
* @tparam T
*/
template <typename T> struct max_op {
/**
* @brief 本体
*
* @param l
* @param r
* @return T
*/
static T exec(const T l, const T r) { return l > r ? l : r; }
};
/**
* @brief テンプレート再帰の末尾
*
* @tparam F 二項演算
* @tparam T
* @param v
* @return T
*/
template <typename F, typename T> inline T multi_op(T &&v) { return v; }
/**
* @brief 複数項における演算の結果を返す
*
* @tparam F
* @tparam T
* @tparam Ts
* @param head
* @param tail
* @return T
*/
template <typename F, typename T, typename... Ts>
inline T multi_op(const T head, Ts &&...tail) {
return F::exec(head, multi_op<F>(tail...));
}
/**
* @brief 複数項の最小値
* @see multi_op
* @tparam T
* @tparam Ts
* @param head
* @param tail
* @return T
*/
template <typename T, typename... Ts>
inline T multi_min(T &&head, Ts &&...tail) {
return multi_op<min_op<T>>(head, tail...);
}
/**
* @brief 複数項の最大値
* @see multi_op
* @tparam T
* @tparam Ts
* @param head
* @param tail
* @return T
*/
template <typename T, typename... Ts>
inline T multi_max(T &&head, Ts &&...tail) {
return multi_op<max_op<T>>(head, tail...);
}
/**
* @brief
* 先頭の値をFで参照する関数に基づいて変更できたらする
* @tparam F
* @tparam T
* @tparam Ts
* @param target
* @param candidates
* @return true
* @return false
*/
template <typename F, typename T, typename... Ts>
inline bool ch_op(T &target, Ts &&...candidates) {
const T old = target;
target = multi_op<F>(target, candidates...);
return old != target;
}
/**
* @brief change min
* @tparam T 型
* @param target 変更する値
* @param candidates
* @return 更新があればtrue
*/
template <typename T, typename... Ts>
inline bool chmin(T &target, Ts &&...candidates) {
return ch_op<min_op<T>>(target, candidates...);
}
/**
* @brief chminのmax版
* @see chmin
* @tparam T 型
* @param target 変更する値
* @param candidates
* @return 更新があればtrue
*/
template <typename T, typename... Ts>
inline bool chmax(T &target, Ts &&...candidates) {
return ch_op<max_op<T>>(target, candidates...);
}
/* #endregion */
/* #region template/Random.hpp*/
/**
* @file Random.hpp
* @author btk
* @brief 乱数生成系
* @version 0.1
* @date 2019-07-13
* @copyright Copyright (c) 2019
*/
//! 乱数のシード値をプロセスIDとして取得
const pid_t pid = getpid();
/**
* @brief XorShift32の実装
*/
class XorShift32 {
private:
//! XorShiftの現在の値
unsigned value;
/**
* @brief XorShift32のアルゴリズムに基づいて value を更新
*/
inline void update() {
value = value ^ (value << 13);
value = value ^ (value >> 17);
value = value ^ (value << 5);
}
/**
* @brief 値を更新し,更新前の値を返却
* @return unsigned 呼び出し時の value を用いる
*/
inline unsigned get() {
unsigned v = value;
update();
return v;
}
public:
/**
* @brief [0, 2^bit) の範囲の乱数値を取り出す
* @tparam デフォルトは31
* @return int
*/
template <int bit = 31> inline int next_int() {
return (int)(get() >> (32 - bit));
}
/**
* @brief [-2^bit,2^bit)の範囲の乱数値を取り出す
* @tparam デフォルトは31
* @return int
*/
template <int bit = 31> inline int next_signed() {
unsigned v = get();
return (int)((v >> (31 - bit)) - (1 << (bit)));
}
/**
* @brief next_int呼び出し時の最大値を取得
* @tparam 31
* @return int
*/
template <int bit = 31> inline int range_max() {
return (int)((1u << bit) - 1);
};
/**
* @brief Construct a new XorShift32 object
* @param seed
* @details 初期シードをvalueとするXorShift32のインスタンスを生成
*/
XorShift32(const unsigned seed) {
value = seed;
update();
}
/**
* @brief Construct a new XorShift 32 object
* @details 初期シードをプロセスIDとするXorShift32のインスタンスを生成
*/
XorShift32() : XorShift32(pid) {}
};
/* #endregion */
/* #region Template.hpp*/
/**
* @file Template.hpp
* @brief 競技プログラミング用テンプレート
* @author btk15049
* @date 2019/05/02
*/
/* #endregion */
/* #region graph/Graph.hpp*/
/**
* @file Graph.hpp
* @brief グラフクラス
* @author btk15049
* @date 2019/03/11
* @details
* verify: WUPC C
*/
/**
* @brief 辺を扱う構造体の例
* @details
* 辺に重みなどを加えたい場合は変数とかを増やして作る.
* Graphに使うために必要な要件:
* - id,a,bは必須,他のパラメータ増やすときはコンストラクタを忘れずに
* - versusは必須,基本的にコピペでOK
*/
struct Edge {
//! 辺id
int id;
//! 端点
int a;
//! 端点
int b;
/**
* @brief Construct a new Edge object
* @param id 辺番号
* @param a 辺に接続する頂点番号
* @param b 辺に接続する頂点番号
*/
Edge(int id = 0, int a = 0, int b = 0) : id(id), a(a), b(b) {}
/**
* @brief 辺における,vの対になってる頂点番号を取得する
* @param v 頂点番号
* @return int vじゃない方の頂点番号
*/
inline int versus(const int v) const { return a ^ b ^ v; }
};
/**
* @brief 重み付き辺を扱う構造体の例
* @details
辺に重みなどを加えたい場合は変数とかを増やして作る.
Graphに使うために必要な要件:
- id,a,bは必須,他のパラメータ増やすときはコンストラクタを忘れずに
- versusは必須,基本的にコピペでOK
*/
template <typename COST_TYPE> struct WeightedEdge {
//! 辺id
int id;
//! 端点
int a;
//! 端点
int b;
//! 辺重み
COST_TYPE cost;
/**
* @brief Construct a new Weighted Edge object
*
* @param id
* @param a
* @param b
* @param cost
*/
WeightedEdge(int id = 0, int a = 0, int b = 0, int cost = 0)
: id(id), a(a), b(b), cost(cost) {}
/**
* @brief 辺における,vの対になってる頂点番号を取得する
* @param v 頂点番号
* @return int vじゃない方の頂点番号
*/
inline int versus(const int v) const { return a ^ b ^ v; }
};
/**
* @brief グラフクラス
* @tparam E=Edge 新たなグラフクラス作るときは書き換える
* @details 0-indexedで使うことしか考えてないので注意.
*/
template <typename E = Edge> class Graph {
private:
//! 辺集合
std::vector<E> edges;
//! 隣接リスト
std::vector<std::vector<int>> g;
public:
/**
* @brief Construct a new Graph object
* @param reserved_vertex_size 頂点数の最大値,vectorのサイズ確保用
* @param reserved_edge_size 辺数の最大値,vectorのサイズ確保用
*/
Graph(int reserved_vertex_size = 1, int reserved_edge_size = -1) {
g.reserve(reserved_vertex_size);
edges.reserve(std::max(reserved_vertex_size, reserved_edge_size));
}
/**
* @brief グラフの頂点数を返す
* @return int 頂点数
*/
inline int size() { return g.size(); }
/**
* @brief vの次数を返す
* @param v 頂点番号
* @return int 次数
*/
inline int degree(const int v) { return g[v].size(); }
/**
* @brief グラフ全体の辺の数を返す
* @return int グラフ全体の辺の数
*/
inline int degree() { return edges.size(); }
/**
* @brief グラフの頂点数を変更する
* @todo 分かりづらいので,set_vertex_sizeとかに変える
* @return int
*/
inline void resize(const int n) { g.resize(n); }
/**
* @brief "無向"辺(a,b)を追加する.
* @param a 頂点番号
* @param b 頂点番号
* @param params 重みとか,容量とか
* @details paramsはemplace_backと同じノリで続けて足してけばOK
*/
template <typename... Ts> inline void add_edge(int a, int b, Ts &&...params) {
const int id = edges.size();
if ((int)g.size() <= std::max(a, b)) {
g.resize(std::max(a, b) + 1);
}
g[a].emplace_back(id);
g[b].emplace_back(id);
edges.emplace_back(id, a, b, std::forward<Ts>(params)...);
}
/**
* @brief "無向"辺Eを追加する.
* @details paramsはemplace_backと同じノリで続けて足してけばOK
*/
/**
* @brief 辺を追加 idは自動付与
* @param e
*/
inline void add_edge(E e) {
e.id = edges.size();
if ((int)g.size() <= max(e.a, e.b)) {
g.resize(max(e.a, e.b) + 1);
}
g[e.a].emplace_back(e.id);
g[e.b].emplace_back(e.id);
edges.emplace_back(e);
}
/**
* @brief "有向"辺(a,b)を追加する.
* @param a 頂点番号
* @param b 頂点番号
* @param params 重みとか,容量とか
* @details paramsはemplace_backと同じノリで続けて足してけばOK
*/
template <typename... Ts> inline void add_arc(int a, int b, Ts &&...params) {
const int id = edges.size();
if ((int)g.size() <= std::max(a, b)) {
g.resize(std::max(a, b) + 1);
}
g[a].emplace_back(id);
edges.emplace_back(id, a, b, std::forward<Ts>(params)...);
}
/**
* @brief 辺を追加 idは自動付与
* @param e
*/
inline void add_arc(E e) {
e.id = edges.size();
if ((int)g.size() <= std::max(e.a, e.b)) {
g.resize(std::max(e.a, e.b) + 1);
}
g[e.a].emplace_back(e.id);
edges.emplace_back(e);
}
/**
* @brief vの隣接頂点を返す
* @param v int
* @return vector<int>
*/
inline std::vector<int> Ns(const int v) {
std::vector<int> ns(g[v].size());
for (int i = 0; i < degree(v); i++) {
ns[i] = edges[g[v][i]].versus(v);
}
return ns;
}
/**
* @brief vに隣接する辺番号の集合を返す
* @param v int 頂点番号
* @return vector<int> 辺番号の集合
*/
inline const std::vector<int> &operator[](const int v) { return g[v]; }
/**
* @brief 辺番号から辺の参照を取得する
* @param edge_id
* @return E&
*/
inline E &i2e(const int edge_id) { return edges[edge_id]; }
};
/* #endregion */
/* #region graph/Dinic.hpp*/
/**
* @file Dinic.hpp
* @brief Dinic法の実装
* @author btk15049
* @date 2019/03/13
* @details
* @todo project selection problem
* verify: WUPC F
*/
#include <queue>
/**
* @brief フロー用の辺構造体
* @tparam F 流量の型
*/
template <typename F> struct FlowEdge {
//! 辺id
int id;
//! 端点
int a;
//! 端点
int b;
//! その辺に流せる流量
F cap;
//! 逆向き辺のid
int rev;
/**
* @brief Construct a new Edge object
* @param id 辺番号
* @param a 辺に接続する頂点番号
* @param b 辺に接続する頂点番号
* @param cap 辺に許容できる流量
* @param rev 対応する逆向き辺のid
*/
FlowEdge(int id = 0, int a = 0, int b = 0, F cap = 0, int rev = 0)
: id(id), a(a), b(b), cap(cap), rev(rev) {}
/**
* @brief 辺における,vの対になってる頂点番号を取得する
* @param v 頂点番号
* @return int vじゃない方の頂点番号
*/
inline int versus(const int v) const { return a ^ b ^ v; }
};
/**
* @brief フロー用のグラフクラス,Graphを継承
* @tparam T 辺構造体
*/
template <typename T> class FlowGraph : public Graph<T> {
private:
using E = T;
using Graph<E>::add_arc; // add_arcは外から呼び出せないようにする
public:
/**
* @brief a->bへ流量fの辺を追加
* @tparam F 流量の型
* @param a 頂点番号
* @param b 頂点番号
* @param f 最大流量
* @details Graph::add_edge をオーバーライドしている.
*/
template <typename F> inline void add_edge(int a, int b, F f) {
const int id = this->degree();
this->add_arc(a, b, f, id + 1);
this->add_arc(b, a, 0, id);
}
/**
* @brief Construct a new Flow Graph object
* @details
* 完全転送してるので詳しくはGraphクラスのコンストラクタを参照.
*/
template <typename... Ts>
FlowGraph(Ts &&...params) : Graph<E>(std::forward<Ts>(params)...) {}
};
/**
* @brief Dinic法の実装
* @tparam T 流量の型
* @tparam flow_inf 流量の最大値
*/
template <typename T, T flow_inf> class Dinic {
private:
using F = T;
using E = FlowEdge<F>;
FlowGraph<E> *G;
/**
* @brief 最短路求めるBFSをする
* @param s 始点
* @return vector<int> sから各頂点への最短距離
*/
std::vector<int> bfs(const int s) {
int N = G->size();
std::queue<int> que;
std::vector<int> dist(N, -1);
dist[s] = 0;
que.push(s);
for (; !que.empty(); que.pop()) {
const int v = que.front();
for (int id : (*G)[v]) {
const E &e = G->i2e(id);
const int u = e.versus(v);
if (e.cap > 0 && dist[u] == -1) {
dist[u] = dist[v] + 1;
que.push(u);
}
}
}
return dist;
}
/**
* @brief s->tに向けてできるだけフローを流す
*/
F dfs(const int v, const int s, const F f, std::vector<unsigned> &I,
std::vector<int> &D) {
if (v == s)
return f;
const std::vector<int> &edge_ids = (*G)[v];
for (unsigned &i = I[v]; i < edge_ids.size(); i++) {
E &e = G->i2e(edge_ids[i]);
E &re = G->i2e(e.rev);
const int u = e.versus(v);
if (re.cap > 0 && D[v] > D[u]) {
F d = dfs(u, s, std::min(f, re.cap), I, D);
if (d > 0) {
e.cap += d;
re.cap -= d;
return d;
}
}
}
return 0;
}
public:
/**
* @brief 現在の残余グラフから得られる最大流を求めて流す.
* @param s 始点
* @param t 終点
* @return F 流量
*/
F solve(const int s, const int t) {
F res = 0;
while (true) {
std::vector<int> dist = bfs(s);
if (dist[t] < 0 || flow_inf == res)
break;
std::vector<unsigned> iter(G->size(), 0);
while (true) {
F f = dfs(t, s, flow_inf - res, iter, dist);
if (f == 0)
break;
res += f;
}
}
return res;
}
/**
* @brief Construct a new Dinic object
* @param G 最大流を流したいグラフ
*/
Dinic(FlowGraph<E> &G) : G(&G) {}
};
/* #endregion */
/* #endregion */
/*</body>*/
#endif
int N, M, T;
int x[112345];
int y[112345];
using V = vector<int>;
using VV = vector<V>;
struct P {
int edge_id;
int before_label;
int after_label;
};
bitset<50000> B[50000];
void solve1() {
for (int i : range(N)) {
B[i][i] = true;
}
for (int i : !range(M)) {
auto tmp = B[x[i]] | B[y[i]];
B[x[i]] = tmp;
B[y[i]] = tmp;
}
auto ok = B[0];
for (int i : range(1, N)) {
ok &= B[i];
}
if (ok.any()) {
int target = ok._Find_first();
bitset<50000> cur;
cur[target] = true;
string ret(M, '^');
for (int i : !range(M)) {
if (cur[x[i]]) {
ret[i] = '^';
cur[y[i]] = true;
} else if (cur[y[i]]) {
ret[i] = 'v';
cur[x[i]] = true;
}
}
printf("%s\n", ret.c_str());
} else {
printf("-1\n");
}
}
void solve2() {
vector<vector<P>> g(N);
FlowGraph<FlowEdge<int>> fg(N + N + M + M + 2);
int lb = 0;
for (int i : range(N)) {
g[i].push_back(P{-1, lb, lb});
lb++;
}
for (int i : range(M)) {
P p1{i, lb, lb + 1};
P p2{i, lb, lb + 1};
fg.add_edge(lb, lb + 1, 1);
// cerr << lb << " " << lb + 1 << " " << 1 << endl;
lb += 2;
g[x[i]].push_back(p1);
g[y[i]].push_back(p2);
}
for (int i : range(N)) {
g[i].push_back(P{-1, lb, lb});
lb++;
}
int S = lb++;
int T = lb++;
for (int i : range(N)) {
fg.add_edge(S, g[i].front().before_label, 1);
for (int j : range(1, g[i].size())) {
fg.add_edge(g[i][j - 1].after_label, g[i][j].before_label, 1);
// cerr << g[i][j - 1].after_label << " " << g[i][j].before_label
//<< " " << 1 << endl;
}
fg.add_edge(g[i].back().after_label, T, 1);
}
int flow = Dinic<int, 2>(fg).solve(S, T);
// cerr << flow << endl;
if (flow == 1) {
printf("-1\n");
} else {
string ret(M, '^');
for (int i : range(N)) {
for (int j : range(g[i].size())) {
if (g[i][j].edge_id != -1) {
bool use = false;
for (int eid : fg[g[i][j].after_label]) {
auto e = fg.i2e(eid);
if (e.versus(g[i][j].after_label) == g[i][j + 1].before_label &&
e.cap == 0) {
use = true;
}
}
if (use && y[g[i][j].edge_id] == i) {
ret[g[i][j].edge_id] = 'v';
}
}
}
}
printf("%s\n", ret.c_str());
}
}
void input() {
scanf("%d%d%d", &N, &M, &T);
for (int i : range(M)) {
scanf("%d%d", x + i, y + i);
x[i]--;
y[i]--;
}
// N = 400;
// M = 100000;
// T = 2;
// vector<int> g(N);
// iota(ALL(g), 0);
// srand(time(NULL));
// printf("%d %d 2\n", N, M);
// for (int i : range(M)) {
// swap(g[abs(rand() % N)], g[N - 1]);
// x[i] = g[N - 1];
// swap(g[abs(rand() % (N - 1))], g[N - 1]);
// y[i] = g[N - 1];
// printf("%d %d\n", x[i] + 1, y[i] + 1);
//}
}
int main() {
/* write here */
input();
if (T == 2) {
solve2();
} else {
solve1();
}
return 0;
} | replace | 897 | 898 | 897 | 912 | -11 | |
p02827 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll, ll>
#define poly vector<ll>
#define mem(a) memset((a), 0, sizeof(a))
#define For(i, l, r) for (int i = (int)(l); i <= (int)(r); i++)
#define Rep(i, r, l) for (int i = (int)(r); i >= (int)(l); i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
#define gc getchar
inline ll read() {
ll x = 0;
char ch = gc();
bool positive = 1;
for (; !isdigit(ch); ch = gc())
if (ch == '-')
positive = 0;
for (; isdigit(ch); ch = gc())
x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(ll a) {
if (a < 0) {
a = -a;
putchar('-');
}
if (a >= 10)
write(a / 10);
putchar('0' + a % 10);
}
inline void writeln(ll a) {
write(a);
puts("");
}
inline void wri(ll a) {
write(a);
putchar(' ');
}
inline ull rnd() { return ((ull)rand() << 30 ^ rand()) << 4 | rand() % 4; }
const int N = 50005, M = 100005, K = 256;
int n, m, x[M], y[M], vis[N], to[N];
char ans[M];
void GG() {
puts("-1");
exit(0);
}
int main() {
#ifdef Brollan
freopen("1.in", "r", stdin);
#endif
n = read(), m = read();
int T = read();
double t = clock();
if (T == 1) {
static bitset<N> s[N];
For(i, 1, n) s[i][i] = 1;
For(i, 1, m) {
x[i] = read();
y[i] = read();
s[x[i]] = s[y[i]] = s[x[i]] | s[y[i]];
}
For(i, 1, n) if (s[i].count() == n) {
vis[i] = 1;
Rep(j, m, 1) {
// cout<<x[i]<<" "<<vis[x[i]]<<endl;
if (vis[x[j]])
ans[j] = '^';
else
ans[j] = 'v';
vis[x[j]] = vis[y[j]] = vis[x[j]] | vis[y[j]];
}
cout << (ans + 1) << endl;
return 0;
}
} else {
static bitset<K + 2> s[M][K + 2];
For(i, 1, m) {
x[i] = read();
y[i] = read();
}
For(i, 1, n) For(j, i + 1, min(n, K)) s[0][i][j] = s[0][j][i] = 1;
For(o, 0, 1000) {
int node = 0;
For(j, 0, 511) to[j] = 0;
For(j, 0, min(255, n - 1)) {
int t = rnd() % min(n, 500) + 1;
while (to[t])
t = rnd() % min(n, 500) + 1;
to[t] = ++node;
}
For(i, 1, m) {
memcpy(s[i], s[i - 1], sizeof(s[i]));
int X = to[x[i]], Y = to[y[i]];
if (to[X] && to[Y]) {
s[i][Y] = s[i][X] = s[i][Y] | s[i][X];
For(j, 1, K) s[i][j][X] = s[i][j][Y] = s[i][j][X] | s[i][j][Y];
s[i][X][Y] = s[i][Y][X] = s[i][X][X] = s[i][Y][Y] = 0;
}
}
For(X, 1, n)
For(Y, X + 1, min(n, 500)) if (to[X] && to[Y] && s[m][to[X]][to[Y]]) {
Rep(i, m, 1) {
if (s[i - 1][to[X]][to[Y]]) {
if (X == x[i] || Y == x[i])
ans[i] = '^';
else
ans[i] = 'v';
} else {
if (X == x[i] || Y == x[i]) {
ans[i] = '^';
if (X == x[i])
X = y[i];
else
Y = y[i];
} else {
ans[i] = 'v';
if (X == y[i])
X = x[i];
else
Y = x[i];
}
}
}
cout << (ans + 1) << endl;
exit(0);
}
if ((clock() - t) / CLOCKS_PER_SEC > 1.6)
GG();
}
}
GG();
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll, ll>
#define poly vector<ll>
#define mem(a) memset((a), 0, sizeof(a))
#define For(i, l, r) for (int i = (int)(l); i <= (int)(r); i++)
#define Rep(i, r, l) for (int i = (int)(r); i >= (int)(l); i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
#define gc getchar
inline ll read() {
ll x = 0;
char ch = gc();
bool positive = 1;
for (; !isdigit(ch); ch = gc())
if (ch == '-')
positive = 0;
for (; isdigit(ch); ch = gc())
x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(ll a) {
if (a < 0) {
a = -a;
putchar('-');
}
if (a >= 10)
write(a / 10);
putchar('0' + a % 10);
}
inline void writeln(ll a) {
write(a);
puts("");
}
inline void wri(ll a) {
write(a);
putchar(' ');
}
inline ll rnd() {
ull ans = 0;
For(i, 0, 4) ans = ans << 15 ^ rand();
return ans % ((ull)1 << 63);
}
const int N = 50005, M = 100005, K = 256;
int n, m, x[M], y[M], vis[N], to[N];
char ans[M];
void GG() {
puts("-1");
exit(0);
}
int main() {
#ifdef Brollan
freopen("1.in", "r", stdin);
#endif
n = read(), m = read();
int T = read();
double t = clock();
if (T == 1) {
static bitset<N> s[N];
For(i, 1, n) s[i][i] = 1;
For(i, 1, m) {
x[i] = read();
y[i] = read();
s[x[i]] = s[y[i]] = s[x[i]] | s[y[i]];
}
For(i, 1, n) if (s[i].count() == n) {
vis[i] = 1;
Rep(j, m, 1) {
// cout<<x[i]<<" "<<vis[x[i]]<<endl;
if (vis[x[j]])
ans[j] = '^';
else
ans[j] = 'v';
vis[x[j]] = vis[y[j]] = vis[x[j]] | vis[y[j]];
}
cout << (ans + 1) << endl;
return 0;
}
} else {
static bitset<K + 2> s[M][K + 2];
For(i, 1, m) {
x[i] = read();
y[i] = read();
}
For(i, 1, n) For(j, i + 1, min(n, K)) s[0][i][j] = s[0][j][i] = 1;
For(o, 0, 1000) {
int node = 0;
For(j, 0, 511) to[j] = 0;
For(j, 0, min(255, n - 1)) {
int t = rnd() % min(n, 500) + 1;
while (to[t])
t = rnd() % min(n, 500) + 1;
to[t] = ++node;
}
For(i, 1, m) {
memcpy(s[i], s[i - 1], sizeof(s[i]));
int X = to[x[i]], Y = to[y[i]];
if (to[X] && to[Y]) {
s[i][Y] = s[i][X] = s[i][Y] | s[i][X];
For(j, 1, K) s[i][j][X] = s[i][j][Y] = s[i][j][X] | s[i][j][Y];
s[i][X][Y] = s[i][Y][X] = s[i][X][X] = s[i][Y][Y] = 0;
}
}
For(X, 1, n)
For(Y, X + 1, min(n, 500)) if (to[X] && to[Y] && s[m][to[X]][to[Y]]) {
Rep(i, m, 1) {
if (s[i - 1][to[X]][to[Y]]) {
if (X == x[i] || Y == x[i])
ans[i] = '^';
else
ans[i] = 'v';
} else {
if (X == x[i] || Y == x[i]) {
ans[i] = '^';
if (X == x[i])
X = y[i];
else
Y = y[i];
} else {
ans[i] = 'v';
if (X == y[i])
X = x[i];
else
Y = x[i];
}
}
}
cout << (ans + 1) << endl;
exit(0);
}
if ((clock() - t) / CLOCKS_PER_SEC > 1.6)
GG();
}
}
GG();
} | replace | 50 | 51 | 50 | 55 | TLE | |
p02828 | C++ | Runtime Error | #include <bits/stdc++.h>
#define IL __inline__ __attribute__((always_inline))
#define For(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define FOR(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++i)
#define Rep(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define REP(i, a, b) for (int i = (a)-1, i##end = (b); i >= i##end; --i)
typedef long long LL;
template <class T> IL bool chkmax(T &a, const T &b) {
return a < b ? ((a = b), 1) : 0;
}
template <class T> IL bool chkmin(T &a, const T &b) {
return a > b ? ((a = b), 1) : 0;
}
template <class T> IL T mymax(const T &a, const T &b) { return a > b ? a : b; }
template <class T> IL T mymin(const T &a, const T &b) { return a < b ? a : b; }
template <class T> IL T myabs(const T &a) { return a > 0 ? a : -a; }
const int INF = 0X3F3F3F3F;
const double EPS = 1E-8, PI = acos(-1.0);
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
#define SZ(x) ((int)(x).size())
namespace Math {
const int MOD = 998244353;
IL int add(int a, int b) {
a += b;
return a >= MOD ? a - MOD : a;
}
template <class... Args> IL int add(int a, const Args &...args) {
a += add(args...);
return a >= MOD ? a - MOD : a;
}
IL int sub(int a, int b) {
a -= b;
return a < 0 ? a + MOD : a;
}
IL int mul(int a, int b) { return (LL)a * b % MOD; }
template <class... Args> IL int mul(int a, const Args &...args) {
return (LL)a * mul(args...) % MOD;
}
IL int quickPow(int a, int p) {
int ret = 1;
for (; p; p >>= 1, a = mul(a, a)) {
if (p & 1) {
ret = mul(ret, a);
}
}
return ret;
}
} // namespace Math
using namespace Math;
const int MAXN = 400 + 5;
int h[MAXN], right[MAXN][MAXN], pref[MAXN][MAXN], binom[MAXN][MAXN],
power[MAXN], f[MAXN][MAXN][MAXN][2];
int solve(int l, int r, int h) {
if (pref[h][r] - pref[h][l - 1] < r - l + 1) {
std::array<std::array<int, 2>, MAXN> g;
For(i, 1, r - l + 1) { g[i][0] = g[i][1] = 0; }
g[0][0] = g[0][1] = 1;
int cur = 0;
For(i, l, r) {
if (::h[i] >= h && (i == l || ::h[i - 1] < h)) {
solve(i, right[h][i], h);
int cnt = right[h][i] - i + 1;
Rep(j, cur + cnt, 0) {
g[j][0] = mul(g[j][0], f[i][h][0][0]);
g[j][1] = mul(g[j][1], f[i][h][0][1]);
Rep(k, mymin(j, cnt), 1) {
g[j][0] = add(g[j][0], mul(g[j - k][0], f[i][h][k][0]));
g[j][1] = add(g[j][1], mul(g[j - k][1], f[i][h][k][1]));
}
}
cur += cnt;
}
}
For(i, 0, pref[h][r] - pref[h][l - 1]) {
f[l][h][i][0] = g[i][0];
f[l][h][i][1] = g[i][1];
}
return pref[h][r] - pref[h][l - 1];
}
int num = solve(l, r, h + 1), new_n = r - l + 1 - num;
For(i, 0, num) {
f[l][h][i][0] = add(f[l][h][i][0], f[l][h + 1][i][0]);
f[l][h][i][1] = add(f[l][h][i][1], f[l][h + 1][i][0]);
f[l][h][i][0] =
add(f[l][h][i][0], mul(f[l][h + 1][i][0], sub(power[i], 1)));
f[l][h][i + new_n][1] =
add(f[l][h][i + new_n][1],
mul(f[l][h + 1][i][1], sub(power[i + new_n], 1)));
int cnt = (r - l + 1) - i;
For(j, 1, cnt) {
f[l][h][i + j][0] = add(f[l][h][i + j][0],
mul(f[l][h + 1][i][0], binom[cnt][j], power[i]));
}
cnt -= new_n;
For(j, 1, cnt) {
f[l][h][i + j + new_n][1] =
add(f[l][h][i + j + new_n][1],
mul(f[l][h + 1][i][1], binom[cnt][j], power[i + new_n]));
}
}
return r - l + 1;
}
IL void init(int n) {
binom[0][0] = 1;
For(i, 1, n) {
binom[i][0] = 1;
For(j, 1, n) { binom[i][j] = add(binom[i - 1][j], binom[i - 1][j - 1]); }
}
power[0] = 1;
For(i, 1, n) { power[i] = add(power[i - 1], power[i - 1]); }
}
int main() {
#ifndef ONLINE_JUDGE
freopen("rook.in", "r", stdin);
#endif
int n;
scanf("%d", &n);
For(i, 1, n) { scanf("%d", &h[i]); }
For(i, 1, n) {
For(j, 1, n) { pref[i][j] = pref[i][j - 1] + (h[j] >= i); }
right[i][n + 1] = n;
Rep(j, n, 1) {
if (h[j] < i) {
right[i][j] = j - 1;
} else {
right[i][j] = right[i][j + 1];
}
}
}
init(n);
solve(1, n, 1);
printf("%d\n", f[1][1][n][1]);
return 0;
}
| #include <bits/stdc++.h>
#define IL __inline__ __attribute__((always_inline))
#define For(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define FOR(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++i)
#define Rep(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define REP(i, a, b) for (int i = (a)-1, i##end = (b); i >= i##end; --i)
typedef long long LL;
template <class T> IL bool chkmax(T &a, const T &b) {
return a < b ? ((a = b), 1) : 0;
}
template <class T> IL bool chkmin(T &a, const T &b) {
return a > b ? ((a = b), 1) : 0;
}
template <class T> IL T mymax(const T &a, const T &b) { return a > b ? a : b; }
template <class T> IL T mymin(const T &a, const T &b) { return a < b ? a : b; }
template <class T> IL T myabs(const T &a) { return a > 0 ? a : -a; }
const int INF = 0X3F3F3F3F;
const double EPS = 1E-8, PI = acos(-1.0);
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
#define SZ(x) ((int)(x).size())
namespace Math {
const int MOD = 998244353;
IL int add(int a, int b) {
a += b;
return a >= MOD ? a - MOD : a;
}
template <class... Args> IL int add(int a, const Args &...args) {
a += add(args...);
return a >= MOD ? a - MOD : a;
}
IL int sub(int a, int b) {
a -= b;
return a < 0 ? a + MOD : a;
}
IL int mul(int a, int b) { return (LL)a * b % MOD; }
template <class... Args> IL int mul(int a, const Args &...args) {
return (LL)a * mul(args...) % MOD;
}
IL int quickPow(int a, int p) {
int ret = 1;
for (; p; p >>= 1, a = mul(a, a)) {
if (p & 1) {
ret = mul(ret, a);
}
}
return ret;
}
} // namespace Math
using namespace Math;
const int MAXN = 400 + 5;
int h[MAXN], right[MAXN][MAXN], pref[MAXN][MAXN], binom[MAXN][MAXN],
power[MAXN], f[MAXN][MAXN][MAXN][2];
int solve(int l, int r, int h) {
if (pref[h][r] - pref[h][l - 1] < r - l + 1) {
std::array<std::array<int, 2>, MAXN> g;
For(i, 1, r - l + 1) { g[i][0] = g[i][1] = 0; }
g[0][0] = g[0][1] = 1;
int cur = 0;
For(i, l, r) {
if (::h[i] >= h && (i == l || ::h[i - 1] < h)) {
solve(i, right[h][i], h);
int cnt = right[h][i] - i + 1;
Rep(j, cur + cnt, 0) {
g[j][0] = mul(g[j][0], f[i][h][0][0]);
g[j][1] = mul(g[j][1], f[i][h][0][1]);
Rep(k, mymin(j, cnt), 1) {
g[j][0] = add(g[j][0], mul(g[j - k][0], f[i][h][k][0]));
g[j][1] = add(g[j][1], mul(g[j - k][1], f[i][h][k][1]));
}
}
cur += cnt;
}
}
For(i, 0, pref[h][r] - pref[h][l - 1]) {
f[l][h][i][0] = g[i][0];
f[l][h][i][1] = g[i][1];
}
return pref[h][r] - pref[h][l - 1];
}
int num = solve(l, r, h + 1), new_n = r - l + 1 - num;
For(i, 0, num) {
f[l][h][i][0] = add(f[l][h][i][0], f[l][h + 1][i][0]);
f[l][h][i][1] = add(f[l][h][i][1], f[l][h + 1][i][0]);
f[l][h][i][0] =
add(f[l][h][i][0], mul(f[l][h + 1][i][0], sub(power[i], 1)));
f[l][h][i + new_n][1] =
add(f[l][h][i + new_n][1],
mul(f[l][h + 1][i][1], sub(power[i + new_n], 1)));
int cnt = (r - l + 1) - i;
For(j, 1, cnt) {
f[l][h][i + j][0] = add(f[l][h][i + j][0],
mul(f[l][h + 1][i][0], binom[cnt][j], power[i]));
}
cnt -= new_n;
For(j, 1, cnt) {
f[l][h][i + j + new_n][1] =
add(f[l][h][i + j + new_n][1],
mul(f[l][h + 1][i][1], binom[cnt][j], power[i + new_n]));
}
}
return r - l + 1;
}
IL void init(int n) {
binom[0][0] = 1;
For(i, 1, n) {
binom[i][0] = 1;
For(j, 1, n) { binom[i][j] = add(binom[i - 1][j], binom[i - 1][j - 1]); }
}
power[0] = 1;
For(i, 1, n) { power[i] = add(power[i - 1], power[i - 1]); }
}
int main() {
int n;
scanf("%d", &n);
For(i, 1, n) { scanf("%d", &h[i]); }
For(i, 1, n) {
For(j, 1, n) { pref[i][j] = pref[i][j - 1] + (h[j] >= i); }
right[i][n + 1] = n;
Rep(j, n, 1) {
if (h[j] < i) {
right[i][j] = j - 1;
} else {
right[i][j] = right[i][j + 1];
}
}
}
init(n);
solve(1, n, 1);
printf("%d\n", f[1][1][n][1]);
return 0;
}
| delete | 136 | 139 | 136 | 136 | -11 | |
p02828 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define N 420
#define M 8200
const LL mod = 998244353;
LL n, ans, a[N], b[N][N], p[N][N], cnt, fa[M], sz[M], sz2[M], sum[M], C[N][N],
f[M][N], g[M][N], dp[N], pw[N];
void upd(LL &x, LL y) { x = (x + y % mod + mod) % mod; }
int main() {
scanf("%lld", &n);
pw[0] = 1;
for (LL i = 1; i <= n; ++i)
pw[i] = pw[i - 1] * 2 % mod;
for (LL i = 1; i <= n; ++i) {
scanf("%lld", a + i);
for (LL j = 1; j <= a[i]; ++j)
b[j][i] = 1;
}
for (LL i = 1; i <= n; ++i) {
for (LL j = 1; j <= n; ++j)
if (b[i][j]) {
if (!b[i][j - 1]) {
p[i][j] = ++cnt;
fa[cnt] = p[i - 1][j];
} else
p[i][j] = p[i][j - 1];
++sz[p[i][j]];
++sz2[fa[p[i][j]]];
}
}
for (LL i = 1; i <= cnt; ++i) {
sum[i] = sz[i] - sz2[i];
f[i][0] = 1;
g[i][0] = 1;
}
for (LL i = 0; i <= n; ++i) {
C[i][0] = 1;
for (LL j = 1; j <= i; ++j)
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
}
for (LL v = cnt; v; --v) {
memset(dp, 0, sizeof dp);
for (LL i = 0; i <= sz[v]; ++i) {
upd(dp[i], g[v][i] * (pw[sz[v] - i] - 1));
for (LL j = 1; j <= i; ++j)
upd(dp[i - j], g[v][i] * C[i][j] % mod * pw[sz[v] - i]);
}
memcpy(g[v], dp, sizeof g[v]);
memset(dp, 0, sizeof dp);
for (LL i = 0; i <= sz[v]; ++i) {
upd(g[v][sz[v] - i], f[v][i]);
for (LL j = 0; j <= sz[v] - i; ++j)
upd(dp[i + j], f[v][i] * C[sz[v] - i][j] % mod * pw[i]);
}
memcpy(f[v], dp, sizeof f[v]);
LL u = fa[v];
memset(dp, 0, sizeof dp);
for (LL i = 0; i <= sum[u]; ++i)
for (LL j = 0; j <= sz[v]; ++j) {
upd(dp[i + j], f[u][i] * f[v][j]);
}
sum[u] += sz[v];
memcpy(f[u], dp, sizeof f[u]);
memset(dp, 0, sizeof dp);
for (LL i = 0; i <= sum[u]; ++i)
for (LL j = 0; j <= sz[v]; ++j) {
upd(dp[i + j], g[u][i] * g[v][j]);
}
memcpy(g[u], dp, sizeof g[u]);
}
printf("%lld\n", g[1][0]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define N 420
#define M 82000
const LL mod = 998244353;
LL n, ans, a[N], b[N][N], p[N][N], cnt, fa[M], sz[M], sz2[M], sum[M], C[N][N],
f[M][N], g[M][N], dp[N], pw[N];
void upd(LL &x, LL y) { x = (x + y % mod + mod) % mod; }
int main() {
scanf("%lld", &n);
pw[0] = 1;
for (LL i = 1; i <= n; ++i)
pw[i] = pw[i - 1] * 2 % mod;
for (LL i = 1; i <= n; ++i) {
scanf("%lld", a + i);
for (LL j = 1; j <= a[i]; ++j)
b[j][i] = 1;
}
for (LL i = 1; i <= n; ++i) {
for (LL j = 1; j <= n; ++j)
if (b[i][j]) {
if (!b[i][j - 1]) {
p[i][j] = ++cnt;
fa[cnt] = p[i - 1][j];
} else
p[i][j] = p[i][j - 1];
++sz[p[i][j]];
++sz2[fa[p[i][j]]];
}
}
for (LL i = 1; i <= cnt; ++i) {
sum[i] = sz[i] - sz2[i];
f[i][0] = 1;
g[i][0] = 1;
}
for (LL i = 0; i <= n; ++i) {
C[i][0] = 1;
for (LL j = 1; j <= i; ++j)
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
}
for (LL v = cnt; v; --v) {
memset(dp, 0, sizeof dp);
for (LL i = 0; i <= sz[v]; ++i) {
upd(dp[i], g[v][i] * (pw[sz[v] - i] - 1));
for (LL j = 1; j <= i; ++j)
upd(dp[i - j], g[v][i] * C[i][j] % mod * pw[sz[v] - i]);
}
memcpy(g[v], dp, sizeof g[v]);
memset(dp, 0, sizeof dp);
for (LL i = 0; i <= sz[v]; ++i) {
upd(g[v][sz[v] - i], f[v][i]);
for (LL j = 0; j <= sz[v] - i; ++j)
upd(dp[i + j], f[v][i] * C[sz[v] - i][j] % mod * pw[i]);
}
memcpy(f[v], dp, sizeof f[v]);
LL u = fa[v];
memset(dp, 0, sizeof dp);
for (LL i = 0; i <= sum[u]; ++i)
for (LL j = 0; j <= sz[v]; ++j) {
upd(dp[i + j], f[u][i] * f[v][j]);
}
sum[u] += sz[v];
memcpy(f[u], dp, sizeof f[u]);
memset(dp, 0, sizeof dp);
for (LL i = 0; i <= sum[u]; ++i)
for (LL j = 0; j <= sz[v]; ++j) {
upd(dp[i + j], g[u][i] * g[v][j]);
}
memcpy(g[u], dp, sizeof g[u]);
}
printf("%lld\n", g[1][0]);
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02828 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb emplace_back
#define X first
#define Y second
const int N = 405;
const int S = N * N;
typedef pair<int, int> ii;
const int mod = 998244353;
void add(int &a, int b) {
a += b;
if (a >= mod)
a -= mod;
}
void sub(int &a, int b) {
a -= b;
if (a < 0)
a += mod;
}
int mul(int a, int b) { return 1ll * a * b % mod; }
int Pow(int a, int b) {
int ans = 1;
while (b) {
if (b & 1)
ans = mul(ans, a);
a = mul(a, a);
b >>= 1;
}
return ans;
}
int inv(int a, int p) { return a == 1 ? 1 : p - 1ll * p * inv(p % a, a) / a; }
int Fac[N];
int Inv[N];
int Ckn(int n, int k) {
if (n < k)
return 0;
if (k < 0)
return 0;
return mul(Fac[n], mul(Inv[k], Inv[n - k]));
}
int a[N];
ii R[N];
int F[S][N];
int G[S][N];
int tot = 0;
int cal(int l, int r, int h) {
vector<int> vec;
int p = l;
for (int i = l; i <= r; ++i)
if (a[i] == h) {
if (i > p)
vec.pb(cal(p, i - 1, h + 1));
p = i + 1;
}
if (r >= p)
vec.pb(cal(p, r, h + 1));
vector<int> f(1, 1);
vector<int> g(1, 1);
int len = 0;
for (int x : vec) {
int L = R[x].Y - R[x].X + 1;
vector<int> nf(len + L + 1, 0);
vector<int> ng(len + L + 1, 0);
for (int i = 0; i <= L; ++i)
for (int j = 0; j <= len; ++j)
add(nf[i + j], mul(f[j], F[x][i])), add(ng[i + j], mul(g[j], G[x][i]));
f.swap(nf);
g.swap(ng);
len += L;
}
int x = tot;
int L = r - l + 1;
vector<int> ng(L + 1);
for (int i = 0; i <= len; ++i)
ng[i + L - len] = g[i];
g.swap(ng);
f.resize(L + 1);
for (int i = 0; i <= L; ++i) {
add(F[x][i], g[i]);
add(G[x][i], mul(g[i], Pow(2, L - i)));
add(F[x][i], mul(f[i], Pow(2, L - i) - 1));
for (int j = 1; j <= i; ++j) {
int M = mul(Pow(2, L - i), Ckn(i, j));
add(G[x][i - j], mul(M, g[i]));
add(F[x][i - j], mul(M, f[i]));
}
}
R[x] = ii(l, r);
return tot++;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
Fac[0] = Inv[0] = 1;
for (int i = 1; i < N; ++i)
Fac[i] = mul(Fac[i - 1], i);
Inv[N - 1] = inv(Fac[N - 1], mod);
for (int i = N - 2; i; --i)
Inv[i] = mul(Inv[i + 1], i + 1);
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
cout << F[cal(1, n, 1)][0] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pb emplace_back
#define X first
#define Y second
const int N = 405;
const int S = N * N;
typedef pair<int, int> ii;
const int mod = 998244353;
void add(int &a, int b) {
a += b;
if (a >= mod)
a -= mod;
}
void sub(int &a, int b) {
a -= b;
if (a < 0)
a += mod;
}
int mul(int a, int b) { return 1ll * a * b % mod; }
int Pow(int a, int b) {
int ans = 1;
while (b) {
if (b & 1)
ans = mul(ans, a);
a = mul(a, a);
b >>= 1;
}
return ans;
}
int inv(int a, int p) { return a == 1 ? 1 : p - 1ll * p * inv(p % a, a) / a; }
int Fac[N];
int Inv[N];
int Ckn(int n, int k) {
if (n < k)
return 0;
if (k < 0)
return 0;
return mul(Fac[n], mul(Inv[k], Inv[n - k]));
}
int a[N];
ii R[S];
int F[S][N];
int G[S][N];
int tot = 0;
int cal(int l, int r, int h) {
vector<int> vec;
int p = l;
for (int i = l; i <= r; ++i)
if (a[i] == h) {
if (i > p)
vec.pb(cal(p, i - 1, h + 1));
p = i + 1;
}
if (r >= p)
vec.pb(cal(p, r, h + 1));
vector<int> f(1, 1);
vector<int> g(1, 1);
int len = 0;
for (int x : vec) {
int L = R[x].Y - R[x].X + 1;
vector<int> nf(len + L + 1, 0);
vector<int> ng(len + L + 1, 0);
for (int i = 0; i <= L; ++i)
for (int j = 0; j <= len; ++j)
add(nf[i + j], mul(f[j], F[x][i])), add(ng[i + j], mul(g[j], G[x][i]));
f.swap(nf);
g.swap(ng);
len += L;
}
int x = tot;
int L = r - l + 1;
vector<int> ng(L + 1);
for (int i = 0; i <= len; ++i)
ng[i + L - len] = g[i];
g.swap(ng);
f.resize(L + 1);
for (int i = 0; i <= L; ++i) {
add(F[x][i], g[i]);
add(G[x][i], mul(g[i], Pow(2, L - i)));
add(F[x][i], mul(f[i], Pow(2, L - i) - 1));
for (int j = 1; j <= i; ++j) {
int M = mul(Pow(2, L - i), Ckn(i, j));
add(G[x][i - j], mul(M, g[i]));
add(F[x][i - j], mul(M, f[i]));
}
}
R[x] = ii(l, r);
return tot++;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
Fac[0] = Inv[0] = 1;
for (int i = 1; i < N; ++i)
Fac[i] = mul(Fac[i - 1], i);
Inv[N - 1] = inv(Fac[N - 1], mod);
for (int i = N - 2; i; --i)
Inv[i] = mul(Inv[i + 1], i + 1);
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i];
cout << F[cal(1, n, 1)][0] << endl;
} | replace | 57 | 58 | 57 | 58 | -11 | |
p02828 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <int MOD_> struct modnum {
static constexpr int MOD = MOD_;
static_assert(MOD_ > 0, "MOD must be positive");
private:
using ll = long long;
int v;
static int minv(int a, int m) {
a %= m;
assert(a);
return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
}
public:
modnum() : v(0) {}
modnum(ll v_) : v(int(v_ % MOD)) {
if (v < 0)
v += MOD;
}
explicit operator int() const { return v; }
friend std::ostream &operator<<(std::ostream &out, const modnum &n) {
return out << int(n);
}
friend std::istream &operator>>(std::istream &in, modnum &n) {
ll v_;
in >> v_;
n = modnum(v_);
return in;
}
friend bool operator==(const modnum &a, const modnum &b) {
return a.v == b.v;
}
friend bool operator!=(const modnum &a, const modnum &b) {
return a.v != b.v;
}
modnum inv() const {
modnum res;
res.v = minv(v, MOD);
return res;
}
friend modnum inv(const modnum &m) { return m.inv(); }
modnum neg() const {
modnum res;
res.v = v ? MOD - v : 0;
return res;
}
friend modnum neg(const modnum &m) { return m.neg(); }
modnum operator-() const { return neg(); }
modnum operator+() const { return modnum(*this); }
modnum &operator++() {
v++;
if (v == MOD)
v = 0;
return *this;
}
modnum &operator--() {
if (v == 0)
v = MOD;
v--;
return *this;
}
modnum &operator+=(const modnum &o) {
v += o.v;
if (v >= MOD)
v -= MOD;
return *this;
}
modnum &operator-=(const modnum &o) {
v -= o.v;
if (v < 0)
v += MOD;
return *this;
}
modnum &operator*=(const modnum &o) {
v = int(ll(v) * ll(o.v) % MOD);
return *this;
}
modnum &operator/=(const modnum &o) { return *this *= o.inv(); }
friend modnum operator++(modnum &a, int) {
modnum r = a;
++a;
return r;
}
friend modnum operator--(modnum &a, int) {
modnum r = a;
--a;
return r;
}
friend modnum operator+(const modnum &a, const modnum &b) {
return modnum(a) += b;
}
friend modnum operator-(const modnum &a, const modnum &b) {
return modnum(a) -= b;
}
friend modnum operator*(const modnum &a, const modnum &b) {
return modnum(a) *= b;
}
friend modnum operator/(const modnum &a, const modnum &b) {
return modnum(a) /= b;
}
};
template <typename T> T pow(T a, long long b) {
assert(b >= 0);
T r = 1;
while (b) {
if (b & 1)
r *= a;
b >>= 1;
a *= a;
}
return r;
}
using num = modnum<998244353>;
void test2() {
int ans = 0;
for (int mr = 0; mr < 4; mr++) {
for (int mc = 0; mc < 4; mc++) {
for (int a = 0; a < 4; a++) {
for (int b = 0; b < 4; b++) {
if ((a & mr) == a && (b & mc) == b) {
if ((a && b) == false) {
int sgn = __builtin_popcount(mc) + __builtin_popcount(mr) +
__builtin_popcount(a) + __builtin_popcount(b);
int p2 =
(2 - __builtin_popcount(mc)) * (2 - __builtin_popcount(mr));
if (sgn & 1)
ans -= (1 << p2);
else
ans += (1 << p2);
}
}
}
}
}
}
cerr << ans << '\n';
assert(ans == 11);
}
const int MAXN = 400;
int N;
int H[MAXN];
num fact[MAXN];
num ifact[MAXN];
num p2[MAXN * MAXN];
void precomp() {
fact[0] = 1;
for (int i = 1; i <= N; i++)
fact[i] = fact[i - 1] * num(i);
ifact[N] = inv(fact[N]);
for (int i = N; i >= 1; i--)
ifact[i - 1] = ifact[i] * num(i);
p2[0] = 1;
for (int i = 1; i <= N * N; i++)
p2[i] = p2[i - 1] + p2[i - 1];
}
int pneg1(int n) { return (n & 1) ? -1 : 1; }
num binom(int n, int r) {
assert(0 <= r && r <= n);
return fact[n] * ifact[n - r] * ifact[r];
}
vector<pair<num, num>> dp(int l, int r, int h) {
if (l > r) {
return vector<pair<num, num>>(h + 1, pair<num, num>(1, 1));
}
int m = int(min_element(H + l, H + r + 1) - H);
// cerr << l << ' ' << r << ' ' << h << ' ' << m << '\n';
auto v1 = dp(l, m - 1, H[m]);
auto v2 = dp(m + 1, r, H[m]);
for (int i = 0; i <= H[m]; i++) {
v1[i].first *= v2[i].first;
v1[i].second *= v2[i].second;
v1[i].first *= (p2[H[m] - i] + num(-1) + num(1));
v1[i].second *= (p2[H[m] - i] + num(-1));
}
v2 = {};
int dh = H[m] - h;
vector<pair<num, num>> res(h + 1);
for (int i = 0; i <= h; i++) {
for (int j = i; j <= i + dh; j++) {
res[i].first += binom(dh, j - i) * pneg1(j - i) *
(v1[j].first - (j == i ? 0 : v1[j].second));
res[i].second +=
binom(dh, j - i) * pneg1(j - i) * (j == i ? v1[j].second : 0);
}
}
return res;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> H[i];
}
precomp();
auto res = dp(0, N - 1, 0);
cout << res[0].first << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template <int MOD_> struct modnum {
static constexpr int MOD = MOD_;
static_assert(MOD_ > 0, "MOD must be positive");
private:
using ll = long long;
int v;
static int minv(int a, int m) {
a %= m;
assert(a);
return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
}
public:
modnum() : v(0) {}
modnum(ll v_) : v(int(v_ % MOD)) {
if (v < 0)
v += MOD;
}
explicit operator int() const { return v; }
friend std::ostream &operator<<(std::ostream &out, const modnum &n) {
return out << int(n);
}
friend std::istream &operator>>(std::istream &in, modnum &n) {
ll v_;
in >> v_;
n = modnum(v_);
return in;
}
friend bool operator==(const modnum &a, const modnum &b) {
return a.v == b.v;
}
friend bool operator!=(const modnum &a, const modnum &b) {
return a.v != b.v;
}
modnum inv() const {
modnum res;
res.v = minv(v, MOD);
return res;
}
friend modnum inv(const modnum &m) { return m.inv(); }
modnum neg() const {
modnum res;
res.v = v ? MOD - v : 0;
return res;
}
friend modnum neg(const modnum &m) { return m.neg(); }
modnum operator-() const { return neg(); }
modnum operator+() const { return modnum(*this); }
modnum &operator++() {
v++;
if (v == MOD)
v = 0;
return *this;
}
modnum &operator--() {
if (v == 0)
v = MOD;
v--;
return *this;
}
modnum &operator+=(const modnum &o) {
v += o.v;
if (v >= MOD)
v -= MOD;
return *this;
}
modnum &operator-=(const modnum &o) {
v -= o.v;
if (v < 0)
v += MOD;
return *this;
}
modnum &operator*=(const modnum &o) {
v = int(ll(v) * ll(o.v) % MOD);
return *this;
}
modnum &operator/=(const modnum &o) { return *this *= o.inv(); }
friend modnum operator++(modnum &a, int) {
modnum r = a;
++a;
return r;
}
friend modnum operator--(modnum &a, int) {
modnum r = a;
--a;
return r;
}
friend modnum operator+(const modnum &a, const modnum &b) {
return modnum(a) += b;
}
friend modnum operator-(const modnum &a, const modnum &b) {
return modnum(a) -= b;
}
friend modnum operator*(const modnum &a, const modnum &b) {
return modnum(a) *= b;
}
friend modnum operator/(const modnum &a, const modnum &b) {
return modnum(a) /= b;
}
};
template <typename T> T pow(T a, long long b) {
assert(b >= 0);
T r = 1;
while (b) {
if (b & 1)
r *= a;
b >>= 1;
a *= a;
}
return r;
}
using num = modnum<998244353>;
void test2() {
int ans = 0;
for (int mr = 0; mr < 4; mr++) {
for (int mc = 0; mc < 4; mc++) {
for (int a = 0; a < 4; a++) {
for (int b = 0; b < 4; b++) {
if ((a & mr) == a && (b & mc) == b) {
if ((a && b) == false) {
int sgn = __builtin_popcount(mc) + __builtin_popcount(mr) +
__builtin_popcount(a) + __builtin_popcount(b);
int p2 =
(2 - __builtin_popcount(mc)) * (2 - __builtin_popcount(mr));
if (sgn & 1)
ans -= (1 << p2);
else
ans += (1 << p2);
}
}
}
}
}
}
cerr << ans << '\n';
assert(ans == 11);
}
const int MAXN = 410;
int N;
int H[MAXN];
num fact[MAXN];
num ifact[MAXN];
num p2[MAXN * MAXN];
void precomp() {
fact[0] = 1;
for (int i = 1; i <= N; i++)
fact[i] = fact[i - 1] * num(i);
ifact[N] = inv(fact[N]);
for (int i = N; i >= 1; i--)
ifact[i - 1] = ifact[i] * num(i);
p2[0] = 1;
for (int i = 1; i <= N * N; i++)
p2[i] = p2[i - 1] + p2[i - 1];
}
int pneg1(int n) { return (n & 1) ? -1 : 1; }
num binom(int n, int r) {
assert(0 <= r && r <= n);
return fact[n] * ifact[n - r] * ifact[r];
}
vector<pair<num, num>> dp(int l, int r, int h) {
if (l > r) {
return vector<pair<num, num>>(h + 1, pair<num, num>(1, 1));
}
int m = int(min_element(H + l, H + r + 1) - H);
// cerr << l << ' ' << r << ' ' << h << ' ' << m << '\n';
auto v1 = dp(l, m - 1, H[m]);
auto v2 = dp(m + 1, r, H[m]);
for (int i = 0; i <= H[m]; i++) {
v1[i].first *= v2[i].first;
v1[i].second *= v2[i].second;
v1[i].first *= (p2[H[m] - i] + num(-1) + num(1));
v1[i].second *= (p2[H[m] - i] + num(-1));
}
v2 = {};
int dh = H[m] - h;
vector<pair<num, num>> res(h + 1);
for (int i = 0; i <= h; i++) {
for (int j = i; j <= i + dh; j++) {
res[i].first += binom(dh, j - i) * pneg1(j - i) *
(v1[j].first - (j == i ? 0 : v1[j].second));
res[i].second +=
binom(dh, j - i) * pneg1(j - i) * (j == i ? v1[j].second : 0);
}
}
return res;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
cin >> H[i];
}
precomp();
auto res = dp(0, N - 1, 0);
cout << res[0].first << '\n';
return 0;
}
| replace | 151 | 152 | 151 | 152 | 0 | |
p02828 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
const int MAXN = 405;
const ll MOD = 998244353;
int n, id;
int h[MAXN];
ll a[MAXN];
ll b[MAXN];
ll C[MAXN][MAXN];
ll pw2[MAXN];
ll f[MAXN << 1][2][MAXN];
queue<int> Q;
int newnode() {
int res = 0;
if (!Q.empty()) {
res = Q.front();
Q.pop();
} else
res = ++id;
memset(f[res], 0, sizeof(f[res]));
return res;
}
int solve(int l, int r, int d) {
int x = newnode();
if (l > r) {
f[x][0][0] = f[x][1][0] = 1;
return x;
}
for (int i = l; i <= r; i++)
if (h[i] < d) {
int u = solve(l, i - 1, d), v = solve(i + 1, r, d);
for (int j = 0; j <= i - l; j++)
for (int k = 0; k <= r - i; k++) {
(f[x][0][j + k] += f[u][0][j] * f[v][0][k]) %= MOD;
(f[x][1][j + k + 1] += f[u][1][j] * f[v][1][k]) %= MOD;
}
Q.push(u);
Q.push(v);
return x;
}
int u = solve(l, r, d + 1);
for (int j = 0; j <= r - l + 1; j++) {
(f[x][0][j] += f[u][1][j]) %= MOD;
(f[x][1][j] += f[u][1][j]) %= MOD;
}
for (int j = 0; j <= r - l + 1; j++) {
(f[x][0][j] += f[u][0][j] * (pw2[r - l + 1 - j] - 1)) %= MOD;
(f[x][1][j] += f[u][1][j] * (pw2[r - l + 1 - j] - 1)) %= MOD;
}
for (int j = 1; j <= r - l + 1; j++)
for (int k = 1; k <= j; k++) {
(f[x][0][j - k] += f[u][0][j] * C[j][k] % MOD * pw2[r - l + 1 - j]) %=
MOD;
(f[x][1][j - k] += f[u][1][j] * C[j][k] % MOD * pw2[r - l + 1 - j]) %=
MOD;
}
Q.push(u);
return x;
}
int main() {
scanf("%d", &n);
pw2[0] = 1;
for (int i = 1; i <= n; i++)
pw2[i] = pw2[i - 1] * 2 % MOD;
for (int i = 0; i <= n; i++) {
C[i][0] = 1;
for (int j = 1; j <= i; j++)
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
}
for (int i = 1; i <= n; i++)
scanf("%d", &h[i]);
solve(1, n, 1);
printf("%lld\n", f[1][0][0]);
return 0;
} | #include <algorithm>
#include <bitset>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <vector>
using namespace std;
typedef long long ll;
const int MAXN = 405;
const ll MOD = 998244353;
int n, id;
int h[MAXN];
ll a[MAXN];
ll b[MAXN];
ll C[MAXN][MAXN];
ll pw2[MAXN];
ll f[MAXN << 2][2][MAXN];
queue<int> Q;
int newnode() {
int res = 0;
if (!Q.empty()) {
res = Q.front();
Q.pop();
} else
res = ++id;
memset(f[res], 0, sizeof(f[res]));
return res;
}
int solve(int l, int r, int d) {
int x = newnode();
if (l > r) {
f[x][0][0] = f[x][1][0] = 1;
return x;
}
for (int i = l; i <= r; i++)
if (h[i] < d) {
int u = solve(l, i - 1, d), v = solve(i + 1, r, d);
for (int j = 0; j <= i - l; j++)
for (int k = 0; k <= r - i; k++) {
(f[x][0][j + k] += f[u][0][j] * f[v][0][k]) %= MOD;
(f[x][1][j + k + 1] += f[u][1][j] * f[v][1][k]) %= MOD;
}
Q.push(u);
Q.push(v);
return x;
}
int u = solve(l, r, d + 1);
for (int j = 0; j <= r - l + 1; j++) {
(f[x][0][j] += f[u][1][j]) %= MOD;
(f[x][1][j] += f[u][1][j]) %= MOD;
}
for (int j = 0; j <= r - l + 1; j++) {
(f[x][0][j] += f[u][0][j] * (pw2[r - l + 1 - j] - 1)) %= MOD;
(f[x][1][j] += f[u][1][j] * (pw2[r - l + 1 - j] - 1)) %= MOD;
}
for (int j = 1; j <= r - l + 1; j++)
for (int k = 1; k <= j; k++) {
(f[x][0][j - k] += f[u][0][j] * C[j][k] % MOD * pw2[r - l + 1 - j]) %=
MOD;
(f[x][1][j - k] += f[u][1][j] * C[j][k] % MOD * pw2[r - l + 1 - j]) %=
MOD;
}
Q.push(u);
return x;
}
int main() {
scanf("%d", &n);
pw2[0] = 1;
for (int i = 1; i <= n; i++)
pw2[i] = pw2[i - 1] * 2 % MOD;
for (int i = 0; i <= n; i++) {
C[i][0] = 1;
for (int j = 1; j <= i; j++)
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
}
for (int i = 1; i <= n; i++)
scanf("%d", &h[i]);
solve(1, n, 1);
printf("%lld\n", f[1][0][0]);
return 0;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p02828 | C++ | Runtime Error | #include <cstdio>
#define N 403
#define mod 998244353
using namespace std;
long long newf[N], f[N][N][N], g[N][N][N], C[N][N], th2[N];
int a[N], n;
void dfs(int l, int r, int h) {
// g[l][h][0]=1;f[l][h][0]=1;
int start = 0;
bool bo = false;
for (int i = l; i <= r; i++) {
if (a[i - 1] <= h && a[i] > h && start == 0)
start = i;
if (a[i] <= h) {
if (start != 0) {
bo = true;
dfs(start, i - 1, h + 1);
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int j = (r - l + 1); j >= 0; j--) {
int sp = f[l][h][j];
if (j == 0)
sp = 1;
if (sp == 0)
continue;
for (int k = 0; k <= (i - start); k++)
newf[j + k] = (newf[j + k] + sp * f[start][h + 1][k] % mod) % mod;
}
for (int i = (r - l + 1); i >= 0; i--)
f[l][h][i] = newf[i];
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int j = (r - l + 1); j >= 0; j--) {
int sp = g[l][h][j];
if (j == 0)
sp = 1;
if (sp == 0)
continue;
for (int k = 0; k <= (i - start); k++)
newf[j + k] = (newf[j + k] + sp * g[start][h + 1][k] % mod) % mod;
}
for (int i = (r - l + 1); i >= 0; i--)
g[l][h][i] = newf[i];
}
start = 0;
}
}
if (start > 0) {
bo = true;
dfs(start, r, h + 1);
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int j = (r - l + 1); j >= 0; j--) {
int sp = f[l][h][j];
if (j == 0)
sp = 1;
if (sp == 0)
continue;
for (int k = 0; k <= (r - l + 1); k++)
newf[j + k] = (newf[j + k] + sp * f[start][h + 1][k] % mod) % mod;
}
for (int i = (r - l + 1); i >= 0; i--)
f[l][h][i] = newf[i];
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int j = (r - l + 1); j >= 0; j--) {
int sp = g[l][h][j];
if (j == 0)
sp = 1;
if (sp == 0)
continue;
for (int k = 0; k <= (r - l + 1); k++)
newf[j + k] = (newf[j + k] + sp * g[start][h + 1][k] % mod) % mod;
}
for (int i = (r - l + 1); i >= 0; i--)
g[l][h][i] = newf[i];
}
int num = 0;
for (int i = l; i <= r; i++)
if (a[i] == h)
num++;
if (!bo) {
f[l][h][num] = th2[num] - 1;
for (int i = 0; i <= r - l + 1; i++)
g[l][h][i] = C[num][i];
f[l][h][0] = g[l][h][0];
return;
}
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int i = (r - l + 1); i >= 0; i--) {
if (f[l][h][i] == 0)
continue;
int slen = (r - l + 1) - i - num;
for (int j = 0; j <= slen; j++) {
if (j == 0)
newf[i + j + num] = (newf[i + j + num] + f[l][h][i] * C[slen][j] % mod *
(th2[i + num] - 1) % mod) %
mod;
else
newf[i + j + num] = (newf[i + j + num] + f[l][h][i] * C[slen][j] % mod *
th2[i + num] % mod) %
mod;
}
}
for (int i = (r - l + 1); i >= 0; i--)
f[l][h][i] = newf[i];
for (int i = 0; i <= (r - l + 1); i++)
f[l][h][i] = (f[l][h][i] + g[l][h][i]) % mod;
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int i = 0; i <= (r - l + 1); i++) {
if (g[l][h][i] == 0)
continue;
int slen = (r - l + 1) - i;
for (int j = 0; j <= slen; j++)
newf[i + j] =
(newf[i + j] + g[l][h][i] * C[slen][j] % mod * th2[i] % mod) % mod;
}
for (int i = (r - l + 1); i >= 0; i--)
g[l][h][i] = newf[i];
}
int main() {
scanf("%d", &n);
C[0][0] = 1;
for (int i = 1; i <= n; i++) {
C[i][0] = 1;
for (int j = 1; j <= i; j++)
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
}
th2[0] = 1;
for (int i = 1; i <= n; i++)
th2[i] = th2[i - 1] * 2 % mod;
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
// num=0;
dfs(1, n, 1);
printf("%lld\n", f[1][1][n]);
} | #include <cstdio>
#define N 405
#define mod 998244353
using namespace std;
long long newf[N], f[N][N][N], g[N][N][N], C[N][N], th2[N];
int a[N], n;
void dfs(int l, int r, int h) {
// g[l][h][0]=1;f[l][h][0]=1;
int start = 0;
bool bo = false;
for (int i = l; i <= r; i++) {
if (a[i - 1] <= h && a[i] > h && start == 0)
start = i;
if (a[i] <= h) {
if (start != 0) {
bo = true;
dfs(start, i - 1, h + 1);
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int j = (r - l + 1); j >= 0; j--) {
int sp = f[l][h][j];
if (j == 0)
sp = 1;
if (sp == 0)
continue;
for (int k = 0; k <= (i - start); k++)
newf[j + k] = (newf[j + k] + sp * f[start][h + 1][k] % mod) % mod;
}
for (int i = (r - l + 1); i >= 0; i--)
f[l][h][i] = newf[i];
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int j = (r - l + 1); j >= 0; j--) {
int sp = g[l][h][j];
if (j == 0)
sp = 1;
if (sp == 0)
continue;
for (int k = 0; k <= (i - start); k++)
newf[j + k] = (newf[j + k] + sp * g[start][h + 1][k] % mod) % mod;
}
for (int i = (r - l + 1); i >= 0; i--)
g[l][h][i] = newf[i];
}
start = 0;
}
}
if (start > 0) {
bo = true;
dfs(start, r, h + 1);
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int j = (r - l + 1); j >= 0; j--) {
int sp = f[l][h][j];
if (j == 0)
sp = 1;
if (sp == 0)
continue;
for (int k = 0; k <= (r - l + 1); k++)
newf[j + k] = (newf[j + k] + sp * f[start][h + 1][k] % mod) % mod;
}
for (int i = (r - l + 1); i >= 0; i--)
f[l][h][i] = newf[i];
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int j = (r - l + 1); j >= 0; j--) {
int sp = g[l][h][j];
if (j == 0)
sp = 1;
if (sp == 0)
continue;
for (int k = 0; k <= (r - l + 1); k++)
newf[j + k] = (newf[j + k] + sp * g[start][h + 1][k] % mod) % mod;
}
for (int i = (r - l + 1); i >= 0; i--)
g[l][h][i] = newf[i];
}
int num = 0;
for (int i = l; i <= r; i++)
if (a[i] == h)
num++;
if (!bo) {
f[l][h][num] = th2[num] - 1;
for (int i = 0; i <= r - l + 1; i++)
g[l][h][i] = C[num][i];
f[l][h][0] = g[l][h][0];
return;
}
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int i = (r - l + 1); i >= 0; i--) {
if (f[l][h][i] == 0)
continue;
int slen = (r - l + 1) - i - num;
for (int j = 0; j <= slen; j++) {
if (j == 0)
newf[i + j + num] = (newf[i + j + num] + f[l][h][i] * C[slen][j] % mod *
(th2[i + num] - 1) % mod) %
mod;
else
newf[i + j + num] = (newf[i + j + num] + f[l][h][i] * C[slen][j] % mod *
th2[i + num] % mod) %
mod;
}
}
for (int i = (r - l + 1); i >= 0; i--)
f[l][h][i] = newf[i];
for (int i = 0; i <= (r - l + 1); i++)
f[l][h][i] = (f[l][h][i] + g[l][h][i]) % mod;
for (int i = 0; i <= (r - l + 1); i++)
newf[i] = 0;
for (int i = 0; i <= (r - l + 1); i++) {
if (g[l][h][i] == 0)
continue;
int slen = (r - l + 1) - i;
for (int j = 0; j <= slen; j++)
newf[i + j] =
(newf[i + j] + g[l][h][i] * C[slen][j] % mod * th2[i] % mod) % mod;
}
for (int i = (r - l + 1); i >= 0; i--)
g[l][h][i] = newf[i];
}
int main() {
scanf("%d", &n);
C[0][0] = 1;
for (int i = 1; i <= n; i++) {
C[i][0] = 1;
for (int j = 1; j <= i; j++)
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
}
th2[0] = 1;
for (int i = 1; i <= n; i++)
th2[i] = th2[i - 1] * 2 % mod;
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
// num=0;
dfs(1, n, 1);
printf("%lld\n", f[1][1][n]);
} | replace | 1 | 2 | 1 | 2 | -11 | |
p02829 | Python | Runtime Error | a, b = map(int, input().split())
print(6 - a - b)
| a = int(input())
b = int(input())
print(6 - a - b)
| replace | 0 | 1 | 0 | 2 | ValueError: not enough values to unpack (expected 2, got 1) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02829/Python/s060375473.py", line 1, in <module>
a, b = map(int, input().split())
ValueError: not enough values to unpack (expected 2, got 1)
|
p02829 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 1e6 + 9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf = 1e14;
ll mod = 1e9 + 7;
ll powm(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t = 1;
// cin>>t;
while (t--) {
ll a, b;
cin >> a >> b;
ll x = 1 ^ 2 ^ 3;
cout << (x ^ a ^ b);
}
} | #include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 1e6 + 9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf = 1e14;
ll mod = 1e9 + 7;
ll powm(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin>>t;
while (t--) {
ll a, b;
cin >> a >> b;
ll x = 1 ^ 2 ^ 3;
cout << (x ^ a ^ b);
}
} | delete | 24 | 28 | 24 | 24 | 0 | |
p02829 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define emp emplace
#define ins insert
#define mp make_pair
#define mt make_tuple
#define sz(s) (int)s.size()
#define forp(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define ren(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, a, b) for (int i = a; i >= b; i--)
#define w(t) while (t)
#define sc(a) scanf("%d", &a);
#define on cout << "\n"
#define os cout << " "
#define o2(a, b) cout << a << " " << b
#define o(a) cout << a
#define ppr(a) cout << a.first << " " << a.second
#define bitcount __builtin_popcount
#define gcd __gcd
#define all(v) v.begin(), v.end()
#define mem(n, m) memset(n, m, sizeof(n))
#define pii pair<int, int>
#define tiii tuple<int, int, int>
#define pll pair<long long, long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ret return
#define present(s, x) (s.find(x) != s.end())
#define cpresent(s, x) (find(all(s), x) != s.end())
#define ford(container, it) \
for (auto it = container.begin(); it != container.end(); it++)
#define fors(container, it, a, b) for (auto it = a; it != b; it++)
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define MOD 1000000007
#define EPSILON 1e-9
#define PI acos(-1)
#define inf 1e9
#define int long long
#define debug(a) \
cerr << #a << ": "; \
for (auto i : a) \
cerr << i << " "; \
cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
typedef long long ll;
typedef long double ldo;
typedef double db;
using namespace std;
auto start = std::chrono::system_clock::now();
inline void skj() {
std::chrono::time_point<std::chrono::system_clock> end;
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
std::time_t end_time = std::chrono::system_clock::to_time_t(end);
cerr << "Time taken " << elapsed_seconds.count() * 1000 << "\n";
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// uniform_int_distribution<int> ud(1, 100); use this for random number
// generator
// custom hash for unordered map
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
inline int binexp(int a, int b, int m) {
if (a == 0) {
ret 0;
}
int res = 1;
a %= m;
while (b) {
if (b & 1)
res = (res * 1ll * a) % m;
a = (a * 1ll * a) % m;
b >>= 1;
}
return res;
}
inline void solve_me_senpai() {
int a, b;
cin >> a >> b;
sii s;
rep(i, 3) s.ins(i + 1);
s.erase(a);
s.erase(b);
o(*s.begin());
}
signed main() {
boost
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
int a = 1;
while (t--) {
// cout << "Case #" << a << ": ";
solve_me_senpai();
a++;
}
// skj();
return 0;
} | #include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define emp emplace
#define ins insert
#define mp make_pair
#define mt make_tuple
#define sz(s) (int)s.size()
#define forp(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define ren(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, a, b) for (int i = a; i >= b; i--)
#define w(t) while (t)
#define sc(a) scanf("%d", &a);
#define on cout << "\n"
#define os cout << " "
#define o2(a, b) cout << a << " " << b
#define o(a) cout << a
#define ppr(a) cout << a.first << " " << a.second
#define bitcount __builtin_popcount
#define gcd __gcd
#define all(v) v.begin(), v.end()
#define mem(n, m) memset(n, m, sizeof(n))
#define pii pair<int, int>
#define tiii tuple<int, int, int>
#define pll pair<long long, long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ret return
#define present(s, x) (s.find(x) != s.end())
#define cpresent(s, x) (find(all(s), x) != s.end())
#define ford(container, it) \
for (auto it = container.begin(); it != container.end(); it++)
#define fors(container, it, a, b) for (auto it = a; it != b; it++)
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define MOD 1000000007
#define EPSILON 1e-9
#define PI acos(-1)
#define inf 1e9
#define int long long
#define debug(a) \
cerr << #a << ": "; \
for (auto i : a) \
cerr << i << " "; \
cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
typedef long long ll;
typedef long double ldo;
typedef double db;
using namespace std;
auto start = std::chrono::system_clock::now();
inline void skj() {
std::chrono::time_point<std::chrono::system_clock> end;
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
std::time_t end_time = std::chrono::system_clock::to_time_t(end);
cerr << "Time taken " << elapsed_seconds.count() * 1000 << "\n";
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// uniform_int_distribution<int> ud(1, 100); use this for random number
// generator
// custom hash for unordered map
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
inline int binexp(int a, int b, int m) {
if (a == 0) {
ret 0;
}
int res = 1;
a %= m;
while (b) {
if (b & 1)
res = (res * 1ll * a) % m;
a = (a * 1ll * a) % m;
b >>= 1;
}
return res;
}
inline void solve_me_senpai() {
int a, b;
cin >> a >> b;
sii s;
rep(i, 3) s.ins(i + 1);
s.erase(a);
s.erase(b);
o(*s.begin());
}
signed main() {
boost
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t = 1;
// cin >> t;
int a = 1;
while (t--) {
// cout << "Case #" << a << ": ";
solve_me_senpai();
a++;
}
// skj();
return 0;
} | replace | 120 | 125 | 120 | 125 | 0 | |
p02829 | C++ | Runtime Error | /*
साहिल पे पहुंचने से इनकार किसे है लेकिन,
तूफ़ानो से लड़ने का मज़ा ही कुछ और है,
कहते है, कि किस्मत खुदा लिखता है लेकिन,
उसे मिटा के खुद गढ़ने का मजा ही कुछ और है।
*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define ull unsigned int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define S(arr) sort(arr.begin(), arr.end());
#define RS(arr) sort(arr.rbegin(), arr.rend());
#define R(arr) reverse(arr.begin(), arr.end());
#define si set<int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define pii pair<int, int>
#define vpi vector<pii>
#define vpp vector<pair<int, pii>>
#define mii map<int, int>
#define mci map<char, int>
#define mpi map<pii, int>
#define spi set<pii>
#define speed \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define all(p) p.begin(), p.end()
#define T \
int tcf; \
cin >> tcf; \
while (tcf--)
#define que_max(t) priority_queue<t>
#define que_min(t) priority_queue<t, vector<t>, greater<t>>
#define debuga(a, l, r) \
for (auto x : a) \
cout << x << " "; \
cout << endl;
#define debug1(x) cout << #x " = " << x << endl;
#define debug2(x, y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define debug3(x, y, z) \
cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define debug4(x, y, z, w) \
cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " \
<< #w " = " << w << endl;
#define debug5(x, y, z, w, v) \
cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " \
<< #w " = " << w << " " << #v " = " << v << endl;
#define debug6(x, y, z, w, v, a) debug3(a, y, x) debug3(w, v, a)
#define p2d(v) \
for (auto a : v) { \
for (auto b : a) \
cout << b << " "; \
cout << endl; \
}
#define p1d(v) \
for (auto a : v) \
cout << a << " "; \
cout << endl;
#define ppi(v) \
for (auto a : v) \
cout << a.ff << " " << a.ss << endl;
void read(int n = 10) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << setprecision(n) << fixed;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int M = 1e9 + 7;
int M1 = 998244353;
#define qqq 4000005
int32_t main() {
read();
int a, b;
cin >> a >> b;
cout << 6 - a - b;
} | /*
साहिल पे पहुंचने से इनकार किसे है लेकिन,
तूफ़ानो से लड़ने का मज़ा ही कुछ और है,
कहते है, कि किस्मत खुदा लिखता है लेकिन,
उसे मिटा के खुद गढ़ने का मजा ही कुछ और है।
*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define ull unsigned int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define S(arr) sort(arr.begin(), arr.end());
#define RS(arr) sort(arr.rbegin(), arr.rend());
#define R(arr) reverse(arr.begin(), arr.end());
#define si set<int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define pii pair<int, int>
#define vpi vector<pii>
#define vpp vector<pair<int, pii>>
#define mii map<int, int>
#define mci map<char, int>
#define mpi map<pii, int>
#define spi set<pii>
#define speed \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define all(p) p.begin(), p.end()
#define T \
int tcf; \
cin >> tcf; \
while (tcf--)
#define que_max(t) priority_queue<t>
#define que_min(t) priority_queue<t, vector<t>, greater<t>>
#define debuga(a, l, r) \
for (auto x : a) \
cout << x << " "; \
cout << endl;
#define debug1(x) cout << #x " = " << x << endl;
#define debug2(x, y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define debug3(x, y, z) \
cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define debug4(x, y, z, w) \
cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " \
<< #w " = " << w << endl;
#define debug5(x, y, z, w, v) \
cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " \
<< #w " = " << w << " " << #v " = " << v << endl;
#define debug6(x, y, z, w, v, a) debug3(a, y, x) debug3(w, v, a)
#define p2d(v) \
for (auto a : v) { \
for (auto b : a) \
cout << b << " "; \
cout << endl; \
}
#define p1d(v) \
for (auto a : v) \
cout << a << " "; \
cout << endl;
#define ppi(v) \
for (auto a : v) \
cout << a.ff << " " << a.ss << endl;
void read(int n = 10) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << setprecision(n) << fixed;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int M = 1e9 + 7;
int M1 = 998244353;
#define qqq 4000005
int32_t main() {
// read();
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a, b;
cin >> a >> b;
cout << 6 - a - b;
} | replace | 92 | 93 | 92 | 97 | 0 | |
p02829 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
typedef long long ll;
int main() {
int a, b;
cin >> a >> b;
for (int i = 1; i <= 3; i++) {
if (i != a && i != b) {
cout << i << endl;
return 1;
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
typedef long long ll;
int main() {
int a, b;
cin >> a >> b;
cout << 6 - (a + b) << endl;
} | replace | 10 | 16 | 10 | 11 | 1 | |
p02829 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fa(x, v) for (auto x : v)
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll) int(s.length())
#define sz(v) (ll) int(v.size())
#define MOD 1000000007
void Fast_IO() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
freopen("debug.out", "w", stderr);
#endif
}
// Code Here
int main() {
Fast_IO();
ll a, b;
cin >> a >> b;
if (a > b)
swap(a, b);
if (a == 1 && b == 2)
cout << 3;
else if (a == 1 && b == 3)
cout << 2;
else
cout << 1;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fa(x, v) for (auto x : v)
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll) int(s.length())
#define sz(v) (ll) int(v.size())
#define MOD 1000000007
void Fast_IO() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
freopen("debug.out", "w", stderr);
#endif
}
// Code Here
int main() {
// Fast_IO();
ll a, b;
cin >> a >> b;
if (a > b)
swap(a, b);
if (a == 1 && b == 2)
cout << 3;
else if (a == 1 && b == 3)
cout << 2;
else
cout << 1;
return 0;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p02829 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N = 100005;
#define M 1000000007
#define double long double
#define BINF 10000000000000000
#define init(arr, val) memset(arr, val, sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;
#undef int
int main() {
#define int long long int
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("ip.txt", "r", stdin);
freopen("op.txt", "w", stdout);
#endif
int a, b;
cin >> a >> b;
a ^= b;
cout << a << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N = 100005;
#define M 1000000007
#define double long double
#define BINF 10000000000000000
#define init(arr, val) memset(arr, val, sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;
#undef int
int main() {
#define int long long int
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a, b;
cin >> a >> b;
a ^= b;
cout << a << endl;
return 0;
}
| delete | 26 | 31 | 26 | 26 | 0 | |
p02829 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int c = 6 - a - b;
cout << c;
return 1;
} | #include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int c = 6 - a - b;
cout << c;
return 0;
}
| replace | 8 | 9 | 8 | 9 | 1 | |
p02829 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(s) (int)s.size()
#define endl '\n'
void PLAY() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
PLAY();
int a, b;
cin >> a >> b;
cout << 6 - (a + b) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(s) (int)s.size()
#define endl '\n'
void PLAY() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
PLAY();
int a, b;
cin >> a >> b;
cout << 6 - (a + b) << endl;
return 0;
} | replace | 10 | 14 | 10 | 11 | 0 | |
p02829 | Python | Runtime Error | a, b = map(int, input().split())
ans = 6 - (a + b)
print(ans)
| a = int(input())
b = int(input())
print(6 - a - b)
| replace | 0 | 3 | 0 | 3 | ValueError: not enough values to unpack (expected 2, got 1) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02829/Python/s996128891.py", line 1, in <module>
a, b = map(int, input().split())
ValueError: not enough values to unpack (expected 2, got 1)
|
p02829 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
vector<int> ans{1, 2, 3};
ans.erase(ans.begin() + a - 1);
ans.erase(ans.begin() + b - 1);
cout << ans.at(0) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int ans;
for (int i = 1; i < 4; i++) {
if (i != a && i != b) {
ans = i;
}
}
cout << ans << endl;
} | replace | 6 | 10 | 6 | 13 | 0 | |
p02829 | C++ | Runtime Error | #include <iostream>
int main() {
int a, b;
std::cin >> a >> b;
return 6 - a - b;
}
| #include <iostream>
int main() {
int a, b;
std::cin >> a >> b;
std::cout << 6 - a - b;
return 0;
} | replace | 5 | 6 | 5 | 7 | 2 | |
p02829 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A;
int B;
int quizChoice = 6;
cin >> A;
cin >> B;
quizChoice -= (A + B);
return quizChoice;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A;
int B;
int quizChoice = 6;
cin >> A;
cin >> B;
quizChoice -= (A + B);
cout << quizChoice;
return 0;
} | replace | 13 | 14 | 13 | 16 | 2 | |
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
char a[100], b[100], c[100];
int i, n;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
a[i] = '\0';
for (i = 0; i < n; i++) {
cin >> b[i];
}
b[i] = '\0';
// cout<<a<<" "<<b<<endl;
int j = 0;
for (i = 0; i < n; i++, j = j + 2) {
c[j] = a[i];
c[j + 1] = b[i];
// cout<<"cj="<<c[j]<<" "<<"j+1="<<c[j+1]<<endl;
// j=j+2;
}
c[n * 2] = '\0';
cout << c << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
char a[101], b[101], c[204];
int i, n;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
a[i] = '\0';
for (i = 0; i < n; i++) {
cin >> b[i];
}
b[i] = '\0';
// cout<<a<<" "<<b<<endl;
int j = 0;
for (i = 0; i < n; i++, j = j + 2) {
c[j] = a[i];
c[j + 1] = b[i];
// cout<<"cj="<<c[j]<<" "<<"j+1="<<c[j+1]<<endl;
// j=j+2;
}
c[n * 2] = '\0';
cout << c << endl;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02830 | C++ | Runtime Error | #include <stdio.h>
int main(void) {
int len, i, j = 0;
char str1[100], str2[100], str3[200];
scanf("%d", &len);
scanf("%s %s", str1, str2);
for (i = 0; i <= len; i++) {
str3[j] = str1[i];
j++;
str3[j] = str2[i];
j++;
}
printf("%s\n", str3);
return 0;
}
| #include <stdio.h>
int main(void) {
int len, i, j = 0;
char str1[101], str2[101], str3[202];
scanf("%d", &len);
scanf("%s %s", str1, str2);
for (i = 0; i <= len; i++) {
str3[j] = str1[i];
j++;
str3[j] = str2[i];
j++;
}
printf("%s\n", str3);
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char a[n], b[n];
string s = "";
scanf("%s%s", a[n], b[n]);
for (int i = 0; i < n; i++) {
s += a[i];
s += b[i];
}
cout << s << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s = "", a, b;
cin >> n;
cin >> a >> b;
for (int i = 0; i < n; i++) {
s += a[i];
s += b[i];
}
cout << s << "\n";
return 0;
} | replace | 4 | 7 | 4 | 7 | -11 | |
p02830 | C++ | Runtime Error | #include <iostream>
using namespace std;
int n, i;
string s, t;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = 0; i < n; i++) {
cin >> t[i];
}
for (i = 0; i < n; i++) {
cout << s[i] << t[i];
}
return 0;
}
| #include <iostream>
using namespace std;
int n, i;
string s, t;
int main() {
cin >> n >> s >> t;
for (i = 0; i < n; i++) {
cout << s[i] << t[i];
}
return 0;
}
| replace | 7 | 14 | 7 | 8 | 0 | |
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprrev(i, a, b) for (int i = b - 1; i >= a; i--) // [a, b)
#define reprev(i, n) reprrev(i, 0, n)
#define _GLIBCXX_DEBUG
using ll = long long;
using ull = unsigned long long;
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;
}
const ll mod = 1e9 + 7;
void chmod(ll &M) {
if (M >= mod)
M %= mod;
else if (M < 0) {
M += (abs(M) / mod + 1) * mod;
M %= mod;
}
}
ll modpow(ll x, ll n) {
if (n == 0)
return 1;
ll res = modpow(x, n / 2);
if (n % 2 == 0)
return res * res % mod;
else
return res * res % mod * x % mod;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
using namespace std;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
string S, T;
cin >> S >> T;
string R;
rep(i, 2 * N) {
R += S.at(i);
R += T.at(i);
}
cout << R << endl;
} | #include <bits/stdc++.h>
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprrev(i, a, b) for (int i = b - 1; i >= a; i--) // [a, b)
#define reprev(i, n) reprrev(i, 0, n)
#define _GLIBCXX_DEBUG
using ll = long long;
using ull = unsigned long long;
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;
}
const ll mod = 1e9 + 7;
void chmod(ll &M) {
if (M >= mod)
M %= mod;
else if (M < 0) {
M += (abs(M) / mod + 1) * mod;
M %= mod;
}
}
ll modpow(ll x, ll n) {
if (n == 0)
return 1;
ll res = modpow(x, n / 2);
if (n % 2 == 0)
return res * res % mod;
else
return res * res % mod * x % mod;
}
int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
using namespace std;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
string S, T;
cin >> S >> T;
string R;
rep(i, N) {
R += S.at(i);
R += T.at(i);
}
cout << R << endl;
} | replace | 61 | 62 | 61 | 62 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 2) >= this->size() (which is 2)
|
p02830 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main(void) {
// Your code here!
int n;
cin >> n;
string s, t;
cin >> s >> t;
for (int i = 0; i < n; i++) {
cout << s[i] << t[i];
}
cout << "\n";
return 1;
}
| #include <iostream>
#include <string>
using namespace std;
int main(void) {
// Your code here!
int n;
cin >> n;
string s, t;
cin >> s >> t;
for (int i = 0; i < n; i++) {
cout << s[i] << t[i];
}
cout << "\n";
}
| delete | 13 | 14 | 13 | 13 | 1 | |
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int a;
string s, t;
cin >> a;
cin >> s >> t;
string ans = s + t;
for (int i = 0; i < 2 * a; i++) {
if (i % 2 == 0) {
ans.at(i) = s.at(i / 2);
} else {
ans.at(i) = s.at((i + 1) / 2);
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a;
string s, t;
cin >> a;
cin >> s >> t;
string ans = s + t;
for (int i = 0; i < 2 * a; i++) {
if (i % 2 == 0) {
ans.at(i) = s.at(i / 2);
} else {
ans.at(i) = t.at((i - 1) / 2);
}
}
cout << ans << endl;
}
| replace | 13 | 14 | 13 | 14 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 2) >= this->size() (which is 2)
|
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
int main() {
int N;
cin >> N;
vchar S(N), T(N);
rep(i, N) { cin >> S[i]; }
rep(i, N) { cin >> T[i]; }
vchar ans(2 * N);
int j = 0, k = 0;
rep(i, 2 * N + 1) {
if (i % 2 == 0)
ans[i] = S[j++];
else
ans[i] = T[k++];
}
rep(i, 2 * N) { cout << ans[i]; }
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
int main() {
int N;
cin >> N;
vchar S(N), T(N);
rep(i, N) { cin >> S[i]; }
rep(i, N) { cin >> T[i]; }
vchar ans(2 * N);
int j = 0, k = 0;
rep(i, 2 * N) {
if (i % 2 == 0)
ans[i] = S[j++];
else
ans[i] = T[k++];
}
rep(i, 2 * N) { cout << ans[i]; }
} | replace | 28 | 29 | 28 | 29 | 0 | |
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s, t;
cin >> s >> t;
for (int i = 0; i < n * 2; i++) {
cout << s.at(i) << t.at(i);
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s, t;
cin >> s >> t;
for (int i = 0; i < n; i++) {
cout << s.at(i) << t.at(i);
}
cout << endl;
} | replace | 11 | 12 | 11 | 12 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 2) >= this->size() (which is 2)
|
p02830 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int a;
unsigned char *s = new unsigned char[101];
unsigned char *t = new unsigned char[101];
unsigned char *r = new unsigned char[101];
cin >> a >> s >> t;
for (int i = 0; i < a; i++) {
r[2 * i] = s[i];
r[2 * i + 1] = t[i];
}
cout << r;
delete[] s;
delete[] t;
delete[] r;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int a;
unsigned char *s = new unsigned char[101];
unsigned char *t = new unsigned char[101];
unsigned char *r = new unsigned char[201];
cin >> a >> s >> t;
for (int i = 0; i < a; i++) {
r[2 * i] = s[i];
r[2 * i + 1] = t[i];
}
cout << r;
delete[] s;
delete[] t;
delete[] r;
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02830 | C++ | Runtime Error |
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int i, j, k, n, l, m;
string str1, str2;
string str3;
cin >> n;
cin >> str1 >> str2;
for (i = 0, j = 0; i < n; i++) {
str3[j++] = str1[i];
str3[j++] = str2[i];
}
for (i = 0; i < n * n; i++) {
cout << str3[i];
}
return 0;
} |
#include <cmath>
#include <iostream>
using namespace std;
int main() {
int i, j, k, n, l, m;
string str1, str2;
string str3;
cin >> n;
cin >> str1 >> str2;
for (i = 0, j = 0; i < n; i++) {
str3[j++] = str1[i];
str3[j++] = str2[i];
}
for (i = 0; i < n + n; i++) {
cout << str3[i];
}
return 0;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 1e6 + 9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf = 1e14;
ll mod = 1e9 + 7;
ll powm(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t = 1;
// cin>>t;
while (t--) {
ll n;
cin >> n;
string s, t;
cin >> s >> t;
for (int i = 0; i < n; i++) {
cout << s[i] << t[i];
}
}
} | #include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 1e6 + 9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf = 1e14;
ll mod = 1e9 + 7;
ll powm(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin>>t;
while (t--) {
ll n;
cin >> n;
string s, t;
cin >> s >> t;
for (int i = 0; i < n; i++) {
cout << s[i] << t[i];
}
}
} | delete | 24 | 28 | 24 | 24 | -11 | |
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >> n;
vector<char> a, b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
rep(i, n) cout << a[i] << b[i];
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >> n;
vector<char> a(n);
vector<char> b(n);
rep(i, n) cin >> a[i];
rep(i, n) cin >> b[i];
rep(i, n) cout << a[i] << b[i];
cout << endl;
}
| replace | 11 | 12 | 11 | 13 | -11 | |
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s, t;
cin >> n >> s >> t;
for (int i = 0; i = n; i++) {
cout << s.at(i) << t.at(i);
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s, t;
cin >> n >> s >> t;
for (int i = 0; i < n; i++) {
cout << s.at(i) << t.at(i);
}
}
| replace | 6 | 7 | 6 | 7 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 2) >= this->size() (which is 2)
|
p02830 | 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 <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#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;
int main() {
int N;
string S, T;
cin >> N >> S >> T;
for (int i = 0; i <= N; i++) {
cout << S.at(i) << T.at(i) << 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 <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#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;
int main() {
int N;
string S, T;
cin >> N >> S >> T;
for (int i = 0; i < N; i++) {
cout << S.at(i) << T.at(i);
}
}
| replace | 24 | 26 | 24 | 26 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 2) >= this->size() (which is 2)
|
p02830 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
string S, T;
char ans[200] = {};
int N, i, count = 0;
cin >> N;
cin >> S >> T;
for (i = 0; i <= N * 2; i += 2) {
ans[i] = S[count];
ans[i + 1] = T[count];
count++;
}
cout << ans << endl;
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
int main() {
string S, T;
char ans[200] = {};
int N, i, count = 0;
cin >> N;
cin >> S >> T;
for (i = 0; i < N * 2; i += 2) {
ans[i] = S[count];
ans[i + 1] = T[count];
count++;
}
cout << ans << endl;
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02830 | Python | Runtime Error | n = int(input())
s, t = [int(input()) for i in range(2)]
out = ""
for i in range(n):
out += s[i] + t[i]
print(out)
| n = int(input())
s, t = input().split()
out = ""
for i in range(n):
out += s[i] + t[i]
print(out)
| replace | 1 | 2 | 1 | 2 | ValueError: invalid literal for int() with base 10: 'ip cc' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02830/Python/s669050732.py", line 2, in <module>
s, t = [int(input()) for i in range(2)]
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02830/Python/s669050732.py", line 2, in <listcomp>
s, t = [int(input()) for i in range(2)]
ValueError: invalid literal for int() with base 10: 'ip cc'
|
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S, T;
cin >> S, T;
for (int i = 0; i < N; i++) {
cout << S.at(i) << T.at(i);
}
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S, T;
cin >> S >> T;
for (int i = 0; i < N; i++) {
cout << S.at(i) << T.at(i);
}
cout << endl;
}
| replace | 11 | 12 | 11 | 12 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
|
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i, a, n) for (int i = a; i < n; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define COUT cout << fixed << setprecision(12)
#define SET set<ll, greater<ll>> gquiz
#define ITERATOR set<ll, greater<ll>>::iterator itr
#define V vector<ll> vector
#define sz size()
#define A vector<pair<ll, ll>> vect
ll N = 100000, M = 100000;
#define B vect.push_back(make_pair(N, M));
ll MOD = 1000000007;
void solve() {
ll a, b;
cin >> a >> b;
ll c[4] = {0};
c[a - 1]++;
c[b - 1]++;
if (c[0] == 0)
cout << 1;
else if (c[1] == 0)
cout << 2;
else if (c[2] == 0)
cout << 3;
}
int main() { solve(); } | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i, a, n) for (int i = a; i < n; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define COUT cout << fixed << setprecision(12)
#define SET set<ll, greater<ll>> gquiz
#define ITERATOR set<ll, greater<ll>>::iterator itr
#define V vector<ll> vector
#define sz size()
#define A vector<pair<ll, ll>> vect
ll N = 100000, M = 100000;
#define B vect.push_back(make_pair(N, M));
ll MOD = 1000000007;
void solve() {
ll n;
cin >> n;
string s, t;
cin >> s;
cin >> t;
for (ll i = 0; i < n; i++)
cout << s[i] << t[i];
}
int main() { solve(); } | replace | 22 | 33 | 22 | 29 | 0 | |
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s, t;
for (int i = 0; i < n; i++) {
cout << s.at(i);
cout << t.at(i);
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s, t;
cin >> s >> t;
for (int i = 0; i < n; i++) {
cout << s.at(i);
cout << t.at(i);
}
cout << endl;
} | insert | 7 | 7 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
|
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string raw;
string s, t;
cin >> N;
cin >> raw;
s = raw.substr(0, N);
t = raw.substr(N + 1, N);
for (int i = 0; i < N; i++) {
cout << s[i] << t[i];
}
cout << "\n";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string raw;
string s, t;
getline(cin, raw);
N = stoi(raw);
getline(cin, raw);
s = raw.substr(0, N);
t = raw.substr(N + 1, N);
for (int i = 0; i < N; i++) {
cout << s[i] << t[i];
}
cout << "\n";
} | replace | 8 | 10 | 8 | 11 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr: __pos (which is 3) > this->size() (which is 2)
|
p02830 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define int long long
#define all(x) (x).begin(), (x).end()
signed main() {
int N;
string S, T, U;
cin >> N >> S >> T;
rep(i, N) {
U[2 * i] = S[i];
U[2 * i + 1] = T[i];
}
cout << U;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define int long long
#define all(x) (x).begin(), (x).end()
signed main() {
int N;
string S, T, U;
cin >> N >> S >> T;
rep(i, N) {
U += S[i];
U += T[i];
}
cout << U;
} | replace | 17 | 19 | 17 | 19 | 0 | |
p02830 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
string a, b, c;
cin >> a >> b;
c = a.at(0);
c += b.at(0);
for (int i = 1; i <= n; i++) {
c += a.at(i);
c += b.at(i);
}
cout << c << endl;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
string a, b, c;
cin >> a >> b;
c = a.at(0);
c += b.at(0);
for (int i = 1; i < n; i++) {
c += a.at(i);
c += b.at(i);
}
cout << c << endl;
} | replace | 10 | 11 | 10 | 11 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 2) >= this->size() (which is 2)
|
p02830 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S, T;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S.at(i);
}
for (int i = 0; i < N; i++) {
cin >> T.at(i);
}
for (int i = 0; i < N; i++) {
cout << S.at(i) << T.at(i);
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S, T;
cin >> N >> S >> T;
for (int i = 0; i < N; i++) {
cout << S.at(i) << T.at(i);
}
} | replace | 5 | 12 | 5 | 6 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
|
p02831 | Python | Runtime Error | import fractions
a, b = map(int, input().split())
print(int(a * b / fractions.gcd(a * b)))
| import fractions
a, b = map(int, input().split())
print(a * b // fractions.gcd(a, b))
| replace | 4 | 5 | 4 | 5 | AttributeError: module 'fractions' has no attribute 'gcd' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02831/Python/s463768606.py", line 5, in <module>
print(int(a * b / fractions.gcd(a * b)))
AttributeError: module 'fractions' has no attribute 'gcd'
|
p02831 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return (b, a % b);
}
int main() {
ll a, b;
cin >> a >> b;
cout << (a * b) / gcd(a, b);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
ll a, b;
cin >> a >> b;
cout << (a * b) / gcd(a, b);
} | replace | 6 | 8 | 6 | 7 | 0 | |
p02831 | Python | Runtime Error | # C - Snack
from math import gcd
A, B = map(int, input().split())
print(A * B // gcd(A, B))
| # C - Snack
from fractions import gcd
A, B = map(int, input().split())
print(A * B // gcd(A, B))
| replace | 2 | 3 | 2 | 3 | 0 | |
p02831 | Python | Runtime Error | # from fractions import gcd
from math import gcd
a, b = map(int, input().split())
print(a * b // gcd(a, b))
exit(0)
| from fractions import gcd
# from math import gcd
a, b = map(int, input().split())
print(a * b // gcd(a, b))
exit(0)
| replace | 0 | 2 | 0 | 3 | 0 | |
p02831 | Python | Runtime Error | import math
a, b = map(int, input().split())
print((a * b) // math.gcd(a, b))
| import math
a, b = map(int, input().split())
i = 1
flag = True
while flag:
if (a * i) % b == 0:
flag = False
ans = a * i
break
i += 1
print(ans)
| replace | 3 | 4 | 3 | 14 | 0 | |
p02831 | Python | Runtime Error | from math import gcd
a, b = map(int, input().split())
print(int(a * b / gcd(a, b)))
| from fractions import gcd
a, b = map(int, input().split())
print(int(a * b / gcd(a, b)))
| replace | 0 | 1 | 0 | 1 | 0 | |
p02831 | Python | Runtime Error | from math import gcd
a, b = tuple(map(int, input().split()))
print(int(a * b / gcd(a, b)))
| from fractions import gcd
a, b = tuple(map(int, input().split()))
print(int(a * b / gcd(a, b)))
| replace | 0 | 1 | 0 | 1 | 0 | |
p02831 | Python | Runtime Error | # abc148_c.py
import sys
import time
import unittest
from io import StringIO
import math
def resolve():
A, B = [int(i) for i in input().split()]
print(int(A * B / math.gcd(A, B)))
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def setUp(self):
self.startTime = time.time()
def tearDown(self):
t = time.time() - self.startTime
print("%s: %.3f" % (self.id(), t), flush=True)
def test_入力例_1(self):
input = """2 3"""
output = """6"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """123 456"""
output = """18696"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """100000 99999"""
output = """9999900000"""
self.assertIO(input, output)
if __name__ == "__main__":
if "IS_LOCAL" in locals():
suite = unittest.TestLoader().loadTestsFromTestCase(TestClass)
unittest.TextTestRunner(verbosity=0).run(suite)
else:
resolve()
| # abc148_c.py
import sys
import time
import unittest
from io import StringIO
import fractions as math
def resolve():
A, B = [int(i) for i in input().split()]
print(int(A * B / math.gcd(A, B)))
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def setUp(self):
self.startTime = time.time()
def tearDown(self):
t = time.time() - self.startTime
print("%s: %.3f" % (self.id(), t), flush=True)
def test_入力例_1(self):
input = """2 3"""
output = """6"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """123 456"""
output = """18696"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """100000 99999"""
output = """9999900000"""
self.assertIO(input, output)
if __name__ == "__main__":
if "IS_LOCAL" in locals():
suite = unittest.TestLoader().loadTestsFromTestCase(TestClass)
unittest.TextTestRunner(verbosity=0).run(suite)
else:
resolve()
| replace | 5 | 6 | 5 | 6 | 0 | |
p02831 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define SPEED \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
int main() {
SPEED;
ll l, g;
cin >> l >> g;
if (l > g)
swap(l, g);
ll i;
for (i = g;; i++) {
if (i % l == 0 and i % g == 0) {
break;
}
}
cout << i << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define SPEED \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
int main() {
ll a, b;
cin >> a >> b;
cout << a * b / (__gcd(a, b)) << endl;
return 0;
} | replace | 15 | 27 | 15 | 18 | TLE | |
p02831 | Python | Runtime Error | from math import gcd
a, b = map(int, input().split())
lcm = a * b // gcd(a, b)
print(lcm)
| from fractions import gcd
a, b = map(int, input().split())
lcm = a * b // gcd(a, b)
print(lcm)
| replace | 0 | 1 | 0 | 1 | 0 | |
p02831 | C++ | Runtime Error | #include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
typedef pair<ll, ll> PII;
int n;
string s1, s2, ans;
ll a, b;
ll f(ll a, ll b) { b == 0 ? a : f(b, a % b); }
int main() {
cin >> a >> b;
cout << a * b / f(a, b);
} | #include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;
const int N = 1e5 + 10;
typedef long long ll;
typedef pair<ll, ll> PII;
int n;
string s1, s2, ans;
ll a, b;
ll f(ll a, ll b) { return b == 0 ? a : f(b, a % b); }
int main() {
cin >> a >> b;
cout << a * b / f(a, b);
} | replace | 16 | 17 | 16 | 17 | 0 | |
p02831 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define ef emplace_front
#define eb emplace_back
#define mp make_pair
#define MOD 1000000007
typedef long double f80;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef float f32;
typedef double f64;
typedef long double f80;
typedef unordered_set<int> usi;
typedef set<int> si;
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
if (!a)
return b;
return gcd(b, a % b);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
ll a, b;
cin >> a >> b;
cout << a / gcd(a, b) * b;
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define ef emplace_front
#define eb emplace_back
#define mp make_pair
#define MOD 1000000007
typedef long double f80;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef float f32;
typedef double f64;
typedef long double f80;
typedef unordered_set<int> usi;
typedef set<int> si;
ll gcd(ll a, ll b) {
if (a < b)
return gcd(b, a);
if (!b)
return a;
return gcd(b, a % b);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
ll a, b;
cin >> a >> b;
cout << a / gcd(a, b) * b;
} | replace | 45 | 47 | 45 | 47 | -8 | |
p02831 | C++ | Runtime Error | #include <cstdlib>
#include <iostream>
using namespace std;
long gcd(long x, long y) {
long t;
if (x < y) {
long tmp = x;
x = y;
y = tmp;
}
t = x % y;
if (t == 0) {
return y;
} else {
gcd(y, t);
}
}
int main() {
long a, b;
cin >> a >> b;
cout << (a * b) / gcd(a, b) << endl;
return 0;
}
| #include <cstdlib>
#include <iostream>
using namespace std;
long gcd(long x, long y) {
long t;
if (x < y) {
long tmp = x;
x = y;
y = tmp;
}
t = x % y;
if (t == 0) {
return y;
} else {
return gcd(y, t);
}
}
int main() {
long a, b;
cin >> a >> b;
cout << (a * b) / gcd(a, b) << endl;
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p02831 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long n, k, mn;
int main() {
cin >> n >> k;
if (n < k) {
mn = n;
} else {
mn = k;
}
for (int i = mn; i <= n * k; i++) {
if (i % n == 0 && i % k == 0) {
cout << i;
return 0;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long n, k, mn;
int main() {
cin >> n >> k;
cout << n * k / __gcd(n, k);
return 0;
} | replace | 8 | 19 | 8 | 9 | TLE | |
p02831 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int a, b;
cin >> a >> b;
int max = 0;
for (int i = 1; i < min(a, b); i++) {
if (a % i == 0 && b % i == 0) {
max = i;
}
}
cout << (int64_t)a * b / max << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int a, b;
cin >> a >> b;
int max = 0;
for (int i = 1; i <= min(a, b); i++) {
if (a % i == 0 && b % i == 0) {
max = i;
}
}
cout << (int64_t)a * b / max << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02831 | Python | Runtime Error | from math import gcd
a, b = map(int, input().split())
print(a * b // gcd(a, b))
| def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
a, b = map(int, input().split())
print(a * b // gcd(a, b))
| replace | 0 | 1 | 0 | 5 | 0 | |
p02831 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
long int a, b;
cin >> a >> b;
for (long int i = 0; i < 10000000000; i++) {
if (i % a == 0 && i % b == 0) {
cout << i << endl;
}
}
} | #include <iostream>
using namespace std;
int main() {
long int a, b;
cin >> a >> b;
for (int i = 1; i <= b; i++) {
if (a * i % b == 0) {
cout << a * i << endl;
return 0;
}
}
} | replace | 6 | 9 | 6 | 10 | TLE | |
p02831 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
if (b == 1)
return a;
return GCD(b, a % b);
}
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int main() {
long long a, b;
scanf("%lld %lld", &a, &b);
printf("%lld", LCM(a, b));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
return GCD(b, a % b);
}
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int main() {
long long a, b;
scanf("%lld %lld", &a, &b);
printf("%lld", LCM(a, b));
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02831 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
gcd(b, a % b);
}
int main() {
long long a, b;
cin >> a >> b;
if (b % a == 0)
cout << b;
else
cout << a / gcd(a, b) * b;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
gcd(b, a % b);
}
int main() {
long long a, b;
cin >> a >> b;
// cout<<a/gcd(a,b)*b<<endl;
for (int i = 1; i <= b; i++) {
if ((a * i) % b == 0) {
cout << a * i << endl;
break;
}
}
return 0;
}
| replace | 10 | 14 | 10 | 17 | 0 | |
p02831 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b;
cin >> a >> b;
if (__gcd(a, b) == 1) {
cout << a * b;
} else {
for (long long int i = max(a, b);; i++) {
if (i % a == 0 && i % b == 0) {
cout << i;
break;
}
}
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b;
cin >> a >> b;
cout << (a * b) / __gcd(a, b);
}
| replace | 5 | 15 | 5 | 6 | TLE | |
p02831 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() {
ll a, b;
cout << lcm(a, b) << endl;
// cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() {
ll a, b;
cin >> a >> b;
cout << lcm(a, b) << endl;
// cout << ans << endl;
return 0;
} | insert | 26 | 26 | 26 | 27 | 0 | |
p02831 | C++ | Time Limit Exceeded | /*
*/
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define cint const int
#define ld long double
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
using namespace std;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef set<int> si;
typedef set<string> ss;
typedef pair<int, int> pi;
// typedef pair <long long, long long> pll;
// typedef pair <int, long long> pil;
// typedef pair <int, string> pis;
// typedef pair <int, char> pic;
// typedef pair <long long, int> pli;
// typedef pair <long long, string> pls;
// typedef pair <long long, char> plc;
// typedef pair <string, int> psi;
// typedef pair <string, long long> psl;
// typedef pair <string, char> psc;
// typedef pair <char, int> pci;
// typedef pair <char, long long> pcl;
// typedef pair <char, string> pcs;
ll a, b;
int main() {
cin >> a >> b;
for (int i = max(a, b);; ++i) {
if (i % a == 0 && i % b == 0) {
cout << i;
return 0;
}
}
return 0;
} | /*
*/
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define cint const int
#define ld long double
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
using namespace std;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef set<int> si;
typedef set<string> ss;
typedef pair<int, int> pi;
// typedef pair <long long, long long> pll;
// typedef pair <int, long long> pil;
// typedef pair <int, string> pis;
// typedef pair <int, char> pic;
// typedef pair <long long, int> pli;
// typedef pair <long long, string> pls;
// typedef pair <long long, char> plc;
// typedef pair <string, int> psi;
// typedef pair <string, long long> psl;
// typedef pair <string, char> psc;
// typedef pair <char, int> pci;
// typedef pair <char, long long> pcl;
// typedef pair <char, string> pcs;
ll a, b;
int main() {
cin >> a >> b;
for (ll i = max(a, b);; i += max(a, b)) {
if (i % a == 0 && i % b == 0) {
cout << i;
return 0;
}
}
return 0;
} | replace | 48 | 49 | 48 | 49 | TLE | |
p02831 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
LL a, b;
cin >> a >> b;
if (a > b) {
swap(a, b);
}
if (b - a == 1) {
cout << a * b << "\n";
return 0;
}
for (LL i = a;; i++) {
if (i % a == 0 && i % b == 0) {
cout << i << "\n";
return 0;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
LL a, b;
cin >> a >> b;
if (a > b) {
swap(a, b);
}
for (LL i = b;; i += b) {
if (i % a == 0) {
cout << i << "\n";
return 0;
}
}
}
| replace | 10 | 16 | 10 | 13 | TLE | |
p02831 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
long long c = a * b;
long long ans;
for (long long i = 1; i <= c; ++i) {
if (i % a == 0 && i % b == 0) {
ans = i;
break;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
long long c = a * b;
long long ans;
for (long long i = 1; i <= c; ++i) {
ans = a * i;
if (ans % a == 0 && ans % b == 0) {
break;
}
}
cout << ans << endl;
} | replace | 8 | 10 | 8 | 10 | TLE | |
p02831 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define p_q priority_queue
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
ll a, b;
cin >> a >> b;
ll min, el;
if (a > b) {
min = b;
el = a;
} else {
min = a;
el = b;
}
ll g = 0, gm = 0;
for (ll i = 1; i < min; i++) {
if (min % i == 0 && el % i == 0) {
g = i;
if (gm < g) {
gm = g;
}
}
}
a /= gm;
b /= gm;
cout << a * b * gm << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define p_q priority_queue
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
ll a, b;
cin >> a >> b;
ll min, el;
if (a > b) {
min = b;
el = a;
} else {
min = a;
el = b;
}
ll g = 1, gm = 1;
for (ll i = 1; i <= min; i++) {
if (min % i == 0 && el % i == 0) {
g = i;
if (gm < g) {
gm = g;
}
}
}
a /= gm;
b /= gm;
cout << a * b * gm << endl;
}
| replace | 20 | 22 | 20 | 22 | 0 | |
p02831 | C++ | Time Limit Exceeded | #include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
long long a, b, n;
scanf("%d %d", &a, &b);
for (long long i = a; i > 0; i--) {
if (a % i == 0 && b % i == 0) {
n = i;
break;
}
}
printf("%lld", a * b / n);
return 0;
} | #include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
long long a, b, n;
scanf("%lld %lld", &a, &b);
for (long long i = a; i > 0; i--) {
if (a % i == 0 && b % i == 0) {
n = i;
break;
}
}
printf("%lld", a * b / n);
return 0;
} | replace | 9 | 10 | 9 | 10 | TLE | |
p02831 | Python | Runtime Error | import math
A, B = map(int, input().split())
def lcm(x, y):
return (x * y) // math.gcd(x, y)
print(lcm(A, B))
| import math
A, B = map(int, input().split())
def gcd(a, b):
while b:
a, b = b, a % b
return a
# a,bの最小公倍数
def lcm(a, b):
return a * b // gcd(a, b)
print(lcm(A, B))
| replace | 5 | 7 | 5 | 16 | 0 | |
p02831 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a, b;
int p = a * b;
int g = __gcd(a, b);
int l = p / g;
cout << l;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
long int a, b;
cin >> a >> b;
long int p = a * b;
long int g = __gcd(a, b);
long int l = p / g;
cout << l;
} | replace | 4 | 8 | 4 | 9 | 0 | |
p02831 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
int v = max(A, B);
int i = 1;
int ans = v;
while (!((ans / A > 0 && ans / B > 0) && (ans % A == 0 && ans % B == 0))) {
i++;
ans = v * i;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
int v = max(A, B);
int w = min(A, B);
long int ans = v;
while ((ans % w != 0) || !(ans / v > 0)) {
ans += v;
}
cout << ans << endl;
}
| replace | 7 | 12 | 7 | 11 | TLE | |
p02831 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return (gcd(b, a % b));
}
int main() {
ll a, b;
ll ans = a * b;
ll k = gcd(a, b);
ans /= k;
cout << ans << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return (gcd(b, a % b));
}
int main() {
ll a, b;
cin >> a >> b;
ll ans = a * b;
ll k = gcd(a, b);
ans /= k;
cout << ans << "\n";
return 0;
} | insert | 10 | 10 | 10 | 11 | 0 | |
p02831 | C++ | Runtime Error | #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
ll gcd(ll a, ll b) {
if (a < b) {
ll t = a;
a = b;
b = t;
}
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main() {
ll a, b;
cin >> a >> b;
cout << (a * b) / gcd(a, b) << endl;
return 10;
} | #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
ll gcd(ll a, ll b) {
if (a < b) {
ll t = a;
a = b;
b = t;
}
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main() {
ll a, b;
cin >> a >> b;
cout << (a * b) / gcd(a, b) << endl;
return 0;
} | replace | 35 | 36 | 35 | 36 | 10 | |
p02831 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
string a, b;
cin >> a >> b;
for (i = 0; i < n; i++) {
cout << a[i] << b[i];
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long m, n, r, t;
cin >> m >> n;
t = m * n;
do {
r = m % n;
m = n;
n = r;
} while (r != 0);
cout << t / m << endl;
return 0;
} | replace | 3 | 10 | 3 | 12 | 0 | |
p02831 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define freinput "input.txt", "r", stdin
#define freoutput "output.txt", "w", stdout
#define mp make_pair
#define fi first
#define sc second
#define pb push_back
#define ellapse printf("Time : %0.3lf\n", clock() * 1.0 / CLOCKS_PER_SEC);
typedef long long ll;
typedef unsigned long int uld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
struct comp {
bool operator()(int a, int b) { return a > b; }
};
int main() {
long a, b;
cin >> a >> b;
for (long i = 1; i <= 10000000000; i++) {
if (i % a == 0 && i % b == 0) {
cout << i << endl;
break;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#define freinput "input.txt", "r", stdin
#define freoutput "output.txt", "w", stdout
#define mp make_pair
#define fi first
#define sc second
#define pb push_back
#define ellapse printf("Time : %0.3lf\n", clock() * 1.0 / CLOCKS_PER_SEC);
typedef long long ll;
typedef unsigned long int uld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
struct comp {
bool operator()(int a, int b) { return a > b; }
};
int main() {
long a, b;
cin >> a >> b;
cout << (a * b) / __gcd(a, b) << endl;
}
| replace | 21 | 27 | 21 | 22 | TLE | |
p02831 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int min_ = min(a, b);
int i = min_;
while ((i % a != 0) || (i % b != 0)) {
i += min_;
// cout << i << endl;
}
cout << i << endl;
} | #include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
long long i = b;
while (i % a != 0) {
i += b;
// cout << i << endl;
}
cout << i << endl;
}
| replace | 7 | 11 | 7 | 10 | TLE | |
p02831 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
long long ans;
ans = max(a, b);
for (long long i = 0; i < 1e9; i++) {
if (ans % a == 0 && ans % b == 0) {
cout << ans << endl;
return 0;
}
ans++;
}
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
long long ans = a * b / __gcd(a, b);
cout << ans << endl;
return 0;
} | replace | 7 | 16 | 7 | 10 | TLE | |
p02831 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll a, b;
cout << a * b / __gcd(a, b);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll a, b;
cin >> a >> b;
cout << a * b / __gcd(a, b);
return 0;
} | insert | 6 | 6 | 6 | 7 | 0 | |
p02831 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 998244353
using namespace std;
long long PGCD(long long a, long long b) {
if (a % b == 0)
return b;
return PGCD(b, a % b);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long a, b;
if (a < b)
swap(a, b);
cout << (a * b) / PGCD(a, b);
} | #include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 998244353
using namespace std;
long long PGCD(long long a, long long b) {
if (a % b == 0)
return b;
return PGCD(b, a % b);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long a, b;
cin >> a >> b;
if (a < b)
swap(a, b);
cout << (a * b) / PGCD(a, b);
} | insert | 22 | 22 | 22 | 23 | 0 | |
p02832 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> a(n);
int b = 1;
for (int i = 0; i < n; i++) {
cin >> a.at(n);
if (a.at(i) == b)
b++;
}
if (b == 1)
cout << -1 << endl;
else
cout << n - b + 1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> a(n);
int b = 1;
for (int i = 0; i < n; i++) {
cin >> a.at(i);
if (a.at(i) == b)
b++;
}
if (b == 1)
cout << -1 << endl;
else
cout << n - b + 1 << endl;
} | replace | 10 | 11 | 10 | 11 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p02832 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mp make_pair
#define endl "\n"
#define pb push_back
#define ll long long
int main() {
#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
IOS;
ll i, n;
cin >> n;
vector<ll> a(n);
for (i = 0; i < n; i++)
cin >> a[i];
ll cnt = 0;
ll ans = 0;
for (i = 0; i < n; i++) {
if (a[i] == (cnt + 1)) {
cnt++;
} else
ans++;
}
if (cnt == 0) {
cout << "-1" << endl;
} else
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mp make_pair
#define endl "\n"
#define pb push_back
#define ll long long
int main() {
IOS;
ll i, n;
cin >> n;
vector<ll> a(n);
for (i = 0; i < n; i++)
cin >> a[i];
ll cnt = 0;
ll ans = 0;
for (i = 0; i < n; i++) {
if (a[i] == (cnt + 1)) {
cnt++;
} else
ans++;
}
if (cnt == 0) {
cout << "-1" << endl;
} else
cout << ans << endl;
return 0;
} | delete | 14 | 20 | 14 | 14 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02832 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;
int main() {
int n;
cin >> n;
vector<vector<int>> indices(n + 1);
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
indices[a].push_back(i);
}
int x = 0;
int i = 1;
while (true) {
auto it = lower_bound(indices[i].begin(), indices[i].end(), x);
if (it == indices[i].end())
break;
x = *it + 1;
++i;
}
if (i == 1)
cout << -1 << endl;
else
cout << n - i + 1 << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;
int main() {
int n;
cin >> n;
vector<vector<int>> indices(n + 1);
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
indices[a].push_back(i);
}
int x = 0;
int i = 1;
while (i <= n) {
auto it = lower_bound(indices[i].begin(), indices[i].end(), x);
if (it == indices[i].end())
break;
x = *it + 1;
++i;
}
if (i == 1)
cout << -1 << endl;
else
cout << n - i + 1 << endl;
return 0;
} | replace | 32 | 33 | 32 | 33 | 0 | |
p02832 | C++ | Runtime Error | #include "bits/stdc++.h"
#include <cassert>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int a[100006];
signed main() {
int n;
cin >> n;
rep(i, n) cin >> a[i];
int now = 0;
rep(i, n) {
if (a[i] == now + 1)
now++;
}
if (now)
cout << n - now << endl;
else
cout << -1 << endl;
} | #include "bits/stdc++.h"
#include <cassert>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int a[1000006];
signed main() {
int n;
cin >> n;
rep(i, n) cin >> a[i];
int now = 0;
rep(i, n) {
if (a[i] == now + 1)
now++;
}
if (now)
cout << n - now << endl;
else
cout << -1 << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02832 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, t = 1;
long long b[20001];
cin >> a;
for (int i = 0; i < a; i++)
cin >> b[i];
for (int i = 0; i < a; i++)
if (b[i] == t)
t++;
if (t > 1)
cout << a - t + 1 << endl;
else
cout << "-1" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, t = 1;
long long b[200001];
cin >> a;
for (int i = 0; i < a; i++)
cin >> b[i];
for (int i = 0; i < a; i++)
if (b[i] == t)
t++;
if (t > 1)
cout << a - t + 1 << endl;
else
cout << "-1" << endl;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02832 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int break_num = 0;
int a[n];
bool break_flg[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
break_flg[i] = false;
}
for (int i = 0; i < n; i++) {
int index_num = 0;
for (int j = 0; j <= i; j++) {
if (break_flg[j] == true) {
continue;
}
if (break_flg[j] == false) {
index_num++;
}
if (index_num != a[j]) {
break_flg[j] = true;
break_num++;
}
}
}
if (break_num == n) {
cout << -1 << endl;
;
} else {
cout << break_num << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int break_num = 0;
int a[n];
bool break_flg[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
break_flg[i] = false;
}
int index_num = 0;
for (int i = 1; i <= n; i++) {
if (i - break_num != a[i - 1]) {
break_num++;
}
}
if (break_num == n) {
cout << -1 << endl;
;
} else {
cout << break_num << endl;
}
return 0;
} | replace | 14 | 27 | 14 | 18 | TLE | |
p02832 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int length;
cin >> length;
int tot = 0;
int brick[100000];
int sen = 1;
for (int i = 0; i < length; i++) {
cin >> brick[i];
if (brick[i] != sen) {
tot++;
} else {
sen++;
}
}
if (sen == 1) {
tot = -1;
}
cout << tot << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int length;
cin >> length;
int tot = 0;
int brick[1000000];
int sen = 1;
for (int i = 0; i < length; i++) {
cin >> brick[i];
if (brick[i] != sen) {
tot++;
} else {
sen++;
}
}
if (sen == 1) {
tot = -1;
}
cout << tot << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02832 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long int a, b, c, ar[100009], sum, cnt;
int main() {
cin >> a;
long long int j = 1;
for (int i = 1; i <= a; i++)
cin >> ar[i];
for (int i = 1; i <= a; i++) {
if (ar[i] != j)
cnt++;
else {
j++;
}
}
if (cnt == a)
cout << "-1" << endl;
else
cout << cnt << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long int a, b, c, ar[1000009], sum, cnt;
int main() {
cin >> a;
long long int j = 1;
for (int i = 1; i <= a; i++)
cin >> ar[i];
for (int i = 1; i <= a; i++) {
if (ar[i] != j)
cnt++;
else {
j++;
}
}
if (cnt == a)
cout << "-1" << endl;
else
cout << cnt << endl;
return 0;
}
| replace | 2 | 3 | 2 | 3 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.