結果
問題 | No.927 Second Permutation |
ユーザー |
|
提出日時 | 2022-03-06 13:39:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 457 bytes |
コンパイル時間 | 1,597 ms |
コンパイル使用メモリ | 171,108 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 23:08:26 |
合計ジャッジ時間 | 3,452 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include<bits/stdc++.h>using namespace std;int main(){string S;cin>>S;int A[202020];int N=S.size();for(int i=1;i<=N;i++)A[i]=S[i-1]-'0';sort(A+1,A+N+1);int count=0;if(A[N]==A[1])count++;int z=0;for(int i=1;i<=N;i++)if(A[i]==0)z++;if(z==N-1)count++;if(count>0)cout<<-1;else {int U=0;for(int i=1;i<=N;i++){if(A[1]!=A[i]&&U==0)U=i;}swap(A[U-1],A[U]);for(int i=N;i>=1;i--)cout<<A[i];}}