Submission #1274192

#TimeUsernameProblemLanguageResultExecution timeMemory
1274192dhuyyyyType Printer (IOI08_printer)C++20
0 / 100
2 ms2396 KiB
#include<bits/stdc++.h> #define fi first #define se second #define int long long using namespace std; using ll = long long; using ii = pair<int, int>; using aa = array<int,3>; const int N = 600; const int INF = 1e9; const int MOD = 998244353; int n, m, u, timer = 0; int trie[N][27], dp[N], num[N]; bool check[N]; string s[25005]; vector <aa> adj[25005]; vector <char> operations; void add(string s){ u = 0; for (char c : s){ if (trie[u][c - 'a'] == 0) trie[u][c - 'a'] = ++timer; u = trie[u][c - 'a']; } check[u] = 1; } void get(int u, int cur){ num[u] = cur; for (int j = 0; j <= 25; j++){ if (trie[u][j]){ get(trie[u][j],cur + 1); num[u] = max(num[u],num[trie[u][j]]); } } for (int j = 0; j <= 25; j++){ if (trie[u][j]){ adj[u].push_back({num[trie[u][j]],trie[u][j],j}); } } sort(adj[u].begin(),adj[u].end()); } void dfs(int u){ if (check[u]) operations.push_back('P'); for (aa it : adj[u]){ operations.push_back(it[2] + 'a'); dfs(it[1]); } operations.push_back('-'); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif cin >> n; for (int i = 1; i <= n; i++){ cin >> s[i]; add(s[i]); } get(0,0); dfs(0); while (operations.back() == '-') operations.pop_back(); cout << (int)operations.size() << '\n'; for (char c : operations) cout << c << '\n'; return 0; } /* ██╗░░██╗██╗░░██╗░█████╗░███╗░░██╗░██████╗░ ░██████╗██╗██╗░░░██╗ ░█████╗░██╗░░░██╗████████╗███████╗ ██║░██╔╝██║░░██║██╔══██╗████╗░██║██╔════╝░ ██╔════╝██║██║░░░██║ ██╔══██╗██║░░░██║╚══██╔══╝██╔════╝ █████═╝░███████║███████║██╔██╗██║██║░░██╗░ ╚█████╗░██║██║░░░██║ ██║░░╚═╝██║░░░██║░░░██║░░░█████╗░░ ██╔═██╗░██╔══██║██╔══██║██║╚████║██║░░╚██╗ ░╚═══██╗██║██║░░░██║ ██║░░██╗██║░░░██║░░░██║░░░██╔══╝░░ ██║░╚██╗██║░░██║██║░░██║██║░╚███║╚██████╔╝ ██████╔╝██║╚██████╔╝ ╚█████╔╝╚██████╔╝░░░██║░░░███████╗ ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝░╚═════╝░ ╚═════╝░╚═╝░╚═════╝░ ░╚════╝░░╚═════╝░░░░╚═╝░░░╚══════╝ */

Compilation message (stderr)

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