結果

問題 No.762 PDCAパス
ユーザー lunnearlunnear
提出日時 2019-01-05 02:46:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,414 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 72,000 KB
実行使用メモリ 8,076 KB
最終ジャッジ日時 2023-08-15 15:33:56
合計ジャッジ時間 2,943 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 39 ms
4,616 KB
testcase_23 AC 38 ms
4,644 KB
testcase_24 AC 31 ms
7,824 KB
testcase_25 AC 30 ms
8,076 KB
testcase_26 AC 95 ms
6,584 KB
testcase_27 AC 95 ms
6,644 KB
testcase_28 AC 34 ms
6,784 KB
testcase_29 AC 33 ms
6,780 KB
testcase_30 AC 32 ms
6,132 KB
testcase_31 AC 31 ms
6,048 KB
testcase_32 AC 31 ms
5,972 KB
testcase_33 AC 30 ms
5,568 KB
testcase_34 AC 33 ms
5,464 KB
testcase_35 AC 31 ms
5,444 KB
testcase_36 AC 28 ms
4,608 KB
testcase_37 AC 28 ms
4,612 KB
testcase_38 AC 28 ms
4,668 KB
testcase_39 AC 28 ms
4,692 KB
testcase_40 AC 29 ms
4,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#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;
        scanf("%d %d", &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