답안 #904805

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
904805 2024-01-12T08:37:40 Z andrei_iorgulescu Cubeword (CEOI19_cubeword) C++14
84 / 100
1100 ms 20268 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);
    }
    long long 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 = 0; j < S; j++)
            {
                for (int k = 0; k < S; k++)
                {
                    for (int q = 0; q < S; q++)
                    {
                        if (1ll * cst[i][q] * cst[j][q] * cst[k][q] != 0)
                            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 = 0; B < S; B++)
            {
                for (int C = 0; C < S; C++)
                {
                    for (int D = 0; D < S; D++)
                    {
                        if (cost[A][B][C] != 0 and cost[A][B][D] != 0 and cost[A][C][D] != 0 and cost[B][C][D] != 0)
                        {
                            int adg = (__int128)1 * cost[A][B][C] * cost[A][B][D] * cost[A][C][D] * cost[B][C][D] % modulo;
                            ans += adg;
                        }
                    }
                }
            }
        }
    }
    cout << ans % modulo;
    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 368 ms 18848 KB Output is correct
2 Correct 382 ms 18924 KB Output is correct
3 Correct 367 ms 19104 KB Output is correct
4 Correct 391 ms 18908 KB Output is correct
5 Correct 377 ms 18872 KB Output is correct
6 Correct 401 ms 19440 KB Output is correct
7 Correct 347 ms 18864 KB Output is correct
8 Correct 356 ms 19080 KB Output is correct
9 Correct 338 ms 18832 KB Output is correct
10 Correct 358 ms 18864 KB Output is correct
11 Correct 378 ms 19056 KB Output is correct
12 Correct 364 ms 18880 KB Output is correct
13 Correct 389 ms 19024 KB Output is correct
14 Correct 354 ms 19068 KB Output is correct
15 Correct 344 ms 18900 KB Output is correct
16 Correct 402 ms 18816 KB Output is correct
17 Correct 340 ms 19036 KB Output is correct
18 Correct 367 ms 18936 KB Output is correct
19 Correct 361 ms 19036 KB Output is correct
20 Correct 392 ms 19064 KB Output is correct
21 Correct 362 ms 19048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 368 ms 18848 KB Output is correct
2 Correct 382 ms 18924 KB Output is correct
3 Correct 367 ms 19104 KB Output is correct
4 Correct 391 ms 18908 KB Output is correct
5 Correct 377 ms 18872 KB Output is correct
6 Correct 401 ms 19440 KB Output is correct
7 Correct 347 ms 18864 KB Output is correct
8 Correct 356 ms 19080 KB Output is correct
9 Correct 338 ms 18832 KB Output is correct
10 Correct 358 ms 18864 KB Output is correct
11 Correct 378 ms 19056 KB Output is correct
12 Correct 364 ms 18880 KB Output is correct
13 Correct 389 ms 19024 KB Output is correct
14 Correct 354 ms 19068 KB Output is correct
15 Correct 344 ms 18900 KB Output is correct
16 Correct 402 ms 18816 KB Output is correct
17 Correct 340 ms 19036 KB Output is correct
18 Correct 367 ms 18936 KB Output is correct
19 Correct 361 ms 19036 KB Output is correct
20 Correct 392 ms 19064 KB Output is correct
21 Correct 362 ms 19048 KB Output is correct
22 Correct 430 ms 19576 KB Output is correct
23 Correct 388 ms 19620 KB Output is correct
24 Correct 401 ms 19484 KB Output is correct
25 Correct 433 ms 19580 KB Output is correct
26 Correct 443 ms 19620 KB Output is correct
27 Correct 369 ms 19756 KB Output is correct
28 Correct 390 ms 19556 KB Output is correct
29 Correct 414 ms 19772 KB Output is correct
30 Correct 357 ms 19520 KB Output is correct
31 Correct 387 ms 19568 KB Output is correct
32 Correct 360 ms 19604 KB Output is correct
33 Correct 407 ms 19804 KB Output is correct
34 Correct 432 ms 19460 KB Output is correct
35 Correct 400 ms 19584 KB Output is correct
36 Correct 386 ms 19716 KB Output is correct
37 Correct 340 ms 19720 KB Output is correct
38 Correct 413 ms 19752 KB Output is correct
39 Correct 418 ms 19568 KB Output is correct
40 Correct 413 ms 19932 KB Output is correct
41 Correct 448 ms 19488 KB Output is correct
42 Correct 380 ms 19856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 368 ms 18848 KB Output is correct
2 Correct 382 ms 18924 KB Output is correct
3 Correct 367 ms 19104 KB Output is correct
4 Correct 391 ms 18908 KB Output is correct
5 Correct 377 ms 18872 KB Output is correct
6 Correct 401 ms 19440 KB Output is correct
7 Correct 347 ms 18864 KB Output is correct
8 Correct 356 ms 19080 KB Output is correct
9 Correct 338 ms 18832 KB Output is correct
10 Correct 358 ms 18864 KB Output is correct
11 Correct 378 ms 19056 KB Output is correct
12 Correct 364 ms 18880 KB Output is correct
13 Correct 389 ms 19024 KB Output is correct
14 Correct 354 ms 19068 KB Output is correct
15 Correct 344 ms 18900 KB Output is correct
16 Correct 402 ms 18816 KB Output is correct
17 Correct 340 ms 19036 KB Output is correct
18 Correct 367 ms 18936 KB Output is correct
19 Correct 361 ms 19036 KB Output is correct
20 Correct 392 ms 19064 KB Output is correct
21 Correct 362 ms 19048 KB Output is correct
22 Correct 430 ms 19576 KB Output is correct
23 Correct 388 ms 19620 KB Output is correct
24 Correct 401 ms 19484 KB Output is correct
25 Correct 433 ms 19580 KB Output is correct
26 Correct 443 ms 19620 KB Output is correct
27 Correct 369 ms 19756 KB Output is correct
28 Correct 390 ms 19556 KB Output is correct
29 Correct 414 ms 19772 KB Output is correct
30 Correct 357 ms 19520 KB Output is correct
31 Correct 387 ms 19568 KB Output is correct
32 Correct 360 ms 19604 KB Output is correct
33 Correct 407 ms 19804 KB Output is correct
34 Correct 432 ms 19460 KB Output is correct
35 Correct 400 ms 19584 KB Output is correct
36 Correct 386 ms 19716 KB Output is correct
37 Correct 340 ms 19720 KB Output is correct
38 Correct 413 ms 19752 KB Output is correct
39 Correct 418 ms 19568 KB Output is correct
40 Correct 413 ms 19932 KB Output is correct
41 Correct 448 ms 19488 KB Output is correct
42 Correct 380 ms 19856 KB Output is correct
43 Correct 530 ms 19880 KB Output is correct
44 Correct 485 ms 19956 KB Output is correct
45 Correct 523 ms 19796 KB Output is correct
46 Correct 584 ms 20268 KB Output is correct
47 Correct 464 ms 19768 KB Output is correct
48 Correct 474 ms 19836 KB Output is correct
49 Correct 512 ms 19752 KB Output is correct
50 Correct 531 ms 19880 KB Output is correct
51 Correct 528 ms 19912 KB Output is correct
52 Correct 531 ms 20144 KB Output is correct
53 Correct 501 ms 19752 KB Output is correct
54 Correct 513 ms 20188 KB Output is correct
55 Correct 493 ms 20052 KB Output is correct
56 Correct 525 ms 20100 KB Output is correct
57 Correct 519 ms 19676 KB Output is correct
58 Correct 502 ms 20064 KB Output is correct
59 Correct 482 ms 19828 KB Output is correct
60 Correct 520 ms 19836 KB Output is correct
61 Correct 482 ms 19892 KB Output is correct
62 Correct 530 ms 19700 KB Output is correct
63 Correct 529 ms 19828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 368 ms 18848 KB Output is correct
2 Correct 382 ms 18924 KB Output is correct
3 Correct 367 ms 19104 KB Output is correct
4 Correct 391 ms 18908 KB Output is correct
5 Correct 377 ms 18872 KB Output is correct
6 Correct 401 ms 19440 KB Output is correct
7 Correct 347 ms 18864 KB Output is correct
8 Correct 356 ms 19080 KB Output is correct
9 Correct 338 ms 18832 KB Output is correct
10 Correct 358 ms 18864 KB Output is correct
11 Correct 378 ms 19056 KB Output is correct
12 Correct 364 ms 18880 KB Output is correct
13 Correct 389 ms 19024 KB Output is correct
14 Correct 354 ms 19068 KB Output is correct
15 Correct 344 ms 18900 KB Output is correct
16 Correct 402 ms 18816 KB Output is correct
17 Correct 340 ms 19036 KB Output is correct
18 Correct 367 ms 18936 KB Output is correct
19 Correct 361 ms 19036 KB Output is correct
20 Correct 392 ms 19064 KB Output is correct
21 Correct 362 ms 19048 KB Output is correct
22 Correct 430 ms 19576 KB Output is correct
23 Correct 388 ms 19620 KB Output is correct
24 Correct 401 ms 19484 KB Output is correct
25 Correct 433 ms 19580 KB Output is correct
26 Correct 443 ms 19620 KB Output is correct
27 Correct 369 ms 19756 KB Output is correct
28 Correct 390 ms 19556 KB Output is correct
29 Correct 414 ms 19772 KB Output is correct
30 Correct 357 ms 19520 KB Output is correct
31 Correct 387 ms 19568 KB Output is correct
32 Correct 360 ms 19604 KB Output is correct
33 Correct 407 ms 19804 KB Output is correct
34 Correct 432 ms 19460 KB Output is correct
35 Correct 400 ms 19584 KB Output is correct
36 Correct 386 ms 19716 KB Output is correct
37 Correct 340 ms 19720 KB Output is correct
38 Correct 413 ms 19752 KB Output is correct
39 Correct 418 ms 19568 KB Output is correct
40 Correct 413 ms 19932 KB Output is correct
41 Correct 448 ms 19488 KB Output is correct
42 Correct 380 ms 19856 KB Output is correct
43 Correct 530 ms 19880 KB Output is correct
44 Correct 485 ms 19956 KB Output is correct
45 Correct 523 ms 19796 KB Output is correct
46 Correct 584 ms 20268 KB Output is correct
47 Correct 464 ms 19768 KB Output is correct
48 Correct 474 ms 19836 KB Output is correct
49 Correct 512 ms 19752 KB Output is correct
50 Correct 531 ms 19880 KB Output is correct
51 Correct 528 ms 19912 KB Output is correct
52 Correct 531 ms 20144 KB Output is correct
53 Correct 501 ms 19752 KB Output is correct
54 Correct 513 ms 20188 KB Output is correct
55 Correct 493 ms 20052 KB Output is correct
56 Correct 525 ms 20100 KB Output is correct
57 Correct 519 ms 19676 KB Output is correct
58 Correct 502 ms 20064 KB Output is correct
59 Correct 482 ms 19828 KB Output is correct
60 Correct 520 ms 19836 KB Output is correct
61 Correct 482 ms 19892 KB Output is correct
62 Correct 530 ms 19700 KB Output is correct
63 Correct 529 ms 19828 KB Output is correct
64 Execution timed out 1154 ms 16220 KB Time limit exceeded
65 Halted 0 ms 0 KB -