結果
問題 | No.1290 Addition and Subtraction Operation |
ユーザー | kyort0n |
提出日時 | 2020-11-13 18:40:06 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,076 bytes |
コンパイル時間 | 2,326 ms |
コンパイル使用メモリ | 179,496 KB |
実行使用メモリ | 14,408 KB |
最終ジャッジ日時 | 2024-07-22 20:16:43 |
合計ジャッジ時間 | 5,798 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
7,392 KB |
testcase_01 | AC | 3 ms
6,944 KB |
testcase_02 | AC | 3 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 3 ms
6,948 KB |
testcase_09 | AC | 3 ms
6,940 KB |
testcase_10 | AC | 3 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 3 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 3 ms
7,772 KB |
testcase_16 | AC | 3 ms
6,944 KB |
testcase_17 | WA | - |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 3 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | WA | - |
testcase_25 | AC | 3 ms
6,940 KB |
testcase_26 | AC | 3 ms
6,944 KB |
testcase_27 | AC | 3 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 3 ms
7,648 KB |
testcase_30 | AC | 3 ms
6,940 KB |
testcase_31 | AC | 3 ms
7,524 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 3 ms
6,940 KB |
testcase_34 | WA | - |
testcase_35 | AC | 3 ms
6,940 KB |
testcase_36 | AC | 2 ms
6,944 KB |
testcase_37 | AC | 3 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,944 KB |
testcase_39 | AC | 2 ms
6,940 KB |
testcase_40 | WA | - |
testcase_41 | AC | 2 ms
6,944 KB |
testcase_42 | AC | 16 ms
6,944 KB |
testcase_43 | AC | 16 ms
6,940 KB |
testcase_44 | AC | 17 ms
7,660 KB |
testcase_45 | AC | 17 ms
6,948 KB |
testcase_46 | AC | 17 ms
6,940 KB |
testcase_47 | AC | 17 ms
6,940 KB |
testcase_48 | AC | 17 ms
6,940 KB |
testcase_49 | AC | 16 ms
6,940 KB |
testcase_50 | AC | 17 ms
7,660 KB |
testcase_51 | AC | 17 ms
6,944 KB |
testcase_52 | AC | 17 ms
7,660 KB |
testcase_53 | AC | 17 ms
7,660 KB |
testcase_54 | AC | 17 ms
6,944 KB |
testcase_55 | AC | 17 ms
6,944 KB |
testcase_56 | AC | 16 ms
6,940 KB |
testcase_57 | AC | 24 ms
14,120 KB |
testcase_58 | AC | 29 ms
14,328 KB |
testcase_59 | AC | 26 ms
13,988 KB |
testcase_60 | AC | 41 ms
14,252 KB |
testcase_61 | AC | 36 ms
14,124 KB |
testcase_62 | AC | 38 ms
14,328 KB |
testcase_63 | AC | 30 ms
14,248 KB |
testcase_64 | AC | 20 ms
13,864 KB |
testcase_65 | AC | 22 ms
14,332 KB |
testcase_66 | AC | 32 ms
13,996 KB |
testcase_67 | AC | 43 ms
14,328 KB |
testcase_68 | AC | 36 ms
14,324 KB |
testcase_69 | AC | 28 ms
14,340 KB |
testcase_70 | AC | 28 ms
13,988 KB |
testcase_71 | AC | 33 ms
13,736 KB |
testcase_72 | AC | 23 ms
14,072 KB |
testcase_73 | AC | 33 ms
14,120 KB |
testcase_74 | AC | 19 ms
14,248 KB |
testcase_75 | AC | 21 ms
14,328 KB |
testcase_76 | AC | 28 ms
14,184 KB |
testcase_77 | WA | - |
testcase_78 | WA | - |
testcase_79 | WA | - |
testcase_80 | WA | - |
testcase_81 | WA | - |
testcase_82 | AC | 35 ms
14,324 KB |
testcase_83 | AC | 44 ms
14,324 KB |
testcase_84 | AC | 42 ms
14,120 KB |
testcase_85 | AC | 27 ms
14,328 KB |
testcase_86 | AC | 21 ms
14,116 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } const long long INF = 1e18; //const ll mod = 1000000007; ll N, M; ll B[100500]; ll C[100500]; ll L[105000], R[105000]; struct UnionFind { vector<int> par; vector<int> rank; vector<ll> Size; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1); for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1; } int root(int x) { if (par[x] == x) { return x; } else { int r = root(par[x]); return par[x] = r; } } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (rank[x] < rank[y]) swap(x, y); if (rank[x] == rank[y]) ++rank[x]; par[y] = x; Size[x] += Size[y]; return true; } ll size(int x){ return Size[root(x)]; } }; ll sum[105000]; ll subsum[105000]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; for(int i = 1; i <= N; i++) cin >> B[i]; for(int i = 0; i <= N; i++) { C[i] = B[i] + B[i+1]; } N++; UnionFind vertex(N); for(int i = 0; i < M; i++) { cin >> L[i] >> R[i]; L[i]--; if((R[i] - L[i]) % 2 == 0) { //vertex.merge(L[i], R[i]); } } UnionFind bipartite(2 * N), connected(N); for(int i = 0; i < M; i++) { if((R[i] - L[i]) % 2 == 1) { ll a = vertex.root(L[i]); ll b = vertex.root(R[i]); bipartite.merge(a + N, b); bipartite.merge(a, b + N); connected.merge(a, b); } } for(int i = 0; i < N; i++) { sum[connected.root(vertex.root(i))] += C[i]; if(bipartite.issame(vertex.root(i), connected.root(vertex.root(i)))) subsum[connected.root(vertex.root(i))] += C[i]; } /* for(int i = 0; i < N; i++) { if(vertex.root(i) == i) cerr << i << " "; } cerr << endl; */ string ans = "YES"; for(int i = 0; i < N; i++) { if(vertex.root(i) != i) continue; if(connected.root(i) != i) continue; //cerr << i << " " << sum[i] << " " << subsum[i] << " " << bipartite.issame(i, i + N) << endl; if(bipartite.issame(i, i + N)) { if(abs(sum[i]) % 2 != 0) { //cerr << i << endl; ans = "NO"; } } else { if(subsum[i] * 2 != sum[i]) { //cerr << i << endl; ans = "NO"; } } } cout << ans << endl; return 0; }