답안 #636852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636852 2022-08-30T10:13:22 Z drkarlicio2107 Boat (APIO16_boat) C++14
0 / 100
1867 ms 32188 KB
#include <bits/stdc++.h>
using namespace std; long long int mod=1e9+7;
pair <long long int, long long int> l [1000];
long long int dp [2][1000010];
vector < pair < pair< int, int> , pair <int, int> > > s;
int dulj [1000010];
int m (int a, int b){
	if (a+b<mod) return a+b;
	return a+b-mod;
}
int main(){
	ios_base::sync_with_stdio (false);
	cin.tie (0);
	long long int n; cin >> n;
	for (int i=0; i<n; i++){
		long long int a,b; cin >> a >> b; 
		l [i].first=a; l[i].second=b; s.push_back ({{a, b}, {i, 0}}); dulj [i]=b-a+1;
	}
	s.push_back ({{0, 0}, {0, 0}});
	sort (s.begin(), s.end()); long long int maxi=0;
	for (int i=1; i<s.size(); i++){
		if (l [s[i].second.first].first>l [s[i-1].second.first].second){
			l [s[i].second.first].first=l [s[i-1].second.first].second+1;
			l [s[i].second.first].second=dulj [s[i].second.first]+l [s[i].second.first].first;
		}
		maxi=max (maxi, l [s[i].second.first].second);
	}
	//cout << maxi << endl;
	dp [0][0]=1; 
	for (int j=1; j<maxi+1; j++) dp [0][j]+=dp [0][j-1];
	for (int i=0; i<n; i++){
		for (int j=l [i].first; j<=l [i].second; j++){
			dp [1][j]=(dp [1][j]+dp [0][j-1])%mod;
			//cout << dp [1][j] << endl;
		}
		dp [1][0]=(dp [1][0]+dp [0][maxi])%mod;
		for (int j=1; j<maxi+1; j++){
			//cout << dp [1][j] << " "; 
			dp[1][j]=(dp [1][j]+dp [1][j-1])%mod; 
			//cout << dp [1][j] << endl;
		}
		//cout << endl;
		swap (dp [0], dp [1]);
		for (int j=0; j<maxi+1; j++) dp [1][j]=0;
	}
	cout << (dp [0][maxi]-1)%mod << endl;
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for (int i=1; i<s.size(); i++){
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1867 ms 16008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1867 ms 16008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 32188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1867 ms 16008 KB Output isn't correct
2 Halted 0 ms 0 KB -