Submission #53708

# Submission time Handle Problem Language Result Execution time Memory
53708 2018-07-01T05:24:01 Z 김세빈(#1437) Type Printer (IOI08_printer) C++11
100 / 100
65 ms 3868 KB
#include <bits/stdc++.h>

using namespace std;

char V[1010101], s[22], str[30303][22];
int K[30303];
int n, p, ans, x, t, m;

bool comp(int ca, int cb)
{
	int i;
	
	for(i=0;i<m && str[ca][i] && str[cb][i];i++){
		if(str[ca][i] != str[cb][i]){
			if(i == x){
				if(str[ca][i] == str[t][i]) return 0;
				if(str[cb][i] == str[t][i]) return 1;
			}
			return str[ca][i] < str[cb][i];
		}
	}
	
	if(!str[ca][i]) return 1;
	
	return 0;
}

int main()
{
	int i, j, k, l;
	
	scanf("%d", &n);
	
	for(i=0;i<n;i++){
		scanf("%s",str[i]);
		k = strlen(str[i]);
		if(k > m) m = k, t = i;
		K[i] = i;
	}
	
	l = 0;
	
	for(x=0;x<m;x++){
		sort(K+l, K+n, comp);
		for(; l<n && str[K[l]][x] != str[t][x]; l++);
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<p && str[K[i]][j];j++) if(s[j] != str[K[i]][j]) break;
		for(;j<p;p--) V[ans++] = '-';
		for(;str[K[i]][j];j++) s[p++] = V[ans++] = str[K[i]][j];
		V[ans++] = 'P';
	}
	
	printf("%d\n", ans);
	
	for(i=0;i<ans;i++) printf("%c\n", V[i]);
	
	return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
printer.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",str[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 564 KB Output is correct
2 Correct 2 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 564 KB Output is correct
2 Correct 2 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 580 KB Output is correct
2 Correct 2 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 620 KB Output is correct
2 Correct 5 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 780 KB Output is correct
2 Correct 11 ms 1096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1292 KB Output is correct
2 Correct 11 ms 1292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2076 KB Output is correct
2 Correct 60 ms 3356 KB Output is correct
3 Correct 38 ms 3356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 3356 KB Output is correct
2 Correct 65 ms 3868 KB Output is correct
3 Correct 43 ms 3868 KB Output is correct
4 Correct 57 ms 3868 KB Output is correct