제출 #437266

#제출 시각아이디문제언어결과실행 시간메모리
437266errorgornDungeons Game (IOI21_dungeons)C++17
63 / 100
4463 ms926144 KiB
#include "dungeons.h"

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back

#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
ll win_s[50005];
ll lose_s[50005];
ll win_n[50005];
ll lose_n[50005];

struct edge{
  int to;
  ll sum;
  ll mx; //we cant have more strength or we will overshoot
};

vector<ll> ds;
edge tkd[28][50005][28];

void init(int N, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l) {
  n=N;

  rep(x,0,n) win_s[x]=s[x];
  rep(x,0,n) lose_s[x]=p[x];
  rep(x,0,n) win_n[x]=w[x];
  rep(x,0,n) lose_n[x]=l[x];

  for (int x=1;x<2e7;x<<=1) ds.pub(x); //start of bueket sizes
  ds.pub(1e18);

  //for (auto &it:ds) cout<<it<<" "; cout<<endl;

  memset(tkd,-1,sizeof(tkd));

  rep(i,0,sz(ds)-1){
    rep(x,0,n){
      if (win_s[x]<ds[i]){ //cfm will win
        tkd[i][x][0]=edge({win_n[x],win_s[x],(ll)1e18});
      }
      else if (win_s[x]<ds[i+1]){ //by default, we lose, but if we win we must stop!
        tkd[i][x][0]=edge({lose_n[x],lose_s[x],win_s[x]});
      }
      else{ //cfm will lose
        tkd[i][x][0]=edge({lose_n[x],lose_s[x],(ll)1e18});
      }
    }

    rep(y,0,27){
      rep(x,0,n){
        int temp=tkd[i][x][y].to;

        if (temp==-1 || tkd[i][temp][y].to==-1) continue;

        edge res=edge({
          tkd[i][temp][y].to,
          tkd[i][x][y].sum+tkd[i][temp][y].sum,
          min(tkd[i][x][y].mx,tkd[i][temp][y].mx-tkd[i][x][y].sum)
        });

        tkd[i][x][y+1]=res;
      }
    }
  }
}

long long simulate(int CURR, int S) {
  ll curr=CURR,s=S;

  rep(x,0,sz(ds)-1){
    //when we traverse a edge we cannot overshoot over some guy whos in our bucket
    //also sum must be contained in the bucket

    rep(y,28,0){
      if (tkd[x][curr][y].to!=-1 && s+tkd[x][curr][y].sum<ds[x+1] && s<tkd[x][curr][y].mx){
        tie(curr,s)=ii(tkd[x][curr][y].to,s+tkd[x][curr][y].sum);
      }
    }

    //cout<<"debug: "<<curr<<" "<<s<<endl;

    if (curr==n) break;

    //manually do extra one
    if (win_s[curr]<=s){
      s+=win_s[curr];
      curr=win_n[curr];
    }
    else{
      s+=lose_s[curr];
      curr=lose_n[curr];
    }
  }

  return s;

}

컴파일 시 표준 에러 (stderr) 메시지

dungeons.cpp: In function 'void init(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
dungeons.cpp:55:35: warning: narrowing conversion of 'win_n[x]' from 'long long int' to 'int' [-Wnarrowing]
   55 |         tkd[i][x][0]=edge({win_n[x],win_s[x],(ll)1e18});
      |                            ~~~~~~~^
dungeons.cpp:58:36: warning: narrowing conversion of 'lose_n[x]' from 'long long int' to 'int' [-Wnarrowing]
   58 |         tkd[i][x][0]=edge({lose_n[x],lose_s[x],win_s[x]});
      |                            ~~~~~~~~^
dungeons.cpp:61:36: warning: narrowing conversion of 'lose_n[x]' from 'long long int' to 'int' [-Wnarrowing]
   61 |         tkd[i][x][0]=edge({lose_n[x],lose_s[x],(ll)1e18});
      |                            ~~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...