Submission #720336

# Submission time Handle Problem Language Result Execution time Memory
720336 2023-04-08T03:43:34 Z Yell0 Type Printer (IOI08_printer) C++17
0 / 100
168 ms 5120 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 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 1064 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 1240 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1740 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 2820 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 168 ms 5120 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 160 ms 4908 KB Expected EOF
2 Halted 0 ms 0 KB -