Submission #70447137


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
using pii = pair<ll, ll>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using mint = modint998244353;
// using mint = modint1000000007;
#define endl '\n'
#define rep(i, a) for (ll i = 0; i < a; i++)
#define f(i, a, b) for (ll i = a; i < b; i++)
#define rf(i, a, b) for (ll i = a; i > b; i--)
#define all(x) (x).begin(), (x).end()
const ll INF = LLONG_MAX / 4;
vi dx = {1, 0, -1, 0, 1, 1, -1, -1};
vi dy = {0, 1, 0, -1, 1, -1, 1, -1};
void io_setup() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(16);
}

int main(void) {
    io_setup();
    ll n,m,c;
    cin>> n >> m >> c;
    vi a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    vpii num = {{0,0}};
    
    rep(i,n){
        if(a[i] == num[num.size()-1].first)num[num.size()-1].second++;
        else num.push_back({a[i], 1});
    }
    num.push_back({m,0});
    int size = num.size();
    rep(i,size){
        num.push_back({num[i].first + m, num[i].second});
    }
    
    int l=0, r=0;
    ll sum = 0;
    ll ans = 0;
    rep(i,num.size()/2){
        l = num[i].first;
        if(i>0)sum -= num[i-1].second;
        while(sum<c){
            sum += num[r].second;
            r++;
        }
        if(i>0)ans += (num[i].first - num[i-1].first) * sum;
        // cerr << i << " " << num[i].first - num[i-1].first << " " << sum << endl;
    }
    
    cout << ans << endl;
}

Submission Info

Submission Time
Task D - On AtCoder Conference
User karas1
Language C++ 20 (gcc 12.2)
Score 425
Code Size 1789 Byte
Status AC
Exec Time 79 ms
Memory 23520 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:21:36: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::vector<std::pair<long long int, long long int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   21 | #define rep(i, a) for (ll i = 0; i < a; i++)
      |                                    ^
Main.cpp:56:5: note: in expansion of macro ‘rep’
   56 |     rep(i,num.size()/2){
      |     ^~~
Main.cpp:53:9: warning: variable ‘l’ set but not used [-Wunused-but-set-variable]
   53 |     int l=0, r=0;
      |         ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 2
AC × 32
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3448 KiB
example_01.txt AC 1 ms 3532 KiB
hand_00.txt AC 38 ms 7008 KiB
hand_01.txt AC 38 ms 7104 KiB
hand_02.txt AC 79 ms 23520 KiB
hand_03.txt AC 22 ms 6916 KiB
hand_04.txt AC 1 ms 3512 KiB
hand_05.txt AC 1 ms 3528 KiB
random_00.txt AC 37 ms 7056 KiB
random_01.txt AC 36 ms 7060 KiB
random_02.txt AC 39 ms 6988 KiB
random_03.txt AC 53 ms 8120 KiB
random_04.txt AC 55 ms 9120 KiB
random_05.txt AC 54 ms 8076 KiB
random_06.txt AC 73 ms 23484 KiB
random_07.txt AC 69 ms 23388 KiB
random_08.txt AC 67 ms 15516 KiB
random_09.txt AC 44 ms 7000 KiB
random_10.txt AC 39 ms 7044 KiB
random_11.txt AC 41 ms 7392 KiB
random_12.txt AC 42 ms 6968 KiB
random_13.txt AC 50 ms 7316 KiB
random_14.txt AC 50 ms 7060 KiB
random_15.txt AC 42 ms 7288 KiB
random_16.txt AC 57 ms 7348 KiB
random_17.txt AC 58 ms 7348 KiB
random_18.txt AC 45 ms 9172 KiB
random_19.txt AC 64 ms 9152 KiB
random_20.txt AC 63 ms 8072 KiB
random_21.txt AC 66 ms 23520 KiB
random_22.txt AC 74 ms 15340 KiB
random_23.txt AC 79 ms 23468 KiB