結果

問題 No.19 ステージの選択
ユーザー momoyuumomoyuu
提出日時 2023-10-24 17:32:25
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,088 bytes
コンパイル時間 3,103 ms
コンパイル使用メモリ 250,356 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 17:32:30
合計ジャッジ時間 3,966 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    
    int n;
    cin>>n;
    vector<double> l(n);
    vector<int> u(n);
    double ans = 0;
    vector<int> cnt(n,0);
    vector<int> vis(n,0);
    for(int i = 0;i<n;i++){
        cin>>l[i]>>u[i];
        u[i]--;
        cnt[u[i]]++;
        if(u[i]==i){
            ans += l[i];
            vis[i]++;
        }
    }
    vector<int> que;
    for(int i = 0;i<n;i++) if(cnt[i]==0) que.push_back(i);
    for(int i = 0;i<que.size();i++){
        int ni = que[i];
        vis[ni]++;
        ans += l[ni];
        l[u[ni]] /= 2.;
        cnt[u[ni]]--;
        if(cnt[u[ni]]==0) que.push_back(u[ni]);
    }
    for(int i = 0;i<n;i++){
        if(vis[i]) continue;
        double mn = 1e9;
        int ni = i;
        while(true){
            mn = min(mn,l[ni]);
            vis[ni]++;
            ans += l[ni] / 2.;
            ni = u[ni];
            if(ni==i) break;
        }
        ans += mn/2.;
    }
    cout<<setprecision(1)<<fixed<<ans<<endl;
}

0