結果

問題 No.953 席
ユーザー %20%20
提出日時 2019-12-16 03:52:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,261 bytes
コンパイル時間 2,358 ms
コンパイル使用メモリ 214,992 KB
実行使用メモリ 9,304 KB
最終ジャッジ日時 2023-09-15 16:45:02
合計ジャッジ時間 6,689 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 51 ms
4,380 KB
testcase_03 AC 49 ms
4,384 KB
testcase_04 AC 50 ms
4,380 KB
testcase_05 AC 45 ms
4,380 KB
testcase_06 AC 50 ms
4,380 KB
testcase_07 AC 64 ms
8,728 KB
testcase_08 AC 71 ms
7,244 KB
testcase_09 AC 66 ms
9,304 KB
testcase_10 AC 20 ms
5,168 KB
testcase_11 AC 54 ms
6,216 KB
testcase_12 AC 60 ms
5,692 KB
testcase_13 AC 73 ms
7,008 KB
testcase_14 AC 59 ms
5,316 KB
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 AC 54 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 77 ms
7,076 KB
testcase_26 AC 39 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

using ll=long long;
using pli=pair<ll,int>;

int main(){cin.tie(0);ios::sync_with_stdio(false);
	int N,K1,K2;cin>>N>>K1>>K2;
	vector<int>f(N+2),g(3*N);
	for(int i=1;i<=N;++i){
		int t=2*abs(i-K1)+abs(i-K2);
		f[i]=t;
		g[t]=i;
	}
	set<int>good,bad;
	for(int i=1;i<=N;++i){
		good.insert(f[i]);
	}
	vector<bool>v(N+1);
	int Q;cin>>Q;
	priority_queue<pli,vector<pli>,greater<pli>>pq;
	for(int _=0;_<Q;++_){
		ll A,B;cin>>A>>B;
		redo:
		while(pq.size()&&pq.top().first<=A){
			int k=pq.top().second;pq.pop();
			v[k]=false;
			if((k-1<1||!v[k-1])&&(k+1>N||!v[k+1])){
				good.insert(f[k]);
			}else{
				bad.insert(f[k]);
			}
			if(k>1&&!v[k-1]&&(k-2<1||!v[k-2])){
				bad.erase(f[k-1]);
				good.insert(f[k-1]);
			}
			if(k<N&&!v[k+1]&&(k+2>N||!v[k+2])){
				bad.erase(f[k+1]);
				good.insert(f[k+1]);
			}
		}
		int k;
		if(good.size()){
			k=*good.begin();
			good.erase(k);
		}else if(bad.size()){
			k=*bad.begin();
			bad.erase(k);
		}else{
			A=pq.top().first;
			goto redo;
		}
		k=g[k];
		cout<<k<<"\n";
		pq.push({A+B,k});
		v[k]=true;
		if(good.count(f[k-1])){
			good.erase(f[k-1]);
			bad.insert(f[k-1]);
		}
		if(good.count(f[k+1])){
			good.erase(f[k+1]);
			bad.insert(f[k+1]);
		}
	}
	return 0;
}
0