Sort by

recency

|

192 Discussions

|

  • + 0 comments
    #include <iostream>
    #include <vector>
    #include <string>
    using namespace std;
    
    long long winningLotteryTicket(const vector<string>& tickets) {
        const int fullMask = (1 << 10) - 1;
        vector<long long> freq(1 << 10, 0);
    
        for (const string& ticket : tickets) {
            int mask = 0;
            for (char c : ticket) {
                mask |= 1 << (c - '0');
            }
            freq[mask]++;
        }
    
        long long count = 0;
        for (int i = 0; i < (1 << 10); i++) {
            if (freq[i] == 0) continue;
            for (int j = i; j < (1 << 10); j++) {
                if (freq[j] == 0) continue;
                if ((i | j) == fullMask) {
                    if (i == j) {
                        count += freq[i] * (freq[i] - 1) / 2;
                    } else {
                        count += freq[i] * freq[j];
                    }
                }
            }
        }
        return count;
    }
    
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
    
        int n; cin >> n;
        vector<string> tickets(n);
        for (int i = 0; i < n; i++) cin >> tickets[i];
        cout << winningLotteryTicket(tickets) << "\n";
        return 0;
    }
    
  • + 0 comments
    import sys
    from collections import Counter
    
    def winningLotteryTicket(tickets):
        FULL = (1 << 10) - 1 
        freq = Counter()
    
        for t in tickets:
            mask = 0
            for ch in set(t): 
                mask |= 1 << (ord(ch) - ord('0'))
            freq[mask] += 1
    
        masks = list(freq.keys())
        masks.sort()
    
        total = 0
        L = len(masks)
        for i in range(L):
            a = masks[i]
            fa = freq[a]
            if (a | a) == FULL:
                total += fa * (fa - 1) // 2
            for j in range(i+1, L):
                b = masks[j]
                if (a | b) == FULL:
                    total += fa * freq[b]
    
        return total
    
    if __name__ == "__main__":
        data = sys.stdin.read().strip().split()
        if not data:
            print(0)
            sys.exit(0)
    
        n = int(data[0])
        tickets = data[1:1+n]
        print(winningLotteryTicket(tickets))
    
  • + 0 comments

    in C++

    long winningLotteryTicket(vector<string> tickets) {
        // A map to store the frequency of each bitmask
        unordered_map<int, long> bitmask_count;
        
        // Process each ticket and compute its bitmask
        for (const string& ticket : tickets) {
            int bitmask = 0;
            
            // Mark the digits that appear in the ticket
            for (char c : ticket) {
                bitmask |= (1 << (c - '0'));
            }
            
            // Increment the count for this bitmask
            bitmask_count[bitmask]++;
        }
        
        long result = 0;
        
        // Now check pairs of bitmasks
        for (auto it1 = bitmask_count.begin(); it1 != bitmask_count.end(); ++it1) {
            for (auto it2 = next(it1); it2 != bitmask_count.end(); ++it2) {
                if ((it1->first | it2->first) == 1023) {
                    result += it1->second * it2->second;
                }
            }
        }
        
        // Check the cases where both bitmasks are the same
        for (auto it1 = bitmask_count.begin(); it1 != bitmask_count.end(); ++it1) {
            if ((it1->first | it1->first) == 1023) {
                result += (it1->second * (it1->second - 1)) / 2;
            }
        }
    
        return result;
    }
    
  • + 2 comments

    FOR CRYPTOCURRENCY RECOVERY, CONTACT TSUTOMU SHIMOMURA

    This is the best crypto recovery company I've come across, and I'm here to tell you about it. TSUTOMU SHIMOMURA was able to 5:15 PM 30/12/2024 REGHWGHBHH recover my crypto cash from my crypto investment platform's locked account. TSUTOMU SHIMOMURA just needed 24HRS to restore the $620,000 I had lost in cryptocurrencies. I sincerely appreciate their assistance and competent service. TSUTOMU SHIMOMURA may be relied on since they are dependable and trustworthy. you can also contact them via WEBSITE: https://tsutomushackexpert.com/ or Email address support@tsutomushackexpert.com, and I’m sure you will be happy you did.

  • + 0 comments

    def winningLotteryTicket(tickets): # Convert each ticket to a bitmask freq = {} FULL_MASK = (1 << 10) - 1 # 1023 = 0b1111111111

    for ticket in tickets:
        mask = 0
        for digit in ticket:
            mask |= 1 << int(digit)
        freq[mask] = freq.get(mask, 0) + 1
    
    masks = list(freq.keys())
    count = 0
    
    for i in range(len(masks)):
        for j in range(i, len(masks)):
            if (masks[i] | masks[j]) == FULL_MASK:
                if i == j:
                    # pairs from the same mask: nC2 = n*(n-1)//2
                    count += freq[masks[i]] * (freq[masks[i]] - 1) // 2
                else:
                    # pairs from different masks
                    count += freq[masks[i]] * freq[masks[j]]
    return count