Sanath12345

Untitled

Jun 26th, 2021
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. //Problem link :
  2. //CREDITS : sanath kumar
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5. #define ll long long int
  6. #define ld long double
  7. #define mod 1000000007
  8. #define inf 1e9
  9. #define endl "\n"
  10. #define pb push_back
  11. #define vi vector<ll>
  12. #define vs vector<string>
  13. #define pii pair<ll,ll>
  14. #define ump unordered_map
  15. #define mp make_pair
  16. #define pq_max priority_queue<ll>
  17. #define pq_min priority_queue<ll,vector<ll>,greater<ll>>
  18. #define all(v) v.begin(),v.end()
  19. #define ff first
  20. #define ss second
  21. #define mid(l,r) (l+(r-l))/2
  22. #define bitc(x) __builtin_popcount(x)
  23. #define read(a,n) for(int i=1;i<=n;i++) cin>>a[i];
  24. #define print_(a,x,y) {for(int i=x;i<=y;i++) cout<<a[i]<<" ";cout<<endl;}
  25. #define loop(i,a,b) for(int i=(a);i<=(b);i++)
  26. #define looprev(i,a,b) for(int i=(a);i>=(b);i--)
  27. #define iter(c,it) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
  28. #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  29. #define log(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
  30. #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
  31. template<typename T> T gcd(T a,T b) {if(b==0) return a; return gcd(b,a%b);}
  32. template<typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
  33. ll add(ll a,ll b) {return ((a%mod)+(b%mod))%mod;}
  34. ll sub(ll a,ll b) {return ((a%mod)-(b%mod)+mod)%mod;}
  35. ll mul(ll a,ll b) {return ((a%mod)*(b%mod))%mod;}
  36.  
  37. void err(istream_iterator<string> it){}
  38. template<typename T,typename... Args>
  39. void err(istream_iterator<string> it,T a,Args... args){
  40. cout<<*it<<" = "<<a<<endl;
  41. err(++it,args...);
  42. }
  43. ll *getfactorial(){
  44. int m=1e6;
  45. ll *fact=new ll[m+1];
  46. fact[0]=1;
  47. loop(i,1,m){
  48. fact[i]=(fact[i-1]*i)%mod;
  49. }
  50. // time complexity O(n)
  51. return fact;
  52. }
  53. vi *getfactors(){
  54. int n=3e3;
  55. vi *factors=new vi[n+5];
  56. loop(i,1,n){
  57. for(int j=i;j<=n;j+=i){
  58. factors[j].pb(i);
  59. }
  60. }
  61. // time complexity O(nlogn)
  62. return factors;
  63. }
  64. ll power(ll a,ll b,ll m=mod){
  65. if(b==0) return 1;
  66. ll smallans=power(a,b/2,m);
  67. ll ans=(smallans*smallans)%m;
  68. if(b%2==1){
  69. ans=(ans*a)%m;
  70. }
  71. return ans;
  72. // time complexity O(logb)
  73. }
  74. bool *isprime(){
  75. int m=1e6;
  76. bool *p=new bool[m+5];
  77. loop(i,0,m) p[i]=true;
  78. p[0]=false;
  79. p[1]=false;
  80. loop(i,2,sqrt(m)){
  81. for(int j=2*i;j<=m;j+=i){
  82. p[j]=false;
  83. }
  84. }
  85. // time complexity O(nlogn)
  86. return p;
  87. }
  88. ll nCr(ll n,ll r,int m=mod){
  89. if(n<r) return 0;
  90. ll *fac=getfactorial();
  91. ll ans=fac[n];
  92. ans=(ans*power(fac[n-r],m-2))%m;
  93. ans=(ans*power(fac[r],m-2))%m;
  94. return ans;
  95. }
  96.  
  97. //==================START==================
  98.  
  99. int n,m,k;
  100. pii dp[2][1005][1005];
  101. void getpref(){
  102. loop(i,1,n){
  103. loop(j,1,m){
  104. dp[0][i][j].ff+=dp[0][i-1][j].ff+dp[0][i][j-1].ff-dp[0][i-1][j-1].ff;
  105. }
  106. }
  107. loop(i,1,n){
  108. loop(j,1,m){
  109. dp[1][i][j].ff+=dp[1][i-1][j].ff+dp[1][i][j-1].ff-dp[1][i-1][j-1].ff;
  110. }
  111. }
  112. }
  113. ll earliset(int p){
  114. ll ans=INT_MAX;
  115. loop(i,k,n){
  116. loop(j,k,m){
  117. int z=dp[p][i][j].ff-dp[p][i-k][j].ff-dp[p][i][j-k].ff+dp[p][i-k][j-k].ff;
  118. // cout<<p<<" "<<i<<" "<<j<<" "<<z<<endl;
  119. if(z==k*k){
  120. ll res=INT_MIN;
  121. loop(x,i-k+1,i){
  122. loop(y,j-k+1,j){
  123. res=max(res,dp[p][x][y].ss);
  124. }
  125. }
  126. ans=min(ans,res);
  127. }
  128. }
  129. }
  130. return ans;
  131. }
  132. int main(){
  133. boost
  134. int t;
  135. cin>>t;
  136. while(t--){
  137. cin>>n>>m>>k;
  138. loop(z,0,1){
  139. loop(i,0,n){
  140. loop(j,0,m){
  141. dp[z][i][j].ff=0;
  142. dp[z][i][j].ss=0;
  143. }
  144. }
  145. }
  146. loop(i,1,n*m){
  147. int x,y;
  148. cin>>x>>y;
  149. if(i%2==1){
  150. dp[0][x][y]={1,i};
  151. }
  152. else{
  153. dp[1][x][y]={1,i};
  154. }
  155. }
  156. getpref();
  157. ll a=earliset(0);
  158. ll b=earliset(1);
  159. // log(a,b);
  160. if(a==INT_MAX and b==INT_MAX) cout<<"Draw"<<endl;
  161. else{
  162. if(a<b) cout<<"Alice"<<endl;
  163. else cout<<"Bob"<<endl;
  164. }
  165. }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment