[SWEA] 시험

문제 보러가기

제한사항

각 테스트 케이스의 첫 번째 줄에는 N, T, P가 공백으로 구분되어 주어진다. (1 ≤ P ≤ N ≤ 2000, 1 ≤ T ≤ 2000)

첫번째 생각

INPUT이 매우 많은 문제이므로, bufferedReader를 사용하기로 한다.

시뮬레이션 문제로 따라하면 무난하게 풀릴 것이라고 생각했다.

문제를 풀며 생긴 문제
  1. 문제조건 :자신과 같은 점수를 획득하고 같은 수의 문제를 풀었지만 번호가 더 작은 참가자의 수

를 제대로 이해하지 못해 문제의 번호를 더해서 정렬을 하는 삽질을 했따..

  1. 1
      for(int n=0; n<N; N++) 
    

    ```

인덱스는 신중하게 두자…. ```

Code

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Solution {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			String[] s = br.readLine().split(" ");
			int N = Integer.parseInt(s[0]); // 참가자의 수
			int K = Integer.parseInt(s[1]); // 문제의 수
			int P = Integer.parseInt(s[2]); // P번의 사람의 점수와 등수를 계산하라.
			
			int[] Problem = new int[K]; 
			int[] count = new int[N];
			int[] score = new int[N];
			
			String[] PInfo = new String[N]; // 참가자들이 풀어낸 문제에 대한 정보
			for(int n=0; n<N; n++) {
				PInfo[n] = br.readLine();
				String[] tmp = PInfo[n].split(" ");
				for(int k=0; k<tmp.length; k++) {
					if ( tmp[k].equals("1") ) {
						count[n]++;
					} else if (tmp[k].equals("0") ) {
						Problem[k]++;
					}
				}
			}
			
			for(int n=0; n<N; n++) { // 지금부터 점수계산 시작
				String[] tmp = PInfo[n].split(" ");
				for(int k=0; k<tmp.length; k++) {
					if ( tmp[k].equals("1") ) {
						score[n] += Problem[k];
					}
				}
			}
			
			ArrayList<Person> aList = new ArrayList<Person>();
			
			for(int i=0; i<N; i++) {
				aList.add(new Person(score[i],count[i],i+1));
			}
			Collections.sort(aList);
			int size = aList.size();
			
			int res = -1;
			int resScore = -1;
			for(int i=0; i<size; i++) {
				Person p = aList.get(i);
				if ( p.P == P ) {
					res = i+1;
					resScore = p.score;
					break;
				}
			}
			System.out.println("#"+tc+" "+resScore+" "+res);
		}
	}
	
	public static class Person implements Comparable<Person>{
		int score; // 점수
		int count; // 풀어낸 문제의 갯수
		int P;
		Person(int S,int C,int p) {
			score = S;
			count = C;
			P = p;
		}
		@Override
		public int compareTo(Person o) {
			if ( this.score > o.score ) {
				return -1;
			} else if ( this.score < o.score ) {
				return 1;
			} else if ( this.count > o.count ) {
				return -1;
			} else if ( this.count < o.count ) {
				return 1;
			} else if ( this.P < o.P ) {
				return -1;
			} else if ( this.P > o.P ) {
				return 1;
			} else {
				return 0;
			}
		}
	}
}