Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- #define pi 3.141592654
- #define NUM 1e18
- #define Mod 1'000'000'007
- #define fixed(n) fixed<<setprecision(n)
- #define cin(v) for(auto &i:v) cin >> i ;
- #define cout(v) for(auto &i:v) cout << i <<" ";
- #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
- #define small(x) (x>=97&&x<=122)
- #define capital(x) (x>=65&&x<=90)
- #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
- #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
- #define sz(x) (int)(x.size())
- #define all(v) ((v).begin()), ((v).end())
- #define allr(v) ((v).rbegin()), ((v).rend())
- #define updmax(a,b) a=max(a,b)
- #define updmin(a,b) a=min(a,b)
- #define ceil(a,b) ((a/b)+(a%b?1:0))
- /* asc -> 1 2 3 ,des -> 3 2 1 */
- /***********************************************************************************/
- using namespace std;
- void Rofyda_Elghadban(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- }
- void solve(){
- int n,m,k,counter1=0,counterdot1=0,mini1=INT_MAX,c1=0,counter2=0,counterdot2=0,mini2=INT_MAX,c2=0;
- cin>>n>>m>>k;
- char arr[n][m];
- for(int i=0;i<n;i++){
- for(int j=0;j<m;j++){
- cin>>arr[i][j];
- }
- }
- for(int i=0;i<n;i++){
- for(int j=0;j<m;j++){
- if(counter1==k){
- c1++;
- }
- if((arr[i][j]=='.'||arr[i][j]=='o')&&counter1!=k){
- counter1++;
- if(arr[i][j]=='.'){
- counterdot1++;
- }
- }else if((arr[i][j]=='.'||arr[i][j]=='o')&&counter1==k){
- mini1=min(mini1,counterdot1);
- if(arr[i][j-k]=='.'&&arr[i][j]=='.'){
- continue;
- }else{
- counterdot1++;
- }
- }else if(arr[i][j]=='x'){
- if(counter1==k){
- mini1=min(mini1,counterdot1);
- counterdot1=0;
- counter1=0;
- }
- }
- }
- counterdot1=0;
- counter1=0;
- }
- for(int i=0;i<m;i++){
- for(int j=0;j<n;j++){
- if(counter2==k){
- c2++;
- }
- if((arr[j][i]=='.'||arr[j][i]=='o')&&counter2!=k){
- counter2++;
- if(arr[j][i]=='.'){
- counterdot2++;
- }
- }else if((arr[j][i]=='.'||arr[j][i]=='o')&&counter2==k){
- mini2=min(mini2,counterdot2);
- if(arr[j][i-k]=='.'&&arr[j][i]=='.'){
- continue;
- }else{
- counterdot2++;
- }
- }else if(arr[j][i]=='x'){
- if(counter2==k){
- mini2=min(mini2,counterdot2);
- counterdot2=0;
- counter2=0;
- }
- }
- }
- counterdot2=0;
- counter2=0;
- }
- if(c1==0&&c2==0){
- cout<<-1<<"\n";
- return;
- }
- cout<<min(mini1,mini2)<<"\n";
- }
- int main(){
- Rofyda_Elghadban();
- // int t;
- // cin>>t;
- // while(t--){
- // solve();
- // }
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement