結果

問題 No.762 PDCAパス
ユーザー bal4ubal4u
提出日時 2019-07-10 19:00:56
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,286 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 31,744 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 19:15:01
合計ジャッジ時間 2,275 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 0 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 4 ms
5,376 KB
testcase_28 AC 6 ms
5,376 KB
testcase_29 AC 7 ms
5,376 KB
testcase_30 AC 6 ms
5,376 KB
testcase_31 AC 6 ms
5,376 KB
testcase_32 AC 6 ms
5,376 KB
testcase_33 AC 6 ms
5,376 KB
testcase_34 AC 7 ms
5,376 KB
testcase_35 AC 6 ms
5,376 KB
testcase_36 AC 6 ms
5,376 KB
testcase_37 AC 6 ms
5,376 KB
testcase_38 AC 6 ms
5,376 KB
testcase_39 AC 6 ms
5,376 KB
testcase_40 AC 7 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: note: in expansion of macro 'gc'
   14 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.762 PDCAパス
// 2019.7.10 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

// 文字列の入力 スペース以下の文字で入力終了
void ins(char *s) {
	do *s = gc(); while (*s++ > ' ');
	*(s - 1) = 0;
}

#define MOD 1000000007
#define MAX 100005
typedef struct { int u, v; } T;
T to[4][MAX]; int hi[4];
char S[MAX];
signed char idx['P' + 1]['P' + 1];
int node[MAX];

int main()
{
	int i, j, u, v, N, M;
	long long ans;

	idx['P']['D'] = 1, idx['D']['P'] = -1;
	idx['D']['C'] = 2, idx['C']['D'] = -2;
	idx['C']['A'] = 3, idx['A']['C'] = -3;
	N = in(), M = in();
	ins(S);
	while (M--) {
		u = in() - 1, v = in() - 1;
		i = idx[S[u]][S[v]];
		if (i > 0) to[i][hi[i]].u = u, to[i][hi[i]++].v = v;
		else if (i < 0) i = -i, to[i][hi[i]].u = v, to[i][hi[i]++].v = u;
	}
	
	for (i = 0; i < hi[1]; i++) node[to[1][i].u] = 1;
	for (j = 1; j <= 3; j++) for (i = 0; i < hi[j]; i++)
		node[to[j][i].v] += node[to[j][i].u];

	ans = 0;
	for (i = 0; i < hi[3]; i++) {
		ans += node[to[3][i].v];
		node[to[3][i].v] = 0;
	}
	printf("%d\n", (int)(ans % MOD));
	return 0;
}
0