답안 #386862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386862 2021-04-07T14:06:02 Z vanic Gift (IZhO18_nicegift) C++14
컴파일 오류
0 ms 0 KB
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
 
using namespace std;
typedef long long ll;
 
const int maxn=1e6+5;
 
ll a[maxn];
ll sum;
pair < ll, int > v[maxn*3];
set < int > cur;
  
int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i=0; i<n; ++i){
		scanf("%lld", a+i);
		sum+=a[i];
	}
	if(sum%k){
		printf("-1\n");
		return 0;
	}
	sum/=k;
	for(int i=0; i<n; ++i){
		if(a[i]>sum){
			printf("-1\n");
			return 0;
		}
	}
	int pos=0;
	int iduc;
	int br=0;
	for(int i=0; i<n; ++i){
		iduc=pos+a[i];
		if(iduc>sum){
			v[br]={pos, i+1};
			++br;
			iduc-=sum;
			pos=0;
		}
		v[br]={pos, i+1};
		++br;
		if(iduc!=sum){
			v[br]={iduc, -i-1};
			++br;
		}
		else{
			iduc=0;
		}
		pos=iduc;
	}
	v[br]={sum, 0};
	++br;
	sort(v, v+br);
	int sol=0;
	for(int i=0; i<br-1; ++i){
		if(v[i].first!=v[i+1].first){
			++sol;
		}
	}
	printf("%d\n", sol);
	assert(0);
	for(int i=0; i<br-1; ++i){
		if(v[i].second>0){
			cur.insert(v[i].second);
		}
		else{
			cur.erase(-v[i].second);
		}
		if(v[i].first==v[i+1].first){
			continue;
		}
		printf("%lld ", v[i+1].first-v[i].first);
		for(int x : cur){
			printf("%d ", x);
		}
		printf("\n");
	}
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:66:2: error: 'assert' was not declared in this scope
   66 |  assert(0);
      |  ^~~~~~
nicegift.cpp:5:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    4 | #include <set>
  +++ |+#include <cassert>
    5 | 
nicegift.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
nicegift.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |   scanf("%lld", a+i);
      |   ~~~~~^~~~~~~~~~~~~