提出 #71169854
ソースコード 拡げる
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
class Main {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int T = sc.nextInt();
C:for (int cases = 0; cases < T; cases++) {
int N = sc.nextInt();
int M = sc.nextInt();
int[] X = new int[N];
int[] Y =new int[M];
int[][] A = new int[N][M];
boolean[] used = new boolean[N*M+1];
int[] numToX = new int[N*M+1];
Arrays.fill(numToX,-1);
int max = 0;
int maxX = 0;
int maxY = 0;
int[] count = new int[N*M+1];
for (int i = 0; i < N; i++) {
X[i] = sc.nextInt();
if (max < X[i]){
maxX = i;
}
max = Math.max(max,X[i]);
count[X[i]]++;
numToX[X[i]] = i;
}
for (int i = 0; i < M; i++) {
Y[i] = sc.nextInt();
if (max <= Y[i]){
maxY = i;
}
max = Math.max(max,Y[i]);
count[Y[i]]++;
if (numToX[Y[i]] != -1){
A[numToX[Y[i]]][i] = Y[i];
used[Y[i]] = true;
}
}
for (int i = 0; i <= N*M; i++) {
if (count[i] >= 3){
System.out.println("No");
continue C;
}
}
if (N*M > max){
System.out.println("No");
continue;
}
if (count[max] == 1){
System.out.println("No");
continue C;
}
System.out.println("Yes");
Pair[] pair = new Pair[N*M+1];
A[maxX][maxY] = max;
int ind = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < maxY; j++) {
pair[ind] = new Pair(X[i],i,j);
ind++;
}
for (int j = maxY+1; j < M; j++) {
pair[ind] = new Pair(X[i],i,j);
ind++;
}
if (used[X[i]]){
continue;
}
A[i][maxY] = X[i];
used[X[i]] = true;
}
for (int i = 0; i < M; i++) {
for (int j = 0; j < maxX; j++) {
pair[ind] = new Pair(Y[i],j,i);
ind++;
}
for (int j = maxY+1; j < M; j++) {
pair[ind] = new Pair(Y[i],j,i);
ind++;
}
if (used[Y[i]]){
continue;
}
A[maxX][i] = Y[i];
used[Y[i]] = true;
}
Arrays.sort(pair);
int index = 1;
for (int i = 0; i <= N*M; i++) {
while (used[index]){
index++;
}
A[pair[i].x][pair[i].y] = index;
used[index] = true;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
System.out.print(A[i][j] +" ");
}
System.out.println();
}
}
MyWriter.flush();
}
static class Pair implements Comparable<Pair>{
static int w,x,y;
public Pair(int W,int X,int Y){
w = W;
x = X;
y = Y;
}
@Override
public int compareTo(Pair o) {
return -Integer.compare(w,o.w);
}
}
private static class MyWriter{
static StringBuilder sb = new StringBuilder();
protected static void flush(){
System.out.print(sb);
sb = new StringBuilder();
}
protected static void println(){
sb.append("\n");
}
protected static void println(int i){
sb.append(i).append("\n");
}
protected static void println(long l) {
sb.append(l).append("\n");
}
protected static void println(double d) {
sb.append(d).append("\n");
}
protected static void println(float f) {
sb.append(f).append("\n");
}
protected static void println(char c) {
sb.append(c).append("\n");
}
protected static void println(boolean b) {
sb.append(b).append("\n");
}
protected static void println(Object obj) {
String s = String.valueOf(obj);
sb.append(s).append("\n");
}
protected static void print(int i){
sb.append(i);
}
protected static void print(long l) {
sb.append(l);
}
protected static void print(double d) {
sb.append(d);
}
protected static void print(float f) {
sb.append(f);
}
protected static void print(char c) {
sb.append(c);
}
protected static void print(boolean b) {
sb.append(b);
}
protected static void print(Object obj) {
String s = String.valueOf(obj);
sb.append(s);
}
protected static void printInv(long a,long b,long MOD){
a %= MOD;
b %= MOD;
println((a * invGcd(b,MOD)[1])%MOD);
}
private static long safeMod(long x, long m){
x %= m;
if(x<0) x += m;
return x;
}
private static long[] invGcd(long a, long b){
a = safeMod(a, b);
if(a==0) return new long[]{b,0};
long s=b, t=a;
long m0=0, m1=1;
while(t>0){
long u = s/t;
s -= t*u;
m0 -= m1*u;
long tmp = s; s = t; t = tmp;
tmp = m0; m0 = m1; m1 = tmp;
}
if(m0<0) m0 += b/s;
return new long[]{s,m0};
}
public static long writerGcd(long... a){
if(a.length == 0) return 0;
long r = Math.abs(a[0]);
for(int i=1; i<a.length; i++){
if(a[i]!=0) {
if(r==0) r = Math.abs(a[i]);
else r = invGcd(r, Math.abs(a[i]))[0];
}
}
return r;
}
}
private static 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();
}
return buflen > 0;
}
}
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());
}
}
}
提出情報
| 提出日時 |
|
| 問題 |
E - Max Matrix 2 |
| ユーザ |
AAH_tomato |
| 言語 |
Java24 (OpenJDK 24.0.2) |
| 得点 |
0 |
| コード長 |
9369 Byte |
| 結果 |
RE |
| 実行時間 |
125 ms |
| メモリ |
51000 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
0 / 450 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt |
| All |
00_sample_00.txt, 01_small_00.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
RE |
49 ms |
38108 KiB |
| 01_small_00.txt |
RE |
45 ms |
37708 KiB |
| 02_random_00.txt |
RE |
125 ms |
51000 KiB |
| 02_random_01.txt |
AC |
104 ms |
48376 KiB |
| 02_random_02.txt |
RE |
118 ms |
48300 KiB |
| 02_random_03.txt |
AC |
105 ms |
48408 KiB |
| 02_random_04.txt |
AC |
111 ms |
44112 KiB |
| 02_random_05.txt |
RE |
74 ms |
46512 KiB |
| 02_random_06.txt |
RE |
90 ms |
47784 KiB |
| 02_random_07.txt |
RE |
87 ms |
47620 KiB |
| 02_random_08.txt |
RE |
77 ms |
45904 KiB |
| 02_random_09.txt |
RE |
77 ms |
41524 KiB |
| 02_random_10.txt |
RE |
47 ms |
38184 KiB |
| 02_random_11.txt |
RE |
47 ms |
38032 KiB |
| 02_random_12.txt |
RE |
46 ms |
37752 KiB |
| 02_random_13.txt |
RE |
45 ms |
38156 KiB |
| 02_random_14.txt |
RE |
45 ms |
37772 KiB |
| 02_random_15.txt |
RE |
46 ms |
38160 KiB |
| 02_random_16.txt |
RE |
45 ms |
37872 KiB |
| 02_random_17.txt |
RE |
45 ms |
37772 KiB |
| 02_random_18.txt |
RE |
46 ms |
38036 KiB |
| 02_random_19.txt |
RE |
45 ms |
37932 KiB |
| 02_random_20.txt |
RE |
46 ms |
38020 KiB |
| 02_random_21.txt |
RE |
98 ms |
46856 KiB |
| 02_random_22.txt |
RE |
78 ms |
46772 KiB |
| 02_random_23.txt |
AC |
58 ms |
42656 KiB |
| 02_random_24.txt |
AC |
60 ms |
42316 KiB |
| 02_random_25.txt |
AC |
59 ms |
41948 KiB |
| 02_random_26.txt |
AC |
55 ms |
41548 KiB |
| 02_random_27.txt |
AC |
70 ms |
41872 KiB |