Submission #483515

# Submission time Handle Problem Language Result Execution time Memory
483515 2021-10-30T07:12:58 Z keta_tsimakuridze Gift (IZhO18_nicegift) C++14
18 / 100
1280 ms 89156 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 = 1e6 + 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;
		exit(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 = 0;
		}
	}
	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);
		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:52: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]
   52 |  for(int i = 0; i < ans.size(); i++) {
      |                 ~~^~~~~~~~~~~~
nicegift.cpp:53: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]
   53 |   for(int j = 0; j < ans[i].size(); j++) {
      |                  ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB n=4
2 Correct 13 ms 23756 KB n=3
3 Correct 13 ms 23784 KB n=3
4 Correct 13 ms 23780 KB n=4
5 Correct 13 ms 23792 KB n=4
6 Correct 12 ms 23744 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB n=4
2 Correct 13 ms 23756 KB n=3
3 Correct 13 ms 23784 KB n=3
4 Correct 13 ms 23780 KB n=4
5 Correct 13 ms 23792 KB n=4
6 Correct 12 ms 23744 KB n=2
7 Correct 14 ms 23756 KB n=5
8 Correct 15 ms 23680 KB n=8
9 Correct 13 ms 23756 KB n=14
10 Correct 14 ms 23720 KB n=11
11 Correct 88 ms 27824 KB n=50000
12 Correct 83 ms 27660 KB n=50000
13 Correct 12 ms 23756 KB n=10
14 Correct 16 ms 23756 KB n=685
15 Correct 14 ms 23756 KB n=623
16 Correct 15 ms 23880 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB n=4
2 Correct 13 ms 23756 KB n=3
3 Correct 13 ms 23784 KB n=3
4 Correct 13 ms 23780 KB n=4
5 Correct 13 ms 23792 KB n=4
6 Correct 12 ms 23744 KB n=2
7 Correct 14 ms 23756 KB n=5
8 Correct 15 ms 23680 KB n=8
9 Correct 13 ms 23756 KB n=14
10 Correct 14 ms 23720 KB n=11
11 Correct 88 ms 27824 KB n=50000
12 Correct 83 ms 27660 KB n=50000
13 Correct 12 ms 23756 KB n=10
14 Correct 16 ms 23756 KB n=685
15 Correct 14 ms 23756 KB n=623
16 Correct 15 ms 23880 KB n=973
17 Runtime error 34 ms 48320 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1280 ms 89156 KB n=1000000
2 Correct 695 ms 62996 KB n=666666
3 Correct 358 ms 43948 KB n=400000
4 Runtime error 220 ms 78532 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23756 KB n=4
2 Correct 13 ms 23756 KB n=3
3 Correct 13 ms 23784 KB n=3
4 Correct 13 ms 23780 KB n=4
5 Correct 13 ms 23792 KB n=4
6 Correct 12 ms 23744 KB n=2
7 Correct 14 ms 23756 KB n=5
8 Correct 15 ms 23680 KB n=8
9 Correct 13 ms 23756 KB n=14
10 Correct 14 ms 23720 KB n=11
11 Correct 88 ms 27824 KB n=50000
12 Correct 83 ms 27660 KB n=50000
13 Correct 12 ms 23756 KB n=10
14 Correct 16 ms 23756 KB n=685
15 Correct 14 ms 23756 KB n=623
16 Correct 15 ms 23880 KB n=973
17 Runtime error 34 ms 48320 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -