結果

問題 No.2740 Old Maid
ユーザー rotti_coderrotti_coder
提出日時 2024-04-20 10:22:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 613 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 1,114 ms
コンパイル使用メモリ 92,480 KB
実行使用メモリ 33,180 KB
最終ジャッジ日時 2024-04-20 10:22:34
合計ジャッジ時間 15,789 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 358 ms
32,920 KB
testcase_01 AC 373 ms
32,848 KB
testcase_02 AC 334 ms
32,924 KB
testcase_03 AC 354 ms
32,924 KB
testcase_04 AC 393 ms
32,924 KB
testcase_05 AC 362 ms
33,052 KB
testcase_06 AC 351 ms
32,928 KB
testcase_07 AC 373 ms
33,180 KB
testcase_08 AC 360 ms
33,052 KB
testcase_09 AC 357 ms
33,180 KB
testcase_10 AC 364 ms
33,052 KB
testcase_11 AC 298 ms
33,028 KB
testcase_12 AC 366 ms
23,988 KB
testcase_13 AC 440 ms
25,608 KB
testcase_14 AC 63 ms
8,320 KB
testcase_15 AC 88 ms
9,856 KB
testcase_16 AC 289 ms
19,328 KB
testcase_17 AC 57 ms
8,192 KB
testcase_18 AC 416 ms
24,632 KB
testcase_19 AC 155 ms
12,288 KB
testcase_20 AC 440 ms
28,272 KB
testcase_21 AC 67 ms
8,960 KB
testcase_22 AC 247 ms
18,716 KB
testcase_23 AC 41 ms
7,040 KB
testcase_24 AC 116 ms
11,904 KB
testcase_25 AC 511 ms
29,688 KB
testcase_26 AC 5 ms
6,940 KB
testcase_27 AC 26 ms
6,944 KB
testcase_28 AC 267 ms
19,232 KB
testcase_29 AC 245 ms
18,304 KB
testcase_30 AC 9 ms
6,944 KB
testcase_31 AC 613 ms
32,264 KB
testcase_32 AC 153 ms
13,540 KB
testcase_33 AC 545 ms
30,660 KB
testcase_34 AC 247 ms
18,032 KB
testcase_35 AC 117 ms
11,672 KB
testcase_36 AC 131 ms
12,288 KB
testcase_37 AC 188 ms
15,488 KB
testcase_38 AC 114 ms
11,008 KB
testcase_39 AC 52 ms
7,680 KB
testcase_40 AC 359 ms
22,020 KB
testcase_41 AC 463 ms
27,924 KB
testcase_42 AC 1 ms
6,944 KB
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 2 ms
6,940 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,940 KB
testcase_49 AC 1 ms
6,944 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,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 1 ms
6,944 KB
testcase_59 AC 2 ms
6,940 KB
testcase_60 AC 1 ms
6,940 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<iostream>
#include<vector>
#include<map>
#include<set>
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int>p(n);
  for(int i=0;i<n;i++)cin >> p[i];
  map<int,int>dict;
  map<int,int>dict2;
  for(int i=0;i<n-1;i++)dict[p[i]]=p[i+1];
  for(int i=1;i<n;i++)dict2[p[i]]=p[i-1];
  set<int>st;
  int x=p[0],y=p[n-1];
  vector<int>ans;
  for(int i=1;i<=n;i++){
    if(i==y)continue;
    if(st.count(i))continue;
    st.insert(i);
    st.insert(dict[i]);
    ans.emplace_back(i);
    ans.emplace_back(dict[i]);
    if(x!=i && y!=dict[i]){
      dict[dict2[i]]=dict[dict[i]];
      dict2[dict[dict[i]]]=dict2[i];
    }
    else if(x==i && y!=dict[i])x=dict[dict[i]];
    else if(y==dict[i] && x!=i)y=dict2[i];
    else break;
  }
  for(int i=0;i<n;i++)cout << ans[i] << " ";
  cout << endl;
}
0