Submission #1081735

#TimeUsernameProblemLanguageResultExecution timeMemory
1081735Boas봉쇄 시간 (IOI23_closing)C++17
0 / 100
1055 ms11848 KiB
#include "closing.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <typename T1, typename T2> using indexed_map = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long #define pb push_back #define loop(x, i) for (int i = 0; i < x; i++) #define ALL(x) begin(x), end(x) typedef pair<int, int> ii; typedef signed i32; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<i32> vi32; typedef vector<bool> vb; typedef vector<vi> vvi; typedef vector<vii> vvii; i32 max_score(i32 N, i32 X, i32 Y, int K, vi32 U, vi32 V, vi32 W) { vi pSum = {0}; vi pSum2 = {0}; loop(N - 1, i) { pSum.pb(pSum.back() + W[i]); pSum2.pb(pSum2.back() + pSum.back()); } int mid = X; // last node for which X is closest for (int i = X; i <= Y; i++) { if (pSum[i] - pSum[X] <= pSum[Y] - pSum[i]) { mid = i; } } auto sumDis = [&](int l, int r) { if (r < l) swap(l, r); int minCount = (r * (r - 1)) / 2 - (l * (l - 1)) / 2; int dis = pSum2[r] - pSum2[l] - minCount * pSum[l]; return dis; }; int res = 0; for (int lx = 0; lx <= X; lx++) { for (int rx = X; rx < N; rx++) { for (int ly = 0; ly <= Y; ly++) { for (int ry = Y; ry < N; ry++) { int dis = sumDis(lx, X) + sumDis(Y, ry); if (ly < rx) { dis += sumDis(Y, ly); dis += sumDis(Y, rx + 1); dis -= sumDis(Y, mid); dis += sumDis(X, rx); dis += sumDis(X, ly - 1); dis -= sumDis(X, mid); } if (dis <= K) { int cnt = (rx - lx + 1) + (ry - ly + 1); res = max(res, cnt); } } } } } /*for (int both = 0; both < N; both++) { int best = 0, bestDis = INT_MAX; for (int i = X; i <= Y; i++) { int dis = sumDis(X, i) + sumDis(i, Y); if (dis < bestDis) { best = i; bestDis = dis; } } }*/ return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...