Submission #720338

# Submission time Handle Problem Language Result Execution time Memory
720338 2023-04-08T03:47:56 Z Yell0 Type Printer (IOI08_printer) C++11
0 / 100
167 ms 4908 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MN=25002;
int N,ans=0;
string w[MN];
stringstream ss;
map<string,int> wpos;

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  cin>>N;
  for(int i=1;i<=N;++i) cin>>w[i];
  sort(w+1,w+1+N);
  int mx=0,mxi=0;
  for(int i=1;i<=N;++i) {
    wpos[w[i]]=i;
    if((int)w[i].size()>mx) {
      mx=w[i].size();
      mxi=i;
    }
  }
  int endp=N;
  for(int i=1;i<=(int)w[mxi].size();++i)
    for(int j=1;j<=N;++j) {
      if((int)w[j].size()<i) continue;
      if(w[j].substr(0,i)==w[mxi].substr(0,i)) wpos[w[j]]=++endp;
    }
  sort(w+1,w+1+N,[](string a,string b) {return wpos[a]<wpos[b];});
  string ct="";
  for(int i=1;i<=N;++i) {
    string cw=w[i];
    while(ct.size()>cw.size()) {
      ct.pop_back();
      ++ans;
      ss<<"-\n";
    }
    while(ct.size()<cw.size()) cw.pop_back();
    while(ct!=cw) {
      ct.pop_back();
      cw.pop_back();
      ++ans;
      ss<<"-\n";
    }
    while(ct.size()<w[i].size()) {
      ++ans;
      ss<<w[i][ct.size()]<<'\n';
      ct.push_back(w[i][ct.size()]);
    }
    ++ans;
    ss<<"P\n";
  }
  cout<<ans<<'\n'<<ss.str()<<'\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 980 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1108 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1108 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1108 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1108 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1236 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 1620 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 2732 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 167 ms 4908 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 4700 KB Expected EOF
2 Halted 0 ms 0 KB -