답안 #396704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
396704 2021-04-30T15:47:33 Z peuch Type Printer (IOI08_printer) C++17
100 / 100
193 ms 87028 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 25000;

int n;
vector<int> ar[MAXN * 26];

int marc[MAXN * 26];
int letras[MAXN * 26][30];
char v[MAXN * 26];

int cnt = 0;

vector<string> palavras;
vector<char> ans;

void dfs(int cur, int pai, int prof){
	if(marc[cur]) ans.push_back('P');
	bool flag = false;
	for(int i = 0; i < ar[cur].size(); i++){
		int viz = ar[cur][i];
		if(viz == pai) continue;
		if(v[viz] == palavras[n - 1][prof]) continue;
		ans.push_back(v[viz]);
		dfs(viz, cur, prof + 1);
		ans.push_back('-');
	}
	for(int i = 0; i < ar[cur].size(); i++){
		int viz = ar[cur][i];
		if(viz == pai) continue;
		if(v[viz] != palavras[n - 1][prof]) continue;
		ans.push_back(v[viz]);
		dfs(viz, cur, prof + 1);
		ans.push_back('-');
	}
}

bool cmp(string a, string b){
	return a.size() < b.size();
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		string aux;
		cin >> aux;
		palavras.push_back(aux);
	}	
	sort(palavras.begin(), palavras.end(), cmp);
	for(int i = 0; i < n; i++){
		int cur = 0;
		for(int j = 0; j < palavras[i].size(); j++){
			if(letras[cur][palavras[i][j] - 'a'] == 0) {
				letras[cur][palavras[i][j] - 'a'] = ++cnt;
				ar[cur].push_back(cnt);
				v[cnt] = palavras[i][j];
			}
			cur = letras[cur][palavras[i][j] - 'a'];
		}
		marc[cur] = 1;
	}
	dfs(0, 0, 0);
	while(ans[ans.size() - 1] == '-') ans.pop_back();
	printf("%d\n", ans.size());
	for(int i = 0; i < ans.size(); i++)
		printf("%c\n", ans[i]);
}

Compilation message

printer.cpp: In function 'void dfs(int, int, int)':
printer.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for(int i = 0; i < ar[cur].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~
printer.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for(int i = 0; i < ar[cur].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~
printer.cpp:20:7: warning: unused variable 'flag' [-Wunused-variable]
   20 |  bool flag = false;
      |       ^~~~
printer.cpp: In function 'int main()':
printer.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int j = 0; j < palavras[i].size(); j++){
      |                  ~~^~~~~~~~~~~~~~~~~~~~
printer.cpp:65:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wformat=]
   65 |  printf("%d\n", ans.size());
      |          ~^     ~~~~~~~~~~
      |           |             |
      |           int           std::vector<char>::size_type {aka long unsigned int}
      |          %ld
printer.cpp:66:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  for(int i = 0; i < ans.size(); i++)
      |                 ~~^~~~~~~~~~~~
printer.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   44 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15564 KB Output is correct
2 Correct 9 ms 15564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15564 KB Output is correct
2 Correct 10 ms 15560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15552 KB Output is correct
2 Correct 9 ms 15564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15564 KB Output is correct
2 Correct 10 ms 15564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15676 KB Output is correct
2 Correct 11 ms 16084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 16588 KB Output is correct
2 Correct 13 ms 16972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 19624 KB Output is correct
2 Correct 32 ms 24312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 25916 KB Output is correct
2 Correct 29 ms 18144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 41856 KB Output is correct
2 Correct 170 ms 75560 KB Output is correct
3 Correct 106 ms 46264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 36040 KB Output is correct
2 Correct 193 ms 87028 KB Output is correct
3 Correct 120 ms 50336 KB Output is correct
4 Correct 188 ms 83000 KB Output is correct