結果
| 問題 |
No.927 Second Permutation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-22 21:36:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 700 bytes |
| コンパイル時間 | 1,206 ms |
| コンパイル使用メモリ | 99,420 KB |
| 最終ジャッジ日時 | 2025-01-08 04:43:13 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cstdlib>
#include <queue>
#include <map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> Pii;
const ll mod = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string x;
cin >> x;
int l = x.length();
map<char, int> count;
for (auto &c: x) count[c]++;
if (count.size() == 1 || count['0'] >= l-1) {
cout << -1 << endl; // impossible
return 0;
}
sort(x.begin(), x.end());
int p = 1;
while (x[p-1] == x[p]) p++;
swap(x[p-1], x[p]);
reverse(x.begin(), x.end());
cout << x << endl;
return 0;
}