#include "tickets.h"
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll,ll>
#define F first
#define S second
using namespace std;
const int NN=1520;
ii a[NN];
ii b[NN];
pair<long long,ii> dp[NN][NN];
long long ans=0;
long long find_maximum(int k,vector<vector<int>>x){
int n=x.size();
int m=x[0].size();
// cout<<endl;
for(int j=0;j<n;j++){
a[j]={1e9,1e9};
b[j]={0,0};
for(int i=0;i<m;i++){
a[j]=min(a[j],{x[j][i],i});
b[j]=max(b[j],{x[j][i],i});
}
// cout<<a[j].F<<" "<<b[j].F<<endl;
}
//cout<<endl;
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
dp[i][j].first=-1e18;
}
}
vector<vector<int>> ann;
vector<int> vec;
for(int i=0;i<x[0].size();i++){
vec.push_back(-1);
}
for(int i=0;i<x.size();i++)ann.push_back(vec);
vec.clear();
dp[0][0]={-a[0].F,{0,a[0].S}};
dp[0][1]={+b[0].F,{0,b[0].S}};
for(int i=0;i<n-1;i++){
for(int j=0;j<n-1;j++){
dp[i+1][j]=max(dp[i+1][j],{dp[i][j].F-a[i+1].F,{j,a[i+1].S}});
dp[i+1][j+1]=max(dp[i+1][j+1],{dp[i][j].F+b[i+1].F,{j,b[i+1].S}});
}
}
/*
cout<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<dp[i][j].F<<" ";
}
cout<<endl;
}
cout<<endl;
*/
ans=dp[n-1][n/2].F;
int idx=n-1,me=n/2;
while(idx>=0){
ann[idx][dp[idx][me].S.S]=0;
me=dp[idx][me].S.F;
idx--;
}
allocate_tickets(ann);
return ans;
}
Compilation message
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i=0;i<x[0].size();i++){
| ~^~~~~~~~~~~~
tickets.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<x.size();i++)ann.push_back(vec);
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
3 ms |
3788 KB |
Output is correct |
6 |
Correct |
42 ms |
54288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
1016 KB |
Output is correct |
5 |
Correct |
36 ms |
6536 KB |
Output is correct |
6 |
Correct |
736 ms |
126752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
There is no ticket of color 0 on day 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
There is no ticket of color 0 on day 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
There is no ticket of color 0 on day 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
There is no ticket of color 0 on day 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
3 ms |
3788 KB |
Output is correct |
6 |
Correct |
42 ms |
54288 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
3 ms |
1016 KB |
Output is correct |
11 |
Correct |
36 ms |
6536 KB |
Output is correct |
12 |
Correct |
736 ms |
126752 KB |
Output is correct |
13 |
Incorrect |
1 ms |
332 KB |
There is no ticket of color 0 on day 1 |
14 |
Halted |
0 ms |
0 KB |
- |