제출 #930243

#제출 시각아이디문제언어결과실행 시간메모리
930243Cutebol선물상자 (IOI15_boxes)C++17
0 / 100
1 ms348 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std ; const int N = 1e7 + 4 ; template <class T> bool chmax( T& x , const T& y ){ bool f = 0 ; if ( x < y ) x = y , f = 1 ; return f ; } template <class T> bool chmin( T &x , const T &y ){ bool f = 0 ; if ( x > y ) x = y , f = 1 ; return f ; } int dis ( int a , int b , int l ){ if ( a > b ) swap(a,b) ; return min ( b-a , a+(l-b) ) ; } long long delivery(int n, int k, int l, int a[]) { int ans = 0 , m = N , cnt = 0 , p = 0 , left = 0 ; for ( int i = 0 ; i < n ; i ++ ){ if ( a[i] <= l/2 ) continue ; chmin ( m , i ) ; if ( a[i] == a[i+1] ){ cnt ++ ; continue ; } ans += dis(a[i] , p , l ) ; if ( left > cnt ){ p = a[i] ; cnt = 0 ; left -= cnt ; continue ; } if ( left == cnt ){ p = 0 ; cnt = 0 ; left = k ; ans += dis(a[i],0,l) ; continue ; } cnt -= left ; int x = cnt/k ; ans += x*(dis(0,a[i],l)*2) ; cnt %= k ; left = cnt , p = a[i] ; } ans += dis(0,p,l) ; left = k , p = 0 ; cnt = 0 ; for ( int i = m-1 ; i >= 0 ; i -- ){ if ( i && a[i] == a[i-1] ){ cnt ++ ; continue ; } ans += dis(a[i] , p , l ) ; if ( left > cnt ){ p = a[i] ; cnt = 0 ; left -= cnt ; continue ; } cout << a[i] << ' ' << i << endl ; if ( left == cnt ){ p = 0 ; cnt = 0 ; left = k ; ans += dis(0,a[i],l) ; continue ; } cnt -= left ; int x = cnt/k ; ans += x*(dis(0,a[i],l)*2) ; cnt %= k ; left = cnt ; p = a[i] ; if ( !cnt ){ left = k ; p = 0 ; ans += dis(0,a[i],l) ; } cnt = 0 ; cout << ans << ' ' << a[i] << endl ; } ans += dis(0,p,l) ; return ans ; } /* int a[N] ; signed main(){ int n , k , l ; cin >> n >> k >> l ; for ( int i = 0 ; i < n ; i ++ ) cin >> a[i] ; cout << delivery( n , k , l , a ) ; } //*/
#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...