Submission #679404

#TimeUsernameProblemLanguageResultExecution timeMemory
679404Chal1shkanChessboard (IZhO18_chessboard)C++14
70 / 100
216 ms5772 KiB
#include <bits/stdc++.h>

# define pb push_back
# define ff first
# define ss second
# define nl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll maxn = 1e5 + 25;
const ll maxl = 22 + 0;
const ll inf = 2e9 + 0;
const ll mod = 998244353;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};

using namespace std;

ll n, k;

struct rect
{
    ll x1, y1, x2, y2;
} q[maxn];

vector <ll> f(ll x)
{
    vector <ll> res;
    res.pb(1);
    for (ll i = 2; i * i <= x; ++i)
    {
        if (x % i == 0)
        {
            res.pb(i);
            if (x % (x / i) == 0 && i != x / i) res.pb(x / i);
        }
    }
    return res;
}

void ma1n ()
{
    cin >> n >> k;
    for (ll i = 1; i <= k; ++i)
    {
        cin >> q[i].x1 >> q[i].y1 >> q[i].x2 >> q[i].y2;
    }
    vector <ll> d = f(n);
    ll ans = n * n;
    for (ll len : d)
    {
        ll cnt0 = 0, cnt1 = 0;
        for (ll i = 1; i <= k; ++i)
        {
            if (((q[i].x1 + len - 1) / len + (q[i].y1 + len - 1) / len) & 1) cnt1++;
            else cnt0++;
        }
        ll sz = (n * n) / len / len;
        ans = min(ans, len * len * (sz / 2) - cnt1 + cnt0);
        ans = min(ans, len * len * ((sz + 1) / 2) - cnt0 + cnt1);
    }
    cout << ans << nl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    // freopen("mooyomooyo.in", "r", stdin);
    // freopen("mooyomooyo.out", "w", stdout);
    int ttt = 1;
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test)
    {
//      cout << "Case " << test << ":" << nl;
        ma1n();
    }
    return 0;
}
#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...