No.8117 Simple Programming Language
タグ : / 解いたユーザー数 57
作問者 : 👑
yimiya(いみや)
Iroha_3856
Problem Statement
for-loop-san, who loves simple and refined things, has created a programming language "Simplang" in which nesting of depth $\color{red} 2$ or more is impossible.
Using Simplang, write a program that solves the following problem.
Problem
Problem Statement
You are given $2$ grids with $H$ rows and $W$ columns, called grid $A,~$grid $B$, respectively.
The cell in the $i$-th row from the top and the $j$-th column from the left of a grid is called cell $(i, j)$.
Cell $(i, j)$ of grid $A$ contains the integer $A_{i, j}$, and cell $(i, j)$ of grid $B$ contains the integer $B_{i, j}$.
Here, it is guaranteed that there is exactly one cell $(i, j)$ such that $A_{i, j} \neq B_{i, j}$. Find that cell $(i, j)$.
Constraints
- $H, W$ are integers satisfying $1 \leq H, W \leq 10$.
- $A_{i, j}, B_{i, j}$ are integers satisfying $1 \leq A_{i, j}, B_{i, j} \leq 100$.
- There is exactly one cell $(i, j)$ such that $A_{i, j} \neq B_{i, j}$.
Input
- $H$ is given as the constant
H. - $W$ is given as the constant
W. - $A_{i, j}$ is given as the constant
A[i,j]($1 \leq i \leq H, ~ 1 \leq j \leq W$). - $B_{i, j}$ is given as the constant
B[i,j]($1 \leq i \leq H, ~ 1 \leq j \leq W$).
Output
Output the answer $(i, j)$ using the return statement.
Sample
Input
H: 3 W: 3 A: 1 2 3 4 5 6 7 8 9 B: 1 2 3 4 5 6 7 9 9
Output
(3,2)
Cell $(3, 2)$ of grid$A$ contains the integer $8$, while cell $(3, 2)$ of grid $B$ contains the integer $9$.
Thus $A_{3, 2} \ne B_{3, 2}$, so output $(3, 2)$.
An overview of the Simplang language specification is given below.
Note that if you output a Simplang program that does not satisfy this specification, the judge result will be WA.
Overview of the Programming Language "Simplang"
The notable specifications of Simplang are as follows.
For sample programs and the source code of the interpreter, see Qiita: yukicoder April Fool Contest 2025 "Simple Programming Language" (limited access).
- Value literals can be integers at least $0$ and less than $10^{100}$. (For example, to define $314$, write
314.) - Variables can be used in the form
$n(where $n$ is an integer at least $0$ and less than $10^{100}$). - For example,
$0,$1,$998244353, and so on can be used. - All variables are initially initialized to $0$.
- A value is assigned to a variable in the form
変数 = 値(variable = value). For example,$1 = 2assigns the integer $2$ to variable $1$. - To compute values, the binary operators
+,-,*,/,%can be used. +denotes addition. For example,$1 + $2denotes (variable $1$) $+$ (variable $2$), and$1 + 1denotes (variable $1$) $+$ $1$.-denotes subtraction. For example,$1 - $2denotes (variable $1$) $-$ (variable $2$), and$1 - 1denotes (variable $1$) $-$ $1$.*denotes multiplication. For example,$1 * $2denotes (variable $1$) $\times$ (variable $2$), and$1 * 10denotes (variable $1$) $\times$ $10$./denotes floor division. For example,$1 / $2denotes the largest integer not exceeding (variable $1$) $\div$ (variable $2$).%denotes the remainder operation. For example,$1 % $2denotes the remainder of (variable $1$) divided by (variable $2$).- Note that the specifications of floor division and the remainder operation differ from those of
C,C++,Java, and so on. - The order of evaluation is the same as in ordinary arithmetic (except that the remainder operation has the same precedence as multiplication and floor division), and parentheses
()can be used to change the precedence. - During computation, you must not produce an integer $x$ that goes beyond the range $x < |10^{100}|$.
- During computation, you must not attempt floor division by $0$ or take a remainder when dividing by $0$.
- Note that unary operators and compound assignment operators do not exist.
- Each constant can be used as a value, but no new value can be assigned to it.
- For example,
$0 = A[H,$1]assigns to variable $0$ the integer written in cell $(H, $ variable $1)$ of grid $A$. - For
A[i,j],B[i,j], $i, j$ must be integer values satisfying $1 \leq i \leq H, ~ 1 \leq j \leq W$. - Note that they are 1-indexed.
- As control structures, only
if-endstatements andwhile-endstatements can be used. - The condition of an
if-endstatement or awhile-endmust be written in the form値 op 値(value op value) using a comparison operator $op$. - The operations available as comparison operators are as follows.
<: True if the left side is less than the right side, and false otherwise. For example,$1 < Hreturns true when (variable $1$) $<$ $H$.<=: True if the left side is less than or equal to the right side, and false otherwise. For example,$1 <= Hreturns true when (variable $1$) $\leq$ $H$.>: True if the left side is greater than the right side, and false otherwise. For example,$1 > Hreturns true when (variable $1$) $>$ $H$.>=: True if the left side is less than the right side, and false otherwise. For example,$1 >= Hreturns true when (variable $1$) $\geq$ $H$.==: True if the left side is equal to the right side, and false otherwise. For example,$1 == Hreturns true when (variable $1$) $=$ $H$.!=: True if the left side is not equal to the right side, and false otherwise. For example,$1 != Hreturns true when (variable $1$) $\ne$ $H$.- A condition cannot be assigned to a variable.
- When answering cell $(i, j)$, write the
returnstatement on the last line of the code in the following form.
What is an if - end statement?
An if - end statement is a control structure written in the following form.
if(条件) 条件が真であるときのみ実行される ... end
For example, a program that takes the absolute value of variable $1$ is as follows.
if($1 < 0) $1 = 0 - $1 end
What is a while - end statement?
A while - end statement is a control structure written in the following form.
while(条件) 条件が真である間だけ繰り返し実行される ... end
For example, a program that stores the sum of $A_{1, 1}, A_{1, 2}, \cdots, A_{1, W}$ in variable $0$ is as follows.
$1 = 1 while($1 <= W) $0 = $0 + A[1,$1] $1 = $1 + 1 end
return(i,j)
- Both line $i$ and line $j$ contain
endas a substring. - For every $k$ with $i < k < j$, line $k$ does not contain
if,whileas a substring.
What does "nesting of depth $2$ or more" mean?
A program has nesting of depth $2$ or more if there exist $1 \leq i < j \leq P$ (where $P$ is the number of lines of the submitted program) satisfying the following conditions.
For example, the following program has nesting of depth $2$ or more, so it is not a valid Simplang program.
$0 = 0
$1 = 0
while($0 < 3)
if($0 == 2)
$1 = $0
end
$0 = $0 + 1
end
return($0, $1)
Conversely, the following program does not have nesting of depth $2$ or more, and it is a valid Simplang program.
$0 = 0 while($0 < 3) $0 = $0 + 1 end if($0 == 3) $1 = $0 + 1 end return($0, $1)
$1 = H: The constant $H$ is assigned to variable $1$.while($0 < 2): If variable $0$ is less than $2$, the body of thewhile-endstatement is repeated. Since variable $0$ is initialized to $0$, the condition is satisfied.$0 = $0 + 1: Variable $0$ $+$ $1$ is assigned to variable $0$.$1 = $1 - W: Variable $1$ $-$ constant $W$ is assigned to variable $1$.while($0 < 2): The condition is checked. This time, the condition is satisfied.$0 = $0 + 1: Addition is performed in the same way.$1 = $1 - W: Subtraction is performed in the same way.while($0 < 2): The condition is checked. This time, the condition is not satisfied, so execution jumps to immediately after theendstatement.return($0,$1): The answer is $($variable $0$, variable $1)$.
A concrete example of the flow of program execution
For example, consider the following Simplang program.
$1 = H while($0 < 2) $0 = $0 + 1 $1 = $1 - W end return($0, $1)
In this case, it is executed in the following order.
In this way, the processing completes in $9$ executions.
Input
There is no input from standard input.In the judge, $H, W, A, B$ are given to the Simplang program printed to standard output.
Output
Print to standard output a Simplang program that finds the cell $(i, j)$ satisfying the conditions of the problem statement.
If you write Simplang code directly, you can submit it as is by selecting Text (cat 8.3) as the submission language.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。