Submission #287470


Source Code Expand

Copy
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
// int a[310][310];
vvint vv;
int n,m,k;
vector<char> c;
int vis[310]={-1};
vector<string> v(310);
string foo(int x,string s){
	// cout<<x<<" "<<s<<endl;
	if(v[x]==s) return s;
	if(vis[x]==-1){
		string tmp="a";
		tmp[0]=c[x];
		if(s.size()<k){
			vis[x]=s.size();
			s=s+tmp;
			// cout<<"s  = "<<s<<endl;
		}
		else{
			s+=tmp;
			rep(i,s.size()-1){
				if(s[i]>s[i+1]){
					s=s.substr(0,i)+s.substr(i+1);
					rep(j,310) if(vis[j]>i) vis[j]--;
					vis[x]=k-1;
					break;
				}
			}
			if(s.size()>k){
				s=s.substr(0,k);
			}
		}
	}
	else{
		string tmp=s;
		reep(i,vis[x],tmp.size()-1){
			swap(tmp[i],tmp[i+1]);
		}
		if(s>tmp){
			s=tmp;
			rep(j,310) if(vis[j]>vis[x]) vis[j]--;
			vis[x]=k-1;
		}
	}
	string ret=s;
	v[x]=s;
	rep(i,vv[x].size()){
		string t=foo(vv[x][i],s);
		if(ret.size()<k) ret=t;
		else if(t.size()==k) ret=min(ret,t);
	}
	// cout<<"ret "<<ret<<endl;
	return v[x]=ret;
}
void mainmain(){
	// int n,m,k;
	cin>>n>>m>>k;
	c=vector<char>(n);
	vv=vvint(n);
	rep(i,n) cin>>c[i];
	// rep(i,n) cout<<c[i]<<" ";
	// cout<<endl;
	rep(i,m){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		vv[x].PB(y);
	}
	string ans="";
	rep(i,n){
		rep(j,310) v[j]="?";
		rep(j,310) vis[j]=-1;
		string t=foo(i,"");
		// cout<<i<<" t "<<t<<endl;
		if(t.size()==k){
			if(ans.size()==0) ans=t;
			else ans=min(ans,t);
		}
	}
	if(ans.size()==0) cout<<-1<<endl;
	else cout<<ans<<endl;
}



}
main() try{
    mainmain();
}
catch(...){
}

Submission Info

Submission Time
Task C - 有向グラフ
User j_gui0121
Language C++11 (GCC 4.8.1)
Score 0
Code Size 3146 Byte
Status WA
Exec Time 2044 ms
Memory 265644 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 4
AC × 22
WA × 3
TLE × 4
MLE × 3
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask0_sample_04.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask0_sample_04.txt, subtask1_manual01.txt, subtask1_manual02.txt, subtask1_manual03.txt, subtask1_manual04.txt, subtask1_manual05.txt, subtask1_manual06.txt, subtask1_manual07.txt, subtask1_manual08.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_special01.txt, subtask1_special02.txt, subtask1_special03.txt, subtask1_special04.txt, subtask1_special05.txt, subtask1_special06.txt, subtask1_special07.txt, subtask1_special08.txt, subtask1_special09.txt, subtask1_special10.txt, subtask1_special11.txt, subtask1_special12.txt, subtask1_special13.txt, subtask1_special14.txt, subtask1_special15.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 23 ms 928 KB
subtask0_sample_02.txt AC 23 ms 796 KB
subtask0_sample_03.txt AC 22 ms 800 KB
subtask0_sample_04.txt AC 21 ms 924 KB
subtask1_manual01.txt AC 23 ms 928 KB
subtask1_manual02.txt AC 23 ms 920 KB
subtask1_manual03.txt AC 22 ms 844 KB
subtask1_manual04.txt AC 22 ms 928 KB
subtask1_manual05.txt AC 23 ms 916 KB
subtask1_manual06.txt AC 21 ms 928 KB
subtask1_manual07.txt AC 22 ms 920 KB
subtask1_manual08.txt AC 21 ms 800 KB
subtask1_random01.txt MLE 1535 ms 265116 KB
subtask1_random02.txt TLE 2044 ms 155356 KB
subtask1_random03.txt MLE 1576 ms 265644 KB
subtask1_random04.txt MLE 1510 ms 264732 KB
subtask1_random05.txt TLE 2031 ms 1176 KB
subtask1_special01.txt TLE 2033 ms 11432 KB
subtask1_special02.txt AC 58 ms 804 KB
subtask1_special03.txt AC 58 ms 932 KB
subtask1_special04.txt AC 44 ms 904 KB
subtask1_special05.txt AC 42 ms 1048 KB
subtask1_special06.txt AC 209 ms 1060 KB
subtask1_special07.txt TLE 2031 ms 1064 KB
subtask1_special08.txt AC 216 ms 872 KB
subtask1_special09.txt AC 214 ms 932 KB
subtask1_special10.txt AC 215 ms 932 KB
subtask1_special11.txt WA 325 ms 1060 KB
subtask1_special12.txt WA 381 ms 1056 KB
subtask1_special13.txt WA 345 ms 1056 KB
subtask1_special14.txt AC 24 ms 932 KB
subtask1_special15.txt AC 40 ms 932 KB