QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#21354#1273. It's All SquaresFudanU1#AC ✓887ms8468kbC++173.6kb2022-03-04 16:44:382022-05-08 02:55:36

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 02:55:36]
  • 评测
  • 测评结果:AC
  • 用时:887ms
  • 内存:8468kb
  • [2022-03-04 16:44:38]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define srep(i, l, r) for (int i = l; i < r; i++)
#define sper(i, r, l) for (int i = r; i > l; i--)
#define maxn 422
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;

int n, m, q;
int a[maxn][maxn];

int ct[maxn * maxn];
int dir[maxn][maxn];
bool vis[maxn][maxn];

bool judge(int x, int y) {
	return !vis[x][y] && 1 <= x && x <= n && 1 <= y && y <= m;
}

int di[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

char s[maxn * maxn << 2]; int l;
int lis[maxn * maxn], cs = 0;
int rlis[maxn * maxn][2], cr = 0;
bool havv[maxn * maxn];

bool get_numx(int x, int y) {
	bool num = 0;
	rep(i, x, n) if (!((dir[i][y] >> 1) & 1)) num ^= 1; 
	return num;
}
bool get_numy(int x, int y) {
	bool num = 0;
	rep(i, y, m) if (!((dir[x][i] >> 3) & 1)) num ^= 1; 
	return num;
}
pii get_st(int x, int y) {
	int i = 1;
	if (s[i] == 'L') {
		if (get_numy(x, y)) return pii(x, y);
		if (get_numy(x, y + 1)) return pii(x, y + 1);
	}
	else if (s[i] == 'R') {
		if (get_numy(x + 1, y)) return pii(x + 1, y);
		if (get_numy(x + 1, y + 1)) return pii(x + 1, y + 1);
	}
	else if (s[i] == 'D') {
		if (get_numx(x + 1, y)) return pii(x + 1, y);
		if (get_numx(x, y)) return pii(x, y);
	}
	else {
		if (get_numx(x + 1, y + 1)) return pii(x + 1, y + 1);
		if (get_numx(x, y + 1)) return pii(x, y + 1);
	}
}

//pii que[maxn * maxn]; int cq = 0, ch = 0;
queue<pii> que;

void update(pii _op) {
	vis[_op.fi][_op.se] = 1;
	++cr; rlis[cr][0] = _op.fi, rlis[cr][1] = _op.se;
	++cs; lis[cs] = a[_op.fi][_op.se];
	ct[lis[cs]]++;
	havv[lis[cs]] = 1;
}

void work(int x, int y, int d) {
	if (d == 1) {
		rep(i, 1, l) {
			if (s[i] == 'L') {
				dir[x][y + 1] &= (15 - 4);
				dir[x][y] &= (15 - 8);
				x -= 1;
			}
			else if (s[i] == 'R') {
				dir[x + 1][y + 1] &= (15 - 4);
				dir[x + 1][y] &= (15 - 8);
				x += 1;
			}
			else if (s[i] == 'D') {
				dir[x + 1][y] &= (15 - 1);
				dir[x][y] &= (15 - 2);
				y -= 1;
			}
			else {
				dir[x + 1][y + 1] &= (15 - 1);
				dir[x][y + 1] &= (15 - 2);
				y += 1;
			}
		}
		
		pii st = get_st(x, y);
		
		//cerr << x << '@' << y << endl;
		
		//cq = ch = 0;
		
		update(st);
		//que[++ch] = st;
		que.push(st);
		while (!que.empty()) {
			//pii op = que[++cq];
			pii op = que.front(); que.pop();
			rep(i, 0, 3) {
				if (!((dir[op.fi][op.se] >> i) & 1)) continue;
				if (!judge(op.fi + di[i][0], op.se + di[i][1])) continue;
				pii _op = pii(op.fi + di[i][0], op.se + di[i][1]);
				update(_op);
				//que[++ch] = _op;
				que.push(_op);
			}
		}
	}
	else {
		rep(i, 1, cs) ct[lis[i]] = 0;
		rep(i, 1, cr) vis[rlis[i][0]][rlis[i][1]] = 0;
		cs = cr = 0;
		
		rep(i, 1, l) {
			if (s[i] == 'L') {
				dir[x][y + 1] = 15;
				dir[x][y] = 15;
				x -= 1;
			}
			else if (s[i] == 'R') {
				dir[x + 1][y + 1] = 15;
				dir[x + 1][y] = 15;
				x += 1;
			}
			else if (s[i] == 'D') {
				dir[x + 1][y] = 15;
				dir[x][y] = 15;
				y -= 1;
			}
			else {
				dir[x + 1][y + 1] = 15;
				dir[x][y + 1] = 15;
				y += 1;
			}
		}
	}
}

int main(){
	int T; scanf("%d", &T);
	while (T--) {
		scanf("%d%d%d", &n, &m, &q);
		rep(i, 1, n) rep(j, 1, m) dir[i][j] = 15;
		rep(i, 1, n) rep(j, 1, m) scanf("%d", &a[i][j]); 
		rep(i, 1, q) {
			int x, y;
			scanf("%d%d%s", &x, &y, s + 1);
			l = strlen(s + 1);
			work(x, y, 1);
			
			int ans = 0;
			rep(i, 1, cs) if (havv[lis[i]] && ct[lis[i]] > 0) havv[lis[i]] = 0, ans++;
			printf("%d\n", ans);
			
			work(x, y, -1);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 5912kb

input:

1
3 3 2
1 2 3
1 1 2
7 8 9
0 0 RRRUUULLLDDD
0 0 RRUULLDD

output:

6
2

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 887ms
memory: 8468kb

input:

10
353 304 4000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98...

output:

59
64
78
56
73
55
62
68
121
101
65
71
72
55
78
79
58
61
57
59
52
66
79
68
68
96
56
79
60
58
58
64
62
58
54
80
52
67
67
50
62
62
70
77
93
69
59
50
53
86
65
74
57
77
51
82
56
81
62
74
63
61
58
55
86
86
53
65
82
63
61
99
77
84
74
83
59
67
73
72
75
51
87
61
51
55
73
75
83
74
75
79
63
94
65
82
87
98
76
7...

result:

ok 217500 lines

Test #3:

score: 0
Accepted
time: 62ms
memory: 7620kb

input:

2
359 306 4000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 ...

output:

66
68
94
59
81
59
58
48
50
90
60
75
46
87
64
65
57
80
69
47
82
60
81
80
50
59
62
65
51
60
56
73
48
57
78
81
52
67
79
51
67
52
58
69
108
48
68
90
89
86
44
82
70
80
59
83
41
90
78
51
71
74
64
74
83
59
78
86
56
68
66
80
73
50
94
68
63
86
74
61
100
76
58
78
59
99
82
69
64
101
65
54
47
64
83
55
68
75
85
...

result:

ok 4600 lines