結果

問題 No.1290 Addition and Subtraction Operation
ユーザー pockynypockyny
提出日時 2020-11-13 23:04:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,249 bytes
コンパイル時間 588 ms
コンパイル使用メモリ 70,052 KB
実行使用メモリ 7,340 KB
最終ジャッジ日時 2023-09-30 04:01:45
合計ジャッジ時間 5,176 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,500 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 WA -
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 WA -
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,384 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 35 ms
5,024 KB
testcase_43 AC 38 ms
4,932 KB
testcase_44 AC 35 ms
4,956 KB
testcase_45 AC 35 ms
4,916 KB
testcase_46 AC 35 ms
4,916 KB
testcase_47 AC 35 ms
4,888 KB
testcase_48 AC 36 ms
4,912 KB
testcase_49 AC 35 ms
5,008 KB
testcase_50 AC 36 ms
4,900 KB
testcase_51 AC 36 ms
4,896 KB
testcase_52 AC 36 ms
5,176 KB
testcase_53 AC 40 ms
4,884 KB
testcase_54 AC 39 ms
5,172 KB
testcase_55 AC 35 ms
5,140 KB
testcase_56 AC 36 ms
4,956 KB
testcase_57 AC 28 ms
6,140 KB
testcase_58 AC 35 ms
6,396 KB
testcase_59 AC 27 ms
6,344 KB
testcase_60 AC 61 ms
7,340 KB
testcase_61 AC 51 ms
6,808 KB
testcase_62 AC 57 ms
7,180 KB
testcase_63 AC 38 ms
6,412 KB
testcase_64 AC 18 ms
6,068 KB
testcase_65 AC 23 ms
5,948 KB
testcase_66 AC 44 ms
6,728 KB
testcase_67 AC 67 ms
7,316 KB
testcase_68 AC 54 ms
6,844 KB
testcase_69 AC 38 ms
6,396 KB
testcase_70 AC 36 ms
6,356 KB
testcase_71 AC 42 ms
6,644 KB
testcase_72 AC 24 ms
6,036 KB
testcase_73 AC 47 ms
6,704 KB
testcase_74 AC 17 ms
5,872 KB
testcase_75 AC 21 ms
5,928 KB
testcase_76 AC 35 ms
6,360 KB
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 AC 58 ms
6,532 KB
testcase_83 AC 78 ms
7,168 KB
testcase_84 AC 73 ms
6,996 KB
testcase_85 AC 40 ms
6,104 KB
testcase_86 AC 34 ms
5,944 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] = false;
}

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[find(i)]==0) continue;
        if(!flag[find(i)]){
            cout << "NO" << endl;
            return 0;
        }
        if((sz2[find(i)] + 10000000000000000) & 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}
0