Submission #1235582

#TimeUsernameProblemLanguageResultExecution timeMemory
1235582haiphong5g0Type Printer (IOI08_printer)C++20
100 / 100
101 ms99088 KiB
#include <bits/stdc++.h> #define task "TEST" #define task2 "A" #define pl pair<int, int> #define pf push_front #define pb push_back #define pob pop_back #define pof pop_front #define mp make_pair #define fi first #define se second #define FOR(i, a, b, c) for (int i=a; i<=b; i+=c) #define FORE(i, a, b, c) for (int i=a; i>=b; i+=c) using namespace std; using ll = long long; using ull = unsigned long long; const int Mod = 1e9+7; const int maxn = 1e6; const ll Inf = 1e9; ll dp[maxn+1], k, n, m; string res, a, mx; struct TrieNode { struct TrieNode* childNode[26]; int wordCount = 0; bool mark = false; }; TrieNode* root = new TrieNode(); void insert_key(TrieNode* root, string& key, bool mark) { TrieNode* currentNode = root; for (auto c : key) { if (currentNode->childNode[c - 'a'] == NULL) { TrieNode* newNode = new TrieNode(); currentNode->childNode[c - 'a'] = newNode; } currentNode = currentNode->childNode[c - 'a']; currentNode->mark = mark; } currentNode->wordCount++; } void Search(TrieNode* root) { TrieNode* currentNode = root; if (root->wordCount) res += 'P'; int last = -1; FOR(c, 0, 25, 1) { TrieNode* Node = currentNode->childNode[c]; if (Node == NULL) continue; if (Node->mark == true) { last = c; continue; } res += (char)(c + 'a'); Search(Node); res += '-'; } if (last == -1) return; res += (char)(last + 'a'); Search(currentNode->childNode[last]); res += '-'; } void Read() { cin >> n; FOR(i, 1, n, 1) { cin >> a; if ((ll)a.length() > m) { m = (ll)a.length(); mx = a; } insert_key(root, a, false); } } void Solve() { insert_key(root, mx, true); Search(root); cout << res.size() - mx.size() << '\n'; FOR(i, 0, res.size() - mx.size()-1, 1) cout << res[i] << '\n'; } int main() { if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; for (t=1; t--;) { Read(); Solve(); } }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:82:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:83:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen (task".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...