結果

問題 No.1508 Avoid being hit
ユーザー kotatsugame
提出日時 2021-05-15 06:06:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 161 ms / 3,000 ms
コード長 805 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 67,764 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-02 13:16:51
合計ジャッジ時間 6,267 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
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