Submission #717644

# Submission time Handle Problem Language Result Execution time Memory
717644 2023-04-02T10:10:19 Z TheSahib Set (COCI21_set) C++17
0 / 110
1 ms 340 KB
#include <bits/stdc++.h>

#define ll long long
#define oo 1e9
#define pii pair<int, int>

using namespace std;

const int MAX = 3 * 13 + 5;

int n, k;


bool arr[MAX];

int hashString(string s){
    int a = 0;
    int b = 1;
    for (int i = s.size() - 1; i >= 0; i--)
    {
        a += (s[i] - '1') * b;
        b *= 3;
    }
    return a;
}

void solve(){
    cin >> n >> k;
    string cards[n];
    for (int i = 0; i < n; i++)
    {
        cin >> cards[i];
        arr[hashString(cards[i])] = true;
    }
    ll ans = 0;
    for(string s:cards){
        char others[k][2];
        for (int i = 0; i < k; i++)
        {
            if(s[i] == '1'){
                others[i][0] = '2';
                others[i][1] = '3';
            }
            if(s[i] == '2'){
                others[i][0] = '1';
                others[i][1] = '3';
            }
            if(s[i] == '3'){
                others[i][0] = '1';
                others[i][1] = '2';
            }
        }
        
        
        for (int mask = 1; mask < (1 << k); mask++)
        {
            for (int subMask = mask; subMask >= 0; subMask = (subMask - 1) & mask)
            {
                string a, b;
                for (int i = 0; i < k; i++)
                {
                    if(!(mask & (1 << i))){
                        a += s[i];
                        b += s[i];
                    }
                    else if(subMask & (1 << i)){
                        a += others[i][1];
                        b += others[i][0];
                    }
                    else{
                        a += others[i][0];
                        b += others[i][1];
                    }
                }
                ans += (arr[hashString(a)] & arr[hashString(b)]);
                if(subMask == 0) break;
            }
        }
    }
    cout << ans / 6 << '\n';
}

int main()
{
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Runtime error 1 ms 340 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Runtime error 1 ms 340 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Runtime error 1 ms 340 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -