답안 #340529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340529 2020-12-27T20:24:20 Z scales Gift (IZhO18_nicegift) C++17
30 / 100
214 ms 32364 KB
#include <bits/stdc++.h>
/*#ifndef LOCAL_RUN
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("fast-math")
    #pragma GCC target("avx2,tune=native")
#endif*/
using namespace std;
int main()
{
      ios::sync_with_stdio(false);
      cin.tie(0);
     // freopen("input.txt","r",stdin);
     // freopen("output.txt","w",stdout);
     long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
     cin>>n;
     cin>>k;
     vector<pair<long long,long long> > a(n);
     sum=0;
     for(i=0;i<n;i++)
     {
         cin>>a[i].first;
         sum=sum+a[i].first;
         a[i].second=i+1;
     }
     sort(a.begin(),a.end());
     /*for(i=0;i<n;i++)
     {
         cout<<a[i].first<<" "<<a[i].second<<endl;
     }*/
     if( ((sum%k)!=0) || a[n-1].first>(sum/k))
     {
         cout<<-1<<endl;
     }
     else
     {
         cout<<sum/k<<endl;
         vector< vector<long long> > viv(sum/k);
         priority_queue<pair<long long, long long> > q;
         queue <pair<long long, long long> > h;
         for(i=0;i<n;i++)
         {
             q.push({a[i].first,a[i].second});
         }
         kol=0;
         l=0;
         while(!q.empty())
         {
             x=q.top().first;
             y=q.top().second;
             //cout<<"x="<<x<<endl;
             x--;
             viv[l].push_back(y);
             kol++;
             if(x!=0)
             {
                 h.push({x,y});
             }
             q.pop();

             if(kol==k)
             {
                 kol=0;
                 l++;
                 while(!h.empty())
                 {
                     q.push(h.front());
                     h.pop();
                 }
             }
         }

         for(i=0;i<sum/k;i++)
         {
             cout<<1<<" ";
             for(j=0;j<k;j++)
             {
                 cout<<viv[i][j]<<" ";
             }
             cout<<endl;
         }
     }

    return 0;
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:15:16: warning: unused variable 't' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                ^
nicegift.cpp:15:22: warning: unused variable 'dno' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                      ^~~
nicegift.cpp:15:30: warning: unused variable 'z' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                              ^
nicegift.cpp:15:32: warning: unused variable 'w' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                                ^
nicegift.cpp:15:34: warning: unused variable 'm' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                                  ^
nicegift.cpp:15:40: warning: unused variable 'x1' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                                        ^~
nicegift.cpp:15:43: warning: unused variable 'y1' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                                           ^~
nicegift.cpp:15:46: warning: unused variable 'tip' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                                              ^~~
nicegift.cpp:15:50: warning: unused variable 'p' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                                                  ^
nicegift.cpp:15:54: warning: unused variable 'r' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                                                      ^
nicegift.cpp:15:60: warning: unused variable 'maxi' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                                                            ^~~~
nicegift.cpp:15:69: warning: unused variable 'v' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,p,l,r,sum,maxi,kol,v;
      |                                                                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 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 0 ms 364 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 384 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 39 ms 1272 KB n=14
10 Correct 23 ms 876 KB n=11
11 Correct 151 ms 5480 KB n=50000
12 Correct 148 ms 5372 KB n=50000
13 Correct 130 ms 3564 KB n=10
14 Correct 113 ms 3180 KB n=685
15 Correct 129 ms 3440 KB n=623
16 Correct 71 ms 2092 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 384 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 39 ms 1272 KB n=14
10 Correct 23 ms 876 KB n=11
11 Correct 151 ms 5480 KB n=50000
12 Correct 148 ms 5372 KB n=50000
13 Correct 130 ms 3564 KB n=10
14 Correct 113 ms 3180 KB n=685
15 Correct 129 ms 3440 KB n=623
16 Correct 71 ms 2092 KB n=973
17 Correct 92 ms 3124 KB n=989
18 Correct 25 ms 1280 KB n=563
19 Correct 27 ms 1900 KB n=592
20 Correct 32 ms 1772 KB n=938
21 Correct 29 ms 1772 KB n=747
22 Correct 29 ms 1772 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Runtime error 214 ms 32364 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 0 ms 364 KB n=3
3 Correct 1 ms 384 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 0 ms 364 KB n=4
6 Correct 0 ms 364 KB n=2
7 Correct 1 ms 384 KB n=5
8 Correct 1 ms 364 KB n=8
9 Correct 39 ms 1272 KB n=14
10 Correct 23 ms 876 KB n=11
11 Correct 151 ms 5480 KB n=50000
12 Correct 148 ms 5372 KB n=50000
13 Correct 130 ms 3564 KB n=10
14 Correct 113 ms 3180 KB n=685
15 Correct 129 ms 3440 KB n=623
16 Correct 71 ms 2092 KB n=973
17 Correct 92 ms 3124 KB n=989
18 Correct 25 ms 1280 KB n=563
19 Correct 27 ms 1900 KB n=592
20 Correct 32 ms 1772 KB n=938
21 Correct 29 ms 1772 KB n=747
22 Correct 29 ms 1772 KB n=991
23 Runtime error 214 ms 32364 KB Execution killed with signal 6 (could be triggered by violating memory limits)
24 Halted 0 ms 0 KB -