結果
問題 |
No.927 Second Permutation
|
ユーザー |
![]() |
提出日時 | 2019-12-15 22:05:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 567 bytes |
コンパイル時間 | 1,798 ms |
コンパイル使用メモリ | 171,664 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 18:22:07 |
合計ジャッジ時間 | 6,108 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | RE * 27 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ string x; int n=x.length(); vector<int> y(n); for(int i=0;i<n;i++){ int s=x[i]-'0'; y[i]=s; } if(y[n-2]==y[n-1]){ cout << -1 << endl; return 0; } else if(n==2 && y[n-1]==0){ cout << -1 << endl; return 0; } sort(y.rbegin(),y.rend()); vector<int> z(n); for(int i=0;i<n-2;i++){ z[i]=y[i]; } z[n-2]=y[n-1]; z[n-1]=y[n-2]; for(int i=0;i<n;i++){ cout << z[i]; } cout << endl; }