結果

問題 No.1935 Water Simulation
ユーザー HIcoderHIcoder
提出日時 2023-07-18 17:28:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,696 bytes
コンパイル時間 1,255 ms
コンパイル使用メモリ 118,336 KB
実行使用メモリ 814,160 KB
最終ジャッジ日時 2023-10-18 20:48:24
合計ジャッジ時間 7,618 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
MLE
*/
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include<tuple>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;

typedef tuple<int,int,int,int> TP;
//typedef vector<int> TP;



int V1,V2,V3,V4;


vector<int> V(4);

/*
TP func(int t1,int t2,int t3,int t4,ll idx){

    TP res=make_tuple(t1,t2,t3,t4);
    if(idx==0){
        int u1=t1-min(V2-t2,t1);
        int u2=t2+min(V2-t2,t1);
        res=make_tuple(u1,u2,t3,t4);
    }
    else if(idx==1){
        int u2=t2-min(V3-t3,t2);
        int u3=t3+min(V3-t3,t2);
        res=make_tuple(t1,u2,u3,t4);
    }else if(idx==2){
        int u3=t3-min(V4-t4,t3);
        int u4=t4+min(V3-t3,t3);
        res=make_tuple(t1,t2,u3,t4);
    }else if(idx==3){
        int u4=t3-min(V1-t1,t3);
        int u1=t1+min(V1-t1,t3);
        res=make_tuple(u1,t2,t3,u4);

    }

    return res;
}
*/

vector<int> func(const vector<int>& t,int idx){

    vector<int> res(4);
    for(int i=0;i<4;i++){
        res[i]=t[i];
    }

    res[idx]=t[idx] - min(V[(idx+1)%4] - t[(idx+1)%4],t[idx]);
    res[(idx+1)%4]=t[(idx+1)%4] + min(V[(idx+1)%4] - t[(idx+1)%4],t[idx]);

    return res;
}


int main(){
    ll N;

    for(int i=0;i<4;i++){
        cin>>V[i];
    }
    cin>>N;

    vector<vector<int>> history;
    map<vector<int>,int> mp;



    auto now=vector<int>{V[0],0,0,0};

    int sz=0;

    int offset=-1;


    vector<vector<int>> cyclehistory;

    while(1){
        /*
        cout<<"sz="<<sz<<endl;
        for(int v:now){
            cout<<v<<' ';
        }
        cout<<endl;
        */


       
        if(mp.count(now)){
            if(offset==-1){
                offset=mp[now];
                cyclehistory.push_back(now);
            }else{
                

                if(mp[now]==offset){
                    break;
                }

                cyclehistory.push_back(now);
            }

    

        }else{
            mp[now]=sz;
        }
        

        history.push_back(now);

        auto nx=func(now,sz%4);

        /*
        for(int v:nx){
            cout<<v<<' ';
        }
        cout<<endl;
        */



        sz++;
        now=nx;
    }

    
    int cycle=cyclehistory.size();
    //cout<<"offset="<<offset<<",cycle="<<cycle<<endl;

    if(N<offset){

        for(int v:history[N]){
            cout<<v<<' ';
        }
        cout<<endl;
    }else{
        N-=offset;
        N%=cycle;


        
        for(int v:cyclehistory[N]){
            cout<<v<<' ';
        }
        cout<<endl;

    }


}
0