답안 #216850

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216850 2020-03-28T07:56:29 Z oolimry Collecting Stamps 3 (JOI20_ho_t3) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define x first
#define t second

using namespace std;
typedef pair<long long, long long> ii;
long long inf = (1LL << 48LL);
vector<ii> arr = {ii({0,0})};

static long long memo[205][205][205];
long long n, L; 


long long dp(int pos, int bound, int taken){
	if(memo[pos][bound][taken] != -1) return memo[pos][bound][taken];
	//cout << pos << " " << bound << " " << taken << endl;
	
	long long ans = inf;
	if(pos == bound){
		if(pos == 0 && taken == 0) return 0;
		else return inf;
	}
	if(taken < 0) return inf;
	if(pos == 0) return inf;
	
	int pos2;
	long long dPos, dCross;
	if(pos < bound || bound == 0){
		pos2 = pos-1;
		if(pos2 == -1) pos2 = n;
	}
	else{
		pos2 = pos+1;
		if(pos2 == n+1) pos2 = 0;
	}
	
	if(pos > pos2) dPos = arr[pos].x - arr[pos2].x;
	else dPos = arr[pos2].x - arr[pos].x;
	
	

	///move from bound to pos
	if(bound > pos){
		dCross = L - (arr[bound].x - arr[pos].x);
	}
	else{
		dCross = L - (arr[pos].x - arr[bound].x);
	}
	
	assert(dPos >= 0);
	assert(dCross >= 0);
	
	if(pos == 1 && bound == 0){
		//cout << pos << " " << bound << " " << pos2 << " " << dPos << " " << dCross << "\n";
	}
	
	ans = min(ans, dp(pos2, bound, taken) + dPos);
	ans = min(ans, dp(bound, pos2, taken) + dCross);
	
	if(dp(pos2, bound, taken - 1) + dPos <= arr[pos].t){
		ans = min(dp(pos2, bound, taken - 1) + dPos, ans);
	}
	
	if(dp(bound, pos2, taken - 1) + dCross <= arr[pos].t){
		ans = min(dp(bound, pos2, taken - 1) + dCross, ans);
	}
	
	memo[pos][bound][taken] = ans;
	return ans;
}
int //main(){
	freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> L;
	
	for(int i = 0;i < n;i++){
		arr.push_back(ii(0,0));
	}
	
	for(int i = 1;i <= n;i++) cin >> arr[i].x;
	for(int i = 1;i <= n;i++) cin >> arr[i].t;
	
	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= n;j++){
			for(int k = 0;k <= n;k++){
				memo[i][j][k] = -1;
			}
		}
	}
	
	
	long long ANS = 0;
	for(long long taken = 0;taken <= n;taken++){
		for(int i = 0;i <= n;i++){
			for(int j = 0;j <= n;j++){
				long long DP = dp(i,j,taken);
				if(DP < inf){
					ANS = max(ANS, taken);
				}
			}
		}
	}
	
	cout << ANS;
	
	
	//cout << dp(1,0,1);
	
}




Compilation message

ho_t3.cpp:72:9: error: 'int freopen' redeclared as different kind of symbol
  freopen("i.txt","r",stdin);
         ^
In file included from /usr/include/c++/7/cstdio:42:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:46,
                 from ho_t3.cpp:1:
/usr/include/stdio.h:278:14: note: previous declaration 'FILE* freopen(const char*, const char*, FILE*)'
 extern FILE *freopen (const char *__restrict __filename,
              ^~~~~~~
ho_t3.cpp:73:27: error: expected constructor, destructor, or type conversion before '(' token
  ios_base::sync_with_stdio(false);
                           ^
ho_t3.cpp:74:2: error: 'cin' does not name a type; did you mean 'sin'?
  cin.tie(0);
  ^~~
  sin
ho_t3.cpp:76:2: error: 'cin' does not name a type; did you mean 'sin'?
  cin >> n >> L;
  ^~~
  sin
ho_t3.cpp:78:2: error: expected unqualified-id before 'for'
  for(int i = 0;i < n;i++){
  ^~~
ho_t3.cpp:78:16: error: 'i' does not name a type
  for(int i = 0;i < n;i++){
                ^
ho_t3.cpp:78:22: error: 'i' does not name a type
  for(int i = 0;i < n;i++){
                      ^
ho_t3.cpp:82:2: error: expected unqualified-id before 'for'
  for(int i = 1;i <= n;i++) cin >> arr[i].x;
  ^~~
ho_t3.cpp:82:16: error: 'i' does not name a type
  for(int i = 1;i <= n;i++) cin >> arr[i].x;
                ^
ho_t3.cpp:82:23: error: 'i' does not name a type
  for(int i = 1;i <= n;i++) cin >> arr[i].x;
                       ^
ho_t3.cpp:83:2: error: expected unqualified-id before 'for'
  for(int i = 1;i <= n;i++) cin >> arr[i].t;
  ^~~
ho_t3.cpp:83:16: error: 'i' does not name a type
  for(int i = 1;i <= n;i++) cin >> arr[i].t;
                ^
ho_t3.cpp:83:23: error: 'i' does not name a type
  for(int i = 1;i <= n;i++) cin >> arr[i].t;
                       ^
ho_t3.cpp:85:2: error: expected unqualified-id before 'for'
  for(int i = 0;i <= n;i++){
  ^~~
ho_t3.cpp:85:16: error: 'i' does not name a type
  for(int i = 0;i <= n;i++){
                ^
ho_t3.cpp:85:23: error: 'i' does not name a type
  for(int i = 0;i <= n;i++){
                       ^
ho_t3.cpp:95:2: error: expected unqualified-id before 'for'
  for(long long taken = 0;taken <= n;taken++){
  ^~~
ho_t3.cpp:95:26: error: 'taken' does not name a type; did you mean 'tan'?
  for(long long taken = 0;taken <= n;taken++){
                          ^~~~~
                          tan
ho_t3.cpp:95:37: error: 'taken' does not name a type; did you mean 'tan'?
  for(long long taken = 0;taken <= n;taken++){
                                     ^~~~~
                                     tan
ho_t3.cpp:106:2: error: 'cout' does not name a type; did you mean 'cosl'?
  cout << ANS;
  ^~~~
  cosl
ho_t3.cpp:111:1: error: expected declaration before '}' token
 }
 ^