結果

問題 No.2740 Old Maid
ユーザー SyNtAx_error_1SyNtAx_error_1
提出日時 2024-04-21 15:16:17
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 2,748 ms
コンパイル使用メモリ 163,456 KB
実行使用メモリ 15,024 KB
最終ジャッジ日時 2024-04-21 15:16:28
合計ジャッジ時間 10,118 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
14,208 KB
testcase_01 AC 155 ms
14,080 KB
testcase_02 AC 155 ms
14,080 KB
testcase_03 AC 154 ms
14,208 KB
testcase_04 AC 156 ms
14,208 KB
testcase_05 AC 156 ms
14,208 KB
testcase_06 AC 156 ms
14,080 KB
testcase_07 AC 162 ms
14,080 KB
testcase_08 AC 158 ms
14,208 KB
testcase_09 AC 156 ms
14,208 KB
testcase_10 AC 153 ms
14,080 KB
testcase_11 AC 165 ms
14,080 KB
testcase_12 AC 132 ms
12,016 KB
testcase_13 AC 149 ms
12,508 KB
testcase_14 AC 26 ms
5,504 KB
testcase_15 AC 35 ms
5,888 KB
testcase_16 AC 95 ms
9,600 KB
testcase_17 AC 23 ms
5,376 KB
testcase_18 AC 137 ms
12,304 KB
testcase_19 AC 51 ms
6,944 KB
testcase_20 AC 163 ms
13,628 KB
testcase_21 AC 30 ms
5,504 KB
testcase_22 AC 96 ms
9,500 KB
testcase_23 AC 18 ms
5,376 KB
testcase_24 AC 50 ms
6,784 KB
testcase_25 AC 182 ms
14,008 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 12 ms
5,376 KB
testcase_28 AC 97 ms
9,772 KB
testcase_29 AC 91 ms
9,468 KB
testcase_30 AC 5 ms
5,376 KB
testcase_31 AC 198 ms
15,024 KB
testcase_32 AC 58 ms
7,424 KB
testcase_33 AC 190 ms
14,412 KB
testcase_34 AC 86 ms
9,216 KB
testcase_35 AC 47 ms
6,784 KB
testcase_36 AC 51 ms
6,940 KB
testcase_37 AC 69 ms
8,576 KB
testcase_38 AC 41 ms
6,272 KB
testcase_39 AC 22 ms
5,376 KB
testcase_40 AC 113 ms
10,624 KB
testcase_41 AC 155 ms
13,380 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 1 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 1 ms
5,376 KB
testcase_53 AC 1 ms
5,376 KB
testcase_54 AC 1 ms
5,376 KB
testcase_55 AC 1 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 1 ms
5,376 KB
testcase_58 AC 1 ms
5,376 KB
testcase_59 AC 1 ms
5,376 KB
testcase_60 AC 1 ms
5,376 KB
testcase_61 AC 1 ms
5,376 KB
testcase_62 AC 1 ms
5,376 KB
testcase_63 AC 1 ms
5,376 KB
testcase_64 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
constexpr int INF = (1u << 31) - 1;

int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for (auto&& p : P)
    cin >> p, p--;
  // set<int> used;
  vector<int> table(N);
  map<int, int> P2;
  for (int i = 0; i < N; i++)
    P2[i] = P[i];
  for (int i = 0; i < N; i++)
    table[P[i]] = i;
  vector<int> ans;
  for (int i = 0; i < N; i++) {
    // cout << i + 1 << ":start" << endl;
    // for (auto [a, b] : P2)
    //   cout << "[" << a + 1 << "," << b + 1 << "]" << endl;
    // iを使えるなら使う
    // id:=Pのi
    int id = table[i];
    // if (used.contains(id)) continue;
    auto itr = P2.lower_bound(id);
    // if (i == 2) cout << itr->second + 1 << "," << id + 1 << endl;
    if ((*itr).first != id) continue;
    auto itr2 = itr;
    if (++itr2 == P2.end()) continue;
    ans.push_back(itr->second);
    ans.push_back(itr2->second);
    P2.erase(itr);
    P2.erase(P2.upper_bound(id));
  }
  // cout << ans.size() << endl;
  for (int i = 0; i < N; i++) {
    cout << ans[i] + 1 << " \n"[i + 1 == N];
  }
}
0