Submission #425575

# Submission time Handle Problem Language Result Execution time Memory
425575 2021-06-13T07:45:41 Z hhhhaura Cubeword (CEOI19_cubeword) C++14
21 / 100
1094 ms 15652 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int 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 = 6, MOD = 998244353;
	int ans = 0;
	vector<vector<signed>> cnt[11];
	vector<signed> cur;
	set<string> st;
	vector<pii> edge = {
		{0, 1}, {0, 4}, {0, 2},
		{1, 5}, {1, 3}, {2, 3},
		{2, 6}, {3, 7}, {5, 7},
		{5, 4}, {6, 7}, {4, 6}
	};
	void init_() {
		rep(i, 0, 10) 
			cnt[i].assign(P, vector<signed>(P, 0));
		cur.assign(8, 0);
		ans = 0, st.clear();
	}
	int count() {
		int a = 0, c;
		rep(i, 3, 10) {
			c = 1;
			for(auto j : edge) {
				c = c * cnt[i][cur[j.first]][cur[j.second]] % MOD;
				if(!c) break;
			}
			a = (a + c);
			if(a >= MOD) a -= MOD;
		}
		return a;
	}
	void solve() {
		for(cur[0] = 0; cur[0] < P; cur[0] ++)
		for(cur[1] = 0; cur[1] < P; cur[1] ++)
		for(cur[2] = 0; cur[2] < P; cur[2] ++)
		for(cur[3] = 0; cur[3] < P; cur[3] ++)
		for(cur[4] = 0; cur[4] < P; cur[4] ++)
		for(cur[5] = 0; cur[5] < P; cur[5] ++)
		for(cur[6] = 0; cur[6] < P; cur[6] ++)
		for(cur[7] = 0; cur[7] < P; cur[7] ++) {
			ans = (ans + count());
			if(ans >= MOD) ans -= MOD;
		}
	}
};
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()) 
			cnt[sz][s[0] - 'a'][s.back() - 'a'] ++;
		st.insert(s);
		s1 = s, reverse(all(s1));
		if(st.find(s1) == st.end()) 
			cnt[sz][s1[0] - 'a'][s1.back() - 'a'] ++;
		st.insert(s1);
	}
	solve();
	cout << ans << "\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;}
      |                     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1022 ms 14792 KB Output is correct
2 Correct 1016 ms 14772 KB Output is correct
3 Correct 1014 ms 14780 KB Output is correct
4 Correct 1094 ms 14664 KB Output is correct
5 Correct 999 ms 14864 KB Output is correct
6 Correct 1000 ms 14780 KB Output is correct
7 Correct 1008 ms 14824 KB Output is correct
8 Correct 1016 ms 14788 KB Output is correct
9 Correct 1008 ms 15632 KB Output is correct
10 Correct 990 ms 15648 KB Output is correct
11 Correct 992 ms 15644 KB Output is correct
12 Correct 972 ms 15632 KB Output is correct
13 Correct 988 ms 15652 KB Output is correct
14 Correct 996 ms 15652 KB Output is correct
15 Correct 1010 ms 15652 KB Output is correct
16 Correct 1026 ms 15636 KB Output is correct
17 Correct 975 ms 15648 KB Output is correct
18 Correct 1008 ms 15636 KB Output is correct
19 Correct 1004 ms 15640 KB Output is correct
20 Correct 975 ms 15644 KB Output is correct
21 Correct 978 ms 15636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1022 ms 14792 KB Output is correct
2 Correct 1016 ms 14772 KB Output is correct
3 Correct 1014 ms 14780 KB Output is correct
4 Correct 1094 ms 14664 KB Output is correct
5 Correct 999 ms 14864 KB Output is correct
6 Correct 1000 ms 14780 KB Output is correct
7 Correct 1008 ms 14824 KB Output is correct
8 Correct 1016 ms 14788 KB Output is correct
9 Correct 1008 ms 15632 KB Output is correct
10 Correct 990 ms 15648 KB Output is correct
11 Correct 992 ms 15644 KB Output is correct
12 Correct 972 ms 15632 KB Output is correct
13 Correct 988 ms 15652 KB Output is correct
14 Correct 996 ms 15652 KB Output is correct
15 Correct 1010 ms 15652 KB Output is correct
16 Correct 1026 ms 15636 KB Output is correct
17 Correct 975 ms 15648 KB Output is correct
18 Correct 1008 ms 15636 KB Output is correct
19 Correct 1004 ms 15640 KB Output is correct
20 Correct 975 ms 15644 KB Output is correct
21 Correct 978 ms 15636 KB Output is correct
22 Runtime error 1 ms 460 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1022 ms 14792 KB Output is correct
2 Correct 1016 ms 14772 KB Output is correct
3 Correct 1014 ms 14780 KB Output is correct
4 Correct 1094 ms 14664 KB Output is correct
5 Correct 999 ms 14864 KB Output is correct
6 Correct 1000 ms 14780 KB Output is correct
7 Correct 1008 ms 14824 KB Output is correct
8 Correct 1016 ms 14788 KB Output is correct
9 Correct 1008 ms 15632 KB Output is correct
10 Correct 990 ms 15648 KB Output is correct
11 Correct 992 ms 15644 KB Output is correct
12 Correct 972 ms 15632 KB Output is correct
13 Correct 988 ms 15652 KB Output is correct
14 Correct 996 ms 15652 KB Output is correct
15 Correct 1010 ms 15652 KB Output is correct
16 Correct 1026 ms 15636 KB Output is correct
17 Correct 975 ms 15648 KB Output is correct
18 Correct 1008 ms 15636 KB Output is correct
19 Correct 1004 ms 15640 KB Output is correct
20 Correct 975 ms 15644 KB Output is correct
21 Correct 978 ms 15636 KB Output is correct
22 Runtime error 1 ms 460 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1022 ms 14792 KB Output is correct
2 Correct 1016 ms 14772 KB Output is correct
3 Correct 1014 ms 14780 KB Output is correct
4 Correct 1094 ms 14664 KB Output is correct
5 Correct 999 ms 14864 KB Output is correct
6 Correct 1000 ms 14780 KB Output is correct
7 Correct 1008 ms 14824 KB Output is correct
8 Correct 1016 ms 14788 KB Output is correct
9 Correct 1008 ms 15632 KB Output is correct
10 Correct 990 ms 15648 KB Output is correct
11 Correct 992 ms 15644 KB Output is correct
12 Correct 972 ms 15632 KB Output is correct
13 Correct 988 ms 15652 KB Output is correct
14 Correct 996 ms 15652 KB Output is correct
15 Correct 1010 ms 15652 KB Output is correct
16 Correct 1026 ms 15636 KB Output is correct
17 Correct 975 ms 15648 KB Output is correct
18 Correct 1008 ms 15636 KB Output is correct
19 Correct 1004 ms 15640 KB Output is correct
20 Correct 975 ms 15644 KB Output is correct
21 Correct 978 ms 15636 KB Output is correct
22 Runtime error 1 ms 460 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -