Submission #1176504

#TimeUsernameProblemLanguageResultExecution timeMemory
1176504justokType Printer (IOI08_printer)C++20
0 / 100
1 ms328 KiB
#include <bits/stdc++.h> // + using namespace std; // +++ #define inf 1e18 // + #define FADY \ ios_base::sync_with_stdio(0), cin.tie(0); \ files(); #define all(a) a.begin(), a.end() #define int long long string YN[2] = {"No", "Yes"}; void files() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); #endif } struct Trie { struct Node { int vis[26]{}; int frq = 0, en = 0; }; vector<Node> tree; Trie() { tree.emplace_back(); } void add(string s) { int idx = 0; for (auto &i : s) { int ch = i - 'a'; if (tree[idx].vis[ch] == 0) { tree[idx].vis[ch] = tree.size(); tree.emplace_back(); } idx = tree[idx].vis[ch]; tree[idx].frq++; } tree[idx].en++; } vector<char> ans; void dfs(int idx, bool big) { if (idx) { } vector<pair<int, int>> v; for (int j = 0; j < 26; ++j) { int nxt = tree[idx].vis[j]; if (nxt) { v.push_back({tree[nxt].frq, j}); } } if (tree[idx].en) { ans.push_back('P'); } sort(all(v)); for (int i = 0; i < v.size(); ++i) { auto [f, ch] = v[i]; ans.push_back(ch + 'a'); bool nwBig = (big && (i == v.size() - 1)); dfs(tree[idx].vis[ch], nwBig); if (!nwBig) { ans.push_back('-'); } } } }; void JustOK() { int n; cin >> n; Trie t; for (int i = 0; i < n; ++i) { string s; cin >> s; t.add(s); } t.dfs(0, 1); cout << t.ans.size() << '\n'; for (auto &i : t.ans) { cout << i << '\n'; } } signed main() { FADY; int tc = 1; // cin >> tc; while (tc--) JustOK(); }

Compilation message (stderr)

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