結果
| 問題 |
No.927 Second Permutation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-23 14:19:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 491 bytes |
| コンパイル時間 | 2,110 ms |
| コンパイル使用メモリ | 193,256 KB |
| 最終ジャッジ日時 | 2025-01-08 05:30:52 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
string s;
cin >> s;
int cnt[10] = {};
for (char c : s) cnt[c - '0']++;
string t;
for (int i = 9; i >= 0; i--) for (int j = 0; j < cnt[i]; j++) t += i + '0';
if (prev_permutation(t.begin(), t.end())) {
if (t[0] == '0') {
cout << -1 << '\n';
} else {
cout << t << '\n';
}
} else {
cout << -1 << '\n';
}
return 0;
}