Submission #211818

# Submission time Handle Problem Language Result Execution time Memory
211818 2020-03-21T12:38:43 Z spdskatr Cubeword (CEOI19_cubeword) C++14
100 / 100
443 ms 23676 KB
    #include <cstdio>
    #include <cstdlib>
    #include <algorithm>
    #include <string>
    #include <cstring>
    #include <iostream>
    #include <vector>
    #include <set>
    #define M 998244353
    using namespace std;
    typedef long long ll;
     
    int N, gr[100005][10], npal[100005];
    ll dp[64][64][64], tot[64][64][64], cnt[64][64], ans;
    string s;
    set<string> ss;
    vector<int> tal[11];
     
    int conv(char c) {
    	if ('a' <= c && c <= 'z') return c - 'a';
    	if ('A' <= c && c <= 'Z') return (c - 'A') + 26;
    	return (c - '0') + 52;
    }
     
    ll pm(ll x, ll y) {
    	return (x * y) % M;
    }
     
    int main() {
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
    	cin >> N;
    	for (int i = 0; i < N; i++) {
    		cin >> s;
    		for (int j = 0; j < s.size(); j++) {
    			gr[i][j] = conv(s[j]);
    		}
    		for (int j = 0; j <= s.size() / 2; j++) {
    			if (s[j] != s[s.size() - 1 - j]) npal[i] = 1;
    		}
    		if (ss.find(s) == ss.end()) {
    			ss.emplace(s);
    			reverse(s.begin(), s.end());
    			ss.emplace(s);
    			tal[s.size()].push_back(i);
    		}
    	}
    	for (int n = 3; n <= 10; n++) {
    		memset(dp, 0, sizeof(dp));
    		memset(cnt, 0, sizeof(cnt));
    		for (int i : tal[n]) {
    			if (npal[i]) {
    				cnt[gr[i][0]][gr[i][n-1]]++;
    				cnt[gr[i][n-1]][gr[i][0]]++;
    			} else {
    				cnt[gr[i][0]][gr[i][n-1]]++;
    			}
    		}
    		for (int a = 0; a < 62; a++) for (int b = a; b < 62; b++) for (int c = b; c < 62; c++) for (int x = 0; x < 62; x++) {
    			dp[a][b][c] = (dp[a][b][c] + pm(cnt[x][a], pm(cnt[x][b], cnt[x][c]))) % M;
    		}
    		for (int a = 0; a < 62; a++) for (int b = a; b < 62; b++) for (int c = b; c < 62; c++) for (int d = c; d < 62; d++) {
    			int fac = 24;
    			if (a == b) {
    				if (b == c) {
    					if (c == d) fac = 1;
    					else fac = 4;
    				} else {
    					if (c == d) fac = 6;
    					else fac = 12;
    				}
    			} else {
    				if (b == c) {
    					if (c == d) fac = 4;
    					else fac = 12;
    				} else {
    					if (c == d) fac = 12;
    					else fac = 24;
    				}
    			}
    			ll pans = ans;
    			ans = (ans + pm(fac, pm(pm(dp[a][b][d], dp[a][b][c]), pm(dp[a][c][d], dp[b][c][d]))))%M;
    		}
    	}
    	cout << ans;
    	return 0;
    }

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:35:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int j = 0; j < s.size(); j++) {
                       ~~^~~~~~~~~~
cubeword.cpp:38:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int j = 0; j <= s.size() / 2; j++) {
                       ~~^~~~~~~~~~~~~~~
cubeword.cpp:81:11: warning: unused variable 'pans' [-Wunused-variable]
        ll pans = ans;
           ^~~~
# Verdict Execution time Memory Grader output
1 Correct 398 ms 22520 KB Output is correct
2 Correct 405 ms 22624 KB Output is correct
3 Correct 403 ms 22520 KB Output is correct
4 Correct 410 ms 22648 KB Output is correct
5 Correct 399 ms 22520 KB Output is correct
6 Correct 395 ms 22524 KB Output is correct
7 Correct 397 ms 22648 KB Output is correct
8 Correct 406 ms 22520 KB Output is correct
9 Correct 394 ms 22392 KB Output is correct
10 Correct 400 ms 22520 KB Output is correct
11 Correct 408 ms 22648 KB Output is correct
12 Correct 404 ms 22392 KB Output is correct
13 Correct 443 ms 22648 KB Output is correct
14 Correct 400 ms 22392 KB Output is correct
15 Correct 411 ms 22732 KB Output is correct
16 Correct 395 ms 22520 KB Output is correct
17 Correct 409 ms 22648 KB Output is correct
18 Correct 421 ms 22520 KB Output is correct
19 Correct 407 ms 22648 KB Output is correct
20 Correct 391 ms 22520 KB Output is correct
21 Correct 412 ms 22520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 398 ms 22520 KB Output is correct
2 Correct 405 ms 22624 KB Output is correct
3 Correct 403 ms 22520 KB Output is correct
4 Correct 410 ms 22648 KB Output is correct
5 Correct 399 ms 22520 KB Output is correct
6 Correct 395 ms 22524 KB Output is correct
7 Correct 397 ms 22648 KB Output is correct
8 Correct 406 ms 22520 KB Output is correct
9 Correct 394 ms 22392 KB Output is correct
10 Correct 400 ms 22520 KB Output is correct
11 Correct 408 ms 22648 KB Output is correct
12 Correct 404 ms 22392 KB Output is correct
13 Correct 443 ms 22648 KB Output is correct
14 Correct 400 ms 22392 KB Output is correct
15 Correct 411 ms 22732 KB Output is correct
16 Correct 395 ms 22520 KB Output is correct
17 Correct 409 ms 22648 KB Output is correct
18 Correct 421 ms 22520 KB Output is correct
19 Correct 407 ms 22648 KB Output is correct
20 Correct 391 ms 22520 KB Output is correct
21 Correct 412 ms 22520 KB Output is correct
22 Correct 397 ms 23128 KB Output is correct
23 Correct 414 ms 23320 KB Output is correct
24 Correct 397 ms 23160 KB Output is correct
25 Correct 410 ms 23160 KB Output is correct
26 Correct 395 ms 23032 KB Output is correct
27 Correct 405 ms 23056 KB Output is correct
28 Correct 396 ms 23032 KB Output is correct
29 Correct 400 ms 23032 KB Output is correct
30 Correct 414 ms 23164 KB Output is correct
31 Correct 398 ms 23136 KB Output is correct
32 Correct 415 ms 23160 KB Output is correct
33 Correct 412 ms 23044 KB Output is correct
34 Correct 411 ms 23260 KB Output is correct
35 Correct 397 ms 23032 KB Output is correct
36 Correct 413 ms 23288 KB Output is correct
37 Correct 402 ms 23032 KB Output is correct
38 Correct 420 ms 23416 KB Output is correct
39 Correct 408 ms 23032 KB Output is correct
40 Correct 408 ms 23260 KB Output is correct
41 Correct 401 ms 23032 KB Output is correct
42 Correct 404 ms 23288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 398 ms 22520 KB Output is correct
2 Correct 405 ms 22624 KB Output is correct
3 Correct 403 ms 22520 KB Output is correct
4 Correct 410 ms 22648 KB Output is correct
5 Correct 399 ms 22520 KB Output is correct
6 Correct 395 ms 22524 KB Output is correct
7 Correct 397 ms 22648 KB Output is correct
8 Correct 406 ms 22520 KB Output is correct
9 Correct 394 ms 22392 KB Output is correct
10 Correct 400 ms 22520 KB Output is correct
11 Correct 408 ms 22648 KB Output is correct
12 Correct 404 ms 22392 KB Output is correct
13 Correct 443 ms 22648 KB Output is correct
14 Correct 400 ms 22392 KB Output is correct
15 Correct 411 ms 22732 KB Output is correct
16 Correct 395 ms 22520 KB Output is correct
17 Correct 409 ms 22648 KB Output is correct
18 Correct 421 ms 22520 KB Output is correct
19 Correct 407 ms 22648 KB Output is correct
20 Correct 391 ms 22520 KB Output is correct
21 Correct 412 ms 22520 KB Output is correct
22 Correct 397 ms 23128 KB Output is correct
23 Correct 414 ms 23320 KB Output is correct
24 Correct 397 ms 23160 KB Output is correct
25 Correct 410 ms 23160 KB Output is correct
26 Correct 395 ms 23032 KB Output is correct
27 Correct 405 ms 23056 KB Output is correct
28 Correct 396 ms 23032 KB Output is correct
29 Correct 400 ms 23032 KB Output is correct
30 Correct 414 ms 23164 KB Output is correct
31 Correct 398 ms 23136 KB Output is correct
32 Correct 415 ms 23160 KB Output is correct
33 Correct 412 ms 23044 KB Output is correct
34 Correct 411 ms 23260 KB Output is correct
35 Correct 397 ms 23032 KB Output is correct
36 Correct 413 ms 23288 KB Output is correct
37 Correct 402 ms 23032 KB Output is correct
38 Correct 420 ms 23416 KB Output is correct
39 Correct 408 ms 23032 KB Output is correct
40 Correct 408 ms 23260 KB Output is correct
41 Correct 401 ms 23032 KB Output is correct
42 Correct 404 ms 23288 KB Output is correct
43 Correct 410 ms 23288 KB Output is correct
44 Correct 402 ms 23288 KB Output is correct
45 Correct 417 ms 23288 KB Output is correct
46 Correct 400 ms 23288 KB Output is correct
47 Correct 417 ms 23300 KB Output is correct
48 Correct 395 ms 23288 KB Output is correct
49 Correct 417 ms 23416 KB Output is correct
50 Correct 395 ms 23288 KB Output is correct
51 Correct 411 ms 23368 KB Output is correct
52 Correct 400 ms 23288 KB Output is correct
53 Correct 416 ms 23372 KB Output is correct
54 Correct 401 ms 23288 KB Output is correct
55 Correct 434 ms 23476 KB Output is correct
56 Correct 401 ms 23288 KB Output is correct
57 Correct 424 ms 23344 KB Output is correct
58 Correct 399 ms 23288 KB Output is correct
59 Correct 418 ms 23272 KB Output is correct
60 Correct 403 ms 23288 KB Output is correct
61 Correct 413 ms 23304 KB Output is correct
62 Correct 398 ms 23288 KB Output is correct
63 Correct 396 ms 23288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 398 ms 22520 KB Output is correct
2 Correct 405 ms 22624 KB Output is correct
3 Correct 403 ms 22520 KB Output is correct
4 Correct 410 ms 22648 KB Output is correct
5 Correct 399 ms 22520 KB Output is correct
6 Correct 395 ms 22524 KB Output is correct
7 Correct 397 ms 22648 KB Output is correct
8 Correct 406 ms 22520 KB Output is correct
9 Correct 394 ms 22392 KB Output is correct
10 Correct 400 ms 22520 KB Output is correct
11 Correct 408 ms 22648 KB Output is correct
12 Correct 404 ms 22392 KB Output is correct
13 Correct 443 ms 22648 KB Output is correct
14 Correct 400 ms 22392 KB Output is correct
15 Correct 411 ms 22732 KB Output is correct
16 Correct 395 ms 22520 KB Output is correct
17 Correct 409 ms 22648 KB Output is correct
18 Correct 421 ms 22520 KB Output is correct
19 Correct 407 ms 22648 KB Output is correct
20 Correct 391 ms 22520 KB Output is correct
21 Correct 412 ms 22520 KB Output is correct
22 Correct 397 ms 23128 KB Output is correct
23 Correct 414 ms 23320 KB Output is correct
24 Correct 397 ms 23160 KB Output is correct
25 Correct 410 ms 23160 KB Output is correct
26 Correct 395 ms 23032 KB Output is correct
27 Correct 405 ms 23056 KB Output is correct
28 Correct 396 ms 23032 KB Output is correct
29 Correct 400 ms 23032 KB Output is correct
30 Correct 414 ms 23164 KB Output is correct
31 Correct 398 ms 23136 KB Output is correct
32 Correct 415 ms 23160 KB Output is correct
33 Correct 412 ms 23044 KB Output is correct
34 Correct 411 ms 23260 KB Output is correct
35 Correct 397 ms 23032 KB Output is correct
36 Correct 413 ms 23288 KB Output is correct
37 Correct 402 ms 23032 KB Output is correct
38 Correct 420 ms 23416 KB Output is correct
39 Correct 408 ms 23032 KB Output is correct
40 Correct 408 ms 23260 KB Output is correct
41 Correct 401 ms 23032 KB Output is correct
42 Correct 404 ms 23288 KB Output is correct
43 Correct 410 ms 23288 KB Output is correct
44 Correct 402 ms 23288 KB Output is correct
45 Correct 417 ms 23288 KB Output is correct
46 Correct 400 ms 23288 KB Output is correct
47 Correct 417 ms 23300 KB Output is correct
48 Correct 395 ms 23288 KB Output is correct
49 Correct 417 ms 23416 KB Output is correct
50 Correct 395 ms 23288 KB Output is correct
51 Correct 411 ms 23368 KB Output is correct
52 Correct 400 ms 23288 KB Output is correct
53 Correct 416 ms 23372 KB Output is correct
54 Correct 401 ms 23288 KB Output is correct
55 Correct 434 ms 23476 KB Output is correct
56 Correct 401 ms 23288 KB Output is correct
57 Correct 424 ms 23344 KB Output is correct
58 Correct 399 ms 23288 KB Output is correct
59 Correct 418 ms 23272 KB Output is correct
60 Correct 403 ms 23288 KB Output is correct
61 Correct 413 ms 23304 KB Output is correct
62 Correct 398 ms 23288 KB Output is correct
63 Correct 396 ms 23288 KB Output is correct
64 Correct 408 ms 23544 KB Output is correct
65 Correct 402 ms 23544 KB Output is correct
66 Correct 404 ms 23672 KB Output is correct
67 Correct 408 ms 23544 KB Output is correct
68 Correct 414 ms 23672 KB Output is correct
69 Correct 413 ms 23544 KB Output is correct
70 Correct 423 ms 23544 KB Output is correct
71 Correct 408 ms 23544 KB Output is correct
72 Correct 416 ms 23544 KB Output is correct
73 Correct 401 ms 23544 KB Output is correct
74 Correct 412 ms 23544 KB Output is correct
75 Correct 430 ms 23416 KB Output is correct
76 Correct 411 ms 23676 KB Output is correct
77 Correct 396 ms 23548 KB Output is correct
78 Correct 423 ms 23544 KB Output is correct
79 Correct 403 ms 23544 KB Output is correct
80 Correct 411 ms 23544 KB Output is correct
81 Correct 416 ms 23544 KB Output is correct
82 Correct 410 ms 23672 KB Output is correct
83 Correct 408 ms 23520 KB Output is correct
84 Correct 399 ms 23548 KB Output is correct