結果

問題 No.1740 Alone 'a'
ユーザー mikammikam
提出日時 2021-11-12 22:39:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,450 bytes
コンパイル時間 1,963 ms
コンパイル使用メモリ 200,320 KB
実行使用メモリ 9,748 KB
最終ジャッジ日時 2023-08-17 02:52:41
合計ジャッジ時間 4,909 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 104 ms
9,748 KB
testcase_04 AC 105 ms
9,740 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 17 ms
4,632 KB
testcase_12 AC 68 ms
8,704 KB
testcase_13 AC 65 ms
8,232 KB
testcase_14 AC 81 ms
9,472 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 62 ms
8,036 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 69 ms
8,612 KB
testcase_20 AC 37 ms
6,236 KB
testcase_21 AC 49 ms
7,120 KB
testcase_22 AC 60 ms
7,772 KB
testcase_23 AC 59 ms
8,040 KB
testcase_24 AC 38 ms
6,144 KB
testcase_25 AC 37 ms
6,188 KB
testcase_26 AC 48 ms
7,028 KB
testcase_27 AC 52 ms
7,288 KB
testcase_28 AC 44 ms
6,792 KB
testcase_29 AC 80 ms
9,456 KB
testcase_30 AC 51 ms
7,200 KB
testcase_31 AC 61 ms
7,928 KB
testcase_32 AC 44 ms
6,680 KB
testcase_33 AC 61 ms
7,880 KB
testcase_34 AC 14 ms
4,376 KB
testcase_35 AC 42 ms
6,500 KB
testcase_36 AC 36 ms
6,096 KB
testcase_37 AC 15 ms
4,380 KB
testcase_38 AC 30 ms
5,600 KB
testcase_39 AC 6 ms
4,380 KB
testcase_40 AC 19 ms
4,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
typedef long long ll;
#define int ll
using vi = vector<int>;
using vs = vector<string>;
using P = pair<int,int>;
template<typename T> bool chmax(T &a, const T b) {if (a < b) {a = b; return true;} else return false; }
template<typename T> bool chmin(T &a, const T b) {if (a > b) {a = b; return true;} else return false; }
const int INF = 1e18;
const int mod = 998244353;

int dp[200200][2][2];//dp[i][j][k]:=i桁まで見てaを(使ってない0)(使った1)、sより小さいことが確定(しない0)(する1)
signed main() {
   cin.tie(0);
   ios_base::sync_with_stdio(false);
   cout << fixed << setprecision(20);

   int n;
   string S;
   cin>>n>>S;
   dp[0][0][0]=1;
   rep(i,n){
       int ni = S[i]-'a';//Sの上からi桁目
       rep(j,2)rep(k,2)rep(x,26){
           int j2 = j,k2 = k;// 遷移後の状態を表す変数 j2, k2 を,遷移前の状態で初期化
           if(x==0)j2++;     // X の上から i 桁目 x が a なら j2 を更新
           if(j2>1)continue; // aの数が 1 より多いなら無視

           if(!k&&(x>ni))continue;//Sより大きいなら無視
           if(x<ni)k2=1;//真に小さいならkを確定

           dp[i+1][j2][k2] += dp[i][j][k];
           dp[i+1][j2][k2] %= mod;
       }
   }
   int ans = dp[n][1][1];
   cout << ans <<"\n";
   return 0;
}
0