#include <bits/stdc++.h> using namespace std; int n; int b, r; bitset <227> mac[227]; char wcz[227]; bitset <227> maska[23][70000]; int d=15; bitset <227> teraa, terb; bitset <227> cel; bitset <227> pus; bitset <227> zak; int x; void suna() { cel=pus; for (int i=0; i<n; i+=d) { x=0; for (int j=0; j<d; j++) { x+=((int)teraa[i+j]<<j); } cel|=maska[i/d][x]; } teraa=cel; } void sunb() { cel=pus; for (int i=0; i<n; i+=d) { x=0; for (int j=0; j<d; j++) { x+=((int)terb[i+j]<<j); } cel|=maska[i/d][x]; } terb=cel; } int main() { scanf("%d%d%d", &n, &b, &r); for (int i=0; i<n; i++) { scanf("%s", wcz); for (int j=0; j<n; j++) { mac[i][j]=(wcz[j]=='1'); } } for (int i=0; i<n; i+=d) { for (int j=0; j<(1<<d); j++) { for (int l=0; l<d; l++) { if (j&(1<<l)) { maska[i/d][j]|=mac[i+l]; } } } } for (int i=b; i<n; i++) zak[i]=1; while(r--) { scanf("%d", &x); teraa[x-1]=1; } terb=teraa; for (int i=0; 1; i++) { if ((teraa&zak)==pus) { printf("%d\n", 2*i); return 0; } suna(); if ((teraa&zak)==pus) { printf("%d\n", 2*i+1); return 0; } suna(); sunb(); if (teraa==terb) { break; } } printf("-1\n"); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #include <bits/stdc++.h> using namespace std; int n; int b, r; bitset <227> mac[227]; char wcz[227]; bitset <227> maska[23][70000]; int d=15; bitset <227> teraa, terb; bitset <227> cel; bitset <227> pus; bitset <227> zak; int x; void suna() { cel=pus; for (int i=0; i<n; i+=d) { x=0; for (int j=0; j<d; j++) { x+=((int)teraa[i+j]<<j); } cel|=maska[i/d][x]; } teraa=cel; } void sunb() { cel=pus; for (int i=0; i<n; i+=d) { x=0; for (int j=0; j<d; j++) { x+=((int)terb[i+j]<<j); } cel|=maska[i/d][x]; } terb=cel; } int main() { scanf("%d%d%d", &n, &b, &r); for (int i=0; i<n; i++) { scanf("%s", wcz); for (int j=0; j<n; j++) { mac[i][j]=(wcz[j]=='1'); } } for (int i=0; i<n; i+=d) { for (int j=0; j<(1<<d); j++) { for (int l=0; l<d; l++) { if (j&(1<<l)) { maska[i/d][j]|=mac[i+l]; } } } } for (int i=b; i<n; i++) zak[i]=1; while(r--) { scanf("%d", &x); teraa[x-1]=1; } terb=teraa; for (int i=0; 1; i++) { if ((teraa&zak)==pus) { printf("%d\n", 2*i); return 0; } suna(); if ((teraa&zak)==pus) { printf("%d\n", 2*i+1); return 0; } suna(); sunb(); if (teraa==terb) { break; } } printf("-1\n"); return 0; } |