CSES - Datatähti 2025 alku - Results
Submission details
Task:Niitty
Sender:OorigamiK
Submission time:2024-11-03 21:22:11 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool recArea(int, int, int, int, int, std::vector<std::vector<std::vector<int> > >&)':
input/code.cpp:6:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |     for (int color = 0; color < flowerSums.size(); color++) {
      |                         ~~~~~~^~~~~~~~~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:91:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::vector<int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for (int color = 0; color < flowerSums.size(); color++) {
      |                         ~~~~~~^~~~~~~~~~~~~~~~~~~
input/code.cpp:120:39: error: 'ceil' was not declared in this scope; did you mean 'ceiling'?
  120 |                             ceiling = ceil(float(ceiling + flooring) / 2);
      |...

Code

#include <iostream>
#include <string>
#include <vector>

bool recArea(int n, int x1, int x2, int y1, int y2, std::vector<std::vector<std::vector<int>>>& flowerSums) {
    for (int color = 0; color < flowerSums.size(); color++) {
        int sum = 0;
        sum += flowerSums[color][x2][y2];
        if (x1 > 0) {
            if (y1 > 0) {
                sum += flowerSums[color][x1 - 1][y1-1];
            }
            sum -= flowerSums[color][x1-1][y2];
        }
        if (y1 > 0) {
            sum -= flowerSums[color][x2][y1-1];
        
        }
        if (sum <= 0) {
            //std::cout << color << " " << sum<<" "<<flowerSums[color][x2][y2] << std::endl;
            return false;
        }
     }
    return true;
}

void recursion(int& SUM, int n, int x1,int x2, int y1, int y2, std::vector<std::vector<std::vector<int>>>& flowerSums) {
    if (recArea(n, x1, x2, y1, y2, flowerSums) && x1<=x2 && y1<=y2) {
        SUM++;
        recursion(SUM, n, x1 + 1, x2, y1, y2, flowerSums);
        recursion(SUM, n, x1, x2 - 1, y1, y2, flowerSums);
        recursion(SUM, n, x1, x2, y1 + 1, y2, flowerSums);
        recursion(SUM, n, x1, x2, y1, y2 - 1, flowerSums);
    }
}

int main()
{
    std::vector<std::string> flowers;
    int n;
    //n = 100;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::string s;
        std::cin >> s;
        //s = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
        //std::cout << s.size() << std::endl;
        flowers.push_back(s);
    }
    std::vector<bool> theFlowers;
    for (int i = 0; i < 26; i++) {
        theFlowers.push_back(false);
    }
    for (std::string s : flowers) {
        for (int i = 0; i < n; i++) {
            int k = int(s[i]) - int('A');
            theFlowers[k] = true;
        }
    }
    std::vector<std::vector<std::vector<int>>> flowerSums;
    int y = 0;
    for (int j = 0; j < 26; j++) {
        if (theFlowers[j]) {
            flowerSums.push_back({});
            for (int i = 0; i < n; i++) {
                flowerSums[y].push_back({});
                for (int k = 0; k < n; k++) {
                    flowerSums[y][i].push_back(0);

                }
            }
            y++;
        }
    }

    y = 0;
    for (int color = 0; color < 26; color++) {
        if (theFlowers[color]) {
            for (int k = 0; k < n; k++) {
                for (int t = 0; t < n; t++) {
                    //std::cout << flowers[k][t] <<" " << int(flowers[k][t]) << " " << int('A') << " " << k << " " << t << std::endl;
                    if (int(flowers[k][t]) - int('A') == color) {
                        flowerSums[y][k][t]++;
                        //std::cout << "debug " << y << " " << k << " " << t << std::endl;
                    }
                }
            }
            y++;
        }
    }
    for (int color = 0; color < flowerSums.size(); color++) {
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < n; j++) {
                flowerSums[color][i][j] += flowerSums[color][i - 1][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 1; j < n; j++) {
                flowerSums[color][i][j] += flowerSums[color][i][j - 1];
            }
        }
    }
    //int SUM = 0;
    //recursion(SUM, n, 0, n - 1, 0, n - 1, flowerSums);
    //std::cout << SUM << std::endl;
    int numOfRec = 0;
    recArea(n, 0, 0, 3, 3, flowerSums);
    for (int x1 = 0; x1 < n; x1++) {
        for (int x2 = x1; x2 < n; x2++) {
            for (int y1 = 0; y1 < n; y1++) {
                int ceiling = n-1;
                int flooring = y1;
                int step = (ceiling + flooring) / 2;   
                //if (x1 == 0 && x2 == n - 1) {
                    //std::cout << recArea(n, 0, n - 2, 0, 3, flowerSums) << std::endl;
                    while (ceiling - flooring>1) {
                        //std::cout << step<<" " << "bound " << flooring << " " << ceiling << " " << step << " " << recArea(n, x1, x2, y1, step, flowerSums) << std::endl;
                        if (recArea(n, x1, x2, y1, step, flowerSums)) {
                            //std::cout << "hi" << std::endl;
                            ceiling = ceil(float(ceiling + flooring) / 2);
                        }
                        else {
                            flooring = floor(float(ceiling + flooring) / 2);
                        }
                        step = (ceiling + flooring) / 2;

                    }
                    if (recArea(n, x1, x2, y1, flooring, flowerSums)) {
                        //std::cout << "hi" << std::endl;

                        step = flooring;
                    }
                    else if (recArea(n,x1,x2,y1,ceiling,flowerSums)) {
                        //std::cout << "hi" << std::endl;

                        step = ceiling;
                    } 
                    else {
                        //std::cout << x1 << " " << x2 << " " << y1 << " " << step << std::endl;
                        step = n;
                    }
                    //std::cout << "bound " << flooring << " " << ceiling << std::endl;

                    //std::cout << "res " << y1 << " " << step << std::endl;

                    numOfRec += n - step;
                //}
            }
        }
    }
    std::cout << numOfRec << std::endl;
}