Submission #57921

#TimeUsernameProblemLanguageResultExecution timeMemory
57921E869120Boxes with souvenirs (IOI15_boxes)C++14
50 / 100
132 ms13132 KiB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int v[10000009], NN, KK, LL; bool used[10000009];

int dist(int L, int R) {
	while (L >= NN) { L -= NN; R -= NN; }
	long long V1 = v[L % NN], V2 = v[R % NN];
	long long ret = min(V2, LL - V1);

	if (L < NN && R >= NN) ret = (LL - V1) + V2; ret *= 2;
	return min(1LL * LL, ret);
}

int c[10000009];

long long delivery(int N, int K, int L, int pos[]) {
	NN = N; KK = K; LL = L;
	for (int i = 0; i < N; i++) v[i] = pos[i];

	for (int i = 0; i < N; i++) c[i] = dist(i, i + K - 1);

	long long minx = (1LL << 60);

	for (int i = 0; i < N; i++) {
		if (used[i] == true) continue;

		long long cx = i, sum = 0;
		while (cx + K < i + N) { sum += c[cx % N]; cx += K; }

		long long ex = i;
		while (used[ex % N] == false) {
			used[ex % N] = true;
			minx = min(minx, sum + dist(cx, ex + N - 1));
			sum -= c[ex % N]; ex += K; sum += c[cx%N]; cx += K;
		}
	}
	return minx;
}

Compilation message (stderr)

boxes.cpp: In function 'int dist(int, int)':
boxes.cpp:13:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if (L < NN && R >= NN) ret = (LL - V1) + V2; ret *= 2;
  ^~
boxes.cpp:13:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if (L < NN && R >= NN) ret = (LL - V1) + V2; ret *= 2;
                                               ^~~
boxes.cpp:14:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
  return min(1LL * LL, ret);
         ~~~^~~~~~~~~~~~~~~
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:36:46: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
    minx = min(minx, sum + dist(cx, ex + N - 1));
                                              ^
boxes.cpp:36:43: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
    minx = min(minx, sum + dist(cx, ex + N - 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...