답안 #898011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
898011 2024-01-04T07:43:49 Z vlnt32 Cloud Computing (CEOI18_clo) C++14
100 / 100
1344 ms 25760 KB
#include <bits/stdc++.h>
#define problem "test"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).resize(unique(ALL(v)) - (v).begin())
#define BIT(x,i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
using namespace std;
const int N = 2000;

template<class X,class Y>
    bool maximize(X &x,Y y){
        if (x < y){
            x = y;    return true;
        }
        return false;
    }

template<class X,class Y>
    bool minimize(X &x,Y y){
        if (x > y){
            x = y;    return true;
        }
        return false;
    }

struct State{
    ll c,f,v;
    State (ll _c = 0,ll _f = 0,ll _v = 0){
        c = _c, f = _f, v = _v;
    }
    void input(){
        cin>>c>>f>>v;
    }
    bool operator < (const State &other) const{
        return f > other.f;
    }
};

int n,m;
State cpt[N + 5],person[N + 5];
ll maxCore,maxF;

namespace subtask1{
    const int nMax = 15;
    const int sMax = 750;
    ll dp[2][N + 5][sMax + 5],oo;

    void process(){
        int sumMax = 0;
        for (int i=1;i<= n;i++ )
            sumMax += cpt[i].c;
        memset(dp,-0x3f,sizeof(dp));
        oo = dp[0][0][0];
        dp[0][0][0] = 0;
        for (int i=0;i<= n;i++ ){
            memset(dp[(i + 1) & 1],-0x3f,sizeof(dp[(i + 1) & 1]));
            for (int j=0;j<= m;j++ )
                for (int cnt=0;cnt<= sumMax;cnt++ )
                    if (dp[i & 1][j][cnt] != oo){
                        if (j < m && person[j + 1].f <= cpt[i].f && person[j + 1].c <= cnt)
                            maximize(dp[i & 1][j + 1][cnt - person[j + 1].c],dp[i & 1][j][cnt] + person[j + 1].v);
                        if (i < n && cnt + cpt[i + 1].c <= sumMax)
                            maximize(dp[(i + 1) & 1][j][cnt + cpt[i + 1].c],dp[i & 1][j][cnt] - cpt[i + 1].v);
                        maximize(dp[(i + 1) & 1][j][cnt],dp[i & 1][j][cnt]);
                        maximize(dp[i & 1][j + 1][cnt],dp[i & 1][j][cnt]);
                        maximize(dp[(i + 1) & 1][j + 1][cnt],dp[i & 1][j][cnt]);
                    }
        }
        ll res = oo;
        for (int cnt=0;cnt<= sumMax;cnt++ )
            maximize(res,dp[n & 1][m][cnt]);
        cout<<res;
    }
};

namespace subtask2{
    const int nMax = 15;
    const int sMax = 750;
    ll dp[2][nMax + 5][sMax + 5],oo;

    void process(){
        int sumMax = 0;
        for (int i=1;i<= n;i++ )
            sumMax += person[i].c;
        memset(dp,-0x3f,sizeof(dp));
        oo = dp[0][0][0];
        dp[0][0][0] = 0;
        for (int i=0;i<= n;i++ ){
            memset(dp[(i + 1) & 1],-0x3f,sizeof(dp[(i + 1) & 1]));
            for (int j=0;j<= m;j++ )
                for (int cnt=0;cnt<= sumMax;cnt++ )
                    if (dp[i & 1][j][cnt] != oo){
                        if (j < m && person[j + 1].f <= cpt[i].f && person[j + 1].c <= cnt)
                            maximize(dp[i & 1][j + 1][cnt - person[j + 1].c],dp[i & 1][j][cnt] + person[j + 1].v);
                        if (i < n){
                            int newCnt = (cnt + cpt[i + 1].c >= sumMax ? sumMax : cnt + cpt[i + 1].c);
                            maximize(dp[(i + 1) & 1][j][newCnt],dp[i & 1][j][cnt] - cpt[i + 1].v);
                        }
                        maximize(dp[(i + 1) & 1][j][cnt],dp[i & 1][j][cnt]);
                        maximize(dp[i & 1][j + 1][cnt],dp[i & 1][j][cnt]);
                        maximize(dp[(i + 1) & 1][j + 1][cnt],dp[i & 1][j][cnt]);
                    }
        }
        ll res = oo;
        for (int cnt=0;cnt<= sumMax;cnt++ )
            maximize(res,dp[n & 1][m][cnt]);
        cout<<res;
    }
};

namespace subtask3{
    const int nMax = 2000;
    ll dp[nMax + 5][nMax + 5],oo;

    void process(){
        for (int i=1;i<= n;i++ )
            for (int j=1;j<= m;j++ ){
                dp[i][j] = max({dp[i][j - 1],dp[i - 1][j],dp[i - 1][j - 1]});
                if (cpt[i].f >= person[j].f)
                    dp[i][j] = max(dp[i][j],dp[i - 1][j - 1] + person[j].v - cpt[i].v);
            }

        cout<<dp[n][m];
    }
}

namespace subtask4{
    const int sumMax = 1e5;

    ll maxValue[sumMax + 5],minCost[sumMax + 5],oo;

    void process(){
        int sumCpt = 0;
        for (int i=1;i<= n;i++ )
            sumCpt += cpt[i].c;
        memset(minCost,0x3f,sizeof(minCost));
        minCost[0] = 0;

        for (int i=1;i<= n;i++ )
            for (int cnt=sumCpt;cnt>= cpt[i].c;cnt-- )
                minimize(minCost[cnt],minCost[cnt - cpt[i].c]  + cpt[i].v);

        int sumPer = 0;
        for (int i=1;i<= m;i++ )
            sumPer += person[i].c;
        memset(maxValue,-0x3f,sizeof(maxValue));
        oo = maxValue[0];
        maxValue[0] = 0;

        for (int i=1;i<= m;i++ )
            for (int cnt=sumPer;cnt>= person[i].c;cnt-- )
                maximize(maxValue[cnt],maxValue[cnt - person[i].c] + person[i].v);

        for (int i=sumCpt;i>= 0;i-- )
            minimize(minCost[i],minCost[i + 1]);

        ll res = 0;

        for (int i=0;i<= min(sumCpt,sumPer);i++ )
            if (maxValue[i] != oo)
                res = max(res,maxValue[i] - minCost[i]);

        cout<<res;
    }
};

namespace subtask6{
    const int nMax = 2000;
    const int cMax = 100;
    ll dp[2][nMax + 5][cMax + 5],oo;

    void process(){
        memset(dp,-0x3f,sizeof(dp));
        oo = dp[0][0][0];
        dp[0][0][0] = 0;
        for (int i=0;i<= n;i++ ){
            memset(dp[(i + 1) & 1],-0x3f,sizeof(dp[(i + 1) & 1]));
            for (int j=0;j<= m;j++ )
                for (int cnt=0;cnt<= 100;cnt++ )
                    if (dp[i & 1][j][cnt] != oo){
                        if (j < m && person[j + 1].f <= cpt[i].f && person[j + 1].c <= cnt)
                            maximize(dp[i & 1][j + 1][cnt - person[j + 1].c],dp[i & 1][j][cnt] + person[j + 1].v);
                        if (i < n && cnt + cpt[i + 1].c <= cMax){
                            int newCnt = (cnt + cpt[i + 1].c);
                            maximize(dp[(i + 1) & 1][j][newCnt],dp[i & 1][j][cnt] - cpt[i + 1].v);
                        }
                        maximize(dp[(i + 1) & 1][j][cnt],dp[i & 1][j][cnt]);
                        maximize(dp[i & 1][j + 1][cnt],dp[i & 1][j][cnt]);
                        maximize(dp[(i + 1) & 1][j + 1][cnt],dp[i & 1][j][cnt]);
                    }
        }
        ll res = 0;
        for (int cnt=0;cnt<= 100;cnt++ )
            maximize(res,dp[n & 1][m][cnt]);
        cout<<res;
    }
};

int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);
    cin>>n;
    for (int i=1;i<= n;i++ ){
        cpt[i].input();
        maxCore = max(maxCore,cpt[i].c);
        maxF = max(maxF,cpt[i].f);
    }
    cin>>m;
    for (int i=1;i<= m;i++ ){
        person[i].input();
        maxCore = max(maxCore,person[i].c);
        maxF = max(maxF,person[i].f);
    }

    sort(cpt + 1,cpt + n + 1);
    sort(person + 1,person + m + 1);

    if (n <= 15)
        subtask1 :: process();
    else if (m <= 15)
        subtask2 :: process();
    else if (maxCore == 1)
        subtask3 :: process();
    else if (maxF == 1)
        subtask4 :: process();
    else subtask6 :: process();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25688 KB Output is correct
2 Correct 5 ms 25688 KB Output is correct
3 Correct 10 ms 25756 KB Output is correct
4 Correct 10 ms 25688 KB Output is correct
5 Correct 42 ms 25688 KB Output is correct
6 Correct 17 ms 25692 KB Output is correct
7 Correct 56 ms 25692 KB Output is correct
8 Correct 57 ms 25740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25688 KB Output is correct
2 Correct 8 ms 25760 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 19 ms 2396 KB Output is correct
6 Correct 13 ms 2396 KB Output is correct
7 Correct 69 ms 2396 KB Output is correct
8 Correct 82 ms 2392 KB Output is correct
9 Correct 75 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 25692 KB Output is correct
2 Correct 13 ms 25692 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 688 KB Output is correct
5 Correct 1 ms 1628 KB Output is correct
6 Correct 1 ms 1624 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 25688 KB Output is correct
2 Correct 11 ms 25692 KB Output is correct
3 Correct 14 ms 2396 KB Output is correct
4 Correct 41 ms 25692 KB Output is correct
5 Correct 117 ms 4640 KB Output is correct
6 Correct 234 ms 4688 KB Output is correct
7 Correct 234 ms 4636 KB Output is correct
8 Correct 223 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 25692 KB Output is correct
2 Correct 3 ms 4700 KB Output is correct
3 Correct 72 ms 4700 KB Output is correct
4 Correct 408 ms 4808 KB Output is correct
5 Correct 1298 ms 4808 KB Output is correct
6 Correct 1344 ms 4816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 25688 KB Output is correct
2 Correct 5 ms 25688 KB Output is correct
3 Correct 10 ms 25756 KB Output is correct
4 Correct 10 ms 25688 KB Output is correct
5 Correct 42 ms 25688 KB Output is correct
6 Correct 17 ms 25692 KB Output is correct
7 Correct 56 ms 25692 KB Output is correct
8 Correct 57 ms 25740 KB Output is correct
9 Correct 5 ms 25688 KB Output is correct
10 Correct 8 ms 25760 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 19 ms 2396 KB Output is correct
14 Correct 13 ms 2396 KB Output is correct
15 Correct 69 ms 2396 KB Output is correct
16 Correct 82 ms 2392 KB Output is correct
17 Correct 75 ms 2396 KB Output is correct
18 Correct 13 ms 25692 KB Output is correct
19 Correct 13 ms 25692 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 1 ms 688 KB Output is correct
22 Correct 1 ms 1628 KB Output is correct
23 Correct 1 ms 1624 KB Output is correct
24 Correct 1 ms 1884 KB Output is correct
25 Correct 1 ms 1884 KB Output is correct
26 Correct 12 ms 25688 KB Output is correct
27 Correct 11 ms 25692 KB Output is correct
28 Correct 14 ms 2396 KB Output is correct
29 Correct 41 ms 25692 KB Output is correct
30 Correct 117 ms 4640 KB Output is correct
31 Correct 234 ms 4688 KB Output is correct
32 Correct 234 ms 4636 KB Output is correct
33 Correct 223 ms 4436 KB Output is correct
34 Correct 7 ms 25692 KB Output is correct
35 Correct 3 ms 4700 KB Output is correct
36 Correct 72 ms 4700 KB Output is correct
37 Correct 408 ms 4808 KB Output is correct
38 Correct 1298 ms 4808 KB Output is correct
39 Correct 1344 ms 4816 KB Output is correct
40 Correct 132 ms 4828 KB Output is correct
41 Correct 321 ms 4836 KB Output is correct
42 Correct 15 ms 24668 KB Output is correct
43 Correct 516 ms 4868 KB Output is correct
44 Correct 502 ms 4700 KB Output is correct
45 Correct 516 ms 4700 KB Output is correct
46 Correct 8 ms 14428 KB Output is correct
47 Correct 15 ms 24600 KB Output is correct
48 Correct 15 ms 24408 KB Output is correct