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
| #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<long long, long long> pll; const int N=1e3+10; const int INF=2e9; int a[N][N]; vector<int>v; int check(int x,int y){
int l,r; for(auto i:v){ l=i/2000; r=i%2000; if(1ll*(x+l)*(y+r)!=a[l][r]) return 0; } return 1; } void solve(){ int n,i,j,m,x,y,k,l,r; cin>>n>>m; v.clear(); l=1,r=1; int cnt=0; x=0; while(cnt<n*m){ char c=getchar(); if(c=='?') cnt++,x=0,r++; else if(c>='0'&&c<='9') x=x*10+c-'0'; else if(x>0) a[l][r]=x,v.push_back(l*2000+r),x=0,cnt++,r++; if(r==m+1) r=1,l++; } if(v.size()==0){ puts("Yes"); return; } int x1,x2,y1,y2; if(v.size()==1){ x1=v[0]/2000; y1=v[0]%2000; l=a[x1][y1]; for(i=1;i*i<=l;i++){ if(l%i) continue; x=i,y=l/i; if(x>=x1&&y>=y1){ puts("Yes"); return; } x=l/i,y=i; if(x>=x1&&y>=y1){ puts("Yes"); return; } } puts("No"); return; } x1=v[0]/2000; y1=v[0]%2000; x2=v[1]/2000; y2=v[1]%2000; l=a[x1][y1]; r=a[x2][y2]; for(i=1;i*i<=l;i++){ if(l%i) continue; x=i,y=l/i; x-=x1,y-=y1; if(1ll*(x+x2)*(y+y2)==r){ if(x<0||y<0); else if(check(x,y)){ puts("Yes"); return; } } x=l/i,y=i; x-=x1,y-=y1; if(1ll*(x+x2)*(y+y2)==r){ if(x<0||y<0); else if(check(x,y)){ puts("Yes"); return; } } } puts("No"); }
int main() { int T=1; cin>>T; for(int i=1;i<=T;i++) { printf("Case #%d: ", i); solve(); } }
|