結果

問題 No.927 Second Permutation
ユーザー mmn15277198mmn15277198
提出日時 2020-07-02 21:32:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 712 bytes
コンパイル時間 719 ms
コンパイル使用メモリ 79,232 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-13 08:37:42
合計ジャッジ時間 4,639 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,196 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

int keta(long long x){
	int sum=0;
	while(x){
		sum++;	
		x/=10;
	}
	return sum;
}

int main() {
	string x;
	cin >> x;
	sort(x.begin(),x.end());
	
	bool same=true;
	for(int i=0;i<x.size()-1;i++){
		if(x[i]!=x[i+1]){
			same=false;
			break;
		}
	}
	
	if(same){
		cout << -1 << endl;
		return 0;
	}	
		
	vector<int> s;
	do{
		s.push_back(atoi(x.c_str()));
	}while(next_permutation(x.begin(),x.end()));
	
	if(s.size()==1){
		cout << -1 << endl;
		return 0;
	}
	
	if(keta(s[s.size()-2])<keta(s[s.size()-1])){
		cout << -1 << endl;
		return 0;
	}
	
	cout << s[s.size()-2] << endl;
	
	return 0;
}
0