Submission #95138

# Submission time Handle Problem Language Result Execution time Memory
95138 2019-01-27T14:59:32 Z SuperJava Type Printer (IOI08_printer) C++17
100 / 100
154 ms 11088 KB
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (200'005)
#define MOD (1000000000l + 7l)
#define OO (1050000000)
#define OOL (1100000000000000000)

//global


int main(){
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	int n;
	cin >> n;
	set<string> w;
	vector<string> v2;
	rep(i,0,n){
		string s;
		cin >> s;
		w.insert(s);
		v2.push_back(s);
	}
	sort(v2.begin(), v2.end(),
		[](string a, string b){
			return sz(a) < sz(b);
		});
	vector<string> v;
	int match = sz(v2[n-1]);
	while(!w.empty()){
		vector<string> d;
		for(auto& a:w){
			if(sz(a) >= match){
				if(a.substr(0,match) == v2[n-1].substr(0,match)){
					d.push_back(a);
					v.push_back(a);
				}
			}
		}
		for(auto& a:d){
			w.erase(a);
		}
		match--;
	}
	reverse(v.begin(), v.end());
	string now = "";
	ll ans = 0;
	string com;
	rep(i,0,n){
		int s = 0;
		while(s < min(sz(v),sz(now)) && v[i][s] == now[s]) s++;
		ans += sz(now)-s+sz(v[i])-s;
		while(sz(now) != s){
			now.erase(sz(now)-1,1);
			com += "-";
		}
		while(sz(now) != sz(v[i])){
			com += v[i][sz(now)];
			now += v[i][sz(now)];
		}
		com += 'P';
		now = v[i];
	}
	cout << sz(com) << endl;
	rep(i,0,sz(com)){
		cout << com[i] << endl;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 420 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1272 KB Output is correct
2 Correct 24 ms 1944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 2420 KB Output is correct
2 Correct 34 ms 3440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 5996 KB Output is correct
2 Correct 154 ms 9544 KB Output is correct
3 Correct 97 ms 8240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 5740 KB Output is correct
2 Correct 136 ms 11088 KB Output is correct
3 Correct 118 ms 9296 KB Output is correct
4 Correct 127 ms 10940 KB Output is correct