답안 #1009930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1009930 2024-06-28T08:06:00 Z snpmrnhlol Ants and Sugar (JOI22_sugar) C++17
6 / 100
140 ms 17340 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5 + 5;
const ll inf = 1e18;
array<ll,3> v[N];
vector <ll> pos;
ll cost[N][4];
ll dp[N][4];
ll n,k,sz;
ll sum = 0;
ll get(){
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    dp[0][3] = 0;
    for(ll i = 1;i < sz;i++){
        for(ll j = 0;j < 4;j++){
            dp[i][j] = -inf;
        }
        for(ll j = 0;j < 4;j++){
            if(j/2 == 0){
                dp[i][j] = max(dp[i][j],dp[i - 1][0] + cost[i][j]);
                dp[i][j] = max(dp[i][j],dp[i - 1][2] + cost[i][j]);
            }else{
                dp[i][j] = max(dp[i][j],dp[i - 1][1] + cost[i][j]);
                dp[i][j] = max(dp[i][j],dp[i - 1][3] + cost[i][j]);
            }
            //cout<<pos[i]<<' '<<cost[i][j]<<' '<<dp[i][j]<<' ';
        }
        //cout<<'\n';
    }
    return max(dp[sz - 1][0],dp[sz - 1][2]);
}
int main(){
    cin>>n>>k;
    for(ll i = 0;i < n;i++){
        cin>>v[i][0]>>v[i][1]>>v[i][2];
        pos.push_back(v[i][1]);
    }
    pos.push_back(-inf);
    pos.push_back(inf);
    sort(pos.begin(),pos.end());
    pos.erase(unique(pos.begin(),pos.end()),pos.end());
    sz = pos.size();
    for(ll i = 0;i < n;i++){
        if(v[i][0] == 1){
            for(ll j = 0;j < sz;j++){
                if(pos[j] == v[i][1]){
                    cost[j][1]+=v[i][2];
                    cost[j][3]+=v[i][2];
                }
            }
            sum+=v[i][2];
        }else if(v[i][0] == 2){
            bool ok = 0;
            for(ll j = 0;j < sz;j++){
                if(v[i][1] - k <= pos[j] && pos[j] <= v[i][1] + k){
                    cost[j][1]-=v[i][2];
                    if(!ok){cost[j][3]-=v[i][2];ok = 1;}
                }
            }
        }
        cout<<sum - get()<<'\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4544 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 33 ms 688 KB Output is correct
7 Correct 18 ms 4444 KB Output is correct
8 Correct 7 ms 4608 KB Output is correct
9 Correct 6 ms 2396 KB Output is correct
10 Correct 67 ms 2652 KB Output is correct
11 Correct 71 ms 4696 KB Output is correct
12 Correct 78 ms 4800 KB Output is correct
13 Correct 67 ms 4696 KB Output is correct
14 Correct 67 ms 4760 KB Output is correct
15 Correct 66 ms 4700 KB Output is correct
16 Correct 93 ms 4700 KB Output is correct
17 Correct 65 ms 2652 KB Output is correct
18 Correct 64 ms 2648 KB Output is correct
19 Correct 66 ms 4832 KB Output is correct
20 Correct 65 ms 2652 KB Output is correct
21 Correct 93 ms 4696 KB Output is correct
22 Correct 66 ms 4700 KB Output is correct
23 Correct 67 ms 2828 KB Output is correct
24 Correct 69 ms 604 KB Output is correct
25 Correct 67 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Runtime error 103 ms 17340 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 140 ms 17340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4544 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 33 ms 688 KB Output is correct
7 Correct 18 ms 4444 KB Output is correct
8 Correct 7 ms 4608 KB Output is correct
9 Correct 6 ms 2396 KB Output is correct
10 Correct 67 ms 2652 KB Output is correct
11 Correct 71 ms 4696 KB Output is correct
12 Correct 78 ms 4800 KB Output is correct
13 Correct 67 ms 4696 KB Output is correct
14 Correct 67 ms 4760 KB Output is correct
15 Correct 66 ms 4700 KB Output is correct
16 Correct 93 ms 4700 KB Output is correct
17 Correct 65 ms 2652 KB Output is correct
18 Correct 64 ms 2648 KB Output is correct
19 Correct 66 ms 4832 KB Output is correct
20 Correct 65 ms 2652 KB Output is correct
21 Correct 93 ms 4696 KB Output is correct
22 Correct 66 ms 4700 KB Output is correct
23 Correct 67 ms 2828 KB Output is correct
24 Correct 69 ms 604 KB Output is correct
25 Correct 67 ms 860 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 456 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Runtime error 103 ms 17340 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -