Submission #920314

#TimeUsernameProblemLanguageResultExecution timeMemory
920314Alihan_8Type Printer (IOI08_printer)C++17
0 / 100
22 ms4036 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' #define int long long using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector <string> s(n); for ( auto &x: s ) cin >> x; sort(all(s)); auto f = [&](auto &u, auto &v){ int i = 0; for (; i < min((int)u.size(), (int)v.size()); i++ ){ if ( u[i] != v[i] ) break; } return i; }; vector <int> pf(n); for ( int i = 1; i < n; i++ ){ pf[i] = pf[i - 1] + f(s[i], s[i - 1]); } auto q = [&](int i){ return pf[i] + (i + 1 < n ? f(s[0], s[i + 1]) + pf[n - 1] - pf[i + 1] : 0); }; auto p = [&](int i){ return pf[n - 1] - pf[i] + (i > 0 ? f(s[n - 1], s[i - 1]) + pf[i - 1] : 0); }; int opt = 0, j = 0; for ( int i = 0; i < n; i++ ){ int t = max(q(i), p(i)); t += s[i].size(); if ( chmax(opt, t) ){ j = i; } } vector <string> a; if ( q(j) >= p(j) ){ for ( int i = j; i >= 0; i-- ){ a.pb(s[i]); } for ( int i = j + 1; i < n; i++ ){ a.pb(s[i]); } } else{ for ( int i = j; i < n; i++ ){ a.pb(s[i]); } for ( int i = j - 1; i >= 0; i-- ){ a.pb(s[i]); } } reverse(all(a)); for ( auto &x: a ) cout << x << ln; vector <char> op; for ( int i = 0; i < n; i++ ){ if ( i > 0 ){ int t = f(a[i - 1], a[i]), d = (int)a[i - 1].size() - t; while ( d-- ){ op.pb('-'); } for ( int j = t; j < a[i].size(); j++ ){ op.pb(a[i][j]); } } else{ for ( auto &x: a[i] ){ op.pb(x); } } op.pb('P'); } cout << op.size() << ln; for ( auto &x: op ){ cout << x << ln; } cout << '\n'; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:89:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |             for ( int j = t; j < a[i].size(); j++ ){
      |                              ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...