結果
| 問題 |
No.927 Second Permutation
|
| コンテスト | |
| ユーザー |
mag
|
| 提出日時 | 2020-06-18 14:21:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 658 bytes |
| コンパイル時間 | 1,924 ms |
| コンパイル使用メモリ | 179,668 KB |
| 実行使用メモリ | 13,760 KB |
| 最終ジャッジ日時 | 2024-07-03 12:46:11 |
| 合計ジャッジ時間 | 5,370 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 TLE * 1 -- * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
int main(){
cin.tie(nullptr);ios_base::sync_with_stdio(false);
string x;cin>>x;
vector<char> vec;
rep(i,x.size()){
vec.push_back(x[i]);
}
sort(vec.begin(),vec.end());
string shake;
vector<int> hoge;
do {
shake="";
rep(i,x.size()){
shake+=vec[i];
}
if(shake[0]!='0')hoge.push_back(stoi(shake));
}while(next_permutation(vec.begin(),vec.end()));
if(hoge.size()!=1){
sort(hoge.rbegin(),hoge.rend());
cout<<hoge[1]<<endl;
}else{
cout<<-1<<endl;
}
}
mag