# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
386685 |
2021-04-07T08:17:58 Z |
vanic |
Gift (IZhO18_nicegift) |
C++14 |
|
2000 ms |
203924 KB |
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <vector>
#include <array>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
ll a[maxn];
ll sum;
array < ll, 3 > v[maxn*4];
set < int > cur;
vector < vector < int > > sol;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
for(int i=0; i<n; i++){
cin >> a[i];
sum+=a[i];
}
if(sum%k){
cout << -1 << '\n';
return 0;
}
sum/=k;
for(int i=0; i<n; i++){
if(a[i]>sum){
cout << -1 << '\n';
return 0;
}
}
int pos=0;
int iduc;
int br=0;
for(int i=0; i<n; i++){
iduc=pos+a[i];
if(iduc>sum){
v[br]={pos, i+1, 1};
br++;
v[br]={sum, i+1, 0};
br++;
iduc-=sum;
pos=0;
}
v[br]={pos, i+1, 1};
br++;
v[br]={iduc, i+1, 0};
br++;
if(iduc==sum){
iduc=0;
}
pos=iduc;
}
sort(v, v+br);
vector < int > vi;
for(int i=0; i<br; i++){
if(v[i][2]){
cur.insert(v[i][1]);
}
else{
cur.erase(v[i][1]);
}
if(i==br-1 || v[i][0]==v[i+1][0]){
continue;
}
vi.push_back(v[i+1][0]-v[i][0]);
for(set < int >::iterator it=cur.begin(); it!=cur.end(); it++){
vi.push_back(*it);
}
sol.push_back(vi);
vi.clear();
}
cout << sol.size() << '\n';
for(int i=0; i<(int)sol.size(); i++){
for(int j=0; j<k+1; j++){
cout << sol[i][j] << ' ';
}
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 |
2 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
496 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 |
2 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
496 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 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
2 ms |
364 KB |
n=11 |
11 |
Correct |
43 ms |
6048 KB |
n=50000 |
12 |
Correct |
35 ms |
5920 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
2 ms |
492 KB |
n=685 |
15 |
Correct |
2 ms |
492 KB |
n=623 |
16 |
Correct |
2 ms |
492 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
2 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
496 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 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
2 ms |
364 KB |
n=11 |
11 |
Correct |
43 ms |
6048 KB |
n=50000 |
12 |
Correct |
35 ms |
5920 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
2 ms |
492 KB |
n=685 |
15 |
Correct |
2 ms |
492 KB |
n=623 |
16 |
Correct |
2 ms |
492 KB |
n=973 |
17 |
Correct |
2 ms |
492 KB |
n=989 |
18 |
Correct |
3 ms |
492 KB |
n=563 |
19 |
Correct |
3 ms |
492 KB |
n=592 |
20 |
Correct |
3 ms |
512 KB |
n=938 |
21 |
Correct |
2 ms |
492 KB |
n=747 |
22 |
Correct |
3 ms |
492 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2093 ms |
203924 KB |
Time limit exceeded |
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 |
2 ms |
364 KB |
n=3 |
4 |
Correct |
1 ms |
364 KB |
n=4 |
5 |
Correct |
1 ms |
496 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 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
2 ms |
364 KB |
n=11 |
11 |
Correct |
43 ms |
6048 KB |
n=50000 |
12 |
Correct |
35 ms |
5920 KB |
n=50000 |
13 |
Correct |
1 ms |
364 KB |
n=10 |
14 |
Correct |
2 ms |
492 KB |
n=685 |
15 |
Correct |
2 ms |
492 KB |
n=623 |
16 |
Correct |
2 ms |
492 KB |
n=973 |
17 |
Correct |
2 ms |
492 KB |
n=989 |
18 |
Correct |
3 ms |
492 KB |
n=563 |
19 |
Correct |
3 ms |
492 KB |
n=592 |
20 |
Correct |
3 ms |
512 KB |
n=938 |
21 |
Correct |
2 ms |
492 KB |
n=747 |
22 |
Correct |
3 ms |
492 KB |
n=991 |
23 |
Execution timed out |
2093 ms |
203924 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |