HDU 5972 Regular Number

Regular Number
思路:
shifit and算法
代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int N = 1000 + 10, M = 5e6 + 10;
char s[M];
bitset<N> f[10], g;
int t, x, n;
int main() {
    while(~scanf("%d", &n)) {
        for (int i = 0; i < 10; ++i) f[i].reset();
        g.reset();
        for (int i = 0; i < n; ++i) {
            scanf("%d", &t);
            while(t--){
                scanf("%d", &x);
                f[x].set(i);
            }
        }
        scanf("%s", s);
        int l = strlen(s);
        for (int i = 0; i < l; ++i) {
            g = g<<1;
            g.set(0);
            g &= f[s[i]-'0'];
            if(g[n-1]) {
                char tmp = s[i+1];
                s[i+1] = '\0';
                puts(s+i+1-n);
                s[i+1] = tmp;
            }
        }
    }
    return 0;
}

posted @ 2019-10-13 19:51  Wisdom+.+  阅读(127)  评论(0编辑  收藏  举报