Submission #276071

# Submission time Handle Problem Language Result Execution time Memory
276071 2020-08-20T10:32:01 Z egekabas Cubeword (CEOI19_cubeword) C++14
100 / 100
274 ms 9424 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
const ll mod = 998244353;
ll ans = 0;
vector<string> a[11];
const ll n = 62;
ll cnt[70][70];
map<char, ll> mpp;
ll dp[70][70][70];
    
ll ft[5] = {1, 1, 2, 6, 24};
ll calc(vector<int> v){
    int ans = ft[4];
    int cur = 0;
    for(int i = 0; i < v.size(); ++i){
        if(i != 0 && v[i] == v[i-1])
            ++cur;
        else{
            ans /= ft[cur];
            cur = 1;
        }
    }
    ans /= ft[cur];
    return ans;
}
int gt[2][2][2];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    int t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        a[s.size()-3].pb(s);
        reverse(all(s));
        a[s.size()-3].pb(s);

    }
    int curcnt = 0;
    for(char i = 'a'; i <= 'z'; ++i)
        mpp[i] = curcnt++;
    for(char i = 'A'; i <= 'Z'; ++i)
        mpp[i] = curcnt++;
    for(char i = '0'; i <= '9'; ++i)
        mpp[i] = curcnt++;
    
    for(int i = 0; i < 4; ++i)
        for(int j = i; j < 4; ++j)
            for(int k = j; k < 4; ++k)
                for(int y = k; y < 4; ++y)
                    gt[j==i][k==j][y==k] = calc({i, j, k, y});

    for(int cur = 0; cur < 8; ++cur){
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                cnt[i][j] = 0;
        sort(all(a[cur]));
        for(int i = 0; i < a[cur].size(); ++i){
            if(i == 0 || a[cur][i] != a[cur][i-1])
                cnt[mpp[a[cur][i][0]]][mpp[a[cur][i].back()]]++;
        }
        for(int i = 0; i < n; ++i)
            for(int j = i; j < n; ++j)
                for(int k = j; k < n; ++k){
                    dp[i][j][k] = 0;
                    for(int mid = 0; mid < n; ++mid){
                        dp[i][j][k] += cnt[i][mid]*cnt[j][mid]%mod*cnt[k][mid]%mod;
                        if(dp[i][j][k] >= mod)
                            dp[i][j][k] -= mod;
                    }
                }
        for(int i = 0; i < n; ++i)
            for(int j = i; j < n; ++j)
                for(int k = j; k < n; ++k)
                    for(int y = k; y < n; ++y){
                        ans += gt[j==i][k==j][y==k]*dp[i][j][k]%mod*dp[i][j][y]%mod*dp[j][k][y]%mod*dp[i][k][y]%mod;
                        if(ans >= mod)
                            ans -= mod;
                    }
    }
    cout << ans << '\n';
    //cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
}

Compilation message

cubeword.cpp: In function 'll calc(std::vector<int>)':
cubeword.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0; i < v.size(); ++i){
      |                    ~~^~~~~~~~~~
cubeword.cpp: In function 'int main()':
cubeword.cpp:76:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for(int i = 0; i < a[cur].size(); ++i){
      |                        ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 244 ms 8304 KB Output is correct
2 Correct 261 ms 9216 KB Output is correct
3 Correct 248 ms 9308 KB Output is correct
4 Correct 257 ms 9184 KB Output is correct
5 Correct 246 ms 9340 KB Output is correct
6 Correct 248 ms 9156 KB Output is correct
7 Correct 248 ms 9212 KB Output is correct
8 Correct 244 ms 9296 KB Output is correct
9 Correct 270 ms 9056 KB Output is correct
10 Correct 247 ms 9308 KB Output is correct
11 Correct 247 ms 9184 KB Output is correct
12 Correct 248 ms 9232 KB Output is correct
13 Correct 243 ms 9176 KB Output is correct
14 Correct 242 ms 9120 KB Output is correct
15 Correct 250 ms 9104 KB Output is correct
16 Correct 243 ms 9224 KB Output is correct
17 Correct 245 ms 9228 KB Output is correct
18 Correct 249 ms 9424 KB Output is correct
19 Correct 243 ms 9228 KB Output is correct
20 Correct 248 ms 9128 KB Output is correct
21 Correct 243 ms 9220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 8304 KB Output is correct
2 Correct 261 ms 9216 KB Output is correct
3 Correct 248 ms 9308 KB Output is correct
4 Correct 257 ms 9184 KB Output is correct
5 Correct 246 ms 9340 KB Output is correct
6 Correct 248 ms 9156 KB Output is correct
7 Correct 248 ms 9212 KB Output is correct
8 Correct 244 ms 9296 KB Output is correct
9 Correct 270 ms 9056 KB Output is correct
10 Correct 247 ms 9308 KB Output is correct
11 Correct 247 ms 9184 KB Output is correct
12 Correct 248 ms 9232 KB Output is correct
13 Correct 243 ms 9176 KB Output is correct
14 Correct 242 ms 9120 KB Output is correct
15 Correct 250 ms 9104 KB Output is correct
16 Correct 243 ms 9224 KB Output is correct
17 Correct 245 ms 9228 KB Output is correct
18 Correct 249 ms 9424 KB Output is correct
19 Correct 243 ms 9228 KB Output is correct
20 Correct 248 ms 9128 KB Output is correct
21 Correct 243 ms 9220 KB Output is correct
22 Correct 241 ms 9036 KB Output is correct
23 Correct 244 ms 9000 KB Output is correct
24 Correct 242 ms 9012 KB Output is correct
25 Correct 244 ms 8924 KB Output is correct
26 Correct 240 ms 8828 KB Output is correct
27 Correct 239 ms 8892 KB Output is correct
28 Correct 246 ms 9032 KB Output is correct
29 Correct 253 ms 9036 KB Output is correct
30 Correct 239 ms 8916 KB Output is correct
31 Correct 249 ms 9012 KB Output is correct
32 Correct 254 ms 9044 KB Output is correct
33 Correct 263 ms 9104 KB Output is correct
34 Correct 245 ms 9104 KB Output is correct
35 Correct 248 ms 9040 KB Output is correct
36 Correct 241 ms 8996 KB Output is correct
37 Correct 245 ms 8964 KB Output is correct
38 Correct 240 ms 9004 KB Output is correct
39 Correct 243 ms 9052 KB Output is correct
40 Correct 245 ms 9008 KB Output is correct
41 Correct 244 ms 9008 KB Output is correct
42 Correct 244 ms 8976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 8304 KB Output is correct
2 Correct 261 ms 9216 KB Output is correct
3 Correct 248 ms 9308 KB Output is correct
4 Correct 257 ms 9184 KB Output is correct
5 Correct 246 ms 9340 KB Output is correct
6 Correct 248 ms 9156 KB Output is correct
7 Correct 248 ms 9212 KB Output is correct
8 Correct 244 ms 9296 KB Output is correct
9 Correct 270 ms 9056 KB Output is correct
10 Correct 247 ms 9308 KB Output is correct
11 Correct 247 ms 9184 KB Output is correct
12 Correct 248 ms 9232 KB Output is correct
13 Correct 243 ms 9176 KB Output is correct
14 Correct 242 ms 9120 KB Output is correct
15 Correct 250 ms 9104 KB Output is correct
16 Correct 243 ms 9224 KB Output is correct
17 Correct 245 ms 9228 KB Output is correct
18 Correct 249 ms 9424 KB Output is correct
19 Correct 243 ms 9228 KB Output is correct
20 Correct 248 ms 9128 KB Output is correct
21 Correct 243 ms 9220 KB Output is correct
22 Correct 241 ms 9036 KB Output is correct
23 Correct 244 ms 9000 KB Output is correct
24 Correct 242 ms 9012 KB Output is correct
25 Correct 244 ms 8924 KB Output is correct
26 Correct 240 ms 8828 KB Output is correct
27 Correct 239 ms 8892 KB Output is correct
28 Correct 246 ms 9032 KB Output is correct
29 Correct 253 ms 9036 KB Output is correct
30 Correct 239 ms 8916 KB Output is correct
31 Correct 249 ms 9012 KB Output is correct
32 Correct 254 ms 9044 KB Output is correct
33 Correct 263 ms 9104 KB Output is correct
34 Correct 245 ms 9104 KB Output is correct
35 Correct 248 ms 9040 KB Output is correct
36 Correct 241 ms 8996 KB Output is correct
37 Correct 245 ms 8964 KB Output is correct
38 Correct 240 ms 9004 KB Output is correct
39 Correct 243 ms 9052 KB Output is correct
40 Correct 245 ms 9008 KB Output is correct
41 Correct 244 ms 9008 KB Output is correct
42 Correct 244 ms 8976 KB Output is correct
43 Correct 262 ms 9396 KB Output is correct
44 Correct 244 ms 9144 KB Output is correct
45 Correct 262 ms 8928 KB Output is correct
46 Correct 243 ms 9192 KB Output is correct
47 Correct 253 ms 9148 KB Output is correct
48 Correct 250 ms 9268 KB Output is correct
49 Correct 241 ms 8872 KB Output is correct
50 Correct 243 ms 8788 KB Output is correct
51 Correct 253 ms 8868 KB Output is correct
52 Correct 246 ms 9004 KB Output is correct
53 Correct 267 ms 8780 KB Output is correct
54 Correct 250 ms 8924 KB Output is correct
55 Correct 244 ms 9008 KB Output is correct
56 Correct 258 ms 9096 KB Output is correct
57 Correct 244 ms 9144 KB Output is correct
58 Correct 269 ms 8776 KB Output is correct
59 Correct 245 ms 8932 KB Output is correct
60 Correct 243 ms 9124 KB Output is correct
61 Correct 241 ms 9132 KB Output is correct
62 Correct 243 ms 8812 KB Output is correct
63 Correct 260 ms 9024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 8304 KB Output is correct
2 Correct 261 ms 9216 KB Output is correct
3 Correct 248 ms 9308 KB Output is correct
4 Correct 257 ms 9184 KB Output is correct
5 Correct 246 ms 9340 KB Output is correct
6 Correct 248 ms 9156 KB Output is correct
7 Correct 248 ms 9212 KB Output is correct
8 Correct 244 ms 9296 KB Output is correct
9 Correct 270 ms 9056 KB Output is correct
10 Correct 247 ms 9308 KB Output is correct
11 Correct 247 ms 9184 KB Output is correct
12 Correct 248 ms 9232 KB Output is correct
13 Correct 243 ms 9176 KB Output is correct
14 Correct 242 ms 9120 KB Output is correct
15 Correct 250 ms 9104 KB Output is correct
16 Correct 243 ms 9224 KB Output is correct
17 Correct 245 ms 9228 KB Output is correct
18 Correct 249 ms 9424 KB Output is correct
19 Correct 243 ms 9228 KB Output is correct
20 Correct 248 ms 9128 KB Output is correct
21 Correct 243 ms 9220 KB Output is correct
22 Correct 241 ms 9036 KB Output is correct
23 Correct 244 ms 9000 KB Output is correct
24 Correct 242 ms 9012 KB Output is correct
25 Correct 244 ms 8924 KB Output is correct
26 Correct 240 ms 8828 KB Output is correct
27 Correct 239 ms 8892 KB Output is correct
28 Correct 246 ms 9032 KB Output is correct
29 Correct 253 ms 9036 KB Output is correct
30 Correct 239 ms 8916 KB Output is correct
31 Correct 249 ms 9012 KB Output is correct
32 Correct 254 ms 9044 KB Output is correct
33 Correct 263 ms 9104 KB Output is correct
34 Correct 245 ms 9104 KB Output is correct
35 Correct 248 ms 9040 KB Output is correct
36 Correct 241 ms 8996 KB Output is correct
37 Correct 245 ms 8964 KB Output is correct
38 Correct 240 ms 9004 KB Output is correct
39 Correct 243 ms 9052 KB Output is correct
40 Correct 245 ms 9008 KB Output is correct
41 Correct 244 ms 9008 KB Output is correct
42 Correct 244 ms 8976 KB Output is correct
43 Correct 262 ms 9396 KB Output is correct
44 Correct 244 ms 9144 KB Output is correct
45 Correct 262 ms 8928 KB Output is correct
46 Correct 243 ms 9192 KB Output is correct
47 Correct 253 ms 9148 KB Output is correct
48 Correct 250 ms 9268 KB Output is correct
49 Correct 241 ms 8872 KB Output is correct
50 Correct 243 ms 8788 KB Output is correct
51 Correct 253 ms 8868 KB Output is correct
52 Correct 246 ms 9004 KB Output is correct
53 Correct 267 ms 8780 KB Output is correct
54 Correct 250 ms 8924 KB Output is correct
55 Correct 244 ms 9008 KB Output is correct
56 Correct 258 ms 9096 KB Output is correct
57 Correct 244 ms 9144 KB Output is correct
58 Correct 269 ms 8776 KB Output is correct
59 Correct 245 ms 8932 KB Output is correct
60 Correct 243 ms 9124 KB Output is correct
61 Correct 241 ms 9132 KB Output is correct
62 Correct 243 ms 8812 KB Output is correct
63 Correct 260 ms 9024 KB Output is correct
64 Correct 248 ms 9136 KB Output is correct
65 Correct 239 ms 9036 KB Output is correct
66 Correct 247 ms 8896 KB Output is correct
67 Correct 248 ms 9260 KB Output is correct
68 Correct 243 ms 9012 KB Output is correct
69 Correct 244 ms 9008 KB Output is correct
70 Correct 246 ms 8928 KB Output is correct
71 Correct 243 ms 9004 KB Output is correct
72 Correct 243 ms 9268 KB Output is correct
73 Correct 241 ms 8904 KB Output is correct
74 Correct 246 ms 9220 KB Output is correct
75 Correct 248 ms 9128 KB Output is correct
76 Correct 255 ms 8900 KB Output is correct
77 Correct 256 ms 9196 KB Output is correct
78 Correct 251 ms 8900 KB Output is correct
79 Correct 251 ms 9140 KB Output is correct
80 Correct 260 ms 8864 KB Output is correct
81 Correct 253 ms 8880 KB Output is correct
82 Correct 254 ms 9140 KB Output is correct
83 Correct 274 ms 8868 KB Output is correct
84 Correct 240 ms 8804 KB Output is correct