結果
| 問題 |
No.2388 At Least K-Characters
|
| コンテスト | |
| ユーザー |
ococonomy1
|
| 提出日時 | 2023-07-21 22:59:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 342 ms / 4,000 ms |
| コード長 | 3,076 bytes |
| コンパイル時間 | 1,045 ms |
| コンパイル使用メモリ | 118,612 KB |
| 最終ジャッジ日時 | 2025-02-15 17:25:01 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using lg = long long;
using pii = pair<int, int>;
using pll = pair<lg, lg>;
#define TEST cerr << "TEST" << endl
#define AMARI 998244353
// #define AMARI 1000000007
#define TEMOTO ((sizeof(long double) == 16) ? false : true)
#define TIME_LIMIT 1980 * (TEMOTO ? 1 : 1000)
#define el '\n'
#define El '\n'
#define mpr make_pair
#define MULTI_TEST_CASE false
void solve(void) {
int n,m,k;
cin >> n >> m >> k;
string s;
cin >> s;
vector<int> icutume(n);
set<char> tst;
for(int i = 0; i < s.size(); i++){
tst.insert(s[i]);
icutume[i] = tst.size();
}
vector<vector<lg>> smaller(m + 1,vector<lg>(27,0)),just(m + 1,vector<lg>(27,0));
just[0][0] = 1;
//配るDP
vector<bool> visited(26,false);
for(int i = 0; i < m; i++){
//just →just
if(i < n)just[i + 1][icutume[i]] = 1;
for(int j = 0; j <= 26; j++){
//smaller → smaller
//if(i == 1 && j == 1)cerr << smaller[i][j] << el;
smaller[i + 1][j] += smaller[i][j] * (lg)j; smaller[i + 1][j] %= AMARI;
if(j != 26){
smaller[i + 1][j + 1] += smaller[i][j] * (lg)(26 - j);
smaller[i + 1][j + 1] %= AMARI;
}
//just → smaller
if(!just[i][j])continue;
int tc = 0,fc = 0;
if(i >= s.size())continue;
//smallerに持ってけるアルファベットが何種類あるか
for(int k = 0; k < s[i] - 'a'; k++){
if(visited[k])tc++;
else fc++;
}
visited[s[i] - 'a'] = true;
//if(i == 1)cerr << tc << ' ' << fc << el;
smaller[i + 1][j] += tc;
if(smaller[i + 1][j] > AMARI)smaller[i + 1][j] -= AMARI;
if(fc){
smaller[i + 1][j + 1] += fc;
if(smaller[i + 1][j + 1] > AMARI)smaller[i + 1][j + 1] -= AMARI;
}
}
}
lg ans = 0;
if(true){
for(int i = 0; i <= m; i++){
for(int j = 0; j <= 26; j++){
if(j >= k)ans += smaller[i][j];
if(ans > AMARI)ans -= AMARI;
//cerr << smaller[i][j] << ' ';
//if(i < n && j >= k)ans += just[i][j];
}
//cerr << el;
}
for(int i = 0; i < n - 1; i++)if(icutume[i] >= k)ans++;
if(ans > AMARI)ans -= AMARI;
}
cout << ans << el;
return;
}
void calc(void) {
return;
}
int main(void) {
cin.tie(nullptr);
ios::sync_with_stdio(false);
calc();
int t = 1;
if (MULTI_TEST_CASE) cin >> t;
while (t--) {
solve();
}
return 0;
}
ococonomy1