結果
問題 |
No.927 Second Permutation
|
ユーザー |
|
提出日時 | 2021-05-10 21:49:56 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 713 bytes |
コンパイル時間 | 1,132 ms |
コンパイル使用メモリ | 118,796 KB |
最終ジャッジ日時 | 2025-01-21 09:51:42 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <algorithm> #include <array> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <numeric> #include <optional> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main() { string x; cin >> x; sort(x.rbegin(), x.rend()); string y = x; for (int64_t i = y.size() - 2; i >= 0; --i) { if (y[i] != y[i + 1]) { swap(y[i], y[i + 1]); break; } } bool ans = true; if (x == y) ans = false; if (y[0] == '0') ans = false; cout << (ans ? y : to_string(-1)) << endl; return 0; }