답안 #1026246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026246 2024-07-17T18:25:59 Z fv3 Type Printer (IOI08_printer) C++14
20 / 100
1000 ms 1884 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll INF = 1ll << 60ll;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int N;
	cin >> N;

	vector<string> words(N);

	for (int i = 0; i < N; i++)
		cin >> words[i];

	vector<string> bestPerm = words;
	ll best = INF;

	do
	{
		ll cnt = 0;
		string lastWord = "";

		for (auto w : words)
		{
			int i = 0;
			for (; i < min(lastWord.size(), w.size()); i++)
			{
				if (w[i] != lastWord[i])
				{
					break;
				}
			}

			for (int j = 0; j < lastWord.size() - i; j++)
				cnt++;

			for (; i < w.size(); i++)
			{
				cnt++;
			}
			cnt++;

			lastWord = w;
		}

		if (cnt < best)
		{
			best = cnt;
			bestPerm = words;
		}
	}
	while (next_permutation(words.begin(), words.end()));

	cout << best << '\n';

	string lastWord = "";
	for (auto w : bestPerm)
	{
		int i = 0;
		for (; i < min(lastWord.size(), w.size()); i++)
		{
			if (w[i] != lastWord[i])
			{
				break;
			}
		}

		for (int j = 0; j < lastWord.size() - i; j++)
			cout << "-\n";

		for (; i < w.size(); i++)
		{
			cout << w[i] << '\n';
		}
		cout << "P\n";

		lastWord = w;
	}

	return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:31:13: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   31 |    for (; i < min(lastWord.size(), w.size()); i++)
      |           ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |    for (int j = 0; j < lastWord.size() - i; j++)
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
printer.cpp:42:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |    for (; i < w.size(); i++)
      |           ~~^~~~~~~~~~
printer.cpp:65:12: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   65 |   for (; i < min(lastWord.size(), w.size()); i++)
      |          ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for (int j = 0; j < lastWord.size() - i; j++)
      |                   ~~^~~~~~~~~~~~~~~~~~~~~
printer.cpp:76:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for (; i < w.size(); i++)
      |          ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 51 ms 424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1038 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1070 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1046 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1051 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1053 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1059 ms 860 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1068 ms 1884 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1046 ms 1880 KB Time limit exceeded
2 Halted 0 ms 0 KB -