結果
問題 | No.927 Second Permutation |
ユーザー |
|
提出日時 | 2019-11-22 21:55:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 789 bytes |
コンパイル時間 | 678 ms |
コンパイル使用メモリ | 82,860 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-11 03:27:27 |
合計ジャッジ時間 | 1,637 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:49:33: warning: 'q' may be used uninitialized [-Wmaybe-uninitialized] 49 | cout << q << p; | ^ main.cpp:32:15: note: 'q' was declared here 32 | int p,q; | ^ main.cpp:49:38: warning: 'p' may be used uninitialized [-Wmaybe-uninitialized] 49 | cout << q << p; | ^ main.cpp:32:13: note: 'p' was declared here 32 | int p,q; | ^
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <queue>#include <map>#include <set>#include <math.h>using namespace std;typedef long long int ll;int cnt[10];int main(){cin.tie(nullptr);ios::sync_with_stdio(false);string s; cin >> s;int ok=0;for(char c:s){cnt[c-'0']++;}for(int i=0;i<10;i++){if(cnt[i])ok++;}if(ok==1){cout << -1 << endl;return 0;}if(ok==2&&s.size()-cnt[0]==1){cout << -1 << endl;return 0;}int p,q;for(int i=0;i<10;i++){if(cnt[i]>0){q=i;for(int j=i+1;j<10;j++){if(cnt[j]>0){p=j;cnt[i]--;cnt[j]--;break;}}break;}}for(int i=9;i>=0;i--){if(i==q){cout << q << p;}for(int j=0;j<cnt[i];j++){cout << i;}}cout << endl;}