結果

問題 No.20 砂漠のオアシス
ユーザー wakannyaaiwakannyaai
提出日時 2020-02-09 18:07:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 9,348 bytes
コンパイル時間 2,372 ms
コンパイル使用メモリ 189,676 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 12:29:07
合計ジャッジ時間 3,359 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 AC 21 ms
6,676 KB
testcase_06 AC 10 ms
6,676 KB
testcase_07 AC 21 ms
6,676 KB
testcase_08 AC 13 ms
6,676 KB
testcase_09 AC 19 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 4 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 6 ms
6,676 KB
testcase_17 AC 5 ms
6,676 KB
testcase_18 AC 6 ms
6,676 KB
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 3 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*やったぜ。 投稿者:変態糞土方 (8月16日(水)07時14分22秒)

昨日の8月15日にいつもの浮浪者のおっさん(60歳)と先日メールくれた汚れ好きの土方のにいちゃん

(45歳)とわし(53歳)の3人で県北にある川の土手の下で盛りあったぜ。

今日は明日が休みなんでコンビニで酒とつまみを買ってから滅多に人が来ない所なんで、

そこでしこたま酒を飲んでからやりはじめたんや。

3人でちんぽ舐めあいながら地下足袋だけになり持って来たいちぢく浣腸を3本ずつ入れあった。

しばらくしたら、けつの穴がひくひくして来るし、糞が出口を求めて腹の中でぐるぐるしている。

浮浪者のおっさんにけつの穴をなめさせながら、兄ちゃんのけつの穴を舐めてたら、

先に兄ちゃんがわしの口に糞をドバーっと出して来た。

それと同時におっさんもわしも糞を出したんや。もう顔中、糞まみれや、

3人で出した糞を手で掬いながらお互いの体にぬりあったり、

糞まみれのちんぽを舐めあって小便で浣腸したりした。ああ~~たまらねえぜ。

しばらくやりまくってから又浣腸をしあうともう気が狂う程気持ちええんじゃ。

浮浪者のおっさんのけつの穴にわしのちんぽを突うずるっ込んでやると

けつの穴が糞と小便でずるずるして気持ちが良い。

にいちゃんもおっさんの口にちんぽ突っ込んで腰をつかって居る。

糞まみれのおっさんのちんぽを掻きながら、思い切り射精したんや。

それからは、もうめちゃくちゃにおっさんと兄ちゃんの糞ちんぽを舐めあい、

糞を塗りあい、二回も男汁を出した。もう一度やりたいぜ。

やはり大勢で糞まみれになると最高やで。こんな、変態親父と糞あそびしないか。

ああ~~早く糞まみれになろうぜ。

岡山の県北であえる奴なら最高や。わしは163*90*53,おっさんは165*75*60、や

糞まみれでやりたいやつ、至急、メールくれや。

土方姿のまま浣腸して、糞だらけでやろうや。*/
#include "bits/stdc++.h"
#include <unordered_set>
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define Sort(a) sort(a.begin(),a.end())
#define cSort(a,cmp) sort(a.begin(),a.end(),cmp)
#define reSort(a) sort(a.rbegin(), a.rend())
static const ll llMAX = numeric_limits<long long>::max();
static const int intMAX = numeric_limits<int>::max();
static const ll  llMIN = numeric_limits<long long>::min();
static const int intMIN = numeric_limits<int>::min();
static const ll d_5 = 100000;
static const ll d9_7 = 1000000007;
static const ll d_9 = 1000000000;
static const double PI=3.14159265358979323846;
//<<std::setprecision(30)
template<class T>
void Printvector(std::vector<T> a){
  int size = a.size();
  rep(i,size){
    cout<<a[i]<<" ";
  }
  cout<<endl;
}
template<class T>
void Printvector(std::vector<std::vector<T>> a){
  int size = a.size();
  rep(i,size){
    int size2=a[i].size();
    rep(j,size2){
      cout<<a[i][j]<<" ";
    }
    cout<<endl;
  }
  cout<<endl;
}
ll digitpower(ll a,ll b){//aのb乗を計算
  if(b==1){
    return a;
  }else if(b==0){
    return 1;
  }
  if(b%2==1){
    ll tmp = digitpower(a,(b-1)/2);
    tmp%=d9_7;
    tmp*=tmp;
    tmp%=d9_7;
    tmp*=a;
    return (tmp)%d9_7;
  }else{
    ll tmp = digitpower(a,(b)/2);
    tmp%=d9_7;
    tmp*=tmp;
    tmp%=d9_7;
    return (tmp)%d9_7;
  }
}

unordered_map<ll,ll> prime_factor(int64_t n) {
  unordered_map<ll,ll> ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
/*struct datas{
  int num;
  int index;
};
bool cmp(const datas &a, const datas &b)
{
    return a.num < b.num;
}*/
template<class T>
vector<T> getaccum(vector<T> a){
  int size=a.size();
  vector<T> ans(size);
  ans[0]=a[0];
  for(int i=0;i<size-1;i++){
    ans[i+1]=ans[i]+a[i+1];
    ans[i+1]%=d9_7;
  }
  return ans;
}


int main(void){
  int n,v,ox,oy;
  cin>>n>>v>>ox>>oy;
  vii l(n,vi(n));
  rep(i,n)rep(j,n){
    cin>>l[i][j];
  }
  ox--;oy--;
  vii dp(n,vi(n,-1));//可能な体力の最大値
  dp[0][0]=v;
  //まず、オアシスによらないことを目指すパターン
  priority_queue<pair<int,pair<int,int>>> opes;
  opes.push({v,{0,0}});
  while(opes.size()>0&& dp[n-1][n-1]<0){
    int nowx=opes.top().second.first;
    int nowy=opes.top().second.second;
    int nowv=opes.top().first;
    opes.pop();
    if(dp[nowy][nowx]>nowv ){
      continue;
    }
    if(nowx<n-1 && !(nowx+1==ox && nowy == oy)){
      if(dp[nowy][nowx+1]<nowv-l[nowy][nowx+1]){
        dp[nowy][nowx+1]=max(dp[nowy][nowx+1],nowv-l[nowy][nowx+1]);
        opes.push({nowv-l[nowy][nowx+1],{nowx+1,nowy}});
      }
      
    }
    if(nowy<n-1&& !(nowx==ox && nowy+1 == oy)){
      if(dp[nowy+1][nowx]<nowv-l[nowy+1][nowx]){
        dp[nowy+1][nowx]=max(dp[nowy+1][nowx],nowv-l[nowy+1][nowx]);
        opes.push({nowv-l[nowy+1][nowx],{nowx,nowy+1}});
      }
      
    }
    if(nowx>0&& !(nowx-1==ox && nowy == oy)){
      if(dp[nowy][nowx-1]<nowv-l[nowy][nowx-1]){
        dp[nowy][nowx-1]=max(dp[nowy][nowx-1],nowv-l[nowy][nowx-1]);
        opes.push({nowv-l[nowy][nowx-1],{nowx-1,nowy}});
      }
    }
    if(nowy>0&& !(nowx==ox && nowy-1 == oy)){
      if(dp[nowy-1][nowx]<nowv-l[nowy-1][nowx]){
        dp[nowy-1][nowx]=max(dp[nowy-1][nowx],nowv-l[nowy-1][nowx]);
        opes.push({nowv-l[nowy-1][nowx],{nowx,nowy-1}});
      }
      
    }
  }
  if(dp[n-1][n-1]>0){
    cout<<"YES"<<endl;
    return 0;
  }
  if(ox==0 && oy==0){
    cout<<"NO"<<endl;
    return 0;
  }
  vii dp2(n,vi(n,-1));//可能な体力の最大値
  dp2[0][0]=v;
  //次に、オアシスによることを目指すパターン
  opes=priority_queue<pair<int,pair<int,int>>>();
  opes.push({v,{0,0}});
  int finalcost=-1;
  while(opes.size()>0){
    int nowx=opes.top().second.first;
    int nowy=opes.top().second.second;
    int nowv=opes.top().first;
    opes.pop();
    if(dp[nowy][nowx]>nowv){
      continue;
    }
    if(nowx+1==ox && nowy==oy){
      finalcost=max(finalcost,(nowv-l[oy][ox])*2);
      continue;
    }else if(nowx==ox && nowy+1==oy){
      finalcost=max(finalcost,(nowv-l[oy][ox])*2);
      continue;
    }else if(nowx==ox && nowy-1==oy){
      finalcost=max(finalcost,(nowv-l[oy][ox])*2);
      continue;
    }else if(nowx-1==ox && nowy==oy){
      finalcost=max(finalcost,(nowv-l[oy][ox])*2);
      continue;
    }
    if(nowx<n-1){
      if(dp2[nowy][nowx+1]<nowv-l[nowy][nowx+1]){
        dp2[nowy][nowx+1]=max(dp2[nowy][nowx+1],nowv-l[nowy][nowx+1]);
        opes.push({nowv-l[nowy][nowx+1],{nowx+1,nowy}});
      }
      
    }
    if(nowy<n-1){
      if(dp2[nowy+1][nowx]<nowv-l[nowy+1][nowx]){
        dp2[nowy+1][nowx]=max(dp2[nowy+1][nowx],nowv-l[nowy+1][nowx]);
        opes.push({nowv-l[nowy+1][nowx],{nowx,nowy+1}});
      }
      
    }
    if(nowx>0){
      if(dp2[nowy][nowx-1]<nowv-l[nowy][nowx-1]){
        dp2[nowy][nowx-1]=max(dp2[nowy][nowx-1],nowv-l[nowy][nowx-1]);
        opes.push({nowv-l[nowy][nowx-1],{nowx-1,nowy}});
      }
    }
    if(nowy>0){
      if(dp2[nowy-1][nowx]<nowv-l[nowy-1][nowx]){
        dp2[nowy-1][nowx]=max(dp2[nowy-1][nowx],nowv-l[nowy-1][nowx]);
        opes.push({nowv-l[nowy-1][nowx],{nowx,nowy-1}});
      }
      
    }
  }
  if(finalcost>=1){
    //cout<<finalcost<<endl;
    vii dp3(n,vi(n,-1));
    dp3[oy][ox]=finalcost;
    opes=priority_queue<pair<int,pair<int,int>>>();
    opes.push({finalcost,{ox,oy}});
    while(opes.size()>0&&dp3[n-1][n-1]<0){
    int nowx=opes.top().second.first;
    int nowy=opes.top().second.second;
    int nowv=opes.top().first;
    opes.pop();
    if(dp[nowy][nowx]>nowv){
      continue;
    }
    if(nowx<n-1 && !(nowx+1==ox && nowy == oy)){
      if(dp3[nowy][nowx+1]<nowv-l[nowy][nowx+1]){
        dp3[nowy][nowx+1]=max(dp3[nowy][nowx+1],nowv-l[nowy][nowx+1]);
        opes.push({nowv-l[nowy][nowx+1],{nowx+1,nowy}});
      }
      
    }
    if(nowy<n-1&& !(nowx==ox && nowy+1 == oy)){
      if(dp3[nowy+1][nowx]<nowv-l[nowy+1][nowx]){
        dp3[nowy+1][nowx]=max(dp3[nowy+1][nowx],nowv-l[nowy+1][nowx]);
        opes.push({nowv-l[nowy+1][nowx],{nowx,nowy+1}});
      }
      
    }
    if(nowx>0&& !(nowx-1==ox && nowy == oy)){
      if(dp3[nowy][nowx-1]<nowv-l[nowy][nowx-1]){
        dp3[nowy][nowx-1]=max(dp3[nowy][nowx-1],nowv-l[nowy][nowx-1]);
        opes.push({nowv-l[nowy][nowx-1],{nowx-1,nowy}});
      }
    }
    if(nowy>0&& !(nowx==ox && nowy-1 == oy)){
      if(dp3[nowy-1][nowx]<nowv-l[nowy-1][nowx]){
        dp3[nowy-1][nowx]=max(dp3[nowy-1][nowx],nowv-l[nowy-1][nowx]);
        opes.push({nowv-l[nowy-1][nowx],{nowx,nowy-1}});
      }
      
    }
  }
    if(dp3[n-1][n-1]>0){
        cout<<"YES"<<endl;
      }else{
        cout<<"NO"<<endl;
      }

  }else{
    cout<<"NO"<<endl;
  }
  
  return 0;
}
0