인프런 커뮤니티 질문&답변
시간초과 에러
작성
·
256
0
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int headCnt = sc.nextInt();
int testCnt = sc.nextInt();
int[][] array = new int[testCnt][headCnt];
for(int i=0; i<testCnt; i++) {
for(int j=0; j<headCnt; j++) {
array[i][j] = sc.nextInt();
}
}
System.out.print(solution(headCnt, testCnt, array));
}
public static int solution(int headCnt, int testCnt, int[][] arr) {
int answer = 0;
for(int i=1; i<=headCnt; i++) {
for(int j=1; i<=headCnt; j++) {
int cnt=0;
for(int k=0; k<testCnt; k++) {
int pi = 0, pj = 0;
for(int s=0; s<headCnt; s++) { //등수
if(arr[k][s] == i) pi = s;
if(arr[k][s] == j) pj = s;
}
if(pi < pj) cnt++;
}
if(cnt == testCnt) {
answer++;
}
}
}
return answer;
}
}왜 에러가 나는지 잘 모르겠습니다





