Submission #388545

# Submission time Handle Problem Language Result Execution time Memory
388545 2021-04-12T04:37:12 Z talant117408 Boat (APIO16_boat) C++17
9 / 100
2000 ms 8876 KB
/*
    Code written by Talant I.D.
*/
#include <bits/stdc++.h>
 
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
 
const int mod = 1e9+7;
 
ll mode(ll a) {
    a %= mod;
    if (a < 0) a += mod;
    return a;
}
 
ll subt(ll a, ll b) {
    return mode(mode(a)-mode(b));
}
 
ll add(ll a, ll b) {
    return mode(mode(a)+mode(b));
}
 
ll mult(ll a, ll b) {
    return mode(mode(a)*mode(b));
}
 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b&1) res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

const int N = 503;
int a[N], b[N], n;

bool subtask1() {
	int flag = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] == b[i]) flag++;
	}
	return flag == n;
}

bool subtask2() {
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += b[i]-a[i];
	}
	return sum <= 1e6;
}

int main() {
	do_not_disturb
	
    cin >> n;
    for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
	}
	
	if (subtask1()) {
		vector <ll> dp(n+1);
		dp[0] = 1;
		for (int i = 1; i <= n; i++) {
			for (int j = i-1; j >= 0; j--) {
				if (a[i] > a[j]) {
					dp[i] = add(dp[i], dp[j]);
				}
			}
		}
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
			ans = add(ans, dp[i]);
		}
		cout << ans << endl;
		return 0;
	}
	else if (subtask2()) {
		vector <vector <ll>> dp(n+1);
		dp[0].pb(1);
		ll ans = 0;
		for (int i = 1; i <= n; i++) {
			for (int take = a[i]; take <= b[i]; take++) {
				dp[i].pb(0);
				for (int j = i-1; j >= 0; j--) {
					 if (take > a[j]) {
						 int needed = min(b[j], take-1);
						 dp[i][take-a[i]] = add(dp[i][take-a[i]], dp[j][needed-a[j]]); 
					 }
				}
				if (take != a[i])
					dp[i][take-a[i]] = add(dp[i][take-a[i]], dp[i][take-1-a[i]]);
			}
			ans = add(ans, dp[i][b[i]-a[i]]);
		}
		
		cout << ans << endl;
		return 0;
	}
	
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 248 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 248 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Execution timed out 2037 ms 8876 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 248 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 2 ms 204 KB Output is correct
11 Correct 2 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Execution timed out 2037 ms 8876 KB Time limit exceeded
22 Halted 0 ms 0 KB -