답안 #379392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
379392 2021-03-18T05:58:53 Z fhvirus Gift (IZhO18_nicegift) C++17
0 / 100
669 ms 116628 KB
// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i=0;i<(n);++i)
#define FOO(i,a,b) for(int i=(a);i<=int(b);++i)
#define OOF(i,a,b) for(int i=(a);i>=int(b);--i)
#define AI(x) begin(x),end(x)
template<class I>bool chmax(I&a,I b){return a<b?(a=b,true):false;}
template<class I>bool chmin(I&a,I b){return b<a?(a=b,true):false;} 
inline ll cdiv(ll x,ll m){return x/m+(x%m?(x<0)^(m>0):0);}
#ifdef OWO
#define safe cerr<<"\033[1;32m"<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<" JIZZ\033[0m\n"
#define debug(args...) SDF(#args, args)
#define OIU(args...) ostream& operator<<(ostream&O,args)
#define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;}
LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss)
template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));}template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';}template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';}
template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));}
#else
#pragma GCC optimize("Ofast")
#define safe ((void)0)
#define debug(...) ((void)0)
#endif
const ll inf = 1e9, INF = 4e18;
const int N = 1e6 + 225;

int n, k;
ll a[N];

inline void fail(){ puts("-1"); exit(0);}

int32_t main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> k;
	FOR(i,n) cin >> a[i];

	ll sum = accumulate(a, a + n, 0ll), y = sum / k;
	if(y * k != sum) fail();
	if(*max_element(a, a + n) > y) fail();

	map<ll, vector<pii>> ms;

	{
		ll cur = 0;
		ll x = 0;
		FOR(i,n){
			ll l = cur, r = cur + a[i];
			if(r > y){
				ms[l].pb(x, i);
				++x;
				ms[0].pb(x, i);
				r -= y;
			} else {
				ms[l].pb(x, i);
			}
			cur = r;
		}
	}
	debug(ms);

	vector<pair<ll, vector<int>>> ans;
	vector<int> cur(k);
	{
		for(auto it = begin(ms); it != prev(end(ms)); ++it){
			auto [x, mod] = *it;
			for(auto [p, i]: mod){
				cur[p] = i;
			}
			ans.pb((*next(it)).ff - x, cur);
			debug(x, cur);
		}
	}

	cout << ans.size() << '\n';
	for(auto [x, v]: ans){
		cout << x << ' ';
		for(int i: v) cout << i + 1 << ' ';
		cout << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Incorrect 1 ms 364 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Incorrect 1 ms 364 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Incorrect 1 ms 364 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 669 ms 116628 KB n=1000000
2 Correct 404 ms 63504 KB n=666666
3 Correct 207 ms 30548 KB n=400000
4 Incorrect 450 ms 77748 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 1 ms 364 KB n=3
4 Incorrect 1 ms 364 KB Not all heaps are empty in the end
5 Halted 0 ms 0 KB -