結果

問題 No.762 PDCAパス
ユーザー lunnearlunnear
提出日時 2018-12-11 15:02:51
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,366 bytes
コンパイル時間 590 ms
コンパイル使用メモリ 73,136 KB
実行使用メモリ 7,948 KB
最終ジャッジ日時 2023-10-21 20:34:57
合計ジャッジ時間 9,972 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 782 ms
4,840 KB
testcase_23 AC 774 ms
4,840 KB
testcase_24 AC 64 ms
7,948 KB
testcase_25 AC 59 ms
7,948 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 AC 67 ms
6,920 KB
testcase_29 AC 70 ms
6,920 KB
testcase_30 AC 67 ms
6,128 KB
testcase_31 AC 68 ms
6,128 KB
testcase_32 AC 68 ms
6,128 KB
testcase_33 AC 64 ms
5,600 KB
testcase_34 AC 68 ms
5,600 KB
testcase_35 AC 68 ms
5,600 KB
testcase_36 AC 62 ms
4,868 KB
testcase_37 AC 65 ms
4,876 KB
testcase_38 AC 64 ms
4,872 KB
testcase_39 AC 66 ms
4,872 KB
testcase_40 AC 65 ms
4,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <list>
#include <map>

#define MOD 1000000007

unsigned long long count;
char *s;
std::list<int> *to;
std::map<char,int> pdca;

void Serch(int index)
{
    for(auto i = to[index].begin(); i != to[index].end(); i++)
    {
        if((s[index] == 'C') && (s[(*i)] == 'A'))
        {
            count++;
            continue;
        }
        
        if(pdca[s[index]] < pdca[s[(*i)]])
        {
            Serch((*i));
        }
    }
}

int main()
{
    pdca['P'] = 0;
    pdca['D'] = 1;
    pdca['C'] = 2;
    pdca['A'] = 3;
    
    
    int n, m;
    std::cin >> n >> m;
    
    to = new std::list<int>[n];
    s = new char[n + 1];
    std::cin >> s;
    
    for(int i = 0; i < m; i++)
    {
        int n1, n2;
        std::cin >> n1 >> n2;
        n1--;
        n2--;
        
        int sub = pdca[s[n1]] - pdca[s[n2]];
        if(abs(sub) == 1)
        {
            if(sub < 0)
                to[n1].push_back(n2);
            else
                to[n2].push_back(n1);
        }
    }
    
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(s[i] != 'P' || to[i].empty())
            continue;
        
        count = 0;
        Serch(i);
        count %= MOD;
        ans += count;
        ans %= MOD;
    }
    
    std::cout << ans << std::endl;
    
    delete[] s;
    delete[] to;
    
    return 0;
}
0