답안 #996496

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
996496 2024-06-10T17:23:22 Z cpptowin Lasers (NOI19_lasers) C++17
100 / 100
77 ms 14288 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(),x.end()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
int l,m,n,a[maxn],p[maxn];
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> l >> m;
    vii range;
    fo(i,1,m)
    {
        cin >> n;
        fo(i,1,n) 
        {
            cin >> a[i];
            p[i] = p[i - 1] + a[i];
        }
        if(p[n] == l) return cout << l,0;
        int L = n,R = 1;
        fo(i,0,n)
        {
            int u = p[i],v = l - (p[n] - p[i - 1]) + 1;
            if(u >= v) range.pb(v,u);
            else continue;
        }
    }
    if(range.empty()) return cout << 0,0;
    sort(range.begin(),range.end(),[](pii a,pii b)
    {
        return a.fi < b.fi or (a.fi == b.fi and a.se > b.se);
    });
    vii res;
    res.pb(range[0]);
    for(auto it : range) 
    {
        if(res.back().se <= it.se)
        {
            auto b = res.back();
            res.pop_back();
            if(it.fi >= b.fi and it.fi <= b.se) 
            {
                b.se = it.se;
                res.pb(b);
            }
            else 
            {
                res.pb(b);
                res.pb(it);
            }
        }
    }
    int ans = 0;
    for(auto [l,r] : res) ans += r - l + 1;
    cout << ans;
}

Compilation message

lasers.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main()
      | ^~~~
lasers.cpp: In function 'int main()':
lasers.cpp:65:13: warning: unused variable 'L' [-Wunused-variable]
   65 |         int L = n,R = 1;
      |             ^
lasers.cpp:65:19: warning: unused variable 'R' [-Wunused-variable]
   65 |         int L = n,R = 1;
      |                   ^
lasers.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
lasers.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2528 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 77 ms 11452 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 13052 KB Output is correct
2 Correct 4 ms 5340 KB Output is correct
3 Correct 6 ms 5532 KB Output is correct
4 Correct 31 ms 13872 KB Output is correct
5 Correct 13 ms 9176 KB Output is correct
6 Correct 20 ms 14132 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 21 ms 9964 KB Output is correct
9 Correct 16 ms 12756 KB Output is correct
10 Correct 31 ms 14288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2520 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 13052 KB Output is correct
2 Correct 4 ms 5340 KB Output is correct
3 Correct 6 ms 5532 KB Output is correct
4 Correct 31 ms 13872 KB Output is correct
5 Correct 13 ms 9176 KB Output is correct
6 Correct 20 ms 14132 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 21 ms 9964 KB Output is correct
9 Correct 16 ms 12756 KB Output is correct
10 Correct 31 ms 14288 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2520 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 69 ms 10692 KB Output is correct
22 Correct 8 ms 4060 KB Output is correct
23 Correct 7 ms 6108 KB Output is correct
24 Correct 34 ms 12540 KB Output is correct
25 Correct 65 ms 10696 KB Output is correct
26 Correct 26 ms 9172 KB Output is correct
27 Correct 10 ms 4060 KB Output is correct
28 Correct 71 ms 10708 KB Output is correct
29 Correct 70 ms 10640 KB Output is correct
30 Correct 22 ms 7636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2528 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 77 ms 11452 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2516 KB Output is correct
21 Correct 26 ms 13052 KB Output is correct
22 Correct 4 ms 5340 KB Output is correct
23 Correct 6 ms 5532 KB Output is correct
24 Correct 31 ms 13872 KB Output is correct
25 Correct 13 ms 9176 KB Output is correct
26 Correct 20 ms 14132 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 21 ms 9964 KB Output is correct
29 Correct 16 ms 12756 KB Output is correct
30 Correct 31 ms 14288 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 0 ms 2520 KB Output is correct
40 Correct 1 ms 2648 KB Output is correct
41 Correct 69 ms 10692 KB Output is correct
42 Correct 8 ms 4060 KB Output is correct
43 Correct 7 ms 6108 KB Output is correct
44 Correct 34 ms 12540 KB Output is correct
45 Correct 65 ms 10696 KB Output is correct
46 Correct 26 ms 9172 KB Output is correct
47 Correct 10 ms 4060 KB Output is correct
48 Correct 71 ms 10708 KB Output is correct
49 Correct 70 ms 10640 KB Output is correct
50 Correct 22 ms 7636 KB Output is correct
51 Correct 16 ms 6568 KB Output is correct
52 Correct 58 ms 12024 KB Output is correct
53 Correct 68 ms 11720 KB Output is correct
54 Correct 18 ms 6100 KB Output is correct
55 Correct 44 ms 9428 KB Output is correct
56 Correct 26 ms 13780 KB Output is correct
57 Correct 29 ms 9932 KB Output is correct
58 Correct 71 ms 12232 KB Output is correct
59 Correct 24 ms 5592 KB Output is correct
60 Correct 30 ms 6868 KB Output is correct