結果
問題 | No.1935 Water Simulation |
ユーザー | sahiya |
提出日時 | 2022-05-13 22:52:57 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 371 ms / 2,000 ms |
コード長 | 3,241 bytes |
コンパイル時間 | 2,152 ms |
コンパイル使用メモリ | 151,140 KB |
実行使用メモリ | 284,888 KB |
最終ジャッジ日時 | 2023-09-29 10:03:16 |
合計ジャッジ時間 | 6,961 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 364 ms
251,996 KB |
testcase_01 | AC | 371 ms
252,124 KB |
testcase_02 | AC | 3 ms
13,688 KB |
testcase_03 | AC | 168 ms
254,772 KB |
testcase_04 | AC | 50 ms
192,664 KB |
testcase_05 | AC | 181 ms
258,404 KB |
testcase_06 | AC | 312 ms
273,740 KB |
testcase_07 | AC | 87 ms
228,304 KB |
testcase_08 | AC | 95 ms
231,960 KB |
testcase_09 | AC | 216 ms
266,368 KB |
testcase_10 | AC | 190 ms
258,076 KB |
testcase_11 | AC | 61 ms
223,436 KB |
testcase_12 | AC | 6 ms
21,948 KB |
testcase_13 | AC | 5 ms
17,844 KB |
testcase_14 | AC | 33 ms
137,372 KB |
testcase_15 | AC | 123 ms
240,868 KB |
testcase_16 | AC | 109 ms
236,444 KB |
testcase_17 | AC | 70 ms
227,740 KB |
testcase_18 | AC | 3 ms
11,580 KB |
testcase_19 | AC | 345 ms
284,888 KB |
testcase_20 | AC | 12 ms
54,824 KB |
testcase_21 | AC | 119 ms
239,304 KB |
testcase_22 | AC | 144 ms
245,856 KB |
testcase_23 | AC | 32 ms
132,976 KB |
testcase_24 | AC | 319 ms
275,664 KB |
testcase_25 | AC | 226 ms
269,676 KB |
testcase_26 | AC | 9 ms
42,416 KB |
testcase_27 | AC | 52 ms
198,956 KB |
testcase_28 | AC | 38 ms
153,672 KB |
testcase_29 | AC | 3 ms
7,476 KB |
testcase_30 | AC | 6 ms
26,240 KB |
testcase_31 | AC | 24 ms
106,244 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; }