# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
378771 | 2021-03-17T04:01:29 Z | daniel920712 | Gift (IZhO18_nicegift) | C++14 | 409 ms | 22908 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%2==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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | n=4 |
2 | Correct | 0 ms | 364 KB | n=3 |
3 | Correct | 0 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 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | n=4 |
2 | Correct | 0 ms | 364 KB | n=3 |
3 | Correct | 0 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 | 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 | 35 ms | 3872 KB | n=50000 |
13 | Correct | 34 ms | 3488 KB | n=10 |
14 | Correct | 27 ms | 3104 KB | n=685 |
15 | Correct | 33 ms | 3360 KB | n=623 |
16 | Correct | 17 ms | 1956 KB | n=973 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | n=4 |
2 | Correct | 0 ms | 364 KB | n=3 |
3 | Correct | 0 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 | 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 | 35 ms | 3872 KB | n=50000 |
13 | Correct | 34 ms | 3488 KB | n=10 |
14 | Correct | 27 ms | 3104 KB | n=685 |
15 | Correct | 33 ms | 3360 KB | n=623 |
16 | Correct | 17 ms | 1956 KB | n=973 |
17 | Incorrect | 14 ms | 2084 KB | Jury has the answer but participant has not |
18 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 409 ms | 22908 KB | n=1000000 |
2 | Correct | 238 ms | 14740 KB | n=666666 |
3 | Correct | 133 ms | 8684 KB | n=400000 |
4 | Correct | 338 ms | 20972 KB | n=285714 |
5 | Correct | 7 ms | 876 KB | n=20000 |
6 | Correct | 300 ms | 18064 KB | n=181818 |
7 | Correct | 4 ms | 620 KB | n=10000 |
8 | Correct | 39 ms | 2156 KB | n=6666 |
9 | Correct | 2 ms | 492 KB | n=4000 |
10 | Correct | 228 ms | 9708 KB | n=2857 |
11 | Correct | 2 ms | 364 KB | n=2000 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 364 KB | n=4 |
2 | Correct | 0 ms | 364 KB | n=3 |
3 | Correct | 0 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 | 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 | 35 ms | 3872 KB | n=50000 |
13 | Correct | 34 ms | 3488 KB | n=10 |
14 | Correct | 27 ms | 3104 KB | n=685 |
15 | Correct | 33 ms | 3360 KB | n=623 |
16 | Correct | 17 ms | 1956 KB | n=973 |
17 | Incorrect | 14 ms | 2084 KB | Jury has the answer but participant has not |
18 | Halted | 0 ms | 0 KB | - |