結果

問題 No.918 LISGRID
ユーザー 37zigen37zigen
提出日時 2020-03-11 14:07:52
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,564 bytes
コンパイル時間 5,849 ms
コンパイル使用メモリ 77,156 KB
実行使用メモリ 64,588 KB
最終ジャッジ日時 2023-08-10 01:29:17
合計ジャッジ時間 24,303 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 161 ms
57,036 KB
testcase_01 AC 359 ms
61,368 KB
testcase_02 WA -
testcase_03 AC 328 ms
61,484 KB
testcase_04 AC 300 ms
59,368 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 162 ms
56,996 KB
testcase_27 AC 162 ms
57,012 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 163 ms
56,760 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
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) {
				if(top==0) {
					for(int w=0;w<W;++w) {
						m[h][(w+W-A[h])%W]=s++;
						--B[w];
					}
				}else {
					int left=Math.min(bottom,A[h]-1);
					int right=A[h]-left;
					for(int w=0;w<bottom;++w) {
						m[h][(w+bottom-left)%bottom]=s++;
						--B[w];
					}
					for(int w=0;w<top;++w) {
						m[h][bottom+(w+top-right)%top]=t-(top-1)+w;
					}
					t-=top;
				}
			}else {
				for(int w=0;w<W;++w) {
					for(int i=h;i<H;++i) {
						if(B[w]>1) {
							m[i][w]=s++;
							B[w]--;
						}else m[i][w]=t--;
					}
				}
				break;
			}
		}
		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