Submission #954818

#TimeUsernameProblemLanguageResultExecution timeMemory
954818PieArmyType Printer (IOI08_printer)C++17
0 / 100
54 ms68180 KiB
typedef long long ll; ll pie(ll army){return (1ll<<army);} #include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n' #define mid ((left+right)>>1) const ll inf=2000000000000000005; const int sonsuz=2000000005; using namespace std; ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;} struct Node{ int *a=new int[26]; bool word=false; int deep=-1,depth=0; }; vector<char>ans; Node trie[500000]; int node_cnt=1; void ekle(string word){ int cur=0; for(char c:word){ if(word.size()>trie[cur].depth){ trie[cur].depth=word.size(); trie[cur].deep=c-'a'; } if(!trie[cur].a[c-'a']){ trie[cur].a[c-'a']=node_cnt++; } cur=trie[cur].a[c-'a']; } trie[cur].word=true; } void code(){ int n;cin>>n; for(int i=0;i<n;i++){ string s;cin>>s; ekle(s); } function<void(int)>f=[&](int pos)->void{ if(trie[pos].word){ ans.pb('P'); } for(int i=0;i<26;i++){ if(trie[pos].deep==i)continue; if(trie[pos].a[i]==0)continue; ans.pb(char('a'+i)); f(trie[pos].a[i]); } if(trie[pos].deep!=-1){ ans.pb(char('a'+trie[pos].deep)); f(trie[pos].a[trie[pos].deep]); } ans.pb('-'); }; f(0); n=ans.size(); while(ans[n-1]=='-')n--; cout<<n<<endl; for(int i=0;i<n;i++) cout<<ans[i]<<endl; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} int t=1; if(!t)cin>>t; while(t--){code();cout<<endl;} return 0; }

Compilation message (stderr)

printer.cpp: In function 'void ekle(std::string)':
printer.cpp:27:23: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |         if(word.size()>trie[cur].depth){
      |            ~~~~~~~~~~~^~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:71:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~
printer.cpp:71:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","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...