fork(1) download
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5. int p[100][100], q[100][100], H, W, K;
  6. int chain() {
  7. int score = 0, cnt = 0;
  8. while (true) {
  9. int r = 0;
  10. for (int i = 0; i < H; i++) {
  11. int L = 0;
  12. for (int j = 0; j <= W; j++) {
  13. if (q[i][j] != q[i][L] || q[i][j] == 11) {
  14. if (j - L >= K) {
  15. for (int k = L; k < j; k++) { r += q[i][k]; q[i][k] = 11; }
  16. }
  17. L = j;
  18. }
  19. }
  20. }
  21. for (int i = 0; i < W; i++) {
  22. vector<int>W;
  23. for (int j = H - 1; j >= 0; j--) {
  24. if (q[j][i] <= 9)W.push_back(q[j][i]);
  25. }
  26. for (int j = H - 1; j >= 0; j--) { q[j][i] = 11; }
  27. for (int j = 0; j < W.size(); j++) { q[H - 1 - j][i] = W[j]; }
  28. }
  29. if (r == 0)return score;
  30. score += r*(1 << cnt); cnt++;
  31. }
  32. }
  33. int main() {
  34. cin >> H >> W >> K;
  35. for (int i = 0; i < H; i++) {
  36. for (int j = 0; j < W; j++) {
  37. char c; cin >> c;
  38. if (c == '.')p[i][j] = 11;
  39. else { p[i][j] = c - '0'; }
  40. }
  41. }
  42. int maxn = 0;
  43. for (int i = 0; i < H; i++) {
  44. for (int j = 0; j < W; j++) {
  45. if (p[i][j] == 11)continue;
  46. for (int k = 0; k < H; k++) {
  47. for (int l = 0; l < W; l++)q[k][l] = p[k][l];
  48. }
  49. q[i][j] = 11; vector<int>V;
  50. for (int k = H - 1; k >= 0; k--) { if (q[k][j] <= 9)V.push_back(q[k][j]); }
  51. for (int k = H - 1; k >= 0; k--) { q[k][j] = 11; }
  52. for (int k = 0; k < V.size(); k++) { q[H - 1 - k][j] = V[k]; }
  53. //cout << i << ' ' << j << ' ' << chain() << endl;
  54. maxn = max(maxn, chain());
  55. }
  56. }
  57. cout << maxn << endl;
  58. return 0;
  59. }
Success #stdin #stdout 0s 3552KB
stdin
7 7 2
8989898
9898989
8989898
9898989
8989898
9898989
8989898
stdout
2520