Ուղարկել | Բոլոր լուծումները | Լավագույն լուծումները | Վերադառնալ ցուցակին |
ACM_0223 - SELF-INTERSECTING PATH |
This sounds like a nice contest problem, doesn’t it? We want to give you an idea what it is like to organize a programming contest. Therefore, your task is to write a validator for the problem described above. (You may read more about validators in the validate problem.
Input
The input contains several test cases. Each test case consists of two lines. The first line contains a single integer N (1 ≤ N ≤ 106), the number of instructions that form the robot’s program. The second line contains N space-separated integers a1 a2 a3 . . . aN (1 ≤ ai ≤ 109), an encoded program for the robot, as described above.
Output
For each test case, print exactly one line. If the given program describes a path that does not intersect itself, print “OK”. Otherwise output a single integer M (0 ≤ M < N ), the maximum number of instructions from the beginning of the program that describe a valid path. That means the path described by the program consisting of instructions a1 a2 a3 . . . aM does not intersect itself and M is maximal with this property.
Examples
№ |
stdin |
stdout |
1 |
7 |
3 |
Ավելացրեց. | Հրանտ Հովհաննիսյան |
Ամսաթիվ. | 2014-10-08 |
Ժամանակի սահմանափակումը. | 1s |
Ծրագրի տեքստի սահմանափակումը. | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Լեզուներ. | Բոլորը բացի ASM32 ASM64 GAWK CLPS CLOJURE D ERL FSHARP FORTRAN GOSU HASK ICON ICK NEM NIM OBJC-CLANG PICO PIKE PYPY PYPY3 PY_NBC RUST SCM guile CHICKEN SED TCL WHITESPACE |
Աղբյուրը. | CTU Open 2014.H |