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
p02703
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long struct E { int to, co, ti; }; struct P { int tim, idx, res; }; bool operator<(const P &a, const P &b) { return a.tim < b.tim; } bool operator>(const P &a, const P &b) { if (a.tim != b.tim) return a.tim > b.tim; return a.res < b.res; } int ans[50][5001]; const long long LINF = 1e18; template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } signed main() { memset(ans, -1, sizeof(ans)); int n, m, s; cin >> n >> m >> s; chmin(s, 5000LL); vector<E> edge[n]; while (m--) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; edge[u].push_back({v, a, b}); edge[v].push_back({u, a, b}); } vector<int> c(n), d(n); for (int i = 0; i < n; i++) cin >> c[i] >> d[i]; priority_queue<P, vector<P>, greater<P>> que; que.push({0, 0, s}); vector<int> fans(n, -1); int cnt = 0; while (que.size()) { P p = que.top(); que.pop(); // cout<<p.idx<<" "<<p.res<<" "<<p.tim<<" "<<cnt<<endl; if (~ans[p.idx][p.res]) continue; ans[p.idx][p.res] = p.tim; if (fans[p.idx] < 0) { fans[p.idx] = p.tim; if (++cnt == n) break; } do { for (auto q : edge[p.idx]) { if (p.res < q.co || ~ans[q.to][p.res - q.co]) continue; que.push({p.tim + q.ti, q.to, p.res - q.co}); } p.res += c[p.idx]; p.tim += d[p.idx]; } while (p.res < 5000); } for (int i = 1; i < n; i++) cout << fans[i] << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long struct E { int to, co, ti; }; struct P { int tim, idx, res; }; bool operator<(const P &a, const P &b) { return a.tim < b.tim; } bool operator>(const P &a, const P &b) { if (a.tim != b.tim) return a.tim > b.tim; return a.res < b.res; } int ans[50][5001]; const long long LINF = 1e18; template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } signed main() { memset(ans, -1, sizeof(ans)); int n, m, s; cin >> n >> m >> s; chmin(s, 5000LL); vector<E> edge[n]; while (m--) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; edge[u].push_back({v, a, b}); edge[v].push_back({u, a, b}); } vector<int> c(n), d(n); for (int i = 0; i < n; i++) cin >> c[i] >> d[i]; priority_queue<P, vector<P>, greater<P>> que; que.push({0, 0, s}); vector<int> fans(n, -1); int cnt = 0; while (que.size()) { P p = que.top(); que.pop(); // cout<<p.idx<<" "<<p.res<<" "<<p.tim<<" "<<cnt<<endl; if (~ans[p.idx][p.res]) continue; ans[p.idx][p.res] = p.tim; if (fans[p.idx] < 0) { fans[p.idx] = p.tim; if (++cnt == n) break; } for (auto q : edge[p.idx]) { if (p.res < q.co || ~ans[q.to][p.res - q.co]) continue; que.push({p.tim + q.ti, q.to, p.res - q.co}); } if (p.res + c[p.idx] < 5000) que.push({p.tim + d[p.idx], p.idx, p.res + c[p.idx]}); } for (int i = 1; i < n; i++) cout << fans[i] << endl; }
replace
54
63
54
61
TLE
p02703
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; const LL inf = 0x3f3f3f3f3f3f3f3f; const int N = 55, M = 110; struct Edge { int to, next; LL a, b; } e[M]; int head[N], idx; LL c[N], d[N]; LL dis[N][2510]; int n, m, s; void add(int u, int v, LL a, LL b) { e[++idx].to = v; e[idx].next = head[u]; e[idx].a = a; e[idx].b = b; head[u] = idx; } void spfa() { queue<PII> q; for (int i = 1; i <= n; i++) { for (int j = 0; j <= 2500; j++) { dis[i][j] = inf; } } dis[1][s] = 0; q.push({1, s}); while (!q.empty()) { int u = q.front().first, w = q.front().second; q.pop(); for (int i = head[u]; i; i = e[i].next) { int v = e[i].to; LL a = e[i].a, b = e[i].b; if (w >= a && dis[v][w - a] > dis[u][w] + b) { dis[v][w - a] = dis[u][w] + b; q.push({v, w - a}); } } if (dis[u][min(w + c[u], (LL)2500)] > dis[u][w] + d[u]) { dis[u][min(w + c[u], (LL)2500)] = dis[u][w] + d[u]; q.push({u, min(w + c[u], (LL)2500)}); } } } int main() { scanf("%d%d%d", &n, &m, &s); s = min(s, 2500); while (m--) { int u, v; LL a, b; scanf("%d%d%lld%lld", &u, &v, &a, &b); add(u, v, a, b); add(v, u, a, b); } for (int i = 1; i <= n; i++) { scanf("%lld %lld", &c[i], &d[i]); } spfa(); for (int i = 2; i <= n; i++) { LL res = inf; for (int j = 0; j <= 2500; j++) res = min(res, dis[i][j]); printf("%lld\n", res); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; const LL inf = 0x3f3f3f3f3f3f3f3f; const int N = 55, M = 110; struct Edge { int to, next; LL a, b; } e[M * 2]; int head[N], idx; LL c[N], d[N]; LL dis[N][2510]; int n, m, s; void add(int u, int v, LL a, LL b) { e[++idx].to = v; e[idx].next = head[u]; e[idx].a = a; e[idx].b = b; head[u] = idx; } void spfa() { queue<PII> q; for (int i = 1; i <= n; i++) { for (int j = 0; j <= 2500; j++) { dis[i][j] = inf; } } dis[1][s] = 0; q.push({1, s}); while (!q.empty()) { int u = q.front().first, w = q.front().second; q.pop(); for (int i = head[u]; i; i = e[i].next) { int v = e[i].to; LL a = e[i].a, b = e[i].b; if (w >= a && dis[v][w - a] > dis[u][w] + b) { dis[v][w - a] = dis[u][w] + b; q.push({v, w - a}); } } if (dis[u][min(w + c[u], (LL)2500)] > dis[u][w] + d[u]) { dis[u][min(w + c[u], (LL)2500)] = dis[u][w] + d[u]; q.push({u, min(w + c[u], (LL)2500)}); } } } int main() { scanf("%d%d%d", &n, &m, &s); s = min(s, 2500); while (m--) { int u, v; LL a, b; scanf("%d%d%lld%lld", &u, &v, &a, &b); add(u, v, a, b); add(v, u, a, b); } for (int i = 1; i <= n; i++) { scanf("%lld %lld", &c[i], &d[i]); } spfa(); for (int i = 2; i <= n; i++) { LL res = inf; for (int j = 0; j <= 2500; j++) res = min(res, dis[i][j]); printf("%lld\n", res); } return 0; }
replace
10
11
10
11
0
p02703
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define pint pair<int, int> #define vec vector<int> #define vvec vector<vec> #define pvec vector<vector<pint>> #define tint tuple<int, int, int> #define mt make_tuple int n, m, s; vvec to; pvec cost; const int inf = 1LL << 60; int dp[60][3000]; // その状態までにかかる時間 int c[60], d[60]; bool chmin(int &a, int b) { if (a > b) { swap(a, b); return true; } else { return false; } } void Dijkstra(int a, int b) { dp[a][b] = 0; priority_queue<tint, vector<tint>, greater<tint>> Q; // {時間、位置、枚数} Q.push(mt(0, a, b)); while (!Q.empty()) { auto p = Q.top(); Q.pop(); int time = get<0>(p); int pos = get<1>(p); int num = get<2>(p); if (time > dp[pos][num]) { continue; } for (int i = 0; i < (int)to[pos].size(); i++) { int length = cost[pos][i].second; int silver = cost[pos][i].first; int next = to[pos][i]; int res = min(num + c[pos], 2999LL); int res2 = num - silver; if (chmin(dp[pos][res], dp[pos][num] + d[pos])) { Q.push(mt(dp[pos][res], pos, res)); } if (res2 >= 0) { if (chmin(dp[next][res2], dp[pos][num] + length)) { Q.push(mt(dp[next][res2], next, res2)); } } } // for-u } // while-Q return; } signed main(void) { cin >> n >> m >> s; to.resize(n); cost.resize(n); for (int i = 0; i < m; i++) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; to[u].push_back(v); to[v].push_back(u); cost[u].push_back({a, b}); cost[v].push_back({a, b}); } for (int i = 0; i < n; i++) { cin >> c[i] >> d[i]; } for (int i = 0; i < 60; i++) { for (int j = 0; j < 3000; j++) { dp[i][j] = inf; } } Dijkstra(0, s); int ans = inf; for (int i = 1; i < n; i++) { int ans = inf; for (int j = 0; j < 3000; j++) { ans = min(ans, dp[i][j]); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define pint pair<int, int> #define vec vector<int> #define vvec vector<vec> #define pvec vector<vector<pint>> #define tint tuple<int, int, int> #define mt make_tuple int n, m, s; vvec to; pvec cost; const int inf = 1LL << 60; int dp[60][3000]; // その状態までにかかる時間 int c[60], d[60]; bool chmin(int &a, int b) { if (a > b) { swap(a, b); return true; } else { return false; } } void Dijkstra(int a, int b) { b = min(b, 2999LL); dp[a][b] = 0; priority_queue<tint, vector<tint>, greater<tint>> Q; // {時間、位置、枚数} Q.push(mt(0, a, b)); while (!Q.empty()) { auto p = Q.top(); Q.pop(); int time = get<0>(p); int pos = get<1>(p); int num = get<2>(p); if (time > dp[pos][num]) { continue; } for (int i = 0; i < (int)to[pos].size(); i++) { int length = cost[pos][i].second; int silver = cost[pos][i].first; int next = to[pos][i]; int res = min(num + c[pos], 2999LL); int res2 = num - silver; if (chmin(dp[pos][res], dp[pos][num] + d[pos])) { Q.push(mt(dp[pos][res], pos, res)); } if (res2 >= 0) { if (chmin(dp[next][res2], dp[pos][num] + length)) { Q.push(mt(dp[next][res2], next, res2)); } } } // for-u } // while-Q return; } signed main(void) { cin >> n >> m >> s; to.resize(n); cost.resize(n); for (int i = 0; i < m; i++) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; to[u].push_back(v); to[v].push_back(u); cost[u].push_back({a, b}); cost[v].push_back({a, b}); } for (int i = 0; i < n; i++) { cin >> c[i] >> d[i]; } for (int i = 0; i < 60; i++) { for (int j = 0; j < 3000; j++) { dp[i][j] = inf; } } Dijkstra(0, s); int ans = inf; for (int i = 1; i < n; i++) { int ans = inf; for (int j = 0; j < 3000; j++) { ans = min(ans, dp[i][j]); } cout << ans << endl; } return 0; }
insert
30
30
30
32
0
p02703
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <random> #include <set> #include <vector> using namespace std; using ll = long long; ll BASE_NUM = 1000000007; const int NONE = -1; template <typename T> struct S { long long node, prev; T cost; S(long long n, T c, long long p) : node(n), cost(c), prev(p) {} bool operator>(const S &s) const { return cost > s.cost; } }; template <typename T> class Dijkstra { long long n; vector<map<long long, T>> G; public: vector<T> minc; vector<long long> prev; Dijkstra(vector<map<long long, T>> &G) : n(G.size()), G(G), minc(n, NONE), prev(G.size()) {} void solve(long long start) { minc.assign(n, NONE); priority_queue<S<T>, vector<S<T>>, greater<S<T>>> pq; pq.push(S<T>(start, 0, NONE)); while (!pq.empty()) { S<T> s = pq.top(); pq.pop(); if (minc[s.node] != NONE) { continue; } minc[s.node] = s.cost; prev[s.node] = s.prev; for (auto itr = G[s.node].begin(); itr != G[s.node].end(); ++itr) { pq.push(S<T>(itr->first, s.cost + itr->second, s.node)); } } } void print() { for (int i = 0; i < n; i++) { cout << i << ":" << minc[i] << endl; } }; }; int main() { // 整数の入力 ll N, M, S; cin >> N >> M >> S; ll MAX_MONEY = 50 * N + 1; vector<map<ll, ll>> G(N * MAX_MONEY); for (int i = 0; i < M; i++) { ll u, v, a, b; cin >> u >> v >> a >> b; u--; v--; for (int j = 0; j < MAX_MONEY; j++) { if (j - a >= 0) { G[u * MAX_MONEY + j][v * MAX_MONEY + j - a] = b; G[v * MAX_MONEY + j][u * MAX_MONEY + j - a] = b; } } } for (int i = 0; i < N; i++) { ll c, d; cin >> c >> d; for (int j = 0; j < MAX_MONEY; j++) { ll trades = 1; while (j + trades * c < MAX_MONEY) { G[i * MAX_MONEY + j][i * MAX_MONEY + j + trades * c] = trades * d; trades++; } } } Dijkstra<ll> dickstra(G); dickstra.solve(min(S, MAX_MONEY - 1)); // dickstra.print(); // cout << MAX_MONEY << endl; for (int i = 1; i < N; i++) { ll min_m = numeric_limits<ll>::max(); for (int j = 0; j < MAX_MONEY; j++) { min_m = min(min_m, dickstra.minc[i * MAX_MONEY + j]); } cout << min_m << endl; } return 0; }
#include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <random> #include <set> #include <vector> using namespace std; using ll = long long; ll BASE_NUM = 1000000007; const int NONE = -1; template <typename T> struct S { long long node, prev; T cost; S(long long n, T c, long long p) : node(n), cost(c), prev(p) {} bool operator>(const S &s) const { return cost > s.cost; } }; template <typename T> class Dijkstra { long long n; vector<map<long long, T>> G; public: vector<T> minc; vector<long long> prev; Dijkstra(vector<map<long long, T>> &G) : n(G.size()), G(G), minc(n, NONE), prev(G.size()) {} void solve(long long start) { minc.assign(n, NONE); priority_queue<S<T>, vector<S<T>>, greater<S<T>>> pq; pq.push(S<T>(start, 0, NONE)); while (!pq.empty()) { S<T> s = pq.top(); pq.pop(); if (minc[s.node] != NONE) { continue; } minc[s.node] = s.cost; prev[s.node] = s.prev; for (auto itr = G[s.node].begin(); itr != G[s.node].end(); ++itr) { pq.push(S<T>(itr->first, s.cost + itr->second, s.node)); } } } void print() { for (int i = 0; i < n; i++) { cout << i << ":" << minc[i] << endl; } }; }; int main() { // 整数の入力 ll N, M, S; cin >> N >> M >> S; ll MAX_MONEY = 50 * N + 1; vector<map<ll, ll>> G(N * MAX_MONEY); for (int i = 0; i < M; i++) { ll u, v, a, b; cin >> u >> v >> a >> b; u--; v--; for (int j = 0; j < MAX_MONEY; j++) { if (j - a >= 0) { G[u * MAX_MONEY + j][v * MAX_MONEY + j - a] = b; G[v * MAX_MONEY + j][u * MAX_MONEY + j - a] = b; } } } for (int i = 0; i < N; i++) { ll c, d; cin >> c >> d; for (int j = 0; j < MAX_MONEY; j++) { if (j + c < MAX_MONEY) { G[i * MAX_MONEY + j][i * MAX_MONEY + j + c] = d; } else { G[i * MAX_MONEY + j][i * MAX_MONEY + MAX_MONEY - 1] = d; } } } Dijkstra<ll> dickstra(G); dickstra.solve(min(S, MAX_MONEY - 1)); // dickstra.print(); // cout << MAX_MONEY << endl; for (int i = 1; i < N; i++) { ll min_m = numeric_limits<ll>::max(); for (int j = 0; j < MAX_MONEY; j++) { min_m = min(min_m, dickstra.minc[i * MAX_MONEY + j]); } cout << min_m << endl; } return 0; }
replace
84
88
84
88
TLE
p02703
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 /* ちゃんと考えてわかって実装 */ const int MAX_V = 50; const int MAX_S = 50 * MAX_V + 5; const ll INF = 1e18; struct Edge { int to, a, b; // これを書いたらerrorが取れた。どうして必要なのォぉ Edge(int to, int a, int b) : to(to), a(a), b(b) {} }; struct State { int v, s; // state = (頂点, 所持金) ll x; // その状態までの経過時間 // これを書いたらerrorが取れた。どうして必要なのォぉ State(int v, int s, ll x) : v(v), s(s), x(x) {} bool operator<(const State other) const { return other.x > x; // (x < other.x だとちゃんと動かねぇ) } }; vector<Edge> g[MAX_V]; // 各頂点から伸びている辺の集合として保持。 ll min_time[MAX_V][MAX_S + 5]; // 状態(v, s)までの最小の時間を記録。 int main(void) { int n, m, s; cin >> n >> m >> s; for (int i = 0; i < m; i++) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; g[u].emplace_back(v, a, b); g[v].emplace_back(u, a, b); } for (int i = 0; i < n; i++) { for (int j = 0; j < MAX_S + 5; j++) { min_time[i][j] = INF; // たどり着けない状態はINFのまま。 // 以下では、たどり着ける状態についてその時間の最小値を探索する。 } } vector<int> c(n), d(n); for (int i = 0; i < n; i++) { cin >> c[i] >> d[i]; } s = min(s, MAX_S); // 十分な値で切り捨てる。 priority_queue<State> pq; // pqに状態(v, s, x)を emplace するときに、 // min_time[v][s]の値を x に更新する。(xが最小じゃないなら更新しない。) auto push = [&](int v, int s, ll x) { if (s < 0) return; if (min_time[v][s] <= x) return; min_time[v][s] = x; pq.emplace(v, s, x); }; // 初期状態は(0, s, 0) push(0, s, 0); while (!pq.empty()) { State now = pq.top(); pq.pop(); int v = now.v, s = now.s; ll x = now.x; // if(min_time[v][s] != x) continue; // なぜ?????(消しても通る) // 遷移その1 : 換金 int next_s = min(s + c[v], MAX_S); push(v, next_s, x + d[v]); // 遷移その2 : 電車に乗る // そこから伸びている辺を全てみる for (Edge e : g[v]) { push(e.to, s - e.a, x + e.b); } } // 答えの出力(min_timeのなかにある) for (int i = 1; i < n; i++) { ll ans = INF; for (int j = 0; j < MAX_S + 5; j++) { ans = min(ans, min_time[i][j]); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 /* ちゃんと考えてわかって実装 */ const int MAX_V = 50; const int MAX_S = 50 * MAX_V + 5; const ll INF = 1e18; struct Edge { int to, a, b; // これを書いたらerrorが取れた。どうして必要なのォぉ Edge(int to, int a, int b) : to(to), a(a), b(b) {} }; struct State { int v, s; // state = (頂点, 所持金) ll x; // その状態までの経過時間 // これを書いたらerrorが取れた。どうして必要なのォぉ State(int v, int s, ll x) : v(v), s(s), x(x) {} bool operator<(const State other) const { return other.x < x; // (x < other.x とか other.x > x (意味は一緒)だとちゃんと動かねぇ) } }; vector<Edge> g[MAX_V]; // 各頂点から伸びている辺の集合として保持。 ll min_time[MAX_V][MAX_S + 5]; // 状態(v, s)までの最小の時間を記録。 int main(void) { int n, m, s; cin >> n >> m >> s; for (int i = 0; i < m; i++) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; g[u].emplace_back(v, a, b); g[v].emplace_back(u, a, b); } for (int i = 0; i < n; i++) { for (int j = 0; j < MAX_S + 5; j++) { min_time[i][j] = INF; // たどり着けない状態はINFのまま。 // 以下では、たどり着ける状態についてその時間の最小値を探索する。 } } vector<int> c(n), d(n); for (int i = 0; i < n; i++) { cin >> c[i] >> d[i]; } s = min(s, MAX_S); // 十分な値で切り捨てる。 priority_queue<State> pq; // pqに状態(v, s, x)を emplace するときに、 // min_time[v][s]の値を x に更新する。(xが最小じゃないなら更新しない。) auto push = [&](int v, int s, ll x) { if (s < 0) return; if (min_time[v][s] <= x) return; min_time[v][s] = x; pq.emplace(v, s, x); }; // 初期状態は(0, s, 0) push(0, s, 0); while (!pq.empty()) { State now = pq.top(); pq.pop(); int v = now.v, s = now.s; ll x = now.x; // if(min_time[v][s] != x) continue; // なぜ?????(消しても通る) // 遷移その1 : 換金 int next_s = min(s + c[v], MAX_S); push(v, next_s, x + d[v]); // 遷移その2 : 電車に乗る // そこから伸びている辺を全てみる for (Edge e : g[v]) { push(e.to, s - e.a, x + e.b); } } // 答えの出力(min_timeのなかにある) for (int i = 1; i < n; i++) { ll ans = INF; for (int j = 0; j < MAX_S + 5; j++) { ans = min(ans, min_time[i][j]); } cout << ans << endl; } return 0; }
replace
24
25
24
26
TLE
p02703
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 /* ちゃんと考えてわかって実装 */ const int MAX_V = 50; const int MAX_S = 50 * MAX_V + 5; const ll INF = 1e18; struct Edge { int to, a, b; // これを書いたらerrorが取れた。どうして必要なのォぉ Edge(int to, int a, int b) : to(to), a(a), b(b) {} }; struct State { int v, s; // state = (頂点, 所持金) ll x; // その状態までの経過時間 // これを書いたらerrorが取れた。どうして必要なのォぉ State(int v, int s, ll x) : v(v), s(s), x(x) {} bool operator<(const State &a) const { return x < a.x; // (x < a.x だとちゃんと動かねぇ) } }; vector<Edge> g[MAX_V]; // 各頂点から伸びている辺の集合として保持。 ll min_time[MAX_V][MAX_S + 5]; // 状態(v, s)までの最小の時間を記録。 int main(void) { int n, m, s; cin >> n >> m >> s; for (int i = 0; i < m; i++) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; g[u].emplace_back(v, a, b); g[v].emplace_back(u, a, b); } for (int i = 0; i < n; i++) { for (int j = 0; j < MAX_S + 5; j++) { min_time[i][j] = INF; // たどり着けない状態はINFのまま。 // 以下では、たどり着ける状態についてその時間の最小値を探索する。 } } vector<int> c(n), d(n); for (int i = 0; i < n; i++) { cin >> c[i] >> d[i]; } s = min(s, MAX_S); // 十分な値で切り捨てる。 priority_queue<State> pq; // pqに状態(v, s, x)を emplace するときに、 // min_time[v][s]の値を x に更新する。(xが最小じゃないなら更新しない。) auto push = [&](int v, int s, ll x) { if (s < 0) return; if (min_time[v][s] <= x) return; min_time[v][s] = x; pq.emplace(v, s, x); }; // 初期状態は(0, s, 0) push(0, s, 0); while (!pq.empty()) { State now = pq.top(); pq.pop(); int v = now.v, s = now.s; ll x = now.x; // if(min_time[v][s] != x) continue; // なぜ?????(消しても通る) // 遷移その1 : 換金 int next_s = min(s + c[v], MAX_S); push(v, next_s, x + d[v]); // 遷移その2 : 電車に乗る // そこから伸びている辺を全てみる for (Edge e : g[v]) { push(e.to, s - e.a, x + e.b); } } // 答えの出力(min_timeのなかにある) for (int i = 1; i < n; i++) { ll ans = INF; for (int j = 0; j < MAX_S + 5; j++) { ans = min(ans, min_time[i][j]); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 /* ちゃんと考えてわかって実装 */ const int MAX_V = 50; const int MAX_S = 50 * MAX_V + 5; const ll INF = 1e18; struct Edge { int to, a, b; // これを書いたらerrorが取れた。どうして必要なのォぉ Edge(int to, int a, int b) : to(to), a(a), b(b) {} }; struct State { int v, s; // state = (頂点, 所持金) ll x; // その状態までの経過時間 // これを書いたらerrorが取れた。どうして必要なのォぉ State(int v, int s, ll x) : v(v), s(s), x(x) {} bool operator<(const State &a) const { return x > a.x; // (x < a.x だとちゃんと動かねぇ) } }; vector<Edge> g[MAX_V]; // 各頂点から伸びている辺の集合として保持。 ll min_time[MAX_V][MAX_S + 5]; // 状態(v, s)までの最小の時間を記録。 int main(void) { int n, m, s; cin >> n >> m >> s; for (int i = 0; i < m; i++) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; g[u].emplace_back(v, a, b); g[v].emplace_back(u, a, b); } for (int i = 0; i < n; i++) { for (int j = 0; j < MAX_S + 5; j++) { min_time[i][j] = INF; // たどり着けない状態はINFのまま。 // 以下では、たどり着ける状態についてその時間の最小値を探索する。 } } vector<int> c(n), d(n); for (int i = 0; i < n; i++) { cin >> c[i] >> d[i]; } s = min(s, MAX_S); // 十分な値で切り捨てる。 priority_queue<State> pq; // pqに状態(v, s, x)を emplace するときに、 // min_time[v][s]の値を x に更新する。(xが最小じゃないなら更新しない。) auto push = [&](int v, int s, ll x) { if (s < 0) return; if (min_time[v][s] <= x) return; min_time[v][s] = x; pq.emplace(v, s, x); }; // 初期状態は(0, s, 0) push(0, s, 0); while (!pq.empty()) { State now = pq.top(); pq.pop(); int v = now.v, s = now.s; ll x = now.x; // if(min_time[v][s] != x) continue; // なぜ?????(消しても通る) // 遷移その1 : 換金 int next_s = min(s + c[v], MAX_S); push(v, next_s, x + d[v]); // 遷移その2 : 電車に乗る // そこから伸びている辺を全てみる for (Edge e : g[v]) { push(e.to, s - e.a, x + e.b); } } // 答えの出力(min_timeのなかにある) for (int i = 1; i < n; i++) { ll ans = INF; for (int j = 0; j < MAX_S + 5; j++) { ans = min(ans, min_time[i][j]); } cout << ans << endl; } return 0; }
replace
24
25
24
25
TLE
p02703
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rep2(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 tmax(a, b, c) max(a, max(b, c)) #define tmin(a, b, c) min(a, min(b, c)) #define pb push_back #define eb emplace_back #define vi vector<int> #define vvi vector<vector<int>> #define vl vector<ll> #define vs vector<string> #define vc vector<char> #define vb vector<bool> #define vp vector<P> using namespace std; using ll = long long; using P = pair<int, int>; using LP = pair<ll, ll>; template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) { is >> t; } return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (T t : v) { os << t << " "; } os << "\n"; return os; } void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; } void YES(bool b) { cout << (b ? "YES" : "NO") << endl; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int inf = 1001001001; const ll linf = 1001001001001001001; vi c, d; struct edge { int to, a, b; }; vector<vl> dijkstra(P start, const vector<vector<edge>> &v) { int n = v.size(); vector<vl> dist(n, vl(6000, linf)); priority_queue<pair<ll, P>, vector<pair<ll, P>>, greater<pair<ll, P>>> q; q.emplace(0LL, start); dist[start.first][start.second] = 0; while (!q.empty()) { auto p = q.top(); // cout << p.second.first << " " << p.second.second << endl; q.pop(); if (dist[p.second.first][p.second.second] < p.first) continue; for (auto e : v[p.second.first]) { if (p.second.second - e.a < 0) continue; if (chmin(dist[e.to][p.second.second - e.a], p.first + e.b)) { q.push({p.first + e.b, {e.to, p.second.second - e.a}}); } } int nc = c[p.second.first]; int nd = d[p.second.first]; if (p.second.second + nc < 6000) { if (chmin(dist[p.second.first][p.second.second + nc], p.first + nd)) { q.push({p.first + nd, {p.second.first, p.second.second + nc}}); } } } return dist; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m, s; cin >> n >> m >> s; vector<vector<edge>> G(n); rep(_, m) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; G[u].pb(edge{v, a, b}); G[v].pb(edge{u, a, b}); } c.resize(n); d.resize(n); rep(i, n) cin >> c[i] >> d[i]; auto v = dijkstra({0, s}, G); rep2(i, 1, n) { ll ans = linf; rep(j, 6000) chmin(ans, v[i][j]); cout << ans << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rep2(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 tmax(a, b, c) max(a, max(b, c)) #define tmin(a, b, c) min(a, min(b, c)) #define pb push_back #define eb emplace_back #define vi vector<int> #define vvi vector<vector<int>> #define vl vector<ll> #define vs vector<string> #define vc vector<char> #define vb vector<bool> #define vp vector<P> using namespace std; using ll = long long; using P = pair<int, int>; using LP = pair<ll, ll>; template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) { is >> t; } return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (T t : v) { os << t << " "; } os << "\n"; return os; } void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; } void YES(bool b) { cout << (b ? "YES" : "NO") << endl; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } const int inf = 1001001001; const ll linf = 1001001001001001001; vi c, d; struct edge { int to, a, b; }; vector<vl> dijkstra(P start, const vector<vector<edge>> &v) { int n = v.size(); vector<vl> dist(n, vl(6000, linf)); priority_queue<pair<ll, P>, vector<pair<ll, P>>, greater<pair<ll, P>>> q; q.emplace(0LL, start); dist[start.first][start.second] = 0; while (!q.empty()) { auto p = q.top(); // cout << p.second.first << " " << p.second.second << endl; q.pop(); if (dist[p.second.first][p.second.second] < p.first) continue; for (auto e : v[p.second.first]) { if (p.second.second - e.a < 0) continue; if (chmin(dist[e.to][p.second.second - e.a], p.first + e.b)) { q.push({p.first + e.b, {e.to, p.second.second - e.a}}); } } int nc = c[p.second.first]; int nd = d[p.second.first]; if (p.second.second + nc < 6000) { if (chmin(dist[p.second.first][p.second.second + nc], p.first + nd)) { q.push({p.first + nd, {p.second.first, p.second.second + nc}}); } } } return dist; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m, s; cin >> n >> m >> s; vector<vector<edge>> G(n); rep(_, m) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; G[u].pb(edge{v, a, b}); G[v].pb(edge{u, a, b}); } c.resize(n); d.resize(n); rep(i, n) cin >> c[i] >> d[i]; auto v = dijkstra({0, min(s, 5999)}, G); rep2(i, 1, n) { ll ans = linf; rep(j, 6000) chmin(ans, v[i][j]); cout << ans << endl; } }
replace
107
108
107
108
0
p02703
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using vec = vector<pair<int, int64_t>>; using graph = vector<vec>; constexpr int64_t inf = 1e18; int main() { int n, m, s; cin >> n >> m >> s; vector<int> u(m), v(m), a(m), b(m), c(n), d(n); for (int i = 0; i < m; i++) { cin >> u.at(i) >> v.at(i) >> a.at(i) >> b.at(i); u.at(i)--; v.at(i)--; } for (int i = 0; i < n; i++) { cin >> c.at(i) >> d.at(i); } graph to(50 * n * n); for (int i = 0; i < m; i++) { for (int j = a.at(i); j < 50 * n; j++) { to.at(50 * n * u.at(i) + j) .emplace_back(50 * n * v.at(i) + j - a.at(i), b.at(i)); to.at(50 * n * v.at(i) + j) .emplace_back(50 * n * u.at(i) + j - a.at(i), b.at(i)); } } for (int i = 0; i < n; i++) { for (int j = 0; j < 50 * n; j++) { int next = min(50 * n - 1, j + c.at(i)); to.at(50 * n * i + j).emplace_back(50 * n * i + next, d.at(i)); } } vector<int64_t> cost(50 * n * n, inf); priority_queue<pair<int64_t, int>> q; q.emplace(0, min(s, 50 * n - 1)); while (!q.empty()) { auto x = q.top(); q.pop(); cost.at(x.second) = min(cost.at(x.second), -x.first); for (auto next : to.at(x.second)) { if (cost.at(next.first) < inf) continue; q.emplace(x.first - next.second, next.first); } } for (int i = 1; i < n; i++) { int64_t ans = inf; for (int j = 0; j < 50 * n; j++) { ans = min(ans, cost.at(50 * n * i + j)); } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; using vec = vector<pair<int, int64_t>>; using graph = vector<vec>; constexpr int64_t inf = 1e18; int main() { int n, m, s; cin >> n >> m >> s; vector<int> u(m), v(m), a(m), b(m), c(n), d(n); for (int i = 0; i < m; i++) { cin >> u.at(i) >> v.at(i) >> a.at(i) >> b.at(i); u.at(i)--; v.at(i)--; } for (int i = 0; i < n; i++) { cin >> c.at(i) >> d.at(i); } graph to(50 * n * n); for (int i = 0; i < m; i++) { for (int j = a.at(i); j < 50 * n; j++) { to.at(50 * n * u.at(i) + j) .emplace_back(50 * n * v.at(i) + j - a.at(i), b.at(i)); to.at(50 * n * v.at(i) + j) .emplace_back(50 * n * u.at(i) + j - a.at(i), b.at(i)); } } for (int i = 0; i < n; i++) { for (int j = 0; j < 50 * n; j++) { int next = min(50 * n - 1, j + c.at(i)); to.at(50 * n * i + j).emplace_back(50 * n * i + next, d.at(i)); } } vector<int64_t> cost(50 * n * n, inf); priority_queue<pair<int64_t, int>> q; q.emplace(0, min(s, 50 * n - 1)); while (!q.empty()) { auto x = q.top(); q.pop(); if (cost.at(x.second) < inf) continue; cost.at(x.second) = -x.first; for (auto next : to.at(x.second)) { if (cost.at(next.first) < inf) continue; q.emplace(x.first - next.second, next.first); } } for (int i = 1; i < n; i++) { int64_t ans = inf; for (int j = 0; j < 50 * n; j++) { ans = min(ans, cost.at(50 * n * i + j)); } cout << ans << endl; } }
replace
40
41
40
43
TLE
p02703
C++
Runtime Error
#include <bits/stdc++.h> // clang-format off using Int = long long; #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on /** * author: knshnb * created: Sun Apr 26 21:18:52 JST 2020 **/ template <class T> inline bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <class T> inline bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } using namespace std; class UndirectedGraph { struct Edge { Int to, cost; }; public: vector<vector<Edge>> G; Int V; UndirectedGraph(Int V) : G(V), V(V) {} void add_edge(Int u, Int v, Int cost) { G[u].push_back({v, cost}); } vector<Int> dijkstra(Int s) { vector<Int> d(V, 1e18); d[s] = 0; priority_queue<pair<Int, Int>, vector<pair<Int, Int>>, greater<pair<Int, Int>>> que; // {dist, v} que.push({0, s}); while (!que.empty()) { pair<Int, Int> p = que.top(); dump(p); que.pop(); Int v = p.second; if (d[v] < p.first) continue; // 定数倍枝刈り for (Edge e : G[v]) { Int tmp = d[v] + e.cost; if (d[e.to] <= tmp) continue; d[e.to] = tmp; que.push({tmp, e.to}); } } return d; } }; signed main() { Int n, m, S; std::cin >> n >> m >> S; const Int K = 5001; auto enc = [&](Int v, Int j) { assert(j < K); return K * v + j; }; UndirectedGraph g(n * K); REP(_, m) { Int u, v, a, b; std::cin >> u >> v >> a >> b; u--, v--; REP(j, a, K) { g.add_edge(enc(u, j), enc(v, j - a), b); g.add_edge(enc(v, j), enc(u, j - a), b); } } REP(i, n) { Int c, d; std::cin >> c >> d; REP(j, K) { if (j + c >= K) break; g.add_edge(enc(i, j), enc(i, j + c), d); } } auto d = g.dijkstra(enc(0, S)); dump(d); REP(i, 1, n) { Int mi = 1e18; REP(j, K) chmin(mi, d[enc(i, j)]); std::cout << mi << "\n"; } }
#include <bits/stdc++.h> // clang-format off using Int = long long; #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on /** * author: knshnb * created: Sun Apr 26 21:18:52 JST 2020 **/ template <class T> inline bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <class T> inline bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } using namespace std; class UndirectedGraph { struct Edge { Int to, cost; }; public: vector<vector<Edge>> G; Int V; UndirectedGraph(Int V) : G(V), V(V) {} void add_edge(Int u, Int v, Int cost) { G[u].push_back({v, cost}); } vector<Int> dijkstra(Int s) { vector<Int> d(V, 1e18); d[s] = 0; priority_queue<pair<Int, Int>, vector<pair<Int, Int>>, greater<pair<Int, Int>>> que; // {dist, v} que.push({0, s}); while (!que.empty()) { pair<Int, Int> p = que.top(); dump(p); que.pop(); Int v = p.second; if (d[v] < p.first) continue; // 定数倍枝刈り for (Edge e : G[v]) { Int tmp = d[v] + e.cost; if (d[e.to] <= tmp) continue; d[e.to] = tmp; que.push({tmp, e.to}); } } return d; } }; signed main() { Int n, m, S; std::cin >> n >> m >> S; const Int K = 5001; auto enc = [&](Int v, Int j) { assert(j < K); return K * v + j; }; UndirectedGraph g(n * K); REP(_, m) { Int u, v, a, b; std::cin >> u >> v >> a >> b; u--, v--; REP(j, a, K) { g.add_edge(enc(u, j), enc(v, j - a), b); g.add_edge(enc(v, j), enc(u, j - a), b); } } REP(i, n) { Int c, d; std::cin >> c >> d; REP(j, K) { if (j + c >= K) break; g.add_edge(enc(i, j), enc(i, j + c), d); } } auto d = g.dijkstra(enc(0, std::min(S, K - 1))); dump(d); REP(i, 1, n) { Int mi = 1e18; REP(j, K) chmin(mi, d[enc(i, j)]); std::cout << mi << "\n"; } }
replace
91
92
91
92
0
p02703
C++
Runtime Error
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> VI; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; #define rep(a, n) for (ll a = 0; a < n; a++) #define repi(a, b, n) for (ll a = b; a < n; a++) const ll INF = 1e15; struct edge { ll to; ll cost; ll time; }; struct Data { ll node; ll cost; ll time; Data(ll node, ll cost, ll time) : node(node), cost(cost), time(time) {} bool operator<(const Data &data) const { return cost > data.cost; } bool operator>(const Data &data) const { return cost < data.cost; } }; int main(void) { ll n, m, s; cin >> n >> m >> s; vector<vector<edge>> edges(n + m); rep(i, m) { ll u, v, a, b; cin >> u >> v >> a >> b; u--; v--; edges[u].push_back({v, -a, b}); edges[v].push_back({u, -a, b}); } rep(i, n) { ll c, d; cin >> c >> d; edges[i].push_back({i, c, d}); } vector<vector<ll>> dp(n, vector<ll>(50 * 101, INF)); priority_queue<Data> q; q.emplace(0, s, 0); dp[0][s] = 0; while (q.size()) { auto t = q.top(); q.pop(); for (auto &e : edges[t.node]) { auto to = e.to; auto cost = t.cost + e.cost; cost = min(cost, 50LL * 100); auto time = t.time + e.time; if (cost < 0) continue; if (dp[to][cost] <= time) continue; dp[to][cost] = time; q.emplace(to, cost, time); } } vector<ll> r(n, INF); rep(i, n - 1) { rep(j, 50 * 101) { r[i + 1] = min(r[i + 1], dp[i + 1][j]); } } rep(i, n - 1) { cout << r[i + 1] << endl; } return 0; }
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> VI; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; #define rep(a, n) for (ll a = 0; a < n; a++) #define repi(a, b, n) for (ll a = b; a < n; a++) const ll INF = 1e15; struct edge { ll to; ll cost; ll time; }; struct Data { ll node; ll cost; ll time; Data(ll node, ll cost, ll time) : node(node), cost(cost), time(time) {} bool operator<(const Data &data) const { return cost > data.cost; } bool operator>(const Data &data) const { return cost < data.cost; } }; int main(void) { ll n, m, s; cin >> n >> m >> s; s = min(s, 50LL * 100); vector<vector<edge>> edges(n + m); rep(i, m) { ll u, v, a, b; cin >> u >> v >> a >> b; u--; v--; edges[u].push_back({v, -a, b}); edges[v].push_back({u, -a, b}); } rep(i, n) { ll c, d; cin >> c >> d; edges[i].push_back({i, c, d}); } vector<vector<ll>> dp(n, vector<ll>(50 * 101, INF)); priority_queue<Data> q; q.emplace(0, s, 0); dp[0][s] = 0; while (q.size()) { auto t = q.top(); q.pop(); for (auto &e : edges[t.node]) { auto to = e.to; auto cost = t.cost + e.cost; cost = min(cost, 50LL * 100); auto time = t.time + e.time; if (cost < 0) continue; if (dp[to][cost] <= time) continue; dp[to][cost] = time; q.emplace(to, cost, time); } } vector<ll> r(n, INF); rep(i, n - 1) { rep(j, 50 * 101) { r[i + 1] = min(r[i + 1], dp[i + 1][j]); } } rep(i, n - 1) { cout << r[i + 1] << endl; } return 0; }
insert
35
35
35
36
0
p02703
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define MAX_INF 0x7f #define MAX_INF_VAL 0x7f7f7f7f #define pi 3.141592653589 #define eps 1e-10 // #define p 2173412051LL #define sz 2 using namespace std; struct p { int u, m; ll t; }; struct cmp { bool operator()(const p &a, const p &b) { if (a.t == b.t) return a.m < b.m; return a.t > b.t; } }; priority_queue<p, vector<p>, cmp> q; ll f[51][5050]; vector<int> e[51]; ll cst[51][51], mins[51][51]; ll c[51], d[51]; int ma; void dijk(int, int, ll); void update(int, int, ll); int main() { int n, mm, s, x, y; ll a, b; ll u, m, t; ll ans; scanf("%d%d%d", &n, &mm, &s); ma = mm * 50; s = min(s, ma); for (int i = 0; i < mm; ++i) { scanf("%d%d%lld%lld", &x, &y, &a, &b); e[x].push_back(y); e[y].push_back(x); cst[x][y] = cst[y][x] = a; mins[x][y] = mins[y][x] = b; } for (int i = 1; i <= n; ++i) scanf("%lld%lld", &c[i], &d[i]); dijk(1, s, 0); for (int i = 2; i <= n; ++i) { ans = 0x7f7f7f7f7f7f7f7f; for (int j = 0; j <= ma; ++j) ans = min(ans, f[i][j]); printf("%lld\n", ans); } return 0; } void dijk(int x, int y, ll z) { p pp; memset(f, MAX_INF, sizeof(f)); q.push({x, y, z}); f[x][y] = z; while (!q.empty()) { pp = q.top(); q.pop(); if (pp.t == f[pp.u][pp.m]) update(pp.u, pp.m, pp.t); } } void update(int u, int m, ll t) { int v = u, nm = m; ll nt = t; for (int i = 1;; ++i) { nm += c[u]; nt += d[u]; if (nm > ma) nm = ma; if (nt < f[v][nm]) { f[v][nm] = nt; q.push({v, nm, nt}); } if (nm == ma) break; } for (int i = 0; i < e[u].size(); ++i) { v = e[u][i]; if (m < cst[u][v]) continue; nm = m - cst[u][v]; nt = t + mins[u][v]; if (nt < f[v][nm]) { f[v][nm] = nt; q.push({v, nm, nt}); } } }
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define MAX_INF 0x7f #define MAX_INF_VAL 0x7f7f7f7f #define pi 3.141592653589 #define eps 1e-10 // #define p 2173412051LL #define sz 2 using namespace std; struct p { int u, m; ll t; }; struct cmp { bool operator()(const p &a, const p &b) { if (a.t == b.t) return a.m < b.m; return a.t > b.t; } }; priority_queue<p, vector<p>, cmp> q; ll f[51][5050]; vector<int> e[51]; ll cst[51][51], mins[51][51]; ll c[51], d[51]; int ma; void dijk(int, int, ll); void update(int, int, ll); int main() { int n, mm, s, x, y; ll a, b; ll u, m, t; ll ans; scanf("%d%d%d", &n, &mm, &s); ma = mm * 50; s = min(s, ma); for (int i = 0; i < mm; ++i) { scanf("%d%d%lld%lld", &x, &y, &a, &b); e[x].push_back(y); e[y].push_back(x); cst[x][y] = cst[y][x] = a; mins[x][y] = mins[y][x] = b; } for (int i = 1; i <= n; ++i) scanf("%lld%lld", &c[i], &d[i]); dijk(1, s, 0); for (int i = 2; i <= n; ++i) { ans = 0x7f7f7f7f7f7f7f7f; for (int j = 0; j <= ma; ++j) ans = min(ans, f[i][j]); printf("%lld\n", ans); } return 0; } void dijk(int x, int y, ll z) { p pp; memset(f, MAX_INF, sizeof(f)); q.push({x, y, z}); f[x][y] = z; while (!q.empty()) { pp = q.top(); q.pop(); if (pp.t == f[pp.u][pp.m]) update(pp.u, pp.m, pp.t); } } void update(int u, int m, ll t) { int v = u, nm = m; ll nt = t; for (int i = 1;; ++i) { nm += c[u]; nt += d[u]; if (nm > ma) nm = ma; if (nt < f[v][nm]) { f[v][nm] = nt; q.push({v, nm, nt}); } else break; if (nm == ma) break; } for (int i = 0; i < e[u].size(); ++i) { v = e[u][i]; if (m < cst[u][v]) continue; nm = m - cst[u][v]; nt = t + mins[u][v]; if (nt < f[v][nm]) { f[v][nm] = nt; q.push({v, nm, nt}); } } }
replace
84
85
84
86
TLE
p02703
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> pii; const int N = 55; const int Mod = 2019; #define pi acos(-1) #define INF 1e18 #define INM INT_MIN #define pb(a) push_back(a) #define mk(a, b) make_pair(a, b) #define dbg(x) cout << "now this num is " << x << endl; #define met0(axx) memset(axx, 0, sizeof(axx)); #define metf(axx) memset(axx, -1, sizeof(axx)); #define sd(ax) scanf("%d", &ax) #define sld(ax) scanf("%lld", &ax) #define sldd(ax, bx) scanf("%lld %lld", &ax, &bx) #define sdd(ax, bx) scanf("%d %d", &ax, &bx) #define sddd(ax, bx, cx) scanf("%d %d %d", &ax, &bx, &cx) #define sfd(ax) scanf("%lf", &ax) #define sfdd(ax, bx) scanf("%lf %lf", &ax, &bx) #define pr(a) printf("%d\n", a) #define plr(a) printf("%lld\n", a) /* 最短路的变形,首先要明确一些条件. 对于金币换银币的操作,在一个地方只能用一枚金币换到c[i]枚银币.(也就是说不能用2,3...枚金币,只能进行一次一枚的兑换) */ int n, m, s, c[N], dd[N]; struct Node { int to, a, b; }; vector<Node> G[N]; LL dis[N][N * N]; // 边界控制 void slove() { for (int i = 0; i <= n; ++i) for (int j = 0; j <= 2500; ++j) dis[i][j] = INF; typedef tuple<LL, int, int> ple; // dis,u,money,多元组容器 priority_queue<ple, vector<ple>, greater<ple>> Q; dis[1][s] = 0; // 初始化,类似dis[s] = 0. Q.push(ple(0, 1, s)); while (!Q.empty()) { int u = get<1>(Q.top()); LL d = get<0>(Q.top()); int mon = get<2>(Q.top()); // 身上的银币数 Q.pop(); if (d > dis[u][mon]) continue; for (int i = 0; i < G[u].size(); ++i) // 更新相邻点的距离 { int y = G[u][i].to, a = G[u][i].a, b = G[u][i].b; if (mon >= a && dis[y][mon - a] > d + b) { dis[y][mon - a] = d + b; Q.push(ple(dis[y][mon - a], y, mon - a)); } } if (dis[u][min(2500, mon + c[u])] > dis[u][mon] + dd[u]) // 兑换 { dis[u][min(2500, mon + c[u])] = dis[u][mon] + dd[u]; Q.push(ple(dis[u][min(2500, mon + c[u])], u, min(2500, mon + c[u]))); } } } int main() { sddd(n, m, s); while (m--) { int x, y, a, b; sdd(x, y), sdd(a, b); G[x].push_back({y, a, b}); G[y].push_back({x, a, b}); } for (int i = 1; i <= n; ++i) sdd(c[i], dd[i]); slove(); for (int i = 2; i <= n; ++i) { LL ans = INF; for (int j = 0; j <= 2500; ++j) ans = min(ans, dis[i][j]); plr(ans); } // system("pause"); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> pii; const int N = 55; const int Mod = 2019; #define pi acos(-1) #define INF 1e18 #define INM INT_MIN #define pb(a) push_back(a) #define mk(a, b) make_pair(a, b) #define dbg(x) cout << "now this num is " << x << endl; #define met0(axx) memset(axx, 0, sizeof(axx)); #define metf(axx) memset(axx, -1, sizeof(axx)); #define sd(ax) scanf("%d", &ax) #define sld(ax) scanf("%lld", &ax) #define sldd(ax, bx) scanf("%lld %lld", &ax, &bx) #define sdd(ax, bx) scanf("%d %d", &ax, &bx) #define sddd(ax, bx, cx) scanf("%d %d %d", &ax, &bx, &cx) #define sfd(ax) scanf("%lf", &ax) #define sfdd(ax, bx) scanf("%lf %lf", &ax, &bx) #define pr(a) printf("%d\n", a) #define plr(a) printf("%lld\n", a) /* 最短路的变形,首先要明确一些条件. 对于金币换银币的操作,在一个地方只能用一枚金币换到c[i]枚银币.(也就是说不能用2,3...枚金币,只能进行一次一枚的兑换) */ int n, m, s, c[N], dd[N]; struct Node { int to, a, b; }; vector<Node> G[N]; LL dis[N][N * N]; // 边界控制 void slove() { for (int i = 0; i <= n; ++i) for (int j = 0; j <= 2500; ++j) dis[i][j] = INF; typedef tuple<LL, int, int> ple; // dis,u,money,多元组容器 priority_queue<ple, vector<ple>, greater<ple>> Q; s = min(2500, s); // s很可能会超过2500,需要过滤一下,不然会re dis[1][s] = 0; // 初始化,类似dis[s] = 0. Q.push(ple(0, 1, s)); while (!Q.empty()) { int u = get<1>(Q.top()); LL d = get<0>(Q.top()); int mon = get<2>(Q.top()); // 身上的银币数 Q.pop(); if (d > dis[u][mon]) continue; for (int i = 0; i < G[u].size(); ++i) // 更新相邻点的距离 { int y = G[u][i].to, a = G[u][i].a, b = G[u][i].b; if (mon >= a && dis[y][mon - a] > d + b) { dis[y][mon - a] = d + b; Q.push(ple(dis[y][mon - a], y, mon - a)); } } if (dis[u][min(2500, mon + c[u])] > dis[u][mon] + dd[u]) // 兑换 { dis[u][min(2500, mon + c[u])] = dis[u][mon] + dd[u]; Q.push(ple(dis[u][min(2500, mon + c[u])], u, min(2500, mon + c[u]))); } } } int main() { sddd(n, m, s); while (m--) { int x, y, a, b; sdd(x, y), sdd(a, b); G[x].push_back({y, a, b}); G[y].push_back({x, a, b}); } for (int i = 1; i <= n; ++i) sdd(c[i], dd[i]); slove(); for (int i = 2; i <= n; ++i) { LL ans = INF; for (int j = 0; j <= 2500; ++j) ans = min(ans, dis[i][j]); plr(ans); } // system("pause"); return 0; }
replace
39
40
39
41
0
p02703
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long N, M, S; // to (ginka, cost) vector<pair<long long, pair<long long, long long>>> tree[100]; long long c[200]; long long d[200]; map<long long, long long> ans; int main() { cin >> N >> M >> S; for (long long i = 0; i < M; i++) { long long u; long long v; long long a; long long b; cin >> u >> v >> a >> b; u--; v--; tree[u].push_back(make_pair(v, make_pair(a, b))); tree[v].push_back(make_pair(u, make_pair(a, b))); } for (long long i = 0; i < N; i++) { cin >> c[i] >> d[i]; } // cost, (point, ginka) priority_queue<pair<long long, pair<long long, long long>>, vector<pair<long long, pair<long long, long long>>>, greater<pair<long long, pair<long long, long long>>>> Q; Q.push(make_pair(0, make_pair(0, S))); // point, ginka map<pair<long long, long long>, long long> memo; while (!Q.empty()) { long long cost = Q.top().first; long long point = Q.top().second.first; long long ginka = Q.top().second.second; // cout << " point " << point << "ginka " << ginka << " cost " << cost << // endl; if (ans.count(point) == 0) { ans[point] = cost; if (ans.size() == N) { break; } } Q.pop(); if (memo.count(make_pair(point, ginka)) > 0) { continue; } memo[make_pair(point, ginka)] = cost; for (long long i = 0; i < tree[point].size(); i++) { long long nextpoint = tree[point][i].first; long long nextginka = tree[point][i].second.first; long long nextcost = tree[point][i].second.second; // 銀貨を使って次のcityにいく if (ginka >= nextginka) { Q.push(make_pair(cost + nextcost, make_pair(nextpoint, ginka - nextginka))); } } // 金貨を銀貨に交換する Q.push(make_pair(cost + d[point], make_pair(point, ginka + c[point]))); } for (long long i = 1; i < N; i++) { // cout << "ans[" << i << "=" << ans[i] << endl; cout << ans[i] << endl; } }
#include <bits/stdc++.h> using namespace std; long long N, M, S; // to (ginka, cost) vector<pair<long long, pair<long long, long long>>> tree[100]; long long c[200]; long long d[200]; map<long long, long long> ans; int main() { cin >> N >> M >> S; for (long long i = 0; i < M; i++) { long long u; long long v; long long a; long long b; cin >> u >> v >> a >> b; u--; v--; tree[u].push_back(make_pair(v, make_pair(a, b))); tree[v].push_back(make_pair(u, make_pair(a, b))); } for (long long i = 0; i < N; i++) { cin >> c[i] >> d[i]; } // cost, (point, ginka) priority_queue<pair<long long, pair<long long, long long>>, vector<pair<long long, pair<long long, long long>>>, greater<pair<long long, pair<long long, long long>>>> Q; Q.push(make_pair(0, make_pair(0, S))); // point, ginka map<pair<long long, long long>, long long> memo; while (!Q.empty()) { long long cost = Q.top().first; long long point = Q.top().second.first; long long ginka = Q.top().second.second; // cout << " point " << point << "ginka " << ginka << " cost " << cost << // endl; if (ans.count(point) == 0) { ans[point] = cost; if (ans.size() == N) { break; } } Q.pop(); if (memo.count(make_pair(point, ginka)) > 0) { continue; } memo[make_pair(point, ginka)] = cost; for (long long i = 0; i < tree[point].size(); i++) { long long nextpoint = tree[point][i].first; long long nextginka = tree[point][i].second.first; long long nextcost = tree[point][i].second.second; // 銀貨を使って次のcityにいく if (ginka >= nextginka) { Q.push(make_pair(cost + nextcost, make_pair(nextpoint, ginka - nextginka))); } } // 金貨を銀貨に交換する if (ginka < 300) { Q.push(make_pair(cost + d[point], make_pair(point, ginka + c[point]))); } } for (long long i = 1; i < N; i++) { // cout << "ans[" << i << "=" << ans[i] << endl; cout << ans[i] << endl; } }
replace
75
76
75
78
TLE
p02703
C++
Time Limit Exceeded
// <head> #include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1002003004; const ll LINF = 1002003004005006007ll; struct preprocess { preprocess() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } ____; // </head> // <library> // </library> struct Edge { ll to, a, b; Edge(ll to, ll a, ll b) : to(to), a(a), b(b) {} }; const ll MAXV = 50; const ll MAXS = MAXV * 50 + 5; vector<Edge> g[MAXV]; ll dp[MAXV][MAXS + 5]; struct Data { ll s, v, t; Data(ll v, ll s, ll t) : v(v), s(s), t(t) {} bool operator<(const Data &a) const { return t > a.t; } }; int main() { ll n, m, s; cin >> n >> m >> s; for (int i = 0; i < m; i++) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; g[u].emplace_back(v, a, b); g[v].emplace_back(u, a, b); } vector<ll> c(n), d(n); for (int i = 0; i < n; i++) { cin >> c[i] >> d[i]; } for (int i = 0; i < MAXV; i++) { for (int j = 0; j < MAXS; j++) { dp[i][j] = LINF; } } s = min(s, MAXS); priority_queue<Data> q; dp[0][s] = 0; q.emplace(0, s, 0); while (!q.empty()) { Data dt = q.top(); q.pop(); if (dp[dt.v][dt.s] < dt.t) continue; if (dt.s < 0) continue; // exchange ll ns = min(MAXS, dt.s + c[dt.v]); dp[dt.v][ns] = min(dp[dt.v][ns], dt.t + d[dt.v]); q.emplace(dt.v, ns, dt.t + d[dt.v]); // move to other station for (Edge e : g[dt.v]) { if (dt.s - e.a >= 0 && dp[e.to][dt.s - e.a] > dp[dt.v][dt.s] + e.b) { dp[e.to][dt.s - e.a] = dp[dt.v][dt.s] + e.b; q.emplace(e.to, dt.s - e.a, dp[e.to][dt.s - e.a]); } } } for (int i = 1; i < n; i++) { ll ans = LINF; for (int j = 0; j < MAXS; j++) { ans = min(ans, dp[i][j]); } cout << ans << '\n'; } }
// <head> #include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1002003004; const ll LINF = 1002003004005006007ll; struct preprocess { preprocess() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } ____; // </head> // <library> // </library> struct Edge { ll to, a, b; Edge(ll to, ll a, ll b) : to(to), a(a), b(b) {} }; const ll MAXV = 50; const ll MAXS = MAXV * 50 + 5; vector<Edge> g[MAXV]; ll dp[MAXV][MAXS + 5]; struct Data { ll s, v, t; Data(ll v, ll s, ll t) : v(v), s(s), t(t) {} bool operator<(const Data &a) const { return t > a.t; } }; int main() { ll n, m, s; cin >> n >> m >> s; for (int i = 0; i < m; i++) { int u, v, a, b; cin >> u >> v >> a >> b; u--; v--; g[u].emplace_back(v, a, b); g[v].emplace_back(u, a, b); } vector<ll> c(n), d(n); for (int i = 0; i < n; i++) { cin >> c[i] >> d[i]; } for (int i = 0; i < MAXV; i++) { for (int j = 0; j < MAXS; j++) { dp[i][j] = LINF; } } s = min(s, MAXS); priority_queue<Data> q; dp[0][s] = 0; q.emplace(0, s, 0); while (!q.empty()) { Data dt = q.top(); q.pop(); if (dp[dt.v][dt.s] < dt.t) continue; if (dt.s < 0) continue; // exchange ll ns = min(MAXS, dt.s + c[dt.v]); if (dp[dt.v][ns] > dt.t + d[dt.v]) { dp[dt.v][ns] = dt.t + d[dt.v]; q.emplace(dt.v, ns, dt.t + d[dt.v]); } // move to other station for (Edge e : g[dt.v]) { if (dt.s - e.a >= 0 && dp[e.to][dt.s - e.a] > dp[dt.v][dt.s] + e.b) { dp[e.to][dt.s - e.a] = dp[dt.v][dt.s] + e.b; q.emplace(e.to, dt.s - e.a, dp[e.to][dt.s - e.a]); } } } for (int i = 1; i < n; i++) { ll ans = LINF; for (int j = 0; j < MAXS; j++) { ans = min(ans, dp[i][j]); } cout << ans << '\n'; } }
replace
69
71
69
73
TLE
p02703
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define X first #define Y second #define all(x) x.begin(), x.end() #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " const int mod = (int)1e9 + 7; const int MX = (int)1e5 + 10; void add_self(int &x, int y) { x += y; if (x >= mod) x -= mod; } void sub_self(int &x, int y) { x -= y; if (x < 0) x += mod; } void mul(int &x, int y) { x = x * 1LL * y % mod; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n, m, s; cin >> n >> m >> s; vector<array<int, 3>> g[n]; int mx = 0; for (int i = 0; i < m; ++i) { int u, v, a, b; cin >> u >> v >> a >> b; --u, --v; g[u].push_back({v, a, b}); g[v].push_back({u, a, b}); mx += a; } vector<pair<int, int>> f(n); for (auto &p : f) { cin >> p.X >> p.Y; // c, d } s = min(s, mx); vector<vector<ll>> best(n, vector<ll>(2555, 9e18)); queue<array<int, 2>> q; q.push({0, s}); best[0][s] = 0; while (!q.empty()) { auto ar = q.front(); q.pop(); int x = ar[0]; int silver = ar[1]; // cout << x << " " << silver << endl; int t = 1; if (silver + t * f[x].X <= mx) { if (best[x][silver + t * f[x].X] > best[x][silver] + t * f[x].Y) { best[x][silver + t * f[x].X] = best[x][silver] + t * f[x].Y; q.push({x, silver + t * f[x].X}); } t++; } for (auto &p : g[x]) { int y = p[0]; int a = p[1]; int b = p[2]; if (silver >= a && best[y][silver - a] > best[x][silver] + b) { best[y][silver - a] = best[x][silver] + b; q.push({y, silver - a}); } } } for (int i = 1; i < n; ++i) { cout << *min_element(all(best[i])) << "\n"; } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long #define X first #define Y second #define all(x) x.begin(), x.end() #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " const int mod = (int)1e9 + 7; const int MX = (int)1e5 + 10; void add_self(int &x, int y) { x += y; if (x >= mod) x -= mod; } void sub_self(int &x, int y) { x -= y; if (x < 0) x += mod; } void mul(int &x, int y) { x = x * 1LL * y % mod; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n, m, s; cin >> n >> m >> s; vector<array<int, 3>> g[n]; int mx = 0; for (int i = 0; i < m; ++i) { int u, v, a, b; cin >> u >> v >> a >> b; --u, --v; g[u].push_back({v, a, b}); g[v].push_back({u, a, b}); mx += a; } vector<pair<int, int>> f(n); for (auto &p : f) { cin >> p.X >> p.Y; // c, d } s = min(s, mx); vector<vector<ll>> best(n, vector<ll>(mx + 1, 9e18)); queue<array<int, 2>> q; q.push({0, s}); best[0][s] = 0; while (!q.empty()) { auto ar = q.front(); q.pop(); int x = ar[0]; int silver = ar[1]; // cout << x << " " << silver << endl; int t = 1; if (silver + t * f[x].X <= mx) { if (best[x][silver + t * f[x].X] > best[x][silver] + t * f[x].Y) { best[x][silver + t * f[x].X] = best[x][silver] + t * f[x].Y; q.push({x, silver + t * f[x].X}); } t++; } for (auto &p : g[x]) { int y = p[0]; int a = p[1]; int b = p[2]; if (silver >= a && best[y][silver - a] > best[x][silver] + b) { best[y][silver - a] = best[x][silver] + b; q.push({y, silver - a}); } } } for (int i = 1; i < n; ++i) { cout << *min_element(all(best[i])) << "\n"; } return 0; }
replace
92
93
92
93
0
p02703
C++
Runtime Error
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> #define ll long long #define int long long #define FOR(i, x, y) for (int i = x; i <= y; ++i) #define pb push_back #define eb emplace_back #define Size(v) (int)v.size() using namespace std; // using namespace __gnu_pbds; const int INF = 1e16; struct Obj { int v, a, b; Obj(int x, int y, int z) { v = x, a = y, b = z; } Obj() { v = 0, a = 0, b = 0; } }; int n, m, s, c[55], d[55]; vector<Obj> adj[55]; int dist[56 * 2600]; vector<pair<int, int>> graph[56 * 2600]; int encode(int i, int j) { return (i * 2501 + j); } bool visited[56 * 2600]; void build(int i, int j) { int yeet = encode(i, j); if (j < 2500) { graph[yeet].eb(encode(i, min(2500LL, j + c[i])), d[i]); } for (auto &p : adj[i]) { int c = p.v, cost = p.a, w = p.b; if (j >= cost) { graph[yeet].eb(encode(c, j - cost), w); } } } void dijkstra(int v) { priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push({0, v}); dist[v] = 0; while (!pq.empty()) { int u = pq.top().second; pq.pop(); if (visited[u]) continue; visited[u] = true; for (auto &p : graph[u]) { int c = p.first, w = p.second; if (dist[c] > dist[u] + w) { dist[c] = dist[u] + w; pq.push({dist[c], c}); } } } } void solve() { cin >> n >> m >> s; FOR(i, 1, m) { int u, v, a, b; cin >> u >> v >> a >> b; adj[u].eb(v, a, b); adj[v].eb(u, a, b); } FOR(i, 1, n) cin >> c[i] >> d[i]; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= 2500; ++j) { build(i, j); } } // cerr << "here\n"; fill(dist, dist + 56 * 2600, INF); dijkstra(encode(1, s)); for (int i = 2; i <= n; ++i) { int ans = 1e15; for (int j = 0; j <= 2500; ++j) { ans = min(ans, dist[encode(i, j)]); } cout << ans << '\n'; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> #define ll long long #define int long long #define FOR(i, x, y) for (int i = x; i <= y; ++i) #define pb push_back #define eb emplace_back #define Size(v) (int)v.size() using namespace std; // using namespace __gnu_pbds; const int INF = 1e16; struct Obj { int v, a, b; Obj(int x, int y, int z) { v = x, a = y, b = z; } Obj() { v = 0, a = 0, b = 0; } }; int n, m, s, c[55], d[55]; vector<Obj> adj[55]; int dist[56 * 2600]; vector<pair<int, int>> graph[56 * 2600]; int encode(int i, int j) { return (i * 2501 + j); } bool visited[56 * 2600]; void build(int i, int j) { int yeet = encode(i, j); if (j < 2500) { graph[yeet].eb(encode(i, min(2500LL, j + c[i])), d[i]); } for (auto &p : adj[i]) { int c = p.v, cost = p.a, w = p.b; if (j >= cost) { graph[yeet].eb(encode(c, j - cost), w); } } } void dijkstra(int v) { priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push({0, v}); dist[v] = 0; while (!pq.empty()) { int u = pq.top().second; pq.pop(); if (visited[u]) continue; visited[u] = true; for (auto &p : graph[u]) { int c = p.first, w = p.second; if (dist[c] > dist[u] + w) { dist[c] = dist[u] + w; pq.push({dist[c], c}); } } } } void solve() { cin >> n >> m >> s; FOR(i, 1, m) { int u, v, a, b; cin >> u >> v >> a >> b; adj[u].eb(v, a, b); adj[v].eb(u, a, b); } FOR(i, 1, n) cin >> c[i] >> d[i]; for (int i = 1; i <= n; ++i) { for (int j = 0; j <= 2500; ++j) { build(i, j); } } // cerr << "here\n"; fill(dist, dist + 56 * 2600, INF); dijkstra(encode(1, min(2500LL, s))); for (int i = 2; i <= n; ++i) { int ans = 1e15; for (int j = 0; j <= 2500; ++j) { ans = min(ans, dist[encode(i, j)]); } cout << ans << '\n'; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; while (t--) solve(); return 0; }
replace
100
101
100
101
0
p02703
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = (0); i < (n); i++) using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<ll, pll> pl3; const ll max_n = 52; const ll max_s = 2500; vector<ll> c, d; vector<pl3> g[max_n]; ll n, m; ll s; const ll INF = 1e15; ll dp[max_n + 1][max_s + 1]; void dijkstra() { s = min(s, max_s); rep(i, n) rep(j, max_s + 1) dp[i][j] = INF; dp[0][s] = 0; priority_queue<pl3, vector<pl3>, greater<pl3>> que; que.push({0, {0, s}}); while (!que.empty()) { pl3 p = que.top(); que.pop(); ll time = p.first; ll v = p.second.first; ll ns = p.second.second; if (dp[v][ns] < time) continue; // 後から最短パスが見つかった場合、先にqueに入っているものはここではじかれる if (ns + c[v] <= max_s) { que.push({time + d[v], {v, ns + c[v]}}); } for (pl3 x : g[v]) { ll w = x.first; ll a = x.second.first; ll b = x.second.second; if (ns < a || dp[w][ns - a] <= time + b) continue; dp[w][ns - a] = time + b; que.push({time + b, {w, ns - a}}); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m >> s; rep(i, m) { ll u, v, a, b; cin >> u >> v >> a >> b; u--; v--; g[u].push_back({v, {a, b}}); g[v].push_back({u, {a, b}}); } c.resize(n); d.resize(n); rep(i, n) cin >> c[i] >> d[i]; dijkstra(); rep(i, n - 1) { ll ans = INF; rep(j, max_s + 1) ans = min(ans, dp[i + 1][j]); cout << ans << "\n"; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = (0); i < (n); i++) using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<ll, pll> pl3; const ll max_n = 52; const ll max_s = 2500; vector<ll> c, d; vector<pl3> g[max_n]; ll n, m; ll s; const ll INF = 1e15; ll dp[max_n + 1][max_s + 1]; void dijkstra() { s = min(s, max_s); rep(i, n) rep(j, max_s + 1) dp[i][j] = INF; dp[0][s] = 0; priority_queue<pl3, vector<pl3>, greater<pl3>> que; que.push({0, {0, s}}); while (!que.empty()) { pl3 p = que.top(); que.pop(); ll time = p.first; ll v = p.second.first; ll ns = p.second.second; if (dp[v][ns] < time) continue; // 後から最短パスが見つかった場合、先にqueに入っているものはここではじかれる if (ns + c[v] <= max_s && dp[v][ns + c[v]] > time + d[v]) { dp[v][ns + c[v]] = time + d[v]; que.push({time + d[v], {v, ns + c[v]}}); } for (pl3 x : g[v]) { ll w = x.first; ll a = x.second.first; ll b = x.second.second; if (ns < a || dp[w][ns - a] <= time + b) continue; dp[w][ns - a] = time + b; que.push({time + b, {w, ns - a}}); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m >> s; rep(i, m) { ll u, v, a, b; cin >> u >> v >> a >> b; u--; v--; g[u].push_back({v, {a, b}}); g[v].push_back({u, {a, b}}); } c.resize(n); d.resize(n); rep(i, n) cin >> c[i] >> d[i]; dijkstra(); rep(i, n - 1) { ll ans = INF; rep(j, max_s + 1) ans = min(ans, dp[i + 1][j]); cout << ans << "\n"; } }
replace
39
40
39
41
TLE
p02703
C++
Runtime Error
// #include<bits\stdc++.h> #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define ll long long #define db double #define INF 1000000000 #define ldb long double #define pb push_back #define get(x) x = read() #define gt(x) scanf("%d", &x) #define gi(x) scanf("%lf", &x) #define put(x) printf("%d\n", x) #define putl(x) printf("%lld\n", x) #define gc(a) scanf("%s", a + 1) #define rep(p, n, i) for (RE ll i = p; i <= n; ++i) #define go(x) for (ll i = lin[x], tn = ver[i]; i; tn = ver[i = nex[i]]) #define fep(n, p, i) for (RE ll i = n; i >= p; --i) #define pii pair<ll, ll> #define mk make_pair #define RE register #define P 1000000007 #define mod 998244353 #define S second #define F first #define gf(x) scanf("%lf", &x) #define pf(x) ((x) * (x)) #define ull unsigned long long #define ui unsigned #define zz p << 1 #define yy p << 1 | 1 using namespace std; char buf[1 << 15], *fs, *ft; inline char getc() { return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft)) ? 0 : *fs++; } inline ll read() { register ll x = 0, f = 1; register char ch = getc(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getc(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getc(); } return x * f; } const ll MAXN = 252; ll n, m, S, cnt, len; ll w[MAXN], vis[MAXN], c[MAXN], ans[MAXN], b[52][MAXN * 10]; ll lin[MAXN], ver[MAXN], nex[MAXN], e[MAXN], e1[MAXN]; struct wy { ll x, v, s; ll friend operator<(wy a, wy b) { return a.v > b.v; } }; inline void add(ll x, ll y, ll z, ll z1) { ver[++len] = y; nex[len] = lin[x]; lin[x] = len; e[len] = z; e1[len] = z1; } priority_queue<wy> q; inline void dij() { q.push((wy){1, 0, S}); vis[1] = 1; while (q.size()) { wy cc = q.top(); q.pop(); if (!vis[cc.x]) vis[cc.x] = cc.v, --cnt; if (b[cc.x][cc.s]) continue; b[cc.x][cc.s] = 1; if (!cnt) return; if (cc.s >= 2500) ; else q.push((wy){cc.x, cc.v + w[cc.x], min(cc.s + c[cc.x], 2518ll)}); go(cc.x) { if (cc.s >= e1[i]) q.push((wy){tn, cc.v + e[i], cc.s - e1[i]}); } } } signed main() { // freopen("1.in","r",stdin); get(n); get(m); get(S); cnt = n - 1; rep(1, m, i) { ll get(x), get(y), get(z1), get(z); add(x, y, z, z1); add(y, x, z, z1); } rep(1, n, i) get(c[i]), get(w[i]); dij(); rep(2, n, i) putl(vis[i]); return 0; }
// #include<bits\stdc++.h> #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define ll long long #define db double #define INF 1000000000 #define ldb long double #define pb push_back #define get(x) x = read() #define gt(x) scanf("%d", &x) #define gi(x) scanf("%lf", &x) #define put(x) printf("%d\n", x) #define putl(x) printf("%lld\n", x) #define gc(a) scanf("%s", a + 1) #define rep(p, n, i) for (RE ll i = p; i <= n; ++i) #define go(x) for (ll i = lin[x], tn = ver[i]; i; tn = ver[i = nex[i]]) #define fep(n, p, i) for (RE ll i = n; i >= p; --i) #define pii pair<ll, ll> #define mk make_pair #define RE register #define P 1000000007 #define mod 998244353 #define S second #define F first #define gf(x) scanf("%lf", &x) #define pf(x) ((x) * (x)) #define ull unsigned long long #define ui unsigned #define zz p << 1 #define yy p << 1 | 1 using namespace std; char buf[1 << 15], *fs, *ft; inline char getc() { return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft)) ? 0 : *fs++; } inline ll read() { register ll x = 0, f = 1; register char ch = getc(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getc(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getc(); } return x * f; } const ll MAXN = 252; ll n, m, S, cnt, len; ll w[MAXN], vis[MAXN], c[MAXN], ans[MAXN], b[52][MAXN * 10]; ll lin[MAXN], ver[MAXN], nex[MAXN], e[MAXN], e1[MAXN]; struct wy { ll x, v, s; ll friend operator<(wy a, wy b) { return a.v > b.v; } }; inline void add(ll x, ll y, ll z, ll z1) { ver[++len] = y; nex[len] = lin[x]; lin[x] = len; e[len] = z; e1[len] = z1; } priority_queue<wy> q; inline void dij() { q.push((wy){1, 0, min(2518ll, S)}); vis[1] = 1; while (q.size()) { wy cc = q.top(); q.pop(); if (!vis[cc.x]) vis[cc.x] = cc.v, --cnt; if (b[cc.x][cc.s]) continue; b[cc.x][cc.s] = 1; if (!cnt) return; if (cc.s >= 2500) ; else q.push((wy){cc.x, cc.v + w[cc.x], min(cc.s + c[cc.x], 2518ll)}); go(cc.x) { if (cc.s >= e1[i]) q.push((wy){tn, cc.v + e[i], cc.s - e1[i]}); } } } signed main() { // freopen("1.in","r",stdin); get(n); get(m); get(S); cnt = n - 1; rep(1, m, i) { ll get(x), get(y), get(z1), get(z); add(x, y, z, z1); add(y, x, z, z1); } rep(1, n, i) get(c[i]), get(w[i]); dij(); rep(2, n, i) putl(vis[i]); return 0; }
replace
85
86
85
86
0
p02703
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int MAX_N = 52; struct Edge { int to; ll cost; ll time; Edge(int to = -1, int cost = -1, ll time = -1) { this->to = to; this->cost = cost; this->time = time; } }; vector<Edge> E[MAX_N]; struct Node { int v; ll coin; ll time; Node(int v = -1, ll coin = -1, ll time = -1) { this->v = v; this->coin = coin; this->time = time; } bool operator>(const Node &n) const { return time > n.time; } }; int main() { ll N, M, S; cin >> N >> M >> S; ll u, v, a, b; for (int i = 0; i < M; ++i) { cin >> u >> v >> a >> b; E[u].push_back(Edge(v, a, b)); E[v].push_back(Edge(u, a, b)); } ll ans[N + 1]; ll changeRate[N + 1]; ll changeTime[N + 1]; ll c, d; for (int i = 1; i <= N; ++i) { cin >> c >> d; ans[i] = LLONG_MAX; changeRate[i] = c; changeTime[i] = d; } ll LIMIT = 5000; priority_queue<Node, vector<Node>, greater<Node>> pque; pque.push(Node(1, min(LIMIT, S), 0)); ll minCoins[N + 1][LIMIT + 1]; bool visited[N + 1][LIMIT + 1]; memset(visited, false, sizeof(visited)); int cnt = 0; for (int i = 0; i <= N; ++i) { for (int j = 0; j <= LIMIT; ++j) { minCoins[i][j] = LLONG_MAX; } } while (!pque.empty()) { Node node = pque.top(); pque.pop(); if (visited[node.v][node.coin]) continue; visited[node.v][node.coin] = true; if (ans[node.v] > node.time) { fprintf(stderr, "%d: v: %d, coin: %lld, time: %lld\n", ++cnt, node.v, node.coin, node.time); } ans[node.v] = min(ans[node.v], node.time); for (int i = 0; i < E[node.v].size(); ++i) { Edge edge = E[node.v][i]; if (node.coin < edge.cost) continue; if (visited[edge.to][node.coin - edge.cost]) continue; // visited[edge.to][node.coin - edge.cost] = true; if (minCoins[edge.to][node.coin - edge.cost] <= node.time + edge.time) continue; minCoins[edge.to][node.coin - edge.cost] = node.time + edge.time; pque.push(Node(edge.to, node.coin - edge.cost, node.time + edge.time)); } while (node.coin < LIMIT) { node.coin += changeRate[node.v]; node.coin = min(LIMIT, node.coin); node.time += changeTime[node.v]; if (visited[node.v][node.coin]) break; // visited[node.v][node.coin] = true; if (minCoins[node.v][node.coin] <= node.time) break; minCoins[node.v][node.coin] = node.time; pque.push(node); } } for (int t = 2; t <= N; ++t) { cout << ans[t] << endl; } return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int MAX_N = 52; struct Edge { int to; ll cost; ll time; Edge(int to = -1, int cost = -1, ll time = -1) { this->to = to; this->cost = cost; this->time = time; } }; vector<Edge> E[MAX_N]; struct Node { int v; ll coin; ll time; Node(int v = -1, ll coin = -1, ll time = -1) { this->v = v; this->coin = coin; this->time = time; } bool operator>(const Node &n) const { return time > n.time; } }; int main() { ll N, M, S; cin >> N >> M >> S; ll u, v, a, b; for (int i = 0; i < M; ++i) { cin >> u >> v >> a >> b; E[u].push_back(Edge(v, a, b)); E[v].push_back(Edge(u, a, b)); } ll ans[N + 1]; ll changeRate[N + 1]; ll changeTime[N + 1]; ll c, d; for (int i = 1; i <= N; ++i) { cin >> c >> d; ans[i] = LLONG_MAX; changeRate[i] = c; changeTime[i] = d; } ll LIMIT = N * 100; priority_queue<Node, vector<Node>, greater<Node>> pque; pque.push(Node(1, min(LIMIT, S), 0)); ll minCoins[N + 1][LIMIT + 1]; bool visited[N + 1][LIMIT + 1]; memset(visited, false, sizeof(visited)); int cnt = 0; for (int i = 0; i <= N; ++i) { for (int j = 0; j <= LIMIT; ++j) { minCoins[i][j] = LLONG_MAX; } } while (!pque.empty()) { Node node = pque.top(); pque.pop(); if (visited[node.v][node.coin]) continue; visited[node.v][node.coin] = true; if (ans[node.v] > node.time) { fprintf(stderr, "%d: v: %d, coin: %lld, time: %lld\n", ++cnt, node.v, node.coin, node.time); } ans[node.v] = min(ans[node.v], node.time); for (int i = 0; i < E[node.v].size(); ++i) { Edge edge = E[node.v][i]; if (node.coin < edge.cost) continue; if (visited[edge.to][node.coin - edge.cost]) continue; // visited[edge.to][node.coin - edge.cost] = true; if (minCoins[edge.to][node.coin - edge.cost] <= node.time + edge.time) continue; minCoins[edge.to][node.coin - edge.cost] = node.time + edge.time; pque.push(Node(edge.to, node.coin - edge.cost, node.time + edge.time)); } while (node.coin < LIMIT) { node.coin += changeRate[node.v]; node.coin = min(LIMIT, node.coin); node.time += changeTime[node.v]; if (visited[node.v][node.coin]) break; // visited[node.v][node.coin] = true; if (minCoins[node.v][node.coin] <= node.time) break; minCoins[node.v][node.coin] = node.time; pque.push(node); } } for (int t = 2; t <= N; ++t) { cout << ans[t] << endl; } return 0; }
replace
69
70
69
70
TLE
p02703
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ar array #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define vt vector #define pb push_back #define all(c) (c).begin(), (c).end() #define sz(x) (int)(x).size() #define F_OR(i, a, b, s) \ for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto &x : a) template <class T> bool umin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool umax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } ll FIRSTTRUE(function<bool(ll)> f, ll lb, ll rb) { while (lb < rb) { ll mb = (lb + rb) / 2; f(mb) ? rb = mb : lb = mb + 1; } return lb; } ll LASTTRUE(function<bool(ll)> f, ll lb, ll rb) { while (lb < rb) { ll mb = (lb + rb + 1) / 2; f(mb) ? lb = mb : rb = mb - 1; } return lb; } template <class A> void read(vt<A> &v); template <class A, size_t S> void read(ar<A, S> &a); template <class T> void read(T &x) { cin >> x; } void read(double &d) { string t; read(t); d = stod(t); } void read(long double &d) { string t; read(t); d = stold(t); } template <class H, class... T> void read(H &h, T &...t) { read(h); read(t...); } template <class A> void read(vt<A> &x) { EACH(a, x) read(a); } template <class A, size_t S> void read(array<A, S> &x) { EACH(a, x) read(a); } string to_string(char c) { return string(1, c); } string to_string(bool b) { return b ? "true" : "false"; } string to_string(const char *s) { return string(s); } string to_string(string s) { return s; } string to_string(vt<bool> v) { string res; FOR(sz(v)) res += char('0' + v[i]); return res; } template <size_t S> string to_string(bitset<S> b) { string res; FOR(S) res += char('0' + b[i]); return res; } template <class T> string to_string(T v) { bool f = 1; string res; EACH(x, v) { if (!f) res += ' '; f = 0; res += to_string(x); } return res; } template <class A> void write(A x) { cout << to_string(x); } template <class H, class... T> void write(const H &h, const T &...t) { write(h); write(t...); } void print() { write("\n"); } template <class H, class... T> void print(const H &h, const T &...t) { write(h); if (sizeof...(t)) write(' '); print(t...); } void DBG() { cerr << "]" << endl; } template <class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef _DEBUG #define dbg(...) \ cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \ DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif template <class T> void offset(ll o, T &x) { x += o; } template <class T> void offset(ll o, vt<T> &x) { EACH(a, x) offset(o, a); } template <class T, size_t S> void offset(ll o, ar<T, S> &x) { EACH(a, x) offset(o, a); } mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count()); ll randint(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(mt_rng); } template <class T, class U> void vti(vt<T> &v, U x, size_t n) { v = vt<T>(n, x); } template <class T, class U> void vti(vt<T> &v, U x, size_t n, size_t m...) { v = vt<T>(n); EACH(a, v) vti(a, x, m); } const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1}; const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; typedef struct edge { ll dest, cost, minutes; } edge; class compare { public: bool operator()(ar<ll, 3> a, ar<ll, 3> b) { return a[0] > b[0]; } }; void solve() { ll n, m, s; read(n, m, s); vt<edge> adj[n]; ll a, b, c, d; FOR(m) { read(a, b, c, d); adj[--a].pb({--b, -c, d}); adj[b].pb({a, -c, d}); } FOR(n) { read(c, d); adj[i].pb({i, c, d}); } vt<vt<ll>> dp(n, vt<ll>(3001, 1e18)); priority_queue<ar<ll, 3>, vt<ar<ll, 3>>, compare> pq; // print(adj[0]);print(adj[1]);print(adj[2]); pq.push({0, 0, s}); dp[0][s] = 0; while (!pq.empty()) { ar<ll, 3> tmp = pq.top(); pq.pop(); ll tm = tmp[0]; ll v = tmp[1]; ll s = tmp[2]; // dbg(tm,v,s); if (tm > dp[v][s]) continue; EACH(x, adj[v]) { if (s + x.cost >= 0) { if (s == 3000 && x.cost > 0) continue; ll ns = min((ll)3000, s + x.cost); if (dp[x.dest][ns] > dp[v][s] + x.minutes) { dp[x.dest][ns] = dp[v][s] + x.minutes; pq.push({dp[v][s] + x.minutes, x.dest, ns}); } } } } vt<ll> dis(n, 1e18); FOR(i, 0, n) { FOR(j, 0, 3001) { dis[i] = min(dis[i], dp[i][j]); } } FOR(i, 1, n) { write(dis[i]); print(); } } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ar array #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define vt vector #define pb push_back #define all(c) (c).begin(), (c).end() #define sz(x) (int)(x).size() #define F_OR(i, a, b, s) \ for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto &x : a) template <class T> bool umin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool umax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } ll FIRSTTRUE(function<bool(ll)> f, ll lb, ll rb) { while (lb < rb) { ll mb = (lb + rb) / 2; f(mb) ? rb = mb : lb = mb + 1; } return lb; } ll LASTTRUE(function<bool(ll)> f, ll lb, ll rb) { while (lb < rb) { ll mb = (lb + rb + 1) / 2; f(mb) ? lb = mb : rb = mb - 1; } return lb; } template <class A> void read(vt<A> &v); template <class A, size_t S> void read(ar<A, S> &a); template <class T> void read(T &x) { cin >> x; } void read(double &d) { string t; read(t); d = stod(t); } void read(long double &d) { string t; read(t); d = stold(t); } template <class H, class... T> void read(H &h, T &...t) { read(h); read(t...); } template <class A> void read(vt<A> &x) { EACH(a, x) read(a); } template <class A, size_t S> void read(array<A, S> &x) { EACH(a, x) read(a); } string to_string(char c) { return string(1, c); } string to_string(bool b) { return b ? "true" : "false"; } string to_string(const char *s) { return string(s); } string to_string(string s) { return s; } string to_string(vt<bool> v) { string res; FOR(sz(v)) res += char('0' + v[i]); return res; } template <size_t S> string to_string(bitset<S> b) { string res; FOR(S) res += char('0' + b[i]); return res; } template <class T> string to_string(T v) { bool f = 1; string res; EACH(x, v) { if (!f) res += ' '; f = 0; res += to_string(x); } return res; } template <class A> void write(A x) { cout << to_string(x); } template <class H, class... T> void write(const H &h, const T &...t) { write(h); write(t...); } void print() { write("\n"); } template <class H, class... T> void print(const H &h, const T &...t) { write(h); if (sizeof...(t)) write(' '); print(t...); } void DBG() { cerr << "]" << endl; } template <class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef _DEBUG #define dbg(...) \ cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", \ DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif template <class T> void offset(ll o, T &x) { x += o; } template <class T> void offset(ll o, vt<T> &x) { EACH(a, x) offset(o, a); } template <class T, size_t S> void offset(ll o, ar<T, S> &x) { EACH(a, x) offset(o, a); } mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count()); ll randint(ll a, ll b) { return uniform_int_distribution<ll>(a, b)(mt_rng); } template <class T, class U> void vti(vt<T> &v, U x, size_t n) { v = vt<T>(n, x); } template <class T, class U> void vti(vt<T> &v, U x, size_t n, size_t m...) { v = vt<T>(n); EACH(a, v) vti(a, x, m); } const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1}; const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; typedef struct edge { ll dest, cost, minutes; } edge; class compare { public: bool operator()(ar<ll, 3> a, ar<ll, 3> b) { return a[0] > b[0]; } }; void solve() { ll n, m, s; read(n, m, s); vt<edge> adj[n]; ll a, b, c, d; FOR(m) { read(a, b, c, d); adj[--a].pb({--b, -c, d}); adj[b].pb({a, -c, d}); } FOR(n) { read(c, d); adj[i].pb({i, c, d}); } vt<vt<ll>> dp(n, vt<ll>(3001, 1e18)); priority_queue<ar<ll, 3>, vt<ar<ll, 3>>, compare> pq; // print(adj[0]);print(adj[1]);print(adj[2]); s = min(s, 3000ll); pq.push({0, 0, s}); dp[0][s] = 0; while (!pq.empty()) { ar<ll, 3> tmp = pq.top(); pq.pop(); ll tm = tmp[0]; ll v = tmp[1]; ll s = tmp[2]; // dbg(tm,v,s); if (tm > dp[v][s]) continue; EACH(x, adj[v]) { if (s + x.cost >= 0) { if (s == 3000 && x.cost > 0) continue; ll ns = min((ll)3000, s + x.cost); if (dp[x.dest][ns] > dp[v][s] + x.minutes) { dp[x.dest][ns] = dp[v][s] + x.minutes; pq.push({dp[v][s] + x.minutes, x.dest, ns}); } } } } vt<ll> dis(n, 1e18); FOR(i, 0, n) { FOR(j, 0, 3001) { dis[i] = min(dis[i], dp[i][j]); } } FOR(i, 1, n) { write(dis[i]); print(); } } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); }
insert
182
182
182
183
0
p02703
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; // const ll mod=998244353; const ll inf = 1LL << 61; typedef pair<ll, pll> ppll; int main() { ll n, m, s; cin >> n >> m >> s; vector<map<ll, pll>> G(n); for (ll i = 0; i < m; i++) { ll u, v, a, b; cin >> u >> v >> a >> b; u--, v--; G[u][v] = {a, b}; G[v][u] = {a, b}; } vec mai(n), mnu(n); for (ll i = 0; i < n; i++) { cin >> mai[i] >> mnu[i]; } mat d(n, vec(50 * (n - 1) + 1, -1)); vec ans(n, -1); vec mins(n, -1); priority_queue<ppll, vector<ppll>, greater<ppll>> q; s = min(s, 50 * (n - 1)); q.push({0, {0, s}}); while (q.size()) { ll td = q.top().first; ll f = q.top().second.first; ll s = q.top().second.second; q.pop(); ll flag = 0; if (ans[f] < 0) ans[f] = td; if (d[f][s] > -1) continue; d[f][s] = td; mins[f] = s; for (auto p : G[f]) { ll t = p.first; ll co = p.second.first; ll v = p.second.second; if (s - co >= 0 && d[t][s - co] == -1) { q.push({td + v, {t, s - co}}); } } for (ll i = 0; 1; i++) { ll ns = min(s + i * mai[f], 50 * (n - 1)); ll nd = td + i * mnu[f]; if (d[f][ns] == -1) q.push({nd, {f, ns}}); if (ns == 50 * (n - 1)) break; } } for (ll i = 1; i < n; i++) { cout << ans[i] << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; // const ll mod=998244353; const ll inf = 1LL << 61; typedef pair<ll, pll> ppll; int main() { ll n, m, s; cin >> n >> m >> s; vector<map<ll, pll>> G(n); for (ll i = 0; i < m; i++) { ll u, v, a, b; cin >> u >> v >> a >> b; u--, v--; G[u][v] = {a, b}; G[v][u] = {a, b}; } vec mai(n), mnu(n); for (ll i = 0; i < n; i++) { cin >> mai[i] >> mnu[i]; } mat d(n, vec(50 * (n - 1) + 1, -1)); vec ans(n, -1); vec mins(n, -1); priority_queue<ppll, vector<ppll>, greater<ppll>> q; s = min(s, 50 * (n - 1)); q.push({0, {0, s}}); while (q.size()) { ll td = q.top().first; ll f = q.top().second.first; ll s = q.top().second.second; q.pop(); ll flag = 0; if (ans[f] < 0) ans[f] = td; if (d[f][s] > -1) continue; d[f][s] = td; mins[f] = s; for (auto p : G[f]) { ll t = p.first; ll co = p.second.first; ll v = p.second.second; if (s - co >= 0 && d[t][s - co] == -1) { q.push({td + v, {t, s - co}}); } } ll ns = min(s + mai[f], 50 * (n - 1)); ll nd = td + mnu[f]; if (d[f][ns] == -1) q.push({nd, {f, ns}}); } for (ll i = 1; i < n; i++) { cout << ans[i] << endl; } }
replace
53
61
53
57
TLE
p02703
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pii; #define fi first #define se second #define mod 1000000007 #define maxn 2500ll #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" struct Cell { ll v, cst, mt; }; vector<Cell> adj[55]; ll dp[55][2505]; pii a[55]; ll dijkstra(ll u, ll c) { set<pair<ll, pii>> st; pii temp; temp.fi = u; temp.se = c; st.insert({0, temp}); dp[u][c] = 0; while (!st.empty()) { pair<ll, pii> temp = *st.begin(); st.erase(st.begin()); ll mnt = temp.fi; u = (temp.se).fi; c = (temp.se).se; if (c < maxn) { ll val = min(maxn, c + a[u].fi); ll &res = dp[u][val]; if (res > mnt + a[u].se) { st.erase({res, {u, val}}); res = mnt + a[u].se; st.insert({res, {u, val}}); } } for (auto it = adj[u].begin(); it != adj[u].end(); it++) { Cell temp = *it; if (c >= temp.cst) { ll &res = dp[temp.v][c - temp.cst]; if (res > mnt + temp.mt) { st.erase({res, {temp.v, c - temp.cst}}); res = mnt + temp.mt; st.insert({res, {temp.v, c - temp.cst}}); } } } } } int main() { ios; ll i, m, s, n, u, j, k; cin >> n >> m >> s; s = min(s, maxn); for (i = 1; i <= m; i++) { Cell temp; cin >> u >> temp.v >> temp.cst >> temp.mt; adj[u].push_back(temp); swap(temp.v, u); adj[u].push_back(temp); } for (i = 1; i <= n; i++) cin >> a[i].fi >> a[i].se; for (i = 1; i <= n; i++) { for (j = 0; j <= maxn; j++) dp[i][j] = LLONG_MAX; } dijkstra(1, s); for (i = 2; i <= n; i++) { ll min1 = LLONG_MAX; for (j = 0; j <= maxn; j++) min1 = min(min1, dp[i][j]); cout << min1 << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pii; #define fi first #define se second #define mod 1000000007 #define maxn 2500ll #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl "\n" struct Cell { ll v, cst, mt; }; vector<Cell> adj[55]; ll dp[55][2505]; pii a[55]; void dijkstra(ll u, ll c) { set<pair<ll, pii>> st; pii temp; temp.fi = u; temp.se = c; st.insert({0, temp}); dp[u][c] = 0; while (!st.empty()) { pair<ll, pii> temp = *st.begin(); st.erase(st.begin()); ll mnt = temp.fi; u = (temp.se).fi; c = (temp.se).se; if (c < maxn) { ll val = min(maxn, c + a[u].fi); ll &res = dp[u][val]; if (res > mnt + a[u].se) { st.erase({res, {u, val}}); res = mnt + a[u].se; st.insert({res, {u, val}}); } } for (auto it = adj[u].begin(); it != adj[u].end(); it++) { Cell temp = *it; if (c >= temp.cst) { ll &res = dp[temp.v][c - temp.cst]; if (res > mnt + temp.mt) { st.erase({res, {temp.v, c - temp.cst}}); res = mnt + temp.mt; st.insert({res, {temp.v, c - temp.cst}}); } } } } } int main() { ios; ll i, m, s, n, u, j, k; cin >> n >> m >> s; s = min(s, maxn); for (i = 1; i <= m; i++) { Cell temp; cin >> u >> temp.v >> temp.cst >> temp.mt; adj[u].push_back(temp); swap(temp.v, u); adj[u].push_back(temp); } for (i = 1; i <= n; i++) cin >> a[i].fi >> a[i].se; for (i = 1; i <= n; i++) { for (j = 0; j <= maxn; j++) dp[i][j] = LLONG_MAX; } dijkstra(1, s); for (i = 2; i <= n; i++) { ll min1 = LLONG_MAX; for (j = 0; j <= maxn; j++) min1 = min(min1, dp[i][j]); cout << min1 << endl; } }
replace
19
20
19
20
0
p02703
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long const int maxn = 55; const ll INF = 1e15; ll all = 0; struct Node { ll id, dis, level; bool operator<(const Node &a) const { return dis > a.dis; } }; ll u[maxn * 2], v[maxn * 2], w[maxn * 2], cost[maxn * 2], nextt[maxn * 2], first[maxn], sign; int book[maxn][2505], n, m; ll dist[maxn][2505]; pair<ll, ll> G[maxn]; void addedge(ll a, ll b, ll c, ll d) { u[++sign] = a; v[sign] = b; w[sign] = c; cost[sign] = d; nextt[sign] = first[a]; first[a] = sign; } priority_queue<Node> Q; void Dijstra(int s, ll money) { while (Q.size()) Q.pop(); for (int i = 1; i <= n; i++) { for (int j = 0; j <= 2500; j++) book[i][j] = 0, dist[i][j] = INF; } dist[s][money] = 0; Q.push({s, 0, money}); while (Q.size()) { Node temp = Q.top(); Q.pop(); ll dis = temp.dis, id = temp.id, level = temp.level; if (book[id][level]) continue; book[id][level] = 1; for (int i = first[id]; i; i = nextt[i]) { if (level < cost[i]) continue; if (dist[v[i]][level - cost[i]] > dis + w[i]) { dist[v[i]][level - cost[i]] = dis + w[i]; Q.push({v[i], dist[v[i]][level - cost[i]], level - cost[i]}); } } if (dist[id][min(2500ll, level + G[id].first)] > dis + G[id].second) { dist[id][min(2500ll, level + G[id].first)] = dis + G[id].second; Q.push({id, dist[id][min(2500ll, level + G[id].first)], min(2500ll, level + G[id].first)}); } } } int main() { ios::sync_with_stdio(false); ll s; cin >> n >> m >> s; for (int i = 1; i <= m; i++) { int x, y, a, b; cin >> x >> y >> a >> b; addedge(x, y, b, a); addedge(y, x, b, a); all += a; } for (int i = 1; i <= n; i++) { ll c, d; cin >> c >> d; G[i].first = c; G[i].second = d; } Dijstra(1, min(s, 2500ll)); for (int i = 2; i <= n; i++) { ll ans = INF; for (int j = 0; j <= 2500; j++) ans = min(ans, dist[i][j]); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const int maxn = 55; const ll INF = 1e15; ll all = 0; struct Node { ll id, dis, level; bool operator<(const Node &a) const { return dis > a.dis; } }; ll u[maxn * 4], v[maxn * 4], w[maxn * 4], cost[maxn * 4], nextt[maxn * 4], first[maxn], sign; int book[maxn][2505], n, m; ll dist[maxn][2505]; pair<ll, ll> G[maxn]; void addedge(ll a, ll b, ll c, ll d) { u[++sign] = a; v[sign] = b; w[sign] = c; cost[sign] = d; nextt[sign] = first[a]; first[a] = sign; } priority_queue<Node> Q; void Dijstra(int s, ll money) { while (Q.size()) Q.pop(); for (int i = 1; i <= n; i++) { for (int j = 0; j <= 2500; j++) book[i][j] = 0, dist[i][j] = INF; } dist[s][money] = 0; Q.push({s, 0, money}); while (Q.size()) { Node temp = Q.top(); Q.pop(); ll dis = temp.dis, id = temp.id, level = temp.level; if (book[id][level]) continue; book[id][level] = 1; for (int i = first[id]; i; i = nextt[i]) { if (level < cost[i]) continue; if (dist[v[i]][level - cost[i]] > dis + w[i]) { dist[v[i]][level - cost[i]] = dis + w[i]; Q.push({v[i], dist[v[i]][level - cost[i]], level - cost[i]}); } } if (dist[id][min(2500ll, level + G[id].first)] > dis + G[id].second) { dist[id][min(2500ll, level + G[id].first)] = dis + G[id].second; Q.push({id, dist[id][min(2500ll, level + G[id].first)], min(2500ll, level + G[id].first)}); } } } int main() { ios::sync_with_stdio(false); ll s; cin >> n >> m >> s; for (int i = 1; i <= m; i++) { int x, y, a, b; cin >> x >> y >> a >> b; addedge(x, y, b, a); addedge(y, x, b, a); all += a; } for (int i = 1; i <= n; i++) { ll c, d; cin >> c >> d; G[i].first = c; G[i].second = d; } Dijstra(1, min(s, 2500ll)); for (int i = 2; i <= n; i++) { ll ans = INF; for (int j = 0; j <= 2500; j++) ans = min(ans, dist[i][j]); cout << ans << endl; } return 0; }
replace
10
11
10
11
0
p02703
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <cfloat> #include <climits> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <tuple> #include <vector> using ll = long long; using namespace std; // LLONG_MAX = 90^18 #define int long long #define CONTAINS(v, n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a) + (size)) #define REMOVE(v, a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v, a) (reverse((v), (v) + (a))) #define LOWER_BOUND(v, a) (lower_bound((v).begin(), (v).end(), (a))) #define UPPER_BOUND(v, a) (upper_bound((v).begin(), (v).end(), (a))) #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define CONTAINS_MAP(m, a) (m).find((a)) != m.end() void YesNo(bool b) { cout << (b ? "Yes" : "No"); } void Yes() { cout << "Yes"; } void No() { cout << "No"; } //---------- ダイクストラ pair<index,len> ---------- void dijkstra(int node_size, vector<pair<int, int>> *link, bool *used, int s, int *result) { REP(i, node_size) { result[i] = INT64_MAX; used[i] = false; } result[s] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q; // len, index q.push(pair<int, int>(0, s)); while (q.size() > 0) { int d, p; tie(d, p) = q.top(); q.pop(); if (used[p]) continue; used[p] = true; for (pair<int, int> &l : link[p]) { if (result[l.first] > d + l.second) { result[l.first] = d + l.second; q.push(pair<int, int>(d + l.second, l.first)); } } } } int N, M, S; vector<int> src_link[51]; int len[51][51]; int cost[51][51]; int C[51]; int D[51]; const int MAX_GINKA = 150000; const int NODE_SIZE = MAX_GINKA * 51; vector<pair<int, int>> _link[NODE_SIZE]; bool _used[NODE_SIZE]; int _result[NODE_SIZE]; signed main() { cin >> N >> M >> S; REP(i, M) { int u, v, a, b; cin >> u >> v >> a >> b; src_link[u].push_back(v); src_link[v].push_back(u); len[u][v] = b; len[v][u] = b; cost[u][v] = a; cost[v][u] = a; } REP(i, N) { cin >> C[i + 1] >> D[i + 1]; } for (int i = 1; i <= N; i++) { for (int j = 0; j < MAX_GINKA; j++) { int c = min(MAX_GINKA - 1, j + C[i]); int d = D[i]; int src = i * MAX_GINKA + j; int dest = i * MAX_GINKA + c; _link[src].push_back(make_pair(dest, d)); } } for (int i = 1; i <= N; i++) { for (int l : src_link[i]) { for (int j = 0; j < MAX_GINKA; j++) { if (cost[i][l] <= j) { int src = i * MAX_GINKA + j; int dest = l * MAX_GINKA + (j - cost[i][l]); _link[src].push_back(make_pair(dest, len[i][l])); } } } } int node_size = MAX_GINKA * 51; int s = min(S, MAX_GINKA - 1); dijkstra(node_size, _link, _used, 1 * MAX_GINKA + s, _result); int min_len[51] = {}; for (int i = 1; i <= N; i++) { min_len[i] = LLONG_MAX; } for (int i = 1; i <= N; i++) { for (int j = 0; j < MAX_GINKA; j++) { int len = _result[i * MAX_GINKA + j]; if (len < LLONG_MAX) { min_len[i] = min(len, min_len[i]); } } } for (int i = 2; i <= N; i++) { cout << min_len[i] << endl; } }
#define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <cfloat> #include <climits> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <tuple> #include <vector> using ll = long long; using namespace std; // LLONG_MAX = 90^18 #define int long long #define CONTAINS(v, n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a) + (size)) #define REMOVE(v, a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v, a) (reverse((v), (v) + (a))) #define LOWER_BOUND(v, a) (lower_bound((v).begin(), (v).end(), (a))) #define UPPER_BOUND(v, a) (upper_bound((v).begin(), (v).end(), (a))) #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define CONTAINS_MAP(m, a) (m).find((a)) != m.end() void YesNo(bool b) { cout << (b ? "Yes" : "No"); } void Yes() { cout << "Yes"; } void No() { cout << "No"; } //---------- ダイクストラ pair<index,len> ---------- void dijkstra(int node_size, vector<pair<int, int>> *link, bool *used, int s, int *result) { REP(i, node_size) { result[i] = INT64_MAX; used[i] = false; } result[s] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q; // len, index q.push(pair<int, int>(0, s)); while (q.size() > 0) { int d, p; tie(d, p) = q.top(); q.pop(); if (used[p]) continue; used[p] = true; for (pair<int, int> &l : link[p]) { if (result[l.first] > d + l.second) { result[l.first] = d + l.second; q.push(pair<int, int>(d + l.second, l.first)); } } } } int N, M, S; vector<int> src_link[51]; int len[51][51]; int cost[51][51]; int C[51]; int D[51]; const int MAX_GINKA = 20000; const int NODE_SIZE = MAX_GINKA * 51; vector<pair<int, int>> _link[NODE_SIZE]; bool _used[NODE_SIZE]; int _result[NODE_SIZE]; signed main() { cin >> N >> M >> S; REP(i, M) { int u, v, a, b; cin >> u >> v >> a >> b; src_link[u].push_back(v); src_link[v].push_back(u); len[u][v] = b; len[v][u] = b; cost[u][v] = a; cost[v][u] = a; } REP(i, N) { cin >> C[i + 1] >> D[i + 1]; } for (int i = 1; i <= N; i++) { for (int j = 0; j < MAX_GINKA; j++) { int c = min(MAX_GINKA - 1, j + C[i]); int d = D[i]; int src = i * MAX_GINKA + j; int dest = i * MAX_GINKA + c; _link[src].push_back(make_pair(dest, d)); } } for (int i = 1; i <= N; i++) { for (int l : src_link[i]) { for (int j = 0; j < MAX_GINKA; j++) { if (cost[i][l] <= j) { int src = i * MAX_GINKA + j; int dest = l * MAX_GINKA + (j - cost[i][l]); _link[src].push_back(make_pair(dest, len[i][l])); } } } } int node_size = MAX_GINKA * 51; int s = min(S, MAX_GINKA - 1); dijkstra(node_size, _link, _used, 1 * MAX_GINKA + s, _result); int min_len[51] = {}; for (int i = 1; i <= N; i++) { min_len[i] = LLONG_MAX; } for (int i = 1; i <= N; i++) { for (int j = 0; j < MAX_GINKA; j++) { int len = _result[i * MAX_GINKA + j]; if (len < LLONG_MAX) { min_len[i] = min(len, min_len[i]); } } } for (int i = 2; i <= N; i++) { cout << min_len[i] << endl; } }
replace
74
75
74
75
TLE
p02703
Python
Time Limit Exceeded
import heapq N, M, init_silver = map(int, input().split()) MAX_COST = 2500 init_silver = min(init_silver, MAX_COST) G = [[] for _ in range(N)] for i in range(M): u, v, silver_cost, time_cost = map(int, input().split()) u, v = u - 1, v - 1 G[u].append([v, silver_cost, time_cost]) G[v].append([u, silver_cost, time_cost]) change_rate, change_cost = [], [] for i in range(N): rate, cost = map(int, input().split()) change_rate.append(rate) change_cost.append(cost) # dp[i][silver] := 頂点iにいて銀貨をsilver枚持っているような状況を作るために必要な最小時間 dp = [[float("inf")] * (MAX_COST + 1) for _ in range(N)] dp[0][init_silver] = 0 # 優先度付きキュー: (time, node, silver) hq = [(0, 0, init_silver)] while hq: time, node, silver = heapq.heappop(hq) self_loop_silver = min(silver + change_rate[node], MAX_COST) self_loop_cost = time + change_cost[node] if self_loop_cost < dp[node][self_loop_silver]: dp[node][self_loop_silver] = self_loop_cost heapq.heappush(hq, (time + change_cost[node], node, self_loop_silver)) for to, silver_cost, time_cost in G[node]: remain_silver = min(silver - silver_cost, MAX_COST) if remain_silver < 0: continue dp_next_value = time + time_cost if dp[to][remain_silver] < dp_next_value: continue dp[to][remain_silver] = dp_next_value heapq.heappush(hq, (dp_next_value, to, remain_silver)) print(*[min(d) for d in dp[1:]], sep="\n")
import heapq N, M, init_silver = map(int, input().split()) MAX_COST = 2500 init_silver = min(init_silver, MAX_COST) G = [[] for _ in range(N)] for i in range(M): u, v, silver_cost, time_cost = map(int, input().split()) u, v = u - 1, v - 1 G[u].append([v, silver_cost, time_cost]) G[v].append([u, silver_cost, time_cost]) change_rate, change_cost = [], [] for i in range(N): rate, cost = map(int, input().split()) change_rate.append(rate) change_cost.append(cost) # dp[i][silver] := 頂点iにいて銀貨をsilver枚持っているような状況を作るために必要な最小時間 dp = [[float("inf")] * (MAX_COST + 1) for _ in range(N)] dp[0][init_silver] = 0 # 優先度付きキュー: (time, node, silver) hq = [(0, 0, init_silver)] while hq: time, node, silver = heapq.heappop(hq) self_loop_silver = min(silver + change_rate[node], MAX_COST) self_loop_cost = time + change_cost[node] if self_loop_cost < dp[node][self_loop_silver]: dp[node][self_loop_silver] = self_loop_cost heapq.heappush(hq, (time + change_cost[node], node, self_loop_silver)) for to, silver_cost, time_cost in G[node]: remain_silver = min(silver - silver_cost, MAX_COST) if remain_silver < 0: continue dp_next_value = time + time_cost if dp[to][remain_silver] <= dp_next_value: continue dp[to][remain_silver] = dp_next_value heapq.heappush(hq, (dp_next_value, to, remain_silver)) print(*[min(d) for d in dp[1:]], sep="\n")
replace
41
42
41
42
TLE
p02703
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef tuple<ll, ll, ll> T; const ll inf = 1e18; const ll MAX = 2500; ll N, S; vector<pair<ll, pair<ll, ll>>> g[100]; ll c[100], d[100]; void solve(int x) { vector<vector<ll>> dp(N + 1, vector<ll>(MAX + 1, inf)); priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> que; que.push({0, {x, S}}); dp[0][S] = 0; while (!que.empty()) { pair<ll, pair<ll, ll>> p = que.top(); que.pop(); ll time = p.first; ll u = p.second.first; ll cost = p.second.second; if (time > dp[u][cost]) continue; if (cost + c[u] <= MAX) { ll n_cost = cost + c[u]; ll n_time = time + d[u]; if (dp[u][n_cost] > n_time) { dp[u][n_cost] = n_time; que.push({n_time, {u, n_cost}}); } } for (auto tmp : g[u]) { ll v = tmp.first; ll a = tmp.second.first; ll b = tmp.second.second; ll n_cost = cost - a; if (n_cost < 0) continue; ll n_time = time + b; if (dp[v][n_cost] > n_time) { dp[v][n_cost] = n_time; que.push({n_time, {v, n_cost}}); } } } for (int i = 1; i < N; i++) { ll ans = inf; for (int j = 0; j <= MAX; j++) { ans = min(dp[i][j], ans); } cout << ans << endl; } } int main() { ll M; cin >> N >> M >> S; for (int i = 0; i < M; i++) { ll u, v; cin >> u >> v; u--; v--; ll a, b; cin >> a >> b; g[u].push_back({v, {a, b}}); g[v].push_back({u, {a, b}}); } for (int i = 0; i < N; i++) { cin >> c[i] >> d[i]; } solve(0); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef tuple<ll, ll, ll> T; const ll inf = 1e18; const ll MAX = 2500; ll N, S; vector<pair<ll, pair<ll, ll>>> g[100]; ll c[100], d[100]; void solve(int x) { if (S >= MAX) S = MAX; vector<vector<ll>> dp(N + 1, vector<ll>(MAX + 1, inf)); priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> que; que.push({0, {x, S}}); dp[0][S] = 0; while (!que.empty()) { pair<ll, pair<ll, ll>> p = que.top(); que.pop(); ll time = p.first; ll u = p.second.first; ll cost = p.second.second; if (time > dp[u][cost]) continue; if (cost + c[u] <= MAX) { ll n_cost = cost + c[u]; ll n_time = time + d[u]; if (dp[u][n_cost] > n_time) { dp[u][n_cost] = n_time; que.push({n_time, {u, n_cost}}); } } for (auto tmp : g[u]) { ll v = tmp.first; ll a = tmp.second.first; ll b = tmp.second.second; ll n_cost = cost - a; if (n_cost < 0) continue; ll n_time = time + b; if (dp[v][n_cost] > n_time) { dp[v][n_cost] = n_time; que.push({n_time, {v, n_cost}}); } } } for (int i = 1; i < N; i++) { ll ans = inf; for (int j = 0; j <= MAX; j++) { ans = min(dp[i][j], ans); } cout << ans << endl; } } int main() { ll M; cin >> N >> M >> S; for (int i = 0; i < M; i++) { ll u, v; cin >> u >> v; u--; v--; ll a, b; cin >> a >> b; g[u].push_back({v, {a, b}}); g[v].push_back({u, {a, b}}); } for (int i = 0; i < N; i++) { cin >> c[i] >> d[i]; } solve(0); }
insert
13
13
13
15
0
p02703
C++
Time Limit Exceeded
#pragma GCC optimize("Ofast") #include <algorithm> #include <queue> #include <stdio.h> #include <vector> using namespace std; struct Edge { long long to, cost, dis; // used in state is cur_v,cur_money,distance with node 1 }; vector<Edge> g[55]; long long c[55], d[55], dp[55][2550], maxv = 2500; struct cmp { bool operator()(const Edge a, const Edge b) const { return a.dis > b.dis; } }; priority_queue<Edge, vector<Edge>, cmp> pq; int main() { long long i, j, n, m, s, u, v, a, b; scanf("%lld%lld%lld", &n, &m, &s); for (i = 0; i < m; i++) { scanf("%lld%lld%lld%lld", &u, &v, &a, &b); g[u].emplace_back((Edge){v, a, b}); g[v].emplace_back((Edge){u, a, b}); } for (i = 1; i <= n; i++) scanf("%lld%lld", &c[i], &d[i]); for (i = 0; i < 55; i++) for (j = 0; j < 2550; j++) dp[i][j] = 100000000000000000; s = min(s, maxv); pq.push({1, s, 0}); dp[1][s] = 0; while (pq.size()) { auto x = pq.top(); pq.pop(); for (auto y : g[x.to]) { for (i = 0;; i++) { if (x.cost + i * c[x.to] < y.cost) continue; if (dp[y.to][min(x.cost + i * c[x.to] - y.cost, maxv)] > dp[x.to][x.cost] + i * d[x.to] + y.dis) { dp[y.to][min(x.cost + i * c[x.to] - y.cost, maxv)] = dp[x.to][x.cost] + i * d[x.to] + y.dis; pq.push({y.to, min(x.cost + i * c[x.to] - y.cost, maxv), dp[y.to][min(x.cost + i * c[x.to] - y.cost, maxv)]}); } if (x.cost + i * c[x.to] - y.cost > maxv) break; } } } for (i = 2; i <= n; i++) printf("%lld\n", *min_element(dp[i], dp[i] + maxv)); }
#pragma GCC optimize("Ofast") #include <algorithm> #include <queue> #include <stdio.h> #include <vector> using namespace std; struct Edge { long long to, cost, dis; // used in state is cur_v,cur_money,distance with node 1 }; vector<Edge> g[55]; long long c[55], d[55], dp[55][2550], maxv = 2500; struct cmp { bool operator()(const Edge a, const Edge b) const { return a.dis > b.dis; } }; priority_queue<Edge, vector<Edge>, cmp> pq; int main() { long long i, j, n, m, s, u, v, a, b; scanf("%lld%lld%lld", &n, &m, &s); for (i = 0; i < m; i++) { scanf("%lld%lld%lld%lld", &u, &v, &a, &b); g[u].emplace_back((Edge){v, a, b}); g[v].emplace_back((Edge){u, a, b}); } for (i = 1; i <= n; i++) scanf("%lld%lld", &c[i], &d[i]); for (i = 0; i < 55; i++) for (j = 0; j < 2550; j++) dp[i][j] = 100000000000000000; s = min(s, maxv); pq.push({1, s, 0}); dp[1][s] = 0; while (pq.size()) { auto x = pq.top(); pq.pop(); if (dp[x.to][x.cost] < x.dis) continue; for (auto y : g[x.to]) { for (i = 0;; i++) { if (x.cost + i * c[x.to] < y.cost) continue; if (dp[y.to][min(x.cost + i * c[x.to] - y.cost, maxv)] > dp[x.to][x.cost] + i * d[x.to] + y.dis) { dp[y.to][min(x.cost + i * c[x.to] - y.cost, maxv)] = dp[x.to][x.cost] + i * d[x.to] + y.dis; pq.push({y.to, min(x.cost + i * c[x.to] - y.cost, maxv), dp[y.to][min(x.cost + i * c[x.to] - y.cost, maxv)]}); } if (x.cost + i * c[x.to] - y.cost > maxv) break; } } } for (i = 2; i <= n; i++) printf("%lld\n", *min_element(dp[i], dp[i] + maxv)); }
insert
35
35
35
37
TLE
p02703
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template <class T> ostream &operator<<(ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template <class T> ostream &operator<<(ostream &s, set<T> P) { for (auto it : P) { s << "<" << it << "> "; } return s << endl; } template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) { for (auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; } using pll = pair<long long, long long>; // (money, time) using Edge = pair<int, pll>; using Graph = vector<vector<Edge>>; const long long INF = 1LL << 60; const int MAX = 2500; int N, M; long long S; Graph G; vector<long long> C, D; // money, time void solve() { if (S >= MAX) S = MAX; vector<vector<long long>> dp(N, vector<long long>(MAX + 1, INF)); priority_queue<pair<long long, pll>, vector<pair<long long, pll>>, greater<pair<long long, pll>>> que; dp[0][S] = 0; que.push(make_pair(0, pll(0, S))); while (!que.empty()) { auto p = que.top(); que.pop(); // COUT(p); long long time = p.first; int v = p.second.first; long long s = p.second.second; if (time > dp[v][s]) continue; { long long ns = s + C[v]; long long ntime = time + D[v]; if (chmin(dp[v][ns], ntime)) { que.push(make_pair(ntime, pll(v, ns))); } } for (auto e : G[v]) { if (s < e.second.first) continue; int nv = e.first; long long ns = s - e.second.first; long long ntime = time + e.second.second; if (chmin(dp[nv][ns], ntime)) { que.push(make_pair(ntime, pll(nv, ns))); } } } for (int v = 1; v < N; ++v) { long long res = INF; for (int s = 0; s <= MAX; ++s) chmin(res, dp[v][s]); cout << res << endl; } } int main() { while (cin >> N >> M >> S) { G.assign(N, vector<Edge>()); for (int i = 0; i < M; ++i) { long long u, v, a, b; cin >> u >> v >> a >> b; --u, --v; G[u].push_back(Edge(v, pll(a, b))); G[v].push_back(Edge(u, pll(a, b))); } C.resize(N); D.resize(N); for (int i = 0; i < N; ++i) cin >> C[i] >> D[i]; solve(); } }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl template <class T1, class T2> ostream &operator<<(ostream &s, pair<T1, T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template <class T> ostream &operator<<(ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template <class T> ostream &operator<<(ostream &s, vector<vector<T>> P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template <class T> ostream &operator<<(ostream &s, set<T> P) { for (auto it : P) { s << "<" << it << "> "; } return s << endl; } template <class T1, class T2> ostream &operator<<(ostream &s, map<T1, T2> P) { for (auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; } using pll = pair<long long, long long>; // (money, time) using Edge = pair<int, pll>; using Graph = vector<vector<Edge>>; const long long INF = 1LL << 60; const int MAX = 2500; int N, M; long long S; Graph G; vector<long long> C, D; // money, time void solve() { if (S >= MAX) S = MAX; vector<vector<long long>> dp(N, vector<long long>(MAX + 1, INF)); priority_queue<pair<long long, pll>, vector<pair<long long, pll>>, greater<pair<long long, pll>>> que; dp[0][S] = 0; que.push(make_pair(0, pll(0, S))); while (!que.empty()) { auto p = que.top(); que.pop(); // COUT(p); long long time = p.first; int v = p.second.first; long long s = p.second.second; if (time > dp[v][s]) continue; if (s + C[v] <= MAX) { long long ns = s + C[v]; long long ntime = time + D[v]; if (chmin(dp[v][ns], ntime)) { que.push(make_pair(ntime, pll(v, ns))); } } for (auto e : G[v]) { if (s < e.second.first) continue; int nv = e.first; long long ns = s - e.second.first; long long ntime = time + e.second.second; if (chmin(dp[nv][ns], ntime)) { que.push(make_pair(ntime, pll(nv, ns))); } } } for (int v = 1; v < N; ++v) { long long res = INF; for (int s = 0; s <= MAX; ++s) chmin(res, dp[v][s]); cout << res << endl; } } int main() { while (cin >> N >> M >> S) { G.assign(N, vector<Edge>()); for (int i = 0; i < M; ++i) { long long u, v, a, b; cin >> u >> v >> a >> b; --u, --v; G[u].push_back(Edge(v, pll(a, b))); G[v].push_back(Edge(u, pll(a, b))); } C.resize(N); D.resize(N); for (int i = 0; i < N; ++i) cin >> C[i] >> D[i]; solve(); } }
replace
79
80
79
80
-6
corrupted size vs. prev_size
p02703
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; #define int long long #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i) #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i) #define ALL(a) a.begin(), a.end() #define IN(a, x, b) (a <= x && x < b) template <class T> inline void out(T t) { cout << t << "\n"; } template <class T, class... Ts> inline void out(T t, Ts... ts) { cout << t << " "; out(ts...); } template <class T> inline bool CHMIN(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool CHMAX(T &a, T b) { if (a < b) { a = b; return true; } return false; } constexpr int INF = 1e18; int dist[55][2525]; signed main() { int N, M, S; cin >> N >> M >> S; vector<vector<tuple<int, int, int>>> g(N); REP(i, M) { int a, b, c, d; cin >> a >> b >> c >> d; --a; --b; g[a].emplace_back(b, c, d); g[b].emplace_back(a, c, d); } vector<int> c(N), d(N); REP(i, N) { cin >> c[i] >> d[i]; } if (S > 2500) { vector<int> d(N, INF); d[0] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que; que.push({0, 0}); while (que.size()) { auto [cost, now] = que.top(); que.pop(); if (d[now] != cost) continue; for (auto [to, hoge, time] : g[now]) { if (CHMIN(d[to], d[now] + time)) { que.push({d[to], to}); } } } FOR(i, 1, N) out(d[i]); return 0; } REP(i, 55) REP(j, 2525) dist[i][j] = INF; dist[0][S] = 0; priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> que; que.push({0, S, 0}); while (que.size()) { auto [time, coin, now] = que.top(); que.pop(); if (dist[now][coin] != time) continue; while (coin <= 2500) { for (auto [to, a, b] : g[now]) { int ncoin = coin - a; int ntime = time + b; if (IN(0, ncoin, 2451) && CHMIN(dist[to][ncoin], ntime)) { que.push({dist[to][ncoin], ncoin, to}); } } coin += c[now]; time += d[now]; } } FOR(i, 1, N) { int ans = INF; REP(j, 2525) CHMIN(ans, dist[i][j]); out(ans); } }
#include "bits/stdc++.h" using namespace std; #define int long long #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i) #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i) #define ALL(a) a.begin(), a.end() #define IN(a, x, b) (a <= x && x < b) template <class T> inline void out(T t) { cout << t << "\n"; } template <class T, class... Ts> inline void out(T t, Ts... ts) { cout << t << " "; out(ts...); } template <class T> inline bool CHMIN(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool CHMAX(T &a, T b) { if (a < b) { a = b; return true; } return false; } constexpr int INF = 1e18; int dist[55][2525]; signed main() { int N, M, S; cin >> N >> M >> S; vector<vector<tuple<int, int, int>>> g(N); REP(i, M) { int a, b, c, d; cin >> a >> b >> c >> d; --a; --b; g[a].emplace_back(b, c, d); g[b].emplace_back(a, c, d); } vector<int> c(N), d(N); REP(i, N) { cin >> c[i] >> d[i]; } if (S > 2500) { vector<int> d(N, INF); d[0] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que; que.push({0, 0}); while (que.size()) { auto [cost, now] = que.top(); que.pop(); if (d[now] != cost) continue; for (auto [to, hoge, time] : g[now]) { if (CHMIN(d[to], d[now] + time)) { que.push({d[to], to}); } } } FOR(i, 1, N) out(d[i]); return 0; } REP(i, 55) REP(j, 2525) dist[i][j] = INF; dist[0][S] = 0; priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> que; que.push({0, S, 0}); while (que.size()) { auto [time, coin, now] = que.top(); que.pop(); if (dist[now][coin] != time) continue; if (CHMIN(dist[now][min(2500ll, coin + c[now])], time + d[now])) que.push({dist[now][min(2500ll, coin + c[now])], min(2500ll, coin + c[now]), now}); for (auto [to, a, b] : g[now]) { if (coin - a >= 0 && CHMIN(dist[to][coin - a], time + b)) que.push({dist[to][coin - a], coin - a, to}); } } FOR(i, 1, N) { int ans = INF; REP(j, 2525) CHMIN(ans, dist[i][j]); out(ans); } }
replace
78
88
78
84
TLE
p02704
C++
Runtime Error
#pragma region template #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vull = vector<ull>; using vvull = vector<vull>; using vvvull = vector<vvull>; using vld = vector<ld>; using vvld = vector<vld>; using vvvld = vector<vvld>; using vs = vector<string>; using pll = pair<ll, ll>; using vp = vector<pll>; template <typename T> using pqrev = priority_queue<T, vector<T>, greater<T>>; #define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++) #define repb(i, n) for (ll i = (n)-1; i >= 0; i--) #define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++) #define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((ll)(x).size()) //* constexpr ll MOD = 1e9 + 7; /*/ constexpr ll MOD = 998244353; //*/ constexpr ll INF = 1e+18; constexpr ld EPS = 1e-12L; constexpr ld PI = 3.14159265358979323846L; constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } template <typename S, typename T> constexpr bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <typename S, typename T> constexpr bool chmin(S &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #ifdef OJ_LOCAL #include "dump.hpp" #else #define dump(...) ((void)0) #endif template <typename T> bool print_(const T &a) { cout << a; return true; } template <typename T> bool print_(const vector<T> &vec) { for (auto &a : vec) { cout << a; if (&a != &vec.back()) { cout << " "; } } return false; } template <typename T> bool print_(const vector<vector<T>> &vv) { for (auto &v : vv) { for (auto &a : v) { cout << a; if (&a != &v.back()) { cout << " "; } } if (&v != &vv.back()) { cout << "\n"; } } return false; } void print() { cout << "\n"; } template <typename Head, typename... Tail> void print(Head &&head, Tail &&...tail) { bool f = print_(head); if (sizeof...(tail) != 0) { cout << (f ? " " : "\n"); } print(forward<Tail>(tail)...); } #pragma endregion void Pr() { cout << -1 << endl; exit(0); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll n; cin >> n; vull s(n); rep(i, n) { cin >> s[i]; } vull t(n); rep(i, n) { cin >> t[i]; } vull u(n); rep(i, n) { cin >> u[i]; } vull v(n); rep(i, n) { cin >> v[i]; } vvull ans(n, vull(n, 0)); vvvull ans2(64, vvull(n, vull(n, 2))); rep(bit, 64) { rep(i, n) { rep(j, n) { if (!s[i] && ((u[i] >> bit) & 1)) { ans2[bit][i][j] = 1; } if (s[i] && !((u[i] >> bit) & 1)) { ans2[bit][i][j] = 0; } if (!t[j] && ((v[j] >> bit) & 1)) { if (ans2[bit][i][j] == 0) { Pr(); } ans2[bit][i][j] = 1; } if (t[j] && !((v[j] >> bit) & 1)) { if (ans2[bit][i][j] == 1) { Pr(); } ans2[bit][i][j] = 0; } } } } return 11; }
#pragma region template #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vull = vector<ull>; using vvull = vector<vull>; using vvvull = vector<vvull>; using vld = vector<ld>; using vvld = vector<vld>; using vvvld = vector<vvld>; using vs = vector<string>; using pll = pair<ll, ll>; using vp = vector<pll>; template <typename T> using pqrev = priority_queue<T, vector<T>, greater<T>>; #define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++) #define repb(i, n) for (ll i = (n)-1; i >= 0; i--) #define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++) #define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((ll)(x).size()) //* constexpr ll MOD = 1e9 + 7; /*/ constexpr ll MOD = 998244353; //*/ constexpr ll INF = 1e+18; constexpr ld EPS = 1e-12L; constexpr ld PI = 3.14159265358979323846L; constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } template <typename S, typename T> constexpr bool chmax(S &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <typename S, typename T> constexpr bool chmin(S &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #ifdef OJ_LOCAL #include "dump.hpp" #else #define dump(...) ((void)0) #endif template <typename T> bool print_(const T &a) { cout << a; return true; } template <typename T> bool print_(const vector<T> &vec) { for (auto &a : vec) { cout << a; if (&a != &vec.back()) { cout << " "; } } return false; } template <typename T> bool print_(const vector<vector<T>> &vv) { for (auto &v : vv) { for (auto &a : v) { cout << a; if (&a != &v.back()) { cout << " "; } } if (&v != &vv.back()) { cout << "\n"; } } return false; } void print() { cout << "\n"; } template <typename Head, typename... Tail> void print(Head &&head, Tail &&...tail) { bool f = print_(head); if (sizeof...(tail) != 0) { cout << (f ? " " : "\n"); } print(forward<Tail>(tail)...); } #pragma endregion void Pr() { cout << -1 << endl; exit(0); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll n; cin >> n; vull s(n); rep(i, n) { cin >> s[i]; } vull t(n); rep(i, n) { cin >> t[i]; } vull u(n); rep(i, n) { cin >> u[i]; } vull v(n); rep(i, n) { cin >> v[i]; } vvull ans(n, vull(n, 0)); vvvull ans2(64, vvull(n, vull(n, 2))); rep(bit, 64) { rep(i, n) { rep(j, n) { if (!s[i] && ((u[i] >> bit) & 1)) { ans2[bit][i][j] = 1; } if (s[i] && !((u[i] >> bit) & 1)) { ans2[bit][i][j] = 0; } if (!t[j] && ((v[j] >> bit) & 1)) { if (ans2[bit][i][j] == 0) { Pr(); } ans2[bit][i][j] = 1; } if (t[j] && !((v[j] >> bit) & 1)) { if (ans2[bit][i][j] == 1) { Pr(); } ans2[bit][i][j] = 0; } } } int umeflg = 0; rep(i, n) { bool f = 1; rep(j, n) { if (ans2[bit][i][j] != 2) { f = 0; } } if (f) { umeflg = 2; break; } } rep(j, n) { bool f = 1; rep(i, n) { if (ans2[bit][i][j] != 2) { f = 0; } } if (f) { umeflg++; break; } } if (umeflg == 3) { if (n == 1) { ans2[bit][0][0] = 0; } else { rep(i, n) { rep(j, n) { ans2[bit][i][j] = (i + j) % 2; } } } } else if (umeflg == 2) { int appear = 0; rep(i, n) { rep(j, n) { if (ans2[bit][i][j] == 0) { appear |= 1; } if (ans2[bit][i][j] == 1) { appear |= 2; } } } if (appear == 3) { rep(i, n) { if (!s[i] && !((u[i] >> bit) & 1)) { rep(j, n) { ans2[bit][i][j] = 0; } } if (s[i] && ((u[i] >> bit) & 1)) { rep(j, n) { ans2[bit][i][j] = 1; } } } } else { bool f = 0; rep(i, n) { if (appear == 1 && s[i] && ((u[i] >> bit) & 1)) { f = 1; rep(j, n) { ans2[bit][i][j] = 1; } } if (appear == 2 && !s[i] && !((u[i] >> bit) & 1)) { f = 1; rep(j, n) { ans2[bit][i][j] = 0; } } } if (f) { rep(i, n) { if (!s[i] && !((u[i] >> bit) & 1)) { rep(j, n) { ans2[bit][i][j] = 0; } } if (s[i] && ((u[i] >> bit) & 1)) { rep(j, n) { ans2[bit][i][j] = 1; } } } } else { vll lst; rep(i, n) { if (appear == 1 && !s[i] && !((u[i] >> bit) & 1)) { lst.emplace_back(i); } if (appear == 2 && s[i] && ((u[i] >> bit) & 1)) { lst.emplace_back(i); } } ll p = 0; rep(j, n) { if (appear == 1 && t[j] && ((v[j] >> bit) & 1)) { ans2[bit][lst[p % SZ(lst)]][j] = 1; p++; } if (appear == 2 && !t[j] && !((v[j] >> bit) & 1)) { ans2[bit][lst[p % SZ(lst)]][j] = 0; p++; } } } rep(i, n) { rep(j, n) { if (ans2[bit][i][j] == 2) { ans2[bit][i][j] = appear == 1 ? 0 : 1; } } } } } else if (umeflg == 1) { int appear = 0; rep(i, n) { rep(j, n) { if (ans2[bit][i][j] == 0) { appear |= 1; } if (ans2[bit][i][j] == 1) { appear |= 2; } } } if (appear == 3) { rep(j, n) { if (!t[j] && !((v[j] >> bit) & 1)) { rep(i, n) { ans2[bit][i][j] = 0; } } if (t[j] && ((v[j] >> bit) & 1)) { rep(i, n) { ans2[bit][i][j] = 1; } } } } else { bool f = 0; rep(j, n) { if (appear == 1 && t[j] && ((v[j] >> bit) & 1)) { f = 1; rep(i, n) { ans2[bit][i][j] = 1; } } if (appear == 2 && !t[j] && !((v[j] >> bit) & 1)) { f = 1; rep(i, n) { ans2[bit][i][j] = 0; } } } if (f) { rep(j, n) { if (!t[j] && !((v[j] >> bit) & 1)) { rep(i, n) { ans2[bit][i][j] = 0; } } if (t[j] && ((v[j] >> bit) & 1)) { rep(i, n) { ans2[bit][i][j] = 1; } } } } else { vll lst; rep(j, n) { if (appear == 1 && !t[j] && !((v[j] >> bit) & 1)) { lst.emplace_back(j); } if (appear == 2 && t[j] && ((v[j] >> bit) & 1)) { lst.emplace_back(j); } } ll p = 0; rep(i, n) { if (appear == 1 && s[i] && ((u[i] >> bit) & 1)) { ans2[bit][i][lst[p % SZ(lst)]] = 1; p++; } if (appear == 2 && !s[i] && !((u[i] >> bit) & 1)) { ans2[bit][i][lst[p % SZ(lst)]] = 0; p++; } } } rep(i, n) { rep(j, n) { if (ans2[bit][i][j] == 2) { ans2[bit][i][j] = appear == 1 ? 0 : 1; } } } } } else { ll ume = 2; rep(i, n) { rep(j, n) { if (ans2[bit][i][j] == 1) { ume = 0; } if (ans2[bit][i][j] == 0) { ume = 1; } } } rep(i, n) { rep(j, n) { if (ans2[bit][i][j] == 2) { ans2[bit][i][j] = ume; } } } } // check rep(i, n) { rep(j, n) { if (ans2[bit][i][j] == 2) { return 22; } } } rep(i, n) { bool f; if (s[i]) { if ((u[i] >> bit) & 1) { f = 0; rep(j, n) { if (ans2[bit][i][j] == 1) { f = 1; } } } else { f = 1; rep(j, n) { if (ans2[bit][i][j] == 1) { f = 0; } } } } else { if ((u[i] >> bit) & 1) { f = 1; rep(j, n) { if (ans2[bit][i][j] == 0) { f = 0; } } } else { f = 0; rep(j, n) { if (ans2[bit][i][j] == 0) { f = 1; } } } } if (!f) Pr(); } rep(j, n) { bool f; if (t[j]) { if ((v[j] >> bit) & 1) { f = 0; rep(i, n) { if (ans2[bit][i][j] == 1) { f = 1; } } } else { f = 1; rep(i, n) { if (ans2[bit][i][j] == 1) { f = 0; } } } } else { if ((v[j] >> bit) & 1) { f = 1; rep(i, n) { if (ans2[bit][i][j] == 0) { f = 0; } } } else { f = 0; rep(i, n) { if (ans2[bit][i][j] == 0) { f = 1; } } } } if (!f) Pr(); } rep(i, n) { rep(j, n) { ans[i][j] += ans2[bit][i][j] << bit; } } } rep(i, n) print(ans[i]); }
replace
139
142
139
428
11
p02704
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; vector<int> s[2]; vector<ull> u[2]; const int N = 500; int n; int val[2][N]; int d[N][N]; void flip() { rep(i, n) rep(j, i) { swap(d[i][j], d[j][i]); } } bool solve() { rep(i, n) rep(j, n) d[i][j] = -1; rep(k, 2) { rep(i, n) { int x = val[k][i]; if (s[k][i] != x) { // 0 and 1 or rep(j, n) { if (d[i][j] == !x) return false; d[i][j] = x; } } } flip(); } bool changed = false; /*rep(_,2) */ { rep(k, 2) { rep(i, n) { int x = val[k][i]; if (s[k][i] == x) { // 0 and 1 or vector<int> p; bool ok = false; rep(j, n) { if (d[i][j] == -1) p.push_back(j); if (d[i][j] == x) ok = true; } if (ok) continue; if (p.size() == 0) return false; if (p.size() == 1) { d[i][p[0]] = x; changed = true; } } } flip(); } } if (changed) { rep(k, 2) { if (k == 0) rep(i, n) { int x = val[k][i]; if (s[k][i] == x) { // 0 and 1 or vector<int> p; bool ok = false; rep(j, n) { if (d[i][j] == -1) p.push_back(j); if (d[i][j] == x) ok = true; } if (ok) continue; if (p.size() == 0) return false; // need this the second iteration if (p.size() == 1) { throw -1; } } } flip(); } } vector<int> is, js; rep(i, n) { bool filled = true; rep(j, n) if (d[i][j] == -1) filled = false; if (!filled) is.push_back(i); } rep(j, n) { bool filled = true; rep(i, n) if (d[i][j] == -1) filled = false; if (!filled) js.push_back(j); } rep(i, is.size()) rep(j, js.size()) { d[is[i]][js[j]] = (i + j) % 2; } return true; } ull ans[N][N]; int main() { cin >> n; rep(i, 2) { s[i] = vector<int>(n); rep(j, n) cin >> s[i][j]; } rep(i, 2) { u[i] = vector<ull>(n); rep(j, n) cin >> u[i][j]; } rep(b, 64) { rep(i, 2) rep(j, n) val[i][j] = u[i][j] >> b & 1; if (!solve()) { cout << "-1" << endl; return 0; } rep(i, n) rep(j, n) ans[i][j] |= ull(d[i][j]) << b; } rep(i, n) { rep(j, n) { cout << ans[i][j] << (j == n - 1 ? '\n' : ' '); } } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; vector<int> s[2]; vector<ull> u[2]; const int N = 500; int n; int val[2][N]; int d[N][N]; void flip() { rep(i, n) rep(j, i) { swap(d[i][j], d[j][i]); } } bool solve() { rep(i, n) rep(j, n) d[i][j] = -1; rep(k, 2) { rep(i, n) { int x = val[k][i]; if (s[k][i] != x) { // 0 and 1 or rep(j, n) { if (d[i][j] == !x) return false; d[i][j] = x; } } } flip(); } bool changed = false; /*rep(_,2) */ { rep(k, 2) { rep(i, n) { int x = val[k][i]; if (s[k][i] == x) { // 0 and 1 or vector<int> p; bool ok = false; rep(j, n) { if (d[i][j] == -1) p.push_back(j); if (d[i][j] == x) ok = true; } if (ok) continue; if (p.size() == 0) return false; if (p.size() == 1) { d[i][p[0]] = x; changed = true; } } } flip(); } } if (changed) { rep(k, 2) { if (k == 0) rep(i, n) { int x = val[k][i]; if (s[k][i] == x) { // 0 and 1 or vector<int> p; bool ok = false; rep(j, n) { if (d[i][j] == -1) p.push_back(j); if (d[i][j] == x) ok = true; } if (ok) continue; if (p.size() == 0) return false; // need this the second iteration if (p.size() == 1) { d[i][p[0]] = x; } } } flip(); } } vector<int> is, js; rep(i, n) { bool filled = true; rep(j, n) if (d[i][j] == -1) filled = false; if (!filled) is.push_back(i); } rep(j, n) { bool filled = true; rep(i, n) if (d[i][j] == -1) filled = false; if (!filled) js.push_back(j); } rep(i, is.size()) rep(j, js.size()) { d[is[i]][js[j]] = (i + j) % 2; } return true; } ull ans[N][N]; int main() { cin >> n; rep(i, 2) { s[i] = vector<int>(n); rep(j, n) cin >> s[i][j]; } rep(i, 2) { u[i] = vector<ull>(n); rep(j, n) cin >> u[i][j]; } rep(b, 64) { rep(i, 2) rep(j, n) val[i][j] = u[i][j] >> b & 1; if (!solve()) { cout << "-1" << endl; return 0; } rep(i, n) rep(j, n) ans[i][j] |= ull(d[i][j]) << b; } rep(i, n) { rep(j, n) { cout << ans[i][j] << (j == n - 1 ? '\n' : ' '); } } return 0; }
replace
81
82
81
82
-6
terminate called after throwing an instance of 'int'
p02704
C++
Runtime Error
#include <bits/stdc++.h> // clang-format off using Int = long long; #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on /** * author: knshnb * created: Sun May 3 13:27:58 JST 2020 **/ template <class T, class S> T make_vec(S x) { return x; } template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); } void no() { std::cout << -1 << std::endl; exit(0); } using ull = unsigned long long; const Int K = 64; signed main() { Int n; std::cin >> n; std::vector<Int> S(n), T(n); std::vector<ull> U(n), V(n); REP(i, n) std::cin >> S[i]; REP(i, n) std::cin >> T[i]; REP(i, n) std::cin >> U[i]; REP(i, n) std::cin >> V[i]; auto solve_1bit = [&n](const std::vector<Int> &x, const std::vector<Int> &y) { auto ret = make_vec<Int>(n, n, -1); auto row = make_vec<Int>(n, 2, true); auto col = make_vec<Int>(n, 2, true); REP(i, n) { if (x[i] < 2) row[i][x[i]] = false; } REP(j, n) { if (y[j] < 2) col[j][y[j]] = false; } REP(i, n) { REP(j, n) { if (x[i] >= 2) ret[i][j] = x[i] - 2; if (y[j] >= 2) ret[i][j] = y[j] - 2; if (x[i] == y[j] && x[i] < 2) ret[i][j] = x[i]; if (ret[i][j] != -1) row[i][ret[i][j]] = col[j][ret[i][j]] = true; } } Int cnti = std::count_if(x.begin(), x.end(), [](Int a) { return a < 2; }); Int cntj = std::count_if(y.begin(), y.end(), [](Int a) { return a < 2; }); if (cnti <= 1 || cntj <= 1) { REP(i, n) { REP(j, n) { if (ret[i][j] != -1) continue; if (row[i][0] && col[j][0]) { ret[i][j] = 1; } else { ret[i][j] = 0; } row[i][ret[i][j]] = col[j][ret[i][j]] = true; } } REP(i, n) REP(j, 2) if (!row[i][j]) assert(0); REP(i, n) REP(j, 2) if (!col[i][j]) assert(0); } else { Int ci = 0; REP(i, n) { if (x[i] >= 2) continue; Int cj = 0; REP(j, n) { if (y[j] >= 2) continue; ret[i][j] = (ci + cj) % 2; cj++; } ci++; } } return ret; }; auto ans = make_vec<ull>(n, n, 0); REP(k, K) { std::vector<Int> x(n), y(n); auto trans = [](Int p, Int q) { if (p == 0 && q == 0) return 0; if (p == 1 && q == 1) return 1; if (p == 1 && q == 0) return 2; if (p == 0 && q == 1) return 3; assert(0); }; REP(i, n) x[i] = trans(S[i], U[i] >> k & 1); REP(j, n) y[j] = trans(T[j], V[j] >> k & 1); auto tmp = solve_1bit(x, y); REP(i, n) { REP(j, n) { ans[i][j] |= ull(tmp[i][j]) << k; } } } // verify ull all = 0; REP(i, K) all |= 1ull << i; REP(i, n) { ull acc = S[i] ? 0 : all; REP(j, n) { if (S[i]) { acc |= ans[i][j]; } else { acc &= ans[i][j]; } } if (acc != U[i]) no(); } REP(j, n) { ull acc = T[j] ? 0 : all; REP(i, n) { if (T[j]) { acc |= ans[i][j]; } else { acc &= ans[i][j]; } } if (acc != V[j]) no(); } REP(i, n) { REP(j, n) std::cout << ans[i][j] << " "; std::cout << "\n"; } }
#include <bits/stdc++.h> // clang-format off using Int = long long; #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on /** * author: knshnb * created: Sun May 3 13:27:58 JST 2020 **/ template <class T, class S> T make_vec(S x) { return x; } template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); } void no() { std::cout << -1 << std::endl; exit(0); } using ull = unsigned long long; const Int K = 64; signed main() { Int n; std::cin >> n; std::vector<Int> S(n), T(n); std::vector<ull> U(n), V(n); REP(i, n) std::cin >> S[i]; REP(i, n) std::cin >> T[i]; REP(i, n) std::cin >> U[i]; REP(i, n) std::cin >> V[i]; auto solve_1bit = [&n](const std::vector<Int> &x, const std::vector<Int> &y) { auto ret = make_vec<Int>(n, n, -1); auto row = make_vec<Int>(n, 2, true); auto col = make_vec<Int>(n, 2, true); REP(i, n) { if (x[i] < 2) row[i][x[i]] = false; } REP(j, n) { if (y[j] < 2) col[j][y[j]] = false; } REP(i, n) { REP(j, n) { if (x[i] >= 2) ret[i][j] = x[i] - 2; if (y[j] >= 2) ret[i][j] = y[j] - 2; if (x[i] == y[j] && x[i] < 2) ret[i][j] = x[i]; if (ret[i][j] != -1) row[i][ret[i][j]] = col[j][ret[i][j]] = true; } } Int cnti = std::count_if(x.begin(), x.end(), [](Int a) { return a < 2; }); Int cntj = std::count_if(y.begin(), y.end(), [](Int a) { return a < 2; }); if (cnti <= 1 || cntj <= 1) { REP(i, n) { REP(j, n) { if (ret[i][j] != -1) continue; if (row[i][0] && col[j][0]) { ret[i][j] = 1; } else { ret[i][j] = 0; } row[i][ret[i][j]] = col[j][ret[i][j]] = true; } } // REP(i, n) REP(j, 2) if (!row[i][j]) assert(0); // REP(i, n) REP(j, 2) if (!col[i][j]) assert(0); } else { Int ci = 0; REP(i, n) { if (x[i] >= 2) continue; Int cj = 0; REP(j, n) { if (y[j] >= 2) continue; ret[i][j] = (ci + cj) % 2; cj++; } ci++; } } return ret; }; auto ans = make_vec<ull>(n, n, 0); REP(k, K) { std::vector<Int> x(n), y(n); auto trans = [](Int p, Int q) { if (p == 0 && q == 0) return 0; if (p == 1 && q == 1) return 1; if (p == 1 && q == 0) return 2; if (p == 0 && q == 1) return 3; assert(0); }; REP(i, n) x[i] = trans(S[i], U[i] >> k & 1); REP(j, n) y[j] = trans(T[j], V[j] >> k & 1); auto tmp = solve_1bit(x, y); REP(i, n) { REP(j, n) { ans[i][j] |= ull(tmp[i][j]) << k; } } } // verify ull all = 0; REP(i, K) all |= 1ull << i; REP(i, n) { ull acc = S[i] ? 0 : all; REP(j, n) { if (S[i]) { acc |= ans[i][j]; } else { acc &= ans[i][j]; } } if (acc != U[i]) no(); } REP(j, n) { ull acc = T[j] ? 0 : all; REP(i, n) { if (T[j]) { acc |= ans[i][j]; } else { acc &= ans[i][j]; } } if (acc != V[j]) no(); } REP(i, n) { REP(j, n) std::cout << ans[i][j] << " "; std::cout << "\n"; } }
replace
75
77
75
77
0
p02704
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; #ifdef ENABLE_DEBUG #define dump(a) cerr << #a << "=" << a << endl #define dumparr(a, n) cerr << #a << "[" << n << "]=" << a[n] << endl #else #define dump(a) #define dumparr(a, n) #endif #define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++) #define For(i, a) FOR(i, 0, a) #define REV(i, a, b) for (ll i = (ll)b - 1LL; i >= (ll)a; i--) #define Rev(i, a) REV(i, 0, a) #define REP(a) For(i, a) #define SIGN(a) (a == 0 ? 0 : (a > 0 ? 1 : -1)) typedef long long int ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair<ll, ll> pll; typedef pair<ll, pll> ppll; typedef vector<ll> vll; typedef long double ld; typedef pair<ld, ld> pdd; const ll INF = (1LL << 50); #if __cplusplus < 201700L ll gcd(ll a, ll b) { if (a < b) return gcd(b, a); ll r; while ((r = a % b)) { a = b; b = r; } return b; } #endif template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <class S, class T> std::ostream &operator<<(std::ostream &os, pair<S, T> a) { os << "(" << a.first << "," << a.second << ")"; return os; } template <class T> std::ostream &operator<<(std::ostream &os, vector<T> a) { os << "[ "; REP(a.size()) { os << a[i] << " "; } os << " ]"; return os; } ull nbit(ull X, ull i) { return (X & (1ULL << i)) > 0ULL; } void solve(long long N, std::vector<long long> S, std::vector<long long> T, std::vector<ull> U, std::vector<ull> V) { vector<vector<ull>> ans(N, vector<ull>(N)); For(xx, 64) { ull x = (1ULL << xx); vector<vector<int>> cur(N, vector<int>(N, -1)); set<ull> flagu, flagv; REP(N) { flagu.insert(i); flagv.insert(i); } For(i, N) { ull u = nbit(U[i], xx); For(j, N) { ull v = nbit(V[j], xx); if (S[i] != u && T[j] != v && S[i] != T[j]) { cout << -1 << endl; return; } if (S[i] != u) { cur[i][j] = u; flagu.erase(i); } if (T[j] != v) { cur[i][j] = v; flagv.erase(j); } if (u == v) { cur[i][j] = u; flagu.erase(i); flagv.erase(j); } } } For(__xx, 2) { { vector<ll> s; for (auto &&i : flagu) { ull u = nbit(U[i], xx); For(j, N) { if (flagv.count(j)) continue; if (cur[i][j] == -1) { cur[i][j] = u; s.push_back(i); } } } for (auto &&i : s) { flagu.erase(i); } } { vector<ll> s; for (auto &&j : flagv) { ull v = nbit(V[j], xx); For(i, N) { if (flagu.count(i)) continue; if (cur[i][j] == -1) { cur[i][j] = v; s.push_back(j); } } } for (auto &&j : s) { flagv.erase(j); } } } if (flagu.size() == 1 || flagv.size() == 1 || (flagu.empty() ^ flagv.empty())) { cout << -1 << endl; return; } vector<ll> us(flagu.begin(), flagu.end()), vs(flagv.begin(), flagv.end()); For(i, us.size()) { For(j, vs.size()) { if (i % (min(i, j)) == j % (min(i, j))) { cur[us[i]][vs[j]] = 1; } else { cur[us[i]][vs[j]] = 0; } } } For(i, N) { For(j, N) { if (cur[i][j] == 1) { ans[i][j] |= x; } } } } For(i, N) { For(j, N) { cout << ans[i][j] << " "; } cout << endl; } } int main() { cout << setprecision(1000); long long N; scanf("%lld", &N); std::vector<long long> S(N); for (int i = 0; i < N; i++) { scanf("%lld", &S[i]); } std::vector<long long> T(N); for (int i = 0; i < N; i++) { scanf("%lld", &T[i]); } std::vector<ull> U(N); for (int i = 0; i < N; i++) { scanf("%llu", &U[i]); } std::vector<ull> V(N); for (int i = 0; i < N; i++) { scanf("%llu", &V[i]); } solve(N, std::move(S), std::move(T), std::move(U), std::move(V)); return 0; }
#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; #ifdef ENABLE_DEBUG #define dump(a) cerr << #a << "=" << a << endl #define dumparr(a, n) cerr << #a << "[" << n << "]=" << a[n] << endl #else #define dump(a) #define dumparr(a, n) #endif #define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++) #define For(i, a) FOR(i, 0, a) #define REV(i, a, b) for (ll i = (ll)b - 1LL; i >= (ll)a; i--) #define Rev(i, a) REV(i, 0, a) #define REP(a) For(i, a) #define SIGN(a) (a == 0 ? 0 : (a > 0 ? 1 : -1)) typedef long long int ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair<ll, ll> pll; typedef pair<ll, pll> ppll; typedef vector<ll> vll; typedef long double ld; typedef pair<ld, ld> pdd; const ll INF = (1LL << 50); #if __cplusplus < 201700L ll gcd(ll a, ll b) { if (a < b) return gcd(b, a); ll r; while ((r = a % b)) { a = b; b = r; } return b; } #endif template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <class S, class T> std::ostream &operator<<(std::ostream &os, pair<S, T> a) { os << "(" << a.first << "," << a.second << ")"; return os; } template <class T> std::ostream &operator<<(std::ostream &os, vector<T> a) { os << "[ "; REP(a.size()) { os << a[i] << " "; } os << " ]"; return os; } ull nbit(ull X, ull i) { return (X & (1ULL << i)) > 0ULL; } void solve(long long N, std::vector<long long> S, std::vector<long long> T, std::vector<ull> U, std::vector<ull> V) { vector<vector<ull>> ans(N, vector<ull>(N)); For(xx, 64) { ull x = (1ULL << xx); vector<vector<int>> cur(N, vector<int>(N, -1)); set<ull> flagu, flagv; REP(N) { flagu.insert(i); flagv.insert(i); } For(i, N) { ull u = nbit(U[i], xx); For(j, N) { ull v = nbit(V[j], xx); if (S[i] != u && T[j] != v && S[i] != T[j]) { cout << -1 << endl; return; } if (S[i] != u) { cur[i][j] = u; flagu.erase(i); } if (T[j] != v) { cur[i][j] = v; flagv.erase(j); } if (u == v) { cur[i][j] = u; flagu.erase(i); flagv.erase(j); } } } For(__xx, 2) { { vector<ll> s; for (auto &&i : flagu) { ull u = nbit(U[i], xx); For(j, N) { if (flagv.count(j)) continue; if (cur[i][j] == -1) { cur[i][j] = u; s.push_back(i); } } } for (auto &&i : s) { flagu.erase(i); } } { vector<ll> s; for (auto &&j : flagv) { ull v = nbit(V[j], xx); For(i, N) { if (flagu.count(i)) continue; if (cur[i][j] == -1) { cur[i][j] = v; s.push_back(j); } } } for (auto &&j : s) { flagv.erase(j); } } } if (flagu.size() == 1 || flagv.size() == 1 || (flagu.empty() ^ flagv.empty())) { cout << -1 << endl; return; } vector<ll> us(flagu.begin(), flagu.end()), vs(flagv.begin(), flagv.end()); For(i, us.size()) { For(j, vs.size()) { if (i % (min(vs.size(), us.size())) == j % (min(vs.size(), us.size()))) { cur[us[i]][vs[j]] = 1; } else { cur[us[i]][vs[j]] = 0; } } } For(i, N) { For(j, N) { if (cur[i][j] == 1) { ans[i][j] |= x; } } } } For(i, N) { For(j, N) { cout << ans[i][j] << " "; } cout << endl; } } int main() { cout << setprecision(1000); long long N; scanf("%lld", &N); std::vector<long long> S(N); for (int i = 0; i < N; i++) { scanf("%lld", &S[i]); } std::vector<long long> T(N); for (int i = 0; i < N; i++) { scanf("%lld", &T[i]); } std::vector<ull> U(N); for (int i = 0; i < N; i++) { scanf("%llu", &U[i]); } std::vector<ull> V(N); for (int i = 0; i < N; i++) { scanf("%llu", &V[i]); } solve(N, std::move(S), std::move(T), std::move(U), std::move(V)); return 0; }
replace
145
146
145
147
0
p02704
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; /* Coded by 秦惜梦 The most attractive girl in the world ......... `;!!!!!!!!!;;;;;;;;::::::'''''''``''''''''````````````````````....`:;;;;;:'.....`:|$$$$$$$|;;;:`. ..........`''``...`''``. ........ ... ... .... ... ... ' ........ '!!!!!!!!!;;;;;;;:::::::::''''':::''''`````````````````````......`:;;;;;!%$$%!'.....`:|$%!;;;'.... .....`....`'''`...```.. ........ .. ... .. ... ... ' ........ .:!!!!!!!!;;;;;;;:::::::::::::::'''''''`````````..```````........`:;!%$$$$$$$$$$$%!'.....`:|!'````.. .........`''``....... ........ ... ... ... .. .. .' ....... `;!!!!!!;;;;;;;;::::::::::::::::'''''```````````.``````... .`';|%$$$$$&&$$$$$$%%;'..`'':'''``.. ...``.....```. .... ....... ... ... ... ... ... .' ....... . '!!!!!!;;;;;;;:::'''''''''::::::'''```````````````````.........':'`.......`:!%%|||%$$$$$&%;'::::''``. .```.. .... .... ....... .. ... .. ... ... ..' ...... '::'''':::::::::::::'''''''''''::::''''``````````````````.........'!$$$$$$%!:`.......`:!%&&&|'``':::'''``.....```. .... ... ...... ....... .. .. ... ..' ``... .`.``'::::::::;;;;:::::'''''''`'''''`````````````..```````........'!$$$$$$$$$$$$$$%!;'`.....`'`..`'::''''`.....```.. .... ... ...... ........ .... ....... ....' ````. .````.`;!!!;;;;;;;;::'''''''``'''''`````````````````````````.. ....`:!|%$$$&&&&&&&$%%$&&&&@&$|::'`.`''''''''`....````. .... ... ...... . .....```..``..... ... ' ```` .````. `;!!;;;;;;;:::::'''''':::'''''````````````........`````.... ........````........``'::::::::'``.``'''''``...````.. .... ... ...... . ......``.```.... .. ' ```. .```. .`';!!;;;;;;;:::::::::::::'''''``````````..........````````...`;$$$$&&&&&&$%%||||!|!;;::::::::'`...`'''''`....````. .... ... ..... . .. .``..```.... .. ' ``. .``. .`'`';!;;;;;;;;:::::::::::'''''`````````...........`````````....'!|%%%%%%%%%%%%%%%%%%$&&&|:'''''''`...`'''''`....```. .... ... ..... . .. .. ...... . .' `. .`. `''''`';!;;;;;;;::::::::::'''''''```````..........````````````....:|%%%%%%%%%%%%%%%%%%%%%%|:`''''''''`...`''''`....```.. ... .. ..... .. . .. .. ... .. ..' ` . .`'''''``';!;;;;;;;:::::::''''''''''```.``........```````````````````!%%%%%%%%%%||!;:''`.........`'''''''`...`''''`...````..... .. .... .. . . . .. .. ...' .''''''````';!;;;;;;;:::::'''''''''''```````````````````````````.........``````... ...```':;!!:....`'''''''``..`'''`....```. ... .. .... .. . . .. .. ...' .`''''''''``````;!;;;;;;:::::'''''''''''``````````'''''''''``....```````````````````````````':!||%|;``....`''''''``..`''``....`.. ... ... . . . .. .. . ... ' .'''''''''````````:;;;;:::'''''':::::::::::::''''''''''''``..``````....```````````````````````````:!!'`'`.....`'''''``...```. ......... .... . .. . . .. ... ' `'''''''''````';;;:::::::::::::::::::::::''''```````````..........```````````````````````````````````'`.``'``....`''''``.. .`.. ..... ... ... . .. .. . .. ' .'''''''''```````';;:::::''''''''''''''''''`''```````.`````.....````````````````````````````````''``````....``''`...``''```...... ........ ... . . . . .. ' `''''''''````'''`````.`::::::::'''''''''''''''''``.``.```........````````````''''`````````````````''''''''`....``'``...``````...... ........ .. . . . . . .. ' .`'''''''```'''''````````':::::::''''''''''''''``.``.`............`````````'''''''''''''''``````````'''''''''`.....````....```... .. ...... . . . .' `'''''''`''''''''````````.`::::::'''''''''''''`.```..............``````````'''''''''''''''''````````''''''''''``.......```......... . .... . ........ ' .`''''''`''''''''``````````.`:::::::'''''''''``.`..............```````'''''''''''''''''''''''''``````'''''''''''''.........``... ..... . ... ..`:::::::::::::'`. ' .'''''`''''''''``````````````':::::''''''''``..````````````````````''''''''''''''''''':''''''```''````''''::''''''`.```.......... ..... .... `'::::::::::::::::`. ' ....`''''''''''```````````````.`':::::'''''`...``````````''''''''''''''''''''''''''''''';:'''``''`::````';:''''''''''.....``......... ..... ... `::::::::::::::::::'`.....' ......`''''''''``````````````````.':::::::'`...``'''````''''''''''''''''''''''''''''''';!:;:'''':!;::'```````''''''''''` ........ ..... ... .. ....`':::':::::::::::'... ' .......`'''''`````````````````````.`':::'```.`''''''````''''''''':'''::'''::''':;::!!!;:;!;;:```````::`````````'''''''''`. ............ .. .. .':::::::::''` ' ........`''`````````````````````````..`':''`:;:'':''':''''''''''''::'':;:'''''''''::'''''':;;;:``````:;'```''``````'``'''''`.... ........... .. `::::::'`. ' ..........`````````````````````````'::::''':;!!!!;:'::':!;;;:::'''';;'''::::''''':'''::'''''''::'`````':''``''````::`':'''''''''. ...... .''`.... ' .`'`.......```````````````````````````````'':!;:::::::::':;::::::::''::''`''::::'`''''':::'':''`:;'`````':'```''`````::`````'''''':;'.................. ....... . ' `'''''```````````````````````````````````.`;!:::::::::::'''::::::::''::''``'::::'``'''''::''''''':'````````````'`````''````````````:!!;'................ .......... ' '''''`````````````````````````````````````;!;;;:':::''::''''::::;;:'':::'```'::'````''''''''''''':'```````````''````````````````````';!!!;'.... ...... ....... ' ''''````````````````````````````````````';!;;;:'::::':''`''':::;;;:'''':'``'':'````.```''''''''`':'````````````'`````````..``....`...`:!!!!:`.`..... . ' '''````````````````````````````````````':;!;;:`'::':'''``''':::;;;:''``'```'':'``....''`'''''''`''`.`````````````.````````.............';;'.`:;;;'`. ..... ... ' ''````````````````````````````````````'':!;::'`::':::''`''''':;;;;:```````'''''```...''`'''''''`''`.``.````````````````````............... `;;;;;;;;;:`. .... ....' ''''''''````````````````````````````''`:!;;:''':''::''`'':''':;;;;'```'```''''''`.`'``:'''::''''''```````````````````````````.............`:;;;;;;;;;;;'. . .... ..' :::::::''''````````````````````````''`'!!;:''''''':''`''''''':;;;:```::``'''':'''`';:';:'::::':`''`''`````````````````'``````````..........`:;;;;;;;;;:. `'.. ..... ' |%$$%%!;;:'''````````````````````''``';!;:'''':'``'''`'':''':::;:'``:!:``':::::::`:!;';;':::::''`''::````'''''````````''`````````...........`:;;;;;;;'. .':` `;;;;:. .. ..... ' @@@@@@@@$|;:''`````````````````''```';!;:::::::'``````'':''::::::'`'!|:`':::;:::'';|!:;;'''''''::::;:``'::''`'````````''````````````.........`:;;;;;` .:;'..';;;;;;;;;:` ......' @@@@@@@@@@$|;:''`````````````:'`````;;;:';;;;::'`'````'':''::::::'`;!!;':::::::'`.';!;;;:::::';!!::;'`':::'``'`.``````''````````.......... ..``';;:` .';;` `:;;;;;;;;;:` `;;;;;; @@@@@@@@@@@&|;:'``````````''```````;;::':;;;;:'`''```'':'::::;;;:':;|!!;:'''''::::!||!!!!;!!!!||;:!'`:::::'````..``````''`````.......... . ..`':;` .';;:` ';;;;;;;;;;:. ';;;;;; @@@@@@@@@@#@$!:''`````````````````::```';;;;::``'''``'::':::;;;::;;!|||!::;;!!!;;;:'``````'':!!!!|:``':::'`````:;:`.``````............. . ..`';' .';;;'..:;;;;;;;;;;'..';;;;;; @@@@@@@@@@@@$|;:'````````````````::````:;;;::'.`''```''''':::;:::;||%|||%%%%%|!:''''`...`'':!;:;|;```:::'``''`';!;'..`````.............. . ..`''. .';;;:` `;;;;;;;;;;;' .:;;;;;; @@@@@@@@@@@&%!;:'```````````````''````':;;;::'..''```````:::::';||%%%%%%$$&&&%!;!|$&%:..';!%%!!|!'`;::::'``''';!;;'...````.............. ....``.. .';;;;'..';;;;;;;;;;;` `:;;;;;; @@@@@@@@@#@%!!;:'````````````````````.'''::::`..````'''::!||||%%%%&&&&&&&&&&&&&$&&&%||||!|%%%%|!:';;;;!;``''`:;;;:`....`...................`....```. .`':::` `:;;;;;;;;;;:` `;;;;;;; @@@@@@##@$|!!;:''```````````````````````':'```..`````':!;:''''':!%$&&&&&&&&&&&&$$$|!;;!|%%%%%%|;':;''::'`'''`:!;:`........................```..````........ .':;;;;;;;;;'. ';;;;;;; !%$$$$%%|!!!;:''``````````````````````````````````````';!:'::'``':|$&&&&&&&&&&&&$$$$$$$$%%%%%|!:```''::'''''```...........................``..`'''`........ ......'::;;'..';;;;;;; ;!!!!!!!!!!;:''``````````````````````````````..````````'!%!;!;;!!%$%$&&&&&&&&&&&&$$$$$$$$$$%%||;``'''':''''``..`.... ... .................`'''````..... .....`....... `::;;;;; ::;!!!!!;;:''````````````````````````````````...````````'!%|!|%$$$$%$&&&&&&&&&&&&&&$$$$$$$$%|||:``''''''''```..`.... .. ... ....`'''`''```.... .'|%%;...... .... .' ``'::::'''````````````````````````````````````..`...```'`'|&$$$$$$$%$&&&&&&&&&&&&&&$$$$$$$$%%%|:`'''''''''```..`.... ....`''```''```... .:%%%%|:...... .......' .````````````````````````````````````````````.``..```````:|&$$$$$$|%$&&&&&&&&&&&&&&&&&$$$$%%%|:'`'''''''````..`.... .``'`````''````. :%%%%%;`....... ........' .``````````````````````````````````````````..`..`````````:%&&&&&&$%|%$&&&&&&&&&&&&&&&&$$$%$%|:'`'''''''````.``..... .``'`````'`'':|:.'!%%%%|'.`````. .......' .```````````````````````````````````````````'`..`````````.:$&&&&&&&&&&&&&&&&&&&&&&&&&&&$$$$%|;'```''''```````....... .``'```'``':|%%|'.'|%%%%;```````...........' .`````````````````````````````````````````:'`..''````````..!&&&&&&&&&&&&&&&&&&&&&&&&&&&$$&$%%;''```''````````.... . .'''`.`'``'`;%%%;``;%%$%!'..................' .``````````````````````````````````````;|:.``.`''''`````...`|&&&&&&&&&&&&&&&&&&&&&&&&&&$$&&$%!:'```````````.``.. .`''```;;'''';%%%:.:%&&$|:...................: .```````````````````````````````````'!!```'`.`:!:''`````. ..`|&&&&&&&&&&&$%%$$$%|%$$&&&$$&&&$%;'`.``..`......`. ..`''''!;''''':|%$|'`!&&$|:...................`: .````````````````````````````````;|:````'::`'!;::''''`. ...`!&&&&&&&&&&&&&&$&&&&&&&&&&$&&&&$|:'```.``......... .`. ....`'''```''''';$&&&;`:!;`......................`: .`````````````````````````````:|;`````'';:'`';:'''```.. ......'|&&&&&&&&&&&%%%$&&&&&&&$$&&&&&%;'`'`..```........ `` `;:`''''``'```'!$&&&%!'.....................```````: .``````````````````````````:|;``````'':;:'``':'''`````. ........`:%&&&&&&&&&&&&&&&&&&&$&&&&|!!!;'''`....``......`. .;%%;`''''';|||!;:''::;;' ..``......``````````````````: .```````````````````````!%:````````'':;:'```'':''````.. ............'|&@&&&&&&&&&&&&&&&$$|;!!!!!;:'``'`....``...````.. `:;;:'''!%;::::::::;;`. .````````'''````````````````: .```````````````````:%!'``````````'::::'````'''''````. .............```;$&@&&&&&&&&&&$|;;!!!!!!!!;```::` ...``.';;'```. `:::'';$$|;:::::!;'`....``````''''''''````''''`````: .```````````````:%|'`````````````'::::'`````'''''''``. ..... ....`````````;$&&&&@&|::!!;!!!!!!!!|!'```';'.. ....'!%%|!::``'':'':|$&&$|!!;:;:'`. .```````':::::''''''''''''''': .``````````;||:```````````````''::'::'````.`'''''''`.. ....... ..`````````````';:`````';!!!!!!!||||!;'```';!:`... ..`:|%%!'''''`:!%$&&&$$$!:;;;:'``'```''::::::::''''':::::''''; ..``';;:'```````````````````'''::'':'```````'''::''`.. ....... ..``````````````````. '||!!!|||||||!!;'````'!|;'``````````'''`';:'`'%&&&&&&|;!;:;!!!;;::;;::::::''''::::::::::; ``...``````````````````````''''''::''''`````````':::''``. ......... ....```````````... .:!||||||%%%|||!!!!;'````'!||;'```.`'''`.`.`''`.;$&&&$: .``'::::;!|%$$%|;:''':::::::::::; .````````````````````'''''''::```'````````.`:::'''```. .......... ............. `!%|!!||||%%||||!!!!!|%%%!:````````..`'''..``''`.....':. . ..`':;;;;;;;::::;!%&%!;;;;:::::; .`````````````````''''''''''''''::'''````..`::''''`````. ........``............ .;%%%|!!!||%%%%%%%|!!!|%%%%%%||%%%%%%!'`'''`````....``..... .. .`':;;;;;;:::::;!%%!;;;;;; .`````````````'''''''''''```''''::'''''``..`''''''```````........````````.....:%%%$%||!|||%%%%%%%||!|%%%%%%%%%%%%|||!'`'''';%%|;`````......'`. .. `':::::::;;;;;|%!;;; .``````````''''''''''```````'```''''````..`.`'''''````````.... ..```.... `|%%%%$%|||!|%%%%%%%%%|!|%%%%%%%%%%%%%%%|:`'''`;%%%%!:.:!|%$$$$|;:'`... .``.. .`. '::::;;;;;;!%!; %!'..```````''''''''''``````````'```'````````.``.`'''''```````....... .;%%%%%%%|!!!||%%%%%|!!!!!|%%%%%%%%%%%%%%%%:`''''!%%%!!!:`:!|%$$$$$$$$$%|'`. .```'`.``. .. .':::|% %%%%%%;```''''''''```````````````'``''``````.````.`''''`..'````.......`'''';|%%%%%%%%||%%%%%%%%%%%|!!%%%%%%%%%%%%%%%%%:`'''';%%||||:`:!|%$$$$$$$$$$$$$%;``. .``''`. ' $$$%%%%%$$|:''````````````````````''''``````.`````.`'''''`... .`':|%$$%%%%%%%%%|!|%%%%%%%%%%|||%%$$%%%%%%%%%%%%%:`'''';%||%%%;.:||%$$$$$$$$$$$$$$&&&%:...````''` ' $$$$$$$$$$%%%%%;`.``````````````````':'``````.`````.`'''''`......`''':!%%%%%%%%%%%%|!!%%%%|||%%|!|%%%%%%%%%%%%%%%%%%:`'''';||%%%|:`;||%$$$$$$$$$$$$&&&&&&&$|'...```'''` ' |%%$$%%$$$$$%%%%%%%;`..`.`````````````':'````.``.```..`''````''''':|!:|%%%%%%%%%%%%|!!|%|||%||!!%%%%%%%%%%%%%%%%%%%:`'''':|%%%%;``;|%%$$$$$$$$$$&&&&&&&&&&&$$;...`````''` ' @$|||||%%%%%%%%%%%%%%%%|:`....```````.`''``'''`````````.````''':;|%|;:|%%%%%%%%%%||!!|||||||!!|%%%%%%%%%%%%%%%%%%%:`'''';|%%%%:.'!|%$$$$$$$$$$$$$&&&&&&&&&&&&$!`..``````''` ' ||||&@&%|!|||%%%%%%%%%%%%%%|:.....```````'````.........`!%%%%%%%%|||;:|%%%%%%%%%%||!!|%|%|!!||%%%%%%%%%%%%%%%%%%%:`'''';|%%%!'`;||%$$$$$$$&&$$$$$&&&&&&@&&&&&$$!`..``````````. ' |||||!|!|$@&%|!|||%%%%%%%%%%%%%:. ...`````''``........:|%%%%%%%%%||%;:|%%%%%%%$%%%%!;|||!!||||%%%%%%%%%%%%%%%%%%:`'''';||%|:`:||%%$$$&&&&&$$%%$$&&&&@######&&$$$!`..``..```````. ' ||||||||!|!!!!|%$%|||||%$%%%%%%%%%!`.....````'`......'|%%%%%%%%%%|%$|;%&&&&&&&&$$$$|!|!!%$$$$&&&&&&&&&$$$$$$$$%;`''':;|||;``;||%$$&&&&&&&$$%%$$&&&&&@######&$$$$%:.....``````````. ' ||%%||||||!!|!!|||!|%$%|||%%%%%%%%%%%|:.....`.`'`...'|%%%%%%%%%$$$$&|:|&&&&&&&&$$$$|;!|$$$$&&&&&&&&&&&&&&&&@&$;`''':;||;``!||%$&$$$&&&&$%%%%%$&#####@@###@&$$&$$$!`.......`````````: .:!|%%|||||||||||||||!|||||%%%%$%%%%%;`.......``:%&&&&&&&&&&&&$$$%;;$&&&&&&&&&&$||$$$&&@@@@@@@@@@@@@@@@@@&!'''':;!:`'!||%$&$$$$$&&&$%%|%%$@######@&&&&&$$$$$$$%;..`...`...`````': .....`;|%%%%%|||!|||!|||!!!||%%%%%%%%%%;`.....:%&&&&&&&&&&&&$$$&$|'!$&&&&&&&$$%$$$&&@@@@@@@@@@@@@@@@@@@@!'::':'`.'|||%$$&&$$$$$&&$%%||%$@#########@@&&$$$$&$%$!`..`...```..````: ..........'!|%|%|||||!||||||||||%%%%%%%%%:...'|&&&&&&&&&&&&&$$&&&$;'|&&&&&$%%$$$&&@@@@@@@@@@@@@@@@@##@@!'::::'`:|%%%$$$&&&$$$$$$$%%|%&@@##########@@@@&&&$$$$$%;..``....````.``: .....```......`;|%|%%||||||||||||||%%%%%%|!:`!&&&&&&&&&&&&&&$$$&&$%::%&$$%%$$&&&@@@@@@@@@@@@@@@@@@@#@&|::::::;|%%$$$$&&&&&$$$$$$%%%%&@@@###########@@@@&&&&&$$$!`..`.....`````.' ..................`;|%%%|%%|||!|||||||%%%|||$&&&&&&&&&&&@&&&$$$&&&$%;;%%%$$&&@@@@@@@@@@@@@@@@@##@#@&$;':::::!%%$$$$&&&&&&&$$$%%%%%|$@@@@##@#########@@@@@&&&&$$|:...`.....`````: ............``..```...`;|%|||%||!!|||||||||%&&&&&&&&&&@@@@&&$$$&&&&$%;;%$$&@@@@@@@@@@@@@@@@@@#@@&$!`.`:::::!%$$$&&&&&&&&$$$$$$%%%||&@@@@##@@@@########@@@@&&&&$$!`...`.....````: ...................```...`:|%||||||||!||||%&&&&&&&&&&&@@@@@&$%&&$$$%%%;:!$&@@@@@@@@@@@@@@#@@&&%;``;|;:::::!$$$&&&&&&&&&&$$$$$%%%%||&@@@@@@@@@@##@#####@@@@@&&&&&$:..```.....```: .....................``.`...`;|%|||||||||%&&&&&&&&&&&&@@@@@@$$&$$%%$$$%!::|&@@@@@####@@@&$%;'':|%|!::::::!$$&&&&&@&&&&&&$$$$$$%%|||$@@@@@@@@@@@@@@@####@@@@@&&&&&%'.```..`...``: ...........................``..'!%|||||!%$&&&&&&&&&&&&@@@@@&$$$%%$$@@@&$%!::|&&&&&&&&$|;::;||||%%|::::::!$$&&&&@@@&&&&&&$$$$$$%%|||$@@@@&&&&&&&@@@@@@@@@@@@@@&&&$$|'.```.......: ...........................```...`;||||%$&&&&&&&&&&&&@@@@@&$%%$$&@@@@&&&&$|!!;;!||;:;!|%%||%$&&$|;:::::!$$&&&@@@@@@@&&&&$$$$$$%%%%|%&@@@&&&&&&&&&&&&&&&&&@@@&&&&$$$!`.``.......: */ int n; int s[505], t[505]; unsigned long long U[505], V[505]; int u[505], v[505]; unsigned long long ans[505][505]; int res[505][505]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", s + i); } for (int i = 1; i <= n; i++) { scanf("%d", t + i); } for (int i = 1; i <= n; i++) { scanf("%llu", U + i); } for (int i = 1; i <= n; i++) { scanf("%llu", V + i); } for (int b = 0; b < 64; b++) { for (int i = 1; i <= n; i++) { u[i] = ((U[i] >> b) & 1); v[i] = ((V[i] >> b) & 1); } vector<int> rs, cs; int R[2] = {0, 0}, C[2] = {0, 0}; for (int i = 1; i <= n; i++) { if (!s[i] && u[i]) { for (int j = 1; j <= n; j++) { res[i][j] = 1; } R[1]++; } else if (s[i] && !u[i]) { for (int j = 1; j <= n; j++) { res[i][j] = 0; } R[0]++; } else { rs.push_back(i); } } for (int j = 1; j <= n; j++) { if (!t[j] && v[j]) { for (int i = 1; i <= n; i++) { res[i][j] = 1; } C[1]++; } else if (t[j] && !v[j]) { for (int i = 1; i <= n; i++) { res[i][j] = 0; } C[0]++; } else { cs.push_back(j); } } if (rs.size() == 1) { int i = rs[0]; for (int $ = 0; $ < cs.size(); $++) { int j = cs[$]; if (R[v[j]]) { res[i][j] = u[i]; } else { res[i][j] = v[j]; } } } else if (cs.size() == 1) { int j = cs[0]; for (int $ = 0; $ < rs.size(); $++) { int i = rs[$]; if (C[u[i]]) { res[i][j] = v[j]; } else { res[i][j] = u[i]; } } } else { for (int i = 0; i < rs.size(); i++) { for (int j = 0; j < cs.size(); j++) { res[rs[i]][cs[i]] = ((i + j) & 1); } } } for (int i = 1; i <= n; i++) { int val; if (!s[i]) { val = 1; for (int j = 1; j <= n; j++) { val &= res[i][j]; } } else { val = 0; for (int j = 1; j <= n; j++) { val |= res[i][j]; } } if (val != u[i]) { puts("-1"); return 0; } } for (int j = 1; j <= n; j++) { int val; if (!t[j]) { val = 1; for (int i = 1; i <= n; i++) { val &= res[i][j]; } } else { val = 0; for (int i = 1; i <= n; i++) { val |= res[i][j]; } } if (val != v[j]) { puts("-1"); return 0; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { ans[i][j] |= (((unsigned long long)res[i][j]) << b); } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { printf("%llu%c", ans[i][j], j == n ? '\n' : ' '); } } return 0; }
#include <bits/stdc++.h> using namespace std; /* Coded by 秦惜梦 The most attractive girl in the world ......... `;!!!!!!!!!;;;;;;;;::::::'''''''``''''''''````````````````````....`:;;;;;:'.....`:|$$$$$$$|;;;:`. ..........`''``...`''``. ........ ... ... .... ... ... ' ........ '!!!!!!!!!;;;;;;;:::::::::''''':::''''`````````````````````......`:;;;;;!%$$%!'.....`:|$%!;;;'.... .....`....`'''`...```.. ........ .. ... .. ... ... ' ........ .:!!!!!!!!;;;;;;;:::::::::::::::'''''''`````````..```````........`:;!%$$$$$$$$$$$%!'.....`:|!'````.. .........`''``....... ........ ... ... ... .. .. .' ....... `;!!!!!!;;;;;;;;::::::::::::::::'''''```````````.``````... .`';|%$$$$$&&$$$$$$%%;'..`'':'''``.. ...``.....```. .... ....... ... ... ... ... ... .' ....... . '!!!!!!;;;;;;;:::'''''''''::::::'''```````````````````.........':'`.......`:!%%|||%$$$$$&%;'::::''``. .```.. .... .... ....... .. ... .. ... ... ..' ...... '::'''':::::::::::::'''''''''''::::''''``````````````````.........'!$$$$$$%!:`.......`:!%&&&|'``':::'''``.....```. .... ... ...... ....... .. .. ... ..' ``... .`.``'::::::::;;;;:::::'''''''`'''''`````````````..```````........'!$$$$$$$$$$$$$$%!;'`.....`'`..`'::''''`.....```.. .... ... ...... ........ .... ....... ....' ````. .````.`;!!!;;;;;;;;::'''''''``'''''`````````````````````````.. ....`:!|%$$$&&&&&&&$%%$&&&&@&$|::'`.`''''''''`....````. .... ... ...... . .....```..``..... ... ' ```` .````. `;!!;;;;;;;:::::'''''':::'''''````````````........`````.... ........````........``'::::::::'``.``'''''``...````.. .... ... ...... . ......``.```.... .. ' ```. .```. .`';!!;;;;;;;:::::::::::::'''''``````````..........````````...`;$$$$&&&&&&$%%||||!|!;;::::::::'`...`'''''`....````. .... ... ..... . .. .``..```.... .. ' ``. .``. .`'`';!;;;;;;;;:::::::::::'''''`````````...........`````````....'!|%%%%%%%%%%%%%%%%%%$&&&|:'''''''`...`'''''`....```. .... ... ..... . .. .. ...... . .' `. .`. `''''`';!;;;;;;;::::::::::'''''''```````..........````````````....:|%%%%%%%%%%%%%%%%%%%%%%|:`''''''''`...`''''`....```.. ... .. ..... .. . .. .. ... .. ..' ` . .`'''''``';!;;;;;;;:::::::''''''''''```.``........```````````````````!%%%%%%%%%%||!;:''`.........`'''''''`...`''''`...````..... .. .... .. . . . .. .. ...' .''''''````';!;;;;;;;:::::'''''''''''```````````````````````````.........``````... ...```':;!!:....`'''''''``..`'''`....```. ... .. .... .. . . .. .. ...' .`''''''''``````;!;;;;;;:::::'''''''''''``````````'''''''''``....```````````````````````````':!||%|;``....`''''''``..`''``....`.. ... ... . . . .. .. . ... ' .'''''''''````````:;;;;:::'''''':::::::::::::''''''''''''``..``````....```````````````````````````:!!'`'`.....`'''''``...```. ......... .... . .. . . .. ... ' `'''''''''````';;;:::::::::::::::::::::::''''```````````..........```````````````````````````````````'`.``'``....`''''``.. .`.. ..... ... ... . .. .. . .. ' .'''''''''```````';;:::::''''''''''''''''''`''```````.`````.....````````````````````````````````''``````....``''`...``''```...... ........ ... . . . . .. ' `''''''''````'''`````.`::::::::'''''''''''''''''``.``.```........````````````''''`````````````````''''''''`....``'``...``````...... ........ .. . . . . . .. ' .`'''''''```'''''````````':::::::''''''''''''''``.``.`............`````````'''''''''''''''``````````'''''''''`.....````....```... .. ...... . . . .' `'''''''`''''''''````````.`::::::'''''''''''''`.```..............``````````'''''''''''''''''````````''''''''''``.......```......... . .... . ........ ' .`''''''`''''''''``````````.`:::::::'''''''''``.`..............```````'''''''''''''''''''''''''``````'''''''''''''.........``... ..... . ... ..`:::::::::::::'`. ' .'''''`''''''''``````````````':::::''''''''``..````````````````````''''''''''''''''''':''''''```''````''''::''''''`.```.......... ..... .... `'::::::::::::::::`. ' ....`''''''''''```````````````.`':::::'''''`...``````````''''''''''''''''''''''''''''''';:'''``''`::````';:''''''''''.....``......... ..... ... `::::::::::::::::::'`.....' ......`''''''''``````````````````.':::::::'`...``'''````''''''''''''''''''''''''''''''';!:;:'''':!;::'```````''''''''''` ........ ..... ... .. ....`':::':::::::::::'... ' .......`'''''`````````````````````.`':::'```.`''''''````''''''''':'''::'''::''':;::!!!;:;!;;:```````::`````````'''''''''`. ............ .. .. .':::::::::''` ' ........`''`````````````````````````..`':''`:;:'':''':''''''''''''::'':;:'''''''''::'''''':;;;:``````:;'```''``````'``'''''`.... ........... .. `::::::'`. ' ..........`````````````````````````'::::''':;!!!!;:'::':!;;;:::'''';;'''::::''''':'''::'''''''::'`````':''``''````::`':'''''''''. ...... .''`.... ' .`'`.......```````````````````````````````'':!;:::::::::':;::::::::''::''`''::::'`''''':::'':''`:;'`````':'```''`````::`````'''''':;'.................. ....... . ' `'''''```````````````````````````````````.`;!:::::::::::'''::::::::''::''``'::::'``'''''::''''''':'````````````'`````''````````````:!!;'................ .......... ' '''''`````````````````````````````````````;!;;;:':::''::''''::::;;:'':::'```'::'````''''''''''''':'```````````''````````````````````';!!!;'.... ...... ....... ' ''''````````````````````````````````````';!;;;:'::::':''`''':::;;;:'''':'``'':'````.```''''''''`':'````````````'`````````..``....`...`:!!!!:`.`..... . ' '''````````````````````````````````````':;!;;:`'::':'''``''':::;;;:''``'```'':'``....''`'''''''`''`.`````````````.````````.............';;'.`:;;;'`. ..... ... ' ''````````````````````````````````````'':!;::'`::':::''`''''':;;;;:```````'''''```...''`'''''''`''`.``.````````````````````............... `;;;;;;;;;:`. .... ....' ''''''''````````````````````````````''`:!;;:''':''::''`'':''':;;;;'```'```''''''`.`'``:'''::''''''```````````````````````````.............`:;;;;;;;;;;;'. . .... ..' :::::::''''````````````````````````''`'!!;:''''''':''`''''''':;;;:```::``'''':'''`';:';:'::::':`''`''`````````````````'``````````..........`:;;;;;;;;;:. `'.. ..... ' |%$$%%!;;:'''````````````````````''``';!;:'''':'``'''`'':''':::;:'``:!:``':::::::`:!;';;':::::''`''::````'''''````````''`````````...........`:;;;;;;;'. .':` `;;;;:. .. ..... ' @@@@@@@@$|;:''`````````````````''```';!;:::::::'``````'':''::::::'`'!|:`':::;:::'';|!:;;'''''''::::;:``'::''`'````````''````````````.........`:;;;;;` .:;'..';;;;;;;;;:` ......' @@@@@@@@@@$|;:''`````````````:'`````;;;:';;;;::'`'````'':''::::::'`;!!;':::::::'`.';!;;;:::::';!!::;'`':::'``'`.``````''````````.......... ..``';;:` .';;` `:;;;;;;;;;:` `;;;;;; @@@@@@@@@@@&|;:'``````````''```````;;::':;;;;:'`''```'':'::::;;;:':;|!!;:'''''::::!||!!!!;!!!!||;:!'`:::::'````..``````''`````.......... . ..`':;` .';;:` ';;;;;;;;;;:. ';;;;;; @@@@@@@@@@#@$!:''`````````````````::```';;;;::``'''``'::':::;;;::;;!|||!::;;!!!;;;:'``````'':!!!!|:``':::'`````:;:`.``````............. . ..`';' .';;;'..:;;;;;;;;;;'..';;;;;; @@@@@@@@@@@@$|;:'````````````````::````:;;;::'.`''```''''':::;:::;||%|||%%%%%|!:''''`...`'':!;:;|;```:::'``''`';!;'..`````.............. . ..`''. .';;;:` `;;;;;;;;;;;' .:;;;;;; @@@@@@@@@@@&%!;:'```````````````''````':;;;::'..''```````:::::';||%%%%%%$$&&&%!;!|$&%:..';!%%!!|!'`;::::'``''';!;;'...````.............. ....``.. .';;;;'..';;;;;;;;;;;` `:;;;;;; @@@@@@@@@#@%!!;:'````````````````````.'''::::`..````'''::!||||%%%%&&&&&&&&&&&&&$&&&%||||!|%%%%|!:';;;;!;``''`:;;;:`....`...................`....```. .`':::` `:;;;;;;;;;;:` `;;;;;;; @@@@@@##@$|!!;:''```````````````````````':'```..`````':!;:''''':!%$&&&&&&&&&&&&$$$|!;;!|%%%%%%|;':;''::'`'''`:!;:`........................```..````........ .':;;;;;;;;;'. ';;;;;;; !%$$$$%%|!!!;:''``````````````````````````````````````';!:'::'``':|$&&&&&&&&&&&&$$$$$$$$%%%%%|!:```''::'''''```...........................``..`'''`........ ......'::;;'..';;;;;;; ;!!!!!!!!!!;:''``````````````````````````````..````````'!%!;!;;!!%$%$&&&&&&&&&&&&$$$$$$$$$$%%||;``'''':''''``..`.... ... .................`'''````..... .....`....... `::;;;;; ::;!!!!!;;:''````````````````````````````````...````````'!%|!|%$$$$%$&&&&&&&&&&&&&&$$$$$$$$%|||:``''''''''```..`.... .. ... ....`'''`''```.... .'|%%;...... .... .' ``'::::'''````````````````````````````````````..`...```'`'|&$$$$$$$%$&&&&&&&&&&&&&&$$$$$$$$%%%|:`'''''''''```..`.... ....`''```''```... .:%%%%|:...... .......' .````````````````````````````````````````````.``..```````:|&$$$$$$|%$&&&&&&&&&&&&&&&&&$$$$%%%|:'`'''''''````..`.... .``'`````''````. :%%%%%;`....... ........' .``````````````````````````````````````````..`..`````````:%&&&&&&$%|%$&&&&&&&&&&&&&&&&$$$%$%|:'`'''''''````.``..... .``'`````'`'':|:.'!%%%%|'.`````. .......' .```````````````````````````````````````````'`..`````````.:$&&&&&&&&&&&&&&&&&&&&&&&&&&&$$$$%|;'```''''```````....... .``'```'``':|%%|'.'|%%%%;```````...........' .`````````````````````````````````````````:'`..''````````..!&&&&&&&&&&&&&&&&&&&&&&&&&&&$$&$%%;''```''````````.... . .'''`.`'``'`;%%%;``;%%$%!'..................' .``````````````````````````````````````;|:.``.`''''`````...`|&&&&&&&&&&&&&&&&&&&&&&&&&&$$&&$%!:'```````````.``.. .`''```;;'''';%%%:.:%&&$|:...................: .```````````````````````````````````'!!```'`.`:!:''`````. ..`|&&&&&&&&&&&$%%$$$%|%$$&&&$$&&&$%;'`.``..`......`. ..`''''!;''''':|%$|'`!&&$|:...................`: .````````````````````````````````;|:````'::`'!;::''''`. ...`!&&&&&&&&&&&&&&$&&&&&&&&&&$&&&&$|:'```.``......... .`. ....`'''```''''';$&&&;`:!;`......................`: .`````````````````````````````:|;`````'';:'`';:'''```.. ......'|&&&&&&&&&&&%%%$&&&&&&&$$&&&&&%;'`'`..```........ `` `;:`''''``'```'!$&&&%!'.....................```````: .``````````````````````````:|;``````'':;:'``':'''`````. ........`:%&&&&&&&&&&&&&&&&&&&$&&&&|!!!;'''`....``......`. .;%%;`''''';|||!;:''::;;' ..``......``````````````````: .```````````````````````!%:````````'':;:'```'':''````.. ............'|&@&&&&&&&&&&&&&&&$$|;!!!!!;:'``'`....``...````.. `:;;:'''!%;::::::::;;`. .````````'''````````````````: .```````````````````:%!'``````````'::::'````'''''````. .............```;$&@&&&&&&&&&&$|;;!!!!!!!!;```::` ...``.';;'```. `:::'';$$|;:::::!;'`....``````''''''''````''''`````: .```````````````:%|'`````````````'::::'`````'''''''``. ..... ....`````````;$&&&&@&|::!!;!!!!!!!!|!'```';'.. ....'!%%|!::``'':'':|$&&$|!!;:;:'`. .```````':::::''''''''''''''': .``````````;||:```````````````''::'::'````.`'''''''`.. ....... ..`````````````';:`````';!!!!!!!||||!;'```';!:`... ..`:|%%!'''''`:!%$&&&$$$!:;;;:'``'```''::::::::''''':::::''''; ..``';;:'```````````````````'''::'':'```````'''::''`.. ....... ..``````````````````. '||!!!|||||||!!;'````'!|;'``````````'''`';:'`'%&&&&&&|;!;:;!!!;;::;;::::::''''::::::::::; ``...``````````````````````''''''::''''`````````':::''``. ......... ....```````````... .:!||||||%%%|||!!!!;'````'!||;'```.`'''`.`.`''`.;$&&&$: .``'::::;!|%$$%|;:''':::::::::::; .````````````````````'''''''::```'````````.`:::'''```. .......... ............. `!%|!!||||%%||||!!!!!|%%%!:````````..`'''..``''`.....':. . ..`':;;;;;;;::::;!%&%!;;;;:::::; .`````````````````''''''''''''''::'''````..`::''''`````. ........``............ .;%%%|!!!||%%%%%%%|!!!|%%%%%%||%%%%%%!'`'''`````....``..... .. .`':;;;;;;:::::;!%%!;;;;;; .`````````````'''''''''''```''''::'''''``..`''''''```````........````````.....:%%%$%||!|||%%%%%%%||!|%%%%%%%%%%%%|||!'`'''';%%|;`````......'`. .. `':::::::;;;;;|%!;;; .``````````''''''''''```````'```''''````..`.`'''''````````.... ..```.... `|%%%%$%|||!|%%%%%%%%%|!|%%%%%%%%%%%%%%%|:`'''`;%%%%!:.:!|%$$$$|;:'`... .``.. .`. '::::;;;;;;!%!; %!'..```````''''''''''``````````'```'````````.``.`'''''```````....... .;%%%%%%%|!!!||%%%%%|!!!!!|%%%%%%%%%%%%%%%%:`''''!%%%!!!:`:!|%$$$$$$$$$%|'`. .```'`.``. .. .':::|% %%%%%%;```''''''''```````````````'``''``````.````.`''''`..'````.......`'''';|%%%%%%%%||%%%%%%%%%%%|!!%%%%%%%%%%%%%%%%%:`'''';%%||||:`:!|%$$$$$$$$$$$$$%;``. .``''`. ' $$$%%%%%$$|:''````````````````````''''``````.`````.`'''''`... .`':|%$$%%%%%%%%%|!|%%%%%%%%%%|||%%$$%%%%%%%%%%%%%:`'''';%||%%%;.:||%$$$$$$$$$$$$$$&&&%:...````''` ' $$$$$$$$$$%%%%%;`.``````````````````':'``````.`````.`'''''`......`''':!%%%%%%%%%%%%|!!%%%%|||%%|!|%%%%%%%%%%%%%%%%%%:`'''';||%%%|:`;||%$$$$$$$$$$$$&&&&&&&$|'...```'''` ' |%%$$%%$$$$$%%%%%%%;`..`.`````````````':'````.``.```..`''````''''':|!:|%%%%%%%%%%%%|!!|%|||%||!!%%%%%%%%%%%%%%%%%%%:`'''':|%%%%;``;|%%$$$$$$$$$$&&&&&&&&&&&$$;...`````''` ' @$|||||%%%%%%%%%%%%%%%%|:`....```````.`''``'''`````````.````''':;|%|;:|%%%%%%%%%%||!!|||||||!!|%%%%%%%%%%%%%%%%%%%:`'''';|%%%%:.'!|%$$$$$$$$$$$$$&&&&&&&&&&&&$!`..``````''` ' ||||&@&%|!|||%%%%%%%%%%%%%%|:.....```````'````.........`!%%%%%%%%|||;:|%%%%%%%%%%||!!|%|%|!!||%%%%%%%%%%%%%%%%%%%:`'''';|%%%!'`;||%$$$$$$$&&$$$$$&&&&&&@&&&&&$$!`..``````````. ' |||||!|!|$@&%|!|||%%%%%%%%%%%%%:. ...`````''``........:|%%%%%%%%%||%;:|%%%%%%%$%%%%!;|||!!||||%%%%%%%%%%%%%%%%%%:`'''';||%|:`:||%%$$$&&&&&$$%%$$&&&&@######&&$$$!`..``..```````. ' ||||||||!|!!!!|%$%|||||%$%%%%%%%%%!`.....````'`......'|%%%%%%%%%%|%$|;%&&&&&&&&$$$$|!|!!%$$$$&&&&&&&&&$$$$$$$$%;`''':;|||;``;||%$$&&&&&&&$$%%$$&&&&&@######&$$$$%:.....``````````. ' ||%%||||||!!|!!|||!|%$%|||%%%%%%%%%%%|:.....`.`'`...'|%%%%%%%%%$$$$&|:|&&&&&&&&$$$$|;!|$$$$&&&&&&&&&&&&&&&&@&$;`''':;||;``!||%$&$$$&&&&$%%%%%$&#####@@###@&$$&$$$!`.......`````````: .:!|%%|||||||||||||||!|||||%%%%$%%%%%;`.......``:%&&&&&&&&&&&&$$$%;;$&&&&&&&&&&$||$$$&&@@@@@@@@@@@@@@@@@@&!'''':;!:`'!||%$&$$$$$&&&$%%|%%$@######@&&&&&$$$$$$$%;..`...`...`````': .....`;|%%%%%|||!|||!|||!!!||%%%%%%%%%%;`.....:%&&&&&&&&&&&&$$$&$|'!$&&&&&&&$$%$$$&&@@@@@@@@@@@@@@@@@@@@!'::':'`.'|||%$$&&$$$$$&&$%%||%$@#########@@&&$$$$&$%$!`..`...```..````: ..........'!|%|%|||||!||||||||||%%%%%%%%%:...'|&&&&&&&&&&&&&$$&&&$;'|&&&&&$%%$$$&&@@@@@@@@@@@@@@@@@##@@!'::::'`:|%%%$$$&&&$$$$$$$%%|%&@@##########@@@@&&&$$$$$%;..``....````.``: .....```......`;|%|%%||||||||||||||%%%%%%|!:`!&&&&&&&&&&&&&&$$$&&$%::%&$$%%$$&&&@@@@@@@@@@@@@@@@@@@#@&|::::::;|%%$$$$&&&&&$$$$$$%%%%&@@@###########@@@@&&&&&$$$!`..`.....`````.' ..................`;|%%%|%%|||!|||||||%%%|||$&&&&&&&&&&&@&&&$$$&&&$%;;%%%$$&&@@@@@@@@@@@@@@@@@##@#@&$;':::::!%%$$$$&&&&&&&$$$%%%%%|$@@@@##@#########@@@@@&&&&$$|:...`.....`````: ............``..```...`;|%|||%||!!|||||||||%&&&&&&&&&&@@@@&&$$$&&&&$%;;%$$&@@@@@@@@@@@@@@@@@@#@@&$!`.`:::::!%$$$&&&&&&&&$$$$$$%%%||&@@@@##@@@@########@@@@&&&&$$!`...`.....````: ...................```...`:|%||||||||!||||%&&&&&&&&&&&@@@@@&$%&&$$$%%%;:!$&@@@@@@@@@@@@@@#@@&&%;``;|;:::::!$$$&&&&&&&&&&$$$$$%%%%||&@@@@@@@@@@##@#####@@@@@&&&&&$:..```.....```: .....................``.`...`;|%|||||||||%&&&&&&&&&&&&@@@@@@$$&$$%%$$$%!::|&@@@@@####@@@&$%;'':|%|!::::::!$$&&&&&@&&&&&&$$$$$$%%|||$@@@@@@@@@@@@@@@####@@@@@&&&&&%'.```..`...``: ...........................``..'!%|||||!%$&&&&&&&&&&&&@@@@@&$$$%%$$@@@&$%!::|&&&&&&&&$|;::;||||%%|::::::!$$&&&&@@@&&&&&&$$$$$$%%|||$@@@@&&&&&&&@@@@@@@@@@@@@@&&&$$|'.```.......: ...........................```...`;||||%$&&&&&&&&&&&&@@@@@&$%%$$&@@@@&&&&$|!!;;!||;:;!|%%||%$&&$|;:::::!$$&&&@@@@@@@&&&&$$$$$$%%%%|%&@@@&&&&&&&&&&&&&&&&&@@@&&&&$$$!`.``.......: */ int n; int s[505], t[505]; unsigned long long U[505], V[505]; int u[505], v[505]; unsigned long long ans[505][505]; int res[505][505]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", s + i); } for (int i = 1; i <= n; i++) { scanf("%d", t + i); } for (int i = 1; i <= n; i++) { scanf("%llu", U + i); } for (int i = 1; i <= n; i++) { scanf("%llu", V + i); } for (int b = 0; b < 64; b++) { for (int i = 1; i <= n; i++) { u[i] = ((U[i] >> b) & 1); v[i] = ((V[i] >> b) & 1); } vector<int> rs, cs; int R[2] = {0, 0}, C[2] = {0, 0}; for (int i = 1; i <= n; i++) { if (!s[i] && u[i]) { for (int j = 1; j <= n; j++) { res[i][j] = 1; } R[1]++; } else if (s[i] && !u[i]) { for (int j = 1; j <= n; j++) { res[i][j] = 0; } R[0]++; } else { rs.push_back(i); } } for (int j = 1; j <= n; j++) { if (!t[j] && v[j]) { for (int i = 1; i <= n; i++) { res[i][j] = 1; } C[1]++; } else if (t[j] && !v[j]) { for (int i = 1; i <= n; i++) { res[i][j] = 0; } C[0]++; } else { cs.push_back(j); } } if (rs.size() == 1) { int i = rs[0]; for (int $ = 0; $ < cs.size(); $++) { int j = cs[$]; if (R[v[j]]) { res[i][j] = u[i]; } else { res[i][j] = v[j]; } } } else if (cs.size() == 1) { int j = cs[0]; for (int $ = 0; $ < rs.size(); $++) { int i = rs[$]; if (C[u[i]]) { res[i][j] = v[j]; } else { res[i][j] = u[i]; } } } else { for (int i = 0; i < rs.size(); i++) { for (int j = 0; j < cs.size(); j++) { res[rs[i]][cs[j]] = ((i + j) & 1); } } } for (int i = 1; i <= n; i++) { int val; if (!s[i]) { val = 1; for (int j = 1; j <= n; j++) { val &= res[i][j]; } } else { val = 0; for (int j = 1; j <= n; j++) { val |= res[i][j]; } } if (val != u[i]) { puts("-1"); return 0; } } for (int j = 1; j <= n; j++) { int val; if (!t[j]) { val = 1; for (int i = 1; i <= n; i++) { val &= res[i][j]; } } else { val = 0; for (int i = 1; i <= n; i++) { val |= res[i][j]; } } if (val != v[j]) { puts("-1"); return 0; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { ans[i][j] |= (((unsigned long long)res[i][j]) << b); } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { printf("%llu%c", ans[i][j], j == n ? '\n' : ' '); } } return 0; }
replace
283
284
283
284
0
p02704
C++
Runtime Error
#pragma region Macros #pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define ld long double #define rep2(i, a, b) for (ll i = a; i <= b; ++i) #define rep(i, n) for (ll i = 0; i < n; i++) #define rep3(i, a, b) for (ll i = a; i >= b; i--) #define pii pair<int, int> #define pll pair<ll, ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define vec vector<int> #define vecll vector<ll> #define vecpii vector<pii> #define vecpll vector<pll> #define vec2(a, b) vector<vec>(a, vec(b)) #define vec2ll(a, b) vector<vecll>(a, vecll(b)) #define vec3(a, b, c) vector<vector<vec>>(a, vec2(b, c)) #define vec3ll(a, b, c) vector<vector<vecll>>(a, vec2ll(b, c)) #define fi first #define se second #define all(c) begin(c), end(c) #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define lb(c, x) distance(c.begin(), lower_bound(all(c), (x))) #define ub(c, x) distance(c.begin(), upper_bound(all(c), (x))) using namespace std; int in() { int x; cin >> x; return x; } ll lin() { unsigned long long x; cin >> x; return x; } string stin() { string s; cin >> s; return s; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } vec iota(int n) { vec a(n); iota(all(a), 0); return a; } void print() { putchar(' '); } void print(bool a) { cout << a; } void print(int a) { cout << a; } void print(long long a) { cout << a; } void print(char a) { cout << a; } void print(string &a) { cout << a; } void print(double a) { cout << a; } template <class T> void print(const vector<T> &); template <class T, size_t size> void print(const array<T, size> &); template <class T, class L> void print(const pair<T, L> &p); template <class T, size_t size> void print(const T (&)[size]); template <class T> void print(const vector<T> &a) { for (auto &e : a) { print(e); cout << " "; } cout << endl; } template <class T> void print(const vector<vector<T>> &a) { for (auto &e : a) { print(e); } } template <class T> void print(const deque<T> &a) { for (auto &e : a) { print(e); cout << " "; } cout << endl; } template <class T, size_t size> void print(const array<T, size> &a) { for (auto &e : a) { print(e); cout << " "; } cout << endl; } template <class T, class L> void print(const pair<T, L> &p) { cout << '('; print(p.first); cout << ","; print(p.second); cout << ')'; } template <class T, size_t size> void print(const T (&a)[size]) { print(a[0]); for (auto i = a; ++i != end(a);) { cout << " "; print(*i); } } template <class T> void print(const T &a) { cout << a; } int out() { putchar('\n'); return 0; } template <class T> int out(const T &t) { print(t); putchar('\n'); return 0; } template <class Head, class... Tail> int out(const Head &head, const Tail &...tail) { print(head); putchar(' '); out(tail...); return 0; } ll gcd(ll a, ll b) { while (b) { ll c = b; b = a % b; a = c; } return a; } ll lcm(ll a, ll b) { if (!a || !b) return 0; return a * b / gcd(a, b); } vector<pll> factor(ll x) { vector<pll> ans; for (ll i = 2; i * i <= x; i++) if (x % i == 0) { ans.push_back({i, 1}); while ((x /= i) % i == 0) ans.back().second++; } if (x != 1) ans.push_back({x, 1}); return ans; } vector<int> divisor(int x) { vector<int> ans; for (int i = 1; i * i <= x; i++) if (x % i == 0) { ans.pb(i); if (i * i != x) ans.pb(x / i); } return ans; } int popcount(ll x) { return __builtin_popcountll(x); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int n) { return uniform_int_distribution<int>(0, n)(rng); } // #define _GLIBCXX_DEBU #define endl '\n' #ifdef _MY_DEBUG #undef endl #define debug(x) cout << #x << ": " << x << endl void err() {} template <class T> void err(const T &t) { print(t); cout << " "; } template <class Head, class... Tail> void err(const Head &head, const Tail &...tail) { print(head); putchar(' '); out(tail...); } #else #define debug(x) template <class... T> void err(const T &...) {} #endif #pragma endregion using ul = unsigned long long; vec s, t; int n; ul ans[510][510]; bool valid(vec x, vec y, vector<vec> &mp) { rep(i, n) { int m = mp[i][0]; if (s[i]) rep(j, n) m |= mp[i][j]; else rep(j, n) m &= mp[i][j]; if (m != x[i]) return false; } rep(j, n) { int m = mp[0][j]; if (t[j]) rep(i, n) m |= mp[i][j]; else rep(i, n) m &= mp[i][j]; if (m != y[j]) return false; } return true; } bool solve(vec x, vec y, ul k) { auto mp = vector<vec>(n, vec(n, -1)); rep(i, n) rep(j, n) { if (x[i] ^ s[i]) mp[i][j] = x[i]; if (y[j] ^ t[j]) { if ((mp[i][j] ^ y[j]) == 1) return false; mp[i][j] = y[j]; } } int cx = 0, cy = 0; rep(i, n) cx += x[i] ^ s[i]; rep(i, n) cy += y[i] ^ t[i]; cx = n - cx, cy = n - cy; if (cx == 0 or cy == 0) { if (!valid(x, y, mp)) return false; } else if (cx > 1 and cy > 1) { int cnt = 0; rep(i, n) { if (!(x[i] ^ s[i])) { int p = cnt++; rep(j, n) { if (!(y[j] ^ t[j])) mp[i][j] = p & 1, p++; } } } } else if (cx == 1 and cy == 1) { int tx, ty; rep(i, n) if (!(x[i] ^ s[i])) tx = i; rep(i, n) if (!(y[i] ^ t[i])) ty = i; rep(id, 2) { mp[tx][ty] = id; if (valid(x, y, mp)) break; if (id == 1) return false; } } else if (cx == 1) { int c[2] = {}; rep(i, n) if (x[i] ^ s[i]) c[x[i]]++; if (c[0] and c[1]) { rep(i, n) rep(j, n) if (mp[i][j] == -1) mp[i][j] = (i + j) & 1; } else { bool flag = false; rep(i, n) rep(j, n) { if (mp[i][j] == -1) { if (t[j]) { if (c[1]) mp[i][j] = x[i]; else mp[i][j] = 1; } else { if (c[0]) mp[i][j] = x[i]; else mp[i][j] = 0; } } } } if (!valid(x, y, mp)) return false; } else if (cy == 1) { int c[2] = {}; rep(i, n) if (y[i] ^ t[i]) c[y[i]]++; if (c[0] and c[1]) { rep(i, n) rep(j, n) if (mp[i][j] == -1) mp[i][j] = (i + j) & 1; } else { bool flag = false; rep(i, n) rep(j, n) { if (mp[i][j] == -1) { if (s[i]) { if (c[1]) mp[i][j] = y[j]; else mp[i][j] = 1; } else { if (c[0]) mp[i][j] = y[j]; else mp[i][j] = 0; } } } } if (!valid(x, y, mp)) return false; } if (!valid(x, y, mp)) return false; rep(i, n) rep(j, n) ans[i][j] += k * mp[i][j]; return true; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); n = in(); vector<ul> u, v; rep(i, n) s.pb(in()); rep(i, n) t.pb(in()); rep(i, n) { ul x; cin >> x; u.pb(x); } rep(i, n) { ul x; cin >> x; v.pb(x); } ul one = 1; rep(_, 64) { vec x, y; rep(i, n) x.pb(u[i] & 1), y.pb(v[i] & 1); for (auto &e : u) e >>= 1; for (auto &e : v) e >>= 1; if (!solve(x, y, one << _)) { assert(0); cout << -1 << endl; return 0; } } rep(i, n) { rep(j, n) { cout << ans[i][j] << " "; } cout << endl; } }
#pragma region Macros #pragma GCC optimize("O3") #include <bits/stdc++.h> #define ll long long #define ld long double #define rep2(i, a, b) for (ll i = a; i <= b; ++i) #define rep(i, n) for (ll i = 0; i < n; i++) #define rep3(i, a, b) for (ll i = a; i >= b; i--) #define pii pair<int, int> #define pll pair<ll, ll> #define pq priority_queue #define pb push_back #define eb emplace_back #define vec vector<int> #define vecll vector<ll> #define vecpii vector<pii> #define vecpll vector<pll> #define vec2(a, b) vector<vec>(a, vec(b)) #define vec2ll(a, b) vector<vecll>(a, vecll(b)) #define vec3(a, b, c) vector<vector<vec>>(a, vec2(b, c)) #define vec3ll(a, b, c) vector<vector<vecll>>(a, vec2ll(b, c)) #define fi first #define se second #define all(c) begin(c), end(c) #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define lb(c, x) distance(c.begin(), lower_bound(all(c), (x))) #define ub(c, x) distance(c.begin(), upper_bound(all(c), (x))) using namespace std; int in() { int x; cin >> x; return x; } ll lin() { unsigned long long x; cin >> x; return x; } string stin() { string s; cin >> s; return s; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } vec iota(int n) { vec a(n); iota(all(a), 0); return a; } void print() { putchar(' '); } void print(bool a) { cout << a; } void print(int a) { cout << a; } void print(long long a) { cout << a; } void print(char a) { cout << a; } void print(string &a) { cout << a; } void print(double a) { cout << a; } template <class T> void print(const vector<T> &); template <class T, size_t size> void print(const array<T, size> &); template <class T, class L> void print(const pair<T, L> &p); template <class T, size_t size> void print(const T (&)[size]); template <class T> void print(const vector<T> &a) { for (auto &e : a) { print(e); cout << " "; } cout << endl; } template <class T> void print(const vector<vector<T>> &a) { for (auto &e : a) { print(e); } } template <class T> void print(const deque<T> &a) { for (auto &e : a) { print(e); cout << " "; } cout << endl; } template <class T, size_t size> void print(const array<T, size> &a) { for (auto &e : a) { print(e); cout << " "; } cout << endl; } template <class T, class L> void print(const pair<T, L> &p) { cout << '('; print(p.first); cout << ","; print(p.second); cout << ')'; } template <class T, size_t size> void print(const T (&a)[size]) { print(a[0]); for (auto i = a; ++i != end(a);) { cout << " "; print(*i); } } template <class T> void print(const T &a) { cout << a; } int out() { putchar('\n'); return 0; } template <class T> int out(const T &t) { print(t); putchar('\n'); return 0; } template <class Head, class... Tail> int out(const Head &head, const Tail &...tail) { print(head); putchar(' '); out(tail...); return 0; } ll gcd(ll a, ll b) { while (b) { ll c = b; b = a % b; a = c; } return a; } ll lcm(ll a, ll b) { if (!a || !b) return 0; return a * b / gcd(a, b); } vector<pll> factor(ll x) { vector<pll> ans; for (ll i = 2; i * i <= x; i++) if (x % i == 0) { ans.push_back({i, 1}); while ((x /= i) % i == 0) ans.back().second++; } if (x != 1) ans.push_back({x, 1}); return ans; } vector<int> divisor(int x) { vector<int> ans; for (int i = 1; i * i <= x; i++) if (x % i == 0) { ans.pb(i); if (i * i != x) ans.pb(x / i); } return ans; } int popcount(ll x) { return __builtin_popcountll(x); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int n) { return uniform_int_distribution<int>(0, n)(rng); } // #define _GLIBCXX_DEBU #define endl '\n' #ifdef _MY_DEBUG #undef endl #define debug(x) cout << #x << ": " << x << endl void err() {} template <class T> void err(const T &t) { print(t); cout << " "; } template <class Head, class... Tail> void err(const Head &head, const Tail &...tail) { print(head); putchar(' '); out(tail...); } #else #define debug(x) template <class... T> void err(const T &...) {} #endif #pragma endregion using ul = unsigned long long; vec s, t; int n; ul ans[510][510]; bool valid(vec x, vec y, vector<vec> &mp) { rep(i, n) { int m = mp[i][0]; if (s[i]) rep(j, n) m |= mp[i][j]; else rep(j, n) m &= mp[i][j]; if (m != x[i]) return false; } rep(j, n) { int m = mp[0][j]; if (t[j]) rep(i, n) m |= mp[i][j]; else rep(i, n) m &= mp[i][j]; if (m != y[j]) return false; } return true; } bool solve(vec x, vec y, ul k) { auto mp = vector<vec>(n, vec(n, -1)); rep(i, n) rep(j, n) { if (x[i] ^ s[i]) mp[i][j] = x[i]; if (y[j] ^ t[j]) { if ((mp[i][j] ^ y[j]) == 1) return false; mp[i][j] = y[j]; } } int cx = 0, cy = 0; rep(i, n) cx += x[i] ^ s[i]; rep(i, n) cy += y[i] ^ t[i]; cx = n - cx, cy = n - cy; if (cx == 0 or cy == 0) { if (!valid(x, y, mp)) return false; } else if (cx > 1 and cy > 1) { int cnt = 0; rep(i, n) { if (!(x[i] ^ s[i])) { int p = cnt++; rep(j, n) { if (!(y[j] ^ t[j])) mp[i][j] = p & 1, p++; } } } } else if (cx == 1 and cy == 1) { int tx, ty; rep(i, n) if (!(x[i] ^ s[i])) tx = i; rep(i, n) if (!(y[i] ^ t[i])) ty = i; rep(id, 2) { mp[tx][ty] = id; if (valid(x, y, mp)) break; if (id == 1) return false; } } else if (cx == 1) { int c[2] = {}; rep(i, n) if (x[i] ^ s[i]) c[x[i]]++; if (c[0] and c[1]) { rep(i, n) rep(j, n) if (mp[i][j] == -1) mp[i][j] = (i + j) & 1; } else { bool flag = false; rep(i, n) rep(j, n) { if (mp[i][j] == -1) { if (t[j]) { if (c[1]) mp[i][j] = x[i]; else mp[i][j] = 1; } else { if (c[0]) mp[i][j] = x[i]; else mp[i][j] = 0; } } } } if (!valid(x, y, mp)) return false; } else if (cy == 1) { int c[2] = {}; rep(i, n) if (y[i] ^ t[i]) c[y[i]]++; if (c[0] and c[1]) { rep(i, n) rep(j, n) if (mp[i][j] == -1) mp[i][j] = (i + j) & 1; } else { bool flag = false; rep(i, n) rep(j, n) { if (mp[i][j] == -1) { if (s[i]) { if (c[1]) mp[i][j] = y[j]; else mp[i][j] = 1; } else { if (c[0]) mp[i][j] = y[j]; else mp[i][j] = 0; } } } } if (!valid(x, y, mp)) return false; } if (!valid(x, y, mp)) return false; rep(i, n) rep(j, n) ans[i][j] += k * mp[i][j]; return true; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); n = in(); vector<ul> u, v; rep(i, n) s.pb(in()); rep(i, n) t.pb(in()); rep(i, n) { ul x; cin >> x; u.pb(x); } rep(i, n) { ul x; cin >> x; v.pb(x); } ul one = 1; rep(_, 64) { vec x, y; rep(i, n) x.pb(u[i] & 1), y.pb(v[i] & 1); for (auto &e : u) e >>= 1; for (auto &e : v) e >>= 1; if (!solve(x, y, one << _)) { cout << -1 << endl; return 0; } } rep(i, n) { rep(j, n) { cout << ans[i][j] << " "; } cout << endl; } }
delete
339
340
339
339
0
p02704
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define cerr \ if (false) \ cerr struct Edge { int u, v; int cap, flow; Edge(int u_, int v_, int cap_, int flow_) : u(u_), v(v_), cap(cap_), flow(flow_) {} }; const int N = 501; const int LIM = N * N; namespace MaxFlow { const int INF = 1e9 + 239; const int MAX_LOG = 1; int n; int start; int end; int d[LIM]; int pnt[LIM]; vector<int> g[LIM]; vector<Edge> ed; int dfs(int u, int flow) { if (flow == 0) { return 0; } if (u == end) { return flow; } for (; pnt[u] < (int)g[u].size(); pnt[u]++) { int ind = g[u][pnt[u]]; int to = ed[ind].v; if (d[to] < d[u] + 1) { continue; } int pushed = dfs(to, min(flow, ed[ind].cap - ed[ind].flow)); if (pushed > 0) { ed[ind].flow += pushed; ed[ind ^ 1].flow -= pushed; return pushed; } } return 0; } bool bfs(int lim) { for (int i = 0; i < n; i++) { d[i] = INF; } d[start] = 0; queue<int> q; q.push(start); while (!q.empty()) { int u = q.front(); q.pop(); for (auto ind : g[u]) { int to = ed[ind].v; if (d[to] > d[u] + 1 && ed[ind].flow + lim <= ed[ind].cap) { d[to] = d[u] + 1; q.push(to); } } } return d[end] < INF; } void init(int n_, int start_, int end_) { n = n_; start = start_; end = end_; ed.clear(); fill(d, d + n, 0); fill(pnt, pnt + n, 0); for (int i = 0; i < n; i++) { g[i].clear(); } } int add_edge(int u, int v, int c) { assert(u < n); assert(v < n); int pnt_ed = (int)ed.size(); ed.push_back(Edge(u, v, c, 0)); ed.push_back(Edge(v, u, 0, 0)); g[u].push_back(pnt_ed); g[v].push_back(pnt_ed + 1); return pnt_ed; } int solve() { int ans = 0; for (int i = MAX_LOG; i >= 0; i--) { while (bfs(1LL << i)) { fill(pnt, pnt + n, 0); while (true) { int nw = dfs(start, INF); if (nw > 0) { ans += nw; } else { break; } } } } return ans; } }; // namespace MaxFlow int s[N]; int t[N]; int ub[N]; int vb[N]; int tans[N][N]; int solve_bit(int n) { int all_ok = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { tans[i][j] = -1; } } auto safe_set = [&](int i, int j, int val) { if (tans[i][j] != -1 && tans[i][j] != val) { all_ok = 0; } tans[i][j] = val; }; vector<int> need_row(n, -1); vector<int> need_col(n, -1); for (int i = 0; i < n; i++) { if (s[i] == 0 && ub[i] == 1) { // cerr << "R " << i << ' ' << 0 << endl; for (int j = 0; j < n; j++) { safe_set(i, j, 1); } } else if (s[i] == 1 && ub[i] == 0) { // cerr << "R " << i << ' ' << 1 << endl; for (int j = 0; j < n; j++) { safe_set(i, j, 0); } } else { if (s[i] == 0) { need_row[i] = 0; } else { need_row[i] = 1; } } } for (int j = 0; j < n; j++) { if (t[j] == 0 && vb[j] == 1) { for (int i = 0; i < n; i++) { safe_set(i, j, 1); } } else if (t[j] == 1 && vb[j] == 0) { for (int i = 0; i < n; i++) { safe_set(i, j, 0); } } else { if (t[j] == 0) { need_col[j] = 0; } else { need_col[j] = 1; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (tans[i][j] == -1 && need_row[i] != -1 && need_row[i] == need_col[j]) { cerr << "ADD " << i << ' ' << j << endl; safe_set(i, j, need_row[i]); } if (tans[i][j] != -1) { if (tans[i][j] == need_row[i]) { need_row[i] = -1; } if (tans[i][j] == need_col[j]) { need_col[j] = -1; } } } } { cerr << "need_row: " << endl; for (auto x : need_row) { cerr << x << ' '; } cerr << endl; } { cerr << "need_col: " << endl; for (auto x : need_col) { cerr << x << ' '; } cerr << endl; } if (!all_ok) { return 0; } cerr << "HR " << endl; vector<pair<int, int>> iv; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (tans[i][j] == -1) { cerr << "EMP " << i << ' ' << j << endl; iv.push_back({i, j}); } } } // who if0 if1 int pnt = (int)iv.size(); vector<int> v_row(n, -1); vector<int> v_col(n, -1); for (int i = 0; i < n; i++) { if (need_row[i] != -1) { cerr << "R: " << i << ' ' << need_row[i] << '\n'; v_row[i] = pnt; pnt++; } } for (int j = 0; j < n; j++) { if (need_col[j] != -1) { cerr << "C: " << j << ' ' << need_col[j] << '\n'; v_col[j] = pnt; pnt++; } } int st = pnt; int en = pnt + 1; MaxFlow::init(pnt + 2, st, en); cerr << "INIT OK" << endl; vector<int> ed_i(iv.size(), -1); vector<int> ed_r(iv.size(), -1); vector<int> ed_c(iv.size(), -1); for (int i = 0; i < (int)iv.size(); i++) { cerr << "+" << endl; ed_i[i] = MaxFlow::add_edge(st, i, 1); int ri, rj; tie(ri, rj) = iv[i]; cerr << ri << ' ' << rj << endl; if (v_row[ri] != -1) assert(need_row[ri] != need_col[rj]); if (v_row[ri] != -1) { ed_r[i] = MaxFlow::add_edge(i, v_row[ri], 1); } if (v_col[rj] != -1) { ed_c[i] = MaxFlow::add_edge(i, v_col[rj], 1); } cerr << "~" << endl; } int c = 0; for (int i = 0; i < n; i++) { if (v_row[i] != -1) { MaxFlow::add_edge(v_row[i], en, 1); c++; } } for (int j = 0; j < n; j++) { if (v_col[j] != -1) { MaxFlow::add_edge(v_col[j], en, 1); c++; } } cerr << "STARTING FLOW " << c << endl; int fl = MaxFlow::solve(); cerr << "FLOW OK" << endl; if (c != fl) { return 0; } for (int i = 0; i < (int)iv.size(); i++) { int ri, rj; tie(ri, rj) = iv[i]; if (ed_r[i] != -1 && MaxFlow::ed[ed_r[i]].flow) { tans[ri][rj] = need_row[ri]; } else if (ed_c[i] != -1 && MaxFlow::ed[ed_c[i]].flow) { tans[ri][rj] = need_col[rj]; } else { assert(MaxFlow::ed[ed_i[i]].flow == 0); tans[ri][rj] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { assert(tans[i][j] == 0 || tans[i][j] == 1); } } return 1; } typedef unsigned long long ull; const int K = 64; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<vector<ull>> ans(n, vector<ull>(n)); vector<ull> u(n); vector<ull> v(n); for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < n; i++) { cin >> t[i]; } for (auto &x : u) { cin >> x; } for (auto &x : v) { cin >> x; } int ok = 1; for (int i = 0; i < K; i++) { vector<int> nu(n); vector<int> nv(n); for (int j = 0; j < n; j++) { ub[j] = ((u[j] >> i) & 1); vb[j] = ((v[j] >> i) & 1); } if (!solve_bit(n)) { ok = 0; } for (int ff = 0; ff < n; ff++) { for (int ss = 0; ss < n; ss++) { if (tans[ff][ss] == 1) { ans[ff][ss] |= (1LL << i); } } } } if (!ok) { cout << -1 << endl; return 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << ans[i][j] << ' '; } cout << '\n'; } }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define cerr \ if (false) \ cerr struct Edge { int u, v; int cap, flow; Edge(int u_, int v_, int cap_, int flow_) : u(u_), v(v_), cap(cap_), flow(flow_) {} }; const int N = 502; const int LIM = N * N; namespace MaxFlow { const int INF = 1e9 + 239; const int MAX_LOG = 1; int n; int start; int end; int d[LIM]; int pnt[LIM]; vector<int> g[LIM]; vector<Edge> ed; int dfs(int u, int flow) { if (flow == 0) { return 0; } if (u == end) { return flow; } for (; pnt[u] < (int)g[u].size(); pnt[u]++) { int ind = g[u][pnt[u]]; int to = ed[ind].v; if (d[to] < d[u] + 1) { continue; } int pushed = dfs(to, min(flow, ed[ind].cap - ed[ind].flow)); if (pushed > 0) { ed[ind].flow += pushed; ed[ind ^ 1].flow -= pushed; return pushed; } } return 0; } bool bfs(int lim) { for (int i = 0; i < n; i++) { d[i] = INF; } d[start] = 0; queue<int> q; q.push(start); while (!q.empty()) { int u = q.front(); q.pop(); for (auto ind : g[u]) { int to = ed[ind].v; if (d[to] > d[u] + 1 && ed[ind].flow + lim <= ed[ind].cap) { d[to] = d[u] + 1; q.push(to); } } } return d[end] < INF; } void init(int n_, int start_, int end_) { n = n_; start = start_; end = end_; ed.clear(); fill(d, d + n, 0); fill(pnt, pnt + n, 0); for (int i = 0; i < n; i++) { g[i].clear(); } } int add_edge(int u, int v, int c) { assert(u < n); assert(v < n); int pnt_ed = (int)ed.size(); ed.push_back(Edge(u, v, c, 0)); ed.push_back(Edge(v, u, 0, 0)); g[u].push_back(pnt_ed); g[v].push_back(pnt_ed + 1); return pnt_ed; } int solve() { int ans = 0; for (int i = MAX_LOG; i >= 0; i--) { while (bfs(1LL << i)) { fill(pnt, pnt + n, 0); while (true) { int nw = dfs(start, INF); if (nw > 0) { ans += nw; } else { break; } } } } return ans; } }; // namespace MaxFlow int s[N]; int t[N]; int ub[N]; int vb[N]; int tans[N][N]; int solve_bit(int n) { int all_ok = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { tans[i][j] = -1; } } auto safe_set = [&](int i, int j, int val) { if (tans[i][j] != -1 && tans[i][j] != val) { all_ok = 0; } tans[i][j] = val; }; vector<int> need_row(n, -1); vector<int> need_col(n, -1); for (int i = 0; i < n; i++) { if (s[i] == 0 && ub[i] == 1) { // cerr << "R " << i << ' ' << 0 << endl; for (int j = 0; j < n; j++) { safe_set(i, j, 1); } } else if (s[i] == 1 && ub[i] == 0) { // cerr << "R " << i << ' ' << 1 << endl; for (int j = 0; j < n; j++) { safe_set(i, j, 0); } } else { if (s[i] == 0) { need_row[i] = 0; } else { need_row[i] = 1; } } } for (int j = 0; j < n; j++) { if (t[j] == 0 && vb[j] == 1) { for (int i = 0; i < n; i++) { safe_set(i, j, 1); } } else if (t[j] == 1 && vb[j] == 0) { for (int i = 0; i < n; i++) { safe_set(i, j, 0); } } else { if (t[j] == 0) { need_col[j] = 0; } else { need_col[j] = 1; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (tans[i][j] == -1 && need_row[i] != -1 && need_row[i] == need_col[j]) { cerr << "ADD " << i << ' ' << j << endl; safe_set(i, j, need_row[i]); } if (tans[i][j] != -1) { if (tans[i][j] == need_row[i]) { need_row[i] = -1; } if (tans[i][j] == need_col[j]) { need_col[j] = -1; } } } } { cerr << "need_row: " << endl; for (auto x : need_row) { cerr << x << ' '; } cerr << endl; } { cerr << "need_col: " << endl; for (auto x : need_col) { cerr << x << ' '; } cerr << endl; } if (!all_ok) { return 0; } cerr << "HR " << endl; vector<pair<int, int>> iv; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (tans[i][j] == -1) { cerr << "EMP " << i << ' ' << j << endl; iv.push_back({i, j}); } } } // who if0 if1 int pnt = (int)iv.size(); vector<int> v_row(n, -1); vector<int> v_col(n, -1); for (int i = 0; i < n; i++) { if (need_row[i] != -1) { cerr << "R: " << i << ' ' << need_row[i] << '\n'; v_row[i] = pnt; pnt++; } } for (int j = 0; j < n; j++) { if (need_col[j] != -1) { cerr << "C: " << j << ' ' << need_col[j] << '\n'; v_col[j] = pnt; pnt++; } } int st = pnt; int en = pnt + 1; MaxFlow::init(pnt + 2, st, en); cerr << "INIT OK" << endl; vector<int> ed_i(iv.size(), -1); vector<int> ed_r(iv.size(), -1); vector<int> ed_c(iv.size(), -1); for (int i = 0; i < (int)iv.size(); i++) { cerr << "+" << endl; ed_i[i] = MaxFlow::add_edge(st, i, 1); int ri, rj; tie(ri, rj) = iv[i]; cerr << ri << ' ' << rj << endl; if (v_row[ri] != -1) assert(need_row[ri] != need_col[rj]); if (v_row[ri] != -1) { ed_r[i] = MaxFlow::add_edge(i, v_row[ri], 1); } if (v_col[rj] != -1) { ed_c[i] = MaxFlow::add_edge(i, v_col[rj], 1); } cerr << "~" << endl; } int c = 0; for (int i = 0; i < n; i++) { if (v_row[i] != -1) { MaxFlow::add_edge(v_row[i], en, 1); c++; } } for (int j = 0; j < n; j++) { if (v_col[j] != -1) { MaxFlow::add_edge(v_col[j], en, 1); c++; } } cerr << "STARTING FLOW " << c << endl; int fl = MaxFlow::solve(); cerr << "FLOW OK" << endl; if (c != fl) { return 0; } for (int i = 0; i < (int)iv.size(); i++) { int ri, rj; tie(ri, rj) = iv[i]; if (ed_r[i] != -1 && MaxFlow::ed[ed_r[i]].flow) { tans[ri][rj] = need_row[ri]; } else if (ed_c[i] != -1 && MaxFlow::ed[ed_c[i]].flow) { tans[ri][rj] = need_col[rj]; } else { assert(MaxFlow::ed[ed_i[i]].flow == 0); tans[ri][rj] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { assert(tans[i][j] == 0 || tans[i][j] == 1); } } return 1; } typedef unsigned long long ull; const int K = 64; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<vector<ull>> ans(n, vector<ull>(n)); vector<ull> u(n); vector<ull> v(n); for (int i = 0; i < n; i++) { cin >> s[i]; } for (int i = 0; i < n; i++) { cin >> t[i]; } for (auto &x : u) { cin >> x; } for (auto &x : v) { cin >> x; } int ok = 1; for (int i = 0; i < K; i++) { vector<int> nu(n); vector<int> nv(n); for (int j = 0; j < n; j++) { ub[j] = ((u[j] >> i) & 1); vb[j] = ((v[j] >> i) & 1); } if (!solve_bit(n)) { ok = 0; } for (int ff = 0; ff < n; ff++) { for (int ss = 0; ss < n; ss++) { if (tans[ff][ss] == 1) { ans[ff][ss] |= (1LL << i); } } } } if (!ok) { cout << -1 << endl; return 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << ans[i][j] << ' '; } cout << '\n'; } }
replace
37
38
37
38
0
p02704
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) #define RREP(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define RFOR(i, a, n) for (int i = (int)(n)-1; i >= (a); --i) #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define dump(x) cerr << #x << " = " << (x) << endl #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl; template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; REP(i, SZ(v)) { if (i) os << ", "; os << v[i]; } return os << "]"; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << " " << p.second << ")"; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = uint64_t; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const int INF = INT_MAX / 2; const ll LINF = LLONG_MAX / 2; const ld eps = 1e-6; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); const int MAX = 64; int N; cin >> N; vi S(N), T(N); vvi U(MAX, vi(N)), V(MAX, vi(N)); REP(i, N) cin >> S[i]; REP(i, N) cin >> T[i]; REP(i, N) { ll u; cin >> u; REP(k, MAX) { U[k][i] = u >> k & 1; } } REP(i, N) { ll v; cin >> v; REP(k, MAX) { V[k][i] = v >> k & 1; } } vvll ans(N, vll(N)); bool valid = true; FOR(k, 0, MAX) { vvi A(N, vi(N, -1)); // 行 REP(i, N) { // 積が1 if (S[i] == 0 and U[k][i] == 1) { REP(j, N) { if (A[i][j] == 0) valid = false; A[i][j] = 1; } } // 和が0 if (S[i] == 1 and U[k][i] == 0) { REP(j, N) { if (A[i][j] == 1) valid = false; A[i][j] = 0; } } } // 列 REP(j, N) { // 積が1 if (T[j] == 0 and V[k][j] == 1) { REP(i, N) { if (A[i][j] == 0) valid = false; A[i][j] = 1; } } // 和が0 if (T[j] == 1 and V[k][j] == 0) { REP(i, N) { if (A[i][j] == 1) valid = false; A[i][j] = 0; } } } REP(i, N) { REP(j, N) { if (A[i][j] != -1) continue; // 両方1(和) if (U[k][i] == 1 and V[k][j] == 1) { A[i][j] = 1; continue; } // 両方0(積) if (U[k][i] == 0 and V[k][j] == 0) { A[i][j] = 0; continue; } } } // 残ってるのは, 片方に積0が複数個, もう片方に和1が複数個. // 両方とも2本以上残っていれば, 市松模様でok map<int, int> rows, cols; REP(i, N) { REP(j, N) { if (A[i][j] != -1) continue; rows[i] = 1; cols[j] = 1; } } if (rows.size() > 1 and cols.size() > 1) { vi rs, cs; for (auto &tp : rows) rs.push_back(tp.first); for (auto &tp : cols) cs.push_back(tp.first); REP(i, rs.size()) { REP(j, cs.size()) { A[rs[i]][cs[j]] = (i + j) & 1 ? 0 : 1; } } } else if (rows.size() == 1) { REP(j, N) { int cnt0 = 0, cnt1 = 0; REP(i, N) { if (A[i][j] == 0) cnt0 = 1; if (A[i][j] == 1) cnt1 = 1; } REP(i, N) if (A[i][j] == -1) { if (V[k][j] == 0) { if (cnt0 == 0) A[i][j] = 0; else A[i][j] = 1; } else { if (cnt1 == 0) A[i][j] = 1; else A[i][j] = 0; } } } } else if (cols.size() == 1) { REP(i, N) { int cnt0 = 0, cnt1 = 0; REP(j, N) { if (A[i][j] == 0) cnt0 = 1; if (A[i][j] == 1) cnt1 = 1; } REP(j, N) if (A[i][j] == -1) { if (U[i][k] == 0) { if (cnt0 == 0) A[i][j] = 0; else A[i][j] = 1; } else { if (cnt1 == 0) A[i][j] = 1; else A[i][j] = 0; } } } } vi rsum(N), rmul(N, 1), csum(N), cmul(N, 1); REP(i, N) { REP(j, N) { rsum[i] |= A[i][j]; csum[j] |= A[i][j]; rmul[i] &= A[i][j]; cmul[j] &= A[i][j]; } } REP(i, N) { if (S[i] == 0 and rmul[i] != U[k][i]) valid = false; if (S[i] == 1 and rsum[i] != U[k][i]) valid = false; } REP(j, N) { if (T[j] == 0 and cmul[j] != V[k][j]) valid = false; if (T[j] == 1 and csum[j] != V[k][j]) valid = false; } REP(i, N) { REP(j, N) { if (A[i][j]) ans[i][j] |= 1ULL << k; } } } if (!valid) { cout << -1 << endl; return 0; } REP(i, N) { REP(j, N) { if (j) cout << " "; cout << ans[i][j]; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); ++i) #define RREP(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define RFOR(i, a, n) for (int i = (int)(n)-1; i >= (a); --i) #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define dump(x) cerr << #x << " = " << (x) << endl #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl; template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; REP(i, SZ(v)) { if (i) os << ", "; os << v[i]; } return os << "]"; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << " " << p.second << ")"; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = uint64_t; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const int INF = INT_MAX / 2; const ll LINF = LLONG_MAX / 2; const ld eps = 1e-6; int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); const int MAX = 64; int N; cin >> N; vi S(N), T(N); vvi U(MAX, vi(N)), V(MAX, vi(N)); REP(i, N) cin >> S[i]; REP(i, N) cin >> T[i]; REP(i, N) { ll u; cin >> u; REP(k, MAX) { U[k][i] = u >> k & 1; } } REP(i, N) { ll v; cin >> v; REP(k, MAX) { V[k][i] = v >> k & 1; } } vvll ans(N, vll(N)); bool valid = true; FOR(k, 0, MAX) { vvi A(N, vi(N, -1)); // 行 REP(i, N) { // 積が1 if (S[i] == 0 and U[k][i] == 1) { REP(j, N) { if (A[i][j] == 0) valid = false; A[i][j] = 1; } } // 和が0 if (S[i] == 1 and U[k][i] == 0) { REP(j, N) { if (A[i][j] == 1) valid = false; A[i][j] = 0; } } } // 列 REP(j, N) { // 積が1 if (T[j] == 0 and V[k][j] == 1) { REP(i, N) { if (A[i][j] == 0) valid = false; A[i][j] = 1; } } // 和が0 if (T[j] == 1 and V[k][j] == 0) { REP(i, N) { if (A[i][j] == 1) valid = false; A[i][j] = 0; } } } REP(i, N) { REP(j, N) { if (A[i][j] != -1) continue; // 両方1(和) if (U[k][i] == 1 and V[k][j] == 1) { A[i][j] = 1; continue; } // 両方0(積) if (U[k][i] == 0 and V[k][j] == 0) { A[i][j] = 0; continue; } } } // 残ってるのは, 片方に積0が複数個, もう片方に和1が複数個. // 両方とも2本以上残っていれば, 市松模様でok map<int, int> rows, cols; REP(i, N) { REP(j, N) { if (A[i][j] != -1) continue; rows[i] = 1; cols[j] = 1; } } if (rows.size() > 1 and cols.size() > 1) { vi rs, cs; for (auto &tp : rows) rs.push_back(tp.first); for (auto &tp : cols) cs.push_back(tp.first); REP(i, rs.size()) { REP(j, cs.size()) { A[rs[i]][cs[j]] = (i + j) & 1 ? 0 : 1; } } } else if (rows.size() == 1) { REP(j, N) { int cnt0 = 0, cnt1 = 0; REP(i, N) { if (A[i][j] == 0) cnt0 = 1; if (A[i][j] == 1) cnt1 = 1; } REP(i, N) if (A[i][j] == -1) { if (V[k][j] == 0) { if (cnt0 == 0) A[i][j] = 0; else A[i][j] = 1; } else { if (cnt1 == 0) A[i][j] = 1; else A[i][j] = 0; } } } } else if (cols.size() == 1) { REP(i, N) { int cnt0 = 0, cnt1 = 0; REP(j, N) { if (A[i][j] == 0) cnt0 = 1; if (A[i][j] == 1) cnt1 = 1; } REP(j, N) if (A[i][j] == -1) { if (U[k][i] == 0) { if (cnt0 == 0) A[i][j] = 0; else A[i][j] = 1; } else { if (cnt1 == 0) A[i][j] = 1; else A[i][j] = 0; } } } } vi rsum(N), rmul(N, 1), csum(N), cmul(N, 1); REP(i, N) { REP(j, N) { rsum[i] |= A[i][j]; csum[j] |= A[i][j]; rmul[i] &= A[i][j]; cmul[j] &= A[i][j]; } } REP(i, N) { if (S[i] == 0 and rmul[i] != U[k][i]) valid = false; if (S[i] == 1 and rsum[i] != U[k][i]) valid = false; } REP(j, N) { if (T[j] == 0 and cmul[j] != V[k][j]) valid = false; if (T[j] == 1 and csum[j] != V[k][j]) valid = false; } REP(i, N) { REP(j, N) { if (A[i][j]) ans[i][j] |= 1ULL << k; } } } if (!valid) { cout << -1 << endl; return 0; } REP(i, N) { REP(j, N) { if (j) cout << " "; cout << ans[i][j]; } cout << endl; } return 0; }
replace
200
201
200
201
0
p02704
C++
Runtime Error
#pragma region kyopro_template #include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define fi first #define se second #define each(x, v) for (auto &x : v) #define all(v) (v).begin(), (v).end() #define sz(v) ((int)(v).size()) #define mem(a, val) memset(a, val, sizeof(a)) #define ini(...) \ int __VA_ARGS__; \ in(__VA_ARGS__) #define inl(...) \ long long __VA_ARGS__; \ in(__VA_ARGS__) #define ins(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define inc(...) \ char __VA_ARGS__; \ in(__VA_ARGS__) #define in2(s, t) \ for (int i = 0; i < (int)s.size(); i++) { \ in(s[i], t[i]); \ } #define in3(s, t, u) \ for (int i = 0; i < (int)s.size(); i++) { \ in(s[i], t[i], u[i]); \ } #define in4(s, t, u, v) \ for (int i = 0; i < (int)s.size(); i++) { \ in(s[i], t[i], u[i], v[i]); \ } #define rep(i, N) for (long long i = 0; i < (long long)(N); i++) #define repr(i, N) for (long long i = (long long)(N)-1; i >= 0; i--) #define rep1(i, N) for (long long i = 1; i <= (long long)(N); i++) #define repr1(i, N) for (long long i = (N); (long long)(i) > 0; i--) using namespace std; void solve(); using ll = long long; template <class T = ll> using V = vector<T>; using vi = vector<int>; using vl = vector<long long>; using vvi = vector<vector<int>>; using vd = V<double>; using vs = V<string>; using vvl = vector<vector<long long>>; using P = pair<long long, long long>; using vp = vector<P>; using pii = pair<int, int>; using vpi = vector<pair<int, int>>; constexpr int inf = 1001001001; constexpr long long infLL = (1LL << 61) - 1; template <typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template <typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; } template <typename T, typename U> ll ceil(T a, U b) { return (a + b - 1) / b; } constexpr ll TEN(int n) { ll ret = 1, x = 10; while (n) { if (n & 1) ret *= x; x *= x; n >>= 1; } return ret; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int s = (int)v.size(); for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i]; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } void in() {} template <typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template <typename T, class... U> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << " "; out(u...); } template <typename T> void die(T x) { out(x); exit(0); } #ifdef NyaanDebug #include "NyaanDebug.h" #define trc(...) \ do { \ cerr << #__VA_ARGS__ << " = "; \ dbg_out(__VA_ARGS__); \ } while (0) #define trca(v, N) \ do { \ cerr << #v << " = "; \ array_out(v, N); \ } while (0) #define trcc(v) \ do { \ cerr << #v << " = {"; \ each(x, v) { cerr << " " << x << ","; } \ cerr << "}" << endl; \ } while (0) #else #define trc(...) #define trca(...) #define trcc(...) int main() { solve(); } #endif struct IoSetupNya { IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7); } } iosetupnya; inline int popcnt(unsigned long long a) { return __builtin_popcountll(a); } inline int lsb(unsigned long long a) { return __builtin_ctzll(a); } inline int msb(unsigned long long a) { return 63 - __builtin_clzll(a); } template <typename T> inline int getbit(T a, int i) { return (a >> i) & 1; } template <typename T> inline void setbit(T &a, int i) { a |= (1LL << i); } template <typename T> inline void delbit(T &a, int i) { a &= ~(1LL << i); } template <typename T> int lb(const vector<T> &v, const T &a) { return lower_bound(begin(v), end(v), a) - begin(v); } template <typename T> int ub(const vector<T> &v, const T &a) { return upper_bound(begin(v), end(v), a) - begin(v); } template <typename T> vector<T> mkrui(const vector<T> &v) { vector<T> ret(v.size() + 1); for (int i = 0; i < int(v.size()); i++) ret[i + 1] = ret[i] + v[i]; return ret; }; template <typename T> vector<T> mkuni(const vector<T> &v) { vector<T> ret(v); sort(ret.begin(), ret.end()); ret.erase(unique(ret.begin(), ret.end()), ret.end()); return ret; } template <typename F> vector<int> mkord(int N, F f) { vector<int> ord(N); iota(begin(ord), end(ord), 0); sort(begin(ord), end(ord), f); return ord; } #pragma endregion constexpr long long MOD = /** 1000000007; //*/ 998244353; int ans[64][512][512]; using u64 = uint64_t; void solve() { ini(N); vs S(N), T(N); V<u64> U(N), V(N); in(S, T, U, V); rep(i, N) S[i] = S[i] == "1" ? "or" : "and"; rep(i, N) T[i] = T[i] == "1" ? "or" : "and"; trc(S, U); trc(T, V); // S,U T,V auto ok = [&](int id) { rep(i, N) { int c = (S[i] == "or" ? 0 : 1); rep(j, N) { if (S[i] == "or") c |= ans[id][i][j]; else c &= ans[id][i][j]; } if (getbit(U[i], id) != c) return false; } rep(j, N) { int c = (T[j] == "or" ? 0 : 1); rep(i, N) { if (T[j] == "or") c |= ans[id][i][j]; else c &= ans[id][i][j]; } if (getbit(V[j], id) != c) return false; } return true; }; rep(id, 64) { vi unusei, unusej; rep(i, N) { if (S[i] == "and" and getbit(U[i], id) == 1) { rep(j, N) ans[id][i][j] = 1; } else if (S[i] == "or" and getbit(U[i], id) == 0) { rep(j, N) ans[id][i][j] = 0; } else unusei.pb(i); } rep(j, N) { if (T[j] == "and" and getbit(V[j], id) == 1) { rep(i, N) ans[id][i][j] = 1; } else if (T[j] == "or" and getbit(V[j], id) == 0) { rep(i, N) ans[id][i][j] = 0; } else unusej.pb(j); } trc(id, unusei, unusej); #ifdef NyaanDebug rep(i, N) trca(ans[id][i], N); #endif rep(i, sz(unusei)) rep(j, sz(unusej)) { ans[id][unusei[i]][unusej[j]] = (i + j) & 1; } if (ok(id)) continue; rep(i, sz(unusei)) rep(j, sz(unusej)) { ans[id][unusei[i]][unusej[j]] = (i + j + 1) & 1; } if (ok(id)) continue; exit(1); } rep(i, N) { rep(j, N) { if (j) cout << " "; u64 bns = 0; rep(id, 64) { if (ans[id][i][j]) bns |= (1uLL << id); } cout << bns; } cout << "\n"; } }
#pragma region kyopro_template #include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define fi first #define se second #define each(x, v) for (auto &x : v) #define all(v) (v).begin(), (v).end() #define sz(v) ((int)(v).size()) #define mem(a, val) memset(a, val, sizeof(a)) #define ini(...) \ int __VA_ARGS__; \ in(__VA_ARGS__) #define inl(...) \ long long __VA_ARGS__; \ in(__VA_ARGS__) #define ins(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) #define inc(...) \ char __VA_ARGS__; \ in(__VA_ARGS__) #define in2(s, t) \ for (int i = 0; i < (int)s.size(); i++) { \ in(s[i], t[i]); \ } #define in3(s, t, u) \ for (int i = 0; i < (int)s.size(); i++) { \ in(s[i], t[i], u[i]); \ } #define in4(s, t, u, v) \ for (int i = 0; i < (int)s.size(); i++) { \ in(s[i], t[i], u[i], v[i]); \ } #define rep(i, N) for (long long i = 0; i < (long long)(N); i++) #define repr(i, N) for (long long i = (long long)(N)-1; i >= 0; i--) #define rep1(i, N) for (long long i = 1; i <= (long long)(N); i++) #define repr1(i, N) for (long long i = (N); (long long)(i) > 0; i--) using namespace std; void solve(); using ll = long long; template <class T = ll> using V = vector<T>; using vi = vector<int>; using vl = vector<long long>; using vvi = vector<vector<int>>; using vd = V<double>; using vs = V<string>; using vvl = vector<vector<long long>>; using P = pair<long long, long long>; using vp = vector<P>; using pii = pair<int, int>; using vpi = vector<pair<int, int>>; constexpr int inf = 1001001001; constexpr long long infLL = (1LL << 61) - 1; template <typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template <typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; } template <typename T, typename U> ll ceil(T a, U b) { return (a + b - 1) / b; } constexpr ll TEN(int n) { ll ret = 1, x = 10; while (n) { if (n & 1) ret *= x; x *= x; n >>= 1; } return ret; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int s = (int)v.size(); for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i]; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } void in() {} template <typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template <typename T, class... U> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << " "; out(u...); } template <typename T> void die(T x) { out(x); exit(0); } #ifdef NyaanDebug #include "NyaanDebug.h" #define trc(...) \ do { \ cerr << #__VA_ARGS__ << " = "; \ dbg_out(__VA_ARGS__); \ } while (0) #define trca(v, N) \ do { \ cerr << #v << " = "; \ array_out(v, N); \ } while (0) #define trcc(v) \ do { \ cerr << #v << " = {"; \ each(x, v) { cerr << " " << x << ","; } \ cerr << "}" << endl; \ } while (0) #else #define trc(...) #define trca(...) #define trcc(...) int main() { solve(); } #endif struct IoSetupNya { IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7); } } iosetupnya; inline int popcnt(unsigned long long a) { return __builtin_popcountll(a); } inline int lsb(unsigned long long a) { return __builtin_ctzll(a); } inline int msb(unsigned long long a) { return 63 - __builtin_clzll(a); } template <typename T> inline int getbit(T a, int i) { return (a >> i) & 1; } template <typename T> inline void setbit(T &a, int i) { a |= (1LL << i); } template <typename T> inline void delbit(T &a, int i) { a &= ~(1LL << i); } template <typename T> int lb(const vector<T> &v, const T &a) { return lower_bound(begin(v), end(v), a) - begin(v); } template <typename T> int ub(const vector<T> &v, const T &a) { return upper_bound(begin(v), end(v), a) - begin(v); } template <typename T> vector<T> mkrui(const vector<T> &v) { vector<T> ret(v.size() + 1); for (int i = 0; i < int(v.size()); i++) ret[i + 1] = ret[i] + v[i]; return ret; }; template <typename T> vector<T> mkuni(const vector<T> &v) { vector<T> ret(v); sort(ret.begin(), ret.end()); ret.erase(unique(ret.begin(), ret.end()), ret.end()); return ret; } template <typename F> vector<int> mkord(int N, F f) { vector<int> ord(N); iota(begin(ord), end(ord), 0); sort(begin(ord), end(ord), f); return ord; } #pragma endregion constexpr long long MOD = /** 1000000007; //*/ 998244353; int ans[64][512][512]; using u64 = uint64_t; void solve() { ini(N); vs S(N), T(N); V<u64> U(N), V(N); in(S, T, U, V); rep(i, N) S[i] = S[i] == "1" ? "or" : "and"; rep(i, N) T[i] = T[i] == "1" ? "or" : "and"; trc(S, U); trc(T, V); // S,U T,V auto ok = [&](int id) { rep(i, N) { int c = (S[i] == "or" ? 0 : 1); rep(j, N) { if (S[i] == "or") c |= ans[id][i][j]; else c &= ans[id][i][j]; } if (getbit(U[i], id) != c) return false; } rep(j, N) { int c = (T[j] == "or" ? 0 : 1); rep(i, N) { if (T[j] == "or") c |= ans[id][i][j]; else c &= ans[id][i][j]; } if (getbit(V[j], id) != c) return false; } return true; }; rep(id, 64) { vi unusei, unusej; rep(i, N) { if (S[i] == "and" and getbit(U[i], id) == 1) { rep(j, N) ans[id][i][j] = 1; } else if (S[i] == "or" and getbit(U[i], id) == 0) { rep(j, N) ans[id][i][j] = 0; } else unusei.pb(i); } rep(j, N) { if (T[j] == "and" and getbit(V[j], id) == 1) { rep(i, N) ans[id][i][j] = 1; } else if (T[j] == "or" and getbit(V[j], id) == 0) { rep(i, N) ans[id][i][j] = 0; } else unusej.pb(j); } trc(id, unusei, unusej); #ifdef NyaanDebug rep(i, N) trca(ans[id][i], N); #endif rep(i, sz(unusei)) rep(j, sz(unusej)) { ans[id][unusei[i]][unusej[j]] = (i + j) & 1; } if (ok(id)) continue; rep(i, sz(unusei)) rep(j, sz(unusej)) { ans[id][unusei[i]][unusej[j]] = (i + j + 1) & 1; } if (ok(id)) continue; rep(i, sz(unusei)) rep(j, sz(unusej)) { ans[id][unusei[i]][unusej[j]] = 0; } if (ok(id)) continue; rep(i, sz(unusei)) rep(j, sz(unusej)) { ans[id][unusei[i]][unusej[j]] = 1; } if (ok(id)) continue; die("-1"); } rep(i, N) { rep(j, N) { if (j) cout << " "; u64 bns = 0; rep(id, 64) { if (ans[id][i][j]) bns |= (1uLL << id); } cout << bns; } cout << "\n"; } }
replace
258
259
258
265
0
p02705
Python
Runtime Error
n, m = map(int, input().split()) a = list(map(int, input().split())) if n - sum(a) >= 0: print(n - sum(a)) else: print(-1)
import math r = int(input()) print(2 * r * math.pi)
replace
0
6
0
4
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/p02705/Python/s499723334.py", line 1, in <module> n, m = map(int, input().split()) ValueError: not enough values to unpack (expected 2, got 1)
p02705
Python
Runtime Error
import math print(int(input()) * 2 * math.pi())
import math print(int(input()) * 2 * math.pi)
replace
2
3
2
3
TypeError: 'float' object is not callable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02705/Python/s976752979.py", line 3, in <module> print(int(input()) * 2 * math.pi()) TypeError: 'float' object is not callable
p02705
Python
Runtime Error
# coding: utf-8 def main(): R = input(int()) return R * 2 * 3.1415 print(main())
# coding: utf-8 def main(): R = int(input()) return R * 2 * 3.1415 print(main())
replace
4
5
4
6
TypeError: can't multiply sequence by non-int of type 'float'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02705/Python/s656493829.py", line 9, in <module> print(main()) File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02705/Python/s656493829.py", line 6, in main return R * 2 * 3.1415 TypeError: can't multiply sequence by non-int of type 'float'
p02705
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <vector> using namespace std; #define int long long #define double long double #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 1000000007 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define e_ 2.718281828459045235360287471352 #define P pair<int, int> // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool p(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[41]; int nis[41]; int nia[41]; int mody[41]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int gyakugen(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } mody[0] = y; rep(1, i, 41) { y = (y * y) % mod; mody[i] = y; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { n = (n * mody[i]) % mod; } } return n; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } bool integer(double n) { if (n == long(n)) return true; else return false; } int poow(int y, int n) { n -= 1; int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int yy = y; mody[0] = yy; rep(1, i, 41) { yy = (yy * yy) % mod; mody[i] = yy; } rep(0, i, 41) nis[i] = 0; nn = n; for (int i = 40; i >= 0; i -= 1) { if (nn >= n2[i]) { nis[i]++; nn -= n2[i]; } } rep(0, i, 41) { if (nis[i] == 1) { y = (y * mody[i]) % mod; } } return y; } int minpow(int x, int y) { int sum = 1; rep(0, i, y) sum *= x; return sum; } int ketawa(int x, int sinsuu) { int sum = 0; rep(0, i, 100) sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i)); return sum; } int sankaku(int a) { return a * (a + 1) / 2; } bool search(int x) { int n; int a[n]; int l = 0, r = n; while (r - l >= 1) { int i = (l + r) / 2; if (a[i] == x) return true; else if (a[i] < x) l = i + 1; else r = i; } return false; } using Graph = vector<vector<int>>; /*int oya[114514]; int depth[114514]; void dfs(const Graph &G, int v, int p, int d) { depth[v] = d; oya[v]=p; for (auto nv : G[v]) { if (nv == p) continue; // nv が親 p だったらダメ dfs(G, nv, v, d+1); // d を 1 増やして子ノードへ } }*/ /*int H=10,W=10; char field[10][10]; char memo[10][10]; void dfs(int h, int w) { memo[h][w] = 'x'; // 八方向を探索 for (int dh = -1; dh <= 1; ++dh) { for (int dw = -1; dw <= 1; ++dw) { if(abs(0-dh)+abs(0-dw)==2)continue; int nh = h + dh, nw = w + dw; // 場外アウトしたり、0 だったりはスルー if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (memo[nh][nw] == 'x') continue; // 再帰的に探索 dfs(nh, nw); } } }*/ int XOR(int a, int b) { int ni = 1; rep(0, i, 41) { n2[i] = ni; ni *= 2; } rep(0, i, 41) nis[i] = 0; for (int i = 40; i >= 0; i -= 1) { if (a >= n2[i]) { nis[i]++; a -= n2[i]; } if (b >= n2[i]) { nis[i]++; b -= n2[i]; } } int sum = 0; rep(0, i, 41) sum += (nis[i] % 2 * n2[i]); return sum; } // int ma[1024577][21]; // for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1; int a[514514]; signed main() { ic(m) ic(n) rep(0, i, n) { cin >> a[i]; m -= a[i]; } if (m < 0) c(-1) else c(m) }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <vector> using namespace std; #define int long long #define double long double #define rep(s, i, n) for (int i = s; i < n; i++) #define c(n) cout << n << endl; #define ic(n) \ int n; \ cin >> n; #define sc(s) \ string s; \ cin >> s; #define mod 1000000007 #define inf 1000000000000000007 #define f first #define s second #define mini(c, a, b) *min_element(c + a, c + b) #define maxi(c, a, b) *max_element(c + a, c + b) #define e_ 2.718281828459045235360287471352 #define P pair<int, int> // printf("%.12Lf\n",); int keta(int x) { rep(0, i, 30) { if (x < 10) { return i + 1; } x = x / 10; } } int gcd(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return bb; } bb = bb % aa; if (bb == 0) { return aa; } } } int lcm(int x, int y) { int aa = x, bb = y; rep(0, i, 1000) { aa = aa % bb; if (aa == 0) { return x / bb * y; } bb = bb % aa; if (bb == 0) { return x / aa * y; } } } bool p(int x) { if (x == 1) return false; rep(2, i, sqrt(x) + 1) { if (x % i == 0 && x != i) { return false; } } return true; } int max(int a, int b) { if (a >= b) return a; else return b; } int min(int a, int b) { if (a >= b) return b; else return a; } int n2[41]; int nis[41]; int nia[41]; int mody[41]; int nn; int com(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int bunsi = 1, bunbo = 1; rep(0, i, y) bunsi = (bunsi * (n - i)) % mod; rep(0, i, y) bunbo = (bunbo * (i + 1)) % mod; mody[0] = bunbo; rep(1, i, 41) { bunbo = (bunbo * bunbo) % mod; mody[i] = bunbo; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { bunsi = (bunsi * mody[i]) % mod; } } return bunsi; } int gyakugen(int n, int y) { int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } mody[0] = y; rep(1, i, 41) { y = (y * y) % mod; mody[i] = y; } rep(0, i, 41) nis[i] = 0; nn = mod - 2; for (int i = 40; i >= 0; i -= 1) { if (nn > n2[i]) { nis[i]++; nn -= n2[i]; } } nis[0]++; rep(0, i, 41) { if (nis[i] == 1) { n = (n * mody[i]) % mod; } } return n; } int yakuwa(int n) { int sum = 0; rep(1, i, sqrt(n + 1)) { if (n % i == 0) sum += i + n / i; if (i * i == n) sum -= i; } return sum; } bool integer(double n) { if (n == long(n)) return true; else return false; } int poow(int y, int n) { n -= 1; int ni = 1; for (int i = 0; i < 41; i++) { n2[i] = ni; ni *= 2; } int yy = y; mody[0] = yy; rep(1, i, 41) { yy = (yy * yy) % mod; mody[i] = yy; } rep(0, i, 41) nis[i] = 0; nn = n; for (int i = 40; i >= 0; i -= 1) { if (nn >= n2[i]) { nis[i]++; nn -= n2[i]; } } rep(0, i, 41) { if (nis[i] == 1) { y = (y * mody[i]) % mod; } } return y; } int minpow(int x, int y) { int sum = 1; rep(0, i, y) sum *= x; return sum; } int ketawa(int x, int sinsuu) { int sum = 0; rep(0, i, 100) sum += (x % poow(sinsuu, i + 1)) / (poow(sinsuu, i)); return sum; } int sankaku(int a) { return a * (a + 1) / 2; } bool search(int x) { int n; int a[n]; int l = 0, r = n; while (r - l >= 1) { int i = (l + r) / 2; if (a[i] == x) return true; else if (a[i] < x) l = i + 1; else r = i; } return false; } using Graph = vector<vector<int>>; /*int oya[114514]; int depth[114514]; void dfs(const Graph &G, int v, int p, int d) { depth[v] = d; oya[v]=p; for (auto nv : G[v]) { if (nv == p) continue; // nv が親 p だったらダメ dfs(G, nv, v, d+1); // d を 1 増やして子ノードへ } }*/ /*int H=10,W=10; char field[10][10]; char memo[10][10]; void dfs(int h, int w) { memo[h][w] = 'x'; // 八方向を探索 for (int dh = -1; dh <= 1; ++dh) { for (int dw = -1; dw <= 1; ++dw) { if(abs(0-dh)+abs(0-dw)==2)continue; int nh = h + dh, nw = w + dw; // 場外アウトしたり、0 だったりはスルー if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue; if (memo[nh][nw] == 'x') continue; // 再帰的に探索 dfs(nh, nw); } } }*/ int XOR(int a, int b) { int ni = 1; rep(0, i, 41) { n2[i] = ni; ni *= 2; } rep(0, i, 41) nis[i] = 0; for (int i = 40; i >= 0; i -= 1) { if (a >= n2[i]) { nis[i]++; a -= n2[i]; } if (b >= n2[i]) { nis[i]++; b -= n2[i]; } } int sum = 0; rep(0, i, 41) sum += (nis[i] % 2 * n2[i]); return sum; } // int ma[1024577][21]; // for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1; int a[514514]; signed main() { double n; cin >> n; c(n * 2 * 3.14159) }
replace
273
280
273
277
-11
p02705
C++
Runtime Error
#include <cstdio> #include <math.h> #define PI acos(-1) using namespace std; int main() { int n; scanf("%lld", &n); printf("%lf", 2 * n * PI); }
#include <cstdio> #include <math.h> #define PI acos(-1) using namespace std; int main() { int n; scanf("%d", &n); printf("%lf", 2 * n * PI); }
replace
8
9
8
9
-6
*** stack smashing detected ***: terminated
p02705
Python
Runtime Error
import math r = input() print(2 * math.pi * r) quit()
import math r = int(input()) print(2 * math.pi * r) quit()
replace
2
3
2
3
TypeError: can't multiply sequence by non-int of type 'float'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02705/Python/s962052579.py", line 3, in <module> print(2 * math.pi * r) TypeError: can't multiply sequence by non-int of type 'float'
p02705
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<string> vst; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0) #define all(ct) ct.begin(), ct.end() #define endl "\n" #define fr(i, a) for (auto i : a) #define f(i, a, b) for (int i = a; i < b; ++i) #define fd(i, a, b) for (int i = a; i >= b; --i) #define pb push_back #define in(d, v) d.find(v) != d.end() #define mp make_pair #define size(a) int(a.size()) const int mod = 1e9 + 7; const ll inf = ll(1e18); const double PI = acos(-1); ll modexp(ll x, ll n, int md) { if (n == 0) return 1; if (n % 2 == 0) return modexp((x * x) % md, n / 2, md); return (x * modexp((x * x) % md, n / 2, md)) % md; } int main() { fastio; // clock_t tm = clock(); ll n, m, s = 0; cin >> n >> m; vl a(m); f(i, 0, m) { cin >> a[i]; s += a[i]; } if (s > n) cout << -1 << endl; else cout << n - s << endl; // cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<string> vst; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0) #define all(ct) ct.begin(), ct.end() #define endl "\n" #define fr(i, a) for (auto i : a) #define f(i, a, b) for (int i = a; i < b; ++i) #define fd(i, a, b) for (int i = a; i >= b; --i) #define pb push_back #define in(d, v) d.find(v) != d.end() #define mp make_pair #define size(a) int(a.size()) const int mod = 1e9 + 7; const ll inf = ll(1e18); const double PI = acos(-1); ll modexp(ll x, ll n, int md) { if (n == 0) return 1; if (n % 2 == 0) return modexp((x * x) % md, n / 2, md); return (x * modexp((x * x) % md, n / 2, md)) % md; } int main() { fastio; // clock_t tm = clock(); double r; cin >> r; double ans = 2 * PI * r; cout << setprecision(8) << ans << endl; // cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl; }
replace
42
53
42
46
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02705
C++
Runtime Error
/* TAHMID RAHMAN DAMIAN FOREVER MATH LOVER NEVER GIVE UP */ #include <bits/stdc++.h> using namespace std; #define pi acos(-1.0) #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define ll long long #define pb push_back #define fi first #define se second #define in insert #define mp make_pair #define gcd(a, b) __gcd(a, b); int main() { fastio; ll n, m, i, s = 0; cin >> n >> m; vector<ll> v(m); for (i = 0; i < m; i++) { cin >> v[i]; } for (i = 0; i < m; i++) { s = s + v[i]; } if (s > n) cout << "-1" << endl; else { cout << n - s << endl; } }
/* TAHMID RAHMAN DAMIAN FOREVER MATH LOVER NEVER GIVE UP */ #include <bits/stdc++.h> using namespace std; #define pi acos(-1.0) #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define ll long long #define pb push_back #define fi first #define se second #define in insert #define mp make_pair #define gcd(a, b) __gcd(a, b); int main() { fastio; double ans, r, p = 3.1416; cin >> r; ans = p * r * 2; cout << ans << endl; }
replace
21
35
21
25
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02705
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, b) for (i = 0; i < b; ++i) #define repp(i, a, b) for (i = a; i < b; ++i) #define endl "\n" // #define LLONG_MAX 99999999999999 typedef long long int lli; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lli t, n, i, j, b, a, q, m; cin >> n >> m; vector<lli> v(m); rep(i, m) cin >> v[i]; lli ans = 0; rep(i, m) { ans += v[i]; } if (ans > n) { cout << -1 << endl; } else { cout << n - ans << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, b) for (i = 0; i < b; ++i) #define repp(i, a, b) for (i = a; i < b; ++i) #define endl "\n" // #define LLONG_MAX 99999999999999 typedef long long int lli; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); lli t, n, i, j, b, a, q, m; double r; cin >> r; cout << 2.0 * 3.141 * r << endl; }
replace
11
21
11
14
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02705
C++
Runtime Error
// https://codeforces.com/contest/1287/problem/A // Author: BrownieTK // #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; //========================Debug====================================== void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifdef local #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif //========================TypeDefs=================================== typedef long long int lli; typedef unsigned long long int ulli; typedef long double ldb; typedef pair<lli, lli> pll; typedef pair<int, int> pii; typedef pair<int, lli> pil; //=========================MACROS==================================== #define pb push_back #define popb pop_back() #define pf push_front #define popf pop_front() #define si size() #define be begin() #define en end() #define all(v) v.be, v.en #define mp make_pair #define mt make_tuple #define acc(v) accumulate(all(v), 0) #define F first #define S second #define forz(i, n) for (int i = 0; i < n; i++) #define fore(i, m, n) for (int i = m; i <= n; i++) #define rforz(i, n) for (int i = n - 1; i >= 0; i--) #define rfore(i, m, n) for (int i = n; i >= m; i--) #define deci(n) fixed << setprecision(n) #define high(n) __builtin_popcount(n) #define highll(n) __builtin_popcountll(n) #define parity(n) __builtin_parity(n) #define clz(n) __builtin_clz(n) #define clzll(n) __builtin_clzll(n) #define ctz(n) __builtin_ctz(n) #define bset(a, p) ((a) | (1ll << (p))) #define bchk(a, p) ((a) & (1ll << (p))) #define bxor(a, p) ((a) ^ (1ll << (p))); #define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a)) #define lb lower_bound #define ub upper_bound #define er equal_range #define findnot find_first_not_of #define maxe *max_element #define mine *min_element #define mod 1000000007 #define mod2 998244353 #define gcd __gcd #define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define endl "\n" #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl #define oset \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define osetlli \ tree<lli, null_type, less<lli>, rb_tree_tag, \ tree_order_statistics_node_update> #define ofk order_of_key #define fbo find_by_order // member functions : // 1. order_of_key(k) : number of elements sbtriectly lesser than k // 2. find_by_order(k) : k-th element in the set //==============================FUNCTIONS=========================================== auto clk = clock(); mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); void run_time() { #ifdef local cout << endl; cout << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl; #endif return; } inline lli power(lli x, lli y, lli p = mod) { lli res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } inline lli modadd(lli a, lli b, lli m = mod) { a += b; if (a >= m) a -= m; return a; } inline lli modmul(lli a, lli b, lli m = mod) { return ((a % m) * (b % m)) % m; } inline lli modi(lli a, lli m = mod) { return power(a, m - 2, m); } //================================CODE============================================= int main() { kira; lli m, n; cin >> m >> n; vector<lli> a(n); forz(i, n) { cin >> a[i]; } lli sum = acc(a); if (sum > m) p1(-1); else cout << m - sum; return 0; }
// https://codeforces.com/contest/1287/problem/A // Author: BrownieTK // #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; //========================Debug====================================== void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifdef local #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif //========================TypeDefs=================================== typedef long long int lli; typedef unsigned long long int ulli; typedef long double ldb; typedef pair<lli, lli> pll; typedef pair<int, int> pii; typedef pair<int, lli> pil; //=========================MACROS==================================== #define pb push_back #define popb pop_back() #define pf push_front #define popf pop_front() #define si size() #define be begin() #define en end() #define all(v) v.be, v.en #define mp make_pair #define mt make_tuple #define acc(v) accumulate(all(v), 0) #define F first #define S second #define forz(i, n) for (int i = 0; i < n; i++) #define fore(i, m, n) for (int i = m; i <= n; i++) #define rforz(i, n) for (int i = n - 1; i >= 0; i--) #define rfore(i, m, n) for (int i = n; i >= m; i--) #define deci(n) fixed << setprecision(n) #define high(n) __builtin_popcount(n) #define highll(n) __builtin_popcountll(n) #define parity(n) __builtin_parity(n) #define clz(n) __builtin_clz(n) #define clzll(n) __builtin_clzll(n) #define ctz(n) __builtin_ctz(n) #define bset(a, p) ((a) | (1ll << (p))) #define bchk(a, p) ((a) & (1ll << (p))) #define bxor(a, p) ((a) ^ (1ll << (p))); #define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a)) #define lb lower_bound #define ub upper_bound #define er equal_range #define findnot find_first_not_of #define maxe *max_element #define mine *min_element #define mod 1000000007 #define mod2 998244353 #define gcd __gcd #define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define endl "\n" #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl #define oset \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define osetlli \ tree<lli, null_type, less<lli>, rb_tree_tag, \ tree_order_statistics_node_update> #define ofk order_of_key #define fbo find_by_order // member functions : // 1. order_of_key(k) : number of elements sbtriectly lesser than k // 2. find_by_order(k) : k-th element in the set //==============================FUNCTIONS=========================================== auto clk = clock(); mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); void run_time() { #ifdef local cout << endl; cout << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl; #endif return; } inline lli power(lli x, lli y, lli p = mod) { lli res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } inline lli modadd(lli a, lli b, lli m = mod) { a += b; if (a >= m) a -= m; return a; } inline lli modmul(lli a, lli b, lli m = mod) { return ((a % m) * (b % m)) % m; } inline lli modi(lli a, lli m = mod) { return power(a, m - 2, m); } //================================CODE============================================= int main() { kira; ldb pi = 3.141592653589793238462643383279502884; ldb r; cin >> r; cout << deci(3) << 2 * pi * r; run_time(); return 0; }
replace
175
184
175
180
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02705
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long #define endl '\n' #define pb push_back #define fi first #define se second #define all(c) (c).begin(), (c).end() typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define TRACE #ifndef ONLINE_JUDGE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif const ll inf = 2e18; const int mod = 1e9 + 7; const int N = 2e5 + 10; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, m; cin >> n >> m; int a[m], sum = 0; for (int i = 0; i < m; i++) { cin >> a[i]; sum += a[i]; } if (sum > n) { cout << -1; } else { cout << (n - sum); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long #define endl '\n' #define pb push_back #define fi first #define se second #define all(c) (c).begin(), (c).end() typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define TRACE #ifndef ONLINE_JUDGE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) #endif const ll inf = 2e18; const int mod = 1e9 + 7; const int N = 2e5 + 10; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); ld r; cin >> r; cout << fixed << setprecision(10) << 2.0 * acos(-1) * r; return 0; }
replace
43
55
43
46
-11
p02705
C++
Runtime Error
///******* In the name of Allah *******/// #include <bits/stdc++.h> using namespace std; void Ok() { int a; double aa, bb; scanf("%ld", &a); aa = a; bb = 2 * 3.1416 * aa; printf("%0.2lf", bb); } int main() { Ok(); return 0; }
///******* In the name of Allah *******/// #include <bits/stdc++.h> using namespace std; void Ok() { int a; double aa, bb; scanf("%d", &a); aa = a; bb = 2 * 3.1416 * aa; printf("%0.2lf", bb); } int main() { Ok(); return 0; }
replace
8
9
8
9
0
p02705
C++
Time Limit Exceeded
// ===================================================================================== // // Filename: at.cpp // // Description: // // Version: 1.0 // Created: 19/04/20 05:21:38 PM IST // Revision: none // Compiler: g++ // // Author: Kiran Bhanushali (), kiranbhanushali143.kb143@gmail.com // Organization: // // ===================================================================================== #include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back // #define _SHOW_TIME void solve() { // your code here; int n, m; cin >> n >> m; int sum = 0; for (int i = 0; i < m; i++) { int x; cin >> x; sum += x; } if (sum <= n) cout << n - sum << endl; else cout << "-1" << endl; } int32_t main() { ///////////////////////////////////// #ifdef _SHOW_TIME int tt = (int)clock(); #endif ///////////////////////////////////// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ///////////////////////////////////// solve(); ///////////////////////////////////// #ifdef _SHOW_TIME cerr << "TIME = " << (double)(clock() - tt) / CLOCKS_PER_SEC << endl; #endif ///////////////////////////////////// return 0; }
// ===================================================================================== // // Filename: at.cpp // // Description: // // Version: 1.0 // Created: 19/04/20 05:21:38 PM IST // Revision: none // Compiler: g++ // // Author: Kiran Bhanushali (), kiranbhanushali143.kb143@gmail.com // Organization: // // ===================================================================================== #include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back // #define _SHOW_TIME void solve() { // your code here; int n, m; cin >> n; double d = 22 / 7.0; d *= 2; d *= n; cout << d << endl; } int32_t main() { ///////////////////////////////////// #ifdef _SHOW_TIME int tt = (int)clock(); #endif ///////////////////////////////////// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ///////////////////////////////////// solve(); ///////////////////////////////////// #ifdef _SHOW_TIME cerr << "TIME = " << (double)(clock() - tt) / CLOCKS_PER_SEC << endl; #endif ///////////////////////////////////// return 0; }
replace
27
39
27
32
TLE
p02705
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ull unsigned long long #define d1(x) cout << #x << " " << x << endl; #define d2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl; #define d2i(x, y, i) \ cout << #x << i << " " << x << " " << #y << i << " " << y << endl; #define fr(i, l, r) for (ll i = l; i < r; i++) #define mems(a, x) memset(a, x, sizeof(a)) #define mod 1000000007 #define ff first #define ss second #define pb(x) push_back(x) #define vll vector<ll> #define pbp(x, y) push_back(make_pair(x, y)) #define mat vector<vector<ll>> #define pi 3.14159265358979323846 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void solve() { ll n, m; cin >> n >> m; ll sm = 0, x; fr(i, 0, m) cin >> x, sm += x; n -= sm; if (n < 0) cout << -1; else cout << n; } int main() { ll t = 1; // cin>>t; while (t--) { solve(); cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ull unsigned long long #define d1(x) cout << #x << " " << x << endl; #define d2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl; #define d2i(x, y, i) \ cout << #x << i << " " << x << " " << #y << i << " " << y << endl; #define fr(i, l, r) for (ll i = l; i < r; i++) #define mems(a, x) memset(a, x, sizeof(a)) #define mod 1000000007 #define ff first #define ss second #define pb(x) push_back(x) #define vll vector<ll> #define pbp(x, y) push_back(make_pair(x, y)) #define mat vector<vector<ll>> #define pi 3.14159265358979323846 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void solve() { double r; cin >> r; cout << fixed; cout << setprecision(10) << (double)2 * pi * r << endl; } int main() { ll t = 1; // cin>>t; while (t--) { solve(); cout << endl; } return 0; }
replace
26
35
26
30
TLE
p02705
C++
Runtime Error
// #pragma GCC optimize("O3") // #pragma GCC target("avx2") // 293206GT #include <algorithm> #include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> typedef long long ll; #define int ll using namespace std; #define put(a) cout << (a) << '\n' #define sqr(x) (x) * (x) typedef pair<ll, ll> pii; typedef long double ld; typedef pair<ld, ld> pld; #define rep(x, y, a) for (int x = (y); x < (int)(a); ++x) #define all(a) a.begin(), a.end() #define chkmax(a, b) a = max(a, (b)) #define chkmin(a, b) a = min(a, (b)) #define prev asasdasd #define next aasdasda #define left asdasdasdasd #define right asnabsdkasdl #define rank asdasdknlasd #define move asdasdas typedef vector<int> vi; typedef vector<pii> vpii; namespace IO { template <class A, class B> ostream &operator<<(ostream &out, pair<A, B> &a) { out << a.first << " " << a.second; return out; } template <class A, class B> ostream &operator<<(ostream &out, vector<pair<A, B>> &a) { for (pair<A, B> x : a) out << x.first << " " << x.second << '\n'; } template <class A> ostream &operator<<(ostream &out, vector<A> &a) { for (A x : a) out << x << ' '; return out; } template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) { in >> a.first >> a.second; return in; } template <class A> istream &operator>>(istream &in, vector<A> &a) { for (A &x : a) in >> x; return in; } } // namespace IO using namespace IO; int solve() { ld r; cin >> r; put(3.141592 * r * 2); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); int t = 1; // cin >> t; while (t--) solve(); }
// #pragma GCC optimize("O3") // #pragma GCC target("avx2") // 293206GT #include <algorithm> #include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> typedef long long ll; #define int ll using namespace std; #define put(a) cout << (a) << '\n' #define sqr(x) (x) * (x) typedef pair<ll, ll> pii; typedef long double ld; typedef pair<ld, ld> pld; #define rep(x, y, a) for (int x = (y); x < (int)(a); ++x) #define all(a) a.begin(), a.end() #define chkmax(a, b) a = max(a, (b)) #define chkmin(a, b) a = min(a, (b)) #define prev asasdasd #define next aasdasda #define left asdasdasdasd #define right asnabsdkasdl #define rank asdasdknlasd #define move asdasdas typedef vector<int> vi; typedef vector<pii> vpii; namespace IO { template <class A, class B> ostream &operator<<(ostream &out, pair<A, B> &a) { out << a.first << " " << a.second; return out; } template <class A, class B> ostream &operator<<(ostream &out, vector<pair<A, B>> &a) { for (pair<A, B> x : a) out << x.first << " " << x.second << '\n'; } template <class A> ostream &operator<<(ostream &out, vector<A> &a) { for (A x : a) out << x << ' '; return out; } template <class A, class B> istream &operator>>(istream &in, pair<A, B> &a) { in >> a.first >> a.second; return in; } template <class A> istream &operator>>(istream &in, vector<A> &a) { for (A &x : a) in >> x; return in; } } // namespace IO using namespace IO; void solve() { ld r; cin >> r; put(3.141592 * r * 2); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); int t = 1; // cin >> t; while (t--) solve(); }
replace
72
73
72
73
0
p02705
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ld long double #define ll long long #define rem 1000000007 typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<ll, ll> pii; #define v(x) vector<x> #define pb(x) push_back(x) #define ppb() pop_back() #define mp(x, y) make_pair(x, y) #define mii map<ll, ll> #define umii unordered_map<ll, ll> #define mxheap priority_queue<ll> // Max Heap #define mnheap priority_queue<ll, vi, greater<ll>> // Min Heap #define da(type, arr, size) \ type *arr = new type[n] // Dynamically allocated array #define f(i, n) for (ll i = 0; i < (n); i++) #define fa(i, a, b) for (ll i = (a); i < (b); i++) #define far(i, a, b) for (ll i = (a); i > (b); i--) #define T \ ll t; \ cin >> t; \ while (t--) #define ff first #define ss second #define mem(a, b) memset(a, b, sizeof(a)) #define sz size() #define setbits(x) __builtin_popcountll(x) // Total set bits in a number #define zerobits(x) \ __builtin_ctzll(x) // This will tell me number of zeroes till first set bit #define all(c) (c).begin(), (c).end() #define setp(x, y) fixed << setprecision(y) << x #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define INF 2e18 ll mod(ll n) { return n > 0 ? n : -1 * n; } ld dist(ll x1, ll y1, ll x2, ll y2) { ld ans = round(pow(mod(x2 - x1), 2)) + round(pow(mod(y2 - y1), 2)); ans = sqrt(ans); return ans; } ld dist(pii a, pii b) { ld ans = round(pow(mod(b.ff - a.ff), 2)) + round(pow(mod(b.ss - a.ss), 2)); ans = sqrt(ans); return ans; } umii isPrime; void SieveOfEratosthenes(ll n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (ll i = p * p; i <= n; i += p) prime[i] = false; } } for (ll p = 2; p <= n; p++) if (prime[p]) isPrime[p] = 1; } int *dp; ll maxCompositeSummands(ll n) { if (n == 2 || n == 1 || n == 3) { return INT_MIN; } if (dp[n] != -1) { return dp[n]; } ll mexx = INT_MIN; for (ll i = 4; i <= n; i++) { if (!isPrime[i]) { mexx = max(mexx, maxCompositeSummands(n - i)); } } return dp[n] = mexx == INT_MIN ? mexx : mexx + 1; } int main() { fast ll n, m; cin >> n >> m; ll sum = 0; for (ll i = 0; i < m; i++) { ll temp; cin >> temp; sum += temp; } ll ans = n - sum; ans < 0 ? cout << -1 << endl : cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ld long double #define ll long long #define rem 1000000007 typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<ll, ll> pii; #define v(x) vector<x> #define pb(x) push_back(x) #define ppb() pop_back() #define mp(x, y) make_pair(x, y) #define mii map<ll, ll> #define umii unordered_map<ll, ll> #define mxheap priority_queue<ll> // Max Heap #define mnheap priority_queue<ll, vi, greater<ll>> // Min Heap #define da(type, arr, size) \ type *arr = new type[n] // Dynamically allocated array #define f(i, n) for (ll i = 0; i < (n); i++) #define fa(i, a, b) for (ll i = (a); i < (b); i++) #define far(i, a, b) for (ll i = (a); i > (b); i--) #define T \ ll t; \ cin >> t; \ while (t--) #define ff first #define ss second #define mem(a, b) memset(a, b, sizeof(a)) #define sz size() #define setbits(x) __builtin_popcountll(x) // Total set bits in a number #define zerobits(x) \ __builtin_ctzll(x) // This will tell me number of zeroes till first set bit #define all(c) (c).begin(), (c).end() #define setp(x, y) fixed << setprecision(y) << x #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define INF 2e18 ll mod(ll n) { return n > 0 ? n : -1 * n; } ld dist(ll x1, ll y1, ll x2, ll y2) { ld ans = round(pow(mod(x2 - x1), 2)) + round(pow(mod(y2 - y1), 2)); ans = sqrt(ans); return ans; } ld dist(pii a, pii b) { ld ans = round(pow(mod(b.ff - a.ff), 2)) + round(pow(mod(b.ss - a.ss), 2)); ans = sqrt(ans); return ans; } umii isPrime; void SieveOfEratosthenes(ll n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (ll i = p * p; i <= n; i += p) prime[i] = false; } } for (ll p = 2; p <= n; p++) if (prime[p]) isPrime[p] = 1; } int *dp; ll maxCompositeSummands(ll n) { if (n == 2 || n == 1 || n == 3) { return INT_MIN; } if (dp[n] != -1) { return dp[n]; } ll mexx = INT_MIN; for (ll i = 4; i <= n; i++) { if (!isPrime[i]) { mexx = max(mexx, maxCompositeSummands(n - i)); } } return dp[n] = mexx == INT_MIN ? mexx : mexx + 1; } int main() { fast ll r; cin >> r; long double pi = 3.141592653; long double ans = 2 * pi * r; cout << ans << endl; }
replace
88
98
88
93
TLE
p02705
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int maxn = 110000; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << setiosflags(ios::fixed) << setprecision(12); ll n, m; cin >> n >> m; vector<int> a(n + 1); ll sum = 0; for (int i = 1; i <= m; i++) { ll t; cin >> t; sum += t; } if (n >= sum) cout << n - sum << "\n"; else cout << -1 << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int maxn = 110000; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << setiosflags(ios::fixed) << setprecision(12); double pi = acos(-1); int n; cin >> n; double ans = 2 * pi * n; cout << ans << "\n"; return 0; }
replace
10
23
10
15
TLE
p02706
C++
Runtime Error
#include <iostream> #include <stdlib.h> #include <string> using namespace std; int main() { int n, m, A[1000], ans; cin >> n >> m; ans = n; for (int i = 0; i < m; i++) { cin >> A[i]; ans = ans - A[i]; } if (ans < 0) ans = -1; cout << ans; return 0; }
#include <iostream> #include <stdlib.h> #include <string> using namespace std; int main() { int n, m, A[10000], ans; cin >> n >> m; ans = n; for (int i = 0; i < m; i++) { cin >> A[i]; ans = ans - A[i]; } if (ans < 0) ans = -1; cout << ans; return 0; }
replace
6
8
6
7
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int ara[1000]; for (int i = 1; i <= m; i++) { cin >> ara[i]; } int sum = 0; for (int i = 1; i <= m; i++) { sum = sum + ara[i]; } if (n >= sum) cout << n - sum << endl; else cout << "-1" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int ara[10000]; for (int i = 1; i <= m; i++) { cin >> ara[i]; } int sum = 0; for (int i = 1; i <= m; i++) { sum = sum + ara[i]; } if (n >= sum) cout << n - sum << endl; else cout << "-1" << endl; return 0; }
replace
7
8
7
8
0
p02706
C++
Runtime Error
#include <iostream> using namespace std; int main() { int day, hw, req[1000] = {}; cin >> day >> hw; for (int i = 0; i < hw; ++i) { cin >> req[i]; day -= req[i]; } if (day >= 0) { cout << day; } else { cout << "-1"; } cout << endl; return 0; }
#include <iostream> using namespace std; int main() { int day, hw, req[10000] = {}; cin >> day >> hw; for (int i = 0; i < hw; ++i) { cin >> req[i]; day -= req[i]; } if (day >= 0) { cout << day; } else { cout << "-1"; } cout << endl; return 0; }
replace
4
5
4
5
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int n, m; cin >> n >> m; vector<int> a(1000100, 0); for (int i = 1; i <= n; i++) { cin >> a[i]; } int s = accumulate(a.begin() + 1, a.end() + n + 1, 0); if (n - s >= 0) cout << n - s << "\n"; else cout << -1 << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int n, m; cin >> n >> m; vector<int> a(1000100, 0); for (int i = 1; i <= n; i++) { cin >> a[i]; } long long s = accumulate(a.begin() + 1, a.begin() + n + 1, 0); if (n - s >= 0) cout << n - s << "\n"; else cout << -1 << "\n"; }
replace
13
14
13
14
0
p02706
C++
Runtime Error
#include <iostream> using namespace std; int main(void) { int N, M; int A[1000]; cin >> N >> M; int sum = 0; for (int i = 0; i < M; i++) { cin >> A[i]; sum += A[i]; } if (N >= sum) { cout << N - sum << endl; } else { cout << "-1" << endl; } return 0; }
#include <iostream> using namespace std; int main(void) { int N, M; int A[10000]; cin >> N >> M; int sum = 0; for (int i = 0; i < M; i++) { cin >> A[i]; sum += A[i]; } if (N >= sum) { cout << N - sum << endl; } else { cout << "-1" << endl; } return 0; }
replace
5
6
5
6
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> #include <sstream> #define ll long long int #include <stdlib.h> #include <vector> #define pi acos(-1) #define maxm 100005 #define pb push_back #define MOD 1e9 + 7 #define highest(x) numeric_limits<x>::max() #define lowest(x) numeric_limits<x>::min() /// s1.substr(1,3);///STARTING FROM INDEX 1, 3 LNEGTH SUBSTRING. /// s1.find("adn")///RETURNS STARTING INDEX OF THE SUBSTRING ///"adn" IF IT EXISTS IN THE STRING S1./// /// s1.find("adn",int pos);///RETURNS STARTING INDEX OF THE /// SUBSTRING "adn" SEARCHING FROM INDEX POS OF STRING s1./// /// string::npos returns a garbage value if not found... /// reverse(s1.begin(),s1.end())-> to reverse a string. /// next_permutation(f,f+n)->f array er next permutation return korbe.. /// str.erase(1,2)->deletes 2 char from index 1.. /// for(auto i:p2)->i=p2.begin() theke p2.end() er ag porjonto.. /// max_element(v,v+4);->return a pointer to the max element /// in a array/vector.. v from 1st element to 4th element. /// same for min_element(v,v+4); ///__builtin_popcount(a);->counts how many number of one's /// in a in binary representation. /// accumulate(l1+1,l1+10+1,0LL)=>it perform the sum from l1[1] to /// l1[10] and 0 is the initial sum. /// cout<<fixed<<setprecision(12)<<x14<<endl;//=>x14 er /// doshomik er por 12 ta 0 thakbe. #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define gcd(a, b) __gcd(a, b) using namespace std; ll l1[200005], vis[200005], l3[200005], s = 0, m = 0, mn = 0; ll dx[] = {1, 0, -1, 0}; ll dy[] = {0, -1, 0, 1}; // vector<ll>v[5]; // set<ll>v2; // map<ll,ll>m2; // vector<pair<ll,ll>>p2; // vector<pair<ll,ll>>p3; char s2[maxm]; // int sum[max]; int tree[maxm * 4]; // int prop[max*3]; void STB(int at, int L, int R) { // int sum[at]=0; if (L == R) { tree[at] = (s2[L - 1] - '0'); return; } int mid = (L + R) / 2; STB(2 * at, L, mid); STB(2 * at + 1, mid + 1, R); // tree[at]=tree[2*at]+tree[2*at+1]; // return sum[at]; } void update(int at, int L, int R, int pos1, int pos2) { if (L > pos2 || R < pos1) return; if (L >= pos1 && R <= pos2) { tree[at] ^= 1; return; } int mid = (L + R) >> 1; // if(pos2<=mid)update((at<<1)+1,L,mid,pos1,pos2); // else if(pos1>mid)update((at<<1)+2,mid+1,R,pos1,pos2); // else{ // update((at<<1)+1,L,mid,pos1,mid); // update((at<<1)+2,mid+1,R,mid+1,pos2); // } update((at << 1), L, mid, pos1, pos2); update((at << 1) + 1, mid + 1, R, pos1, pos2); // tree[at]=tree[(at<<1)+1]+tree[(at<<1)+2]+prop[at]*(R-L+1); } int query(int at, int L, int R, int l) { // if(L<=l && l<=R)return tree[at]; if (L == R) return tree[at]; if (L > l && l > R) return 0; int mid = (L + R) >> 1; // if(l<=mid)query((at<<1)+1,L,mid,l,carry+prop[at]); // else query((at<<1)+2,mid+1,R,l,carry+prop[at]); if (l <= mid) return tree[at] ^ query((at << 1), L, mid, l); else return tree[at] ^ query((at << 1) + 1, mid + 1, R, l); // return ; } /// reverse sorting function. bool revp(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.first != b.first) return a.first > b.first; else return a.second < b.second; } bool revp2(const pair<ll, ll> &a, const pair<ll, ll> &b) { return a.second < b.second; } ll ones(ll n) { ll s = 0; while (n > 0) { if (n & 1) s++; n = n >> 1; // cout<<n<<endl; } return s; } vector<ll> vp2[200005]; vector<ll> vp; map<ll, ll> m3; map<ll, ll> m4; // m3[1]=0; void dfs(ll a) { if (!vis[a]) { vis[a] = 1; // if(a!=1)vp.push_back(m3[a]-(vp2[a].size()-1)); // l3[a]+=vp2[a].size(); for (int i = 0; i < vp2[a].size(); i++) { if (m3[vp2[a][i]] == 0 && vp2[a][i] != 1) m3[vp2[a][i]] = m3[a] + 1; // cout<<"node->"<<vp2[a][i]<<", level->"<<m3[vp2[a][i]]<<endl; // m4[m3[a]+1]++; // m=m3[vp2[a][i]];///koyta level if (!vis[vp2[a][i]]) { dfs(vp2[a][i]); vis[a] += vis[vp2[a][i]]; } } //} } else return; } int main() { // IOS; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ll t, i = 1, j, k, x, y, q = 0, n, c, m, z, z2, l, r, cases = 0, d, p, nl, np, a, e = 1, b, x2 = -1, x1 = 1000000005, x3 = 0, x4 = 0, x5 = 0, x6 = 0, x7 = 0, x8 = 0; double x10 = 100000, x14, x15, x16, x17, x18; char x11, y1 = 'a', y2, y3; int x12 = 0; string s3, s4, s5, s6, s7, s8; queue<ll> q2; stack<ll> st; set<ll> y4; // vector<ll>vp; // vector<ll>vp2[200005]; // vector<ll>vp3; // vector<ll>vp4; map<ll, ll> mp; // set<ll>y4; map<ll, ll> m2; map<ll, ll>::iterator it; // map<ll,ll>m3; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> l1[i]; x3 += l1[i]; } if (x3 > n) cout << -1 << endl; else cout << n - x3 << endl; return 0; }
#include <bits/stdc++.h> #include <sstream> #define ll long long int #include <stdlib.h> #include <vector> #define pi acos(-1) #define maxm 100005 #define pb push_back #define MOD 1e9 + 7 #define highest(x) numeric_limits<x>::max() #define lowest(x) numeric_limits<x>::min() /// s1.substr(1,3);///STARTING FROM INDEX 1, 3 LNEGTH SUBSTRING. /// s1.find("adn")///RETURNS STARTING INDEX OF THE SUBSTRING ///"adn" IF IT EXISTS IN THE STRING S1./// /// s1.find("adn",int pos);///RETURNS STARTING INDEX OF THE /// SUBSTRING "adn" SEARCHING FROM INDEX POS OF STRING s1./// /// string::npos returns a garbage value if not found... /// reverse(s1.begin(),s1.end())-> to reverse a string. /// next_permutation(f,f+n)->f array er next permutation return korbe.. /// str.erase(1,2)->deletes 2 char from index 1.. /// for(auto i:p2)->i=p2.begin() theke p2.end() er ag porjonto.. /// max_element(v,v+4);->return a pointer to the max element /// in a array/vector.. v from 1st element to 4th element. /// same for min_element(v,v+4); ///__builtin_popcount(a);->counts how many number of one's /// in a in binary representation. /// accumulate(l1+1,l1+10+1,0LL)=>it perform the sum from l1[1] to /// l1[10] and 0 is the initial sum. /// cout<<fixed<<setprecision(12)<<x14<<endl;//=>x14 er /// doshomik er por 12 ta 0 thakbe. #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define gcd(a, b) __gcd(a, b) using namespace std; ll l1[200005], vis[200005], l3[200005], s = 0, m = 0, mn = 0; ll dx[] = {1, 0, -1, 0}; ll dy[] = {0, -1, 0, 1}; // vector<ll>v[5]; // set<ll>v2; // map<ll,ll>m2; // vector<pair<ll,ll>>p2; // vector<pair<ll,ll>>p3; char s2[maxm]; // int sum[max]; int tree[maxm * 4]; // int prop[max*3]; void STB(int at, int L, int R) { // int sum[at]=0; if (L == R) { tree[at] = (s2[L - 1] - '0'); return; } int mid = (L + R) / 2; STB(2 * at, L, mid); STB(2 * at + 1, mid + 1, R); // tree[at]=tree[2*at]+tree[2*at+1]; // return sum[at]; } void update(int at, int L, int R, int pos1, int pos2) { if (L > pos2 || R < pos1) return; if (L >= pos1 && R <= pos2) { tree[at] ^= 1; return; } int mid = (L + R) >> 1; // if(pos2<=mid)update((at<<1)+1,L,mid,pos1,pos2); // else if(pos1>mid)update((at<<1)+2,mid+1,R,pos1,pos2); // else{ // update((at<<1)+1,L,mid,pos1,mid); // update((at<<1)+2,mid+1,R,mid+1,pos2); // } update((at << 1), L, mid, pos1, pos2); update((at << 1) + 1, mid + 1, R, pos1, pos2); // tree[at]=tree[(at<<1)+1]+tree[(at<<1)+2]+prop[at]*(R-L+1); } int query(int at, int L, int R, int l) { // if(L<=l && l<=R)return tree[at]; if (L == R) return tree[at]; if (L > l && l > R) return 0; int mid = (L + R) >> 1; // if(l<=mid)query((at<<1)+1,L,mid,l,carry+prop[at]); // else query((at<<1)+2,mid+1,R,l,carry+prop[at]); if (l <= mid) return tree[at] ^ query((at << 1), L, mid, l); else return tree[at] ^ query((at << 1) + 1, mid + 1, R, l); // return ; } /// reverse sorting function. bool revp(const pair<ll, ll> &a, const pair<ll, ll> &b) { if (a.first != b.first) return a.first > b.first; else return a.second < b.second; } bool revp2(const pair<ll, ll> &a, const pair<ll, ll> &b) { return a.second < b.second; } ll ones(ll n) { ll s = 0; while (n > 0) { if (n & 1) s++; n = n >> 1; // cout<<n<<endl; } return s; } vector<ll> vp2[200005]; vector<ll> vp; map<ll, ll> m3; map<ll, ll> m4; // m3[1]=0; void dfs(ll a) { if (!vis[a]) { vis[a] = 1; // if(a!=1)vp.push_back(m3[a]-(vp2[a].size()-1)); // l3[a]+=vp2[a].size(); for (int i = 0; i < vp2[a].size(); i++) { if (m3[vp2[a][i]] == 0 && vp2[a][i] != 1) m3[vp2[a][i]] = m3[a] + 1; // cout<<"node->"<<vp2[a][i]<<", level->"<<m3[vp2[a][i]]<<endl; // m4[m3[a]+1]++; // m=m3[vp2[a][i]];///koyta level if (!vis[vp2[a][i]]) { dfs(vp2[a][i]); vis[a] += vis[vp2[a][i]]; } } //} } else return; } int main() { // IOS; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ll t, i = 1, j, k, x, y, q = 0, n, c, m, z, z2, l, r, cases = 0, d, p, nl, np, a, e = 1, b, x2 = -1, x1 = 1000000005, x3 = 0, x4 = 0, x5 = 0, x6 = 0, x7 = 0, x8 = 0; double x10 = 100000, x14, x15, x16, x17, x18; char x11, y1 = 'a', y2, y3; int x12 = 0; string s3, s4, s5, s6, s7, s8; queue<ll> q2; stack<ll> st; set<ll> y4; // vector<ll>vp; // vector<ll>vp2[200005]; // vector<ll>vp3; // vector<ll>vp4; map<ll, ll> mp; // set<ll>y4; map<ll, ll> m2; map<ll, ll>::iterator it; // map<ll,ll>m3; cin >> n >> k; for (int i = 1; i <= k; i++) { cin >> l1[i]; x3 += l1[i]; } if (x3 > n) cout << -1 << endl; else cout << n - x3 << endl; return 0; }
replace
173
174
173
174
0
p02706
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } int main() { int n, m; cin >> n >> m; vector<int> a(m); rep(i, m) cin >> a[i]; int sum = 0; rep(i, n) sum += a[i]; int res = n - sum; if (res < 0) res = -1; cout << res << "\n"; return 0; }
#include <algorithm> #include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } int main() { int n, m; cin >> n >> m; vector<int> a(m); rep(i, m) cin >> a[i]; int sum = 0; rep(i, m) sum += a[i]; int res = n - sum; if (res < 0) res = -1; cout << res << "\n"; return 0; }
replace
27
28
27
28
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> A; for (int i = 0; i < M; i++) { cin >> A.at(i); } int sum = 0; for (int i = 0; i < M; i++) { sum += A.at(i); } cout << max(N - sum, -1) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> A(M); for (int i = 0; i < M; i++) { cin >> A.at(i); } int sum = 0; for (int i = 0; i < M; i++) { sum += A.at(i); } cout << max(N - sum, -1) << endl; }
replace
6
7
6
7
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
p02706
C++
Runtime Error
#include <iostream> using namespace std; int main() { int N, M; cin >> N; cin >> M; int A[M]; int T = 0; for (int i = 0; i < N; i++) { cin >> A[i]; T += A[i]; } if (N >= T) { cout << N - T << endl; } else { cout << -1 << endl; } }
#include <iostream> using namespace std; int main() { int N, M; cin >> N; cin >> M; int A[M]; int T = 0; for (int i = 0; i < M; i++) { cin >> A[i]; T += A[i]; } if (N >= T) { cout << N - T << endl; } else { cout << -1 << endl; } }
replace
12
13
12
13
0
p02706
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, m, a[1500] = {0}; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i]; } int sum = 0, ans; for (int i = 0; i < m; i++) { sum = sum + a[i]; } ans = n - sum; if (ans >= 0) { cout << ans << "\n"; } else { cout << -1 << "\n"; } return 0; }
#include <iostream> using namespace std; int main() { int n, m, a[10000] = {0}; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i]; } int sum = 0, ans; for (int i = 0; i < m; i++) { sum = sum + a[i]; } ans = n - sum; if (ans >= 0) { cout << ans << "\n"; } else { cout << -1 << "\n"; } return 0; }
replace
4
5
4
5
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int sum; vector<int> syukudai_nissuu; for (int i = 0; i < M; i++) { cin >> syukudai_nissuu.at(i); } sum = accumulate(syukudai_nissuu.begin(), syukudai_nissuu.end(), 0); if (N - sum >= 0) { cout << N - sum << endl; } else { cout << -1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int sum; vector<int> syukudai_nissuu(M); for (int i = 0; i < M; i++) { cin >> syukudai_nissuu.at(i); } sum = accumulate(syukudai_nissuu.begin(), syukudai_nissuu.end(), 0); if (N - sum >= 0) { cout << N - sum << endl; } else { cout << -1 << endl; } }
replace
8
9
8
9
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0, m, n, a[1001], i; cin >> n >> m; for (i = 0; i < m; i++) { cin >> a[i]; sum += a[i]; } if (sum <= n) cout << n - sum; else cout << "-1"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int sum = 0, m, n, a[10001], i; cin >> n >> m; for (i = 0; i < m; i++) { cin >> a[i]; sum += a[i]; } if (sum <= n) cout << n - sum; else cout << "-1"; return 0; }
replace
3
4
3
4
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int(i) = 0; (i) < (n); ++(i)) #define REPV(iter, v) \ for (auto(iter) = (v).begin(); (iter) != (v).end(); ++(iter)) #define ALL(v) (v).begin(), (v).end() #define MOD 1000000007 using namespace std; typedef long long ll; int main() { ll N, M; cin >> N >> M; vector<ll> A(M); REP(i, M) cin >> A[i]; ll sum = 0; REP(i, N) sum += A[i]; ll ans; if (sum <= N) ans = N - sum; else ans = -1; cout << ans << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int(i) = 0; (i) < (n); ++(i)) #define REPV(iter, v) \ for (auto(iter) = (v).begin(); (iter) != (v).end(); ++(iter)) #define ALL(v) (v).begin(), (v).end() #define MOD 1000000007 using namespace std; typedef long long ll; int main() { ll N, M; cin >> N >> M; vector<ll> A(M); REP(i, M) cin >> A[i]; ll sum = 0; REP(i, M) sum += A[i]; ll ans; if (sum <= N) ans = N - sum; else ans = -1; cout << ans << endl; }
replace
19
20
19
20
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using namespace std; using p = pair<int, int>; int main() { int n, m, sum = 0; vector<int> a(1000); cin >> n >> m; rep(i, m) { cin >> a.at(i); sum += a.at(i); } if (sum > n) cout << -1; else cout << n - sum; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using namespace std; using p = pair<int, int>; int main() { int n, m, sum = 0; vector<int> a(10000); cin >> n >> m; rep(i, m) { cin >> a.at(i); sum += a.at(i); } if (sum > n) cout << -1; else cout << n - sum; return 0; }
replace
8
9
8
9
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> vec(100, 0); for (int i = 0; i < M; i++) { cin >> vec.at(i); } int a = 0; for (int i = 0; i < M; i++) { a += vec.at(i); } if (N < a) { cout << "-1" << endl; } else { cout << N - a << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> vec(M); for (int i = 0; i < M; i++) { cin >> vec.at(i); } int a = 0; for (int i = 0; i < M; i++) { a += vec.at(i); } if (N < a) { cout << "-1" << endl; } else { cout << N - a << endl; } }
replace
5
6
5
6
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int sum = 0; vector<int> a(M); for (int i = 0; i < N; i++) { cin >> a.at(i); sum += a.at(i); } if (sum <= N) { cout << N - sum << endl; } else { cout << -1 << endl; } // ここにプログラムを追記 }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int sum = 0; vector<int> a(M); for (int i = 0; i < M; i++) { cin >> a.at(i); sum += a.at(i); } if (sum <= N) { cout << N - sum << endl; } else { cout << -1 << endl; } // ここにプログラムを追記 }
replace
8
9
8
9
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02706
C++
Runtime Error
// int a = stoi(c); 文字列をintへ // 小文字から大文字 // transform(a.begin(), a.end(), a.begin(), ::toupper); // 途中の出力をそのまま残さない // 数値計算 個数以外はdouble // map<キー,値> p は辞書。p[キー] = 値 // map 全探索 // auto begin = p.begin(), end = p.end(); // for (auto it = begin; it != end; it++) {} // mapのキー:it->first mapのバリュー:it->second // 絶対値 abs() // 入力は空白で切れる // 大文字判定 isupper(文字) 小文字判定 islower(文字) // do{}while(next_permutation(ALL(配列))) // while(N)で回すとき、Nはコピーを作っておく // 小文字に対応する文字コード:S[i] - 'a' // 文字コード→小文字:(char)(数字+'a') // グラフの距離:隣接行列で扱う // 等価なものに変換する思考 // bool型 初期値はTrue // 島渡りの問題:中間ノードに着目 // 配列はvector<>を使う:意味わからないエラーがなくなる。 // 背反な事象にちゃんとわける // チェックリストはマップを使う // 数が大きい時の比較はstring型で行う // 全て0になったか調べたい->0になるたびにcntする // またはかかつか // 例外処理は最初にする // x = p^m + q^n...の約数の個数:(n+1)*(m+1).... // N!のどの素因数で何回割れるか // ⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和 // パズルの問題->一般化して全探索 // 数が大きい時のせぐふぉはコードテストで試してみる // スペルミスに注意 // stack<ll> s; // s.push(要素);s.top();s.pop(); // queue<ll> q; // q.push(要素);q.front();q.pop(); // 同じ作業繰り返す系の問題:収束先を見つける // 関係性は隣接行列で記録 // 過半数:N/2.0で判定 // ある量からある量を引く系の問題:端から定義してやる #include <bits/stdc++.h> #define rep(i, N) for (int i = 0; i < N; i++) #define ALL(a) (a).begin(), (a).end() #define ll long long int using namespace std; // 円周率 const double PI = 3.14159265358979323846; // 割るやつ const ll MOD = (pow(10, 9) + 7); // K進数でのNの桁数 ll dig(ll N, ll K) { ll dig = 0; while (N) { dig++; N /= K; } return dig; } // a,bの最大公約数 ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } // a,bの最小公倍数 ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } // 階乗計算 ll f(ll n) { if (n == 0 || n == 1) return 1; else return (n * f(n - 1)); } // Nのd桁目の数 ll dignum(ll N, ll d) { ll x = pow(10, d); N %= x; ll y = pow(10, d - 1); N /= y; return N; } // Nをdで何回割れるか ll divcnt(ll N, ll d) { ll ans = 0; while (1) { if (N % d == 0) { ans++; N /= d; } else break; } return ans; } // 素数判定 bool prime(ll num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } // フィボナッチ数列 vector<ll> memo(pow(10, 6) + 1); ll fibo(ll n) { if (n == 1) return 1; else if (n == 2) return 1; else if (memo[n] != 0) return memo[n]; else return memo[n] = fibo(n - 1) + f(n - 2); } int main() { ll N; cin >> N; ll M; cin >> M; vector<ll> A(M); rep(i, M) cin >> A[i]; ll cnt = 0; rep(i, N) cnt += A[i]; if (cnt > N) cout << -1 << endl; else cout << N - cnt << endl; }
// int a = stoi(c); 文字列をintへ // 小文字から大文字 // transform(a.begin(), a.end(), a.begin(), ::toupper); // 途中の出力をそのまま残さない // 数値計算 個数以外はdouble // map<キー,値> p は辞書。p[キー] = 値 // map 全探索 // auto begin = p.begin(), end = p.end(); // for (auto it = begin; it != end; it++) {} // mapのキー:it->first mapのバリュー:it->second // 絶対値 abs() // 入力は空白で切れる // 大文字判定 isupper(文字) 小文字判定 islower(文字) // do{}while(next_permutation(ALL(配列))) // while(N)で回すとき、Nはコピーを作っておく // 小文字に対応する文字コード:S[i] - 'a' // 文字コード→小文字:(char)(数字+'a') // グラフの距離:隣接行列で扱う // 等価なものに変換する思考 // bool型 初期値はTrue // 島渡りの問題:中間ノードに着目 // 配列はvector<>を使う:意味わからないエラーがなくなる。 // 背反な事象にちゃんとわける // チェックリストはマップを使う // 数が大きい時の比較はstring型で行う // 全て0になったか調べたい->0になるたびにcntする // またはかかつか // 例外処理は最初にする // x = p^m + q^n...の約数の個数:(n+1)*(m+1).... // N!のどの素因数で何回割れるか // ⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和 // パズルの問題->一般化して全探索 // 数が大きい時のせぐふぉはコードテストで試してみる // スペルミスに注意 // stack<ll> s; // s.push(要素);s.top();s.pop(); // queue<ll> q; // q.push(要素);q.front();q.pop(); // 同じ作業繰り返す系の問題:収束先を見つける // 関係性は隣接行列で記録 // 過半数:N/2.0で判定 // ある量からある量を引く系の問題:端から定義してやる #include <bits/stdc++.h> #define rep(i, N) for (int i = 0; i < N; i++) #define ALL(a) (a).begin(), (a).end() #define ll long long int using namespace std; // 円周率 const double PI = 3.14159265358979323846; // 割るやつ const ll MOD = (pow(10, 9) + 7); // K進数でのNの桁数 ll dig(ll N, ll K) { ll dig = 0; while (N) { dig++; N /= K; } return dig; } // a,bの最大公約数 ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } // a,bの最小公倍数 ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } // 階乗計算 ll f(ll n) { if (n == 0 || n == 1) return 1; else return (n * f(n - 1)); } // Nのd桁目の数 ll dignum(ll N, ll d) { ll x = pow(10, d); N %= x; ll y = pow(10, d - 1); N /= y; return N; } // Nをdで何回割れるか ll divcnt(ll N, ll d) { ll ans = 0; while (1) { if (N % d == 0) { ans++; N /= d; } else break; } return ans; } // 素数判定 bool prime(ll num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; } return true; } // フィボナッチ数列 vector<ll> memo(pow(10, 6) + 1); ll fibo(ll n) { if (n == 1) return 1; else if (n == 2) return 1; else if (memo[n] != 0) return memo[n]; else return memo[n] = fibo(n - 1) + f(n - 2); } int main() { ll N; cin >> N; ll M; cin >> M; vector<ll> A(M); rep(i, M) cin >> A[i]; ll cnt = 0; rep(i, M) cnt += A[i]; if (cnt > N) cout << -1 << endl; else cout << N - cnt << endl; }
replace
144
145
144
145
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; const int N = 200005; const long double EPS = 1e-9; const long double PI = acos(-1.); int main() { // #ifdef LOCAL // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ll n, m, sum = 0, a[N]; scanf("%I64d%I64d", &n, &m); for (int i = 0; i < m; i++) { scanf("%I64d", &a[i]); sum += a[i]; } if (sum > n) return printf("%d\n", -1); printf("%I64d\n", n - sum); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; const int N = 200005; const long double EPS = 1e-9; const long double PI = acos(-1.); int main() { // #ifdef LOCAL // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ll n, m, sum = 0, a[N]; scanf("%I64d%I64d", &n, &m); for (int i = 0; i < m; i++) { scanf("%I64d", &a[i]); sum += a[i]; } if (sum > n) return printf("%d\n", -1), 0; printf("%I64d\n", n - sum); return 0; }
replace
22
23
22
23
0
p02706
C++
Runtime Error
#include <array> #include <iostream> using namespace std; int main() { int n, m, sum = 0; array<int, 1000> working_day; cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> working_day[i]; sum += working_day[i]; } if (n >= sum) { cout << n - sum; } else { cout << -1; } return 0; }
#include <array> #include <iostream> using namespace std; int main() { int n, m, sum = 0; array<int, 10000> working_day; cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> working_day[i]; sum += working_day[i]; } if (n >= sum) { cout << n - sum; } else { cout << -1; } return 0; }
replace
6
7
6
7
0
p02706
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <vector> using namespace std; int main() { int n, m, ans = 0, sum = 0; cin >> n >> m; vector<int> a(1000000000); for (int i = 0; i < m; i++) { cin >> a[i]; sum += a[i]; } if (n < sum) { ans = -1; } else { ans = n - sum; } cout << ans << endl; return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <queue> #include <vector> using namespace std; int main() { int n, m, ans = 0, sum = 0; cin >> n >> m; vector<int> a(10000000); for (int i = 0; i < m; i++) { cin >> a[i]; sum += a[i]; } if (n < sum) { ans = -1; } else { ans = n - sum; } cout << ans << endl; return 0; }
replace
10
11
10
11
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, m, sum; ll a[1000]; cin >> n >> m; sum = 0; for (int i = 1; i <= m; i++) { cin >> a[i]; sum += a[i]; } if (n > sum) { cout << n - sum << endl; } else if (n == sum) { cout << "0" << endl; } else if (sum > n) { cout << "-1" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, m, sum; ll a[10000]; cin >> n >> m; sum = 0; for (int i = 1; i <= m; i++) { cin >> a[i]; sum += a[i]; } if (n > sum) { cout << n - sum << endl; } else if (n == sum) { cout << "0" << endl; } else if (sum > n) { cout << "-1" << endl; } return 0; }
replace
5
6
5
6
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> v; for (int i = 0; i < m; i++) { cin >> v.at(i); } int k; k = 0; for (int i = 0; i < m; i++) { k += v.at(i); } if (n < k) { cout << -1 << endl; } else { cout << n - k << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> v(m); for (int i = 0; i < m; i++) { cin >> v.at(i); } int k; k = 0; for (int i = 0; i < m; i++) { k += v.at(i); } if (n < k) { cout << -1 << endl; } else { cout << n - k << endl; } }
replace
7
8
7
8
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; int M; cin >> N >> M; int sum = 0; vector<int> a(M, 0); for (int i = 0; i < M; i++) { cin >> a[i]; sum = sum + a[i]; } if (N - sum < 0) { cout << -1 << endl; return 9; } cout << N - sum << endl; // cout<<N<<" "<<sum<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; int M; cin >> N >> M; int sum = 0; vector<int> a(M, 0); for (int i = 0; i < M; i++) { cin >> a[i]; sum = sum + a[i]; } if (N - sum < 0) { cout << -1 << endl; return 0; } cout << N - sum << endl; // cout<<N<<" "<<sum<<endl; }
replace
14
15
14
15
0
p02706
C++
Runtime Error
// Bismillahir Rahmanir Rahim #include <bits/stdc++.h> using namespace std; int main() { // freopen("a.txt","r",stdin); int n, ar[1001], x = 0, i, j, m, sum; cin >> n >> m; for (i = 0; i < m; i++) { cin >> ar[i]; x += ar[i]; } sum = n - x; if (sum >= 0) cout << sum << endl; else cout << "-1\n"; }
// Bismillahir Rahmanir Rahim #include <bits/stdc++.h> using namespace std; int main() { // freopen("a.txt","r",stdin); int n, ar[10001], x = 0, i, j, m, sum; cin >> n >> m; for (i = 0; i < m; i++) { cin >> ar[i]; x += ar[i]; } sum = n - x; if (sum >= 0) cout << sum << endl; else cout << "-1\n"; }
replace
6
7
6
7
0
p02706
C++
Runtime Error
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <math.h> using namespace std; int main() { int N, M; int A[1000]; cin >> N >> M; for (int i = 0; i < M; i++) { cin >> A[i]; } int sum = 0; for (int i = 0; i < M; i++) { sum += A[i]; } if (N - sum >= 0) cout << N - sum << endl; else cout << -1 << endl; return 0; }
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> #include <vector> #define _USE_MATH_DEFINES #include <math.h> using namespace std; int main() { int N, M; int A[10000]; cin >> N >> M; for (int i = 0; i < M; i++) { cin >> A[i]; } int sum = 0; for (int i = 0; i < M; i++) { sum += A[i]; } if (N - sum >= 0) cout << N - sum << endl; else cout << -1 << endl; return 0; }
replace
11
12
11
12
0
p02706
C++
Runtime Error
#include <iostream> using namespace std; int main() { int i, n, m, sum = 0, a[100]; cin >> n >> m; for (i = 0; i < m; i++) { cin >> a[i]; sum += a[i]; } if (sum > n) cout << -1; else cout << n - sum; return 0; }
#include <iostream> using namespace std; int main() { int i, n, m, sum = 0, a[100000]; cin >> n >> m; for (i = 0; i < m; i++) { cin >> a[i]; sum += a[i]; } if (sum > n) cout << -1; else cout << n - sum; return 0; }
replace
4
5
4
5
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M, sum = 0; cin >> N >> M; vector<int> A(M); for (int i = 0; i < N; i++) { cin >> A.at(i); sum += A.at(i); } if (sum > N) { cout << -1 << endl; } else { cout << N - sum << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int N, M, sum = 0; cin >> N >> M; vector<int> A(M); for (int i = 0; i < M; i++) { cin >> A.at(i); sum += A.at(i); } if (sum > N) { cout << -1 << endl; } else { cout << N - sum << endl; } }
replace
7
8
7
8
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 2) >= this->size() (which is 2)
p02706
C++
Runtime Error
/*input */ // assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) // is(65-90) and 32 for space #pragma GCC target ("avx2") #pragma GCC // optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define pii pair<ll, ll> #define vpii vector<pii> #define vi vector<ll> #define vs vector<string> #define vvi vector<vector<ll>> #define inf (ll)1e18 #define all(it, a) for (auto it = (a).begin(); it != (a).end(); it++) #define F first #define S second #define sz(x) (ll) x.size() #define rep(i, a, b) for (ll i = a; i < b; i++) #define repr(i, a, b) for (ll i = a; i > b; i--) #define lbnd lower_bound #define ubnd upper_bound #define mp make_pair #define whatis(x) cout << #x << " is " << x << "\n"; #define graph(n) adj(n, vector<ll>()) // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define debug(x) cout << #x << " " << x << endl; #define debug_p(x) cout << #x << " " << x.F << " " << x.S << endl; #define debug_v(x) \ { \ cout << #x << " "; \ for (auto ioi : x) \ cout << ioi << " "; \ cout << endl; \ } #define debug_vp(x) \ { \ cout << #x << " "; \ for (auto ioi : x) \ cout << '[' << ioi.F << " " << ioi.S << ']'; \ cout << endl; \ } #define debug_v_v(x) \ { \ cout << #x << "/*\n"; \ for (auto ioi : x) { \ for (auto ioi2 : ioi) \ cout << ioi2 << " "; \ cout << '\n'; \ } \ cout << "*/" << #x << endl; \ } int solve() { ll n, m; cin >> n >> m; vi a(m); ll sum = 0; rep(i, 0, m) { cin >> a[i]; sum += a[i]; } cout << (n >= sum ? n - sum : -1) << "\n"; } int main() { auto start = chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll test_cases = 1; // cin>>test_cases; while (test_cases--) solve(); auto stop = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); // cout<<"\nduration: "<<(double)duration.count()<<" milliseconds"; }
/*input */ // assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) // is(65-90) and 32 for space #pragma GCC target ("avx2") #pragma GCC // optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define pii pair<ll, ll> #define vpii vector<pii> #define vi vector<ll> #define vs vector<string> #define vvi vector<vector<ll>> #define inf (ll)1e18 #define all(it, a) for (auto it = (a).begin(); it != (a).end(); it++) #define F first #define S second #define sz(x) (ll) x.size() #define rep(i, a, b) for (ll i = a; i < b; i++) #define repr(i, a, b) for (ll i = a; i > b; i--) #define lbnd lower_bound #define ubnd upper_bound #define mp make_pair #define whatis(x) cout << #x << " is " << x << "\n"; #define graph(n) adj(n, vector<ll>()) // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define debug(x) cout << #x << " " << x << endl; #define debug_p(x) cout << #x << " " << x.F << " " << x.S << endl; #define debug_v(x) \ { \ cout << #x << " "; \ for (auto ioi : x) \ cout << ioi << " "; \ cout << endl; \ } #define debug_vp(x) \ { \ cout << #x << " "; \ for (auto ioi : x) \ cout << '[' << ioi.F << " " << ioi.S << ']'; \ cout << endl; \ } #define debug_v_v(x) \ { \ cout << #x << "/*\n"; \ for (auto ioi : x) { \ for (auto ioi2 : ioi) \ cout << ioi2 << " "; \ cout << '\n'; \ } \ cout << "*/" << #x << endl; \ } int solve() { ll n, m; cin >> n >> m; vi a(m); ll sum = 0; rep(i, 0, m) { cin >> a[i]; sum += a[i]; } cout << (n >= sum ? n - sum : -1) << "\n"; return 0; } int main() { auto start = chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll test_cases = 1; // cin>>test_cases; while (test_cases--) solve(); auto stop = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); // cout<<"\nduration: "<<(double)duration.count()<<" milliseconds"; }
insert
67
67
67
68
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // define #Asukaminato is cute #define ll long long #define rep(i, m) for (int i = 0; i < (int)(m); i++) const int inf = 1000000000; // 10^9 Ten to the power of nine. int main() { int N, M; cin >> N >> M; int sum = 0; int A[100]; for (int i = 0; i < M; i++) { cin >> A[i]; sum += A[i]; } if (N >= sum) { cout << N - sum; } else { cout << -1; } }
#include <bits/stdc++.h> using namespace std; // define #Asukaminato is cute #define ll long long #define rep(i, m) for (int i = 0; i < (int)(m); i++) const int inf = 1000000000; // 10^9 Ten to the power of nine. int main() { int N, M; cin >> N >> M; int sum = 0; int A[10000]; for (int i = 0; i < M; i++) { cin >> A[i]; sum += A[i]; } if (N >= sum) { cout << N - sum; } else { cout << -1; } }
replace
11
12
11
12
0
p02706
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; int n, m, a[1008], i = 0; int tot = 0; int main() { cin >> n; cin >> m; for (i = 1; i <= m; i++) { cin >> a[i]; } for (i = 1; i <= m; i++) { tot += a[i]; } if (tot <= n) { cout << n - tot; } else { cout << -1; } return 0; }
#include <cstdio> #include <iostream> using namespace std; int n, m, a[10008], i = 0; int tot = 0; int main() { cin >> n; cin >> m; for (i = 1; i <= m; i++) { cin >> a[i]; } for (i = 1; i <= m; i++) { tot += a[i]; } if (tot <= n) { cout << n - tot; } else { cout << -1; } return 0; }
replace
3
4
3
4
0
p02706
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int N; int M; int A; int b; cin >> N >> M; while (M > 0) { cin >> A; b = b + A; } if (N - b >= 0) cout << N - b; else cout << "-1"; }
#include <iostream> using namespace std; int main() { int N; int M; int A; int b; cin >> N >> M; while (M > 0) { cin >> A; b = b + A; M--; } if (N - b >= 0) cout << N - b; else cout << "-1"; }
insert
13
13
13
14
TLE
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef unsigned long long int ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define N 100010 #define M 200010 #define A 110 #define endl "\n" #define mod 1000000007 int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; int arr[1010]; ll tot = 0; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> arr[i]; tot += arr[i]; } if (tot > n) { cout << -1 << endl; } else { cout << n - tot << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef unsigned long long int ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define N 100010 #define M 200010 #define A 110 #define endl "\n" #define mod 1000000007 int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; int arr[10010]; ll tot = 0; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> arr[i]; tot += arr[i]; } if (tot > n) { cout << -1 << endl; } else { cout << n - tot << endl; } return 0; }
replace
23
24
23
24
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[n]; cin >> n >> m; for (int i = 0; i < m; i++) cin >> a[i]; int s = 0; for (int i = 0; i < m; i++) s += a[i]; if (s > n) { cout << "-1" << endl; } else { cout << n - s << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, a[10000]; cin >> n >> m; for (int i = 0; i < m; i++) cin >> a[i]; int s = 0; for (int i = 0; i < m; i++) s += a[i]; if (s > n) { cout << "-1" << endl; } else { cout << n - s << endl; } }
replace
3
4
3
4
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; void solving() { int n, m; cin >> n >> m; int a[m]; int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } n = n - sum; if (n < 0) cout << "-1"; else cout << n << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); solving(); return 0; }
#include <bits/stdc++.h> using namespace std; void solving() { int n, m; cin >> n >> m; int a[m]; int sum = 0; for (int i = 0; i < m; i++) { cin >> a[i]; sum += a[i]; } n = n - sum; if (n < 0) cout << "-1"; else cout << n << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); solving(); return 0; }
replace
7
8
7
8
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int A[10005]; int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); long long n, m; cin >> n >> m; long long total = 0; for (int i = 0; i < n; ++i) { cin >> A[i]; total += A[i]; } total = n - total; if (total >= 0) cout << total << '\n'; else cout << -1 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int A[10005]; int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); long long n, m; cin >> n >> m; long long total = 0; for (int i = 0; i < m; ++i) { cin >> A[i]; total += A[i]; } total = n - total; if (total >= 0) cout << total << '\n'; else cout << -1 << '\n'; return 0; }
replace
14
15
14
15
0
p02706
C++
Runtime Error
#include <algorithm> #include <bitset> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define Per(i, sta, n) for (int i = n - 1; i >= sta; i--) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int n, m; int a[5010]; void solve() { cin >> n >> m; int S = 0; rep(i, m) { cin >> a[i]; S += a[i]; } if (n >= S) cout << n - S << endl; else cout << -1 << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }
#include <algorithm> #include <bitset> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define Per(i, sta, n) for (int i = n - 1; i >= sta; i--) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int n, m; int a[50010]; void solve() { cin >> n >> m; int S = 0; rep(i, m) { cin >> a[i]; S += a[i]; } if (n >= S) cout << n - S << endl; else cout << -1 << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }
replace
43
44
43
44
0
p02706
C++
Runtime Error
#include <iostream> using namespace std; #define M_PI 3.14159265358979323846 int main() { int N, M, sum = 0; int A[100]; cin >> N >> M; for (int i = 0; i < M; i++) { cin >> A[i]; sum += A[i]; } if ((N - sum) >= 0) cout << N - sum; else cout << "-1"; return 0; }
#include <iostream> using namespace std; #define M_PI 3.14159265358979323846 int main() { int N, M, sum = 0; int A[10000]; cin >> N >> M; for (int i = 0; i < M; i++) { cin >> A[i]; sum += A[i]; } if ((N - sum) >= 0) cout << N - sum; else cout << "-1"; return 0; }
replace
6
7
6
7
0
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int a[1010]; int main() { int n, m, sum = 0; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i]; sum += a[i]; } if (sum <= n) printf("%d\n", n - sum); else printf("-1\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int a[10010]; int main() { int n, m, sum = 0; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i]; sum += a[i]; } if (sum <= n) printf("%d\n", n - sum); else printf("-1\n"); return 0; }
replace
3
4
3
4
0
p02706
Python
Runtime Error
n, m = map(int, input().split) a = list(map(int, input().split())) ct = 0 for i in range(m): ct += a[i] if n - ct >= 0: print(n - ct) else: print(-1)
n, m = map(int, input().split()) a = list(map(int, input().split())) ct = 0 for i in range(m): ct += a[i] if n - ct >= 0: print(n - ct) else: print(-1)
replace
0
1
0
1
TypeError: 'builtin_function_or_method' object is not iterable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02706/Python/s941071070.py", line 1, in <module> n, m = map(int, input().split) TypeError: 'builtin_function_or_method' object is not iterable
p02706
Python
Runtime Error
summer_vacation, amount_of_homework = map(int, input().split()) a = map(int, input().split()) homework_list = list[a] total_days = 0 for i in homework_list: total_days += i if summer_vacation >= total_days: print(summer_vacation - total_days) else: print(-1)
summer_vacation, amount_of_homework = map(int, input().split()) a = map(int, input().split()) homework_list = list(a) total_days = 0 for i in homework_list: total_days += i if summer_vacation >= total_days: print(summer_vacation - total_days) else: print(-1)
replace
2
3
2
3
TypeError: 'types.GenericAlias' object is not iterable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02706/Python/s080879362.py", line 7, in <module> for i in homework_list: TypeError: 'types.GenericAlias' object is not iterable
p02706
Python
Runtime Error
n, m = map(int, input().split()) print(max(n - sum(list(map(int, input().split())))), -1)
n, m = map(int, input().split()) A = list(map(int, input().split())) if n >= sum(A): print(n - sum(A)) else: print("-1")
replace
1
2
1
7
TypeError: 'int' object is not iterable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02706/Python/s791039988.py", line 2, in <module> print(max(n - sum(list(map(int, input().split())))), -1) TypeError: 'int' object is not iterable
p02706
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int M, N, l, i = 0, a[1000], j = 0; cin >> M >> N; while (cin >> l) { a[i] = l; i++; } while (j < N) { M = M - a[j]; j++; } if (M >= 0) { cout << M; } else { cout << -1; } }
#include <bits/stdc++.h> using namespace std; int main() { int M, N, l, i = 0, a[10000], j = 0; cin >> M >> N; while (cin >> l) { a[i] = l; i++; } while (j < N) { M = M - a[j]; j++; } if (M >= 0) { cout << M; } else { cout << -1; } }
replace
4
5
4
5
0
p02706
C++
Runtime Error
#include <iostream> using namespace std; int a[1000]; int main() { int n, m; cin >> n >> m; int ans = 0; for (int i = 0; i < m; i++) { cin >> a[i]; ans += a[i]; } if (ans > n) { cout << -1; } else { cout << n - ans; } return 0; }
#include <iostream> using namespace std; int a[100000]; int main() { int n, m; cin >> n >> m; int ans = 0; for (int i = 0; i < m; i++) { cin >> a[i]; ans += a[i]; } if (ans > n) { cout << -1; } else { cout << n - ans; } return 0; }
replace
2
3
2
3
0
p02706
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, a, b) for (int i = (a); i < (b); i++) #define per(i, a, b) for (int i = (b)-1; i >= (a); i--) #define pb push_back #define mp make_pair #define bg begin() #define en end() #define all(v) (v).begin(), (v).end() #define sz(v) (int)(v).size() using namespace std; typedef long long ll; static const long long MOD = 1000000007; int ans; int a[10005]; int main(void) { int n, m, sum = 0; cin >> n >> m; rep(i, 0, m) scanf("%d", &a[i]); rep(i, 0, n) sum += a[i]; ans = n - sum; printf("%d\n", ans >= 0 ? ans : -1); return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, a, b) for (int i = (a); i < (b); i++) #define per(i, a, b) for (int i = (b)-1; i >= (a); i--) #define pb push_back #define mp make_pair #define bg begin() #define en end() #define all(v) (v).begin(), (v).end() #define sz(v) (int)(v).size() using namespace std; typedef long long ll; static const long long MOD = 1000000007; int ans; int a[10005]; int main(void) { int n, m, sum = 0; cin >> n >> m; rep(i, 0, m) scanf("%d", &a[i]); rep(i, 0, m) sum += a[i]; ans = n - sum; printf("%d\n", ans >= 0 ? ans : -1); return 0; }
replace
32
33
32
33
0
p02706
C++
Runtime Error
#include <iostream> using namespace std; int main() { int N, M; int A = 0; int day[1000]; cin >> N >> M; for (int i = 0; i < M; i++) { cin >> day[i]; A += day[i]; }; if ((N - A) >= 0) { cout << N - A << endl; } else { cout << -1 << endl; } return 0; }
#include <iostream> using namespace std; int main() { int N, M; int A = 0; int day[10000]; cin >> N >> M; for (int i = 0; i < M; i++) { cin >> day[i]; A += day[i]; }; if ((N - A) >= 0) { cout << N - A << endl; } else { cout << -1 << endl; } return 0; }
replace
5
6
5
6
0