提出 #70615757
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fix(x) fixed << setprecision(x)
#define rep(i, start, end) for (auto i = (start); (i) < (end); (i)++)
#define repe(i, start, end) for (auto i = (start); (i) <= (end); (i)++)
#define rrep(i, start, end) for (auto i = (start); (i) >= (end); (i)--)
constexpr auto PI = 3.14159265358979;
constexpr int INF = 1e+9;
constexpr long long INFL = 1e+18;
using ll = long long;
using lld = long double;
// using mint = modint1000000007;
using mint = modint998244353;
using Pair_int = pair<int, int>;
using Pair_ll = pair<ll, ll>;
template <class T>
using Graph = vector<vector<T>>;
template <class T1, class T2>
inline auto div_floor(T1 a, T2 b)
{
if (b < 0)
a *= -1, b *= -1;
if (a >= 0)
return a / b;
else
return (a + 1) / b - 1;
}
template <class T1, class T2>
inline auto div_ceil(T1 a, T2 b)
{
if (b < 0)
a *= -1, b *= -1;
if (a <= 0)
return a / b;
else
return (a - 1) / b + 1;
}
ll floor_sqrt(ll x)
{
ll y = sqrt(x);
while (y * y > x)
y--;
while ((y + 1) * (y + 1) <= x)
y++;
return y;
}
ll pow_int(ll x, ll n)
{
ll res = 1;
while (n > 0)
{
if (n & 1)
res *= x;
x *= x;
n >>= 1;
}
return res;
}
ll pow_mod(ll x, ll n, ll mod)
{
ll res = 1;
while (n > 0)
{
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll gcd(ll x, ll y)
{
if (x < y)
swap(x, y);
ll r;
while (y > 0)
{
r = x % y;
x = y;
y = r;
}
return x;
}
ll lcm(ll x, ll y) { return ll(x / gcd(x, y)) * y; }
ll nCk(ll n, ll r)
{
if (r < 0 || n < r)
return 0;
ll ans = 1;
for (ll i = 1; i <= r; i++)
{
ans *= n--;
ans /= i;
}
return ans;
}
int get_rand(int seed, int min, int max)
{
static mt19937_64 mt64(seed);
uniform_int_distribution<int> get_rand_int(min, max);
return get_rand_int(mt64);
}
template <typename T>
inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template <typename T>
inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
template <class T1, class T2>
inline auto mod(T1 x, T2 r) { return (x % r + r) % r; }
// ======================================== //
int main()
{
int N;
cin >> N;
vector<ll> X(N);
rep(i, 0, N) cin >> X[i];
set<ll> st;
st.insert(0);
auto get_d = [&](const auto itr) -> ll
{
if (st.size() == 1)
return 0;
ll res = INFL;
if (itr != st.begin())
chmin(res, abs(*itr - *prev(itr)));
if (next(itr) != st.end())
chmin(res, abs(*itr - *next(itr)));
return res;
};
ll D = 0;
rep(i, 0, N)
{
auto itr_r = st.lower_bound(X[i]);
auto itr_l = prev(itr_r);
ll d_l_old = get_d(itr_l);
ll d_r_old = 0;
if (itr_r != st.end())
d_r_old = get_d(itr_r);
auto itr_x = st.insert(X[i]).first;
ll d_x = get_d(itr_x);
ll d_l_new = get_d(itr_l);
ll d_r_new = 0;
if (itr_r != st.end())
d_r_new = get_d(itr_r);
D += (d_l_new + d_x + d_r_new) - (d_l_old + d_r_old);
cout << D << endl;
}
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
D - Neighbor Distance |
| ユーザ |
Yuulis |
| 言語 |
C++23 (GCC 15.2.0) |
| 得点 |
400 |
| コード長 |
3556 Byte |
| 結果 |
AC |
| 実行時間 |
652 ms |
| メモリ |
32940 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
400 / 400 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample_01.txt |
| All |
sample_01.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| sample_01.txt |
AC |
1 ms |
3440 KiB |
| test_01.txt |
AC |
1 ms |
3496 KiB |
| test_02.txt |
AC |
1 ms |
3536 KiB |
| test_03.txt |
AC |
526 ms |
32668 KiB |
| test_04.txt |
AC |
532 ms |
32668 KiB |
| test_05.txt |
AC |
530 ms |
32672 KiB |
| test_06.txt |
AC |
513 ms |
32936 KiB |
| test_07.txt |
AC |
514 ms |
32920 KiB |
| test_08.txt |
AC |
513 ms |
32940 KiB |
| test_09.txt |
AC |
492 ms |
32676 KiB |
| test_10.txt |
AC |
495 ms |
32908 KiB |
| test_11.txt |
AC |
495 ms |
32684 KiB |
| test_12.txt |
AC |
495 ms |
32668 KiB |
| test_13.txt |
AC |
521 ms |
32924 KiB |
| test_14.txt |
AC |
528 ms |
32924 KiB |
| test_15.txt |
AC |
527 ms |
32936 KiB |
| test_16.txt |
AC |
532 ms |
32936 KiB |
| test_17.txt |
AC |
639 ms |
32920 KiB |
| test_18.txt |
AC |
647 ms |
32932 KiB |
| test_19.txt |
AC |
643 ms |
32924 KiB |
| test_20.txt |
AC |
638 ms |
32932 KiB |
| test_21.txt |
AC |
644 ms |
32924 KiB |
| test_22.txt |
AC |
644 ms |
32936 KiB |
| test_23.txt |
AC |
639 ms |
32924 KiB |
| test_24.txt |
AC |
640 ms |
32936 KiB |
| test_25.txt |
AC |
642 ms |
32920 KiB |
| test_26.txt |
AC |
643 ms |
32936 KiB |
| test_27.txt |
AC |
652 ms |
32924 KiB |
| test_28.txt |
AC |
640 ms |
32940 KiB |
| test_29.txt |
AC |
641 ms |
32924 KiB |
| test_30.txt |
AC |
643 ms |
32940 KiB |