/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 144ms 13.676 MiB
#2 Wrong Answer 146ms 13.52 MiB
#3 Wrong Answer 142ms 13.605 MiB

Code

function countPerfectSquareSubgrids(H, W) {
    // Initialize total count of perfect square sub-grids
    let totalCount = 0;
    
    // The maximum size of the square sub-grid
    const maxSquareSize = Math.min(H, W);
    
    // Iterate over all possible sizes of square sub-grids
    for (let k = 1; k <= maxSquareSize; k++) {
        // Calculate the number of k x k sub-grids
        const countK = (H - k + 1) * (W - k + 1);
        totalCount += countK;
    }
    
    return totalCount;
}

// Sample input
const H = 5;
const W = 3;

// Calling the function and printing the result
const result = countPerfectSquareSubgrids(H, W);
console.log(result); // Output: 26

Information

Submit By
Type
Submission
Problem
P1121 Square Counting Challenge
Contest
Brain Booster #7
Language
JavaScript (Node.js v18.19.1)
Submit At
2024-11-05 15:18:46
Judged At
2024-11-11 02:30:57
Judged By
Score
10
Total Time
146ms
Peak Memory
13.676 MiB