Submission #93415

# Submission time Handle Problem Language Result Execution time Memory
93415 2019-01-08T10:47:49 Z mirbek01 Chessboard (IZhO18_chessboard) C++11
100 / 100
1704 ms 4320 KB
# include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 2;

int n, k, a[N], b[N], c[N], d[N];
long long ans = 1e18;

long long white(int n, int m, int x){
      int a = n / x, b = m / x;
      long long ret = ((a + 1) / 2) * 1ll * ((b + 1) / 2) * 1ll * x * x;
      ret += (a / 2) * 1ll * (b / 2) * 1ll * x * x;
      if(b % 2 == 0){
            ret += ((a + 1) / 2) * 1ll * x * (m - b * x);
      } else {
            ret += (a / 2) * 1ll * x * (m - b * x);
      }
      if(a % 2 == 0){
            ret += ((b + 1) / 2) * 1ll * x * (n - a * x);
      } else {
            ret += (b / 2) * 1ll * x * (n - a * x);
      }
      if((a + b) % 2 == 0)
            ret += (n - a * x) * 1ll * (m - b * x);
      return ret;
}

long long get(int x){
      long long ret, cc = n / x;
      ret = ((cc * cc) / 2) * x * 1ll * x;
      for(int i = 1; i <= k; i ++){
            long long wh = white(c[i], d[i], x) - white(a[i] - 1, d[i], x) - white(c[i], b[i] - 1, x) + white(a[i] - 1, b[i] - 1, x);
            ret -= (c[i] - a[i] + 1) * 1ll * (d[i] - b[i] + 1) - wh;
      }
      for(int i = 1; i <= k; i ++){
            long long wh = white(c[i], d[i], x) - white(a[i] - 1, d[i], x) - white(c[i], b[i] - 1, x) + white(a[i] - 1, b[i] - 1, x);
            ret += wh;
      }
      return min(ret, n * 1ll * n - ret);
}

int main(){
      scanf("%d %d", &n, &k);

      for(int i = 1; i <= k; i ++){
            scanf("%d %d %d %d", a + i, b + i, c + i, d + i);
      }

      for(int i = 1; i * i <= n; i ++){
            if(n % i == 0){
                  ans = min(ans, get(i));
                  if(i != 1) ans = min(ans, get(n / i));
            }
      }

      cout << ans << endl;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:44:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d", &n, &k);
       ~~~~~^~~~~~~~~~~~~~~~~
chessboard.cpp:47:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d %d %d", a + i, b + i, c + i, d + i);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 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 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1224 KB Output is correct
2 Correct 10 ms 732 KB Output is correct
3 Correct 22 ms 888 KB Output is correct
4 Correct 24 ms 1056 KB Output is correct
5 Correct 30 ms 1148 KB Output is correct
6 Correct 19 ms 888 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 20 ms 860 KB Output is correct
9 Correct 49 ms 1808 KB Output is correct
10 Correct 28 ms 1144 KB Output is correct
# Verdict Execution time Memory 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 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 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 380 KB Output is correct
15 Correct 3 ms 296 KB Output is correct
# Verdict Execution time Memory 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 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 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 380 KB Output is correct
15 Correct 3 ms 296 KB Output is correct
16 Correct 22 ms 1148 KB Output is correct
17 Correct 41 ms 2936 KB Output is correct
18 Correct 74 ms 3360 KB Output is correct
19 Correct 343 ms 3064 KB Output is correct
20 Correct 385 ms 3420 KB Output is correct
21 Correct 39 ms 2808 KB Output is correct
22 Correct 12 ms 376 KB Output is correct
23 Correct 54 ms 1528 KB Output is correct
24 Correct 66 ms 3012 KB Output is correct
25 Correct 13 ms 504 KB Output is correct
26 Correct 43 ms 2040 KB Output is correct
27 Correct 69 ms 2424 KB Output is correct
28 Correct 70 ms 3320 KB Output is correct
29 Correct 17 ms 1248 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1224 KB Output is correct
2 Correct 10 ms 732 KB Output is correct
3 Correct 22 ms 888 KB Output is correct
4 Correct 24 ms 1056 KB Output is correct
5 Correct 30 ms 1148 KB Output is correct
6 Correct 19 ms 888 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 20 ms 860 KB Output is correct
9 Correct 49 ms 1808 KB Output is correct
10 Correct 28 ms 1144 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 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 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 380 KB Output is correct
25 Correct 3 ms 296 KB Output is correct
26 Correct 22 ms 1148 KB Output is correct
27 Correct 41 ms 2936 KB Output is correct
28 Correct 74 ms 3360 KB Output is correct
29 Correct 343 ms 3064 KB Output is correct
30 Correct 385 ms 3420 KB Output is correct
31 Correct 39 ms 2808 KB Output is correct
32 Correct 12 ms 376 KB Output is correct
33 Correct 54 ms 1528 KB Output is correct
34 Correct 66 ms 3012 KB Output is correct
35 Correct 13 ms 504 KB Output is correct
36 Correct 43 ms 2040 KB Output is correct
37 Correct 69 ms 2424 KB Output is correct
38 Correct 70 ms 3320 KB Output is correct
39 Correct 17 ms 1248 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 283 ms 3560 KB Output is correct
42 Correct 77 ms 4044 KB Output is correct
43 Correct 153 ms 3648 KB Output is correct
44 Correct 74 ms 3956 KB Output is correct
45 Correct 53 ms 4216 KB Output is correct
46 Correct 321 ms 3960 KB Output is correct
47 Correct 92 ms 3704 KB Output is correct
48 Correct 117 ms 3828 KB Output is correct
49 Correct 67 ms 3576 KB Output is correct
50 Correct 1532 ms 3960 KB Output is correct
51 Correct 1636 ms 4164 KB Output is correct
52 Correct 1513 ms 3804 KB Output is correct
53 Correct 1601 ms 4140 KB Output is correct
54 Correct 1489 ms 3848 KB Output is correct
55 Correct 1687 ms 4216 KB Output is correct
56 Correct 1452 ms 3752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 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 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 34 ms 1224 KB Output is correct
10 Correct 10 ms 732 KB Output is correct
11 Correct 22 ms 888 KB Output is correct
12 Correct 24 ms 1056 KB Output is correct
13 Correct 30 ms 1148 KB Output is correct
14 Correct 19 ms 888 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 20 ms 860 KB Output is correct
17 Correct 49 ms 1808 KB Output is correct
18 Correct 28 ms 1144 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
21 Correct 2 ms 376 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 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 380 KB Output is correct
33 Correct 3 ms 296 KB Output is correct
34 Correct 22 ms 1148 KB Output is correct
35 Correct 41 ms 2936 KB Output is correct
36 Correct 74 ms 3360 KB Output is correct
37 Correct 343 ms 3064 KB Output is correct
38 Correct 385 ms 3420 KB Output is correct
39 Correct 39 ms 2808 KB Output is correct
40 Correct 12 ms 376 KB Output is correct
41 Correct 54 ms 1528 KB Output is correct
42 Correct 66 ms 3012 KB Output is correct
43 Correct 13 ms 504 KB Output is correct
44 Correct 43 ms 2040 KB Output is correct
45 Correct 69 ms 2424 KB Output is correct
46 Correct 70 ms 3320 KB Output is correct
47 Correct 17 ms 1248 KB Output is correct
48 Correct 4 ms 376 KB Output is correct
49 Correct 283 ms 3560 KB Output is correct
50 Correct 77 ms 4044 KB Output is correct
51 Correct 153 ms 3648 KB Output is correct
52 Correct 74 ms 3956 KB Output is correct
53 Correct 53 ms 4216 KB Output is correct
54 Correct 321 ms 3960 KB Output is correct
55 Correct 92 ms 3704 KB Output is correct
56 Correct 117 ms 3828 KB Output is correct
57 Correct 67 ms 3576 KB Output is correct
58 Correct 1532 ms 3960 KB Output is correct
59 Correct 1636 ms 4164 KB Output is correct
60 Correct 1513 ms 3804 KB Output is correct
61 Correct 1601 ms 4140 KB Output is correct
62 Correct 1489 ms 3848 KB Output is correct
63 Correct 1687 ms 4216 KB Output is correct
64 Correct 1452 ms 3752 KB Output is correct
65 Correct 2 ms 376 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 1601 ms 4028 KB Output is correct
68 Correct 1589 ms 4220 KB Output is correct
69 Correct 1378 ms 3704 KB Output is correct
70 Correct 1548 ms 3988 KB Output is correct
71 Correct 1532 ms 3832 KB Output is correct
72 Correct 1472 ms 3820 KB Output is correct
73 Correct 1448 ms 3832 KB Output is correct
74 Correct 1601 ms 3996 KB Output is correct
75 Correct 1493 ms 3852 KB Output is correct
76 Correct 1603 ms 4124 KB Output is correct
77 Correct 234 ms 4216 KB Output is correct
78 Correct 101 ms 3904 KB Output is correct
79 Correct 160 ms 3804 KB Output is correct
80 Correct 169 ms 4080 KB Output is correct
81 Correct 153 ms 3600 KB Output is correct
82 Correct 128 ms 3960 KB Output is correct
83 Correct 94 ms 3832 KB Output is correct
84 Correct 947 ms 4216 KB Output is correct
85 Correct 1704 ms 4216 KB Output is correct
86 Correct 3 ms 376 KB Output is correct
87 Correct 2 ms 376 KB Output is correct
88 Correct 1699 ms 4320 KB Output is correct
89 Correct 318 ms 1144 KB Output is correct
90 Correct 2 ms 376 KB Output is correct