Submission #2127435
Source Code Expand
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, s, k, t, q, ans, sum, last, a[101][101];
bool f[101][101];
struct Edge { LL cost,to; };
vector<Pll>vec[2];
vector<LL>V;
string str,ss;
int dx[2][6] = { { -1,-1, 0,1,1,0 },{ -1,-1, 0,1,1,0 } },
dy[2][6] = { { 0,1,1,1,0,-1 },{ -1,0,1,0,-1,-1 } };
void YN(bool f) {
if (f)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void yn(bool f) {
if (f)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void dfs(int x,int y) {
if (a[x][y] == 0) {
f[x][y] = 1;
rep(i, 6) {
int X = dx[y % 2][i] + x, Y = dy[x % 2][i] + y;
if (X >= 0 && X < m&&Y >= 0 && Y < n&&f[X][Y] == 0)
dfs(X, Y);
}
}
}
int main() {
cin >> n >> m;
rep(i, m)
rep(j, n) {
cin >> a[i][j];
if (a[i][j] == 1) {
if (i == 0||i==m-1)ans += 2;
if (j == 0)ans += 1;
if (j == n - 1)ans += 3;
if (i == 0 && j == n - 1)ans -= 1;
if (m % 2 == 1 && i == m - 1 && j == n - 1)ans -= 1;
}
}
rep(i,m) dfs(i, 0);
rep(i, m) dfs(i, n - 1);
rep(i, n) dfs(0,i);
rep(i, n) dfs(m-1, i);
rep(i, m)
rep(j, n) {
if (f[i][j]) {
rep(k, 6) {
int X = dx[j % 2][k] + i, Y = dy[i % 2][k] + j;
if (X >= 0 && X < m&&Y >= 0 && Y < n&&a[X][Y] == 1)
ans++;
}
}
}
cout <<ans<< endl;
return 0;
}
Submission Info
Judge Result
Set Name |
set01 |
set02 |
set03 |
set04 |
set05 |
Score / Max Score |
20 / 20 |
0 / 20 |
0 / 20 |
0 / 20 |
0 / 20 |
Status |
|
|
|
|
|
Set Name |
Test Cases |
set01 |
data1 |
set02 |
data2 |
set03 |
data3 |
set04 |
data4 |
set05 |
data5 |
Case Name |
Status |
Exec Time |
Memory |
data1 |
AC |
1 ms |
256 KB |
data2 |
WA |
2 ms |
512 KB |
data3 |
WA |
3 ms |
384 KB |
data4 |
WA |
3 ms |
640 KB |
data5 |
WA |
3 ms |
512 KB |