Submission #378852

# Submission time Handle Problem Language Result Execution time Memory
378852 2021-03-17T06:09:04 Z casperwang Gift (IZhO18_nicegift) C++14
0 / 100
11 ms 364 KB
#include <bits/stdc++.h>
#define pb emplace_back
#define pii pair<int,int>
#define ff first
#define ss second
#define All(x) x.begin(), x.end()
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 1000000;
int N, K;
int v[MAXN+1];
int sum, mmax;
vector <pii> arr;
set <int> num;

void update(int x) {
	if (x > 0)
		num.erase(x);
	else
		num.insert(-x);
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> v[i];
		sum += v[i];
		mmax = max(mmax, v[i]);
	}
	if (sum % K || mmax > sum / K) {
		cout << -1 << '\n';
	} else {
		int now = 1;
		for (int i = 1; i <= N; i++) {
			arr.pb(now, -i);
			now += v[i];
			if (now > sum / K) {
				arr.pb(sum / K+1, i);
				now -= sum / K;
				arr.pb(1, -i);
			}
			arr.pb(now, i);
		}
		sort(All(arr));
		int pre;
		for (int i = 0; i < arr.size(); i++) {
			if (i) {
				cout << arr[i].ff - pre;
				for (int j : num) cout << ' ' << j;
				cout << '\n';
			}
			pre = arr[i].ff;
			update(arr[i].ss);
			while (i+1 < arr.size() && arr[i+1].ff == arr[i].ff) {
				update(arr[++i].ss);
			}
		}
	}
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:51:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for (int i = 0; i < arr.size(); i++) {
      |                   ~~^~~~~~~~~~~~
nicegift.cpp:59:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |    while (i+1 < arr.size() && arr[i+1].ff == arr[i].ff) {
      |           ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 364 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -