結果

問題 No.762 PDCAパス
ユーザー lunnearlunnear
提出日時 2018-12-11 15:08:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,359 bytes
コンパイル時間 946 ms
コンパイル使用メモリ 73,148 KB
実行使用メモリ 7,972 KB
最終ジャッジ日時 2023-10-21 20:43:50
合計ジャッジ時間 3,609 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 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 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 66 ms
4,864 KB
testcase_23 AC 66 ms
4,864 KB
testcase_24 AC 68 ms
7,972 KB
testcase_25 AC 66 ms
7,972 KB
testcase_26 AC 130 ms
6,804 KB
testcase_27 AC 130 ms
6,804 KB
testcase_28 AC 73 ms
6,916 KB
testcase_29 AC 73 ms
6,916 KB
testcase_30 AC 71 ms
6,124 KB
testcase_31 AC 71 ms
6,124 KB
testcase_32 AC 72 ms
6,124 KB
testcase_33 AC 69 ms
5,596 KB
testcase_34 AC 69 ms
5,596 KB
testcase_35 AC 69 ms
5,596 KB
testcase_36 AC 63 ms
4,864 KB
testcase_37 AC 63 ms
4,872 KB
testcase_38 AC 64 ms
4,868 KB
testcase_39 AC 64 ms
4,868 KB
testcase_40 AC 63 ms
4,868 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')
        {
            count += to[index].size();
            break;
        }
        
        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