-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprs.cpp
More file actions
115 lines (110 loc) · 2.81 KB
/
prs.cpp
File metadata and controls
115 lines (110 loc) · 2.81 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include <cstdio>
#include <cstdlib>
#define P 'P'
#define R 'R'
#define S 'S'
int method = 0;
void dictionary(int n, int index, int repeat, char repeatChar) {
if (index == n-1) {
if (repeat == 2) {
method += 2;
}
else {
method += 3;
}
return;
}
if (repeat == 3) {
return;
}
if (repeat == 2) {
switch (repeatChar) {
case P:
dictionary(n, index+1, 1, R);
dictionary(n, index+1, 1, S);
break;
case R:
dictionary(n, index+1, 1, P);
dictionary(n, index+1, 1, S);
break;
case S:
dictionary(n, index+1, 1, R);
dictionary(n, index+1, 1, P);
break;
default:
break;
}
}
else {
switch (repeatChar) {
case P:
dictionary(n, index+1, repeat+1, P);
dictionary(n, index+1, 1, R);
dictionary(n, index+1, 1, S);
break;
case R:
dictionary(n, index+1, repeat+1, R);
dictionary(n, index+1, 1, P);
dictionary(n, index+1, 1, S);
break;
case S:
dictionary(n, index+1, repeat+1, S);
dictionary(n, index+1, 1, R);
dictionary(n, index+1, 1, P);
break;
default:
break;
}
}
}
using namespace std;
int main() {
int n;
scanf("%d",&n);
char str[n+1];
int repeat[n];
scanf("%s",str);
repeat[0] = 1;
if (str[0] == S) {
dictionary(n, 1, 1, P);
dictionary(n, 1, 1, R);
}
else if (str[0] == R) {
dictionary(n, 1, 1, P);
}
for (int i = 1; i < n-1; ++i) {
if (str[i] == str[i-1]) {
repeat[i] = repeat[i-1] + 1;
}
else repeat[i] = 1;
if (str[i] == S) {
if (str[i-1] == P) dictionary(n, i+1, repeat[i-1]+1, P);
else dictionary(n, i+1, 1, P);
if (str[i-1] == R) dictionary(n, i+1, repeat[i-1]+1, R);
else dictionary(n, i+1, 1, R);
}
else if (str[i] == R) {
if (str[i-1] == P) dictionary(n, i+1, repeat[i-1]+1, P);
else dictionary(n, i+1, 1, P);
}
}
//printf("%d\n",method);
if (str[n-1] == R) {
if (!(str[n-2] == P && str[n-3] == P)) {
++method;
}
++method;
}
else if (str[n-1] == S) {
if (!(str[n-2] == R && str[n-3] == R)) {
++method;
}
if (!(str[n-2] == P && str[n-3] == P)) {
++method;
}
++method;
}
else method += 1;
printf("%d",method);
}