結果
| 問題 | 
                            No.3157 Nabeatsu
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tobbie
                         | 
                    
| 提出日時 | 2025-05-26 22:43:42 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 768 bytes | 
| コンパイル時間 | 1,851 ms | 
| コンパイル使用メモリ | 196,564 KB | 
| 実行使用メモリ | 8,356 KB | 
| 最終ジャッジ日時 | 2025-05-26 22:43:47 | 
| 合計ジャッジ時間 | 5,377 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 22 WA * 23 | 
ソースコード
#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 m = 0;
    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++;
      }
    }
    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;
}
            
            
            
        
            
tobbie