답안 #386865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386865 2021-04-07T14:10:49 Z vanic Gift (IZhO18_nicegift) C++14
30 / 100
2000 ms 122528 KB
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <cassert>
#include <vector>
 
using namespace std;
typedef long long ll;
 
const int maxn=1e6+5;
 
ll a[maxn];
ll sum;
vector < pair < ll, int > > v;
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;
	for(int i=0; i<n; ++i){
		iduc=pos+a[i];
		if(iduc>sum){
			v.push_back({pos, i+1});
			iduc-=sum;
			pos=0;
		}
		v.push_back({pos, i+1});
		if(iduc!=sum){
			v.push_back({iduc, -i-1});
		}
		else{
			iduc=0;
		}
		pos=iduc;
	}
	v.push_back({sum, 0});
	sort(v.begin(), v.end());
	int sol=0;
	for(int i=0; i<(int)v.size()-1; ++i){
		if(v[i].first!=v[i+1].first){
			++sol;
		}
	}
	printf("%d\n", sol);
	for(int i=0; i<(int)v.size()-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:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |  scanf("%d%d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~
nicegift.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |   scanf("%lld", a+i);
      |   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 2 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 2 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 36 ms 3036 KB n=50000
12 Correct 34 ms 3036 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 2 ms 364 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 2 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 36 ms 3036 KB n=50000
12 Correct 34 ms 3036 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 2 ms 364 KB n=973
17 Correct 2 ms 364 KB n=989
18 Correct 2 ms 364 KB n=563
19 Correct 3 ms 364 KB n=592
20 Correct 3 ms 492 KB n=938
21 Correct 2 ms 384 KB n=747
22 Correct 3 ms 364 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2088 ms 122528 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 2 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 1 ms 364 KB n=14
10 Correct 1 ms 364 KB n=11
11 Correct 36 ms 3036 KB n=50000
12 Correct 34 ms 3036 KB n=50000
13 Correct 1 ms 364 KB n=10
14 Correct 1 ms 364 KB n=685
15 Correct 1 ms 364 KB n=623
16 Correct 2 ms 364 KB n=973
17 Correct 2 ms 364 KB n=989
18 Correct 2 ms 364 KB n=563
19 Correct 3 ms 364 KB n=592
20 Correct 3 ms 492 KB n=938
21 Correct 2 ms 384 KB n=747
22 Correct 3 ms 364 KB n=991
23 Execution timed out 2088 ms 122528 KB Time limit exceeded
24 Halted 0 ms 0 KB -