fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n;
  4. char a[65][65];
  5. string quard(int y, int x, int size){
  6. if(size == 1) return string(1, a[y][x]);
  7. string ret = "";
  8. char target = a[y][x];
  9. bool cn = false;
  10. for(int i = y; i < y + size; i++){
  11. for(int j = x; j < x + size; j++){
  12. if(target != a[i][j]) true;
  13. }
  14. }
  15. if(cn) {
  16. ret += "(";
  17. ret += quard(y, x, size / 2);
  18. ret += quard(y, x + size / 2, size / 2);
  19. ret += quard(y + size / 2, x, size / 2);
  20. ret += quard(y + size / 2, x + size / 2, size / 2);
  21. ret += ")";
  22. return ret;
  23. }
  24. return string(1, a[y][x]);
  25. }
  26. int main(){
  27. cin >> n;
  28. for(int i = 0; i < n; i++){
  29. for(int j = 0; j < n; j++){
  30. cin >> a[i][j];
  31. }
  32. }
  33. cout << quard(0, 0, n) << '\n';
  34. }
Success #stdin #stdout 0s 5312KB
stdin
8
11110000
11110000
00011100
00011100
11110000
11110000
11110011
11110011
stdout
1