結果
| 問題 |
No.1935 Water Simulation
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2022-05-13 21:30:01 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,629 bytes |
| コンパイル時間 | 3,162 ms |
| コンパイル使用メモリ | 125,492 KB |
| 最終ジャッジ日時 | 2025-01-29 06:37:13 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
int hash_4(int a, int b, int c, int d){
b += a * 101;
c += b * 101;
d += c * 101;
return d;
}
int main(){
unordered_map<int, int> A;
int ax,bx,cx,dx; cin >> ax >> bx >> cx >> dx;
int a,b,c,d;
a = ax; b = c = d = 0;
i64 K; cin >> K;
i64 k = K / 4;
i64 t = 0;
A[hash_4(a,b,c,d)] = t;
int f;
while(k){
t++; k--;
f = min(a,bx-b); a -= f; b += f;
f = min(b,cx-c); b -= f; c += f;
f = min(c,dx-d); c -= f; d += f;
f = min(d,ax-a); d -= f; a += f;
int id = hash_4(a,b,c,d);
if(A.count(id)){
i64 cy = t - A[id];
k %= cy;
break;
}
A[id] = t;
}
while(k){
t++; k--;
int f;
f = min(a,bx-b); a -= f; b += f;
f = min(b,cx-c); b -= f; c += f;
f = min(c,dx-d); c -= f; d += f;
f = min(d,ax-a); d -= f; a += f;
}
K %= 4;
if(K){ K--; f = min(a,bx-b); a -= f; b += f; }
if(K){ K--; f = min(b,cx-c); b -= f; c += f; }
if(K){ K--; f = min(c,dx-d); c -= f; d += f; }
if(K){ K--; f = min(d,ax-a); d -= f; a += f; }
cout << a << " " << b << " " << c << " " << d << endl;
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia