Submission

Status:

[P-][P-][PPP][PPP][PPP][PPPPP][PPP-SSS][PP-S][PP-S][PPP-S]

Subtask/Task Score:

{0/10}{0/10}{10/10}{10/10}{10/10}{10/10}{0/10}{0/10}{0/10}{0/10}

Score: 40

User: anonymous

Problemset: ช่องบนไม้

Language: cpp

Time: 0.164 second

Submitted On: 2026-10-27 10:01:34

#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n,w,l; cin >> n >> w >> l;
    vector<set<int>> pos(n);

    for(int i=0;i<n;i++){
        int k; cin >> k;
        set<int> cur;
        for(int j=0;j<k;j++){
            int hole; cin >> hole;
            for(int k=-1;k<=l;k++){
                int p = hole + k;
                if(p >= 1 && p <= w) cur.insert(p);
            }
        }
        if(cur.empty()){
            cout << 0;
            return 0;
        }
        pos[i] = move(cur);
    }

    set<int> ans = pos[0];
    for(int i=1;i<n;i++){
        set<int> nex;
        auto a = ans.begin();
        auto b = pos[i].begin();
        while (a != ans.end() && b != pos[i].end()){
            if(*a < *b)a++;
            else if(*b < *a)b++;
            else{
                nex.insert(*a);
                a++;
                b++;
            }
        }
        ans = move(nex);
        if(ans.empty()){
            cout << 0;
            return 0;
        }
    }
    cout << 1;
}