Submission #481987

# Submission time Handle Problem Language Result Execution time Memory
481987 2021-10-22T14:19:49 Z Lobo Boxes with souvenirs (IOI15_boxes) C++17
0 / 100
1 ms 332 KB
#include "boxes.h"
#include <bits/stdc++.h>
 
using namespace std;
 
const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
 
#define maxn 10000010
 
ll n, kt;
ll dp1[maxn], x1[maxn];
ll dp2[maxn], x2[maxn];
 
long long delivery(int N, int K, int L, int p[]) {
    ii n1 = 0;
    ii n2 = 0;
    kt = K;
    for(ii i = 1; i <= N; i++) {
        dp1[i] = dp2[i] = -1;
        x1[i] = p[i-1];
        x2[i] = L-x1[i];

        if(x1[i] <= x2[i]) {
            n1++;
        }
        else {
            n2++;
        }
    }

    reverse(x1+1,x1+1+n2);
 
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq1;
    pq1.push(mp(0,0));
    for(ii i = 1; i <= n1; i++) {
        ll ans = INFll;
 
        while(pq1.size() && pq1.top().sc < i-kt) pq1.pop();
 
        ans = pq1.top().fr;
 
        dp1[i] = ans + 2*x1[i];
 
        pq1.push(mp(dp1[i],i));
    }
 
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq2;
    pq2.push(mp(0,0));
    for(ii i = 1; i <= n2; i++) {
        ll ans = INFll;
        
        while(pq2.size() && pq2.top().sc < i-kt) pq2.pop();
 
        ans = pq2.top().fr;
 
        dp2[i] = ans + 2*x2[i];
        
        pq2.push(mp(dp2[i],i));
    }
 
    ll ans = dp1[n1]+dp2[n2];
    for(ii i1 = n1-kt, i2 = n2; i1 <= n1; i1++, i2--) {
        ans = min(ans, dp1[i1] + dp2[i2] + L);
    }
 
    return ans;
 
}
 
 
// #include <bits/stdc++.h>
 
// using namespace std;
 
// const long long INFll = (long long) 1e18 + 10;
// const int INFii = (int) 1e9 + 10;
// typedef long long ll;
// typedef int ii;
// typedef long double dbl;
// #define endl '\n'
// #define sc second
// #define fr first
// #define mp make_pair
// #define pb push_back
// #define all(x) x.begin(), x.end()
 
// #define maxn 1100
 
// ll n, kt;
// ll mark1[maxn], dp1[maxn], x1[maxn];
// ll mark2[maxn], dp2[maxn], x2[maxn];
 
// ll sol1(ll i) {
//     if(i == 0) return 0;
//     if(dp1[i] != -1) return dp1[i];
 
//     ll ans = INFll;
 
//     for(ii j = i-1; j >= i-kt && j >= 0; j--) {
//         ans = min(ans, sol1(j));
//     }
 
//     return dp1[i] = ans + x1[i] + min(x1[i],x2[n-i+1]);
// }
 
// ll sol2(ll i) {
//     if(i == 0) return 0;
//     if(dp2[i] != -1) return dp2[i];
 
//     ll ans = INFll;
 
//     for(ii j = i-1; j >= i-kt && j >= 0; j--) {
//         ans = min(ans, sol2(j));
//     }
 
//     return dp2[i] = ans + x2[i] + min(x1[n-i+1],x2[i]);
// }
 
 
// int main() {
//     ios::sync_with_stdio(false); cin.tie(0);
 
//     //freopen("in.in", "r", stdin);
//     //freopen("out.out", "w", stdout);
 
//     ii N, K, L;
//     cin >> N >> K >> L;
//     vector<ii> p;
//     for(ii i = 0; i < N; i++) {
//         ii aa; cin >> aa;
//         p.pb(aa);
//     }
 
//     L--;
//     n = N;
//     kt = K;
//     for(ii i = 1; i <= n; i++) {
//         dp1[i] = dp2[i] = -1;
//         x1[i] = p[i-1];
//         x2[i] = L-x1[i]+1;
//     }
 
//     reverse(x2+1,x2+1+n);
 
//     ll ans = INFll;
//     for(ii i = 0; i <= n; i++) {
//         ans = min(ans, (sol1(i)) + (sol2(n-i)));
//     }
 
//     cout << ans << endl;
 
// }

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:72:19: warning: conversion from 'll' {aka 'long long int'} to 'ii' {aka 'int'} may change value [-Wconversion]
   72 |     for(ii i1 = n1-kt, i2 = n2; i1 <= n1; i1++, i2--) {
      |                 ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -