Submission #391806

# Submission time Handle Problem Language Result Execution time Memory
391806 2021-04-20T00:45:27 Z maomao90 Lasers (NOI19_lasers) C++14
10 / 100
66 ms 32492 KB
#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;
	REP (i, 1, arr.size()) {
		if (arr[i - 1].SE < arr[i].FI) {
			res.pb(f, arr[i - 1].SE);
			f = arr[i].FI;
		}
	}
	res.pb(f, arr[arr.size() - 1].SE);
	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) {
			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

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++)
......
   52 |  REP (i, 0, arr.size()) {
      |       ~~~~~~~~~~~~~~~~                  
lasers.cpp:52:2: note: in expansion of macro 'REP'
   52 |  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++)
......
   93 |  REP (i, 0, ranges[id].size()) {
      |       ~~~~~~~~~~~~~~~~~~~~~~~           
lasers.cpp:93:2: note: in expansion of macro 'REP'
   93 |  REP (i, 0, ranges[id].size()) {
      |  ^~~
lasers.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   65 |  scanf("%d%d", &l, &r);
      |  ~~~~~^~~~~~~~~~~~~~~~
lasers.cpp:67:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   67 |   scanf("%d", &x[i]);
      |   ~~~~~^~~~~~~~~~~~~
lasers.cpp:70:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |    scanf("%d", &walls[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 15 ms 23744 KB Output is correct
4 Correct 15 ms 23800 KB Output is correct
5 Correct 15 ms 23800 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 16 ms 23804 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 17 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 15 ms 23744 KB Output is correct
4 Correct 15 ms 23800 KB Output is correct
5 Correct 15 ms 23800 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 16 ms 23804 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 17 ms 23800 KB Output is correct
11 Incorrect 17 ms 23812 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 32492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 23796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 66 ms 32492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 15 ms 23744 KB Output is correct
4 Correct 15 ms 23800 KB Output is correct
5 Correct 15 ms 23800 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 16 ms 23804 KB Output is correct
8 Correct 15 ms 23756 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 17 ms 23800 KB Output is correct
11 Incorrect 17 ms 23812 KB Output isn't correct
12 Halted 0 ms 0 KB -