Submission #1365334

#TimeUsernameProblemLanguageResultExecution timeMemory
1365334bnd2100Stove (JOI18_stove)C++20
100 / 100
16 ms2016 KiB
/*
* @Author: Twynzz
* @Last Modified by: Twynzz
* @Note For This Problem: https://wbd.ms/share/v2/aHR0cHM6Ly93aGl0ZWJvYXJkLm1pY3Jvc29mdC5jb20vYXBpL3YxLjAvd2hpdGVib2FyZHMvcmVkZWVtL2Y3ZTc5NDk0NDFhNzRkNjA5NTg5MDZkNjc1NDAzNmJlX0JCQTcxNzYyLTEyRTAtNDJFMS1CMzI0LTVCMTMxRjQyNEUzRF9iZDE4OGRiZC0yMDRlLTQ0MmItYTg4Yy03YWM5MDhlY2U4ZTA=
*/


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

char __ST__;
extern char __EN__;

// ------------ Define ------------

#define int long long
#define ll long long
#define ld long double
#define str string
#define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
#define IOS {std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define _TBN_ signed main()
#define setp(n) setprecision(n)<< fixed
#define fi first
#define se second
#define ii pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define iii tuple<int, int, int>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define sz(v) (int)v.size()
#define el "\n"
#define all(x) x.begin(),x.end()

const long long oo = 1e18;
const int MOD = 1e9+7, Mod = 998244353;
const int base = 311, base2 = 293;
const pair<ll, ll> INVALID_ROOT = {oo, oo};

template<class X>
    bool maximize(X &a, const X &b)
    {
        if (a<b)
        {
            a = b;
            return 1;
        }
        return 0;
    }

template<class X>
    bool minimize(X &a, const X &b)
    {
        if (a>b)
        {
            a = b;
            return 1;
        }
        return 0;
    }

namespace sub1
{
    bool checkSub1();
    void sub1();
}
namespace sub2
{
    bool checkSub2();
    void sub2();
}
namespace sub3
{
    bool checkSub3();
    void sub3();
}

int lcm(int a, int b)
{
    return a / gcd(a, b) * b;
}

int sqr(int x) {return x*x;}

inline bool MASK(int mask, int bit) {return ((mask >> bit) & 1);}
inline long long F(int n) {return n * (n + 1) / 2;}
inline int add(int a, int b, int m = MOD)
{
    return ((a % m + b % m) % m + m) % m;
}
inline int sub(int a, int b, int m = MOD)
{
    return ((a % m - b % m) % m + m) % m;
}
inline int mul(int a, int b, int m = MOD)
{
    return (((a % m) * (b % m)) % m + m) % m;
}

int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};

const int maxn = 1e6 + 9;
const int N = 5e4 + 6;

// ------------ Code ------------

int n, k, t[maxn];
_TBN_
{
    IOS;
    if (fopen("xxx.inp","r")) file("xxx");
    cin >>n >>k;
    for(int i = 1; i <= n; i++) cin >>t[i];
    for(int i = 1; i <= 1; i++)
    {
        if (sub1::checkSub1()) {sub1::sub1(); continue;}
        if (sub2::checkSub2()) {sub2::sub2(); continue;}
        if (sub3::checkSub3()) {sub3::sub3(); continue;}
    }
    cerr << "\nStatic memory used: " << fixed << setprecision(3) << ((&__EN__ - &__ST__) / (1.0L * 1024 * 1024)) << "mb\n";
    return 0;
}

namespace sub1
{
    bool checkSub1()
    {
        return 1;
    }
    int dif[maxn];
    void sub1()
    {
        /*
- t[i + 1] - t[i] - 1 = dif[i] là khoảng trống giữa t[i] và t[i + 1]
- Mảng dif có N - 1 phần tử
a[1] --- a[2] --- a[3] --- a[4]
->   dif[1] - dif[2] - dif[3]
- Giả sử ta bật xuyên suốt từ t[1] đến t[n] + 1, tốn 1 lần bật và còn K - 1 lần
// => Chọn K - 1 khoảng trống lớn nhất trong N - 1 khoảng trống để xóa đi
// => Ta sẽ tạo được K đoạn khác nhau
- sort lai mang dif tang dan, dap an la ((t[n] + 1) - t[1]) - Sum(dif[1...K-1])
        */
        for(int i = 1; i < n; i++)
            dif[i] = t[i + 1] - t[i] - 1;
        sort(dif + 1, dif + n, greater<int>());
        int ans = t[n] + 1 - t[1];
        for(int i = 1; i < k; i++)
            ans -= dif[i];
        cout<< ans<< el;
    }
}

namespace sub2
{
    bool checkSub2()
    {
        return 1;
    }
    void sub2()
    {
        
    }
}

namespace sub3
{
    bool checkSub3()
    {
        return 1;
    }
    void sub3()
    {

    }
}



char __EN__;

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:20:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 | #define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stove.cpp:113:31: note: in expansion of macro 'file'
  113 |     if (fopen("xxx.inp","r")) file("xxx");
      |                               ^~~~
stove.cpp:20:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 | #define file(name) {freopen(name".inp","r",stdin);freopen(name".out","w",stdout);}
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:113:31: note: in expansion of macro 'file'
  113 |     if (fopen("xxx.inp","r")) file("xxx");
      |                               ^~~~
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...