Submission #1078156

# Submission time Handle Problem Language Result Execution time Memory
1078156 2024-08-27T13:25:32 Z ntnq Lozinke (COCI17_lozinke) C++17
20 / 100
16 ms 18776 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;
	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 1 ms 3420 KB Output isn't correct
3 Incorrect 2 ms 3420 KB Output isn't correct
4 Incorrect 1 ms 3676 KB Output isn't correct
5 Incorrect 2 ms 3972 KB Output isn't correct
6 Incorrect 2 ms 4108 KB Output isn't correct
7 Incorrect 3 ms 4700 KB Output isn't correct
8 Correct 3 ms 5212 KB Output is correct
9 Incorrect 6 ms 6492 KB Output isn't correct
10 Incorrect 13 ms 10772 KB Output isn't correct
11 Incorrect 7 ms 8796 KB Output isn't correct
12 Correct 16 ms 17648 KB Output is correct
13 Incorrect 8 ms 7772 KB Output isn't correct
14 Incorrect 13 ms 18008 KB Output isn't correct
15 Incorrect 13 ms 18776 KB Output isn't correct
16 Incorrect 4 ms 4188 KB Output isn't correct
17 Correct 4 ms 3764 KB Output is correct
18 Correct 3 ms 3676 KB Output is correct
19 Incorrect 10 ms 12716 KB Output isn't correct
20 Incorrect 4 ms 3928 KB Output isn't correct