# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378780 | 2021-03-17T04:07:56 Z | daniel920712 | Gift (IZhO18_nicegift) | C++14 | 408 ms | 23168 KB |
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <stack> #include <map> #include <vector> using namespace std; map < long long , stack < long long > > all; vector < vector < long long > > que; vector < long long > ttt; vector < pair < long long , long long > > tt2; long long F(long long a,long long b) { if(b==0) return a; return F(b,a%b); } int main() { //freopen("aa.txt","w+t",stdout); long long N,K,i,j,ans=0,x,y,a,b,t,xx,tt,now,con; scanf("%lld %lld",&N,&K); for(i=1;i<=N;i++) { scanf("%lld",&t); all[t].push(i); ans+=t; xx=t; } if(ans%K) printf("-1\n"); else if(ans<=100000) { while(!all.empty()) { ttt.clear(); tt2.clear(); for(i=0;i<K;i++) { if(all.empty()) { printf("-1\n"); return 0; } if(i==0) { a=all.begin()->first; b=all[a].top(); all[a].pop(); if(all[a].empty()) all.erase(a); } else { a=prev(all.end())->first; b=all[a].top(); all[a].pop(); if(all[a].empty()) all.erase(a); } ttt.push_back(b); tt2.push_back(make_pair(a,b)); } que.push_back(ttt); for(auto i:tt2) if(i.first!=1) all[i.first-1].push(i.second); } printf("%lld\n",ans/K); for(auto i:que) { printf("1 "); for(auto j:i) printf("%lld ",j); printf("\n"); } } else { tt=K*N/F(K,N); //printf("%lld\n",tt); ans=(xx*N)/(tt); //printf("%lld\n",ans); con=xx*N/(ans*K); if(con*K>3000000) printf("-1\n"); else { printf("%lld\n",con); now=0; for(i=0;i<con;i++) { printf("%lld ",ans); for(j=0;j<K;j++) { printf("%lld ",now+1); now=(now+1)%N; } printf("\n"); } } } return 0; }
Compilation message
# | 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 | 364 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 | 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 | 4 ms | 1004 KB | n=8 |
9 | Correct | 10 ms | 1192 KB | n=14 |
10 | Correct | 6 ms | 1004 KB | n=11 |
11 | Correct | 38 ms | 3832 KB | n=50000 |
12 | Correct | 37 ms | 3872 KB | n=50000 |
13 | Correct | 34 ms | 3488 KB | n=10 |
14 | Correct | 27 ms | 3232 KB | n=685 |
15 | Correct | 29 ms | 3380 KB | n=623 |
16 | Correct | 16 ms | 1956 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 | 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 | 4 ms | 1004 KB | n=8 |
9 | Correct | 10 ms | 1192 KB | n=14 |
10 | Correct | 6 ms | 1004 KB | n=11 |
11 | Correct | 38 ms | 3832 KB | n=50000 |
12 | Correct | 37 ms | 3872 KB | n=50000 |
13 | Correct | 34 ms | 3488 KB | n=10 |
14 | Correct | 27 ms | 3232 KB | n=685 |
15 | Correct | 29 ms | 3380 KB | n=623 |
16 | Correct | 16 ms | 1956 KB | n=973 |
17 | Correct | 25 ms | 2596 KB | n=989 |
18 | Correct | 10 ms | 1260 KB | n=563 |
19 | Correct | 21 ms | 1644 KB | n=592 |
20 | Correct | 16 ms | 1644 KB | n=938 |
21 | Correct | 13 ms | 1388 KB | n=747 |
22 | Correct | 14 ms | 1516 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 408 ms | 23168 KB | n=1000000 |
2 | Correct | 281 ms | 13800 KB | n=666666 |
3 | Correct | 136 ms | 7532 KB | n=400000 |
4 | Correct | 344 ms | 20076 KB | n=285714 |
5 | Correct | 7 ms | 620 KB | n=20000 |
6 | Correct | 298 ms | 17260 KB | n=181818 |
7 | Correct | 4 ms | 492 KB | n=10000 |
8 | Correct | 38 ms | 2028 KB | n=6666 |
9 | Correct | 2 ms | 364 KB | n=4000 |
10 | Correct | 217 ms | 9836 KB | n=2857 |
11 | Correct | 1 ms | 364 KB | n=2000 |
# | 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 | 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 | 4 ms | 1004 KB | n=8 |
9 | Correct | 10 ms | 1192 KB | n=14 |
10 | Correct | 6 ms | 1004 KB | n=11 |
11 | Correct | 38 ms | 3832 KB | n=50000 |
12 | Correct | 37 ms | 3872 KB | n=50000 |
13 | Correct | 34 ms | 3488 KB | n=10 |
14 | Correct | 27 ms | 3232 KB | n=685 |
15 | Correct | 29 ms | 3380 KB | n=623 |
16 | Correct | 16 ms | 1956 KB | n=973 |
17 | Correct | 25 ms | 2596 KB | n=989 |
18 | Correct | 10 ms | 1260 KB | n=563 |
19 | Correct | 21 ms | 1644 KB | n=592 |
20 | Correct | 16 ms | 1644 KB | n=938 |
21 | Correct | 13 ms | 1388 KB | n=747 |
22 | Correct | 14 ms | 1516 KB | n=991 |
23 | Correct | 408 ms | 23168 KB | n=1000000 |
24 | Correct | 281 ms | 13800 KB | n=666666 |
25 | Correct | 136 ms | 7532 KB | n=400000 |
26 | Correct | 344 ms | 20076 KB | n=285714 |
27 | Correct | 7 ms | 620 KB | n=20000 |
28 | Correct | 298 ms | 17260 KB | n=181818 |
29 | Correct | 4 ms | 492 KB | n=10000 |
30 | Correct | 38 ms | 2028 KB | n=6666 |
31 | Correct | 2 ms | 364 KB | n=4000 |
32 | Correct | 217 ms | 9836 KB | n=2857 |
33 | Correct | 1 ms | 364 KB | n=2000 |
34 | Incorrect | 39 ms | 17644 KB | Taken too much stones from the heap |
35 | Halted | 0 ms | 0 KB | - |