結果

問題 No.762 PDCAパス
ユーザー lunnearlunnear
提出日時 2018-12-11 14:26:03
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,493 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 61,184 KB
実行使用メモリ 9,988 KB
最終ジャッジ日時 2023-10-21 19:18:09
合計ジャッジ時間 7,853 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,696 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 909 ms
4,828 KB
testcase_23 AC 911 ms
4,828 KB
testcase_24 AC 64 ms
9,988 KB
testcase_25 AC 64 ms
9,988 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 <list>

#define MOD 1000000007

struct Node
{
    char data;
    std::list<Node*> to;
};

Node *nodes;
int count;

void Serch(Node *n)
{
    for(auto i = n->to.begin(); i != n->to.end(); i++)
    {
        if((n->data == 2) && ((*i)->data == 3))
        {
            count++;
            count %= MOD;
            continue;
        }
        
        if((n->data + 1) == (*i)->data)
        {
            Serch((*i));
        }
    }
}

int main()
{
    int n, m;
    std::cin >> n >> m;
    
    nodes = new Node[n];
    
    char s[n + 1];
    std::cin >> s;
    
    std::list<int> p;
    
    for(int i = 0; i < n; i++)
    {
        switch(s[i]){
        case 'P': nodes[i].data = 0; p.push_back(i); break;
        case 'D': nodes[i].data = 1; break;
        case 'C': nodes[i].data = 2; break;
        case 'A': nodes[i].data = 3; break;
        }
    }
    for(int i = 0; i < m; i++)
    {
        int n1, n2;
        std::cin >> n1 >> n2;
        n1--;
        n2--;
        
        int sub = nodes[n1].data - nodes[n2].data;
        if(abs(sub) == 1)
        {
            if(sub < 0)
                nodes[n1].to.push_back(&nodes[n2]);
            else
                nodes[n2].to.push_back(&nodes[n1]);
        }
    }
    
    int ans = 0;
    for(auto i = p.begin(); i != p.end(); i++)
    {
        count = 0;
        Serch(&nodes[(*i)]);
        ans += count;
        ans %= MOD;
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}
0