답안 #745676

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745676 2023-05-21T00:41:52 Z 반딧불(#9962) Double Attendance (CCO22_day1problem3) C++17
6 / 25
9 ms 9920 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n[2], k;
pair<ll, ll> arr[2][300002];
ll DP[2][600002];
int ans;

inline ll nxtStart(int d, ll t, bool diff){
    int it = upper_bound(arr[d]+1, arr[d]+n[d]+1, make_pair(t, LLONG_MAX)) - arr[d];
    if(diff) if(it != 1 && arr[d][it-1].second > t) it--;
    if(it == n[d]+1) return 1e18;
    return max(t, arr[d][it].first);
}

int main(){
    scanf("%d %d %d", &n[0], &n[1], &k);
    for(int d=0; d<=1; d++){
        for(int i=1; i<=n[d]; i++) scanf("%lld %lld", &arr[d][i].first, &arr[d][i].second);
        sort(arr[d]+1, arr[d]+n[d]+1);
    }
    for(int i=0; i<=1; i++) for(int j=0; j<=600000; j++) DP[i][j] = 1e18;
    DP[0][(arr[0][1].first == 0 ? 1 : 0)] = 0;
    for(int i=1; i<=n[0]+n[1]; i++){
        /// �������� ��������
        for(int s=0; s<2; s++){
            for(int e=0; e<2; e++){
                if(s==e) DP[e][i] = min(DP[e][i], nxtStart(e, DP[e][i-1], 0));
                else     DP[e][i] = min(DP[e][i], nxtStart(e, DP[s][i-1]+k, 1));
            }
        }
        /// ����� ����
        for(int s=0; s<2; s++){
            int e = !s;
            DP[e][i] = min(DP[e][i], nxtStart(e, DP[s][i]+k, 1));
        }
//        printf("%d: (%lld, %lld)\n", i, DP[0][i], DP[1][i]);
    }
    for(int i=0; i<=n[0]+n[1]; i++) if(DP[0][i] < 1e18 || DP[1][i] < 1e18) ans = i;
    printf("%d", ans);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d %d %d", &n[0], &n[1], &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:22:41: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         for(int i=1; i<=n[d]; i++) scanf("%lld %lld", &arr[d][i].first, &arr[d][i].second);
      |                                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9660 KB Output is correct
3 Incorrect 5 ms 9684 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9660 KB Output is correct
3 Incorrect 5 ms 9684 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9656 KB Output is correct
2 Correct 5 ms 9664 KB Output is correct
3 Correct 7 ms 9920 KB Output is correct
4 Correct 7 ms 9812 KB Output is correct
5 Correct 6 ms 9812 KB Output is correct
6 Correct 8 ms 9812 KB Output is correct
7 Correct 6 ms 9744 KB Output is correct
8 Correct 6 ms 9796 KB Output is correct
9 Correct 6 ms 9812 KB Output is correct
10 Correct 6 ms 9796 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 7 ms 9668 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 7 ms 9812 KB Output is correct
15 Correct 7 ms 9844 KB Output is correct
16 Correct 9 ms 9796 KB Output is correct
17 Correct 7 ms 9788 KB Output is correct
18 Correct 8 ms 9684 KB Output is correct
19 Correct 6 ms 9664 KB Output is correct
20 Correct 8 ms 9812 KB Output is correct
21 Correct 7 ms 9812 KB Output is correct
22 Correct 7 ms 9812 KB Output is correct
23 Correct 7 ms 9660 KB Output is correct
24 Correct 5 ms 9664 KB Output is correct
25 Correct 6 ms 9684 KB Output is correct
26 Correct 7 ms 9812 KB Output is correct
27 Correct 6 ms 9684 KB Output is correct
28 Correct 9 ms 9812 KB Output is correct
29 Correct 7 ms 9792 KB Output is correct
30 Correct 6 ms 9684 KB Output is correct
31 Correct 7 ms 9812 KB Output is correct
32 Correct 6 ms 9812 KB Output is correct
33 Correct 5 ms 9684 KB Output is correct
34 Correct 4 ms 9656 KB Output is correct
35 Correct 5 ms 9656 KB Output is correct
36 Correct 4 ms 9656 KB Output is correct
37 Correct 6 ms 9684 KB Output is correct
38 Correct 5 ms 9684 KB Output is correct
39 Correct 6 ms 9684 KB Output is correct
40 Correct 5 ms 9656 KB Output is correct
41 Correct 5 ms 9684 KB Output is correct
42 Correct 8 ms 9812 KB Output is correct
43 Correct 7 ms 9852 KB Output is correct
44 Correct 8 ms 9792 KB Output is correct
45 Correct 7 ms 9744 KB Output is correct
46 Correct 7 ms 9812 KB Output is correct
47 Correct 6 ms 9684 KB Output is correct
48 Correct 5 ms 9672 KB Output is correct
49 Correct 5 ms 9672 KB Output is correct
50 Correct 5 ms 9684 KB Output is correct
51 Correct 6 ms 9684 KB Output is correct
52 Correct 5 ms 9684 KB Output is correct
53 Correct 5 ms 9676 KB Output is correct
54 Correct 6 ms 9668 KB Output is correct
55 Correct 6 ms 9684 KB Output is correct
56 Correct 5 ms 9664 KB Output is correct
57 Correct 5 ms 9684 KB Output is correct
58 Correct 6 ms 9712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9660 KB Output is correct
3 Incorrect 5 ms 9684 KB Output isn't correct
4 Halted 0 ms 0 KB -