Submission #1079397

# Submission time Handle Problem Language Result Execution time Memory
1079397 2024-08-28T13:54:21 Z anton Tiles (BOI24_tiles) C++17
22 / 100
203 ms 24616 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pt complex<int>
#define pii pair<int, int>
int N, M;


struct Interval{
    int x;
    int yl, yr;
    bool open = false;

    bool operator<(const Interval& b)const{
        return yl<b.yl;
    }
    vector<Interval> clip(pii other_pair){
        ////cout<<"clipping "<<yl<<" "<<yr<<" "<<other_pair.first<<" "<<other_pair.second<<endl;

        if(yr<other_pair.first || other_pair.second<yl){
            return {*this};
        }
        if(yl<=other_pair.first && other_pair.second<=yr){
            return {Interval{x, yl, other_pair.first-1, open}, Interval{x, other_pair.second+1, yr, open}};
        }
        if(other_pair.first<= yl && yr<=other_pair.second){
            return {Interval{x, 0, -1, open}};
        }
        if(other_pair.first<=yl && other_pair.second<=yr){
            return {Interval{x, other_pair.second+1, yr, open}};
        }
        if(other_pair.first>=yl && other_pair.second>=yr){
            return {Interval{x, yl, other_pair.first-1, open}};
        }
        assert(false);
    }

    bool is_valid(){
        return yl<=yr;
    }
};

struct InterSet{
    set<Interval> intervals;
    bool is_valid = true;
    int last_valid = 1e18;
    void insert(Interval new_inter){
        //cout<<"inserting "<<new_inter.yl<<" "<<new_inter.yr<<endl;
        auto lb = intervals.upper_bound(new_inter);
        if(lb!=intervals.begin()){
            --lb;
        }
        auto rb = intervals.upper_bound(Interval{0, new_inter.yr, new_inter.yr, false});
        if(rb!= intervals.end()){
            ++rb;
        }
            
        vector<Interval> to_insert;
        for(auto it = lb; it!= rb;){
            Interval val = *it;
            it = intervals.erase(it);
            vector<Interval>resulting =  val.clip({new_inter.yl, new_inter.yr});
            for(auto val2: resulting){
                if(!new_inter.open){
                    if(pii({val.yl, val.yr}) != pii({val2.yl, val2.yr})){
                        if(is_valid && (new_inter.x-val.x)%2==1){
                            last_valid = new_inter.x-1;
                            ////cout<<"breaking is "<<new_inter.yl<<" "<<new_inter.yr<<endl;
                        }
                        is_valid &= (new_inter.x-val.x)%2==0;
                    }
                }
                
                if(val2.is_valid()){
                    to_insert.push_back(val2);
                }
            }
        }

        for(auto e: to_insert){
            intervals.insert(e);
        }
        if(new_inter.open){
            intervals.insert(new_inter);
        }
        //cout<<endl;
    }
};

signed main(){
    cin>>N>>M;
    vector<pt> pts;
    for(int i = 0; i<N; i++){
        int a, b;
        cin>>a>>b;
        pts.push_back({a, b});
    }

    vector<pair<pt, pt>> edges;
    pt prev= pts.back();
    for(int i = 0; i<N; i++){
        edges.push_back({prev, pts[i]-prev});
        prev = pts[i];
    } 
    
    int area = 0;

    for(auto e: edges){
        area += e.first.imag() * e.second.real();
    }

    if(area<0){
        for(pair<pt, pt>&edge : edges){
            edge = {edge.first+edge.second, -edge.second};
        }
    }

    vector<Interval> inters;
    for(auto e: edges){
        if(e.second.imag()!=0){
            if(e.second.imag()>0){
                inters.push_back(Interval{e.first.real(), e.first.imag(), e.first.imag()+e.second.imag()-1, true});
            }
            else if(e.second.imag()<0){
                inters.push_back(Interval{e.first.real(), e.first.imag()+e.second.imag(), e.first.imag()-1, false});
            }
        }
    }

    auto cmp = [&](Interval& a, Interval& b){
        return a.x<b.x;
    };

    sort(inters.begin(), inters.end(), cmp);
    vector<InterSet> inter_set(2);

    int k = 0;
    for(auto e: inters){
        if(inter_set[0].intervals.size()==0 || inter_set[1].intervals.size()==0){
            if(inter_set[0].is_valid && inter_set[1].is_valid){
                k = e.x-1;
            }
        }
        if(e.open){
            inter_set[e.x%2].insert(e);
        }
        else{
            inter_set[0].insert(e);
            inter_set[1].insert(e);
        }
        if(inter_set[0].intervals.size()==0 || inter_set[1].intervals.size()==0){
            if(inter_set[0].is_valid && inter_set[1].is_valid){
                k = e.x;
            }
        }
    }

    cout<<k<<endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 21 ms 4312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 58 ms 10532 KB Output is correct
3 Correct 65 ms 10556 KB Output is correct
4 Correct 90 ms 18516 KB Output is correct
5 Correct 96 ms 18484 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 141 ms 20732 KB Output is correct
9 Correct 143 ms 20788 KB Output is correct
10 Correct 143 ms 20536 KB Output is correct
11 Correct 144 ms 21036 KB Output is correct
12 Correct 141 ms 24360 KB Output is correct
13 Correct 147 ms 24616 KB Output is correct
14 Correct 149 ms 20788 KB Output is correct
15 Correct 132 ms 20588 KB Output is correct
16 Correct 126 ms 20808 KB Output is correct
17 Correct 155 ms 20792 KB Output is correct
18 Correct 191 ms 20792 KB Output is correct
19 Correct 160 ms 20960 KB Output is correct
20 Correct 177 ms 20720 KB Output is correct
21 Correct 141 ms 20532 KB Output is correct
22 Correct 150 ms 20868 KB Output is correct
23 Correct 143 ms 20372 KB Output is correct
24 Correct 140 ms 20528 KB Output is correct
25 Correct 133 ms 20300 KB Output is correct
26 Correct 152 ms 23140 KB Output is correct
27 Correct 121 ms 23080 KB Output is correct
28 Correct 142 ms 23716 KB Output is correct
29 Correct 129 ms 20792 KB Output is correct
30 Correct 145 ms 20928 KB Output is correct
31 Correct 135 ms 20720 KB Output is correct
32 Correct 147 ms 20740 KB Output is correct
33 Correct 114 ms 20788 KB Output is correct
34 Correct 52 ms 9792 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 416 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 436 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 344 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 0 ms 440 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 203 ms 21128 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 91 ms 19284 KB Output is correct
53 Correct 91 ms 18488 KB Output is correct
54 Correct 87 ms 18580 KB Output is correct
55 Correct 98 ms 18444 KB Output is correct
56 Correct 118 ms 18484 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 142 ms 20336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -