Submission #507390

# Submission time Handle Problem Language Result Execution time Memory
507390 2022-01-12T11:42:25 Z haxorman Type Printer (IOI08_printer) C++14
40 / 100
22 ms 3312 KB
#include <bits/stdc++.h>
using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin >> n;

	vector<string> words(n);
	for (auto& w : words) {
		cin >> w;
	}
	sort(words.begin(), words.end());

	int mx = 0;
	char c;
	for (int i = 0; i < n; ++i) {
		if (mx < words[i].size()) {
			mx = words[i].size();
			c = words[i][0];
		}
	}
	
	vector<string> big, smol;
	for (int i = 0; i < n; ++i) {
		if (words[i][0] == c) {
			big.push_back(words[i]);
		}
		else {
			smol.push_back(words[i]);
		}
	}
	
	for (int i = 0; i < big.size(); ++i) {
		if (big[i].size() == mx) {
			big.push_back(big[i]);
			big.erase(big.begin() + i);
		}
	}
	
	string cur = "0";
	vector<char> out;
	if (smol.size()) {
		cur = smol[0];
		for (auto ch : cur) {
			out.push_back(ch);
		}
		out.push_back('P');

		for (int i = 1; i < smol.size(); ++i) {
			int ind = 0;
			while (ind < min(cur.size(), smol[i].size()) && 
				  cur[ind] == smol[i][ind]) {
				
				ind++;
			}
			ind--;

			int cur_ind = cur.size() - 1;
			while (cur_ind > ind) {
				out.push_back('-');
				cur_ind--;
			}

			for (int j = ind + 1; j < smol[i].size(); ++j) {
				out.push_back(smol[i][j]);
			}
			out.push_back('P');

			cur = smol[i];
		}
	}
	
	int start = 0;
	if (cur[0] == '0') {
		cur = big[0];
		for (auto ch : cur) {
			out.push_back(ch);
		}
		out.push_back('P');
		start = 1;
	}
	
	for (int i = start; i < big.size(); ++i) {
		int ind = 0;
		while (ind < min(cur.size(), big[i].size()) && 
			  cur[ind] == big[i][ind]) {
			
			ind++;
		}
		ind--;

		int cur_ind = cur.size() - 1;
		while (cur_ind > ind) {
			out.push_back('-');
			cur_ind--;
		}

		for (int j = ind + 1; j < big[i].size(); ++j) {
			out.push_back(big[i][j]);
		}
		out.push_back('P');

		cur = big[i];
	}

	cout << out.size() << "\n";
	for (auto ch : out) {
		cout << ch << "\n";
	}
}

Compilation message

printer.cpp: In function 'int32_t main()':
printer.cpp:19:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |   if (mx < words[i].size()) {
      |       ~~~^~~~~~~~~~~~~~~~~
printer.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for (int i = 0; i < big.size(); ++i) {
      |                  ~~^~~~~~~~~~~~
printer.cpp:36:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |   if (big[i].size() == mx) {
      |       ~~~~~~~~~~~~~~^~~~~
printer.cpp:51:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for (int i = 1; i < smol.size(); ++i) {
      |                   ~~^~~~~~~~~~~~~
printer.cpp:53:15: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   53 |    while (ind < min(cur.size(), smol[i].size()) &&
      |           ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:66:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |    for (int j = ind + 1; j < smol[i].size(); ++j) {
      |                          ~~^~~~~~~~~~~~~~~~
printer.cpp:85:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |  for (int i = start; i < big.size(); ++i) {
      |                      ~~^~~~~~~~~~~~
printer.cpp:87:14: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   87 |   while (ind < min(cur.size(), big[i].size()) &&
      |          ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:100:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |   for (int j = ind + 1; j < big[i].size(); ++j) {
      |                         ~~^~~~~~~~~~~~~~~
printer.cpp:27:3: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |   if (words[i][0] == c) {
      |   ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 316 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 716 KB Output is correct
2 Incorrect 10 ms 1224 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 3312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 3268 KB Output isn't correct
2 Halted 0 ms 0 KB -