結果

問題 No.1171 Runs in Subsequences
ユーザー sahiyasahiya
提出日時 2020-12-23 16:20:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 2,287 bytes
コンパイル時間 1,820 ms
コンパイル使用メモリ 113,700 KB
実行使用メモリ 85,020 KB
最終ジャッジ日時 2023-10-21 15:12:13
合計ジャッジ時間 4,140 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 78 ms
82,072 KB
testcase_16 AC 79 ms
82,332 KB
testcase_17 AC 88 ms
85,020 KB
testcase_18 AC 88 ms
85,020 KB
testcase_19 AC 79 ms
85,020 KB
testcase_20 AC 76 ms
85,020 KB
testcase_21 AC 80 ms
85,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;
struct edge {
    int to, cost, id;
};
const ll MOD = 1E+09 + 7; // =998244353;
const ll INF = 1E18;
const int MAX_N = 2E+05;

ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 };

ll dp1[MAX_N + 1][26], dp2[MAX_N + 1][26];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;

    cin >> s;

    int ns = s.size();
    for (int i = 1; i <= ns; i++) {
        for (int j = 0; j < 26; j++) {
            dp1[i][j] = dp1[i - 1][j];
            if (s[i - 1] - 'a' == j) {
                for (int a = 0; a < 26; a++) {
                    dp1[i][j] += dp1[i - 1][a];
                    dp1[i][j] %= MOD;
                }
                dp1[i][j]++;
            }
        }
    }

    for (int i = 1; i <= ns; i++) {
        for (int j = 0; j < 26; j++) {
            dp2[i][j] = dp2[i - 1][j];
            if (s[i - 1] - 'a' == j) {
                for (int a = 0; a < 26; a++) {
                    if (a != j) {
                        dp2[i][j] += dp2[i - 1][a] + dp1[i - 1][a];
                    } else {
                        dp2[i][j] += dp2[i - 1][j];
                    }
                    dp2[i][j] %= MOD;
                }
                dp2[i][j]++;
            }
        }
    }

    // for (int i = 1; i <= ns; i++) {
    //     for (int j = 0; j < 26; j++) {
    //         cout << "i = " << i << ", j = " << j << ", dp1 = " << dp1[i][j] << "\n";
    //     }
    // }
    // for (int i = 1; i <= ns; i++) {
    //     for (int j = 0; j < 26; j++) {
    //         cout << "i = " << i << ", j = " << j << ", dp2 = " << dp2[i][j] << "\n";
    //     }
    // }
    ll ans = 0;
    for (int a = 0; a < 26; a++) {
        ans += dp2[ns][a];
        ans %= MOD;
    }

    cout << ans << "\n";

    return 0;
}
0