Submission #745680

# Submission time Handle Problem Language Result Execution time Memory
745680 2023-05-21T01:21:10 Z 반딧불(#9962) Double Attendance (CCO22_day1problem3) C++17
15 / 25
477 ms 125932 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n[2], k;
pair<int, int> arr[2][300002];
int idx[2][4002];
int DP[2][4002][4002]; /// DP[d][i][j]: d�� i�� ��ġ�� �ְ� �ݴ��� j�� ������ ���� �� �ִ� ��
int ans;

int main(){
    scanf("%d %d %d", &n[0], &n[1], &k);
    k*=2;
    for(int d=0; d<=1; d++){
        for(int i=1; i<=n[d]; i++){
            scanf("%d %d", &arr[d][i].first, &arr[d][i].second);
            arr[d][i].first *= 2, arr[d][i].second *= 2;
            arr[d][i].first++, arr[d][i].second--;
        }
        sort(arr[d]+1, arr[d]+n[d]+1);
    }
    for(int d=0; d<=1; d++){
        for(int i=1; i<=n[d]; i++){
            for(int j=arr[d][i].first; j<=arr[d][i].second; j++) idx[d][j] = i;
        }
    }
    for(int d=0; d<=1; d++) for(int i=0; i<=4000; i++) for(int j=0; j<=4000; j++) DP[d][i][j] = -1e9;
    DP[0][1][0] = !!(idx[0][1]);

    for(int s=0; s<=8000; s++){
        for(int i=max(s-4000, 0); i<=4000 && i<=s; i++){
            int j = s-i;
            if(DP[0][i][j] >= 0){
                int d = 0;
//                if(ans < DP[d][i][j]) printf("%d %d %d: %d\n", d, i, j, DP[d][i][j]);
                ans = max(ans, DP[d][i][j]);
                DP[d][i+1][j] = max(DP[d][i+1][j], DP[d][i][j] + (idx[d][i] != idx[d][i+1] && idx[d][i+1]));
                if(i+k<=4000)
                    DP[!d][i][i+k] = max(DP[!d][i][i+k], DP[d][i][j] + (idx[!d][j] != idx[!d][i+k] && idx[!d][i+k]));
            }
            if(DP[1][i][j] >= 0){
                int d = 1;
//                if(ans < DP[d][i][j]) printf("%d %d %d: %d\n", d, i, j, DP[d][i][j]);
                ans = max(ans, DP[d][i][j]);
                DP[d][i][j+1] = max(DP[d][i][j+1], DP[d][i][j] + (idx[d][j] != idx[d][j+1] && idx[d][j+1]));
                if(j+k<=4000)
                    DP[!d][j+k][j] = max(DP[!d][j+k][j], DP[d][i][j] + (idx[!d][i] != idx[!d][j+k] && idx[!d][j+k]));
            }
        }
    }

    printf("%d", ans);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d %d %d", &n[0], &n[1], &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:18:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |             scanf("%d %d", &arr[d][i].first, &arr[d][i].second);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 402 ms 125664 KB Output is correct
2 Correct 477 ms 125656 KB Output is correct
3 Correct 437 ms 125668 KB Output is correct
4 Correct 412 ms 125908 KB Output is correct
5 Correct 421 ms 125668 KB Output is correct
6 Correct 397 ms 125804 KB Output is correct
7 Correct 396 ms 125656 KB Output is correct
8 Correct 408 ms 125832 KB Output is correct
9 Correct 374 ms 125680 KB Output is correct
10 Correct 421 ms 125932 KB Output is correct
11 Correct 309 ms 125684 KB Output is correct
12 Correct 428 ms 125804 KB Output is correct
13 Correct 445 ms 125680 KB Output is correct
14 Correct 415 ms 125676 KB Output is correct
15 Correct 415 ms 125684 KB Output is correct
16 Correct 419 ms 125684 KB Output is correct
17 Correct 407 ms 125644 KB Output is correct
18 Correct 314 ms 125756 KB Output is correct
19 Correct 320 ms 125684 KB Output is correct
20 Correct 330 ms 125764 KB Output is correct
21 Correct 308 ms 125644 KB Output is correct
22 Correct 334 ms 125672 KB Output is correct
23 Correct 385 ms 125648 KB Output is correct
24 Correct 370 ms 125580 KB Output is correct
25 Correct 424 ms 125660 KB Output is correct
26 Correct 412 ms 125664 KB Output is correct
27 Correct 443 ms 125676 KB Output is correct
28 Correct 379 ms 125776 KB Output is correct
29 Correct 377 ms 125664 KB Output is correct
30 Correct 446 ms 125792 KB Output is correct
31 Correct 358 ms 125672 KB Output is correct
32 Correct 445 ms 125760 KB Output is correct
33 Correct 424 ms 125900 KB Output is correct
34 Correct 393 ms 125752 KB Output is correct
35 Correct 409 ms 125676 KB Output is correct
36 Correct 410 ms 125672 KB Output is correct
37 Correct 401 ms 125672 KB Output is correct
38 Correct 408 ms 125664 KB Output is correct
39 Correct 427 ms 125664 KB Output is correct
40 Correct 418 ms 125644 KB Output is correct
41 Correct 398 ms 125712 KB Output is correct
42 Correct 377 ms 125588 KB Output is correct
43 Correct 425 ms 125684 KB Output is correct
44 Correct 385 ms 125676 KB Output is correct
45 Correct 384 ms 125776 KB Output is correct
46 Correct 366 ms 125640 KB Output is correct
47 Correct 387 ms 125800 KB Output is correct
48 Correct 451 ms 125676 KB Output is correct
49 Correct 434 ms 125672 KB Output is correct
50 Correct 411 ms 125776 KB Output is correct
51 Correct 440 ms 125652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 402 ms 125664 KB Output is correct
2 Correct 477 ms 125656 KB Output is correct
3 Correct 437 ms 125668 KB Output is correct
4 Correct 412 ms 125908 KB Output is correct
5 Correct 421 ms 125668 KB Output is correct
6 Correct 397 ms 125804 KB Output is correct
7 Correct 396 ms 125656 KB Output is correct
8 Correct 408 ms 125832 KB Output is correct
9 Correct 374 ms 125680 KB Output is correct
10 Correct 421 ms 125932 KB Output is correct
11 Correct 309 ms 125684 KB Output is correct
12 Correct 428 ms 125804 KB Output is correct
13 Correct 445 ms 125680 KB Output is correct
14 Correct 415 ms 125676 KB Output is correct
15 Correct 415 ms 125684 KB Output is correct
16 Correct 419 ms 125684 KB Output is correct
17 Correct 407 ms 125644 KB Output is correct
18 Correct 314 ms 125756 KB Output is correct
19 Correct 320 ms 125684 KB Output is correct
20 Correct 330 ms 125764 KB Output is correct
21 Correct 308 ms 125644 KB Output is correct
22 Correct 334 ms 125672 KB Output is correct
23 Correct 385 ms 125648 KB Output is correct
24 Correct 370 ms 125580 KB Output is correct
25 Correct 424 ms 125660 KB Output is correct
26 Correct 412 ms 125664 KB Output is correct
27 Correct 443 ms 125676 KB Output is correct
28 Correct 379 ms 125776 KB Output is correct
29 Correct 377 ms 125664 KB Output is correct
30 Correct 446 ms 125792 KB Output is correct
31 Correct 358 ms 125672 KB Output is correct
32 Correct 445 ms 125760 KB Output is correct
33 Correct 424 ms 125900 KB Output is correct
34 Correct 393 ms 125752 KB Output is correct
35 Correct 409 ms 125676 KB Output is correct
36 Correct 410 ms 125672 KB Output is correct
37 Correct 401 ms 125672 KB Output is correct
38 Correct 408 ms 125664 KB Output is correct
39 Correct 427 ms 125664 KB Output is correct
40 Correct 418 ms 125644 KB Output is correct
41 Correct 398 ms 125712 KB Output is correct
42 Correct 377 ms 125588 KB Output is correct
43 Correct 425 ms 125684 KB Output is correct
44 Correct 385 ms 125676 KB Output is correct
45 Correct 384 ms 125776 KB Output is correct
46 Correct 366 ms 125640 KB Output is correct
47 Correct 387 ms 125800 KB Output is correct
48 Correct 451 ms 125676 KB Output is correct
49 Correct 434 ms 125672 KB Output is correct
50 Correct 411 ms 125776 KB Output is correct
51 Correct 440 ms 125652 KB Output is correct
52 Correct 432 ms 125812 KB Output is correct
53 Correct 417 ms 125676 KB Output is correct
54 Correct 424 ms 125800 KB Output is correct
55 Correct 426 ms 125680 KB Output is correct
56 Correct 448 ms 125772 KB Output is correct
57 Correct 414 ms 125716 KB Output is correct
58 Correct 421 ms 125712 KB Output is correct
59 Correct 428 ms 125712 KB Output is correct
60 Correct 402 ms 125616 KB Output is correct
61 Correct 384 ms 125812 KB Output is correct
62 Correct 436 ms 125688 KB Output is correct
63 Correct 449 ms 125680 KB Output is correct
64 Correct 448 ms 125732 KB Output is correct
65 Correct 326 ms 125744 KB Output is correct
66 Correct 352 ms 125748 KB Output is correct
67 Correct 431 ms 125720 KB Output is correct
68 Correct 464 ms 125720 KB Output is correct
69 Correct 417 ms 125728 KB Output is correct
70 Correct 426 ms 125784 KB Output is correct
71 Correct 437 ms 125708 KB Output is correct
72 Correct 428 ms 125804 KB Output is correct
73 Correct 439 ms 125676 KB Output is correct
74 Correct 411 ms 125804 KB Output is correct
75 Correct 451 ms 125812 KB Output is correct
76 Correct 445 ms 125684 KB Output is correct
77 Correct 428 ms 125752 KB Output is correct
78 Correct 417 ms 125720 KB Output is correct
79 Correct 412 ms 125780 KB Output is correct
80 Correct 436 ms 125688 KB Output is correct
81 Correct 416 ms 125712 KB Output is correct
82 Correct 331 ms 125692 KB Output is correct
83 Correct 324 ms 125764 KB Output is correct
84 Correct 375 ms 125644 KB Output is correct
85 Correct 316 ms 125732 KB Output is correct
86 Correct 338 ms 125712 KB Output is correct
87 Correct 318 ms 125676 KB Output is correct
88 Correct 341 ms 125772 KB Output is correct
89 Correct 331 ms 125612 KB Output is correct
90 Correct 313 ms 125548 KB Output is correct
91 Correct 314 ms 125560 KB Output is correct
92 Correct 318 ms 125772 KB Output is correct
93 Correct 312 ms 125664 KB Output is correct
94 Correct 330 ms 125760 KB Output is correct
95 Correct 314 ms 125680 KB Output is correct
96 Correct 367 ms 125676 KB Output is correct
97 Correct 426 ms 125692 KB Output is correct
98 Correct 417 ms 125696 KB Output is correct
99 Correct 445 ms 125684 KB Output is correct
100 Correct 435 ms 125640 KB Output is correct
101 Correct 436 ms 125688 KB Output is correct
102 Correct 433 ms 125680 KB Output is correct
103 Correct 446 ms 125616 KB Output is correct
104 Correct 449 ms 125684 KB Output is correct
105 Correct 448 ms 125808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 429 ms 125652 KB Output is correct
2 Runtime error 3 ms 468 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 402 ms 125664 KB Output is correct
2 Correct 477 ms 125656 KB Output is correct
3 Correct 437 ms 125668 KB Output is correct
4 Correct 412 ms 125908 KB Output is correct
5 Correct 421 ms 125668 KB Output is correct
6 Correct 397 ms 125804 KB Output is correct
7 Correct 396 ms 125656 KB Output is correct
8 Correct 408 ms 125832 KB Output is correct
9 Correct 374 ms 125680 KB Output is correct
10 Correct 421 ms 125932 KB Output is correct
11 Correct 309 ms 125684 KB Output is correct
12 Correct 428 ms 125804 KB Output is correct
13 Correct 445 ms 125680 KB Output is correct
14 Correct 415 ms 125676 KB Output is correct
15 Correct 415 ms 125684 KB Output is correct
16 Correct 419 ms 125684 KB Output is correct
17 Correct 407 ms 125644 KB Output is correct
18 Correct 314 ms 125756 KB Output is correct
19 Correct 320 ms 125684 KB Output is correct
20 Correct 330 ms 125764 KB Output is correct
21 Correct 308 ms 125644 KB Output is correct
22 Correct 334 ms 125672 KB Output is correct
23 Correct 385 ms 125648 KB Output is correct
24 Correct 370 ms 125580 KB Output is correct
25 Correct 424 ms 125660 KB Output is correct
26 Correct 412 ms 125664 KB Output is correct
27 Correct 443 ms 125676 KB Output is correct
28 Correct 379 ms 125776 KB Output is correct
29 Correct 377 ms 125664 KB Output is correct
30 Correct 446 ms 125792 KB Output is correct
31 Correct 358 ms 125672 KB Output is correct
32 Correct 445 ms 125760 KB Output is correct
33 Correct 424 ms 125900 KB Output is correct
34 Correct 393 ms 125752 KB Output is correct
35 Correct 409 ms 125676 KB Output is correct
36 Correct 410 ms 125672 KB Output is correct
37 Correct 401 ms 125672 KB Output is correct
38 Correct 408 ms 125664 KB Output is correct
39 Correct 427 ms 125664 KB Output is correct
40 Correct 418 ms 125644 KB Output is correct
41 Correct 398 ms 125712 KB Output is correct
42 Correct 377 ms 125588 KB Output is correct
43 Correct 425 ms 125684 KB Output is correct
44 Correct 385 ms 125676 KB Output is correct
45 Correct 384 ms 125776 KB Output is correct
46 Correct 366 ms 125640 KB Output is correct
47 Correct 387 ms 125800 KB Output is correct
48 Correct 451 ms 125676 KB Output is correct
49 Correct 434 ms 125672 KB Output is correct
50 Correct 411 ms 125776 KB Output is correct
51 Correct 440 ms 125652 KB Output is correct
52 Correct 432 ms 125812 KB Output is correct
53 Correct 417 ms 125676 KB Output is correct
54 Correct 424 ms 125800 KB Output is correct
55 Correct 426 ms 125680 KB Output is correct
56 Correct 448 ms 125772 KB Output is correct
57 Correct 414 ms 125716 KB Output is correct
58 Correct 421 ms 125712 KB Output is correct
59 Correct 428 ms 125712 KB Output is correct
60 Correct 402 ms 125616 KB Output is correct
61 Correct 384 ms 125812 KB Output is correct
62 Correct 436 ms 125688 KB Output is correct
63 Correct 449 ms 125680 KB Output is correct
64 Correct 448 ms 125732 KB Output is correct
65 Correct 326 ms 125744 KB Output is correct
66 Correct 352 ms 125748 KB Output is correct
67 Correct 431 ms 125720 KB Output is correct
68 Correct 464 ms 125720 KB Output is correct
69 Correct 417 ms 125728 KB Output is correct
70 Correct 426 ms 125784 KB Output is correct
71 Correct 437 ms 125708 KB Output is correct
72 Correct 428 ms 125804 KB Output is correct
73 Correct 439 ms 125676 KB Output is correct
74 Correct 411 ms 125804 KB Output is correct
75 Correct 451 ms 125812 KB Output is correct
76 Correct 445 ms 125684 KB Output is correct
77 Correct 428 ms 125752 KB Output is correct
78 Correct 417 ms 125720 KB Output is correct
79 Correct 412 ms 125780 KB Output is correct
80 Correct 436 ms 125688 KB Output is correct
81 Correct 416 ms 125712 KB Output is correct
82 Correct 331 ms 125692 KB Output is correct
83 Correct 324 ms 125764 KB Output is correct
84 Correct 375 ms 125644 KB Output is correct
85 Correct 316 ms 125732 KB Output is correct
86 Correct 338 ms 125712 KB Output is correct
87 Correct 318 ms 125676 KB Output is correct
88 Correct 341 ms 125772 KB Output is correct
89 Correct 331 ms 125612 KB Output is correct
90 Correct 313 ms 125548 KB Output is correct
91 Correct 314 ms 125560 KB Output is correct
92 Correct 318 ms 125772 KB Output is correct
93 Correct 312 ms 125664 KB Output is correct
94 Correct 330 ms 125760 KB Output is correct
95 Correct 314 ms 125680 KB Output is correct
96 Correct 367 ms 125676 KB Output is correct
97 Correct 426 ms 125692 KB Output is correct
98 Correct 417 ms 125696 KB Output is correct
99 Correct 445 ms 125684 KB Output is correct
100 Correct 435 ms 125640 KB Output is correct
101 Correct 436 ms 125688 KB Output is correct
102 Correct 433 ms 125680 KB Output is correct
103 Correct 446 ms 125616 KB Output is correct
104 Correct 449 ms 125684 KB Output is correct
105 Correct 448 ms 125808 KB Output is correct
106 Correct 429 ms 125652 KB Output is correct
107 Runtime error 3 ms 468 KB Execution killed with signal 11
108 Halted 0 ms 0 KB -