Submission #639280

#TimeUsernameProblemLanguageResultExecution timeMemory
639280slimeCarnival Tickets (IOI20_tickets)C++14
39 / 100
3072 ms2097152 KiB
#include "tickets.h" #include "bits/stdc++.h" using namespace std; 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; for (int i = 0; i < n; i++) { std::vector<int> row(m); for (int j = 0; j < m; j++) { row[j] = -1; } answer.push_back(row); } long long ps[n+1][m+1]; for(int i=0; i<=n; i++) { for(int j=0; j<=m; j++) { ps[i][j] = 0; } } for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { ps[i][j] = ps[i][j-1] + x[i-1][j-1]; } } long long dp[n+1][n*k/2 + 1]; for(int i=0; i<=n; i++) { for(int j=0; j<=n*k/2; j++) { dp[i][j] = -1e16; } } dp[0][0] = 0; for(int i=1; i<=n; i++) { for(int j=0; j<=n*k/2; j++) { for(int elev=0; elev<=min(j, k); elev++) { dp[i][j] = max(dp[i][j], dp[i-1][j - elev] - ps[i][k-elev] + ps[i][m] - ps[i][m-elev]); } } } int cur = n*k/2; for(int i=n; i>=1; i--) { for(int elev=0; elev<=min(cur, k); elev++) { if(dp[i-1][cur-elev] - ps[i][k-elev] + ps[i][m] - ps[i][m-elev] == dp[i][cur]) { for(int j=m-elev; j<m; j++) answer[i-1][j] = 1; // to add for(int j=0; j<k-elev; j++) answer[i-1][j] = -2; // to subtract cur -= elev; break; } } } int nxt = 0; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { if(answer[i][j] == 1) { answer[i][j] = nxt; nxt = (nxt + 1) % k; } } } for(int i=0; i<n; i++) { bool bruh[m]; for(int j=0; j<m; j++) bruh[j] = 0; for(int j=0; j<m; j++) if(answer[i][j] >= 0) bruh[answer[i][j]] = 1; nxt = 0; for(int j=0; j<m; j++) { if(answer[i][j] == -2) { while(bruh[nxt]) nxt++; bruh[nxt] = 1; answer[i][j] = nxt; } } } allocate_tickets(answer); return dp[n][n*k/2]; }
#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...