QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#563017#1827. Token GamekarunaAC ✓678ms4184kbC++202.1kb2024-09-14 00:13:472024-09-14 00:13:47

Judging History

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

  • [2024-09-14 00:13:47]
  • 评测
  • 测评结果:AC
  • 用时:678ms
  • 内存:4184kb
  • [2024-09-14 00:13:47]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ff first
#define ss second
using namespace std;

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

const int SZ = 303;

int dp[SZ][SZ];
bool check(int x1, int y1, int x2, int y2) {
	if (x1 == x2 && abs(y1 - y2) == 1) return false;
	if (y1 == y2 && abs(x1 - x2) == 1) return false;
	if (abs(x1 - x2) <= 1 || abs(y1 - y2) <= 1) return true;
	return (dp[x1][x2] ^ dp[y1][y2]) != 0;
}
int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	for (int y = 1; y < SZ; y++) {
		for (int x = 1; x < SZ; x++) {
			if (abs(x - y) <= 1) {
				continue;
			}
			vector<int> V;
			for (int z = 1; z < x; z++) V.push_back(dp[z][y]);
			for (int z = 1; z < y; z++) V.push_back(dp[x][z]);
			sort(V.begin(), V.end());
			V.erase(unique(V.begin(), V.end()), V.end());

			int sz = V.size();
			dp[x][y] = sz;
			for (int i = 0; i < sz; i++) if (V[i] != i) {
				dp[x][y] = i;
				break;
			}
		}
	}
	
	int q; cin >> q;
	while (q--) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;

		int ans = 0;
		if (x1 == x2) {
			if (y1 > y2) {
				for (int i = y2 + 1; i < y1; i++) if (!check(x1, i, x2, y2)) ++ans;
				for (int i = 1; i < y2; i++) if (!check(x1, y1, x2, i)) ++ans;
			}
			else {
				for (int i = 1; i < y1; i++) if (!check(x1, i, x2, y2)) ++ans;
				for (int i = y1 + 1; i < y2; i++) if (!check(x1, y1, x2, i)) ++ans;
			}
		}
		else {
			for (int i = 1; i < y1; i++) if (!check(x1, i, x2, y2)) ++ans;
			for (int i = 1; i < y2; i++) if (!check(x1, y1, x2, i)) ++ans;
		}

		if (y1 == y2) {
			if (x1 > x2) {
				for (int i = x2 + 1; i < x1; i++) if (!check(i, y1, x2, y2)) ++ans;
				for (int i = 1; i < x2; i++) if (!check(x1, y1, i, y2)) ++ans;
			}
			else {
				for (int i = 1; i < x1; i++) if (!check(i, y1, x2, y2)) ++ans;
				for (int i = x1 + 1; i < x2; i++) if (!check(x1, y1, i, y2)) ++ans;
			}
		}
		else {
			for (int i = 1; i < x1; i++) if (!check(i, y1, x2, y2)) ++ans;
			for (int i = 1; i < x2; i++) if (!check(x1, y1, i, y2)) ++ans;
		}
		cout << ans << '\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 604ms
memory: 4184kb

input:

5
6 6 6 3
6 6 2 2
1 6 3 1
3 6 1 3
6 3 1 5

output:

3
0
1
1
0

result:

ok 5 number(s): "3 0 1 1 0"

Test #2:

score: 0
Accepted
time: 678ms
memory: 4000kb

input:

100000
215 233 28 258
15 243 61 148
172 28 96 37
15 132 62 27
41 186 255 54
145 192 249 263
274 70 185 197
50 101 202 230
256 11 285 19
149 268 163 107
177 201 216 126
65 17 105 263
143 148 2 230
40 128 259 176
183 192 293 169
281 59 240 229
257 157 126 182
161 51 164 14
149 191 227 102
55 14 267 19...

output:

3
1
1
1
1
2
2
3
1
1
3
1
1
1
1
3
3
1
1
1
1
1
1
2
1
1
1
2
1
1
3
1
3
1
1
2
1
1
1
3
4
1
1
3
1
2
2
1
1
1
3
1
1
1
3
1
1
1
1
2
3
1
3
1
1
3
1
3
3
2
1
2
3
3
1
1
1
2
2
1
2
1
3
1
1
1
1
1
2
1
4
1
1
1
3
3
1
1
1
1
2
1
1
1
1
3
2
3
2
1
1
3
1
1
1
1
2
1
1
2
3
1
3
1
1
1
2
3
3
1
2
3
1
1
1
1
1
2
3
2
2
2
1
1
3
1
1
1
2
2
...

result:

ok 100000 numbers