当前位置:网站首页>AtCoder Beginner Contest 252
AtCoder Beginner Contest 252
2022-06-09 08:55:00 【Shirandexiaowo】
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 了 , In fact, the order of the sequence is still not considered very clearly … I got it. Come on
// 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;
}
边栏推荐
- Precautions for Tencent cloud pagoda website construction
- SQL: 员工薪水中位数
- 认识了一位大佬!
- The energy efficiency management platform of the microgrid of the company promotes the upgrading of the power grid to the energy Internet
- Boot1.62.0 compilation static library FPIC link problem
- 如何使用阿里云 CDN 对部署在函数计算上的静态网站进行缓存
- 汇编_基础概念
- Virtual machine installation and configuration
- 配置Conda环境和Pytorch安装
- Nodejs uses net module to create TCP server and client
猜你喜欢

RMAN backup concept_ About backup retention policy

Self made compiler learning 3: introduction to flex and bison

防火门监控系统对防火门状态进行24小时实时自动巡检

SQL: people flow in the gymnasium (common solution for continuous day cases)

Energy management and control system for industrial enterprises helps enterprises strengthen energy management and improve equipment operation efficiency

远程预付费管理系统帮助物业解决收费难统计难问题

Description de l'éditeur - alternative

NetCore框架WTM的分表分库实现
![[program life] internet job division; Internet development process; Division of responsibilities](/img/e5/7fe5bb866f132f19a248087559e369.png)
[program life] internet job division; Internet development process; Division of responsibilities

面向高校 | “云原生技术应用与实践”示范课程项目开放申报
随机推荐
85. (leaflet house) leaflet military plotting - line arrow drawing
If and ifnull in MySQL
剩余电流继电器用剩余电流互感器来检测剩余电流防止电气火灾的发生
Modify PE program entry point
Configuring the environment for RMAN backups_ Configure backup optimization
Open source EDA software yosys for integrated circuit design 1: tool installation
Sql: reformat department table (row to column problem: group by + aggregate function)
LeetCode 第 295 场周赛
Configuring the environment for RMAN backups_ Configure advanced backup options
10种提问型爆文标题句式 直接套用
安科瑞综合能效管理系统在数据中心的应用
Oracle locally managed tablespaces
vim的简单使用
49-oauth2 pkce configuration in authorization code
Mock interview plan; Campus simulated interview plan; Job search simulation interview contest plan; Planning book of simulated job hunting competition of School of economics and management; College st
安科瑞企业微电网能效管理平台推动电网向能源互联网升级
Configuring the environment for RMAN backups_ Configure the deletion policy for archived redo logs
web知识点123
Mode de programmation 3D: mode d'isolement dépendant
Sql: median employee salary