結果

問題 No.2437 Fragile Multiples of 11
ユーザー Nzt3Nzt3
提出日時 2024-04-26 16:38:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 445 ms / 2,000 ms
コード長 1,774 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 199,604 KB
実行使用メモリ 39,060 KB
最終ジャッジ日時 2024-04-26 16:38:42
合計ジャッジ時間 10,219 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
38,796 KB
testcase_01 AC 11 ms
38,992 KB
testcase_02 AC 24 ms
38,680 KB
testcase_03 AC 436 ms
38,692 KB
testcase_04 AC 406 ms
38,752 KB
testcase_05 AC 402 ms
38,764 KB
testcase_06 AC 445 ms
38,820 KB
testcase_07 AC 409 ms
38,992 KB
testcase_08 AC 401 ms
38,896 KB
testcase_09 AC 434 ms
38,800 KB
testcase_10 AC 412 ms
38,692 KB
testcase_11 AC 411 ms
38,856 KB
testcase_12 AC 439 ms
38,864 KB
testcase_13 AC 437 ms
38,812 KB
testcase_14 AC 441 ms
39,008 KB
testcase_15 AC 13 ms
39,012 KB
testcase_16 AC 10 ms
38,736 KB
testcase_17 AC 10 ms
38,804 KB
testcase_18 AC 12 ms
39,060 KB
testcase_19 AC 11 ms
39,012 KB
testcase_20 AC 12 ms
38,836 KB
testcase_21 AC 12 ms
38,708 KB
testcase_22 AC 11 ms
38,900 KB
testcase_23 AC 12 ms
38,868 KB
testcase_24 AC 57 ms
38,852 KB
testcase_25 AC 27 ms
39,008 KB
testcase_26 AC 22 ms
38,792 KB
testcase_27 AC 55 ms
38,784 KB
testcase_28 AC 369 ms
38,756 KB
testcase_29 AC 355 ms
38,796 KB
testcase_30 AC 312 ms
38,756 KB
testcase_31 AC 267 ms
38,796 KB
testcase_32 AC 187 ms
38,912 KB
testcase_33 AC 53 ms
38,812 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';
}
0