← CSES Better

Four Sum

ZCO · 2017 · Zonal Computing Olympiad · ZCO17001

Open official problem ↗
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

arrays · meet-in-the-middle · counting

The organizer’s problem statement is available at the official source link.

four sum pairs

Pair sums reduce four choices to two lookups

Group two indices into a left pair sum and the other two into a complementary right pair sum.

State table
IndicesPair sumsMatch condition
i < jS[i] + S[j](S[i]+S[j]) + (S[k]+S[l]) = T
k < lS[k] + S[l]quadruple indices satisfy the statement constraints
  1. 1

    Build pair sums

    Generate valid pair sums for the first two indices.
  2. 2

    Find complements

    For each pair on the remaining indices, look up the complementary sum.
  3. 3

    Count index quadruples

    Enforce the task’s distinct-index/order constraints when counting matching quadruples.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 chars

Run output

Run your code to see output.