기몽수
코딩 기록일지
기몽수
전체 방문자
오늘
어제
  • 분류 전체보기 (443)
    • 알고리즘 - SWEA (210)
      • D1 (19)
      • D2 (25)
      • D3 (143)
      • D4 (21)
      • D5 (2)
    • 알고리즘 - Programmers (74)
      • Unrated (34)
      • Lv 0 (4)
      • Lv 1 (3)
      • Lv 2 (32)
      • Lv 3 (1)
    • 알고리즘 - Baekjoon (158)
      • Bronze (1)
      • Silver (65)
      • Gold (90)
      • Platinum (2)
    • 취업 (0)
    • SSAFY (1)
hELLO · Designed By 김용수.
기몽수

코딩 기록일지

알고리즘 - SWEA/D3

[SW expert Academy] SWEA 8888번 시험 자바(Java)

2023. 11. 4. 01:03

[D3] 시험 - 8888

문제 링크

성능 요약

메모리: 146,616 KB, 시간: 1,208 ms, 코드길이: 2,088 Bytes

제출 일자

2023-11-04 01:01

출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do

import java.io.*;
import java.util.*;
class Solution {
	public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		for(int tc = 1; tc <= T; tc++) {
            StringTokenizer  st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int t = Integer.parseInt(st.nextToken());
            int p = Integer.parseInt(st.nextToken());
            int[][] perScore = 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 perScore[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] += (perScore[i][j] * score[j]);
                    totalSolve[i] += perScore[i][j];
                }
            }
            ArrayList<int[] > answer = new ArrayList<>();
            for(int i = 0; i < n; i++) answer.add( new int[] {i+1,totalSolve[i], totalScore[i]});
        	Collections.sort(answer, (o1,o2) -> {
                if(o1[2] == o2[2]){
                    if(o1[1] == o2[1]) return Integer.compare(o1[0],o2[0]);
                    return Integer.compare(o2[1],o1[1]);
                }
                 return Integer.compare(o2[2],o1[2]);
            });
            int rank = 0;
            int total = 0;
            for(int i = 0; i < n; i++){
                int[] people = answer.get(i);
                if(people[0] == p){
                    rank = i + 1;
                    total = people[2];
                    break;
                }
            }
            System.out.println("#" + tc + " " + total + " " + rank);
        }
	}
}

'알고리즘 - SWEA > D3' 카테고리의 다른 글

[SW expert Academy] SWEA 11445번 무한 사전 자바(Java)  (1) 2023.11.04
[SW expert Academy] SWEA 7193번 승현이의 수학공부 자바(Java)  (0) 2023.11.04
[SW expert Academy] SWEA 4299번 태혁이의 사랑은 타이밍 자바(Java)  (1) 2023.11.03
[SW expert Academy] SWEA 7510번 상원이의 연속 합 자바(Java)  (1) 2023.11.03
[SW expert Academy] SWEA 5549번 홀수일까 짝수일까 자바(Java)  (0) 2023.11.02
    '알고리즘 - SWEA/D3' 카테고리의 다른 글
    • [SW expert Academy] SWEA 11445번 무한 사전 자바(Java)
    • [SW expert Academy] SWEA 7193번 승현이의 수학공부 자바(Java)
    • [SW expert Academy] SWEA 4299번 태혁이의 사랑은 타이밍 자바(Java)
    • [SW expert Academy] SWEA 7510번 상원이의 연속 합 자바(Java)
    기몽수
    기몽수

    티스토리툴바