結果

問題 No.927 Second Permutation
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-12-13 00:15:02
言語 Go
(1.22.1)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 11,780 ms
コンパイル使用メモリ 211,696 KB
実行使用メモリ 5,496 KB
最終ジャッジ日時 2023-09-08 07:14:29
合計ジャッジ時間 14,198 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 6 ms
4,380 KB
testcase_11 AC 10 ms
5,488 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 7 ms
5,480 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 12 ms
5,492 KB
testcase_17 AC 11 ms
5,492 KB
testcase_18 AC 11 ms
5,492 KB
testcase_19 AC 11 ms
5,492 KB
testcase_20 AC 11 ms
5,496 KB
testcase_21 AC 11 ms
5,496 KB
testcase_22 AC 11 ms
5,492 KB
testcase_23 AC 11 ms
5,496 KB
testcase_24 AC 4 ms
5,472 KB
testcase_25 AC 3 ms
4,384 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 6 ms
5,488 KB
testcase_29 AC 6 ms
5,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanLines)
	stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))

	x := read(stdin)
	chars := strings.Split(x, "")
	sort.Strings(chars)

	p := 0
	for p < len(chars)-1 && chars[p] == chars[p+1] {
		p++
	}

	ok := false
	for i := p; i < len(chars); i++ {
		if chars[p] != chars[i] {
			chars[p], chars[i] = chars[i], chars[p]
			ok = true
			break
		}
	}

	if ok {
		var sb strings.Builder
		for i := len(chars) - 1; i >= 0; i-- {
			sb.WriteString(chars[i])
		}

		y := sb.String()
		if strings.HasPrefix(y, "0") {
			fmt.Println(-1)
		} else {
			fmt.Println(y)
		}
	} else {
		fmt.Println(-1)
	}
}

func read(stdin *bufio.Scanner) string {
	stdin.Scan()
	return stdin.Text()
}
0