結果
問題 | No.927 Second Permutation |
ユーザー |
![]() |
提出日時 | 2019-11-22 21:27:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,003 bytes |
コンパイル時間 | 1,107 ms |
コンパイル使用メモリ | 114,040 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-11 02:49:49 |
合計ジャッジ時間 | 2,065 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:44:15: warning: 'k' may be used uninitialized [-Wmaybe-uninitialized] 44 | }else if(k==n-1){ | ^~ main.cpp:35:13: note: 'k' was declared here 35 | int k; | ^
ソースコード
#include <cstdio>#include <cstring>#include <iostream>#include <string>#include <cmath>#include <bitset>#include <vector>#include <map>#include <set>#include <queue>#include <deque>#include <algorithm>#include <complex>#include <unordered_map>#include <unordered_set>#include <random>#include <cassert>#include <fstream>#include <utility>#include <functional>#include <time.h>#include <stack>#include <array>#define popcount __builtin_popcountusing namespace std;typedef long long int ll;typedef pair<int, int> P;int main(){string x;cin>>x;sort(x.begin(), x.end(), greater<char>());int n=x.size();int k;for(int i=n-1; i>=0; i--){if(x[i]!='0'){k=i;break;}}if(k==0){cout<<-1<<endl;}else if(k==n-1){bool ok=0;for(int i=0; i<n-1; i++){if(x[i]!=x[i+1]){ok=1;break;}}if(!ok){cout<<-1<<endl;return 0;}swap(x[n-1], x[n-2]);cout<<x<<endl;}else{swap(x[k], x[k+1]);cout<<x<<endl;}return 0;}