답안 #173978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173978 2020-01-06T04:06:17 Z juggernaut Chessboard (IZhO18_chessboard) C++14
47 / 100
2000 ms 5752 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>p1[100001],p2[100001];
inline int get_x(int k,int x,int white){
    int res;
    if(white)res=((x/k+1)/2)*k;
    else res=((x/k)/2)*k;
    if(((x+k-1)/k)%2==white)res+=(x%k);
    return res;
}
inline int get_xy(int k,int y,int x){
    if(x==0||y==0)return 0;
    int res=(((x/k)*(y/k)+1)/2)*k*k,a,b;
    a=(x+k-1)/k;b=(y+k-1)/k;
    res+=(x%k)*get_x(k,y,a%2);
    res+=(y%k)*get_x(k,x,b%2);
    if(!((a+b)&1))res-=(x%k)*(y%k);
    return res;
}
inline int get_range(int k,int x,int y,int x2,int y2){
    return get_xy(k,x2,y2)+get_xy(k,x-1,y-1)-get_xy(k,x-1,y2)-get_xy(k,x2,y-1);
}
inline int get(int f){
    int cnt=0,c[2],wh,bl;
    c[0]=f*f*(((n/f)*(n/f))/2);
    c[1]=f*f*(((n/f)*(n/f)+1)/2);
    for(int i=0;i<k;i++){
        //c[(p[i].fr/f+p[i].sc/f)%2]++;
        wh=get_range(f,p1[i].first,p1[i].second,p2[i].first,p2[i].second);
        bl=(abs(p1[i].second-p2[i].second)+1)*(abs(p1[i].first-p2[i].first)+1)-wh;
        c[0]-=bl;
        c[0]+=wh;
        swap(bl,wh);
        c[1]-=bl;
        c[1]+=wh;
    }
    return min(c[0],c[1]);
}
main(){
    scanf("%lld%lld",&n,&k);
    for(i=0;i<k;i++){
        scanf("%lld%lld%lld%lld",&p1[i].fr,&p1[i].sc,&p2[i].fr,&p2[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);
}
/*
int get_x(int k,int x,int white){
    int res;
    if(white)res=((x/k+1)/2)*k;
    else res=((x/k)/2)*k;
    if(((x+k-1)/k)%2==white)res+=(x%k);
    return res;
}
int get_xy(int k,int y,int x){
    int res=(((x/k)*(y/k)+1)/2)*k*k,a,b;
    a=(x+k-1)/k;b=(y+k-1)/k;
    res+=(x%k)*get_x(k,y,a%2);
    res+=(y%k)*get_x(k,x,b%2);
    if(!((a+b)&1))res-=(x%k)*(y%k);
    return res;
}
*/

Compilation message

chessboard.cpp: In function 'long long int get(long long int)':
chessboard.cpp:29:9: warning: unused variable 'cnt' [-Wunused-variable]
     int cnt=0,c[2],wh,bl;
         ^~~
chessboard.cpp: At global scope:
chessboard.cpp:44:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:45: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:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld%lld",&p1[i].fr,&p1[i].sc,&p2[i].fr,&p2[i].sc);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 256 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 2296 KB Output is correct
2 Correct 13 ms 888 KB Output is correct
3 Correct 30 ms 1656 KB Output is correct
4 Correct 33 ms 1784 KB Output is correct
5 Correct 41 ms 2040 KB Output is correct
6 Correct 28 ms 1400 KB Output is correct
7 Correct 7 ms 632 KB Output is correct
8 Correct 27 ms 1400 KB Output is correct
9 Correct 69 ms 3192 KB Output is correct
10 Correct 39 ms 1912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 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 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 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 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 33 ms 1624 KB Output is correct
17 Correct 60 ms 4336 KB Output is correct
18 Correct 114 ms 5056 KB Output is correct
19 Correct 603 ms 4552 KB Output is correct
20 Correct 674 ms 5152 KB Output is correct
21 Correct 54 ms 4216 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 90 ms 2376 KB Output is correct
24 Correct 102 ms 4600 KB Output is correct
25 Correct 19 ms 760 KB Output is correct
26 Correct 65 ms 3064 KB Output is correct
27 Correct 110 ms 3596 KB Output is correct
28 Correct 109 ms 4856 KB Output is correct
29 Correct 24 ms 2040 KB Output is correct
30 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 2296 KB Output is correct
2 Correct 13 ms 888 KB Output is correct
3 Correct 30 ms 1656 KB Output is correct
4 Correct 33 ms 1784 KB Output is correct
5 Correct 41 ms 2040 KB Output is correct
6 Correct 28 ms 1400 KB Output is correct
7 Correct 7 ms 632 KB Output is correct
8 Correct 27 ms 1400 KB Output is correct
9 Correct 69 ms 3192 KB Output is correct
10 Correct 39 ms 1912 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 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 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 4 ms 376 KB Output is correct
24 Correct 4 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 33 ms 1624 KB Output is correct
27 Correct 60 ms 4336 KB Output is correct
28 Correct 114 ms 5056 KB Output is correct
29 Correct 603 ms 4552 KB Output is correct
30 Correct 674 ms 5152 KB Output is correct
31 Correct 54 ms 4216 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 90 ms 2376 KB Output is correct
34 Correct 102 ms 4600 KB Output is correct
35 Correct 19 ms 760 KB Output is correct
36 Correct 65 ms 3064 KB Output is correct
37 Correct 110 ms 3596 KB Output is correct
38 Correct 109 ms 4856 KB Output is correct
39 Correct 24 ms 2040 KB Output is correct
40 Correct 5 ms 504 KB Output is correct
41 Correct 489 ms 4984 KB Output is correct
42 Correct 114 ms 5368 KB Output is correct
43 Correct 257 ms 4984 KB Output is correct
44 Correct 114 ms 5368 KB Output is correct
45 Correct 73 ms 5752 KB Output is correct
46 Correct 548 ms 5496 KB Output is correct
47 Correct 64 ms 4984 KB Output is correct
48 Correct 187 ms 5168 KB Output is correct
49 Correct 102 ms 4984 KB Output is correct
50 Execution timed out 2039 ms 5280 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 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 256 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 46 ms 2296 KB Output is correct
10 Correct 13 ms 888 KB Output is correct
11 Correct 30 ms 1656 KB Output is correct
12 Correct 33 ms 1784 KB Output is correct
13 Correct 41 ms 2040 KB Output is correct
14 Correct 28 ms 1400 KB Output is correct
15 Correct 7 ms 632 KB Output is correct
16 Correct 27 ms 1400 KB Output is correct
17 Correct 69 ms 3192 KB Output is correct
18 Correct 39 ms 1912 KB Output is correct
19 Correct 3 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 4 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 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 3 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 4 ms 376 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 33 ms 1624 KB Output is correct
35 Correct 60 ms 4336 KB Output is correct
36 Correct 114 ms 5056 KB Output is correct
37 Correct 603 ms 4552 KB Output is correct
38 Correct 674 ms 5152 KB Output is correct
39 Correct 54 ms 4216 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 90 ms 2376 KB Output is correct
42 Correct 102 ms 4600 KB Output is correct
43 Correct 19 ms 760 KB Output is correct
44 Correct 65 ms 3064 KB Output is correct
45 Correct 110 ms 3596 KB Output is correct
46 Correct 109 ms 4856 KB Output is correct
47 Correct 24 ms 2040 KB Output is correct
48 Correct 5 ms 504 KB Output is correct
49 Correct 489 ms 4984 KB Output is correct
50 Correct 114 ms 5368 KB Output is correct
51 Correct 257 ms 4984 KB Output is correct
52 Correct 114 ms 5368 KB Output is correct
53 Correct 73 ms 5752 KB Output is correct
54 Correct 548 ms 5496 KB Output is correct
55 Correct 64 ms 4984 KB Output is correct
56 Correct 187 ms 5168 KB Output is correct
57 Correct 102 ms 4984 KB Output is correct
58 Execution timed out 2039 ms 5280 KB Time limit exceeded
59 Halted 0 ms 0 KB -