답안 #904814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
904814 2024-01-12T08:49:23 Z andrei_iorgulescu Cubeword (CEOI19_cubeword) C++14
100 / 100
363 ms 21100 KB
#include <bits/stdc++.h>

using namespace std;

const int S = 62;
const int modulo = 998244353;
vector<string>cuv[15];
int cst[S][S];
int cost[S][S][S];

int toint(char c)
{
    if (c >= 'a' and c <= 'z')
        return c - 'a';
    else if (c >= 'A' and c <= 'Z')
        return 26 + c - 'A';
    else
        return 52 + c - '0';
}

bool palint(string s)
{
    for (int i = 1; i < s.size() - 1; i++)
        if (s[i] != s[s.size() - 1 - i])
            return false;
    return true;
}

string inv(string s)
{
    reverse(s.begin(),s.end());
    return s;
}

map<string,bool>mp;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        cuv[s.size()].push_back(s);
    }
    int ans = 0;
    for (int l = 3; l <= 10; l++)
    {
        for (int i = 0; i < S; i++)
            for (int j = 0; j < S; j++)
                cst[i][j] = 0;
        for (int i = 0; i < S; i++)
            for (int j = 0; j < S; j++)
                for (int k = 0; k < S; k++)
                    cost[i][j][k] = 0;
        for (auto it : cuv[l])
        {
            if (mp[inv(it)] == true)
                continue;
            mp[it] = true;
            cst[toint(it[0])][toint(it[l - 1])]++;
            if (it[0] != it[l - 1])
                cst[toint(it[l - 1])][toint(it[0])]++;
            else if (palint(it) == false)
                cst[toint(it[0])][toint(it[l - 1])]++;
        }
        for (int i = 0; i < S; i++)
        {
            for (int j = i; j < S; j++)
            {
                for (int k = j; k < S; k++)
                {
                    for (int q = 0; q < S; q++)
                        cost[i][j][k] = (0ll + cost[i][j][k] + 1ll * cst[i][q] * cst[j][q] * cst[k][q]) % modulo;
                }
            }
        }
        for (int A = 0; A < S; A++)
        {
            for (int B = A; B < S; B++)
            {
                for (int C = B; C < S; C++)
                {
                    for (int D = C; D < S; D++)
                    {
                        int fra = 1,frb = 0,frc = 0,frd = 0;
                        if (B == A)
                            fra++;
                        else
                            frb++;
                        if (C == A)
                            fra++;
                        else if (C == B)
                            frb++;
                        else
                            frc++;
                        if (D == A)
                            fra++;
                        else if (D == B)
                            frb++;
                        else if (D == C)
                            frc++;
                        else
                            frd++;
                        int dv = 1;
                        for (int i = 2; i <= fra; i++)
                            dv *= i;
                        for (int i = 2; i <= frb; i++)
                            dv *= i;
                        for (int i = 2; i <= frc; i++)
                            dv *= i;
                        int adg = 1ll * cost[A][B][C] * cost[A][B][D] % modulo * cost[A][C][D] % modulo * cost[B][C][D] % modulo;
                        int radg = 1ll * adg * 24 / dv % modulo;
                        ans = (ans + radg) % modulo;
                    }
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Compilation message

cubeword.cpp: In function 'bool palint(std::string)':
cubeword.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i = 1; i < s.size() - 1; i++)
      |                     ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 18988 KB Output is correct
2 Correct 293 ms 19064 KB Output is correct
3 Correct 291 ms 19104 KB Output is correct
4 Correct 306 ms 19084 KB Output is correct
5 Correct 266 ms 19052 KB Output is correct
6 Correct 350 ms 18868 KB Output is correct
7 Correct 310 ms 19100 KB Output is correct
8 Correct 285 ms 18884 KB Output is correct
9 Correct 298 ms 18872 KB Output is correct
10 Correct 292 ms 18876 KB Output is correct
11 Correct 309 ms 18932 KB Output is correct
12 Correct 304 ms 18896 KB Output is correct
13 Correct 278 ms 19000 KB Output is correct
14 Correct 275 ms 18980 KB Output is correct
15 Correct 288 ms 18968 KB Output is correct
16 Correct 246 ms 18820 KB Output is correct
17 Correct 330 ms 18944 KB Output is correct
18 Correct 302 ms 18824 KB Output is correct
19 Correct 273 ms 19040 KB Output is correct
20 Correct 292 ms 18816 KB Output is correct
21 Correct 291 ms 18864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 18988 KB Output is correct
2 Correct 293 ms 19064 KB Output is correct
3 Correct 291 ms 19104 KB Output is correct
4 Correct 306 ms 19084 KB Output is correct
5 Correct 266 ms 19052 KB Output is correct
6 Correct 350 ms 18868 KB Output is correct
7 Correct 310 ms 19100 KB Output is correct
8 Correct 285 ms 18884 KB Output is correct
9 Correct 298 ms 18872 KB Output is correct
10 Correct 292 ms 18876 KB Output is correct
11 Correct 309 ms 18932 KB Output is correct
12 Correct 304 ms 18896 KB Output is correct
13 Correct 278 ms 19000 KB Output is correct
14 Correct 275 ms 18980 KB Output is correct
15 Correct 288 ms 18968 KB Output is correct
16 Correct 246 ms 18820 KB Output is correct
17 Correct 330 ms 18944 KB Output is correct
18 Correct 302 ms 18824 KB Output is correct
19 Correct 273 ms 19040 KB Output is correct
20 Correct 292 ms 18816 KB Output is correct
21 Correct 291 ms 18864 KB Output is correct
22 Correct 350 ms 19712 KB Output is correct
23 Correct 313 ms 19700 KB Output is correct
24 Correct 283 ms 19628 KB Output is correct
25 Correct 363 ms 19696 KB Output is correct
26 Correct 298 ms 19620 KB Output is correct
27 Correct 300 ms 19448 KB Output is correct
28 Correct 332 ms 19460 KB Output is correct
29 Correct 343 ms 19604 KB Output is correct
30 Correct 274 ms 19700 KB Output is correct
31 Correct 340 ms 19568 KB Output is correct
32 Correct 341 ms 19608 KB Output is correct
33 Correct 321 ms 19696 KB Output is correct
34 Correct 355 ms 19596 KB Output is correct
35 Correct 331 ms 19676 KB Output is correct
36 Correct 274 ms 19680 KB Output is correct
37 Correct 275 ms 19788 KB Output is correct
38 Correct 279 ms 19524 KB Output is correct
39 Correct 252 ms 19640 KB Output is correct
40 Correct 259 ms 19688 KB Output is correct
41 Correct 292 ms 19680 KB Output is correct
42 Correct 269 ms 19756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 18988 KB Output is correct
2 Correct 293 ms 19064 KB Output is correct
3 Correct 291 ms 19104 KB Output is correct
4 Correct 306 ms 19084 KB Output is correct
5 Correct 266 ms 19052 KB Output is correct
6 Correct 350 ms 18868 KB Output is correct
7 Correct 310 ms 19100 KB Output is correct
8 Correct 285 ms 18884 KB Output is correct
9 Correct 298 ms 18872 KB Output is correct
10 Correct 292 ms 18876 KB Output is correct
11 Correct 309 ms 18932 KB Output is correct
12 Correct 304 ms 18896 KB Output is correct
13 Correct 278 ms 19000 KB Output is correct
14 Correct 275 ms 18980 KB Output is correct
15 Correct 288 ms 18968 KB Output is correct
16 Correct 246 ms 18820 KB Output is correct
17 Correct 330 ms 18944 KB Output is correct
18 Correct 302 ms 18824 KB Output is correct
19 Correct 273 ms 19040 KB Output is correct
20 Correct 292 ms 18816 KB Output is correct
21 Correct 291 ms 18864 KB Output is correct
22 Correct 350 ms 19712 KB Output is correct
23 Correct 313 ms 19700 KB Output is correct
24 Correct 283 ms 19628 KB Output is correct
25 Correct 363 ms 19696 KB Output is correct
26 Correct 298 ms 19620 KB Output is correct
27 Correct 300 ms 19448 KB Output is correct
28 Correct 332 ms 19460 KB Output is correct
29 Correct 343 ms 19604 KB Output is correct
30 Correct 274 ms 19700 KB Output is correct
31 Correct 340 ms 19568 KB Output is correct
32 Correct 341 ms 19608 KB Output is correct
33 Correct 321 ms 19696 KB Output is correct
34 Correct 355 ms 19596 KB Output is correct
35 Correct 331 ms 19676 KB Output is correct
36 Correct 274 ms 19680 KB Output is correct
37 Correct 275 ms 19788 KB Output is correct
38 Correct 279 ms 19524 KB Output is correct
39 Correct 252 ms 19640 KB Output is correct
40 Correct 259 ms 19688 KB Output is correct
41 Correct 292 ms 19680 KB Output is correct
42 Correct 269 ms 19756 KB Output is correct
43 Correct 280 ms 20096 KB Output is correct
44 Correct 317 ms 20136 KB Output is correct
45 Correct 262 ms 19772 KB Output is correct
46 Correct 270 ms 20012 KB Output is correct
47 Correct 291 ms 19896 KB Output is correct
48 Correct 248 ms 19916 KB Output is correct
49 Correct 258 ms 19884 KB Output is correct
50 Correct 271 ms 19880 KB Output is correct
51 Correct 316 ms 19664 KB Output is correct
52 Correct 257 ms 19796 KB Output is correct
53 Correct 279 ms 19880 KB Output is correct
54 Correct 280 ms 19912 KB Output is correct
55 Correct 269 ms 19772 KB Output is correct
56 Correct 295 ms 20196 KB Output is correct
57 Correct 236 ms 19900 KB Output is correct
58 Correct 313 ms 19752 KB Output is correct
59 Correct 272 ms 19904 KB Output is correct
60 Correct 309 ms 19900 KB Output is correct
61 Correct 261 ms 20160 KB Output is correct
62 Correct 313 ms 19672 KB Output is correct
63 Correct 283 ms 19908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 281 ms 18988 KB Output is correct
2 Correct 293 ms 19064 KB Output is correct
3 Correct 291 ms 19104 KB Output is correct
4 Correct 306 ms 19084 KB Output is correct
5 Correct 266 ms 19052 KB Output is correct
6 Correct 350 ms 18868 KB Output is correct
7 Correct 310 ms 19100 KB Output is correct
8 Correct 285 ms 18884 KB Output is correct
9 Correct 298 ms 18872 KB Output is correct
10 Correct 292 ms 18876 KB Output is correct
11 Correct 309 ms 18932 KB Output is correct
12 Correct 304 ms 18896 KB Output is correct
13 Correct 278 ms 19000 KB Output is correct
14 Correct 275 ms 18980 KB Output is correct
15 Correct 288 ms 18968 KB Output is correct
16 Correct 246 ms 18820 KB Output is correct
17 Correct 330 ms 18944 KB Output is correct
18 Correct 302 ms 18824 KB Output is correct
19 Correct 273 ms 19040 KB Output is correct
20 Correct 292 ms 18816 KB Output is correct
21 Correct 291 ms 18864 KB Output is correct
22 Correct 350 ms 19712 KB Output is correct
23 Correct 313 ms 19700 KB Output is correct
24 Correct 283 ms 19628 KB Output is correct
25 Correct 363 ms 19696 KB Output is correct
26 Correct 298 ms 19620 KB Output is correct
27 Correct 300 ms 19448 KB Output is correct
28 Correct 332 ms 19460 KB Output is correct
29 Correct 343 ms 19604 KB Output is correct
30 Correct 274 ms 19700 KB Output is correct
31 Correct 340 ms 19568 KB Output is correct
32 Correct 341 ms 19608 KB Output is correct
33 Correct 321 ms 19696 KB Output is correct
34 Correct 355 ms 19596 KB Output is correct
35 Correct 331 ms 19676 KB Output is correct
36 Correct 274 ms 19680 KB Output is correct
37 Correct 275 ms 19788 KB Output is correct
38 Correct 279 ms 19524 KB Output is correct
39 Correct 252 ms 19640 KB Output is correct
40 Correct 259 ms 19688 KB Output is correct
41 Correct 292 ms 19680 KB Output is correct
42 Correct 269 ms 19756 KB Output is correct
43 Correct 280 ms 20096 KB Output is correct
44 Correct 317 ms 20136 KB Output is correct
45 Correct 262 ms 19772 KB Output is correct
46 Correct 270 ms 20012 KB Output is correct
47 Correct 291 ms 19896 KB Output is correct
48 Correct 248 ms 19916 KB Output is correct
49 Correct 258 ms 19884 KB Output is correct
50 Correct 271 ms 19880 KB Output is correct
51 Correct 316 ms 19664 KB Output is correct
52 Correct 257 ms 19796 KB Output is correct
53 Correct 279 ms 19880 KB Output is correct
54 Correct 280 ms 19912 KB Output is correct
55 Correct 269 ms 19772 KB Output is correct
56 Correct 295 ms 20196 KB Output is correct
57 Correct 236 ms 19900 KB Output is correct
58 Correct 313 ms 19752 KB Output is correct
59 Correct 272 ms 19904 KB Output is correct
60 Correct 309 ms 19900 KB Output is correct
61 Correct 261 ms 20160 KB Output is correct
62 Correct 313 ms 19672 KB Output is correct
63 Correct 283 ms 19908 KB Output is correct
64 Correct 265 ms 20392 KB Output is correct
65 Correct 288 ms 20664 KB Output is correct
66 Correct 279 ms 20864 KB Output is correct
67 Correct 275 ms 21004 KB Output is correct
68 Correct 327 ms 21080 KB Output is correct
69 Correct 318 ms 20888 KB Output is correct
70 Correct 298 ms 20976 KB Output is correct
71 Correct 324 ms 20912 KB Output is correct
72 Correct 321 ms 20976 KB Output is correct
73 Correct 310 ms 20880 KB Output is correct
74 Correct 274 ms 20976 KB Output is correct
75 Correct 252 ms 20708 KB Output is correct
76 Correct 303 ms 20648 KB Output is correct
77 Correct 300 ms 20720 KB Output is correct
78 Correct 276 ms 20880 KB Output is correct
79 Correct 281 ms 20892 KB Output is correct
80 Correct 334 ms 20744 KB Output is correct
81 Correct 313 ms 20912 KB Output is correct
82 Correct 265 ms 20640 KB Output is correct
83 Correct 291 ms 20884 KB Output is correct
84 Correct 296 ms 21100 KB Output is correct