QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#312428#5146. SkillshazeTL 1ms3600kbC++231.9kb2024-01-23 21:34:322024-01-23 21:34:32

Judging History

你现在查看的是最新测评结果

  • [2024-01-23 21:34:32]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3600kb
  • [2024-01-23 21:34:32]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define irep(i, l, r) for(int i = (l); i <= (r); ++ i)
#define ll long long
void solve(){
    int n;
    cin >> n;
    vector<array<int, 3>>a(n + 1);
    irep(i, 1, n){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    map<array<int, 4>, ll> f;
    ll ans = 0;
    queue<array<int, 4>>stk;
    function<void(int, int, int, int)> work = [&](int i, int j, int k, int l) -> void{
        if(j > 100 || k > 100 || l > 100)return;
        if(i == n)ans = max(ans, f[{i, j, k, l}]);
        if(i + 1 <= n){
            //choose j
            int J = j, K = k, L = l, del = 0, cur = f[{i, j, k, l}];
            J = 0, del += a[i + 1][0];
            if(k != -1)K = k + 1, del -= K;
            if(l != -1)L = l + 1, del -= L;
            f[{i + 1, J, K, L}] = max(f[{i + 1, J, K, L}], 1ll * cur + del);
            stk.push({i + 1, J, K, L});
            // choose k
            J = j, K = k, L = l, del = 0;
            if(j != -1)J = j + 1, del -= J;
            K = 0, del += a[i + 1][1];
            if(l != -1)L = l + 1, del -= L;
            f[{i + 1, J, K, L}] = max(f[{i + 1, J, K, L}], 1ll * cur + del);
            stk.push({i + 1, J, K, L});
            // choose l
            J = j, K = k, L = l, del = 0;
            if(j != -1)J = j + 1, del -= J;
            if(k != -1)K = k + 1, del -= K;
            L = 0, del += a[i + 1][2];
            f[{i + 1, J, K, L}] = max(f[{i + 1, J, K, L}], 1ll * cur + del);
            stk.push({i + 1, J, K, L});
        }
        return;
    };
    f[{0, -1, -1, -1}] = 0;
    stk.push({0, -1, -1, -1});
    while(stk.size()){
        auto [aa,bb,cc,dd] = stk.front();
        work(aa, bb, cc, dd);
        stk.pop();
    }
    cout << ans << '\n';
    return;
}

int main(){
    int TestCase;
    cin >> TestCase;
    while(TestCase --){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3600kb

input:

2
3
1 1 10
1 10 1
10 1 1
5
1 2 3
6 5 4
7 8 9
12 11 10
13 14 15

output:

26
41

result:

ok 2 number(s): "26 41"

Test #2:

score: -100
Time Limit Exceeded

input:

1
200
6219 3608 2383
1139 2158 8611
6721 8216 8887
8736 6707 9755
7210 248 167
3849 276 8050
971 5062 1914
8290 1562 6017
8993 7990 3460
6323 6099 757
7652 4740 6117
6560 4206 180
3705 8906 5752
9619 8939 9696
793 6680 1777
384 3606 8772
9258 3906 709
4396 5083 6614
6057 4410 3132
8596 825 7437
6098...

output:


result: