結果

問題 No.2740 Old Maid
ユーザー Series_205Series_205
提出日時 2024-04-20 16:46:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 404 ms / 2,000 ms
コード長 1,772 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 211,988 KB
実行使用メモリ 23,688 KB
最終ジャッジ日時 2024-04-20 16:46:38
合計ジャッジ時間 14,277 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 224 ms
23,040 KB
testcase_01 AC 219 ms
22,912 KB
testcase_02 AC 218 ms
22,912 KB
testcase_03 AC 219 ms
22,912 KB
testcase_04 AC 218 ms
22,784 KB
testcase_05 AC 222 ms
23,040 KB
testcase_06 AC 218 ms
22,912 KB
testcase_07 AC 218 ms
23,040 KB
testcase_08 AC 222 ms
22,784 KB
testcase_09 AC 225 ms
22,912 KB
testcase_10 AC 208 ms
22,784 KB
testcase_11 AC 218 ms
22,784 KB
testcase_12 AC 280 ms
18,100 KB
testcase_13 AC 286 ms
19,084 KB
testcase_14 AC 44 ms
6,940 KB
testcase_15 AC 62 ms
8,192 KB
testcase_16 AC 193 ms
14,464 KB
testcase_17 AC 41 ms
6,940 KB
testcase_18 AC 287 ms
18,612 KB
testcase_19 AC 90 ms
9,600 KB
testcase_20 AC 313 ms
20,968 KB
testcase_21 AC 51 ms
7,220 KB
testcase_22 AC 179 ms
14,080 KB
testcase_23 AC 31 ms
6,940 KB
testcase_24 AC 87 ms
9,344 KB
testcase_25 AC 375 ms
21,752 KB
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 20 ms
6,940 KB
testcase_28 AC 181 ms
14,336 KB
testcase_29 AC 167 ms
13,824 KB
testcase_30 AC 7 ms
6,940 KB
testcase_31 AC 404 ms
23,688 KB
testcase_32 AC 103 ms
10,624 KB
testcase_33 AC 380 ms
22,724 KB
testcase_34 AC 171 ms
13,568 KB
testcase_35 AC 86 ms
9,472 KB
testcase_36 AC 88 ms
9,472 KB
testcase_37 AC 132 ms
12,028 KB
testcase_38 AC 74 ms
8,576 KB
testcase_39 AC 37 ms
6,944 KB
testcase_40 AC 239 ms
16,256 KB
testcase_41 AC 368 ms
20,628 KB
testcase_42 AC 1 ms
6,940 KB
testcase_43 AC 2 ms
6,944 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 2 ms
6,944 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,940 KB
testcase_51 AC 3 ms
6,940 KB
testcase_52 AC 2 ms
6,940 KB
testcase_53 AC 2 ms
6,940 KB
testcase_54 AC 2 ms
6,940 KB
testcase_55 AC 2 ms
6,944 KB
testcase_56 AC 2 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,940 KB
testcase_60 AC 2 ms
6,944 KB
testcase_61 AC 2 ms
6,940 KB
testcase_62 AC 2 ms
6,944 KB
testcase_63 AC 2 ms
6,944 KB
testcase_64 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, n) FOR(i, 0, n)
#define FORR(i, l, r) for(ll i = r - 1; i >= l; i--)
#define ALL(ar) begin(ar), end(ar)

template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for(T &x : v) is >> x;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for(size_t i = 0; i < v.size(); i++) os << (i ? " " : "") << v[i];
    return os;
}
//-------------------------------------------------

void solve() {
    int n;
    cin >> n;
    vector<int> p(n);
    cin >> p;
    set<int> st;
    map<int, int> pos;
    rep(i, n) st.insert(i);
    rep(i, n) {
        p[i]--;
        pos[p[i]] = i;
    }

    vector<int> q;
    rep(i, n / 2) {
        auto mn = pos.begin();
        auto nxt = st.upper_bound(mn->second);
        if(nxt == st.end()) {
            mn++;
            nxt = st.upper_bound(mn->second);
        }

        q.push_back(mn->first + 1);
        q.push_back(p[*nxt] + 1);
        pos.erase(p[*nxt]);
        st.erase(nxt);
        st.erase(mn->second);
        pos.erase(mn);
    }

    cout << q << endl;
}

int main() {
    int t = 1;
    // cin >> t;
    while(t--) solve();
}
0