답안 #1079468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079468 2024-08-28T15:23:20 Z LittleOrange 송신탑 (IOI22_towers) C++17
0 / 100
4000 ms 4240 KB
#include "towers.h"

#include <vector>
#include<bits/stdc++.h>
using namespace std;
using ll = int;
const ll big = 1e9+10;
ll n;
vector<ll> h;
//ll mx;
vector<ll> ps;
struct obj{
  ll v,c;
  bool operator<(const obj &o) const{
    return v<o.v;
  }
  bool operator>(const obj &o) const{
    return v>o.v;
  }
};

void init(int N, std::vector<int> H) {
  n = N;
  h = H;
  //for(ll i = 0;i<n;i++) if((i==0||(h[i-1]<h[i]))&&(i==n-1||h[i]>h[i+1])) mx = i;
  //for(ll i = 1;i<n-1;i++){
  //  if (h[i-1]<h[i]&&h[i]>h[i+1]){
  //    ps.push_back(i);
  //  }
  //}
  //for(auto [u,v] : ps) cerr << "[" << u << "," << v << "]" << " ";cerr << "\n";
}
void init_ps(ll d){
  vector<ll> l(n,0),r(n,0);
  {
    vector<pair<ll,ll>> v;
    v.push_back({h[0],h[0]});
    for(ll i = 1;i<n;i++){
      ll mi = h[i];
      while(v.size()&&v.back().first<h[i]){
        mi = min(mi,v.back().second);
        v.pop_back();
      }
      if (mi<=h[i]-d) l[i] = 1;
      v.push_back({h[i],mi});
    }
  }
  {
    vector<pair<ll,ll>> v;
    v.push_back({h[n-1],h[n-1]});
    for(ll i = n-2;i>=0;i--){
      ll mi = h[i];
      while(v.size()&&v.back().first<h[i]){
        mi = min(mi,v.back().second);
        v.pop_back();
      }
      if (mi<=h[i]-d) r[i] = 1;
      v.push_back({h[i],mi});
    }
  }
  for(ll i = 0;i<n;i++) if(l[i]&&r[i]) ps.push_back(i);
}

int max_towers(int L, int R, int D) {
  if(ps.empty()) init_ps(D);
  ll l = L, r = R, d = D;
  ll ans = 1;
  auto it0 = lower_bound(ps.begin(),ps.end(),r);
  ll rf = it0-ps.begin();
  auto it1 = lower_bound(ps.begin(),ps.end(),l+1);
  ll lf = it1-ps.begin();
  //cerr << lf << " " << rf << "\n";
  return max(0,rf-lf)+1;
  /*vector<obj> a,b;
  a.push_back({0,0});
  b.push_back({big,0});
  for(ll i = l;i<=r;i++){
    ll cur = 0;
    auto it = lower_bound(b.begin(),b.end(),obj({h[i]-1,0}),greater<obj>());
    --it;
    cur = (*it).c;
    ans = max(ans,cur+1);
    obj oa = {h[i],cur+1};
    if (a.size()<=oa.c) a.push_back(oa);
    else a[oa.c] = min(a[oa.c],oa);
    auto it0 = lower_bound(a.begin(),a.end(),obj({h[i]-d+1,0}));
    --it0;
    obj ob = {h[i]-d,(*it0).c};
    if (b.size()<=ob.c) b.push_back(ob);
    else b[ob.c] = max(b[ob.c],ob);
    ans = max(ans,cur+1);
    //cerr << "a:";for(auto [u,v] : a) cerr << "(" << u <<"," << v << ") ";cerr << "\n";
    //cerr << "b:";for(auto [u,v] : b) cerr << "(" << u <<"," << v << ") ";cerr << "\n";
  }*/
  return ans;
}

Compilation message

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:66:20: warning: unused variable 'd' [-Wunused-variable]
   66 |   ll l = L, r = R, d = D;
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 283 ms 2156 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '91', found: '92'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '91', found: '92'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 532 ms 2260 KB Output is correct
2 Correct 682 ms 2256 KB Output is correct
3 Correct 672 ms 2256 KB Output is correct
4 Correct 649 ms 2256 KB Output is correct
5 Correct 718 ms 2256 KB Output is correct
6 Correct 717 ms 2256 KB Output is correct
7 Correct 652 ms 2256 KB Output is correct
8 Execution timed out 4021 ms 4240 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 183 ms 856 KB 2nd lines differ - on the 1st token, expected: '7063', found: '7197'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '91', found: '92'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 283 ms 2156 KB 2nd lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -