Submission #494417

# Submission time Handle Problem Language Result Execution time Memory
494417 2021-12-15T12:13:56 Z asandikci Anagramistica (COCI21_anagramistica) C++17
10 / 110
39 ms 30740 KB
#include"iostream"
#include"vector"
// #include"queue"
// #include"deque"
// #include"set"
#include"map"
#include"algorithm"
#include"cstring"
#define int long long
using namespace std;

const int modn = 1e9+7;
const int maxn = 2005;


int add(int a,int b){
  return ((a+b)%modn+modn)%modn;
}
int mult(int a,int b){
  return (a*b)%modn;
}

int c[maxn][maxn];
int dp[maxn][maxn];
int arr[maxn];
map<string,int> mp;
void solve(){
  int n,k;
  cin >> n >> k;
  string str[n+5];
  int num=1;
  for(int i=0;i<n;i++){
    cin >> str[i];
    sort(str[i].begin(),str[i].end());
    if(mp[str[i]]==0){
      mp[str[i]]=num;
      arr[num]=1;
      num++;
    }
    else{
      arr[mp[str[i]]]++;
    }
  }
  c[0][0]=1;
  for(int i=1;i<=n;i++){
    c[i][0]=1;
    for(int j=1;j<=i;j++){
      c[i][j] = add(c[i][j],add(c[i-1][j-1],c[i-1][j]));
    }
  }
  int disct = mp.size();
  int ans=0;
  

  dp[0][0]=1;
  for(int i=1;i<=disct;i++){
    for(int j=0;j<=k;j++){
      for(int g=0;g<=arr[i];g++){
        dp[i][j] = add(dp[i][j],mult(c[arr[i]][g] , dp[i-1][j-c[g][2]]));
      }
    }
  }
  cout << dp[disct][k];
}

signed main(){
  ios::sync_with_stdio(false); cin.tie(0);
  // freopen("","r",stdin);freopen("","w",stdout);
  int t=1;
  // cin >>t;
  for(int i=1;i<=t;i++){
    // cout << "Case " << i << ":\n";
    solve();
  }
}

Compilation message

anagramistica.cpp: In function 'void solve()':
anagramistica.cpp:52:7: warning: unused variable 'ans' [-Wunused-variable]
   52 |   int ans=0;
      |       ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 11708 KB Output is correct
2 Runtime error 39 ms 30740 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 13 ms 11708 KB Output is correct
7 Runtime error 39 ms 30740 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -