結果

問題 No.938 賢人を探せ
ユーザー kat0rikkat0rik
提出日時 2020-01-06 13:00:03
言語 Go
(1.22.1)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 13,663 ms
コンパイル使用メモリ 202,312 KB
実行使用メモリ 14,356 KB
最終ジャッジ日時 2023-08-21 03:42:50
合計ジャッジ時間 18,314 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 425 ms
14,356 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 178 ms
7,568 KB
testcase_09 AC 180 ms
7,580 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 210 ms
7,448 KB
testcase_12 AC 177 ms
7,416 KB
testcase_13 AC 177 ms
7,404 KB
testcase_14 AC 174 ms
7,324 KB
testcase_15 AC 176 ms
7,404 KB
testcase_16 AC 174 ms
7,392 KB
testcase_17 AC 175 ms
7,376 KB
testcase_18 AC 177 ms
7,408 KB
testcase_19 AC 175 ms
7,412 KB
testcase_20 AC 177 ms
7,408 KB
testcase_21 AC 178 ms
7,404 KB
testcase_22 AC 257 ms
14,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"sort"
)

type student struct {
	id   int
	name string
	bad  bool
}

type sts []student

func (s sts) Len() int {
	return len(s)
}
func (s sts) Less(i, j int) bool {
	return s[i].id < s[j].id
}
func (s sts) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	var N int
	fmt.Scan(&N)
	students := make(map[string]student, 0)
	for i := 0; i < N; i++ {
		sta := new(student)
		stb := new(student)
		fmt.Scan(&sta.name, &stb.name)
		if v, ok := students[sta.name]; !ok {
			sta.id = i
			sta.bad = true
			students[sta.name] = *sta
		} else {
			v.bad = true
			students[sta.name] = v
		}
		if _, ok := students[stb.name]; !ok {
			stb.id = i
			students[stb.name] = *stb
		}
	}
	a := make([]student, 0)
	for _, v := range students {
		if !v.bad {
			a = append(a, v)
		}
	}
	sort.Sort(sts(a))
	for i := range a {
		fmt.Println(a[i].name)
	}
}
0