Submission #439640

# Submission time Handle Problem Language Result Execution time Memory
439640 2021-06-30T12:02:21 Z prvocislo Cubeword (CEOI19_cubeword) C++17
100 / 100
499 ms 17664 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int mod = 998244353, abc = 62;
void upd(int &a, const int &b) { 
    a += b;
    if (a >= mod) a -= mod;
}
int mul(const int &a, const int &b) { return (a * 1ll * b) % (ll)mod; }
//                  000 001 010 011 100 101 110 111
const int per[8] = { 24, 12, 12,  4, 12,  6,  4,  1 };
int conv(char c)
{
    if ('a' <= c && c <= 'z') return c - 'a';
    if ('A' <= c && c <= 'Z') return 26 + c - 'A';
    if ('0' <= c && c <= '9') return 26 + 26 + c - '0';
}
int cnt[abc][abc][abc], e[abc][abc], ans = 0;
void solve(const set<string> &v)
{
    memset(cnt, 0, sizeof(cnt)), memset(e, 0, sizeof(e));
    for (const string &i : v) e[conv(i[0])][conv(i.back())]++;
    for (int c1 = 0; c1 < abc; c1++) for (int c2 = c1; c2 < abc; c2++) for (int c3 = c2; c3 < abc; c3++)
        for (int ja = 0; ja < abc; ja++)
            upd(cnt[c1][c2][c3], (e[ja][c1] * 1ll * e[ja][c2] * 1ll * e[ja][c3]) % mod);
    for (int c1 = 0; c1 < abc; c1++) for (int c2 = 0; c2 < abc; c2++) for (int c3 = 0; c3 < abc; c3++)
    {
        vector<int> c = {c1, c2, c3}; sort(c.begin(), c.end());
        cnt[c1][c2][c3] = cnt[c[0]][c[1]][c[2]];
    }
    for (int c1 = 0; c1 < abc; c1++) for (int c2 = c1; c2 < abc; c2++) for (int c3 = c2; c3 < abc; c3++) for (int c4 = c3; c4 < abc; c4++)
    {
        int pr = mul(mul(cnt[c1][c2][c3], cnt[c2][c3][c4]), mul(cnt[c3][c4][c1], cnt[c4][c1][c2]));
        int msk = (c1 == c2) | ((c2 == c3) << 1) | ((c3 == c4) << 2);
        upd(ans, mul(pr, per[msk]));
    } 
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<set<string> > v(11);
    for (int i = 0; i < n; i++)
    {
        string s; cin >> s;
        v[s.size()].insert(s);
        reverse(s.begin(), s.end());
        v[s.size()].insert(s);
    }
    for (int i = 3; i <= 10; i++) if (v[i].size()) solve(v[i]);
    cout << ans << "\n";
    return 0;
}

Compilation message

cubeword.cpp: In function 'int conv(char)':
cubeword.cpp:18:1: warning: control reaches end of non-void function [-Wreturn-type]
   18 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 396 ms 16580 KB Output is correct
2 Correct 413 ms 16580 KB Output is correct
3 Correct 393 ms 16592 KB Output is correct
4 Correct 412 ms 16576 KB Output is correct
5 Correct 369 ms 16588 KB Output is correct
6 Correct 400 ms 16596 KB Output is correct
7 Correct 377 ms 16600 KB Output is correct
8 Correct 382 ms 16592 KB Output is correct
9 Correct 367 ms 16584 KB Output is correct
10 Correct 378 ms 16596 KB Output is correct
11 Correct 368 ms 16696 KB Output is correct
12 Correct 410 ms 16580 KB Output is correct
13 Correct 357 ms 16588 KB Output is correct
14 Correct 394 ms 16592 KB Output is correct
15 Correct 371 ms 16520 KB Output is correct
16 Correct 419 ms 16584 KB Output is correct
17 Correct 384 ms 16576 KB Output is correct
18 Correct 353 ms 16696 KB Output is correct
19 Correct 356 ms 16580 KB Output is correct
20 Correct 384 ms 16708 KB Output is correct
21 Correct 377 ms 16580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 396 ms 16580 KB Output is correct
2 Correct 413 ms 16580 KB Output is correct
3 Correct 393 ms 16592 KB Output is correct
4 Correct 412 ms 16576 KB Output is correct
5 Correct 369 ms 16588 KB Output is correct
6 Correct 400 ms 16596 KB Output is correct
7 Correct 377 ms 16600 KB Output is correct
8 Correct 382 ms 16592 KB Output is correct
9 Correct 367 ms 16584 KB Output is correct
10 Correct 378 ms 16596 KB Output is correct
11 Correct 368 ms 16696 KB Output is correct
12 Correct 410 ms 16580 KB Output is correct
13 Correct 357 ms 16588 KB Output is correct
14 Correct 394 ms 16592 KB Output is correct
15 Correct 371 ms 16520 KB Output is correct
16 Correct 419 ms 16584 KB Output is correct
17 Correct 384 ms 16576 KB Output is correct
18 Correct 353 ms 16696 KB Output is correct
19 Correct 356 ms 16580 KB Output is correct
20 Correct 384 ms 16708 KB Output is correct
21 Correct 377 ms 16580 KB Output is correct
22 Correct 362 ms 17168 KB Output is correct
23 Correct 366 ms 17084 KB Output is correct
24 Correct 358 ms 17220 KB Output is correct
25 Correct 410 ms 17152 KB Output is correct
26 Correct 409 ms 17220 KB Output is correct
27 Correct 383 ms 17220 KB Output is correct
28 Correct 399 ms 17156 KB Output is correct
29 Correct 386 ms 17164 KB Output is correct
30 Correct 356 ms 17152 KB Output is correct
31 Correct 369 ms 17156 KB Output is correct
32 Correct 391 ms 17148 KB Output is correct
33 Correct 375 ms 17152 KB Output is correct
34 Correct 382 ms 17156 KB Output is correct
35 Correct 369 ms 17220 KB Output is correct
36 Correct 376 ms 17128 KB Output is correct
37 Correct 376 ms 17160 KB Output is correct
38 Correct 394 ms 17280 KB Output is correct
39 Correct 391 ms 17168 KB Output is correct
40 Correct 368 ms 17048 KB Output is correct
41 Correct 375 ms 17164 KB Output is correct
42 Correct 383 ms 17244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 396 ms 16580 KB Output is correct
2 Correct 413 ms 16580 KB Output is correct
3 Correct 393 ms 16592 KB Output is correct
4 Correct 412 ms 16576 KB Output is correct
5 Correct 369 ms 16588 KB Output is correct
6 Correct 400 ms 16596 KB Output is correct
7 Correct 377 ms 16600 KB Output is correct
8 Correct 382 ms 16592 KB Output is correct
9 Correct 367 ms 16584 KB Output is correct
10 Correct 378 ms 16596 KB Output is correct
11 Correct 368 ms 16696 KB Output is correct
12 Correct 410 ms 16580 KB Output is correct
13 Correct 357 ms 16588 KB Output is correct
14 Correct 394 ms 16592 KB Output is correct
15 Correct 371 ms 16520 KB Output is correct
16 Correct 419 ms 16584 KB Output is correct
17 Correct 384 ms 16576 KB Output is correct
18 Correct 353 ms 16696 KB Output is correct
19 Correct 356 ms 16580 KB Output is correct
20 Correct 384 ms 16708 KB Output is correct
21 Correct 377 ms 16580 KB Output is correct
22 Correct 362 ms 17168 KB Output is correct
23 Correct 366 ms 17084 KB Output is correct
24 Correct 358 ms 17220 KB Output is correct
25 Correct 410 ms 17152 KB Output is correct
26 Correct 409 ms 17220 KB Output is correct
27 Correct 383 ms 17220 KB Output is correct
28 Correct 399 ms 17156 KB Output is correct
29 Correct 386 ms 17164 KB Output is correct
30 Correct 356 ms 17152 KB Output is correct
31 Correct 369 ms 17156 KB Output is correct
32 Correct 391 ms 17148 KB Output is correct
33 Correct 375 ms 17152 KB Output is correct
34 Correct 382 ms 17156 KB Output is correct
35 Correct 369 ms 17220 KB Output is correct
36 Correct 376 ms 17128 KB Output is correct
37 Correct 376 ms 17160 KB Output is correct
38 Correct 394 ms 17280 KB Output is correct
39 Correct 391 ms 17168 KB Output is correct
40 Correct 368 ms 17048 KB Output is correct
41 Correct 375 ms 17164 KB Output is correct
42 Correct 383 ms 17244 KB Output is correct
43 Correct 357 ms 17348 KB Output is correct
44 Correct 375 ms 17360 KB Output is correct
45 Correct 420 ms 17336 KB Output is correct
46 Correct 398 ms 17244 KB Output is correct
47 Correct 367 ms 17440 KB Output is correct
48 Correct 389 ms 17348 KB Output is correct
49 Correct 394 ms 17472 KB Output is correct
50 Correct 408 ms 17248 KB Output is correct
51 Correct 421 ms 17464 KB Output is correct
52 Correct 376 ms 17348 KB Output is correct
53 Correct 390 ms 17372 KB Output is correct
54 Correct 404 ms 17344 KB Output is correct
55 Correct 366 ms 17256 KB Output is correct
56 Correct 403 ms 17412 KB Output is correct
57 Correct 401 ms 17264 KB Output is correct
58 Correct 411 ms 17424 KB Output is correct
59 Correct 384 ms 17224 KB Output is correct
60 Correct 396 ms 17348 KB Output is correct
61 Correct 402 ms 17240 KB Output is correct
62 Correct 356 ms 17336 KB Output is correct
63 Correct 387 ms 17296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 396 ms 16580 KB Output is correct
2 Correct 413 ms 16580 KB Output is correct
3 Correct 393 ms 16592 KB Output is correct
4 Correct 412 ms 16576 KB Output is correct
5 Correct 369 ms 16588 KB Output is correct
6 Correct 400 ms 16596 KB Output is correct
7 Correct 377 ms 16600 KB Output is correct
8 Correct 382 ms 16592 KB Output is correct
9 Correct 367 ms 16584 KB Output is correct
10 Correct 378 ms 16596 KB Output is correct
11 Correct 368 ms 16696 KB Output is correct
12 Correct 410 ms 16580 KB Output is correct
13 Correct 357 ms 16588 KB Output is correct
14 Correct 394 ms 16592 KB Output is correct
15 Correct 371 ms 16520 KB Output is correct
16 Correct 419 ms 16584 KB Output is correct
17 Correct 384 ms 16576 KB Output is correct
18 Correct 353 ms 16696 KB Output is correct
19 Correct 356 ms 16580 KB Output is correct
20 Correct 384 ms 16708 KB Output is correct
21 Correct 377 ms 16580 KB Output is correct
22 Correct 362 ms 17168 KB Output is correct
23 Correct 366 ms 17084 KB Output is correct
24 Correct 358 ms 17220 KB Output is correct
25 Correct 410 ms 17152 KB Output is correct
26 Correct 409 ms 17220 KB Output is correct
27 Correct 383 ms 17220 KB Output is correct
28 Correct 399 ms 17156 KB Output is correct
29 Correct 386 ms 17164 KB Output is correct
30 Correct 356 ms 17152 KB Output is correct
31 Correct 369 ms 17156 KB Output is correct
32 Correct 391 ms 17148 KB Output is correct
33 Correct 375 ms 17152 KB Output is correct
34 Correct 382 ms 17156 KB Output is correct
35 Correct 369 ms 17220 KB Output is correct
36 Correct 376 ms 17128 KB Output is correct
37 Correct 376 ms 17160 KB Output is correct
38 Correct 394 ms 17280 KB Output is correct
39 Correct 391 ms 17168 KB Output is correct
40 Correct 368 ms 17048 KB Output is correct
41 Correct 375 ms 17164 KB Output is correct
42 Correct 383 ms 17244 KB Output is correct
43 Correct 357 ms 17348 KB Output is correct
44 Correct 375 ms 17360 KB Output is correct
45 Correct 420 ms 17336 KB Output is correct
46 Correct 398 ms 17244 KB Output is correct
47 Correct 367 ms 17440 KB Output is correct
48 Correct 389 ms 17348 KB Output is correct
49 Correct 394 ms 17472 KB Output is correct
50 Correct 408 ms 17248 KB Output is correct
51 Correct 421 ms 17464 KB Output is correct
52 Correct 376 ms 17348 KB Output is correct
53 Correct 390 ms 17372 KB Output is correct
54 Correct 404 ms 17344 KB Output is correct
55 Correct 366 ms 17256 KB Output is correct
56 Correct 403 ms 17412 KB Output is correct
57 Correct 401 ms 17264 KB Output is correct
58 Correct 411 ms 17424 KB Output is correct
59 Correct 384 ms 17224 KB Output is correct
60 Correct 396 ms 17348 KB Output is correct
61 Correct 402 ms 17240 KB Output is correct
62 Correct 356 ms 17336 KB Output is correct
63 Correct 387 ms 17296 KB Output is correct
64 Correct 383 ms 17536 KB Output is correct
65 Correct 466 ms 17476 KB Output is correct
66 Correct 370 ms 17476 KB Output is correct
67 Correct 390 ms 17640 KB Output is correct
68 Correct 431 ms 17476 KB Output is correct
69 Correct 407 ms 17516 KB Output is correct
70 Correct 413 ms 17476 KB Output is correct
71 Correct 386 ms 17664 KB Output is correct
72 Correct 373 ms 17536 KB Output is correct
73 Correct 359 ms 17572 KB Output is correct
74 Correct 434 ms 17572 KB Output is correct
75 Correct 463 ms 17572 KB Output is correct
76 Correct 499 ms 17572 KB Output is correct
77 Correct 479 ms 17640 KB Output is correct
78 Correct 360 ms 17576 KB Output is correct
79 Correct 399 ms 17564 KB Output is correct
80 Correct 386 ms 17580 KB Output is correct
81 Correct 378 ms 17536 KB Output is correct
82 Correct 405 ms 17564 KB Output is correct
83 Correct 434 ms 17576 KB Output is correct
84 Correct 394 ms 17480 KB Output is correct