QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#118111 | #5444. Tavern Chess | hos_lyric | AC ✓ | 1269ms | 124412kb | C++14 | 4.2kb | 2023-07-03 03:46:41 | 2023-07-03 03:46:51 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
using Double = double;
int N[2];
Int A[2][7];
Int ASum[2][1 << 7];
map<vector<int>, pair<Double, Double>> cache[2][7][7];
pair<Double, Double> solve(int turn, int cur0, int cur1, const vector<int> &ps) {
#define id(h, i) ((h) ? (N[0] + (i)) : (i))
int alive[2] = {};
for (int h = 0; h < 2; ++h) for (int i = 0; i < N[h]; ++i) {
if (~ps[id(h, i)]) {
++alive[h];
}
}
if (!alive[0] && !alive[1]) return make_pair(0.0, 0.0);
if (!alive[0]) return make_pair(0.0, 1.0);
if (!alive[1]) return make_pair(1.0, 0.0);
for (; !~ps[id(0, cur0)]; ) if (++cur0 == N[0]) cur0 = 0;
for (; !~ps[id(1, cur1)]; ) if (++cur1 == N[1]) cur1 = 0;
int nxt0 = cur0;
int nxt1 = cur1;
if (turn == 0) if (++nxt0 == N[0]) nxt0 = 0;
if (turn == 1) if (++nxt1 == N[1]) nxt1 = 0;
auto it = cache[turn][cur0][cur1].find(ps);
if (it != cache[turn][cur0][cur1].end()) return it->second;
Double ret[2] = {};
const int i = turn ? cur1 : cur0;
for (int j = 0; j < N[turn ^ 1]; ++j) if (~ps[id(turn ^ 1, j)]) {
const Int ai = A[turn ][i];
const Int aj = A[turn ^ 1][j];
const Int hi = ai - ASum[turn ^ 1][ps[id(turn, i)]];
const Int hj = aj - ASum[turn ][ps[id(turn ^ 1, j)]];
auto qs = ps;
if (hi > aj) {
if (hj > ai) {
assert(false);
} else {
qs[id(turn, i)] |= 1 << j;
qs[id(turn ^ 1, j)] = -1;
}
} else {
if (hj > ai) {
qs[id(turn, i)] = -1;
qs[id(turn ^ 1, j)] |= 1 << i;
} else {
qs[id(turn, i)] = -1;
qs[id(turn ^ 1, j)] = -1;
}
}
const auto res = solve(turn ^ 1, nxt0, nxt1, qs);
ret[0] += res.first;
ret[1] += res.second;
}
for (int h = 0; h < 2; ++h) {
ret[h] /= alive[turn ^ 1];
}
#undef id
// if(N[0]==2)cerr<<turn<<" "<<cur0<<" "<<cur1<<" "<<ps<<": "<<ret[0]<<" "<<ret[1]<<endl;
return cache[turn][cur0][cur1][ps] = make_pair(ret[0], ret[1]);
}
int main() {
for (; ~scanf("%d%d", &N[0], &N[1]); ) {
for (int h = 0; h < 2; ++h) for (int i = 0; i < N[h]; ++i) {
scanf("%lld", &A[h][i]);
}
for (int h = 0; h < 2; ++h) {
for (int i = 0; i < N[h]; ++i) {
for (int p = 0; p < 1 << i; ++p) {
ASum[h][p | 1 << i] = ASum[h][p] + A[h][i];
}
}
}
for (int h = 0; h < 2; ++h) {
for (int i0 = 0; i0 < N[0]; ++i0) for (int i1 = 0; i1 < N[1]; ++i1) {
cache[h][i0][i1].clear();
}
}
Double ans[2] = {};
for (int h = 0; h < 2; ++h) if (N[h] >= N[h ^ 1]) {
// cerr<<"start turn = "<<h<<endl;
const auto res = solve(h, 0, 0, vector<int>(N[0] + N[1], 0));
ans[0] += res.first;
ans[1] += res.second;
}
if (N[0] == N[1]) {
for (int h = 0; h < 2; ++h) {
ans[h] /= 2.0;
}
}
printf("%.12f\n", ans[0]);
printf("%.12f\n", ans[1]);
printf("%.12f\n", 1.0 - (ans[0] + ans[1]));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3648kb
input:
2 3 2 5 3 4 1
output:
0.125000000000 0.750000000000 0.125000000000
result:
ok 3 numbers
Test #2:
score: 0
Accepted
time: 8ms
memory: 5004kb
input:
6 6 1 1 4 5 1 4 1 1 4 5 1 4
output:
0.241867283951 0.241867283951 0.516265432099
result:
ok 3 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
7 7 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
0.000000000000 0.000000000000 1.000000000000
result:
ok 3 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
1 7 7 1 1 1 1 1 1 1
output:
0.000000000000 0.000000000000 1.000000000000
result:
ok 3 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
2 3 736618938 652769331 328875880 97571721 44608905
output:
1.000000000000 0.000000000000 0.000000000000
result:
ok 3 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3708kb
input:
5 4 53585130 731696211 668322278 611205195 158818781 569587984 776042583 745745433 330119007
output:
0.066840277778 0.664351851852 0.268807870370
result:
ok 3 numbers
Test #7:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
7 2 578505806 551611151 92903265 403642038 542119417 57334031 307573613 897644535 168524310
output:
1.000000000000 0.000000000000 0.000000000000
result:
ok 3 numbers
Test #8:
score: 0
Accepted
time: 4ms
memory: 4752kb
input:
5 6 113196606 64768263 772808463 787707989 500151952 481840741 676847825 4641268 431386165 847736311 169677832
output:
0.136323173868 0.522397183642 0.341279642490
result:
ok 3 numbers
Test #9:
score: 0
Accepted
time: 28ms
memory: 9244kb
input:
6 6 260666773 527612597 471926610 702232282 559007797 606173983 560573055 928117268 101411867 875949818 907478252 182117037
output:
0.000000000000 0.960819573045 0.039180426955
result:
ok 3 numbers
Test #10:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
3 3 333377599 3066695 67916629 426841530 865184552 974638244
output:
0.000000000000 1.000000000000 0.000000000000
result:
ok 3 numbers
Test #11:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
1 1 529429019 529428649
output:
1.000000000000 0.000000000000 0.000000000000
result:
ok 3 numbers
Test #12:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
3 3 12886596 817437415 465037461 12886473 817437448 465037967
output:
0.069444444444 0.652777777778 0.277777777778
result:
ok 3 numbers
Test #13:
score: 0
Accepted
time: 37ms
memory: 10316kb
input:
6 6 211213374 319527017 257080158 176742665 53109345 33822515 53109265 319527076 176743175 257080012 211212799 33822353
output:
0.423399959276 0.319386584791 0.257213455933
result:
ok 3 numbers
Test #14:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
1 2 1 1 1
output:
0.000000000000 1.000000000000 0.000000000000
result:
ok 3 numbers
Test #15:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
1 2 1 1 3
output:
0.000000000000 1.000000000000 0.000000000000
result:
ok 3 numbers
Test #16:
score: 0
Accepted
time: 1ms
memory: 3728kb
input:
1 2 2 4 2
output:
0.000000000000 1.000000000000 0.000000000000
result:
ok 3 numbers
Test #17:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
1 2 3 5 5
output:
0.000000000000 1.000000000000 0.000000000000
result:
ok 3 numbers
Test #18:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
1 2 4 1 2
output:
1.000000000000 0.000000000000 0.000000000000
result:
ok 3 numbers
Test #19:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
1 2 5 2 5
output:
0.000000000000 0.000000000000 1.000000000000
result:
ok 3 numbers
Test #20:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
1 2 5 5 5
output:
0.000000000000 1.000000000000 0.000000000000
result:
ok 3 numbers
Test #21:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
2 2 1 1 1 3
output:
0.000000000000 1.000000000000 0.000000000000
result:
ok 3 numbers
Test #22:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
2 2 1 1 2 3
output:
0.000000000000 1.000000000000 0.000000000000
result:
ok 3 numbers
Test #23:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
2 2 1 4 2 5
output:
0.000000000000 0.500000000000 0.500000000000
result:
ok 3 numbers
Test #24:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
2 2 2 2 1 4
output:
0.000000000000 0.000000000000 1.000000000000
result:
ok 3 numbers
Test #25:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
2 2 3 2 4 1
output:
0.000000000000 0.500000000000 0.500000000000
result:
ok 3 numbers
Test #26:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
2 2 3 3 1 3
output:
1.000000000000 0.000000000000 0.000000000000
result:
ok 3 numbers
Test #27:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
2 2 3 3 2 4
output:
0.000000000000 0.000000000000 1.000000000000
result:
ok 3 numbers
Test #28:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
2 2 3 3 5 3
output:
0.000000000000 1.000000000000 0.000000000000
result:
ok 3 numbers
Test #29:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
2 2 4 3 2 1
output:
1.000000000000 0.000000000000 0.000000000000
result:
ok 3 numbers
Test #30:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
2 2 4 3 4 4
output:
0.000000000000 1.000000000000 0.000000000000
result:
ok 3 numbers
Test #31:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
2 2 5 1 5 2
output:
0.125000000000 0.625000000000 0.250000000000
result:
ok 3 numbers
Test #32:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
2 2 5 1 5 3
output:
0.125000000000 0.625000000000 0.250000000000
result:
ok 3 numbers
Test #33:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
2 2 5 2 2 3
output:
0.875000000000 0.000000000000 0.125000000000
result:
ok 3 numbers
Test #34:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
2 2 5 4 1 2
output:
1.000000000000 0.000000000000 0.000000000000
result:
ok 3 numbers
Test #35:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
2 2 5 4 3 5
output:
0.875000000000 0.000000000000 0.125000000000
result:
ok 3 numbers
Test #36:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
2 2 5 5 1 4
output:
1.000000000000 0.000000000000 0.000000000000
result:
ok 3 numbers
Test #37:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
2 2 5 5 2 2
output:
1.000000000000 0.000000000000 0.000000000000
result:
ok 3 numbers
Test #38:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
1 1 6 6
output:
0.000000000000 0.000000000000 1.000000000000
result:
ok 3 numbers
Test #39:
score: 0
Accepted
time: 2ms
memory: 3828kb
input:
5 5 6 5 9 9 3 3 5 9 9 6
output:
0.297870370370 0.278773148148 0.423356481481
result:
ok 3 numbers
Test #40:
score: 0
Accepted
time: 19ms
memory: 7176kb
input:
6 6 10 2 3 4 5 7 5 2 4 3 10 7
output:
0.254010456854 0.192773705418 0.553215837727
result:
ok 3 numbers
Test #41:
score: 0
Accepted
time: 146ms
memory: 23684kb
input:
7 7 7 6 8 6 7 3 9 7 6 9 8 7 3 6
output:
0.310913751426 0.365768367914 0.323317880660
result:
ok 3 numbers
Test #42:
score: 0
Accepted
time: 6ms
memory: 5376kb
input:
6 6 5 4 7 9 9 10 9 4 9 7 5 10
output:
0.216942435057 0.327856545782 0.455201019162
result:
ok 3 numbers
Test #43:
score: 0
Accepted
time: 1ms
memory: 3672kb
input:
4 4 9 7 10 6 9 7 6 10
output:
0.330873842593 0.262297453704 0.406828703704
result:
ok 3 numbers
Test #44:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
3 3 3 10 3 3 10 3
output:
0.187500000000 0.187500000000 0.625000000000
result:
ok 3 numbers
Test #45:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
2 2 3 4 3 4
output:
0.000000000000 0.000000000000 1.000000000000
result:
ok 3 numbers
Test #46:
score: 0
Accepted
time: 257ms
memory: 35176kb
input:
7 7 922750124 99645786 685060385 948410807 266950246 996521461 883971852 266950246 99645786 883971852 685060385 922750124 996521461 948410807
output:
0.363356371416 0.279566405512 0.357077223072
result:
ok 3 numbers
Test #47:
score: 0
Accepted
time: 589ms
memory: 61848kb
input:
7 7 241155912 361580213 393947982 781406405 485516551 277202028 115028196 485516551 361580213 115028196 393947982 241155912 277202028 781406405
output:
0.370176093600 0.278789945304 0.351033961097
result:
ok 3 numbers
Test #48:
score: 0
Accepted
time: 172ms
memory: 24392kb
input:
7 7 565748008 734938287 873800405 879803305 473331973 893190834 623040014 473331973 734938287 623040014 873800405 565748008 893190834 879803305
output:
0.364305908017 0.315603554227 0.320090537756
result:
ok 3 numbers
Test #49:
score: 0
Accepted
time: 492ms
memory: 58728kb
input:
7 7 14 4 6 5 201506030 15 15 4 14 201506030 15 15 6 5
output:
0.178183791652 0.337081509870 0.484734698478
result:
ok 3 numbers
Test #50:
score: 0
Accepted
time: 515ms
memory: 58076kb
input:
7 7 3 2 3 5 784861968 2 1 2 3 784861968 1 2 3 5
output:
0.223075021873 0.316151580233 0.460773397894
result:
ok 3 numbers
Test #51:
score: 0
Accepted
time: 1269ms
memory: 124412kb
input:
7 7 8 15 3 9 168061718 2 5 15 8 168061718 5 2 3 9
output:
0.212969595988 0.319962995067 0.467067408945
result:
ok 3 numbers
Test #52:
score: 0
Accepted
time: 258ms
memory: 39040kb
input:
7 7 859736717 19 19 18 13 10 7 7 10 13 18 19 19 859736717
output:
0.393620652595 0.147967266252 0.458412081153
result:
ok 3 numbers
Test #53:
score: 0
Accepted
time: 379ms
memory: 52644kb
input:
7 7 761045932 18 13 11 9 7 6 6 7 9 11 13 18 761045932
output:
0.382467689555 0.147493238655 0.470039071790
result:
ok 3 numbers
Test #54:
score: 0
Accepted
time: 447ms
memory: 57040kb
input:
7 7 379524878 17 16 14 10 6 1 1 6 10 14 16 17 379524878
output:
0.379260293300 0.176536722080 0.444202984620
result:
ok 3 numbers
Test #55:
score: 0
Accepted
time: 437ms
memory: 60516kb
input:
7 7 986258805 329018732 16 14 10 10 4 4 10 10 14 16 329018732 986258805
output:
0.335206523508 0.168228186482 0.496565290010
result:
ok 3 numbers
Test #56:
score: 0
Accepted
time: 390ms
memory: 56508kb
input:
7 7 402437510 39859989 20 20 18 17 7 7 17 18 20 20 39859989 402437510
output:
0.328699473643 0.160263058269 0.511037468088
result:
ok 3 numbers
Test #57:
score: 0
Accepted
time: 509ms
memory: 68276kb
input:
7 7 719895666 88341845 15 11 10 6 5 5 6 10 11 15 88341845 719895666
output:
0.341541058763 0.169436596666 0.489022344571
result:
ok 3 numbers
Test #58:
score: 0
Accepted
time: 902ms
memory: 102084kb
input:
7 7 22 657372492 8 20 531193761 10 21 8 22 20 657372492 531193761 21 10
output:
0.283032035859 0.214331641403 0.502636322739
result:
ok 3 numbers
Test #59:
score: 0
Accepted
time: 894ms
memory: 98628kb
input:
7 7 8 559730577 2 23 543514141 3 24 2 8 23 559730577 543514141 24 3
output:
0.283681616583 0.222015713450 0.494302669967
result:
ok 3 numbers
Test #60:
score: 0
Accepted
time: 747ms
memory: 84084kb
input:
7 7 24 416408320 4 25 698151361 24 15 4 24 25 416408320 698151361 15 24
output:
0.297516368443 0.247286586967 0.455197044590
result:
ok 3 numbers