結果

問題 No.762 PDCAパス
ユーザー tetsuzuki1115tetsuzuki1115
提出日時 2019-08-26 02:14:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,415 bytes
コンパイル時間 1,010 ms
コンパイル使用メモリ 99,560 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-25 00:07:59
合計ジャッジ時間 10,248 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 TLE -
testcase_23 TLE -
testcase_24 AC 63 ms
8,064 KB
testcase_25 AC 62 ms
8,064 KB
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

vector< vector<int> > P;
string S;

bool is_PDCA( char a, char b ) {
    bool ret = false;
    string pdca = "PDCA";
    for ( int i = 0; i < 3; i++ ) {
        if ( pdca[i] == a && pdca[i+1] == b ) { ret = true; }
    }
    return ret;
}

long long dfs( int v ) {

    if ( S[v] == 'A' ) { return 1; }
    long long ret = 0;
    for ( int i = 0; i < P[v].size(); i++ ) {
        ret += dfs( P[v][i] );
        ret %= MOD;
    }
    return ret;
}

int main() {

    int N,M;
    cin >> N >> M >> S;
    
    P.resize(N);

    vector<int> start;
    for ( int i = 0; i < S.length(); i++ ) {
        if ( S[i] == 'P' ) { start.push_back(i); }
    }

    for ( int i = 0; i < M; i++ ) {
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        if ( is_PDCA( S[a], S[b] ) ) {
            P[a].push_back( b );
        }
        if ( is_PDCA( S[b], S[a] ) ) {
            P[b].push_back( a );
        }        
    }

    long long ans = 0;
    for ( int i = 0; i < start.size(); i++ ) {
        ans += dfs( start[i] );
        ans %= MOD;
    }

    cout << ans << endl;


    return 0;
}
0