codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

546C.md (2208B)


      1 Source: https://codeforces.com/problemset/problem/546/C
      2 
      3 C. Soldier and Cards
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Two bored soldiers are playing card war. Their card deck consists of exactly *n* cards, numbered from 1 to *n*, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game.
     22 
     23 The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins.
     24 
     25 You have to calculate how many fights will happen and who will win the game, or state that game won't end.
     26 
     27 Input
     28 
     29 First line contains a single integer *n* (2 ≤ *n* ≤ 10), the number of cards.
     30 
     31 Second line contains integer *k*1 (1 ≤ *k*1 ≤ *n* - 1), the number of the first soldier's cards. Then follow *k*1 integers that are the values on the first soldier's cards, from top to bottom of his stack.
     32 
     33 Third line contains integer *k*2 (*k*1 + *k*2 = *n*), the number of the second soldier's cards. Then follow *k*2 integers that are the values on the second soldier's cards, from top to bottom of his stack.
     34 
     35 All card values are different.
     36 
     37 Output
     38 
     39 If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won.
     40 
     41 If the game won't end and will continue forever output  - 1.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 4  
     49 2 1 3  
     50 2 4 2
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 6 2
     57 ```
     58 
     59 Input
     60 
     61 ```
     62 3  
     63 1 2  
     64 2 1 3
     65 ```
     66 
     67 Output
     68 
     69 ```
     70 -1
     71 ```
     72 
     73 Note
     74 
     75 First sample:
     76 
     77  ![](https://espresso.codeforces.com/4cee28c57f69ccf0ecb2ae3a8cc8ad3c889f59c2.png) 
     78 
     79 Second sample:
     80 
     81  ![](https://espresso.codeforces.com/d64d7c35c4e7a82969460877cc43795fd9c5e129.png)