Submission #1046919

# Submission time Handle Problem Language Result Execution time Memory
1046919 2024-08-07T06:18:16 Z 변재우(#11026) Treatment Project (JOI20_treatment) C++17
5 / 100
30 ms 600 KB
// #include <bits/stdc++.h>
// #define int long long
// using namespace std;

// const int Nmax=5010, INF=1e18;
// int N, M, T[Nmax], L[Nmax], R[Nmax], C[Nmax], D[Nmax];
// vector<int> adj[Nmax];
// priority_queue<pair<int, int>> PQ;

// signed main() {
//     ios_base::sync_with_stdio(0); cin.tie(0);
//     cin>>N>>M;
//     for(int i=1; i<=M; i++) {
//         cin>>T[i]>>L[i]>>R[i]>>C[i];
//         if(L[i]==1) adj[0].push_back(i);
//         if(R[i]==N) adj[i].push_back(M+1);
//     }
//     for(int i=1; i<=M; i++) for(int j=i+1; j<=M; j++) {
//         int l1=L[i]+max(0ll, T[j]-T[i]), r1=R[i]-max(0ll, T[j]-T[i]);
//         int l2=L[j]+max(0ll, T[i]-T[j]), r2=R[j]-max(0ll, T[i]-T[j]);
//         if(l1>r1 || l2>r2) continue;
//         if(!(l1>r2+1 || l2>r1+1)) adj[i].push_back(j), adj[j].push_back(i);
//     }
//     fill(D+1, D+M+2, INF);
//     PQ.push({0, 0});
//     while(!PQ.empty()) {
//         int curr=PQ.top().second, dist=-PQ.top().first; PQ.pop();
//         if(dist!=D[curr]) continue;
//         for(int next:adj[curr]) if(D[next]>D[curr]+C[next]) D[next]=D[curr]+C[next], PQ.push({-D[next], next});
//     }
//     if(D[M+1]==INF) cout<<-1;
//     else cout<<D[M+1];
//     return 0;
// }

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

const int INF=1e18;
int N, M, ans=INF;
struct Data {int t, l, r, c;}A[16];

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>M;
    for(int i=0; i<M; i++) cin>>A[i].t>>A[i].l>>A[i].r>>A[i].c;
    for(int i=0; i<(1<<M); i++) {
        int sum=0;
        vector<Data> V;
        for(int j=0; j<M; j++) if(i&(1<<j)) V.push_back(A[j]), sum+=A[j].c;
        sort(V.begin(), V.end(), [](Data a, Data b) {return a.t<b.t;});
        vector<pair<int, int>> T;
        for(int j=0; j<V.size(); j++) {
            if(j>0) {
                for(auto &v:T) {
                    if(v.first>1) v.first+=V[j].t-V[j-1].t;
                    if(v.second<N) v.second-=V[j].t-V[j-1].t;
                }
            }
            int l=V[j].l, r=V[j].r;
            for(int k=0; k<T.size(); k++) {
                if(!(T[k].first>r+1 || l>T[k].second+1)) {
                    l=min(l, T[k].first), r=max(r, T[k].second);
                    swap(T[k], T.back()); T.pop_back();
                    k--;
                }
            }
            T.push_back({l, r});
        }
        if(T.size()==1 && T[0].first==1 && T[0].second==N) ans=min(ans, sum);
    }
    if(ans==INF) cout<<-1;
    else cout<<ans;
    return 0;
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:54:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<Data>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for(int j=0; j<V.size(); j++) {
      |                      ~^~~~~~~~~
treatment.cpp:62:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             for(int k=0; k<T.size(); k++) {
      |                          ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 17 ms 456 KB Output is correct
3 Correct 22 ms 456 KB Output is correct
4 Correct 30 ms 348 KB Output is correct
5 Correct 21 ms 348 KB Output is correct
6 Correct 17 ms 456 KB Output is correct
7 Correct 18 ms 452 KB Output is correct
8 Correct 18 ms 348 KB Output is correct
9 Correct 17 ms 348 KB Output is correct
10 Correct 28 ms 348 KB Output is correct
11 Correct 19 ms 348 KB Output is correct
12 Correct 18 ms 348 KB Output is correct
13 Correct 18 ms 456 KB Output is correct
14 Correct 17 ms 348 KB Output is correct
15 Correct 17 ms 348 KB Output is correct
16 Correct 19 ms 348 KB Output is correct
17 Correct 18 ms 344 KB Output is correct
18 Correct 19 ms 348 KB Output is correct
19 Correct 30 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 17 ms 456 KB Output is correct
3 Correct 22 ms 456 KB Output is correct
4 Correct 30 ms 348 KB Output is correct
5 Correct 21 ms 348 KB Output is correct
6 Correct 17 ms 456 KB Output is correct
7 Correct 18 ms 452 KB Output is correct
8 Correct 18 ms 348 KB Output is correct
9 Correct 17 ms 348 KB Output is correct
10 Correct 28 ms 348 KB Output is correct
11 Correct 19 ms 348 KB Output is correct
12 Correct 18 ms 348 KB Output is correct
13 Correct 18 ms 456 KB Output is correct
14 Correct 17 ms 348 KB Output is correct
15 Correct 17 ms 348 KB Output is correct
16 Correct 19 ms 348 KB Output is correct
17 Correct 18 ms 344 KB Output is correct
18 Correct 19 ms 348 KB Output is correct
19 Correct 30 ms 344 KB Output is correct
20 Runtime error 1 ms 600 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -