Submission #1105148

# Submission time Handle Problem Language Result Execution time Memory
1105148 2024-10-25T15:08:30 Z monaxia Stove (JOI18_stove) C++17
100 / 100
101 ms 7684 KB
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fr first
#define sc second
#define all(v) v.begin(), v.end()
#define mod (long long)(1e9 + 7)
#define eps (long long)(1e-9)
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll LIMIT = 2e3 + 5;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random (int l, int r){return uniform_int_distribution <int> (l, r)(rng);}

struct ranges{
    int range, i1, i2;
};

bool comp(ranges& a, ranges& b){
    return a.range < b.range;
}

void solve(){
    int n, k, ans = 0;
    cin >> n >> k;

    vector <int> a(n + 1);
    vector <ranges> init;
    set <pair <int, int>> range;

    for(int i = 1; i <= n; i ++){
        cin >> a[i];
        if(i > 1) init.pb({a[i] - a[i - 1] - 1, i - 1, i});
        range.insert({a[i], a[i]});
    }

    sort(all(init), comp);

    for(auto& w : init){
        if(range.size() == k) break;

        auto it2 = range.lower_bound({a[w.i2], a[w.i2]});
        auto it1 = it2;
        it1 --;

        auto temp1 = *it2, temp2 = *it1;

        range.insert({it1 -> fr, it2 -> sc});
        range.erase(temp1);
        range.erase(temp2);
    }

    for(auto& x : range){
        ans += (x.sc - x.fr + 1);
    }

    cout << ans;
}
signed main()
{
    cin.tie(0)->sync_with_stdio(0);
 
    if(fopen("blank.inp", "r")){
        freopen("blank.inp", "r", stdin);
        freopen("blank.out", "w", stdout);
    }
    
    // cout << 1; return 0;

    ll n = 1;

    // cin >> n;

    while(n) {
        solve();
        n --;
        cout << "\n";
    }
 
    // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}

Compilation message

stove.cpp: In function 'void solve()':
stove.cpp:44:25: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |         if(range.size() == k) break;
      |            ~~~~~~~~~~~~~^~~~
stove.cpp: In function 'int main()':
stove.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen("blank.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen("blank.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 3 ms 592 KB Output is correct
12 Correct 3 ms 592 KB Output is correct
13 Correct 2 ms 656 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 3 ms 760 KB Output is correct
11 Correct 3 ms 592 KB Output is correct
12 Correct 3 ms 592 KB Output is correct
13 Correct 2 ms 656 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 101 ms 7684 KB Output is correct
17 Correct 100 ms 7684 KB Output is correct
18 Correct 99 ms 7420 KB Output is correct
19 Correct 97 ms 7684 KB Output is correct
20 Correct 72 ms 7600 KB Output is correct
21 Correct 43 ms 7684 KB Output is correct
22 Correct 37 ms 7676 KB Output is correct
23 Correct 36 ms 7604 KB Output is correct
24 Correct 38 ms 7432 KB Output is correct