結果

問題 No.2772 Appearing Even Times
コンテスト
ユーザー Nzt3
提出日時 2024-05-31 23:42:27
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 750 ms / 4,000 ms
コード長 1,292 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,120 ms
コンパイル使用メモリ 212,680 KB
実行使用メモリ 324,824 KB
最終ジャッジ日時 2026-07-04 20:12:19
合計ジャッジ時間 12,265 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int MOD=998244353;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define replr(i,l,r) for(int i=(l);i<(int)(r);i++)

ll memo[10002][1<<10][2][2];
string N;
int len;

void ch(ll &a,ll b){
  a=(a+b)%MOD;
}
ll rec(int p,int s,int t,int led_0){
  if(memo[p][s][t][led_0]!=-1)return memo[p][s][t][led_0];
  if(p==len){
    if(s==0&&led_0==0)return memo[p][s][t][led_0]=1;
    return memo[p][s][t][led_0]=0;
  }
  ll ret=0;
  if(t){
    if(led_0){
      replr(i,1,N[p]){
        ch(ret,rec(p+1,s^(1<<i),0,0));
      }
      ch(ret,rec(p+1,s,0,1));
      ch(ret,rec(p+1,s^(1<<N[p]),1,0));
    }else{
      rep(i,N[p]){
        ch(ret,rec(p+1,s^(1<<i),0,0));
      }
      ch(ret,rec(p+1,s^(1<<N[p]),1,0));
    }
  }else{
    if(led_0){
      rep(i,9){
        ch(ret,rec(p+1,s^(1<<(i+1)),0,0));
      }
      ch(ret,rec(p+1,s,0,1));
    }else{
      rep(i,10){
        ch(ret,rec(p+1,s^(1<<i),0,0));
      }
    }
  }
  return memo[p][s][t][led_0]=ret;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin>>N;
  len=N.size();
  rep(i,10002){
    rep(j,1<<10){
      rep(k,2){
        rep(l,2){
          memo[i][j][k][l]=-1;
        }
      }
    }
  }
  for(auto &i:N)i-='0';
  cout<<rec(0,0,1,1)<<'\n';
}
0