Submission #377131

#TimeUsernameProblemLanguageResultExecution timeMemory
377131kevinxiehkType Printer (IOI08_printer)C++17
100 / 100
120 ms5604 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define fi first #define se second #define ick cout<<"ickbmi32.9\n" using namespace std; string arr[25005]; int n; bool cmp(string a,string b){ for(int i=0;i<min(a.length(),b.length());i++){ if(a[i]==b[i])continue; if(a[i]==arr[n-1][i])return false; if(b[i]==arr[n-1][i])return true; return a[i]<b[i]; } return a.length()<b.length(); } bool cmp2(string a,string b){ return a.length()<b.length(); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>n; for(int i=0;i<n;i++)cin>>arr[i]; sort(arr,arr+n,cmp2); sort(arr,arr+n-1,cmp); vector<char>ans; for(int i=0;i<arr[0].length();i++)ans.pb(arr[0][i]); ans.pb('P'); for(int i=1;i<n;i++){ int p=0; while(p<min(arr[i].length(),arr[i-1].length())&&arr[i][p]==arr[i-1][p])p++; for(int j=0;j<arr[i-1].length()-p;j++)ans.pb('-'); for(;p<arr[i].length();p++)ans.pb(arr[i][p]); ans.pb('P'); } cout<<ans.size()<<'\n'; for(auto&x:ans)cout<<x<<'\n'; //for(int i=0;i<n;i++)cout<<arr[i]<<'\n'; return 0; }

Compilation message (stderr)

printer.cpp: In function 'bool cmp(std::string, std::string)':
printer.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   11 |     for(int i=0;i<min(a.length(),b.length());i++){
      |                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=0;i<arr[0].length();i++)ans.pb(arr[0][i]);
      |                 ~^~~~~~~~~~~~~~~~
printer.cpp:34:16: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   34 |         while(p<min(arr[i].length(),arr[i-1].length())&&arr[i][p]==arr[i-1][p])p++;
      |               ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int j=0;j<arr[i-1].length()-p;j++)ans.pb('-');
      |                     ~^~~~~~~~~~~~~~~~~~~~
printer.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(;p<arr[i].length();p++)ans.pb(arr[i][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...