QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72938#4379. GrammarpoiWA 24ms6344kbC++2.5kb2023-01-20 19:28:482023-01-20 19:28:49

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-20 19:28:49]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:6344kb
  • [2023-01-20 19:28:48]
  • 提交

answer

#include "iostream"
#include "cstring"
#include "cstdio"
#include "algorithm"
#include "queue"
#include "vector"
#include "queue"
#include "stack"
#include "ctime"
#include "set"
#include "map"
#include "bitset"
using namespace std;
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define mp make_pair
#define rep( i , a , b ) for( int i = (a) , i##end = b ; i <= i##end ; ++ i )
#define per( i , a , b ) for( int i = (a) , i##end = b ; i >= i##end ; -- i )
#define mem( a ) memset( a , 0 , sizeof (a) )
#define all( x ) x.begin() , x.end()
//#define int long long
typedef long long ll;
const int MAXN = 2e3 + 10;
const int P = 998244353;
int n , q;

struct tr {
	int v; string S;
	tr( ) = default;
	tr( int l , string t ) : v(l) , S(t) {}
	
};

vector<tr> G[MAXN];

int loop[MAXN] , vis[MAXN] , cid , ins[MAXN];
ll le[MAXN];
void dfs( int u ) {
	if( ins[u] ) {
		loop[u] = 1; return;
	} else if( vis[u] == cid ) {
		return;
	} else le[u] = 0;
	vis[u] = cid , ins[u] = 1;
	for( auto& t : G[u] ) {
		le[u] += t.S.length();
		if( t.v ) {
			dfs( t.v );
			if( !loop[t.v] ) le[u] += le[t.v];
			loop[u] |= loop[t.v];
		}
		if( le[u] > 2e18 ) le[u] = 2e18;
	}
	ins[u] = 0;
}

int plen[MAXN] , flg = 0;
char que( int u , int c ) {
	if( plen[u] && !flg ) {
		int l = plen[u] - c;
		c = c % l , c = ( !c ? l : c ) , flg = 1;
	}
	plen[u] = c;
	for( auto& t : G[u] ) {
		if( c <= t.S.length() ) return t.S[c - 1];
		c -= t.S.length();
		if( t.v == 0 ) return 0;
		if( loop[t.v] ) return que( t.v , c );
		else {
			if( c <= le[t.v] ) return que( t.v , c );
			c -= le[t.v];
		}
	}
}

char ch[MAXN];
void solve() {
	cin >> n >> q;
	rep( i , 1 , n ) {
		int x;
		scanf("\n[%d]->",&x);
		scanf("%s",ch + 1);
		int l = strlen( ch + 1 ) , ot = 0;
		G[x].eb( 0 , "" );
		rep( i , 1 , l ) {
			if( ch[i] == '[' ) {
				++ i;
				int ret = 0;
				while( ch[i] >= '0' && ch[i] <= '9' ) ret = ret * 10 + ch[i] - '0' , ++ i;
				G[x].back().v = ret;
				G[x].eb( 0 , "" );
			} else {
				G[x].back().S.pb( ch[i] );
			}
		}
	}
	rep( i , 1 , n ) cid = i , dfs( i );
//	cout << le[2] << endl;
	rep( i , 1 , q ) {
		int u;
		ll l;
		scanf("%d%lld",&u,&l);
		flg = 0;
		char as = que( u , l );
		if( as ) putchar( as ) , puts("");
		else puts("-1");
		rep( i , 1 , n ) plen[i] = 0;
	}
}

signed main() {
//	freopen("in","r",stdin);
//	freopen("out","w",stdout);
	int T;cin >> T;while( T-- ) solve();
//	solve();
}

详细

Test #1:

score: 0
Wrong Answer
time: 24ms
memory: 6344kb

input:

10
1000 1000
[1]->ymkl[794]l[2]a[106]v[2][97]x[9]udiq[3]jrpt[265]l[111]w[43]jnb[4]dpjp[3][23]q[511]roml[49][20]j[34][4]qcgjv[443]qg[2][201]j[75]y[2]qi[51][49]y[536]vxdo[243]h[431]vp[470]i[154][30]uhvipimij[65]zoe[36]r
[2]->gka[94][216][410]or[58]v[12][3]gf[20]u[328][115][71][79]j[239][102][3]y[46]mr...

output:

q
c
v
t
z
n
i
t
t
j
b
c
q
b
y
-1
z
t
w
c
m
l
h
n
h
-1
n
c
x
i
s
v
u
o
d
d
o
x
l
n
i
v
l
o
l
o
-1
k
c
l
f
f
z
q
b
d
c
x
m
i
z
-1
o
y
o
r
w
e
-1
-1
z
j
b
j
f
h
e
r
g
i
m
n
m
l
k
f
-1
r
d
p
c
s
v
q
d
l
s
q
x
l
s
f
b
-1
p
-1
n
m
l
-1
-1
c
y
p
e
n
f
s
p
b
-1
c
h
c
x
s
s
t
t
r
-1
a
t
l
s
t
d
d
q
m
e
-1
v
...

result:

wrong answer 70th lines differ - expected: 'f', found: '-1'