結果

問題 No.1935 Water Simulation
コンテスト
ユーザー tombo_
提出日時 2026-02-07 16:15:22
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 542 ms / 2,000 ms
コード長 3,206 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,869 ms
コンパイル使用メモリ 285,584 KB
実行使用メモリ 436,480 KB
最終ジャッジ日時 2026-02-07 16:15:35
合計ジャッジ時間 12,234 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define REP(i, l, r) rep(i, l, r+1)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
struct Edge {
  int to; ll w;
};
using Graph = vector<vector<int> >;
//using Graph = vector<vector<Edge> >;
const ll INF = 2e18;
//const int INF = 2e9;
template<class T> using vc = vector<T>;
template<class T> using vv = vector<vector<T> >;
template<class T> using vvv = vector<vector<vector<T> > >;
template<class T> using vvvv = vector<vector<vector<vector<T> > > >;
template<class T> using pq = priority_queue<T>;
template<class T> using pq_g = priority_queue<T, vc<T>, greater<T> >;
template<class T> istream& operator>>(istream& i, vc<T>& v) { rep(j, 0, v.size()) i>>v[j]; return i; }
template<class T> ostream& operator<<(ostream& o, vc<T>& v) { rep(j, 0, v.size()) o<<v[j]<<" "; return o; }
template<class T> bool chmin(T& a, T b) {
  if(a > b) {
      a = b;
      return true;
  }
  return false;
}
template<class T> bool chmax(T& a, T b) {
  if(a < b) {
      a = b;
      return true;
  }
  return false;
}
constexpr double EPS = 1e-9;

inline bool eq(double a, double b) { return fabs(a - b) < EPS; }
inline bool lt(double a, double b) { return a < b - EPS; }
inline bool gt(double a, double b) { return a > b + EPS; }
inline int sgn(double x) {
    if (x > EPS) return 1;
    if (x < -EPS) return -1;
    return 0;
}

int main() {
  // 高速化
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  // 小数点の出力桁数を指定
  cout << fixed << setprecision(10);
  // メイン
  int v1, v2, v3, v4;
  cin >> v1 >> v2 >> v3 >> v4;
  ll N;
  cin >> N;
  int sum = v1;
  vector v(61, vector(v1+1, vector(v2+1, vector<array<int, 3>>(v3+1))));
  REP(i, 0, v1) REP(j, 0, v2) REP(k, 0, v3) {
      if(i+j+k > sum || sum-i-j-k>v4) continue;
      int l = sum-i-j-k;
      int c1 = i, c2 = j, c3 = k, c4 = l;
      int n1 = min(v2-c2, c1); c1 -= n1; c2 += n1;
      int n2 = min(v3-c3, c2); c2 -= n2; c3 += n2;
      int n3 = min(v4-c4, c3); c3 -= n3; c4 += n3;
      int n4 = min(v1-c1, c4); c4 -= n4; c1 += n4;
      v[0][i][j][k] = {c1, c2, c3};
  }
  rep(itr, 1, 60) {
      REP(i, 0, v1) REP(j, 0, v2) REP(k, 0, v3) {
          auto [a, b, c] = v[itr-1][i][j][k];
          v[itr][i][j][k] = v[itr-1][a][b][c];
      }
  }
  int a=v1, b=0, c=0;
  rep(i, 0, 60) {
      if((N/4)>>i&1) {
          auto [na, nb, nc] = v[i][a][b][c];
          a = na, b = nb, c = nc;
      }
  }
  rep(i, 0, N%4) {
      int d = sum-a-b-c;
      if(i%4==0) { int n1 = min(v2-b, a); a -= n1, b += n1; }
      if(i%4==1) { int n2 = min(v3-c, b); b -= n2, c += n2; }
      if(i%4==2) { int n3 = min(v4-d, c); c -= n3, d += n3; }
      if(i%4==3) { int n4 = min(v1-a, d); d -= n4, a += n4; }
  }
  cout << a << " " << b << " " << c << " " << sum-a-b-c << endl;

  return 0;
}
0