Submission #90522

# Submission time Handle Problem Language Result Execution time Memory
90522 2018-12-22T07:16:27 Z szawinis Boat (APIO16_boat) C++17
0 / 100
5 ms 2560 KB
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>
using namespace std;
#define long long long
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const int N = 510;

class APIO16_boat {

	void add(long &a, long b) {
		a += b;
		if(a >= MOD) a -= MOD;
	}
	long mul(long a, long b) { return a*b % MOD; }
	long modPow(long b, long e) {
		if(e == 0) return 1;
		if(e == 1) return b;
		return mul(modPow(mul(b, b), e >> 1), modPow(b, e & 1));
	}

	int n, a[N], b[N];
	pair<int,int> segs[N];
	vector<int> vals;
	unordered_map<int, int> rev;

	long ans, inv[N], dp[N][N];

public:
	void solve(istream &cin, ostream &cout) {
		cin >> n;
		vals.push_back(0);
		for(int i = 1; i <= n; i++) {
			cin >> a[i] >> b[i];
			vals.push_back(a[i]);
			vals.push_back(b[i]+1);
		}
		sort(vals.begin(), vals.end());
		vals.resize(unique(vals.begin(), vals.end()) - vals.begin());
		for(int i = 0; i < vals.size(); i++) rev[vals[i]] = i;
		for(int i = 1; i <= n; i++) segs[i] = {rev[a[i]], rev[b[i]+1]};

		inv[0] = 1;
		for(int i = 1; i <= n; i++) inv[i] = mul(inv[i-1], modPow(i, MOD-2));

//		for(int x: vals) cout << x << ' ';
//		cout << endl;
//		for(int i = 1; i <= n; i++) cout << segs[i].first << ' ' << segs[i].second << endl;

		for(int j = 0; j < vals.size(); j++) dp[0][j] = 1;
		for(int i = 1; i <= n; i++) {
			for(int j = segs[i].first; j < segs[i].second; j++) {
				int cnt = 1;
				long f = vals[j+1] - vals[j], sum = f;
				for(int k = i-1; k >= 0; k--) {
					if(segs[k].first <= j && j < segs[k].second) {
						f = mul(f, vals[j+1] - vals[j] - cnt);
						f = mul(f, inv[cnt + 1]);
						sum += f;
						++cnt;
					}
					add(dp[i][j], mul(dp[k][j-1], sum));
				}
			}
			partial_sum(dp[i], dp[i] + vals.size(), dp[i]);
			add(ans, dp[i][vals.size() - 1]);
		}
		cout << ans;
	}
};

class Solver {
public:
	void solve(std::istream& in, std::ostream& out) {
	    APIO16_boat *obj = new APIO16_boat();
		obj->solve(in, out);
		delete obj;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	Solver solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Compilation message

boat.cpp: In member function 'void APIO16_boat::solve(std::istream&, std::ostream&)':
boat.cpp:47:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < vals.size(); i++) rev[vals[i]] = i;
                  ~~^~~~~~~~~~~~~
boat.cpp:57:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < vals.size(); j++) dp[0][j] = 1;
                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2428 KB Output isn't correct
2 Halted 0 ms 0 KB -