結果

問題 No.765 ukuku 2
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-03-25 10:16:19
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 2,388 ms / 3,000 ms
コード長 3,095 bytes
コンパイル時間 696 ms
コンパイル使用メモリ 106,512 KB
実行使用メモリ 13,668 KB
最終ジャッジ日時 2023-09-04 00:00:20
合計ジャッジ時間 39,395 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
6,704 KB
testcase_01 AC 38 ms
6,680 KB
testcase_02 AC 38 ms
6,732 KB
testcase_03 AC 39 ms
6,744 KB
testcase_04 AC 38 ms
7,540 KB
testcase_05 AC 38 ms
6,672 KB
testcase_06 AC 38 ms
7,068 KB
testcase_07 AC 38 ms
6,732 KB
testcase_08 AC 37 ms
6,688 KB
testcase_09 AC 38 ms
6,704 KB
testcase_10 AC 37 ms
6,736 KB
testcase_11 AC 38 ms
6,724 KB
testcase_12 AC 37 ms
6,724 KB
testcase_13 AC 38 ms
6,812 KB
testcase_14 AC 38 ms
6,684 KB
testcase_15 AC 38 ms
7,000 KB
testcase_16 AC 38 ms
6,700 KB
testcase_17 AC 37 ms
6,728 KB
testcase_18 AC 38 ms
6,708 KB
testcase_19 AC 38 ms
7,492 KB
testcase_20 AC 38 ms
7,336 KB
testcase_21 AC 38 ms
6,728 KB
testcase_22 AC 37 ms
6,736 KB
testcase_23 AC 38 ms
7,192 KB
testcase_24 AC 39 ms
6,744 KB
testcase_25 AC 38 ms
6,736 KB
testcase_26 AC 38 ms
6,724 KB
testcase_27 AC 39 ms
6,736 KB
testcase_28 AC 39 ms
6,688 KB
testcase_29 AC 39 ms
6,684 KB
testcase_30 AC 1,541 ms
13,332 KB
testcase_31 AC 1,493 ms
12,780 KB
testcase_32 AC 1,257 ms
12,472 KB
testcase_33 AC 1,407 ms
13,268 KB
testcase_34 AC 1,417 ms
13,308 KB
testcase_35 AC 2,062 ms
13,308 KB
testcase_36 AC 2,075 ms
13,252 KB
testcase_37 AC 2,326 ms
13,304 KB
testcase_38 AC 2,388 ms
13,668 KB
testcase_39 AC 2,324 ms
13,348 KB
testcase_40 AC 1,568 ms
12,720 KB
testcase_41 AC 1,710 ms
12,752 KB
testcase_42 AC 1,823 ms
12,860 KB
testcase_43 AC 1,655 ms
12,452 KB
testcase_44 AC 1,661 ms
12,600 KB
testcase_45 AC 1,897 ms
13,564 KB
testcase_46 AC 1,624 ms
12,464 KB
testcase_47 AC 1,897 ms
12,860 KB
testcase_48 AC 1,846 ms
13,036 KB
testcase_49 AC 1,873 ms
12,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum long[] P = [1000000007, 1000000009];
enum LIM = 2 * 10^^5;

int N;
string S;

void main() {
  auto BASE = new long[P.length];
  BASE[0] = 314159265L;
  foreach (h; 1 .. P.length) {
    BASE[h] = (BASE[h - 1] * 123456789L) % 999999937L;
  }
  auto BB = new long[][](P.length, LIM + 1);
  foreach (h; 0 .. P.length) {
    BB[h][0] = 1;
    foreach (i; 0 .. LIM) {
      BB[h][i + 1] = (BB[h][i] * BASE[h]) % P[h];
    }
  }
  
  try {
    for (; ; ) {
      S = readToken();
      N = cast(int)(S.length);
      auto sum0 = new long[][](P.length, N + 1);
      auto sum1 = new long[][](P.length, N + 1);
      foreach (h; 0 .. P.length) {
        foreach (i; 0 .. N) {
          sum0[h][i + 1] = (sum0[h][i] + S[i] * BB[h][i]) % P[h];
          sum1[h][i + 1] = (sum1[h][i] + S[i] * BB[h][N - i]) % P[h];
        }
      }
      int calc(int l, int r) {
        int lo = 0, hi = min(l + 1, N - r) + 1;
        for (; lo + 1 < hi; ) {
          const mid = (lo + hi) / 2;
          bool ok = true;
          foreach (h; 0 .. P.length) {
            const tmpL = (sum0[h][l + 1] - sum0[h][l + 1 - mid]) * BB[h][N - r];
            const tmpR = (sum1[h][r + mid] - sum1[h][r]) * BB[h][l];
            if ((tmpL - tmpR) % P[h] != 0) {
              ok = false;
              break;
            }
          }
          (ok ? lo : hi) = mid;
        }
        debug {
          writeln("calc ", l, " ", r, " = ", lo);
        }
        return lo;
      }
      int ans;
      foreach (i; 0 .. N) {
        foreach (s; 0 .. 2) {
          if (i + s < N) {
            const int a = calc(i, i + s);
            chmax(ans, 2 * a - 1 + s - 1);
            if (0 <= i - a) {
              chmax(ans, 2 * a - 1 + s + 2 * calc(i - a - 1, i + s + a));
            }
            if (i + s + a < N) {
              chmax(ans, 2 * a - 1 + s + 2 * calc(i - a, i + s + a + 1));
            }
          }
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0