結果
問題 | No.3157 Nabeatsu |
ユーザー |
|
提出日時 | 2025-05-05 03:08:50 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 800 bytes |
コンパイル時間 | 3,350 ms |
コンパイル使用メモリ | 278,452 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2025-05-05 03:12:06 |
合計ジャッジ時間 | 5,999 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h> using namespace std; bool is_nabeatsu(string N){ int digitsum = 0; for (char c:N) digitsum += c - '0'; return digitsum % 3 ==0 || find(N.begin(), N.end(), '3') != N.end(); } int main(){ string N; cin >> N; assert(N.size() <= 1000000 || N == "1" + string(1000000, '0')); assert(N[0] != '0'); while (is_nabeatsu(N)){ auto it = find(N.begin(), N.end(), '3'); if (it == N.end()){ for (int i = N.size() - 1;; i--){ if (N[i] == '0') N[i] = '9'; else{ N[i]--; break; } } } else{ *it = '2'; while(++it != N.end()) *it = '9'; } } cout << N << endl; return 0; }