結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー butsurizukibutsurizuki
提出日時 2022-10-07 10:18:35
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,349 ms / 3,000 ms
コード長 2,252 bytes
コンパイル時間 8,869 ms
コンパイル使用メモリ 336,388 KB
実行使用メモリ 54,048 KB
最終ジャッジ日時 2023-08-24 04:09:20
合計ジャッジ時間 70,481 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 392 ms
25,280 KB
testcase_03 AC 713 ms
34,460 KB
testcase_04 AC 397 ms
25,024 KB
testcase_05 AC 181 ms
15,440 KB
testcase_06 AC 423 ms
26,488 KB
testcase_07 AC 987 ms
46,612 KB
testcase_08 AC 32 ms
7,572 KB
testcase_09 AC 738 ms
37,868 KB
testcase_10 AC 99 ms
11,576 KB
testcase_11 AC 174 ms
15,588 KB
testcase_12 AC 344 ms
23,152 KB
testcase_13 AC 897 ms
43,208 KB
testcase_14 AC 251 ms
19,988 KB
testcase_15 AC 486 ms
28,128 KB
testcase_16 AC 916 ms
43,884 KB
testcase_17 AC 562 ms
31,404 KB
testcase_18 AC 1,013 ms
46,052 KB
testcase_19 AC 171 ms
15,824 KB
testcase_20 AC 1,009 ms
46,016 KB
testcase_21 AC 58 ms
10,668 KB
testcase_22 AC 1,177 ms
49,752 KB
testcase_23 AC 1,075 ms
49,676 KB
testcase_24 AC 1,066 ms
49,708 KB
testcase_25 AC 1,129 ms
49,720 KB
testcase_26 AC 1,161 ms
49,772 KB
testcase_27 AC 1,071 ms
49,668 KB
testcase_28 AC 1,056 ms
49,696 KB
testcase_29 AC 1,130 ms
49,824 KB
testcase_30 AC 1,128 ms
49,644 KB
testcase_31 AC 1,089 ms
49,772 KB
testcase_32 AC 1,081 ms
49,672 KB
testcase_33 AC 1,147 ms
49,764 KB
testcase_34 AC 1,158 ms
49,744 KB
testcase_35 AC 1,145 ms
49,740 KB
testcase_36 AC 1,161 ms
49,792 KB
testcase_37 AC 1,117 ms
49,668 KB
testcase_38 AC 1,169 ms
49,676 KB
testcase_39 AC 1,083 ms
49,764 KB
testcase_40 AC 1,140 ms
49,744 KB
testcase_41 AC 1,182 ms
49,688 KB
testcase_42 AC 686 ms
20,692 KB
testcase_43 AC 656 ms
20,700 KB
testcase_44 AC 677 ms
20,720 KB
testcase_45 AC 629 ms
20,888 KB
testcase_46 AC 612 ms
20,796 KB
testcase_47 AC 1,271 ms
52,296 KB
testcase_48 AC 1,349 ms
52,352 KB
testcase_49 AC 1,277 ms
52,300 KB
testcase_50 AC 1,254 ms
52,332 KB
testcase_51 AC 1,332 ms
52,296 KB
testcase_52 AC 1,222 ms
50,344 KB
testcase_53 AC 1,215 ms
50,500 KB
testcase_54 AC 1,256 ms
50,460 KB
testcase_55 AC 1,164 ms
49,252 KB
testcase_56 AC 1,202 ms
49,300 KB
testcase_57 AC 1,174 ms
49,280 KB
testcase_58 AC 55 ms
4,676 KB
testcase_59 AC 1,260 ms
54,048 KB
testcase_60 AC 26 ms
6,844 KB
testcase_61 AC 1,202 ms
49,364 KB
testcase_62 AC 8 ms
4,380 KB
testcase_63 AC 130 ms
6,832 KB
testcase_64 AC 115 ms
6,528 KB
testcase_65 AC 155 ms
6,880 KB
testcase_66 AC 1,138 ms
49,028 KB
testcase_67 AC 69 ms
10,116 KB
testcase_68 AC 71 ms
4,588 KB
testcase_69 AC 65 ms
10,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

// Safer-Faster-RollingHash
// https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
// https://atcoder.jp/contests/abc141/submissions/7717102
typedef unsigned long long int ull;

const ull MASK30 = (1ull << 30) - 1;
const ull MASK31 = (1ull << 31) - 1;
const ull MOD = (1ull << 61) - 1;
const ull MASK61 = MOD;

//mod 2^61-1を計算する関数
ull CalcMod(ull x)
{
    ull xu = x >> 61;
    ull xd = x & MASK61;
    ull res = xu + xd;
    if (res >= MOD) res -= MOD;
    return res;
}

//a*b mod 2^61-1を返す関数(最後にModを取る)
ull Mul(ull a, ull b)
{
    ull au = a >> 31;
    ull ad = a & MASK31;
    ull bu = b >> 31;
    ull bd = b & MASK31;
    ull mid = ad * bu + au * bd;
    ull midu = mid >> 30;
    ull midd = mid & MASK30;
    return CalcMod(au * bu * 2 + midu + (midd << 31) + ad * bd);
}

ull hBase;
void genBase(mt19937_64 &eg){
  hBase=CalcMod((ull)eg());
}

int main(){
  random_device seed_gen;
  mt19937_64 engine(seed_gen());

  registerValidation();
  int n=inf.readInt(1,200000);inf.readEoln();
  vector<string> s(n);
  int sigl=0;
  for(int i=0;i<n;i++){
    s[i]=inf.readToken();inf.readEoln();
    sigl+=s[i].size();
    ensuref(sigl<=1000000,"too long input");
    for(auto &nx : s[i]){
      ensuref('a'<=nx && nx<='z',"invalid char");
    }
  }
  inf.readEof();

  vector<int> res(n,1);
  for(int tr=0;tr<1;tr++){
    genBase(engine);
    set<ull> st;
    for(int i=0;i<n;i++){
      ull ordHash=0;
      for(auto &nx : s[i]){
        ordHash=CalcMod(Mul(ordHash,hBase)+((ull)nx));
      }
      if(st.find(ordHash)==st.end()){res[i]=0;}
      // cout << "Cur : " << ordHash << "\n";
      st.insert(ordHash);
      ull pos=1;
      for(int j=s[i].size()-1;j>0;j--){
        ull npos=Mul(pos,hBase);
        ull subdel =CalcMod(Mul(pos,((ull)s[i][j]))+Mul(npos,((ull)s[i][j-1])));
        ull addel  =CalcMod(Mul(pos,((ull)s[i][j-1]))+Mul(npos,((ull)s[i][j])));
        ull curHash=CalcMod(ordHash+MOD-subdel+addel);
        st.insert(curHash);
        // cout << "Swap " << j << " : " << curHash << "\n";
        pos=npos;
      }
    }
  }
  for(auto &nx : res){
    if(nx==1){cout << "Yes\n";}
    else{cout << "No\n";}
  }
  return 0;
}
0