結果

問題 No.927 Second Permutation
ユーザー hirono999hirono999
提出日時 2019-11-22 22:53:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,383 bytes
コンパイル時間 1,627 ms
コンパイル使用メモリ 163,328 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 12:16:19
合計ジャッジ時間 2,685 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 5 ms
6,940 KB
testcase_17 AC 5 ms
6,944 KB
testcase_18 AC 6 ms
6,944 KB
testcase_19 AC 5 ms
6,944 KB
testcase_20 AC 6 ms
6,940 KB
testcase_21 AC 5 ms
6,940 KB
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 5 ms
6,944 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 3 ms
6,944 KB
testcase_28 AC 4 ms
6,940 KB
testcase_29 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

string solve(string X){
    sort(ALL(X));
    reverse(ALL(X));
    string ans = X;

    ll i = sz(X)-2;
    while(i >= 0){
        if(ans[i+1]!=ans[i]){
            char tp = ans[i];
            ans[i] = ans[i+1];
            ans[i+1] = tp;
            break;
        }
        i--;
    }

    if(ans[0] == '0' || ans == X) return "-1";
    else return ans;

}

int main(){
    string X; cin >> X;
    pr(solve(X));
    return 0;
}
0