kingofcoding1's blog

By kingofcoding1, history, 12 months ago, In English

https://www.aiasoft.ge/problem/72 if someone goes here and solove this riddle i am gonna be so heppy cause it took me huge amount of time to get the correct answer but failled on test n2 #include <bits/stdc++.h> using namespace std; using ll = long long;

int main() { ios::sync_with_stdio(false); cin.tie(nullptr);

ll h, w;
cin >> h >> w;
int N;
cin >> N;

vector<pair<ll,ll>> pts(N);
for(int i = 0; i < N; i++) {
    cin >> pts[i].first >> pts[i].second;
}

vector<ll> Ys;
Ys.reserve(N + 2);
Ys.push_back(0);
Ys.push_back(h);
for(auto &p : pts) Ys.push_back(p.second);
sort(Ys.begin(), Ys.end());
Ys.erase(unique(Ys.begin(), Ys.end()), Ys.end());

auto idx = [&](ll y) {
    return int(lower_bound(Ys.begin(), Ys.end(), y) - Ys.begin());
};

int M = Ys.size();
vector<vector<ll>> addEv(M), remEv(M);
for(int i = 0; i + 1 < N; i++) {
    auto A = pts[i], B = pts[i+1];
    if(A.second == B.second) continue;
    if(A.second > B.second) swap(A, B);
    int lo = idx(A.second), hi = idx(B.second);
    addEv[lo].push_back(A.first);
    remEv[hi].push_back(A.first);
}

multiset<ll> active;
long double uncleaned = 0.0L;

for(int i = 0; i + 1 < M; i++) {
    ll y0 = Ys[i], y1 = Ys[i+1], dy = y1 - y0;
    if(dy == 0) continue;

    for(ll x : addEv[i]) active.insert(x);
    for(ll x : remEv[i]) {
        auto it = active.find(x);
        if(it != active.end()) active.erase(it);
    }

    long double width;
    size_t k = active.size();

    if(k == 0) {
        width = (long double)w;
    }
    else if(k == 1) {
        ll x0 = *active.begin();
        width = (long double)w - x0;
    }
    else if(k == 2) {
        auto it = active.begin();
        ll x1 = *++it;
        width = (long double)w - x1;
    }
    else if(k == 3) {
        auto it = active.begin();
        ++it; ++it;
        ll x2 = *it;
        width = (long double)w - x2;
    }
    else if(k == 4) {
        auto it = active.end();
        ll x3 = *--it;
        width = (long double)w - x3;
    }
    else if(k == 5) {
        auto it = active.end();
        ll x4 = *--it;
        width = (long double)w - x4;
    }
    else {
        ll xmax = *active.rbegin();
        width = (long double)w - xmax;
    }

    uncleaned += width * dy;
}

ll answer = llround(uncleaned);
cout << answer << "\n";
return 0;

} here is my code but it faiils so help

Full text and comments »

  • Vote: I like it
  • -7
  • Vote: I do not like it

By kingofcoding1, history, 12 months ago, In English

can someone help me by soloving this riddle? i am not able to solove it correctly so codeforse users pls help love you all guys

Problem Description Imagine a rectangular floor-cleaning device with height h. The right side of the device is damaged, forming a jagged path consisting of horizontal and vertical segments. The intact parts of the device stay tightly attached to the floor.

The device is placed inside a corridor with height h and width w, and it moves from right to left. While cleaning, the top and bottom edges of the device stay tightly attached to the corridor walls, so the device cannot rotate or tilt.

The floor-cleaning ends when the rightmost edge of the device passes beyond the leftmost edge of the corridor.

On the left, there is an illustration showing the initial position of the device (light gray), and on the right, an illustration of the corridor after cleaning — the white area is the cleaned part, while the dark gray is the uncleaned floor.

Your Task Write a program that determines the area of the floor that remains uncleaned after the device has finished cleaning.

Input Format The first line contains two integers h and w — the height and width of the corridor, respectively.

The second line contains an integer N — the number of points that define the damaged jagged edge on the right of the device. This edge consists of N — 1 segments.

The next N lines contain two integers xi and yi — the coordinates of the i-th point on the broken edge. The coordinate system starts at the top-left corner of the device: y1 = 0 and yN = h.

Constraints 1 < N ≤ 100000

0 < w, h ≤ 1234567890

0 ≤ xi ≤ w

0 ≤ yi ≤ h

Output Format Print a single integer — the area of the floor that remains uncleaned.

Sample Input Copy Edit 15 10 16 6 0 6 2 11 2 11 6 8 6 8 4 9 4 9 5 10 5 10 3 6 3 6 7 12 7 12 8 9 8 9 10 Sample Output Copy Edit 58

Full text and comments »

  • Vote: I like it
  • +1
  • Vote: I do not like it