QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#42727#4174. 学校食堂MatrixCascade#100 ✓90ms71892kbC++1.7kb2022-08-03 16:17:212022-08-03 16:17:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-03 16:17:24]
  • 评测
  • 测评结果:100
  • 用时:90ms
  • 内存:71892kb
  • [2022-08-03 16:17:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int C;
int t[1031],b[1301];
int dp[1031][1<<9][33];
int n;
int main(){
    scanf("%d",&C);
    while(C--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
        {
            scanf("%d%d",&t[i],&b[i]);
        }
        memset(dp,0x3f,sizeof(dp));
        dp[1][0][7]=0;
        for(int i=1;i<=n;++i)
        {
            for(int j=0;j<(1<<8);++j)
            {
                for(int k=-8;k<=7;++k)
                {
                    if(dp[i][j][k+8]!=0x3f3f3f3f)
                    {
                        if(j&1)
                        {
                            dp[i+1][j>>1][k+7]=min(dp[i+1][j>>1][k+7],dp[i][j][k+8]);
                        }
                        else
                        {
                            int maxx=0x3f3f3f3f;
                            for(int r=0;r<=7;++r)
                            {
                                if(!((j>>r)&1))
                                {
                                    if(i+r>maxx)break;
                                    maxx=min(maxx,i+r+b[i+r]);
                                    //cout<<t[i+k]<<" "<<t[i+r]<<" "<<dp[i][j][k+8]<<" "<<dp[i][j|(i<<r)][r+8]<<i<<" "<<endl;
                                    dp[i][j|(1<<r)][r+8]=min(dp[i][j|(1<<r)][r+8],dp[i][j][k+8]+((i+k)?t[i+k]^t[i+r]:0));
                                }
                            }
                        }
                    }
                }
            }
        }
        int anss=0x3f3f3f3f;
        for(int i=0;i<=8;++i)
        {
            //cout<<dp[n][0][i]<<endl;
            anss=min(anss,dp[n+1][0][i]);
        }
        printf("%d\n",anss);
    }
    return 0;
}

详细

Test #1:

score: 4
Accepted
time: 33ms
memory: 71736kb

input:

4
6
512 2
371 0
855 1
538 1
651 1
543 1
6
195 2
390 2
217 1
403 1
10 1
645 1
6
811 2
605 2
421 1
152 0
352 1
554 0
6
758 2
771 0
121 0
673 1
71 1
535 0

output:

1070
1428
2439
2142

result:

ok 4 lines

Test #2:

score: 4
Accepted
time: 32ms
memory: 71880kb

input:

3
8
2 0
0 0
14 1
6 3
3 0
3 2
7 1
16 3
8
14 1
6 0
13 0
0 3
1 1
9 1
15 1
8 2
8
0 0
9 0
16 3
9 0
16 2
7 0
16 2
5 1

output:

56
39
67

result:

ok 3 lines

Test #3:

score: 4
Accepted
time: 53ms
memory: 71736kb

input:

5
10
19 1
12 1
8 0
27 0
2 0
25 1
7 1
11 1
1 0
1 1
10
25 1
0 0
6 0
3 0
13 0
5 0
8 1
13 1
28 0
16 1
10
8 1
12 0
15 0
0 1
17 0
19 0
22 1
32 1
9 1
31 0
10
18 0
14 1
19 0
13 0
18 0
5 0
5 1
0 1
8 0
26 1
10
10 1
2 1
26 1
11 1
14 0
21 1
15 0
9 0
10 1
5 0

output:

142
103
163
118
119

result:

ok 5 lines

Test #4:

score: 4
Accepted
time: 33ms
memory: 71832kb

input:

4
12
112 3
30 3
120 0
46 1
106 2
18 3
126 2
7 4
59 0
8 4
68 3
18 2
12
53 3
18 4
53 2
118 4
99 2
116 3
118 4
95 4
3 3
106 2
110 3
43 3
12
26 3
34 0
90 4
6 4
67 0
79 2
30 0
39 3
118 0
108 1
12 4
72 2
12
15 3
39 1
90 1
87 1
70 4
11 1
41 2
21 2
17 3
22 2
128 0
11 1

output:

430
321
506
618

result:

ok 4 lines

Test #5:

score: 4
Accepted
time: 39ms
memory: 71816kb

input:

5
18
244 1
716 1
657 1
239 1
645 1
268 0
199 1
488 0
476 0
313 0
56 1
692 0
716 0
771 1
49 1
612 0
372 1
768 1
18
320 0
965 1
341 1
929 0
14 1
636 1
346 0
859 0
246 1
255 0
186 0
274 0
7 0
69 1
285 0
36 1
124 0
720 0
18
686 1
103 0
228 0
201 1
381 1
457 1
203 0
620 0
495 0
501 0
352 1
786 1
681 1
22...

output:

6226
5946
6782
7907
8187

result:

ok 5 lines

Test #6:

score: 4
Accepted
time: 23ms
memory: 71892kb

input:

3
16
686 7
874 2
789 1
994 5
762 4
451 6
318 0
825 7
180 1
360 1
110 6
260 4
111 6
468 0
669 3
246 7
16
523 1
446 5
755 6
585 7
264 6
504 2
83 3
286 7
460 7
386 0
594 7
513 1
195 2
971 6
690 4
75 2
16
297 3
627 6
854 7
51 2
732 5
219 6
912 0
469 2
224 6
287 7
729 6
908 5
260 7
842 0
90 6
253 7

output:

4325
3732
4403

result:

ok 3 lines

Test #7:

score: 4
Accepted
time: 40ms
memory: 71828kb

input:

5
20
0 5
29 0
3 5
16 5
11 2
5 2
9 1
19 1
3 2
23 3
27 2
17 4
21 5
22 2
11 5
15 2
11 3
7 3
3 5
32 1
20
17 3
1 2
19 1
5 5
18 3
7 0
2 5
7 4
0 0
29 5
5 3
7 2
27 4
28 5
16 0
5 0
8 1
1 5
24 5
20 1
20
11 4
30 1
20 3
30 5
29 0
23 5
7 0
1 5
18 5
11 0
10 3
12 0
19 0
29 3
12 3
14 1
0 5
16 4
9 1
1 0
20
32 5
12 1...

output:

167
159
169
207
164

result:

ok 5 lines

Test #8:

score: 4
Accepted
time: 28ms
memory: 71752kb

input:

3
20
11 1
53 0
24 1
116 1
31 0
87 0
5 1
53 0
6 1
3 1
31 0
117 0
87 0
10 1
15 1
99 0
91 1
10 1
111 1
121 1
20
56 1
121 1
38 1
94 0
26 1
60 1
25 0
79 1
121 1
8 1
42 1
79 1
81 1
18 1
67 0
120 1
64 0
53 1
24 1
108 0
20
94 0
116 0
98 1
90 1
21 1
83 1
43 1
35 0
87 1
33 1
2 1
75 0
81 0
13 1
42 0
12 0
93 1
...

output:

992
1068
927

result:

ok 3 lines

Test #9:

score: 4
Accepted
time: 79ms
memory: 71828kb

input:

5
400
124 1
7 1
111 0
63 1
12 1
7 0
83 0
78 0
66 0
29 1
83 1
14 0
87 0
104 0
40 0
0 1
105 1
91 1
128 1
15 1
57 0
12 0
79 0
12 1
126 0
83 0
127 0
69 1
56 1
48 1
106 0
35 0
105 1
51 1
29 0
45 0
23 1
37 0
71 0
86 1
48 1
127 0
3 0
72 0
55 1
69 1
123 0
92 1
82 0
125 1
45 1
13 0
17 1
4 1
71 0
81 0
94 1
10...

output:

22028
22721
22685
22612
22144

result:

ok 5 lines

Test #10:

score: 4
Accepted
time: 70ms
memory: 71840kb

input:

5
500
222 4
363 1
112 5
793 3
638 5
357 2
309 2
735 6
135 3
392 0
642 0
267 2
680 3
377 0
414 6
788 2
16 3
466 1
208 5
645 5
113 6
372 0
75 2
22 2
91 3
533 0
26 0
651 0
116 5
636 3
322 3
553 1
791 3
200 6
307 1
235 4
789 5
67 6
16 2
77 3
447 1
202 3
306 3
623 1
357 1
688 5
88 4
88 6
217 1
770 5
372 ...

output:

130252
127698
133050
126989
133903

result:

ok 5 lines

Test #11:

score: 4
Accepted
time: 52ms
memory: 71840kb

input:

4
500
650 5
650 4
768 0
877 7
444 6
156 3
399 6
923 6
663 5
987 0
721 2
837 5
886 7
356 1
37 2
55 0
484 0
787 6
377 5
361 5
88 7
777 4
57 5
911 3
869 6
250 5
12 7
334 0
116 1
764 3
869 4
681 2
185 4
899 6
454 7
842 0
846 5
677 0
855 2
794 6
897 2
341 7
593 5
93 3
76 5
885 6
528 5
481 3
713 3
773 4
4...

output:

129513
131433
131592
134197

result:

ok 4 lines

Test #12:

score: 4
Accepted
time: 54ms
memory: 71804kb

input:

4
600
15 1
3 1
1 1
12 0
7 2
2 0
7 0
16 1
10 2
0 1
6 2
12 2
2 1
3 1
12 2
6 0
12 1
5 0
4 2
15 2
7 2
5 1
9 0
1 0
4 0
9 2
8 1
11 2
2 1
14 1
1 2
1 2
15 0
13 1
0 0
4 2
7 1
7 2
14 2
4 0
16 0
5 0
9 0
14 1
1 0
16 2
1 1
13 1
9 2
6 1
12 2
7 1
0 2
15 0
1 0
16 0
2 1
0 0
0 0
3 2
11 1
12 0
6 2
13 0
8 0
13 2
14 2
5...

output:

4103
4216
4052
4139

result:

ok 4 lines

Test #13:

score: 4
Accepted
time: 38ms
memory: 71876kb

input:

3
600
45 1
133 1
119 2
38 1
154 0
121 0
83 2
27 0
17 2
53 2
156 1
144 1
54 1
139 1
56 3
74 1
50 1
88 3
193 1
143 2
57 0
17 1
169 3
132 0
110 0
158 0
108 3
163 3
98 0
140 1
62 0
83 2
186 3
145 3
172 1
77 0
112 0
170 0
92 0
74 1
76 2
121 1
199 1
38 2
18 3
164 2
72 3
127 2
40 0
7 0
5 0
52 3
167 0
75 1
...

output:

50916
48160
48261

result:

ok 3 lines

Test #14:

score: 4
Accepted
time: 48ms
memory: 71812kb

input:

4
700
56 0
37 1
5 1
16 0
37 0
5 0
26 0
39 1
60 0
60 0
8 0
56 0
46 0
5 1
29 0
55 1
24 0
38 1
5 1
39 0
37 1
12 0
54 1
41 1
47 0
46 0
62 0
25 1
18 0
46 0
38 0
27 0
1 0
39 1
32 1
41 1
60 1
55 0
59 1
1 0
33 1
15 1
26 0
5 1
44 1
64 1
58 1
29 0
16 1
56 1
56 0
5 1
47 0
25 0
43 0
15 1
33 0
56 1
38 1
50 1
60 ...

output:

19842
20146
19571
19917

result:

ok 4 lines

Test #15:

score: 4
Accepted
time: 54ms
memory: 71820kb

input:

4
700
396 4
467 4
249 0
332 3
363 4
405 1
402 1
238 4
223 3
494 1
66 4
121 1
498 4
430 0
483 1
115 2
124 2
331 2
86 4
61 1
418 1
235 1
178 3
386 0
88 3
0 2
18 2
444 0
247 3
93 2
179 0
474 3
8 3
461 2
397 0
173 0
324 4
321 3
198 1
380 1
221 2
301 0
229 0
336 2
290 0
216 2
93 4
301 3
203 1
340 4
266 4...

output:

113418
113407
112093
111696

result:

ok 4 lines

Test #16:

score: 4
Accepted
time: 57ms
memory: 71828kb

input:

4
700
569 0
423 4
760 4
548 4
134 3
907 0
545 1
381 2
857 1
26 1
437 2
529 7
24 4
604 3
319 6
185 7
789 0
971 2
582 4
684 5
928 5
242 5
831 1
767 1
404 5
695 1
805 2
651 3
647 2
350 2
557 0
929 4
953 4
520 0
336 5
950 7
130 3
66 4
341 1
821 6
870 6
716 3
290 1
271 3
429 3
894 5
964 7
844 5
994 4
438...

output:

186385
178804
182064
184148

result:

ok 4 lines

Test #17:

score: 4
Accepted
time: 78ms
memory: 71760kb

input:

5
800
15 2
29 0
1 0
16 0
18 2
7 2
13 2
4 1
11 1
4 0
31 1
15 1
10 0
26 1
15 2
11 1
20 1
11 2
17 0
31 0
3 1
25 0
27 0
6 2
3 2
9 1
18 1
21 1
32 0
9 2
3 1
23 1
10 2
15 2
27 0
10 1
20 0
9 0
13 1
13 1
22 2
12 2
1 1
8 1
13 2
21 1
24 0
15 1
30 1
21 0
1 1
7 0
15 0
24 2
16 2
0 0
26 0
1 0
27 1
23 0
30 2
8 2
29...

output:

10225
10331
10841
10109
9978

result:

ok 5 lines

Test #18:

score: 4
Accepted
time: 75ms
memory: 71820kb

input:

5
800
35 1
102 1
59 1
88 1
65 0
107 1
84 0
42 0
18 1
119 0
86 0
99 1
48 1
86 1
39 0
43 1
33 1
8 1
121 0
8 0
98 0
119 0
46 1
7 1
85 0
31 0
66 0
29 0
33 1
103 1
126 1
84 0
94 0
54 0
95 0
35 1
7 1
43 0
30 1
107 0
18 0
52 0
52 1
105 0
116 0
84 1
122 1
47 1
84 1
72 1
41 0
62 0
90 0
102 1
39 0
75 1
103 0
...

output:

43832
45313
45987
43967
44808

result:

ok 5 lines

Test #19:

score: 4
Accepted
time: 56ms
memory: 71824kb

input:

4
900
73 1
11 0
109 0
74 1
129 1
93 0
119 0
155 0
1 1
44 0
142 0
87 0
39 1
96 1
161 0
162 0
30 1
4 0
86 0
6 0
25 0
188 1
76 1
75 0
127 0
73 0
17 0
48 0
39 1
172 1
111 0
49 0
72 0
22 0
193 0
147 1
109 1
7 0
19 1
2 0
175 1
29 1
176 1
139 0
29 0
197 0
47 0
117 1
170 1
55 0
196 1
47 0
99 0
182 0
196 1
1...

output:

91454
88061
92272
91361

result:

ok 4 lines

Test #20:

score: 4
Accepted
time: 60ms
memory: 71732kb

input:

4
900
324 2
269 5
329 0
197 6
500 1
59 2
486 3
470 1
89 1
213 3
479 2
116 5
72 3
275 4
435 3
111 5
356 3
105 5
73 2
20 1
460 2
408 4
71 3
67 5
168 6
270 3
4 1
56 0
323 5
77 2
310 2
403 1
375 3
455 3
155 2
223 6
145 4
499 6
381 3
424 6
271 1
475 1
310 3
228 6
157 4
163 5
345 3
468 4
188 0
484 3
156 0...

output:

126048
123741
128020
126682

result:

ok 4 lines

Test #21:

score: 4
Accepted
time: 43ms
memory: 71756kb

input:

3
1000
21 4
21 0
19 5
11 1
9 3
16 0
3 3
21 1
28 2
30 3
3 3
29 1
7 1
22 0
27 3
29 0
26 1
19 4
25 0
21 5
9 5
6 0
4 5
0 3
17 2
29 2
27 0
15 4
21 0
10 4
12 5
15 3
6 4
26 4
3 5
18 5
14 5
4 5
23 5
4 1
15 5
15 3
27 3
15 2
31 4
21 5
20 4
20 4
2 4
21 1
10 0
6 5
28 1
11 0
1 3
14 2
25 4
11 5
15 5
17 5
32 3
16 ...

output:

10772
10722
10383

result:

ok 3 lines

Test #22:

score: 4
Accepted
time: 43ms
memory: 71828kb

input:

3
1000
264 1
978 1
738 1
355 1
394 0
176 1
715 0
764 1
704 1
809 1
561 0
109 0
705 0
799 1
293 0
646 1
249 1
323 1
824 1
625 1
683 1
913 0
275 1
573 1
126 0
972 1
358 0
579 0
317 1
397 1
279 0
666 0
66 1
293 0
692 0
788 0
897 1
244 1
572 0
513 0
565 0
384 1
924 0
710 1
839 0
168 0
348 0
98 0
532 0
1...

output:

440367
428074
423337

result:

ok 3 lines

Test #23:

score: 4
Accepted
time: 46ms
memory: 71824kb

input:

3
1000
382 2
357 4
529 5
196 4
118 5
220 5
530 4
581 1
62 1
370 0
35 0
538 1
426 5
45 6
23 3
570 4
230 0
198 3
303 2
240 3
240 1
376 0
86 3
228 1
394 5
562 5
48 3
443 0
413 5
136 5
360 1
140 3
211 2
67 5
230 0
293 4
207 2
377 2
340 6
106 3
268 3
319 5
358 0
485 0
335 2
325 5
327 1
493 1
97 1
512 0
4...

output:

214852
215629
213471

result:

ok 3 lines

Test #24:

score: 4
Accepted
time: 90ms
memory: 71824kb

input:

5
1000
71 2
106 3
71 5
117 7
93 1
66 2
13 0
17 3
55 1
20 3
89 2
113 4
37 4
110 1
92 0
75 0
75 7
75 5
1 6
103 0
100 4
63 7
14 3
18 2
38 5
83 1
35 6
126 3
107 4
68 2
96 1
36 3
9 0
27 0
100 5
0 5
77 3
91 1
114 1
94 6
12 2
26 4
60 6
10 0
128 7
7 6
45 2
7 0
15 5
60 4
74 2
4 1
53 5
85 7
56 5
25 3
127 6
43...

output:

34462
35172
34186
33621
33792

result:

ok 5 lines

Test #25:

score: 4
Accepted
time: 73ms
memory: 71832kb

input:

4
1000
29 6
657 4
993 0
681 1
673 7
412 1
398 2
171 5
298 3
214 5
552 7
334 1
928 7
405 3
368 7
227 2
655 7
872 5
832 7
694 6
402 5
585 4
44 0
121 5
887 2
478 1
773 7
833 6
503 4
156 6
31 4
234 3
552 1
757 1
455 0
209 5
9 3
774 1
62 1
61 0
988 4
366 2
645 1
905 5
835 2
737 0
963 4
201 4
392 7
714 3
...

output:

262467
261880
261042
268581

result:

ok 4 lines