Round B China New Grad Test 2014


  Submissions
Sudoku Checker
5pt
Not attempted
1471/2010 users correct (73%)
9pt
Not attempted
1146/1443 users correct (79%)
Meet and party
9pt
Not attempted
496/823 users correct (60%)
15pt
Not attempted
47/409 users correct (11%)
Hex
12pt
Not attempted
19/260 users correct (7%)
13pt
Not attempted
14/18 users correct (78%)
Dragon Maze
8pt
Not attempted
336/594 users correct (57%)
12pt
Not attempted
229/330 users correct (69%)
Ignore all my comments
7pt
Not attempted
73/469 users correct (16%)
10pt
Not attempted
67/71 users correct (94%)
  Top Scores
TankEngineer100
LTzycLT100
l521530100
navi85
wishstudio85
Nekosyndrome83
W.Junqiao83
iloahz83
zhuyin75
cpcs75
Practice Mode

Problem D. Dragon Maze

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
8 points
Large input
12 points

Problem

You are the prince of Dragon Kingdom and your kingdom is in danger of running out of power. You must find power to save your kingdom and its people. An old legend states that power comes from a place known as Dragon Maze. Dragon Maze appears randomly out of nowhere without notice and suddenly disappears without warning. You know where Dragon Maze is now, so it is important you retrieve some power before it disappears.

Dragon Maze is a rectangular maze, an N x M grid of cells. The top left corner cell of the maze is (0,0) and the bottom right corner is (N-1, M-1). Each cell making up the maze can be either a dangerous place which you never escape after entering, or a safe place that contains a certain amount of power. The power in a safe cell is automatically gathered once you enter that cell, and can only be gathered once. Starting from a cell, you can walk up/down/left/right to adjacent cells with a single step.

Now you know where the entrance and exit cells are, that they are different, and that they are both safe cells. In order to get out of Dragon Maze before it disappears, you must walk from the entrance cell to the exit cell taking as few steps as possible. If there are multiple choices for the path you could take, you must choose the one on which you collect as much power as possible in order to save your kingdom.

Input

The first line of the input gives the number of test cases, T. T test cases follow.

Each test case starts with a line containing two integers N and M, which give the size of Dragon Maze as described above. The second line of each test case contains four integers enx, eny, exx, exy, describing the position of entrance cell (enx, eny) and exit cell (exx, exy). Then N lines follow and each line has M numbers, separated by spaces, describing the N x M cells of Dragon Maze from top to bottom. Each number for a cell is either -1, which indicates a cell is dangerous, or a positive integer, which indicates a safe cell containing a certain amount of power.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1). If it's possible for you to walk from the entrance to the exit, y should be the maximum total amount of power you can collect by taking the fewest steps possible. If you cannot walk from the entrance to the exit, y should be the string "Mission Impossible." (quotes for clarity). Please note that the judge requires an exact match, so any other output like "mission impossible." or "Mission Impossible" (which is missing the trailing period) will be judged incorrect.

Limits

The amount of power contained in each cell will not exceed 10,000.
1 ≤ T ≤ 30.
0 ≤ enx, exx < N.
0 ≤ eny, exy < M.

Small dataset

1 ≤ N, M ≤ 10.

Large dataset

1 ≤ N, M ≤ 100.

Sample


Input
 

Output
 
2
2 3
0 2 1 0
2 -1 5
3 -1 6
4 4
0 2 3 2
-1 1 1 2
1 1 1 1
2 -1 -1 1
1 1 1 1
Case #1: Mission Impossible.
Case #2: 7

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
7 points
Large input
10 points

Problem

Good programmers write fabulous comments. Igor is a programmer and he likes the old C-style comments in /* ... */ blocks. For him, it would be ideal if he could use this style as a uniform comment format for all programming languages or even documents, for example Python, Haskell or HTML/XML documents.

Making this happen doesn't seem too difficult to Igor. What he will need is a comment pre-processor that removes all the comment blocks in /*, followed by comment text, and by another */. Then the processed text can be handed over to the compiler/document renderer to which it belongs—whatever it is.

Igor's pre-processor isn't quite that simple, though. Here are some cool things it does:

  • The comments the pre-processor reads can be nested the same way brackets are nested in most programming languages. It's possible to have comments inside comments. For example, the following code block has an outer level of comments that should be removed by the comment pre-processor. The block contains two inner comments.
    printf("Hello /* a comment /* a comment inside comment */ 
            inside /* another comment inside comment */ 
            string */ world");
    
    After the pre-process step, it becomes:
    printf("Hello  world");
    
  • Igor recognizes comments can appear anywhere in the text, including inside a string "/*...*/", a constant number 12/*...*/34 or even in a character escape \/*...*/n

    Or more formally:

    text:
      text-piece
      text-piece remaining-text
    text-piece:
      char-sequence-without-/*
      empty-string
    remaining-text:
      comment-block text
    
    comment-block:
      /* comment-content */
    comment-content:
      comment-piece
      comment-piece remaining-comment
    comment-piece:
      char-sequence-without-/*-or-*/
      empty-string
    remaining-comment:
      comment-block comment-content
    
    char:
      letters
      digits
      punctuations
      whitespaces
    

    Our pre-processor, given a text, removes all comment-block instances as specified.

    Notes

  • Igor only needs to remove the comment in one pass. He doesn't remove additional comment blocks created as a result of the removal of any comment block. For example:
    //*no recursion*/* file header */
    should generate:
    /* file header */
  • The * character in any /* or /*cannot be re-used in another /* or */. For example the following does NOT form a proper comment block
    /*/
    

    Input

    A text document with comment blocks in /* and */. The input file is valid. It follows the specification of text in the problem statement. The input file always terminates with a newline symbol.

    Output

    We only have one test case for this problem. First we need to output the following line.

    Case #1:
    
    Then, print the document with all comments removed, in the way specified in the problem statements. Don't remove any spaces or empty lines outside comments.

    Limits

    The input program contains only:

  • Letters: a-z, A-Z,
  • Digits: 0-9
  • Punctuation: ~ ! @ # % ^ & * ( ) - + = : ; " ' < > , . ? | / \ { } [ ] _
  • Whitespace characters: space, newline

    Small dataset

    The small input contains a program of less than 2k bytes.

    Large dataset

    The large input contains a program of less than 100k bytes.

    Sample


    Input
     
    //*no recursion*/* file header
    ***********/************
    * Sample input program *
    **********/*************
    */
    int spawn_workers(int worker_count) {
      /* The block below is supposed to spawn 100 workers.
         But it creates many more.
         Commented until I figure out why.
      for (int i = 0; i < worker_count; ++i) {
        if(!fork()) {
          /* This is the worker. Start working. */
          do_work();
        }
      }
      */
      return 0; /* successfully spawned 100 workers */
    }
    
    int main() {
      printf("Hello /*a comment inside string*/ world");
      int worker_count = 0/*octal number*/144;
      if (spawn_workers(worker_count) != 0) {
        exit(-1);
      }
      return 0;
    }
    
    



    Output
     
    Case #1:
    /* file header
    ************************
    */
    int spawn_workers(int worker_count) {
      
      return 0; 
    }
    
    int main() {
      printf("Hello  world");
      int worker_count = 0144;
      if (spawn_workers(worker_count) != 0) {
        exit(-1);
      }
      return 0;
    }
    
    
  • You cannot ask questions at this time. Please email us at codejam@google.com.
    You have 0 submissions.