답안 #223103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223103 2020-04-14T18:48:52 Z ryansee Cubeword (CEOI19_cubeword) C++14
100 / 100
1095 ms 20896 KB
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(int i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (100006)
ll n,mod=998244353,dp[62][62][62];
ll e[62][62];
vector<string> A[11];
unordered_map<string,bool> mp;
ll d(char ch){
	if(ch>='a'&&ch<='z') return ch-'a';
	else if(ch>='A'&&ch<='Z') return ch-'A'+26;
	else return 52+ch-'0';
}
// 0...61
int main(){
	FAST
	cin>>n;
	FOR(i,1,n){
		string a;cin>>a;
		A[a.size()].pb(a);
		// for(auto i:a) assert((i>='a'&&i<='p')||(i>='A'&&i<='P'));
	}
	ll sum=0;
	FOR(l,3,10){
		vector<string> v;
		FOR(i,0,siz(A[l])-1){
			reverse(all(A[l][i]));
			if(mp[A[l][i]])continue;
			reverse(all(A[l][i]));
			mp[A[l][i]]=1;
			v.pb(A[l][i]);
		}
		A[l]=v;
		mmst(e,0),mmst(dp,0);
		ll ans=0;
		auto ispalin=[&](string s){
			string tmp=s;
			reverse(all(tmp));
			return tmp==s;
		};
		for(auto i:A[l]){
			++ e[d(i[0])][d(i.back())];
			++ e[d(i.back())][d(i[0])];
			if(ispalin(i)) --e[d(i[0])][d(i[0])];
		}
		FOR(i,0,61)FOR(j,0,i)FOR(k,0,j)FOR(t,0,61){
			dp[i][j][k]+=e[t][i]*e[t][j]*e[t][k]%mod,dp[i][j][k]%=mod;
		}
		FOR(i,0,61)FOR(j,0,i)FOR(k,0,j)FOR(l,0,k){
			// ll a=0,b=0,c=0,d=0;
			// FOR(t,0,61){
				// a+=e[t][i]*e[t][j]*e[t][k]%mod,a%=mod;
				// b+=e[t][i]*e[t][j]*e[t][l]%mod,b%=mod;
				// c+=e[t][i]*e[t][k]*e[t][l]%mod,c%=mod;
				// d+=e[t][j]*e[t][k]*e[t][l]%mod,d%=mod;
			// }
			auto p=[&](ll a,ll b,ll c,ll d){
				vector<pi> v;
				v.eb(1, a);
				if(b==a) ++v[0].f; else v.eb(1,b);
				if(c==a) ++ v[0].f; else if(c==b) ++ v[1].f; else v.eb(1,c);
				if(d==a) ++ v[0].f; else if(d==b) ++ v[1].f; else if(a==b&&c==d) ++ v[1].f; else if(c==d) ++ v[2].f; else v.eb(1,d);
				if(siz(v)==4) return 4*3*2;
				else if(siz(v)==3) return 4*3;
				else if(siz(v)==2&&v[0].f==2) return 6; // 2 2
				else if(siz(v)==2) return 4;
				else return 1;
			};
			ans+=dp[i][j][k]*dp[i][j][l]%mod*dp[i][k][l]%mod*dp[j][k][l]%mod*p(i,j,k,l),ans%=mod;
		}
		sum+=ans,sum%=mod;
	}
	cout<<sum<<'\n';
} //
/*
1
badab

1
aoboc

2
FLOC
COLF

3
baobab
baboab
bob

3
OFDING
LFBMIO
ACCEPO

3
MANBLA
MANCOE
ANDNAE

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 968 ms 20312 KB Output is correct
2 Correct 999 ms 20460 KB Output is correct
3 Correct 988 ms 20420 KB Output is correct
4 Correct 1008 ms 20536 KB Output is correct
5 Correct 1065 ms 20476 KB Output is correct
6 Correct 994 ms 20460 KB Output is correct
7 Correct 1018 ms 20340 KB Output is correct
8 Correct 1028 ms 20516 KB Output is correct
9 Correct 1010 ms 20396 KB Output is correct
10 Correct 1000 ms 20488 KB Output is correct
11 Correct 1040 ms 20324 KB Output is correct
12 Correct 985 ms 20488 KB Output is correct
13 Correct 993 ms 20456 KB Output is correct
14 Correct 1018 ms 20352 KB Output is correct
15 Correct 992 ms 20328 KB Output is correct
16 Correct 1014 ms 20520 KB Output is correct
17 Correct 1016 ms 20412 KB Output is correct
18 Correct 1024 ms 20416 KB Output is correct
19 Correct 1006 ms 20480 KB Output is correct
20 Correct 1048 ms 20376 KB Output is correct
21 Correct 1012 ms 20408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 968 ms 20312 KB Output is correct
2 Correct 999 ms 20460 KB Output is correct
3 Correct 988 ms 20420 KB Output is correct
4 Correct 1008 ms 20536 KB Output is correct
5 Correct 1065 ms 20476 KB Output is correct
6 Correct 994 ms 20460 KB Output is correct
7 Correct 1018 ms 20340 KB Output is correct
8 Correct 1028 ms 20516 KB Output is correct
9 Correct 1010 ms 20396 KB Output is correct
10 Correct 1000 ms 20488 KB Output is correct
11 Correct 1040 ms 20324 KB Output is correct
12 Correct 985 ms 20488 KB Output is correct
13 Correct 993 ms 20456 KB Output is correct
14 Correct 1018 ms 20352 KB Output is correct
15 Correct 992 ms 20328 KB Output is correct
16 Correct 1014 ms 20520 KB Output is correct
17 Correct 1016 ms 20412 KB Output is correct
18 Correct 1024 ms 20416 KB Output is correct
19 Correct 1006 ms 20480 KB Output is correct
20 Correct 1048 ms 20376 KB Output is correct
21 Correct 1012 ms 20408 KB Output is correct
22 Correct 1004 ms 20524 KB Output is correct
23 Correct 1041 ms 20432 KB Output is correct
24 Correct 1000 ms 20488 KB Output is correct
25 Correct 1020 ms 20496 KB Output is correct
26 Correct 1020 ms 20512 KB Output is correct
27 Correct 1025 ms 20608 KB Output is correct
28 Correct 1000 ms 20656 KB Output is correct
29 Correct 1012 ms 20460 KB Output is correct
30 Correct 985 ms 20464 KB Output is correct
31 Correct 1004 ms 20428 KB Output is correct
32 Correct 1034 ms 20372 KB Output is correct
33 Correct 1008 ms 20524 KB Output is correct
34 Correct 1004 ms 20548 KB Output is correct
35 Correct 1004 ms 20448 KB Output is correct
36 Correct 1018 ms 20480 KB Output is correct
37 Correct 1008 ms 20516 KB Output is correct
38 Correct 1002 ms 20536 KB Output is correct
39 Correct 986 ms 20468 KB Output is correct
40 Correct 1014 ms 20444 KB Output is correct
41 Correct 1018 ms 20496 KB Output is correct
42 Correct 1010 ms 20532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 968 ms 20312 KB Output is correct
2 Correct 999 ms 20460 KB Output is correct
3 Correct 988 ms 20420 KB Output is correct
4 Correct 1008 ms 20536 KB Output is correct
5 Correct 1065 ms 20476 KB Output is correct
6 Correct 994 ms 20460 KB Output is correct
7 Correct 1018 ms 20340 KB Output is correct
8 Correct 1028 ms 20516 KB Output is correct
9 Correct 1010 ms 20396 KB Output is correct
10 Correct 1000 ms 20488 KB Output is correct
11 Correct 1040 ms 20324 KB Output is correct
12 Correct 985 ms 20488 KB Output is correct
13 Correct 993 ms 20456 KB Output is correct
14 Correct 1018 ms 20352 KB Output is correct
15 Correct 992 ms 20328 KB Output is correct
16 Correct 1014 ms 20520 KB Output is correct
17 Correct 1016 ms 20412 KB Output is correct
18 Correct 1024 ms 20416 KB Output is correct
19 Correct 1006 ms 20480 KB Output is correct
20 Correct 1048 ms 20376 KB Output is correct
21 Correct 1012 ms 20408 KB Output is correct
22 Correct 1004 ms 20524 KB Output is correct
23 Correct 1041 ms 20432 KB Output is correct
24 Correct 1000 ms 20488 KB Output is correct
25 Correct 1020 ms 20496 KB Output is correct
26 Correct 1020 ms 20512 KB Output is correct
27 Correct 1025 ms 20608 KB Output is correct
28 Correct 1000 ms 20656 KB Output is correct
29 Correct 1012 ms 20460 KB Output is correct
30 Correct 985 ms 20464 KB Output is correct
31 Correct 1004 ms 20428 KB Output is correct
32 Correct 1034 ms 20372 KB Output is correct
33 Correct 1008 ms 20524 KB Output is correct
34 Correct 1004 ms 20548 KB Output is correct
35 Correct 1004 ms 20448 KB Output is correct
36 Correct 1018 ms 20480 KB Output is correct
37 Correct 1008 ms 20516 KB Output is correct
38 Correct 1002 ms 20536 KB Output is correct
39 Correct 986 ms 20468 KB Output is correct
40 Correct 1014 ms 20444 KB Output is correct
41 Correct 1018 ms 20496 KB Output is correct
42 Correct 1010 ms 20532 KB Output is correct
43 Correct 991 ms 20692 KB Output is correct
44 Correct 1014 ms 20852 KB Output is correct
45 Correct 966 ms 20632 KB Output is correct
46 Correct 1000 ms 20616 KB Output is correct
47 Correct 998 ms 20584 KB Output is correct
48 Correct 989 ms 20532 KB Output is correct
49 Correct 990 ms 20620 KB Output is correct
50 Correct 972 ms 20632 KB Output is correct
51 Correct 987 ms 20712 KB Output is correct
52 Correct 1008 ms 20892 KB Output is correct
53 Correct 982 ms 20616 KB Output is correct
54 Correct 1024 ms 20660 KB Output is correct
55 Correct 1010 ms 20824 KB Output is correct
56 Correct 1016 ms 20620 KB Output is correct
57 Correct 1016 ms 20584 KB Output is correct
58 Correct 981 ms 20596 KB Output is correct
59 Correct 1000 ms 20652 KB Output is correct
60 Correct 1022 ms 20664 KB Output is correct
61 Correct 1002 ms 20512 KB Output is correct
62 Correct 983 ms 20496 KB Output is correct
63 Correct 1004 ms 20560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 968 ms 20312 KB Output is correct
2 Correct 999 ms 20460 KB Output is correct
3 Correct 988 ms 20420 KB Output is correct
4 Correct 1008 ms 20536 KB Output is correct
5 Correct 1065 ms 20476 KB Output is correct
6 Correct 994 ms 20460 KB Output is correct
7 Correct 1018 ms 20340 KB Output is correct
8 Correct 1028 ms 20516 KB Output is correct
9 Correct 1010 ms 20396 KB Output is correct
10 Correct 1000 ms 20488 KB Output is correct
11 Correct 1040 ms 20324 KB Output is correct
12 Correct 985 ms 20488 KB Output is correct
13 Correct 993 ms 20456 KB Output is correct
14 Correct 1018 ms 20352 KB Output is correct
15 Correct 992 ms 20328 KB Output is correct
16 Correct 1014 ms 20520 KB Output is correct
17 Correct 1016 ms 20412 KB Output is correct
18 Correct 1024 ms 20416 KB Output is correct
19 Correct 1006 ms 20480 KB Output is correct
20 Correct 1048 ms 20376 KB Output is correct
21 Correct 1012 ms 20408 KB Output is correct
22 Correct 1004 ms 20524 KB Output is correct
23 Correct 1041 ms 20432 KB Output is correct
24 Correct 1000 ms 20488 KB Output is correct
25 Correct 1020 ms 20496 KB Output is correct
26 Correct 1020 ms 20512 KB Output is correct
27 Correct 1025 ms 20608 KB Output is correct
28 Correct 1000 ms 20656 KB Output is correct
29 Correct 1012 ms 20460 KB Output is correct
30 Correct 985 ms 20464 KB Output is correct
31 Correct 1004 ms 20428 KB Output is correct
32 Correct 1034 ms 20372 KB Output is correct
33 Correct 1008 ms 20524 KB Output is correct
34 Correct 1004 ms 20548 KB Output is correct
35 Correct 1004 ms 20448 KB Output is correct
36 Correct 1018 ms 20480 KB Output is correct
37 Correct 1008 ms 20516 KB Output is correct
38 Correct 1002 ms 20536 KB Output is correct
39 Correct 986 ms 20468 KB Output is correct
40 Correct 1014 ms 20444 KB Output is correct
41 Correct 1018 ms 20496 KB Output is correct
42 Correct 1010 ms 20532 KB Output is correct
43 Correct 991 ms 20692 KB Output is correct
44 Correct 1014 ms 20852 KB Output is correct
45 Correct 966 ms 20632 KB Output is correct
46 Correct 1000 ms 20616 KB Output is correct
47 Correct 998 ms 20584 KB Output is correct
48 Correct 989 ms 20532 KB Output is correct
49 Correct 990 ms 20620 KB Output is correct
50 Correct 972 ms 20632 KB Output is correct
51 Correct 987 ms 20712 KB Output is correct
52 Correct 1008 ms 20892 KB Output is correct
53 Correct 982 ms 20616 KB Output is correct
54 Correct 1024 ms 20660 KB Output is correct
55 Correct 1010 ms 20824 KB Output is correct
56 Correct 1016 ms 20620 KB Output is correct
57 Correct 1016 ms 20584 KB Output is correct
58 Correct 981 ms 20596 KB Output is correct
59 Correct 1000 ms 20652 KB Output is correct
60 Correct 1022 ms 20664 KB Output is correct
61 Correct 1002 ms 20512 KB Output is correct
62 Correct 983 ms 20496 KB Output is correct
63 Correct 1004 ms 20560 KB Output is correct
64 Correct 1026 ms 20768 KB Output is correct
65 Correct 1010 ms 20840 KB Output is correct
66 Correct 1031 ms 20764 KB Output is correct
67 Correct 1022 ms 20880 KB Output is correct
68 Correct 1008 ms 20856 KB Output is correct
69 Correct 1034 ms 20812 KB Output is correct
70 Correct 1018 ms 20848 KB Output is correct
71 Correct 1002 ms 20884 KB Output is correct
72 Correct 1022 ms 20744 KB Output is correct
73 Correct 1047 ms 20780 KB Output is correct
74 Correct 1095 ms 20820 KB Output is correct
75 Correct 1051 ms 20696 KB Output is correct
76 Correct 1054 ms 20748 KB Output is correct
77 Correct 1041 ms 20728 KB Output is correct
78 Correct 1016 ms 20664 KB Output is correct
79 Correct 1008 ms 20880 KB Output is correct
80 Correct 1000 ms 20896 KB Output is correct
81 Correct 1057 ms 20672 KB Output is correct
82 Correct 1044 ms 20788 KB Output is correct
83 Correct 1056 ms 20752 KB Output is correct
84 Correct 1048 ms 20780 KB Output is correct