ログインしてください。
提出 #41093939
ソースコード 拡げる
#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
using ll = long long;
const double pi = 3.14159265359;
const ll INF = 1LL << 60;
template<class T> inline bool chmin(T& a, T b){ if (a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if (a < b){a = b; return true;} return false;}
using mint = modint998244353;
//using mint = modint1000000007;
//using mint = modint; // mint::set_mod(p); later
//using mint = static_modint<1000000009>;
int N;
string s;
vector<vector<int>> lut (30, vector<int>(110, (int) 1e9));
mint dp[105][105];
// TT のうち、後半の T の先頭が s[x] であるような部分文字列の個数
// (ただし、同じアルファベットはより左から選ぶことで重複カウントを防ぐ)
mint solve(int x){
char sx = s[x];
int pos = lut[sx-'a'][0];
if (pos >= x){ return 0; }
for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dp[i][j] = 0;
dp[pos][x] = 1;
for (int i = pos; i < x; i++){
for (int j = 0; j < N; j++){
for (char c = 'a'; c <= 'z'; c++){
int ni = lut[c-'a'][i+1];
int nj = lut[c-'a'][j+1];
if (ni < x && nj < N){
dp[ni][nj] += dp[i][j];
}
}
}
}
mint ans = 0;
for (int i = 0; i < N; i++){
for (int j = 0; j < N; j++){
if (lut[sx-'a'][i+1] == x){
ans += dp[i][j];
}
}
}
return ans;
}
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
cin >> s;
N = (int) s.length();
// Look up table
for (char c = 'a'; c <= 'z'; c++){
int idx = (int)(1e9);
for (int i = N - 1; i >= 0; i--){
if (s[i] == c){
idx = i;
}
lut[c - 'a'][i] = idx;
}
}
mint ans = 0;
for (int i = 1; i < N; i++){
ans += solve(i);
}
cout << ans.val() << endl;
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Square Subsequence |
| ユーザ | unnohideyuki |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 500 |
| コード長 | 1946 Byte |
| 結果 | AC |
| 実行時間 | 26 ms |
| メモリ | 3728 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, example0.txt, example1.txt, example2.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 7 ms | 3632 KiB |
| 001.txt | AC | 2 ms | 3580 KiB |
| 002.txt | AC | 4 ms | 3716 KiB |
| 003.txt | AC | 2 ms | 3692 KiB |
| 004.txt | AC | 2 ms | 3728 KiB |
| 005.txt | AC | 2 ms | 3648 KiB |
| 006.txt | AC | 21 ms | 3648 KiB |
| 007.txt | AC | 21 ms | 3640 KiB |
| 008.txt | AC | 19 ms | 3616 KiB |
| 009.txt | AC | 18 ms | 3692 KiB |
| 010.txt | AC | 21 ms | 3568 KiB |
| 011.txt | AC | 24 ms | 3572 KiB |
| 012.txt | AC | 22 ms | 3580 KiB |
| 013.txt | AC | 25 ms | 3644 KiB |
| 014.txt | AC | 26 ms | 3696 KiB |
| 015.txt | AC | 22 ms | 3568 KiB |
| 016.txt | AC | 17 ms | 3612 KiB |
| 017.txt | AC | 17 ms | 3692 KiB |
| 018.txt | AC | 17 ms | 3720 KiB |
| 019.txt | AC | 17 ms | 3612 KiB |
| 020.txt | AC | 19 ms | 3696 KiB |
| 021.txt | AC | 23 ms | 3692 KiB |
| 022.txt | AC | 18 ms | 3560 KiB |
| 023.txt | AC | 19 ms | 3616 KiB |
| 024.txt | AC | 18 ms | 3716 KiB |
| 025.txt | AC | 5 ms | 3728 KiB |
| 026.txt | AC | 15 ms | 3616 KiB |
| 027.txt | AC | 6 ms | 3568 KiB |
| 028.txt | AC | 6 ms | 3648 KiB |
| 029.txt | AC | 14 ms | 3628 KiB |
| 030.txt | AC | 15 ms | 3644 KiB |
| 031.txt | AC | 4 ms | 3692 KiB |
| 032.txt | AC | 3 ms | 3644 KiB |
| 033.txt | AC | 2 ms | 3696 KiB |
| 034.txt | AC | 3 ms | 3568 KiB |
| 035.txt | AC | 17 ms | 3628 KiB |
| 036.txt | AC | 21 ms | 3696 KiB |
| 037.txt | AC | 22 ms | 3696 KiB |
| 038.txt | AC | 17 ms | 3576 KiB |
| 039.txt | AC | 18 ms | 3612 KiB |
| 040.txt | AC | 25 ms | 3648 KiB |
| 041.txt | AC | 19 ms | 3720 KiB |
| 042.txt | AC | 20 ms | 3560 KiB |
| 043.txt | AC | 20 ms | 3692 KiB |
| 044.txt | AC | 16 ms | 3652 KiB |
| example0.txt | AC | 3 ms | 3624 KiB |
| example1.txt | AC | 2 ms | 3648 KiB |
| example2.txt | AC | 3 ms | 3572 KiB |