c++ test

C++ code posted
created at 02 Jul 04:08, updated at 04 Aug 12:40

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <algorithm>
using namespace std;

class xlong {
public:
    int p[100], h;
    
    xlong() {
        h = 1;
        p[0] = 0;
    }
    /* 
      fff
    */
    xlong(int n) {
        h = 1;
        p[0] = n;
    }
    
    xlong operator +(xlong x) {
        xlong res(0);
        int m = 0;
        for (int i = 0; i < 100; i++) {
            m = (i < h ? p[i] : 0) + (i < x.h ? x.p[i] : 0) + m;
            res.p[i] = m % 10;
            m /= 10;
        }
        res.h = 99;
        for (int i = 99; i > 0 && res.p[i] == 0; i--)
            res.h = i;
        return res;
    }
};

ostream& operator << (ostream& out, xlong x) {
    for (int i = x.h - 1; i >= 0; i--)
        cout << x.p[i];
    return out;
}

int main() {
    long long n, t, k;
    cin >> n >> t >> k;
    long long p[t];
    xlong d[t];
    for (int i = 0; i < t; i++)
        cin >> p[i];
    sort(p, p + t);
    for (int i = 0; i < t; i++) {
        d[i] = 0;
        if (p[i] <= k)
            d[i] = 1;
        for (int j = 0; j < i; j++)
            if (p[i] - p[j] <= k)
                d[i] = d[i] + d[j];
        if (p[i] == n) {
            cout << d[i];
            return 0;
        }
    }
    cout << 0;
    return 0;
}
1.27 KB in 3 ms with coderay