CSES - Datatähti 2025 alku - Results
Submission details
Task:Niitty
Sender:Lelleri
Submission time:2024-11-04 22:17:02 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::map<std::__cxx11::basic_string<char>, int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i=0; i<species_to_number.size(); i++){
      |                  ~^~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:60:16: error: 'mask' was not declared in this scope; did you mean 'mask1'?
   60 |             if(mask == existing_species_mask){
      |                ^~~~
      |                mask1
input/code.cpp:63:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |                 for (int i=0; i < column.size(); i++){
      |                               ~~^~~~~~~~~~~~~~~

Code

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include<cmath>
#include <bitset>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<vector<string>> string_rows(n, vector<string>(n, ""));
    for(int i=0; i<n; i++){
        string row;
        cin >> row;
        for(int j=0; j<n; j++){
            string_rows[i][j] = row[j];
        }
    }
    
    
    map<string, int> species_to_number;
    
    vector<vector<int>> rows (n, vector<int>(n, 0));
    for(int y=0; y<n; y++){
        for(int x=0; x<n; x++){
            if(species_to_number.find(string_rows[y][x]) == species_to_number.end()){
                species_to_number[string_rows[y][x]] = species_to_number.size()+1;
            }
            rows[y][x] = species_to_number[string_rows[y][x]];
        }
    }
    
    int existing_species_mask = 0;
    for(int i=0; i<species_to_number.size(); i++){
        existing_species_mask += pow(2, i);
    }
    
    uint64_t fitting_fences = 0;
    
    vector<int> found_species_per_row(n, 0);
    
    for(int i=0; i<n; i++){
        int row_mask = 0;
        for(int j=0; j<n; j++){
            row_mask = row_mask | rows[i][j];
        }
        found_species_per_row[i] = row_mask;
    }
    
    for(int y1=0; y1<n; y1++){
        vector<int> found_species_per_column (n, 0);
        
        int mask1 = 0;
        for(int y2=y1; y2<n; y2++){
            mask1 = mask1 | found_species_per_row[y2];

            if(mask == existing_species_mask){
                vector<int> column = rows[y2];

                for (int i=0; i < column.size(); i++){
                    found_species_per_column[i] = found_species_per_column[i] | (int)pow(2, column[i])>>1;
                }
                
                for(int x1=0; x1<n; x1++){
                    int mask2 = 0;
                    
                    for(int x2=x1; x2<n; x2++){
                        mask2 = mask2 | found_species_per_column[x2];
                        
                        if(mask2 == existing_species_mask){
                            fitting_fences += n-x2;
                            break;
                        }
                    }
                }
            }
        }
    }
    
    cout << fitting_fences;
    
    return 0;
}