QOJ.ac

QOJ

時間限制: 5 s 記憶體限制: 512 MB 總分: 100 通信

#295. Encoding Interference

统计

Please note:

  1. On QOJ, you do not need to worry about the restriction "the following keywords are not allowed" described in the problem; the two programs you submit will be run separately.
  2. When submitting, you need to submit code.cpp and decode.cpp, which must include code.h and decode.h respectively.

Alice and Bob are currently in two far-apart countries. Because they cannot meet, they can only transmit information through the Internet. Simply put, Alice sends a $q$-ary code of length $k$ to Bob each time. A $q$-ary code means each digit of the code is a non-negative integer less than $q$.

However, during transmission, the information is often subject to some interference. Bob already knows that the scale of this interference is a non-negative integer $d$. If we let $e = \lfloor (d-1) / 2 \rfloor$ (i.e., $d-1$ divided by 2, rounded down), then the interference will cause at most $e$ digit errors. Here $e \le k$. If $e = 0$, no errors will occur. If $e = k$, for a code of length $k$, it might become any code of length $k$ due to interference. At the same time, Bob also knows that the scale of this interference does not change with the increase of the code length, but is determined only by geographical factors. That is to say, if Alice transmits a $q$-ary code of length $k+1$ to Bob, the scale of interference received during transmission is still $d$. However, the increase in code length will bring more cost issues.

Bob hopes to design an error-correcting system. By sending a $q$-ary code of length $n \ge k$, he can avoid receiving incorrect information due to interference. This error-correcting system consists of two parts: the CODE system and the DECODE system. Bob hopes that after designing them, he will send the CODE system to Alice and keep the DECODE system for himself.

Afterwards, Bob and Alice agree: each time before Alice sends a code I of length $k$, she first obtains a code II of length $n$ through the CODE system (here both code I and code II are $q$-ary codes), and then sends code II to Bob. Code II will be subjected to interference of scale $d$ during transmission, so the code III actually received by Bob may be different from code II. Finally, Bob uses the DECODE system to calculate code I from code III. This completes the error-correcting work.

Note: The code sent by Alice each time is always a $q$-ary code of length $k$, and the scale of interference received is always $d$. The length of the transmitted code directly determines the transmission cost (here, transmitting information over the Internet is not considered free, but requires a cost proportional to the length of the transmitted code). Therefore, Bob hopes that on the basis of being able to achieve correct error correction, the length $n$ of code II sent each time is as small as possible.

Program Requirements

This problem requires contestants to write two independent programs, corresponding to the CODE system and the DECODE system respectively.

For C/C++ contestants, you need to submit code.h and decode.h.

The procedure in code.h:

int Alice_solve(int k, int d, int q, int B[]);

is for the CODE system. For given coefficients $k$, $d$, $q$ and code I (stored in B[1] to B[k]), it needs to return the length $n$ of code II, and store code II in B[].

The procedure in decode.h:

void Bob_solve(int k, int d, int q, int B[]);

is for the DECODE system. For given coefficients $k$, $d$, $q$ and code III, assuming the length of code III is $n$, then B[1] to B[n] stores code III. It needs to find the earliest code I (the original code sent by Alice) through B[], and store it in B (B[1] to B[k]).

For code.h and decode.h, we require that there is no mutual calling relationship between the contestant's two programs, and we forbid the appearance of strings like #define, #if in the programs. The file forbidden_c.txt provided in the contest lists the strings that are forbidden to appear in the .h files submitted by C/C++ contestants.

We provide a grading program code_administrator.cpp. After the contestant's code (code.h and decode.h) is submitted, we will compile code_administrator.cpp together with code.h and decode.h (code_administrator.cpp calls code.h and decode.h). Note that code_administrator.cpp reads information from the input file code.in and tests the error-correcting system provided by the contestant, and the test results will be fed back to the output file code.out. It should be noted that because code.h and decode.h are compiled as one program, duplicate variable name definitions (including duplication with variables in code_administrator.cpp) may cause compilation failure.

We provide a reference code, code.h and decode.h, so that contestants can better understand the work to be completed.

For Pascal contestants, you need to submit code.pas and decode.pas.

In code.pas, the first four lines must be:

unit code;
interface
function Alice_solve(k,d,q:longint;var B:array of longint):longint;
implementation

and the last two lines must be:

begin
end.

For decode.pas, the last two lines have the same requirement, and the first four lines must be:

unit decode;
interface
procedure Bob_solve(k,d,q:longint;var B:array of longint);
implementation

Details can be found in the files code.pas and decode.pas provided in the contest.

Contestants only need to write the content inside the Alice_solve and Bob_solve procedures. Variables can be declared between implementation and the procedure declaration. The contestant's code.pas and decode.pas must not call each other. For this reason, forbidden_pas.txt provided in the contest lists all strings that should be forbidden in the programs submitted by Pascal contestants.

We provide a grading program code_administrator.pas. Note that code_administrator.pas reads information from the input file code.in and tests the error-correcting system provided by the contestant, and the test results will be fed back to the output file code.out.

We provide a reference code, code.pas and decode.pas, so that contestants can better understand the work to be completed.

Input Format

For the input file code.in, the first line gives the coefficients $k$, $d$, $q$.

The next line has an integer $T$, representing that Alice wants to transmit $T$ $q$-ary codes of length $k$ to Bob.

The next $T$ lines, each containing $k$ non-negative integers, describe a $q$-ary code.

In the contest, we provide a valid code.in for contestants to test.

Output Format

The output file has a total of $T$ lines, generated by code_administrator. Each line starts with the string YES or NO, indicating whether the error-correcting system is correct. If it is YES, it is followed by an integer $n$, which is the length of code II. In the contest, contestants can obtain a valid output file code.out through the provided program and input file code.in.

Scoring

For the output file code.out, if NO appears, the error-correcting system fails and receives 0 points. Otherwise, the maximum length of code II is considered. According to the grading coefficients $p(1)$ to $p(10)$, we give the score of this test point. If the maximum length of code II does not exceed $p(u)$, you will get at least $u$ points, and the score of each test point does not exceed 10 points.

Constraints

Test Case $k$ $d$ $q$
1 $\le 10$ 7 $\le 4$
2 $\le 20$ 5 2
3 116 3 3
4 502 3 2
5 $\le 100$ 5 $1000 \le q \le 10000$
6 $\le 50$ 7 $1000 \le q \le 10000$
7 $\le 40$ 9 $1000 \le q \le 10000$
8 120 4 2
9 247 4 2
10 42 8 2

For all data, $T \le 100$.

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.