結果

問題 No.927 Second Permutation
コンテスト
ユーザー Ichimiya
提出日時 2020-08-03 00:20:40
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 495 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,614 ms
コンパイル使用メモリ 190,328 KB
実行使用メモリ 198,300 KB
最終ジャッジ日時 2026-04-02 18:23:19
合計ジャッジ時間 3,228 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 RE * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	string X;
	cin >> X;

	string S = X;
	sort(S.begin(), S.end());
	string R = S;
	reverse(R.begin(), R.end());

	if (S.at(0) == S.at(S.size() - 1)) {
		cout << -1 << endl;
		return 0;
	}

	int ans = -1;
	for (int i = stoi(R)-1; i > 0; i--) {
		string s = to_string(i);
		sort(s.begin(), s.end());

		if (s == S) {
			ans = i;
			break;
		}
	}

	cout << ans << endl;
}
0