結果
| 問題 | No.927 Second Permutation |
| コンテスト | |
| ユーザー |
queee
|
| 提出日時 | 2019-11-22 21:54:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 590 bytes |
| 記録 | |
| コンパイル時間 | 1,027 ms |
| コンパイル使用メモリ | 55,124 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 03:26:12 |
| 合計ジャッジ時間 | 1,590 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 22 WA * 5 |
ソースコード
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
string s; cin >> s; int n = s.size();
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;
}
//cout << f1 << " " << f2 << endl;
if (f1 == 10 || f2 == 10) 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