이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
const int N = 2000010;
const int rem_07 = 1e9 + 7;
const int rem_09 = 1e9 + 9;
using namespace std;
int n;
char st[N];
int hsh_07[N], hsh_09[N], deg_27_07[N], deg_27_09[N];
vector <int> ans;
int get_hesh(int l, int r, int rem) {
    if (l > r) return 0;
    int ans;
    if (rem == rem_07)
        ans = ((long long)hsh_07[r] - (long long)hsh_07[l - 1] * deg_27_07[r - l + 1]) % rem;
    else
        ans = ((long long)hsh_09[r] - (long long)hsh_09[l - 1] * deg_27_09[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_07[0] = deg_27_09[0] = 1;
    for (int i = 0; i < n; i++) {
        hsh_07[i + 1] = ((long long) hsh_07[i] * 27 + st[i] - 'A' + 1) % rem_07;
        hsh_09[i + 1] = ((long long) hsh_09[i] * 27 + st[i] - 'A' + 1) % rem_09;
        deg_27_07[i + 1] = ((long long) deg_27_07[i] * 27) % rem_07;
        deg_27_09[i + 1] = ((long long) deg_27_09[i] * 27) % rem_09;
    }
    int a_len = (n - 1) >> 1;
    for (int i = 1; i <= n; i++) {
        int whole_hesh_left_07, whole_hesh_left_09, whole_hesh_right_07, whole_hesh_right_09;
        if (i <= a_len) {
            int remaining = a_len - i + 1;
            int hsh_right_07 = get_hesh(i + 1, i + remaining, rem_07);
            int hsh_right_09 = get_hesh(i + 1, i + remaining, rem_09);
            int hsh_left_07 = hsh_07[i - 1];
            int hsh_left_09 = hsh_09[i - 1];
            whole_hesh_left_07 = ((long long) hsh_left_07 * deg_27_07[remaining] + hsh_right_07) % rem_07;
            whole_hesh_left_09 = ((long long) hsh_left_09 * deg_27_09[remaining] + hsh_right_09) % rem_09;
        } else {
            whole_hesh_left_07 = hsh_07[a_len];
            whole_hesh_left_09 = hsh_09[a_len];
        }
        int l_0 = n - a_len + 1;
        if (i >= l_0) {
            l_0--;
            int remaining = n - i;
            int hsh_right_07 = get_hesh(i + 1, n, rem_07);
            int hsh_right_09 = get_hesh(i + 1, n, rem_09);
            int hsh_left_07 = get_hesh(l_0, i - 1, rem_07);
            int hsh_left_09 = get_hesh(l_0, i - 1, rem_09);
            whole_hesh_right_07 = ((long long) hsh_left_07 * deg_27_07[remaining] + hsh_right_07) % rem_07;
            whole_hesh_right_09 = ((long long) hsh_left_09 * deg_27_09[remaining] + hsh_right_09) % rem_09;
        } else {
            whole_hesh_right_07 = get_hesh(l_0, n, rem_07);
            whole_hesh_right_09 = get_hesh(l_0, n, rem_09);
        }
        if (whole_hesh_left_07 == whole_hesh_right_07 && whole_hesh_left_09 == whole_hesh_right_09) {
            ans.push_back(i - 1);
        }
    }
    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";
    }
}
컴파일 시 표준 에러 (stderr) 메시지
friends.cpp: In function 'int main()':
friends.cpp:28:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %s", &n, st);
                           ^| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |