Submission #577556

# Submission time Handle Problem Language Result Execution time Memory
577556 2022-06-15T04:40:47 Z balbit Treatment Project (JOI20_treatment) C++14
35 / 100
3000 ms 10924 KB
#include <bits/stdc++.h>
using namespace std;
#define int ll
#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?????
bool done[maxn];
ll dst[maxn];

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));

    memset(dst, 0x3f, sizeof dst);
    int n = SZ(v);
    for (rect &R : v) {
        if (isbeg[R.i]) {
            dst[R.i] = R.c;

        }
    }

    ll re = inf;
    REP(round, SZ(v)) {
        int go = -1, mnd = inf;
        REP(i,n)  {
            if (!done[i] && dst[i] < mnd) {
                mnd = dst[i]; go = i;
            }
        }
        if (go == -1) break;
        done[go] = 1;
        if (isend[go]) {
            MN(re, mnd);
        }

        REP(j,n) {
            if (!done[j]) {
                // test if i can update him
                if (v[go].x + v[go].r + 1 >= v[j].x &&
                    v[go].y + v[go].r + 1 >= v[j].y
                    ) {
                    MN(dst[j], dst[go] + v[j].c);
                }
            }
        }

    }
    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;

}

/*
10 5
1 8 10 30
1 1 6 50
2 7 7 100
3 5 7 11
2 8 8 11



7 6 10 4
4 1 3 1
*/

Compilation message

treatment.cpp: In function 'long long int get(std::vector<rect>)':
treatment.cpp:47:16: warning: unused variable 'R' [-Wunused-variable]
   47 |     for (rect &R : v) {
      |                ^
# Verdict Execution time Memory Grader output
1 Execution timed out 3072 ms 10924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2632 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2632 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2676 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2632 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2632 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2676 KB Output is correct
14 Correct 1 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 161 ms 3340 KB Output is correct
21 Correct 161 ms 3324 KB Output is correct
22 Correct 174 ms 3344 KB Output is correct
23 Correct 117 ms 3340 KB Output is correct
24 Correct 182 ms 3404 KB Output is correct
25 Correct 80 ms 3312 KB Output is correct
26 Correct 48 ms 3344 KB Output is correct
27 Correct 44 ms 3312 KB Output is correct
28 Correct 180 ms 3404 KB Output is correct
29 Correct 62 ms 3344 KB Output is correct
30 Correct 6 ms 3344 KB Output is correct
31 Correct 4 ms 3344 KB Output is correct
32 Correct 193 ms 3412 KB Output is correct
33 Correct 159 ms 3396 KB Output is correct
34 Correct 141 ms 3344 KB Output is correct
35 Correct 186 ms 3372 KB Output is correct
36 Correct 163 ms 3344 KB Output is correct
37 Correct 135 ms 3360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3072 ms 10924 KB Time limit exceeded
2 Halted 0 ms 0 KB -