답안 #679360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679360 2023-01-08T07:08:29 Z Chal1shkan Chessboard (IZhO18_chessboard) C++14
31 / 100
28 ms 5216 KB
#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];

ll pref[1007][1007];

ll get (ll x1, ll y1, ll x2, ll y2)
{
    return pref[x2][y2] - pref[x1 - 1][y2] - pref[x2][y1 - 1] + pref[x1 - 1][y1 - 1];
}

bool prime (ll x)
{
    for (ll i = 2; i * i <= x; ++i)
    {
        if (x % i == 0) return 0;
        if (x % (x / i) == 0) return 0; 
    }
    return 1;
}

ll solve1 (ll len)
{
    ll res1 = 0, res2 = 0;;
    ll cnt = 0;
    for (ll i = 1; i <= n; i += len)
    {
        if (cnt % 2 == 0)
        {
            bool boo = 1;
            for (ll j = 1; j <= n; j += len)
            {
                if (boo)
                {
                    res1 += (len * len) - get(i, j, i + len - 1, j + len - 1);
                    res2 += get(i, j, i + len - 1, j + len - 1);
                }
                else
                {
                    res1 +=  get(i, j, i + len - 1, j + len - 1);
                    res2 += (len * len) - get(i, j, i + len - 1, j + len - 1);
                }
                boo ^= 1;
            }
        }
        else
        {
            bool boo = 1;
            for (ll j = 1; j <= n; j += len)
            {
                if (boo)
                {
                    res1 += get(i, j, i + len - 1, j + len - 1);
                    res2 += (len * len) - get(i, j, i + len - 1, j + len - 1);
                }
                else
                {    
                    res1 += (len * len) - get(i, j, i + len - 1, j + len - 1);
                    res2 +=  get(i, j, i + len - 1, j + len - 1);
                }
                boo ^= 1;
            }
        }
        cnt++;
    }
    return min(res1, res2);
}

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;
    }
    if (prime(n))
    {
        ll cnt0 = 0, cnt1 = 0;
        for (ll i = 1; i <= k; ++i)
        {
            if ((q[i].x1 + q[i].y1) & 1) cnt1++;
            else cnt0++;
        }
        ll ans1 = ((((n + 1) / 2) * ((n + 1) / 2)) + ((n / 2) * (n / 2))) - cnt0 + cnt1;
        ll ans2 = ((((n + 1) / 2) * (n / 2)) + (((n + 1) / 2) * (n / 2))) - cnt1 + cnt0;
        cout << min(ans1, ans2) << nl;
    }
    else if (n <= 100)
    {
        for (ll i = 1; i <= k; ++i)
        {
            pref[q[i].x1][q[i].y1]++;
        }
        for (ll i = 1; i <= n; ++i)
        {
            for (ll j = 1; j <= n; ++j)
            {
                pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1]; 
            }
        }
        ll ans = n * n;
        for (ll len = 1; len < n; ++len)
        {
            if (n % len == 0)
            {
                ans = min(ans, solve1(len));
            }
        }
        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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2284 KB Output is correct
2 Correct 5 ms 852 KB Output is correct
3 Correct 11 ms 1492 KB Output is correct
4 Correct 21 ms 2556 KB Output is correct
5 Correct 16 ms 3244 KB Output is correct
6 Correct 11 ms 2132 KB Output is correct
7 Correct 3 ms 728 KB Output is correct
8 Correct 11 ms 2264 KB Output is correct
9 Correct 28 ms 5216 KB Output is correct
10 Correct 16 ms 3020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Incorrect 7 ms 1152 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2284 KB Output is correct
2 Correct 5 ms 852 KB Output is correct
3 Correct 11 ms 1492 KB Output is correct
4 Correct 21 ms 2556 KB Output is correct
5 Correct 16 ms 3244 KB Output is correct
6 Correct 11 ms 2132 KB Output is correct
7 Correct 3 ms 728 KB Output is correct
8 Correct 11 ms 2264 KB Output is correct
9 Correct 28 ms 5216 KB Output is correct
10 Correct 16 ms 3020 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 724 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 724 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Incorrect 7 ms 1152 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 18 ms 2284 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 11 ms 1492 KB Output is correct
12 Correct 21 ms 2556 KB Output is correct
13 Correct 16 ms 3244 KB Output is correct
14 Correct 11 ms 2132 KB Output is correct
15 Correct 3 ms 728 KB Output is correct
16 Correct 11 ms 2264 KB Output is correct
17 Correct 28 ms 5216 KB Output is correct
18 Correct 16 ms 3020 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 724 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Incorrect 7 ms 1152 KB Output isn't correct
35 Halted 0 ms 0 KB -