답안 #930243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930243 2024-02-19T07:37:35 Z Cutebol 선물상자 (IOI15_boxes) C++17
0 / 100
1 ms 348 KB
#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 ) ;
}
//*/
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -