結果
| 問題 |
No.2740 Old Maid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-20 10:39:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 2,000 ms |
| コード長 | 1,069 bytes |
| コンパイル時間 | 2,050 ms |
| コンパイル使用メモリ | 200,048 KB |
| 最終ジャッジ日時 | 2025-02-21 06:10:22 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 62 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N; cin >> N;
vector<bool> already(N);
vector<int> P(N),rev(N),answer,fro(N,-1),bac(N,-1);
for(int i=0; i<N; i++){
int p; cin >> p; p--;
rev.at(p) = i; P.at(i) = p;
}
for(int i=1; i<N; i++) bac.at(i) = i-1;
for(int i=0; i<N-1; i++) fro.at(i) = i+1;
for(int i=0; i<N; i++){
if(already.at(i)) continue;
int pos = rev.at(i);
if(fro.at(pos) == -1) continue;
answer.push_back(P.at(pos));
answer.push_back(P.at(fro.at(pos)));
already.at(P.at(pos)) = true;
already.at(P.at(fro.at(pos))) = true;
int one = bac.at(pos),two = pos,three = fro.at(pos),four = fro.at(fro.at(pos));
if(one == -1 && four == -1){}
else if(one == -1){bac.at(four) = -1;}
else if(four == -1){fro.at(one) = -1;}
else{bac.at(four) = one; fro.at(one) = four;}
}
for(auto &a : answer) cout << a+1 << " "; cout << endl;
}