Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.nananananite.apcs211102;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class APCS11011P2 {
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
- int[][] data;//HOR(m=x) - VER(n=y)
- int m, n, h;
- int[] r, c, t;//r = x, c = y
- String[] raw;
- APCS11011P2() throws IOException {
- //INPUT
- raw = bufferedReader.readLine().split(" ");
- m = Integer.parseInt(raw[0]);
- n = Integer.parseInt(raw[1]);
- h = Integer.parseInt(raw[2]);
- data = new int[m][n];
- r = new int[h]; c = new int[h]; t = new int[h];
- for (int i = 0; i < h; i++)
- {
- raw = bufferedReader.readLine().split(" ");
- r[i] = Integer.parseInt(raw[0]);
- c[i] = Integer.parseInt(raw[1]);
- t[i] = Integer.parseInt(raw[2]);
- }
- //PROCESS: 0 = BLANK, 1 = NODE
- int max = 0;
- int latest = 0;
- for (int i = 0; i < h; i++)
- {
- if(t[i] == 0)//ADD
- {
- data[r[i]][c[i]] = 1;
- if(i != 0)
- {
- int x = r[i]-1, y = c[i];
- int detect = 0;
- //UP = 2
- while (x >= 0) {
- if (data[x][y] == 1)
- detect++;
- x--;
- }
- x = r[i]-1; y = c[i];
- while (x >= 0 && detect != 0 && data[x][y] != 1) {
- if(data[x][y] == 3 || data[x][y] == 4)
- data[x][y] = 4;
- else
- data[x][y] = 2;
- x--;
- }
- x = r[i]+1; y = c[i];
- detect = 0;
- //DOWN = 2
- while (x <= m-1) {
- if (data[x][y] == 1)
- detect++;
- x++;
- }
- x = r[i]+1; y = c[i];
- while (x <= m-1 && detect != 0 && data[x][y] != 1) {
- if(data[x][y] == 3 || data[x][y] == 4)
- data[x][y] = 4;
- else
- data[x][y] = 2;
- x++;
- }
- x = r[i]; y = c[i]-1;
- detect = 0;
- //LEFT = 3
- while (y >= 0) {
- if (data[x][y] == 1)
- detect++;
- y--;
- }
- x = r[i]; y = c[i]-1;
- while (y >= 0 && detect != 0 && data[x][y] != 1) {
- if(data[x][y] == 2 || data[x][y] == 4)
- data[x][y] = 4;
- else
- data[x][y] = 3;
- y--;
- }
- x = r[i]; y = c[i]+1;
- detect = 0;
- //RIGHT = 3
- while (y <= n-1) {
- if (data[x][y] == 1)
- detect++;
- y++;
- }
- x = r[i]; y = c[i]+1;
- while (y <= n-1 && detect != 0 && data[x][y] != 1) {
- if(data[x][y] == 2 || data[x][y] == 4)
- data[x][y] = 4;
- else
- data[x][y] = 3;
- y++;
- }
- }
- }
- if(t[i] == 1)//REMOVE
- {
- data[r[i]][c[i]] = 0;
- if(i != 0)
- {
- int x = r[i]-1, y = c[i];
- int detect = 0;
- //UP = 2
- while (x >= 0) {
- if (data[x][y] == 1)
- detect++;
- x--;
- }
- x = r[i]-1; y = c[i];
- while (x >= 0 && detect != 0 && data[x][y] != 1) {
- if(data[x][y] == 4)
- data[x][y] = 3;
- else
- data[x][y] = 0;
- x--;
- }
- x = r[i]+1; y = c[i];
- detect = 0;
- //DOWN = 2
- while (x <= m-1) {
- if (data[x][y] == 1)
- detect++;
- x++;
- }
- x = r[i]+1; y = c[i];
- while (x <= m-1 && detect != 0 && data[x][y] != 1) {
- if(data[x][y] == 4)
- data[x][y] = 3;
- else
- data[x][y] = 0;
- x++;
- }
- x = r[i]; y = c[i]-1;
- detect = 0;
- //LEFT = 3
- while (y >= 0) {
- if (data[x][y] == 1)
- detect++;
- y--;
- }
- x = r[i]; y = c[i]-1;
- while (y >= 0 && detect != 0 && data[x][y] != 1) {
- if(data[x][y] == 4)
- data[x][y] = 2;
- else
- data[x][y] = 0;
- y--;
- }
- x = r[i]; y = c[i]+1;
- detect = 0;
- //RIGHT = 3
- while (y <= n-1) {
- if (data[x][y] == 1)
- detect++;
- y++;
- }
- x = r[i]; y = c[i]+1;
- while (y <= n-1 && detect != 0 && data[x][y] != 1) {
- if(data[x][y] == 4)
- data[x][y] = 2;
- else
- data[x][y] = 0;
- y++;
- }
- }
- }
- int sum = 0;
- for (int a = 0; a < m; a++)
- {
- for (int b = 0; b < n; b++)
- {
- if(data[a][b] != 0)
- sum++;
- }
- }
- if (sum >= max)
- max = sum;
- latest = sum;
- /*
- for (int a = 0; a < m; a++)
- {
- for (int b = 0; b < n; b++)
- {
- System.out.print(data[a][b] + " ");
- }
- System.out.println();
- }
- System.out.println();
- */
- }
- System.out.println(max);
- System.out.println(latest);
- }
- public static void main(String[] args) throws IOException {
- new APCS11011P2();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement