Submission #46792

# Submission time Handle Problem Language Result Execution time Memory
46792 2018-04-23T10:13:36 Z Waschbar Spiral (BOI16_spiral) C++17
0 / 100
335 ms 172536 KB
///©Waschbar
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1050;
const int INF = 1e9;
const long long MOD = 1e9+7;

long long g[3*MAXN+10][3*MAXN+10];
long long sum[3*MAXN+10][3*MAXN+10];

int n, m;

void func(long long k, int x,  int y, int num, char c) {
         if(x >= MAXN+5 || y >= MAXN+5) return;
         if(x <= -MAXN+1 || y <= -MAXN+1) return;
         if(k == 1){
            g[x+MAXN][y+MAXN] = k++;
         }
         if(c == 'R') {
            for(int i = 1; i <= num; i++) {
                y++;
                if(x >= MAXN+5 || y >= MAXN+5) break;
                if(x <= -MAXN+1 || y <= -MAXN+1) return;
                //cout << x << " "<<y <<" "<<k<<endl;
                g[x+MAXN][y+MAXN] = k++;
            }
            for(int i = 1; i <= num; i++) {
                x++;
                if(x <= -MAXN+1 || y <= -MAXN+1) return;
                if(x >= MAXN+5 || y >= MAXN+5) break;
                //cout << x << " "<<y <<" "<<k<<endl;
                g[x+MAXN][y+MAXN] = k++;
            }
            func(k,x,y,num+1,'L');
            return;
         }
         if(c == 'L') {
            for(int i = 1; i <= num; i++) {
                y--;
                if(x <= -MAXN+1 || y <= -MAXN+1) return;
                if(x >= MAXN+5 || y >= MAXN+5) break;
                //cout << x << " "<<y <<" "<<k<<endl;
                g[x+MAXN][y+MAXN] = k++;
            }
            for(int i = 1; i <= num; i++) {
                x--;
                if(x <= -MAXN+1 || y <= -MAXN+1) return;
                if(x >= MAXN+5 || y >= MAXN+5) break;
                //cout << x << " "<<y <<" "<<k<<endl;
                g[x+MAXN][y+MAXN] = k++;
            }
            func(k,x,y,num+1,'R');
            return;
         }
}

int main() {

    ios_base::sync_with_stdio(false);

    cin >> n;

    func(1,0,0,1,'R');

    for(int i = 1; i <= 2*MAXN+5; i++)
        for(int j = 1; j <= 2*MAXN+5; j++)
            sum[i][j] = ((sum[i-1][j]+(sum[i][j-1]-sum[i-1][j-1]+MOD)%MOD+MOD)%MOD+g[i][j]+MOD)%MOD;


    cin >> m;
    while(m--) {
        int x1, y1, x2, y2;
        cin >> y1 >> x1 >> y2 >> x2;
        x1 += MAXN; x2 += MAXN;
        y1 += MAXN; y2 += MAXN;
        cout << (long long)(sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1]+MOD)%MOD << endl;
    }

    /*for(int i = 0; i <= 12; i++) {
        for(int j = 0; j <= 12; j++) {
            if(g[i+MAXN-5][j+MAXN-5] < 10) cout << " ";
            cout << g[i+MAXN-5][j+MAXN-5] << " ";
        }
        cout << endl;
    }*/

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 170 ms 86272 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Runtime error 335 ms 172520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Incorrect 170 ms 86272 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Runtime error 326 ms 172536 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Incorrect 170 ms 86272 KB Output isn't correct