結果
問題 |
No.927 Second Permutation
|
ユーザー |
|
提出日時 | 2020-04-01 15:43:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 735 bytes |
コンパイル時間 | 1,793 ms |
コンパイル使用メモリ | 170,644 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 22:15:21 |
合計ジャッジ時間 | 2,631 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll INF=1LL<<60; const int inf=1<<30; const int mod=1e4+7; int main(){ cin.tie(0); ios::sync_with_stdio(false); string x;cin >> x; sort(x.begin(),x.end()); reverse(x.begin(),x.end()); int n=x.size(); string s=x; for(int i=n-1;i>0;i--){ if(x[i]!=x[i-1]){ swap(x[i],x[i-1]); break; } } if(x[0]=='0'||x==s){ cout << -1 << endl; } else{ cout << x << endl; } }