結果

問題 No.2740 Old Maid
ユーザー ponjuiceponjuice
提出日時 2024-04-17 23:08:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 205 ms / 2,000 ms
コード長 726 bytes
コンパイル時間 2,564 ms
コンパイル使用メモリ 203,416 KB
実行使用メモリ 15,144 KB
最終ジャッジ日時 2024-04-17 23:08:58
合計ジャッジ時間 12,613 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 179 ms
14,208 KB
testcase_01 AC 155 ms
14,464 KB
testcase_02 AC 154 ms
14,208 KB
testcase_03 AC 153 ms
14,208 KB
testcase_04 AC 154 ms
14,208 KB
testcase_05 AC 154 ms
14,208 KB
testcase_06 AC 157 ms
14,336 KB
testcase_07 AC 153 ms
14,208 KB
testcase_08 AC 151 ms
14,208 KB
testcase_09 AC 151 ms
14,208 KB
testcase_10 AC 151 ms
14,208 KB
testcase_11 AC 156 ms
14,336 KB
testcase_12 AC 163 ms
12,140 KB
testcase_13 AC 149 ms
12,636 KB
testcase_14 AC 27 ms
6,944 KB
testcase_15 AC 38 ms
6,940 KB
testcase_16 AC 103 ms
9,856 KB
testcase_17 AC 26 ms
6,944 KB
testcase_18 AC 150 ms
12,308 KB
testcase_19 AC 55 ms
6,940 KB
testcase_20 AC 182 ms
13,624 KB
testcase_21 AC 31 ms
6,944 KB
testcase_22 AC 113 ms
9,728 KB
testcase_23 AC 20 ms
6,940 KB
testcase_24 AC 50 ms
6,944 KB
testcase_25 AC 190 ms
14,260 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 13 ms
6,944 KB
testcase_28 AC 107 ms
9,728 KB
testcase_29 AC 97 ms
9,344 KB
testcase_30 AC 5 ms
6,944 KB
testcase_31 AC 205 ms
15,144 KB
testcase_32 AC 61 ms
7,552 KB
testcase_33 AC 190 ms
14,664 KB
testcase_34 AC 93 ms
9,344 KB
testcase_35 AC 50 ms
6,944 KB
testcase_36 AC 56 ms
7,040 KB
testcase_37 AC 75 ms
8,576 KB
testcase_38 AC 45 ms
6,944 KB
testcase_39 AC 23 ms
6,940 KB
testcase_40 AC 122 ms
10,752 KB
testcase_41 AC 168 ms
13,632 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 2 ms
6,944 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 1 ms
6,940 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 1 ms
6,944 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 2 ms
6,944 KB
testcase_52 AC 2 ms
6,944 KB
testcase_53 AC 2 ms
6,944 KB
testcase_54 AC 1 ms
6,940 KB
testcase_55 AC 2 ms
6,944 KB
testcase_56 AC 1 ms
6,944 KB
testcase_57 AC 2 ms
6,944 KB
testcase_58 AC 2 ms
6,944 KB
testcase_59 AC 2 ms
6,944 KB
testcase_60 AC 2 ms
6,940 KB
testcase_61 AC 2 ms
6,944 KB
testcase_62 AC 2 ms
6,940 KB
testcase_63 AC 2 ms
6,940 KB
testcase_64 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> r(n, 1);
    set<int> ex;
    for(int i = 0; i < n; i++) {
        cin >> p[i]; p[i]--;
        ex.insert(i);
        r[p[i]] = i;
    }

    vector<int> ans;

    for(int i = 0; i < n; i++){
        if(r[i] >= 0){
            auto itr = ex.upper_bound(r[i]);
            if(itr == ex.end()) continue;

            ans.emplace_back(i + 1);
            ans.emplace_back(p[*itr] + 1);

            r[p[*itr]] = -1;
            ex.erase(itr);
            
            ex.erase(r[i]);
            r[i] = -1;
        }
    }

    for(int i = 0; i < n; i++){
        cout << ans[i] << " \n"[i == n-1];
    }
}
0