Submission #675806

#TimeUsernameProblemLanguageResultExecution timeMemory
675806CookieType Printer (IOI08_printer)C++14
20 / 100
38 ms17680 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; ifstream fin("inpppp.txt"); ofstream fout("outt.txt"); #define ll long long #define vt vector #define pb push_back #define fi first #define se second #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define pii pair<int, int> #define pll pair<ll, ll> //#define int long long typedef unsigned long long ull; const int mxn = 2e4; const ll p[4] = {2, 3, 5, 7}; int n, mx = 0, t = 0; string no; struct th{ int nxt[26] = {}; }; vt<char>res; th trie[mxn * 21]; bool spe[mxn * 21]; void add(string s){ int nd = 0; for(int i = 0; i < s.size(); i++){ int c = s[i] - 'a'; if(trie[nd].nxt[c] == 0)trie[nd].nxt[c] = ++t; nd = trie[nd].nxt[c]; } } void find(string s){ int nd =0; for(int i = 0; i < s.size(); i++){ int c = s[i] - 'a'; if(trie[nd].nxt[c] == 0)trie[nd].nxt[c] = ++t; nd = trie[nd].nxt[c]; spe[nd] = true; } } void dfs(int s){ bool leaf = true; for(int i = 0; i < 26; i++){ int v = trie[s].nxt[i]; if(!spe[v] && v){ leaf = false; res.pb((char)(i + 'a')); dfs(v); } } for(int i = 0; i < 26; i++){ int v = trie[s].nxt[i]; if(spe[v] && v){ leaf = false; res.pb((char)(i + 'a')); dfs(v); } } if(leaf)res.pb('P'); if(!spe[s])res.pb('-'); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; spe[0] = true; forr(i, 0, n){ string s; cin >> s; add(s); if(s.size() > mx){ mx = s.size(); no = s; } } find(no); dfs(0); cout << res.size() << "\n"; for(auto i: res)cout << i << "\n"; return 0; }

Compilation message (stderr)

printer.cpp: In function 'void add(std::string)':
printer.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
printer.cpp: In function 'void find(std::string)':
printer.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:75:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   75 |         if(s.size() > mx){
      |            ~~~~~~~~~^~~~
#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...