# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1077292 | khactrung1912 | Lozinke (COCI17_lozinke) | C++14 | 1067 ms | 65536 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;
#define fi first
#define se second
#define pb push_back
#define ins insert
#define BIT(x,i) ((1LL<<i)&x)
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define ll long long
#define ull unsigned long long
#define name "PASS"
const int mod=int(1e9+7);
int pi[8]={0,0,1,-1,1,1,-1,-1};
int pj[8]={-1,1,0,0,1,-1,1,-1};
template<class A,class B> inline void add(A &a,B b) { a+=b;while (a>=mod) a-=mod;}
template<class A,class B> inline void sub(A &a,B b) { a-=b;while (a>=mod) a-=mod;while (a<0) a+=mod;}
template<class A,class B> bool _max(A &a,B b) {if (a<b) return a=b,1; return 0;}
template<class A,class B> bool _min(A &a,B b) {if (a>b) return a=b,1; return 0;}
int n,res;
const int nmax=20010;
string a[nmax];
namespace Subtask1{
bool check(string &s,string &t){
int d=0;
for(auto chr:t) d+=chr==s[d];
return d==s.size();
}
void solve(){
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if (i!=j) res+=check(a[i],a[j]);
cout<<res;
}
}
namespace Subtask2{
void solve(){
unordered_map<string,int> dp;
for(int i=1;i<=n;i++) dp[a[i]]++;
for(int i=1;i<=n;i++){
dp[a[i]]--;
unordered_map<string,bool> uwu;
for(int mask=1;mask<(1<<a[i].size());mask++)
{
string tmp="";
for(int j=0;j<a[i].size();j++)
if (BIT(mask,j)) tmp+=a[i][j];
res+=dp[tmp]*(uwu[tmp]==0);
uwu[tmp]=1;
}
dp[a[i]]++;
}
cout<<res;
}
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if (fopen(name".INP","r"))
{
freopen(name".INP","r",stdin);
freopen(name".OUT","w+",stdout);
}
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
if (n<=2000) return Subtask1::solve(),0;
Subtask2::solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |