답안 #118072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118072 2019-06-18T06:29:33 Z baluteshih Type Printer (IOI08_printer) C++14
40 / 100
51 ms 4688 KB
#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";
}

Compilation message

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;
                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 2 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 2 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1152 KB Output is correct
2 Correct 2 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1408 KB Output is correct
2 Incorrect 10 ms 1664 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 1680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2452 KB Output is correct
2 Correct 51 ms 4688 KB Output is correct
3 Incorrect 32 ms 3472 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 2068 KB Output isn't correct
2 Halted 0 ms 0 KB -