結果
問題 | No.927 Second Permutation |
ユーザー |
![]() |
提出日時 | 2024-11-13 17:32:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 515 bytes |
コンパイル時間 | 1,952 ms |
コンパイル使用メモリ | 196,644 KB |
最終ジャッジ日時 | 2025-02-25 04:06:09 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N = S.size(); sort(S.rbegin(), S.rend()); for (int i = N - 1; i >= 1; i--) { if (S[i] != S[i - 1]) { swap(S[i], S[i - 1]); if (S[0] != '0') { cout << S; return 0; } else { cout << -1; return 0; } } } cout << -1; return 0; }