Submission #1026291

#TimeUsernameProblemLanguageResultExecution timeMemory
1026291fv3Type Printer (IOI08_printer)C++14
10 / 100
25 ms2296 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll INF = 1ll << 60ll; vector<int> order(26); bool compare(string a, string b) { for (int i = 0; i < min(a.size(), b.size()); i++) { if (order[a[i]-'a'] > order[b[i]-'a']) return true; if (order[a[i]-'a'] < order[b[i]-'a']) return false; } return a.size() < b.size(); } string printSolution(vector<string>&bestPerm) { string res = ""; string lastWord = ""; for (auto w : bestPerm) { int i = 0; for (; i < min(lastWord.size(), w.size()); i++) { if (w[i] != lastWord[i]) break; } for (int j = 0; j < lastWord.size() - i; j++) res += "-"; for (; i < w.size(); i++) res += w[i]; res += "P"; lastWord = w; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vector<string> words(N); string longest = ""; for (int i = 0; i < N; i++) { cin >> words[i]; if (words[i].size() > longest.size()) longest = words[i]; } int x = 1; for (auto c : longest) { if (order[c-'a']) continue; order[c-'a'] = x++; } for (int i = 0; i < 26; i++) { if (order[i] == 0) order[i] = x++; } sort(words.begin(), words.end(), compare); string res = printSolution(words); cout << res.size() << '\n'; for (auto c : res) { cout << c << '\n'; } return 0; }

Compilation message (stderr)

printer.cpp: In function 'bool compare(std::string, std::string)':
printer.cpp:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   11 |  for (int i = 0; i < min(a.size(), b.size()); i++)
      |                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'std::string printSolution(std::vector<std::__cxx11::basic_string<char> >&)':
printer.cpp:27:12: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   27 |   for (; i < min(lastWord.size(), w.size()); i++)
      |          ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:33:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   for (int j = 0; j < lastWord.size() - i; j++)
      |                   ~~^~~~~~~~~~~~~~~~~~~~~
printer.cpp:36:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |   for (; i < w.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...