結果

問題 No.19 ステージの選択
ユーザー なおなお
提出日時 2014-10-09 16:55:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,269 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 80,252 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 23:26:23
合計ジャッジ時間 1,775 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
#define REP(i, n) for(int(i)=0;(i)<(n);++(i))
void rc(int v,int mn,int mx){if(v<mn||mx<v){cerr<<"error"<<endl;}}

int N;
int L[101], S[101];
bool f[101];
const int INF = 1<<29;

int check(int i, vector<int> &v){
    set<int> s;
    s.insert(i);
    while(1){
        i = S[i];
        if(s.count(i)){
            v.insert(v.end(), s.begin(), s.end());
            return i;
        }
        s.insert(i);
    }
}

int main(){
    cin >> N; rc(N,1,100);
    REP(i,N){
        cin >> L[i] >> S[i]; rc(L[i],1,100); rc(S[i],1,N);
        L[i]*=2;
        S[i]--;
    }
    int total = 0;
    REP(i,N){
        if(f[i]) continue;
        vector<int> v;
        int ret = check(i, v);
        if(ret != i){
            total += L[i]/2;
            f[i] = true;
        } else {
            int s = v.size();
            int minv = INF;
            REP(j,s){
                total += L[v[j]]/2;
                minv = min(minv, L[v[j]]);
                f[v[j]] = true;
            }
            total += minv/2;
        }
    }
    cout << fixed << setprecision(1) << total/2.0 << endl;

    return 0;
}
0