제출 #687477

#제출 시각아이디문제언어결과실행 시간메모리
687477CDuongCollecting Stamps 3 (JOI20_ho_t3)C++17
15 / 100
107 ms135220 KiB
/* #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt") */ #include <bits/stdc++.h> #define taskname "" #define all(x) x.begin(), x.end() #define int long long #define ll long long #define ld long double #define pb push_back #define ff first #define ss second #define pii pair<int, int> #define vi vector<int> using namespace std; const int mxN = 1e5 + 5; const int mod = 1e9 + 7; const int lim = 1e9; const ll oo = 1e18; int n, l, ans; int dp[205][205][205][2]; void solve() { cin >> n >> l; int x[n + 1], t[n + 1]; x[0] = t[0] = 0; for(int i = 1; i <= n; ++i) cin >> x[i]; for(int i = 1; i <= n; ++i) cin >> t[i]; auto dis = [&](int idx_1, int idx_2) { int tmp = abs(x[idx_1] - x[idx_2]); return min(tmp, l - tmp); }; auto calc_dis = [&](int idx_1, int idx_2) { int tmp_1 = l - x[idx_1], tmp_2 = x[idx_2]; int res = tmp_1 + tmp_2 + min(tmp_1, tmp_2); if(res > lim) return (ll)-1; return res; }; memset(dp, -1, sizeof dp); dp[0][0][0][0] = dp[0][0][0][2] = 0; for(int i = n; i > 0; --i) { for(int j = 0; j < i; ++j) { int tmp_1 = l - x[i], tmp_2 = x[j]; int res = tmp_1 + tmp_2; dp[0][i][j][0] = res + tmp_1; dp[0][i][j][1] = res + tmp_2; // cout << 0 << " " << i << " " << j << " " << 0 << " " << dp[0][i][j][0] << endl; // cout << 0 << " " << i << " " << j << " " << 1 << " " << dp[0][i][j][1] << endl; } } // cout << endl; auto calc_dp = [&](int i, int st, int en, bool point) { int cur_dp = INT_MAX; if(point) { int pre_en = (en + n) % (n + 1); if(dp[i][st][pre_en][point] != -1) cur_dp = min(cur_dp, dp[i][st][pre_en][point] + dis(pre_en, en)); if(dp[i][st][pre_en][!point] != -1) cur_dp = min(cur_dp, dp[i][st][pre_en][!point] + dis(st, en)); if(dp[i - 1][st][pre_en][point] != -1) { int new_time = dp[i - 1][st][pre_en][point] + dis(pre_en, en); if(new_time <= t[en]) cur_dp = min(cur_dp, new_time); } if(dp[i - 1][st][pre_en][!point] != -1) { int new_time = dp[i - 1][st][pre_en][!point] + dis(st, en); if(new_time <= t[en]) cur_dp = min(cur_dp, new_time); } if(cur_dp > lim) cur_dp = -1; dp[i][st][en][point] = cur_dp; } else { int nxt_st = (st + 1) % (n + 1); if(dp[i][nxt_st][en][point] != -1) cur_dp = min(cur_dp, dp[i][nxt_st][en][point] + dis(st, nxt_st)); if(dp[i][nxt_st][en][!point] != -1) cur_dp = min(cur_dp, dp[i][nxt_st][en][!point] + dis(st, en)); if(dp[i - 1][nxt_st][en][point] != -1) { int new_time = dp[i - 1][nxt_st][en][point] + dis(st, nxt_st); if(new_time <= t[st]) cur_dp = min(cur_dp, new_time); } if(dp[i - 1][nxt_st][en][!point] != -1) { int new_time = dp[i - 1][nxt_st][en][!point] + dis(st, en); if(new_time <= t[st]) cur_dp = min(cur_dp, new_time); } if(cur_dp > lim) cur_dp = -1; dp[i][st][en][point] = cur_dp; } if(cur_dp != -1) return i; else return (ll)-1; }; for(int i = 1; i <= n; ++i) { for(int len = i; len <= n; ++len) { for(int en = 0; en <= len; ++en) { int st = en - len; if(st < 0) st += n + 1; for(int point = 0; point <= 1; ++point) { ans = max(ans, calc_dp(i, st, en, point)); // cout << i << " " << st << " " << en << " " << point << " " << dp[i][st][en][point] << endl; } } } // cout << endl; } cout << ans << endl; } signed main() { #ifndef CDuongg if(fopen(taskname".inp", "r")) assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout)); #else freopen("bai3.inp", "r", stdin); freopen("bai3.out", "w", stdout); auto start = chrono::high_resolution_clock::now(); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; //cin >> t; while(t--) solve(); #ifdef CDuongg auto end = chrono::high_resolution_clock::now(); cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '='; cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl; #endif }

컴파일 시 표준 에러 (stderr) 메시지

ho_t3.cpp: In function 'void solve()':
ho_t3.cpp:41:10: warning: variable 'calc_dis' set but not used [-Wunused-but-set-variable]
   41 |     auto calc_dis = [&](int idx_1, int idx_2) {
      |          ^~~~~~~~
ho_t3.cpp:50:35: warning: array subscript 2 is above array bounds of 'long long int [2]' [-Warray-bounds]
   50 |     dp[0][0][0][0] = dp[0][0][0][2] = 0;
      |                      ~~~~~~~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...