Submission #1072685

#TimeUsernameProblemLanguageResultExecution timeMemory
1072685_rain_Lasers (NOI19_lasers)C++14
100 / 100
126 ms13780 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fixbug false

void SETIO(string name = ""){
    if (name=="") return;
    freopen((name+".inp").c_str(),"r",stdin);
//    freopen((name+".out").c_str(),"w",stdout);
    return;
}

int numrow , L;
#define fi first
#define se second

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    SETIO("");

    cin >> L >> numrow;
    vector<pair<int,int>> ev;
    for (int i = 1; i <= numrow; ++i){
          int x; cin >> x;
          vector<int> a(x+2,0) , pre(x+2,0);
          for (int j = 1; j <= x; ++j) {
            cin >> a[j];
            pre[j] = pre[j - 1] + a[j];
          }
          for (int j = 1; j <= x; ++j){
            int jump = a[j];
            int l = pre[j - 1] + 1 , r = L - (pre[x] - pre[j]);
            if (l + jump - 1 < r - jump + 1) continue;
            ev.push_back({min(L+1,l + jump) , -1});
            ev.push_back({max(1,r - jump + 1) , 1});
            if (fixbug){
                cout << "FIXBUG\n";
                cout << i << ' ' << j << ' ' << l << ' ' << r << '\n';
            }
          }
    }
    sort(ev.begin(),ev.end());
    int leftmost = -1 , sum = 0 , ans= 0;
    for (int i = 0; i < ev.size(); ++i){
        if (leftmost == -1) leftmost = ev[i].fi;
        sum += ev[i].se;
        if (sum==0){
            if (fixbug){
                    cout << "DEBUG\n";
                    cout << ev[i].fi << ' ' << ev[i].se << '\n';
            }
            ans += ev[i].fi - leftmost ;
            leftmost = -1;
        }
    }
    cout << ans;
}

Compilation message (stderr)

lasers.cpp: In function 'int main()':
lasers.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < ev.size(); ++i){
      |                     ~~^~~~~~~~~~~
lasers.cpp: In function 'void SETIO(std::string)':
lasers.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen((name+".inp").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...