結果

問題 No.927 Second Permutation
ユーザー IchimiyaIchimiya
提出日時 2020-08-03 00:19:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 503 bytes
コンパイル時間 1,572 ms
コンパイル使用メモリ 168,812 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 03:29:30
合計ジャッジ時間 6,637 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

	string S = to_string(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