結果

問題 No.1740 Alone 'a'
ユーザー umezoumezo
提出日時 2021-11-12 22:43:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 761 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 200,640 KB
実行使用メモリ 10,012 KB
最終ジャッジ日時 2023-08-17 03:01:07
合計ジャッジ時間 4,933 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 105 ms
10,012 KB
testcase_04 AC 105 ms
9,788 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 18 ms
4,624 KB
testcase_12 AC 73 ms
8,516 KB
testcase_13 AC 68 ms
8,236 KB
testcase_14 AC 84 ms
9,460 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 64 ms
8,272 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 71 ms
8,716 KB
testcase_20 AC 38 ms
6,156 KB
testcase_21 AC 52 ms
7,104 KB
testcase_22 AC 62 ms
7,808 KB
testcase_23 AC 61 ms
7,976 KB
testcase_24 AC 38 ms
6,148 KB
testcase_25 AC 39 ms
6,176 KB
testcase_26 AC 50 ms
7,260 KB
testcase_27 AC 54 ms
7,240 KB
testcase_28 AC 45 ms
6,564 KB
testcase_29 AC 84 ms
9,392 KB
testcase_30 AC 53 ms
7,140 KB
testcase_31 AC 64 ms
7,896 KB
testcase_32 AC 46 ms
6,676 KB
testcase_33 AC 63 ms
8,000 KB
testcase_34 AC 15 ms
4,380 KB
testcase_35 AC 44 ms
6,476 KB
testcase_36 AC 37 ms
6,036 KB
testcase_37 AC 15 ms
4,412 KB
testcase_38 AC 31 ms
5,796 KB
testcase_39 AC 6 ms
4,376 KB
testcase_40 AC 20 ms
4,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const int MOD=998244353;
ll dp[200200][2][2];

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  string s;
  int n;
  cin>>n>>s;
  
  int cnt=0;
  rep(i,n){
    if(s[i]=='a') cnt++;
  }

  dp[0][0][0]=1;
  rep(i,n){
    int Ni=s[i]-'a';
    rep(j,2) rep(k,2) rep(x,26){
      int j2=j,k2=k;

      if(x==0) ++j2;
      if(j2>1) continue;

      if(!k && (x>Ni)) continue;
      if(x<Ni) k2=1;

      dp[i+1][j2][k2]=(dp[i+1][j2][k2]+dp[i][j][k])%MOD;
    }
  }
  if(cnt==1) cout<<(dp[n][1][0]+dp[n][1][1]-1+MOD)%MOD<<endl;
  else cout<<(dp[n][1][0]+dp[n][1][1])%MOD<<endl;
  
  return 0;
}
0