답안 #378611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378611 2021-03-17T02:15:12 Z daniel920712 Gift (IZhO18_nicegift) C++14
0 / 100
2000 ms 96152 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <stack>
#include <map>

using namespace std;
map < int , stack < int > > all;
int tt[1000005];
int main()
{
    //freopen("aa.txt","w+t",stdout);
    int N,K,i,j,ans=0,x,y,a,b,t;
    scanf("%d %d",&N,&K);
    for(i=1;i<=N;i++)
    {
        scanf("%d",&t);
        all[t].push(i);
        ans+=t;
        tt[i]=t;
    }
    if(ans%K||N==2&&tt[1]!=tt[2]) printf("-1\n");
    else
    {
        //printf("%d\n",ans/K);
        while(!all.empty())
        {
            x=all.begin()->second.top();
            a=all.begin()->first;
            all[a].pop();

            //if(prev(all.end())->second.empty()) while(1);
            y=prev(all.end())->second.top();
            b=prev(all.end())->first;
            all[b].pop();
            printf("1 %d %d\n",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);
        }
    }
    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:22:19: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   22 |     if(ans%K||N==2&&tt[1]!=tt[2]) printf("-1\n");
      |               ~~~~^~~~~~~~~~~~~~
nicegift.cpp:13:15: warning: unused variable 'j' [-Wunused-variable]
   13 |     int N,K,i,j,ans=0,x,y,a,b,t;
      |               ^
nicegift.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%d %d",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~~
nicegift.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |         scanf("%d",&t);
      |         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2094 ms 96152 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -