結果

問題 No.2740 Old Maid
ユーザー tobbietobbie
提出日時 2024-04-25 19:08:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 562 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 1,965 ms
コンパイル使用メモリ 174,124 KB
実行使用メモリ 22,792 KB
最終ジャッジ日時 2024-04-25 19:08:37
合計ジャッジ時間 18,643 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 266 ms
22,400 KB
testcase_01 AC 269 ms
22,400 KB
testcase_02 AC 267 ms
22,400 KB
testcase_03 AC 269 ms
22,400 KB
testcase_04 AC 272 ms
22,272 KB
testcase_05 AC 293 ms
22,272 KB
testcase_06 AC 265 ms
22,400 KB
testcase_07 AC 269 ms
22,272 KB
testcase_08 AC 269 ms
22,400 KB
testcase_09 AC 292 ms
22,400 KB
testcase_10 AC 258 ms
22,400 KB
testcase_11 AC 273 ms
22,272 KB
testcase_12 AC 332 ms
17,428 KB
testcase_13 AC 416 ms
18,492 KB
testcase_14 AC 56 ms
6,944 KB
testcase_15 AC 79 ms
7,892 KB
testcase_16 AC 250 ms
14,080 KB
testcase_17 AC 53 ms
6,940 KB
testcase_18 AC 386 ms
17,924 KB
testcase_19 AC 119 ms
9,528 KB
testcase_20 AC 448 ms
20,180 KB
testcase_21 AC 64 ms
7,096 KB
testcase_22 AC 237 ms
13,824 KB
testcase_23 AC 37 ms
6,940 KB
testcase_24 AC 111 ms
9,240 KB
testcase_25 AC 479 ms
21,180 KB
testcase_26 AC 5 ms
6,940 KB
testcase_27 AC 24 ms
6,940 KB
testcase_28 AC 241 ms
13,824 KB
testcase_29 AC 234 ms
13,440 KB
testcase_30 AC 9 ms
6,944 KB
testcase_31 AC 562 ms
22,792 KB
testcase_32 AC 140 ms
10,240 KB
testcase_33 AC 513 ms
21,872 KB
testcase_34 AC 229 ms
13,312 KB
testcase_35 AC 106 ms
9,004 KB
testcase_36 AC 116 ms
9,344 KB
testcase_37 AC 176 ms
11,648 KB
testcase_38 AC 95 ms
8,436 KB
testcase_39 AC 47 ms
6,940 KB
testcase_40 AC 336 ms
15,872 KB
testcase_41 AC 442 ms
20,108 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 1 ms
6,944 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 2 ms
6,944 KB
testcase_47 AC 1 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,940 KB
testcase_53 AC 2 ms
6,940 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 1 ms
6,940 KB
testcase_61 AC 2 ms
6,944 KB
testcase_62 AC 2 ms
6,940 KB
testcase_63 AC 2 ms
6,940 KB
testcase_64 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  map<int, int> p;
  map<int, int> m;
  rep(i, N) {
    int pi; cin >> pi;
    p[i] = pi;
    m[pi] = i;
  }
  vector<int> q;
  while ((int)q.size() < N) {
    map<int, int>::iterator it, it2;
    it = m.begin();
    while (1) {
      it2 = p.find(it->second);
      it2++;
      if (it2 != p.end())
	break;
      it++;
    }
    int x = it->second;
    int y = it2->first;
    q.push_back(p[x]);
    q.push_back(p[y]);
    m.erase(p[x]);
    m.erase(p[y]);
    p.erase(x);
    p.erase(y);
  }
  rep(i, N)
    cout << q[i] << " ";
  cout << endl;
  return 0;
}
0