답안 #577535

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
577535 2022-06-15T04:03:16 Z balbit 치료 계획 (JOI20_treatment) C++14
0 / 100
3000 ms 8380 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define f first
#define s second

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

#define MX(a,b) a =  max(a,b)
#define MN(a,b) a =  min(a,b)
#define FOR(i,a,b) for (int i = a; i<b; ++i)
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<"- "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S && ...y){cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT


const int maxn = 3e5+5;
const int mod = 1e9+7;
const ll inf = 0x3f3f3f3f3f3f3f3f;

struct rect{
    int x,y,r,c,i;

    bool operator < (rect &R) {
        if (y != R.y) return y < R.y;
        return x < R.x;
    }
};

bool isbeg[maxn], isend[maxn]; // for each rectangle, is it the beg or end?????

ll get(vector<rect> v) {
    for (rect &R : v) {
        bug(R.x,R.y,R.r,R.c,R.i);
        bug(isbeg[R.i]);
        bug(isend[R.i]);
    }

    sort(ALL(v));
    vector<ll> dp(SZ(v), inf);
    ll re = inf;
    REP(i, SZ(v)) {
        if (isbeg[v[i].i]) {
            dp[i] = v[i].c;
        }
        else REP(j,i) {
            if (v[j].y + v[j].r + 1 >= v[i].y &&
                v[j].x + v[j].r + 1 >= v[i].x
                ) {
                MN(dp[i], dp[j] + v[i].c);
            }
        }
        if (isend[v[i].i]) {
            MN(re, dp[i]);
        }
    }
    if (re == inf) re = -1;
    return re;
}

signed main(){
    ios::sync_with_stdio(0), cin.tie(0);
    bug(1,2);

    vector<rect> go;
    int n,m; cin>>n>>m;
    REP(i,m) {
        int t,l,r,c; cin>>t>>l>>r>>c;
        --l; --r;
        isbeg[i] = l == 0;
        isend[i] = r == n-1;
        go.pb({l+t, l-t,r-l,c,i});
    }

    ll re =get(go);
    cout<<re<<endl;

}

Compilation message

treatment.cpp: In function 'long long int get(std::vector<rect>)':
treatment.cpp:45:16: warning: unused variable 'R' [-Wunused-variable]
   45 |     for (rect &R : v) {
      |                ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3068 ms 8380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 328 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 328 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3068 ms 8380 KB Time limit exceeded
2 Halted 0 ms 0 KB -