제출 #1093980

#제출 시각아이디문제언어결과실행 시간메모리
1093980clementineType Printer (IOI08_printer)C++17
50 / 100
129 ms72424 KiB
#include<bits/stdc++.h> using namespace std; const int k = 26; struct Node { bool isend = false; int next[k]; bool big[k]; Node(){ fill(begin(next), end(next), -1); } }; vector<Node> trie; void addstring(string s) { int v = 0; for(auto ch : s) { int c = ch - 'a'; if(trie[v].next[c] == -1) { trie[v].next[c] = trie.size(); trie.emplace_back(); } v = trie[v].next[c]; //cout << v << '\n'; } trie[v].isend = true; } void addbig(string s) { int v = 0; for(auto ch : s) { int c = ch - 'a'; if(trie[v].next[c] == -1) { trie[v].next[c] = trie.size(); trie.emplace_back(); } trie[v].big[c] = true; v = trie[v].next[c]; //cout << v << '\n'; } trie[v].isend = true; } vector<char> ans; void dfs(int u) { //cout << "this is u : " << u << "\n"; if(trie[u].isend) { ans.push_back('P'); //cout << " one \n"; } for(int i = 0; i < k; i ++) { if(trie[u].next[i] != -1 && !trie[u].big[i]) { ans.push_back('a' + i); //cout << "two \n"; dfs(trie[u].next[i]); ans.push_back('-'); } } for(int i = 0; i < k; i ++) { if(trie[u].next[i] != -1 && trie[u].big[i]) { ans.push_back('a' + i); //cout << "foutr \n"; dfs(trie[u].next[i]); ans.push_back('-'); } } } int main() { int n; cin >> n; vector<string> s; trie.emplace_back(); for(int i = 0; i < n; i ++) { string a; cin >> a; s.push_back(a); } sort(s.begin(), s.end(), [](string a, string b){return a.length() < b.length();}); //cout << s[n-1] << "!!!!! \n"; for(int i = 0; i < n-1; i ++) { addstring(s[i]); } addbig(s[n-1]); dfs(0); for(int i = ans.size() - 1; ans[i] != 'P'; i --) { ans.pop_back(); } cout << ans.size() << '\n'; for(int i = 0; i < ans.size() ; i ++) { cout << ans[i] << '\n'; } }

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

printer.cpp: In function 'int main()':
printer.cpp:108:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for(int i = 0; i < ans.size() ; i ++)
      |                    ~~^~~~~~~~~~~~
#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...