Submission #223582

# Submission time Handle Problem Language Result Execution time Memory
223582 2020-04-15T14:01:40 Z CaroLinda Cubeword (CEOI19_cubeword) C++14
100 / 100
578 ms 26248 KB
#include <bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define lp(i,a,b) for(int i = a ; i < b ; i++)
#define pii pair<int,int>
#define pb push_back
#define mk make_pair
#define ll long long
#define ff first
#define ss second
#define debug printf

const int MAXN = 1e5+10 ;
const int MAX = 64 ;
const int MOD =  998244353 ;

using namespace std ;

int N ;
ll resp ;
ll dp[MAX][MAX][MAX] ;
ll fat[10] ;
string aux ;
vector<string> str[ 15 ] ;
int code[200] ;
int mat[MAX][MAX] ;
set<string> S ;

ll perm(int a , int b, int c, int d)
{

    int s[4] = {a,b,c,d} ;

    ll tot = 24LL ;

    int last = 0 ;

    for(int i = 1 ; i < 4 ; i++ )
    {
        if( s[i] == s[i-1] ) continue ;
        tot /= fat[( i - last )] ;
        last = i ;
    }

    tot /= fat[(4-last)] ;

    return tot ;

}

inline void calculate( vector<string> v )
{

    lp(i,0,62)
        lp(j,0,62) mat[i][j] = 0 ;

    for(auto s : v )
    {
        int x = code[s[0]] ;
        int y = code[ s[ s.size()-1 ] ] ;

        mat[x][y] ++ ;
    }

    for(int i = 0 ; i < 62 ; i++ )
        for(int j = i ; j < 62 ; j++ )
            for(int g = j ; g < 62 ; g++ )
            {
                dp[i][j][g] = 0LL ;

                for(int k = 0 ; k < 62 ; k++ )
                {
                    ll to_add = ( 1LL*mat[i][k] * mat[j][k] ) % MOD ;
                    to_add *= 1LL*mat[g][k] ;
                    to_add %= MOD ;

                    dp[i][j][g] += to_add ;
                    dp[i][j][g] %= MOD ;

                }

                dp[i][g][j] = dp[j][i][g] = dp[j][g][i] = dp[g][i][j] = dp[g][j][i] = dp[i][j][g] ;

            }

    for(int a = 0 ;a < 62 ; a  ++ )
        for(int b = a ; b < 62 ; b++ )
            for(int c = b ; c < 62 ; c++ )
                for(int d = c ; d < 62 ; d++ )
                {
                    ll to_add = 1LL*dp[a][b][c]*dp[a][b][d] ;
                    to_add %= MOD ;

                    to_add *= (1LL*dp[b][c][d]*dp[a][c][d])%MOD ;
                    to_add %= MOD ;

                    to_add *= perm(a,b,c,d) ;
                    to_add %= MOD ;

                    resp += to_add ;
                    resp %= MOD ;

                }

}

int main()
{

    lp(i,0,26) code[ i + 'A' ] = i ;
    lp(i,0,26) code[ i + 'a' ] = i+26 ;
    lp(i,0,10) code[i+'0'] = i + 52 ;
    fat[0] = 1 ;
    for(int i = 1 ; i < 10 ; i++ ) fat[i] = i*fat[i-1] ;

    scanf("%d", &N ) ;
    for(int i = 1 , tam , x , y ;i <= N ; i++ )
    {
        cin >> aux ;
        S.insert(aux) ;
        reverse(all(aux)) ;
        S.insert(aux) ;
    }

    for(auto s : S) str[ s.size() ].pb(s) ;

    lp(i,3,11) calculate( str[i]) ;

    printf("%lld\n" , resp ) ;

}

Compilation message

cubeword.cpp: In function 'void calculate(std::vector<std::__cxx11::basic_string<char> >)':
cubeword.cpp:59:26: warning: array subscript has type 'char' [-Wchar-subscripts]
         int x = code[s[0]] ;
                          ^
cubeword.cpp:60:39: warning: array subscript has type 'char' [-Wchar-subscripts]
         int y = code[ s[ s.size()-1 ] ] ;
                                       ^
cubeword.cpp: In function 'int main()':
cubeword.cpp:117:21: warning: unused variable 'tam' [-Wunused-variable]
     for(int i = 1 , tam , x , y ;i <= N ; i++ )
                     ^~~
cubeword.cpp:117:27: warning: unused variable 'x' [-Wunused-variable]
     for(int i = 1 , tam , x , y ;i <= N ; i++ )
                           ^
cubeword.cpp:117:31: warning: unused variable 'y' [-Wunused-variable]
     for(int i = 1 , tam , x , y ;i <= N ; i++ )
                               ^
cubeword.cpp:116:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N ) ;
     ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 533 ms 25916 KB Output is correct
2 Correct 528 ms 25720 KB Output is correct
3 Correct 552 ms 25760 KB Output is correct
4 Correct 533 ms 25696 KB Output is correct
5 Correct 539 ms 25820 KB Output is correct
6 Correct 542 ms 25816 KB Output is correct
7 Correct 553 ms 25684 KB Output is correct
8 Correct 539 ms 25748 KB Output is correct
9 Correct 543 ms 25772 KB Output is correct
10 Correct 533 ms 25624 KB Output is correct
11 Correct 532 ms 25944 KB Output is correct
12 Correct 551 ms 25748 KB Output is correct
13 Correct 578 ms 25704 KB Output is correct
14 Correct 532 ms 25712 KB Output is correct
15 Correct 534 ms 25800 KB Output is correct
16 Correct 540 ms 25696 KB Output is correct
17 Correct 534 ms 25772 KB Output is correct
18 Correct 539 ms 25728 KB Output is correct
19 Correct 533 ms 25636 KB Output is correct
20 Correct 542 ms 25968 KB Output is correct
21 Correct 529 ms 25828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 533 ms 25916 KB Output is correct
2 Correct 528 ms 25720 KB Output is correct
3 Correct 552 ms 25760 KB Output is correct
4 Correct 533 ms 25696 KB Output is correct
5 Correct 539 ms 25820 KB Output is correct
6 Correct 542 ms 25816 KB Output is correct
7 Correct 553 ms 25684 KB Output is correct
8 Correct 539 ms 25748 KB Output is correct
9 Correct 543 ms 25772 KB Output is correct
10 Correct 533 ms 25624 KB Output is correct
11 Correct 532 ms 25944 KB Output is correct
12 Correct 551 ms 25748 KB Output is correct
13 Correct 578 ms 25704 KB Output is correct
14 Correct 532 ms 25712 KB Output is correct
15 Correct 534 ms 25800 KB Output is correct
16 Correct 540 ms 25696 KB Output is correct
17 Correct 534 ms 25772 KB Output is correct
18 Correct 539 ms 25728 KB Output is correct
19 Correct 533 ms 25636 KB Output is correct
20 Correct 542 ms 25968 KB Output is correct
21 Correct 529 ms 25828 KB Output is correct
22 Correct 528 ms 25624 KB Output is correct
23 Correct 540 ms 25316 KB Output is correct
24 Correct 542 ms 25560 KB Output is correct
25 Correct 539 ms 25360 KB Output is correct
26 Correct 539 ms 25444 KB Output is correct
27 Correct 529 ms 25420 KB Output is correct
28 Correct 532 ms 25608 KB Output is correct
29 Correct 527 ms 25492 KB Output is correct
30 Correct 528 ms 25376 KB Output is correct
31 Correct 527 ms 25408 KB Output is correct
32 Correct 532 ms 25576 KB Output is correct
33 Correct 529 ms 25428 KB Output is correct
34 Correct 530 ms 25544 KB Output is correct
35 Correct 529 ms 25636 KB Output is correct
36 Correct 526 ms 25404 KB Output is correct
37 Correct 528 ms 25584 KB Output is correct
38 Correct 537 ms 25452 KB Output is correct
39 Correct 524 ms 25532 KB Output is correct
40 Correct 540 ms 25568 KB Output is correct
41 Correct 531 ms 25520 KB Output is correct
42 Correct 538 ms 25368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 533 ms 25916 KB Output is correct
2 Correct 528 ms 25720 KB Output is correct
3 Correct 552 ms 25760 KB Output is correct
4 Correct 533 ms 25696 KB Output is correct
5 Correct 539 ms 25820 KB Output is correct
6 Correct 542 ms 25816 KB Output is correct
7 Correct 553 ms 25684 KB Output is correct
8 Correct 539 ms 25748 KB Output is correct
9 Correct 543 ms 25772 KB Output is correct
10 Correct 533 ms 25624 KB Output is correct
11 Correct 532 ms 25944 KB Output is correct
12 Correct 551 ms 25748 KB Output is correct
13 Correct 578 ms 25704 KB Output is correct
14 Correct 532 ms 25712 KB Output is correct
15 Correct 534 ms 25800 KB Output is correct
16 Correct 540 ms 25696 KB Output is correct
17 Correct 534 ms 25772 KB Output is correct
18 Correct 539 ms 25728 KB Output is correct
19 Correct 533 ms 25636 KB Output is correct
20 Correct 542 ms 25968 KB Output is correct
21 Correct 529 ms 25828 KB Output is correct
22 Correct 528 ms 25624 KB Output is correct
23 Correct 540 ms 25316 KB Output is correct
24 Correct 542 ms 25560 KB Output is correct
25 Correct 539 ms 25360 KB Output is correct
26 Correct 539 ms 25444 KB Output is correct
27 Correct 529 ms 25420 KB Output is correct
28 Correct 532 ms 25608 KB Output is correct
29 Correct 527 ms 25492 KB Output is correct
30 Correct 528 ms 25376 KB Output is correct
31 Correct 527 ms 25408 KB Output is correct
32 Correct 532 ms 25576 KB Output is correct
33 Correct 529 ms 25428 KB Output is correct
34 Correct 530 ms 25544 KB Output is correct
35 Correct 529 ms 25636 KB Output is correct
36 Correct 526 ms 25404 KB Output is correct
37 Correct 528 ms 25584 KB Output is correct
38 Correct 537 ms 25452 KB Output is correct
39 Correct 524 ms 25532 KB Output is correct
40 Correct 540 ms 25568 KB Output is correct
41 Correct 531 ms 25520 KB Output is correct
42 Correct 538 ms 25368 KB Output is correct
43 Correct 516 ms 25512 KB Output is correct
44 Correct 516 ms 25608 KB Output is correct
45 Correct 517 ms 25588 KB Output is correct
46 Correct 510 ms 25892 KB Output is correct
47 Correct 507 ms 25792 KB Output is correct
48 Correct 530 ms 25736 KB Output is correct
49 Correct 517 ms 25548 KB Output is correct
50 Correct 552 ms 25444 KB Output is correct
51 Correct 535 ms 25928 KB Output is correct
52 Correct 519 ms 25848 KB Output is correct
53 Correct 524 ms 25796 KB Output is correct
54 Correct 524 ms 25720 KB Output is correct
55 Correct 508 ms 25564 KB Output is correct
56 Correct 504 ms 25836 KB Output is correct
57 Correct 515 ms 26024 KB Output is correct
58 Correct 506 ms 25800 KB Output is correct
59 Correct 512 ms 25572 KB Output is correct
60 Correct 516 ms 25676 KB Output is correct
61 Correct 515 ms 25816 KB Output is correct
62 Correct 524 ms 26028 KB Output is correct
63 Correct 520 ms 25544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 533 ms 25916 KB Output is correct
2 Correct 528 ms 25720 KB Output is correct
3 Correct 552 ms 25760 KB Output is correct
4 Correct 533 ms 25696 KB Output is correct
5 Correct 539 ms 25820 KB Output is correct
6 Correct 542 ms 25816 KB Output is correct
7 Correct 553 ms 25684 KB Output is correct
8 Correct 539 ms 25748 KB Output is correct
9 Correct 543 ms 25772 KB Output is correct
10 Correct 533 ms 25624 KB Output is correct
11 Correct 532 ms 25944 KB Output is correct
12 Correct 551 ms 25748 KB Output is correct
13 Correct 578 ms 25704 KB Output is correct
14 Correct 532 ms 25712 KB Output is correct
15 Correct 534 ms 25800 KB Output is correct
16 Correct 540 ms 25696 KB Output is correct
17 Correct 534 ms 25772 KB Output is correct
18 Correct 539 ms 25728 KB Output is correct
19 Correct 533 ms 25636 KB Output is correct
20 Correct 542 ms 25968 KB Output is correct
21 Correct 529 ms 25828 KB Output is correct
22 Correct 528 ms 25624 KB Output is correct
23 Correct 540 ms 25316 KB Output is correct
24 Correct 542 ms 25560 KB Output is correct
25 Correct 539 ms 25360 KB Output is correct
26 Correct 539 ms 25444 KB Output is correct
27 Correct 529 ms 25420 KB Output is correct
28 Correct 532 ms 25608 KB Output is correct
29 Correct 527 ms 25492 KB Output is correct
30 Correct 528 ms 25376 KB Output is correct
31 Correct 527 ms 25408 KB Output is correct
32 Correct 532 ms 25576 KB Output is correct
33 Correct 529 ms 25428 KB Output is correct
34 Correct 530 ms 25544 KB Output is correct
35 Correct 529 ms 25636 KB Output is correct
36 Correct 526 ms 25404 KB Output is correct
37 Correct 528 ms 25584 KB Output is correct
38 Correct 537 ms 25452 KB Output is correct
39 Correct 524 ms 25532 KB Output is correct
40 Correct 540 ms 25568 KB Output is correct
41 Correct 531 ms 25520 KB Output is correct
42 Correct 538 ms 25368 KB Output is correct
43 Correct 516 ms 25512 KB Output is correct
44 Correct 516 ms 25608 KB Output is correct
45 Correct 517 ms 25588 KB Output is correct
46 Correct 510 ms 25892 KB Output is correct
47 Correct 507 ms 25792 KB Output is correct
48 Correct 530 ms 25736 KB Output is correct
49 Correct 517 ms 25548 KB Output is correct
50 Correct 552 ms 25444 KB Output is correct
51 Correct 535 ms 25928 KB Output is correct
52 Correct 519 ms 25848 KB Output is correct
53 Correct 524 ms 25796 KB Output is correct
54 Correct 524 ms 25720 KB Output is correct
55 Correct 508 ms 25564 KB Output is correct
56 Correct 504 ms 25836 KB Output is correct
57 Correct 515 ms 26024 KB Output is correct
58 Correct 506 ms 25800 KB Output is correct
59 Correct 512 ms 25572 KB Output is correct
60 Correct 516 ms 25676 KB Output is correct
61 Correct 515 ms 25816 KB Output is correct
62 Correct 524 ms 26028 KB Output is correct
63 Correct 520 ms 25544 KB Output is correct
64 Correct 504 ms 25852 KB Output is correct
65 Correct 518 ms 26248 KB Output is correct
66 Correct 508 ms 26104 KB Output is correct
67 Correct 520 ms 26176 KB Output is correct
68 Correct 506 ms 26072 KB Output is correct
69 Correct 509 ms 26124 KB Output is correct
70 Correct 517 ms 26192 KB Output is correct
71 Correct 506 ms 26032 KB Output is correct
72 Correct 510 ms 25968 KB Output is correct
73 Correct 516 ms 25936 KB Output is correct
74 Correct 511 ms 25744 KB Output is correct
75 Correct 515 ms 26164 KB Output is correct
76 Correct 514 ms 26156 KB Output is correct
77 Correct 508 ms 25860 KB Output is correct
78 Correct 524 ms 26240 KB Output is correct
79 Correct 523 ms 26080 KB Output is correct
80 Correct 511 ms 26228 KB Output is correct
81 Correct 523 ms 26192 KB Output is correct
82 Correct 505 ms 25820 KB Output is correct
83 Correct 512 ms 25980 KB Output is correct
84 Correct 529 ms 26048 KB Output is correct