Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int t, n;
- int i;
- /* Queues */
- int mountain[100000], branch[100000];
- /* Lengths of queues */
- int mountainl, branchl;
- /* Last car pushed into the lake */
- int lake;
- int main(void) {
- /* Read the integer T */
- scanf("%d", &t);
- /* Run code T times */
- while (t--) {
- /* Reset */
- memset(mountain, 0, 100000*sizeof(int));
- memset(branch, 0, 100000*sizeof(int));
- mountainl = branchl = lake = 0;
- /* Read the integer N */
- scanf("%d", &n);
- mountainl = n;
- /* Read the numbers of the next N cars */
- for (i = 0; i < n; i++)
- scanf("%d", &mountain[i]);
- /* Attempt */
- while (1) {
- /* Slide from mountain directly into lake if possible */
- if (mountainl && mountain[mountainl-1] == lake+1) {
- mountain[--mountainl] = 0;
- lake++;
- }
- /* Slide from branch into lake if possible */
- else if (branchl && branch[branchl-1] == lake+1) {
- branch[--branchl] = 0;
- lake++;
- }
- /* Otherwise slide from mountain to branch */
- else if (mountainl) {
- branch[branchl++] = mountain[mountainl-1];
- mountain[--mountainl] = 0;
- }
- else break;
- }
- puts(branchl ? "N" : "Y");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement