結果
| 問題 |
No.2019 Digits Filling for All Substrings
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-22 23:07:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 2,583 bytes |
| コンパイル時間 | 3,206 ms |
| コンパイル使用メモリ | 181,668 KB |
| 最終ジャッジ日時 | 2025-01-30 12:59:33 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
#include <unordered_map>
#include <bitset>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for (int i=0;i<n;i+=1)
#define rrep(i,n) for (int i=n-1;i>-1;i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<class T>
bool chmin(T &a, T b){
if (a>b){
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b){
if (a<b){
a = b;
return true;
}
return false;
}
template<class T>
T sum(vec<T> x){
T res=0;
for (auto e:x){
res += e;
}
return res;
}
template<class T>
void printv(vec<T> x){
for (auto e:x){
cout<<e<<" ";
}
cout<<endl;
}
template<class T>
ostream& operator<<(ostream& os, const vec<T>& A){
os << "{";
rep(i,A.size()){
os << A[i];
if (i!=A.size()-1){
os << ' ';
}
}
os<<"}";
return os;
}
template<class T,class U>
ostream& operator<<(ostream& os, const pair<T,U>& A){
os << "(" << A.first <<", " << A.second << ")";
return os;
}
template<class T>
ostream& operator<<(ostream& os, const deque<T>& A){
os << "deque({";
rep(i,A.size()){
os << A[i];
if (i!=A.size()-1){
os << ' ';
}
}
os<<"})";
return os;
}
int pow(int a, int b, int mod){
int res = 1;
while (b){
if (b&1){
res = res * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return res;
}
using mint = modint998244353;
const mint i10 = mint(10).inv();
ostream& operator<<(ostream& os, const mint& a){
os << a.val();
return os;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
cin>>N;
string S;
cin>>S;
vec<mint> tmp(3,0);
mint res = 0;
rep(i,N){
vec<mint> c(3);
if (S[i]=='?'){
c[0] = 4;
c[1] = 3;
c[2] = 3;
}
else{
c[int(S[i])%3] = 1;
}
vec<mint> ntmp(3);
rep(r,3){
rep(rr,3){
ntmp[(r+rr)%3] += tmp[r] * c[rr];
}
}
rep(r,3){
ntmp[r] += c[r];
}
swap(tmp,ntmp);
res += tmp[0];
//cout << tmp << endl;
//cout << res << endl;
}
cout << res.val() << endl;
}