Submission #444696

#TimeUsernameProblemLanguageResultExecution timeMemory
444696penguinhackerSlagalica (COCI19_slagalica2)C++14
70 / 70
50 ms3032 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=1e5; int n; ar<int, 2> a[mxN], first, last; priority_queue<int, vector<int>, greater<int>> same[2], dif[2]; bool ck(int sub, int at) { if (sub!=-1&&dif[sub].empty()) return 0; int d[2]={(int)dif[0].size(), (int)dif[1].size()}; if (sub!=-1) --d[sub]; if (!d[0]&&!d[1]&&same[at^1].size()) return 0; if (at!=last[1]) { if (!d[at]) return 0; --d[at]; at^=1; } return d[0]==d[1]; } void init() { cin >> n; for (int i=0; i<n; ++i) { int t, a; cin >> t >> a; if (t==1) dif[1].push(a); else if (t==2) same[1].push(a); else if (t==3) same[0].push(a); else if (t==4) dif[0].push(a); else if (t==5||t==6) { if (first[0]) { cout << -1; exit(0); } first={a, t==6}; } else { if (last[0]) { cout << -1; exit(0); } last={a, t==7}; } } if (!first[0]||!last[0]||!ck(-1, first[1])) { cout << -1; exit(0); } } int main() { ios::sync_with_stdio(0); cin.tie(0); init(); cout << first[0] << " "; int cur=first[1]; for (int i=1; i<n-1; ++i) { bool ok[2]={same[cur].size(), ck(cur, cur^1)}; assert(ok[0]||ok[1]); if (ok[0]&&!ok[1]||ok[0]&&ok[1]&&same[cur].top()<dif[cur].top()) { cout << same[cur].top() << " "; same[cur].pop(); } else { cout << dif[cur].top() << " "; dif[cur].pop(); cur^=1; } } assert(same[0].empty()&&same[1].empty()&&dif[0].empty()&&dif[1].empty()&&cur==last[1]); cout << last[0]; return 0; }

Compilation message (stderr)

slagalica.cpp: In function 'int main()':
slagalica.cpp:69:29: warning: narrowing conversion of 'same[cur].std::priority_queue<int, std::vector<int>, std::greater<int> >::size()' from 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} to 'bool' [-Wnarrowing]
   69 |   bool ok[2]={same[cur].size(), ck(cur, cur^1)};
      |               ~~~~~~~~~~~~~~^~
slagalica.cpp:71:12: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   71 |   if (ok[0]&&!ok[1]||ok[0]&&ok[1]&&same[cur].top()<dif[cur].top()) {
      |       ~~~~~^~~~~~~~
#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...