백준/정렬
백준 8979 올림픽
have a good time
2021. 11. 11. 22:59
반례를 찾을 수 없어서. 일단 부분점수 45 점을 맞았지만, 코드를 올린다.
<부분점수 45점 맞은 코드>
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
class Medal implements Comparable<Medal> {
int country;
int g;
int s;
int c;
public Medal(int country, int g, int s, int c) {
this.country = country;
this.g= g;
this.s =s;
this.c=c;
}
@Override
public int compareTo(Medal o) {
if(this.g==o.g) {
if(this.s==o.s) {
return -(this.c-o.c);
}else return -(this.s-o.s);
}else return - (this.g-o.g);
}
}
public class Main {
static int N;
static int M;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
PriorityQueue<Medal> pq = new PriorityQueue<Medal>();
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
for(int i =0; i<N;i++) {
StringTokenizer st1= new StringTokenizer(br.readLine(), " " );
int country= Integer.parseInt(st1.nextToken());
int g= Integer.parseInt(st1.nextToken());
int s = Integer.parseInt(st1.nextToken());
int c = Integer.parseInt(st1.nextToken());
pq.offer(new Medal(country,g,s,c));
}
int rank =1;
Medal a = pq.poll();
if(a.country==M) {
System.out.println(rank);
System.exit(0);
}
while(!pq.isEmpty()) {
int same =0;
Medal b = pq.poll();
if(a.g==b.g && a.s==b.s&&a.c==b.c) {
if(b.country == M) {
System.out.println( rank);
System.exit(0);
}else {
same++;
rank+=same;
a=b;
}
}else {
if(b.country == M) {
System.out.println(rank+1);
System.exit(0);
}else {
rank = rank+1;
a=b;
}
}
}
}
}
왜 안될까.....?
참고자료 블로그의 코드를 거의 많이 참고했고, while문에서 내가 풀어보려했는데, 해결되지 않았다