Submission #3231490
Source Code Expand
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>
using namespace std;
struct Initializer {
Initializer() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(15);
}
} initializer;
template<typename T> istream& operator>>(istream &s, vector<T> &v) {
for (T &t : v) s >> t;
return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
for (const T &t : v) s << t << endl;
return s;
}
template<int N> class AdjacentLoop {
private:
const static array<int, N> dy, dx;
struct Iterator {
const int y, x, h, w;
int val;
Iterator(int y, int x, int h, int w, int val) : y(y), x(x), h(h), w(w), val(val) {
for (; this->val < N; ++this->val) {
int yy = y + dy[this->val];
int xx = x + dx[this->val];
if (0 <= yy && yy < h && 0 <= xx && xx < w) break;
}
}
pair<int, int> operator*() {return make_pair(y + dy[val], x + dx[val]);}
bool operator!=(Iterator& itr) {return val < itr.val;}
void operator++() {
while (++val < N) {
int yy = y + dy[val];
int xx = x + dx[val];
if (0 <= yy && yy < h && 0 <= xx && xx < w) break;
}
}
};
Iterator i, n;
public:
AdjacentLoop(int y, int x, int h, int w) : i(y, x, h, w, 0), n(y, x, h, w, N) {}
Iterator& begin() {return i;}
Iterator& end() {return n;}
};
template<> const array<int, 2> AdjacentLoop<2>::dy = {{0, 1}};
template<> const array<int, 2> AdjacentLoop<2>::dx = {{1, 0}};
template<> const array<int, 4> AdjacentLoop<4>::dy = {{0, -1, 0, 1}};
template<> const array<int, 4> AdjacentLoop<4>::dx = {{1, 0, -1, 0}};
template<> const array<int, 5> AdjacentLoop<5>::dy = {{0, -1, 0, 1, 0}};
template<> const array<int, 5> AdjacentLoop<5>::dx = {{1, 0, -1, 0, 0}};
template<> const array<int, 8> AdjacentLoop<8>::dy = {{-1, -1, -1, 0, 0, 1, 1, 1}};
template<> const array<int, 8> AdjacentLoop<8>::dx = {{-1, 0, 1, -1, 1, -1, 0, 1}};
template<> const array<int, 9> AdjacentLoop<9>::dy = {{-1, -1, -1, 0, 0, 0, 1, 1, 1}};
template<> const array<int, 9> AdjacentLoop<9>::dx = {{-1, 0, 1, -1, 0, 1, -1, 0, 1}};
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
cin >> s;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (s[i][j] == '#') continue;
s[i][j] = '0';
for (auto k : AdjacentLoop<8>(i, j, h, w)) {
if (s[k.first][k.second] == '#') ++s[i][j];
}
}
}
cout << s;
}
Submission Info
Submission Time |
|
Task |
B - Minesweeper |
User |
not |
Language |
C++14 (GCC 5.4.1) |
Score |
200 |
Code Size |
2693 Byte |
Status |
AC |
Exec Time |
1 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
200 / 200 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_1.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
1 ms |
256 KB |
sample_02.txt |
AC |
1 ms |
256 KB |
sample_03.txt |
AC |
1 ms |
256 KB |
subtask_1_1.txt |
AC |
1 ms |
256 KB |
subtask_1_10.txt |
AC |
1 ms |
256 KB |
subtask_1_11.txt |
AC |
1 ms |
256 KB |
subtask_1_12.txt |
AC |
1 ms |
256 KB |
subtask_1_2.txt |
AC |
1 ms |
256 KB |
subtask_1_3.txt |
AC |
1 ms |
256 KB |
subtask_1_4.txt |
AC |
1 ms |
256 KB |
subtask_1_5.txt |
AC |
1 ms |
256 KB |
subtask_1_6.txt |
AC |
1 ms |
256 KB |
subtask_1_7.txt |
AC |
1 ms |
256 KB |
subtask_1_8.txt |
AC |
1 ms |
256 KB |
subtask_1_9.txt |
AC |
1 ms |
256 KB |