Submission #917166

# Submission time Handle Problem Language Result Execution time Memory
917166 2024-01-27T11:00:43 Z dilanyan Chessboard (IZhO18_chessboard) C++17
8 / 100
16 ms 3164 KB
//-------------dilanyan------------\\ 
 
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
 
//------------------KarginDefines--------------------\\ 
 
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
 
 
//-------------------KarginConstants------------------\\ 
 
const ll mod = 1000000007;
const ll inf = 1e9 + 15;
 
//-------------------KarginCode------------------------\\ 
 
const int N = 1005;
bool a[N][N]; // false -> white true -> black
int pref[2][N][N]; // 0 spitakneri qanaky minchev i,j u 1 severi qanaky

bool isprime(int n) {
    if (n <= 1) return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

void KarginSolve() {
    int n, k;
    cin >> n >> k;
    int sq = sqrt(n);
    vector<int> div;
    for (int i = 1;i <= sq;i++) {
        if (n % i == 0) {
            div.pb(i);
            if (i * i != n) div.pb(n / i);
        }
    }
    if (div.size() == 2) {
        ll fb = (n * n + 1) / 2, fw = n * n / 2;
        for (int i = 0; i < k;i++) {
            int x, y;
            cin >> x >> y >> x >> y;
            if (x & 1) {
                if (y & 1) fb--;
                else fw--;
            }
            else {
                if (y & 1) fw--;
                else fb--;
            }
        }
        cout << min(fb, fw) << '\n';
    }
    else if (n <= 1000) {
        for (int i = 0; i < k;i++) {
            int x1, y1, x2, y2;
            cin >> x1 >> y1 >> x2 >> y2;
            a[x1][y1] = true;
        }
        for (int i = 1;i <= n;i++) {
            for (int j = 1;j <= n;j++) {
                for (int c = 0;c < 2;c++) {
                    pref[c][i][j] = pref[c][i - 1][j] + pref[c][i][j - 1] - pref[c][i - 1][j - 1] + (a[i][j] == c);
                }
            }
        }
        int ans = n * n / 2;
        for (int d : div) {
            if (d == n) continue;
            int fw = 0, fb = 0;
            for (int i = d, it = 1;i <= n;i += d, it++) {
                for (int j = d, jt = 1;j <= n;j += d, jt++) {
                    if (it & 1) {
                        if (jt & 1) {
                            fb += pref[0][i][j] - pref[0][i - d][j] - pref[0][i][j - d] + pref[0][i - d][j - d];
                            fw += pref[1][i][j] - pref[1][i - d][j] - pref[1][i][j - d] + pref[1][i - d][j - d];
                        }
                        else {
                            fb += pref[1][i][j] - pref[1][i - d][j] - pref[1][i][j - d] + pref[1][i - d][j - d];
                            fw += pref[0][i][j] - pref[0][i - d][j] - pref[0][i][j - d] + pref[0][i - d][j - d];
                        }
                    }
                    else {
                        if (jt & 1) {
                            fb += pref[1][i][j] - pref[1][i - d][j] - pref[1][i][j - d] + pref[1][i - d][j - d];
                            fw += pref[0][i][j] - pref[0][i - d][j] - pref[0][i][j - d] + pref[0][i - d][j - d];
                        }
                        else {
                            fb += pref[0][i][j] - pref[0][i - d][j] - pref[0][i][j - d] + pref[0][i - d][j - d];
                            fw += pref[1][i][j] - pref[1][i - d][j] - pref[1][i][j - d] + pref[1][i - d][j - d];
                        }
                    }
                }
            }
            ans = min(ans, min(fw, fb));
        }
        cout << ans << '\n';
    }
}
 
int main() {
    //Usaco
    Kargin;
    int test = 1;
    //cin >> test;
    while (test--) {
        KarginSolve();
    }
    return 0;
}

Compilation message

chessboard.cpp:1:1: warning: multi-line comment [-Wcomment]
    1 | //-------------dilanyan------------\\
      | ^
chessboard.cpp:8:1: warning: multi-line comment [-Wcomment]
    8 | //------------------KarginDefines--------------------\\
      | ^
chessboard.cpp:22:1: warning: multi-line comment [-Wcomment]
   22 | //-------------------KarginConstants------------------\\
      | ^
chessboard.cpp:27:1: warning: multi-line comment [-Wcomment]
   27 | //-------------------KarginCode------------------------\\
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 2 ms 3164 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2908 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 3164 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 2 ms 3164 KB Output is correct
10 Incorrect 1 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 1112 KB Output is correct
3 Correct 1 ms 1112 KB Output is correct
4 Correct 1 ms 1116 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 1 ms 1116 KB Output is correct
9 Incorrect 16 ms 1884 KB Output isn't correct
10 Halted 0 ms 0 KB -