結果

問題 No.2740 Old Maid
ユーザー mealymealy
提出日時 2024-04-21 13:36:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,758 bytes
コンパイル時間 5,623 ms
コンパイル使用メモリ 336,356 KB
実行使用メモリ 7,692 KB
最終ジャッジ日時 2024-04-21 13:36:51
合計ジャッジ時間 10,875 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
7,532 KB
testcase_01 AC 78 ms
7,604 KB
testcase_02 AC 77 ms
7,692 KB
testcase_03 AC 77 ms
7,564 KB
testcase_04 AC 74 ms
7,564 KB
testcase_05 AC 80 ms
7,564 KB
testcase_06 AC 76 ms
7,692 KB
testcase_07 AC 75 ms
7,692 KB
testcase_08 AC 77 ms
7,564 KB
testcase_09 AC 78 ms
7,688 KB
testcase_10 AC 75 ms
7,688 KB
testcase_11 AC 78 ms
7,692 KB
testcase_12 AC 54 ms
6,600 KB
testcase_13 AC 56 ms
6,912 KB
testcase_14 AC 14 ms
5,376 KB
testcase_15 AC 17 ms
5,376 KB
testcase_16 AC 41 ms
5,504 KB
testcase_17 AC 12 ms
5,376 KB
testcase_18 AC 55 ms
6,680 KB
testcase_19 AC 23 ms
5,376 KB
testcase_20 AC 64 ms
7,064 KB
testcase_21 AC 15 ms
5,376 KB
testcase_22 AC 38 ms
5,504 KB
testcase_23 AC 10 ms
5,376 KB
testcase_24 AC 22 ms
5,376 KB
testcase_25 AC 75 ms
7,136 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 7 ms
5,376 KB
testcase_28 AC 40 ms
5,504 KB
testcase_29 AC 36 ms
5,632 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 74 ms
7,504 KB
testcase_32 AC 25 ms
5,376 KB
testcase_33 AC 71 ms
7,324 KB
testcase_34 AC 37 ms
5,504 KB
testcase_35 AC 21 ms
5,376 KB
testcase_36 AC 23 ms
5,376 KB
testcase_37 AC 32 ms
5,376 KB
testcase_38 AC 21 ms
5,376 KB
testcase_39 AC 12 ms
5,376 KB
testcase_40 AC 47 ms
5,888 KB
testcase_41 AC 63 ms
7,164 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 1 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 1 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 1 ms
5,376 KB
testcase_57 AC 2 ms
5,376 KB
testcase_58 AC 1 ms
5,376 KB
testcase_59 AC 1 ms
5,376 KB
testcase_60 AC 2 ms
5,376 KB
testcase_61 AC 2 ms
5,376 KB
testcase_62 AC 2 ms
5,376 KB
testcase_63 AC 2 ms
5,376 KB
testcase_64 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using mint = atcoder::modint998244353;
//using mint = atcoder::modint1000000007;
using namespace atcoder;
using namespace std;

using ll = long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vi = vector<int>;
using vm = vector<mint>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vpi = vector<pair<int,int>>;
using vpl = vector<pair<ll,ll>>;
#define rep(i,n) for (ll i = 0; i < n; i++)
#define replr(i,l,r) for (ll i = l; i < r; i++)
set<char> abc = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
const int inf =1e9;
const ll infl = 4e18;

template <typename T>
bool chmax(T &a, const T& b) {if (a < b) {a = b;  return true;}return false;}
template <typename T>
bool chmin(T &a, const T& b) {if (a > b) {a = b;  return true;}return false;}
template <typename T>
T max(vector<T> &v) {T m = 0;for (auto x : v) chmax(m, x);return m;}
template <typename T>
T min(vector<T> &v) {T m = inf;for (auto x : v) chmin(m, x);return m;}
template <typename T>
void print(vector<T> &v){for(auto x : v){cout<<x<<' ';}cout<<'\n';}
/*memo
一番若いものを選び続ける
*/


int main(){
    int N; cin >> N;
    vi p(N);rep(i,N) cin >> p[i];
    vi pos(N);
    vi nex(N,-1);
    vi pre(N,-1);
    rep(i,N-1) nex[i] =i+1;
    replr(i,1,N) pre[i] = i-1;
    rep(i,N) pos[p[i]-1] = i;
    vi q;
    rep(i,N){
        int x=pos[i];
        if (p[x]==-1) continue;
        if (nex[x]==-1) continue;
        q.push_back(p[x]);
        q.push_back(p[nex[x]]);
        if (pre[x]!=-1) nex[pre[x]]=nex[nex[x]];
        if (nex[nex[x]]!=-1) pre[nex[nex[x]]]=pre[x];
        p[x]=-1;
        p[nex[x]]=-1;
    }
    print(q);
}
0