제출 #699099

#제출 시각아이디문제언어결과실행 시간메모리
699099DennisTranLasers (NOI19_lasers)C++17
10 / 100
31 ms7148 KiB
#pragma GCC optimize("O2") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FOD(i, a, b) for (int i = (a); i >= (b); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define ALL(x) (x).begin(), (x).end() #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define ii pair <int, int> #define fi first #define se second using namespace std; const int MAXN = 5e5 + 5; int L, R, a[MAXN], sum[MAXN]; vector <ii> ans; void solve(void) { cin >> L >> R; FOR(i, 1, R) { int n; cin >> n; FOR(i, 1, n) cin >> a[i], sum[i] = sum[i - 1] + a[i]; vector <ii> lines; FOR(i, 0, n) { int l = sum[i] + 1; int r = L - sum[n] + sum[i] + 1; if (r > l) lines.emplace_back(l, r); //if (r > l) cout << l << ' ' << r << '\n'; } vector <ii> new_lines; new_lines.emplace_back(1, 1); for (auto x : lines) if (x.fi <= new_lines.back().se) new_lines.back().se = x.se; else new_lines.emplace_back(x); new_lines.emplace_back(L + 1, L + 1); REP(i, (int) new_lines.size() - 1) { int l = new_lines[i].se, r = new_lines[i + 1].fi; if (r > l) ans.emplace_back(l, r); //if (r > l) cout << l << ' ' << r << '\n'; } //cout << '\n'; } vector <ii> new_ans; sort(ALL(ans)); for (auto x : ans) if (new_ans.size() && x.fi <= new_ans.back().se) new_ans.back().se = x.se; else new_ans.emplace_back(x); int ans = 0; for (auto x : new_ans) ans += x.se - x.fi; cout << ans; } signed main(void) { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //file("LASERS"); //int T; cin >> T; while (T--) solve(); cerr << "Time elapsed: " << TIME << " s.\n"; return (0 ^ 0); }
#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...