結果
問題 | No.927 Second Permutation |
ユーザー |
|
提出日時 | 2020-04-01 20:31:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,053 bytes |
コンパイル時間 | 1,720 ms |
コンパイル使用メモリ | 176,756 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-27 05:56:30 |
合計ジャッジ時間 | 2,708 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; int main(){ string x; cin >> x; map<char,int> mp; rep(i,x.size()){ mp[x[i]] ++; } if(mp.size() == 1){ cout << -1 << endl; return 0; } if(mp.size() == 2 && mp.find('0') != mp.end()){ if(mp['0'] == x.size()-1){ cout << -1 << endl; return 0; } } bool fi = true,se = false ; char f,s; for(auto p:mp){ if(fi){ f= p.first;fi = false;se = true;} else if(se){s = p.first;break;} } mp[s] --; mp[f] --; string ans = ""; for(auto p:mp){ rep(i,p.second){ ans += p.first ; } if(p.first == f) {ans += s; ans += f;} } reverse(ans.begin(),ans.end()); cout << ans << endl; return 0; }