Submission #737942

#TimeUsernameProblemLanguageResultExecution timeMemory
737942guagua0407Type Printer (IOI08_printer)C++17
20 / 100
46 ms52632 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=2.5e4*20+5; int trie[mxn][26]; char c[mxn]; int cur=1; vector<char> ans; string mx=""; void dfs(int v,int d=0,bool tf=true){ if(v!=0) ans.push_back(c[v]); int cnt=0; for(int i=0;i<26;i++){ if(trie[v][i]!=-1){ cnt++; if(tf and d<mx.length() and (mx[d]-'a')==i) continue; dfs(trie[v][i],d+1,false); } } if(tf and d<mx.length()){ dfs(trie[v][mx[d]-'a'],d+1,true); } if(cnt==0) ans.push_back('P'); if(v!=0) ans.push_back('-'); } void insert(string str){ int v=0,i=0; while(i<str.length()){ if(trie[v][str[i]-'a']==-1){ trie[v][str[i]-'a']=cur; v=cur; c[cur]=str[i]; cur++; } else{ v=trie[v][str[i]-'a']; } i++; } } int main() {_ for(int i=0;i<mxn;i++){ for(int j=0;j<26;j++){ trie[i][j]=-1; } } int n; cin>>n; for(int i=0;i<n;i++){ string str; cin>>str; insert(str); if(str.length()>mx.length()){ mx=str; } } dfs(0); while(ans.back()=='-') ans.pop_back(); cout<<(int)ans.size()<<'\n'; for(auto v:ans){ cout<<v<<'\n'; } return 0; } //maybe its multiset not set

Compilation message (stderr)

printer.cpp: In function 'void dfs(int, int, bool)':
printer.cpp:29:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             if(tf and d<mx.length() and (mx[d]-'a')==i) continue;
      |                       ~^~~~~~~~~~~~
printer.cpp:33:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     if(tf and d<mx.length()){
      |               ~^~~~~~~~~~~~
printer.cpp: In function 'void insert(std::string)':
printer.cpp:42:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     while(i<str.length()){
      |           ~^~~~~~~~~~~~~
printer.cpp: In function 'void setIO(std::string)':
printer.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...