제출 #440541

#제출 시각아이디문제언어결과실행 시간메모리
440541dxz05Type Printer (IOI08_printer)C++14
80 / 100
1099 ms69400 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #define SZ(x) (int)(x).size() const int MAXN = 6e5 + 3e2; string str[MAXN]; int next_free = 2; int trie[MAXN][27]; bool term[MAXN]; void add(string &s){ int v = 1; for (int i = 0; i < s.size(); i++){ int x = s[i] - 'a'; if (trie[v][x] == 0) trie[v][x] = next_free++; v = trie[v][x]; } term[v] = true; } int idx = 0; string gs; void sort(int v){ if (term[v]) str[++idx] = gs; for (int i = 0; i <= 26; i++){ if (trie[v][i] != 0){ gs += char('a' + i); sort(trie[v][i]); gs.pop_back(); } } } int main(){ ios_base::sync_with_stdio(false); int n; cin >> n; int ind = 0; for (int i = 1; i <= n; i++){ cin >> str[i]; if (str[i].size() > str[ind].size()) ind = i; } string longest = str[ind]; for (int i = 1; i <= n; i++){ int j = 0; while (j < str[i].size() && j < longest.size() && str[i][j] == longest[j]) j++; if (j) str[i] = string(j, '{') + str[i]; add(str[i]); } sort(1); vector<char> ans; for (int it = 1; it <= n; it++){ int j = 0; while (j < str[it].size() && str[it][j] == '{') j++; str[it].erase(0, j); int m = str[it - 1].size(), k = str[it].size(); if (m > k){ int need = m - k; while (need--) ans.push_back('-'); m = k; } int cnt = 0; for (int i = 0; i < min(m, k); i++){ if (str[it - 1][i] == str[it][i]) cnt++; else break; } int need = max(0, m - cnt); while (need--){ ans.push_back('-'); } for (int i = cnt; i < k; i++){ ans.push_back(str[it][i]); } ans.push_back('P'); } cout << ans.size() << endl; for (char c : ans) cout << c << endl; return 0; }

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

printer.cpp: In function 'void add(std::string&)':
printer.cpp:18:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for (int i = 0; i < s.size(); i++){
      |                     ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:57:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         while (j < str[i].size() && j < longest.size() && str[i][j] == longest[j]) j++;
      |                ~~^~~~~~~~~~~~~~~
printer.cpp:57:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         while (j < str[i].size() && j < longest.size() && str[i][j] == longest[j]) j++;
      |                                     ~~^~~~~~~~~~~~~~~~
printer.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         while (j < str[it].size() && str[it][j] == '{') j++;
      |                ~~^~~~~~~~~~~~~~~~
#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...