結果

問題 No.3157 Nabeatsu
ユーザー it_is_a_pity_
提出日時 2025-05-23 19:55:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,321 bytes
コンパイル時間 3,976 ms
コンパイル使用メモリ 251,716 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-23 19:55:45
合計ジャッジ時間 6,705 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(v) v.begin(),v.end()
const ll INF = (ll)2e18;

void f(string &S){
    

    bool FIND = false;

    rep(i,S.size()){
        if(S[i]=='3'){
            S[i] = '2';
            FIND = true;

            for (ll j = i + 1; j < S.size(); j++){
                S[j] = '9';
            }
            break;
        }
    }

    ll sum = 0;
    rep(i,S.size()){
        sum += S[i] - '0';
    }
    sum %= 3;

    if(sum!=0){
        cout << S << endl;
        return;
    }


    if(sum==0){
        if(S.back()=='0'){
            rep(i,S.size()){
                if(S[S.size()-1-i]!='0'){
                    S[S.size() - 1 - i] = char(S[S.size() - 1 - i] - 1);
                    for (ll pos = S.size() - 1 - i; pos < S.size();pos++){
                        S[pos] = '9';
                    }
                    break;
                }
            }
            cout << S << endl;
        }
        else{
            S.back() = char(S.back() - 1);
            cout << S << endl;
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string N;
    cin >> N;
    f(N);
}
0