Submission #407355

# Submission time Handle Problem Language Result Execution time Memory
407355 2021-05-18T19:07:19 Z arayi Chessboard (IZhO18_chessboard) C++17
100 / 100
525 ms 5840 KB
//Arayi
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#include <chrono>
#include <random>
#include <complex>

#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jigglypuff
#define ld long double
#define itn int
#define pir pair<int, int>
#define all(x) (x).begin(), (x).end()
#define str string
#define enl endl
#define en endl
#define cd complex<long double>
#define vcd vector<cd>
#define vii vector<int>
#define vlli vector<lli>
using namespace std;

lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x, ld y1, ld x2, ld y2)
{
    return sqrt((x - x2) * (x - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
    return (a * (a + 1LL)) / 2;
}
mt19937 rnd(363542);
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 0, -1, 0, 1, -1, -1, 1, 1, 0 };
int dy[] = { -1, 0, 1, 0, -1, 1, -1, 1, 0 };


const int N = 5e6 + 30;
const lli mod = 1e9 + 7;
const ld pi = acos(-1);
const ld e = log2(3);
const int T = 1000;

lli bp(lli a, lli b = mod - 2LL)
{
    lli ret = 1;
    while (b)
    {
        if (b & 1) ret *= a, ret %= mod;
        a *= a;
        a %= mod;
        b >>= 1;
    }
    return ret;
}
ostream& operator<<(ostream& c, pir a)
{
    c << a.fr << " " << a.sc;
    return c;
}
template<class T>
void maxi(T& a, T b)
{
    a = max(a, b);
}
template <class T>
void mini(T& a, T b)
{
    a = min(a, b);
}


lli n, k;
lli x1[N], x2[N], y1[N], y2[N];
lli sum, pat = mod * mod;
lli sp(lli i, lli j, lli x)
{
    if (((i / x) + (j / x)) % 2 == 0) return 1;
    return 0;
}
lli f1(lli x1, lli y1, lli x2, lli y2, lli x)
{
    return (x2 - x1 + 1LL) * 1LL * (y2 - y1 + 1LL) * sp(x1, y1, x);
}
lli f2(lli x1, lli y1, lli x2, lli y2, lli x)
{
    lli l = (y1 - 1 + x) / x, r = y2 / x;
    l *= x, r *= x;
    if (r < l) return f1(x1, y1, x2, y2, x);
    lli sm = f1(x1, y1, x2, l - 1, x) + f1(x1, r, x2, y2, x);
    lli s = (r - l) / x; s = (s + sp(x1, l, x)) / 2;
    sm += s * x * 1LL * (x2 - x1 + 1LL);
    return sm;
}
int main()
{
    fastio;
    cin >> n >> k;
    for (int i = 0; i < k; i++)
    {
        cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        x1[i]--, x2[i]--, y1[i]--, y2[i]--;
        sum += (x2[i] - x1[i] + 1) * 1LL * (y2[i] - y1[i] + 1);
    }
    for (lli x = 1; x < n; x++)
    {
        if (n % x) continue;
        lli sm = 0;
        lli ssp = ((n / x) * (n / x) + 1LL) / 2LL;
        ssp *= x * x;
        //cout << x << " " << ssp << endl;
        for (int i = 0; i < k; i++)
        {
            bool bl1 = ((x1[i] / x) != (x2[i] / x));
            bool bl2 = ((y1[i] / x) != (y2[i] / x));
            if (!bl1 && !bl2) sm += f1(x1[i], y1[i], x2[i], y2[i], x);
            else if (bl1 && !bl2) sm += f2(y1[i], x1[i], y2[i], x2[i], x);
            else if (!bl1 && bl2) sm += f2(x1[i], y1[i], x2[i], y2[i], x);
            else
            {
                lli i2 = (x2[i] / x) * x, j2 = (y2[i] / x) * x;
                lli i1 = ((x1[i] - 1 + x) / x) * x, j1 = ((y1[i] - 1 + x) / x) * x;
                //cout << i1 << " " << i2 << " " << j1 << " " << j2 << endl;
                sm += f2(y1[i], i1, j1 - 1, x2[i], x) + f2(i2, j1, x2[i], y2[i], x) + f2(j2, x1[i], y2[i], i2 - 1, x) + f2(x1[i], y1[i], i1 - 1, j2 - 1, x);
                lli s = ((i2 - i1) / x) * 1LL * ((j2 - j1) / x);
                sm += x * x * ((s + sp(i1, j1, x)) / 2LL);
            }
        }
        //cout << sm << endl;
        lli s = n * n - ssp - sum + sm;
        //cout << s << endl;
        mini(pat, s + sm);
        mini(pat, n * n - s - sm);
    }
    cout << pat << endl;
    return 0;
}


/*

    __
  *(><)*
    \/ /
    ||/
  --||
    ||
    /\
   /  \
  /    \

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2296 KB Output is correct
2 Correct 8 ms 844 KB Output is correct
3 Correct 18 ms 1576 KB Output is correct
4 Correct 19 ms 1752 KB Output is correct
5 Correct 24 ms 1964 KB Output is correct
6 Correct 16 ms 1356 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 16 ms 1356 KB Output is correct
9 Correct 39 ms 3140 KB Output is correct
10 Correct 22 ms 1924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 12 ms 1100 KB Output is correct
17 Correct 31 ms 2960 KB Output is correct
18 Correct 41 ms 3380 KB Output is correct
19 Correct 88 ms 3100 KB Output is correct
20 Correct 97 ms 3420 KB Output is correct
21 Correct 30 ms 2764 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 22 ms 1612 KB Output is correct
24 Correct 38 ms 3148 KB Output is correct
25 Correct 5 ms 588 KB Output is correct
26 Correct 24 ms 1996 KB Output is correct
27 Correct 38 ms 2460 KB Output is correct
28 Correct 40 ms 3304 KB Output is correct
29 Correct 14 ms 1488 KB Output is correct
30 Correct 2 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2296 KB Output is correct
2 Correct 8 ms 844 KB Output is correct
3 Correct 18 ms 1576 KB Output is correct
4 Correct 19 ms 1752 KB Output is correct
5 Correct 24 ms 1964 KB Output is correct
6 Correct 16 ms 1356 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 16 ms 1356 KB Output is correct
9 Correct 39 ms 3140 KB Output is correct
10 Correct 22 ms 1924 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 12 ms 1100 KB Output is correct
27 Correct 31 ms 2960 KB Output is correct
28 Correct 41 ms 3380 KB Output is correct
29 Correct 88 ms 3100 KB Output is correct
30 Correct 97 ms 3420 KB Output is correct
31 Correct 30 ms 2764 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 22 ms 1612 KB Output is correct
34 Correct 38 ms 3148 KB Output is correct
35 Correct 5 ms 588 KB Output is correct
36 Correct 24 ms 1996 KB Output is correct
37 Correct 38 ms 2460 KB Output is correct
38 Correct 40 ms 3304 KB Output is correct
39 Correct 14 ms 1488 KB Output is correct
40 Correct 2 ms 428 KB Output is correct
41 Correct 83 ms 2924 KB Output is correct
42 Correct 47 ms 3292 KB Output is correct
43 Correct 61 ms 2892 KB Output is correct
44 Correct 45 ms 3160 KB Output is correct
45 Correct 42 ms 3312 KB Output is correct
46 Correct 96 ms 3256 KB Output is correct
47 Correct 37 ms 2884 KB Output is correct
48 Correct 51 ms 2984 KB Output is correct
49 Correct 41 ms 2952 KB Output is correct
50 Correct 333 ms 3268 KB Output is correct
51 Correct 356 ms 3352 KB Output is correct
52 Correct 335 ms 3052 KB Output is correct
53 Correct 351 ms 3268 KB Output is correct
54 Correct 329 ms 3112 KB Output is correct
55 Correct 368 ms 3396 KB Output is correct
56 Correct 319 ms 3108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 27 ms 2296 KB Output is correct
10 Correct 8 ms 844 KB Output is correct
11 Correct 18 ms 1576 KB Output is correct
12 Correct 19 ms 1752 KB Output is correct
13 Correct 24 ms 1964 KB Output is correct
14 Correct 16 ms 1356 KB Output is correct
15 Correct 4 ms 460 KB Output is correct
16 Correct 16 ms 1356 KB Output is correct
17 Correct 39 ms 3140 KB Output is correct
18 Correct 22 ms 1924 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 12 ms 1100 KB Output is correct
35 Correct 31 ms 2960 KB Output is correct
36 Correct 41 ms 3380 KB Output is correct
37 Correct 88 ms 3100 KB Output is correct
38 Correct 97 ms 3420 KB Output is correct
39 Correct 30 ms 2764 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 22 ms 1612 KB Output is correct
42 Correct 38 ms 3148 KB Output is correct
43 Correct 5 ms 588 KB Output is correct
44 Correct 24 ms 1996 KB Output is correct
45 Correct 38 ms 2460 KB Output is correct
46 Correct 40 ms 3304 KB Output is correct
47 Correct 14 ms 1488 KB Output is correct
48 Correct 2 ms 428 KB Output is correct
49 Correct 83 ms 2924 KB Output is correct
50 Correct 47 ms 3292 KB Output is correct
51 Correct 61 ms 2892 KB Output is correct
52 Correct 45 ms 3160 KB Output is correct
53 Correct 42 ms 3312 KB Output is correct
54 Correct 96 ms 3256 KB Output is correct
55 Correct 37 ms 2884 KB Output is correct
56 Correct 51 ms 2984 KB Output is correct
57 Correct 41 ms 2952 KB Output is correct
58 Correct 333 ms 3268 KB Output is correct
59 Correct 356 ms 3352 KB Output is correct
60 Correct 335 ms 3052 KB Output is correct
61 Correct 351 ms 3268 KB Output is correct
62 Correct 329 ms 3112 KB Output is correct
63 Correct 368 ms 3396 KB Output is correct
64 Correct 319 ms 3108 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 332 KB Output is correct
67 Correct 500 ms 3288 KB Output is correct
68 Correct 507 ms 5444 KB Output is correct
69 Correct 432 ms 4872 KB Output is correct
70 Correct 445 ms 5312 KB Output is correct
71 Correct 463 ms 5240 KB Output is correct
72 Correct 454 ms 5216 KB Output is correct
73 Correct 470 ms 5028 KB Output is correct
74 Correct 492 ms 5316 KB Output is correct
75 Correct 476 ms 5224 KB Output is correct
76 Correct 505 ms 5532 KB Output is correct
77 Correct 110 ms 5788 KB Output is correct
78 Correct 54 ms 5204 KB Output is correct
79 Correct 84 ms 5004 KB Output is correct
80 Correct 88 ms 5188 KB Output is correct
81 Correct 82 ms 4932 KB Output is correct
82 Correct 74 ms 5396 KB Output is correct
83 Correct 66 ms 5060 KB Output is correct
84 Correct 315 ms 5600 KB Output is correct
85 Correct 516 ms 5828 KB Output is correct
86 Correct 2 ms 332 KB Output is correct
87 Correct 1 ms 332 KB Output is correct
88 Correct 525 ms 5840 KB Output is correct
89 Correct 114 ms 1492 KB Output is correct
90 Correct 1 ms 332 KB Output is correct