Submission #519035

#TimeUsernameProblemLanguageResultExecution timeMemory
519035AdamGSType Printer (IOI08_printer)C++17
100 / 100
65 ms7512 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=25e3+7, INF=1e9+7; string T[LIM], P[LIM]; int lcp(string a, string b) { int ans=0; while(ans<a.size() && ans<b.size() && a[ans]==b[ans]) ++ans; return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; rep(i, n) cin >> T[i]; sort(T, T+n); pair<int,int>ma={-1, -1}; rep(i, n) { pair<int,int>p={T[i].size(), i}; ma=max(ma, p); } P[0]=T[ma.nd]; int mi1=0, mi2=0, p1=ma.nd-1, p2=ma.nd+1; if(p1>=0) mi1=lcp(P[0], T[p1]); else mi1=-1; if(p2<n) mi2=lcp(P[0], T[p2]); else mi2=-1; rep(i, n-1) { if(mi1>=mi2) { P[i+1]=T[p1]; --p1; if(p1>=0) mi1=lcp(P[0], T[p1]); else mi1=-1; } else { P[i+1]=T[p2]; ++p2; if(p2<n) mi2=lcp(P[0], T[p2]); else mi2=-1; } } reverse(P, P+n); string x=""; vector<char>ans; rep(i, n) { int p=lcp(x, P[i]); while(x.size()>p) { ans.pb('-'); x.pop_back(); } while(x.size()<P[i].size()) { ans.pb(P[i][x.size()]); x+=P[i][x.size()]; } ans.pb('P'); } cout << ans.size() << '\n'; for(auto i : ans) cout << i << '\n'; }

Compilation message (stderr)

printer.cpp: In function 'int lcp(std::string, std::string)':
printer.cpp:14:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  while(ans<a.size() && ans<b.size() && a[ans]==b[ans]) ++ans;
      |        ~~~^~~~~~~~~
printer.cpp:14:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  while(ans<a.size() && ans<b.size() && a[ans]==b[ans]) ++ans;
      |                        ~~~^~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:52:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |   while(x.size()>p) {
      |         ~~~~~~~~^~
#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...