답안 #789199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789199 2023-07-21T07:31:51 Z 반딧불(#10041) Cookies (JOI23_cookies) C++17
0 / 100
1 ms 312 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, k;
int a[15002], b[15002];

bool DP[502][502];
vector<vector<int> > ans;
int cnt;

void track(int x, int y){
    if(!x) return;
    if(DP[x-1][y]){
        track(x-1, y);
        return;
    }
    ans.push_back(vector<int> ());
    for(int i=0; i<b[x]; i++) ans.back().push_back(++cnt);
    track(x, y-b[x]);
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &a[i]);
    scanf("%d", &k);
    for(int i=1; i<=k; i++) scanf("%d", &b[i]);

    DP[0][0] = 1;
    for(int i=1; i<=k; i++){
        for(int j=0; j<=n; j++) if(DP[i-1][j]) DP[i][j] = 1;
        for(int j=0; j+b[i]<=n; j++) if(DP[i][j]) DP[i][j+b[i]] = 1;
    }
    if(!DP[k][n]){
        printf("-1");
        return 0;
    }
    track(k, n);
    printf("%d\n", (int)ans.size());
    for(auto p: ans){
        printf("%d ", (int)p.size());
        for(auto x: p) printf("%d ", x);
        puts("");
    }
}

Compilation message

cookies.cpp: In function 'int main()':
cookies.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
cookies.cpp:27:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     for(int i=1; i<=n; i++) scanf("%d", &a[i]);
      |                             ~~~~~^~~~~~~~~~~~~
cookies.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf("%d", &k);
      |     ~~~~~^~~~~~~~~~
cookies.cpp:29:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     for(int i=1; i<=k; i++) scanf("%d", &b[i]);
      |                             ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Incorrect 0 ms 212 KB Number of cookies does not match with A_i
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -