50164. Dice
難度:3.5/5 Used Time: 12:181
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
int r, c;
int arr[1024][1024];
void ipt(){
scanf("%d %d", &r, &c);
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
scanf("%d", &arr[i][j]);
}
}
}
int count_valid_12(int x, int y){
int cnt[7] = {0};
if(arr[x + 1][y] + arr[x + 1][y + 2] != 7) return 0;
if(arr[x + 1][y + 1] + arr[x + 1][y + 1 + 2] != 7) return 0;
for(int i = 0; i < 4; i++) cnt[arr[x + 1][y + i]]++;
for(int i = 1; i <= 6; i++) if(cnt[i] >= 2) return 0;
int res_1 = -1, res_2 = -1;
for(int i = 1; i <= 6; i++){
if(cnt[i] == 0 && res_1 == -1) res_1 = i;
else if(cnt[i] == 0) res_2 = i;
}
int up_1 = 0, down_1 = 0, up_2 = 0, down_2 = 0;
for(int i = 0; i < 4; i++){
if(arr[x][y + i] == res_1) up_1++;
if(arr[x + 2][y + i] == res_1) down_1++;
if(arr[x][y + i] == res_2) up_2++;
if(arr[x + 2][y + i] == res_2) down_2++;
}
int ans = up_1 * down_2 + up_2 * down_1;
// printf("ans is %d\n", ans);
return ans;
}
void solve(){
int cnt = 0;
for(int i = 0; i < r - 2; i++){
for(int j = 0; j < c - 3; j++){
cnt += count_valid_12(i, j);
}
}
printf("%d\n", cnt);
}
int main(){
ipt();
solve();
}