Submission #1176389

#TimeUsernameProblemLanguageResultExecution timeMemory
1176389youssefproofType Printer (IOI08_printer)C++20
0 / 100
46 ms328 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define proof ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define tests ll T;cin >> T;while(T--) using namespace std; using namespace __gnu_pbds; #define ordered_set tree< int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> const ll mod = 1e9 + 7; struct Node{ ll cntr; ll nxt[26]; bool endofword = false; }; vector<Node>tri(1); void Insert(string &s) { ll curr = 0; for (int i = 0;i < s.size();i++) { if (!tri[curr].nxt[s[i]-'a']) { tri[curr].nxt[s[i] - 'a'] = tri.size(); tri.emplace_back(); } curr = tri[curr].nxt[s[i]-'a']; tri[curr].cntr++; } tri[curr].endofword = true; } vector<char>ans; void dfs(ll node,ll start = 0) { if (tri[node].endofword) ans.push_back('P'); ll cntr = 0; for (int i = 0;i < 26;i++) { if (tri[node].nxt[i]) cntr++; } for (int i = 0;i < 26;i++) { if (tri[node].nxt[(i + start) % 26]) { ans.push_back(((i + start) % 26) + 'a'); if (cntr==1) dfs(tri[node].nxt[(i + start) % 26],start); else { dfs(tri[node].nxt[(i + start) % 26]); } ans.push_back('-'); } } } void solve() { ll n;cin >> n; while (n--) { string s;cin >> s; Insert(s); } vector<char>anss; ll mini = LLONG_MAX; for (int i = 0;i < 26;i++) { dfs(0,i); while (ans.back() == '-') ans.pop_back(); if (ans.size() < mini) { mini = ans.size(); anss = ans; } ans.clear(); } cout << anss.size() << '\n'; for (auto &i : anss) { cout << i << '\n'; } } int main() { proof; #ifndef ONLINE_JUDGE freopen("C:/Users/youss/OneDrive/Desktop/IO/input.txt", "r", stdin); freopen("C:/Users/youss/OneDrive/Desktop/IO/output.txt", "w", stdout); freopen("C:/Users/youss/OneDrive/Desktop/IO/error.txt", "w", stderr); #endif //tests solve(); }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:75:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |     freopen("C:/Users/youss/OneDrive/Desktop/IO/input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:76:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |     freopen("C:/Users/youss/OneDrive/Desktop/IO/output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:77:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |     freopen("C:/Users/youss/OneDrive/Desktop/IO/error.txt", "w", stderr);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...