답안 #992511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
992511 2024-06-04T14:20:07 Z tch1cherin Chessboard (IZhO18_chessboard) C++17
100 / 100
548 ms 9036 KB
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<vector<array<int, 3>>> rect(N + 1);
  for (int i = 0; i < K; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, y2--;
    rect[x1].push_back({y1, y2, 1});
    rect[x2].push_back({y1, y2, -1});
  }
  auto Even = [&](int L, int R, int d) {
    int l = L % (2 * d) >= d ? L + d - L % d : L;
    int r = R % (2 * d) >= d ? R - R % d - 1 : R;
    return l > r ? pair {0, -1} : pair {l / (2 * d) * d + l % (2 * d), r / (2 * d) * d + r % (2 * d)};
  };
  auto Odd = [&](int L, int R, int d) {
    int l = L % (2 * d) < d ? L + d - L % d : L;
    int r = R % (2 * d) < d ? R - R % d - 1 : R;
    return l > r ? pair {0, -1} : pair {l / (2 * d) * d + (l - d) % (2 * d), r / (2 * d) * d + (r - d) % (2 * d)};
  };
  long long answer = numeric_limits<long long>::max();
  for (int d = 1; d < N; d++) {
    if (N % d == 0) {
      int N_even = N / (2 * d) * d + min(d, N % (2 * d)), N_odd = N / (2 * d) * d + max(0, N % (2 * d) - d);
      int cnt_e = 0, cnt_o = 0;
      long long answer_e = 0, answer_o = 0;
      for (int i = 0; i < N; i++) {
        for (auto [j1, j2, t] : rect[i]) {
          auto [j1_e, j2_e] = Even(j1, j2, d);
          auto [j1_o, j2_o] = Odd(j1, j2, d);
          cnt_e += t * (j2_e - j1_e + 1);
          cnt_o += t * (j2_o - j1_o + 1);
        }
        int r = (i / d) % 2;
        answer_o += (r ? cnt_e : N_even - cnt_e) + (!r ? cnt_o : N_odd - cnt_o);
        answer_e += (!r ? cnt_e : N_even - cnt_e) + (r ? cnt_o : N_odd - cnt_o);
      }
      answer = min({answer, answer_e, answer_o});
    }
  }
  cout << answer << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 4444 KB Output is correct
2 Correct 6 ms 1628 KB Output is correct
3 Correct 18 ms 4968 KB Output is correct
4 Correct 16 ms 3164 KB Output is correct
5 Correct 22 ms 5200 KB Output is correct
6 Correct 13 ms 3676 KB Output is correct
7 Correct 3 ms 1372 KB Output is correct
8 Correct 13 ms 3676 KB Output is correct
9 Correct 31 ms 6668 KB Output is correct
10 Correct 17 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 10 ms 1880 KB Output is correct
17 Correct 25 ms 5100 KB Output is correct
18 Correct 29 ms 5212 KB Output is correct
19 Correct 100 ms 4956 KB Output is correct
20 Correct 115 ms 5240 KB Output is correct
21 Correct 20 ms 4956 KB Output is correct
22 Correct 1 ms 456 KB Output is correct
23 Correct 19 ms 2652 KB Output is correct
24 Correct 28 ms 5208 KB Output is correct
25 Correct 5 ms 860 KB Output is correct
26 Correct 17 ms 3336 KB Output is correct
27 Correct 26 ms 4424 KB Output is correct
28 Correct 29 ms 5212 KB Output is correct
29 Correct 8 ms 2652 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 4444 KB Output is correct
2 Correct 6 ms 1628 KB Output is correct
3 Correct 18 ms 4968 KB Output is correct
4 Correct 16 ms 3164 KB Output is correct
5 Correct 22 ms 5200 KB Output is correct
6 Correct 13 ms 3676 KB Output is correct
7 Correct 3 ms 1372 KB Output is correct
8 Correct 13 ms 3676 KB Output is correct
9 Correct 31 ms 6668 KB Output is correct
10 Correct 17 ms 4444 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 10 ms 1880 KB Output is correct
27 Correct 25 ms 5100 KB Output is correct
28 Correct 29 ms 5212 KB Output is correct
29 Correct 100 ms 4956 KB Output is correct
30 Correct 115 ms 5240 KB Output is correct
31 Correct 20 ms 4956 KB Output is correct
32 Correct 1 ms 456 KB Output is correct
33 Correct 19 ms 2652 KB Output is correct
34 Correct 28 ms 5208 KB Output is correct
35 Correct 5 ms 860 KB Output is correct
36 Correct 17 ms 3336 KB Output is correct
37 Correct 26 ms 4424 KB Output is correct
38 Correct 29 ms 5212 KB Output is correct
39 Correct 8 ms 2652 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 108 ms 7772 KB Output is correct
42 Correct 44 ms 8540 KB Output is correct
43 Correct 64 ms 8028 KB Output is correct
44 Correct 41 ms 8524 KB Output is correct
45 Correct 36 ms 9036 KB Output is correct
46 Correct 111 ms 8528 KB Output is correct
47 Correct 31 ms 8272 KB Output is correct
48 Correct 53 ms 8284 KB Output is correct
49 Correct 37 ms 8020 KB Output is correct
50 Correct 467 ms 8028 KB Output is correct
51 Correct 495 ms 8432 KB Output is correct
52 Correct 458 ms 8004 KB Output is correct
53 Correct 499 ms 8532 KB Output is correct
54 Correct 447 ms 8028 KB Output is correct
55 Correct 503 ms 8784 KB Output is correct
56 Correct 440 ms 7760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 25 ms 4444 KB Output is correct
10 Correct 6 ms 1628 KB Output is correct
11 Correct 18 ms 4968 KB Output is correct
12 Correct 16 ms 3164 KB Output is correct
13 Correct 22 ms 5200 KB Output is correct
14 Correct 13 ms 3676 KB Output is correct
15 Correct 3 ms 1372 KB Output is correct
16 Correct 13 ms 3676 KB Output is correct
17 Correct 31 ms 6668 KB Output is correct
18 Correct 17 ms 4444 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 10 ms 1880 KB Output is correct
35 Correct 25 ms 5100 KB Output is correct
36 Correct 29 ms 5212 KB Output is correct
37 Correct 100 ms 4956 KB Output is correct
38 Correct 115 ms 5240 KB Output is correct
39 Correct 20 ms 4956 KB Output is correct
40 Correct 1 ms 456 KB Output is correct
41 Correct 19 ms 2652 KB Output is correct
42 Correct 28 ms 5208 KB Output is correct
43 Correct 5 ms 860 KB Output is correct
44 Correct 17 ms 3336 KB Output is correct
45 Correct 26 ms 4424 KB Output is correct
46 Correct 29 ms 5212 KB Output is correct
47 Correct 8 ms 2652 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 108 ms 7772 KB Output is correct
50 Correct 44 ms 8540 KB Output is correct
51 Correct 64 ms 8028 KB Output is correct
52 Correct 41 ms 8524 KB Output is correct
53 Correct 36 ms 9036 KB Output is correct
54 Correct 111 ms 8528 KB Output is correct
55 Correct 31 ms 8272 KB Output is correct
56 Correct 53 ms 8284 KB Output is correct
57 Correct 37 ms 8020 KB Output is correct
58 Correct 467 ms 8028 KB Output is correct
59 Correct 495 ms 8432 KB Output is correct
60 Correct 458 ms 8004 KB Output is correct
61 Correct 499 ms 8532 KB Output is correct
62 Correct 447 ms 8028 KB Output is correct
63 Correct 503 ms 8784 KB Output is correct
64 Correct 440 ms 7760 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 528 ms 8120 KB Output is correct
68 Correct 522 ms 7936 KB Output is correct
69 Correct 450 ms 7252 KB Output is correct
70 Correct 474 ms 7764 KB Output is correct
71 Correct 487 ms 7768 KB Output is correct
72 Correct 462 ms 7504 KB Output is correct
73 Correct 479 ms 7504 KB Output is correct
74 Correct 517 ms 8024 KB Output is correct
75 Correct 480 ms 7516 KB Output is correct
76 Correct 516 ms 8016 KB Output is correct
77 Correct 98 ms 8784 KB Output is correct
78 Correct 48 ms 8280 KB Output is correct
79 Correct 72 ms 8028 KB Output is correct
80 Correct 70 ms 8272 KB Output is correct
81 Correct 71 ms 7744 KB Output is correct
82 Correct 63 ms 8536 KB Output is correct
83 Correct 48 ms 8024 KB Output is correct
84 Correct 320 ms 8540 KB Output is correct
85 Correct 548 ms 8276 KB Output is correct
86 Correct 23 ms 2396 KB Output is correct
87 Correct 23 ms 2392 KB Output is correct
88 Correct 545 ms 8264 KB Output is correct
89 Correct 133 ms 3496 KB Output is correct
90 Correct 22 ms 2396 KB Output is correct