#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf = 1e18;
const ll mod2 = 998244353;
const int mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
if(x+y>=mod2) x-=mod2;
if(x+y<0)x+=mod2;
return x+y;
}
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a, b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,lim,w,l,r ;
int kk;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
// modwwe
phongbeo();
// checktime
}
bool vis[301][301][31][2];
string c[31];
vector<id> v[31];
int pos[31][31];
char cost[31];
struct sc
{
int a;
short b,c,d;
bool f;
};
struct state
{
short b,c;
short d;
bool f;
bool g;
short k;
};
state trace[301][301][31][2];
int hihi[2];
vector<int> ans[301],ans2[301];
bool chec[31];
void phongbeo()
{
string a,b;
cin>>a>>b;
hihi[0]=-1;
hihi[1]=1;
a=" "+a;
b=" "+b;
cin>>n;
pos[0][0]=0;
dem=0;
for(int i=1; i<=n; i++)
{
cin>>c[i];
for(int j=0; j<c[i].size(); j++)
{
pos[i][j]=++dem;
cost[dem]=c[i][j];
}
chec[dem]=1;
}
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
for(int z=0; z<c[j].size(); z++)
{
bool de=0;
dem=0;
for(int t=z; t<c[j].size(); t++)
{
if(dem==c[i].size()) break;
if(c[i][dem++]!=c[j][t])
de=1;
}
if(!de)
{
if(c[i].size()>=c[j].size()-z)
{
if(c[i].size()==c[j].size()-z)v[pos[j][z]].pb({0,0,i});
else v[pos[j][z]].pb({pos[i][c[j].size()-z],1,i});
}
else
{
v[pos[j][z]].pb({pos[j][z+c[i].size()],0,i});
}
}
}
v[0].pb({pos[i][0],1,i});
v[0].pb({pos[i][0],0,i});
}
deque<sc>p;
p.pb({0,0,0,0,0});
while(!p.empty())
{
sc x=p.front();
p.pop_front();
if(vis[x.b][x.c][x.d][x.f]) continue;
if(x.b==a.size()-1&&x.c==b.size()-1&&x.d==0)
{
cout<<x.a,down
while(x.b!=0||x.c!=0||x.d!=0)
{
state f=trace[x.b][x.c][x.d][x.f];
if(f.k!=0)
{
if(f.k<0)
ans[x.b].pb({abs(f.k)});
else ans2[x.c].pb({abs(f.k)});
}
x.b=f.b;
x.c=f.c;
x.d=f.d;
x.f=f.f;
}
for(int i=0; i<a.size(); i++)
{
cout<<ans[i].size()<<" ";
for(auto x:ans[i])
cout<<x<<" ";
down
}
// debug
for(int i=0; i<b.size(); i++)
{
cout<<ans2[i].size()<<" ";
for(auto x:ans2[i])
cout<<x<<" ";
down
}
exit(0);
}
vis[x.b][x.c][x.d][x.f]=1;
for(auto f:v[x.d])
{
int new_f=x.f;
if(f.b==1) new_f=1-new_f;
if(f.a==0)new_f=0;
if(!vis[x.b][x.c][f.a][new_f])
{
p.pb({x.a+1,x.b,x.c,f.a,new_f});
if(trace[x.b][x.c][f.a][new_f].g==0)
{
if(x.d==0)
trace[x.b][x.c][f.a][new_f]= {x.b,x.c,x.d,x.f,1,f.c*hihi[new_f]};
else trace[x.b][x.c][f.a][new_f]= {x.b,x.c,x.d,x.f,1,f.c*hihi[1-x.f]};
}
}
}
if(x.d!=0)
{
if(x.b!=a.size()&&a[x.b+1]==cost[x.d]&&x.f==1)
{
if(chec[x.d])
{
if(!vis[x.b+1][x.c][0][0])
{
p.push_front({x.a,x.b+1,x.c,0,0});
trace[x.b+1][x.c][0][0]= {x.b,x.c,x.d,x.f,1,0};
}
}
else
{
if(!vis[x.b+1][x.c][x.d+1][x.f])
{
p.push_front({x.a,x.b+1,x.c,x.d+1,x.f});
trace[x.b+1][x.c][x.d+1][x.f]= {x.b,x.c,x.d,x.f,1,0};
}
}
}
if(x.c!=b.size()&&b[x.c+1]==cost[x.d]&&x.f==0)
{
if(chec[x.d])
{
if(!vis[x.b][x.c+1][0][0])
{
p.push_front({x.a,x.b,x.c+1,0,0});
trace[x.b][x.c+1][0][0]= {x.b,x.c,x.d,x.f,1,0};
}
}
else
{
if(!vis[x.b][x.c+1][x.d+1][x.f])
{
p.push_front({x.a,x.b,x.c+1,x.d+1,x.f});
trace[x.b][x.c+1][x.d+1][x.f]= {x.b,x.c,x.d,x.f,1,0};
}
}
}
}
else
{
if(x.a==a.size()||x.c==b.size()) continue;
if(a[x.b+1]==b[x.c+1])
{
if(!vis[x.b+1][x.c][x.d][x.f])
{
p.push_front({x.a,x.b+1,x.c+1,x.d,x.f});
trace[x.b+1][x.c+1][x.d][x.f]= {x.b,x.c,x.d,x.f,1,0};
}
}
}
}
///bccaaaaaaab
///bccaaabb
cout<<-1;
}
컴파일 시 표준 에러 (stderr) 메시지
robots.cpp:36:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
36 | const int inf = 1e18;
| ^~~~
robots.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
73 | main()
| ^~~~
robots.cpp: In function 'void phongbeo()':
robots.cpp:209:39: warning: narrowing conversion of 'f.id::a' from 'int' to 'short int' [-Wnarrowing]
209 | p.pb({x.a+1,x.b,x.c,f.a,new_f});
| ~~^
robots.cpp:209:41: warning: narrowing conversion of 'new_f' from 'int' to 'bool' [-Wnarrowing]
209 | p.pb({x.a+1,x.b,x.c,f.a,new_f});
| ^~~~~
robots.cpp:213:76: warning: narrowing conversion of '(f.id::c * hihi[new_f])' from 'int' to 'short int' [-Wnarrowing]
213 | trace[x.b][x.c][f.a][new_f]= {x.b,x.c,x.d,x.f,1,f.c*hihi[new_f]};
| ~~~^~~~~~~~~~~~
robots.cpp:214:97: warning: narrowing conversion of '(f.id::c * hihi[(1 - ((int)x.sc::f))])' from 'int' to 'short int' [-Wnarrowing]
214 | else trace[x.b][x.c][f.a][new_f]= {x.b,x.c,x.d,x.f,1,f.c*hihi[1-x.f]};
| ~~~^~~~~~~~~~~~
robots.cpp:226:46: warning: narrowing conversion of '(((int)x.sc::b) + 1)' from 'int' to 'short int' [-Wnarrowing]
226 | p.push_front({x.a,x.b+1,x.c,0,0});
| ~~~^~
robots.cpp:234:46: warning: narrowing conversion of '(((int)x.sc::b) + 1)' from 'int' to 'short int' [-Wnarrowing]
234 | p.push_front({x.a,x.b+1,x.c,x.d+1,x.f});
| ~~~^~
robots.cpp:234:56: warning: narrowing conversion of '(((int)x.sc::d) + 1)' from 'int' to 'short int' [-Wnarrowing]
234 | p.push_front({x.a,x.b+1,x.c,x.d+1,x.f});
| ~~~^~
robots.cpp:245:50: warning: narrowing conversion of '(((int)x.sc::c) + 1)' from 'int' to 'short int' [-Wnarrowing]
245 | p.push_front({x.a,x.b,x.c+1,0,0});
| ~~~^~
robots.cpp:253:50: warning: narrowing conversion of '(((int)x.sc::c) + 1)' from 'int' to 'short int' [-Wnarrowing]
253 | p.push_front({x.a,x.b,x.c+1,x.d+1,x.f});
| ~~~^~
robots.cpp:253:56: warning: narrowing conversion of '(((int)x.sc::d) + 1)' from 'int' to 'short int' [-Wnarrowing]
253 | p.push_front({x.a,x.b,x.c+1,x.d+1,x.f});
| ~~~^~
robots.cpp:266:42: warning: narrowing conversion of '(((int)x.sc::b) + 1)' from 'int' to 'short int' [-Wnarrowing]
266 | p.push_front({x.a,x.b+1,x.c+1,x.d,x.f});
| ~~~^~
robots.cpp:266:48: warning: narrowing conversion of '(((int)x.sc::c) + 1)' from 'int' to 'short int' [-Wnarrowing]
266 | p.push_front({x.a,x.b+1,x.c+1,x.d,x.f});
| ~~~^~
robots.cpp: In function 'int main()':
robots.cpp:11:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
robots.cpp:77:9: note: in expansion of macro 'fin'
77 | fin(task);
| ^~~
robots.cpp:12:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define fou(x) freopen(x".out","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
robots.cpp:78:9: note: in expansion of macro 'fou'
78 | fou(task);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |