답안 #1093467

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093467 2024-09-26T22:55:06 Z vtnoo Type Printer (IOI08_printer) C++17
0 / 100
1000 ms 3116 KB
#include<bits/stdc++.h>
//SHORTEST CODE:::::
#define ll long long
#define ull unsigned long long
#define vi vector<int> 
#define vll vector<long long> 
#define PB push_back
#define snd second
#define fst first
#define ii pair<int, int>
#define MP make_pair
#define forn(i,n) for(int i=0;i<n;++i)
#define forsn(i,s,n) for(int i=s; i<n; ++i)
#define SIZE(c) int((c).size())
#define all(x) x.begin(), x.end()
#define endl '\n'
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define imp(x) {for(auto __:x)cout<<__<<" "; cout<<"\n";}
//DEBUG:::::
#define DBG(x) cerr << #x << " = " << (x) << endl
#define RAYA cerr << "===============================" << endl

using namespace std;
     
inline void FIO() {ios_base::sync_with_stdio(false); cin.tie(NULL);}

int dx[4]={0, 0, 1, -1};
int dy[4]={1, -1, 0, 0};
/*Cosas a tener en cuenta:
-Mantenlo Simple
-Leer TODO el enunciado*/

const int mxn=1e5*2+10, M=1e9+7;
/*ll fact[mxn];

ll pw(ll a, ll b){
	if(b==0)return 1;
	if(b%2==0)return pw(a*a%M,b/2)%M;
	else return (a*pw(a*a%M,b/2))%M;
}

ll C(ll n, ll k){
	if(n<k)return 0LL;
	return (fact[n]*pw((fact[k]*fact[n-k])%M, M-2))%M;
}*/

int main(){FIO();
	int n;cin>>n;
	vector<string> v(n);
	vi ind(n);
	forn(i,n){
		ind[i]=i;
		cin>>v[i];
	}
	int maxres=1e9;
	vector<char> ret;
	do{
		vector<char> cur;
		string s=v[ind[0]];
		//Leo el primer string
		forn(i,SIZE(s))cur.PB(s[i]);
		//Construyo la respuesta para el orden
		forsn(i,1,n){
			cur.PB('P');
			int j=0;
			//Maximo prefijo
			while(j<min(SIZE(s), SIZE(v[ind[i]])) and s[j]==v[ind[i]][j]){
				j++;
			}
			//Sacamos el ultimo elemento
			int SZ=SIZE(s);
			forsn(_,j,SZ){
				s.pop_back();
				cur.PB('-');
			}	
			//Ingresamos la siguiente palabra
			forsn(_,j,SIZE(v[ind[i]])){
				s.PB(v[ind[i]][_]);
				cur.PB(v[ind[i]][_]);
			}
		}
		cur.PB('-');
		if(SIZE(cur)<maxres){
			ret=cur;
			maxres=SIZE(cur);
		}
	}while(next_permutation(all(ind)));
	cout<<maxres<<endl;
	forn(i,SIZE(ret))cout<<ret[i]<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 348 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1037 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1056 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1053 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1036 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1052 ms 604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1037 ms 1728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1043 ms 3116 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1034 ms 2820 KB Time limit exceeded
2 Halted 0 ms 0 KB -