Submission #65252109


Source Code Expand

#pragma GCC optimize("Ofast,O3,unroll-loops")

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

#define ll long long
#define ld long double
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define nl cout<<"\n"
#define ca(v) for(auto i:v) cout<<i<<" ";
#define cap(v) for(auto [a,b]:v) cout<<a<<"|"<<b<<" ";
#define cbit(x) __builtin_popcount(x)
#define yesno(b) cout<<((b) ? "YES\n" : "NO\n");
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define read_graph(n, m) \
    for(int i = 0; i < (m); i++) { \
        int u, v; \
        cin >> u >> v; \
        u--; v--; \
        adj[u].push_back(v); \
        adj[v].push_back(u); \
    }
#define read_graph_d(n, m) \
    for(int i = 0; i < (m); i++) { \
        int u, v; \
        cin >> u >> v; \
        u--; v--; \
        adj[u].push_back(v); \
    }
#define read_tree(n) read_graph((n), (n)-1)
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

//////////////////////////////////////////////////////////////////////////////

const int xm[4] = {-1, 1, 0, 0};
const int ym[4] = {0, 0, -1, 1};
// const int xm[8] = {-1, -1, 1, 1, -1, 1, 0, 0};
// const int ym[8] = {1, -1, 1, -1, 0, 0, -1, 1};

const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const int MAXN = 5e5 + 5;

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const ll B = uniform_int_distribution<ll>(256, MOD - 1)(rng);
ll gen() { ll x = 0; while(x == 0) x = rng() % MOD; return x; }


struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint& operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}
    mint& operator-=(const mint a) {if ((x += MOD-a.x) >= MOD) x -= MOD;return *this;}
    mint& operator*=(const mint a) {(x *= a.x) %= MOD;return *this;}
    mint operator+(const mint a) const {mint res(*this);return res+=a;}
    mint operator-(const mint a) const {mint res(*this);return res-=a;}
    mint operator*(const mint a) const {mint res(*this);return res*=a;}
    mint pow(ll b) const {
      mint res(1), a(*this);
      while (b) {
        if (b & 1) res *= a;
        a *= a;
        b >>= 1;
      }
      return res;
    }
    mint minv() const {return pow(MOD-2);}
    mint& operator/=(const mint a) {return (*this) *= a.minv();}
    mint operator/(const mint a) const {mint res(*this);return res/=a;}
};
mint fpow(mint a, ll b) {
    return a.pow(b);
}
ostream& operator<<(ostream& os, const mint& a) {os << a.x; return os;}

ll gcd(ll x, ll y) { if(!y) return x; return gcd(y, x%y); }
ll lcm(ll a, ll b) { return a*b/gcd(a, b); }

// mint fact[MAXN], i_fact[MAXN];
// void gen_fact(){
//     fact[0] = 1;
//     for(ll i=1; i<MAXN; i++) fact[i] = (fact[i-1]*i);
//     for(ll i=0; i<MAXN; i++) i_fact[i] = fact[i].minv();
// }
// mint comb(ll a, ll b) {
//     return fact[a] * i_fact[a-b] * i_fact[b];
// }
// mint perm(ll a, ll b) {
//     return fact[a] * i_fact[a-b];
// }

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n, d;
    cin>>n>>d;
    vector<int> cnt(1e6+5);
    vector<vector<int>> dp(1e6+5, vector<int>(2,n));
    dp[0][0] = 0;
    int ar[n];
    for(int i=0; i<n; i++) {
        cin>>ar[i];
        cnt[ar[i]]++;
    }
    if(d == 0){
        int sm = 0;
        for(int i=0; i<cnt.size(); i++) {
            if(cnt[i]) sm += cnt[i] - 1;
        }
        cout<<sm;
        return 0;
    }

    for(int i=0; i<cnt.size(); i++) {
        if(i-d < 0) {
            dp[i][0] = cnt[i];
            dp[i][1] = 0;
        } else {
            dp[i][0] = min(dp[i-d][1], dp[i-d][0]) + cnt[i];
            dp[i][1] = dp[i-d][0];
        }
    } 
    int res = 0;
    for(int i=1; i<=d; i++) {
        res += min(dp[cnt.size()-i][0], dp[cnt.size()-i][1]);
    }
    cout<<res;
}

Submission Info

Submission Time
Task D - Forbidden Difference
User keepers
Language C++ 20 (gcc 12.2)
Score 425
Code Size 4164 Byte
Status AC
Exec Time 63 ms
Memory 62532 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:120:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  120 |         for(int i=0; i<cnt.size(); i++) {
      |                      ~^~~~~~~~~~~
Main.cpp:127:19: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  127 |     for(int i=0; i<cnt.size(); i++) {
      |                  ~^~~~~~~~~~~
Main.cpp:105:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  105 |         freopen("input.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:106:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  106 |         freopen("output.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 40
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 44 ms 61680 KiB
00_sample_02.txt AC 45 ms 61684 KiB
00_sample_03.txt AC 45 ms 61736 KiB
01_random_01.txt AC 50 ms 62528 KiB
01_random_02.txt AC 44 ms 61664 KiB
01_random_03.txt AC 50 ms 62444 KiB
01_random_04.txt AC 47 ms 61980 KiB
01_random_05.txt AC 51 ms 62480 KiB
01_random_06.txt AC 49 ms 62376 KiB
01_random_07.txt AC 46 ms 62444 KiB
01_random_08.txt AC 47 ms 62200 KiB
01_random_09.txt AC 50 ms 62452 KiB
01_random_10.txt AC 49 ms 62448 KiB
01_random_11.txt AC 50 ms 62448 KiB
01_random_12.txt AC 49 ms 62192 KiB
01_random_13.txt AC 51 ms 62484 KiB
01_random_14.txt AC 47 ms 61924 KiB
01_random_15.txt AC 47 ms 62480 KiB
01_random_16.txt AC 46 ms 61920 KiB
01_random_17.txt AC 52 ms 62532 KiB
01_random_18.txt AC 50 ms 62192 KiB
01_random_19.txt AC 52 ms 62492 KiB
01_random_20.txt AC 50 ms 62244 KiB
01_random_21.txt AC 52 ms 62532 KiB
01_random_22.txt AC 51 ms 62332 KiB
01_random_23.txt AC 48 ms 62472 KiB
01_random_24.txt AC 49 ms 62176 KiB
01_random_25.txt AC 60 ms 62480 KiB
01_random_26.txt AC 49 ms 61948 KiB
01_random_27.txt AC 59 ms 62448 KiB
01_random_28.txt AC 48 ms 61932 KiB
01_random_29.txt AC 63 ms 62524 KiB
01_random_30.txt AC 61 ms 62512 KiB
01_random_31.txt AC 56 ms 62456 KiB
01_random_32.txt AC 50 ms 61912 KiB
02_handmade_01.txt AC 55 ms 62436 KiB
02_handmade_02.txt AC 49 ms 62480 KiB
02_handmade_03.txt AC 41 ms 61584 KiB
02_handmade_04.txt AC 44 ms 61728 KiB
02_handmade_05.txt AC 47 ms 61708 KiB