結果

問題 No.1290 Addition and Subtraction Operation
ユーザー fastmathfastmath
提出日時 2020-11-14 17:52:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,508 bytes
コンパイル時間 2,821 ms
コンパイル使用メモリ 202,292 KB
実行使用メモリ 13,120 KB
最終ジャッジ日時 2023-09-30 05:14:48
合計ジャッジ時間 8,064 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,980 KB
testcase_01 AC 4 ms
6,952 KB
testcase_02 AC 3 ms
6,856 KB
testcase_03 AC 4 ms
6,872 KB
testcase_04 AC 3 ms
6,996 KB
testcase_05 AC 4 ms
6,924 KB
testcase_06 AC 4 ms
6,888 KB
testcase_07 AC 3 ms
7,144 KB
testcase_08 AC 3 ms
7,032 KB
testcase_09 AC 3 ms
6,952 KB
testcase_10 AC 4 ms
6,900 KB
testcase_11 AC 4 ms
7,028 KB
testcase_12 AC 4 ms
6,976 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 3 ms
6,920 KB
testcase_15 AC 3 ms
6,876 KB
testcase_16 AC 3 ms
7,096 KB
testcase_17 AC 3 ms
6,872 KB
testcase_18 AC 4 ms
6,968 KB
testcase_19 AC 3 ms
6,892 KB
testcase_20 AC 4 ms
6,948 KB
testcase_21 AC 3 ms
6,864 KB
testcase_22 AC 4 ms
6,928 KB
testcase_23 AC 3 ms
6,920 KB
testcase_24 AC 4 ms
6,900 KB
testcase_25 AC 4 ms
6,872 KB
testcase_26 AC 3 ms
6,868 KB
testcase_27 AC 4 ms
6,928 KB
testcase_28 AC 3 ms
7,092 KB
testcase_29 AC 3 ms
6,872 KB
testcase_30 AC 3 ms
6,864 KB
testcase_31 AC 4 ms
6,888 KB
testcase_32 AC 3 ms
6,900 KB
testcase_33 AC 3 ms
6,900 KB
testcase_34 AC 4 ms
6,900 KB
testcase_35 AC 3 ms
6,896 KB
testcase_36 AC 4 ms
6,900 KB
testcase_37 AC 3 ms
6,988 KB
testcase_38 AC 4 ms
6,872 KB
testcase_39 AC 4 ms
6,876 KB
testcase_40 AC 4 ms
6,860 KB
testcase_41 AC 4 ms
6,924 KB
testcase_42 AC 21 ms
8,604 KB
testcase_43 AC 21 ms
8,608 KB
testcase_44 AC 21 ms
8,604 KB
testcase_45 AC 21 ms
8,608 KB
testcase_46 AC 21 ms
8,600 KB
testcase_47 AC 21 ms
8,560 KB
testcase_48 AC 21 ms
8,696 KB
testcase_49 AC 21 ms
8,612 KB
testcase_50 AC 21 ms
8,604 KB
testcase_51 AC 21 ms
8,580 KB
testcase_52 AC 21 ms
8,684 KB
testcase_53 AC 21 ms
8,560 KB
testcase_54 AC 21 ms
8,680 KB
testcase_55 AC 21 ms
8,576 KB
testcase_56 AC 21 ms
8,684 KB
testcase_57 AC 25 ms
10,188 KB
testcase_58 AC 34 ms
10,828 KB
testcase_59 AC 25 ms
10,040 KB
testcase_60 AC 67 ms
12,992 KB
testcase_61 AC 53 ms
11,744 KB
testcase_62 AC 57 ms
12,048 KB
testcase_63 AC 33 ms
10,784 KB
testcase_64 AC 14 ms
9,144 KB
testcase_65 AC 20 ms
9,628 KB
testcase_66 AC 42 ms
11,132 KB
testcase_67 AC 70 ms
13,120 KB
testcase_68 AC 53 ms
11,956 KB
testcase_69 AC 33 ms
10,860 KB
testcase_70 AC 30 ms
10,516 KB
testcase_71 AC 39 ms
11,088 KB
testcase_72 AC 21 ms
9,716 KB
testcase_73 AC 46 ms
11,468 KB
testcase_74 AC 13 ms
9,040 KB
testcase_75 AC 18 ms
9,428 KB
testcase_76 AC 31 ms
10,692 KB
testcase_77 AC 58 ms
11,972 KB
testcase_78 AC 51 ms
11,536 KB
testcase_79 AC 34 ms
10,452 KB
testcase_80 AC 70 ms
12,788 KB
testcase_81 AC 67 ms
12,748 KB
testcase_82 AC 43 ms
11,108 KB
testcase_83 AC 68 ms
12,868 KB
testcase_84 AC 62 ms
12,452 KB
testcase_85 AC 26 ms
9,876 KB
testcase_86 AC 18 ms
9,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 1e5+7;
vector <int> g[N];
int sum[N], comp[N];
int a[N], d[N];

bool used[N];
void dfs(int u, int c) {
    used[u] = 1;
    comp[u] = c;
    sum[c] += d[u];
    for (int v : g[u]) {
        if (!used[v]) {
            dfs(v, c);
        }   
    }   
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20); 
    #endif
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        if (i % 2 == 0)
            a[i] = -a[i];
        d[i] = a[i] - a[i - 1];

        //debug(d[i]);

    }   

    while (m--) {
        int l, r;
        cin >> l >> r;
        g[r + 1].app(l);
        g[l].app(r + 1);
    }   

    int ptr = 0;
    for (int i = 1; i <= n + 1; ++i) {
        if (!used[i]) {
            dfs(i, ptr);
            ptr++;
        }   
    }   
    for (int i = 0; i < ptr; ++i) {
        if (sum[i] != 0 && comp[n + 1] != i) {
            cout << "NO" << endl;
            exit(0);
        }   
    }   
    cout << "YES" << endl;
}
0