Submission #314317

#TimeUsernameProblemLanguageResultExecution timeMemory
314317ShiftyBlockType Printer (IOI08_printer)C++11
40 / 100
719 ms1812 KiB
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pii pair<int, int> #define long long long #define v vector #define rep(i,a,b) for(int i=a; i<b; i++) void setIO(string name, int submit) { if (submit) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } else{ ios_base::sync_with_stdio(0); cin.tie(0); } } int main() { setIO("printer", 0); int N; cin>>N; v<string> arr; for (int i = 0; i < N; ++i) { string line; cin>>line; arr.push_back(line); } sort(arr.begin(), arr.end()); int basecost=0; int worst=0; rep(i,0,N){ int len=arr[i].size(); if(arr[worst].size()<arr[i].size()){ worst=i; } if(i==0){ basecost+=arr[i].size(); } else{ basecost+=arr[i-1].size(); int same=0; rep(j,0, min(arr[i-1].size(), arr[i].size())){ if(arr[i-1][j]==arr[i][j]) same++; else break; } basecost-=same; basecost+=arr[i].size()-same; } } cout<<basecost+arr.size()+arr[arr.size()-1].size()-arr[worst].size()<<endl; string prev=""; rep(i, 0,N){ if(arr[i][0]==arr[worst][0]) continue; if(prev=="") { rep(j,0,arr[i].size()){ cout<<arr[i][j]<<endl; } prev=arr[i]; cout<<"P"<<endl; } else{ int same=0; rep(j,0, min(prev.size(), arr[i].size())){ if(prev[j]==arr[i][j]) same++; else break; } rep(j,0, prev.size()-same) { cout<<"-"<<endl; } rep(j,same, arr[i].size()){ cout<<arr[i][j]<<endl; } cout<<"P"<<endl; prev=arr[i]; } } rep(i,0,N){ if(arr[i][0]!=arr[worst][0]) continue; int j=worst+1; while(j<N && arr[j][0]==arr[worst][0]){ int same=0; rep(k,0, min(prev.size(), arr[j].size())){ if(prev[k]==arr[j][k]) same++; else break; } rep(k,0, prev.size()-same) { cout<<"-"<<endl; } rep(k,same, arr[j].size()){ cout<<arr[j][k]<<endl; } cout<<"P"<<endl; prev=arr[j]; j++; } j=i; while(j<=worst){ int same=0; rep(k,0, min(prev.size(), arr[j].size())){ if(prev[k]==arr[j][k]) same++; else break; } rep(k,0, prev.size()-same) { cout<<"-"<<endl; } rep(k,same, arr[j].size()){ cout<<arr[j][k]<<endl; } cout<<"P"<<endl; prev=arr[j]; //cout<<j<<endl; j++; } break; } return 0; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   47 |       rep(j,0, min(arr[i-1].size(), arr[i].size())){
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:47:7: note: in expansion of macro 'rep'
   47 |       rep(j,0, min(arr[i-1].size(), arr[i].size())){
      |       ^~~
printer.cpp:37:10: warning: unused variable 'len' [-Wunused-variable]
   37 |      int len=arr[i].size();
      |          ^~~
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   60 |       rep(j,0,arr[i].size()){
      |           ~~~~~~~~~~~~~~~~~       
printer.cpp:60:7: note: in expansion of macro 'rep'
   60 |       rep(j,0,arr[i].size()){
      |       ^~~
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   68 |       rep(j,0, min(prev.size(), arr[i].size())){
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:68:7: note: in expansion of macro 'rep'
   68 |       rep(j,0, min(prev.size(), arr[i].size())){
      |       ^~~
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   72 |       rep(j,0, prev.size()-same) {
      |           ~~~~~~~~~~~~~~~~~~~~~   
printer.cpp:72:7: note: in expansion of macro 'rep'
   72 |       rep(j,0, prev.size()-same) {
      |       ^~~
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   75 |       rep(j,same, arr[i].size()){
      |           ~~~~~~~~~~~~~~~~~~~~~   
printer.cpp:75:7: note: in expansion of macro 'rep'
   75 |       rep(j,same, arr[i].size()){
      |       ^~~
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   87 |       rep(k,0, min(prev.size(), arr[j].size())){
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:87:7: note: in expansion of macro 'rep'
   87 |       rep(k,0, min(prev.size(), arr[j].size())){
      |       ^~~
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   91 |       rep(k,0, prev.size()-same) {
      |           ~~~~~~~~~~~~~~~~~~~~~   
printer.cpp:91:7: note: in expansion of macro 'rep'
   91 |       rep(k,0, prev.size()-same) {
      |       ^~~
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   94 |       rep(k,same, arr[j].size()){
      |           ~~~~~~~~~~~~~~~~~~~~~   
printer.cpp:94:7: note: in expansion of macro 'rep'
   94 |       rep(k,same, arr[j].size()){
      |       ^~~
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
  106 |       rep(k,0, min(prev.size(), arr[j].size())){
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:106:7: note: in expansion of macro 'rep'
  106 |       rep(k,0, min(prev.size(), arr[j].size())){
      |       ^~~
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
  110 |       rep(k,0, prev.size()-same) {
      |           ~~~~~~~~~~~~~~~~~~~~~   
printer.cpp:110:7: note: in expansion of macro 'rep'
  110 |       rep(k,0, prev.size()-same) {
      |       ^~~
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
  113 |       rep(k,same, arr[j].size()){
      |           ~~~~~~~~~~~~~~~~~~~~~   
printer.cpp:113:7: note: in expansion of macro 'rep'
  113 |       rep(k,same, arr[j].size()){
      |       ^~~
printer.cpp: In function 'void setIO(std::string, int)':
printer.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   13 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...