답안 #1037715

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037715 2024-07-29T07:19:43 Z 변재우(#10984) Cookies (JOI23_cookies) C++17
6 / 100
71 ms 1880 KB
#include <bits/stdc++.h>
using namespace std;

const int Nmax=510;
int N, M, tot, mx, ans, A[Nmax], B[Nmax], X[Nmax], P[Nmax][Nmax];
bool D[Nmax][Nmax];
vector<int> Y[Nmax];
vector<pair<int, int>> V;

void Trace(int x, int i) {
    if(!i) return;
    X[i]=B[P[x][i]];
    return Trace(x-B[P[x][i]], i-1);
}

bool chk(int ans) {
    bool flag=true;
    Trace(tot, ans);
    V.clear();
    for(int i=1; i<=ans; i++) V.push_back({X[i], i}), Y[i].clear();
    for(int i=1; i<=N; i++) {
        sort(V.rbegin(), V.rend());
        for(int j=0; j<A[i]; j++) {
            V[j].first--, Y[V[j].second].push_back(i);
            if(V[j].first<0) {flag=false; goto out;}
        }
    }
    out:
    if(!flag) return false;
    cout<<ans<<"\n";
    for(int i=1; i<=ans; i++) {
        cout<<X[i]<<" ";
        for(int j:Y[i]) cout<<j<<" ";
        cout<<"\n";
    }
    return true;
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N;
    for(int i=1; i<=N; i++) cin>>A[i], tot+=A[i], mx=max(mx, A[i]);
    cin>>M;
    for(int i=1; i<=M; i++) cin>>B[i];
    D[0][0]=true;
    for(int i=1; i<=M; i++) {
        for(int j=B[i]; j<=500; j++) {
            for(int k=1; k<=500; k++) {
                if(D[j-B[i]][k-1]) P[j][k]=i, D[j][k]=true;
            }
        }
    }
    for(int i=mx; i<=500; i++) if(D[tot][i]) {
        if(chk(i)) return 0;
    }
    cout<<-1;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1880 KB Output is correct
2 Correct 1 ms 1624 KB Output is correct
3 Correct 2 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 2 ms 1624 KB Output is correct
8 Correct 13 ms 1628 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 71 ms 1624 KB Output is correct
11 Correct 17 ms 860 KB Output is correct
12 Correct 12 ms 1628 KB Output is correct
13 Correct 12 ms 1728 KB Output is correct
14 Correct 21 ms 1240 KB Output is correct
15 Correct 46 ms 1372 KB Output is correct
16 Correct 24 ms 1112 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1628 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
21 Correct 13 ms 1688 KB Output is correct
22 Correct 34 ms 1628 KB Output is correct
23 Correct 36 ms 1628 KB Output is correct
24 Correct 5 ms 1628 KB Output is correct
25 Correct 5 ms 1628 KB Output is correct
26 Correct 4 ms 1372 KB Output is correct
27 Correct 4 ms 1368 KB Output is correct
28 Correct 12 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 1 ms 1628 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 13 ms 1744 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Incorrect 1 ms 1628 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1628 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 1628 KB Output is correct
4 Correct 2 ms 1624 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 1 ms 1628 KB Output is correct
8 Correct 1 ms 1628 KB Output is correct
9 Correct 1 ms 1628 KB Output is correct
10 Correct 1 ms 1628 KB Output is correct
11 Correct 1 ms 1628 KB Output is correct
12 Correct 1 ms 1628 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1628 KB Output is correct
15 Correct 1 ms 1628 KB Output is correct
16 Correct 1 ms 1628 KB Output is correct
17 Incorrect 2 ms 1624 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1880 KB Output is correct
2 Correct 1 ms 1624 KB Output is correct
3 Correct 2 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 2 ms 1624 KB Output is correct
8 Correct 13 ms 1628 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 71 ms 1624 KB Output is correct
11 Correct 17 ms 860 KB Output is correct
12 Correct 12 ms 1628 KB Output is correct
13 Correct 12 ms 1728 KB Output is correct
14 Correct 21 ms 1240 KB Output is correct
15 Correct 46 ms 1372 KB Output is correct
16 Correct 24 ms 1112 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1628 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
21 Correct 13 ms 1688 KB Output is correct
22 Correct 34 ms 1628 KB Output is correct
23 Correct 36 ms 1628 KB Output is correct
24 Correct 5 ms 1628 KB Output is correct
25 Correct 5 ms 1628 KB Output is correct
26 Correct 4 ms 1372 KB Output is correct
27 Correct 4 ms 1368 KB Output is correct
28 Correct 12 ms 1372 KB Output is correct
29 Correct 3 ms 1628 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1628 KB Output is correct
32 Correct 2 ms 1624 KB Output is correct
33 Correct 1 ms 1628 KB Output is correct
34 Correct 1 ms 1628 KB Output is correct
35 Correct 1 ms 1628 KB Output is correct
36 Correct 1 ms 1628 KB Output is correct
37 Correct 1 ms 1628 KB Output is correct
38 Correct 1 ms 1628 KB Output is correct
39 Correct 1 ms 1628 KB Output is correct
40 Correct 1 ms 1628 KB Output is correct
41 Correct 1 ms 1372 KB Output is correct
42 Correct 1 ms 1628 KB Output is correct
43 Correct 1 ms 1628 KB Output is correct
44 Correct 1 ms 1628 KB Output is correct
45 Incorrect 2 ms 1624 KB Output isn't correct
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1880 KB Output is correct
2 Correct 1 ms 1624 KB Output is correct
3 Correct 2 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 2 ms 1624 KB Output is correct
8 Correct 13 ms 1628 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 71 ms 1624 KB Output is correct
11 Correct 17 ms 860 KB Output is correct
12 Correct 12 ms 1628 KB Output is correct
13 Correct 12 ms 1728 KB Output is correct
14 Correct 21 ms 1240 KB Output is correct
15 Correct 46 ms 1372 KB Output is correct
16 Correct 24 ms 1112 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1628 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
21 Correct 13 ms 1688 KB Output is correct
22 Correct 34 ms 1628 KB Output is correct
23 Correct 36 ms 1628 KB Output is correct
24 Correct 5 ms 1628 KB Output is correct
25 Correct 5 ms 1628 KB Output is correct
26 Correct 4 ms 1372 KB Output is correct
27 Correct 4 ms 1368 KB Output is correct
28 Correct 12 ms 1372 KB Output is correct
29 Correct 3 ms 1628 KB Output is correct
30 Correct 1 ms 1116 KB Output is correct
31 Correct 1 ms 1628 KB Output is correct
32 Correct 2 ms 1624 KB Output is correct
33 Correct 1 ms 1628 KB Output is correct
34 Correct 1 ms 1628 KB Output is correct
35 Correct 1 ms 1628 KB Output is correct
36 Correct 1 ms 1628 KB Output is correct
37 Correct 1 ms 1628 KB Output is correct
38 Correct 1 ms 1628 KB Output is correct
39 Correct 1 ms 1628 KB Output is correct
40 Correct 1 ms 1628 KB Output is correct
41 Correct 1 ms 1372 KB Output is correct
42 Correct 1 ms 1628 KB Output is correct
43 Correct 1 ms 1628 KB Output is correct
44 Correct 1 ms 1628 KB Output is correct
45 Incorrect 2 ms 1624 KB Output isn't correct
46 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1880 KB Output is correct
2 Correct 1 ms 1624 KB Output is correct
3 Correct 2 ms 1628 KB Output is correct
4 Correct 1 ms 1628 KB Output is correct
5 Correct 2 ms 1628 KB Output is correct
6 Correct 1 ms 1628 KB Output is correct
7 Correct 2 ms 1624 KB Output is correct
8 Correct 13 ms 1628 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 71 ms 1624 KB Output is correct
11 Correct 17 ms 860 KB Output is correct
12 Correct 12 ms 1628 KB Output is correct
13 Correct 12 ms 1728 KB Output is correct
14 Correct 21 ms 1240 KB Output is correct
15 Correct 46 ms 1372 KB Output is correct
16 Correct 24 ms 1112 KB Output is correct
17 Correct 2 ms 1628 KB Output is correct
18 Correct 2 ms 1628 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 4 ms 860 KB Output is correct
21 Correct 13 ms 1688 KB Output is correct
22 Correct 34 ms 1628 KB Output is correct
23 Correct 36 ms 1628 KB Output is correct
24 Correct 5 ms 1628 KB Output is correct
25 Correct 5 ms 1628 KB Output is correct
26 Correct 4 ms 1372 KB Output is correct
27 Correct 4 ms 1368 KB Output is correct
28 Correct 12 ms 1372 KB Output is correct
29 Correct 1 ms 1112 KB Output is correct
30 Correct 1 ms 1628 KB Output is correct
31 Correct 1 ms 1628 KB Output is correct
32 Correct 1 ms 1628 KB Output is correct
33 Correct 13 ms 1744 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 1628 KB Output is correct
36 Correct 1 ms 1628 KB Output is correct
37 Incorrect 1 ms 1628 KB Output isn't correct
38 Halted 0 ms 0 KB -