开二维数组就一定会超内存吗
查看原帖
开二维数组就一定会超内存吗
1060961
Kxzzy_n楼主2024/3/18 21:19

想不出其他方法了,开个二维数组最后一个数据点爆内存了呜呜呜

import java.io.*;
import java.util.*;
public class Main {
	static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args) throws Exception{
//		Scanner scanner=new Scanner(System.in);
		String[] sp=br.readLine().split(" ");
		int n=Integer.parseInt(sp[0]);
		int m=Integer.parseInt(sp[1]);
		int t=Integer.parseInt(sp[2]);
		int[][] arr=new int[n+1][t+1];
		for(int i=0;i<m;i++) {
			sp=br.readLine().split(" ");
			int ts=Integer.parseInt(sp[0]);
			int id=Integer.parseInt(sp[1]);
			arr[id][ts]++;
		}
		br.close();
		int count=0;
		for(int i=1;i<=n;i++) {
			boolean loop=false;
			//循环每个店铺的订餐情况
			int res=0;//初始积分
			for(int j=1;j<=t;j++) {//循环每个时间段
				if (arr[i][j]==0) {
					res=Math.max(0, res-1);
				}else {
					res+=arr[i][j]*2;
				}
				if (res>5) {
					loop=true;
				}
				if (res<=3) {
					loop=false;
				}
			}
			if (loop) {
				count++;
			}
		
		}
		bw.write(count+"");
		bw.flush();
	
	}
}

2024/3/18 21:19
加载中...