結果
| 問題 |
No.1935 Water Simulation
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2022-05-13 21:45:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 2,000 ms |
| コード長 | 3,209 bytes |
| コンパイル時間 | 1,534 ms |
| コンパイル使用メモリ | 132,260 KB |
| 最終ジャッジ日時 | 2025-01-29 06:46:13 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
return vector<vector<T>>(n, vector<T>(m, v));
}
template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}
template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
if(v.empty()) {
cout << endl;
return;
}
for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
cout << v.back() << endl;
}
using T = tuple<int, int, int>;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout << setprecision(10) << fixed;
vector<int> v(4);
for(int i = 0; i < 4; i++) cin >> v[i];
ll n; cin >> n;
auto calc = [&](int a, int b, int c, int cnt=4){
vector<int> u = {a, b, c, v[0]-(a+b+c)};
// cout << "=====" << endl;
// print_vector(u);
for(int i = 0; i < cnt; i++){
int j = (i+1)%4;
if(u[i]+u[j] >= v[j]){
u[i] -= v[j]-u[j];
u[j] = v[j];
}else{
u[j] += u[i];
u[i] = 0;
}
// print_vector(u);
}
return T(u[0], u[1], u[2]);
};
auto nx = vec3d(v[0]+1, v[1]+1, v[2]+1, T(0, 0, 0));
for(int a = 0; a <= v[0]; a++){
for(int b = 0; a+b <= v[0] && b <= v[1]; b++){
for(int c = 0; a+b+c <= v[0] && c <= v[2]; c++){
nx[a][b][c] = calc(a, b, c);
}
}
}
auto dist = vec3d(v[0]+1, v[1]+1, v[2]+1, -1);
T cur(v[0], 0, 0);
dist[v[0]][0][0] = 0;
vector<T> path;
int cycle_start = -1;
int cycle_len = 0;
while(true){
path.push_back(cur);
auto [a, b, c] = cur;
auto [aa, bb, cc] = nx[a][b][c];
if(dist[aa][bb][cc] == -1){
dist[aa][bb][cc] = dist[a][b][c]+1;
cur = T(aa, bb, cc);
}else{
cycle_start = dist[aa][bb][cc];
cycle_len = dist[a][b][c]+1-dist[aa][bb][cc];
break;
}
}
ll len = n/4;
int rem = n%4;
if(len <= cycle_start){
auto [a, b, c] = path[len];
auto [aa, bb, cc] = calc(a, b, c, rem);
cout << aa << ' ' << bb << ' ' << cc << ' ' << v[0]-(aa+bb+cc) << endl;
}else{
int l = (len-cycle_start)%cycle_len;
auto [a, b, c] = path[cycle_start+l];
auto [aa, bb, cc] = calc(a, b, c, rem);
cout << aa << ' ' << bb << ' ' << cc << ' ' << v[0]-(aa+bb+cc) << endl;
}
}
milanis48663220