結果
問題 | No.927 Second Permutation |
ユーザー |
![]() |
提出日時 | 2019-11-22 21:53:16 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 546 bytes |
コンパイル時間 | 422 ms |
コンパイル使用メモリ | 56,904 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-11 03:25:07 |
合計ジャッジ時間 | 1,345 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include<iostream>using namespace std;int main(){string s;cin>>s;int fre[10];for(int i=0;i<10;i++)fre[i]=0;int n=s.length();for(int i=0;i<n;i++){fre[s[i]-'0']++;}string res;for(int i=9;i>=0;i--){while(fre[i]--)res+=char(i+'0');}int id=-1;for(int i=n-2;i>=0;i--){if(res[i]!=res[i+1]){id=i;break;}}if(id==-1){cout<<-1;return 0;}else swap(res[id],res[id+1]);if(res[0]!='0')cout<<res;else cout<<-1;}