結果
問題 |
No.3157 Nabeatsu
|
ユーザー |
|
提出日時 | 2025-07-15 22:13:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 1,300 bytes |
コンパイル時間 | 4,313 ms |
コンパイル使用メモリ | 253,544 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-07-15 22:13:34 |
合計ジャッジ時間 | 8,860 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } ll inf_ll = 9223372036854775807; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) using mint = atcoder::modint998244353; using mint1 = atcoder::modint1000000007; using Pa = std::pair<ll, ll>; int Yes(bool x){ if(x) cout << "Yes"; else cout << "No"; cout << endl; return 0; } string f(string &S){ ll N = S.size(); bool x = false; ll M = 0; rep(i, N){ if(x){ S[i] = '9'; continue; } if(S[i] == '3'){ x = true; S[i] = '2'; } M += (S[i] - '0'); } if(x) return f(S); if(M % 3 > 0) return S; ll j = N-1; while(j >= 0){ if(S[j] > '0'){ S[j] = S[j] - 1; break; } S[j] = '9'; j--; } return f(S); } int main(){ string N; cin >> N; string ans = f(N); bool x = true; for(auto i : ans){ if(i == '0' && x) continue; x = false; cout << i; } }