답안 #53707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
53707 2018-07-01T05:15:29 Z 김세빈(#1437) Type Printer (IOI08_printer) C++11
80 / 100
69 ms 3884 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;
	int l, r;
	
	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, r = n;
	
	for(x=0;x<m;x++){
		sort(K+l, K+r, comp);
		for(j=l; j<r; j++) if(K[j] == t) break;
		for(l=j; l >= 0 && str[K[l]][x] == str[t][x]; l--); l++;
		for(r=j; r < n && str[K[r]][x] == str[t][x]; r++);
	}
	
	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:46:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   for(l=j; l >= 0 && str[K[l]][x] == str[t][x]; l--); l++;
   ^~~
printer.cpp:46:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   for(l=j; l >= 0 && str[K[l]][x] == str[t][x]; l--); l++;
                                                       ^
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]);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 288 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 560 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 612 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 612 KB Output is correct
2 Correct 2 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 612 KB Output is correct
2 Correct 3 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 672 KB Output is correct
2 Incorrect 5 ms 672 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 732 KB Output is correct
2 Correct 11 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1132 KB Output is correct
2 Correct 12 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2028 KB Output is correct
2 Correct 61 ms 3436 KB Output is correct
3 Incorrect 39 ms 3436 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 3436 KB Output is correct
2 Correct 63 ms 3884 KB Output is correct
3 Correct 42 ms 3884 KB Output is correct
4 Correct 69 ms 3884 KB Output is correct