Submission #689446

# Submission time Handle Problem Language Result Execution time Memory
689446 2023-01-28T13:53:39 Z YENGOYAN Chessboard (IZhO18_chessboard) C++17
70 / 100
377 ms 5396 KB
/*
        //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
        \\                                    //
        //  271828___182845__904523__53602__  \\
        \\  87___47____13______52____66__24_  //
        //  97___75____72______47____09___36  \\
        \\  999595_____74______96____69___67  //
        //  62___77____24______07____66__30_  \\
        \\  35___35____47______59____45713__  //
        //                                    \\
        \\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
                                                    */

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>

using namespace std;
using ll = long long;
const int N = 3e5 + 5;
const ll mod = 1e9 + 7, inf = 1e18;

struct rec {
    ll x1, y1, x2, y2;
};

bool ev_od(ll x, ll y, ll side) {
    ll xx = (x + side - 1) / side, yy = (y + side - 1) / side;
    if (xx % 2 == yy % 2) return 0;
    return 1;
}

void solve() {
    ll n, k; cin >> n >> k;
    vector<rec> v(k);
    for(int i = 0; i < k; ++i) {
        cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
    }
    ll ans = n * n;
    for (int i = 1; i < n; ++i) {
        if (n % i) continue;
        ll od = 0, ev = 0;
        for (rec& ii : v) {
            ll xx2 = ii.x2 / i * i;
            ll xx1 = (ii.x1 + i - 1) / i * i;
            ll yy2 = ii.y2 / i * i;
            ll yy1 = (ii.y1 + i - 1) / i * i;
            //if(i == 2) cout << xx1 << " " << yy1 << " " << xx2 << " " << yy2 << "\n";
            if (xx1 < xx2 && yy1 < yy2) {
                ll ynd = (xx2 - xx1) / i * (yy2 - yy1) / i;
                ev += (ynd + ((xx1 / i) % 2 == (yy1 / i) % 2)) / 2 * i * i;
                od += (ynd + ((xx1 / i) % 2 != (yy1 / i) % 2)) / 2 * i * i;
                // bajnel vec uxankyan
                // dzax verev
                if (ev_od(ii.x1, ii.y1, i)) {
                    od += (xx1 - ii.x1) * (yy1 - ii.y1);
                }
                else {
                    ev += (xx1 - ii.x1) * (yy1 - ii.y1);
                }
                // aj verev
                if (ev_od(xx2, ii.y1, i)) {
                    od += (yy1 - ii.y1) * (ii.x2 - xx2);
                }
                else {
                    ev += (yy1 - ii.y1) * (ii.x2 - xx2);
                }
                // verev mejtex
                ll h = yy1 - ii.y1;
                if (ev_od(xx1, ii.y1, i)) {
                    ll w = xx2 - xx1, c = w / i;
                    od += (c + 1) / 2 * h * i;
                    ev += c / 2 * h * i;
                }
                else {
                    ll w = xx2 - xx1, c = w / i;
                    od += c / 2 * h * i;
                    ev += (c + 1) / 2 * h * i;
                }
                // mejtex dzax
                ll w = xx1 - ii.x1;
                if (ev_od(ii.x1, yy1, i)) {
                    ll h = yy2 - yy1, c = h / i;
                    od += (c + 1) / 2 * w * i;
                    ev += c / 2 * w * i;
                }
                else {
                    ll h = yy2 - yy1, c = h / i;
                    od += c / 2 * w * i;
                    ev += (c + 1) / 2 * w * i;
                }
                // mejtex aj
                w = ii.x2 - xx2;
                if (ev_od(xx2, yy1, i)) {
                    ll h = yy2 - yy1, c = h / i;
                    od += (c + 1) / 2 * w * i;
                    ev += c / 2 * w * i;
                }
                else {
                    ll h = yy2 - yy1, c = h / i;
                    od += c / 2 * w * i;
                    ev += (c + 1) / 2 * w * i;
                }
                // dzax var
                if (ev_od(ii.x1, yy2, i)) {
                    od += (xx1 - ii.x1) * (ii.y2 - yy2);
                }
                else {
                    ev += (xx1 - ii.x1) * (ii.y2 - yy2);
                }
                // aj var
                if (ev_od(xx2, yy2, i)) {
                    od += (ii.x2 - xx2) * (ii.y2 - yy2);
                }
                else {
                    ev += (ii.x2 - xx2) * (ii.y2 - yy2);
                }
                // var mejtex
                h = ii.y2 - yy2;
                if (ev_od(xx1, yy2, i)) {
                    ll w = xx2 - xx1, c = w / i;
                    od += (c + 1) / 2 * h * i;
                    ev += c / 2 * h * i;
                }
                else {
                    ll w = xx2 - xx1, c = w / i;
                    od += c / 2 * h * i;
                    ev += (c + 1) / 2 * h * i;
                }
            }
            /*
                        6 3
                        1 3 1 3
                        1 4 1 4
                        2 3 2 3
            */
            else if (xx1 >= xx2 && yy1 >= yy2) {
                //if(i == 2) cout << "DEBUG\n";
                // bajnel petq che, patasxany hashvac e
                if (ev_od(ii.x1, ii.y1, i)) {
                    od += (ii.x2 - ii.x1 + 1) * (ii.y2 - ii.y1 + 1);
                }
                else {
                    ev += (ii.x2 - ii.x1 + 1) * (ii.y2 - ii.y1 + 1);
                }
            }
            else if (xx1 >= xx2) {
                // bajnel ireq uxxankyan, verevi u vari masy arandzin, mejtexy arandzin
                // verevi masy
                if (ev_od(ii.x1, ii.y1, i)) {
                    od += (yy1 - ii.y1) * (ii.x2 - ii.x1);
                }
                else {
                    ev += (yy1 - ii.y1) * (ii.x2 - ii.x1);
                }
                // vari masy
                if (ev_od(ii.x1, yy2, i)) {
                    od += (ii.y2 - yy2) * (ii.x2 - ii.x1);
                }
                else {
                    ev += (ii.y2 - yy2) * (ii.x2 - ii.x1);
                }
                // mejtexi masy
                ll h = yy2 - yy1, c = h / i;
                if (ev_od(ii.x1, yy1, i)) {
                    od += (c + 1) / 2 * i * (ii.x2 - ii.x1);
                    ev += c / 2 * i * (ii.x2 - ii.x1);
                }
                else {
                    od += c / 2 * i * (ii.x2 - ii.x1);
                    ev += (c + 1) / 2 * i * (ii.x2 - ii.x1);
                }
            }
            else {
                // bajnel ireq uxxankyan, dzax u aj masy arandzin, mejtexy arandzin
                // dzax masy
                if (ev_od(ii.x1, ii.y1, i)) {
                    od += (ii.x2 - ii.x1) * (ii.y2 - ii.y1);
                }
                else {
                    ev += (ii.x2 - ii.x1) * (ii.y2 - ii.y1);
                }
                // aj masy
                if (ev_od(xx2, ii.y1, i)) {
                    od += (ii.x2 - xx2) * (ii.y2 - ii.y1);
                }
                else {
                    ev += (ii.x2 - xx2) * (ii.y2 - ii.y1);
                }
                // mejtexi masy
                ll w = xx2 - xx1, c = w / i;
                if (ev_od(xx1, ii.y1, i)) {
                    od += (c + 1) / 2 * i * (ii.y2 - ii.y1);
                    ev += c / 2 * i * (ii.y2 - ii.y1);
                }
                else {
                    od += c / 2 * i * (ii.y2 - ii.y1);
                    ev += (c + 1) / 2 * i * (ii.y2 - ii.y1);
                }
            }
        }
        ll edge = n / i, c = (edge * edge + 1) / 2;
        ll a = od + c * i * i - ev;
        c = edge * edge / 2;
        ll b = ev + c * i * i - od;
        ans = min({ ans, a, b });
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //int t; cin >> t;
    //while (t--)	
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2260 KB Output is correct
2 Correct 6 ms 724 KB Output is correct
3 Correct 13 ms 1492 KB Output is correct
4 Correct 15 ms 1684 KB Output is correct
5 Correct 20 ms 2004 KB Output is correct
6 Correct 11 ms 1364 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 14 ms 1364 KB Output is correct
9 Correct 29 ms 3028 KB Output is correct
10 Correct 22 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 12 ms 1108 KB Output is correct
17 Correct 22 ms 2900 KB Output is correct
18 Correct 30 ms 3412 KB Output is correct
19 Correct 79 ms 3028 KB Output is correct
20 Correct 86 ms 3412 KB Output is correct
21 Correct 21 ms 2772 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 18 ms 1620 KB Output is correct
24 Correct 29 ms 3028 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 21 ms 2088 KB Output is correct
27 Correct 25 ms 2388 KB Output is correct
28 Correct 29 ms 3284 KB Output is correct
29 Correct 9 ms 1364 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 2260 KB Output is correct
2 Correct 6 ms 724 KB Output is correct
3 Correct 13 ms 1492 KB Output is correct
4 Correct 15 ms 1684 KB Output is correct
5 Correct 20 ms 2004 KB Output is correct
6 Correct 11 ms 1364 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 14 ms 1364 KB Output is correct
9 Correct 29 ms 3028 KB Output is correct
10 Correct 22 ms 1876 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 12 ms 1108 KB Output is correct
27 Correct 22 ms 2900 KB Output is correct
28 Correct 30 ms 3412 KB Output is correct
29 Correct 79 ms 3028 KB Output is correct
30 Correct 86 ms 3412 KB Output is correct
31 Correct 21 ms 2772 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 18 ms 1620 KB Output is correct
34 Correct 29 ms 3028 KB Output is correct
35 Correct 4 ms 468 KB Output is correct
36 Correct 21 ms 2088 KB Output is correct
37 Correct 25 ms 2388 KB Output is correct
38 Correct 29 ms 3284 KB Output is correct
39 Correct 9 ms 1364 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 77 ms 2900 KB Output is correct
42 Correct 33 ms 3156 KB Output is correct
43 Correct 48 ms 2900 KB Output is correct
44 Correct 36 ms 3156 KB Output is correct
45 Correct 41 ms 3284 KB Output is correct
46 Correct 85 ms 3156 KB Output is correct
47 Correct 26 ms 2900 KB Output is correct
48 Correct 42 ms 3028 KB Output is correct
49 Correct 30 ms 2900 KB Output is correct
50 Correct 342 ms 3156 KB Output is correct
51 Correct 352 ms 3284 KB Output is correct
52 Correct 330 ms 3028 KB Output is correct
53 Correct 353 ms 3284 KB Output is correct
54 Correct 322 ms 3028 KB Output is correct
55 Correct 374 ms 3412 KB Output is correct
56 Correct 312 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 25 ms 2260 KB Output is correct
10 Correct 6 ms 724 KB Output is correct
11 Correct 13 ms 1492 KB Output is correct
12 Correct 15 ms 1684 KB Output is correct
13 Correct 20 ms 2004 KB Output is correct
14 Correct 11 ms 1364 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
16 Correct 14 ms 1364 KB Output is correct
17 Correct 29 ms 3028 KB Output is correct
18 Correct 22 ms 1876 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 12 ms 1108 KB Output is correct
35 Correct 22 ms 2900 KB Output is correct
36 Correct 30 ms 3412 KB Output is correct
37 Correct 79 ms 3028 KB Output is correct
38 Correct 86 ms 3412 KB Output is correct
39 Correct 21 ms 2772 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 18 ms 1620 KB Output is correct
42 Correct 29 ms 3028 KB Output is correct
43 Correct 4 ms 468 KB Output is correct
44 Correct 21 ms 2088 KB Output is correct
45 Correct 25 ms 2388 KB Output is correct
46 Correct 29 ms 3284 KB Output is correct
47 Correct 9 ms 1364 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 77 ms 2900 KB Output is correct
50 Correct 33 ms 3156 KB Output is correct
51 Correct 48 ms 2900 KB Output is correct
52 Correct 36 ms 3156 KB Output is correct
53 Correct 41 ms 3284 KB Output is correct
54 Correct 85 ms 3156 KB Output is correct
55 Correct 26 ms 2900 KB Output is correct
56 Correct 42 ms 3028 KB Output is correct
57 Correct 30 ms 2900 KB Output is correct
58 Correct 342 ms 3156 KB Output is correct
59 Correct 352 ms 3284 KB Output is correct
60 Correct 330 ms 3028 KB Output is correct
61 Correct 353 ms 3284 KB Output is correct
62 Correct 322 ms 3028 KB Output is correct
63 Correct 374 ms 3412 KB Output is correct
64 Correct 312 ms 2900 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Incorrect 377 ms 5396 KB Output isn't correct
68 Halted 0 ms 0 KB -