답안 #679358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
679358 2023-01-08T07:05:39 Z Chal1shkan Chessboard (IZhO18_chessboard) C++14
23 / 100
9 ms 4880 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;

int n, k;

struct rect
{
    int x1, y1, x2, y2;
} q[maxn];

int pref[1007][1007];

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

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

int solve1 (int len)
{
    int res1 = 0, res2 = 0;;
    int cnt = 0;
    for (int i = 1; i <= n; i += len)
    {
        if (cnt % 2 == 0)
        {
            bool boo = 1;
            for (int 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 (int 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 (int i = 1; i <= k; ++i)
    {
        cin >> q[i].x1 >> q[i].y1 >> q[i].x2 >> q[i].y2;
        pref[q[i].x1][q[i].y1]++;
    }
    if (prime(n))
    {
        int cnt0 = 0, cnt1 = 0;
        for (int i = 1; i <= k; ++i)
        {
            if ((q[i].x1 + q[i].y1) & 1) cnt1++;
            else cnt0++;
        }
        int ans1 = ((((n + 1) / 2) * ((n + 1) / 2)) + ((n / 2) * (n / 2))) - cnt0 + cnt1;
        int ans2 = ((((n + 1) / 2) * (n / 2)) + (((n + 1) / 2) * (n / 2))) - cnt1 + cnt0;
        cout << min(ans1, ans2) << nl;
    }
    else if (n <= 100)
    {
        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= n; ++j)
            {
                pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1]; 
            }
        }
        int ans = n * n;
        for (int 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 708 KB Output is correct
4 Correct 1 ms 708 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 584 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 468 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 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Incorrect 9 ms 4880 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 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 708 KB Output is correct
4 Correct 1 ms 708 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 584 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Runtime error 1 ms 468 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -