Submission #245830

# Submission time Handle Problem Language Result Execution time Memory
245830 2020-07-07T14:35:12 Z kevlee Type Printer (IOI08_printer) C++17
100 / 100
89 ms 6256 KB
#include <bits/stdc++.h>
using namespace std;
char s[25005][27];
int n, maxi, maxx;
pair<pair<int, string>, int>p[25005];
int main () {
	scanf("%d", &n);
	for (int i=0; i<n; i++) {
		scanf("%s", s[i]);
		int len=strlen(s[i]);
		if (len>maxx) {
			maxx=len;
			maxi=i;
		}
	}
	for (int i=0; i<n; i++) {
		int cnt=0;
		for (int j=0; j<maxx; j++) {
			if (s[i][j]!=s[maxi][j]) break;
			cnt++;
		}
		string tmp=s[i];
		p[i]={{cnt, tmp}, i};
	}
	sort(p, p+n);
	string prev="";
	vector<char>v;
	for (int i=0; i<n; i++) {
		int cnt=0;
		string cur=p[i].first.second;
		for (int j=0; j<prev.size(); j++) {
			if (prev[j]!=cur[j]) break;
			cnt++;
		}
		for (int j=0; j<prev.size()-cnt; j++) v.push_back('-');
		for (int j=cnt; j<cur.size(); j++) v.push_back(cur[j]);
		v.push_back('P');
		prev=cur;
	}
	printf("%d\n", v.size());
	for (int i=0; i<v.size(); i++) printf("%c\n", v[i]);
	return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0; j<prev.size(); j++) {
                 ~^~~~~~~~~~~~
printer.cpp:35:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0; j<prev.size()-cnt; j++) v.push_back('-');
                 ~^~~~~~~~~~~~~~~~
printer.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=cnt; j<cur.size(); j++) v.push_back(cur[j]);
                   ~^~~~~~~~~~~
printer.cpp:40:25: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", v.size());
                 ~~~~~~~~^
printer.cpp:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0; i<v.size(); i++) printf("%c\n", v[i]);
                ~^~~~~~~~~
printer.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
printer.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", s[i]);
   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1536 KB Output is correct
2 Correct 5 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1536 KB Output is correct
2 Correct 5 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1536 KB Output is correct
2 Correct 5 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1536 KB Output is correct
2 Correct 5 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1536 KB Output is correct
2 Correct 6 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1664 KB Output is correct
2 Correct 7 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1920 KB Output is correct
2 Correct 19 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2428 KB Output is correct
2 Correct 17 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 3440 KB Output is correct
2 Correct 82 ms 5608 KB Output is correct
3 Correct 48 ms 4464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 3312 KB Output is correct
2 Correct 89 ms 6256 KB Output is correct
3 Correct 54 ms 4728 KB Output is correct
4 Correct 78 ms 6128 KB Output is correct