Submission #377398

#TimeUsernameProblemLanguageResultExecution timeMemory
377398ThistleCarnival Tickets (IOI20_tickets)C++14
27 / 100
714 ms73528 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()) 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]; } } } allocate_tickets(answer); return ans; }

Compilation message (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:32:3: note: in expansion of macro 'rep'
   32 |   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:34:3: note: in expansion of macro 'rep'
   34 |   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:38:3: note: in expansion of macro 'rep'
   38 |   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:38:11: note: in expansion of macro 'rep'
   38 |   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:43:3: note: in expansion of macro 'rep'
   43 |   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:43:11: note: in expansion of macro 'rep'
   43 |   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:55:3: note: in expansion of macro 'rep'
   55 |   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:55:11: note: in expansion of macro 'rep'
   55 |   rep(i,n)rep(j,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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...