답안 #151947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151947 2019-09-05T15:27:28 Z erebos 선물상자 (IOI15_boxes) C++17
0 / 100
2 ms 376 KB
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
int n;
inline int tozero(int idx) {
	return min(idx, n-idx);
}
bool cmp(int a, int b) {
	return tozero(a)>tozero(b);
}
long long delivery(int N, int K, int L, int p[]) {
	n=N;
	ll ans=0;
	for(int i=0; i<n; ++i) {
		if(p[i]>=K) {
			ans+=(p[i]/K)*(tozero(i)*2);
			p[i]%=K;
			if(p[i]!=0) {
			}
		}
	}
	int s, e=-1, i_have=K;
	for(int i=0; i<n; ++i) {
		if(p[i]) {
			if(i_have==K) {
				s=i;
			}
			if(i_have>p[i]) {
				i_have-=p[i];
				e=i;
			} else if(i_have==p[i]) {
				i_have=K;
				ans+=tozero(s)+tozero(i);
				e=-1;
			} else {
				s=i;
				i_have=i_have+K-(p[i]);
				ans+=tozero(s)+tozero(i);
				e=-1;
			}
		}
	}
	if(e!=-1) {
		ans+=tozero(e);
	}
	return ans;
}

Compilation message

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:12:38: warning: unused parameter 'L' [-Wunused-parameter]
 long long delivery(int N, int K, int L, int p[]) {
                                      ^
boxes.cpp:23:6: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int s, e=-1, i_have=K;
      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -