Submission #318440

# Submission time Handle Problem Language Result Execution time Memory
318440 2020-11-01T21:54:59 Z shrek12357 Type Printer (IOI08_printer) C++14
0 / 100
913 ms 26328 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0); 

const int MAXN = 25000 * 20 + 3;

int counter = 1;

vector<int> adjList[MAXN];
map<int, int> cc;
vector<char> ans;
int depth[MAXN];

bool comp(int a, int b) {
	return depth[a] < depth[b];
}

void init(string word, int src, int pos) {
	if (pos >= word.size()) {
		return;
	}
	int idx = -1;
	for (auto i : adjList[src]) {
		if (cc[i] == word[pos]) {
			idx = i;
			break;
		}
	}
	int nxt = -1;
	if (idx == -1) {
		adjList[src].push_back(counter);
		cc[counter] = word[pos];
		nxt = counter;
		counter++;
	}
	else {
		nxt = idx;
	}
	init(word, nxt, pos + 1);
	depth[src] = max(depth[src], depth[nxt] + 1);
}

void dfs(int src) {
	if (adjList[src].size() == 0) {
		ans.push_back('P');
	}
	sort(adjList[src].begin(), adjList[src].end(), comp);
	for (auto i : adjList[src]) {
		ans.push_back(cc[i]);
		dfs(i);
	}
	if(src != 0)
		ans.push_back('-');
}

int main() {
	int n;
	cin >> n;
	vector<string> words;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		init(s, 0, 0);
	}
	dfs(0);
	while (ans[ans.size() - 1] == '-') {
		ans.pop_back();
	}
	cout << ans.size() << endl;
	for (auto i : ans) {
		cout << i << endl;
	}
	cout << "P" << endl;
}

Compilation message

printer.cpp: In function 'void init(std::string, int, int)':
printer.cpp:31:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  if (pos >= word.size()) {
      |      ~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12012 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 12140 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 12140 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 12140 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 12140 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 12780 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 144 ms 14308 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 357 ms 17824 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 913 ms 26328 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 787 ms 23136 KB Expected EOF
2 Halted 0 ms 0 KB -