結果
問題 | No.927 Second Permutation |
ユーザー |
![]() |
提出日時 | 2019-11-22 21:31:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 758 bytes |
コンパイル時間 | 1,586 ms |
コンパイル使用メモリ | 162,532 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 02:53:28 |
合計ジャッジ時間 | 2,664 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include "bits/stdc++.h" #define REP(i, n) for(int i = 0; i < int(n); i++) #define FOR(i,n,m) for(int i = int(n); i < int(m); i++) using namespace std; typedef long long ll; const int MOD = 1e9 + 7; const int INF = 1e9 + 6; const ll LLINF = 1e18 + 1; int main() { string s; cin >> s; sort(s.rbegin(), s.rend()); bool same = true; REP(i, s.size()) { if (s[0] != s[i]) { same = false; } } if (same) { puts("-1"); return 0; } for (int i = s.size() - 1; i >= 0; i--) { if (s[i] != s[s.size() - 1]) { swap(s[i], s[i + 1]); break; } } if (s[0] == '0') { puts("-1"); } else { cout << s << endl; } return 0; }