답안 #414135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
414135 2021-05-30T06:34:48 Z 600Mihnea Cultivation (JOI17_cultivation) C++17
15 / 100
2000 ms 340 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
/// #define y1 y4234234234234324239423492348324382432949234234923492348234234932849238439483948249327532653428523492573454

const int N = 300 + 7;
const int INF = (int) 1e9 + 7;

int dimx, dimy, n;

struct point {
  int x;
  int y;
};

bool operator < (point a, point b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}

point v[N];

struct Event {
  int when;
  int l, r;
  int coef;
};

bool operator < (Event a, Event b) {
  if (a.when != b.when) return a.when < b.when;
  return a.coef < b.coef;
}

bool ok(int a, int b, int c, int d) {
  bool ok1 = 0, ok2 = 0;

  vector<Event> events;
  for (int i = 1; i <= n; i++) {
    int x1 = v[i].x - a, x2 = v[i].x + b;
    int y1 = v[i].y - c, y2 = v[i].y + d;

    x1 = max(x1, 1);
    x2 = min(x2, dimx);

    y1 = max(y1, 1);
    y2 = min(y2, dimy);

    events.push_back({x1, y1, y2, +1});
    if (x2 < dimx) {
      events.push_back({x2 + 1, y1, y2, -1});
    }
    ok1 |= (x1 == 1);
    ok2 |= (x2 == dimx);
  }
  sort(events.begin(), events.end());


  if (!ok1 || !ok2) {
    return 0;
  }

  vector<pair<int, int>> intervals;

  for (int step = 0; step < (int) events.size(); step++) {
    auto it = events[step];
    int l = it.l, r = it.r + 1;
    if (it.coef == 1) {
      intervals.push_back({l, r});
    } else {
      pair<int, int> pr = {l, r};
      for (auto &it : intervals) {
        if (it == pr) {
          swap(it, intervals.back());
        }
      }
      assert(!intervals.empty());
      assert(intervals.back() == pr);
      intervals.pop_back();
    }
    if (step + 1 < (int) events.size() && events[step + 1].when == events[step].when) {
      continue;
    }
    sort(intervals.begin(), intervals.end());
    /**cout << events[step].when << " ---------> ";
    cout << (int) intervals.size() << " : ";
    for (auto &it : intervals) {
      cout << it.first << " " << it.second << " | ";
    }
    cout << "\n";**/
    bool good = 1;
    int last = 1;
    for (auto &it : intervals) {
      if (it.first > last) {
        good = 0;
        break;
      }
      last = max(last, it.second);
    }
   /// cout << last << " and " << dimy + 1 << "\n";
    good &= (last == dimy + 1);
    if (!good) {
      return 0;
    }
  }
  return 1;
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);

  ///freopen ("input", "r", stdin);

  cin >> dimx >> dimy >> n;

  for (int i = 1; i <= n; i++) {
    cin >> v[i].x >> v[i].y;
  }

  ///cout << ok(1, 2, 1, 0) << "\n";
  ///return 0;

  int sol = INF;

  for (int a = 0; a <= dimx; a++) {
    for (int b = 0; b <= dimx; b++) {
      for (int c = 0; c <= dimy; c++) {
        for (int d = 0; d <= dimy; d++) {
          if (a + b + c + d >= sol) continue;
          if (ok(a, b, c, d)) {
            sol = a + b + c + d;
          }
        }
      }
    }
  }
  cout << sol << "\n";

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 5 ms 312 KB Output is correct
18 Correct 11 ms 320 KB Output is correct
19 Correct 239 ms 300 KB Output is correct
20 Correct 14 ms 328 KB Output is correct
21 Correct 1257 ms 296 KB Output is correct
22 Correct 169 ms 204 KB Output is correct
23 Correct 638 ms 308 KB Output is correct
24 Correct 116 ms 308 KB Output is correct
25 Correct 174 ms 332 KB Output is correct
26 Correct 510 ms 340 KB Output is correct
27 Correct 186 ms 332 KB Output is correct
28 Correct 182 ms 332 KB Output is correct
29 Correct 76 ms 332 KB Output is correct
30 Correct 108 ms 336 KB Output is correct
31 Correct 64 ms 332 KB Output is correct
32 Correct 108 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 5 ms 312 KB Output is correct
18 Correct 11 ms 320 KB Output is correct
19 Correct 239 ms 300 KB Output is correct
20 Correct 14 ms 328 KB Output is correct
21 Correct 1257 ms 296 KB Output is correct
22 Correct 169 ms 204 KB Output is correct
23 Correct 638 ms 308 KB Output is correct
24 Correct 116 ms 308 KB Output is correct
25 Correct 174 ms 332 KB Output is correct
26 Correct 510 ms 340 KB Output is correct
27 Correct 186 ms 332 KB Output is correct
28 Correct 182 ms 332 KB Output is correct
29 Correct 76 ms 332 KB Output is correct
30 Correct 108 ms 336 KB Output is correct
31 Correct 64 ms 332 KB Output is correct
32 Correct 108 ms 324 KB Output is correct
33 Execution timed out 2066 ms 332 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2050 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2050 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 5 ms 312 KB Output is correct
18 Correct 11 ms 320 KB Output is correct
19 Correct 239 ms 300 KB Output is correct
20 Correct 14 ms 328 KB Output is correct
21 Correct 1257 ms 296 KB Output is correct
22 Correct 169 ms 204 KB Output is correct
23 Correct 638 ms 308 KB Output is correct
24 Correct 116 ms 308 KB Output is correct
25 Correct 174 ms 332 KB Output is correct
26 Correct 510 ms 340 KB Output is correct
27 Correct 186 ms 332 KB Output is correct
28 Correct 182 ms 332 KB Output is correct
29 Correct 76 ms 332 KB Output is correct
30 Correct 108 ms 336 KB Output is correct
31 Correct 64 ms 332 KB Output is correct
32 Correct 108 ms 324 KB Output is correct
33 Execution timed out 2066 ms 332 KB Time limit exceeded
34 Halted 0 ms 0 KB -