ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

10708๋ฒˆ: ํฌ๋ฆฌ์Šค๋งˆ์Šค ํŒŒํ‹ฐ

JOI๋Š” ์นœ๊ตฌ 1๋ถ€ํ„ฐ ์นœ๊ตฌ N๊นŒ์ง€ ์ด N ๋ช…์˜ ์นœ๊ตฌ์™€ ํ•จ๊ป˜, ํฌ๋ฆฌ์Šค๋งˆ์Šค ํŒŒํ‹ฐ์— ๊ฐ”์Šต๋‹ˆ๋‹ค. ํฌ๋ฆฌ์Šค๋งˆ์Šค ํŒŒํ‹ฐ ๋ถ„์œ„๊ธฐ๋„ ๋‹ฌ์•„์˜ค๋ฅด๋‹ˆ, JOI๋Š” ์นœ๊ตฌ๋“ค๊ณผ ํ•จ๊ป˜ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒŒ์ž„์„ ํ•˜๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ฐ€์žฅ ๋จผ์ €, JO

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ Go

// https://www.acmicpc.net/problem/10708
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, m int
	fmt.Fscanln(reader, &n)
	fmt.Fscanln(reader, &m)

	var targets = make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Fscanf(reader, "%d ", &targets[i])
	}

	var scores = make([]int, n)
	for i := 0; i < m; i++ {
		var target = targets[i]
		var writes = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%d ", &writes[j])
			if writes[j] == target {
				scores[j]++
			} else {
				scores[target-1]++
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, scores[i])
	}
}

๐ŸŽจ Python3

# https://www.acmicpc.net/problem/10708
import sys

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    m = int(sys.stdin.readline())

    targets = list(map(int, sys.stdin.readline().split()))
    scores = [0 for i in range(n)]
    for i in range(m):
        target = targets[i]
        writes = list(map(int, sys.stdin.readline().split()))
        for j in range(n):
            if writes[j] == target:
                scores[j] += 1
            else:
                scores[target-1] += 1
    
    for i in range(n):
        print(scores[i])
728x90
๋Œ“๊ธ€