結果

問題 No.1740 Alone 'a'
ユーザー srtubakisrtubaki
提出日時 2021-11-12 22:37:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 5,414 bytes
コンパイル時間 2,293 ms
コンパイル使用メモリ 209,072 KB
実行使用メモリ 33,256 KB
最終ジャッジ日時 2023-08-17 02:49:53
合計ジャッジ時間 6,214 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 122 ms
33,144 KB
testcase_04 AC 121 ms
33,256 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 21 ms
8,572 KB
testcase_12 AC 87 ms
27,160 KB
testcase_13 AC 82 ms
25,908 KB
testcase_14 AC 102 ms
31,652 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 79 ms
25,008 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 15 ms
6,712 KB
testcase_19 AC 88 ms
27,420 KB
testcase_20 AC 51 ms
15,712 KB
testcase_21 AC 67 ms
20,084 KB
testcase_22 AC 75 ms
23,632 KB
testcase_23 AC 75 ms
23,656 KB
testcase_24 AC 51 ms
15,668 KB
testcase_25 AC 51 ms
15,956 KB
testcase_26 AC 66 ms
19,816 KB
testcase_27 AC 70 ms
21,188 KB
testcase_28 AC 58 ms
18,088 KB
testcase_29 AC 103 ms
31,636 KB
testcase_30 AC 70 ms
20,716 KB
testcase_31 AC 77 ms
24,584 KB
testcase_32 AC 60 ms
18,352 KB
testcase_33 AC 76 ms
24,044 KB
testcase_34 AC 17 ms
7,512 KB
testcase_35 AC 57 ms
17,536 KB
testcase_36 AC 47 ms
15,164 KB
testcase_37 AC 18 ms
7,520 KB
testcase_38 AC 41 ms
13,316 KB
testcase_39 AC 8 ms
4,756 KB
testcase_40 AC 25 ms
9,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region template
#include <bits/stdc++.h>

#include <atcoder/modint.hpp>

using namespace std;
using namespace atcoder;

// clang-format off
using mint = static_modint<998244353>;
using vm = vector<mint>;
using vvm = vector<vm>;
ostream& operator<<(ostream& os, const mint& v){ os << v.val(); return os; }

using ll = long long; using vl = vector<ll>; using vvl = vector<vl>;
using ld = long double; using vld = vector<ld>; using vvld = vector<vld>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
template <class T> using V = vector<T>; template <class T> using VV = vector<V<T>>;
template <class T> using VVV = vector<VV<T>>;
using vb = vector<bool>;
using vs = vector<string>;
using mll = map<ll, ll>;
using msl = map<string, ll>;
template<class T> using     heap = priority_queue<T>;
template<class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = 3001001000100100100LL;
constexpr int inf_int = 1000000009;
#define endl '\n'

#define  _overload(_1, _2, _3, name, ...) name
#define   rep(...) _overload(__VA_ARGS__,   _rep,   _rep2,)(__VA_ARGS__)
#define  repc(...) _overload(__VA_ARGS__,  _repc,  _repc2,)(__VA_ARGS__)
#define  repr(...) _overload(__VA_ARGS__,  _repr,  _repr2,)(__VA_ARGS__)
#define reprc(...) _overload(__VA_ARGS__, _reprc, _reprc2,)(__VA_ARGS__)
#define   _rep(i,k,n) for(ll i=(k)  , i##_xxxx=(n); i < i##_xxxx; ++i)
#define  _repc(i,k,n) for(ll i=(k)  , i##_xxxx=(n); i <=i##_xxxx; ++i)
#define  _repr(i,k,n) for(ll i=(n)-1, i##_xxxx=(k); i >=i##_xxxx; --i)
#define _reprc(i,k,n) for(ll i=(n)  , i##_xxxx=(k); i >=i##_xxxx; --i)
#define   _rep2(i,n)   _rep(i,0,n)
#define  _repc2(i,n)  _repc(i,1,n)
#define  _repr2(i,n)  _repr(i,0,n)
#define _reprc2(i,n) _reprc(i,1,n)

#define rall(o) rbegin(o), rend(o)
#define  all(o)  begin(o),  end(o)
template <class C> ll sz(const C& c) { return static_cast<ll>(c.size()); }
template <class T> bool chmax(T& m, const T& v){ if (m < v){ m = v; return true; } return false; }
template <class T> bool chmin(T& m, const T& v){ if (v < m){ m = v; return true; } return false; }
template <class T> T udiv(const T& a, const T& b){ return (a + b - 1) / b; }
template <class T> T rdiv(const T& a, const T& b){ return (a + b / 2) / b; }
template <class T, class S>             string join(const T& v, const S& sep                  ){ stringstream ss; bool f = false; for (const auto& e : v){ if (f) ss << sep; f = true; ss << e;} return ss.str(); }
template <class T, class S, class... U> string join(const T& v, const S& sep, const U& ...args){ stringstream ss; bool f = false; for (const auto& c : v){ if (f) ss << sep; f = true; ss << join(c, args...); } return ss.str(); }
template <class T>            ostream& operator<<(ostream& os, const vector<T>&            seq){ os << '[' << join(seq, ",") << ']'; return os; } template <class T>            ostream& operator<<(ostream& os, const vector<vector<T>>&    seq){ os << '[' << join(seq, ",\n ") << ']'; return os; }
template <class T>            ostream& operator<<(ostream& os, const deque<T>&             seq){ os << '[' << join(seq, ",") << ']'; return os; }
template <class T>            ostream& operator<<(ostream& os, const set<T>&               seq){ os << '{' << join(seq, ",") << '}'; return os; }
template <class T , class TH> ostream& operator<<(ostream& os, const unordered_set<T, TH>& seq){ os << '{' << join(seq, ",") << '}'; return os; }
template <class TK, class TV> ostream& operator<<(ostream& os, const map<TK, TV>&          seq){ os << '{'; bool f = false; for (const auto& e : seq){ if (f) os << ','; f = true; os << e.first << ":" << e.second; } os << '}'; return os; }
template <class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>&          pa){ os << '(' << pa.first << ',' << pa.second << ')'; return os; }

#if LOCAL
#define debug(...) _debug(__VA_ARGS__, __LINE__)
#else
#define debug(...)
#endif
void print() { std::cout << '\n'; }
template <class S>             void  print(const S& a){ std::cout << a << '\n'; }
template <class S>             void _debug(const S& a){ std::cerr << "(L:" << std::setw(3) << a << ")\n"; }
template <class S, class... T> void  print(const S& a, const T&... args){ std::cout << a << ' ';  print(args...); }
template <class S, class... T> void _debug(const S& a, const T&... args){ std::cerr << a << ' '; _debug(args...); }

struct setup_main { setup_main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << fixed << setprecision(15); } } setup_main_;
// clang-format on
#pragma endregion

/*/
桁dp

dp[i][smaller][a]

dp[i][1][1] = 上からi桁を見て、aを一つ含み、確実にSより小さいような組み合わせ
dp[i][1][0] = 上からi桁を見て、aを含まず、確実にSより小さいような組み合わせ
dp[i][0][*] = 上からi桁を見て、Sと一致する組み合わせ
/*/

void solve(ll N, string S) {
    vector<vector<vector<mint>>> dp(N + 1, vvm(2, vm(2, 0)));
    dp[0][0][0] = 1;

    rep(i, N) rep(smaller, 2) rep(a, 2) {
        debug(i, smaller, a, dp[i][smaller][a]);
        for (char x = 'a'; x <= (smaller ? 'z' : S[i]); x++) {
            if (x == 'a' and a) continue;
            dp[i + 1][smaller or x < S[i]][a or x == 'a'] += dp[i][smaller][a];
        }
    }

    debug(dp);
    print(dp[N][1][1]);
}

int main() {
    ll N;
    string S;
    cin >> N >> S;

    solve(N, S);
}
0