Submission #957566

#TimeUsernameProblemLanguageResultExecution timeMemory
957566hirayuu_ojType Printer (IOI08_printer)C++17
40 / 100
39 ms9040 KiB
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define rep2(i,a,b) for(int i=a; i<(b); i++) #define all(x) x.begin(),x.end() using ll=long long; const int INF=INT_MAX>>1; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin>>n; vector<string> s(n); rep(i,n){ cin>>s[i]; } sort(all(s)); rep(i,n){ s.push_back(s[i]); } rep(i,n){ s.push_back(s[i]); } vector<char> fin; rep(_,2){ int mx=-INF; int pos=0; rep(i,n){ ll ng=0; rep(j,min(s[i].size(),s[i+1].size())){ if(s[i][j]==s[i+1][j]){ ng++; } else{ break; } } int now=(s[i].size()+s[i+1].size()-ng*2)-s[i+1].size(); if(mx<now){ mx=now; pos=i+1; } } vector<char> ans; for(char i:s[pos]){ ans.push_back(i); } ans.push_back('P'); rep2(i,pos,pos+n-1){ ll ng=0; rep(j,min(s[i].size(),s[i+1].size())){ if(s[i][j]==s[i+1][j]){ ng++; } else{ break; } } rep(j,s[i].size()-ng){ ans.push_back('-'); } rep2(j,ng,s[i+1].size()){ ans.push_back(s[i+1][j]); } ans.push_back('P'); } if(fin.size()==0 or fin.size()>=ans.size()){ fin=ans; } reverse(all(s)); } cout<<fin.size()<<"\n"; for(char i:fin){ cout<<i<<"\n"; } }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:3:32: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
    3 | #define rep(i,n) for(int i=0; i<(n); i++)
      |                                ^
printer.cpp:31:13: note: in expansion of macro 'rep'
   31 |             rep(j,min(s[i].size(),s[i+1].size())){
      |             ^~~
printer.cpp:3:32: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
    3 | #define rep(i,n) for(int i=0; i<(n); i++)
      |                                ^
printer.cpp:52:13: note: in expansion of macro 'rep'
   52 |             rep(j,min(s[i].size(),s[i+1].size())){
      |             ^~~
printer.cpp:3:32: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
    3 | #define rep(i,n) for(int i=0; i<(n); i++)
      |                                ^
printer.cpp:60:13: note: in expansion of macro 'rep'
   60 |             rep(j,s[i].size()-ng){
      |             ^~~
printer.cpp:4:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep2(i,a,b) for(int i=a; i<(b); i++)
      |                                   ^
printer.cpp:63:13: note: in expansion of macro 'rep2'
   63 |             rep2(j,ng,s[i+1].size()){
      |             ^~~~
#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...