Submission #956773

# Submission time Handle Problem Language Result Execution time Memory
956773 2024-04-02T12:56:44 Z DeltaStruct Type Printer (IOI08_printer) C++17
30 / 100
841 ms 5684 KB
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n; cin >> n; vector<string> A(n); for (auto& a:A) cin >> a;
  sort(A.begin(),A.end()); string s,r; int mx = numeric_limits<int>::max();
  for (int m(0);m < n;++m){
    //int m = lower_bound(A.begin(),A.end(),to_string(x))-A.begin();
    if (m) while(A[m-1][0]==A[m][0]){ ++m; if (m==n) break; }
    if (m==n) continue;
    for (int i(m);i < n;++i){
      int t(0);
      if (i!=m) for (int k(0);;++k,++t) if (A[i-1].size()==k||A[i].size()==k||A[i-1][k]!=A[i][k]) break;
      if (i!=m) for (int k(t);k < A[i-1].size();++k) s += '-';
      for (int k(t);k < A[i].size();++k) s += A[i][k];
      s += 'P';
    }
    for (int i(0);i < m;++i){
      int t(0);
      if (m!=n) for (int k(0);;++k,++t) if (A[(i?i:n)-1].size()==k||A[i].size()==k||A[(i?i:n)-1][k]!=A[i][k]) break;
      if (n!=m) for (int k(t);k < A[(i?i:n)-1].size();++k) s += '-';
      for (int k(t);k < A[i].size();++k) s += A[i][k];
      s += 'P';
    }
    if (mx>s.size()) mx = s.size(),r = s;
    s = "";
  }
  cout << mx << endl; for (char a:r) cout << a << endl;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:13:58: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   13 |       if (i!=m) for (int k(0);;++k,++t) if (A[i-1].size()==k||A[i].size()==k||A[i-1][k]!=A[i][k]) break;
      |                                             ~~~~~~~~~~~~~^~~
printer.cpp:13:74: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   13 |       if (i!=m) for (int k(0);;++k,++t) if (A[i-1].size()==k||A[i].size()==k||A[i-1][k]!=A[i][k]) break;
      |                                                               ~~~~~~~~~~~^~~
printer.cpp:14:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |       if (i!=m) for (int k(t);k < A[i-1].size();++k) s += '-';
      |                               ~~^~~~~~~~~~~~~~~
printer.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |       for (int k(t);k < A[i].size();++k) s += A[i][k];
      |                     ~~^~~~~~~~~~~~~
printer.cpp:20:64: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |       if (m!=n) for (int k(0);;++k,++t) if (A[(i?i:n)-1].size()==k||A[i].size()==k||A[(i?i:n)-1][k]!=A[i][k]) break;
      |                                             ~~~~~~~~~~~~~~~~~~~^~~
printer.cpp:20:80: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |       if (m!=n) for (int k(0);;++k,++t) if (A[(i?i:n)-1].size()==k||A[i].size()==k||A[(i?i:n)-1][k]!=A[i][k]) break;
      |                                                                     ~~~~~~~~~~~^~~
printer.cpp:21:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |       if (n!=m) for (int k(t);k < A[(i?i:n)-1].size();++k) s += '-';
      |                               ~~^~~~~~~~~~~~~~~~~~~~~
printer.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |       for (int k(t);k < A[i].size();++k) s += A[i][k];
      |                     ~~^~~~~~~~~~~~~
printer.cpp:25:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     if (mx>s.size()) mx = s.size(),r = s;
      |         ~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 604 KB Output is correct
2 Incorrect 132 ms 1192 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 159 ms 1288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 394 ms 2796 KB Output is correct
2 Correct 841 ms 5684 KB Output is correct
3 Incorrect 462 ms 4432 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 332 ms 2608 KB Output isn't correct
2 Halted 0 ms 0 KB -