結果

問題 No.2740 Old Maid
ユーザー Ryoga.exeRyoga.exe
提出日時 2024-04-21 02:08:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 564 ms / 2,000 ms
コード長 906 bytes
コンパイル時間 3,208 ms
コンパイル使用メモリ 206,008 KB
実行使用メモリ 17,968 KB
最終ジャッジ日時 2024-04-21 02:09:19
合計ジャッジ時間 15,793 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 269 ms
17,840 KB
testcase_01 AC 292 ms
17,716 KB
testcase_02 AC 269 ms
17,720 KB
testcase_03 AC 271 ms
17,716 KB
testcase_04 AC 269 ms
17,720 KB
testcase_05 AC 283 ms
17,712 KB
testcase_06 AC 270 ms
17,716 KB
testcase_07 AC 269 ms
17,716 KB
testcase_08 AC 270 ms
17,844 KB
testcase_09 AC 284 ms
17,720 KB
testcase_10 AC 265 ms
17,720 KB
testcase_11 AC 258 ms
17,968 KB
testcase_12 AC 379 ms
13,640 KB
testcase_13 AC 394 ms
14,400 KB
testcase_14 AC 49 ms
6,940 KB
testcase_15 AC 73 ms
6,944 KB
testcase_16 AC 236 ms
11,008 KB
testcase_17 AC 46 ms
6,940 KB
testcase_18 AC 389 ms
14,120 KB
testcase_19 AC 107 ms
7,680 KB
testcase_20 AC 426 ms
15,720 KB
testcase_21 AC 56 ms
6,940 KB
testcase_22 AC 225 ms
10,880 KB
testcase_23 AC 32 ms
6,940 KB
testcase_24 AC 136 ms
7,428 KB
testcase_25 AC 466 ms
16,208 KB
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 20 ms
6,940 KB
testcase_28 AC 236 ms
11,136 KB
testcase_29 AC 217 ms
10,752 KB
testcase_30 AC 8 ms
6,940 KB
testcase_31 AC 564 ms
17,444 KB
testcase_32 AC 121 ms
8,576 KB
testcase_33 AC 500 ms
16,696 KB
testcase_34 AC 252 ms
10,624 KB
testcase_35 AC 101 ms
7,552 KB
testcase_36 AC 106 ms
7,680 KB
testcase_37 AC 171 ms
9,344 KB
testcase_38 AC 84 ms
7,168 KB
testcase_39 AC 42 ms
6,944 KB
testcase_40 AC 299 ms
12,288 KB
testcase_41 AC 458 ms
15,448 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 2 ms
6,940 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 2 ms
6,940 KB
testcase_52 AC 2 ms
6,940 KB
testcase_53 AC 2 ms
6,944 KB
testcase_54 AC 2 ms
6,944 KB
testcase_55 AC 2 ms
6,940 KB
testcase_56 AC 2 ms
6,940 KB
testcase_57 AC 2 ms
6,944 KB
testcase_58 AC 2 ms
6,940 KB
testcase_59 AC 2 ms
6,944 KB
testcase_60 AC 2 ms
6,940 KB
testcase_61 AC 2 ms
6,940 KB
testcase_62 AC 2 ms
6,940 KB
testcase_63 AC 2 ms
6,940 KB
testcase_64 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    map<int, pair<int, int>> mp;
    for (auto &e : p) {
        cin >> e;
        mp[e] = {-1, -1};
    }
    for (int i = 0; i < n; i++) {
        if (i - 1 >= 0) {
            mp[p[i]].first = p[i - 1];
        }
        if (i + 1 < n) {
            mp[p[i]].second = p[i + 1];
        }
    }
    vector<int> ans;
    for (int i = 1; i <= n; i++) {
        const auto [prv, nxt] = mp[i];
        if (nxt == -1) {
            continue;
        }
        ans.push_back(i);
        ans.push_back(nxt);
        cout << i << " " << nxt << " ";
        auto &[nprv, nnxt] = mp[nxt];
        if (prv != -1) {
            mp[prv].second = nnxt;
        }
        if (nnxt != -1) {
            mp[nnxt].first = prv;
        }
        nprv = -1;
        nnxt = -1;
    }
    cout << endl;
    return 0;
}
0