Submission #971592

# Submission time Handle Problem Language Result Execution time Memory
971592 2024-04-29T03:40:50 Z Cookie Double Attendance (CCO22_day1problem3) C++14
21 / 25
67 ms 63568 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod =1e9 + 7, pr = 31;
const int mxn = 1e6 + 5, mxq = 1e5 + 5, sq = 500, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e9 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
int n1, n2, t;
void comb(pii &a, pii b){
    if(a.fi < b.fi)a = b;
    if(a.fi == b.fi && a.se > b.se)a = b;
}
pii dp[2005][2005][2], one[2005], two[2005];
void solve(){
    cin >> n1 >> n2 >> t;
    for(int i = 1; i <= n1; i++){
        cin >> one[i].fi >> one[i].se;
    }
    sort(one + 1, one + n1 + 1);
    for(int i = 1; i <= n2; i++){
        cin >> two[i].fi >> two[i].se;
    }
    sort(two + 1, two + n2 + 1);
    for(int i = 0; i <= n1; i++){
        for(int j = 0; j <= n2; j++){
            dp[i][j][0] = dp[i][j][1] = mpp(-inf, inf);
        }
    }
    dp[0][0][0] = mpp(0, 0);
    int ans = 0;
    for(int i = 0; i <= n1; i++){
        for(int j = 0; j <= n2; j++){
            for(int k = 0; k < 2; k++){
                if(dp[i][j][k].fi == -inf)continue;
                if(k == 0){
                    if(i < n1){
                        assert(dp[i][j][k].se <= one[i + 1].fi);
                        comb(dp[i + 1][j][0], mpp(dp[i][j][k].fi + 1, one[i + 1].fi));
                    }if(j < n2){
                        comb(dp[i][j + 1][0], dp[i][j][k]);
                        if(dp[i][j][k].se + t < two[j + 1].se){
                            comb(dp[i][j + 1][1], mpp(dp[i][j][k].fi + 1, max(dp[i][j][k].se + t, two[j + 1].fi)));
                        }
                    }
                }else{
                    if(j < n2){
                        assert(dp[i][j][k].se <= two[j + 1].fi);
                        comb(dp[i][j + 1][1], mpp(dp[i][j][k].fi + 1, two[j + 1].fi));
                    }if(i < n1){
                        comb(dp[i + 1][j][1], dp[i][j][k]);
                        if(dp[i][j][k].se + t < one[i + 1].se){
                            comb(dp[i + 1][j][0], mpp(dp[i][j][k].fi + 1, max(dp[i][j][k].se + t, one[i + 1].fi)));
                        }
                    }
                }
                ans = max(ans, dp[i][j][k].fi);
            }
        }
    }
    
    cout << ans;
}



signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("THREE.inp", "r", stdin);
    //freopen("THREE.out", "w", stdout);
    int tt; tt = 1;
    while(tt--){
        solve();

    }
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2516 KB Output is correct
22 Correct 2 ms 2512 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2420 KB Output is correct
44 Correct 1 ms 2648 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2392 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2516 KB Output is correct
22 Correct 2 ms 2512 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2420 KB Output is correct
44 Correct 1 ms 2648 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2392 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 16 ms 33372 KB Output is correct
59 Correct 13 ms 33372 KB Output is correct
60 Correct 1 ms 2392 KB Output is correct
61 Correct 1 ms 2396 KB Output is correct
62 Correct 1 ms 4444 KB Output is correct
63 Correct 1 ms 4444 KB Output is correct
64 Correct 34 ms 47708 KB Output is correct
65 Correct 33 ms 63312 KB Output is correct
66 Correct 27 ms 63324 KB Output is correct
67 Correct 13 ms 59996 KB Output is correct
68 Correct 15 ms 27224 KB Output is correct
69 Correct 28 ms 47836 KB Output is correct
70 Correct 30 ms 45656 KB Output is correct
71 Correct 9 ms 62040 KB Output is correct
72 Correct 1 ms 2392 KB Output is correct
73 Correct 1 ms 4444 KB Output is correct
74 Correct 1 ms 4440 KB Output is correct
75 Correct 1 ms 4444 KB Output is correct
76 Correct 1 ms 2396 KB Output is correct
77 Correct 8 ms 43612 KB Output is correct
78 Correct 18 ms 45660 KB Output is correct
79 Correct 27 ms 43608 KB Output is correct
80 Correct 29 ms 41564 KB Output is correct
81 Correct 12 ms 21080 KB Output is correct
82 Correct 2 ms 8540 KB Output is correct
83 Correct 20 ms 43760 KB Output is correct
84 Correct 11 ms 53852 KB Output is correct
85 Correct 24 ms 55900 KB Output is correct
86 Correct 6 ms 14940 KB Output is correct
87 Correct 2 ms 6488 KB Output is correct
88 Correct 1 ms 344 KB Output is correct
89 Correct 0 ms 348 KB Output is correct
90 Correct 1 ms 348 KB Output is correct
91 Correct 0 ms 344 KB Output is correct
92 Correct 1 ms 348 KB Output is correct
93 Correct 1 ms 348 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 344 KB Output is correct
96 Correct 0 ms 344 KB Output is correct
97 Correct 3 ms 10588 KB Output is correct
98 Correct 3 ms 10768 KB Output is correct
99 Correct 3 ms 10584 KB Output is correct
100 Correct 2 ms 10588 KB Output is correct
101 Correct 2 ms 10588 KB Output is correct
102 Correct 1 ms 6488 KB Output is correct
103 Correct 1 ms 4444 KB Output is correct
104 Correct 1 ms 348 KB Output is correct
105 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 480 KB Output is correct
3 Correct 38 ms 63276 KB Output is correct
4 Correct 41 ms 63548 KB Output is correct
5 Correct 40 ms 63348 KB Output is correct
6 Correct 45 ms 63324 KB Output is correct
7 Correct 45 ms 63360 KB Output is correct
8 Correct 27 ms 63324 KB Output is correct
9 Correct 29 ms 63320 KB Output is correct
10 Correct 27 ms 63324 KB Output is correct
11 Correct 2 ms 4696 KB Output is correct
12 Correct 21 ms 49752 KB Output is correct
13 Correct 8 ms 59996 KB Output is correct
14 Correct 44 ms 63320 KB Output is correct
15 Correct 48 ms 63528 KB Output is correct
16 Correct 54 ms 63324 KB Output is correct
17 Correct 30 ms 54100 KB Output is correct
18 Correct 7 ms 23132 KB Output is correct
19 Correct 24 ms 43608 KB Output is correct
20 Correct 44 ms 63324 KB Output is correct
21 Correct 45 ms 63320 KB Output is correct
22 Correct 45 ms 63324 KB Output is correct
23 Correct 33 ms 57948 KB Output is correct
24 Correct 3 ms 6744 KB Output is correct
25 Correct 25 ms 43612 KB Output is correct
26 Correct 26 ms 58076 KB Output is correct
27 Correct 3 ms 6748 KB Output is correct
28 Correct 49 ms 63364 KB Output is correct
29 Correct 21 ms 47708 KB Output is correct
30 Correct 11 ms 23196 KB Output is correct
31 Correct 48 ms 63324 KB Output is correct
32 Correct 29 ms 63272 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 344 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 44 ms 63292 KB Output is correct
43 Correct 48 ms 63244 KB Output is correct
44 Correct 48 ms 63568 KB Output is correct
45 Correct 50 ms 63360 KB Output is correct
46 Correct 49 ms 63320 KB Output is correct
47 Correct 7 ms 49752 KB Output is correct
48 Correct 6 ms 53848 KB Output is correct
49 Correct 1 ms 600 KB Output is correct
50 Correct 1 ms 484 KB Output is correct
51 Correct 8 ms 62044 KB Output is correct
52 Correct 8 ms 62004 KB Output is correct
53 Correct 1 ms 480 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 7 ms 62044 KB Output is correct
56 Correct 7 ms 62044 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2516 KB Output is correct
22 Correct 2 ms 2512 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2420 KB Output is correct
44 Correct 1 ms 2648 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2392 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 6492 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 16 ms 33372 KB Output is correct
59 Correct 13 ms 33372 KB Output is correct
60 Correct 1 ms 2392 KB Output is correct
61 Correct 1 ms 2396 KB Output is correct
62 Correct 1 ms 4444 KB Output is correct
63 Correct 1 ms 4444 KB Output is correct
64 Correct 34 ms 47708 KB Output is correct
65 Correct 33 ms 63312 KB Output is correct
66 Correct 27 ms 63324 KB Output is correct
67 Correct 13 ms 59996 KB Output is correct
68 Correct 15 ms 27224 KB Output is correct
69 Correct 28 ms 47836 KB Output is correct
70 Correct 30 ms 45656 KB Output is correct
71 Correct 9 ms 62040 KB Output is correct
72 Correct 1 ms 2392 KB Output is correct
73 Correct 1 ms 4444 KB Output is correct
74 Correct 1 ms 4440 KB Output is correct
75 Correct 1 ms 4444 KB Output is correct
76 Correct 1 ms 2396 KB Output is correct
77 Correct 8 ms 43612 KB Output is correct
78 Correct 18 ms 45660 KB Output is correct
79 Correct 27 ms 43608 KB Output is correct
80 Correct 29 ms 41564 KB Output is correct
81 Correct 12 ms 21080 KB Output is correct
82 Correct 2 ms 8540 KB Output is correct
83 Correct 20 ms 43760 KB Output is correct
84 Correct 11 ms 53852 KB Output is correct
85 Correct 24 ms 55900 KB Output is correct
86 Correct 6 ms 14940 KB Output is correct
87 Correct 2 ms 6488 KB Output is correct
88 Correct 1 ms 344 KB Output is correct
89 Correct 0 ms 348 KB Output is correct
90 Correct 1 ms 348 KB Output is correct
91 Correct 0 ms 344 KB Output is correct
92 Correct 1 ms 348 KB Output is correct
93 Correct 1 ms 348 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 344 KB Output is correct
96 Correct 0 ms 344 KB Output is correct
97 Correct 3 ms 10588 KB Output is correct
98 Correct 3 ms 10768 KB Output is correct
99 Correct 3 ms 10584 KB Output is correct
100 Correct 2 ms 10588 KB Output is correct
101 Correct 2 ms 10588 KB Output is correct
102 Correct 1 ms 6488 KB Output is correct
103 Correct 1 ms 4444 KB Output is correct
104 Correct 1 ms 348 KB Output is correct
105 Correct 0 ms 348 KB Output is correct
106 Correct 0 ms 344 KB Output is correct
107 Correct 1 ms 480 KB Output is correct
108 Correct 38 ms 63276 KB Output is correct
109 Correct 41 ms 63548 KB Output is correct
110 Correct 40 ms 63348 KB Output is correct
111 Correct 45 ms 63324 KB Output is correct
112 Correct 45 ms 63360 KB Output is correct
113 Correct 27 ms 63324 KB Output is correct
114 Correct 29 ms 63320 KB Output is correct
115 Correct 27 ms 63324 KB Output is correct
116 Correct 2 ms 4696 KB Output is correct
117 Correct 21 ms 49752 KB Output is correct
118 Correct 8 ms 59996 KB Output is correct
119 Correct 44 ms 63320 KB Output is correct
120 Correct 48 ms 63528 KB Output is correct
121 Correct 54 ms 63324 KB Output is correct
122 Correct 30 ms 54100 KB Output is correct
123 Correct 7 ms 23132 KB Output is correct
124 Correct 24 ms 43608 KB Output is correct
125 Correct 44 ms 63324 KB Output is correct
126 Correct 45 ms 63320 KB Output is correct
127 Correct 45 ms 63324 KB Output is correct
128 Correct 33 ms 57948 KB Output is correct
129 Correct 3 ms 6744 KB Output is correct
130 Correct 25 ms 43612 KB Output is correct
131 Correct 26 ms 58076 KB Output is correct
132 Correct 3 ms 6748 KB Output is correct
133 Correct 49 ms 63364 KB Output is correct
134 Correct 21 ms 47708 KB Output is correct
135 Correct 11 ms 23196 KB Output is correct
136 Correct 48 ms 63324 KB Output is correct
137 Correct 29 ms 63272 KB Output is correct
138 Correct 1 ms 348 KB Output is correct
139 Correct 0 ms 348 KB Output is correct
140 Correct 0 ms 344 KB Output is correct
141 Correct 0 ms 348 KB Output is correct
142 Correct 0 ms 348 KB Output is correct
143 Correct 0 ms 348 KB Output is correct
144 Correct 1 ms 348 KB Output is correct
145 Correct 0 ms 344 KB Output is correct
146 Correct 0 ms 348 KB Output is correct
147 Correct 44 ms 63292 KB Output is correct
148 Correct 48 ms 63244 KB Output is correct
149 Correct 48 ms 63568 KB Output is correct
150 Correct 50 ms 63360 KB Output is correct
151 Correct 49 ms 63320 KB Output is correct
152 Correct 7 ms 49752 KB Output is correct
153 Correct 6 ms 53848 KB Output is correct
154 Correct 1 ms 600 KB Output is correct
155 Correct 1 ms 484 KB Output is correct
156 Correct 8 ms 62044 KB Output is correct
157 Correct 8 ms 62004 KB Output is correct
158 Correct 1 ms 480 KB Output is correct
159 Correct 1 ms 348 KB Output is correct
160 Correct 7 ms 62044 KB Output is correct
161 Correct 7 ms 62044 KB Output is correct
162 Correct 1 ms 604 KB Output is correct
163 Correct 1 ms 604 KB Output is correct
164 Correct 0 ms 348 KB Output is correct
165 Runtime error 67 ms 17140 KB Execution killed with signal 6
166 Halted 0 ms 0 KB -