题目描述
Problem Background
This is a hack problem. In this type of problem, you will be given several questions and several pieces of code that solve the corresponding questions. However, the provided code does not produce correct outputs for certain inputs. Situations where the code fails to produce correct outputs include:
- Outputting incorrect results.
- Running out of time.
- Producing some undefined runtime behaviors. Currently, detectable undefined behaviors only include array out-of-bounds.
For each question, you need to submit an input dataset that meets the requirements, causing the given code to fail to produce correct outputs. You can directly use the 'Submit Answer' feature or submit a data generator written in any language.
Problem Description
The following provides the problem descriptions for three questions:
Question 1
Given two integers $a, b$, calculate the value of $a + b$.
Question 2
Given a string $s$ containing only lowercase letters, count how many lowercase a letters are in $s$.
Question 3
Given an array $a$ of length $n$ (indexed from 0), for all $i$ satisfying $0 \leq i < n$, let $b_i = a_{(i + 1) \bmod n} - a_i$, where $(i + 1) \bmod n$ denotes the result of $i + 1$ modulo $n$. Calculate the array $b$.
Input and Output Formats
Input Format
Question 1
The input contains one line with two integers separated by a single space, representing $a$ and $b$ respectively.
Question 2
The input contains one line with a string $s$.
Question 3
The input contains two lines.
The first line is an integer representing the sequence length $n$.
The second line contains $n$ integers separated by single spaces, representing $a_1, a_2, \dots a_n$ respectively.
Output Format
Question 1
Output one line with one integer representing the answer.
Question 2
Output one line with one integer representing the answer.
Question 3
Output one line with $n$ integers representing $b_0, b_1, \dots b_{n - 1}$ respectively. The integers should be separated by single spaces.
Sample Input and Output
Sample Input #1
1 1
Sample Output #1
2
Sample Input #2
ahpphsomhspldaaaaaa
Sample Output #2
7
Sample Input #3
2
1 1
Sample Output #3
0 0
Notes
Sample Group and Actual Input Explanation
The three samples correspond to the sample input and output for the three questions.
If you use the 'Submit Answer' method, please name the three input data files as 1.in, 2.in, and 3.in, and compress them into a zip file for submission.
If you use a data generator, your generator can read an integer $x$ from standard input, where $1 \leq x \leq 3$ represents the problem number for the test point, and then output the corresponding input data.
Clearly, your program should not read any content mentioned in the 'Input Format', but should construct them, nor should it output any content mentioned in the 'Output Format' (only output the constructed input data). You should not use the samples to test your program; these are just sample explanations for the three questions.
Data Size Requirements
The data you provide must meet the following requirements:
- Fully comply with the 'Input Format' regulations, without any extra input, but can have trailing spaces at the end of lines and a carriage return at the end of the text.
- For Question 1, $1 \leq a, b \leq 2 \times 10^9$.
- For Question 2, $s$ contains only lowercase English letters, with ASCII values in the range $[97, 122]$, and the length of $s$ should be $\geq 1$ and not exceed $10^6$.
- For Question 3, $1 \leq n \leq 100$, $-10^9 \leq a_i \leq 10^9$.
Target Code
You need to hack the following code:
Question 1
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a + b << endl;
}
Question 2
#include <cstring>
#include <iostream>
using namespace std;
char s[1000005];
int main() {
cin >> s;
int ans = 0;
for (int i = 0; i < strlen(s); ++i) {
if (s[i] == 'a')
++ans;
}
cout << ans << endl;
return 0;
}
Question 3
#include <iostream>
using namespace std;
const int maxn = 100;
int a[maxn], b[maxn];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) {
b[i] = a[i + 1] - a[i];
if (i + 1 == n)
b[i] = a[0] - a[i];
}
for (int i = 0; i < n; ++i) {
cout << b[i] << " \n"[i == (n - 1)];
}
}
The compilation options for the target code are -std=c++14 -fno-asm -O2. The compiler is the g++ provided by Luogu. You can select the C++14 language in the 'Online IDE' to get an identical compilation environment.
Scoring Explanation
This problem consists of three test points, corresponding to the three questions, each worth 10 points.
Data Judgment
The data you provide must fully comply with the 'Data Size Requirements'; otherwise, it will result in an unaccepted outcome.
Timeout Judgment
The program's execution time is checked periodically. We guarantee that the number of instructions between two checks is a quantity unrelated to the input size, i.e., $O(1)$ instructions are checked. The number of instructions between two checks is not too many, generally not exceeding 100 C++ statements.
If the program's execution time exceeds $500 \text{ms}$, it is judged as a timeout and returns an accepted result.
Incorrect Result Judgment
If the program ends within the specified time and produces an output, we will compare this output with the completely correct output. If they differ, it is judged as a successful hack, returning an accepted result.
Undefined Behavior Judgment
We will check whether the array index exceeds the array range before each explicit array element call. If it exceeds, it is judged as a successful hack, returning an accepted result.
This means that if you want to hack through undefined behavior, you can only hack explicit array element calls.
Sample Program
This is a sample program to help you understand what you need to output, but it cannot produce correct hack data. Directly submitting this program will not earn points.
#include <iostream>
using namespace std;
int main() {
int taskId;
cin >> taskId;
if (taskId == 1) {
cout << "1 1" <<endl;
} else if (taskId == 2) {
cout << "aba" << endl;
} else if (taskId == 3) {
cout << "2\n1 1" << endl;
} else { // This else will not be executed
cout << "OvoOvoovOovO" << endl;
}
}
If you use the 'Submit Answer' feature, please ensure that after opening the zip file, you can and can only directly see the three .in files. This means the file structure must be:
ans.zip
|---1.in
|---2.in
|---3.in
The three files should not be contained in an additional folder, i.e., the file structure should not be:
ans.zip
|---ans(folder)
|---1.in
|---2.in
|---3.in
Explanation of Evaluation Information
If the hack is successful, the corresponding test point information is accepted. If other information is returned, it indicates that the program itself has errors.
For example, if TLE is returned, it does not mean that the corresponding program was successfully hacked to timeout, but rather that the data generator itself timed out, and the test point does not earn points.
Specifically, returning UKE results may indicate illegal data (extra content, missing content, or data range not meeting requirements).
Special Notes on This Problem
This problem is the first hack problem and also a trial problem. The intention of this type of problem is to allow players to practice targeted error-prone points in the code. Within a week after the 'Luogu Beginner Contest #8' ends, you can attempt to attack the special judge without penalty (except for maliciously clogging the judge and repeated submissions). Permitted attack behaviors include but are not limited to attempting to submit various input data in hopes of causing the special judge to return incorrect results. If an attack is successful, please post in the discussion area and at 一扶苏一.
Special reminder: Maliciously clogging the judge includes repeatedly submitting data that causes the program to time out and has no essential differences.
It should be noted that under the Le Duo competition system, repeated attempts to submit will lower the score for this problem.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分