제출 #377401

#제출 시각아이디문제언어결과실행 시간메모리
377401Thistle카니발 티켓 (IOI20_tickets)C++14
41 / 100
711 ms57708 KiB
#include "tickets.h" #include <vector> #include<algorithm> #include<set> #include<iostream> #include<random> #include<queue> #include<cassert> using namespace std; using ll=long long; using H=pair<ll, ll>; #define vec vector #define vi vec<ll> #define pb push_back #define all(a) (a).begin(),(a).end() #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++) #define rep(i,n) rng((i),0,(n)) #define siz(a) int((a).size()) #define fs first #define sc second constexpr ll inf=1e16; constexpr ll Inf=1e9+1; long long find_maximum(int k, std::vector<std::vector<int>> x) { int n = x.size(); int m = x[0].size(); std::vector<std::vector<int>> answer(n,vec<int>(m,-1)); ll ans=0; if(m==1){ vi v; rep(i,n) v.pb(x[i][0]); sort(all(v)); rep(i,n){ if(i<n/2) ans-=v[i]; else ans+=v[i]; } rep(i,n)rep(j,m) answer[i][j]=0; } else if(k==1){ vec<int> mx(n,-Inf),mn(n,Inf); vec<int>mxi(n,-1),mni(n,-1); rep(i,n)rep(j,m){ if(mx[i]<x[i][j]){ mx[i]=max(mx[i],x[i][j]); mxi[i]=j; } if(mn[i]>x[i][j]){ mn[i]=min(mn[i],x[i][j]); mni[i]=j; } } vec<vi> dp=vec<vi>(n+1,vi(n+1,-inf)); dp[0][0]=0; rep(i,n)rep(j,n+1){ if(dp[i][j]==inf) continue; dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+mx[i]); dp[i+1][j]=max(dp[i+1][j],dp[i][j]-mn[i]); } ans=dp[n][n/2]; ll k=dp[n][n/2]; int c=n/2; for(int i=n-1;i>=0;i--){ if(c>0&&dp[i][c-1]+mx[i]==k){ answer[i][mxi[i]]=0; c--; k=dp[i][c]; } else if(dp[i][c]-mn[i]==k){ answer[i][mni[i]]=0; k=dp[i][c]; } } } else{ priority_queue<H>p; vi one(n,0); rep(i,n)rep(j,m) if(x[i][j]==1) one[i]++; rep(i,n) p.push(H{one[i],i}); vi fst(n,0),lst(n,m-1); rep(iter,k){ vi v; vec<bool>used(n,0); rep(i,n/2){ v.pb(p.top().sc); used[p.top().sc]=1; p.pop(); } int cnt1=0,cnt0=0; rep(i,n){ if(used[i]){ if(one[i]>0) { cnt1++,one[i]--; answer[i][lst[i]--]=iter; } else{ cnt0++; answer[i][fst[i]++]=iter; } } else{ if(m-iter-one[i]>0) { cnt0++; answer[i][fst[i]++]=iter; } else{ cnt1++,one[i]--; answer[i][lst[i]--]=iter; } } } ans+=min(cnt0,cnt1); for(auto g:v) p.push(H{one[g],g}); } } allocate_tickets(answer); return ans; }

컴파일 시 표준 에러 (stderr) 메시지

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:34:3: note: in expansion of macro 'rep'
   34 |   rep(i,n) v.pb(x[i][0]);
      |   ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:36:3: note: in expansion of macro 'rep'
   36 |   rep(i,n){
      |   ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:40:3: note: in expansion of macro 'rep'
   40 |   rep(i,n)rep(j,m) answer[i][j]=0;
      |   ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:40:11: note: in expansion of macro 'rep'
   40 |   rep(i,n)rep(j,m) answer[i][j]=0;
      |           ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:45:3: note: in expansion of macro 'rep'
   45 |   rep(i,n)rep(j,m){
      |   ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:45:11: note: in expansion of macro 'rep'
   45 |   rep(i,n)rep(j,m){
      |           ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:57:3: note: in expansion of macro 'rep'
   57 |   rep(i,n)rep(j,n+1){
      |   ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:57:11: note: in expansion of macro 'rep'
   57 |   rep(i,n)rep(j,n+1){
      |           ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:80:3: note: in expansion of macro 'rep'
   80 |   rep(i,n)rep(j,m) if(x[i][j]==1) one[i]++;
      |   ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:80:11: note: in expansion of macro 'rep'
   80 |   rep(i,n)rep(j,m) if(x[i][j]==1) one[i]++;
      |           ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:81:3: note: in expansion of macro 'rep'
   81 |   rep(i,n) p.push(H{one[i],i});
      |   ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'iter' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:83:3: note: in expansion of macro 'rep'
   83 |   rep(iter,k){
      |   ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:86:4: note: in expansion of macro 'rep'
   86 |    rep(i,n/2){
      |    ^~~
tickets.cpp:16:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   16 | #define rng(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
      |                            ^
tickets.cpp:17:18: note: in expansion of macro 'rng'
   17 | #define rep(i,n) rng((i),0,(n))
      |                  ^~~
tickets.cpp:92:4: note: in expansion of macro 'rep'
   92 |    rep(i,n){
      |    ^~~
#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...