제출 #1104223

#제출 시각아이디문제언어결과실행 시간메모리
1104223dzhoz0Type Printer (IOI08_printer)C++17
100 / 100
142 ms232568 KiB
/* ghmt the cutie :3 UwU */ #include <bits/stdc++.h> using namespace std; #define int long long #define INF 1e18 #define f first #define s second #define pii pair<int, int> #define vi vector<int> const int MOD = 1'000'000'000 + 7; void setIO(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #ifdef LOCAL freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout); #else if (!name.empty()) { freopen((name + ".INP").c_str(), "r", stdin); freopen((name + ".OUT").c_str(), "w", stdout); } #endif } const int MAXNODES = 1e6; struct Node { int child[26]; int cnt; bool stop; int mx; Node() { memset(child, -1, sizeof(child)); stop = 0; cnt = 0; mx = 0; } }; Node trie[MAXNODES + 5]; int sz = 0; void insert(string &s) { int pos = 0; for(char c : s) { if(trie[pos].child[c - 'a'] == -1) { trie[pos].child[c - 'a'] = ++sz; } pos = trie[pos].child[c - 'a']; trie[pos].cnt++; trie[pos].mx = max(trie[pos].mx, (int)s.size()); } trie[pos].stop = 1; } vector<char> ops; void traverse(int id) { if(trie[id].stop == 1) ops.push_back('P'); vector<pair<int, char>> v; for(char c = 'a'; c <= 'z'; c++) { if(trie[id].child[c - 'a'] != -1) { // ops.push_back(c); // traverse(trie[id].child[c - 'a']); v.push_back({trie[trie[id].child[c - 'a']].mx, c}); } } sort(v.begin(), v.end()); for(auto it : v) { ops.push_back(it.s); traverse(trie[id].child[it.s - 'a']); } ops.push_back('-'); } void solve() { int n; cin >> n; vector<string> a(n); for(string &s : a) { cin >> s; insert(s); } traverse(0); while(ops.back() != 'P') ops.pop_back(); cout << ops.size() << '\n'; for(char c : ops) cout << c << '\n'; } signed main() { setIO(); int t = 1; // cin >> t; while (t--) solve(); }

컴파일 시 표준 에러 (stderr) 메시지

printer.cpp: In function 'void setIO(std::string)':
printer.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen((name + ".INP").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen((name + ".OUT").c_str(), "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...