Submission #307156

#TimeUsernameProblemLanguageResultExecution timeMemory
307156Ruxandra985Carnival Tickets (IOI20_tickets)C++14
27 / 100
780 ms72572 KiB
#include <bits/stdc++.h> #include "tickets.h" #define DIMN 1510 #define MLD 1000000000 using namespace std; pair <int , int> v[2 * DIMN]; long long dp[DIMN][DIMN]; int tt[DIMN][DIMN]; int f[DIMN]; long long find_maximum(int k, vector<vector<int>> x) { int n = x.size() , i , j , pv , pw , elem; int m = x[0].size(); long long sol = 0; vector<vector<int>> answer; for (i = 0; i < n; i++) { vector<int> row; row.resize(m , -1); answer.push_back(row); } if (m == 1){ for (i = 0 ; i < n ; i++){ answer[i][0] = 0; v[i] = make_pair(x[i][0] , i); } sort (v , v + n); for (i = 0 ; i < n ; i++){ if (i < n / 2) sol = sol - v[i].first; else sol = sol + v[i].first; } } else if (k == 1){ /// dp[i][j] = smin daca esti la linia i si ai selectat j din stanga tt[0][0] = 1; for (i = 1 ; i <= n ; i++){ for (j = 0 ; j <= n / 2 && j <= i ; j++){ if (j != 0){ if (!tt[i - 1][j] && tt[i - 1][j - 1]){ dp[i][j] = dp[i - 1][j - 1] + x[i - 1][0]; tt[i][j] = -1; } else if (!tt[i - 1][j - 1] && tt[i - 1][j]){ dp[i][j] = dp[i - 1][j] + MLD - x[i - 1].back(); tt[i][j] = 1; } else if (tt[i - 1][j - 1] && tt[i - 1][j]){ if (dp[i - 1][j] + MLD - x[i - 1].back() <= dp[i - 1][j - 1] + x[i - 1][0]){ dp[i][j] = dp[i - 1][j] + MLD - x[i - 1].back(); tt[i][j] = 1; } else { dp[i][j] = dp[i - 1][j - 1] + x[i - 1][0]; tt[i][j] = -1; } } } else if (tt[i - 1][j]){ dp[i][j] = dp[i - 1][j] + MLD - x[i - 1].back(); tt[i][j] = 1; } } } sol = 1LL * MLD * n / 2 - dp[n][n / 2]; i = n; j = n / 2; while (i){ if (tt[i][j] == -1){ answer[i - 1][0] = 0; j--; } else { answer[i - 1][m - 1] = 0; } i--; } } allocate_tickets(answer); return sol; }

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:15:29: warning: unused variable 'pv' [-Wunused-variable]
   15 |  int n = x.size() , i , j , pv , pw , elem;
      |                             ^~
tickets.cpp:15:34: warning: unused variable 'pw' [-Wunused-variable]
   15 |  int n = x.size() , i , j , pv , pw , elem;
      |                                  ^~
tickets.cpp:15:39: warning: unused variable 'elem' [-Wunused-variable]
   15 |  int n = x.size() , i , j , pv , pw , elem;
      |                                       ^~~~
#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...