답안 #380517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380517 2021-03-22T06:45:45 Z Haruto810198 Slagalica (COCI19_slagalica2) C++17
70 / 70
48 ms 10108 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define double long double

#define FOR(i,l,r,d) for(int i=(l);i<=(r);i+=(d))
#define szof(x) ((int)(x).size())

#define vi vector<int>
#define pii pair<int,int>

#define F first
#define S second

#define pb push_back
#define eb emplace_back
#define mkp make_pair

const int INF=2147483647;
const int MOD=1000000007;
const int mod=998244353;
const double eps=1e-12;

int n;
vector<pii> edge[3]; /// <idx,to>
int indeg[3], outdeg[3];

vi res;

/// nodes :
/// 0 : |
/// 1 : <
/// 2 : >

void EulerCircuit(int v){

    while(!edge[v].empty()){ /// for all edges from v :
        pii i = edge[v].back();
        /// remove i
        edge[v].pop_back();
        /// dfs
        EulerCircuit(i.S);
        res.pb(i.F);
    }

}

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    /// input
    cin>>n;
    FOR(i,1,n,1){

        int type, idx;
        cin>>type>>idx;

        if(type==1) edge[1].eb(idx,2);
        if(type==2) edge[1].eb(idx,1);
        if(type==3) edge[2].eb(idx,2);
        if(type==4) edge[2].eb(idx,1);
        if(type==5) edge[0].eb(idx,2);
        if(type==6) edge[0].eb(idx,1);
        if(type==7) edge[1].eb(idx,0);
        if(type==8) edge[2].eb(idx,0);

    }

    /// check if Euler circuit exists
    FOR(i,0,2,1){
        outdeg[i] = szof(edge[i]);
        for(pii j : edge[i]){
            indeg[j.S]++;
        }
    }

    FOR(i,0,2,1){
        if( indeg[i] != outdeg[i] ){
            cout<<-1<<'\n';
            return 0;
        }
    }

    /// sort edges
    FOR(i,0,2,1){
        sort(edge[i].begin(),edge[i].end());
        reverse(edge[i].begin(),edge[i].end());
    }

    /// find lex. smallest Euler circuit
    EulerCircuit(0);

    /// output
    reverse(res.begin(),res.end());
    for(int i : res){
        cout<<i<<" ";
    }
    cout<<'\n';

    return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 8924 KB Output is correct
2 Correct 20 ms 3168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8664 KB Output is correct
2 Correct 20 ms 3184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2268 KB Output is correct
2 Correct 43 ms 8932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2188 KB Output is correct
2 Correct 38 ms 9464 KB Output is correct
3 Correct 46 ms 9304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 6716 KB Output is correct
2 Correct 20 ms 3012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 9700 KB Output is correct
2 Correct 26 ms 2992 KB Output is correct
3 Correct 43 ms 9052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2268 KB Output is correct
2 Correct 39 ms 8728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 10108 KB Output is correct
2 Correct 18 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 8572 KB Output is correct
2 Correct 24 ms 3016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 9944 KB Output is correct
2 Correct 20 ms 3168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 8452 KB Output is correct
2 Correct 21 ms 2984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 8536 KB Output is correct
2 Correct 20 ms 3164 KB Output is correct