Submission #720337

# Submission time Handle Problem Language Result Execution time Memory
720337 2023-04-08T03:45:30 Z Yell0 Type Printer (IOI08_printer) C++17
0 / 100
165 ms 4928 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()<<endl;
  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 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 4 ms 1236 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1644 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 2744 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 158 ms 4928 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 165 ms 4700 KB Expected EOF
2 Halted 0 ms 0 KB -