답안 #701785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701785 2023-02-22T06:11:59 Z lto5 Lightning Rod (NOI18_lightningrod) C++14
0 / 100
2000 ms 6628 KB
#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

namespace sub1 {
void solve(int n) {
  vector<pair<int, int>> vt;
  stack<int> st;
  while (n--) {
    int x, y;
    cin >> x >> y;
    vt.emplace_back(x + y, y - x);
  }
  sort(vt.begin(), vt.end());
  for (auto [x, y] : vt) {
    while (!st.empty() && st.top() <= y) {
      st.pop();
    }
    st.push(y);
  }
  cout << st.size();
}
}  // namespace sub1

namespace sub2 {
const int N = 1e7 + 5;
pair<int, int> st[N];
int max_y[N];

void solve(int n) {
  int top = 0;
  while (n--) {
    int x, y;
    cin >> x >> y;
    /*
      /\            ___
     /  \ --->         |
    /    \             |
    */
    // rotate 45 degrees
    int nx = x + y;
    int ny = x - y;
    x = nx, y = ny;
    debug(x, y);
    while (top > 0 && st[top].first <= x) {
      top--;
    }
    // debug(top);
    if (top > 0 && max_y[top] >= y) {
      continue;
    }
    // debug('.', top);
    st[++top] = {x, y};
    max_y[top] = max(max_y[top - 1], y);
  }
  cout << top;
}
}  // namespace sub2

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#define task "a"
  if (fopen(task ".inp", "r")) {
    freopen(task ".inp", "r", stdin);
    freopen(task ".out", "w", stdout);
  }
  int n;
  cin >> n;
  // if (n <= 1e6) {
  //   sub1::solve(n);
  //   return 0;
  // }
  sub2::solve(n);
  return 0;
}

Compilation message

lightningrod.cpp: In function 'void sub1::solve(int)':
lightningrod.cpp:23:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |   for (auto [x, y] : vt) {
      |             ^
lightningrod.cpp: In function 'int main()':
lightningrod.cpp:74:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |     freopen(task ".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
lightningrod.cpp:75:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |     freopen(task ".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2094 ms 6628 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2059 ms 5156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2094 ms 6628 KB Time limit exceeded
2 Halted 0 ms 0 KB -