/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 123ms 13.754 MiB
#2 Wrong Answer 127ms 13.578 MiB
#3 Wrong Answer 128ms 13.602 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-05 15:18:46
Judged By
Score
10
Total Time
128ms
Peak Memory
13.754 MiB