제출 #589647

#제출 시각아이디문제언어결과실행 시간메모리
589647nguyen31hoang08minh2003Anagramistica (COCI21_anagramistica)C++14
110 / 110
11 ms8020 KiB
/* +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+ |:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:| |\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/| |/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\| +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+ |\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/| |/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\| |:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:| +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+ |:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:| |\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/| |/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\| +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+ |\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/| |/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\| |:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:| +------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+ */ #include <bits/stdc++.h> #define fore(i, a, b) for (signed i = (a), i##_last = (b); i < i##_last; ++i) #define fort(i, a, b) for (signed i = (a), i##_last = (b); i <= i##_last; ++i) #define ford(i, a, b) for (signed i = (a), i##_last = (b); i >= i##_last; --i) #define fi first #define se second #define pb push_back #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using ld = long double; template<class A, class B> bool maxi(A &a, const B &b) {return (a < b) ? (a = b, true):false;}; template<class A, class B> bool mini(A &a, const B &b) {return (a > b) ? (a = b, true):false;}; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<ll> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; template<class T> T sorted(T t) { sort(all(t)); return t; } const int MOD = 1e9 + 7; #define maxN 2005 #define maxK 2005 int C(int n, int k) { static int c[maxN][maxN]; static bool seen[maxN][maxN]; if (n < k || n < 0) return 0; if (n == k) return 1; if (!seen[n][k]) { seen[n][k] = true; c[n][k] = (C(n - 1, k - 1) + C(n - 1, k)) % MOD; } return c[n][k]; } string word[maxN]; int n, k, m, g[maxN]; map<string, int> anagrams; void input() { cin >> n >> k; fore(i, 0, n) { cin >> word[i]; ++anagrams[sorted(word[i])]; } } int DP(int x, int y) { static int dp[maxN][maxK]; static bool seen[maxN][maxK]; if (y < 0) return 0; if (x < 0) return !y; if (!seen[x][y]) { seen[x][y] = true; for (int z = 0; z <= g[x] && C(z, 2) <= k; ++z) (dp[x][y] += 1LL * DP(x - 1, y - C(z, 2)) * C(g[x], z) % MOD) %= MOD; } return dp[x][y]; } void solve() { for (const auto &[x, y] : anagrams) g[m++] = y; cout << DP(m - 1, k) << '\n'; } int main() { #ifdef LOCAL freopen("input.INP", "r", stdin); #endif // LOCAL cin.tie(0) -> sync_with_stdio(0); cout.tie(0); input(); solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

anagramistica.cpp: In function 'void solve()':
anagramistica.cpp:96:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   96 |     for (const auto &[x, y] : anagrams)
      |                      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...