Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.math.*;
- import java.util.*;
- import java.awt.geom.*;
- import static java.lang.Math.*;
- public class Solution implements Runnable {
- public static void main(String[] args) throws Exception {
- new Thread(null, new Solution(), "", 1 << 25).start();
- }
- BufferedReader in;
- PrintWriter out;
- StringTokenizer st;
- final String fname = "high";
- private String next() throws Exception {
- if (st == null || !st.hasMoreElements())
- st = new StringTokenizer(in.readLine());
- return st.nextToken();
- }
- private int nextInt() throws Exception {
- return Integer.parseInt(next());
- }
- private long nextLong() throws Exception {
- return Long.parseLong(next());
- }
- private double nextDouble() throws Exception {
- return Double.parseDouble(next());
- }
- public void run() {
- try {
- Locale.setDefault(Locale.ENGLISH);
- in = new BufferedReader(new FileReader(fname+".in"));
- out = new PrintWriter(new FileWriter(fname+".out"));
- //in = new BufferedReader(new InputStreamReader(System.in));
- //out = new PrintWriter(new OutputStreamWriter(System.out));
- solve();
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- } finally {
- out.close();
- }
- }
- int n;
- String s[];
- int ans [] = new int [6];
- int count [] = new int [1<<5];
- int acount [] = new int [1<<5];
- void doMask(int mask) {
- HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
- for (int i=0;i<n;i++) {
- int h=0;
- for (int j=0;j<5;j++) {
- if (((1<<j) & mask)>0) {
- h=h*31+(s[i].charAt(j)-'a'+1);
- }
- }
- if (!map.containsKey(h)) map.put(h, 1); else {
- int value = map.get(h)+1;
- map.put(h, value);
- }
- }
- int ret=0;
- for (int hash : map.keySet()) {
- int cnt = map.get(hash);
- ret+=(cnt)*(cnt-1)/2;
- }
- count[mask]=ret;
- }
- public void solve() throws Exception {
- n=nextInt();
- s = new String [n];
- for (int i=0;i<n;i++)
- s[i]=next();
- for (int mask=1;mask<(1<<5);mask++) {
- doMask(mask);
- }
- for (int mask=1;mask<(1<<5);mask++) {
- int bitCount = BigInteger.valueOf(mask).bitCount();
- for (int omask=1;omask<(1<<5);omask++) {
- int obitCount = BigInteger.valueOf(omask).bitCount();
- if ((omask & mask) == mask) {
- if ((obitCount-bitCount)%2==0) {
- acount[mask]+=count[omask];
- } else {
- acount[mask]-=count[omask];
- }
- }
- }
- }
- int all=0;
- for (int mask=1;mask<(1<<5);mask++) {
- ans[5-BigInteger.valueOf(mask).bitCount()]+=acount[mask];
- all+=acount[mask];
- }
- ans[5]=n*(n-1)/2-all;
- for (int i=0;i<6;i++)
- out.print(ans[i]+" ");
- out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment