結果

問題 No.927 Second Permutation
ユーザー cureskolcureskol
提出日時 2020-03-19 20:24:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 1,402 ms
コンパイル使用メモリ 175,676 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 21:05:44
合計ジャッジ時間 3,251 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 6 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 11 ms
4,376 KB
testcase_20 AC 10 ms
4,376 KB
testcase_21 AC 10 ms
4,376 KB
testcase_22 AC 9 ms
4,380 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0