답안 #1037617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037617 2024-07-29T06:02:05 Z 김은성(#10980) Cookies (JOI23_cookies) C++17
7 / 100
9 ms 16988 KB
#include <bits/stdc++.h>
using namespace std;
const int INF = 1234123412;
int a[15009], dp[2][15009];
int cnt[15009];
short opt[15009][15009];
bool pos[15009];
int main(){
    int n, m, i, j, v, N = 0;
    scanf("%d", &n);
    for(i=1; i<=n; i++){
        scanf("%d", &a[i]);
        cnt[i] = a[i];
        N += a[i];
    }
    sort(cnt+1, cnt+n+1, [](int &u, int &v){return u > v;});
    for(i=n; i>=1; i--)
        cnt[i] += cnt[i+1];
    scanf("%d", &m);
    for(i=1; i<=m; i++){
        scanf("%d", &v);
        pos[v] = 1;
    }
    for(j=0; j<=N; j++)
        dp[n%2][j] = INF;
    dp[n%2][0] = 0;
    opt[n][0] = 0;
    for(i=n; i>=1; i--){
        if(pos[i]){
            for(j=0; j<cnt[i]; j++){
                if(dp[i%2][j+1] > dp[i%2][j] + 1){
                    dp[i%2][j+1] = dp[i%2][j] + 1;
                    opt[i][j+1] = -1;
                }
            }
        }
        for(j=0; j<=N; j++)
            dp[(i-1)%2][j] = INF;
        for(j=0; j<=cnt[i]; j++){
            if(j + dp[i%2][j] <= N && dp[(i-1)%2][j+dp[i%2][j]] > dp[i%2][j]){
                dp[(i-1)%2][j+dp[i%2][j]] = dp[i%2][j];
                opt[i-1][j+dp[i%2][j]] = j;
            }
        }
    }
    int row = 1, col = N;
    if(dp[1][N] >= INF){
        printf("-1\n");
        return 0;
    }
    vector<int> vec;
    while(row <= n && col > 0){
        if(opt[row][col] == -1){
            vec.push_back(row);
            col--;
        }
        else{
            col = opt[row][col];
            row++;
        }
    }
    for(i=0; i<vec.size()/2; i++)
        swap(vec[i], vec[(int)vec.size()-1-i]);
    priority_queue<pair<int, int> > qa;
    for(i=1; i<=n; i++)
        qa.push(make_pair(a[i], i));
    printf("%d\n", vec.size());
    for(i=0; i<vec.size(); i++){
        printf("%d ", vec[i]);
        vector<pair<int, int> > temp;
        for(int j=0; j<vec[i]; j++){
            temp.push_back(qa.top());
            temp.back().first--;
            printf("%d ", temp.back().second);
            qa.pop();
        }
        printf("\n");
        while(!temp.empty()){
            qa.push(temp.back());
            temp.pop_back();
        }
    }
    return 0;
}

Compilation message

cookies.cpp: In function 'int main()':
cookies.cpp:62:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(i=0; i<vec.size()/2; i++)
      |              ~^~~~~~~~~~~~~
cookies.cpp:67:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   67 |     printf("%d\n", vec.size());
      |             ~^     ~~~~~~~~~~
      |              |             |
      |              int           std::vector<int>::size_type {aka long unsigned int}
      |             %ld
cookies.cpp:68:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(i=0; i<vec.size(); i++){
      |              ~^~~~~~~~~~~
cookies.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
cookies.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
cookies.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d", &m);
      |     ~~~~~^~~~~~~~~~
cookies.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d", &v);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 612 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 2 ms 16876 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 860 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 2 ms 2652 KB Output is correct
19 Correct 9 ms 16988 KB Output is correct
20 Correct 8 ms 16988 KB Output is correct
21 Correct 8 ms 16980 KB Output is correct
22 Correct 3 ms 4696 KB Output is correct
23 Correct 2 ms 16872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -