A - ASCII code
// shiran
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
char c = 'a' + n - 97;
printf("%c", c);
return 0;
}
// shiran
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int a[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
int maxn = 0;
rep(i, 1, n + 1) cin >> a[i], maxn = max(maxn, a[i]);
set<int> S;
rep(i, 1, n + 1)
if (a[i] == maxn)
S.insert(i);
while (k -- )
{
int x;
cin >> x;
if (S.count(x))
{
puts("Yes");
return 0;
}
}
puts("No");
return 0;
}
C - Slot Strategy
// shiran
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 210, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int n;
int t[N];
string s[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
rep(i, 1, n + 1) cin >> s[i];
int res = 0x3f3f3f3f;
rep(i, 0, 10)
{
map<int, int> mp;
int k = 1, ans = 0;
rep(j, 1, n + 1)
{
int p = s[j].find(to_string(i));
if (mp[p])
{
ans = max(ans, 10 * mp[p] + p);
mp[p] ++ ;
}
else
{
mp[p] ++ ;
ans = max(ans, p);
}
}
res = min(res, ans);
}
cout << res << endl;
return 0;
}
D - Distinct Trio
// shiran
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int n;
ll a[N], s[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
rep(i, 1, n + 1) cin >> a[i], s[a[i]] ++ ;
rep(i, 1, N) s[i] += s[i - 1];
ll ans = 0;
rep(i, 1, n + 1)
{
ans += 1ll * s[a[i] - 1] * (n - s[a[i]]);
}
printf("%lld", ans);
return 0;
}
E - Road Reduction
// shiran
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<ll, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = N * 2;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int n, m;
struct Edge
{
ll to, cost, idx;
};
vector<Edge> g[N];
bool st[N];
int ans[M];
void dijkstra()
{
vector<ll> dist(n + 1, 1ll<<60);
dist[1] = 0;
priority_queue<PII, vector<PII>, greater<PII>> q;
q.push({0, 1});
while (q.size())
{
auto t = q.top();
q.pop();
int ver = t.se;
if (st[ver]) continue;
st[ver] = true;
for (auto [vv, c, i] : g[ver])
{
if (dist[vv] > dist[ver] + c)
{
dist[vv] = dist[ver] + c;
ans[vv] = i;
q.push({dist[vv], vv});
}
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
rep(i, 1, m + 1)
{
int a, b, c;
cin >> a >> b >> c;
g[a].pb({b, c, i});
g[b].pb({a, c, i});
}
dijkstra();
rep(i, 1, m + 1)
if (ans[i])
printf("%d ", ans[i]);
return 0;
}
F - Bread
// shiran
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9+7;
const int N = 200010, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int n;
ll k;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
priority_queue<ll, vector<ll>, greater<ll>> q;
cin >> n >> k;
ll ans = 0;
rep(i, 1, n + 1)
{
ll x;
cin >> x;
k -= x;
q.push(x);
}
if (k > 0)
{
q.push(k);
}
while (q.size() > 1)
{
ll a = q.top();
q.pop();
ll b = q.top();
q.pop();
ans += (a + b);
q.push(a + b);
}
printf("%lld", ans);
return 0;
}
G - Pre-Order
WA了,其实序列的顺序还是没有考虑很清楚…弄明白了来补题
// shiran
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define sz(x) (int)size(x)
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mk make_mair
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 998244353;
const int N = 510, M = 300010;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int n;
int pre[N];
ll f[N][N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
rep(i, 1, n + 1) cin >> pre[i];
for (int len = 1; len <= n; len ++ )
{
for(int l = 1; l + len - 1 <= n; l ++ )
{
int r = l + len - 1;
if (len == 1) f[l][r] = 1;
else
{
for (int k = l + 1; k <= r; k ++ )
if (pre[l] < pre[k])
f[l][r] = (f[l][r] + f[l][k - 1] * f[k][r]) % mod;
}
}
}
printf("%lld\n", f[1][n]);
return 0;
}