結果

問題 No.1508 Avoid being hit
ユーザー kotatsugamekotatsugame
提出日時 2021-05-15 06:06:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 3,000 ms
コード長 805 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 68,148 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 11:18:06
合計ジャッジ時間 5,962 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 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,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 40 ms
6,944 KB
testcase_17 AC 23 ms
6,940 KB
testcase_18 AC 21 ms
6,944 KB
testcase_19 AC 33 ms
6,940 KB
testcase_20 AC 53 ms
6,940 KB
testcase_21 AC 35 ms
6,940 KB
testcase_22 AC 44 ms
6,944 KB
testcase_23 AC 48 ms
6,944 KB
testcase_24 AC 162 ms
6,940 KB
testcase_25 AC 145 ms
6,948 KB
testcase_26 AC 12 ms
6,940 KB
testcase_27 AC 76 ms
6,940 KB
testcase_28 AC 76 ms
6,944 KB
testcase_29 AC 149 ms
6,944 KB
testcase_30 AC 80 ms
6,944 KB
testcase_31 AC 130 ms
6,940 KB
testcase_32 AC 139 ms
6,940 KB
testcase_33 AC 39 ms
6,944 KB
testcase_34 AC 131 ms
6,944 KB
testcase_35 AC 15 ms
6,944 KB
testcase_36 AC 76 ms
6,940 KB
testcase_37 AC 35 ms
6,944 KB
testcase_38 AC 107 ms
6,940 KB
testcase_39 AC 70 ms
6,940 KB
testcase_40 AC 138 ms
6,944 KB
testcase_41 AC 84 ms
6,944 KB
testcase_42 AC 141 ms
6,940 KB
testcase_43 AC 165 ms
6,940 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
int N,Q;
int A[1<<17],B[1<<17];
int L[1<<17],R[1<<17];
main()
{
	cin>>N>>Q;
	for(int i=0;i<Q;i++)cin>>A[i];
	for(int i=0;i<Q;i++)cin>>B[i];
	L[Q]=0,R[Q]=N+1;
	for(int i=Q;i--;)
	{
		if(A[i]>B[i])swap(A[i],B[i]);
		int l=L[i+1]-1,r=R[i+1]+1;
		if(l<0)l=0;
		if(r>N+1)r=N+1;
		if(A[i]==l+1||B[i]==l+1)
		{
			l++;
			if(A[i]==l&&B[i]==l+1)l++;
		}
		if(A[i]==r-1||B[i]==r-1)
		{
			r--;
			if(A[i]==r-1&&B[i]==r)r--;
		}
		if(l+1>=r)
		{
			cout<<"NO"<<endl;
			return 0;
		}
		L[i]=l;
		R[i]=r;
	}
	cout<<"YES"<<endl;
	int pos=L[0]+1;
	cout<<pos<<endl;
	for(int i=0;i<Q;i++)
	{
		if(pos<=L[i])pos++;
		else if(pos>=R[i])pos--;
		else if(pos==A[i]||pos==B[i])
		{
			pos--;
			if(pos<=L[i]||pos==A[i]||pos==B[i])pos+=2;
		}
		cout<<pos<<endl;
	}
}
0