結果
問題 | No.919 You Are A Project Manager |
ユーザー | 37zigen |
提出日時 | 2020-03-13 17:50:36 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 990 ms / 3,000 ms |
コード長 | 5,425 bytes |
コンパイル時間 | 4,825 ms |
コンパイル使用メモリ | 76,492 KB |
実行使用メモリ | 52,516 KB |
最終ジャッジ日時 | 2023-08-14 13:35:18 |
合計ジャッジ時間 | 35,445 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 637 ms
43,556 KB |
testcase_01 | AC | 40 ms
33,680 KB |
testcase_02 | AC | 44 ms
33,908 KB |
testcase_03 | AC | 41 ms
33,680 KB |
testcase_04 | AC | 367 ms
41,648 KB |
testcase_05 | AC | 347 ms
41,756 KB |
testcase_06 | AC | 90 ms
36,140 KB |
testcase_07 | AC | 410 ms
38,784 KB |
testcase_08 | AC | 233 ms
37,860 KB |
testcase_09 | AC | 302 ms
41,576 KB |
testcase_10 | AC | 220 ms
38,504 KB |
testcase_11 | AC | 255 ms
41,480 KB |
testcase_12 | AC | 57 ms
34,500 KB |
testcase_13 | AC | 245 ms
37,820 KB |
testcase_14 | AC | 74 ms
35,396 KB |
testcase_15 | AC | 157 ms
41,480 KB |
testcase_16 | AC | 421 ms
42,060 KB |
testcase_17 | AC | 608 ms
43,792 KB |
testcase_18 | AC | 632 ms
43,488 KB |
testcase_19 | AC | 667 ms
43,528 KB |
testcase_20 | AC | 847 ms
42,032 KB |
testcase_21 | AC | 689 ms
44,076 KB |
testcase_22 | AC | 548 ms
42,864 KB |
testcase_23 | AC | 457 ms
42,708 KB |
testcase_24 | AC | 532 ms
39,168 KB |
testcase_25 | AC | 480 ms
42,680 KB |
testcase_26 | AC | 845 ms
44,520 KB |
testcase_27 | AC | 728 ms
43,800 KB |
testcase_28 | AC | 961 ms
44,740 KB |
testcase_29 | AC | 652 ms
43,728 KB |
testcase_30 | AC | 691 ms
44,108 KB |
testcase_31 | AC | 689 ms
44,052 KB |
testcase_32 | AC | 716 ms
43,664 KB |
testcase_33 | AC | 478 ms
39,260 KB |
testcase_34 | AC | 503 ms
42,972 KB |
testcase_35 | AC | 945 ms
41,784 KB |
testcase_36 | AC | 935 ms
44,672 KB |
testcase_37 | AC | 990 ms
44,780 KB |
testcase_38 | AC | 976 ms
44,784 KB |
testcase_39 | AC | 62 ms
44,444 KB |
testcase_40 | AC | 255 ms
41,452 KB |
testcase_41 | AC | 82 ms
36,244 KB |
testcase_42 | AC | 93 ms
37,216 KB |
testcase_43 | AC | 110 ms
37,644 KB |
testcase_44 | AC | 210 ms
41,504 KB |
testcase_45 | AC | 93 ms
37,116 KB |
testcase_46 | AC | 257 ms
41,428 KB |
testcase_47 | AC | 520 ms
39,164 KB |
testcase_48 | AC | 552 ms
42,716 KB |
testcase_49 | AC | 495 ms
38,872 KB |
testcase_50 | AC | 489 ms
52,516 KB |
testcase_51 | AC | 435 ms
38,652 KB |
testcase_52 | AC | 380 ms
37,592 KB |
testcase_53 | AC | 445 ms
38,808 KB |
testcase_54 | AC | 167 ms
39,256 KB |
testcase_55 | AC | 41 ms
33,620 KB |
testcase_56 | AC | 45 ms
33,576 KB |
testcase_57 | AC | 51 ms
34,324 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.NoSuchElementException; class BitVector{ long[] small; int[] big; int n; public BitVector(int n) { this.n=n; small=new long[n/64+1]; big=new int[n/64+1]; } void set(int k) { small[k/64]|=1L<<(k%64); } void build() { for(int i=0;i<big.length;++i) { big[i]=(i>0?Long.bitCount(small[i-1]):0)+(i>0?big[i-1]:0); } } int access(int k) { return (int) ((small[k/64]>>>(k%64))&1); } //[l,r) int rank(int l,int r,long m) { if(l>=r)return 0; int ret=bitCount(r)-bitCount(l); return m==1?ret:(r-l-ret); } //[0,n) int bitCount(int n) { n=Math.min(n, this.n); if(n<=0)return 0; --n; return big[n/64]+Long.bitCount((small[n/64]<<(63-n%64))>>>(63-n%64)); } } class WaveletMatrix{ int w=64; BitVector[] b=new BitVector[w];//b[i]:=&2^{i+1}で安定ソートしたときの第&2^{i} int[] nz=new int[w]; int n; final long base=Long.MAX_VALUE/2; public WaveletMatrix(long[] a) { n=a.length; for(int i=0;i<b.length;++i)b[i]=new BitVector(n); long[][] sorted=new long[n][]; for(int i=0;i<a.length;++i) { sorted[i]= new long[]{a[i]+base,0}; } Comparator<long[]> comp=new Comparator<long[]>() { @Override public int compare(long[] o1, long[] o2) { return Long.compare((o1[0]>>>o1[1])&1, (o2[0]>>>o2[1])&1); } }; for(int bit=w-1;bit>=0;--bit) { for(int i=0;i<n;++i)sorted[i][1]=bit+1; if(bit<w-1)Arrays.sort(sorted, comp);//安定ソート for(int i=0;i<n;++i)if(((sorted[i][0]>>>bit)&1)==1) { b[bit].set(i); } } for(int i=0;i<b.length;++i)b[i].build(); for(int i=0;i<b.length;++i)nz[i]=b[i].rank(0, n, 0); } long access(int k) { long ret=0; int pos=k; for(int bit=w-1;bit>=0;--bit) { int v=b[bit].access(pos); ret|=(1L<<bit)*v; pos=b[bit].rank(0, pos, v)+(v==0?0:nz[bit]); } return ret-base; } long quantile(int l,int r,int k) { if(k+1>r-l)throw new AssertionError(); long ret=0; for(int bit=w-1;bit>=0;--bit) { int nl=-1,nr=-1; if(b[bit].rank(l, r, 0)>=k+1) { nl=b[bit].rank(0, l, 0); nr=nl+b[bit].rank(l, r, 0); }else { nl=nz[bit]+b[bit].rank(0, l, 1); nr=nl+b[bit].rank(l, r, 1); k-=b[bit].rank(l, r, 0); ret|=1L<<bit; } l=nl;r=nr; } return ret-base; } } class Main { public static void main(String[] args) { new Main().run(); } void run() { FastScanner sc=new FastScanner(); int N=sc.nextInt(); long[] a=new long[N]; for(int i=0;i<N;++i)a[i]=sc.nextLong(); WaveletMatrix wm=new WaveletMatrix(a); PrintWriter pw=new PrintWriter(System.out); long ans=0; for(int K=1;K<=N;++K) { long[] right=new long[N/K]; long[] left=new long[N/K]; for(int i=0;i<N/K;++i)right[i]=wm.quantile(N-(i+1)*K, N-i*K, (K+1)/2-1)+(i>0?right[i-1]:0); for(int i=0;i<N/K;++i)left[i]=wm.quantile(i*K, (i+1)*K, (K+1)/2-1)+(i>0?left[i-1]:0); for(int i=1;i<N/K;++i)right[i]=Math.max(right[i], right[i-1]); for(int i=1;i<N/K;++i)left[i]=Math.max(left[i], left[i-1]); for(int i=-1;i<N/K;++i)ans=Math.max(ans, K*((i==-1?0:left[i])+(N/K-i-2==-1?0:right[N/K-i-2]))); } pw.println(ans); pw.close(); } void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));} } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }