結果

問題 No.2019 Digits Filling for All Substrings
ユーザー Nzt3Nzt3
提出日時 2022-07-22 22:38:48
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 1,859 ms
コンパイル使用メモリ 194,384 KB
最終ジャッジ日時 2025-01-30 12:48:13
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  string S;
  cin>>S;
  array<long long,3>ans={0,0,0};
  long long ret=0;
  for(int i=0;i<N;i++){
    array<long long,3>now={0,0,0};
    if(S[i]=='?'){
      now[0]=(4+ans[0]*4+ans[1]*3+ans[2]*3)%mod;
      now[1]=(3+ans[1]*4+ans[0]*3+ans[2]*3)%mod;
      now[2]=(3+ans[2]*4+ans[1]*3+ans[0]*3)%mod;
    }else{
      for(int j=0;j<3;j++){
        now[(j+S[i]-48)%3]=ans[j];
      }
      now[(S[i]-48)%3]+=1;
    }
    ans=now;
    ret=(ret+ans[0])%mod;
  }
  cout<<ret<<'\n';
}
0