QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#515523#2266. Colorful RectangleWorldFinalEscapedWA 4894ms5552kbC++202.0kb2024-08-11 18:19:492024-08-11 18:19:49

Judging History

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

  • [2024-08-11 18:19:49]
  • 评测
  • 测评结果:WA
  • 用时:4894ms
  • 内存:5552kb
  • [2024-08-11 18:19:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 100005;
const int LIM = 15;

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", 2 * 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) {
            if (clock() / 1. / CLOCKS_PER_SEC > 4.90) {
                printf("%d\n", 2 * ans);
                exit(0); 
            } 
            if (a[i].x - a[j].x >= ans) break;
            j = back[j]; 
            ans = min(ans, a[i].x - a[j].x + calc(j, i));
            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: 3808kb

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: 1ms
memory: 3832kb

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: 3944kb

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: 0
Accepted
time: 73ms
memory: 4116kb

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:

476190

result:

ok single line: '476190'

Test #5:

score: 0
Accepted
time: 4ms
memory: 3840kb

input:

600
46864911 65058066 1
43812689 67844083 1
47624523 65356242 1
65763113 65439718 2
66870643 65931362 0
100000000 43232094 2
99773659 8651677 1
66502329 65775578 0
67130062 61467562 2
41297284 85249873 0
45570122 61586875 1
68626502 64903738 2
44727214 64595373 1
69383055 64974526 2
50960869 6495575...

output:

29384768

result:

ok single line: '29384768'

Test #6:

score: 0
Accepted
time: 44ms
memory: 4084kb

input:

10000
2177 6599212 0
3313 13493229 1
8624 80455572 2
10635 33135945 0
13266 17210177 0
21252 67913127 0
25630 44096615 0
26868 61301695 0
35959 34225877 2
40034 86139028 1
49019 16335976 0
56879 37023369 1
58406 27475381 2
65029 74490416 1
76280 94487503 0
78480 69430131 0
79030 23340728 0
79320 803...

output:

529732

result:

ok single line: '529732'

Test #7:

score: 0
Accepted
time: 4894ms
memory: 4996kb

input:

60000
56904392 34119842 0
56860702 34345199 0
56863596 34223670 0
56833507 34167094 0
69029799 88014623 1
56701555 34308096 0
56818682 34376693 0
56834926 34330417 0
56949550 34257853 0
56684748 34297211 0
56900683 34127043 0
69073935 88044683 1
57002769 34170885 0
56645259 34209545 0
56949514 34101...

output:

214547970

result:

ok single line: '214547970'

Test #8:

score: 0
Accepted
time: 68ms
memory: 4100kb

input:

10000
5943 40201737 0
14879 96360008 1
84275 93764821 1
88316 65975310 2
92537 83169863 2
120913 54444955 1
122906 99179164 2
129216 52068348 1
138852 89877942 2
141123 97415909 1
155989 59760984 2
169805 6529653 2
170898 51961777 2
189693 18175483 1
198839 91060856 0
200187 19004619 0
207702 916481...

output:

392858

result:

ok single line: '392858'

Test #9:

score: -100
Wrong Answer
time: 4894ms
memory: 5552kb

input:

99999
65554710 12155679 0
78502621 86698549 1
66034198 11853186 0
78908439 86997239 1
75690302 59078887 2
75917845 58838788 2
78706695 87224574 1
75278920 59317406 2
75811752 58764827 2
65449462 11911322 0
79138515 86744879 1
65343865 11801595 0
65831220 12681966 0
78208917 86344984 1
78233596 86692...

output:

168316148

result:

wrong answer 1st lines differ - expected: '167810038', found: '168316148'