Submission #293345

# Submission time Handle Problem Language Result Execution time Memory
293345 2020-09-07T23:54:18 Z Hemimor Type Printer (IOI08_printer) C++14
80 / 100
1000 ms 49072 KB
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int M=500000;
int id=1;
map<char,int> mp[M];
int par[M];
bool used[M],vis[M];

int n;
string res;

int Add(string s){
	int v=0;
	for(auto c:s){
		if(mp[v].find(c)==mp[v].end()){
			mp[v][c]=id;
			par[id]=v;
			id++;
		}
		v=mp[v][c];
	}
	vis[v]=true;
	return v;
}

void dfs(int v){
	if(vis[v]) res+='P';
	char c_;
	int u_=-1;
	for(auto p:mp[v]){
		char c=p.first;
		int u=p.second;
		if(used[u]) c_=c,u_=u;
		else{
			res+=c;
			dfs(u);
			res+='-';
		}
	}
	if(u_>=0){
		res+=c_;
		dfs(u_);
	}
}

int main(){
	par[0]=-1;
	cin>>n;
	int mx=0,v;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		int j=Add(s);
		if(s.size()>mx){
			mx=s.size();
			v=j;
		}
	}
	while(v>=0){
		used[v]=true;
		v=par[v];
	}
	dfs(0);
	cout<<res.size()<<endl;
	for(auto c:res) cout<<c<<endl;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:88:14: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   88 |   if(s.size()>mx){
      |      ~~~~~~~~^~~
printer.cpp:95:4: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
   95 |   v=par[v];
      |   ~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23808 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23868 KB Output is correct
2 Correct 15 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23808 KB Output is correct
2 Correct 32 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 24316 KB Output is correct
2 Correct 56 ms 24320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 25336 KB Output is correct
2 Correct 273 ms 27128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 347 ms 27908 KB Output is correct
2 Correct 110 ms 24952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 790 ms 33300 KB Output is correct
2 Execution timed out 1089 ms 45184 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 660 ms 31248 KB Output is correct
2 Execution timed out 1099 ms 49072 KB Time limit exceeded
3 Halted 0 ms 0 KB -