1126 字
6 分钟
abc457
NOTE

比赛链接:Atcoder Beginner Contest 457

A - Array#

关键词:签到

Code#

// Problem: AT ABC457 A
// Contest: AtCoder - Polaris.AI Programming Contest 2026(AtCoder Beginner Contest 457)
// URL: https://atcoder.jp/contests/abc457/tasks/abc457_a
// Time: 2026-05-09 20:00:09
#include <bits/stdc++.h>
using namespace std;
// clang-format off
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define fastio() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// clang-format on
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<long long, long long>;
const int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int inf = 0x3f3f3f3f;
const int N = 0;
void solve()
{
int n;
cin >> n;
vector<ll> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
int x;
cin >> x;
cout << a[x] << endl;
}
int main()
{
fastio();
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}

B - Arrays#

关键词:签到

NOTE

注意使用 resize() 分配空间。

Code#

// Problem: AT ABC457 B
// Contest: AtCoder - Polaris.AI Programming Contest 2026(AtCoder Beginner Contest 457)
// URL: https://atcoder.jp/contests/abc457/tasks/abc457_b
// Time: 2026-05-09 20:00:10
#include <bits/stdc++.h>
using namespace std;
// clang-format off
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define fastio() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// clang-format on
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<long long, long long>;
const int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
void solve()
{
int n;
cin >> n;
vector<vector<int>> a(n + 1);
for (int i = 1; i <= n; i++)
{
int m;
cin >> m;
a[i].resize(m + 1);
for (int j = 1; j <= m; j++)
cin >> a[i][j];
}
int x, y;
cin >> x >> y;
cout << a[x][y] << endl;
}
int main()
{
fastio();
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}

C - Long Sequence#

关键词:模拟

思路#

直接模拟即可。注意计算最后一轮的位置时,可以通过取模来实现。

Code#

// Problem: AT ABC457 C
// Contest: AtCoder - Polaris.AI Programming Contest 2026(AtCoder Beginner Contest 457)
// URL: https://atcoder.jp/contests/abc457/tasks/abc457_c
// Time: 2026-05-09 20:00:11
#include <bits/stdc++.h>
using namespace std;
// clang-format off
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define fastio() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// clang-format on
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<long long, long long>;
const int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int inf = 0x3f3f3f3f;
const int N = 0;
void solve()
{
ll n, k;
cin >> n >> k;
vector<vector<ll>> a(n + 1);
vector<ll> L(n + 1);
for (int i = 1; i <= n; i++)
{
int m;
cin >> m;
L[i] = m;
a[i].resize(m + 1);
for (int j = 1; j <= m; j++)
cin >> a[i][j];
}
vector<int> c(n + 1);
for (int i = 1; i <= n; i++)
cin >> c[i];
for (int i = 1; i <= n; i++)
{
ll t = (ll) c[i] * L[i];
if (k <= t)
{
ll pos = k % L[i];
if (pos == 0)
pos = L[i];
cout << a[i][pos] << endl;
return;
}
else
k -= t;
}
}
int main()
{
fastio();
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}

D - Raise Minimum#

关键词:二分答案

思路#

题目求最小值最大,考虑二分答案。

我们遍历所有的 AiA_i,计算“为了让所有数都至少达到 mid,我们总共需要花费多少次操作(存入 tmp)。

NOTE

注意:使用小数计算 ceil 可能会丢精度,最好使用整数。也就是ceil(a / b) == (a + b - 1) / b

另外这道题需要用 __int128。假设序列长度 N=2×105N = 2 \times 10^5,操作次数 K=1018K = 10^{18},如果我们把这 101810^{18} 次操作全部加在最后那个元素 ANA_N 上(此时 i=2×105i = 2 \times 10^5)。那么 ANA_N 最终的值会变成:AN+K×N1018+1018×21052×1023A_N + K \times N \approx 10^{18} + 10^{18} \times 2 \cdot 10^5 \approx 2 \times 10^{23}

__int128 的用法详见杂项文档。

Code#

// Problem: AT ABC457 D
// Contest: AtCoder - Polaris.AI Programming Contest 2026(AtCoder Beginner Contest 457)
// URL: https://atcoder.jp/contests/abc457/tasks/abc457_d
// Time: 2026-05-09 20:00:12
#include <bits/stdc++.h>
using namespace std;
// clang-format off
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define fastio() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// clang-format on
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using pll = pair<long long, long long>;
const int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
void write(__int128 x)
{
if (x < 0)
{
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
void solve()
{
ll n, k;
cin >> n >> k;
vector<ll> a(n + 1);
for (ll i = 1; i <= n; i++)
cin >> a[i];
__int128 l = 0, r = 1e24, res;
while (l < r)
{
__int128 mid = (l + r + 1) >> 1;
__int128 tmp = 0;
bool flag = true;
for (int i = 1; i <= n; i++)
{
if (a[i] < mid)
{
__int128 cnt = (mid - a[i] + i - 1) / i;
tmp += cnt;
}
if (tmp > k)
{
flag = false;
break;
}
}
if (flag)
res = mid, l = mid;
else
r = mid - 1;
}
write(res);
}
int main()
{
fastio();
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}