DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord-backed certification.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

Do Not Believe T's Story

Back to problem

Editorial

This is an encoding problem: agree in advance on a family of candidate subsets, find one contained in the input set SSS, and transmit its identifier. The second execution reconstructs the selected subset from that identifier alone.

Let N=1 000 000N=1\,000\,000N=1000000 and K=10 000K=10\,000K=10000. Subtract 111 from every input value, so that the universe is {0,…,N−1}\{0,\ldots,N-1\}{0,…,N−1}.

Shared permutations and buckets

Prepare T=12T=12T=12 permutations f0,…,fT−1f_0,\ldots,f_{T-1}f0​,…,fT−1​, reproducible in both executions. The implementation initializes with a fixed seed, repeatedly shuffles the same array, and stores a copy after each shuffle. The seed is fixed independently of the input and test data.

For each permutation, map every x∈Sx\in Sx∈S to y=ft(x)y=f_t(x)y=ft​(x), and divide the universe into buckets of size B=400B=400B. There are

G=N/B=2 500G=N/B=2\,500G=N/B=2500

buckets. A mapped value is represented by its bucket and its position inside that bucket:

b=⌊y/B⌋,p=y mod B.b=\left\lfloor y/B\right\rfloor,\qquad p=y\bmod B.b=⌊y/B⌋,p=ymodB.

If a bucket contains at least 999 input elements, consider its 999-element subsets. For sorted positions

0≤p1<p2<⋯<p9<B,0\le p_1<p_2<\cdots<p_9<B,0≤p1​<p2​<⋯<

define the colexicographic combination rank

r=∑j=19(pjj).r=\sum_{j=1}^{9}\binom{p_j}{j}.r=j=1∑9​(jp

This is a bijection between the 999-element subsets of a bucket and the integers 0,…,L−10,\ldots,L-10,…,L−1, where

L=(4009)=659 797 329 990 167 600.L=\binom{400}{9}=659\,797\,329\,990\,167\,600.L=(9400​)=659797329990167600.

Fitting the message into 64 bits

Encoding the permutation, bucket, and unrestricted combination rank would require TGLTGLTGL codes, which exceeds the available range. We therefore allow only some combinations in each permutation--bucket pair.

Reserve messages 1,…,N1,\ldots,N1,…,N for directly transmitting one original input value. Message 000 is unused. Allocate the remaining space equally among the TGTGTG pairs, with

A=⌊264−1−NTG⌋=614 891 469 123 618A=\left\lfloor\frac{2^{64}-1-N}{TG}\right\rfloor =614\,891\,469\,123\,618A=⌊TG264−1−N

codes per pair. Combine the two indices as u=tG+bu=tG+bu=tG+b.

For each uuu, deterministically generate coefficients from a second fixed seed and uuu. Choose

1≤αu<L,gcd⁡(αu,L)=1,0≤βu<L.1\le\alpha_u<L,\qquad \gcd(\alpha_u,L)=1,\qquad 0\le\beta_u<L.1≤αu​<L,gcd(α

The implementation uses SplitMix64 and retries the choice of αu\alpha_uαu​ until it is coprime to LLL. Both executions reproduce the same coefficients, so they need not be transmitted.

Transform a combination rank by

c=(αur+βu) mod L.c=(\alpha_u r+\beta_u)\bmod L.c=(αu​r+βu​)

This map is invertible modulo LLL. Accept the candidate only when c<Ac<Ac<A, and transmit

X=N+1+uA+c.X=N+1+uA+c.X=N+1+uA+c.

Consequently,

N+1≤X≤N+TGA≤264−1.N+1\le X\le N+TGA\le2^{64}-1.N+1≤X≤N+TGA≤264−

The invertible affine filter distributes the permitted ranks more broadly than simply accepting the smallest original ranks.

The encoder visits permutations and buckets in order. In each bucket containing k≥9k\ge9k≥9 input elements, it enumerates all (k9)\binom{k}{9}(9k​) subsets if necessary, stopping immediately when one passes the filter. There is no cutoff on the number of combinations examined. If every candidate in all 121212 permutations fails, transmit one element of in its original, one-based form. This is the one-element fallback.

Decoding

For a message produced by the encoder, 1≤X≤N1\le X\le N1≤X≤N identifies the fallback value directly. Otherwise, recover

u=⌊X−N−1A⌋,c=(X−N−1) mod A,u=\left\lfloor\frac{X-N-1}{A}\right\rfloor,\qquad c=(X-N-1)\bmod A,u=⌊AX−N−1​

and then

t=⌊u/G⌋,b=u mod G.t=\left\lfloor u/G\right\rfloor,\qquad b=u\bmod G.t=⌊u/G⌋,b=umodG.

Regenerate the coefficients for uuu, and invert the filter:

r=αu−1(c−βu) mod L.r=\alpha_u^{-1}(c-\beta_u)\bmod L.r=αu−1​(c−β

The inverse is taken modulo LLL, not modulo AAA. Normalize the subtraction before multiplying by the inverse.

Unrank the combination in reverse order, from j=9j=9j=9 down to 111. Choose the largest permitted pjp_jpj​ satisfying

(pjj)≤r,\binom{p_j}{j}\le r,(jpj​​)≤r,

subtract this binomial coefficient from rrr, and restrict the next position to values smaller than pjp_jpj​. Binary search finds each position. Finally, map each bB+pjbB+p_jbB+pj through and add to restore the original numbering.

Invertibility of the rank and affine maps ensures that a successful search reconstructs exactly the selected 999 distinct input elements. The fallback reconstructs one input element. Thus every reconstructed value belongs to SSS.

Precompute the binomial coefficients up to (4009)\binom{400}{9}(9400​). These coefficients, ranks, and messages fit in unsigned 64-bit integers. Products such as αur+βu\alpha_u r+\beta_uαu​r+, modular multiplication during decoding, and message construction use intermediates. The extended Euclidean algorithm for the modular inverse uses signed 128-bit intermediates.

Estimated frequency of recovering nine elements

For an estimate, idealize the shared permutations as independent uniform random permutations. Also approximate each affine permutation of combination ranks by a uniform random permutation of all LLL ranks. The latter is an approximation: the affine family does not contain every permutation of the rank space.

Under the uniform-shuffle model, the number YYY of input elements in a particular bucket has the hypergeometric distribution

Pr⁡(Y=k)=(Bk)(N−BK−k)(NK),E[Y]=KB/N=4.\Pr(Y=k)=\frac{\binom{B}{k}\binom{N-B}{K-k}}{\binom NK}, \qquad \mathbb E[Y]=KB/N=4.Pr(Y=k)=(

If the bucket contains kkk elements, it offers mk=(k9)m_k=\binom{k}{9}mk​=(9k​) candidate subsets; take for . In the uniform-rank-permutation model, the probability that all candidates fail is

(L−Amk)(Lmk)≈(1−p)mk,p=A/L≈0.00093194.\frac{\binom{L-A}{m_k}}{\binom{L}{m_k}} \approx(1-p)^{m_k}, \qquad p=A/L\approx0.00093194.(mk​

Hence the estimated probability that a particular bucket provides an encodable subset is

q≈∑k=9B(Bk)(N−BK−k)(NK)(1−(1−p)(k9))≈0.0004094405.q\approx\sum_{k=9}^{B} \frac{\binom{B}{k}\binom{N-B}{K-k}}{\binom NK} \left(1-(1-p)^{\binom{k}{9}}\right) \approx0.0004094405.q≈k=9∑B

If we additionally ignore dependencies between buckets and trials, the estimated failure probability over all TG=30 000TG=30\,000TG=30000 pairs is

(1−q)TG≈4.62×10−6,(1-q)^{TG}\approx4.62\times10^{-6},(1−q)TG≈4.62×10−6,

giving an estimated nine-element recovery rate of about

99.99954%.\boxed{99.99954\%}.99.99954%​.

This numerical estimate relies on the uniformity and independence approximations above. With fixed seeds, the implementation is deterministic; the estimate is not a worst-case guarantee of recovering nine elements for every valid SSS. When no candidate passes the filter, the encoder uses the valid one-element fallback.

mt19937\_64
=
400
p9​
<
B,
j​
​
)
.
​
⌋
=
614891469123618
u
​
,
L
)
=
1,0≤
βu​<
L.
mod
L.
1.
SSS
⌋
,
c
=
(X−
N−
1)mod
A,
u
​
)
mod
L.
​
ft−1f_t^{-1}ft−1​
111
βu​
unsigned \_\_int128
K
N
​
)
(kB​)(K−kN−B​)
​
,
E
[
Y
]
=
KB/N=
4.
mk=0m_k=0mk​=0
k<9k<9k<9
L
​
)
(mk​L−A​)
​
≈
(1−
p)mk​,p=
A/L≈
0.00093194.
​
(KN​)(kB​)(K−kN−B​)​
(1−(1−p)(9k​))
≈
0.0004094405.