Submission #1079426

# Submission time Handle Problem Language Result Execution time Memory
1079426 2024-08-28T14:26:26 Z anton Tiles (BOI24_tiles) C++17
46 / 100
254 ms 23464 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;
    }

    int len() const{
        return yr-yl+1;
    }
};
Interval merge_inter(Interval a, Interval b){
    return Interval{a.x, a.yl, b.yr, true};
}
struct InterSet{
    set<Interval> intervals;
    bool is_valid = true;
    int nb_unpair= 0;
    
    void insert_small(Interval new_inter){
        if((new_inter.len())%2 ==1){
            nb_unpair++;
        }
        intervals.insert(new_inter);
    }
    std::set<Interval>::iterator merge(std::set<Interval>::iterator a, std::set<Interval>::iterator b){
        if(a->yr+1 == b->yl){
            Interval ia = *a;
            Interval ib = *b;
            erase(a);
            erase(b);
            Interval result =merge_inter(ia, ib);
            insert_small(result);
            return intervals.find(result);
        }
        return a;
    }
    void insert(Interval new_inter){
        insert_small(new_inter);
        auto it = intervals.find(new_inter);
        if(it!=intervals.begin()){
            auto prev= it;
            --prev;
            it = merge(prev, it);
        }
        auto next = it;
        next++;
        if(next!=intervals.end()){
            it = merge(it, next);
        }
    }
    std::set<Interval>::iterator erase(std::set<Interval>::iterator it){
        if(((*it).len())%2==1){
            nb_unpair--;
        }
        return intervals.erase(it);
    }
    
    void insert_big(Interval new_inter){
        //cout<<"inserting "<<new_inter.yl<<" "<<new_inter.yr<<endl;

        for(auto e: intervals){
            //cout<<e.yl<<" "<<e.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 = 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})){
                        is_valid &= (new_inter.x-val.x)%2==0;
                    }
                }
                
                if(val2.is_valid()){
                    to_insert.push_back(val2);
                }
            }
        }

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

        //cout<<nb_unpair<<endl;
        ////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;
    Interval prev_inter = Interval{0, 0, 0, true};
    for(auto e: inters){
        if(e.x!=prev_inter.x){
            //cout<<"nb_unpair: "<<inter_set[0].nb_unpair<<" "<<inter_set[1].nb_unpair<<endl;
            for(int i= 0; i<2; i++){
                inter_set[i].is_valid &= (inter_set[i].nb_unpair ==0);
            }
        }
        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_big(e);
        }
        else{
            inter_set[0].insert_big(e);
            inter_set[1].insert_big(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;
            }
        }
        prev_inter = e;
    }

    cout<<k<<endl;
}

Compilation message

Main.cpp: In member function 'void InterSet::insert_big(Interval)':
Main.cpp:98:18: warning: variable 'e' set but not used [-Wunused-but-set-variable]
   98 |         for(auto e: intervals){
      |                  ^
Main.cpp:135:18: warning: variable 'e' set but not used [-Wunused-but-set-variable]
  135 |         for(auto e: intervals){
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 436 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 27 ms 4224 KB Output is correct
3 Correct 117 ms 19768 KB Output is correct
4 Correct 59 ms 10308 KB Output is correct
5 Correct 63 ms 10308 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 135 ms 20348 KB Output is correct
9 Correct 71 ms 11612 KB Output is correct
10 Correct 150 ms 20276 KB Output is correct
11 Correct 95 ms 9532 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 128 ms 20528 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 116 ms 18432 KB Output is correct
6 Correct 140 ms 18488 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Incorrect 6 ms 1212 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 64 ms 10300 KB Output is correct
3 Correct 70 ms 10468 KB Output is correct
4 Correct 120 ms 18540 KB Output is correct
5 Correct 117 ms 18448 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 176 ms 20116 KB Output is correct
9 Correct 186 ms 20140 KB Output is correct
10 Correct 166 ms 19936 KB Output is correct
11 Correct 191 ms 20024 KB Output is correct
12 Correct 182 ms 20032 KB Output is correct
13 Correct 158 ms 20400 KB Output is correct
14 Correct 137 ms 20204 KB Output is correct
15 Correct 142 ms 20020 KB Output is correct
16 Correct 132 ms 19952 KB Output is correct
17 Correct 203 ms 20240 KB Output is correct
18 Correct 254 ms 20140 KB Output is correct
19 Correct 192 ms 20292 KB Output is correct
20 Correct 199 ms 20292 KB Output is correct
21 Correct 182 ms 19940 KB Output is correct
22 Correct 181 ms 20332 KB Output is correct
23 Correct 163 ms 20060 KB Output is correct
24 Correct 164 ms 20024 KB Output is correct
25 Correct 167 ms 19996 KB Output is correct
26 Correct 202 ms 22984 KB Output is correct
27 Correct 156 ms 23048 KB Output is correct
28 Correct 168 ms 23464 KB Output is correct
29 Correct 162 ms 20404 KB Output is correct
30 Correct 184 ms 20196 KB Output is correct
31 Correct 151 ms 20032 KB Output is correct
32 Correct 176 ms 20280 KB Output is correct
33 Correct 131 ms 20268 KB Output is correct
34 Correct 61 ms 9608 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 246 ms 20464 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 105 ms 18980 KB Output is correct
53 Correct 113 ms 18492 KB Output is correct
54 Correct 110 ms 18496 KB Output is correct
55 Correct 108 ms 18540 KB Output is correct
56 Correct 120 ms 18492 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 19608 KB Output is correct
2 Correct 72 ms 10324 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 135 ms 20336 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 145 ms 20172 KB Output is correct
7 Incorrect 1 ms 604 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 432 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 436 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 27 ms 4224 KB Output is correct
34 Correct 117 ms 19768 KB Output is correct
35 Correct 59 ms 10308 KB Output is correct
36 Correct 63 ms 10308 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 135 ms 20348 KB Output is correct
40 Correct 71 ms 11612 KB Output is correct
41 Correct 150 ms 20276 KB Output is correct
42 Correct 95 ms 9532 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 128 ms 20528 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 344 KB Output is correct
49 Correct 0 ms 344 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 344 KB Output is correct
53 Correct 116 ms 18432 KB Output is correct
54 Correct 140 ms 18488 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Incorrect 6 ms 1212 KB Output isn't correct
59 Halted 0 ms 0 KB -