結果
問題 | No.919 You Are A Project Manager |
ユーザー | aajisaka |
提出日時 | 2019-10-25 03:02:41 |
言語 | Java21 (openjdk 21) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 4,316 bytes |
コンパイル時間 | 5,043 ms |
コンパイル使用メモリ | 79,148 KB |
実行使用メモリ | 69,744 KB |
最終ジャッジ日時 | 2023-09-26 23:32:43 |
合計ジャッジ時間 | 67,766 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,352 ms
68,264 KB |
testcase_01 | AC | 128 ms
56,080 KB |
testcase_02 | AC | 128 ms
55,712 KB |
testcase_03 | AC | 128 ms
55,968 KB |
testcase_04 | AC | 493 ms
63,976 KB |
testcase_05 | AC | 514 ms
64,004 KB |
testcase_06 | AC | 293 ms
60,740 KB |
testcase_07 | AC | 1,270 ms
69,148 KB |
testcase_08 | AC | 584 ms
62,744 KB |
testcase_09 | AC | 494 ms
62,952 KB |
testcase_10 | AC | 624 ms
62,856 KB |
testcase_11 | AC | 608 ms
62,960 KB |
testcase_12 | AC | 181 ms
57,552 KB |
testcase_13 | AC | 663 ms
62,636 KB |
testcase_14 | AC | 213 ms
60,676 KB |
testcase_15 | AC | 430 ms
63,420 KB |
testcase_16 | AC | 879 ms
68,720 KB |
testcase_17 | AC | 992 ms
69,220 KB |
testcase_18 | AC | 990 ms
65,492 KB |
testcase_19 | AC | 1,228 ms
65,644 KB |
testcase_20 | AC | 2,064 ms
69,380 KB |
testcase_21 | WA | - |
testcase_22 | AC | 1,301 ms
69,128 KB |
testcase_23 | AC | 1,299 ms
68,808 KB |
testcase_24 | AC | 1,345 ms
69,600 KB |
testcase_25 | AC | 1,255 ms
69,208 KB |
testcase_26 | AC | 1,937 ms
69,488 KB |
testcase_27 | AC | 1,873 ms
69,224 KB |
testcase_28 | AC | 2,172 ms
69,236 KB |
testcase_29 | AC | 1,082 ms
65,732 KB |
testcase_30 | AC | 1,096 ms
66,604 KB |
testcase_31 | AC | 1,006 ms
68,636 KB |
testcase_32 | AC | 995 ms
68,908 KB |
testcase_33 | AC | 1,384 ms
69,144 KB |
testcase_34 | AC | 1,410 ms
69,236 KB |
testcase_35 | AC | 2,041 ms
69,620 KB |
testcase_36 | AC | 2,049 ms
69,304 KB |
testcase_37 | AC | 1,996 ms
69,560 KB |
testcase_38 | AC | 2,212 ms
69,460 KB |
testcase_39 | AC | 181 ms
57,792 KB |
testcase_40 | AC | 435 ms
64,036 KB |
testcase_41 | AC | 241 ms
61,436 KB |
testcase_42 | AC | 279 ms
62,268 KB |
testcase_43 | AC | 358 ms
61,072 KB |
testcase_44 | AC | 489 ms
64,772 KB |
testcase_45 | AC | 300 ms
64,920 KB |
testcase_46 | AC | 451 ms
61,592 KB |
testcase_47 | AC | 1,340 ms
69,744 KB |
testcase_48 | AC | 1,297 ms
69,264 KB |
testcase_49 | AC | 1,349 ms
69,704 KB |
testcase_50 | AC | 1,327 ms
69,700 KB |
testcase_51 | AC | 1,195 ms
68,808 KB |
testcase_52 | AC | 993 ms
68,800 KB |
testcase_53 | AC | 1,287 ms
69,052 KB |
testcase_54 | AC | 437 ms
61,072 KB |
testcase_55 | AC | 128 ms
55,692 KB |
testcase_56 | AC | 131 ms
55,772 KB |
testcase_57 | AC | 135 ms
55,960 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<>(); 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); } }