Autohamil
SRM 684 · 2016-03-02 · by subscriber
Problem Statement
A deterministic finite automaton is a machine that processes strings. The automaton has a finite set of possible states. The states are numbered 0 through n-1, where n is the number of states. At any moment the automaton is in one of those states. At the beginning, the automaton is in state 0.
The automaton processes a string by reading it one character at a time. The automaton has a program (also called a "transition function"): a set of instructions that tell it how to change its state. Each instruction has the form "if you are in state X and you read the character Y, change your state to Z". There is exactly one instruction for each valid combination (X,Y). You are given the description of a specific deterministic finite automaton:- If you are in state i and you read the character '0', change your state to z0[i].
- If you are in state i and you read the character '1', change your state to z1[i].
Constraints
- z0 and z1 will contain exactly n elements.
- n will be between 1 and 50, inclusive.
- Each element in z0 and z1 will be between 0 and n - 1, inclusive.
{0,1}
{0,1}
Returns: "Does not exist"
Regardless of what string you choose, the automaton will remain in state 0 during the entire computation. It will never change its state from 0 to 1.
{1,1}
{1,1}
Returns: "Exists"
Any non-empty string works.
{1,2,2}
{2,2,2}
Returns: "Exists"
For example, the string "01" works: The automaton begins in state 0. The automaton reads the character '0' and changes its state to 1. The automaton reads the character '1' and changes its state to 2.
{2,2,2}
{2,2,2}
Returns: "Does not exist"
{1,2,0,3}
{3,2,0,3}
Returns: "Exists"
Submissions are judged against all 217 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Autohamil with a public method string check(vector<int> z0, vector<int> z1) · 217 test cases · 2 s / 256 MB per case