작성일 :

문제 링크

10708번 - 크리스마스 파티

설명

매 게임마다 정답을 맞힌 사람은 1점, 타겟은 추가로 오답 수만큼 점수를 얻습니다. 모든 게임의 합계를 구하는 문제입니다.


접근법

각 게임에서 타겟을 알고 있으므로, 모든 친구의 선택을 확인해 맞힌 사람에게 1점을 더합니다.

맞힌 사람 수를 이용해 오답 수를 계산하고, 타겟에게 추가 점수를 더합니다.

이를 M번 반복해 점수를 출력합니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine()!);
    var m = int.Parse(Console.ReadLine()!);
    var targets = Console.ReadLine()!.Split();

    var score = new int[n];
    for (var i = 0; i < m; i++) {
      var target = int.Parse(targets[i]) - 1;
      var picks = Console.ReadLine()!.Split();

      var correct = 0;
      for (var j = 0; j < n; j++) {
        if (int.Parse(picks[j]) - 1 == target) {
          score[j]++;
          correct++;
        }
      }

      score[target] += n - correct;
    }

    for (var i = 0; i < n; i++)
      Console.WriteLine(score[i]);
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m; cin >> n >> m;
  vi target(m);
  for (int i = 0; i < m; i++) {
    cin >> target[i];
    target[i]--;
  }

  vi score(n, 0);
  for (int i = 0; i < m; i++) {
    int correct = 0;
    for (int j = 0; j < n; j++) {
      int pick; cin >> pick;
      if (pick - 1 == target[i]) {
        score[j]++;
        correct++;
      }
    }
    score[target[i]] += n - correct;
  }

  for (int i = 0; i < n; i++)
    cout << score[i] << "\n";

  return 0;
}