Submission #401724

#TimeUsernameProblemLanguageResultExecution timeMemory
401724bonopoRobots (IOI13_robots)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define el "\n" #define f first #define s second typedef long long ll; const ll MM=1e5+5, MOD=1e9+7; int aA, aB, aT, x[MM], y[MM], u[MM]; priority_queue<pair<int,int>> pq; struct toy { int wt, sz, idx; } t[10*MM]; bool cmpw(toy a, toy b) { return a.wt<b.wt; } bool cmps(toy a, toy b) { return a.sz<b.sz; } bool check(int sec) { memset(u, 0, sizeof(u)); int ptr=1, hv=0; // take highest weight you can sort(t+1, t+aT+1, cmpw); for(int i=1; i<=aA; ++i) { while(ptr<=aT&&t[ptr].wt<x[i]) { pq.push({t[ptr].sz, ptr++}); } int cnt=sec; while(!pq.empty()&&cnt) { pair<int,int> e=pq.top(); pq.pop(); if(!u[t[e.s].idx]) { u[t[e.s].idx]=1; ++hv; --cnt; } } } sort(t+1, t+aT+1, cmps); while(!pq.empty()) pq.pop(); ptr=1; // take highest size you can for(int i=1; i<=aB; ++i) { while(ptr<=aT&&t[ptr].sz<y[i]) { pq.push({t[ptr].wt, ptr++}); } int cnt=sec; while(!pq.empty()&&cnt) { pair<int,int> e=pq.top(); pq.pop(); if(!u[t[e.s].idx]) { u[t[e.s].idx]=1; ++hv; --cnt; } } } return hv==aT; } int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) { aA=A; aB=B; aT=T; for(int i=0; i<A; ++i) x[i+1]=X[i]; for(int i=0; i<B; ++i) y[i+1]=Y[i]; for(int i=0; i<T; ++i) t[i+1].wt=W[i]; for(int i=0; i<T; ++i) t[i+1].sz=S[i]; for(int i=0; i<T; ++i) t[i+1].idx=i+1; if(A>0) sort(x+1, x+A+1); if(B>0) sort(y+1, y+B+1); int lo=1, hi=T, mid, ans=-1; while(lo<=hi) { mid=(lo+hi)/2; if(check(mid)) hi=mid-1, ans=mid; else lo=mid+1; } return ans; }

Compilation message (stderr)

robots.cpp: In function 'bool check(int)':
robots.cpp:31:36: warning: operation on 'ptr' may be undefined [-Wsequence-point]
   31 |             pq.push({t[ptr].sz, ptr++}); }
      |                                 ~~~^~
robots.cpp:31:36: warning: operation on 'ptr' may be undefined [-Wsequence-point]
robots.cpp:41:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   41 |     while(!pq.empty()) pq.pop(); ptr=1;
      |     ^~~~~
robots.cpp:41:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   41 |     while(!pq.empty()) pq.pop(); ptr=1;
      |                                  ^~~
robots.cpp:45:36: warning: operation on 'ptr' may be undefined [-Wsequence-point]
   45 |             pq.push({t[ptr].wt, ptr++}); }
      |                                 ~~~^~
robots.cpp:45:36: warning: operation on 'ptr' may be undefined [-Wsequence-point]
/usr/bin/ld: /tmp/ccIEeE0A.o: in function `main':
grader.c:(.text.startup+0x1b1): undefined reference to `putaway'
collect2: error: ld returned 1 exit status