結果

問題 No.1935 Water Simulation
ユーザー tnakao0123tnakao0123
提出日時 2022-05-13 23:10:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,513 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 64,904 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-29 08:53:18
合計ジャッジ時間 2,020 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1935.cc:  No.1935 Water Simulation - yukicoder
 */

#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
 
using namespace std;

/* constant */

const int K = 4;

/* typedef */

typedef long long ll;
typedef vector<int> vi;
typedef map<int,int> mii;

/* global variables */

/* subroutines */

int v2bits(int v[]) {
  int bits = 0;
  for (int i = 0; i < K; i++)
    bits |= v[i] << (i * 8);
  return bits;
}

void bits2v(int bits, int v[]) {
  for (int i = 0; i < K; i++)
    v[i] = (bits >> (i * 8)) & 0xff;
}

void printv(int vs[]) {
  for (int i = 0; i < K; i++) printf("%d ", vs[i]);
}

/* main */

int main() {
  int vs[K];
  for (int i = 0; i < K; i++) scanf("%d", vs + i);

  ll n;
  scanf("%lld", &n);

  int xs[K];
  fill(xs, xs + K, 0);
  xs[0] = vs[0];

  vi bs;
  mii cache;
  int l = 0, r = 0, b0 = v2bits(xs);
  bs.push_back(b0);
  cache[b0] = 0;
  //printv(xs), printf(": %d\n", l);

  for (;;) {
    int i = l % K;
    int j = (i + 1) % K;
    int d = min(xs[i], vs[j] - xs[j]);
    xs[i] -= d, xs[j] += d;
    l++;
    //printv(xs), printf(": %d\n", l);

    int bits = v2bits(xs);
    mii::iterator mit = cache.find(bits);
    if (mit != cache.end()) {
      r = mit->second;
      break;
    }

    bs.push_back(bits);
    cache[bits] = l;
  }
  //printf("r=%d, l=%d\n", r, l);

  int b = (n < r) ? bs[n] : bs[r + (n - r) % (l - r)];
  bits2v(b, xs);
  for (int i = 0; i < K; i++)
    printf("%d%c", xs[i], (i + 1 < K) ? ' ' : '\n');
  return 0;
}
0