# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378860 | 2021-03-17T06:30:32 Z | Seanliu | Gift (IZhO18_nicegift) | C++14 | 2 ms | 1004 KB |
#include <iostream> #include <map> #include <deque> #include <vector> #define int long long int using namespace std; const int maxN = 1e2 + 326; map<int, deque<int>> mp; vector<vector<int>> ans; int N, K, arr[maxN]; int sm[maxN]; struct Obj{ int num; deque<int> poss; Obj(){} Obj(int num, deque<int> dq): num(num), poss(dq){} }; deque<Obj> has[maxN]; signed main(){ cin >> N >> K; for(int i = 1; i <= N; i++){ cin >> arr[i]; if(!mp.count(arr[i])){ mp[arr[i]] = deque<int>(); } mp[arr[i]].push_back(i); } for(auto &[v, vec] : mp){ while(vec.size() >= K){ vector<int> tmp = vector<int>(); tmp.push_back(v); for(int i = 0; i < K; i++){ tmp.push_back(vec.front()); vec.pop_front(); } ans.push_back(tmp); } if(vec.size()){ has[vec.size()].emplace_back(v, vec); sm[vec.size()] += v; } } for(int i = 1; i < K && i <= (K - i); i++){ if(sm[i] != sm[K - i]){ cout << -1 << endl; return 0; } while(has[i].size()){ vector<int> tmp = vector<int>(); tmp.push_back(min(has[i].front().num, has[K - i].front().num)); for(int x : has[i].front().poss) tmp.push_back(x); for(int x : has[K - i].front().poss) tmp.push_back(x); ans.push_back(tmp); if(tmp[0] == has[i].front().num) has[i].pop_front(); else { has[i][0].num -= tmp[0]; } if(tmp[0] == has[K - i].front().num) has[K - i].pop_front(); else { has[K - i][0].num -= tmp[0]; } } } cout << ans.size() << endl; for(auto v : ans){ for(int x : v) cout << x << " "; cout << endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 620 KB | n=4 |
2 | Incorrect | 1 ms | 620 KB | Same heap occurs twice |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 620 KB | n=4 |
2 | Incorrect | 1 ms | 620 KB | Same heap occurs twice |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 620 KB | n=4 |
2 | Incorrect | 1 ms | 620 KB | Same heap occurs twice |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 2 ms | 1004 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 620 KB | n=4 |
2 | Incorrect | 1 ms | 620 KB | Same heap occurs twice |
3 | Halted | 0 ms | 0 KB | - |