Submission #1372256
Source Code Expand
#include<iostream> #include<string> #include<vector> #include<valarray> #include<cmath> #include<tuple> #include<utility> #include<algorithm> template<typename T> T read(){ T x; std::cin >> x; return x; } template<typename T> std::vector<T> readVec(int32_t n) { std::vector<T> vec; for (int32_t i=0; i<n; i++) { vec.push_back(read<T>()); } return vec; } typedef std::tuple<uint32_t, uint32_t> idx2d; std::vector<idx2d> surroundings(uint32_t x, uint32_t y, uint32_t height, uint32_t width){ std::vector<idx2d> ret; for (int i=-1; i<=1; ++i) { for (int j=-1; j<=1; ++j) { if (0<=i+x && i+x<height && 0<=j+y && j+y<width && (i!=0 || j!=0)) { ret.push_back(std::make_tuple(i+x, j+y)); } } } return ret; } std::vector<std::string> guess(std::vector<std::string> image){ for (int i=0; i<image.size(); ++i) { for (int j=0; j<image[0].length(); ++j) { if (image[i][j] == '#') { for (idx2d k : surroundings(i, j, image.size(), image[0].length())) { if (image[std::get<0>(k)][std::get<1>(k)]=='.') { image[i][j] = '*'; break; } } } } } return image; } bool valid(std::vector<std::string> image) { for (int i=0; i<image.size(); ++i) { for (int j=0; j<image[0].length(); ++j) { if (image[i][j] == '*') { bool flag=false; for (idx2d k : surroundings(i, j, image.size(), image[0].length())) { if (image[std::get<0>(k)][std::get<1>(k)]=='#') { flag=true; break; } } if (!flag) { return false; } } } } return true; } int main() { const int h = read<int>(); const int w = read<int>(); auto image = readVec<std::string>(h); auto preshrink = guess(std::move(image)); if (valid(preshrink)) { std::cout << "possible" << std::endl; for (auto line : preshrink){ std::replace(line.begin(), line.end(), '*', '.'); std::cout << line << std::endl; } } else { std::cout << "impossible" << std::endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 画像処理高橋君 |
User | seiyab |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 2491 Byte |
Status | AC |
Exec Time | 3 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 100 / 100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_0.txt, example_1.txt, example_2.txt |
All | example_0.txt, example_1.txt, example_2.txt, handmade_0.txt, handmade_1.txt, possible_0.txt, possible_1.txt, possible_2.txt, possible_3.txt, possible_4.txt, possible_5.txt, possible_6.txt, possible_7.txt, possible_8.txt, possible_9.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
example_0.txt | AC | 1 ms | 256 KB |
example_1.txt | AC | 1 ms | 256 KB |
example_2.txt | AC | 1 ms | 256 KB |
handmade_0.txt | AC | 1 ms | 256 KB |
handmade_1.txt | AC | 1 ms | 256 KB |
possible_0.txt | AC | 2 ms | 256 KB |
possible_1.txt | AC | 3 ms | 256 KB |
possible_2.txt | AC | 2 ms | 256 KB |
possible_3.txt | AC | 3 ms | 256 KB |
possible_4.txt | AC | 2 ms | 256 KB |
possible_5.txt | AC | 1 ms | 256 KB |
possible_6.txt | AC | 2 ms | 256 KB |
possible_7.txt | AC | 3 ms | 256 KB |
possible_8.txt | AC | 3 ms | 256 KB |
possible_9.txt | AC | 2 ms | 256 KB |
random_0.txt | AC | 1 ms | 256 KB |
random_1.txt | AC | 2 ms | 256 KB |
random_2.txt | AC | 1 ms | 256 KB |
random_3.txt | AC | 1 ms | 256 KB |
random_4.txt | AC | 1 ms | 256 KB |
random_5.txt | AC | 2 ms | 256 KB |
random_6.txt | AC | 2 ms | 256 KB |
random_7.txt | AC | 2 ms | 256 KB |
random_8.txt | AC | 1 ms | 256 KB |
random_9.txt | AC | 2 ms | 256 KB |