結果
| 問題 |
No.927 Second Permutation
|
| コンテスト | |
| ユーザー |
Ichimiya
|
| 提出日時 | 2020-08-03 00:34:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 571 bytes |
| コンパイル時間 | 1,804 ms |
| コンパイル使用メモリ | 171,852 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 01:28:21 |
| 合計ジャッジ時間 | 2,637 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#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;
}
bool b = false;
for (int i = R.size()-1; i > 0; i--) {
if (R.at(i) != R.at(i - 1)) {
char ch = R.at(i);
R.at(i) = R.at(i - 1);
R.at(i - 1) = ch;
b = true;
break;
}
}
if (R.at(0) == '0') b = false;
cout << (b ? R : "-1") << endl;
}
Ichimiya