#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define DEBUG(codx1) cout << '>' << #codx1 << ':' << codx1 << endl; #define REP(i,n) for(int i=0;i<(n);i++) #define FOR(i,vecc2,b) for(int i=(vecc2);i<=(b);i++) #define FORD(i,vecc2,b) for(int i=(vecc2);i>=(b);i--) inline bool EQ(double vecc2, double b) { return fabs(vecc2-b) < 1e-9; } const int mod=1000000007; typedef long long ll; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n>>b)&1; } inline void set_bit(int & n, int b) { n |= two(b); } inline void unset_bit(int & n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int resultAns = 0; while(n && ++resultAns) n-=n&(-n); return resultAns; } template void chmax(T & vecc2, const T & b) { vecc2 = max(vecc2, b); } template void chmin(T & vecc2, const T & b) { vecc2 = min(vecc2, b); } #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << std::endl; } template void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } #else #define trace(...) #endif #define si(codx1) scanf("%i",&codx1) #define sll(codx1) scanf("%lld",&codx1) #define pi(codx1) printf("%i\n",codx1) #define F first #define S second #define PB push_back #define MP make_pair typedef long long LL; typedef pair PII; typedef vector VI; typedef vector VPII; inline void add(int &codx1, int cody1){codx1+=cody1; if(codx1>=mod)codx1-=mod; if(codx1<0)codx1+=mod;} inline int mul(int codx1, int cody1){ return ((LL)codx1 * cody1)%mod;} int gcd(int vecc2, int b){ if(b)return gcd(b,vecc2%b); return vecc2;} int power(int vecc2 ,int p){int ret = 1; while(p){if(p&1)ret=mul(ret,vecc2); vecc2=mul(vecc2,vecc2); p/=2;}return ret;} #define lld long double #define MOD 1000000007 using namespace std; const int INF=1000000000; const lld EPS=1e-9; int indx[25][25]; char used[25][25]; char grid[25][25]; int mazes[25][25]; int N=0; int n,m; lld vecc2[407][407]; lld crrr[407]; int geti(int codx1, int cody1) { if(indx[codx1][cody1]==-1) { indx[codx1][cody1]=N; N++; } return indx[codx1][cody1]; } int gTy(int codx1, int cody1) { if (codx1<0 || codx1>=n || cody1<0 || cody1>=m) return 1; if (grid[codx1][cody1]=='O' || grid[codx1][cody1]=='A') return 0; if (grid[codx1][cody1]=='#') return 1; if (grid[codx1][cody1]=='%') return 2; if (grid[codx1][cody1]=='*') return 3; return 100; } void depth(int codx1, int cody1) { int xnum1=codx1; int ynum1=cody1; if(codx1<0 || codx1>=n || cody1<0 || cody1>=m || used[codx1][cody1]==1 || gTy(codx1,cody1)!=0) return; used[codx1][cody1]=1; int jj1 = geti(codx1,cody1); int h=0,r=0; if(mazes[codx1][cody1]!=-1) { xnum1 = mazes[codx1][cody1]/100; ynum1 = mazes[codx1][cody1]%100; } if(gTy(xnum1-1,ynum1)!=1)h++; if(gTy(xnum1,ynum1-1)!=1)h++; if(gTy(xnum1+1,ynum1)!=1)h++; if(gTy(xnum1,ynum1+1)!=1)h++; if(gTy(xnum1-1,ynum1)==2)r++; if(gTy(xnum1,ynum1-1)==2)r++; if(gTy(xnum1+1,ynum1)==2)r++; if(gTy(xnum1,ynum1+1)==2)r++; if(h==0) { vecc2[jj1][jj1]=1; return; } if(gTy(xnum1-1,ynum1)==0) vecc2[jj1][geti(xnum1-1,ynum1)]=-1; if(gTy(xnum1,ynum1-1)==0) vecc2[jj1][geti(xnum1,ynum1-1)]=-1; if(gTy(xnum1+1,ynum1)==0) vecc2[jj1][geti(xnum1+1,ynum1)]=-1; if(gTy(xnum1,ynum1+1)==0) vecc2[jj1][geti(xnum1,ynum1+1)]=-1; vecc2[jj1][jj1]+=h; crrr[jj1]=r; depth(xnum1-1,ynum1); depth(xnum1,ynum1-1); depth(xnum1+1,ynum1); depth(xnum1,ynum1+1); } int phyGa (vector < vector > vecc2, vector & vecc) { int n = (int) vecc2.size(); int m = (int) vecc2[0].size() - 1; vector ggc (m, -1); for (int tt2=0, row=0; tt2 abs (vecc2[tt1][tt2])) tt1 = i; if (abs (vecc2[tt1][tt2]) < EPS) continue; for (int i=tt2; i<=m; ++i) swap (vecc2[tt1][i], vecc2[row][i]); ggc[tt2] = row; for (int i=0; i EPS) return 0; } for (int i=0; i>n >> m >> k; for(i=0;i> grid[i]; for(i=0;i vecc; vector > aa; aa.resize(N); for(int i=0;i