답안 #804517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804517 2023-08-03T09:29:03 Z mousebeaver Cookies (JOI23_cookies) C++14
0 / 100
1 ms 328 KB
#define ll long long
#define INF numeric_limits<ll>::max()/2
#define pll pair<ll, ll>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    bool sub1 = true;

    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++)
    {
        cin>>a[i];
        if(a[i] != 1 || n > 500)
        {
            sub1 = false;
        }
    }
    ll m;
    cin>>m;
    vector<ll> b(m);
    for(ll i = 0; i < m; i++)
    {
        cin>>b[i];
    }

    if(sub1)
    {
        //Subtask 1:
        vector<pll> dp(n+1, {INF, -1}); //Number, last
        dp[0] = {0, 0};
        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < m && i+b[j] <= n; j++)
            {
                if(dp[i].first+1 < dp[i+b[j]].first)
                {
                    dp[i+b[j]].first = dp[i].first+1;
                    dp[i+b[j]].second = j;
                }
            }
        }

        if(dp[n].first == INF)
        {
            cout<<-1<<"\n";
        }
        else
        {
            cout<<dp[n].first<<"\n";
            ll k = n;
            ll counter = 1;
            while(k > 0)
            {
                ll box = b[dp[k].second];
                k -= box;
                cout<<box<<" ";
                while(box > 0)
                {
                    cout<<counter<<" ";
                    counter++;
                    box--;
                }
                cout<<"\n";
            }
        }
    }

    //Subtask 2:
    ll sum = 0;
    for(ll i : a)
    {
        sum += i;
    }
    
    if(sum%b[0] != 0 || *max_element(a.begin(), a.end()) > sum/b[0])
    {
        cout<<-1<<"\n";
    }
    else
    {
        vector<vector<ll>> output(sum/b[0], vector<ll> (0));
        priority_queue<pll, vector<pll>, greater<pll>> q; //Contained, index
        for(ll i = 0; i < sum/b[0]; i++)
        {
            q.push({0, i});
        }

        for(ll i = 0; i < n; i++)
        {
            vector<pll> used(0); //Contained, index
            for(ll j = 0; j < a[i]; j++)
            {
                ll c, index;
                tie(c, index) = q.top();
                q.pop();
                used.push_back({c+1, index});
                output[index].push_back(i+1);
            }
            for(pll p : used)
            {
                q.push(p);
            }
        }

        cout<<sum/b[0]<<"\n";
        for(ll i = 0; i < sum/b[0]; i++)
        {
            cout<<b[0]<<" ";
            for(ll j : output[i])
            {
                cout<<j<<" ";
            }
            cout<<"\n";
        }
    }

    return 0;  
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Extra information in the output file
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 328 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Extra information in the output file
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Extra information in the output file
2 Halted 0 ms 0 KB -