Submission #968008

# Submission time Handle Problem Language Result Execution time Memory
968008 2024-04-23T06:53:34 Z PM1 Spiral (BOI16_spiral) C++17
12 / 100
69 ms 63064 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxn=2005,M=1e9+7;
ll n,ps[mxn][mxn],q,a[mxn][mxn];
int cal(int x,int y,int xx,int yy){
	if(x==2*n && y==0){
		return ps[xx][yy];
	}
	else if(x==2*n){
		return (ps[xx][yy]-ps[xx][y-1]+M)%M;
	}
	else if(y==0){
		return (ps[xx][yy]-ps[x+1][yy]+M)%M;
	}
	return (ps[xx][yy]-ps[xx][y-1]-ps[x+1][yy]+ps[x+1][y-1]+M)%M;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>q;
	int cnt=n,x=n,y=n+1,w=1,k=2;
	a[n][n]=1;
	while(cnt--){
		a[x][y]=k;
		k++;
		for(int i=1;i<=w;i++,k++){
			x--;
			a[x][y]=k;
		}
		w++;
		for(int i=1;i<=w;i++,k++){
			y--;
			a[x][y]=k;
		}
		for(int i=1;i<=w;i++,k++){
			x++;
			a[x][y]=k;
		}
		for(int i=1;i<=w;i++,k++){
			y++;
			a[x][y]=k;
		}
		y++;
		w++;
	}
	for(int i=2*n;i>=0;i--){
		for(int j=0;j<=2*n;j++){
			ps[i][j]=0;
			ps[i][j]=(-cal(i,j,i,j)+a[i][j]+M)%M;
		}
	}
	while(q--){
		int x,y,xx,yy;
		cin>>y>>x>>yy>>xx;
		cout<<(cal(2*n-(x+n),y+n,2*n-(xx+n),yy+n)+M)%M<<'\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 69 ms 63064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 4700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 63064 KB Output is correct
2 Runtime error 4 ms 4952 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 4700 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 63064 KB Output is correct
2 Runtime error 4 ms 4700 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -