結果

問題 No.1617 Palindrome Removal
ユーザー msm1993msm1993
提出日時 2021-07-28 11:10:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 3,240 bytes
コンパイル時間 2,300 ms
コンパイル使用メモリ 186,188 KB
実行使用メモリ 8,984 KB
最終ジャッジ日時 2023-10-11 07:01:08
合計ジャッジ時間 5,690 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
8,824 KB
testcase_01 AC 28 ms
8,924 KB
testcase_02 AC 27 ms
8,984 KB
testcase_03 AC 27 ms
8,912 KB
testcase_04 AC 30 ms
8,916 KB
testcase_05 AC 23 ms
8,472 KB
testcase_06 AC 6 ms
6,848 KB
testcase_07 AC 4 ms
6,240 KB
testcase_08 AC 2 ms
5,412 KB
testcase_09 AC 2 ms
5,392 KB
testcase_10 AC 45 ms
8,924 KB
testcase_11 AC 40 ms
8,624 KB
testcase_12 AC 49 ms
8,860 KB
testcase_13 AC 50 ms
8,856 KB
testcase_14 AC 2 ms
5,320 KB
testcase_15 AC 2 ms
5,384 KB
testcase_16 AC 2 ms
5,544 KB
testcase_17 AC 2 ms
5,308 KB
testcase_18 AC 2 ms
5,388 KB
testcase_19 AC 2 ms
5,544 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,300 KB
testcase_22 AC 2 ms
5,456 KB
testcase_23 AC 2 ms
5,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
  walloc1d(arr, x2-x1, mem);
  (*arr) -= x1;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class T> int Distinct(int N, T A[], int sorted=0, void *mem = wmem){
  int i;
  int k;
  int res = 1;
  T*a;
  if(N==0){
    return 0;
  }
  if(sorted){
    for(i=(1);i<(N);i++){
      if(A[i]!=A[i-1]){
        res++;
      }
    }
  }
  else{
    walloc1d(&a,N,&mem);
    for(i=(0);i<(N);i++){
      a[i] = A[i];
    }
    sort(a,a+N);
    for(i=(1);i<(N);i++){
      if(a[i]!=a[i-1]){
        res++;
      }
    }
  }
  return res;
}
template<class T> inline int isPalindrome(const int N, const T A[]){
  int i = 0;
  int j = N-1;
  while(i < j){
    if(A[i] != A[j]){
      return 0;
    }
    ;
    i++;
    j--;
  }
  return 1;
}
int N;
char S[1000000+2];
int main(){
  wmem = memarr;
  N = rd(S);
  if(!isPalindrome(N,S)){
    wt_L(N);
    wt_L('\n');
    return 0;
  }
  if(N==3 || Distinct(N,S)==1){
    wt_L(-(N%2));
    wt_L('\n');
    return 0;
  }
  wt_L(N-2);
  wt_L('\n');
  return 0;
}
// cLay version 20210717-1 [beta]

// --- original code ---
// int N;
// char S[1d6+2];
// {
//   rd(S@N);
//   if(!isPalindrome(N,S)) wt(N), return 0;
//   if(N==3 || Distinct(N,S)==1) wt(-(N%2)), return 0;
//   wt(N-2);
// }
0