結果
| 問題 |
No.927 Second Permutation
|
| コンテスト | |
| ユーザー |
cureskol
|
| 提出日時 | 2020-03-19 20:24:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 700 bytes |
| コンパイル時間 | 1,755 ms |
| コンパイル使用メモリ | 178,672 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-14 03:28:01 |
| 合計ジャッジ時間 | 3,371 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<typename T>
void fin(T a){
cout<<a<<endl;
exit(0);
}
typedef pair<int,int> P;
signed main(){
string s;cin>>s;
map<char,int> m;
for(char p:s)m[p]++;
vector<P> v;
for(auto p:m){
int a=p.first-'0',b=p.second;
v.push_back(P(a,b));
}
reverse(v.begin(),v.end());
if(v.size()==1)fin(-1);
if(v[0].second==1&&v[1].first==0)fin(-1);
for(int i=0;i<v.size()-2;i++)while(v[i].second--)cout<<v[i].first;
for(int i=0;i<v[v.size()-2].second-1;i++)cout<<v[v.size()-2].first;
cout<<v.back().first;
cout<<v[v.size()-2].first;
for(int i=0;i<v.back().second-1;i++)cout<<v.back().first;
cout<<endl;
}
cureskol