|
| 1 | +```java |
| 2 | +import java.util.*; |
| 3 | +import java.io.*; |
| 4 | + |
| 5 | +class IOController { |
| 6 | + BufferedReader br; |
| 7 | + BufferedWriter bw; |
| 8 | + StringTokenizer st; |
| 9 | + |
| 10 | + public IOController() { |
| 11 | + br = new BufferedReader(new InputStreamReader(System.in)); |
| 12 | + bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 13 | + st = new StringTokenizer(""); |
| 14 | + } |
| 15 | + |
| 16 | + String nextLine() throws Exception { |
| 17 | + String line = br.readLine(); |
| 18 | + st = new StringTokenizer(line); |
| 19 | + return line; |
| 20 | + } |
| 21 | + |
| 22 | + String nextToken() throws Exception { |
| 23 | + while (!st.hasMoreTokens()) nextLine(); |
| 24 | + return st.nextToken(); |
| 25 | + } |
| 26 | + |
| 27 | + int nextInt() throws Exception { |
| 28 | + return Integer.parseInt(nextToken()); |
| 29 | + } |
| 30 | + |
| 31 | + long nextLong() throws Exception { |
| 32 | + return Long.parseLong(nextToken()); |
| 33 | + } |
| 34 | + |
| 35 | + double nextDouble() throws Exception { |
| 36 | + return Double.parseDouble(nextToken()); |
| 37 | + } |
| 38 | + |
| 39 | + void close() throws Exception { |
| 40 | + bw.flush(); |
| 41 | + bw.close(); |
| 42 | + } |
| 43 | + |
| 44 | + void write(String content) throws Exception { |
| 45 | + bw.write(content); |
| 46 | + } |
| 47 | + |
| 48 | +} |
| 49 | + |
| 50 | +public class Main { |
| 51 | + |
| 52 | + static IOController io; |
| 53 | + |
| 54 | + // |
| 55 | + |
| 56 | + static int N, M, K; |
| 57 | + static int[][] UL, UR, DL, DR; |
| 58 | + static boolean[][] res; |
| 59 | + |
| 60 | + public static void main(String[] args) throws Exception { |
| 61 | + |
| 62 | + io = new IOController(); |
| 63 | + |
| 64 | + init(); |
| 65 | + solve(); |
| 66 | + |
| 67 | + io.close(); |
| 68 | + |
| 69 | + } |
| 70 | + |
| 71 | + static void init() throws Exception { |
| 72 | + |
| 73 | + N = io.nextInt(); |
| 74 | + M = io.nextInt(); |
| 75 | + K = io.nextInt(); |
| 76 | + UL = new int[N+2][M+2]; |
| 77 | + UR = new int[N+2][M+2]; |
| 78 | + DL = new int[N+2][M+2]; |
| 79 | + DR = new int[N+2][M+2]; |
| 80 | + res = new boolean[N+2][M+2]; |
| 81 | + while(K-->0) { |
| 82 | + int x = io.nextInt(); |
| 83 | + int y = io.nextInt(); |
| 84 | + int w = io.nextInt(); |
| 85 | + UL[x][y] = w+1; |
| 86 | + UR[x][y] = w+1; |
| 87 | + DL[x][y] = w+1; |
| 88 | + DR[x][y] = w+1; |
| 89 | + } |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + static void solve() throws Exception { |
| 94 | + |
| 95 | + for(int i=1;i<=N;i++) for(int j=1;j<=M;j++) { |
| 96 | + if(UR[i][j] > 0) { |
| 97 | + res[i][j] = true; |
| 98 | + UR[i+1][j] = Math.max(UR[i+1][j], UR[i][j]-1); |
| 99 | + UR[i][j+1] = Math.max(UR[i][j+1], UR[i][j]-1); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + for(int i=1;i<=N;i++) for(int j=M;j>=1;j--) { |
| 104 | + if(UL[i][j] > 0) { |
| 105 | + res[i][j] = true; |
| 106 | + UL[i+1][j] = Math.max(UL[i+1][j], UL[i][j]-1); |
| 107 | + UL[i][j-1] = Math.max(UL[i][j-1], UL[i][j]-1); |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + for(int i=N;i>=1;i--) for(int j=1;j<=M;j++) { |
| 112 | + if(DR[i][j] > 0) { |
| 113 | + res[i][j] = true; |
| 114 | + DR[i-1][j] = Math.max(DR[i-1][j], DR[i][j]-1); |
| 115 | + DR[i][j+1] = Math.max(DR[i][j+1], DR[i][j]-1); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + for(int i=N;i>=1;i--) for(int j=M;j>=1;j--) { |
| 120 | + if(DL[i][j] > 0) { |
| 121 | + res[i][j] = true; |
| 122 | + DL[i-1][j] = Math.max(DL[i-1][j], DL[i][j]-1); |
| 123 | + DL[i][j-1] = Math.max(DL[i][j-1], DL[i][j]-1); |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + int ans = 0; |
| 128 | + for(int i=1;i<=N;i++) for(int j=1;j<=M;j++) ans += res[i][j] ? 1 : 0; |
| 129 | + io.write(ans + "\n"); |
| 130 | + |
| 131 | + } |
| 132 | + |
| 133 | +} |
| 134 | +``` |
0 commit comments