QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#65855#4843. Infectious DiseaseNebula_xuanAC ✓1339ms225420kbC++142.2kb2022-12-03 20:54:312022-12-03 20:54:35

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-03 20:54:35]
  • 评测
  • 测评结果:AC
  • 用时:1339ms
  • 内存:225420kb
  • [2022-12-03 20:54:31]
  • 提交

answer

/****************
 *@description:for the Escape Project
 *@author: Nebula_xuan
 * @Date: 2022-12-03 20:37:06
 *************************************************************************/

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <assert.h>
// cout << fixed << setprecision(8) <<a;

using namespace std;

#define endl char(10)
#define int long long
#define hey cout << 1 << endl
//记得%d应该写成%lld

typedef pair<int, int> PII;
typedef long long ll;
const int N = 14e6 + 10;
int n, p[N], dp[16][N];
int ny[N];
const int MOD = 1e9 + 7;
int qmi(int a, int b)
{
    int ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ans;
}
int inv(int x)
{
    return qmi(x, MOD - 2);
}
int c(int n, int m)
{
    if (m > n)
        return 0;
    return (p[n] * ny[m] % MOD) * ny[n - m] % MOD;
}
void solve()
{
    cin >> n;
    dp[0][1] = 1;
    p[0] = 1;
    for (int i = 1; i <= n + 5; i++)
        p[i] = p[i - 1] * i % MOD;
    ny[n + 5] = qmi(p[n + 5], MOD - 2);
    for (int i = n + 4; i >= 0; i--)
        ny[i] = (ny[i + 1] * (i + 1)) % MOD;
    for (int i = 1; i <= 15; i++)
    {
        int sheng = n - qmi(3, i - 1), xuan = qmi(3, i) - qmi(3, i - 1);
        if (sheng <= xuan)
        {
            for (int j = 1; j <= (1 << (i - 1)); j++)
                dp[i][0] = (dp[i][0] + dp[i - 1][j]) % MOD;
            break;
        }
        int all = inv(c(sheng, xuan));
        for (int j = 0; j <= (1 << i); j++)
        {
            for (int k = max(1ll, (j + 1) >> 1); k <= (1 << (i - 1)); k++)
            {
                int gan = 2 * k - j;
                dp[i][j] = (dp[i][j] + dp[i - 1][k] * c(2 * k, gan) % MOD * c(sheng - 2 * k, xuan - gan) % MOD * all) % MOD;
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= 15; i++)
        ans = (ans + dp[i][0] * i) % MOD;
    cout << ans;
}

signed main()
{
    int T;
    T = 1;

    while (T--)
    {
        solve();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 7316kb

input:

2

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

114

output:

505208013

result:

ok 1 number(s): "505208013"

Test #3:

score: 0
Accepted
time: 1339ms
memory: 225420kb

input:

14000000

output:

44565093

result:

ok 1 number(s): "44565093"

Test #4:

score: 0
Accepted
time: 1330ms
memory: 199072kb

input:

12345678

output:

123143093

result:

ok 1 number(s): "123143093"

Test #5:

score: 0
Accepted
time: 90ms
memory: 20080kb

input:

776777

output:

764022068

result:

ok 1 number(s): "764022068"

Test #6:

score: 0
Accepted
time: 4ms
memory: 7316kb

input:

3

output:

1

result:

ok 1 number(s): "1"

Test #7:

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

input:

4

output:

666666673

result:

ok 1 number(s): "666666673"

Test #8:

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

input:

5

output:

833333341

result:

ok 1 number(s): "833333341"

Test #9:

score: 0
Accepted
time: 6ms
memory: 7332kb

input:

6

output:

300000004

result:

ok 1 number(s): "300000004"

Test #10:

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

input:

7

output:

533333339

result:

ok 1 number(s): "533333339"

Test #11:

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

input:

8

output:

952380961

result:

ok 1 number(s): "952380961"

Test #12:

score: 0
Accepted
time: 5ms
memory: 7368kb

input:

9

output:

964285723

result:

ok 1 number(s): "964285723"

Test #13:

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

input:

10

output:

416666672

result:

ok 1 number(s): "416666672"

Test #14:

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

input:

26

output:

990086590

result:

ok 1 number(s): "990086590"

Test #15:

score: 0
Accepted
time: 5ms
memory: 7368kb

input:

27

output:

528360342

result:

ok 1 number(s): "528360342"

Test #16:

score: 0
Accepted
time: 5ms
memory: 7388kb

input:

28

output:

273239648

result:

ok 1 number(s): "273239648"

Test #17:

score: 0
Accepted
time: 329ms
memory: 82628kb

input:

4782967

output:

332194401

result:

ok 1 number(s): "332194401"

Test #18:

score: 0
Accepted
time: 338ms
memory: 82988kb

input:

4782968

output:

362625027

result:

ok 1 number(s): "362625027"

Test #19:

score: 0
Accepted
time: 333ms
memory: 85456kb

input:

4782969

output:

971032452

result:

ok 1 number(s): "971032452"

Test #20:

score: 0
Accepted
time: 799ms
memory: 83260kb

input:

4782970

output:

452836984

result:

ok 1 number(s): "452836984"

Test #21:

score: 0
Accepted
time: 772ms
memory: 82692kb

input:

4782971

output:

349324970

result:

ok 1 number(s): "349324970"

Test #22:

score: 0
Accepted
time: 744ms
memory: 82140kb

input:

4782972

output:

46862963

result:

ok 1 number(s): "46862963"

Test #23:

score: 0
Accepted
time: 6ms
memory: 10396kb

input:

114514

output:

972669965

result:

ok 1 number(s): "972669965"

Test #24:

score: 0
Accepted
time: 308ms
memory: 37828kb

input:

1919810

output:

482430785

result:

ok 1 number(s): "482430785"

Test #25:

score: 0
Accepted
time: 1244ms
memory: 144868kb

input:

8877877

output:

486769120

result:

ok 1 number(s): "486769120"