Submission #314340

# Submission time Handle Problem Language Result Execution time Memory
314340 2020-10-19T18:15:00 Z ShiftyBlock Type Printer (IOI08_printer) C++11
80 / 100
1000 ms 3596 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);
    }
    
}
bool compare(pair<int,string> a, pair<int,string> b){
	int samea=a.f; int sameb=b.f;
    if(samea==sameb){
    	int cmp= a.s.compare(b.s);
    	if(cmp<0) return true;
    	else return false;
    }
    return samea<sameb;
 
}
 
int main() {
    setIO("printer", 0);
 
    int N;
    cin>>N;
    v<pair<int,string>> arr;
    v<int> sim; sim.push_back(0);
    int worst=0;
    for (int i = 0; i < N; ++i)
    {
    	string line; cin>>line; arr.push_back(make_pair(0,line));
    	if(arr[worst].s.size()<line.size()){
    		worst=i;
    	}
    }
    rep(i,0,N){
    	int same=0;
    	rep(j,0, min(arr[i].s.size(), arr[worst].s.size())){
    		if(arr[i].s[j]==arr[worst].s[j]) same++;
    		else break;
    	}
    	arr[i].f=same;
    }
    int basecost=0;
	sort(arr.begin(), arr.end(), compare);
 
    rep(i,0,N){
    	int len=arr[i].s.size();
    	int plen=arr[i-1].s.size();
    	if(i==0){
    		basecost+=len; basecost++;
    	}
    	else{
    		int same=0;
    		rep(j,0,min(len,plen)){
    			if(arr[i].s[j]!=arr[i-1].s[j]) break;
    			same++;
    		}
    		basecost+=plen-same;
    		basecost+=len-same;
    		basecost++;
    		sim.push_back(same);
    	}
    }
    cout<<basecost<<endl;
    rep(i, 0,N){
    	int len=arr[i].s.size();
    	int plen=arr[i-1].s.size();
    	//cout<<arr[i].f<<endl;
    	if(i==0){
    		rep(j,0,len){
    			cout<<arr[i].s[j]<<endl;
    		}
    		cout<<"P"<<endl;
    	}
    	else{
    		int same=sim[i];
    		rep(j,0, plen-same) {
    			cout<<"-"<<endl;
    		}
    		rep(j,same, len){
    			cout<<arr[i].s[j]<<endl;
    		}
    		cout<<"P"<<endl;
    	}
    	
    }
    return 0;
}
 
 
 

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   50 |      rep(j,0, min(arr[i].s.size(), arr[worst].s.size())){
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:50:6: note: in expansion of macro 'rep'
   50 |      rep(j,0, min(arr[i].s.size(), arr[worst].s.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 0 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 416 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 4 ms 384 KB Output is correct
2 Correct 17 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 384 KB Output is correct
2 Correct 40 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 740 KB Output is correct
2 Correct 248 ms 964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 1140 KB Output is correct
2 Correct 98 ms 1148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 745 ms 2160 KB Output is correct
2 Execution timed out 1093 ms 3344 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 627 ms 2152 KB Output is correct
2 Execution timed out 1048 ms 3596 KB Time limit exceeded
3 Halted 0 ms 0 KB -