Submission #6429604


Source Code Expand

//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 998244353;
const int INF = 1e9 + 7;
const int MAXN = 2e5 + 5;
const double eps = 1e-9;
char str[MAXN];
int dp[MAXN][3][3]; // ind, sm, last, two cons

void add(int& a, int b) {
	a = (a+b) % MOD;
}

int main() {
	scanf("%s", str);
	int n = strlen(str);
	if (n == 2) return !pri(str[0] == str[1] ? 1 : 2);
	if (n == 3) {
		if (str[0] == str[1] && str[1] == str[2])
			return !pri(1);
		if (str[0] != str[1] && str[1] != str[2]) {
			if (str[0] == str[2])
				return pri(8);
			return pri(3);
		}
		return pri(7);
	}
	bool fl = 1, fl2 = 1;
	int sm = 0;
	ll p2 = 1;
	for (int i = 0; i < n; i++) {
		fl &= str[i] == str[0];
		sm = (sm+str[i]-'a')%3;
		if (i) {
			fl2 &= (str[i] != str[i-1]);
			p2 = (p2 * 3ll) % MOD;
		}
	}
	if (fl) return !pri(1);
	for (int i = 0; i < 3; i++)
		dp[1][i][i] = 1;
	for (int i = 1; i < n; i++)
		for (int nx = 0; nx < 3; nx++)
			for (int j = 0; j < 3; j++) // sm
				for (int k = 0; k < 3; k++) // last
					if (k != nx)
						add(dp[i+1][(j+nx)%3][nx], dp[i][j][k]);

	int ans = (dp[n][sm][0]+dp[n][sm][1]) % MOD;
	ans = (ans + dp[n][sm][2]) % MOD;
	ans = (p2 - ans + MOD) % MOD;
	if (fl2) ans = (ans+1) % MOD;
	pri(ans);
    return 0;
}

Submission Info

Submission Time
Task F - Normalization
User eshoru
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2321 Byte
Status RE
Exec Time 19 ms
Memory 7424 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:45:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", str);
                  ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
RE × 1
AC × 53
RE × 25
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt, 55.txt, 56.txt, 57.txt, 58.txt, 59.txt, 60.txt, 61.txt, 62.txt, 63.txt, 64.txt, 65.txt, 66.txt, 67.txt, 68.txt, 69.txt, 70.txt, 71.txt, 72.txt, 73.txt, 74.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 1 ms 256 KB
02.txt RE 1 ms 256 KB
03.txt RE 1 ms 256 KB
04.txt RE 1 ms 256 KB
05.txt RE 1 ms 256 KB
06.txt RE 1 ms 256 KB
07.txt RE 1 ms 256 KB
08.txt RE 1 ms 256 KB
09.txt RE 1 ms 256 KB
10.txt RE 1 ms 256 KB
11.txt RE 1 ms 256 KB
12.txt RE 1 ms 256 KB
13.txt RE 1 ms 256 KB
14.txt AC 1 ms 256 KB
15.txt RE 1 ms 256 KB
16.txt RE 1 ms 256 KB
17.txt RE 1 ms 256 KB
18.txt RE 1 ms 256 KB
19.txt RE 1 ms 256 KB
20.txt RE 1 ms 256 KB
21.txt RE 1 ms 256 KB
22.txt RE 1 ms 256 KB
23.txt RE 1 ms 256 KB
24.txt RE 1 ms 256 KB
25.txt RE 1 ms 256 KB
26.txt RE 1 ms 256 KB
27.txt AC 1 ms 256 KB
28.txt AC 1 ms 256 KB
29.txt AC 1 ms 256 KB
30.txt AC 1 ms 256 KB
31.txt AC 1 ms 256 KB
32.txt AC 1 ms 256 KB
33.txt AC 1 ms 256 KB
34.txt AC 1 ms 256 KB
35.txt AC 1 ms 256 KB
36.txt AC 1 ms 256 KB
37.txt AC 16 ms 6656 KB
38.txt AC 3 ms 896 KB
39.txt AC 2 ms 640 KB
40.txt AC 9 ms 4352 KB
41.txt AC 19 ms 7424 KB
42.txt AC 17 ms 6656 KB
43.txt AC 13 ms 6528 KB
44.txt AC 19 ms 7296 KB
45.txt AC 11 ms 4480 KB
46.txt AC 17 ms 6656 KB
47.txt AC 16 ms 6528 KB
48.txt AC 10 ms 4480 KB
49.txt AC 10 ms 4480 KB
50.txt AC 8 ms 4352 KB
51.txt AC 11 ms 4480 KB
52.txt AC 3 ms 1024 KB
53.txt AC 14 ms 6528 KB
54.txt AC 6 ms 1792 KB
55.txt AC 13 ms 6528 KB
56.txt AC 13 ms 6528 KB
57.txt AC 3 ms 768 KB
58.txt AC 17 ms 6528 KB
59.txt AC 2 ms 384 KB
60.txt AC 14 ms 6528 KB
61.txt AC 2 ms 256 KB
62.txt AC 2 ms 256 KB
63.txt AC 3 ms 384 KB
64.txt AC 3 ms 384 KB
65.txt AC 2 ms 384 KB
66.txt AC 2 ms 384 KB
67.txt AC 19 ms 7424 KB
68.txt AC 19 ms 7424 KB
69.txt AC 19 ms 7424 KB
70.txt AC 19 ms 7424 KB
71.txt AC 19 ms 7424 KB
72.txt AC 19 ms 7424 KB
73.txt AC 19 ms 7424 KB
74.txt AC 19 ms 7424 KB
s1.txt RE 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB
s4.txt AC 1 ms 256 KB