QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#515466 | #2266. Colorful Rectangle | WorldFinalEscaped# | WA | 3ms | 4016kb | C++17 | 2.0kb | 2024-08-11 17:56:54 | 2024-08-11 17:56:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int LIM = 305;
struct node {
int x, y, c;
} a[N];
int ans = 1e9;
int qwq[N], len, n;
int calc(int L, int R) {
// printf("calc %d %d\n", L, R);
len = 0;
for (int i = L; i <= R; i++) {
qwq[++len] = a[i].y * 3 + a[i].c;
}
sort(qwq + 1, qwq + len + 1);
int las[3];
memset(las, -0x3f, sizeof(las));
int ret = 1e9;
for (int i = 1; i <= len; i++) {
int u = qwq[i];
las[u % 3] = u / 3;
int t = *min_element(las, las + 3);
ret = min(ret, u / 3 - t);
}
// printf("get result = %d\n", ret);
return ret;
}
void solve() {
sort(a + 1, a + n + 1, [&](node x, node y) { return x.x < y.x; });
static int back[N];
for (int i = 1; i <= n; i++) {
if (a[i].x == a[i - 1].x) back[i] = back[i - 1];
else back[i] = i;
}
int las[3];
memset(las, -0x3f, sizeof(las));
for (int i = 1; i <= n; i++) {
if (clock() / 1. / CLOCKS_PER_SEC > 4.90) {
printf("%d\n", ans);
exit(0);
}
las[a[i].c] = i;
int t = *min_element(las, las + 3);
if (t <= 0 || a[i].x - a[t].x >= ans || a[i].x == a[i + 1].x) continue;
int down = max(1, t - LIM);
int times = LIM, j = t;
while (times-- && j >= down) {
if (clock() / 1. / CLOCKS_PER_SEC > 4.90) {
printf("%d\n", ans);
exit(0);
}
if (a[i].x - a[j].x >= ans) break;
ans = min(ans, a[i].x - a[j].x + calc(j, i));
if (j == back[j]) break;
else j = back[j];
}
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i].x, &a[i].y);
scanf("%d", &a[i].c);
}
solve();
for (int i = 1; i <= n; i++)
swap(a[i].x, a[i].y);
solve();
printf("%d\n", 2 * ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
input:
10 9991473 83825681 1 26476526 51616963 1 50765942 43355004 0 53028333 5604344 2 57100206 5782798 0 80628150 92688632 2 82964896 73929713 2 85102330 11439534 1 86076990 82286008 0 89626190 52420216 0
output:
75818374
result:
ok single line: '75818374'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
150 90758267 21234402 1 21737107 45944411 2 71064827 33646685 1 15732041 80099984 2 59366384 89336101 1 23463874 1772178 1 63300491 91439944 2 55016570 76385018 2 68263153 41801574 2 87098378 47936087 1 52162678 88263752 2 33679612 20590713 2 75242487 92720661 1 1669174 61465572 2 99532428 10613104 ...
output:
29171440
result:
ok single line: '29171440'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3976kb
input:
10 4093976 78512657 0 27609174 62042588 1 31354091 61870386 0 35151441 36807411 1 37547440 25518220 0 44055162 7821981 2 66673981 41182270 0 83484785 58963611 1 83713705 24676214 2 88603397 80197017 0
output:
75778302
result:
ok single line: '75778302'
Test #4:
score: -100
Wrong Answer
time: 3ms
memory: 4016kb
input:
10000 12096 65562074 1 14562 60486739 1 20187 50242814 1 35859 51060918 0 50463 52231435 1 56216 44100657 2 68431 98864745 1 73973 62323865 1 74745 22912751 2 100382 29322594 2 106833 31933585 2 123956 66437573 2 124095 72164704 2 130151 80006173 1 149897 26940530 1 150544 42049736 2 154249 83266583...
output:
600048
result:
wrong answer 1st lines differ - expected: '476190', found: '600048'