답안 #141700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
141700 2019-08-08T22:47:01 Z silxikys Chessboard (IZhO18_chessboard) C++14
8 / 100
47 ms 4208 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 1e5+5;
int N, K;

struct Rect
{
    int x1, y1, x2, y2;
};
vector<Rect> recs;

bool isWhite(int r, int c, int sz) {
    r /= sz;
    c /= sz;
    return (r+c) % 2 == 0;
}

ll solve(int sz) {
    ll res = 0;
    ll num = N/sz;
    if (num % 2 == 0) {
        res = 1LL*N*N/2;
    }
    else {
        res = (1LL*sz*sz) * (1LL*N*N) / 2;
    }
    //cout << sz << ": " << res << '\n';
    for (Rect re: recs) {
        for (int r = re.x1; r <= re.x2; r++) {
            for (int c = re.y1; c <= re.y2; c++) {
                if (isWhite(r,c,sz)) res++;
                else res--;
            }
        }
    }
    return res;
}

ll solve2(int sz) {
    ll res = 0;
    ll num = N/sz;
    if (num % 2 == 0) {
        res = 1LL*N*N/2;
    }
    else {
        res = (1LL*sz*sz) * (1LL*N*N+1) / 2;
    }
    for (Rect re: recs) {
        for (int r = re.x1; r <= re.x1; r++) {
            for (int c = re.y1; c <= re.y2; c++) {
                if (!isWhite(r,c,sz)) res++;
                else res--;
            }
        }
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> K;
    for (int i = 0; i < K; i++) {
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        x1--;
        y1--;
        x2--;
        y2--;
        recs.push_back({x1,y1,x2,y2});
    }
    ll ans = 1LL*N*N;
    for (int sz = 1; sz < N; sz++) {
        if (N % sz == 0) {
            ans = min(ans,solve(sz));
            ans = min(ans,solve2(sz));
        }
    }
    cout << ans << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 2924 KB Output is correct
2 Correct 10 ms 1272 KB Output is correct
3 Correct 21 ms 2440 KB Output is correct
4 Correct 22 ms 2296 KB Output is correct
5 Correct 28 ms 2676 KB Output is correct
6 Correct 19 ms 2292 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 19 ms 2288 KB Output is correct
9 Correct 47 ms 4208 KB Output is correct
10 Correct 26 ms 2544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 2924 KB Output is correct
2 Correct 10 ms 1272 KB Output is correct
3 Correct 21 ms 2440 KB Output is correct
4 Correct 22 ms 2296 KB Output is correct
5 Correct 28 ms 2676 KB Output is correct
6 Correct 19 ms 2292 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 19 ms 2288 KB Output is correct
9 Correct 47 ms 4208 KB Output is correct
10 Correct 26 ms 2544 KB Output is correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -