-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
53d0765
commit 3af0a8b
Showing
232 changed files
with
3,898 additions
and
404 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
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,15 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define int long long | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n, s, k; cin >> n >> s >> k; | ||
int ans = 0; | ||
for (int i = 0; i < n; i++) { | ||
int x, y; cin >> x >> y; | ||
ans += x * y; | ||
} | ||
if (ans < s) ans += k; | ||
cout << 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,20 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int k, g, m; cin >> k >> g >> m; | ||
int gc = 0, mc = 0; | ||
while (k--) { | ||
if (gc == g) gc = 0; | ||
else if (mc == 0) mc = m; | ||
else { | ||
int req = g - gc; | ||
int transfer = min(req, mc); | ||
mc -= transfer; | ||
gc += transfer; | ||
} | ||
} | ||
cout << gc << ' ' << mc; | ||
} |
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,22 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n, m; string s; cin >> n >> m >> s; | ||
int mx = 0, cur = 0, left = m; | ||
for (int i = 0; i < n; i++) { | ||
if (s[i] == '2') cur++; | ||
else if (s[i] == '1') { | ||
if (left == 0) cur++; | ||
else left--; | ||
} | ||
if (s[i] == '0' || i == n - 1) { | ||
mx = max(mx, cur); | ||
cur = 0; | ||
left = m; | ||
} | ||
} | ||
cout << mx; | ||
} |
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,72 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define int long long | ||
|
||
int inversions(vector<int> &arr) { | ||
multiset<int> set1; | ||
set1.insert(arr[0]); | ||
int invcount = 0; | ||
multiset<int>::iterator itset1; | ||
for (int i=1; i<arr.size(); i++) { | ||
set1.insert(arr[i]); | ||
itset1 = set1.upper_bound(arr[i]); | ||
invcount += distance(itset1, set1.end()); | ||
} | ||
return invcount; | ||
} | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n, m; cin >> n >> m; | ||
set<int> a[6], b[6], c[6], d[6]; | ||
multiset<int> aa, bb; | ||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < m; j++) { | ||
int x; cin >> x; | ||
a[i].insert(x); | ||
c[j].insert(x); | ||
aa.insert(x); | ||
} | ||
} | ||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < m; j++) { | ||
int x; cin >> x; | ||
b[i].insert(x); | ||
d[j].insert(x); | ||
bb.insert(x); | ||
} | ||
} | ||
|
||
if (aa != bb) { cout << -1; return 0; } | ||
|
||
bool b1 = true; bool used1[6]{}; vector<int> v1; | ||
for (int i = 0; i < n; i++) { | ||
bool bb = false; | ||
for (int j = 0; j < n; j++) { | ||
if (!used1[j] && b[i] == a[j]) { | ||
v1.push_back(j); | ||
used1[j] = 1; | ||
bb = true; | ||
break; | ||
} | ||
} | ||
if (!bb) { b1 = 0; break; } | ||
} | ||
|
||
bool b2 = true; bool used2[6]{}; vector<int> v2; | ||
for (int i = 0; i < m; i++) { | ||
bool bb = false; | ||
for (int j = 0; j < m; j++) { | ||
if (!used2[j] && d[i] == c[j]) { | ||
v2.push_back(j); | ||
used2[j] = 1; | ||
bb = true; | ||
break; | ||
} | ||
} | ||
if (!bb) { b2 = 0; break; } | ||
} | ||
|
||
if (!b1 || !b2) cout << -1; | ||
else cout << inversions(v1) + inversions(v2); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,31 +1,23 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
#define int long long | ||
|
||
int n, k; | ||
int pre[5005], c[5005], s[5005]; | ||
int dp[5005][5005]; | ||
|
||
int cost(int l, int r) { | ||
int res = -(l <= 1 ? 0 : c[l] * c[l - 1]) -(r >= n ? 0 : c[r] * c[r + 1]); | ||
res += (pre[r] - pre[l - 1]); | ||
return res; | ||
} | ||
int c[5005], s[5005]; | ||
int dp[5005][5005][2]; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
cin >> n >> k; | ||
cin >> n >> k; c[0] = c[n + 1] = 0; | ||
for (int i = 1; i <= n; i++) cin >> c[i]; | ||
for (int i = 1; i <= n; i++) cin >> s[i]; | ||
pre[0] = 0; for (int i = 1; i <= n; i++) pre[i] = pre[i-1] + s[i]; | ||
|
||
cout << cost(2, 2) << '\n'; | ||
for (int i = 0; i <= n; i++) for (int j = 0; j <= k; j++) { | ||
if (i == 0 || j == 0) dp[i][j] = 0; | ||
dp[i][j] = dp[i - 1][j]; | ||
for (int a = 1; a <= j; a++) | ||
dp[i][j] = max(dp[i][j], dp[i - a][j - a] + cost(i - a + 1, i)); | ||
for (int i = 0; i <= n; i++) for (int j = 0; j <= k; j++) for (int f = 1; f >= 0; f--) { | ||
if (i == 0 && f == 0) dp[i][j][f] = 0; | ||
else if (i == 0 && f == 1) dp[i][j][f] = -1e18; | ||
else if (f == 1) dp[i][j][f] = max(dp[i-1][j-1][0]+s[i]-c[i]*c[i-1], dp[i-1][j-1][1]+s[i]); | ||
else if (f == 0) dp[i][j][f] = max(dp[i-1][j][0], dp[i][j][1]-c[i]*c[i+1]); | ||
} | ||
|
||
cout << dp[n][k]; | ||
cout << dp[n][k][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,60 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define int long long | ||
|
||
int n, k, q, a[100005]; | ||
int fw1[100005], fw2[100005], fw3[100005]; | ||
|
||
void update(int *t, int p, int v) { | ||
while (p <= n) { | ||
t[p] += v; | ||
p += p & -p; | ||
} | ||
} | ||
|
||
void update(int p, int v) { | ||
update(fw1, p, v); | ||
update(fw2, p, p * v); | ||
update(fw3, p, (n - p + 1) * v); | ||
} | ||
|
||
int query(int *t, int p) { | ||
int res = 0; | ||
while (p) { | ||
res += t[p]; | ||
p -= p & -p; | ||
} | ||
return res; | ||
} | ||
|
||
int query(int *t, int l, int r) { | ||
return query(t, r) - query(t, l - 1); | ||
} | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
cin >> n >> k; | ||
for (int i = 1; i <= n; i++) { | ||
cin >> a[i]; | ||
update(i, a[i]); | ||
} | ||
|
||
cin >> q; | ||
while (q--) { | ||
int t, b[k]; cin >> t; | ||
if (t == 1) { | ||
for (int i = 0; i < k; i++) cin >> b[i]; | ||
int tmp = a[b[0]]; | ||
for (int i = 1; i < k; i++) | ||
update(b[i - 1], a[b[i]] - a[b[i - 1]]), a[b[i - 1]] = a[b[i]]; | ||
update(b[k - 1], tmp - a[b[k - 1]]); a[b[k - 1]] = tmp; | ||
} else { | ||
int l, r, m; cin >> l >> r >> m; | ||
int sum = 0; | ||
sum += query(fw2, l, l + m - 2) - ((l - 1) * query(fw1, l, l + m - 2)); | ||
sum = sum + query(fw3, r - m + 2, r) - ((n - r) * query(fw1, r - m + 2, r)); | ||
sum += m * query(fw1, l + m - 1, r - m + 1); | ||
cout << sum << '\n'; | ||
} | ||
} | ||
} |
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
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
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,16 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define int long long | ||
const int m = 1e9 + 7; | ||
|
||
int dp[2005]; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n; cin >> n; | ||
dp[0] = 1; dp[3] = 1; | ||
for (int i = 4; i <= n; i++) { | ||
for (int j = 0; j <= i - 3; j++) dp[i] = (dp[i] + dp[j]) % m; | ||
} | ||
cout << dp[n]; | ||
} |
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,36 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
typedef long long ll; | ||
|
||
int dp[19][(1 << 19)], g[19][19]; | ||
|
||
int32_t main() { | ||
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); | ||
int n, m; cin >> n >> m; | ||
for (int i = 0; i < m; i++) { | ||
int u, v; cin >> u >> v; | ||
g[u][v] = g[v][u] = 1; | ||
} | ||
|
||
int ans = 0; | ||
for (int mask = 1; mask < (1 << n); mask++) { | ||
int mnbit = __builtin_ctz(mask); | ||
if ((1 << mnbit) == mask) { | ||
dp[mnbit][mask] = 1; | ||
continue; | ||
} | ||
|
||
for (int i = mnbit + 1; i < n; i++) { | ||
if (!(mask & (1 << i))) continue; | ||
if (__builtin_popcount(mask) == 2) { | ||
dp[i][mask] = g[mnbit][i]; | ||
continue; | ||
} | ||
for (int j = mnbit + 1; j < n; j++) | ||
if (g[i][j]) dp[i][mask] += dp[j][mask ^ (1 << i)]; | ||
ans += g[i][mnbit] * dp[i][mask]; | ||
} | ||
} | ||
|
||
cout << ans / 2; | ||
} |
Oops, something went wrong.