結果

問題 No.927 Second Permutation
ユーザー Ichimiya
提出日時 2020-08-03 00:20:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 495 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 171,224 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-19 20:56:19
合計ジャッジ時間 6,065 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 RE * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#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