Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Paint Sheets

Try to solve the Number of Ways to Paint Sheets problem.

Statement

You are given an integer n and an integer array limit of length m.

You want to divide a strip of length n into two segments and paint each segment with a distinct color from index 00 to m −1- 1.

A configuration is determined by choosing an ordered pair of distinct color indices (i, j) where i ≠\neq j, and an integer length x such that:

  • The first segment has length x, painted with color i, with 1≤x≤1 \leq x \leq limit[i].

  • The second segment has length n −x- x, painted with color j, with 1≤1 \leq n −x≤- x \leq limit[j].

Return the total number of valid ways to paint the strip.

Constraints:

  • 2≤2 \leq n ≤109\leq 10^9

  • 2≤2 \leq m ==== limit.length ≤105\leq 10^5

  • 1≤1 \leq limit[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Paint Sheets

Try to solve the Number of Ways to Paint Sheets problem.

Statement

You are given an integer n and an integer array limit of length m.

You want to divide a strip of length n into two segments and paint each segment with a distinct color from index 00 to m −1- 1.

A configuration is determined by choosing an ordered pair of distinct color indices (i, j) where i ≠\neq j, and an integer length x such that:

  • The first segment has length x, painted with color i, with 1≤x≤1 \leq x \leq limit[i].

  • The second segment has length n −x- x, painted with color j, with 1≤1 \leq n −x≤- x \leq limit[j].

Return the total number of valid ways to paint the strip.

Constraints:

  • 2≤2 \leq n ≤109\leq 10^9

  • 2≤2 \leq m ==== limit.length ≤105\leq 10^5

  • 1≤1 \leq limit[i] ≤109\leq 10^9