# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
336744 | nandonathaniel | PIN (CEOI10_pin) | C++14 | 664 ms | 14780 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;
map<string,int> mp[16];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
long long ans=0;
string s;
int n,d;
cin >> n >> d;
for(int it=1;it<=n;it++){
cin >> s;
for(int mask=0;mask<(1<<4);mask++){
if(__builtin_popcount(mask)!=d)continue;
string t="";
vector<int> v;
bool ya[4];
memset(ya,false,sizeof(ya));
for(int i=0;i<4;i++){
if((1<<i) & mask)v.push_back(i);
else ya[i]=true;
}
for(int i=0;i<(1<<v.size());i++){
for(int j=0;j<v.size();j++){
if((1<<j) & i)ya[v[j]]=true;
}
int msk=0;
string k="";
for(int j=0;j<4;j++){
if(ya[j]){
msk+=(1<<j);
k+=s[j];
}
}
if(__builtin_popcount(i)&1)ans-=mp[msk][k];
else ans+=mp[msk][k];
for(int j=0;j<v.size();j++){
if((1<<j) & i)ya[v[j]]=false;
}
}
}
for(int mask=0;mask<(1<<4);mask++){
string t="";
for(int i=0;i<4;i++){
if((1<<i) & mask)t+=s[i];
}
mp[mask][t]++;
}
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |