結果

問題 No.1290 Addition and Subtraction Operation
ユーザー pockynypockyny
提出日時 2020-11-13 22:52:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,113 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 71,496 KB
実行使用メモリ 7,428 KB
最終ジャッジ日時 2023-09-30 03:53:28
合計ジャッジ時間 6,369 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,384 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 WA -
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 WA -
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 41 ms
4,940 KB
testcase_43 AC 41 ms
5,024 KB
testcase_44 AC 41 ms
5,008 KB
testcase_45 AC 41 ms
5,060 KB
testcase_46 AC 41 ms
5,000 KB
testcase_47 AC 41 ms
4,936 KB
testcase_48 AC 41 ms
5,000 KB
testcase_49 AC 41 ms
4,976 KB
testcase_50 AC 41 ms
5,012 KB
testcase_51 AC 41 ms
5,000 KB
testcase_52 AC 41 ms
5,140 KB
testcase_53 AC 41 ms
4,972 KB
testcase_54 AC 41 ms
5,152 KB
testcase_55 AC 41 ms
5,064 KB
testcase_56 AC 41 ms
4,988 KB
testcase_57 AC 33 ms
6,468 KB
testcase_58 AC 42 ms
6,496 KB
testcase_59 AC 31 ms
6,140 KB
testcase_60 AC 70 ms
7,272 KB
testcase_61 AC 57 ms
6,848 KB
testcase_62 AC 60 ms
7,284 KB
testcase_63 AC 41 ms
6,544 KB
testcase_64 AC 20 ms
5,824 KB
testcase_65 AC 26 ms
5,992 KB
testcase_66 AC 48 ms
6,668 KB
testcase_67 AC 73 ms
7,324 KB
testcase_68 AC 58 ms
6,964 KB
testcase_69 AC 41 ms
6,488 KB
testcase_70 AC 38 ms
6,544 KB
testcase_71 AC 46 ms
6,600 KB
testcase_72 AC 27 ms
6,092 KB
testcase_73 AC 53 ms
7,064 KB
testcase_74 AC 20 ms
5,876 KB
testcase_75 AC 24 ms
6,016 KB
testcase_76 AC 39 ms
6,416 KB
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 65 ms
6,908 KB
testcase_83 AC 86 ms
7,236 KB
testcase_84 AC 82 ms
7,108 KB
testcase_85 AC 48 ms
6,116 KB
testcase_86 AC 39 ms
5,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
int par[100010],sz[100010];
long long sz2[100010],b[100010];
bool flag[100010];
void init(int n){
	for(int i=0;i<n;i++) par[i] = i,sz[i] = 1,sz2[i] = b[i],flag[i] = 0;
}

int find(int x){
	if(par[x]==x) return x;
	return par[x] = find(par[x]);
}

void unite(int x, int y, bool f){
	x = find(x); y = find(y);
	if(x==y){
        flag[x] |= f;
        return;
    }
	if(sz[x]>sz[y]) swap(x,y);
	par[x] = y; sz[y] += sz[x]; sz2[y] += sz2[x]; flag[y] |= f;
}

bool same(int x, int y){
	return find(x)==find(y);
}

long long l[100010],r[100010];
int main(){
    int i,n,m; cin >> n >> m;
    for(i=0;i<n;i++) cin >> b[i];
    for(i=0;i<m;i++) cin >> l[i] >> r[i];
    for(i=n;i>0;i--) b[i] += b[i - 1];
    init(n + 1);
    for(i=0;i<m;i++){
        l[i]--; r[i]--;
        bool f = false;
        if(!((r[i] - l[i])&1)) f = true;
        unite(l[i],r[i] + 1,f);
    }
    for(i=0;i<=n;i++){
        if(find(i)!=i) continue;
        if(sz2[par[find(i)]]!=0 && !flag[find(i)]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}
0