답안 #1081360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081360 2024-08-30T01:50:44 Z LCJLY Fish 2 (JOI22_fish2) C++14
0 / 100
1 ms 2396 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

int arr[505];
int a,b;
int memo[505][505];

bool dp(int l, int r, int val){
	if(l<a&&r>b){
		return true;
	}
	if(memo[l][r]!=-1) return memo[l][r];
	bool ans=false;
	if(l>=a){
		if(val>=arr[l]){
			ans|=dp(l-1,r,val+arr[l]);
		}
	}
	
	if(r<=b){
		if(val>=arr[r]){
			ans|=dp(l,r+1,val+arr[r]);
		}
	}
	return memo[l][r]=ans;
}

void solve(){ 	
	int n;
	cin >> n;
	
	for(int x=0;x<n;x++){
		cin >> arr[x];
	}
	
	int q;
	cin >> q;
	int temp,temp2,temp3;
	for(int x=0;x<q;x++){
		cin >> temp >> temp2 >> temp3;
		if(temp==1){
			//add
			temp2--;
			arr[temp2]=temp3;
		}
		else{
			//query
			a=temp2-1;
			b=temp3-1;
			int counter=0;
			memset(memo,-1,sizeof(memo));
			for(int y=a;y<=b;y++){
				counter+=dp(y-1,y+1,arr[y]);
				//show2(y,y,counter,counter);
			}
			cout << counter << "\n";
		}
	}
}

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	//freopen("in.txt","r",stdin);
	while(t--){
		solve();
	}
}

Compilation message

fish2.cpp: In function 'bool dp(long long int, long long int, long long int)':
fish2.cpp:35:19: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   35 |  return memo[l][r]=ans;
      |         ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -