QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#628660#7718. CoconutsAfterlife#AC ✓2356ms47116kbC++202.3kb2024-10-10 21:30:122024-10-10 21:30:12

Judging History

This is the latest submission verdict.

  • [2024-10-10 21:30:12]
  • Judged
  • Verdict: AC
  • Time: 2356ms
  • Memory: 47116kb
  • [2024-10-10 21:30:12]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int n,m;
int d[10];
unordered_map<ull,double> mp;
ull H(const vector<int> &a,const vector<int> &b){
    ull t=0;
    for(int i=0;i<(int)a.size();++i){
        t=t*11+a[i];
    }
    for(auto x:b)
    {
        t=t*13131331+x;
    }
    return t;
}
double dfs(const vector<int> &a,const vector<int> &b,int m){
    if(!m)return 0;
    // auto now=make_pair(H(a),H(b));
    auto now=H(a, b);
    if(mp.count(now))return mp[now];
    int k=a.size();
    double mx=0;
    for(int i=0;i<k;++i){
        int sum=0;
        double zz=0;
        if(i>0&&a[i]==a[i-1])continue;
        double las=0;int lasto=0;
        for(int j=0;j<k;++j){
            if(b[j]<=a[i])continue;
            double tmp=0;
            
            if(j>0&&b[j]==b[j-1]){
                tmp=las;
            }
            else{
                int z=0;
                int o=1;

                auto a0=a;
                auto b0=b;
                a0.erase(a0.begin()+i);
                b0.erase(b0.begin()+j);
                for(int p=0,q=0;p<k-1;++p){
                    while(q<k-1&&b0[q]>a0[p])++q;
                    if(q<=p){
                        o=0;
                        break;
                    }
                    o*=(q-p);
                }
                lasto=o;
                if(o){
                    if(b[j]==a[i]+1){
                        tmp=las=(dfs(a0,b0,m-1)+1)*o;
                    }
                    else{
                        auto A=a;
                        ++A[i];
                        tmp=las=dfs(A,b,m-1)*o;
                    }
                }
                else{
                    tmp=las=0;
                }
            }
            zz+=tmp;
            sum+=lasto;
        }
        mx=max(mx,zz/sum);
    }
    return mp[now]=mx;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(10);
    cin>>n>>m;
    for(int i=0;i<n;++i){
        cin>>d[i];
    }
    vector<int> a(n),b(n);
    for(int i=0;i<n;++i){
        b[i]=d[i];
    }
    sort(b.begin(),b.end(),greater<int>());
    cout<<dfs(a,b,m)<<'\n';
   // cerr<<" size: "<<mp.size()<<endl;
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

input:

3 2
1 3 3

output:

0.6666666667

result:

ok found '0.6666667', expected '0.6666667', error '0.0000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

4 5
2 2 3 3

output:

1.8333333333

result:

ok found '1.8333333', expected '1.8333333', error '0.0000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3756kb

input:

2 7
4 4

output:

1.0000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 4036kb

input:

5 5
3 3 2 3 2

output:

1.7000000000

result:

ok found '1.7000000', expected '1.7000000', error '0.0000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

2 6
4 2

output:

2.0000000000

result:

ok found '2.0000000', expected '2.0000000', error '0.0000000'

Test #6:

score: 0
Accepted
time: 0ms
memory: 4040kb

input:

4 6
2 3 3 3

output:

2.0000000000

result:

ok found '2.0000000', expected '2.0000000', error '0.0000000'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3972kb

input:

3 4
4 4 4

output:

1.0000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

3 7
4 4 4

output:

1.0000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #9:

score: 0
Accepted
time: 0ms
memory: 4044kb

input:

1 3
3

output:

1.0000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

5 2
3 2 2 2 3

output:

0.6000000000

result:

ok found '0.6000000', expected '0.6000000', error '0.0000000'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

5 5
4 4 3 2 3

output:

1.2000000000

result:

ok found '1.2000000', expected '1.2000000', error '0.0000000'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3812kb

input:

4 7
3 4 3 4

output:

1.8333333333

result:

ok found '1.8333333', expected '1.8333333', error '0.0000000'

Test #13:

score: 0
Accepted
time: 0ms
memory: 4032kb

input:

1 1
1

output:

1.0000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

5 1
1 1 1 1 1

output:

1.0000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3936kb

input:

5 3
2 2 2 2 2

output:

1.0000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

6 9
2 2 2 2 2 2

output:

4.0000000000

result:

ok found '4.0000000', expected '4.0000000', error '0.0000000'

Test #17:

score: 0
Accepted
time: 0ms
memory: 4056kb

input:

6 10
3 3 3 2 3 3

output:

3.0000000000

result:

ok found '3.0000000', expected '3.0000000', error '0.0000000'

Test #18:

score: 0
Accepted
time: 1ms
memory: 3860kb

input:

6 19
4 4 3 3 4 4

output:

5.0000000000

result:

ok found '5.0000000', expected '5.0000000', error '0.0000000'

Test #19:

score: 0
Accepted
time: 2ms
memory: 3912kb

input:

7 16
2 4 5 3 2 5 3

output:

4.3095238095

result:

ok found '4.3095238', expected '4.3095238', error '0.0000000'

Test #20:

score: 0
Accepted
time: 1ms
memory: 3784kb

input:

5 27
5 5 6 6 6

output:

4.0000000000

result:

ok found '4.0000000', expected '4.0000000', error '0.0000000'

Test #21:

score: 0
Accepted
time: 1ms
memory: 3852kb

input:

8 15
7 7 7 7 6 5 7 6

output:

2.0000000000

result:

ok found '2.0000000', expected '2.0000000', error '0.0000000'

Test #22:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

9 3
2 2 2 2 3 4 3 3 4

output:

0.7777777778

result:

ok found '0.7777778', expected '0.7777778', error '0.0000000'

Test #23:

score: 0
Accepted
time: 1ms
memory: 3820kb

input:

7 8
6 9 5 3 8 9 5

output:

0.8095238095

result:

ok found '0.8095238', expected '0.8095238', error '0.0000000'

Test #24:

score: 0
Accepted
time: 3ms
memory: 3988kb

input:

5 38
10 8 10 10 8

output:

4.0000000000

result:

ok found '4.0000000', expected '4.0000000', error '0.0000000'

Test #25:

score: 0
Accepted
time: 0ms
memory: 3944kb

input:

1 10
10

output:

1.0000000000

result:

ok found '1.0000000', expected '1.0000000', error '0.0000000'

Test #26:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

2 20
10 10

output:

2.0000000000

result:

ok found '2.0000000', expected '2.0000000', error '0.0000000'

Test #27:

score: 0
Accepted
time: 138ms
memory: 12572kb

input:

10 100
10 10 10 10 10 10 10 10 10 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #28:

score: 0
Accepted
time: 10ms
memory: 4204kb

input:

10 50
5 5 6 6 5 6 5 5 5 5

output:

9.0000000000

result:

ok found '9.0000000', expected '9.0000000', error '0.0000000'

Test #29:

score: 0
Accepted
time: 21ms
memory: 4676kb

input:

10 50
5 5 5 5 5 6 5 5 7 6

output:

9.0000000000

result:

ok found '9.0000000', expected '9.0000000', error '0.0000000'

Test #30:

score: 0
Accepted
time: 166ms
memory: 8896kb

input:

10 50
6 6 7 8 5 5 6 5 6 8

output:

7.6666666667

result:

ok found '7.6666667', expected '7.6666667', error '0.0000000'

Test #31:

score: 0
Accepted
time: 24ms
memory: 4620kb

input:

10 50
6 5 5 5 7 6 5 5 5 5

output:

9.0000000000

result:

ok found '9.0000000', expected '9.0000000', error '0.0000000'

Test #32:

score: 0
Accepted
time: 626ms
memory: 22472kb

input:

10 50
6 5 8 9 9 6 7 5 5 7

output:

7.0083333333

result:

ok found '7.0083333', expected '7.0083333', error '0.0000000'

Test #33:

score: 0
Accepted
time: 21ms
memory: 4836kb

input:

10 50
7 7 7 7 7 7 7 7 7 6

output:

7.0000000000

result:

ok found '7.0000000', expected '7.0000000', error '0.0000000'

Test #34:

score: 0
Accepted
time: 108ms
memory: 7964kb

input:

10 50
7 8 6 8 7 7 8 8 8 7

output:

6.0833333333

result:

ok found '6.0833333', expected '6.0833333', error '0.0000000'

Test #35:

score: 0
Accepted
time: 180ms
memory: 9212kb

input:

10 50
9 8 6 9 8 8 8 8 8 6

output:

6.0000000000

result:

ok found '6.0000000', expected '6.0000000', error '0.0000000'

Test #36:

score: 0
Accepted
time: 130ms
memory: 8056kb

input:

10 50
7 8 7 8 7 8 6 6 6 7

output:

6.8916666667

result:

ok found '6.8916667', expected '6.8916667', error '0.0000000'

Test #37:

score: 0
Accepted
time: 56ms
memory: 5944kb

input:

10 50
8 8 7 7 7 8 7 8 7 7

output:

6.0333333333

result:

ok found '6.0333333', expected '6.0333333', error '0.0000000'

Test #38:

score: 0
Accepted
time: 46ms
memory: 5708kb

input:

10 50
7 7 7 7 7 8 7 8 7 7

output:

6.5333333333

result:

ok found '6.5333333', expected '6.5333333', error '0.0000000'

Test #39:

score: 0
Accepted
time: 419ms
memory: 13760kb

input:

10 50
10 9 8 10 10 10 7 10 10 9

output:

5.0000000000

result:

ok found '5.0000000', expected '5.0000000', error '0.0000000'

Test #40:

score: 0
Accepted
time: 93ms
memory: 7972kb

input:

10 50
9 9 8 8 9 8 8 8 8 8

output:

5.8333333333

result:

ok found '5.8333333', expected '5.8333333', error '0.0000000'

Test #41:

score: 0
Accepted
time: 292ms
memory: 12688kb

input:

10 50
9 9 8 10 9 10 10 10 9 8

output:

5.0000000000

result:

ok found '5.0000000', expected '5.0000000', error '0.0000000'

Test #42:

score: 0
Accepted
time: 152ms
memory: 9104kb

input:

10 50
9 9 10 10 9 9 10 10 10 9

output:

5.0000000000

result:

ok found '5.0000000', expected '5.0000000', error '0.0000000'

Test #43:

score: 0
Accepted
time: 2356ms
memory: 46912kb

input:

10 55
1 2 3 4 5 6 7 8 9 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #44:

score: 0
Accepted
time: 2098ms
memory: 43800kb

input:

10 56
2 2 3 4 5 6 7 8 9 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #45:

score: 0
Accepted
time: 1665ms
memory: 42332kb

input:

10 57
2 2 3 4 5 6 7 9 9 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #46:

score: 0
Accepted
time: 1784ms
memory: 42500kb

input:

10 56
1 2 3 4 6 6 7 8 9 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #47:

score: 0
Accepted
time: 1342ms
memory: 29564kb

input:

10 54
1 2 3 4 5 6 7 8 9 9

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #48:

score: 0
Accepted
time: 1560ms
memory: 42144kb

input:

10 54
1 2 3 4 5 5 7 8 9 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #49:

score: 0
Accepted
time: 1834ms
memory: 42320kb

input:

10 54
1 2 3 4 5 6 7 9 9 10

output:

9.0000000000

result:

ok found '9.0000000', expected '9.0000000', error '0.0000000'

Test #50:

score: 0
Accepted
time: 1753ms
memory: 43248kb

input:

10 76
8 10 8 10 7 9 9 6 8 8

output:

8.9000000000

result:

ok found '8.9000000', expected '8.9000000', error '0.0000000'

Test #51:

score: 0
Accepted
time: 480ms
memory: 15524kb

input:

10 51
5 1 3 3 6 9 2 6 8 8

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #52:

score: 0
Accepted
time: 1348ms
memory: 42328kb

input:

10 60
6 3 10 2 4 2 10 5 8 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #53:

score: 0
Accepted
time: 1772ms
memory: 43456kb

input:

10 64
9 4 10 4 3 5 10 10 2 7

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #54:

score: 0
Accepted
time: 459ms
memory: 14596kb

input:

10 47
10 3 3 9 4 3 1 2 5 7

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #55:

score: 0
Accepted
time: 491ms
memory: 15344kb

input:

10 47
5 7 4 1 5 10 6 3 4 2

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #56:

score: 0
Accepted
time: 1995ms
memory: 43624kb

input:

10 60
3 4 8 3 7 10 8 2 6 9

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #57:

score: 0
Accepted
time: 1920ms
memory: 42960kb

input:

10 57
1 10 8 6 5 9 3 4 9 2

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #58:

score: 0
Accepted
time: 852ms
memory: 22624kb

input:

10 48
6 2 4 8 5 3 1 2 7 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #59:

score: 0
Accepted
time: 1160ms
memory: 27460kb

input:

10 51
3 1 4 9 2 7 5 10 6 4

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'

Test #60:

score: 0
Accepted
time: 1297ms
memory: 42232kb

input:

10 74
4 8 7 8 7 10 6 8 10 8

output:

9.0000000000

result:

ok found '9.0000000', expected '9.0000000', error '0.0000000'

Test #61:

score: 0
Accepted
time: 1996ms
memory: 47116kb

input:

10 71
8 10 10 9 10 8 9 6 7 10

output:

7.8444444444

result:

ok found '7.8444444', expected '7.8444444', error '0.0000000'

Test #62:

score: 0
Accepted
time: 380ms
memory: 16548kb

input:

10 93
9 9 10 10 10 10 10 9 10 10

output:

9.0000000000

result:

ok found '9.0000000', expected '9.0000000', error '0.0000000'

Test #63:

score: 0
Accepted
time: 1103ms
memory: 29740kb

input:

10 74
8 10 10 10 10 8 7 10 9 10

output:

7.7333333333

result:

ok found '7.7333333', expected '7.7333333', error '0.0000000'

Test #64:

score: 0
Accepted
time: 339ms
memory: 15976kb

input:

10 80
10 10 10 10 8 10 10 10 8 10

output:

8.0000000000

result:

ok found '8.0000000', expected '8.0000000', error '0.0000000'

Test #65:

score: 0
Accepted
time: 629ms
memory: 22992kb

input:

10 79
7 9 9 7 10 9 9 9 10 9

output:

8.8000000000

result:

ok found '8.8000000', expected '8.8000000', error '0.0000000'

Test #66:

score: 0
Accepted
time: 1200ms
memory: 30668kb

input:

10 67
7 9 8 7 10 10 10 10 7 9

output:

7.1333333333

result:

ok found '7.1333333', expected '7.1333333', error '0.0000000'

Test #67:

score: 0
Accepted
time: 623ms
memory: 23532kb

input:

10 86
10 8 10 10 10 10 7 10 10 8

output:

9.0000000000

result:

ok found '9.0000000', expected '9.0000000', error '0.0000000'

Test #68:

score: 0
Accepted
time: 117ms
memory: 9736kb

input:

10 67
10 10 10 10 10 10 10 10 10 10

output:

6.0000000000

result:

ok found '6.0000000', expected '6.0000000', error '0.0000000'

Test #69:

score: 0
Accepted
time: 367ms
memory: 14988kb

input:

10 59
10 8 10 10 7 10 10 10 10 10

output:

5.8666666667

result:

ok found '5.8666667', expected '5.8666667', error '0.0000000'

Test #70:

score: 0
Accepted
time: 1263ms
memory: 29324kb

input:

10 58
9 8 10 6 7 8 6 7 6 9

output:

7.1111111111

result:

ok found '7.1111111', expected '7.1111111', error '0.0000000'

Test #71:

score: 0
Accepted
time: 1103ms
memory: 30388kb

input:

10 89
7 10 10 9 10 10 10 7 8 10

output:

9.0000000000

result:

ok found '9.0000000', expected '9.0000000', error '0.0000000'

Test #72:

score: 0
Accepted
time: 1287ms
memory: 42308kb

input:

10 70
10 6 9 6 10 8 6 5 10 6

output:

8.9000000000

result:

ok found '8.9000000', expected '8.9000000', error '0.0000000'

Test #73:

score: 0
Accepted
time: 281ms
memory: 14576kb

input:

10 90
10 10 10 10 10 10 10 9 10 10

output:

9.0000000000

result:

ok found '9.0000000', expected '9.0000000', error '0.0000000'

Test #74:

score: 0
Accepted
time: 518ms
memory: 22424kb

input:

10 97
10 10 9 10 10 10 10 10 8 10

output:

10.0000000000

result:

ok found '10.0000000', expected '10.0000000', error '0.0000000'