結果

問題 No.1935 Water Simulation
ユーザー gs18115gs18115
提出日時 2022-05-13 22:00:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,563 bytes
コンパイル時間 599 ms
コンパイル使用メモリ 70,416 KB
実行使用メモリ 24,152 KB
最終ジャッジ日時 2023-09-29 10:00:46
合計ジャッジ時間 1,877 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
23,900 KB
testcase_01 AC 6 ms
23,948 KB
testcase_02 AC 3 ms
11,572 KB
testcase_03 AC 6 ms
23,832 KB
testcase_04 AC 5 ms
17,960 KB
testcase_05 AC 6 ms
24,152 KB
testcase_06 AC 5 ms
23,900 KB
testcase_07 AC 4 ms
19,732 KB
testcase_08 AC 6 ms
19,744 KB
testcase_09 AC 6 ms
23,856 KB
testcase_10 AC 5 ms
23,860 KB
testcase_11 AC 4 ms
17,696 KB
testcase_12 AC 3 ms
11,544 KB
testcase_13 AC 3 ms
11,612 KB
testcase_14 AC 4 ms
15,696 KB
testcase_15 AC 5 ms
21,932 KB
testcase_16 AC 6 ms
21,836 KB
testcase_17 AC 5 ms
17,808 KB
testcase_18 AC 3 ms
9,568 KB
testcase_19 AC 5 ms
24,112 KB
testcase_20 AC 3 ms
13,740 KB
testcase_21 AC 5 ms
22,056 KB
testcase_22 AC 5 ms
21,808 KB
testcase_23 AC 4 ms
15,932 KB
testcase_24 AC 6 ms
24,072 KB
testcase_25 AC 5 ms
23,860 KB
testcase_26 AC 3 ms
11,572 KB
testcase_27 AC 4 ms
17,804 KB
testcase_28 AC 3 ms
15,696 KB
testcase_29 AC 2 ms
9,492 KB
testcase_30 AC 3 ms
11,836 KB
testcase_31 AC 4 ms
15,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
int dp[101][101][101][4];
int va[4140101];
int vb[440101];
int vc[4140101];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c,d;
    ll n;
    cin>>a>>b>>c>>d>>n;
    for(int i=0;i<=a;i++)
        for(int j=0;j<=b;j++)
            for(int k=0;k<=c;k++)
                for(int l=0;l<4;l++)
                    dp[i][j][k][l]=-1;
    int ca=a,cb=0,cc=0,cd=0;
    dp[ca][cb][cc][0]=0;
    va[0]=ca;
    int ip=-1,cyc=0;
    for(int i=1;i<=n;i++)
    {
        if(i%4==0)
        {
            int v=min(cd,a-ca);
            cd-=v;
            ca+=v;
        }
        else if(i%4==1)
        {
            int v=min(ca,b-cb);
            ca-=v;
            cb+=v;
        }
        else if(i%4==2)
        {
            int v=min(cb,c-cc);
            cb-=v;
            cc+=v;
        }
        else
        {
            int v=min(cc,d-cd);
            cc-=v;
            cd+=v;
        }
        if(dp[ca][cb][cc][i%4]!=-1)
        {
            ip=dp[ca][cb][cc][i%4];
            cyc=i-ip;
            break;
        }
        dp[ca][cb][cc][i%4]=i;
        va[i]=ca,vb[i]=cb,vc[i]=cc;
    }
    if(ip!=-1)
        n=(n-ip)%cyc+ip;
    cout<<va[n]<<' '<<vb[n]<<' '<<vc[n]<<' '<<a-va[n]-vb[n]-vc[n]<<endl;
    return 0;
}
0