結果
問題 |
No.927 Second Permutation
|
ユーザー |
|
提出日時 | 2020-04-01 20:29:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,141 bytes |
コンパイル時間 | 1,887 ms |
コンパイル使用メモリ | 176,984 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 05:51:43 |
合計ジャッジ時間 | 2,939 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 10 WA * 17 |
ソースコード
#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;} } cout << s << endl; mp[s] --; mp[f] --; string ans = ""; for(auto p:mp){ cout << p.first << " " << p.second << endl; 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; }