답안 #173244

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173244 2020-01-03T16:13:31 Z LinusTorvaldsFan Chessboard (IZhO18_chessboard) C++14
100 / 100
1268 ms 4312 KB
#include <iostream>
#include <algorithm>
#include <vector>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
using namespace std;
 
typedef long long ll;
 
struct Rect{
  int x1,y1,x2,y2;
  Rect(int x1,int y1,int x2, int y2):x1(x1),y1(y1),x2(x2),y2(y2){}
  Rect(){}
};
 
const int maxk=100002;
Rect rects[maxk];
int n,k;
 
int up(int x, int y){
    return (x/y)+(x%y!=0);
}
 
vector<ll> get(int x1,int x2, int l){
  vector<ll> ans={0,0};  
  int nx1=up(x1,l)*l;
  
  if(nx1>x2){
    ans[(x1/l)&1]+=x2-x1+1;
    return ans;
  }
  
  ans[(x1/l)&1]+=nx1-x1;
  x1=nx1;
  
  int nx2=x2/l*l;
  
  ans[(x2/l)&1]+=x2-nx2;
  
  x2=nx2;
  
  if(x1>x2)return ans;
  ans[(x2/l)&1]++;
  x2--;
  if(x1>x2)return ans;
  int blocks=(x2-x1+1)/l;
  ans[(x1/l)&1]+=((blocks>>1)+(blocks&1))*l;
  ans[((x1/l)+1)&1]+=(blocks>>1)*l;
  return ans;
}
 
ll solve(ll l){
  ll black_colored_1=0;
  ll need_black_1=0;
  ll total_1=0;
  
  ll black_colored_2=0;
  ll need_black_2=0;
  ll total_2=0;
  auto t1=get(0,n-1,l);
  need_black_1+=t1[0]*t1[0]+t1[1]*t1[1];
  need_black_2+=t1[0]*t1[1]+t1[1]*t1[0];    
  
  for(int i=0;i<k;i++){
    auto t1=get(rects[i].x1-1,rects[i].x2-1,l);
    auto t2=get(rects[i].y1-1,rects[i].y2-1,l);
    black_colored_1+=t1[0]*t2[0]+t1[1]*t2[1];
    total_1+=t1[0]*t2[1]+t1[1]*t2[0];
    total_2+=t1[0]*t2[0]+t1[1]*t2[1];
    black_colored_2+=t1[0]*t2[1]+t1[1]*t2[0];
  }
  total_1+=need_black_1-black_colored_1;
  total_2+=need_black_2-black_colored_2;
  return min(total_1,total_2);
}
 
signed main(){
  //ios_base::sync_with_stdio(0); cin.tie(0);
  cin>>n;
  cin>>k;
  
  for(int i=0;i<k;i++){
    //cin>>rects[i].x1>>rects[i].y1>>rects[i].x2>>rects[i].y2;
    scanf("%d%d%d%d",&rects[i].x1,&rects[i].y1,&rects[i].x2,&rects[i].y2);
  }
  
  ll ans=1e18;
 
  for(int i=1;i*i<=n;i++){
    if(n%i==0){
      int l=i;
      if(l==n)continue;
      ans=min(ans,solve(l));
    }
    if(n%i==0){
      int l=n/i;
      if(l==n)continue;
      ans=min(ans,solve(l));
    }
  }
  cout<<ans;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:86:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d",&rects[i].x1,&rects[i].y1,&rects[i].x2,&rects[i].y2);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 2808 KB Output is correct
2 Correct 11 ms 1016 KB Output is correct
3 Correct 25 ms 1912 KB Output is correct
4 Correct 27 ms 1912 KB Output is correct
5 Correct 33 ms 2424 KB Output is correct
6 Correct 22 ms 1656 KB Output is correct
7 Correct 8 ms 632 KB Output is correct
8 Correct 23 ms 1620 KB Output is correct
9 Correct 54 ms 3756 KB Output is correct
10 Correct 31 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 380 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 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 292 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 380 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 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 292 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
16 Correct 21 ms 1144 KB Output is correct
17 Correct 44 ms 3068 KB Output is correct
18 Correct 69 ms 3508 KB Output is correct
19 Correct 251 ms 3172 KB Output is correct
20 Correct 277 ms 3512 KB Output is correct
21 Correct 43 ms 2936 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 47 ms 1708 KB Output is correct
24 Correct 63 ms 3192 KB Output is correct
25 Correct 11 ms 632 KB Output is correct
26 Correct 40 ms 2168 KB Output is correct
27 Correct 62 ms 2524 KB Output is correct
28 Correct 68 ms 3320 KB Output is correct
29 Correct 19 ms 1528 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 2808 KB Output is correct
2 Correct 11 ms 1016 KB Output is correct
3 Correct 25 ms 1912 KB Output is correct
4 Correct 27 ms 1912 KB Output is correct
5 Correct 33 ms 2424 KB Output is correct
6 Correct 22 ms 1656 KB Output is correct
7 Correct 8 ms 632 KB Output is correct
8 Correct 23 ms 1620 KB Output is correct
9 Correct 54 ms 3756 KB Output is correct
10 Correct 31 ms 2296 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 380 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 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 292 KB Output is correct
25 Correct 3 ms 380 KB Output is correct
26 Correct 21 ms 1144 KB Output is correct
27 Correct 44 ms 3068 KB Output is correct
28 Correct 69 ms 3508 KB Output is correct
29 Correct 251 ms 3172 KB Output is correct
30 Correct 277 ms 3512 KB Output is correct
31 Correct 43 ms 2936 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 47 ms 1708 KB Output is correct
34 Correct 63 ms 3192 KB Output is correct
35 Correct 11 ms 632 KB Output is correct
36 Correct 40 ms 2168 KB Output is correct
37 Correct 62 ms 2524 KB Output is correct
38 Correct 68 ms 3320 KB Output is correct
39 Correct 19 ms 1528 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 211 ms 3636 KB Output is correct
42 Correct 73 ms 4088 KB Output is correct
43 Correct 123 ms 3656 KB Output is correct
44 Correct 71 ms 3960 KB Output is correct
45 Correct 59 ms 4264 KB Output is correct
46 Correct 235 ms 4036 KB Output is correct
47 Correct 51 ms 3752 KB Output is correct
48 Correct 92 ms 3804 KB Output is correct
49 Correct 65 ms 3576 KB Output is correct
50 Correct 1056 ms 3948 KB Output is correct
51 Correct 1122 ms 4188 KB Output is correct
52 Correct 1038 ms 3916 KB Output is correct
53 Correct 1121 ms 4136 KB Output is correct
54 Correct 1027 ms 3868 KB Output is correct
55 Correct 1171 ms 4300 KB Output is correct
56 Correct 999 ms 3776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 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 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 352 KB Output is correct
9 Correct 38 ms 2808 KB Output is correct
10 Correct 11 ms 1016 KB Output is correct
11 Correct 25 ms 1912 KB Output is correct
12 Correct 27 ms 1912 KB Output is correct
13 Correct 33 ms 2424 KB Output is correct
14 Correct 22 ms 1656 KB Output is correct
15 Correct 8 ms 632 KB Output is correct
16 Correct 23 ms 1620 KB Output is correct
17 Correct 54 ms 3756 KB Output is correct
18 Correct 31 ms 2296 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 380 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 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 292 KB Output is correct
33 Correct 3 ms 380 KB Output is correct
34 Correct 21 ms 1144 KB Output is correct
35 Correct 44 ms 3068 KB Output is correct
36 Correct 69 ms 3508 KB Output is correct
37 Correct 251 ms 3172 KB Output is correct
38 Correct 277 ms 3512 KB Output is correct
39 Correct 43 ms 2936 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 47 ms 1708 KB Output is correct
42 Correct 63 ms 3192 KB Output is correct
43 Correct 11 ms 632 KB Output is correct
44 Correct 40 ms 2168 KB Output is correct
45 Correct 62 ms 2524 KB Output is correct
46 Correct 68 ms 3320 KB Output is correct
47 Correct 19 ms 1528 KB Output is correct
48 Correct 4 ms 376 KB Output is correct
49 Correct 211 ms 3636 KB Output is correct
50 Correct 73 ms 4088 KB Output is correct
51 Correct 123 ms 3656 KB Output is correct
52 Correct 71 ms 3960 KB Output is correct
53 Correct 59 ms 4264 KB Output is correct
54 Correct 235 ms 4036 KB Output is correct
55 Correct 51 ms 3752 KB Output is correct
56 Correct 92 ms 3804 KB Output is correct
57 Correct 65 ms 3576 KB Output is correct
58 Correct 1056 ms 3948 KB Output is correct
59 Correct 1122 ms 4188 KB Output is correct
60 Correct 1038 ms 3916 KB Output is correct
61 Correct 1121 ms 4136 KB Output is correct
62 Correct 1027 ms 3868 KB Output is correct
63 Correct 1171 ms 4300 KB Output is correct
64 Correct 999 ms 3776 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 256 KB Output is correct
67 Correct 1175 ms 4052 KB Output is correct
68 Correct 1167 ms 4044 KB Output is correct
69 Correct 1002 ms 3584 KB Output is correct
70 Correct 1096 ms 3936 KB Output is correct
71 Correct 1098 ms 3876 KB Output is correct
72 Correct 1079 ms 3820 KB Output is correct
73 Correct 1064 ms 3808 KB Output is correct
74 Correct 1154 ms 3992 KB Output is correct
75 Correct 1090 ms 3848 KB Output is correct
76 Correct 1170 ms 4088 KB Output is correct
77 Correct 195 ms 4272 KB Output is correct
78 Correct 73 ms 3804 KB Output is correct
79 Correct 140 ms 3712 KB Output is correct
80 Correct 140 ms 3832 KB Output is correct
81 Correct 129 ms 3576 KB Output is correct
82 Correct 113 ms 4060 KB Output is correct
83 Correct 89 ms 3676 KB Output is correct
84 Correct 699 ms 4184 KB Output is correct
85 Correct 1244 ms 4212 KB Output is correct
86 Correct 3 ms 256 KB Output is correct
87 Correct 2 ms 376 KB Output is correct
88 Correct 1268 ms 4312 KB Output is correct
89 Correct 237 ms 1016 KB Output is correct
90 Correct 2 ms 376 KB Output is correct