답안 #1057034

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057034 2024-08-13T13:29:59 Z mychecksedad 송신탑 (IOI22_towers) C++17
23 / 100
4000 ms 6960 KB
#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long int
#define en cout << '\n'
#define pi pair<int,int>
#define vi vector<int> 
#define ff first
#define ss second

struct Fenwick{
  vector<int> t;
  int n;
  Fenwick(int n): n(n){
    t.resize(n+1);
  }
  void add(int v){
    while(v <= n){
      t[v]++;
      v += v&-v;
    }
  }
  int get(int v){
    int res = 0;
    while(v > 0){
      res += t[v];
      v -= v&-v;
    }
    return res;
  }
};


void op(vector<int> &a, vector<int> &A, vector<int> &B){
  if(a.size() <= 1){
    A = a;
    B.pb(0);
    return;
  }
  A.pb(a[0]);
  A.pb(a[1]);
  B.pb(0);
  B.pb(1);
  for(int i = 2; i < a.size(); ++i){
    if(a[i] > A.back() && A.back() > A[int(A.size()) - 2]){
      A.pop_back();
      B.pop_back();
      A.pb(a[i]);
      B.pb(i);
    }else if(a[i] < A.back() && A.back() < A[int(A.size()) - 2]){
      A.pop_back();
      B.pop_back();
      A.pb(a[i]);
      B.pb(i);
    }else{
      A.pb(a[i]);
      B.pb(i);
    }
  }
  
}
int n;
vector<int> A, B, A2, A1, B1, B2, a;
Fenwick f(1000000);
void init(int nn, std::vector<int> aa) { n=nn;a=aa;
  if(n == 1) return;
  op(a, A, B);
  // elimizde a b var cool
  // if(A[0] > A[1]){
  //   for(int i = 0; i < A.size(); i += 2){
  //     f.add(B[i]);
  //   }
  // }else{
  //   for(int i = 1; i < A.size(); i += 2){
  //     f.add(B[i]);
  //   }
  // }
  for(int i = 1; i + 1 < n; ++i){
    if(a[i] > a[i - 1] && a[i] > a[i + 1]) f.add(i + 1);
  }
}

int max_towers(int L, int R, int D) { ++L, ++R;
  if(n == 1 || L == R) return 1;
  --L, --R;
  vector<int> X;
  for(int i = L; i <= R; ++i) X.pb(a[i]);
  A.clear();
  B.clear();
  op(X, A, B);

  // set<pair<int, int>> s;
  // priority_queue<pair<int, int>> q;
  // for(int i = 0; i < A.size(); ++i){
    // s.insert({i, A[i]});
    // if(i > 0 && i + 1 < A.size()){
    //   if(A < )
    //   q.push({-min(A[i + 1] - A[i], A[i - 1] - A[i]), i});
    // }
  // }
  bool ok = 1;
  while(ok){
    ok = 0;
    if(A.size() == 1) return 1;
    int mindif = 1000000000, pos = -1;
    for(int i = 0; i < A.size(); ++i){
      if(i + 2 < A.size() && A[i] < A[i + 1]){  
        if(mindif > A[i + 1] - A[i]){
          mindif = A[i + 1] - A[i];
          pos = i;
        }
      }
      if(i > 1 && A[i] < A[i - 1]){  
        if(mindif > A[i - 1] - A[i]){
          mindif = A[i - 1] - A[i];
          pos = i;
        }
      }
    }
    if(pos == -1) break;
    if(mindif < D)
      A.erase(A.begin() + pos), ok = 1;
    else 
      break;
    for(int i = 0; i + 2 < A.size(); ++i){
      if(A[i] < A[i + 1] && A[i + 1] < A[i + 2]){
        A.erase(A.begin() + i + 1); 
        --i;
        continue;
      }
      if(A[i] > A[i + 1] && A[i + 1] > A[i + 2]){
        A.erase(A.begin() + i + 1);
        --i;
        continue;
      }
    }
  }
  // for(auto k: A) cout << k<< ' '; 
  int ans = 0;
  for(int i = 1; i + 1 < A.size(); ++i){
    if(A[i] > A[i - 1] && A[i] > A[i + 1] ) ++ans;
  }
  return max(ans+1,1);
}

Compilation message

towers.cpp: In function 'void op(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
towers.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for(int i = 2; i < a.size(); ++i){
      |                  ~~^~~~~~~~~~
towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:108:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for(int i = 0; i < A.size(); ++i){
      |                    ~~^~~~~~~~~~
towers.cpp:109:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |       if(i + 2 < A.size() && A[i] < A[i + 1]){
      |          ~~~~~~^~~~~~~~~~
towers.cpp:127:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |     for(int i = 0; i + 2 < A.size(); ++i){
      |                    ~~~~~~^~~~~~~~~~
towers.cpp:142:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |   for(int i = 1; i + 1 < A.size(); ++i){
      |                  ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4058 ms 5440 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4184 KB Output is correct
2 Correct 1 ms 4184 KB Output is correct
3 Correct 1 ms 4184 KB Output is correct
4 Correct 1 ms 4184 KB Output is correct
5 Correct 1 ms 4184 KB Output is correct
6 Correct 1 ms 4184 KB Output is correct
7 Correct 1 ms 4184 KB Output is correct
8 Correct 1 ms 4184 KB Output is correct
9 Correct 1 ms 4184 KB Output is correct
10 Correct 1 ms 4184 KB Output is correct
11 Correct 1 ms 4184 KB Output is correct
12 Correct 1 ms 4184 KB Output is correct
13 Correct 1 ms 4184 KB Output is correct
14 Correct 1 ms 4184 KB Output is correct
15 Correct 1 ms 4184 KB Output is correct
16 Correct 1 ms 4184 KB Output is correct
17 Correct 1 ms 4184 KB Output is correct
18 Correct 2 ms 4252 KB Output is correct
19 Correct 2 ms 4300 KB Output is correct
20 Correct 2 ms 4184 KB Output is correct
21 Correct 1 ms 4184 KB Output is correct
22 Correct 1 ms 4184 KB Output is correct
23 Correct 1 ms 4184 KB Output is correct
24 Correct 1 ms 4180 KB Output is correct
25 Correct 1 ms 4184 KB Output is correct
26 Correct 2 ms 4184 KB Output is correct
27 Correct 1 ms 4184 KB Output is correct
28 Correct 6 ms 4184 KB Output is correct
29 Correct 5 ms 4184 KB Output is correct
30 Correct 3 ms 4184 KB Output is correct
31 Correct 3 ms 4180 KB Output is correct
32 Correct 2 ms 4184 KB Output is correct
33 Correct 1 ms 4184 KB Output is correct
34 Correct 1 ms 4184 KB Output is correct
35 Correct 1 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4184 KB Output is correct
2 Correct 1 ms 4184 KB Output is correct
3 Correct 1 ms 4184 KB Output is correct
4 Correct 1 ms 4184 KB Output is correct
5 Correct 1 ms 4184 KB Output is correct
6 Correct 1 ms 4184 KB Output is correct
7 Correct 1 ms 4184 KB Output is correct
8 Correct 1 ms 4184 KB Output is correct
9 Correct 1 ms 4184 KB Output is correct
10 Correct 1 ms 4184 KB Output is correct
11 Correct 1 ms 4184 KB Output is correct
12 Correct 1 ms 4184 KB Output is correct
13 Correct 1 ms 4184 KB Output is correct
14 Correct 1 ms 4184 KB Output is correct
15 Correct 1 ms 4184 KB Output is correct
16 Correct 1 ms 4184 KB Output is correct
17 Correct 1 ms 4184 KB Output is correct
18 Correct 2 ms 4252 KB Output is correct
19 Correct 2 ms 4300 KB Output is correct
20 Correct 2 ms 4184 KB Output is correct
21 Correct 1 ms 4184 KB Output is correct
22 Correct 1 ms 4184 KB Output is correct
23 Correct 1 ms 4184 KB Output is correct
24 Correct 1 ms 4180 KB Output is correct
25 Correct 1 ms 4184 KB Output is correct
26 Correct 2 ms 4184 KB Output is correct
27 Correct 1 ms 4184 KB Output is correct
28 Correct 6 ms 4184 KB Output is correct
29 Correct 5 ms 4184 KB Output is correct
30 Correct 3 ms 4184 KB Output is correct
31 Correct 3 ms 4180 KB Output is correct
32 Correct 2 ms 4184 KB Output is correct
33 Correct 1 ms 4184 KB Output is correct
34 Correct 1 ms 4184 KB Output is correct
35 Correct 1 ms 4184 KB Output is correct
36 Correct 25 ms 5588 KB Output is correct
37 Correct 344 ms 6356 KB Output is correct
38 Correct 40 ms 6356 KB Output is correct
39 Correct 607 ms 6540 KB Output is correct
40 Correct 42 ms 6356 KB Output is correct
41 Correct 3116 ms 6724 KB Output is correct
42 Correct 9 ms 6356 KB Output is correct
43 Correct 9 ms 5584 KB Output is correct
44 Correct 8 ms 5496 KB Output is correct
45 Correct 8 ms 5464 KB Output is correct
46 Correct 8 ms 5464 KB Output is correct
47 Correct 10 ms 6356 KB Output is correct
48 Correct 9 ms 6356 KB Output is correct
49 Correct 9 ms 6356 KB Output is correct
50 Correct 11 ms 5716 KB Output is correct
51 Correct 9 ms 5464 KB Output is correct
52 Correct 11 ms 6520 KB Output is correct
53 Correct 10 ms 6724 KB Output is correct
54 Correct 11 ms 6724 KB Output is correct
55 Correct 9 ms 6016 KB Output is correct
56 Correct 9 ms 5892 KB Output is correct
57 Correct 2107 ms 6500 KB Output is correct
58 Correct 1789 ms 6468 KB Output is correct
59 Correct 1152 ms 6468 KB Output is correct
60 Correct 14 ms 6724 KB Output is correct
61 Correct 1745 ms 6768 KB Output is correct
62 Correct 3912 ms 6724 KB Output is correct
63 Correct 1510 ms 6724 KB Output is correct
64 Correct 8 ms 5840 KB Output is correct
65 Correct 8 ms 5840 KB Output is correct
66 Correct 9 ms 6012 KB Output is correct
67 Correct 9 ms 5840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4083 ms 6960 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4056 ms 4848 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4184 KB Output is correct
2 Correct 1 ms 4184 KB Output is correct
3 Correct 1 ms 4184 KB Output is correct
4 Correct 1 ms 4184 KB Output is correct
5 Correct 1 ms 4184 KB Output is correct
6 Correct 1 ms 4184 KB Output is correct
7 Correct 1 ms 4184 KB Output is correct
8 Correct 1 ms 4184 KB Output is correct
9 Correct 1 ms 4184 KB Output is correct
10 Correct 1 ms 4184 KB Output is correct
11 Correct 1 ms 4184 KB Output is correct
12 Correct 1 ms 4184 KB Output is correct
13 Correct 1 ms 4184 KB Output is correct
14 Correct 1 ms 4184 KB Output is correct
15 Correct 1 ms 4184 KB Output is correct
16 Correct 1 ms 4184 KB Output is correct
17 Correct 1 ms 4184 KB Output is correct
18 Correct 2 ms 4252 KB Output is correct
19 Correct 2 ms 4300 KB Output is correct
20 Correct 2 ms 4184 KB Output is correct
21 Correct 1 ms 4184 KB Output is correct
22 Correct 1 ms 4184 KB Output is correct
23 Correct 1 ms 4184 KB Output is correct
24 Correct 1 ms 4180 KB Output is correct
25 Correct 1 ms 4184 KB Output is correct
26 Correct 2 ms 4184 KB Output is correct
27 Correct 1 ms 4184 KB Output is correct
28 Correct 6 ms 4184 KB Output is correct
29 Correct 5 ms 4184 KB Output is correct
30 Correct 3 ms 4184 KB Output is correct
31 Correct 3 ms 4180 KB Output is correct
32 Correct 2 ms 4184 KB Output is correct
33 Correct 1 ms 4184 KB Output is correct
34 Correct 1 ms 4184 KB Output is correct
35 Correct 1 ms 4184 KB Output is correct
36 Correct 25 ms 5588 KB Output is correct
37 Correct 344 ms 6356 KB Output is correct
38 Correct 40 ms 6356 KB Output is correct
39 Correct 607 ms 6540 KB Output is correct
40 Correct 42 ms 6356 KB Output is correct
41 Correct 3116 ms 6724 KB Output is correct
42 Correct 9 ms 6356 KB Output is correct
43 Correct 9 ms 5584 KB Output is correct
44 Correct 8 ms 5496 KB Output is correct
45 Correct 8 ms 5464 KB Output is correct
46 Correct 8 ms 5464 KB Output is correct
47 Correct 10 ms 6356 KB Output is correct
48 Correct 9 ms 6356 KB Output is correct
49 Correct 9 ms 6356 KB Output is correct
50 Correct 11 ms 5716 KB Output is correct
51 Correct 9 ms 5464 KB Output is correct
52 Correct 11 ms 6520 KB Output is correct
53 Correct 10 ms 6724 KB Output is correct
54 Correct 11 ms 6724 KB Output is correct
55 Correct 9 ms 6016 KB Output is correct
56 Correct 9 ms 5892 KB Output is correct
57 Correct 2107 ms 6500 KB Output is correct
58 Correct 1789 ms 6468 KB Output is correct
59 Correct 1152 ms 6468 KB Output is correct
60 Correct 14 ms 6724 KB Output is correct
61 Correct 1745 ms 6768 KB Output is correct
62 Correct 3912 ms 6724 KB Output is correct
63 Correct 1510 ms 6724 KB Output is correct
64 Correct 8 ms 5840 KB Output is correct
65 Correct 8 ms 5840 KB Output is correct
66 Correct 9 ms 6012 KB Output is correct
67 Correct 9 ms 5840 KB Output is correct
68 Execution timed out 4083 ms 6960 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4058 ms 5440 KB Time limit exceeded
2 Halted 0 ms 0 KB -