結果

問題 No.2740 Old Maid
ユーザー shobonvipshobonvip
提出日時 2024-04-21 00:29:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 364 ms / 2,000 ms
コード長 1,688 bytes
コンパイル時間 4,335 ms
コンパイル使用メモリ 258,740 KB
実行使用メモリ 24,200 KB
最終ジャッジ日時 2024-04-21 00:29:57
合計ジャッジ時間 15,545 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 245 ms
23,424 KB
testcase_01 AC 246 ms
23,680 KB
testcase_02 AC 272 ms
23,552 KB
testcase_03 AC 251 ms
23,552 KB
testcase_04 AC 252 ms
23,552 KB
testcase_05 AC 250 ms
23,424 KB
testcase_06 AC 264 ms
23,680 KB
testcase_07 AC 242 ms
23,424 KB
testcase_08 AC 248 ms
23,552 KB
testcase_09 AC 251 ms
23,552 KB
testcase_10 AC 232 ms
23,552 KB
testcase_11 AC 221 ms
23,552 KB
testcase_12 AC 259 ms
17,876 KB
testcase_13 AC 252 ms
19,540 KB
testcase_14 AC 42 ms
6,784 KB
testcase_15 AC 60 ms
7,680 KB
testcase_16 AC 172 ms
14,720 KB
testcase_17 AC 40 ms
6,656 KB
testcase_18 AC 251 ms
18,408 KB
testcase_19 AC 88 ms
9,472 KB
testcase_20 AC 307 ms
21,372 KB
testcase_21 AC 47 ms
6,964 KB
testcase_22 AC 162 ms
14,336 KB
testcase_23 AC 30 ms
5,888 KB
testcase_24 AC 81 ms
9,344 KB
testcase_25 AC 340 ms
22,316 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 20 ms
5,376 KB
testcase_28 AC 169 ms
14,592 KB
testcase_29 AC 154 ms
14,208 KB
testcase_30 AC 8 ms
5,376 KB
testcase_31 AC 362 ms
24,200 KB
testcase_32 AC 97 ms
10,240 KB
testcase_33 AC 364 ms
22,932 KB
testcase_34 AC 156 ms
13,440 KB
testcase_35 AC 86 ms
9,088 KB
testcase_36 AC 85 ms
9,472 KB
testcase_37 AC 127 ms
12,160 KB
testcase_38 AC 70 ms
8,448 KB
testcase_39 AC 35 ms
6,144 KB
testcase_40 AC 200 ms
16,512 KB
testcase_41 AC 300 ms
21,160 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
testcase_54 AC 1 ms
5,376 KB
testcase_55 AC 1 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 2 ms
5,376 KB
testcase_58 AC 2 ms
5,376 KB
testcase_59 AC 2 ms
5,376 KB
testcase_60 AC 2 ms
5,376 KB
testcase_61 AC 2 ms
5,376 KB
testcase_62 AC 2 ms
5,376 KB
testcase_63 AC 1 ms
5,376 KB
testcase_64 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}



int main(){
	int n; cin >> n;
	vector<int> p(n),r(n);
	rep(i,0,n){
		cin >> p[i];
		p[i]--;
		r[p[i]] = i;
	} 
	set<int> alive;
	rep(i,0,n){
		alive.insert(i);
	}
	set<int> pr;
	rep(i,0,n) pr.insert(i);

	vector<int> q(0);
	rep(i,0,n/2){
		auto itr_pr = alive.begin();

		auto itr = pr.find(r[*itr_pr]);
		itr++;
		if (itr == pr.end()){
			itr_pr++;
			itr = pr.find(r[*itr_pr]);
		}else{
			itr--;
		}

		int tar1 = *itr;
		itr++;
		int tar2 = *itr;

		alive.erase(p[tar1]);
		alive.erase(p[tar2]);
		pr.erase(tar1);
		pr.erase(tar2);
		q.push_back(p[tar1]);
		q.push_back(p[tar2]);
	}
	rep(i,0,n){
		cout << q[i] + 1 << ' ';
	}
	cout << '\n';
}

0