Submission #667339

#TimeUsernameProblemLanguageResultExecution timeMemory
667339marvinthangType Printer (IOI08_printer)C++17
0 / 100
39 ms36296 KiB
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i) #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } struct Node { Node *child[26]; int terminal; Node() { REP(i, 26) child[i] = nullptr; terminal = 0; } }; int N; string maxS; Node *root = new Node(); void addString(const string &s) { Node *p = root; FORE(it, s) { if (p->child[*it - 'a'] == nullptr) p->child[*it - 'a'] = new Node(); p = p->child[*it - 'a']; } p->terminal++; } void init(void) { cin >> N; int sum = 0; REP(i, N) { string s; cin >> s; sum += s.size(); if (maxS.size() < s.size()) maxS = s; addString(s); } } string res; void dfs(Node *p, int depth, bool type) { REP(i, p->terminal) res += 'P'; if (depth == maxS.size()) return; if (type) { REP(i, 26) if (p->child[i] != nullptr && i != maxS[depth] - 'a') { res += char(i + 'a'); dfs(p->child[i], depth + 1, 0); res += '-'; } res += maxS[depth]; dfs(p->child[maxS[depth] - 'a'], depth + 1, 1); } else { REP(i, 26) if (p->child[i] != nullptr) { res += char(i + 'a'); dfs(p->child[i], depth + 1, 0); res += '-'; } } } void process(void) { dfs(root, 0, 1); cout << res.size() << '\n' << res; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr); file("type-printer"); init(); process(); return (0^0); }

Compilation message (stderr)

printer.cpp: In function 'void dfs(Node*, int, bool)':
printer.cpp:46:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  if (depth == maxS.size()) return;
      |      ~~~~~~^~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:7:67: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define          file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:71:2: note: in expansion of macro 'file'
   71 |  file("type-printer");
      |  ^~~~
printer.cpp:7:100: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 | #define          file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:71:2: note: in expansion of macro 'file'
   71 |  file("type-printer");
      |  ^~~~
#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...