답안 #378695

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378695 2021-03-17T03:17:56 Z fhvirus Gift (IZhO18_nicegift) C++17
7 / 100
18 ms 1132 KB
// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long 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 <= (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 a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr << endl;}
template<class I, class...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<class I> void DE(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
const int N = 1e5 + 225;
int n, k;
ll a[N];

template<typename T> using maxheap = 
	priority_queue<T, vector<T>>;

int32_t main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> k;
	if(k != 2) return 7122;
	FOO(i,1,n) cin >> a[i];
	ll sum = 0;
	FOO(i,1,n) sum += a[i];
	if(sum % 2 == 1){
		cout << -1;
		return 0;
	}
	FOO(i,1,n){
		if(a[i] * 2 > sum){
			cout << -1;
			return 0;
		}
	}

	maxheap<pair<ll, int>> pq;
	FOO(i,1,n) if(a[i]) pq.emplace(a[i], i);

	vector<pair<int, vector<int>>> ans;
	while(!pq.empty()){
		if(pq.size() == 1){
			cout << -1;
			return 0;
		}
		auto [s, i] = pq.top(); pq.pop();
		auto [t, j] = pq.top(); pq.pop();

		ans.pb(a[j], vector<int>());
		ans.back().ss.pb(i);
		ans.back().ss.pb(j);

		a[i] -= a[j];
		a[j] = 0;
		if(a[i]) pq.emplace(a[i], i);
	}
	cout << ans.size() << '\n';
	for(auto [x, v]: ans){
		cout << x << ' ';
		for(auto i: v) cout << i << ' ';
		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 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# 결과 실행 시간 메모리 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 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 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 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 1132 KB Added number should be positive
2 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 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 1 ms 364 KB n=8
9 Incorrect 1 ms 364 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -