Submission #176097

#TimeUsernameProblemLanguageResultExecution timeMemory
176097mat_vBoxes with souvenirs (IOI15_boxes)C++14
0 / 100
2 ms380 KiB
#include <bits/stdc++.h> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) #include "boxes.h" #define maxn 10000005 using namespace std; typedef long long ll; int n,k; int niz[maxn]; int d; set<int>s; ll dist(int l, int r){ if(l > r)swap(l, r); ll res = min(r - l, l + d - r); return res; } ll levi[maxn]; ll desni[maxn]; long long delivery(int N, int K, int L, int p[]) { n = N, k = K, d = L; ff(i,1,n)niz[i] = p[i - 1]; ff(i,1,n){ s.insert(niz[i]); } n = s.size(); int br = 1; for(auto c:s){ niz[br++] = c; } levi[0] = 0; desni[n + 1] = 0; ff(i,1,n){ if(k == 1 || i%k == 1){ levi[i] = levi[i - 1] + 2*niz[i]; } else{ levi[i] = levi[i - 1] - niz[i - 1] + niz[i] - niz[i - 1] + niz[i]; } } fb(i,n,1){ int kol = n - i + 1; if(kol%k == 1 || k == 1){ desni[i] = desni[i + 1] + 2*(d-niz[i]); //cout << i << " " << desni[i] << endl; //exit(0); } else{ desni[i] = desni[i + 1] - (d-niz[i + 1]) + (d-niz[i]) - (d-niz[i + 1]) + (d-niz[i]); } } ll res = levi[1] + desni[2]; ff(i,1,n){ res = min(res, levi[i] + desni[i + 1]); } ff(i,1,n){ res = min(res, levi[i - 1] + d + desni[i + k]); } return res; } /* int aa[105]; int N,K,L; int main(){ cin >> N >> K >> L; ff(i,0,N - 1)cin >> aa[i]; cout << delivery(N,K,L,aa); return 0; } /* 3 2 8 1 2 5 */

Compilation message (stderr)

boxes.cpp:70:1: warning: "/*" within comment [-Wcomment]
 /*
  
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:26:15: warning: conversion to 'int' from 'std::set<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
     n = s.size();
         ~~~~~~^~
#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...