# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
381309 | timg8710 | Sails (IOI07_sails) | Java | 1100 ms | 23164 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// package olypmiads;
import java.io.*;
import java.util.*;
public class sails {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
int N = Integer.parseInt(br.readLine());
int[][] nums = new int[N][2];
for(int i = 0; i<N; i++){
StringTokenizer st = new StringTokenizer(br.readLine()); nums[i] = new int[]{Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())};
}
Arrays.sort(nums, (int[] a, int[] b) -> b[0] - a[0]);
int l = 1;
int r = N;
while(l < r){
int mid = (l+r)/2;
if(good(mid, nums) != -1){
r = mid;
}else{
l = mid+1;
}
}
pw.println(good(r, nums));
pw.close();
br.close();
}
static long good(int max, int[][] nums){
int r = 0;
long ret = 0;
Queue<Integer> run = new PriorityQueue<>(Comparator.reverseOrder());
for(int i = 10; i>=1; i--){
while(r < nums.length && nums[r][0] >= i){
run.add(nums[r][1]);
r++;
}
long take = Math.min(run.size(), max);
ret += take*(take-1)/2;
List<Integer> taken = new ArrayList(); //this is messy but whatever its fine
while(take > 0){
taken.add(run.poll()-1); take--;
}
for(int j : taken) if(j != 0) run.add(j);
}
return run.isEmpty() ? ret : -1;
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |