답안 #784220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
784220 2023-07-15T21:30:12 Z GordonRemzi007 송신탑 (IOI22_towers) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> a;
bool srt(pair<int,int> a, pair<int,int> b) {
    return a.first < b.first;
}
void init(int n, int h[]) {
    a = vector<int>(n);
    for(int i = 0; i < n; i++) a[i] = h[i];
}
int max_towers(int l, int r, int d) {
    int res = 0, f, s;
    bool ok;
    vector<bool> used(a.size(), false);
    vector<pair<int,int>> b(r-l+1);
    for(int i = l; i <= r; i++) b[i] = {a[i], i};
    sort(b.begin(), b.end(), srt);
    for(int i = 0; i < b.size(); i++) {
        f = b[i].second, s = b[i].second;
        ok = true;
        //find closest left and right a[i] >= a[b[i].second]+d
        for(; f >= l; f--) {
            if(used[f]) {
                ok = false;
                break;
            }
            if(a[f] >= a[b[i].second]+d) break;
            if(f == l) {
                f = b[i].second;
                break;
            }
        }
        for(; s <= r; s++) {
            if(used[s]) {
                ok = false;
                break;
            }
            if(a[s] >= a[b[i].second]+d) break;
            if(s == r) {
                s = b[i].second;
                break;
            }
        }
        if(ok) {
            used[b[i].second] = true;
            res++;
        }
    }
    return res;
}
int main() {

}

Compilation message

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:22:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 0; i < b.size(); i++) {
      |                    ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccPP36HU.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccXWv30U.o:towers.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccPP36HU.o: in function `main':
stub.cpp:(.text.startup+0x179): undefined reference to `init(int, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status