답안 #423576

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
423576 2021-06-11T09:41:56 Z JvThunder Autobahn (COI21_autobahn) C++14
50 / 100
374 ms 56992 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
typedef long long ll;

using namespace std;

int n,k,z;
multiset<pair<pair<int,int>,int>> s;
vector<pair<pair<int,int>,int>> val;
int add[1005] = {0};
void solve()
{
    cin >> n >> k >> z;
    set<int> all;
    for(int i=0;i<n;i++)
    {
        int l,t,r;
        cin >> l >> t >> r;
        s.insert({{l,l+t-1},0});
        s.insert({{l+t,r},1});
        all.insert(l);
        all.insert(l+t);
        all.insert(r+1);
    }

    priority_queue<pair<int,int>> pq;
    int cnt = 0;
    auto itr = s.begin();
    int prv = 0;
    for(int x=1;x<=1000;x++)
    {
        if(pq.size()>=k) val.pb({{prv,x-1},cnt});
        prv = x;

        while(itr!=s.end() && (*itr).fir.fir<=x)
        {
            if((*itr).sec==1) cnt++;
            pq.push({-(*itr).fir.sec,(*itr).sec});
            itr++;
        }

        while(!pq.empty() && -pq.top().fir<x)
        {
            if(pq.top().sec==1) cnt--;
            pq.pop();
        }
    }

    for(auto x:val)
    {
        //cout << " " << x.fir.fir << " " << x.fir.sec << " " << x.sec << endl;
        for(int i=x.fir.fir;i<=x.fir.sec;i++) add[i] = x.sec;
    }

    int sum = 0; int mxsum = 0;
    for(int i=1;i<=z;i++) sum += add[i], mxsum = max(mxsum,sum);
    for(int i=z+1;i<=1000;i++) sum -= add[i-z], sum += add[i], mxsum = max(mxsum,sum);;
    cout << mxsum << endl;
    return;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int tc=1;
	//cin>>tc;
	for(int i=1;i<=tc;i++) solve();
 	return 0;
}

Compilation message

autobahn.cpp: In function 'void solve()':
autobahn.cpp:35:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |         if(pq.size()>=k) val.pb({{prv,x-1},cnt});
      |            ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 2 ms 452 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 452 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 476 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 2 ms 452 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 452 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 476 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Runtime error 374 ms 56992 KB Execution killed with signal 11
22 Halted 0 ms 0 KB -