CSES - Datatähti 2025 alku - Results
Submission details
Task:Niitty
Sender:Lelleri
Submission time:2024-11-04 22:18:13 +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:50:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             for (int i=0; i < column.size(); i++){
      |                           ~~^~~~~~~~~~~~~~~
input/code.cpp: At global scope:
input/code.cpp:70:5: error: 'cout' does not name a type
   70 |     cout << fitting_fences;
      |     ^~~~
input/code.cpp:72:5: error: expected unqualified-id before 'return'
   72 |     return 0;
      |     ^~~~~~
input/code.cpp:73:1: error: expected declaration before '}' token
   73 | }
      | ^

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;

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