Submission #904801

# Submission time Handle Problem Language Result Execution time Memory
904801 2024-01-12T08:35:03 Z andrei_iorgulescu Cubeword (CEOI19_cubeword) C++14
84 / 100
1100 ms 20260 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 = 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 = 1ll * cost[A][B][C] * cost[A][B][D] % modulo * cost[A][C][D] % modulo * cost[B][C][D] % modulo;
                            ans = (ans + adg) % 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++)
      |                     ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 375 ms 18928 KB Output is correct
2 Correct 335 ms 19060 KB Output is correct
3 Correct 382 ms 18980 KB Output is correct
4 Correct 356 ms 19084 KB Output is correct
5 Correct 406 ms 18864 KB Output is correct
6 Correct 369 ms 18920 KB Output is correct
7 Correct 368 ms 18924 KB Output is correct
8 Correct 329 ms 19064 KB Output is correct
9 Correct 364 ms 19064 KB Output is correct
10 Correct 332 ms 18852 KB Output is correct
11 Correct 383 ms 19188 KB Output is correct
12 Correct 391 ms 19084 KB Output is correct
13 Correct 427 ms 19192 KB Output is correct
14 Correct 347 ms 18880 KB Output is correct
15 Correct 386 ms 18980 KB Output is correct
16 Correct 340 ms 19028 KB Output is correct
17 Correct 353 ms 18976 KB Output is correct
18 Correct 352 ms 18936 KB Output is correct
19 Correct 406 ms 18868 KB Output is correct
20 Correct 392 ms 18852 KB Output is correct
21 Correct 376 ms 18956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 375 ms 18928 KB Output is correct
2 Correct 335 ms 19060 KB Output is correct
3 Correct 382 ms 18980 KB Output is correct
4 Correct 356 ms 19084 KB Output is correct
5 Correct 406 ms 18864 KB Output is correct
6 Correct 369 ms 18920 KB Output is correct
7 Correct 368 ms 18924 KB Output is correct
8 Correct 329 ms 19064 KB Output is correct
9 Correct 364 ms 19064 KB Output is correct
10 Correct 332 ms 18852 KB Output is correct
11 Correct 383 ms 19188 KB Output is correct
12 Correct 391 ms 19084 KB Output is correct
13 Correct 427 ms 19192 KB Output is correct
14 Correct 347 ms 18880 KB Output is correct
15 Correct 386 ms 18980 KB Output is correct
16 Correct 340 ms 19028 KB Output is correct
17 Correct 353 ms 18976 KB Output is correct
18 Correct 352 ms 18936 KB Output is correct
19 Correct 406 ms 18868 KB Output is correct
20 Correct 392 ms 18852 KB Output is correct
21 Correct 376 ms 18956 KB Output is correct
22 Correct 407 ms 19568 KB Output is correct
23 Correct 447 ms 19624 KB Output is correct
24 Correct 394 ms 19552 KB Output is correct
25 Correct 403 ms 19840 KB Output is correct
26 Correct 427 ms 19476 KB Output is correct
27 Correct 452 ms 19476 KB Output is correct
28 Correct 424 ms 19940 KB Output is correct
29 Correct 402 ms 19648 KB Output is correct
30 Correct 414 ms 19596 KB Output is correct
31 Correct 405 ms 19600 KB Output is correct
32 Correct 436 ms 19540 KB Output is correct
33 Correct 385 ms 19548 KB Output is correct
34 Correct 443 ms 19600 KB Output is correct
35 Correct 437 ms 19812 KB Output is correct
36 Correct 379 ms 19552 KB Output is correct
37 Correct 436 ms 19520 KB Output is correct
38 Correct 432 ms 19496 KB Output is correct
39 Correct 448 ms 19564 KB Output is correct
40 Correct 402 ms 19668 KB Output is correct
41 Correct 407 ms 19548 KB Output is correct
42 Correct 435 ms 19892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 375 ms 18928 KB Output is correct
2 Correct 335 ms 19060 KB Output is correct
3 Correct 382 ms 18980 KB Output is correct
4 Correct 356 ms 19084 KB Output is correct
5 Correct 406 ms 18864 KB Output is correct
6 Correct 369 ms 18920 KB Output is correct
7 Correct 368 ms 18924 KB Output is correct
8 Correct 329 ms 19064 KB Output is correct
9 Correct 364 ms 19064 KB Output is correct
10 Correct 332 ms 18852 KB Output is correct
11 Correct 383 ms 19188 KB Output is correct
12 Correct 391 ms 19084 KB Output is correct
13 Correct 427 ms 19192 KB Output is correct
14 Correct 347 ms 18880 KB Output is correct
15 Correct 386 ms 18980 KB Output is correct
16 Correct 340 ms 19028 KB Output is correct
17 Correct 353 ms 18976 KB Output is correct
18 Correct 352 ms 18936 KB Output is correct
19 Correct 406 ms 18868 KB Output is correct
20 Correct 392 ms 18852 KB Output is correct
21 Correct 376 ms 18956 KB Output is correct
22 Correct 407 ms 19568 KB Output is correct
23 Correct 447 ms 19624 KB Output is correct
24 Correct 394 ms 19552 KB Output is correct
25 Correct 403 ms 19840 KB Output is correct
26 Correct 427 ms 19476 KB Output is correct
27 Correct 452 ms 19476 KB Output is correct
28 Correct 424 ms 19940 KB Output is correct
29 Correct 402 ms 19648 KB Output is correct
30 Correct 414 ms 19596 KB Output is correct
31 Correct 405 ms 19600 KB Output is correct
32 Correct 436 ms 19540 KB Output is correct
33 Correct 385 ms 19548 KB Output is correct
34 Correct 443 ms 19600 KB Output is correct
35 Correct 437 ms 19812 KB Output is correct
36 Correct 379 ms 19552 KB Output is correct
37 Correct 436 ms 19520 KB Output is correct
38 Correct 432 ms 19496 KB Output is correct
39 Correct 448 ms 19564 KB Output is correct
40 Correct 402 ms 19668 KB Output is correct
41 Correct 407 ms 19548 KB Output is correct
42 Correct 435 ms 19892 KB Output is correct
43 Correct 528 ms 20260 KB Output is correct
44 Correct 477 ms 19988 KB Output is correct
45 Correct 495 ms 19920 KB Output is correct
46 Correct 516 ms 20016 KB Output is correct
47 Correct 463 ms 19792 KB Output is correct
48 Correct 501 ms 19676 KB Output is correct
49 Correct 493 ms 19864 KB Output is correct
50 Correct 476 ms 19756 KB Output is correct
51 Correct 472 ms 19684 KB Output is correct
52 Correct 497 ms 20000 KB Output is correct
53 Correct 449 ms 19836 KB Output is correct
54 Correct 498 ms 19892 KB Output is correct
55 Correct 483 ms 19752 KB Output is correct
56 Correct 428 ms 19884 KB Output is correct
57 Correct 460 ms 19900 KB Output is correct
58 Correct 474 ms 19912 KB Output is correct
59 Correct 603 ms 19664 KB Output is correct
60 Correct 510 ms 19808 KB Output is correct
61 Correct 497 ms 19820 KB Output is correct
62 Correct 517 ms 19688 KB Output is correct
63 Correct 527 ms 19912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 375 ms 18928 KB Output is correct
2 Correct 335 ms 19060 KB Output is correct
3 Correct 382 ms 18980 KB Output is correct
4 Correct 356 ms 19084 KB Output is correct
5 Correct 406 ms 18864 KB Output is correct
6 Correct 369 ms 18920 KB Output is correct
7 Correct 368 ms 18924 KB Output is correct
8 Correct 329 ms 19064 KB Output is correct
9 Correct 364 ms 19064 KB Output is correct
10 Correct 332 ms 18852 KB Output is correct
11 Correct 383 ms 19188 KB Output is correct
12 Correct 391 ms 19084 KB Output is correct
13 Correct 427 ms 19192 KB Output is correct
14 Correct 347 ms 18880 KB Output is correct
15 Correct 386 ms 18980 KB Output is correct
16 Correct 340 ms 19028 KB Output is correct
17 Correct 353 ms 18976 KB Output is correct
18 Correct 352 ms 18936 KB Output is correct
19 Correct 406 ms 18868 KB Output is correct
20 Correct 392 ms 18852 KB Output is correct
21 Correct 376 ms 18956 KB Output is correct
22 Correct 407 ms 19568 KB Output is correct
23 Correct 447 ms 19624 KB Output is correct
24 Correct 394 ms 19552 KB Output is correct
25 Correct 403 ms 19840 KB Output is correct
26 Correct 427 ms 19476 KB Output is correct
27 Correct 452 ms 19476 KB Output is correct
28 Correct 424 ms 19940 KB Output is correct
29 Correct 402 ms 19648 KB Output is correct
30 Correct 414 ms 19596 KB Output is correct
31 Correct 405 ms 19600 KB Output is correct
32 Correct 436 ms 19540 KB Output is correct
33 Correct 385 ms 19548 KB Output is correct
34 Correct 443 ms 19600 KB Output is correct
35 Correct 437 ms 19812 KB Output is correct
36 Correct 379 ms 19552 KB Output is correct
37 Correct 436 ms 19520 KB Output is correct
38 Correct 432 ms 19496 KB Output is correct
39 Correct 448 ms 19564 KB Output is correct
40 Correct 402 ms 19668 KB Output is correct
41 Correct 407 ms 19548 KB Output is correct
42 Correct 435 ms 19892 KB Output is correct
43 Correct 528 ms 20260 KB Output is correct
44 Correct 477 ms 19988 KB Output is correct
45 Correct 495 ms 19920 KB Output is correct
46 Correct 516 ms 20016 KB Output is correct
47 Correct 463 ms 19792 KB Output is correct
48 Correct 501 ms 19676 KB Output is correct
49 Correct 493 ms 19864 KB Output is correct
50 Correct 476 ms 19756 KB Output is correct
51 Correct 472 ms 19684 KB Output is correct
52 Correct 497 ms 20000 KB Output is correct
53 Correct 449 ms 19836 KB Output is correct
54 Correct 498 ms 19892 KB Output is correct
55 Correct 483 ms 19752 KB Output is correct
56 Correct 428 ms 19884 KB Output is correct
57 Correct 460 ms 19900 KB Output is correct
58 Correct 474 ms 19912 KB Output is correct
59 Correct 603 ms 19664 KB Output is correct
60 Correct 510 ms 19808 KB Output is correct
61 Correct 497 ms 19820 KB Output is correct
62 Correct 517 ms 19688 KB Output is correct
63 Correct 527 ms 19912 KB Output is correct
64 Execution timed out 1108 ms 16128 KB Time limit exceeded
65 Halted 0 ms 0 KB -