답안 #486377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486377 2021-11-11T13:16:27 Z PoPularPlusPlus Type Printer (IOI08_printer) C++17
30 / 100
49 ms 5952 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long 
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007; 
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}

bool check(string& a , string& b){
	for(int i = 0; i < (int)a.size(); i++){
		if(a[i]!=b[i])return 1;
	}
	return 0;
}

void solve(){
	int n;
	cin >> n;
	string arr[n];
	for(int i = 0; i < n; i++)cin >> arr[i];
	sort(arr,arr + n);
	int mx = 0 , pos = -1;
	for(int i = 0; i < n-1 ;i++){
		if(arr[i][0] != arr[i + 1][0]){
			if(mx < (int)arr[i].size()){
				mx = arr[i].size();
				pos = i;
			}
		}
	}
	if(mx < (int)arr[n-1].size()){
		mx = arr[n-1].size();
		pos = n-1;
	}
	string a[n];
	int cur = 0;
	for(int i = pos + 1; i < n; i++){
		a[cur++] = arr[i];
	}
	for(int i = 0; i <= pos; i++){
		a[cur++] = arr[i];
	}
	for(int i = 0; i < n; i++)arr[i] = a[i];
	vector<char> v;
	string s = "";
	for(int i = 0; i < n; i++){
		while(check(s,arr[i])){
			v.pb('-');
			s.pop_back();
		}
		for(int j = s.size(); j < (int)arr[i].size(); j++){
			s += arr[i][j];
			v.pb(arr[i][j]);
		}
		v.pb('P');
	}
	cout << v.size() << '\n';
	for(char c : v)cout << c << '\n';
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
	//int t;cin >> t;while(t--)
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 716 KB Output is correct
2 Incorrect 13 ms 1352 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 1480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 3188 KB Output is correct
2 Correct 49 ms 5952 KB Output is correct
3 Incorrect 39 ms 5052 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 2764 KB Output isn't correct
2 Halted 0 ms 0 KB -