QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 150

#4081. 하나 둘 셋

Statistics

有一个长度为 $N$ 的数组 $A$,数组中只包含 $1,2,3$ 三种数值。我们希望在该数组中尽可能多地找到满足下述条件的三索引有序组 $(i,j,k)$。

对于数组中的三个索引 $i,j,k$($0 \le i < j < k < N$),需要满足:

  • $A[i]=1,\ A[j]=2,\ A[k]=3$,或者
  • $A[i]=3,\ A[j]=2,\ A[k]=1$。

另外,每一个索引最多只能被包含在一个有序组中。

例如,给定 $A={1,2,3,2,3,1}$,一种满足条件的答案为 $(0,1,4)$ 与 $(2,3,5)$。 ($A[0]=1,\ A[1]=2,\ A[4]=3$,以及 $A[2]=3,\ A[3]=2,\ A[5]=1$。)

当给定数组 $A$ 时,请编写程序,尽可能多地找出满足条件的有序组并进行报告。

你需要实现如下函数:

  • void maximize(vector<int> A)

其中,$A$ 是一个长度为 $N$ 的 vector,只包含 $1,2,3$ 三种数值。maximize 函数需要在 $A$ 中尽可能多地找出满足题目条件的有序组 $(i,j,k)$,并且对于每一个找到的 $(i,j,k)$,恰好调用一次评测器提供的 answer(int i, int j, int k) 函数。

如果存在多种方法可以得到最大数量的有序组,任选其中一种即可。有序组之间的调用顺序将被忽略。也就是说,在上述示例中,可以先调用 answer(0,1,4) 再调用 answer(2,3,5),也可以反过来。

实现细节

你需要提交一个名为 onetwothree.cpp 的文件,且只能提交这一份文件。该文件中必须实现如下函数:

  • void maximize(vector<int> A);

该函数的行为应当与上文描述完全一致。当然,你可以在内部实现并调用其他辅助函数。提交的代码不得进行输入输出操作,也不得访问其他文件。

评测器示例

给定的评测器将以如下格式读取输入:

  • 第 1 行:$N$
  • 第 2 行:$N$ 个整数,每个都是 $1,2,3$ 之一

评测器会先在第一行输出 maximize 函数调用 answer(i,j,k) 的次数,然后对于每一次 answer(i,j,k) 调用,在接下来的一行输出对应的 $i,j,k$。

限制

  • $3 \le N \le 15{,}000$

子任务

  • 子任务 1(14 分):$N \le 18$
  • 子任务 2(29 分):$N \le 100$
  • 子任务 3(53 分):$N \le 3{,}000$
  • 子任务 4(54 分):除原始限制条件外,没有额外限制

样例数据

输入

6
1 2 3 2 3 1

在上述输入下,根据你代码的具体行为,可能得到如下执行示例:

maximize({1, 2, 3, 2, 3, 1})
answer(0, 1, 4)
answer(2, 3, 5)

输出为:

2
0 1 4
2 3 5

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.