結果
| 問題 |
No.3157 Nabeatsu
|
| コンテスト | |
| ユーザー |
SnowBeenDiding
|
| 提出日時 | 2025-05-23 19:18:18 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 1,170 bytes |
| コンパイル時間 | 5,186 ms |
| コンパイル使用メモリ | 335,116 KB |
| 実行使用メモリ | 8,244 KB |
| 最終ジャッジ日時 | 2025-05-23 19:18:27 |
| 合計ジャッジ時間 | 7,625 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;
typedef long long ll;
string san_nasi(string s) {
int n = s.size();
string ret;
bool san = 0;
rep(i, 0, n) {
if (san) {
ret += '9';
continue;
} else if (s[i] == '3') {
san = 1;
ret += '2';
continue;
}
ret += s[i];
}
return ret;
}
string dec(string s) {
int n = s.size();
reverse(s.begin(), s.end());
s[0]--;
rep(i, 0, n) {
if (s[i] < '0') {
s[i + 1]--;
s[i] = '9';
}
}
while (s.back() == '0')
s.pop_back();
reverse(s.begin(), s.end());
return s;
}
bool san(string s) {
int sum = 0;
for (auto c : s) {
sum += c - '0';
}
return sum % 3 == 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
s = san_nasi(s);
while (1) {
if (!san(s))
break;
s = dec(s);
s = san_nasi(s);
}
cout << s << endl;
}
SnowBeenDiding