Submission

Status:

[PP][PP][PPP][PPP][PPP][PPPPP][PPPPPPP][PPPP][PPPP][PPPPP]

Subtask/Task Score:

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

Score: 100

User: anonymous

Problemset: ช่องบนไม้

Language: cpp

Time: 0.251 second

Submitted On: 2026-10-27 10:11:39

#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 = -l; 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;
}