結果
問題 | No.919 You Are A Project Manager |
ユーザー | aajisaka |
提出日時 | 2019-10-25 04:32:24 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,658 bytes |
コンパイル時間 | 5,487 ms |
コンパイル使用メモリ | 78,884 KB |
実行使用メモリ | 95,952 KB |
最終ジャッジ日時 | 2023-09-25 17:51:40 |
合計ジャッジ時間 | 56,614 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 127 ms
55,528 KB |
testcase_02 | AC | 125 ms
55,888 KB |
testcase_03 | AC | 125 ms
55,932 KB |
testcase_04 | AC | 463 ms
63,572 KB |
testcase_05 | AC | 492 ms
64,372 KB |
testcase_06 | AC | 288 ms
64,264 KB |
testcase_07 | AC | 969 ms
63,064 KB |
testcase_08 | AC | 528 ms
63,260 KB |
testcase_09 | AC | 486 ms
62,580 KB |
testcase_10 | AC | 617 ms
62,956 KB |
testcase_11 | AC | 575 ms
62,924 KB |
testcase_12 | AC | 175 ms
56,796 KB |
testcase_13 | AC | 619 ms
62,524 KB |
testcase_14 | AC | 206 ms
60,520 KB |
testcase_15 | AC | 412 ms
61,088 KB |
testcase_16 | AC | 922 ms
69,504 KB |
testcase_17 | AC | 976 ms
69,540 KB |
testcase_18 | AC | 919 ms
69,572 KB |
testcase_19 | AC | 1,192 ms
69,468 KB |
testcase_20 | AC | 1,565 ms
65,660 KB |
testcase_21 | WA | - |
testcase_22 | AC | 1,030 ms
63,336 KB |
testcase_23 | AC | 1,013 ms
63,164 KB |
testcase_24 | AC | 1,042 ms
63,380 KB |
testcase_25 | AC | 1,012 ms
64,040 KB |
testcase_26 | AC | 1,578 ms
65,416 KB |
testcase_27 | AC | 1,446 ms
64,064 KB |
testcase_28 | AC | 1,655 ms
66,052 KB |
testcase_29 | AC | 949 ms
69,772 KB |
testcase_30 | AC | 946 ms
68,888 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 1,068 ms
63,076 KB |
testcase_34 | AC | 1,082 ms
63,236 KB |
testcase_35 | AC | 1,659 ms
65,272 KB |
testcase_36 | AC | 1,686 ms
65,272 KB |
testcase_37 | AC | 1,677 ms
65,312 KB |
testcase_38 | AC | 1,658 ms
65,528 KB |
testcase_39 | AC | 176 ms
56,796 KB |
testcase_40 | AC | 427 ms
61,932 KB |
testcase_41 | AC | 226 ms
61,540 KB |
testcase_42 | AC | 251 ms
58,852 KB |
testcase_43 | AC | 347 ms
61,864 KB |
testcase_44 | AC | 473 ms
62,836 KB |
testcase_45 | AC | 265 ms
62,076 KB |
testcase_46 | AC | 444 ms
61,468 KB |
testcase_47 | AC | 1,007 ms
63,244 KB |
testcase_48 | AC | 1,014 ms
63,340 KB |
testcase_49 | AC | 1,053 ms
63,812 KB |
testcase_50 | AC | 1,060 ms
63,064 KB |
testcase_51 | AC | 978 ms
63,336 KB |
testcase_52 | AC | 889 ms
63,476 KB |
testcase_53 | AC | 976 ms
63,976 KB |
testcase_54 | AC | 425 ms
60,900 KB |
testcase_55 | AC | 127 ms
55,400 KB |
testcase_56 | AC | 129 ms
56,012 KB |
testcase_57 | AC | 135 ms
55,724 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<>(11); // Avoid NPE in push() lower.add(Integer.MIN_VALUE); higher.add(Integer.MAX_VALUE); count = 2; } Median(int capacity) { lower = new PriorityQueue<>(capacity/2+2, Comparator.reverseOrder()); higher = new PriorityQueue<>(capacity/2+2); // 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(k); Median med2 = new Median(k); 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 = 1; List<Median> vm1 = new ArrayList<>(); List<Median> vm2 = new ArrayList<>(); for(int i=0; i<q; i++) { vm1.add(new Median(h+1)); vm2.add(new Median(h+1)); } for(int i=0; i<n; i++) { vm1.get(0).push(a.get(i)); vm2.get(0).push(a.get(n-1-i)); } for(int k=n; 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); } }