Submission #64856282
Source Code Expand
Copy
#include <stdio.h>#define MOD_BY 6165748424457383623ULL#define MULT 556365909070653953ULLtypedef unsigned long long ull;ull add(ull a, ull b) {return a + b - MOD_BY * (a + b >= MOD_BY);}ull sub(ull a, ull b) {return b == 0 ? a : add(a, MOD_BY - b);}ull mul(ull a, ull b) {ull r = 0;while (b > 0) {if (b & 1) r = add(r, a);a = add(a, a);b >>= 1;
#include <stdio.h>
#define MOD_BY 6165748424457383623ULL
#define MULT 556365909070653953ULL
typedef unsigned long long ull;
ull add(ull a, ull b) {
return a + b - MOD_BY * (a + b >= MOD_BY);
}
ull sub(ull a, ull b) {
return b == 0 ? a : add(a, MOD_BY - b);
}
ull mul(ull a, ull b) {
ull r = 0;
while (b > 0) {
if (b & 1) r = add(r, a);
a = add(a, a);
b >>= 1;
}
return r;
}
ull pou(ull a, ull b) {
ull r = 1;
while (b > 0) {
if (b & 1) r = mul(r, a);
a = mul(a, a);
b >>= 1;
}
return r;
}
ull inv(ull a) {
return pou(a, MOD_BY - 2);
}
char S[512345];
ull from_left[512345], from_left_sum[512345];
ull from_right[512345], from_right_sum[512345];
ull mult_pow[512345], inv_mult_pow[512345];
int main(void) {
int len, i;
if (scanf("%512344s", S) != 1) return 1;
mult_pow[0] = 1;
mult_pow[1] = MULT;
inv_mult_pow[0] = 1;
inv_mult_pow[1] = inv(MULT);
for (i = 0; S[i] != '\0'; i++) {
if (i > 1) {
mult_pow[i] = mul(mult_pow[i - 1], MULT);
inv_mult_pow[i] = mul(inv_mult_pow[i - 1], inv_mult_pow[1]);
}
from_left[i] = mul(S[i], mult_pow[i]);
if (i > 0) {
from_left_sum[i] = add(from_left_sum[i - 1], from_left[i]);
} else {
from_left_sum[i] = from_left[i];
}
}
len = i;
for (i = len - 1; i >= 0; i--) {
from_right[i] = mul(S[i], mult_pow[len - 1 - i]);
from_right_sum[i] = add(from_right_sum[i + 1], from_right[i]);
}
for (i = len; i > 0; i--) {
ull lhash = mul(sub(from_left_sum[len - 1], i < len ? from_left_sum[len - 1 - i] : 0), inv_mult_pow[len - i]);
if (lhash == from_right_sum[len - i]) {
/* 右の部分が回文 → あとは残り (左) をひっくり返してくっつければおk */
int j;
fputs(S, stdout);
for (j = len - i - 1; j >= 0; j--) {
putchar(S[j]);
}
putchar('\n');
return 0;
}
}
puts("ERROR!!!!!");
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | F - ABCBA |
| User | mikecat |
| Language | C (gcc 12.2.0) |
| Score | 500 |
| Code Size | 1928 Byte |
| Status | AC |
| Exec Time | 441 ms |
| Memory | 25596 KB |
Judge Result
| Set Name | Sample | All | after_contest | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | 0 / 0 | ||||||
| Status |
|
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | sample_01.txt, sample_02.txt, sample_03.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt |
| after_contest | after_contest_01.txt, after_contest_02.txt, after_contest_03.txt, after_contest_04.txt, after_contest_05.txt, after_contest_06.txt, after_contest_07.txt, after_contest_08.txt, after_contest_09.txt, after_contest_10.txt, after_contest_11.txt, after_contest_12.txt, after_contest_13.txt, after_contest_14.txt, after_contest_15.txt, after_contest_16.txt, after_contest_17.txt, after_contest_18.txt, after_contest_19.txt, after_contest_20.txt, after_contest_21.txt, after_contest_22.txt, after_contest_23.txt, after_contest_24.txt, after_contest_25.txt, after_contest_26.txt, after_contest_27.txt, after_contest_28.txt, after_contest_29.txt, after_contest_30.txt, after_contest_31.txt, after_contest_32.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| after_contest_01.txt | AC | 315 ms | 25528 KB |
| after_contest_02.txt | AC | 317 ms | 25568 KB |
| after_contest_03.txt | AC | 440 ms | 25552 KB |
| after_contest_04.txt | AC | 440 ms | 25444 KB |
| after_contest_05.txt | AC | 317 ms | 25564 KB |
| after_contest_06.txt | AC | 317 ms | 25460 KB |
| after_contest_07.txt | AC | 441 ms | 25560 KB |
| after_contest_08.txt | AC | 440 ms | 25552 KB |
| after_contest_09.txt | AC | 331 ms | 25456 KB |
| after_contest_10.txt | AC | 346 ms | 25456 KB |
| after_contest_11.txt | AC | 317 ms | 25540 KB |
| after_contest_12.txt | AC | 317 ms | 25532 KB |
| after_contest_13.txt | AC | 317 ms | 25536 KB |
| after_contest_14.txt | AC | 317 ms | 25560 KB |
| after_contest_15.txt | AC | 440 ms | 25444 KB |
| after_contest_16.txt | AC | 440 ms | 25532 KB |
| after_contest_17.txt | AC | 317 ms | 25460 KB |
| after_contest_18.txt | AC | 317 ms | 25540 KB |
| after_contest_19.txt | AC | 440 ms | 25596 KB |
| after_contest_20.txt | AC | 440 ms | 25548 KB |
| after_contest_21.txt | AC | 346 ms | 25524 KB |
| after_contest_22.txt | AC | 354 ms | 25464 KB |
| after_contest_23.txt | AC | 317 ms | 25480 KB |
| after_contest_24.txt | AC | 318 ms | 25540 KB |
| after_contest_25.txt | AC | 378 ms | 25460 KB |
| after_contest_26.txt | AC | 378 ms | 25456 KB |
| after_contest_27.txt | AC | 378 ms | 25532 KB |
| after_contest_28.txt | AC | 378 ms | 25596 KB |
| after_contest_29.txt | AC | 378 ms | 25460 KB |
| after_contest_30.txt | AC | 378 ms | 25532 KB |
| after_contest_31.txt | AC | 378 ms | 25504 KB |
| after_contest_32.txt | AC | 378 ms | 25520 KB |
| sample_01.txt | AC | 1 ms | 1644 KB |
| sample_02.txt | AC | 0 ms | 1612 KB |
| sample_03.txt | AC | 0 ms | 1600 KB |
| test_01.txt | AC | 0 ms | 1548 KB |
| test_02.txt | AC | 0 ms | 1608 KB |
| test_03.txt | AC | 1 ms | 1628 KB |
| test_04.txt | AC | 0 ms | 1640 KB |
| test_05.txt | AC | 0 ms | 1540 KB |
| test_06.txt | AC | 0 ms | 1544 KB |
| test_07.txt | AC | 0 ms | 1624 KB |
| test_08.txt | AC | 0 ms | 1632 KB |
| test_09.txt | AC | 1 ms | 1628 KB |
| test_10.txt | AC | 441 ms | 25536 KB |
| test_11.txt | AC | 440 ms | 25592 KB |
| test_12.txt | AC | 440 ms | 25536 KB |
| test_13.txt | AC | 440 ms | 25440 KB |
| test_14.txt | AC | 374 ms | 25596 KB |
| test_15.txt | AC | 317 ms | 25528 KB |
| test_16.txt | AC | 440 ms | 25460 KB |
| test_17.txt | AC | 339 ms | 25556 KB |
| test_18.txt | AC | 361 ms | 25540 KB |
| test_19.txt | AC | 327 ms | 25552 KB |
| test_20.txt | AC | 316 ms | 25464 KB |
| test_21.txt | AC | 441 ms | 25536 KB |
| test_22.txt | AC | 387 ms | 25388 KB |
| test_23.txt | AC | 396 ms | 25448 KB |
| test_24.txt | AC | 393 ms | 25528 KB |
| test_25.txt | AC | 316 ms | 25460 KB |
| test_26.txt | AC | 440 ms | 25516 KB |
| test_27.txt | AC | 433 ms | 25460 KB |
| test_28.txt | AC | 385 ms | 25388 KB |
| test_29.txt | AC | 419 ms | 25540 KB |
| test_30.txt | AC | 316 ms | 25556 KB |
| test_31.txt | AC | 439 ms | 25548 KB |
| test_32.txt | AC | 423 ms | 25552 KB |
| test_33.txt | AC | 422 ms | 25556 KB |