結果
問題 | No.927 Second Permutation |
ユーザー |
![]() |
提出日時 | 2019-11-22 21:28:11 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 611 bytes |
コンパイル時間 | 715 ms |
コンパイル使用メモリ | 77,544 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 02:50:59 |
合計ジャッジ時間 | 1,710 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); string x; cin >> x; int n = x.size(); sort(x.begin(), x.end()); for (int i = 1; i < n; i++) { if (x[i - 1] != x[i]) { swap(x[i - 1], x[i]); if (x.back() == '0') break; reverse(x.begin(), x.end()); cout << x << endl; exit(0); } } cout << -1 << endl; return 0; }