結果
| 問題 | No.927 Second Permutation |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-22 21:38:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 662 bytes |
| 記録 | |
| コンパイル時間 | 802 ms |
| コンパイル使用メモリ | 82,600 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 03:01:48 |
| 合計ジャッジ時間 | 2,030 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 17 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:46:17: warning: 'p' may be used uninitialized [-Wmaybe-uninitialized]
46 | cout << p << endl;
| ^
main.cpp:28:13: note: 'p' was declared here
28 | int p;
| ^
ソースコード
#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=1;i<10;i++){
if(cnt[i])ok++;
}
if(ok==1){
cout << -1 << endl;
return 0;
}
int p;
for(int i=0;i<10;i++){
if(cnt[i]>0){
for(int j=i+1;j<10;j++){
if(cnt[j]>0){
p=j;
cnt[j]--;
break;
}
}
break;
}
}
for(int i=9;i>=0;i--){
for(int j=0;j<cnt[i];j++){
cout << i;
}
}
cout << p << endl;
}