-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QOJ: The 3rd Universal Cup. Stage 5: Moscow
- Loading branch information
Showing
3 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* @file 9135.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-09-03 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
|
||
#define maxn 505 | ||
|
||
typedef pair<int, int> pii; | ||
typedef pair<int64_t, int> pli; | ||
|
||
int64_t a[maxn], f[maxn][maxn]; | ||
vector<pii> graph[maxn]; | ||
bool vis[maxn]; | ||
|
||
void solve(void) { | ||
int n; | ||
cin >> n; | ||
for (int i = 1; i <= n; i++) cin >> a[i]; | ||
|
||
for (int len = 2; len <= n; len++) { | ||
priority_queue<pli, vector<pli>, greater<pli>> que; | ||
for (int i = 1; i <= n; i++) graph[i].clear(), vis[i] = false; | ||
|
||
for (int l = 1, r = len; r <= n; l++, r++) { | ||
f[l][r] = 1e18; | ||
for (int c = 1; c <= n; c++) { | ||
int clen = min(c - 1, n - c), cl = c - clen, cr = c + clen; | ||
|
||
auto rev = [&](int p) { return p + (c - p) * 2; }; | ||
|
||
int pl = rev(r), pr = rev(l); | ||
if (1 <= pl && pr <= n) graph[pl].emplace_back(l, a[c]); | ||
|
||
if (cl == 1) { | ||
if (cr >= r || cr < l) continue; | ||
f[l][r] = min(f[l][r], max(f[rev(cr)][rev(l)], f[cr + 1][r]) + a[c]); | ||
} else { | ||
if (cl <= l || cl > r) continue; | ||
f[l][r] = min(f[l][r], max(f[rev(r)][rev(cl)], f[l][cl - 1]) + a[c]); | ||
} | ||
} | ||
que.emplace(f[l][r], l); | ||
} | ||
while (!que.empty()) { | ||
int p = que.top().second; | ||
que.pop(); | ||
if (vis[p]) continue; | ||
vis[p] = true; | ||
for (auto [i, d] : graph[p]) | ||
if (f[i][i + len - 1] > f[p][p + len - 1] + d) que.emplace(f[i][i + len - 1] = f[p][p + len - 1] + d, i); | ||
} | ||
} | ||
|
||
cout << f[1][n] << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int _ = 1; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* @file 9136.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-09-03 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
void solve(void) { | ||
int n = 4, k = 2048; | ||
cout << 25 << endl; | ||
cout << "$0 = $1 * " << fixed << 1. / k << endl; | ||
for (int i = 1; i <= n; i++) cout << "$" << i << " = $0 * $" << i - 1 << endl; | ||
for (int i = 1; i <= n; i++) { | ||
double frac = 1; | ||
for (int j = 1; j <= i + 1; j++) frac /= j; | ||
cout << "$" << i << " = $" << i << " * " << fixed << frac << endl; | ||
} | ||
cout << "$0 = $0 + 1" << endl; | ||
for (int i = 1; i <= n; i++) cout << "$0 = $0 + $" << i << endl; | ||
for (int i = 2; i <= k; i *= 2) cout << "$0 = $0 * $0" << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
cout << setprecision(15); | ||
solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @file 9142.cpp | ||
* @author Macesuted (i@macesuted.moe) | ||
* @date 2024-09-03 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
|
||
#define maxn 200005 | ||
|
||
int a[maxn]; | ||
|
||
void solve(void) { | ||
int n; | ||
cin >> n; | ||
for (int i = 1; i <= n; i++) cin >> a[i]; | ||
int64_t sum = 0; | ||
sort(a + 1, a + n + 1); | ||
for (int i = 1; i < n; i++) sum += a[i]; | ||
cout << sum << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int _ = 1; | ||
cin >> _; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |