답안 #46793

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46793 2018-04-23T10:16:09 Z Waschbar Spiral (BOI16_spiral) C++17
12 / 100
534 ms 242684 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);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin >> n;

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

    for(int i = 1; i <= 3*MAXN+5; i++)
        for(int j = 1; j <= 3*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+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+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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 349 ms 121300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 513 ms 242564 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 349 ms 121300 KB Output is correct
2 Runtime error 534 ms 242564 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 530 ms 242684 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 349 ms 121300 KB Output is correct
2 Runtime error 513 ms 242564 KB Execution killed with signal 11 (could be triggered by violating memory limits)