제출 #1309655

#제출 시각아이디문제언어결과실행 시간메모리
1309655ilovewaguriFuel Station (NOI20_fuelstation)C++20
0 / 100
62 ms6728 KiB
#include<bits/stdc++.h>
using namespace std;
#define NAME "FFUEL"
#define nl '\n'
#define allofa(x,sz) x+1,x+sz+1
#define allof(x) x.begin(),x.end()
#define mset(x,val) memset(x,val,sizeof(x))
template<typename T> T Max(T x, T y){return(x>y)?x:y;};
template<typename T> T Min(T x, T y){return(x<y)?x:y;};
template<class X,class Y> bool minimize(X &a, Y b){if(a>b){a=b;return true;}return false;};
template<class X,class Y> bool maximize(X &a, Y b){if(a<b){a=b;return true;}return false;};
typedef long long ll;
const ll mod = (long long)1e9+7;
const ll LINF = (long long)1e18;
const int INF = (int)1e9;
const int MAXN = (int)3e5+5;
int n,d;

void ccps() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    if(fopen(NAME".inp","r")) {
        freopen(NAME".inp","r",stdin);
        freopen(NAME".out","w",stdout);
    }
}

struct station {
    int p,a,b;
    station(): p(0), a(0), b(0) {}
    station(int P, int A, int B): p(P), a(A), b(B) {}
    bool operator <(const station &ot) const {
        if(p==ot.p) {
            return -a<-ot.a;
        }
        return p<ot.p;
    }
};
vector<station> st;

namespace sub1 {
    bool check() {
        return n==1;
    }

    bool check(int mid) {
        return mid-st[0].p+st[0].a>=d-st[0].p;
    }

    void sol() {
        int lo = Min<int>(st[0].p,st[0].a), hi = st[0].b;
        int res = 0;
        while(lo<=hi) {
            int mid = (lo+hi)>>1;
            if(check(mid)) {
                res = mid;
                hi = mid-1;
            }
            else lo = mid+1;
        }
        cout << res;
    }
}

namespace sub3 {
    bool check() {
        return d<=1e4 and n<=1e4;
    }

    void sol() {
        sort(allof(st));
        st.push_back({d,0,0});
        int res = INF;
        for (int f = d; f>=0; f--) {
            bool canGo = true;
            for (int i = 0; i<n; i++) {
                if(f>st[i].b) {
                    canGo = false;
                    break;
                }
            }
            if(!canGo) continue;
            int cur = f;
            if(st[0].p>cur) continue;
            for (int i = 0; i<n; i++) {
                if(i>0 and st[i].p==st[i-1].p) continue;
                cur-=(st[i].p-(i>0?st[i-1].p:0));
                cur+=st[i].a;
                if(st[i+1].p - st[i].p>cur) {
                    canGo = false;
                    break;
                }
            }
            if(canGo) minimize(res, f);
        }
        cout << res;
    }
}

signed main() {
    ccps();
    cin >> n >> d;
    for (int i = 1; i<=n; i++) {
        int x,a,b; cin >> x >> a >> b;
        st.push_back({x,a,b});
    }
   if(sub1::check()) return sub1::sol(),0;
   else if(sub3::check()) return sub3::sol(),0;
}

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

FuelStation.cpp: In function 'void ccps()':
FuelStation.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
FuelStation.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(NAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...