Contest Duration: - (local time) (120 minutes) Back to Home

Submission #169865

Source Code Expand

Copy
```#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

unsigned long xor128(unsigned long n){
static unsigned long x=time(NULL),y=362436069,z=521288629,w=88675123;
unsigned long t;
t=(x^(x<<11));
x=y;
y=z;
z=w;
return w=((w^(w>>19))^(t^(t>>8)))%n;
}

int count_opens(VI &perm, VI &coins) {
int opens = 0;
int N = perm.size();

for (int i = 0; i < N; i++) {
bool rev = true;
for (int j = 0; j < i; j++) {
rev = !(coins[perm[i]] % coins[perm[j]]) ^ rev;
}
opens += rev;
}

return opens;
}

int main(void) {
int N;
cin >> N;
VI coins(N);
for(auto &coin : coins) {
cin >> coin;
}

VI perm(N);
iota(perm.begin(), perm.end(), 0);

int opens = 0;
int loop;

if (N <= 8) {
loop = 0;
do {
opens += count_opens(perm, coins);
loop++;
} while(next_permutation(perm.begin(), perm.end()));
}else {
loop = 1e+5;
for (int l = 0; l < loop; l++) {
random_shuffle(perm.begin(), perm.end(), xor128);
opens += count_opens(perm, coins);
}
}

cout << ((double)opens / (double)loop) << endl;

return 0;
}
```

#### Submission Info

Submission Time 2014-05-10 23:00:09+0900 C - コイン snakazawa C++11 (GCC 4.8.1) 99 1621 Byte WA 2031 ms 932 KB

#### Judge Result

Score / Max Score 0 / 0 99 / 99 0 / 1
Status
 AC × 2 WA × 1
 AC × 20
 AC × 24 WA × 4 TLE × 12
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
sample_01.txt WA 20 ms 928 KB
sample_02.txt AC 21 ms 920 KB
sample_03.txt AC 20 ms 748 KB
subtask1_01.txt AC 23 ms 928 KB
subtask1_02.txt AC 21 ms 804 KB
subtask1_03.txt AC 22 ms 928 KB
subtask1_04.txt AC 28 ms 924 KB
subtask1_05.txt AC 30 ms 800 KB
subtask1_06.txt AC 24 ms 844 KB
subtask1_07.txt AC 28 ms 812 KB
subtask1_08.txt AC 22 ms 924 KB
subtask1_09.txt AC 22 ms 928 KB
subtask1_10.txt AC 28 ms 932 KB
subtask1_11.txt AC 20 ms 928 KB
subtask1_12.txt AC 29 ms 920 KB
subtask1_13.txt AC 21 ms 924 KB
subtask1_14.txt AC 22 ms 912 KB
subtask1_15.txt AC 28 ms 796 KB
subtask1_16.txt AC 29 ms 736 KB
subtask1_17.txt AC 28 ms 928 KB
subtask1_18.txt AC 29 ms 764 KB
subtask1_19.txt AC 29 ms 772 KB
subtask1_20.txt AC 28 ms 804 KB
subtask2_01.txt WA 61 ms 924 KB
subtask2_02.txt AC 162 ms 792 KB
subtask2_03.txt WA 253 ms 800 KB
subtask2_04.txt WA 786 ms 808 KB
subtask2_05.txt TLE 2029 ms 800 KB
subtask2_06.txt AC 1849 ms 796 KB
subtask2_07.txt AC 1441 ms 800 KB
subtask2_08.txt TLE 2029 ms 884 KB
subtask2_09.txt TLE 2030 ms 808 KB
subtask2_10.txt TLE 2030 ms 800 KB
subtask2_11.txt TLE 2029 ms 924 KB
subtask2_12.txt TLE 2030 ms 808 KB
subtask2_13.txt WA 1089 ms 804 KB
subtask2_14.txt TLE 2030 ms 808 KB
subtask2_15.txt TLE 2031 ms 804 KB
subtask2_16.txt TLE 2030 ms 800 KB
subtask2_17.txt TLE 2029 ms 808 KB
subtask2_18.txt AC 1083 ms 800 KB
subtask2_19.txt TLE 2029 ms 880 KB
subtask2_20.txt TLE 2031 ms 792 KB