Submission #391807

#TimeUsernameProblemLanguageResultExecution timeMemory
391807maomao90Lasers (NOI19_lasers)C++14
100 / 100
440 ms67872 KiB
#include <bits/stdc++.h> using namespace std; #define mnto(x, y) x = min(x, (__typeof__(x)) y) #define mxto(x, y) x = max(x, (__typeof__(x)) y) #define REP(i, s, e) for (int i = s; i < e; i++) #define RREP(i, s, e) for (int i = s; i >= e; i--) typedef long long ll; typedef long double ld; #define MP make_pair #define FI first #define SE second typedef pair<int, int> ii; typedef pair<ll, ll> pll; #define MT make_tuple typedef tuple<int, int, int> iii; #define ALL(_a) _a.begin(), _a.end() #define pb emplace_back typedef vector<int> vi; typedef vector<ii> vii; #define INF 1000000005 #define LINF 1000000000000000005 #define MOD 1000000007 #define MAXR 500005 int l, r; int x[MAXR]; vi walls[MAXR]; vii ranges[MAXR], temp; int sum[MAXR]; priority_queue<ii, vector<ii>, greater<ii> > pq; int ans; vii joinRanges(vii arr) { vii res; if (arr.empty()) return res; int f = arr[0].FI, s = arr[0].SE; REP (i, 1, arr.size()) { if (s < arr[i].FI) { res.pb(f, s); f = arr[i].FI; s = arr[i].SE; } mxto(s, arr[i].SE); } res.pb(f, s); return res; } vii inv(vii arr) { vii res; int prv = 0; REP (i, 0, arr.size()) { if (prv < arr[i].FI) { res.pb(prv, arr[i].FI); } prv = arr[i].SE; } if (prv < l) { res.pb(prv, l); } return res; } int main() { scanf("%d%d", &l, &r); REP (i, 0, r) { scanf("%d", &x[i]); REP (j, 0, x[i]) { walls[i].pb(0); scanf("%d", &walls[i][j]); sum[i] += walls[i][j]; } } REP (i, 0, r) { int cur = 0; REP (j, 0, x[i] + 1) { if (cur < cur + l - sum[i]) { ranges[i].pb(cur, cur + l - sum[i]); // [l, r) } if (j != x[i]) cur += walls[i][j]; } ranges[i] = joinRanges(ranges[i]); ranges[i] = inv(ranges[i]); pq.push(MP(ranges[i].size(), i)); } while (pq.size() > 1) { int sze, i; tie(sze, i) = pq.top(); pq.pop(); int nsze, ni; tie(nsze, ni) = pq.top(); pq.pop(); temp.clear(); merge(ALL(ranges[i]), ALL(ranges[ni]), back_inserter<vii>(temp)); ranges[ni] = joinRanges(temp); pq.push(MP(ranges[ni].size(), ni)); } int id = pq.top().SE; REP (i, 0, ranges[id].size()) { ans += ranges[id][i].SE - ranges[id][i].FI; } printf("%d\n", ans); return 0; }

Compilation message (stderr)

lasers.cpp: In function 'vii joinRanges(vii)':
lasers.cpp:6:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
   39 |  REP (i, 1, arr.size()) {
      |       ~~~~~~~~~~~~~~~~                  
lasers.cpp:39:2: note: in expansion of macro 'REP'
   39 |  REP (i, 1, arr.size()) {
      |  ^~~
lasers.cpp: In function 'vii inv(vii)':
lasers.cpp:6:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
   54 |  REP (i, 0, arr.size()) {
      |       ~~~~~~~~~~~~~~~~                  
lasers.cpp:54:2: note: in expansion of macro 'REP'
   54 |  REP (i, 0, arr.size()) {
      |  ^~~
lasers.cpp: In function 'int main()':
lasers.cpp:6:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
   97 |  REP (i, 0, ranges[id].size()) {
      |       ~~~~~~~~~~~~~~~~~~~~~~~           
lasers.cpp:97:2: note: in expansion of macro 'REP'
   97 |  REP (i, 0, ranges[id].size()) {
      |  ^~~
lasers.cpp:67:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |  scanf("%d%d", &l, &r);
      |  ~~~~~^~~~~~~~~~~~~~~~
lasers.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   69 |   scanf("%d", &x[i]);
      |   ~~~~~^~~~~~~~~~~~~
lasers.cpp:72:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |    scanf("%d", &walls[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~
#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...