結果

問題 No.927 Second Permutation
ユーザー KKT89KKT89
提出日時 2019-11-22 21:38:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 662 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 80,408 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-01 11:11:50
合計ジャッジ時間 1,999 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:46:17: 警告: ‘p’ may be used uninitialized [-Wmaybe-uninitialized]
   46 |         cout << p << endl;
      |                 ^
main.cpp:28:13: 備考: ‘p’ はここで定義されています
   28 |         int p;
      |             ^

ソースコード

diff #

#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;
}
0