Submission #1051545

#TimeUsernameProblemLanguageResultExecution timeMemory
1051545pcc카니발 티켓 (IOI20_tickets)C++17
12 / 100
3083 ms173060 KiB
#include "tickets.h"
#include <vector>
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second


/*
	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++) {
			if (j < k) {
				row[j] = j;
			} else {
				row[j] = -1;
			}
		}
		answer.push_back(row);
	}
	allocate_tickets(answer);
	return 1;
*/

const ll inf = 1e18;
const int mxn = 2022;

vector<vector<int>> ansv;
vector<vector<ll>> dp;
vector<vector<int>> pre;
vector<pll> choice[mxn];
int len[mxn];

long long find_maximum(int k, std::vector<std::vector<int>> x) {
	int N = x.size();
	int M = x[0].size();
	int K = k;
	ansv = vector<vector<int>>(N,vector<int>(M,-1));

	dp = vector<vector<ll>>(N+1,vector<ll>(N*K/2+1,-inf));
	pre = vector<vector<int>>(N+1,vector<int>(N*K/2+1,-1));

	for(int i = 0;i<N;i++){
		int pl = 0,pr = M-1;
		ll sum = 0;
		for(int j = 0;j<K;j++)sum -= x[i][pl++];
		choice[i].push_back(pll(sum,K));
		for(int j = 1;j<=K;j++){
			sum += x[i][--pl];
			sum += x[i][pr--];
			cerr<<i<<":"<<sum<<endl;
			choice[i].push_back(pll(sum,pl));
		}
		reverse(choice[i].begin(),choice[i].end());
	}

	cerr<<"DPING"<<endl;

	for(int i = 0;i<N;i++){
		for(auto &j:choice[i])cerr<<j.fs<<' '<<j.sc<<',';cerr<<endl;
	}cerr<<endl;

	dp[0][0] = 0;
	for(int i = 1;i<=N;i++){
		for(int j = 0;j<choice[i-1].size();j++){
			pll now = choice[i-1][j];
			for(int k = now.sc;k<=(N*K)/2;k++){
				if(dp[i][k]<=dp[i-1][k-now.sc]+now.fs){
					dp[i][k] = dp[i-1][k-now.sc]+now.fs;
					pre[i][k] = j;
				}
			}
		}
	}

	cerr<<"DP DONE!"<<endl;

	for(int i = 0;i<=N;i++){
		for(int j = 0;j<=N*K/2;j++)cerr<<dp[i][j]<<' ';cerr<<endl;
	}cerr<<endl;
	for(int i = 0;i<=N;i++){
		for(int j = 0;j<=N*K/2;j++)cerr<<pre[i][j]<<' ';cerr<<endl;
	}cerr<<endl;

	ll ans = dp[N][N*K/2];
	int now = N*K/2;
	for(int i = N;i>=1;i--){
		len[i-1] = pre[i][now];
		now -= pre[i][now];
	}

	cerr<<"LEN: ";for(int i = 0;i<N;i++)cerr<<len[i]<<' ';cerr<<endl;

	int C = 0;
	for(int i = 0;i<N;i++){
		for(int j = 0;j<len[i];j++)ansv[i][j] = C,C = (C+1)%K;
	}
	for(int i = 0;i<N;i++){
		set<int> st;
		for(int j = 0;j<K;j++)st.insert(j);
		for(int j = 0;j<len[i];j++)st.erase(ansv[i][j]);
		for(int j = 0;j<K-len[i];j++){
			ansv[i][M-1-j] = *st.begin();
			st.erase(st.begin());
		}
	}

	allocate_tickets(ansv);
	return ans;
}

Compilation message (stderr)

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:69:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   69 |   for(auto &j:choice[i])cerr<<j.fs<<' '<<j.sc<<',';cerr<<endl;
      |   ^~~
tickets.cpp:69:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   69 |   for(auto &j:choice[i])cerr<<j.fs<<' '<<j.sc<<',';cerr<<endl;
      |                                                    ^~~~
tickets.cpp:74:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for(int j = 0;j<choice[i-1].size();j++){
      |                 ~^~~~~~~~~~~~~~~~~~~
tickets.cpp:88:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   88 |   for(int j = 0;j<=N*K/2;j++)cerr<<dp[i][j]<<' ';cerr<<endl;
      |   ^~~
tickets.cpp:88:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   88 |   for(int j = 0;j<=N*K/2;j++)cerr<<dp[i][j]<<' ';cerr<<endl;
      |                                                  ^~~~
tickets.cpp:91:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   91 |   for(int j = 0;j<=N*K/2;j++)cerr<<pre[i][j]<<' ';cerr<<endl;
      |   ^~~
tickets.cpp:91:51: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   91 |   for(int j = 0;j<=N*K/2;j++)cerr<<pre[i][j]<<' ';cerr<<endl;
      |                                                   ^~~~
#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...