結果
問題 | No.927 Second Permutation |
ユーザー |
![]() |
提出日時 | 2019-12-13 00:15:02 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 841 bytes |
コンパイル時間 | 14,732 ms |
コンパイル使用メモリ | 226,048 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 00:30:53 |
合計ジャッジ時間 | 16,217 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
package mainimport ("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 := 0for p < len(chars)-1 && chars[p] == chars[p+1] {p++}ok := falsefor i := p; i < len(chars); i++ {if chars[p] != chars[i] {chars[p], chars[i] = chars[i], chars[p]ok = truebreak}}if ok {var sb strings.Builderfor 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()}