Submission #689594

# Submission time Handle Problem Language Result Execution time Memory
689594 2023-01-28T19:46:21 Z YENGOYAN Chessboard (IZhO18_chessboard) C++17
70 / 100
550 ms 4252 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 - 1) / i * i;
            ll xx1 = (ii.x1 - 1) / i * i;
            ll yy2 = (ii.y2 - 1) / i * i;
            ll yy1 = (ii.y1 - 1) / i * i;
            ++xx1, ++yy1;
            ++xx2, ++yy2;
            //cout << xx1 << " " << yy1 << " " << xx2 << " " << yy2 << "\n";
            //if(i == 2) cout << xx1 << " " << yy1 << " " << xx2 << " " << yy2 << "\n";
            if (xx1 < xx2 && yy1 < yy2) {
                ll ynd = (xx2 - xx1 + 1) / i * (yy2 - yy1 + 1) / 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
                //cout << "DEBUG\n";
                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 1 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 21 ms 2264 KB Output is correct
2 Correct 6 ms 724 KB Output is correct
3 Correct 13 ms 1492 KB Output is correct
4 Correct 14 ms 1704 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 12 ms 1364 KB Output is correct
9 Correct 29 ms 3028 KB Output is correct
10 Correct 16 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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 10 ms 1608 KB Output is correct
17 Correct 24 ms 3724 KB Output is correct
18 Correct 35 ms 4180 KB Output is correct
19 Correct 106 ms 3848 KB Output is correct
20 Correct 120 ms 4180 KB Output is correct
21 Correct 32 ms 3612 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 21 ms 2272 KB Output is correct
24 Correct 32 ms 3904 KB Output is correct
25 Correct 5 ms 708 KB Output is correct
26 Correct 22 ms 2856 KB Output is correct
27 Correct 33 ms 3212 KB Output is correct
28 Correct 33 ms 4052 KB Output is correct
29 Correct 10 ms 1876 KB Output is correct
30 Correct 2 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2264 KB Output is correct
2 Correct 6 ms 724 KB Output is correct
3 Correct 13 ms 1492 KB Output is correct
4 Correct 14 ms 1704 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 12 ms 1364 KB Output is correct
9 Correct 29 ms 3028 KB Output is correct
10 Correct 16 ms 1876 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 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 10 ms 1608 KB Output is correct
27 Correct 24 ms 3724 KB Output is correct
28 Correct 35 ms 4180 KB Output is correct
29 Correct 106 ms 3848 KB Output is correct
30 Correct 120 ms 4180 KB Output is correct
31 Correct 32 ms 3612 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 21 ms 2272 KB Output is correct
34 Correct 32 ms 3904 KB Output is correct
35 Correct 5 ms 708 KB Output is correct
36 Correct 22 ms 2856 KB Output is correct
37 Correct 33 ms 3212 KB Output is correct
38 Correct 33 ms 4052 KB Output is correct
39 Correct 10 ms 1876 KB Output is correct
40 Correct 2 ms 448 KB Output is correct
41 Correct 98 ms 3676 KB Output is correct
42 Correct 40 ms 4028 KB Output is correct
43 Correct 62 ms 3696 KB Output is correct
44 Correct 39 ms 3924 KB Output is correct
45 Correct 37 ms 4104 KB Output is correct
46 Correct 112 ms 3984 KB Output is correct
47 Correct 29 ms 3756 KB Output is correct
48 Correct 49 ms 3808 KB Output is correct
49 Correct 34 ms 3656 KB Output is correct
50 Correct 482 ms 3924 KB Output is correct
51 Correct 508 ms 4120 KB Output is correct
52 Correct 476 ms 3908 KB Output is correct
53 Correct 496 ms 4052 KB Output is correct
54 Correct 473 ms 3796 KB Output is correct
55 Correct 524 ms 4180 KB Output is correct
56 Correct 451 ms 3780 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 1 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 21 ms 2264 KB Output is correct
10 Correct 6 ms 724 KB Output is correct
11 Correct 13 ms 1492 KB Output is correct
12 Correct 14 ms 1704 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 12 ms 1364 KB Output is correct
17 Correct 29 ms 3028 KB Output is correct
18 Correct 16 ms 1876 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 332 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 328 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 1 ms 316 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 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 10 ms 1608 KB Output is correct
35 Correct 24 ms 3724 KB Output is correct
36 Correct 35 ms 4180 KB Output is correct
37 Correct 106 ms 3848 KB Output is correct
38 Correct 120 ms 4180 KB Output is correct
39 Correct 32 ms 3612 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 21 ms 2272 KB Output is correct
42 Correct 32 ms 3904 KB Output is correct
43 Correct 5 ms 708 KB Output is correct
44 Correct 22 ms 2856 KB Output is correct
45 Correct 33 ms 3212 KB Output is correct
46 Correct 33 ms 4052 KB Output is correct
47 Correct 10 ms 1876 KB Output is correct
48 Correct 2 ms 448 KB Output is correct
49 Correct 98 ms 3676 KB Output is correct
50 Correct 40 ms 4028 KB Output is correct
51 Correct 62 ms 3696 KB Output is correct
52 Correct 39 ms 3924 KB Output is correct
53 Correct 37 ms 4104 KB Output is correct
54 Correct 112 ms 3984 KB Output is correct
55 Correct 29 ms 3756 KB Output is correct
56 Correct 49 ms 3808 KB Output is correct
57 Correct 34 ms 3656 KB Output is correct
58 Correct 482 ms 3924 KB Output is correct
59 Correct 508 ms 4120 KB Output is correct
60 Correct 476 ms 3908 KB Output is correct
61 Correct 496 ms 4052 KB Output is correct
62 Correct 473 ms 3796 KB Output is correct
63 Correct 524 ms 4180 KB Output is correct
64 Correct 451 ms 3780 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Incorrect 550 ms 4252 KB Output isn't correct
68 Halted 0 ms 0 KB -