P27859 [洛谷] [Language Month Competition 202308] Pink Rabbit Failed System Test
普及
题目描述

Problem Background

Pink Rabbit scored -154 in a CF contest, serving as a warning against failing system tests.

This is a hack problem. In this problem, you will be given two questions and two pieces of code that solve the respective problems. However, the provided code does not produce correct outputs for certain inputs. Incorrect outputs include:

  1. Outputting a wrong result.
  2. Running out of time.
  3. Producing undefined behavior at runtime. Currently, detectable undefined behavior only includes out-of-bounds array access.

For these two problems, you need to submit input data that meets the requirements separately, causing the given code to fail to produce correct outputs. You can use the 'Submit Answer' feature directly or submit a data generator written in any language.


Hint: If you use the Submit Answer feature, remember to switch the language back to the one you are using when submitting other problems.

Problem Description

Below are the descriptions of the two problems:

Problem 1

Given $n$ elements numbered from $1$ to $n$, you need to mark $k$ of these elements. If two elements have consecutive numbers, they are considered adjacent.

Calculate the possible minimum and possible maximum number of elements that are not marked but have at least one adjacent element marked.

Problem 2

Given a string containing only lowercase letters a, b, and c, determine if the string meets all the following characteristics:

  1. The string contains at least one a and one b, with all as before bs.
  2. If the string contains c, all as are before bs and cs, and all bs are before cs.
  3. The number of cs is equal to the number of as or the number of bs.

Input and Output Formats

Input Format

Problem 1

The input consists of a single line with two integers $n$ and $k$.

Problem 2

The input consists of a single line with a string $S$.

Output Format

Problem 1

The output consists of a single line with two integers, representing the possible minimum and maximum numbers respectively.

Problem 2

The output consists of a single line with a string. If $S$ meets the requirements, output YES; otherwise, output NO.

Sample Input and Output

Sample Input #1

6 3

Sample Output #1

1 3

Sample Input #2

aaabccc

Sample Output #2

YES

Notes

Sample Sets and Actual Input Notes

The two samples correspond to the sample input and output for the two problems.

If you use the 'Submit Answer' method directly, please name the input data files as 1.in and 2.in and compress them into a zip file for submission.

If you use a data generator, your generator should read an integer $x$ from standard input, where $1 \leq x \leq 2$, indicating the problem number for the test point, and then output the corresponding input data.

Clearly, your program should not read any of the content mentioned in the 'Input Format', nor should it output any of the content mentioned in the 'Sample Output'. You should not use the samples to test your program; they are merely illustrative examples for the two problems.

Data Scale Requirements

The data you provide must meet the following requirements:

  1. Fully comply with the 'Input Format' regulations, without any extra input, but may include a trailing newline.
  2. For Problem 1, $1 \leq n \leq 10^9$, $0 \leq k \leq n$.
  3. For Problem 2, $1 \leq |S| \leq 5000$ ($|S|$ represents the length of string $S$), and $S$ contains only lowercase letters a, b, c.

Target Code

You need to hack the following code:

Problem 1

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    if (k == n || k == 0) {
        cout << "0 0" << endl;
        return 0;
    }
    cout << "1 ";
    if (k * 3 <= n)
        cout << 2 * k << endl;
    else
        cout << n - k << endl;
    return 0;
}

Problem 2

#include <bits/stdc++.h>
using namespace std;

char str[5005];
int i, n, A, B, C;

int main() {
    cin >> str;
    n = strlen(str);
    if (str[0] != 'a') {
        cout << "NO" << endl;
        return 0;
    }
    for (i = 0; i < n; ++i) 
        if (str[i] != 'a') break;
    A = i;
    for (; i < n; ++i)
        if (str[i] != 'b') break;
    if (i == n || str[i] != 'c') {
        cout << "NO" << endl;
        return 0;
    }
    B = i - A;
    for (; i < n; ++i)
        if (str[i] != 'c') break;
    if (i != n) {
        cout << "NO" << endl;
        return 0;
    }
    C = n - B - A;
    if (C != A && C != B) 
        cout << "NO" << endl;
    else 
        cout << "YES" << endl;
    return 0;
}

The compilation options for the target code are -std=c++14 -fno-asm -O2. The compiler used is the g++ provided by Luogu. You can select the C++14 language in the 'Online IDE' to get an identical compilation environment.

Data Judgment

The data you provide must fully comply with the 'Data Scale Requirements'; otherwise, you will receive an Unaccepted result.

Timeout Judgment

We will check the program's running time periodically as it executes a certain number of instructions. We guarantee that the number of instructions between two checks is a quantity unrelated to the input scale, i.e., we check every $O(1)$ instructions. The number of instructions between two checks will not be too many, usually no more than 100 C++ statements.

If the program's running time exceeds $500 \text{ms}$, it is judged as running out of time 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 the array index before each explicit array element access to see if it exceeds the array range. If it does, 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 access.

Sample Program

This is a sample program to help you understand what you need to output, but it cannot produce correct hack data. Submitting this program directly will not earn you points.

#include <iostream>

using namespace std;

int main() {
  int taskId;
  cin >> taskId;
  if (taskId == 1) {
    cout << "" <<endl;
  } else if (taskId == 2) {
    cout << "" << endl;
  } else { // This else will not be executed
    cout << "Stupid Fusu!" << endl;
  }
}

If you use the 'Submit Answer' feature, ensure that opening the compressed package directly shows only the two .in files. This means the file structure must be:

ans.zip
 |---1.in
 |---2.in

The 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

About Evaluation Information

If the hack is successful, the corresponding test point information will be accepted. If other information is returned, it indicates that there is an error with the program itself.

For example, if TLE is returned, it does not mean that the corresponding program was successfully hacked to timeout; it means 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).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
6 3
样例输出
1 3