답안 #829262

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
829262 2023-08-18T07:52:07 Z Hanksburger Cookies (JOI23_cookies) C++17
0 / 100
1000 ms 24712 KB
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > dp[505][505];
vector<int> pre[505][505], tmp;
int b[505];
vector<pair<int, int> > operation(vector<pair<int, int> > x, int val)
{
    if (x.size()<val)
    {
        vector<pair<int, int> > useless;
        return useless;
    }
    tmp.clear();
    for (int i=0; i<val; i++)
    {
        if (!x[i].first)
        {
            vector<pair<int, int> > useless;
            return useless;
        }
        x[i].first--;
        tmp.push_back(x[i].second);
    }
    sort(x.begin(), x.end(), greater<pair<int, int> >());
    return x;
}
vector<pair<int, int> > compare(vector<pair<int, int> > x, vector<pair<int, int> > y)
{
    if (x.empty())
        return y;
    if (y.empty())
        return x;
    for (int i=0; i<x.size(); i++)
    {
        if (x[i].first<y[i].first)
            return x;
        else if (x[i].first>y[i].first)
            return y;
    }
    return x;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, sum=0;
    cin >> n;
    for (int i=0; i<n; i++)
    {
        int x;
        cin >> x;
        dp[0][0].push_back({x, i+1});
        sum+=x;
    }
    cin >> m;
    for (int i=1; i<=m; i++)
        cin >> b[i];
    sort(b+1, b+m+1);
    for (int i=1; i<=sum; i++)
    {
        for (int j=1; j<=sum; j++)
        {
            for (int k=1; k<=m; k++)
            {
                if (i<b[k])
                    break;
                vector<pair<int, int> > res=compare(dp[i][j], operation(dp[i-b[k]][j-1], b[k]));
                if (res!=dp[i][j])
                {
                    dp[i][j]=res;
                    pre[i][j]=tmp;
                }
            }
            if (i==sum && dp[i][j].size())
            {
                cout << j << '\n';
                int ind1=sum, ind2=j;
                while (ind2)
                {
                    cout << pre[ind1][ind2].size() << ' ';
                    for (int val:pre[ind1][ind2])
                        cout << val << ' ';
                    cout << '\n';
                    ind1-=pre[ind1][ind2].size();
                    ind2--;
                }
                return 0;
            }
        }
    }
    cout << -1;
}

Compilation message

cookies.cpp: In function 'std::vector<std::pair<int, int> > operation(std::vector<std::pair<int, int> >, int)':
cookies.cpp:8:17: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    8 |     if (x.size()<val)
      |         ~~~~~~~~^~~~
cookies.cpp: In function 'std::vector<std::pair<int, int> > compare(std::vector<std::pair<int, int> >, std::vector<std::pair<int, int> >)':
cookies.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i=0; i<x.size(); i++)
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12244 KB Output is correct
2 Correct 6 ms 12244 KB Output is correct
3 Correct 6 ms 12244 KB Output is correct
4 Correct 7 ms 12244 KB Output is correct
5 Correct 5 ms 12244 KB Output is correct
6 Correct 6 ms 12244 KB Output is correct
7 Correct 6 ms 12204 KB Output is correct
8 Correct 13 ms 14192 KB Output is correct
9 Correct 6 ms 12304 KB Output is correct
10 Execution timed out 1091 ms 21660 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12244 KB Output is correct
2 Correct 5 ms 12244 KB Output is correct
3 Correct 6 ms 12232 KB Output is correct
4 Correct 5 ms 12244 KB Output is correct
5 Correct 12 ms 14184 KB Output is correct
6 Correct 6 ms 12244 KB Output is correct
7 Correct 6 ms 12244 KB Output is correct
8 Correct 9 ms 12244 KB Output is correct
9 Runtime error 34 ms 24712 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12244 KB Output is correct
2 Correct 5 ms 12244 KB Output is correct
3 Correct 6 ms 12244 KB Output is correct
4 Correct 7 ms 12296 KB Output is correct
5 Correct 6 ms 12244 KB Output is correct
6 Correct 6 ms 12296 KB Output is correct
7 Correct 5 ms 12244 KB Output is correct
8 Correct 7 ms 12372 KB Output is correct
9 Correct 6 ms 12244 KB Output is correct
10 Correct 6 ms 12300 KB Output is correct
11 Correct 6 ms 12208 KB Output is correct
12 Incorrect 6 ms 12268 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12244 KB Output is correct
2 Correct 6 ms 12244 KB Output is correct
3 Correct 6 ms 12244 KB Output is correct
4 Correct 7 ms 12244 KB Output is correct
5 Correct 5 ms 12244 KB Output is correct
6 Correct 6 ms 12244 KB Output is correct
7 Correct 6 ms 12204 KB Output is correct
8 Correct 13 ms 14192 KB Output is correct
9 Correct 6 ms 12304 KB Output is correct
10 Execution timed out 1091 ms 21660 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12244 KB Output is correct
2 Correct 6 ms 12244 KB Output is correct
3 Correct 6 ms 12244 KB Output is correct
4 Correct 7 ms 12244 KB Output is correct
5 Correct 5 ms 12244 KB Output is correct
6 Correct 6 ms 12244 KB Output is correct
7 Correct 6 ms 12204 KB Output is correct
8 Correct 13 ms 14192 KB Output is correct
9 Correct 6 ms 12304 KB Output is correct
10 Execution timed out 1091 ms 21660 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 12244 KB Output is correct
2 Correct 6 ms 12244 KB Output is correct
3 Correct 6 ms 12244 KB Output is correct
4 Correct 7 ms 12244 KB Output is correct
5 Correct 5 ms 12244 KB Output is correct
6 Correct 6 ms 12244 KB Output is correct
7 Correct 6 ms 12204 KB Output is correct
8 Correct 13 ms 14192 KB Output is correct
9 Correct 6 ms 12304 KB Output is correct
10 Execution timed out 1091 ms 21660 KB Time limit exceeded
11 Halted 0 ms 0 KB -