結果
問題 |
No.3157 Nabeatsu
|
ユーザー |
![]() |
提出日時 | 2025-05-23 21:23:40 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 151 ms / 2,000 ms |
コード長 | 1,080 bytes |
コンパイル時間 | 2,702 ms |
コンパイル使用メモリ | 278,128 KB |
実行使用メモリ | 102,428 KB |
最終ジャッジ日時 | 2025-05-23 21:23:53 |
合計ジャッジ時間 | 6,917 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h> using namespace std; string S; int N; vector<int> ans; void f(int n, int mod, bool giri) { if (n == N) { if (mod != 0) { for (int d : ans) cout << d; cout << endl; exit(0); // 成功したら即終了 } else { return; } } if (giri) { for (int i = S[n] - '0'; i >= 0; --i) { if (i == 3) continue; if (i == S[n] - '0') { ans.push_back(i); f(n + 1, (mod + i) % 3, true); ans.pop_back(); } else { ans.push_back(i); f(n + 1, (mod + i) % 3, false); ans.pop_back(); } } } else { for (int i = 9; i >= 0; --i) { if (i == 3) continue; ans.push_back(i); f(n + 1, (mod + i) % 3, false); ans.pop_back(); } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> S; N = S.size(); f(0, 0, true); return 0; }