답안 #447259

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447259 2021-07-25T15:18:14 Z yungyao Cubeword (CEOI19_cubeword) C++17
100 / 100
380 ms 19524 KB
using namespace std;
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <utility>
#include <memory.h>
#include <vector>
#include <bitset>
 
typedef pair<int,int> pii;
typedef long long LL;
 
#define iter(x) x.begin(),x.end()
#define F first
#define S second
#define pb push_back
#define mkp make_pair
 
#include <climits>
const int maxn = 70,mod = (119 << 23)^1;
 
int ctoi(char c){
    if (c >= 'a' and c <= 'p') return c - 'a';
    else if (c >= 'A' and c <= 'P') return c - 'A' + 16;
    else if (c > 'p' and c <= 'z') return c - 'p' + 31;
    else if (c > 'P' and c <= 'Z') return c - 'P' + 41;
    else return c - '0' + 52;
}

LL dp[maxn][maxn][maxn]{};
int perm_cnt(int a,int b,int c,int d){
    int bb = 24,bbb = 1,cc = 1;
    if (a == b) bbb *= ++cc;
    else {bb /= bbb; bbb = 1; cc = 1;}
    if (b == c) bbb *= ++cc;
    else {bb /= bbb; bbb = 1; cc = 1;}
    if (c == d) bbb *= ++cc;
    bb /= bbb;
    return bb;
}
 
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    set <string> st[11];
    int n;
 
    cin >> n;
    for (int i=0;i<n;++i){
        string s; cin >> s;
        st[s.size()].insert(s);
        reverse(iter(s));
        st[s.size()].insert(s);
    }
 
    LL ans = 0;
    for (int len=3;len<=10;++len) if (!st[len].empty()){
        int mx = 0;
        LL cnt[maxn][maxn]{};
        memset(dp,0,sizeof(dp));
        for (string s:st[len]){
            ++cnt[ctoi(s[0])][ctoi(s.back())];
            mx = max(mx,ctoi(s[0]));
        }
        for (int i=0;i<=mx;++i) for (int j=i;j<=mx;++j) for (int k=j;k<=mx;++k) for (int l=0;l<=mx;++l){
            dp[i][j][k] += cnt[i][l] * cnt[j][l] % mod * cnt[k][l] % mod;
            dp[i][j][k] %= mod;
        }
        for (int i=0;i<=mx;++i) for (int j=i;j<=mx;++j) for (int k=j;k<=mx;++k) for (int l=k;l<=mx;++l){
            ans += dp[i][j][k] * dp[i][j][l] % mod * dp[i][k][l] % mod * dp[j][k][l] % mod * perm_cnt(i,j,k,l);
            ans %= mod;
        }
    }
 
    cout << ans;
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 18272 KB Output is correct
2 Correct 143 ms 18336 KB Output is correct
3 Correct 149 ms 18244 KB Output is correct
4 Correct 162 ms 18256 KB Output is correct
5 Correct 173 ms 18368 KB Output is correct
6 Correct 147 ms 18264 KB Output is correct
7 Correct 151 ms 18460 KB Output is correct
8 Correct 147 ms 18332 KB Output is correct
9 Correct 158 ms 18336 KB Output is correct
10 Correct 155 ms 18356 KB Output is correct
11 Correct 148 ms 18244 KB Output is correct
12 Correct 151 ms 18304 KB Output is correct
13 Correct 172 ms 18428 KB Output is correct
14 Correct 158 ms 18280 KB Output is correct
15 Correct 151 ms 18356 KB Output is correct
16 Correct 151 ms 18464 KB Output is correct
17 Correct 156 ms 18356 KB Output is correct
18 Correct 152 ms 18316 KB Output is correct
19 Correct 156 ms 18240 KB Output is correct
20 Correct 153 ms 18264 KB Output is correct
21 Correct 167 ms 18348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 18272 KB Output is correct
2 Correct 143 ms 18336 KB Output is correct
3 Correct 149 ms 18244 KB Output is correct
4 Correct 162 ms 18256 KB Output is correct
5 Correct 173 ms 18368 KB Output is correct
6 Correct 147 ms 18264 KB Output is correct
7 Correct 151 ms 18460 KB Output is correct
8 Correct 147 ms 18332 KB Output is correct
9 Correct 158 ms 18336 KB Output is correct
10 Correct 155 ms 18356 KB Output is correct
11 Correct 148 ms 18244 KB Output is correct
12 Correct 151 ms 18304 KB Output is correct
13 Correct 172 ms 18428 KB Output is correct
14 Correct 158 ms 18280 KB Output is correct
15 Correct 151 ms 18356 KB Output is correct
16 Correct 151 ms 18464 KB Output is correct
17 Correct 156 ms 18356 KB Output is correct
18 Correct 152 ms 18316 KB Output is correct
19 Correct 156 ms 18240 KB Output is correct
20 Correct 153 ms 18264 KB Output is correct
21 Correct 167 ms 18348 KB Output is correct
22 Correct 157 ms 18944 KB Output is correct
23 Correct 163 ms 18900 KB Output is correct
24 Correct 174 ms 18836 KB Output is correct
25 Correct 165 ms 19000 KB Output is correct
26 Correct 163 ms 18916 KB Output is correct
27 Correct 167 ms 18884 KB Output is correct
28 Correct 165 ms 18952 KB Output is correct
29 Correct 157 ms 18876 KB Output is correct
30 Correct 156 ms 18840 KB Output is correct
31 Correct 154 ms 18868 KB Output is correct
32 Correct 157 ms 18884 KB Output is correct
33 Correct 151 ms 18888 KB Output is correct
34 Correct 153 ms 18884 KB Output is correct
35 Correct 155 ms 18932 KB Output is correct
36 Correct 162 ms 18932 KB Output is correct
37 Correct 151 ms 18896 KB Output is correct
38 Correct 159 ms 18876 KB Output is correct
39 Correct 165 ms 18884 KB Output is correct
40 Correct 163 ms 18960 KB Output is correct
41 Correct 157 ms 18876 KB Output is correct
42 Correct 154 ms 18912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 18272 KB Output is correct
2 Correct 143 ms 18336 KB Output is correct
3 Correct 149 ms 18244 KB Output is correct
4 Correct 162 ms 18256 KB Output is correct
5 Correct 173 ms 18368 KB Output is correct
6 Correct 147 ms 18264 KB Output is correct
7 Correct 151 ms 18460 KB Output is correct
8 Correct 147 ms 18332 KB Output is correct
9 Correct 158 ms 18336 KB Output is correct
10 Correct 155 ms 18356 KB Output is correct
11 Correct 148 ms 18244 KB Output is correct
12 Correct 151 ms 18304 KB Output is correct
13 Correct 172 ms 18428 KB Output is correct
14 Correct 158 ms 18280 KB Output is correct
15 Correct 151 ms 18356 KB Output is correct
16 Correct 151 ms 18464 KB Output is correct
17 Correct 156 ms 18356 KB Output is correct
18 Correct 152 ms 18316 KB Output is correct
19 Correct 156 ms 18240 KB Output is correct
20 Correct 153 ms 18264 KB Output is correct
21 Correct 167 ms 18348 KB Output is correct
22 Correct 157 ms 18944 KB Output is correct
23 Correct 163 ms 18900 KB Output is correct
24 Correct 174 ms 18836 KB Output is correct
25 Correct 165 ms 19000 KB Output is correct
26 Correct 163 ms 18916 KB Output is correct
27 Correct 167 ms 18884 KB Output is correct
28 Correct 165 ms 18952 KB Output is correct
29 Correct 157 ms 18876 KB Output is correct
30 Correct 156 ms 18840 KB Output is correct
31 Correct 154 ms 18868 KB Output is correct
32 Correct 157 ms 18884 KB Output is correct
33 Correct 151 ms 18888 KB Output is correct
34 Correct 153 ms 18884 KB Output is correct
35 Correct 155 ms 18932 KB Output is correct
36 Correct 162 ms 18932 KB Output is correct
37 Correct 151 ms 18896 KB Output is correct
38 Correct 159 ms 18876 KB Output is correct
39 Correct 165 ms 18884 KB Output is correct
40 Correct 163 ms 18960 KB Output is correct
41 Correct 157 ms 18876 KB Output is correct
42 Correct 154 ms 18912 KB Output is correct
43 Correct 169 ms 19080 KB Output is correct
44 Correct 185 ms 19012 KB Output is correct
45 Correct 166 ms 19012 KB Output is correct
46 Correct 181 ms 19260 KB Output is correct
47 Correct 171 ms 19120 KB Output is correct
48 Correct 168 ms 19116 KB Output is correct
49 Correct 174 ms 19012 KB Output is correct
50 Correct 179 ms 19088 KB Output is correct
51 Correct 167 ms 19012 KB Output is correct
52 Correct 165 ms 19080 KB Output is correct
53 Correct 178 ms 19084 KB Output is correct
54 Correct 173 ms 19036 KB Output is correct
55 Correct 182 ms 19052 KB Output is correct
56 Correct 169 ms 18996 KB Output is correct
57 Correct 173 ms 19092 KB Output is correct
58 Correct 169 ms 19040 KB Output is correct
59 Correct 192 ms 19012 KB Output is correct
60 Correct 192 ms 19032 KB Output is correct
61 Correct 186 ms 19140 KB Output is correct
62 Correct 182 ms 18992 KB Output is correct
63 Correct 170 ms 19212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 18272 KB Output is correct
2 Correct 143 ms 18336 KB Output is correct
3 Correct 149 ms 18244 KB Output is correct
4 Correct 162 ms 18256 KB Output is correct
5 Correct 173 ms 18368 KB Output is correct
6 Correct 147 ms 18264 KB Output is correct
7 Correct 151 ms 18460 KB Output is correct
8 Correct 147 ms 18332 KB Output is correct
9 Correct 158 ms 18336 KB Output is correct
10 Correct 155 ms 18356 KB Output is correct
11 Correct 148 ms 18244 KB Output is correct
12 Correct 151 ms 18304 KB Output is correct
13 Correct 172 ms 18428 KB Output is correct
14 Correct 158 ms 18280 KB Output is correct
15 Correct 151 ms 18356 KB Output is correct
16 Correct 151 ms 18464 KB Output is correct
17 Correct 156 ms 18356 KB Output is correct
18 Correct 152 ms 18316 KB Output is correct
19 Correct 156 ms 18240 KB Output is correct
20 Correct 153 ms 18264 KB Output is correct
21 Correct 167 ms 18348 KB Output is correct
22 Correct 157 ms 18944 KB Output is correct
23 Correct 163 ms 18900 KB Output is correct
24 Correct 174 ms 18836 KB Output is correct
25 Correct 165 ms 19000 KB Output is correct
26 Correct 163 ms 18916 KB Output is correct
27 Correct 167 ms 18884 KB Output is correct
28 Correct 165 ms 18952 KB Output is correct
29 Correct 157 ms 18876 KB Output is correct
30 Correct 156 ms 18840 KB Output is correct
31 Correct 154 ms 18868 KB Output is correct
32 Correct 157 ms 18884 KB Output is correct
33 Correct 151 ms 18888 KB Output is correct
34 Correct 153 ms 18884 KB Output is correct
35 Correct 155 ms 18932 KB Output is correct
36 Correct 162 ms 18932 KB Output is correct
37 Correct 151 ms 18896 KB Output is correct
38 Correct 159 ms 18876 KB Output is correct
39 Correct 165 ms 18884 KB Output is correct
40 Correct 163 ms 18960 KB Output is correct
41 Correct 157 ms 18876 KB Output is correct
42 Correct 154 ms 18912 KB Output is correct
43 Correct 169 ms 19080 KB Output is correct
44 Correct 185 ms 19012 KB Output is correct
45 Correct 166 ms 19012 KB Output is correct
46 Correct 181 ms 19260 KB Output is correct
47 Correct 171 ms 19120 KB Output is correct
48 Correct 168 ms 19116 KB Output is correct
49 Correct 174 ms 19012 KB Output is correct
50 Correct 179 ms 19088 KB Output is correct
51 Correct 167 ms 19012 KB Output is correct
52 Correct 165 ms 19080 KB Output is correct
53 Correct 178 ms 19084 KB Output is correct
54 Correct 173 ms 19036 KB Output is correct
55 Correct 182 ms 19052 KB Output is correct
56 Correct 169 ms 18996 KB Output is correct
57 Correct 173 ms 19092 KB Output is correct
58 Correct 169 ms 19040 KB Output is correct
59 Correct 192 ms 19012 KB Output is correct
60 Correct 192 ms 19032 KB Output is correct
61 Correct 186 ms 19140 KB Output is correct
62 Correct 182 ms 18992 KB Output is correct
63 Correct 170 ms 19212 KB Output is correct
64 Correct 353 ms 19344 KB Output is correct
65 Correct 347 ms 19388 KB Output is correct
66 Correct 361 ms 19464 KB Output is correct
67 Correct 359 ms 19268 KB Output is correct
68 Correct 373 ms 19524 KB Output is correct
69 Correct 346 ms 19268 KB Output is correct
70 Correct 352 ms 19412 KB Output is correct
71 Correct 347 ms 19268 KB Output is correct
72 Correct 349 ms 19432 KB Output is correct
73 Correct 353 ms 19336 KB Output is correct
74 Correct 346 ms 19272 KB Output is correct
75 Correct 346 ms 19268 KB Output is correct
76 Correct 348 ms 19396 KB Output is correct
77 Correct 352 ms 19268 KB Output is correct
78 Correct 345 ms 19232 KB Output is correct
79 Correct 365 ms 19340 KB Output is correct
80 Correct 346 ms 19340 KB Output is correct
81 Correct 369 ms 19396 KB Output is correct
82 Correct 355 ms 19304 KB Output is correct
83 Correct 350 ms 19396 KB Output is correct
84 Correct 380 ms 19304 KB Output is correct