結果
| 問題 | No.3157 Nabeatsu | 
| コンテスト | |
| ユーザー |  tobbie | 
| 提出日時 | 2025-05-26 22:49:05 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 83 ms / 2,000 ms | 
| コード長 | 770 bytes | 
| コンパイル時間 | 2,209 ms | 
| コンパイル使用メモリ | 196,356 KB | 
| 実行使用メモリ | 8,292 KB | 
| 最終ジャッジ日時 | 2025-05-26 22:49:11 | 
| 合計ジャッジ時間 | 5,439 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 45 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
int main() {
  string n;
  cin >> n;
  vector<int> ns((int)n.size());
  int nn = (int)n.size();
  rep(i, nn)
    ns[i] =  n[i] - '0';
  bool ok = false;  
  while (!ok) {
    int thr = -1;
    rep(j, nn) {
      if (ns[j] == 3 && thr < 0)
	thr = j;
    }
    if (thr >= 0) {
      ns[thr] = 2; thr++;
      while (thr < nn) {
	ns[thr] = 9;
	thr++;
      }
    }
    int m = 0;
    rep(j, nn) {
      m = (m * 10 + ns[j]) % 3;
    }
    if (m % 3 != 0) {
      rep(j, nn)
	cout << ns[j];
      cout << endl;
      ok = true;
    } else {
      int j = nn - 1;
      ns[j]--;
      while (j > 0 && ns[j] < 0) {
	ns[j] += 10;
	j--;
	ns[j]--;
      }
    }
  }
  return 0;
}
            
            
            
        