Advertisement
Rofyda_Elghadban1

Untitled

Jan 20th, 2024
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.95 KB | None | 0 0
  1.  #include <bits/stdc++.h>
  2.  #define ll long long
  3.  #define ull unsigned long long
  4.  #define pi 3.141592654
  5.  #define NUM 1e18
  6.  #define Mod  1'000'000'007
  7.  #define fixed(n) fixed<<setprecision(n)
  8.  #define cin(v) for(auto &i:v) cin >> i ;
  9.  #define cout(v) for(auto &i:v) cout << i  <<" ";
  10.  #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  11.  #define small(x) (x>=97&&x<=122)
  12.  #define capital(x) (x>=65&&x<=90)
  13.  #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  14.  #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  15.  #define sz(x) (int)(x.size())
  16.  #define all(v) ((v).begin()), ((v).end())
  17.  #define allr(v) ((v).rbegin()), ((v).rend())
  18.  #define updmax(a,b) a=max(a,b)
  19.  #define updmin(a,b) a=min(a,b)
  20.  #define ceil(a,b) ((a/b)+(a%b?1:0))
  21.  /* asc -> 1 2 3 ,des -> 3 2 1 */
  22.  
  23.  /***********************************************************************************/
  24.  using namespace std;
  25.  void Rofyda_Elghadban(){
  26.   #ifndef ONLINE_JUDGE  
  27.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  28.    #endif
  29.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  30.  }
  31.  
  32.  void solve(){
  33.   int n,m,k,counter1=0,counterdot1=0,mini1=INT_MAX,c1=0,counter2=0,counterdot2=0,mini2=INT_MAX,c2=0;
  34.   cin>>n>>m>>k;
  35.   char arr[n][m];
  36.   for(int i=0;i<n;i++){
  37.     for(int j=0;j<m;j++){
  38.       cin>>arr[i][j];
  39.     }
  40.   }
  41.   for(int i=0;i<n;i++){
  42.     for(int j=0;j<m;j++){
  43.       if(counter1==k){
  44.         c1++;
  45.       }
  46.       if((arr[i][j]=='.'||arr[i][j]=='o')&&counter1!=k){
  47.         counter1++;
  48.         if(arr[i][j]=='.'){
  49.           counterdot1++;
  50.         }
  51.       }else if((arr[i][j]=='.'||arr[i][j]=='o')&&counter1==k){
  52.         mini1=min(mini1,counterdot1);
  53.         if(arr[i][j-k]=='.'&&arr[i][j]=='.'){
  54.           continue;
  55.         }else{
  56.           counterdot1++;
  57.         }
  58.       }else if(arr[i][j]=='x'){
  59.         if(counter1==k){
  60.           mini1=min(mini1,counterdot1);
  61.           counterdot1=0;
  62.           counter1=0;
  63.         }
  64.       }
  65.     }
  66.     counterdot1=0;
  67.     counter1=0;
  68.   }
  69.   for(int i=0;i<m;i++){
  70.     for(int j=0;j<n;j++){
  71.       if(counter2==k){
  72.         c2++;
  73.       }
  74.       if((arr[j][i]=='.'||arr[j][i]=='o')&&counter2!=k){
  75.         counter2++;
  76.         if(arr[j][i]=='.'){
  77.           counterdot2++;
  78.         }
  79.       }else if((arr[j][i]=='.'||arr[j][i]=='o')&&counter2==k){
  80.         mini2=min(mini2,counterdot2);
  81.         if(arr[j][i-k]=='.'&&arr[j][i]=='.'){
  82.           continue;
  83.         }else{
  84.           counterdot2++;
  85.         }
  86.       }else if(arr[j][i]=='x'){
  87.         if(counter2==k){
  88.           mini2=min(mini2,counterdot2);
  89.           counterdot2=0;
  90.           counter2=0;
  91.         }
  92.       }
  93.     }
  94.     counterdot2=0;
  95.     counter2=0;
  96.   }
  97.   if(c1==0&&c2==0){
  98.     cout<<-1<<"\n";
  99.     return;
  100.   }
  101.   cout<<min(mini1,mini2)<<"\n";
  102.  }
  103.  
  104.  int main(){
  105.   Rofyda_Elghadban();
  106.   // int t;
  107.   // cin>>t;
  108.   // while(t--){
  109.   //   solve();
  110.   // }
  111.   solve();
  112.   return 0;
  113.  }
  114.  
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement