This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |