QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560436#670. K-th Stringucup-team1198#RE 0ms3812kbC++201.7kb2024-09-12 15:45:082024-09-12 15:45:09

Judging History

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

  • [2024-09-12 15:45:09]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3812kb
  • [2024-09-12 15:45:08]
  • 提交

answer

#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;

const int MOD = 1e9 + 7;

int add(int a, int b) {
  return a + b >= MOD ? a + b - MOD : a + b;
}

int sub(int a, int b) {
  return a >= b ? a - b : a + MOD - b;
}

int mul(int a, int b) {
  return (1ll * a * b) % MOD;
}

int knapsack(vector<int> x, int s, int k) {
  vector<vector<int>> dp(s + 1, vector<int>(k + 1, 0));
  dp[0][0] = 1;
  for (int t : x) {
    for (int i = k - 1; i >= 0; --i) {
      for (int j = s - t; j >= 0; --j) {
        dp[j + t][i + 1] = add(dp[j + t][i + 1], dp[j][i]);
      }
    }
  }
  return dp[s][k];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int l = s.size();
  int sumid = (s[0] - 'a') * n + l - k;
  int ans = 0;
  for (int i = l; i <= n; ++i) {
    vector<int> ind;
    for (int j = 0; j + l < i; ++j) {
      ind.push_back(j);
    }
    for (int j = i; j < n; ++j) {
      ind.push_back(j);
    }
    int sum = sumid;
    int k = (s[0] - 'a');
    for (int j = 0; j < l; ++j) {
      if (s[j] < s[0]) {
        --k;
        sum -= (i - l + j);
      }
    }
    int mlt = 1;
    for (int i = 1; i <= k; ++i) {
      mlt = mul(mlt, i);
    }
    for (int i = 1; i <= n - l - k; ++i) {
      mlt = mul(mlt, i);
    }
    ans = add(ans, mul(mlt, knapsack(ind, sum, k)));
  }
  cout << ans << "\n";

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 12
caedgfb

output:

0

result:

ok single line: '0'

Test #2:

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

input:

2 3
b

output:

1

result:

ok single line: '1'

Test #3:

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

input:

8 4
febadh

output:

0

result:

ok single line: '0'

Test #4:

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

input:

1 1
a

output:

1

result:

ok single line: '1'

Test #5:

score: -100
Runtime Error

input:

4 9
bca

output:


result: