Submission #483519

# Submission time Handle Problem Language Result Execution time Memory
483519 2021-10-30T07:52:40 Z keta_tsimakuridze Gift (IZhO18_nicegift) C++14
30 / 100
104 ms 13020 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define pii pair<int,int>
#define int long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7; // !
int t,a[N],n,k;
vector<pii> v[N];
vector<vector<int> > ans;
set<pii> s;
main(){
	cin >> n >> k;
	int mx = 0, sum = 0;
	for(int i = 1; i <= n; i++) cin >> a[i], sum += a[i], mx = max(mx, a[i]);
	if(sum % k || mx > sum/k) {
		cout << -1;
		return 0;
	}
	sum /= k;
	int cur = 0, c = 0;
	for(int i = 1; i <= n; i++) {
		if(cur == sum) c++, cur = 0;
		int x = min(a[i], sum - cur);
		cur += x; // cout << i <<" " << x << endl;
		v[c].push_back({i, x});
		if(a[i] > x) {
			c++;
			v[c].push_back({i, a[i] - x});
			cur = a[i] - x;
		}
	}
	for(int i = 0; i <= c; i++) reverse(v[i].begin(), v[i].end()), 
								s.insert({v[i].back().s, i});
	while(s.size()) {
		int x = (*s.begin()).f;
		vector<int> a;
		a.push_back(x);
		assert(x > 0);
		for(set<pii> :: iterator it = s.begin(); it != s.end(); it++) {
			a.push_back( v[(*it).s].back().f);
			v[(*it).s].back().s -= x;
			if(!v[(*it).s].back().s) v[(*it).s].pop_back();
		}
		ans.push_back(a);
		s.clear();
		if(!v[0].size()) break;
		for(int i = 0; i <= c; i++) {
			s.insert({v[i].back().s, i});
		}
	}
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++) {
		for(int j = 0; j < ans[i].size(); j++) {
			cout << ans[i][j] <<" ";
		}
		cout << endl;
	}
}

Compilation message

nicegift.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main(){
      | ^~~~
nicegift.cpp: In function 'int main()':
nicegift.cpp:53:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |  for(int i = 0; i < ans.size(); i++) {
      |                 ~~^~~~~~~~~~~~
nicegift.cpp:54:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int j = 0; j < ans[i].size(); j++) {
      |                  ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB n=4
2 Correct 3 ms 4940 KB n=3
3 Correct 2 ms 4940 KB n=3
4 Correct 3 ms 4940 KB n=4
5 Correct 3 ms 4940 KB n=4
6 Correct 3 ms 4940 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB n=4
2 Correct 3 ms 4940 KB n=3
3 Correct 2 ms 4940 KB n=3
4 Correct 3 ms 4940 KB n=4
5 Correct 3 ms 4940 KB n=4
6 Correct 3 ms 4940 KB n=2
7 Correct 3 ms 4940 KB n=5
8 Correct 3 ms 4940 KB n=8
9 Correct 2 ms 4940 KB n=14
10 Correct 3 ms 4940 KB n=11
11 Correct 77 ms 9092 KB n=50000
12 Correct 72 ms 8916 KB n=50000
13 Correct 3 ms 4980 KB n=10
14 Correct 4 ms 5068 KB n=685
15 Correct 4 ms 5068 KB n=623
16 Correct 4 ms 5068 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB n=4
2 Correct 3 ms 4940 KB n=3
3 Correct 2 ms 4940 KB n=3
4 Correct 3 ms 4940 KB n=4
5 Correct 3 ms 4940 KB n=4
6 Correct 3 ms 4940 KB n=2
7 Correct 3 ms 4940 KB n=5
8 Correct 3 ms 4940 KB n=8
9 Correct 2 ms 4940 KB n=14
10 Correct 3 ms 4940 KB n=11
11 Correct 77 ms 9092 KB n=50000
12 Correct 72 ms 8916 KB n=50000
13 Correct 3 ms 4980 KB n=10
14 Correct 4 ms 5068 KB n=685
15 Correct 4 ms 5068 KB n=623
16 Correct 4 ms 5068 KB n=973
17 Correct 4 ms 5068 KB n=989
18 Correct 4 ms 5068 KB n=563
19 Correct 6 ms 5196 KB n=592
20 Correct 6 ms 5196 KB n=938
21 Correct 5 ms 5132 KB n=747
22 Correct 6 ms 5196 KB n=991
# Verdict Execution time Memory Grader output
1 Runtime error 104 ms 13020 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4940 KB n=4
2 Correct 3 ms 4940 KB n=3
3 Correct 2 ms 4940 KB n=3
4 Correct 3 ms 4940 KB n=4
5 Correct 3 ms 4940 KB n=4
6 Correct 3 ms 4940 KB n=2
7 Correct 3 ms 4940 KB n=5
8 Correct 3 ms 4940 KB n=8
9 Correct 2 ms 4940 KB n=14
10 Correct 3 ms 4940 KB n=11
11 Correct 77 ms 9092 KB n=50000
12 Correct 72 ms 8916 KB n=50000
13 Correct 3 ms 4980 KB n=10
14 Correct 4 ms 5068 KB n=685
15 Correct 4 ms 5068 KB n=623
16 Correct 4 ms 5068 KB n=973
17 Correct 4 ms 5068 KB n=989
18 Correct 4 ms 5068 KB n=563
19 Correct 6 ms 5196 KB n=592
20 Correct 6 ms 5196 KB n=938
21 Correct 5 ms 5132 KB n=747
22 Correct 6 ms 5196 KB n=991
23 Runtime error 104 ms 13020 KB Execution killed with signal 11
24 Halted 0 ms 0 KB -