結果
| 問題 |
No.3277 Forever Monotonic Number
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-19 22:17:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,469 ms / 4,000 ms |
| コード長 | 1,487 bytes |
| コンパイル時間 | 2,004 ms |
| コンパイル使用メモリ | 200,864 KB |
| 実行使用メモリ | 99,456 KB |
| 最終ジャッジ日時 | 2025-09-19 22:18:10 |
| 合計ジャッジ時間 | 18,392 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | scanf("%d", &T);
| ~~~~~^~~~~~~~~~
main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
36 | scanf("%lld", &n);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pli;
const int N = 2000086, MOD = 998244353, INF = 0x3f3f3f3f;
ll res;
int n, m, cnt, w[N];
inline ll qmi(ll a, ll b, ll c) { ll res = 1; while (b) { if (b & 1) res = res * a % c; a = a * a % c; b >>= 1; } return res; }
int a[20][20];
set<ll> st;
void dfs(ll v, ll p, int t) {
st.insert(v);
if (v >= 1e15) return;
for (int i = 1; i <= t; i++) {
dfs(v + p * i, p * 10, i);
}
}
int main() {
for (int i = 1; i <= 9; i++) dfs(i, 10, i);
for (auto u = st.begin(); u != st.end(); ) {
ll t = *u, sum = 0;
while (t) sum += t % 10, t /= 10;
if (*u > 10 && !st.count(sum)) u = st.erase(u);
else ++u;
}
int T;
scanf("%d", &T);
while (T--) {
ll n;
scanf("%lld", &n);
ll t = *st.lower_bound(n + 1);
if (t <= (n + 1) * 9) {
ll g = t - (n + 1);
ll len = g / 8, c = g % 8;
res = c * qmi(10, len, MOD) % MOD;
res = (res + (qmi(10, len, MOD) - 1 + MOD) % MOD * qmi(9, MOD - 2, MOD) % MOD * 8) % MOD;
res = (res + (qmi(10, n + 1, MOD) - 1 + MOD) % MOD * qmi(9, MOD - 2, MOD)) % MOD;
} else {
ll c = t % 9, len = t / 9;
res = (qmi(10, len, MOD) - 1 + MOD) % MOD;;
res = (res + c * qmi(10, len, MOD)) % MOD;
}
printf("%lld\n", res);
}
return 0;
}