内存超限了怎么办啊
  • 板块P3913 车的攻击
  • 楼主ioio99
  • 当前回复5
  • 已保存回复5
  • 发布时间2022/7/24 11:51
  • 上次更新2023/10/27 18:40:42
查看原帖
内存超限了怎么办啊
607095
ioio99楼主2022/7/24 11:51
import java.io.*;
public class Main {
	public static void main(String[] args) throws Exception{
		BufferedWriter pi=new BufferedWriter(new OutputStreamWriter(System.out));
		PrintWriter pw=new PrintWriter(pi);
		Read read=new Read();
		int n=read.nextInt();
		int k=read.nextInt();
		int a[]=new int[n+1];//判断行是否被攻击
		int s1=0;
		int b[]=new int[n+1];//判断列是否被攻击
		int s2=0;
		long sum=0;
		for(int z=0;z<k;z++)
		{
			int i=read.nextInt();
			int j=read.nextInt();
			if(a[i]==0)
			{
				s1++;
				a[i]=1;
				sum+=(n-s2);
			}
			if(b[j]==0)
			{
				s2++;
				b[j]=1;
				sum+=(n-s1);
			}
		}
		pw.print(sum);
		pw.flush();
	}
	
}
class Read{
	BufferedReader sh=new BufferedReader(new InputStreamReader(System.in));
	StreamTokenizer st=new StreamTokenizer(sh);
	public int nextInt() throws Exception{
		st.nextToken();
		return (int)st.nval;
	}
	public String next() throws Exception{
		st.nextToken();
		return st.sval;
	}
	public String nextLine() throws Exception{
		return sh.readLine();
	}
}

2022/7/24 11:51
加载中...