Submission #169849


Source Code Expand

Copy
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <list>
#include <vector>
#include <queue>

typedef unsigned long long int ulli;

int N;
std::vector<ulli> C;

ulli fact(ulli n) {
	ulli a = 1;
	if(n == 0) return 1;
	for(ulli i=1; i<=n; ++i) a *= i;
	return a;
}

ulli count(const std::vector<int>& q) {
	std::vector<bool> t(N);
	std::fill(t.begin(), t.end(), false);
	
	for(int n=0; n<N; ++n) {
		for(int i=n+1; i<N; ++i) {
			if(C[q[i]] % C[q[n]] == 0) {
				if(t[i]) t[i] = false; else t[i] = true;
			}
		}
	}
	
	ulli k = 0;
	for(int n=0; n<N; ++n) {if(!t[n]) ++k;}
	
	return k;
}

ulli search(std::vector<int>& q) {
	if(q.size() == N) return count(q);
	
	ulli k = 0;
	for(int n=0; n<N; ++n) {
		auto itr = std::find(q.begin(), q.end(), n);
		if(itr == q.end()) {
			std::vector<int> r(q);
			r.push_back(n);
			k += search(r);
		}
	}
	
	return k;
}


int main(void) {
	std::cin >> N;
	
	C = std::vector<ulli>(N);
	for(int n=0; n<N; ++n) std::cin >> C[n];
	
	std::vector<int> q;
	ulli A = search(q);
	ulli B = fact(N);
	
	double ans = static_cast<double>(A) / static_cast<double>(B);
	
	std::cout << std::fixed << std::setprecision(8) << ans << std::endl;
	
	return 0;
}

Submission Info

Submission Time
Task C - コイン
User material
Language C++11 (GCC 4.8.1)
Score 99
Code Size 1263 Byte
Status TLE
Exec Time 2032 ms
Memory 936 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 22 ms 800 KB
sample_02.txt AC 23 ms 808 KB
sample_03.txt AC 23 ms 916 KB
subtask1_01.txt AC 23 ms 808 KB
subtask1_02.txt AC 25 ms 800 KB
subtask1_03.txt AC 22 ms 732 KB
subtask1_04.txt AC 65 ms 816 KB
subtask1_05.txt AC 66 ms 816 KB
subtask1_06.txt AC 29 ms 748 KB
subtask1_07.txt AC 63 ms 804 KB
subtask1_08.txt AC 23 ms 748 KB
subtask1_09.txt AC 21 ms 800 KB
subtask1_10.txt AC 66 ms 808 KB
subtask1_11.txt AC 24 ms 800 KB
subtask1_12.txt AC 62 ms 840 KB
subtask1_13.txt AC 24 ms 808 KB
subtask1_14.txt AC 26 ms 800 KB
subtask1_15.txt AC 67 ms 788 KB
subtask1_16.txt AC 61 ms 804 KB
subtask1_17.txt AC 69 ms 812 KB
subtask1_18.txt AC 67 ms 804 KB
subtask1_19.txt AC 126 ms 804 KB
subtask1_20.txt AC 68 ms 800 KB
subtask2_01.txt TLE 2031 ms 804 KB
subtask2_02.txt TLE 2032 ms 880 KB
subtask2_03.txt TLE 2031 ms 804 KB
subtask2_04.txt TLE 2030 ms 932 KB
subtask2_05.txt TLE 2030 ms 924 KB
subtask2_06.txt TLE 2030 ms 932 KB
subtask2_07.txt TLE 2029 ms 932 KB
subtask2_08.txt TLE 2030 ms 932 KB
subtask2_09.txt TLE 2029 ms 924 KB
subtask2_10.txt TLE 2029 ms 924 KB
subtask2_11.txt TLE 2030 ms 936 KB
subtask2_12.txt TLE 2030 ms 932 KB
subtask2_13.txt TLE 2030 ms 928 KB
subtask2_14.txt TLE 2029 ms 928 KB
subtask2_15.txt TLE 2029 ms 932 KB
subtask2_16.txt TLE 2030 ms 932 KB
subtask2_17.txt TLE 2031 ms 924 KB
subtask2_18.txt TLE 2030 ms 928 KB
subtask2_19.txt TLE 2030 ms 932 KB
subtask2_20.txt TLE 2029 ms 936 KB