# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
378677 |
2021-03-17T03:07:55 Z |
fhvirus |
Gift (IZhO18_nicegift) |
C++17 |
|
1390 ms |
524292 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 & 1){
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()){
auto [s, i] = pq.top(); pq.pop();
auto [t, j] = pq.top(); pq.pop();
ll x = min(a[i], a[j]);
a[i] -= x;
a[j] -= x;
ans.pb(x, vector<int>());
ans.back().ss.pb(i);
ans.back().ss.pb(j);
if(a[i]) pq.emplace(a[i], i);
if(a[j]) pq.emplace(a[j], j);
}
cout << ans.size() << '\n';
for(auto [x, v]: ans){
cout << x << ' ';
for(auto i: v) cout << i << ' ';
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
512 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
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 |
512 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Runtime error |
1390 ms |
524292 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
512 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Runtime error |
1390 ms |
524292 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
1132 KB |
Added number should be positive |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
512 KB |
n=4 |
5 |
Correct |
1 ms |
364 KB |
n=4 |
6 |
Correct |
1 ms |
364 KB |
n=2 |
7 |
Correct |
0 ms |
364 KB |
n=5 |
8 |
Runtime error |
1390 ms |
524292 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |