Submission #302998
Source Code Expand
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <cstdio>
#include <string.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, b, e) for(int i = b; i < e; i++)
#define to_bit(i) static_cast< bitset<8> >(i)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long>PLL;
typedef queue<int> QI;
typedef priority_queue<int> maxpq;
typedef priority_queue<int, vector<int>, greater<int> > minpq;
struct edge{int to, cost;};
void begin(){cin.tie(0); ios::sync_with_stdio(false);};
int gcd(int a, int b){if(a%b==0){return(b);}else{return(gcd(b,a%b));}};
int lcm(int m, int n){if((0 == m)||(0 == n)){return 0;} return ((m / gcd(m, n)) * n);};
unsigned long long comb(long n, long m){unsigned long long c = 1; m = (n - m < m ? n - m : m);
for(long ns = n - m + 1, ms = 1; ms <= m; ns ++, ms ++){c *= ns; c /= ms;} return c;};
void cp(int a1[], int a2[], int l){REP(i, l) a2[i] = a1[i];};
void cp(string a1[], string a2[], int l){REP(i, l) a2[i] = a1[i];};
double sq(double d){return d*d;};
int sq(int i){return i*i;};
double sqdist(int x1, int y1, int x2, int y2){
double dx = x1 - x2, dy = y1 - y2; return dx*dx + dy*dy;
};
bool inside(int y, int x, int h, int w){return 0 <= y && y <= (h-1) && 0 <= x && x <= (w-1);};
// 線分の交差判定
bool isCross(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){
// 並行な場合
int m = (x2-x1)*(y4-y3)-(y2-y1)*(x4-x3);
if(m == 0) return false;
// 媒介変数の値が0より大きく1以下なら交差する、これは問題の状況によって変わるかも。
double r =(double)((y4-y3)*(x3-x1)-(x4-x3)*(y3-y1))/m;
double s =(double)((y2-y1)*(x3-x1)-(x2-x1)*(y3-y1))/m;
return (0 < r && r <= 1 && 0 < s && s <= 1);
};
// 外積の計算 AB CD の内積を求める
int crossProdct(int ax, int ay, int bx, int by, int cx, int cy, int dx, int dy){
int abx = bx - ax; int aby = by - ay;
int cdx = dx - cx; int cdy = dy - cy;
return abx * cdy - cdx * aby;
};
double crossProdct(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy){
double abx = bx - ax; double aby = by - ay;
double cdx = dx - cx; double cdy = dy - cy;
return abx * cdy - cdx * aby;
};
double innerProduct(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy){
double abx = bx - ax; double aby = by - ay;
double cdx = dx - cx; double cdy = dy - cy;
return abx * cdx + aby * cdy;
};
// 三角形の内部判定 ABCの中にPがあるか判定
bool inTriangle(int ax, int ay, int bx, int by, int cx, int cy, int px, int py){
int c1 = crossProdct(ax, ay, bx, by, bx, by, px, py);
int c2 = crossProdct(bx, by, cx, cy, cx, cy, px, py);
int c3 = crossProdct(cx, cy, ax, ay, ax, ay, px, py);
return (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0);
};
bool inTriangle(double ax, double ay, double bx, double by, double cx, double cy, double px, double py){
double c1 = crossProdct(ax, ay, bx, by, bx, by, px, py);
double c2 = crossProdct(bx, by, cx, cy, cx, cy, px, py);
double c3 = crossProdct(cx, cy, ax, ay, ax, ay, px, py);
return (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0);
};
// 三角形の外心
void circumcenter(double ax, double ay, double bx, double by, double cx, double cy, double res[3]){
// AB AC を求める
double abx = bx - ax; double aby = by - ay;
double acx = cx - ax; double acy = cy - ay;
double m = abx * acy - acx * aby; // 分母 m = 0 となるのは3点が一直線になるとき
double s = (abx * acx + aby * acy - sq(acx) - sq(acy)) / m; // 媒介変数s
res[0] = abx / 2 + s * aby / 2; res[1] = aby / 2 - s * abx / 2;
// cout << res[0] << " " << res[1] << endl;
res[2] = sqrt(sqdist(0, 0, res[0], res[1]));
res[0] += ax; res[1] += ay;
};
class BinaryIndexedTree{
public:
int n; vector<int> bit;
BinaryIndexedTree(int _n){
n = _n;
bit.resize(n+1,0);
}
int sum(int i){
int sum = 0;
while(i > 0){
sum += bit[i];
i -= i & -i;
}
return sum;
}
void add(int i, int v){
while(i <= n){
bit[i] += v;
i += i & -i;
}
}
};
class UnionFindTree{
public:
vector<int> parent, rank;
int n;
std::set<int> set;
// 初期化
UnionFindTree(int _n){
n = _n;
for(int i = 0; i < n; i++){
parent.resize(n);
rank.resize(n);
parent[i] = i;
rank[i] = 0;
}
}
// 根を求める
int find(int x){
if(parent[x] == x){
return x;
}else{
return parent[x] = find(parent[x]);
}
}
// xとyの集合を結合
void unite(int x, int y){
x = find(x);
y = find(y);
if(x == y){
set.insert(x);
return;
}
if(rank[x] < rank[y]){
parent[x] = y;
set.erase(x);
set.insert(y);
}else{
parent[y] = x;
set.erase(y);
set.insert(x);
if(rank[x] == rank[y]) rank[x]++;
}
}
// xとyが同じ集合か
bool same(int x, int y){
return find(x) == find(y);
}
// 集合の数を数える
int count(){
return (int)set.size();
}
};
// ワーシャルフロイド法
void warshallFloyd(int d[100][100], int n){
for(int k = 0; k < n; ++k)
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
if(d[i][k] != -1 && d[k][j] != -1){
if(d[i][j] == -1){
d[i][j] = d[i][k] + d[k][j];
}else{
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
};
// d:隣接行列 n:グラフのサイズ s:始点 dist:始点からの距離が入る配列
void dijkstra(int d[1000][1000], int n, int s, int dist[1000]){
REP(i, n) dist[i] = -1;
dist[s] = 0;
priority_queue<PII, vector<PII>, greater<PII> > q;
q.push(PII(0, s));
while (!q.empty()) {
PII p = q.top(); q.pop();
int i = p.second;
if(dist[i] < p.first) continue;
for(int j = 0; j < n; j++){
if(d[i][j] == -1) continue;
if(dist[j] == -1){
dist[j] = dist[i] + d[i][j];
q.push(PII(dist[j], j));
}else if(dist[j] > dist[i] + d[i][j]){
dist[j] = dist[i] + d[i][j];
q.push(PII(dist[j], j));
}
}
}
};
/**
* start
* @author yoshikyoto
*/
int n, coins[100];
int cou = 0;
int dfs(int d, int used[8], int perm[8]){
// cout << "dfs " << d << endl;
if(d == n){
int flag[8]; REP(i, n) flag[i] = true;
// REP(i, d) cout << perm[i] << " ";
// cout << endl;
REP(i, n){
int val = perm[i];
for(int j = i+1; j < n; j++){
// cout << perm[j] << " " << val << endl;
if(perm[j] % val == 0){
flag[j] = !flag[j];
}
}
}
int sum = 0;
REP(i, n) sum += flag[i];
// cout << sum << endl;
cou++;
return sum;
}
int sum = 0;
REP(i, n){
if(!used[i]){
perm[d] = coins[i];
used[i] = 1;
sum += dfs(d+1, used, perm);
used[i] = 0;
}
}
return sum;
};
int main(int argc, const char * argv[]){
begin();
cin >> n;
if(n > 8) return 0;
REP(i, n) cin >> coins[i];
int used[8]; REP(i, 8) used[i] = 0;
int perm[8];
// cout << dfs(0, used, perm) / (long double)cou << endl;
printf("%f", (dfs(0, used, perm) / (double)cou));
}
Submission Info
Submission Time |
|
Task |
C - コイン |
User |
yoshikyoto |
Language |
C++ (G++ 4.6.4) |
Score |
0 |
Code Size |
8333 Byte |
Status |
WA |
Exec Time |
44 ms |
Memory |
1052 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
Subtask2 |
Score / Max Score |
0 / 0 |
0 / 99 |
0 / 1 |
Status |
|
|
|
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 |
WA |
44 ms |
948 KB |
sample_02.txt |
WA |
26 ms |
928 KB |
sample_03.txt |
WA |
26 ms |
952 KB |
subtask1_01.txt |
WA |
26 ms |
952 KB |
subtask1_02.txt |
WA |
26 ms |
1044 KB |
subtask1_03.txt |
WA |
28 ms |
980 KB |
subtask1_04.txt |
WA |
39 ms |
1008 KB |
subtask1_05.txt |
WA |
39 ms |
980 KB |
subtask1_06.txt |
WA |
26 ms |
948 KB |
subtask1_07.txt |
WA |
34 ms |
952 KB |
subtask1_08.txt |
WA |
26 ms |
928 KB |
subtask1_09.txt |
WA |
29 ms |
872 KB |
subtask1_10.txt |
WA |
39 ms |
1048 KB |
subtask1_11.txt |
WA |
27 ms |
1044 KB |
subtask1_12.txt |
WA |
38 ms |
860 KB |
subtask1_13.txt |
WA |
26 ms |
944 KB |
subtask1_14.txt |
WA |
27 ms |
948 KB |
subtask1_15.txt |
WA |
43 ms |
952 KB |
subtask1_16.txt |
WA |
36 ms |
1048 KB |
subtask1_17.txt |
WA |
39 ms |
1044 KB |
subtask1_18.txt |
WA |
41 ms |
1040 KB |
subtask1_19.txt |
WA |
38 ms |
1048 KB |
subtask1_20.txt |
WA |
40 ms |
984 KB |
subtask2_01.txt |
WA |
25 ms |
952 KB |
subtask2_02.txt |
WA |
25 ms |
952 KB |
subtask2_03.txt |
WA |
25 ms |
880 KB |
subtask2_04.txt |
WA |
24 ms |
920 KB |
subtask2_05.txt |
WA |
25 ms |
924 KB |
subtask2_06.txt |
WA |
25 ms |
1048 KB |
subtask2_07.txt |
WA |
26 ms |
876 KB |
subtask2_08.txt |
WA |
26 ms |
880 KB |
subtask2_09.txt |
WA |
25 ms |
944 KB |
subtask2_10.txt |
WA |
24 ms |
948 KB |
subtask2_11.txt |
WA |
25 ms |
948 KB |
subtask2_12.txt |
WA |
29 ms |
952 KB |
subtask2_13.txt |
WA |
24 ms |
924 KB |
subtask2_14.txt |
WA |
24 ms |
1048 KB |
subtask2_15.txt |
WA |
27 ms |
1052 KB |
subtask2_16.txt |
WA |
25 ms |
1040 KB |
subtask2_17.txt |
WA |
25 ms |
932 KB |
subtask2_18.txt |
WA |
24 ms |
1032 KB |
subtask2_19.txt |
WA |
25 ms |
952 KB |
subtask2_20.txt |
WA |
25 ms |
984 KB |