Submission #141698

# Submission time Handle Problem Language Result Execution time Memory
141698 2019-08-08T22:34:12 Z silxikys Chessboard (IZhO18_chessboard) C++14
8 / 100
45 ms 4200 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 r: recs) {
        if (isWhite(r.x1,r.y1,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 r: recs) {
        if (!isWhite(r.x1,r.y1,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';
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2872 KB Output is correct
2 Correct 10 ms 1272 KB Output is correct
3 Correct 22 ms 2544 KB Output is correct
4 Correct 22 ms 2288 KB Output is correct
5 Correct 28 ms 2692 KB Output is correct
6 Correct 19 ms 2292 KB Output is correct
7 Correct 6 ms 764 KB Output is correct
8 Correct 20 ms 2292 KB Output is correct
9 Correct 45 ms 4200 KB Output is correct
10 Correct 30 ms 2548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2872 KB Output is correct
2 Correct 10 ms 1272 KB Output is correct
3 Correct 22 ms 2544 KB Output is correct
4 Correct 22 ms 2288 KB Output is correct
5 Correct 28 ms 2692 KB Output is correct
6 Correct 19 ms 2292 KB Output is correct
7 Correct 6 ms 764 KB Output is correct
8 Correct 20 ms 2292 KB Output is correct
9 Correct 45 ms 4200 KB Output is correct
10 Correct 30 ms 2548 KB Output is correct
11 Incorrect 2 ms 376 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -