結果
問題 | No.2325 Skill Tree |
ユーザー | Naoto Fujiwara |
提出日時 | 2023-05-29 18:35:42 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 803 ms / 3,000 ms |
コード長 | 2,275 bytes |
コンパイル時間 | 2,166 ms |
コンパイル使用メモリ | 103,180 KB |
実行使用メモリ | 25,816 KB |
最終ジャッジ日時 | 2023-08-27 23:49:46 |
合計ジャッジ時間 | 23,156 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 252 ms
5,128 KB |
testcase_08 | AC | 167 ms
8,096 KB |
testcase_09 | AC | 290 ms
6,948 KB |
testcase_10 | AC | 210 ms
11,472 KB |
testcase_11 | AC | 287 ms
9,360 KB |
testcase_12 | AC | 519 ms
15,672 KB |
testcase_13 | AC | 527 ms
15,880 KB |
testcase_14 | AC | 534 ms
15,620 KB |
testcase_15 | AC | 526 ms
15,576 KB |
testcase_16 | AC | 528 ms
15,548 KB |
testcase_17 | AC | 514 ms
15,612 KB |
testcase_18 | AC | 512 ms
15,616 KB |
testcase_19 | AC | 512 ms
15,512 KB |
testcase_20 | AC | 511 ms
15,624 KB |
testcase_21 | AC | 510 ms
15,588 KB |
testcase_22 | AC | 528 ms
15,696 KB |
testcase_23 | AC | 534 ms
15,600 KB |
testcase_24 | AC | 530 ms
15,688 KB |
testcase_25 | AC | 524 ms
15,576 KB |
testcase_26 | AC | 525 ms
15,820 KB |
testcase_27 | AC | 803 ms
25,552 KB |
testcase_28 | AC | 763 ms
25,768 KB |
testcase_29 | AC | 755 ms
25,612 KB |
testcase_30 | AC | 759 ms
25,588 KB |
testcase_31 | AC | 751 ms
25,552 KB |
testcase_32 | AC | 779 ms
25,192 KB |
testcase_33 | AC | 790 ms
25,816 KB |
testcase_34 | AC | 781 ms
25,676 KB |
testcase_35 | AC | 715 ms
25,060 KB |
testcase_36 | AC | 710 ms
25,060 KB |
testcase_37 | AC | 717 ms
25,620 KB |
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内: main.cpp:54:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 54 | auto [lev,id]=pq.top(); | ^ main.cpp:76:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 76 | for(auto [id,lev]:minlevel){ | ^ main.cpp:84:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions] 84 | for(auto [lev,num]:cnt){ | ^
ソースコード
//AC #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; } }