Submission #969625

#TimeUsernameProblemLanguageResultExecution timeMemory
969625SeenSiravitType Printer (IOI08_printer)C++14
0 / 100
1046 ms1708 KiB
#include<bits/stdc++.h> using namespace std; int n; vector<string> words; int base = 0; int find_position(string s , string res){ for(int i=0;i<min(s.length() , res.length());i++){ if(res[i] != s[i]) return i; } return min(s.length() , res.length()); } int main(){ cin>> n; words.assign(n , ""); for(int i=0;i<n;i++){ cin>> words[i]; if(words[i].length() > words[base].length()) base = i; } /* word 1 -> word 2 -> word 3 -> ...-> word n-1 -> word n (base) each step must change as least as possible reverse : word n -> word n-1 -> ... -> word 2 -> word 1 O(n^2 * mxLen) 25000^2 * 20 = 12,500,000 */ int ans = 0; stack<char> st; swap(words[0] , words[base]); for(int i=0;i<n-1;i++){ int pos = i+1 , mn = INT_MAX , idx = 0; for(int j=i+1;j<n;j++){ int dummy = find_position(words[j] , words[i]); int op = words[i].length() + words[j].length() - 2*dummy; if(op < mn) pos = j , mn = op , idx = dummy; } ans += mn + 1; st.push('P'); int curr = words[i].length() - 1; while(curr >= idx) st.push(words[i][curr--]); for(int j=words[pos].length()-1;j>=idx;j--) st.push('-'); swap(words[i+1] , words[pos]); // cout<< ans << "\n"; } ans += words[n-1].length() + 1; cout<< ans << "\n"; for(auto c : words[n-1]) cout<< c << "\n"; while(!st.empty()) cout<< st.top() << "\n" , st.pop(); return 0; }

Compilation message (stderr)

printer.cpp: In function 'int find_position(std::string, std::string)':
printer.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   10 |     for(int i=0;i<min(s.length() , res.length());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...