Submission #293347

#TimeUsernameProblemLanguageResultExecution timeMemory
293347HemimorType Printer (IOI08_printer)C++14
100 / 100
167 ms56452 KiB
#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,mp[M][26]; //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][c-'a']==-1){ mp[v][c-'a']=id; par[id]=v; id++; } v=mp[v][c-'a']; } vis[v]=true; return v; } void dfs(int v){ if(vis[v]) res+='P'; char c_; int u_=-1; for(int i=0;i<26;i++) if(mp[v][i]>=0){ char c=(char)('a'+i); int u=mp[v][i]; if(used[u]) c_=c,u_=u; else{ res+=c; dfs(u); res+='-'; } } if(u_>=0){ res+=c_; dfs(u_); } } int main(){ for(int i=0;i<M;i++) for(int j=0;j<26;j++) mp[i][j]=-1; par[0]=-1; scanf("%d",&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); printf("%d\n",(int)res.size()); for(auto c:res) printf("%c\n",c); }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:89:14: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   89 |   if(s.size()>mx){
      |      ~~~~~~~~^~~
printer.cpp:83:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   83 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
printer.cpp:96:4: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |   v=par[v];
      |   ~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...