Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f("panda.in");
- ofstream g("panda.out");
- bool complementare(int a, int b, int s)
- {
- bitset<8> aBin;
- bitset<8> bBin;
- int i = 0;
- int j = 0;
- int aux = 8;
- while(aux!=0)
- {
- --aux;
- aBin[i++] = a%2;
- a/=2;
- }
- aux = 8;
- while(aux!=0)
- {
- --aux;
- bBin[j++] = b%2;
- b/=2;
- }
- for(int z = 0; z<s; ++z)
- {
- if(aBin[z]==0 && bBin[z]==0) return false;
- if(aBin[z]==1 && bBin[z]==1) return false;
- }
- return true;
- }
- struct {
- int lin;
- int col;
- }C[10001],ps,pf;
- int p,n,m,t,i,j,v[1001][1001],l,c,k,s,a[1001][1001],x,P,pm,um,K,dl[]={-1,0,1,0},dc[]={0,1,0,-1},vc;
- int main()
- {
- f>>P;
- f>>n>>m>>t;
- f>>l>>c>>k>>s;
- for(i=1;i<=t;++i)
- for(j=1;j<=2;++j)
- f>>a[i][j];
- for(i=1;i<=n;++i)
- for(j=1;j<=m;++j)
- f>>v[i][j];
- if(P==1){
- for(i=1;i<=n;++i){
- for(j=1;j<=m;++j){
- if(complementare(v[i][j],k,s)) x++;
- }
- }
- g<<x-1;
- }
- else{
- for(i=0;i<=n+1;++i)
- v[i][0]=v[i][m+1]=-1;
- for(j=0;j<=m+1;j++)
- v[0][j]=v[n+1][j]=-1;
- pm=um=0;
- C[0]=ps;
- v[ps.lin][ps.col]=1;
- while(pm<=um && v[pf.lin][pf.col]==0){
- p=C[pm];
- pm++;
- for(K=0;K<4;k++){
- vc.lin=p.lin+dl[k]; vc.col=p.col+dc[p];
- if(v[vc.lin][vc.col]==0){
- v[vc.lin][vc.col]=v[p.lin][p.col]+1;
- um++;C[um]=vc;
- }
- }
- }
- cout<<v[pf.lin][pf.col];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement