답안 #1107669

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107669 2024-11-01T22:04:29 Z imarn Worst Reporter 4 (JOI21_worst_reporter4) C++14
0 / 100
7 ms 17744 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
const int mxn=2e5+5;
vector<int> g[mxn];
int a[mxn],h[mxn],c[mxn];
map<int,ll>dp[mxn];
bool vis[mxn]{0};
void dfs(int u){
    vis[u]=1;
    for(auto v:g[u]){
        if(vis[v])continue;
        dfs(v);
        if(dp[v].size()>dp[u].size())swap(dp[u],dp[v]);
        for(auto it:dp[v])dp[u][it.f]+=it.s;
    }
    auto it = dp[u].lower_bound(h[u]);
    int cur=c[u];
    for(;it!=dp[u].end();){
        if(cur>=it->s){cur-=it->s;auto ij=it;it++;dp[u].erase(ij);}
        else {it->s-=cur;break;}
    }dp[u][h[u]]+=c[u];
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;ll rs=0;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>h[i]>>c[i];h[i]=-h[i];
        g[a[i]].pb(i);rs+=c[i];
    }dfs(1);ll rs2=0;
    for(auto it:dp[1])rs2+=it.s;
    cout<<rs-rs2;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16720 KB Output is correct
2 Correct 3 ms 16720 KB Output is correct
3 Correct 3 ms 16720 KB Output is correct
4 Correct 3 ms 16720 KB Output is correct
5 Correct 7 ms 17744 KB Output is correct
6 Incorrect 6 ms 17448 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16720 KB Output is correct
2 Correct 3 ms 16720 KB Output is correct
3 Correct 3 ms 16720 KB Output is correct
4 Correct 3 ms 16720 KB Output is correct
5 Correct 7 ms 17744 KB Output is correct
6 Incorrect 6 ms 17448 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16720 KB Output is correct
2 Correct 3 ms 16720 KB Output is correct
3 Correct 3 ms 16720 KB Output is correct
4 Correct 3 ms 16720 KB Output is correct
5 Correct 7 ms 17744 KB Output is correct
6 Incorrect 6 ms 17448 KB Output isn't correct
7 Halted 0 ms 0 KB -