답안 #248679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
248679 2020-07-13T05:53:11 Z SamAnd Lasers (NOI19_lasers) C++17
100 / 100
216 ms 18268 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 500005;

int n, d;

int a[N];

int p[N], s[N];

void solv()
{
    scanf("%d%d", &d, &n);
    vector<pair<int, int> > v;
    while (n--)
    {
        int m;
        scanf("%d", &m);
        for (int i = 1; i <= m; ++i)
            scanf("%d", &a[i]);

        for (int i = 1; i <= m; ++i)
            p[i] = p[i - 1] + a[i];
        s[m + 1] = 0;
        for (int i = m; i >= 1; --i)
            s[i] = s[i + 1] + a[i];
        int x = 1;
        for (int i = 0; i <= m; ++i)
        {
            int l = 1 + p[i];
            int r = d - s[i + 1];
            if (l > r)
                continue;
            if (x < l)
            {
                v.push_back(m_p(x, l - 1));
            }
            x = max(x, r + 1);
        }
        if (x <= d)
            v.push_back(m_p(x, d));
    }
    vector<pair<int, int> > u;
    for (int i = 0; i < v.size(); ++i)
    {
        u.push_back(m_p(v[i].fi, 1));
        u.push_back(m_p(v[i].se + 1, -1));
    }
    sort(all(u));
    int p = 0;
    int ans = 0;
    for (int i = 0; i < u.size(); ++i)
    {
        p += u[i].se;
        if (p > 0)
            ans += (u[i + 1].fi - u[i].fi);
    }
    printf("%d\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}

Compilation message

lasers.cpp: In function 'void solv()':
lasers.cpp:52:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
lasers.cpp:60:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < u.size(); ++i)
                     ~~^~~~~~~~~~
lasers.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &d, &n);
     ~~~~~^~~~~~~~~~~~~~~~
lasers.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &m);
         ~~~~~^~~~~~~~~~
lasers.cpp:28:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &a[i]);
             ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 190 ms 18268 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 211 ms 12004 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 8512 KB Output is correct
2 Correct 11 ms 2044 KB Output is correct
3 Correct 15 ms 1664 KB Output is correct
4 Correct 81 ms 8808 KB Output is correct
5 Correct 33 ms 4972 KB Output is correct
6 Correct 55 ms 6640 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 59 ms 6000 KB Output is correct
9 Correct 43 ms 7280 KB Output is correct
10 Correct 83 ms 9316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 8512 KB Output is correct
2 Correct 11 ms 2044 KB Output is correct
3 Correct 15 ms 1664 KB Output is correct
4 Correct 81 ms 8808 KB Output is correct
5 Correct 33 ms 4972 KB Output is correct
6 Correct 55 ms 6640 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 59 ms 6000 KB Output is correct
9 Correct 43 ms 7280 KB Output is correct
10 Correct 83 ms 9316 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 288 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 216 ms 10892 KB Output is correct
22 Correct 30 ms 2680 KB Output is correct
23 Correct 34 ms 2552 KB Output is correct
24 Correct 83 ms 8344 KB Output is correct
25 Correct 202 ms 10828 KB Output is correct
26 Correct 64 ms 6884 KB Output is correct
27 Correct 25 ms 2424 KB Output is correct
28 Correct 195 ms 10852 KB Output is correct
29 Correct 202 ms 10852 KB Output is correct
30 Correct 58 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 190 ms 18268 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 211 ms 12004 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 75 ms 8512 KB Output is correct
22 Correct 11 ms 2044 KB Output is correct
23 Correct 15 ms 1664 KB Output is correct
24 Correct 81 ms 8808 KB Output is correct
25 Correct 33 ms 4972 KB Output is correct
26 Correct 55 ms 6640 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 59 ms 6000 KB Output is correct
29 Correct 43 ms 7280 KB Output is correct
30 Correct 83 ms 9316 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 0 ms 288 KB Output is correct
33 Correct 0 ms 384 KB Output is correct
34 Correct 0 ms 384 KB Output is correct
35 Correct 0 ms 384 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 216 ms 10892 KB Output is correct
42 Correct 30 ms 2680 KB Output is correct
43 Correct 34 ms 2552 KB Output is correct
44 Correct 83 ms 8344 KB Output is correct
45 Correct 202 ms 10828 KB Output is correct
46 Correct 64 ms 6884 KB Output is correct
47 Correct 25 ms 2424 KB Output is correct
48 Correct 195 ms 10852 KB Output is correct
49 Correct 202 ms 10852 KB Output is correct
50 Correct 58 ms 5228 KB Output is correct
51 Correct 27 ms 3056 KB Output is correct
52 Correct 212 ms 12132 KB Output is correct
53 Correct 210 ms 12004 KB Output is correct
54 Correct 47 ms 4588 KB Output is correct
55 Correct 114 ms 9444 KB Output is correct
56 Correct 71 ms 8424 KB Output is correct
57 Correct 77 ms 7780 KB Output is correct
58 Correct 210 ms 12132 KB Output is correct
59 Correct 56 ms 4840 KB Output is correct
60 Correct 78 ms 5868 KB Output is correct