結果

問題 No.927 Second Permutation
ユーザー IchimiyaIchimiya
提出日時 2020-08-03 00:20:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 495 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 168,508 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-27 03:33:57
合計ジャッジ時間 5,117 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 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 AC 5 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 4 ms
4,376 KB
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() {
	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