結果

問題 No.2740 Old Maid
ユーザー rii922
提出日時 2024-04-20 19:04:36
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,720 bytes
コンパイル時間 3,097 ms
コンパイル使用メモリ 258,408 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 16:23:38
合計ジャッジ時間 7,897 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 62
権限があれば一括ダウンロードができます

ソースコード

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