Turn off internal display without closing lid
CJam, 30 26 bytes
q~](/:$_za+{e`0f=:m!:*}//*
Try it online in the CJam interpreter.
It completes this test case in less than a second:
$ time cjam <(echo 'q~](/:$_za+{e`0f=:m!:*}%)\:*\/N') < test-large.in | md5sum
5801bbf8ed0f4e43284f7ec2206fd3ff -
real 0m0.308s
user 0m0.667s
sys 0m0.044s
Running it in the online interpreter should take less than 10 seconds.
Algorithm
The result does not depend on the order of A, so we can assume it to be sorted. This means that B must also be sorted to attain the maximal dot product.
Now, if r1, … rn are the length of the runs of the sorted A, there are ∏rk! different rearrangements of the elements of A that still result in ascending order.
Likewise, if s1, … sn are the length of the runs of the sorted B, there are ∏sk! different rearrangements of the elements of B that still result in ascending order.
However, this counts all pairings multiple times. If we take the pairs of of the corresponding elements of sorted A and sorted B and define t1, … tn as the length of the runs of the resulting array, ∏tk! is the aforementioned multiplier.
Thus, the desired result is (∏rk!) × (∏sk!) ÷ (∏tk!).
Code
q~ Read and evaluate all input.
] Wrap the resulting integers in an array.
( Shift out the first (length).
/ Split the remainder into chunks of that length.
:$ Sort each chunk.
_z Push a copy and transpose rows with columns.
This pushes the array of corresponding pairs.
a+ Wrap in array and concatenate (append).
{ }/ For A, B, and zip(A,B):
e` Perform run-length encoding.
0f= Select the runs.
:m! Apply factorial to each.
:* Reduce by multiplication.
/ Divide the second result by the third.
* Multiply the quotient with the first result.
Yes, Apache can be used as a proxy server on Windows, using the built-in mod_proxy. PHP is not required for the proxy functionality. We have been using it as a reverse proxy for years running on Windows Server 2003 with no issues, and there is no reason why Windows Server 2008 will be any different.
I recommend you use the latest stable 2.2 version as older versions had some issues with the reverse proxy functionality.
Matlab, 230 bytes
Edit: Many things fixed to match dennis' test cases, and nnz is replaced by numel due to nil values.
f=1;t=-1;q=1;a=sort(input(''));b=sort(input(''));for i=unique(a)c=b(find(a==i));r=numel(c(c==t));f=f*factorial(numel(c))*sum(arrayfun(@(u)nchoosek(max(q,r),u),0:min(q,r)));z=c(end);y=numel(c(c==z));q=(t==z)*(q+r)+(t~=z)*y;t=z;end,f
Execution
[2 2 1 2 1]
[3 2 3 2 1]
f =
24
Dennis' Testcase:
A = importdata('f:\a.csv'); for i=1:100,a=sort(A(i,1:6));b=sort(A(i,7:12));
f=1;t=-1;q=1;for i=unique(a)c=b(find(a==i));r=numel(c(c==t));f=f*factorial(numel(c))*sum(arrayfun(@(u)nchoosek(max(q,r),u),0:min(q,r)));z=c(end);y=numel(c(c==z));q=(t==z)*(q+r)+(t~=z)*y;t=z;end;
disp(f);end
Outputs:
4
4
8
4
8
2
4
4
4
36
2
8
24
8
2
2
6
2
8
2
12
2
8
12
4
12
4
6
8
8
6
4
48
8
4
1
4
4
8
4
12
2
96
2
4
2
6
24
24
48
4
8
12
8
4
2
24
16
2
8
24
4
24
4
12
8
12
4
8
4
16
4
8
8
4
4
4
4
72
24
4
4
4
2
12
4
8
4
36
6
12
8
4
2
8
24
6
1
2
2