結果
| 問題 |
No.927 Second Permutation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-14 08:12:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 2,000 ms |
| コード長 | 551 bytes |
| コンパイル時間 | 1,647 ms |
| コンパイル使用メモリ | 175,752 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-26 22:36:33 |
| 合計ジャッジ時間 | 3,148 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
int main(){
string s; cin>>s;
int n=s.size();
vector<int> v;
rep(i,n){
v.push_back(stoi(s.substr(i,1)));
}
sort(rall(v));
bool flg=false;
while(!flg&&n>2){
n--;
if(v[n]!=v[n-1]) flg=true;
}
if(flg){
int t=v[n-1];
v[n-1]=v[n];
v[n]=t;
for(auto x:v) cout << x;
cout << endl;
} else { cout << "-1" << endl;
}
}