結果

問題 No.2740 Old Maid
ユーザー rii922rii922
提出日時 2024-04-20 19:04:36
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,720 bytes
コンパイル時間 3,588 ms
コンパイル使用メモリ 286,672 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 19:04:45
合計ジャッジ時間 7,918 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
6,816 KB
testcase_01 AC 33 ms
6,944 KB
testcase_02 AC 37 ms
6,940 KB
testcase_03 AC 33 ms
6,940 KB
testcase_04 AC 34 ms
6,940 KB
testcase_05 AC 33 ms
6,944 KB
testcase_06 AC 35 ms
6,940 KB
testcase_07 AC 35 ms
6,944 KB
testcase_08 AC 34 ms
6,940 KB
testcase_09 AC 33 ms
6,944 KB
testcase_10 AC 34 ms
6,940 KB
testcase_11 AC 33 ms
6,940 KB
testcase_12 AC 29 ms
6,940 KB
testcase_13 AC 30 ms
6,940 KB
testcase_14 AC 8 ms
6,940 KB
testcase_15 AC 10 ms
6,940 KB
testcase_16 AC 22 ms
6,944 KB
testcase_17 AC 7 ms
6,944 KB
testcase_18 AC 29 ms
6,940 KB
testcase_19 AC 13 ms
6,944 KB
testcase_20 AC 35 ms
6,940 KB
testcase_21 AC 8 ms
6,944 KB
testcase_22 AC 23 ms
6,940 KB
testcase_23 AC 6 ms
6,944 KB
testcase_24 AC 13 ms
6,944 KB
testcase_25 AC 37 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 5 ms
6,940 KB
testcase_28 AC 22 ms
6,944 KB
testcase_29 AC 20 ms
6,940 KB
testcase_30 AC 3 ms
6,944 KB
testcase_31 AC 41 ms
6,940 KB
testcase_32 AC 14 ms
6,944 KB
testcase_33 AC 40 ms
6,944 KB
testcase_34 AC 21 ms
6,940 KB
testcase_35 AC 12 ms
6,944 KB
testcase_36 AC 12 ms
6,944 KB
testcase_37 AC 17 ms
6,940 KB
testcase_38 AC 11 ms
6,940 KB
testcase_39 AC 6 ms
6,944 KB
testcase_40 AC 27 ms
6,940 KB
testcase_41 AC 34 ms
6,940 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 1 ms
6,940 KB
testcase_46 AC 1 ms
6,944 KB
testcase_47 AC 2 ms
6,944 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 2 ms
6,944 KB
testcase_50 AC 1 ms
6,940 KB
testcase_51 AC 1 ms
6,940 KB
testcase_52 AC 2 ms
6,940 KB
testcase_53 AC 1 ms
6,940 KB
testcase_54 AC 1 ms
6,940 KB
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 1 ms
6,944 KB
testcase_57 AC 2 ms
6,940 KB
testcase_58 AC 1 ms
6,940 KB
testcase_59 AC 1 ms
6,940 KB
testcase_60 AC 1 ms
6,944 KB
testcase_61 AC 1 ms
6,940 KB
testcase_62 AC 2 ms
6,944 KB
testcase_63 AC 1 ms
6,940 KB
testcase_64 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
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 (b<a) { a=b; return 1; } return 0; }
template<class T>bool chmaxeq(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }
template<class T>bool chmineq(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }
bool yes(bool a) { cout << (a?"yes":"no") << endl; return a; }
bool Yes(bool a) { cout << (a?"Yes":"No") << endl; return a; }
bool YES(bool a) { cout << (a?"YES":"NO") << endl; return a; }
void _main();
int main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(16); _main(); return 0; }

void _main() {
	int N; cin >> N;
	vector<pi> ans;
	stack<int> s;
	rep(i, N) {
		int p; cin >> p;
		if (s.empty() || p<s.top()) s.push(p);
		else {
			ans.push_back({s.top(), p});
			s.pop();
		}
	}
	while (!s.empty()) {
		int p1 = s.top();
		s.pop();
		int p2 = s.top();
		s.pop();
		ans.push_back({p2, p1});
	}
	sort(all(ans));
	rep(i, N/2) cout << ans[i].first << ' ' << ans[i].second << (i==N/2-1?'\n':' ');
}
0