Submission #569800

# Submission time Handle Problem Language Result Execution time Memory
569800 2022-05-27T20:09:55 Z AmirElarbi Autobahn (COI21_autobahn) C++14
50 / 100
1000 ms 136164 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e4+7;
const int nax = 2e6+7;

typedef complex<int> Point;
#define X real()
#define Y imag()
int n,x,ka;
ll  tot[nax], s[nax], e[nax], t[nax], cnt[nax],pref[nax], rev[nax];
set<ll> ind;
map<ll,ll> cnv;
void add(ll pos){
    ind.insert(pos);
    ind.insert(pos + x);
    ind.insert(pos - x);

}
int main()
{
    optimise;
    cin >> n >> ka >> x;
    ll res  = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> s[i] >> t[i] >> e[i];
        add(s[i]);
        add(e[i]+1);
        add(e[i]);
        add(s[i]+t[i]);
    }
    int k = 0, mxd;
    for(auto y : ind){
        cnv[y]  = k;
        rev[k]  = y;
        mxd = y;
        k++;
    }
    for (int i = 0; i < n; ++i)
    {
        cnt[cnv[s[i]] +1]++;
        cnt[cnv[e[i] + 1] +1]--;
        tot[cnv[s[i] + t[i]] +1]++;
        tot[cnv[e[i] + 1] +1]--;
    }
    for (int i = 1; i < k; ++i)
    {
        cnt[i] += cnt[i-1];
        tot[i] += tot[i-1];
    }
    for (int i = 1; i < k; ++i)
    {
        pref[i] = pref[i-1];
        if(cnt[i-1] >= ka && i-2 >=0) pref[i] += (rev[i-1]-rev[i-2])*tot[i-1];
    }
    for (int i = 0; i < k; ++i)
    {
        int to = cnv[rev[i]+x]+1;
        if(rev[i]+x > mxd) break;
        res = max(res, pref[to] - pref[i+1]);
    }
    cout << res << endl;
}

Compilation message

autobahn.cpp: In function 'int main()':
autobahn.cpp:77:23: warning: 'mxd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   77 |         if(rev[i]+x > mxd) break;
      |                       ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 2 ms 464 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 524 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 2 ms 464 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 524 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 3 ms 724 KB Output is correct
20 Correct 2 ms 724 KB Output is correct
21 Execution timed out 1071 ms 136164 KB Time limit exceeded
22 Halted 0 ms 0 KB -