제출 #368066

#제출 시각아이디문제언어결과실행 시간메모리
368066benedict0724Spiral (BOI16_spiral)C++17
0 / 100
62 ms32264 KiB
#include <iostream> using namespace std; int arr[2003][2003]; int main() { arr[1001][1001] = 1; int x = 1001, y = 1001, cnt = 1; for(int i=1;i<=1000;i++){ arr[++x][y] = ++cnt; for(int j=1;j<=2*i-1;j++) arr[x][++y] = ++cnt; for(int j=1;j<=2*i;j++) arr[--x][y] = ++cnt; for(int j=1;j<=2*i;j++) arr[x][--y] = ++cnt; for(int j=1;j<=2*i;j++) arr[++x][y] = ++cnt; } for(int i=1;i<=2001;i++){ for(int j=1;j<=2001;j++){ arr[i][j] += arr[i-1][j] + arr[i][j-1] - arr[i-1][j-1]; } } ios::sync_with_stdio(false); int n, q; cin >> n >> q; for(int i=1;i<=q;i++){ int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; x1 += 1001; x2 += 1001; y1 += 1001; y2 += 1001; cout << arr[x2][y2] - arr[x2][y1-1] - arr[x1-1][y2] + arr[x1-1][y1-1] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...