| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 391949 | Jarif_Rahman | Anagramistica (COCI21_anagramistica) | C++17 | 40 ms | 50736 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll md = 1e9 + 7;
struct combination{
vector<vector<ll>> ncr;
combination(int k){
ncr = vector<vector<ll>>(k, vector<ll>(k, 0));
for(int i = 0; i < k; i++) ncr[i][0] = 1;
for(int i = 1; i < k; i++) for(int j = 1; j <= i; j++) ncr[i][j] = (ncr[i-1][j-1] + ncr[i-1][j])%md;
}
};
inline ll pw(ll x, ll p){
if(p == 0) return 1;
if(p%2 == 0) return((x*x)%md, p/2);
return (pw(x, p-1)*x)%md;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k; cin >> n >> k;
vector<str> v(n);
for(str &s: v){
cin >> s;
sort(s.begin(), s.end());
}
sort(v.begin(), v.end());
vector<int> sth;
ll ans = 0, p = 0;
for(int i = 0; i < n; i++){
if(i != 0 && v[i] == v[i-1]){
sth.back()++;
}
else{
sth.pb(1);
}
}
n = sth.size();
combination cmb(2500);
vector<vector<ll>> dp(n, vector<ll>(k+1, 0));
for(int i = n-1; i >= 0; i--){
ll c = sth[i];
for(int ki = 0; ki <= k; ki++){
for(int j = 0; j <= c; j++){
ll x = j;
x = x*(x-1)/2;
if(x > ki) continue;
if(x == ki && i == n-1){
dp[i][ki]+=cmb.ncr[c][j];
dp[i][ki]%=md;
continue;
}
if(i == n-1) continue;
dp[i][ki]+=(cmb.ncr[c][j]*dp[i+1][ki-x])%md;
dp[i][ki]%=md;
}
}
}
ans = dp[0][k];
ans%=md;
cout << ans << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
