結果

問題 No.2740 Old Maid
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2024-04-20 21:43:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 376 ms / 2,000 ms
コード長 2,237 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 175,584 KB
実行使用メモリ 24,192 KB
最終ジャッジ日時 2024-04-20 21:43:46
合計ジャッジ時間 13,101 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 214 ms
23,936 KB
testcase_01 AC 210 ms
24,192 KB
testcase_02 AC 212 ms
23,936 KB
testcase_03 AC 211 ms
24,064 KB
testcase_04 AC 214 ms
24,064 KB
testcase_05 AC 210 ms
23,936 KB
testcase_06 AC 210 ms
24,064 KB
testcase_07 AC 211 ms
24,064 KB
testcase_08 AC 209 ms
24,064 KB
testcase_09 AC 215 ms
24,192 KB
testcase_10 AC 202 ms
23,936 KB
testcase_11 AC 205 ms
24,064 KB
testcase_12 AC 246 ms
18,284 KB
testcase_13 AC 258 ms
19,568 KB
testcase_14 AC 37 ms
7,040 KB
testcase_15 AC 53 ms
8,064 KB
testcase_16 AC 176 ms
14,792 KB
testcase_17 AC 36 ms
6,944 KB
testcase_18 AC 241 ms
18,952 KB
testcase_19 AC 78 ms
10,028 KB
testcase_20 AC 300 ms
21,272 KB
testcase_21 AC 45 ms
7,552 KB
testcase_22 AC 169 ms
14,552 KB
testcase_23 AC 27 ms
6,940 KB
testcase_24 AC 77 ms
9,852 KB
testcase_25 AC 343 ms
22,344 KB
testcase_26 AC 4 ms
6,940 KB
testcase_27 AC 17 ms
6,944 KB
testcase_28 AC 176 ms
14,680 KB
testcase_29 AC 163 ms
14,244 KB
testcase_30 AC 6 ms
6,940 KB
testcase_31 AC 376 ms
24,096 KB
testcase_32 AC 91 ms
10,632 KB
testcase_33 AC 340 ms
23,088 KB
testcase_34 AC 150 ms
13,972 KB
testcase_35 AC 76 ms
9,728 KB
testcase_36 AC 79 ms
9,968 KB
testcase_37 AC 126 ms
12,252 KB
testcase_38 AC 63 ms
8,960 KB
testcase_39 AC 34 ms
6,940 KB
testcase_40 AC 198 ms
16,772 KB
testcase_41 AC 313 ms
21,308 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,940 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,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,948 KB
testcase_58 AC 2 ms
6,944 KB
testcase_59 AC 2 ms
6,944 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>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/



int N, p[201010];

vector<int> q;

int pp[201010];
set<int> restNumbers;
set<pair<int,int>> orders;

bool tryChoice(int mi) {
    auto ite = orders.lower_bound({pp[mi], -1});
    auto miOrder = *ite;
    ite++;
    if (ite == orders.end()) return false;

    auto nextOrder = *ite;

    q.push_back(mi);
    restNumbers.erase(mi);
    orders.erase(miOrder);

    q.push_back(nextOrder.second);
    restNumbers.erase(nextOrder.second);
    orders.erase(nextOrder);

    return true;
}

void _main() {
    cin >> N;
    rep(i, 0, N) cin >> p[i];

    rep(i, 0, N) pp[p[i]] = i;
    rep(i, 0, N) restNumbers.insert(i + 1);
    rep(i, 0, N) orders.insert({i, p[i]});
    
    rep(_i, 0, N / 2) {
        auto ite = restNumbers.begin();
        // the best
        if (tryChoice(*ite)) continue;

        // the 2nd best
        ite++;
        tryChoice(*ite);
    }
    
    rep(i, 0, N) {
        if (i) printf(" ");
        printf("%d", q[i]);
    }
    printf("\n");
}





/*
## 前提知識
## 解法


*/
0