結果
| 問題 |
No.927 Second Permutation
|
| コンテスト | |
| ユーザー |
queee
|
| 提出日時 | 2019-11-22 21:55:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 654 bytes |
| コンパイル時間 | 430 ms |
| コンパイル使用メモリ | 56,344 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-11 03:30:00 |
| 合計ジャッジ時間 | 1,468 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
string s; cin >> s; int n = s.size(), num123456789=0;
int nm[10]; fill(nm, nm+10, 0); int f1=10, f2=10;
for(int i=0; i<n; i++) {
int now = s[i]-'0';
nm[now]++;
if (now < f1) f2=f1, f1=now;
else if (f1 < now && now < f2) f2=now;
num123456789 += now>1;
}
//cout << f1 << " " << f2 << endl;
if (f1 == 10 || f2 == 10 || num123456789 <= 1) return puts("-1") * 0;
for(int i=9; i>=0; i--) {
for(int j=0; j<nm[i]; j++) {
if (j == 0 && i == f1) cout << f2;
else if (j == nm[i]-1 && i == f2) cout << f1;
else cout << i;
}
}
}
queee