結果
| 問題 |
No.2943 Sigma String of String Score Problem
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-10-21 11:55:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 559 ms / 3,000 ms |
| コード長 | 1,884 bytes |
| コンパイル時間 | 498 ms |
| コンパイル使用メモリ | 41,976 KB |
| 最終ジャッジ日時 | 2025-02-24 22:10:49 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:67:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
67 | scanf("%s%s", s, t);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2943.cc: No.2943 Sigma String of String Score Problem - yukicoder
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 100000;
const int MAX_M = 1000;
const int MOD = 998244353;
/* typedef */
template<const int MOD>
struct MI {
int v;
MI(): v() {}
MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }
MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }
explicit operator int() const { return v; }
MI operator+(const MI m) const { return MI(v + m.v); }
MI operator-(const MI m) const { return MI(v + MOD - m.v); }
MI operator*(const MI m) const { return MI((long long)v * m.v); }
MI &operator+=(const MI m) { return (*this = *this + m); }
MI &operator-=(const MI m) { return (*this = *this - m); }
MI &operator*=(const MI m) { return (*this = *this * m); }
bool operator==(const MI m) const { return v == m.v; }
bool operator!=(const MI m) const { return v != m.v; }
MI pow(int n) const { // a^n % MOD
MI pm = 1, a = *this;
while (n > 0) {
if (n & 1) pm *= a;
a *= a;
n >>= 1;
}
return pm;
}
MI inv() const { return pow(MOD - 2); }
MI operator/(const MI m) const { return *this * m.inv(); }
MI &operator/=(const MI m) { return (*this = *this / m); }
};
using mi = MI<MOD>;
/* global variables */
char s[MAX_N + 4], t[MAX_M + 4];
mi dp[2][MAX_M + 1];
/* subroutines */
/* main */
int main() {
scanf("%s%s", s, t);
int n = strlen(s), m = strlen(t);
dp[0][0] = 1;
int cur = 0, nxt = 1;
for (int i = 0; i < n; i++) {
fill(dp[nxt], dp[nxt] + m + 1, 0);
for (int j = 0; j <= m; j++)
if ((int)dp[cur][j]) {
dp[nxt][j] += dp[cur][j] * 2;
if (j < m && s[i] == t[j])
dp[nxt][j + 1] += dp[cur][j];
}
swap(cur, nxt);
}
printf("%d\n", (int)dp[cur][m]);
return 0;
}
tnakao0123