Sort by

recency

|

191 Discussions

|

  • + 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;
    }
    
  • + 0 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
    
  • + 0 comments

    Java 8 solution:

    import java.io.*;
    import java.math.*;
    import java.security.*;
    import java.text.*;
    import java.util.*;
    import java.util.concurrent.*;
    import java.util.function.*;
    import java.util.regex.*;
    import java.util.stream.*;
    import static java.util.stream.Collectors.joining;
    import static java.util.stream.Collectors.toList;
    
    class Result {
    
        /*
         * Complete the 'winningLotteryTicket' function below.
         *
         * The function is expected to return a LONG_INTEGER.
         * The function accepts STRING_ARRAY tickets as parameter.
         */
    
        public static long winningLotteryTicket(List<String> tickets) {
            // Write your code here
            long[] freq = new long[1024]; 
            long answer = 0;
    
            for (String s : tickets) {
                int output = Freq_to_Decimal(s); 
                freq[output]++;
            }
            for (int i = 0; i < 1024; i++) {
                for (int j = i; j < 1024; j++) {
                    if ((i | j) == 1023) {
                        if (i == j) {
                            answer += (freq[i] * (freq[i] - 1)) / 2;
                        } else {
                            answer += freq[i] * freq[j];
                        }
                    }
                }
            }
    
            return answer;
        }
        static int Freq_to_Decimal(String s) {
            int ans = 0;
            for (char c : s.toCharArray()) {
                int bit = c - '0'; 
                ans = ans | (1 << (9 - bit)); 
            }
            return ans;
        }
    }
    
    public class Solution {
        public static void main(String[] args) throws IOException {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out));
    
            int n = Integer.parseInt(bufferedReader.readLine().trim()); 
    
            List<String> tickets = IntStream.range(0, n).mapToObj(i -> {
                try {
                    return bufferedReader.readLine();
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            })
            .collect(toList()); 
            long result = Result.winningLotteryTicket(tickets); 
    
            bufferedWriter.write(String.valueOf(result)); 
            bufferedWriter.newLine();
    
            bufferedReader.close();
            bufferedWriter.close();
        }
    }