답안 #426102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426102 2021-06-13T14:04:14 Z hhhhaura Cubeword (CEOI19_cubeword) C++14
100 / 100
469 ms 35768 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(signed i = a; i <= b; i++)
#define rrep(i, a, b) for(signed i = b; i >= a; i--)
#define ceil(a, b) ((a + b - 1) / (b))
#define all(x) x.begin(), x.end()

#define INF 1000000000000000000
#define eps (1e-9)

using namespace std;
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
	const int P = 62, MOD = 998244353;
	signed cnt[11][70][70];
	int dp[11][70][70][70];
	set<string> st;
	void init_() { 
		st.clear();
	}
	int solve() {
		int x = 0;
		rep(len, 3, 10) rep(a, 0, P - 1) 
			rep(b, a, P - 1) rep(c, b, P - 1) {
				int cur = 0;
				rep(d, 0, P - 1) {
					cur += cnt[len][d][a] * cnt[len][d][b] % MOD
						*cnt[len][d][c] % MOD; 
				}			
				cur %= MOD; 
				dp[len][a][b][c] = dp[len][b][c][a] 
					= dp[len][c][b][a] = dp[len][a][c][b]
					= dp[len][c][a][b] = dp[len][b][a][c] = cur;
			}
		int ans = 0;
		rep(len, 3, 10) rep(a, 0, P - 1) rep(b, a + 1, P - 1) { 
			rep(c, b + 1, P - 1) rep(d, c + 1, P - 1) {
				int cur = (dp[len][a][b][d] * dp[len][a][b][c] % MOD
					* dp[len][a][c][d] % MOD * dp[len][b][c][d] % MOD);
				ans += cur * 24;
			}
			ans %= MOD;
		}
		rep(len, 3, 10) rep(a, 0, P - 1) rep(b, a + 1, P - 1) { 
			rep(c, b + 1, P - 1) rep(d, c, c) {
				int cur = (dp[len][a][b][d] * dp[len][a][b][c] % MOD
					* dp[len][a][c][d] % MOD * dp[len][b][c][d] % MOD);
				ans += cur * 12;
			}
			ans %= MOD;
		}
		rep(len, 3, 10) rep(a, 0, P - 1) rep(b, a + 1, P - 1) { 
			rep(c, b, b) rep(d, c + 1, P - 1) {
				int cur = (dp[len][a][b][d] * dp[len][a][b][c] % MOD
					* dp[len][a][c][d] % MOD * dp[len][b][c][d] % MOD);
				ans += cur * 12;
			}
			ans %= MOD;
		}
		rep(len, 3, 10) rep(a, 0, P - 1) rep(b, a + 1, P - 1) { 
			rep(c, b, b) rep(d, c, c) {
				int cur = (dp[len][a][b][d] * dp[len][a][b][c] % MOD
					* dp[len][a][c][d] % MOD * dp[len][b][c][d] % MOD);
				ans += cur * 4;
			}
			ans %= MOD;
		}
		rep(len, 3, 10) rep(a, 0, P - 1) rep(b, a, a) { 
			rep(c, b + 1,  P - 1) rep(d, c + 1, P - 1) {
				int cur = (dp[len][a][b][d] * dp[len][a][b][c] % MOD
					* dp[len][a][c][d] % MOD * dp[len][b][c][d] % MOD);
				ans += cur * 12;
			}
			ans %= MOD;
		}
		rep(len, 3, 10) rep(a, 0, P - 1) rep(b, a, a) { 
			rep(c, b + 1, P - 1) rep(d, c, c) {
				int cur = (dp[len][a][b][d] * dp[len][a][b][c] % MOD
					* dp[len][a][c][d] % MOD * dp[len][b][c][d] % MOD);
				ans += cur * 6;
			}
			ans %= MOD;
		}
		rep(len, 3, 10) rep(a, 0, P - 1) rep(b, a, a) { 
			rep(c, b, b) rep(d, c + 1, P - 1) {
				int cur = (dp[len][a][b][d] * dp[len][a][b][c] % MOD
					* dp[len][a][c][d] % MOD * dp[len][b][c][d] % MOD);
				ans += cur * 4;
			}
			ans %= MOD;
		}
		rep(len, 3, 10) rep(a, 0, P - 1) rep(b, a, a) { 
			rep(c, b, b) rep(d, c, c) {
				int cur = (dp[len][a][b][d] * dp[len][a][b][c] % MOD
					* dp[len][a][c][d] % MOD * dp[len][b][c][d] % MOD);
				ans += cur;
			}
			ans %= MOD;
		}
		
		return ans;
	}
	void add(string s) {
		int sz = s.size(), pre, suf;
		if(isdigit(s[0])) pre = 52 + s[0] - '0';
		if(islower(s[0])) pre = s[0] - 'a';
		if(isupper(s[0])) pre = s[0] - 'A' + 26; 
		
		if(isdigit(s.back())) suf = 52 + s.back() - '0';
		if(islower(s.back())) suf = s.back() - 'a';
		if(isupper(s.back())) suf = s.back() - 'A' + 26; 
		cnt[sz][pre][suf] ++;
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n; cin >> n;
	init_();
	rep(i, 1, n) {
		string s, s1; cin >> s;
		int sz = s.size();
		if(st.find(s) == st.end()) add(s);
		st.insert(s);
		s1 = s, reverse(all(s1));
		if(st.find(s1) == st.end()) add(s1);
		st.insert(s1);
	}
	cout << solve() << "\n";
	return 0;
} 

Compilation message

cubeword.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
cubeword.cpp:22:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   22 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
cubeword.cpp:22:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   22 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
cubeword.cpp: In function 'long long int solver::solve()':
cubeword.cpp:38:7: warning: unused variable 'x' [-Wunused-variable]
   38 |   int x = 0;
      |       ^
cubeword.cpp: In function 'int main()':
cubeword.cpp:138:7: warning: unused variable 'sz' [-Wunused-variable]
  138 |   int sz = s.size();
      |       ^~
cubeword.cpp: In function 'void solver::add(std::string)':
cubeword.cpp:128:19: warning: 'suf' may be used uninitialized in this function [-Wmaybe-uninitialized]
  128 |   cnt[sz][pre][suf] ++;
      |   ~~~~~~~~~~~~~~~~^
cubeword.cpp:128:19: warning: 'pre' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 356 ms 33548 KB Output is correct
2 Correct 358 ms 33836 KB Output is correct
3 Correct 371 ms 33848 KB Output is correct
4 Correct 389 ms 33868 KB Output is correct
5 Correct 469 ms 33988 KB Output is correct
6 Correct 380 ms 33800 KB Output is correct
7 Correct 403 ms 33988 KB Output is correct
8 Correct 376 ms 33872 KB Output is correct
9 Correct 358 ms 33840 KB Output is correct
10 Correct 357 ms 33880 KB Output is correct
11 Correct 388 ms 33880 KB Output is correct
12 Correct 366 ms 33888 KB Output is correct
13 Correct 362 ms 33916 KB Output is correct
14 Correct 365 ms 33856 KB Output is correct
15 Correct 386 ms 33820 KB Output is correct
16 Correct 370 ms 33944 KB Output is correct
17 Correct 364 ms 33824 KB Output is correct
18 Correct 364 ms 33948 KB Output is correct
19 Correct 430 ms 33860 KB Output is correct
20 Correct 373 ms 33972 KB Output is correct
21 Correct 408 ms 33824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 356 ms 33548 KB Output is correct
2 Correct 358 ms 33836 KB Output is correct
3 Correct 371 ms 33848 KB Output is correct
4 Correct 389 ms 33868 KB Output is correct
5 Correct 469 ms 33988 KB Output is correct
6 Correct 380 ms 33800 KB Output is correct
7 Correct 403 ms 33988 KB Output is correct
8 Correct 376 ms 33872 KB Output is correct
9 Correct 358 ms 33840 KB Output is correct
10 Correct 357 ms 33880 KB Output is correct
11 Correct 388 ms 33880 KB Output is correct
12 Correct 366 ms 33888 KB Output is correct
13 Correct 362 ms 33916 KB Output is correct
14 Correct 365 ms 33856 KB Output is correct
15 Correct 386 ms 33820 KB Output is correct
16 Correct 370 ms 33944 KB Output is correct
17 Correct 364 ms 33824 KB Output is correct
18 Correct 364 ms 33948 KB Output is correct
19 Correct 430 ms 33860 KB Output is correct
20 Correct 373 ms 33972 KB Output is correct
21 Correct 408 ms 33824 KB Output is correct
22 Correct 389 ms 34608 KB Output is correct
23 Correct 390 ms 34580 KB Output is correct
24 Correct 370 ms 34664 KB Output is correct
25 Correct 360 ms 34500 KB Output is correct
26 Correct 381 ms 34488 KB Output is correct
27 Correct 342 ms 34472 KB Output is correct
28 Correct 373 ms 34580 KB Output is correct
29 Correct 357 ms 34496 KB Output is correct
30 Correct 419 ms 34652 KB Output is correct
31 Correct 340 ms 34500 KB Output is correct
32 Correct 350 ms 34668 KB Output is correct
33 Correct 416 ms 34756 KB Output is correct
34 Correct 377 ms 34696 KB Output is correct
35 Correct 355 ms 34600 KB Output is correct
36 Correct 379 ms 34572 KB Output is correct
37 Correct 379 ms 34592 KB Output is correct
38 Correct 377 ms 34648 KB Output is correct
39 Correct 344 ms 34628 KB Output is correct
40 Correct 448 ms 34620 KB Output is correct
41 Correct 360 ms 34596 KB Output is correct
42 Correct 418 ms 34504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 356 ms 33548 KB Output is correct
2 Correct 358 ms 33836 KB Output is correct
3 Correct 371 ms 33848 KB Output is correct
4 Correct 389 ms 33868 KB Output is correct
5 Correct 469 ms 33988 KB Output is correct
6 Correct 380 ms 33800 KB Output is correct
7 Correct 403 ms 33988 KB Output is correct
8 Correct 376 ms 33872 KB Output is correct
9 Correct 358 ms 33840 KB Output is correct
10 Correct 357 ms 33880 KB Output is correct
11 Correct 388 ms 33880 KB Output is correct
12 Correct 366 ms 33888 KB Output is correct
13 Correct 362 ms 33916 KB Output is correct
14 Correct 365 ms 33856 KB Output is correct
15 Correct 386 ms 33820 KB Output is correct
16 Correct 370 ms 33944 KB Output is correct
17 Correct 364 ms 33824 KB Output is correct
18 Correct 364 ms 33948 KB Output is correct
19 Correct 430 ms 33860 KB Output is correct
20 Correct 373 ms 33972 KB Output is correct
21 Correct 408 ms 33824 KB Output is correct
22 Correct 389 ms 34608 KB Output is correct
23 Correct 390 ms 34580 KB Output is correct
24 Correct 370 ms 34664 KB Output is correct
25 Correct 360 ms 34500 KB Output is correct
26 Correct 381 ms 34488 KB Output is correct
27 Correct 342 ms 34472 KB Output is correct
28 Correct 373 ms 34580 KB Output is correct
29 Correct 357 ms 34496 KB Output is correct
30 Correct 419 ms 34652 KB Output is correct
31 Correct 340 ms 34500 KB Output is correct
32 Correct 350 ms 34668 KB Output is correct
33 Correct 416 ms 34756 KB Output is correct
34 Correct 377 ms 34696 KB Output is correct
35 Correct 355 ms 34600 KB Output is correct
36 Correct 379 ms 34572 KB Output is correct
37 Correct 379 ms 34592 KB Output is correct
38 Correct 377 ms 34648 KB Output is correct
39 Correct 344 ms 34628 KB Output is correct
40 Correct 448 ms 34620 KB Output is correct
41 Correct 360 ms 34596 KB Output is correct
42 Correct 418 ms 34504 KB Output is correct
43 Correct 345 ms 34864 KB Output is correct
44 Correct 415 ms 35392 KB Output is correct
45 Correct 338 ms 35268 KB Output is correct
46 Correct 345 ms 35348 KB Output is correct
47 Correct 357 ms 35308 KB Output is correct
48 Correct 359 ms 35268 KB Output is correct
49 Correct 349 ms 35236 KB Output is correct
50 Correct 375 ms 35436 KB Output is correct
51 Correct 341 ms 35308 KB Output is correct
52 Correct 378 ms 35220 KB Output is correct
53 Correct 369 ms 35344 KB Output is correct
54 Correct 343 ms 35268 KB Output is correct
55 Correct 359 ms 35396 KB Output is correct
56 Correct 351 ms 35344 KB Output is correct
57 Correct 342 ms 35300 KB Output is correct
58 Correct 377 ms 35284 KB Output is correct
59 Correct 425 ms 35400 KB Output is correct
60 Correct 339 ms 35272 KB Output is correct
61 Correct 356 ms 35468 KB Output is correct
62 Correct 355 ms 35228 KB Output is correct
63 Correct 379 ms 35500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 356 ms 33548 KB Output is correct
2 Correct 358 ms 33836 KB Output is correct
3 Correct 371 ms 33848 KB Output is correct
4 Correct 389 ms 33868 KB Output is correct
5 Correct 469 ms 33988 KB Output is correct
6 Correct 380 ms 33800 KB Output is correct
7 Correct 403 ms 33988 KB Output is correct
8 Correct 376 ms 33872 KB Output is correct
9 Correct 358 ms 33840 KB Output is correct
10 Correct 357 ms 33880 KB Output is correct
11 Correct 388 ms 33880 KB Output is correct
12 Correct 366 ms 33888 KB Output is correct
13 Correct 362 ms 33916 KB Output is correct
14 Correct 365 ms 33856 KB Output is correct
15 Correct 386 ms 33820 KB Output is correct
16 Correct 370 ms 33944 KB Output is correct
17 Correct 364 ms 33824 KB Output is correct
18 Correct 364 ms 33948 KB Output is correct
19 Correct 430 ms 33860 KB Output is correct
20 Correct 373 ms 33972 KB Output is correct
21 Correct 408 ms 33824 KB Output is correct
22 Correct 389 ms 34608 KB Output is correct
23 Correct 390 ms 34580 KB Output is correct
24 Correct 370 ms 34664 KB Output is correct
25 Correct 360 ms 34500 KB Output is correct
26 Correct 381 ms 34488 KB Output is correct
27 Correct 342 ms 34472 KB Output is correct
28 Correct 373 ms 34580 KB Output is correct
29 Correct 357 ms 34496 KB Output is correct
30 Correct 419 ms 34652 KB Output is correct
31 Correct 340 ms 34500 KB Output is correct
32 Correct 350 ms 34668 KB Output is correct
33 Correct 416 ms 34756 KB Output is correct
34 Correct 377 ms 34696 KB Output is correct
35 Correct 355 ms 34600 KB Output is correct
36 Correct 379 ms 34572 KB Output is correct
37 Correct 379 ms 34592 KB Output is correct
38 Correct 377 ms 34648 KB Output is correct
39 Correct 344 ms 34628 KB Output is correct
40 Correct 448 ms 34620 KB Output is correct
41 Correct 360 ms 34596 KB Output is correct
42 Correct 418 ms 34504 KB Output is correct
43 Correct 345 ms 34864 KB Output is correct
44 Correct 415 ms 35392 KB Output is correct
45 Correct 338 ms 35268 KB Output is correct
46 Correct 345 ms 35348 KB Output is correct
47 Correct 357 ms 35308 KB Output is correct
48 Correct 359 ms 35268 KB Output is correct
49 Correct 349 ms 35236 KB Output is correct
50 Correct 375 ms 35436 KB Output is correct
51 Correct 341 ms 35308 KB Output is correct
52 Correct 378 ms 35220 KB Output is correct
53 Correct 369 ms 35344 KB Output is correct
54 Correct 343 ms 35268 KB Output is correct
55 Correct 359 ms 35396 KB Output is correct
56 Correct 351 ms 35344 KB Output is correct
57 Correct 342 ms 35300 KB Output is correct
58 Correct 377 ms 35284 KB Output is correct
59 Correct 425 ms 35400 KB Output is correct
60 Correct 339 ms 35272 KB Output is correct
61 Correct 356 ms 35468 KB Output is correct
62 Correct 355 ms 35228 KB Output is correct
63 Correct 379 ms 35500 KB Output is correct
64 Correct 352 ms 35544 KB Output is correct
65 Correct 360 ms 35652 KB Output is correct
66 Correct 373 ms 35568 KB Output is correct
67 Correct 404 ms 35596 KB Output is correct
68 Correct 354 ms 35492 KB Output is correct
69 Correct 368 ms 35736 KB Output is correct
70 Correct 378 ms 35556 KB Output is correct
71 Correct 409 ms 35596 KB Output is correct
72 Correct 366 ms 35592 KB Output is correct
73 Correct 351 ms 35700 KB Output is correct
74 Correct 389 ms 35596 KB Output is correct
75 Correct 397 ms 35596 KB Output is correct
76 Correct 368 ms 35564 KB Output is correct
77 Correct 376 ms 35596 KB Output is correct
78 Correct 380 ms 35600 KB Output is correct
79 Correct 353 ms 35600 KB Output is correct
80 Correct 412 ms 35600 KB Output is correct
81 Correct 376 ms 35540 KB Output is correct
82 Correct 349 ms 35500 KB Output is correct
83 Correct 354 ms 35768 KB Output is correct
84 Correct 360 ms 35624 KB Output is correct