Submission #915108

# Submission time Handle Problem Language Result Execution time Memory
915108 2024-01-23T11:03:58 Z mychecksedad Collecting Stamps 3 (JOI20_ho_t3) C++17
0 / 100
1 ms 348 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 200+100, M = 1e5+10, K = 52, MX = 30;


int n;
ll L;
array<ll, 2> dp[N][N][2], a[N];
void solve(){
  cin >> n >> L;
  for(int i = 1; i <= n; ++i) cin >> a[i][0];
  for(int i = 1; i <= n; ++i) cin >> a[i][1];
  sort(a+1, a+1+n);
  for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j) dp[i][j][0] = dp[i][j][1] = {(ll)1e18, 0ll};
  dp[0][0][0] = {0, 0};
  dp[0][0][1] = {0, 0};
  a[0] = {0, 0};
  a[n + 1] = {L, 0};
  for(int i = 0; i <= n; ++i){
    for(int j = 0; j <= n-i; ++j){
      if(i == 0){
        if(j == 0) continue;
        dp[i][j][1][0] = dp[i][j - 1][1][0] + abs(a[n - j + 1][0] - a[n - j + 2][0]);
        dp[i][j][1][1] = dp[i][j - 1][1][1] + (dp[i][j][1][0] <= a[n - j + 1][1]); 
      }else if(j == 0){
        dp[i][j][0][0] = dp[i - 1][j][0][0] + abs(a[i][0] - a[i - 1][0]);
        dp[i][j][0][1] = dp[i - 1][j][0][1] + (dp[i][j][0][0] <= a[i][1]); 
      }else{
        if(dp[i - 1][j][0][0] + abs(a[i][0] - a[i - 1][0]) < dp[i - 1][j][1][0] + abs(a[i][0] + L - a[n - j + 1][0])){
          dp[i][j][0][0] = dp[i - 1][j][0][0] + abs(a[i][0] - a[i - 1][0]);
          dp[i][j][0][1] = dp[i - 1][j][0][1] + (dp[i][j][0][0] <= a[i][1]);
        }else{
          dp[i][j][0][0] = dp[i - 1][j][1][0] + abs(a[i][0] + L - a[n - j + 2][0]);
          dp[i][j][0][1] = max(dp[i - 1][j][1][1], dp[i - 1][j][0][1]) + (dp[i][j][0][0] <= a[i][1]);
        }
        if(dp[i][j - 1][1][0] + abs(a[n - j + 1][0] - a[n - j + 2][0]) < dp[i][j - 1][0][0] + abs(a[n - j + 1][0] + L - a[i][0])){
          dp[i][j][1][0] = dp[i][j - 1][1][0] + abs(a[n - j + 1][0] - a[n - j + 2][0]);
          dp[i][j][1][1] = dp[i][j - 1][1][1] + (dp[i][j][1][0] <= a[n - j + 1][1]);
        }else{
          dp[i][j][1][0] = dp[i][j - 1][0][0] + abs(a[n - j + 1][0] + L - a[i][0]);
          dp[i][j][1][1] = max(dp[i][j - 1][1][1], dp[i][j - 1][0][1]) + (dp[i][j][1][0] <= a[i][n - j + 1]);
        }
      }
      // cout << i << ' ' << j << ' ' << dp[i][j][0][0] << ' ' << dp[i][j][0][1] << ' ' << dp[i][j][1][0] << ' ' << dp[i][j][1][1] << '\n';
    }
    // en;
  }
  ll ans = 0;
  for(int i = 0; i <= n; ++i) ans = max({ans, dp[i][n-i][0][1], dp[i][n-i][1][1]});
  cout << ans;
}



int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // cin >> tt;
  while(tt--){
    solve();
    // en;
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:64:15: warning: unused variable 'aa' [-Wunused-variable]
   64 |   int tt = 1, aa;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -