답안 #171142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171142 2019-12-27T13:41:05 Z juggernaut Gift (IZhO18_nicegift) C++14
30 / 100
2000 ms 196728 KB
//Just try and the idea will come!
#include<bits/stdc++.h>
#define int long long int
using namespace std;
priority_queue<pair<int,int>>q;
int n,k,i,x;
pair<int,int>a[100000];
vector<vector<int>>ans;
main(){
    scanf("%lld%lld",&n,&k);
    for(i=0;i<n;i++){
        scanf("%lld",&x);
        q.push({x,i+1});
    }
    while(!q.empty()){
        if(q.size()<k){
            puts("-1");
            return 0;
        }
        vector<int>res;
        for(i=0;i<k;i++)a[i]=q.top(),q.pop();
        for(i=0;i<k;i++){
            res.push_back(a[i].second);
            if(a[i].first!=1)q.push({a[i].first-1,a[i].second});
        }
        ans.push_back(res);
    }
    printf("%lld\n",(int)ans.size());
    for(auto res:ans){
        printf("1 ");
        for(int to:res)printf("%lld ",to);
        puts("");
    }
}

Compilation message

nicegift.cpp:9:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q.size()<k){
            ~~~~~~~~^~
nicegift.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~
nicegift.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&x);
         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 256 KB n=3
3 Correct 2 ms 256 KB n=3
4 Correct 2 ms 256 KB n=4
5 Correct 2 ms 256 KB n=4
6 Correct 2 ms 256 KB n=2
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 256 KB n=3
3 Correct 2 ms 256 KB n=3
4 Correct 2 ms 256 KB n=4
5 Correct 2 ms 256 KB n=4
6 Correct 2 ms 256 KB n=2
7 Correct 2 ms 256 KB n=5
8 Correct 5 ms 960 KB n=8
9 Correct 25 ms 1204 KB n=14
10 Correct 7 ms 888 KB n=11
11 Correct 47 ms 4576 KB n=50000
12 Correct 47 ms 4576 KB n=50000
13 Correct 32 ms 3500 KB n=10
14 Correct 31 ms 3076 KB n=685
15 Correct 33 ms 3376 KB n=623
16 Correct 19 ms 1968 KB n=973
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 256 KB n=3
3 Correct 2 ms 256 KB n=3
4 Correct 2 ms 256 KB n=4
5 Correct 2 ms 256 KB n=4
6 Correct 2 ms 256 KB n=2
7 Correct 2 ms 256 KB n=5
8 Correct 5 ms 960 KB n=8
9 Correct 25 ms 1204 KB n=14
10 Correct 7 ms 888 KB n=11
11 Correct 47 ms 4576 KB n=50000
12 Correct 47 ms 4576 KB n=50000
13 Correct 32 ms 3500 KB n=10
14 Correct 31 ms 3076 KB n=685
15 Correct 33 ms 3376 KB n=623
16 Correct 19 ms 1968 KB n=973
17 Correct 31 ms 2604 KB n=989
18 Correct 15 ms 1272 KB n=563
19 Correct 23 ms 1656 KB n=592
20 Correct 23 ms 1656 KB n=938
21 Correct 19 ms 1400 KB n=747
22 Correct 14 ms 1528 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2041 ms 196728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB n=4
2 Correct 2 ms 256 KB n=3
3 Correct 2 ms 256 KB n=3
4 Correct 2 ms 256 KB n=4
5 Correct 2 ms 256 KB n=4
6 Correct 2 ms 256 KB n=2
7 Correct 2 ms 256 KB n=5
8 Correct 5 ms 960 KB n=8
9 Correct 25 ms 1204 KB n=14
10 Correct 7 ms 888 KB n=11
11 Correct 47 ms 4576 KB n=50000
12 Correct 47 ms 4576 KB n=50000
13 Correct 32 ms 3500 KB n=10
14 Correct 31 ms 3076 KB n=685
15 Correct 33 ms 3376 KB n=623
16 Correct 19 ms 1968 KB n=973
17 Correct 31 ms 2604 KB n=989
18 Correct 15 ms 1272 KB n=563
19 Correct 23 ms 1656 KB n=592
20 Correct 23 ms 1656 KB n=938
21 Correct 19 ms 1400 KB n=747
22 Correct 14 ms 1528 KB n=991
23 Execution timed out 2041 ms 196728 KB Time limit exceeded
24 Halted 0 ms 0 KB -