結果
問題 | No.1935 Water Simulation |
ユーザー | sahiya |
提出日時 | 2022-05-13 22:52:57 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 435 ms / 2,000 ms |
コード長 | 3,241 bytes |
コンパイル時間 | 2,270 ms |
コンパイル使用メモリ | 152,112 KB |
実行使用メモリ | 158,720 KB |
最終ジャッジ日時 | 2024-07-22 04:36:58 |
合計ジャッジ時間 | 7,651 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 435 ms
158,592 KB |
testcase_01 | AC | 421 ms
158,720 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 211 ms
98,816 KB |
testcase_04 | AC | 33 ms
24,192 KB |
testcase_05 | AC | 232 ms
105,344 KB |
testcase_06 | AC | 359 ms
137,728 KB |
testcase_07 | AC | 75 ms
46,464 KB |
testcase_08 | AC | 86 ms
52,480 KB |
testcase_09 | AC | 259 ms
119,040 KB |
testcase_10 | AC | 222 ms
105,216 KB |
testcase_11 | AC | 43 ms
30,464 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 18 ms
14,720 KB |
testcase_15 | AC | 133 ms
73,088 KB |
testcase_16 | AC | 106 ms
63,232 KB |
testcase_17 | AC | 48 ms
31,872 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 428 ms
154,368 KB |
testcase_20 | AC | 4 ms
5,376 KB |
testcase_21 | AC | 117 ms
70,528 KB |
testcase_22 | AC | 147 ms
81,024 KB |
testcase_23 | AC | 17 ms
13,952 KB |
testcase_24 | AC | 346 ms
137,728 KB |
testcase_25 | AC | 305 ms
126,208 KB |
testcase_26 | AC | 3 ms
5,376 KB |
testcase_27 | AC | 35 ms
25,344 KB |
testcase_28 | AC | 22 ms
17,024 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 3 ms
5,376 KB |
testcase_31 | AC | 10 ms
9,984 KB |
ソースコード
#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; }