結果
問題 | No.1171 Runs in Subsequences |
ユーザー | 👑 jupiro |
提出日時 | 2020-08-14 22:02:36 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 133 ms / 2,000 ms |
コード長 | 2,543 bytes |
コンパイル時間 | 1,429 ms |
コンパイル使用メモリ | 132,820 KB |
実行使用メモリ | 100,352 KB |
最終ジャッジ日時 | 2024-04-18 21:50:41 |
合計ジャッジ時間 | 2,928 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 1 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 3 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 126 ms
96,768 KB |
testcase_16 | AC | 124 ms
95,616 KB |
testcase_17 | AC | 133 ms
100,352 KB |
testcase_18 | AC | 130 ms
100,352 KB |
testcase_19 | AC | 131 ms
100,224 KB |
testcase_20 | AC | 127 ms
100,352 KB |
testcase_21 | AC | 129 ms
100,224 KB |
ソースコード
#include <stdio.h> #include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> #include <numeric> #include <cctype> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; const long double PI = acos((long double)(-1)); using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; struct mint { long long x; mint(long long x = 0) :x((x% mod + mod) % mod) {} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s; cin >> s; int n = s.size(); vector dp1(n + 1, vector<mint>(27)), dp2(n + 1, vector<mint>(27)); dp1[0][26] = 0; dp2[0][26] = 1; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < 27; j++) { //取らない dp2[i + 1][j] += dp2[i][j]; dp1[i + 1][j] += dp1[i][j]; //取る dp2[i + 1][s[i] - 'a'] += dp2[i][j]; if (s[i] - 'a' == j) { dp1[i + 1][j] += dp1[i][j]; } else { dp1[i + 1][s[i] - 'a'] += dp1[i][j] + dp2[i][j]; } } } mint res = 0; for (int i = 0; i < 26; i++) res += dp1[n][i]; cout << res.x << "\n"; }