Submission #721076

#TimeUsernameProblemLanguageResultExecution timeMemory
721076Magikarp4000Alternating Current (BOI18_alternating)C++17
0 / 100
3083 ms6616 KiB
#include <bits/stdc++.h> using namespace std; #define INF int(1e9+7) #define FOR(i,s,n) for (int i = s; i < n; i++) #define FORR(i,n,s) for (int i = n; i > s; i--) #define FORX(u, arr) for (auto u : arr) #define ln '\n' #define ll long long #define PII pair<int, int> #define PLL pair<ll, ll> #define ALL(v) v.begin(), v.end() #define PB push_back #define F first #define S second const ll LLINF = 1e18+1; struct Wire { int l,r,idx; }; const int MAXN = 1e5+1; int n,m; PII p[MAXN], q[MAXN]; bool res[MAXN], z[MAXN]; vector<Wire> pro,noob; int pn,nn; int w[MAXN]; bool cmp(const Wire& x, const Wire& y) { return x.l < y.l; } bool check(int k) { vector<PII> a,b; vector<int> dir(m,0); FOR(i,0,m) res[i] = 0; FOR(i,0,pn) { if ((i+k)%2 == 0) { a.PB(q[pro[(i+k)%pn].idx]); dir[pro[i].idx] = 0; } else { b.PB(q[pro[(i+k)%pn].idx]); dir[pro[i].idx] = 1; res[pro[i].idx] = 1; } } FOR(i,0,nn) { if (dir[w[noob[i].idx]] == 0) { b.PB(q[noob[i].idx]); res[noob[i].idx] = 1; } else a.PB(q[noob[i].idx]); } sort(ALL(a)); sort(ALL(b)); // FORX(u,a) cout << u.F << ' '; // cout << ln; // FORX(u,b) cout << u.F << ' '; // cout << ln; // cout << ln; int pos = a[0].S, idx = 0; while (idx < a.size() && pos < a[0].F+n-1) { if (a[idx].F > pos+1) return 0; pos = max(pos,a[idx].S); idx++; } if (pos < a[0].F+n-1) return 0; pos = b[0].S, idx = 0; while (idx < b.size() && pos < b[0].F+n-1) { if (b[idx].F > pos+1) return 0; pos = max(pos,b[idx].S); idx++; } if (pos < b[0].F+n-1) return 0; return 1; } signed main() { cin >> n >> m; FOR(i,0,m) cin >> p[i].F >> p[i].S; FOR(i,0,m) { q[i].F = p[i].F; q[i].S = p[i].S < p[i].F ? p[i].S+n : p[i].S; } FOR(i,0,m) { if (z[i]) continue; FOR(j,0,m) { if (i == j) continue; if ((q[i].F <= q[j].F && q[i].S >= q[j].S) || ((p[i].S%n) == p[i].F-1) || (p[j].S >= p[j].F && q[i].F <= p[j].F+n && q[i].S >= p[j].S+n)) { z[j] = 1; w[j] = i; } } } FOR(i,0,m) { if (!z[i]) pro.PB({q[i].F,q[i].S,i}); else noob.PB({q[i].F,q[i].S,i}); } sort(ALL(pro),cmp); sort(ALL(noob),cmp); // FORX(u,pro) cout << u.idx << ' '; // cout << ln; // FORX(u,noob) cout << u.idx << ' '; // cout << ln; pn = pro.size(), nn = noob.size(); FOR(i,0,pn) { // FOR(j,0,pn) { // if ((j+i)%2 == 0) cout << (i+j)%pn; // } // cout << ln; // FOR(j,0,pn) { // if ((j+i)%2 == 1) cout << (i+j)%pn; // } // cout << ln << ln; if (check(i)) { FOR(j,0,m) cout << res[j]; return 0; } } cout << "impossible"; }

Compilation message (stderr)

alternating.cpp: In function 'bool check(int)':
alternating.cpp:63:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     while (idx < a.size() && pos < a[0].F+n-1) {
      |            ~~~~^~~~~~~~~~
alternating.cpp:70:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     while (idx < b.size() && pos < b[0].F+n-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...