Submission #1007834

#TimeUsernameProblemLanguageResultExecution timeMemory
1007834christinelynnLasers (NOI19_lasers)C++17
100 / 100
69 ms12160 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define fi first #define se second #define pb push_back #define pii pair<int,int> #define piii pair<pair<int,int>,pair<int,int>> #define pip pair<int,pair<int,int>> signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int ans = 0; int n, q; cin >> n >> q; vector<pair<int,int>>v; for(int i = 1; i <= q; i++){ int x; cin >> x; int a[x+5]; int tmp = 0; for(int i = 1; i <= x; i++){ cin >> a[i]; tmp += a[i]; } int rem = n - tmp; int cnt = 0; int last = 0; for(int i = 1; i <= x; i++){ last += a[i]; int val = a[i] - rem; if(val <= 0)continue; v.pb({last-val+1,last}); } } sort(v.begin(),v.end()); int last = 0; for(int i = 0; i < v.size(); i++){ //cout << "here >> " << v[i].fi << " " << v[i].se << endl; if(v[i].fi > last){ ans += (v[i].se - v[i].fi + 1); last = v[i].se; } else if(v[i].se > last){ ans += (v[i].se - last); last = v[i].se; } } cout << ans << endl; }

Compilation message (stderr)

lasers.cpp: In function 'int main()':
lasers.cpp:27:13: warning: unused variable 'cnt' [-Wunused-variable]
   27 |         int cnt = 0;
      |             ^~~
lasers.cpp:38:22: 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]
   38 |     for(int i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
#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...