Submission #782798

#TimeUsernameProblemLanguageResultExecution timeMemory
782798canadavid1Type Printer (IOI08_printer)C++14
20 / 100
1078 ms2536 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x),end(x) using i32 = int32_t; using i64 = int64_t; int common_substring(string a,string b) { if(a.size() < b.size()) swap(a,b); for(int i = b.size()-1;i >= 0; i--) { if(a.substr(0,i)==b.substr(0,i)) return i; } return 0; } int main() { cin.tie(nullptr)->sync_with_stdio(false); i32 N; cin >> N; vector<string> words(N); for(int i = 0; i < N; i++) { cin >> words[i]; } sort(all(words)); string min_ops = ""; do { string curr = ""; string ops = ""; for(auto i : words) { i32 l = common_substring(curr,i); while(curr.size()>l) { curr.pop_back(); ops.push_back('-'); } curr += i.substr(l); ops += i.substr(l); ops.push_back('P'); } if(min_ops.size()==0||ops.size() < min_ops.size()) min_ops = ops; } while(next_permutation(all(words))); cout << min_ops.size() << "\n"; for(auto i : min_ops) cout << i << "\n"; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:38:30: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'i32' {aka 'int'} [-Wsign-compare]
   38 |             while(curr.size()>l)
      |                   ~~~~~~~~~~~^~
#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...