답안 #961463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961463 2024-04-12T06:43:33 Z vjudge1 Lightning Rod (NOI18_lightningrod) C++17
100 / 100
1387 ms 186548 KB
#include <bits/stdc++.h>
 
#pragma optimize("Ofast")
#pragma target("avx2")
 
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
// #define int ll
 
const int MAX=5e5+5;
const int B=90;
const int N=105;
const int block=400;
const int maxB=MAX/B+10;
const ll inf=2e18;  
const int mod=998244353;
const int mod1=1e9+9;
const ld eps=1e-9;
 
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
 
int binpow(int a,int n){
  if(!n)return 1;
  if(n%2==1)return a*binpow(a,n-1)%mod;
  int k=binpow(a,n/2);
  return k*k%mod;
}

int n;
vector<pii> v;

void solve(){
  cin>>n;
  ll mx=-inf;
  ll px=-inf,py=-inf;
  for(int i=1;i<=n;i++){
    int x,y;
    cin>>x>>y;
    if(x+y>mx){
      if(!v.empty()&&v[sz(v)-1].F==x){
        v[sz(v)-1].S=max(v[sz(v)-1].S,-x+y);
      }
      else v.pb({x,-x+y});
      mx=x+y;
    }
    px=x,py=y;
  }
  int ans=0;
  mx=inf;
  for(int i=sz(v)-1;i>=0;i--){
    if(-v[i].S<mx){
      mx=-v[i].S;
      ans++;
    }
  }
  cout<<ans;
}

signed main(){
  //  freopen("help.in","r",stdin);
  //  freopen("help.out","w",stdout);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // prec();
  int t=1;
  // cin>>t;
  while(t--)solve();
}

Compilation message

lightningrod.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize("Ofast")
      | 
lightningrod.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    4 | #pragma target("avx2")
      | 
lightningrod.cpp: In function 'void solve()':
lightningrod.cpp:52:6: warning: variable 'px' set but not used [-Wunused-but-set-variable]
   52 |   ll px=-inf,py=-inf;
      |      ^~
lightningrod.cpp:52:14: warning: variable 'py' set but not used [-Wunused-but-set-variable]
   52 |   ll px=-inf,py=-inf;
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1184 ms 178560 KB Output is correct
2 Correct 1184 ms 184508 KB Output is correct
3 Correct 1139 ms 186548 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 600 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 600 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 452 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 600 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 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 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 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 600 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 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 30 ms 2640 KB Output is correct
15 Correct 27 ms 2644 KB Output is correct
16 Correct 27 ms 3108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1158 ms 75632 KB Output is correct
2 Correct 1166 ms 154040 KB Output is correct
3 Correct 1148 ms 152284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1184 ms 178560 KB Output is correct
2 Correct 1184 ms 184508 KB Output is correct
3 Correct 1139 ms 186548 KB Output is correct
4 Correct 0 ms 344 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 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 452 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 30 ms 2640 KB Output is correct
18 Correct 27 ms 2644 KB Output is correct
19 Correct 27 ms 3108 KB Output is correct
20 Correct 1158 ms 75632 KB Output is correct
21 Correct 1166 ms 154040 KB Output is correct
22 Correct 1148 ms 152284 KB Output is correct
23 Correct 1387 ms 171488 KB Output is correct
24 Correct 1290 ms 156928 KB Output is correct
25 Correct 1235 ms 143848 KB Output is correct