Submission #699111

#TimeUsernameProblemLanguageResultExecution timeMemory
699111DennisTranLasers (NOI19_lasers)C++17
100 / 100
434 ms23476 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]; map <int, int> mp; void solve(void) { cin >> L >> R; FOR(i, 1, R) { int n; cin >> n; int D = L; FOR(i, 1, n) cin >> a[i], sum[i] = sum[i - 1] + a[i], D -= a[i]; sum[n + 1] = L; FOR(i, 0, n) { int l = sum[i] + D + 1; int r = sum[i + 1]; if (r >= l) mp[l]++, mp[r + 1]--; //if (r >= l) cout << l << ' ' << r << '\n'; } //cout << '\n'; } int ans = 0, sum = 0; for (auto it = mp.begin(); it != mp.end() && next(it) != mp.end(); it++) { sum += it -> se; if (sum > 0) ans += next(it) -> fi - it ->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); }

Compilation message (stderr)

lasers.cpp: In function 'int main()':
lasers.cpp:9:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
lasers.cpp:44:5: note: in expansion of macro 'file'
   44 |     file("LASERS");
      |     ^~~~
lasers.cpp:9:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
lasers.cpp:44:5: note: in expansion of macro 'file'
   44 |     file("LASERS");
      |     ^~~~
#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...