結果
| 問題 | No.1185 完全な3の倍数 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-06 14:59:11 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1 ms / 2,000 ms |
| + 616µs | |
| コード長 | 548 bytes |
| 記録 | |
| コンパイル時間 | 2,169 ms |
| コンパイル使用メモリ | 340,404 KB |
| 実行使用メモリ | 9,868 KB |
| 最終ジャッジ日時 | 2026-11-06 14:59:19 |
| 合計ジャッジ時間 | 4,567 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
long dp[12][2];
int main() {
string S;
cin >> S;
const int N = S.size();
long ans = 0;
dp[0][0] = 1;
for(int i = 0; i < N; i++) {
for(int j = 0; j < 2; j++) {
int lim = j ? 9 : S[i] - '0';
for(int d: {0,3,6,9}) if(d <= lim) {
dp[i + 1][j || d < S[i]-'0'] += dp[i][j];
}
}
}
long tmp = dp[N][0] + dp[N][1] - 4;
for(int x = 10; x < 100 && x <= stoll(S); x++) {
int t = (x % 10) + (x / 10);
if (t % 3 == 0 and ((x /10) % 3 != 0)) {
tmp++;
}
}
cout << tmp << endl;
}