Advertisement
DABRiXPERT

APCS11011P2

Nov 27th, 2021
1,126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.15 KB | None | 0 0
  1. package com.nananananite.apcs211102;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. public class APCS11011P2 {
  8.  
  9.     BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  10.     int[][] data;//HOR(m=x) - VER(n=y)
  11.     int m, n, h;
  12.     int[] r, c, t;//r = x, c = y
  13.     String[] raw;
  14.     APCS11011P2() throws IOException {
  15.         //INPUT
  16.         raw = bufferedReader.readLine().split(" ");
  17.         m = Integer.parseInt(raw[0]);
  18.         n = Integer.parseInt(raw[1]);
  19.         h = Integer.parseInt(raw[2]);
  20.         data = new int[m][n];
  21.         r = new int[h];  c = new int[h];  t = new int[h];
  22.         for (int i = 0; i < h; i++)
  23.         {
  24.             raw = bufferedReader.readLine().split(" ");
  25.             r[i] = Integer.parseInt(raw[0]);
  26.             c[i] = Integer.parseInt(raw[1]);
  27.             t[i] = Integer.parseInt(raw[2]);
  28.         }
  29.         //PROCESS: 0 = BLANK, 1 = NODE
  30.         int max = 0;
  31.         int latest = 0;
  32.         for (int i = 0; i < h; i++)
  33.         {
  34.             if(t[i] == 0)//ADD
  35.             {
  36.                 data[r[i]][c[i]] = 1;
  37.                 if(i != 0)
  38.                 {
  39.                     int x = r[i]-1, y = c[i];
  40.                     int detect = 0;
  41.                     //UP = 2
  42.                     while (x >= 0) {
  43.                         if (data[x][y] == 1)
  44.                             detect++;
  45.                         x--;
  46.                     }
  47.                     x = r[i]-1; y = c[i];
  48.                     while (x >= 0 && detect != 0 && data[x][y] != 1) {
  49.                         if(data[x][y] == 3 || data[x][y] == 4)
  50.                             data[x][y] = 4;
  51.                         else
  52.                             data[x][y] = 2;
  53.                         x--;
  54.                     }
  55.  
  56.                     x = r[i]+1; y = c[i];
  57.                     detect = 0;
  58.                     //DOWN = 2
  59.                     while (x <= m-1) {
  60.                         if (data[x][y] == 1)
  61.                             detect++;
  62.                         x++;
  63.                     }
  64.                     x = r[i]+1; y = c[i];
  65.                     while (x <= m-1 && detect != 0 && data[x][y] != 1) {
  66.                         if(data[x][y] == 3 || data[x][y] == 4)
  67.                             data[x][y] = 4;
  68.                         else
  69.                             data[x][y] = 2;
  70.                         x++;
  71.                     }
  72.  
  73.                     x = r[i]; y = c[i]-1;
  74.                     detect = 0;
  75.                     //LEFT = 3
  76.                     while (y >= 0) {
  77.                         if (data[x][y] == 1)
  78.                             detect++;
  79.                         y--;
  80.                     }
  81.                     x = r[i]; y = c[i]-1;
  82.                     while (y >= 0 && detect != 0 && data[x][y] != 1) {
  83.                         if(data[x][y] == 2 || data[x][y] == 4)
  84.                             data[x][y] = 4;
  85.                         else
  86.                             data[x][y] = 3;
  87.                         y--;
  88.                     }
  89.  
  90.                     x = r[i]; y = c[i]+1;
  91.                     detect = 0;
  92.                     //RIGHT = 3
  93.                     while (y <= n-1) {
  94.                         if (data[x][y] == 1)
  95.                             detect++;
  96.                         y++;
  97.                     }
  98.                     x = r[i]; y = c[i]+1;
  99.                     while (y <= n-1 && detect != 0 && data[x][y] != 1) {
  100.                         if(data[x][y] == 2 || data[x][y] == 4)
  101.                             data[x][y] = 4;
  102.                         else
  103.                             data[x][y] = 3;
  104.                         y++;
  105.                     }
  106.  
  107.                 }
  108.             }
  109.             if(t[i] == 1)//REMOVE
  110.             {
  111.                 data[r[i]][c[i]] = 0;
  112.                 if(i != 0)
  113.                 {
  114.                     int x = r[i]-1, y = c[i];
  115.                     int detect = 0;
  116.                     //UP = 2
  117.                     while (x >= 0) {
  118.                         if (data[x][y] == 1)
  119.                             detect++;
  120.                         x--;
  121.                     }
  122.                     x = r[i]-1; y = c[i];
  123.                     while (x >= 0 && detect != 0 && data[x][y] != 1) {
  124.                         if(data[x][y] == 4)
  125.                             data[x][y] = 3;
  126.                         else
  127.                             data[x][y] = 0;
  128.                         x--;
  129.                     }
  130.  
  131.                     x = r[i]+1; y = c[i];
  132.                     detect = 0;
  133.                     //DOWN = 2
  134.                     while (x <= m-1) {
  135.                         if (data[x][y] == 1)
  136.                             detect++;
  137.                         x++;
  138.                     }
  139.                     x = r[i]+1; y = c[i];
  140.                     while (x <= m-1 && detect != 0 && data[x][y] != 1) {
  141.                         if(data[x][y] == 4)
  142.                             data[x][y] = 3;
  143.                         else
  144.                             data[x][y] = 0;
  145.                         x++;
  146.                     }
  147.  
  148.                     x = r[i]; y = c[i]-1;
  149.                     detect = 0;
  150.                     //LEFT = 3
  151.                     while (y >= 0) {
  152.                         if (data[x][y] == 1)
  153.                             detect++;
  154.                         y--;
  155.                     }
  156.                     x = r[i]; y = c[i]-1;
  157.                     while (y >= 0 && detect != 0 && data[x][y] != 1) {
  158.                         if(data[x][y] == 4)
  159.                             data[x][y] = 2;
  160.                         else
  161.                             data[x][y] = 0;
  162.                         y--;
  163.                     }
  164.  
  165.                     x = r[i]; y = c[i]+1;
  166.                     detect = 0;
  167.                     //RIGHT = 3
  168.                     while (y <= n-1) {
  169.                         if (data[x][y] == 1)
  170.                             detect++;
  171.                         y++;
  172.                     }
  173.                     x = r[i]; y = c[i]+1;
  174.                     while (y <= n-1 && detect != 0 && data[x][y] != 1) {
  175.                         if(data[x][y] == 4)
  176.                             data[x][y] = 2;
  177.                         else
  178.                             data[x][y] = 0;
  179.                         y++;
  180.                     }
  181.  
  182.                 }
  183.             }
  184.             int sum = 0;
  185.             for (int a = 0; a < m; a++)
  186.             {
  187.                 for (int b = 0; b < n; b++)
  188.                 {
  189.                     if(data[a][b] != 0)
  190.                         sum++;
  191.                 }
  192.             }
  193.  
  194.             if (sum >= max)
  195.                 max = sum;
  196.             latest = sum;
  197.             /*
  198.             for (int a = 0; a < m; a++)
  199.             {
  200.                 for (int b = 0; b < n; b++)
  201.                 {
  202.                     System.out.print(data[a][b] + " ");
  203.                 }
  204.                 System.out.println();
  205.             }
  206.             System.out.println();
  207.             */
  208.         }
  209.  
  210.         System.out.println(max);
  211.         System.out.println(latest);
  212.  
  213.     }
  214.     public static void main(String[] args) throws IOException {
  215.         new APCS11011P2();
  216.     }
  217. }
  218.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement