답안 #378668

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378668 2021-03-17T03:04:22 Z daniel920712 Gift (IZhO18_nicegift) C++14
18 / 100
2000 ms 279480 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 < pair < long long , long long > > que;
long long ttt[1000005];
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;
        ttt[i]=t;
        xx=t;
    }
    if(ans%K) printf("-1\n");
    else if(K==2)
    {

        while(!all.empty())
        {
            x=all.begin()->second.top();
            a=all.begin()->first;
            all[a].pop();

            if(prev(all.end())->second.empty())
            {
                printf("-1\n");
                return 0;
            }
            y=prev(all.end())->second.top();
            b=prev(all.end())->first;
            all[b].pop();
            //printf("1 %lld %lld\n",x,y);
            que.push_back(make_pair(x,y));

            if(all[a].empty()) all.erase(a);
            if(a!=b&&all[b].empty()) all.erase(b);
            if(a!=1) all[a-1].push(x);
            if(b!=1) all[b-1].push(y);
        }
        printf("%lld\n",ans/K);
        for(auto i:que) printf("1 %lld %lld\n",i.first,i.second);
    }
    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

nicegift.cpp: In function 'int main()':
nicegift.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     scanf("%lld %lld",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
nicegift.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |         scanf("%lld",&t);
      |         ~~~~~^~~~~~~~~~~
nicegift.cpp:20:39: warning: 'xx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |     long long N,K,i,j,ans=0,x,y,a,b,t,xx,tt,now,con;
      |                                       ^~
# 결과 실행 시간 메모리 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 0 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
# 결과 실행 시간 메모리 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 0 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 3 ms 748 KB n=8
9 Correct 6 ms 748 KB n=14
10 Correct 4 ms 748 KB n=11
11 Correct 24 ms 2784 KB n=50000
12 Correct 21 ms 2784 KB n=50000
13 Correct 21 ms 1632 KB n=10
14 Correct 16 ms 1508 KB n=685
15 Correct 17 ms 1632 KB n=623
16 Correct 10 ms 1124 KB n=973
# 결과 실행 시간 메모리 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 0 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 3 ms 748 KB n=8
9 Correct 6 ms 748 KB n=14
10 Correct 4 ms 748 KB n=11
11 Correct 24 ms 2784 KB n=50000
12 Correct 21 ms 2784 KB n=50000
13 Correct 21 ms 1632 KB n=10
14 Correct 16 ms 1508 KB n=685
15 Correct 17 ms 1632 KB n=623
16 Correct 10 ms 1124 KB n=973
17 Incorrect 1 ms 364 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2106 ms 279480 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 364 KB n=5
8 Correct 3 ms 748 KB n=8
9 Correct 6 ms 748 KB n=14
10 Correct 4 ms 748 KB n=11
11 Correct 24 ms 2784 KB n=50000
12 Correct 21 ms 2784 KB n=50000
13 Correct 21 ms 1632 KB n=10
14 Correct 16 ms 1508 KB n=685
15 Correct 17 ms 1632 KB n=623
16 Correct 10 ms 1124 KB n=973
17 Incorrect 1 ms 364 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -