結果
問題 | No.165 四角で囲え! |
ユーザー | 37zigen |
提出日時 | 2020-04-03 17:28:04 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,907 ms / 5,000 ms |
コード長 | 3,957 bytes |
コンパイル時間 | 2,908 ms |
コンパイル使用メモリ | 79,980 KB |
実行使用メモリ | 56,476 KB |
最終ジャッジ日時 | 2024-07-03 01:02:57 |
合計ジャッジ時間 | 35,315 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,375 ms
56,420 KB |
testcase_01 | AC | 1,232 ms
56,108 KB |
testcase_02 | AC | 1,211 ms
56,304 KB |
testcase_03 | AC | 1,285 ms
56,216 KB |
testcase_04 | AC | 1,251 ms
56,308 KB |
testcase_05 | AC | 1,380 ms
56,312 KB |
testcase_06 | AC | 1,410 ms
56,108 KB |
testcase_07 | AC | 1,218 ms
56,204 KB |
testcase_08 | AC | 1,174 ms
56,052 KB |
testcase_09 | AC | 1,199 ms
56,168 KB |
testcase_10 | AC | 1,196 ms
56,220 KB |
testcase_11 | AC | 1,320 ms
56,248 KB |
testcase_12 | AC | 1,217 ms
56,328 KB |
testcase_13 | AC | 1,308 ms
56,272 KB |
testcase_14 | AC | 1,408 ms
56,476 KB |
testcase_15 | AC | 1,203 ms
56,236 KB |
testcase_16 | AC | 1,340 ms
56,180 KB |
testcase_17 | AC | 1,376 ms
56,452 KB |
testcase_18 | AC | 1,907 ms
56,384 KB |
testcase_19 | AC | 1,266 ms
56,328 KB |
testcase_20 | AC | 1,358 ms
56,264 KB |
testcase_21 | AC | 1,178 ms
56,148 KB |
testcase_22 | AC | 1,177 ms
56,084 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.NoSuchElementException; class Main { public static void main(String[] args) { new Main().run(); } long access(int[][] a,int i,int j) { if(i<0||j<0)return 0; return a[i][j]; } int[] get(int[][][] sum,int left,int right,int top,int bottom){ int[] ret=new int[2]; for(int t=0;t<2;++t) { ret[t]=(int)(access(sum[t],bottom-1,right-1)-access(sum[t],bottom-1,left-1)-access(sum[t],top-1,right-1)+access(sum[t],top-1,left-1)); } return ret; } void solve(int N,int B,int[] X,int[] Y,int[] P) { int M=400; int[][][] sum=new int[2][M][M]; for(int i=0;i<N;++i) { sum[0][Y[i]][X[i]]+=1; sum[1][Y[i]][X[i]]+=P[i]; } for(int t=0;t<2;++t) { for(int i=0;i<M;++i) { for(int j=0;j<M;++j) { sum[t][i][j]+=(int)(access(sum[t],i-1,j)+access(sum[t],i,j-1)-access(sum[t],i-1,j-1)); } } } int ans=0; for(int left=0;left<M;++left) { for(int top=0;top<M;++top) { int right=M; for(int bottom=top+1;bottom<=M;++bottom) { while(get(sum,left,right,top,bottom)[1]>B)--right; ans=Math.max(ans, get(sum,left,right,top,bottom)[0]); } } } System.out.println(ans); } void run() { FastScanner sc=new FastScanner(); int N=sc.nextInt(); int B=sc.nextInt(); int[] X=new int[N]; int[] Y=new int[N]; int[] P=new int[N]; for(int i=0;i<N;++i) { X[i]=sc.nextInt(); Y[i]=sc.nextInt(); P[i]=sc.nextInt(); } int[] X_distinct=Arrays.stream(X).distinct().sorted().toArray(); int[] Y_distinct=Arrays.stream(Y).distinct().sorted().toArray(); for(int i=0;i<N;++i) { X[i]=Arrays.binarySearch(X_distinct, X[i]); Y[i]=Arrays.binarySearch(Y_distinct, Y[i]); } solve(N,B,X,Y,P); } static 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());} }