結果
問題 |
No.927 Second Permutation
|
ユーザー |
![]() |
提出日時 | 2020-07-02 21:32:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 712 bytes |
コンパイル時間 | 820 ms |
コンパイル使用メモリ | 79,544 KB |
実行使用メモリ | 13,884 KB |
最終ジャッジ日時 | 2024-09-15 05:48:08 |
合計ジャッジ時間 | 4,732 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 TLE * 1 -- * 21 |
ソースコード
#include <string> #include <vector> #include <iostream> #include <algorithm> #include <functional> using namespace std; int keta(long long x){ int sum=0; while(x){ sum++; x/=10; } return sum; } int main() { string x; cin >> x; sort(x.begin(),x.end()); bool same=true; for(int i=0;i<x.size()-1;i++){ if(x[i]!=x[i+1]){ same=false; break; } } if(same){ cout << -1 << endl; return 0; } vector<int> s; do{ s.push_back(atoi(x.c_str())); }while(next_permutation(x.begin(),x.end())); if(s.size()==1){ cout << -1 << endl; return 0; } if(keta(s[s.size()-2])<keta(s[s.size()-1])){ cout << -1 << endl; return 0; } cout << s[s.size()-2] << endl; return 0; }