結果

問題 No.2740 Old Maid
ユーザー zatsu308zatsu308
提出日時 2024-04-20 13:10:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 2,003 bytes
コンパイル時間 3,780 ms
コンパイル使用メモリ 228,160 KB
実行使用メモリ 15,040 KB
最終ジャッジ日時 2024-04-20 13:11:03
合計ジャッジ時間 12,501 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
14,208 KB
testcase_01 AC 184 ms
14,208 KB
testcase_02 AC 165 ms
14,208 KB
testcase_03 AC 166 ms
14,208 KB
testcase_04 AC 166 ms
14,208 KB
testcase_05 AC 211 ms
14,208 KB
testcase_06 AC 166 ms
14,080 KB
testcase_07 AC 165 ms
14,208 KB
testcase_08 AC 166 ms
14,080 KB
testcase_09 AC 167 ms
14,080 KB
testcase_10 AC 161 ms
14,336 KB
testcase_11 AC 202 ms
14,080 KB
testcase_12 AC 183 ms
11,912 KB
testcase_13 AC 197 ms
12,656 KB
testcase_14 AC 32 ms
5,504 KB
testcase_15 AC 47 ms
6,016 KB
testcase_16 AC 130 ms
9,852 KB
testcase_17 AC 30 ms
5,376 KB
testcase_18 AC 189 ms
12,328 KB
testcase_19 AC 75 ms
6,912 KB
testcase_20 AC 230 ms
13,520 KB
testcase_21 AC 38 ms
5,632 KB
testcase_22 AC 129 ms
9,728 KB
testcase_23 AC 23 ms
5,376 KB
testcase_24 AC 64 ms
6,656 KB
testcase_25 AC 256 ms
14,032 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 15 ms
5,376 KB
testcase_28 AC 131 ms
9,668 KB
testcase_29 AC 138 ms
9,368 KB
testcase_30 AC 6 ms
5,376 KB
testcase_31 AC 277 ms
15,040 KB
testcase_32 AC 77 ms
7,680 KB
testcase_33 AC 255 ms
14,556 KB
testcase_34 AC 118 ms
9,412 KB
testcase_35 AC 59 ms
6,912 KB
testcase_36 AC 67 ms
6,912 KB
testcase_37 AC 110 ms
8,320 KB
testcase_38 AC 53 ms
6,272 KB
testcase_39 AC 27 ms
5,376 KB
testcase_40 AC 164 ms
10,624 KB
testcase_41 AC 229 ms
13,400 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 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 1 ms
5,376 KB
testcase_56 AC 1 ms
5,376 KB
testcase_57 AC 1 ms
5,376 KB
testcase_58 AC 2 ms
5,376 KB
testcase_59 AC 2 ms
5,376 KB
testcase_60 AC 2 ms
5,376 KB
testcase_61 AC 1 ms
5,376 KB
testcase_62 AC 2 ms
5,376 KB
testcase_63 AC 1 ms
5,376 KB
testcase_64 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll mod = 998244353;

template<ll mod>
struct Mint {
  using M=Mint; ll v;
  M& put(ll x) { v=(x<mod)?x:x-mod; return *this; }
  Mint(ll x=0) { put(x%mod+mod); }
  M operator+(M m) {return M().put(v+m.v);}
  M operator-(M m) {return M().put(v+mod-m.v);}
  M operator*(M m) {return M().put(v*m.v%mod);}
  M operator/(M m) {return M().put(v*m.inv().v%mod);}
// BEGIN IGNORE
  M operator+=(M m) { return put(v+m.v); }
  M operator-=(M m) { return put(v+mod-m.v); }
  M operator*=(M m) { return put(v*m.v%mod); }
  M operator/=(M m) { return put(v*m.inv().v%mod); }
// END IGNORE
  bool operator==(M m) { return v==m.v; }
  M pow(ll m) const {
    M x=v, res=1;
    while (m) {
      if (m&1) res=res*x;
      x=x*x; m>>=1;
    }
    return res;
  }
  M inv() { return pow(mod-2); }
};

using mint = Mint<mod>;

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> // for tree
#include<ext/pb_ds/tag_and_trait.hpp> // for tree

using namespace __gnu_pbds;

template <typename T>
using gtree = tree<T, null_type, less<T>, rb_tree_tag,
  tree_order_statistics_node_update>;

int main(){

  cin.tie(0);
  cin.sync_with_stdio(0);

  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; ++i){
    cin >> p[i];
    --p[i];
  }
  vector<int> inv(n);
  for(int i = 0; i < n; ++i){
    inv[p[i]] = i;
  }
  gtree<int> gt;
  for(int i = 0; i < n; ++i){
    gt.insert(i);
  }
  int k = 0;
  vector<int> q;
  for(int iter = 0; iter < n / 2; ++iter){
    while(true){
      int key = inv[k];
      if(gt.find(key) != gt.end() && gt.order_of_key(key) != gt.size() - 1){
        int idx1 = key;
        int idx2 = *gt.find_by_order(gt.order_of_key(key) + 1);
        gt.erase(idx1);
        gt.erase(idx2);
        q.emplace_back(p[idx1]);
        q.emplace_back(p[idx2]);
        break;
      }
      ++k;
    }
  }
  for(int i = 0; i < q.size(); ++i){
    cout << q[i] + 1 << " \n"[i + 1 == q.size()];
  }
}
0