結果
問題 | No.919 You Are A Project Manager |
ユーザー | aajisaka |
提出日時 | 2019-10-25 03:12:45 |
言語 | Java21 (openjdk 21) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 4,351 bytes |
コンパイル時間 | 5,149 ms |
コンパイル使用メモリ | 77,360 KB |
実行使用メモリ | 71,404 KB |
最終ジャッジ日時 | 2023-09-26 23:34:55 |
合計ジャッジ時間 | 64,108 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,444 ms
68,004 KB |
testcase_01 | AC | 130 ms
55,756 KB |
testcase_02 | AC | 130 ms
55,924 KB |
testcase_03 | AC | 132 ms
55,692 KB |
testcase_04 | AC | 517 ms
64,584 KB |
testcase_05 | AC | 503 ms
64,448 KB |
testcase_06 | AC | 305 ms
61,580 KB |
testcase_07 | AC | 1,265 ms
69,224 KB |
testcase_08 | AC | 582 ms
62,388 KB |
testcase_09 | AC | 513 ms
62,452 KB |
testcase_10 | AC | 628 ms
63,088 KB |
testcase_11 | AC | 604 ms
62,580 KB |
testcase_12 | AC | 186 ms
57,368 KB |
testcase_13 | AC | 691 ms
62,636 KB |
testcase_14 | AC | 224 ms
60,760 KB |
testcase_15 | AC | 436 ms
61,352 KB |
testcase_16 | AC | 882 ms
68,128 KB |
testcase_17 | AC | 1,037 ms
67,856 KB |
testcase_18 | AC | 952 ms
65,552 KB |
testcase_19 | AC | 1,253 ms
68,232 KB |
testcase_20 | AC | 1,996 ms
71,404 KB |
testcase_21 | WA | - |
testcase_22 | AC | 1,300 ms
69,804 KB |
testcase_23 | AC | 1,304 ms
70,908 KB |
testcase_24 | AC | 1,329 ms
68,884 KB |
testcase_25 | AC | 1,254 ms
69,528 KB |
testcase_26 | AC | 2,133 ms
69,680 KB |
testcase_27 | AC | 1,839 ms
69,172 KB |
testcase_28 | AC | 2,105 ms
69,628 KB |
testcase_29 | AC | 1,102 ms
65,900 KB |
testcase_30 | AC | 1,056 ms
65,784 KB |
testcase_31 | AC | 958 ms
68,248 KB |
testcase_32 | AC | 981 ms
64,452 KB |
testcase_33 | AC | 1,359 ms
68,972 KB |
testcase_34 | AC | 1,356 ms
68,780 KB |
testcase_35 | AC | 2,001 ms
69,488 KB |
testcase_36 | AC | 2,204 ms
69,480 KB |
testcase_37 | AC | 2,015 ms
69,280 KB |
testcase_38 | AC | 2,007 ms
69,508 KB |
testcase_39 | AC | 185 ms
57,420 KB |
testcase_40 | AC | 435 ms
60,460 KB |
testcase_41 | AC | 259 ms
61,540 KB |
testcase_42 | AC | 288 ms
60,168 KB |
testcase_43 | AC | 380 ms
61,756 KB |
testcase_44 | AC | 496 ms
62,344 KB |
testcase_45 | AC | 302 ms
64,064 KB |
testcase_46 | AC | 449 ms
61,404 KB |
testcase_47 | AC | 1,314 ms
69,724 KB |
testcase_48 | AC | 1,304 ms
69,220 KB |
testcase_49 | AC | 1,315 ms
69,220 KB |
testcase_50 | AC | 1,300 ms
69,600 KB |
testcase_51 | AC | 1,201 ms
69,316 KB |
testcase_52 | AC | 1,025 ms
69,144 KB |
testcase_53 | AC | 1,259 ms
69,160 KB |
testcase_54 | AC | 436 ms
61,452 KB |
testcase_55 | AC | 129 ms
55,728 KB |
testcase_56 | AC | 132 ms
55,756 KB |
testcase_57 | AC | 137 ms
55,800 KB |
ソースコード
import java.util.*; public class Solution { static class Median { final PriorityQueue<Integer> lower, higher; int count; Median() { lower = new PriorityQueue<>(11, Comparator.reverseOrder()); higher = new PriorityQueue<>(); // Avoid NPE in push() lower.add(Integer.MIN_VALUE); higher.add(Integer.MAX_VALUE); count = 2; } void push(int a) { if (count % 2 == 0) { lower.add(a); } else { higher.add(a); } if (lower.peek() > higher.peek()) { Integer high = lower.poll(); Integer low = higher.poll(); higher.add(high); lower.add(low); } count++; } Integer get() { return lower.peek(); } void erase(int a) { if (lower.remove(a)) { if (lower.size() < higher.size()) { lower.add(higher.poll()); } } else if (higher.remove(a)) { if (lower.size() + 1 > higher.size()) { higher.add(lower.poll()); } } count--; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); final int h = 400; List<Integer> a = new ArrayList<>(); for(int i=0; i<n; i++) { a.add(sc.nextInt()); } long ans = 0; for(int k=1; k<=Math.min(h, n); k++) { List<Long> v1 = new ArrayList<>(); List<Long> v2 = new ArrayList<>(); v1.add(0L); v2.add(0L); long no1 = 0; long no2 = 0; long ma1 = 0; long ma2 = 0; for(int i=0; i+k<=n; i+=k) { Median med1 = new Median(); Median med2 = new Median(); for(int j=i; j<i+k; j++) { med1.push(a.get(j)); med2.push(a.get(n-1-j)); } no1 += med1.get(); ma1 = Math.max(ma1, no1); v1.add(ma1); no2 += med2.get(); ma2 = Math.max(ma2, no2); v2.add(ma2); } for(int i=0; i<v1.size(); i++) { ans = Math.max(ans, (v1.get(i)+v2.get(v1.size()-1-i))*k); } } int q = n/(h+1); List<Median> vm1 = new ArrayList<>(); List<Median> vm2 = new ArrayList<>(); for(int i=0; i<q; i++) { vm1.add(new Median()); vm2.add(new Median()); } for(int i=0; i<q*(h+1); i++) { vm1.get(i/(h+1)).push(a.get(i)); vm2.get(i/(h+1)).push(a.get(n-1-i)); } for(int k=h+1; k<=n; k++) { int t = vm1.size(); List<Long> v1 = new ArrayList<>(); List<Long> v2 = new ArrayList<>(); v1.add(0L); v2.add(0L); long no1 = 0; long no2 = 0; long ma1 = 0; long ma2 = 0; for(int i=0; i<t; i++) { no1 += vm1.get(i).get(); ma1 = Math.max(ma1, no1); v1.add(ma1); no2 += vm2.get(i).get(); ma2 = Math.max(ma2, no2); v2.add(ma2); } for(int i=0; i<=t; i++) { ans = Math.max(ans, (v1.get(i)+v2.get(t-i))*k); } for(int i=0; i<t; i++) { int bleft = i*k; int bright = (i+1)*k; int aleft = i*(k+1); int aright = (i+1)*(k+1); if (aright > n) { vm1.remove(vm1.size()-1); vm2.remove(vm2.size()-1); continue; } for(int j=bleft; j<aleft; j++) { vm1.get(i).erase(a.get(j)); vm2.get(i).erase(a.get(n-1-j)); } for(int j=bright; j<aright; j++) { vm1.get(i).push(a.get(j)); vm2.get(i).push(a.get(n-1-j)); } } } System.out.println(ans); } }