結果

問題 No.765 ukuku 2
ユーザー rickythetarickytheta
提出日時 2018-12-13 00:38:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,682 bytes
コンパイル時間 1,772 ms
コンパイル使用メモリ 162,300 KB
実行使用メモリ 7,120 KB
最終ジャッジ日時 2024-09-25 03:48:07
合計ジャッジ時間 4,874 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,816 KB
testcase_01 AC 4 ms
6,816 KB
testcase_02 AC 4 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 WA -
testcase_12 AC 4 ms
6,940 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 4 ms
6,944 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 4 ms
6,940 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 78 ms
6,944 KB
testcase_31 WA -
testcase_32 AC 79 ms
6,940 KB
testcase_33 AC 61 ms
6,944 KB
testcase_34 AC 62 ms
6,940 KB
testcase_35 AC 121 ms
6,940 KB
testcase_36 WA -
testcase_37 AC 132 ms
7,116 KB
testcase_38 AC 119 ms
6,940 KB
testcase_39 WA -
testcase_40 AC 63 ms
6,944 KB
testcase_41 AC 86 ms
6,944 KB
testcase_42 WA -
testcase_43 AC 83 ms
6,944 KB
testcase_44 AC 74 ms
6,940 KB
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |   scanf("%s",s);
      |   ~~~~~^~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

// const ll B = 10007;
const ll B = 1000;
const ll MOD = 1000000007;
int bpow[252521];

int n;
char s[252521];
char rs[252521];
int hsh[252521], rhsh[252521];

int rhash(int *h, int l, int r){
  // s[l,...,r-1]
  return (h[r] - (ll)h[l]*bpow[r-l]%MOD + MOD) % MOD;
}

int main(){
  scanf("%s",s);
  n = strlen(s);
  REP(i,n)rs[n-1-i] = s[i];
  REP(i,n)hsh[i+1] = ((ll)hsh[i]*B + s[i]) % MOD;
  REP(i,n)rhsh[i+1] = ((ll)rhsh[i]*B + rs[i]) % MOD;
  bpow[0] = 1;
  FOR(i,1,252521)bpow[i] = (ll)bpow[i-1]*B%MOD;

  int ans = 1;
  // center character is s[i]
  REP(i,n){
    // no remove
    int low = 0, high = min(i, n-1-i)+1;
    while(low+1<high){
      int len = (low+high)/2;
      int lefthash = rhash(hsh, i-len, i);
      int righthash = rhash(rhsh, n-1-len-i, n-i-1);
      if(lefthash == righthash){
        low = len;
      }else{
        high = len;
      }
    }
    int clen = low;
    // printf("%d: %d\n",i,clen);
    CHMAX(ans, 2*clen);  // remove center character
    if(2*clen+1 < n)CHMAX(ans, 2*clen+1); // remove other character
    // remove left
    if(i-clen > 0){
      int l = i-clen-1;
      int r = i+clen;
      int low = 0, high = min(l, n-1-r)+1;
      while(low+1<high){
        int len = (low+high)/2;
        int lefthash = rhash(hsh, l-len, l);
        int righthash = rhash(rhsh, n-1-len-r, n-r-1);
        if(lefthash == righthash){
          low = len;
        }else{
          high = len;
        }
      }
      CHMAX(ans, 2*clen+2*low);
    }
    // remove right
    if(i+clen < n-1){
      int l = i-clen;
      int r = i+clen+1;
      int low = 0, high = min(l, n-1-r)+1;
      while(low+1<high){
        int len = (low+high)/2;
        int lefthash = rhash(hsh, l-len, l);
        int righthash = rhash(rhsh, n-1-len-r, n-r-1);
        if(lefthash == righthash){
          low = len;
        }else{
          high = len;
        }
      }
      CHMAX(ans, 2*clen+2*low);
    }
  }
  // center character is s[i], s[i+1]
  REP(i,n-1)if(s[i]==s[i+1]){
    // no remove
    int l = i, r = i+1;
    int low = 0, high = min(l, n-1-r)+1;
    while(low+1<high){
      int len = (low+high)/2;
      int lefthash = rhash(hsh, l-len, l);
      int righthash = rhash(rhsh, n-1-len-r, n-r-1);
      if(lefthash == righthash){
        low = len;
      }else{
        high = len;
      }
    }
    int clen = low;
    CHMAX(ans, 2*clen+1);  // remove center character
    if(2*clen+2 < n)CHMAX(ans, 2*clen+2); // remove other character
    // remove left
    if(i-clen > 0){
      int l = i-clen-1;
      int r = i+1+clen;
      int low = 0, high = min(l, n-1-r)+1;
      while(low+1<high){
        int len = (low+high)/2;
        int lefthash = rhash(hsh, l-len, l);
        int righthash = rhash(rhsh, n-1-len-r, n-r-1);
        if(lefthash == righthash){
          low = len;
        }else{
          high = len;
        }
      }
      CHMAX(ans, 2*clen+2+2*low);
    }
    // remove right
    if(i+1+clen < n-1){
      int l = i-clen;
      int r = i+1+clen+1;
      int low = 0, high = min(l, n-1-r)+1;
      while(low+1<high){
        int len = (low+high)/2;
        int lefthash = rhash(hsh, l-len, l);
        int righthash = rhash(rhsh, n-1-len-r, n-r-1);
        if(lefthash == righthash){
          low = len;
        }else{
          high = len;
        }
      }
      CHMAX(ans, 2*clen+2+2*low);
    }
  }
  printf("%d\n",ans);
  return 0;
}
0