답안 #551227

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551227 2022-04-20T06:06:46 Z Pherokung Type Printer (IOI08_printer) C++14
100 / 100
117 ms 51624 KB
#include<bits/stdc++.h>
using namespace std;
#define N 25000
int n,l,sz=0,cnt=0,mx_l,st;
char s[25];
vector<char> ans;
struct node{
	int nxt[26], val, mx;
} trie[1000005];

void dfs(int pos){
	if(cnt == n) return;
	vector<pair<int,int> > v;
	if(trie[pos].val == 1 && cnt != n) ans.push_back('P'), cnt++;
	for(int i=0;i<=25;i++) if(trie[pos].nxt[i] && cnt != n) v.push_back({trie[trie[pos].nxt[i]].mx,i});
	sort(v.begin(),v.end());
	for(auto x : v) ans.push_back(x.second + 'a'), dfs(trie[pos].nxt[x.second]);
	if(cnt != n)ans.push_back('-');
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		l = strlen(s+1);
		int now = 0;
		for(int j=1;j<=l;j++){
			int idx = s[j] - 'a';
			if(!trie[now].nxt[idx]) trie[now].nxt[idx] = ++sz;
			trie[now].mx = max(trie[now].mx,l);
			now = trie[now].nxt[idx];
		}
		trie[now].val = 1;
	}
	
	dfs(0);
	
	printf("%d\n",ans.size());
	for(auto x : ans) printf("%c\n",x);
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:38:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wformat=]
   38 |  printf("%d\n",ans.size());
      |          ~^    ~~~~~~~~~~
      |           |            |
      |           int          std::vector<char>::size_type {aka long unsigned int}
      |          %ld
printer.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
printer.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |   scanf("%s",s+1);
      |   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1108 KB Output is correct
2 Correct 4 ms 1336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3284 KB Output is correct
2 Correct 15 ms 6628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 7760 KB Output is correct
2 Correct 9 ms 1928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 19120 KB Output is correct
2 Correct 103 ms 43416 KB Output is correct
3 Correct 53 ms 22576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 15024 KB Output is correct
2 Correct 117 ms 51624 KB Output is correct
3 Correct 60 ms 25528 KB Output is correct
4 Correct 108 ms 48700 KB Output is correct