我的java代码会超时0.2m左右,不知道还能怎么改减少运行时间
  • 板块P3397 地毯
  • 楼主User_BDAD
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/3/28 18:57
  • 上次更新2024/3/28 20:55:14
查看原帖
我的java代码会超时0.2m左右,不知道还能怎么改减少运行时间
1321318
User_BDAD楼主2024/3/28 18:57
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a[][] = new int[n + 2][m + 2];
		// 差分
		for (int i = 0; i < m; i++) {
			int x1 = sc.nextInt();
			int y1 = sc.nextInt();
			int x2 = sc.nextInt();
			int y2 = sc.nextInt();

			++a[x1][y1];
			++a[x2 + 1][y2 + 1];
			--a[x2 + 1][y1];
			--a[x1][y2 + 1];
		}
		// 前缀求和
		// 输出
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
				System.out.print(a[i][j] + " ");
			}
			System.out.println();
		}
	}
}

2024/3/28 18:57
加载中...