QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789420#9782. NonZero PrefSuf Sumsucup-team3519#AC ✓1203ms3948kbC++173.7kb2024-11-27 20:19:182024-11-27 20:19:21

Judging History

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

  • [2024-11-27 20:19:21]
  • 评测
  • 测评结果:AC
  • 用时:1203ms
  • 内存:3948kb
  • [2024-11-27 20:19:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define V vector
#define pb push_back
#define fi first
#define se second
#define all0(x) (x).begin(), (x).end()
#define all1(x) (x).begin() + 1, (x).end()

typedef long long LL;
typedef pair<int, int> pi;

mt19937 mrand(chrono::steady_clock().now().time_since_epoch().count());

int mod;
LL MOD(LL x) {
    if(x >= mod) return x- mod;
    if(x < 0) return x + mod;
    return x;
}

LL qpow(LL x, LL k) {
    LL ans =1 ;
    while(k) {
        if(k & 1) ans = x * ans % mod;
        k >>= 1;
        x = x * x % mod;
    }
    return ans;
}
int n;
const int N = 101;
int ans[N], hav[N];

LL deal_dp(int t, int sum) {
    // cout << "t, sum : " << t << " " << sum << endl;
    V<V<LL>> dp(n * 2 + 1, V<LL>(2));
    V<V<LL>> n_dp(n * 2 + 1, V<LL>(2));
    dp[n][0] = 1;
    int lo = 2 - sum;   
    for(int i = 1; i <= n; i++) {
        for(auto &v : n_dp) for(auto &x : v) x = 0;
        for(int j = -n; j <= n; j++) {
            //
            int l = lo + j, r = j + 2;
            l = max(-n, l);
            //0->0
            if(l <= n) n_dp[l + n][0] = MOD(n_dp[l + n][0] + dp[j + n][0]);
            if(r <= n) n_dp[r + n][0] = MOD(n_dp[r + n][0] - dp[j + n][0]);
            //1->1
            if(l <= n) n_dp[l + n][1] = MOD(n_dp[l + n][1] + dp[j + n][1]);
            if(r <= n) n_dp[r + n][1] = MOD(n_dp[r + n][1] - dp[j + n][1]);

            l = j + -t, r = lo - 1 + j + 1;
            l = max(-n, l);
            // cout << "i, j, l, r : " << i << " " << j << " " << l << " " << r << endl;
            if(l <= r) {
                //0->1
                if(l <= n) n_dp[l + n][1] = MOD(n_dp[l + n][1] + dp[j + n][0]);
                if(r <= n) n_dp[r + n][1] = MOD(n_dp[r + n][1] - dp[j + n][0]);
                //1->1
                if(l <= n) n_dp[l + n][1] = MOD(n_dp[l + n][1] + dp[j + n][1]);
                if(r <= n) n_dp[r + n][1] = MOD(n_dp[r + n][1] - dp[j + n][1]);
            }
        }
        for(int i = 1; i < n_dp.size(); i++) {
            n_dp[i][0] = MOD(n_dp[i][0] + n_dp[i - 1][0]);
            n_dp[i][1] = MOD(n_dp[i][1] + n_dp[i - 1][1]);
        }
        swap(dp, n_dp);
        // cout << "dp , i : " << i << endl;
        // for(int i = -n; i <= n; i++) cout << dp[n + i][0] << " ";
        // cout << endl;
        // for(int i = -n; i <= n; i++) cout << dp[i + n][1] << " ";
        // cout << endl;
    } 
    return dp[sum + n][1];
}

LL cal_t(int t) {
    if(hav[t]) return ans[t];
    //
    for(int sum = 1; sum <= n; sum++) {
        ans[t] = MOD(ans[t] + deal_dp(t, sum));
        // cout << "t, sum, dp : " << t << " " << sum << " " << deal_dp(t, sum) << endl;
    }
    hav[t] = 1;
    return ans[t];
}


void solve(){
    int m; cin >> n >> m;
    cin >> mod;
    LL ans = 0;
    ans = qpow(2 * m + 1, n);
    // cout << "ans : " << ans << endl;
    for(int x = 1; x <= m; x++) {
        ans -= 2 * cal_t(m / x);    
    }
    ans = MOD(ans % mod);
    // cout << "ans : " << ans << endl;


    int tot = n * m;

    V<LL> dp(2 * tot + 1);
    auto n_dp = dp;
    dp[tot] = 1;
    for(int i = 1; i <= n; i++) {
        for(auto &x : n_dp) x = 0;
        for(int j = -tot; j <= tot; j++) {
            if(dp[tot + j] == 0) continue;
            for(int k = j - m; k <= j + m; k++) {
                n_dp[tot + k] = MOD(n_dp[tot + k] + dp[tot + j]);
            }
        }
        dp = n_dp;
    }
    ans = MOD(ans - dp[tot]);
    // cout << "ans : " << ans << endl;
    cout << ans << "\n";

}
int main() {
    // ios::sync_with_stdio(0),cin.tie(0);
    // int t; cin >> t;
    // while(t--) 
        solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3812kb

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 181ms
memory: 3744kb

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #3:

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

input:

2 1 998244353

output:

2

result:

ok single line: '2'

Test #4:

score: 0
Accepted
time: 183ms
memory: 3696kb

input:

69 42 696969697

output:

378553557

result:

ok single line: '378553557'

Test #5:

score: 0
Accepted
time: 242ms
memory: 3948kb

input:

61 75 677323601

output:

34613998

result:

ok single line: '34613998'

Test #6:

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

input:

13 14 670577333

output:

41465431

result:

ok single line: '41465431'

Test #7:

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

input:

14 6 987686347

output:

37536510

result:

ok single line: '37536510'

Test #8:

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

input:

15 12 196428923

output:

29322522

result:

ok single line: '29322522'

Test #9:

score: 0
Accepted
time: 42ms
memory: 3672kb

input:

68 7 786815587

output:

149281835

result:

ok single line: '149281835'

Test #10:

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

input:

3 2 503002109

output:

82

result:

ok single line: '82'

Test #11:

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

input:

13 5 756093197

output:

415698676

result:

ok single line: '415698676'

Test #12:

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

input:

2 3 646574611

output:

30

result:

ok single line: '30'

Test #13:

score: 0
Accepted
time: 71ms
memory: 3728kb

input:

39 68 120037189

output:

43217507

result:

ok single line: '43217507'

Test #14:

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

input:

13 4 423132517

output:

360231790

result:

ok single line: '360231790'

Test #15:

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

input:

14 3 309713387

output:

94215386

result:

ok single line: '94215386'

Test #16:

score: 0
Accepted
time: 22ms
memory: 3704kb

input:

24 77 886983941

output:

211636479

result:

ok single line: '211636479'

Test #17:

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

input:

3 3 504388063

output:

270

result:

ok single line: '270'

Test #18:

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

input:

3 1 936205423

output:

8

result:

ok single line: '8'

Test #19:

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

input:

3 3 295983139

output:

270

result:

ok single line: '270'

Test #20:

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

input:

10 15 446169107

output:

149884328

result:

ok single line: '149884328'

Test #21:

score: 0
Accepted
time: 15ms
memory: 3540kb

input:

37 18 833753929

output:

592917251

result:

ok single line: '592917251'

Test #22:

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

input:

11 3 998773403

output:

860630017

result:

ok single line: '860630017'

Test #23:

score: 0
Accepted
time: 8ms
memory: 3620kb

input:

14 85 688036639

output:

347188409

result:

ok single line: '347188409'

Test #24:

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

input:

3 3 844621907

output:

270

result:

ok single line: '270'

Test #25:

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

input:

3 4 204335891

output:

620

result:

ok single line: '620'

Test #26:

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

input:

7 8 113007667

output:

58946097

result:

ok single line: '58946097'

Test #27:

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

input:

4 1 637268377

output:

22

result:

ok single line: '22'

Test #28:

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

input:

11 14 391637237

output:

303270280

result:

ok single line: '303270280'

Test #29:

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

input:

3 2 208286231

output:

82

result:

ok single line: '82'

Test #30:

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

input:

2 11 662696483

output:

462

result:

ok single line: '462'

Test #31:

score: 0
Accepted
time: 9ms
memory: 3620kb

input:

19 55 974135299

output:

887460557

result:

ok single line: '887460557'

Test #32:

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

input:

6 8 417027509

output:

23351024

result:

ok single line: '23351024'

Test #33:

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

input:

8 13 624006587

output:

353008442

result:

ok single line: '353008442'

Test #34:

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

input:

10 10 740294671

output:

79436611

result:

ok single line: '79436611'

Test #35:

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

input:

11 10 394088657

output:

161476458

result:

ok single line: '161476458'

Test #36:

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

input:

9 27 562853573

output:

135252259

result:

ok single line: '135252259'

Test #37:

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

input:

8 3 829129009

output:

5349034

result:

ok single line: '5349034'

Test #38:

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

input:

51 49 924010279

output:

815049368

result:

ok single line: '815049368'

Test #39:

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

input:

12 2 308466749

output:

223013998

result:

ok single line: '223013998'

Test #40:

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

input:

7 4 567557693

output:

4502296

result:

ok single line: '4502296'

Test #41:

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

input:

36 93 943780729

output:

13599465

result:

ok single line: '13599465'

Test #42:

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

input:

2 1 828681127

output:

2

result:

ok single line: '2'

Test #43:

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

input:

3 3 534160729

output:

270

result:

ok single line: '270'

Test #44:

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

input:

7 12 920925433

output:

453086694

result:

ok single line: '453086694'

Test #45:

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

input:

3 2 440546987

output:

82

result:

ok single line: '82'

Test #46:

score: 0
Accepted
time: 122ms
memory: 3676kb

input:

90 9 291269963

output:

72560304

result:

ok single line: '72560304'

Test #47:

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

input:

38 10 867575113

output:

165530481

result:

ok single line: '165530481'

Test #48:

score: 0
Accepted
time: 61ms
memory: 3572kb

input:

48 37 152663531

output:

135425620

result:

ok single line: '135425620'

Test #49:

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

input:

15 15 991731803

output:

102703562

result:

ok single line: '102703562'

Test #50:

score: 0
Accepted
time: 1203ms
memory: 3616kb

input:

100 100 696969697

output:

313377809

result:

ok single line: '313377809'

Extra Test:

score: 0
Extra Test Passed