Submission #997454

#TimeUsernameProblemLanguageResultExecution timeMemory
997454hasan2006Type Printer (IOI08_printer)C++17
100 / 100
68 ms5584 KiB
#include <bits/stdc++.h> using namespace std; #define all(s) s.begin(),s.end() #define pb push_back #define ll long long vector<string>v; deque<char>d; vector<char>ans; string a; bool cmp(string b , string c){ int i = 0; for(i = 0; i < min(b.size() , c.size()); i++){ if(b[i] == c[i] && (b[i] == a[i])) continue; if(b[i] == a[i]) return 0; if(c[i] == a[i]) return 1; return b < c; } return (b.size() < c.size()); } void solve() { ll n , i , l , mx = 0; cin>>n; v.resize(n); for(i = 0; i < n; i++){ cin>>v[i]; if(v[i].size() > mx) mx = v[i].size() , a = v[i]; } sort(all(v) , cmp); for(auto to : v){ l = 0; for(i = 0; i < min(to.size(), d.size()); i++){ if(d[i] != to[i]) break; l++; } while(d.size() > l) ans.pb('-') , d.pop_back(); while(l < to.size()) ans.pb(to[l]) ,d.pb(to[l]) , l++; ans.pb('P'); } cout<<ans.size()<<"\n"; for(auto to : ans) cout<<char(to)<<"\n"; } int main(){ solve(); } // Author : حسن

Compilation message (stderr)

printer.cpp: In function 'bool cmp(std::string, std::string)':
printer.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   15 |     for(i = 0; i < min(b.size() , c.size()); i++){
      |                ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'void solve()':
printer.cpp:34:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   34 |         if(v[i].size() > mx)
      |            ~~~~~~~~~~~~^~~~
printer.cpp:40:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'const long unsigned int' [-Wsign-compare]
   40 |         for(i  = 0; i < min(to.size(), d.size()); i++){
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:45:24: warning: comparison of integer expressions of different signedness: 'std::deque<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   45 |         while(d.size() > l)
      |               ~~~~~~~~~^~~
printer.cpp:47:17: 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]
   47 |         while(l < to.size())
      |               ~~^~~~~~~~~~~
#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...