CF2264F.Deranged Calculator

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Hacks are disabled on this problem.

We are excited to introduce a new language for this Codeforces round: the Deranged Calculator language (DC).

The DC language is a simplified programming language with some weird constraints. It only supports a single expression on one line and only has a single positive integer nn as input. The syntax of the expression is similar to that of most programming languages (in fact, the expression is valid Python), but it is very limited:

  • Expressions consist of the input parameter nn, parenthesized expressions, and calls to the round function. These are joined together by the operators +, -, *, and /.
  • Grouping with parentheses () can be used to change the order of operations, as usual.
  • The operators * and / have equal precedence and take precedence over + and -, which also have equal precedence. Operators of equal precedence are evaluated from left to right.
  • The round function takes a single expression as its argument and rounds its value to the nearest integer, rounding up when the fractional part is exactly 0.50.5. (For example, round(n/(n-n-n-n)) will always evaluate to 00, because x/(x−x−x−x)=−12x/(x-x-x-x)=-\frac{1}{2} for a positive integer xx. The fractional part is 0.50.5, so it will be rounded up to 00.)
  • Only the input value nn can be used; no numeric constants are allowed in the program.
  • All operations are performed using exact fractional arithmetic, so division does not round and can produce fractions.

A derangement of nn numbers is a permutation of those numbers in which none of the numbers appears in its original position. For example, the derangements of the sequence [1,2,3][1, 2, 3] are [2,3,1][2, 3, 1] and [3,1,2][3, 1, 2].

You are given a single integer kk. Your job is to make a valid DC program that, for every integer nn (2≤n≤k2 \le n \le k), calculates the number of derangements of the sequence [1,2,…,n][1, 2, \ldots, n], when nn is given as input to the DC program. The length of the program should not exceed 10 00010\,000 characters.

A local testing tool is provided to help you develop your solution. It can be found under Contest Materials.

本题禁用 hack。

我们很高兴在本次 Codeforces 比赛中引入一门新语言:错位计算器语言(Deranged Calculator language,简称 DC)。

DC 语言是一门简化版的编程语言,具有一些奇特的限制。它仅支持单行单表达式,且唯一输入为一个正整数 nn。该表达式的语法与大多数编程语言类似(实际上,该表达式是合法的 Python 表达式),但功能非常受限:

  • 表达式由输入参数 nn、括号包围的子表达式以及对 round 函数的调用组成;这些成分通过运算符 +、-、* 和 / 连接。
  • 可使用圆括号 () 进行分组以改变运算顺序,规则与常规一致。
  • 运算符 * 和 / 优先级相同,且高于 + 和 -;而 + 和 - 的优先级也相同。同级运算符按从左到右顺序求值。
  • round 函数接收一个表达式作为其唯一参数,并将其值四舍五入到最接近的整数;当小数部分恰好为 0.50.5 时向上取整。(例如,round(n/(n-n-n-n)) 的结果恒为 00,因为对任意正整数 xx,有 x/(x−x−x−x)=−12x/(x-x-x-x)=-\frac{1}{2},其小数部分为 0.50.5,故向上取整得 00。)
  • 程序中仅允许使用输入值 nn,不得出现任何数值常量。
  • 所有运算均采用精确的分数运算,因此除法不进行舍入,可能产生分数结果。

nn 个数的错位排列(derangement)是指这 nn 个数的一个排列,其中每个数都不出现在其原始位置上。例如,序列 [1,2,3][1, 2, 3] 的错位排列为 [2,3,1][2, 3, 1] 和 [3,1,2][3, 1, 2]。

你将获得一个整数 kk。你的任务是编写一个合法的 DC 程序,使得:对每个整数 nn(满足 2≤n≤k2 \le n \le k),当以 nn 作为输入运行该 DC 程序时,程序输出序列 [1,2,…,n][1, 2, \ldots, n] 的错位排列数目。该程序长度不得超过 10 00010\,000 个字符。

我们提供了一个本地测试工具以协助你开发解决方案。该工具位于“比赛资料”(Contest Materials)中。

输入格式

The only line of input contains a single integer kk (k∈2,3,50k \in {2,3,50}).

Your DC program should output the correct number of derangements for all integers nn such that 2≤n≤k2 \le n \le k.

输入仅包含一行,其中有一个整数 kk(k∈{2,3,50}k \in \{2,3,50\})。

你的分治(DC)程序应输出所有满足 2≤n≤k2 \le n \le k 的整数 nn 对应的错排数。

输出格式

Output a valid DC expression on a single line. The expression should only consist of the characters round()+-*/ and the length of the expression should not exceed 10 00010\,000 characters.

Your expression will be run on all integers nn such that 2≤n≤k2 \le n \le k. For each such run, the DC expression should not divide by 00 at any time, and its value must be the number of derangements of nn.

在单行内输出一个有效的 DC 表达式。该表达式仅可包含字符 round、+、-、*、/,且其长度不得超过 10 00010\,000 个字符。

您的表达式将在所有满足 2≤n≤k2 \le n \le k 的整数 nn 上运行。对每个这样的 nn,DC 表达式在运行过程中不得出现除零错误,且其计算结果必须等于 nn 的错排数(即 nn 个元素的错排数目)。

输入输出样例

  • 输入#1

    2

    输出#1

    n-n/n
  • 输入#2

    3

    输出#2

    n+round(n-n*(n/(n+n)))-n

说明/提示

For the first example, n-n/n is a valid DC program that calculates n−1n-1. The number of derangements for n=2n=2 is 11, so this program correctly computes the answer for n=2n=2.

In the second example, a slightly overcomplicated expression is used, which shows all the features of the language in action. For n=3n=3, the value of the expression is: 3+round(3−3⋅(33+3))−3=round(3−32)=round(32)=round(1.5)=23+\text{round}(3-3 \cdot(\frac{3}{3+3}))-3 = \text{round}(3 - \frac{3}{2}) = \text{round}(\frac{3}{2}) = \text{round}(1.5)=2. It correctly calculates the number of derangements of the sequence [1,2,3][1,2,3]. For n=2n=2 it can be verified that the value of the expression becomes 11.

对于第一个例子,n-n/n 是一个有效的 DC 程序,用于计算 n−1n-1。当 n=2n=2 时,错排数为 11,因此该程序正确地计算出了 n=2n=2 时的答案。

在第二个例子中,使用了一个略显复杂的表达式,它展示了该语言的所有特性。当 n=3n=3 时,该表达式的值为:
3+round(3−3⋅(33+3))−3=round(3−32)=round(32)=round(1.5)=23+\text{round}(3-3 \cdot(\frac{3}{3+3}))-3 = \text{round}(3 - \frac{3}{2}) = \text{round}(\frac{3}{2}) = \text{round}(1.5)=2。
它正确地计算出了序列 [1,2,3][1,2,3] 的错排数。当 n=2n=2 时,可以验证该表达式的值为 11。

输入解题思路,AI测评打分。不知道怎么写?

首页