Submission #203557

# Submission time Handle Problem Language Result Execution time Memory
203557 2020-02-21T08:25:28 Z blacktulip Semiexpress (JOI17_semiexpress) C++17
48 / 100
1000 ms 91684 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long lo;
typedef pair< lo,lo > PII;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define int long long
#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 MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 100000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;
 
int n,m,b,c,a,k,flag,t;
int cev,ans;
map<PII,int> dp;
map<int,int> vis;
string s;
set<int> st,st1;
vector<int> v;

inline int f(int sira,int kac){
	//~ cout<<sira<<" : : "<<kac<<endl;
	int cevv=-inf;
	if(kac<0)return -inf;
	if(sira>n){
		//~ if(kac!=0)return -inf;
		return 0;
	}
	if(dp.find(mp(sira,kac))!=dp.end())return dp[mp(sira,kac)];
	if(vis[sira]){
		//~ cout<<"**\n";
		int bas=sira;
		int son=0;
		if(vis[sira]<(int)v.size())
			son=v[vis[sira]]-1;
		else son=n;
		while(bas<=son){
			if((sira-1)*b+(ort-sira)*a>t)son=ort-1;
			else bas=ort+1;
		}
		
		//~ cout<<"***\n";
		if(son<sira){
			cevv=max(cevv,f(n+1,kac));
			//~ cevv=max(cevv,f(sira+1,kac-1));
		}
		else{
			cevv=max(cevv,f(son+1,kac)+son-sira+1);
		}
		
	}
	else{
		//~ cout<<"()\n";
		//~ cevv=max(cevv,f(sira+1,kac));
		auto it1=st.upper_bound(sira);
		auto it=it1;
		//~ if(it==st.begin())cout<<"one\n";
		it--;
		int bas=sira;
		int son=0;
		if(it1!=st.end())
			son=*it1-1;
		else son=n-1;
		//~ if(sira==5)cout<<son<<"yess"<<*it1<<endl;
		while(bas<=son){
			//~ if(sira==8){
				//~ cout<<bas<<" ()() "<<son<<" ()() "<<ort<<" ()() "<<(*it-1)*b+(sira-*it)*c+(ort-sira)*a<<"DEBUG"<<endl;
			//~ }
			if((*it-1)*b+(sira-*it)*c+(ort-sira)*a>t)son=ort-1;
			else bas=ort+1;
		}
		//~ cout<<sira<<" : : "<<son<<endl;
		cevv=max(cevv,f(*it1,kac));
		//~ if(son<sira)cevv=max(cevv,f(sira+1,kac));
		cevv=max(cevv,f(son+1,kac-1)+son-sira+1);
		
	}
	return dp[mp(sira,kac)]=cevv;
}

main(void){
	//~ memset(dp,-1,sizeof(dp));
	scanf("%lld %lld %lld",&n,&m,&k);
	scanf("%lld %lld %lld",&a,&b,&c);
	scanf("%lld",&t);
	for(int i=1;i<=m;i++){
		int x;
		scanf("%lld",&x);
		vis[x]=i;
		v.pb(x);
		st.insert(x);
		k--;
	}
	cev=f(1,k);
	printf("%lld\n",--cev);
	return 0;
}

Compilation message

semiexpress.cpp:94:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(void){
          ^
semiexpress.cpp: In function 'int main()':
semiexpress.cpp:96:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %lld",&n,&m,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
semiexpress.cpp:97:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %lld",&a,&b,&c);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
semiexpress.cpp:98:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&t);
  ~~~~~^~~~~~~~~~~
semiexpress.cpp:101:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&x);
   ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 4 ms 256 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 6 ms 632 KB Output is correct
20 Correct 7 ms 888 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Correct 571 ms 58228 KB Output is correct
23 Execution timed out 1075 ms 91684 KB Time limit exceeded
24 Halted 0 ms 0 KB -