結果

問題 No.2740 Old Maid
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-04-20 13:03:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 451 ms / 2,000 ms
コード長 985 bytes
コンパイル時間 2,824 ms
コンパイル使用メモリ 205,584 KB
実行使用メモリ 24,356 KB
最終ジャッジ日時 2024-04-20 13:03:31
合計ジャッジ時間 14,435 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 209 ms
23,680 KB
testcase_01 AC 203 ms
23,552 KB
testcase_02 AC 205 ms
23,552 KB
testcase_03 AC 209 ms
23,552 KB
testcase_04 AC 207 ms
23,680 KB
testcase_05 AC 206 ms
23,552 KB
testcase_06 AC 204 ms
23,552 KB
testcase_07 AC 215 ms
23,552 KB
testcase_08 AC 205 ms
23,424 KB
testcase_09 AC 206 ms
23,680 KB
testcase_10 AC 198 ms
23,552 KB
testcase_11 AC 195 ms
23,552 KB
testcase_12 AC 326 ms
18,408 KB
testcase_13 AC 332 ms
19,692 KB
testcase_14 AC 44 ms
7,168 KB
testcase_15 AC 65 ms
8,064 KB
testcase_16 AC 220 ms
14,720 KB
testcase_17 AC 41 ms
6,784 KB
testcase_18 AC 332 ms
18,948 KB
testcase_19 AC 99 ms
9,856 KB
testcase_20 AC 423 ms
21,652 KB
testcase_21 AC 52 ms
7,424 KB
testcase_22 AC 215 ms
14,464 KB
testcase_23 AC 32 ms
6,144 KB
testcase_24 AC 91 ms
9,472 KB
testcase_25 AC 436 ms
22,472 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 19 ms
5,376 KB
testcase_28 AC 210 ms
14,812 KB
testcase_29 AC 192 ms
14,248 KB
testcase_30 AC 8 ms
5,376 KB
testcase_31 AC 451 ms
24,356 KB
testcase_32 AC 124 ms
10,880 KB
testcase_33 AC 447 ms
23,216 KB
testcase_34 AC 195 ms
14,080 KB
testcase_35 AC 93 ms
9,600 KB
testcase_36 AC 98 ms
9,728 KB
testcase_37 AC 185 ms
12,288 KB
testcase_38 AC 83 ms
8,832 KB
testcase_39 AC 39 ms
6,912 KB
testcase_40 AC 270 ms
16,640 KB
testcase_41 AC 374 ms
21,176 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 3 ms
5,376 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 2 ms
5,376 KB
testcase_58 AC 2 ms
5,376 KB
testcase_59 AC 2 ms
5,376 KB
testcase_60 AC 2 ms
5,376 KB
testcase_61 AC 2 ms
5,376 KB
testcase_62 AC 2 ms
5,376 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}
int main() {
    fast_io();
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> pinv(n);
    set<pair<int, int>> pi, ip;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
        pinv[p[i]] = i;
        pi.insert({p[i], i});
        ip.insert({i, p[i]});
    }
    vector<int> ans;
    for (int i = 0; i < n / 2; i++) {
        auto it = pi.begin();
        if (*ip.rbegin() == make_pair(it->second, it->first)) {
            it++;
        }
        auto [p1, i1] = *it;
        auto it_ip = ip.find({i1, p1});
        it_ip++;
        auto [i2, p2] = *it_ip;
        ans.push_back(p1 + 1);
        ans.push_back(p2 + 1);
        pi.erase({p1, i1});
        pi.erase({p2, i2});
        ip.erase({i1, p1});
        ip.erase({i2, p2});
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << " \n"[i == n - 1];
    }
}
0