結果
問題 | No.1508 Avoid being hit |
ユーザー |
👑 ![]() |
提出日時 | 2021-05-14 23:10:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,242 bytes |
コンパイル時間 | 2,058 ms |
コンパイル使用メモリ | 202,336 KB |
最終ジャッジ日時 | 2025-01-21 12:10:14 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 WA * 2 TLE * 8 |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; int main() { int n, q; cin >> n >> q; vector<int> a(q), b(q); REP(i, q) cin >> a[i], --a[i]; REP(i, q) cin >> b[i], --b[i]; REP(i, q) { if (a[i] > b[i]) swap(a[i], b[i]); } vector<int> k; auto f = [&](auto &&f, int i, int g) -> void { k.emplace_back(g); if (i == -1) { cout << "YES\n" << g + 1 << '\n'; reverse(ALL(k)); REP(i, q) cout << k[i] + 1 << '\n'; exit(0); } if (a[i] == g) { if (g > 0) f(f, i - 1, g - 1); if (a[i] + 1 < b[i]) f(f, i - 1, g + 1); } else if (b[i] == g) { if (g + 1 < n) f(f, i - 1, g + 1); if (a[i] + 1 < b[i]) f(f, i - 1, g - 1); } else { if (g > 0 && a[i] != g - 1 && b[i] != g - 1) f(f, i - 1, g - 1); f(f, i - 1, g); if (g + 1 < n && a[i] != g + 1 && b[i] != g + 1) f(f, i - 1, g + 1); } k.pop_back(); }; set<int> goal; if (a[q - 1] > 0) { goal.emplace(a[q - 1] - 1); goal.emplace(max(a[q - 1] - 2, 0)); } if (a[q - 1] + 1 < b[q - 1]) { goal.emplace(a[q - 1] + 1); goal.emplace(b[q - 1] - 1); } if (a[q - 1] + 2 < b[q - 1]) { goal.emplace(a[q - 1] + 2); goal.emplace(b[q - 1] - 2); } if (b[q - 1] + 1 < n) { goal.emplace(b[q - 1] + 1); goal.emplace(min(b[q - 1] + 2, n - 1)); } for (int g : goal) f(f, q - 2, g); cout << "NO\n"; return 0; }