답안 #589647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589647 2022-07-05T04:27:49 Z nguyen31hoang08minh2003 Anagramistica (COCI21_anagramistica) C++14
110 / 110
11 ms 8020 KB
/*
+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|
|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|
|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|
+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|
|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|
|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|
+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|:\/\/:|
|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|\/\/\/|
|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|/:/\:\|
+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|\:\/:/|
|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|/\/\/\|
|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|:/\/\:|
+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
*/
#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;
}

Compilation message

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)
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 388 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 400 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 3 ms 3732 KB Output is correct
3 Correct 2 ms 1056 KB Output is correct
4 Correct 2 ms 2516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 388 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 400 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 3 ms 3732 KB Output is correct
8 Correct 2 ms 1056 KB Output is correct
9 Correct 2 ms 2516 KB Output is correct
10 Correct 4 ms 2388 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 2 ms 852 KB Output is correct
14 Correct 3 ms 1876 KB Output is correct
15 Correct 2 ms 980 KB Output is correct
16 Correct 11 ms 8020 KB Output is correct
17 Correct 11 ms 1108 KB Output is correct
18 Correct 2 ms 2132 KB Output is correct