結果

問題 No.927 Second Permutation
ユーザー YamaKasa
提出日時 2019-11-29 01:45:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 549 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 173,232 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-20 13:06:54
合計ジャッジ時間 3,296 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    string X;
    cin >> X;
    int l = X.length();
    vector<int> a(l);
    for (int i = 0; i < l; i++) {
        a[i] = X[i] - '0';
    }
    sort(a.begin(), a.end(), greater<int>());
    if (prev_permutation(a.begin(), a.end())) {
        if (a[0] == 0) {
            cout << "-1";
        } else {
            for (int i : a) {
                cout << i;
            }
            cout << "\n";
        }
    } else {
        cout << "-1\n";
    }
    return 0;
}
0