Submission #191131

#TimeUsernameProblemLanguageResultExecution timeMemory
191131godwindChessboard (IZhO18_chessboard)C++14
39 / 100
437 ms20792 KiB
// O O O O O O O O O O O O O O O OO O OO O OO O O O TTCH O TTTCH O TTTCH O O O O
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("no-stack-protector")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
#include <cassert>
 
using namespace std;

#define int long long
#define y1 y11
#define double long double
#define less less228
#define left left228
#define right right228
#define list list228



template<typename T> void uin(T &a, T b) {
    if (b < a) a = b;
}
template<typename T> void uax(T &a, T b) {
    if (b > a) a = b;
}
 
 
random_device rnd;
 
template<typename T> void shuffle(vector< T > &v) {
    for (int i = 1; i < (int)v.size(); ++i) {
        swap(v[rnd() % i], v[i]);
    }
    for (int i = (int)v.size() - 1; i; --i) {
        swap(v[rnd() % i], v[i]);
    }
}

const int INF = 1e9 + 228;
const int N = 100 * 1000 + 228;

vector<int> get_divisors(int n) {
    int i = 1;
    vector<int> v;
    while (i * i <= n) {
        if (n % i == 0) {
            v.push_back(i);
            if (n / i != i && i != 1) {
                v.push_back(n / i);
            }
        }
        ++i;
    }
    sort(v.begin(), v.end());
    return v;
}

pair<int, int> get(int x1, int y1, int x2, int y2) {
    int white = (x2 - x1 + 1) * (y2 - y1 + 1) / 2;
    int black = white;
    if ( ((x2 - x1 + 1) * (y2 - y1 + 1)) % 2 == 1 ) {
        if ((x1 + y1) % 2 == 0) ++white;
        else ++black;
    }
    return {white, black};
}

int a[1005][1005];
int b[1005][1005];

int n, k;
int x1[N], y1[N], x2[N], y2[N];
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= k; ++i) {
        cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        for (int x = x1[i]; x <= x2[i]; ++x) {
            for (int y = y1[i]; y <= y2[i]; ++y) {
                b[x][y] = 1;
            }
        }
    }
    vector<int> div = get_divisors(n);
    int res = INF;
    for (int d : div) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                a[i][j] = 0;
                if (((i - 1) / d + (j - 1) / d) & 1) {
                    a[i][j] = 1;
                }
            }
        }
        int cur = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                cur += (a[i][j] ^ b[i][j]);
                a[i][j] ^= 1;
            }
        }
        uin(res, cur);
        cur = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                cur += (a[i][j] ^ b[i][j]);
            }
        }
        uin(res, cur);
    }
    cout << res << '\n';
    return 0;
}
// RU_023


/*

2 0


6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6

4 1
4 1 4 4


*/





#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...
#Verdict Execution timeMemoryGrader output
Fetching results...