Submission #287370

# Submission time Handle Problem Language Result Execution time Memory
287370 2020-08-31T16:32:07 Z Berted Chessboard (IZhO18_chessboard) C++14
0 / 100
7 ms 1920 KB
#include <iostream>
#include <list>
#include <vector>
#include <algorithm>
#define ll long long
#define vi vector<int>
#define piv pair<ll, vector<int>>
#define pii pair<ll, int>
#define fst first
#define snd second
using namespace std;

int N, K;
ll S = 0;
pii A[1000001];
list<piv> L;

int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N >> K;
	for (int i = 0; i < N; i++) {cin >> A[i].fst; A[i].snd = i; S += A[i].fst;}
	
	if (S % K) {cout << "-1\n";}
	else
	{
		sort(A, A + N, greater<pii>()); S /= K;
		if (A[0].fst <= S)
		{
			L.push_back({S, vi()});
			auto it = L.begin();
			for (int i = 0; i < N; i++)
			{
				while (A[i].fst)
				{
					if (it -> fst > A[i].fst)
					{
						it -> fst -= A[i].fst;
						vector<int> cpy = it -> snd;
						cpy.push_back(A[i].snd + 1);
						L.insert(it, make_pair(A[i].fst, cpy));
						A[i].fst = 0;
					}
					else
					{
						A[i].fst -= it -> fst;
						it -> snd.push_back(A[i].snd + 1);
						it = next(it);
						if (it == L.end()) {it = L.begin();}
					}
				}
			}
			cout << L.size() << "\n";
			for (const auto &x : L)
			{
				cout << x.fst;
				for (const auto &y : x.snd) {cout << " " << y;}
				cout << "\n";
			}
		}
		else {cout << "-1\n";}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 512 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 512 KB Execution killed with signal 8
2 Halted 0 ms 0 KB -