結果

問題 No.1935 Water Simulation
ユーザー umezo
提出日時 2022-05-14 02:47:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 2,180 ms
コンパイル使用メモリ 203,900 KB
最終ジャッジ日時 2025-01-29 07:51:36
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  vector<int> V(4),A(4);
  rep(i,4) cin>>V[i];
  A[0]=V[0];
  ll n;
  cin>>n;
  
  auto f=[&](int i){
    int dif=min(V[(i+1)%4]-A[(i+1)%4],A[i]);
    A[(i+1)%4]+=dif;
    A[i]-=dif;
  };
  
  if(n<10000000){
    rep(i,n) f(i%4);
    rep(i,4){
      if(i) cout<<" ";
      cout<<A[i];
    }
    cout<<endl;
    return 0;
  }
  
  map<vector<int>,int> m;
  m[A]=0;
  int cnt=0,c,a,b;
  while(1){
    cnt++;
    f((cnt-1)%4);
    if(cnt%4==0){
      if(m.count(A)){
        a=m[A];
        b=cnt-a;
        c=cnt-1;
        break;
      }
      m[A]=4*cnt;
    }
  }
  n=(n-a)%b+a;
  rep(i,4) A[i]=0;
  A[0]=V[0];
  rep(i,n) f(i%4);
  rep(i,4){
    if(i) cout<<" ";
    cout<<A[i];
  }
  cout<<endl;
  
  return 0;
}
0