This page is still under construction.

Parts of this page are still being built. What you see may change.

Zero Division Checker

Time limit2sMemory limit512 MB

Summary
Given variable ranges, decide whether some assignment causes a division by zero in an 8-bit reverse Polish notation evaluation.
Level

Medium6 of 10

Topics
Stack, Brute force, Implementation, Math
Solved
No attempts yet

Problem

Morishita is in trouble. Anehara wrote a program for him, and it crashes.

The program Anehara wrote reads a reverse Polish notation expression and prints the result of evaluating it. The crash log suggests the cause is a division by zero. Maybe Morishita entered a bad expression, or maybe, just maybe, Anehara's program has a bug.

Morishita thought about reading Anehara's program, but it seems to be written in assembly, a language he does not understand, and just looking at it gives him a pounding headache.

So Morishita decided to have you write a program that checks whether an expression is bad. An expression is bad when evaluating it can divide by zero.

Anehara's code runs on a very old computer: the arithmetic is done on integers, and results are stored as 8-bit unsigned integers. For example, 255+1 becomes 0, and 3/2 becomes 1.

Oh, don't tell Anehara.

(Reference) Pseudocode that evaluates an expression in reverse Polish notation

s = empty stack
n = number of elements in the expression
for i in 1..n:
  if the i-th element of the expression is an integer:
    push that integer onto s
  if the i-th element of the expression is a variable:
    push the value of that variable onto s
  if the i-th element of the expression is an operator:
    pop a value from s and call it b
    pop a value from s and call it a
    if the operator is '+':
      let r = (a + b) % 256
    if the operator is '-':
      let r = (a - b + 256) % 256
    if the operator is '*':
      let r = (a * b) % 256
    if the operator is '/':
      let r = (a / b) % 256
    push r onto s
pop a value from s and take it as the result of evaluating the expression

Input

m
name1 lb1 ub1
...
namem lbm ubm
n
e1 e2 ... en
  • 0 ≤ m ≤ 100
  • 0 ≤ lbi ≤ ubi ≤ 255
  • 1 ≤ length of namei (1 ≤ i ≤ m) ≤ 20
  • 1 ≤ n ≤ 100
  • m is the number of variables, and namei, lbi, ubi are the name, lower bound, and upper bound of variable i.
  • n is the number of elements in the expression, and ei is the i-th element of the expression.
  • Each variable appears at most once in the expression.

Output

Print error in one line if the expression is bad, or correct if it is not.

Examples3

  1. Example 1

    Input
    1
    a 1 10
    3
    10 a /
    
    Expected output
    correct
    
  2. Example 2

    Input
    2
    a 1 10
    b 1 10
    5
    1 a b - /
    
    Expected output
    error
    
  3. Example 3

    Input
    1
    a 0 255
    7
    1 a 2 * 1 + /
    
    Expected output
    correct