結果

問題 No.3157 Nabeatsu
ユーザー BunnyHunger
提出日時 2025-07-12 02:59:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 857 bytes
コンパイル時間 2,246 ms
コンパイル使用メモリ 194,388 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-07-12 03:00:02
合計ジャッジ時間 6,779 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool check1(const string &s) {
    return count(s.begin(), s.end(), '3') > 0;
}

bool check2(const string &s) {
    int x = 0;
    for(char c : s) x = (x + c - '0');
    return x % 3 == 0;
}

int main() {
    string s;
    cin >> s;
    while(check1(s) or check2(s)) {
        if(check1(s)) {
            for(int i = 0; i < s.size(); i ++) {
                if(s[i] == '3') {
                    s[i] = '2';
                    for(int j = i + 1; j < s.size(); j ++) s[j] = '9';
                    break;
                }
            }
        }else{
            for(int i = s.size() - 1; i >= 0; i --) {
                if(s[i] > '0') {
                    s[i] --;
                    break;
                }
                s[i] = '9';
            }
        }
    }
    cout << s << "\n";
    return 0;
}
0