結果
| 問題 | No.762 PDCAパス | 
| コンテスト | |
| ユーザー |  bal4u | 
| 提出日時 | 2019-07-10 19:00:56 | 
| 言語 | C (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 7 ms / 2,000 ms | 
| コード長 | 1,286 bytes | 
| コンパイル時間 | 443 ms | 
| コンパイル使用メモリ | 30,848 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-10-15 20:03:52 | 
| 合計ジャッジ時間 | 2,873 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 38 | 
コンパイルメッセージ
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();
      |                        ^~
            
            ソースコード
// 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;
}
            
            
            
        