結果
| 問題 |
No.2673 A present from B
|
| コンテスト | |
| ユーザー |
eoeo
|
| 提出日時 | 2024-03-17 00:44:37 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
CE
(最初)
|
| 実行時間 | - |
| コード長 | 7,633 bytes |
| コンパイル時間 | 6,912 ms |
| コンパイル使用メモリ | 261,768 KB |
| 最終ジャッジ日時 | 2025-02-20 06:59:12 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 WA * 5 |
コンパイルメッセージ
main.cpp: In function 'void solve(int)':
main.cpp:39:12: warning: ignoring return value of 'constexpr std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
39 | a[i];
| ^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/vector:64,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/functional:62,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:71,
from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.4.0/include/c++/12/bits/stl_vector.h:1123:7: note: declared here
1123 | operator[](size_type __n) _GLIBCXX_NOEXCEPT
| ^~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef MY_DEBUG
#define dbg(var) debug_out(#var, "=", var)
#define dbgm(...) debug_out(__VA_ARGS__)
#else
#define dbg(...)
#define dbgm(...)
#endif
void debug_out();
template <class Head, class... Tail>
void debug_out(Head, Tail...);
template <class T>
bool chmax(T &, const T &);
template <class T>
bool chmin(T &, const T &);
template <class T>
T pwr(T, ll);
template <class T>
T squ(T x) { return x * x; }
ll fact(ll);
ll comb(ll, ll);
ll ctoll(char);
char lltoc(ll);
bool flg(ll b, ll i) { return ((b) >> (i)) & 1LL; } // flg(0b010, 1LL) -> true
const ll LINF = (ll)4e18 + 7;
const double EPS = 1e-9;
const int MAX_DUBUG_SIZE = 10;
void solve([[maybe_unused]] int test)
{
ll n, m;
cin >> n >> m;
vector<ll> a(m);
for (ll i = 0; i < m; i++)
{
cin >> a[i];
a[i];
}
vector<ll> dist(n + 2);
for (ll i = 0; i < n + 2; i++)
{
dist[i] = i - 1;
}
for (ll i = m - 1; i >= 0; i--)
{
dbg(dist);
ll x = a[i];
if (dist[x] == dist[x + 1])
continue;
else if (dist[x] < dist[x + 1])
{
swap(dist[x], dist[x + 1]);
if (dist[x - 1] < dist[x])
dist[x] = dist[x - 1] + 1;
for (ll j = x + 2; j <= n and (dist[j] > dist[j - 1] + 1); j++)
{
dist[j]--;
}
}
else
{
swap(dist[x], dist[x + 1]);
if (dist[x + 2] < dist[x + 1])
dist[x + 1] = dist[x + 2] + 1;
for (ll j = x - 1; j <= n and (dist[j] > dist[j + 1] + 1); j--)
{
dist[j]--;
}
}
}
dbg(dist);
for (ll i = 2; i < ssize(dist) - 1; i++)
{
cout << dist[i] << (i == ssize(dist) - 2 ? "\n" : " ");
}
}
int main()
{
cin.tie(nullptr), ios::sync_with_stdio(false);
cout << fixed << setprecision(12), cerr << fixed << setprecision(12);
int testcase_size = 1;
// cin >> testcase_size;
for (int _t = 0; _t < testcase_size; _t++)
{
solve(_t);
}
}
/*
-----------------------------------MY_FUNCTIONS------------------------------------ */
template <class First, class Second>
ostream &operator<<(ostream &os, const pair<First, Second> &pp);
template <class T>
ostream &operator<<(ostream &os, const vector<T> &V);
template <class T>
ostream &operator<<(ostream &os, const vector<vector<T>> &VV);
template <class T>
ostream &operator<<(ostream &os, const vector<vector<vector<T>>> &VVV);
template <class T>
ostream &operator<<(ostream &os, const set<T> &SS);
template <class Key, class Tp>
ostream &operator<<(ostream &os, const map<Key, Tp> &MM);
void debug_out();
void debug_out_vl(vector<ll> V);
void debug_out_vvl(vector<vector<ll>> VV);
template <class Head, class... Tail>
void debug_out(Head H, Tail... T);
template <class First, class Second>
ostream &operator<<(ostream &os, const pair<First, Second> &pp)
{
return os << "{" << pp.first << "," << pp.second << "}";
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &V)
{
if (V.empty())
return os << "[]";
os << "[";
for (ll i = 0; i < (ll)V.size(); i++)
{
os << V[i] << (i == int(V.size() - 1) ? "]" : ",");
}
return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<vector<T>> &VV)
{
if (VV.empty())
return os << "[[]]";
os << "[" << endl;
for (auto &&V : VV)
{
os << V << endl;
}
os << "]";
return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<vector<vector<T>>> &VVV)
{
if (VVV.empty())
return os << "[[[]]]";
os << "[" << endl;
int cnt = 0;
for (auto &&VV : VVV)
{
os << cnt++ << VV << endl
<< endl;
}
os << "]";
return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &SS)
{
if (SS.empty())
return os << "[]";
os << "[";
auto ii = SS.begin();
for (; ii != SS.end(); ii++)
os << *ii << (ii == prev(SS.end()) ? "]" : ",");
return os;
}
template <class Key, class Tp>
ostream &operator<<(ostream &os, const map<Key, Tp> &MM)
{
if (MM.empty())
return os << "[{:}]";
os << "[";
auto ii = MM.begin();
for (; ii != MM.end(); ii++)
os << "{" << ii->first << ":" << ii->second << "}" << (ii == prev(MM.end()) ? "]" : ",");
return os;
}
void debug_out() { cerr << endl; }
void debug_out_vl(vector<ll> V)
{
const int MAX_SIZE = min((int)V.size(), MAX_DUBUG_SIZE);
cerr << "\033[33m";
if (V.empty())
{
cerr << "[]" << endl;
return;
}
cerr << "[";
for (int i = 0; i < MAX_SIZE; i++)
{
if (V[i] == LINF)
cerr << "INF";
else
cerr << V[i];
if (i == (int)V.size() - 1)
cerr << "]" << endl;
else if (i == MAX_DUBUG_SIZE - 1)
cerr << ",..." << endl;
else
cerr << ",";
}
return;
}
void debug_out_vvl(vector<vector<ll>> VV)
{
cerr << "\033[33m";
if (VV.empty())
{
cerr << "[[]]" << endl;
return;
}
cerr << "[" << endl;
int MAX_ROW = min((int)VV.size(), MAX_DUBUG_SIZE);
for (int i = 0; i < MAX_ROW; i++)
{
const int MAX_COLUMN = min((int)VV[i].size(), MAX_DUBUG_SIZE);
if (VV[i].empty())
{
cerr << "[]" << endl;
continue;
}
cerr << "[";
for (int j = 0; j < MAX_COLUMN; j++)
{
if (VV[i][j] == LINF)
cerr << "INF";
else
cerr << VV[i][j];
if (j == (int)VV[i].size() - 1)
cerr << "]" << endl;
else if (j == MAX_DUBUG_SIZE - 1)
cerr << ",..." << endl;
else
cerr << ",";
}
if (i != (int)VV.size() - 1 and i == MAX_DUBUG_SIZE - 1)
{
cerr << ":\n:\033[m" << endl;
return;
}
}
cerr << "]\033[m" << endl;
return;
}
template <class Head, class... Tail>
void debug_out(Head H, Tail... T)
{
if constexpr (std::is_same_v<Head, vector<ll>>)
{
debug_out_vl(H);
}
else if constexpr (std::is_same_v<Head, vector<vector<ll>>>)
{
debug_out_vvl(H);
}
else
{
cerr << "\033[33m" << H << "\033[m ";
}
debug_out(T...);
}
template <class T>
bool chmax(T &a, const T &b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b)
{
if (b < a)
{
a = b;
return true;
}
return false;
}
template <class T>
T pwr(T x, ll n)
{
T res = 1;
for (int i = 0; i < n; i++)
{
res *= x;
}
return res;
}
ll fact(ll n)
{
ll res = 1;
for (ll i = 1; i <= n; i++)
res *= i;
return res;
}
ll comb(ll n, ll r)
{ // comb(60, 30)までオーバーフローなし
ll res = 1;
for (int i = 1; i <= r; i++)
{
res *= n--;
res /= i;
}
return res;
}
ll ctoll(char c)
{
if (c < '0' or '9' < c)
{
cerr << "\n\033[33m ctoll に '0'~'9' 以外の文字が入りました.\033[m\n"
<< endl;
}
return ll(c - '0');
}
char lltoc(ll n)
{
if (n < 0 or 9 < n)
{
cerr << "\n\033[33m lltoc に 0 ~ 9 以外の数字が入りました.\033[m\n"
<< endl;
}
return char(n + '0');
}
eoeo