QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 256 MB 總分: 100 互動

#403. Memory2

统计

There are $2N$ cards in total, each having one integer between $0$ and $N-1$ written on its face, with each integer appearing on exactly two cards. You and JOI are practicing a game called Concentration using these $2N$ cards.

At the start of the practice, the cards are placed face-down in a row on a table. We call the $(i+1)$-th card from the left the card $i$ ($0 \le i \le 2N-1$). Let $A_i$ ($0 \le i \le 2N-1$) be the integer written on the face of card $i$. Initially, neither you nor JOI knows the values of $A_i$ ($0 \le i \le 2N-1$).

You and JOI can repeat the following interaction up to $K$ times:

  1. You specify two cards out of the $2N$ cards.
  2. JOI turns over the two specified cards and secretly looks at the integers written on them. If the integers on the two cards are equal, he remembers that value and tells it to you. Otherwise, he remembers the integer that is easier for him to remember among the two and tells it to you.

The ease of remembering an integer for JOI is represented by $N$ integers $P_0, P_1, \dots, P_{N-1}$. These integers satisfy the following two conditions:

  • $0 \le P_i \le N-1$ ($0 \le i \le N-1$).
  • $P_i \neq P_j$ ($0 \le i < j \le N-1$).

For JOI, integer $i$ is easier to remember than $j$ if and only if $P_i < P_j$.

Your task is to identify the integer written on each card by interacting with JOI at most $K$ times. Note that you do not know the values of $P_0, P_1, \dots, P_{N-1}$ which represent the ease of remembering integers for JOI.

Implementation Details

You must write a program that implements the method to identify the integer written on each card. Your program must include Memory2_lib.h.

Your program must implement the following routine:

  • void Solve(int T, int N)

This routine is called exactly once for each test case. The argument $T$ represents the subtask number, and $N$ represents that there are $2N$ cards.

This routine must identify the integers written on the cards by calling Flip and answer the contents by calling Answer.

You can call the following functions in your program:

  • int Flip(int I, int J)

This function is called when you specify cards to JOI. The arguments $I$ and $J$ are the indices of the cards JOI turns over.

$I$ and $J$ must be distinct integers between $0$ and $2N-1$. Calling Flip with arguments that do not satisfy this results in Wrong Answer [1].

This function returns the integer $A_I$ if $A_I = A_J$, otherwise it returns the integer among $A_I$ and $A_J$ that is easier for JOI to remember.

Calling this function more than $K$ times results in Wrong Answer [2].

  • void Answer(int I, int J, int X)

This function indicates that you have identified the cards on which the integer $X$ is written.

The arguments $I, J, X$ must satisfy the following conditions:

  • $0 \le I \le 2N-1$.
  • $0 \le J \le 2N-1$.
  • $I \neq J$.
  • $A_I = A_J = X$.

Calling Answer with arguments that do not satisfy these results in Wrong Answer [3].

The argument $X$ must be different from the argument $X$ in any previous call. If this is not satisfied, it results in Wrong Answer [4].

This function must be called exactly $N$ times. If this is not satisfied, it results in Wrong Answer [5].

You are free to implement other routines for internal use or declare global variables. However, your submission must not interact with standard input/output or any other files in any way.

Constraints

All input data satisfy the following conditions:

  • $1 \le N \le 50$.
  • $0 \le P_i \le N-1$ ($0 \le i \le N-1$).
  • $P_i \neq P_j$ ($0 \le i < j \le N-1$).
  • $0 \le A_i \le N-1$ ($0 \le i \le 2N-1$).
  • For any $x$ ($0 \le x \le N-1$), there are exactly two indices $i$ ($0 \le i \le 2N-1$) such that $A_i = x$.

Subtasks

Subtask 1 [10 points]

The following conditions are satisfied: $T = 1$. $K = 10\,000$. * $P_i = i$ ($0 \le i \le N-1$).

Subtask 2 [50 points]

The following conditions are satisfied: $T = 2$. $K = 400$. * $P_i = i$ ($0 \le i \le N-1$).

Subtask 3 [40 points]

The following conditions are satisfied: $T = 3$. $K = 300$.

Examples

The following table shows an example of the input read by the sample grader and the corresponding routine calls.

Input Routine Call Return Value
1 3 10000 Flip(0, 2) 1
0 1 2 Flip(0, 4) 1
1 0 2 0 1 2 Flip(1, 2) 0
Answer(0, 4, 1)
Flip(1, 3) 0
Flip(5, 2) 2
Flip(4, 5) 1
Answer(1, 3, 0)
Answer(5, 2, 2)

Note that the function calls in this example are not necessarily meaningful calls.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.