結果

問題 No.918 LISGRID
ユーザー 37zigen37zigen
提出日時 2020-03-11 15:37:12
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,620 bytes
コンパイル時間 3,093 ms
コンパイル使用メモリ 84,968 KB
実行使用メモリ 66,164 KB
最終ジャッジ日時 2023-08-10 01:33:31
合計ジャッジ時間 19,739 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
56,608 KB
testcase_01 AC 351 ms
61,004 KB
testcase_02 AC 297 ms
59,608 KB
testcase_03 AC 305 ms
61,924 KB
testcase_04 AC 291 ms
59,276 KB
testcase_05 AC 367 ms
62,604 KB
testcase_06 AC 359 ms
61,768 KB
testcase_07 AC 380 ms
61,208 KB
testcase_08 AC 402 ms
62,908 KB
testcase_09 WA -
testcase_10 AC 356 ms
60,324 KB
testcase_11 AC 378 ms
61,932 KB
testcase_12 AC 460 ms
62,848 KB
testcase_13 AC 369 ms
62,896 KB
testcase_14 AC 374 ms
60,488 KB
testcase_15 AC 379 ms
61,820 KB
testcase_16 AC 320 ms
60,236 KB
testcase_17 AC 352 ms
61,576 KB
testcase_18 WA -
testcase_19 AC 287 ms
60,176 KB
testcase_20 AC 379 ms
61,788 KB
testcase_21 AC 304 ms
59,560 KB
testcase_22 AC 278 ms
59,544 KB
testcase_23 AC 316 ms
60,848 KB
testcase_24 AC 205 ms
55,500 KB
testcase_25 AC 197 ms
56,920 KB
testcase_26 AC 167 ms
56,784 KB
testcase_27 AC 163 ms
56,872 KB
testcase_28 AC 163 ms
56,996 KB
testcase_29 AC 164 ms
57,260 KB
testcase_30 WA -
testcase_31 AC 165 ms
57,180 KB
testcase_32 AC 169 ms
56,908 KB
testcase_33 AC 166 ms
56,896 KB
testcase_34 AC 206 ms
57,096 KB
testcase_35 AC 261 ms
57,952 KB
testcase_36 AC 190 ms
56,876 KB
testcase_37 AC 380 ms
61,988 KB
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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


0