답안 #50843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50843 2018-06-13T16:31:37 Z Nicksechko Chessboard (IZhO18_chessboard) C++14
100 / 100
830 ms 2300 KB
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>
 
#define x1 X
#define x2 XX
#define y1 Y
#define y2 YY

#define mp make_pair
#define pb push_back
 
 
typedef long long ll;
typedef long double ld;

#define f first
#define s second
 
using namespace std;

const int N = 2e5 + 123;

int n, k, x1[N], x2[N], y1[N], y2[N];

ll ans = 1e18;

int get(int x, int side) {
  if (x < 0) return 0;
  int id = x / side;
  int ans = (id + 1) / 2 * side;
  if (!(id & 1)) ans += x % side + 1;
  return ans;
}


ll calc(int side) {
  if (side == n) return 1e18;
  ll even = 0, odd = 0;
  for (int i = 0;i < k;i++) {
    // number of even elements
    ll a1 = get(y2[i], side) - get(y1[i] - 1, side);
    ll a2 = y2[i] - y1[i] + 1 - a1;
    ll b1 = get(x2[i], side) - get(x1[i] - 1, side);
    ll b2 = x2[i] - x1[i] + 1 - b1;
    int idx = x1[i] / side;
    int idy = y1[i] / side;
    // row is odd
    if (idx & 1) {
      swap(a1, a2);
    } 
    // column is odd
    if (idy & 1) {
      swap(b1, b2);      
    }
   // cout << "i = " << i << " a1 = " << a1 << " a2 = " << a2 << " b1 = " << b1 << " b2 = " << b2 << endl;
   // cout << "x1 = " << x1[i] << " x2 = " << x2[i] << " y1 = " << y1[i] << " y2 = " << y2[i] << endl;
   // cout << "Ylen = " << y2[i] - y1[i] + 1 << endl;
    // 
    ll f0 = 1ll * a1 * b1 + 1ll * a2 * b2;
    ll f1 = 1ll * a2 * b1 + 1ll * a1 * b2;
    if (!((idx + idy) & 1)) swap(f0, f1);
    odd += f1;
    even += f0;
  }
  int cnt = n / side;
  ll tot = 1ll * cnt * cnt;
  // case 1 black - even, white - odd
  ll E = (tot / 2) * 1ll * side * side - even + odd;
  // case 2 black - odd, white - even
  ll O = (tot + 1) / 2 * 1ll * side * side - odd + even;
  return min(E, O);
}

int main() {
  #ifdef wws 
    freopen("input", "r", stdin);
  #endif
  scanf("%d%d", &n, &k);
  for (int i = 0;i < k;i++) {
    scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]);
    x1[i]--;
    x2[i]--;
    y1[i]--;
    y2[i]--;
  } 
  //cout << calc(1) << endl; return 0;
  for (int i = 1;1ll * i * i <= n;i++) {
    if (n % i == 0) {
      ans = min(ans, calc(i));
      if (n / i != i) ans = min(ans, calc(n / i));
    }
  }
  cout << ans << endl;
  return 0;
}
 

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:89:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &n, &k);
   ~~~~~^~~~~~~~~~~~~~~~
chessboard.cpp:91:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 3 ms 544 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 1504 KB Output is correct
2 Correct 11 ms 1504 KB Output is correct
3 Correct 29 ms 1504 KB Output is correct
4 Correct 25 ms 1504 KB Output is correct
5 Correct 51 ms 1504 KB Output is correct
6 Correct 35 ms 1504 KB Output is correct
7 Correct 9 ms 1504 KB Output is correct
8 Correct 22 ms 1504 KB Output is correct
9 Correct 81 ms 2156 KB Output is correct
10 Correct 35 ms 2156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2156 KB Output is correct
2 Correct 2 ms 2156 KB Output is correct
3 Correct 3 ms 2156 KB Output is correct
4 Correct 4 ms 2156 KB Output is correct
5 Correct 3 ms 2156 KB Output is correct
6 Correct 3 ms 2156 KB Output is correct
7 Correct 3 ms 2156 KB Output is correct
8 Correct 4 ms 2156 KB Output is correct
9 Correct 3 ms 2156 KB Output is correct
10 Correct 3 ms 2156 KB Output is correct
11 Correct 3 ms 2156 KB Output is correct
12 Correct 3 ms 2156 KB Output is correct
13 Correct 2 ms 2156 KB Output is correct
14 Correct 3 ms 2156 KB Output is correct
15 Correct 4 ms 2156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2156 KB Output is correct
2 Correct 2 ms 2156 KB Output is correct
3 Correct 3 ms 2156 KB Output is correct
4 Correct 4 ms 2156 KB Output is correct
5 Correct 3 ms 2156 KB Output is correct
6 Correct 3 ms 2156 KB Output is correct
7 Correct 3 ms 2156 KB Output is correct
8 Correct 4 ms 2156 KB Output is correct
9 Correct 3 ms 2156 KB Output is correct
10 Correct 3 ms 2156 KB Output is correct
11 Correct 3 ms 2156 KB Output is correct
12 Correct 3 ms 2156 KB Output is correct
13 Correct 2 ms 2156 KB Output is correct
14 Correct 3 ms 2156 KB Output is correct
15 Correct 4 ms 2156 KB Output is correct
16 Correct 18 ms 2156 KB Output is correct
17 Correct 39 ms 2156 KB Output is correct
18 Correct 83 ms 2168 KB Output is correct
19 Correct 188 ms 2168 KB Output is correct
20 Correct 190 ms 2172 KB Output is correct
21 Correct 46 ms 2172 KB Output is correct
22 Correct 3 ms 2172 KB Output is correct
23 Correct 42 ms 2172 KB Output is correct
24 Correct 68 ms 2248 KB Output is correct
25 Correct 10 ms 2248 KB Output is correct
26 Correct 38 ms 2248 KB Output is correct
27 Correct 48 ms 2248 KB Output is correct
28 Correct 58 ms 2248 KB Output is correct
29 Correct 19 ms 2248 KB Output is correct
30 Correct 4 ms 2248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 1504 KB Output is correct
2 Correct 11 ms 1504 KB Output is correct
3 Correct 29 ms 1504 KB Output is correct
4 Correct 25 ms 1504 KB Output is correct
5 Correct 51 ms 1504 KB Output is correct
6 Correct 35 ms 1504 KB Output is correct
7 Correct 9 ms 1504 KB Output is correct
8 Correct 22 ms 1504 KB Output is correct
9 Correct 81 ms 2156 KB Output is correct
10 Correct 35 ms 2156 KB Output is correct
11 Correct 3 ms 2156 KB Output is correct
12 Correct 2 ms 2156 KB Output is correct
13 Correct 3 ms 2156 KB Output is correct
14 Correct 4 ms 2156 KB Output is correct
15 Correct 3 ms 2156 KB Output is correct
16 Correct 3 ms 2156 KB Output is correct
17 Correct 3 ms 2156 KB Output is correct
18 Correct 4 ms 2156 KB Output is correct
19 Correct 3 ms 2156 KB Output is correct
20 Correct 3 ms 2156 KB Output is correct
21 Correct 3 ms 2156 KB Output is correct
22 Correct 3 ms 2156 KB Output is correct
23 Correct 2 ms 2156 KB Output is correct
24 Correct 3 ms 2156 KB Output is correct
25 Correct 4 ms 2156 KB Output is correct
26 Correct 18 ms 2156 KB Output is correct
27 Correct 39 ms 2156 KB Output is correct
28 Correct 83 ms 2168 KB Output is correct
29 Correct 188 ms 2168 KB Output is correct
30 Correct 190 ms 2172 KB Output is correct
31 Correct 46 ms 2172 KB Output is correct
32 Correct 3 ms 2172 KB Output is correct
33 Correct 42 ms 2172 KB Output is correct
34 Correct 68 ms 2248 KB Output is correct
35 Correct 10 ms 2248 KB Output is correct
36 Correct 38 ms 2248 KB Output is correct
37 Correct 48 ms 2248 KB Output is correct
38 Correct 58 ms 2248 KB Output is correct
39 Correct 19 ms 2248 KB Output is correct
40 Correct 4 ms 2248 KB Output is correct
41 Correct 166 ms 2248 KB Output is correct
42 Correct 73 ms 2248 KB Output is correct
43 Correct 113 ms 2248 KB Output is correct
44 Correct 66 ms 2248 KB Output is correct
45 Correct 60 ms 2248 KB Output is correct
46 Correct 157 ms 2248 KB Output is correct
47 Correct 51 ms 2248 KB Output is correct
48 Correct 84 ms 2248 KB Output is correct
49 Correct 99 ms 2248 KB Output is correct
50 Correct 660 ms 2248 KB Output is correct
51 Correct 674 ms 2248 KB Output is correct
52 Correct 699 ms 2248 KB Output is correct
53 Correct 753 ms 2248 KB Output is correct
54 Correct 801 ms 2248 KB Output is correct
55 Correct 830 ms 2296 KB Output is correct
56 Correct 676 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 3 ms 544 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 44 ms 1504 KB Output is correct
10 Correct 11 ms 1504 KB Output is correct
11 Correct 29 ms 1504 KB Output is correct
12 Correct 25 ms 1504 KB Output is correct
13 Correct 51 ms 1504 KB Output is correct
14 Correct 35 ms 1504 KB Output is correct
15 Correct 9 ms 1504 KB Output is correct
16 Correct 22 ms 1504 KB Output is correct
17 Correct 81 ms 2156 KB Output is correct
18 Correct 35 ms 2156 KB Output is correct
19 Correct 3 ms 2156 KB Output is correct
20 Correct 2 ms 2156 KB Output is correct
21 Correct 3 ms 2156 KB Output is correct
22 Correct 4 ms 2156 KB Output is correct
23 Correct 3 ms 2156 KB Output is correct
24 Correct 3 ms 2156 KB Output is correct
25 Correct 3 ms 2156 KB Output is correct
26 Correct 4 ms 2156 KB Output is correct
27 Correct 3 ms 2156 KB Output is correct
28 Correct 3 ms 2156 KB Output is correct
29 Correct 3 ms 2156 KB Output is correct
30 Correct 3 ms 2156 KB Output is correct
31 Correct 2 ms 2156 KB Output is correct
32 Correct 3 ms 2156 KB Output is correct
33 Correct 4 ms 2156 KB Output is correct
34 Correct 18 ms 2156 KB Output is correct
35 Correct 39 ms 2156 KB Output is correct
36 Correct 83 ms 2168 KB Output is correct
37 Correct 188 ms 2168 KB Output is correct
38 Correct 190 ms 2172 KB Output is correct
39 Correct 46 ms 2172 KB Output is correct
40 Correct 3 ms 2172 KB Output is correct
41 Correct 42 ms 2172 KB Output is correct
42 Correct 68 ms 2248 KB Output is correct
43 Correct 10 ms 2248 KB Output is correct
44 Correct 38 ms 2248 KB Output is correct
45 Correct 48 ms 2248 KB Output is correct
46 Correct 58 ms 2248 KB Output is correct
47 Correct 19 ms 2248 KB Output is correct
48 Correct 4 ms 2248 KB Output is correct
49 Correct 166 ms 2248 KB Output is correct
50 Correct 73 ms 2248 KB Output is correct
51 Correct 113 ms 2248 KB Output is correct
52 Correct 66 ms 2248 KB Output is correct
53 Correct 60 ms 2248 KB Output is correct
54 Correct 157 ms 2248 KB Output is correct
55 Correct 51 ms 2248 KB Output is correct
56 Correct 84 ms 2248 KB Output is correct
57 Correct 99 ms 2248 KB Output is correct
58 Correct 660 ms 2248 KB Output is correct
59 Correct 674 ms 2248 KB Output is correct
60 Correct 699 ms 2248 KB Output is correct
61 Correct 753 ms 2248 KB Output is correct
62 Correct 801 ms 2248 KB Output is correct
63 Correct 830 ms 2296 KB Output is correct
64 Correct 676 ms 2296 KB Output is correct
65 Correct 2 ms 2296 KB Output is correct
66 Correct 2 ms 2296 KB Output is correct
67 Correct 723 ms 2296 KB Output is correct
68 Correct 722 ms 2296 KB Output is correct
69 Correct 581 ms 2296 KB Output is correct
70 Correct 823 ms 2296 KB Output is correct
71 Correct 789 ms 2296 KB Output is correct
72 Correct 589 ms 2296 KB Output is correct
73 Correct 650 ms 2296 KB Output is correct
74 Correct 695 ms 2296 KB Output is correct
75 Correct 643 ms 2296 KB Output is correct
76 Correct 672 ms 2296 KB Output is correct
77 Correct 122 ms 2300 KB Output is correct
78 Correct 60 ms 2300 KB Output is correct
79 Correct 96 ms 2300 KB Output is correct
80 Correct 100 ms 2300 KB Output is correct
81 Correct 124 ms 2300 KB Output is correct
82 Correct 110 ms 2300 KB Output is correct
83 Correct 75 ms 2300 KB Output is correct
84 Correct 436 ms 2300 KB Output is correct
85 Correct 691 ms 2300 KB Output is correct
86 Correct 3 ms 2300 KB Output is correct
87 Correct 2 ms 2300 KB Output is correct
88 Correct 827 ms 2300 KB Output is correct
89 Correct 142 ms 2300 KB Output is correct
90 Correct 2 ms 2300 KB Output is correct