답안 #525285

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
525285 2022-02-11T09:02:00 Z sicho_mohit Lasers (NOI19_lasers) C++14
100 / 100
331 ms 41284 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std ;
const int N=1e5+5;
int main ()
{
    ll n , k ;
    cin >> n >> k ;
    vector<vector<ll>>prefix(k+1);
    for (int i=0;i<k;i++)
    {
        int t ;
        cin >> t ;
        ll sum=0;
        prefix[i].pb(0);
        for (int j=0;j<t;j++)
        {
            ll  a;
            cin >> a ;
            sum+=a;
            prefix[i].pb(sum);
        }
    }
    vector<pair<ll,ll>>ans;
    // start from each row 
    for (int i=0;i<k;i++)
    {
        // work on this row 
        for (int j=1;j<prefix[i].size();j++)
        {
            ll l=prefix[i][j-1]+1;
            ll r=(n-(prefix[i][prefix[i].size()-1]-prefix[i][j]));
            ll s=r-l+1;
            ll w=prefix[i][j]-prefix[i][j-1];
            if(2*w-s>0)
            {
                ans.pb({r-w+1,l+w-1});
            }
        }
    }
    sort(ans.begin(),ans.end());
    if(ans.size()==0)
    cout<<"0"<<"\n";
    else
    {
        ll emax=ans[0].ss;
        ll finalans=ans[0].ss-ans[0].ff+1;
        for (int i=1;i<ans.size();)
        {
            while(ans[i].ss<=emax&&i<ans.size())
            {
                i++;
            }
            if(i<ans.size())
            {
            if(ans[i].ff>emax)
            {
                finalans+=ans[i].ss-ans[i].ff+1;
            }
            else if(ans[i].ff==emax)
            {
                finalans+=ans[i].ss-ans[i].ff;
            }
            else
            {
                finalans+=ans[i].ss-emax;
            }
            emax=max(emax,ans[i].ss);
            i++;
            }
        }
        cout<<finalans<<"\n";
    }
}

Compilation message

lasers.cpp: In function 'int main()':
lasers.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for (int j=1;j<prefix[i].size();j++)
      |                      ~^~~~~~~~~~~~~~~~~
lasers.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for (int i=1;i<ans.size();)
      |                      ~^~~~~~~~~~~
lasers.cpp:53:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             while(ans[i].ss<=emax&&i<ans.size())
      |                                    ~^~~~~~~~~~~
lasers.cpp:57:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             if(i<ans.size())
      |                ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 326 ms 41284 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 316 ms 37552 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 7452 KB Output is correct
2 Correct 13 ms 1692 KB Output is correct
3 Correct 21 ms 1636 KB Output is correct
4 Correct 64 ms 7532 KB Output is correct
5 Correct 27 ms 4816 KB Output is correct
6 Correct 58 ms 5944 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 85 ms 6976 KB Output is correct
9 Correct 39 ms 7060 KB Output is correct
10 Correct 65 ms 7888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 292 KB Output is correct
7 Correct 1 ms 300 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 7452 KB Output is correct
2 Correct 13 ms 1692 KB Output is correct
3 Correct 21 ms 1636 KB Output is correct
4 Correct 64 ms 7532 KB Output is correct
5 Correct 27 ms 4816 KB Output is correct
6 Correct 58 ms 5944 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 85 ms 6976 KB Output is correct
9 Correct 39 ms 7060 KB Output is correct
10 Correct 65 ms 7888 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 288 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
16 Correct 1 ms 292 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 292 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 297 ms 36092 KB Output is correct
22 Correct 34 ms 3536 KB Output is correct
23 Correct 19 ms 2556 KB Output is correct
24 Correct 81 ms 10508 KB Output is correct
25 Correct 280 ms 35952 KB Output is correct
26 Correct 71 ms 8724 KB Output is correct
27 Correct 29 ms 3100 KB Output is correct
28 Correct 283 ms 35852 KB Output is correct
29 Correct 307 ms 36016 KB Output is correct
30 Correct 62 ms 7164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 292 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 326 ms 41284 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 316 ms 37552 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 59 ms 7452 KB Output is correct
22 Correct 13 ms 1692 KB Output is correct
23 Correct 21 ms 1636 KB Output is correct
24 Correct 64 ms 7532 KB Output is correct
25 Correct 27 ms 4816 KB Output is correct
26 Correct 58 ms 5944 KB Output is correct
27 Correct 2 ms 460 KB Output is correct
28 Correct 85 ms 6976 KB Output is correct
29 Correct 39 ms 7060 KB Output is correct
30 Correct 65 ms 7888 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 0 ms 288 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 292 KB Output is correct
36 Correct 1 ms 292 KB Output is correct
37 Correct 1 ms 300 KB Output is correct
38 Correct 1 ms 292 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 297 ms 36092 KB Output is correct
42 Correct 34 ms 3536 KB Output is correct
43 Correct 19 ms 2556 KB Output is correct
44 Correct 81 ms 10508 KB Output is correct
45 Correct 280 ms 35952 KB Output is correct
46 Correct 71 ms 8724 KB Output is correct
47 Correct 29 ms 3100 KB Output is correct
48 Correct 283 ms 35852 KB Output is correct
49 Correct 307 ms 36016 KB Output is correct
50 Correct 62 ms 7164 KB Output is correct
51 Correct 37 ms 3168 KB Output is correct
52 Correct 329 ms 37156 KB Output is correct
53 Correct 331 ms 37068 KB Output is correct
54 Correct 65 ms 5944 KB Output is correct
55 Correct 148 ms 12688 KB Output is correct
56 Correct 87 ms 9608 KB Output is correct
57 Correct 99 ms 9812 KB Output is correct
58 Correct 325 ms 37416 KB Output is correct
59 Correct 68 ms 6320 KB Output is correct
60 Correct 104 ms 8128 KB Output is correct