Submission #968001

# Submission time Handle Problem Language Result Execution time Memory
968001 2024-04-23T06:51:00 Z PM1 Spiral (BOI16_spiral) C++17
0 / 100
75 ms 63312 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)<<'\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 63312 KB Output isn't correct
2 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 Incorrect 75 ms 63312 KB Output isn't correct
2 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 Incorrect 75 ms 63312 KB Output isn't correct
2 Halted 0 ms 0 KB -