Submission #757772

# Submission time Handle Problem Language Result Execution time Memory
757772 2023-06-13T18:12:28 Z taher Type Printer (IOI08_printer) C++17
100 / 100
151 ms 5600 KB
#include <bits/stdc++.h>

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0 ; i < n ; i++) {
    cin >> v[i];
  }
  sort(v.begin(),v.end(),[&](string a , string b) {
    int q = (int)a.length();
    int s = (int)b.length();
    return q <  s;
  });
  auto Get = [&](string a , string b) {
    int cnt = 0;
    for (int i = 0 ; i < min((int)a.length() , (int)b.length()) ; i++) {
      if (a[i] != b[i]) break;
      else cnt++;
    }
    return cnt;
  };
  string get = v[n - 1];
  sort(v.begin(),v.end(),[&](string a , string b) {
    int _fa = Get(get , a);
    int _fb = Get(get , b);
    if (_fa == _fb) {
      return a < b;
    }
    return _fa < _fb;
  });
  //debug(v);
  vector<char> ans;
  int last = -1;
  for (int i = 0 ; i < n ; i++) {
    int nxt = -1;
    bool ok = true;
    for (int j = 0 ; j < (int)v[i].length() ; j++) {
      if (j > last) ans.emplace_back(v[i][j]);
      if (i < n - 1 && j < (int)v[i + 1].length() && v[i][j] == v[i + 1][j] && ok) {
        nxt = j;
      }
      else ok = false;
    }
    ans.emplace_back('P');
    if (i == n - 1) continue;
    for (int j = (int)v[i].length() - 1 ; j > nxt ; j--) {
      ans.emplace_back('-');
    }
    swap(last , nxt);
  }
  cout << (int)ans.size() << '\n';
  for (int i = 0 ; i < (int)ans.size() ; i++) {
    cout << ans[i] << '\n';
  }
  return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 596 KB Output is correct
2 Correct 23 ms 1036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1248 KB Output is correct
2 Correct 42 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 2352 KB Output is correct
2 Correct 138 ms 4684 KB Output is correct
3 Correct 139 ms 3744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 2208 KB Output is correct
2 Correct 151 ms 5600 KB Output is correct
3 Correct 132 ms 4184 KB Output is correct
4 Correct 144 ms 5408 KB Output is correct