# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378831 | 2021-03-17T05:44:39 Z | daniel920712 | Gift (IZhO18_nicegift) | C++14 | 401 ms | 23584 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; } 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 | 0 ms | 364 KB | n=4 |
2 | Correct | 0 ms | 364 KB | n=3 |
3 | Correct | 1 ms | 364 KB | n=3 |
4 | Correct | 0 ms | 364 KB | n=4 |
5 | Correct | 0 ms | 364 KB | n=4 |
6 | Correct | 0 ms | 364 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | n=4 |
2 | Correct | 0 ms | 364 KB | n=3 |
3 | Correct | 1 ms | 364 KB | n=3 |
4 | Correct | 0 ms | 364 KB | n=4 |
5 | Correct | 0 ms | 364 KB | n=4 |
6 | Correct | 0 ms | 364 KB | n=2 |
7 | Correct | 0 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 | 37 ms | 3872 KB | n=50000 |
12 | Correct | 34 ms | 4020 KB | n=50000 |
13 | Correct | 32 ms | 3488 KB | n=10 |
14 | Correct | 21 ms | 3104 KB | n=685 |
15 | Correct | 24 ms | 3380 KB | n=623 |
16 | Correct | 13 ms | 1956 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | n=4 |
2 | Correct | 0 ms | 364 KB | n=3 |
3 | Correct | 1 ms | 364 KB | n=3 |
4 | Correct | 0 ms | 364 KB | n=4 |
5 | Correct | 0 ms | 364 KB | n=4 |
6 | Correct | 0 ms | 364 KB | n=2 |
7 | Correct | 0 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 | 37 ms | 3872 KB | n=50000 |
12 | Correct | 34 ms | 4020 KB | n=50000 |
13 | Correct | 32 ms | 3488 KB | n=10 |
14 | Correct | 21 ms | 3104 KB | n=685 |
15 | Correct | 24 ms | 3380 KB | n=623 |
16 | Correct | 13 ms | 1956 KB | n=973 |
17 | Correct | 20 ms | 2596 KB | n=989 |
18 | Correct | 9 ms | 1260 KB | n=563 |
19 | Correct | 15 ms | 1772 KB | n=592 |
20 | Correct | 15 ms | 1644 KB | n=938 |
21 | Correct | 12 ms | 1388 KB | n=747 |
22 | Correct | 13 ms | 1516 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 401 ms | 23584 KB | n=1000000 |
2 | Correct | 248 ms | 14956 KB | n=666666 |
3 | Correct | 138 ms | 8812 KB | n=400000 |
4 | Correct | 335 ms | 20844 KB | n=285714 |
5 | Correct | 7 ms | 876 KB | n=20000 |
6 | Correct | 295 ms | 18028 KB | n=181818 |
7 | Correct | 4 ms | 620 KB | n=10000 |
8 | Correct | 41 ms | 2156 KB | n=6666 |
9 | Correct | 2 ms | 492 KB | n=4000 |
10 | Correct | 216 ms | 9836 KB | n=2857 |
11 | Correct | 1 ms | 364 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | n=4 |
2 | Correct | 0 ms | 364 KB | n=3 |
3 | Correct | 1 ms | 364 KB | n=3 |
4 | Correct | 0 ms | 364 KB | n=4 |
5 | Correct | 0 ms | 364 KB | n=4 |
6 | Correct | 0 ms | 364 KB | n=2 |
7 | Correct | 0 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 | 37 ms | 3872 KB | n=50000 |
12 | Correct | 34 ms | 4020 KB | n=50000 |
13 | Correct | 32 ms | 3488 KB | n=10 |
14 | Correct | 21 ms | 3104 KB | n=685 |
15 | Correct | 24 ms | 3380 KB | n=623 |
16 | Correct | 13 ms | 1956 KB | n=973 |
17 | Correct | 20 ms | 2596 KB | n=989 |
18 | Correct | 9 ms | 1260 KB | n=563 |
19 | Correct | 15 ms | 1772 KB | n=592 |
20 | Correct | 15 ms | 1644 KB | n=938 |
21 | Correct | 12 ms | 1388 KB | n=747 |
22 | Correct | 13 ms | 1516 KB | n=991 |
23 | Correct | 401 ms | 23584 KB | n=1000000 |
24 | Correct | 248 ms | 14956 KB | n=666666 |
25 | Correct | 138 ms | 8812 KB | n=400000 |
26 | Correct | 335 ms | 20844 KB | n=285714 |
27 | Correct | 7 ms | 876 KB | n=20000 |
28 | Correct | 295 ms | 18028 KB | n=181818 |
29 | Correct | 4 ms | 620 KB | n=10000 |
30 | Correct | 41 ms | 2156 KB | n=6666 |
31 | Correct | 2 ms | 492 KB | n=4000 |
32 | Correct | 216 ms | 9836 KB | n=2857 |
33 | Correct | 1 ms | 364 KB | n=2000 |
34 | Incorrect | 34 ms | 17644 KB | Taken too much stones from the heap |
35 | Halted | 0 ms | 0 KB | - |