QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#15407. 异步处理器

الإحصائيات

给你一个由 $n$ 条指令组成的程序,由一个拥有单个整数寄存器 $A$ 的处理器执行,寄存器 $A$ 的初始值为 $0$。每条指令为以下两种类型之一:

  • + v —— 执行 $A := A + v$;
  • = v —— 执行 $A := v$。

程序中的指令从 $1$ 到 $n$ 编号。每条指令 $i$ 最初的时间戳为 $i$。

部分指令被标记为异步(asynchronous)。如果指令 $i$ 是异步的,其时间戳可以被修改为任何大于 $i$ 的实数。

在所有时间戳调整完毕后,所有时间戳必须互不相同。然后,处理器按照时间戳递增的顺序执行这些指令。

考虑所有可能的异步指令时间戳选择,求在所有指令执行完毕后,寄存器 $A$ 能够得到的不同最终值的数量。

输入格式

第一行包含一个整数 $n$,表示程序中的指令数量($1 \le n \le 2000$)。

接下来的 $n$ 行中,第 $i$ 行描述指令 $i$,包含三个标记(token)。第一个标记为 +=,表示指令的类型。第二个标记为一个整数 $v$,表示指令的参数($1 \le v \le 500$)。最后一个标记为 async(如果该指令被标记为异步)或 sync(否则)。

输出格式

输出一个整数,表示程序执行后 $A$ 可以达到的不同最终值的数量。

样例

输入样例 1

3
+ 1 sync
= 2 async
+ 3 async

输出样例 1

2

输入样例 2

10
= 7 async
+ 3 async
+ 5 sync
+ 3 async
= 1 sync
+ 9 async
+ 10 async
+ 1 sync
+ 3 async
+ 4 sync

输出样例 2

30

说明

在第一个样例中,程序执行开始时,指令 1 将 $A$ 设为 1。然后,指令 2 和指令 3 将按以下两种顺序之一执行:

  • 如果 = 2+ 3 之前执行,最终 $A$ 将等于 5;
  • 如果 + 3= 2 之前执行,最终 $A$ 将等于 2。

因此,最后 $A$ 有两种可能的取值:5 和 2。

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.