슈콩

[SWEA] 시험 본문

Algorithms/SWEA

[SWEA] 시험

shukong 2025. 11. 17. 17:30

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AW45RuSae2gDFAQ7

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			st = new StringTokenizer(br.readLine());
			int n = Integer.parseInt(st.nextToken());
			int t = Integer.parseInt(st.nextToken());
			int p = Integer.parseInt(st.nextToken());
			int[][] problem = new int[n][t];
			int[] score = new int[t];
			for(int i=0;i<n;i++) {
				st = new StringTokenizer(br.readLine());
				for(int j=0;j<t;j++) {
					int val = Integer.parseInt(st.nextToken());
					if(val==0) {
						score[j]++;
					}
					else problem[i][j] = 1;
				}
			}
			int[] totalScore = new int[n];
			int[] totalSolve = new int[n];
			for(int i=0;i<n;i++) {
				for(int j=0;j<t;j++) {
					totalScore[i] += problem[i][j] * score[j];
					totalSolve[i] += problem[i][j];
				}
			}
			List<int[]> list = new LinkedList<>();
			for(int i=0;i<n;i++) {
				list.add(new int[] {i+1,totalScore[i],totalSolve[i]});
			}
			Collections.sort(list,(a,b)->{
				if(a[1]==b[1]) {
					if(a[2]==b[2]) {
						return Integer.compare(a[0], b[0]);
					}
					return Integer.compare(b[2], a[2]);
				}
				return Integer.compare(b[1], a[1]);
			});
			int rank = 0;
			int sum = totalScore[p-1];
			for(int j=0;j<n;j++) {
				if(list.get(j)[0]==p) rank = j+1;
			}
			System.out.println("#"+tc+" "+sum+" "+rank);
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 영준이와 신비한 뿔의 숲  (0) 2025.11.17
[SWEA] 두문자어  (0) 2025.11.17
[SWEA] 장애물 경주 난이도  (0) 2025.11.17
[SWEA] 문제 제목 붙이기  (0) 2025.11.17
[SWEA] 준홍이의 카드놀이  (0) 2025.11.17