Submission #336423

#TimeUsernameProblemLanguageResultExecution timeMemory
336423ncduy0303Lasers (NOI19_lasers)C++17
100 / 100
149 ms10076 KiB
#include <bits/stdc++.h> using namespace std; #define ar array #define ll long long const int MAX_N = 1e5 + 1; const int MOD = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e18; void solve() { int len, n; cin >> len >> n; vector<ar<int,2>> block; // all ranges where the laser cannot pass through for (int i = 0; i < n; i++) { int m; cin >> m; vector<int> ps(m + 1); for (int i = 1; i <= m; i++) { cin >> ps[i]; ps[i] += ps[i - 1]; } for (int i = 1; i <= m; i++) { int l = len - (ps[m] - ps[i - 1]) + 1; int r = ps[i]; if (l <= r) block.push_back({l, r}); } } sort(block.begin(), block.end()); if (block.empty()) { cout << 0 << "\n"; return; } int ans = 0; auto rng = block[0]; for (int i = 1; i < block.size(); i++) { auto new_rng = block[i]; if (rng[1] + 1 < new_rng[0]) { ans += rng[1] - rng[0] + 1; rng = new_rng; } else { rng[1] = max(rng[1], new_rng[1]); } } ans += rng[1] - rng[0] + 1; cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++) { // cout << "Case #" << t << ": "; solve(); } }

Compilation message (stderr)

lasers.cpp: In function 'void solve()':
lasers.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i = 1; i < block.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...