# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
99768 | 2019-03-07T01:34:56 Z | choikiwon | Gift (IZhO18_nicegift) | C++17 | 2000 ms | 196864 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MN = 1000010; int N, K; priority_queue<pair<ll, int> > pq; vector<vector<int> > S; vector<ll> X; int main() { std::ios::sync_with_stdio(false); cin >> N >> K; ll sum = 0; for(int i = 0; i < N; i++) { ll t; cin >> t; pq.push({t, i}); sum += t; } if(sum % K) { cout << -1; return 0; } while(!pq.empty()) { vector<pair<ll, int> > V; for(int i = 0; i < K; i++) { if(pq.empty()) { printf("-1"); return 0; } V.push_back(pq.top()); pq.pop(); } /* for(int i = 0; i < V.size(); i++) { cout << V[i].first << ' '; } cout << endl; //*/ if(pq.empty() || V.back().first < V[0].first - pq.top().first) { X.push_back(V.back().first); S.push_back(vector<int>()); for(int i = 0; i < K; i++) { S.back().push_back(V[i].second); V[i].first -= X.back(); } } else { ll d = (V.back().first + K - 2) * (K - 1) / K; ll t = V[0].first - pq.top().first; X.push_back(max(t, V.back().first - d)); S.push_back(vector<int>()); for(int i = 0; i < K; i++) { S.back().push_back(V[i].second); V[i].first -= X.back(); } } //cout << X.back() << endl; for(int i = 0; i < K; i++) { if(V[i].first) { pq.push(V[i]); } } } cout << X.size() << '\n'; for(int i = 0; i < X.size(); i++) { cout << X[i] << ' '; for(int j = 0; j < S[i].size(); j++) { cout << S[i][j] + 1 << ' '; } cout << '\n'; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | n=4 |
2 | Correct | 2 ms | 384 KB | n=3 |
3 | Correct | 2 ms | 256 KB | n=3 |
4 | Correct | 2 ms | 384 KB | n=4 |
5 | Correct | 2 ms | 384 KB | n=4 |
6 | Correct | 2 ms | 300 KB | n=2 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | n=4 |
2 | Correct | 2 ms | 384 KB | n=3 |
3 | Correct | 2 ms | 256 KB | n=3 |
4 | Correct | 2 ms | 384 KB | n=4 |
5 | Correct | 2 ms | 384 KB | n=4 |
6 | Correct | 2 ms | 300 KB | n=2 |
7 | Correct | 2 ms | 384 KB | n=5 |
8 | Correct | 2 ms | 384 KB | n=8 |
9 | Correct | 3 ms | 384 KB | n=14 |
10 | Correct | 3 ms | 384 KB | n=11 |
11 | Correct | 33 ms | 3820 KB | n=50000 |
12 | Correct | 39 ms | 3440 KB | n=50000 |
13 | Correct | 3 ms | 512 KB | n=10 |
14 | Correct | 5 ms | 640 KB | n=685 |
15 | Correct | 5 ms | 640 KB | n=623 |
16 | Correct | 5 ms | 640 KB | n=973 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | n=4 |
2 | Correct | 2 ms | 384 KB | n=3 |
3 | Correct | 2 ms | 256 KB | n=3 |
4 | Correct | 2 ms | 384 KB | n=4 |
5 | Correct | 2 ms | 384 KB | n=4 |
6 | Correct | 2 ms | 300 KB | n=2 |
7 | Correct | 2 ms | 384 KB | n=5 |
8 | Correct | 2 ms | 384 KB | n=8 |
9 | Correct | 3 ms | 384 KB | n=14 |
10 | Correct | 3 ms | 384 KB | n=11 |
11 | Correct | 33 ms | 3820 KB | n=50000 |
12 | Correct | 39 ms | 3440 KB | n=50000 |
13 | Correct | 3 ms | 512 KB | n=10 |
14 | Correct | 5 ms | 640 KB | n=685 |
15 | Correct | 5 ms | 640 KB | n=623 |
16 | Correct | 5 ms | 640 KB | n=973 |
17 | Execution timed out | 2107 ms | 190464 KB | Time limit exceeded |
18 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2021 ms | 196864 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | n=4 |
2 | Correct | 2 ms | 384 KB | n=3 |
3 | Correct | 2 ms | 256 KB | n=3 |
4 | Correct | 2 ms | 384 KB | n=4 |
5 | Correct | 2 ms | 384 KB | n=4 |
6 | Correct | 2 ms | 300 KB | n=2 |
7 | Correct | 2 ms | 384 KB | n=5 |
8 | Correct | 2 ms | 384 KB | n=8 |
9 | Correct | 3 ms | 384 KB | n=14 |
10 | Correct | 3 ms | 384 KB | n=11 |
11 | Correct | 33 ms | 3820 KB | n=50000 |
12 | Correct | 39 ms | 3440 KB | n=50000 |
13 | Correct | 3 ms | 512 KB | n=10 |
14 | Correct | 5 ms | 640 KB | n=685 |
15 | Correct | 5 ms | 640 KB | n=623 |
16 | Correct | 5 ms | 640 KB | n=973 |
17 | Execution timed out | 2107 ms | 190464 KB | Time limit exceeded |
18 | Halted | 0 ms | 0 KB | - |