import java.util.*; public class Main2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int d = sc.nextInt(); sc.nextLine(); List<Integer> dec = new ArrayList<>(); // HashSet<Integer> set = new HashSet<>(); int max = 0; //双层矩阵 for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { int m = sc.nextInt(); //set.add(m); max = Math.max(max, m); dec.add(m); } sc.nextLine(); } int count = 0; for (int num : dec) { if ((max - num) % d == 0) { count += (max - num) / d; } else { count = -1; break; } } System.out.println(count); } }
全部评论
(1) 回帖