답안 #516489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516489 2022-01-21T12:11:52 Z jurgis Spiral (BOI16_spiral) C++14
0 / 100
110 ms 262148 KB
#include <iostream>
#include <bits/stdc++.h>
#define F(end) for(int i =0; i< end; i++)
#define ll long long
using namespace std;
int ps[1000][1000];
const int mod = 1e9+7;
ll calc(int x1, int y1, int x2, int y2){
    return (ps[max(x1, x2)][max(y1, y2)] + ps[min(x1, x2)-1][min(y1, y2)-1] - ps[min(x1, x2)-1][max(y1, y2)] - ps[max(x1, x2)][min(y1, y2)-1]) % mod;
}
int main()
{
    int n, q; cin>>n>>q; bool filled = false;
    int grid [2*n+2][2*n+2]; int layer = 0; grid[n+1][n+1] = 1; int cnt=1; int init=1;
    while(layer<n){
        layer++;
        for(int i=1; i<=2*layer; i++){
            init++;
            grid[n+layer+1][n-layer +i+1] = init;
        }
        for(int i=1; i<=2*layer; i++){
            init++;
            grid[n+layer - i +1][n+layer+1] = init;
        }
         for(int i=1; i<=2*layer; i++){
            init++;
            grid[n-layer+1][n+layer - i+1] = init;
        }
         for(int i=1; i<=2*layer; i++){
            init++;
            grid[n-layer + i+1][n -layer+1] = init;
        }

    }
  /*  for(int i=2*n+1; i>=1; i--){
        for(int j=1; j<=2*n+1; j++){
            cout<<grid[j][i]<<" ";
        }
        cout<<endl;
    }
    */
    F(2*n+2) ps[i][0] = 0;
    F(2*n+2) ps[0][i] = 0;
    for(int i = 1; i<=2*n+1; i++){
        for(int j=1; j<=2*n+1; j++){
                ps[i][j] = grid[i][j] + ps[i-1][j]+ps[i][j-1] - ps[i-1][j-1];
        }
    }
    F(q){
        int x1, x2, y1, y2; cin>>x1>>y1>>x2>>y2; x1+=n+1; y1+=n+1; x2+=n+1; y2+=n+1;
        cout<<calc(x1, y1, x2, y2)<<"\n";

    }
}

Compilation message

spiral.cpp: In function 'int main()':
spiral.cpp:13:31: warning: unused variable 'filled' [-Wunused-variable]
   13 |     int n, q; cin>>n>>q; bool filled = false;
      |                               ^~~~~~
spiral.cpp:14:69: warning: unused variable 'cnt' [-Wunused-variable]
   14 |     int grid [2*n+2][2*n+2]; int layer = 0; grid[n+1][n+1] = 1; int cnt=1; int init=1;
      |                                                                     ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 31 ms 40088 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 110 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 31 ms 40088 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 101 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 31 ms 40088 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -