結果

問題 No.2437 Fragile Multiples of 11
ユーザー Nzt3Nzt3
提出日時 2024-04-26 16:42:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,966 bytes
コンパイル時間 2,173 ms
コンパイル使用メモリ 198,208 KB
実行使用メモリ 45,568 KB
最終ジャッジ日時 2024-04-26 16:42:48
合計ジャッジ時間 9,519 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 625 ms
44,288 KB
testcase_01 AC 690 ms
38,924 KB
testcase_02 AC 1,218 ms
38,960 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int MOD=998244353;
int N;
string X;

ll dp[100][1<<11][11][2];
ll next_s[1<<11][10];

void ch(ll &a,ll b){
  a=(a+b)%MOD;
}

ll rec(int k=0,int s=0,int leading_0=1,int mod11=0, bool less=false){
  if(k==N){
    if(mod11==0&&(s&1)==0&&leading_0==0)return 1ll;
    return 0ll;
  }
  if(less && dp[k][s][mod11][leading_0]!=-1)return dp[k][s][mod11][leading_0];
  if(less){
    ll ret=0;
    if(leading_0){
      for(int i=1;i<10;i++){
        ch(ret,rec(k+1,next_s[s][i]|(1<<mod11),0,(mod11*10+i)%11,true));
      }
      ch(ret,rec(k+1,next_s[s][0],1,(mod11*10)%11,true));
    }else{
      for(int i=0;i<10;i++){
        ch(ret,rec(k+1,next_s[s][i]|(1<<mod11),0,(mod11*10+i)%11,true));
      }
    }
    return dp[k][s][mod11][leading_0]=ret;
  }else{
    ll ret=0;
    // Xの最上位桁は0ではない -> not less && leading_0 は最初の1回だけ
    if(leading_0){
      for(int i=1;i<X[k];i++){
        ch(ret,rec(k+1,next_s[s][i]|(1<<mod11),0,(mod11*10+i)%11,true));
      }
      ch(ret,rec(k+1,next_s[s][0],1,(mod11*10)%11,true));
      ch(ret,rec(k+1,next_s[s][X[k]]|(1<<mod11),0,(mod11*10+X[k])%11,false));
    }else{
      for(int i=0;i<X[k];i++){
        ch(ret,rec(k+1,next_s[s][i]|(1<<mod11),0,(mod11*10+i)%11,true));
      }
      ch(ret,rec(k+1,next_s[s][X[k]]|(1<<mod11),0,(mod11*10+X[k])%11,false));
    }
    return ret;
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);  
  cin>>N>>X;
  for(auto &i:X)i-='0';
  fill(dp[0][0][0],dp[99][(1<<11)-1][11],-1ll);
  for(int i=0;i<1<<11;i++){
    for(int j=0;j<10;j++){
      int t=0;
      for(int k=0;k<11;k++){
        if(i>>k&1)t|=1<<((k*10+j)%11);
      }
      next_s[i][j]=t;
    }
  }
  cout<<rec()<<'\n';
  X.clear();
  for(int i=0;i<100;i++)X.push_back(0);
  for(ll i=0;i<1000000;i++){
    ll t=(i*i+10)%MOD;
    for(int j=0;j<100;j++){
      X[j]=t%10;
      t=(t*t+1)%MOD;
    }
    rec();
  }
}
0