Submission #483872

#TimeUsernameProblemLanguageResultExecution timeMemory
483872Sohsoh84Anagramistica (COCI21_anagramistica)C++17
110 / 110
11 ms6400 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << ": " << x << endl; #define int ll const ll MAXN = 3e3 + 10; const ll INF = 8e18; const ll MOD = 1e9 + 7; // 998244353; ll poww(ll a, ll b, ll md) { return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md)); } ll A[MAXN], n, k, fact[MAXN], inv[MAXN], dp[MAXN][MAXN]; inline ll C(int k, int n) { return fact[n] * inv[k] % MOD * inv[n - k] % MOD; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); fact[0] = inv[0] = 1; for (int i = 1; i < MAXN; i++) fact[i] = i * fact[i - 1] % MOD, inv[i] = poww(fact[i], MOD - 2, MOD); cin >> n >> k; vector<string> v; for (int i = 0; i < n; i++) { string s; cin >> s; sort(all(s)); v.push_back(s); } sort(all(v)); int n = 0; for (int i = 0; i < v.size(); i++) { if (i == 0 || v[i] != v[i - 1]) n++; A[n]++; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= k; j++) { for (int t = 0; t <= A[i]; t++) { ll c2 = t * (t - 1) / 2; ll c = C(t, A[i]); if (c2 > j) continue; dp[i][j] += dp[i - 1][j - c2] * c % MOD; dp[i][j] %= MOD; } } } cout << dp[n][k] << endl; return 0; }

Compilation message (stderr)

anagramistica.cpp: In function 'int32_t main()':
anagramistica.cpp:46:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for (int i = 0; i < v.size(); i++) {
      |                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...