QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#865871#117. Asceticismmakrav49 6ms7424kbC++201.3kb2025-01-22 03:04:232025-01-22 03:04:24

Judging History

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

  • [2025-01-22 03:04:24]
  • 评测
  • 测评结果:49
  • 用时:6ms
  • 内存:7424kb
  • [2025-01-22 03:04:23]
  • 提交

answer

#include <bits/stdc++.h>
#include <cassert>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
void shuf(vector<T>& a) {
    for (int i = 1; i < sz(a); i++) swap(a[i], a[rnd() % (i + 1)]);
}

const int mod = 1e9 + 7;
int sum(int x, int y) {
    return (x + y >= mod ? x + y - mod : x + y);
}
int mul(int x, int y) {
    return (x * 1ll * y) % mod;
}

void solve() {
    int n, k; cin >> n >> k;
    k--;
    vector<vector<int>> dp(n + 1, vector<int>(n + 1));
    dp[1][0] = 1;
    for (int np = 2; np <= n; np++) {
        for (int cnt = 0; cnt <= k; cnt++) {
            dp[np][cnt] = sum(mul(cnt + 1, dp[np - 1][cnt]), (cnt == 0 ? 0 : mul(np - cnt, dp[np - 1][cnt - 1])));
        }
    }
    cout << dp[n][k] << '\n';
}

signed main() {
    int tt = 1;
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> tt;
    #else
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
    #endif

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

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 4
Accepted

Test #1:

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

input:

1 1

output:

1

result:

ok single line: '1'

Test #2:

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

input:

10 10

output:

1

result:

ok single line: '1'

Test #3:

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

input:

10 2

output:

1013

result:

ok single line: '1013'

Test #4:

score: 4
Accepted
time: 1ms
memory: 3712kb

input:

10 1

output:

1

result:

ok single line: '1'

Test #5:

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

input:

10 7

output:

455192

result:

ok single line: '455192'

Test #6:

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

input:

8 3

output:

4293

result:

ok single line: '4293'

Test #7:

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

input:

9 6

output:

88234

result:

ok single line: '88234'

Test #8:

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

input:

3 3

output:

1

result:

ok single line: '1'

Test #9:

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

input:

5 2

output:

26

result:

ok single line: '26'

Test #10:

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

input:

7 5

output:

1191

result:

ok single line: '1191'

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #11:

score: 20
Accepted
time: 0ms
memory: 3840kb

input:

100 48

output:

491709703

result:

ok single line: '491709703'

Test #12:

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

input:

300 1

output:

1

result:

ok single line: '1'

Test #13:

score: 20
Accepted
time: 0ms
memory: 3824kb

input:

300 2

output:

322050458

result:

ok single line: '322050458'

Test #14:

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

input:

300 123

output:

562526258

result:

ok single line: '562526258'

Test #15:

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

input:

300 295

output:

713150320

result:

ok single line: '713150320'

Test #16:

score: 20
Accepted
time: 1ms
memory: 3764kb

input:

300 300

output:

1

result:

ok single line: '1'

Test #17:

score: 20
Accepted
time: 1ms
memory: 3968kb

input:

199 28

output:

168902681

result:

ok single line: '168902681'

Test #18:

score: 20
Accepted
time: 0ms
memory: 3840kb

input:

253 152

output:

68568956

result:

ok single line: '68568956'

Test #19:

score: 20
Accepted
time: 1ms
memory: 3712kb

input:

135 124

output:

736486204

result:

ok single line: '736486204'

Test #20:

score: 20
Accepted
time: 0ms
memory: 3712kb

input:

13 11

output:

1479726

result:

ok single line: '1479726'

Subtask #3:

score: 25
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #21:

score: 25
Accepted
time: 0ms
memory: 7296kb

input:

1000 1

output:

1

result:

ok single line: '1'

Test #22:

score: 25
Accepted
time: 0ms
memory: 7296kb

input:

1000 2

output:

688422209

result:

ok single line: '688422209'

Test #23:

score: 25
Accepted
time: 3ms
memory: 7424kb

input:

1000 452

output:

103920245

result:

ok single line: '103920245'

Test #24:

score: 25
Accepted
time: 3ms
memory: 7424kb

input:

1000 504

output:

359395606

result:

ok single line: '359395606'

Test #25:

score: 25
Accepted
time: 6ms
memory: 7424kb

input:

1000 952

output:

419943092

result:

ok single line: '419943092'

Test #26:

score: 25
Accepted
time: 4ms
memory: 7296kb

input:

1000 998

output:

945760313

result:

ok single line: '945760313'

Test #27:

score: 25
Accepted
time: 5ms
memory: 7424kb

input:

1000 1000

output:

1

result:

ok single line: '1'

Test #28:

score: 25
Accepted
time: 2ms
memory: 4992kb

input:

603 536

output:

797752199

result:

ok single line: '797752199'

Test #29:

score: 25
Accepted
time: 0ms
memory: 3840kb

input:

194 115

output:

19316534

result:

ok single line: '19316534'

Test #30:

score: 25
Accepted
time: 5ms
memory: 7424kb

input:

995 965

output:

79761626

result:

ok single line: '79761626'

Subtask #4:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #31:

score: 0
Time Limit Exceeded

input:

100000 1

output:


result: