# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
480232 | mohamedsobhi777 | PIN (CEOI10_pin) | C++14 | 216 ms | 18084 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;
const int N = 2e5 + 7;
int n, d;
long long ans ;
string st[N] ;
map<long long,long long> atm[17] ;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
#endif
cin >> n >> d ;
d = 4 - d;
for(int i = 0 ;i < n; ++ i){
cin >> st[i] ;
}
vector<int> masks ;
for(int i = 1;i < 16 ;++ i){
masks.push_back(i) ;
}
sort(masks.begin(), masks.end(), [&](int x, int y){
return __builtin_popcount(x) > __builtin_popcount(y) ;
}) ;
for(int i = 0 ;i < n; ++ i ){
long long ret = 0 ;
vector<long long> dp(18, 0) ;
for(auto u : masks){
int hsh = 0 ;
for(int k = 0 ; k < 4 ; ++ k){
if(u&(1<<k)){
hsh = hsh * 150 + st[i][k] ;
}
}
dp[u] += atm[u][hsh]++ ;
for(int sub = u ; sub ; sub = (sub - 1) & u){
if(u != sub)
dp[sub] -= dp[u] ;
}
}
for(auto u : masks){
if(__builtin_popcount(u) == d){
ret += dp[u] ;
}
}
ans += ret ;
}
cout << ans ;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |