Submission #314331

# Submission time Handle Problem Language Result Execution time Memory
314331 2020-10-19T17:52:28 Z ShiftyBlock Type Printer (IOI08_printer) C++11
80 / 100
1000 ms 3180 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;
    int worst=0;
    for (int i = 0; i < N; ++i)
    {
    	string line; cin>>line; arr.push_back(line);
    	if(arr[worst].size()<line.size()){
    		worst=i;
    	}
    }
    int basecost=0;
	longest= arr[worst];
sort(arr.begin(), arr.end(), compare);
 	
 	v<int> samearr; samearr.push_back(0);
    rep(i,0,N){
    	int len=arr[i].size();int plen=arr[i-1].size();
    	if(i==0){
    		basecost+=len; basecost++;
    	}
    	else{
    		int same=0;
    		rep(j,0, min(plen, len)){
    			if(arr[i-1][j]==arr[i][j]) same++;
    			else break;
    		}
    		samearr.push_back(same);
    		basecost+=plen-same;
    		basecost+=len-same;
    		basecost++;
    	}
    }
    longest=arr[worst];
    cout<<basecost<<endl;
    rep(i, 0,N){
    	int len=arr[i].size();
    	int plen=arr[i-1].size();
    	if(i==0){
    		rep(j,0,len){
    			cout<<arr[i][j]<<endl;
    		}
    		cout<<"P"<<endl;
    	}
    	else{
    		int same=samearr[i];
    		rep(j,0, plen-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 '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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 18 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 384 KB Output is correct
2 Correct 39 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 632 KB Output is correct
2 Correct 246 ms 1304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 298 ms 1032 KB Output is correct
2 Correct 97 ms 1060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 752 ms 2032 KB Output is correct
2 Execution timed out 1086 ms 2928 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 602 ms 1904 KB Output is correct
2 Execution timed out 1088 ms 3180 KB Time limit exceeded
3 Halted 0 ms 0 KB -