답안 #1078874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078874 2024-08-28T07:34:59 Z LittleOrange 송신탑 (IOI22_towers) C++17
0 / 100
541 ms 2768 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<pair<ll,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;
  ll l = 0;
  for(ll i = 2;i<n;i++){
    if (h[i]>h[i-1]!=h[i-1]>h[i-2]){
      ps.push_back({l,i-1});
      l = i-1;
    }
  }
  ps.push_back({l,n-1});
  //for(auto [u,v] : ps) cerr << "[" << u << "," << v << "]" << " ";cerr << "\n";
}

int max_towers(int L, int R, int D) {
  ll l = L, r = R, d = D;
  ll ans = 1;
  auto it0 = lower_bound(ps.begin(),ps.end(),make_pair(r,0));
  ll rf = it0-ps.begin();
  auto it1 = lower_bound(ps.begin(),ps.end(),make_pair(l,0));
  ll lf = it1-ps.begin();
  //cerr << lf << " " << rf << "\n";
  return (rf-lf)/2+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 'void init(int, std::vector<int>)':
towers.cpp:28:13: warning: suggest parentheses around comparison in operand of '!=' [-Wparentheses]
   28 |     if (h[i]>h[i-1]!=h[i-1]>h[i-2]){
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:38:20: warning: unused variable 'd' [-Wunused-variable]
   38 |   ll l = L, r = R, d = D;
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 296 ms 1112 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '17'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '17'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 541 ms 2768 KB 4th lines differ - on the 1st token, expected: '13956', found: '13957'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 190 ms 856 KB 1st lines differ - on the 1st token, expected: '7197', found: '8004'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB 1st lines differ - on the 1st token, expected: '13', found: '17'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 296 ms 1112 KB 12th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -