답안 #378848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378848 2021-03-17T06:04:03 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, i);
				now -= sum / K;
				arr.pb(1, -i);
			}
			arr.pb(now, i);
		}
		sort(All(arr));
		// for (auto [p, v] : arr) debug(p, v);
		int pre = 1;
		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:52: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]
   52 |   for (int i = 0; i < arr.size(); i++) {
      |                   ~~^~~~~~~~~~~~
nicegift.cpp:60: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]
   60 |    while (i+1 < arr.size() && arr[i+1].ff == arr[i].ff) {
      |           ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 364 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -