답안 #121448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121448 2019-06-26T14:16:56 Z TadijaSebez Type Printer (IOI08_printer) C++11
100 / 100
64 ms 4332 KB
#include <stdio.h>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define pb push_back
const int N=25050;
char s[N][21];
int len[N],heavy;
bool comp(int a, int b)
{
	int i;
	for(i=0;i<20;i++) if(s[a][i]!=s[b][i]) break;
	if(s[a][i]==s[heavy][i]) return 0;
	if(s[b][i]==s[heavy][i]) return 1;
	return s[a][i]<s[b][i];
}
int id[N];
vector<char> sol;
int main()
{
	int n,i;
	scanf("%i",&n);
	for(i=1;i<=n;i++)
	{
		id[i]=i;
		scanf("%s",s[i]);
		len[i]=strlen(s[i]);
		if(len[heavy]<len[i]) heavy=i;
	}
	sort(id+1,id+1+n,comp);
	int j,k=-1;
	for(i=1;i<=n;i++)
	{
		if(i>1)
		{
			k=len[id[i-1]];
			for(j=0;j<len[id[i-1]];j++){ if(s[id[i]][j]!=s[id[i-1]][j]) break;k--;}
			for(j=0;j<k;j++) sol.pb('-');
			k=len[id[i-1]]-k-1;
		}
		for(j=k+1;j<len[id[i]];j++) sol.pb(s[id[i]][j]);
		sol.pb('P');
	}
	printf("%i\n",sol.size());
	for(i=0;i<sol.size();i++) printf("%c\n",sol[i]);
	return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:45:26: warning: format '%i' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%i\n",sol.size());
                ~~~~~~~~~~^
printer.cpp:46:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<sol.size();i++) printf("%c\n",sol[i]);
          ~^~~~~~~~~~~
printer.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
printer.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",s[i]);
   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 356 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 640 KB Output is correct
2 Correct 9 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1148 KB Output is correct
2 Correct 9 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 2128 KB Output is correct
2 Correct 47 ms 3816 KB Output is correct
3 Correct 33 ms 2676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2160 KB Output is correct
2 Correct 64 ms 4332 KB Output is correct
3 Correct 36 ms 3056 KB Output is correct
4 Correct 51 ms 4176 KB Output is correct