QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#334404#4174. 学校食堂Link_Cut_Y#32 23ms44736kbC++141.9kb2024-02-21 21:18:082024-02-21 21:18:09

Judging History

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

  • [2024-02-21 21:18:09]
  • 评测
  • 测评结果:32
  • 用时:23ms
  • 内存:44736kb
  • [2024-02-21 21:18:08]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#define gc getchar
#define pc putchar
#define rep(i, a, b) for (int i = (a); i <= (b); i ++ )
#define rop(i, a, b) for (int i = (a); i < (b); i ++ )
#define dep(i, a, b) for (int i = (a); i >= (b); i -- )

using namespace std;

const int N = 100010;
const int mod = 998244353; int T = 1;
void read() { return; } template <typename T, typename ...T2> void read(T &s, T2 &...oth) { s = 0; char ch = gc(); bool f = 0; for (; ch < '0' or ch > '9'; ch = gc()) if (ch == '-') f = 1; for (; ch >= '0' and ch <= '9'; ch = gc()) s = (s << 1) + (s << 3) + (ch ^ 48); s = f ? -s : s; read(oth...); return; }
void write(char ch) { return; } template <typename T, typename ...T2> void write(char ch, T s, T2 ...oth) { if (!s) { pc('0'); pc(ch); write(ch, oth...); return; } int stk[100], top = 0; if (s < 0) pc('-'), s = ~s + 1; while (s) stk[ ++ top] = s % 10, s /= 10; do pc(stk[top -- ] + (1 << 4) + (1 << 5)); while (top); pc(ch); write(ch, oth...); return; }
int qpow(int a, int b = mod - 2, int s = 1) { for (; b; b >>= 1, a = a * a % mod) if (b & 1) s = s * a % mod; return s; }

int n, t[N], b[N], f[1010][1 << 9][20];
void sub(int ans = 0x3f3f3f3f) {
	read(n); rep(i, 1, n) read(t[i], b[i]);
	memset(f, 0x3f, sizeof f); f[1][0][7] = 0;
	rep(i, 1, n) rop(j, 0, (1 << b[i] + 1)) rep(k, -8, b[i]) if (f[i][j][k + 8] != 0x3f3f3f3f) {
		if (j & 1) f[i + 1][j >> 1][k + 7] = min(f[i + 1][j >> 1][k + 7], f[i][j][k + 8]);
		else {
			int lim = n + 10;
			rep(o, 0, b[i]) if (!((j >> o) & 1)) {
				if (i + o > lim) break;
				lim = min(lim, i + o + b[i + o]);
				f[i][j | (1 << o)][o + 8] = min(f[i][j | (1 << o)][o + 8], f[i][j][k + 8] 
					+ (i + k ? (t[i + k] ^ t[i + o]) : 0));
			}
		}
	} rep(i, 0, 8) ans = min(ans, f[n + 1][0][i]); write('\n', ans);
}
signed main() { read(T); while (T -- ) sub(); return 0; }


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 44736kb

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:

1712
1428
2439
2142

result:

wrong answer 1st lines differ - expected: '1070', found: '1712'

Test #2:

score: 0
Wrong Answer
time: 8ms
memory: 44140kb

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
80

result:

wrong answer 3rd lines differ - expected: '67', found: '80'

Test #3:

score: 4
Accepted
time: 7ms
memory: 44000kb

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: 0
Wrong Answer
time: 7ms
memory: 44360kb

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:

498
321
548
618

result:

wrong answer 1st lines differ - expected: '430', found: '498'

Test #5:

score: 4
Accepted
time: 8ms
memory: 44388kb

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: 0
Wrong Answer
time: 13ms
memory: 44000kb

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:

5015
3978
4403

result:

wrong answer 1st lines differ - expected: '4325', found: '5015'

Test #7:

score: 0
Wrong Answer
time: 8ms
memory: 44000kb

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:

198
161
205
207
196

result:

wrong answer 1st lines differ - expected: '167', found: '198'

Test #8:

score: 4
Accepted
time: 7ms
memory: 43968kb

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: 12ms
memory: 43944kb

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: 0
Wrong Answer
time: 8ms
memory: 44372kb

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:

140030
136926
146568
140835
142761

result:

wrong answer 1st lines differ - expected: '130252', found: '140030'

Test #11:

score: 0
Wrong Answer
time: 11ms
memory: 44068kb

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:

143769
144443
145156
147958

result:

wrong answer 1st lines differ - expected: '129513', found: '143769'

Test #12:

score: 0
Wrong Answer
time: 9ms
memory: 44400kb

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:

4153
4306
4104
4223

result:

wrong answer 1st lines differ - expected: '4103', found: '4153'

Test #13:

score: 0
Wrong Answer
time: 3ms
memory: 44080kb

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:

52954
50648
49935

result:

wrong answer 1st lines differ - expected: '50916', found: '52954'

Test #14:

score: 4
Accepted
time: 4ms
memory: 44116kb

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: 0
Wrong Answer
time: 6ms
memory: 44584kb

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:

121793
120251
120051
118992

result:

wrong answer 1st lines differ - expected: '113418', found: '121793'

Test #16:

score: 0
Wrong Answer
time: 11ms
memory: 44068kb

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:

208685
201846
205214
199555

result:

wrong answer 1st lines differ - expected: '186385', found: '208685'

Test #17:

score: 0
Wrong Answer
time: 11ms
memory: 44128kb

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:

10385
10403
10978
10305
10212

result:

wrong answer 1st lines differ - expected: '10225', found: '10385'

Test #18:

score: 4
Accepted
time: 15ms
memory: 44348kb

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: 4ms
memory: 44432kb

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: 0
Wrong Answer
time: 13ms
memory: 44000kb

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:

139707
134403
137885
138338

result:

wrong answer 1st lines differ - expected: '126048', found: '139707'

Test #21:

score: 0
Wrong Answer
time: 8ms
memory: 44384kb

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:

11418
11332
11069

result:

wrong answer 1st lines differ - expected: '10772', found: '11418'

Test #22:

score: 4
Accepted
time: 9ms
memory: 44640kb

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: 0
Wrong Answer
time: 8ms
memory: 44012kb

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:

234014
230141
230145

result:

wrong answer 1st lines differ - expected: '214852', found: '234014'

Test #24:

score: 0
Wrong Answer
time: 23ms
memory: 44036kb

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:

37526
39302
37966
37234
37219

result:

wrong answer 1st lines differ - expected: '34462', found: '37526'

Test #25:

score: 0
Wrong Answer
time: 15ms
memory: 44060kb

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:

293977
293435
291280
297256

result:

wrong answer 1st lines differ - expected: '262467', found: '293977'