Submission #426082

# Submission time Handle Problem Language Result Execution time Memory
426082 2021-06-13T13:47:43 Z hhhhaura Cubeword (CEOI19_cubeword) C++14
0 / 100
1100 ms 7500 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 = 16, MOD = 998244353;
	signed cnt[11][70][70];
	int dp[11][70][70][70];
	set<string> st;
	void init_() { 
		st.clear();
	}
	int solve() {
		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, 0, P - 1) { 
			rep(c, 0, P - 1) rep(d, 0, P - 1) {
				ans = ans + (dp[len][a][b][d] * dp[len][a][b][c] % MOD
					* dp[len][a][c][d] % MOD * dp[len][b][c][d] % MOD);
			}
			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; 
		print(s, sz, pre, suf);
		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 'int main()':
cubeword.cpp:80:7: warning: unused variable 'sz' [-Wunused-variable]
   80 |   int sz = s.size();
      |       ^~
cubeword.cpp: In function 'void solver::add(std::string)':
cubeword.cpp:70:19: warning: 'suf' may be used uninitialized in this function [-Wmaybe-uninitialized]
   70 |   cnt[sz][pre][suf] ++;
      |   ~~~~~~~~~~~~~~~~^
cubeword.cpp:70:19: warning: 'pre' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Execution timed out 1191 ms 7500 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1191 ms 7500 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1191 ms 7500 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1191 ms 7500 KB Time limit exceeded
2 Halted 0 ms 0 KB -