# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
636645 | Mr_Ph | Lozinke (COCI17_lozinke) | C++14 | 3 ms | 340 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.
///Never gonna give you up.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
const ll mod=(ll)1e9+7;
const ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
///the end of the defines ;)
void bla()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("notsus.txt","w",stdout);
#endif
}
ll power(ll x,ll y)
{
if(y==0)
return 1;
if(y==1)
return x%mod;
ll r=power(x%mod,(y%mod)/2)%mod;
if(y%2)
return ((r%mod)*(r%mod)*(x%mod));
else
return ((r%mod)*(r%mod));
}
ll lcm(ll a,ll b)
{
return max(a,b)/__gcd(a,b)*min(a,b);
}
void preprocess(){}
void solve()
{
int n;
cin>>n;
vector<string>arr(n);
ent(arr);
sort(all(arr));
map<string,int>mp;
int ans=0;
for(int i=0;i<n;i++)mp[arr[i]]++;
for(int i=0;i<n;i++)
{
mp[arr[i]]--;
bool valid=true;
set<string>st;
for(int k=0; k<arr[i].sz; k++)
{
string c;
for(int e=k; e<arr[i].sz; e++)
{
c+=arr[i][e];
st.insert(c);
}
}
for(auto i:st)
{
ans+=mp[i];
//cout<<i<<" "<<mp[i]<<endl;
}
//cout<<"goodbye"<<endl;
mp[arr[i]]++;
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
preprocess();
bla();
int t=1;
//cin>>t;
while(t--)
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |