제출 #464328

#제출 시각아이디문제언어결과실행 시간메모리
464328sumit_kk10선물상자 (IOI15_boxes)C++14
0 / 100
13 ms16000 KiB
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) #define ll long long int #define ld long double using namespace std; const int N = 1e6 + 5; const int MOD = 1e9 + 7; int delivery(int N, int K, int L, int positions[]){ int n = N, k = K, l = L; sort(positions + 1, positions + n + 1); long long pre_dp[n + 2][k + 1], suf_dp[n + 2][k + 1]; for(int j = 1; j <= k; ++j) pre_dp[1][j] = 2*positions[1]; for(int i = 2; i <= n; ++i){ for(int j = 1; j <= k; ++j){ pre_dp[i][j] = INT_MAX; if(j == 1) pre_dp[i][j] = min(pre_dp[i][j], pre_dp[i - 1][k] + 2*positions[i]); else pre_dp[i][j] = min(pre_dp[i][j], pre_dp[i - 1][j - 1] + 2*(positions[i] - positions[i - 1])); } } for(int i = 1; i <= n; ++i){ ll x = l - positions[i]; positions[i] = x; } for(int j = 1; j <= k; ++j){ suf_dp[n][j] = 2*positions[n]; suf_dp[n + 1][j] = 0; pre_dp[0][j] = 0; } for(int i = n - 1; i >= 1; --i){ for(int j = 1; j <= k; ++j){ suf_dp[i][j] = INT_MAX; if(j == 1) suf_dp[i][j] = min(suf_dp[i][j], suf_dp[i + 1][k] + 2*positions[i]); else suf_dp[i][j] = min(suf_dp[i][j], suf_dp[i + 1][j - 1] + 2*(positions[i] - positions[i + 1])); } } ll ans = INT_MAX; for(int i = 1; i <= n; ++i){ ll mn = INT_MAX; for(int j = 1; j <= k; ++j) mn = min(mn, suf_dp[i + 1][j]); for(int j = 1; j <= k; ++j) ans = min(ans, pre_dp[i][j] + mn); } return ans; }

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

boxes.cpp: In function 'int delivery(int, int, int, int*)':
boxes.cpp:9:18: warning: declaration of 'N' shadows a global declaration [-Wshadow]
    9 | int delivery(int N, int K, int L, int positions[]){
      |              ~~~~^
boxes.cpp:6:11: note: shadowed declaration is here
    6 | const int N = 1e6 + 5;
      |           ^
boxes.cpp:24:24: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   24 |         positions[i] = x;
      |                        ^
boxes.cpp:46:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   46 |     return ans;
      |            ^~~
#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...