Submission #808982

#TimeUsernameProblemLanguageResultExecution timeMemory
808982BoomydayType Printer (IOI08_printer)C++17
80 / 100
466 ms262144 KiB
// // Created by adavy on 8/5/2023. // // // Created by adavy on 2/4/2023. // // // Created by adavy on 1/31/2023. // // My Header #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; // yay python! using ii = pair<int,int>; using pl = pair<ll,ll>; using pd = pair<db,db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<str>; using vii = vector<ii>; using vpl = vector<pl>; using vpd = vector<pd>; #define tcT template<class T #define tcTU tcT, class U tcT> using V = vector<T>; tcT, size_t SZ> using AR = array<T,SZ>; tcT> using PR = pair<T,T>; // pairs #define mp make_pair #define f first #define s second #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define len(x) int((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) rbegin(x), rend(x) #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define eb emplace_back #define pf push_front const int MOD = 1e9+7; // 998244353; const int MX = 2e5+5; const ll INF = 1e18; // not too close to LLONG_MAX const ld PI = acos((ld)-1); const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!! vector<char> toPrint; struct Trie{ bool active = 0; vector<Trie> links; int numWords=0; int wordsTot=0; bool special = 0; void activate(){ active = 1; numWords = 0; wordsTot = 0; special = 0; links.rsz(26); } void dfs(){ F0R(i, numWords) toPrint.pb('P'); int specialFound = -1; F0R(i, 26){ if (links[i].active&&links[i].wordsTot>0){ if (links[i].special){ specialFound =i; continue; } toPrint.pb('a'+i); links[i].dfs(); toPrint.pb('-'); } } if (specialFound!=-1){ toPrint.pb('a'+specialFound); links[specialFound].dfs(); toPrint.pb('-'); } } void add_word(string& s, bool isSpecial = 0){ special = isSpecial; wordsTot++; if (s.size()==0){ numWords++; return;} int nextChar = s.back()-'a'; if (links[nextChar].active == 0) links[nextChar].activate(); s.pop_back(); links[nextChar].add_word(s,isSpecial); } }; int main(){ std::ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<str> words(n); Trie t; t.activate(); trav(i, words){ cin >> i; reverse(all(i));} std::sort(all(words), [] (const std::string& first, const std::string& second){ return first.size() < second.size(); }); int bs = words.back().size(); F0R(i, words.size()-1) t.add_word(words[i]); t.add_word(words.back(),1); t.dfs(); cout << toPrint.size()-bs << endl; //trav(i, toPrint) cout << i << endl; F0R(i, toPrint.size()-bs) cout << toPrint[i] << endl; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:47:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
      |                                        ^
printer.cpp:48:18: note: in expansion of macro 'FOR'
   48 | #define F0R(i,a) FOR(i,0,a)
      |                  ^~~
printer.cpp:143:5: note: in expansion of macro 'F0R'
  143 |     F0R(i, words.size()-1) t.add_word(words[i]);
      |     ^~~
printer.cpp:47:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
      |                                        ^
printer.cpp:48:18: note: in expansion of macro 'FOR'
   48 | #define F0R(i,a) FOR(i,0,a)
      |                  ^~~
printer.cpp:149:5: note: in expansion of macro 'F0R'
  149 |     F0R(i, toPrint.size()-bs) cout << toPrint[i] << endl;
      |     ^~~
#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...