Submission #407344

#TimeUsernameProblemLanguageResultExecution timeMemory
407344MDarioBoxes with souvenirs (IOI15_boxes)C++11
Compilation error
0 ms0 KiB
#include "boxes.h" #include <stdio.h> #include <stdlib.h> #include<bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second static char _buffer[1024]; static int _currentChar = 0; static int _charsNumber = 0; static FILE *_inputFile, *_outputFile; static inline int _read() { if (_charsNumber < 0) { exit(1); } if (!_charsNumber || _currentChar == _charsNumber) { _charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile); _currentChar = 0; } if (_charsNumber <= 0) { return -1; } return _buffer[_currentChar++]; } static inline int _readInt() { int c, x, s; c = _read(); while (c <= 32) c = _read(); x = 0; s = 1; if (c == '-') { s = -1; c = _read(); } while (c > 32) { x *= 10; x += c - '0'; c = _read(); } if (s < 0) x = -x; return x; } long long delivery(int n, int K, int L, int p[]){ vector<pair<ll, ll>> v1, v2; ll k=K, l=L; v1.push_back({0, 0}); v2.push_back({0, 0}); for(int i=0; i<n; i++){ if(p[i]!=0){ if(p[i]<=l/2)v1.push_back({p[i], 0}); } } for(int i=n-1; i>=0; i--){ if(p[i]!=0){ if(p[i]>l/2)v2.push_back({l-p[i], 0}); } } for(int i=0; i<v1.size(); i++){ if(i<k)v1[i].S=v1[i].F*2; else v1[i].S=v1[i].F*2+v1[i-k].S; } for(int i=0; i<v2.size(); i++){ if(i<k)v2[i].S=v2[i].F*2; else v2[i].S=v2[i].F*2+v2[i-k].S; } ll r=v1.back().S+v2.back().S; for(int i=0; i<v1.size()&&i<k; i++){ ll c=v1.size()-1-i, c1; c1=(k-(c%k))%k; if(c1>=v1.size()){ r=min(r, v1[c].S+l); } else{ r=min(r, v1[c].S+l+v2[v2.size()-c1].S); } } cout << r; return r; } int main() { _inputFile = fopen("boxes.in", "rb"); _outputFile = fopen("boxes.out", "w"); int N, K, L, i; N = _readInt(); K = _readInt(); L = _readInt(); int *p = (int*)malloc(sizeof(int) * (unsigned int)N); for (i = 0; i < N; i++) { p[i] = _readInt(); } fprintf(_outputFile, "%lld\n", delivery(N, K, L, p)); return 0; }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:61:19: 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]
   61 |     for(int i=0; i<v1.size(); i++){
      |                  ~^~~~~~~~~~
boxes.cpp:65:19: 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]
   65 |     for(int i=0; i<v2.size(); i++){
      |                  ~^~~~~~~~~~
boxes.cpp:70:19: 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]
   70 |     for(int i=0; i<v1.size()&&i<k; i++){
      |                  ~^~~~~~~~~~
boxes.cpp:73:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         if(c1>=v1.size()){
      |            ~~^~~~~~~~~~~
/usr/bin/ld: /tmp/ccwsngzH.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/ccJMoQuD.o:boxes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status