Submission #127247

# Submission time Handle Problem Language Result Execution time Memory
127247 2019-07-09T07:23:37 Z ekrem Boxes with souvenirs (IOI15_boxes) C++
0 / 100
3 ms 376 KB
#include "boxes.h"
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

typedef long long ll;
typedef pair < int , int > ii;

int n, opt, ans, cvp, bas[N], son[N];

long long delivery(int n, int k, int l, int p[]) {
	for(int i = 0; i < n; i++)
		bas[i] = (i >= k) ? bas[i - k] + p[i]*2 : p[i]*2;
	for(int i = n - 1; i >= 0; i--)
		son[i] = (n - i > k) ? son[i + k] + (l - p[i])*2 : (l - p[i])*2;
	// for(int i = 0; i < n; i++)
	// 	cout << "AMK" << i << " " << bas[i] << " " << son[i] << endl;
	cvp = ans = son[0];
	for(int i = 1; i < n; i++){
		if(son[i] + ((i + k - 1)/k)*l <= ans){
			ans = son[i] + ((i + k - 1)/k)*l;
			opt = i;
		}
	}
	cvp = min(cvp, ans);
	// cout << opt << " " << ans << " " << l << endl;
	for(int i = 1; i <= n; i++){
		while(opt < n and son[opt + 1] + (opt - i + 1 + k - 1)/k*l <= son[opt] + (opt - i + k - 1)/k*l)
			opt++;
		// cout << i << " " << opt << endl;
		cvp = min(cvp, son[opt] + (opt - i + k - 1)/k*l + bas[i - 1]);
	}
    return cvp;
}



// 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;
// }

// int main() {
// 	_inputFile = fopen("in.txt", "rb");
// 	_outputFile = fopen("out.txt", "w");

//     int NN, K, L, i;
//     NN = _readInt();
//     K = _readInt();
//     L = _readInt();

//     int *p = (int*)malloc(sizeof(int) * (unsigned int)N);

//     for (i = 0; i < NN; i++) {
//         p[i] = _readInt();
//     }

//     fprintf(_outputFile, "%lld\n", delivery(NN, K, L, p));
//     return 0;
// }

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:21:48: warning: declaration of 'n' shadows a global declaration [-Wshadow]
 long long delivery(int n, int k, int l, int p[]) {
                                                ^
boxes.cpp:19:5: note: shadowed declaration is here
 int n, opt, ans, cvp, bas[N], son[N];
     ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -