Adding some more judges, here and there.
[and.git] / NEERC / inspection / check.dpr
blobe6d52b0093e943ac6a2c70e9987ddacdba0b47e5
1 (*\r
2     Checker for NEERC'2009 Problem I: Inspection\r
3     (C) Pavel Mavrin\r
4 *)\r
5 \r
6 {$O+,Q+,R+}\r
7 {$APPTYPE CONSOLE}\r
8 \r
9 program Check;\r
11 uses\r
12   TestLib, SysUtils;\r
15 var\r
16   ja, pa: integer;\r
18   i, j, k, n, x, kk: Integer;\r
19   a, b: array[1..100, 1..100] of boolean;\r
21 begin \r
23   n := inf.readlongint;\r
24   fillchar(a, sizeof(a), 0);\r
25   fillchar(b, sizeof(b), 0);\r
26   for i := 1 to n do begin\r
27     k := inf.readlongint;\r
28     for j := 1 to k do begin\r
29       x := inf.readlongint;\r
30       a[i][x] := true;\r
31     end;\r
32   end;\r
34   pa := ouf.readlongint;\r
35   ouf.nextline;\r
36   for i := 1 to pa do begin\r
37     if (ouf.seekeoln) then Quit(_PE, Format('Empty line in output file: line %d', [i]));\r
38     k := ouf.readlongint;\r
39     if (k < 1) or (k > n) then Quit(_WA, Format('Node number %d is not in range', [k]));\r
40     while not ouf.seekeoln do begin\r
41       kk := ouf.readlongint;\r
42       if (kk < 1) or (kk > n) then Quit(_WA, Format('Node number %d is not in range', [kk]));\r
43       if not a[k][kk] then Quit(_WA, Format('There is no slope from %d to %d', [k, kk]));\r
44       b[k][kk] := true;\r
45       k := kk;\r
46     end;\r
47     ouf.nextline;\r
48   end;\r
50   for i := 1 to n do\r
51     for j := 1 to n do\r
52       if a[i][j] and not b[i][j] then Quit(_WA, Format('Slope from %d to %d was not inspected', [i, j]));\r
54   ja := ans.readlongint;\r
55   if (pa > ja) then \r
56     Quit(_WA, Format('Not optimal solution: %d instead of %d', [pa, ja]));\r
57   if (pa < ja) then \r
58     Quit(_FAIL, Format('Jury solution is not optimal : %d instead of %d', [pa, ja]));\r
59   Quit(_OK, Format('%d paths', [pa]));\r
60 end.\r