結果

問題 No.1935 Water Simulation
ユーザー sahiyasahiya
提出日時 2022-05-13 22:52:57
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 337 ms / 2,000 ms
コード長 3,241 bytes
コンパイル時間 1,691 ms
使用メモリ 158,784 KB
最終ジャッジ日時 2023-02-21 18:53:59
合計ジャッジ時間 6,747 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 332 ms
158,784 KB
testcase_01 AC 337 ms
158,716 KB
testcase_02 AC 1 ms
6,272 KB
testcase_03 AC 185 ms
98,736 KB
testcase_04 AC 34 ms
24,256 KB
testcase_05 AC 179 ms
105,236 KB
testcase_06 AC 259 ms
137,892 KB
testcase_07 AC 71 ms
46,604 KB
testcase_08 AC 82 ms
52,584 KB
testcase_09 AC 219 ms
119,044 KB
testcase_10 AC 177 ms
105,316 KB
testcase_11 AC 43 ms
30,544 KB
testcase_12 AC 2 ms
6,168 KB
testcase_13 AC 2 ms
6,276 KB
testcase_14 AC 18 ms
14,700 KB
testcase_15 AC 115 ms
72,996 KB
testcase_16 AC 98 ms
63,252 KB
testcase_17 AC 46 ms
31,840 KB
testcase_18 AC 2 ms
6,172 KB
testcase_19 AC 311 ms
154,364 KB
testcase_20 AC 3 ms
6,212 KB
testcase_21 AC 112 ms
70,672 KB
testcase_22 AC 131 ms
81,024 KB
testcase_23 AC 16 ms
13,872 KB
testcase_24 AC 255 ms
137,828 KB
testcase_25 AC 220 ms
126,272 KB
testcase_26 AC 3 ms
6,232 KB
testcase_27 AC 35 ms
25,508 KB
testcase_28 AC 21 ms
17,196 KB
testcase_29 AC 1 ms
6,252 KB
testcase_30 AC 2 ms
6,168 KB
testcase_31 AC 9 ms
10,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define PC(x) __builtin_popcount(x)
#define PCL(x) __builtin_popcountll(x)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tp;
struct edge {
    int to, cost, id;
};
const double PI = 3.14159265358979323846;
const double PI2 = PI * 2.0;
const double EPS = 1E-09;
const ll MOD = 1E+09 + 7; // =998244353;
const ll INFL = 1E18;
const int INFI = 1E09;
const int MAX_N = 2E+05;

ll dx[4] = { 0, -1, 0, 1 }, dy[4] = { 1, 0, -1, 0 };

ll N;
int V[4];
tp dp[101][101][101][65];

tp calc(tp t)
{
    vector<int> v;
    v.push_back(get<0>(t));
    v.push_back(get<1>(t));
    v.push_back(get<2>(t));
    int sum = 0;
    for (int i = 0; i < 3; ++i) {
        sum += v[i];
    }
    v.push_back(V[0] - sum);

    for (int i = 0; i < 4; ++i) {
        int next = (i + 1) % 4;
        if (V[next] - v[next] > v[i]) {
            v[next] += v[i];
            v[i] = 0;
        } else {
            v[i] -= V[next] - v[next];
            v[next] = V[next];
        }
    }
    return { v[0], v[1], v[2] };
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> V[0] >> V[1] >> V[2] >> V[3] >> N;

    for (int v0 = 0; v0 <= V[0]; ++v0) {
        for (int v1 = 0; v0 + v1 <= V[0]; ++v1) {
            for (int v2 = 0; v0 + v1 + v2 <= V[0]; ++v2) {
                dp[v0][v1][v2][0] = calc({ v0, v1, v2 });
            }
        }
    }

    for (int k = 0; k < 64; ++k) {
        for (int v0 = 0; v0 <= V[0]; ++v0) {
            for (int v1 = 0; v0 + v1 <= V[0]; ++v1) {
                for (int v2 = 0; v0 + v1 + v2 <= V[0]; ++v2) {
                    auto t = dp[v0][v1][v2][k];
                    dp[v0][v1][v2][k + 1] = dp[get<0>(t)][get<1>(t)][get<2>(t)][k];
                }
            }
        }
    }

    tp ans = { V[0], 0, 0 };
    int kk = 0;
    ll r = N % 4;
    N /= 4;
    while (N > 0) {
        if (N & 1) {
            ans = dp[get<0>(ans)][get<1>(ans)][get<2>(ans)][kk];
        }
        kk++;
        N /= 2;
    }
    vector<int> v = { get<0>(ans),
        get<1>(ans),
        get<2>(ans) };
    for (int i = 0; i < r; ++i) {
        int next = (i + 1) % 4;
        if (V[next] - v[next] > v[i]) {
            v[next] += v[i];
            v[i] = 0;
        } else {
            v[i] -= V[next] - v[next];
            v[next] = V[next];
        }
    }

    // for (int i = 0; i < N; i++) {
    //     for (int j = 0; j < N; j++) {
    //         cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
    //     }
    // }
    int sum = v[0] + v[1] + v[2];
    cout << v[0] << " " << v[1] << " " << v[2] << " " << V[0] - sum << "\n";

    return 0;
}
0