답안 #889610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889610 2023-12-20T03:52:10 Z dimashhh Lasers (NOI19_lasers) C++17
100 / 100
162 ms 52916 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 1,MOD = 1e9 + 7;
typedef long long ll;
#define int long long
int n,m;
ll ans =0;
bool ok = true;
vector<int> g[N];
void solve(){
    vector<pair<int,int>> _;
    for(int i = 1;i <= m;i++){
        int cur = 1,sum = 0;
        for(auto j:g[i]){
            sum += j;
        }
        if(sum == n){
            cout << n;
            return;
        }
        vector<pair<int,int>> v,all;
        for(auto j:g[i]){
            if(n - sum >= cur){
                v.push_back({cur,n - sum});
            }
            cur += j;
            sum -= j;
        }
        if(n - sum >= cur){
            v.push_back({cur,n - sum});
        }
        int k = v.size();
        for(int f = 0;f < k;f++){
            int mx = v[f].second;
            for(int j = f + 1;j <= k;j++){
                if(j == k || v[j].first > mx){
                    all.push_back({v[f].first,mx});
                    f = j - 1;
                    break;
                }else{
                    mx = max(mx,v[j].second);
                }
            }
        }
        sort(all.begin(),all.end());
        if(all.empty()) continue;
        if(all[0].first != 1){
            _.push_back({1,all[0].first - 1});
        }
        if(all.back().second != n){
            _.push_back({all.back().second + 1,n});
        }
        for(int j = 1;j < all.size();j++){
            int l = all[j - 1].second + 1,r = all[j].first - 1;
            if(l <= r){
                _.push_back({l,r});
            }
        }
    }
    vector<pair<int,int>> v = _;
    sort(v.begin(),v.end());
    int k = v.size();
    for(int i = 0;i < k;i++){
        int mx = v[i].second;
        for(int j = i + 1;j <= k;j++){
            if(j == k || v[j].first > mx){
                ans += (mx - v[i].first + 1);
                i = j - 1;
                break;
            }else{
                mx = max(mx,v[j].second);
            }
        }
    }
    cout << ans << '\n';
}
void test(){
    cin >> n >> m;
    for(int i = 1;i <= m;i++){
        int k;
        cin >> k;
        if(k > 1){
            ok = false;
        }
        while(k--){
            int s;
            cin >> s;
            g[i].push_back(s);

        }
    }
    solve();
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        test();
    }
}

Compilation message

lasers.cpp: In function 'void solve()':
lasers.cpp:55:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(int j = 1;j < all.size();j++){
      |                       ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
8 Correct 5 ms 23952 KB Output is correct
9 Correct 5 ms 23900 KB Output is correct
10 Correct 5 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
8 Correct 5 ms 23952 KB Output is correct
9 Correct 5 ms 23900 KB Output is correct
10 Correct 5 ms 23900 KB Output is correct
11 Correct 5 ms 23896 KB Output is correct
12 Correct 87 ms 44944 KB Output is correct
13 Correct 5 ms 23896 KB Output is correct
14 Correct 5 ms 23900 KB Output is correct
15 Correct 5 ms 23900 KB Output is correct
16 Correct 6 ms 23908 KB Output is correct
17 Correct 154 ms 52116 KB Output is correct
18 Correct 5 ms 23940 KB Output is correct
19 Correct 8 ms 23944 KB Output is correct
20 Correct 5 ms 23896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 38976 KB Output is correct
2 Correct 11 ms 26772 KB Output is correct
3 Correct 13 ms 26548 KB Output is correct
4 Correct 57 ms 39932 KB Output is correct
5 Correct 24 ms 33484 KB Output is correct
6 Correct 35 ms 40400 KB Output is correct
7 Correct 6 ms 24236 KB Output is correct
8 Correct 42 ms 45264 KB Output is correct
9 Correct 28 ms 33768 KB Output is correct
10 Correct 51 ms 42792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 6 ms 23900 KB Output is correct
3 Correct 5 ms 23964 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 24152 KB Output is correct
7 Correct 6 ms 23936 KB Output is correct
8 Correct 6 ms 23900 KB Output is correct
9 Correct 6 ms 23948 KB Output is correct
10 Correct 7 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 38976 KB Output is correct
2 Correct 11 ms 26772 KB Output is correct
3 Correct 13 ms 26548 KB Output is correct
4 Correct 57 ms 39932 KB Output is correct
5 Correct 24 ms 33484 KB Output is correct
6 Correct 35 ms 40400 KB Output is correct
7 Correct 6 ms 24236 KB Output is correct
8 Correct 42 ms 45264 KB Output is correct
9 Correct 28 ms 33768 KB Output is correct
10 Correct 51 ms 42792 KB Output is correct
11 Correct 5 ms 23900 KB Output is correct
12 Correct 6 ms 23900 KB Output is correct
13 Correct 5 ms 23964 KB Output is correct
14 Correct 5 ms 23900 KB Output is correct
15 Correct 5 ms 23900 KB Output is correct
16 Correct 5 ms 24152 KB Output is correct
17 Correct 6 ms 23936 KB Output is correct
18 Correct 6 ms 23900 KB Output is correct
19 Correct 6 ms 23948 KB Output is correct
20 Correct 7 ms 23900 KB Output is correct
21 Correct 162 ms 51636 KB Output is correct
22 Correct 20 ms 27140 KB Output is correct
23 Correct 19 ms 27280 KB Output is correct
24 Correct 49 ms 37904 KB Output is correct
25 Correct 158 ms 51588 KB Output is correct
26 Correct 39 ms 33700 KB Output is correct
27 Correct 20 ms 27440 KB Output is correct
28 Correct 160 ms 51596 KB Output is correct
29 Correct 149 ms 51624 KB Output is correct
30 Correct 40 ms 32568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23900 KB Output is correct
5 Correct 5 ms 23900 KB Output is correct
6 Correct 5 ms 23900 KB Output is correct
7 Correct 5 ms 23900 KB Output is correct
8 Correct 5 ms 23952 KB Output is correct
9 Correct 5 ms 23900 KB Output is correct
10 Correct 5 ms 23900 KB Output is correct
11 Correct 5 ms 23896 KB Output is correct
12 Correct 87 ms 44944 KB Output is correct
13 Correct 5 ms 23896 KB Output is correct
14 Correct 5 ms 23900 KB Output is correct
15 Correct 5 ms 23900 KB Output is correct
16 Correct 6 ms 23908 KB Output is correct
17 Correct 154 ms 52116 KB Output is correct
18 Correct 5 ms 23940 KB Output is correct
19 Correct 8 ms 23944 KB Output is correct
20 Correct 5 ms 23896 KB Output is correct
21 Correct 47 ms 38976 KB Output is correct
22 Correct 11 ms 26772 KB Output is correct
23 Correct 13 ms 26548 KB Output is correct
24 Correct 57 ms 39932 KB Output is correct
25 Correct 24 ms 33484 KB Output is correct
26 Correct 35 ms 40400 KB Output is correct
27 Correct 6 ms 24236 KB Output is correct
28 Correct 42 ms 45264 KB Output is correct
29 Correct 28 ms 33768 KB Output is correct
30 Correct 51 ms 42792 KB Output is correct
31 Correct 5 ms 23900 KB Output is correct
32 Correct 6 ms 23900 KB Output is correct
33 Correct 5 ms 23964 KB Output is correct
34 Correct 5 ms 23900 KB Output is correct
35 Correct 5 ms 23900 KB Output is correct
36 Correct 5 ms 24152 KB Output is correct
37 Correct 6 ms 23936 KB Output is correct
38 Correct 6 ms 23900 KB Output is correct
39 Correct 6 ms 23948 KB Output is correct
40 Correct 7 ms 23900 KB Output is correct
41 Correct 162 ms 51636 KB Output is correct
42 Correct 20 ms 27140 KB Output is correct
43 Correct 19 ms 27280 KB Output is correct
44 Correct 49 ms 37904 KB Output is correct
45 Correct 158 ms 51588 KB Output is correct
46 Correct 39 ms 33700 KB Output is correct
47 Correct 20 ms 27440 KB Output is correct
48 Correct 160 ms 51596 KB Output is correct
49 Correct 149 ms 51624 KB Output is correct
50 Correct 40 ms 32568 KB Output is correct
51 Correct 24 ms 27708 KB Output is correct
52 Correct 150 ms 49356 KB Output is correct
53 Correct 159 ms 52368 KB Output is correct
54 Correct 30 ms 30136 KB Output is correct
55 Correct 63 ms 39648 KB Output is correct
56 Correct 43 ms 36384 KB Output is correct
57 Correct 48 ms 34232 KB Output is correct
58 Correct 157 ms 52916 KB Output is correct
59 Correct 36 ms 31140 KB Output is correct
60 Correct 46 ms 33732 KB Output is correct