답안 #341313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341313 2020-12-29T13:11:18 Z _ani Gift (IZhO18_nicegift) C++17
7 / 100
851 ms 30772 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
const int N = 1'000'002;
pair<ll,int> a[N];
priority_queue<pair<ll, int>> q;
vector<pair<ll, vector<int>>>ans;
int main()
{
	ll n, k;
	ll prv, x = 0;
	bool ok = true;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		prv = x;
		cin >> x;
		if (i != 0 && x != prv)
			ok = false;
		q.push({ x, i });
	}
	if (ok) {
		if (n % k == 0)
		{
			cout << n / k << '\n';
			for (int i = 0; i < n; i+=k)
			{
				cout << x << ' ';
				for (int j = i; j < i + k; j++)
					cout << j + 1 << ' ';
				cout << '\n';
			}
		}
		else if (x % k == 0)
		{
			cout << n << '\n';
			for (int i = 0; i < n; i++)
			{
				cout << x / k << ' ';
				int j = i;
				int c = 0;
				while (c < k)
				{
					cout << j + 1 << ' ';
					j++;
					if (j >= n)
						j %= n;
					c++;
				}
				cout << '\n';
			}
		}
		else cout << -1;
	}
	else {
		while (!q.empty()) {
			vector<int> cur;
			if (q.size() < k)
			{
				cout << -1;
				return 0;
			}
			for (int i = 0; i < k; i++)
			{
				a[i] = q.top();
				cur.push_back(a[i].second);
				q.pop();
			}
			for (int i = 0; i < k - 1; i++)
			{
				a[i].first -= a[k - 1].first;
				if (a[i].first)q.push(a[i]);
			}
			ans.push_back({ a[k - 1].first,cur });
		}
		cout << ans.size() << '\n';
		for (auto b : ans)
		{
			cout << b.first << ' ';
			sort(b.second.begin(), b.second.end());
			for (auto x : b.second)
				cout << x + 1 << ' ';
			cout << '\n';
		}
	}
	return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:61:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   61 |    if (q.size() < k)
      |        ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 0 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 0 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 851 ms 30772 KB n=1000000
2 Correct 547 ms 19196 KB n=666666
3 Correct 316 ms 10696 KB n=400000
4 Correct 508 ms 22248 KB n=285714
5 Correct 23 ms 1256 KB n=20000
6 Correct 424 ms 21384 KB n=181818
7 Correct 8 ms 876 KB n=10000
8 Incorrect 5 ms 696 KB Jury has the answer but participant has not
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 0 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 0 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -