結果
| 問題 |
No.927 Second Permutation
|
| コンテスト | |
| ユーザー |
kya_ski
|
| 提出日時 | 2019-11-22 22:03:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 686 bytes |
| コンパイル時間 | 1,603 ms |
| コンパイル使用メモリ | 170,796 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 03:41:33 |
| 合計ジャッジ時間 | 2,628 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int n = s.length();
bool same = true, one = true;
for (int i = 0; i < n-1; i++) {
if (s[i] != s[i+1]) same = false;
}
sort(s.begin(), s.end());
reverse(s.begin(), s.end());
if (s[1] != '0') one = false;
if (same == false && one == false) {
reverse(s.begin(), s.end());
for (int i = 1; i < n; i++) {
if (s[i] != '0') {
swap(s[i], s[i-1]);
break;
}
}
reverse(s.begin(), s.end());
cout << s << endl;
} else {
cout << -1 << endl;
}
return 0;
}
kya_ski