結果

問題 No.2325 Skill Tree
ユーザー HIcoderHIcoder
提出日時 2023-05-28 15:39:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 892 ms / 3,000 ms
コード長 2,270 bytes
コンパイル時間 1,073 ms
コンパイル使用メモリ 103,296 KB
実行使用メモリ 25,688 KB
最終ジャッジ日時 2023-08-27 12:38:32
合計ジャッジ時間 23,285 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 256 ms
5,092 KB
testcase_08 AC 171 ms
8,080 KB
testcase_09 AC 289 ms
7,140 KB
testcase_10 AC 217 ms
11,316 KB
testcase_11 AC 294 ms
9,516 KB
testcase_12 AC 536 ms
15,788 KB
testcase_13 AC 532 ms
15,532 KB
testcase_14 AC 526 ms
15,524 KB
testcase_15 AC 532 ms
15,552 KB
testcase_16 AC 528 ms
15,500 KB
testcase_17 AC 517 ms
15,520 KB
testcase_18 AC 515 ms
15,580 KB
testcase_19 AC 517 ms
15,584 KB
testcase_20 AC 520 ms
15,548 KB
testcase_21 AC 519 ms
15,628 KB
testcase_22 AC 537 ms
15,668 KB
testcase_23 AC 535 ms
15,532 KB
testcase_24 AC 527 ms
15,696 KB
testcase_25 AC 537 ms
15,788 KB
testcase_26 AC 535 ms
15,764 KB
testcase_27 AC 853 ms
25,620 KB
testcase_28 AC 846 ms
25,672 KB
testcase_29 AC 853 ms
25,572 KB
testcase_30 AC 825 ms
25,568 KB
testcase_31 AC 844 ms
25,484 KB
testcase_32 AC 892 ms
25,152 KB
testcase_33 AC 881 ms
25,512 KB
testcase_34 AC 885 ms
25,688 KB
testcase_35 AC 784 ms
25,316 KB
testcase_36 AC 768 ms
24,764 KB
testcase_37 AC 793 ms
25,576 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:53:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   53 |         auto [lev,id]=pq.top();
      |              ^
main.cpp:75:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   75 |     for(auto [id,lev]:minlevel){
      |              ^
main.cpp:83:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   83 |     for(auto [lev,num]:cnt){
      |              ^

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<tuple>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;

int main(){
    int N;
    cin>>N;
    vector<vector<int>> G(N+1);
    vector<int> indeg(N+1,0);
    vector<int> L(N+1),A(N+1);
    vector<int> requiredlevel(N+1);
   
    for(int i=2;i<=N;i++){
        cin>>L[i]>>A[i];
        //state[L[i]].emplace_back(A[i],i);
        G[A[i]].push_back(i);//A[i]からiに辺をはる
        indeg[i]++;
        requiredlevel[i]=L[i];

    }

    

    priority_queue<P,vector<P>,greater<P>> pq;
    
    for(int to:G[1]){
        indeg[to]--;
        if(indeg[to]==0){
            pq.emplace(requiredlevel[to],to);
        }
    }

    map<int,int> minlevel;

    vector<bool> islearned(N+1,false);
    int nowlev=0;

    while(!pq.empty()){
        auto [lev,id]=pq.top();
        pq.pop();
        
        if(islearned[id]) continue;

        if(nowlev<lev){
            nowlev=lev;
        }

        minlevel[id]=nowlev;
        islearned[id]=true;

        for(int to:G[id]){
            indeg[to]--;
            if(indeg[to]==0 && !islearned[to]){
                pq.emplace(requiredlevel[to],to);
            }
        }
    }

    map<int,int> cnt;

    for(auto [id,lev]:minlevel){
        cnt[lev]++;//levのレベルでidの技を覚えられる
    }
    

    vector<pair<int,int>> ansq1;
    ansq1.emplace_back(0,1);
    int cntsum=1;
    for(auto [lev,num]:cnt){
        cntsum+=num;
        ansq1.emplace_back(lev,cntsum);
    }


   

    int Q;
    cin>>Q;
    vector<int> ans(Q);


    int t,x,y;
    for(int q=0;q<Q;q++){
        
        cin>>t;
        if(t==1){
            cin>>x;//レベルx

            auto it=upper_bound(ansq1.begin(),ansq1.end(),make_pair(x+1,-1));

            if(it==ansq1.begin()){
                ans[q]=-1;
            }else{
                it--;
                ans[q]=it->second;
            }

        }else{
            cin>>y;
            ans[q] =(minlevel.count(y)?minlevel[y]:-1);
        }
    }

    for(auto v:ans){
        cout<<v<<endl;
    }

}
0