답안 #423741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423741 2021-06-11T12:14:29 Z lyc 치료 계획 (JOI20_treatment) C++14
5 / 100
401 ms 2428 KB
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef pair<int,int> ii;

const int mxN = 100001;

int N, M;
struct Treatment {
    int T, L, R, C;
};
vector<Treatment> treat;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> N >> M;
    FOR(i,1,M){
        int T, L, R, C;
        cin >> T >> L >> R >> C;
        treat.push_back({T,L,R,C});
    }
    sort(ALL(treat),[](Treatment &a, Treatment &b){ return a.T < b.T; });

    ll ans = 1e18;
    FOR(b,0,(1<<M)-1){
        set<ii> ranges, tmp;
        ranges.insert(ii(1,N));
        int t = 1;
        ll cost = 0;
        FOR(i,0,M-1) if (b&(1<<i)) {
            auto tr = treat[i];
            cost += tr.C;
            if (t < tr.T) {
                int e = tr.T - t;
                t = tr.T;
                tmp.clear();
                for (auto it = ranges.begin(), y = it; it != ranges.end(); ++it) {
                    auto x = *it;
                    x.first = max(1,x.first-e);
                    x.second = min(N,x.second+e);
                    while ((y = next(it)) != ranges.end()) {
                        if (x.second >= y->first-e) {
                            x.second = min(N,y->second+e);
                            ranges.erase(y);
                        } else break;
                    }
                    tmp.insert(x);
                }
                ranges = tmp;
            }

            tmp.clear();
            for (auto& x : ranges) {
                if (x.second < tr.L || x.first > tr.R) tmp.insert(x);
                else {
                    if (x.first < tr.L) tmp.insert(ii(x.first,tr.L-1));
                    if (x.second > tr.R) tmp.insert(ii(tr.R+1,x.second));
                }
            }
            ranges = tmp;
        }
        if (ranges.empty()) {
            //TRACE(b _ cost);
            ans = min(ans,cost);
        }
    }
    if (ans == 1e18) cout << -1 << '\n';
    else cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 2428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 66 ms 256 KB Output is correct
3 Correct 64 ms 204 KB Output is correct
4 Correct 104 ms 204 KB Output is correct
5 Correct 107 ms 204 KB Output is correct
6 Correct 74 ms 204 KB Output is correct
7 Correct 119 ms 204 KB Output is correct
8 Correct 264 ms 284 KB Output is correct
9 Correct 103 ms 284 KB Output is correct
10 Correct 173 ms 204 KB Output is correct
11 Correct 401 ms 304 KB Output is correct
12 Correct 127 ms 324 KB Output is correct
13 Correct 92 ms 204 KB Output is correct
14 Correct 85 ms 292 KB Output is correct
15 Correct 88 ms 300 KB Output is correct
16 Correct 92 ms 288 KB Output is correct
17 Correct 125 ms 204 KB Output is correct
18 Correct 67 ms 284 KB Output is correct
19 Correct 114 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 66 ms 256 KB Output is correct
3 Correct 64 ms 204 KB Output is correct
4 Correct 104 ms 204 KB Output is correct
5 Correct 107 ms 204 KB Output is correct
6 Correct 74 ms 204 KB Output is correct
7 Correct 119 ms 204 KB Output is correct
8 Correct 264 ms 284 KB Output is correct
9 Correct 103 ms 284 KB Output is correct
10 Correct 173 ms 204 KB Output is correct
11 Correct 401 ms 304 KB Output is correct
12 Correct 127 ms 324 KB Output is correct
13 Correct 92 ms 204 KB Output is correct
14 Correct 85 ms 292 KB Output is correct
15 Correct 88 ms 300 KB Output is correct
16 Correct 92 ms 288 KB Output is correct
17 Correct 125 ms 204 KB Output is correct
18 Correct 67 ms 284 KB Output is correct
19 Correct 114 ms 204 KB Output is correct
20 Incorrect 27 ms 460 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 2428 KB Output isn't correct
2 Halted 0 ms 0 KB -