Submission #969627

#TimeUsernameProblemLanguageResultExecution timeMemory
969627SeenSiravitType Printer (IOI08_printer)C++14
10 / 100
1040 ms1364 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; } 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"; cout<< "P" << "\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...