| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 38478 | bakurits | 세 명의 친구들 (BOI14_friends) | C++14 | 99 ms | 22528 KiB | 
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 <stdio.h>
#include <vector>
#include <string>
const int N = 2000010;
const int rem = 1e9 + 7;
using namespace std;
int n;
char st[N];
int hsh[N], deg_27[N];
vector <int> ans;
int get_hesh(int l, int r) {
    if (l > r) return 0;
    int ans = ((long long)hsh[r] - (long long)hsh[l - 1] * deg_27[r - l + 1]) % rem;
    return (ans + rem) % rem;
}
int main() {
    scanf("%d %s", &n, st);
    
    if (!(n & 1)) {
        printf("NOT POSSIBLE\n");
        return 0;
    }   
    deg_27[0] = 1;
    for (int i = 0; i < n; i++) {
        hsh[i + 1] = ((long long)hsh[i] * 27 + st[i] - 'A' + 1) % rem;
        deg_27[i + 1] = ((long long)deg_27[i] * 27) % rem;
    }
    int a_len = (n - 1) >> 1;
    for (int i = 1; i <= n; i++) {
        int whole_hesh_left, whole_hesh_right;
        if (i <= a_len) {
            int remaining = a_len - i + 1;
            int hsh_right = get_hesh(i + 1, i + remaining);
            int hsh_left = hsh[i - 1];
            whole_hesh_left = ((long long)hsh_left * deg_27[remaining] + hsh_right) % rem;
        } else {
            whole_hesh_left = hsh[a_len];
        }
        int l_0 = n - a_len + 1;
        if (i >= l_0) {
            l_0--;
            int remaining = n - i;
            int hsh_right = get_hesh(i + 1, n);
            int hsh_left = get_hesh(l_0, i - 1);
            whole_hesh_right = ((long long)hsh_left * deg_27[remaining] + hsh_right) % rem;
        } else {
            whole_hesh_right = get_hesh(l_0, n);
        }
        if (whole_hesh_left == whole_hesh_right) {
            ans.push_back(i - 1);
        }
       // printf("%d %d \n", whole_hesh_left, whole_hesh_right);
    }
    if (ans.size() > 1) {
        printf("NOT UNIQUE\n");
    } else if (ans.size() == 0) {
        printf("NOT POSSIBLE\n");
    } else {
        int arr = ans[0];
        string res = st;
        res.erase(res.begin() + arr);
        cout << res.substr(0, a_len) << "\n";
    }
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
