Submission #1370296


Source Code Expand

#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;
 
const int N = (int) 1e5 + 10;
const int M = (int) 101;
const ll big =  (1LL << 51);
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int INF1 = (int) 1e9 + 3;
const double EPS = (double) 1e-6;
const double PI =  3.14159265359;

int n, c, k;
int t[N], dp[N];

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n >> c >> k;
    for (int i = 1; i <= n; i++) {
      cin >> t[i];
    }
    sort(t + 1, t + n + 1);
    multiset<int> st;
    st.insert(0);
    for (int i = 1, l = 0; i <= n; i++) {
      while (l < i && (t[l + 1] + k < t[i] || i - l > c)) {
        st.erase(st.find(dp[l]));
        ++l;
      }
      dp[i] = *st.begin() + 1;
      st.insert(dp[i]);
      continue;
      dp[i] = INF;
      for (int j = 0; j < i; j++) {
        if (i - j <= c && t[j + 1] + k >= t[i]) {
          dp[i] = min(dp[i], dp[j] + 1);
        }
      }
    }
    cout << dp[n];
    return 0;
}

Submission Info

Submission Time
Task A - Airport Bus
User Nurlykhan
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1493 Byte
Status AC
Exec Time 55 ms
Memory 1024 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 12
Set Name Test Cases
Sample sample1.txt, sample2.txt
All sample1.txt, sample2.txt, in1.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, sample1.txt, sample2.txt
Case Name Status Exec Time Memory
in1.txt AC 2 ms 256 KB
in2.txt AC 53 ms 1024 KB
in3.txt AC 52 ms 1024 KB
in4.txt AC 52 ms 1024 KB
in5.txt AC 2 ms 256 KB
in6.txt AC 54 ms 1024 KB
in7.txt AC 48 ms 896 KB
in8.txt AC 55 ms 1024 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB