Submission #1038017

# Submission time Handle Problem Language Result Execution time Memory
1038017 2024-07-29T12:08:11 Z Madhav_1608 Rabbit Carrot (LMIO19_triusis) C++17
100 / 100
26 ms 7000 KB
#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
using namespace std;
// #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef pair<ll,ll> pll;
#define double long double
const double eps = 1e-9; 
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define all(v) v.begin(),v.end()
template <typename I>
void print(vector<I> &v){
    FOR(i,0,v.size()-1){cout << v[i] << " ";}
    cout << v.back() << "\n";
}
ll gcd(ll a,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else if(a<b){return gcd(b%a,a);}
    else{return gcd(a%b,b);}
}
ll lcm(ll a,ll b){
    return (a/gcd(a,b))*b;
}
ll merge_sort(vector<ll> &a,ll left,ll right,ll n){
    if(left==right){
        return 0;
    }
    else{
        ll mid = (left+right)/2;
        ll x = merge_sort(a,left,mid,n);
        ll y = merge_sort(a,mid+1,right,n);

// Do the operations here ......

        ll mad = left;
        ll hav = mid+1;
        vector<ll> to_be;
        while(mad<=mid && hav<=right){
            if(a[mad]<=a[hav]){
                to_be.push_back(a[mad]);
                mad++;
            }
            else{
                to_be.push_back(a[hav]);
                hav++;
            }
        }
        FOR(i,mad,mid+1){
            to_be.push_back(a[i]);
        }
        FOR(i,hav,right+1){
            to_be.push_back(a[i]);
        }
        FOR(i,left,right+1){
            a[i] = to_be[i-left];
        }
        return 0;
    }
}
void setIO(string name = "") {
    freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
    freopen((name + ".out").c_str(), "w", stdout);
}

int main(){
    //setIO
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin >> n >> m;
    ll mad = n;
    vll a(n+1,0);
    FOR(i,1,n+1){
        cin >> a[i];
    }
    vll b;
    FOR(i,0,n+1){
        if(a[i]<=(i*m)){
            b.push_back((i*m)-a[i]);
        }
    }
    n = b.size();
    vll length(n,INT_MAX);
    FOR(i,0,n){
        ll curr = upper_bound(all(length),b[i])-length.begin();
        length[curr] = b[i];
    }
    for(ll i=(n-1);i>=0;i--){
        if(length[i]<INT_MAX){
            cout << (mad-i) << "\n";
            break;
        }
    }
    return 0;
}

Compilation message

triusis.cpp: In function 'll merge_sort(std::vector<long long int>&, ll, ll, ll)':
triusis.cpp:50:12: warning: unused variable 'x' [-Wunused-variable]
   50 |         ll x = merge_sort(a,left,mid,n);
      |            ^
triusis.cpp:51:12: warning: unused variable 'y' [-Wunused-variable]
   51 |         ll y = merge_sort(a,mid+1,right,n);
      |            ^
triusis.cpp: In function 'void setIO(std::string)':
triusis.cpp:81:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:82:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |     freopen((name + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 856 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 472 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 472 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 548 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 484 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 548 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 484 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 856 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 464 KB Output is correct
24 Correct 1 ms 600 KB Output is correct
25 Correct 1 ms 472 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 16 ms 5588 KB Output is correct
45 Correct 14 ms 3940 KB Output is correct
46 Correct 26 ms 5592 KB Output is correct
47 Correct 23 ms 5472 KB Output is correct
48 Correct 19 ms 6248 KB Output is correct
49 Correct 22 ms 6232 KB Output is correct
50 Correct 22 ms 6356 KB Output is correct
51 Correct 23 ms 7000 KB Output is correct
52 Correct 22 ms 6100 KB Output is correct
53 Correct 16 ms 3044 KB Output is correct
54 Correct 19 ms 6236 KB Output is correct
55 Correct 19 ms 6356 KB Output is correct