답안 #118146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118146 2019-06-18T09:02:24 Z baluteshih Type Printer (IOI08_printer) C++14
100 / 100
61 ms 6476 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 pl;

void DQ(int l,int r,int d)
{
	if(l==r) return;
	int in=-1,out=-1,flag=0,ls=l;
	vector<string> v;
	for(int i=l;i<=r;++i)
		if(i!=ls&&((s[i-1].size()<=d&&s[i].size()>d)||s[i][d]!=s[i-1][d]))
			if(pl<i)
			{
				in=ls,out=i,DQ(ls,i-1,d+1),flag=1;
				break;
			}
			else
				ls=i;
	if(!flag)
		in=ls,out=r+1,DQ(ls,r,d+1);
	for(int i=l;i<in;++i)
		v.pb(s[i]);
	for(int i=out;i<=r;++i)
		v.pb(s[i]);
	for(int i=in;i<out;++i)
		v.pb(s[i]);
	for(int i=l;i<=r;++i)
		s[i]=v[i-l];
}

int main()
{jizz
	int n,L,mx=-1;
	cin >> n;
	for(int i=0;i<n;++i)
		cin >> s[i];
	sort(s,s+n);
	for(int i=0;i<n;++i)
		if((int)s[i].size()>mx)
			mx=s[i].size(),pl=i;
	DQ(0,n-1,0);
	for(int i=0;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];
	}
	cout << output.size() << "\n";
	for(auto c:output)
		cout << c << "\n";
}

Compilation message

printer.cpp: In function 'void DQ(int, int, int)':
printer.cpp:25:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i!=ls&&((s[i-1].size()<=d&&s[i].size()>d)||s[i][d]!=s[i-1][d]))
               ~~~~~~~~~~~~~^~~
printer.cpp:25:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(i!=ls&&((s[i-1].size()<=d&&s[i].size()>d)||s[i][d]!=s[i-1][d]))
                                 ~~~~~~~~~~~^~
printer.cpp:25:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   if(i!=ls&&((s[i-1].size()<=d&&s[i].size()>d)||s[i][d]!=s[i-1][d]))
     ^
printer.cpp: In function 'int main()':
printer.cpp:59:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<nw.size()&&j<s[i].size();++j)
               ~^~~~~~~~~~
printer.cpp:59:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<nw.size()&&j<s[i].size();++j)
                            ~^~~~~~~~~~~~
printer.cpp:65:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=L;j<nw.size();++j)
               ~^~~~~~~~~~
printer.cpp:67:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=L;j<s[i].size();++j)
               ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 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 3 ms 1200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1152 KB Output is correct
2 Correct 3 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1280 KB Output is correct
2 Correct 4 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1464 KB Output is correct
2 Correct 12 ms 1856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 1932 KB Output is correct
2 Correct 11 ms 2084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 3256 KB Output is correct
2 Correct 53 ms 5704 KB Output is correct
3 Correct 35 ms 4272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 2652 KB Output is correct
2 Correct 61 ms 6476 KB Output is correct
3 Correct 39 ms 4576 KB Output is correct
4 Correct 53 ms 6368 KB Output is correct