답안 #105725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
105725 2019-04-14T06:13:09 Z Pro_ktmr Boat (APIO16_boat) C++14
0 / 100
889 ms 525312 KB
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define MOD 1000000007

int N;
int a[500],b[500];
vector<int> zaatu;

int dp[500][1002] = {};
int solve(int now, int bef){
	if(now == N) return 1;
	if(dp[now][bef] != 0) return dp[now][bef];
	LL ans = solve(now+1,bef);
	for(int i=max(zaatu[bef]+1,a[now]); i<b[now]; i++){
		ans += solve(now+1, lower_bound(zaatu.begin(), zaatu.end(), i)-zaatu.begin());
		ans %= MOD;
	}
	return dp[now][bef] = ans % MOD;
}

int main(){
	
	scanf("%d", &N);
	for(int i=0; i<N; i++){
		scanf("%d%d", a+i, b+i);
		b[i]++;
		//zaatu.PB(a[i]);
		//zaatu.PB(b[i]);
		for(int j=a[i]; j<b[i]; j++) zaatu.PB(j);
	}
	zaatu.PB(0);
	sort(zaatu.begin(), zaatu.end());

	int dp[2][1002];
	for(int i=0; i<zaatu.size(); i++){
		dp[N%2][i] = 1;
	}
	for(int i=N-1; i>=0; i--){
		for(int j=0; j<zaatu.size(); j++){
			LL ans = dp[(i+1)%2][j];
			for(int k=max(zaatu[j]+1, a[i]); k<b[i]; k++){
				ans += dp[(i+1)%2][lower_bound(zaatu.begin(), zaatu.end(), k)-zaatu.begin()];
				ans %= MOD;
			}
			dp[i][j] = ans;
		}
	}

	cout << dp[0][0] - 1 << endl;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:39:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<zaatu.size(); i++){
               ~^~~~~~~~~~~~~
boat.cpp:43:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0; j<zaatu.size(); j++){
                ~^~~~~~~~~~~~~
boat.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
boat.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", a+i, b+i);
   ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 889 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -