본문 바로가기

USACO/Bronze

백준 18268 Cow Gymnastics (USACO December 2019 Bronze 1번)

문제 링크: https://www.acmicpc.net/problem/18268

 

18268번: Cow Gymnastics

The consistent pairs of cows are $(1,4)$, $(2,4)$, $(3,4)$, and $(1,3)$.

www.acmicpc.net

각각의 pair에 대해서 K sessions 동안 한마리가 다른 한마리보다 계속 등수가 앞서면 답을 1 증가시킴.

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
#include <bits/stdc++.h>
using namespace std;
 
int N, K, ranking[11][21];
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> K >> N;
    for(int i = 0; i < K; i++for(int j = 0; j < N; j++) {
        int r;
        cin >> r;
        ranking[i][r] = j;
    }
 
    int ans = 0;
    for(int i = 1; i <= N; i++for(int j = 1; j <= N; j++) {
        if(i == j) continue;
        bool ok = true;
        for(int k = 0; k < K; k++) {
            if(ranking[k][i] > ranking[k][j]) ok = false;
        }
        if(ok) ans++;
    }
 
    cout << ans << '\n';
    return 0;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter