#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 13, T = 205;
int dp[1<<N][N][T], x[N], t[N], ans = 0;
signed main(){
fastio
int n,l;
cin >> n >> l;
for(int i = 0;i < n;i++){
cin >> x[i];
}
for(int i = 0;i < n;i++){
cin >> t[i];
}
for(int mask = 0; mask < (1<<n); mask++){
for(int i = 0;i < n;i++){
for(int tt = 0; tt < T;tt++){
dp[mask][i][tt] = -1e18;
}
}
}
for(int i = 0;i < n;i++){
int tmp = min(x[i],(0-x[i]+l)%l);
dp[(1<<i)][i][tmp] = (tmp <= t[i]);
ans = max(ans,dp[(1<<i)][i][tmp]);
}
for(int mask = 0;mask < (1<<n);mask++){
for(int i = 0;i < n;i++){
if(mask&(1<<i)){
for(int j = 0;j < n;j++){
if(!(mask&(1<<j))){
for(int tt = 0; tt < T; tt++){
int tmp = min((x[j]-x[i]+l)%l,(x[i]-x[j]+l)%l);
if(tt+tmp < T){
dp[mask^(1<<j)][j][tt+tmp] = max(dp[mask^(1<<j)][j][tt+tmp],dp[mask][i][tt]+(tt+tmp <= t[j]));
ans = max(dp[mask^(1<<j)][j][tt+tmp],ans);
}
}
}
}
}
}
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
9 ms |
9764 KB |
Output is correct |
4 |
Correct |
2 ms |
1108 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
102 ms |
85768 KB |
Output is correct |
7 |
Correct |
3 ms |
4564 KB |
Output is correct |
8 |
Correct |
19 ms |
20820 KB |
Output is correct |
9 |
Correct |
94 ms |
85656 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
91 ms |
85756 KB |
Output is correct |
13 |
Correct |
91 ms |
85828 KB |
Output is correct |
14 |
Correct |
2 ms |
2260 KB |
Output is correct |
15 |
Correct |
5 ms |
4564 KB |
Output is correct |
16 |
Correct |
104 ms |
85752 KB |
Output is correct |
17 |
Correct |
100 ms |
85748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
9 ms |
9764 KB |
Output is correct |
4 |
Correct |
2 ms |
1108 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
102 ms |
85768 KB |
Output is correct |
7 |
Correct |
3 ms |
4564 KB |
Output is correct |
8 |
Correct |
19 ms |
20820 KB |
Output is correct |
9 |
Correct |
94 ms |
85656 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
91 ms |
85756 KB |
Output is correct |
13 |
Correct |
91 ms |
85828 KB |
Output is correct |
14 |
Correct |
2 ms |
2260 KB |
Output is correct |
15 |
Correct |
5 ms |
4564 KB |
Output is correct |
16 |
Correct |
104 ms |
85752 KB |
Output is correct |
17 |
Correct |
100 ms |
85748 KB |
Output is correct |
18 |
Runtime error |
359 ms |
346904 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
9 ms |
9764 KB |
Output is correct |
4 |
Correct |
2 ms |
1108 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
102 ms |
85768 KB |
Output is correct |
7 |
Correct |
3 ms |
4564 KB |
Output is correct |
8 |
Correct |
19 ms |
20820 KB |
Output is correct |
9 |
Correct |
94 ms |
85656 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
91 ms |
85756 KB |
Output is correct |
13 |
Correct |
91 ms |
85828 KB |
Output is correct |
14 |
Correct |
2 ms |
2260 KB |
Output is correct |
15 |
Correct |
5 ms |
4564 KB |
Output is correct |
16 |
Correct |
104 ms |
85752 KB |
Output is correct |
17 |
Correct |
100 ms |
85748 KB |
Output is correct |
18 |
Runtime error |
371 ms |
346828 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
9 ms |
9764 KB |
Output is correct |
4 |
Correct |
2 ms |
1108 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
102 ms |
85768 KB |
Output is correct |
7 |
Correct |
3 ms |
4564 KB |
Output is correct |
8 |
Correct |
19 ms |
20820 KB |
Output is correct |
9 |
Correct |
94 ms |
85656 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
91 ms |
85756 KB |
Output is correct |
13 |
Correct |
91 ms |
85828 KB |
Output is correct |
14 |
Correct |
2 ms |
2260 KB |
Output is correct |
15 |
Correct |
5 ms |
4564 KB |
Output is correct |
16 |
Correct |
104 ms |
85752 KB |
Output is correct |
17 |
Correct |
100 ms |
85748 KB |
Output is correct |
18 |
Runtime error |
359 ms |
346904 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |