Submission #884326

# Submission time Handle Problem Language Result Execution time Memory
884326 2023-12-07T07:01:42 Z vjudge1 Lozinke (COCI17_lozinke) C++17
100 / 100
69 ms 1628 KB
#ifndef Local
    #pragma GCC optimize("O3,unroll-loops")
    const int lim=2e5+100;
#else
    const int lim=2e3+100;
#endif

#include "bits/stdc++.h"
using namespace std;

#define int int64_t
#define pb push_back

const int mod=1e9+7;
using pii=pair<int,int>;

inline void solve(){
    int n;
    cin>>n;
    unordered_map<string,int>all;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        all[s]++;
    }
    int ans=0;
    for(auto [s,c]:all){
        ans+=c*(c-1);
        string now="";
        unordered_set<string>did;
        for(int i=0;i<s.size()-1;i++){
            now+=s[i];
            did.insert(now);
        }
        for(int i=1;i<s.size();i++){
            now="";
            for(int j=i;j<s.size();j++){
                now+=s[j];
                did.insert(now);
            }
        }
        for(string ss:did){
            if(!all.count(ss))continue;
            ans+=c*all[ss];
        }
    }
    cout<<ans<<"\n";
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
#ifdef Local  
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
#else
    //freopen("grass.in","r",stdin);
    //freopen("grass.out","w",stdout);
#endif
    int t=1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}

Compilation message

lozinke.cpp: In function 'void solve()':
lozinke.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int i=0;i<s.size()-1;i++){
      |                     ~^~~~~~~~~~~
lozinke.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int i=1;i<s.size();i++){
      |                     ~^~~~~~~~~
lozinke.cpp:37:26: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |             for(int j=i;j<s.size();j++){
      |                         ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 516 KB Output is correct
6 Correct 6 ms 604 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 6 ms 564 KB Output is correct
9 Correct 26 ms 860 KB Output is correct
10 Correct 27 ms 856 KB Output is correct
11 Correct 43 ms 1116 KB Output is correct
12 Correct 59 ms 1148 KB Output is correct
13 Correct 65 ms 1368 KB Output is correct
14 Correct 69 ms 1628 KB Output is correct
15 Correct 57 ms 1372 KB Output is correct
16 Correct 10 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 46 ms 1372 KB Output is correct
20 Correct 11 ms 344 KB Output is correct