結果
問題 | No.927 Second Permutation |
ユーザー |
![]() |
提出日時 | 2019-12-07 02:27:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 515 bytes |
コンパイル時間 | 1,864 ms |
コンパイル使用メモリ | 172,952 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 06:27:21 |
合計ジャッジ時間 | 2,754 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>#define rep(i,n) for(int i=0;i<(n);++i)#define all(a) (a).begin(),(a).end()using namespace std;typedef long long ll;string f(string s) {string ret = "";for (auto c: s) {ret += ('9' - c) + '0';}return ret;}int main() {ios::sync_with_stdio(false);cin.tie(0);string S;cin >> S;sort(S.rbegin(), S.rend());string T = f(S);next_permutation(all(T));T = f(T);if (T[0] == '0' || T == S) {cout << -1 << endl;}else {cout << T << endl;}return 0;}