이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cassert>
#include <climits>
#include <cstdio>
using namespace std;
typedef long long ll;
ll dist(int x, int y, int xx, int yy) {
return abs(xx - x) + abs(yy - y);
}
const ll MOD = 1000000007;
int main() {
//freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(false);
ll n;
int m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y >> x >> y;
if (x == 0 && y == 0) {
cout << 1 << endl;
continue;
}
int k = max(abs(x), abs(y));
if (abs(x) >= abs(y) && x<0 || abs(y)>=abs(x) && y < 0) {
ll ans = ((ll)2 * (ll)k + (ll)1)*((ll)2 * (ll)k + (ll)1) - dist(k, -k, x, y);
cout << ans%MOD << endl;
}
else {
ll ans = ((ll)2 * ((ll)k-(ll)1) + (ll)1)*((ll)2 * ((ll)k - (ll)1) + (ll)1) + dist(k, -k, x, y);
//cout << dist(k, -k, x, y) << endl;
cout << ans%MOD << endl;
}
}
//system("pause");
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
spiral.cpp: In function 'int main()':
spiral.cpp:34:24: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if (abs(x) >= abs(y) && x<0 || abs(y)>=abs(x) && y < 0) {
~~~~~~~~~~~~~~~~~^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |