답안 #898934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
898934 2024-01-05T09:15:49 Z vjudge1 Magic Tree (CEOI19_magictree) C++17
14 / 100
40 ms 11460 KB
//In His Name
#include <bits/stdc++.h>
//#pragma GCC optimization("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
using namespace std;
#define ll long long
#define int ll
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
#define bug(x) cout << "Ah shit , here we go again : " << x <<endl
#define all(x) x.begin() , x.end()
const int maxn = 1e5 + 10, MOD = 1e9 + 7 ;
const ll INF = 1e18 + 100;

struct hoom{
    int v , d , w;
};

int n , m , k  , maxi = -INF , ar[maxn] , javab;
vector<int> adj[maxn] , nums;
vector<hoom> mive;

bool cmp(hoom x , hoom y){
    return (x.v < y.v);
}

void Dfs(int v , int p , int mask){
    for(int u : adj[v]){
        if(u == p) continue;
        Dfs(u , v , mask);
    }
    if(ar[v] != -1){
        if((mask & (1 << ar[v]))) {
            if (maxi <= mive[ar[v]].d) {
                javab += mive[ar[v]].w;
                maxi = max(maxi, mive[ar[v]].d);
            }
        }
    }
}

void Sub1(){
    int res = 0;
    for(int i = 1 ; i < (1 << (n+1)) ; i++){
        maxi = -INF , javab = 0;
        Dfs(0 , -1 , i);
       res = max(res , javab);
    }
    cout << res;
}

void Sub3(){
    for(auto i : mive) nums.pb(i.d);
    reverse(all(nums));
    vector<int> ans;
    int N = nums.size();
    for (int i = 0; i < N; i++) {
        auto it = upper_bound(ans.begin(), ans.end(), nums[i]);
        if (it == ans.end()) {
            ans.push_back(nums[i]);
        }
        else {
            *it = nums[i];
        }
    }
    cout << ans.size();
}


int32_t main(){    
    ios_base::sync_with_stdio(false);
    cin.tie(0) , cout.tie(0);

    cin >> n >> m >> k;
    memset(ar , -1 , sizeof ar);
    int is3 = true;
    for(int i = 1 ; i < n ; i++){
        int p;
        cin >> p;
        p--;
        adj[p].pb(i);
        if(p != i-1) is3 = false;
    }
    int sum = 0;
    for(int i = 0 ; i < m ; i++){
        int a , b , c;
        cin >> a >> b >> c;
        a--;
        sum += c;
        if(c != 1) is3 = false;
        mive.pb({a , b , c});
        ar[a] = i;
    }
    if(is3){
        sort(all(mive)  ,cmp);
        Sub3();
        return 0;
    }
    if(n <= 20){
        Sub1();
        return 0;
    }
    cout << sum;

}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 6236 KB Output is correct
2 Correct 15 ms 6908 KB Output is correct
3 Correct 29 ms 8216 KB Output is correct
4 Correct 24 ms 9684 KB Output is correct
5 Correct 29 ms 8144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 40 ms 10780 KB Output is correct
5 Correct 33 ms 11460 KB Output is correct
6 Correct 37 ms 11208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 8648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 3932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -