Submission #91643

#TimeUsernameProblemLanguageResultExecution timeMemory
91643Retro3014Type Printer (IOI08_printer)C++17
100 / 100
108 ms5744 KiB
#include <iostream> #include <algorithm> #include <string> #include <vector> using namespace std; #define MAX_N 25000 int N; string str[MAX_N+1]; string l; vector<char> stack, ans; bool sf(string s1, string s2){ int t=0; while(1){ if(s1.size()<=t || s2.size()<=t) return s1<s2; if(s1[t]==l[t] && s2[t]==l[t]) t++; else if(s1[t]==l[t]) return false; else if(s2[t]==l[t]) return true; else return s1<s2; } } int main(){ scanf("%d", &N); for(int i=0; i<N; i++){ cin>>str[i]; if(l.size()<str[i].size()){ l=str[i]; } } sort(str, str+N, sf); for(int i=0; i<N; i++){ for(int j=0; j<str[i].size(); j++){ if(stack.size()==j){ stack.push_back(str[i][j]); ans.push_back(str[i][j]); } while(stack.size()>j && stack[j]!=str[i][j]){ stack.pop_back(); ans.push_back('-'); } if(stack.size()==j){ stack.push_back(str[i][j]); ans.push_back(str[i][j]); } } ans.push_back('P'); } printf("%d\n", (int)ans.size()); for(int i=0; i<ans.size(); i++){ printf("%c\n", ans[i]); } return 0; }

Compilation message (stderr)

printer.cpp: In function 'bool sf(std::__cxx11::string, std::__cxx11::string)':
printer.cpp:17:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(s1.size()<=t || s2.size()<=t)    return s1<s2;
            ~~~~~~~~~^~~
printer.cpp:17:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(s1.size()<=t || s2.size()<=t)    return s1<s2;
                            ~~~~~~~~~^~~
printer.cpp: In function 'int main()':
printer.cpp:35:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0; j<str[i].size(); j++){
                      ~^~~~~~~~~~~~~~
printer.cpp:36:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(stack.size()==j){
                ~~~~~~~~~~~~^~~
printer.cpp:40:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(stack.size()>j && stack[j]!=str[i][j]){
                   ~~~~~~~~~~~~^~
printer.cpp:43:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(stack.size()==j){
                ~~~~~~~~~~~~^~~
printer.cpp:51:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<ans.size(); i++){
                  ~^~~~~~~~~~~
printer.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
#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...