답안 #797932

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
797932 2023-07-30T07:26:09 Z acatmeowmeow Type Printer (IOI08_printer) C++11
0 / 100
43 ms 36680 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long 

struct trie {
	bool mark;
	trie *next[26];
	
	void extend(int index) { if (!next[index]) next[index] = new trie(); }

	void add(string&s, int index) {
		if (s.size() - 1 == index) mark = true;
		else {
			char nextChar = s[index + 1];
			extend(nextChar - 'a');
			next[nextChar - 'a']->add(s, index + 1);
		}
	}

	void query(vector<char>&ans) {
		if (mark) ans.push_back('P');
		for (int i = 0; i < 26; i++) {
			if (!next[i]) continue;
			ans.push_back(i + 'a');
			next[i]->query(ans);
			ans.push_back('-');
		}
	}
};

const int N = 25000;
int n;
trie *root[26];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		string s;
		cin >> s;
		if (!root[s[0] - 'a']) root[s[0] - 'a'] = new trie();
		root[s[0] - 'a']->add(s, 0);
	}
	vector<char> ans;
	for (int i = 0; i < 26; i++) {
		if (!root[i]) continue;
		ans.push_back(i + 'a');
		root[i]->query(ans);
		ans.push_back('-');
	}
	cout << ans.size() << '\n';
	for (auto&v : ans) cout << v << '\n';
	return 0;
}

Compilation message

printer.cpp: In member function 'void trie::add(std::string&, long long int)':
printer.cpp:14:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   14 |   if (s.size() - 1 == index) mark = true;
      |       ~~~~~~~~~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 5972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 14820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 36680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 28592 KB Output isn't correct
2 Halted 0 ms 0 KB -