Editorial for Restangles


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Spoiler Alert


Hint 1

  • Duyệt qua các hình chữ nhật, tăng biến đếm nếu chu vi thỏa mãn điều kiện

Hint 2

  • Dùng toán học, với vị trí (i, j) thì có bao nhiêu vị trí (i', j') để tạo thành hình chữ nhật ((i, i'), (j, j')) thỏa mãn điều kiện

Hint 3

  • Formula: Tại (i, j) thỏa điều kiện 2 * (i + j) ≥ k(n - i + 1) * (m - j + 1) cách chọn hình chữ nhật

Reference AC code | O(n) time | O(n) auxiliary space |

C++
int main()
{
    int n = readInt();
    int m = readInt();
    int k = readInt();

    ll res = 0;
    for (int a = 1; a <= n; ++a)
        for (int b = 1; b <= m; ++b)
            if (2 * (a + b) >= k) 
                res += 1LL * (n - a + 1) * (m - b + 1); 

    cout << res;
    return 0;
}


Comments

There are no comments at the moment.