Advertisement
Guest User

CCC 2014 S3

a guest
Nov 22nd, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int t, n;
  5. int i;
  6.  
  7. /* Queues */
  8. int mountain[100000], branch[100000];
  9.  
  10. /* Lengths of queues */
  11. int mountainl, branchl;
  12.  
  13. /* Last car pushed into the lake */
  14. int lake;
  15.  
  16. int main(void) {
  17.     /* Read the integer T */
  18.     scanf("%d", &t);
  19.  
  20.     /* Run code T times */
  21.     while (t--) {
  22.         /* Reset */
  23.         memset(mountain, 0, 100000*sizeof(int));
  24.         memset(branch, 0, 100000*sizeof(int));
  25.         mountainl = branchl = lake = 0;
  26.  
  27.         /* Read the integer N */
  28.         scanf("%d", &n);
  29.         mountainl = n;
  30.  
  31.         /* Read the numbers of the next N cars */
  32.         for (i = 0; i < n; i++)
  33.             scanf("%d", &mountain[i]);
  34.  
  35.         /* Attempt */
  36.         while (1) {
  37.             /* Slide from mountain directly into lake if possible */
  38.             if (mountainl && mountain[mountainl-1] == lake+1) {
  39.                 mountain[--mountainl] = 0;
  40.                 lake++;
  41.             }
  42.  
  43.             /* Slide from branch into lake if possible */
  44.             else if (branchl && branch[branchl-1] == lake+1) {
  45.                 branch[--branchl] = 0;
  46.                 lake++;
  47.             }
  48.  
  49.             /* Otherwise slide from mountain to branch */
  50.             else if (mountainl) {
  51.                 branch[branchl++] = mountain[mountainl-1];
  52.                 mountain[--mountainl] = 0;
  53.             }
  54.  
  55.             else break;
  56.         }
  57.  
  58.         puts(branchl ? "N" : "Y");
  59.     }
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement