Submission #1262770

#TimeUsernameProblemLanguageResultExecution timeMemory
1262770tminhType Printer (IOI08_printer)C++20
0 / 100
31 ms36064 KiB
#include "bits/stdc++.h" using namespace std; #define task "" #define ll long long #define endl '\n' #define fi first #define se second #define vall(a) (a).begin(), (a).end() #define sze(a) (int)a.size() #define pii pair<int, int> #define pll pair<ll, ll> #define ep emplace_back #define pb push_back #define pf push_front const ll mod = 1e9 + 7; const int N = 1e5 + 5; const ll oo = 1e18; bool START; struct node { node *child[26]; int need, depth; node() { for (int i = 0; i < 26; ++i) child[i] = nullptr; need = depth = 0; } }; node* root = new node(); int n; void add(const string s) { node* p = root; for (char ch : s) { if (p->child[ch - 'a'] == nullptr) p->child[ch - 'a'] = new node(); p = p->child[ch - 'a']; p->depth = max(p->depth, sze(s)); } ++p->need; } string ans = ""; void dfs(node* u) { for (int i = 1; i <= u->need; ++i) ans += 'P'; vector<pii> adj; for (int i = 0; i < 26; ++i) { if (u->child[i] == nullptr) continue; adj.pb(make_pair(u->child[i]->depth, i)); } sort(vall(adj)); for (auto [d, i] : adj) { ans += char(i + 'a'); dfs(u->child[i]); ans += '-'; } } inline void solve() { dfs(root); while(!ans.empty() && ans.back() == '-') ans.pop_back(); cout << sze(ans) << endl << ans; } string s; inline void input() { cin >> n; while(n--) { cin >> s; add(s); } return solve(); } bool END; int main() { if(fopen(task ".inp", "r")) { freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); input(); cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl; cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n"; return 0; }

Compilation message (stderr)

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