제출 #979556

#제출 시각아이디문제언어결과실행 시간메모리
979556kilkuwu선물상자 (IOI15_boxes)C++17
20 / 100
1 ms348 KiB
#include "boxes.h" #include <bits/stdc++.h> #ifdef LOCAL #include "template/debug.hpp" #else #define dbg(...) ; #define timer(...) ; #endif long long delivery(int N, int K, int L, int p[]) { int split = std::upper_bound(p, p + N, L / 2) - p; int left = split; int right = split; long long ans = 0; while (left >= K) { ans += p[left - 1] * 2; left -= K; } while (N - right >= K) { ans += (L - p[right]) * 2; right += K; } // now what can we do ? // we can go in either direction if (right == N && left == 0) return ans; if (right == N || left == 0) { if (right == N) { return ans + p[left - 1] * 2; } else { return ans + (L - p[right]) * 2; } } // both of em are non negative long long naive = ans + p[left - 1] * 2 + (L - p[right]) * 2; // that's the naieve solution int tot = left + N - right; long long round = ans + L; if (tot > K) { int left_remain = tot - K; int right_remain = tot - K; round += std::min(p[left_remain - 1], L - p[N - right_remain]) * 2; } ans += std::min(naive, round); return ans; } #ifdef LOCAL int main() { int N, K, L, i; std::cin >> N >> K >> L; int *p = (int*)malloc(sizeof(int) * (unsigned int)N); for (i = 0; i < N; i++) { std::cin >> p[i]; } std::cout << delivery(N, K, L, p) << "\n"; return 0; } #endif

컴파일 시 표준 에러 (stderr) 메시지

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:13:49: warning: conversion from 'long int' to 'int' may change value [-Wconversion]
   13 |   int split = std::upper_bound(p, p + N, L / 2) - p;
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
#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...