#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 = 16;
int dp[1<<N][N][N], x[N], t[N], ans = 0;
//mask, at, taken, dp[i][j][k] => time
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 j = 0;j <= n;j++){
dp[mask][i][j] = 1e18;
}
}
}
for(int i = 0;i < n;i++){
int tmp = min(x[i],(0-x[i]+l)%l);
int take = (tmp <= t[i]);
dp[(1<<i)][i][take] = 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 take = 0;take <= n;take++){
if(dp[mask][i][take]==1e18) continue;
int tmp = min((x[j]-x[i]+l)%l,(x[i]-x[j]+l)%l);
int tt = dp[mask][i][take]+tmp;
dp[mask^(1<<j)][j][take+(tt<=t[j])] = tt;
}
}
}
}
}
}
int ans = 0;
for(int mask = 0;mask < (1<<n);mask++){
for(int i = 0;i < n;i++){
for(int j = 0;j <= n;j++){
if(dp[mask][i][j]!=1e18){
ans = max(ans,j);
}
}
}
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Incorrect |
16 ms |
8512 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Incorrect |
16 ms |
8512 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Incorrect |
16 ms |
8512 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
1236 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Incorrect |
16 ms |
8512 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |