Submission #207918

# Submission time Handle Problem Language Result Execution time Memory
207918 2020-03-09T12:18:54 Z E869120 Cubeword (CEOI19_cubeword) C++14
84 / 100
368 ms 12328 KB
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

const long long mod = 998244353;
const int MAX_VAL = 32;

int N; string S[1 << 18];
char c[10009];

int cnt[62][62];
long long ret[62][62][62];

int getc(char d) {
	if ('a' <= d && d <= 'z') return (d - 'a');
	if ('A' <= d && d <= 'Z') return (d - 'A') + 16;
	return (d - '0') + 52;
}

long long getcnt(int v1, int v2) {
	return cnt[v1][v2];
}

long long solve(int pos) {
	for (int i = 0; i < 62 * 62; i++) cnt[i / 62][i % 62] = 0;

	vector<string> vec;
	for (int i = 1; i <= N; i++) {
		if (S[i].size() != pos) continue;
		string T = S[i]; reverse(T.begin(), T.end());
		vec.push_back(S[i]);
		vec.push_back(T);
	}
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());

	for (string i : vec) {
		int c1 = getc(i[0]), c2 = getc(i[i.size() - 1]);
		cnt[c1][c2] += 1;
	}

	for (int i = 0; i < MAX_VAL; i++) {
		for (int j = i; j < MAX_VAL; j++) {
			for (int k = j; k < MAX_VAL; k++) {
				ret[i][j][k] = 0;
				for (int l = 0; l < MAX_VAL; l++) {
					ret[i][j][k] += getcnt(i, l) * getcnt(j, l) * getcnt(k, l);
					ret[i][j][k] %= mod;
				}
			}
		}
	}

	long long val = 0;
	for (int i = 0; i < MAX_VAL; i++) {
		for (int j = 0; j < MAX_VAL; j++) {
			for (int k = 0; k < MAX_VAL; k++) {
				for (int l = 0; l < MAX_VAL; l++) {
					int c[4] = { i, j, k, l };
					sort(c, c + 4);
					int A = c[0], B = c[1], C = c[2], D = c[3];
					val += (ret[A][B][C] * ret[A][B][D] % mod) * (ret[A][C][D] * ret[B][C][D] % mod);
					val %= mod;
				}
			}
		}
	}
	return val;
}

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 11; j++) c[j] = 0;
		scanf("%s", &c);
		for (int j = 0; j < 11; j++) { if (c[j] == 0) break; S[i] += c[j]; }
	}

	long long ans = 0;
	for (int i = 3; i <= 10; i++) {
		ans += solve(i);
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Compilation message

cubeword.cpp:6:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
cubeword.cpp: In function 'long long int solve(int)':
cubeword.cpp:32:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (S[i].size() != pos) continue;
       ~~~~~~~~~~~~^~~~~~
cubeword.cpp: In function 'int main()':
cubeword.cpp:78:17: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[10009]' [-Wformat=]
   scanf("%s", &c);
               ~~^
cubeword.cpp:78:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", &c);
   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 345 ms 12180 KB Output is correct
2 Correct 343 ms 12328 KB Output is correct
3 Correct 345 ms 12292 KB Output is correct
4 Correct 350 ms 12312 KB Output is correct
5 Correct 354 ms 12284 KB Output is correct
6 Correct 348 ms 12224 KB Output is correct
7 Correct 343 ms 12260 KB Output is correct
8 Correct 338 ms 12212 KB Output is correct
9 Correct 350 ms 12184 KB Output is correct
10 Correct 352 ms 12264 KB Output is correct
11 Correct 349 ms 12192 KB Output is correct
12 Correct 354 ms 12272 KB Output is correct
13 Correct 340 ms 12192 KB Output is correct
14 Correct 356 ms 12272 KB Output is correct
15 Correct 345 ms 12324 KB Output is correct
16 Correct 346 ms 12188 KB Output is correct
17 Correct 354 ms 12188 KB Output is correct
18 Correct 354 ms 12264 KB Output is correct
19 Correct 366 ms 12228 KB Output is correct
20 Correct 347 ms 12192 KB Output is correct
21 Correct 353 ms 12308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 345 ms 12180 KB Output is correct
2 Correct 343 ms 12328 KB Output is correct
3 Correct 345 ms 12292 KB Output is correct
4 Correct 350 ms 12312 KB Output is correct
5 Correct 354 ms 12284 KB Output is correct
6 Correct 348 ms 12224 KB Output is correct
7 Correct 343 ms 12260 KB Output is correct
8 Correct 338 ms 12212 KB Output is correct
9 Correct 350 ms 12184 KB Output is correct
10 Correct 352 ms 12264 KB Output is correct
11 Correct 349 ms 12192 KB Output is correct
12 Correct 354 ms 12272 KB Output is correct
13 Correct 340 ms 12192 KB Output is correct
14 Correct 356 ms 12272 KB Output is correct
15 Correct 345 ms 12324 KB Output is correct
16 Correct 346 ms 12188 KB Output is correct
17 Correct 354 ms 12188 KB Output is correct
18 Correct 354 ms 12264 KB Output is correct
19 Correct 366 ms 12228 KB Output is correct
20 Correct 347 ms 12192 KB Output is correct
21 Correct 353 ms 12308 KB Output is correct
22 Correct 340 ms 10860 KB Output is correct
23 Correct 368 ms 10860 KB Output is correct
24 Correct 345 ms 10844 KB Output is correct
25 Correct 367 ms 10836 KB Output is correct
26 Correct 346 ms 10864 KB Output is correct
27 Correct 352 ms 10848 KB Output is correct
28 Correct 342 ms 10844 KB Output is correct
29 Correct 353 ms 10860 KB Output is correct
30 Correct 343 ms 10840 KB Output is correct
31 Correct 338 ms 10856 KB Output is correct
32 Correct 342 ms 10844 KB Output is correct
33 Correct 346 ms 10836 KB Output is correct
34 Correct 334 ms 10896 KB Output is correct
35 Correct 344 ms 10848 KB Output is correct
36 Correct 330 ms 10860 KB Output is correct
37 Correct 341 ms 10860 KB Output is correct
38 Correct 343 ms 10996 KB Output is correct
39 Correct 348 ms 10852 KB Output is correct
40 Correct 337 ms 11016 KB Output is correct
41 Correct 334 ms 10828 KB Output is correct
42 Correct 340 ms 11012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 345 ms 12180 KB Output is correct
2 Correct 343 ms 12328 KB Output is correct
3 Correct 345 ms 12292 KB Output is correct
4 Correct 350 ms 12312 KB Output is correct
5 Correct 354 ms 12284 KB Output is correct
6 Correct 348 ms 12224 KB Output is correct
7 Correct 343 ms 12260 KB Output is correct
8 Correct 338 ms 12212 KB Output is correct
9 Correct 350 ms 12184 KB Output is correct
10 Correct 352 ms 12264 KB Output is correct
11 Correct 349 ms 12192 KB Output is correct
12 Correct 354 ms 12272 KB Output is correct
13 Correct 340 ms 12192 KB Output is correct
14 Correct 356 ms 12272 KB Output is correct
15 Correct 345 ms 12324 KB Output is correct
16 Correct 346 ms 12188 KB Output is correct
17 Correct 354 ms 12188 KB Output is correct
18 Correct 354 ms 12264 KB Output is correct
19 Correct 366 ms 12228 KB Output is correct
20 Correct 347 ms 12192 KB Output is correct
21 Correct 353 ms 12308 KB Output is correct
22 Correct 340 ms 10860 KB Output is correct
23 Correct 368 ms 10860 KB Output is correct
24 Correct 345 ms 10844 KB Output is correct
25 Correct 367 ms 10836 KB Output is correct
26 Correct 346 ms 10864 KB Output is correct
27 Correct 352 ms 10848 KB Output is correct
28 Correct 342 ms 10844 KB Output is correct
29 Correct 353 ms 10860 KB Output is correct
30 Correct 343 ms 10840 KB Output is correct
31 Correct 338 ms 10856 KB Output is correct
32 Correct 342 ms 10844 KB Output is correct
33 Correct 346 ms 10836 KB Output is correct
34 Correct 334 ms 10896 KB Output is correct
35 Correct 344 ms 10848 KB Output is correct
36 Correct 330 ms 10860 KB Output is correct
37 Correct 341 ms 10860 KB Output is correct
38 Correct 343 ms 10996 KB Output is correct
39 Correct 348 ms 10852 KB Output is correct
40 Correct 337 ms 11016 KB Output is correct
41 Correct 334 ms 10828 KB Output is correct
42 Correct 340 ms 11012 KB Output is correct
43 Correct 342 ms 10884 KB Output is correct
44 Correct 346 ms 11524 KB Output is correct
45 Correct 344 ms 11644 KB Output is correct
46 Correct 345 ms 11528 KB Output is correct
47 Correct 345 ms 11512 KB Output is correct
48 Correct 332 ms 11520 KB Output is correct
49 Correct 340 ms 11508 KB Output is correct
50 Correct 341 ms 11524 KB Output is correct
51 Correct 340 ms 11504 KB Output is correct
52 Correct 344 ms 11504 KB Output is correct
53 Correct 342 ms 11532 KB Output is correct
54 Correct 349 ms 11576 KB Output is correct
55 Correct 329 ms 11520 KB Output is correct
56 Correct 335 ms 11600 KB Output is correct
57 Correct 344 ms 11520 KB Output is correct
58 Correct 342 ms 11516 KB Output is correct
59 Correct 347 ms 11604 KB Output is correct
60 Correct 342 ms 11524 KB Output is correct
61 Correct 343 ms 11648 KB Output is correct
62 Correct 348 ms 11656 KB Output is correct
63 Correct 339 ms 11516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 345 ms 12180 KB Output is correct
2 Correct 343 ms 12328 KB Output is correct
3 Correct 345 ms 12292 KB Output is correct
4 Correct 350 ms 12312 KB Output is correct
5 Correct 354 ms 12284 KB Output is correct
6 Correct 348 ms 12224 KB Output is correct
7 Correct 343 ms 12260 KB Output is correct
8 Correct 338 ms 12212 KB Output is correct
9 Correct 350 ms 12184 KB Output is correct
10 Correct 352 ms 12264 KB Output is correct
11 Correct 349 ms 12192 KB Output is correct
12 Correct 354 ms 12272 KB Output is correct
13 Correct 340 ms 12192 KB Output is correct
14 Correct 356 ms 12272 KB Output is correct
15 Correct 345 ms 12324 KB Output is correct
16 Correct 346 ms 12188 KB Output is correct
17 Correct 354 ms 12188 KB Output is correct
18 Correct 354 ms 12264 KB Output is correct
19 Correct 366 ms 12228 KB Output is correct
20 Correct 347 ms 12192 KB Output is correct
21 Correct 353 ms 12308 KB Output is correct
22 Correct 340 ms 10860 KB Output is correct
23 Correct 368 ms 10860 KB Output is correct
24 Correct 345 ms 10844 KB Output is correct
25 Correct 367 ms 10836 KB Output is correct
26 Correct 346 ms 10864 KB Output is correct
27 Correct 352 ms 10848 KB Output is correct
28 Correct 342 ms 10844 KB Output is correct
29 Correct 353 ms 10860 KB Output is correct
30 Correct 343 ms 10840 KB Output is correct
31 Correct 338 ms 10856 KB Output is correct
32 Correct 342 ms 10844 KB Output is correct
33 Correct 346 ms 10836 KB Output is correct
34 Correct 334 ms 10896 KB Output is correct
35 Correct 344 ms 10848 KB Output is correct
36 Correct 330 ms 10860 KB Output is correct
37 Correct 341 ms 10860 KB Output is correct
38 Correct 343 ms 10996 KB Output is correct
39 Correct 348 ms 10852 KB Output is correct
40 Correct 337 ms 11016 KB Output is correct
41 Correct 334 ms 10828 KB Output is correct
42 Correct 340 ms 11012 KB Output is correct
43 Correct 342 ms 10884 KB Output is correct
44 Correct 346 ms 11524 KB Output is correct
45 Correct 344 ms 11644 KB Output is correct
46 Correct 345 ms 11528 KB Output is correct
47 Correct 345 ms 11512 KB Output is correct
48 Correct 332 ms 11520 KB Output is correct
49 Correct 340 ms 11508 KB Output is correct
50 Correct 341 ms 11524 KB Output is correct
51 Correct 340 ms 11504 KB Output is correct
52 Correct 344 ms 11504 KB Output is correct
53 Correct 342 ms 11532 KB Output is correct
54 Correct 349 ms 11576 KB Output is correct
55 Correct 329 ms 11520 KB Output is correct
56 Correct 335 ms 11600 KB Output is correct
57 Correct 344 ms 11520 KB Output is correct
58 Correct 342 ms 11516 KB Output is correct
59 Correct 347 ms 11604 KB Output is correct
60 Correct 342 ms 11524 KB Output is correct
61 Correct 343 ms 11648 KB Output is correct
62 Correct 348 ms 11656 KB Output is correct
63 Correct 339 ms 11516 KB Output is correct
64 Incorrect 361 ms 11772 KB Output isn't correct
65 Halted 0 ms 0 KB -