답안 #646541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646541 2022-09-30T02:49:11 Z kith14 Lightning Rod (NOI18_lightningrod) C++17
100 / 100
1781 ms 229556 KB
#include <bits/stdc++.h>
using namespace std;

#define ll int
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>

#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define x first
#define y second
#define mp make_pair
#define pb push_back

const ll N = 5e5+5, MOD = 1e9+7;
ll tc = 1, n, m, xr[N], yr[N];
string s, s1, s2, ye = "YA", no = "TIDAK";

void input(){
  cin >> n;
}

//check if a can consume b
bool eat(pairll a, pairll b){
  if (a == b) return 1;
  if (a.sc > b.sc){
    ll df = a.sc-b.sc;
    if (a.fr-df <= b.fr && b.fr <= a.fr+df) return 1;
  } 
  return 0;
}

void solve(){
  vector<pairll> v;
  //note that xr is increasing
  repp(i,1,n){
    ll xr, yr;
    cin >> xr >> yr;
    //while current point can consume other points
    while(v.size() && eat(mp(xr,yr),v.back())){
      v.pop_back();
    }
    //if empty or the last point cannot consume current point
    if (v.empty() || !eat(v.back(),mp(xr,yr))) v.pb(mp(xr,yr));
  }
  cout << v.size() << endl;
  //for (auto i : v) cout << i.fr << " " << i.sc << endl;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  //cin >> tc;
  while(tc--){
    input();
    solve();
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1501 ms 229456 KB Output is correct
2 Correct 1565 ms 229556 KB Output is correct
3 Correct 1484 ms 229364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 37 ms 3888 KB Output is correct
15 Correct 38 ms 3648 KB Output is correct
16 Correct 42 ms 3836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1480 ms 145220 KB Output is correct
2 Correct 1542 ms 140676 KB Output is correct
3 Correct 1503 ms 141564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1501 ms 229456 KB Output is correct
2 Correct 1565 ms 229556 KB Output is correct
3 Correct 1484 ms 229364 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 37 ms 3888 KB Output is correct
18 Correct 38 ms 3648 KB Output is correct
19 Correct 42 ms 3836 KB Output is correct
20 Correct 1480 ms 145220 KB Output is correct
21 Correct 1542 ms 140676 KB Output is correct
22 Correct 1503 ms 141564 KB Output is correct
23 Correct 1781 ms 172328 KB Output is correct
24 Correct 1742 ms 152688 KB Output is correct
25 Correct 1673 ms 137636 KB Output is correct