結果

問題 No.762 PDCAパス
ユーザー 佐藤竜也佐藤竜也
提出日時 2023-03-24 17:03:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,247 bytes
コンパイル時間 1,826 ms
コンパイル使用メモリ 176,720 KB
実行使用メモリ 35,964 KB
最終ジャッジ日時 2023-10-18 20:30:21
合計ジャッジ時間 9,773 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,816 KB
testcase_01 AC 3 ms
5,468 KB
testcase_02 AC 3 ms
5,468 KB
testcase_03 AC 4 ms
5,468 KB
testcase_04 AC 3 ms
5,468 KB
testcase_05 AC 3 ms
5,468 KB
testcase_06 AC 4 ms
5,468 KB
testcase_07 AC 4 ms
5,468 KB
testcase_08 AC 4 ms
5,468 KB
testcase_09 AC 4 ms
5,468 KB
testcase_10 AC 4 ms
5,468 KB
testcase_11 AC 4 ms
5,468 KB
testcase_12 AC 3 ms
5,468 KB
testcase_13 AC 3 ms
5,468 KB
testcase_14 AC 4 ms
5,468 KB
testcase_15 AC 4 ms
5,468 KB
testcase_16 AC 3 ms
5,468 KB
testcase_17 AC 3 ms
5,468 KB
testcase_18 AC 3 ms
5,468 KB
testcase_19 AC 4 ms
5,468 KB
testcase_20 AC 3 ms
5,468 KB
testcase_21 AC 4 ms
5,468 KB
testcase_22 AC 1,098 ms
12,308 KB
testcase_23 AC 1,095 ms
12,308 KB
testcase_24 AC 69 ms
9,140 KB
testcase_25 AC 68 ms
9,140 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 <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2(i, n, s) for (int i = (n - 1); i >= (s); i--)
#define all(a)  (a).begin(),(a).end()
#define all_c(a, b) (a).begin(), (a).end(), back_inserter((b))
vector<int> dy = {-1, 0, 1, 0, -1, -1, 1, 1};
vector<int> dx = {0, 1, 0, -1, -1, 1, 1, -1};
const ll INF = numeric_limits<long long>::max();
const ll MOD = 1'000'000'007;
ll unused = INF % MOD;

ll gcd(ll A, ll B) {
    if (B == 0) return A;
    return gcd(B, A % B);
}

ll lcm(ll A, ll B) {
    ll g = gcd(A, B);
    return A / g * B;
}

// 二分検索の雛型
bool binary_search(int N, int A[], int K) {
    int left = 0, right = N - 1;
    while (left <= right) {
        int mid = (left + right) / 2;
        if (A[mid] == K) return true;
        if (A[mid] < K) left = mid + 1;
        else right = mid - 1;
    }
    return false;
}

/*
lower_bound -> if (A[mid] < K)
upper_bound -> if (A[mid] <= K)
*/
int binary_search2(int N, ll A[], ll K) {
    int left = 0, right = N;
    while (left < right) {
        int mid = (left + right) / 2;
        if (A[mid] < K) left = mid + 1;
        else right = mid;
    }
    return right;
}

/* メモ帳
・小数点以下表示 / cout << fixed << setprecision(12) << 
・ルートの計算   / sqrt(A)

・順列全列挙
    do {
        
    } while (next_permutation(V.begin() V.end()));

・bit検索
for (int i = 0; i < (1 << N); i++) {
    rep(j, 0, N) {
        int wari = (1 << j);
        if ((i / wari) % 2 == 1) {
            
        }
    }
}
*/

int N, M;
string S;
vector<vector<int>> V(100009);
ll ans = 0;

int main() {
    cin >> N >> M >> S;
    rep(i, 0, M) {
        int u, v; cin >> u >> v;
        V[u].push_back(v);
        V[v].push_back(u);
    }
    
    queue<int> Q;
    rep(i, 0, N) if (S[i] == 'P') Q.push(i + 1);
    while (Q.size() > 0) {
        int now = Q.front(); Q.pop();
        for (auto next: V[now]) {
            if (S[now - 1] == 'P' && S[next - 1] == 'D') Q.push(next);
            if (S[now - 1] == 'D' && S[next - 1] == 'C') Q.push(next);
            if (S[now - 1] == 'C' && S[next - 1] == 'A') ans++;
        }
    }
    
    cout << ans % 1000000007 << endl;
}
0