結果
問題 | No.1290 Addition and Subtraction Operation |
ユーザー | satashun |
提出日時 | 2020-11-14 13:58:17 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 96 ms / 2,000 ms |
コード長 | 2,798 bytes |
コンパイル時間 | 2,492 ms |
コンパイル使用メモリ | 211,232 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-07-22 22:54:17 |
合計ジャッジ時間 | 7,778 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 0 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 1 ms
5,376 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 1 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 1 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 1 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 2 ms
5,376 KB |
testcase_40 | AC | 1 ms
5,376 KB |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | AC | 40 ms
5,376 KB |
testcase_43 | AC | 41 ms
5,376 KB |
testcase_44 | AC | 40 ms
5,376 KB |
testcase_45 | AC | 41 ms
5,376 KB |
testcase_46 | AC | 39 ms
5,376 KB |
testcase_47 | AC | 39 ms
5,376 KB |
testcase_48 | AC | 41 ms
5,376 KB |
testcase_49 | AC | 39 ms
5,376 KB |
testcase_50 | AC | 39 ms
5,376 KB |
testcase_51 | AC | 40 ms
5,376 KB |
testcase_52 | AC | 41 ms
5,376 KB |
testcase_53 | AC | 41 ms
5,376 KB |
testcase_54 | AC | 41 ms
5,376 KB |
testcase_55 | AC | 41 ms
5,376 KB |
testcase_56 | AC | 40 ms
5,376 KB |
testcase_57 | AC | 57 ms
9,472 KB |
testcase_58 | AC | 66 ms
8,448 KB |
testcase_59 | AC | 54 ms
9,600 KB |
testcase_60 | AC | 81 ms
6,144 KB |
testcase_61 | AC | 70 ms
7,040 KB |
testcase_62 | AC | 73 ms
6,656 KB |
testcase_63 | AC | 64 ms
8,576 KB |
testcase_64 | AC | 46 ms
10,880 KB |
testcase_65 | AC | 47 ms
10,368 KB |
testcase_66 | AC | 67 ms
7,680 KB |
testcase_67 | AC | 78 ms
5,888 KB |
testcase_68 | AC | 71 ms
6,784 KB |
testcase_69 | AC | 64 ms
8,448 KB |
testcase_70 | AC | 61 ms
8,832 KB |
testcase_71 | AC | 68 ms
7,936 KB |
testcase_72 | AC | 50 ms
10,112 KB |
testcase_73 | AC | 67 ms
7,296 KB |
testcase_74 | AC | 45 ms
11,008 KB |
testcase_75 | AC | 46 ms
10,496 KB |
testcase_76 | AC | 61 ms
8,704 KB |
testcase_77 | AC | 88 ms
6,656 KB |
testcase_78 | AC | 85 ms
7,168 KB |
testcase_79 | AC | 78 ms
9,088 KB |
testcase_80 | AC | 94 ms
6,016 KB |
testcase_81 | AC | 96 ms
6,272 KB |
testcase_82 | AC | 88 ms
7,936 KB |
testcase_83 | AC | 92 ms
6,272 KB |
testcase_84 | AC | 90 ms
6,400 KB |
testcase_85 | AC | 71 ms
9,856 KB |
testcase_86 | AC | 64 ms
10,880 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() #define SZ(x) ((int)(x).size()) constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T &t, const U &u) { if (t > u) t = u; } template <class T, class U> void chmax(T &t, const U &u) { if (t < u) t = u; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif class unionfind { vector<int> par, rank; public: void init(int n) { par.resize(n); rank.resize(n); for (int i = 0; i < n; i++) { par[i] = i; rank[i] = 0; } } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) par[x] = y; else { par[y] = x; if (rank[x] == rank[y]) ++rank[x]; } } bool same(int x, int y) { return (find(x) == find(y)); } }; int main() { int N, M; cin >> N >> M; V<int> B(N + 2), D(N + 2); rep(i, N) { int x; cin >> x; if (i & 1) x = -x; B[i + 1] = x; } for (int i = 0; i <= N; ++i) { D[i] = B[i + 1] - B[i]; } unionfind uf; uf.init(N + 1); rep(i, M) { int l, r; cin >> l >> r; --l; uf.unite(l, r); } map<int, ll> sum; rep(i, N + 1) sum[uf.find(i)] += D[i]; bool ok = 1; for (auto &p : sum) if (p.se) ok = 0; cout << (ok ? "YES" : "NO") << endl; return 0; }