Submission #1078156

#TimeUsernameProblemLanguageResultExecution timeMemory
1078156ntnqLozinke (COCI17_lozinke)C++17
20 / 100
16 ms18776 KiB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define N 100005
#define quick ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
int n, a[N], ans;
string s[N];
struct node 
{
	node* child[26];
	int dem;
};

node* u1 = new node();

void Add(string s) 
{
	node* u = u1;
	for (int i = 0 ; i < s.size();i++) 
	{
		int k = s[i] - 'a';
		if (u -> child[k] == NULL) 
		 u -> child[k] = new node();
		u = u -> child[k];
		u -> dem++; 
	}
}

int getTrie(string s)
{
	node* u = u1;
	for (int i = 0 ; i < s.size(); i++) 
	{
		int k = s[i] - 'a';
		u = u -> child[k];
		if (i == s.size() - 1) return (u -> dem) - 1;		
	}
}

int main()
{
	quick;
	cin >> n;
	for (int i = 1; i <= n; i++) 
	{
		cin >> s[i];
		Add(s[i]);
	}
	for (int i = 1; i <= n; i++)
	{
		ans += getTrie(s[i]);
	} 
	cout << ans;
	return 0;
}

Compilation message (stderr)

lozinke.cpp: In function 'void Add(std::string)':
lozinke.cpp:23:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for (int i = 0 ; i < s.size();i++)
      |                   ~~^~~~~~~~~~
lozinke.cpp: In function 'int getTrie(std::string)':
lozinke.cpp:36:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for (int i = 0 ; i < s.size(); i++)
      |                   ~~^~~~~~~~~~
lozinke.cpp:40:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   if (i == s.size() - 1) return (u -> dem) - 1;
      |       ~~^~~~~~~~~~~~~~~
lozinke.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...