結果

問題 No.3157 Nabeatsu
ユーザー tobbie
提出日時 2025-05-26 22:16:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 642 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 196,032 KB
実行使用メモリ 11,044 KB
最終ジャッジ日時 2025-05-26 22:16:39
合計ジャッジ時間 6,449 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 TLE * 1 -- * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    bool thr = false;
    rep(j, nn) {
      m = m * 10 + ns[j] % 3;
      if (ns[j] == 3)
	thr = true;
    }
    if (!thr && 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;
}
0