Submission #792835

# Submission time Handle Problem Language Result Execution time Memory
792835 2023-07-25T09:35:10 Z IvanJ Boat (APIO16_boat) C++17
0 / 100
10 ms 16340 KB
#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 505;
const int MOD = 1e9 + 7;

int add(int x, int y) {x += y;if(x >= MOD) x -= MOD;return x;}
int sub(int x, int y) {x -= y;if(x < 0) x += MOD;return x;}

int n;
int a[maxn], b[maxn];

int main() {
	scanf("%d", &n);
	for(int i = 0;i < n;i++) 
		scanf("%d%d", a + i, b + i);
	
	vector<int> dp(1e6 + 1, 0), pref(1e6 + 1, 0);
	int maxi = 0;
	for(int i = 0;i < n;i++) {
		maxi = max(maxi, b[i]);
		for(int j = a[i];j <= b[i];j++) {
			if(i == 0) dp[j] = 1;
			else {
				if(j - 1 >= a[i - 1]) {
					int sum = pref[j - 1];
					dp[j] = add(dp[j], sum);
				}
			}
		}
		if(i == 0) dp[0] = 1;
		
		//for(int j = 0;j <= maxi;j++) cout << dp[j] << " ";
		//cout << "\n";
		
		pref[0] = dp[0];
		for(int j = 1;j <= maxi;j++) 
			pref[j] = add(pref[j - 1], dp[j]);
	}
	printf("%d\n", sub(pref[maxi], (n > 1) ? dp[0] : 0));
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
boat.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |   scanf("%d%d", a + i, b + i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 16340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 16340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 16300 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 16340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -