結果

問題 No.1340 おーじ君をさがせ
ユーザー maspymaspy
提出日時 2020-09-26 16:14:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,478 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 77,148 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-05-05 02:28:11
合計ジャッジ時間 2,834 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
13,440 KB
testcase_01 WA -
testcase_02 AC 5 ms
13,184 KB
testcase_03 AC 7 ms
13,184 KB
testcase_04 AC 7 ms
13,184 KB
testcase_05 AC 6 ms
13,312 KB
testcase_06 AC 7 ms
13,184 KB
testcase_07 AC 7 ms
13,184 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 21 ms
13,184 KB
testcase_11 WA -
testcase_12 AC 11 ms
7,168 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 12 ms
7,040 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 14 ms
13,312 KB
testcase_21 AC 8 ms
5,376 KB
testcase_22 AC 6 ms
5,376 KB
testcase_23 AC 8 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 11 ms
5,376 KB
testcase_26 AC 11 ms
5,376 KB
testcase_27 AC 12 ms
5,376 KB
testcase_28 AC 10 ms
5,376 KB
testcase_29 AC 20 ms
13,440 KB
testcase_30 AC 8 ms
5,376 KB
testcase_31 AC 7 ms
5,376 KB
testcase_32 AC 10 ms
5,376 KB
testcase_33 AC 10 ms
5,376 KB
testcase_34 AC 10 ms
5,376 KB
testcase_35 AC 10 ms
5,376 KB
testcase_36 WA -
testcase_37 AC 9 ms
13,312 KB
testcase_38 AC 37 ms
13,312 KB
testcase_39 AC 9 ms
5,376 KB
testcase_40 AC 10 ms
5,376 KB
testcase_41 AC 9 ms
5,376 KB
testcase_42 AC 8 ms
13,312 KB
testcase_43 AC 8 ms
13,184 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 6 ms
5,376 KB
testcase_50 AC 6 ms
5,376 KB
testcase_51 AC 6 ms
5,376 KB
testcase_52 AC 5 ms
5,376 KB
testcase_53 AC 5 ms
5,376 KB
testcase_54 WA -
testcase_55 AC 4 ms
5,376 KB
testcase_56 AC 7 ms
13,184 KB
testcase_57 AC 8 ms
13,184 KB
testcase_58 AC 6 ms
13,312 KB
testcase_59 AC 5 ms
5,376 KB
testcase_60 AC 6 ms
13,184 KB
testcase_61 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 適当な時刻まで探索して、
// 最後 2 回の到着時刻で周期を決め打ってしまう
// 厳密解の意味では N^3M 解法?(自信なし)

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;


bool dp[1000000][100];
int frm[10000];
int to[10000];

ll N, M, T, ans;

int main(){
    cin >> N >> M >> T;
    vector<int> vec;
    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        vec.emplace_back(N*a+b);
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    M = vec.size();

    for(int i=0;i<M;i++){
        frm[i] = vec[i] / N;
        to[i] = vec[i] % N;
    }
    dp[0][0] = true;
    // 適当なところまで探索する
    int T0 = min(100000ll, 100000000/(N*M+1));
    for(int t=1;t<=T0;t++){
        for(int e=0;e<M;e++){
            dp[t][to[e]] |= dp[t-1][frm[e]];
        }
    }
    for(int v=0;v<N;v++){
        // last two
        ll t1 = -1;
        ll t2 = -1;
        for (int t=0;t<T0;t++){
            if(dp[t][v]){
                t1 = t2;
                t2 = t;
            }
        }
        if(T < T0){
            ans += (dp[T][v] ? 1 : 0);
        } else{
            if(t1 >= 0){
                ll p = t2 - t1;
                ll n = (T-T0)/p+1;
                ans += (dp[T-n*p][v] ? 1 : 0);
            }
        }
    }
    if(ans==0){
        ans-=1;
    }
    cout << ans << endl;
    return 0;
}
0