Submission #3248060


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

void eliminate_empty_line(vector< vector<bool> > &map)
{
  auto itr = map.begin();
  while (itr != map.end()) {
    if ( accumulate(itr->begin(), itr->end(), true, logical_and<bool>()) ) {
      itr = map.erase(itr);
    } else {
      ++itr;
    }
  }
}

vector< vector<bool> > transpose(vector< vector<bool> > &src)
{
  uint64_t H = src.size(), W = src[0].size();
  vector< vector<bool> > dst(W, vector<bool>(H));
  for (uint64_t h = 0; h < H; ++h) {
    for (uint64_t w = 0; w < W; ++w) {
      dst[w][h] = src[h][w];
    }
  }
  return dst;
}

ostream& operator<<(ostream &os, const vector< vector<bool> > &map)
{
  for (uint64_t h = 0; h < map.size(); ++h) {
    for (uint64_t w = 0; w < map[h].size(); ++w) {
      os << (map[h][w] ? '.' : '#');
    }
    os << endl;
  }
  return os;
}

int main()
{
  uint64_t H, W;
  cin >> H >> W;
  
  vector< vector<bool> > map(H, vector<bool>(W));
  for (uint64_t h = 0; h < H; ++h) {
    for (uint64_t w = 0; w < W; ++w) {
      char c;
      cin >> c;
      map[h][w] = c == '.';
    }
  }
  
  eliminate_empty_line(map);
  
  map = transpose(map);
  
  eliminate_empty_line(map);
  
  map = transpose(map);
  
  cout << map << endl;
  
  return 0;
}

Submission Info

Submission Time
Task B - Grid Compression
User material
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1310 Byte
Status AC
Exec Time 2 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 4
AC × 12
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
0_03.txt AC 1 ms 256 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 2 ms 256 KB
1_02.txt AC 2 ms 256 KB
1_03.txt AC 2 ms 256 KB
1_04.txt AC 2 ms 256 KB
1_05.txt AC 2 ms 256 KB
1_06.txt AC 2 ms 256 KB
1_07.txt AC 2 ms 256 KB