結果

問題 No.2437 Fragile Multiples of 11
ユーザー Nzt3Nzt3
提出日時 2024-04-26 16:45:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,161 ms / 2,000 ms
コード長 1,974 bytes
コンパイル時間 2,375 ms
コンパイル使用メモリ 197,736 KB
実行使用メモリ 39,040 KB
最終ジャッジ日時 2024-04-26 16:46:13
合計ジャッジ時間 41,232 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,100 ms
38,784 KB
testcase_01 AC 1,125 ms
38,912 KB
testcase_02 AC 1,072 ms
39,040 KB
testcase_03 AC 1,130 ms
38,784 KB
testcase_04 AC 1,120 ms
39,040 KB
testcase_05 AC 1,119 ms
38,912 KB
testcase_06 AC 1,122 ms
38,912 KB
testcase_07 AC 1,142 ms
39,040 KB
testcase_08 AC 1,161 ms
38,912 KB
testcase_09 AC 1,091 ms
38,784 KB
testcase_10 AC 1,113 ms
38,912 KB
testcase_11 AC 1,082 ms
39,040 KB
testcase_12 AC 1,095 ms
38,912 KB
testcase_13 AC 1,093 ms
39,040 KB
testcase_14 AC 1,122 ms
38,784 KB
testcase_15 AC 1,131 ms
38,784 KB
testcase_16 AC 1,090 ms
38,784 KB
testcase_17 AC 1,102 ms
38,912 KB
testcase_18 AC 1,128 ms
38,912 KB
testcase_19 AC 1,120 ms
38,912 KB
testcase_20 AC 1,101 ms
38,912 KB
testcase_21 AC 1,111 ms
39,040 KB
testcase_22 AC 1,121 ms
38,912 KB
testcase_23 AC 1,114 ms
38,912 KB
testcase_24 AC 921 ms
39,040 KB
testcase_25 AC 1,073 ms
38,912 KB
testcase_26 AC 1,126 ms
38,912 KB
testcase_27 AC 979 ms
38,912 KB
testcase_28 AC 1,087 ms
39,040 KB
testcase_29 AC 1,114 ms
39,040 KB
testcase_30 AC 1,113 ms
38,912 KB
testcase_31 AC 1,005 ms
38,912 KB
testcase_32 AC 990 ms
38,912 KB
testcase_33 AC 974 ms
38,912 KB
権限があれば一括ダウンロードができます

ソースコード

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();
  N=100;
  for(int i=0;i<100;i++)X.push_back(0);
  for(ll i=0;i<100000;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