Submission #932001

#TimeUsernameProblemLanguageResultExecution timeMemory
932001rahidilbayramliType Printer (IOI08_printer)C++17
100 / 100
110 ms113320 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define vl vector<ll> #define vi vector<int> #define pll pair<ll, ll> #define pii pair<int, int> #define all(v) v.begin(), v.end() #define pb push_back #define f first #define s second using namespace std; using namespace __gnu_pbds; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; vector<char>res; string maxs; struct triee{ struct tr{ ll a[26]; tr(ll x = -1){ memset(a, x, sizeof(a)); } }; vector<tr>v; vl vis; triee() : v({tr()}), vis({0}) {} void add(string s) { ll node = 0; for(auto u : s) { ll ch = u - 'a'; if(v[node].a[ch] == -1) { v[node].a[ch] = (ll)v.size(); v.pb(tr()); vis.pb(0LL); } node = v[node].a[ch]; } vis[node] = 1; } void dfs(ll node, ll depth = 0) { if(vis[node]) { res.pb('P'); vis[node] = 0; } if(depth == maxs.size()) return; ll ch = maxs[depth] - 'a'; for(ll i = 0; i < 26; i++) { if(i != ch && v[node].a[i] != -1) { res.pb(i+'a'); dfs(v[node].a[i], depth+1); res.pb('-'); } } if(v[node].a[ch] != -1) { res.pb(ch+'a'); dfs(v[node].a[ch], depth+1); res.pb('-'); } } } y; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll tests = 1; //cin >> tests; while(tests--) { ll n, i; cin >> n; for(i = 0; i < n; i++) { string s; cin >> s; if(s.size() > maxs.size()) maxs = s; y.add(s); } y.dfs(0LL, 0LL); while(res.back() == '-') res.pop_back(); cout << (ll)res.size() << "\n"; for(auto u : res) cout << u << "\n"; } }

Compilation message (stderr)

printer.cpp: In member function 'void triee::dfs(long long int, long long int)':
printer.cpp:57:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         if(depth == maxs.size())
      |            ~~~~~~^~~~~~~~~~~~~~
#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...