이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
string s[25005],output,nw;
int main()
{jizz
int n,L,r=0,mx=-1e9,p,LCP;
cin >> n;
s[0]="";
for(int i=1;i<=n;++i)
cin >> s[i];
sort(s,s+n+1);
s[0]=s[n];
for(int i=1;i<=n;++i)
{
LCP=min(s[i-1].size(),s[i].size());
for(int j=0;j<s[i-1].size()&&j<s[i].size();++j)
if(s[i-1][j]!=s[i][j])
{
LCP=j;
break;
}
if((int)s[i-1].size()-2*LCP>mx)
p=i,mx=s[i-1].size()-2*LCP,r=0;
if((int)s[i].size()-2*LCP>mx)
p=i==1?n:i-1,mx=s[i].size()-2*LCP,r=1;
}
if(!r)
{
for(int i=p;i<=n;++i)
{
L=min(nw.size(),s[i].size());
for(int j=0;j<nw.size()&&j<s[i].size();++j)
if(nw[j]!=s[i][j])
{
L=j;
break;
}
for(int j=L;j<nw.size();++j)
output.pb('-');
for(int j=L;j<s[i].size();++j)
output.pb(s[i][j]);
output.pb('P'),nw=s[i];
}
for(int i=1;i<p;++i)
{
L=min(nw.size(),s[i].size());
for(int j=0;j<nw.size()&&j<s[i].size();++j)
if(nw[j]!=s[i][j])
{
L=j;
break;
}
for(int j=L;j<nw.size();++j)
output.pb('-');
for(int j=L;j<s[i].size();++j)
output.pb(s[i][j]);
output.pb('P'),nw=s[i];
}
}
else
{
for(int i=p;i>=1;--i)
{
L=min(nw.size(),s[i].size());
for(int j=0;j<nw.size()&&j<s[i].size();++j)
if(nw[j]!=s[i][j])
{
L=j;
break;
}
for(int j=L;j<nw.size();++j)
output.pb('-');
for(int j=L;j<s[i].size();++j)
output.pb(s[i][j]);
output.pb('P'),nw=s[i];
}
for(int i=n;i>p;--i)
{
L=min(nw.size(),s[i].size());
for(int j=0;j<nw.size()&&j<s[i].size();++j)
if(nw[j]!=s[i][j])
{
L=j;
break;
}
for(int j=L;j<nw.size();++j)
output.pb('-');
for(int j=L;j<s[i].size();++j)
output.pb(s[i][j]);
output.pb('P'),nw=s[i];
}
}
cout << output.size() << "\n";
for(auto c:output)
cout << c << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
printer.cpp: In function 'int main()':
printer.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<s[i-1].size()&&j<s[i].size();++j)
~^~~~~~~~~~~~~~
printer.cpp:30:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<s[i-1].size()&&j<s[i].size();++j)
~^~~~~~~~~~~~
printer.cpp:46:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<nw.size()&&j<s[i].size();++j)
~^~~~~~~~~~
printer.cpp:46:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<nw.size()&&j<s[i].size();++j)
~^~~~~~~~~~~~
printer.cpp:52:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=L;j<nw.size();++j)
~^~~~~~~~~~
printer.cpp:54:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=L;j<s[i].size();++j)
~^~~~~~~~~~~~
printer.cpp:61:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<nw.size()&&j<s[i].size();++j)
~^~~~~~~~~~
printer.cpp:61:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<nw.size()&&j<s[i].size();++j)
~^~~~~~~~~~~~
printer.cpp:67:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=L;j<nw.size();++j)
~^~~~~~~~~~
printer.cpp:69:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=L;j<s[i].size();++j)
~^~~~~~~~~~~~
printer.cpp:79:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<nw.size()&&j<s[i].size();++j)
~^~~~~~~~~~
printer.cpp:79:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<nw.size()&&j<s[i].size();++j)
~^~~~~~~~~~~~
printer.cpp:85:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=L;j<nw.size();++j)
~^~~~~~~~~~
printer.cpp:87:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=L;j<s[i].size();++j)
~^~~~~~~~~~~~
printer.cpp:94:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<nw.size()&&j<s[i].size();++j)
~^~~~~~~~~~
printer.cpp:94:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<nw.size()&&j<s[i].size();++j)
~^~~~~~~~~~~~
printer.cpp:100:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=L;j<nw.size();++j)
~^~~~~~~~~~
printer.cpp:102:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=L;j<s[i].size();++j)
~^~~~~~~~~~~~
printer.cpp:20:22: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
int n,L,r=0,mx=-1e9,p,LCP;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |