Submission #1094532

#TimeUsernameProblemLanguageResultExecution timeMemory
1094532vjudge1Type Printer (IOI08_printer)C++17
100 / 100
123 ms106436 KiB
// #pragma GCC optimize ("O3") // #pragma GCC optimize ("unroll-loops") // #pragma comment(linker, "/STACK:2000000") #include<bits/stdc++.h> using namespace std; #define ll long long #define int long long #define ld long double #define endl "\n" #define FOCUS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); void Go() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } ll node=1; struct trienode { trienode* child[26]; bool wordEnd; ll cur_node; ll mx; trienode() { wordEnd=false; for(auto &it:child)it= nullptr; cur_node=0; } }; struct Trie { trienode* root=new trienode(); void insert(string s) { trienode* cur=root; ll cnt=0; for(auto it:s) { if(cur->child[it-'a']== nullptr) cur->child[it-'a']=new trienode (),cur->child[it-'a']->cur_node=node++; cur=cur->child[it-'a']; cur->mx=max(cur->mx,(int)s.size()-cnt++); } cur->wordEnd=true; } bool search(string s) { trienode*cur=root; for(auto it:s) { if(cur->child[it-'a']== nullptr)return false; cur=cur->child[it-'a']; } return cur->wordEnd; } }; int depth[25001]; vector<char>ans; void dfs(trienode* cur) { vector<pair<ll,ll>>temp; for(int i=0;i<=25;i++) { if(cur->child[i]!= nullptr) temp.push_back({cur->child[i]->mx,i}); } sort(temp.begin(),temp.end()); for(auto it:temp) { ans.push_back((char)(it.second+'a')); if(cur->child[it.second]->wordEnd) ans.push_back('P'); dfs(cur->child[it.second]); ans.push_back('-'); } } signed main() { //Go(); ll n; cin>>n; Trie trie; for(int i=0;i<n;i++) { string x; cin>>x; trie.insert(x); } dfs(trie.root); while (ans.size()&&ans.back()=='-')ans.pop_back(); cout<<ans.size()<<endl; for(auto it:ans) cout<<it<<endl; return 0; }

Compilation message (stderr)

printer.cpp: In function 'void Go()':
printer.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen("output.txt", "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...