Submission #445769

#TimeUsernameProblemLanguageResultExecution timeMemory
445769dxz05Type Printer (IOI08_printer)C++14
100 / 100
105 ms43712 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #define SZ(x) (int)(x).size() const int MAXN = 1e6 + 3e2; pair<int, string> str[MAXN]; int main(){ //ios_base::sync_with_stdio(false); //cin.tie(nullptr); cout.tie(nullptr); int n; scanf("%d", &n); int ind = 0; for (int i = 1; i <= n; i++){ char c[25]; scanf("%s", &c); int len = strlen(c); str[i].second.resize(len); for (int j = 0; j < len; j++) str[i].second[j] = c[j]; if (str[i].second.size() > str[ind].second.size()) ind = i; } string longest = str[ind].second; for (int i = 1; i <= n; i++){ int j = 0; while (j < str[i].second.size() && str[i].second[j] == longest[j]) j++; str[i].first = j; } sort(str + 1, str + n + 1); vector<char> ans; for (int it = 1; it <= n; it++){ string s = str[it].second, t = str[it - 1].second; if (SZ(t) > SZ(s)){ int need = SZ(t) - SZ(s); while (need--) ans.push_back('-'); t.resize(s.size()); } int cnt = 0; for (int i = 0; i < min(SZ(t), SZ(s)); i++){ if (t[i] == s[i]) cnt++; else break; } int need = max(0, SZ(t) - cnt); while (need--){ ans.push_back('-'); } for (int i = cnt; i < s.size(); i++){ ans.push_back(s[i]); } ans.push_back('P'); } printf("%d\n", SZ(ans)); for (char c : ans) printf("%c\n", c); return 0; } /** 3 print the poem */

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:22:17: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[25]' [-Wformat=]
   22 |         scanf("%s", &c);
      |                ~^   ~~
      |                 |   |
      |                 |   char (*)[25]
      |                 char*
printer.cpp:33:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         while (j < str[i].second.size() && str[i].second[j] == longest[j]) j++;
      |                ~~^~~~~~~~~~~~~~~~~~~~~~
printer.cpp:60:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for (int i = cnt; i < s.size(); i++){
      |                           ~~^~~~~~~~~~
printer.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
printer.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%s", &c);
      |         ~~~~~^~~~~~~~~~
#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...