Submission #739604

# Submission time Handle Problem Language Result Execution time Memory
739604 2023-05-10T18:24:52 Z MODDI Type Printer (IOI08_printer) C++14
10 / 100
52 ms 2236 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n;
vector<string> str;
bool lower(string a, string b){
	for(int i = 0; i < a.size(); i++){
		if(a[i] < b[i])	return true;
		else if(b[i] < a[i])	return false;
	}
	return true;
}
bool comp(string& a, string& b){
	if(a.size() < b.size())	return true;
	else if(b.size() < a.size())	return false;
	else{
		return lower(a, b);
	}
}
int main(){
	cin>>n;
	str.resize(n);
	for(int i = 0; i < n; i++)
		cin>>str[i];
		
	sort(str.begin(), str.end(), comp);
	string printer;
	vector<char> moves;
	for(int i = 0; i < str.size(); i++){
		while(printer.size() > str[i].size())
		{
			moves.pb('-');
			printer.pop_back();
		}
		int first = 0;
		while(first < str[i].size() && printer[first] == str[i][first])	first++;
//		assert(false);
		while(printer.size() > first)
		{
			printer.pop_back();
			moves.pb('-');
		}
//		assert(false);
		while(printer != str[i]){
			printer.pb(str[i][first]);
			moves.pb(str[i][first]);
			first++;
		}
		moves.pb('P');
	}
	
	cout<<moves.size()<<endl;
	for(auto t : moves)
		cout<<t<<'\n';
	return 0;
}

Compilation message

printer.cpp: In function 'bool lower(std::string, std::string)':
printer.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for(int i = 0; i < a.size(); i++){
      |                 ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:35:19: 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 < str.size(); i++){
      |                 ~~^~~~~~~~~~~~
printer.cpp:42:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   while(first < str[i].size() && printer[first] == str[i][first]) first++;
      |         ~~~~~~^~~~~~~~~~~~~~~
printer.cpp:44:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |   while(printer.size() > first)
      |         ~~~~~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 2236 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 2012 KB Output isn't correct
2 Halted 0 ms 0 KB -