結果
問題 |
No.3157 Nabeatsu
|
ユーザー |
|
提出日時 | 2025-05-23 19:41:12 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 1,680 bytes |
コンパイル時間 | 5,135 ms |
コンパイル使用メモリ | 333,884 KB |
実行使用メモリ | 12,064 KB |
最終ジャッジ日時 | 2025-05-23 19:41:48 |
合計ジャッジ時間 | 7,937 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; typedef long long ll; const int INF = 1<<30; const ll INFLL = 1LL<<60; const ll MOD = 998244353; const double INFD = 1.0E18; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; //const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; //const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using Pair = pair<ll, ll>; using Graph = vector<vector<pair<int, int>>>; using mint = atcoder::modint1000000007; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); string s; cin >> s; int n = s.size(); //最初にsが3の倍数かどうかを判定 vector<int> a(n); for (int i = 0; i < n; i++) a[i] = s[i] - '0'; while (true){ bool three = false; int mod = 0; for (int i = 0; i < n; i++){ if (three) a[i] = 9; else{ if (a[i] == 3){ three = true; a[i] = 2; mod = (mod + 2) % 3; } else{ mod = (mod + a[i]) % 3; } } } if (mod != 0) break; vector<int> na(n); for (int i = 0; i < n; i++) na[i] = a[i]; na[n - 1]--; for (int i = n - 1; i > 0; i--){ if (na[i] != -1) break; na[i] = 9; na[i - 1]--; } swap(a, na); } bool atama = true; for (int i = 0; i < n; i++){ if (a[i] == 0 && atama) continue; atama = false; cout << a[i]; } cout << endl; return 0; }