#P17548. [JAG 2026 Summer Camp #2] Longest Path on DAG

    ID: 20274 远端评测题 2000ms 2048MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>动态规划 DP二分cdq 分治交互题Special JudgeICPC2026

[JAG 2026 Summer Camp #2] Longest Path on DAG

Problem Description

This is an interactive problem.

You are given a positive integer NN and a sequence S=(S1,S2,…,SN)S=(S_1,S_2,\ldots,S_N) of length NN whose elements are all either 00 or 11.

There is a directed bipartite graph GG with NN vertices numbered 1,2,…,N1,2,\ldots,N. Each vertex of GG is colored: vertex vv is white if Sv=0S_v=0 and black if Sv=1S_v=1. Every directed edge (u,v)(u,v) in GG satisfies both of the following conditions:

  • u<vu<v.
  • Vertices uu and vv have different colors.

The judge has GG hidden, and you are not explicitly given any information about its edges. Instead, you may send the following two types of queries to the judge, at most 1500015000 queries in total:

  • in u V: Ask the judge about a black vertex uu and a set VV of zero or more white vertices. The judge answers whether there exists a vertex vv in VV such that the edge (v,u)(v,u) exists.
  • out u V: Ask the judge about a black vertex uu and a set VV of zero or more white vertices. The judge answers whether there exists a vertex vv in VV such that the edge (u,v)(u,v) exists.

Output any one of the longest paths in GG.

Note that the hidden graph GG is fixed before the interaction and remains unchanged.

Interaction

First, an integer NN (2≤N≤5002\le N\le 500) is given from standard input. The next line contains NN integers S1,S2,…,SNS_1,S_2,\ldots,S_N, each of which is 00 or 11, separated by spaces.

N
S_1 S_2 ... S_N

After reading the input, you may make at most 1500015000 in queries and out queries in total, as described below.

in query

First, choose a black vertex uu and a set VV of zero or more white vertices. Then, construct a string T=T1T2…TNT=T_1T_2\ldots T_N of length NN consisting only of 0s and 1s such that TvT_v is 1 if and only if v∈Vv\in V. Print the query to standard output in the following format:

in u T

The judge determines whether there exists a vertex vv in VV such that the edge (v,u)(v,u) exists. Let rr be 11 if such a vertex exists and 00 otherwise. The value rr is given from standard input in the following format:

r

out query

First, choose a black vertex uu and a set VV of zero or more white vertices. Then, construct a string T=T1T2…TNT=T_1T_2\ldots T_N of length NN consisting only of 0s and 1s such that TvT_v is 1 if and only if v∈Vv\in V. Print the query to standard output in the following format:

out u T

The judge determines whether there exists a vertex vv in VV such that the edge (u,v)(u,v) exists. Let rr be 11 if such a vertex exists and 00 otherwise. The value rr is given from standard input in the following format:

r

Once you have determined a longest path, let v1,v2,…,vkv_1,v_2,\ldots,v_k be the vertex numbers in the order in which they appear on the path, and print your answer to standard output in the following format:

! k v_1 v_2 ... v_k

Terminate your program immediately after outputting the answer.

Notes on Interactive Judging

If your output does not conform to the specified format, or if your program terminates without outputting an answer, the verdict is undefined. Terminate your program immediately after outputting the answer. Otherwise, the verdict is undefined.

Whenever you output something, end it with a newline and flush standard output.

If you make more than 1500015000 queries, the verdict is undefined. Note that outputting the answer does not count as a query.

5
1 0 0 1 0

1

1

0

1


out 1 01101

in 4 01100

in 4 01000

out 4 01001

! 4 1 3 4 5

Hint

In this sample interaction, the hidden graph has the edge set E(G)={(1,2),(1,3),(1,5),(3,4),(4,5)}E(G)=\{(1,2),(1,3),(1,5),(3,4),(4,5)\}. This information is not given to the program.