結果

問題 No.919 You Are A Project Manager
ユーザー aajisakaaajisaka
提出日時 2019-10-25 02:54:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 4,315 bytes
コンパイル時間 4,112 ms
コンパイル使用メモリ 78,852 KB
実行使用メモリ 70,808 KB
最終ジャッジ日時 2023-09-25 14:41:57
合計ジャッジ時間 64,643 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,369 ms
68,396 KB
testcase_01 WA -
testcase_02 AC 122 ms
55,720 KB
testcase_03 WA -
testcase_04 AC 467 ms
64,104 KB
testcase_05 AC 511 ms
65,596 KB
testcase_06 AC 295 ms
63,100 KB
testcase_07 AC 1,253 ms
69,428 KB
testcase_08 AC 551 ms
62,404 KB
testcase_09 AC 492 ms
62,480 KB
testcase_10 AC 624 ms
62,576 KB
testcase_11 AC 604 ms
62,676 KB
testcase_12 AC 175 ms
57,248 KB
testcase_13 AC 658 ms
62,716 KB
testcase_14 AC 218 ms
60,956 KB
testcase_15 AC 423 ms
65,116 KB
testcase_16 AC 850 ms
68,856 KB
testcase_17 AC 1,057 ms
65,980 KB
testcase_18 AC 988 ms
65,780 KB
testcase_19 AC 1,304 ms
65,440 KB
testcase_20 AC 2,076 ms
69,564 KB
testcase_21 WA -
testcase_22 AC 1,268 ms
67,476 KB
testcase_23 AC 1,279 ms
70,808 KB
testcase_24 AC 1,318 ms
69,220 KB
testcase_25 AC 1,201 ms
68,860 KB
testcase_26 AC 2,009 ms
69,488 KB
testcase_27 AC 1,822 ms
70,776 KB
testcase_28 AC 2,106 ms
67,452 KB
testcase_29 AC 1,001 ms
66,292 KB
testcase_30 AC 1,037 ms
65,848 KB
testcase_31 AC 1,045 ms
65,136 KB
testcase_32 AC 969 ms
68,540 KB
testcase_33 AC 1,400 ms
69,660 KB
testcase_34 AC 1,405 ms
69,296 KB
testcase_35 AC 2,056 ms
69,876 KB
testcase_36 AC 1,970 ms
69,280 KB
testcase_37 AC 1,978 ms
69,352 KB
testcase_38 AC 2,041 ms
69,824 KB
testcase_39 AC 175 ms
57,156 KB
testcase_40 AC 421 ms
61,364 KB
testcase_41 AC 242 ms
61,468 KB
testcase_42 AC 293 ms
62,856 KB
testcase_43 AC 358 ms
60,496 KB
testcase_44 AC 479 ms
62,592 KB
testcase_45 AC 269 ms
60,624 KB
testcase_46 AC 447 ms
61,712 KB
testcase_47 AC 1,290 ms
69,152 KB
testcase_48 AC 1,269 ms
69,112 KB
testcase_49 AC 1,302 ms
69,348 KB
testcase_50 AC 1,286 ms
69,452 KB
testcase_51 AC 1,173 ms
69,204 KB
testcase_52 AC 1,007 ms
68,888 KB
testcase_53 AC 1,254 ms
69,164 KB
testcase_54 AC 432 ms
63,076 KB
testcase_55 AC 125 ms
55,464 KB
testcase_56 AC 126 ms
55,468 KB
testcase_57 AC 130 ms
55,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
    }
}
0