답안 #926344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926344 2024-02-12T20:00:52 Z AlphaMale06 Chessboard (IZhO18_chessboard) C++14
70 / 100
294 ms 3672 KB
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define int long long

struct rect{
    int x1, y1, x2, y2;
};

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    rect a[k];
    for(int i=0; i< k; i++){
        cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
        a[i].x1--;
        a[i].x2--;
        a[i].y1--;
        a[i].y2--;
    }
    int ans=1e12;
    for(int d=1; d<n; d++){
        if(n%d!=0)continue;
        int flip=d*d*(((n*n)/(d*d)+1)/2);
        for(int i=0; i< k; i++){
            int subx1=a[i].x1/d;
            int subx2=a[i].x2/d;
            int suby1=a[i].y1/d;
            int suby2=a[i].y2/d;
            //tretiras ovaj case isto kao i 1x1 kvadrate, jer skroz spadaju u to
            if(subx1==subx2 && suby1==suby2){
                if((subx1&1)==(suby1&1))flip-=(a[i].x2-a[i].x1+1)*(a[i].y2-a[i].y1+1);
                else flip+=(a[i].x2-a[i].x1+1)*(a[i].y2-a[i].y1+1);
                continue;
            }
            //kad nije u samo jednom dxd polju
            if(subx1==subx2){//kad je samo po y vise polja
                int dify=suby2-suby1-1; //broj polja izmedju
                if(dify&1){//ako je neparno onda utice na score
                    if(subx1%2==suby1%2){//u ovom slucaju pravougaonik koji pokrivas ima jedno vise belo nego crno dxd
                        flip+=d*(a[i].x2-a[i].x1+1);
                    }
                    else{ //u suprotnom jedno vise crno dxd
                        flip-=d*(a[i].x2-a[i].x1+1);
                    }
                }
                //sad treba samo ove otsecke
                if(subx1%2==suby1%2){
                    flip-=(a[i].x2-a[i].x1+1)*((suby1+1)*d-a[i].y1);
                }
                else{
                    flip+=(a[i].x2-a[i].x1+1)*((suby1+1)*d-a[i].y1);
                }
                if(subx1%2==suby2%2){
                    flip-=(a[i].x2-a[i].x1+1)*(a[i].y2-suby2*d+1);
                }
                else{
                    flip+=(a[i].x2-a[i].x1+1)*(a[i].y2-suby2*d+1);
                }
            }
            else if(suby1==suby2){//kad je samo po x vise polja
                int difx=subx2-subx1-1; //broj polja izmedju
                if(difx&1){//ako je neparno onda utice na score
                    if(suby1%2==subx1%2){//u ovom slucaju pravougaonik koji pokrivas ima jedno vise belo nego crno dxd
                        flip+=d*(a[i].y2-a[i].y1+1);
                    }
                    else{ //u suprotnom jedno vise crno dxd
                        flip-=d*(a[i].y2-a[i].y1+1);
                    }
                }
                //sad treba samo ove otsecke
                if(suby1%2==subx1%2){
                    flip-=(a[i].y2-a[i].y1+1)*((subx1+1)*d-a[i].x1);
                }
                else{
                    flip+=(a[i].y2-a[i].y1+1)*((subx1+1)*d-a[i].x1);
                }
                if(suby1%2==subx2%2){
                    flip-=(a[i].y2-a[i].y1+1)*(a[i].x2-subx2*d+1);
                }
                else{
                    flip+=(a[i].y2-a[i].y1+1)*(a[i].x2-subx2*d+1);
                }
            }
            else{//kad je vise polja i po x i po y
                //oduzmes/dodas coskove
                if(subx1%2==suby1%2){
                    flip-=((subx1+1)*d-a[i].x1)*((suby1+1)*d-a[i].y1);
                }
                else{
                    flip+=((subx1+1)*d-a[i].x1)*((suby1+1)*d-a[i].y1);
                }
                if(subx1%2==suby2%2){
                    flip-=((subx1+1)*d-a[i].x1)*(a[i].y2-suby2*d+1);
                }
                else{
                    flip+=((subx1+1)*d-a[i].x1)*(a[i].y2-suby2*d+1);
                }
                if(subx2%2==suby1%2){
                    flip-=(a[i].x2-subx2*d+1)*((suby1+1)*d-a[i].y1);
                }
                else{
                    flip+=(a[i].x2-subx2*d+1)*((suby1+1)*d-a[i].y1);
                }
                if(subx2%2==suby2%2){
                    flip-=(a[i].x2-subx2*d+1)*(a[i].y2-suby2*d+1);
                }
                else{
                    flip+=(a[i].x2-subx2*d+1)*(a[i].y2-suby2*d+1);
                }
                //ivice
                int difx=subx2-subx1-1;
                int dify=suby2-suby1-1;
                if(difx%2==1){//ako ivice po x-u doprinose nesto
                    if(subx1%2!=suby1%2){
                        flip-=((suby1+1)*d-a[i].y1)*d;
                    }
                    else{
                        flip+=((suby1+1)*d-a[i].y1)*d;
                    }
                    if(subx1%2!=suby2%2){
                        flip-=(a[i].y2-suby2*d+1)*d;
                    }
                    else{
                        flip+=(a[i].y2-suby2*d+1)*d;
                    }
                }
                if(dify%2==1){//ako ivice po y-u doprinose nesto
                    if(suby1%2!=subx1%2){
                        flip-=((subx1+1)*d-a[i].x1)*d;
                    }
                    else{
                        flip+=((subx1+1)*d-a[i].x1)*d;
                    }
                    if(suby1%2!=subx2%2){
                        flip-=(a[i].x2-subx2*d+1)*d;
                    }
                    else{
                        flip+=(a[i].x2-subx2*d+1)*d;
                    }
                }
                if(difx%2==0 && dify%2==0){//ako deo u sredini doprinosi nesto
                    if(subx1%2==suby1%2){
                        flip-=d*d;
                    }
                    else flip+=d*d;
                }
            }
        }
        ans=min({ans, flip, n*n-flip});
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 2412 KB Output is correct
2 Correct 6 ms 860 KB Output is correct
3 Correct 11 ms 1628 KB Output is correct
4 Correct 13 ms 1884 KB Output is correct
5 Correct 16 ms 2140 KB Output is correct
6 Correct 10 ms 1372 KB Output is correct
7 Correct 3 ms 688 KB Output is correct
8 Correct 10 ms 1368 KB Output is correct
9 Correct 25 ms 3164 KB Output is correct
10 Correct 14 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 8 ms 1312 KB Output is correct
17 Correct 27 ms 2916 KB Output is correct
18 Correct 29 ms 3548 KB Output is correct
19 Correct 68 ms 3168 KB Output is correct
20 Correct 73 ms 3516 KB Output is correct
21 Correct 18 ms 2984 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 14 ms 1776 KB Output is correct
24 Correct 26 ms 3176 KB Output is correct
25 Correct 3 ms 608 KB Output is correct
26 Correct 15 ms 2152 KB Output is correct
27 Correct 24 ms 2584 KB Output is correct
28 Correct 25 ms 3432 KB Output is correct
29 Correct 8 ms 1368 KB Output is correct
30 Correct 2 ms 360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 2412 KB Output is correct
2 Correct 6 ms 860 KB Output is correct
3 Correct 11 ms 1628 KB Output is correct
4 Correct 13 ms 1884 KB Output is correct
5 Correct 16 ms 2140 KB Output is correct
6 Correct 10 ms 1372 KB Output is correct
7 Correct 3 ms 688 KB Output is correct
8 Correct 10 ms 1368 KB Output is correct
9 Correct 25 ms 3164 KB Output is correct
10 Correct 14 ms 2024 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 8 ms 1312 KB Output is correct
27 Correct 27 ms 2916 KB Output is correct
28 Correct 29 ms 3548 KB Output is correct
29 Correct 68 ms 3168 KB Output is correct
30 Correct 73 ms 3516 KB Output is correct
31 Correct 18 ms 2984 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 14 ms 1776 KB Output is correct
34 Correct 26 ms 3176 KB Output is correct
35 Correct 3 ms 608 KB Output is correct
36 Correct 15 ms 2152 KB Output is correct
37 Correct 24 ms 2584 KB Output is correct
38 Correct 25 ms 3432 KB Output is correct
39 Correct 8 ms 1368 KB Output is correct
40 Correct 2 ms 360 KB Output is correct
41 Correct 61 ms 2908 KB Output is correct
42 Correct 29 ms 3164 KB Output is correct
43 Correct 41 ms 2904 KB Output is correct
44 Correct 28 ms 3164 KB Output is correct
45 Correct 27 ms 3420 KB Output is correct
46 Correct 68 ms 3164 KB Output is correct
47 Correct 32 ms 2908 KB Output is correct
48 Correct 35 ms 3160 KB Output is correct
49 Correct 27 ms 3048 KB Output is correct
50 Correct 264 ms 3268 KB Output is correct
51 Correct 281 ms 3672 KB Output is correct
52 Correct 262 ms 3160 KB Output is correct
53 Correct 287 ms 3420 KB Output is correct
54 Correct 269 ms 3412 KB Output is correct
55 Correct 293 ms 3552 KB Output is correct
56 Correct 263 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 17 ms 2412 KB Output is correct
10 Correct 6 ms 860 KB Output is correct
11 Correct 11 ms 1628 KB Output is correct
12 Correct 13 ms 1884 KB Output is correct
13 Correct 16 ms 2140 KB Output is correct
14 Correct 10 ms 1372 KB Output is correct
15 Correct 3 ms 688 KB Output is correct
16 Correct 10 ms 1368 KB Output is correct
17 Correct 25 ms 3164 KB Output is correct
18 Correct 14 ms 2024 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 352 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 8 ms 1312 KB Output is correct
35 Correct 27 ms 2916 KB Output is correct
36 Correct 29 ms 3548 KB Output is correct
37 Correct 68 ms 3168 KB Output is correct
38 Correct 73 ms 3516 KB Output is correct
39 Correct 18 ms 2984 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 14 ms 1776 KB Output is correct
42 Correct 26 ms 3176 KB Output is correct
43 Correct 3 ms 608 KB Output is correct
44 Correct 15 ms 2152 KB Output is correct
45 Correct 24 ms 2584 KB Output is correct
46 Correct 25 ms 3432 KB Output is correct
47 Correct 8 ms 1368 KB Output is correct
48 Correct 2 ms 360 KB Output is correct
49 Correct 61 ms 2908 KB Output is correct
50 Correct 29 ms 3164 KB Output is correct
51 Correct 41 ms 2904 KB Output is correct
52 Correct 28 ms 3164 KB Output is correct
53 Correct 27 ms 3420 KB Output is correct
54 Correct 68 ms 3164 KB Output is correct
55 Correct 32 ms 2908 KB Output is correct
56 Correct 35 ms 3160 KB Output is correct
57 Correct 27 ms 3048 KB Output is correct
58 Correct 264 ms 3268 KB Output is correct
59 Correct 281 ms 3672 KB Output is correct
60 Correct 262 ms 3160 KB Output is correct
61 Correct 287 ms 3420 KB Output is correct
62 Correct 269 ms 3412 KB Output is correct
63 Correct 293 ms 3552 KB Output is correct
64 Correct 263 ms 3156 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Incorrect 294 ms 3164 KB Output isn't correct
68 Halted 0 ms 0 KB -