답안 #917049

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
917049 2024-01-27T05:03:12 Z sleepntsheep 세 명의 친구들 (BOI14_friends) C++17
0 / 100
63 ms 56144 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 3000005

string u;
int n;

constexpr i64 B = 237, M = 1000000007;

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

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

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

    bp[0] = 1;
    for (int i = 1; i <= n + 1; ++i) bp[i] = bp[i-1] * B % M;
    i64 IB = bpowc(B, M-2);
    for (int i = n; i >= 1; --i) ibp[i] = bp[i+1] * IB % M;

    for (int i = 1; i <= n; ++i)
        a[i] = (a[i-1] + u[i] * bp[i-1] % M) % M;


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

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

    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;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 54124 KB Output is correct
2 Correct 51 ms 56104 KB Output is correct
3 Correct 51 ms 56144 KB Output is correct
4 Correct 53 ms 56136 KB Output is correct
5 Correct 52 ms 56136 KB Output is correct
6 Correct 50 ms 54096 KB Output is correct
7 Incorrect 63 ms 54308 KB Output isn't correct
8 Halted 0 ms 0 KB -