Comparing Fractions

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

This problem is interactive. Refer to the Interaction section below for a better understanding.

Today was the first class of CS999.

First, you have learned non-negative integer less than or equal to 4×10184 \times 10^{18}.
You have also learned the addition, subtraction, and comparison of two integers.

The homework is to compare two fractions AB\frac{A}{B} and CD\frac{C}{D}. Professor told you that you can solve homework only using classroom materials.

You are only allowed to use the following operations:

  • Addition: For two integers aa and bb, you can calculate a+ba+b. The result should be less than or equal to 4×10184 \times 10^{18}.
  • Subtraction: For two integers aa and bb, you can calculate aba-b. The result should be non-negative.
  • Comparison: For two integers aa and bb, you can know whether two elements are equal or which one is greater.

By using these operations, you have to compare two fractions.

제한

  • 1A,B,C,D1091 \leq A, B, C, D \leq 10^9

힌트

Interaction Protocol

You cannot get AA, BB, CC, nor DD directly in this problem.
Instead, you can use some operations to a hidden array of length 10610^6; X_1,X_2,,X_106X\_1, X\_2, \cdots, X\_{10^6}.

Initially, XX satisfies X_1=AX\_1=A, X_2=BX\_2=B, X_3=CX\_3=C, X_4=DX\_4=D, and X_i=0X\_i=0 for ii greater than 44.

You can use the following commands to do operations:

  • To add two elements of XX, print a string "+ i j k" (1i,j,k1061 \le i, j, k \le 10^6). X_iX\_i will be replaced with a value of X_j+X_kX\_j+X\_k.
    To perform this operation, X_j+X_kX\_j + X\_k must be less than or equal to 4×10184 \times 10^{18}. If not, you will receive a verdict of "Wrong Answer". Nothing will be given to the input.

  • To subtract two elements of XX, print a string "- i j k" (1i,j,k1061 \le i, j, k \le 10^6). X_iX\_i will be replaced with a value of X_jX_kX\_j-X\_k.
    To perform this operation, X_jX_kX\_j \ge X\_k must be satisfied. If not, you will receive a verdict of "Wrong Answer". Nothing will be given to the input.

  • To compare two elements of XX, print a string "< i j" (1i,j1061 \le i, j \le 10^6). A line containing one integer will be given to the input. 

    • "-1" will be given when X_i\<X_jX\_i\<X\_j.
    • "0" will be given when X_i=X_jX\_i=X\_j.
    • "1" will be given when X_i>X_jX\_i>X\_j.

After successfully comparing AB\frac{A}{B} and CD\frac{C}{D},

  • If AB<CD\frac{A}{B} < \frac{C}{D}, print "! -1".
  • If AB= CD\frac{A}{B} = \frac{C}{D}, print "! 0".
  • If AB> CD\frac{A}{B} > \frac{C}{D}, print "! 1".

If you ask more than 200,001200\\,001 commands or make an invalid query, the interactor will terminate immediately and your program will receive the verdict "Wrong Answer".

Scoring

If your comparison is incorrect, your score will be 00.

Otherwise, the score of the program will be graded with three factors:

  • i_maxi\_{max}, the maximum index of the array XX you have used in operations.
  • n_opn\_{op}, the number of operations you have done. Answer command will not be counted.
  • X_maxX\_{max}, the maximum number in the array XX during operations.