Submission #314321

# Submission time Handle Problem Language Result Execution time Memory
314321 2020-10-19T17:11:49 Z ShiftyBlock Type Printer (IOI08_printer) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pii pair<int, int>
#define long long long
#define v vector
#define rep(i,a,b) for(int i=a; i<b; i++)
void setIO(string name, int submit) {
    if (submit) {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        freopen((name + ".in").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
    else{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
    }
    
}
string longest;
bool compare(string a, string b){
	int samea=0; int sameb=0;
    rep(j,0, a.size()){
   		if(longest[j]==a[j]) samea++;
 	 	else break;
    }
    rep(j,0, b.size()){
   		if(longest[j]==b[j]) sameb++;
 	 	else break;
    }
    if(samea==sameb){
    	int cmp= a.compare(b);
    	if(cmp<0) return true;
    	else return false;
    }
    return samea<sameb;

}

int main() {
    setIO("printer", 0);

    int N;
    cin>>N;
    v<string> arr;
    for (int i = 0; i < N; ++i)
    {
    	string line; cin>>line; arr.push_back(line);
    }
    sort(arr.begin(), arr.end());
    int basecost=0;
   int worst=0;
    rep(i,0,N){
    	int len=arr[i].size();
    	if(arr[worst].size()<len){
    		worst=i;
    	}
    	if(i==0){
    		basecost+=len;
    	}
    	else{
    		basecost+=arr[i-1].size();
    		int same=0;
    		rep(j,0, min(arr[i-1].size(), len)){
    			if(arr[i-1][j]==arr[i][j]) same++;
    			else break;
    		}
    		basecost-=same;
    		basecost+=len-same;
    	}
    }
    longest=arr[worst];
    cout<<basecost+arr.size()+arr[arr.size()-1].size()-arr[worst].size()<<endl;
    sort(arr.begin(), arr.end(), compare);
    rep(i, 0,N){
    	int len=arr[i].size();
    	if(i==0){
    		rep(j,0,len){
    			cout<<arr[i][j]<<endl;
    		}
    		cout<<"P"<<endl;
    	}
    	else{
    		int same=0;
    		rep(j,0, min(arr[i-1].size(),len)){
    			if(arr[i-1][j]==arr[i][j]) same++;
    			else break;
    		}
    		rep(j,0, arr[i-1].size()-same) {
    			cout<<"-"<<endl;
    		}
    		rep(j,same, len){
    			cout<<arr[i][j]<<endl;
    		}
    		cout<<"P"<<endl;
    	}
    	
    }
    return 0;
}








Compilation message

printer.cpp: In function 'bool compare(std::string, std::string)':
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   25 |     rep(j,0, a.size()){
      |         ~~~~~~~~~~~~~             
printer.cpp:25:5: note: in expansion of macro 'rep'
   25 |     rep(j,0, a.size()){
      |     ^~~
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   29 |     rep(j,0, b.size()){
      |         ~~~~~~~~~~~~~             
printer.cpp:29:5: note: in expansion of macro 'rep'
   29 |     rep(j,0, b.size()){
      |     ^~~
printer.cpp: In function 'int main()':
printer.cpp:57:26: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |      if(arr[worst].size()<len){
      |         ~~~~~~~~~~~~~~~~~^~~~
printer.cpp:66:40: error: no matching function for call to 'min(std::__cxx11::basic_string<char>::size_type, int&)'
   66 |       rep(j,0, min(arr[i-1].size(), len)){
      |                                        ^
printer.cpp:8:35: note: in definition of macro 'rep'
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
      |                                   ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  198 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note:   template argument deduction/substitution failed:
printer.cpp:66:40: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
   66 |       rep(j,0, min(arr[i-1].size(), len)){
      |                                        ^
printer.cpp:8:35: note: in definition of macro 'rep'
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
      |                                   ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note:   template argument deduction/substitution failed:
printer.cpp:66:40: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
   66 |       rep(j,0, min(arr[i-1].size(), len)){
      |                                        ^
printer.cpp:8:35: note: in definition of macro 'rep'
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
      |                                   ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3444 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3444:5: note:   template argument deduction/substitution failed:
printer.cpp:66:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   66 |       rep(j,0, min(arr[i-1].size(), len)){
      |                                        ^
printer.cpp:8:35: note: in definition of macro 'rep'
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
      |                                   ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3450 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
printer.cpp:66:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   66 |       rep(j,0, min(arr[i-1].size(), len)){
      |                                        ^
printer.cpp:8:35: note: in definition of macro 'rep'
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
      |                                   ^
printer.cpp:87:39: error: no matching function for call to 'min(std::__cxx11::basic_string<char>::size_type, int&)'
   87 |       rep(j,0, min(arr[i-1].size(),len)){
      |                                       ^
printer.cpp:8:35: note: in definition of macro 'rep'
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
      |                                   ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  198 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note:   template argument deduction/substitution failed:
printer.cpp:87:39: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
   87 |       rep(j,0, min(arr[i-1].size(),len)){
      |                                       ^
printer.cpp:8:35: note: in definition of macro 'rep'
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
      |                                   ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note:   template argument deduction/substitution failed:
printer.cpp:87:39: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'int')
   87 |       rep(j,0, min(arr[i-1].size(),len)){
      |                                       ^
printer.cpp:8:35: note: in definition of macro 'rep'
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
      |                                   ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3444 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3444:5: note:   template argument deduction/substitution failed:
printer.cpp:87:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   87 |       rep(j,0, min(arr[i-1].size(),len)){
      |                                       ^
printer.cpp:8:35: note: in definition of macro 'rep'
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
      |                                   ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3450 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
printer.cpp:87:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   87 |       rep(j,0, min(arr[i-1].size(),len)){
      |                                       ^
printer.cpp:8:35: note: in definition of macro 'rep'
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
      |                                   ^
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   91 |       rep(j,0, arr[i-1].size()-same) {
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:91:7: note: in expansion of macro 'rep'
   91 |       rep(j,0, arr[i-1].size()-same) {
      |       ^~~
printer.cpp: In function 'void setIO(std::string, int)':
printer.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   13 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~