Submission #74540

# Submission time Handle Problem Language Result Execution time Memory
74540 2018-09-03T11:40:09 Z ZZangZZang Lozinke (COCI17_lozinke) C++17
85 / 100
1000 ms 4076 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <functional>
#include <string>
#include <set>

typedef long long ll;
using namespace std;

ll n, sol = 0;
string s[20001];
multiset<ll> ms;

ll trans(string& s)
{
	ll ret = 0;
	for(ll i=0; i<s.size(); i++) ret += (ll)(s[i]-'a'+1), ret *= 27;
	return ret;
}

int main()
{
	scanf("%lld", &n);
	for(ll i=0; i<n; i++)
	{
		char str[20]; scanf("%s", str);
		s[i] = string(str);
		ms.insert(trans(s[i]));
	}
	for(ll k=0; k<n; k++)
	{
		set<ll> l;
		vector<ll> v;
		ll full = trans(s[k]);
		for(ll i=0; i<s[k].size(); i++)
		{
			string tmp;
			for(ll j=i; j<s[k].size(); j++)
			{
				tmp += s[k][j];
				ll ttmp = trans(tmp);
				if(l.find(ttmp) == l.end()) l.insert(ttmp), v.push_back(ttmp);
			}
		}
		for(ll i=0; i<v.size(); i++)
		{
			if(v[i] == full) sol += (ll)(ms.count(v[i]) - 1);
			else sol += (ll)(ms.count(v[i]));
		}
	}
	printf("%lld", sol);
	return 0;
}

Compilation message

lozinke.cpp: In function 'll trans(std::__cxx11::string&)':
lozinke.cpp:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ll i=0; i<s.size(); i++) ret += (ll)(s[i]-'a'+1), ret *= 27;
              ~^~~~~~~~~
lozinke.cpp: In function 'int main()':
lozinke.cpp:38:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ll i=0; i<s[k].size(); i++)
               ~^~~~~~~~~~~~
lozinke.cpp:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(ll j=i; j<s[k].size(); j++)
                ~^~~~~~~~~~~~
lozinke.cpp:48:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(ll i=0; i<v.size(); i++)
               ~^~~~~~~~~
lozinke.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
lozinke.cpp:29:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   char str[20]; scanf("%s", str);
                 ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 892 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
3 Correct 3 ms 1152 KB Output is correct
4 Correct 3 ms 1160 KB Output is correct
5 Correct 8 ms 1204 KB Output is correct
6 Correct 12 ms 1212 KB Output is correct
7 Correct 15 ms 1368 KB Output is correct
8 Correct 15 ms 1368 KB Output is correct
9 Correct 235 ms 1824 KB Output is correct
10 Correct 87 ms 1928 KB Output is correct
11 Correct 470 ms 2272 KB Output is correct
12 Correct 117 ms 2504 KB Output is correct
13 Correct 147 ms 2840 KB Output is correct
14 Correct 334 ms 2964 KB Output is correct
15 Correct 155 ms 3220 KB Output is correct
16 Correct 166 ms 3388 KB Output is correct
17 Execution timed out 1067 ms 3468 KB Time limit exceeded
18 Execution timed out 1084 ms 3684 KB Time limit exceeded
19 Correct 162 ms 3888 KB Output is correct
20 Execution timed out 1055 ms 4076 KB Time limit exceeded