답안 #407340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
407340 2021-05-18T18:36:01 Z arayi Chessboard (IZhO18_chessboard) C++17
70 / 100
505 ms 5844 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;
bool 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;
    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) + 1) / 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;
                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 * 1LL * 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;
}


/*

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

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 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
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 3684 KB Output is correct
2 Correct 8 ms 1220 KB Output is correct
3 Correct 18 ms 2528 KB Output is correct
4 Correct 19 ms 2608 KB Output is correct
5 Correct 25 ms 3340 KB Output is correct
6 Correct 16 ms 2224 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 16 ms 2192 KB Output is correct
9 Correct 42 ms 5120 KB Output is correct
10 Correct 23 ms 3024 KB Output is correct
# 결과 실행 시간 메모리 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 2 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 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 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 2 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 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 12 ms 1612 KB Output is correct
17 Correct 31 ms 4272 KB Output is correct
18 Correct 43 ms 5028 KB Output is correct
19 Correct 88 ms 4436 KB Output is correct
20 Correct 99 ms 4904 KB Output is correct
21 Correct 30 ms 4172 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 22 ms 2312 KB Output is correct
24 Correct 38 ms 4584 KB Output is correct
25 Correct 5 ms 756 KB Output is correct
26 Correct 24 ms 3020 KB Output is correct
27 Correct 32 ms 3524 KB Output is correct
28 Correct 40 ms 4824 KB Output is correct
29 Correct 13 ms 1908 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 3684 KB Output is correct
2 Correct 8 ms 1220 KB Output is correct
3 Correct 18 ms 2528 KB Output is correct
4 Correct 19 ms 2608 KB Output is correct
5 Correct 25 ms 3340 KB Output is correct
6 Correct 16 ms 2224 KB Output is correct
7 Correct 4 ms 716 KB Output is correct
8 Correct 16 ms 2192 KB Output is correct
9 Correct 42 ms 5120 KB Output is correct
10 Correct 23 ms 3024 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 2 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 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 12 ms 1612 KB Output is correct
27 Correct 31 ms 4272 KB Output is correct
28 Correct 43 ms 5028 KB Output is correct
29 Correct 88 ms 4436 KB Output is correct
30 Correct 99 ms 4904 KB Output is correct
31 Correct 30 ms 4172 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 22 ms 2312 KB Output is correct
34 Correct 38 ms 4584 KB Output is correct
35 Correct 5 ms 756 KB Output is correct
36 Correct 24 ms 3020 KB Output is correct
37 Correct 32 ms 3524 KB Output is correct
38 Correct 40 ms 4824 KB Output is correct
39 Correct 13 ms 1908 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 83 ms 4912 KB Output is correct
42 Correct 47 ms 5480 KB Output is correct
43 Correct 58 ms 4912 KB Output is correct
44 Correct 46 ms 5244 KB Output is correct
45 Correct 44 ms 5708 KB Output is correct
46 Correct 95 ms 5356 KB Output is correct
47 Correct 38 ms 5016 KB Output is correct
48 Correct 52 ms 5124 KB Output is correct
49 Correct 41 ms 4976 KB Output is correct
50 Correct 334 ms 5340 KB Output is correct
51 Correct 360 ms 5676 KB Output is correct
52 Correct 333 ms 5324 KB Output is correct
53 Correct 353 ms 5604 KB Output is correct
54 Correct 328 ms 5252 KB Output is correct
55 Correct 369 ms 5844 KB Output is correct
56 Correct 319 ms 5088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 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 34 ms 3684 KB Output is correct
10 Correct 8 ms 1220 KB Output is correct
11 Correct 18 ms 2528 KB Output is correct
12 Correct 19 ms 2608 KB Output is correct
13 Correct 25 ms 3340 KB Output is correct
14 Correct 16 ms 2224 KB Output is correct
15 Correct 4 ms 716 KB Output is correct
16 Correct 16 ms 2192 KB Output is correct
17 Correct 42 ms 5120 KB Output is correct
18 Correct 23 ms 3024 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 2 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 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 12 ms 1612 KB Output is correct
35 Correct 31 ms 4272 KB Output is correct
36 Correct 43 ms 5028 KB Output is correct
37 Correct 88 ms 4436 KB Output is correct
38 Correct 99 ms 4904 KB Output is correct
39 Correct 30 ms 4172 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 22 ms 2312 KB Output is correct
42 Correct 38 ms 4584 KB Output is correct
43 Correct 5 ms 756 KB Output is correct
44 Correct 24 ms 3020 KB Output is correct
45 Correct 32 ms 3524 KB Output is correct
46 Correct 40 ms 4824 KB Output is correct
47 Correct 13 ms 1908 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
49 Correct 83 ms 4912 KB Output is correct
50 Correct 47 ms 5480 KB Output is correct
51 Correct 58 ms 4912 KB Output is correct
52 Correct 46 ms 5244 KB Output is correct
53 Correct 44 ms 5708 KB Output is correct
54 Correct 95 ms 5356 KB Output is correct
55 Correct 38 ms 5016 KB Output is correct
56 Correct 52 ms 5124 KB Output is correct
57 Correct 41 ms 4976 KB Output is correct
58 Correct 334 ms 5340 KB Output is correct
59 Correct 360 ms 5676 KB Output is correct
60 Correct 333 ms 5324 KB Output is correct
61 Correct 353 ms 5604 KB Output is correct
62 Correct 328 ms 5252 KB Output is correct
63 Correct 369 ms 5844 KB Output is correct
64 Correct 319 ms 5088 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 1 ms 332 KB Output is correct
67 Incorrect 505 ms 5500 KB Output isn't correct
68 Halted 0 ms 0 KB -