# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96661 | noneTP | Parametriziran (COCI19_parametriziran) | C++14 | 2307 ms | 42820 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
int hv[10];
char s[10];
map<int, int> dp[64][64];
int main(){
LL ans = 0;
hv[0] = 1;
for(int i=1;i<10;i++) hv[i] = (hv[i-1]*1ll*hf)%mod;
int n, m;
scanf("%d%d", &n, &m);
for(int i=1;i<=n;i++){
scanf("%s", s);
int b = 0;
for(int j=0;j<m;j++){
if(s[j] == '?') b+=(1<<j);
}
for(int j=0;j<(1<<m);j++){
int c = (b|j), val = 0;
for(int k=0;k<m;k++){
if((c>>k)&1) continue;
val = (val + hv[k]*1ll*s[k])%mod;
}
c ^= j;
if(dp[j][c].count(val)) ans = (ans + dp[j][c][val]);
}
vector<int> v;
int x = (1<<m)-1 - b;
for(int j=0;j<m;j++){
if((x>>j)&1) v.push_back(j);
}
int sz = v.size();
for(int j=0;j<(1<<sz);j++){
int c = 0, val = 0;
for(int k=0;k<sz;k++){
if((j>>k)&1) c |= (1<<v[k]);
else val = (val + hv[v[k]]*1ll*s[v[k]])%mod;
}
dp[b][c][val]++;
}
}
printf("%lld\n", ans);
}
Compilation message (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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |