답안 #780560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780560 2023-07-12T10:13:53 Z vjudge1 Go (COCI18_go) C++17
40 / 100
1000 ms 135116 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long lo; 

#define fi first
#define se second
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000;
const lo li = 1001;
const lo mod = 1000000007;

int n,m,a[101],k,flag,t[101],b[101];
int cev;
string s;
vector<int> v;
map<pair<int,pair<int,int>>,int> dp[li*li];

inline int in(){
	int x;
	scanf("%d",&x);
	return x;
}

inline int f(int tim,int l,int r,int kim){
	int cevv=0;
	if(l<=1 && r>=m)return 0;
	//~ cout<<tim<<" () "<<l<<" () "<<r<<" () "<<kim<<" () "<<t[l-1]<<endl;
	int ll=l;
	if(kim==1)ll=r;
	if(dp[tim].find({l,{r,kim}})!=dp[tim].end())return dp[tim][{l,{r,kim}}];
	if(kim==0){
		if(l>1){
			cevv=max(cevv,f(tim+a[l]-a[l-1],l-1,r,0)+(tim+a[l]-a[l-1]<t[l-1]?b[l-1]:0));
		}
		if(r<m){
			cevv=max(cevv,f(tim+a[r+1]-a[l],l,r+1,1)+(tim+a[r+1]-a[l]<t[r+1]?b[r+1]:0));
		}
	}
	else{
		if(l>1){
			cevv=max(cevv,f(tim+a[r]-a[l-1],l-1,r,0)+(tim+a[r]-a[l-1]<t[l-1]?b[l-1]:0));
		}
		if(r<m){
			cevv=max(cevv,f(tim+a[r+1]-a[r],l,r+1,1)+(tim+a[r+1]-a[r]<t[r+1]?b[r+1]:0));
		}
	}
	return dp[tim][{l,{r,kim}}]=cevv;
}

int main(void){
	n=in(),k=in(),m=in();
	//~ memset(dp,-1,sizeof(dp));
	for(int i=1;i<=m;i++){
		a[i]=in(),b[i]=in(),t[i]=in();
	}
	int l=0,r=0;
	for(int i=1;i<=m;i++){
		if(a[i]<=k){l=i;r=i+1;}
	}
	int at=f(k-a[l],l,l,0)+(k-a[l]<t[l]?b[l]:0);
	//~ memset(dp,-1,sizeof(dp));
	int kat=f(a[r]-k,r,r,1)+(a[r]-k<t[r]?b[r]:0);
	if(l==0)at=0;
	if(r==m+1)at=0;
	printf("%d\n",max(at,kat));
	return 0;
}

Compilation message

go.cpp: In function 'int f(int, int, int, int)':
go.cpp:36:6: warning: variable 'll' set but not used [-Wunused-but-set-variable]
   36 |  int ll=l;
      |      ^~
go.cpp: In function 'int in()':
go.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d",&x);
      |  ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 58 ms 95788 KB Execution killed with signal 11
2 Correct 21 ms 47292 KB Output is correct
3 Runtime error 58 ms 95708 KB Execution killed with signal 11
4 Correct 21 ms 47344 KB Output is correct
5 Correct 911 ms 123456 KB Output is correct
6 Correct 257 ms 75416 KB Output is correct
7 Execution timed out 1097 ms 134712 KB Time limit exceeded
8 Execution timed out 1075 ms 135116 KB Time limit exceeded
9 Execution timed out 1074 ms 133428 KB Time limit exceeded
10 Execution timed out 1081 ms 135092 KB Time limit exceeded