답안 #682632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682632 2023-01-16T16:05:42 Z Alex_tz307 Anagramistica (COCI21_anagramistica) C++17
110 / 110
10 ms 14292 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int mod = 1e9 + 7;
const int N = 2e3;
int dp[1 + N], C[1 + N][1 + N];
 
void addSelf(int &x, int y) {
  x += y;
  if (x >= mod) {
    x -= mod;
  }
}
 
int add(int x, int y) {
  addSelf(x, y);
  return x;
}
 
int mult(int x, int y) {
  return (int64_t)x * y % mod;
}
 
void precalc(int n) {
  for (int i = 0; i <= n; ++i) {
    C[i][0] = 1;
 
    for (int j = 1; j <= i; ++j) {
      C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);
    }
  }
}
 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
 
  int n, k;
  cin >> n >> k;
 
  precalc(n);
 
  unordered_map<string, int> cnt;
 
  for (int i = 0; i < n; ++i) {
    string word;
    cin >> word;
 
    sort(word.begin(), word.end());
 
    cnt[word] += 1;
  }
 
  dp[0] = 1;
 
  for (const auto &it : cnt) {
    int subSize = it.second;
 
    for (int pairs = k; pairs >= 0; --pairs) {
      for (int take = 1; take <= subSize && C[take][2] <= pairs; ++take) {
        addSelf(dp[pairs], mult(dp[pairs - C[take][2]], C[subSize][take]));
      }
    }
  }
 
  cout << dp[k] << '\n';
 
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8148 KB Output is correct
2 Correct 7 ms 10196 KB Output is correct
3 Correct 9 ms 12116 KB Output is correct
4 Correct 8 ms 14036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 6 ms 8148 KB Output is correct
7 Correct 7 ms 10196 KB Output is correct
8 Correct 9 ms 12116 KB Output is correct
9 Correct 8 ms 14036 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
11 Correct 2 ms 3412 KB Output is correct
12 Correct 3 ms 6356 KB Output is correct
13 Correct 5 ms 6356 KB Output is correct
14 Correct 6 ms 10196 KB Output is correct
15 Correct 6 ms 10136 KB Output is correct
16 Correct 10 ms 14292 KB Output is correct
17 Correct 10 ms 14036 KB Output is correct
18 Correct 8 ms 14036 KB Output is correct