Submission #1117548

# Submission time Handle Problem Language Result Execution time Memory
1117548 2024-11-23T22:50:14 Z secretwood01 Global Warming (NOI13_gw) Java 11
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;

class Element {
private:
  int nothing;
public:
    int val;
    int ind;
    Element(int val, int ind) : val(val), ind(ind) {}
    bool operator<(const Element& o) const {
        return val > o.val; // For descending order
    }
};

bool funt(int mid, std::vector<Element>& T) {
    int islands = 0;
    int index = 0;
    std::vector<bool> v(T.size(), false);
    while (islands < mid && index < T.size()) {
        int currVal = T[index].val;
        while (index < T.size() && T[index].val == currVal) {
            Element curr = T[index];
            v[curr.ind] = true;
            bool left = curr.ind == 0 || !v[curr.ind - 1];
            bool right = curr.ind == v.size() - 1 || !v[curr.ind + 1];
            if (left && right) islands++;
            bool negLeft = curr.ind != 0 && v[curr.ind - 1];
            bool negRight = curr.ind != v.size() - 1 && v[curr.ind + 1];
            if (negLeft && negRight) islands--;
            index++;
        }
    }
    return islands >= mid;
}

int bs(std::vector<Element>& T) {
    int lo = 1;
    int hi = T.size();
    while (lo < hi) {
        int mid = lo + (hi - lo + 1) / 2;
        if (funt(mid, T)) {
            lo = mid;
        } else {
            hi = mid - 1;
        }
    }
    return lo;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N;
    std::cin >> N;
    std::vector<Element> Arr;
    for (int i = 0; i < N; i++) {
        int value;
        std::cin >> value;
        Arr.emplace_back(value, i);
    }
    std::sort(Arr.begin(), Arr.end());
    std::cout << bs(Arr) << std::endl;
    return 0;
}

Compilation message

gw.java:1: error: illegal character: '#'
#include <iostream>
^
gw.java:1: error: class, interface, or enum expected
#include <iostream>
         ^
gw.java:2: error: illegal character: '#'
#include <vector>
^
gw.java:3: error: illegal character: '#'
#include <algorithm>
^
gw.java:4: error: illegal character: '#'
#include <fstream>
^
gw.java:8: error: illegal start of type
private:
       ^
gw.java:10: error: illegal start of type
public:
      ^
gw.java:13: error: ';' expected
    Element(int val, int ind) : val(val), ind(ind) {}
                             ^
gw.java:14: error: ';' expected
    bool operator<(const Element& o) const {
                 ^
gw.java:14: error: <identifier> expected
    bool operator<(const Element& o) const {
                  ^
gw.java:14: error: illegal start of type
    bool operator<(const Element& o) const {
                   ^
gw.java:19: error: class, interface, or enum expected
bool funt(int mid, std::vector<Element>& T) {
^
gw.java:21: error: class, interface, or enum expected
    int index = 0;
    ^
gw.java:22: error: class, interface, or enum expected
    std::vector<bool> v(T.size(), false);
    ^
gw.java:23: error: class, interface, or enum expected
    while (islands < mid && index < T.size()) {
    ^
gw.java:25: error: class, interface, or enum expected
        while (index < T.size() && T[index].val == currVal) {
        ^
gw.java:27: error: class, interface, or enum expected
            v[curr.ind] = true;
            ^
gw.java:28: error: class, interface, or enum expected
            bool left = curr.ind == 0 || !v[curr.ind - 1];
            ^
gw.java:29: error: class, interface, or enum expected
            bool right = curr.ind == v.size() - 1 || !v[curr.ind + 1];
            ^
gw.java:30: error: class, interface, or enum expected
            if (left && right) islands++;
            ^
gw.java:31: error: class, interface, or enum expected
            bool negLeft = curr.ind != 0 && v[curr.ind - 1];
            ^
gw.java:32: error: class, interface, or enum expected
            bool negRight = curr.ind != v.size() - 1 && v[curr.ind + 1];
            ^
gw.java:33: error: class, interface, or enum expected
            if (negLeft && negRight) islands--;
            ^
gw.java:34: error: class, interface, or enum expected
            index++;
            ^
gw.java:35: error: class, interface, or enum expected
        }
        ^
gw.java:38: error: class, interface, or enum expected
}
^
gw.java:42: error: class, interface, or enum expected
    int hi = T.size();
    ^
gw.java:43: error: class, interface, or enum expected
    while (lo < hi) {
    ^
gw.java:45: error: class, interface, or enum expected
        if (funt(mid, T)) {
        ^
gw.java:47: error: class, interface, or enum expected
        } else {
        ^
gw.java:49: error: class, interface, or enum expected
        }
        ^
gw.java:52: error: class, interface, or enum expected
}
^
gw.java:56: error: class, interface, or enum expected
    std::cin.tie(nullptr);
    ^
gw.java:57: error: class, interface, or enum expected
    int N;
    ^
gw.java:58: error: class, interface, or enum expected
    std::cin >> N;
    ^
gw.java:59: error: class, interface, or enum expected
    std::vector<Element> Arr;
    ^
gw.java:60: error: class, interface, or enum expected
    for (int i = 0; i < N; i++) {
    ^
gw.java:60: error: class, interface, or enum expected
    for (int i = 0; i < N; i++) {
                    ^
gw.java:60: error: class, interface, or enum expected
    for (int i = 0; i < N; i++) {
                           ^
gw.java:62: error: class, interface, or enum expected
        std::cin >> value;
        ^
gw.java:63: error: class, interface, or enum expected
        Arr.emplace_back(value, i);
        ^
gw.java:64: error: class, interface, or enum expected
    }
    ^
gw.java:66: error: class, interface, or enum expected
    std::cout << bs(Arr) << std::endl;
    ^
gw.java:67: error: class, interface, or enum expected
    return 0;
    ^
gw.java:68: error: class, interface, or enum expected
}
^
45 errors