結果
| 問題 |
No.2867 NOT FOUND 404 Again
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-30 22:49:25 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,530 bytes |
| コンパイル時間 | 1,230 ms |
| コンパイル使用メモリ | 99,108 KB |
| 実行使用メモリ | 214,472 KB |
| 最終ジャッジ日時 | 2024-08-30 22:49:31 |
| 合計ジャッジ時間 | 5,856 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 1 TLE * 1 -- * 16 |
ソースコード
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <tuple>
using namespace std;
using ll = long long;
int main () {
string n; cin >> n;
vector<int> N(n.size());
for (int i = 0; i < n.size(); i++) N[i] = n[i] - '0';
const int len = static_cast<int>(n.size());
const ll MOD = 998244353;
const auto ban = vector<int>({4, 0, 4});
map<int, ll> mp;
auto encode = [&] (int pos, bool less, int cur) {
int res = 0;
int p = 1;
res += p * pos;
p *= len;
res += p * static_cast<int> (less);
p *= 2;
res += p * cur;
return res;
};
auto dp = [&] (auto dp, int pos, bool less, int cur) {
auto key = encode(pos, less, cur);
if (mp.find(key) != mp.end()) return mp[key];
if (pos == len) {
if (cur == 3) return 0LL;
return 1LL;
}
ll res = 0;
for (int nex = 0; nex < 10; nex++) {
if (!less && N[pos] < nex) continue;
bool nl = less || nex < N[pos];
int nc = cur;
if (nc < 3) {
if (ban[nc] == nex) {
nc++;
}
else if (nex == 4) {
nc = 1;
}
else {
nc = 0;
}
}
res += dp(dp, pos + 1, nl, nc);
res %= MOD;
}
return mp[key] = res;
};
cout << dp(dp, 0, false, 0) - 1 << "\n";
}