結果
問題 | No.1935 Water Simulation |
ユーザー |
|
提出日時 | 2022-05-15 16:16:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 2,083 bytes |
コンパイル時間 | 4,328 ms |
コンパイル使用メモリ | 257,636 KB |
最終ジャッジ日時 | 2025-01-29 08:15:51 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; //#define DISABLE_PRINT #if defined(ENABLE_PRINT) && !defined(DISABLE_PRINT) #define P(...) fprintf(stderr, __VA_ARGS__) #define P2(fmt) fprintf(stderr, fmt) #define LP fprintf(stderr, "L: %d\n", __LINE__) #else #define P(...) ((void)0) #define P2(fmt) ((void)0) #define LP ((void)0) #endif #define rep(i, n) for(int i = 0; i < (int)(n); ++i) #define ALL(x) x.begin(),x.end() using ll = long long; using ull = unsigned long long; int main(int, const char**) { array<int, 4> V; array<int, 4> W{}; rep(i, 4) cin >> V[i]; ll N; cin >> N; auto enc = [&](const array<int, 4>& w) { ll v = 0; rep(i, 4) { v *= 1000; v += w[i]; } return v; }; auto dec = [&](ll e) { array<int, 4> dec; rep(i, 4) { dec[3 - i] = e % 1000; e /= 1000; } return dec; }; using Key = pair<int, ll>; ll c = 0; W[0] = V[0]; map<Key, int> m; Key current; for(c = 0; c < N; ++c) { auto e = enc(W); current = Key{(int)c % 4, e}; if(m.find(current) != m.end()) break; m[current] = c; auto f = c % 4; auto t = (c + 1) % 4; auto move = min(W[f], V[t] - W[t]); W[f] -= move; W[t] += move; } if(c == N) { P("easy\n"); auto ans = W; for(auto a : ans) { cout << a << " "; } cout << endl; return 0; } auto loop = c - m[current]; auto lead = m[current]; auto mod = (N - lead) % loop; P("loop: %lld, lead: %d, mod: %lld\n", loop, lead, mod); for(auto p : m) { { auto d = dec(p.first.second); P("idx: %d, v: %d %d %d %d\n", p.second, d[0], d[1], d[2], d[3]); } if(p.second != mod + lead) continue; auto ans = dec(p.first.second); for(auto a : ans) { cout << a << " "; } cout << endl; break; } return 0; }