Submission #976745

# Submission time Handle Problem Language Result Execution time Memory
976745 2024-05-07T05:06:20 Z Amaarsaa Boxes with souvenirs (IOI15_boxes) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "boxes.h"
using namespace std;
using ll = long long ;

ll delivery(ll N, ll K, ll L, ll p[]) {
	ll ans, cnt_ard, cnt_urd, res;
	vector < ll > ard, urd;
	ll cnt = 0, i, j, r, s;
	for (i = 0; i < N; i ++) {
		if ( p[i] * 2 > L) {
			ard.push_back(p[i]);
		}
		else {
			if (p[i] * 2 < L) urd.push_back(p[i]);
			else cnt ++;
		}
	}
	ans = 0;
	for (i = K - 1; i < urd.size(); i += K) {
		ans += urd[i];
	}
	j = i - K + 1;
	reverse(ard.begin(), ard.end());
	for (i = K - 1; i < ard.size(); i += K) {
		ans += (L - ard[i]);
	}
	r = i - K + 1;
	ans *= 2;
	cnt_urd = urd.size() - j;
	cnt_ard = ard.size() - r;
	res = ((cnt_ard + cnt_urd + cnt + K - 1) / K) * L;
	if ( cnt_ard != 0) {
		res = min(res, (((L - ard.back()) * 2) + ((cnt_urd + cnt + K - 1)/K) * L) );
	}
	if ( cnt_urd != 0) {
		res = min(res, (((urd.back()) * 2) + ((cnt_ard + cnt + K - 1)/K) * L) );
	}
	if ( cnt_ard != 0 && cnt_urd != 0) {
		res = min(res, (((L - ard.back()) * 2) + (urd.back() * 2)+ ((cnt + K - 1)/K) * L) );
	}
	
	return res + ans;
	
}

Compilation message

boxes.cpp: In function 'll delivery(ll, ll, ll, ll*)':
boxes.cpp:20:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for (i = K - 1; i < urd.size(); i += K) {
      |                  ~~^~~~~~~~~~~~
boxes.cpp:25:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for (i = K - 1; i < ard.size(); i += K) {
      |                  ~~^~~~~~~~~~~~
boxes.cpp:9:23: warning: unused variable 's' [-Wunused-variable]
    9 |  ll cnt = 0, i, j, r, s;
      |                       ^
/usr/bin/ld: /tmp/ccBFY0rA.o: in function `main':
grader.c:(.text.startup+0x1ef): undefined reference to `delivery(int, int, int, int*)'
collect2: error: ld returned 1 exit status