Submission #464328

# Submission time Handle Problem Language Result Execution time Memory
464328 2021-08-13T02:48:42 Z sumit_kk10 Boxes with souvenirs (IOI15_boxes) C++14
0 / 100
13 ms 16000 KB
#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;
}

Compilation message

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 time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 16000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -