제출 #67904

#제출 시각아이디문제언어결과실행 시간메모리
67904theknife2001선물상자 (IOI15_boxes)C++17
10 / 100
3 ms376 KiB
#include "boxes.h" //#include "grader.cpp" #include <bits/stdc++.h> #define mid (l+r)/2 using namespace std; const int N=1e7+55; long long tree[N*4][2]; long long dp[N][2]; int n; void build(int l , int r , int node) { if(l==r) { tree[node][0]=1e9+55; tree[node][1]=1e9+55; return ; } build(l,mid,node*2); build(mid+1,r,node*2+1); tree[node][0]=1e9+55; tree[node][1]=1e9+55; } void update(int l , int r , int node, int ind , int val , int q) { if(l==r&&l==ind) { tree[node][q]=val; return ; } if(ind<=mid) update(l,mid,node*2,ind,val,q); else update(mid+1,r,node*2+1,ind,val,q); tree[node][q]=min(tree[node*2][q],tree[node*2+1][q]); } long long query(int l , int r , int node , int x , int y , int q) { if(l>y||r<x) return 1e9+55; if(x<=l&&r<=y) return tree[node][q]; return min(query(l,mid,node*2,x,y,q),query(mid+1,r,node*2+1,x,y,q)); } long long delivery(int N, int k, int L, int p[]) { n=N; build(0,n-1,1); int j=0; for(;j<n;j++) if(p[j]) break; if(j==n) return 0; int x=k; j=0; for(int i=0;i<n;i++) { while(p[i]==0) { i++; j++; } if(i-j>=x) { dp[i][0]=query(0,n-1,1,i-x,i,0)+p[i]+min(p[i],L-p[i]); // cout<<i<<' '<<dp[i][0]<<endl; } else { dp[i][0]=p[i]+min(p[i],L-p[i]); // cout<<i<<' '<<dp[i][0]<<endl; } update(0,n-1,1,i,dp[i][0],0); } for(int i=n-1;i>=0;i--) { if(p[i]==0) break; if(i+x<n) { dp[i][1]=query(0,n-1,1,i,i+x,1)+(L-p[i])+min(p[i],L-p[i]); } else { dp[i][1]=L-p[i]+min(p[i],L-p[i]); } update(0,n-1,1,i,dp[i][1],1); } int i=0; while(p[i]==0) i++; // cout<<i<<endl; long long ans=dp[i][1]; // cerr<<ans<<endl; for(;i<n;i++) { ans=min(dp[i][0]+(i+1<n?dp[i+1][1]:0),ans); // cerr<<i<<' '<<dp[i][0]+(i+1<n?dp[i+1][1]:0)<<endl; } return ans; } /* 10 5 100 1 5 20 35 41 42 55 56 57 58 */

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

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:52:48: warning: declaration of 'N' shadows a global declaration [-Wshadow]
 long long delivery(int N, int k, int L, int p[])
                                                ^
boxes.cpp:8:11: note: shadowed declaration is here
 const int N=1e7+55;
           ^
boxes.cpp:81:33: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         update(0,n-1,1,i,dp[i][0],0);
                          ~~~~~~~^
boxes.cpp:96:33: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         update(0,n-1,1,i,dp[i][1],1);
                          ~~~~~~~^
#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...