Submission #363659

#TimeUsernameProblemLanguageResultExecution timeMemory
363659Sparky_09Carnival Tickets (IOI20_tickets)C++17
27 / 100
623 ms56996 KiB
#include "tickets.h"
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;

void usaco(string s){
  freopen((s+".in").c_str(), "r", stdin);
  freopen((s+".out").c_str(), "w", stdout);
}

int n,m;
const ll N = 2e3+100;
ll t[N];

struct node{
	ll num,val;
}a[N];

ll cmp(node a,node b){
	return a.val < b.val;
}

long long find_maximum(int k, vector<vector<int>> x) {
	n = x.size();
	m = x[0].size();
	vector<vector<int>> ans(n, vector<int>(m, -1));
	if(m == 1){
		for(int i = 0; i < n; i++) 
			ans[i][0]=0;
		allocate_tickets(ans);
		ll s = 0;
		for(int i = 0; i < n; i++) 
			t[i] = x[i][0];
		sort(t, t+n);
		for(int i = 0;i < n/2; i++) 
			s -= t[i];
		for(int i = n/2; i < n; i++) 
			s += t[i];
		return s;
	}
	else if(k == 1){
		ll s = 0;
		for(int i = 0; i < n; i++) 
			s += x[i][n-1];
		for(int i = 0; i < n; i++) 
			a[i] = (node){i,x[i][0]+x[i][n-1]};
		sort(a , a+n, cmp);
		for(int i = 0; i < n/2; i++) 
			s -= a[i].val, ans[a[i].num][0] = 0;
		for(int i= n/2 ;i < n; i++) 
			ans[a[i].num][n-1]=0;
		allocate_tickets(ans);
		return s;
	}
}

Compilation message (stderr)

tickets.cpp: In function 'void usaco(std::string)':
tickets.cpp:14:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   freopen((s+".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tickets.cpp:15:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   15 |   freopen((s+".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tickets.cpp: In function 'long long int find_maximum(int, std::vector<std::vector<int> >)':
tickets.cpp:33:47: warning: control reaches end of non-void function [-Wreturn-type]
   33 |  vector<vector<int>> ans(n, vector<int>(m, -1));
      |                                               ^
#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...