Submission #674884

# Submission time Handle Problem Language Result Execution time Memory
674884 2022-12-26T12:47:00 Z finn__ Osmosmjerka (COCI17_osmosmjerka) C++17
80 / 160
4000 ms 83336 KB
#include <bits/stdc++.h>
using namespace std;

#define MOD ((1ULL << 61) - 1)
#define BASE 1000000009

vector<__uint128_t> p;
map<uint64_t, size_t> c;

void check_str(string const &s, size_t k, size_t n)
{
    vector<vector<uint64_t>> t(32, vector<uint64_t>(s.size()));
    for (size_t i = 0; i < s.size(); i++)
        t[0][i] = s[i];

    __uint128_t m = BASE;
    for (size_t i = 1; i < 32; i++)
    {
        for (size_t j = 0; j < s.size(); j++)
            t[i][j] = (t[i - 1][j] * m + t[i - 1][(j + (1 << (i - 1))) % s.size()]) % MOD;
        m = (m * m) % MOD;
    }

    for (size_t i = 0; i < n; i++)
    {
        __uint128_t m = BASE, h = 0;
        size_t j = i;
        for (size_t z = 0; z < 32; z++)
        {
            if (k & (1 << z))
            {
                h = (h * m + t[z][j]) % MOD;
                j = (j + (1 << z)) % s.size();
            }
            m = (m * m) % MOD;
        }
        c[h]++;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    size_t n, m, k;
    cin >> n >> m >> k;

    vector<string> y(n);
    for (string &s : y)
        cin >> s;

    p = vector<__uint128_t>(n + m);
    p[0] = 1;
    for (size_t i = 1; i < p.size(); i++)
        p[i] = (p[i - 1] * BASE) % MOD;

    for (size_t i = 0; i < n; i++)
    {
        check_str(y[i], k, m);
        reverse(y[i].begin(), y[i].end());
        check_str(y[i], k, m);
        reverse(y[i].begin(), y[i].end());
    }

    for (size_t j = 0; j < m; j++)
    {
        string s;
        for (size_t i = 0; i < n; i++)
            s.push_back(y[i][j]);
        check_str(s, k, n);
        reverse(s.begin(), s.end());
        check_str(s, k, n);
    }

    for (size_t i = 0; i < max(n, m); i++)
    {
        string s;
        for (size_t j = 0; j < n * m; j++)
            s.push_back(y[(i + j) % n][j % m]);
        check_str(s, k, max(n, m));
        reverse(s.begin(), s.end());
        check_str(s, k, max(n, m));
    }

    for (size_t i = 0; i < max(n, m); i++)
    {
        string s;
        for (size_t j = 0; j < n * m; j++)
            s.push_back(y[(i - j + n * m) % n][j % m]);
        check_str(s, k, max(n, m));
        reverse(s.begin(), s.end());
        check_str(s, k, max(n, m));
    }

    uint64_t total = 0, all_pos = n * m * 8 * n * m * 8;
    for (auto const [h, x] : c)
        total += x * x;

    cout << total / __gcd(total, all_pos) << '/' << all_pos / __gcd(total, all_pos) << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 340 KB Output is correct
4 Correct 23 ms 468 KB Output is correct
5 Correct 179 ms 872 KB Output is correct
6 Incorrect 2232 ms 5208 KB Output isn't correct
7 Execution timed out 4082 ms 21896 KB Time limit exceeded
8 Execution timed out 4075 ms 83336 KB Time limit exceeded