답안 #41089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41089 2018-02-12T15:10:19 Z IvanC Stove (JOI18_stove) C++14
0 / 100
2 ms 480 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int vetor[MAXN],N,K;
int func(int val){
	int ini = -1,fim = -1;
	int tot = 0;
	for(int i = 1;i<=N;i++){
		if(vetor[i] + 1 > fim){
			ini = vetor[i];
			fim = vetor[i] + val;
			tot += 1;
		}
	}
	return tot;
}
int calc(int val){
	int ini = -1,fim = -1,last = -1;
	int tot = 0;
	for(int i = 1;i<=N;i++){
		if(vetor[i] + 1 > fim){
			tot += last - ini;
			ini = vetor[i];
			fim = vetor[i] + val;
			last = vetor[i] + 1;
		}
		else{
			last = vetor[i] + 1;
		}
	}
	tot += last - ini;
	return tot;
}
int main(){
	scanf("%d %d",&N,&K);
	for(int i = 1;i<=N;i++) scanf("%d",&vetor[i]);
	int ini = 1,fim = (int)1e9,meio,resp = -1;
	while(ini <= fim){
		meio = (ini+fim)/2;
		if(func(meio) <= K){
			resp = meio;
			fim = meio - 1;
		}
		else{
			ini = meio + 1;
		}
	}
	printf("%d\n",calc(resp));
	return 0;
}

Compilation message

stove.cpp: In function 'int func(int)':
stove.cpp:6:6: warning: variable 'ini' set but not used [-Wunused-but-set-variable]
  int ini = -1,fim = -1;
      ^
stove.cpp: In function 'int main()':
stove.cpp:35:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&N,&K);
                      ^
stove.cpp:36:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1;i<=N;i++) scanf("%d",&vetor[i]);
                                               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 2 ms 480 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 2 ms 480 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 2 ms 480 KB Output isn't correct
3 Halted 0 ms 0 KB -