結果
問題 | No.2860 Heal Slimes |
ユーザー |
👑 ![]() |
提出日時 | 2024-08-25 17:06:46 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,258 bytes |
コンパイル時間 | 3,471 ms |
コンパイル使用メモリ | 260,496 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-08-25 17:06:54 |
合計ジャッジ時間 | 7,902 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 WA * 10 |
ソースコード
#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) using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int 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; bool solve(const int k, const int x, const vector<int>& h) { const int n = h.size(); if (k == n) return ranges::is_sorted(h) && h.front() == h.back(); vector<vector<ll>> diff(k); FOR(i, 1, n) { const int index = (i - 1) % k; diff[index].emplace_back(h[i] - h[i - 1]); if (diff[index].back() % x != 0) return false; diff[index].back() /= x; } vector<int> can_op(k, -1); can_op[k - 1] = 1; for (int i = 1; i + k < n; ++i) { if (can_op[(i - 1 + k) % k] == -1) can_op[(i - 1 + k) % k] = 0; } can_op[(n - 1) % k] = (can_op[(n - 1) % k] == -1 ? 2 : (can_op[(n - 1) % k] | 2)); REP(i, k) { if (can_op[i] == -1) { if (ranges::count(diff[i], 0) != diff[i].size()) return false; } else if (can_op[i] == 0) { ll op = 0; for (const ll d : diff[i]) { op += d; if (op > 0) return false; } if (op != 0) return false; } else if (can_op[i] == 1) { ll op = 0; for (const ll d : diff[i]) { op += d; } if (op < 0) return false; } else if (can_op[i] == 2) { ll op = 0; for (const ll d : diff[i]) { op += d; if (op > 0) return false; } } } return true; } int main() { int t; cin >> t; while (t--) { int n, k, x; cin >> n >> k >> x; vector<int> h(n); for (int& h_i : h) cin >> h_i; cout << (solve(k, x, h) ? "Yes\n" : "No\n"); } return 0; }