답안 #661146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
661146 2022-11-24T17:04:01 Z as111 Type Printer (IOI08_printer) C++14
0 / 100
710 ms 57168 KB
//tries data structure, can be used for prefixes, etc.
#include <iostream>
#include <vector>
#include <string>

#define MAXN 25000

using namespace std;

struct Trie {
	int nex[26]; // index of next trie for each letter
	int prev; // parent
	bool end; // end of a word
	Trie() {
		fill(nex, nex + 26, -1);
		prev = -1;
		end = false;
	}
};
int N;
Trie tries[MAXN * 20 + 5];
char letters[200]; // store letter for each ascii value
int index = 1;
int wc = 0; //word count
void traverse(int curr) {
	for (int c = 0; c < 26; c++) { // loop through each letter
		if (tries[curr].nex[c] != -1) {
			cout << letters[c] << endl;
			traverse(tries[curr].nex[c]);
			if (wc == N) return;
 			cout << "-" << endl;
		}
	}
	if (tries[curr].end) {
		cout << "P" << endl;
		wc++;
	}
	return;
}
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		string str;
		cin >> str;
		int curr = 0;
		for (int j = 0; j < str.length(); j++) {
			int c = (int)str[j] - 97;
			letters[c] = str[j];
			if (tries[curr].nex[c] != -1) { // prefix recorded previously
				curr = tries[curr].nex[c];
			}
			else {
				tries[curr].nex[c] = index;
				tries[index].prev = curr;
				curr = index;
				index++;
			}
			cout << curr << endl;
		}
		tries[curr].end = true;
		cout << endl;
	}
	int curr = 0;
	traverse(curr);
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:47:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for (int j = 0; j < str.length(); j++) {
      |                   ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 54996 KB Line "2" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 54988 KB Line "2" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 55044 KB Line "2" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 54996 KB Line "2" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 54992 KB Line "2" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 55108 KB Line "2" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 124 ms 55372 KB Line "2" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 314 ms 55816 KB Line "2" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 710 ms 57168 KB Line "2" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 615 ms 56988 KB Line "2" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -