CSES - Datatähti 2020 alku - Results
Submission details
Task:Ruudukko
Sender:aki
Submission time:2019-10-03 11:27:16 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
Test results
testverdicttime
#10.01 sdetails
#20.01 sdetails
#30.01 sdetails
#40.01 sdetails
#50.01 sdetails
#60.01 sdetails

Code

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

inline int onko_harmoniset(const std::string& str0, const std::string& str1)
{
    if(str0.length() != str1.length()) return 0;

    unsigned char map_0[26], map_1[26];
    for(int i = 0; i < 26; i++)
    {
        map_0[i] = 0;
        map_1[i] = 0;
    }
    
    const char* str0_r = str0.c_str();
    const char* str1_r = str1.c_str();

    for(unsigned int i = 0; i < str0.length(); i++)
    {
        const unsigned char a = (str0_r[i] & 0b111111);
        const unsigned char b = (str1_r[i] & 0b111111);

        

        if((map_0[a] == 0) && (map_1[b] == 0))
        {   
            map_0[a] = b;
            map_1[b] = a;
        }
        else
        {
            if((map_0[a] != b) || (map_1[b] != a))
            {
                return 0;
            }
        }
    }
    return 1;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    
    int n;
    std::cin >> n;
    std::vector<std::string> mjt;
    mjt.resize(n);

    for(int i = 0; i < n; i++)
    {
        std::cin >> mjt[i];
    }

    int hn = 0;
    for(unsigned int i0 = 0; i0 < mjt.size(); i0++)
    {
        for(unsigned int i1 = i0 + 1; i1 < mjt.size(); i1++)
        {   
            hn += onko_harmoniset(mjt[i0], mjt[i1]);  
        }
    }
    std::cout << hn;

    return 0;
}

Test details

Test 1

Verdict:

input
1

correct output

user output
0

Test 2

Verdict:

input
2

correct output
1 2 
2 1 

user output
1

Test 3

Verdict:

input
5

correct output
1 2 3 4 5 
2 1 4 3 6 
3 4 1 2 7 
4 3 2 1 8 
5 6 7 8 1 

user output
10

Test 4

Verdict:

input
42

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
861

Test 5

Verdict:

input
99

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
4851

Test 6

Verdict:

input
100

correct output
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
4950