Submission #917058

# Submission time Handle Problem Language Result Execution time Memory
917058 2024-01-27T05:14:58 Z sleepntsheep Three Friends (BOI14_friends) C++17
0 / 100
396 ms 145228 KB
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include <complex>

using u32 = unsigned;
using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

using namespace std;
using pt = complex<f80>;
#define ALL(x) begin(x), end(x)
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 2000005

string u;
int n;


i64 bpowc(i64 a, i64 b, i64 m)
{
    if (!b) return 1;
    i64 r = bpowc(a, b>>1, m);
    if (b&1) return r*r%m*a%m;
    return r*r%m;
}

constexpr array<i64, 2> Hash[] = {{137, 1000000007}, {203, 1000000009}, {109, 969414643}};
constexpr int HH = sizeof Hash / sizeof Hash[0];

i64 a[HH][N], bp[HH][N], ibp[HH][N], ib[HH];


int main()
{
    ShinLena;
    cin >> n >> u;
    u = " " + u;

    for (int h = 0; h < HH; ++h)
    {
        bp[h][0] = 1;
        for (int i = 1; i <= n + 1; ++i) bp[h][i] = bp[h][i-1] * Hash[h][0] % Hash[h][1];
        ib[h] = bpowc(Hash[h][0], Hash[h][1] - 2, Hash[h][1]);
        for (int i = n; i >= 1; --i) ibp[h][i] = bp[h][i+1] * ib[h] % Hash[h][1];

        for (int i = 1; i <= n; ++i)
            a[h][i] = (a[h][i-1] + (u[i] - 'A') * bp[h][i-1] % Hash[h][1]) % Hash[h][1];
    }


    set<array<i64, HH>> S;
    int at = 0;
    for (int i = 1; i <= n; ++i)
    {
        int eq = 0;
        array<i64, HH> ah{};
        if (i > n / 2)
        {
            for (int h = 0; h < HH; ++h)
            {
                i64 fst = a[h][n/2];
                i64 lst = (a[h][i-1] - a[h][n/2] + Hash[h][1]) % Hash[h][1];
                lst = (lst + (a[h][n] - a[h][i] + Hash[h][1]) % Hash[h][1] * ib[h] % Hash[h][1]) % Hash[h][1];
                fst = fst * bp[h][n/2] % Hash[h][1];
                ah[h] = lst * ibp[h][n/2] % Hash[h][1];
                if (fst == lst) ++eq;
            }
            if (eq == HH) S.insert(ah), at = i;
        }
        else
        {
            for (int h = 0; h < HH; ++h)
            {
                i64 fst = (a[h][i-1] + (a[h][n/2+1] - a[h][i] + Hash[h][1]) % Hash[h][1]
                        * ib[h] % Hash[h][1]) % Hash[h][1];
                i64 lst = (a[h][n] - a[h][n/2+1] + Hash[h][1]) % Hash[h][1];
                fst = fst * bp[h][n/2+1] % Hash[h][1];

                ah[h] = lst * ibp[h][n/2+1] % Hash[h][1];
                if (fst == lst) ++eq;
            }
            if (eq == HH) S.insert(ah), at = i;
        }
    }

    if (S.empty())
    {
        cout << "NOT POSSIBLE";
    }
    else if (S.size() > 1)
    {
        cout << "NOT UNIQUE";
    }
    else
    {
        u.erase(u.begin() + at);
        cout << u.substr(1, n/2);
    }

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 2 ms 10588 KB Output is correct
2 Correct 2 ms 10588 KB Output is correct
3 Correct 2 ms 10588 KB Output is correct
4 Correct 2 ms 10584 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 2 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 3 ms 10584 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 2 ms 10584 KB Output is correct
17 Correct 2 ms 10584 KB Output is correct
18 Correct 2 ms 10588 KB Output is correct
19 Correct 2 ms 10588 KB Output is correct
20 Correct 2 ms 10588 KB Output is correct
21 Correct 2 ms 10584 KB Output is correct
22 Correct 2 ms 10840 KB Output is correct
23 Correct 2 ms 10588 KB Output is correct
24 Incorrect 2 ms 10596 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 395 ms 145224 KB Output is correct
2 Correct 396 ms 145220 KB Output is correct
3 Correct 393 ms 145060 KB Output is correct
4 Correct 395 ms 145224 KB Output is correct
5 Correct 395 ms 145228 KB Output is correct
6 Incorrect 318 ms 145224 KB Output isn't correct
7 Halted 0 ms 0 KB -