Submission #1753957


Source Code Expand

import java.util.*;
import java.io.*;

public class Main {
	static IO io = new IO();
	public static void main(String[] args) {
		
		int n = io.nextInt();
		List<Integer> c = new ArrayList<>();	// 1..10^9
		for (int i=0; i<n; i++) c.add(io.nextInt());
		
		Deque<int[]> que = new ArrayDeque<>();
		Deque<List<Integer>> tmp = new ArrayDeque<>();
		boolean b[] = new boolean[n];	// おもてtrueうらfalse

		for (int i=0; i<n; i++) {
			List<Integer> init = new ArrayList<>();
			init.add(i);
 			tmp.offer(init);
		}

		// 並び方の列挙
		while (!tmp.isEmpty()) {
			List<Integer> poll = tmp.poll();
			if (poll.size()==n) {
				int offer[] = new int[n];
				for (int i = 0; i < n; i++) offer[i] = c.get(poll.get(i));
				que.offer(offer);
			}
			for (int i=0; i<n; i++) {
				if (!poll.contains(i)) {
					List<Integer> next = new ArrayList<>(poll);
					next.add(i);
					tmp.offer(next);
				}
			}
		}

		double ans = 0;
		int cnt = que.size();
		// 期待値を求める
		while (!que.isEmpty()) {
			int poll[] = que.poll();
			Arrays.fill(b, true);
			for (int i=0; i<n; i++) {
				for (int j=i+1; j<n; j++) {
					if (poll[j]%poll[i]==0) b[j] = !b[j];
				}
			}
			for (int i=0; i<n; i++) if (b[i]) ans++;
		}
		
		ans /= cnt;
		System.out.println(ans);
	}

	static class IO extends PrintWriter {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		public IO() { this(System.in);}
		public IO(InputStream source) { super(System.out); this.in = source;}
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			}else{
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
		private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
		private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
		private static boolean isNewLine(int c) { return c == '\n' || c == '\r';}
		private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
		private void skipNewLine() { while(hasNextByte() && isNewLine(buffer[ptr])) ptr++;}
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public boolean hasNextLine() { skipNewLine(); return hasNextByte();}
		public String next() {
			if (!hasNext()) {
				throw new NoSuchElementException();
			}
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public char[] nextCharArray(int len) {
			if (!hasNext()) {
				throw new NoSuchElementException();
			}
			char[] s = new char[len];
			int i = 0;
			int b = readByte();
			while(isPrintableChar(b)) {
				if (i == len) {
					throw new InputMismatchException();
				}
				s[i++] = (char) b;
				b = readByte();
			}
			return s;
		}
		public String nextLine() {
			if (!hasNextLine()) {
				throw new NoSuchElementException();
			}
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(!isNewLine(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public long nextLong() {
			if (!hasNext()) {
				throw new NoSuchElementException();
			}
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true){
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				}else if(b == -1 || !isPrintableChar(b)){
					return minus ? -n : n;
				}else{
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
				throw new NumberFormatException();
			}
			return (int) nl;
		}
		public char nextChar() {
			if (!hasNext()) {
				throw new NoSuchElementException();
			}
			return (char) readByte();
		}
		public double nextDouble() { return Double.parseDouble(next());}
		public int[] arrayInt(int n) { int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a;}
		public long[] arrayLong(int n) { long[] a = new long[n]; for(int i=0;i<n;i++) a[i] = nextLong(); return a;}
		public double[] arrayDouble(int n) { double[] a = new double[n]; for(int i=0;i<n;i++) a[i] = nextDouble(); return a;}
		public void arrayInt(int[]... a) {for(int i=0;i<a[0].length;i++) for(int j=0;j<a.length;j++) a[j][i] = nextInt();}
		public int[][] matrixInt(int n,int m) { int[][] a = new int[n][]; for(int i=0;i<n;i++) a[i] = arrayInt(m); return a;}
		public char[][] charMap(int n,int m) { char[][] a = new char[n][]; for(int i=0;i<n;i++) a[i] = nextCharArray(m); return a;}
		public void close() {
			super.close();
			try {
				in.close();
			} catch (IOException e) {}
		}
	}
}

Submission Info

Submission Time
Task C - コイン
User creep04
Language Java8 (OpenJDK 1.8.0)
Score 99
Code Size 5151 Byte
Status TLE
Exec Time 2111 ms
Memory 401188 KB

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 99 / 99 0 / 1
Status
AC × 3
AC × 20
AC × 20
TLE × 20
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt
Subtask2 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt, subtask2_20.txt
Case Name Status Exec Time Memory
sample_01.txt AC 74 ms 19152 KB
sample_02.txt AC 75 ms 23124 KB
sample_03.txt AC 79 ms 18900 KB
subtask1_01.txt AC 73 ms 22740 KB
subtask1_02.txt AC 94 ms 21588 KB
subtask1_03.txt AC 74 ms 18644 KB
subtask1_04.txt AC 208 ms 41104 KB
subtask1_05.txt AC 260 ms 44940 KB
subtask1_06.txt AC 118 ms 22356 KB
subtask1_07.txt AC 208 ms 41704 KB
subtask1_08.txt AC 85 ms 18516 KB
subtask1_09.txt AC 74 ms 19284 KB
subtask1_10.txt AC 273 ms 39672 KB
subtask1_11.txt AC 89 ms 21332 KB
subtask1_12.txt AC 237 ms 46988 KB
subtask1_13.txt AC 78 ms 20692 KB
subtask1_14.txt AC 127 ms 23448 KB
subtask1_15.txt AC 228 ms 41700 KB
subtask1_16.txt AC 218 ms 45844 KB
subtask1_17.txt AC 261 ms 43788 KB
subtask1_18.txt AC 216 ms 42504 KB
subtask1_19.txt AC 240 ms 43440 KB
subtask1_20.txt AC 214 ms 44216 KB
subtask2_01.txt TLE 2111 ms 363492 KB
subtask2_02.txt TLE 2111 ms 401188 KB
subtask2_03.txt TLE 2106 ms 169544 KB
subtask2_04.txt TLE 2110 ms 170500 KB
subtask2_05.txt TLE 2111 ms 380040 KB
subtask2_06.txt TLE 2111 ms 368500 KB
subtask2_07.txt TLE 2111 ms 374340 KB
subtask2_08.txt TLE 2107 ms 374336 KB
subtask2_09.txt TLE 2111 ms 374780 KB
subtask2_10.txt TLE 2111 ms 373412 KB
subtask2_11.txt TLE 2110 ms 367856 KB
subtask2_12.txt TLE 2110 ms 174400 KB
subtask2_13.txt TLE 2110 ms 214288 KB
subtask2_14.txt TLE 2110 ms 173680 KB
subtask2_15.txt TLE 2110 ms 174620 KB
subtask2_16.txt TLE 2111 ms 383324 KB
subtask2_17.txt TLE 2110 ms 170508 KB
subtask2_18.txt TLE 2110 ms 169088 KB
subtask2_19.txt TLE 2110 ms 177008 KB
subtask2_20.txt TLE 2110 ms 173072 KB