Submission #938847

# Submission time Handle Problem Language Result Execution time Memory
938847 2024-03-05T16:36:09 Z Darren0724 Spiral (BOI16_spiral) C++17
12 / 100
105 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long 
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e9;
const int mod=1e9+7;
int32_t main() {
    LCBorz;
    int n;cin>>n;
    n=2*n+1;
    vector v(n+2,vector<int>(n+2,1));
    vector pre(n+2,vector<int>(n+2));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            v[i][j]=0;
        }
    }
    int now=n*n,dir=0;
    vector<int> dx={0,-1,0,1},dy={-1,0,1,0};
    int x=n,y=n;
    auto valid=[&](int a,int b,int dir){
        a+=dx[dir];
        b+=dy[dir];
        return a>0&&a<=n&&b>0&&b<=n&&v[a][b]==0;
    };
    while(1){
        v[x][y]=now;
        now--;
        if(now==0)break;
        if(!valid(x,y,dir)){
            dir=(dir+1)%4;
        }
        x+=dx[dir],y+=dy[dir];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            pre[i][j]=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]+v[n+1-i][j];
        }
    }
    int q;cin>>q;
    for(int i=0;i<q;i++){
        int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
        x1+=n/2,y1+=n/2,x2+=n/2+1,y2+=n/2+1;
        cout<<(pre[y2][x2]-pre[y2][x1]-pre[y1][x2]+pre[y1][x1])%mod<<endl;
    }

    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 58 ms 63380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 99 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 63380 KB Output is correct
2 Runtime error 105 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 70 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 63380 KB Output is correct
2 Runtime error 99 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -