AtCoder Regular Contest 080

Submission #1491823

Source codeソースコード

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
#define INF INT_MAX/2
#define def make_pair(INF,INF)
template<class V, int NV> struct SegTree { //[l,r]
    V comp(V l, V r) { return min(l, r); };
    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int l, int r) { if (l>r)return def;l+=NV;r+=NV+1;V ret=def; while(l<r){
        if(l&1)ret=comp(ret,val[l++]);if(r&1)ret=comp(ret,val[--r]);l/=2;r/= 2;}return ret;}
    void update(int i, V v) { i+=NV;val[i]=v;while(i>1)i>>=1,val[i]=comp(val[i*2],val[i*2+1]); }
    void add(int i, V v) { update(i, val[i + NV] + v); }};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/
 
 
 
 
int N, P[201010];
SegTree<pair<int, int>, 1 << 18> st1, st2;
//---------------------------------------------------------------------------------------------------
vector<int> E[201010];
int PA[201010];
void dfs(int L, int R, int pa = 0) {
    pair<int, int> mi1, mi2;
 
    if (L + 1 == R) {
        E[pa].push_back(P[L]);
        PA[P[L]] = P[R];
        return;
    }
 
    if (L % 2 == 0) {
        mi1 = st1.get(L, R - 1);
        mi2 = st2.get(mi1.second + 1, R);
    } else {
        mi1 = st2.get(L, R - 1);
        mi2 = st1.get(mi1.second + 1, R);
    }
 
    int A = mi1.second;
    int B = mi2.second;
 
    E[pa].push_back(mi1.first);
    PA[mi1.first] = mi2.first;
 
    if (L != A) dfs(L, A - 1, mi1.first);
    if (A + 1 != B) dfs(A + 1, B - 1, mi1.first);
    if (R != B) dfs(B + 1, R, mi1.first);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N; rep(i, 0, N) cin >> P[i];
 
    rep(i, 0, N) {
        if (i % 2 == 0) st1.update(i, { P[i], i });
        else st2.update(i, { P[i], i });
    }
 
    dfs(0, N - 1);
 
    vector<int> ans;
    priority_queue<int> que;
    que.push(-E[0].front());
 
    while (!que.empty()) {
        int q = -que.top(); que.pop();
 
        ans.push_back(q);
        ans.push_back(PA[q]);
 
        fore(i, E[q]) que.push(-i);
    }
 
    rep(i, 0, ans.size()) {
        if (i) printf(" ");
        printf("%d", ans[i]);
    }
    printf("\n");
}

Submission

Task問題 E - Young Maids
User nameユーザ名 はまやんはまやん
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 800
Source lengthソースコード長 3043 Byte
File nameファイル名
Exec time実行時間 113 ms
Memory usageメモリ使用量 52852 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_00.txt,0_01.txt,0_02.txt
All 800 / 800 0_00.txt,0_01.txt,0_02.txt,1_00.txt,1_01.txt,1_02.txt,1_03.txt,1_04.txt,1_05.txt,1_06.txt,1_07.txt,1_08.txt,1_09.txt,1_10.txt,1_11.txt,1_12.txt,1_13.txt,1_14.txt,1_15.txt,1_16.txt,1_17.txt,1_18.txt,1_19.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_00.txt AC 6 ms 13824 KB
0_01.txt AC 6 ms 13824 KB
0_02.txt AC 6 ms 13824 KB
1_00.txt AC 6 ms 13824 KB
1_01.txt AC 6 ms 13824 KB
1_02.txt AC 107 ms 52852 KB
1_03.txt AC 109 ms 52852 KB
1_04.txt AC 113 ms 52852 KB
1_05.txt AC 93 ms 18932 KB
1_06.txt AC 92 ms 19060 KB
1_07.txt AC 93 ms 18548 KB
1_08.txt AC 94 ms 18932 KB
1_09.txt AC 107 ms 52724 KB
1_10.txt AC 110 ms 44400 KB
1_11.txt AC 103 ms 42868 KB
1_12.txt AC 93 ms 18636 KB
1_13.txt AC 94 ms 18804 KB
1_14.txt AC 93 ms 18676 KB
1_15.txt AC 94 ms 18804 KB
1_16.txt AC 97 ms 18804 KB
1_17.txt AC 94 ms 18804 KB
1_18.txt AC 93 ms 18804 KB
1_19.txt AC 93 ms 18804 KB