Submission #49904

# Submission time Handle Problem Language Result Execution time Memory
49904 2018-06-04T16:07:51 Z computerbox Lozinke (COCI17_lozinke) C++14
0 / 100
3 ms 524 KB
 //ID:computerbox --> Hajiyev Huseyn
#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);/*cin.tie(0); cout.tie(0);*/
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 2000

using namespace std;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}      
  private:
    bool first;
    string separator;
};
 
template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}

struct vertex
{
  set<ll>leaf;
  ll next[30];
};
ll sz;
vertex t[3000000];

void add_string(string stroka,ll index)
{
  ll v=0;
  for(ll i=0;i<stroka.size();i++)
  {
    char c=stroka[i]-'a';
    if(t[v].next[c]==-1)
    {
      memset(t[sz].next,255,sizeof t[sz].next);
      t[v].next[c]=sz++;
    }
    v=t[v].next[c];
    t[v].leaf.insert(index);
  
  }

}





ll find(string stroka)
{
  ll maxa=0;
  ll v=0;
  ll cnt=0;
  for(ll i=0;i<stroka.size();i++)
  {
    char c=stroka[i]-'a';
    if(t[v].next[c]==-1)return 0;
    v=t[v].next[c];
  
  }
  return (t[v].leaf.size()-1);
}
ll n;
vector<string>nuj;
string stroka;
string abc;
int main(){
FAST_READ;
cin.tie(0);
cin>>n;
for(ll i=0;i<=3000000;i++)
{
  memset(t[i].next,-1,sizeof t[i].next);
}
sz=1;
for(ll i=1;i<=n;i++)
{
  cin>>stroka;
  string neww="";
  for(ll j=0;j<stroka.size();j++)
  {
    neww="";
     for(ll jj=j;jj<stroka.size();jj++)
     {
      neww+=stroka[jj];
      //debt(neww,j);
      add_string(neww,i);
     }
  }

  nuj.pb(stroka);
}

ll cnt=0;
for(ll i=0;i<nuj.size();i++)
{
  ll ans=find(nuj[i]);
  cnt=cnt+ans;
}
cout<<cnt<<endl;



return 0;
} 

Compilation message

lozinke.cpp: In function 'void add_string(std::__cxx11::string, long long int)':
lozinke.cpp:103:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ll i=0;i<stroka.size();i++)
              ~^~~~~~~~~~~~~~
lozinke.cpp:106:19: warning: array subscript has type 'char' [-Wchar-subscripts]
     if(t[v].next[c]==-1)
                   ^
lozinke.cpp:109:18: warning: array subscript has type 'char' [-Wchar-subscripts]
       t[v].next[c]=sz++;
                  ^
lozinke.cpp:111:18: warning: array subscript has type 'char' [-Wchar-subscripts]
     v=t[v].next[c];
                  ^
lozinke.cpp: In function 'long long int find(std::__cxx11::string)':
lozinke.cpp:127:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ll i=0;i<stroka.size();i++)
              ~^~~~~~~~~~~~~~
lozinke.cpp:130:19: warning: array subscript has type 'char' [-Wchar-subscripts]
     if(t[v].next[c]==-1)return 0;
                   ^
lozinke.cpp:131:18: warning: array subscript has type 'char' [-Wchar-subscripts]
     v=t[v].next[c];
                  ^
lozinke.cpp:124:6: warning: unused variable 'maxa' [-Wunused-variable]
   ll maxa=0;
      ^~~~
lozinke.cpp:126:6: warning: unused variable 'cnt' [-Wunused-variable]
   ll cnt=0;
      ^~~
lozinke.cpp: In function 'int main()':
lozinke.cpp:153:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ll j=0;j<stroka.size();j++)
              ~^~~~~~~~~~~~~~
lozinke.cpp:156:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for(ll jj=j;jj<stroka.size();jj++)
                  ~~^~~~~~~~~~~~~~
lozinke.cpp:168:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 for(ll i=0;i<nuj.size();i++)
            ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 2 ms 484 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 1 ms 484 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 1 ms 484 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 1 ms 484 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 2 ms 484 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 2 ms 484 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 2 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 2 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 2 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 2 ms 520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 3 ms 520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 2 ms 520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 1 ms 524 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 2 ms 524 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 2 ms 524 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 2 ms 524 KB Execution killed with signal 11 (could be triggered by violating memory limits)