답안 #303723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
303723 2020-09-20T15:12:32 Z FlashGamezzz Type Printer (IOI08_printer) C++17
80 / 100
1000 ms 134564 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <queue>

using namespace std;

vector< vector<long> > lets;
vector< vector<int> > has;
vector<bool> endb;
vector<int> length;
vector<char> ans;

void add(long c, int i, string s){
	if (i == s.length()){
		endb[c] = true; length[c] = max(0, length[c]);
		return;
	}
	int l = int(s[i])-97;
	if (lets[c][l] == 0){
		vector<long> t; for (int j = 0; j < 26; j++) t.push_back(0);
		lets.push_back(t); endb.push_back(false); length.push_back(-100);
		has.push_back(vector<int>()); has[c].push_back(l);
		lets[c][l] = lets.size()-1;
	}
	add(lets[c][l], i+1, s);
	length[c] = max(length[lets[c][l]]+1, length[c]);
}

void solve(long c){
	if (endb[c]){
		ans.push_back('P');
	}
	vector< pair<int, int> > ls;
	for (int a : has[c]){
		ls.push_back(make_pair(length[lets[c][a]], a));
	}
	sort(ls.begin(), ls.end());
	for (pair<int, int> a : ls){
		ans.push_back(char(a.second+97));
		solve(lets[c][a.second]);
		ans.push_back('-');
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	vector<long> t;
	for (int j = 0; j < 26; j++) t.push_back(0);
	lets.push_back(t); endb.push_back(false); length.push_back(-100);
	for (int i = 0; i < n; i++){
		string s; cin >> s;
		add(0, 0, s);
	}
	solve(0);
	long count = ans.size();
	while (ans[count-1] == '-'){
		count--;
	}
	cout << count << endl;
	for (int i = 0; i < count; i++){
		cout << ans[i] << endl;
	}
}

Compilation message

printer.cpp: In function 'void add(long int, int, std::string)':
printer.cpp:20:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  if (i == s.length()){
      |      ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 21 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 2432 KB Output is correct
2 Correct 49 ms 3004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 8084 KB Output is correct
2 Correct 307 ms 16844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 363 ms 19864 KB Output is correct
2 Correct 100 ms 4336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 914 ms 49724 KB Output is correct
2 Execution timed out 1097 ms 113412 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 754 ms 38744 KB Output is correct
2 Execution timed out 1100 ms 134564 KB Time limit exceeded
3 Halted 0 ms 0 KB -