結果

問題 No.1292 パタパタ三角形
ユーザー LayCurseLayCurse
提出日時 2020-11-21 19:03:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 6,478 bytes
コンパイル時間 2,905 ms
コンパイル使用メモリ 212,688 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-30 22:12:09
合計ジャッジ時間 6,976 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
メンバ関数 ‘int HashMap<KEY, VAL>::getHash(std::pair<int, int>) [with KEY = std::pair<int, int>; VAL = int]’ 内,
    inlined from ‘VAL& HashMap<KEY, VAL>::operator[](KEY) [with KEY = std::pair<int, int>; VAL = int]’ at main.cpp:227:20,
    inlined from ‘int main()’ at main.cpp:296:20:
main.cpp:223:95: 警告: ‘hs.HashMap<std::pair<int, int>, int>::mask’ is used uninitialized [-Wuninitialized]
  223 |     d = (((((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) >> 32) * HashMap_ullP_L[2]) & mask;
      |                                                                                               ^~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:295:30: 備考: ‘hs.HashMap<std::pair<int, int>, int>::mask’ はここで定義されています
  295 |   HashMap<pair<int,int>,int> hs;
      |                              ^~
メンバ関数 ‘VAL& HashMap<KEY, VAL>::operator[](KEY) [with KEY = std::pair<int, int>; VAL = int]’ 内,
    inlined from ‘int main()’ at main.cpp:296:20:
main.cpp:229:16: 警告: ‘hs.HashMap<std::pair<int, int>, int>::used’ is used uninitialized [-Wuninitialized]
  229 |       if(used[k]==1 && key[k]==a){
      |          ~~~~~~^
main.cpp: 関数 ‘int main()’ 内:
main.cpp:295:30: 備考: ‘hs.HashMap<std::pair<int, int>, int>::used’ はここで定義されています
  295 |   HashMap<pair<int,int>,int> hs;
      |                              ^~
メンバ関数 ‘VAL& HashMap<KEY, VAL>::operator[](KEY) [with KEY = std::pair<int, int>; VAL = int]’ 内,
    inlined from ‘int main()’ at main.cpp:296:20:
main.cpp:229:27: 警告: ‘hs.HashMap<std::pair<int, int>, int>::key’ may be used uninitialized [-Wmaybe-uninitialized]
  229 |       if(used[k]==1 && key[k]==a){
      |                        ~~~^
main.cpp: 関数 ‘int main()’ 内:
main.cpp:295:30: 備考: ‘hs.HashMap<std::pair<int, int>, int>::key’ はここで定義されています
  295 |   HashMap<pair<int,int>,int> hs;
 

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct Rand{
  unsigned x;
  unsigned y;
  unsigned z;
  unsigned w;
  Rand(void){
    x=123456789;
    y=362436069;
    z=521288629;
    w=(unsigned)time(NULL);
  }
  Rand(unsigned seed){
    x=123456789;
    y=362436069;
    z=521288629;
    w=seed;
  }
  inline unsigned get(void){
    unsigned t;
    t = (x^(x<<11));
    x=y;
    y=z;
    z=w;
    w = (w^(w>>19))^(t^(t>>8));
    return w;
  }
  inline double getUni(void){
    return get()/4294967296.0;
  }
  inline int get(int a){
    return (int)(a*getUni());
  }
  inline int get(int a, int b){
    return a+(int)((b-a+1)*getUni());
  }
  inline long long get(long long a){
    return(long long)(a*getUni());
  }
  inline long long get(long long a, long long b){
    return a+(long long)((b-a+1)*getUni());
  }
  inline double get(double a, double b){
    return a+(b-a)*getUni();
  }
  inline int getExp(int a){
    return(int)(exp(getUni()*log(a+1.0))-1.0);
  }
  inline int getExp(int a, int b){
    return a+(int)(exp(getUni()*log((b-a+1)+1.0))-1.0);
  }
}
;
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 S, class T> inline S moddw_L(S a, const T b){
  a %= b;
  if(a < 0){
    a += b;
  }
  return a;
}
unsigned long long HashMap_ullP_L[4];
template<class KEY, class VAL> struct HashMap{
  char*used;
  KEY*key;
  VAL*val;
  int mem;
  int n;
  int mask;
  HashMap(){
    mem = 0;
  }
  ~HashMap(){
    free();
  }
  void expand(int nn){
    if(mem >= nn){
      return;
    }
    if(mem){
      free();
    }
    mem = nn;
    used = new char[nn];
    key = new KEY[nn];
    val = new VAL[nn];
  }
  void free(){
    if(mem){
      mem = 0;
      delete[] used;
      delete[] key;
      delete[] val;
    }
  }
  void init(int nn){
    int i;
    n = 1;
    nn = nn + (nn + 1) / 2;
    while(n < nn){
      n *= 2;
    }
    mask = n - 1;
    expand(n);
    for(i=(0);i<(n);i++){
      used[i] = 0;
    }
  }
  inline int getHash(const int a){
    unsigned long long d = a;
    d = (((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) & mask;
    return d;
  }
  inline int getHash(const unsigned a){
    unsigned long long d = a;
    d = (((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) & mask;
    return d;
  }
  inline int getHash(const long long a){
    unsigned long long d = a;
    d = (((((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) >> 32) * HashMap_ullP_L[2]) & mask;
    return d;
  }
  inline int getHash(const unsigned long long a){
    unsigned long long d = a;
    d = (((((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) >> 32) * HashMap_ullP_L[2]) & mask;
    return d;
  }
  inline int getHash(const pair<int,int> a){
    unsigned long long d = (((unsigned long long)a.first) << 32) + ((unsigned long long)a.second);
    d = (((((d * HashMap_ullP_L[0]) >> 32) * HashMap_ullP_L[1]) >> 32) * HashMap_ullP_L[2]) & mask;
    return d;
  }
  inline VAL& operator[](const KEY a){
    int k = getHash(a);
    for(;;){
      if(used[k]==1 && key[k]==a){
        break;
      }
      if(used[k]==0){
        used[k] = 1;
        key[k] = a;
        break;
      }
      k = (k+1) & mask;
    }
    return val[k];
  }
  inline bool exist(const KEY a){
    int k = getHash(a);
    for(;;){
      if(used[k]==1 && key[k]==a){
        return true;
      }
      if(used[k]==0){
        break;
      }
      k = (k+1) & mask;
    }
    return false;
  }
  template<class S> inline bool exist(const KEY a, S &res){
    int k = getHash(a);
    for(;;){
      if(used[k]==1 && key[k]==a){
        res = val[k];
        return true;
      }
      if(used[k]==0){
        break;
      }
      k = (k+1) & mask;
    }
    return false;
  }
}
;
int N;
char S[200000+2];
int main(){
  int i;
  {
    int i;
    int j;
    int k;
    Rand rnd;
    for(i=(0);i<(20);i++){
      rnd.get(2);
    }
    for(i=(0);i<(4);i++){
      for(j=(0);j<(32);j++){
        k = rnd.get(1,62);
        HashMap_ullP_L[i] |= (1ULL << k);
      }
      HashMap_ullP_L[i] |= (1ULL << 0);
      HashMap_ullP_L[i] |= (1ULL << 63);
    }
  }
  int x = 0;
  int y = 0;
  int k;
  int res = 1;
  HashMap<pair<int,int>,int> hs;
  hs[make_pair(x,y)] = 1;
  N = rd(S);
  for(i=(0);i<(N);i++){
    k =(moddw_L((S[i] - 'a' - y),3));
    if(k==0 && (x+y)%2==0){
      x--;
    }
    if(k==0 && (x+y)%2==1){
      x++;
    }
    if(k==1){
      y--;
    }
    if(k==2){
      y++;
    }
    if(!hs.exist(make_pair(x,y))){
      res++;
      hs[make_pair(x,y)] = 1;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay version 20201121-1

// --- original code ---
// int N;
// char S[2d5+2];
// {
//   int x = 0, y = 0, k, res = 1;
//   HashMap<pair<int,int>,int> hs;
//   hs[make_pair(x,y)] = 1;
// 
//   rd(S@N);
//   rep(i,N){
//     k = (S[i] - 'a' - y) %% 3;
//     if(k==0 && (x+y)%2==0) x--;
//     if(k==0 && (x+y)%2==1) x++;
//     if(k==1) y--;
//     if(k==2) y++;
//     if(!hs.exist(make_pair(x,y))) res++, hs[make_pair(x,y)] = 1;
//   }
//   wt(res);
// }
0