結果

問題 No.953 席
ユーザー 👑 kmjpkmjp
提出日時 2019-12-16 00:24:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,991 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 179,608 KB
実行使用メモリ 11,628 KB
最終ジャッジ日時 2023-09-15 15:56:11
合計ジャッジ時間 10,300 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 396 ms
10,948 KB
testcase_08 AC 431 ms
11,292 KB
testcase_09 AC 342 ms
10,780 KB
testcase_10 AC 108 ms
5,892 KB
testcase_11 AC 304 ms
9,380 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 432 ms
11,628 KB
testcase_26 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void solve()’ 内:
main.cpp:56:50: 警告: ‘x’ may be used uninitialized [-Wmaybe-uninitialized]
   56 |                         if(K2+i<=N) order[K2+i]=x++;
      |                                                 ~^~
main.cpp:44:23: 備考: ‘x’ はここで定義されています
   44 |         int i,j,k,l,r,x,y; string s;
      |                       ^

ソースコード

diff #

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

#undef _P
#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 ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K1,K2,M;
int order[101010];
int X[101010],Y[101010];

set<pair<int,int>> A;
set<pair<int,int>> B;
set<pair<int,int>> ev;
int ret[101010];

void fix(int x) {
	if(x<1 || x>N) return;
	if(A.count({order[x],x})==0 && B.count({order[x],x})==0) return;
	int nei=0;
	if(x>1&&A.count({order[x-1],x-1})==0 && B.count({order[x-1],x-1})==0) nei++;
	if(x<N&&A.count({order[x+1],x+1})==0 && B.count({order[x+1],x+1})==0) nei++;
	
	if(nei==0) {
		B.erase({order[x],x});
		A.insert({order[x],x});
	}
	else {
		A.erase({order[x],x});
		B.insert({order[x],x});
	}
	
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K1>>K2;
	if(K1<K2) {
		x=0;
		FOR(i,N) {
			if(K1-i>=1) order[K1-i]=x++;
			if(K2+i<=N) order[K2+i]=x++;
		}
	}
	else {
		FOR(i,N) {
			if(K2+i<=N) order[K2+i]=x++;
			if(K1-i>=1) order[K1-i]=x++;
		}
	}
	
	FOR(i,N) A.insert({order[i+1],i+1});
	cin>>M;
	FOR(i,M) {
		cin>>X[i]>>Y[i];
		ev.insert({X[i],M+i});
	}
	
	queue<int> Q;
	int pret=-1;
	while(ev.size()) {
		auto p=*ev.begin();
		ev.erase(ev.begin());
		
		if(pret<p.first) {
			while(Q.size() && (A.size()+B.size())) {
				x=Q.front();
				if(A.size()) {
					auto p2=*A.begin();
					A.erase(A.begin());
					ret[x]=p2.second;
					//cerr<<"!"<<p.first<<" "<<x<<" "<<ret[x]<<endl;
					ev.insert({p.first+Y[x],x});
					fix(ret[x]-1);
					fix(ret[x]+1);
					Q.pop();
				}
				else if(B.size()) {
					auto p2=*B.begin();
					B.erase(B.begin());
					ret[x]=p2.second;
					//cerr<<p.first<<" "<<x<<" "<<ret[x]<<endl;
					ev.insert({p.first+Y[x],x});
					fix(ret[x]-1);
					fix(ret[x]+1);
					Q.pop();
				}
			}
		}
		pret=p.first;
		
		if(p.second<M) {
			x=p.second;
			//cerr<<"#"<<ret[x]<<endl;
			B.insert({order[ret[x]],ret[x]});
			fix(ret[x]);
			fix(ret[x]-1);
			fix(ret[x]+1);
			
		}
		else {
			x=p.second-M;
			if(A.size()) {
				auto p2=*A.begin();
				A.erase(A.begin());
				ret[x]=p2.second;
					//cerr<<"!"<<p.first<<" "<<x<<" "<<ret[x]<<endl;
				ev.insert({p.first+Y[x],x});
				fix(ret[x]-1);
				fix(ret[x]+1);
			}
			else if(B.size()) {
				auto p2=*B.begin();
				B.erase(B.begin());
				ret[x]=p2.second;
					//cerr<<p.first<<" "<<x<<" "<<ret[x]<<endl;
				ev.insert({p.first+Y[x],x});
				fix(ret[x]-1);
				fix(ret[x]+1);
			}
			else {
				Q.push(x);
			}
		}
		
	}
	
	
	FOR(i,M) cout<<ret[i]<<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