Submission #519624

#TimeUsernameProblemLanguageResultExecution timeMemory
519624silverfishBoxes with souvenirs (IOI15_boxes)C++17
70 / 100
751 ms524288 KiB
#include <bits/stdc++.h> #include "boxes.h" using namespace std; using ll = long long; const ll N = 10000007, inf = 1e18+10; ll dp[N], s[N]; array<ll,2> fen[N]; void ins(ll v, int p){ int po = p; for(;p<N;p+=p&-p){ if(v < fen[p][0]){ fen[p][0] = v; fen[p][1] = po; } } } int get(int p){ ll mn=inf, mnpos = -1; for(;p>0;p-=p&-p){ if(fen[p][0] < mn){ mn = fen[p][0]; mnpos = fen[p][1]; } } return mnpos; } long long delivery(int n, int k, int L, int p[]) { ll l = L; fill(dp, dp+N, inf); fill(fen, fen+N, array<ll,2>{inf, -1}); for(int i = 0; i < n; ++i){ s[i] = (i ? dp[i-1] : 0) + min(2LL*(l-p[i]), l); ins(s[i], n-i); int pos = n-get(n-i+k-1); // cout << pos << ' ' << get(n-i+k-1) << ' ' << (n-i+k-1) <<'\n'; dp[i] = dp[pos-1]+min({l,2LL*p[i], 2LL*(l-p[pos])}); } return dp[n-1]; }

Compilation message (stderr)

boxes.cpp: In function 'int get(int)':
boxes.cpp:28:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   28 |         return mnpos;
      |                ^~~~~
#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...