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

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:26:40: error: missing template arguments before '(' token
   26 |     vector<vector<int>> rows (n, vector(n, 0));
      |                                        ^
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:66:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             for (int i=0; i < column.size(); i++){
      |                           ~~^~~~~~~~~~~~~~~
input/code.cpp:70:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |...

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(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);
        
        for(int y2=y1; y2<n; y2++){
            int mask = 0;
            for(int row_i=y1; row_i<y2; row_i++){
                mask = mask | found_species_per_row[row_i];
                if(mask == existing_species_mask){
                    break;
                }
            }
            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<column.size(); x1++){
                int mask = 0;
                
                for(int x2=x1; x2<column.size(); x2++){
                    mask = mask | found_species_per_column[x2];
                    
                    if(mask == existing_species_mask){
                        fitting_fences += column.size()-x2;
                        break;
                    }
                }
            }
        }
    }
    
    cout << fitting_fences;
    
    return 0;
}