Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
for _ in range(int(input())):
s = input()
t = input()
lcp = 0
n = len(s)
m = len(t)
for i in range(1, min(n, m) + 1):
if s[:i] == t[:i]:
lcp = i
print(n + m - max(lcp, 1) + 1)
2025B - Binomial Coefficients, Kind Of
Idea: adedalic
Tutorial
Tutorial is loading...
Solution (adedalic)
#include<bits/stdc++.h>
using namespace std;
const int MOD = int(1e9) + 7;
int main() {
int t; cin >> t;
vector<int> ks(t);
for (int _ = 0; _ < 2; _++)
for (int i = 0; i < t; i++)
cin >> ks[i];
vector<int> ans(1 + *max_element(ks.begin(), ks.end()), 1);
for (int i = 1; i < (int)ans.size(); i++)
ans[i] = (2LL * ans[i - 1]) % MOD;
for (int k : ks)
cout << ans[k] << '\n';
return 0;
}
Idea: fcspartakm
Tutorial
Tutorial is loading...
Solution (awoo)
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
j = 0
for i in range(n):
j = max(i, j)
while j + 1 < n and a[j + 1] - a[j] <= 1 and a[j + 1] - a[i] < k:
j += 1
ans = max(ans, j - i + 1)
print(ans)
Idea: adedalic
Tutorial
Tutorial is loading...
Solution (adedalic)
#include<bits/stdc++.h>
using namespace std;
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define sz(a) int((a).size())
typedef long long li;
const int INF = int(1e9);
const li INF64 = li(1e18);
int n, m;
vector<int> rs;
bool read() {
if(!(cin >> n >> m))
return false;
rs.resize(n);
fore (i, 0, n)
cin >> rs[i];
return true;
}
struct LazySum {
vector<int> ps;
LazySum(int n) : ps(n, 0) {}
//[l, r]
void add(int l, int r, int val) {
if (l > r) return;
ps[l] += val;
ps[r + 1] -= val;
}
void pushToAndClear(vector<int> &d) {
int sum = 0;
fore (i, 0, sz(ps)) {
sum += ps[i];
ps[i] = 0;
if (i < sz(d))
d[i] += sum;
}
}
};
void solve() {
LazySum ls(m + 2);
vector<int> d(m + 1, -INF);
d[0] = 0;
int cntP = 0;
for (int r : rs) {
if (r == 0) {
ls.pushToAndClear(d);
for (int i = m; i > 0; i--)
d[i] = max(d[i], d[i - 1]);
cntP++;
continue;
}
if (r > 0)
ls.add(r, m, 1);
else
ls.add(0, cntP + r, 1);
}
ls.pushToAndClear(d);
cout << *max_element(d.begin(), d.end()) << endl;
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
int tt = clock();
#endif
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
if(read()) {
solve();
#ifdef _DEBUG
cerr << "TIME = " << clock() - tt << endl;
tt = clock();
#endif
}
return 0;
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int add(int x, int y) {
x += y;
if (x >= MOD) x -= MOD;
return x;
}
int mul(int x, int y) {
return x * 1LL * y % MOD;
}
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> ways(m + 1, vector<int>(m + 1));
ways[0][0] = 1;
for (int i = 0; i < m; ++i) {
for (int j = 0; j <= i; ++j) {
ways[i + 1][j + 1] = add(ways[i + 1][j + 1], ways[i][j]);
if (j) ways[i + 1][j - 1] = add(ways[i + 1][j - 1], ways[i][j]);
}
}
vector<vector<int>> dp(n + 1, vector<int>(m + 1));
dp[0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= m; ++j) {
for (int k = 0; k <= m; ++k) {
int nj = i ? j - k : j + k;
if (0 <= nj && nj <= m) {
dp[i + 1][nj] = add(dp[i + 1][nj], mul(dp[i][j], ways[m][k]));
}
}
}
}
cout << dp[n][0] << '\n';
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
const int N = 300043;
string choice = "xy";
string sign = "+-";
int qs[N][2];
string ans[N];
int n, q;
vector<int> g[N];
int color[N];
void pair_queries(int q1, int q2)
{
if(q1 > q2) swap(q1, q2);
for(int i = 0; i < 2; i++)
for(int j = 0; j < 2; j++)
if(qs[q1][i] == qs[q2][j])
{
ans[q1] = { choice[i], sign[0] };
ans[q2] = { choice[j], sign[1] };
return;
}
}
bool dfs(int v, int pe = -1)
{
// return true if parent edge still exists
color[v] = 1;
vector<int> edge_nums;
for(auto e : g[v])
{
int u = v ^ qs[e][0] ^ qs[e][1];
if(color[u] == 1) continue;
if(color[u] == 0)
{
if(dfs(u, e))
edge_nums.push_back(e);
}
else
edge_nums.push_back(e);
}
bool res = true;
if(edge_nums.size() % 2 != 0)
{
if(pe != -1) edge_nums.push_back(pe);
else edge_nums.pop_back();
res = false;
}
for(int i = 0; i < edge_nums.size(); i += 2)
pair_queries(edge_nums[i], edge_nums[i + 1]);
color[v] = 2;
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
for(int i = 0; i < q; i++)
{
cin >> qs[i][0] >> qs[i][1];
--qs[i][0];
--qs[i][1];
g[qs[i][0]].push_back(i);
g[qs[i][1]].push_back(i);
ans[i] = "x+";
}
for(int i = 0; i < n; i++)
if(color[i] == 0)
dfs(i);
for(int i = 0; i < q; i++) cout << ans[i] << endl;
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (awoo)
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
struct query{
int t, v;
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int m;
cin >> m;
vector<query> q(m);
forn(i, m) cin >> q[i].t >> q[i].v;
vector<pair<int, int>> xs;
forn(i, m) xs.push_back({q[i].v, i});
sort(xs.rbegin(), xs.rend());
forn(i, m) q[i].v = xs.rend() - lower_bound(xs.rbegin(), xs.rend(), make_pair(q[i].v, i)) - 1;
const int p = sqrt(m + 10);
const int siz = (m + p - 1) / p;
vector<int> tp(m);
vector<int> val(m);
vector<vector<long long>> dp(p, vector<long long>(2 * siz + 1));
vector<int> blbal(p);
auto upd = [&](const query &q){
tp[q.v] = q.t;
val[q.v] = xs[q.v].first;
blbal[q.v / siz] += q.t == 1 ? 1 : -1;
};
auto recalc = [&](int b){
dp[b].assign(2 * siz + 1, 0);
int bal = 0;
for (int i = b * siz; i < m && i < (b + 1) * siz; ++i){
if (tp[i] == 1){
dp[b][0] += val[i];
dp[b][0] += val[i];
dp[b][-bal + siz] -= val[i];
++bal;
}
else if (tp[i] == 2){
dp[b][-bal + 1 + siz] += val[i];
--bal;
}
}
forn(i, 2 * siz){
dp[b][i + 1] += dp[b][i];
}
};
auto get = [&](int b, int bal){
bal += siz;
if (bal < 0) return dp[b][0];
if (bal >= 2 * siz + 1) return dp[b].back();
return dp[b][bal];
};
for (auto it : q){
upd(it);
recalc(it.v / siz);
int bal = 0;
long long ans = 0;
for (int i = 0; i * siz < m; ++i){
ans += get(i, bal);
bal += blbal[i];
}
cout << ans << '\n';
}
return 0;
}