이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const ll INF = 1e18;
#define int long long
using node = tuple<int, int, int, int>;
int answer = INF;
vector<node> adj;
int n, kk;
int f(int x, int y, int xx){
int sm = 0, _x = (x/xx)*xx, _y = (y/xx)*xx;
if((_x/xx+_y/xx)&1){
sm += ((_x/xx)*(_y/xx))/2*(xx*xx);
sm += (_y/xx+1)/2*(x-_x)*xx;
sm += (_x/xx+1)/2*(y-_y)*xx;
}
else{
sm += ((_x/xx)*(_y /xx)+1)/2*(xx*xx);
sm += (_y/xx)/2*(x-_x)*xx;
sm += ((_x/xx))/2*(y-_y)*xx;
sm += (x-_x)*(y-_y);
}
return sm;
}
void solve(int x){
int ans = n*n-f(n, n, x);
for(auto xx : adj){
int a, b, c, d;
tie(a, b, c, d) = xx;
int w = f(c, d, x)+f(a-1, b-1, x)-f(c, b-1, x)-f(a-1, d, x);
ans += w, ans -= (c-a+1)*(d-b+1)-w;
}
umin(answer, ans);
umin(answer, n*n-ans);
}
signed main(){
// freopen("file.txt", "r", stdin);
scanf("%lld%lld", &n, &kk);
bool done = 1;
for(int i = 1; i <= kk; ++i){
int a, b, c, d;
scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
adj.pb({a, b, c, d});
done &= (a==c and b==d);
}
assert(done);
for(int i = 1; i*i <= n; ++i){
solve(i);
if(i!=n/i and i>1)
solve(n/i);
}
printf("%lld\n", answer);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
chessboard.cpp: In function 'int main()':
chessboard.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%lld%lld", &n, &kk);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |