Submission #1078716

# Submission time Handle Problem Language Result Execution time Memory
1078716 2024-08-28T05:00:42 Z khactrung1912 Lozinke (COCI17_lozinke) C++14
20 / 100
16 ms 18780 KB
#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;
//	freopen("PASS.inp", "r", stdin);
//	freopen("PASS.out", "w", stdout);
	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

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 time Memory Grader output
1 Incorrect 2 ms 3416 KB Output isn't correct
2 Incorrect 2 ms 3600 KB Output isn't correct
3 Incorrect 2 ms 3588 KB Output isn't correct
4 Incorrect 2 ms 3672 KB Output isn't correct
5 Incorrect 2 ms 3932 KB Output isn't correct
6 Incorrect 2 ms 4148 KB Output isn't correct
7 Incorrect 2 ms 4700 KB Output isn't correct
8 Correct 3 ms 5256 KB Output is correct
9 Incorrect 5 ms 6488 KB Output isn't correct
10 Incorrect 8 ms 10588 KB Output isn't correct
11 Incorrect 10 ms 8796 KB Output isn't correct
12 Correct 16 ms 17500 KB Output is correct
13 Incorrect 7 ms 7956 KB Output isn't correct
14 Incorrect 14 ms 18012 KB Output isn't correct
15 Incorrect 15 ms 18780 KB Output isn't correct
16 Incorrect 5 ms 4188 KB Output isn't correct
17 Correct 3 ms 3676 KB Output is correct
18 Correct 4 ms 3704 KB Output is correct
19 Incorrect 13 ms 12892 KB Output isn't correct
20 Incorrect 4 ms 4052 KB Output isn't correct