結果
問題 | No.165 四角で囲え! |
ユーザー | 37zigen |
提出日時 | 2020-04-03 17:02:22 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,143 bytes |
コンパイル時間 | 6,761 ms |
コンパイル使用メモリ | 76,460 KB |
実行使用メモリ | 69,236 KB |
最終ジャッジ日時 | 2023-09-15 23:46:17 |
合計ジャッジ時間 | 41,460 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 1,310 ms
61,912 KB |
testcase_02 | AC | 1,306 ms
64,000 KB |
testcase_03 | AC | 1,433 ms
64,008 KB |
testcase_04 | AC | 1,436 ms
63,896 KB |
testcase_05 | AC | 1,567 ms
63,692 KB |
testcase_06 | WA | - |
testcase_07 | AC | 1,467 ms
63,792 KB |
testcase_08 | AC | 1,320 ms
63,932 KB |
testcase_09 | AC | 1,339 ms
63,696 KB |
testcase_10 | AC | 1,205 ms
69,236 KB |
testcase_11 | AC | 1,475 ms
63,768 KB |
testcase_12 | AC | 1,553 ms
64,244 KB |
testcase_13 | WA | - |
testcase_14 | AC | 1,540 ms
63,628 KB |
testcase_15 | AC | 1,409 ms
64,248 KB |
testcase_16 | AC | 1,400 ms
63,660 KB |
testcase_17 | AC | 1,828 ms
64,996 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 1,447 ms
64,248 KB |
testcase_21 | AC | 1,255 ms
68,780 KB |
testcase_22 | AC | 1,261 ms
68,672 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays;import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; class Main { public static void main(String[] args) { new Main().run(); } int 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]=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-2,left-2); } 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]+=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) { for(int j=0;j<X_distinct.length;++j) { if(X[i]==X_distinct[j]) { X[i]=j; break; } } for(int j=0;j<Y_distinct.length;++j) { if(Y[i]==Y_distinct[j]) { Y[i]=j; break; } } } 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());} }