Guest User

Untitled

a guest
Nov 1st, 2011
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.65 KB | None | 0 0
  1. import java.io.*;
  2. import java.math.*;
  3. import java.util.*;
  4. import java.awt.geom.*;
  5.  
  6. import static java.lang.Math.*;
  7.  
  8. public class Solution implements Runnable {
  9.  
  10.     public static void main(String[] args) throws Exception {
  11.         new Thread(null, new Solution(), "", 1 << 25).start();
  12.     }
  13.  
  14.     BufferedReader in;
  15.     PrintWriter out;
  16.     StringTokenizer st;
  17.  
  18.     final String fname = "high";
  19.    
  20.     private String next() throws Exception {
  21.         if (st == null || !st.hasMoreElements())
  22.             st = new StringTokenizer(in.readLine());
  23.         return st.nextToken();
  24.     }
  25.  
  26.     private int nextInt() throws Exception {
  27.         return Integer.parseInt(next());
  28.     }
  29.  
  30.     private long nextLong() throws Exception {
  31.         return Long.parseLong(next());
  32.     }
  33.  
  34.     private double nextDouble() throws Exception {
  35.         return Double.parseDouble(next());
  36.     }
  37.    
  38.     public void run() {
  39.         try {
  40.             Locale.setDefault(Locale.ENGLISH);
  41.             in = new BufferedReader(new FileReader(fname+".in"));
  42.             out = new PrintWriter(new FileWriter(fname+".out"));
  43.             //in = new BufferedReader(new InputStreamReader(System.in));
  44.             //out = new PrintWriter(new OutputStreamWriter(System.out));
  45.             solve();
  46.         } catch (Exception ex) {
  47.             throw new RuntimeException(ex);
  48.         } finally {
  49.             out.close();
  50.         }
  51.     }
  52.    
  53.     int n;
  54.     String s[];
  55.     int ans [] = new int [6];
  56.     int count [] = new int [1<<5];
  57.     int acount [] = new int [1<<5];
  58.    
  59.     void doMask(int mask) {
  60.         HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
  61.         for (int i=0;i<n;i++) {
  62.             int h=0;
  63.             for (int j=0;j<5;j++) {
  64.                 if (((1<<j) & mask)>0) {
  65.                     h=h*31+(s[i].charAt(j)-'a'+1);
  66.                 }
  67.             }
  68.             if (!map.containsKey(h)) map.put(h, 1); else {
  69.                 int value = map.get(h)+1;
  70.                 map.put(h, value);
  71.             }
  72.         }
  73.         int ret=0;
  74.         for (int hash : map.keySet()) {
  75.             int cnt = map.get(hash);
  76.             ret+=(cnt)*(cnt-1)/2;
  77.         }
  78.         count[mask]=ret;
  79.     }
  80.    
  81.     public void solve() throws Exception {
  82.         n=nextInt();
  83.         s = new String [n];
  84.         for (int i=0;i<n;i++)
  85.             s[i]=next();
  86.        
  87.         for (int mask=1;mask<(1<<5);mask++) {
  88.             doMask(mask);
  89.         }
  90.        
  91.         for (int mask=1;mask<(1<<5);mask++) {
  92.             int bitCount = BigInteger.valueOf(mask).bitCount();
  93.             for (int omask=1;omask<(1<<5);omask++) {
  94.                 int obitCount = BigInteger.valueOf(omask).bitCount();
  95.                 if ((omask & mask) == mask) {
  96.                     if ((obitCount-bitCount)%2==0) {
  97.                         acount[mask]+=count[omask];
  98.                     } else {
  99.                         acount[mask]-=count[omask];
  100.                     }
  101.                 }
  102.             }
  103.         }
  104.        
  105.         int all=0;
  106.         for (int mask=1;mask<(1<<5);mask++) {
  107.             ans[5-BigInteger.valueOf(mask).bitCount()]+=acount[mask];
  108.             all+=acount[mask];
  109.         }
  110.        
  111.         ans[5]=n*(n-1)/2-all;
  112.         for (int i=0;i<6;i++)
  113.             out.print(ans[i]+" ");
  114.         out.println();
  115.     }
  116.    
  117. }
  118.  
  119.  
Advertisement
Add Comment
Please, Sign In to add comment