[SWEA] 7853 오타

Time Lapse :17min 38sec

7853.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#define MOD 1000000007
int main(void){
register int test_case, idx;
register long answer;
int T;
char c[1001];
scanf("%d",&T);
getchar();
for(test_case = 1; test_case<=T; test_case++){
idx = 0;
answer = 1;
c[idx++] = getchar();
c[idx++] = getchar();
c[idx++] = getchar();
while('a'<=c[idx-1]){
answer = c[idx-3]!=c[idx-2]&&c[idx-3]!=c[idx-1]&&c[idx-2]!=c[idx-1] ? (answer+(answer<<1))%MOD : c[idx-3]==c[idx-2]&&c[idx-2]==c[idx-1] ? answer : (answer<<1)%MOD;
c[idx++] = getchar();
}
answer <<= c[0]!=c[1]&&c[idx-2]!=c[idx-3] ? 2 : c[0]==c[1]&&c[idx-2]==c[idx-3] ? 0 : 1;
printf("#%d %d\n",test_case,answer%MOD);
}
return 0;
}
/* SAME CODE
#include <stdio.h>
#define MOD 1000000007
int main(void){
register int test_case, idx, i;
register long answer;
int T;
char c[1001];
scanf("%d",&T);
getchar();
for(test_case = 1; test_case<=T; test_case++){
idx = 0;
answer = 1;
do {
c[idx++] = getchar();
}while('a'<=c[idx-1]&&c[idx-1]<='z');
answer <<= c[0]!=c[1]&&c[idx-2]!=c[idx-3] ? 2 : c[0]==c[1]&&c[idx-2]==c[idx-3] ? 0 : 1;
for(i=1;i<idx-2;i++)
answer = c[i-1]!=c[i]&&c[i-1]!=c[i+1]&&c[i]!=c[i+1] ?
(answer+(answer<<1))%MOD : c[i-1]==c[i]&&c[i]==c[i+1] ?
answer : (answer<<1)%MOD;

printf("#%d %d\n",test_case,answer%MOD);
}
return 0;
}
*/
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/7853/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.