結果

問題 No.1508 Avoid being hit
ユーザー 👑 kmjpkmjp
提出日時 2021-05-15 00:27:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 3,000 ms
コード長 2,076 bytes
コンパイル時間 2,342 ms
コンパイル使用メモリ 206,200 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-10 05:43:15
合計ジャッジ時間 7,251 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
9,292 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 4 ms
6,944 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 26 ms
8,104 KB
testcase_17 AC 16 ms
7,072 KB
testcase_18 AC 16 ms
7,224 KB
testcase_19 AC 22 ms
7,680 KB
testcase_20 AC 39 ms
9,216 KB
testcase_21 AC 26 ms
7,932 KB
testcase_22 AC 31 ms
8,448 KB
testcase_23 AC 34 ms
8,940 KB
testcase_24 AC 167 ms
10,584 KB
testcase_25 AC 159 ms
10,200 KB
testcase_26 AC 14 ms
6,940 KB
testcase_27 AC 79 ms
7,964 KB
testcase_28 AC 81 ms
8,112 KB
testcase_29 AC 157 ms
10,368 KB
testcase_30 AC 85 ms
8,588 KB
testcase_31 AC 137 ms
9,680 KB
testcase_32 AC 146 ms
10,084 KB
testcase_33 AC 42 ms
7,440 KB
testcase_34 AC 124 ms
10,120 KB
testcase_35 AC 15 ms
6,940 KB
testcase_36 AC 70 ms
8,316 KB
testcase_37 AC 34 ms
7,168 KB
testcase_38 AC 101 ms
9,232 KB
testcase_39 AC 67 ms
8,128 KB
testcase_40 AC 128 ms
10,112 KB
testcase_41 AC 75 ms
8,448 KB
testcase_42 AC 132 ms
10,240 KB
testcase_43 AC 155 ms
10,752 KB
testcase_44 AC 3 ms
6,944 KB
testcase_45 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,Q;
int A[101010],B[101010];

vector<pair<int,int>> R[101010];

int ok(int v,vector<pair<int,int>> R) {
	FORR2(a,b,R) if(a<=v&&v<=b) return 1;
	return 0;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	FOR(i,Q) cin>>A[i];
	FOR(i,Q) cin>>B[i];
	R[0]={{1,N}};
	FOR(i,Q) {
		vector<pair<int,int>> V,W;
		
		FORR(p,R[i]) {
			auto r=p;
			r.first=max(1,r.first-1);
			r.second=min(N,r.second+1);
			if(V.size()&&V.back().second+1>=r.first) {
				V.back().second=r.second;
			}
			else V.push_back(r);
		}
		FORR(r,V) {
			if(r.first<=A[i]&&A[i]<=r.second) {
				W.push_back({r.first,A[i]-1});
				W.push_back({A[i]+1,r.second});
			}
			else {
				W.push_back(r);
			}
		}
		V.clear();
		FORR(r,W) {
			if(r.first<=B[i]&&B[i]<=r.second) {
				V.push_back({r.first,B[i]-1});
				V.push_back({B[i]+1,r.second});
			}
			else {
				V.push_back(r);
			}
		}
		FORR(r,V) {
			if(r.first<=r.second) R[i+1].push_back(r);
		}
		
	}
	
	if(R[Q].empty()) {
		cout<<"NO"<<endl;
	}
	else {
		int cur=R[Q][0].first;
		vector<int> ret;
		ret.push_back(cur);
		for(i=Q-1;i>=0;i--) {
			for(x=max(1,cur-1);x<=min(N,cur+1);x++) if(ok(x,R[i])) {
				cur=x;
				break;
			}
			ret.push_back(cur);
		}
		reverse(ALL(ret));
		cout<<"YES"<<endl;
		FORR(r,ret) cout<<r<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0