結果
問題 | No.1290 Addition and Subtraction Operation |
ユーザー | Mister |
提出日時 | 2020-11-30 09:06:59 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 2,594 bytes |
コンパイル時間 | 1,198 ms |
コンパイル使用メモリ | 89,736 KB |
実行使用メモリ | 11,376 KB |
最終ジャッジ日時 | 2024-09-13 02:14:58 |
合計ジャッジ時間 | 6,220 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 2 ms
6,944 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,944 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 2 ms
6,940 KB |
testcase_34 | AC | 2 ms
6,944 KB |
testcase_35 | AC | 2 ms
6,944 KB |
testcase_36 | AC | 2 ms
6,940 KB |
testcase_37 | AC | 2 ms
6,944 KB |
testcase_38 | AC | 2 ms
6,940 KB |
testcase_39 | AC | 2 ms
6,940 KB |
testcase_40 | AC | 2 ms
6,944 KB |
testcase_41 | AC | 2 ms
6,940 KB |
testcase_42 | AC | 16 ms
6,944 KB |
testcase_43 | AC | 16 ms
6,940 KB |
testcase_44 | AC | 16 ms
6,944 KB |
testcase_45 | AC | 16 ms
6,944 KB |
testcase_46 | AC | 16 ms
6,944 KB |
testcase_47 | AC | 16 ms
6,944 KB |
testcase_48 | AC | 16 ms
6,940 KB |
testcase_49 | AC | 16 ms
6,940 KB |
testcase_50 | AC | 16 ms
6,940 KB |
testcase_51 | AC | 16 ms
6,940 KB |
testcase_52 | AC | 17 ms
6,944 KB |
testcase_53 | AC | 16 ms
6,940 KB |
testcase_54 | AC | 16 ms
6,940 KB |
testcase_55 | AC | 16 ms
6,940 KB |
testcase_56 | AC | 16 ms
6,944 KB |
testcase_57 | AC | 25 ms
10,732 KB |
testcase_58 | AC | 27 ms
10,228 KB |
testcase_59 | AC | 25 ms
10,740 KB |
testcase_60 | AC | 35 ms
9,200 KB |
testcase_61 | AC | 31 ms
9,520 KB |
testcase_62 | AC | 32 ms
9,460 KB |
testcase_63 | AC | 28 ms
10,224 KB |
testcase_64 | AC | 21 ms
11,376 KB |
testcase_65 | AC | 23 ms
10,996 KB |
testcase_66 | AC | 30 ms
9,812 KB |
testcase_67 | AC | 36 ms
9,200 KB |
testcase_68 | AC | 33 ms
9,580 KB |
testcase_69 | AC | 28 ms
10,224 KB |
testcase_70 | AC | 26 ms
10,352 KB |
testcase_71 | AC | 29 ms
9,964 KB |
testcase_72 | AC | 24 ms
10,992 KB |
testcase_73 | AC | 30 ms
9,720 KB |
testcase_74 | AC | 20 ms
11,372 KB |
testcase_75 | AC | 22 ms
10,996 KB |
testcase_76 | AC | 26 ms
10,340 KB |
testcase_77 | AC | 37 ms
9,328 KB |
testcase_78 | AC | 36 ms
9,712 KB |
testcase_79 | AC | 31 ms
10,476 KB |
testcase_80 | AC | 39 ms
9,076 KB |
testcase_81 | AC | 38 ms
9,140 KB |
testcase_82 | AC | 31 ms
9,780 KB |
testcase_83 | AC | 37 ms
9,256 KB |
testcase_84 | AC | 36 ms
9,328 KB |
testcase_85 | AC | 27 ms
10,868 KB |
testcase_86 | AC | 24 ms
11,376 KB |
ソースコード
#line 1 "combined.cpp" #include <algorithm> #include <cassert> #include <vector> namespace atcoder { struct dsu { public: dsu() : _n(0) {} dsu(int n) : _n(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } private: int _n; std::vector<int> parent_or_size; }; } // namespace atcoder #include <iostream> #line 70 "combined.cpp" using namespace std; using lint = long long; void solve() { int n, m; cin >> n >> m; vector<lint> xs(n); for (auto& x : xs) cin >> x; xs.insert(xs.begin(), 0); xs.push_back(0); for (int i = 0; i <= n; i += 2) { xs[i] = -xs[i]; } vector<lint> ds(n + 1); for (int i = 0; i <= n; ++i) { ds[i] = xs[i + 1] - xs[i]; } atcoder::dsu uf(n + 1); while (m--) { int l, r; cin >> l >> r; uf.merge(--l, r); } for (auto g : uf.groups()) { lint sum = 0; for (auto v : g) sum += ds[v]; if (sum != 0) { cout << "NO\n"; return; } } cout << "YES\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }