답안 #711771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711771 2023-03-17T13:26:38 Z Luicosas Slagalica (COCI19_slagalica2) C++17
70 / 70
47 ms 8704 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back
#define sz(x) (int)(x.size())
#define itr(x) x.begin(), x.end()
#define prv(x) for(auto& i : x) cout << i << " "; cout << "\n";
#ifdef LOCAL
#define debug(...) cerr << #__VA_ARGS__ << " : "; for(auto& i : {__VA_ARGS__}) cerr << i << " "; cerr << "\n";
#else 
#define debug(...)
#endif

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n;
    cin >> n;

    array<int,2> st, en, o{0, 0};
    vector<vector<array<int,2>>> adj(2);
    for(int i = 0; i < n; i++) {
        int type, val;
        cin >> type >> val;
        if(type == 1) {
            adj[0].pb({val, 1});
            o[0] += 1;
            o[1] -= 1;
        } else if(type == 2) {
            adj[0].pb({val, 0});
        } else if(type == 3) {
            adj[1].pb({val, 1});
        } else if(type == 4) {
            adj[1].pb({val, 0});
            o[1] += 1;
            o[0] -= 1;
        } else if(type == 5) {
            st = {1, val};
        } else if(type == 6) {
            st = {0, val};
        } else if(type == 7) {
            en = {0, val};
        } else if(type == 8) {
            en = {1, val};
        } 
    }

    if(st[0] != en[0] && !(o[st[0]] == 1 && o[en[0]] == -1)) {
        cout << -1 << "\n";
        return 0;
    }
    if(st[0] == en[0] && !(o[0] == 0 && o[1] == 0)) {
        cout << -1 << "\n";
        return 0;
    }

    sort(itr(adj[0]));
    sort(itr(adj[1]));
    vector<int> ans, checked(2, 0);
    function<void(int)> dfs = [&](int idx) {
        if(checked[idx] == sz(adj[idx])) {
            return;
        } 

        while(checked[idx] < sz(adj[idx])) {
            auto& e = adj[idx][checked[idx]]; 
            checked[idx]++;
            dfs(e[1]);
            ans.pb(e[0]);
        }
    };
    dfs(st[0]);

    cout << st[1] << " ";
    for(int i = n - 3; i >= 0; i--) {
        cout << ans[i] << " ";
    }
    cout << en[1] << "\n";
}

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:52:23: warning: 'en.std::array<int, 2>::_M_elems[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |     if(st[0] != en[0] && !(o[st[0]] == 1 && o[en[0]] == -1)) {
slagalica.cpp:52:23: warning: 'st.std::array<int, 2>::_M_elems[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]
slagalica.cpp:82:22: warning: 'en.std::array<int, 2>::_M_elems[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   82 |     cout << en[1] << "\n";
      |                      ^~~~
slagalica.cpp:78:22: warning: 'st.std::array<int, 2>::_M_elems[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   78 |     cout << st[1] << " ";
      |                      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 7716 KB Output is correct
2 Correct 15 ms 1196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 7472 KB Output is correct
2 Correct 13 ms 1252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1232 KB Output is correct
2 Correct 32 ms 7432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1184 KB Output is correct
2 Correct 29 ms 7772 KB Output is correct
3 Correct 47 ms 7120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 5256 KB Output is correct
2 Correct 14 ms 1232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 7908 KB Output is correct
2 Correct 15 ms 1316 KB Output is correct
3 Correct 39 ms 6768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1356 KB Output is correct
2 Correct 34 ms 8500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 8704 KB Output is correct
2 Correct 15 ms 1308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 7368 KB Output is correct
2 Correct 15 ms 1232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 8640 KB Output is correct
2 Correct 14 ms 1232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 7348 KB Output is correct
2 Correct 14 ms 1212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 7428 KB Output is correct
2 Correct 18 ms 1264 KB Output is correct