# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
592441 | ogibogi2004 | 카니발 티켓 (IOI20_tickets) | C++14 | 1 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "tickets.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
long long find_maximum(int k, vector<vector<int>> x1) {
//cout<<"?\n";
vector<vector<ll> >x;
for(int i=0;i<x1.size();i++)
{
vector<ll>row;
for(int j=0;j<x1[i].size();j++)row.push_back(x1[i][j]);
x.push_back(row);
}
ll n = x.size();
ll m = x[0].size();
vector<vector<int>> answer;
vector<pair<ll,ll>>smallest[n];
int ptr1[n],ptr2[n];
for(ll i=0;i<n;i++)
{
for(ll j=0;j<m;j++)smallest[i].push_back({x[i][j],j});
sort(smallest[i].begin(),smallest[i].end());
ptr1[i]=0;ptr2[i]=smallest[i].size()-1;
}
ll ans=0;
for(int i=0;i<n;i++)
{
answer.push_back({});
for(int j=0;j<m;j++)answer[i].push_back(-1);
}
for(int r=0;r<k;r++)
{
int dp[n][n];
bool c[n][n];
memset(c,0,sizeof(c));
int hist[n][n];
for(int i=0;i<n;i++)
{
//cout<<r<<" "<<i<<endl;
if(i==0)
{
c[0][0]=1;
c[0][1]=1;
hist[0][0]=0;
hist[0][1]=1;
dp[0][0]=smallest[0][ptr2[i]].first;
dp[0][1]=-smallest[0][ptr1[i]].first;
continue;
}
for(int j=n/2;j>=0;j--)
{
//plus
if(c[i-1][j])
{
if(c[i][j])
{
if(dp[i-1][j]+smallest[i][ptr2[i]].first>dp[i][j])
{
dp[i][j]=dp[i-1][j]+smallest[i][ptr2[i]].first;
hist[i][j]=0;
}
}
else
{
dp[i][j]=dp[i-1][j]+smallest[i][ptr2[i]].first;
hist[i][j]=0;
c[i][j]=1;
}
}
//minus
if(c[i-1][j-1])
{
if(!c[i][j])
{
dp[i][j]=dp[i-1][j-1]-smallest[i][ptr1[i]].first;
hist[i][j]=1;
c[i][j]=1;
}
else
{
if(dp[i-1][j-1]-smallest[i][ptr1[i]].first>dp[i][j])
{
dp[i][j]=dp[i-1][j-1]-smallest[i][ptr1[i]].first;
hist[i][j]=1;
}
}
}
//if(c[i][j])cout<<i<<" "<<j<<" : "<<dp[i][j]<<endl;
}
}
//cout<<r<<" "<<dp[n-1][n/2]<<endl;
ans+=dp[n-1][n/2];
int t=n/2;
for(int i=n-1;i>=0;i--)
{
//cout<<i<<" "<<t<<endl;
int f=hist[i][t];
//cout<<" "<<f<<endl;
if(f==1)
{
answer[i][smallest[i][ptr1[i]].second]=r;
ptr1[i]++;
}
else
{
answer[i][smallest[i][ptr2[i]].second]=r;
ptr2[i]--;
}
t-=f;
}
//cout<<"alo\n";
}
allocate_tickets(answer);
return ans;
}
/*
2 3 2
0 2 5
1 1 3
*/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |