結果

問題 No.762 PDCAパス
ユーザー lunnearlunnear
提出日時 2018-12-11 14:38:33
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,497 bytes
コンパイル時間 485 ms
コンパイル使用メモリ 61,644 KB
実行使用メモリ 10,024 KB
最終ジャッジ日時 2023-10-21 19:34:43
合計ジャッジ時間 10,122 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 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 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 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 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 2 ms
4,348 KB
testcase_18 AC 2 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 831 ms
4,864 KB
testcase_23 AC 825 ms
4,864 KB
testcase_24 AC 66 ms
10,024 KB
testcase_25 AC 66 ms
10,024 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 AC 79 ms
8,852 KB
testcase_29 AC 78 ms
8,860 KB
testcase_30 AC 76 ms
7,840 KB
testcase_31 AC 75 ms
7,840 KB
testcase_32 AC 75 ms
7,852 KB
testcase_33 AC 72 ms
6,844 KB
testcase_34 AC 73 ms
6,848 KB
testcase_35 AC 71 ms
6,840 KB
testcase_36 AC 63 ms
5,440 KB
testcase_37 AC 62 ms
5,448 KB
testcase_38 AC 63 ms
5,448 KB
testcase_39 AC 63 ms
5,448 KB
testcase_40 AC 63 ms
5,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <list>

#define MOD 1000000007

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

Node *nodes;
unsigned long long count;

void Serch(Node *n)
{
    for(auto i = n->to.begin(); i != n->to.end(); i++)
    {
        if((n->data == 2) && ((*i)->data == 3))
        {
            count++;
            continue;
        }
        
        if(n->data < (*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)]);
        count %= MOD;
        ans += count;
        ans %= MOD;
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}
0