답안 #380515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380515 2021-03-22T06:28:25 Z Haruto810198 Slagalica (COCI19_slagalica2) C++17
10 / 70
1000 ms 4392 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;

set<int> vis; /// visited edges

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

vi res;

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

void EulerCircuit(int v){

    for(pii i : edge[v]){ /// for all edges from v :
        if( vis.find(i.F) == vis.end() ){ /// if i is not visited
            /// mark i as visited
            vis.insert(i.F);
            /// 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());
    }

    /// 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 364 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 Execution timed out 1091 ms 3808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1088 ms 3744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 3288 KB Output is correct
2 Execution timed out 1082 ms 3780 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3228 KB Output is correct
2 Execution timed out 1096 ms 3556 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1096 ms 3892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1085 ms 3812 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 3164 KB Output is correct
2 Execution timed out 1082 ms 4120 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 4392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1041 ms 3888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1043 ms 4184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1095 ms 3844 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1085 ms 3712 KB Time limit exceeded
2 Halted 0 ms 0 KB -