General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
143943114 Practice:
mkmeden
377A - 65 C++17 (GCC 7-32) Time limit exceeded on test 10 2000 ms 109004 KB 2022-01-25 10:27:39 2022-01-25 10:27:39
→ Source
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n)for(ll i=0;i<n;i++)
ull mod = 1e9 +7;

ull gcd(ull a, ull b)
{
  if (b == 0)
    return a;

  return gcd(b, a % b);
}

bool inside(ll i , ll j , ll r, ll c )
{
  return (i<r && i>=0 && j>=0 && j<c);
}

pair<int ,int >directions[4] = {{0,1} , {1,0}, {0,-1}, {-1 ,0}};



void solve()
{
  int n , m , k ;
  cin>>n>>m>>k;

  char arr[n][m];

  pair<int , int >p ;
  int ctr= 0 ;

  for(int i = 0 ;i<n ; i++)
  for(int j = 0 ; j<m ; j++)
  {
    cin>>arr[i][j];

    if(arr[i][j]=='.')
    {
      p.first=i;
      p.second=j;
      ctr++;
    }

    
  }


    if(k==0)
    {
      for(int i =  0 ; i<n ; i++)
      {
        for(int j = 0 ;j<m ;j++)
        cout<<arr[i][j];
        cout<<endl;
      }

        return ;

    }

  set<vector<int>>s ;

  queue<vector<int>>q; 
  q.push({p.first , p.second});

  while(q.empty()==false)
  {
    auto u = q.front();
    q.pop();
    s.insert(u);
    if(s.size()==ctr-k)
    break;

  
    for(auto x :directions)
    {
      int xi = x.first+u[0];
      int yi = x.second +u[1];

      if(inside(xi,yi ,n,m) && arr[xi][yi]=='.' && s.find({xi,yi})==s.end())
      q.push({xi,yi});
    }
    
  }

  for(int i = 0 ;i<n ;i++)
  for(int j = 0 ;j<m ;j++ )
  if(arr[i][j]=='.' && s.find({i,j})==s.end())
  arr[i][j]='X';

  for(int i =  0 ; i<n ; i++)
  {
    for(int j = 0 ;j<m ;j++)
    cout<<arr[i][j];
    cout<<endl;
  }

  
}


int main()
{

 // freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

  unsigned long long t=1;
  //cin >> t;

  while (t--)
  {
    solve();
  }
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details