Submission #1106192

# Submission time Handle Problem Language Result Execution time Memory
1106192 2024-10-29T13:53:25 Z Rainmaker2627 Type Printer (IOI08_printer) C++17
0 / 100
55 ms 35912 KB
#include<bits/stdc++.h>
using namespace std;

struct trie_node {
	bool end;
	int depth;
	trie_node* child[26];

	trie_node(int d) {
		end=false;
		depth=d;
		for (int i = 0; i < 26; ++i) child[i]=nullptr;
	}

	void add(string s, int i=0) {
		if (i==s.length()) {
			end=true;
		} else {
			if (child[s[i]-'a']==nullptr) child[s[i]-'a']=new trie_node(depth+1);
			child[s[i]-'a']->add(s, i+1);
		}
	}

	void traverse(char avoid) {
		if (end) cout << "P\n";
		for (char i = 'a'; i <= 'z'; ++i) {
			if (i==avoid || child[i-'a']==nullptr) continue;
			cout << i << '\n';
			child[i-'a']->traverse('-');
			cout << "-\n";
		}
	}
};

int main() {
	cin.tie(0)->sync_with_stdio(false);

	int n;
	cin >> n;

	string l="";
	trie_node begin(0);
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		if (s.length()>l.length()) l=s;
		begin.add(s);
	}

	trie_node *cur = &begin;
	for (int i = 0; i < l.length(); ++i) {
		cur->traverse(l[i]);
		cur=cur->child[l[i]-'a'];
		cout << l[i] << '\n';
	} cout << "P\n";

	return 0;
}

Compilation message

printer.cpp: In member function 'void trie_node::add(std::string, int)':
printer.cpp:16:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   if (i==s.length()) {
      |       ~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for (int i = 0; i < l.length(); ++i) {
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Expected integer, but "t" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Expected integer, but "h" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1872 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 5968 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 14672 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 55 ms 35912 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 28272 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -