結果
問題 |
No.927 Second Permutation
|
ユーザー |
![]() |
提出日時 | 2020-08-03 00:19:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 503 bytes |
コンパイル時間 | 1,802 ms |
コンパイル使用メモリ | 171,352 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-19 20:52:38 |
合計ジャッジ時間 | 5,783 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 RE * 22 |
ソースコード
#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; }