結果

問題 No.2162 Copy and Paste 2
ユーザー 👑 chro_96chro_96
提出日時 2022-12-13 19:35:43
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 473 ms / 7,000 ms
コード長 2,690 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 32,512 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-25 03:59:28
合計ジャッジ時間 7,710 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,464 KB
testcase_01 AC 3 ms
7,516 KB
testcase_02 AC 3 ms
7,364 KB
testcase_03 AC 4 ms
7,544 KB
testcase_04 AC 3 ms
7,552 KB
testcase_05 AC 3 ms
7,552 KB
testcase_06 AC 43 ms
7,424 KB
testcase_07 AC 48 ms
7,500 KB
testcase_08 AC 158 ms
7,448 KB
testcase_09 AC 159 ms
7,476 KB
testcase_10 AC 169 ms
7,488 KB
testcase_11 AC 217 ms
7,504 KB
testcase_12 AC 248 ms
7,492 KB
testcase_13 AC 307 ms
7,480 KB
testcase_14 AC 171 ms
7,516 KB
testcase_15 AC 200 ms
7,456 KB
testcase_16 AC 203 ms
7,352 KB
testcase_17 AC 319 ms
7,536 KB
testcase_18 AC 413 ms
7,444 KB
testcase_19 AC 371 ms
7,448 KB
testcase_20 AC 350 ms
7,544 KB
testcase_21 AC 204 ms
7,356 KB
testcase_22 AC 190 ms
7,552 KB
testcase_23 AC 21 ms
7,504 KB
testcase_24 AC 461 ms
7,480 KB
testcase_25 AC 467 ms
7,500 KB
testcase_26 AC 473 ms
7,552 KB
testcase_27 AC 468 ms
7,484 KB
testcase_28 AC 469 ms
7,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

#define INF 2000000000

void set_segt (int *t, int idx, int val, int size) {
  idx = idx+size-1;
  t[idx] = val;
  
  while (idx > 0) {
    idx = (idx-1)/2;
    t[idx] = t[2*idx+1];
    if (t[2*idx+2] > t[2*idx+1]) {
      t[idx] = t[2*idx+2];
    }
  }
  
  return;
}

int get_segt (int *t, int idx, int size) {
  return t[idx+size-1];
}

int max_segt_rec (int *t, int a, int b, int k, int l, int r) {
  int ans = 0;
  int tmp = 0;
  
  if (r <= a || b <= l) {
    return -INF;
  }
  
  if (a <= l && r <= b) {
    return t[k];
  }
  
  ans = max_segt_rec(t, a, b, 2*k+1, l, (l+r)/2);
  tmp = max_segt_rec(t, a, b, 2*k+2, (l+r)/2, r);
  
  if (ans < tmp) {
    ans = tmp;
  }
  
  return ans;
}

int max_segt (int *t, int a, int b, int size) {
  return max_segt_rec(t, a, b, 0, 0, size);
}

int bin_search_segt_rec (int *t, int a, int b, int v, int k, int l, int r) {
  int ans = 0;
  
  if (r-l <= 1) {
    if (t[k] >= v && a <= l && r <= b) {
      return l;
    }
    return -1;
  }
  
  if (r <= a || b <= l || t[k] < v) {
    return -1;
  }
  
  ans = bin_search_segt_rec(t, a, b, v, 2*k+1, l, (l+r)/2);
  if (ans < 0) {
    ans = bin_search_segt_rec(t, a, b, v, 2*k+2, (l+r)/2, r);
  }
  
  return ans;
}

int bin_search_segt (int *t, int a, int b, int v, int size) {
  return bin_search_segt_rec(t, a, b, v, 0, 0, size);
}

int main () {
  char s[200001] = "";
  
  int res = 0;
  
  int len = 0;
  int z[200000] = {};
  
  int size = 1;
  int tz[600000] = {};
  int tm[600000] = {};
  
  int idx1 = 1;
  int idx2 = 0;
  
  res = scanf("%s", s);
  while (s[len] != '\0') {
    len++;
  }
  
  while (size <= len) {
    size <<= 1;
  }
  
  for (int i = 0; i <= len; i++) {
    set_segt(tm, i, -len, size);
  }
  
  z[0] = len;
  while (idx1 < len) {
    while (idx1+idx2 < len && s[idx2] == s[idx1+idx2]) {
      idx2++;
    }
    z[idx1] = idx2;
    if (idx2 != 0) {
      int idx3 = 1;
      while (idx3 < idx2 && idx3+z[idx3] < idx2) {
        z[idx1+idx3] = z[idx3];
        idx3++;
      }
      idx1 += idx3;
      idx2 -= idx3;
    } else {
      idx1++;
    }
  }
  
  for (int i = 0; i < len; i++) {
    set_segt(tz, i, z[i], size);
  }
  
  for (int i = 2; i <= len/2; i++) {
    int tmp_idx = bin_search_segt(tz, i, len, i, size);
    if (tmp_idx >= 0) {
      int tmp_cnt = (-1)*max_segt(tm, 0, i+1, size);
      tmp_cnt++;
      while (tmp_idx >= 0) {
        tmp_cnt -= i-1;
        if (tmp_cnt < (-1)*get_segt(tm, tmp_idx+i, size)) {
          set_segt(tm, tmp_idx+i, -tmp_cnt, size);
        }
        tmp_idx = bin_search_segt(tz, tmp_idx+i, len, i, size);
      }
    }
  }
  
  printf("%d\n", (-1)*max_segt(tm, 0, len+1, size));
  return 0;
}
0