Submission #420232

#TimeUsernameProblemLanguageResultExecution timeMemory
420232ismoilovBoxes with souvenirs (IOI15_boxes)C++14
35 / 100
1 ms300 KiB
#include "boxes.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
#define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++)
#define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--)
#define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--)
 
ll delivery(int n, int k, int L, int p[]) {
	vector <ll> a, b;
	ll ans = 0, l = L;
	fp(i,0,n){
		if(p[i] < l-p[i])
			a.push_back(p[i]*2);
		else
			b.push_back((l-p[i])*2);
	}
	sort(all(a));
	sort(all(b));
	ll aa = 0, bb = 0;
	if(a.size() % k != 0)
		aa = a[a.size()-1];
	if(b.size() % k != 0)
		bb = b[b.size()-1];
	if(l > aa + bb){
		int x = a.size()-1;
		while(x >= 0)
			ans += a[x], x -= k;
		x = b.size()-1;
		while(x >= 0)
			ans += b[x], x -= k;
		return ans;
	}
	else{
		fp(i,0,k){
			if(a.empty()){
				if(!b.empty())
					b.pop_back();
				continue;
			}
			if(b.empty()){
				if(!a.empty())
					a.pop_back();
				continue;
			}
			if(a.back() > b.back())
				a.pop_back();
			else
				b.pop_back();
		}
		int	x = a.size()-1;
		while(x >= 0)
			ans += a[x], x -= k;
		x = b.size()-1;
		while(x >= 0)
			ans += b[x], x -= k;
		return ans+l;
	}
}

Compilation message (stderr)

boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
boxes.cpp:15:2: note: in expansion of macro 'fp'
   15 |  fp(i,0,n){
      |  ^~
boxes.cpp:29:19: warning: conversion from 'std::vector<long long int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   29 |   int x = a.size()-1;
      |           ~~~~~~~~^~
boxes.cpp:32:15: warning: conversion from 'std::vector<long long int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   32 |   x = b.size()-1;
      |       ~~~~~~~~^~
boxes.cpp:7:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    7 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
boxes.cpp:38:3: note: in expansion of macro 'fp'
   38 |   fp(i,0,k){
      |   ^~
boxes.cpp:54:19: warning: conversion from 'std::vector<long long int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   54 |   int x = a.size()-1;
      |           ~~~~~~~~^~
boxes.cpp:57:15: warning: conversion from 'std::vector<long long int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   57 |   x = b.size()-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...