Submission details
Task:Forest density
Sender:Isak
Submission time:2025-09-22 17:01:59 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.12 sdetails
#3ACCEPTED0.10 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:24:10: warning: ignoring return value of 'char* fgets(char*, int, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     fgets(line, n+4, stdin);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
input/code.cpp:26:14: warning: ignoring return value of 'char* fgets(char*, int, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         fgets(line, n+4, stdin);
      |         ~~~~~^~~~~~~~~~~~~~~~~~

Code

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

int main() {
    uint64_t n = 0;
    uint64_t q = 1;
    if (scanf("%ld %ld", &n, &q) == 0)
        return EXIT_FAILURE;

    // main algo

    uint64_t *tab = (uint64_t *) malloc((n + 1)*(n + 1)* sizeof(uint64_t));
    char *line = (char *) malloc((n+4) * sizeof(char));

    for (uint64_t i = 0; i <= n; i++){
        tab[i*(n+1)] = 0;
        tab[i] = 0;
    }

    fgets(line, n+4, stdin);
    for (uint64_t i = 1; i <= n; i++){
        fgets(line, n+4, stdin);
        // printf("%s. line :%ld\n", line, i );
        for (uint64_t j = 1; j <= n; j++){
            tab[i+j*(n+1)] = tab[i-1+j*(n+1)] + tab[i+(j-1)*(n+1)] - tab[i-1+(j-1)*(n+1)] + (line[j-1] == '*' ? 1 : 0);
        }
    }
    // for (uint64_t i = 1; i <= n; i++){
    //     for (uint64_t j = 1; j <= n; j++){
    //         printf("%2ld, ", tab[i+(n+1)*j]);
    //     }
    //     printf("\n");
    // }

    uint64_t x1, y1, x2, y2;
    for (uint64_t i = 0; i < q; i++){
        if (scanf("%ld %ld %ld %ld", &x1, &y1, &x2, &y2) == 0)
            return EXIT_FAILURE;
        printf("%ld\n", tab[x2+(n+1)*y2] + tab[x1-1+(n+1)*(y1 - 1)] - tab[x1-1+(n+1)*y2] - tab[x2+(n+1)*(y1 - 1)]);
    }


    return EXIT_SUCCESS;
}

Test details

Test 1

Verdict: ACCEPTED

input
10 100
**.*.*.**.
*.**.*..*.
.*****.**.
**....***.
...

correct output
10
14
5
7
8
...

user output
10
14
5
7
8
...
Truncated

Test 2

Verdict: ACCEPTED

input
1000 200000
**.**.****..**.***..**.***.**....

correct output
41079
2824
15631
1548
8483
...

user output
41079
2824
15631
1548
8483
...
Truncated

Test 3

Verdict: ACCEPTED

input
1000 200000
******************************...

correct output
1000000
1000000
1000000
1000000
1000000
...

user output
1000000
1000000
1000000
1000000
1000000
...
Truncated