# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
411158 |
2021-05-24T12:36:11 Z |
송준혁(#7506) |
JOI15_keys (JOI15_keys) |
C++14 |
|
1 ms |
384 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define MOD 1000000007
#define INF (1ll<<62)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int N, M, K, sum;
int P[2020], ans[2020], B[2][2020], D[2][2020];
bool chk[2020];
pii A[4040], nx[2020];
int main(){
scanf("%d %d %d", &N, &M, &K);
for (int i=1; i<=N; i++){
scanf("%d %d", &A[i*2-1].fi, &A[i*2].fi);
A[i*2-1].se = i, A[i*2].se = -i;
}
sort(A+1, A+2*N+1);
sum += A[1].fi + M - A[2*N].fi;
for (int i=2; i<=2*N; i++){
if (A[i-1].se > 0){
if (A[i].se > 0) P[A[i-1].se] += A[i].fi-A[i-1].fi;
else{
if (A[i-1].se == -A[i].se) P[-A[i].se] += A[i].fi-A[i-1].fi;
else{
chk[-A[i].se] = true;
nx[A[i-1].se] = pii(-A[i].se, A[i].fi-A[i-1].fi);
}
}
}
else{
if (A[i].se > 0) sum += A[i].fi-A[i-1].fi;
else P[-A[i].se] += A[i].fi-A[i-1].fi;
}
}
int n=0;
for (int i=1; i<=N; i++){
if (chk[i]) continue;
int t=1, u=i;
for (; nx[u].fi; t++, u=nx[u].fi);
for (int j=0; j<=t+5; j++) D[0][j]=D[1][j]=0;
D[1][1] = P[i], D[1][0] = -MOD;
for (t=1, u=i; nx[u].fi; t++, u=nx[u].fi){
for (int j=1; j<=t+1; j++){
if (j <= t) B[0][j] = max(D[0][j], D[1][j]);
else B[0][j] = 0;
B[1][j] = max(D[0][j-1] + P[nx[u].fi], D[1][j-1] + P[nx[u].fi] + nx[u].se);
}
for (int j=1; j<=t+1; j++) D[0][j] = B[0][j], D[1][j] = B[1][j];
}
for (int j=0; j<=n+t; j++) B[0][j] = 0;
for (int j=0; j<=n; j++) for (int k=0; k<=t; k++){
B[0][j+k] = max(B[0][j+k], ans[j] + max(D[0][k], D[1][k]));
}
n += t;
for (int j=0; j<=n; j++) ans[j] = B[0][j];
}
printf("%d\n", sum + ans[K]);
return 0;
}
Compilation message
keys.cpp: In function 'int main()':
keys.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d %d %d", &N, &M, &K);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
keys.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | scanf("%d %d", &A[i*2-1].fi, &A[i*2].fi);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
300 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |