This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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}, {61, 1000000009}, {31, 969414643},
{281, 969414643}
};
*/
constexpr array<i64, 2> Hash[] = {{137, 1000000007}
};
constexpr int HH = sizeof Hash / sizeof Hash[0];
i64 a[HH][N], bp[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 = 1; i <= n; ++i)
a[h][i] = (a[h][i-1] + (u[i] - 'A' + 2) * 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];
ah[h] = fst;
fst = fst * bp[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];
ah[h] = fst;
fst = fst * bp[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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |