fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int baris, kolom, lantai;
  6. bool masihsatu = true;
  7. cin >> baris >> kolom;
  8.  
  9. vector<vector<int>> kotak(baris, vector<int>(kolom));
  10. for (int a = 0; a < baris; a++) {
  11. for (int b = 0; b < kolom; b++) {
  12. char input;
  13. cin >> input;
  14. kotak[a][b] = input - '0';
  15.  
  16. if (masihsatu && kotak[a][b] == 1) {
  17. if (b > kolom - 2) {
  18. for (int c = 0; c < kolom; c++) {
  19. kotak[a][c] = 0;
  20. lantai = a + 1;
  21. }
  22. }
  23. } else {
  24. masihsatu = false;
  25. }
  26. }
  27. masihsatu = true;
  28. }
  29.  
  30. vector<int> batas(kolom);
  31. int target;
  32. for (int a = 0; a < kolom; a++) {
  33. batas[a] = lantai;
  34. while (batas[a] < baris && kotak[batas[a]][a] == 0) {
  35. batas[a]++;
  36. }
  37.  
  38. target = batas[a];
  39. for (int c = 0; c < batas[a]; c++) {
  40. if (kotak[c][a] == 1) {
  41. kotak[c][a] = 0;
  42. if (target > 1) kotak[target - 1][a] = 1;
  43. while (target > 2 && kotak[target - 2][a] == 1 ) {
  44. target--;
  45. }
  46.  
  47. }
  48. }
  49. }
  50.  
  51. for (int a = 0; a < baris; a++) {
  52. for (int b = 0; b < kolom; b++) {
  53. cout << kotak[a][b];
  54. }
  55. cout << endl;
  56. }
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
Success #stdin #stdout 0.01s 5332KB
stdin
6 3
111
111
111
111
111
111
stdout
000
000
000
000
000
000