結果

問題 No.1935 Water Simulation
ユーザー gs18115gs18115
提出日時 2022-05-13 22:00:45
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,563 bytes
コンパイル時間 454 ms
使用メモリ 18,272 KB
最終ジャッジ日時 2023-02-21 18:48:37
合計ジャッジ時間 1,989 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 3 ms
6,252 KB
testcase_01 AC 2 ms
6,208 KB
testcase_02 AC 2 ms
6,212 KB
testcase_03 AC 5 ms
8,800 KB
testcase_04 AC 3 ms
6,276 KB
testcase_05 AC 7 ms
12,488 KB
testcase_06 AC 5 ms
10,304 KB
testcase_07 AC 5 ms
10,168 KB
testcase_08 AC 5 ms
10,388 KB
testcase_09 AC 7 ms
11,600 KB
testcase_10 AC 6 ms
9,908 KB
testcase_11 AC 4 ms
7,536 KB
testcase_12 AC 2 ms
6,200 KB
testcase_13 AC 2 ms
6,196 KB
testcase_14 AC 5 ms
9,076 KB
testcase_15 AC 3 ms
6,168 KB
testcase_16 AC 8 ms
12,660 KB
testcase_17 AC 5 ms
9,952 KB
testcase_18 AC 1 ms
6,200 KB
testcase_19 AC 5 ms
8,012 KB
testcase_20 AC 2 ms
6,264 KB
testcase_21 AC 8 ms
13,588 KB
testcase_22 AC 2 ms
6,264 KB
testcase_23 AC 4 ms
8,644 KB
testcase_24 AC 11 ms
18,272 KB
testcase_25 AC 3 ms
7,012 KB
testcase_26 AC 2 ms
6,196 KB
testcase_27 AC 4 ms
8,372 KB
testcase_28 AC 3 ms
6,516 KB
testcase_29 AC 1 ms
6,164 KB
testcase_30 AC 2 ms
6,168 KB
testcase_31 AC 3 ms
6,192 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