제출 #588615

#제출 시각아이디문제언어결과실행 시간메모리
588615leeh18Type Printer (IOI08_printer)C++17
100 / 100
193 ms99124 KiB
// #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; #define sz(x) (int)size(x) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define rep(i, a, b) for(int i = a; i < (b); ++i) typedef pair<int, int> pii; typedef vector<int> vi; template<class Fun> class y_combinator_result { Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {} template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count()); void set_io(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } struct node { int max_len; bool check; array<unique_ptr<node>, 26> ch; node() : max_len(0), check(false) {} void insert(const string &s, int pos = 0) { if (sz(s) == pos) { check = true; return; } auto c = int(s[pos] - 'a'); if (ch[c] == nullptr) { ch[c] = make_unique<node>(); } ch[c]->max_len = max(ch[c]->max_len, sz(s)); ch[c]->insert(s, pos + 1); } void dfs(vector<char>& ans) const { vector<pair<int, int>> pool; for (int i = 0; i < sz(ch); i++) { if (ch[i]) { pool.push_back({ch[i]->max_len, i}); } } if (check) { ans.push_back('P'); } sort(pool.begin(), pool.end()); for (auto [val, idx] : pool) { ans.push_back(char('a' + idx)); ch[idx]->dfs(ans); ans.push_back('-'); } } }; void solve() { int n; cin >> n; node trie; int mx = 0; for (int i = 0; i < n; i++) { string s; cin >> s; trie.insert(s); mx = max(mx, sz(s)); } vector<char> ans; trie.dfs(ans); ans.resize(sz(ans) - mx); cout << ans.size() << '\n'; for (auto x : ans) { cout << x << '\n'; } } auto main() -> signed { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }

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

printer.cpp: In function 'void set_io(std::string)':
printer.cpp:33:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  freopen((s + ".in").c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:34:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  freopen((s + ".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...