結果

問題 No.953 席
ユーザー %20%20
提出日時 2019-12-14 16:25:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,261 bytes
コンパイル時間 2,585 ms
コンパイル使用メモリ 215,624 KB
実行使用メモリ 9,380 KB
最終ジャッジ日時 2023-09-15 15:25:59
合計ジャッジ時間 5,853 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 51 ms
4,380 KB
testcase_03 AC 49 ms
4,376 KB
testcase_04 AC 50 ms
4,376 KB
testcase_05 AC 45 ms
4,376 KB
testcase_06 AC 50 ms
4,380 KB
testcase_07 AC 64 ms
8,680 KB
testcase_08 AC 70 ms
7,164 KB
testcase_09 AC 67 ms
9,380 KB
testcase_10 AC 20 ms
5,344 KB
testcase_11 AC 55 ms
6,192 KB
testcase_12 AC 60 ms
5,620 KB
testcase_13 AC 72 ms
6,984 KB
testcase_14 AC 59 ms
5,172 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,376 KB
testcase_24 WA -
testcase_25 AC 77 ms
7,016 KB
testcase_26 AC 38 ms
4,380 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+1),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