답안 #168541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168541 2019-12-13T15:11:05 Z juggernaut Chessboard (IZhO18_chessboard) C++14
70 / 100
815 ms 5880 KB
//Just try and the idea will come!
#include<bits/stdc++.h>
#define int long long int
#define fr first
#define sc second
using namespace std;
int n,k,i,j,x,y,res;
pair<int,int>p[100001],s[100001];
int get(int x1,int y1,int x2,int y2){
    if(x1>x2||y1>y2)return 0;
    int res=(x2-x1+1)*((y2-y1+1)/2);
    if((y2-y1+1)&1){
        res+=(x2-x1+1)/2;
        if((x1+y1)%2==0&&(x2-x1+1)%2==1)res++;
    }
    return res;
}
int get_x(int x1,int y1,int x2,int y2,int f){
    if(x1>x2||y1>y2)return 0;
    int res,x,xx;
    x=(x1+f-1)/f;
    xx=(x2-f+1)/f;
    res=get(x,y1/f,xx,y1/f)*(y2-y1+1);
    if((x1+y1)%2==0)res+=max(0ll,(x*f-1-x1+1))*(y2-y1+1);
    if((x2+y2)%2==0)res+=max(0ll,(x2-xx*f))*(y2-y1+1);
    return res;
}
int get_y(int x1,int y1,int x2,int y2,int f){
    if(x1>x2||y1>y2)return 0;
    int res,x,yy;
    y=(y1+f-1)/f;
    yy=(y2-f+1)/f;
    res=get(x/f,y,x/f,yy)*(x2-x1+1);
    if((x1+y1)%2==0)res+=max(0ll,(y*f-1-y1+1))*(x2-x1+1);
    if((x2+y2)%2==0)res+=max(0ll,(y2-yy*f))*(x2-x1+1);
    return res;
}
int count_white(int x1,int y1,int x2,int y2,int f){
    int x,y,xx,yy,res;
    x=(x1+f-1)/f;
    y=(y1+f-1)/f;
    xx=(x2-f+1)/f;
    yy=(y2-f+1)/f;
    res=f*f*get(x,y,xx,yy);
    res+=get_x(x1,y1,x2,y-1,f)+get_x(x1,yy+1,x2,y2,f);
    res+=get_y(x1,y,x-1,yy,f)+get_y(xx+1,y,x2,yy,f);
    return res;
}
int get(int f){
    int cnt=0,c[2],x;
    c[0]=c[1]=0;
    for(int i=0;i<k;i++){
        x=get(s[i].fr/f,s[i].sc/f,p[i].fr/f,p[i].sc/f);
        c[0]+=x;
        c[1]+=(p[i].fr-s[i].fr+1)*(p[i].sc-s[i].sc+1)-x;
    }
    int m=n/f;
    int res=f*f*((m/2)*m+((m%2)*(m/2)))-c[1]+c[0];
    res=min(res,f*f*((m/2)*m+((m%2)*((m+1)/2)))-c[0]+c[1]);
    return res;
}
main(){
    scanf("%lld%lld",&n,&k);
    for(i=0;i<k;i++){
        scanf("%lld%lld%lld%lld",&s[i].fr,&s[i].sc,&p[i].fr,&p[i].sc);
        p[i].fr--;
        p[i].sc--;
        s[i].fr--;
        s[i].sc--;
    }
    res=get(1);
    for(j=2;j*j<=n;j++){
        if(n%j==0){
            res=min(res,get(j));
            res=min(res,get(n/j));
        }
    }
    printf("%lld",res);
}

Compilation message

chessboard.cpp: In function 'long long int get(long long int)':
chessboard.cpp:50:9: warning: unused variable 'cnt' [-Wunused-variable]
     int cnt=0,c[2],x;
         ^~~
chessboard.cpp: At global scope:
chessboard.cpp:62:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~
chessboard.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld%lld",&s[i].fr,&s[i].sc,&p[i].fr,&p[i].sc);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chessboard.cpp: In function 'long long int get_y(long long int, long long int, long long int, long long int, long long int)':
chessboard.cpp:33:12: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
     res=get(x/f,y,x/f,yy)*(x2-x1+1);
         ~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 3192 KB Output is correct
2 Correct 11 ms 1144 KB Output is correct
3 Correct 24 ms 2552 KB Output is correct
4 Correct 25 ms 2652 KB Output is correct
5 Correct 31 ms 3320 KB Output is correct
6 Correct 21 ms 2296 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 21 ms 2296 KB Output is correct
9 Correct 51 ms 5212 KB Output is correct
10 Correct 29 ms 3064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 380 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 380 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 18 ms 1656 KB Output is correct
17 Correct 42 ms 4268 KB Output is correct
18 Correct 62 ms 4760 KB Output is correct
19 Correct 184 ms 4472 KB Output is correct
20 Correct 204 ms 5112 KB Output is correct
21 Correct 41 ms 4208 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 37 ms 2296 KB Output is correct
24 Correct 55 ms 4600 KB Output is correct
25 Correct 9 ms 760 KB Output is correct
26 Correct 36 ms 3064 KB Output is correct
27 Correct 50 ms 3500 KB Output is correct
28 Correct 58 ms 4856 KB Output is correct
29 Correct 18 ms 1912 KB Output is correct
30 Correct 4 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 3192 KB Output is correct
2 Correct 11 ms 1144 KB Output is correct
3 Correct 24 ms 2552 KB Output is correct
4 Correct 25 ms 2652 KB Output is correct
5 Correct 31 ms 3320 KB Output is correct
6 Correct 21 ms 2296 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 21 ms 2296 KB Output is correct
9 Correct 51 ms 5212 KB Output is correct
10 Correct 29 ms 3064 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 380 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 18 ms 1656 KB Output is correct
27 Correct 42 ms 4268 KB Output is correct
28 Correct 62 ms 4760 KB Output is correct
29 Correct 184 ms 4472 KB Output is correct
30 Correct 204 ms 5112 KB Output is correct
31 Correct 41 ms 4208 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 37 ms 2296 KB Output is correct
34 Correct 55 ms 4600 KB Output is correct
35 Correct 9 ms 760 KB Output is correct
36 Correct 36 ms 3064 KB Output is correct
37 Correct 50 ms 3500 KB Output is correct
38 Correct 58 ms 4856 KB Output is correct
39 Correct 18 ms 1912 KB Output is correct
40 Correct 4 ms 476 KB Output is correct
41 Correct 157 ms 4828 KB Output is correct
42 Correct 65 ms 5624 KB Output is correct
43 Correct 98 ms 4984 KB Output is correct
44 Correct 63 ms 5368 KB Output is correct
45 Correct 56 ms 5752 KB Output is correct
46 Correct 177 ms 5104 KB Output is correct
47 Correct 49 ms 4984 KB Output is correct
48 Correct 81 ms 5112 KB Output is correct
49 Correct 59 ms 4988 KB Output is correct
50 Correct 741 ms 5112 KB Output is correct
51 Correct 790 ms 5744 KB Output is correct
52 Correct 736 ms 5372 KB Output is correct
53 Correct 786 ms 5724 KB Output is correct
54 Correct 726 ms 5240 KB Output is correct
55 Correct 815 ms 5880 KB Output is correct
56 Correct 704 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 36 ms 3192 KB Output is correct
10 Correct 11 ms 1144 KB Output is correct
11 Correct 24 ms 2552 KB Output is correct
12 Correct 25 ms 2652 KB Output is correct
13 Correct 31 ms 3320 KB Output is correct
14 Correct 21 ms 2296 KB Output is correct
15 Correct 6 ms 760 KB Output is correct
16 Correct 21 ms 2296 KB Output is correct
17 Correct 51 ms 5212 KB Output is correct
18 Correct 29 ms 3064 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 380 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 18 ms 1656 KB Output is correct
35 Correct 42 ms 4268 KB Output is correct
36 Correct 62 ms 4760 KB Output is correct
37 Correct 184 ms 4472 KB Output is correct
38 Correct 204 ms 5112 KB Output is correct
39 Correct 41 ms 4208 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 37 ms 2296 KB Output is correct
42 Correct 55 ms 4600 KB Output is correct
43 Correct 9 ms 760 KB Output is correct
44 Correct 36 ms 3064 KB Output is correct
45 Correct 50 ms 3500 KB Output is correct
46 Correct 58 ms 4856 KB Output is correct
47 Correct 18 ms 1912 KB Output is correct
48 Correct 4 ms 476 KB Output is correct
49 Correct 157 ms 4828 KB Output is correct
50 Correct 65 ms 5624 KB Output is correct
51 Correct 98 ms 4984 KB Output is correct
52 Correct 63 ms 5368 KB Output is correct
53 Correct 56 ms 5752 KB Output is correct
54 Correct 177 ms 5104 KB Output is correct
55 Correct 49 ms 4984 KB Output is correct
56 Correct 81 ms 5112 KB Output is correct
57 Correct 59 ms 4988 KB Output is correct
58 Correct 741 ms 5112 KB Output is correct
59 Correct 790 ms 5744 KB Output is correct
60 Correct 736 ms 5372 KB Output is correct
61 Correct 786 ms 5724 KB Output is correct
62 Correct 726 ms 5240 KB Output is correct
63 Correct 815 ms 5880 KB Output is correct
64 Correct 704 ms 5240 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Incorrect 2 ms 376 KB Output isn't correct
67 Halted 0 ms 0 KB -