Submission #199747

#TimeUsernameProblemLanguageResultExecution timeMemory
199747SamAndSlagalica (COCI19_slagalica2)C++17
70 / 70
66 ms3576 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100005, INF = 1000000009; struct ban { int x; ban(){} ban(int x) { this->x = x; } }; bool operator<(const ban& a, const ban& b) { return a.x > b.x; } int n; priority_queue<ban> q[10]; int s, f; int u[10]; bool stg() { int z = s; int q[10]; for (int i = 1; i <= 8; ++i) q[i] = u[i]; if (z == 0) q[2] = 0; else q[3] = 0; if (z == 0 && q[1]) { --q[1]; z = 1; } else if (z == 1 && q[4]) { --q[4]; z = 0; } if (z == 0) q[2] = 0; else q[3] = 0; if (q[2] || q[3]) return false; if (abs(q[1] - q[4]) >= 2) return false; if (q[1] == q[4] + 1) { if (z == 0) { --q[1]; z = 1; } } if (q[4] == q[1] + 1) { if (z == 1) { --q[4]; z = 0; } } if (q[1] == q[4]) q[1] = q[4] = 0; else return false; if (f && z) return false; if (!f && !z) return false; return true; } int ans[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { int ty, x; scanf("%d%d", &ty, &x); q[ty].push(ban(x)); } if (!q[5].empty()) { s = 1; ans[1] = q[5].top().x; q[5].pop(); } else { s = 0; ans[1] = q[6].top().x; q[6].pop(); } if (!q[7].empty()) { f = 1; ans[n] = q[7].top().x; q[7].pop(); } else { f = 0; ans[n] = q[8].top().x; q[8].pop(); } for (int i = 1; i <= 8; ++i) { u[i] = q[i].size(); } if (!stg()) { printf("-1\n"); return 0; } for (int ii = 2; ii < n; ++ii) { int minu = INF; for (int i = 1; i <= 8; ++i) { if (!q[i].empty()) { if (i == 1 && s == 1) continue; if (i == 2 && s == 1) continue; if (i == 3 && s == 0) continue; if (i == 4 && s == 0) continue; --u[i]; int ss = s; if (i == 1) s = 1; if (i == 2) s = 0; if (i == 3) s = 1; if (i == 4) s = 0; if (stg()) { minu = min(minu, q[i].top().x); } ++u[i]; s = ss; } } for (int i = 1; i <= 8; ++i) { if (!q[i].empty()) { if (i == 1 && s == 1) continue; if (i == 2 && s == 1) continue; if (i == 3 && s == 0) continue; if (i == 4 && s == 0) continue; if (q[i].top().x == minu) { ans[ii] = q[i].top().x; q[i].pop(); --u[i]; if (i == 1) s = 1; if (i == 2) s = 0; if (i == 3) s = 1; if (i == 4) s = 0; break; } } } } for (int i = 1; i <= n; ++i) printf("%d ", ans[i]); printf("\n"); return 0; }

Compilation message (stderr)

slagalica.cpp: In function 'int main()':
slagalica.cpp:83:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
slagalica.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &ty, &x);
         ~~~~~^~~~~~~~~~~~~~~~~
#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...