Advertisement
willy108

perimeter silver

Mar 14th, 2021
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <cmath>
  7. #include <cassert>
  8. #include <algorithm>
  9. #include <vector>
  10. #include <random>
  11. #include <chrono>
  12.  
  13. #define cont continue
  14. #define pow2(n) (1 << (n))
  15. #define ll long long
  16. #define pii pair<int, int>
  17. #define pb push_back
  18. #define mp make_pair
  19. #define lsb(n) ((n)&(-(n)))
  20. #define LC(n) (((n) << 1) + 1)
  21. #define RC(n) (((n) << 1) + 2)
  22. #define add(a, b) (((a)%mod + (b)%mod)%mod)
  23. #define mul(a, b) (((a)%mod * (b)%mod)%mod)
  24. #define init(arr, val) memset(arr, val, sizeof(arr))
  25. //geniousity limit exceeded
  26. #define moo printf
  27. #define oom scanf
  28. const ll mod = 1e9 + 7;
  29. const int MX = 1e3 +10, int_max = 0x3f3f3f3f;
  30. using namespace std;
  31.  
  32. void setIO(const string& file_name){
  33.     freopen((file_name+".in").c_str(), "r", stdin);
  34.     freopen((file_name+".out").c_str(), "w+", stdout);
  35. }
  36.  
  37. char arr[MX][MX];
  38. bool vis[MX][MX];
  39. int n, ar, A, P;
  40. int dfs(int x, int y){
  41.   if(x < 0 || y < 0 || x >= n || y >= n || arr[x][y] == '.') return 1;
  42.   if(vis[x][y]) return 0;
  43.   vis[x][y] = true;
  44.   ar++;
  45.   return dfs(x + 1, y) + dfs(x, y + 1) + dfs(x - 1, y) + dfs(x, y - 1);
  46. }
  47.  
  48.  
  49.  
  50. int main(){
  51.   cin.tie(0) -> sync_with_stdio(0);
  52.   setIO("perimeter");
  53.   oom("%d", &n);
  54.   for(int i = 0; i<n; i++){
  55.     scanf("%s", arr[i]);
  56.   }
  57.   A = 0, P = int_max;
  58.   for(int i = 0; i<n; i++){
  59.     for(int j = 0; j<n; j++){
  60.       if(!vis[i][j] && arr[i][j] == '#'){
  61.         ar = 0;
  62.         int res = dfs(i, j);
  63.         if(A < ar || (A == ar && P > res)){
  64.           P = res, A = ar;
  65.         }
  66.       }
  67.     }
  68.   }
  69.   moo("%d %d\n", A, P);
  70.     return 0;
  71. }
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement