結果

問題 No.1055 牛歩
ユーザー 沙耶花沙耶花
提出日時 2020-05-15 22:52:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,546 bytes
コンパイル時間 3,506 ms
コンパイル使用メモリ 208,068 KB
実行使用メモリ 5,120 KB
最終ジャッジ日時 2023-10-19 16:02:00
合計ジャッジ時間 5,546 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
5,120 KB
testcase_01 AC 26 ms
4,592 KB
testcase_02 AC 21 ms
4,348 KB
testcase_03 AC 21 ms
4,348 KB
testcase_04 AC 21 ms
4,348 KB
testcase_05 WA -
testcase_06 AC 23 ms
4,348 KB
testcase_07 AC 23 ms
4,348 KB
testcase_08 AC 23 ms
4,348 KB
testcase_09 AC 19 ms
4,348 KB
testcase_10 AC 20 ms
4,348 KB
testcase_11 AC 20 ms
4,348 KB
testcase_12 AC 18 ms
4,348 KB
testcase_13 AC 17 ms
4,348 KB
testcase_14 AC 19 ms
4,348 KB
testcase_15 AC 19 ms
4,348 KB
testcase_16 AC 15 ms
4,348 KB
testcase_17 WA -
testcase_18 AC 16 ms
4,348 KB
testcase_19 WA -
testcase_20 AC 20 ms
4,348 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 21 ms
4,348 KB
testcase_24 AC 21 ms
4,348 KB
testcase_25 AC 19 ms
4,348 KB
testcase_26 AC 21 ms
4,348 KB
testcase_27 AC 22 ms
4,348 KB
testcase_28 AC 21 ms
4,348 KB
testcase_29 AC 18 ms
4,348 KB
testcase_30 AC 22 ms
4,348 KB
testcase_31 AC 6 ms
4,348 KB
testcase_32 AC 5 ms
4,348 KB
testcase_33 AC 6 ms
4,348 KB
testcase_34 AC 5 ms
4,348 KB
testcase_35 AC 5 ms
4,348 KB
testcase_36 AC 5 ms
4,348 KB
testcase_37 AC 5 ms
4,348 KB
testcase_38 AC 5 ms
4,348 KB
testcase_39 AC 2 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 3 ms
4,348 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 3 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 3 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 2 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 2 ms
4,348 KB
testcase_61 AC 2 ms
4,348 KB
testcase_62 AC 2 ms
4,348 KB
testcase_63 AC 2 ms
4,348 KB
testcase_64 AC 2 ms
4,348 KB
testcase_65 AC 2 ms
4,348 KB
testcase_66 AC 2 ms
4,348 KB
testcase_67 AC 2 ms
4,348 KB
testcase_68 AC 2 ms
4,348 KB
testcase_69 AC 2 ms
4,348 KB
testcase_70 AC 2 ms
4,348 KB
testcase_71 AC 2 ms
4,348 KB
testcase_72 WA -
testcase_73 AC 2 ms
4,348 KB
testcase_74 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000


int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<int> A(M);
	for(int i=0;i<M;i++)scanf("%d",&A[i]);
	
	vector<int> X(M);
	for(int i=0;i<M;i++){
		if(i==0)X[i] = A[i];
		else X[i] = A[i]-A[i-1];
	}
	X.push_back(N+1 - A.back());
	
	int Q;
	cin>>Q;
	vector<int> B(Q);
	for(int i=0;i<Q;i++){
		scanf("%d",&B[i]);
		B[i]--;
	}
	
	vector<bool> bridge(N,false);
	
	for(int i=0;i<Q;i++){
		if(bridge[B[i]]){
			bridge[B[i]]=false;
		}
		if((B[i]!=0&&bridge[B[i]-1])||(B[i]!=N-1&&bridge[B[i]+1])){
			int pre = B[i]-1;
			int nxt = B[i]+1;
			if(X[B[i]]==2&&X[B[i]+1]==2){
				bridge[B[i]]=true;
				continue;
			}
			
			if(X[B[i]]>X[B[i]+1]){
				X[B[i]]--;
				X[B[i]+1]++;
			}
			else{
				X[B[i]]++;
				X[B[i]+1]--;
			}
			
			while(pre>=0&&bridge[pre]){
				if(X[pre]>X[pre+1]){
					X[pre]--;
					X[pre+1]++;
				}
				else{
					X[pre]++;
					X[pre+1]--;
				}
				bridge[pre]=false;
			}
			
			while(nxt<N&&bridge[nxt]){
				if(X[nxt]>X[nxt+1]){
					X[nxt]--;
					X[nxt+1]++;
				}
				else{
					X[nxt]++;
					X[nxt+1]--;
				}
				bridge[nxt]=false;
			}
			
		}
		else{
			if(X[B[i]]==1&&X[B[i]+1]==1){
				cout<<"NO"<<endl;
				return 0;
			}
			if(X[B[i]]==2&&X[B[i]+1]==2){
				bridge[B[i]]=true;
			}
			else{
				if(X[B[i]]>X[B[i]+1]){
					X[B[i]]--;
					X[B[i]+1]++;
				}
				else{
					X[B[i]]++;
					X[B[i]+1]--;
				}
			}
		}
	}
	
	cout<<"YES"<<endl;
	
	return 0;
}
0