Submission #310773

# Submission time Handle Problem Language Result Execution time Memory
310773 2020-10-07T21:16:30 Z sofapuden Type Printer (IOI08_printer) C++14
100 / 100
126 ms 8072 KB
#include <bits/stdc++.h>

using namespace std;

int main(){
	int n; cin >> n;
	vector<string> v(n);
	for(auto &x : v)cin >> x;
	vector<vector<string>> out(21);
	vector<int> used(n,0);
	int ls = -1, lsn = 0;
	for(int i = 0; i < n; ++i){
		if((int)v[i].size() > lsn){
			lsn = v[i].size();
			ls = i;
		}
	}
	for(int i = 0; i < lsn; ++i){
		for(int j = 0; j < n; ++j){
			if(used[j])continue;
			if((int)v[j].size() < i){out[i].push_back(v[j]);used[j] = 1;}
			if(v[ls][i] != v[j][i]){out[i].push_back(v[j]);used[j] = 1;}
		}
	}
	for(int i = 0; i < n; ++i){
		if(!used[i])out[20].push_back(v[i]);
	}
	for(int i = 0; i < 21; ++i){
		sort(out[i].begin(),out[i].end());
	}
	string cur;
	vector<char> oututo;
	for(auto x : out){
		for(auto y : x){
			int go = min(cur.size(),y.size());
			for(int i = 0; i < min((int)cur.size(),(int)y.size()); ++i){
				if(cur[i] != y[i]){go = i; break;}
			}
			while(go < (int)cur.size()){
				cur.pop_back();
				oututo.push_back('-');
			}
			for(int i = go; i < (int)y.size(); ++i){
				oututo.push_back(y[i]);
				cur+=y[i];
			}
			oututo.push_back('P');
		}
	}
	cout << oututo.size() << "\n";
	for(auto x : oututo)cout << x << "\n";
}
				
		
	
			
		
		
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 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 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 896 KB Output is correct
2 Correct 18 ms 1440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1768 KB Output is correct
2 Correct 20 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 3616 KB Output is correct
2 Correct 104 ms 6784 KB Output is correct
3 Correct 74 ms 6352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 3564 KB Output is correct
2 Correct 126 ms 8072 KB Output is correct
3 Correct 82 ms 7024 KB Output is correct
4 Correct 113 ms 7800 KB Output is correct