Submission #897764


Source Code Expand

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
 
public class Main {
	static Scanner in;
	static int r, c, n, ri, ci;
	static long a[][];
	static String ans = "Yes";
	public static void main(String[] args) throws FileNotFoundException {
//		in = new Scanner(new File("input.txt"));
		in = new Scanner(System.in);
		r = in.nextInt();
		c = in.nextInt();
		n = in.nextInt();
		a = new long[r + 1][c + 1];
		for(int i = 1;i <= r;i++){
			for(int j = 1;j <= c;j++){
				a[i][j] = -1;
			}
		}
		while(n-- > 0){
			ri = in.nextInt();
			ci = in.nextInt();
			a[ri][ci] = in.nextLong();
		}
		if(r == 2 && c == 2){
			if(a[1][1] == -1 && a[2][1] + a[1][2] - a[2][2] < 0) ans = "No";
			else if(a[1][2] == -1 && a[2][2] + a[1][1] - a[2][1] < 0) ans = "No";
			else if(a[2][1] == -1 && a[2][2] + a[1][1] - a[1][2] < 0) ans = "No";
			else if(a[2][2] == -1 && a[2][1] + a[1][2] - a[1][1] < 0) ans = "No";
			else{
				if(a[1][1] + a[2][2] != a[1][2] + a[2][1]) ans = "No";
			}
		}else{
			// check horizontal
			for(int i = 1;i <= r - 2;i++){
				long first = -1;
				long second = -1;
				for(int j = 1;j <= c;j++){
					if(a[i][j] != -1 && a[i + 2][j] != -1){
						if(first >= 0) second = Math.abs(a[i][j] - a[i + 2][j]);
						else{
							first = Math.abs(a[i][j] - a[i + 2][j]);
							second = Math.abs(a[i][j] - a[i + 2][j]);
						}
						if(first != second){
							ans = "No";
							break;
						}
					}
				}
			}
			// check vertical
			for(int i = 1;i <= c - 2;i++){
				long first = -1;
				long second = -1;
				for(int j = 1;j <= r;j++){
					if(a[j][i] != -1 && a[j][i + 2] != -1){
						if(first >= 0) second = Math.abs(a[j][i] - a[j][i + 2]);
						else{
							first = Math.abs(a[j][i] - a[j][i + 2]);
							second = Math.abs(a[j][i] - a[j][i + 2]);
						}
						if(first != second){
							ans = "No";
							break;
						}
					}
				}
			}
		}
		System.out.println(ans);
	}
}

Submission Info

Submission Time
Task D - Grid and Integers
User pvtuan10
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 2124 Byte
Status WA
Exec Time 2149 ms
Memory 921100 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 800
Status
AC × 4
WA × 1
AC × 9
WA × 1
TLE × 3
MLE × 56
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt
Case Name Status Exec Time Memory
0_00.txt WA 126 ms 9552 KiB
0_01.txt AC 124 ms 9684 KiB
0_02.txt AC 124 ms 9680 KiB
0_03.txt AC 124 ms 9664 KiB
0_04.txt AC 125 ms 9680 KiB
1_00.txt MLE 1033 ms 871448 KiB
1_01.txt MLE 1035 ms 871476 KiB
1_02.txt MLE 1035 ms 871480 KiB
1_03.txt MLE 1038 ms 871720 KiB
1_04.txt MLE 1038 ms 871468 KiB
1_05.txt MLE 1036 ms 871352 KiB
1_06.txt MLE 1032 ms 871476 KiB
1_07.txt MLE 1040 ms 871480 KiB
1_08.txt MLE 1035 ms 871612 KiB
1_09.txt MLE 1033 ms 871352 KiB
1_10.txt MLE 1032 ms 871352 KiB
1_11.txt MLE 1034 ms 871336 KiB
1_12.txt MLE 1038 ms 871348 KiB
1_13.txt MLE 1039 ms 871484 KiB
1_14.txt MLE 1033 ms 871604 KiB
1_15.txt MLE 1032 ms 871472 KiB
1_16.txt MLE 1034 ms 871468 KiB
1_17.txt MLE 1050 ms 871460 KiB
1_18.txt MLE 1037 ms 871476 KiB
1_19.txt MLE 1033 ms 871352 KiB
1_20.txt MLE 1041 ms 869792 KiB
1_21.txt MLE 1044 ms 870716 KiB
1_22.txt MLE 1092 ms 866168 KiB
1_23.txt MLE 1036 ms 871344 KiB
1_24.txt MLE 1041 ms 871216 KiB
1_25.txt MLE 1057 ms 870036 KiB
1_26.txt TLE 2149 ms 872688 KiB
1_27.txt MLE 1036 ms 872480 KiB
1_28.txt MLE 1047 ms 871268 KiB
1_29.txt MLE 1034 ms 871972 KiB
1_30.txt MLE 1035 ms 875276 KiB
1_31.txt MLE 1041 ms 873904 KiB
1_32.txt MLE 1071 ms 900624 KiB
1_33.txt MLE 1057 ms 902064 KiB
1_34.txt MLE 1041 ms 871568 KiB
1_35.txt AC 751 ms 97524 KiB
1_36.txt MLE 1086 ms 867332 KiB
1_37.txt MLE 1084 ms 897432 KiB
1_38.txt MLE 1032 ms 871984 KiB
1_39.txt MLE 1032 ms 873636 KiB
1_40.txt MLE 1057 ms 871352 KiB
1_41.txt MLE 1039 ms 871184 KiB
1_42.txt MLE 1067 ms 901788 KiB
1_43.txt MLE 1045 ms 873808 KiB
1_44.txt MLE 1098 ms 866372 KiB
1_45.txt TLE 2134 ms 591676 KiB
1_46.txt MLE 1039 ms 874516 KiB
1_47.txt MLE 1039 ms 873252 KiB
1_48.txt MLE 1067 ms 866556 KiB
1_49.txt MLE 1047 ms 869936 KiB
1_50.txt MLE 1067 ms 898852 KiB
1_51.txt MLE 1063 ms 896860 KiB
1_52.txt MLE 1036 ms 872108 KiB
1_53.txt MLE 1067 ms 901424 KiB
1_54.txt MLE 1064 ms 867156 KiB
1_55.txt TLE 2027 ms 604400 KiB
1_56.txt MLE 1067 ms 898408 KiB
1_57.txt MLE 1064 ms 921100 KiB
1_58.txt MLE 1046 ms 868108 KiB
1_59.txt MLE 1034 ms 872720 KiB
1_60.txt AC 124 ms 9676 KiB
1_61.txt AC 125 ms 9680 KiB
1_62.txt AC 127 ms 9676 KiB
1_63.txt AC 125 ms 9684 KiB