This repository has been archived by the owner on Jan 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 05e828f
Showing
20 changed files
with
786 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,40 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
|
||
const ll INF = 1e17; | ||
const int N = 10010; | ||
const int M = 10010; | ||
const int K = 1010; | ||
|
||
ll A[N], dp[K][N]; | ||
|
||
int main() | ||
{ | ||
int n, k, m; | ||
scanf("%d%d%d", &n, &k, &m); | ||
|
||
ll tt = 0; | ||
for (int i = 1; i <= n; ++i) { | ||
scanf("%lld", &A[i]); | ||
tt += A[i]; | ||
} | ||
|
||
for (int i = 1; i <= k; ++i) { | ||
dp[i][0] = INF; | ||
for (int j = 1; j <= n; ++j) { | ||
dp[i][j] = dp[i][j-1]; | ||
for (int l = 1; l <= j-m+1; ++l) { | ||
ll sum = 0; | ||
for (int h = l; h <= j; ++h) | ||
sum += A[h]; | ||
dp[i][j] = min(dp[i][j], dp[i-1][max(0, l-2)] + sum); | ||
} | ||
} | ||
} | ||
|
||
printf("%lld\n", tt-dp[k][n]); | ||
|
||
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,35 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
|
||
const ll INF = 1e17; | ||
const int N = 10010; | ||
const int M = 10010; | ||
const int K = 1010; | ||
|
||
ll A[N], qs[N], dp[K][N]; | ||
|
||
int main() | ||
{ | ||
int n, k, m; | ||
scanf("%d%d%d", &n, &k, &m); | ||
|
||
for (int i = 1; i <= n; ++i) { | ||
scanf("%lld", &A[i]); | ||
qs[i] = qs[i-1]+A[i]; | ||
} | ||
|
||
for (int i = 1; i <= k; ++i) { | ||
dp[i][0] = INF; | ||
for (int j = 1; j <= n; ++j) { | ||
dp[i][j] = dp[i][j-1]; | ||
for (int l = 1; l <= j-m+1; ++l) | ||
dp[i][j] = min(dp[i][j], dp[i-1][max(0, l-2)] + qs[j]-qs[l-1]); | ||
} | ||
} | ||
|
||
printf("%lld\n", qs[n]-dp[k][n]); | ||
|
||
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,40 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
|
||
const ll INF = 1e17; | ||
const int N = 10010; | ||
const int M = 10010; | ||
const int K = 1010; | ||
|
||
ll A[N], dp[K][N]; | ||
|
||
int main() | ||
{ | ||
int n, k, m; | ||
scanf("%d%d%d", &n, &k, &m); | ||
|
||
ll tt = 0; | ||
for (int i = 1; i <= n; ++i) { | ||
scanf("%lld", &A[i]); | ||
tt += A[i]; | ||
} | ||
|
||
for (int i = 1; i <= k; ++i) { | ||
dp[i][0] = INF; | ||
for (int j = 1; j <= n; ++j) { | ||
dp[i][j] = dp[i][j-1]; | ||
ll sum = 0; | ||
for (int l = j; l >= 1; --l) { | ||
sum += A[l]; | ||
if (l <= j-m+1) | ||
dp[i][j] = min(dp[i][j], dp[i-1][max(0, l-2)] + sum); | ||
} | ||
} | ||
} | ||
|
||
printf("%lld\n", tt-dp[k][n]); | ||
|
||
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,39 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
|
||
const ll INF = 1e17; | ||
const int N = 10010; | ||
const int M = 10010; | ||
const int K = 1010; | ||
|
||
ll qs[N], dp[K][N], pmin[K][N]; | ||
|
||
int main() | ||
{ | ||
int n, k, m; | ||
scanf("%d%d%d", &n, &k, &m); | ||
|
||
pmin[0][0] = INF; | ||
for (int i = 1; i <= n; ++i) { | ||
scanf("%lld", &qs[i]); | ||
qs[i] += qs[i-1]; | ||
pmin[0][i] = min(pmin[0][i-1], -qs[i-1]); | ||
} | ||
|
||
for (int i = 1; i <= k; ++i) { | ||
dp[i][0] = INF; | ||
pmin[i][0] = INF; | ||
for (int j = 1; j <= n; ++j) { | ||
dp[i][j] = dp[i][j-1]; | ||
if (j-m+1 >= 1) | ||
dp[i][j] = min(dp[i][j], pmin[i-1][j-m+1] + qs[j]); | ||
pmin[i][j] = min(pmin[i][j-1], dp[i][max(j-2, 0)] - qs[j-1]); | ||
} | ||
} | ||
|
||
printf("%lld\n", qs[n]-dp[k][n]); | ||
|
||
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,39 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
|
||
const ll INF = 1e17; | ||
const int N = 10010; | ||
const int M = 10010; | ||
const int K = 1010; | ||
|
||
ll A[N], qs[N], dp[K][N], pmin[K][N]; | ||
|
||
int main() | ||
{ | ||
int n, k, m; | ||
scanf("%d%d%d", &n, &k, &m); | ||
|
||
pmin[0][0] = INF; | ||
for (int i = 1; i <= n; ++i) { | ||
scanf("%lld", &A[i]); | ||
qs[i] = qs[i-1]+A[i]; | ||
pmin[0][i] = min(pmin[0][i-1], -qs[i-1]); | ||
} | ||
|
||
for (int i = 1; i <= k; ++i) { | ||
dp[i][0] = INF; | ||
pmin[i][0] = INF; | ||
for (int j = 1; j <= n; ++j) { | ||
dp[i][j] = dp[i][j-1]; | ||
if (j-m+1 >= 1) | ||
dp[i][j] = min(dp[i][j], pmin[i-1][j-m+1] + qs[j]); | ||
pmin[i][j] = min(pmin[i][j-1], dp[i][max(j-2, 0)] - qs[j-1]); | ||
} | ||
} | ||
|
||
printf("%lld\n", qs[n]-dp[k][n]); | ||
|
||
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,40 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
|
||
const ll INF = 1e17; | ||
const int N = 100010; | ||
const int M = 100010; | ||
const int K = 1010; | ||
|
||
ll A[N], qs[N], dp[2][N], pmin[2][N]; | ||
|
||
int main() | ||
{ | ||
int n, k, m; | ||
scanf("%d%d%d", &n, &k, &m); | ||
|
||
pmin[0][0] = INF; | ||
for (int i = 1; i <= n; ++i) { | ||
scanf("%lld", &A[i]); | ||
qs[i] = qs[i-1]+A[i]; | ||
pmin[0][i] = min(pmin[0][i-1], -qs[i-1]); | ||
} | ||
|
||
for (int i = 1; i <= k; ++i) { | ||
int x = i&1; | ||
dp[x][0] = INF; | ||
pmin[x][0] = INF; | ||
for (int j = 1; j <= n; ++j) { | ||
dp[x][j] = dp[x][j-1]; | ||
if (j-m+1 >= 1) | ||
dp[x][j] = min(dp[x][j], pmin[x^1][j-m+1] + qs[j]); | ||
pmin[x][j] = min(pmin[x][j-1], dp[x][max(j-2, 0)] - qs[j-1]); | ||
} | ||
} | ||
|
||
printf("%lld\n", qs[n]-dp[k&1][n]); | ||
|
||
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,66 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using pii = pair<int, int>; | ||
|
||
const int N = 200010; | ||
const int M = 500010; | ||
|
||
int n, m, p; | ||
bool vis[N]; | ||
int num[N]; | ||
vector<pii> G[N]; | ||
pii P[M]; | ||
|
||
void dfs(int u, int k, int x) | ||
{ | ||
vis[u] = true; | ||
num[u] = x; | ||
for (auto v : G[u]) { | ||
if (v.second < k && !vis[v.first]) | ||
dfs(v.first, k, x); | ||
} | ||
} | ||
|
||
bool check(int k) | ||
{ | ||
fill(vis, vis+n+1, false); | ||
for (int i = 1; i <= n; ++i) { | ||
if (!vis[i]) | ||
dfs(i, k, i); | ||
} | ||
for (int i = 0; i < p; ++i) { | ||
if (num[P[i].first] == num[P[i].second]) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
int main() | ||
{ | ||
scanf("%d%d%d", &n, &m, &p); | ||
for (int i = 0; i < m; ++i) { | ||
int u, v, w; | ||
scanf("%d%d%d", &u, &v, &w); | ||
G[u].emplace_back(v, w); | ||
G[v].emplace_back(u, w); | ||
} | ||
for (int i = 0; i < p; ++i) | ||
scanf("%d%d", &P[i].first, &P[i].second); | ||
|
||
int b = 1; | ||
int e = 1e9+1; | ||
while (b < e) { | ||
int mid = (b+e+1)/2; | ||
if (check(mid)) | ||
b = mid; | ||
else | ||
e = mid-1; | ||
} | ||
|
||
if (e == 1e9+1) | ||
e = -1; | ||
printf("%d\n", e); | ||
|
||
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,26 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
const int N = 4e4+5; | ||
|
||
int n, m, p, u, v, w, ans, H[N]; | ||
vector<tuple<int, int, int> > g; | ||
vector<pair<int, int> > q; | ||
|
||
int find(int x) { return H[x] = H[x] == x ? x : find(H[x]); } | ||
|
||
bool check(int m) { | ||
for(int i = 1; i <= n; ++i) H[i] = i; | ||
for(auto x : g) if(get<2>(x) < m) H[find(get<0>(x))] = find(get<1>(x)); | ||
for(auto x : q) if(find(x.first) == find(x.second)) return false; | ||
return true; | ||
} | ||
|
||
int main() { | ||
scanf("%d %d %d", &n, &m, &p); | ||
while(m--) scanf("%d %d %d", &u, &v, &w), g.emplace_back(u, v, w); | ||
while(p--) scanf("%d %d", &u, &v), q.emplace_back(u, v); | ||
for(int i = 29; i >= 0; --i) if(check(ans|1<<i)) ans |= 1<<i; | ||
if(ans > 1e9) puts("-1"); | ||
else printf("%d\n", ans); | ||
} |
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,18 @@ | ||
#include <bits/stdc++.h> | ||
#define long long long | ||
using namespace std; | ||
|
||
const int N = 1e5+5; | ||
|
||
int n, w, h; | ||
long A[N], B[N]; | ||
|
||
int main() { | ||
scanf("%d %d %d", &n, &w, &h); | ||
for(int i = 1; i <= n; ++i) scanf("%lld", A+i), A[i] += A[i-1]; | ||
for(int i = 1; i <= n; ++i) scanf("%lld", B+i), B[i] += B[i-1]; | ||
long mx1 = 0, mx2 = 0; | ||
for(int i = w; i <= n; ++i) mx1 = max(mx1, A[i] - A[i-w]); | ||
for(int i = h; i <= n; ++i) mx2 = max(mx2, B[i] - B[i-h]); | ||
printf("%lld\n", mx1 * h + mx2 * w); | ||
} |
Oops, something went wrong.