結果
問題 |
No.918 LISGRID
|
ユーザー |
|
提出日時 | 2020-03-11 15:46:15 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 465 ms / 2,000 ms |
コード長 | 1,629 bytes |
コンパイル時間 | 2,549 ms |
コンパイル使用メモリ | 80,736 KB |
実行使用メモリ | 49,800 KB |
最終ジャッジ日時 | 2024-11-16 00:16:34 |
合計ジャッジ時間 | 16,929 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; class Main { public static void main(String[] args) { new Main().run(); } void run() { Scanner sc=new Scanner(System.in); int H=sc.nextInt(); int W=sc.nextInt(); int[] A=new int[H]; int[] B=new int[W]; int[][] m=new int[H][W]; for(int h=0;h<H;++h)for(int w=0;w<W;++w)m[h][w]=-1; for(int i=0;i<A.length;++i) { A[i]=-sc.nextInt(); } for(int i=0;i<B.length;++i) { B[i]=-sc.nextInt(); } Arrays.sort(A); Arrays.sort(B); for(int i=0;i<A.length;++i)A[i]*=-1; for(int i=0;i<B.length;++i)B[i]*=-1; int s=1,t=H*W; for(int h=0;h<H;++h) { int bottom=0,top=0; for(int w=0;w<W;++w) { if(B[w]>1)++bottom; else ++top; } if(A[h]>1) { int left=Math.min(bottom,(top==0?A[h]:(A[h]-1))); int right=A[h]-left; for(int w=0;w<left;++w) { m[h][bottom-left+w]=s++; } for(int w=0;w<bottom-left;++w) { m[h][bottom-left-1-w]=s++; } for(int w=0;w<top-right;++w) { m[h][bottom+w]=t--; } for(int w=0;w<right;++w) { m[h][W-1-w]=t--; } }else { for(int w=0;w<W;++w) { s=t-(H-h)+1; int t_=t; for(int i=h;i<H;++i) { if(B[w]>1) { {m[i][w]=s++;B[w]--;} }else m[i][w]=t--; } t=t_-(H-h); } break; } for(int w=0;w<W;++w)B[w]=Math.max(B[w]-1, 1); } PrintWriter pw=new PrintWriter(System.out); for(int h=0;h<H;++h) { for(int w=0;w<W;++w) { pw.print(m[h][w]+(w==W-1?"\n":" ")); } } pw.close(); } void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));} }