Submission #838366

# Submission time Handle Problem Language Result Execution time Memory
838366 2023-08-26T17:28:06 Z ma_moutahid Carnival Tickets (IOI20_tickets) C++17
0 / 100
3000 ms 212 KB
#include "tickets.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
long long prize=0;
using ll=long long;
#define vi vector<long long>
#define vii vector<vi>
#define pi pair<long long,long long>
ll INF=1e9;
vector<vi> ans;

int n,m;


long long find_maximum(int k, std::vector<std::vector<int>> x) {
	n = x.size();
	m = x[0].size();
	long long prize=0;
	std::vector<std::vector<int>> answer(n, std::vector<int>(m));
	vector<vi>ones(n);
	vector<vi>zeroes(n);
	map<int,int>diff;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(x[i][j])ones[i].push_back(j);
			else { zeroes[i].push_back(j);}
		}
		diff.insert(pi(ones[i].size()-zeroes[i].size(),i));
	
	}
	ll result=0;
	for(int i=0;i<k;i++){
		vi used(n);
		int z=0;int o=0;
		auto b=diff.rbegin();
		int ao=0;
		int az=0;
		while(o<n/2){
			int node=b->second;
			if(used[node])continue;
			used[node]=1;
			o++;
			if(!ones[node].empty()){
				answer[node][ones[node].back()]=i;
				ao++;
			}
			else {
				answer[node][zeroes[node].back()]=i;
			}
		}
		auto b2=diff.begin();
		while(z<n/2){
			int node=b2->second;
			if(used[node])continue;
			used[node]=1;
			z++;
			if(!zeroes[node].empty()){
				answer[node][zeroes[node].back()]=i;
				az++;
			}
			else {
				answer[node][ones[node].back()]=i;
			}
		}
		result+=min(ao,az);
	}
	
	return result;
}

Compilation message

tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:19:12: warning: unused variable 'prize' [-Wunused-variable]
   19 |  long long prize=0;
      |            ^~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 3062 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3067 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3058 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3078 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3062 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -