Submission #711771

#TimeUsernameProblemLanguageResultExecution timeMemory
711771LuicosasSlagalica (COCI19_slagalica2)C++17
70 / 70
47 ms8704 KiB
#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 (stderr)

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] << " ";
      |                      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...