Submission #489758

# Submission time Handle Problem Language Result Execution time Memory
489758 2021-11-24T12:22:11 Z HappyPacMan Type Printer (IOI08_printer) C++14
20 / 100
60 ms 36576 KB
#include<bits/stdc++.h>

using namespace std;

struct Node{
  Node *nxt[26];
  int dep;
  Node(){
    for(int i=0;i<26;i++) nxt[i] = NULL;
    dep = 0;
  }
};
void Insert(Node *root,string str){
  if(str.empty()) return;
  char c = str.back();
  if(root->nxt[c-'a'] == NULL) root->nxt[str.back()-'a'] = new Node;
  str.pop_back();
  Insert(root->nxt[c-'a'],str);
  root->dep = max(root->dep,root->nxt[c-'a']->dep+1);
}
vector<char> res;
void Run(Node *root){
  if(root->dep == 0){
    res.push_back('P');
    return;
  }
  
  for(int i=0;i<26;i++){
    if(root->nxt[i] != NULL && root->nxt[i]->dep != root->dep-1){
      res.push_back(i+'a');
      Run(root->nxt[i]);
      res.push_back('-');
    }
  }
  for(int i=0;i<26;i++){
    if(root->nxt[i] != NULL && root->nxt[i]->dep == root->dep-1){
      res.push_back(i+'a');
      Run(root->nxt[i]);
      res.push_back('-');
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  
  int N;
  cin >> N;
  Node *root = new Node();
  for(int i=0;i<N;i++){
    string str;
    cin >> str;
    reverse(str.begin(),str.end());
    Insert(root,str);
  }
  Run(root);
  while(res.back() == '-') res.pop_back();
  cout << res.size() << '\n';
  for(char c : res) cout << c << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 0 ms 204 KB didn't print every word
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1740 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 5920 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 14744 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 36576 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 28792 KB didn't print every word
2 Halted 0 ms 0 KB -