Submission #572155

# Submission time Handle Problem Language Result Execution time Memory
572155 2022-06-03T19:52:33 Z Hanksburger Type Printer (IOI08_printer) C++17
100 / 100
52 ms 7524 KB
#include <bits/stdc++.h>
using namespace std;
string a[25005], b[25005];
vector<char> ans;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, l, r, cur, maxi=0;
	cin >> n;
	for (int i=1; i<=n; i++)
		cin >> a[i];
	sort(a+1, a+n+1);
	for (int i=1; i<=n; i++)
	{
		if (maxi<a[i].length())
		{
			maxi=a[i].length();
			l=r=cur=i;
			b[n]=a[i];
		}
	}
	while (l!=1 || r!=n)
	{
		int index=0, jndex=0;
		if (l!=1)
		{
			for (int i=0; i<min(a[l-1].length(), a[cur].length()); i++)
			{
				if (a[l-1][i]!=a[cur][i])
					break;
				index++;
			}
		}
		if (r!=n)
		{
			for (int i=0; i<min(a[cur].length(), a[r+1].length()); i++)
			{
				if (a[cur][i]!=a[r+1][i])
					break;
				jndex++;
			}
		}
		if (l!=1 && index>=jndex)
		{
			l--;
			b[n+l-r]=a[l];
		}
		else
		{
			r++;
			b[n+l-r]=a[r];
		}
	}
	for (int i=0; i<b[1].length(); i++)
		ans.push_back(b[1][i]);
	ans.push_back('P');
	for (int i=2; i<=n; i++)
	{
		int index=0;
		for (int j=0; j<min(b[i-1].length(), b[i].length()); j++)
		{
			if (b[i-1][j]!=b[i][j])
				break;
			index++;
		}
		for (int j=1; j<=b[i-1].length()-index; j++)
			ans.push_back('-');
		for (int j=index; j<b[i].length(); j++)
			ans.push_back(b[i][j]);
		ans.push_back('P');
	}
	cout << ans.size() << '\n';
	for (int i=0; i<ans.size(); i++)
		cout << ans[i] << '\n';
	return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:17:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   if (maxi<a[i].length())
      |       ~~~~^~~~~~~~~~~~~~
printer.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   29 |    for (int i=0; i<min(a[l-1].length(), a[cur].length()); i++)
      |                  ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   38 |    for (int i=0; i<min(a[cur].length(), a[r+1].length()); i++)
      |                  ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:56:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for (int i=0; i<b[1].length(); i++)
      |                ~^~~~~~~~~~~~~~
printer.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   62 |   for (int j=0; j<min(b[i-1].length(), b[i].length()); j++)
      |                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for (int j=1; j<=b[i-1].length()-index; j++)
      |                 ~^~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   for (int j=index; j<b[i].length(); j++)
      |                     ~^~~~~~~~~~~~~~
printer.cpp:75:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |  for (int i=0; i<ans.size(); i++)
      |                ~^~~~~~~~~~~
printer.cpp:38:44: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |    for (int i=0; i<min(a[cur].length(), a[r+1].length()); i++)
      |                                           ~^~
printer.cpp:29:27: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |    for (int i=0; i<min(a[l-1].length(), a[cur].length()); i++)
      |                          ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 2 ms 1888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1888 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1800 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1876 KB Output is correct
2 Correct 2 ms 2004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2132 KB Output is correct
2 Correct 11 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2540 KB Output is correct
2 Correct 7 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 3676 KB Output is correct
2 Correct 45 ms 6676 KB Output is correct
3 Correct 29 ms 5572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 3036 KB Output is correct
2 Correct 52 ms 7524 KB Output is correct
3 Correct 32 ms 6112 KB Output is correct
4 Correct 52 ms 7320 KB Output is correct